|
19 | 19 | #include <linux/pci.h>
|
20 | 20 | #include <linux/mdio.h>
|
21 | 21 |
|
| 22 | +#include <net/xdp.h> |
| 23 | + |
22 | 24 | struct igb_adapter;
|
23 | 25 |
|
24 | 26 | #define E1000_PCS_CFG_IGN_SD 1
|
@@ -79,6 +81,12 @@ struct igb_adapter;
|
79 | 81 | #define IGB_I210_RX_LATENCY_100 2213
|
80 | 82 | #define IGB_I210_RX_LATENCY_1000 448
|
81 | 83 |
|
| 84 | +/* XDP */ |
| 85 | +#define IGB_XDP_PASS 0 |
| 86 | +#define IGB_XDP_CONSUMED BIT(0) |
| 87 | +#define IGB_XDP_TX BIT(1) |
| 88 | +#define IGB_XDP_REDIR BIT(2) |
| 89 | + |
82 | 90 | struct vf_data_storage {
|
83 | 91 | unsigned char vf_mac_addresses[ETH_ALEN];
|
84 | 92 | u16 vf_mc_hashes[IGB_MAX_VF_MC_ENTRIES];
|
@@ -132,17 +140,62 @@ struct vf_mac_filter {
|
132 | 140 |
|
133 | 141 | /* Supported Rx Buffer Sizes */
|
134 | 142 | #define IGB_RXBUFFER_256 256
|
| 143 | +#define IGB_RXBUFFER_1536 1536 |
135 | 144 | #define IGB_RXBUFFER_2048 2048
|
136 | 145 | #define IGB_RXBUFFER_3072 3072
|
137 | 146 | #define IGB_RX_HDR_LEN IGB_RXBUFFER_256
|
138 | 147 | #define IGB_TS_HDR_LEN 16
|
139 | 148 |
|
140 |
| -#define IGB_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) |
| 149 | +/* Attempt to maximize the headroom available for incoming frames. We |
| 150 | + * use a 2K buffer for receives and need 1536/1534 to store the data for |
| 151 | + * the frame. This leaves us with 512 bytes of room. From that we need |
| 152 | + * to deduct the space needed for the shared info and the padding needed |
| 153 | + * to IP align the frame. |
| 154 | + * |
| 155 | + * Note: For cache line sizes 256 or larger this value is going to end |
| 156 | + * up negative. In these cases we should fall back to the 3K |
| 157 | + * buffers. |
| 158 | + */ |
141 | 159 | #if (PAGE_SIZE < 8192)
|
142 |
| -#define IGB_MAX_FRAME_BUILD_SKB \ |
143 |
| - (SKB_WITH_OVERHEAD(IGB_RXBUFFER_2048) - IGB_SKB_PAD - IGB_TS_HDR_LEN) |
| 160 | +#define IGB_MAX_FRAME_BUILD_SKB (IGB_RXBUFFER_1536 - NET_IP_ALIGN) |
| 161 | +#define IGB_2K_TOO_SMALL_WITH_PADDING \ |
| 162 | +((NET_SKB_PAD + IGB_TS_HDR_LEN + IGB_RXBUFFER_1536) > SKB_WITH_OVERHEAD(IGB_RXBUFFER_2048)) |
| 163 | + |
| 164 | +static inline int igb_compute_pad(int rx_buf_len) |
| 165 | +{ |
| 166 | + int page_size, pad_size; |
| 167 | + |
| 168 | + page_size = ALIGN(rx_buf_len, PAGE_SIZE / 2); |
| 169 | + pad_size = SKB_WITH_OVERHEAD(page_size) - rx_buf_len; |
| 170 | + |
| 171 | + return pad_size; |
| 172 | +} |
| 173 | + |
| 174 | +static inline int igb_skb_pad(void) |
| 175 | +{ |
| 176 | + int rx_buf_len; |
| 177 | + |
| 178 | + /* If a 2K buffer cannot handle a standard Ethernet frame then |
| 179 | + * optimize padding for a 3K buffer instead of a 1.5K buffer. |
| 180 | + * |
| 181 | + * For a 3K buffer we need to add enough padding to allow for |
| 182 | + * tailroom due to NET_IP_ALIGN possibly shifting us out of |
| 183 | + * cache-line alignment. |
| 184 | + */ |
| 185 | + if (IGB_2K_TOO_SMALL_WITH_PADDING) |
| 186 | + rx_buf_len = IGB_RXBUFFER_3072 + SKB_DATA_ALIGN(NET_IP_ALIGN); |
| 187 | + else |
| 188 | + rx_buf_len = IGB_RXBUFFER_1536; |
| 189 | + |
| 190 | + /* if needed make room for NET_IP_ALIGN */ |
| 191 | + rx_buf_len -= NET_IP_ALIGN; |
| 192 | + |
| 193 | + return igb_compute_pad(rx_buf_len); |
| 194 | +} |
| 195 | + |
| 196 | +#define IGB_SKB_PAD igb_skb_pad() |
144 | 197 | #else
|
145 |
| -#define IGB_MAX_FRAME_BUILD_SKB (IGB_RXBUFFER_2048 - IGB_TS_HDR_LEN) |
| 198 | +#define IGB_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) |
146 | 199 | #endif
|
147 | 200 |
|
148 | 201 | /* How many Rx Buffers do we bundle into one write to the hardware ? */
|
@@ -194,13 +247,22 @@ enum igb_tx_flags {
|
194 | 247 | #define IGB_SFF_ADDRESSING_MODE 0x4
|
195 | 248 | #define IGB_SFF_8472_UNSUP 0x00
|
196 | 249 |
|
| 250 | +enum igb_tx_buf_type { |
| 251 | + IGB_TYPE_SKB = 0, |
| 252 | + IGB_TYPE_XDP, |
| 253 | +}; |
| 254 | + |
197 | 255 | /* wrapper around a pointer to a socket buffer,
|
198 | 256 | * so a DMA handle can be stored along with the buffer
|
199 | 257 | */
|
200 | 258 | struct igb_tx_buffer {
|
201 | 259 | union e1000_adv_tx_desc *next_to_watch;
|
202 | 260 | unsigned long time_stamp;
|
203 |
| - struct sk_buff *skb; |
| 261 | + enum igb_tx_buf_type type; |
| 262 | + union { |
| 263 | + struct sk_buff *skb; |
| 264 | + struct xdp_frame *xdpf; |
| 265 | + }; |
204 | 266 | unsigned int bytecount;
|
205 | 267 | u16 gso_segs;
|
206 | 268 | __be16 protocol;
|
@@ -248,6 +310,7 @@ struct igb_ring_container {
|
248 | 310 | struct igb_ring {
|
249 | 311 | struct igb_q_vector *q_vector; /* backlink to q_vector */
|
250 | 312 | struct net_device *netdev; /* back pointer to net_device */
|
| 313 | + struct bpf_prog *xdp_prog; |
251 | 314 | struct device *dev; /* device pointer for dma mapping */
|
252 | 315 | union { /* array of buffer info structs */
|
253 | 316 | struct igb_tx_buffer *tx_buffer_info;
|
@@ -288,6 +351,7 @@ struct igb_ring {
|
288 | 351 | struct u64_stats_sync rx_syncp;
|
289 | 352 | };
|
290 | 353 | };
|
| 354 | + struct xdp_rxq_info xdp_rxq; |
291 | 355 | } ____cacheline_internodealigned_in_smp;
|
292 | 356 |
|
293 | 357 | struct igb_q_vector {
|
@@ -339,7 +403,7 @@ static inline unsigned int igb_rx_bufsz(struct igb_ring *ring)
|
339 | 403 | return IGB_RXBUFFER_3072;
|
340 | 404 |
|
341 | 405 | if (ring_uses_build_skb(ring))
|
342 |
| - return IGB_MAX_FRAME_BUILD_SKB + IGB_TS_HDR_LEN; |
| 406 | + return IGB_MAX_FRAME_BUILD_SKB; |
343 | 407 | #endif
|
344 | 408 | return IGB_RXBUFFER_2048;
|
345 | 409 | }
|
@@ -467,6 +531,7 @@ struct igb_adapter {
|
467 | 531 | unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
|
468 | 532 |
|
469 | 533 | struct net_device *netdev;
|
| 534 | + struct bpf_prog *xdp_prog; |
470 | 535 |
|
471 | 536 | unsigned long state;
|
472 | 537 | unsigned int flags;
|
@@ -643,6 +708,9 @@ enum igb_boards {
|
643 | 708 |
|
644 | 709 | extern char igb_driver_name[];
|
645 | 710 |
|
| 711 | +int igb_xmit_xdp_ring(struct igb_adapter *adapter, |
| 712 | + struct igb_ring *ring, |
| 713 | + struct xdp_frame *xdpf); |
646 | 714 | int igb_open(struct net_device *netdev);
|
647 | 715 | int igb_close(struct net_device *netdev);
|
648 | 716 | int igb_up(struct igb_adapter *);
|
|
0 commit comments