diff options
author | Arnd Bergmann <arnd@arndb.de> | 2006-10-08 18:08:02 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-10-17 17:46:32 -0400 |
commit | a9fc6338bd51a3d5735839e756fe7b741c2e6fad (patch) | |
tree | 0c75d1739bd65f21b125562dd9f603b1d195dd8c /drivers/usb | |
parent | c41286fd42f3545513f8de9f61028120b6d38e89 (diff) |
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: David Hollis <dhollis@davehollis.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/net/asix.c | 4 | ||||
-rw-r--r-- | drivers/usb/net/mcs7830.c | 5 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.c | 1 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.h | 1 |
4 files changed, 11 insertions, 0 deletions
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c index 5edd0534c7ab..881841e600de 100644 --- a/drivers/usb/net/asix.c +++ b/drivers/usb/net/asix.c | |||
@@ -569,10 +569,12 @@ static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) | |||
569 | struct usbnet *dev = netdev_priv(netdev); | 569 | struct usbnet *dev = netdev_priv(netdev); |
570 | u16 res; | 570 | u16 res; |
571 | 571 | ||
572 | mutex_lock(&dev->phy_mutex); | ||
572 | asix_set_sw_mii(dev); | 573 | asix_set_sw_mii(dev); |
573 | asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, | 574 | asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, |
574 | (__u16)loc, 2, (u16 *)&res); | 575 | (__u16)loc, 2, (u16 *)&res); |
575 | asix_set_hw_mii(dev); | 576 | asix_set_hw_mii(dev); |
577 | mutex_unlock(&dev->phy_mutex); | ||
576 | 578 | ||
577 | devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff)); | 579 | devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff)); |
578 | 580 | ||
@@ -586,10 +588,12 @@ asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | |||
586 | u16 res = cpu_to_le16(val); | 588 | u16 res = cpu_to_le16(val); |
587 | 589 | ||
588 | devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val); | 590 | devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val); |
591 | mutex_lock(&dev->phy_mutex); | ||
589 | asix_set_sw_mii(dev); | 592 | asix_set_sw_mii(dev); |
590 | asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, | 593 | asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, |
591 | (__u16)loc, 2, (u16 *)&res); | 594 | (__u16)loc, 2, (u16 *)&res); |
592 | asix_set_hw_mii(dev); | 595 | asix_set_hw_mii(dev); |
596 | mutex_unlock(&dev->phy_mutex); | ||
593 | } | 597 | } |
594 | 598 | ||
595 | /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */ | 599 | /* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */ |
diff --git a/drivers/usb/net/mcs7830.c b/drivers/usb/net/mcs7830.c index 23a80667f17e..6240b978fe3d 100644 --- a/drivers/usb/net/mcs7830.c +++ b/drivers/usb/net/mcs7830.c | |||
@@ -184,6 +184,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index) | |||
184 | HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index, | 184 | HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index, |
185 | }; | 185 | }; |
186 | 186 | ||
187 | mutex_lock(&dev->phy_mutex); | ||
187 | /* write the MII command */ | 188 | /* write the MII command */ |
188 | ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd); | 189 | ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd); |
189 | if (ret < 0) | 190 | if (ret < 0) |
@@ -208,6 +209,7 @@ static int mcs7830_read_phy(struct usbnet *dev, u8 index) | |||
208 | dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n", | 209 | dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n", |
209 | index, val, i); | 210 | index, val, i); |
210 | out: | 211 | out: |
212 | mutex_unlock(&dev->phy_mutex); | ||
211 | return ret; | 213 | return ret; |
212 | } | 214 | } |
213 | 215 | ||
@@ -222,6 +224,8 @@ static int mcs7830_write_phy(struct usbnet *dev, u8 index, u16 val) | |||
222 | HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F), | 224 | HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F), |
223 | }; | 225 | }; |
224 | 226 | ||
227 | mutex_lock(&dev->phy_mutex); | ||
228 | |||
225 | /* write the new register contents */ | 229 | /* write the new register contents */ |
226 | le_val = cpu_to_le16(val); | 230 | le_val = cpu_to_le16(val); |
227 | ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val); | 231 | 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 | dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n", | 252 | dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n", |
249 | index, val, i); | 253 | index, val, i); |
250 | out: | 254 | out: |
255 | mutex_unlock(&dev->phy_mutex); | ||
251 | return ret; | 256 | return ret; |
252 | } | 257 | } |
253 | 258 | ||
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index decc1b179246..cf3d20eb781c 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -1144,6 +1144,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
1144 | dev->delay.function = usbnet_bh; | 1144 | dev->delay.function = usbnet_bh; |
1145 | dev->delay.data = (unsigned long) dev; | 1145 | dev->delay.data = (unsigned long) dev; |
1146 | init_timer (&dev->delay); | 1146 | init_timer (&dev->delay); |
1147 | mutex_init (&dev->phy_mutex); | ||
1147 | 1148 | ||
1148 | SET_MODULE_OWNER (net); | 1149 | SET_MODULE_OWNER (net); |
1149 | dev->net = net; | 1150 | dev->net = net; |
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h index 743947c3fb83..07c70abbe0ec 100644 --- a/drivers/usb/net/usbnet.h +++ b/drivers/usb/net/usbnet.h | |||
@@ -30,6 +30,7 @@ struct usbnet { | |||
30 | struct usb_device *udev; | 30 | struct usb_device *udev; |
31 | struct driver_info *driver_info; | 31 | struct driver_info *driver_info; |
32 | wait_queue_head_t *wait; | 32 | wait_queue_head_t *wait; |
33 | struct mutex phy_mutex; | ||
33 | 34 | ||
34 | /* i/o info: pipes etc */ | 35 | /* i/o info: pipes etc */ |
35 | unsigned in, out; | 36 | unsigned in, out; |