fe533fcc8159a583c17908c57bdef985492f8573
[dpdk.git] / drivers / net / mlx5 / mlx5.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2015 6WIND S.A.
3  * Copyright 2015 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_PMD_MLX5_H_
7 #define RTE_PMD_MLX5_H_
8
9 #include <stddef.h>
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <limits.h>
13 #include <sys/queue.h>
14
15 #include <rte_pci.h>
16 #include <rte_ether.h>
17 #include <ethdev_driver.h>
18 #include <rte_rwlock.h>
19 #include <rte_interrupts.h>
20 #include <rte_errno.h>
21 #include <rte_flow.h>
22 #include <rte_mtr.h>
23
24 #include <mlx5_glue.h>
25 #include <mlx5_devx_cmds.h>
26 #include <mlx5_prm.h>
27 #include <mlx5_common_mp.h>
28 #include <mlx5_common_mr.h>
29 #include <mlx5_common_devx.h>
30
31 #include "mlx5_defs.h"
32 #include "mlx5_utils.h"
33 #include "mlx5_os.h"
34 #include "mlx5_autoconf.h"
35
36
37 #define MLX5_SH(dev) (((struct mlx5_priv *)(dev)->data->dev_private)->sh)
38
39 /*
40  * Number of modification commands.
41  * The maximal actions amount in FW is some constant, and it is 16 in the
42  * latest releases. In some old releases, it will be limited to 8.
43  * Since there is no interface to query the capacity, the maximal value should
44  * be used to allow PMD to create the flow. The validation will be done in the
45  * lower driver layer or FW. A failure will be returned if exceeds the maximal
46  * supported actions number on the root table.
47  * On non-root tables, there is no limitation, but 32 is enough right now.
48  */
49 #define MLX5_MAX_MODIFY_NUM                     32
50 #define MLX5_ROOT_TBL_MODIFY_NUM                16
51
52 enum mlx5_ipool_index {
53 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
54         MLX5_IPOOL_DECAP_ENCAP = 0, /* Pool for encap/decap resource. */
55         MLX5_IPOOL_PUSH_VLAN, /* Pool for push vlan resource. */
56         MLX5_IPOOL_TAG, /* Pool for tag resource. */
57         MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */
58         MLX5_IPOOL_JUMP, /* Pool for jump resource. */
59         MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */
60         MLX5_IPOOL_DEST_ARRAY, /* Pool for destination array resource. */
61         MLX5_IPOOL_TUNNEL_ID, /* Pool for tunnel offload context */
62         MLX5_IPOOL_TNL_TBL_ID, /* Pool for tunnel table ID. */
63 #endif
64         MLX5_IPOOL_MTR, /* Pool for meter resource. */
65         MLX5_IPOOL_MCP, /* Pool for metadata resource. */
66         MLX5_IPOOL_HRXQ, /* Pool for hrxq resource. */
67         MLX5_IPOOL_MLX5_FLOW, /* Pool for mlx5 flow handle. */
68         MLX5_IPOOL_RTE_FLOW, /* Pool for rte_flow. */
69         MLX5_IPOOL_RSS_EXPANTION_FLOW_ID, /* Pool for Queue/RSS flow ID. */
70         MLX5_IPOOL_RSS_SHARED_ACTIONS, /* Pool for RSS shared actions. */
71         MLX5_IPOOL_MTR_POLICY, /* Pool for meter policy resource. */
72         MLX5_IPOOL_MAX,
73 };
74
75 /*
76  * There are three reclaim memory mode supported.
77  * 0(none) means no memory reclaim.
78  * 1(light) means only PMD level reclaim.
79  * 2(aggressive) means both PMD and rdma-core level reclaim.
80  */
81 enum mlx5_reclaim_mem_mode {
82         MLX5_RCM_NONE, /* Don't reclaim memory. */
83         MLX5_RCM_LIGHT, /* Reclaim PMD level. */
84         MLX5_RCM_AGGR, /* Reclaim PMD and rdma-core level. */
85 };
86
87 /* The type of flow. */
88 enum mlx5_flow_type {
89         MLX5_FLOW_TYPE_CTL, /* Control flow. */
90         MLX5_FLOW_TYPE_GEN, /* General flow. */
91         MLX5_FLOW_TYPE_MCP, /* MCP flow. */
92         MLX5_FLOW_TYPE_MAXI,
93 };
94
95 /* Hlist and list callback context. */
96 struct mlx5_flow_cb_ctx {
97         struct rte_eth_dev *dev;
98         struct rte_flow_error *error;
99         void *data;
100         void *data2;
101 };
102
103 /* Device attributes used in mlx5 PMD */
104 struct mlx5_dev_attr {
105         uint64_t        device_cap_flags_ex;
106         int             max_qp_wr;
107         int             max_sge;
108         int             max_cq;
109         int             max_qp;
110         int             max_cqe;
111         uint32_t        max_pd;
112         uint32_t        max_mr;
113         uint32_t        max_srq;
114         uint32_t        max_srq_wr;
115         uint32_t        raw_packet_caps;
116         uint32_t        max_rwq_indirection_table_size;
117         uint32_t        max_tso;
118         uint32_t        tso_supported_qpts;
119         uint64_t        flags;
120         uint64_t        comp_mask;
121         uint32_t        sw_parsing_offloads;
122         uint32_t        min_single_stride_log_num_of_bytes;
123         uint32_t        max_single_stride_log_num_of_bytes;
124         uint32_t        min_single_wqe_log_num_of_strides;
125         uint32_t        max_single_wqe_log_num_of_strides;
126         uint32_t        stride_supported_qpts;
127         uint32_t        tunnel_offloads_caps;
128         char            fw_ver[64];
129 };
130
131 /** Data associated with devices to spawn. */
132 struct mlx5_dev_spawn_data {
133         uint32_t ifindex; /**< Network interface index. */
134         uint32_t max_port; /**< Device maximal port index. */
135         uint32_t phys_port; /**< Device physical port index. */
136         int pf_bond; /**< bonding device PF index. < 0 - no bonding */
137         int numa_node; /**< Device numa node. */
138         struct mlx5_switch_info info; /**< Switch information. */
139         void *phys_dev; /**< Associated physical device. */
140         struct rte_eth_dev *eth_dev; /**< Associated Ethernet device. */
141         struct rte_pci_device *pci_dev; /**< Backend PCI device. */
142         struct mlx5_bond_info *bond_info;
143 };
144
145 /** Data associated with socket messages. */
146 struct mlx5_flow_dump_req  {
147         uint32_t port_id; /**< There are plans in DPDK to extend port_id. */
148         uint64_t flow_id;
149 } __rte_packed;
150
151 struct mlx5_flow_dump_ack {
152         int rc; /**< Return code. */
153 };
154
155 /** Key string for IPC. */
156 #define MLX5_MP_NAME "net_mlx5_mp"
157
158 /** Initialize a multi-process ID. */
159 static inline void
160 mlx5_mp_id_init(struct mlx5_mp_id *mp_id, uint16_t port_id)
161 {
162         mp_id->port_id = port_id;
163         strlcpy(mp_id->name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
164 }
165
166 LIST_HEAD(mlx5_dev_list, mlx5_dev_ctx_shared);
167
168 /* Shared data between primary and secondary processes. */
169 struct mlx5_shared_data {
170         rte_spinlock_t lock;
171         /* Global spinlock for primary and secondary processes. */
172         int init_done; /* Whether primary has done initialization. */
173         unsigned int secondary_cnt; /* Number of secondary processes init'd. */
174         struct mlx5_dev_list mem_event_cb_list;
175         rte_rwlock_t mem_event_rwlock;
176 };
177
178 /* Per-process data structure, not visible to other processes. */
179 struct mlx5_local_data {
180         int init_done; /* Whether a secondary has done initialization. */
181 };
182
183 extern struct mlx5_shared_data *mlx5_shared_data;
184
185 /* Dev ops structs */
186 extern const struct eth_dev_ops mlx5_dev_ops;
187 extern const struct eth_dev_ops mlx5_dev_sec_ops;
188 extern const struct eth_dev_ops mlx5_dev_ops_isolate;
189
190 struct mlx5_counter_ctrl {
191         /* Name of the counter. */
192         char dpdk_name[RTE_ETH_XSTATS_NAME_SIZE];
193         /* Name of the counter on the device table. */
194         char ctr_name[RTE_ETH_XSTATS_NAME_SIZE];
195         uint32_t dev:1; /**< Nonzero for dev counters. */
196 };
197
198 struct mlx5_xstats_ctrl {
199         /* Number of device stats. */
200         uint16_t stats_n;
201         /* Number of device stats identified by PMD. */
202         uint16_t  mlx5_stats_n;
203         /* Index in the device counters table. */
204         uint16_t dev_table_idx[MLX5_MAX_XSTATS];
205         uint64_t base[MLX5_MAX_XSTATS];
206         uint64_t xstats[MLX5_MAX_XSTATS];
207         uint64_t hw_stats[MLX5_MAX_XSTATS];
208         struct mlx5_counter_ctrl info[MLX5_MAX_XSTATS];
209 };
210
211 struct mlx5_stats_ctrl {
212         /* Base for imissed counter. */
213         uint64_t imissed_base;
214         uint64_t imissed;
215 };
216
217 /* Default PMD specific parameter value. */
218 #define MLX5_ARG_UNSET (-1)
219
220 #define MLX5_LRO_SUPPORTED(dev) \
221         (((struct mlx5_priv *)((dev)->data->dev_private))->config.lro.supported)
222
223 /* Maximal size of coalesced segment for LRO is set in chunks of 256 Bytes. */
224 #define MLX5_LRO_SEG_CHUNK_SIZE 256u
225
226 /* Maximal size of aggregated LRO packet. */
227 #define MLX5_MAX_LRO_SIZE (UINT8_MAX * MLX5_LRO_SEG_CHUNK_SIZE)
228
229 /* Maximal number of segments to split. */
230 #define MLX5_MAX_RXQ_NSEG (1u << MLX5_MAX_LOG_RQ_SEGS)
231
232 /* LRO configurations structure. */
233 struct mlx5_lro_config {
234         uint32_t supported:1; /* Whether LRO is supported. */
235         uint32_t timeout; /* User configuration. */
236 };
237
238 /*
239  * Device configuration structure.
240  *
241  * Merged configuration from:
242  *
243  *  - Device capabilities,
244  *  - User device parameters disabled features.
245  */
246 struct mlx5_dev_config {
247         unsigned int hw_csum:1; /* Checksum offload is supported. */
248         unsigned int hw_vlan_strip:1; /* VLAN stripping is supported. */
249         unsigned int hw_vlan_insert:1; /* VLAN insertion in WQE is supported. */
250         unsigned int hw_fcs_strip:1; /* FCS stripping is supported. */
251         unsigned int hw_padding:1; /* End alignment padding is supported. */
252         unsigned int vf:1; /* This is a VF. */
253         unsigned int sf:1; /* This is a SF. */
254         unsigned int tunnel_en:1;
255         /* Whether tunnel stateless offloads are supported. */
256         unsigned int mpls_en:1; /* MPLS over GRE/UDP is enabled. */
257         unsigned int cqe_comp:1; /* CQE compression is enabled. */
258         unsigned int cqe_comp_fmt:3; /* CQE compression format. */
259         unsigned int tso:1; /* Whether TSO is supported. */
260         unsigned int rx_vec_en:1; /* Rx vector is enabled. */
261         unsigned int mr_ext_memseg_en:1;
262         /* Whether memseg should be extended for MR creation. */
263         unsigned int l3_vxlan_en:1; /* Enable L3 VXLAN flow creation. */
264         unsigned int vf_nl_en:1; /* Enable Netlink requests in VF mode. */
265         unsigned int dv_esw_en:1; /* Enable E-Switch DV flow. */
266         unsigned int dv_flow_en:1; /* Enable DV flow. */
267         unsigned int dv_xmeta_en:2; /* Enable extensive flow metadata. */
268         unsigned int lacp_by_user:1;
269         /* Enable user to manage LACP traffic. */
270         unsigned int swp:1; /* Tx generic tunnel checksum and TSO offload. */
271         unsigned int devx:1; /* Whether devx interface is available or not. */
272         unsigned int dest_tir:1; /* Whether advanced DR API is available. */
273         unsigned int reclaim_mode:2; /* Memory reclaim mode. */
274         unsigned int rt_timestamp:1; /* realtime timestamp format. */
275         unsigned int sys_mem_en:1; /* The default memory allocator. */
276         unsigned int decap_en:1; /* Whether decap will be used or not. */
277         unsigned int dv_miss_info:1; /* restore packet after partial hw miss */
278         unsigned int allow_duplicate_pattern:1;
279         /* Allow/Prevent the duplicate rules pattern. */
280         unsigned int mr_mempool_reg_en:1;
281         /* Allow/prevent implicit mempool memory registration. */
282         struct {
283                 unsigned int enabled:1; /* Whether MPRQ is enabled. */
284                 unsigned int stride_num_n; /* Number of strides. */
285                 unsigned int stride_size_n; /* Size of a stride. */
286                 unsigned int min_stride_size_n; /* Min size of a stride. */
287                 unsigned int max_stride_size_n; /* Max size of a stride. */
288                 unsigned int max_memcpy_len;
289                 /* Maximum packet size to memcpy Rx packets. */
290                 unsigned int min_rxqs_num;
291                 /* Rx queue count threshold to enable MPRQ. */
292         } mprq; /* Configurations for Multi-Packet RQ. */
293         int mps; /* Multi-packet send supported mode. */
294         int dbnc; /* Skip doorbell register write barrier. */
295         unsigned int flow_prio; /* Number of flow priorities. */
296         enum modify_reg flow_mreg_c[MLX5_MREG_C_NUM];
297         /* Availibility of mreg_c's. */
298         unsigned int tso_max_payload_sz; /* Maximum TCP payload for TSO. */
299         unsigned int ind_table_max_size; /* Maximum indirection table size. */
300         unsigned int max_dump_files_num; /* Maximum dump files per queue. */
301         unsigned int log_hp_size; /* Single hairpin queue data size in total. */
302         int txqs_inline; /* Queue number threshold for inlining. */
303         int txq_inline_min; /* Minimal amount of data bytes to inline. */
304         int txq_inline_max; /* Max packet size for inlining with SEND. */
305         int txq_inline_mpw; /* Max packet size for inlining with eMPW. */
306         int tx_pp; /* Timestamp scheduling granularity in nanoseconds. */
307         int tx_skew; /* Tx scheduling skew between WQE and data on wire. */
308         struct mlx5_hca_attr hca_attr; /* HCA attributes. */
309         struct mlx5_lro_config lro; /* LRO configuration. */
310 };
311
312
313 /* Structure for VF VLAN workaround. */
314 struct mlx5_vf_vlan {
315         uint32_t tag:12;
316         uint32_t created:1;
317 };
318
319 /* Flow drop context necessary due to Verbs API. */
320 struct mlx5_drop {
321         struct mlx5_hrxq *hrxq; /* Hash Rx queue queue. */
322         struct mlx5_rxq_obj *rxq; /* Rx queue object. */
323 };
324
325 /* Loopback dummy queue resources required due to Verbs API. */
326 struct mlx5_lb_ctx {
327         struct ibv_qp *qp; /* QP object. */
328         void *ibv_cq; /* Completion queue. */
329         uint16_t refcnt; /* Reference count for representors. */
330 };
331
332 #define MLX5_COUNTERS_PER_POOL 512
333 #define MLX5_MAX_PENDING_QUERIES 4
334 #define MLX5_CNT_CONTAINER_RESIZE 64
335 #define MLX5_CNT_SHARED_OFFSET 0x80000000
336 #define IS_LEGACY_SHARED_CNT(cnt) (!!((cnt) & MLX5_CNT_SHARED_OFFSET))
337 #define IS_BATCH_CNT(cnt) (((cnt) & (MLX5_CNT_SHARED_OFFSET - 1)) >= \
338                            MLX5_CNT_BATCH_OFFSET)
339 #define MLX5_CNT_SIZE (sizeof(struct mlx5_flow_counter))
340 #define MLX5_AGE_SIZE (sizeof(struct mlx5_age_param))
341
342 #define MLX5_CNT_LEN(pool) \
343         (MLX5_CNT_SIZE + \
344         ((pool)->is_aged ? MLX5_AGE_SIZE : 0))
345 #define MLX5_POOL_GET_CNT(pool, index) \
346         ((struct mlx5_flow_counter *) \
347         ((uint8_t *)((pool) + 1) + (index) * (MLX5_CNT_LEN(pool))))
348 #define MLX5_CNT_ARRAY_IDX(pool, cnt) \
349         ((int)(((uint8_t *)(cnt) - (uint8_t *)((pool) + 1)) / \
350         MLX5_CNT_LEN(pool)))
351 /*
352  * The pool index and offset of counter in the pool array makes up the
353  * counter index. In case the counter is from pool 0 and offset 0, it
354  * should plus 1 to avoid index 0, since 0 means invalid counter index
355  * currently.
356  */
357 #define MLX5_MAKE_CNT_IDX(pi, offset) \
358         ((pi) * MLX5_COUNTERS_PER_POOL + (offset) + 1)
359 #define MLX5_CNT_TO_AGE(cnt) \
360         ((struct mlx5_age_param *)((cnt) + 1))
361 /*
362  * The maximum single counter is 0x800000 as MLX5_CNT_BATCH_OFFSET
363  * defines. The pool size is 512, pool index should never reach
364  * INT16_MAX.
365  */
366 #define POOL_IDX_INVALID UINT16_MAX
367
368 /* Age status. */
369 enum {
370         AGE_FREE, /* Initialized state. */
371         AGE_CANDIDATE, /* Counter assigned to flows. */
372         AGE_TMOUT, /* Timeout, wait for rte_flow_get_aged_flows and destroy. */
373 };
374
375 enum mlx5_counter_type {
376         MLX5_COUNTER_TYPE_ORIGIN,
377         MLX5_COUNTER_TYPE_AGE,
378         MLX5_COUNTER_TYPE_MAX,
379 };
380
381 /* Counter age parameter. */
382 struct mlx5_age_param {
383         uint16_t state; /**< Age state (atomically accessed). */
384         uint16_t port_id; /**< Port id of the counter. */
385         uint32_t timeout:24; /**< Aging timeout in seconds. */
386         uint32_t sec_since_last_hit;
387         /**< Time in seconds since last hit (atomically accessed). */
388         void *context; /**< Flow counter age context. */
389 };
390
391 struct flow_counter_stats {
392         uint64_t hits;
393         uint64_t bytes;
394 };
395
396 /* Shared counters information for counters. */
397 struct mlx5_flow_counter_shared {
398         union {
399                 uint32_t refcnt; /* Only for shared action management. */
400                 uint32_t id; /* User counter ID for legacy sharing. */
401         };
402 };
403
404 /* Shared counter configuration. */
405 struct mlx5_shared_counter_conf {
406         struct rte_eth_dev *dev; /* The device shared counter belongs to. */
407         uint32_t id; /* The shared counter ID. */
408 };
409
410 struct mlx5_flow_counter_pool;
411 /* Generic counters information. */
412 struct mlx5_flow_counter {
413         union {
414                 /*
415                  * User-defined counter shared info is only used during
416                  * counter active time. And aging counter sharing is not
417                  * supported, so active shared counter will not be chained
418                  * to the aging list. For shared counter, only when it is
419                  * released, the TAILQ entry memory will be used, at that
420                  * time, shared memory is not used anymore.
421                  *
422                  * Similarly to none-batch counter dcs, since it doesn't
423                  * support aging, while counter is allocated, the entry
424                  * memory is not used anymore. In this case, as bytes
425                  * memory is used only when counter is allocated, and
426                  * entry memory is used only when counter is free. The
427                  * dcs pointer can be saved to these two different place
428                  * at different stage. It will eliminate the individual
429                  * counter extend struct.
430                  */
431                 TAILQ_ENTRY(mlx5_flow_counter) next;
432                 /**< Pointer to the next flow counter structure. */
433                 struct {
434                         struct mlx5_flow_counter_shared shared_info;
435                         /**< Shared counter information. */
436                         void *dcs_when_active;
437                         /*
438                          * For non-batch mode, the dcs will be saved
439                          * here when the counter is free.
440                          */
441                 };
442         };
443         union {
444                 uint64_t hits; /**< Reset value of hits packets. */
445                 struct mlx5_flow_counter_pool *pool; /**< Counter pool. */
446         };
447         union {
448                 uint64_t bytes; /**< Reset value of bytes. */
449                 void *dcs_when_free;
450                 /*
451                  * For non-batch mode, the dcs will be saved here
452                  * when the counter is free.
453                  */
454         };
455         void *action; /**< Pointer to the dv action. */
456 };
457
458 TAILQ_HEAD(mlx5_counters, mlx5_flow_counter);
459
460 /* Generic counter pool structure - query is in pool resolution. */
461 struct mlx5_flow_counter_pool {
462         TAILQ_ENTRY(mlx5_flow_counter_pool) next;
463         struct mlx5_counters counters[2]; /* Free counter list. */
464         struct mlx5_devx_obj *min_dcs;
465         /* The devx object of the minimum counter ID. */
466         uint64_t time_of_last_age_check;
467         /* System time (from rte_rdtsc()) read in the last aging check. */
468         uint32_t index:30; /* Pool index in container. */
469         uint32_t is_aged:1; /* Pool with aging counter. */
470         volatile uint32_t query_gen:1; /* Query round. */
471         rte_spinlock_t sl; /* The pool lock. */
472         rte_spinlock_t csl; /* The pool counter free list lock. */
473         struct mlx5_counter_stats_raw *raw;
474         struct mlx5_counter_stats_raw *raw_hw;
475         /* The raw on HW working. */
476 };
477
478 /* Memory management structure for group of counter statistics raws. */
479 struct mlx5_counter_stats_mem_mng {
480         LIST_ENTRY(mlx5_counter_stats_mem_mng) next;
481         struct mlx5_counter_stats_raw *raws;
482         struct mlx5_devx_obj *dm;
483         void *umem;
484 };
485
486 /* Raw memory structure for the counter statistics values of a pool. */
487 struct mlx5_counter_stats_raw {
488         LIST_ENTRY(mlx5_counter_stats_raw) next;
489         struct mlx5_counter_stats_mem_mng *mem_mng;
490         volatile struct flow_counter_stats *data;
491 };
492
493 TAILQ_HEAD(mlx5_counter_pools, mlx5_flow_counter_pool);
494
495 /* Counter global management structure. */
496 struct mlx5_flow_counter_mng {
497         volatile uint16_t n_valid; /* Number of valid pools. */
498         uint16_t n; /* Number of pools. */
499         uint16_t last_pool_idx; /* Last used pool index */
500         int min_id; /* The minimum counter ID in the pools. */
501         int max_id; /* The maximum counter ID in the pools. */
502         rte_spinlock_t pool_update_sl; /* The pool update lock. */
503         rte_spinlock_t csl[MLX5_COUNTER_TYPE_MAX];
504         /* The counter free list lock. */
505         struct mlx5_counters counters[MLX5_COUNTER_TYPE_MAX];
506         /* Free counter list. */
507         struct mlx5_flow_counter_pool **pools; /* Counter pool array. */
508         struct mlx5_counter_stats_mem_mng *mem_mng;
509         /* Hold the memory management for the next allocated pools raws. */
510         struct mlx5_counters flow_counters; /* Legacy flow counter list. */
511         uint8_t pending_queries;
512         uint16_t pool_index;
513         uint8_t query_thread_on;
514         bool relaxed_ordering_read;
515         bool relaxed_ordering_write;
516         bool counter_fallback; /* Use counter fallback management. */
517         LIST_HEAD(mem_mngs, mlx5_counter_stats_mem_mng) mem_mngs;
518         LIST_HEAD(stat_raws, mlx5_counter_stats_raw) free_stat_raws;
519 };
520
521 /* ASO structures. */
522 #define MLX5_ASO_QUEUE_LOG_DESC 10
523
524 struct mlx5_aso_cq {
525         uint16_t log_desc_n;
526         uint32_t cq_ci:24;
527         struct mlx5_devx_cq cq_obj;
528         uint64_t errors;
529 };
530
531 struct mlx5_aso_sq_elem {
532         union {
533                 struct {
534                         struct mlx5_aso_age_pool *pool;
535                         uint16_t burst_size;
536                 };
537                 struct mlx5_aso_mtr *mtr;
538                 struct {
539                         struct mlx5_aso_ct_action *ct;
540                         char *query_data;
541                 };
542         };
543 };
544
545 struct mlx5_aso_sq {
546         uint16_t log_desc_n;
547         rte_spinlock_t sqsl;
548         struct mlx5_aso_cq cq;
549         struct mlx5_devx_sq sq_obj;
550         volatile uint64_t *uar_addr;
551         struct mlx5_pmd_mr mr;
552         uint16_t pi;
553         uint32_t head;
554         uint32_t tail;
555         uint32_t sqn;
556         struct mlx5_aso_sq_elem elts[1 << MLX5_ASO_QUEUE_LOG_DESC];
557         uint16_t next; /* Pool index of the next pool to query. */
558 };
559
560 struct mlx5_aso_age_action {
561         LIST_ENTRY(mlx5_aso_age_action) next;
562         void *dr_action;
563         uint32_t refcnt;
564         /* Following fields relevant only when action is active. */
565         uint16_t offset; /* Offset of ASO Flow Hit flag in DevX object. */
566         struct mlx5_age_param age_params;
567 };
568
569 #define MLX5_ASO_AGE_ACTIONS_PER_POOL 512
570
571 struct mlx5_aso_age_pool {
572         struct mlx5_devx_obj *flow_hit_aso_obj;
573         uint16_t index; /* Pool index in pools array. */
574         uint64_t time_of_last_age_check; /* In seconds. */
575         struct mlx5_aso_age_action actions[MLX5_ASO_AGE_ACTIONS_PER_POOL];
576 };
577
578 LIST_HEAD(aso_age_list, mlx5_aso_age_action);
579
580 struct mlx5_aso_age_mng {
581         struct mlx5_aso_age_pool **pools;
582         uint16_t n; /* Total number of pools. */
583         uint16_t next; /* Number of pools in use, index of next free pool. */
584         rte_spinlock_t resize_sl; /* Lock for resize objects. */
585         rte_spinlock_t free_sl; /* Lock for free list access. */
586         struct aso_age_list free; /* Free age actions list - ready to use. */
587         struct mlx5_aso_sq aso_sq; /* ASO queue objects. */
588 };
589
590 /* Management structure for geneve tlv option */
591 struct mlx5_geneve_tlv_option_resource {
592         struct mlx5_devx_obj *obj; /* Pointer to the geneve tlv opt object. */
593         rte_be16_t option_class; /* geneve tlv opt class.*/
594         uint8_t option_type; /* geneve tlv opt type.*/
595         uint8_t length; /* geneve tlv opt length. */
596         uint32_t refcnt; /* geneve tlv object reference counter */
597 };
598
599
600 #define MLX5_AGE_EVENT_NEW              1
601 #define MLX5_AGE_TRIGGER                2
602 #define MLX5_AGE_SET(age_info, BIT) \
603         ((age_info)->flags |= (1 << (BIT)))
604 #define MLX5_AGE_UNSET(age_info, BIT) \
605         ((age_info)->flags &= ~(1 << (BIT)))
606 #define MLX5_AGE_GET(age_info, BIT) \
607         ((age_info)->flags & (1 << (BIT)))
608 #define GET_PORT_AGE_INFO(priv) \
609         (&((priv)->sh->port[(priv)->dev_port - 1].age_info))
610 /* Current time in seconds. */
611 #define MLX5_CURR_TIME_SEC      (rte_rdtsc() / rte_get_tsc_hz())
612
613 /* Aging information for per port. */
614 struct mlx5_age_info {
615         uint8_t flags; /* Indicate if is new event or need to be triggered. */
616         struct mlx5_counters aged_counters; /* Aged counter list. */
617         struct aso_age_list aged_aso; /* Aged ASO actions list. */
618         rte_spinlock_t aged_sl; /* Aged flow list lock. */
619 };
620
621 /* Per port data of shared IB device. */
622 struct mlx5_dev_shared_port {
623         uint32_t ih_port_id;
624         uint32_t devx_ih_port_id;
625         /*
626          * Interrupt handler port_id. Used by shared interrupt
627          * handler to find the corresponding rte_eth device
628          * by IB port index. If value is equal or greater
629          * RTE_MAX_ETHPORTS it means there is no subhandler
630          * installed for specified IB port index.
631          */
632         struct mlx5_age_info age_info;
633         /* Aging information for per port. */
634 };
635
636 /*
637  * Max number of actions per DV flow.
638  * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED
639  * in rdma-core file providers/mlx5/verbs.c.
640  */
641 #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8
642
643 /* ASO flow meter structures */
644 /* Modify this value if enum rte_mtr_color changes. */
645 #define RTE_MTR_DROPPED RTE_COLORS
646 /* Yellow is now supported. */
647 #define MLX5_MTR_RTE_COLORS (RTE_COLOR_YELLOW + 1)
648 /* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */
649 #define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF
650 #define MLX5_INVALID_POLICY_ID UINT32_MAX
651 /* Suffix table_id on MLX5_FLOW_TABLE_LEVEL_METER. */
652 #define MLX5_MTR_TABLE_ID_SUFFIX 1
653 /* Drop table_id on MLX5_FLOW_TABLE_LEVEL_METER. */
654 #define MLX5_MTR_TABLE_ID_DROP 2
655 /* Priority of the meter policy matcher. */
656 #define MLX5_MTR_POLICY_MATCHER_PRIO 0
657 /* Default policy. */
658 #define MLX5_MTR_POLICY_MODE_DEF 1
659 /* Only green color valid. */
660 #define MLX5_MTR_POLICY_MODE_OG 2
661 /* Only yellow color valid. */
662 #define MLX5_MTR_POLICY_MODE_OY 3
663
664 enum mlx5_meter_domain {
665         MLX5_MTR_DOMAIN_INGRESS,
666         MLX5_MTR_DOMAIN_EGRESS,
667         MLX5_MTR_DOMAIN_TRANSFER,
668         MLX5_MTR_DOMAIN_MAX,
669 };
670 #define MLX5_MTR_DOMAIN_INGRESS_BIT  (1 << MLX5_MTR_DOMAIN_INGRESS)
671 #define MLX5_MTR_DOMAIN_EGRESS_BIT   (1 << MLX5_MTR_DOMAIN_EGRESS)
672 #define MLX5_MTR_DOMAIN_TRANSFER_BIT (1 << MLX5_MTR_DOMAIN_TRANSFER)
673 #define MLX5_MTR_ALL_DOMAIN_BIT      (MLX5_MTR_DOMAIN_INGRESS_BIT | \
674                                         MLX5_MTR_DOMAIN_EGRESS_BIT | \
675                                         MLX5_MTR_DOMAIN_TRANSFER_BIT)
676
677 /* The color tag rule structure. */
678 struct mlx5_sub_policy_color_rule {
679         void *rule;
680         /* The color rule. */
681         struct mlx5_flow_dv_matcher *matcher;
682         /* The color matcher. */
683         TAILQ_ENTRY(mlx5_sub_policy_color_rule) next_port;
684         /**< Pointer to the next color rule structure. */
685         int32_t src_port;
686         /* On which src port this rule applied. */
687 };
688
689 TAILQ_HEAD(mlx5_sub_policy_color_rules, mlx5_sub_policy_color_rule);
690
691 /*
692  * Meter sub-policy structure.
693  * Each RSS TIR in meter policy need its own sub-policy resource.
694  */
695 struct mlx5_flow_meter_sub_policy {
696         uint32_t main_policy_id:1;
697         /* Main policy id is same as this sub_policy id. */
698         uint32_t idx:31;
699         /* Index to sub_policy ipool entity. */
700         void *main_policy;
701         /* Point to struct mlx5_flow_meter_policy. */
702         struct mlx5_flow_tbl_resource *tbl_rsc;
703         /* The sub-policy table resource. */
704         uint32_t rix_hrxq[MLX5_MTR_RTE_COLORS];
705         /* Index to TIR resource. */
706         struct mlx5_flow_tbl_resource *jump_tbl[MLX5_MTR_RTE_COLORS];
707         /* Meter jump/drop table. */
708         struct mlx5_sub_policy_color_rules color_rules[RTE_COLORS];
709         /* List for the color rules. */
710 };
711
712 struct mlx5_meter_policy_acts {
713         uint8_t actions_n;
714         /* Number of actions. */
715         void *dv_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS];
716         /* Action list. */
717 };
718
719 struct mlx5_meter_policy_action_container {
720         uint32_t rix_mark;
721         /* Index to the mark action. */
722         struct mlx5_flow_dv_modify_hdr_resource *modify_hdr;
723         /* Pointer to modify header resource in cache. */
724         uint8_t fate_action;
725         /* Fate action type. */
726         union {
727                 struct rte_flow_action *rss;
728                 /* Rss action configuration. */
729                 uint32_t rix_port_id_action;
730                 /* Index to port ID action resource. */
731                 void *dr_jump_action[MLX5_MTR_DOMAIN_MAX];
732                 /* Jump/drop action per color. */
733                 uint16_t queue;
734                 /* Queue action configuration. */
735                 struct {
736                         uint32_t next_mtr_id;
737                         /* The next meter id. */
738                         void *next_sub_policy;
739                         /* Next meter's sub-policy. */
740                 };
741         };
742 };
743
744 /* Flow meter policy parameter structure. */
745 struct mlx5_flow_meter_policy {
746         struct rte_eth_dev *dev;
747         /* The port dev on which policy is created. */
748         uint32_t is_rss:1;
749         /* Is RSS policy table. */
750         uint32_t ingress:1;
751         /* Rule applies to ingress domain. */
752         uint32_t egress:1;
753         /* Rule applies to egress domain. */
754         uint32_t transfer:1;
755         /* Rule applies to transfer domain. */
756         uint32_t is_queue:1;
757         /* Is queue action in policy table. */
758         uint32_t is_hierarchy:1;
759         /* Is meter action in policy table. */
760         uint32_t skip_y:1;
761         /* If yellow color policy is skipped. */
762         uint32_t skip_g:1;
763         /* If green color policy is skipped. */
764         rte_spinlock_t sl;
765         uint32_t ref_cnt;
766         /* Use count. */
767         struct mlx5_meter_policy_action_container act_cnt[MLX5_MTR_RTE_COLORS];
768         /* Policy actions container. */
769         void *dr_drop_action[MLX5_MTR_DOMAIN_MAX];
770         /* drop action for red color. */
771         uint16_t sub_policy_num;
772         /* Count sub policy tables, 3 bits per domain. */
773         struct mlx5_flow_meter_sub_policy **sub_policys[MLX5_MTR_DOMAIN_MAX];
774         /* Sub policy table array must be the end of struct. */
775 };
776
777 /* The maximum sub policy is relate to struct mlx5_rss_hash_fields[]. */
778 #define MLX5_MTR_RSS_MAX_SUB_POLICY 7
779 #define MLX5_MTR_SUB_POLICY_NUM_SHIFT  3
780 #define MLX5_MTR_SUB_POLICY_NUM_MASK  0x7
781 #define MLX5_MTRS_DEFAULT_RULE_PRIORITY 0xFFFF
782 #define MLX5_MTR_CHAIN_MAX_NUM 8
783
784 /* Flow meter default policy parameter structure.
785  * Policy index 0 is reserved by default policy table.
786  * Action per color as below:
787  * green - do nothing, yellow - do nothing, red - drop
788  */
789 struct mlx5_flow_meter_def_policy {
790         struct mlx5_flow_meter_sub_policy sub_policy;
791         /* Policy rules jump to other tables. */
792         void *dr_jump_action[RTE_COLORS];
793         /* Jump action per color. */
794 };
795
796 /* Meter parameter structure. */
797 struct mlx5_flow_meter_info {
798         uint32_t meter_id;
799         /**< Meter id. */
800         uint32_t policy_id;
801         /* Policy id, the first sub_policy idx. */
802         struct mlx5_flow_meter_profile *profile;
803         /**< Meter profile parameters. */
804         rte_spinlock_t sl; /**< Meter action spinlock. */
805         /** Set of stats counters to be enabled.
806          * @see enum rte_mtr_stats_type
807          */
808         uint32_t bytes_dropped:1;
809         /** Set bytes dropped stats to be enabled. */
810         uint32_t pkts_dropped:1;
811         /** Set packets dropped stats to be enabled. */
812         uint32_t active_state:1;
813         /**< Meter hw active state. */
814         uint32_t shared:1;
815         /**< Meter shared or not. */
816         uint32_t is_enable:1;
817         /**< Meter disable/enable state. */
818         uint32_t ingress:1;
819         /**< Rule applies to egress traffic. */
820         uint32_t egress:1;
821         /**
822          * Instead of simply matching the properties of traffic as it would
823          * appear on a given DPDK port ID, enabling this attribute transfers
824          * a flow rule to the lowest possible level of any device endpoints
825          * found in the pattern.
826          *
827          * When supported, this effectively enables an application to
828          * re-route traffic not necessarily intended for it (e.g. coming
829          * from or addressed to different physical ports, VFs or
830          * applications) at the device level.
831          *
832          * It complements the behavior of some pattern items such as
833          * RTE_FLOW_ITEM_TYPE_PHY_PORT and is meaningless without them.
834          *
835          * When transferring flow rules, ingress and egress attributes keep
836          * their original meaning, as if processing traffic emitted or
837          * received by the application.
838          */
839         uint32_t transfer:1;
840         uint32_t def_policy:1;
841         /* Meter points to default policy. */
842         void *drop_rule[MLX5_MTR_DOMAIN_MAX];
843         /* Meter drop rule in drop table. */
844         uint32_t drop_cnt;
845         /**< Color counter for drop. */
846         uint32_t ref_cnt;
847         /**< Use count. */
848         struct mlx5_indexed_pool *flow_ipool;
849         /**< Index pool for flow id. */
850         void *meter_action;
851         /**< Flow meter action. */
852 };
853
854 /* PPS(packets per second) map to BPS(Bytes per second).
855  * HW treat packet as 128bytes in PPS mode
856  */
857 #define MLX5_MTRS_PPS_MAP_BPS_SHIFT 7
858
859 /* RFC2697 parameter structure. */
860 struct mlx5_flow_meter_srtcm_rfc2697_prm {
861         rte_be32_t cbs_cir;
862         /*
863          * bit 24-28: cbs_exponent, bit 16-23 cbs_mantissa,
864          * bit 8-12: cir_exponent, bit 0-7 cir_mantissa.
865          */
866         rte_be32_t ebs_eir;
867         /*
868          * bit 24-28: ebs_exponent, bit 16-23 ebs_mantissa,
869          * bit 8-12: eir_exponent, bit 0-7 eir_mantissa.
870          */
871 };
872
873 /* Flow meter profile structure. */
874 struct mlx5_flow_meter_profile {
875         TAILQ_ENTRY(mlx5_flow_meter_profile) next;
876         /**< Pointer to the next flow meter structure. */
877         uint32_t id; /**< Profile id. */
878         struct rte_mtr_meter_profile profile; /**< Profile detail. */
879         union {
880                 struct mlx5_flow_meter_srtcm_rfc2697_prm srtcm_prm;
881                 /**< srtcm_rfc2697 struct. */
882         };
883         uint32_t ref_cnt; /**< Use count. */
884         uint32_t g_support:1; /**< If G color will be generated. */
885         uint32_t y_support:1; /**< If Y color will be generated. */
886 };
887
888 /* 2 meters in each ASO cache line */
889 #define MLX5_MTRS_CONTAINER_RESIZE 64
890 /*
891  * The pool index and offset of meter in the pool array makes up the
892  * meter index. In case the meter is from pool 0 and offset 0, it
893  * should plus 1 to avoid index 0, since 0 means invalid meter index
894  * currently.
895  */
896 #define MLX5_MAKE_MTR_IDX(pi, offset) \
897                 ((pi) * MLX5_ASO_MTRS_PER_POOL + (offset) + 1)
898
899 /*aso flow meter state*/
900 enum mlx5_aso_mtr_state {
901         ASO_METER_FREE, /* In free list. */
902         ASO_METER_WAIT, /* ACCESS_ASO WQE in progress. */
903         ASO_METER_READY, /* CQE received. */
904 };
905
906 /* Generic aso_flow_meter information. */
907 struct mlx5_aso_mtr {
908         LIST_ENTRY(mlx5_aso_mtr) next;
909         struct mlx5_flow_meter_info fm;
910         /**< Pointer to the next aso flow meter structure. */
911         uint8_t state; /**< ASO flow meter state. */
912         uint8_t offset;
913 };
914
915 /* Generic aso_flow_meter pool structure. */
916 struct mlx5_aso_mtr_pool {
917         struct mlx5_aso_mtr mtrs[MLX5_ASO_MTRS_PER_POOL];
918         /*Must be the first in pool*/
919         struct mlx5_devx_obj *devx_obj;
920         /* The devx object of the minimum aso flow meter ID. */
921         uint32_t index; /* Pool index in management structure. */
922 };
923
924 LIST_HEAD(aso_meter_list, mlx5_aso_mtr);
925 /* Pools management structure for ASO flow meter pools. */
926 struct mlx5_aso_mtr_pools_mng {
927         volatile uint16_t n_valid; /* Number of valid pools. */
928         uint16_t n; /* Number of pools. */
929         rte_spinlock_t mtrsl; /* The ASO flow meter free list lock. */
930         struct aso_meter_list meters; /* Free ASO flow meter list. */
931         struct mlx5_aso_sq sq; /*SQ using by ASO flow meter. */
932         struct mlx5_aso_mtr_pool **pools; /* ASO flow meter pool array. */
933 };
934
935 /* Meter management structure for global flow meter resource. */
936 struct mlx5_flow_mtr_mng {
937         struct mlx5_aso_mtr_pools_mng pools_mng;
938         /* Pools management structure for ASO flow meter pools. */
939         struct mlx5_flow_meter_def_policy *def_policy[MLX5_MTR_DOMAIN_MAX];
940         /* Default policy table. */
941         uint32_t def_policy_id;
942         /* Default policy id. */
943         uint32_t def_policy_ref_cnt;
944         /** def_policy meter use count. */
945         struct mlx5_flow_tbl_resource *drop_tbl[MLX5_MTR_DOMAIN_MAX];
946         /* Meter drop table. */
947         struct mlx5_flow_dv_matcher *
948                         drop_matcher[MLX5_MTR_DOMAIN_MAX][MLX5_REG_BITS];
949         /* Matcher meter in drop table. */
950         struct mlx5_flow_dv_matcher *def_matcher[MLX5_MTR_DOMAIN_MAX];
951         /* Default matcher in drop table. */
952         void *def_rule[MLX5_MTR_DOMAIN_MAX];
953         /* Default rule in drop table. */
954         uint8_t max_mtr_bits;
955         /* Indicate how many bits are used by meter id at the most. */
956         uint8_t max_mtr_flow_bits;
957         /* Indicate how many bits are used by meter flow id at the most. */
958 };
959
960 /* Table key of the hash organization. */
961 union mlx5_flow_tbl_key {
962         struct {
963                 /* Table ID should be at the lowest address. */
964                 uint32_t level; /**< Level of the table. */
965                 uint32_t id:22; /**< ID of the table. */
966                 uint32_t dummy:1;       /**< Dummy table for DV API. */
967                 uint32_t is_fdb:1;      /**< 1 - FDB, 0 - NIC TX/RX. */
968                 uint32_t is_egress:1;   /**< 1 - egress, 0 - ingress. */
969                 uint32_t reserved:7;    /**< must be zero for comparison. */
970         };
971         uint64_t v64;                   /**< full 64bits value of key */
972 };
973
974 /* Table structure. */
975 struct mlx5_flow_tbl_resource {
976         void *obj; /**< Pointer to DR table object. */
977         uint32_t refcnt; /**< Reference counter. */
978 };
979
980 #define MLX5_MAX_TABLES UINT16_MAX
981 #define MLX5_HAIRPIN_TX_TABLE (UINT16_MAX - 1)
982 /* Reserve the last two tables for metadata register copy. */
983 #define MLX5_FLOW_MREG_ACT_TABLE_GROUP (MLX5_MAX_TABLES - 1)
984 #define MLX5_FLOW_MREG_CP_TABLE_GROUP (MLX5_MAX_TABLES - 2)
985 /* Tables for metering splits should be added here. */
986 #define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 3)
987 #define MLX5_FLOW_TABLE_LEVEL_POLICY (MLX5_MAX_TABLES - 4)
988 #define MLX5_MAX_TABLES_EXTERNAL MLX5_FLOW_TABLE_LEVEL_POLICY
989 #define MLX5_MAX_TABLES_FDB UINT16_MAX
990 #define MLX5_FLOW_TABLE_FACTOR 10
991
992 /* ID generation structure. */
993 struct mlx5_flow_id_pool {
994         uint32_t *free_arr; /**< Pointer to the a array of free values. */
995         uint32_t base_index;
996         /**< The next index that can be used without any free elements. */
997         uint32_t *curr; /**< Pointer to the index to pop. */
998         uint32_t *last; /**< Pointer to the last element in the empty arrray. */
999         uint32_t max_id; /**< Maximum id can be allocated from the pool. */
1000 };
1001
1002 /* Tx pacing queue structure - for Clock and Rearm queues. */
1003 struct mlx5_txpp_wq {
1004         /* Completion Queue related data.*/
1005         struct mlx5_devx_cq cq_obj;
1006         uint32_t cq_ci:24;
1007         uint32_t arm_sn:2;
1008         /* Send Queue related data.*/
1009         struct mlx5_devx_sq sq_obj;
1010         uint16_t sq_size; /* Number of WQEs in the queue. */
1011         uint16_t sq_ci; /* Next WQE to execute. */
1012 };
1013
1014 /* Tx packet pacing internal timestamp. */
1015 struct mlx5_txpp_ts {
1016         uint64_t ci_ts;
1017         uint64_t ts;
1018 };
1019
1020 /* Tx packet pacing structure. */
1021 struct mlx5_dev_txpp {
1022         pthread_mutex_t mutex; /* Pacing create/destroy mutex. */
1023         uint32_t refcnt; /* Pacing reference counter. */
1024         uint32_t freq; /* Timestamp frequency, Hz. */
1025         uint32_t tick; /* Completion tick duration in nanoseconds. */
1026         uint32_t test; /* Packet pacing test mode. */
1027         int32_t skew; /* Scheduling skew. */
1028         struct rte_intr_handle intr_handle; /* Periodic interrupt. */
1029         void *echan; /* Event Channel. */
1030         struct mlx5_txpp_wq clock_queue; /* Clock Queue. */
1031         struct mlx5_txpp_wq rearm_queue; /* Clock Queue. */
1032         void *pp; /* Packet pacing context. */
1033         uint16_t pp_id; /* Packet pacing context index. */
1034         uint16_t ts_n; /* Number of captured timestamps. */
1035         uint16_t ts_p; /* Pointer to statisticks timestamp. */
1036         struct mlx5_txpp_ts *tsa; /* Timestamps sliding window stats. */
1037         struct mlx5_txpp_ts ts; /* Cached completion id/timestamp. */
1038         uint32_t sync_lost:1; /* ci/timestamp synchronization lost. */
1039         /* Statistics counters. */
1040         uint64_t err_miss_int; /* Missed service interrupt. */
1041         uint64_t err_rearm_queue; /* Rearm Queue errors. */
1042         uint64_t err_clock_queue; /* Clock Queue errors. */
1043         uint64_t err_ts_past; /* Timestamp in the past. */
1044         uint64_t err_ts_future; /* Timestamp in the distant future. */
1045 };
1046
1047 /* Supported flex parser profile ID. */
1048 enum mlx5_flex_parser_profile_id {
1049         MLX5_FLEX_PARSER_ECPRI_0 = 0,
1050         MLX5_FLEX_PARSER_MAX = 8,
1051 };
1052
1053 /* Sample ID information of flex parser structure. */
1054 struct mlx5_flex_parser_profiles {
1055         uint32_t num;           /* Actual number of samples. */
1056         uint32_t ids[8];        /* Sample IDs for this profile. */
1057         uint8_t offset[8];      /* Bytes offset of each parser. */
1058         void *obj;              /* Flex parser node object. */
1059 };
1060
1061 /* Max member ports per bonding device. */
1062 #define MLX5_BOND_MAX_PORTS 2
1063
1064 /* Bonding device information. */
1065 struct mlx5_bond_info {
1066         int n_port; /* Number of bond member ports. */
1067         uint32_t ifindex;
1068         char ifname[MLX5_NAMESIZE + 1];
1069         struct {
1070                 char ifname[MLX5_NAMESIZE + 1];
1071                 uint32_t ifindex;
1072                 struct rte_pci_addr pci_addr;
1073         } ports[MLX5_BOND_MAX_PORTS];
1074 };
1075
1076 /* Number of connection tracking objects per pool: must be a power of 2. */
1077 #define MLX5_ASO_CT_ACTIONS_PER_POOL 64
1078
1079 /* Generate incremental and unique CT index from pool and offset. */
1080 #define MLX5_MAKE_CT_IDX(pool, offset) \
1081         ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1)
1082
1083 /* ASO Conntrack state. */
1084 enum mlx5_aso_ct_state {
1085         ASO_CONNTRACK_FREE, /* Inactive, in the free list. */
1086         ASO_CONNTRACK_WAIT, /* WQE sent in the SQ. */
1087         ASO_CONNTRACK_READY, /* CQE received w/o error. */
1088         ASO_CONNTRACK_QUERY, /* WQE for query sent. */
1089         ASO_CONNTRACK_MAX, /* Guard. */
1090 };
1091
1092 /* Generic ASO connection tracking structure. */
1093 struct mlx5_aso_ct_action {
1094         LIST_ENTRY(mlx5_aso_ct_action) next; /* Pointer to the next ASO CT. */
1095         void *dr_action_orig; /* General action object for original dir. */
1096         void *dr_action_rply; /* General action object for reply dir. */
1097         uint32_t refcnt; /* Action used count in device flows. */
1098         uint16_t offset; /* Offset of ASO CT in DevX objects bulk. */
1099         uint16_t peer; /* The only peer port index could also use this CT. */
1100         enum mlx5_aso_ct_state state; /* ASO CT state. */
1101         bool is_original; /* The direction of the DR action to be used. */
1102 };
1103
1104 /* CT action object state update. */
1105 #define MLX5_ASO_CT_UPDATE_STATE(c, s) \
1106         __atomic_store_n(&((c)->state), (s), __ATOMIC_RELAXED)
1107
1108 /* ASO connection tracking software pool definition. */
1109 struct mlx5_aso_ct_pool {
1110         uint16_t index; /* Pool index in pools array. */
1111         struct mlx5_devx_obj *devx_obj;
1112         /* The first devx object in the bulk, used for freeing (not yet). */
1113         struct mlx5_aso_ct_action actions[MLX5_ASO_CT_ACTIONS_PER_POOL];
1114         /* CT action structures bulk. */
1115 };
1116
1117 LIST_HEAD(aso_ct_list, mlx5_aso_ct_action);
1118
1119 /* Pools management structure for ASO connection tracking pools. */
1120 struct mlx5_aso_ct_pools_mng {
1121         struct mlx5_aso_ct_pool **pools;
1122         uint16_t n; /* Total number of pools. */
1123         uint16_t next; /* Number of pools in use, index of next free pool. */
1124         rte_spinlock_t ct_sl; /* The ASO CT free list lock. */
1125         rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */
1126         struct aso_ct_list free_cts; /* Free ASO CT objects list. */
1127         struct mlx5_aso_sq aso_sq; /* ASO queue objects. */
1128 };
1129
1130 /*
1131  * Shared Infiniband device context for Master/Representors
1132  * which belong to same IB device with multiple IB ports.
1133  **/
1134 struct mlx5_dev_ctx_shared {
1135         LIST_ENTRY(mlx5_dev_ctx_shared) next;
1136         uint32_t refcnt;
1137         uint32_t devx:1; /* Opened with DV. */
1138         uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */
1139         uint32_t rq_ts_format:2; /* RQ timestamp formats supported. */
1140         uint32_t sq_ts_format:2; /* SQ timestamp formats supported. */
1141         uint32_t steering_format_version:4;
1142         /* Indicates the device steering logic format. */
1143         uint32_t qp_ts_format:2; /* QP timestamp formats supported. */
1144         uint32_t meter_aso_en:1; /* Flow Meter ASO is supported. */
1145         uint32_t ct_aso_en:1; /* Connection Tracking ASO is supported. */
1146         uint32_t tunnel_header_0_1:1; /* tunnel_header_0_1 is supported. */
1147         uint32_t misc5_cap:1; /* misc5 matcher parameter is supported. */
1148         uint32_t reclaim_mode:1; /* Reclaim memory. */
1149         uint32_t max_port; /* Maximal IB device port index. */
1150         struct mlx5_bond_info bond; /* Bonding information. */
1151         void *ctx; /* Verbs/DV/DevX context. */
1152         void *pd; /* Protection Domain. */
1153         uint32_t pdn; /* Protection Domain number. */
1154         uint32_t tdn; /* Transport Domain number. */
1155         char ibdev_name[MLX5_FS_NAME_MAX]; /* SYSFS dev name. */
1156         char ibdev_path[MLX5_FS_PATH_MAX]; /* SYSFS dev path for secondary */
1157         struct mlx5_dev_attr device_attr; /* Device properties. */
1158         int numa_node; /* Numa node of backing physical device. */
1159         LIST_ENTRY(mlx5_dev_ctx_shared) mem_event_cb;
1160         /**< Called by memory event callback. */
1161         struct mlx5_mr_share_cache share_cache;
1162         /* Packet pacing related structure. */
1163         struct mlx5_dev_txpp txpp;
1164         /* Shared DV/DR flow data section. */
1165         uint32_t dv_meta_mask; /* flow META metadata supported mask. */
1166         uint32_t dv_mark_mask; /* flow MARK metadata supported mask. */
1167         uint32_t dv_regc0_mask; /* available bits of metatada reg_c[0]. */
1168         void *fdb_domain; /* FDB Direct Rules name space handle. */
1169         void *rx_domain; /* RX Direct Rules name space handle. */
1170         void *tx_domain; /* TX Direct Rules name space handle. */
1171 #ifndef RTE_ARCH_64
1172         rte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR */
1173         rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX];
1174         /* UAR same-page access control required in 32bit implementations. */
1175 #endif
1176         struct mlx5_hlist *flow_tbls;
1177         struct mlx5_flow_tunnel_hub *tunnel_hub;
1178         /* Direct Rules tables for FDB, NIC TX+RX */
1179         void *dr_drop_action; /* Pointer to DR drop action, any domain. */
1180         void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
1181         struct mlx5_hlist *encaps_decaps; /* Encap/decap action hash list. */
1182         struct mlx5_hlist *modify_cmds;
1183         struct mlx5_hlist *tag_table;
1184         struct mlx5_list *port_id_action_list; /* Port ID action list. */
1185         struct mlx5_list *push_vlan_action_list; /* Push VLAN actions. */
1186         struct mlx5_list *sample_action_list; /* List of sample actions. */
1187         struct mlx5_list *dest_array_list;
1188         /* List of destination array actions. */
1189         struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
1190         void *default_miss_action; /* Default miss action. */
1191         struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX];
1192         struct mlx5_indexed_pool *mdh_ipools[MLX5_MAX_MODIFY_NUM];
1193         /* Memory Pool for mlx5 flow resources. */
1194         struct mlx5_l3t_tbl *cnt_id_tbl; /* Shared counter lookup table. */
1195         /* Shared interrupt handler section. */
1196         struct rte_intr_handle intr_handle; /* Interrupt handler for device. */
1197         struct rte_intr_handle intr_handle_devx; /* DEVX interrupt handler. */
1198         void *devx_comp; /* DEVX async comp obj. */
1199         struct mlx5_devx_obj *tis; /* TIS object. */
1200         struct mlx5_devx_obj *td; /* Transport domain. */
1201         void *tx_uar; /* Tx/packet pacing shared UAR. */
1202         struct mlx5_flex_parser_profiles fp[MLX5_FLEX_PARSER_MAX];
1203         /* Flex parser profiles information. */
1204         void *devx_rx_uar; /* DevX UAR for Rx. */
1205         struct mlx5_aso_age_mng *aso_age_mng;
1206         /* Management data for aging mechanism using ASO Flow Hit. */
1207         struct mlx5_geneve_tlv_option_resource *geneve_tlv_option_resource;
1208         /* Management structure for geneve tlv option */
1209         rte_spinlock_t geneve_tlv_opt_sl; /* Lock for geneve tlv resource */
1210         struct mlx5_flow_mtr_mng *mtrmng;
1211         /* Meter management structure. */
1212         struct mlx5_aso_ct_pools_mng *ct_mng;
1213         /* Management data for ASO connection tracking. */
1214         struct mlx5_lb_ctx self_lb; /* QP to enable self loopback for Devx. */
1215         struct mlx5_dev_shared_port port[]; /* per device port data array. */
1216 };
1217
1218 /*
1219  * Per-process private structure.
1220  * Caution, secondary process may rebuild the struct during port start.
1221  */
1222 struct mlx5_proc_priv {
1223         size_t uar_table_sz;
1224         /* Size of UAR register table. */
1225         void *uar_table[];
1226         /* Table of UAR registers for each process. */
1227 };
1228
1229 /* MTR profile list. */
1230 TAILQ_HEAD(mlx5_mtr_profiles, mlx5_flow_meter_profile);
1231 /* MTR list. */
1232 TAILQ_HEAD(mlx5_legacy_flow_meters, mlx5_legacy_flow_meter);
1233
1234 /* RSS description. */
1235 struct mlx5_flow_rss_desc {
1236         uint32_t level;
1237         uint32_t queue_num; /**< Number of entries in @p queue. */
1238         uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
1239         uint64_t hash_fields; /* Verbs Hash fields. */
1240         uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */
1241         uint32_t key_len; /**< RSS hash key len. */
1242         uint32_t tunnel; /**< Queue in tunnel. */
1243         uint32_t shared_rss; /**< Shared RSS index. */
1244         struct mlx5_ind_table_obj *ind_tbl;
1245         /**< Indirection table for shared RSS hash RX queues. */
1246         union {
1247                 uint16_t *queue; /**< Destination queues. */
1248                 const uint16_t *const_q; /**< Const pointer convert. */
1249         };
1250 };
1251
1252 #define MLX5_PROC_PRIV(port_id) \
1253         ((struct mlx5_proc_priv *)rte_eth_devices[port_id].process_private)
1254
1255 /* Verbs/DevX Rx queue elements. */
1256 struct mlx5_rxq_obj {
1257         LIST_ENTRY(mlx5_rxq_obj) next; /* Pointer to the next element. */
1258         struct mlx5_rxq_ctrl *rxq_ctrl; /* Back pointer to parent. */
1259         int fd; /* File descriptor for event channel */
1260         RTE_STD_C11
1261         union {
1262                 struct {
1263                         void *wq; /* Work Queue. */
1264                         void *ibv_cq; /* Completion Queue. */
1265                         void *ibv_channel;
1266                 };
1267                 struct mlx5_devx_obj *rq; /* DevX RQ object for hairpin. */
1268                 struct {
1269                         struct mlx5_devx_rq rq_obj; /* DevX RQ object. */
1270                         struct mlx5_devx_cq cq_obj; /* DevX CQ object. */
1271                         void *devx_channel;
1272                 };
1273         };
1274 };
1275
1276 /* Indirection table. */
1277 struct mlx5_ind_table_obj {
1278         LIST_ENTRY(mlx5_ind_table_obj) next; /* Pointer to the next element. */
1279         uint32_t refcnt; /* Reference counter. */
1280         RTE_STD_C11
1281         union {
1282                 void *ind_table; /**< Indirection table. */
1283                 struct mlx5_devx_obj *rqt; /* DevX RQT object. */
1284         };
1285         uint32_t queues_n; /**< Number of queues in the list. */
1286         uint16_t *queues; /**< Queue list. */
1287 };
1288
1289 /* Hash Rx queue. */
1290 __extension__
1291 struct mlx5_hrxq {
1292         struct mlx5_list_entry entry; /* List entry. */
1293         uint32_t standalone:1; /* This object used in shared action. */
1294         struct mlx5_ind_table_obj *ind_table; /* Indirection table. */
1295         RTE_STD_C11
1296         union {
1297                 void *qp; /* Verbs queue pair. */
1298                 struct mlx5_devx_obj *tir; /* DevX TIR object. */
1299         };
1300 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
1301         void *action; /* DV QP action pointer. */
1302 #endif
1303         uint64_t hash_fields; /* Verbs Hash fields. */
1304         uint32_t rss_key_len; /* Hash key length in bytes. */
1305         uint32_t idx; /* Hash Rx queue index. */
1306         uint8_t rss_key[]; /* Hash key. */
1307 };
1308
1309 /* Verbs/DevX Tx queue elements. */
1310 struct mlx5_txq_obj {
1311         LIST_ENTRY(mlx5_txq_obj) next; /* Pointer to the next element. */
1312         struct mlx5_txq_ctrl *txq_ctrl; /* Pointer to the control queue. */
1313         RTE_STD_C11
1314         union {
1315                 struct {
1316                         void *cq; /* Completion Queue. */
1317                         void *qp; /* Queue Pair. */
1318                 };
1319                 struct {
1320                         struct mlx5_devx_obj *sq;
1321                         /* DevX object for Sx queue. */
1322                         struct mlx5_devx_obj *tis; /* The TIS object. */
1323                 };
1324                 struct {
1325                         struct rte_eth_dev *dev;
1326                         struct mlx5_devx_cq cq_obj;
1327                         /* DevX CQ object and its resources. */
1328                         struct mlx5_devx_sq sq_obj;
1329                         /* DevX SQ object and its resources. */
1330                 };
1331         };
1332 };
1333
1334 enum mlx5_rxq_modify_type {
1335         MLX5_RXQ_MOD_ERR2RST, /* modify state from error to reset. */
1336         MLX5_RXQ_MOD_RST2RDY, /* modify state from reset to ready. */
1337         MLX5_RXQ_MOD_RDY2ERR, /* modify state from ready to error. */
1338         MLX5_RXQ_MOD_RDY2RST, /* modify state from ready to reset. */
1339 };
1340
1341 enum mlx5_txq_modify_type {
1342         MLX5_TXQ_MOD_RST2RDY, /* modify state from reset to ready. */
1343         MLX5_TXQ_MOD_RDY2RST, /* modify state from ready to reset. */
1344         MLX5_TXQ_MOD_ERR2RDY, /* modify state from error to ready. */
1345 };
1346
1347 /* HW objects operations structure. */
1348 struct mlx5_obj_ops {
1349         int (*rxq_obj_modify_vlan_strip)(struct mlx5_rxq_obj *rxq_obj, int on);
1350         int (*rxq_obj_new)(struct rte_eth_dev *dev, uint16_t idx);
1351         int (*rxq_event_get)(struct mlx5_rxq_obj *rxq_obj);
1352         int (*rxq_obj_modify)(struct mlx5_rxq_obj *rxq_obj, uint8_t type);
1353         void (*rxq_obj_release)(struct mlx5_rxq_obj *rxq_obj);
1354         int (*ind_table_new)(struct rte_eth_dev *dev, const unsigned int log_n,
1355                              struct mlx5_ind_table_obj *ind_tbl);
1356         int (*ind_table_modify)(struct rte_eth_dev *dev,
1357                                 const unsigned int log_n,
1358                                 const uint16_t *queues, const uint32_t queues_n,
1359                                 struct mlx5_ind_table_obj *ind_tbl);
1360         void (*ind_table_destroy)(struct mlx5_ind_table_obj *ind_tbl);
1361         int (*hrxq_new)(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
1362                         int tunnel __rte_unused);
1363         int (*hrxq_modify)(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
1364                            const uint8_t *rss_key,
1365                            uint64_t hash_fields,
1366                            const struct mlx5_ind_table_obj *ind_tbl);
1367         void (*hrxq_destroy)(struct mlx5_hrxq *hrxq);
1368         int (*drop_action_create)(struct rte_eth_dev *dev);
1369         void (*drop_action_destroy)(struct rte_eth_dev *dev);
1370         int (*txq_obj_new)(struct rte_eth_dev *dev, uint16_t idx);
1371         int (*txq_obj_modify)(struct mlx5_txq_obj *obj,
1372                               enum mlx5_txq_modify_type type, uint8_t dev_port);
1373         void (*txq_obj_release)(struct mlx5_txq_obj *txq_obj);
1374         int (*lb_dummy_queue_create)(struct rte_eth_dev *dev);
1375         void (*lb_dummy_queue_release)(struct rte_eth_dev *dev);
1376 };
1377
1378 #define MLX5_RSS_HASH_FIELDS_LEN RTE_DIM(mlx5_rss_hash_fields)
1379
1380 /* MR operations structure. */
1381 struct mlx5_mr_ops {
1382         mlx5_reg_mr_t reg_mr;
1383         mlx5_dereg_mr_t dereg_mr;
1384 };
1385
1386 struct mlx5_priv {
1387         struct rte_eth_dev_data *dev_data;  /* Pointer to device data. */
1388         struct mlx5_dev_ctx_shared *sh; /* Shared device context. */
1389         uint32_t dev_port; /* Device port number. */
1390         struct rte_pci_device *pci_dev; /* Backend PCI device. */
1391         struct rte_ether_addr mac[MLX5_MAX_MAC_ADDRESSES]; /* MAC addresses. */
1392         BITFIELD_DECLARE(mac_own, uint64_t, MLX5_MAX_MAC_ADDRESSES);
1393         /* Bit-field of MAC addresses owned by the PMD. */
1394         uint16_t vlan_filter[MLX5_MAX_VLAN_IDS]; /* VLAN filters table. */
1395         unsigned int vlan_filter_n; /* Number of configured VLAN filters. */
1396         /* Device properties. */
1397         uint16_t mtu; /* Configured MTU. */
1398         unsigned int isolated:1; /* Whether isolated mode is enabled. */
1399         unsigned int representor:1; /* Device is a port representor. */
1400         unsigned int master:1; /* Device is a E-Switch master. */
1401         unsigned int txpp_en:1; /* Tx packet pacing enabled. */
1402         unsigned int sampler_en:1; /* Whether support sampler. */
1403         unsigned int mtr_en:1; /* Whether support meter. */
1404         unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
1405         unsigned int lb_used:1; /* Loopback queue is referred to. */
1406         uint16_t domain_id; /* Switch domain identifier. */
1407         uint16_t vport_id; /* Associated VF vport index (if any). */
1408         uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
1409         uint32_t vport_meta_mask; /* Used for vport index field match mask. */
1410         uint16_t representor_id; /* UINT16_MAX if not a representor. */
1411         int32_t pf_bond; /* >=0, representor owner PF index in bonding. */
1412         unsigned int if_index; /* Associated kernel network device index. */
1413         /* RX/TX queues. */
1414         unsigned int rxqs_n; /* RX queues array size. */
1415         unsigned int txqs_n; /* TX queues array size. */
1416         struct mlx5_rxq_data *(*rxqs)[]; /* RX queues. */
1417         struct mlx5_txq_data *(*txqs)[]; /* TX queues. */
1418         struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */
1419         struct rte_eth_rss_conf rss_conf; /* RSS configuration. */
1420         unsigned int (*reta_idx)[]; /* RETA index table. */
1421         unsigned int reta_idx_n; /* RETA index size. */
1422         struct mlx5_drop drop_queue; /* Flow drop queues. */
1423         void *root_drop_action; /* Pointer to root drop action. */
1424         struct mlx5_indexed_pool *flows[MLX5_FLOW_TYPE_MAXI];
1425         /* RTE Flow rules. */
1426         uint32_t ctrl_flows; /* Control flow rules. */
1427         rte_spinlock_t flow_list_lock;
1428         struct mlx5_obj_ops obj_ops; /* HW objects operations. */
1429         LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */
1430         LIST_HEAD(rxqobj, mlx5_rxq_obj) rxqsobj; /* Verbs/DevX Rx queues. */
1431         struct mlx5_list *hrxqs; /* Hash Rx queues. */
1432         LIST_HEAD(txq, mlx5_txq_ctrl) txqsctrl; /* DPDK Tx queues. */
1433         LIST_HEAD(txqobj, mlx5_txq_obj) txqsobj; /* Verbs/DevX Tx queues. */
1434         /* Indirection tables. */
1435         LIST_HEAD(ind_tables, mlx5_ind_table_obj) ind_tbls;
1436         /* Pointer to next element. */
1437         rte_rwlock_t ind_tbls_lock;
1438         uint32_t refcnt; /**< Reference counter. */
1439         /**< Verbs modify header action object. */
1440         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
1441         uint8_t max_lro_msg_size;
1442         uint32_t link_speed_capa; /* Link speed capabilities. */
1443         struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */
1444         struct mlx5_stats_ctrl stats_ctrl; /* Stats control. */
1445         struct mlx5_dev_config config; /* Device configuration. */
1446         /* Context for Verbs allocator. */
1447         int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
1448         int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
1449         struct mlx5_nl_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */
1450         struct mlx5_hlist *mreg_cp_tbl;
1451         /* Hash table of Rx metadata register copy table. */
1452         uint8_t mtr_sfx_reg; /* Meter prefix-suffix flow match REG_C. */
1453         uint8_t mtr_color_reg; /* Meter color match REG_C. */
1454         struct mlx5_legacy_flow_meters flow_meters; /* MTR list. */
1455         struct mlx5_l3t_tbl *mtr_profile_tbl; /* Meter index lookup table. */
1456         struct mlx5_l3t_tbl *policy_idx_tbl; /* Policy index lookup table. */
1457         struct mlx5_l3t_tbl *mtr_idx_tbl; /* Meter index lookup table. */
1458         uint8_t skip_default_rss_reta; /* Skip configuration of default reta. */
1459         uint8_t fdb_def_rule; /* Whether fdb jump to table 1 is configured. */
1460         struct mlx5_mp_id mp_id; /* ID of a multi-process process */
1461         LIST_HEAD(fdir, mlx5_fdir_flow) fdir_flows; /* fdir flows. */
1462         rte_spinlock_t shared_act_sl; /* Shared actions spinlock. */
1463         uint32_t rss_shared_actions; /* RSS shared actions. */
1464         struct mlx5_devx_obj *q_counters; /* DevX queue counter object. */
1465         uint32_t counter_set_id; /* Queue counter ID to set in DevX objects. */
1466 };
1467
1468 #define PORT_ID(priv) ((priv)->dev_data->port_id)
1469 #define ETH_DEV(priv) (&rte_eth_devices[PORT_ID(priv)])
1470
1471 struct rte_hairpin_peer_info {
1472         uint32_t qp_id;
1473         uint32_t vhca_id;
1474         uint16_t peer_q;
1475         uint16_t tx_explicit;
1476         uint16_t manual_bind;
1477 };
1478
1479 #define BUF_SIZE 1024
1480 enum dr_dump_rec_type {
1481         DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT = 4410,
1482         DR_DUMP_REC_TYPE_PMD_MODIFY_HDR = 4420,
1483         DR_DUMP_REC_TYPE_PMD_COUNTER = 4430,
1484 };
1485
1486 /* mlx5.c */
1487
1488 int mlx5_getenv_int(const char *);
1489 int mlx5_proc_priv_init(struct rte_eth_dev *dev);
1490 void mlx5_proc_priv_uninit(struct rte_eth_dev *dev);
1491 int mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev,
1492                               struct rte_eth_udp_tunnel *udp_tunnel);
1493 uint16_t mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev);
1494 int mlx5_dev_close(struct rte_eth_dev *dev);
1495 int mlx5_net_remove(struct rte_device *dev);
1496 bool mlx5_is_hpf(struct rte_eth_dev *dev);
1497 bool mlx5_is_sf_repr(struct rte_eth_dev *dev);
1498 void mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh);
1499
1500 /* Macro to iterate over all valid ports for mlx5 driver. */
1501 #define MLX5_ETH_FOREACH_DEV(port_id, dev) \
1502         for (port_id = mlx5_eth_find_next(0, dev); \
1503              port_id < RTE_MAX_ETHPORTS; \
1504              port_id = mlx5_eth_find_next(port_id + 1, dev))
1505 int mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs);
1506 struct mlx5_dev_ctx_shared *
1507 mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
1508                            const struct mlx5_dev_config *config);
1509 void mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh);
1510 int mlx5_dev_ctx_shared_mempool_subscribe(struct rte_eth_dev *dev);
1511 void mlx5_free_table_hash_list(struct mlx5_priv *priv);
1512 int mlx5_alloc_table_hash_list(struct mlx5_priv *priv);
1513 void mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
1514                          struct mlx5_dev_config *config);
1515 void mlx5_set_metadata_mask(struct rte_eth_dev *dev);
1516 int mlx5_dev_check_sibling_config(struct mlx5_priv *priv,
1517                                   struct mlx5_dev_config *config,
1518                                   struct rte_device *dpdk_dev);
1519 int mlx5_dev_configure(struct rte_eth_dev *dev);
1520 int mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info);
1521 int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size);
1522 int mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
1523 int mlx5_hairpin_cap_get(struct rte_eth_dev *dev,
1524                          struct rte_eth_hairpin_cap *cap);
1525 bool mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev);
1526 int mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev);
1527 int mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh);
1528 int mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh);
1529 int mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh);
1530
1531 /* mlx5_ethdev.c */
1532
1533 int mlx5_dev_configure(struct rte_eth_dev *dev);
1534 int mlx5_representor_info_get(struct rte_eth_dev *dev,
1535                               struct rte_eth_representor_info *info);
1536 #define MLX5_REPRESENTOR_ID(pf, type, repr) \
1537                 (((pf) << 14) + ((type) << 12) + ((repr) & 0xfff))
1538 #define MLX5_REPRESENTOR_REPR(repr_id) \
1539                 ((repr_id) & 0xfff)
1540 #define MLX5_REPRESENTOR_TYPE(repr_id) \
1541                 (((repr_id) >> 12) & 3)
1542 uint16_t mlx5_representor_id_encode(const struct mlx5_switch_info *info,
1543                                     enum rte_eth_representor_type hpf_type);
1544 int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver,
1545                         size_t fw_size);
1546 int mlx5_dev_infos_get(struct rte_eth_dev *dev,
1547                        struct rte_eth_dev_info *info);
1548 const uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev);
1549 int mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
1550 int mlx5_hairpin_cap_get(struct rte_eth_dev *dev,
1551                          struct rte_eth_hairpin_cap *cap);
1552 eth_rx_burst_t mlx5_select_rx_function(struct rte_eth_dev *dev);
1553 struct mlx5_priv *mlx5_port_to_eswitch_info(uint16_t port, bool valid);
1554 struct mlx5_priv *mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev);
1555 int mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev);
1556
1557 /* mlx5_ethdev_os.c */
1558
1559 int mlx5_get_ifname(const struct rte_eth_dev *dev,
1560                         char (*ifname)[MLX5_NAMESIZE]);
1561 unsigned int mlx5_ifindex(const struct rte_eth_dev *dev);
1562 int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]);
1563 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
1564 int mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
1565 int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
1566 int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete);
1567 int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev,
1568                            struct rte_eth_fc_conf *fc_conf);
1569 int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
1570                            struct rte_eth_fc_conf *fc_conf);
1571 void mlx5_dev_interrupt_handler(void *arg);
1572 void mlx5_dev_interrupt_handler_devx(void *arg);
1573 int mlx5_set_link_down(struct rte_eth_dev *dev);
1574 int mlx5_set_link_up(struct rte_eth_dev *dev);
1575 int mlx5_is_removed(struct rte_eth_dev *dev);
1576 int mlx5_sysfs_switch_info(unsigned int ifindex,
1577                            struct mlx5_switch_info *info);
1578 void mlx5_translate_port_name(const char *port_name_in,
1579                               struct mlx5_switch_info *port_info_out);
1580 void mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
1581                                    rte_intr_callback_fn cb_fn, void *cb_arg);
1582 int mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
1583                          char *ifname);
1584 int mlx5_get_module_info(struct rte_eth_dev *dev,
1585                          struct rte_eth_dev_module_info *modinfo);
1586 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
1587                            struct rte_dev_eeprom_info *info);
1588 int mlx5_os_read_dev_stat(struct mlx5_priv *priv,
1589                           const char *ctr_name, uint64_t *stat);
1590 int mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats);
1591 int mlx5_os_get_stats_n(struct rte_eth_dev *dev);
1592 void mlx5_os_stats_init(struct rte_eth_dev *dev);
1593
1594 /* mlx5_mac.c */
1595
1596 void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
1597 int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
1598                       uint32_t index, uint32_t vmdq);
1599 int mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
1600 int mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
1601                         struct rte_ether_addr *mc_addr_set,
1602                         uint32_t nb_mc_addr);
1603
1604 /* mlx5_rss.c */
1605
1606 int mlx5_rss_hash_update(struct rte_eth_dev *dev,
1607                          struct rte_eth_rss_conf *rss_conf);
1608 int mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
1609                            struct rte_eth_rss_conf *rss_conf);
1610 int mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size);
1611 int mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
1612                             struct rte_eth_rss_reta_entry64 *reta_conf,
1613                             uint16_t reta_size);
1614 int mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
1615                              struct rte_eth_rss_reta_entry64 *reta_conf,
1616                              uint16_t reta_size);
1617
1618 /* mlx5_rxmode.c */
1619
1620 int mlx5_promiscuous_enable(struct rte_eth_dev *dev);
1621 int mlx5_promiscuous_disable(struct rte_eth_dev *dev);
1622 int mlx5_allmulticast_enable(struct rte_eth_dev *dev);
1623 int mlx5_allmulticast_disable(struct rte_eth_dev *dev);
1624
1625 /* mlx5_stats.c */
1626
1627 int mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
1628 int mlx5_stats_reset(struct rte_eth_dev *dev);
1629 int mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
1630                     unsigned int n);
1631 int mlx5_xstats_reset(struct rte_eth_dev *dev);
1632 int mlx5_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
1633                           struct rte_eth_xstat_name *xstats_names,
1634                           unsigned int n);
1635
1636 /* mlx5_vlan.c */
1637
1638 int mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
1639 void mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on);
1640 int mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask);
1641
1642 /* mlx5_vlan_os.c */
1643
1644 void mlx5_vlan_vmwa_exit(void *ctx);
1645 void mlx5_vlan_vmwa_release(struct rte_eth_dev *dev,
1646                             struct mlx5_vf_vlan *vf_vlan);
1647 void mlx5_vlan_vmwa_acquire(struct rte_eth_dev *dev,
1648                             struct mlx5_vf_vlan *vf_vlan);
1649 void *mlx5_vlan_vmwa_init(struct rte_eth_dev *dev, uint32_t ifindex);
1650
1651 /* mlx5_trigger.c */
1652
1653 int mlx5_dev_start(struct rte_eth_dev *dev);
1654 int mlx5_dev_stop(struct rte_eth_dev *dev);
1655 int mlx5_traffic_enable(struct rte_eth_dev *dev);
1656 void mlx5_traffic_disable(struct rte_eth_dev *dev);
1657 int mlx5_traffic_restart(struct rte_eth_dev *dev);
1658 int mlx5_hairpin_queue_peer_update(struct rte_eth_dev *dev, uint16_t peer_queue,
1659                                    struct rte_hairpin_peer_info *current_info,
1660                                    struct rte_hairpin_peer_info *peer_info,
1661                                    uint32_t direction);
1662 int mlx5_hairpin_queue_peer_bind(struct rte_eth_dev *dev, uint16_t cur_queue,
1663                                  struct rte_hairpin_peer_info *peer_info,
1664                                  uint32_t direction);
1665 int mlx5_hairpin_queue_peer_unbind(struct rte_eth_dev *dev, uint16_t cur_queue,
1666                                    uint32_t direction);
1667 int mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port);
1668 int mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port);
1669 int mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
1670                                 size_t len, uint32_t direction);
1671
1672 /* mlx5_flow.c */
1673
1674 int mlx5_flow_discover_mreg_c(struct rte_eth_dev *eth_dev);
1675 bool mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev);
1676 void mlx5_flow_print(struct rte_flow *flow);
1677 int mlx5_flow_validate(struct rte_eth_dev *dev,
1678                        const struct rte_flow_attr *attr,
1679                        const struct rte_flow_item items[],
1680                        const struct rte_flow_action actions[],
1681                        struct rte_flow_error *error);
1682 struct rte_flow *mlx5_flow_create(struct rte_eth_dev *dev,
1683                                   const struct rte_flow_attr *attr,
1684                                   const struct rte_flow_item items[],
1685                                   const struct rte_flow_action actions[],
1686                                   struct rte_flow_error *error);
1687 int mlx5_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
1688                       struct rte_flow_error *error);
1689 void mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type,
1690                           bool active);
1691 int mlx5_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
1692 int mlx5_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
1693                     const struct rte_flow_action *action, void *data,
1694                     struct rte_flow_error *error);
1695 int mlx5_flow_isolate(struct rte_eth_dev *dev, int enable,
1696                       struct rte_flow_error *error);
1697 int mlx5_flow_ops_get(struct rte_eth_dev *dev, const struct rte_flow_ops **ops);
1698 int mlx5_flow_start_default(struct rte_eth_dev *dev);
1699 void mlx5_flow_stop_default(struct rte_eth_dev *dev);
1700 int mlx5_flow_verify(struct rte_eth_dev *dev);
1701 int mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev, uint32_t queue);
1702 int mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
1703                         struct rte_flow_item_eth *eth_spec,
1704                         struct rte_flow_item_eth *eth_mask,
1705                         struct rte_flow_item_vlan *vlan_spec,
1706                         struct rte_flow_item_vlan *vlan_mask);
1707 int mlx5_ctrl_flow(struct rte_eth_dev *dev,
1708                    struct rte_flow_item_eth *eth_spec,
1709                    struct rte_flow_item_eth *eth_mask);
1710 int mlx5_flow_lacp_miss(struct rte_eth_dev *dev);
1711 struct rte_flow *mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev);
1712 void mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
1713                                        uint64_t async_id, int status);
1714 void mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh);
1715 void mlx5_flow_query_alarm(void *arg);
1716 uint32_t mlx5_counter_alloc(struct rte_eth_dev *dev);
1717 void mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt);
1718 int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
1719                        bool clear, uint64_t *pkts, uint64_t *bytes);
1720 int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,
1721                         FILE *file, struct rte_flow_error *error);
1722 int save_dump_file(const unsigned char *data, uint32_t size,
1723                 uint32_t type, uint32_t id, void *arg, FILE *file);
1724 int mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow,
1725         struct rte_flow_query_count *count, struct rte_flow_error *error);
1726 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1727 int mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev, struct rte_flow *flow,
1728                 FILE *file, struct rte_flow_error *error);
1729 #endif
1730 void mlx5_flow_rxq_dynf_metadata_set(struct rte_eth_dev *dev);
1731 int mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts,
1732                         uint32_t nb_contexts, struct rte_flow_error *error);
1733 int mlx5_validate_action_ct(struct rte_eth_dev *dev,
1734                             const struct rte_flow_action_conntrack *conntrack,
1735                             struct rte_flow_error *error);
1736
1737
1738 /* mlx5_mp_os.c */
1739
1740 int mlx5_mp_os_primary_handle(const struct rte_mp_msg *mp_msg,
1741                               const void *peer);
1742 int mlx5_mp_os_secondary_handle(const struct rte_mp_msg *mp_msg,
1743                                 const void *peer);
1744 void mlx5_mp_os_req_start_rxtx(struct rte_eth_dev *dev);
1745 void mlx5_mp_os_req_stop_rxtx(struct rte_eth_dev *dev);
1746 int mlx5_mp_os_req_queue_control(struct rte_eth_dev *dev, uint16_t queue_id,
1747                                  enum mlx5_mp_req_type req_type);
1748
1749 /* mlx5_socket.c */
1750
1751 int mlx5_pmd_socket_init(void);
1752
1753 /* mlx5_flow_meter.c */
1754
1755 int mlx5_flow_meter_ops_get(struct rte_eth_dev *dev, void *arg);
1756 struct mlx5_flow_meter_info *mlx5_flow_meter_find(struct mlx5_priv *priv,
1757                 uint32_t meter_id, uint32_t *mtr_idx);
1758 struct mlx5_flow_meter_info *
1759 flow_dv_meter_find_by_idx(struct mlx5_priv *priv, uint32_t idx);
1760 int mlx5_flow_meter_attach(struct mlx5_priv *priv,
1761                            struct mlx5_flow_meter_info *fm,
1762                            const struct rte_flow_attr *attr,
1763                            struct rte_flow_error *error);
1764 void mlx5_flow_meter_detach(struct mlx5_priv *priv,
1765                             struct mlx5_flow_meter_info *fm);
1766 struct mlx5_flow_meter_policy *mlx5_flow_meter_policy_find
1767                 (struct rte_eth_dev *dev,
1768                 uint32_t policy_id,
1769                 uint32_t *policy_idx);
1770 struct mlx5_flow_meter_policy *
1771 mlx5_flow_meter_hierarchy_get_final_policy(struct rte_eth_dev *dev,
1772                                         struct mlx5_flow_meter_policy *policy);
1773 int mlx5_flow_meter_flush(struct rte_eth_dev *dev,
1774                           struct rte_mtr_error *error);
1775 void mlx5_flow_meter_rxq_flush(struct rte_eth_dev *dev);
1776
1777 /* mlx5_os.c */
1778 struct rte_pci_driver;
1779 int mlx5_os_get_dev_attr(void *ctx, struct mlx5_dev_attr *dev_attr);
1780 void mlx5_os_free_shared_dr(struct mlx5_priv *priv);
1781 int mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,
1782                          const struct mlx5_dev_config *config,
1783                          struct mlx5_dev_ctx_shared *sh);
1784 int mlx5_os_get_pdn(void *pd, uint32_t *pdn);
1785 int mlx5_os_net_probe(struct rte_device *dev);
1786 void mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh);
1787 void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh);
1788 void mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
1789                            mlx5_dereg_mr_t *dereg_mr_cb);
1790 void mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
1791 int mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
1792                          uint32_t index);
1793 int mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, unsigned int iface_idx,
1794                                struct rte_ether_addr *mac_addr,
1795                                int vf_index);
1796 int mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable);
1797 int mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable);
1798 int mlx5_os_set_nonblock_channel_fd(int fd);
1799 void mlx5_os_mac_addr_flush(struct rte_eth_dev *dev);
1800
1801 /* mlx5_txpp.c */
1802
1803 int mlx5_txpp_start(struct rte_eth_dev *dev);
1804 void mlx5_txpp_stop(struct rte_eth_dev *dev);
1805 int mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp);
1806 int mlx5_txpp_xstats_get(struct rte_eth_dev *dev,
1807                          struct rte_eth_xstat *stats,
1808                          unsigned int n, unsigned int n_used);
1809 int mlx5_txpp_xstats_reset(struct rte_eth_dev *dev);
1810 int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev,
1811                                struct rte_eth_xstat_name *xstats_names,
1812                                unsigned int n, unsigned int n_used);
1813 void mlx5_txpp_interrupt_handler(void *cb_arg);
1814
1815 /* mlx5_rxtx.c */
1816
1817 eth_tx_burst_t mlx5_select_tx_function(struct rte_eth_dev *dev);
1818
1819 /* mlx5_flow_aso.c */
1820
1821 int mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh,
1822                 enum mlx5_access_aso_opc_mod aso_opc_mod);
1823 int mlx5_aso_flow_hit_queue_poll_start(struct mlx5_dev_ctx_shared *sh);
1824 int mlx5_aso_flow_hit_queue_poll_stop(struct mlx5_dev_ctx_shared *sh);
1825 void mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh,
1826                 enum mlx5_access_aso_opc_mod aso_opc_mod);
1827 int mlx5_aso_meter_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
1828                 struct mlx5_aso_mtr *mtr);
1829 int mlx5_aso_mtr_wait(struct mlx5_dev_ctx_shared *sh,
1830                 struct mlx5_aso_mtr *mtr);
1831 int mlx5_aso_ct_update_by_wqe(struct mlx5_dev_ctx_shared *sh,
1832                               struct mlx5_aso_ct_action *ct,
1833                               const struct rte_flow_action_conntrack *profile);
1834 int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh,
1835                            struct mlx5_aso_ct_action *ct);
1836 int mlx5_aso_ct_query_by_wqe(struct mlx5_dev_ctx_shared *sh,
1837                              struct mlx5_aso_ct_action *ct,
1838                              struct rte_flow_action_conntrack *profile);
1839 int mlx5_aso_ct_available(struct mlx5_dev_ctx_shared *sh,
1840                           struct mlx5_aso_ct_action *ct);
1841
1842 #endif /* RTE_PMD_MLX5_H_ */