Skip to content

Commit 80f6ccf

Browse files
sriramykuba-moo
authored andcommitted
igb: Introduce XSK data structures and helpers
Add the following ring flag: - IGB_RING_FLAG_TX_DISABLED (when xsk pool is being setup) Add a xdp_buff array for use with XSK receive batch API, and a pointer to xsk_pool in igb_adapter. Add enable/disable functions for TX and RX rings. Add enable/disable functions for XSK pool. Add xsk wakeup function. None of the above functionality will be active until NETDEV_XDP_ACT_XSK_ZEROCOPY is advertised in netdev->xdp_features. Signed-off-by: Sriram Yagnaraman <[email protected]> [Kurt: Add READ/WRITE_ONCE(), synchronize_net(), remove IGB_RING_FLAG_AF_XDP_ZC] Signed-off-by: Kurt Kanzenbach <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Tested-by: George Kuruvinakunnel <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6dc75fc commit 80f6ccf

File tree

4 files changed

+229
-2
lines changed

4 files changed

+229
-2
lines changed

drivers/net/ethernet/intel/igb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ obj-$(CONFIG_IGB) += igb.o
88

99
igb-y := igb_main.o igb_ethtool.o e1000_82575.o \
1010
e1000_mac.o e1000_nvm.o e1000_phy.o e1000_mbx.o \
11-
e1000_i210.o igb_ptp.o igb_hwmon.o
11+
e1000_i210.o igb_ptp.o igb_hwmon.o igb_xsk.o

drivers/net/ethernet/intel/igb/igb.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/lockdep.h>
2222

2323
#include <net/xdp.h>
24+
#include <net/xdp_sock_drv.h>
2425

2526
struct igb_adapter;
2627

@@ -321,6 +322,7 @@ struct igb_ring {
321322
union { /* array of buffer info structs */
322323
struct igb_tx_buffer *tx_buffer_info;
323324
struct igb_rx_buffer *rx_buffer_info;
325+
struct xdp_buff **rx_buffer_info_zc;
324326
};
325327
void *desc; /* descriptor ring memory */
326328
unsigned long flags; /* ring specific flags */
@@ -358,6 +360,7 @@ struct igb_ring {
358360
};
359361
};
360362
struct xdp_rxq_info xdp_rxq;
363+
struct xsk_buff_pool *xsk_pool;
361364
} ____cacheline_internodealigned_in_smp;
362365

363366
struct igb_q_vector {
@@ -385,7 +388,8 @@ enum e1000_ring_flags_t {
385388
IGB_RING_FLAG_RX_SCTP_CSUM,
386389
IGB_RING_FLAG_RX_LB_VLAN_BSWAP,
387390
IGB_RING_FLAG_TX_CTX_IDX,
388-
IGB_RING_FLAG_TX_DETECT_HANG
391+
IGB_RING_FLAG_TX_DETECT_HANG,
392+
IGB_RING_FLAG_TX_DISABLED
389393
};
390394

391395
#define ring_uses_large_buffer(ring) \
@@ -841,4 +845,11 @@ int igb_add_mac_steering_filter(struct igb_adapter *adapter,
841845
int igb_del_mac_steering_filter(struct igb_adapter *adapter,
842846
const u8 *addr, u8 queue, u8 flags);
843847

848+
struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,
849+
struct igb_ring *ring);
850+
int igb_xsk_pool_setup(struct igb_adapter *adapter,
851+
struct xsk_buff_pool *pool,
852+
u16 qid);
853+
int igb_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags);
854+
844855
#endif /* _IGB_H_ */

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,9 +2908,14 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
29082908

29092909
static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
29102910
{
2911+
struct igb_adapter *adapter = netdev_priv(dev);
2912+
29112913
switch (xdp->command) {
29122914
case XDP_SETUP_PROG:
29132915
return igb_xdp_setup(dev, xdp);
2916+
case XDP_SETUP_XSK_POOL:
2917+
return igb_xsk_pool_setup(adapter, xdp->xsk.pool,
2918+
xdp->xsk.queue_id);
29142919
default:
29152920
return -EINVAL;
29162921
}
@@ -3019,6 +3024,7 @@ static const struct net_device_ops igb_netdev_ops = {
30193024
.ndo_setup_tc = igb_setup_tc,
30203025
.ndo_bpf = igb_xdp,
30213026
.ndo_xdp_xmit = igb_xdp_xmit,
3027+
.ndo_xsk_wakeup = igb_xsk_wakeup,
30223028
};
30233029

30243030
/**
@@ -4341,6 +4347,8 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,
43414347
u64 tdba = ring->dma;
43424348
int reg_idx = ring->reg_idx;
43434349

4350+
WRITE_ONCE(ring->xsk_pool, igb_xsk_pool(adapter, ring));
4351+
43444352
wr32(E1000_TDLEN(reg_idx),
43454353
ring->count * sizeof(union e1000_adv_tx_desc));
43464354
wr32(E1000_TDBAL(reg_idx),
@@ -4736,6 +4744,7 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,
47364744
xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq);
47374745
WARN_ON(xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
47384746
MEM_TYPE_PAGE_SHARED, NULL));
4747+
WRITE_ONCE(ring->xsk_pool, igb_xsk_pool(adapter, ring));
47394748

47404749
/* disable the queue */
47414750
wr32(E1000_RXDCTL(reg_idx), 0);
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright(c) 2018 Intel Corporation. */
3+
4+
#include <linux/bpf_trace.h>
5+
#include <net/xdp_sock_drv.h>
6+
#include <net/xdp.h>
7+
8+
#include "e1000_hw.h"
9+
#include "igb.h"
10+
11+
static int igb_realloc_rx_buffer_info(struct igb_ring *ring, bool pool_present)
12+
{
13+
int size = pool_present ?
14+
sizeof(*ring->rx_buffer_info_zc) * ring->count :
15+
sizeof(*ring->rx_buffer_info) * ring->count;
16+
void *buff_info = vmalloc(size);
17+
18+
if (!buff_info)
19+
return -ENOMEM;
20+
21+
if (pool_present) {
22+
vfree(ring->rx_buffer_info);
23+
ring->rx_buffer_info = NULL;
24+
ring->rx_buffer_info_zc = buff_info;
25+
} else {
26+
vfree(ring->rx_buffer_info_zc);
27+
ring->rx_buffer_info_zc = NULL;
28+
ring->rx_buffer_info = buff_info;
29+
}
30+
31+
return 0;
32+
}
33+
34+
static void igb_txrx_ring_disable(struct igb_adapter *adapter, u16 qid)
35+
{
36+
struct igb_ring *tx_ring = adapter->tx_ring[qid];
37+
struct igb_ring *rx_ring = adapter->rx_ring[qid];
38+
struct e1000_hw *hw = &adapter->hw;
39+
40+
set_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
41+
42+
wr32(E1000_TXDCTL(tx_ring->reg_idx), 0);
43+
wr32(E1000_RXDCTL(rx_ring->reg_idx), 0);
44+
45+
synchronize_net();
46+
47+
/* Rx/Tx share the same napi context. */
48+
napi_disable(&rx_ring->q_vector->napi);
49+
50+
igb_clean_tx_ring(tx_ring);
51+
igb_clean_rx_ring(rx_ring);
52+
53+
memset(&rx_ring->rx_stats, 0, sizeof(rx_ring->rx_stats));
54+
memset(&tx_ring->tx_stats, 0, sizeof(tx_ring->tx_stats));
55+
}
56+
57+
static void igb_txrx_ring_enable(struct igb_adapter *adapter, u16 qid)
58+
{
59+
struct igb_ring *tx_ring = adapter->tx_ring[qid];
60+
struct igb_ring *rx_ring = adapter->rx_ring[qid];
61+
62+
igb_configure_tx_ring(adapter, tx_ring);
63+
igb_configure_rx_ring(adapter, rx_ring);
64+
65+
synchronize_net();
66+
67+
clear_bit(IGB_RING_FLAG_TX_DISABLED, &tx_ring->flags);
68+
69+
/* call igb_desc_unused which always leaves
70+
* at least 1 descriptor unused to make sure
71+
* next_to_use != next_to_clean
72+
*/
73+
igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
74+
75+
/* Rx/Tx share the same napi context. */
76+
napi_enable(&rx_ring->q_vector->napi);
77+
}
78+
79+
struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,
80+
struct igb_ring *ring)
81+
{
82+
int qid = ring->queue_index;
83+
struct xsk_buff_pool *pool;
84+
85+
pool = xsk_get_pool_from_qid(adapter->netdev, qid);
86+
87+
if (!igb_xdp_is_enabled(adapter))
88+
return NULL;
89+
90+
return (pool && pool->dev) ? pool : NULL;
91+
}
92+
93+
static int igb_xsk_pool_enable(struct igb_adapter *adapter,
94+
struct xsk_buff_pool *pool,
95+
u16 qid)
96+
{
97+
struct net_device *netdev = adapter->netdev;
98+
struct igb_ring *rx_ring;
99+
bool if_running;
100+
int err;
101+
102+
if (qid >= adapter->num_rx_queues)
103+
return -EINVAL;
104+
105+
if (qid >= netdev->real_num_rx_queues ||
106+
qid >= netdev->real_num_tx_queues)
107+
return -EINVAL;
108+
109+
err = xsk_pool_dma_map(pool, &adapter->pdev->dev, IGB_RX_DMA_ATTR);
110+
if (err)
111+
return err;
112+
113+
rx_ring = adapter->rx_ring[qid];
114+
if_running = netif_running(adapter->netdev) && igb_xdp_is_enabled(adapter);
115+
if (if_running)
116+
igb_txrx_ring_disable(adapter, qid);
117+
118+
if (if_running) {
119+
err = igb_realloc_rx_buffer_info(rx_ring, true);
120+
if (!err) {
121+
igb_txrx_ring_enable(adapter, qid);
122+
/* Kick start the NAPI context so that receiving will start */
123+
err = igb_xsk_wakeup(adapter->netdev, qid, XDP_WAKEUP_RX);
124+
}
125+
126+
if (err) {
127+
xsk_pool_dma_unmap(pool, IGB_RX_DMA_ATTR);
128+
return err;
129+
}
130+
}
131+
132+
return 0;
133+
}
134+
135+
static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)
136+
{
137+
struct xsk_buff_pool *pool;
138+
struct igb_ring *rx_ring;
139+
bool if_running;
140+
int err;
141+
142+
pool = xsk_get_pool_from_qid(adapter->netdev, qid);
143+
if (!pool)
144+
return -EINVAL;
145+
146+
rx_ring = adapter->rx_ring[qid];
147+
if_running = netif_running(adapter->netdev) && igb_xdp_is_enabled(adapter);
148+
if (if_running)
149+
igb_txrx_ring_disable(adapter, qid);
150+
151+
xsk_pool_dma_unmap(pool, IGB_RX_DMA_ATTR);
152+
153+
if (if_running) {
154+
err = igb_realloc_rx_buffer_info(rx_ring, false);
155+
if (err)
156+
return err;
157+
158+
igb_txrx_ring_enable(adapter, qid);
159+
}
160+
161+
return 0;
162+
}
163+
164+
int igb_xsk_pool_setup(struct igb_adapter *adapter,
165+
struct xsk_buff_pool *pool,
166+
u16 qid)
167+
{
168+
return pool ? igb_xsk_pool_enable(adapter, pool, qid) :
169+
igb_xsk_pool_disable(adapter, qid);
170+
}
171+
172+
int igb_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags)
173+
{
174+
struct igb_adapter *adapter = netdev_priv(dev);
175+
struct e1000_hw *hw = &adapter->hw;
176+
struct igb_ring *ring;
177+
u32 eics = 0;
178+
179+
if (test_bit(__IGB_DOWN, &adapter->state))
180+
return -ENETDOWN;
181+
182+
if (!igb_xdp_is_enabled(adapter))
183+
return -EINVAL;
184+
185+
if (qid >= adapter->num_tx_queues)
186+
return -EINVAL;
187+
188+
ring = adapter->tx_ring[qid];
189+
190+
if (test_bit(IGB_RING_FLAG_TX_DISABLED, &ring->flags))
191+
return -ENETDOWN;
192+
193+
if (!READ_ONCE(ring->xsk_pool))
194+
return -EINVAL;
195+
196+
if (!napi_if_scheduled_mark_missed(&ring->q_vector->napi)) {
197+
/* Cause software interrupt */
198+
if (adapter->flags & IGB_FLAG_HAS_MSIX) {
199+
eics |= ring->q_vector->eims_value;
200+
wr32(E1000_EICS, eics);
201+
} else {
202+
wr32(E1000_ICS, E1000_ICS_RXDMT0);
203+
}
204+
}
205+
206+
return 0;
207+
}

0 commit comments

Comments
 (0)