Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _ICE_RXTX_H_
6 : : #define _ICE_RXTX_H_
7 : :
8 : : #include "ice_ethdev.h"
9 : :
10 : : #define ICE_ALIGN_RING_DESC 32
11 : : #define ICE_MIN_RING_DESC 64
12 : : #define ICE_MAX_RING_DESC (8192 - 32)
13 : : #define ICE_DMA_MEM_ALIGN 4096
14 : : #define ICE_RING_BASE_ALIGN 128
15 : :
16 : : #define ICE_RX_MAX_BURST 32
17 : : #define ICE_TX_MAX_BURST 32
18 : :
19 : : /* Maximal number of segments to split. */
20 : : #define ICE_RX_MAX_NSEG 2
21 : :
22 : : #define ICE_CHK_Q_ENA_COUNT 100
23 : : #define ICE_CHK_Q_ENA_INTERVAL_US 100
24 : :
25 : : #ifdef RTE_LIBRTE_ICE_16BYTE_RX_DESC
26 : : #define ice_rx_flex_desc ice_16b_rx_flex_desc
27 : : #else
28 : : #define ice_rx_flex_desc ice_32b_rx_flex_desc
29 : : #endif
30 : :
31 : : #define ICE_SUPPORT_CHAIN_NUM 5
32 : :
33 : : #define ICE_TD_CMD ICE_TX_DESC_CMD_EOP
34 : :
35 : : #define ICE_VPMD_RX_BURST 32
36 : : #define ICE_VPMD_TX_BURST 32
37 : : #define ICE_RXQ_REARM_THRESH 64
38 : : #define ICE_MAX_RX_BURST ICE_RXQ_REARM_THRESH
39 : : #define ICE_TX_MAX_FREE_BUF_SZ 64
40 : : #define ICE_DESCS_PER_LOOP 4
41 : :
42 : : #define ICE_FDIR_PKT_LEN 512
43 : :
44 : : #define ICE_RXDID_COMMS_OVS 22
45 : :
46 : : #define ICE_TX_MIN_PKT_LEN 17
47 : :
48 : : #define ICE_TX_OFFLOAD_MASK ( \
49 : : RTE_MBUF_F_TX_OUTER_IPV6 | \
50 : : RTE_MBUF_F_TX_OUTER_IPV4 | \
51 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
52 : : RTE_MBUF_F_TX_VLAN | \
53 : : RTE_MBUF_F_TX_IPV6 | \
54 : : RTE_MBUF_F_TX_IPV4 | \
55 : : RTE_MBUF_F_TX_IP_CKSUM | \
56 : : RTE_MBUF_F_TX_L4_MASK | \
57 : : RTE_MBUF_F_TX_IEEE1588_TMST | \
58 : : RTE_MBUF_F_TX_TCP_SEG | \
59 : : RTE_MBUF_F_TX_QINQ | \
60 : : RTE_MBUF_F_TX_TUNNEL_MASK | \
61 : : RTE_MBUF_F_TX_UDP_SEG | \
62 : : RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
63 : :
64 : : #define ICE_TX_OFFLOAD_NOTSUP_MASK \
65 : : (RTE_MBUF_F_TX_OFFLOAD_MASK ^ ICE_TX_OFFLOAD_MASK)
66 : :
67 : : extern uint64_t ice_timestamp_dynflag;
68 : : extern int ice_timestamp_dynfield_offset;
69 : :
70 : : /* Max header size can be 2K - 64 bytes */
71 : : #define ICE_RX_HDR_BUF_SIZE (2048 - 64)
72 : :
73 : : /* Max data buffer size must be 16K - 128 bytes */
74 : : #define ICE_RX_MAX_DATA_BUF_SIZE (16 * 1024 - 128)
75 : :
76 : : #define ICE_HEADER_SPLIT_ENA BIT(0)
77 : :
78 : : #define ICE_TX_MTU_SEG_MAX 8
79 : :
80 : : typedef void (*ice_rx_release_mbufs_t)(struct ice_rx_queue *rxq);
81 : : typedef void (*ice_tx_release_mbufs_t)(struct ice_tx_queue *txq);
82 : : typedef void (*ice_rxd_to_pkt_fields_t)(struct ice_rx_queue *rxq,
83 : : struct rte_mbuf *mb,
84 : : volatile union ice_rx_flex_desc *rxdp);
85 : :
86 : : struct ice_rx_entry {
87 : : struct rte_mbuf *mbuf;
88 : : };
89 : :
90 : : enum ice_rx_dtype {
91 : : ICE_RX_DTYPE_NO_SPLIT = 0,
92 : : ICE_RX_DTYPE_HEADER_SPLIT = 1,
93 : : ICE_RX_DTYPE_SPLIT_ALWAYS = 2,
94 : : };
95 : :
96 : : struct ice_rx_queue {
97 : : struct rte_mempool *mp; /* mbuf pool to populate RX ring */
98 : : volatile union ice_rx_flex_desc *rx_ring;/* RX ring virtual address */
99 : : rte_iova_t rx_ring_dma; /* RX ring DMA address */
100 : : struct ice_rx_entry *sw_ring; /* address of RX soft ring */
101 : : uint16_t nb_rx_desc; /* number of RX descriptors */
102 : : uint16_t rx_free_thresh; /* max free RX desc to hold */
103 : : uint16_t rx_tail; /* current value of tail */
104 : : uint16_t nb_rx_hold; /* number of held free RX desc */
105 : : struct rte_mbuf *pkt_first_seg; /**< first segment of current packet */
106 : : struct rte_mbuf *pkt_last_seg; /**< last segment of current packet */
107 : : uint16_t rx_nb_avail; /**< number of staged packets ready */
108 : : uint16_t rx_next_avail; /**< index of next staged packets */
109 : : uint16_t rx_free_trigger; /**< triggers rx buffer allocation */
110 : : struct rte_mbuf fake_mbuf; /**< dummy mbuf */
111 : : struct rte_mbuf *rx_stage[ICE_RX_MAX_BURST * 2];
112 : :
113 : : uint16_t rxrearm_nb; /**< number of remaining to be re-armed */
114 : : uint16_t rxrearm_start; /**< the idx we start the re-arming from */
115 : : uint64_t mbuf_initializer; /**< value to init mbufs */
116 : :
117 : : uint16_t port_id; /* device port ID */
118 : : uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
119 : : uint8_t fdir_enabled; /* 0 if FDIR disabled, 1 when enabled */
120 : : uint16_t queue_id; /* RX queue index */
121 : : uint16_t reg_idx; /* RX queue register index */
122 : : uint8_t drop_en; /* if not 0, set register bit */
123 : : volatile uint8_t *qrx_tail; /* register address of tail */
124 : : struct ice_vsi *vsi; /* the VSI this queue belongs to */
125 : : uint16_t rx_buf_len; /* The packet buffer size */
126 : : uint16_t rx_hdr_len; /* The header buffer size */
127 : : uint16_t max_pkt_len; /* Maximum packet length */
128 : : bool q_set; /* indicate if rx queue has been configured */
129 : : bool rx_deferred_start; /* don't start this queue in dev start */
130 : : uint8_t proto_xtr; /* Protocol extraction from flexible descriptor */
131 : : int xtr_field_offs; /*Protocol extraction matedata offset*/
132 : : uint64_t xtr_ol_flag; /* Protocol extraction offload flag */
133 : : uint32_t rxdid; /* Receive Flex Descriptor profile ID */
134 : : ice_rx_release_mbufs_t rx_rel_mbufs;
135 : : uint64_t offloads;
136 : : uint32_t time_high;
137 : : uint32_t hw_register_set;
138 : : const struct rte_memzone *mz;
139 : : uint32_t hw_time_high; /* high 32 bits of timestamp */
140 : : uint32_t hw_time_low; /* low 32 bits of timestamp */
141 : : uint64_t hw_time_update; /* SW time of HW record updating */
142 : : struct rte_eth_rxseg_split rxseg[ICE_RX_MAX_NSEG];
143 : : uint32_t rxseg_nb;
144 : : bool ts_enable; /* if rxq timestamp is enabled */
145 : : };
146 : :
147 : : struct ice_tx_entry {
148 : : struct rte_mbuf *mbuf;
149 : : uint16_t next_id;
150 : : uint16_t last_id;
151 : : };
152 : :
153 : : struct ice_vec_tx_entry {
154 : : struct rte_mbuf *mbuf;
155 : : };
156 : :
157 : : struct ice_tx_queue {
158 : : uint16_t nb_tx_desc; /* number of TX descriptors */
159 : : rte_iova_t tx_ring_dma; /* TX ring DMA address */
160 : : volatile struct ice_tx_desc *tx_ring; /* TX ring virtual address */
161 : : struct ice_tx_entry *sw_ring; /* virtual address of SW ring */
162 : : uint16_t tx_tail; /* current value of tail register */
163 : : volatile uint8_t *qtx_tail; /* register address of tail */
164 : : uint16_t nb_tx_used; /* number of TX desc used since RS bit set */
165 : : /* index to last TX descriptor to have been cleaned */
166 : : uint16_t last_desc_cleaned;
167 : : /* Total number of TX descriptors ready to be allocated. */
168 : : uint16_t nb_tx_free;
169 : : /* Start freeing TX buffers if there are less free descriptors than
170 : : * this value.
171 : : */
172 : : uint16_t tx_free_thresh;
173 : : /* Number of TX descriptors to use before RS bit is set. */
174 : : uint16_t tx_rs_thresh;
175 : : uint8_t pthresh; /**< Prefetch threshold register. */
176 : : uint8_t hthresh; /**< Host threshold register. */
177 : : uint8_t wthresh; /**< Write-back threshold reg. */
178 : : uint16_t port_id; /* Device port identifier. */
179 : : uint16_t queue_id; /* TX queue index. */
180 : : uint32_t q_teid; /* TX schedule node id. */
181 : : uint16_t reg_idx;
182 : : uint64_t offloads;
183 : : struct ice_vsi *vsi; /* the VSI this queue belongs to */
184 : : uint16_t tx_next_dd;
185 : : uint16_t tx_next_rs;
186 : : uint64_t mbuf_errors;
187 : : bool tx_deferred_start; /* don't start this queue in dev start */
188 : : bool q_set; /* indicate if tx queue has been configured */
189 : : ice_tx_release_mbufs_t tx_rel_mbufs;
190 : : const struct rte_memzone *mz;
191 : : };
192 : :
193 : : /* Offload features */
194 : : union ice_tx_offload {
195 : : uint64_t data;
196 : : struct {
197 : : uint64_t l2_len:7; /* L2 (MAC) Header Length. */
198 : : uint64_t l3_len:9; /* L3 (IP) Header Length. */
199 : : uint64_t l4_len:8; /* L4 Header Length. */
200 : : uint64_t tso_segsz:16; /* TCP TSO segment size */
201 : : uint64_t outer_l2_len:8; /* outer L2 Header Length */
202 : : uint64_t outer_l3_len:16; /* outer L3 Header Length */
203 : : };
204 : : };
205 : :
206 : : /* Rx Flex Descriptor for Comms Package Profile
207 : : * RxDID Profile ID 22 (swap Hash and FlowID)
208 : : * Flex-field 0: Flow ID lower 16-bits
209 : : * Flex-field 1: Flow ID upper 16-bits
210 : : * Flex-field 2: RSS hash lower 16-bits
211 : : * Flex-field 3: RSS hash upper 16-bits
212 : : * Flex-field 4: AUX0
213 : : * Flex-field 5: AUX1
214 : : */
215 : : struct ice_32b_rx_flex_desc_comms_ovs {
216 : : /* Qword 0 */
217 : : u8 rxdid;
218 : : u8 mir_id_umb_cast;
219 : : __le16 ptype_flexi_flags0;
220 : : __le16 pkt_len;
221 : : __le16 hdr_len_sph_flex_flags1;
222 : :
223 : : /* Qword 1 */
224 : : __le16 status_error0;
225 : : __le16 l2tag1;
226 : : __le32 flow_id;
227 : :
228 : : /* Qword 2 */
229 : : __le16 status_error1;
230 : : u8 flexi_flags2;
231 : : u8 ts_low;
232 : : __le16 l2tag2_1st;
233 : : __le16 l2tag2_2nd;
234 : :
235 : : /* Qword 3 */
236 : : __le32 rss_hash;
237 : : union {
238 : : struct {
239 : : __le16 aux0;
240 : : __le16 aux1;
241 : : } flex;
242 : : __le32 ts_high;
243 : : } flex_ts;
244 : : };
245 : :
246 : : int ice_rx_queue_setup(struct rte_eth_dev *dev,
247 : : uint16_t queue_idx,
248 : : uint16_t nb_desc,
249 : : unsigned int socket_id,
250 : : const struct rte_eth_rxconf *rx_conf,
251 : : struct rte_mempool *mp);
252 : : int ice_tx_queue_setup(struct rte_eth_dev *dev,
253 : : uint16_t queue_idx,
254 : : uint16_t nb_desc,
255 : : unsigned int socket_id,
256 : : const struct rte_eth_txconf *tx_conf);
257 : : int ice_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
258 : : int ice_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
259 : : int ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
260 : : int ice_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
261 : : int ice_fdir_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
262 : : int ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
263 : : int ice_fdir_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
264 : : int ice_fdir_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
265 : : void ice_rx_queue_release(void *rxq);
266 : : void ice_tx_queue_release(void *txq);
267 : : void ice_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
268 : : void ice_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
269 : : void ice_free_queues(struct rte_eth_dev *dev);
270 : : int ice_fdir_setup_tx_resources(struct ice_pf *pf);
271 : : int ice_fdir_setup_rx_resources(struct ice_pf *pf);
272 : : uint16_t ice_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
273 : : uint16_t nb_pkts);
274 : : uint16_t ice_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
275 : : uint16_t nb_pkts);
276 : : void ice_set_rx_function(struct rte_eth_dev *dev);
277 : : uint16_t ice_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
278 : : uint16_t nb_pkts);
279 : : void ice_set_tx_function_flag(struct rte_eth_dev *dev,
280 : : struct ice_tx_queue *txq);
281 : : void ice_set_tx_function(struct rte_eth_dev *dev);
282 : : uint32_t ice_rx_queue_count(void *rx_queue);
283 : : void ice_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
284 : : struct rte_eth_rxq_info *qinfo);
285 : : void ice_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
286 : : struct rte_eth_txq_info *qinfo);
287 : : int ice_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
288 : : struct rte_eth_burst_mode *mode);
289 : : int ice_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t queue_id,
290 : : struct rte_eth_burst_mode *mode);
291 : : int ice_rx_descriptor_status(void *rx_queue, uint16_t offset);
292 : : int ice_tx_descriptor_status(void *tx_queue, uint16_t offset);
293 : : void ice_set_default_ptype_table(struct rte_eth_dev *dev);
294 : : const uint32_t *ice_dev_supported_ptypes_get(struct rte_eth_dev *dev,
295 : : size_t *no_of_elements);
296 : : void ice_select_rxd_to_pkt_fields_handler(struct ice_rx_queue *rxq,
297 : : uint32_t rxdid);
298 : :
299 : : int ice_rx_vec_dev_check(struct rte_eth_dev *dev);
300 : : int ice_tx_vec_dev_check(struct rte_eth_dev *dev);
301 : : int ice_rxq_vec_setup(struct ice_rx_queue *rxq);
302 : : int ice_txq_vec_setup(struct ice_tx_queue *txq);
303 : : uint16_t ice_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
304 : : uint16_t nb_pkts);
305 : : uint16_t ice_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
306 : : uint16_t nb_pkts);
307 : : uint16_t ice_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
308 : : uint16_t nb_pkts);
309 : : uint16_t ice_recv_pkts_vec_avx2(void *rx_queue, struct rte_mbuf **rx_pkts,
310 : : uint16_t nb_pkts);
311 : : uint16_t ice_recv_pkts_vec_avx2_offload(void *rx_queue, struct rte_mbuf **rx_pkts,
312 : : uint16_t nb_pkts);
313 : : uint16_t ice_recv_scattered_pkts_vec_avx2(void *rx_queue,
314 : : struct rte_mbuf **rx_pkts,
315 : : uint16_t nb_pkts);
316 : : uint16_t ice_recv_scattered_pkts_vec_avx2_offload(void *rx_queue,
317 : : struct rte_mbuf **rx_pkts,
318 : : uint16_t nb_pkts);
319 : : uint16_t ice_xmit_pkts_vec_avx2(void *tx_queue, struct rte_mbuf **tx_pkts,
320 : : uint16_t nb_pkts);
321 : : uint16_t ice_xmit_pkts_vec_avx2_offload(void *tx_queue, struct rte_mbuf **tx_pkts,
322 : : uint16_t nb_pkts);
323 : : uint16_t ice_recv_pkts_vec_avx512(void *rx_queue, struct rte_mbuf **rx_pkts,
324 : : uint16_t nb_pkts);
325 : : uint16_t ice_recv_pkts_vec_avx512_offload(void *rx_queue,
326 : : struct rte_mbuf **rx_pkts,
327 : : uint16_t nb_pkts);
328 : : uint16_t ice_recv_scattered_pkts_vec_avx512(void *rx_queue,
329 : : struct rte_mbuf **rx_pkts,
330 : : uint16_t nb_pkts);
331 : : uint16_t ice_recv_scattered_pkts_vec_avx512_offload(void *rx_queue,
332 : : struct rte_mbuf **rx_pkts,
333 : : uint16_t nb_pkts);
334 : : uint16_t ice_xmit_pkts_vec_avx512(void *tx_queue, struct rte_mbuf **tx_pkts,
335 : : uint16_t nb_pkts);
336 : : uint16_t ice_xmit_pkts_vec_avx512_offload(void *tx_queue,
337 : : struct rte_mbuf **tx_pkts,
338 : : uint16_t nb_pkts);
339 : : int ice_fdir_programming(struct ice_pf *pf, struct ice_fltr_desc *fdir_desc);
340 : : int ice_tx_done_cleanup(void *txq, uint32_t free_cnt);
341 : : int ice_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc);
342 : :
343 : : #define FDIR_PARSING_ENABLE_PER_QUEUE(ad, on) do { \
344 : : int i; \
345 : : for (i = 0; i < (ad)->pf.dev_data->nb_rx_queues; i++) { \
346 : : struct ice_rx_queue *rxq = (ad)->pf.dev_data->rx_queues[i]; \
347 : : if (!rxq) \
348 : : continue; \
349 : : rxq->fdir_enabled = on; \
350 : : } \
351 : : PMD_DRV_LOG(DEBUG, "FDIR processing on RX set to %d", on); \
352 : : } while (0)
353 : :
354 : : /* Enable/disable flow director parsing from Rx descriptor in data path. */
355 : : static inline
356 : 0 : void ice_fdir_rx_parsing_enable(struct ice_adapter *ad, bool on)
357 : : {
358 [ # # ]: 0 : if (on) {
359 : : /* Enable flow director parsing from Rx descriptor */
360 [ # # # # ]: 0 : FDIR_PARSING_ENABLE_PER_QUEUE(ad, on);
361 : 0 : ad->fdir_ref_cnt++;
362 : : } else {
363 [ # # ]: 0 : if (ad->fdir_ref_cnt >= 1) {
364 : 0 : ad->fdir_ref_cnt--;
365 : :
366 [ # # ]: 0 : if (ad->fdir_ref_cnt == 0)
367 [ # # # # ]: 0 : FDIR_PARSING_ENABLE_PER_QUEUE(ad, on);
368 : : }
369 : : }
370 : 0 : }
371 : :
372 : : #define ICE_TIMESYNC_REG_WRAP_GUARD_BAND 10000
373 : :
374 : : /* Helper function to convert a 32b nanoseconds timestamp to 64b. */
375 : : static inline
376 : 0 : uint64_t ice_tstamp_convert_32b_64b(struct ice_hw *hw, struct ice_adapter *ad,
377 : : uint32_t flag, uint32_t in_timestamp)
378 : : {
379 : 0 : uint8_t tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
380 : : const uint64_t mask = 0xFFFFFFFF;
381 : : uint32_t hi, lo, lo2, delta;
382 : : uint64_t ns;
383 : :
384 [ # # ]: 0 : if (flag) {
385 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
386 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
387 : :
388 : : /*
389 : : * On typical system, the delta between lo and lo2 is ~1000ns,
390 : : * so 10000 seems a large-enough but not overly-big guard band.
391 : : */
392 [ # # ]: 0 : if (lo > (UINT32_MAX - ICE_TIMESYNC_REG_WRAP_GUARD_BAND))
393 : 0 : lo2 = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
394 : : else
395 : : lo2 = lo;
396 : :
397 [ # # ]: 0 : if (lo2 < lo) {
398 : 0 : lo = ICE_READ_REG(hw, GLTSYN_TIME_L(tmr_idx));
399 : 0 : hi = ICE_READ_REG(hw, GLTSYN_TIME_H(tmr_idx));
400 : : }
401 : :
402 : 0 : ad->time_hw = ((uint64_t)hi << 32) | lo;
403 : : }
404 : :
405 : 0 : delta = (in_timestamp - (uint32_t)(ad->time_hw & mask));
406 [ # # ]: 0 : if (delta > (mask / 2)) {
407 : 0 : delta = ((uint32_t)(ad->time_hw & mask) - in_timestamp);
408 : 0 : ns = ad->time_hw - delta;
409 : : } else {
410 : 0 : ns = ad->time_hw + delta;
411 : : }
412 : :
413 : 0 : return ns;
414 : : }
415 : :
416 : : #endif /* _ICE_RXTX_H_ */
|