public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: David Brownell <david-b@pacbell.net>
Cc: linux-usb-devel@lists.sourceforge.net,
	David Hollis <dhollis@davehollis.com>,
	support@moschip.com, dbrownell@users.sourceforge.net,
	linux-kernel@vger.kernel.org, Michael Helmling <supermihi@web.de>
Subject: [PATCH 2/3] usbnet: add a mutex around phy register access
Date: Sun, 17 Sep 2006 01:03:06 +0200	[thread overview]
Message-ID: <200609170103.07280.arnd@arndb.de> (raw)
In-Reply-To: <200609170055.34565.arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
Index: linux-cg/drivers/usb/net/asix.c
===================================================================
--- linux-cg.orig/drivers/usb/net/asix.c	2006-09-17 00:10:53.000000000 +0200
+++ linux-cg/drivers/usb/net/asix.c	2006-09-17 00:18:08.000000000 +0200
@@ -328,10 +328,12 @@
 	struct usbnet *dev = netdev_priv(netdev);
 	u16 res;
 
+	mutex_lock(&dev->phy_mutex);
 	asix_set_sw_mii(dev);
 	asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
 				(__u16)loc, 2, (u16 *)&res);
 	asix_set_hw_mii(dev);
+	mutex_unlock(&dev->phy_mutex);
 
 	return res & 0xffff;
 }
@@ -348,10 +350,12 @@
 	struct usbnet *dev = netdev_priv(netdev);
 	u16 res = val;
 
+	mutex_lock(&dev->phy_mutex);
 	asix_set_sw_mii(dev);
 	asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
 				(__u16)loc, 2, (u16 *)&res);
 	asix_set_hw_mii(dev);
+	mutex_unlock(&dev->phy_mutex);
 }
 
 /* same as above, but converts new value to le16 byte order before writing */
Index: linux-cg/drivers/usb/net/usbnet.c
===================================================================
--- linux-cg.orig/drivers/usb/net/usbnet.c	2006-09-17 00:10:53.000000000 +0200
+++ linux-cg/drivers/usb/net/usbnet.c	2006-09-17 00:18:08.000000000 +0200
@@ -1112,6 +1112,7 @@
 	dev->delay.function = usbnet_bh;
 	dev->delay.data = (unsigned long) dev;
 	init_timer (&dev->delay);
+	mutex_init (&dev->phy_mutex);
 
 	SET_MODULE_OWNER (net);
 	dev->net = net;
Index: linux-cg/drivers/usb/net/usbnet.h
===================================================================
--- linux-cg.orig/drivers/usb/net/usbnet.h	2006-09-17 00:10:53.000000000 +0200
+++ linux-cg/drivers/usb/net/usbnet.h	2006-09-17 00:18:08.000000000 +0200
@@ -30,6 +30,7 @@
 	struct usb_device	*udev;
 	struct driver_info	*driver_info;
 	wait_queue_head_t	*wait;
+	struct mutex		phy_mutex;
 
 	/* i/o info: pipes etc */
 	unsigned		in, out;
Index: linux-cg/drivers/usb/net/mcs7830.c
===================================================================
--- linux-cg.orig/drivers/usb/net/mcs7830.c	2006-09-17 00:10:53.000000000 +0200
+++ linux-cg/drivers/usb/net/mcs7830.c	2006-09-17 00:18:08.000000000 +0200
@@ -184,6 +184,7 @@
 		HIF_REG_PHY_CMD2_PEND_FLAG_BIT | index,
 	};
 
+	mutex_lock(&dev->phy_mutex);
 	/* write the MII command */
 	ret = mcs7830_set_reg(dev, HIF_REG_PHY_CMD1, 2, cmd);
 	if (ret < 0)
@@ -208,6 +209,7 @@
 	dev_dbg(&dev->udev->dev, "read PHY reg %02x: %04x (%d tries)\n",
 		index, val, i);
 out:
+	mutex_unlock(&dev->phy_mutex);
 	return ret;
 }
 
@@ -222,6 +224,8 @@
 		HIF_REG_PHY_CMD2_PEND_FLAG_BIT | (index & 0x1F),
 	};
 
+	mutex_lock(&dev->phy_mutex);
+
 	/* write the new register contents */
 	le_val = cpu_to_le16(val);
 	ret = mcs7830_set_reg(dev, HIF_REG_PHY_DATA, 2, &le_val);
@@ -248,6 +252,7 @@
 	dev_dbg(&dev->udev->dev, "write PHY reg %02x: %04x (%d tries)\n",
 		index, val, i);
 out:
+	mutex_unlock(&dev->phy_mutex);
 	return ret;
 }
 


       reply	other threads:[~2006-09-16 23:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200609170055.34565.arnd@arndb.de>
2006-09-16 23:03 ` Arnd Bergmann [this message]
2006-09-27 19:33   ` [PATCH 2/3] usbnet: add a mutex around phy register access dhollis
     [not found] ` <200609170057.07460.arnd@arndb.de>
2006-09-16 23:03   ` [PATCH 3/3] usbnet: improve generic ethtool support Arnd Bergmann
2006-09-27 19:33     ` dhollis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200609170103.07280.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=david-b@pacbell.net \
    --cc=dbrownell@users.sourceforge.net \
    --cc=dhollis@davehollis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=supermihi@web.de \
    --cc=support@moschip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox