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