Skip to content

Commit 132c32e

Browse files
elvinongbldavem330
authored andcommitted
net: stmmac: Add TX via XDP zero-copy socket
We 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(). Signed-off-by: Ong Boon Leong <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bba2556 commit 132c32e

File tree

3 files changed

+310
-29
lines changed

3 files changed

+310
-29
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum stmmac_txbuf_type {
4040
STMMAC_TXBUF_T_SKB,
4141
STMMAC_TXBUF_T_XDP_TX,
4242
STMMAC_TXBUF_T_XDP_NDO,
43+
STMMAC_TXBUF_T_XSK_TX,
4344
};
4445

4546
struct stmmac_tx_info {
@@ -69,6 +70,8 @@ struct stmmac_tx_queue {
6970
struct xdp_frame **xdpf;
7071
};
7172
struct stmmac_tx_info *tx_skbuff_dma;
73+
struct xsk_buff_pool *xsk_pool;
74+
u32 xsk_frames_done;
7275
unsigned int cur_tx;
7376
unsigned int dirty_tx;
7477
dma_addr_t dma_tx_phy;
@@ -116,6 +119,7 @@ struct stmmac_rx_queue {
116119
struct stmmac_channel {
117120
struct napi_struct rx_napi ____cacheline_aligned_in_smp;
118121
struct napi_struct tx_napi ____cacheline_aligned_in_smp;
122+
struct napi_struct rxtx_napi ____cacheline_aligned_in_smp;
119123
struct stmmac_priv *priv_data;
120124
spinlock_t lock;
121125
u32 index;
@@ -338,6 +342,8 @@ static inline unsigned int stmmac_rx_offset(struct stmmac_priv *priv)
338342

339343
void stmmac_disable_rx_queue(struct stmmac_priv *priv, u32 queue);
340344
void stmmac_enable_rx_queue(struct stmmac_priv *priv, u32 queue);
345+
void stmmac_disable_tx_queue(struct stmmac_priv *priv, u32 queue);
346+
void stmmac_enable_tx_queue(struct stmmac_priv *priv, u32 queue);
341347
int stmmac_xsk_wakeup(struct net_device *dev, u32 queue, u32 flags);
342348

343349
#if IS_ENABLED(CONFIG_STMMAC_SELFTESTS)

0 commit comments

Comments
 (0)