From patchwork Tue Jan 17 12:54:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Antipov X-Patchwork-Id: 6255 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1774023F72 for ; Tue, 17 Jan 2012 12:53:21 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id EE0FCA18708 for ; Tue, 17 Jan 2012 12:53:20 +0000 (UTC) Received: by bkbzt4 with SMTP id zt4so1629274bkb.11 for ; Tue, 17 Jan 2012 04:53:20 -0800 (PST) Received: by 10.205.141.72 with SMTP id jd8mr2145869bkc.135.1326804800647; Tue, 17 Jan 2012 04:53:20 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs118082bkc; Tue, 17 Jan 2012 04:53:20 -0800 (PST) Received: by 10.204.153.15 with SMTP id i15mr6504277bkw.43.1326804799338; Tue, 17 Jan 2012 04:53:19 -0800 (PST) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id ig14si4093696bkc.121.2012.01.17.04.53.19 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jan 2012 04:53:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) smtp.mail=dmitry.antipov@linaro.org Received: by bkbzs8 with SMTP id zs8so1010202bkb.37 for ; Tue, 17 Jan 2012 04:53:19 -0800 (PST) Received: by 10.204.128.138 with SMTP id k10mr2689670bks.95.1326804798919; Tue, 17 Jan 2012 04:53:18 -0800 (PST) Received: from localhost.localdomain ([78.153.153.8]) by mx.google.com with ESMTPS id d23sm46940090bkw.15.2012.01.17.04.53.17 (version=SSLv3 cipher=OTHER); Tue, 17 Jan 2012 04:53:18 -0800 (PST) From: Dmitry Antipov To: Steve Glendinning Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linaro-dev@lists.linaro.org, patches@linaro.org, Dmitry Antipov Subject: [PATCH 3/3] smsc95xx: use usleep_range(), get rid out of jiffies Date: Tue, 17 Jan 2012 16:54:12 +0400 Message-Id: <1326804852-17742-1-git-send-email-dmitry.antipov@linaro.org> X-Mailer: git-send-email 1.7.7.5 Use usleep_range() with return value to implement time-bounded wait-for hardware loop where delay is applicable; use ktime instead of jiffies for a busy-wait loop. Signed-off-by: Dmitry Antipov --- drivers/net/usb/smsc95xx.c | 52 ++++++++++++++++++++----------------------- 1 files changed, 24 insertions(+), 28 deletions(-) diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c index d45520e..7264090 100644 --- a/drivers/net/usb/smsc95xx.c +++ b/drivers/net/usb/smsc95xx.c @@ -114,19 +114,18 @@ static int smsc95xx_write_reg(struct usbnet *dev, u32 index, u32 data) return ret; } -/* Loop until the read is completed with timeout - * called with phy_mutex held */ +/* Busy-wait loop until the read is completed, but + no longer than 10ms. Called with phy_mutex held. */ static int smsc95xx_phy_wait_not_busy(struct usbnet *dev) { - unsigned long start_time = jiffies; + ktime_t start = ktime_get(); u32 val; - do { + while (ktime_us_delta(ktime_get(), start) < 10000) { smsc95xx_read_reg(dev, MII_ADDR, &val); if (!(val & MII_BUSY_)) return 0; - } while (!time_after(jiffies, start_time + HZ)); - + } return -EIO; } @@ -195,15 +194,15 @@ static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, static int smsc95xx_wait_eeprom(struct usbnet *dev) { - unsigned long start_time = jiffies; + unsigned long timeout = 0; u32 val; do { smsc95xx_read_reg(dev, E2P_CMD, &val); if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) break; - udelay(40); - } while (!time_after(jiffies, start_time + HZ)); + timeout += usleep_range(40, 50); + } while (timeout < USEC_PER_MSEC * 10); if (val & (E2P_CMD_TIMEOUT_ | E2P_CMD_BUSY_)) { netdev_warn(dev->net, "EEPROM read operation timeout\n"); @@ -215,17 +214,15 @@ static int smsc95xx_wait_eeprom(struct usbnet *dev) static int smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) { - unsigned long start_time = jiffies; + unsigned long timeout = 0; u32 val; do { smsc95xx_read_reg(dev, E2P_CMD, &val); - if (!(val & E2P_CMD_BUSY_)) return 0; - - udelay(40); - } while (!time_after(jiffies, start_time + HZ)); + timeout += usleep_range(40, 50); + } while (timeout < USEC_PER_MSEC * 10); netdev_warn(dev->net, "EEPROM is busy\n"); return -EIO; @@ -674,7 +671,8 @@ static void smsc95xx_start_rx_path(struct usbnet *dev) static int smsc95xx_phy_initialize(struct usbnet *dev) { - int bmcr, timeout = 0; + int bmcr; + unsigned long timeout = 0; /* Initialize MII structure */ dev->mii.dev = dev->net; @@ -688,12 +686,11 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) smsc95xx_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); do { - msleep(10); + timeout += usleep_range(10000, 15000); bmcr = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, MII_BMCR); - timeout++; - } while ((bmcr & BMCR_RESET) && (timeout < 100)); + } while ((bmcr & BMCR_RESET) && (timeout < USEC_PER_SEC)); - if (timeout >= 100) { + if (timeout >= USEC_PER_SEC) { netdev_warn(dev->net, "timeout on PHY Reset"); return -EIO; } @@ -717,7 +714,8 @@ static int smsc95xx_reset(struct usbnet *dev) { struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); u32 read_buf, write_buf, burst_cap; - int ret = 0, timeout; + unsigned long timeout; + int ret = 0; netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); @@ -736,11 +734,10 @@ static int smsc95xx_reset(struct usbnet *dev) netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret); return ret; } - msleep(10); - timeout++; - } while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); + timeout += usleep_range(10000, 15000); + } while ((read_buf & HW_CFG_LRST_) && (timeout < USEC_PER_SEC)); - if (timeout >= 100) { + if (timeout >= USEC_PER_SEC) { netdev_warn(dev->net, "timeout waiting for completion of Lite Reset\n"); return ret; } @@ -759,11 +756,10 @@ static int smsc95xx_reset(struct usbnet *dev) netdev_warn(dev->net, "Failed to read PM_CTRL: %d\n", ret); return ret; } - msleep(10); - timeout++; - } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); + timeout += usleep_range(10000, 15000); + } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < USEC_PER_SEC)); - if (timeout >= 100) { + if (timeout >= USEC_PER_SEC) { netdev_warn(dev->net, "timeout waiting for PHY Reset\n"); return ret; }