1
2
3
4#ifndef _ICE_TXRX_H_
5#define _ICE_TXRX_H_
6
7#include "ice_type.h"
8
9#define ICE_DFLT_IRQ_WORK 256
10#define ICE_RXBUF_3072 3072
11#define ICE_RXBUF_2048 2048
12#define ICE_RXBUF_1536 1536
13#define ICE_MAX_CHAINED_RX_BUFS 5
14#define ICE_MAX_BUF_TXD 8
15#define ICE_MIN_TX_LEN 17
16
17
18
19
20
21#define ICE_MAX_READ_REQ_SIZE 4096
22#define ICE_MAX_DATA_PER_TXD (16 * 1024 - 1)
23#define ICE_MAX_DATA_PER_TXD_ALIGNED \
24 (~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD)
25
26#define ICE_RX_BUF_WRITE 16
27#define ICE_MAX_TXQ_PER_TXQG 128
28
29
30
31
32
33
34
35
36
37
38
39#if (PAGE_SIZE < 8192)
40#define ICE_2K_TOO_SMALL_WITH_PADDING \
41 ((unsigned int)(NET_SKB_PAD + ICE_RXBUF_1536) > \
42 SKB_WITH_OVERHEAD(ICE_RXBUF_2048))
43
44
45
46
47
48
49
50
51
52
53static inline int ice_compute_pad(int rx_buf_len)
54{
55 int half_page_size;
56
57 half_page_size = ALIGN(rx_buf_len, PAGE_SIZE / 2);
58 return SKB_WITH_OVERHEAD(half_page_size) - rx_buf_len;
59}
60
61
62
63
64
65
66
67static inline int ice_skb_pad(void)
68{
69 int rx_buf_len;
70
71
72
73
74
75
76
77
78 if (ICE_2K_TOO_SMALL_WITH_PADDING)
79 rx_buf_len = ICE_RXBUF_3072 + SKB_DATA_ALIGN(NET_IP_ALIGN);
80 else
81 rx_buf_len = ICE_RXBUF_1536;
82
83
84 rx_buf_len -= NET_IP_ALIGN;
85
86 return ice_compute_pad(rx_buf_len);
87}
88
89#define ICE_SKB_PAD ice_skb_pad()
90#else
91#define ICE_2K_TOO_SMALL_WITH_PADDING false
92#define ICE_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
93#endif
94
95
96
97
98
99
100
101
102#define ICE_CACHE_LINE_BYTES 64
103#define ICE_DESCS_PER_CACHE_LINE (ICE_CACHE_LINE_BYTES / \
104 sizeof(struct ice_tx_desc))
105#define ICE_DESCS_FOR_CTX_DESC 1
106#define ICE_DESCS_FOR_SKB_DATA_PTR 1
107
108#define DESC_NEEDED (MAX_SKB_FRAGS + ICE_DESCS_FOR_CTX_DESC + \
109 ICE_DESCS_PER_CACHE_LINE + ICE_DESCS_FOR_SKB_DATA_PTR)
110#define ICE_DESC_UNUSED(R) \
111 (u16)((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
112 (R)->next_to_clean - (R)->next_to_use - 1)
113
114#define ICE_TX_FLAGS_TSO BIT(0)
115#define ICE_TX_FLAGS_HW_VLAN BIT(1)
116#define ICE_TX_FLAGS_SW_VLAN BIT(2)
117
118
119
120#define ICE_TX_FLAGS_DUMMY_PKT BIT(3)
121#define ICE_TX_FLAGS_IPV4 BIT(5)
122#define ICE_TX_FLAGS_IPV6 BIT(6)
123#define ICE_TX_FLAGS_TUNNEL BIT(7)
124#define ICE_TX_FLAGS_VLAN_M 0xffff0000
125#define ICE_TX_FLAGS_VLAN_PR_M 0xe0000000
126#define ICE_TX_FLAGS_VLAN_PR_S 29
127#define ICE_TX_FLAGS_VLAN_S 16
128
129#define ICE_XDP_PASS 0
130#define ICE_XDP_CONSUMED BIT(0)
131#define ICE_XDP_TX BIT(1)
132#define ICE_XDP_REDIR BIT(2)
133
134#define ICE_RX_DMA_ATTR \
135 (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
136
137#define ICE_ETH_PKT_HDR_PAD (ETH_HLEN + ETH_FCS_LEN + (VLAN_HLEN * 2))
138
139#define ICE_TXD_LAST_DESC_CMD (ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)
140
141struct ice_tx_buf {
142 struct ice_tx_desc *next_to_watch;
143 union {
144 struct sk_buff *skb;
145 void *raw_buf;
146 };
147 unsigned int bytecount;
148 unsigned short gso_segs;
149 u32 tx_flags;
150 DEFINE_DMA_UNMAP_LEN(len);
151 DEFINE_DMA_UNMAP_ADDR(dma);
152};
153
154struct ice_tx_offload_params {
155 u64 cd_qw1;
156 struct ice_ring *tx_ring;
157 u32 td_cmd;
158 u32 td_offset;
159 u32 td_l2tag1;
160 u32 cd_tunnel_params;
161 u16 cd_l2tag2;
162 u8 header_len;
163};
164
165struct ice_rx_buf {
166 union {
167 struct {
168 struct sk_buff *skb;
169 dma_addr_t dma;
170 struct page *page;
171 unsigned int page_offset;
172 u16 pagecnt_bias;
173 };
174 struct {
175 struct xdp_buff *xdp;
176 };
177 };
178};
179
180struct ice_q_stats {
181 u64 pkts;
182 u64 bytes;
183};
184
185struct ice_txq_stats {
186 u64 restart_q;
187 u64 tx_busy;
188 u64 tx_linearize;
189 int prev_pkt;
190};
191
192struct ice_rxq_stats {
193 u64 non_eop_descs;
194 u64 alloc_page_failed;
195 u64 alloc_buf_failed;
196 u64 gro_dropped;
197};
198
199
200
201
202
203
204enum ice_dyn_idx_t {
205 ICE_IDX_ITR0 = 0,
206 ICE_IDX_ITR1 = 1,
207 ICE_IDX_ITR2 = 2,
208 ICE_ITR_NONE = 3
209};
210
211
212enum ice_rx_dtype {
213 ICE_RX_DTYPE_NO_SPLIT = 0,
214 ICE_RX_DTYPE_HEADER_SPLIT = 1,
215 ICE_RX_DTYPE_SPLIT_ALWAYS = 2,
216};
217
218
219#define ICE_RX_ITR ICE_IDX_ITR0
220#define ICE_TX_ITR ICE_IDX_ITR1
221#define ICE_ITR_8K 124
222#define ICE_ITR_20K 50
223#define ICE_ITR_MAX 8160
224#define ICE_DFLT_TX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
225#define ICE_DFLT_RX_ITR (ICE_ITR_20K | ICE_ITR_DYNAMIC)
226#define ICE_ITR_DYNAMIC 0x8000
227#define ITR_IS_DYNAMIC(setting) (!!((setting) & ICE_ITR_DYNAMIC))
228#define ITR_TO_REG(setting) ((setting) & ~ICE_ITR_DYNAMIC)
229#define ICE_ITR_GRAN_S 1
230#define ICE_ITR_GRAN_US BIT(ICE_ITR_GRAN_S)
231#define ICE_ITR_MASK 0x1FFE
232#define ITR_REG_ALIGN(setting) ((setting) & ICE_ITR_MASK)
233
234#define ICE_ITR_ADAPTIVE_MIN_INC 0x0002
235#define ICE_ITR_ADAPTIVE_MIN_USECS 0x0002
236#define ICE_ITR_ADAPTIVE_MAX_USECS 0x00FA
237#define ICE_ITR_ADAPTIVE_LATENCY 0x8000
238#define ICE_ITR_ADAPTIVE_BULK 0x0000
239
240#define ICE_DFLT_INTRL 0
241#define ICE_MAX_INTRL 236
242
243#define ICE_WB_ON_ITR_USECS 2
244#define ICE_IN_WB_ON_ITR_MODE 255
245
246
247
248
249#define ICE_GLINT_DYN_CTL_WB_ON_ITR(usecs, itr_idx) \
250 ((((usecs) << (GLINT_DYN_CTL_INTERVAL_S - ICE_ITR_GRAN_S)) & \
251 GLINT_DYN_CTL_INTERVAL_M) | \
252 (((itr_idx) << GLINT_DYN_CTL_ITR_INDX_S) & \
253 GLINT_DYN_CTL_ITR_INDX_M) | GLINT_DYN_CTL_INTENA_MSK_M | \
254 GLINT_DYN_CTL_WB_ON_ITR_M)
255
256
257#define ICE_TX_ADVANCED 0
258#define ICE_TX_LEGACY 1
259
260
261struct ice_ring {
262
263 struct ice_ring *next;
264 void *desc;
265 struct device *dev;
266 struct net_device *netdev;
267 struct ice_vsi *vsi;
268 struct ice_q_vector *q_vector;
269 u8 __iomem *tail;
270 union {
271 struct ice_tx_buf *tx_buf;
272 struct ice_rx_buf *rx_buf;
273 };
274
275 u16 q_index;
276 u16 q_handle;
277
278 u8 ring_active:1;
279
280 u16 count;
281 u16 reg_idx;
282
283
284 u16 next_to_use;
285 u16 next_to_clean;
286 u16 next_to_alloc;
287
288
289 struct ice_q_stats stats;
290 struct u64_stats_sync syncp;
291 union {
292 struct ice_txq_stats tx_stats;
293 struct ice_rxq_stats rx_stats;
294 };
295
296 struct rcu_head rcu;
297 struct bpf_prog *xdp_prog;
298 struct xdp_umem *xsk_umem;
299
300 struct xdp_rxq_info xdp_rxq;
301
302
303
304#define ICE_TX_FLAGS_RING_XDP BIT(0)
305#define ICE_RX_FLAGS_RING_BUILD_SKB BIT(1)
306 u8 flags;
307 dma_addr_t dma;
308 unsigned int size;
309 u32 txq_teid;
310 u16 rx_buf_len;
311 u8 dcb_tc;
312} ____cacheline_internodealigned_in_smp;
313
314static inline bool ice_ring_uses_build_skb(struct ice_ring *ring)
315{
316 return !!(ring->flags & ICE_RX_FLAGS_RING_BUILD_SKB);
317}
318
319static inline void ice_set_ring_build_skb_ena(struct ice_ring *ring)
320{
321 ring->flags |= ICE_RX_FLAGS_RING_BUILD_SKB;
322}
323
324static inline void ice_clear_ring_build_skb_ena(struct ice_ring *ring)
325{
326 ring->flags &= ~ICE_RX_FLAGS_RING_BUILD_SKB;
327}
328
329static inline bool ice_ring_is_xdp(struct ice_ring *ring)
330{
331 return !!(ring->flags & ICE_TX_FLAGS_RING_XDP);
332}
333
334struct ice_ring_container {
335
336 struct ice_ring *ring;
337 unsigned long next_update;
338 unsigned int total_bytes;
339 unsigned int total_pkts;
340 u16 itr_idx;
341 u16 target_itr;
342 u16 current_itr;
343
344
345
346
347 u16 itr_setting;
348};
349
350struct ice_coalesce_stored {
351 u16 itr_tx;
352 u16 itr_rx;
353 u8 intrl;
354};
355
356
357#define ice_for_each_ring(pos, head) \
358 for (pos = (head).ring; pos; pos = pos->next)
359
360static inline unsigned int ice_rx_pg_order(struct ice_ring *ring)
361{
362#if (PAGE_SIZE < 8192)
363 if (ring->rx_buf_len > (PAGE_SIZE / 2))
364 return 1;
365#endif
366 return 0;
367}
368
369#define ice_rx_pg_size(_ring) (PAGE_SIZE << ice_rx_pg_order(_ring))
370
371union ice_32b_rx_flex_desc;
372
373bool ice_alloc_rx_bufs(struct ice_ring *rxr, u16 cleaned_count);
374netdev_tx_t ice_start_xmit(struct sk_buff *skb, struct net_device *netdev);
375void ice_clean_tx_ring(struct ice_ring *tx_ring);
376void ice_clean_rx_ring(struct ice_ring *rx_ring);
377int ice_setup_tx_ring(struct ice_ring *tx_ring);
378int ice_setup_rx_ring(struct ice_ring *rx_ring);
379void ice_free_tx_ring(struct ice_ring *tx_ring);
380void ice_free_rx_ring(struct ice_ring *rx_ring);
381int ice_napi_poll(struct napi_struct *napi, int budget);
382int
383ice_prgm_fdir_fltr(struct ice_vsi *vsi, struct ice_fltr_desc *fdir_desc,
384 u8 *raw_packet);
385int ice_clean_rx_irq(struct ice_ring *rx_ring, int budget);
386void ice_clean_ctrl_tx_irq(struct ice_ring *tx_ring);
387#endif
388