net: fec: improve XDP copy mode and add AF_XDP zero-copy support
Subsystems (5)
Wei Fang
maintainerv2 cover net: fec: improve XDP copy mode and add AF_XDP zero-copy support
This patch set optimizes the XDP copy mode logic as follows.
1. Separate the processing of RX XDP frames from fec_enet_rx_queue(), and adds a separate function fec_enet_rx_queue_xdp() for handling XDP frames.
2. For TX XDP packets, using the batch sending method to avoid frequent MMIO writes.
3. Use the switch statement to check the tx_buf type instead of the if...else... statement, making the cleanup logic of TX BD ring cleared and more efficient.
We compared the performance of XDP copy mode before and after applying this patch set, and the results show that the performance has improved.
Before applying this patch set.
root@imx93evk:~# ./xdp-bench tx eth0 Summary 396,868 rx/s 0 err,drop/s Summary 396,024 rx/s 0 err,drop/s
root@imx93evk:~# ./xdp-bench drop eth0 Summary 684,781 rx/s 0 err/s Summary 675,746 rx/s 0 err/s
root@imx93evk:~# ./xdp-bench pass eth0 Summary 208,552 rx/s 0 err,drop/s Summary 208,654 rx/s 0 err,drop/s
root@imx93evk:~# ./xdp-bench redirect eth0 eth0 eth0->eth0 311,210 rx/s 0 err,drop/s 311,208 xmit/s eth0->eth0 310,808 rx/s 0 err,drop/s 310,809 xmit/s
After applying this patch set.
root@imx93evk:~# ./xdp-bench tx eth0 Summary 425,778 rx/s 0 err,drop/s Summary 426,042 rx/s 0 err,drop/s
root@imx93evk:~# ./xdp-bench drop eth0 Summary 698,351 rx/s 0 err/s Summary 701,882 rx/s 0 err/s
root@imx93evk:~# ./xdp-bench pass eth0 Summary 210,348 rx/s 0 err,drop/s Summary 210,016 rx/s 0 err,drop/s
root@imx93evk:~# ./xdp-bench redirect eth0 eth0 eth0->eth0 354,407 rx/s 0 err,drop/s 354,401 xmit/s eth0->eth0 350,381 rx/s 0 err,drop/s 350,389 xmit/s
This patch set also addes the AF_XDP zero-copy support, and we tested the performance on i.MX93 platform with xdpsock tool. The following is the performance comparison of copy mode and zero-copy mode. It can be seen that the performance of zero-copy mode is better than that of copy mode.
1. MAC swap L2 forwarding
1.1 Zero-copy mode
root@imx93evk:~# ./xdpsock -i eth0 -l -z
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00
rx 414715 415455
tx 414715 4154551.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -l -c
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00
rx 356396 356609
tx 356396 3566092. TX only
2.1 Zero-copy mode
root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -z
sock0@eth0:0 txonly xdp-drv
pps pkts 1.00
rx 0 0
tx 1119573 11267202.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -c
sock0@eth0:0 txonly xdp-drv
pps pkts 1.00
rx 0 0
tx 406864 407616---
v2:
1. Improve the commit message
2. Remove the unused variable dma from fec_enet_rx_queue_xsk() to fix the build warning
3. Remove fec_txq_trigger_xmit() from fec_enet_xsk_tx_xmit()
4. Separate some new patches, patch 4, 8, 13.
5. Collect Reviewed-by tags.
vl link: https://lore.kernel.org/imx/[email protected]/
---
Wei Fang (14):
net: fec: add fec_txq_trigger_xmit() helper
net: fec: add fec_rx_error_check() to check RX errors
net: fec: add rx_shift to indicate the extra bytes padded in front of
RX frame
net: fec: add fec_build_skb() to build a skb
net: fec: improve fec_enet_rx_queue()
net: fec: add fec_enet_rx_queue_xdp() for XDP path
net: fec: transmit XDP frames in bulk
net: fec: remove unnecessary NULL pointer check when clearing TX BD
ring
net: fec: use switch statement to check the type of tx_buf
net: fec: remove the size parameter from fec_enet_create_page_pool()
net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()
net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page
pool
net: fec: improve fec_enet_tx_queue()
net: fec: add AF_XDP zero-copy support
drivers/net/ethernet/freescale/fec.h | 14 +- drivers/net/ethernet/freescale/fec_main.c | 1455 +++++++++++++++------ 2 files changed, 1079 insertions(+), 390 deletions(-)
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 1/14 net: fec: add fec_txq_trigger_xmit() helper
Currently, the workaround for FEC_QUIRK_ERR007885 has three call sites, so add the helper fec_txq_trigger_xmit() to make the code more concise and reusable.
--- drivers/net/ethernet/freescale/fec_main.c | 32 ++++++++++------------- 1 file changed, 14 insertions(+), 18 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +14 -18
@@ -508,6 +508,17 @@ fec_enet_create_page_pool(struct fec_enet_private *fep,return err; } +static void fec_txq_trigger_xmit (struct fec_enet_private *fep, +struct fec_enet_priv_tx_q *txq) +{ +if (!(fep->quirks &FEC_QUIRK_ERR007885 ) || + !readl (txq->bd.reg_desc_active) || + !readl (txq->bd.reg_desc_active) || + !readl (txq->bd.reg_desc_active) || + !readl (txq->bd.reg_desc_active)) +writel (0 , txq->bd.reg_desc_active); +} +static struct bufdesc * fec_enet_txq_submit_frag_skb(struct fec_enet_priv_tx_q *txq, struct sk_buff *skb,
@@ -717,12 +728,7 @@ static int fec_enet_txq_submit_skb(struct fec_enet_priv_tx_q *txq, txq->bd.cur = bdp;/* Trigger transmission start */ -if (!(fep->quirks &FEC_QUIRK_ERR007885 ) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active)) -writel (0 , txq->bd.reg_desc_active); +fec_txq_trigger_xmit (fep, txq);return 0 ; }
@@ -913,12 +919,7 @@ static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq, txq->bd.cur = bdp;/* Trigger transmission start */ -if (!(fep->quirks &FEC_QUIRK_ERR007885 ) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active)) -writel (0 , txq->bd.reg_desc_active); +fec_txq_trigger_xmit (fep, txq);return 0 ;
@@ -3935,12 +3936,7 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, txq->bd.cur = bdp;/* Trigger transmission start */ -if (!(fep->quirks &FEC_QUIRK_ERR007885 ) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active) || - !readl (txq->bd.reg_desc_active)) -writel (0 , txq->bd.reg_desc_active); +fec_txq_trigger_xmit (fep, txq);return 0 ; }
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 2/14 net: fec: add fec_rx_error_check() to check RX errors
In reply to Wei FangExtract fec_rx_error_check() from fec_enet_rx_queue(), this helper is used to check RX errors. And it will be used in XDP and XDP zero copy paths in subsequent patches.
--- drivers/net/ethernet/freescale/fec_main.c | 58 ++++++++++++++--------- 1 file changed, 36 insertions(+), 22 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +36 -22
@@ -1746,6 +1746,41 @@ static void fec_enet_rx_vlan(const struct net_device *ndev, struct sk_buff *skb) } } +static int fec_rx_error_check (struct net_device *ndev,u16 status) +{ +if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH |BD_ENET_RX_NO | +BD_ENET_RX_CR |BD_ENET_RX_OV |BD_ENET_RX_LAST | +BD_ENET_RX_CL )) { + ndev->stats.rx_errors++; + +if (status &BD_ENET_RX_OV ) { +/* FIFO overrun */ + ndev->stats.rx_fifo_errors++; +return -EIO ; + } + +if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH | +BD_ENET_RX_LAST )) { +/* Frame too long or too short. */ + ndev->stats.rx_length_errors++; +if ((status &BD_ENET_RX_LAST ) &&net_ratelimit ()) +netdev_err (ndev,"rcv is not +last\n" ); + } + +/* CRC Error */ +if (status &BD_ENET_RX_CR ) + ndev->stats.rx_crc_errors++; + +/* Report late collisions as a frame error. */ +if (status & (BD_ENET_RX_NO |BD_ENET_RX_CL )) + ndev->stats.rx_frame_errors++; + +return -EIO ; + } + +return 0 ; +} +/* During a receive, the bd_rx.cur points to the current incoming buffer. * When we update through the ring, if the next incoming buffer has * not been given to the system, we just set the empty indicator,
@@ -1806,29 +1841,8 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)/* Check for errors. */ status ^=BD_ENET_RX_LAST ; -if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH |BD_ENET_RX_NO | -BD_ENET_RX_CR |BD_ENET_RX_OV |BD_ENET_RX_LAST | -BD_ENET_RX_CL )) { - ndev->stats.rx_errors++; -if (status &BD_ENET_RX_OV ) { -/* FIFO overrun */ - ndev->stats.rx_fifo_errors++; - goto rx_processing_done; - } -if (status & (BD_ENET_RX_LG |BD_ENET_RX_SH - |BD_ENET_RX_LAST )) { -/* Frame too long or too short. */ - ndev->stats.rx_length_errors++; -if (status &BD_ENET_RX_LAST ) -netdev_err (ndev,"rcv is not +last\n" ); - } -if (status &BD_ENET_RX_CR )/* CRC Error */ - ndev->stats.rx_crc_errors++; -/* Report late collisions as a frame error. */ -if (status & (BD_ENET_RX_NO |BD_ENET_RX_CL )) - ndev->stats.rx_frame_errors++; +if (unlikely (fec_rx_error_check (ndev, status))) goto rx_processing_done; - }/* Process the incoming frame. */ ndev->stats.rx_packets++;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 3/14 net: fec: add rx_shift to indicate the extra bytes padded in front of RX frame
In reply to Wei FangThe FEC of some platforms supports RX FIFO shift-16, it means the actual frame data starts at bit 16 of the first word read from RX FIFO aligning the Ethernet payload on a 32-bit boundary. The MAC writes two additional bytes in front of each frame received into the RX FIFO. Currently, the fec_enet_rx_queue() updates the data_start, sub_len and the rx_bytes statistics by checking whether FEC_QUIRK_HAS_RACC is set. This makes the code less concise, so rx_shift is added to represent the number of extra bytes padded in front of the RX frame. Furthermore, when adding separate RX handling functions for XDP copy mode and zero copy mode in the future, it will no longer be necessary to check FEC_QUIRK_HAS_RACC to update the corresponding variables.
--- drivers/net/ethernet/freescale/fec.h | 1 + drivers/net/ethernet/freescale/fec_main.c | 21 ++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -0
@@ -643,6 +643,7 @@ struct fec_enet_private {struct pm_qos_request pm_qos_req;unsigned int tx_align; +unsigned int rx_shift;/* hw interrupt coalesce */ unsigned int rx_pkts_itr;
drivers/net/ethernet/freescale/fec_main.c +8 -13
@@ -1799,22 +1799,14 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)struct bufdesc_ex *ebdp =NULL ;int index =0 ;bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ; +u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift;struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);u32 ret, xdp_result =FEC_ENET_XDP_PASS ; -u32 data_start =FEC_ENET_XDP_HEADROOM ; +u32 sub_len =4 + fep->rx_shift;int cpu =smp_processor_id ();struct xdp_buff xdp;struct page *page;__fec32 cbd_bufaddr; -u32 sub_len =4 ; - -/*If it has the FEC_QUIRK_HAS_RACC quirk property, the bit of -* FEC_RACC_SHIFT16 is set by default in the probe function. -*/ -if (fep->quirks &FEC_QUIRK_HAS_RACC ) { - data_start +=2 ; - sub_len +=2 ; - }#if defined(CONFIG_COLDFIRE ) && !defined(CONFIG_COLDFIRE_COHERENT_DMA )/*
@@ -1847,9 +1839,7 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)/* Process the incoming frame. */ ndev->stats.rx_packets++; pkt_len =fec16_to_cpu (bdp->cbd_datlen); - ndev->stats.rx_bytes += pkt_len; -if (fep->quirks &FEC_QUIRK_HAS_RACC ) - ndev->stats.rx_bytes -=2 ; + ndev->stats.rx_bytes += pkt_len - fep->rx_shift; index =fec_enet_get_bd_index (bdp, &rxq->bd); page = rxq->rx_buf[index];
@@ -4602,6 +4592,11 @@ fec_probe(struct platform_device *pdev) ndev->max_mtu = fep->max_buf_size -ETH_HLEN -ETH_FCS_LEN ; +if (fep->quirks &FEC_QUIRK_HAS_RACC ) + fep->rx_shift =2 ; +else + fep->rx_shift =0 ; + ret =register_netdev (ndev);if (ret) goto failed_register;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 4/14 net: fec: add fec_build_skb() to build a skb
In reply to Wei FangExtract the helper fec_build_skb() from fec_enet_rx_queue(), so that the code for building a skb is centralized in fec_build_skb(), which makes the code of fec_enet_rx_queue() more concise and readable.
--- drivers/net/ethernet/freescale/fec_main.c | 106 ++++++++++++---------- 1 file changed, 60 insertions(+), 46 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +60 -46
@@ -1781,6 +1781,59 @@ static int fec_rx_error_check(struct net_device *ndev, u16 status)return 0 ; } +static struct sk_buff *fec_build_skb (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq, +struct bufdesc *bdp, +struct page *page,u32 len) +{ +struct net_device *ndev = fep->netdev; +struct bufdesc_ex *ebdp; +struct sk_buff *skb; + + skb =build_skb (page_address (page), +PAGE_SIZE << fep->pagepool_order); +if (unlikely (!skb)) { +page_pool_recycle_direct (rxq->page_pool, page); + ndev->stats.rx_dropped++; +if (net_ratelimit ()) +netdev_err (ndev,"build_skb failed\n" ); + +return NULL ; + } + +skb_reserve (skb,FEC_ENET_XDP_HEADROOM + fep->rx_shift); +skb_put (skb, len); +skb_mark_for_recycle (skb); + +/* Get offloads from the enhanced buffer descriptor */ +if (fep->bufdesc_ex) { + ebdp = (struct bufdesc_ex *)bdp; + +/* If this is a VLAN packet remove the VLAN Tag */ +if (ebdp->cbd_esc &cpu_to_fec32 (BD_ENET_RX_VLAN )) +fec_enet_rx_vlan (ndev, skb); + +/* Get receive timestamp from the skb */ +if (fep->hwts_rx_en) +fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), +skb_hwtstamps (skb)); + +if (fep->csum_flags &FLAG_RX_CSUM_ENABLED ) { +if (!(ebdp->cbd_esc & +cpu_to_fec32 (FLAG_RX_CSUM_ERROR ))) +/* don't check it */ + skb->ip_summed =CHECKSUM_UNNECESSARY ; +else +skb_checksum_none_assert (skb); + } + } + + skb->protocol =eth_type_trans (skb, ndev); +skb_record_rx_queue (skb, rxq->bd.qid); + +return skb; +} +/* During a receive, the bd_rx.cur points to the current incoming buffer. * When we update through the ring, if the next incoming buffer has * not been given to the system, we just set the empty indicator,
@@ -1796,7 +1849,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)struct sk_buff *skb;ushort pkt_len;int pkt_received =0 ; -struct bufdesc_ex *ebdp =NULL ;int index =0 ;bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift;
@@ -1866,24 +1918,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) goto rx_processing_done; } -/* The packet length includes FCS, but we don't want to -* include that when passing upstream as it messes up -* bridging applications. -*/ - skb =build_skb (page_address (page), -PAGE_SIZE << fep->pagepool_order); -if (unlikely (!skb)) { -page_pool_recycle_direct (rxq->page_pool, page); - ndev->stats.rx_dropped++; - -netdev_err_once (ndev,"build_skb failed!\n" ); - goto rx_processing_done; - } - -skb_reserve (skb, data_start); -skb_put (skb, pkt_len - sub_len); -skb_mark_for_recycle (skb); -if (unlikely (need_swap)) {u8 *data;
@@ -1891,34 +1925,14 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)swap_buffer (data, pkt_len); } -/* Extract the enhanced buffer descriptor */ - ebdp =NULL ; -if (fep->bufdesc_ex) - ebdp = (struct bufdesc_ex *)bdp; - -/* If this is a VLAN packet remove the VLAN Tag */ -if (fep->bufdesc_ex && - (ebdp->cbd_esc &cpu_to_fec32 (BD_ENET_RX_VLAN ))) -fec_enet_rx_vlan (ndev, skb); - - skb->protocol =eth_type_trans (skb, ndev); - -/* Get receive timestamp from the skb */ -if (fep->hwts_rx_en && fep->bufdesc_ex) -fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), -skb_hwtstamps (skb)); - -if (fep->bufdesc_ex && - (fep->csum_flags &FLAG_RX_CSUM_ENABLED )) { -if (!(ebdp->cbd_esc &cpu_to_fec32 (FLAG_RX_CSUM_ERROR ))) { -/* don't check it */ - skb->ip_summed =CHECKSUM_UNNECESSARY ; - }else { -skb_checksum_none_assert (skb); - } - } +/* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =fec_build_skb (fep, rxq, bdp, page, pkt_len - sub_len); +if (!skb) + goto rx_processing_done; -skb_record_rx_queue (skb, queue_id);napi_gro_receive (&fep->napi, skb); rx_processing_done:
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 04/14] net: fec: add fec_build_skb() to build a skb
Quoted 6 lines · Wei Fang
Extract the helper
fec_build_skb()fromfec_enet_rx_queue(), so that the code for building a skb is centralized infec_build_skb(), which makes the code offec_enet_rx_queue()more concise and readable.Signed-off-by Wei Fang <[email protected]>---
Quoted 145 lines
drivers/net/ethernet/freescale/fec_main.c | 106 ++++++++++++---------- 1 file changed, 60 insertions(+), 46 deletions(-)drivers/net/ethernet/freescale/fec_main.c +60
-47@@ -1781,6 +1781,59 @@ static int fec_rx_error_check(struct net_device *ndev, u16 status)return 0 ; } +static struct sk_buff *fec_build_skb (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq, +struct bufdesc *bdp, +struct page *page,u32 len) +{ +struct net_device *ndev = fep->netdev; +struct bufdesc_ex *ebdp; +struct sk_buff *skb; + + skb =build_skb (page_address (page), +PAGE_SIZE << fep->pagepool_order); +if (unlikely (!skb)) { +page_pool_recycle_direct (rxq->page_pool, page); + ndev->stats.rx_dropped++; +if (net_ratelimit ()) +netdev_err (ndev,"build_skb failed\n" ); + +return NULL ; + } + +skb_reserve (skb,FEC_ENET_XDP_HEADROOM + fep->rx_shift); +skb_put (skb, len); +skb_mark_for_recycle (skb); + +/* Get offloads from the enhanced buffer descriptor */ +if (fep->bufdesc_ex) { + ebdp = (struct bufdesc_ex *)bdp; + +/* If this is a VLAN packet remove the VLAN Tag */ +if (ebdp->cbd_esc &cpu_to_fec32 (BD_ENET_RX_VLAN )) +fec_enet_rx_vlan (ndev, skb); + +/* Get receive timestamp from the skb */ +if (fep->hwts_rx_en) +fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), +skb_hwtstamps (skb)); + +if (fep->csum_flags &FLAG_RX_CSUM_ENABLED ) { +if (!(ebdp->cbd_esc & +cpu_to_fec32 (FLAG_RX_CSUM_ERROR ))) +/* don't check it */ + skb->ip_summed =CHECKSUM_UNNECESSARY ; +else +skb_checksum_none_assert (skb); + } + } + + skb->protocol =eth_type_trans (skb, ndev); +skb_record_rx_queue (skb, rxq->bd.qid); + +return skb; +} +/* During a receive, the bd_rx.cur points to the current incoming buffer. * When we update through the ring, if the next incoming buffer has * not been given to the system, we just set the empty indicator, @@ -1796,7 +1849,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)struct sk_buff *skb;ushort pkt_len;int pkt_received =0 ; -struct bufdesc_ex *ebdp =NULL ;int index =0 ;bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift;@@ -1866,24 +1918,6 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) goto rx_processing_done; } -/* The packet length includes FCS, but we don't want to -* include that when passing upstream as it messes up -* bridging applications. -*/ - skb =build_skb (page_address (page), -PAGE_SIZE << fep->pagepool_order); -if (unlikely (!skb)) { -page_pool_recycle_direct (rxq->page_pool, page); - ndev->stats.rx_dropped++; - -netdev_err_once (ndev,"build_skb failed!\n" ); - goto rx_processing_done; - } - -skb_reserve (skb, data_start); -skb_put (skb, pkt_len - sub_len); -skb_mark_for_recycle (skb); -if (unlikely (need_swap)) {u8 *data;@@ -1891,34 +1925,14 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)swap_buffer (data, pkt_len); } -/* Extract the enhanced buffer descriptor */ - ebdp =NULL ; -if (fep->bufdesc_ex) - ebdp = (struct bufdesc_ex *)bdp; - -/* If this is a VLAN packet remove the VLAN Tag */ -if (fep->bufdesc_ex && - (ebdp->cbd_esc &cpu_to_fec32 (BD_ENET_RX_VLAN ))) -fec_enet_rx_vlan (ndev, skb); - - skb->protocol =eth_type_trans (skb, ndev); - -/* Get receive timestamp from the skb */ -if (fep->hwts_rx_en && fep->bufdesc_ex) -fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), -skb_hwtstamps (skb)); - -if (fep->bufdesc_ex && - (fep->csum_flags &FLAG_RX_CSUM_ENABLED )) { -if (!(ebdp->cbd_esc &cpu_to_fec32 (FLAG_RX_CSUM_ERROR ))) { -/* don't check it */ - skb->ip_summed =CHECKSUM_UNNECESSARY ; - }else { -skb_checksum_none_assert (skb); - } - } +/* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =fec_build_skb (fep, rxq, bdp, page, pkt_len - sub_len); +if (!skb) + goto rx_processing_done; -skb_record_rx_queue (skb, queue_id);napi_gro_receive (&fep->napi, skb); rx_processing_done: --2.34.1
Wei Fang
maintainerPATCH v2 5/14 net: fec: improve fec_enet_rx_queue()
In reply to Wei FangThis patch has made the following adjustments to fec_enet_rx_queue().
1. The function parameters are modified to maintain the same style as subsequently added XDP-related interfaces.
2. Some variables are initialized at the time of declaration, and the order of local variables is updated to follow the reverse xmas tree style.
3. Replace variable cbd_bufaddr with dma.
--- drivers/net/ethernet/freescale/fec_main.c | 35 ++++++++++------------- 1 file changed, 15 insertions(+), 20 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +15 -20
@@ -1839,26 +1839,25 @@ static struct sk_buff *fec_build_skb(struct fec_enet_private *fep,* not been given to the system, we just set the empty indicator, * effectively tossing the packet. */ -static int -fec_enet_rx_queue (struct net_device *ndev,u16 queue_id,int budget) +static int fec_enet_rx_queue (struct fec_enet_private *fep, +u16 queue,int budget) { -struct fec_enet_private *fep =netdev_priv (ndev); -struct fec_enet_priv_rx_q *rxq; -struct bufdesc *bdp; -unsigned short status; -struct sk_buff *skb; -ushort pkt_len; -int pkt_received =0 ; -int index =0 ; -bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift; +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue];struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog); +bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 ret, xdp_result =FEC_ENET_XDP_PASS ; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = rxq->bd.cur;u32 sub_len =4 + fep->rx_shift;int cpu =smp_processor_id (); +int pkt_received =0 ; +u16 status, pkt_len; +struct sk_buff *skb;struct xdp_buff xdp;struct page *page; -__fec32 cbd_bufaddr; +dma_addr_t dma; +int index;#if defined(CONFIG_COLDFIRE ) && !defined(CONFIG_COLDFIRE_COHERENT_DMA )/*
@@ -1867,12 +1866,10 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)*/ flush_cache_all ();#endif - rxq = fep->rx_queue[queue_id];/* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ - bdp = rxq->bd.cur;xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq);while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) {
@@ -1881,7 +1878,7 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)break ; pkt_received++; -writel (FEC_ENET_RXF_GET (queue_id), fep->hwp +FEC_IEVENT ); +writel (FEC_ENET_RXF_GET (queue), fep->hwp +FEC_IEVENT );/* Check for errors. */ status ^=BD_ENET_RX_LAST ;
@@ -1895,15 +1892,13 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) index =fec_enet_get_bd_index (bdp, &rxq->bd); page = rxq->rx_buf[index]; - cbd_bufaddr = bdp->cbd_bufaddr; + dma =fec32_to_cpu (bdp->cbd_bufaddr);if (fec_enet_update_cbd (rxq, bdp, index)) { ndev->stats.rx_dropped++; goto rx_processing_done; } -dma_sync_single_for_cpu (&fep->pdev->dev, -fec32_to_cpu (cbd_bufaddr), - pkt_len, +dma_sync_single_for_cpu (&fep->pdev->dev, dma, pkt_len,DMA_FROM_DEVICE );prefetch (page_address (page));
@@ -1979,7 +1974,7 @@ static int fec_enet_rx(struct net_device *ndev, int budget)/* Make sure that AVB queues are processed first. */ for (i = fep->num_rx_queues -1 ; i >=0 ; i--) - done +=fec_enet_rx_queue (ndev, i, budget - done); + done +=fec_enet_rx_queue (fep, i, budget - done);return done; }
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 05/14] net: fec: improve fec_enet_rx_queue()
Quoted 5 lines · Wei Fang
This patch has made the following adjustments to
fec_enet_rx_queue().1. The function parameters are modified to maintain the same style as subsequently added XDP-related interfaces.
Quoted 8 lines
2. Some variables are initialized at the time of declaration, and the order of local variables is updated to follow the reverse xmas tree style.
3. Replace variable
cbd_bufaddrwith dma.Signed-off-by Wei Fang <[email protected]>---
Quoted 97 lines
drivers/net/ethernet/freescale/fec_main.c | 35 ++++++++++------------- 1 file changed, 15 insertions(+), 20 deletions(-)drivers/net/ethernet/freescale/fec_main.c +15
-21@@ -1839,26 +1839,25 @@ static struct sk_buff *fec_build_skb(struct fec_enet_private *fep,* not been given to the system, we just set the empty indicator, * effectively tossing the packet. */ -static int -fec_enet_rx_queue (struct net_device *ndev,u16 queue_id,int budget) +static int fec_enet_rx_queue (struct fec_enet_private *fep, +u16 queue,int budget) { -struct fec_enet_private *fep =netdev_priv (ndev); -struct fec_enet_priv_rx_q *rxq; -struct bufdesc *bdp; -unsigned short status; -struct sk_buff *skb; -ushort pkt_len; -int pkt_received =0 ; -int index =0 ; -bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift; +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue];struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog); +bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ;u32 ret, xdp_result =FEC_ENET_XDP_PASS ; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = rxq->bd.cur;u32 sub_len =4 + fep->rx_shift;int cpu =smp_processor_id (); +int pkt_received =0 ; +u16 status, pkt_len; +struct sk_buff *skb;struct xdp_buff xdp;struct page *page; -__fec32 cbd_bufaddr; +dma_addr_t dma; +int index;#if defined(CONFIG_COLDFIRE ) && !defined(CONFIG_COLDFIRE_COHERENT_DMA )/* @@ -1867,12 +1866,10 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)*/ flush_cache_all ();#endif - rxq = fep->rx_queue[queue_id];/* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ - bdp = rxq->bd.cur;xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq);while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) {@@ -1881,7 +1878,7 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget)break ; pkt_received++; -writel (FEC_ENET_RXF_GET (queue_id), fep->hwp +FEC_IEVENT ); +writel (FEC_ENET_RXF_GET (queue), fep->hwp +FEC_IEVENT );/* Check for errors. */ status ^=BD_ENET_RX_LAST ;@@ -1895,15 +1892,13 @@ fec_enet_rx_queue(struct net_device *ndev, u16 queue_id, int budget) index =fec_enet_get_bd_index (bdp, &rxq->bd); page = rxq->rx_buf[index]; - cbd_bufaddr = bdp->cbd_bufaddr; + dma =fec32_to_cpu (bdp->cbd_bufaddr);if (fec_enet_update_cbd (rxq, bdp, index)) { ndev->stats.rx_dropped++; goto rx_processing_done; } -dma_sync_single_for_cpu (&fep->pdev->dev, -fec32_to_cpu (cbd_bufaddr), - pkt_len, +dma_sync_single_for_cpu (&fep->pdev->dev, dma, pkt_len,DMA_FROM_DEVICE );prefetch (page_address (page));@@ -1979,7 +1974,7 @@ static int fec_enet_rx(struct net_device *ndev, int budget)/* Make sure that AVB queues are processed first. */ for (i = fep->num_rx_queues -1 ; i >=0 ; i--) - done +=fec_enet_rx_queue (ndev, i, budget - done); + done +=fec_enet_rx_queue (fep, i, budget - done);return done; } --2.34.1
Wei Fang
maintainerPATCH v2 6/14 net: fec: add fec_enet_rx_queue_xdp() for XDP path
In reply to Wei FangCurrently, the processing of XDP path packets and protocol stack packets are both mixed in fec_enet_rx_queue(), which makes the logic somewhat confusing and debugging more difficult. Furthermore, some logic is not needed by each other. For example, the kernel path does not need to call xdp_init_buff(), and XDP path does not support swap_buffer(), etc. This prevents XDP from achieving its maximum performance. Therefore, XDP path packets processing has been separated from fec_enet_rx_queue() by adding the fec_enet_rx_queue_xdp() function to optimize XDP path logic and improve XDP performance.
The XDP performance on the iMX93 platform was compared before and after applying this patch. Detailed results are as follows and we can see the performance has been improved.
Env: i.MX93, packet size 64 bytes including FCS, only single core and RX BD ring are used to receive packets, flow-control is off.
Before the patch is applied:
xdp-bench tx eth0
Summary 396,868 rx/s 0 err,drop/s Summary 396,024 rx/s 0 err,drop/s
xdp-bench drop eth0
Summary 684,781 rx/s 0 err/s Summary 675,746 rx/s 0 err/s
xdp-bench pass eth0
Summary 208,552 rx/s 0 err,drop/s Summary 208,654 rx/s 0 err,drop/s
xdp-bench redirect eth0 eth0
eth0->eth0 311,210 rx/s 0 err,drop/s 311,208 xmit/s eth0->eth0 310,808 rx/s 0 err,drop/s 310,809 xmit/s
After the patch is applied:
xdp-bench tx eth0
Summary 409,975 rx/s 0 err,drop/s Summary 411,073 rx/s 0 err,drop/s
xdp-bench drop eth0
Summary 700,681 rx/s 0 err/s Summary 698,102 rx/s 0 err/s
xdp-bench pass eth0
Summary 211,356 rx/s 0 err,drop/s Summary 210,629 rx/s 0 err,drop/s
xdp-bench redirect eth0 eth0
eth0->eth0 320,351 rx/s 0 err,drop/s 320,348 xmit/s eth0->eth0 318,988 rx/s 0 err,drop/s 318,988 xmit/s
--- drivers/net/ethernet/freescale/fec_main.c | 292 ++++++++++++++-------- 1 file changed, 188 insertions(+), 104 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +188 -104
@@ -79,7 +79,7 @@ static void set_multicast_list(struct net_device *ndev);static void fec_enet_itr_coal_set (struct net_device *ndev);static int fec_enet_xdp_tx_xmit (struct fec_enet_private *fep,int cpu,struct xdp_buff *xdp, -u32 dma_sync_len); +u32 dma_sync_len,int queue);#define DRIVER_NAME "fec"
@@ -1665,71 +1665,6 @@ static int fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq,return 0 ; } -static u32 -fec_enet_run_xdp (struct fec_enet_private *fep,struct bpf_prog *prog, -struct xdp_buff *xdp,struct fec_enet_priv_rx_q *rxq,int cpu) -{ -unsigned int sync, len = xdp->data_end - xdp->data; -u32 ret =FEC_ENET_XDP_PASS ; -struct page *page; -int err; -u32 act; - - act =bpf_prog_run_xdp (prog, xdp); - -/* Due xdp_adjust_tail and xdp_adjust_head: DMA sync for_device cover -* max len CPU touch -*/ - sync = xdp->data_end - xdp->data; - sync =max (sync, len); - -switch (act) { -case XDP_PASS : - rxq->stats[RX_XDP_PASS ]++; - ret =FEC_ENET_XDP_PASS ; -break ; - -case XDP_REDIRECT : - rxq->stats[RX_XDP_REDIRECT ]++; - err =xdp_do_redirect (fep->netdev, xdp, prog); -if (unlikely (err)) - goto xdp_err; - - ret =FEC_ENET_XDP_REDIR ; -break ; - -case XDP_TX : - rxq->stats[RX_XDP_TX ]++; - err =fec_enet_xdp_tx_xmit (fep, cpu, xdp, sync); -if (unlikely (err)) { - rxq->stats[RX_XDP_TX_ERRORS ]++; - goto xdp_err; - } - - ret =FEC_ENET_XDP_TX ; -break ; - -default : -bpf_warn_invalid_xdp_action (fep->netdev, prog, act); - fallthrough; - -case XDP_ABORTED : - fallthrough;/* handle aborts by dropping packet */ - -case XDP_DROP : - rxq->stats[RX_XDP_DROP ]++; -xdp_err: - ret =FEC_ENET_XDP_CONSUMED ; - page =virt_to_head_page (xdp->data); -page_pool_put_page (rxq->page_pool, page, sync, true); -if (act !=XDP_DROP ) -trace_xdp_exception (fep->netdev, prog, act); -break ; - } - -return ret; -} -static void fec_enet_rx_vlan (const struct net_device *ndev,struct sk_buff *skb) {if (ndev->features &NETIF_F_HW_VLAN_CTAG_RX ) {
@@ -1842,19 +1777,14 @@ static struct sk_buff *fec_build_skb(struct fec_enet_private *fep,static int fec_enet_rx_queue (struct fec_enet_private *fep,u16 queue,int budget) { -u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift;struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue]; -struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ; -u32 ret, xdp_result =FEC_ENET_XDP_PASS ;struct net_device *ndev = fep->netdev;struct bufdesc *bdp = rxq->bd.cur;u32 sub_len =4 + fep->rx_shift; -int cpu =smp_processor_id ();int pkt_received =0 ;u16 status, pkt_len;struct sk_buff *skb; -struct xdp_buff xdp;struct page *page;dma_addr_t dma;int index;
@@ -1870,8 +1800,6 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep,/* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ -xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq); -while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) {if (pkt_received >= budget)
@@ -1902,17 +1830,6 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep, DMA_FROM_DEVICE);prefetch (page_address (page)); -if (xdp_prog) { -xdp_buff_clear_frags_flag (&xdp); -/* subtract 16bit shift and FCS */ -xdp_prepare_buff (&xdp,page_address (page), - data_start, pkt_len - sub_len, false); - ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, cpu); - xdp_result |= ret; -if (ret !=FEC_ENET_XDP_PASS ) - goto rx_processing_done; - } -if (unlikely (need_swap)) {u8 *data;
@@ -1961,7 +1878,181 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep, } rxq->bd.cur = bdp; -if (xdp_result &FEC_ENET_XDP_REDIR ) +return pkt_received; +} + +static void fec_xdp_drop (struct fec_enet_priv_rx_q *rxq, +struct xdp_buff *xdp,u32 sync) +{ +struct page *page =virt_to_head_page (xdp->data); + +page_pool_put_page (rxq->page_pool, page, sync, true); +} + +static int +fec_enet_xdp_get_tx_queue (struct fec_enet_private *fep,int index) +{ +if (unlikely (index <0 )) +return 0 ; + +return (index % fep->num_tx_queues); +} + +static int fec_enet_rx_queue_xdp (struct fec_enet_private *fep,int queue, +int budget,struct bpf_prog *prog) +{ +u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift; +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue]; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = rxq->bd.cur; +u32 sub_len =4 + fep->rx_shift; +int cpu =smp_processor_id (); +int pkt_received =0 ; +struct sk_buff *skb; +u16 status, pkt_len; +struct xdp_buff xdp; +int tx_qid = queue; +struct page *page; +u32 xdp_res =0 ; +dma_addr_t dma; +int index, err; +u32 act, sync; + +#if defined(CONFIG_COLDFIRE ) && !defined(CONFIG_COLDFIRE_COHERENT_DMA ) +/* +* Hacky flush of all caches instead of using the DMA API for the TSO +* headers. +*/ +flush_cache_all (); +#endif + +if (unlikely (queue >= fep->num_tx_queues)) + tx_qid =fec_enet_xdp_get_tx_queue (fep, cpu); + +xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq); + +while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) { +if (pkt_received >= budget) +break ; + pkt_received++; + +writel (FEC_ENET_RXF_GET (queue), fep->hwp +FEC_IEVENT ); + +/* Check for errors. */ + status ^=BD_ENET_RX_LAST ; +if (unlikely (fec_rx_error_check (ndev, status))) + goto rx_processing_done; + +/* Process the incoming frame. */ + ndev->stats.rx_packets++; + pkt_len =fec16_to_cpu (bdp->cbd_datlen); + ndev->stats.rx_bytes += pkt_len - fep->rx_shift; + + index =fec_enet_get_bd_index (bdp, &rxq->bd); + page = rxq->rx_buf[index]; + dma =fec32_to_cpu (bdp->cbd_bufaddr); + +if (fec_enet_update_cbd (rxq, bdp, index)) { + ndev->stats.rx_dropped++; + goto rx_processing_done; + } + +dma_sync_single_for_cpu (&fep->pdev->dev, dma, pkt_len, +DMA_FROM_DEVICE ); +prefetch (page_address (page)); + +xdp_buff_clear_frags_flag (&xdp); +/* subtract 16bit shift and FCS */ + pkt_len -= sub_len; +xdp_prepare_buff (&xdp,page_address (page), data_start, + pkt_len, false); + + act =bpf_prog_run_xdp (prog, &xdp); +/* Due xdp_adjust_tail and xdp_adjust_head: DMA sync +* for_device cover max len CPU touch. +*/ + sync = xdp.data_end - xdp.data; + sync =max (sync, pkt_len); + +switch (act) { +case XDP_PASS : + rxq->stats[RX_XDP_PASS ]++; +/* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =fec_build_skb (fep, rxq, bdp, page, pkt_len); +if (!skb) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_PASS ); + }else { +napi_gro_receive (&fep->napi, skb); + } +break ; +case XDP_REDIRECT : + rxq->stats[RX_XDP_REDIRECT ]++; + err =xdp_do_redirect (ndev, &xdp, prog); +if (unlikely (err)) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_REDIRECT ); + }else { + xdp_res |=FEC_ENET_XDP_REDIR ; + } +break ; +case XDP_TX : + rxq->stats[RX_XDP_TX ]++; + err =fec_enet_xdp_tx_xmit (fep, cpu, &xdp, sync, tx_qid); +if (unlikely (err)) { + rxq->stats[RX_XDP_TX_ERRORS ]++; +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_TX ); + } +break ; +default : +bpf_warn_invalid_xdp_action (ndev, prog, act); + fallthrough; +case XDP_ABORTED : +/* handle aborts by dropping packet */ + fallthrough; +case XDP_DROP : + rxq->stats[RX_XDP_DROP ]++; +fec_xdp_drop (rxq, &xdp, sync); +break ; + } + +rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; + +if (fep->bufdesc_ex) { +struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; + + ebdp->cbd_esc =cpu_to_fec32 (BD_ENET_RX_INT ); + ebdp->cbd_prot =0 ; + ebdp->cbd_bdu =0 ; + } + +/* Make sure the updates to rest of the descriptor are +* performed before transferring ownership. +*/ +dma_wmb (); + bdp->cbd_sc =cpu_to_fec16 (status); + +/* Update BD pointer to next entry */ + bdp =fec_enet_get_nextdesc (bdp, &rxq->bd); + +/* Doing this here will keep the FEC running while we process +* incoming frames. On a heavily loaded network, we should be +* able to keep up at the expense of system resources. +*/ +writel (0 , rxq->bd.reg_desc_active); + } + + rxq->bd.cur = bdp; + +if (xdp_res &FEC_ENET_XDP_REDIR )xdp_do_flush ();return pkt_received;
@@ -1970,11 +2061,17 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep,static int fec_enet_rx (struct net_device *ndev,int budget) {struct fec_enet_private *fep =netdev_priv (ndev); +struct bpf_prog *prog =READ_ONCE (fep->xdp_prog);int i, done =0 ;/* Make sure that AVB queues are processed first. */ -for (i = fep->num_rx_queues -1 ; i >=0 ; i--) - done +=fec_enet_rx_queue (fep, i, budget - done); +for (i = fep->num_rx_queues -1 ; i >=0 ; i--) { +if (prog) + done +=fec_enet_rx_queue_xdp (fep, i, budget - done, + prog); +else + done +=fec_enet_rx_queue (fep, i, budget - done); + }return done; }
@@ -3854,15 +3951,6 @@ static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf) } } -static int -fec_enet_xdp_get_tx_queue (struct fec_enet_private *fep,int index) -{ -if (unlikely (index <0 )) -return 0 ; - -return (index % fep->num_tx_queues); -} - static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, struct fec_enet_priv_tx_q *txq, void *frame, u32 dma_sync_len,
@@ -3956,15 +4044,11 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep,static int fec_enet_xdp_tx_xmit (struct fec_enet_private *fep,int cpu,struct xdp_buff *xdp, -u32 dma_sync_len) +u32 dma_sync_len,int queue) { -struct fec_enet_priv_tx_q *txq; -struct netdev_queue *nq; -int queue, ret; - - queue =fec_enet_xdp_get_tx_queue (fep, cpu); - txq = fep->tx_queue[queue]; - nq =netdev_get_tx_queue (fep->netdev, queue); +struct netdev_queue *nq =netdev_get_tx_queue (fep->netdev, queue); +struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue]; +int ret;__netif_tx_lock (nq, cpu);
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH v2 net-next 06/14] net: fec: add fec_enet_rx_queue_xdp() for XDP path
Quoted 375 lines · Wei Fang
Currently, the processing of XDP path packets and protocol stack packets are both mixed in
fec_enet_rx_queue(), which makes the logic somewhat confusing and debugging more difficult. Furthermore, some logic is not needed by each other. For example, the kernel path does not need to callxdp_init_buff(), and XDP path does not supportswap_buffer(), etc. This prevents XDP from achieving its maximum performance. Therefore, XDP path packets processing has been separated fromfec_enet_rx_queue()by adding thefec_enet_rx_queue_xdp()function to optimize XDP path logic and improve XDP performance.The XDP performance on the iMX93 platform was compared before and after applying this patch. Detailed results are as follows and we can see the performance has been improved.
Env: i.MX93, packet size 64 bytes including FCS, only single core and RX BD ring are used to receive packets, flow-control is off.
Before the patch is applied:
xdp-bench tx eth0Summary 396,868 rx/s 0 err,drop/s Summary 396,024 rx/s 0 err,drop/sxdp-bench drop eth0
Summary 684,781 rx/s 0 err/s Summary 675,746 rx/s 0 err/sxdp-bench pass eth0
Summary 208,552 rx/s 0 err,drop/s Summary 208,654 rx/s 0 err,drop/sxdp-bench redirect eth0 eth0
eth0->eth0 311,210 rx/s 0 err,drop/s 311,208 xmit/s eth0->eth0 310,808 rx/s 0 err,drop/s 310,809 xmit/sAfter the patch is applied:
xdp-bench tx eth0Summary 409,975 rx/s 0 err,drop/s Summary 411,073 rx/s 0 err,drop/sxdp-bench drop eth0
Summary 700,681 rx/s 0 err/s Summary 698,102 rx/s 0 err/sxdp-bench pass eth0
Summary 211,356 rx/s 0 err,drop/s Summary 210,629 rx/s 0 err,drop/sxdp-bench redirect eth0 eth0
eth0->eth0 320,351 rx/s 0 err,drop/s 320,348 xmit/s eth0->eth0 318,988 rx/s 0 err,drop/s 318,988 xmit/sSigned-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 292 ++++++++++++++-------- 1 file changed, 188 insertions(+), 104 deletions(-)drivers/net/ethernet/freescale/fec_main.c +176
-85@@ -79,7 +79,7 @@ static void set_multicast_list(struct net_device *ndev);static void fec_enet_itr_coal_set (struct net_device *ndev);static int fec_enet_xdp_tx_xmit (struct fec_enet_private *fep,int cpu,struct xdp_buff *xdp, -u32 dma_sync_len); +u32 dma_sync_len,int queue);#define DRIVER_NAME "fec"@@ -1665,71 +1665,6 @@ static int fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq,return 0 ; } -static u32 -fec_enet_run_xdp (struct fec_enet_private *fep,struct bpf_prog *prog, -struct xdp_buff *xdp,struct fec_enet_priv_rx_q *rxq,int cpu) -{ -unsigned int sync, len = xdp->data_end - xdp->data; -u32 ret =FEC_ENET_XDP_PASS ; -struct page *page; -int err; -u32 act; - - act =bpf_prog_run_xdp (prog, xdp); - -/* Due xdp_adjust_tail and xdp_adjust_head: DMA sync for_device cover -* max len CPU touch -*/ - sync = xdp->data_end - xdp->data; - sync =max (sync, len); - -switch (act) { -case XDP_PASS : - rxq->stats[RX_XDP_PASS ]++; - ret =FEC_ENET_XDP_PASS ; -break ; - -case XDP_REDIRECT : - rxq->stats[RX_XDP_REDIRECT ]++; - err =xdp_do_redirect (fep->netdev, xdp, prog); -if (unlikely (err)) - goto xdp_err; - - ret =FEC_ENET_XDP_REDIR ; -break ; - -case XDP_TX : - rxq->stats[RX_XDP_TX ]++; - err =fec_enet_xdp_tx_xmit (fep, cpu, xdp, sync); -if (unlikely (err)) { - rxq->stats[RX_XDP_TX_ERRORS ]++; - goto xdp_err; - } - - ret =FEC_ENET_XDP_TX ; -break ; - -default : -bpf_warn_invalid_xdp_action (fep->netdev, prog, act); - fallthrough; - -case XDP_ABORTED : - fallthrough;/* handle aborts by dropping packet */ - -case XDP_DROP : - rxq->stats[RX_XDP_DROP ]++; -xdp_err: - ret =FEC_ENET_XDP_CONSUMED ; - page =virt_to_head_page (xdp->data); -page_pool_put_page (rxq->page_pool, page, sync, true); -if (act !=XDP_DROP ) -trace_xdp_exception (fep->netdev, prog, act); -break ; - } - -return ret; -} -static void fec_enet_rx_vlan (const struct net_device *ndev,struct sk_buff *skb) {if (ndev->features &NETIF_F_HW_VLAN_CTAG_RX ) {@@ -1842,19 +1777,14 @@ static struct sk_buff *fec_build_skb(struct fec_enet_private *fep,static int fec_enet_rx_queue (struct fec_enet_private *fep,u16 queue,int budget) { -u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift;struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue]; -struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);bool need_swap = fep->quirks &FEC_QUIRK_SWAP_FRAME ; -u32 ret, xdp_result =FEC_ENET_XDP_PASS ;struct net_device *ndev = fep->netdev;struct bufdesc *bdp = rxq->bd.cur;u32 sub_len =4 + fep->rx_shift; -int cpu =smp_processor_id ();int pkt_received =0 ;u16 status, pkt_len;struct sk_buff *skb; -struct xdp_buff xdp;struct page *page;dma_addr_t dma;int index;@@ -1870,8 +1800,6 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep,/* First, grab all of the stats for the incoming packet. * These get messed up if we get called due to a busy condition. */ -xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq); -while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) {if (pkt_received >= budget)@@ -1902,17 +1830,6 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep, DMA_FROM_DEVICE);prefetch (page_address (page)); -if (xdp_prog) { -xdp_buff_clear_frags_flag (&xdp); -/* subtract 16bit shift and FCS */ -xdp_prepare_buff (&xdp,page_address (page), - data_start, pkt_len - sub_len, false); - ret =fec_enet_run_xdp (fep, xdp_prog, &xdp, rxq, cpu); - xdp_result |= ret; -if (ret !=FEC_ENET_XDP_PASS ) - goto rx_processing_done; - } -if (unlikely (need_swap)) {u8 *data;@@ -1961,7 +1878,181 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep, } rxq->bd.cur = bdp; -if (xdp_result &FEC_ENET_XDP_REDIR ) +return pkt_received; +} + +static void fec_xdp_drop (struct fec_enet_priv_rx_q *rxq, +struct xdp_buff *xdp,u32 sync) +{ +struct page *page =virt_to_head_page (xdp->data); + +page_pool_put_page (rxq->page_pool, page, sync, true); +} + +static int +fec_enet_xdp_get_tx_queue (struct fec_enet_private *fep,int index) +{ +if (unlikely (index <0 )) +return 0 ; + +return (index % fep->num_tx_queues); +} + +static int fec_enet_rx_queue_xdp (struct fec_enet_private *fep,int queue, +int budget,struct bpf_prog *prog) +{ +u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift; +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue]; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = rxq->bd.cur; +u32 sub_len =4 + fep->rx_shift; +int cpu =smp_processor_id (); +int pkt_received =0 ; +struct sk_buff *skb; +u16 status, pkt_len; +struct xdp_buff xdp; +int tx_qid = queue; +struct page *page; +u32 xdp_res =0 ; +dma_addr_t dma; +int index, err; +u32 act, sync; + +#if defined(CONFIG_COLDFIRE ) && !defined(CONFIG_COLDFIRE_COHERENT_DMA ) +/* +* Hacky flush of all caches instead of using the DMA API for the TSO +* headers. +*/ +flush_cache_all (); +#endif + +if (unlikely (queue >= fep->num_tx_queues)) + tx_qid =fec_enet_xdp_get_tx_queue (fep, cpu); + +xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq); + +while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) { +if (pkt_received >= budget) +break ; + pkt_received++; + +writel (FEC_ENET_RXF_GET (queue), fep->hwp +FEC_IEVENT ); + +/* Check for errors. */ + status ^=BD_ENET_RX_LAST ; +if (unlikely (fec_rx_error_check (ndev, status))) + goto rx_processing_done; + +/* Process the incoming frame. */ + ndev->stats.rx_packets++; + pkt_len =fec16_to_cpu (bdp->cbd_datlen); + ndev->stats.rx_bytes += pkt_len - fep->rx_shift; + + index =fec_enet_get_bd_index (bdp, &rxq->bd); + page = rxq->rx_buf[index]; + dma =fec32_to_cpu (bdp->cbd_bufaddr); + +if (fec_enet_update_cbd (rxq, bdp, index)) { + ndev->stats.rx_dropped++; + goto rx_processing_done; + } + +dma_sync_single_for_cpu (&fep->pdev->dev, dma, pkt_len, +DMA_FROM_DEVICE ); +prefetch (page_address (page)); + +xdp_buff_clear_frags_flag (&xdp); +/* subtract 16bit shift and FCS */ + pkt_len -= sub_len; +xdp_prepare_buff (&xdp,page_address (page), data_start, + pkt_len, false); + + act =bpf_prog_run_xdp (prog, &xdp); +/* Due xdp_adjust_tail and xdp_adjust_head: DMA sync +* for_device cover max len CPU touch. +*/ + sync = xdp.data_end - xdp.data; + sync =max (sync, pkt_len); + +switch (act) { +case XDP_PASS : + rxq->stats[RX_XDP_PASS ]++; +/* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =fec_build_skb (fep, rxq, bdp, page, pkt_len); +if (!skb) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_PASS ); + }else { +napi_gro_receive (&fep->napi, skb); + } +break ; +case XDP_REDIRECT : + rxq->stats[RX_XDP_REDIRECT ]++; + err =xdp_do_redirect (ndev, &xdp, prog); +if (unlikely (err)) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_REDIRECT ); + }else { + xdp_res |=FEC_ENET_XDP_REDIR ; + } +break ; +case XDP_TX : + rxq->stats[RX_XDP_TX ]++; + err =fec_enet_xdp_tx_xmit (fep, cpu, &xdp, sync, tx_qid); +if (unlikely (err)) { + rxq->stats[RX_XDP_TX_ERRORS ]++; +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_TX ); + } +break ; +default : +bpf_warn_invalid_xdp_action (ndev, prog, act); + fallthrough; +case XDP_ABORTED : +/* handle aborts by dropping packet */ + fallthrough; +case XDP_DROP : + rxq->stats[RX_XDP_DROP ]++; +fec_xdp_drop (rxq, &xdp, sync); +break ; + } + +rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; + +if (fep->bufdesc_ex) { +struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; + + ebdp->cbd_esc =cpu_to_fec32 (BD_ENET_RX_INT ); + ebdp->cbd_prot =0 ; + ebdp->cbd_bdu =0 ; + } + +/* Make sure the updates to rest of the descriptor are +* performed before transferring ownership. +*/ +dma_wmb (); + bdp->cbd_sc =cpu_to_fec16 (status); + +/* Update BD pointer to next entry */ + bdp =fec_enet_get_nextdesc (bdp, &rxq->bd); + +/* Doing this here will keep the FEC running while we process +* incoming frames. On a heavily loaded network, we should be +* able to keep up at the expense of system resources. +*/ +writel (0 , rxq->bd.reg_desc_active); + } + + rxq->bd.cur = bdp; + +if (xdp_res &FEC_ENET_XDP_REDIR )xdp_do_flush ();return pkt_received;@@ -1970,11 +2061,17 @@ static int fec_enet_rx_queue(struct fec_enet_private *fep,static int fec_enet_rx (struct net_device *ndev,int budget) {struct fec_enet_private *fep =netdev_priv (ndev);
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_rx_queue(struct fec_enet_private *fep, · line 2071
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +5
-2+struct bpf_prog *prog =READ_ONCE (fep->xdp_prog);int i, done =0 ;/* Make sure that AVB queues are processed first. */ -for (i = fep->num_rx_queues -1 ; i >=0 ; i--) - done +=fec_enet_rx_queue (fep, i, budget - done); +for (i = fep->num_rx_queues -1 ; i >=0 ; i--) { +if (prog) + done +=fec_enet_rx_queue_xdp (fep, i, budget - done, + prog);
Patch still is hard to review. It may be simpe if
1. create new patch cp fec_enet_rx_queue() to fec_enet_rx_queue_xdp().
2. the change may small if base on 1.
Quoted 23 lines
drivers/net/ethernet/freescale/fec_main.c +3
-9+else + done +=fec_enet_rx_queue (fep, i, budget - done); + }return done; }@@ -3854,15 +3951,6 @@ static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf) } } -static int -fec_enet_xdp_get_tx_queue (struct fec_enet_private *fep,int index) -{ -if (unlikely (index <0 )) -return 0 ; - -return (index % fep->num_tx_queues); -} - static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, struct fec_enet_priv_tx_q *txq, void *frame, u32 dma_sync_len,
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, · line 4047
Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +1
-1@@ -3956,15 +4044,11 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep,static int fec_enet_xdp_tx_xmit (struct fec_enet_private *fep,int cpu,struct xdp_buff *xdp, -u32 dma_sync_len) +u32 dma_sync_len,int queue)
you can split it new patch, just add queue id at fec_enet_xdp_tx_xmit().
Frank
Quoted 17 lines
drivers/net/ethernet/freescale/fec_main.c +3
-8{ -struct fec_enet_priv_tx_q *txq; -struct netdev_queue *nq; -int queue, ret; - - queue =fec_enet_xdp_get_tx_queue (fep, cpu); - txq = fep->tx_queue[queue]; - nq =netdev_get_tx_queue (fep->netdev, queue); +struct netdev_queue *nq =netdev_get_tx_queue (fep->netdev, queue); +struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue]; +int ret;__netif_tx_lock (nq, cpu); --2.34.1
Wei Fang
maintainerRE: [PATCH v2 net-next 06/14] net: fec: add fec_enet_rx_queue_xdp() for XDP path
Quoted 167 lines
Quoted 11 lines
drivers/net/ethernet/freescale/fec_main.c +11
-0+static int fec_enet_rx_queue_xdp (struct fec_enet_private *fep,int queue, +int budget,struct bpf_prog *prog) +{ +u32 data_start =FEC_ENET_XDP_HEADROOM + fep->rx_shift; +struct fec_enet_priv_rx_q *rxq = fep->rx_queue[queue]; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = rxq->bd.cur; +u32 sub_len =4 + fep->rx_shift; +int cpu =smp_processor_id (); +int pkt_received =0 ; +struct sk_buff *skb;drivers/net/ethernet/freescale/fec_main.c static int fec_enet_rx_queue(struct fec_enet_private *fep,
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10
-0+u16 status, pkt_len; +struct xdp_buff xdp; +int tx_qid = queue; +struct page *page; +u32 xdp_res =0 ; +dma_addr_t dma; +int index, err; +u32 act, sync; + +#if defined(CONFIG_COLDFIRE )&& !defined(CONFIG_COLDFIRE_COHERENT_DMA)
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_rx_queue(struct
Quoted 138 lines
drivers/net/ethernet/freescale/fec_main.c +134
-0+/* +* Hacky flush of all caches instead of using the DMA API for the TSO +* headers. +*/ +flush_cache_all (); +#endif + +if (unlikely (queue >= fep->num_tx_queues)) + tx_qid =fec_enet_xdp_get_tx_queue (fep, cpu); + +xdp_init_buff (&xdp,PAGE_SIZE << fep->pagepool_order, &rxq->xdp_rxq); + +while (!((status =fec16_to_cpu (bdp->cbd_sc)) &BD_ENET_RX_EMPTY )) { +if (pkt_received >= budget) +break ; + pkt_received++; + +writel (FEC_ENET_RXF_GET (queue), fep->hwp +FEC_IEVENT ); + +/* Check for errors. */ + status ^=BD_ENET_RX_LAST ; +if (unlikely (fec_rx_error_check (ndev, status))) + goto rx_processing_done; + +/* Process the incoming frame. */ + ndev->stats.rx_packets++; + pkt_len =fec16_to_cpu (bdp->cbd_datlen); + ndev->stats.rx_bytes += pkt_len - fep->rx_shift; + + index =fec_enet_get_bd_index (bdp, &rxq->bd); + page = rxq->rx_buf[index]; + dma =fec32_to_cpu (bdp->cbd_bufaddr); + +if (fec_enet_update_cbd (rxq, bdp, index)) { + ndev->stats.rx_dropped++; + goto rx_processing_done; + } + +dma_sync_single_for_cpu (&fep->pdev->dev, dma, pkt_len, +DMA_FROM_DEVICE ); +prefetch (page_address (page)); + +xdp_buff_clear_frags_flag (&xdp); +/* subtract 16bit shift and FCS */ + pkt_len -= sub_len; +xdp_prepare_buff (&xdp,page_address (page), data_start, + pkt_len, false); + + act =bpf_prog_run_xdp (prog, &xdp); +/* Due xdp_adjust_tail and xdp_adjust_head: DMA sync +* for_device cover max len CPU touch. +*/ + sync = xdp.data_end - xdp.data; + sync =max (sync, pkt_len); + +switch (act) { +case XDP_PASS : + rxq->stats[RX_XDP_PASS ]++; +/* The packet length includes FCS, but we don't want to +* include that when passing upstream as it messes up +* bridging applications. +*/ + skb =fec_build_skb (fep, rxq, bdp, page, pkt_len); +if (!skb) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_PASS ); + }else { +napi_gro_receive (&fep->napi, skb); + } +break ; +case XDP_REDIRECT : + rxq->stats[RX_XDP_REDIRECT ]++; + err =xdp_do_redirect (ndev, &xdp, prog); +if (unlikely (err)) { +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_REDIRECT ); + }else { + xdp_res |=FEC_ENET_XDP_REDIR ; + } +break ; +case XDP_TX : + rxq->stats[RX_XDP_TX ]++; + err =fec_enet_xdp_tx_xmit (fep, cpu, &xdp, sync, tx_qid); +if (unlikely (err)) { + rxq->stats[RX_XDP_TX_ERRORS ]++; +fec_xdp_drop (rxq, &xdp, sync); +trace_xdp_exception (ndev, prog,XDP_TX ); + } +break ; +default : +bpf_warn_invalid_xdp_action (ndev, prog, act); + fallthrough; +case XDP_ABORTED : +/* handle aborts by dropping packet */ + fallthrough; +case XDP_DROP : + rxq->stats[RX_XDP_DROP ]++; +fec_xdp_drop (rxq, &xdp, sync); +break ; + } + +rx_processing_done: +/* Clear the status flags for this buffer */ + status &= ~BD_ENET_RX_STATS ; +/* Mark the buffer empty */ + status |=BD_ENET_RX_EMPTY ; + +if (fep->bufdesc_ex) { +struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; + + ebdp->cbd_esc =cpu_to_fec32 (BD_ENET_RX_INT ); + ebdp->cbd_prot =0 ; + ebdp->cbd_bdu =0 ; + } + +/* Make sure the updates to rest of the descriptor are +* performed before transferring ownership. +*/ +dma_wmb (); + bdp->cbd_sc =cpu_to_fec16 (status); + +/* Update BD pointer to next entry */ + bdp =fec_enet_get_nextdesc (bdp, &rxq->bd); + +/* Doing this here will keep the FEC running while we process +* incoming frames. On a heavily loaded network, we should be +* able to keep up at the expense of system resources. +*/ +writel (0 , rxq->bd.reg_desc_active); + } + + rxq->bd.cur = bdp; + +if (xdp_res &FEC_ENET_XDP_REDIR )xdp_do_flush ();return pkt_received;@@ -1970,11 +2061,17 @@ static int fec_enet_rx_queue(struct
fec_enet_private*fep,Quoted 6 lines
drivers/net/ethernet/freescale/fec_main.c +1
-0static int fec_enet_rx (struct net_device *ndev,int budget) {struct fec_enet_private *fep =netdev_priv (ndev); +struct bpf_prog *prog =READ_ONCE (fep->xdp_prog);int i, done =0 ;
Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_rx_queue(struct fec_enet_private *fep, · line 2071
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +4
-2/* Make sure that AVB queues are processed first. */ -for (i = fep->num_rx_queues -1 ; i >=0 ; i--) - done +=fec_enet_rx_queue (fep, i, budget - done); +for (i = fep->num_rx_queues -1 ; i >=0 ; i--) { +if (prog) + done +=fec_enet_rx_queue_xdp (fep, i, budget - done, + prog);Patch still is hard to review. It may be simpe if
1. create new patch cpfec_enet_rx_queue()tofec_enet_rx_queue_xdp().
2. the change may small if base on 1.
fec_enet_rx_queue_xdp() is basically the same as fec_enet_rx_queue(), the biggest difference is probably the removal of the fec_enet_run_xdp() function and the relocation of its code to fec_enet_rx_queue_xdp().
The current patch set already has 14 patches, which is close to the 15-patch limit. I would like to leave the last new patch for the comment below, because it does indeed differ somewhat from the previous logic.
Quoted 26 lines
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_bpf(struct net_device *dev,
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0+else + done +=fec_enet_rx_queue (fep, i, budget - done); + }return done; }@@ -3854,15 +3951,6 @@ static int fec_enet_bpf(struct net_device *dev,struct
netdev_bpf*bpf)drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct
Quoted 16 lines
drivers/net/ethernet/freescale/fec_main.c +0
-9} } -static int -fec_enet_xdp_get_tx_queue (struct fec_enet_private *fep,int index) -{ -if (unlikely (index <0 )) -return 0 ; - -return (index % fep->num_tx_queues); -} - static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, struct fec_enet_priv_tx_q *txq, void *frame, u32 dma_sync_len,@@ -3956,15 +4044,11 @@ static int fec_enet_txq_xmit_frame(struct
fec_enet_private*fep,Quoted 1 line
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, · line 4047
Quoted 4 lines
static int fec_enet_xdp_tx_xmit(struct
fec_enet_private*fep,drivers/net/ethernet/freescale/fec_main.c +1
-1int cpu, struct xdp_buff *xdp, - u32 dma_sync_len) + u32 dma_sync_len, int queue)you can split it new patch, just add queue id at
fec_enet_xdp_tx_xmit().
Yes, this is a new change to the previous logic, I will add a new patch.
Wei Fang
maintainerPATCH v2 7/14 net: fec: transmit XDP frames in bulk
In reply to Wei FangCurrently, the driver writes the ENET_TDAR register for every XDP frame to trigger transmit start. Frequent MMIO writes consume more CPU cycles and may reduce XDP TX performance, so transmit XDP frames in bulk.
--- drivers/net/ethernet/freescale/fec_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +9 -3
@@ -2006,6 +2006,8 @@ static int fec_enet_rx_queue_xdp(struct fec_enet_private *fep, int queue, rxq->stats[RX_XDP_TX_ERRORS ]++;fec_xdp_drop (rxq, &xdp, sync);trace_xdp_exception (ndev, prog,XDP_TX ); + }else { + xdp_res |=FEC_ENET_XDP_TX ; }break ;default :
@@ -2055,6 +2057,10 @@ static int fec_enet_rx_queue_xdp(struct fec_enet_private *fep, int queue,if (xdp_res &FEC_ENET_XDP_REDIR )xdp_do_flush (); +if (xdp_res &FEC_ENET_XDP_TX ) +/* Trigger transmission start */ +fec_txq_trigger_xmit (fep, fep->tx_queue[tx_qid]); +return pkt_received; }
@@ -4036,9 +4042,6 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, txq->bd.cur = bdp; -/* Trigger transmission start */ -fec_txq_trigger_xmit (fep, txq); -return 0 ; }
@@ -4088,6 +4091,9 @@ static int fec_enet_xdp_xmit(struct net_device *dev, sent_frames++; } +if (sent_frames) +fec_txq_trigger_xmit (fep, txq); +__netif_tx_unlock (nq);return sent_frames;
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 07/14] net: fec: transmit XDP frames in bulk
Quoted 6 lines · Wei Fang
Currently, the driver writes the
ENET_TDARregister for every XDP frame to trigger transmit start. Frequent MMIO writes consume more CPU cycles and may reduce XDP TX performance, so transmit XDP frames in bulk.Signed-off-by Wei Fang <[email protected]>---
Quoted 50 lines
drivers/net/ethernet/freescale/fec_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/net/ethernet/freescale/fec_main.c +9
-4@@ -2006,6 +2006,8 @@ static int fec_enet_rx_queue_xdp(struct fec_enet_private *fep, int queue, rxq->stats[RX_XDP_TX_ERRORS ]++;fec_xdp_drop (rxq, &xdp, sync);trace_xdp_exception (ndev, prog,XDP_TX ); + }else { + xdp_res |=FEC_ENET_XDP_TX ; }break ;default :@@ -2055,6 +2057,10 @@ static int fec_enet_rx_queue_xdp(struct fec_enet_private *fep, int queue,if (xdp_res &FEC_ENET_XDP_REDIR )xdp_do_flush (); +if (xdp_res &FEC_ENET_XDP_TX ) +/* Trigger transmission start */ +fec_txq_trigger_xmit (fep, fep->tx_queue[tx_qid]); +return pkt_received; }@@ -4036,9 +4042,6 @@ static int fec_enet_txq_xmit_frame(struct fec_enet_private *fep, txq->bd.cur = bdp; -/* Trigger transmission start */ -fec_txq_trigger_xmit (fep, txq); -return 0 ; }@@ -4088,6 +4091,9 @@ static int fec_enet_xdp_xmit(struct net_device *dev, sent_frames++; } +if (sent_frames) +fec_txq_trigger_xmit (fep, txq); +__netif_tx_unlock (nq);return sent_frames; --2.34.1
Wei Fang
maintainerPATCH v2 8/14 net: fec: remove unnecessary NULL pointer check when clearing TX BD ring
In reply to Wei FangThe tx_buf pointer will not NULL when its type is FEC_TXBUF_T_XDP_NDO or FEC_TXBUF_T_XDP_TX. If the type is FEC_TXBUF_T_SKB, dev_kfree_skb_any() will do NULL pointer check. So it is unnecessary to do NULL pointer check in fec_enet_bd_init() and fec_enet_tx_queue().
--- drivers/net/ethernet/freescale/fec_main.c | 35 ++++++++--------------- 1 file changed, 12 insertions(+), 23 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +12 -23
@@ -1032,24 +1032,19 @@ static void fec_enet_bd_init(struct net_device *dev)fec32_to_cpu (bdp->cbd_bufaddr),fec16_to_cpu (bdp->cbd_datlen), DMA_TO_DEVICE); -if (txq->tx_buf[i].buf_p) -dev_kfree_skb_any (txq->tx_buf[i].buf_p); +dev_kfree_skb_any (txq->tx_buf[i].buf_p); }else if (txq->tx_buf[i].type ==FEC_TXBUF_T_XDP_NDO ) { -if (bdp->cbd_bufaddr) -dma_unmap_single (&fep->pdev->dev, -fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); +dma_unmap_single (&fep->pdev->dev, +fec32_to_cpu (bdp->cbd_bufaddr), +fec16_to_cpu (bdp->cbd_datlen), +DMA_TO_DEVICE ); -if (txq->tx_buf[i].buf_p) -xdp_return_frame (txq->tx_buf[i].buf_p); +xdp_return_frame (txq->tx_buf[i].buf_p); }else {struct page *page = txq->tx_buf[i].buf_p; -if (page) -page_pool_put_page (pp_page_to_nmdesc (page)->pp, - page,0 , - false); +page_pool_put_page (pp_page_to_nmdesc (page)->pp, + page,0 , false); } txq->tx_buf[i].buf_p =NULL ;
@@ -1537,21 +1532,15 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) { xdpf = txq->tx_buf[index].buf_p; -if (bdp->cbd_bufaddr) -dma_unmap_single (&fep->pdev->dev, -fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); +dma_unmap_single (&fep->pdev->dev, +fec32_to_cpu (bdp->cbd_bufaddr), +fec16_to_cpu (bdp->cbd_datlen), +DMA_TO_DEVICE ); }else { page = txq->tx_buf[index].buf_p; } bdp->cbd_bufaddr =cpu_to_fec32 (0 ); -if (unlikely (!txq->tx_buf[index].buf_p)) { - txq->tx_buf[index].type =FEC_TXBUF_T_SKB ; - goto tx_buf_done; - } - frame_len =fec16_to_cpu (bdp->cbd_datlen); }
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 08/14] net: fec: remove unnecessary NULL pointer check when clearing TX BD ring
Quoted 7 lines · Wei Fang
The
tx_bufpointer will not NULL when its type isFEC_TXBUF_T_XDP_NDOorFEC_TXBUF_T_XDP_TX. If the type isFEC_TXBUF_T_SKB,dev_kfree_skb_any()will do NULL pointer check. So it is unnecessary to do NULL pointer check infec_enet_bd_init()andfec_enet_tx_queue().Signed-off-by Wei Fang <[email protected]>---
Quoted 69 lines
drivers/net/ethernet/freescale/fec_main.c | 35 ++++++++--------------- 1 file changed, 12 insertions(+), 23 deletions(-)drivers/net/ethernet/freescale/fec_main.c +12
-24@@ -1032,24 +1032,19 @@ static void fec_enet_bd_init(struct net_device *dev)fec32_to_cpu (bdp->cbd_bufaddr),fec16_to_cpu (bdp->cbd_datlen), DMA_TO_DEVICE); -if (txq->tx_buf[i].buf_p) -dev_kfree_skb_any (txq->tx_buf[i].buf_p); +dev_kfree_skb_any (txq->tx_buf[i].buf_p); }else if (txq->tx_buf[i].type ==FEC_TXBUF_T_XDP_NDO ) { -if (bdp->cbd_bufaddr) -dma_unmap_single (&fep->pdev->dev, -fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); +dma_unmap_single (&fep->pdev->dev, +fec32_to_cpu (bdp->cbd_bufaddr), +fec16_to_cpu (bdp->cbd_datlen), +DMA_TO_DEVICE ); -if (txq->tx_buf[i].buf_p) -xdp_return_frame (txq->tx_buf[i].buf_p); +xdp_return_frame (txq->tx_buf[i].buf_p); }else {struct page *page = txq->tx_buf[i].buf_p; -if (page) -page_pool_put_page (pp_page_to_nmdesc (page)->pp, - page,0 , - false); +page_pool_put_page (pp_page_to_nmdesc (page)->pp, + page,0 , false); } txq->tx_buf[i].buf_p =NULL ;@@ -1537,21 +1532,15 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) { xdpf = txq->tx_buf[index].buf_p; -if (bdp->cbd_bufaddr) -dma_unmap_single (&fep->pdev->dev, -fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); +dma_unmap_single (&fep->pdev->dev, +fec32_to_cpu (bdp->cbd_bufaddr), +fec16_to_cpu (bdp->cbd_datlen), +DMA_TO_DEVICE ); }else { page = txq->tx_buf[index].buf_p; } bdp->cbd_bufaddr =cpu_to_fec32 (0 ); -if (unlikely (!txq->tx_buf[index].buf_p)) { - txq->tx_buf[index].type =FEC_TXBUF_T_SKB ; - goto tx_buf_done; - } - frame_len =fec16_to_cpu (bdp->cbd_datlen); } --2.34.1
Wei Fang
maintainerPATCH v2 9/14 net: fec: use switch statement to check the type of tx_buf
In reply to Wei FangThe tx_buf has three types: FEC_TXBUF_T_SKB, FEC_TXBUF_T_XDP_NDO and FEC_TXBUF_T_XDP_TX. Currently, the driver uses 'if...else...' statements to check the type and perform the corresponding processing. This is very detrimental to future expansion. To support AF_XDP zero-copy mode, two new types will be added in the future, continuing to use 'if...else...' would be a very bad coding style. So the 'if...else...' statements in the current driver are replaced with switch statements.
--- drivers/net/ethernet/freescale/fec_main.c | 136 ++++++++++++---------- 1 file changed, 74 insertions(+), 62 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +74 -62
@@ -1023,9 +1023,13 @@ static void fec_enet_bd_init(struct net_device *dev) txq->bd.cur = bdp;for (i =0 ; i < txq->bd.ring_size; i++) { +struct page *page; +/* Initialize the BD for every fragment in the page. */ bdp->cbd_sc =cpu_to_fec16 (0 ); -if (txq->tx_buf[i].type ==FEC_TXBUF_T_SKB ) { + +switch (txq->tx_buf[i].type) { +case FEC_TXBUF_T_SKB :if (bdp->cbd_bufaddr && !IS_TSO_HEADER (txq,fec32_to_cpu (bdp->cbd_bufaddr))) dma_unmap_single(&fep->pdev->dev,
@@ -1033,19 +1037,22 @@ static void fec_enet_bd_init(struct net_device *dev)fec16_to_cpu (bdp->cbd_datlen), DMA_TO_DEVICE);dev_kfree_skb_any (txq->tx_buf[i].buf_p); - }else if (txq->tx_buf[i].type ==FEC_TXBUF_T_XDP_NDO ) { +break ; +case FEC_TXBUF_T_XDP_NDO :dma_unmap_single (&fep->pdev->dev,fec32_to_cpu (bdp->cbd_bufaddr),fec16_to_cpu (bdp->cbd_datlen),DMA_TO_DEVICE ); -xdp_return_frame (txq->tx_buf[i].buf_p); - }else { -struct page *page = txq->tx_buf[i].buf_p; - +break ; +case FEC_TXBUF_T_XDP_TX : + page = txq->tx_buf[i].buf_p;page_pool_put_page (pp_page_to_nmdesc (page)->pp, page,0 , false); - } +break ; +default : +break ; + }; txq->tx_buf[i].buf_p =NULL ;/* restore default tx buffer type: FEC_TXBUF_T_SKB */
@@ -1509,39 +1516,69 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)break ; index =fec_enet_get_bd_index (bdp, &txq->bd); + frame_len =fec16_to_cpu (bdp->cbd_datlen); -if (txq->tx_buf[index].type ==FEC_TXBUF_T_SKB ) { - skb = txq->tx_buf[index].buf_p; +switch (txq->tx_buf[index].type) { +case FEC_TXBUF_T_SKB :if (bdp->cbd_bufaddr && !IS_TSO_HEADER (txq,fec32_to_cpu (bdp->cbd_bufaddr)))dma_unmap_single (&fep->pdev->dev,fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); + frame_len,DMA_TO_DEVICE ); + bdp->cbd_bufaddr =cpu_to_fec32 (0 ); + skb = txq->tx_buf[index].buf_p;if (!skb) goto tx_buf_done; - }else { + + frame_len = skb->len; + +/* NOTE: SKBTX_IN_PROGRESS being set does not imply it's we who +* are to time stamp the packet, so we still need to check time +* stamping enabled flag. +*/ +if (unlikely (skb_shinfo (skb)->tx_flags &SKBTX_IN_PROGRESS && + fep->hwts_tx_en) && fep->bufdesc_ex) { +struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; +struct skb_shared_hwtstamps shhwtstamps; + +fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), &shhwtstamps); +skb_tstamp_tx (skb, &shhwtstamps); + } + +/* Free the sk buffer associated with this last transmit */ +napi_consume_skb (skb, budget); +break ; +case FEC_TXBUF_T_XDP_NDO :/* Tx processing cannot call any XDP (or page pool) APIs if * the "budget" is 0. Because NAPI is called with budget of * 0 (such as netpoll) indicates we may be in an IRQ context, * however, we can't use the page pool from IRQ context. */ if (unlikely (!budget)) -break ; + goto out; -if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) { - xdpf = txq->tx_buf[index].buf_p; -dma_unmap_single (&fep->pdev->dev, -fec32_to_cpu (bdp->cbd_bufaddr), -fec16_to_cpu (bdp->cbd_datlen), -DMA_TO_DEVICE ); - }else { - page = txq->tx_buf[index].buf_p; - } + xdpf = txq->tx_buf[index].buf_p; +dma_unmap_single (&fep->pdev->dev, +fec32_to_cpu (bdp->cbd_bufaddr), + frame_len,DMA_TO_DEVICE ); + bdp->cbd_bufaddr =cpu_to_fec32 (0 ); +xdp_return_frame_rx_napi (xdpf); +break ; +case FEC_TXBUF_T_XDP_TX : +if (unlikely (!budget)) + goto out; bdp->cbd_bufaddr =cpu_to_fec32 (0 ); - frame_len =fec16_to_cpu (bdp->cbd_datlen); + page = txq->tx_buf[index].buf_p; +/* The dma_sync_size = 0 as XDP_TX has already synced +* DMA for_device +*/ +page_pool_put_page (pp_page_to_nmdesc (page)->pp, page, +0 , true); +break ; +default : +break ; }/* Check for errors. */
@@ -1561,11 +1598,7 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget) ndev->stats.tx_carrier_errors++; }else { ndev->stats.tx_packets++; - -if (txq->tx_buf[index].type ==FEC_TXBUF_T_SKB ) - ndev->stats.tx_bytes += skb->len; -else - ndev->stats.tx_bytes += frame_len; + ndev->stats.tx_bytes += frame_len; }/* Deferred means some collisions occurred during transmit,
@@ -1574,30 +1607,6 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (status &BD_ENET_TX_DEF ) ndev->stats.collisions++; -if (txq->tx_buf[index].type ==FEC_TXBUF_T_SKB ) { -/* NOTE: SKBTX_IN_PROGRESS being set does not imply it's we who -* are to time stamp the packet, so we still need to check time -* stamping enabled flag. -*/ -if (unlikely (skb_shinfo (skb)->tx_flags &SKBTX_IN_PROGRESS && - fep->hwts_tx_en) && fep->bufdesc_ex) { -struct skb_shared_hwtstamps shhwtstamps; -struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; - -fec_enet_hwtstamp (fep,fec32_to_cpu (ebdp->ts), &shhwtstamps); -skb_tstamp_tx (skb, &shhwtstamps); - } - -/* Free the sk buffer associated with this last transmit */ -napi_consume_skb (skb, budget); - }else if (txq->tx_buf[index].type ==FEC_TXBUF_T_XDP_NDO ) { -xdp_return_frame_rx_napi (xdpf); - }else {/* recycle pages of XDP_TX frames */ -/* The dma_sync_size = 0 as XDP_TX has already synced DMA for_device */ -page_pool_put_page (pp_page_to_nmdesc (page)->pp, page, -0 , true); - } - txq->tx_buf[index].buf_p =NULL ;/* restore default tx buffer type: FEC_TXBUF_T_SKB */ txq->tx_buf[index].type =FEC_TXBUF_T_SKB ;
@@ -1621,6 +1630,8 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget) } } +out: +/* ERR006358: Keep the transmitter going */ if (bdp != txq->bd.cur &&readl (txq->bd.reg_desc_active) ==0 )
@@ -3414,6 +3425,7 @@ static void fec_enet_free_buffers(struct net_device *ndev)unsigned int i;struct fec_enet_priv_tx_q *txq;struct fec_enet_priv_rx_q *rxq; +struct page *page;unsigned int q;for (q =0 ; q < fep->num_rx_queues; q++) {
@@ -3437,20 +3449,20 @@ static void fec_enet_free_buffers(struct net_device *ndev)kfree (txq->tx_bounce[i]); txq->tx_bounce[i] =NULL ; -if (!txq->tx_buf[i].buf_p) { - txq->tx_buf[i].type =FEC_TXBUF_T_SKB ; -continue ; - } - -if (txq->tx_buf[i].type ==FEC_TXBUF_T_SKB ) { +switch (txq->tx_buf[i].type) { +case FEC_TXBUF_T_SKB :dev_kfree_skb (txq->tx_buf[i].buf_p); - }else if (txq->tx_buf[i].type ==FEC_TXBUF_T_XDP_NDO ) { +break ; +case FEC_TXBUF_T_XDP_NDO :xdp_return_frame (txq->tx_buf[i].buf_p); - }else { -struct page *page = txq->tx_buf[i].buf_p; - +break ; +case FEC_TXBUF_T_XDP_TX : + page = txq->tx_buf[i].buf_p;page_pool_put_page (pp_page_to_nmdesc (page)->pp, page,0 , false); +break ; +default : +break ; } txq->tx_buf[i].buf_p =NULL ;
Signature · 1 line
2.34.1
Wei Fang
maintainerPATCH v2 10/14 net: fec: remove the size parameter from fec_enet_create_page_pool()
In reply to Wei FangSince the rxq is one of the parameters of fec_enet_create_page_pool(), so we can get the ring size from rxq->bd.ring_size, so it is safe to remove the size parameter from fec_enet_create_page_pool().
--- drivers/net/ethernet/freescale/fec_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +3 -3
@@ -467,13 +467,13 @@ fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)static int fec_enet_create_page_pool (struct fec_enet_private *fep, -struct fec_enet_priv_rx_q *rxq,int size) +struct fec_enet_priv_rx_q *rxq) {struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);struct page_pool_params pp_params = { .order = fep->pagepool_order, .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , - .pool_size = size, + .pool_size = rxq->bd.ring_size, .nid =dev_to_node (&fep->pdev->dev), .dev = &fep->pdev->dev, .dma_dir = xdp_prog ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ,
@@ -3552,7 +3552,7 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) rxq = fep->rx_queue[queue]; bdp = rxq->bd.base; - err =fec_enet_create_page_pool (fep, rxq, rxq->bd.ring_size); + err =fec_enet_create_page_pool (fep, rxq);if (err <0 ) {netdev_err (ndev,"%s failed queue %d (%d)\n" , __func__, queue, err);return err;
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 10/14] net: fec: remove the size parameter from fec_enet_create_page_pool()
Quoted 3 lines · Wei Fang
Since the rxq is one of the parameters of
fec_enet_create_page_pool(), so we can get the ring size fromrxq->bd.ring_size, so it is safe to remove the size parameter fromfec_enet_create_page_pool().
Remove the size parameter from fec_enet_create_page_pool(), since rxq->bd.ring_size already contains this information.
Quoted 38 lines
Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/ethernet/freescale/fec_main.c +3
-4@@ -467,13 +467,13 @@ fec_enet_clear_csum(struct sk_buff *skb, struct net_device *ndev)static int fec_enet_create_page_pool (struct fec_enet_private *fep, -struct fec_enet_priv_rx_q *rxq,int size) +struct fec_enet_priv_rx_q *rxq) {struct bpf_prog *xdp_prog =READ_ONCE (fep->xdp_prog);struct page_pool_params pp_params = { .order = fep->pagepool_order, .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , - .pool_size = size, + .pool_size = rxq->bd.ring_size, .nid =dev_to_node (&fep->pdev->dev), .dev = &fep->pdev->dev, .dma_dir = xdp_prog ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ,@@ -3552,7 +3552,7 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) rxq = fep->rx_queue[queue]; bdp = rxq->bd.base; - err =fec_enet_create_page_pool (fep, rxq, rxq->bd.ring_size); + err =fec_enet_create_page_pool (fep, rxq);if (err <0 ) {netdev_err (ndev,"%s failed queue %d (%d)\n" , __func__, queue, err);return err; --2.34.1
Wei Fang
maintainerPATCH v2 11/14 net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()
In reply to Wei FangExtract fec_xdp_rxq_info_reg() from fec_enet_create_page_pool() and move it out of fec_enet_create_page_pool(), so that it can be reused in the subsequent patches to support XDP zero copy mode.
--- drivers/net/ethernet/freescale/fec_main.c | 58 ++++++++++++++++------- 1 file changed, 40 insertions(+), 18 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +40 -18
@@ -489,23 +489,7 @@ fec_enet_create_page_pool(struct fec_enet_private *fep,return err; } - err =xdp_rxq_info_reg (&rxq->xdp_rxq, fep->netdev, rxq->id,0 ); -if (err <0 ) - goto err_free_pp; - - err =xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , - rxq->page_pool); -if (err) - goto err_unregister_rxq; -return 0 ; - -err_unregister_rxq: -xdp_rxq_info_unreg (&rxq->xdp_rxq); -err_free_pp: -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; -return err; } static void fec_txq_trigger_xmit(struct fec_enet_private *fep,
@@ -3419,6 +3403,38 @@ static const struct ethtool_ops fec_enet_ethtool_ops = { .self_test = net_selftest, }; +static int fec_xdp_rxq_info_reg (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) +{ +struct net_device *ndev = fep->netdev; +int err; + + err =xdp_rxq_info_reg (&rxq->xdp_rxq, ndev, rxq->id,0 ); +if (err) { +netdev_err (ndev,"Failed to register xdp rxq info\n" ); +return err; + } + + err =xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , + rxq->page_pool); +if (err) { +netdev_err (ndev,"Failed to register XDP mem model\n" ); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + +return err; + } + +return 0 ; +} + +static void fec_xdp_rxq_info_unreg (struct fec_enet_priv_rx_q *rxq) +{ +if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) { +xdp_rxq_info_unreg_mem_model (&rxq->xdp_rxq); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + } +} +static void fec_enet_free_buffers (struct net_device *ndev) {struct fec_enet_private *fep =netdev_priv (ndev);
@@ -3430,6 +3446,9 @@ static void fec_enet_free_buffers(struct net_device *ndev)for (q =0 ; q < fep->num_rx_queues; q++) { rxq = fep->rx_queue[q]; + +fec_xdp_rxq_info_unreg (rxq); +for (i =0 ; i < rxq->bd.ring_size; i++)page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], false);
@@ -3437,8 +3456,6 @@ static void fec_enet_free_buffers(struct net_device *ndev)for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; -if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) -xdp_rxq_info_unreg (&rxq->xdp_rxq);page_pool_destroy (rxq->page_pool); rxq->page_pool =NULL ; }
@@ -3593,6 +3610,11 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)/* Set the last buffer to wrap. */ bdp =fec_enet_get_prevdesc (bdp, &rxq->bd); bdp->cbd_sc |=cpu_to_fec16 (BD_ENET_RX_WRAP ); + + err =fec_xdp_rxq_info_reg (fep, rxq); +if (err) + goto err_alloc; +return 0 ; err_alloc:
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH v2 net-next 11/14] net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()
Quoted 24 lines · Wei Fang
Extract
fec_xdp_rxq_info_reg()fromfec_enet_create_page_pool()and move it out offec_enet_create_page_pool(), so that it can be reused in the subsequent patches to support XDP zero copy mode.Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 58 ++++++++++++++++------- 1 file changed, 40 insertions(+), 18 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-7@@ -489,23 +489,7 @@ fec_enet_create_page_pool(struct fec_enet_private *fep,return err; } - err =xdp_rxq_info_reg (&rxq->xdp_rxq, fep->netdev, rxq->id,0 ); -if (err <0 ) - goto err_free_pp; - - err =xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , - rxq->page_pool); -if (err)
drivers/net/ethernet/freescale/fec_main.c fec_enet_create_page_pool(struct fec_enet_private *fep, · line 508
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +0
-9- goto err_unregister_rxq; -return 0 ; - -err_unregister_rxq: -xdp_rxq_info_unreg (&rxq->xdp_rxq); -err_free_pp: -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; -return err;
Noramlly this patch should put helper fec_xdp_rxq_info_reg() before fec_enet_create_page_pool(). then call fec_xdp_rxq_info_reg() here.
Quoted 53 lines
drivers/net/ethernet/freescale/fec_main.c +35
-0} static void fec_txq_trigger_xmit(struct fec_enet_private *fep,@@ -3419,6 +3403,38 @@ static const struct ethtool_ops fec_enet_ethtool_ops = { .self_test = net_selftest, }; +static int fec_xdp_rxq_info_reg (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) +{ +struct net_device *ndev = fep->netdev; +int err; + + err =xdp_rxq_info_reg (&rxq->xdp_rxq, ndev, rxq->id,0 ); +if (err) { +netdev_err (ndev,"Failed to register xdp rxq info\n" ); +return err; + } + + err =xdp_rxq_info_reg_mem_model (&rxq->xdp_rxq,MEM_TYPE_PAGE_POOL , + rxq->page_pool); +if (err) { +netdev_err (ndev,"Failed to register XDP mem model\n" ); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + +return err; + } + +return 0 ; +} + +static void fec_xdp_rxq_info_unreg (struct fec_enet_priv_rx_q *rxq) +{ +if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) { +xdp_rxq_info_unreg_mem_model (&rxq->xdp_rxq); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + } +} +static void fec_enet_free_buffers (struct net_device *ndev) {struct fec_enet_private *fep =netdev_priv (ndev);@@ -3430,6 +3446,9 @@ static void fec_enet_free_buffers(struct net_device *ndev)for (q =0 ; q < fep->num_rx_queues; q++) { rxq = fep->rx_queue[q]; + +fec_xdp_rxq_info_unreg (rxq); +for (i =0 ; i < rxq->bd.ring_size; i++)page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], false);
drivers/net/ethernet/freescale/fec_main.c static void fec_enet_free_buffers(struct net_device *ndev) · line 3441
Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +0
-2@@ -3437,8 +3456,6 @@ static void fec_enet_free_buffers(struct net_device *ndev)for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; -if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) -xdp_rxq_info_unreg (&rxq->xdp_rxq);
why put fec_xdp_rxq_info_unreg() here to do exactly replacement.
Frank
Quoted 18 lines
drivers/net/ethernet/freescale/fec_main.c +5
-1page_pool_destroy (rxq->page_pool); rxq->page_pool =NULL ; }@@ -3593,6 +3610,11 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)/* Set the last buffer to wrap. */ bdp =fec_enet_get_prevdesc (bdp, &rxq->bd); bdp->cbd_sc |=cpu_to_fec16 (BD_ENET_RX_WRAP ); + + err =fec_xdp_rxq_info_reg (fep, rxq); +if (err) + goto err_alloc; +return 0 ; err_alloc: --2.34.1
Wei Fang
maintainerRE: [PATCH v2 net-next 11/14] net: fec: move xdp_rxq_info* APIs out of fec_enet_create_page_pool()
Quoted 26 lines · Wei Fang
Review
Quoted 10 lines
Extract
fec_xdp_rxq_info_reg()fromfec_enet_create_page_pool()and move it out offec_enet_create_page_pool(), so that it can be reused in the subsequent patches to support XDP zero copy mode.Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 58 ++++++++++++++++------- 1 file changed, 40 insertions(+), 18 deletions(-)(quoted diff) +0
-0
b/drivers/net/ethernet/freescale/fec_main.cdrivers/net/ethernet/freescale/fec_main.c fec_enet_create_page_pool(struct
Quoted 4 lines
index
c1786ccf0443..a418f0153d43100644drivers/net/ethernet/freescale/fec_main.c +0
-0@@ -489,23 +489,7 @@ fec_enet_create_page_pool(struct
fec_enet_private*fep,drivers/net/ethernet/freescale/fec_main.c fec_enet_create_page_pool(struct fec_enet_private *fep,
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c +0
-5return err; } - err =xdp_rxq_info_reg (&rxq->xdp_rxq, fep->netdev, rxq->id,0 ); -if (err <0 ) - goto err_free_pp; - - err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq,
MEM_TYPE_PAGE_POOL,
Quoted 15 lines
drivers/net/ethernet/freescale/fec_main.c fec_enet_create_page_pool(struct fec_enet_private *fep, · line 508
Quoted 12 lines
drivers/net/ethernet/freescale/fec_main.c +0
-11- rxq->page_pool); -if (err) - goto err_unregister_rxq; -return 0 ; - -err_unregister_rxq: -xdp_rxq_info_unreg (&rxq->xdp_rxq); -err_free_pp: -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; -return err;Noramlly this patch should put helper
fec_xdp_rxq_info_reg()beforefec_enet_create_page_pool(). then callfec_xdp_rxq_info_reg()here.
The main purpose of this patch is to move the xdp-related logic out of fec_enet_create_page_pool(), so there is no need to use two patches to solve such a trivial matter.
Quoted 58 lines
drivers/net/ethernet/freescale/fec_main.c static const struct ethtool_ops
Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +0
-0} static void fec_txq_trigger_xmit(struct fec_enet_private *fep,@@ -3419,6 +3403,38 @@ static const struct ethtool_ops
fec_enet_ethtool_ops= {Quoted 6 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0.self_test = net_selftest, }; +static int fec_xdp_rxq_info_reg (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) +{drivers/net/ethernet/freescale/fec_main.c static const struct ethtool_ops fec_enet_ethtool_ops = {
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +10
-0+struct net_device *ndev = fep->netdev; +int err; + + err =xdp_rxq_info_reg (&rxq->xdp_rxq, ndev, rxq->id,0 ); +if (err) { +netdev_err (ndev,"Failed to register xdp rxq info\n" ); +return err; + } + + err = xdp_rxq_info_reg_mem_model(&rxq->xdp_rxq,
MEM_TYPE_PAGE_POOL,drivers/net/ethernet/freescale/fec_main.c static void fec_enet_free_buffers(struct net_device
Quoted 23 lines
drivers/net/ethernet/freescale/fec_main.c +19
-0+ rxq->page_pool); +if (err) { +netdev_err (ndev,"Failed to register XDP mem model\n" ); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + +return err; + } + +return 0 ; +} + +static void fec_xdp_rxq_info_unreg (struct fec_enet_priv_rx_q *rxq) +{ +if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) { +xdp_rxq_info_unreg_mem_model (&rxq->xdp_rxq); +xdp_rxq_info_unreg (&rxq->xdp_rxq); + } +} +static void fec_enet_free_buffers (struct net_device *ndev) {struct fec_enet_private *fep =netdev_priv (ndev);@@ -3430,6 +3446,9 @@ static void fec_enet_free_buffers(struct net_device*ndev)
drivers/net/ethernet/freescale/fec_main.c static void fec_enet_free_buffers(struct net_device
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +3
-0for (q =0 ; q < fep->num_rx_queues; q++) { rxq = fep->rx_queue[q]; + +fec_xdp_rxq_info_unreg (rxq); +for (i =0 ; i < rxq->bd.ring_size; i++)page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], false);@@ -3437,8 +3456,6 @@ static void fec_enet_free_buffers(struct net_device*ndev)
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c static void fec_enet_free_buffers(struct net_device *ndev) · line 3441
Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +0
-2for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; -if (xdp_rxq_info_is_reg (&rxq->xdp_rxq)) -xdp_rxq_info_unreg (&rxq->xdp_rxq);why put
fec_xdp_rxq_info_unreg()here to do exactly replacement.
It's fine to put it in the original position, the only reason is that I want the order to be reversed from that in fec_enet_alloc_rxq_buffers().
Quoted 20 lines
Frank
drivers/net/ethernet/freescale/fec_main.c fec_enet_alloc_rxq_buffers(struct net_device
Quoted 4 lines
drivers/net/ethernet/freescale/fec_main.c +0
-0page_pool_destroy (rxq->page_pool); rxq->page_pool =NULL ; }@@ -3593,6 +3610,11 @@ fec_enet_alloc_rxq_buffers(struct net_device*ndev, unsigned int queue)
Quoted 14 lines
drivers/net/ethernet/freescale/fec_main.c +5
-1/* Set the last buffer to wrap. */ bdp =fec_enet_get_prevdesc (bdp, &rxq->bd); bdp->cbd_sc |=cpu_to_fec16 (BD_ENET_RX_WRAP ); + + err =fec_xdp_rxq_info_reg (fep, rxq); +if (err) + goto err_alloc; +return 0 ; err_alloc: --2.34.1
Wei Fang
maintainerPATCH v2 12/14 net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pool
In reply to Wei FangCurrently, the buffers of RX queue are allocated from the page pool. In the subsequent patches to support XDP zero copy, the RX buffers will be allocated from the UMEM. Therefore, extract fec_alloc_rxq_buffers_pp() from fec_enet_alloc_rxq_buffers() and we will add another helper to allocate RX buffers from UMEM for the XDP zero copy mode.
--- drivers/net/ethernet/freescale/fec_main.c | 78 ++++++++++++++++------- 1 file changed, 54 insertions(+), 24 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +54 -24
@@ -3435,6 +3435,24 @@ static void fec_xdp_rxq_info_unreg(struct fec_enet_priv_rx_q *rxq) } } +static void fec_free_rxq_buffers (struct fec_enet_priv_rx_q *rxq) +{ +int i; + +for (i =0 ; i < rxq->bd.ring_size; i++) { +struct page *page = rxq->rx_buf[i]; + +if (!page) +continue ; + +page_pool_put_full_page (rxq->page_pool, page, false); + rxq->rx_buf[i] =NULL ; + } + +page_pool_destroy (rxq->page_pool); + rxq->page_pool =NULL ; +} +static void fec_enet_free_buffers (struct net_device *ndev) {struct fec_enet_private *fep =netdev_priv (ndev);
@@ -3448,16 +3466,10 @@ static void fec_enet_free_buffers(struct net_device *ndev) rxq = fep->rx_queue[q];fec_xdp_rxq_info_unreg (rxq); - -for (i =0 ; i < rxq->bd.ring_size; i++) -page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], - false); +fec_free_rxq_buffers (rxq);for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; - -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; }for (q =0 ; q < fep->num_tx_queues; q++) {
@@ -3556,22 +3568,18 @@ static int fec_enet_alloc_queue(struct net_device *ndev)return ret; } -static int -fec_enet_alloc_rxq_buffers (struct net_device *ndev,unsigned int queue) +static int fec_alloc_rxq_buffers_pp (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) { -struct fec_enet_private *fep =netdev_priv (ndev); -struct fec_enet_priv_rx_q *rxq; +struct bufdesc *bdp = rxq->bd.base;dma_addr_t phys_addr; -struct bufdesc *bdp;struct page *page;int i, err; - rxq = fep->rx_queue[queue]; - bdp = rxq->bd.base; - err =fec_enet_create_page_pool (fep, rxq);if (err <0 ) { -netdev_err (ndev,"%s failed queue %d (%d)\n" , __func__, queue, err); +netdev_err (fep->netdev,"%s failed queue %d (%d)\n" , + __func__, rxq->bd.qid, err);return err; }
@@ -3590,8 +3598,10 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)for (i =0 ; i < rxq->bd.ring_size; i++) { page =page_pool_dev_alloc_pages (rxq->page_pool); -if (!page) - goto err_alloc; +if (!page) { + err = -ENOMEM ; + goto free_rx_buffers; + } phys_addr =page_pool_get_dma_addr (page) +FEC_ENET_XDP_HEADROOM ; bdp->cbd_bufaddr =cpu_to_fec32 (phys_addr);
@@ -3601,6 +3611,7 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)if (fep->bufdesc_ex) {struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; + ebdp->cbd_esc =cpu_to_fec32 (BD_ENET_RX_INT ); }
@@ -3611,15 +3622,34 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) bdp =fec_enet_get_prevdesc (bdp, &rxq->bd); bdp->cbd_sc |=cpu_to_fec16 (BD_ENET_RX_WRAP ); - err =fec_xdp_rxq_info_reg (fep, rxq); +return 0 ; + +free_rx_buffers: +fec_free_rxq_buffers (rxq); + +return err; +} + +static int +fec_enet_alloc_rxq_buffers (struct net_device *ndev,unsigned int queue) +{ +struct fec_enet_private *fep =netdev_priv (ndev); +struct fec_enet_priv_rx_q *rxq; +int err; + + rxq = fep->rx_queue[queue]; + err =fec_alloc_rxq_buffers_pp (fep, rxq);if (err) - goto err_alloc; +return err; -return 0 ; + err =fec_xdp_rxq_info_reg (fep, rxq); +if (err) { +fec_free_rxq_buffers (rxq); - err_alloc: -fec_enet_free_buffers (ndev); -return -ENOMEM ; +return err; + } + +return 0 ; } static int
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH v2 net-next 12/14] net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pool
Quoted 87 lines · Wei Fang
Currently, the buffers of RX queue are allocated from the page pool. In the subsequent patches to support XDP zero copy, the RX buffers will be allocated from the UMEM. Therefore, extract
fec_alloc_rxq_buffers_pp()fromfec_enet_alloc_rxq_buffers()and we will add another helper to allocate RX buffers from UMEM for the XDP zero copy mode.Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 78 ++++++++++++++++------- 1 file changed, 54 insertions(+), 24 deletions(-)drivers/net/ethernet/freescale/fec_main.c +24
-16@@ -3435,6 +3435,24 @@ static void fec_xdp_rxq_info_unreg(struct fec_enet_priv_rx_q *rxq) } } +static void fec_free_rxq_buffers (struct fec_enet_priv_rx_q *rxq) +{ +int i; + +for (i =0 ; i < rxq->bd.ring_size; i++) { +struct page *page = rxq->rx_buf[i]; + +if (!page) +continue ; + +page_pool_put_full_page (rxq->page_pool, page, false); + rxq->rx_buf[i] =NULL ; + } + +page_pool_destroy (rxq->page_pool); + rxq->page_pool =NULL ; +} +static void fec_enet_free_buffers (struct net_device *ndev) {struct fec_enet_private *fep =netdev_priv (ndev);@@ -3448,16 +3466,10 @@ static void fec_enet_free_buffers(struct net_device *ndev) rxq = fep->rx_queue[q];fec_xdp_rxq_info_unreg (rxq); - -for (i =0 ; i < rxq->bd.ring_size; i++) -page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], - false); +fec_free_rxq_buffers (rxq);for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; - -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; }for (q =0 ; q < fep->num_tx_queues; q++) {@@ -3556,22 +3568,18 @@ static int fec_enet_alloc_queue(struct net_device *ndev)return ret; } -static int -fec_enet_alloc_rxq_buffers (struct net_device *ndev,unsigned int queue) +static int fec_alloc_rxq_buffers_pp (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) { -struct fec_enet_private *fep =netdev_priv (ndev); -struct fec_enet_priv_rx_q *rxq; +struct bufdesc *bdp = rxq->bd.base;dma_addr_t phys_addr; -struct bufdesc *bdp;struct page *page;int i, err; - rxq = fep->rx_queue[queue]; - bdp = rxq->bd.base; - err =fec_enet_create_page_pool (fep, rxq);if (err <0 ) { -netdev_err (ndev,"%s failed queue %d (%d)\n" , __func__, queue, err); +netdev_err (fep->netdev,"%s failed queue %d (%d)\n" , + __func__, rxq->bd.qid, err);return err; }
drivers/net/ethernet/freescale/fec_main.c fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) · line 3603
Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c +3
-2@@ -3590,8 +3598,10 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)for (i =0 ; i < rxq->bd.ring_size; i++) { page =page_pool_dev_alloc_pages (rxq->page_pool); -if (!page) - goto err_alloc; +if (!page) { + err = -ENOMEM ; + goto free_rx_buffers;
look like this part is bug fix, miss set err to -ENOMEM
drivers/net/ethernet/freescale/fec_main.c fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) · line 3614
Quoted 9 lines
drivers/net/ethernet/freescale/fec_main.c +2
-0+ } phys_addr =page_pool_get_dma_addr (page) +FEC_ENET_XDP_HEADROOM ; bdp->cbd_bufaddr =cpu_to_fec32 (phys_addr);@@ -3601,6 +3611,7 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)if (fep->bufdesc_ex) {struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; +
uneccesary change
Frank
Quoted 47 lines
drivers/net/ethernet/freescale/fec_main.c +25
-7ebdp->cbd_esc =cpu_to_fec32 (BD_ENET_RX_INT ); }@@ -3611,15 +3622,34 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) bdp =fec_enet_get_prevdesc (bdp, &rxq->bd); bdp->cbd_sc |=cpu_to_fec16 (BD_ENET_RX_WRAP ); - err =fec_xdp_rxq_info_reg (fep, rxq); +return 0 ; + +free_rx_buffers: +fec_free_rxq_buffers (rxq); + +return err; +} + +static int +fec_enet_alloc_rxq_buffers (struct net_device *ndev,unsigned int queue) +{ +struct fec_enet_private *fep =netdev_priv (ndev); +struct fec_enet_priv_rx_q *rxq; +int err; + + rxq = fep->rx_queue[queue]; + err =fec_alloc_rxq_buffers_pp (fep, rxq);if (err) - goto err_alloc; +return err; -return 0 ; + err =fec_xdp_rxq_info_reg (fep, rxq); +if (err) { +fec_free_rxq_buffers (rxq); - err_alloc: -fec_enet_free_buffers (ndev); -return -ENOMEM ; +return err; + } + +return 0 ; } static int --2.34.1
Wei Fang
maintainerRE: [PATCH v2 net-next 12/14] net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pool
Quoted 93 lines · Wei Fang
Quoted 5 lines
Currently, the buffers of RX queue are allocated from the page pool. In the subsequent patches to support XDP zero copy, the RX buffers will be allocated from the UMEM. Therefore, extract
fec_alloc_rxq_buffers_pp()fromfec_enet_alloc_rxq_buffers()and we will add another helper to allocate RX buffers from UMEM for the XDP zerocopy mode.
drivers/net/ethernet/freescale/fec_main.c static void fec_xdp_rxq_info_unreg(struct
Quoted 13 lines
Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 78 ++++++++++++++++------- 1 file changed, 54 insertions(+), 24 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-0@@ -3435,6 +3435,24 @@ static void fec_xdp_rxq_info_unreg(struct
fec_enet_priv_rx_q*rxq)Quoted 72 lines
drivers/net/ethernet/freescale/fec_main.c +18
-0} } +static void fec_free_rxq_buffers (struct fec_enet_priv_rx_q *rxq) { +int i; + +for (i =0 ; i < rxq->bd.ring_size; i++) { +struct page *page = rxq->rx_buf[i]; + +if (!page) +continue ; + +page_pool_put_full_page (rxq->page_pool, page, false); + rxq->rx_buf[i] =NULL ; + } + +page_pool_destroy (rxq->page_pool); + rxq->page_pool =NULL ; +} +static void fec_enet_free_buffers (struct net_device *ndev) { struct fec_enet_private *fep = netdev_priv(ndev); @@ -3448,16 +3466,10 @@ static void fec_enet_free_buffers(struct net_device *ndev) rxq = fep->rx_queue[q];drivers/net/ethernet/freescale/fec_main.c +1
-7fec_xdp_rxq_info_unreg (rxq); - -for (i =0 ; i < rxq->bd.ring_size; i++) -page_pool_put_full_page (rxq->page_pool, rxq->rx_buf[i], - false); +fec_free_rxq_buffers (rxq);for (i =0 ; i <XDP_STATS_TOTAL ; i++) rxq->stats[i] =0 ; - -page_pool_destroy (rxq->page_pool); - rxq->page_pool =NULL ; } for (q = 0; q < fep->num_tx_queues; q++) { @@ -3556,22 +3568,18 @@static int
fec_enet_alloc_queue(struct net_device *ndev)drivers/net/ethernet/freescale/fec_main.c +0
-2return ret; } -static int -fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned intqueue)
drivers/net/ethernet/freescale/fec_main.c +5
-7+static int fec_alloc_rxq_buffers_pp (struct fec_enet_private *fep, +struct fec_enet_priv_rx_q *rxq) { -struct fec_enet_private *fep =netdev_priv (ndev); -struct fec_enet_priv_rx_q *rxq; +struct bufdesc *bdp = rxq->bd.base;dma_addr_t phys_addr; -struct bufdesc *bdp;struct page *page;int i, err; - rxq = fep->rx_queue[queue]; - bdp = rxq->bd.base; - err =fec_enet_create_page_pool (fep, rxq);if (err <0 ) { -netdev_err (ndev,"%s failed queue %d (%d)\n" , __func__, queue, err); +netdev_err (fep->netdev,"%s failed queue %d (%d)\n" , + __func__, rxq->bd.qid, err);return err; }@@ -3590,8 +3598,10 @@ fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) · line 3603
Quoted 7 lines
drivers/net/ethernet/freescale/fec_main.c +3
-2for (i =0 ; i < rxq->bd.ring_size; i++) { page =page_pool_dev_alloc_pages (rxq->page_pool); -if (!page) - goto err_alloc; +if (!page) { + err = -ENOMEM ; + goto free_rx_buffers;look like this part is bug fix, miss set err to
-ENOMEM
This is not a bug fix, the previous logic returned "-ENOMEM" directly at the err_alloc label, see below.
err_alloc:
fec_enet_free_buffers(ndev); return -ENOMEM;
Wei Fang
maintainerRE: [PATCH v2 net-next 12/14] net: fec: add fec_alloc_rxq_buffers_pp() to allocate buffers from page pool
In reply to Frank LiQuoted 8 lines
drivers/net/ethernet/freescale/fec_main.c fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue) · line 3614
Quoted 6 lines
fec_enet_alloc_rxq_buffers(struct net_device *ndev, unsigned int queue)drivers/net/ethernet/freescale/fec_main.c +1
-0if (fep->bufdesc_ex) {struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp; +uneccesary change
This might be a problem with how git displays it, the actual change is in fec_alloc_rxq_buffers_pp(), as shown below. We need to add a blank after the variable definition.
if (fep->bufdesc_ex) {
struct bufdesc_ex *ebdp = (struct bufdesc_ex *)bdp;
ebdp->cbd_esc = cpu_to_fec32(BD_ENET_RX_INT);
}Wei Fang
maintainerPATCH v2 13/14 net: fec: improve fec_enet_tx_queue()
In reply to Wei FangTo support AF_XDP zero-copy mode in the subsequent patch, the following adjustments have been made to fec_tx_queue().
1. Change the parameters of fec_tx_queue().
2. Some variables are initialized at the time of declaration, and the order of local variables is updated to follow the reverse xmas tree style.
3. Remove the variable xdpf and add the variable tx_buf.
--- drivers/net/ethernet/freescale/fec_main.c | 43 +++++++++-------------- 1 file changed, 17 insertions(+), 26 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +17 -26
@@ -1467,27 +1467,18 @@ fec_enet_hwtstamp(struct fec_enet_private *fep, unsigned ts, hwtstamps->hwtstamp =ns_to_ktime (ns); } -static void -fec_enet_tx_queue (struct net_device *ndev,u16 queue_id,int budget) +static void fec_enet_tx_queue (struct fec_enet_private *fep, +u16 queue,int budget) { -struct fec_enet_private *fep; -struct xdp_frame *xdpf; -struct bufdesc *bdp; +struct netdev_queue *nq =netdev_get_tx_queue (fep->netdev, queue); +struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue]; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = txq->dirty_tx; +int index, frame_len, entries_free; +struct fec_tx_buffer *tx_buf;unsigned short status; -struct sk_buff *skb; -struct fec_enet_priv_tx_q *txq; -struct netdev_queue *nq; -int index =0 ; -int entries_free; +struct sk_buff *skb;struct page *page; -int frame_len; - - fep =netdev_priv (ndev); - - txq = fep->tx_queue[queue_id]; -/* get next bdp of dirty_tx */ - nq =netdev_get_tx_queue (ndev, queue_id); - bdp = txq->dirty_tx;/* get next bdp of dirty_tx */ bdp =fec_enet_get_nextdesc (bdp, &txq->bd);
@@ -1500,9 +1491,10 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)break ; index =fec_enet_get_bd_index (bdp, &txq->bd); + tx_buf = &txq->tx_buf[index]; frame_len =fec16_to_cpu (bdp->cbd_datlen); -switch (txq->tx_buf[index].type) { +switch (tx_buf->type) {case FEC_TXBUF_T_SKB :if (bdp->cbd_bufaddr && !IS_TSO_HEADER (txq,fec32_to_cpu (bdp->cbd_bufaddr)))
@@ -1511,7 +1503,7 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget) frame_len, DMA_TO_DEVICE); bdp->cbd_bufaddr =cpu_to_fec32 (0 ); - skb = txq->tx_buf[index].buf_p; + skb = tx_buf->buf_p;if (!skb) goto tx_buf_done;
@@ -1542,19 +1534,18 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (unlikely (!budget)) goto out; - xdpf = txq->tx_buf[index].buf_p;dma_unmap_single (&fep->pdev->dev,fec32_to_cpu (bdp->cbd_bufaddr), frame_len,DMA_TO_DEVICE ); bdp->cbd_bufaddr =cpu_to_fec32 (0 ); -xdp_return_frame_rx_napi (xdpf); +xdp_return_frame_rx_napi (tx_buf->buf_p);break ;case FEC_TXBUF_T_XDP_TX :if (unlikely (!budget)) goto out; bdp->cbd_bufaddr =cpu_to_fec32 (0 ); - page = txq->tx_buf[index].buf_p; + page = tx_buf->buf_p;/* The dma_sync_size = 0 as XDP_TX has already synced * DMA for_device */
@@ -1591,9 +1582,9 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (status &BD_ENET_TX_DEF ) ndev->stats.collisions++; - txq->tx_buf[index].buf_p =NULL ; + tx_buf->buf_p =NULL ;/* restore default tx buffer type: FEC_TXBUF_T_SKB */ - txq->tx_buf[index].type =FEC_TXBUF_T_SKB ; + tx_buf->type =FEC_TXBUF_T_SKB ; tx_buf_done:/* Make sure the update to bdp and tx_buf are performed
@@ -1629,7 +1620,7 @@ static void fec_enet_tx(struct net_device *ndev, int budget)/* Make sure that AVB queues are processed first. */ for (i = fep->num_tx_queues -1 ; i >=0 ; i--) -fec_enet_tx_queue (ndev, i, budget); +fec_enet_tx_queue (fep, i, budget); } static int fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq,
Signature · 1 line
2.34.1
Re: [PATCH v2 net-next 13/14] net: fec: improve fec_enet_tx_queue()
Quoted 11 lines · Wei Fang
To support
AF_XDPzero-copy mode in the subsequent patch, the following adjustments have been made tofec_tx_queue().1. Change the parameters of
fec_tx_queue().
2. Some variables are initialized at the time of declaration, and the order of local variables is updated to follow the reverse xmas tree style.
3. Remove the variable xdpf and add the variabletx_buf.Signed-off-by Wei Fang <[email protected]>---
Quoted 111 lines
drivers/net/ethernet/freescale/fec_main.c | 43 +++++++++-------------- 1 file changed, 17 insertions(+), 26 deletions(-)drivers/net/ethernet/freescale/fec_main.c +17
-27@@ -1467,27 +1467,18 @@ fec_enet_hwtstamp(struct fec_enet_private *fep, unsigned ts, hwtstamps->hwtstamp =ns_to_ktime (ns); } -static void -fec_enet_tx_queue (struct net_device *ndev,u16 queue_id,int budget) +static void fec_enet_tx_queue (struct fec_enet_private *fep, +u16 queue,int budget) { -struct fec_enet_private *fep; -struct xdp_frame *xdpf; -struct bufdesc *bdp; +struct netdev_queue *nq =netdev_get_tx_queue (fep->netdev, queue); +struct fec_enet_priv_tx_q *txq = fep->tx_queue[queue]; +struct net_device *ndev = fep->netdev; +struct bufdesc *bdp = txq->dirty_tx; +int index, frame_len, entries_free; +struct fec_tx_buffer *tx_buf;unsigned short status; -struct sk_buff *skb; -struct fec_enet_priv_tx_q *txq; -struct netdev_queue *nq; -int index =0 ; -int entries_free; +struct sk_buff *skb;struct page *page; -int frame_len; - - fep =netdev_priv (ndev); - - txq = fep->tx_queue[queue_id]; -/* get next bdp of dirty_tx */ - nq =netdev_get_tx_queue (ndev, queue_id); - bdp = txq->dirty_tx;/* get next bdp of dirty_tx */ bdp =fec_enet_get_nextdesc (bdp, &txq->bd);@@ -1500,9 +1491,10 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)break ; index =fec_enet_get_bd_index (bdp, &txq->bd); + tx_buf = &txq->tx_buf[index]; frame_len =fec16_to_cpu (bdp->cbd_datlen); -switch (txq->tx_buf[index].type) { +switch (tx_buf->type) {case FEC_TXBUF_T_SKB :if (bdp->cbd_bufaddr && !IS_TSO_HEADER (txq,fec32_to_cpu (bdp->cbd_bufaddr)))@@ -1511,7 +1503,7 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget) frame_len, DMA_TO_DEVICE); bdp->cbd_bufaddr =cpu_to_fec32 (0 ); - skb = txq->tx_buf[index].buf_p; + skb = tx_buf->buf_p;if (!skb) goto tx_buf_done;@@ -1542,19 +1534,18 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (unlikely (!budget)) goto out; - xdpf = txq->tx_buf[index].buf_p;dma_unmap_single (&fep->pdev->dev,fec32_to_cpu (bdp->cbd_bufaddr), frame_len,DMA_TO_DEVICE ); bdp->cbd_bufaddr =cpu_to_fec32 (0 ); -xdp_return_frame_rx_napi (xdpf); +xdp_return_frame_rx_napi (tx_buf->buf_p);break ;case FEC_TXBUF_T_XDP_TX :if (unlikely (!budget)) goto out; bdp->cbd_bufaddr =cpu_to_fec32 (0 ); - page = txq->tx_buf[index].buf_p; + page = tx_buf->buf_p;/* The dma_sync_size = 0 as XDP_TX has already synced * DMA for_device */ @@ -1591,9 +1582,9 @@ fec_enet_tx_queue(struct net_device *ndev, u16 queue_id, int budget)if (status &BD_ENET_TX_DEF ) ndev->stats.collisions++; - txq->tx_buf[index].buf_p =NULL ; + tx_buf->buf_p =NULL ;/* restore default tx buffer type: FEC_TXBUF_T_SKB */ - txq->tx_buf[index].type =FEC_TXBUF_T_SKB ; + tx_buf->type =FEC_TXBUF_T_SKB ; tx_buf_done:/* Make sure the update to bdp and tx_buf are performed @@ -1629,7 +1620,7 @@ static void fec_enet_tx(struct net_device *ndev, int budget)/* Make sure that AVB queues are processed first. */ for (i = fep->num_tx_queues -1 ; i >=0 ; i--) -fec_enet_tx_queue (ndev, i, budget); +fec_enet_tx_queue (fep, i, budget); } static int fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq, --2.34.1
Wei Fang
maintainerPATCH v2 14/14 net: fec: add AF_XDP zero-copy support
In reply to Wei FangAdd AF_XDP zero-copy support for both TX and RX.
For RX, instead of allocating buffers from the page pool, the buffers are allocated from xsk pool, so fec_alloc_rxq_buffers_zc() is added to allocate RX buffers from xsk pool. And fec_enet_rx_queue_xsk() is used to process the frames from the RX queue which is bound to the AF_XDP socket. Similar to the XDP copy mode, the zero-copy mode also supports XDP_TX, XDP_PASS, XDP_DROP and XDP_REDIRECT actions. In addition, fec_enet_xsk_tx_xmit() is similar to fec_enet_xdp_tx_xmit() and is used to handle XDP_TX action in zero-copy mode.
For TX, there are two cases, one is the frames from the AF_XDP socket, so fec_enet_xsk_xmit() is added to directly transmit the frames from the socket and the buffer type is marked as FEC_TXBUF_T_XSK_XMIT. The other one is the frams from the RX queue (XDP_TX action), the buffer type is marked as FEC_TXBUF_T_XSK_TX. Therefore, fec_enet_tx_queue() could correctly clean the TX queue base on the buffer type.
Also, some tests have been done on the i.MX93-EVK board with the xdpsock tool, the following are the results.
Env: i.MX93 connects to a packet generator, the link speed is 1Gbps, and flow-control is off. The RX packet size is 64 bytes including FCS. Only one RX queue (CPU) is used to receive frames.
1. MAC swap L2 forwarding
1.1 Zero-copy mode
root@imx93evk:~# ./xdpsock -i eth0 -l -z
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00
rx 414715 415455
tx 414715 4154551.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -l -c
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00
rx 356396 356609
tx 356396 3566092. TX only
2.1 Zero-copy mode
root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -z
sock0@eth0:0 txonly xdp-drv
pps pkts 1.00
rx 0 0
tx 1119573 11267202.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -c
sock0@eth0:0 txonly xdp-drv
pps pkts 1.00
rx 0 0
tx 406864 407616--- drivers/net/ethernet/freescale/fec.h | 13 +- drivers/net/ethernet/freescale/fec_main.c | 611 ++++++++++++++++++++-- 2 files changed, 582 insertions(+), 42 deletions(-)
drivers/net/ethernet/freescale/fec.h +12 -1
@@ -340,6 +340,7 @@ struct bufdesc_ex {#define FEC_ENET_TX_FRPPG (PAGE_SIZE / FEC_ENET_TX_FRSIZE)#define TX_RING_SIZE 1024/* Must be power of two */ #define TX_RING_MOD_MASK 511/* for this to work */ +#define FEC_XSK_TX_BUDGET_MAX 256#define BD_ENET_RX_INT 0x00800000#define BD_ENET_RX_PTP ((ushort)0x0400)
@@ -528,6 +529,8 @@ enum fec_txbuf_type {FEC_TXBUF_T_SKB ,FEC_TXBUF_T_XDP_NDO ,FEC_TXBUF_T_XDP_TX , +FEC_TXBUF_T_XSK_XMIT , + FEC_TXBUF_T_XSK_TX, }; struct fec_tx_buffer {
@@ -539,6 +542,7 @@ struct fec_enet_priv_tx_q {struct bufdesc_prop bd;unsigned char *tx_bounce[TX_RING_SIZE ];struct fec_tx_buffer tx_buf[TX_RING_SIZE ]; +struct xsk_buff_pool *xsk_pool;unsigned short tx_stop_threshold;unsigned short tx_wake_threshold;
@@ -548,9 +552,16 @@ struct fec_enet_priv_tx_q {dma_addr_t tso_hdrs_dma; }; +union fec_rx_buffer { +void *buf_p; +struct page *page; +struct xdp_buff *xdp; +}; +struct fec_enet_priv_rx_q {struct bufdesc_prop bd; -struct page *rx_buf[RX_RING_SIZE ]; +union fec_rx_buffer rx_buf[RX_RING_SIZE ]; +struct xsk_buff_pool *xsk_pool;/* page_pool */ struct page_pool *page_pool;
drivers/net/ethernet/freescale/fec_main.c +570 -41
797 lines not on this page · raw message
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH v2 net-next 14/14] net: fec: add AF_XDP zero-copy support
kernel test robot noticed the following build warnings:
Hi Wei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Wei-Fang/net-fec-add-fec_txq_trigger_xmit-helper/20260116-154834 base: net-next/main patch link: https://lore.kernel.org/r/20260116074027.1603841-15-wei.fang%40nxp.com patch subject: [PATCH v2 net-next 14/14] net: fec: add AF_XDP zero-copy support config: arm-imx_v4_v5_defconfig (https://download.01.org/0day-ci/archive/20260116/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260116/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/freescale/fec_main.c:1040:4: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
1040 | default:
| ^
drivers/net/ethernet/freescale/fec_main.c:1040:4: note: insert 'break;' to avoid fall-through
1040 | default:
| ^
| break; 1 warning generated.
vim +1040 drivers/net/ethernet/freescale/fec_main.c
61a4427b955f79d drivers/net/ethernet/freescale/fec_main.c Nimrod Andy 2014-06-12 970
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 971 /* Init RX & TX buffer descriptors
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 972 */
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 973 static void fec_enet_bd_init(struct net_device *dev)
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 974 {
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 975 struct fec_enet_private *fep = netdev_priv(dev);
4d494cdc92b3b9a drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2014-09-13 976 struct fec_enet_priv_tx_q *txq;
4d494cdc92b3b9a drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2014-09-13 977 struct fec_enet_priv_rx_q *rxq;
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 978 struct bufdesc *bdp;
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 979 unsigned int i;
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 980 unsigned int q;
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 981
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 982 for (q = 0; q < fep->num_rx_queues; q++) {
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 983 /* Initialize the receive buffer descriptors. */
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 984 rxq = fep->rx_queue[q];
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 985 bdp = rxq->bd.base;
4d494cdc92b3b9a drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2014-09-13 986
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 987 for (i = 0; i < rxq->bd.ring_size; i++) {
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 988
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 989 /* Initialize the BD for every fragment in the page. */
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 990 if (bdp->cbd_bufaddr)
5cfa30397bc3677 drivers/net/ethernet/freescale/fec_main.c Johannes Berg 2016-01-24 991 bdp->cbd_sc = cpu_to_fec16(BD_ENET_RX_EMPTY);
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 992 else
5cfa30397bc3677 drivers/net/ethernet/freescale/fec_main.c Johannes Berg 2016-01-24 993 bdp->cbd_sc = cpu_to_fec16(0);
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 994 bdp = fec_enet_get_nextdesc(bdp, &rxq->bd);
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 995 }
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 996
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 997 /* Set the last buffer to wrap */
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 998 bdp = fec_enet_get_prevdesc(bdp, &rxq->bd);
bd31490718b47d9 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2025-11-19 999 bdp->cbd_sc |= cpu_to_fec16(BD_ENET_RX_WRAP);
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1000
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1001 rxq->bd.cur = rxq->bd.base;
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 1002 }
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1003
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 1004 for (q = 0; q < fep->num_tx_queues; q++) {
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1005 /* ...and the same for transmit */
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 1006 txq = fep->tx_queue[q];
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1007 bdp = txq->bd.base;
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1008 txq->bd.cur = bdp;
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1009
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1010 for (i = 0; i < txq->bd.ring_size; i++) {
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1011 struct page *page;
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1012
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1013 /* Initialize the BD for every fragment in the page. */
5cfa30397bc3677 drivers/net/ethernet/freescale/fec_main.c Johannes Berg 2016-01-24 1014 bdp->cbd_sc = cpu_to_fec16(0);
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1015
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1016 switch (txq->tx_buf[i].type) {
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1017 case FEC_TXBUF_T_SKB:
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1018 if (bdp->cbd_bufaddr &&
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1019 !IS_TSO_HEADER(txq, fec32_to_cpu(bdp->cbd_bufaddr)))
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1020 dma_unmap_single(&fep->pdev->dev,
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1021 fec32_to_cpu(bdp->cbd_bufaddr),
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1022 fec16_to_cpu(bdp->cbd_datlen),
178e5f57a8d8f8f drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2017-12-22 1023 DMA_TO_DEVICE);
af6f4791380c320 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-08-15 1024 dev_kfree_skb_any(txq->tx_buf[i].buf_p);
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1025 break;
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1026 case FEC_TXBUF_T_XDP_NDO:
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1027 dma_unmap_single(&fep->pdev->dev,
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1028 fec32_to_cpu(bdp->cbd_bufaddr),
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1029 fec16_to_cpu(bdp->cbd_datlen),
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1030 DMA_TO_DEVICE);
af6f4791380c320 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-08-15 1031 xdp_return_frame(txq->tx_buf[i].buf_p);
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1032 break;
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1033 case FEC_TXBUF_T_XDP_TX:
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1034 page = txq->tx_buf[i].buf_p;
65589e860a80369 drivers/net/ethernet/freescale/fec_main.c Byungchul Park 2025-07-21 1035 page_pool_put_page(pp_page_to_nmdesc(page)->pp,
f1d89a02b16bcdc drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1036 page, 0, false);
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1037 break;
f9806afd55c4ab1 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1038 case FEC_TXBUF_T_XSK_TX:
f9806afd55c4ab1 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1039 xsk_buff_free(txq->tx_buf[i].buf_p);
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 @1040 default:
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1041 break;
81725cc0fbfea44 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2026-01-16 1042 };
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1043
af6f4791380c320 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-08-15 1044 txq->tx_buf[i].buf_p = NULL;
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1045 /* restore default tx buffer type: FEC_TXBUF_T_SKB */
20f797399035a80 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2023-07-06 1046 txq->tx_buf[i].type = FEC_TXBUF_T_SKB;
5cfa30397bc3677 drivers/net/ethernet/freescale/fec_main.c Johannes Berg 2016-01-24 1047 bdp->cbd_bufaddr = cpu_to_fec32(0);
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1048 bdp = fec_enet_get_nextdesc(bdp, &txq->bd);
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1049 }
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1050
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1051 /* Set the last buffer to wrap */
7355f2760620b38 drivers/net/ethernet/freescale/fec_main.c Troy Kisky 2016-02-05 1052 bdp = fec_enet_get_prevdesc(bdp, &txq->bd);
bd31490718b47d9 drivers/net/ethernet/freescale/fec_main.c Wei Fang 2025-11-19 1053 bdp->cbd_sc |= cpu_to_fec16(BD_ENET_TX_WRAP);
4d494cdc92b3b9a drivers/net/ethernet/freescale/fec_main.c Fugang Duan 2014-09-13 1054 txq->dirty_tx = bdp;
14109a59caf93e6 drivers/net/ethernet/freescale/fec.c Frank Li 2013-03-26 1055 }
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 1056 }
59d0f746564495c drivers/net/ethernet/freescale/fec_main.c Frank Li 2014-09-13 1057 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Frank Li
maintainerRe: [PATCH v2 net-next 14/14] net: fec: add AF_XDP zero-copy support
In reply to Wei FangQuoted 65 lines · Wei Fang
Add
AF_XDPzero-copy support for both TX and RX.For RX, instead of allocating buffers from the page pool, the buffers are allocated from xsk pool, so
fec_alloc_rxq_buffers_zc()is added to allocate RX buffers from xsk pool. Andfec_enet_rx_queue_xsk()is used to process the frames from the RX queue which is bound to theAF_XDPsocket. Similar to the XDP copy mode, the zero-copy mode also supportsXDP_TX,XDP_PASS,XDP_DROPandXDP_REDIRECTactions. In addition,fec_enet_xsk_tx_xmit()is similar tofec_enet_xdp_tx_xmit()and is used to handleXDP_TXaction in zero-copy mode.For TX, there are two cases, one is the frames from the
AF_XDPsocket, sofec_enet_xsk_xmit()is added to directly transmit the frames from the socket and the buffer type is marked asFEC_TXBUF_T_XSK_XMIT. The other one is the frams from the RX queue (XDP_TXaction), the buffer type is marked asFEC_TXBUF_T_XSK_TX. Therefore,fec_enet_tx_queue()could correctly clean the TX queue base on the buffer type.Also, some tests have been done on the i.MX93-EVK board with the xdpsock tool, the following are the results.
Env: i.MX93 connects to a packet generator, the link speed is 1Gbps, and flow-control is off. The RX packet size is 64 bytes including FCS. Only one RX queue (CPU) is used to receive frames.
1. MAC swap L2 forwarding
1.1 Zero-copy moderoot@imx93evk:~# ./xdpsock -i eth0 -l -z sock0@eth0:0 l2fwd xdp-drv pps pkts 1.00 rx 414715 415455 tx 414715 4154551.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -l -c sock0@eth0:0 l2fwd xdp-drv pps pkts 1.00 rx 356396 356609 tx 356396 3566092. TX only
2.1 Zero-copy moderoot@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -z sock0@eth0:0 txonly xdp-drv pps pkts 1.00 rx 0 0 tx 1119573 11267202.2 Copy mode
root@imx93evk:~# ./xdpsock -i eth0 -t -s 64 -c sock0@eth0:0 txonly xdp-drv pps pkts 1.00 rx 0 0 tx 406864 407616Signed-off-by Wei Fang <[email protected]>--- drivers/net/ethernet/freescale/fec.h | 13 +- drivers/net/ethernet/freescale/fec_main.c | 611 ++++++++++++++++++++-- 2 files changed, 582 insertions(+), 42 deletions(-)drivers/net/ethernet/freescale/fec.h +0
-0
...
Quoted 11 lines
static int
fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf){drivers/net/ethernet/freescale/fec.h +5
-0struct fec_enet_private *fep =netdev_priv (dev);bool is_run =netif_running (dev);struct bpf_prog *old_prog; +/* No need to support the SoCs that require to do the frame swap +* because the performance wouldn't be better than the skb mode. +*/ +if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) +return -EOPNOTSUPP ;
drivers/net/ethernet/freescale/fec.h
Quoted 10 lines
drivers/net/ethernet/freescale/fec.h +1
-7+switch (bpf->command) {case XDP_SETUP_PROG : -/* No need to support the SoCs that require to -* do the frame swap because the performance wouldn't be -* better than the skb mode. -*/ -if (fep->quirks &FEC_QUIRK_SWAP_FRAME ) -return -EOPNOTSUPP ; -
This part can be new patch.
Code itself look good, but I am not familar XDP's logic.
Frank
Quoted 64 lines
drivers/net/ethernet/freescale/fec.h +28
-3if (!bpf->prog)xdp_features_clear_redirect_target (dev);@@ -3994,7 +4497,8 @@ static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf)return 0 ;case XDP_SETUP_XSK_POOL : -return -EOPNOTSUPP ; +return fec_setup_xsk_pool (dev, bpf->xsk.pool, + bpf->xsk.queue_id);default :return -EOPNOTSUPP ;@@ -4143,6 +4647,29 @@ static int fec_enet_xdp_xmit(struct net_device *dev,return sent_frames; } +static int fec_enet_xsk_wakeup (struct net_device *ndev,u32 queue,u32 flags) +{ +struct fec_enet_private *fep =netdev_priv (ndev); +struct fec_enet_priv_rx_q *rxq; + +if (!netif_running (ndev) || !netif_carrier_ok (ndev)) +return -ENETDOWN ; + +if (queue >= fep->num_rx_queues || queue >= fep->num_tx_queues) +return -ERANGE ; + + rxq = fep->rx_queue[queue]; +if (!rxq->xsk_pool) +return -EINVAL ; + +if (!napi_if_scheduled_mark_missed (&fep->napi)) { +if (likely (napi_schedule_prep (&fep->napi))) +__napi_schedule (&fep->napi); + } + +return 0 ; +} +static int fec_hwtstamp_get (struct net_device *ndev,struct kernel_hwtstamp_config *config) {@@ -4205,6 +4732,7 @@ static const struct net_device_ops fec_netdev_ops = { .ndo_set_features = fec_set_features, .ndo_bpf = fec_enet_bpf, .ndo_xdp_xmit = fec_enet_xdp_xmit, + .ndo_xsk_wakeup = fec_enet_xsk_wakeup, .ndo_hwtstamp_get = fec_hwtstamp_get, .ndo_hwtstamp_set = fec_hwtstamp_set, };@@ -4332,7 +4860,8 @@ static int fec_enet_init(struct net_device *ndev)if (!(fep->quirks &FEC_QUIRK_SWAP_FRAME )) ndev->xdp_features =NETDEV_XDP_ACT_BASIC | -NETDEV_XDP_ACT_REDIRECT ; +NETDEV_XDP_ACT_REDIRECT | +NETDEV_XDP_ACT_XSK_ZEROCOPY ;fec_restart (ndev); --2.34.1