igc: Add support for AF_XDP zero-copy
Subsystems (3)
v5 cover igc: Add support for AF_XDP zero-copy
Hi all,
This is the fifth version of this series which adds AF_XDP zero-copy support to igc driver.
The only change from v4:
- igc_setup_rx_resources() - Modified to pass napi_id as a parameter to xdp_rxq_info_reg(). Earlier we were passing 0 instead, which implies napi_id is was unavailable/unknown.
Known issues (carried from v3):
When an XDP application is running in Tx-Only mode with Zero-Copy enabled, it is not expected to add the frames to the fill-queue. I have noticed the following two issues in this scenario:
- If XDP_USE_NEED_WAKEUP flag is not set by application, igc_poll() will go into infinite loop because the buffer allocation resulting in igc_clean_rx_irq_zc() indicating that all work is not done and NAPI should keep polling. This does not occur if XDP_USE_NEED_WAKEUP flag is set.
- Since there are no buffers allocated by userspace for the fill queue, there is no memory allocated for the NIC to copy the data to. If the packet received is destined to the hardware queue where XDP application is running, no packets are received even on other queues.
Both these issues can be mitigated by adding a few frames to the fill queue. The second issue can also be mitigated by making sure no packets are being received on the hardware queue where Rx is running.
v4 is here:
https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20210222090936.6768-1-jithu.joseph at intel.com/
v3 is here:
https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20210209024243.23406-1-vedang.patel at intel.com/
v2 is here:
https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201223203705.78705-1-andre.guedes at intel.com/
v1 is here:
https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20201217202415.77891-1-andre.guedes at intel.com/
Andre Guedes (9):
igc: Move igc_xdp_is_enabled()
igc: Refactor __igc_xdp_run_prog()
igc: Refactor igc_clean_rx_ring()
igc: Refactor XDP rxq info registration
igc: Introduce TX/RX stats helpers
igc: Introduce igc_unmap_tx_buffer() helper
igc: Replace IGC_TX_FLAGS_XDP flag by an enum
igc: Enable RX via AF_XDP zero-copy
igc: Enable TX via AF_XDP zero-copy
drivers/net/ethernet/intel/igc/igc.h | 33 +- drivers/net/ethernet/intel/igc/igc_base.h | 2 + drivers/net/ethernet/intel/igc/igc_main.c | 652 ++++++++++++++++++---- drivers/net/ethernet/intel/igc/igc_xdp.c | 107 +++- drivers/net/ethernet/intel/igc/igc_xdp.h | 8 +- 5 files changed, 675 insertions(+), 127 deletions(-)
base-commit: bae0e60bed826a21db719985ceefe1e3eb3f58e5
Signature · 1 line
2.17.1
PATCH v5 1/9 igc: Move igc_xdp_is_enabled()
From: Andre Guedes <[email protected]>
Move the helper igc_xdp_is_enabled() to igc_xdp.h so it can be reused in igc_xdp.c by upcoming patches that will introduce AF_XDP zero-copy support to the driver.
--- drivers/net/ethernet/intel/igc/igc_main.c | 5 ----- drivers/net/ethernet/intel/igc/igc_xdp.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +0 -5
@@ -515,11 +515,6 @@ static int igc_setup_all_rx_resources(struct igc_adapter *adapter)return err; } -static bool igc_xdp_is_enabled (struct igc_adapter *adapter) -{ -return !!adapter->xdp_prog; -} -/** * igc_configure_rx_ring - Configure a receive ring after Reset * @adapter: board private structure
drivers/net/ethernet/intel/igc/igc_xdp.h +5 -0
@@ -10,4 +10,9 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,int igc_xdp_register_rxq_info (struct igc_ring *ring);void igc_xdp_unregister_rxq_info (struct igc_ring *ring); +static inline bool igc_xdp_is_enabled (struct igc_adapter *adapter) +{ +return !!adapter->xdp_prog; +} +#endif /* _IGC_XDP_H_ */
Signature · 1 line
2.17.1
PATCH v5 1/9 igc: Move igc_xdp_is_enabled()
Quoted 6 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Move the helper
igc_xdp_is_enabled()toigc_xdp.hso it can be reused inigc_xdp.cby upcoming patches that will introduceAF_XDPzero-copy support to the driver.
Quoted 9 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 5 ----- drivers/net/ethernet/intel/igc/igc_xdp.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-)
PATCH v5 2/9 igc: Refactor __igc_xdp_run_prog()
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Refactor __igc_xdp_run_prog() helper from igc_xdp_run_prog(), preparing the code for AF_XDP zero-copy support which is added by upcoming patches.
The existing igc_xdp_run_prog() caters to regular XDP rx path which has to verify if bpf_prog is not NULL. Zero-copy path assumes that bpf_prog is not NULL and hence this check is not required. Therefore it makes sense to refactor the common code into a helper function, to avoid code duplication.
--- drivers/net/ethernet/intel/igc/igc_main.c | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +28 -28
@@ -2021,38 +2021,22 @@ static int igc_xdp_xmit_back(struct igc_adapter *adapter, struct xdp_buff *xdp)return res; } -static struct sk_buff *igc_xdp_run_prog (struct igc_adapter *adapter, -struct xdp_buff *xdp) +/* This function assumes rcu_read_lock() is held by the caller. */ +static int __igc_xdp_run_prog (struct igc_adapter *adapter, +struct bpf_prog *prog, +struct xdp_buff *xdp) { -struct bpf_prog *prog; -int res; -u32 act; - -rcu_read_lock (); - - prog =READ_ONCE (adapter->xdp_prog); -if (!prog) { - res =IGC_XDP_PASS ; - goto unlock; - } +u32 act =bpf_prog_run_xdp (prog, xdp); - act =bpf_prog_run_xdp (prog, xdp);switch (act) {case XDP_PASS : - res =IGC_XDP_PASS ; -break ; +return IGC_XDP_PASS ;case XDP_TX : -if (igc_xdp_xmit_back (adapter, xdp) <0 ) - res =IGC_XDP_CONSUMED ; -else - res =IGC_XDP_TX ; -break ; +return igc_xdp_xmit_back (adapter, xdp) <0 ? +IGC_XDP_CONSUMED :IGC_XDP_TX ;case XDP_REDIRECT : -if (xdp_do_redirect (adapter->netdev, xdp, prog) <0 ) - res =IGC_XDP_CONSUMED ; -else - res =IGC_XDP_REDIRECT ; -break ; +return xdp_do_redirect (adapter->netdev, xdp, prog) <0 ? +IGC_XDP_CONSUMED :IGC_XDP_REDIRECT ;default :bpf_warn_invalid_xdp_action (act); fallthrough;
@@ -2060,9 +2044,25 @@ static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter,trace_xdp_exception (adapter->netdev, prog, act); fallthrough;case XDP_DROP : - res =IGC_XDP_CONSUMED ; -break ; +return IGC_XDP_CONSUMED ; } +} + +static struct sk_buff *igc_xdp_run_prog (struct igc_adapter *adapter, +struct xdp_buff *xdp) +{ +struct bpf_prog *prog; +int res; + +rcu_read_lock (); + + prog =READ_ONCE (adapter->xdp_prog); +if (!prog) { + res =IGC_XDP_PASS ; + goto unlock; + } + + res =__igc_xdp_run_prog (adapter, prog, xdp); unlock:rcu_read_unlock ();
Signature · 1 line
2.17.1
PATCH v5 2/9 igc: Refactor __igc_xdp_run_prog()
Quoted 12 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Refactor
__igc_xdp_run_prog()helper fromigc_xdp_run_prog(), preparing the code forAF_XDPzero-copy support which is added by upcoming patches.The existing
igc_xdp_run_prog()caters to regular XDP rx path which has to verify ifbpf_progis not NULL. Zero-copy path assumes thatbpf_progis not NULL and hence this check is not required. Therefore it makes sense to refactor the common code into a helper function, to avoid code duplication.
Quoted 8 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-)
PATCH v5 3/9 igc: Refactor igc_clean_rx_ring()
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Refactor igc_clean_rx_ring() helper, preparing the code for AF_XDP zero-copy support which is added by upcoming patches.
The refactor consists of encapsulating page-shared specific code into its own helper, leaving common code that will be shared by both page-shared and xsk pool in igc_clean_rx_ring().
--- drivers/net/ethernet/intel/igc/igc_main.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +14 -9
@@ -346,11 +346,7 @@ static int igc_setup_all_tx_resources(struct igc_adapter *adapter)return err; } -/** -* igc_clean_rx_ring - Free Rx Buffers per Queue -* @rx_ring: ring to free buffers from -*/ -static void igc_clean_rx_ring (struct igc_ring *rx_ring) +static void igc_clean_rx_ring_page_shared (struct igc_ring *rx_ring) {u16 i = rx_ring->next_to_clean;
@@ -383,12 +379,21 @@ static void igc_clean_rx_ring(struct igc_ring *rx_ring)if (i == rx_ring->count) i =0 ; } +} + +/** +* igc_clean_rx_ring - Free Rx Buffers per Queue +* @ring: ring to free buffers from +*/ +static void igc_clean_rx_ring (struct igc_ring *ring) +{ +igc_clean_rx_ring_page_shared (ring); -clear_ring_uses_large_buffer (rx_ring); +clear_ring_uses_large_buffer (ring); - rx_ring->next_to_alloc =0 ; - rx_ring->next_to_clean =0 ; - rx_ring->next_to_use =0 ; + ring->next_to_alloc =0 ; + ring->next_to_clean =0 ; + ring->next_to_use =0 ; }/**
Signature · 1 line
2.17.1
PATCH v5 3/9 igc: Refactor igc_clean_rx_ring()
Quoted 9 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Refactor
igc_clean_rx_ring()helper, preparing the code forAF_XDPzero-copy support which is added by upcoming patches.The refactor consists of encapsulating page-shared specific code into its own helper, leaving common code that will be shared by both page-shared and xsk pool in
igc_clean_rx_ring().
Quoted 8 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
PATCH v5 4/9 igc: Refactor XDP rxq info registration
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Refactor XDP rxq info registration code, preparing the driver for AF_XDP zero-copy support which is added by upcoming patches.
Currently, xdp_rxq and memory model are both registered during RX resource setup time by igc_xdp_register_rxq_info() helper. With AF_XDP, we want to register the memory model later on while configuring the ring because we will know which memory model type to register (MEM_TYPE_PAGE_SHARED or MEM_TYPE_XSK_BUFF_POOL).
The helpers igc_xdp_register_rxq_info() and igc_xdp_unregister_rxq_ info() are not useful anymore so they are removed.
--- drivers/net/ethernet/intel/igc/igc_main.c | 16 ++++++++++---- drivers/net/ethernet/intel/igc/igc_xdp.c | 27 ----------------------- drivers/net/ethernet/intel/igc/igc_xdp.h | 3 --- 3 files changed, 12 insertions(+), 34 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +12 -4
@@ -419,7 +419,7 @@ void igc_free_rx_resources(struct igc_ring *rx_ring) {igc_clean_rx_ring (rx_ring); -igc_xdp_unregister_rxq_info (rx_ring); +xdp_rxq_info_unreg (&rx_ring->xdp_rxq);vfree (rx_ring->rx_buffer_info); rx_ring->rx_buffer_info =NULL ;
@@ -458,11 +458,16 @@ int igc_setup_rx_resources(struct igc_ring *rx_ring) {struct net_device *ndev = rx_ring->netdev;struct device *dev = rx_ring->dev; +u8 index = rx_ring->queue_index;int size, desc_len, res; - res =igc_xdp_register_rxq_info (rx_ring); -if (res <0 ) + res =xdp_rxq_info_reg (&rx_ring->xdp_rxq, ndev, index, + rx_ring->q_vector->napi.napi_id); +if (res <0 ) { +netdev_err (ndev,"Failed to register xdp_rxq index %u\n" , + index);return res; + } size =sizeof (struct igc_rx_buffer ) * rx_ring->count; rx_ring->rx_buffer_info =vzalloc (size);
@@ -488,7 +493,7 @@ int igc_setup_rx_resources(struct igc_ring *rx_ring)return 0 ; err: -igc_xdp_unregister_rxq_info (rx_ring); +xdp_rxq_info_unreg (&rx_ring->xdp_rxq);vfree (rx_ring->rx_buffer_info); rx_ring->rx_buffer_info =NULL ;netdev_err (ndev,"Unable to allocate memory for Rx descriptor ring\n" );
@@ -536,6 +541,9 @@ static void igc_configure_rx_ring(struct igc_adapter *adapter,u32 srrctl =0 , rxdctl =0 ;u64 rdba = ring->dma; +WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, +MEM_TYPE_PAGE_SHARED ,NULL )); +if (igc_xdp_is_enabled (adapter))set_ring_uses_large_buffer (ring);
drivers/net/ethernet/intel/igc/igc_xdp.c +0 -27
@@ -31,30 +31,3 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,return 0 ; } - -int igc_xdp_register_rxq_info (struct igc_ring *ring) -{ -struct net_device *dev = ring->netdev; -int err; - - err =xdp_rxq_info_reg (&ring->xdp_rxq, dev, ring->queue_index,0 ); -if (err) { -netdev_err (dev,"Failed to register xdp rxq info\n" ); -return err; - } - - err =xdp_rxq_info_reg_mem_model (&ring->xdp_rxq,MEM_TYPE_PAGE_SHARED , -NULL ); -if (err) { -netdev_err (dev,"Failed to register xdp rxq mem model\n" ); -xdp_rxq_info_unreg (&ring->xdp_rxq); -return err; - } - -return 0 ; -} - -void igc_xdp_unregister_rxq_info (struct igc_ring *ring) -{ -xdp_rxq_info_unreg (&ring->xdp_rxq); -}
drivers/net/ethernet/intel/igc/igc_xdp.h +0 -3
@@ -7,9 +7,6 @@int igc_xdp_set_prog (struct igc_adapter *adapter,struct bpf_prog *prog,struct netlink_ext_ack *extack); -int igc_xdp_register_rxq_info (struct igc_ring *ring); -void igc_xdp_unregister_rxq_info (struct igc_ring *ring); -static inline bool igc_xdp_is_enabled (struct igc_adapter *adapter) {return !!adapter->xdp_prog;
Signature · 1 line
2.17.1
PATCH v5 4/9 igc: Refactor XDP rxq info registration
Quoted 18 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Refactor XDP rxq info registration code, preparing the driver for
AF_XDPzero-copy support which is added by upcoming patches.Currently,
xdp_rxqand memory model are both registered during RX resource setup time byigc_xdp_register_rxq_info()helper. WithAF_XDP, we want to register the memory model later on while configuring the ring because we will know which memory model type to register (MEM_TYPE_PAGE_SHAREDorMEM_TYPE_XSK_BUFF_POOL).The helpers
igc_xdp_register_rxq_info()andigc_xdp_unregister_rxq_info()are not useful anymore so they are removed.Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>
Quoted 6 lines
--- drivers/net/ethernet/intel/igc/igc_main.c | 16 ++++++++++---- drivers/net/ethernet/intel/igc/igc_xdp.c | 27 ----------------------- drivers/net/ethernet/intel/igc/igc_xdp.h | 3 --- 3 files changed, 12 insertions(+), 34 deletions(-)
PATCH v5 5/9 igc: Introduce TX/RX stats helpers
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
In preparation for AF_XDP zero-copy support, encapsulate the code that updates the driver RX stats in its own local helper so it can be reused in the zero-copy path. Likewise, encapsulate TX stats code as well.
--- drivers/net/ethernet/intel/igc/igc_main.c | 43 ++++++++++++++++------- 1 file changed, 31 insertions(+), 12 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +31 -12
@@ -2112,6 +2112,20 @@ static void igc_finalize_xdp(struct igc_adapter *adapter, int status)xdp_do_flush (); } +static void igc_update_rx_stats (struct igc_q_vector *q_vector, +unsigned int packets,unsigned int bytes) +{ +struct igc_ring *ring = q_vector->rx.ring; + +u64_stats_update_begin (&ring->rx_syncp); + ring->rx_stats.packets += packets; + ring->rx_stats.bytes += bytes; +u64_stats_update_end (&ring->rx_syncp); + + q_vector->rx.total_packets += packets; + q_vector->rx.total_bytes += bytes; +} +static int igc_clean_rx_irq (struct igc_q_vector *q_vector,const int budget) {unsigned int total_bytes =0 , total_packets =0 ;
@@ -2235,12 +2249,7 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)/* place incomplete frames back on ring for completion */ rx_ring->skb = skb; -u64_stats_update_begin (&rx_ring->rx_syncp); - rx_ring->rx_stats.packets += total_packets; - rx_ring->rx_stats.bytes += total_bytes; -u64_stats_update_end (&rx_ring->rx_syncp); - q_vector->rx.total_packets += total_packets; - q_vector->rx.total_bytes += total_bytes; +igc_update_rx_stats (q_vector, total_packets, total_bytes);if (cleaned_count)igc_alloc_rx_buffers (rx_ring, cleaned_count);
@@ -2248,6 +2257,20 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)return total_packets; } +static void igc_update_tx_stats (struct igc_q_vector *q_vector, +unsigned int packets,unsigned int bytes) +{ +struct igc_ring *ring = q_vector->tx.ring; + +u64_stats_update_begin (&ring->tx_syncp); + ring->tx_stats.bytes += bytes; + ring->tx_stats.packets += packets; +u64_stats_update_end (&ring->tx_syncp); + + q_vector->tx.total_bytes += bytes; + q_vector->tx.total_packets += packets; +} +/** * igc_clean_tx_irq - Reclaim resources after transmit completes * @q_vector: pointer to q_vector containing needed info
@@ -2350,12 +2373,8 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget) i += tx_ring->count; tx_ring->next_to_clean = i; -u64_stats_update_begin (&tx_ring->tx_syncp); - tx_ring->tx_stats.bytes += total_bytes; - tx_ring->tx_stats.packets += total_packets; -u64_stats_update_end (&tx_ring->tx_syncp); - q_vector->tx.total_bytes += total_bytes; - q_vector->tx.total_packets += total_packets; + +igc_update_tx_stats (q_vector, total_packets, total_bytes);if (test_bit (IGC_RING_FLAG_TX_DETECT_HANG , &tx_ring->flags)) {struct igc_hw *hw = &adapter->hw;
Signature · 1 line
2.17.1
PATCH v5 5/9 igc: Introduce TX/RX stats helpers
Quoted 6 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
In preparation for
AF_XDPzero-copy support, encapsulate the code that updates the driver RX stats in its own local helper so it can be reused in the zero-copy path. Likewise, encapsulate TX stats code as well.
Quoted 8 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 43 ++++++++++++++++------- 1 file changed, 31 insertions(+), 12 deletions(-)
PATCH v5 6/9 igc: Introduce igc_unmap_tx_buffer() helper
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
In preparation for AF_XDP zero-copy support, encapsulate the code that unmaps tx buffers into its own local helper so we can reuse it, avoiding code duplication.
--- drivers/net/ethernet/intel/igc/igc_main.c | 49 +++++++---------------- 1 file changed, 15 insertions(+), 34 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +15 -34
@@ -171,6 +171,14 @@ static void igc_get_hw_control(struct igc_adapter *adapter) ctrl_ext | IGC_CTRL_EXT_DRV_LOAD); } +static void igc_unmap_tx_buffer (struct device *dev,struct igc_tx_buffer *buf) +{ +dma_unmap_single (dev,dma_unmap_addr (buf, dma), +dma_unmap_len (buf, len),DMA_TO_DEVICE ); + +dma_unmap_len_set (buf, len,0 ); +} +/** * igc_clean_tx_ring - Free Tx Buffers * @tx_ring: ring to be cleaned
@@ -188,11 +196,7 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)else dev_kfree_skb_any (tx_buffer->skb); -/* unmap skb header data */ -dma_unmap_single (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);/* check for eop_desc to determine the end of the packet */ eop_desc = tx_buffer->next_to_watch;
@@ -211,10 +215,7 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)/* unmap any remaining paged data */ if (dma_unmap_len (tx_buffer, len)) -dma_unmap_page (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer); }/* move us one more past the eop_desc for start of next pkt */
@@ -1219,11 +1220,7 @@ static int igc_tx_map(struct igc_ring *tx_ring,/* clear dma mappings for failed tx_buffer_info map */ while (tx_buffer != first) {if (dma_unmap_len (tx_buffer, len)) -dma_unmap_page (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); -dma_unmap_len_set (tx_buffer, len,0 ); +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);if (i-- ==0 ) i += tx_ring->count;
@@ -1231,11 +1228,7 @@ static int igc_tx_map(struct igc_ring *tx_ring, }if (dma_unmap_len (tx_buffer, len)) -dma_unmap_single (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); -dma_unmap_len_set (tx_buffer, len,0 ); +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);dev_kfree_skb_any (tx_buffer->skb); tx_buffer->skb =NULL ;
@@ -2321,14 +2314,7 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget)else napi_consume_skb (tx_buffer->skb, napi_budget); -/* unmap skb header data */ -dma_unmap_single (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); - -/* clear tx_buffer data */ -dma_unmap_len_set (tx_buffer, len,0 ); +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);/* clear last DMA location and unmap remaining buffers */ while (tx_desc != eop_desc) {
@@ -2342,13 +2328,8 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget) }/* unmap any remaining paged data */ -if (dma_unmap_len (tx_buffer, len)) { -dma_unmap_page (tx_ring->dev, -dma_unmap_addr (tx_buffer, dma), -dma_unmap_len (tx_buffer, len), -DMA_TO_DEVICE ); -dma_unmap_len_set (tx_buffer, len,0 ); - } +if (dma_unmap_len (tx_buffer, len)) +igc_unmap_tx_buffer (tx_ring->dev, tx_buffer); }/* move us one more past the eop_desc for start of next pkt */
Signature · 1 line
2.17.1
PATCH v5 6/9 igc: Introduce igc_unmap_tx_buffer() helper
Quoted 6 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
In preparation for
AF_XDPzero-copy support, encapsulate the code that unmaps tx buffers into its own local helper so we can reuse it, avoiding code duplication.
Quoted 8 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 49 +++++++---------------- 1 file changed, 15 insertions(+), 34 deletions(-)
PATCH v5 7/9 igc: Replace IGC_TX_FLAGS_XDP flag by an enum
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Up to this point, tx buffers are associated with either a skb or a xdpf, and the IGC_TX_FLAGS_XDP flag was enough to distinguish between these two case. However, with upcoming patches that will add AF_XDP zero-copy support, a third case will be introduced so this flag-based approach won't fit well.
In preparation to land AF_XDP zero-copy support, replace the IGC_TX_FLAGS_XDP flag by an enum which will be extended once zero-copy support is introduced to the driver.
--- drivers/net/ethernet/intel/igc/igc.h | 8 +++++-- drivers/net/ethernet/intel/igc/igc_main.c | 27 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +6 -2
@@ -390,8 +390,6 @@ enum igc_tx_flags {/* olinfo flags */ IGC_TX_FLAGS_IPV4 =0x10 , IGC_TX_FLAGS_CSUM = 0x20, - - IGC_TX_FLAGS_XDP = 0x100, }; enum igc_boards {
@@ -408,12 +406,18 @@ enum igc_boards {#define TXD_USE_COUNT (S ) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD)#define DESC_NEEDED (MAX_SKB_FRAGS + 4) +enum igc_tx_buffer_type { +IGC_TX_BUFFER_TYPE_SKB , +IGC_TX_BUFFER_TYPE_XDP , +}; +/* wrapper around a pointer to a socket buffer, * so a DMA handle can be stored along with the buffer */ struct igc_tx_buffer {union igc_adv_tx_desc *next_to_watch;unsigned long time_stamp; +enum igc_tx_buffer_type type;union {struct sk_buff *skb;struct xdp_frame *xdpf;
drivers/net/ethernet/intel/igc/igc_main.c +22 -5
@@ -191,10 +191,18 @@ static void igc_clean_tx_ring(struct igc_ring *tx_ring)while (i != tx_ring->next_to_use) {union igc_adv_tx_desc *eop_desc, *tx_desc; -if (tx_buffer->tx_flags &IGC_TX_FLAGS_XDP ) +switch (tx_buffer->type) { +case IGC_TX_BUFFER_TYPE_XDP :xdp_return_frame (tx_buffer->xdpf); -else +break ; +case IGC_TX_BUFFER_TYPE_SKB :dev_kfree_skb_any (tx_buffer->skb); +break ; +default : +netdev_warn_once (tx_ring->netdev, +"Unknown tx buffer type\n" ); +break ; + }igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);
@@ -1361,6 +1369,7 @@ static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb,/* record the location of the first descriptor for this packet */ first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; + first->type =IGC_TX_BUFFER_TYPE_SKB ; first->skb = skb; first->bytecount = skb->len; first->gso_segs =1 ;
@@ -1944,8 +1953,8 @@ static int igc_xdp_init_tx_buffer(struct igc_tx_buffer *buffer,return -ENOMEM ; } + buffer->type =IGC_TX_BUFFER_TYPE_XDP ; buffer->xdpf = xdpf; - buffer->tx_flags =IGC_TX_FLAGS_XDP ; buffer->protocol =0 ; buffer->bytecount = xdpf->len; buffer->gso_segs =1 ;
@@ -2309,10 +2318,18 @@ static bool igc_clean_tx_irq(struct igc_q_vector *q_vector, int napi_budget) total_bytes += tx_buffer->bytecount; total_packets += tx_buffer->gso_segs; -if (tx_buffer->tx_flags &IGC_TX_FLAGS_XDP ) +switch (tx_buffer->type) { +case IGC_TX_BUFFER_TYPE_XDP :xdp_return_frame (tx_buffer->xdpf); -else +break ; +case IGC_TX_BUFFER_TYPE_SKB :napi_consume_skb (tx_buffer->skb, napi_budget); +break ; +default : +netdev_warn_once (tx_ring->netdev, +"Unknown tx buffer type\n" ); +break ; + }igc_unmap_tx_buffer (tx_ring->dev, tx_buffer);
Signature · 1 line
2.17.1
PATCH v5 7/9 igc: Replace IGC_TX_FLAGS_XDP flag by an enum
Quoted 12 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Up to this point, tx buffers are associated with either a skb or a xdpf, and the
IGC_TX_FLAGS_XDPflag was enough to distinguish between these two case. However, with upcoming patches that will addAF_XDPzero-copy support, a third case will be introduced so this flag-based approach won't fit well.In preparation to land
AF_XDPzero-copy support, replace theIGC_TX_FLAGS_XDPflag by an enum which will be extended once zero-copy support is introduced to the driver.
Quoted 9 lines
Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 8 +++++-- drivers/net/ethernet/intel/igc/igc_main.c | 27 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-)
PATCH v5 8/9 igc: Enable RX via AF_XDP zero-copy
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Add support for receiving packets via AF_XDP zero-copy mechanism.
Add a new flag to 'enum igc_ring_flags_t' to indicate the ring has AF_XDP zero-copy enabled so proper ring setup is carried out during ring configuration in igc_configure_rx_ring().
RX buffers can now be allocated via the shared pages mechanism (default behavior of the driver) or via xsk pool (when AF_XDP zero-copy is enabled) so a union is added to the 'struct igc_rx_buffer' to cover both cases.
When AF_XDP zero-copy is enabled, rx buffers are allocated from the xsk pool using the new helper igc_alloc_rx_buffers_zc() which is the counterpart of igc_alloc_rx_buffers().
Likewise other Intel drivers that support AF_XDP zero-copy, in igc we have a dedicated path for cleaning up rx irqs when zero-copy is enabled. This avoids adding too many checks within igc_clean_rx_irq(), resulting in a more readable and efficient code since this function is called from the hot-path of the driver.
--- drivers/net/ethernet/intel/igc/igc.h | 22 +- drivers/net/ethernet/intel/igc/igc_base.h | 1 + drivers/net/ethernet/intel/igc/igc_main.c | 338 +++++++++++++++++++++- drivers/net/ethernet/intel/igc/igc_xdp.c | 98 +++++++ drivers/net/ethernet/intel/igc/igc_xdp.h | 2 + 5 files changed, 442 insertions(+), 19 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +16 -6
@@ -118,6 +118,7 @@ struct igc_ring { };struct xdp_rxq_info xdp_rxq; +struct xsk_buff_pool *xsk_pool; }____cacheline_internodealigned_in_smp ;/* Board specific private data structure */
@@ -255,6 +256,9 @@ bool igc_has_link(struct igc_adapter *adapter);void igc_reset (struct igc_adapter *adapter);int igc_set_spd_dplx (struct igc_adapter *adapter,u32 spd,u8 dplx);void igc_update_stats (struct igc_adapter *adapter); +void igc_disable_rx_ring (struct igc_ring *ring); +void igc_enable_rx_ring (struct igc_ring *ring); +int igc_xsk_wakeup (struct net_device *dev,u32 queue_id,u32 flags);/* igc_dump declarations */ void igc_rings_dump (struct igc_adapter *adapter);
@@ -432,14 +436,19 @@ struct igc_tx_buffer { };struct igc_rx_buffer { -dma_addr_t dma; -struct page *page; +union { +struct { +dma_addr_t dma; +struct page *page;#if (BITS_PER_LONG >32 ) || (PAGE_SIZE >=65536 ) -__u32 page_offset; +__u32 page_offset;#else -__u16 page_offset; +__u16 page_offset;#endif -__u16 pagecnt_bias; +__u16 pagecnt_bias; + }; +struct xdp_buff *xdp; + }; };struct igc_q_vector {
@@ -525,7 +534,8 @@ enum igc_ring_flags_t {IGC_RING_FLAG_RX_SCTP_CSUM ,IGC_RING_FLAG_RX_LB_VLAN_BSWAP ,IGC_RING_FLAG_TX_CTX_IDX , - IGC_RING_FLAG_TX_DETECT_HANG +IGC_RING_FLAG_TX_DETECT_HANG , + IGC_RING_FLAG_AF_XDP_ZC, };#define ring_uses_large_buffer (ring) \
drivers/net/ethernet/intel/igc/igc_base.h +1 -0
@@ -81,6 +81,7 @@ union igc_adv_rx_desc {/* Additional Receive Descriptor Control definitions */ #define IGC_RXDCTL_QUEUE_ENABLE 0x02000000/* Ena specific Rx Queue */ +#define IGC_RXDCTL_SWFLUSH 0x04000000/* Receive Software Flush */ /* SRRCTL bit definitions */ #define IGC_SRRCTL_BSIZEPKT_SHIFT 10/* Shift _right_ */
drivers/net/ethernet/intel/igc/igc_main.c +325 -13
429 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_xdp.c +98 -0
107 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_xdp.h +2 -0
@@ -6,6 +6,8 @@int igc_xdp_set_prog (struct igc_adapter *adapter,struct bpf_prog *prog,struct netlink_ext_ack *extack); +int igc_xdp_setup_pool (struct igc_adapter *adapter,struct xsk_buff_pool *pool, +u16 queue_id);static inline bool igc_xdp_is_enabled (struct igc_adapter *adapter) {
Signature · 1 line
2.17.1
PATCH v5 8/9 igc: Enable RX via AF_XDP zero-copy
Quoted 27 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Add support for receiving packets via
AF_XDPzero-copy mechanism.Add a new flag to 'enum
igc_ring_flags_t' to indicate the ring hasAF_XDPzero-copy enabled so proper ring setup is carried out during ring configuration inigc_configure_rx_ring().RX buffers can now be allocated via the shared pages mechanism (default behavior of the driver) or via xsk pool (when
AF_XDPzero-copy is enabled) so a union is added to the 'structigc_rx_buffer' to cover both cases.When
AF_XDPzero-copy is enabled, rx buffers are allocated from the xsk pool using the new helperigc_alloc_rx_buffers_zc()which is the counterpart ofigc_alloc_rx_buffers().Likewise other Intel drivers that support
AF_XDPzero-copy, in igc we have a dedicated path for cleaning up rx irqs when zero-copy is enabled. This avoids adding too many checks withinigc_clean_rx_irq(), resulting in a more readable and efficient code since this function is called from the hot-path of the driver.Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>
Quoted 8 lines
--- drivers/net/ethernet/intel/igc/igc.h | 22 +- drivers/net/ethernet/intel/igc/igc_base.h | 1 + drivers/net/ethernet/intel/igc/igc_main.c | 338 +++++++++++++++++++++- drivers/net/ethernet/intel/igc/igc_xdp.c | 98 +++++++ drivers/net/ethernet/intel/igc/igc_xdp.h | 2 + 5 files changed, 442 insertions(+), 19 deletions(-)
PATCH v5 9/9 igc: Enable TX via AF_XDP zero-copy
In reply to Jithu JosephFrom: Andre Guedes <[email protected]>
Add support for transmitting packets via AF_XDP zero-copy mechanism.
The packet transmission itself is implemented by igc_xdp_xmit_zc() which is called from igc_clean_tx_irq() when the ring has AF_XDP zero-copy enabled. Likewise i40e and ice drivers, the transmission budget used is the number of descriptors available on the ring.
A new tx buffer type is introduced to 'enum igc_tx_buffer_type' to indicate the tx buffer uses memory from xsk pool so it can be properly cleaned after transmission or when the ring is cleaned.
The I225 controller has only 4 Tx hardware queues so the main difference between igc and other Intel drivers that support AF_XDP zero-copy is that there is no tx ring dedicated exclusively to XDP. Instead, tx rings are shared between the network stack and XDP, and netdev queue lock is used to ensure mutual exclusion. This is the same approach implemented to support XDP_TX and XDP_REDIRECT actions.
--- drivers/net/ethernet/intel/igc/igc.h | 3 + drivers/net/ethernet/intel/igc/igc_base.h | 1 + drivers/net/ethernet/intel/igc/igc_main.c | 113 +++++++++++++++++++++- drivers/net/ethernet/intel/igc/igc_xdp.c | 20 +++- 4 files changed, 129 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +3 -0
@@ -258,6 +258,8 @@ int igc_set_spd_dplx(struct igc_adapter *adapter, u32 spd, u8 dplx);void igc_update_stats (struct igc_adapter *adapter);void igc_disable_rx_ring (struct igc_ring *ring);void igc_enable_rx_ring (struct igc_ring *ring); +void igc_disable_tx_ring (struct igc_ring *ring); +void igc_enable_tx_ring (struct igc_ring *ring);int igc_xsk_wakeup (struct net_device *dev,u32 queue_id,u32 flags);/* igc_dump declarations */
@@ -413,6 +415,7 @@ enum igc_boards {enum igc_tx_buffer_type {IGC_TX_BUFFER_TYPE_SKB ,IGC_TX_BUFFER_TYPE_XDP , +IGC_TX_BUFFER_TYPE_XSK , };/* wrapper around a pointer to a socket buffer,
drivers/net/ethernet/intel/igc/igc_base.h +1 -0
@@ -78,6 +78,7 @@ union igc_adv_rx_desc {/* Additional Transmit Descriptor Control definitions */ #define IGC_TXDCTL_QUEUE_ENABLE 0x02000000/* Ena specific Tx Queue */ +#define IGC_TXDCTL_SWFLUSH 0x04000000/* Transmit Software Flush */ /* Additional Receive Descriptor Control definitions */ #define IGC_RXDCTL_QUEUE_ENABLE 0x02000000/* Ena specific Rx Queue */
drivers/net/ethernet/intel/igc/igc_main.c +109 -4
188 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_xdp.c +16 -4
@@ -39,13 +39,14 @@ static int igc_xdp_enable_pool(struct igc_adapter *adapter, {struct net_device *ndev = adapter->netdev;struct device *dev = &adapter->pdev->dev; -struct igc_ring *rx_ring; +struct igc_ring *rx_ring, *tx_ring;struct napi_struct *napi;bool needs_reset;u32 frame_size;int err; -if (queue_id >= adapter->num_rx_queues) +if (queue_id >= adapter->num_rx_queues || + queue_id >= adapter->num_tx_queues)return -EINVAL ; frame_size =xsk_pool_get_rx_frame_size (pool);
@@ -67,18 +68,23 @@ static int igc_xdp_enable_pool(struct igc_adapter *adapter, needs_reset =netif_running (adapter->netdev) &&igc_xdp_is_enabled (adapter); rx_ring = adapter->rx_ring[queue_id]; + tx_ring = adapter->tx_ring[queue_id]; +/* Rx and Tx rings share the same napi context. */ napi = &rx_ring->q_vector->napi;if (needs_reset) {igc_disable_rx_ring (rx_ring); +igc_disable_tx_ring (tx_ring);napi_disable (napi); }set_bit (IGC_RING_FLAG_AF_XDP_ZC , &rx_ring->flags); +set_bit (IGC_RING_FLAG_AF_XDP_ZC , &tx_ring->flags);if (needs_reset) {napi_enable (napi);igc_enable_rx_ring (rx_ring); +igc_enable_tx_ring (tx_ring); err =igc_xsk_wakeup (ndev, queue_id,XDP_WAKEUP_RX );if (err)
@@ -90,12 +96,13 @@ static int igc_xdp_enable_pool(struct igc_adapter *adapter,static int igc_xdp_disable_pool (struct igc_adapter *adapter,u16 queue_id) { +struct igc_ring *rx_ring, *tx_ring;struct xsk_buff_pool *pool; -struct igc_ring *rx_ring;struct napi_struct *napi;bool needs_reset; -if (queue_id >= adapter->num_rx_queues) +if (queue_id >= adapter->num_rx_queues || + queue_id >= adapter->num_tx_queues)return -EINVAL ; pool =xsk_get_pool_from_qid (adapter->netdev, queue_id);
@@ -105,19 +112,24 @@ static int igc_xdp_disable_pool(struct igc_adapter *adapter, u16 queue_id) needs_reset =netif_running (adapter->netdev) &&igc_xdp_is_enabled (adapter); rx_ring = adapter->rx_ring[queue_id]; + tx_ring = adapter->tx_ring[queue_id]; +/* Rx and Tx rings share the same napi context. */ napi = &rx_ring->q_vector->napi;if (needs_reset) {igc_disable_rx_ring (rx_ring); +igc_disable_tx_ring (tx_ring);napi_disable (napi); }xsk_pool_dma_unmap (pool,IGC_RX_DMA_ATTR );clear_bit (IGC_RING_FLAG_AF_XDP_ZC , &rx_ring->flags); +clear_bit (IGC_RING_FLAG_AF_XDP_ZC , &tx_ring->flags);if (needs_reset) {napi_enable (napi);igc_enable_rx_ring (rx_ring); +igc_enable_tx_ring (tx_ring); }return 0 ;
Signature · 1 line
2.17.1
PATCH v5 9/9 igc: Enable TX via AF_XDP zero-copy
Quoted 24 lines · Jithu Joseph
From: Andre Guedes <[email protected]>
Add support for transmitting packets via
AF_XDPzero-copy mechanism.The packet transmission itself is implemented by
igc_xdp_xmit_zc()which is called fromigc_clean_tx_irq()when the ring hasAF_XDPzero-copy enabled. Likewise i40e and ice drivers, the transmission budget used is the number of descriptors available on the ring.A new tx buffer type is introduced to 'enum
igc_tx_buffer_type' to indicate the tx buffer uses memory from xsk pool so it can be properly cleaned after transmission or when the ring is cleaned.The I225 controller has only 4 Tx hardware queues so the main difference between igc and other Intel drivers that support
AF_XDPzero-copy is that there is no tx ring dedicated exclusively to XDP. Instead, tx rings are shared between the network stack and XDP, and netdev queue lock is used to ensure mutual exclusion. This is the same approach implemented to supportXDP_TXandXDP_REDIRECTactions.Signed-off-by Andre Guedes <[email protected]>Signed-off-by Vedang Patel <[email protected]>Signed-off-by Jithu Joseph <[email protected]>Reviewed-by Maciej Fijalkowski <[email protected]>
Quoted 7 lines
--- drivers/net/ethernet/intel/igc/igc.h | 3 + drivers/net/ethernet/intel/igc/igc_base.h | 1 + drivers/net/ethernet/intel/igc/igc_main.c | 113 +++++++++++++++++++++- drivers/net/ethernet/intel/igc/igc_xdp.c | 20 +++- 4 files changed, 129 insertions(+), 8 deletions(-)