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