Skip to content

Commit

Permalink
net: usb: asix: refactor asix_read_phy_addr() and handle errors on re…
Browse files Browse the repository at this point in the history
…turn

[ Upstream commit 7e88b11 ]

Refactor asix_read_phy_addr() to return usable error value directly and
make sure all callers handle this error.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
olerem authored and Sasha Levin committed Aug 26, 2021
1 parent cf4c166 commit 4e4f3cb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
3 changes: 1 addition & 2 deletions drivers/net/usb/asix.h
Expand Up @@ -205,8 +205,7 @@ struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
int asix_set_sw_mii(struct usbnet *dev, int in_pm);
int asix_set_hw_mii(struct usbnet *dev, int in_pm);

int asix_read_phy_addr(struct usbnet *dev, int internal);
int asix_get_phy_addr(struct usbnet *dev);
int asix_read_phy_addr(struct usbnet *dev, bool internal);

int asix_sw_reset(struct usbnet *dev, u8 flags, int in_pm);

Expand Down
31 changes: 16 additions & 15 deletions drivers/net/usb/asix_common.c
Expand Up @@ -288,32 +288,33 @@ int asix_set_hw_mii(struct usbnet *dev, int in_pm)
return ret;
}

int asix_read_phy_addr(struct usbnet *dev, int internal)
int asix_read_phy_addr(struct usbnet *dev, bool internal)
{
int offset = (internal ? 1 : 0);
int ret, offset;
u8 buf[2];
int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf, 0);

netdev_dbg(dev->net, "asix_get_phy_addr()\n");
ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf, 0);
if (ret < 0)
goto error;

if (ret < 2) {
netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
goto out;
ret = -EIO;
goto error;
}
netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
*((__le16 *)buf));

offset = (internal ? 1 : 0);
ret = buf[offset];

out:
netdev_dbg(dev->net, "%s PHY address 0x%x\n",
internal ? "internal" : "external", ret);

return ret;
}

int asix_get_phy_addr(struct usbnet *dev)
{
/* return the address of the internal phy */
return asix_read_phy_addr(dev, 1);
}
error:
netdev_err(dev->net, "Error reading PHY_ID register: %02x\n", ret);

return ret;
}

int asix_sw_reset(struct usbnet *dev, u8 flags, int in_pm)
{
Expand Down
15 changes: 12 additions & 3 deletions drivers/net/usb/asix_devices.c
Expand Up @@ -262,7 +262,10 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
dev->mii.mdio_write = asix_mdio_write;
dev->mii.phy_id_mask = 0x3f;
dev->mii.reg_num_mask = 0x1f;
dev->mii.phy_id = asix_get_phy_addr(dev);

dev->mii.phy_id = asix_read_phy_addr(dev, true);
if (dev->mii.phy_id < 0)
return dev->mii.phy_id;

dev->net->netdev_ops = &ax88172_netdev_ops;
dev->net->ethtool_ops = &ax88172_ethtool_ops;
Expand Down Expand Up @@ -717,7 +720,10 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
dev->mii.mdio_write = asix_mdio_write;
dev->mii.phy_id_mask = 0x1f;
dev->mii.reg_num_mask = 0x1f;
dev->mii.phy_id = asix_get_phy_addr(dev);

dev->mii.phy_id = asix_read_phy_addr(dev, true);
if (dev->mii.phy_id < 0)
return dev->mii.phy_id;

dev->net->netdev_ops = &ax88772_netdev_ops;
dev->net->ethtool_ops = &ax88772_ethtool_ops;
Expand Down Expand Up @@ -1081,7 +1087,10 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
dev->mii.phy_id_mask = 0x1f;
dev->mii.reg_num_mask = 0xff;
dev->mii.supports_gmii = 1;
dev->mii.phy_id = asix_get_phy_addr(dev);

dev->mii.phy_id = asix_read_phy_addr(dev, true);
if (dev->mii.phy_id < 0)
return dev->mii.phy_id;

dev->net->netdev_ops = &ax88178_netdev_ops;
dev->net->ethtool_ops = &ax88178_ethtool_ops;
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/usb/ax88172a.c
Expand Up @@ -220,6 +220,11 @@ static int ax88172a_bind(struct usbnet *dev, struct usb_interface *intf)
}

priv->phy_addr = asix_read_phy_addr(dev, priv->use_embdphy);
if (priv->phy_addr < 0) {
ret = priv->phy_addr;
goto free;
}

ax88172a_reset_phy(dev, priv->use_embdphy);

/* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
Expand Down

0 comments on commit 4e4f3cb

Please sign in to comment.