[U-Boot] [PATCH v3 07/13] net: ftgmac100: handle timeouts when transmitting

Cédric Le Goater clg at kaod.org
Wed Oct 10 11:41:56 UTC 2018


Signed-off-by: Cédric Le Goater <clg at kaod.org>
---
 drivers/net/ftgmac100.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index b46187b567c6..edf34c601c68 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -28,6 +28,9 @@
 /* PKTBUFSTX/PKTBUFSRX must both be power of 2 */
 #define PKTBUFSTX	4	/* must be power of 2 */
 
+/* Timeout for transmit */
+#define FTGMAC100_TX_TIMEOUT_MS		1000
+
 /* Timeout for a mdio read/write operation */
 #define FTGMAC100_MDIO_TIMEOUT_USEC	10000
 
@@ -412,6 +415,7 @@ static int ftgmac100_send(struct udevice *dev, void *packet, int length)
 		roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN);
 	ulong data_start;
 	ulong data_end;
+	ulong start;
 
 	invalidate_dcache_range(des_start, des_end);
 
@@ -444,6 +448,20 @@ static int ftgmac100_send(struct udevice *dev, void *packet, int length)
 	/* Start transmit */
 	writel(1, &ftgmac100->txpd);
 
+	/* Wait until packet is transmitted */
+	start = get_timer(0);
+	while (get_timer(start) < FTGMAC100_TX_TIMEOUT_MS) {
+		invalidate_dcache_range(des_start, des_end);
+		if (!(curr_des->txdes0 & FTGMAC100_TXDES0_TXDMA_OWN))
+			break;
+		udelay(10);
+	}
+
+	if (get_timer(start) >= FTGMAC100_TX_TIMEOUT_MS) {
+		dev_err(dev, "transmit timeout\n");
+		return -ETIMEDOUT;
+	}
+
 	debug("%s(): packet sent\n", __func__);
 
 	/* Move to next descriptor */
-- 
2.17.1



More information about the U-Boot mailing list