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