diff mbox series

[10/13] net: rtl8139: Factor out hardware reset

Message ID 20200412220359.28224-10-marek.vasut+renesas@gmail.com
State New
Headers show
Series [01/13] net: rtl8139: Register macro cleanup | expand

Commit Message

Marek Vasut April 12, 2020, 10:03 p.m. UTC
This hardware reset and reset-wait implementation was twice in the
driver, factor it out into a separate function. This really should
use wait_for_bit() eventually and return -ETIMEDOUT, but thus far,
handling of any of this is missing from the driver. This must be
added later. Thus far, no functional change.

Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
Cc: Joe Hershberger <joe.hershberger at ni.com>
---
 drivers/net/rtl8139.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 6aed7bd895..68ef9eea25 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -370,16 +370,13 @@  static void rtl8139_set_rx_mode(struct eth_device *dev)
 	outl(0xffffffff, ioaddr + RTL_REG_MAR0 + 4);
 }
 
-static void rtl8139_reset(struct eth_device *dev)
+static void rtl8139_hw_reset(struct eth_device *dev)
 {
 	u8 reg;
 	int i;
 
 	outb(RTL_REG_CHIPCMD_CMDRESET, ioaddr + RTL_REG_CHIPCMD);
 
-	cur_rx = 0;
-	cur_tx = 0;
-
 	/* Give the chip 10ms to finish the reset. */
 	for (i = 0; i < 100; i++) {
 		reg = inb(ioaddr + RTL_REG_CHIPCMD);
@@ -388,7 +385,16 @@  static void rtl8139_reset(struct eth_device *dev)
 
 		udelay(100);
 	}
+}
+
+static void rtl8139_reset(struct eth_device *dev)
+{
+	int i;
+
+	cur_rx = 0;
+	cur_tx = 0;
 
+	rtl8139_hw_reset(dev);
 
 	for (i = 0; i < ETH_ALEN; i++)
 		outb(dev->enetaddr[i], ioaddr + RTL_REG_MAC0 + i);
@@ -570,19 +576,7 @@  static int rtl8139_recv(struct eth_device *dev)
 
 static void rtl8139_stop(struct eth_device *dev)
 {
-	u8 reg;
-	int i;
-
 	ioaddr = dev->iobase;
 
-	/* reset the chip */
-	outb(RTL_REG_CHIPCMD_CMDRESET, ioaddr + RTL_REG_CHIPCMD);
-
-	/* Give the chip 10ms to finish the reset. */
-	for (i = 0; i < 100; i++) {
-		reg = inb(ioaddr + RTL_REG_CHIPCMD);
-		if (!(reg & RTL_REG_CHIPCMD_CMDRESET))
-			break;
-		udelay (100); /* wait 100us */
-	}
+	rtl8139_hw_reset(dev);
 }