Commit a9fc6338 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

usbnet: add a mutex around phy register access

When working on the mcs7830, I noticed the need for a mutex in its
mdio_read/mdio_write functions. A related problem seems to be present
in the asix driver in the respective functions.

This introduces a mutex in the common usbnet driver and uses it
from the two hardware specific drivers.
Acked-by: default avatarDavid Hollis <dhollis@davehollis.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c41286fd
...@@ -569,10 +569,12 @@ static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) ...@@ -569,10 +569,12 @@ static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
struct usbnet *dev = netdev_priv(netdev); struct usbnet *dev = netdev_priv(netdev);
u16 res; u16 res;
mutex_lock(&dev->phy_mutex);
asix_set_sw_mii(dev); asix_set_sw_mii(dev);
asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
(__u16)loc, 2, (u16 *)&res); (__u16)loc, 2, (u16 *)&res);
asix_set_hw_mii(dev); asix_set_hw_mii(dev);
mutex_unlock(&dev->phy_mutex);
devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff)); devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff));
...@@ -586,10 +588,12 @@ asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) ...@@ -586,10 +588,12 @@ asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
u16 res = cpu_to_le16(val); u16 res = cpu_to_le16(val);
devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val); devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val);
mutex_lock(&dev->phy_mutex);
asix_set_sw_mii(dev); asix_set_sw_mii(dev);
asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
(__u16)loc, 2, (u16 *)&res); (__u16)loc, 2, (u16 *)&res);
asix_set_hw_mii(dev); asix_set_hw_mii(dev);
mutex_unlock(&dev->phy_mutex);
} }
/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */ /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
......
...@@ -184,6 +184,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index) ...@@ -184,6 +184,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index)
HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index, HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
}; };
mutex_lock(&dev->phy_mutex);
/* write the MII command */ /* write the MII command */
ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd); ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
if (ret < 0) if (ret < 0)
...@@ -208,6 +209,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index) ...@@ -208,6 +209,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index)
dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n", dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
index, val, i); index, val, i);
out: out:
mutex_unlock(&dev->phy_mutex);
return ret; return ret;
} }
...@@ -222,6 +224,8 @@ static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val) ...@@ -222,6 +224,8 @@ static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F), HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
}; };
mutex_lock(&dev->phy_mutex);
/* write the new register contents */ /* write the new register contents */
le_val = cpu_to_le16(val); le_val = cpu_to_le16(val);
ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val); ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
...@@ -248,6 +252,7 @@ static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val) ...@@ -248,6 +252,7 @@ static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val)
dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n", dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
index, val, i); index, val, i);
out: out:
mutex_unlock(&dev->phy_mutex);
return ret; return ret;
} }
......
...@@ -1144,6 +1144,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) ...@@ -1144,6 +1144,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
dev->delay.function = usbnet_bh; dev->delay.function = usbnet_bh;
dev->delay.data = (unsigned long) dev; dev->delay.data = (unsigned long) dev;
init_timer (&dev->delay); init_timer (&dev->delay);
mutex_init (&dev->phy_mutex);
SET_MODULE_OWNER (net); SET_MODULE_OWNER (net);
dev->net = net; dev->net = net;
......
...@@ -30,6 +30,7 @@ struct usbnet { ...@@ -30,6 +30,7 @@ struct usbnet {
struct usb_device *udev; struct usb_device *udev;
struct driver_info *driver_info; struct driver_info *driver_info;
wait_queue_head_t *wait; wait_queue_head_t *wait;
struct mutex phy_mutex;
/* i/o info: pipes etc */ /* i/o info: pipes etc */
unsigned in, out; unsigned in, out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment