Skip to contentSkip to conversation

net: hix5hd2_gmac: do not release the RX ring on interface close

PATCH New David Yang 1 participant 1 message Nov 20

Subsystems (4)
lore
Share & tools
lore

David Yang

author
#0 lore raw

PATCH 1/1 net: hix5hd2_gmac: do not release the RX ring on interface close

hix5hd2_net_close() frees the receive buffers while the free queue still holds the descriptors the block has already fetched.

A port that keeps receiving then DMAs arrived frames into buffers the slab has already taken back; on Hi3716cv200 the descriptors at the next open all carried the previous session's stamps, and the frames received then came up as slab garbage -- six parsed as LLC, the rest with an unrecognized ethertype.

Do not release the receive buffers, their descriptors and the queue pointers on the close, until the device goes away, so the block keeps ownership of every address it prefetches.

The sibling hisi_femac has the same defect and resets the port before freeing its ring, as in commit d54b21d82430 ("net: hisilicon:
hisi_femac: Stop the receiver before releasing the RX ring"); this one, however, has no reset feature and has to keep them alive across a close.

Fixes 57c5bc9ad7d7 ("net: hisilicon: add hix5hd2 mac driver")
---
 drivers/net/ethernet/hisilicon/hix5hd2_gmac.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hix5hd2_gmac.c +14 -2
index 12a5657653f8..8c67a0670cbb 100644
@@ -792,7 +792,7 @@ static netdev_tx_t hix5hd2_net_xmit(struct sk_buff *skb, struct net_device *dev)
 	return NETDEV_TX_OK;
 }
 
-static void hix5hd2_free_dma_desc_rings(struct hix5hd2_priv *priv)
+static void hix5hd2_free_rx_buffers(struct hix5hd2_priv *priv)
 {
 	struct hix5hd2_desc *desc;
 	dma_addr_t addr;
@@ -810,6 +810,13 @@ static void hix5hd2_free_dma_desc_rings(struct hix5hd2_priv *priv)
 		dev_kfree_skb_any(skb);
 		priv->rx_skb[i] = NULL;
 	}
+}
+
+static void hix5hd2_free_tx_buffers(struct hix5hd2_priv *priv)
+{
+	struct hix5hd2_desc *desc;
+	dma_addr_t addr;
+	int i;
 
 	for (i = 0; i < TX_DESC_NUM; i++) {
 		struct sk_buff *skb = priv->tx_skb[i];
@@ -873,7 +880,10 @@ static int hix5hd2_net_close(struct net_device *dev)
 	hix5hd2_irq_disable(priv);
 	napi_disable(&priv->napi);
 	netif_stop_queue(dev);
-	hix5hd2_free_dma_desc_rings(priv);
+	/* free rx buffers when device goes away, not when interface closed;
+	 * the hardware prefetches rx descriptors and cannot be expelled
+	 */
+	hix5hd2_free_tx_buffers(priv);
 
 	if (dev->phydev) {
 		phy_stop(dev->phydev);
@@ -985,6 +995,8 @@ static void hix5hd2_destroy_hw_desc_queue(struct hix5hd2_priv *priv)
 {
 	int i;
 
+	hix5hd2_free_rx_buffers(priv);
+
 	for (i = 0; i < QUEUE_NUMS; i++) {
 		if (priv->pool[i].desc) {
 			dma_free_coherent(priv->dev, priv->pool[i].size,
Signature · 1 line
2.53.0