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