Skip to contentSkip to conversation

FEC: Remove endless loop in the FEC driver

PATCH New Marek Vasut 2 participants 7 messages Aug 29, 2012 – Sep 28, 2012 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 FEC: Remove endless loop in the FEC driver

The FEC hardware sometimes errors out on data transfer and hangs in the tightloop adjusted by this patch. So add timeout into the tightloop to make such a hang recoverable.

Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>
---
 drivers/net/fec_mxc.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/fec_mxc.c +13 -1
index bc44d38..6f071e9 100644
@@ -35,6 +35,12 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/*
+ * Timeout the transfer after 5 mS. This is usually a bit more, since
+ * the code in the tightloops this timeout is used in adds some overhead.
+ */
+#define FEC_XFER_TIMEOUT	5000
+
 #ifndef CONFIG_MII
 #error "CONFIG_MII has to be defined!"
 #endif
@@ -697,6 +703,8 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 	unsigned int status;
 	uint32_t size, end;
 	uint32_t addr;
+	int timeout = FEC_XFER_TIMEOUT;
+	int ret = 0;
 
 	/*
 	 * This routine transmits one frame.  This routine only accepts
@@ -764,6 +772,10 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 	while (readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_READY) {
 		udelay(1);
 		invalidate_dcache_range(addr, addr + size);
+		if (!timeout--) {
+			ret = -EINVAL;
+			break;
+		}
 	}
 
 	debug("fec_send: status 0x%x index %d\n",
@@ -775,7 +787,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 	else
 		fec->tbd_index = 1;
 
-	return 0;
+	return ret;
 }
 
 /**
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/3 FEC: Rework the TX wait mechanism

The mechanism waiting for transmission to finish in fec_send() now relies on the E-bit being cleared in the TX buffer descriptor. In case of data cache being on, this means invalidation of data cache above this TX buffer descriptor on each test for the E-bit being cleared.

Apparently, there is another way to check if the transmission did complete. This is by checking the TDAR bit in the X_DES_ACTIVE register. Reading a register does not need any data cache invalidation, which is beneficial.

Rework the sequence that wait for completion of the transmission so that the TDAR bit is tested first and afterwards check the E-bit being clear. This cuts down the number of cache invalidation calls to one.

Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>
---
 drivers/net/fec_mxc.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/net/fec_mxc.c +11 -9
index 6f071e9..6ede464 100644
@@ -768,19 +768,21 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 	 * invalidate data cache to see what's really in RAM. Also, we need
 	 * barrier here.
 	 */
-	invalidate_dcache_range(addr, addr + size);
-	while (readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_READY) {
-		udelay(1);
-		invalidate_dcache_range(addr, addr + size);
-		if (!timeout--) {
-			ret = -EINVAL;
+	while (--timeout) {
+		if (!(readl(&fec->eth->x_des_active) & (1 << 24)))
 			break;
-		}
 	}
 
-	debug("fec_send: status 0x%x index %d\n",
+	if (!timeout)
+		ret = -EINVAL;
+
+	invalidate_dcache_range(addr, addr + size);
+	if (readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_READY)
+		ret = -EINVAL;
+
+	debug("fec_send: status 0x%x index %d ret %i\n",
 			readw(&fec->tbd_base[fec->tbd_index].status),
-			fec->tbd_index);
+			fec->tbd_index, ret);
 	/* for next transmission use the other buffer */
 	if (fec->tbd_index)
 		fec->tbd_index = 0;
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 FEC: Rework the TX wait mechanism

Hi Marek,

Quoted 15 lines · Marek Vasut

The mechanism waiting for transmission to finish in fec_send() now relies on the E-bit being cleared in the TX buffer descriptor. In case of data cache being on, this means invalidation of data cache above this TX buffer descriptor on each test for the E-bit being cleared.

Apparently, there is another way to check if the transmission did complete. This is by checking the TDAR bit in the X_DES_ACTIVE register. Reading a register does not need any data cache invalidation, which is beneficial.

Rework the sequence that wait for completion of the transmission so that the TDAR bit is tested first and afterwards check the E-bit being clear. This cuts down the number of cache invalidation calls to one.

Quoted 6 lines
Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>

---

Applied, thanks.

-Joe

#3 lore raw

PATCH 3/3 FEC: Replace magic contants

In reply to Marek Vasut

Replace the magic contant 1 << 24 with properly defined bits.

Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>
---
 drivers/net/fec_mxc.c |    6 +++---
 drivers/net/fec_mxc.h |    3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/net/fec_mxc.c +3 -3
index 6ede464..3e232c7 100644
@@ -256,7 +256,7 @@ static int miiphy_wait_aneg(struct eth_device *dev)
 
 static int fec_rx_task_enable(struct fec_priv *fec)
 {
-	writel(1 << 24, &fec->eth->r_des_active);
+	writel(FEC_R_DES_ACTIVE_RDAR, &fec->eth->r_des_active);
 	return 0;
 }
 
@@ -267,7 +267,7 @@ static int fec_rx_task_disable(struct fec_priv *fec)
 
 static int fec_tx_task_enable(struct fec_priv *fec)
 {
-	writel(1 << 24, &fec->eth->x_des_active);
+	writel(FEC_X_DES_ACTIVE_TDAR, &fec->eth->x_des_active);
 	return 0;
 }
 
@@ -769,7 +769,7 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 	 * barrier here.
 	 */
 	while (--timeout) {
-		if (!(readl(&fec->eth->x_des_active) & (1 << 24)))
+		if (!(readl(&fec->eth->x_des_active) & FEC_X_DES_ACTIVE_TDAR))
 			break;
 	}
 
drivers/net/fec_mxc.h +3 -0
index 852b2e0..203285a 100644
@@ -213,6 +213,9 @@ struct ethernet_regs {
 
 #define FEC_X_WMRK_STRFWD		0x00000100
 
+#define FEC_X_DES_ACTIVE_TDAR		0x01000000
+#define FEC_R_DES_ACTIVE_RDAR		0x01000000
+
 #if defined(CONFIG_MX25) || defined(CONFIG_MX53)
 /* defines for MIIGSK */
 /* RMII frequency control: 0=50MHz, 1=5MHz */
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 1/3 FEC: Remove endless loop in the FEC driver

In reply to Marek Vasut

Hi Marek,

Quoted 10 lines · Marek Vasut

The FEC hardware sometimes errors out on data transfer and hangs in the tightloop adjusted by this patch. So add timeout into the tightloop to make such a hang recoverable.

Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>

---

Applied, thanks.

-Joe

#6 lore raw

PATCH 1/3 FEC: Remove endless loop in the FEC driver

Dear Joe Hershberger,

Quoted 7 lines

Hi Marek,

Quoted 4 lines · Marek Vasut

The FEC hardware sometimes errors out on data transfer and hangs in the tightloop adjusted by this patch. So add timeout into the tightloop to make such a hang recoverable.

Quoted 8 lines
Quoted 6 lines
Cc Joe Hershberger <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Otavio Salvador <[email protected]>
Cc Stefano Babic <[email protected]>

---

Applied, thanks.

Doesn't this go via -imx ? Anyway, all these FEC patches from me MUST go into current release. That is imperative, they are important bugfixes.

Quoted 1 line

-Joe

Best regards,
Marek Vasut