Xilinx axienet fixes
v3 cover Xilinx axienet fixes
Various fixes for the Xilinx AXI Ethernet driver.
Changed since v2:
-added Reviewed-by tags, added some explanation to commit messages, no code changes
Changed since v1:
-corrected a Fixes tag to point to mainline commit -split up reset changes into 3 patches -added ratelimit on netdev_warn in TX busy case
Robert Hancock (9):
net: axienet: increase reset timeout
net: axienet: Wait for PhyRstCmplt after core reset
net: axienet: reset core on initialization prior to MDIO access
net: axienet: add missing memory barriers
net: axienet: limit minimum TX ring size
net: axienet: Fix TX ring slot available check
net: axienet: fix number of TX ring slots for available check
net: axienet: fix for TX busy handling
net: axienet: increase default TX ring size to 128
.../net/ethernet/xilinx/xilinx_axienet_main.c | 135 +++++++++++------- 1 file changed, 84 insertions(+), 51 deletions(-)
Signature · 1 line
2.31.1
PATCH v3 1/9 net: axienet: increase reset timeout
The previous timeout of 1ms was too short to handle some cases where the core is reset just after the input clocks were started, which will be introduced in an upcoming patch. Increase the timeout to 50ms. Also simplify the reset timeout checking to use read_poll_timeout.
--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -10
@@ -496,7 +496,8 @@ static void axienet_setoptions(struct net_device *ndev, u32 options)static int __axienet_device_reset (struct axienet_local *lp) { -u32 timeout; +u32 value; +int ret;/* Reset Axi DMA. This would reset Axi Ethernet core as well. The reset * process of Axi DMA takes a while to complete as all pending
@@ -506,15 +507,13 @@ static int __axienet_device_reset(struct axienet_local *lp)* they both reset the entire DMA core, so only one needs to be used. */ axienet_dma_out32 (lp,XAXIDMA_TX_CR_OFFSET ,XAXIDMA_CR_RESET_MASK ); - timeout =DELAY_OF_ONE_MILLISEC ; -while (axienet_dma_in32 (lp,XAXIDMA_TX_CR_OFFSET ) & -XAXIDMA_CR_RESET_MASK ) { -udelay (1 ); -if (--timeout ==0 ) { -netdev_err (lp->ndev,"%s: DMA reset timeout!\n" , - __func__); -return -ETIMEDOUT ; - } + ret =read_poll_timeout (axienet_dma_in32, value, + !(value &XAXIDMA_CR_RESET_MASK ), +DELAY_OF_ONE_MILLISEC ,50000 , false, lp, +XAXIDMA_TX_CR_OFFSET ); +if (ret) { +dev_err (lp->dev,"%s: DMA reset timeout!\n" , __func__); +return ret; }return 0 ;
Signature · 1 line
2.31.1
PATCH v3 2/9 net: axienet: Wait for PhyRstCmplt after core reset
In reply to Robert HancockWhen resetting the device, wait for the PhyRstCmplt bit to be set in the interrupt status register before continuing initialization, to ensure that the core is actually ready. When using an external PHY, this also ensures we do not start trying to access the PHY while it is still in reset. The PHY reset is initiated by the core reset which is triggered just above, but remains asserted for 5ms after the core is reset according to the documentation.
The MgtRdy bit could also be waited for, but unfortunately when using 7-series devices, the bit does not appear to work as documented (it seems to behave as some sort of link state indication and not just an indication the transceiver is ready) so it can't really be relied on for this purpose.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +10 -0
@@ -516,6 +516,16 @@ static int __axienet_device_reset(struct axienet_local *lp)return ret; } +/* Wait for PhyRstCmplt bit to be set, indicating the PHY reset has finished */ + ret =read_poll_timeout (axienet_ior, value, + value &XAE_INT_PHYRSTCMPLT_MASK , +DELAY_OF_ONE_MILLISEC ,50000 , false, lp, +XAE_IS_OFFSET ); +if (ret) { +dev_err (lp->dev,"%s: timeout waiting for PhyRstCmplt\n" , __func__); +return ret; + } +return 0 ; }
Signature · 1 line
2.31.1
PATCH v3 3/9 net: axienet: reset core on initialization prior to MDIO access
In reply to Robert HancockIn some cases where the Xilinx Ethernet core was used in 1000Base-X or SGMII modes, which use the internal PCS/PMA PHY, and the MGT transceiver clock source for the PCS was not running at the time the FPGA logic was loaded, the core would come up in a state where the PCS could not be found on the MDIO bus. To fix this, the Ethernet core (including the PCS) should be reset after enabling the clocks, prior to attempting to access the PCS using of_mdio_find_device.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +5 -0
@@ -2036,6 +2036,11 @@ static int axienet_probe(struct platform_device *pdev) lp->coalesce_count_rx =XAXIDMA_DFT_RX_THRESHOLD ; lp->coalesce_count_tx =XAXIDMA_DFT_TX_THRESHOLD ; +/* Reset core now that clocks are enabled, prior to accessing MDIO */ + ret =__axienet_device_reset (lp); +if (ret) + goto cleanup_clk; + lp->phy_node =of_parse_phandle (pdev->dev.of_node,"phy-handle" ,0 );if (lp->phy_node) { ret =axienet_mdio_setup (lp);
Signature · 1 line
2.31.1
PATCH v3 4/9 net: axienet: add missing memory barriers
In reply to Robert HancockThis driver was missing some required memory barriers:
Use dma_rmb to ensure we see all updates to the descriptor after we see that an entry has been completed.
Use wmb and rmb to avoid stale descriptor status between the TX path and TX complete IRQ path.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +10 -1
@@ -632,6 +632,8 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd,if (nr_bds ==-1 && !(status &XAXIDMA_BD_STS_COMPLETE_MASK ))break ; +/* Ensure we see complete descriptor update */ +dma_rmb (); phys =desc_get_phys_addr (lp, cur_p); dma_unmap_single(ndev->dev.parent, phys, (cur_p->cntrl & XAXIDMA_BD_CTRL_LENGTH_MASK),
@@ -645,8 +647,10 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd, cur_p->app1 =0 ; cur_p->app2 =0 ; cur_p->app4 =0 ; - cur_p->status =0 ; cur_p->skb =NULL ; +/* ensure our transmit path and device don't prematurely see status cleared */ +wmb (); + cur_p->status =0 ;if (sizep) *sizep += status &XAXIDMA_BD_STS_ACTUAL_LEN_MASK ;
@@ -704,6 +708,9 @@ static inline int axienet_check_tx_bd_space(struct axienet_local *lp, int num_frag) {struct axidma_bd *cur_p; + +/* Ensure we see all descriptor updates from device or TX IRQ path */ +rmb (); cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num];if (cur_p->status &XAXIDMA_BD_STS_ALL_MASK )return NETDEV_TX_BUSY ;
@@ -843,6 +850,8 @@ static void axienet_recv(struct net_device *ndev) tail_p = lp->rx_bd_p +sizeof (*lp->rx_bd_v) * lp->rx_bd_ci; +/* Ensure we see complete descriptor update */ +dma_rmb (); phys =desc_get_phys_addr (lp, cur_p);dma_unmap_single (ndev->dev.parent, phys, lp->max_frm_size,DMA_FROM_DEVICE );
Signature · 1 line
2.31.1
PATCH v3 5/9 net: axienet: limit minimum TX ring size
In reply to Robert HancockThe driver will not work properly if the TX ring size is set to below MAX_SKB_FRAGS + 1 since it needs to hold at least one full maximally fragmented packet in the TX ring. Limit setting the ring size to below this value.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +3 -1
@@ -43,6 +43,7 @@/* Descriptors defines for Tx and Rx DMA */ #define TX_BD_NUM_DEFAULT 64#define RX_BD_NUM_DEFAULT 1024 +#define TX_BD_NUM_MIN (MAX_SKB_FRAGS + 1)#define TX_BD_NUM_MAX 4096#define RX_BD_NUM_MAX 4096
@@ -1370,7 +1371,8 @@ axienet_ethtools_set_ringparam(struct net_device *ndev,if (ering->rx_pending >RX_BD_NUM_MAX || ering->rx_mini_pending || ering->rx_jumbo_pending || - ering->rx_pending >TX_BD_NUM_MAX ) + ering->tx_pending <TX_BD_NUM_MIN || + ering->tx_pending >TX_BD_NUM_MAX )return -EINVAL ;if (netif_running (ndev))
Signature · 1 line
2.31.1
PATCH v3 6/9 net: axienet: Fix TX ring slot available check
In reply to Robert HancockThe check for whether a TX ring slot was available was incorrect, since a slot which had been loaded with transmit data but the device had not started transmitting would be treated as available, potentially causing non-transmitted slots to be overwritten. The control field in the descriptor should be checked, rather than the status field (which may only be updated when the device completes the entry).
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -2
@@ -643,7 +643,6 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd,if (cur_p->skb && (status &XAXIDMA_BD_STS_COMPLETE_MASK ))dev_consume_skb_irq (cur_p->skb); - cur_p->cntrl =0 ; cur_p->app0 =0 ; cur_p->app1 =0 ; cur_p->app2 =0 ;
@@ -651,6 +650,7 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd, cur_p->skb =NULL ;/* ensure our transmit path and device don't prematurely see status cleared */ wmb (); + cur_p->cntrl =0 ; cur_p->status =0 ;if (sizep)
@@ -713,7 +713,7 @@ static inline int axienet_check_tx_bd_space(struct axienet_local *lp,/* Ensure we see all descriptor updates from device or TX IRQ path */ rmb (); cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num]; -if (cur_p->status &XAXIDMA_BD_STS_ALL_MASK ) +if (cur_p->cntrl)return NETDEV_TX_BUSY ;return 0 ; }
Signature · 1 line
2.31.1
PATCH v3 7/9 net: axienet: fix number of TX ring slots for available check
In reply to Robert HancockThe check for the number of available TX ring slots was off by 1 since a slot is required for the skb header as well as each fragment. This could result in overwriting a TX ring slot that was still in use.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -2
@@ -747,7 +747,7 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev) num_frag =skb_shinfo (skb)->nr_frags; cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; -if (axienet_check_tx_bd_space (lp, num_frag)) { +if (axienet_check_tx_bd_space (lp, num_frag +1 )) {if (netif_queue_stopped (ndev))return NETDEV_TX_BUSY ;
@@ -757,7 +757,7 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)smp_mb ();/* Space might have just been freed - check again */ -if (axienet_check_tx_bd_space (lp, num_frag)) +if (axienet_check_tx_bd_space (lp, num_frag +1 ))return NETDEV_TX_BUSY ;netif_wake_queue (ndev);
Signature · 1 line
2.31.1
PATCH v3 8/9 net: axienet: fix for TX busy handling
In reply to Robert HancockNetwork 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.
--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +47 -39
@@ -660,6 +660,32 @@ static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd,return i; } +/** +* axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy +* @lp: Pointer to the axienet_local structure +* @num_frag: The number of BDs to check for +* +* Return: 0, on success +* NETDEV_TX_BUSY, if any of the descriptors are not free +* +* This function is invoked before BDs are allocated and transmission starts. +* This function returns 0 if a BD or group of BDs can be allocated for +* transmission. If the BD or any of the BDs are not free the function +* returns a busy status. This is invoked from axienet_start_xmit. +*/ +static inline int axienet_check_tx_bd_space (struct axienet_local *lp, +int num_frag) +{ +struct axidma_bd *cur_p; + +/* Ensure we see all descriptor updates from device or TX IRQ path */ +rmb (); + cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num]; +if (cur_p->cntrl) +return NETDEV_TX_BUSY ; +return 0 ; +} +/** * axienet_start_xmit_done - Invoked once a transmit is completed by the * Axi DMA Tx channel.
@@ -689,33 +715,8 @@ static void axienet_start_xmit_done(struct net_device *ndev)/* Matches barrier in axienet_start_xmit */ smp_mb (); -netif_wake_queue (ndev); -} - -/** -* axienet_check_tx_bd_space - Checks if a BD/group of BDs are currently busy -* @lp: Pointer to the axienet_local structure -* @num_frag: The number of BDs to check for -* -* Return: 0, on success -* NETDEV_TX_BUSY, if any of the descriptors are not free -* -* This function is invoked before BDs are allocated and transmission starts. -* This function returns 0 if a BD or group of BDs can be allocated for -* transmission. If the BD or any of the BDs are not free the function -* returns a busy status. This is invoked from axienet_start_xmit. -*/ -static inline int axienet_check_tx_bd_space (struct axienet_local *lp, -int num_frag) -{ -struct axidma_bd *cur_p; - -/* Ensure we see all descriptor updates from device or TX IRQ path */ -rmb (); - cur_p = &lp->tx_bd_v[(lp->tx_bd_tail + num_frag) % lp->tx_bd_num]; -if (cur_p->cntrl) -return NETDEV_TX_BUSY ; -return 0 ; +if (!axienet_check_tx_bd_space (lp,MAX_SKB_FRAGS +1 )) +netif_wake_queue (ndev); }/**
@@ -748,19 +749,14 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev) cur_p = &lp->tx_bd_v[lp->tx_bd_tail];if (axienet_check_tx_bd_space (lp, num_frag +1 )) { -if (netif_queue_stopped (ndev)) -return NETDEV_TX_BUSY ; - +/* Should not happen as last start_xmit call should have +* checked for sufficient space and queue should only be +* woken when sufficient space is available. +*/ netif_stop_queue (ndev); - -/* Matches barrier in axienet_start_xmit_done */ -smp_mb (); - -/* Space might have just been freed - check again */ -if (axienet_check_tx_bd_space (lp, num_frag +1 )) -return NETDEV_TX_BUSY ; - -netif_wake_queue (ndev); +if (net_ratelimit ()) +netdev_warn (ndev,"TX ring unexpectedly full\n" ); +return NETDEV_TX_BUSY ; }if (skb->ip_summed ==CHECKSUM_PARTIAL ) {
@@ -821,6 +817,18 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)if (++lp->tx_bd_tail >= lp->tx_bd_num) lp->tx_bd_tail =0 ; +/* Stop queue if next transmit may not have space */ +if (axienet_check_tx_bd_space (lp,MAX_SKB_FRAGS +1 )) { +netif_stop_queue (ndev); + +/* Matches barrier in axienet_start_xmit_done */ +smp_mb (); + +/* Space might have just been freed - check again */ +if (!axienet_check_tx_bd_space (lp,MAX_SKB_FRAGS +1 )) +netif_wake_queue (ndev); + } +return NETDEV_TX_OK ; }
Signature · 1 line
2.31.1
PATCH v3 9/9 net: axienet: increase default TX ring size to 128
In reply to Robert HancockWith previous changes to make the driver handle the TX ring size more correctly, the default TX ring size of 64 appears to significantly bottleneck TX performance to around 600 Mbps on a 1 Gbps link on ZynqMP. Increasing this to 128 seems to bring performance up to near line rate and shouldn't cause excess bufferbloat (this driver doesn't yet support modern byte-based queue management).
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
@@ -41,7 +41,7 @@#include "xilinx_axienet.h" /* Descriptors defines for Tx and Rx DMA */ -#define TX_BD_NUM_DEFAULT 64 +#define TX_BD_NUM_DEFAULT 128#define RX_BD_NUM_DEFAULT 1024#define TX_BD_NUM_MIN (MAX_SKB_FRAGS + 1)#define TX_BD_NUM_MAX 4096
Signature · 1 line
2.31.1
Quoted 22 lines · Robert Hancock
Various fixes for the Xilinx AXI Ethernet driver.
Changed since v2:
-added Reviewed-by tags, added some explanation to commit messages, no code changesChanged since v1:
(quoted diff) +0
-3-corrected a Fixes tag to point to mainline commit -split up reset changes into 3 patches -added ratelimit on netdev_warn in TX busy caseRobert Hancock (9):
net: axienet: increase reset timeout
net: axienet: Wait for PhyRstCmplt after core reset
net: axienet: reset core on initialization prior to MDIO access
net: axienet: add missing memory barriers
net: axienet: limit minimum TX ring size
net: axienet: Fix TX ring slot available check
net: axienet: fix number of TX ring slots for available check
net: axienet: fix for TX busy handling
net: axienet: increase default TX ring size to 128
Quoted 3 lines
.../net/ethernet/xilinx/xilinx_axienet_main.c | 135 +++++++++++------- 1 file changed, 84 insertions(+), 51 deletions(-)
FYI, for the netdev/cc_maintainers Patchwork check, I dropped Ariane Keller < [email protected]> from the CC list as their mail was bouncing.
Signature · 3 lines
Robert Hancock Senior Hardware Designer, Calian Advanced Technologies www.calian.com
Quoted 31 lines
-----Original Message-----
From: Robert Hancock <[email protected]>
Sent: Wednesday, January 19, 2022 4:35 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Michal Simek <[email protected]>; Radhey Shyam Pandey <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH net v3 0/9] Xilinx axienet fixesQuoted 21 lines · Robert Hancock
Various fixes for the Xilinx AXI Ethernet driver.
Changed since v2:
-added Reviewed-by tags, added some explanation to commit messages, no code changesChanged since v1:
-corrected a Fixes tag to point to mainline commit -split up reset changes into 3 patches -added ratelimit onnetdev_warnin TX busy caseRobert Hancock (9):
net: axienet: increase reset timeout
net: axienet: Wait for PhyRstCmplt after core reset
net: axienet: reset core on initialization prior to MDIO access
net: axienet: add missing memory barriers
net: axienet: limit minimum TX ring size
net: axienet: Fix TX ring slot available check
net: axienet: fix number of TX ring slots for available check
net: axienet: fix for TX busy handling
net: axienet: increase default TX ring size to 128
Quoted 7 lines
Quoted 4 lines
.../net/ethernet/xilinx/xilinx_axienet_main.c | 135 +++++++++++------- 1 file changed, 84 insertions(+), 51 deletions(-)FYI, for the netdev/cc_maintainers Patchwork check, I dropped Ariane Keller < [email protected]> from the CC list as their mail was bouncing.
Thanks for the series. I have added Harini to this thread to also review and add her Tested-by tag. Just FYI- We are in feature freeze so plan is to close on this series by next week. Hope that's fine.
Quoted 4 lines
--
Robert Hancock
Senior Hardware Designer, Calian Advanced Technologies www.calian.com