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 #include "rte_pmd_mlx5.h" 37 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 38 #ifndef RTE_EXEC_ENV_WINDOWS 39 #define HAVE_MLX5_HWS_SUPPORT 1 40 #else 41 #define __be64 uint64_t 42 #endif 43 #include "hws/mlx5dr.h" 44 #endif 45 46 #define MLX5_SH(dev) (((struct mlx5_priv *)(dev)->data->dev_private)->sh) 47 48 #define MLX5_HW_INV_QUEUE UINT32_MAX 49 50 /* 51 * The default ipool threshold value indicates which per_core_cache 52 * value to set. 53 */ 54 #define MLX5_HW_IPOOL_SIZE_THRESHOLD (1 << 19) 55 /* The default min local cache size. */ 56 #define MLX5_HW_IPOOL_CACHE_MIN (1 << 9) 57 58 /* 59 * Number of modification commands. 60 * The maximal actions amount in FW is some constant, and it is 16 in the 61 * latest releases. In some old releases, it will be limited to 8. 62 * Since there is no interface to query the capacity, the maximal value should 63 * be used to allow PMD to create the flow. The validation will be done in the 64 * lower driver layer or FW. A failure will be returned if exceeds the maximal 65 * supported actions number on the root table. 66 * On non-root tables, there is no limitation, but 32 is enough right now. 67 */ 68 #define MLX5_MAX_MODIFY_NUM 32 69 #define MLX5_ROOT_TBL_MODIFY_NUM 16 70 71 /* Maximal number of flex items created on the port.*/ 72 #define MLX5_PORT_FLEX_ITEM_NUM 4 73 74 /* Maximal number of field/field parts to map into sample registers .*/ 75 #define MLX5_FLEX_ITEM_MAPPING_NUM 32 76 77 enum mlx5_ipool_index { 78 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 79 MLX5_IPOOL_DECAP_ENCAP = 0, /* Pool for encap/decap resource. */ 80 MLX5_IPOOL_PUSH_VLAN, /* Pool for push vlan resource. */ 81 MLX5_IPOOL_TAG, /* Pool for tag resource. */ 82 MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */ 83 MLX5_IPOOL_JUMP, /* Pool for SWS jump resource. */ 84 /* Pool for HWS group. Jump action will be created internally. */ 85 MLX5_IPOOL_HW_GRP = MLX5_IPOOL_JUMP, 86 MLX5_IPOOL_SAMPLE, /* Pool for sample resource. */ 87 MLX5_IPOOL_DEST_ARRAY, /* Pool for destination array resource. */ 88 MLX5_IPOOL_TUNNEL_ID, /* Pool for tunnel offload context */ 89 MLX5_IPOOL_TNL_TBL_ID, /* Pool for tunnel table ID. */ 90 #endif 91 MLX5_IPOOL_MTR, /* Pool for meter resource. */ 92 MLX5_IPOOL_MCP, /* Pool for metadata resource. */ 93 MLX5_IPOOL_HRXQ, /* Pool for hrxq resource. */ 94 MLX5_IPOOL_MLX5_FLOW, /* Pool for mlx5 flow handle. */ 95 MLX5_IPOOL_RTE_FLOW, /* Pool for rte_flow. */ 96 MLX5_IPOOL_RSS_EXPANTION_FLOW_ID, /* Pool for Queue/RSS flow ID. */ 97 MLX5_IPOOL_RSS_SHARED_ACTIONS, /* Pool for RSS shared actions. */ 98 MLX5_IPOOL_MTR_POLICY, /* Pool for meter policy resource. */ 99 MLX5_IPOOL_MAX, 100 }; 101 102 /* 103 * There are three reclaim memory mode supported. 104 * 0(none) means no memory reclaim. 105 * 1(light) means only PMD level reclaim. 106 * 2(aggressive) means both PMD and rdma-core level reclaim. 107 */ 108 enum mlx5_reclaim_mem_mode { 109 MLX5_RCM_NONE, /* Don't reclaim memory. */ 110 MLX5_RCM_LIGHT, /* Reclaim PMD level. */ 111 MLX5_RCM_AGGR, /* Reclaim PMD and rdma-core level. */ 112 }; 113 114 /* The type of flow. */ 115 enum mlx5_flow_type { 116 MLX5_FLOW_TYPE_CTL, /* Control flow. */ 117 MLX5_FLOW_TYPE_GEN, /* General flow. */ 118 MLX5_FLOW_TYPE_MCP, /* MCP flow. */ 119 MLX5_FLOW_TYPE_MAXI, 120 }; 121 122 /* The mode of delay drop for Rx queues. */ 123 enum mlx5_delay_drop_mode { 124 MLX5_DELAY_DROP_NONE = 0, /* All disabled. */ 125 MLX5_DELAY_DROP_STANDARD = RTE_BIT32(0), /* Standard queues enable. */ 126 MLX5_DELAY_DROP_HAIRPIN = RTE_BIT32(1), /* Hairpin queues enable. */ 127 }; 128 129 /* The HWS action type root/non-root. */ 130 enum mlx5_hw_action_flag_type { 131 MLX5_HW_ACTION_FLAG_ROOT, /* Root action. */ 132 MLX5_HW_ACTION_FLAG_NONE_ROOT, /* Non-root ation. */ 133 MLX5_HW_ACTION_FLAG_MAX, /* Maximum action flag. */ 134 }; 135 136 /* Hlist and list callback context. */ 137 struct mlx5_flow_cb_ctx { 138 struct rte_eth_dev *dev; 139 struct rte_flow_error *error; 140 void *data; 141 void *data2; 142 }; 143 144 struct flow_hw_port_info { 145 uint32_t regc_mask; 146 uint32_t regc_value; 147 uint32_t is_wire:1; 148 uint32_t direction:2; 149 }; 150 151 enum mlx5_vport_direction { 152 MLX5_VPORT_DIRECTION_ANY = 0, 153 MLX5_VPORT_DIRECTION_NORTH, 154 MLX5_VPORT_DIRECTION_SOUTH, 155 }; 156 157 /* Device capabilities structure which isn't changed in any stage. */ 158 struct mlx5_dev_cap { 159 int max_cq; /* Maximum number of supported CQs */ 160 int max_qp; /* Maximum number of supported QPs. */ 161 int max_qp_wr; /* Maximum number of outstanding WR on any WQ. */ 162 int max_sge; 163 /* Maximum number of s/g per WR for SQ & RQ of QP for non RDMA Read 164 * operations. 165 */ 166 int mps; /* Multi-packet send supported mode. */ 167 uint32_t vf:1; /* This is a VF. */ 168 uint32_t sf:1; /* This is a SF. */ 169 uint32_t txpp_en:1; /* Tx packet pacing is supported. */ 170 uint32_t mpls_en:1; /* MPLS over GRE/UDP is supported. */ 171 uint32_t cqe_comp:1; /* CQE compression is supported. */ 172 uint32_t hw_csum:1; /* Checksum offload is supported. */ 173 uint32_t hw_padding:1; /* End alignment padding is supported. */ 174 uint32_t dest_tir:1; /* Whether advanced DR API is available. */ 175 uint32_t dv_esw_en:1; /* E-Switch DV flow is supported. */ 176 uint32_t dv_flow_en:1; /* DV flow is supported. */ 177 uint32_t swp:3; /* Tx generic tunnel checksum and TSO offload. */ 178 uint32_t hw_vlan_strip:1; /* VLAN stripping is supported. */ 179 uint32_t scatter_fcs_w_decap_disable:1; 180 /* HW has bug working with tunnel packet decap and scatter FCS. */ 181 uint32_t hw_fcs_strip:1; /* FCS stripping is supported. */ 182 uint32_t rt_timestamp:1; /* Realtime timestamp format. */ 183 uint32_t rq_delay_drop_en:1; /* Enable RxQ delay drop. */ 184 uint32_t tunnel_en:3; 185 /* Whether tunnel stateless offloads are supported. */ 186 uint32_t ind_table_max_size; 187 /* Maximum receive WQ indirection table size. */ 188 uint32_t tso:1; /* Whether TSO is supported. */ 189 uint32_t tso_max_payload_sz; /* Maximum TCP payload for TSO. */ 190 struct { 191 uint32_t enabled:1; /* Whether MPRQ is enabled. */ 192 uint32_t log_min_stride_size; /* Log min size of a stride. */ 193 uint32_t log_max_stride_size; /* Log max size of a stride. */ 194 uint32_t log_min_stride_num; /* Log min num of strides. */ 195 uint32_t log_max_stride_num; /* Log max num of strides. */ 196 uint32_t log_min_stride_wqe_size; 197 /* Log min WQE size, (size of single stride)*(num of strides).*/ 198 } mprq; /* Capability for Multi-Packet RQ. */ 199 char fw_ver[64]; /* Firmware version of this device. */ 200 struct flow_hw_port_info esw_info; /* E-switch manager reg_c0. */ 201 }; 202 203 #define MLX5_MPESW_PORT_INVALID (-1) 204 205 /** Data associated with devices to spawn. */ 206 struct mlx5_dev_spawn_data { 207 uint32_t ifindex; /**< Network interface index. */ 208 uint32_t max_port; /**< Device maximal port index. */ 209 uint32_t phys_port; /**< Device physical port index. */ 210 int pf_bond; /**< bonding device PF index. < 0 - no bonding */ 211 int mpesw_port; /**< MPESW uplink index. Valid if mpesw_owner_port >= 0. */ 212 struct mlx5_switch_info info; /**< Switch information. */ 213 const char *phys_dev_name; /**< Name of physical device. */ 214 struct rte_eth_dev *eth_dev; /**< Associated Ethernet device. */ 215 struct rte_pci_device *pci_dev; /**< Backend PCI device. */ 216 struct mlx5_common_device *cdev; /**< Backend common device. */ 217 struct mlx5_bond_info *bond_info; 218 }; 219 220 /** 221 * Check if the port requested to be probed is MPESW physical device 222 * or a representor port. 223 * 224 * @param spawn 225 * Parameters of the probed port. 226 * 227 * @return 228 * True if the probed port is a physical device or representor in MPESW setup. 229 * False otherwise or MPESW was not configured. 230 */ 231 static inline bool 232 mlx5_is_probed_port_on_mpesw_device(struct mlx5_dev_spawn_data *spawn) 233 { 234 return spawn->mpesw_port >= 0; 235 } 236 237 /** Data associated with socket messages. */ 238 struct mlx5_flow_dump_req { 239 uint32_t port_id; /**< There are plans in DPDK to extend port_id. */ 240 uint64_t flow_id; 241 } __rte_packed; 242 243 struct mlx5_flow_dump_ack { 244 int rc; /**< Return code. */ 245 }; 246 247 LIST_HEAD(mlx5_dev_list, mlx5_dev_ctx_shared); 248 249 /* Shared data between primary and secondary processes. */ 250 struct mlx5_shared_data { 251 rte_spinlock_t lock; 252 /* Global spinlock for primary and secondary processes. */ 253 int init_done; /* Whether primary has done initialization. */ 254 unsigned int secondary_cnt; /* Number of secondary processes init'd. */ 255 }; 256 257 /* Per-process data structure, not visible to other processes. */ 258 struct mlx5_local_data { 259 int init_done; /* Whether a secondary has done initialization. */ 260 }; 261 262 extern struct mlx5_shared_data *mlx5_shared_data; 263 264 /* Dev ops structs */ 265 extern const struct eth_dev_ops mlx5_dev_ops; 266 extern const struct eth_dev_ops mlx5_dev_sec_ops; 267 extern const struct eth_dev_ops mlx5_dev_ops_isolate; 268 269 struct mlx5_counter_ctrl { 270 /* Name of the counter. */ 271 char dpdk_name[RTE_ETH_XSTATS_NAME_SIZE]; 272 /* Name of the counter on the device table. */ 273 char ctr_name[RTE_ETH_XSTATS_NAME_SIZE]; 274 uint32_t dev:1; /**< Nonzero for dev counters. */ 275 }; 276 277 struct mlx5_xstats_ctrl { 278 /* Number of device stats. */ 279 uint16_t stats_n; 280 /* Number of device stats, for the 2nd port in bond. */ 281 uint16_t stats_n_2nd; 282 /* Number of device stats identified by PMD. */ 283 uint16_t mlx5_stats_n; 284 /* First device counters index. */ 285 uint16_t dev_cnt_start; 286 /* Index in the device counters table. */ 287 uint16_t dev_table_idx[MLX5_MAX_XSTATS]; 288 /* Index in the output table. */ 289 uint16_t xstats_o_idx[MLX5_MAX_XSTATS]; 290 uint64_t base[MLX5_MAX_XSTATS]; 291 uint64_t xstats[MLX5_MAX_XSTATS]; 292 uint64_t hw_stats[MLX5_MAX_XSTATS]; 293 struct mlx5_counter_ctrl info[MLX5_MAX_XSTATS]; 294 /* Index in the device counters table, for the 2nd port in bond. */ 295 uint16_t dev_table_idx_2nd[MLX5_MAX_XSTATS]; 296 /* Index in the output table, for the 2nd port in bond. */ 297 uint16_t xstats_o_idx_2nd[MLX5_MAX_XSTATS]; 298 }; 299 300 /* xstats array size. */ 301 extern const unsigned int xstats_n; 302 303 struct mlx5_stats_ctrl { 304 /* Base for imissed counter. */ 305 uint64_t imissed_base; 306 uint64_t imissed; 307 }; 308 309 /* Maximal size of coalesced segment for LRO is set in chunks of 256 Bytes. */ 310 #define MLX5_LRO_SEG_CHUNK_SIZE 256u 311 312 /* Maximal size of aggregated LRO packet. */ 313 #define MLX5_MAX_LRO_SIZE (UINT8_MAX * MLX5_LRO_SEG_CHUNK_SIZE) 314 315 /* Maximal number of segments to split. */ 316 #define MLX5_MAX_RXQ_NSEG (1u << MLX5_MAX_LOG_RQ_SEGS) 317 318 /* 319 * Port configuration structure. 320 * User device parameters disabled features. 321 * This structure contains all configurations coming from devargs which 322 * oriented to port. When probing again, devargs doesn't have to be compatible 323 * with primary devargs. It is updated for each port in spawn function. 324 */ 325 struct mlx5_port_config { 326 unsigned int hw_vlan_insert:1; /* VLAN insertion in WQE is supported. */ 327 unsigned int hw_padding:1; /* End alignment padding is supported. */ 328 unsigned int cqe_comp:1; /* CQE compression is enabled. */ 329 unsigned int enh_cqe_comp:1; /* Enhanced CQE compression is enabled. */ 330 unsigned int cqe_comp_fmt:3; /* CQE compression format. */ 331 unsigned int rx_vec_en:1; /* Rx vector is enabled. */ 332 unsigned int std_delay_drop:1; /* Enable standard Rxq delay drop. */ 333 unsigned int hp_delay_drop:1; /* Enable hairpin Rxq delay drop. */ 334 struct { 335 unsigned int enabled:1; /* Whether MPRQ is enabled. */ 336 unsigned int log_stride_num; /* Log number of strides. */ 337 unsigned int log_stride_size; /* Log size of a stride. */ 338 unsigned int max_memcpy_len; 339 /* Maximum packet size to memcpy Rx packets. */ 340 unsigned int min_rxqs_num; 341 /* Rx queue count threshold to enable MPRQ. */ 342 } mprq; /* Configurations for Multi-Packet RQ. */ 343 int mps; /* Multi-packet send supported mode. */ 344 unsigned int max_dump_files_num; /* Maximum dump files per queue. */ 345 unsigned int log_hp_size; /* Single hairpin queue data size in total. */ 346 unsigned int lro_timeout; /* LRO user configuration. */ 347 int txqs_inline; /* Queue number threshold for inlining. */ 348 int txq_inline_min; /* Minimal amount of data bytes to inline. */ 349 int txq_inline_max; /* Max packet size for inlining with SEND. */ 350 int txq_inline_mpw; /* Max packet size for inlining with eMPW. */ 351 }; 352 353 /* 354 * Share context device configuration structure. 355 * User device parameters disabled features. 356 * This structure updated once for device in mlx5_alloc_shared_dev_ctx() 357 * function and cannot change even when probing again. 358 */ 359 struct mlx5_sh_config { 360 int tx_pp; /* Timestamp scheduling granularity in nanoseconds. */ 361 int tx_skew; /* Tx scheduling skew between WQE and data on wire. */ 362 uint32_t reclaim_mode:2; /* Memory reclaim mode. */ 363 uint32_t dv_esw_en:1; /* Enable E-Switch DV flow. */ 364 /* Enable DV flow. 1 means SW steering, 2 means HW steering. */ 365 uint32_t dv_flow_en:2; /* Enable DV flow. */ 366 uint32_t dv_xmeta_en:3; /* Enable extensive flow metadata. */ 367 uint32_t dv_miss_info:1; /* Restore packet after partial hw miss. */ 368 uint32_t l3_vxlan_en:1; /* Enable L3 VXLAN flow creation. */ 369 uint32_t vf_nl_en:1; /* Enable Netlink requests in VF mode. */ 370 uint32_t lacp_by_user:1; /* Enable user to manage LACP traffic. */ 371 uint32_t decap_en:1; /* Whether decap will be used or not. */ 372 uint32_t hw_fcs_strip:1; /* FCS stripping is supported. */ 373 uint32_t allow_duplicate_pattern:1; 374 uint32_t lro_allowed:1; /* Whether LRO is allowed. */ 375 struct { 376 uint16_t service_core; 377 uint32_t cycle_time; /* query cycle time in milli-second. */ 378 } cnt_svc; /* configure for HW steering's counter's service. */ 379 /* Allow/Prevent the duplicate rules pattern. */ 380 uint32_t fdb_def_rule:1; /* Create FDB default jump rule */ 381 uint32_t repr_matching:1; /* Enable implicit vport matching in HWS FDB. */ 382 }; 383 384 /* Structure for VF VLAN workaround. */ 385 struct mlx5_vf_vlan { 386 uint32_t tag:12; 387 uint32_t created:1; 388 }; 389 390 /* Flow drop context necessary due to Verbs API. */ 391 struct mlx5_drop { 392 struct mlx5_hrxq *hrxq; /* Hash Rx queue queue. */ 393 struct mlx5_rxq_priv *rxq; /* Rx queue. */ 394 }; 395 396 /* Loopback dummy queue resources required due to Verbs API. */ 397 struct mlx5_lb_ctx { 398 struct ibv_qp *qp; /* QP object. */ 399 void *ibv_cq; /* Completion queue. */ 400 RTE_ATOMIC(uint16_t) refcnt; /* Reference count for representors. */ 401 }; 402 403 /* External queue descriptor. */ 404 struct mlx5_external_q { 405 uint32_t hw_id; /* Queue index in the Hardware. */ 406 RTE_ATOMIC(uint32_t) refcnt; /* Reference counter. */ 407 }; 408 409 /* HW steering queue job descriptor type. */ 410 enum mlx5_hw_job_type { 411 MLX5_HW_Q_JOB_TYPE_CREATE, /* Flow create job type. */ 412 MLX5_HW_Q_JOB_TYPE_DESTROY, /* Flow destroy job type. */ 413 MLX5_HW_Q_JOB_TYPE_UPDATE, /* Flow update job type. */ 414 MLX5_HW_Q_JOB_TYPE_QUERY, /* Flow query job type. */ 415 MLX5_HW_Q_JOB_TYPE_UPDATE_QUERY, /* Flow update and query job type. */ 416 MLX5_HW_Q_JOB_TYPE_RSZTBL_FLOW_CREATE, /* Non-optimized flow create job type. */ 417 MLX5_HW_Q_JOB_TYPE_RSZTBL_FLOW_DESTROY, /* Non-optimized destroy create job type. */ 418 MLX5_HW_Q_JOB_TYPE_RSZTBL_FLOW_MOVE, /* Move flow after table resize. */ 419 }; 420 421 enum mlx5_hw_indirect_type { 422 MLX5_HW_INDIRECT_TYPE_LEGACY, 423 MLX5_HW_INDIRECT_TYPE_LIST 424 }; 425 426 #define MLX5_HW_MAX_ITEMS (16) 427 428 /* HW steering flow management job descriptor. */ 429 struct mlx5_hw_q_job { 430 uint32_t type; /* Job type. */ 431 uint32_t indirect_type; 432 const void *action; /* Indirect action attached to the job. */ 433 void *user_data; /* Job user data. */ 434 struct { 435 /* User memory for query output */ 436 void *user; 437 /* Data extracted from hardware */ 438 void *hw; 439 } query; 440 }; 441 442 /* HW steering job descriptor LIFO pool. */ 443 struct __rte_cache_aligned mlx5_hw_q { 444 uint32_t job_idx; /* Free job index. */ 445 uint32_t size; /* Job LIFO queue size. */ 446 uint32_t ongoing_flow_ops; /* Number of ongoing flow operations. */ 447 struct mlx5_hw_q_job **job; /* LIFO header. */ 448 struct rte_ring *indir_cq; /* Indirect action SW completion queue. */ 449 struct rte_ring *indir_iq; /* Indirect action SW in progress queue. */ 450 struct rte_ring *flow_transfer_pending; 451 struct rte_ring *flow_transfer_completed; 452 }; 453 454 455 #define MLX5_COUNTER_POOLS_MAX_NUM (1 << 15) 456 #define MLX5_COUNTERS_PER_POOL 512 457 #define MLX5_MAX_PENDING_QUERIES 4 458 #define MLX5_CNT_MR_ALLOC_BULK 64 459 #define MLX5_CNT_SHARED_OFFSET 0x80000000 460 #define IS_BATCH_CNT(cnt) (((cnt) & (MLX5_CNT_SHARED_OFFSET - 1)) >= \ 461 MLX5_CNT_BATCH_OFFSET) 462 #define MLX5_CNT_SIZE (sizeof(struct mlx5_flow_counter)) 463 #define MLX5_AGE_SIZE (sizeof(struct mlx5_age_param)) 464 465 #define MLX5_CNT_LEN(pool) \ 466 (MLX5_CNT_SIZE + \ 467 ((pool)->is_aged ? MLX5_AGE_SIZE : 0)) 468 #define MLX5_POOL_GET_CNT(pool, index) \ 469 ((struct mlx5_flow_counter *) \ 470 ((uint8_t *)((pool) + 1) + (index) * (MLX5_CNT_LEN(pool)))) 471 #define MLX5_CNT_ARRAY_IDX(pool, cnt) \ 472 ((int)(((uint8_t *)(cnt) - (uint8_t *)((pool) + 1)) / \ 473 MLX5_CNT_LEN(pool))) 474 #define MLX5_TS_MASK_SECS 8ull 475 /* timestamp wrapping in seconds, must be power of 2. */ 476 477 /* 478 * The pool index and offset of counter in the pool array makes up the 479 * counter index. In case the counter is from pool 0 and offset 0, it 480 * should plus 1 to avoid index 0, since 0 means invalid counter index 481 * currently. 482 */ 483 #define MLX5_MAKE_CNT_IDX(pi, offset) \ 484 ((pi) * MLX5_COUNTERS_PER_POOL + (offset) + 1) 485 #define MLX5_CNT_TO_AGE(cnt) \ 486 ((struct mlx5_age_param *)((cnt) + 1)) 487 /* 488 * The maximum single counter is 0x800000 as MLX5_CNT_BATCH_OFFSET 489 * defines. The pool size is 512, pool index should never reach 490 * INT16_MAX. 491 */ 492 #define POOL_IDX_INVALID UINT16_MAX 493 494 /* Age status. */ 495 enum { 496 AGE_FREE, /* Initialized state. */ 497 AGE_CANDIDATE, /* Counter assigned to flows. */ 498 AGE_TMOUT, /* Timeout, wait for rte_flow_get_aged_flows and destroy. */ 499 }; 500 501 enum mlx5_counter_type { 502 MLX5_COUNTER_TYPE_ORIGIN, 503 MLX5_COUNTER_TYPE_AGE, 504 MLX5_COUNTER_TYPE_MAX, 505 }; 506 507 /* Counter age parameter. */ 508 struct mlx5_age_param { 509 RTE_ATOMIC(uint16_t) state; /**< Age state (atomically accessed). */ 510 uint16_t port_id; /**< Port id of the counter. */ 511 uint32_t timeout:24; /**< Aging timeout in seconds. */ 512 RTE_ATOMIC(uint32_t) sec_since_last_hit; 513 /**< Time in seconds since last hit (atomically accessed). */ 514 void *context; /**< Flow counter age context. */ 515 }; 516 517 struct flow_counter_stats { 518 uint64_t hits; 519 uint64_t bytes; 520 }; 521 522 /* Shared counters information for counters. */ 523 struct mlx5_flow_counter_shared { 524 union { 525 RTE_ATOMIC(uint32_t) refcnt; /* Only for shared action management. */ 526 uint32_t id; /* User counter ID for legacy sharing. */ 527 }; 528 }; 529 530 struct mlx5_flow_counter_pool; 531 /* Generic counters information. */ 532 struct mlx5_flow_counter { 533 union { 534 /* 535 * User-defined counter shared info is only used during 536 * counter active time. And aging counter sharing is not 537 * supported, so active shared counter will not be chained 538 * to the aging list. For shared counter, only when it is 539 * released, the TAILQ entry memory will be used, at that 540 * time, shared memory is not used anymore. 541 * 542 * Similarly to none-batch counter dcs, since it doesn't 543 * support aging, while counter is allocated, the entry 544 * memory is not used anymore. In this case, as bytes 545 * memory is used only when counter is allocated, and 546 * entry memory is used only when counter is free. The 547 * dcs pointer can be saved to these two different place 548 * at different stage. It will eliminate the individual 549 * counter extend struct. 550 */ 551 TAILQ_ENTRY(mlx5_flow_counter) next; 552 /**< Pointer to the next flow counter structure. */ 553 struct { 554 struct mlx5_flow_counter_shared shared_info; 555 /**< Shared counter information. */ 556 void *dcs_when_active; 557 /* 558 * For non-batch mode, the dcs will be saved 559 * here when the counter is free. 560 */ 561 }; 562 }; 563 union { 564 uint64_t hits; /**< Reset value of hits packets. */ 565 struct mlx5_flow_counter_pool *pool; /**< Counter pool. */ 566 }; 567 union { 568 uint64_t bytes; /**< Reset value of bytes. */ 569 void *dcs_when_free; 570 /* 571 * For non-batch mode, the dcs will be saved here 572 * when the counter is free. 573 */ 574 }; 575 void *action; /**< Pointer to the dv action. */ 576 }; 577 578 TAILQ_HEAD(mlx5_counters, mlx5_flow_counter); 579 580 /* Generic counter pool structure - query is in pool resolution. */ 581 struct mlx5_flow_counter_pool { 582 TAILQ_ENTRY(mlx5_flow_counter_pool) next; 583 struct mlx5_counters counters[2]; /* Free counter list. */ 584 struct mlx5_devx_obj *min_dcs; 585 /* The devx object of the minimum counter ID. */ 586 uint64_t time_of_last_age_check; 587 /* System time (from rte_rdtsc()) read in the last aging check. */ 588 uint32_t index:30; /* Pool index in container. */ 589 uint32_t is_aged:1; /* Pool with aging counter. */ 590 volatile uint32_t query_gen:1; /* Query round. */ 591 rte_spinlock_t sl; /* The pool lock. */ 592 rte_spinlock_t csl; /* The pool counter free list lock. */ 593 struct mlx5_counter_stats_raw *raw; 594 struct mlx5_counter_stats_raw *raw_hw; 595 /* The raw on HW working. */ 596 }; 597 598 /* Memory management structure for group of counter statistics raws. */ 599 struct mlx5_counter_stats_mem_mng { 600 LIST_ENTRY(mlx5_counter_stats_mem_mng) next; 601 struct mlx5_counter_stats_raw *raws; 602 struct mlx5_pmd_wrapped_mr wm; 603 }; 604 605 /* Raw memory structure for the counter statistics values of a pool. */ 606 struct mlx5_counter_stats_raw { 607 LIST_ENTRY(mlx5_counter_stats_raw) next; 608 struct mlx5_counter_stats_mem_mng *mem_mng; 609 volatile struct flow_counter_stats *data; 610 }; 611 612 TAILQ_HEAD(mlx5_counter_pools, mlx5_flow_counter_pool); 613 614 /* Counter global management structure. */ 615 struct mlx5_flow_counter_mng { 616 volatile RTE_ATOMIC(uint16_t) n_valid; /* Number of valid pools. */ 617 uint16_t last_pool_idx; /* Last used pool index */ 618 int min_id; /* The minimum counter ID in the pools. */ 619 int max_id; /* The maximum counter ID in the pools. */ 620 rte_spinlock_t pool_update_sl; /* The pool update lock. */ 621 rte_spinlock_t csl[MLX5_COUNTER_TYPE_MAX]; 622 /* The counter free list lock. */ 623 struct mlx5_counters counters[MLX5_COUNTER_TYPE_MAX]; 624 /* Free counter list. */ 625 struct mlx5_flow_counter_pool **pools; /* Counter pool array. */ 626 struct mlx5_counter_stats_mem_mng *mem_mng; 627 /* Hold the memory management for the next allocated pools raws. */ 628 struct mlx5_counters flow_counters; /* Legacy flow counter list. */ 629 uint8_t pending_queries; 630 uint16_t pool_index; 631 uint8_t query_thread_on; 632 bool counter_fallback; /* Use counter fallback management. */ 633 LIST_HEAD(mem_mngs, mlx5_counter_stats_mem_mng) mem_mngs; 634 LIST_HEAD(stat_raws, mlx5_counter_stats_raw) free_stat_raws; 635 }; 636 637 /* ASO structures. */ 638 #define MLX5_ASO_QUEUE_LOG_DESC 10 639 640 struct mlx5_aso_cq { 641 uint16_t log_desc_n; 642 uint32_t cq_ci:24; 643 struct mlx5_devx_cq cq_obj; 644 uint64_t errors; 645 }; 646 647 struct mlx5_aso_sq_elem { 648 union { 649 struct { 650 struct mlx5_aso_age_pool *pool; 651 uint16_t burst_size; 652 }; 653 struct mlx5_aso_mtr *mtr; 654 struct { 655 struct mlx5_aso_ct_action *ct; 656 char *query_data; 657 }; 658 void *user_data; 659 struct mlx5_quota *quota_obj; 660 }; 661 }; 662 663 struct mlx5_aso_sq { 664 uint16_t log_desc_n; 665 rte_spinlock_t sqsl; 666 struct mlx5_aso_cq cq; 667 struct mlx5_devx_sq sq_obj; 668 struct mlx5_pmd_mr mr; 669 volatile struct mlx5_aso_wqe *db; 670 uint16_t pi; 671 uint16_t db_pi; 672 uint32_t head; 673 uint32_t tail; 674 uint32_t sqn; 675 struct mlx5_aso_sq_elem elts[1 << MLX5_ASO_QUEUE_LOG_DESC]; 676 uint16_t next; /* Pool index of the next pool to query. */ 677 }; 678 679 struct mlx5_aso_age_action { 680 LIST_ENTRY(mlx5_aso_age_action) next; 681 void *dr_action; 682 RTE_ATOMIC(uint32_t) refcnt; 683 /* Following fields relevant only when action is active. */ 684 uint16_t offset; /* Offset of ASO Flow Hit flag in DevX object. */ 685 struct mlx5_age_param age_params; 686 }; 687 688 #define MLX5_ASO_AGE_ACTIONS_PER_POOL 512 689 #define MLX5_ASO_AGE_CONTAINER_RESIZE 64 690 691 struct mlx5_aso_age_pool { 692 struct mlx5_devx_obj *flow_hit_aso_obj; 693 uint16_t index; /* Pool index in pools array. */ 694 uint64_t time_of_last_age_check; /* In seconds. */ 695 struct mlx5_aso_age_action actions[MLX5_ASO_AGE_ACTIONS_PER_POOL]; 696 }; 697 698 LIST_HEAD(aso_age_list, mlx5_aso_age_action); 699 700 struct mlx5_aso_age_mng { 701 struct mlx5_aso_age_pool **pools; 702 uint16_t n; /* Total number of pools. */ 703 uint16_t next; /* Number of pools in use, index of next free pool. */ 704 rte_rwlock_t resize_rwl; /* Lock for resize objects. */ 705 rte_spinlock_t free_sl; /* Lock for free list access. */ 706 struct aso_age_list free; /* Free age actions list - ready to use. */ 707 struct mlx5_aso_sq aso_sq; /* ASO queue objects. */ 708 }; 709 710 /* Management structure for geneve tlv option */ 711 struct mlx5_geneve_tlv_option_resource { 712 struct mlx5_devx_obj *obj; /* Pointer to the geneve tlv opt object. */ 713 rte_be16_t option_class; /* geneve tlv opt class.*/ 714 uint8_t option_type; /* geneve tlv opt type.*/ 715 uint8_t length; /* geneve tlv opt length. */ 716 RTE_ATOMIC(uint32_t) refcnt; /* geneve tlv object reference counter */ 717 }; 718 719 720 #define MLX5_AGE_EVENT_NEW 1 721 #define MLX5_AGE_TRIGGER 2 722 #define MLX5_AGE_SET(age_info, BIT) \ 723 ((age_info)->flags |= (1 << (BIT))) 724 #define MLX5_AGE_UNSET(age_info, BIT) \ 725 ((age_info)->flags &= ~(1 << (BIT))) 726 #define MLX5_AGE_GET(age_info, BIT) \ 727 ((age_info)->flags & (1 << (BIT))) 728 #define GET_PORT_AGE_INFO(priv) \ 729 (&((priv)->sh->port[(priv)->dev_port - 1].age_info)) 730 /* Current time in seconds. */ 731 #define MLX5_CURR_TIME_SEC (rte_rdtsc() / rte_get_tsc_hz()) 732 733 /* 734 * HW steering queue oriented AGE info. 735 * It contains an array of rings, one for each HWS queue. 736 */ 737 struct mlx5_hws_q_age_info { 738 uint16_t nb_rings; /* Number of aged-out ring lists. */ 739 struct rte_ring *aged_lists[]; /* Aged-out lists. */ 740 }; 741 742 /* 743 * HW steering AGE info. 744 * It has a ring list containing all aged out flow rules. 745 */ 746 struct mlx5_hws_age_info { 747 struct rte_ring *aged_list; /* Aged out lists. */ 748 }; 749 750 /* Aging information for per port. */ 751 struct mlx5_age_info { 752 uint8_t flags; /* Indicate if is new event or need to be triggered. */ 753 union { 754 /* SW/FW steering AGE info. */ 755 struct { 756 struct mlx5_counters aged_counters; 757 /* Aged counter list. */ 758 struct aso_age_list aged_aso; 759 /* Aged ASO actions list. */ 760 rte_spinlock_t aged_sl; /* Aged flow list lock. */ 761 }; 762 struct { 763 struct mlx5_indexed_pool *ages_ipool; 764 union { 765 struct mlx5_hws_age_info hw_age; 766 /* HW steering AGE info. */ 767 struct mlx5_hws_q_age_info *hw_q_age; 768 /* HW steering queue oriented AGE info. */ 769 }; 770 }; 771 }; 772 }; 773 774 /* Per port data of shared IB device. */ 775 struct mlx5_dev_shared_port { 776 uint32_t ih_port_id; 777 uint32_t devx_ih_port_id; 778 uint32_t nl_ih_port_id; 779 /* 780 * Interrupt handler port_id. Used by shared interrupt 781 * handler to find the corresponding rte_eth device 782 * by IB port index. If value is equal or greater 783 * RTE_MAX_ETHPORTS it means there is no subhandler 784 * installed for specified IB port index. 785 */ 786 struct mlx5_age_info age_info; 787 /* Aging information for per port. */ 788 }; 789 790 /* 791 * Max number of actions per DV flow. 792 * See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED 793 * in rdma-core file providers/mlx5/verbs.c. 794 */ 795 #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 796 797 /* ASO flow meter structures */ 798 /* Modify this value if enum rte_mtr_color changes. */ 799 #define RTE_MTR_DROPPED RTE_COLORS 800 /* Yellow is now supported. */ 801 #define MLX5_MTR_RTE_COLORS (RTE_COLOR_YELLOW + 1) 802 /* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */ 803 #define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF 804 #define MLX5_INVALID_POLICY_ID UINT32_MAX 805 /* Suffix table_id on MLX5_FLOW_TABLE_LEVEL_METER. */ 806 #define MLX5_MTR_TABLE_ID_SUFFIX 1 807 /* Drop table_id on MLX5_FLOW_TABLE_LEVEL_METER. */ 808 #define MLX5_MTR_TABLE_ID_DROP 2 809 /* Priority of the meter policy matcher. */ 810 #define MLX5_MTR_POLICY_MATCHER_PRIO 0 811 /* Green & yellow color valid for now. */ 812 #define MLX5_MTR_POLICY_MODE_ALL 0 813 /* Default policy. */ 814 #define MLX5_MTR_POLICY_MODE_DEF 1 815 /* Only green color valid. */ 816 #define MLX5_MTR_POLICY_MODE_OG 2 817 /* Only yellow color valid. */ 818 #define MLX5_MTR_POLICY_MODE_OY 3 819 820 /* Max number of meters. */ 821 #define MLX5_MTR_MAX(priv) (mlx5_flow_mtr_max_get(priv)) 822 /* Max number of meters allocated in non template mode. */ 823 #define MLX5_MTR_NT_MAX(priv) (MLX5_MTR_MAX(priv) >> 1) 824 /* Max number of connection tracking. */ 825 #define MLX5_CT_MAX(priv) (1 << (priv)->sh->cdev->config.hca_attr.log_max_conn_track_offload) 826 /* Max number of connection tracking allocated in non template mode. */ 827 #define MLX5_CT_NT_MAX(priv) (MLX5_CT_MAX(priv) >> 1) 828 /* Max number of counters. */ 829 #define MLX5_CNT_MAX(priv) ((priv)->sh->hws_max_nb_counters) 830 /* Max number of counters allocated in non template mode. */ 831 #define MLX5_CNT_NT_MAX(priv) (MLX5_CNT_MAX(priv) >> 1) 832 833 enum mlx5_meter_domain { 834 MLX5_MTR_DOMAIN_INGRESS, 835 MLX5_MTR_DOMAIN_EGRESS, 836 MLX5_MTR_DOMAIN_TRANSFER, 837 MLX5_MTR_DOMAIN_MAX, 838 }; 839 #define MLX5_MTR_DOMAIN_INGRESS_BIT (1 << MLX5_MTR_DOMAIN_INGRESS) 840 #define MLX5_MTR_DOMAIN_EGRESS_BIT (1 << MLX5_MTR_DOMAIN_EGRESS) 841 #define MLX5_MTR_DOMAIN_TRANSFER_BIT (1 << MLX5_MTR_DOMAIN_TRANSFER) 842 #define MLX5_MTR_ALL_DOMAIN_BIT (MLX5_MTR_DOMAIN_INGRESS_BIT | \ 843 MLX5_MTR_DOMAIN_EGRESS_BIT | \ 844 MLX5_MTR_DOMAIN_TRANSFER_BIT) 845 846 /* The color tag rule structure. */ 847 struct mlx5_sub_policy_color_rule { 848 void *rule; 849 /* The color rule. */ 850 struct mlx5_flow_dv_matcher *matcher; 851 /* The color matcher. */ 852 TAILQ_ENTRY(mlx5_sub_policy_color_rule) next_port; 853 /**< Pointer to the next color rule structure. */ 854 int32_t src_port; 855 /* On which src port this rule applied. */ 856 }; 857 858 TAILQ_HEAD(mlx5_sub_policy_color_rules, mlx5_sub_policy_color_rule); 859 860 /* 861 * Meter sub-policy structure. 862 * Each RSS TIR in meter policy need its own sub-policy resource. 863 */ 864 struct mlx5_flow_meter_sub_policy { 865 uint32_t main_policy_id:1; 866 /* Main policy id is same as this sub_policy id. */ 867 uint32_t idx:31; 868 /* Index to sub_policy ipool entity. */ 869 void *main_policy; 870 /* Point to struct mlx5_flow_meter_policy. */ 871 struct mlx5_flow_tbl_resource *tbl_rsc; 872 /* The sub-policy table resource. */ 873 uint32_t rix_hrxq[MLX5_MTR_RTE_COLORS]; 874 /* Index to TIR resource. */ 875 struct mlx5_flow_tbl_resource *jump_tbl[MLX5_MTR_RTE_COLORS]; 876 /* Meter jump/drop table. */ 877 struct mlx5_sub_policy_color_rules color_rules[RTE_COLORS]; 878 /* List for the color rules. */ 879 }; 880 881 struct mlx5_meter_policy_acts { 882 uint8_t actions_n; 883 /* Number of actions. */ 884 void *dv_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; 885 /* Action list. */ 886 }; 887 888 struct mlx5_meter_policy_action_container { 889 uint32_t rix_mark; 890 /* Index to the mark action. */ 891 struct mlx5_flow_dv_modify_hdr_resource *modify_hdr; 892 /* Pointer to modify header resource in cache. */ 893 uint8_t fate_action; 894 /* Fate action type. */ 895 union { 896 struct rte_flow_action *rss; 897 /* Rss action configuration. */ 898 uint32_t rix_port_id_action; 899 /* Index to port ID action resource. */ 900 void *dr_jump_action[MLX5_MTR_DOMAIN_MAX]; 901 /* Jump/drop action per color. */ 902 uint16_t queue; 903 /* Queue action configuration. */ 904 struct { 905 uint32_t next_mtr_id; 906 /* The next meter id. */ 907 void *next_sub_policy; 908 /* Next meter's sub-policy. */ 909 }; 910 }; 911 }; 912 913 /* Flow meter policy parameter structure. */ 914 struct mlx5_flow_meter_policy { 915 uint32_t is_rss:1; 916 /* Is RSS policy table. */ 917 uint32_t ingress:1; 918 /* Rule applies to ingress domain. */ 919 uint32_t egress:1; 920 /* Rule applies to egress domain. */ 921 uint32_t transfer:1; 922 /* Rule applies to transfer domain. */ 923 uint32_t is_queue:1; 924 /* Is queue action in policy table. */ 925 uint32_t is_hierarchy:1; 926 /* Is meter action in policy table. */ 927 uint32_t match_port:1; 928 /* If policy flows match src port. */ 929 uint32_t hierarchy_match_port:1; 930 /* Is any meter in hierarchy contains policy flow that matches src port. */ 931 uint32_t skip_r:1; 932 /* If red color policy is skipped. */ 933 uint32_t skip_y:1; 934 /* If yellow color policy is skipped. */ 935 uint32_t skip_g:1; 936 /* If green color policy is skipped. */ 937 uint32_t mark:1; 938 /* If policy contains mark action. */ 939 uint32_t initialized:1; 940 /* Initialized. */ 941 uint16_t group; 942 /* The group. */ 943 rte_spinlock_t sl; 944 RTE_ATOMIC(uint32_t) ref_cnt; 945 /* Use count. */ 946 struct rte_flow_pattern_template *hws_item_templ; 947 /* Hardware steering item templates. */ 948 struct rte_flow_actions_template *hws_act_templ[MLX5_MTR_DOMAIN_MAX]; 949 /* Hardware steering action templates. */ 950 struct rte_flow_template_table *hws_flow_table[MLX5_MTR_DOMAIN_MAX]; 951 /* Hardware steering tables. */ 952 struct rte_flow *hws_flow_rule[MLX5_MTR_DOMAIN_MAX][RTE_COLORS]; 953 /* Hardware steering rules. */ 954 struct mlx5_meter_policy_action_container act_cnt[MLX5_MTR_RTE_COLORS]; 955 /* Policy actions container. */ 956 void *dr_drop_action[MLX5_MTR_DOMAIN_MAX]; 957 /* drop action for red color. */ 958 uint16_t sub_policy_num; 959 /* Count sub policy tables, 3 bits per domain. */ 960 struct mlx5_flow_meter_sub_policy **sub_policys[MLX5_MTR_DOMAIN_MAX]; 961 /* Sub policy table array must be the end of struct. */ 962 }; 963 964 /* The maximum sub policy is relate to struct mlx5_rss_hash_fields[]. */ 965 #define MLX5_MTR_RSS_MAX_SUB_POLICY 7 966 #define MLX5_MTR_SUB_POLICY_NUM_SHIFT 3 967 #define MLX5_MTR_SUB_POLICY_NUM_MASK 0x7 968 #define MLX5_MTRS_DEFAULT_RULE_PRIORITY 0xFFFF 969 #define MLX5_MTR_CHAIN_MAX_NUM 8 970 971 /* Flow meter default policy parameter structure. 972 * Policy index 0 is reserved by default policy table. 973 * Action per color as below: 974 * green - do nothing, yellow - do nothing, red - drop 975 */ 976 struct mlx5_flow_meter_def_policy { 977 struct mlx5_flow_meter_sub_policy sub_policy; 978 /* Policy rules jump to other tables. */ 979 void *dr_jump_action[RTE_COLORS]; 980 /* Jump action per color. */ 981 }; 982 983 /* Meter parameter structure. */ 984 struct mlx5_flow_meter_info { 985 uint32_t meter_id; 986 /**< Meter id. */ 987 uint32_t policy_id; 988 /* Policy id, the first sub_policy idx. */ 989 struct mlx5_flow_meter_profile *profile; 990 /**< Meter profile parameters. */ 991 rte_spinlock_t sl; /**< Meter action spinlock. */ 992 /** Set of stats counters to be enabled. 993 * @see enum rte_mtr_stats_type 994 */ 995 uint32_t bytes_dropped:1; 996 /** Set bytes dropped stats to be enabled. */ 997 uint32_t pkts_dropped:1; 998 /** Set packets dropped stats to be enabled. */ 999 uint32_t active_state:1; 1000 /**< Meter hw active state. */ 1001 uint32_t shared:1; 1002 /**< Meter shared or not. */ 1003 uint32_t is_enable:1; 1004 /**< Meter disable/enable state. */ 1005 uint32_t ingress:1; 1006 /**< Rule applies to egress traffic. */ 1007 uint32_t egress:1; 1008 /** 1009 * Instead of simply matching the properties of traffic as it would 1010 * appear on a given DPDK port ID, enabling this attribute transfers 1011 * a flow rule to the lowest possible level of any device endpoints 1012 * found in the pattern. 1013 * 1014 * When supported, this effectively enables an application to 1015 * re-route traffic not necessarily intended for it (e.g. coming 1016 * from or addressed to different physical ports, VFs or 1017 * applications) at the device level. 1018 * 1019 * It complements the behavior of some pattern items such as 1020 * RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT and is meaningless without them. 1021 * 1022 * When transferring flow rules, ingress and egress attributes keep 1023 * their original meaning, as if processing traffic emitted or 1024 * received by the application. 1025 */ 1026 uint32_t transfer:1; 1027 uint32_t def_policy:1; 1028 uint32_t initialized:1; 1029 /* Meter points to default policy. */ 1030 uint32_t color_aware:1; 1031 /* Meter is color aware mode. */ 1032 void *drop_rule[MLX5_MTR_DOMAIN_MAX]; 1033 /* Meter drop rule in drop table. */ 1034 uint32_t drop_cnt; 1035 /**< Color counter for drop. */ 1036 uint32_t ref_cnt; 1037 /**< Use count. */ 1038 struct mlx5_indexed_pool *flow_ipool; 1039 /**< Index pool for flow id. */ 1040 void *meter_action_g; 1041 /**< Flow meter action. */ 1042 void *meter_action_y; 1043 /**< Flow meter action for yellow init_color. */ 1044 uint32_t meter_offset; 1045 /**< Flow meter offset. */ 1046 uint16_t group; 1047 /**< Flow meter group. */ 1048 }; 1049 1050 /* PPS(packets per second) map to BPS(Bytes per second). 1051 * HW treat packet as 128bytes in PPS mode 1052 */ 1053 #define MLX5_MTRS_PPS_MAP_BPS_SHIFT 7 1054 1055 /* RFC2697 parameter structure. */ 1056 struct mlx5_flow_meter_srtcm_rfc2697_prm { 1057 rte_be32_t cbs_cir; 1058 /* 1059 * bit 24-28: cbs_exponent, bit 16-23 cbs_mantissa, 1060 * bit 8-12: cir_exponent, bit 0-7 cir_mantissa. 1061 */ 1062 rte_be32_t ebs_eir; 1063 /* 1064 * bit 24-28: ebs_exponent, bit 16-23 ebs_mantissa, 1065 * bit 8-12: eir_exponent, bit 0-7 eir_mantissa. 1066 */ 1067 }; 1068 1069 /* Flow meter profile structure. */ 1070 struct mlx5_flow_meter_profile { 1071 TAILQ_ENTRY(mlx5_flow_meter_profile) next; 1072 /**< Pointer to the next flow meter structure. */ 1073 uint32_t id; /**< Profile id. */ 1074 struct rte_mtr_meter_profile profile; /**< Profile detail. */ 1075 union { 1076 struct mlx5_flow_meter_srtcm_rfc2697_prm srtcm_prm; 1077 /**< srtcm_rfc2697 struct. */ 1078 }; 1079 RTE_ATOMIC(uint32_t) ref_cnt; /**< Use count. */ 1080 uint32_t g_support:1; /**< If G color will be generated. */ 1081 uint32_t y_support:1; /**< If Y color will be generated. */ 1082 uint32_t initialized:1; /**< Initialized. */ 1083 }; 1084 1085 /* 2 meters in each ASO cache line */ 1086 #define MLX5_MTRS_CONTAINER_RESIZE 64 1087 /* 1088 * The pool index and offset of meter in the pool array makes up the 1089 * meter index. In case the meter is from pool 0 and offset 0, it 1090 * should plus 1 to avoid index 0, since 0 means invalid meter index 1091 * currently. 1092 */ 1093 #define MLX5_MAKE_MTR_IDX(pi, offset) \ 1094 ((pi) * MLX5_ASO_MTRS_PER_POOL + (offset) + 1) 1095 1096 /*aso flow meter state*/ 1097 enum mlx5_aso_mtr_state { 1098 ASO_METER_FREE, /* In free list. */ 1099 ASO_METER_WAIT, /* ACCESS_ASO WQE in progress. */ 1100 ASO_METER_WAIT_ASYNC, /* CQE will be handled by async pull. */ 1101 ASO_METER_READY, /* CQE received. */ 1102 }; 1103 1104 /*aso flow meter type*/ 1105 enum mlx5_aso_mtr_type { 1106 ASO_METER_INDIRECT, 1107 ASO_METER_DIRECT, 1108 }; 1109 1110 /* Generic aso_flow_meter information. */ 1111 struct mlx5_aso_mtr { 1112 union { 1113 LIST_ENTRY(mlx5_aso_mtr) next; 1114 struct mlx5_aso_mtr_pool *pool; 1115 }; 1116 enum mlx5_aso_mtr_type type; 1117 struct mlx5_flow_meter_info fm; 1118 /**< Pointer to the next aso flow meter structure. */ 1119 RTE_ATOMIC(uint8_t) state; /**< ASO flow meter state. */ 1120 uint32_t offset; 1121 enum rte_color init_color; 1122 }; 1123 1124 /* Generic aso_flow_meter pool structure. */ 1125 struct mlx5_aso_mtr_pool { 1126 struct mlx5_aso_mtr mtrs[MLX5_ASO_MTRS_PER_POOL]; 1127 /*Must be the first in pool*/ 1128 struct mlx5_devx_obj *devx_obj; 1129 /* The devx object of the minimum aso flow meter ID. */ 1130 struct mlx5dr_action *action; /* HWS action. */ 1131 struct mlx5_indexed_pool *idx_pool; /* HWS index pool. */ 1132 uint32_t index; /* Pool index in management structure. */ 1133 uint32_t nb_sq; /* Number of ASO SQ. */ 1134 struct mlx5_aso_sq *sq; /* ASO SQs. */ 1135 }; 1136 1137 LIST_HEAD(aso_meter_list, mlx5_aso_mtr); 1138 /* Pools management structure for ASO flow meter pools. */ 1139 struct mlx5_aso_mtr_pools_mng { 1140 volatile uint16_t n_valid; /* Number of valid pools. */ 1141 uint16_t n; /* Number of pools. */ 1142 rte_spinlock_t mtrsl; /* The ASO flow meter free list lock. */ 1143 rte_rwlock_t resize_mtrwl; /* Lock for resize objects. */ 1144 struct aso_meter_list meters; /* Free ASO flow meter list. */ 1145 struct mlx5_aso_sq sq; /*SQ using by ASO flow meter. */ 1146 struct mlx5_aso_mtr_pool **pools; /* ASO flow meter pool array. */ 1147 }; 1148 1149 /* Bulk management structure for ASO flow meter. */ 1150 struct mlx5_mtr_bulk { 1151 uint32_t size; /* Number of ASO objects. */ 1152 struct mlx5dr_action *action; /* HWS action */ 1153 struct mlx5_devx_obj *devx_obj; /* DEVX object. */ 1154 struct mlx5_aso_mtr *aso; /* Array of ASO objects. */ 1155 }; 1156 1157 /* Meter management structure for global flow meter resource. */ 1158 struct mlx5_flow_mtr_mng { 1159 struct mlx5_aso_mtr_pools_mng pools_mng; 1160 /* Pools management structure for ASO flow meter pools. */ 1161 struct mlx5_flow_meter_def_policy *def_policy[MLX5_MTR_DOMAIN_MAX]; 1162 /* Default policy table. */ 1163 uint32_t def_policy_id; 1164 /* Default policy id. */ 1165 RTE_ATOMIC(uint32_t) def_policy_ref_cnt; 1166 /** def_policy meter use count. */ 1167 struct mlx5_flow_tbl_resource *drop_tbl[MLX5_MTR_DOMAIN_MAX]; 1168 /* Meter drop table. */ 1169 struct mlx5_flow_dv_matcher * 1170 drop_matcher[MLX5_MTR_DOMAIN_MAX][MLX5_REG_BITS]; 1171 /* Matcher meter in drop table. */ 1172 struct mlx5_flow_dv_matcher *def_matcher[MLX5_MTR_DOMAIN_MAX]; 1173 /* Default matcher in drop table. */ 1174 void *def_rule[MLX5_MTR_DOMAIN_MAX]; 1175 /* Default rule in drop table. */ 1176 uint8_t max_mtr_bits; 1177 /* Indicate how many bits are used by meter id at the most. */ 1178 uint8_t max_mtr_flow_bits; 1179 /* Indicate how many bits are used by meter flow id at the most. */ 1180 }; 1181 1182 /* Table key of the hash organization. */ 1183 union mlx5_flow_tbl_key { 1184 struct { 1185 /* Table ID should be at the lowest address. */ 1186 uint32_t level; /**< Level of the table. */ 1187 uint32_t id:22; /**< ID of the table. */ 1188 uint32_t dummy:1; /**< Dummy table for DV API. */ 1189 uint32_t is_fdb:1; /**< 1 - FDB, 0 - NIC TX/RX. */ 1190 uint32_t is_egress:1; /**< 1 - egress, 0 - ingress. */ 1191 uint32_t reserved:7; /**< must be zero for comparison. */ 1192 }; 1193 uint64_t v64; /**< full 64bits value of key */ 1194 }; 1195 1196 /* Table structure. */ 1197 struct mlx5_flow_tbl_resource { 1198 void *obj; /**< Pointer to DR table object. */ 1199 }; 1200 1201 #define MLX5_MAX_TABLES UINT16_MAX 1202 #define MLX5_HAIRPIN_TX_TABLE (UINT16_MAX - 1) 1203 /* Reserve the last two tables for metadata register copy. */ 1204 #define MLX5_FLOW_MREG_ACT_TABLE_GROUP (MLX5_MAX_TABLES - 1) 1205 #define MLX5_FLOW_MREG_CP_TABLE_GROUP (MLX5_MAX_TABLES - 2) 1206 /* Tables for metering splits should be added here. */ 1207 #define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 3) 1208 #define MLX5_FLOW_TABLE_LEVEL_POLICY (MLX5_MAX_TABLES - 4) 1209 #define MLX5_MAX_TABLES_EXTERNAL MLX5_FLOW_TABLE_LEVEL_POLICY 1210 #define MLX5_FLOW_TABLE_HWS_POLICY (MLX5_MAX_TABLES - 10) 1211 #define MLX5_MAX_TABLES_FDB UINT16_MAX 1212 #define MLX5_FLOW_TABLE_PTYPE_RSS_NUM 1024 1213 #define MLX5_FLOW_TABLE_PTYPE_RSS_LAST (MLX5_MAX_TABLES - 11) 1214 #define MLX5_FLOW_TABLE_PTYPE_RSS_BASE \ 1215 (1 + MLX5_FLOW_TABLE_PTYPE_RSS_LAST - MLX5_FLOW_TABLE_PTYPE_RSS_NUM) 1216 #define MLX5_FLOW_TABLE_FACTOR 10 1217 1218 /* ID generation structure. */ 1219 struct mlx5_flow_id_pool { 1220 uint32_t *free_arr; /**< Pointer to the a array of free values. */ 1221 uint32_t base_index; 1222 /**< The next index that can be used without any free elements. */ 1223 uint32_t *curr; /**< Pointer to the index to pop. */ 1224 uint32_t *last; /**< Pointer to the last element in the empty array. */ 1225 uint32_t max_id; /**< Maximum id can be allocated from the pool. */ 1226 }; 1227 1228 /* Tx pacing queue structure - for Clock and Rearm queues. */ 1229 struct mlx5_txpp_wq { 1230 /* Completion Queue related data.*/ 1231 struct mlx5_devx_cq cq_obj; 1232 uint32_t cq_ci:24; 1233 uint32_t arm_sn:2; 1234 /* Send Queue related data.*/ 1235 struct mlx5_devx_sq sq_obj; 1236 uint16_t sq_size; /* Number of WQEs in the queue. */ 1237 uint16_t sq_ci; /* Next WQE to execute. */ 1238 }; 1239 1240 /* Tx packet pacing internal timestamp. */ 1241 struct mlx5_txpp_ts { 1242 RTE_ATOMIC(uint64_t) ci_ts; 1243 RTE_ATOMIC(uint64_t) ts; 1244 }; 1245 1246 /* Tx packet pacing structure. */ 1247 struct mlx5_dev_txpp { 1248 pthread_mutex_t mutex; /* Pacing create/destroy mutex. */ 1249 uint32_t refcnt; /* Pacing reference counter. */ 1250 uint32_t freq; /* Timestamp frequency, Hz. */ 1251 uint32_t tick; /* Completion tick duration in nanoseconds. */ 1252 uint32_t test; /* Packet pacing test mode. */ 1253 int32_t skew; /* Scheduling skew. */ 1254 struct rte_intr_handle *intr_handle; /* Periodic interrupt. */ 1255 void *echan; /* Event Channel. */ 1256 struct mlx5_txpp_wq clock_queue; /* Clock Queue. */ 1257 struct mlx5_txpp_wq rearm_queue; /* Clock Queue. */ 1258 void *pp; /* Packet pacing context. */ 1259 uint16_t pp_id; /* Packet pacing context index. */ 1260 uint16_t ts_n; /* Number of captured timestamps. */ 1261 uint16_t ts_p; /* Pointer to statistics timestamp. */ 1262 struct mlx5_txpp_ts *tsa; /* Timestamps sliding window stats. */ 1263 struct mlx5_txpp_ts ts; /* Cached completion id/timestamp. */ 1264 uint32_t sync_lost:1; /* ci/timestamp synchronization lost. */ 1265 /* Statistics counters. */ 1266 RTE_ATOMIC(uint64_t) err_miss_int; /* Missed service interrupt. */ 1267 RTE_ATOMIC(uint64_t) err_rearm_queue; /* Rearm Queue errors. */ 1268 RTE_ATOMIC(uint64_t) err_clock_queue; /* Clock Queue errors. */ 1269 RTE_ATOMIC(uint64_t) err_ts_past; /* Timestamp in the past. */ 1270 RTE_ATOMIC(uint64_t) err_ts_future; /* Timestamp in the distant future. */ 1271 RTE_ATOMIC(uint64_t) err_ts_order; /* Timestamp not in ascending order. */ 1272 }; 1273 1274 /* Sample ID information of eCPRI flex parser structure. */ 1275 struct mlx5_ecpri_parser_profile { 1276 uint32_t num; /* Actual number of samples. */ 1277 uint32_t ids[8]; /* Sample IDs for this profile. */ 1278 uint8_t offset[8]; /* Bytes offset of each parser. */ 1279 void *obj; /* Flex parser node object. */ 1280 }; 1281 1282 /* Max member ports per bonding device. */ 1283 #define MLX5_BOND_MAX_PORTS 2 1284 1285 /* Bonding device information. */ 1286 struct mlx5_bond_info { 1287 int n_port; /* Number of bond member ports. */ 1288 uint32_t ifindex; 1289 char ifname[MLX5_NAMESIZE + 1]; 1290 struct { 1291 char ifname[MLX5_NAMESIZE + 1]; 1292 uint32_t ifindex; 1293 struct rte_pci_addr pci_addr; 1294 } ports[MLX5_BOND_MAX_PORTS]; 1295 }; 1296 1297 /* Number of connection tracking objects per pool: must be a power of 2. */ 1298 #define MLX5_ASO_CT_ACTIONS_PER_POOL 64 1299 1300 /* Generate incremental and unique CT index from pool and offset. */ 1301 #define MLX5_MAKE_CT_IDX(pool, offset) \ 1302 ((pool) * MLX5_ASO_CT_ACTIONS_PER_POOL + (offset) + 1) 1303 1304 /* ASO Conntrack state. */ 1305 enum mlx5_aso_ct_state { 1306 ASO_CONNTRACK_FREE, /* Inactive, in the free list. */ 1307 ASO_CONNTRACK_WAIT, /* WQE sent in the SQ. */ 1308 ASO_CONNTRACK_WAIT_ASYNC, /* CQE will be handled by async pull. */ 1309 ASO_CONNTRACK_READY, /* CQE received w/o error. */ 1310 ASO_CONNTRACK_QUERY, /* WQE for query sent. */ 1311 ASO_CONNTRACK_MAX, /* Guard. */ 1312 }; 1313 1314 /* Generic ASO connection tracking structure. */ 1315 struct mlx5_aso_ct_action { 1316 union { 1317 /* SWS mode struct. */ 1318 struct { 1319 /* Pointer to the next ASO CT. Used only in SWS. */ 1320 LIST_ENTRY(mlx5_aso_ct_action) next; 1321 }; 1322 /* HWS mode struct. */ 1323 struct { 1324 /* Pointer to action pool. Used only in HWS. */ 1325 struct mlx5_aso_ct_pool *pool; 1326 }; 1327 }; 1328 /* General action object for original dir. */ 1329 void *dr_action_orig; 1330 /* General action object for reply dir. */ 1331 void *dr_action_rply; 1332 RTE_ATOMIC(uint32_t) refcnt; /* Action used count in device flows. */ 1333 uint32_t offset; /* Offset of ASO CT in DevX objects bulk. */ 1334 uint16_t peer; /* The only peer port index could also use this CT. */ 1335 RTE_ATOMIC(enum mlx5_aso_ct_state) state; /* ASO CT state. */ 1336 bool is_original; /* The direction of the DR action to be used. */ 1337 }; 1338 1339 /* CT action object state update. */ 1340 #define MLX5_ASO_CT_UPDATE_STATE(c, s) \ 1341 rte_atomic_store_explicit(&((c)->state), (s), rte_memory_order_relaxed) 1342 1343 #ifdef PEDANTIC 1344 #pragma GCC diagnostic ignored "-Wpedantic" 1345 #endif 1346 1347 /* ASO connection tracking software pool definition. */ 1348 struct mlx5_aso_ct_pool { 1349 uint16_t index; /* Pool index in pools array. */ 1350 /* Free ASO CT index in the pool. Used by HWS. */ 1351 struct mlx5_indexed_pool *cts; 1352 struct mlx5_devx_obj *devx_obj; 1353 union { 1354 void *dummy_action; 1355 /* Dummy action to increase the reference count in the driver. */ 1356 struct mlx5dr_action *dr_action; 1357 /* HWS action. */ 1358 }; 1359 struct mlx5_aso_sq *sq; /* Async ASO SQ. */ 1360 struct mlx5_aso_sq *shared_sq; /* Shared ASO SQ. */ 1361 struct mlx5_aso_ct_action actions[]; 1362 /* CT action structures bulk. */ 1363 }; 1364 1365 LIST_HEAD(aso_ct_list, mlx5_aso_ct_action); 1366 1367 #define MLX5_ASO_CT_SQ_NUM 16 1368 1369 /* Pools management structure for ASO connection tracking pools. */ 1370 struct mlx5_aso_ct_pools_mng { 1371 struct mlx5_aso_ct_pool **pools; 1372 uint16_t n; /* Total number of pools. */ 1373 uint16_t next; /* Number of pools in use, index of next free pool. */ 1374 uint32_t nb_sq; /* Number of ASO SQ. */ 1375 rte_spinlock_t ct_sl; /* The ASO CT free list lock. */ 1376 rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */ 1377 struct aso_ct_list free_cts; /* Free ASO CT objects list. */ 1378 struct mlx5_aso_sq aso_sqs[]; /* ASO queue objects. */ 1379 }; 1380 1381 #ifdef PEDANTIC 1382 #pragma GCC diagnostic error "-Wpedantic" 1383 #endif 1384 1385 /* LAG attr. */ 1386 struct mlx5_lag { 1387 uint8_t tx_remap_affinity[16]; /* The PF port number of affinity */ 1388 uint8_t affinity_mode; /* TIS or hash based affinity */ 1389 }; 1390 1391 /* DevX flex parser context. */ 1392 struct mlx5_flex_parser_devx { 1393 struct mlx5_list_entry entry; /* List element at the beginning. */ 1394 uint32_t num_samples; 1395 uint8_t anchor_id; 1396 void *devx_obj; 1397 struct mlx5_devx_graph_node_attr devx_conf; 1398 uint32_t sample_ids[MLX5_GRAPH_NODE_SAMPLE_NUM]; 1399 struct mlx5_devx_match_sample_info_query_attr sample_info[MLX5_GRAPH_NODE_SAMPLE_NUM]; 1400 }; 1401 1402 /* Pattern field descriptor - how to translate flex pattern into samples. */ 1403 __extension__ 1404 struct mlx5_flex_pattern_field { 1405 uint16_t width:6; 1406 uint16_t shift:5; 1407 uint16_t reg_id:5; 1408 }; 1409 1410 #define MLX5_INVALID_SAMPLE_REG_ID 0x1F 1411 1412 /* Port flex item context. */ 1413 struct mlx5_flex_item { 1414 struct mlx5_flex_parser_devx *devx_fp; /* DevX flex parser object. */ 1415 RTE_ATOMIC(uint32_t) refcnt; /* Atomically accessed refcnt by flows. */ 1416 enum rte_flow_item_flex_tunnel_mode tunnel_mode; /* Tunnel mode. */ 1417 uint32_t mapnum; /* Number of pattern translation entries. */ 1418 struct mlx5_flex_pattern_field map[MLX5_FLEX_ITEM_MAPPING_NUM]; 1419 }; 1420 1421 /* 1422 * Sample an IPv6 address and the first dword of SRv6 header. 1423 * Then it is 16 + 4 = 20 bytes which is 5 dwords. 1424 */ 1425 #define MLX5_SRV6_SAMPLE_NUM 5 1426 /* Mlx5 internal flex parser profile structure. */ 1427 struct mlx5_internal_flex_parser_profile { 1428 RTE_ATOMIC(uint32_t) refcnt; 1429 struct mlx5_flex_item flex; /* Hold map info for modify field. */ 1430 }; 1431 1432 struct mlx5_send_to_kernel_action { 1433 void *action; 1434 void *tbl; 1435 }; 1436 1437 #define HWS_CNT_ASO_SQ_NUM 4 1438 1439 struct mlx5_hws_aso_mng { 1440 uint16_t sq_num; 1441 struct mlx5_aso_sq sqs[HWS_CNT_ASO_SQ_NUM]; 1442 }; 1443 1444 struct mlx5_hws_cnt_svc_mng { 1445 uint32_t refcnt; 1446 uint32_t service_core; 1447 uint32_t query_interval; 1448 rte_thread_t service_thread; 1449 uint8_t svc_running; 1450 alignas(RTE_CACHE_LINE_SIZE) struct mlx5_hws_aso_mng aso_mng; 1451 }; 1452 1453 #define MLX5_FLOW_HW_TAGS_MAX 12 1454 #define MLX5_FLOW_NAT64_REGS_MAX 3 1455 1456 struct mlx5_dev_registers { 1457 enum modify_reg aso_reg; 1458 enum modify_reg hw_avl_tags[MLX5_FLOW_HW_TAGS_MAX]; 1459 enum modify_reg nat64_regs[MLX5_FLOW_NAT64_REGS_MAX]; 1460 }; 1461 1462 #if defined(HAVE_MLX5DV_DR) && \ 1463 (defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER) || \ 1464 defined(HAVE_MLX5_DR_CREATE_ACTION_ASO)) 1465 #define HAVE_MLX5_DR_CREATE_ACTION_ASO_EXT 1466 #endif 1467 1468 struct mlx5_geneve_tlv_options; 1469 1470 enum mlx5_ipv6_tc_support { 1471 MLX5_IPV6_TC_UNKNOWN = 0, 1472 MLX5_IPV6_TC_FALLBACK, 1473 MLX5_IPV6_TC_OK, 1474 }; 1475 1476 struct mlx5_common_nic_config { 1477 enum mlx5_ipv6_tc_support ipv6_tc_fallback; 1478 /* Whether ipv6 traffic class should use old value. */ 1479 }; 1480 1481 /** 1482 * Physical device structure. 1483 * This device is created once per NIC to manage recourses shared by all ports 1484 * under same physical device. 1485 */ 1486 struct mlx5_physical_device { 1487 LIST_ENTRY(mlx5_physical_device) next; 1488 struct mlx5_dev_ctx_shared *sh; /* Created on sherd context. */ 1489 uint64_t guid; /* System image guid, the uniq ID of physical device. */ 1490 struct mlx5_geneve_tlv_options *tlv_options; 1491 struct mlx5_common_nic_config config; 1492 uint32_t refcnt; 1493 }; 1494 1495 /* 1496 * Shared Infiniband device context for Master/Representors 1497 * which belong to same IB device with multiple IB ports. 1498 **/ 1499 struct mlx5_dev_ctx_shared { 1500 LIST_ENTRY(mlx5_dev_ctx_shared) next; 1501 uint32_t refcnt; 1502 uint32_t esw_mode:1; /* Whether is E-Switch mode. */ 1503 uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */ 1504 uint32_t steering_format_version:4; 1505 /* Indicates the device steering logic format. */ 1506 uint32_t meter_aso_en:1; /* Flow Meter ASO is supported. */ 1507 uint32_t ct_aso_en:1; /* Connection Tracking ASO is supported. */ 1508 uint32_t tunnel_header_0_1:1; /* tunnel_header_0_1 is supported. */ 1509 uint32_t tunnel_header_2_3:1; /* tunnel_header_2_3 is supported. */ 1510 uint32_t misc5_cap:1; /* misc5 matcher parameter is supported. */ 1511 uint32_t dr_root_drop_action_en:1; /* DR drop action is usable on root tables. */ 1512 uint32_t drop_action_check_flag:1; /* Check Flag for drop action. */ 1513 uint32_t flow_priority_check_flag:1; /* Check Flag for flow priority. */ 1514 uint32_t metadata_regc_check_flag:1; /* Check Flag for metadata REGC. */ 1515 uint32_t shared_mark_enabled:1; 1516 /* If mark action is enabled on Rxqs (shared E-Switch domain). */ 1517 uint32_t lag_rx_port_affinity_en:1; 1518 /* lag_rx_port_affinity is supported. */ 1519 uint32_t hws_max_log_bulk_sz:5; 1520 /* Log of minimal HWS counters created hard coded. */ 1521 uint32_t hws_max_nb_counters; /* Maximal number for HWS counters. */ 1522 uint32_t max_port; /* Maximal IB device port index. */ 1523 struct mlx5_bond_info bond; /* Bonding information. */ 1524 struct mlx5_common_device *cdev; /* Backend mlx5 device. */ 1525 struct mlx5_physical_device *phdev; /* Backend physical device. */ 1526 uint32_t tdn; /* Transport Domain number. */ 1527 char ibdev_name[MLX5_FS_NAME_MAX]; /* SYSFS dev name. */ 1528 char ibdev_path[MLX5_FS_PATH_MAX]; /* SYSFS dev path for secondary */ 1529 struct mlx5_dev_cap dev_cap; /* Device capabilities. */ 1530 struct mlx5_sh_config config; /* Device configuration. */ 1531 int numa_node; /* Numa node of backing physical device. */ 1532 /* Packet pacing related structure. */ 1533 struct mlx5_dev_txpp txpp; 1534 /* Shared DV/DR flow data section. */ 1535 uint32_t dv_meta_mask; /* flow META metadata supported mask. */ 1536 uint32_t dv_mark_mask; /* flow MARK metadata supported mask. */ 1537 uint32_t dv_regc0_mask; /* available bits of metadata reg_c[0]. */ 1538 void *fdb_domain; /* FDB Direct Rules name space handle. */ 1539 void *rx_domain; /* RX Direct Rules name space handle. */ 1540 void *tx_domain; /* TX Direct Rules name space handle. */ 1541 #ifndef RTE_ARCH_64 1542 rte_spinlock_t uar_lock_cq; /* CQs share a common distinct UAR. */ 1543 rte_spinlock_t uar_lock[MLX5_UAR_PAGE_NUM_MAX]; 1544 /* UAR same-page access control required in 32bit implementations. */ 1545 #endif 1546 union { 1547 struct mlx5_hlist *flow_tbls; /* SWS flow table. */ 1548 struct mlx5_hlist *groups; /* HWS flow group. */ 1549 }; 1550 struct mlx5_hlist *mreg_cp_tbl; 1551 /* Hash table of Rx metadata register copy table. */ 1552 struct mlx5_flow_tunnel_hub *tunnel_hub; 1553 /* Direct Rules tables for FDB, NIC TX+RX */ 1554 void *dr_drop_action; /* Pointer to DR drop action, any domain. */ 1555 void *pop_vlan_action; /* Pointer to DR pop VLAN action. */ 1556 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 1557 struct mlx5_send_to_kernel_action send_to_kernel_action[MLX5DR_TABLE_TYPE_MAX]; 1558 #endif 1559 RTE_ATOMIC(struct mlx5_hlist *) encaps_decaps; /* Encap/decap action hash list. */ 1560 RTE_ATOMIC(struct mlx5_hlist *) modify_cmds; 1561 RTE_ATOMIC(struct mlx5_hlist *) tag_table; 1562 struct mlx5_list *port_id_action_list; /* Port ID action list. */ 1563 struct mlx5_list *push_vlan_action_list; /* Push VLAN actions. */ 1564 struct mlx5_list *sample_action_list; /* List of sample actions. */ 1565 struct mlx5_list *dest_array_list; 1566 struct mlx5_list *flex_parsers_dv; /* Flex Item parsers. */ 1567 /* List of destination array actions. */ 1568 struct mlx5_flow_counter_mng sws_cmng; 1569 /* SW steering counters management structure. */ 1570 void *default_miss_action; /* Default miss action. */ 1571 struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX]; 1572 RTE_ATOMIC(struct mlx5_indexed_pool *) mdh_ipools[MLX5_MAX_MODIFY_NUM]; 1573 /* Shared interrupt handler section. */ 1574 struct rte_intr_handle *intr_handle; /* Interrupt handler for device. */ 1575 struct rte_intr_handle *intr_handle_devx; /* DEVX interrupt handler. */ 1576 struct rte_intr_handle *intr_handle_nl; /* Netlink interrupt handler. */ 1577 void *devx_comp; /* DEVX async comp obj. */ 1578 struct mlx5_devx_obj *tis[16]; /* TIS object. */ 1579 struct mlx5_devx_obj *td; /* Transport domain. */ 1580 struct mlx5_lag lag; /* LAG attributes */ 1581 struct mlx5_uar tx_uar; /* DevX UAR for Tx and Txpp and ASO SQs. */ 1582 struct mlx5_uar rx_uar; /* DevX UAR for Rx. */ 1583 struct mlx5_proc_priv *pppriv; /* Pointer to primary private process. */ 1584 struct mlx5_ecpri_parser_profile ecpri_parser; 1585 struct mlx5_internal_flex_parser_profile srh_flex_parser; /* srh flex parser structure. */ 1586 /* Flex parser profiles information. */ 1587 LIST_HEAD(shared_rxqs, mlx5_rxq_ctrl) shared_rxqs; /* Shared RXQs. */ 1588 struct mlx5_aso_age_mng *aso_age_mng; 1589 /* Management data for aging mechanism using ASO Flow Hit. */ 1590 struct mlx5_geneve_tlv_option_resource *geneve_tlv_option_resource; 1591 /* Management structure for geneve tlv option */ 1592 rte_spinlock_t geneve_tlv_opt_sl; /* Lock for geneve tlv resource */ 1593 struct mlx5_flow_mtr_mng *mtrmng; 1594 /* Meter management structure. */ 1595 struct mlx5_aso_ct_pools_mng *ct_mng; /* Management data for ASO CT in HWS only. */ 1596 struct mlx5_lb_ctx self_lb; /* QP to enable self loopback for Devx. */ 1597 unsigned int flow_max_priority; 1598 enum modify_reg flow_mreg_c[MLX5_MREG_C_NUM]; 1599 /* Availability of mreg_c's. */ 1600 void *devx_channel_lwm; 1601 struct rte_intr_handle *intr_handle_lwm; 1602 pthread_mutex_t lwm_config_lock; 1603 uint32_t host_shaper_rate:8; 1604 uint32_t lwm_triggered:1; 1605 struct mlx5_hws_cnt_svc_mng *cnt_svc; 1606 rte_spinlock_t cpool_lock; 1607 LIST_HEAD(hws_cpool_list, mlx5_hws_cnt_pool) hws_cpool_list; /* Count pool list. */ 1608 struct mlx5_dev_registers registers; 1609 struct mlx5_dev_shared_port port[]; /* per device port data array. */ 1610 }; 1611 1612 /* 1613 * Per-process private structure. 1614 * Caution, secondary process may rebuild the struct during port start. 1615 */ 1616 struct mlx5_proc_priv { 1617 RTE_ATOMIC(void *) hca_bar; 1618 /* Mapped HCA PCI BAR area. */ 1619 size_t uar_table_sz; 1620 /* Size of UAR register table. */ 1621 struct mlx5_uar_data uar_table[]; 1622 /* Table of UAR registers for each process. */ 1623 }; 1624 1625 /* MTR profile list. */ 1626 TAILQ_HEAD(mlx5_mtr_profiles, mlx5_flow_meter_profile); 1627 /* MTR list. */ 1628 TAILQ_HEAD(mlx5_legacy_flow_meters, mlx5_legacy_flow_meter); 1629 1630 struct mlx5_mtr_config { 1631 uint32_t nb_meters; /**< Number of configured meters */ 1632 uint32_t nb_meter_profiles; /**< Number of configured meter profiles */ 1633 uint32_t nb_meter_policies; /**< Number of configured meter policies */ 1634 }; 1635 1636 /* RSS description. */ 1637 struct mlx5_flow_rss_desc { 1638 bool symmetric_hash_function; /**< Symmetric hash function */ 1639 uint32_t level; 1640 uint32_t queue_num; /**< Number of entries in @p queue. */ 1641 uint64_t types; /**< Specific RSS hash types (see RTE_ETH_RSS_*). */ 1642 uint64_t hash_fields; /* Verbs Hash fields. */ 1643 uint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */ 1644 uint32_t key_len; /**< RSS hash key len. */ 1645 uint32_t hws_flags; /**< HW steering action. */ 1646 uint32_t tunnel; /**< Queue in tunnel. */ 1647 uint32_t shared_rss; /**< Shared RSS index. */ 1648 struct mlx5_ind_table_obj *ind_tbl; 1649 /**< Indirection table for shared RSS hash RX queues. */ 1650 union { 1651 uint16_t *queue; /**< Destination queues. */ 1652 const uint16_t *const_q; /**< Const pointer convert. */ 1653 }; 1654 }; 1655 1656 #define MLX5_PROC_PRIV(port_id) \ 1657 ((struct mlx5_proc_priv *)rte_eth_devices[port_id].process_private) 1658 1659 /* Verbs/DevX Rx queue elements. */ 1660 struct mlx5_rxq_obj { 1661 LIST_ENTRY(mlx5_rxq_obj) next; /* Pointer to the next element. */ 1662 struct mlx5_rxq_ctrl *rxq_ctrl; /* Back pointer to parent. */ 1663 int fd; /* File descriptor for event channel */ 1664 union { 1665 struct { 1666 void *wq; /* Work Queue. */ 1667 void *ibv_cq; /* Completion Queue. */ 1668 void *ibv_channel; 1669 }; 1670 struct mlx5_devx_obj *rq; /* DevX RQ object for hairpin. */ 1671 struct { 1672 struct mlx5_devx_rmp devx_rmp; /* RMP for shared RQ. */ 1673 struct mlx5_devx_cq cq_obj; /* DevX CQ object. */ 1674 void *devx_channel; 1675 }; 1676 }; 1677 }; 1678 1679 /* Indirection table. */ 1680 struct mlx5_ind_table_obj { 1681 LIST_ENTRY(mlx5_ind_table_obj) next; /* Pointer to the next element. */ 1682 RTE_ATOMIC(uint32_t) refcnt; /* Reference counter. */ 1683 union { 1684 void *ind_table; /**< Indirection table. */ 1685 struct mlx5_devx_obj *rqt; /* DevX RQT object. */ 1686 }; 1687 uint32_t queues_n; /**< Number of queues in the list. */ 1688 uint16_t *queues; /**< Queue list. */ 1689 }; 1690 1691 /* Hash Rx queue. */ 1692 __extension__ 1693 struct mlx5_hrxq { 1694 struct mlx5_list_entry entry; /* List entry. */ 1695 uint32_t standalone:1; /* This object used in shared action. */ 1696 struct mlx5_ind_table_obj *ind_table; /* Indirection table. */ 1697 union { 1698 void *qp; /* Verbs queue pair. */ 1699 struct mlx5_devx_obj *tir; /* DevX TIR object. */ 1700 }; 1701 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 1702 void *action; /* DV QP action pointer. */ 1703 #endif 1704 bool symmetric_hash_function; /* Symmetric hash function */ 1705 uint32_t hws_flags; /* Hw steering flags. */ 1706 uint64_t hash_fields; /* Verbs Hash fields. */ 1707 uint32_t rss_key_len; /* Hash key length in bytes. */ 1708 uint32_t idx; /* Hash Rx queue index. */ 1709 uint8_t rss_key[]; /* Hash key. */ 1710 }; 1711 1712 /* Verbs/DevX Tx queue elements. */ 1713 struct mlx5_txq_obj { 1714 LIST_ENTRY(mlx5_txq_obj) next; /* Pointer to the next element. */ 1715 struct mlx5_txq_ctrl *txq_ctrl; /* Pointer to the control queue. */ 1716 union { 1717 struct { 1718 void *cq; /* Completion Queue. */ 1719 void *qp; /* Queue Pair. */ 1720 }; 1721 struct { 1722 struct mlx5_devx_obj *sq; 1723 /* DevX object for Sx queue. */ 1724 struct mlx5_devx_obj *tis; /* The TIS object. */ 1725 void *umem_buf_wq_buffer; 1726 void *umem_obj_wq_buffer; 1727 }; 1728 struct { 1729 struct rte_eth_dev *dev; 1730 struct mlx5_devx_cq cq_obj; 1731 /* DevX CQ object and its resources. */ 1732 struct mlx5_devx_sq sq_obj; 1733 /* DevX SQ object and its resources. */ 1734 }; 1735 }; 1736 }; 1737 1738 enum mlx5_rxq_modify_type { 1739 MLX5_RXQ_MOD_ERR2RST, /* modify state from error to reset. */ 1740 MLX5_RXQ_MOD_RST2RDY, /* modify state from reset to ready. */ 1741 MLX5_RXQ_MOD_RDY2ERR, /* modify state from ready to error. */ 1742 MLX5_RXQ_MOD_RDY2RST, /* modify state from ready to reset. */ 1743 MLX5_RXQ_MOD_RDY2RDY, /* modify state from ready to ready. */ 1744 }; 1745 1746 enum mlx5_txq_modify_type { 1747 MLX5_TXQ_MOD_RST2RDY, /* modify state from reset to ready. */ 1748 MLX5_TXQ_MOD_RDY2RST, /* modify state from ready to reset. */ 1749 MLX5_TXQ_MOD_ERR2RDY, /* modify state from error to ready. */ 1750 }; 1751 1752 struct mlx5_rxq_priv; 1753 struct mlx5_priv; 1754 1755 /* HW objects operations structure. */ 1756 struct mlx5_obj_ops { 1757 int (*rxq_obj_modify_vlan_strip)(struct mlx5_rxq_priv *rxq, int on); 1758 int (*rxq_obj_new)(struct mlx5_rxq_priv *rxq); 1759 int (*rxq_event_get)(struct mlx5_rxq_obj *rxq_obj); 1760 int (*rxq_obj_modify)(struct mlx5_rxq_priv *rxq, uint8_t type); 1761 void (*rxq_obj_release)(struct mlx5_rxq_priv *rxq); 1762 int (*rxq_event_get_lwm)(struct mlx5_priv *priv, int *rxq_idx, int *port_id); 1763 int (*ind_table_new)(struct rte_eth_dev *dev, const unsigned int log_n, 1764 struct mlx5_ind_table_obj *ind_tbl); 1765 int (*ind_table_modify)(struct rte_eth_dev *dev, 1766 const unsigned int log_n, 1767 const uint16_t *queues, const uint32_t queues_n, 1768 struct mlx5_ind_table_obj *ind_tbl); 1769 void (*ind_table_destroy)(struct mlx5_ind_table_obj *ind_tbl); 1770 int (*hrxq_new)(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq, 1771 int tunnel __rte_unused); 1772 int (*hrxq_modify)(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq, 1773 const uint8_t *rss_key, 1774 uint64_t hash_fields, 1775 bool symmetric_hash_function, 1776 const struct mlx5_ind_table_obj *ind_tbl); 1777 void (*hrxq_destroy)(struct mlx5_hrxq *hrxq); 1778 int (*drop_action_create)(struct rte_eth_dev *dev); 1779 void (*drop_action_destroy)(struct rte_eth_dev *dev); 1780 int (*txq_obj_new)(struct rte_eth_dev *dev, uint16_t idx); 1781 int (*txq_obj_modify)(struct mlx5_txq_obj *obj, 1782 enum mlx5_txq_modify_type type, uint8_t dev_port); 1783 void (*txq_obj_release)(struct mlx5_txq_obj *txq_obj); 1784 int (*lb_dummy_queue_create)(struct rte_eth_dev *dev); 1785 void (*lb_dummy_queue_release)(struct rte_eth_dev *dev); 1786 }; 1787 1788 #define MLX5_RSS_HASH_FIELDS_LEN RTE_DIM(mlx5_rss_hash_fields) 1789 1790 enum mlx5_hw_ctrl_flow_type { 1791 MLX5_HW_CTRL_FLOW_TYPE_GENERAL, 1792 MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS_ROOT, 1793 MLX5_HW_CTRL_FLOW_TYPE_SQ_MISS, 1794 MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_JUMP, 1795 MLX5_HW_CTRL_FLOW_TYPE_TX_META_COPY, 1796 MLX5_HW_CTRL_FLOW_TYPE_TX_REPR_MATCH, 1797 MLX5_HW_CTRL_FLOW_TYPE_LACP_RX, 1798 MLX5_HW_CTRL_FLOW_TYPE_DEFAULT_RX_RSS, 1799 }; 1800 1801 /** Additional info about control flow rule. */ 1802 struct mlx5_hw_ctrl_flow_info { 1803 /** Determines the kind of control flow rule. */ 1804 enum mlx5_hw_ctrl_flow_type type; 1805 union { 1806 /** 1807 * If control flow is a SQ miss flow (root or not), 1808 * then fields contains matching SQ number. 1809 */ 1810 uint32_t esw_mgr_sq; 1811 /** 1812 * If control flow is a Tx representor matching, 1813 * then fields contains matching SQ number. 1814 */ 1815 uint32_t tx_repr_sq; 1816 }; 1817 }; 1818 1819 /** Entry for tracking control flow rules in HWS. */ 1820 struct mlx5_hw_ctrl_flow { 1821 LIST_ENTRY(mlx5_hw_ctrl_flow) next; 1822 /** 1823 * Owner device is a port on behalf of which flow rule was created. 1824 * 1825 * It's different from the port which really created the flow rule 1826 * if and only if flow rule is created on transfer proxy port 1827 * on behalf of representor port. 1828 */ 1829 struct rte_eth_dev *owner_dev; 1830 /** Pointer to flow rule handle. */ 1831 struct rte_flow *flow; 1832 /** Additional information about the control flow rule. */ 1833 struct mlx5_hw_ctrl_flow_info info; 1834 }; 1835 1836 /* HW Steering port configuration passed to rte_flow_configure(). */ 1837 struct mlx5_flow_hw_attr { 1838 struct rte_flow_port_attr port_attr; 1839 uint16_t nb_queue; 1840 struct rte_flow_queue_attr *queue_attr; 1841 bool nt_mode; 1842 }; 1843 1844 /* 1845 * Flow rule structure for flow engine mode control, focus on group 0. 1846 * Apply to all supported domains. 1847 */ 1848 struct mlx5_dv_flow_info { 1849 LIST_ENTRY(mlx5_dv_flow_info) next; 1850 uint32_t orig_prio; /* prio set by user */ 1851 uint32_t flow_idx_high_prio; 1852 /* flow index owned by standby mode. priority is lower unless DUP flags. */ 1853 uint32_t flow_idx_low_prio; 1854 struct rte_flow_item *items; 1855 struct rte_flow_action *actions; 1856 struct rte_flow_attr attr; 1857 }; 1858 1859 struct rte_pmd_mlx5_flow_engine_mode_info { 1860 enum rte_pmd_mlx5_flow_engine_mode mode; 1861 uint32_t mode_flag; 1862 /* The list is maintained in insertion order. */ 1863 LIST_HEAD(hot_up_info, mlx5_dv_flow_info) hot_upgrade; 1864 }; 1865 1866 struct mlx5_flow_hw_ctrl_rx; 1867 1868 enum mlx5_quota_state { 1869 MLX5_QUOTA_STATE_FREE, /* quota not in use */ 1870 MLX5_QUOTA_STATE_READY, /* quota is ready */ 1871 MLX5_QUOTA_STATE_WAIT /* quota waits WR completion */ 1872 }; 1873 1874 struct mlx5_quota { 1875 RTE_ATOMIC(uint8_t) state; /* object state */ 1876 uint8_t mode; /* metering mode */ 1877 /** 1878 * Keep track of application update types. 1879 * PMD does not allow 2 consecutive ADD updates. 1880 */ 1881 enum rte_flow_update_quota_op last_update; 1882 }; 1883 1884 /* Bulk management structure for flow quota. */ 1885 struct mlx5_quota_ctx { 1886 struct mlx5dr_action *dr_action; /* HWS action */ 1887 struct mlx5_devx_obj *devx_obj; /* DEVX ranged object. */ 1888 struct mlx5_pmd_mr mr; /* MR for READ from MTR ASO */ 1889 struct mlx5_aso_mtr_dseg **read_buf; /* Buffers for READ */ 1890 struct mlx5_aso_sq *sq; /* SQs for sync/async ACCESS_ASO WRs */ 1891 struct mlx5_indexed_pool *quota_ipool; /* Manage quota objects */ 1892 }; 1893 1894 struct mlx5_priv { 1895 struct rte_eth_dev_data *dev_data; /* Pointer to device data. */ 1896 struct mlx5_dev_ctx_shared *sh; /* Shared device context. */ 1897 uint32_t dev_port; /* Device port number. */ 1898 struct rte_pci_device *pci_dev; /* Backend PCI device. */ 1899 struct rte_ether_addr mac[MLX5_MAX_MAC_ADDRESSES]; /* MAC addresses. */ 1900 BITFIELD_DECLARE(mac_own, uint64_t, MLX5_MAX_MAC_ADDRESSES); 1901 /* Bit-field of MAC addresses owned by the PMD. */ 1902 uint16_t vlan_filter[MLX5_MAX_VLAN_IDS]; /* VLAN filters table. */ 1903 unsigned int vlan_filter_n; /* Number of configured VLAN filters. */ 1904 /* Device properties. */ 1905 uint16_t mtu; /* Configured MTU. */ 1906 unsigned int isolated:1; /* Whether isolated mode is enabled. */ 1907 unsigned int representor:1; /* Device is a port representor. */ 1908 unsigned int master:1; /* Device is a E-Switch master. */ 1909 unsigned int txpp_en:1; /* Tx packet pacing enabled. */ 1910 unsigned int sampler_en:1; /* Whether support sampler. */ 1911 unsigned int mtr_en:1; /* Whether support meter. */ 1912 unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ 1913 unsigned int lb_used:1; /* Loopback queue is referred to. */ 1914 unsigned int rmv_notified:1; /* Notified about removal event */ 1915 uint32_t mark_enabled:1; /* If mark action is enabled on rxqs. */ 1916 uint32_t num_lag_ports:4; /* Number of ports can be bonded. */ 1917 uint32_t tunnel_enabled:1; /* If tunnel offloading is enabled on rxqs. */ 1918 uint16_t domain_id; /* Switch domain identifier. */ 1919 uint16_t vport_id; /* Associated VF vport index (if any). */ 1920 uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */ 1921 uint32_t vport_meta_mask; /* Used for vport index field match mask. */ 1922 uint16_t representor_id; /* UINT16_MAX if not a representor. */ 1923 int32_t pf_bond; /* >=0, representor owner PF index in bonding. */ 1924 int32_t mpesw_owner; /* >=0, representor owner PF index in MPESW. */ 1925 int32_t mpesw_port; /* Related port index of MPESW device. < 0 - no MPESW. */ 1926 bool mpesw_uplink; /* If true, port is an uplink port. */ 1927 unsigned int if_index; /* Associated kernel network device index. */ 1928 /* RX/TX queues. */ 1929 unsigned int rxqs_n; /* RX queues array size. */ 1930 unsigned int txqs_n; /* TX queues array size. */ 1931 struct mlx5_external_q *ext_rxqs; /* External RX queues array. */ 1932 struct mlx5_external_q *ext_txqs; /* External TX queues array. */ 1933 struct mlx5_rxq_priv *(*rxq_privs)[]; /* RX queue non-shared data. */ 1934 struct mlx5_txq_data *(*txqs)[]; /* TX queues. */ 1935 struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */ 1936 struct rte_eth_rss_conf rss_conf; /* RSS configuration. */ 1937 unsigned int (*reta_idx)[]; /* RETA index table. */ 1938 unsigned int reta_idx_n; /* RETA index size. */ 1939 struct mlx5_drop drop_queue; /* Flow drop queues. */ 1940 void *root_drop_action; /* Pointer to root drop action. */ 1941 rte_spinlock_t hw_ctrl_lock; 1942 LIST_HEAD(hw_ctrl_flow, mlx5_hw_ctrl_flow) hw_ctrl_flows; 1943 LIST_HEAD(hw_ext_ctrl_flow, mlx5_hw_ctrl_flow) hw_ext_ctrl_flows; 1944 struct mlx5_flow_hw_ctrl_fdb *hw_ctrl_fdb; 1945 struct rte_flow_pattern_template *hw_tx_repr_tagging_pt; 1946 struct rte_flow_actions_template *hw_tx_repr_tagging_at; 1947 struct rte_flow_template_table *hw_tx_repr_tagging_tbl; 1948 struct mlx5_indexed_pool *flows[MLX5_FLOW_TYPE_MAXI]; 1949 /* RTE Flow rules. */ 1950 uint32_t ctrl_flows; /* Control flow rules. */ 1951 rte_spinlock_t flow_list_lock; 1952 struct mlx5_obj_ops obj_ops; /* HW objects operations. */ 1953 LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */ 1954 LIST_HEAD(rxqobj, mlx5_rxq_obj) rxqsobj; /* Verbs/DevX Rx queues. */ 1955 struct mlx5_list *hrxqs; /* Hash Rx queues. */ 1956 LIST_HEAD(txq, mlx5_txq_ctrl) txqsctrl; /* DPDK Tx queues. */ 1957 LIST_HEAD(txqobj, mlx5_txq_obj) txqsobj; /* Verbs/DevX Tx queues. */ 1958 /* Indirection tables. */ 1959 LIST_HEAD(ind_tables, mlx5_ind_table_obj) ind_tbls; 1960 /* Standalone indirect tables. */ 1961 LIST_HEAD(stdl_ind_tables, mlx5_ind_table_obj) standalone_ind_tbls; 1962 /* Objects created with indirect list action */ 1963 LIST_HEAD(indirect_list, mlx5_indirect_list) indirect_list_head; 1964 /* Pointer to next element. */ 1965 rte_rwlock_t ind_tbls_lock; 1966 uint32_t refcnt; /**< Reference counter. */ 1967 /**< Verbs modify header action object. */ 1968 uint8_t ft_type; /**< Flow table type, Rx or Tx. */ 1969 uint32_t max_lro_msg_size; 1970 uint32_t link_speed_capa; /* Link speed capabilities. */ 1971 struct mlx5_xstats_ctrl xstats_ctrl; /* Extended stats control. */ 1972 struct mlx5_stats_ctrl stats_ctrl; /* Stats control. */ 1973 struct mlx5_port_config config; /* Port configuration. */ 1974 /* Context for Verbs allocator. */ 1975 int nl_socket_rdma; /* Netlink socket (NETLINK_RDMA). */ 1976 int nl_socket_route; /* Netlink socket (NETLINK_ROUTE). */ 1977 struct mlx5_nl_vlan_vmwa_context *vmwa_context; /* VLAN WA context. */ 1978 struct mlx5_mtr_config mtr_config; /* Meter configuration */ 1979 uint8_t mtr_sfx_reg; /* Meter prefix-suffix flow match REG_C. */ 1980 struct mlx5_legacy_flow_meters flow_meters; /* MTR list. */ 1981 struct mlx5_l3t_tbl *mtr_profile_tbl; /* Meter index lookup table. */ 1982 struct mlx5_flow_meter_profile *mtr_profile_arr; /* Profile array. */ 1983 struct mlx5_l3t_tbl *policy_idx_tbl; /* Policy index lookup table. */ 1984 struct mlx5_flow_meter_policy *mtr_policy_arr; /* Policy array. */ 1985 struct mlx5_l3t_tbl *mtr_idx_tbl; /* Meter index lookup table. */ 1986 struct mlx5_mtr_bulk mtr_bulk; /* Meter index mapping for HWS */ 1987 struct mlx5_quota_ctx quota_ctx; /* Quota index mapping for HWS */ 1988 uint8_t skip_default_rss_reta; /* Skip configuration of default reta. */ 1989 uint8_t fdb_def_rule; /* Whether fdb jump to table 1 is configured. */ 1990 struct mlx5_mp_id mp_id; /* ID of a multi-process process */ 1991 LIST_HEAD(fdir, mlx5_fdir_flow) fdir_flows; /* fdir flows. */ 1992 rte_spinlock_t shared_act_sl; /* Shared actions spinlock. */ 1993 uint32_t rss_shared_actions; /* RSS shared actions. */ 1994 /* If true, indicates that we failed to allocate a q counter in the past. */ 1995 bool q_counters_allocation_failure; 1996 struct mlx5_devx_obj *q_counters; /* DevX queue counter object. */ 1997 uint32_t counter_set_id; /* Queue counter ID to set in DevX objects. */ 1998 /* DevX queue counter object for all hairpin queues of the port. */ 1999 struct mlx5_devx_obj *q_counters_hairpin; 2000 uint32_t lag_affinity_idx; /* LAG mode queue 0 affinity starting. */ 2001 rte_spinlock_t flex_item_sl; /* Flex item list spinlock. */ 2002 struct mlx5_flex_item flex_item[MLX5_PORT_FLEX_ITEM_NUM]; 2003 /* Flex items have been created on the port. */ 2004 uint32_t flex_item_map; /* Map of allocated flex item elements. */ 2005 uint32_t nb_queue; /* HW steering queue number. */ 2006 struct mlx5_hws_cnt_pool *hws_cpool; /* HW steering's counter pool. */ 2007 RTE_ATOMIC(uint32_t) hws_mark_refcnt; /* HWS mark action reference counter. */ 2008 struct rte_pmd_mlx5_flow_engine_mode_info mode_info; /* Process set flow engine info. */ 2009 struct mlx5_flow_hw_attr *hw_attr; /* HW Steering port configuration. */ 2010 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 2011 /* Item template list. */ 2012 LIST_HEAD(flow_hw_itt, rte_flow_pattern_template) flow_hw_itt; 2013 /* Action template list. */ 2014 LIST_HEAD(flow_hw_at, rte_flow_actions_template) flow_hw_at; 2015 struct mlx5dr_context *dr_ctx; /**< HW steering DR context. */ 2016 /* Pointer to the GENEVE TLV options. */ 2017 struct mlx5_geneve_tlv_options *tlv_options; 2018 /* HW steering queue polling mechanism job descriptor LIFO. */ 2019 uint32_t hws_strict_queue:1; 2020 /**< Whether all operations strictly happen on the same HWS queue. */ 2021 uint32_t hws_age_req:1; /**< Whether this port has AGE indexed pool. */ 2022 struct mlx5_hw_q *hw_q; 2023 /* HW steering rte flow table list header. */ 2024 LIST_HEAD(flow_hw_tbl, rte_flow_template_table) flow_hw_tbl; 2025 /* HW steering rte flow group list header */ 2026 LIST_HEAD(flow_hw_grp, mlx5_flow_group) flow_hw_grp; 2027 struct mlx5dr_action *hw_push_vlan[MLX5DR_TABLE_TYPE_MAX]; 2028 struct mlx5dr_action *hw_pop_vlan[MLX5DR_TABLE_TYPE_MAX]; 2029 struct mlx5dr_action **hw_vport; 2030 /* HW steering global drop action. */ 2031 struct mlx5dr_action *hw_drop[2]; 2032 /* HW steering global tag action. */ 2033 struct mlx5dr_action *hw_tag[2]; 2034 /* HW steering global default miss action. */ 2035 struct mlx5dr_action *hw_def_miss; 2036 /* HW steering global send to kernel action. */ 2037 struct mlx5dr_action *hw_send_to_kernel[MLX5DR_TABLE_TYPE_MAX]; 2038 /* HW steering create ongoing rte flow table list header. */ 2039 LIST_HEAD(flow_hw_tbl_ongo, rte_flow_template_table) flow_hw_tbl_ongo; 2040 struct mlx5_indexed_pool *acts_ipool; /* Action data indexed pool. */ 2041 struct mlx5_aso_ct_pools_mng *ct_mng; 2042 /* Management data for ASO connection tracking. */ 2043 struct mlx5_aso_ct_pool *hws_ctpool; /* HW steering's CT pool. */ 2044 struct mlx5_aso_mtr_pool *hws_mpool; /* HW steering's Meter pool. */ 2045 struct mlx5_flow_hw_ctrl_rx *hw_ctrl_rx; 2046 /**< HW steering templates used to create control flow rules. */ 2047 2048 struct rte_flow_actions_template *action_template_drop[MLX5DR_TABLE_TYPE_MAX]; 2049 2050 /* 2051 * The NAT64 action can be shared among matchers per domain. 2052 * [0]: RTE_FLOW_NAT64_6TO4, [1]: RTE_FLOW_NAT64_4TO6 2053 * Todo: consider to add *_MAX macro. 2054 */ 2055 struct mlx5dr_action *action_nat64[MLX5DR_TABLE_TYPE_MAX][2]; 2056 struct mlx5_indexed_pool *ptype_rss_groups; 2057 #endif 2058 struct rte_eth_dev *shared_host; /* Host device for HW steering. */ 2059 RTE_ATOMIC(uint16_t) shared_refcnt; /* HW steering host reference counter. */ 2060 }; 2061 2062 static __rte_always_inline bool 2063 mlx5_hws_active(const struct rte_eth_dev *dev) 2064 { 2065 #if defined(HAVE_MLX5_HWS_SUPPORT) 2066 const struct mlx5_priv *priv = dev->data->dev_private; 2067 2068 return priv->sh->config.dv_flow_en == 2; 2069 #else 2070 RTE_SET_USED(dev); 2071 return false; 2072 #endif 2073 } 2074 2075 #define PORT_ID(priv) ((priv)->dev_data->port_id) 2076 #define ETH_DEV(priv) (&rte_eth_devices[PORT_ID(priv)]) 2077 #define CTRL_QUEUE_ID(priv) ((priv)->nb_queue - 1) 2078 2079 struct rte_hairpin_peer_info { 2080 uint32_t qp_id; 2081 uint32_t vhca_id; 2082 uint16_t peer_q; 2083 uint16_t tx_explicit; 2084 uint16_t manual_bind; 2085 }; 2086 2087 #define BUF_SIZE 1024 2088 enum dr_dump_rec_type { 2089 DR_DUMP_REC_TYPE_PMD_PKT_REFORMAT = 4410, 2090 DR_DUMP_REC_TYPE_PMD_MODIFY_HDR = 4420, 2091 DR_DUMP_REC_TYPE_PMD_COUNTER = 4430, 2092 }; 2093 2094 #if defined(HAVE_MLX5_HWS_SUPPORT) 2095 static __rte_always_inline struct mlx5_hw_q_job * 2096 flow_hw_job_get(struct mlx5_priv *priv, uint32_t queue) 2097 { 2098 MLX5_ASSERT(priv->hw_q[queue].job_idx <= priv->hw_q[queue].size); 2099 return priv->hw_q[queue].job_idx ? 2100 priv->hw_q[queue].job[--priv->hw_q[queue].job_idx] : NULL; 2101 } 2102 2103 static __rte_always_inline void 2104 flow_hw_job_put(struct mlx5_priv *priv, struct mlx5_hw_q_job *job, uint32_t queue) 2105 { 2106 MLX5_ASSERT(priv->hw_q[queue].job_idx < priv->hw_q[queue].size); 2107 priv->hw_q[queue].job[priv->hw_q[queue].job_idx++] = job; 2108 } 2109 2110 struct mlx5_hw_q_job * 2111 mlx5_flow_action_job_init(struct mlx5_priv *priv, uint32_t queue, 2112 const struct rte_flow_action_handle *handle, 2113 void *user_data, void *query_data, 2114 enum mlx5_hw_job_type type, 2115 struct rte_flow_error *error); 2116 #endif 2117 2118 /** 2119 * Indicates whether HW objects operations can be created by DevX. 2120 * 2121 * This function is used for both: 2122 * Before creation - deciding whether to create HW objects operations by DevX. 2123 * After creation - indicator if HW objects operations were created by DevX. 2124 * 2125 * @param sh 2126 * Pointer to shared device context. 2127 * 2128 * @return 2129 * True if HW objects were created by DevX, False otherwise. 2130 */ 2131 static inline bool 2132 mlx5_devx_obj_ops_en(struct mlx5_dev_ctx_shared *sh) 2133 { 2134 /* 2135 * When advanced DR API is available and DV flow is supported and 2136 * DevX is supported, HW objects operations are created by DevX. 2137 */ 2138 return (sh->cdev->config.devx && sh->config.dv_flow_en && 2139 sh->dev_cap.dest_tir); 2140 } 2141 2142 /** 2143 * Check if the port is either MPESW physical device or a representor port. 2144 * 2145 * @param priv 2146 * Pointer to port's private data. 2147 * 2148 * @return 2149 * True if the port is a physical device or representor in MPESW setup. 2150 * False otherwise or MPESW was not configured. 2151 */ 2152 static inline bool 2153 mlx5_is_port_on_mpesw_device(struct mlx5_priv *priv) 2154 { 2155 return priv->mpesw_port >= 0; 2156 } 2157 2158 /* mlx5.c */ 2159 2160 int mlx5_getenv_int(const char *); 2161 int mlx5_proc_priv_init(struct rte_eth_dev *dev); 2162 void mlx5_proc_priv_uninit(struct rte_eth_dev *dev); 2163 int mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev, 2164 struct rte_eth_udp_tunnel *udp_tunnel); 2165 uint16_t mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev); 2166 int mlx5_dev_close(struct rte_eth_dev *dev); 2167 int mlx5_net_remove(struct mlx5_common_device *cdev); 2168 bool mlx5_is_hpf(struct rte_eth_dev *dev); 2169 bool mlx5_is_sf_repr(struct rte_eth_dev *dev); 2170 void mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh); 2171 int mlx5_lwm_setup(struct mlx5_priv *priv); 2172 void mlx5_lwm_unset(struct mlx5_dev_ctx_shared *sh); 2173 2174 /* Macro to iterate over all valid ports for mlx5 driver. */ 2175 #define MLX5_ETH_FOREACH_DEV(port_id, dev) \ 2176 for (port_id = mlx5_eth_find_next(0, dev); \ 2177 port_id < RTE_MAX_ETHPORTS; \ 2178 port_id = mlx5_eth_find_next(port_id + 1, dev)) 2179 void mlx5_rt_timestamp_config(struct mlx5_dev_ctx_shared *sh, 2180 struct mlx5_hca_attr *hca_attr); 2181 struct mlx5_dev_ctx_shared * 2182 mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, 2183 struct mlx5_kvargs_ctrl *mkvlist); 2184 void mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh); 2185 int mlx5_dev_ctx_shared_mempool_subscribe(struct rte_eth_dev *dev); 2186 void mlx5_free_table_hash_list(struct mlx5_priv *priv); 2187 int mlx5_alloc_table_hash_list(struct mlx5_priv *priv); 2188 void mlx5_set_min_inline(struct mlx5_priv *priv); 2189 void mlx5_set_metadata_mask(struct rte_eth_dev *dev); 2190 int mlx5_probe_again_args_validate(struct mlx5_common_device *cdev, 2191 struct mlx5_kvargs_ctrl *mkvlist); 2192 int mlx5_port_args_config(struct mlx5_priv *priv, 2193 struct mlx5_kvargs_ctrl *mkvlist, 2194 struct mlx5_port_config *config); 2195 void mlx5_port_args_set_used(const char *name, uint16_t port_id, 2196 struct mlx5_kvargs_ctrl *mkvlist); 2197 bool mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev); 2198 int mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev); 2199 void mlx5_flow_counter_mode_config(struct rte_eth_dev *dev); 2200 int mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh); 2201 int mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh); 2202 int mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh); 2203 struct mlx5_physical_device * 2204 mlx5_get_locked_physical_device(struct mlx5_priv *priv); 2205 void mlx5_unlock_physical_device(void); 2206 2207 /* mlx5_ethdev.c */ 2208 2209 int mlx5_dev_configure(struct rte_eth_dev *dev); 2210 int mlx5_representor_info_get(struct rte_eth_dev *dev, 2211 struct rte_eth_representor_info *info); 2212 #define MLX5_REPRESENTOR_ID(pf, type, repr) \ 2213 (((pf) << 14) + ((type) << 12) + ((repr) & 0xfff)) 2214 #define MLX5_REPRESENTOR_REPR(repr_id) \ 2215 ((repr_id) & 0xfff) 2216 #define MLX5_REPRESENTOR_TYPE(repr_id) \ 2217 (((repr_id) >> 12) & 3) 2218 uint16_t mlx5_representor_id_encode(const struct mlx5_switch_info *info, 2219 enum rte_eth_representor_type hpf_type); 2220 int mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info); 2221 int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size); 2222 const uint32_t *mlx5_dev_supported_ptypes_get(struct rte_eth_dev *dev, 2223 size_t *no_of_elements); 2224 int mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu); 2225 int mlx5_hairpin_cap_get(struct rte_eth_dev *dev, 2226 struct rte_eth_hairpin_cap *cap); 2227 eth_rx_burst_t mlx5_select_rx_function(struct rte_eth_dev *dev); 2228 struct mlx5_priv *mlx5_port_to_eswitch_info(uint16_t port, bool valid); 2229 struct mlx5_priv *mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev); 2230 int mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev); 2231 uint64_t mlx5_get_restore_flags(struct rte_eth_dev *dev, 2232 enum rte_eth_dev_operation op); 2233 2234 /* mlx5_ethdev_os.c */ 2235 2236 int mlx5_get_ifname(const struct rte_eth_dev *dev, 2237 char (*ifname)[MLX5_NAMESIZE]); 2238 unsigned int mlx5_ifindex(const struct rte_eth_dev *dev); 2239 int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]); 2240 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu); 2241 int mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu); 2242 int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock); 2243 int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete); 2244 int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, 2245 struct rte_eth_fc_conf *fc_conf); 2246 int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, 2247 struct rte_eth_fc_conf *fc_conf); 2248 void mlx5_dev_interrupt_handler(void *arg); 2249 void mlx5_dev_interrupt_handler_devx(void *arg); 2250 void mlx5_dev_interrupt_handler_nl(void *arg); 2251 int mlx5_set_link_down(struct rte_eth_dev *dev); 2252 int mlx5_set_link_up(struct rte_eth_dev *dev); 2253 int mlx5_is_removed(struct rte_eth_dev *dev); 2254 int mlx5_sysfs_switch_info(unsigned int ifindex, 2255 struct mlx5_switch_info *info); 2256 void mlx5_translate_port_name(const char *port_name_in, 2257 struct mlx5_switch_info *port_info_out); 2258 int mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex, 2259 char *ifname); 2260 int mlx5_get_module_info(struct rte_eth_dev *dev, 2261 struct rte_eth_dev_module_info *modinfo); 2262 int mlx5_get_module_eeprom(struct rte_eth_dev *dev, 2263 struct rte_dev_eeprom_info *info); 2264 int mlx5_os_read_dev_stat(struct mlx5_priv *priv, 2265 const char *ctr_name, uint64_t *stat); 2266 int mlx5_os_read_dev_counters(struct rte_eth_dev *dev, bool bond_master, uint64_t *stats); 2267 int mlx5_os_get_stats_n(struct rte_eth_dev *dev, bool bond_master, 2268 uint16_t *n_stats, uint16_t *n_stats_sec); 2269 void mlx5_os_stats_init(struct rte_eth_dev *dev); 2270 int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev); 2271 2272 /* mlx5_mac.c */ 2273 2274 void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); 2275 int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 2276 uint32_t index, uint32_t vmdq); 2277 int mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr); 2278 int mlx5_set_mc_addr_list(struct rte_eth_dev *dev, 2279 struct rte_ether_addr *mc_addr_set, 2280 uint32_t nb_mc_addr); 2281 2282 /* mlx5_rss.c */ 2283 2284 int mlx5_rss_hash_update(struct rte_eth_dev *dev, 2285 struct rte_eth_rss_conf *rss_conf); 2286 int mlx5_rss_hash_conf_get(struct rte_eth_dev *dev, 2287 struct rte_eth_rss_conf *rss_conf); 2288 int mlx5_rss_reta_index_resize(struct rte_eth_dev *dev, unsigned int reta_size); 2289 int mlx5_dev_rss_reta_query(struct rte_eth_dev *dev, 2290 struct rte_eth_rss_reta_entry64 *reta_conf, 2291 uint16_t reta_size); 2292 int mlx5_dev_rss_reta_update(struct rte_eth_dev *dev, 2293 struct rte_eth_rss_reta_entry64 *reta_conf, 2294 uint16_t reta_size); 2295 2296 /* mlx5_rxmode.c */ 2297 2298 int mlx5_promiscuous_enable(struct rte_eth_dev *dev); 2299 int mlx5_promiscuous_disable(struct rte_eth_dev *dev); 2300 int mlx5_allmulticast_enable(struct rte_eth_dev *dev); 2301 int mlx5_allmulticast_disable(struct rte_eth_dev *dev); 2302 2303 /* mlx5_stats.c */ 2304 2305 int mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); 2306 int mlx5_stats_reset(struct rte_eth_dev *dev); 2307 int mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, 2308 unsigned int n); 2309 int mlx5_xstats_reset(struct rte_eth_dev *dev); 2310 int mlx5_xstats_get_names(struct rte_eth_dev *dev __rte_unused, 2311 struct rte_eth_xstat_name *xstats_names, 2312 unsigned int n); 2313 2314 /* mlx5_vlan.c */ 2315 2316 int mlx5_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on); 2317 void mlx5_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on); 2318 int mlx5_vlan_offload_set(struct rte_eth_dev *dev, int mask); 2319 2320 /* mlx5_vlan_os.c */ 2321 2322 void mlx5_vlan_vmwa_exit(void *ctx); 2323 void mlx5_vlan_vmwa_release(struct rte_eth_dev *dev, 2324 struct mlx5_vf_vlan *vf_vlan); 2325 void mlx5_vlan_vmwa_acquire(struct rte_eth_dev *dev, 2326 struct mlx5_vf_vlan *vf_vlan); 2327 void *mlx5_vlan_vmwa_init(struct rte_eth_dev *dev, uint32_t ifindex); 2328 2329 /* mlx5_trigger.c */ 2330 2331 int mlx5_dev_start(struct rte_eth_dev *dev); 2332 int mlx5_dev_stop(struct rte_eth_dev *dev); 2333 int mlx5_traffic_enable(struct rte_eth_dev *dev); 2334 void mlx5_traffic_disable(struct rte_eth_dev *dev); 2335 int mlx5_traffic_restart(struct rte_eth_dev *dev); 2336 int mlx5_hairpin_queue_peer_update(struct rte_eth_dev *dev, uint16_t peer_queue, 2337 struct rte_hairpin_peer_info *current_info, 2338 struct rte_hairpin_peer_info *peer_info, 2339 uint32_t direction); 2340 int mlx5_hairpin_queue_peer_bind(struct rte_eth_dev *dev, uint16_t cur_queue, 2341 struct rte_hairpin_peer_info *peer_info, 2342 uint32_t direction); 2343 int mlx5_hairpin_queue_peer_unbind(struct rte_eth_dev *dev, uint16_t cur_queue, 2344 uint32_t direction); 2345 int mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port); 2346 int mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port); 2347 int mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports, 2348 size_t len, uint32_t direction); 2349 2350 /* mlx5_flow.c */ 2351 2352 int mlx5_flow_discover_mreg_c(struct rte_eth_dev *eth_dev); 2353 bool mlx5_flow_ext_mreg_supported(struct rte_eth_dev *dev); 2354 void mlx5_flow_print(struct rte_flow *flow); 2355 int mlx5_flow_validate(struct rte_eth_dev *dev, 2356 const struct rte_flow_attr *attr, 2357 const struct rte_flow_item items[], 2358 const struct rte_flow_action actions[], 2359 struct rte_flow_error *error); 2360 uintptr_t 2361 mlx5_flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type, 2362 const struct rte_flow_attr *attr, 2363 const struct rte_flow_item items[], 2364 const struct rte_flow_action actions[], 2365 bool external, struct rte_flow_error *error); 2366 void 2367 mlx5_flow_list_destroy(struct rte_eth_dev *dev, enum mlx5_flow_type type, 2368 uintptr_t flow_idx); 2369 struct rte_flow *mlx5_flow_create(struct rte_eth_dev *dev, 2370 const struct rte_flow_attr *attr, 2371 const struct rte_flow_item items[], 2372 const struct rte_flow_action actions[], 2373 struct rte_flow_error *error); 2374 int mlx5_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow, 2375 struct rte_flow_error *error); 2376 void mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type, 2377 bool active); 2378 int mlx5_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error); 2379 int mlx5_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow, 2380 const struct rte_flow_action *action, void *data, 2381 struct rte_flow_error *error); 2382 int mlx5_flow_isolate(struct rte_eth_dev *dev, int enable, 2383 struct rte_flow_error *error); 2384 int mlx5_flow_ops_get(struct rte_eth_dev *dev, const struct rte_flow_ops **ops); 2385 int mlx5_flow_start_default(struct rte_eth_dev *dev); 2386 void mlx5_flow_stop_default(struct rte_eth_dev *dev); 2387 int mlx5_flow_verify(struct rte_eth_dev *dev); 2388 int mlx5_ctrl_flow_source_queue(struct rte_eth_dev *dev, uint32_t sq_num); 2389 int mlx5_ctrl_flow_vlan(struct rte_eth_dev *dev, 2390 struct rte_flow_item_eth *eth_spec, 2391 struct rte_flow_item_eth *eth_mask, 2392 struct rte_flow_item_vlan *vlan_spec, 2393 struct rte_flow_item_vlan *vlan_mask); 2394 int mlx5_ctrl_flow(struct rte_eth_dev *dev, 2395 struct rte_flow_item_eth *eth_spec, 2396 struct rte_flow_item_eth *eth_mask); 2397 int mlx5_flow_lacp_miss(struct rte_eth_dev *dev); 2398 struct rte_flow *mlx5_flow_create_esw_table_zero_flow(struct rte_eth_dev *dev); 2399 uint32_t mlx5_flow_create_devx_sq_miss_flow(struct rte_eth_dev *dev, 2400 uint32_t sq_num); 2401 void mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh, 2402 uint64_t async_id, int status); 2403 void mlx5_set_query_alarm(struct mlx5_dev_ctx_shared *sh); 2404 void mlx5_flow_query_alarm(void *arg); 2405 uint32_t mlx5_counter_alloc(struct rte_eth_dev *dev); 2406 void mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt); 2407 int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt, 2408 bool clear, uint64_t *pkts, uint64_t *bytes, void **action); 2409 int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow, 2410 FILE *file, struct rte_flow_error *error); 2411 int save_dump_file(const unsigned char *data, uint32_t size, 2412 uint32_t type, uint64_t id, void *arg, FILE *file); 2413 int mlx5_flow_query_counter(struct rte_eth_dev *dev, struct rte_flow *flow, 2414 struct rte_flow_query_count *count, struct rte_flow_error *error); 2415 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 2416 int mlx5_flow_dev_dump_ipool(struct rte_eth_dev *dev, struct rte_flow *flow, 2417 FILE *file, struct rte_flow_error *error); 2418 #endif 2419 int mlx5_flow_rx_metadata_negotiate(struct rte_eth_dev *dev, 2420 uint64_t *features); 2421 void mlx5_flow_rxq_dynf_set(struct rte_eth_dev *dev); 2422 int mlx5_flow_get_aged_flows(struct rte_eth_dev *dev, void **contexts, 2423 uint32_t nb_contexts, struct rte_flow_error *error); 2424 int mlx5_validate_action_ct(struct rte_eth_dev *dev, 2425 const struct rte_flow_action_conntrack *conntrack, 2426 struct rte_flow_error *error); 2427 2428 int mlx5_flow_get_q_aged_flows(struct rte_eth_dev *dev, uint32_t queue_id, 2429 void **contexts, uint32_t nb_contexts, 2430 struct rte_flow_error *error); 2431 2432 /* mlx5_mp_os.c */ 2433 2434 int mlx5_mp_os_primary_handle(const struct rte_mp_msg *mp_msg, 2435 const void *peer); 2436 int mlx5_mp_os_secondary_handle(const struct rte_mp_msg *mp_msg, 2437 const void *peer); 2438 void mlx5_mp_os_req_start_rxtx(struct rte_eth_dev *dev); 2439 void mlx5_mp_os_req_stop_rxtx(struct rte_eth_dev *dev); 2440 int mlx5_mp_os_req_queue_control(struct rte_eth_dev *dev, uint16_t queue_id, 2441 enum mlx5_mp_req_type req_type); 2442 2443 /* mlx5_socket.c */ 2444 2445 int mlx5_pmd_socket_init(void); 2446 void mlx5_pmd_socket_uninit(void); 2447 2448 /* mlx5_flow_meter.c */ 2449 2450 int mlx5_flow_meter_init(struct rte_eth_dev *dev, 2451 uint32_t nb_meters, 2452 uint32_t nb_meter_profiles, 2453 uint32_t nb_meter_policies, 2454 uint32_t nb_queues); 2455 void mlx5_flow_meter_uninit(struct rte_eth_dev *dev); 2456 int mlx5_flow_meter_ops_get(struct rte_eth_dev *dev, void *arg); 2457 struct mlx5_flow_meter_info *mlx5_flow_meter_find(struct mlx5_priv *priv, 2458 uint32_t meter_id, uint32_t *mtr_idx); 2459 struct mlx5_flow_meter_info * 2460 flow_dv_meter_find_by_idx(struct mlx5_priv *priv, uint32_t idx); 2461 int mlx5_flow_meter_attach(struct mlx5_priv *priv, 2462 struct mlx5_flow_meter_info *fm, 2463 const struct rte_flow_attr *attr, 2464 struct rte_flow_error *error); 2465 void mlx5_flow_meter_detach(struct mlx5_priv *priv, 2466 struct mlx5_flow_meter_info *fm); 2467 struct mlx5_flow_meter_policy *mlx5_flow_meter_policy_find 2468 (struct rte_eth_dev *dev, 2469 uint32_t policy_id, 2470 uint32_t *policy_idx); 2471 struct mlx5_flow_meter_info * 2472 mlx5_flow_meter_hierarchy_next_meter(struct mlx5_priv *priv, 2473 struct mlx5_flow_meter_policy *policy, 2474 uint32_t *mtr_idx); 2475 struct mlx5_flow_meter_policy * 2476 mlx5_flow_meter_hierarchy_get_final_policy(struct rte_eth_dev *dev, 2477 struct mlx5_flow_meter_policy *policy); 2478 int mlx5_flow_meter_flush(struct rte_eth_dev *dev, 2479 struct rte_mtr_error *error); 2480 void mlx5_flow_meter_rxq_flush(struct rte_eth_dev *dev); 2481 uint32_t mlx5_flow_mtr_max_get(struct mlx5_priv *priv); 2482 2483 /* mlx5_os.c */ 2484 2485 struct rte_pci_driver; 2486 int mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh); 2487 void mlx5_os_free_shared_dr(struct mlx5_priv *priv); 2488 int mlx5_os_net_probe(struct mlx5_common_device *cdev, 2489 struct mlx5_kvargs_ctrl *mkvlist); 2490 void mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh); 2491 void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh); 2492 void mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); 2493 int mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 2494 uint32_t index); 2495 int mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, unsigned int iface_idx, 2496 struct rte_ether_addr *mac_addr, 2497 int vf_index); 2498 int mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable); 2499 int mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable); 2500 int mlx5_os_set_nonblock_channel_fd(int fd); 2501 void mlx5_os_mac_addr_flush(struct rte_eth_dev *dev); 2502 void mlx5_os_net_cleanup(void); 2503 2504 /* mlx5_txpp.c */ 2505 2506 int mlx5_txpp_start(struct rte_eth_dev *dev); 2507 void mlx5_txpp_stop(struct rte_eth_dev *dev); 2508 int mlx5_txpp_read_clock(struct rte_eth_dev *dev, uint64_t *timestamp); 2509 int mlx5_txpp_xstats_get(struct rte_eth_dev *dev, 2510 struct rte_eth_xstat *stats, 2511 unsigned int n, unsigned int n_used); 2512 int mlx5_txpp_xstats_reset(struct rte_eth_dev *dev); 2513 int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev, 2514 struct rte_eth_xstat_name *xstats_names, 2515 unsigned int n, unsigned int n_used); 2516 void mlx5_txpp_interrupt_handler(void *cb_arg); 2517 int mlx5_txpp_map_hca_bar(struct rte_eth_dev *dev); 2518 void mlx5_txpp_unmap_hca_bar(struct rte_eth_dev *dev); 2519 2520 /* mlx5_rxtx.c */ 2521 2522 eth_tx_burst_t mlx5_select_tx_function(struct rte_eth_dev *dev); 2523 2524 /* mlx5_flow_aso.c */ 2525 2526 int mlx5_aso_mtr_queue_init(struct mlx5_dev_ctx_shared *sh, 2527 struct mlx5_aso_mtr_pool *hws_pool, 2528 struct mlx5_aso_mtr_pools_mng *pool_mng, 2529 uint32_t nb_queues); 2530 void mlx5_aso_mtr_queue_uninit(struct mlx5_dev_ctx_shared *sh, 2531 struct mlx5_aso_mtr_pool *hws_pool, 2532 struct mlx5_aso_mtr_pools_mng *pool_mng); 2533 int mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh, 2534 enum mlx5_access_aso_opc_mod aso_opc_mode, 2535 uint32_t nb_queues); 2536 int mlx5_aso_flow_hit_queue_poll_start(struct mlx5_dev_ctx_shared *sh); 2537 int mlx5_aso_flow_hit_queue_poll_stop(struct mlx5_dev_ctx_shared *sh); 2538 void mlx5_aso_queue_uninit(struct mlx5_dev_ctx_shared *sh, 2539 enum mlx5_access_aso_opc_mod aso_opc_mod); 2540 int mlx5_aso_meter_update_by_wqe(struct mlx5_priv *priv, uint32_t queue, 2541 struct mlx5_aso_mtr *mtr, 2542 struct mlx5_mtr_bulk *bulk, 2543 struct mlx5_hw_q_job *job, bool push); 2544 int mlx5_aso_mtr_wait(struct mlx5_priv *priv, 2545 struct mlx5_aso_mtr *mtr, bool is_tmpl_api); 2546 int mlx5_aso_ct_update_by_wqe(struct mlx5_dev_ctx_shared *sh, uint32_t queue, 2547 struct mlx5_aso_ct_action *ct, 2548 const struct rte_flow_action_conntrack *profile, 2549 void *user_data, 2550 bool push); 2551 int mlx5_aso_ct_wait_ready(struct mlx5_dev_ctx_shared *sh, uint32_t queue, 2552 struct mlx5_aso_ct_action *ct); 2553 int mlx5_aso_ct_query_by_wqe(struct mlx5_dev_ctx_shared *sh, uint32_t queue, 2554 struct mlx5_aso_ct_action *ct, 2555 struct rte_flow_action_conntrack *profile, 2556 void *user_data, bool push); 2557 int mlx5_aso_ct_available(struct mlx5_dev_ctx_shared *sh, uint32_t queue, 2558 struct mlx5_aso_ct_action *ct); 2559 uint32_t 2560 mlx5_get_supported_sw_parsing_offloads(const struct mlx5_hca_attr *attr); 2561 uint32_t 2562 mlx5_get_supported_tunneling_offloads(const struct mlx5_hca_attr *attr); 2563 2564 void mlx5_aso_ct_obj_analyze(struct rte_flow_action_conntrack *profile, 2565 char *wdata); 2566 void mlx5_aso_push_wqe(struct mlx5_dev_ctx_shared *sh, 2567 struct mlx5_aso_sq *sq); 2568 int mlx5_aso_pull_completion(struct mlx5_aso_sq *sq, 2569 struct rte_flow_op_result res[], 2570 uint16_t n_res); 2571 int mlx5_aso_cnt_queue_init(struct mlx5_dev_ctx_shared *sh); 2572 void mlx5_aso_cnt_queue_uninit(struct mlx5_dev_ctx_shared *sh); 2573 int mlx5_aso_cnt_query(struct mlx5_dev_ctx_shared *sh, 2574 struct mlx5_hws_cnt_pool *cpool); 2575 int mlx5_aso_ct_queue_init(struct mlx5_dev_ctx_shared *sh, 2576 struct mlx5_aso_ct_pools_mng *ct_mng, 2577 uint32_t nb_queues); 2578 int mlx5_aso_ct_queue_uninit(struct mlx5_dev_ctx_shared *sh, 2579 struct mlx5_aso_ct_pools_mng *ct_mng); 2580 int 2581 mlx5_aso_sq_create(struct mlx5_common_device *cdev, struct mlx5_aso_sq *sq, 2582 void *uar, uint16_t log_desc_n); 2583 void 2584 mlx5_aso_destroy_sq(struct mlx5_aso_sq *sq); 2585 void 2586 mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq); 2587 void 2588 mlx5_aso_cqe_err_handle(struct mlx5_aso_sq *sq); 2589 2590 /* mlx5_flow_flex.c */ 2591 2592 struct rte_flow_item_flex_handle * 2593 flow_dv_item_create(struct rte_eth_dev *dev, 2594 const struct rte_flow_item_flex_conf *conf, 2595 struct rte_flow_error *error); 2596 int flow_dv_item_release(struct rte_eth_dev *dev, 2597 const struct rte_flow_item_flex_handle *flex_handle, 2598 struct rte_flow_error *error); 2599 int mlx5_flex_item_port_init(struct rte_eth_dev *dev); 2600 void mlx5_flex_item_port_cleanup(struct rte_eth_dev *dev); 2601 void mlx5_flex_flow_translate_item(struct rte_eth_dev *dev, void *matcher, 2602 void *key, const struct rte_flow_item *item, 2603 bool is_inner); 2604 int mlx5_flex_get_sample_id(const struct mlx5_flex_item *tp, 2605 uint32_t idx, uint32_t *pos, 2606 bool is_inner, uint32_t *def); 2607 int mlx5_flex_get_parser_value_per_byte_off(const struct rte_flow_item_flex *item, 2608 void *flex, uint32_t byte_off, 2609 bool is_mask, bool tunnel, uint32_t *value); 2610 int mlx5_flex_acquire_index(struct rte_eth_dev *dev, 2611 struct rte_flow_item_flex_handle *handle, 2612 bool acquire); 2613 int mlx5_flex_release_index(struct rte_eth_dev *dev, int index); 2614 2615 /* Flex parser list callbacks. */ 2616 struct mlx5_list_entry *mlx5_flex_parser_create_cb(void *list_ctx, void *ctx); 2617 int mlx5_flex_parser_match_cb(void *list_ctx, 2618 struct mlx5_list_entry *iter, void *ctx); 2619 void mlx5_flex_parser_remove_cb(void *list_ctx, struct mlx5_list_entry *entry); 2620 struct mlx5_list_entry *mlx5_flex_parser_clone_cb(void *list_ctx, 2621 struct mlx5_list_entry *entry, 2622 void *ctx); 2623 void mlx5_flex_parser_clone_free_cb(void *tool_ctx, 2624 struct mlx5_list_entry *entry); 2625 2626 int 2627 mlx5_flow_quota_destroy(struct rte_eth_dev *dev); 2628 int 2629 mlx5_flow_quota_init(struct rte_eth_dev *dev, uint32_t nb_quotas); 2630 struct rte_flow_action_handle * 2631 mlx5_quota_alloc(struct rte_eth_dev *dev, uint32_t queue, 2632 const struct rte_flow_action_quota *conf, 2633 struct mlx5_hw_q_job *job, bool push, 2634 struct rte_flow_error *error); 2635 void 2636 mlx5_quota_async_completion(struct rte_eth_dev *dev, uint32_t queue, 2637 struct mlx5_hw_q_job *job); 2638 int 2639 mlx5_quota_query_update(struct rte_eth_dev *dev, uint32_t queue, 2640 struct rte_flow_action_handle *handle, 2641 const struct rte_flow_action *update, 2642 struct rte_flow_query_quota *query, 2643 struct mlx5_hw_q_job *async_job, bool push, 2644 struct rte_flow_error *error); 2645 int mlx5_quota_query(struct rte_eth_dev *dev, uint32_t queue, 2646 const struct rte_flow_action_handle *handle, 2647 struct rte_flow_query_quota *query, 2648 struct mlx5_hw_q_job *async_job, bool push, 2649 struct rte_flow_error *error); 2650 2651 int mlx5_alloc_srh_flex_parser(struct rte_eth_dev *dev); 2652 2653 void mlx5_free_srh_flex_parser(struct rte_eth_dev *dev); 2654 #endif /* RTE_PMD_MLX5_H_ */ 2655