Skip to content

Commit bba2556

Browse files
elvinongbldavem330
authored andcommitted
net: stmmac: Enable RX via AF_XDP zero-copy
This 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. Signed-off-by: Ong Boon Leong <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bba71ca commit bba2556

File tree

4 files changed

+679
-29
lines changed

4 files changed

+679
-29
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ struct stmmac_tx_queue {
7777
};
7878

7979
struct stmmac_rx_buffer {
80-
struct page *page;
81-
dma_addr_t addr;
82-
__u32 page_offset;
80+
union {
81+
struct {
82+
struct page *page;
83+
dma_addr_t addr;
84+
__u32 page_offset;
85+
};
86+
struct xdp_buff *xdp;
87+
};
8388
struct page *sec_page;
8489
dma_addr_t sec_addr;
8590
};
@@ -88,13 +93,15 @@ struct stmmac_rx_queue {
8893
u32 rx_count_frames;
8994
u32 queue_index;
9095
struct xdp_rxq_info xdp_rxq;
96+
struct xsk_buff_pool *xsk_pool;
9197
struct page_pool *page_pool;
9298
struct stmmac_rx_buffer *buf_pool;
9399
struct stmmac_priv *priv_data;
94100
struct dma_extended_desc *dma_erx;
95101
struct dma_desc *dma_rx ____cacheline_aligned_in_smp;
96102
unsigned int cur_rx;
97103
unsigned int dirty_rx;
104+
unsigned int buf_alloc_num;
98105
u32 rx_zeroc_thresh;
99106
dma_addr_t dma_rx_phy;
100107
u32 rx_tail_addr;
@@ -283,6 +290,7 @@ struct stmmac_priv {
283290
struct stmmac_rss rss;
284291

285292
/* XDP BPF Program */
293+
unsigned long *af_xdp_zc_qps;
286294
struct bpf_prog *xdp_prog;
287295
};
288296

@@ -328,6 +336,10 @@ static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
328336
return 0;
329337
}
330338

339+
void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
340+
void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
341+
int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
342+
331343
#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)
332344
void stmmac_selftest_run(struct net_device *dev,
333345
struct ethtool_test *etest, u64 *buf);

0 commit comments

Comments
 (0)