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