stmmac: add XDP ZC support
Subsystems (6)
v2 cover stmmac: add XDP ZC support
Hi,
This is the v2 patch series to add XDP ZC support to stmmac driver.
Summary of v2 patch change:-
6/7: fix synchronize_rcu() is called stmmac_disable_all_queues() that is
used by ndo_setup_tc().
########################################################################
Continuous burst traffics are generated by pktgen script and in the midst of each packet processing operation by xdpsock the following tc-loop.sh script is looped continuously:-
#!/bin/bash
tc qdisc del dev eth0 parent root
tc qdisc add dev eth0 ingress
tc qdisc add dev eth0 root mqprio num_tc 4 map 0 1 2 3 0 0 0 0 0 0 0 0 0 0 0 0 queues 1@0 1@1 1@2 1@3 hw 0 tc filter add dev eth0 parent ffff: protocol 802.1Q flower vlan_prio 0 hw_tc 0
tc filter add dev eth0 parent ffff: protocol 802.1Q flower vlan_prio 1 hw_tc 1
tc filter add dev eth0 parent ffff: protocol 802.1Q flower vlan_prio 2 hw_tc 2
tc filter add dev eth0 parent ffff: protocol 802.1Q flower vlan_prio 3 hw_tc 3
tc qdisc list dev eth0
tc filter show dev eth0 ingress
On different ssh terminal
$ while true; do ./tc-loop.sh; sleep 1; done
The v2 patch series have been tested using the xdpsock app:
$ ./xdpsock -i eth0 -l -z
From xdpsock poller pps report and dmesg, we don't find any warning related to rcu and the only difference when the script is executed is the pps rate drops momentarily.
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 436347 191361334 tx 436411 191361334
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 254117 191615476 tx 254053 191615412
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 466395 192081924 tx 466395 192081860
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 287410 192369365 tx 287474 192369365
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 395853 192765329 tx 395789 192765265
sock0@eth0:0 l2fwd xdp-drv
pps pkts 1.00 rx 466132 193231514 tx 466132 193231450
########################################################################
Based on the above result, the fix looks promising. Appreciate that if community can help to review the patch series and provide me feedback for improvement.
Thanks,
Boon Leong
------------------------------------------------------------------------
History of patch series as follow:-
v1: https://patchwork.kernel.org/project/netdevbpf/list/?series=465747&state=*
------------------------------------------------------------------------
Ong Boon Leong (7):
net: stmmac: rearrange RX buffer allocation and free functions
net: stmmac: introduce dma_recycle_rx_skbufs for
stmmac_reinit_rx_buffers
net: stmmac: refactor stmmac_init_rx_buffers for
stmmac_reinit_rx_buffers
net: stmmac: rearrange RX and TX desc init into per-queue basis
net: stmmac: Refactor __stmmac_xdp_run_prog for XDP ZC
net: stmmac: Enable RX via AF_XDP zero-copy
net: stmmac: Add TX via XDP zero-copy socket
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 24 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 1718 +++++++++++++---- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 95 + .../net/ethernet/stmicro/stmmac/stmmac_xdp.h | 3 + 4 files changed, 1411 insertions(+), 429 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/7 net: stmmac: rearrange RX buffer allocation and free functions
This patch restructures the per RX queue buffer allocation from page_pool to stmmac_alloc_rx_buffers().
We also rearrange dma_free_rx_skbufs() so that it can be used in init_dma_rx_desc_rings() during freeing of RX buffer in the event of page_pool allocation failure to replace the more efficient method earlier. The replacement is needed to make the RX buffer alloc and free method scalable to XDP ZC xsk_pool alloc and free later.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +47 -37
@@ -1475,6 +1475,43 @@ static void stmmac_free_tx_buffer(struct stmmac_priv *priv, u32 queue, int i) tx_q->tx_skbuff_dma[i].map_as_page = false; } +/** +* dma_free_rx_skbufs - free RX dma buffers +* @priv: private structure +* @queue: RX queue index +*/ +static void dma_free_rx_skbufs (struct stmmac_priv *priv,u32 queue) +{ +int i; + +for (i =0 ; i < priv->dma_rx_size; i++) +stmmac_free_rx_buffer (priv, queue, i); +} + +static int stmmac_alloc_rx_buffers (struct stmmac_priv *priv,u32 queue, +gfp_t flags) +{ +struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +int i; + +for (i =0 ; i < priv->dma_rx_size; i++) { +struct dma_desc *p; +int ret; + +if (priv->extend_desc) + p = &((rx_q->dma_erx + i)->basic); +else + p = rx_q->dma_rx + i; + + ret =stmmac_init_rx_buffers (priv, p, i, flags, + queue); +if (ret) +return ret; + } + +return 0 ; +} +/** * stmmac_reinit_rx_buffers - reinit the RX descriptor buffer. * @priv: driver private structure
@@ -1547,15 +1584,14 @@ static void stmmac_reinit_rx_buffers(struct stmmac_priv *priv)return ; err_reinit_rx_buffers: -do { -while (--i >=0 ) -stmmac_free_rx_buffer (priv, queue, i); +while (queue >=0 ) { +dma_free_rx_skbufs (priv, queue);if (queue ==0 )break ; - i = priv->dma_rx_size; - }while (queue-- >0 ); + queue--; + } }/**
@@ -1572,7 +1608,6 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)u32 rx_count = priv->plat->rx_queues_to_use;int ret = -ENOMEM ;int queue; -int i;/* RX INITIALIZATION */ netif_dbg(priv, probe, priv->dev,
@@ -1580,7 +1615,7 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)for (queue =0 ; queue < rx_count; queue++) {struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; -int ret; + netif_dbg(priv, probe, priv->dev, "(%s) dma_rx_phy=0x%08x\n", __func__,
@@ -1596,22 +1631,12 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)"Register MEM_TYPE_PAGE_POOL RxQ-%d\n" , rx_q->queue_index); -for (i =0 ; i < priv->dma_rx_size; i++) { -struct dma_desc *p; - -if (priv->extend_desc) - p = &((rx_q->dma_erx + i)->basic); -else - p = rx_q->dma_rx + i; - - ret =stmmac_init_rx_buffers (priv, p, i, flags, - queue); -if (ret) - goto err_init_rx_buffers; - } + ret =stmmac_alloc_rx_buffers (priv, queue, flags); +if (ret <0 ) + goto err_init_rx_buffers; rx_q->cur_rx =0 ; - rx_q->dirty_rx = (unsigned int )(i - priv->dma_rx_size); + rx_q->dirty_rx =0 ;/* Setup the chained descriptor addresses */ if (priv->mode ==STMMAC_CHAIN_MODE ) {
@@ -1630,13 +1655,11 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) err_init_rx_buffers:while (queue >=0 ) { -while (--i >=0 ) -stmmac_free_rx_buffer (priv, queue, i); +dma_free_rx_skbufs (priv, queue);if (queue ==0 )break ; - i = priv->dma_rx_size; queue--; }
@@ -1731,19 +1754,6 @@ static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)return ret; } -/** -* dma_free_rx_skbufs - free RX dma buffers -* @priv: private structure -* @queue: RX queue index -*/ -static void dma_free_rx_skbufs (struct stmmac_priv *priv,u32 queue) -{ -int i; - -for (i =0 ; i < priv->dma_rx_size; i++) -stmmac_free_rx_buffer (priv, queue, i); -} -/** * dma_free_tx_skbufs - free TX dma buffers * @priv: private structure
Signature · 1 line
2.25.1
PATCH v2 2/7 net: stmmac: introduce dma_recycle_rx_skbufs for stmmac_reinit_rx_buffers
In reply to Ong Boon LeongRearrange RX buffer page_pool recycling logics into dma_recycle_rx_skbufs, so that we prepare stmmac_reinit_rx_buffers() for XSK pool expansion.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +27 -17
@@ -1512,6 +1512,31 @@ static int stmmac_alloc_rx_buffers(struct stmmac_priv *priv, u32 queue,return 0 ; } +/** +* dma_recycle_rx_skbufs - recycle RX dma buffers +* @priv: private structure +* @queue: RX queue index +*/ +static void dma_recycle_rx_skbufs (struct stmmac_priv *priv,u32 queue) +{ +struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +int i; + +for (i =0 ; i < priv->dma_rx_size; i++) { +struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i]; + +if (buf->page) { +page_pool_recycle_direct (rx_q->page_pool, buf->page); + buf->page =NULL ; + } + +if (priv->sph && buf->sec_page) { +page_pool_recycle_direct (rx_q->page_pool, buf->sec_page); + buf->sec_page =NULL ; + } + } +} +/** * stmmac_reinit_rx_buffers - reinit the RX descriptor buffer. * @priv: driver private structure
@@ -1524,23 +1549,8 @@ static void stmmac_reinit_rx_buffers(struct stmmac_priv *priv)u32 queue;int i; -for (queue =0 ; queue < rx_count; queue++) { -struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; - -for (i =0 ; i < priv->dma_rx_size; i++) { -struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i]; - -if (buf->page) { -page_pool_recycle_direct (rx_q->page_pool, buf->page); - buf->page =NULL ; - } - -if (priv->sph && buf->sec_page) { -page_pool_recycle_direct (rx_q->page_pool, buf->sec_page); - buf->sec_page =NULL ; - } - } - } +for (queue =0 ; queue < rx_count; queue++) +dma_recycle_rx_skbufs (priv, queue);for (queue =0 ; queue < rx_count; queue++) {struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
Signature · 1 line
2.25.1
PATCH v2 3/7 net: stmmac: refactor stmmac_init_rx_buffers for stmmac_reinit_rx_buffers
In reply to Ong Boon LeongThe per-queue RX buffer allocation in stmmac_reinit_rx_buffers() can be made to use stmmac_alloc_rx_buffers() by merging the page_pool alloc checks for "buf->page" and "buf->sec_page" in stmmac_init_rx_buffers().
This is in preparation for XSK pool allocation later.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 378 +++++++++--------- 1 file changed, 189 insertions(+), 189 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +189 -189
@@ -1388,12 +1388,14 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i]; - buf->page =page_pool_dev_alloc_pages (rx_q->page_pool); -if (!buf->page) -return -ENOMEM ; - buf->page_offset =stmmac_rx_offset (priv); +if (!buf->page) { + buf->page =page_pool_dev_alloc_pages (rx_q->page_pool); +if (!buf->page) +return -ENOMEM ; + buf->page_offset =stmmac_rx_offset (priv); + } -if (priv->sph) { +if (priv->sph && !buf->sec_page) { buf->sec_page =page_pool_dev_alloc_pages (rx_q->page_pool);if (!buf->sec_page)return -ENOMEM ;
@@ -1547,48 +1549,16 @@ static void stmmac_reinit_rx_buffers(struct stmmac_priv *priv) {u32 rx_count = priv->plat->rx_queues_to_use;u32 queue; -int i;for (queue =0 ; queue < rx_count; queue++)dma_recycle_rx_skbufs (priv, queue);for (queue =0 ; queue < rx_count; queue++) { -struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; - -for (i =0 ; i < priv->dma_rx_size; i++) { -struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i]; -struct dma_desc *p; - -if (priv->extend_desc) - p = &((rx_q->dma_erx + i)->basic); -else - p = rx_q->dma_rx + i; - -if (!buf->page) { - buf->page =page_pool_dev_alloc_pages (rx_q->page_pool); -if (!buf->page) - goto err_reinit_rx_buffers; - - buf->addr =page_pool_get_dma_addr (buf->page) + - buf->page_offset; - } - -if (priv->sph && !buf->sec_page) { - buf->sec_page =page_pool_dev_alloc_pages (rx_q->page_pool); -if (!buf->sec_page) - goto err_reinit_rx_buffers; - - buf->sec_addr =page_pool_get_dma_addr (buf->sec_page); - } +int ret; -stmmac_set_desc_addr (priv, p, buf->addr); -if (priv->sph) -stmmac_set_desc_sec_addr (priv, p, buf->sec_addr, true); -else -stmmac_set_desc_sec_addr (priv, p, buf->sec_addr, false); -if (priv->dma_buf_sz == BUF_SIZE_16KiB) -stmmac_init_desc3 (priv, p); - } + ret =stmmac_alloc_rx_buffers (priv, queue,GFP_KERNEL ); +if (ret <0 ) + goto err_reinit_rx_buffers; }return ;
@@ -1791,153 +1761,173 @@ static void stmmac_free_tx_skbufs(struct stmmac_priv *priv) }/** -* free_dma_rx_desc_resources - free RX dma desc resources +* __free_dma_rx_desc_resources - free RX dma desc resources (per queue) * @priv: private structure +* @queue: RX queue index */ -static void free_dma_rx_desc_resources (struct stmmac_priv *priv) +static void __free_dma_rx_desc_resources (struct stmmac_priv *priv,u32 queue) { -u32 rx_count = priv->plat->rx_queues_to_use; -u32 queue; +struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; -/* Free RX queue resources */ -for (queue =0 ; queue < rx_count; queue++) { -struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +/* Release the DMA RX socket buffers */ +dma_free_rx_skbufs (priv, queue); -/* Release the DMA RX socket buffers */ -dma_free_rx_skbufs (priv, queue); +/* Free DMA regions of consistent memory previously allocated */ +if (!priv->extend_desc) +dma_free_coherent (priv->device, priv->dma_rx_size * +sizeof (struct dma_desc ), + rx_q->dma_rx, rx_q->dma_rx_phy); +else +dma_free_coherent (priv->device, priv->dma_rx_size * +sizeof (struct dma_extended_desc ), + rx_q->dma_erx, rx_q->dma_rx_phy); -/* Free DMA regions of consistent memory previously allocated */ -if (!priv->extend_desc) -dma_free_coherent (priv->device, priv->dma_rx_size * -sizeof (struct dma_desc ), - rx_q->dma_rx, rx_q->dma_rx_phy); -else -dma_free_coherent (priv->device, priv->dma_rx_size * -sizeof (struct dma_extended_desc ), - rx_q->dma_erx, rx_q->dma_rx_phy); +if (xdp_rxq_info_is_reg (&rx_q->xdp_rxq)) +xdp_rxq_info_unreg (&rx_q->xdp_rxq); -if (xdp_rxq_info_is_reg (&rx_q->xdp_rxq)) -xdp_rxq_info_unreg (&rx_q->xdp_rxq); +kfree (rx_q->buf_pool); +if (rx_q->page_pool) +page_pool_destroy (rx_q->page_pool); +} -kfree (rx_q->buf_pool); -if (rx_q->page_pool) -page_pool_destroy (rx_q->page_pool); - } +static void free_dma_rx_desc_resources (struct stmmac_priv *priv) +{ +u32 rx_count = priv->plat->rx_queues_to_use; +u32 queue; + +/* Free RX queue resources */ +for (queue =0 ; queue < rx_count; queue++) +__free_dma_rx_desc_resources (priv, queue); }/** -* free_dma_tx_desc_resources - free TX dma desc resources +* __free_dma_tx_desc_resources - free TX dma desc resources (per queue) * @priv: private structure +* @queue: TX queue index */ -static void free_dma_tx_desc_resources (struct stmmac_priv *priv) +static void __free_dma_tx_desc_resources (struct stmmac_priv *priv,u32 queue) { -u32 tx_count = priv->plat->tx_queues_to_use; -u32 queue; +struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; +size_t size; +void *addr; -/* Free TX queue resources */ -for (queue =0 ; queue < tx_count; queue++) { -struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; -size_t size; -void *addr; +/* Release the DMA TX socket buffers */ +dma_free_tx_skbufs (priv, queue); + +if (priv->extend_desc) { + size =sizeof (struct dma_extended_desc ); + addr = tx_q->dma_etx; + }else if (tx_q->tbs &STMMAC_TBS_AVAIL ) { + size =sizeof (struct dma_edesc ); + addr = tx_q->dma_entx; + }else { + size =sizeof (struct dma_desc ); + addr = tx_q->dma_tx; + } -/* Release the DMA TX socket buffers */ -dma_free_tx_skbufs (priv, queue); + size *= priv->dma_tx_size; -if (priv->extend_desc) { - size =sizeof (struct dma_extended_desc ); - addr = tx_q->dma_etx; - }else if (tx_q->tbs &STMMAC_TBS_AVAIL ) { - size =sizeof (struct dma_edesc ); - addr = tx_q->dma_entx; - }else { - size =sizeof (struct dma_desc ); - addr = tx_q->dma_tx; - } +dma_free_coherent (priv->device, size, addr, tx_q->dma_tx_phy); - size *= priv->dma_tx_size; +kfree (tx_q->tx_skbuff_dma); +kfree (tx_q->tx_skbuff); +} -dma_free_coherent (priv->device, size, addr, tx_q->dma_tx_phy); +static void free_dma_tx_desc_resources (struct stmmac_priv *priv) +{ +u32 tx_count = priv->plat->tx_queues_to_use; +u32 queue; -kfree (tx_q->tx_skbuff_dma); -kfree (tx_q->tx_skbuff); - } +/* Free TX queue resources */ +for (queue =0 ; queue < tx_count; queue++) +__free_dma_tx_desc_resources (priv, queue); }/** -* alloc_dma_rx_desc_resources - alloc RX resources. +* __alloc_dma_rx_desc_resources - alloc RX resources (per queue). * @priv: private structure +* @queue: RX queue index * Description: according to which descriptor can be used (extend or basic) * this function allocates the resources for TX and RX paths. In case of * reception, for example, it pre-allocated the RX socket buffer in order to * allow zero-copy mechanism. */ -static int alloc_dma_rx_desc_resources (struct stmmac_priv *priv) +static int __alloc_dma_rx_desc_resources (struct stmmac_priv *priv,u32 queue) { +struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +struct stmmac_channel *ch = &priv->channel[queue];bool xdp_prog =stmmac_xdp_is_enabled (priv); -u32 rx_count = priv->plat->rx_queues_to_use; -int ret = -ENOMEM ; -u32 queue; +struct page_pool_params pp_params = {0 }; +unsigned int num_pages; +int ret; -/* RX queues buffers and DMA */ -for (queue =0 ; queue < rx_count; queue++) { -struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; -struct stmmac_channel *ch = &priv->channel[queue]; -struct page_pool_params pp_params = {0 }; -unsigned int num_pages; -int ret; + rx_q->queue_index = queue; + rx_q->priv_data = priv; + + pp_params.flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; + pp_params.pool_size = priv->dma_rx_size; + num_pages =DIV_ROUND_UP (priv->dma_buf_sz,PAGE_SIZE ); + pp_params.order =ilog2 (num_pages); + pp_params.nid =dev_to_node (priv->device); + pp_params.dev = priv->device; + pp_params.dma_dir = xdp_prog ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ; + pp_params.offset =stmmac_rx_offset (priv); + pp_params.max_len =STMMAC_MAX_RX_BUF_SIZE (num_pages); + + rx_q->page_pool =page_pool_create (&pp_params); +if (IS_ERR (rx_q->page_pool)) { + ret =PTR_ERR (rx_q->page_pool); + rx_q->page_pool =NULL ; +return ret; + } - rx_q->queue_index = queue; - rx_q->priv_data = priv; - - pp_params.flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; - pp_params.pool_size = priv->dma_rx_size; - num_pages =DIV_ROUND_UP (priv->dma_buf_sz,PAGE_SIZE ); - pp_params.order =ilog2 (num_pages); - pp_params.nid =dev_to_node (priv->device); - pp_params.dev = priv->device; - pp_params.dma_dir = xdp_prog ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ; - pp_params.offset =stmmac_rx_offset (priv); - pp_params.max_len =STMMAC_MAX_RX_BUF_SIZE (num_pages); - - rx_q->page_pool =page_pool_create (&pp_params); -if (IS_ERR (rx_q->page_pool)) { - ret =PTR_ERR (rx_q->page_pool); - rx_q->page_pool =NULL ; - goto err_dma; - } + rx_q->buf_pool =kcalloc (priv->dma_rx_size, +sizeof (*rx_q->buf_pool), +GFP_KERNEL ); +if (!rx_q->buf_pool) +return -ENOMEM ; - rx_q->buf_pool =kcalloc (priv->dma_rx_size, -sizeof (*rx_q->buf_pool), -GFP_KERNEL ); -if (!rx_q->buf_pool) - goto err_dma; +if (priv->extend_desc) { + rx_q->dma_erx =dma_alloc_coherent (priv->device, + priv->dma_rx_size * +sizeof (struct dma_extended_desc ), + &rx_q->dma_rx_phy, +GFP_KERNEL ); +if (!rx_q->dma_erx) +return -ENOMEM ; -if (priv->extend_desc) { - rx_q->dma_erx =dma_alloc_coherent (priv->device, - priv->dma_rx_size * -sizeof (struct dma_extended_desc ), - &rx_q->dma_rx_phy, -GFP_KERNEL ); -if (!rx_q->dma_erx) - goto err_dma; + }else { + rx_q->dma_rx =dma_alloc_coherent (priv->device, + priv->dma_rx_size * +sizeof (struct dma_desc ), + &rx_q->dma_rx_phy, +GFP_KERNEL ); +if (!rx_q->dma_rx) +return -ENOMEM ; + } - }else { - rx_q->dma_rx =dma_alloc_coherent (priv->device, - priv->dma_rx_size * -sizeof (struct dma_desc ), - &rx_q->dma_rx_phy, -GFP_KERNEL ); -if (!rx_q->dma_rx) - goto err_dma; - } + ret =xdp_rxq_info_reg (&rx_q->xdp_rxq, priv->dev, + rx_q->queue_index, + ch->rx_napi.napi_id); +if (ret) { +netdev_err (priv->dev,"Failed to register xdp rxq info\n" ); +return -EINVAL ; + } - ret =xdp_rxq_info_reg (&rx_q->xdp_rxq, priv->dev, - rx_q->queue_index, - ch->rx_napi.napi_id); -if (ret) { -netdev_err (priv->dev,"Failed to register xdp rxq info\n" ); +return 0 ; +} + +static int alloc_dma_rx_desc_resources (struct stmmac_priv *priv) +{ +u32 rx_count = priv->plat->rx_queues_to_use; +u32 queue; +int ret; + +/* RX queues buffers and DMA */ +for (queue =0 ; queue < rx_count; queue++) { + ret =__alloc_dma_rx_desc_resources (priv, queue); +if (ret) goto err_dma; - } }return 0 ;
@@ -1949,60 +1939,70 @@ static int alloc_dma_rx_desc_resources(struct stmmac_priv *priv) }/** -* alloc_dma_tx_desc_resources - alloc TX resources. +* __alloc_dma_tx_desc_resources - alloc TX resources (per queue). * @priv: private structure +* @queue: TX queue index * Description: according to which descriptor can be used (extend or basic) * this function allocates the resources for TX and RX paths. In case of * reception, for example, it pre-allocated the RX socket buffer in order to * allow zero-copy mechanism. */ -static int alloc_dma_tx_desc_resources (struct stmmac_priv *priv) +static int __alloc_dma_tx_desc_resources (struct stmmac_priv *priv,u32 queue) { -u32 tx_count = priv->plat->tx_queues_to_use; -int ret = -ENOMEM ; -u32 queue; +struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; +size_t size; +void *addr; -/* TX queues buffers and DMA */ -for (queue =0 ; queue < tx_count; queue++) { -struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; -size_t size; -void *addr; + tx_q->queue_index = queue; + tx_q->priv_data = priv; - tx_q->queue_index = queue; - tx_q->priv_data = priv; + tx_q->tx_skbuff_dma =kcalloc (priv->dma_tx_size, +sizeof (*tx_q->tx_skbuff_dma), +GFP_KERNEL ); +if (!tx_q->tx_skbuff_dma) +return -ENOMEM ; - tx_q->tx_skbuff_dma =kcalloc (priv->dma_tx_size, -sizeof (*tx_q->tx_skbuff_dma), -GFP_KERNEL ); -if (!tx_q->tx_skbuff_dma) - goto err_dma; + tx_q->tx_skbuff =kcalloc (priv->dma_tx_size, +sizeof (struct sk_buff *), +GFP_KERNEL ); +if (!tx_q->tx_skbuff) +return -ENOMEM ; - tx_q->tx_skbuff =kcalloc (priv->dma_tx_size, -sizeof (struct sk_buff *), -GFP_KERNEL ); -if (!tx_q->tx_skbuff) - goto err_dma; +if (priv->extend_desc) + size =sizeof (struct dma_extended_desc ); +else if (tx_q->tbs &STMMAC_TBS_AVAIL ) + size =sizeof (struct dma_edesc ); +else + size =sizeof (struct dma_desc ); -if (priv->extend_desc) - size =sizeof (struct dma_extended_desc ); -else if (tx_q->tbs &STMMAC_TBS_AVAIL ) - size =sizeof (struct dma_edesc ); -else - size =sizeof (struct dma_desc ); + size *= priv->dma_tx_size; - size *= priv->dma_tx_size; + addr =dma_alloc_coherent (priv->device, size, + &tx_q->dma_tx_phy,GFP_KERNEL ); +if (!addr) +return -ENOMEM ; - addr =dma_alloc_coherent (priv->device, size, - &tx_q->dma_tx_phy,GFP_KERNEL ); -if (!addr) - goto err_dma; +if (priv->extend_desc) + tx_q->dma_etx = addr; +else if (tx_q->tbs &STMMAC_TBS_AVAIL ) + tx_q->dma_entx = addr; +else + tx_q->dma_tx = addr; -if (priv->extend_desc) - tx_q->dma_etx = addr; -else if (tx_q->tbs &STMMAC_TBS_AVAIL ) - tx_q->dma_entx = addr; -else - tx_q->dma_tx = addr; +return 0 ; +} + +static int alloc_dma_tx_desc_resources (struct stmmac_priv *priv) +{ +u32 tx_count = priv->plat->tx_queues_to_use; +u32 queue; +int ret; + +/* TX queues buffers and DMA */ +for (queue =0 ; queue < tx_count; queue++) { + ret =__alloc_dma_tx_desc_resources (priv, queue); +if (ret) + goto err_dma; }return 0 ;
Signature · 1 line
2.25.1
PATCH v2 4/7 net: stmmac: rearrange RX and TX desc init into per-queue basis
In reply to Ong Boon LeongBelow functions are made to be per-queue in preparation of XDP ZC:
__init_dma_rx_desc_rings(struct stmmac_priv *priv, u32 queue, gfp_t flags) __init_dma_tx_desc_rings(struct stmmac_priv *priv, u32 queue)
The original functions below are stay maintained for all queue usage:
init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) init_dma_tx_desc_rings(struct net_device *dev)
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 180 ++++++++++-------- 1 file changed, 100 insertions(+), 80 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +100 -80
@@ -1575,60 +1575,70 @@ static void stmmac_reinit_rx_buffers(struct stmmac_priv *priv) }/** -* init_dma_rx_desc_rings - init the RX descriptor rings -* @dev: net device structure +* __init_dma_rx_desc_rings - init the RX descriptor ring (per queue) +* @priv: driver private structure +* @queue: RX queue index * @flags: gfp flag. * Description: this function initializes the DMA RX descriptors * and allocates the socket buffers. It supports the chained and ring * modes. */ -static int init_dma_rx_desc_rings (struct net_device *dev,gfp_t flags) +static int __init_dma_rx_desc_rings (struct stmmac_priv *priv,u32 queue,gfp_t flags) { -struct stmmac_priv *priv =netdev_priv (dev); -u32 rx_count = priv->plat->rx_queues_to_use; -int ret = -ENOMEM ; -int queue; +struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +int ret; -/* RX INITIALIZATION */ netif_dbg (priv, probe, priv->dev, -"SKB addresses:\nskb\t\tskb data\tdma data\n" ); +"(%s) dma_rx_phy=0x%08x\n" , __func__, + (u32 )rx_q->dma_rx_phy); -for (queue =0 ; queue < rx_count; queue++) { -struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +stmmac_clear_rx_descriptors (priv, queue); +WARN_ON (xdp_rxq_info_reg_mem_model (&rx_q->xdp_rxq, +MEM_TYPE_PAGE_POOL , + rx_q->page_pool)); -netif_dbg (priv, probe, priv->dev, -"(%s) dma_rx_phy=0x%08x\n" , __func__, - (u32 )rx_q->dma_rx_phy); +netdev_info (priv->dev, +"Register MEM_TYPE_PAGE_POOL RxQ-%d\n" , + rx_q->queue_index); -stmmac_clear_rx_descriptors (priv, queue); + ret =stmmac_alloc_rx_buffers (priv, queue, flags); +if (ret <0 ) +return -ENOMEM ; -WARN_ON (xdp_rxq_info_reg_mem_model (&rx_q->xdp_rxq, -MEM_TYPE_PAGE_POOL , - rx_q->page_pool)); + rx_q->cur_rx =0 ; + rx_q->dirty_rx =0 ; -netdev_info (priv->dev, -"Register MEM_TYPE_PAGE_POOL RxQ-%d\n" , - rx_q->queue_index); +/* Setup the chained descriptor addresses */ +if (priv->mode ==STMMAC_CHAIN_MODE ) { +if (priv->extend_desc) +stmmac_mode_init (priv, rx_q->dma_erx, + rx_q->dma_rx_phy, + priv->dma_rx_size,1 ); +else +stmmac_mode_init (priv, rx_q->dma_rx, + rx_q->dma_rx_phy, + priv->dma_rx_size,0 ); + } - ret =stmmac_alloc_rx_buffers (priv, queue, flags); -if (ret <0 ) - goto err_init_rx_buffers; +return 0 ; +} - rx_q->cur_rx =0 ; - rx_q->dirty_rx =0 ; +static int init_dma_rx_desc_rings (struct net_device *dev,gfp_t flags) +{ +struct stmmac_priv *priv =netdev_priv (dev); +u32 rx_count = priv->plat->rx_queues_to_use; +u32 queue; +int ret; -/* Setup the chained descriptor addresses */ -if (priv->mode ==STMMAC_CHAIN_MODE ) { -if (priv->extend_desc) -stmmac_mode_init (priv, rx_q->dma_erx, - rx_q->dma_rx_phy, - priv->dma_rx_size,1 ); -else -stmmac_mode_init (priv, rx_q->dma_rx, - rx_q->dma_rx_phy, - priv->dma_rx_size,0 ); - } +/* RX INITIALIZATION */ +netif_dbg (priv, probe, priv->dev, +"SKB addresses:\nskb\t\tskb data\tdma data\n" ); + +for (queue =0 ; queue < rx_count; queue++) { + ret =__init_dma_rx_desc_rings (priv, queue, flags); +if (ret) + goto err_init_rx_buffers; }return 0 ;
@@ -1647,63 +1657,73 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) }/** -* init_dma_tx_desc_rings - init the TX descriptor rings -* @dev: net device structure. +* __init_dma_tx_desc_rings - init the TX descriptor ring (per queue) +* @priv: driver private structure +* @queue : TX queue index * Description: this function initializes the DMA TX descriptors * and allocates the socket buffers. It supports the chained and ring * modes. */ -static int init_dma_tx_desc_rings (struct net_device *dev) +static int __init_dma_tx_desc_rings (struct stmmac_priv *priv,u32 queue) { -struct stmmac_priv *priv =netdev_priv (dev); -u32 tx_queue_cnt = priv->plat->tx_queues_to_use; -u32 queue; +struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];int i; -for (queue =0 ; queue < tx_queue_cnt; queue++) { -struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; - -netif_dbg (priv, probe, priv->dev, -"(%s) dma_tx_phy=0x%08x\n" , __func__, - (u32 )tx_q->dma_tx_phy); - -/* Setup the chained descriptor addresses */ -if (priv->mode ==STMMAC_CHAIN_MODE ) { -if (priv->extend_desc) -stmmac_mode_init (priv, tx_q->dma_etx, - tx_q->dma_tx_phy, - priv->dma_tx_size,1 ); -else if (!(tx_q->tbs &STMMAC_TBS_AVAIL )) -stmmac_mode_init (priv, tx_q->dma_tx, - tx_q->dma_tx_phy, - priv->dma_tx_size,0 ); - } +netif_dbg (priv, probe, priv->dev, +"(%s) dma_tx_phy=0x%08x\n" , __func__, + (u32 )tx_q->dma_tx_phy); -for (i =0 ; i < priv->dma_tx_size; i++) { -struct dma_desc *p; -if (priv->extend_desc) - p = &((tx_q->dma_etx + i)->basic); -else if (tx_q->tbs &STMMAC_TBS_AVAIL ) - p = &((tx_q->dma_entx + i)->basic); -else - p = tx_q->dma_tx + i; +/* Setup the chained descriptor addresses */ +if (priv->mode ==STMMAC_CHAIN_MODE ) { +if (priv->extend_desc) +stmmac_mode_init (priv, tx_q->dma_etx, + tx_q->dma_tx_phy, + priv->dma_tx_size,1 ); +else if (!(tx_q->tbs &STMMAC_TBS_AVAIL )) +stmmac_mode_init (priv, tx_q->dma_tx, + tx_q->dma_tx_phy, + priv->dma_tx_size,0 ); + } -stmmac_clear_desc (priv, p); +for (i =0 ; i < priv->dma_tx_size; i++) { +struct dma_desc *p; - tx_q->tx_skbuff_dma[i].buf =0 ; - tx_q->tx_skbuff_dma[i].map_as_page = false; - tx_q->tx_skbuff_dma[i].len =0 ; - tx_q->tx_skbuff_dma[i].last_segment = false; - tx_q->tx_skbuff[i] =NULL ; - } +if (priv->extend_desc) + p = &((tx_q->dma_etx + i)->basic); +else if (tx_q->tbs &STMMAC_TBS_AVAIL ) + p = &((tx_q->dma_entx + i)->basic); +else + p = tx_q->dma_tx + i; - tx_q->dirty_tx =0 ; - tx_q->cur_tx =0 ; - tx_q->mss =0 ; +stmmac_clear_desc (priv, p); -netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, queue)); + tx_q->tx_skbuff_dma[i].buf =0 ; + tx_q->tx_skbuff_dma[i].map_as_page = false; + tx_q->tx_skbuff_dma[i].len =0 ; + tx_q->tx_skbuff_dma[i].last_segment = false; + tx_q->tx_skbuff[i] =NULL ; } + tx_q->dirty_tx =0 ; + tx_q->cur_tx =0 ; + tx_q->mss =0 ; + +netdev_tx_reset_queue (netdev_get_tx_queue (priv->dev, queue)); + +return 0 ; +} + +static int init_dma_tx_desc_rings (struct net_device *dev) +{ +struct stmmac_priv *priv =netdev_priv (dev); +u32 tx_queue_cnt; +u32 queue; + + tx_queue_cnt = priv->plat->tx_queues_to_use; + +for (queue =0 ; queue < tx_queue_cnt; queue++) +__init_dma_tx_desc_rings (priv, queue); +return 0 ; }
Signature · 1 line
2.25.1
PATCH v2 5/7 net: stmmac: Refactor __stmmac_xdp_run_prog for XDP ZC
In reply to Ong Boon LeongPrepare stmmac_xdp_run_prog() for AF_XDP zero-copy support which will be added by upcoming patches by splitting out the XDP verdict processing into __stmmac_xdp_run_prog() and it callable for XDP ZC path which does not need to verify bpf_prog is not NULL.
The stmmac_xdp_run_prog() is used for regular XDP Rx path which requires bpf_prog to be verified.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +23 -12
@@ -4408,20 +4408,13 @@ static int stmmac_xdp_xmit_back(struct stmmac_priv *priv,return res; } -static struct sk_buff *stmmac_xdp_run_prog (struct stmmac_priv *priv, -struct xdp_buff *xdp) +/* This function assumes rcu_read_lock() is held by the caller. */ +static int __stmmac_xdp_run_prog (struct stmmac_priv *priv, +struct bpf_prog *prog, +struct xdp_buff *xdp) { -struct bpf_prog *prog; -int res;u32 act; - -rcu_read_lock (); - - prog =READ_ONCE (priv->xdp_prog); -if (!prog) { - res =STMMAC_XDP_PASS ; - goto unlock; - } +int res; act =bpf_prog_run_xdp (prog, xdp);switch (act) {
@@ -4448,6 +4441,24 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,break ; } +return res; +} + +static struct sk_buff *stmmac_xdp_run_prog (struct stmmac_priv *priv, +struct xdp_buff *xdp) +{ +struct bpf_prog *prog; +int res; + +rcu_read_lock (); + + prog =READ_ONCE (priv->xdp_prog); +if (!prog) { + res =STMMAC_XDP_PASS ; + goto unlock; + } + + res =__stmmac_xdp_run_prog (priv, prog, xdp); unlock:rcu_read_unlock ();return ERR_PTR (-res);
Signature · 1 line
2.25.1
PATCH v2 6/7 net: stmmac: Enable RX via AF_XDP zero-copy
In reply to Ong Boon LeongThis patch adds the support for receiving packet via AF_XDP zero-copy mechanism.
XDP ZC uses 1:1 mapping of XDP buffer to receive packet, therefore the use of split header is not used currently. The 'xdp_buff' is declared as union together with a struct that contains 'page', 'addr' and 'page_offset' that are associated with primary buffer.
RX buffers are now allocated either via page_pool or xsk pool. For RX buffers from xsk_pool they are allocated and deallocated using below functions:
* stmmac_alloc_rx_buffers_zc(struct stmmac_priv *priv, u32 queue)
* dma_free_rx_xskbufs(struct stmmac_priv *priv, u32 queue)
With above functions now available, we then extend the following driver functions to support XDP ZC:
* stmmac_reinit_rx_buffers()
* __init_dma_rx_desc_rings()
* init_dma_rx_desc_rings()
* __free_dma_rx_desc_resources()
Note: stmmac_alloc_rx_buffers_zc() may return -ENOMEM due to RX XDP buffer pool is not allocated (e.g. samples/bpf/xdpsock TX-only). But, it is still ok to let TX XDP ZC to continue, therefore, the -ENOMEM is silently ignored to let the driver succcessfully transition to XDP ZC mode for the said RX and TX queue.
As XDP ZC buffer size is different, the DMA buffer size is required to be reprogrammed accordingly for RX DMA/Queue that is populated with XDP buffer from XSK pool.
Next, to add or remove per-queue XSK pool, stmmac_xdp_setup_pool() will call stmmac_xdp_enable_pool() or stmmac_xdp_disable_pool() that in-turn coordinates the tearing down and setting up RX ring via RX buffers and descriptors removal and reallocation through stmmac_disable_rx_queue() and stmmac_enable_rx_queue(). In addition, stmmac_xsk_wakeup() is added to initiate XDP RX buffer replenishing by signalling user application to add available XDP frames back to FILL queue.
For RX processing using XDP zero-copy buffer, stmmac_rx_zc() is introduced which is implemented with the assumption that RX split header is disabled. For XDP verdict is XDP_PASS, the XDP buffer is copied into a sk_buff allocated through stmmac_construct_skb_zc() and sent to Linux network GRO inside stmmac_dispatch_skb_zc(). Free RX buffers are then replenished using stmmac_rx_refill_zc()
v2: introduce __stmmac_disable_all_queues() to contain the original code
that does napi_disable() and then make stmmac_setup_tc_block_cb() to use it. Move synchronize_rcu() into stmmac_disable_all_queues() that eventually calls __stmmac_disable_all_queues(). Then, make both stmmac_release() and stmmac_suspend() to use stmmac_disable_all_queues(). Thanks David Miller for spotting the synchronize_rcu() issue in v1 patch.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 18 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 600 +++++++++++++++++- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 87 +++ .../net/ethernet/stmicro/stmmac/stmmac_xdp.h | 3 + 4 files changed, 679 insertions(+), 29 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +15 -3
@@ -77,9 +77,14 @@ struct stmmac_tx_queue { };struct stmmac_rx_buffer { -struct page *page; -dma_addr_t addr; -__u32 page_offset; +union { +struct { +struct page *page; +dma_addr_t addr; +__u32 page_offset; + }; +struct xdp_buff *xdp; + };struct page *sec_page;dma_addr_t sec_addr; };
@@ -88,6 +93,7 @@ struct stmmac_rx_queue {u32 rx_count_frames;u32 queue_index;struct xdp_rxq_info xdp_rxq; +struct xsk_buff_pool *xsk_pool;struct page_pool *page_pool;struct stmmac_rx_buffer *buf_pool;struct stmmac_priv *priv_data;
@@ -95,6 +101,7 @@ struct stmmac_rx_queue {struct dma_desc *dma_rx____cacheline_aligned_in_smp ;unsigned int cur_rx;unsigned int dirty_rx; +unsigned int buf_alloc_num;u32 rx_zeroc_thresh;dma_addr_t dma_rx_phy;u32 rx_tail_addr;
@@ -283,6 +290,7 @@ struct stmmac_priv {struct stmmac_rss rss;/* XDP BPF Program */ +unsigned long *af_xdp_zc_qps;struct bpf_prog *xdp_prog; };
@@ -328,6 +336,10 @@ static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)return 0 ; } +void stmmac_disable_rx_queue (struct stmmac_priv *priv,u32 queue); +void stmmac_enable_rx_queue (struct stmmac_priv *priv,u32 queue); +int stmmac_xsk_wakeup (struct net_device *dev,u32 queue,u32 flags); +#if IS_ENABLED (CONFIG_STMMAC_SELFTESTS )void stmmac_selftest_run (struct net_device *dev,struct ethtool_test *etest,u64 *buf);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +574 -26
735 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c +87 -0
96 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h +3 -0
@@ -5,7 +5,10 @@#define _STMMAC_XDP_H_#define STMMAC_MAX_RX_BUF_SIZE (num) (((num) * PAGE_SIZE) - XDP_PACKET_HEADROOM) +#define STMMAC_RX_DMA_ATTR (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) +int stmmac_xdp_setup_pool (struct stmmac_priv *priv,struct xsk_buff_pool *pool, +u16 queue);int stmmac_xdp_set_prog (struct stmmac_priv *priv,struct bpf_prog *prog,struct netlink_ext_ack *extack);
Signature · 1 line
2.25.1
PATCH v2 7/7 net: stmmac: Add TX via XDP zero-copy socket
In reply to Ong Boon LeongWe add the support of XDP ZC TX submission and cleaning into stmmac_tx_clean(). The function is made to clean as many TX complete frames as possible, i.e. limit by priv->dma_tx_size instead of NAPI budget. For TX ring that is associated with XSK pool, the function stmmac_xdp_xmit_zc() is introduced to TX frame buffers from XSK pool by using xsk_tx_peek_desc(). To make stmmac_tx_clean() support the cleaning of XSK TX frames, STMMAC_TXBUF_T_XSK_TX TX buffer type is introduced.
As stmmac_tx_clean() uses the return value to cue whether NAPI function should continue to poll, we augment the caller of stmmac_tx_clean() to pass NAPI budget instead of priv->dma_tx_size through 'budget' input and made stmmac_tx_clean() to always clean up-to the TX ring size instead. This allows us to use the return boolean status of stmmac_xdp_xmit_zc() to decide if XSK TX work is done or not: If true, set 'xmits' to return 'budget - 1' so that NAPI poll may exit. Else, set 'xmits' to return 'budget' to make NAPI poll continue to poll since XSK TX work is not done. Finally, at the end of stmmac_tx_clean(), the function now take a maximum value between 'count' and 'xmits' so that status from both TX cleaning and XSK TX (only for XDP ZC) is considered.
This patch adds a new NAPI poll called stmmac_napi_poll_rxtx() that is meant to be enabled/disabled for RX and TX ring that are bound to XSK pool. This NAPI poll function starts with cleaning TX ring, then submits XSK TX frames to TX ring before proceed to perform RX operations, i.e. , receiving RX frames and replenishing RX ring with RX free buffers obtained from XSK pool. Therefore, during XSK RX and TX setup, the driver enables stmmac_napi_poll_rxtx() for RX and TX operations, then during XSK RX and TX pool tear-down, the driver reenables the exisiting independent NAPI poll functions accordingly: stmmac_napi_poll_rx() and stmmac_napi_poll_tx().
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 6 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 317 ++++++++++++++++-- .../net/ethernet/stmicro/stmmac/stmmac_xdp.c | 16 +- 3 files changed, 310 insertions(+), 29 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +6 -0
@@ -40,6 +40,7 @@ enum stmmac_txbuf_type {STMMAC_TXBUF_T_SKB ,STMMAC_TXBUF_T_XDP_TX ,STMMAC_TXBUF_T_XDP_NDO , + STMMAC_TXBUF_T_XSK_TX, }; struct stmmac_tx_info {
@@ -69,6 +70,8 @@ struct stmmac_tx_queue {struct xdp_frame **xdpf; };struct stmmac_tx_info *tx_skbuff_dma; +struct xsk_buff_pool *xsk_pool; +u32 xsk_frames_done;unsigned int cur_tx;unsigned int dirty_tx;dma_addr_t dma_tx_phy;
@@ -116,6 +119,7 @@ struct stmmac_rx_queue {struct stmmac_channel {struct napi_struct rx_napi____cacheline_aligned_in_smp ;struct napi_struct tx_napi____cacheline_aligned_in_smp ; +struct napi_struct rxtx_napi____cacheline_aligned_in_smp ;struct stmmac_priv *priv_data;spinlock_t lock;u32 index;
@@ -338,6 +342,8 @@ static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)void stmmac_disable_rx_queue (struct stmmac_priv *priv,u32 queue);void stmmac_enable_rx_queue (struct stmmac_priv *priv,u32 queue); +void stmmac_disable_tx_queue (struct stmmac_priv *priv,u32 queue); +void stmmac_enable_tx_queue (struct stmmac_priv *priv,u32 queue);int stmmac_xsk_wakeup (struct net_device *dev,u32 queue,u32 flags);#if IS_ENABLED (CONFIG_STMMAC_SELFTESTS )
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +292 -25
520 lines not on this page · raw message
drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.c +12 -4
@@ -14,7 +14,8 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv,u32 frame_size;int err; -if (queue >= priv->plat->rx_queues_to_use) +if (queue >= priv->plat->rx_queues_to_use || + queue >= priv->plat->tx_queues_to_use)return -EINVAL ; frame_size =xsk_pool_get_rx_frame_size (pool);
@@ -34,14 +35,17 @@ static int stmmac_xdp_enable_pool(struct stmmac_priv *priv,if (need_update) {stmmac_disable_rx_queue (priv, queue); +stmmac_disable_tx_queue (priv, queue);napi_disable (&ch->rx_napi); +napi_disable (&ch->tx_napi); }set_bit (queue, priv->af_xdp_zc_qps);if (need_update) { -napi_enable (&ch->rx_napi); +napi_enable (&ch->rxtx_napi);stmmac_enable_rx_queue (priv, queue); +stmmac_enable_tx_queue (priv, queue); err =stmmac_xsk_wakeup (priv->dev, queue,XDP_WAKEUP_RX );if (err)
@@ -57,7 +61,8 @@ static int stmmac_xdp_disable_pool(struct stmmac_priv *priv, u16 queue)struct xsk_buff_pool *pool;bool need_update; -if (queue >= priv->plat->rx_queues_to_use) +if (queue >= priv->plat->rx_queues_to_use || + queue >= priv->plat->tx_queues_to_use)return -EINVAL ; pool =xsk_get_pool_from_qid (priv->dev, queue);
@@ -68,8 +73,9 @@ static int stmmac_xdp_disable_pool(struct stmmac_priv *priv, u16 queue)if (need_update) {stmmac_disable_rx_queue (priv, queue); +stmmac_disable_tx_queue (priv, queue);synchronize_rcu (); -napi_disable (&ch->rx_napi); +napi_disable (&ch->rxtx_napi); }xsk_pool_dma_unmap (pool,STMMAC_RX_DMA_ATTR );
@@ -78,7 +84,9 @@ static int stmmac_xdp_disable_pool(struct stmmac_priv *priv, u16 queue)if (need_update) {napi_enable (&ch->rx_napi); +napi_enable (&ch->tx_napi);stmmac_enable_rx_queue (priv, queue); +stmmac_enable_tx_queue (priv, queue); }return 0 ;
Signature · 1 line
2.25.1
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Tue, 13 Apr 2021 17:36:19 +0800 you wrote:
Hi,
This is the v2 patch series to add XDP ZC support to stmmac driver.
Summary of v2 patch change:-
6/7: fix
synchronize_rcu()is calledstmmac_disable_all_queues()that is
used byndo_setup_tc().[...]
Here is the summary with links:
- [net-next,v2,1/7] net: stmmac: rearrange RX buffer allocation and free functions
https://git.kernel.org/netdev/net-next/c/4298255f26fa - [net-next,v2,2/7] net: stmmac: introduce dma_recycle_rx_skbufs for stmmac_reinit_rx_buffers https://git.kernel.org/netdev/net-next/c/80f573c995fc - [net-next,v2,3/7] net: stmmac: refactor stmmac_init_rx_buffers for stmmac_reinit_rx_buffers https://git.kernel.org/netdev/net-next/c/da5ec7f22a0f - [net-next,v2,4/7] net: stmmac: rearrange RX and TX desc init into per-queue basis https://git.kernel.org/netdev/net-next/c/de0b90e52a11 - [net-next,v2,5/7] net: stmmac: Refactor __stmmac_xdp_run_prog for XDP ZC https://git.kernel.org/netdev/net-next/c/bba71cac680f - [net-next,v2,6/7] net: stmmac: Enable RX via AF_XDP zero-copy https://git.kernel.org/netdev/net-next/c/bba2556efad6 - [net-next,v2,7/7] net: stmmac: Add TX via XDP zero-copy socket https://git.kernel.org/netdev/net-next/c/132c32ee5bc0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html