2019-05-19 15:51:43 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2008-10-02 05:27:57 +00:00
/***************************************************************************
*
* Copyright ( C ) 2007 - 2008 SMSC
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <linux/module.h>
# include <linux/kmod.h>
# include <linux/netdevice.h>
# include <linux/etherdevice.h>
# include <linux/ethtool.h>
# include <linux/mii.h>
# include <linux/usb.h>
2012-10-26 03:43:56 +00:00
# include <linux/bitrev.h>
# include <linux/crc16.h>
2008-10-02 05:27:57 +00:00
# include <linux/crc32.h>
# include <linux/usb/usbnet.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 17:04:11 +09:00
# include <linux/slab.h>
2016-04-29 09:05:59 +02:00
# include <linux/of_net.h>
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
# include <linux/irq.h>
# include <linux/irqdomain.h>
2020-08-26 13:17:17 +02:00
# include <linux/mdio.h>
# include <linux/phy.h>
2022-02-09 13:42:55 +01:00
# include <net/selftests.h>
2008-10-02 05:27:57 +00:00
# include "smsc95xx.h"
# define SMSC_CHIPNAME "smsc95xx"
2020-08-26 13:17:17 +02:00
# define SMSC_DRIVER_VERSION "2.0.0"
2008-10-02 05:27:57 +00:00
# define HS_USB_PKT_SIZE (512)
# define FS_USB_PKT_SIZE (64)
# define DEFAULT_HS_BURST_CAP_SIZE (16 * 1024 + 5 * HS_USB_PKT_SIZE)
# define DEFAULT_FS_BURST_CAP_SIZE (6 * 1024 + 33 * FS_USB_PKT_SIZE)
# define DEFAULT_BULK_IN_DELAY (0x00002000)
# define MAX_SINGLE_PACKET_SIZE (2048)
# define LAN95XX_EEPROM_MAGIC (0x9500)
# define EEPROM_MAC_OFFSET (0x01)
2008-11-20 04:19:21 -08:00
# define DEFAULT_TX_CSUM_ENABLE (true)
2008-10-02 05:27:57 +00:00
# define DEFAULT_RX_CSUM_ENABLE (true)
# define SMSC95XX_INTERNAL_PHY_ID (1)
# define SMSC95XX_TX_OVERHEAD (8)
2008-11-20 04:19:21 -08:00
# define SMSC95XX_TX_OVERHEAD_CSUM (12)
2012-11-22 08:05:24 +00:00
# define SUPPORTED_WAKE (WAKE_PHY | WAKE_UCAST | WAKE_BCAST | \
2012-10-26 03:43:56 +00:00
WAKE_MCAST | WAKE_ARP | WAKE_MAGIC )
2008-10-02 05:27:57 +00:00
2012-11-22 08:05:23 +00:00
# define FEATURE_8_WAKEUP_FILTERS (0x01)
# define FEATURE_PHY_NLP_CROSSOVER (0x02)
2013-02-22 03:05:05 +00:00
# define FEATURE_REMOTE_WAKEUP (0x04)
2012-11-22 08:05:23 +00:00
2013-01-03 03:00:16 +00:00
# define SUSPEND_SUSPEND0 (0x01)
# define SUSPEND_SUSPEND1 (0x02)
# define SUSPEND_SUSPEND2 (0x04)
# define SUSPEND_SUSPEND3 (0x08)
# define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3 )
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
# define SMSC95XX_NR_IRQS (1) /* raise to 12 for GPIOs */
# define PHY_HWIRQ (SMSC95XX_NR_IRQS - 1)
2008-10-02 05:27:57 +00:00
struct smsc95xx_priv {
u32 mac_cr ;
2011-03-18 03:53:58 +00:00
u32 hash_hi ;
u32 hash_lo ;
2012-09-28 00:07:12 +00:00
u32 wolopts ;
2008-10-02 05:27:57 +00:00
spinlock_t mac_cr_lock ;
2012-11-22 08:05:23 +00:00
u8 features ;
2013-01-03 03:00:16 +00:00
u8 suspend_flags ;
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
struct irq_chip irqchip ;
struct irq_domain * irqdomain ;
struct fwnode_handle * irqfwnode ;
2020-08-26 13:17:17 +02:00
struct mii_bus * mdiobus ;
struct phy_device * phydev ;
2022-07-01 22:47:51 +02:00
struct task_struct * pm_task ;
2008-10-02 05:27:57 +00:00
} ;
2011-12-19 14:08:01 +00:00
static bool turbo_mode = true ;
2008-10-02 05:27:57 +00:00
module_param ( turbo_mode , bool , 0644 ) ;
MODULE_PARM_DESC ( turbo_mode , " Enable multiple frames per Rx transaction " ) ;
2022-07-01 22:47:52 +02:00
static int __must_check smsc95xx_read_reg ( struct usbnet * dev , u32 index ,
u32 * data )
2008-10-02 05:27:57 +00:00
{
2022-07-01 22:47:51 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-10-24 19:47:04 +00:00
u32 buf ;
2008-10-02 05:27:57 +00:00
int ret ;
2012-11-06 04:53:07 +00:00
int ( * fn ) ( struct usbnet * , u8 , u8 , u16 , u16 , void * , u16 ) ;
2008-10-02 05:27:57 +00:00
2022-07-01 22:47:51 +02:00
if ( current ! = pdata - > pm_task )
2012-11-06 04:53:07 +00:00
fn = usbnet_read_cmd ;
else
fn = usbnet_read_cmd_nopm ;
ret = fn ( dev , USB_VENDOR_REQUEST_READ_REGISTER , USB_DIR_IN
| USB_TYPE_VENDOR | USB_RECIP_DEVICE ,
0 , index , & buf , 4 ) ;
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret < 0 ) {
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net , " Failed to read reg index 0x%08x: %d \n " ,
index , ret ) ;
2016-05-04 09:22:01 +03:00
return ret ;
}
2008-10-02 05:27:57 +00:00
2012-10-24 19:47:04 +00:00
le32_to_cpus ( & buf ) ;
* data = buf ;
2008-10-02 05:27:57 +00:00
return ret ;
}
2022-07-01 22:47:52 +02:00
static int __must_check smsc95xx_write_reg ( struct usbnet * dev , u32 index ,
u32 data )
2008-10-02 05:27:57 +00:00
{
2022-07-01 22:47:51 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-10-24 19:47:04 +00:00
u32 buf ;
2008-10-02 05:27:57 +00:00
int ret ;
2012-11-06 04:53:07 +00:00
int ( * fn ) ( struct usbnet * , u8 , u8 , u16 , u16 , const void * , u16 ) ;
2008-10-02 05:27:57 +00:00
2022-07-01 22:47:51 +02:00
if ( current ! = pdata - > pm_task )
2012-11-06 04:53:07 +00:00
fn = usbnet_write_cmd ;
else
fn = usbnet_write_cmd_nopm ;
2012-10-24 19:47:04 +00:00
buf = data ;
cpu_to_le32s ( & buf ) ;
2008-10-02 05:27:57 +00:00
2012-11-06 04:53:07 +00:00
ret = fn ( dev , USB_VENDOR_REQUEST_WRITE_REGISTER , USB_DIR_OUT
| USB_TYPE_VENDOR | USB_RECIP_DEVICE ,
0 , index , & buf , 4 ) ;
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret < 0 & & ret ! = - ENODEV )
2012-11-24 01:27:49 +00:00
netdev_warn ( dev - > net , " Failed to write reg index 0x%08x: %d \n " ,
index , ret ) ;
2008-10-02 05:27:57 +00:00
return ret ;
}
/* Loop until the read is completed with timeout
* called with phy_mutex held */
2022-07-01 22:47:52 +02:00
static int __must_check smsc95xx_phy_wait_not_busy ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
unsigned long start_time = jiffies ;
u32 val ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
do {
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , MII_ADDR , & val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
/* Ignore -ENODEV error during disconnect() */
if ( ret = = - ENODEV )
return 0 ;
2012-11-30 05:55:52 +00:00
netdev_warn ( dev - > net , " Error reading MII_ACCESS \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
if ( ! ( val & MII_BUSY_ ) )
return 0 ;
} while ( ! time_after ( jiffies , start_time + HZ ) ) ;
return - EIO ;
}
2020-08-26 13:17:17 +02:00
static u32 mii_address_cmd ( int phy_id , int idx , u16 op )
{
return ( phy_id & 0x1f ) < < 11 | ( idx & 0x1f ) < < 6 | op ;
}
2022-07-01 22:47:52 +02:00
static int smsc95xx_mdio_read ( struct usbnet * dev , int phy_id , int idx )
2008-10-02 05:27:57 +00:00
{
u32 val , addr ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
mutex_lock ( & dev - > phy_mutex ) ;
/* confirm MII not busy */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_phy_wait_not_busy ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
2020-08-26 13:17:17 +02:00
netdev_warn ( dev - > net , " %s: MII is busy \n " , __func__ ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
/* set the address, index & direction (read from PHY) */
2020-08-26 13:17:17 +02:00
addr = mii_address_cmd ( phy_id , idx , MII_READ_ | MII_BUSY_ ) ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , MII_ADDR , addr ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net , " Error writing MII_ADDR \n " ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_phy_wait_not_busy ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Timed out reading MII reg %02X \n " , idx ) ;
goto done ;
}
2008-10-02 05:27:57 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , MII_DATA , & val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net , " Error reading MII_DATA \n " ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:09 +00:00
ret = ( u16 ) ( val & 0xFFFF ) ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:09 +00:00
done :
mutex_unlock ( & dev - > phy_mutex ) ;
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
/* Ignore -ENODEV error during disconnect() */
if ( ret = = - ENODEV )
return 0 ;
2012-09-28 00:07:09 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
}
2022-07-01 22:47:52 +02:00
static void smsc95xx_mdio_write ( struct usbnet * dev , int phy_id , int idx ,
int regval )
2008-10-02 05:27:57 +00:00
{
u32 val , addr ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
mutex_lock ( & dev - > phy_mutex ) ;
/* confirm MII not busy */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_phy_wait_not_busy ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
2020-08-26 13:17:17 +02:00
netdev_warn ( dev - > net , " %s: MII is busy \n " , __func__ ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
val = regval ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , MII_DATA , val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net , " Error writing MII_DATA \n " ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
/* set the address, index & direction (write to PHY) */
2020-08-26 13:17:17 +02:00
addr = mii_address_cmd ( phy_id , idx , MII_WRITE_ | MII_BUSY_ ) ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , MII_ADDR , addr ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
smsc95xx: Ignore -ENODEV errors when device is unplugged
According to Documentation/driver-api/usb/URB.rst when a device
is unplugged usb_submit_urb() returns -ENODEV.
This error code propagates all the way up to usbnet_read_cmd() and
usbnet_write_cmd() calls inside the smsc95xx.c driver during
Ethernet cable unplug, unbind or reboot.
This causes the following errors to be shown on reboot, for example:
ci_hdrc ci_hdrc.1: remove, state 1
usb usb2: USB disconnect, device number 1
usb 2-1: USB disconnect, device number 2
usb 2-1.1: USB disconnect, device number 3
smsc95xx 2-1.1:1.0 eth1: unregister 'smsc95xx' usb-ci_hdrc.1-1.1, smsc95xx USB 2.0 Ethernet
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: Failed to read reg index 0x00000114: -19
smsc95xx 2-1.1:1.0 eth1: Error reading MII_ACCESS
smsc95xx 2-1.1:1.0 eth1: __smsc95xx_mdio_read: MII is busy
smsc95xx 2-1.1:1.0 eth1: hardware isn't capable of remote wakeup
usb 2-1.4: USB disconnect, device number 4
ci_hdrc ci_hdrc.1: USB bus 2 deregistered
ci_hdrc ci_hdrc.0: remove, state 4
usb usb1: USB disconnect, device number 1
ci_hdrc ci_hdrc.0: USB bus 1 deregistered
imx2-wdt 30280000.watchdog: Device shutdown: Expect reboot!
reboot: Restarting system
Ignore the -ENODEV errors inside __smsc95xx_mdio_read() and
__smsc95xx_phy_wait_not_busy() and do not print error messages
when -ENODEV is returned.
Fixes: a049a30fc27c ("net: usb: Correct PHY handling of smsc95xx")
Signed-off-by: Fabio Estevam <festevam@denx.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-05 17:47:20 -03:00
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net , " Error writing MII_ADDR \n " ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2008-10-02 05:27:57 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_phy_wait_not_busy ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Timed out writing MII reg %02X \n " , idx ) ;
goto done ;
}
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:09 +00:00
done :
2008-10-02 05:27:57 +00:00
mutex_unlock ( & dev - > phy_mutex ) ;
}
2020-08-26 13:17:17 +02:00
static int smsc95xx_mdiobus_read ( struct mii_bus * bus , int phy_id , int idx )
2012-11-22 08:05:24 +00:00
{
2020-08-26 13:17:17 +02:00
struct usbnet * dev = bus - > priv ;
2022-07-01 22:47:52 +02:00
return smsc95xx_mdio_read ( dev , phy_id , idx ) ;
2012-11-22 08:05:24 +00:00
}
2020-08-26 13:17:17 +02:00
static int smsc95xx_mdiobus_write ( struct mii_bus * bus , int phy_id , int idx ,
u16 regval )
2012-11-22 08:05:24 +00:00
{
2020-08-26 13:17:17 +02:00
struct usbnet * dev = bus - > priv ;
2022-07-01 22:47:52 +02:00
smsc95xx_mdio_write ( dev , phy_id , idx , regval ) ;
2020-08-26 13:17:17 +02:00
return 0 ;
2012-11-22 08:05:24 +00:00
}
2012-09-28 00:07:09 +00:00
static int __must_check smsc95xx_wait_eeprom ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
unsigned long start_time = jiffies ;
u32 val ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
do {
2012-09-28 00:07:09 +00:00
ret = smsc95xx_read_reg ( dev , E2P_CMD , & val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error reading E2P_CMD \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
if ( ! ( val & E2P_CMD_BUSY_ ) | | ( val & E2P_CMD_TIMEOUT_ ) )
break ;
udelay ( 40 ) ;
} while ( ! time_after ( jiffies , start_time + HZ ) ) ;
if ( val & ( E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_ ) ) {
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " EEPROM read operation timeout \n " ) ;
2008-10-02 05:27:57 +00:00
return - EIO ;
}
return 0 ;
}
2012-09-28 00:07:09 +00:00
static int __must_check smsc95xx_eeprom_confirm_not_busy ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
unsigned long start_time = jiffies ;
u32 val ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
do {
2012-09-28 00:07:09 +00:00
ret = smsc95xx_read_reg ( dev , E2P_CMD , & val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error reading E2P_CMD \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
if ( ! ( val & E2P_CMD_BUSY_ ) )
return 0 ;
udelay ( 40 ) ;
} while ( ! time_after ( jiffies , start_time + HZ ) ) ;
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " EEPROM is busy \n " ) ;
2008-10-02 05:27:57 +00:00
return - EIO ;
}
static int smsc95xx_read_eeprom ( struct usbnet * dev , u32 offset , u32 length ,
u8 * data )
{
u32 val ;
int i , ret ;
BUG_ON ( ! dev ) ;
BUG_ON ( ! data ) ;
ret = smsc95xx_eeprom_confirm_not_busy ( dev ) ;
if ( ret )
return ret ;
for ( i = 0 ; i < length ; i + + ) {
val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | ( offset & E2P_CMD_ADDR_ ) ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , E2P_CMD , val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error writing E2P_CMD \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
ret = smsc95xx_wait_eeprom ( dev ) ;
if ( ret < 0 )
return ret ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_read_reg ( dev , E2P_DATA , & val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error reading E2P_DATA \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
data [ i ] = val & 0xFF ;
offset + + ;
}
return 0 ;
}
static int smsc95xx_write_eeprom ( struct usbnet * dev , u32 offset , u32 length ,
u8 * data )
{
u32 val ;
int i , ret ;
BUG_ON ( ! dev ) ;
BUG_ON ( ! data ) ;
ret = smsc95xx_eeprom_confirm_not_busy ( dev ) ;
if ( ret )
return ret ;
/* Issue write/erase enable command */
val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_ ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , E2P_CMD , val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error writing E2P_DATA \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
ret = smsc95xx_wait_eeprom ( dev ) ;
if ( ret < 0 )
return ret ;
for ( i = 0 ; i < length ; i + + ) {
/* Fill data register */
val = data [ i ] ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , E2P_DATA , val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error writing E2P_DATA \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
/* Send "write" command */
val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | ( offset & E2P_CMD_ADDR_ ) ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , E2P_CMD , val ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Error writing E2P_CMD \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
ret = smsc95xx_wait_eeprom ( dev ) ;
if ( ret < 0 )
return ret ;
offset + + ;
}
return 0 ;
}
2012-09-28 00:07:09 +00:00
static int __must_check smsc95xx_write_reg_async ( struct usbnet * dev , u16 index ,
2012-12-10 01:03:08 +00:00
u32 data )
2008-10-02 05:27:57 +00:00
{
2008-10-09 14:34:47 -07:00
const u16 size = 4 ;
2012-12-10 01:03:08 +00:00
u32 buf ;
2012-10-24 19:47:04 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
2012-12-10 01:03:08 +00:00
buf = data ;
cpu_to_le32s ( & buf ) ;
2012-10-24 19:47:04 +00:00
ret = usbnet_write_cmd_async ( dev , USB_VENDOR_REQUEST_WRITE_REGISTER ,
USB_DIR_OUT | USB_TYPE_VENDOR |
USB_RECIP_DEVICE ,
2012-12-10 01:03:08 +00:00
0 , index , & buf , size ) ;
2012-10-24 19:47:04 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " Error write async cmd, sts=%d \n " ,
ret ) ;
return ret ;
2008-10-02 05:27:57 +00:00
}
/* returns hash bit number for given MAC address
* example :
* 01 00 5 E 00 00 01 - > returns bit number 31 */
static unsigned int smsc95xx_hash ( char addr [ ETH_ALEN ] )
{
return ( ether_crc ( ETH_ALEN , addr ) > > 26 ) & 0x3f ;
}
static void smsc95xx_set_multicast ( struct net_device * netdev )
{
struct usbnet * dev = netdev_priv ( netdev ) ;
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2008-10-02 05:27:57 +00:00
unsigned long flags ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
2011-03-18 03:53:58 +00:00
pdata - > hash_hi = 0 ;
pdata - > hash_lo = 0 ;
2008-10-02 05:27:57 +00:00
spin_lock_irqsave ( & pdata - > mac_cr_lock , flags ) ;
if ( dev - > net - > flags & IFF_PROMISC ) {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , drv , dev - > net , " promiscuous mode enabled \n " ) ;
2008-10-02 05:27:57 +00:00
pdata - > mac_cr | = MAC_CR_PRMS_ ;
pdata - > mac_cr & = ~ ( MAC_CR_MCPAS_ | MAC_CR_HPFILT_ ) ;
} else if ( dev - > net - > flags & IFF_ALLMULTI ) {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , drv , dev - > net , " receive all multicast enabled \n " ) ;
2008-10-02 05:27:57 +00:00
pdata - > mac_cr | = MAC_CR_MCPAS_ ;
pdata - > mac_cr & = ~ ( MAC_CR_PRMS_ | MAC_CR_HPFILT_ ) ;
2010-02-08 04:30:35 +00:00
} else if ( ! netdev_mc_empty ( dev - > net ) ) {
2010-04-01 21:22:57 +00:00
struct netdev_hw_addr * ha ;
2008-10-02 05:27:57 +00:00
pdata - > mac_cr | = MAC_CR_HPFILT_ ;
pdata - > mac_cr & = ~ ( MAC_CR_PRMS_ | MAC_CR_MCPAS_ ) ;
2010-04-01 21:22:57 +00:00
netdev_for_each_mc_addr ( ha , netdev ) {
u32 bitnum = smsc95xx_hash ( ha - > addr ) ;
2010-02-18 04:02:26 +00:00
u32 mask = 0x01 < < ( bitnum & 0x1F ) ;
if ( bitnum & 0x20 )
2011-03-18 03:53:58 +00:00
pdata - > hash_hi | = mask ;
2010-02-18 04:02:26 +00:00
else
2011-03-18 03:53:58 +00:00
pdata - > hash_lo | = mask ;
2008-10-02 05:27:57 +00:00
}
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , drv , dev - > net , " HASHH=0x%08X, HASHL=0x%08X \n " ,
2011-03-18 03:53:58 +00:00
pdata - > hash_hi , pdata - > hash_lo ) ;
2008-10-02 05:27:57 +00:00
} else {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , drv , dev - > net , " receive own packets only \n " ) ;
2008-10-02 05:27:57 +00:00
pdata - > mac_cr & =
~ ( MAC_CR_PRMS_ | MAC_CR_MCPAS_ | MAC_CR_HPFILT_ ) ;
}
spin_unlock_irqrestore ( & pdata - > mac_cr_lock , flags ) ;
/* Initiate async writes, as we can't wait for completion here */
2012-12-10 01:03:08 +00:00
ret = smsc95xx_write_reg_async ( dev , HASHH , pdata - > hash_hi ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " failed to initiate async write to HASHH \n " ) ;
2012-09-28 00:07:09 +00:00
2012-12-10 01:03:08 +00:00
ret = smsc95xx_write_reg_async ( dev , HASHL , pdata - > hash_lo ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " failed to initiate async write to HASHL \n " ) ;
2012-09-28 00:07:09 +00:00
2012-12-10 01:03:08 +00:00
ret = smsc95xx_write_reg_async ( dev , MAC_CR , pdata - > mac_cr ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " failed to initiate async write to MAC_CR \n " ) ;
2008-10-02 05:27:57 +00:00
}
2020-08-26 13:17:17 +02:00
static int smsc95xx_phy_update_flowcontrol ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
2017-09-11 17:43:11 +00:00
u32 flow = 0 , afc_cfg ;
2020-08-26 13:17:17 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
bool tx_pause , rx_pause ;
2008-10-02 05:27:57 +00:00
int ret = smsc95xx_read_reg ( dev , AFC_CFG , & afc_cfg ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2020-08-26 13:17:17 +02:00
if ( pdata - > phydev - > duplex = = DUPLEX_FULL ) {
phy_get_pause ( pdata - > phydev , & tx_pause , & rx_pause ) ;
2008-10-02 05:27:57 +00:00
2020-08-26 13:17:17 +02:00
if ( rx_pause )
2008-10-02 05:27:57 +00:00
flow = 0xFFFF0002 ;
2020-08-26 13:17:17 +02:00
if ( tx_pause ) {
2008-10-02 05:27:57 +00:00
afc_cfg | = 0xF ;
2017-09-11 17:43:11 +00:00
flow | = 0xFFFF0000 ;
} else {
2008-10-02 05:27:57 +00:00
afc_cfg & = ~ 0xF ;
2017-09-11 17:43:11 +00:00
}
2008-10-02 05:27:57 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , link , dev - > net , " rx pause %s, tx pause %s \n " ,
2020-08-26 13:17:17 +02:00
rx_pause ? " enabled " : " disabled " ,
tx_pause ? " enabled " : " disabled " ) ;
2008-10-02 05:27:57 +00:00
} else {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , link , dev - > net , " half duplex \n " ) ;
2008-10-02 05:27:57 +00:00
afc_cfg | = 0xF ;
}
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , FLOW , flow ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
2013-01-03 03:00:15 +00:00
return ret ;
2012-09-28 00:07:09 +00:00
2013-01-03 03:00:15 +00:00
return smsc95xx_write_reg ( dev , AFC_CFG , afc_cfg ) ;
2008-10-02 05:27:57 +00:00
}
2022-05-12 10:42:04 +02:00
static void smsc95xx_mac_update_fullduplex ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2008-10-02 05:27:57 +00:00
unsigned long flags ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
spin_lock_irqsave ( & pdata - > mac_cr_lock , flags ) ;
2020-08-26 13:17:17 +02:00
if ( pdata - > phydev - > duplex ! = DUPLEX_FULL ) {
2008-10-02 05:27:57 +00:00
pdata - > mac_cr & = ~ MAC_CR_FDPX_ ;
pdata - > mac_cr | = MAC_CR_RCVOWN_ ;
} else {
pdata - > mac_cr & = ~ MAC_CR_RCVOWN_ ;
pdata - > mac_cr | = MAC_CR_FDPX_ ;
}
spin_unlock_irqrestore ( & pdata - > mac_cr_lock , flags ) ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , MAC_CR , pdata - > mac_cr ) ;
2022-05-12 10:42:04 +02:00
if ( ret < 0 ) {
if ( ret ! = - ENODEV )
netdev_warn ( dev - > net ,
" Error updating MAC full duplex mode \n " ) ;
return ;
}
2008-10-02 05:27:57 +00:00
2020-08-26 13:17:17 +02:00
ret = smsc95xx_phy_update_flowcontrol ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " Error updating PHY flow control \n " ) ;
2008-10-02 05:27:57 +00:00
}
static void smsc95xx_status ( struct usbnet * dev , struct urb * urb )
{
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
unsigned long flags ;
2008-10-02 05:27:57 +00:00
u32 intdata ;
if ( urb - > actual_length ! = 4 ) {
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " unexpected urb length %d \n " ,
urb - > actual_length ) ;
2008-10-02 05:27:57 +00:00
return ;
}
2018-11-14 11:50:21 +00:00
intdata = get_unaligned_le32 ( urb - > transfer_buffer ) ;
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , link , dev - > net , " intdata: 0x%08X \n " , intdata ) ;
2008-10-02 05:27:57 +00:00
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
local_irq_save ( flags ) ;
2008-10-02 05:27:57 +00:00
if ( intdata & INT_ENP_PHY_INT_ )
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
generic_handle_domain_irq ( pdata - > irqdomain , PHY_HWIRQ ) ;
2008-10-02 05:27:57 +00:00
else
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " unexpected interrupt, intdata=0x%08X \n " ,
intdata ) ;
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
local_irq_restore ( flags ) ;
2008-10-02 05:27:57 +00:00
}
2008-11-20 04:19:21 -08:00
/* Enable or disable Tx & Rx checksum offload engines */
2011-11-15 15:29:55 +00:00
static int smsc95xx_set_features ( struct net_device * netdev ,
netdev_features_t features )
2008-10-02 05:27:57 +00:00
{
2011-04-01 20:56:23 -07:00
struct usbnet * dev = netdev_priv ( netdev ) ;
2008-10-02 05:27:57 +00:00
u32 read_buf ;
2011-04-01 20:56:23 -07:00
int ret ;
ret = smsc95xx_read_reg ( dev , COE_CR , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2017-05-19 14:00:25 +00:00
if ( features & NETIF_F_IP_CSUM )
2008-11-20 04:19:21 -08:00
read_buf | = Tx_COE_EN_ ;
else
read_buf & = ~ Tx_COE_EN_ ;
2011-04-01 20:56:23 -07:00
if ( features & NETIF_F_RXCSUM )
2008-10-02 05:27:57 +00:00
read_buf | = Rx_COE_EN_ ;
else
read_buf & = ~ Rx_COE_EN_ ;
ret = smsc95xx_write_reg ( dev , COE_CR , read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , hw , dev - > net , " COE_CR = 0x%08x \n " , read_buf ) ;
2008-10-02 05:27:57 +00:00
return 0 ;
}
static int smsc95xx_ethtool_get_eeprom_len ( struct net_device * net )
{
return MAX_EEPROM_SIZE ;
}
static int smsc95xx_ethtool_get_eeprom ( struct net_device * netdev ,
struct ethtool_eeprom * ee , u8 * data )
{
struct usbnet * dev = netdev_priv ( netdev ) ;
ee - > magic = LAN95XX_EEPROM_MAGIC ;
return smsc95xx_read_eeprom ( dev , ee - > offset , ee - > len , data ) ;
}
static int smsc95xx_ethtool_set_eeprom ( struct net_device * netdev ,
struct ethtool_eeprom * ee , u8 * data )
{
struct usbnet * dev = netdev_priv ( netdev ) ;
if ( ee - > magic ! = LAN95XX_EEPROM_MAGIC ) {
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " EEPROM: magic value mismatch, magic = 0x%x \n " ,
ee - > magic ) ;
2008-10-02 05:27:57 +00:00
return - EINVAL ;
}
return smsc95xx_write_eeprom ( dev , ee - > offset , ee - > len , data ) ;
}
2012-07-09 17:44:45 -04:00
static int smsc95xx_ethtool_getregslen ( struct net_device * netdev )
{
/* all smsc95xx registers */
2012-12-10 01:03:07 +00:00
return COE_CR - ID_REV + sizeof ( u32 ) ;
2012-07-09 17:44:45 -04:00
}
static void
smsc95xx_ethtool_getregs ( struct net_device * netdev , struct ethtool_regs * regs ,
void * buf )
{
struct usbnet * dev = netdev_priv ( netdev ) ;
2012-07-10 20:32:51 +00:00
unsigned int i , j ;
int retval ;
2012-07-09 17:44:45 -04:00
u32 * data = buf ;
retval = smsc95xx_read_reg ( dev , ID_REV , & regs - > version ) ;
if ( retval < 0 ) {
netdev_warn ( netdev , " REGS: cannot read ID_REV \n " ) ;
return ;
}
for ( i = ID_REV , j = 0 ; i < = COE_CR ; i + = ( sizeof ( u32 ) ) , j + + ) {
retval = smsc95xx_read_reg ( dev , i , & data [ j ] ) ;
if ( retval < 0 ) {
netdev_warn ( netdev , " REGS: cannot read reg[%x] \n " , i ) ;
return ;
}
}
}
2012-09-28 00:07:12 +00:00
static void smsc95xx_ethtool_get_wol ( struct net_device * net ,
struct ethtool_wolinfo * wolinfo )
{
struct usbnet * dev = netdev_priv ( net ) ;
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-09-28 00:07:12 +00:00
wolinfo - > supported = SUPPORTED_WAKE ;
wolinfo - > wolopts = pdata - > wolopts ;
}
static int smsc95xx_ethtool_set_wol ( struct net_device * net ,
struct ethtool_wolinfo * wolinfo )
{
struct usbnet * dev = netdev_priv ( net ) ;
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-11-30 05:55:50 +00:00
int ret ;
2012-09-28 00:07:12 +00:00
2018-09-28 16:18:56 -07:00
if ( wolinfo - > wolopts & ~ SUPPORTED_WAKE )
return - EINVAL ;
2012-09-28 00:07:12 +00:00
pdata - > wolopts = wolinfo - > wolopts & SUPPORTED_WAKE ;
2012-11-30 05:55:50 +00:00
ret = device_set_wakeup_enable ( & dev - > udev - > dev , pdata - > wolopts ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " device_set_wakeup_enable error %d \n " , ret ) ;
2012-11-30 05:55:50 +00:00
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:12 +00:00
}
2020-08-26 13:17:17 +02:00
static u32 smsc95xx_get_link ( struct net_device * net )
2016-09-02 20:34:22 +00:00
{
2020-08-26 13:17:17 +02:00
phy_read_status ( net - > phydev ) ;
return net - > phydev - > link ;
2016-09-02 20:34:22 +00:00
}
2022-02-09 13:42:55 +01:00
static void smsc95xx_ethtool_get_strings ( struct net_device * netdev , u32 sset ,
u8 * data )
{
switch ( sset ) {
case ETH_SS_TEST :
net_selftest_get_strings ( data ) ;
break ;
}
}
static int smsc95xx_ethtool_get_sset_count ( struct net_device * ndev , int sset )
{
switch ( sset ) {
case ETH_SS_TEST :
return net_selftest_get_count ( ) ;
default :
return - EOPNOTSUPP ;
}
}
2009-09-02 01:03:33 -07:00
static const struct ethtool_ops smsc95xx_ethtool_ops = {
2020-08-26 13:17:17 +02:00
. get_link = smsc95xx_get_link ,
. nway_reset = phy_ethtool_nway_reset ,
2008-10-02 05:27:57 +00:00
. get_drvinfo = usbnet_get_drvinfo ,
. get_msglevel = usbnet_get_msglevel ,
. set_msglevel = usbnet_set_msglevel ,
. get_eeprom_len = smsc95xx_ethtool_get_eeprom_len ,
. get_eeprom = smsc95xx_ethtool_get_eeprom ,
. set_eeprom = smsc95xx_ethtool_set_eeprom ,
2012-07-09 17:44:45 -04:00
. get_regs_len = smsc95xx_ethtool_getregslen ,
. get_regs = smsc95xx_ethtool_getregs ,
2012-09-28 00:07:12 +00:00
. get_wol = smsc95xx_ethtool_get_wol ,
. set_wol = smsc95xx_ethtool_set_wol ,
2020-08-26 13:17:17 +02:00
. get_link_ksettings = phy_ethtool_get_link_ksettings ,
. set_link_ksettings = phy_ethtool_set_link_ksettings ,
2017-07-13 19:40:57 +02:00
. get_ts_info = ethtool_op_get_ts_info ,
2022-02-09 13:42:55 +01:00
. self_test = net_selftest ,
. get_strings = smsc95xx_ethtool_get_strings ,
. get_sset_count = smsc95xx_ethtool_get_sset_count ,
2008-10-02 05:27:57 +00:00
} ;
static int smsc95xx_ioctl ( struct net_device * netdev , struct ifreq * rq , int cmd )
{
if ( ! netif_running ( netdev ) )
return - EINVAL ;
2020-08-26 13:17:17 +02:00
return phy_mii_ioctl ( netdev - > phydev , rq , cmd ) ;
2008-10-02 05:27:57 +00:00
}
static void smsc95xx_init_mac_address ( struct usbnet * dev )
{
2021-10-21 06:12:04 -07:00
u8 addr [ ETH_ALEN ] ;
2016-04-29 09:05:59 +02:00
/* maybe the boot loader passed the MAC address in devicetree */
2021-10-07 11:18:47 -07:00
if ( ! platform_get_ethdev_address ( & dev - > udev - > dev , dev - > net ) ) {
2020-09-30 16:25:25 +02:00
if ( is_valid_ether_addr ( dev - > net - > dev_addr ) ) {
/* device tree values are valid so use them */
netif_dbg ( dev , ifup , dev - > net , " MAC address read from the device tree \n " ) ;
return ;
}
2016-04-29 09:05:59 +02:00
}
2008-10-02 05:27:57 +00:00
/* try reading mac address from EEPROM */
2021-10-21 06:12:04 -07:00
if ( smsc95xx_read_eeprom ( dev , EEPROM_MAC_OFFSET , ETH_ALEN , addr ) = = 0 ) {
eth_hw_addr_set ( dev - > net , addr ) ;
2008-10-02 05:27:57 +00:00
if ( is_valid_ether_addr ( dev - > net - > dev_addr ) ) {
/* eeprom values are valid so use them */
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net , " MAC address read from EEPROM \n " ) ;
2008-10-02 05:27:57 +00:00
return ;
}
}
2016-04-29 09:05:59 +02:00
/* no useful static MAC address found. generate a random one */
2012-02-15 06:45:39 +00:00
eth_hw_addr_random ( dev - > net ) ;
2012-07-12 19:33:07 +00:00
netif_dbg ( dev , ifup , dev - > net , " MAC address set to eth_random_addr \n " ) ;
2008-10-02 05:27:57 +00:00
}
static int smsc95xx_set_mac_address ( struct usbnet * dev )
{
u32 addr_lo = dev - > net - > dev_addr [ 0 ] | dev - > net - > dev_addr [ 1 ] < < 8 |
dev - > net - > dev_addr [ 2 ] < < 16 | dev - > net - > dev_addr [ 3 ] < < 24 ;
u32 addr_hi = dev - > net - > dev_addr [ 4 ] | dev - > net - > dev_addr [ 5 ] < < 8 ;
int ret ;
ret = smsc95xx_write_reg ( dev , ADDRL , addr_lo ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
2013-01-03 03:00:15 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2013-01-03 03:00:15 +00:00
return smsc95xx_write_reg ( dev , ADDRH , addr_hi ) ;
2008-10-02 05:27:57 +00:00
}
/* starts the TX path */
2012-09-28 00:07:09 +00:00
static int smsc95xx_start_tx_path ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2008-10-02 05:27:57 +00:00
unsigned long flags ;
2012-09-28 00:07:09 +00:00
int ret ;
2008-10-02 05:27:57 +00:00
/* Enable Tx at MAC */
spin_lock_irqsave ( & pdata - > mac_cr_lock , flags ) ;
pdata - > mac_cr | = MAC_CR_TXEN_ ;
spin_unlock_irqrestore ( & pdata - > mac_cr_lock , flags ) ;
2012-09-28 00:07:09 +00:00
ret = smsc95xx_write_reg ( dev , MAC_CR , pdata - > mac_cr ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
/* Enable Tx at SCSRs */
2013-01-03 03:00:15 +00:00
return smsc95xx_write_reg ( dev , TX_CFG , TX_CFG_ON_ ) ;
2008-10-02 05:27:57 +00:00
}
/* Starts the Receive path */
2022-07-01 22:47:52 +02:00
static int smsc95xx_start_rx_path ( struct usbnet * dev )
2008-10-02 05:27:57 +00:00
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2008-10-02 05:27:57 +00:00
unsigned long flags ;
spin_lock_irqsave ( & pdata - > mac_cr_lock , flags ) ;
pdata - > mac_cr | = MAC_CR_RXEN_ ;
spin_unlock_irqrestore ( & pdata - > mac_cr_lock , flags ) ;
2022-07-01 22:47:52 +02:00
return smsc95xx_write_reg ( dev , MAC_CR , pdata - > mac_cr ) ;
2008-10-02 05:27:57 +00:00
}
static int smsc95xx_reset ( struct usbnet * dev )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2008-10-02 05:27:57 +00:00
u32 read_buf , write_buf , burst_cap ;
int ret = 0 , timeout ;
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net , " entering smsc95xx_reset \n " ) ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , HW_CFG , HW_CFG_LRST_ ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
timeout = 0 ;
do {
2012-09-28 00:07:07 +00:00
msleep ( 10 ) ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , HW_CFG , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
timeout + + ;
} while ( ( read_buf & HW_CFG_LRST_ ) & & ( timeout < 100 ) ) ;
if ( timeout > = 100 ) {
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " timeout waiting for completion of Lite Reset \n " ) ;
2008-10-02 05:27:57 +00:00
return ret ;
}
ret = smsc95xx_set_mac_address ( dev ) ;
if ( ret < 0 )
return ret ;
2012-11-24 01:27:49 +00:00
netif_dbg ( dev , ifup , dev - > net , " MAC Address: %pM \n " ,
dev - > net - > dev_addr ) ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , HW_CFG , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2012-11-24 01:27:49 +00:00
netif_dbg ( dev , ifup , dev - > net , " Read Value from HW_CFG : 0x%08x \n " ,
read_buf ) ;
2008-10-02 05:27:57 +00:00
read_buf | = HW_CFG_BIR_ ;
ret = smsc95xx_write_reg ( dev , HW_CFG , read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , HW_CFG , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net ,
" Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x \n " ,
read_buf ) ;
2008-10-02 05:27:57 +00:00
if ( ! turbo_mode ) {
burst_cap = 0 ;
dev - > rx_urb_size = MAX_SINGLE_PACKET_SIZE ;
} else if ( dev - > udev - > speed = = USB_SPEED_HIGH ) {
burst_cap = DEFAULT_HS_BURST_CAP_SIZE / HS_USB_PKT_SIZE ;
dev - > rx_urb_size = DEFAULT_HS_BURST_CAP_SIZE ;
} else {
burst_cap = DEFAULT_FS_BURST_CAP_SIZE / FS_USB_PKT_SIZE ;
dev - > rx_urb_size = DEFAULT_FS_BURST_CAP_SIZE ;
}
2012-11-24 01:27:49 +00:00
netif_dbg ( dev , ifup , dev - > net , " rx_urb_size=%ld \n " ,
( ulong ) dev - > rx_urb_size ) ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_write_reg ( dev , BURST_CAP , burst_cap ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , BURST_CAP , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:09 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net ,
" Read Value from BURST_CAP after writing: 0x%08x \n " ,
read_buf ) ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , BULK_IN_DLY , DEFAULT_BULK_IN_DELAY ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , BULK_IN_DLY , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:09 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net ,
" Read Value from BULK_IN_DLY after writing: 0x%08x \n " ,
read_buf ) ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , HW_CFG , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:09 +00:00
2012-11-24 01:27:49 +00:00
netif_dbg ( dev , ifup , dev - > net , " Read Value from HW_CFG: 0x%08x \n " ,
read_buf ) ;
2008-10-02 05:27:57 +00:00
if ( turbo_mode )
read_buf | = ( HW_CFG_MEF_ | HW_CFG_BCE_ ) ;
read_buf & = ~ HW_CFG_RXDOFF_ ;
/* set Rx data offset=2, Make IP header aligns on word boundary. */
read_buf | = NET_IP_ALIGN < < 9 ;
ret = smsc95xx_write_reg ( dev , HW_CFG , read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , HW_CFG , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:09 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net ,
" Read Value from HW_CFG after writing: 0x%08x \n " , read_buf ) ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , INT_STS , INT_STS_CLEAR_ALL_ ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
ret = smsc95xx_read_reg ( dev , ID_REV , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net , " ID_REV = 0x%08x \n " , read_buf ) ;
2008-10-02 05:27:57 +00:00
2009-05-01 05:46:51 +00:00
/* Configure GPIO pins as LED outputs */
write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
LED_GPIO_CFG_FDX_LED ;
ret = smsc95xx_write_reg ( dev , LED_GPIO_CFG , write_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2009-05-01 05:46:51 +00:00
2008-10-02 05:27:57 +00:00
/* Init Tx */
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , FLOW , 0 ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , AFC_CFG , AFC_CFG_DEFAULT ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
/* Don't need mac_cr_lock during initialisation */
ret = smsc95xx_read_reg ( dev , MAC_CR , & pdata - > mac_cr ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
/* Init Rx */
/* Set Vlan */
2012-09-28 00:07:08 +00:00
ret = smsc95xx_write_reg ( dev , VLAN1 , ( u32 ) ETH_P_8021Q ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2008-11-20 04:19:21 -08:00
/* Enable or disable checksum offload engines */
2012-09-28 00:07:09 +00:00
ret = smsc95xx_set_features ( dev - > net , dev - > net - > features ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Failed to set checksum offload features \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
smsc95xx_set_multicast ( dev - > net ) ;
ret = smsc95xx_read_reg ( dev , INT_EP_CTL , & read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
/* enable PHY interrupts */
read_buf | = INT_EP_CTL_PHY_INT_ ;
ret = smsc95xx_write_reg ( dev , INT_EP_CTL , read_buf ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2008-10-02 05:27:57 +00:00
2012-09-28 00:07:09 +00:00
ret = smsc95xx_start_tx_path ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Failed to start TX path \n " ) ;
return ret ;
}
2012-09-28 00:07:09 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_start_rx_path ( dev ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " Failed to start RX path \n " ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , ifup , dev - > net , " smsc95xx_reset, return 0 \n " ) ;
2008-10-02 05:27:57 +00:00
return 0 ;
}
2009-03-20 19:35:58 +00:00
static const struct net_device_ops smsc95xx_netdev_ops = {
. ndo_open = usbnet_open ,
. ndo_stop = usbnet_stop ,
. ndo_start_xmit = usbnet_start_xmit ,
. ndo_tx_timeout = usbnet_tx_timeout ,
. ndo_change_mtu = usbnet_change_mtu ,
2020-11-10 20:51:03 +01:00
. ndo_get_stats64 = dev_get_tstats64 ,
2009-03-20 19:35:58 +00:00
. ndo_set_mac_address = eth_mac_addr ,
. ndo_validate_addr = eth_validate_addr ,
2021-07-27 15:45:13 +02:00
. ndo_eth_ioctl = smsc95xx_ioctl ,
2011-08-16 06:29:01 +00:00
. ndo_set_rx_mode = smsc95xx_set_multicast ,
2011-04-01 20:56:23 -07:00
. ndo_set_features = smsc95xx_set_features ,
2009-03-20 19:35:58 +00:00
} ;
2021-11-22 18:44:45 +00:00
static void smsc95xx_handle_link_change ( struct net_device * net )
{
struct usbnet * dev = netdev_priv ( net ) ;
phy_print_status ( net - > phydev ) ;
2022-05-12 10:42:04 +02:00
smsc95xx_mac_update_fullduplex ( dev ) ;
2021-11-22 18:44:45 +00:00
usbnet_defer_kevent ( dev , EVENT_LINK_CHANGE ) ;
}
2008-10-02 05:27:57 +00:00
static int smsc95xx_bind ( struct usbnet * dev , struct usb_interface * intf )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata ;
2020-08-26 13:17:17 +02:00
bool is_internal_phy ;
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
char usb_path [ 64 ] ;
int ret , phy_irq ;
2012-10-26 03:43:56 +00:00
u32 val ;
2008-10-02 05:27:57 +00:00
printk ( KERN_INFO SMSC_CHIPNAME " v " SMSC_DRIVER_VERSION " \n " ) ;
ret = usbnet_get_endpoints ( dev , intf ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " usbnet_get_endpoints failed: %d \n " , ret ) ;
return ret ;
}
2008-10-02 05:27:57 +00:00
2020-08-26 13:17:16 +02:00
pdata = kzalloc ( sizeof ( * pdata ) , GFP_KERNEL ) ;
2013-02-03 17:28:11 +00:00
if ( ! pdata )
2008-10-02 05:27:57 +00:00
return - ENOMEM ;
2020-08-26 13:17:16 +02:00
dev - > driver_priv = pdata ;
2008-10-02 05:27:57 +00:00
spin_lock_init ( & pdata - > mac_cr_lock ) ;
2017-05-19 14:00:25 +00:00
/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
* RFC 2460 , ipv6 UDP calculated checksum yields a result of zero must
* be changed to 0xffff . RFC 768 , ipv4 UDP computed checksum is zero ,
* it is transmitted as all ones . The zero transmitted checksum means
* transmitter generated no checksum . Hence , enable csum offload only
* for ipv4 packets .
*/
2011-04-01 20:56:23 -07:00
if ( DEFAULT_TX_CSUM_ENABLE )
2017-05-19 14:00:25 +00:00
dev - > net - > features | = NETIF_F_IP_CSUM ;
2011-04-01 20:56:23 -07:00
if ( DEFAULT_RX_CSUM_ENABLE )
dev - > net - > features | = NETIF_F_RXCSUM ;
2017-05-19 14:00:25 +00:00
dev - > net - > hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM ;
2018-11-14 11:50:19 +00:00
set_bit ( EVENT_NO_IP_ALIGN , & dev - > flags ) ;
2008-10-02 05:27:57 +00:00
2010-10-18 13:16:39 +00:00
smsc95xx_init_mac_address ( dev ) ;
2008-10-02 05:27:57 +00:00
/* Init all registers */
ret = smsc95xx_reset ( dev ) ;
2020-07-06 10:39:34 +02:00
if ( ret )
goto free_pdata ;
2008-10-02 05:27:57 +00:00
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
/* create irq domain for use by PHY driver and GPIO consumers */
usb_make_path ( dev - > udev , usb_path , sizeof ( usb_path ) ) ;
pdata - > irqfwnode = irq_domain_alloc_named_fwnode ( usb_path ) ;
if ( ! pdata - > irqfwnode ) {
ret = - ENOMEM ;
goto free_pdata ;
}
pdata - > irqdomain = irq_domain_create_linear ( pdata - > irqfwnode ,
SMSC95XX_NR_IRQS ,
& irq_domain_simple_ops ,
pdata ) ;
if ( ! pdata - > irqdomain ) {
ret = - ENOMEM ;
goto free_irqfwnode ;
}
phy_irq = irq_create_mapping ( pdata - > irqdomain , PHY_HWIRQ ) ;
if ( ! phy_irq ) {
ret = - ENOENT ;
goto remove_irqdomain ;
}
pdata - > irqchip = dummy_irq_chip ;
pdata - > irqchip . name = SMSC_CHIPNAME ;
irq_set_chip_and_handler_name ( phy_irq , & pdata - > irqchip ,
handle_simple_irq , " phy " ) ;
2020-08-26 13:17:17 +02:00
pdata - > mdiobus = mdiobus_alloc ( ) ;
if ( ! pdata - > mdiobus ) {
ret = - ENOMEM ;
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
goto dispose_irq ;
2020-08-26 13:17:17 +02:00
}
ret = smsc95xx_read_reg ( dev , HW_CFG , & val ) ;
if ( ret < 0 )
goto free_mdio ;
is_internal_phy = ! ( val & HW_CFG_PSEL_ ) ;
if ( is_internal_phy )
pdata - > mdiobus - > phy_mask = ~ ( 1u < < SMSC95XX_INTERNAL_PHY_ID ) ;
pdata - > mdiobus - > priv = dev ;
pdata - > mdiobus - > read = smsc95xx_mdiobus_read ;
pdata - > mdiobus - > write = smsc95xx_mdiobus_write ;
pdata - > mdiobus - > name = " smsc95xx-mdiobus " ;
pdata - > mdiobus - > parent = & dev - > udev - > dev ;
snprintf ( pdata - > mdiobus - > id , ARRAY_SIZE ( pdata - > mdiobus - > id ) ,
" usb-%03d:%03d " , dev - > udev - > bus - > busnum , dev - > udev - > devnum ) ;
ret = mdiobus_register ( pdata - > mdiobus ) ;
if ( ret ) {
netdev_err ( dev - > net , " Could not register MDIO bus \n " ) ;
goto free_mdio ;
}
pdata - > phydev = phy_find_first ( pdata - > mdiobus ) ;
if ( ! pdata - > phydev ) {
netdev_err ( dev - > net , " no PHY found \n " ) ;
ret = - ENODEV ;
goto unregister_mdio ;
}
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
pdata - > phydev - > irq = phy_irq ;
2020-08-26 13:17:17 +02:00
pdata - > phydev - > is_internal = is_internal_phy ;
2012-10-26 03:43:56 +00:00
/* detect device revision as different features may be available */
ret = smsc95xx_read_reg ( dev , ID_REV , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2020-08-26 13:17:17 +02:00
goto unregister_mdio ;
2020-07-06 10:39:35 +02:00
2012-10-26 03:43:56 +00:00
val > > = 16 ;
2012-11-22 08:05:23 +00:00
if ( ( val = = ID_REV_CHIP_ID_9500A_ ) | | ( val = = ID_REV_CHIP_ID_9530_ ) | |
( val = = ID_REV_CHIP_ID_89530_ ) | | ( val = = ID_REV_CHIP_ID_9730_ ) )
pdata - > features = ( FEATURE_8_WAKEUP_FILTERS |
FEATURE_PHY_NLP_CROSSOVER |
2013-02-22 03:05:05 +00:00
FEATURE_REMOTE_WAKEUP ) ;
2012-11-22 08:05:23 +00:00
else if ( val = = ID_REV_CHIP_ID_9512_ )
pdata - > features = FEATURE_8_WAKEUP_FILTERS ;
2012-10-26 03:43:56 +00:00
2009-03-20 19:35:58 +00:00
dev - > net - > netdev_ops = & smsc95xx_netdev_ops ;
2008-10-02 05:27:57 +00:00
dev - > net - > ethtool_ops = & smsc95xx_ethtool_ops ;
dev - > net - > flags | = IFF_MULTICAST ;
2011-04-01 20:56:23 -07:00
dev - > net - > hard_header_len + = SMSC95XX_TX_OVERHEAD_CSUM ;
2018-11-08 20:38:26 +01:00
dev - > net - > min_mtu = ETH_MIN_MTU ;
dev - > net - > max_mtu = ETH_DATA_LEN ;
2012-04-20 09:39:23 +00:00
dev - > hard_mtu = dev - > net - > mtu + dev - > net - > hard_header_len ;
2021-11-22 18:44:45 +00:00
ret = phy_connect_direct ( dev - > net , pdata - > phydev ,
& smsc95xx_handle_link_change ,
PHY_INTERFACE_MODE_MII ) ;
if ( ret ) {
netdev_err ( dev - > net , " can't attach PHY to %s \n " , pdata - > mdiobus - > id ) ;
goto unregister_mdio ;
}
phy_attached_info ( dev - > net - > phydev ) ;
2020-08-26 13:17:17 +02:00
return 0 ;
2016-05-26 04:06:47 +02:00
2020-08-26 13:17:17 +02:00
unregister_mdio :
mdiobus_unregister ( pdata - > mdiobus ) ;
2016-05-26 04:06:47 +02:00
2020-08-26 13:17:17 +02:00
free_mdio :
mdiobus_free ( pdata - > mdiobus ) ;
2020-07-06 10:39:34 +02:00
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
dispose_irq :
irq_dispose_mapping ( phy_irq ) ;
remove_irqdomain :
irq_domain_remove ( pdata - > irqdomain ) ;
free_irqfwnode :
irq_domain_free_fwnode ( pdata - > irqfwnode ) ;
2020-07-06 10:39:34 +02:00
free_pdata :
kfree ( pdata ) ;
return ret ;
2008-10-02 05:27:57 +00:00
}
static void smsc95xx_unbind ( struct usbnet * dev , struct usb_interface * intf )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2021-11-22 18:44:45 +00:00
phy_disconnect ( dev - > net - > phydev ) ;
2020-08-26 13:17:17 +02:00
mdiobus_unregister ( pdata - > mdiobus ) ;
mdiobus_free ( pdata - > mdiobus ) ;
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
irq_dispose_mapping ( irq_find_mapping ( pdata - > irqdomain , PHY_HWIRQ ) ) ;
irq_domain_remove ( pdata - > irqdomain ) ;
irq_domain_free_fwnode ( pdata - > irqfwnode ) ;
2020-08-26 13:17:16 +02:00
netif_dbg ( dev , ifdown , dev - > net , " free pdata \n " ) ;
kfree ( pdata ) ;
2008-10-02 05:27:57 +00:00
}
2020-08-26 13:17:17 +02:00
static int smsc95xx_start_phy ( struct usbnet * dev )
{
2021-11-22 18:44:45 +00:00
phy_start ( dev - > net - > phydev ) ;
2020-08-26 13:17:17 +02:00
return 0 ;
}
2021-11-22 18:44:45 +00:00
static int smsc95xx_stop ( struct usbnet * dev )
2020-08-26 13:17:17 +02:00
{
2022-05-12 10:42:01 +02:00
phy_stop ( dev - > net - > phydev ) ;
2021-11-22 18:44:45 +00:00
2020-08-26 13:17:17 +02:00
return 0 ;
}
2012-11-30 05:55:51 +00:00
static u32 smsc_crc ( const u8 * buffer , size_t len , int filter )
2012-10-26 03:43:56 +00:00
{
2012-11-30 05:55:51 +00:00
u32 crc = bitrev16 ( crc16 ( 0xFFFF , buffer , len ) ) ;
return crc < < ( ( filter % 2 ) * 16 ) ;
2012-10-26 03:43:56 +00:00
}
2022-07-01 22:47:52 +02:00
static int smsc95xx_link_ok ( struct usbnet * dev )
2012-11-22 08:05:24 +00:00
{
2022-07-01 22:47:52 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-11-22 08:05:24 +00:00
int ret ;
/* first, a dummy read, needed to latch some MII phys */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_mdio_read ( dev , pdata - > phydev - > mdio . addr , MII_BMSR ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:24 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_mdio_read ( dev , pdata - > phydev - > mdio . addr , MII_BMSR ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:24 +00:00
return ! ! ( ret & BMSR_LSTATUS ) ;
}
2012-11-22 08:05:25 +00:00
static int smsc95xx_enter_suspend0 ( struct usbnet * dev )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-11-22 08:05:25 +00:00
u32 val ;
int ret ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
val & = ( ~ ( PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_ ) ) ;
val | = PM_CTL_SUS_MODE_0 ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
/* clear wol status */
val & = ~ PM_CTL_WUPS_ ;
val | = PM_CTL_WUPS_WOL_ ;
/* enable energy detection */
if ( pdata - > wolopts & WAKE_PHY )
val | = PM_CTL_WUPS_ED_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
/* read back PM_CTRL */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-02-22 03:05:03 +00:00
if ( ret < 0 )
return ret ;
2012-11-22 08:05:25 +00:00
2013-01-03 03:00:16 +00:00
pdata - > suspend_flags | = SUSPEND_SUSPEND0 ;
2013-02-22 03:05:03 +00:00
return 0 ;
2012-11-22 08:05:25 +00:00
}
static int smsc95xx_enter_suspend1 ( struct usbnet * dev )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2022-07-01 22:47:52 +02:00
int ret , phy_id = pdata - > phydev - > mdio . addr ;
2012-11-22 08:05:25 +00:00
u32 val ;
/* reconfigure link pulse detection timing for
* compatibility with non - standard link partners
*/
if ( pdata - > features & FEATURE_PHY_NLP_CROSSOVER )
2022-07-01 22:47:52 +02:00
smsc95xx_mdio_write ( dev , phy_id , PHY_EDPD_CONFIG ,
PHY_EDPD_CONFIG_DEFAULT ) ;
2012-11-22 08:05:25 +00:00
/* enable energy detect power-down mode */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_mdio_read ( dev , phy_id , PHY_MODE_CTRL_STS ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
ret | = MODE_CTRL_STS_EDPWRDOWN_ ;
2022-07-01 22:47:52 +02:00
smsc95xx_mdio_write ( dev , phy_id , PHY_MODE_CTRL_STS , ret ) ;
2012-11-22 08:05:25 +00:00
/* enter SUSPEND1 mode */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
val & = ~ ( PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_ ) ;
val | = PM_CTL_SUS_MODE_1 ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
/* clear wol status, enable energy detection */
val & = ~ PM_CTL_WUPS_ ;
val | = ( PM_CTL_WUPS_ED_ | PM_CTL_ED_EN_ ) ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-02-22 03:05:03 +00:00
if ( ret < 0 )
return ret ;
2012-11-22 08:05:25 +00:00
2013-01-03 03:00:16 +00:00
pdata - > suspend_flags | = SUSPEND_SUSPEND1 ;
2013-02-22 03:05:03 +00:00
return 0 ;
2012-11-22 08:05:25 +00:00
}
static int smsc95xx_enter_suspend2 ( struct usbnet * dev )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-11-22 08:05:25 +00:00
u32 val ;
int ret ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
return ret ;
2012-11-22 08:05:25 +00:00
val & = ~ ( PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_ ) ;
val | = PM_CTL_SUS_MODE_2 ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-02-22 03:05:03 +00:00
if ( ret < 0 )
return ret ;
2012-11-22 08:05:25 +00:00
2013-01-03 03:00:16 +00:00
pdata - > suspend_flags | = SUSPEND_SUSPEND2 ;
2013-02-22 03:05:03 +00:00
return 0 ;
2012-11-22 08:05:25 +00:00
}
2013-01-03 03:00:16 +00:00
static int smsc95xx_enter_suspend3 ( struct usbnet * dev )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2013-01-03 03:00:16 +00:00
u32 val ;
int ret ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , RX_FIFO_INF , & val ) ;
2013-01-03 03:00:16 +00:00
if ( ret < 0 )
return ret ;
2017-04-13 10:08:44 +02:00
if ( val & RX_FIFO_INF_USED_ ) {
2013-01-03 03:00:16 +00:00
netdev_info ( dev - > net , " rx fifo not empty in autosuspend \n " ) ;
return - EBUSY ;
}
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:16 +00:00
if ( ret < 0 )
return ret ;
val & = ~ ( PM_CTL_SUS_MODE_ | PM_CTL_WUPS_ | PM_CTL_PHY_RST_ ) ;
val | = PM_CTL_SUS_MODE_3 | PM_CTL_RES_CLR_WKP_STS ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:16 +00:00
if ( ret < 0 )
return ret ;
/* clear wol status */
val & = ~ PM_CTL_WUPS_ ;
val | = PM_CTL_WUPS_WOL_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:16 +00:00
if ( ret < 0 )
return ret ;
pdata - > suspend_flags | = SUSPEND_SUSPEND3 ;
return 0 ;
}
static int smsc95xx_autosuspend ( struct usbnet * dev , u32 link_up )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2013-01-03 03:00:16 +00:00
if ( ! netif_running ( dev - > net ) ) {
/* interface is ifconfig down so fully power down hw */
netdev_dbg ( dev - > net , " autosuspend entering SUSPEND2 \n " ) ;
return smsc95xx_enter_suspend2 ( dev ) ;
}
if ( ! link_up ) {
/* link is down so enter EDPD mode, but only if device can
* reliably resume from it . This check should be redundant
2013-02-22 03:05:05 +00:00
* as current FEATURE_REMOTE_WAKEUP parts also support
2013-01-03 03:00:16 +00:00
* FEATURE_PHY_NLP_CROSSOVER but it ' s included for clarity */
if ( ! ( pdata - > features & FEATURE_PHY_NLP_CROSSOVER ) ) {
netdev_warn ( dev - > net , " EDPD not supported \n " ) ;
return - EBUSY ;
}
netdev_dbg ( dev - > net , " autosuspend entering SUSPEND1 \n " ) ;
netdev_info ( dev - > net , " entering SUSPEND1 mode \n " ) ;
return smsc95xx_enter_suspend1 ( dev ) ;
}
netdev_dbg ( dev - > net , " autosuspend entering SUSPEND3 \n " ) ;
return smsc95xx_enter_suspend3 ( dev ) ;
}
2012-09-28 00:07:11 +00:00
static int smsc95xx_suspend ( struct usb_interface * intf , pm_message_t message )
{
struct usbnet * dev = usb_get_intfdata ( intf ) ;
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2012-11-22 08:05:24 +00:00
u32 val , link_up ;
2012-09-28 00:07:11 +00:00
int ret ;
2022-07-01 22:47:51 +02:00
pdata - > pm_task = current ;
2012-09-28 00:07:11 +00:00
ret = usbnet_suspend ( intf , message ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
netdev_warn ( dev - > net , " usbnet_suspend error \n " ) ;
2022-07-01 22:47:51 +02:00
pdata - > pm_task = NULL ;
2012-11-30 05:55:52 +00:00
return ret ;
}
2012-09-28 00:07:11 +00:00
2013-01-03 03:00:16 +00:00
if ( pdata - > suspend_flags ) {
netdev_warn ( dev - > net , " error during last resume \n " ) ;
pdata - > suspend_flags = 0 ;
}
2022-07-01 22:47:52 +02:00
link_up = smsc95xx_link_ok ( dev ) ;
2012-11-22 08:05:24 +00:00
2013-02-22 03:05:04 +00:00
if ( message . event = = PM_EVENT_AUTO_SUSPEND & &
2013-02-22 03:05:05 +00:00
( pdata - > features & FEATURE_REMOTE_WAKEUP ) ) {
2013-01-03 03:00:16 +00:00
ret = smsc95xx_autosuspend ( dev , link_up ) ;
goto done ;
}
/* if we get this far we're not autosuspending */
2012-11-22 08:05:24 +00:00
/* if no wol options set, or if link is down and we're not waking on
* PHY activity , enter lowest power SUSPEND2 mode
*/
if ( ! ( pdata - > wolopts & SUPPORTED_WAKE ) | |
! ( link_up | | ( pdata - > wolopts & WAKE_PHY ) ) ) {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " entering SUSPEND2 mode \n " ) ;
2012-09-28 00:07:12 +00:00
/* disable energy detect (link up) & wake up events */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , WUCSR , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
val & = ~ ( WUCSR_MPEN_ | WUCSR_WAKE_EN_ ) ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUCSR , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
val & = ~ ( PM_CTL_ED_EN_ | PM_CTL_WOL_EN_ ) ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
2012-11-30 05:55:49 +00:00
ret = smsc95xx_enter_suspend2 ( dev ) ;
goto done ;
2012-09-28 00:07:12 +00:00
}
2012-11-22 08:05:24 +00:00
if ( pdata - > wolopts & WAKE_PHY ) {
/* if link is down then configure EDPD and enter SUSPEND1,
* otherwise enter SUSPEND0 below
*/
if ( ! link_up ) {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " entering SUSPEND1 mode \n " ) ;
2012-11-30 05:55:49 +00:00
ret = smsc95xx_enter_suspend1 ( dev ) ;
goto done ;
2012-11-22 08:05:24 +00:00
}
}
2012-10-26 03:43:56 +00:00
if ( pdata - > wolopts & ( WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST ) ) {
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:03:40 -07:00
u32 * filter_mask = kcalloc ( 32 , sizeof ( u32 ) , GFP_KERNEL ) ;
2012-11-06 04:53:06 +00:00
u32 command [ 2 ] ;
u32 offset [ 2 ] ;
u32 crc [ 4 ] ;
2012-11-22 08:05:23 +00:00
int wuff_filter_count =
( pdata - > features & FEATURE_8_WAKEUP_FILTERS ) ?
LAN9500A_WUFF_NUM : LAN9500_WUFF_NUM ;
2012-10-26 03:43:56 +00:00
int i , filter = 0 ;
2012-11-30 05:55:48 +00:00
if ( ! filter_mask ) {
netdev_warn ( dev - > net , " Unable to allocate filter_mask \n " ) ;
2012-11-30 05:55:49 +00:00
ret = - ENOMEM ;
goto done ;
2012-11-30 05:55:48 +00:00
}
2012-11-06 04:53:06 +00:00
memset ( command , 0 , sizeof ( command ) ) ;
memset ( offset , 0 , sizeof ( offset ) ) ;
memset ( crc , 0 , sizeof ( crc ) ) ;
2012-10-26 03:43:56 +00:00
if ( pdata - > wolopts & WAKE_BCAST ) {
const u8 bcast [ ] = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ;
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling broadcast detection \n " ) ;
2012-10-26 03:43:56 +00:00
filter_mask [ filter * 4 ] = 0x003F ;
filter_mask [ filter * 4 + 1 ] = 0x00 ;
filter_mask [ filter * 4 + 2 ] = 0x00 ;
filter_mask [ filter * 4 + 3 ] = 0x00 ;
command [ filter / 4 ] | = 0x05UL < < ( ( filter % 4 ) * 8 ) ;
offset [ filter / 4 ] | = 0x00 < < ( ( filter % 4 ) * 8 ) ;
crc [ filter / 2 ] | = smsc_crc ( bcast , 6 , filter ) ;
filter + + ;
}
if ( pdata - > wolopts & WAKE_MCAST ) {
const u8 mcast [ ] = { 0x01 , 0x00 , 0x5E } ;
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling multicast detection \n " ) ;
2012-10-26 03:43:56 +00:00
filter_mask [ filter * 4 ] = 0x0007 ;
filter_mask [ filter * 4 + 1 ] = 0x00 ;
filter_mask [ filter * 4 + 2 ] = 0x00 ;
filter_mask [ filter * 4 + 3 ] = 0x00 ;
command [ filter / 4 ] | = 0x09UL < < ( ( filter % 4 ) * 8 ) ;
offset [ filter / 4 ] | = 0x00 < < ( ( filter % 4 ) * 8 ) ;
crc [ filter / 2 ] | = smsc_crc ( mcast , 3 , filter ) ;
filter + + ;
}
if ( pdata - > wolopts & WAKE_ARP ) {
const u8 arp [ ] = { 0x08 , 0x06 } ;
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling ARP detection \n " ) ;
2012-10-26 03:43:56 +00:00
filter_mask [ filter * 4 ] = 0x0003 ;
filter_mask [ filter * 4 + 1 ] = 0x00 ;
filter_mask [ filter * 4 + 2 ] = 0x00 ;
filter_mask [ filter * 4 + 3 ] = 0x00 ;
command [ filter / 4 ] | = 0x05UL < < ( ( filter % 4 ) * 8 ) ;
offset [ filter / 4 ] | = 0x0C < < ( ( filter % 4 ) * 8 ) ;
crc [ filter / 2 ] | = smsc_crc ( arp , 2 , filter ) ;
filter + + ;
}
if ( pdata - > wolopts & WAKE_UCAST ) {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling unicast detection \n " ) ;
2012-10-26 03:43:56 +00:00
filter_mask [ filter * 4 ] = 0x003F ;
filter_mask [ filter * 4 + 1 ] = 0x00 ;
filter_mask [ filter * 4 + 2 ] = 0x00 ;
filter_mask [ filter * 4 + 3 ] = 0x00 ;
command [ filter / 4 ] | = 0x01UL < < ( ( filter % 4 ) * 8 ) ;
offset [ filter / 4 ] | = 0x00 < < ( ( filter % 4 ) * 8 ) ;
crc [ filter / 2 ] | = smsc_crc ( dev - > net - > dev_addr , ETH_ALEN , filter ) ;
filter + + ;
}
2012-11-22 08:05:23 +00:00
for ( i = 0 ; i < ( wuff_filter_count * 4 ) ; i + + ) {
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUFF , filter_mask [ i ] ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 ) {
2012-11-06 04:53:06 +00:00
kfree ( filter_mask ) ;
2012-11-30 05:55:52 +00:00
goto done ;
}
2012-10-26 03:43:56 +00:00
}
2012-11-06 04:53:06 +00:00
kfree ( filter_mask ) ;
2012-10-26 03:43:56 +00:00
2012-11-22 08:05:23 +00:00
for ( i = 0 ; i < ( wuff_filter_count / 4 ) ; i + + ) {
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUFF , command [ i ] ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-10-26 03:43:56 +00:00
}
2012-11-22 08:05:23 +00:00
for ( i = 0 ; i < ( wuff_filter_count / 4 ) ; i + + ) {
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUFF , offset [ i ] ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-10-26 03:43:56 +00:00
}
2012-11-22 08:05:23 +00:00
for ( i = 0 ; i < ( wuff_filter_count / 2 ) ; i + + ) {
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUFF , crc [ i ] ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-10-26 03:43:56 +00:00
}
/* clear any pending pattern match packet status */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , WUCSR , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-10-26 03:43:56 +00:00
val | = WUCSR_WUFR_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUCSR , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-10-26 03:43:56 +00:00
}
2012-09-28 00:07:12 +00:00
if ( pdata - > wolopts & WAKE_MAGIC ) {
/* clear any pending magic packet status */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , WUCSR , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
val | = WUCSR_MPR_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUCSR , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
}
2012-10-26 03:43:56 +00:00
/* enable/disable wakeup sources */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , WUCSR , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
2012-10-26 03:43:56 +00:00
if ( pdata - > wolopts & ( WAKE_BCAST | WAKE_MCAST | WAKE_ARP | WAKE_UCAST ) ) {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling pattern match wakeup \n " ) ;
2012-10-26 03:43:56 +00:00
val | = WUCSR_WAKE_EN_ ;
} else {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " disabling pattern match wakeup \n " ) ;
2012-10-26 03:43:56 +00:00
val & = ~ WUCSR_WAKE_EN_ ;
}
2012-09-28 00:07:12 +00:00
if ( pdata - > wolopts & WAKE_MAGIC ) {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " enabling magic packet wakeup \n " ) ;
2012-09-28 00:07:12 +00:00
val | = WUCSR_MPEN_ ;
} else {
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " disabling magic packet wakeup \n " ) ;
2012-09-28 00:07:12 +00:00
val & = ~ WUCSR_MPEN_ ;
}
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUCSR , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
/* enable wol wakeup source */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
val | = PM_CTL_WOL_EN_ ;
2012-11-22 08:05:24 +00:00
/* phy energy detect wakeup source */
if ( pdata - > wolopts & WAKE_PHY )
val | = PM_CTL_ED_EN_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2012-11-30 05:55:52 +00:00
goto done ;
2012-09-28 00:07:12 +00:00
2012-10-26 03:43:56 +00:00
/* enable receiver to enable frame reception */
2022-07-01 22:47:52 +02:00
smsc95xx_start_rx_path ( dev ) ;
2012-09-28 00:07:12 +00:00
/* some wol options are enabled, so enter SUSPEND0 */
2012-11-24 01:27:49 +00:00
netdev_info ( dev - > net , " entering SUSPEND0 mode \n " ) ;
2012-11-30 05:55:49 +00:00
ret = smsc95xx_enter_suspend0 ( dev ) ;
done :
2013-03-15 12:08:58 +08:00
/*
* TODO : resume ( ) might need to handle the suspend failure
* in system sleep
*/
if ( ret & & PMSG_IS_AUTO ( message ) )
2012-11-30 05:55:49 +00:00
usbnet_resume ( intf ) ;
2018-10-31 22:52:19 +01:00
2022-07-01 22:47:51 +02:00
pdata - > pm_task = NULL ;
2012-11-30 05:55:49 +00:00
return ret ;
2012-09-28 00:07:12 +00:00
}
static int smsc95xx_resume ( struct usb_interface * intf )
{
struct usbnet * dev = usb_get_intfdata ( intf ) ;
2014-11-11 14:10:47 +05:30
struct smsc95xx_priv * pdata ;
u8 suspend_flags ;
2012-09-28 00:07:12 +00:00
int ret ;
u32 val ;
BUG_ON ( ! dev ) ;
2020-08-26 13:17:16 +02:00
pdata = dev - > driver_priv ;
2014-11-11 14:10:47 +05:30
suspend_flags = pdata - > suspend_flags ;
2012-09-28 00:07:12 +00:00
2013-01-03 03:00:16 +00:00
netdev_dbg ( dev - > net , " resume suspend_flags=0x%02x \n " , suspend_flags ) ;
/* do this first to ensure it's cleared even in error case */
pdata - > suspend_flags = 0 ;
2022-07-01 22:47:51 +02:00
pdata - > pm_task = current ;
2013-01-03 03:00:16 +00:00
if ( suspend_flags & SUSPEND_ALLMODES ) {
2012-10-26 03:43:56 +00:00
/* clear wake-up sources */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , WUCSR , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2022-07-01 22:47:51 +02:00
goto done ;
2012-09-28 00:07:12 +00:00
2012-10-26 03:43:56 +00:00
val & = ~ ( WUCSR_WAKE_EN_ | WUCSR_MPEN_ ) ;
2012-09-28 00:07:12 +00:00
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , WUCSR , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2022-07-01 22:47:51 +02:00
goto done ;
2012-09-28 00:07:12 +00:00
/* clear wake-up status */
2022-07-01 22:47:52 +02:00
ret = smsc95xx_read_reg ( dev , PM_CTRL , & val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2022-07-01 22:47:51 +02:00
goto done ;
2012-09-28 00:07:12 +00:00
val & = ~ PM_CTL_WOL_EN_ ;
val | = PM_CTL_WUPS_ ;
2022-07-01 22:47:52 +02:00
ret = smsc95xx_write_reg ( dev , PM_CTRL , val ) ;
2013-01-03 03:00:15 +00:00
if ( ret < 0 )
2022-07-01 22:47:51 +02:00
goto done ;
2012-09-28 00:07:12 +00:00
}
usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling
Link status of SMSC LAN95xx chips is polled once per second, even though
they're capable of signaling PHY interrupts through the MAC layer.
Forward those interrupts to the PHY driver to avoid polling. Benefits
are reduced bus traffic, reduced CPU overhead and quicker interface
bringup.
Polling was introduced in 2016 by commit d69d16949346 ("usbnet:
smsc95xx: fix link detection for disabled autonegotiation").
Back then, the LAN95xx driver neglected to enable the ENERGYON interrupt,
hence couldn't detect link-up events when auto-negotiation was disabled.
The proper solution would have been to enable the ENERGYON interrupt
instead of polling.
Since then, PHY handling was moved from the LAN95xx driver to the SMSC
PHY driver with commit 05b35e7eb9a1 ("smsc95xx: add phylib support").
That PHY driver is capable of link detection with auto-negotiation
disabled because it enables the ENERGYON interrupt.
Note that signaling interrupts through the MAC layer not only works with
the integrated PHY, but also with an external PHY, provided its
interrupt pin is attached to LAN95xx's nPHY_INT pin.
In the unlikely event that the interrupt pin of an external PHY is
attached to a GPIO of the SoC (or not connected at all), the driver can
be amended to retrieve the irq from the PHY's of_node.
To forward PHY interrupts to phylib, it is not sufficient to call
phy_mac_interrupt(). Instead, the PHY's interrupt handler needs to run
so that PHY interrupts are cleared. That's because according to page
119 of the LAN950x datasheet, "The source of this interrupt is a level.
The interrupt persists until it is cleared in the PHY."
https://www.microchip.com/content/dam/mchp/documents/UNG/ProductDocuments/DataSheets/LAN950x-Data-Sheet-DS00001875D.pdf
Therefore, create an IRQ domain with a single IRQ for the PHY. In the
future, the IRQ domain may be extended to support the 11 GPIOs on the
LAN95xx.
Normally the PHY interrupt should be masked until the PHY driver has
cleared it. However masking requires a (sleeping) USB transaction and
interrupts are received in (non-sleepable) softirq context. I decided
not to mask the interrupt at all (by using the dummy_irq_chip's noop
->irq_mask() callback): The USB interrupt endpoint is polled in 1 msec
intervals and normally that's sufficient to wake the PHY driver's IRQ
thread and have it clear the interrupt. If it does take longer, worst
thing that can happen is the IRQ thread is woken again. No big deal.
Because PHY interrupts are now perpetually enabled, there's no need to
selectively enable them on suspend. So remove all invocations of
smsc95xx_enable_phy_wakeup_interrupts().
In smsc95xx_resume(), move the call of phy_init_hw() before
usbnet_resume() (which restarts the status URB) to ensure that the PHY
is fully initialized when an interrupt is handled.
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> # from a PHY perspective
Cc: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-05-12 10:42:05 +02:00
phy_init_hw ( pdata - > phydev ) ;
2012-11-22 08:05:22 +00:00
ret = usbnet_resume ( intf ) ;
2012-11-30 05:55:52 +00:00
if ( ret < 0 )
netdev_warn ( dev - > net , " usbnet_resume error \n " ) ;
2012-09-28 00:07:12 +00:00
2022-07-01 22:47:51 +02:00
done :
pdata - > pm_task = NULL ;
2012-11-30 05:55:52 +00:00
return ret ;
2012-09-28 00:07:11 +00:00
}
2014-07-10 11:49:42 +09:00
static int smsc95xx_reset_resume ( struct usb_interface * intf )
{
struct usbnet * dev = usb_get_intfdata ( intf ) ;
2022-07-01 22:47:51 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2014-07-10 11:49:42 +09:00
int ret ;
2022-07-01 22:47:51 +02:00
pdata - > pm_task = current ;
2014-07-10 11:49:42 +09:00
ret = smsc95xx_reset ( dev ) ;
2022-07-01 22:47:51 +02:00
pdata - > pm_task = NULL ;
2014-07-10 11:49:42 +09:00
if ( ret < 0 )
return ret ;
return smsc95xx_resume ( intf ) ;
}
2008-10-02 05:27:57 +00:00
static void smsc95xx_rx_csum_offload ( struct sk_buff * skb )
{
skb - > csum = * ( u16 * ) ( skb_tail_pointer ( skb ) - 2 ) ;
skb - > ip_summed = CHECKSUM_COMPLETE ;
skb_trim ( skb , skb - > len - 2 ) ;
}
static int smsc95xx_rx_fixup ( struct usbnet * dev , struct sk_buff * skb )
{
2014-02-13 17:50:19 +01:00
/* This check is no longer done by usbnet */
if ( skb - > len < dev - > net - > hard_header_len )
return 0 ;
2008-10-02 05:27:57 +00:00
while ( skb - > len > 0 ) {
u32 header , align_count ;
struct sk_buff * ax_skb ;
unsigned char * packet ;
u16 size ;
2018-11-14 11:50:21 +00:00
header = get_unaligned_le32 ( skb - > data ) ;
2008-10-02 05:27:57 +00:00
skb_pull ( skb , 4 + NET_IP_ALIGN ) ;
packet = skb - > data ;
/* get the packet length */
size = ( u16 ) ( ( header & RX_STS_FL_ ) > > 16 ) ;
align_count = ( 4 - ( ( size + NET_IP_ALIGN ) % 4 ) ) % 4 ;
if ( unlikely ( header & RX_STS_ES_ ) ) {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , rx_err , dev - > net ,
" Error header=0x%08x \n " , header ) ;
2009-06-29 16:53:00 +00:00
dev - > net - > stats . rx_errors + + ;
dev - > net - > stats . rx_dropped + + ;
2008-10-02 05:27:57 +00:00
if ( header & RX_STS_CRC_ ) {
2009-06-29 16:53:00 +00:00
dev - > net - > stats . rx_crc_errors + + ;
2008-10-02 05:27:57 +00:00
} else {
if ( header & ( RX_STS_TL_ | RX_STS_RF_ ) )
2009-06-29 16:53:00 +00:00
dev - > net - > stats . rx_frame_errors + + ;
2008-10-02 05:27:57 +00:00
if ( ( header & RX_STS_LE_ ) & &
( ! ( header & RX_STS_FT_ ) ) )
2009-06-29 16:53:00 +00:00
dev - > net - > stats . rx_length_errors + + ;
2008-10-02 05:27:57 +00:00
}
} else {
/* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
if ( unlikely ( size > ( ETH_FRAME_LEN + 12 ) ) ) {
2010-02-17 10:30:24 +00:00
netif_dbg ( dev , rx_err , dev - > net ,
" size err header=0x%08x \n " , header ) ;
2008-10-02 05:27:57 +00:00
return 0 ;
}
/* last frame in this batch */
if ( skb - > len = = size ) {
2011-04-01 20:56:23 -07:00
if ( dev - > net - > features & NETIF_F_RXCSUM )
2008-10-02 05:27:57 +00:00
smsc95xx_rx_csum_offload ( skb ) ;
2009-05-13 10:10:41 +00:00
skb_trim ( skb , skb - > len - 4 ) ; /* remove fcs */
2008-10-02 05:27:57 +00:00
skb - > truesize = size + sizeof ( struct sk_buff ) ;
return 1 ;
}
ax_skb = skb_clone ( skb , GFP_ATOMIC ) ;
if ( unlikely ( ! ax_skb ) ) {
2010-02-17 10:30:23 +00:00
netdev_warn ( dev - > net , " Error allocating skb \n " ) ;
2008-10-02 05:27:57 +00:00
return 0 ;
}
ax_skb - > len = size ;
ax_skb - > data = packet ;
skb_set_tail_pointer ( ax_skb , size ) ;
2011-04-01 20:56:23 -07:00
if ( dev - > net - > features & NETIF_F_RXCSUM )
2008-10-02 05:27:57 +00:00
smsc95xx_rx_csum_offload ( ax_skb ) ;
2009-05-13 10:10:41 +00:00
skb_trim ( ax_skb , ax_skb - > len - 4 ) ; /* remove fcs */
2008-10-02 05:27:57 +00:00
ax_skb - > truesize = size + sizeof ( struct sk_buff ) ;
usbnet_skb_return ( dev , ax_skb ) ;
}
skb_pull ( skb , size ) ;
/* padding bytes before the next frame starts */
if ( skb - > len )
skb_pull ( skb , align_count ) ;
}
return 1 ;
}
2008-11-20 04:19:21 -08:00
static u32 smsc95xx_calc_csum_preamble ( struct sk_buff * skb )
{
2010-12-14 15:24:08 +00:00
u16 low_16 = ( u16 ) skb_checksum_start_offset ( skb ) ;
u16 high_16 = low_16 + skb - > csum_offset ;
2008-11-20 04:19:21 -08:00
return ( high_16 < < 16 ) | low_16 ;
}
2018-11-14 11:50:22 +00:00
/* The TX CSUM won't work if the checksum lies in the last 4 bytes of the
* transmission . This is fairly unlikely , only seems to trigger with some
* short TCP ACK packets sent .
*
* Note , this calculation should probably check for the alignment of the
* data as well , but a straight check for csum being in the last four bytes
* of the packet should be ok for now .
*/
static bool smsc95xx_can_tx_checksum ( struct sk_buff * skb )
{
unsigned int len = skb - > len - skb_checksum_start_offset ( skb ) ;
if ( skb - > len < = 45 )
return false ;
return skb - > csum_offset < ( len - ( 4 + 1 ) ) ;
}
2008-10-02 05:27:57 +00:00
static struct sk_buff * smsc95xx_tx_fixup ( struct usbnet * dev ,
struct sk_buff * skb , gfp_t flags )
{
2011-04-01 20:56:23 -07:00
bool csum = skb - > ip_summed = = CHECKSUM_PARTIAL ;
2008-11-20 04:19:21 -08:00
int overhead = csum ? SMSC95XX_TX_OVERHEAD_CSUM : SMSC95XX_TX_OVERHEAD ;
2008-10-02 05:27:57 +00:00
u32 tx_cmd_a , tx_cmd_b ;
2018-11-14 11:50:20 +00:00
void * ptr ;
2008-10-02 05:27:57 +00:00
2008-11-20 04:19:21 -08:00
/* We do not advertise SG, so skbs should be already linearized */
BUG_ON ( skb_shinfo ( skb ) - > nr_frags ) ;
2017-04-19 11:13:40 +01:00
/* Make writable and expand header space by overhead if required */
if ( skb_cow_head ( skb , overhead ) ) {
/* Must deallocate here as returning NULL to indicate error
* means the skb won ' t be deallocated in the caller .
*/
2008-10-02 05:27:57 +00:00
dev_kfree_skb_any ( skb ) ;
2017-04-19 11:13:40 +01:00
return NULL ;
2008-10-02 05:27:57 +00:00
}
2018-11-14 11:50:20 +00:00
tx_cmd_b = ( u32 ) skb - > len ;
tx_cmd_a = tx_cmd_b | TX_CMD_A_FIRST_SEG_ | TX_CMD_A_LAST_SEG_ ;
2008-11-20 04:19:21 -08:00
if ( csum ) {
2018-11-14 11:50:22 +00:00
if ( ! smsc95xx_can_tx_checksum ( skb ) ) {
2010-03-18 22:18:41 -07:00
/* workaround - hardware tx checksum does not work
* properly with extremely small packets */
2010-12-14 15:24:08 +00:00
long csstart = skb_checksum_start_offset ( skb ) ;
2010-03-18 22:18:41 -07:00
__wsum calc = csum_partial ( skb - > data + csstart ,
skb - > len - csstart , 0 ) ;
* ( ( __sum16 * ) ( skb - > data + csstart
+ skb - > csum_offset ) ) = csum_fold ( calc ) ;
csum = false ;
} else {
u32 csum_preamble = smsc95xx_calc_csum_preamble ( skb ) ;
2018-11-14 11:50:20 +00:00
ptr = skb_push ( skb , 4 ) ;
put_unaligned_le32 ( csum_preamble , ptr ) ;
tx_cmd_a + = 4 ;
tx_cmd_b + = 4 ;
tx_cmd_b | = TX_CMD_B_CSUM_ENABLE ;
2010-03-18 22:18:41 -07:00
}
2008-11-20 04:19:21 -08:00
}
2018-11-14 11:50:20 +00:00
ptr = skb_push ( skb , 8 ) ;
put_unaligned_le32 ( tx_cmd_a , ptr ) ;
put_unaligned_le32 ( tx_cmd_b , ptr + 4 ) ;
2008-10-02 05:27:57 +00:00
return skb ;
}
2013-01-03 03:00:16 +00:00
static int smsc95xx_manage_power ( struct usbnet * dev , int on )
{
2020-08-26 13:17:16 +02:00
struct smsc95xx_priv * pdata = dev - > driver_priv ;
2013-01-03 03:00:16 +00:00
dev - > intf - > needs_remote_wakeup = on ;
2013-02-22 03:05:05 +00:00
if ( pdata - > features & FEATURE_REMOTE_WAKEUP )
2013-01-03 03:00:16 +00:00
return 0 ;
2013-02-22 03:05:05 +00:00
/* this chip revision isn't capable of remote wakeup */
netdev_info ( dev - > net , " hardware isn't capable of remote wakeup \n " ) ;
2013-01-03 03:00:16 +00:00
if ( on )
usb_autopm_get_interface_no_resume ( dev - > intf ) ;
else
usb_autopm_put_interface ( dev - > intf ) ;
return 0 ;
}
2008-10-02 05:27:57 +00:00
static const struct driver_info smsc95xx_info = {
. description = " smsc95xx USB 2.0 Ethernet " ,
. bind = smsc95xx_bind ,
. unbind = smsc95xx_unbind ,
2022-01-13 21:01:11 +01:00
. reset = smsc95xx_reset ,
. check_connect = smsc95xx_start_phy ,
2021-11-22 18:44:45 +00:00
. stop = smsc95xx_stop ,
2008-10-02 05:27:57 +00:00
. rx_fixup = smsc95xx_rx_fixup ,
. tx_fixup = smsc95xx_tx_fixup ,
. status = smsc95xx_status ,
2013-01-03 03:00:16 +00:00
. manage_power = smsc95xx_manage_power ,
2012-04-23 04:05:20 +00:00
. flags = FLAG_ETHER | FLAG_SEND_ZLP | FLAG_LINK_INTR ,
2008-10-02 05:27:57 +00:00
} ;
static const struct usb_device_id products [ ] = {
{
/* SMSC9500 USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9500 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2009-09-22 05:13:02 +00:00
{
/* SMSC9505 USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9505 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9500A USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9E00 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9505A USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9E01 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2009-05-01 06:07:22 +00:00
{
/* SMSC9512/9514 USB Hub & Ethernet Device */
USB_DEVICE ( 0x0424 , 0xec00 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2009-09-22 05:13:02 +00:00
{
/* SMSC9500 USB Ethernet Device (SAL10) */
USB_DEVICE ( 0x0424 , 0x9900 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9505 USB Ethernet Device (SAL10) */
USB_DEVICE ( 0x0424 , 0x9901 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9500A USB Ethernet Device (SAL10) */
USB_DEVICE ( 0x0424 , 0x9902 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9505A USB Ethernet Device (SAL10) */
USB_DEVICE ( 0x0424 , 0x9903 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9512/9514 USB Hub & Ethernet Device (SAL10) */
USB_DEVICE ( 0x0424 , 0x9904 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9500A USB Ethernet Device (HAL) */
USB_DEVICE ( 0x0424 , 0x9905 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9505A USB Ethernet Device (HAL) */
USB_DEVICE ( 0x0424 , 0x9906 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9500 USB Ethernet Device (Alternate ID) */
USB_DEVICE ( 0x0424 , 0x9907 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9500A USB Ethernet Device (Alternate ID) */
USB_DEVICE ( 0x0424 , 0x9908 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC9512/9514 USB Hub & Ethernet Device (Alternate ID) */
USB_DEVICE ( 0x0424 , 0x9909 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2011-04-10 18:59:27 -07:00
{
/* SMSC LAN9530 USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9530 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC LAN9730 USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9730 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
{
/* SMSC LAN89530 USB Ethernet Device */
USB_DEVICE ( 0x0424 , 0x9E08 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2022-06-13 14:42:07 +05:30
{
/* Microchip's EVB-LAN8670-USB 10BASE-T1S Ethernet Device */
USB_DEVICE ( 0x184F , 0x0051 ) ,
. driver_info = ( unsigned long ) & smsc95xx_info ,
} ,
2008-10-02 05:27:57 +00:00
{ } , /* END */
} ;
MODULE_DEVICE_TABLE ( usb , products ) ;
static struct usb_driver smsc95xx_driver = {
. name = " smsc95xx " ,
. id_table = products ,
. probe = usbnet_probe ,
2012-09-28 00:07:11 +00:00
. suspend = smsc95xx_suspend ,
2012-09-28 00:07:12 +00:00
. resume = smsc95xx_resume ,
2014-07-10 11:49:42 +09:00
. reset_resume = smsc95xx_reset_resume ,
2008-10-02 05:27:57 +00:00
. disconnect = usbnet_disconnect ,
2012-04-23 10:08:51 -07:00
. disable_hub_initiated_lpm = 1 ,
2013-01-03 03:00:16 +00:00
. supports_autosuspend = 1 ,
2008-10-02 05:27:57 +00:00
} ;
2011-11-18 09:44:20 -08:00
module_usb_driver ( smsc95xx_driver ) ;
2008-10-02 05:27:57 +00:00
MODULE_AUTHOR ( " Nancy Lin " ) ;
2012-04-16 12:13:29 +01:00
MODULE_AUTHOR ( " Steve Glendinning <steve.glendinning@shawell.net> " ) ;
2008-10-02 05:27:57 +00:00
MODULE_DESCRIPTION ( " SMSC95XX USB 2.0 Ethernet Devices " ) ;
MODULE_LICENSE ( " GPL " ) ;