lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1eacb44f2585c21a259f7132e0d860a0ed021550.camel@microchip.com>
Date:   Mon, 29 Jun 2020 20:02:09 +0000
From:   <Andre.Edich@...rochip.com>
To:     <netdev@...r.kernel.org>, <UNGLinuxDriver@...rochip.com>,
        <steve.glendinning@...well.net>
CC:     <Parthiban.Veerasooran@...rochip.com>
Subject: [PATCH net-next 7/8] smsc95xx: use PHY framework instead of MII
 library

Since the PHY framework is used anyway, replace the rest of the calls
to
the MII library, including those from the USB Network driver
infrastructure, by the calls to the PHY framework.

Signed-off-by: Andre Edich <andre.edich@...rochip.com>
---
 drivers/net/usb/smsc95xx.c | 92 +++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 56 deletions(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index bcdd7e726f5b..06fcc2518305 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -51,6 +51,9 @@
 #define SUSPEND_ALLMODES		(SUSPEND_SUSPEND0 |
SUSPEND_SUSPEND1 | \
 					 SUSPEND_SUSPEND2 |
SUSPEND_SUSPEND3)
 
+#define PHY_ID_MASK  0x1f
+#define REG_NUM_MASK 0x1f
+
 struct smsc95xx_priv {
 	u32 chip_id;
 	u32 mac_cr;
@@ -173,10 +176,9 @@ 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 usbnet *dev, int phy_id, int
idx,
 				int in_pm)
 {
-	struct usbnet *dev = netdev_priv(netdev);
 	u32 val, addr;
 	int ret;
 
@@ -190,8 +192,8 @@ static int __smsc95xx_mdio_read(struct net_device
*netdev, int phy_id, int idx,
 	}
 
 	/* set the address, index & direction (read from PHY) */
-	phy_id &= dev->mii.phy_id_mask;
-	idx &= dev->mii.reg_num_mask;
+	phy_id &= PHY_ID_MASK;
+	idx &= REG_NUM_MASK;
 	addr = (phy_id << 11) | (idx << 6) | MII_READ_ | MII_BUSY_;
 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
 	if (ret < 0) {
@@ -218,10 +220,9 @@ 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,
+static void __smsc95xx_mdio_write(struct usbnet *dev, int phy_id,
 				  int idx, int regval, int in_pm)
 {
-	struct usbnet *dev = netdev_priv(netdev);
 	u32 val, addr;
 	int ret;
 
@@ -242,8 +243,8 @@ static void __smsc95xx_mdio_write(struct net_device
*netdev, int phy_id,
 	}
 
 	/* set the address, index & direction (write to PHY) */
-	phy_id &= dev->mii.phy_id_mask;
-	idx &= dev->mii.reg_num_mask;
+	phy_id &= PHY_ID_MASK;
+	idx &= REG_NUM_MASK;
 	addr = (phy_id << 11) | (idx << 6) | MII_WRITE_ | MII_BUSY_;
 	ret = __smsc95xx_write_reg(dev, MII_ADDR, addr, in_pm);
 	if (ret < 0) {
@@ -263,34 +264,23 @@ static void __smsc95xx_mdio_write(struct
net_device *netdev, int phy_id,
 
 static int smsc95xx_mdio_read_nopm(struct usbnet *dev, int idx)
 {
-	struct mii_if_info *mii = &dev->mii;
+	struct smsc95xx_priv *pdata = dev->driver_priv;
 
-	return __smsc95xx_mdio_read(dev->net, mii->phy_id, idx, 1);
+	return __smsc95xx_mdio_read(dev, pdata->phydev->mdio.addr, idx,
1);
 }
 
 static void smsc95xx_mdio_write_nopm(struct usbnet *dev, int idx, int
regval)
 {
-	struct mii_if_info *mii = &dev->mii;
-
-	__smsc95xx_mdio_write(dev->net, mii->phy_id, idx, regval, 1);
-}
-
-static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id,
int idx)
-{
-	return __smsc95xx_mdio_read(netdev, phy_id, idx, 0);
-}
+	struct smsc95xx_priv *pdata = dev->driver_priv;
 
-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(dev, pdata->phydev->mdio.addr, idx,
regval, 1);
 }
 
 static int smsc95xx_mdiobus_read(struct mii_bus *bus, int phy_id, int
idx)
 {
 	struct usbnet *dev = bus->priv;
 
-	return __smsc95xx_mdio_read(dev->net, phy_id, idx, 0);
+	return __smsc95xx_mdio_read(dev, phy_id, idx, 0);
 }
 
 static int smsc95xx_mdiobus_write(struct mii_bus *bus, int phy_id, int
idx,
@@ -298,7 +288,7 @@ static int smsc95xx_mdiobus_write(struct mii_bus
*bus, int phy_id, int idx,
 {
 	struct usbnet *dev = bus->priv;
 
-	__smsc95xx_mdio_write(dev->net, phy_id, idx, regval, 0);
+	__smsc95xx_mdio_write(dev, phy_id, idx, regval, 0);
 	return 0;
 }
 
@@ -569,8 +559,7 @@ 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_cmd ecmd = { .cmd = ETHTOOL_GSET };
+	struct ethtool_link_ksettings cmd;
 	unsigned long flags;
 	u16 lcladv, rmtadv;
 	int ret;
@@ -584,17 +573,16 @@ static int smsc95xx_link_reset(struct usbnet
*dev)
 	if (ret < 0)
 		return ret;
 
-	mii_check_media(mii, 1, 1);
-	mii_ethtool_gset(&dev->mii, &ecmd);
+	phy_ethtool_ksettings_get(pdata->phydev, &cmd);
 	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);
+		  cmd.base.speed, cmd.base.duplex, lcladv, rmtadv);
 
 	spin_lock_irqsave(&pdata->mac_cr_lock, flags);
-	if (ecmd.duplex != DUPLEX_FULL) {
+	if (cmd.base.duplex != DUPLEX_FULL) {
 		pdata->mac_cr &= ~MAC_CR_FDPX_;
 		pdata->mac_cr |= MAC_CR_RCVOWN_;
 	} else {
@@ -607,7 +595,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, cmd.base.duplex,
lcladv,
+					      rmtadv);
 	if (ret < 0)
 		netdev_warn(dev->net, "Error updating PHY flow
control\n");
 
@@ -780,6 +769,9 @@ static void set_mdix_status(struct net_device *net,
__u8 mdix_ctrl)
 	struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev-
> data[0]);
 	int buf;
 
+	if (pdata->mdix_ctrl == mdix_ctrl)
+		return;
+
 	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_) ||
@@ -821,7 +813,7 @@ static int smsc95xx_get_link_ksettings(struct
net_device *net,
 	struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev-
> data[0]);
 	int retval;
 
-	retval = usbnet_get_link_ksettings(net, cmd);
+	retval = phy_ethtool_get_link_ksettings(net, cmd);
 
 	cmd->base.eth_tp_mdix = pdata->mdix_ctrl;
 	cmd->base.eth_tp_mdix_ctrl = pdata->mdix_ctrl;
@@ -832,21 +824,19 @@ static int smsc95xx_get_link_ksettings(struct
net_device *net,
 static int smsc95xx_set_link_ksettings(struct net_device *net,
 				       const struct
ethtool_link_ksettings *cmd)
 {
-	struct usbnet *dev = netdev_priv(net);
-	struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev-
> data[0]);
-	int retval;
-
-	if (pdata->mdix_ctrl != cmd->base.eth_tp_mdix_ctrl)
-		set_mdix_status(net, cmd->base.eth_tp_mdix_ctrl);
-
-	retval = usbnet_set_link_ksettings(net, cmd);
+	set_mdix_status(net, cmd->base.eth_tp_mdix_ctrl);
+	return phy_ethtool_set_link_ksettings(net, cmd);
+}
 
-	return retval;
+static u32 smsc95xx_get_link(struct net_device *net)
+{
+	phy_read_status(net->phydev);
+	return net->phydev->link;
 }
 
 static const struct ethtool_ops smsc95xx_ethtool_ops = {
-	.get_link	= usbnet_get_link,
-	.nway_reset	= usbnet_nway_reset,
+	.get_link	= smsc95xx_get_link,
+	.nway_reset	= phy_ethtool_nway_reset,
 	.get_drvinfo	= usbnet_get_drvinfo,
 	.get_msglevel	= usbnet_get_msglevel,
 	.set_msglevel	= usbnet_set_msglevel,
@@ -864,12 +854,10 @@ 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);
-
 	if (!netif_running(netdev))
 		return -EINVAL;
 
-	return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
+	return phy_mii_ioctl(netdev->phydev, rq, cmd);
 }
 
 static void smsc95xx_init_mac_address(struct usbnet *dev)
@@ -1179,7 +1167,7 @@ static int smsc95xx_start_phy(struct usbnet *dev)
 
 	phy_attached_info(net->phydev);
 	phy_start(net->phydev);
-	mii_nway_restart(&dev->mii);
+	phy_start_aneg(net->phydev);
 	return 0;
 }
 
@@ -1268,9 +1256,6 @@ static int smsc95xx_bind(struct usbnet *dev,
struct usb_interface *intf)
 	pdata->mdiobus->write = smsc95xx_mdiobus_write;
 	pdata->mdiobus->name = "smsc95xx-mdiobus";
 
-	dev->mii.phy_id_mask = 0x1f;
-	dev->mii.reg_num_mask = 0x1f;
-
 	snprintf(pdata->mdiobus->id, ARRAY_SIZE(pdata->mdiobus->id),
 		 "usb-%03d:%03d", dev->udev->bus->busnum, dev->udev-
> devnum);
 
@@ -1287,11 +1272,6 @@ static int smsc95xx_bind(struct usbnet *dev,
struct usb_interface *intf)
 		goto unregister_mdio;
 	}
 
-	dev->mii.dev = dev->net;
-	dev->mii.mdio_read = smsc95xx_mdio_read;
-	dev->mii.mdio_write = smsc95xx_mdio_write;
-	dev->mii.phy_id = pdata->phydev->mdio.addr;
-
 	/* detect device revision as different features may be
available */
 	ret = smsc95xx_read_reg(dev, ID_REV, &val);
 	if (ret < 0)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ