Skip to content

Commit 74dd40b

Browse files
bengaldavem330
authored andcommitted
net: arc_emac: prevent reuse of unreclaimed tx descriptors
This patch changes the logic in tx path to ensure that tx descriptors are reused for transmission only after they have been reclaimed by arc_emac_tx_clean(). Signed-off-by: Beniamino Galvani <b.galvani@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7ce7679 commit 74dd40b

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

‎drivers/net/ethernet/arc/emac_main.c‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
#define DRV_NAME "arc_emac"
3030
#define DRV_VERSION "1.0"
3131

32+
/**
33+
* arc_emac_tx_avail - Return the number of available slots in the tx ring.
34+
* @priv: Pointer to ARC EMAC private data structure.
35+
*
36+
* returns: the number of slots available for transmission in tx the ring.
37+
*/
38+
static inline int arc_emac_tx_avail(struct arc_emac_priv *priv)
39+
{
40+
return (priv->txbd_dirty + TX_BD_NUM - priv->txbd_curr - 1) % TX_BD_NUM;
41+
}
42+
3243
/**
3344
* arc_emac_adjust_link - Adjust the PHY link duplex.
3445
* @ndev: Pointer to the net_device structure.
@@ -180,10 +191,15 @@ static void arc_emac_tx_clean(struct net_device *ndev)
180191
txbd->info = 0;
181192

182193
*txbd_dirty = (*txbd_dirty + 1) % TX_BD_NUM;
183-
184-
if (netif_queue_stopped(ndev))
185-
netif_wake_queue(ndev);
186194
}
195+
196+
/* Ensure that txbd_dirty is visible to tx() before checking
197+
* for queue stopped.
198+
*/
199+
smp_mb();
200+
201+
if (netif_queue_stopped(ndev) && arc_emac_tx_avail(priv))
202+
netif_wake_queue(ndev);
187203
}
188204

189205
/**
@@ -574,11 +590,9 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
574590

575591
len = max_t(unsigned int, ETH_ZLEN, skb->len);
576592

577-
/* EMAC still holds this buffer in its possession.
578-
* CPU must not modify this buffer descriptor
579-
*/
580-
if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC)) {
593+
if (unlikely(!arc_emac_tx_avail(priv))) {
581594
netif_stop_queue(ndev);
595+
netdev_err(ndev, "BUG! Tx Ring full when queue awake!\n");
582596
return NETDEV_TX_BUSY;
583597
}
584598

@@ -607,12 +621,19 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
607621
/* Increment index to point to the next BD */
608622
*txbd_curr = (*txbd_curr + 1) % TX_BD_NUM;
609623

610-
/* Get "info" of the next BD */
611-
info = &priv->txbd[*txbd_curr].info;
624+
/* Ensure that tx_clean() sees the new txbd_curr before
625+
* checking the queue status. This prevents an unneeded wake
626+
* of the queue in tx_clean().
627+
*/
628+
smp_mb();
612629

613-
/* Check if if Tx BD ring is full - next BD is still owned by EMAC */
614-
if (unlikely((le32_to_cpu(*info) & OWN_MASK) == FOR_EMAC))
630+
if (!arc_emac_tx_avail(priv)) {
615631
netif_stop_queue(ndev);
632+
/* Refresh tx_dirty */
633+
smp_mb();
634+
if (arc_emac_tx_avail(priv))
635+
netif_start_queue(ndev);
636+
}
616637

617638
arc_reg_set(priv, R_STATUS, TXPL_MASK);
618639

0 commit comments

Comments
 (0)