3daf0db13caf5c50cd6d2deef1d5ea9978be3ebd
[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 <net/if.h>
14 #include <netinet/in.h>
15 #include <sys/queue.h>
16
17 /* Verbs header. */
18 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
19 #ifdef PEDANTIC
20 #pragma GCC diagnostic ignored "-Wpedantic"
21 #endif
22 #include <infiniband/verbs.h>
23 #ifdef PEDANTIC
24 #pragma GCC diagnostic error "-Wpedantic"
25 #endif
26
27 #include <rte_pci.h>
28 #include <rte_ether.h>
29 #include <rte_ethdev_driver.h>
30 #include <rte_rwlock.h>
31 #include <rte_interrupts.h>
32 #include <rte_errno.h>
33 #include <rte_flow.h>
34
35 #include <mlx5_glue.h>
36 #include <mlx5_devx_cmds.h>
37 #include <mlx5_prm.h>
38
39 #include "mlx5_defs.h"
40 #include "mlx5_utils.h"
41 #include "mlx5_mr.h"
42 #include "mlx5_autoconf.h"
43
44 /* Request types for IPC. */
45 enum mlx5_mp_req_type {
46         MLX5_MP_REQ_VERBS_CMD_FD = 1,
47         MLX5_MP_REQ_CREATE_MR,
48         MLX5_MP_REQ_START_RXTX,
49         MLX5_MP_REQ_STOP_RXTX,
50         MLX5_MP_REQ_QUEUE_STATE_MODIFY,
51 };
52
53 struct mlx5_mp_arg_queue_state_modify {
54         uint8_t is_wq; /* Set if WQ. */
55         uint16_t queue_id; /* DPDK queue ID. */
56         enum ibv_wq_state state; /* WQ requested state. */
57 };
58
59 /* Pameters for IPC. */
60 struct mlx5_mp_param {
61         enum mlx5_mp_req_type type;
62         int port_id;
63         int result;
64         RTE_STD_C11
65         union {
66                 uintptr_t addr; /* MLX5_MP_REQ_CREATE_MR */
67                 struct mlx5_mp_arg_queue_state_modify state_modify;
68                 /* MLX5_MP_REQ_QUEUE_STATE_MODIFY */
69         } args;
70 };
71
72 /** Request timeout for IPC. */
73 #define MLX5_MP_REQ_TIMEOUT_SEC 5
74
75 /** Key string for IPC. */
76 #define MLX5_MP_NAME "net_mlx5_mp"
77
78 /* Recognized Infiniband device physical port name types. */
79 enum mlx5_phys_port_name_type {
80         MLX5_PHYS_PORT_NAME_TYPE_NOTSET = 0, /* Not set. */
81         MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 */
82         MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */
83         MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */
84         MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
85 };
86
87 /** Switch information returned by mlx5_nl_switch_info(). */
88 struct mlx5_switch_info {
89         uint32_t master:1; /**< Master device. */
90         uint32_t representor:1; /**< Representor device. */
91         enum mlx5_phys_port_name_type name_type; /** < Port name type. */
92         int32_t pf_num; /**< PF number (valid for pfxvfx format only). */
93         int32_t port_name; /**< Representor port name. */
94         uint64_t switch_id; /**< Switch identifier. */
95 };
96
97 LIST_HEAD(mlx5_dev_list, mlx5_ibv_shared);
98
99 /* Shared data between primary and secondary processes. */
100 struct mlx5_shared_data {
101         rte_spinlock_t lock;
102         /* Global spinlock for primary and secondary processes. */
103         int init_done; /* Whether primary has done initialization. */
104         unsigned int secondary_cnt; /* Number of secondary processes init'd. */
105         struct mlx5_dev_list mem_event_cb_list;
106         rte_rwlock_t mem_event_rwlock;
107 };
108
109 /* Per-process data structure, not visible to other processes. */
110 struct mlx5_local_data {
111         int init_done; /* Whether a secondary has done initialization. */
112 };
113
114 extern struct mlx5_shared_data *mlx5_shared_data;
115
116 struct mlx5_counter_ctrl {
117         /* Name of the counter. */
118         char dpdk_name[RTE_ETH_XSTATS_NAME_SIZE];
119         /* Name of the counter on the device table. */
120         char ctr_name[RTE_ETH_XSTATS_NAME_SIZE];
121         uint32_t ib:1; /**< Nonzero for IB counters. */
122 };
123
124 struct mlx5_xstats_ctrl {
125         /* Number of device stats. */
126         uint16_t stats_n;
127         /* Number of device stats identified by PMD. */
128         uint16_t  mlx5_stats_n;
129         /* Index in the device counters table. */
130         uint16_t dev_table_idx[MLX5_MAX_XSTATS];
131         uint64_t base[MLX5_MAX_XSTATS];
132         struct mlx5_counter_ctrl info[MLX5_MAX_XSTATS];
133 };
134
135 struct mlx5_stats_ctrl {
136         /* Base for imissed counter. */
137         uint64_t imissed_base;
138 };
139
140 /* Flow list . */
141 TAILQ_HEAD(mlx5_flows, rte_flow);
142
143 /* Default PMD specific parameter value. */
144 #define MLX5_ARG_UNSET (-1)
145
146 #define MLX5_LRO_SUPPORTED(dev) \
147         (((struct mlx5_priv *)((dev)->data->dev_private))->config.lro.supported)
148
149 /* Maximal size of coalesced segment for LRO is set in chunks of 256 Bytes. */
150 #define MLX5_LRO_SEG_CHUNK_SIZE 256u
151
152 /* Maximal size of aggregated LRO packet. */
153 #define MLX5_MAX_LRO_SIZE (UINT8_MAX * MLX5_LRO_SEG_CHUNK_SIZE)
154
155 /* LRO configurations structure. */
156 struct mlx5_lro_config {
157         uint32_t supported:1; /* Whether LRO is supported. */
158         uint32_t timeout; /* User configuration. */
159 };
160
161 /*
162  * Device configuration structure.
163  *
164  * Merged configuration from:
165  *
166  *  - Device capabilities,
167  *  - User device parameters disabled features.
168  */
169 struct mlx5_dev_config {
170         unsigned int hw_csum:1; /* Checksum offload is supported. */
171         unsigned int hw_vlan_strip:1; /* VLAN stripping is supported. */
172         unsigned int hw_vlan_insert:1; /* VLAN insertion in WQE is supported. */
173         unsigned int hw_fcs_strip:1; /* FCS stripping is supported. */
174         unsigned int hw_padding:1; /* End alignment padding is supported. */
175         unsigned int vf:1; /* This is a VF. */
176         unsigned int tunnel_en:1;
177         /* Whether tunnel stateless offloads are supported. */
178         unsigned int mpls_en:1; /* MPLS over GRE/UDP is enabled. */
179         unsigned int cqe_comp:1; /* CQE compression is enabled. */
180         unsigned int cqe_pad:1; /* CQE padding is enabled. */
181         unsigned int tso:1; /* Whether TSO is supported. */
182         unsigned int rx_vec_en:1; /* Rx vector is enabled. */
183         unsigned int mr_ext_memseg_en:1;
184         /* Whether memseg should be extended for MR creation. */
185         unsigned int l3_vxlan_en:1; /* Enable L3 VXLAN flow creation. */
186         unsigned int vf_nl_en:1; /* Enable Netlink requests in VF mode. */
187         unsigned int dv_esw_en:1; /* Enable E-Switch DV flow. */
188         unsigned int dv_flow_en:1; /* Enable DV flow. */
189         unsigned int dv_xmeta_en:2; /* Enable extensive flow metadata. */
190         unsigned int swp:1; /* Tx generic tunnel checksum and TSO offload. */
191         unsigned int devx:1; /* Whether devx interface is available or not. */
192         unsigned int dest_tir:1; /* Whether advanced DR API is available. */
193         struct {
194                 unsigned int enabled:1; /* Whether MPRQ is enabled. */
195                 unsigned int stride_num_n; /* Number of strides. */
196                 unsigned int min_stride_size_n; /* Min size of a stride. */
197                 unsigned int max_stride_size_n; /* Max size of a stride. */
198                 unsigned int max_memcpy_len;
199                 /* Maximum packet size to memcpy Rx packets. */
200                 unsigned int min_rxqs_num;
201                 /* Rx queue count threshold to enable MPRQ. */
202         } mprq; /* Configurations for Multi-Packet RQ. */
203         int mps; /* Multi-packet send supported mode. */
204         int dbnc; /* Skip doorbell register write barrier. */
205         unsigned int flow_prio; /* Number of flow priorities. */
206         enum modify_reg flow_mreg_c[MLX5_MREG_C_NUM];
207         /* Availibility of mreg_c's. */
208         unsigned int tso_max_payload_sz; /* Maximum TCP payload for TSO. */
209         unsigned int ind_table_max_size; /* Maximum indirection table size. */
210         unsigned int max_dump_files_num; /* Maximum dump files per queue. */
211         int txqs_inline; /* Queue number threshold for inlining. */
212         int txq_inline_min; /* Minimal amount of data bytes to inline. */
213         int txq_inline_max; /* Max packet size for inlining with SEND. */
214         int txq_inline_mpw; /* Max packet size for inlining with eMPW. */
215         struct mlx5_hca_attr hca_attr; /* HCA attributes. */
216         struct mlx5_lro_config lro; /* LRO configuration. */
217 };
218
219
220 /**
221  * Type of object being allocated.
222  */
223 enum mlx5_verbs_alloc_type {
224         MLX5_VERBS_ALLOC_TYPE_NONE,
225         MLX5_VERBS_ALLOC_TYPE_TX_QUEUE,
226         MLX5_VERBS_ALLOC_TYPE_RX_QUEUE,
227 };
228
229 /* VLAN netdev for VLAN workaround. */
230 struct mlx5_vlan_dev {
231         uint32_t refcnt;
232         uint32_t ifindex; /**< Own interface index. */
233 };
234
235 /* Structure for VF VLAN workaround. */
236 struct mlx5_vf_vlan {
237         uint32_t tag:12;
238         uint32_t created:1;
239 };
240
241 /*
242  * Array of VLAN devices created on the base of VF
243  * used for workaround in virtual environments.
244  */
245 struct mlx5_vlan_vmwa_context {
246         int nl_socket;
247         uint32_t nl_sn;
248         uint32_t vf_ifindex;
249         struct rte_eth_dev *dev;
250         struct mlx5_vlan_dev vlan_dev[4096];
251 };
252
253 /**
254  * Verbs allocator needs a context to know in the callback which kind of
255  * resources it is allocating.
256  */
257 struct mlx5_verbs_alloc_ctx {
258         enum mlx5_verbs_alloc_type type; /* Kind of object being allocated. */
259         const void *obj; /* Pointer to the DPDK object. */
260 };
261
262 LIST_HEAD(mlx5_mr_list, mlx5_mr);
263
264 /* Flow drop context necessary due to Verbs API. */
265 struct mlx5_drop {
266         struct mlx5_hrxq *hrxq; /* Hash Rx queue queue. */
267         struct mlx5_rxq_obj *rxq; /* Rx queue object. */
268 };
269
270 #define MLX5_COUNTERS_PER_POOL 512
271 #define MLX5_MAX_PENDING_QUERIES 4
272
273 struct mlx5_flow_counter_pool;
274
275 struct flow_counter_stats {
276         uint64_t hits;
277         uint64_t bytes;
278 };
279
280 /* Counters information. */
281 struct mlx5_flow_counter {
282         TAILQ_ENTRY(mlx5_flow_counter) next;
283         /**< Pointer to the next flow counter structure. */
284         uint32_t shared:1; /**< Share counter ID with other flow rules. */
285         uint32_t batch: 1;
286         /**< Whether the counter was allocated by batch command. */
287         uint32_t ref_cnt:30; /**< Reference counter. */
288         uint32_t id; /**< Counter ID. */
289         union {  /**< Holds the counters for the rule. */
290 #if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42)
291                 struct ibv_counter_set *cs;
292 #elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
293                 struct ibv_counters *cs;
294 #endif
295                 struct mlx5_devx_obj *dcs; /**< Counter Devx object. */
296                 struct mlx5_flow_counter_pool *pool; /**< The counter pool. */
297         };
298         union {
299                 uint64_t hits; /**< Reset value of hits packets. */
300                 int64_t query_gen; /**< Generation of the last release. */
301         };
302         uint64_t bytes; /**< Reset value of bytes. */
303         void *action; /**< Pointer to the dv action. */
304 };
305
306 TAILQ_HEAD(mlx5_counters, mlx5_flow_counter);
307
308 /* Counter pool structure - query is in pool resolution. */
309 struct mlx5_flow_counter_pool {
310         TAILQ_ENTRY(mlx5_flow_counter_pool) next;
311         struct mlx5_counters counters; /* Free counter list. */
312         union {
313                 struct mlx5_devx_obj *min_dcs;
314                 rte_atomic64_t a64_dcs;
315         };
316         /* The devx object of the minimum counter ID. */
317         rte_atomic64_t query_gen;
318         uint32_t n_counters: 16; /* Number of devx allocated counters. */
319         rte_spinlock_t sl; /* The pool lock. */
320         struct mlx5_counter_stats_raw *raw;
321         struct mlx5_counter_stats_raw *raw_hw; /* The raw on HW working. */
322         struct mlx5_flow_counter counters_raw[]; /* The pool counters memory. */
323 };
324
325 struct mlx5_counter_stats_raw;
326
327 /* Memory management structure for group of counter statistics raws. */
328 struct mlx5_counter_stats_mem_mng {
329         LIST_ENTRY(mlx5_counter_stats_mem_mng) next;
330         struct mlx5_counter_stats_raw *raws;
331         struct mlx5_devx_obj *dm;
332         struct mlx5dv_devx_umem *umem;
333 };
334
335 /* Raw memory structure for the counter statistics values of a pool. */
336 struct mlx5_counter_stats_raw {
337         LIST_ENTRY(mlx5_counter_stats_raw) next;
338         int min_dcs_id;
339         struct mlx5_counter_stats_mem_mng *mem_mng;
340         volatile struct flow_counter_stats *data;
341 };
342
343 TAILQ_HEAD(mlx5_counter_pools, mlx5_flow_counter_pool);
344
345 /* Container structure for counter pools. */
346 struct mlx5_pools_container {
347         rte_atomic16_t n_valid; /* Number of valid pools. */
348         uint16_t n; /* Number of pools. */
349         struct mlx5_counter_pools pool_list; /* Counter pool list. */
350         struct mlx5_flow_counter_pool **pools; /* Counter pool array. */
351         struct mlx5_counter_stats_mem_mng *init_mem_mng;
352         /* Hold the memory management for the next allocated pools raws. */
353 };
354
355 /* Counter global management structure. */
356 struct mlx5_flow_counter_mng {
357         uint8_t mhi[2]; /* master \ host container index. */
358         struct mlx5_pools_container ccont[2 * 2];
359         /* 2 containers for single and for batch for double-buffer. */
360         struct mlx5_counters flow_counters; /* Legacy flow counter list. */
361         uint8_t pending_queries;
362         uint8_t batch;
363         uint16_t pool_index;
364         uint8_t query_thread_on;
365         LIST_HEAD(mem_mngs, mlx5_counter_stats_mem_mng) mem_mngs;
366         LIST_HEAD(stat_raws, mlx5_counter_stats_raw) free_stat_raws;
367 };
368
369 /* Per port data of shared IB device. */
370 struct mlx5_ibv_shared_port {
371         uint32_t ih_port_id;
372         uint32_t devx_ih_port_id;
373         /*
374          * Interrupt handler port_id. Used by shared interrupt
375          * handler to find the corresponding rte_eth device
376          * by IB port index. If value is equal or greater
377          * RTE_MAX_ETHPORTS it means there is no subhandler
378          * installed for specified IB port index.
379          */
380 };
381
382 /* Table key of the hash organization. */
383 union mlx5_flow_tbl_key {
384         struct {
385                 /* Table ID should be at the lowest address. */
386                 uint32_t table_id;      /**< ID of the table. */
387                 uint16_t reserved;      /**< must be zero for comparison. */
388                 uint8_t domain;         /**< 1 - FDB, 0 - NIC TX/RX. */
389                 uint8_t direction;      /**< 1 - egress, 0 - ingress. */
390         };
391         uint64_t v64;                   /**< full 64bits value of key */
392 };
393
394 /* Table structure. */
395 struct mlx5_flow_tbl_resource {
396         void *obj; /**< Pointer to DR table object. */
397         rte_atomic32_t refcnt; /**< Reference counter. */
398 };
399
400 #define MLX5_MAX_TABLES UINT16_MAX
401 #define MLX5_FLOW_TABLE_LEVEL_METER (UINT16_MAX - 3)
402 #define MLX5_FLOW_TABLE_LEVEL_SUFFIX (UINT16_MAX - 2)
403 #define MLX5_HAIRPIN_TX_TABLE (UINT16_MAX - 1)
404 /* Reserve the last two tables for metadata register copy. */
405 #define MLX5_FLOW_MREG_ACT_TABLE_GROUP (MLX5_MAX_TABLES - 1)
406 #define MLX5_FLOW_MREG_CP_TABLE_GROUP (MLX5_MAX_TABLES - 2)
407 /* Tables for metering splits should be added here. */
408 #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)
409 #define MLX5_MAX_TABLES_FDB UINT16_MAX
410
411 #define MLX5_DBR_PAGE_SIZE 4096 /* Must be >= 512. */
412 #define MLX5_DBR_SIZE 8
413 #define MLX5_DBR_PER_PAGE (MLX5_DBR_PAGE_SIZE / MLX5_DBR_SIZE)
414 #define MLX5_DBR_BITMAP_SIZE (MLX5_DBR_PER_PAGE / 64)
415
416 struct mlx5_devx_dbr_page {
417         /* Door-bell records, must be first member in structure. */
418         uint8_t dbrs[MLX5_DBR_PAGE_SIZE];
419         LIST_ENTRY(mlx5_devx_dbr_page) next; /* Pointer to the next element. */
420         struct mlx5dv_devx_umem *umem;
421         uint32_t dbr_count; /* Number of door-bell records in use. */
422         /* 1 bit marks matching door-bell is in use. */
423         uint64_t dbr_bitmap[MLX5_DBR_BITMAP_SIZE];
424 };
425
426 /* ID generation structure. */
427 struct mlx5_flow_id_pool {
428         uint32_t *free_arr; /**< Pointer to the a array of free values. */
429         uint32_t base_index;
430         /**< The next index that can be used without any free elements. */
431         uint32_t *curr; /**< Pointer to the index to pop. */
432         uint32_t *last; /**< Pointer to the last element in the empty arrray. */
433         uint32_t max_id; /**< Maximum id can be allocated from the pool. */
434 };
435
436 /*
437  * Shared Infiniband device context for Master/Representors
438  * which belong to same IB device with multiple IB ports.
439  **/
440 struct mlx5_ibv_shared {
441         LIST_ENTRY(mlx5_ibv_shared) next;
442         uint32_t refcnt;
443         uint32_t devx:1; /* Opened with DV. */
444         uint32_t max_port; /* Maximal IB device port index. */
445         struct ibv_context *ctx; /* Verbs/DV context. */
446         struct ibv_pd *pd; /* Protection Domain. */
447         uint32_t pdn; /* Protection Domain number. */
448         uint32_t tdn; /* Transport Domain number. */
449         char ibdev_name[IBV_SYSFS_NAME_MAX]; /* IB device name. */
450         char ibdev_path[IBV_SYSFS_PATH_MAX]; /* IB device path for secondary */
451         struct ibv_device_attr_ex device_attr; /* Device properties. */
452         LIST_ENTRY(mlx5_ibv_shared) mem_event_cb;
453         /**< Called by memory event callback. */
454         struct {
455                 uint32_t dev_gen; /* Generation number to flush local caches. */
456                 rte_rwlock_t rwlock; /* MR Lock. */
457                 struct mlx5_mr_btree cache; /* Global MR cache table. */
458                 struct mlx5_mr_list mr_list; /* Registered MR list. */
459                 struct mlx5_mr_list mr_free_list; /* Freed MR list. */
460         } mr;
461         /* Shared DV/DR flow data section. */
462         pthread_mutex_t dv_mutex; /* DV context mutex. */
463         uint32_t dv_meta_mask; /* flow META metadata supported mask. */
464         uint32_t dv_mark_mask; /* flow MARK metadata supported mask. */
465         uint32_t dv_regc0_mask; /* available bits of metatada reg_c[0]. */
466         uint32_t dv_refcnt; /* DV/DR data reference counter. */
467         void *fdb_domain; /* FDB Direct Rules name space handle. */
468         struct mlx5_flow_tbl_resource *fdb_mtr_sfx_tbl;
469         /* FDB meter suffix rules table. */
470         void *rx_domain; /* RX Direct Rules name space handle. */
471         struct mlx5_flow_tbl_resource *rx_mtr_sfx_tbl;
472         /* RX meter suffix rules table. */
473         void *tx_domain; /* TX Direct Rules name space handle. */
474         struct mlx5_flow_tbl_resource *tx_mtr_sfx_tbl;
475         /* TX meter suffix rules table. */
476         struct mlx5_hlist *flow_tbls;
477         /* Direct Rules tables for FDB, NIC TX+RX */
478         void *esw_drop_action; /* Pointer to DR E-Switch drop action. */
479         void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
480         LIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps;
481         LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds;
482         struct mlx5_hlist *tag_table;
483         LIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource)
484                 port_id_action_list; /* List of port ID actions. */
485         LIST_HEAD(push_vlan_action_list, mlx5_flow_dv_push_vlan_action_resource)
486                 push_vlan_action_list; /* List of push VLAN actions. */
487         struct mlx5_flow_counter_mng cmng; /* Counters management structure. */
488         /* Shared interrupt handler section. */
489         pthread_mutex_t intr_mutex; /* Interrupt config mutex. */
490         uint32_t intr_cnt; /* Interrupt handler reference counter. */
491         struct rte_intr_handle intr_handle; /* Interrupt handler for device. */
492         uint32_t devx_intr_cnt; /* Devx interrupt handler reference counter. */
493         struct rte_intr_handle intr_handle_devx; /* DEVX interrupt handler. */
494         struct mlx5dv_devx_cmd_comp *devx_comp; /* DEVX async comp obj. */
495         struct mlx5_devx_obj *tis; /* TIS object. */
496         struct mlx5_devx_obj *td; /* Transport domain. */
497         struct mlx5_flow_id_pool *flow_id_pool; /* Flow ID pool. */
498         struct mlx5_ibv_shared_port port[]; /* per device port data array. */
499 };
500
501 /* Per-process private structure. */
502 struct mlx5_proc_priv {
503         size_t uar_table_sz;
504         /* Size of UAR register table. */
505         void *uar_table[];
506         /* Table of UAR registers for each process. */
507 };
508
509 /* MTR profile list. */
510 TAILQ_HEAD(mlx5_mtr_profiles, mlx5_flow_meter_profile);
511 /* MTR list. */
512 TAILQ_HEAD(mlx5_flow_meters, mlx5_flow_meter);
513
514 #define MLX5_PROC_PRIV(port_id) \
515         ((struct mlx5_proc_priv *)rte_eth_devices[port_id].process_private)
516
517 struct mlx5_priv {
518         struct rte_eth_dev_data *dev_data;  /* Pointer to device data. */
519         struct mlx5_ibv_shared *sh; /* Shared IB device context. */
520         uint32_t ibv_port; /* IB device port number. */
521         struct rte_pci_device *pci_dev; /* Backend PCI device. */
522         struct rte_ether_addr mac[MLX5_MAX_MAC_ADDRESSES]; /* MAC addresses. */
523         BITFIELD_DECLARE(mac_own, uint64_t, MLX5_MAX_MAC_ADDRESSES);
524         /* Bit-field of MAC addresses owned by the PMD. */
525         uint16_t vlan_filter[MLX5_MAX_VLAN_IDS]; /* VLAN filters table. */
526         unsigned int vlan_filter_n; /* Number of configured VLAN filters. */
527         /* Device properties. */
528         uint16_t mtu; /* Configured MTU. */
529         unsigned int isolated:1; /* Whether isolated mode is enabled. */
530         unsigned int representor:1; /* Device is a port representor. */
531         unsigned int master:1; /* Device is a E-Switch master. */
532         unsigned int dr_shared:1; /* DV/DR data is shared. */
533         unsigned int counter_fallback:1; /* Use counter fallback management. */
534         unsigned int mtr_en:1; /* Whether support meter. */
535         unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */
536         uint16_t domain_id; /* Switch domain identifier. */
537         uint16_t vport_id; /* Associated VF vport index (if any). */
538         uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
539         uint32_t vport_meta_mask; /* Used for vport index field match mask. */
540         int32_t representor_id; /* Port representor identifier. */
541         int32_t pf_bond; /* >=0 means PF index in bonding configuration. */
542         unsigned int if_index; /* Associated kernel network device index. */
543         /* RX/TX queues. */
544         unsigned int rxqs_n; /* RX queues array size. */
545         unsigned int txqs_n; /* TX queues array size. */
546         struct mlx5_rxq_data *(*rxqs)[]; /* RX queues. */
547         struct mlx5_txq_data *(*txqs)[]; /* TX queues. */
548         struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */
549         struct rte_eth_rss_conf rss_conf; /* RSS configuration. */
550         unsigned int (*reta_idx)[]; /* RETA index table. */
551         unsigned int reta_idx_n; /* RETA index size. */
552         struct mlx5_drop drop_queue; /* Flow drop queues. */
553         struct mlx5_flows flows; /* RTE Flow rules. */
554         struct mlx5_flows ctrl_flows; /* Control flow rules. */
555         LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */
556         LIST_HEAD(rxqobj, mlx5_rxq_obj) rxqsobj; /* Verbs/DevX Rx queues. */
557         LIST_HEAD(hrxq, mlx5_hrxq) hrxqs; /* Verbs Hash Rx queues. */
558         LIST_HEAD(txq, mlx5_txq_ctrl) txqsctrl; /* DPDK Tx queues. */
559         LIST_HEAD(txqobj, mlx5_txq_obj) txqsobj; /* Verbs/DevX Tx queues. */
560         /* Indirection tables. */
561         LIST_HEAD(ind_tables, mlx5_ind_table_obj) ind_tbls;
562         /* Pointer to next element. */
563         rte_atomic32_t refcnt; /**< Reference counter. */
564         struct ibv_flow_action *verbs_action;
565         /**< Verbs modify header action object. */
566         uint8_t ft_type; /**< Flow table type, Rx or Tx. */
567         uint8_t max_lro_msg_size;
568         /* Tags resources cache. */
569         uint32_t link_speed_capa; /* Link speed capabilities. */
570         struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */
571         struct mlx5_stats_ctrl stats_ctrl; /* Stats control. */
572         struct mlx5_dev_config config; /* Device configuration. */
573         struct mlx5_verbs_alloc_ctx verbs_alloc_ctx;
574         /* Context for Verbs allocator. */
575         int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */
576         int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */
577         uint32_t nl_sn; /* Netlink message sequence number. */
578         LIST_HEAD(dbrpage, mlx5_devx_dbr_page) dbrpgs; /* Door-bell pages. */
579         struct mlx5_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */
580         struct mlx5_flow_id_pool *qrss_id_pool;
581         struct mlx5_hlist *mreg_cp_tbl;
582         /* Hash table of Rx metadata register copy table. */
583         uint8_t mtr_sfx_reg; /* Meter prefix-suffix flow match REG_C. */
584         uint8_t mtr_color_reg; /* Meter color match REG_C. */
585         struct mlx5_mtr_profiles flow_meter_profiles; /* MTR profile list. */
586         struct mlx5_flow_meters flow_meters; /* MTR list. */
587 #ifndef RTE_ARCH_64
588         rte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR */
589         rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX];
590         /* UAR same-page access control required in 32bit implementations. */
591 #endif
592         uint8_t skip_default_rss_reta; /* Skip configuration of default reta. */
593 };
594
595 #define PORT_ID(priv) ((priv)->dev_data->port_id)
596 #define ETH_DEV(priv) (&rte_eth_devices[PORT_ID(priv)])
597
598 /* mlx5.c */
599
600 int mlx5_getenv_int(const char *);
601 int mlx5_proc_priv_init(struct rte_eth_dev *dev);
602 int64_t mlx5_get_dbr(struct rte_eth_dev *dev,
603                      struct mlx5_devx_dbr_page **dbr_page);
604 int32_t mlx5_release_dbr(struct rte_eth_dev *dev, uint32_t umem_id,
605                          uint64_t offset);
606 int mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev,
607                               struct rte_eth_udp_tunnel *udp_tunnel);
608 uint16_t mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev);
609
610 /* Macro to iterate over all valid ports for mlx5 driver. */
611 #define MLX5_ETH_FOREACH_DEV(port_id, pci_dev) \
612         for (port_id = mlx5_eth_find_next(0, pci_dev); \
613              port_id < RTE_MAX_ETHPORTS; \
614              port_id = mlx5_eth_find_next(port_id + 1, pci_dev))
615
616 /* mlx5_ethdev.c */
617
618 int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]);
619 int mlx5_get_master_ifname(const char *ibdev_path, char (*ifname)[IF_NAMESIZE]);
620 unsigned int mlx5_ifindex(const struct rte_eth_dev *dev);
621 int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr);
622 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
623 int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep,
624                    unsigned int flags);
625 int mlx5_dev_configure(struct rte_eth_dev *dev);
626 int mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info);
627 int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock);
628 int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size);
629 const uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev);
630 int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete);
631 int mlx5_force_link_status_change(struct rte_eth_dev *dev, int status);
632 int mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
633 int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev,
634                            struct rte_eth_fc_conf *fc_conf);
635 int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
636                            struct rte_eth_fc_conf *fc_conf);
637 void mlx5_dev_link_status_handler(void *arg);
638 void mlx5_dev_interrupt_handler(void *arg);
639 void mlx5_dev_interrupt_handler_devx(void *arg);
640 void mlx5_dev_interrupt_handler_uninstall(struct rte_eth_dev *dev);
641 void mlx5_dev_interrupt_handler_install(struct rte_eth_dev *dev);
642 void mlx5_dev_interrupt_handler_devx_uninstall(struct rte_eth_dev *dev);
643 void mlx5_dev_interrupt_handler_devx_install(struct rte_eth_dev *dev);
644 int mlx5_set_link_down(struct rte_eth_dev *dev);
645 int mlx5_set_link_up(struct rte_eth_dev *dev);
646 int mlx5_is_removed(struct rte_eth_dev *dev);
647 eth_tx_burst_t mlx5_select_tx_function(struct rte_eth_dev *dev);
648 eth_rx_burst_t mlx5_select_rx_function(struct rte_eth_dev *dev);
649 struct mlx5_priv *mlx5_port_to_eswitch_info(uint16_t port, bool valid);
650 struct mlx5_priv *mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev);
651 int mlx5_sysfs_switch_info(unsigned int ifindex,
652                            struct mlx5_switch_info *info);
653 void mlx5_sysfs_check_switch_info(bool device_dir,
654                                   struct mlx5_switch_info *switch_info);
655 void mlx5_nl_check_switch_info(bool nun_vf_set,
656                                struct mlx5_switch_info *switch_info);
657 void mlx5_translate_port_name(const char *port_name_in,
658                               struct mlx5_switch_info *port_info_out);
659 void mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
660                                    rte_intr_callback_fn cb_fn, void *cb_arg);
661 int mlx5_get_module_info(struct rte_eth_dev *dev,
662                          struct rte_eth_dev_module_info *modinfo);
663 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
664                            struct rte_dev_eeprom_info *info);
665 int mlx5_hairpin_cap_get(struct rte_eth_dev *dev,
666                          struct rte_eth_hairpin_cap *cap);
667 int mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev);
668
669 /* mlx5_mac.c */
670
671 int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]);
672 void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
673 int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
674                       uint32_t index, uint32_t vmdq);
675 int mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr);
676 int mlx5_set_mc_addr_list(struct rte_eth_dev *dev,
677                         struct rte_ether_addr *mc_addr_set,
678                         uint32_t nb_mc_addr);
679
680 /* mlx5_rss.c */
681
682 int mlx5_rss_hash_update(struct rte_eth_dev *dev,
683                          struct rte_eth_rss_conf *rss_conf);
684 int mlx5_rss_hash_conf_get(struct rte_eth_dev *dev,
685                            struct rte_eth_rss_conf *rss_conf);
686 int mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size);
687 int mlx5_dev_rss_reta_query(struct rte_eth_dev *dev,
688                             struct rte_eth_rss_reta_entry64 *reta_conf,
689                             uint16_t reta_size);
690 int mlx5_dev_rss_reta_update(struct rte_eth_dev *dev,
691                              struct rte_eth_rss_reta_entry64 *reta_conf,
692                              uint16_t reta_size);
693
694 /* mlx5_rxmode.c */
695
696 int mlx5_promiscuous_enable(struct rte_eth_dev *dev);
697 int mlx5_promiscuous_disable(struct rte_eth_dev *dev);
698 int mlx5_allmulticast_enable(struct rte_eth_dev *dev);
699 int mlx5_allmulticast_disable(struct rte_eth_dev *dev);
700
701 /* mlx5_stats.c */
702
703 void mlx5_stats_init(struct rte_eth_dev *dev);
704 int mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
705 int mlx5_stats_reset(struct rte_eth_dev *dev);
706 int mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
707                     unsigned int n);
708 int mlx5_xstats_reset(struct rte_eth_dev *dev);
709 int mlx5_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
710                           struct rte_eth_xstat_name *xstats_names,
711                           unsigned int n);
712
713 /* mlx5_vlan.c */
714
715 int mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
716 void mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on);
717 int mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask);
718
719 /* mlx5_trigger.c */
720
721 int mlx5_dev_start(struct rte_eth_dev *dev);
722 void mlx5_dev_stop(struct rte_eth_dev *dev);
723 int mlx5_traffic_enable(struct rte_eth_dev *dev);
724 void mlx5_traffic_disable(struct rte_eth_dev *dev);
725 int mlx5_traffic_restart(struct rte_eth_dev *dev);
726
727 /* mlx5_flow.c */
728
729 int mlx5_flow_discover_mreg_c(struct rte_eth_dev *eth_dev);
730 bool mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev);
731 int mlx5_flow_discover_priorities(struct rte_eth_dev *dev);
732 void mlx5_flow_print(struct rte_flow *flow);
733 int mlx5_flow_validate(struct rte_eth_dev *dev,
734                        const struct rte_flow_attr *attr,
735                        const struct rte_flow_item items[],
736                        const struct rte_flow_action actions[],
737                        struct rte_flow_error *error);
738 struct rte_flow *mlx5_flow_create(struct rte_eth_dev *dev,
739                                   const struct rte_flow_attr *attr,
740                                   const struct rte_flow_item items[],
741                                   const struct rte_flow_action actions[],
742                                   struct rte_flow_error *error);
743 int mlx5_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
744                       struct rte_flow_error *error);
745 void mlx5_flow_list_flush(struct rte_eth_dev *dev, struct mlx5_flows *list);
746 int mlx5_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error);
747 int mlx5_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
748                     const struct rte_flow_action *action, void *data,
749                     struct rte_flow_error *error);
750 int mlx5_flow_isolate(struct rte_eth_dev *dev, int enable,
751                       struct rte_flow_error *error);
752 int mlx5_dev_filter_ctrl(struct rte_eth_dev *dev,
753                          enum rte_filter_type filter_type,
754                          enum rte_filter_op filter_op,
755                          void *arg);
756 int mlx5_flow_start(struct rte_eth_dev *dev, struct mlx5_flows *list);
757 void mlx5_flow_stop(struct rte_eth_dev *dev, struct mlx5_flows *list);
758 int mlx5_flow_verify(struct rte_eth_dev *dev);
759 int mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev, uint32_t queue);
760 int mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev,
761                         struct rte_flow_item_eth *eth_spec,
762                         struct rte_flow_item_eth *eth_mask,
763                         struct rte_flow_item_vlan *vlan_spec,
764                         struct rte_flow_item_vlan *vlan_mask);
765 int mlx5_ctrl_flow(struct rte_eth_dev *dev,
766                    struct rte_flow_item_eth *eth_spec,
767                    struct rte_flow_item_eth *eth_mask);
768 struct rte_flow *mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev);
769 int mlx5_flow_create_drop_queue(struct rte_eth_dev *dev);
770 void mlx5_flow_delete_drop_queue(struct rte_eth_dev *dev);
771 void mlx5_flow_async_pool_query_handle(struct mlx5_ibv_shared *sh,
772                                        uint64_t async_id, int status);
773 void mlx5_set_query_alarm(struct mlx5_ibv_shared *sh);
774 void mlx5_flow_query_alarm(void *arg);
775 struct mlx5_flow_counter *mlx5_counter_alloc(struct rte_eth_dev *dev);
776 void mlx5_counter_free(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt);
777 int mlx5_counter_query(struct rte_eth_dev *dev, struct mlx5_flow_counter *cnt,
778                        bool clear, uint64_t *pkts, uint64_t *bytes);
779 int mlx5_flow_dev_dump(struct rte_eth_dev *dev, FILE *file,
780                        struct rte_flow_error *error);
781
782 /* mlx5_mp.c */
783 void mlx5_mp_req_start_rxtx(struct rte_eth_dev *dev);
784 void mlx5_mp_req_stop_rxtx(struct rte_eth_dev *dev);
785 int mlx5_mp_req_mr_create(struct rte_eth_dev *dev, uintptr_t addr);
786 int mlx5_mp_req_verbs_cmd_fd(struct rte_eth_dev *dev);
787 int mlx5_mp_req_queue_state_modify(struct rte_eth_dev *dev,
788                                    struct mlx5_mp_arg_queue_state_modify *sm);
789 int mlx5_mp_init_primary(void);
790 void mlx5_mp_uninit_primary(void);
791 int mlx5_mp_init_secondary(void);
792 void mlx5_mp_uninit_secondary(void);
793
794 /* mlx5_socket.c */
795
796 int mlx5_pmd_socket_init(void);
797 void mlx5_pmd_socket_uninit(void);
798
799 /* mlx5_nl.c */
800
801 int mlx5_nl_init(int protocol);
802 int mlx5_nl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
803                          uint32_t index);
804 int mlx5_nl_mac_addr_remove(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
805                             uint32_t index);
806 void mlx5_nl_mac_addr_sync(struct rte_eth_dev *dev);
807 void mlx5_nl_mac_addr_flush(struct rte_eth_dev *dev);
808 int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable);
809 int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable);
810 unsigned int mlx5_nl_portnum(int nl, const char *name);
811 unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
812 int mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev,
813                                struct rte_ether_addr *mac, int vf_index);
814 int mlx5_nl_switch_info(int nl, unsigned int ifindex,
815                         struct mlx5_switch_info *info);
816
817 struct mlx5_vlan_vmwa_context *mlx5_vlan_vmwa_init(struct rte_eth_dev *dev,
818                                                    uint32_t ifindex);
819 void mlx5_vlan_vmwa_exit(struct mlx5_vlan_vmwa_context *ctx);
820 void mlx5_vlan_vmwa_release(struct rte_eth_dev *dev,
821                             struct mlx5_vf_vlan *vf_vlan);
822 void mlx5_vlan_vmwa_acquire(struct rte_eth_dev *dev,
823                             struct mlx5_vf_vlan *vf_vlan);
824
825 /* mlx5_flow_meter.c */
826
827 int mlx5_flow_meter_ops_get(struct rte_eth_dev *dev, void *arg);
828 struct mlx5_flow_meter *mlx5_flow_meter_find(struct mlx5_priv *priv,
829                                              uint32_t meter_id);
830 struct mlx5_flow_meter *mlx5_flow_meter_attach
831                                         (struct mlx5_priv *priv,
832                                          uint32_t meter_id,
833                                          const struct rte_flow_attr *attr,
834                                          struct rte_flow_error *error);
835 void mlx5_flow_meter_detach(struct mlx5_flow_meter *fm);
836
837 #endif /* RTE_PMD_MLX5_H_ */