Skip to content

Commit bb193e3

Browse files
robhancockseddavem330
authored andcommitted
net: axienet: fix for TX busy handling
Network driver documentation indicates we should be avoiding returning NETDEV_TX_BUSY from ndo_start_xmit in normal cases, since it requires the packets to be requeued. Instead the queue should be stopped after a packet is added to the TX ring when there may not be enough room for an additional one. Also, when TX ring entries are completed, we should only wake the queue if we know there is room for another full maximally fragmented packet. Print a warning if there is insufficient space at the start of start_xmit, since this should no longer happen. Combined with increasing the default TX ring size (in a subsequent patch), this appears to recover the TX performance lost by previous changes to actually manage the TX ring state properly. Fixes: 8a3b7a2 ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver") Signed-off-by: Robert Hancock <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aba57a8 commit bb193e3

File tree

1 file changed

+47
-39
lines changed

1 file changed

+47
-39
lines changed

drivers/net/ethernet/xilinx/xilinx_axienet_main.c

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,32 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd,
660660
return i;
661661
}
662662

663+
/**
664+
* axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy
665+
* @lp: Pointer to the axienet_local structure
666+
* @num_frag: The number of BDs to check for
667+
*
668+
* Return: 0, on success
669+
* NETDEV_TX_BUSY, if any of the descriptors are not free
670+
*
671+
* This function is invoked before BDs are allocated and transmission starts.
672+
* This function returns 0 if a BD or group of BDs can be allocated for
673+
* transmission. If the BD or any of the BDs are not free the function
674+
* returns a busy status. This is invoked from axienet_start_xmit.
675+
*/
676+
static inline int axienet_check_tx_bd_space(struct axienet_local *lp,
677+
int num_frag)
678+
{
679+
struct axidma_bd *cur_p;
680+
681+
/* Ensure we see all descriptor updates from device or TX IRQ path */
682+
rmb();
683+
cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num];
684+
if (cur_p->cntrl)
685+
return NETDEV_TX_BUSY;
686+
return 0;
687+
}
688+
663689
/**
664690
* axienet_start_xmit_done - Invoked once a transmit is completed by the
665691
* Axi DMA Tx channel.
@@ -689,33 +715,8 @@ static void axienet_start_xmit_done(struct net_device *ndev)
689715
/* Matches barrier in axienet_start_xmit */
690716
smp_mb();
691717

692-
netif_wake_queue(ndev);
693-
}
694-
695-
/**
696-
* axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy
697-
* @lp: Pointer to the axienet_local structure
698-
* @num_frag: The number of BDs to check for
699-
*
700-
* Return: 0, on success
701-
* NETDEV_TX_BUSY, if any of the descriptors are not free
702-
*
703-
* This function is invoked before BDs are allocated and transmission starts.
704-
* This function returns 0 if a BD or group of BDs can be allocated for
705-
* transmission. If the BD or any of the BDs are not free the function
706-
* returns a busy status. This is invoked from axienet_start_xmit.
707-
*/
708-
static inline int axienet_check_tx_bd_space(struct axienet_local *lp,
709-
int num_frag)
710-
{
711-
struct axidma_bd *cur_p;
712-
713-
/* Ensure we see all descriptor updates from device or TX IRQ path */
714-
rmb();
715-
cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num];
716-
if (cur_p->cntrl)
717-
return NETDEV_TX_BUSY;
718-
return 0;
718+
if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1))
719+
netif_wake_queue(ndev);
719720
}
720721

721722
/**
@@ -748,19 +749,14 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
748749
cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
749750

750751
if (axienet_check_tx_bd_space(lp, num_frag + 1)) {
751-
if (netif_queue_stopped(ndev))
752-
return NETDEV_TX_BUSY;
753-
752+
/* Should not happen as last start_xmit call should have
753+
* checked for sufficient space and queue should only be
754+
* woken when sufficient space is available.
755+
*/
754756
netif_stop_queue(ndev);
755-
756-
/* Matches barrier in axienet_start_xmit_done */
757-
smp_mb();
758-
759-
/* Space might have just been freed - check again */
760-
if (axienet_check_tx_bd_space(lp, num_frag + 1))
761-
return NETDEV_TX_BUSY;
762-
763-
netif_wake_queue(ndev);
757+
if (net_ratelimit())
758+
netdev_warn(ndev, "TX ring unexpectedly full\n");
759+
return NETDEV_TX_BUSY;
764760
}
765761

766762
if (skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -821,6 +817,18 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
821817
if (++lp->tx_bd_tail >= lp->tx_bd_num)
822818
lp->tx_bd_tail = 0;
823819

820+
/* Stop queue if next transmit may not have space */
821+
if (axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1)) {
822+
netif_stop_queue(ndev);
823+
824+
/* Matches barrier in axienet_start_xmit_done */
825+
smp_mb();
826+
827+
/* Space might have just been freed - check again */
828+
if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1))
829+
netif_wake_queue(ndev);
830+
}
831+
824832
return NETDEV_TX_OK;
825833
}
826834

0 commit comments

Comments
 (0)