[PATCH 02/13] net: rtl8169: clean receive buffer after net handler

Lucas Stach dev at lynxeye.de
Sun Nov 2 12:13:44 PST 2014


The processing of the buffer might change some data, which
will eventually trigger a cache writeback later on, corrupting
data written by the network chip. Clean the cache range
to make sure there is no writeback pending.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/net/rtl8169.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 0cd5763..5702900 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -233,6 +233,8 @@ static void rtl8169_init_ring(struct rtl8169_priv *priv)
 	priv->rx_desc = dma_alloc_coherent(NUM_RX_DESC *
 				sizeof(struct bufdesc));
 	priv->rx_buf = malloc(NUM_RX_DESC * PKT_BUF_SIZE);
+	dma_clean_range((unsigned long)priv->rx_buf,
+			(unsigned long)priv->rx_buf + NUM_RX_DESC * PKT_BUF_SIZE);
 
 	memset(priv->tx_desc, 0, NUM_TX_DESC * sizeof(struct bufdesc));
 	memset(priv->rx_desc, 0, NUM_RX_DESC * sizeof(struct bufdesc));
@@ -421,6 +423,15 @@ static int rtl8169_eth_rx(struct eth_device *edev)
 			net_receive(edev, priv->rx_buf + entry * PKT_BUF_SIZE,
 			            pkt_size);
 
+			/*
+			 * the buffer is going to be reused by HW, make sure to
+			 * clean out any potentially modified data
+			 */
+			dma_clean_range((unsigned long)priv->rx_buf
+			               + entry * PKT_BUF_SIZE,
+			              (unsigned long)priv->rx_buf
+			               + entry * PKT_BUF_SIZE + pkt_size);
+
 			if (entry == NUM_RX_DESC - 1)
 				priv->rx_desc[entry].status = BD_STAT_OWN |
 					BD_STAT_EOR | PKT_BUF_SIZE;
-- 
1.9.3




More information about the barebox mailing list