usbnet: smsc95xx: Convert to phydev
Subsystems (5)
cover usbnet: smsc95xx: Convert to phydev
This series first cleans up the in_pm variable and _nopm() functions, in preparations for conversion to phy_device instead of ad-hoc PHY configuration.
This is followed by a registration of an MDIO bus, attaching a PHY device to it and conversion and cleanup of assorted functions to use the new PHY device functions.
This patchset also allows using other PHYs but the internal one, since the PHY code scans for the first available PHY, however the code was only tested with the internal PHY on a RasPi B+ thus far, as that is the most common use for this device it seems.
Marek Vasut (19):
usbnet: smsc95xx: Fix memory leak in smsc95xx_bind
usbnet: smsc95xx: Stop propagation of in_pm
usbnet: smsc95xx: Remove smsc95xx_{read,write}_reg_nopm()
usbnet: smsc95xx: Remove __smsc95xx_{read,write}_reg()
usbnet: smsc95xx: Remove smsc95xx_{read,write}_nopm()
usbnet: smsc95xx: Remove __smsc95xx_mdio_{read,write}()
usbnet: smsc95xx: Split the reset function
usbnet: smsc95xx: Register MII bus
usbnet: smsc95xx: Connect to phydev
usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
usbnet: smsc95xx: Replace smsc95xx_mdio_write() with phy_write()
usbnet: smsc95xx: Replace ad-hoc PHY functions with generic ones
usbnet: smsc95xx: Replace smsc95xx_link_ok_nopm()
usbnet: smsc95xx: Replace mii_nway_restart()
usbnet: smsc95xx: Replace mii_ethtool_gset()
usbnet: smsc95xx: Replace mii_check_media()
usbnet: smsc95xx: Replace generic_mii_ioctl()
usbnet: smsc95xx: Remove all of the carrier checking code
usbnet: smsc95xx: Use phy bit operations
drivers/net/usb/smsc95xx.c | 478 ++++++++++++++++++------------------- 1 file changed, 229 insertions(+), 249 deletions(-)
Signature · 1 line
2.19.2
PATCH 1/19 usbnet: smsc95xx: Fix memory leak in smsc95xx_bind
In case reading of PHY register fails in smsc95xx_bind(), the private data allocated earlier are not free()d. Free them before bailing out.
--- drivers/net/usb/smsc95xx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/smsc95xx.c +4 -1
@@ -1303,7 +1303,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)/* detect device revision as different features may be available */ ret =smsc95xx_read_reg (dev,ID_REV , &val);if (ret <0 ) -return ret; + goto err_read_reg; val >>=16 ; pdata->chip_id = val; pdata->mdix_ctrl =get_mdix_status (dev->net);
@@ -1329,6 +1329,9 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)schedule_delayed_work (&pdata->carrier_check,CARRIER_CHECK_DELAY );return 0 ; +err_read_reg: +kfree (pdata); +return ret; }static void smsc95xx_unbind (struct usbnet *dev,struct usb_interface *intf)
PATCH 2/19 usbnet: smsc95xx: Stop propagation of in_pm
In reply to Marek VasutThe information whether the SMSC95xx is in_pm or not can be derived from the usbdev->suspend_count. First thing called in smsc95xx_suspend() is usbnet_suspend(), which increments the usbdev->suspend_count and since then the driver only calls _nopm() functions and functions with in_pm set to 1. The smsc95xx_resume() does the inverse, it calls functions with _nopm() suffix and with in_pm set to 1 until usbnet_resume(), which sets the usbdev->suspend_count to 0.
Thus, this patch replaces all the in_pm variables used throughout the driver with simple call to smsc95xx_in_pm(), which checks whether the usbdev->suspend_count is zero or not.
--- drivers/net/usb/smsc95xx.c | 63 ++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 30 deletions(-)
drivers/net/usb/smsc95xx.c +33 -30
@@ -82,8 +82,13 @@ static bool turbo_mode = true;module_param (turbo_mode, bool,0644 );MODULE_PARM_DESC (turbo_mode,"Enable multiple frames per Rx transaction" ); +static int smsc95xx_in_pm (struct usbnet *dev) +{ +return dev->suspend_count !=0 ; +} +static int __must_check __smsc95xx_read_reg (struct usbnet *dev,u32 index, -u32 *data,int in_pm) +u32 *data) {u32 buf;int ret;
@@ -91,7 +96,7 @@ static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,BUG_ON (!dev); -if (!in_pm) +if (!smsc95xx_in_pm (dev)) fn = usbnet_read_cmd;else fn = usbnet_read_cmd_nopm;
@@ -112,7 +117,7 @@ static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index, }static int __must_check __smsc95xx_write_reg (struct usbnet *dev,u32 index, -u32 data,int in_pm) +u32 data) {u32 buf;int ret;
@@ -120,7 +125,7 @@ static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,BUG_ON (!dev); -if (!in_pm) +if (!smsc95xx_in_pm (dev)) fn = usbnet_write_cmd;else fn = usbnet_write_cmd_nopm;
@@ -141,38 +146,37 @@ static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,static int __must_check smsc95xx_read_reg_nopm (struct usbnet *dev,u32 index,u32 *data) { -return __smsc95xx_read_reg (dev, index, data,1 ); +return __smsc95xx_read_reg (dev, index, data); }static int __must_check smsc95xx_write_reg_nopm (struct usbnet *dev,u32 index,u32 data) { -return __smsc95xx_write_reg (dev, index, data,1 ); +return __smsc95xx_write_reg (dev, index, data); }static int __must_check smsc95xx_read_reg (struct usbnet *dev,u32 index,u32 *data) { -return __smsc95xx_read_reg (dev, index, data,0 ); +return __smsc95xx_read_reg (dev, index, data); }static int __must_check smsc95xx_write_reg (struct usbnet *dev,u32 index,u32 data) { -return __smsc95xx_write_reg (dev, index, data,0 ); +return __smsc95xx_write_reg (dev, index, data); }/* Loop until the read is completed with timeout * called with phy_mutex held */ -static int __must_check __smsc95xx_phy_wait_not_busy (struct usbnet *dev, -int in_pm) +static int __must_check __smsc95xx_phy_wait_not_busy (struct usbnet *dev) {unsigned long start_time = jiffies;u32 val;int ret; do { - ret = __smsc95xx_read_reg(dev, MII_ADDR, &val, in_pm); + ret = __smsc95xx_read_reg(dev, MII_ADDR, &val); if (ret < 0) { netdev_warn(dev->net, "Error reading MII_ACCESS\n"); return ret;
@@ -185,8 +189,7 @@ static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev,return -EIO ; } -static int __smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx, -int in_pm) +static int __smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) {struct usbnet *dev =netdev_priv (netdev);u32 val, addr;
@@ -195,7 +198,7 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx,mutex_lock (&dev->phy_mutex);/* confirm MII not busy */ - ret =__smsc95xx_phy_wait_not_busy (dev, in_pm); + ret =__smsc95xx_phy_wait_not_busy (dev);if (ret <0 ) {netdev_warn (dev->net,"MII is busy in smsc95xx_mdio_read\n" ); goto done;
@@ -205,19 +208,19 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, phy_id &= dev->mii.phy_id_mask; idx &= dev->mii.reg_num_mask; addr = (phy_id <<11 ) | (idx <<6 ) |MII_READ_ |MII_BUSY_ ; - ret =__smsc95xx_write_reg (dev,MII_ADDR , addr, in_pm); + ret =__smsc95xx_write_reg (dev,MII_ADDR , addr);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_ADDR\n" ); goto done; } - ret =__smsc95xx_phy_wait_not_busy (dev, in_pm); + ret =__smsc95xx_phy_wait_not_busy (dev);if (ret <0 ) {netdev_warn (dev->net,"Timed out reading MII reg %02X\n" , idx); goto done; } - ret =__smsc95xx_read_reg (dev,MII_DATA , &val, in_pm); + ret =__smsc95xx_read_reg (dev,MII_DATA , &val);if (ret <0 ) {netdev_warn (dev->net,"Error reading MII_DATA\n" ); goto done;
@@ -231,7 +234,7 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx, }static void __smsc95xx_mdio_write (struct net_device *netdev,int phy_id, -int idx,int regval,int in_pm) +int idx,int regval) {struct usbnet *dev =netdev_priv (netdev);u32 val, addr;
@@ -240,14 +243,14 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,mutex_lock (&dev->phy_mutex);/* confirm MII not busy */ - ret =__smsc95xx_phy_wait_not_busy (dev, in_pm); + ret =__smsc95xx_phy_wait_not_busy (dev);if (ret <0 ) {netdev_warn (dev->net,"MII is busy in smsc95xx_mdio_write\n" ); goto done; } val = regval; - ret =__smsc95xx_write_reg (dev,MII_DATA , val, in_pm); + ret =__smsc95xx_write_reg (dev,MII_DATA , val);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_DATA\n" ); goto done;
@@ -257,13 +260,13 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, phy_id &= dev->mii.phy_id_mask; idx &= dev->mii.reg_num_mask; addr = (phy_id <<11 ) | (idx <<6 ) |MII_WRITE_ |MII_BUSY_ ; - ret =__smsc95xx_write_reg (dev,MII_ADDR , addr, in_pm); + ret =__smsc95xx_write_reg (dev,MII_ADDR , addr);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_ADDR\n" ); goto done; } - ret =__smsc95xx_phy_wait_not_busy (dev, in_pm); + ret =__smsc95xx_phy_wait_not_busy (dev);if (ret <0 ) {netdev_warn (dev->net,"Timed out writing MII reg %02X\n" , idx); goto done;
@@ -276,24 +279,24 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,static int smsc95xx_mdio_read_nopm (struct net_device *netdev,int phy_id,int idx) { -return __smsc95xx_mdio_read (netdev, phy_id, idx,1 ); +return __smsc95xx_mdio_read (netdev, phy_id, idx); }static void smsc95xx_mdio_write_nopm (struct net_device *netdev,int phy_id,int idx,int regval) { -__smsc95xx_mdio_write (netdev, phy_id, idx, regval,1 ); +__smsc95xx_mdio_write (netdev, phy_id, idx, regval); }static int smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) { -return __smsc95xx_mdio_read (netdev, phy_id, idx,0 ); +return __smsc95xx_mdio_read (netdev, phy_id, idx); }static void smsc95xx_mdio_write (struct net_device *netdev,int phy_id,int idx,int regval) { -__smsc95xx_mdio_write (netdev, phy_id, idx, regval,0 ); +__smsc95xx_mdio_write (netdev, phy_id, idx, regval); }static int __must_check smsc95xx_wait_eeprom (struct usbnet *dev)
@@ -972,7 +975,7 @@ static int smsc95xx_start_tx_path(struct usbnet *dev) }/* Starts the Receive path */ -static int smsc95xx_start_rx_path (struct usbnet *dev,int in_pm) +static int smsc95xx_start_rx_path (struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);unsigned long flags;
@@ -981,7 +984,7 @@ static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm) pdata->mac_cr |=MAC_CR_RXEN_ ;spin_unlock_irqrestore (&pdata->mac_cr_lock, flags); -return __smsc95xx_write_reg (dev,MAC_CR , pdata->mac_cr, in_pm); +return __smsc95xx_write_reg (dev,MAC_CR , pdata->mac_cr); }static int smsc95xx_phy_initialize (struct usbnet *dev)
@@ -1233,7 +1236,7 @@ static int smsc95xx_reset(struct usbnet *dev)return ret; } - ret =smsc95xx_start_rx_path (dev,0 ); + ret =smsc95xx_start_rx_path (dev);if (ret <0 ) {netdev_warn (dev->net,"Failed to start RX path\n" );return ret;
@@ -1833,7 +1836,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) goto done;/* enable receiver to enable frame reception */ -smsc95xx_start_rx_path (dev,1 ); +smsc95xx_start_rx_path (dev);/* some wol options are enabled, so enter SUSPEND0 */ netdev_info (dev->net,"entering SUSPEND0 mode\n" );
Re: [PATCH 02/19] usbnet: smsc95xx: Stop propagation of in_pm
Quoted 7 lines · Marek Vasut
The information whether the SMSC95xx is
in_pmor not can be derived from theusbdev->suspend_count. First thing called insmsc95xx_suspend()isusbnet_suspend(), which increments theusbdev->suspend_countand since then the driver only calls_nopm()functions and functions within_pmset to 1. Thesmsc95xx_resume()does the inverse, it calls functions with_nopm()suffix and within_pmset to 1 untilusbnet_resume(), which sets theusbdev->suspend_countto 0.
Hi,
unfortunately I am forced to disagree in the strongest terms.
The logic behind this patch is wrong. The "in_pm" parameter exists because some function need to be called in the code paths needed to implement power management. Under those circumstances they must not take a pm reference to keep the device awake, lest the driver deadlock.
(For example __smsc95xx_read_reg)
However from other code paths precisely that reference must be taken in order to make sure that the driver do not try to communicate with a suspended device.
If you check the suspend counter, you will omit the necessary getting of a reference precisely when it is needed. The driver will never dedalock, but you will cause numerous races.
I must suggest to simply drop this part and redo the series.
Regards
Oliver
Re: [PATCH 02/19] usbnet: smsc95xx: Stop propagation of in_pm
Quoted 10 lines · Oliver Neukum
Quoted 7 lines · Marek Vasut
The information whether the SMSC95xx is
in_pmor not can be derived from theusbdev->suspend_count. First thing called insmsc95xx_suspend()isusbnet_suspend(), which increments theusbdev->suspend_countand since then the driver only calls_nopm()functions and functions within_pmset to 1. Thesmsc95xx_resume()does the inverse, it calls functions with_nopm()suffix and within_pmset to 1 untilusbnet_resume(), which sets theusbdev->suspend_countto 0.Hi,
Hello Oliver,
Quoted 9 lines
unfortunately I am forced to disagree in the strongest terms.
The logic behind this patch is wrong. The "
in_pm" parameter exists because some function need to be called in the code paths needed to implement power management. Under those circumstances they must not take a pm reference to keep the device awake, lest the driver deadlock.
(For example__smsc95xx_read_reg)
Quoted 8 lines
However from other code paths precisely that reference must be taken in order to make sure that the driver do not try to communicate with a suspended device.
If you check the suspend counter, you will omit the necessary getting of a reference precisely when it is needed. The driver will never dedalock, but you will cause numerous races.I must suggest to simply drop this part and redo the series.
OK, let's drop the whole series.
PATCH 3/19 usbnet: smsc95xx: Remove smsc95xx_{read,write}_reg_nopm()
In reply to Marek VasutThese functions are now equal to smsc95xx_{read,write}_reg(), deduplicate them.
--- drivers/net/usb/smsc95xx.c | 78 ++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 45 deletions(-)
drivers/net/usb/smsc95xx.c +33 -45
@@ -143,18 +143,6 @@ static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,return ret; } -static int __must_check smsc95xx_read_reg_nopm (struct usbnet *dev,u32 index, -u32 *data) -{ -return __smsc95xx_read_reg (dev, index, data); -} - -static int __must_check smsc95xx_write_reg_nopm (struct usbnet *dev,u32 index, -u32 data) -{ -return __smsc95xx_write_reg (dev, index, data); -} -static int __must_check smsc95xx_read_reg (struct usbnet *dev,u32 index,u32 *data) {
@@ -1403,14 +1391,14 @@ static int smsc95xx_enter_suspend0(struct usbnet *dev)u32 val;int ret; - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )return ret; val &= (~(PM_CTL_SUS_MODE_ |PM_CTL_WUPS_ |PM_CTL_PHY_RST_ )); val |=PM_CTL_SUS_MODE_0 ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1422,12 +1410,12 @@ static int smsc95xx_enter_suspend0(struct usbnet *dev)if (pdata->wolopts &WAKE_PHY ) val |=PM_CTL_WUPS_ED_ ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;/* read back PM_CTRL */ - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )return ret;
@@ -1460,14 +1448,14 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev)smsc95xx_mdio_write_nopm (dev->net, mii->phy_id,PHY_MODE_CTRL_STS , ret);/* enter SUSPEND1 mode */ - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )return ret; val &= ~(PM_CTL_SUS_MODE_ |PM_CTL_WUPS_ |PM_CTL_PHY_RST_ ); val |=PM_CTL_SUS_MODE_1 ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1475,7 +1463,7 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev) val &= ~PM_CTL_WUPS_ ; val |= (PM_CTL_WUPS_ED_ |PM_CTL_ED_EN_ ); - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1490,14 +1478,14 @@ static int smsc95xx_enter_suspend2(struct usbnet *dev)u32 val;int ret; - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )return ret; val &= ~(PM_CTL_SUS_MODE_ |PM_CTL_WUPS_ |PM_CTL_PHY_RST_ ); val |=PM_CTL_SUS_MODE_2 ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1512,7 +1500,7 @@ static int smsc95xx_enter_suspend3(struct usbnet *dev)u32 val;int ret; - ret =smsc95xx_read_reg_nopm (dev,RX_FIFO_INF , &val); + ret =smsc95xx_read_reg (dev,RX_FIFO_INF , &val);if (ret <0 )return ret;
@@ -1521,14 +1509,14 @@ static int smsc95xx_enter_suspend3(struct usbnet *dev)return -EBUSY ; } - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);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 ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1536,7 +1524,7 @@ static int smsc95xx_enter_suspend3(struct usbnet *dev) val &= ~PM_CTL_WUPS_ ; val |=PM_CTL_WUPS_WOL_ ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret;
@@ -1630,23 +1618,23 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)netdev_info (dev->net,"entering SUSPEND2 mode\n" );/* disable energy detect (link up) & wake up events */ - ret =smsc95xx_read_reg_nopm (dev,WUCSR , &val); + ret =smsc95xx_read_reg (dev,WUCSR , &val);if (ret <0 ) goto done; val &= ~(WUCSR_MPEN_ |WUCSR_WAKE_EN_ ); - ret =smsc95xx_write_reg_nopm (dev,WUCSR , val); + ret =smsc95xx_write_reg (dev,WUCSR , val);if (ret <0 ) goto done; - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 ) goto done; val &= ~(PM_CTL_ED_EN_ |PM_CTL_WOL_EN_ ); - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 ) goto done;
@@ -1744,7 +1732,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) }for (i =0 ; i < (wuff_filter_count *4 ); i++) { - ret =smsc95xx_write_reg_nopm (dev,WUFF , filter_mask[i]); + ret =smsc95xx_write_reg (dev,WUFF , filter_mask[i]);if (ret <0 ) {kfree (filter_mask); goto done;
@@ -1753,50 +1741,50 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)kfree (filter_mask);for (i =0 ; i < (wuff_filter_count /4 ); i++) { - ret =smsc95xx_write_reg_nopm (dev,WUFF , command[i]); + ret =smsc95xx_write_reg (dev,WUFF , command[i]);if (ret <0 ) goto done; }for (i =0 ; i < (wuff_filter_count /4 ); i++) { - ret =smsc95xx_write_reg_nopm (dev,WUFF , offset[i]); + ret =smsc95xx_write_reg (dev,WUFF , offset[i]);if (ret <0 ) goto done; }for (i =0 ; i < (wuff_filter_count /2 ); i++) { - ret =smsc95xx_write_reg_nopm (dev,WUFF , crc[i]); + ret =smsc95xx_write_reg (dev,WUFF , crc[i]);if (ret <0 ) goto done; }/* clear any pending pattern match packet status */ - ret =smsc95xx_read_reg_nopm (dev,WUCSR , &val); + ret =smsc95xx_read_reg (dev,WUCSR , &val);if (ret <0 ) goto done; val |=WUCSR_WUFR_ ; - ret =smsc95xx_write_reg_nopm (dev,WUCSR , val); + ret =smsc95xx_write_reg (dev,WUCSR , val);if (ret <0 ) goto done; }if (pdata->wolopts &WAKE_MAGIC ) {/* clear any pending magic packet status */ - ret =smsc95xx_read_reg_nopm (dev,WUCSR , &val); + ret =smsc95xx_read_reg (dev,WUCSR , &val);if (ret <0 ) goto done; val |=WUCSR_MPR_ ; - ret =smsc95xx_write_reg_nopm (dev,WUCSR , val); + ret =smsc95xx_write_reg (dev,WUCSR , val);if (ret <0 ) goto done; }/* enable/disable wakeup sources */ - ret =smsc95xx_read_reg_nopm (dev,WUCSR , &val); + ret =smsc95xx_read_reg (dev,WUCSR , &val);if (ret <0 ) goto done;
@@ -1816,12 +1804,12 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message) val &= ~WUCSR_MPEN_ ; } - ret =smsc95xx_write_reg_nopm (dev,WUCSR , val); + ret =smsc95xx_write_reg (dev,WUCSR , val);if (ret <0 ) goto done;/* enable wol wakeup source */ - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 ) goto done;
@@ -1831,7 +1819,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)if (pdata->wolopts &WAKE_PHY ) val |=PM_CTL_ED_EN_ ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 ) goto done;
@@ -1877,25 +1865,25 @@ static int smsc95xx_resume(struct usb_interface *intf)if (suspend_flags &SUSPEND_ALLMODES ) {/* clear wake-up sources */ - ret =smsc95xx_read_reg_nopm (dev,WUCSR , &val); + ret =smsc95xx_read_reg (dev,WUCSR , &val);if (ret <0 )return ret; val &= ~(WUCSR_WAKE_EN_ |WUCSR_MPEN_ ); - ret =smsc95xx_write_reg_nopm (dev,WUCSR , val); + ret =smsc95xx_write_reg (dev,WUCSR , val);if (ret <0 )return ret;/* clear wake-up status */ - ret =smsc95xx_read_reg_nopm (dev,PM_CTRL , &val); + ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )return ret; val &= ~PM_CTL_WOL_EN_ ; val |=PM_CTL_WUPS_ ; - ret =smsc95xx_write_reg_nopm (dev,PM_CTRL , val); + ret =smsc95xx_write_reg (dev,PM_CTRL , val);if (ret <0 )return ret; }
PATCH 4/19 usbnet: smsc95xx: Remove __smsc95xx_{read,write}_reg()
In reply to Marek VasutInline those functions into smsc95xx_{read,write}_reg() to get rid of the wrapper.
--- drivers/net/usb/smsc95xx.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-)
drivers/net/usb/smsc95xx.c +10 -22
@@ -87,8 +87,8 @@ static int smsc95xx_in_pm(struct usbnet *dev)return dev->suspend_count !=0 ; } -static int __must_check __smsc95xx_read_reg (struct usbnet *dev,u32 index, -u32 *data) +static int __must_check smsc95xx_read_reg (struct usbnet *dev,u32 index, +u32 *data) {u32 buf;int ret;
@@ -116,8 +116,8 @@ static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,return ret; } -static int __must_check __smsc95xx_write_reg (struct usbnet *dev,u32 index, -u32 data) +static int __must_check smsc95xx_write_reg (struct usbnet *dev,u32 index, +u32 data) {u32 buf;int ret;
@@ -143,18 +143,6 @@ static int __must_check __smsc95xx_write_reg(struct usbnet *dev, u32 index,return ret; } -static int __must_check smsc95xx_read_reg (struct usbnet *dev,u32 index, -u32 *data) -{ -return __smsc95xx_read_reg (dev, index, data); -} - -static int __must_check smsc95xx_write_reg (struct usbnet *dev,u32 index, -u32 data) -{ -return __smsc95xx_write_reg (dev, index, data); -} -/* Loop until the read is completed with timeout * called with phy_mutex held */ static int __must_check __smsc95xx_phy_wait_not_busy (struct usbnet *dev)
@@ -164,7 +152,7 @@ static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev)int ret; do { - ret = __smsc95xx_read_reg(dev, MII_ADDR, &val); + ret = smsc95xx_read_reg(dev, MII_ADDR, &val); if (ret < 0) { netdev_warn(dev->net, "Error reading MII_ACCESS\n"); return ret;
@@ -196,7 +184,7 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) phy_id &= dev->mii.phy_id_mask; idx &= dev->mii.reg_num_mask; addr = (phy_id <<11 ) | (idx <<6 ) |MII_READ_ |MII_BUSY_ ; - ret =__smsc95xx_write_reg (dev,MII_ADDR , addr); + ret =smsc95xx_write_reg (dev,MII_ADDR , addr);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_ADDR\n" ); goto done;
@@ -208,7 +196,7 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) goto done; } - ret =__smsc95xx_read_reg (dev,MII_DATA , &val); + ret =smsc95xx_read_reg (dev,MII_DATA , &val);if (ret <0 ) {netdev_warn (dev->net,"Error reading MII_DATA\n" ); goto done;
@@ -238,7 +226,7 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, } val = regval; - ret =__smsc95xx_write_reg (dev,MII_DATA , val); + ret =smsc95xx_write_reg (dev,MII_DATA , val);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_DATA\n" ); goto done;
@@ -248,7 +236,7 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id, phy_id &= dev->mii.phy_id_mask; idx &= dev->mii.reg_num_mask; addr = (phy_id <<11 ) | (idx <<6 ) |MII_WRITE_ |MII_BUSY_ ; - ret =__smsc95xx_write_reg (dev,MII_ADDR , addr); + ret =smsc95xx_write_reg (dev,MII_ADDR , addr);if (ret <0 ) {netdev_warn (dev->net,"Error writing MII_ADDR\n" ); goto done;
@@ -972,7 +960,7 @@ static int smsc95xx_start_rx_path(struct usbnet *dev) pdata->mac_cr |=MAC_CR_RXEN_ ;spin_unlock_irqrestore (&pdata->mac_cr_lock, flags); -return __smsc95xx_write_reg (dev,MAC_CR , pdata->mac_cr); +return smsc95xx_write_reg (dev,MAC_CR , pdata->mac_cr); }static int smsc95xx_phy_initialize (struct usbnet *dev)
PATCH 5/19 usbnet: smsc95xx: Remove smsc95xx_{read,write}_nopm()
In reply to Marek VasutThese functions are now equal to smsc95xx_mdio_{read,write}(), deduplicate them.
--- drivers/net/usb/smsc95xx.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/net/usb/smsc95xx.c +9 -21
@@ -252,18 +252,6 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,mutex_unlock (&dev->phy_mutex); } -static int smsc95xx_mdio_read_nopm (struct net_device *netdev,int phy_id, -int idx) -{ -return __smsc95xx_mdio_read (netdev, phy_id, idx); -} - -static void smsc95xx_mdio_write_nopm (struct net_device *netdev,int phy_id, -int idx,int regval) -{ -__smsc95xx_mdio_write (netdev, phy_id, idx, regval); -} -static int smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) {return __smsc95xx_mdio_read (netdev, phy_id, idx);
@@ -1340,18 +1328,18 @@ static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)netdev_dbg (dev->net,"enabling PHY wakeup interrupts\n" );/* read to clear */ - ret =smsc95xx_mdio_read_nopm (dev->net, mii->phy_id,PHY_INT_SRC ); + ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_INT_SRC );if (ret <0 )return ret;/* enable interrupt source */ - ret =smsc95xx_mdio_read_nopm (dev->net, mii->phy_id,PHY_INT_MASK ); + ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_INT_MASK );if (ret <0 )return ret; ret |= mask; -smsc95xx_mdio_write_nopm (dev->net, mii->phy_id,PHY_INT_MASK , ret); +smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_INT_MASK , ret);return 0 ; }
@@ -1362,11 +1350,11 @@ static int smsc95xx_link_ok_nopm(struct usbnet *dev)int ret;/* first, a dummy read, needed to latch some MII phys */ - ret =smsc95xx_mdio_read_nopm (dev->net, mii->phy_id,MII_BMSR ); + ret =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_BMSR );if (ret <0 )return ret; - ret =smsc95xx_mdio_read_nopm (dev->net, mii->phy_id,MII_BMSR ); + ret =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_BMSR );if (ret <0 )return ret;
@@ -1423,17 +1411,17 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev)* compatibility with non-standard link partners */ if (pdata->features &FEATURE_PHY_NLP_CROSSOVER ) -smsc95xx_mdio_write_nopm (dev->net, mii->phy_id,PHY_EDPD_CONFIG , -PHY_EDPD_CONFIG_DEFAULT ); +smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_EDPD_CONFIG , +PHY_EDPD_CONFIG_DEFAULT );/* enable energy detect power-down mode */ - ret =smsc95xx_mdio_read_nopm (dev->net, mii->phy_id,PHY_MODE_CTRL_STS ); + ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_MODE_CTRL_STS );if (ret <0 )return ret; ret |=MODE_CTRL_STS_EDPWRDOWN_ ; -smsc95xx_mdio_write_nopm (dev->net, mii->phy_id,PHY_MODE_CTRL_STS , ret); +smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_MODE_CTRL_STS , ret);/* enter SUSPEND1 mode */ ret =smsc95xx_read_reg (dev,PM_CTRL , &val);
PATCH 6/19 usbnet: smsc95xx: Remove __smsc95xx_mdio_{read,write}()
In reply to Marek VasutInline those functions into smsc95xx_mdio_{read,write}() to get rid of the wrapper.
--- drivers/net/usb/smsc95xx.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/net/usb/smsc95xx.c +3 -14
@@ -165,7 +165,7 @@ static int __must_check __smsc95xx_phy_wait_not_busy(struct usbnet *dev)return -EIO ; } -static int __smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) +static int smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) {struct usbnet *dev =netdev_priv (netdev);u32 val, addr;
@@ -209,8 +209,8 @@ static int __smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)return ret; } -static void __smsc95xx_mdio_write (struct net_device *netdev,int phy_id, -int idx,int regval) +static void smsc95xx_mdio_write (struct net_device *netdev,int phy_id, +int idx,int regval) {struct usbnet *dev =netdev_priv (netdev);u32 val, addr;
@@ -252,17 +252,6 @@ static void __smsc95xx_mdio_write(struct net_device *netdev, int phy_id,mutex_unlock (&dev->phy_mutex); } -static int smsc95xx_mdio_read (struct net_device *netdev,int phy_id,int idx) -{ -return __smsc95xx_mdio_read (netdev, phy_id, idx); -} - -static void smsc95xx_mdio_write (struct net_device *netdev,int phy_id,int idx, -int regval) -{ -__smsc95xx_mdio_write (netdev, phy_id, idx, regval); -} -static int __must_check smsc95xx_wait_eeprom (struct usbnet *dev) {unsigned long start_time = jiffies;
PATCH 7/19 usbnet: smsc95xx: Split the reset function
In reply to Marek VasutThe smsc95xx_reset() is called either during bind or later during the driver operation. However, the MII structure can be populated only once, when the smsc95xx_reset() is called from the drivers bind function.
Split the reset function to allow filling the MII structure only once. This is done in preparation of phydev conversion, where the code will connect to PHY between those two halves of the reset function.
--- drivers/net/usb/smsc95xx.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)
drivers/net/usb/smsc95xx.c +27 -9
@@ -944,14 +944,6 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) {int bmcr, ret, timeout =0 ; -/* Initialize MII structure */ - dev->mii.dev = dev->net; - dev->mii.mdio_read = smsc95xx_mdio_read; - dev->mii.mdio_write = smsc95xx_mdio_write; - dev->mii.phy_id_mask =0x1f ; - dev->mii.reg_num_mask =0x1f ; - dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; -/* reset phy and wait for reset to complete */ smsc95xx_mdio_write (dev->net, dev->mii.phy_id,MII_BMCR ,BMCR_RESET );
@@ -985,7 +977,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)return 0 ; } -static int smsc95xx_reset (struct usbnet *dev) +static int smsc95xx_reset_pre (struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);u32 read_buf, write_buf, burst_cap;
@@ -1165,6 +1157,13 @@ static int smsc95xx_reset(struct usbnet *dev) }smsc95xx_set_multicast (dev->net); +return 0 ; +} + +static int smsc95xx_reset_post (struct usbnet *dev) +{ +u32 read_buf; +int ret; ret =smsc95xx_phy_initialize (dev);if (ret <0 ) {
@@ -1199,6 +1198,25 @@ static int smsc95xx_reset(struct usbnet *dev)return 0 ; } +static int smsc95xx_reset (struct usbnet *dev) +{ +int ret; + + ret =smsc95xx_reset_pre (dev); +if (ret) +return ret; + +/* Initialize MII structure */ + dev->mii.dev = dev->net; + dev->mii.mdio_read = smsc95xx_mdio_read; + dev->mii.mdio_write = smsc95xx_mdio_write; + dev->mii.phy_id_mask =0x1f ; + dev->mii.reg_num_mask =0x1f ; + dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; + +return smsc95xx_reset_post (dev); +} +static const struct net_device_ops smsc95xx_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop,
Re: [PATCH 07/19] usbnet: smsc95xx: Split the reset function
Quoted 42 lines · Marek Vasut
The
smsc95xx_reset()is called either during bind or later during the driver operation. However, the MII structure can be populated only once, when thesmsc95xx_reset()is called from the drivers bind function.Split the reset function to allow filling the MII structure only once. This is done in preparation of phydev conversion, where the code will connect to PHY between those two halves of the reset function.
Signed-off-by Marek Vasut <[email protected]>Cc David S. Miller <[email protected]>Cc Nisar Sayed <[email protected]>Cc Woojung Huh <[email protected]>Cc Andrew Lunn <[email protected]>Cc Florian Fainelli <[email protected]>--- drivers/net/usb/smsc95xx.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-)drivers/net/usb/smsc95xx.c +0
-8@@ -944,14 +944,6 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) {int bmcr, ret, timeout =0 ; -/* Initialize MII structure */ - dev->mii.dev = dev->net; - dev->mii.mdio_read = smsc95xx_mdio_read; - dev->mii.mdio_write = smsc95xx_mdio_write; - dev->mii.phy_id_mask =0x1f ; - dev->mii.reg_num_mask =0x1f ; - dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; -/* reset phy and wait for reset to complete */ smsc95xx_mdio_write (dev->net, dev->mii.phy_id,MII_BMCR ,BMCR_RESET );
drivers/net/usb/smsc95xx.c static int smsc95xx_phy_initialize(struct usbnet *dev) · line 980
Quoted 5 lines
drivers/net/usb/smsc95xx.c +1
-1@@ -985,7 +977,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)return 0 ; } -static int smsc95xx_reset (struct usbnet *dev) +static int smsc95xx_reset_pre (struct usbnet *dev)
Hi,
may I request that you choose different names? These names suggest a connection with the pre_reset() and post_reset() methods of a USB driver.
Regards
Oliver
PATCH 8/19 usbnet: smsc95xx: Register MII bus
In reply to Marek VasutRegister MII bus so that a phydev can attach to it. This works in parallel with the existing MII bus accessors within the driver, however the existing accessors will be removed in subsequent patch.
--- drivers/net/usb/smsc95xx.c | 77 ++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 12 deletions(-)
drivers/net/usb/smsc95xx.c +65 -12
@@ -30,6 +30,7 @@#include <linux/usb/usbnet.h> #include <linux/slab.h> #include <linux/of_net.h> +#include <linux/phy.h> #include "smsc95xx.h" #define SMSC_CHIPNAME "smsc95xx"
@@ -76,6 +77,7 @@ struct smsc95xx_priv {bool link_ok;struct delayed_work carrier_check;struct usbnet *dev; +struct mii_bus *mii_bus; };static bool turbo_mode = true;
@@ -209,6 +211,14 @@ static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)return ret; } +static int smsc95xx_mii_read (struct mii_bus *bus,int phy_id,int reg) +{ +struct usbnet *dev = bus->priv; +struct net_device *netdev = dev->net; + +return smsc95xx_mdio_read (netdev, phy_id, reg); +} +static void smsc95xx_mdio_write (struct net_device *netdev,int phy_id,int idx,int regval) {
@@ -252,6 +262,16 @@ static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id,mutex_unlock (&dev->phy_mutex); } +static int smsc95xx_mii_write (struct mii_bus *bus,int phy_id,int reg,u16 val) +{ +struct usbnet *dev = bus->priv; +struct net_device *netdev = dev->net; + +smsc95xx_mdio_write (netdev, phy_id, reg, val); + +return 0 ; +} +static int __must_check smsc95xx_wait_eeprom (struct usbnet *dev) {unsigned long start_time = jiffies;
@@ -1206,14 +1226,6 @@ static int smsc95xx_reset(struct usbnet *dev)if (ret)return ret; -/* Initialize MII structure */ - dev->mii.dev = dev->net; - dev->mii.mdio_read = smsc95xx_mdio_read; - dev->mii.mdio_write = smsc95xx_mdio_write; - dev->mii.phy_id_mask =0x1f ; - dev->mii.reg_num_mask =0x1f ; - dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; -return smsc95xx_reset_post (dev); }
@@ -1234,6 +1246,7 @@ static const struct net_device_ops smsc95xx_netdev_ops = {static int smsc95xx_bind (struct usbnet *dev,struct usb_interface *intf) {struct smsc95xx_priv *pdata =NULL ; +struct mii_bus *bus;u32 val;int ret;
@@ -1252,6 +1265,25 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)if (!pdata)return -ENOMEM ; + pdata->dev = dev; + + bus =mdiobus_alloc (); +if (!bus) { + ret = -ENOMEM ; + goto err_mdiobus_alloc; + } + + bus->priv = dev; + bus->name ="smsc95xx_mii_bus" ; + bus->read = smsc95xx_mii_read; + bus->write = smsc95xx_mii_write; + bus->parent = dev->net->dev.parent; + bus->phy_mask =BIT (0 ); +snprintf (bus->id,MII_BUS_ID_SIZE ,"usb-%03d:%03d" , + dev->udev->bus->busnum, dev->udev->devnum); + + pdata->mii_bus = bus; +spin_lock_init (&pdata->mac_cr_lock);/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
@@ -1272,12 +1304,30 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)smsc95xx_init_mac_address (dev);/* Init all registers */ - ret =smsc95xx_reset (dev); + ret =smsc95xx_reset_pre (dev); +if (ret) + goto err_mdiobus_alloc; + +/* Initialize MII structure */ + dev->mii.dev = dev->net; + dev->mii.mdio_read = smsc95xx_mdio_read; + dev->mii.mdio_write = smsc95xx_mdio_write; + dev->mii.phy_id_mask =0x1f ; + dev->mii.reg_num_mask =0x1f ; + dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; + + ret =mdiobus_register (bus); +if (ret) + goto err_mdiobus_register; + + ret =smsc95xx_reset_post (dev); +if (ret) + goto err_mdiobus_register;/* detect device revision as different features may be available */ ret =smsc95xx_read_reg (dev,ID_REV , &val);if (ret <0 ) - goto err_read_reg; + goto err_mdiobus_register; val >>=16 ; pdata->chip_id = val; pdata->mdix_ctrl =get_mdix_status (dev->net);
@@ -1298,12 +1348,13 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->max_mtu =ETH_DATA_LEN ; dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; - pdata->dev = dev;INIT_DELAYED_WORK (&pdata->carrier_check, check_carrier);schedule_delayed_work (&pdata->carrier_check,CARRIER_CHECK_DELAY );return 0 ; -err_read_reg: +err_mdiobus_register: +mdiobus_free (bus); +err_mdiobus_alloc:kfree (pdata);return ret; }
@@ -1315,6 +1366,8 @@ static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)if (pdata) {cancel_delayed_work (&pdata->carrier_check);netif_dbg (dev, ifdown, dev->net,"free pdata\n" ); +mdiobus_unregister (pdata->mii_bus); +mdiobus_free (pdata->mii_bus);kfree (pdata); pdata =NULL ; dev->data[0 ] =0 ;
PATCH 9/19 usbnet: smsc95xx: Connect to phydev
In reply to Marek VasutAdd code to detect and connect to PHY. The internal PHY of the SMSC95xx is a regular SMSC LAN8700 and the driver only supports the internal PHY, so just use the SMSC PHY driver to configure the PHY. Note that the driver does a lot of extra configuration of the PHY, which is left in to avoid breakage. Some of the extra configuration is sorted out by later patches in this series.
--- drivers/net/usb/smsc95xx.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
drivers/net/usb/smsc95xx.c +27 -2
@@ -78,6 +78,7 @@ struct smsc95xx_priv {struct delayed_work carrier_check;struct usbnet *dev;struct mii_bus *mii_bus; +struct phy_device *phydev; };static bool turbo_mode = true;
@@ -960,6 +961,11 @@ static int smsc95xx_start_rx_path(struct usbnet *dev)return smsc95xx_write_reg (dev,MAC_CR , pdata->mac_cr); } + +static void smsc95xx_adjust_link (struct net_device *netdev) +{ +} +static int smsc95xx_phy_initialize (struct usbnet *dev) {int bmcr, ret, timeout =0 ;
@@ -1308,6 +1314,10 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)if (ret) goto err_mdiobus_alloc; + ret =mdiobus_register (bus); +if (ret) + goto err_mdiobus_register; +/* Initialize MII structure */ dev->mii.dev = dev->net; dev->mii.mdio_read = smsc95xx_mdio_read;
@@ -1316,9 +1326,24 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->mii.reg_num_mask =0x1f ; dev->mii.phy_id =SMSC95XX_INTERNAL_PHY_ID ; - ret =mdiobus_register (bus); -if (ret) +/* Connect to PHY */ + pdata->phydev =phy_find_first (pdata->mii_bus); +if (!pdata->phydev) { +netdev_err (dev->net,"no PHY found\n" ); + ret = -EIO ; goto err_mdiobus_register; + } + + ret =phy_connect_direct (dev->net, pdata->phydev, + &smsc95xx_adjust_link, +PHY_INTERFACE_MODE_MII ); +if (ret) { +netdev_err (dev->net,"Could not connect to PHY device\n" ); + goto err_mdiobus_register; + } + +genphy_resume (pdata->phydev); +phy_start (pdata->phydev); ret =smsc95xx_reset_post (dev);if (ret)
Re: [PATCH 09/19] usbnet: smsc95xx: Connect to phydev
Quoted 6 lines · Marek Vasut
Add code to detect and connect to PHY. The internal PHY of the SMSC95xx is a regular SMSC LAN8700 and the driver only supports the internal PHY, so just use the SMSC PHY driver to configure the PHY. Note that the driver does a lot of extra configuration of the PHY, which is left in to avoid breakage. Some of the extra configuration is sorted out by later patches in this series.
Hi Marek
A MAC driver is not expected to touch the PHY at all. Please try to remove as much of the extra configuration as possible, adding it to the LAN8700 PHY driver as needed.
You also have to be careful of locking. phylib takes the phydev lock when calling into the PHY driver. Anything the MAC does to the PHY is not going to be done with this lock held. So bad things can happen.
Andrew
Re: [PATCH 09/19] usbnet: smsc95xx: Connect to phydev
Quoted 11 lines · Andrew Lunn
Quoted 6 lines · Marek Vasut
Add code to detect and connect to PHY. The internal PHY of the SMSC95xx is a regular SMSC LAN8700 and the driver only supports the internal PHY, so just use the SMSC PHY driver to configure the PHY. Note that the driver does a lot of extra configuration of the PHY, which is left in to avoid breakage. Some of the extra configuration is sorted out by later patches in this series.
Hi Marek
A MAC driver is not expected to touch the PHY at all.
Well, sure, that's not how the SMSC95xx driver is implemented. This series tries to make that a bit better.
Quoted 3 lines
Please try to
remove as much of the extra configuration as possible, adding it to the LAN8700 PHY driver as needed.
Sure, that's the plan.
Quoted 3 lines
You also have to be careful of locking. phylib takes the phydev lock when calling into the PHY driver. Anything the MAC does to the PHY is not going to be done with this lock held. So bad things can happen.
I think I can add a patch which grabs the lock in the MDIO accessors used by the SMSC95xx driver, at least temporarily, until it is fully migrated to phydev ? Or is there a better option ?
PATCH 10/19 usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
In reply to Marek VasutJust replace smsc95xx_mdio_read() with generic phy_read() to reduce usage of the ad-hoc accessors.
--- drivers/net/usb/smsc95xx.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
drivers/net/usb/smsc95xx.c +20 -17
@@ -547,7 +547,7 @@ static int smsc95xx_link_reset(struct usbnet *dev)int ret;/* clear interrupt status */ - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_INT_SRC ); + ret =phy_read (pdata->phydev,PHY_INT_SRC );if (ret <0 )return ret;
@@ -557,8 +557,8 @@ static int smsc95xx_link_reset(struct usbnet *dev)mii_check_media (mii,1 ,1 );mii_ethtool_gset (&dev->mii, &ecmd); - lcladv =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_ADVERTISE ); - rmtadv =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_LPA ); + lcladv =phy_read (pdata->phydev,MII_ADVERTISE ); + rmtadv =phy_read (pdata->phydev,MII_LPA ); netif_dbg(dev, link, dev->net, "speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n",
@@ -630,7 +630,7 @@ static void check_carrier(struct work_struct *work)if (pdata->suspend_flags !=0 )return ; - ret =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,MII_BMSR ); + ret =phy_read (pdata->phydev,MII_BMSR );if (ret <0 ) {netdev_warn (dev->net,"Failed to read MII_BMSR\n" );return ;
@@ -764,10 +764,11 @@ static int smsc95xx_ethtool_set_wol(struct net_device *net,static int get_mdix_status (struct net_device *net) {struct usbnet *dev =netdev_priv (net); +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);u32 val;int buf; - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS ); + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS );if (buf &SPECIAL_CTRL_STS_OVRRD_AMDIX_ ) {if (buf &SPECIAL_CTRL_STS_AMDIX_ENABLE_ )return ETH_TP_MDI_AUTO ;
@@ -793,7 +794,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) (pdata->chip_id == ID_REV_CHIP_ID_89530_) || (pdata->chip_id == ID_REV_CHIP_ID_9730_)) {/* Extend Manual AutoMDIX timer for 9500A/9500Ai */ - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,PHY_EDPD_CONFIG ); buf |=PHY_EDPD_CONFIG_EXT_CROSSOVER_ ; smsc95xx_mdio_write(dev->net, dev->mii.phy_id,
@@ -801,7 +802,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) }if (mdix_ctrl ==ETH_TP_MDI ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |
@@ -809,7 +810,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_X ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |
@@ -818,7 +819,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_AUTO ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |
@@ -968,6 +969,7 @@ static void smsc95xx_adjust_link(struct net_device *netdev)static int smsc95xx_phy_initialize (struct usbnet *dev) { +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);int bmcr, ret, timeout =0 ;/* reset phy and wait for reset to complete */
@@ -975,7 +977,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)do {msleep (10 ); - bmcr =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,MII_BMCR ); + bmcr =phy_read (pdata->phydev,MII_BMCR ); timeout++; }while ((bmcr &BMCR_RESET ) && (timeout <100 ));
@@ -989,7 +991,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) ADVERTISE_PAUSE_ASYM);/* read to clear */ - ret =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,PHY_INT_SRC ); + ret =phy_read (pdata->phydev,PHY_INT_SRC );if (ret <0 ) {netdev_warn (dev->net,"Failed to read PHY_INT_SRC during init\n" );return ret;
@@ -1407,18 +1409,19 @@ static u32 smsc_crc(const u8 *buffer, size_t len, int filter)static int smsc95xx_enable_phy_wakeup_interrupts (struct usbnet *dev,u16 mask) { +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);struct mii_if_info *mii = &dev->mii;int ret;netdev_dbg (dev->net,"enabling PHY wakeup interrupts\n" );/* read to clear */ - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_INT_SRC ); + ret =phy_read (pdata->phydev,PHY_INT_SRC );if (ret <0 )return ret;/* enable interrupt source */ - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_INT_MASK ); + ret =phy_read (pdata->phydev,PHY_INT_MASK );if (ret <0 )return ret;
@@ -1431,15 +1434,15 @@ static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)static int smsc95xx_link_ok_nopm (struct usbnet *dev) { -struct mii_if_info *mii = &dev->mii; +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);int ret;/* first, a dummy read, needed to latch some MII phys */ - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_BMSR ); + ret =phy_read (pdata->phydev,MII_BMSR );if (ret <0 )return ret; - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,MII_BMSR ); + ret =phy_read (pdata->phydev,MII_BMSR );if (ret <0 )return ret;
@@ -1500,7 +1503,7 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev) PHY_EDPD_CONFIG_DEFAULT);/* enable energy detect power-down mode */ - ret =smsc95xx_mdio_read (dev->net, mii->phy_id,PHY_MODE_CTRL_STS ); + ret =phy_read (pdata->phydev,PHY_MODE_CTRL_STS );if (ret <0 )return ret;
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
drivers/net/usb/smsc95xx.c static void smsc95xx_adjust_link(struct net_device *netdev)
Quoted 49 lines
static int
get_mdix_status(struct net_device *net){drivers/net/usb/smsc95xx.c +6
-5struct usbnet *dev =netdev_priv (net); +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);u32 val;int buf; - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS ); + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS );if (buf &SPECIAL_CTRL_STS_OVRRD_AMDIX_ ) {if (buf &SPECIAL_CTRL_STS_AMDIX_ENABLE_ )return ETH_TP_MDI_AUTO ;@@ -793,7 +794,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) (pdata->chip_id == ID_REV_CHIP_ID_89530_) || (pdata->chip_id == ID_REV_CHIP_ID_9730_)) {/* Extend Manual AutoMDIX timer for 9500A/9500Ai */ - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,PHY_EDPD_CONFIG ); buf |=PHY_EDPD_CONFIG_EXT_CROSSOVER_ ; smsc95xx_mdio_write(dev->net, dev->mii.phy_id,@@ -801,7 +802,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) }if (mdix_ctrl ==ETH_TP_MDI ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -809,7 +810,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_X ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -818,7 +819,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_AUTO ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -968,6 +969,7 @@ static void smsc95xx_adjust_link(struct net_device *netdev)
All this crossover code should be moved into the PHY driver.
Andrew
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
Quoted 43 lines · Andrew Lunn
Quoted 43 lines
static int
get_mdix_status(struct net_device *net){drivers/net/usb/smsc95xx.c +5
-4struct usbnet *dev =netdev_priv (net); +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);u32 val;int buf; - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS ); + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS );if (buf &SPECIAL_CTRL_STS_OVRRD_AMDIX_ ) {if (buf &SPECIAL_CTRL_STS_AMDIX_ENABLE_ )return ETH_TP_MDI_AUTO ;@@ -793,7 +794,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) (pdata->chip_id == ID_REV_CHIP_ID_89530_) || (pdata->chip_id == ID_REV_CHIP_ID_9730_)) {/* Extend Manual AutoMDIX timer for 9500A/9500Ai */ - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,PHY_EDPD_CONFIG ); buf |=PHY_EDPD_CONFIG_EXT_CROSSOVER_ ; smsc95xx_mdio_write(dev->net, dev->mii.phy_id,@@ -801,7 +802,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) }if (mdix_ctrl ==ETH_TP_MDI ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -809,7 +810,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_X ) { - buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -818,7 +819,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)smsc95xx_mdio_write (dev->net, dev->mii.phy_id,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_AUTO ) {
Quoted 8 lines
drivers/net/usb/smsc95xx.c static void smsc95xx_adjust_link(struct net_device *netdev)
Quoted 6 lines
drivers/net/usb/smsc95xx.c +1
-1- buf =smsc95xx_mdio_read (dev->net, dev->mii.phy_id, + buf =phy_read (pdata->phydev,SPECIAL_CTRL_STS ); buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |@@ -968,6 +969,7 @@ static void smsc95xx_adjust_link(struct net_device *netdev)All this crossover code should be moved into the PHY driver.
Fine, this can be done in a subsequent patch though, right ? I'd like to keep the changes small, so if something breaks, it could be bisected easily.
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
Quoted 4 lines
Quoted 1 line
All this crossover code should be moved into the PHY driver.
Fine, this can be done in a subsequent patch though, right ? I'd like to keep the changes small, so if something breaks, it could be bisected easily.
Hi Marek
The problem is, do you have a regression because of the changes you made here, or because you have two things controlling the PHY, the MAC driver and the PHY driver, which are not coordinating?
I don't know if you can do a piecemeal conversation like this. I don't remember anybody else doing anything like this before.
What you can do piecemeal is add new functionality to the existing PHY driver. If you break the PHY driver we can then bisect it to find out which change broke it. Once the PHY driver has everything you need, then swap the MAC driver to use phylib.
Thanks
Andrew
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
Quoted 6 lines · Andrew Lunn
Quoted 4 lines
Quoted 1 line
All this crossover code should be moved into the PHY driver.
Fine, this can be done in a subsequent patch though, right ? I'd like to keep the changes small, so if something breaks, it could be bisected easily.
Hi Marek
Hi,
Quoted 6 lines
The problem is, do you have a regression because of the changes you made here, or because you have two things controlling the PHY, the MAC driver and the PHY driver, which are not coordinating?
I don't know if you can do a piecemeal conversation like this. I don't remember anybody else doing anything like this before.
I'd prefer that.
Quoted 4 lines
What you can do piecemeal is add new functionality to the existing PHY driver. If you break the PHY driver we can then bisect it to find out which change broke it. Once the PHY driver has everything you need, then swap the MAC driver to use phylib.
I wonder, if I use the phylib functions instead of the ad-hoc ones in the MAC driver, is there still a problem with synchronization ?
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
Quoted 2 lines
I wonder, if I use the phylib functions instead of the ad-hoc ones in the MAC driver, is there still a problem with synchronization ?
You would need to look deep into phylib. When does it reset the PHY? Configure auto-neg, setup interrupts, etc? It looks like both are going to do this, so i expect they are going to mess each other up.
Andrew
Re: [PATCH 10/19] usbnet: smsc95xx: Replace smsc95xx_mdio_read() with phy_read()
Quoted 7 lines · Andrew Lunn
Quoted 2 lines
I wonder, if I use the phylib functions instead of the ad-hoc ones in the MAC driver, is there still a problem with synchronization ?
You would need to look deep into phylib. When does it reset the PHY? Configure auto-neg, setup interrupts, etc? It looks like both are going to do this, so i expect they are going to mess each other up.
Marek, I recently went through this exercise when switching r8169 driver to phylib. As Andrew explained:
First add needed functionality to the respective PHY driver(s), then you can switch the network driver.
You can look at f1e911d5d0df ("r8169: add basic phylib support") plus related changes, and to what was added to the Realtek PHY driver module.
PATCH 11/19 usbnet: smsc95xx: Replace smsc95xx_mdio_write() with phy_write()
In reply to Marek VasutJust replace smsc95xx_mdio_write() with generic phy_write() to reduce usage of the ad-hoc accessors.
--- drivers/net/usb/smsc95xx.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/net/usb/smsc95xx.c +10 -12
@@ -797,7 +797,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) buf =phy_read (pdata->phydev,PHY_EDPD_CONFIG ); buf |=PHY_EDPD_CONFIG_EXT_CROSSOVER_ ; -smsc95xx_mdio_write (dev->net, dev->mii.phy_id, +phy_write (pdata->phydev,PHY_EDPD_CONFIG , buf); }
@@ -807,7 +807,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |SPECIAL_CTRL_STS_AMDIX_STATE_ ); -smsc95xx_mdio_write (dev->net, dev->mii.phy_id, +phy_write (pdata->phydev,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_X ) { buf = phy_read(pdata->phydev,
@@ -816,7 +816,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |SPECIAL_CTRL_STS_AMDIX_STATE_ ); buf |=SPECIAL_CTRL_STS_AMDIX_STATE_ ; -smsc95xx_mdio_write (dev->net, dev->mii.phy_id, +phy_write (pdata->phydev,SPECIAL_CTRL_STS , buf); }else if (mdix_ctrl ==ETH_TP_MDI_AUTO ) { buf = phy_read(pdata->phydev,
@@ -825,7 +825,7 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ |SPECIAL_CTRL_STS_AMDIX_STATE_ ); buf |=SPECIAL_CTRL_STS_AMDIX_ENABLE_ ; -smsc95xx_mdio_write (dev->net, dev->mii.phy_id, +phy_write (pdata->phydev,SPECIAL_CTRL_STS , buf); } pdata->mdix_ctrl = mdix_ctrl;
@@ -973,7 +973,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)int bmcr, ret, timeout =0 ;/* reset phy and wait for reset to complete */ -smsc95xx_mdio_write (dev->net, dev->mii.phy_id,MII_BMCR ,BMCR_RESET ); +phy_write (pdata->phydev,MII_BMCR ,BMCR_RESET ); do { msleep(10);
@@ -986,7 +986,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)return -EIO ; } -smsc95xx_mdio_write (dev->net, dev->mii.phy_id,MII_ADVERTISE , +phy_write (pdata->phydev,MII_ADVERTISE ,ADVERTISE_ALL |ADVERTISE_CSMA |ADVERTISE_PAUSE_CAP |ADVERTISE_PAUSE_ASYM );
@@ -997,7 +997,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)return ret; } -smsc95xx_mdio_write (dev->net, dev->mii.phy_id,PHY_INT_MASK , +phy_write (pdata->phydev,PHY_INT_MASK ,PHY_INT_MASK_DEFAULT_ );mii_nway_restart (&dev->mii);
@@ -1410,7 +1410,6 @@ static u32 smsc_crc(const u8 *buffer, size_t len, int filter)static int smsc95xx_enable_phy_wakeup_interrupts (struct usbnet *dev,u16 mask) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); -struct mii_if_info *mii = &dev->mii;int ret;netdev_dbg (dev->net,"enabling PHY wakeup interrupts\n" );
@@ -1427,7 +1426,7 @@ static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask) ret |= mask; -smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_INT_MASK , ret); +phy_write (pdata->phydev,PHY_INT_MASK , ret);return 0 ; }
@@ -1491,7 +1490,6 @@ static int smsc95xx_enter_suspend0(struct usbnet *dev)static int smsc95xx_enter_suspend1 (struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); -struct mii_if_info *mii = &dev->mii;u32 val;int ret;
@@ -1499,7 +1497,7 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev)* compatibility with non-standard link partners */ if (pdata->features &FEATURE_PHY_NLP_CROSSOVER ) -smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_EDPD_CONFIG , +phy_write (pdata->phydev,PHY_EDPD_CONFIG ,PHY_EDPD_CONFIG_DEFAULT );/* enable energy detect power-down mode */
@@ -1509,7 +1507,7 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev) ret |=MODE_CTRL_STS_EDPWRDOWN_ ; -smsc95xx_mdio_write (dev->net, mii->phy_id,PHY_MODE_CTRL_STS , ret); +phy_write (pdata->phydev,PHY_MODE_CTRL_STS , ret);/* enter SUSPEND1 mode */ ret =smsc95xx_read_reg (dev,PM_CTRL , &val);
PATCH 12/19 usbnet: smsc95xx: Replace ad-hoc PHY functions with generic ones
In reply to Marek VasutReplace the ad-hoc reimplementation of genphy_soft_reset() and genphy_config_aneg() with the generic functions.
--- drivers/net/usb/smsc95xx.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/net/usb/smsc95xx.c +7 -16
@@ -970,25 +970,16 @@ static void smsc95xx_adjust_link(struct net_device *netdev)static int smsc95xx_phy_initialize (struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); -int bmcr, ret, timeout =0 ; +int ret;/* reset phy and wait for reset to complete */ -phy_write (pdata->phydev,MII_BMCR ,BMCR_RESET ); - -do { -msleep (10 ); - bmcr =phy_read (pdata->phydev,MII_BMCR ); - timeout++; - }while ((bmcr &BMCR_RESET ) && (timeout <100 )); - -if (timeout >=100 ) { -netdev_warn (dev->net,"timeout on PHY Reset" ); -return -EIO ; - } + ret =genphy_soft_reset (pdata->phydev); +if (ret) +return ret; -phy_write (pdata->phydev,MII_ADVERTISE , -ADVERTISE_ALL |ADVERTISE_CSMA |ADVERTISE_PAUSE_CAP | -ADVERTISE_PAUSE_ASYM ); + ret =genphy_config_aneg (pdata->phydev); +if (ret) +return ret;/* read to clear */ ret =phy_read (pdata->phydev,PHY_INT_SRC );
Re: [PATCH 12/19] usbnet: smsc95xx: Replace ad-hoc PHY functions with generic ones
Quoted 2 lines · Marek Vasut
Replace the ad-hoc reimplementation of
genphy_soft_reset()andgenphy_config_aneg()with the generic functions.
phylib will either call the phy driver specific reset function, or genphy_soft_reset. The same is also true for configuring auto-neg. Please just kill this code and leave the PHY driver to do its job.
Andrew
Re: [PATCH 12/19] usbnet: smsc95xx: Replace ad-hoc PHY functions with generic ones
Quoted 8 lines · Andrew Lunn
Quoted 2 lines · Marek Vasut
Replace the ad-hoc reimplementation of
genphy_soft_reset()andgenphy_config_aneg()with the generic functions.phylib will either call the phy driver specific reset function, or
genphy_soft_reset. The same is also true for configuring auto-neg. Please just kill this code and leave the PHY driver to do its job.
In this patch or subsequent ? I think we should do that in a subsequent patch, to keep this bisectable in case something breaks.
PATCH 13/19 usbnet: smsc95xx: Replace smsc95xx_link_ok_nopm()
In reply to Marek VasutReplace the function with genphy_update_link(), since that's really all that it is.
--- drivers/net/usb/smsc95xx.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/usb/smsc95xx.c +3 -8
@@ -1427,16 +1427,11 @@ static int smsc95xx_link_ok_nopm(struct usbnet *dev)struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);int ret; -/* first, a dummy read, needed to latch some MII phys */ - ret =phy_read (pdata->phydev,MII_BMSR ); -if (ret <0 ) -return ret; - - ret =phy_read (pdata->phydev,MII_BMSR ); -if (ret <0 ) + ret =genphy_update_link (pdata->phydev); +if (ret)return ret; -return !!(ret &BMSR_LSTATUS ); +return pdata->phydev->link; }static int smsc95xx_enter_suspend0 (struct usbnet *dev)
PATCH 14/19 usbnet: smsc95xx: Replace mii_nway_restart()
In reply to Marek VasutThis is in fact genphy_restart_aneg(), just use the generic phydev function.
--- drivers/net/usb/smsc95xx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/smsc95xx.c +4 -1
@@ -990,7 +990,10 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)phy_write (pdata->phydev,PHY_INT_MASK ,PHY_INT_MASK_DEFAULT_ ); -mii_nway_restart (&dev->mii); + + ret =genphy_restart_aneg (pdata->phydev); +if (ret) +return ret;netif_dbg (dev, ifup, dev->net,"phy initialised successfully\n" );return 0 ;
PATCH 15/19 usbnet: smsc95xx: Replace mii_ethtool_gset()
In reply to Marek VasutReplace mii_ethtool_gset() with a phydev compatible function and update the code to match.
--- drivers/net/usb/smsc95xx.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/usb/smsc95xx.c +6 -5
@@ -541,7 +541,7 @@ static int smsc95xx_link_reset(struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);struct mii_if_info *mii = &dev->mii; -struct ethtool_cmd ecmd = { .cmd =ETHTOOL_GSET }; +struct ethtool_link_ksettings ecmd;unsigned long flags;u16 lcladv, rmtadv;int ret;
@@ -556,16 +556,16 @@ static int smsc95xx_link_reset(struct usbnet *dev)return ret;mii_check_media (mii,1 ,1 ); -mii_ethtool_gset (&dev->mii, &ecmd); +phy_ethtool_ksettings_get (pdata->phydev, &ecmd); lcladv =phy_read (pdata->phydev,MII_ADVERTISE ); rmtadv =phy_read (pdata->phydev,MII_LPA );netif_dbg (dev, link, dev->net,"speed: %u duplex: %d lcladv: %04x rmtadv: %04x\n" , -ethtool_cmd_speed (&ecmd), ecmd.duplex, lcladv, rmtadv); + ecmd.base.speed, ecmd.base.duplex, lcladv, rmtadv);spin_lock_irqsave (&pdata->mac_cr_lock, flags); -if (ecmd.duplex !=DUPLEX_FULL ) { +if (ecmd.base.duplex !=DUPLEX_FULL ) { pdata->mac_cr &= ~MAC_CR_FDPX_ ; pdata->mac_cr |=MAC_CR_RCVOWN_ ; }else {
@@ -578,7 +578,8 @@ static int smsc95xx_link_reset(struct usbnet *dev)if (ret <0 )return ret; - ret =smsc95xx_phy_update_flowcontrol (dev, ecmd.duplex, lcladv, rmtadv); + ret =smsc95xx_phy_update_flowcontrol (dev, ecmd.base.duplex, + lcladv, rmtadv);if (ret <0 )netdev_warn (dev->net,"Error updating PHY flow control\n" );
PATCH 16/19 usbnet: smsc95xx: Replace mii_check_media()
In reply to Marek VasutThe mii_check_media() is called to read out the PHY status registers and update the internal status reported by mii_ethtool_gset(), just replace it with phydev compatible phy_read_status().
--- drivers/net/usb/smsc95xx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/usb/smsc95xx.c +1 -2
@@ -540,7 +540,6 @@ static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,static int smsc95xx_link_reset (struct usbnet *dev) {struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); -struct mii_if_info *mii = &dev->mii;struct ethtool_link_ksettings ecmd;unsigned long flags;u16 lcladv, rmtadv;
@@ -555,7 +554,7 @@ static int smsc95xx_link_reset(struct usbnet *dev)if (ret <0 )return ret; -mii_check_media (mii,1 ,1 ); +phy_read_status (pdata->phydev);phy_ethtool_ksettings_get (pdata->phydev, &ecmd); lcladv =phy_read (pdata->phydev,MII_ADVERTISE ); rmtadv =phy_read (pdata->phydev,MII_LPA );
PATCH 17/19 usbnet: smsc95xx: Replace generic_mii_ioctl()
In reply to Marek VasutReplace generic_mii_ioctl() with phydev compatible phy_mii_ioctl().
--- drivers/net/usb/smsc95xx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/usb/smsc95xx.c +2 -1
@@ -882,11 +882,12 @@ static const struct ethtool_ops smsc95xx_ethtool_ops = {static int smsc95xx_ioctl (struct net_device *netdev,struct ifreq *rq,int cmd) {struct usbnet *dev =netdev_priv (netdev); +struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);if (!netif_running (netdev))return -EINVAL ; -return generic_mii_ioctl (&dev->mii,if_mii (rq), cmd,NULL ); +return phy_mii_ioctl (pdata->phydev, rq, cmd); }static void smsc95xx_init_mac_address (struct usbnet *dev)
PATCH 18/19 usbnet: smsc95xx: Remove all of the carrier checking code
In reply to Marek VasutThe carrier checking code is completely handled by the internal phydev state machine, remove it.
--- drivers/net/usb/smsc95xx.c | 53 ++++---------------------------------- 1 file changed, 5 insertions(+), 48 deletions(-)
drivers/net/usb/smsc95xx.c +5 -48
@@ -75,7 +75,6 @@ struct smsc95xx_priv {u8 suspend_flags;u8 mdix_ctrl;bool link_ok; -struct delayed_work carrier_check;struct usbnet *dev;struct mii_bus *mii_bus;struct phy_device *phydev;
@@ -605,44 +604,6 @@ static void smsc95xx_status(struct usbnet *dev, struct urb *urb) intdata); } -static void set_carrier (struct usbnet *dev,bool link) -{ -struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); - -if (pdata->link_ok == link) -return ; - - pdata->link_ok = link; - -if (link) -usbnet_link_change (dev,1 ,0 ); -else -usbnet_link_change (dev,0 ,0 ); -} - -static void check_carrier (struct work_struct *work) -{ - struct smsc95xx_priv *pdata = container_of(work, struct smsc95xx_priv, - carrier_check.work); -struct usbnet *dev = pdata->dev; -int ret; - -if (pdata->suspend_flags !=0 ) -return ; - - ret =phy_read (pdata->phydev,MII_BMSR ); -if (ret <0 ) { -netdev_warn (dev->net,"Failed to read MII_BMSR\n" ); -return ; - } -if (ret &BMSR_LSTATUS ) -set_carrier (dev,1 ); -else -set_carrier (dev,0 ); - -schedule_delayed_work (&pdata->carrier_check,CARRIER_CHECK_DELAY ); -} -/* Enable or disable Tx & Rx checksum offload engines */ static int smsc95xx_set_features (struct net_device *netdev,netdev_features_t features)
@@ -1370,9 +1331,6 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->max_mtu =ETH_DATA_LEN ; dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len; -INIT_DELAYED_WORK (&pdata->carrier_check, check_carrier); -schedule_delayed_work (&pdata->carrier_check,CARRIER_CHECK_DELAY ); -return 0 ; err_mdiobus_register:mdiobus_free (bus);
@@ -1386,7 +1344,6 @@ static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]);if (pdata) { -cancel_delayed_work (&pdata->carrier_check);netif_dbg (dev, ifdown, dev->net,"free pdata\n" );mdiobus_unregister (pdata->mii_bus);mdiobus_free (pdata->mii_bus);
@@ -1639,14 +1596,14 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)u32 val, link_up;int ret; +phy_stop (pdata->phydev); + ret =usbnet_suspend (intf, message);if (ret <0 ) {netdev_warn (dev->net,"usbnet_suspend error\n" );return ret; } -cancel_delayed_work_sync (&pdata->carrier_check); -if (pdata->suspend_flags) {netdev_warn (dev->net,"error during last resume\n" ); pdata->suspend_flags =0 ;
@@ -1891,8 +1848,7 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)usbnet_resume (intf);if (ret) -schedule_delayed_work (&pdata->carrier_check, -CARRIER_CHECK_DELAY ); +phy_start (pdata->phydev);return ret; }
@@ -1913,7 +1869,6 @@ static int smsc95xx_resume(struct usb_interface *intf)/* do this first to ensure it's cleared even in error case */ pdata->suspend_flags =0 ; -schedule_delayed_work (&pdata->carrier_check,CARRIER_CHECK_DELAY );if (suspend_flags &SUSPEND_ALLMODES ) {/* clear wake-up sources */
@@ -1944,6 +1899,8 @@ static int smsc95xx_resume(struct usb_interface *intf)if (ret <0 )netdev_warn (dev->net,"usbnet_resume error\n" ); +phy_start (pdata->phydev); +return ret; }
PATCH 19/19 usbnet: smsc95xx: Use phy bit operations
In reply to Marek VasutUse bit operations provided by bit.h instead of reimplementing them. No functional change.
--- drivers/net/usb/smsc95xx.c | 67 +++++++++++++------------------------- 1 file changed, 22 insertions(+), 45 deletions(-)
drivers/net/usb/smsc95xx.c +22 -45
@@ -748,47 +748,35 @@ static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl) {struct usbnet *dev =netdev_priv (net);struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0 ]); -int buf;if ((pdata->chip_id ==ID_REV_CHIP_ID_9500A_ ) || (pdata->chip_id ==ID_REV_CHIP_ID_9530_ ) || (pdata->chip_id ==ID_REV_CHIP_ID_89530_ ) || (pdata->chip_id ==ID_REV_CHIP_ID_9730_ )) {/* Extend Manual AutoMDIX timer for 9500A/9500Ai */ - buf =phy_read (pdata->phydev, -PHY_EDPD_CONFIG ); - buf |=PHY_EDPD_CONFIG_EXT_CROSSOVER_ ; -phy_write (pdata->phydev, -PHY_EDPD_CONFIG , buf); +phy_set_bits (pdata->phydev,PHY_EDPD_CONFIG , +PHY_EDPD_CONFIG_EXT_CROSSOVER_ ); }if (mdix_ctrl ==ETH_TP_MDI ) { - buf =phy_read (pdata->phydev, -SPECIAL_CTRL_STS ); - buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; - buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | -SPECIAL_CTRL_STS_AMDIX_STATE_ ); -phy_write (pdata->phydev, -SPECIAL_CTRL_STS , buf); +phy_modify (pdata->phydev,SPECIAL_CTRL_STS , +SPECIAL_CTRL_STS_AMDIX_ENABLE_ | +SPECIAL_CTRL_STS_AMDIX_STATE_ , +SPECIAL_CTRL_STS_OVRRD_AMDIX_ ); }else if (mdix_ctrl ==ETH_TP_MDI_X ) { - buf =phy_read (pdata->phydev, -SPECIAL_CTRL_STS ); - buf |=SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; - buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | -SPECIAL_CTRL_STS_AMDIX_STATE_ ); - buf |=SPECIAL_CTRL_STS_AMDIX_STATE_ ; -phy_write (pdata->phydev, -SPECIAL_CTRL_STS , buf); +phy_modify (pdata->phydev,SPECIAL_CTRL_STS , +SPECIAL_CTRL_STS_AMDIX_ENABLE_ | +SPECIAL_CTRL_STS_AMDIX_STATE_ , +SPECIAL_CTRL_STS_OVRRD_AMDIX_ | +SPECIAL_CTRL_STS_AMDIX_STATE_ ); }else if (mdix_ctrl ==ETH_TP_MDI_AUTO ) { - buf =phy_read (pdata->phydev, -SPECIAL_CTRL_STS ); - buf &= ~SPECIAL_CTRL_STS_OVRRD_AMDIX_ ; - buf &= ~(SPECIAL_CTRL_STS_AMDIX_ENABLE_ | -SPECIAL_CTRL_STS_AMDIX_STATE_ ); - buf |=SPECIAL_CTRL_STS_AMDIX_ENABLE_ ; -phy_write (pdata->phydev, -SPECIAL_CTRL_STS , buf); +phy_modify (pdata->phydev,SPECIAL_CTRL_STS , +SPECIAL_CTRL_STS_OVRRD_AMDIX_ | +SPECIAL_CTRL_STS_AMDIX_ENABLE_ | +SPECIAL_CTRL_STS_AMDIX_STATE_ , +SPECIAL_CTRL_STS_AMDIX_ENABLE_ ); } + pdata->mdix_ctrl = mdix_ctrl; }
@@ -951,7 +939,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) }phy_write (pdata->phydev,PHY_INT_MASK , -PHY_INT_MASK_DEFAULT_ ); +PHY_INT_MASK_DEFAULT_ ); ret =genphy_restart_aneg (pdata->phydev);if (ret)
@@ -1372,15 +1360,7 @@ static int smsc95xx_enable_phy_wakeup_interrupts(struct usbnet *dev, u16 mask)return ret;/* enable interrupt source */ - ret =phy_read (pdata->phydev,PHY_INT_MASK ); -if (ret <0 ) -return ret; - - ret |= mask; - -phy_write (pdata->phydev,PHY_INT_MASK , ret); - -return 0 ; +return phy_set_bits (pdata->phydev,PHY_INT_MASK , mask); }static int smsc95xx_link_ok_nopm (struct usbnet *dev)
@@ -1445,17 +1425,14 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev)*/ if (pdata->features &FEATURE_PHY_NLP_CROSSOVER )phy_write (pdata->phydev,PHY_EDPD_CONFIG , -PHY_EDPD_CONFIG_DEFAULT ); +PHY_EDPD_CONFIG_DEFAULT );/* enable energy detect power-down mode */ - ret =phy_read (pdata->phydev,PHY_MODE_CTRL_STS ); + ret =phy_set_bits (pdata->phydev,PHY_MODE_CTRL_STS , +MODE_CTRL_STS_EDPWRDOWN_ );if (ret <0 )return ret; - ret |=MODE_CTRL_STS_EDPWRDOWN_ ; - -phy_write (pdata->phydev,PHY_MODE_CTRL_STS , ret); -/* enter SUSPEND1 mode */ ret =smsc95xx_read_reg (dev,PM_CTRL , &val);if (ret <0 )