net/octeontx2: add flow utility functions
[dpdk.git] / drivers / net / octeontx2 / otx2_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_ETHDEV_H__
6 #define __OTX2_ETHDEV_H__
7
8 #include <stdint.h>
9
10 #include <rte_common.h>
11 #include <rte_ethdev.h>
12 #include <rte_kvargs.h>
13 #include <rte_mbuf.h>
14 #include <rte_mempool.h>
15 #include <rte_string_fns.h>
16 #include <rte_time.h>
17
18 #include "otx2_common.h"
19 #include "otx2_dev.h"
20 #include "otx2_flow.h"
21 #include "otx2_irq.h"
22 #include "otx2_mempool.h"
23 #include "otx2_rx.h"
24 #include "otx2_tm.h"
25 #include "otx2_tx.h"
26
27 #define OTX2_ETH_DEV_PMD_VERSION        "1.0"
28
29 /* Ethdev HWCAP and Fixup flags. Use from MSB bits to avoid conflict with dev */
30
31 /* Minimum CQ size should be 4K */
32 #define OTX2_FIXUP_F_MIN_4K_Q           BIT_ULL(63)
33 #define otx2_ethdev_fixup_is_min_4k_q(dev)      \
34                                 ((dev)->hwcap & OTX2_FIXUP_F_MIN_4K_Q)
35 /* Limit CQ being full */
36 #define OTX2_FIXUP_F_LIMIT_CQ_FULL      BIT_ULL(62)
37 #define otx2_ethdev_fixup_is_limit_cq_full(dev) \
38                                 ((dev)->hwcap & OTX2_FIXUP_F_LIMIT_CQ_FULL)
39
40 /* Used for struct otx2_eth_dev::flags */
41 #define OTX2_LINK_CFG_IN_PROGRESS_F     BIT_ULL(0)
42
43 /* VLAN tag inserted by NIX_TX_VTAG_ACTION.
44  * In Tx space is always reserved for this in FRS.
45  */
46 #define NIX_MAX_VTAG_INS                2
47 #define NIX_MAX_VTAG_ACT_SIZE           (4 * NIX_MAX_VTAG_INS)
48
49 /* ETH_HLEN+ETH_FCS+2*VLAN_HLEN */
50 #define NIX_L2_OVERHEAD \
51         (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 8)
52
53 /* HW config of frame size doesn't include FCS */
54 #define NIX_MAX_HW_FRS                  9212
55 #define NIX_MIN_HW_FRS                  60
56
57 /* Since HW FRS includes NPC VTAG insertion space, user has reduced FRS */
58 #define NIX_MAX_FRS     \
59         (NIX_MAX_HW_FRS + RTE_ETHER_CRC_LEN - NIX_MAX_VTAG_ACT_SIZE)
60
61 #define NIX_MIN_FRS     \
62         (NIX_MIN_HW_FRS + RTE_ETHER_CRC_LEN)
63
64 #define NIX_MAX_MTU     \
65         (NIX_MAX_FRS - NIX_L2_OVERHEAD)
66
67 #define NIX_MAX_SQB                     512
68 #define NIX_MIN_SQB                     32
69 #define NIX_SQB_LIST_SPACE              2
70 #define NIX_RSS_RETA_SIZE_MAX           256
71 /* Group 0 will be used for RSS, 1 -7 will be used for rte_flow RSS action*/
72 #define NIX_RSS_GRPS                    8
73 #define NIX_HASH_KEY_SIZE               48 /* 352 Bits */
74 #define NIX_RSS_RETA_SIZE               64
75 #define NIX_RX_MIN_DESC                 16
76 #define NIX_RX_MIN_DESC_ALIGN           16
77 #define NIX_RX_NB_SEG_MAX               6
78 #define NIX_CQ_ENTRY_SZ                 128
79 #define NIX_CQ_ALIGN                    512
80 #define NIX_SQB_LOWER_THRESH            90
81 #define LMT_SLOT_MASK                   0x7f
82
83 /* If PTP is enabled additional SEND MEM DESC is required which
84  * takes 2 words, hence max 7 iova address are possible
85  */
86 #if defined(RTE_LIBRTE_IEEE1588)
87 #define NIX_TX_NB_SEG_MAX               7
88 #else
89 #define NIX_TX_NB_SEG_MAX               9
90 #endif
91
92 /* Apply BP when CQ is 75% full */
93 #define NIX_CQ_BP_LEVEL (25 * 256 / 100)
94
95 #define CQ_OP_STAT_OP_ERR       63
96 #define CQ_OP_STAT_CQ_ERR       46
97
98 #define OP_ERR                  BIT_ULL(CQ_OP_STAT_OP_ERR)
99 #define CQ_ERR                  BIT_ULL(CQ_OP_STAT_CQ_ERR)
100
101 #define NIX_RSS_OFFLOAD         (ETH_RSS_PORT | ETH_RSS_IP | ETH_RSS_UDP |\
102                                  ETH_RSS_TCP | ETH_RSS_SCTP | \
103                                  ETH_RSS_TUNNEL | ETH_RSS_L2_PAYLOAD)
104
105 #define NIX_TX_OFFLOAD_CAPA ( \
106         DEV_TX_OFFLOAD_MBUF_FAST_FREE   | \
107         DEV_TX_OFFLOAD_MT_LOCKFREE      | \
108         DEV_TX_OFFLOAD_VLAN_INSERT      | \
109         DEV_TX_OFFLOAD_QINQ_INSERT      | \
110         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
111         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  | \
112         DEV_TX_OFFLOAD_TCP_CKSUM        | \
113         DEV_TX_OFFLOAD_UDP_CKSUM        | \
114         DEV_TX_OFFLOAD_SCTP_CKSUM       | \
115         DEV_TX_OFFLOAD_MULTI_SEGS       | \
116         DEV_TX_OFFLOAD_IPV4_CKSUM)
117
118 #define NIX_RX_OFFLOAD_CAPA ( \
119         DEV_RX_OFFLOAD_CHECKSUM         | \
120         DEV_RX_OFFLOAD_SCTP_CKSUM       | \
121         DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
122         DEV_RX_OFFLOAD_SCATTER          | \
123         DEV_RX_OFFLOAD_JUMBO_FRAME      | \
124         DEV_RX_OFFLOAD_OUTER_UDP_CKSUM | \
125         DEV_RX_OFFLOAD_VLAN_STRIP | \
126         DEV_RX_OFFLOAD_VLAN_FILTER | \
127         DEV_RX_OFFLOAD_QINQ_STRIP | \
128         DEV_RX_OFFLOAD_TIMESTAMP)
129
130 #define NIX_DEFAULT_RSS_CTX_GROUP  0
131 #define NIX_DEFAULT_RSS_MCAM_IDX  -1
132
133 #define otx2_ethdev_is_ptp_en(dev)      ((dev)->ptp_en)
134
135 #define NIX_TIMESYNC_TX_CMD_LEN         8
136 /* Additional timesync values. */
137 #define OTX2_CYCLECOUNTER_MASK   0xffffffffffffffffULL
138
139 enum nix_q_size_e {
140         nix_q_size_16,  /* 16 entries */
141         nix_q_size_64,  /* 64 entries */
142         nix_q_size_256,
143         nix_q_size_1K,
144         nix_q_size_4K,
145         nix_q_size_16K,
146         nix_q_size_64K,
147         nix_q_size_256K,
148         nix_q_size_1M,  /* Million entries */
149         nix_q_size_max
150 };
151
152 struct otx2_qint {
153         struct rte_eth_dev *eth_dev;
154         uint8_t qintx;
155 };
156
157 struct otx2_rss_info {
158         uint64_t nix_rss;
159         uint32_t flowkey_cfg;
160         uint16_t rss_size;
161         uint8_t rss_grps;
162         uint8_t alg_idx; /* Selected algo index */
163         uint16_t ind_tbl[NIX_RSS_RETA_SIZE_MAX];
164         uint8_t key[NIX_HASH_KEY_SIZE];
165 };
166
167 struct otx2_eth_qconf {
168         union {
169                 struct rte_eth_txconf tx;
170                 struct rte_eth_rxconf rx;
171         } conf;
172         void *mempool;
173         uint32_t socket_id;
174         uint16_t nb_desc;
175 };
176
177 struct otx2_fc_info {
178         enum rte_eth_fc_mode mode;  /**< Link flow control mode */
179         uint8_t rx_pause;
180         uint8_t tx_pause;
181         uint8_t chan_cnt;
182         uint16_t bpid[NIX_MAX_CHAN];
183 };
184
185 struct otx2_eth_dev {
186         OTX2_DEV; /* Base class */
187         MARKER otx2_eth_dev_data_start;
188         uint16_t sqb_size;
189         uint16_t rx_chan_base;
190         uint16_t tx_chan_base;
191         uint8_t rx_chan_cnt;
192         uint8_t tx_chan_cnt;
193         uint8_t lso_tsov4_idx;
194         uint8_t lso_tsov6_idx;
195         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
196         uint8_t max_mac_entries;
197         uint8_t lf_tx_stats;
198         uint8_t lf_rx_stats;
199         uint16_t flags;
200         uint16_t cints;
201         uint16_t qints;
202         uint8_t configured;
203         uint8_t configured_qints;
204         uint8_t configured_nb_rx_qs;
205         uint8_t configured_nb_tx_qs;
206         uint16_t nix_msixoff;
207         uintptr_t base;
208         uintptr_t lmt_addr;
209         uint16_t scalar_ena;
210         uint16_t max_sqb_count;
211         uint16_t rx_offload_flags; /* Selected Rx offload flags(NIX_RX_*_F) */
212         uint64_t rx_offloads;
213         uint16_t tx_offload_flags; /* Selected Tx offload flags(NIX_TX_*_F) */
214         uint64_t tx_offloads;
215         uint64_t rx_offload_capa;
216         uint64_t tx_offload_capa;
217         struct otx2_qint qints_mem[RTE_MAX_QUEUES_PER_PORT];
218         uint16_t txschq[NIX_TXSCH_LVL_CNT];
219         uint16_t txschq_contig[NIX_TXSCH_LVL_CNT];
220         uint16_t txschq_index[NIX_TXSCH_LVL_CNT];
221         uint16_t txschq_contig_index[NIX_TXSCH_LVL_CNT];
222         /* Dis-contiguous queues */
223         uint16_t txschq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
224         /* Contiguous queues */
225         uint16_t txschq_contig_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
226         uint16_t otx2_tm_root_lvl;
227         uint16_t tm_flags;
228         uint16_t tm_leaf_cnt;
229         struct otx2_nix_tm_node_list node_list;
230         struct otx2_nix_tm_shaper_profile_list shaper_profile_list;
231         struct otx2_rss_info rss_info;
232         struct otx2_fc_info fc_info;
233         uint32_t txmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
234         uint32_t rxmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
235         struct otx2_npc_flow_info npc_flow;
236         struct otx2_eth_qconf *tx_qconf;
237         struct otx2_eth_qconf *rx_qconf;
238         struct rte_eth_dev *eth_dev;
239         /* PTP counters */
240         bool ptp_en;
241         struct otx2_timesync_info tstamp;
242         struct rte_timecounter  systime_tc;
243         struct rte_timecounter  rx_tstamp_tc;
244         struct rte_timecounter  tx_tstamp_tc;
245 } __rte_cache_aligned;
246
247 struct otx2_eth_txq {
248         uint64_t cmd[8];
249         int64_t fc_cache_pkts;
250         uint64_t *fc_mem;
251         void *lmt_addr;
252         rte_iova_t io_addr;
253         rte_iova_t fc_iova;
254         uint16_t sqes_per_sqb_log2;
255         int16_t nb_sqb_bufs_adj;
256         MARKER slow_path_start;
257         uint16_t nb_sqb_bufs;
258         uint16_t sq;
259         uint64_t offloads;
260         struct otx2_eth_dev *dev;
261         struct rte_mempool *sqb_pool;
262         struct otx2_eth_qconf qconf;
263 } __rte_cache_aligned;
264
265 struct otx2_eth_rxq {
266         uint64_t mbuf_initializer;
267         uint64_t data_off;
268         uintptr_t desc;
269         void *lookup_mem;
270         uintptr_t cq_door;
271         uint64_t wdata;
272         int64_t *cq_status;
273         uint32_t head;
274         uint32_t qmask;
275         uint32_t available;
276         uint16_t rq;
277         struct otx2_timesync_info *tstamp;
278         MARKER slow_path_start;
279         uint64_t aura;
280         uint64_t offloads;
281         uint32_t qlen;
282         struct rte_mempool *pool;
283         enum nix_q_size_e qsize;
284         struct rte_eth_dev *eth_dev;
285         struct otx2_eth_qconf qconf;
286 } __rte_cache_aligned;
287
288 static inline struct otx2_eth_dev *
289 otx2_eth_pmd_priv(struct rte_eth_dev *eth_dev)
290 {
291         return eth_dev->data->dev_private;
292 }
293
294 /* Ops */
295 void otx2_nix_info_get(struct rte_eth_dev *eth_dev,
296                        struct rte_eth_dev_info *dev_info);
297 int otx2_nix_get_module_info(struct rte_eth_dev *eth_dev,
298                              struct rte_eth_dev_module_info *modinfo);
299 int otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
300                                struct rte_dev_eeprom_info *info);
301 int otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool);
302 void otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
303                            struct rte_eth_rxq_info *qinfo);
304 void otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
305                            struct rte_eth_txq_info *qinfo);
306 uint32_t otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t qidx);
307 int otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt);
308 int otx2_nix_rx_descriptor_done(void *rxq, uint16_t offset);
309 int otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset);
310
311 void otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en);
312 void otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev);
313 void otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev);
314 void otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev);
315 void otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev);
316 int otx2_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qidx);
317 int otx2_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx);
318 uint64_t otx2_nix_rxq_mbuf_setup(struct otx2_eth_dev *dev, uint16_t port_id);
319
320 /* Link */
321 void otx2_nix_toggle_flag_link_cfg(struct otx2_eth_dev *dev, bool set);
322 int otx2_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete);
323 void otx2_eth_dev_link_status_update(struct otx2_dev *dev,
324                                      struct cgx_link_user_info *link);
325
326 /* IRQ */
327 int otx2_nix_register_irqs(struct rte_eth_dev *eth_dev);
328 int oxt2_nix_register_queue_irqs(struct rte_eth_dev *eth_dev);
329 void otx2_nix_unregister_irqs(struct rte_eth_dev *eth_dev);
330 void oxt2_nix_unregister_queue_irqs(struct rte_eth_dev *eth_dev);
331
332 /* Debug */
333 int otx2_nix_reg_dump(struct otx2_eth_dev *dev, uint64_t *data);
334 int otx2_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
335                          struct rte_dev_reg_info *regs);
336 int otx2_nix_queues_ctx_dump(struct rte_eth_dev *eth_dev);
337 void otx2_nix_cqe_dump(const struct nix_cqe_hdr_s *cq);
338
339 /* Stats */
340 int otx2_nix_dev_stats_get(struct rte_eth_dev *eth_dev,
341                            struct rte_eth_stats *stats);
342 void otx2_nix_dev_stats_reset(struct rte_eth_dev *eth_dev);
343
344 int otx2_nix_queue_stats_mapping(struct rte_eth_dev *dev,
345                                  uint16_t queue_id, uint8_t stat_idx,
346                                  uint8_t is_rx);
347 int otx2_nix_xstats_get(struct rte_eth_dev *eth_dev,
348                         struct rte_eth_xstat *xstats, unsigned int n);
349 int otx2_nix_xstats_get_names(struct rte_eth_dev *eth_dev,
350                               struct rte_eth_xstat_name *xstats_names,
351                               unsigned int limit);
352 void otx2_nix_xstats_reset(struct rte_eth_dev *eth_dev);
353
354 int otx2_nix_xstats_get_by_id(struct rte_eth_dev *eth_dev,
355                               const uint64_t *ids,
356                               uint64_t *values, unsigned int n);
357 int otx2_nix_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
358                                     struct rte_eth_xstat_name *xstats_names,
359                                     const uint64_t *ids, unsigned int limit);
360
361 /* RSS */
362 void otx2_nix_rss_set_key(struct otx2_eth_dev *dev,
363                           uint8_t *key, uint32_t key_len);
364 uint32_t otx2_rss_ethdev_to_nix(struct otx2_eth_dev *dev,
365                                 uint64_t ethdev_rss, uint8_t rss_level);
366 int otx2_rss_set_hf(struct otx2_eth_dev *dev,
367                     uint32_t flowkey_cfg, uint8_t *alg_idx,
368                     uint8_t group, int mcam_index);
369 int otx2_nix_rss_tbl_init(struct otx2_eth_dev *dev, uint8_t group,
370                           uint16_t *ind_tbl);
371 int otx2_nix_rss_config(struct rte_eth_dev *eth_dev);
372
373 int otx2_nix_dev_reta_update(struct rte_eth_dev *eth_dev,
374                              struct rte_eth_rss_reta_entry64 *reta_conf,
375                              uint16_t reta_size);
376 int otx2_nix_dev_reta_query(struct rte_eth_dev *eth_dev,
377                             struct rte_eth_rss_reta_entry64 *reta_conf,
378                             uint16_t reta_size);
379 int otx2_nix_rss_hash_update(struct rte_eth_dev *eth_dev,
380                              struct rte_eth_rss_conf *rss_conf);
381
382 int otx2_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
383                                struct rte_eth_rss_conf *rss_conf);
384
385 /* CGX */
386 int otx2_cgx_rxtx_start(struct otx2_eth_dev *dev);
387 int otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev);
388 int otx2_cgx_mac_addr_set(struct rte_eth_dev *eth_dev,
389                           struct rte_ether_addr *addr);
390
391 /* Flow Control */
392 int otx2_nix_flow_ctrl_get(struct rte_eth_dev *eth_dev,
393                            struct rte_eth_fc_conf *fc_conf);
394
395 int otx2_nix_flow_ctrl_set(struct rte_eth_dev *eth_dev,
396                            struct rte_eth_fc_conf *fc_conf);
397
398 int otx2_nix_rxchan_bpid_cfg(struct rte_eth_dev *eth_dev, bool enb);
399
400 int otx2_nix_update_flow_ctrl_mode(struct rte_eth_dev *eth_dev);
401
402 /* Lookup configuration */
403 void *otx2_nix_fastpath_lookup_mem_get(void);
404
405 /* PTYPES */
406 const uint32_t *otx2_nix_supported_ptypes_get(struct rte_eth_dev *dev);
407
408 /* Mac address handling */
409 int otx2_nix_mac_addr_set(struct rte_eth_dev *eth_dev,
410                           struct rte_ether_addr *addr);
411 int otx2_nix_mac_addr_get(struct rte_eth_dev *eth_dev, uint8_t *addr);
412 int otx2_nix_mac_addr_add(struct rte_eth_dev *eth_dev,
413                           struct rte_ether_addr *addr,
414                           uint32_t index, uint32_t pool);
415 void otx2_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index);
416 int otx2_cgx_mac_max_entries_get(struct otx2_eth_dev *dev);
417
418 /* Devargs */
419 int otx2_ethdev_parse_devargs(struct rte_devargs *devargs,
420                               struct otx2_eth_dev *dev);
421
422 /* Rx and Tx routines */
423 void otx2_nix_form_default_desc(struct otx2_eth_txq *txq);
424
425 /* Timesync - PTP routines */
426 int otx2_nix_timesync_enable(struct rte_eth_dev *eth_dev);
427 int otx2_nix_timesync_disable(struct rte_eth_dev *eth_dev);
428 int otx2_nix_timesync_read_rx_timestamp(struct rte_eth_dev *eth_dev,
429                                         struct timespec *timestamp,
430                                         uint32_t flags);
431 int otx2_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev,
432                                         struct timespec *timestamp);
433 int otx2_nix_timesync_adjust_time(struct rte_eth_dev *eth_dev, int64_t delta);
434 int otx2_nix_timesync_write_time(struct rte_eth_dev *eth_dev,
435                                  const struct timespec *ts);
436 int otx2_nix_timesync_read_time(struct rte_eth_dev *eth_dev,
437                                 struct timespec *ts);
438 int otx2_eth_dev_ptp_info_update(struct otx2_dev *dev, bool ptp_en);
439
440 #endif /* __OTX2_ETHDEV_H__ */