1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2020 Mellanox Technologies, Ltd 3 */ 4 5 #include <errno.h> 6 #include <stdalign.h> 7 #include <stddef.h> 8 #include <stdint.h> 9 #include <stdlib.h> 10 11 #include <rte_windows.h> 12 #include <ethdev_pci.h> 13 14 #include <mlx5_glue.h> 15 #include <mlx5_devx_cmds.h> 16 #include <mlx5_common.h> 17 #include <mlx5_common_mp.h> 18 #include <mlx5_common_mr.h> 19 #include <mlx5_malloc.h> 20 21 #include "mlx5_defs.h" 22 #include "mlx5.h" 23 #include "mlx5_common_os.h" 24 #include "mlx5_utils.h" 25 #include "mlx5_rxtx.h" 26 #include "mlx5_rx.h" 27 #include "mlx5_tx.h" 28 #include "mlx5_autoconf.h" 29 #include "mlx5_flow.h" 30 #include "mlx5_devx.h" 31 32 static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data"; 33 34 /* Spinlock for mlx5_shared_data allocation. */ 35 static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER; 36 37 /* rte flow indexed pool configuration. */ 38 static const struct mlx5_indexed_pool_config default_icfg[] = { 39 { 40 .size = sizeof(struct rte_flow), 41 .trunk_size = 64, 42 .need_lock = 1, 43 .release_mem_en = 0, 44 .malloc = mlx5_malloc, 45 .free = mlx5_free, 46 .per_core_cache = 0, 47 .type = "ctl_flow_ipool", 48 }, 49 { 50 .size = sizeof(struct rte_flow), 51 .trunk_size = 64, 52 .grow_trunk = 3, 53 .grow_shift = 2, 54 .need_lock = 1, 55 .release_mem_en = 0, 56 .malloc = mlx5_malloc, 57 .free = mlx5_free, 58 .per_core_cache = 1 << 14, 59 .type = "rte_flow_ipool", 60 }, 61 { 62 .size = sizeof(struct rte_flow), 63 .trunk_size = 64, 64 .grow_trunk = 3, 65 .grow_shift = 2, 66 .need_lock = 1, 67 .release_mem_en = 0, 68 .malloc = mlx5_malloc, 69 .free = mlx5_free, 70 .per_core_cache = 0, 71 .type = "mcp_flow_ipool", 72 }, 73 }; 74 75 static void 76 mlx5_queue_counter_id_prepare(struct rte_eth_dev *dev) 77 { 78 struct mlx5_priv *priv = dev->data->dev_private; 79 void *ctx = priv->sh->cdev->ctx; 80 81 priv->q_counters = mlx5_devx_cmd_queue_counter_alloc(ctx); 82 if (!priv->q_counters) { 83 DRV_LOG(ERR, "Port %d queue counter object cannot be created " 84 "by DevX - imissed counter will be unavailable", 85 dev->data->port_id); 86 return; 87 } 88 priv->counter_set_id = priv->q_counters->id; 89 } 90 91 /** 92 * Initialize shared data between primary and secondary process. 93 * 94 * A memzone is reserved by primary process and secondary processes attach to 95 * the memzone. 96 * 97 * @return 98 * 0 on success, a negative errno value otherwise and rte_errno is set. 99 */ 100 static int 101 mlx5_init_shared_data(void) 102 { 103 const struct rte_memzone *mz; 104 int ret = 0; 105 106 rte_spinlock_lock(&mlx5_shared_data_lock); 107 if (mlx5_shared_data == NULL) { 108 /* Allocate shared memory. */ 109 mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA, 110 sizeof(*mlx5_shared_data), 111 SOCKET_ID_ANY, 0); 112 if (mz == NULL) { 113 DRV_LOG(ERR, 114 "Cannot allocate mlx5 shared data"); 115 ret = -rte_errno; 116 goto error; 117 } 118 mlx5_shared_data = mz->addr; 119 memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data)); 120 rte_spinlock_init(&mlx5_shared_data->lock); 121 } 122 error: 123 rte_spinlock_unlock(&mlx5_shared_data_lock); 124 return ret; 125 } 126 127 /** 128 * PMD global initialization. 129 * 130 * Independent from individual device, this function initializes global 131 * per-PMD data structures distinguishing primary and secondary processes. 132 * Hence, each initialization is called once per a process. 133 * 134 * @return 135 * 0 on success, a negative errno value otherwise and rte_errno is set. 136 */ 137 static int 138 mlx5_init_once(void) 139 { 140 if (mlx5_init_shared_data()) 141 return -rte_errno; 142 return 0; 143 } 144 145 /** 146 * Get mlx5 device capabilities. 147 * 148 * @param sh 149 * Pointer to shared device context. 150 * 151 * @return 152 * 0 on success, a negative errno value otherwise and rte_errno is set. 153 */ 154 int 155 mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh) 156 { 157 struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr; 158 struct mlx5_context *mlx5_ctx = sh->cdev->ctx; 159 void *pv_iseg = NULL; 160 u32 cb_iseg = 0; 161 162 MLX5_ASSERT(sh->cdev->config.devx); 163 MLX5_ASSERT(mlx5_dev_is_pci(sh->cdev->dev)); 164 pv_iseg = mlx5_glue->query_hca_iseg(mlx5_ctx, &cb_iseg); 165 if (pv_iseg == NULL) { 166 DRV_LOG(ERR, "Failed to get device hca_iseg."); 167 rte_errno = errno; 168 return -rte_errno; 169 } 170 memset(&sh->dev_cap, 0, sizeof(struct mlx5_dev_cap)); 171 sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_DEV_TO_PCI(sh->cdev->dev)); 172 sh->dev_cap.max_cq = 1 << hca_attr->log_max_cq; 173 sh->dev_cap.max_qp = 1 << hca_attr->log_max_qp; 174 sh->dev_cap.max_qp_wr = 1 << hca_attr->log_max_qp_sz; 175 sh->dev_cap.dv_flow_en = 1; 176 DRV_LOG(DEBUG, "MPW isn't supported."); 177 DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is no supported."); 178 sh->dev_cap.hw_csum = hca_attr->csum_cap; 179 DRV_LOG(DEBUG, "Checksum offloading is %ssupported.", 180 (sh->dev_cap.hw_csum ? "" : "not ")); 181 sh->dev_cap.hw_vlan_strip = hca_attr->vlan_cap; 182 DRV_LOG(DEBUG, "VLAN stripping is %ssupported.", 183 (sh->dev_cap.hw_vlan_strip ? "" : "not ")); 184 sh->dev_cap.hw_fcs_strip = hca_attr->scatter_fcs; 185 sh->dev_cap.tso = ((1 << hca_attr->max_lso_cap) > 0); 186 if (sh->dev_cap.tso) 187 sh->dev_cap.tso_max_payload_sz = 1 << hca_attr->max_lso_cap; 188 DRV_LOG(DEBUG, "Counters are not supported."); 189 if (hca_attr->striding_rq) { 190 sh->dev_cap.mprq.enabled = 1; 191 sh->dev_cap.mprq.log_min_stride_size = 192 MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; 193 sh->dev_cap.mprq.log_max_stride_size = 194 MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES; 195 if (hca_attr->ext_stride_num_range) 196 sh->dev_cap.mprq.log_min_stride_num = 197 MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES; 198 else 199 sh->dev_cap.mprq.log_min_stride_num = 200 MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; 201 sh->dev_cap.mprq.log_max_stride_num = 202 MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES; 203 DRV_LOG(DEBUG, "\tmin_single_stride_log_num_of_bytes: %u", 204 sh->dev_cap.mprq.log_min_stride_size); 205 DRV_LOG(DEBUG, "\tmax_single_stride_log_num_of_bytes: %u", 206 sh->dev_cap.mprq.log_max_stride_size); 207 DRV_LOG(DEBUG, "\tmin_single_wqe_log_num_of_strides: %u", 208 sh->dev_cap.mprq.log_min_stride_num); 209 DRV_LOG(DEBUG, "\tmax_single_wqe_log_num_of_strides: %u", 210 sh->dev_cap.mprq.log_max_stride_num); 211 DRV_LOG(DEBUG, "\tmin_stride_wqe_log_size: %u", 212 sh->dev_cap.mprq.log_min_stride_wqe_size); 213 DRV_LOG(DEBUG, "Device supports Multi-Packet RQ."); 214 } 215 if (hca_attr->rss_ind_tbl_cap) { 216 /* 217 * DPDK doesn't support larger/variable indirection tables. 218 * Once DPDK supports it, take max size from device attr. 219 */ 220 sh->dev_cap.ind_table_max_size = 221 RTE_MIN((uint32_t)1 << hca_attr->rss_ind_tbl_cap, 222 (uint32_t)RTE_ETH_RSS_RETA_SIZE_512); 223 DRV_LOG(DEBUG, "Maximum Rx indirection table size is %u", 224 sh->dev_cap.ind_table_max_size); 225 } 226 if (hca_attr->enhanced_multi_pkt_send_wqe) 227 sh->dev_cap.mps = MLX5_MPW_ENHANCED; 228 else if (hca_attr->multi_pkt_send_wqe && 229 sh->dev_cap.mps != MLX5_ARG_UNSET) 230 sh->dev_cap.mps = MLX5_MPW; 231 else 232 sh->dev_cap.mps = MLX5_MPW_DISABLED; 233 sh->dev_cap.swp = mlx5_get_supported_sw_parsing_offloads(hca_attr); 234 sh->dev_cap.tunnel_en = mlx5_get_supported_tunneling_offloads(hca_attr); 235 if (sh->dev_cap.tunnel_en) { 236 DRV_LOG(DEBUG, "Tunnel offloading is supported for %s%s%s", 237 sh->dev_cap.tunnel_en & 238 MLX5_TUNNELED_OFFLOADS_VXLAN_CAP ? "[VXLAN]" : "", 239 sh->dev_cap.tunnel_en & 240 MLX5_TUNNELED_OFFLOADS_GRE_CAP ? "[GRE]" : "", 241 sh->dev_cap.tunnel_en & 242 MLX5_TUNNELED_OFFLOADS_GENEVE_CAP ? "[GENEVE]" : ""); 243 } else { 244 DRV_LOG(DEBUG, "Tunnel offloading is not supported."); 245 } 246 sh->dev_cap.cqe_comp = 0; 247 #if (RTE_CACHE_LINE_SIZE == 128) 248 if (hca_attr->cqe_compression_128) 249 sh->dev_cap.cqe_comp = 1; 250 DRV_LOG(DEBUG, "Rx CQE 128B compression is %ssupported.", 251 sh->dev_cap.cqe_comp ? "" : "not "); 252 #else 253 if (hca_attr->cqe_compression) 254 sh->dev_cap.cqe_comp = 1; 255 DRV_LOG(DEBUG, "Rx CQE compression is %ssupported.", 256 sh->dev_cap.cqe_comp ? "" : "not "); 257 #endif 258 snprintf(sh->dev_cap.fw_ver, 64, "%x.%x.%04x", 259 MLX5_GET(initial_seg, pv_iseg, fw_rev_major), 260 MLX5_GET(initial_seg, pv_iseg, fw_rev_minor), 261 MLX5_GET(initial_seg, pv_iseg, fw_rev_subminor)); 262 DRV_LOG(DEBUG, "Packet pacing is not supported."); 263 mlx5_rt_timestamp_config(sh, hca_attr); 264 return 0; 265 } 266 267 /** 268 * Initialize DR related data within private structure. 269 * Routine checks the reference counter and does actual 270 * resources creation/initialization only if counter is zero. 271 * 272 * @param[in] priv 273 * Pointer to the private device data structure. 274 * 275 * @return 276 * Zero on success, positive error code otherwise. 277 */ 278 static int 279 mlx5_alloc_shared_dr(struct mlx5_priv *priv) 280 { 281 struct mlx5_dev_ctx_shared *sh = priv->sh; 282 int err = 0; 283 284 if (!sh->flow_tbls) 285 err = mlx5_alloc_table_hash_list(priv); 286 else 287 DRV_LOG(DEBUG, "sh->flow_tbls[%p] already created, reuse", 288 (void *)sh->flow_tbls); 289 return err; 290 } 291 /** 292 * Destroy DR related data within private structure. 293 * 294 * @param[in] priv 295 * Pointer to the private device data structure. 296 */ 297 void 298 mlx5_os_free_shared_dr(struct mlx5_priv *priv) 299 { 300 mlx5_free_table_hash_list(priv); 301 } 302 303 /** 304 * Set the completion channel file descriptor interrupt as non-blocking. 305 * Currently it has no support under Windows. 306 * 307 * @param[in] rxq_obj 308 * Pointer to RQ channel object, which includes the channel fd 309 * 310 * @param[out] fd 311 * The file descriptor (representing the interrupt) used in this channel. 312 * 313 * @return 314 * 0 on successfully setting the fd to non-blocking, non-zero otherwise. 315 */ 316 int 317 mlx5_os_set_nonblock_channel_fd(int fd) 318 { 319 (void)fd; 320 DRV_LOG(WARNING, "%s: is not supported", __func__); 321 return -ENOTSUP; 322 } 323 324 /** 325 * Spawn an Ethernet device from DevX information. 326 * 327 * @param dpdk_dev 328 * Backing DPDK device. 329 * @param spawn 330 * Verbs device parameters (name, port, switch_info) to spawn. 331 * @param mkvlist 332 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs. 333 * 334 * @return 335 * A valid Ethernet device object on success, NULL otherwise and rte_errno 336 * is set. The following errors are defined: 337 * 338 * EEXIST: device is already spawned 339 */ 340 static struct rte_eth_dev * 341 mlx5_dev_spawn(struct rte_device *dpdk_dev, 342 struct mlx5_dev_spawn_data *spawn, 343 struct mlx5_kvargs_ctrl *mkvlist) 344 { 345 const struct mlx5_switch_info *switch_info = &spawn->info; 346 struct mlx5_dev_ctx_shared *sh = NULL; 347 struct rte_eth_dev *eth_dev = NULL; 348 struct mlx5_priv *priv = NULL; 349 int err = 0; 350 struct rte_ether_addr mac; 351 char name[RTE_ETH_NAME_MAX_LEN]; 352 int own_domain_id = 0; 353 uint16_t port_id; 354 int i; 355 struct mlx5_indexed_pool_config icfg[RTE_DIM(default_icfg)]; 356 357 memcpy(icfg, default_icfg, sizeof(icfg)); 358 /* Build device name. */ 359 strlcpy(name, dpdk_dev->name, sizeof(name)); 360 /* check if the device is already spawned */ 361 if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) { 362 rte_errno = EEXIST; 363 return NULL; 364 } 365 DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name); 366 sh = mlx5_alloc_shared_dev_ctx(spawn, mkvlist); 367 if (!sh) 368 return NULL; 369 if (!sh->config.dv_flow_en) { 370 DRV_LOG(ERR, "Windows flow mode must be DV flow enable."); 371 err = ENOTSUP; 372 goto error; 373 } 374 if (sh->config.vf_nl_en) { 375 DRV_LOG(DEBUG, "VF netlink isn't supported."); 376 sh->config.vf_nl_en = 0; 377 } 378 /* Initialize the shutdown event in mlx5_dev_spawn to 379 * support mlx5_is_removed for Windows. 380 */ 381 err = mlx5_glue->devx_init_showdown_event(sh->cdev->ctx); 382 if (err) { 383 DRV_LOG(ERR, "failed to init showdown event: %s", 384 strerror(errno)); 385 goto error; 386 } 387 /* Allocate private eth device data. */ 388 priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, 389 sizeof(*priv), 390 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 391 if (priv == NULL) { 392 DRV_LOG(ERR, "priv allocation failure"); 393 err = ENOMEM; 394 goto error; 395 } 396 priv->sh = sh; 397 priv->dev_port = spawn->phys_port; 398 priv->pci_dev = spawn->pci_dev; 399 priv->mtu = RTE_ETHER_MTU; 400 priv->mp_id.port_id = port_id; 401 strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN); 402 priv->representor = !!switch_info->representor; 403 priv->master = !!switch_info->master; 404 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 405 priv->vport_meta_tag = 0; 406 priv->vport_meta_mask = 0; 407 priv->pf_bond = spawn->pf_bond; 408 priv->vport_id = -1; 409 /* representor_id field keeps the unmodified VF index. */ 410 priv->representor_id = -1; 411 /* 412 * Look for sibling devices in order to reuse their switch domain 413 * if any, otherwise allocate one. 414 */ 415 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 416 const struct mlx5_priv *opriv = 417 rte_eth_devices[port_id].data->dev_private; 418 419 if (!opriv || 420 opriv->sh != priv->sh || 421 opriv->domain_id == 422 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) 423 continue; 424 priv->domain_id = opriv->domain_id; 425 break; 426 } 427 if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { 428 err = rte_eth_switch_domain_alloc(&priv->domain_id); 429 if (err) { 430 err = rte_errno; 431 DRV_LOG(ERR, "unable to allocate switch domain: %s", 432 strerror(rte_errno)); 433 goto error; 434 } 435 own_domain_id = 1; 436 } 437 /* Process parameters and store port configuration on priv structure. */ 438 err = mlx5_port_args_config(priv, mkvlist, &priv->config); 439 if (err) { 440 err = rte_errno; 441 DRV_LOG(ERR, "Failed to process port configure: %s", 442 strerror(rte_errno)); 443 goto error; 444 } 445 eth_dev = rte_eth_dev_allocate(name); 446 if (eth_dev == NULL) { 447 DRV_LOG(ERR, "can not allocate rte ethdev"); 448 err = ENOMEM; 449 goto error; 450 } 451 if (priv->representor) { 452 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; 453 eth_dev->data->representor_id = priv->representor_id; 454 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 455 struct mlx5_priv *opriv = 456 rte_eth_devices[port_id].data->dev_private; 457 if (opriv && 458 opriv->master && 459 opriv->domain_id == priv->domain_id && 460 opriv->sh == priv->sh) { 461 eth_dev->data->backer_port_id = port_id; 462 break; 463 } 464 } 465 if (port_id >= RTE_MAX_ETHPORTS) 466 eth_dev->data->backer_port_id = eth_dev->data->port_id; 467 } 468 /* 469 * Store associated network device interface index. This index 470 * is permanent throughout the lifetime of device. So, we may store 471 * the ifindex here and use the cached value further. 472 */ 473 MLX5_ASSERT(spawn->ifindex); 474 priv->if_index = spawn->ifindex; 475 eth_dev->data->dev_private = priv; 476 priv->dev_data = eth_dev->data; 477 eth_dev->data->mac_addrs = priv->mac; 478 eth_dev->device = dpdk_dev; 479 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 480 /* Configure the first MAC address by default. */ 481 if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) { 482 DRV_LOG(ERR, 483 "port %u cannot get MAC address, is mlx5_en" 484 " loaded? (errno: %s).", 485 eth_dev->data->port_id, strerror(rte_errno)); 486 err = ENODEV; 487 goto error; 488 } 489 DRV_LOG(INFO, 490 "port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT, 491 eth_dev->data->port_id, RTE_ETHER_ADDR_BYTES(&mac)); 492 #ifdef RTE_LIBRTE_MLX5_DEBUG 493 { 494 char ifname[MLX5_NAMESIZE]; 495 496 if (mlx5_get_ifname(eth_dev, &ifname) == 0) 497 DRV_LOG(DEBUG, "port %u ifname is \"%s\"", 498 eth_dev->data->port_id, ifname); 499 else 500 DRV_LOG(DEBUG, "port %u ifname is unknown.", 501 eth_dev->data->port_id); 502 } 503 #endif 504 /* Get actual MTU if possible. */ 505 err = mlx5_get_mtu(eth_dev, &priv->mtu); 506 if (err) { 507 err = rte_errno; 508 goto error; 509 } 510 DRV_LOG(DEBUG, "port %u MTU is %u.", eth_dev->data->port_id, 511 priv->mtu); 512 /* Initialize burst functions to prevent crashes before link-up. */ 513 eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; 514 eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; 515 eth_dev->dev_ops = &mlx5_dev_ops; 516 eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 517 eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 518 eth_dev->rx_queue_count = mlx5_rx_queue_count; 519 /* Register MAC address. */ 520 claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); 521 priv->ctrl_flows = 0; 522 TAILQ_INIT(&priv->flow_meters); 523 priv->mtr_profile_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_PTR); 524 if (!priv->mtr_profile_tbl) 525 goto error; 526 /* Bring Ethernet device up. */ 527 DRV_LOG(DEBUG, "port %u forcing Ethernet interface up.", 528 eth_dev->data->port_id); 529 /* nl calls are unsupported - set to -1 not to fail on release */ 530 priv->nl_socket_rdma = -1; 531 priv->nl_socket_route = -1; 532 mlx5_set_link_up(eth_dev); 533 /* 534 * Even though the interrupt handler is not installed yet, 535 * interrupts will still trigger on the async_fd from 536 * Verbs context returned by ibv_open_device(). 537 */ 538 mlx5_link_update(eth_dev, 0); 539 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) { 540 icfg[i].release_mem_en = !!sh->config.reclaim_mode; 541 if (sh->config.reclaim_mode) 542 icfg[i].per_core_cache = 0; 543 #ifdef HAVE_MLX5_HWS_SUPPORT 544 if (priv->sh->config.dv_flow_en == 2) 545 icfg[i].size = sizeof(struct rte_flow_hw) + sizeof(struct rte_flow_nt2hws); 546 #endif 547 priv->flows[i] = mlx5_ipool_create(&icfg[i]); 548 if (!priv->flows[i]) 549 goto error; 550 } 551 /* Create context for virtual machine VLAN workaround. */ 552 priv->vmwa_context = NULL; 553 if (sh->config.dv_flow_en) { 554 err = mlx5_alloc_shared_dr(priv); 555 if (err) 556 goto error; 557 } 558 /* No supported flow priority number detection. */ 559 priv->sh->flow_max_priority = -1; 560 mlx5_set_metadata_mask(eth_dev); 561 if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 562 !priv->sh->dv_regc0_mask) { 563 DRV_LOG(ERR, "metadata mode %u is not supported " 564 "(no metadata reg_c[0] is available).", 565 sh->config.dv_xmeta_en); 566 err = ENOTSUP; 567 goto error; 568 } 569 priv->hrxqs = mlx5_list_create("hrxq", eth_dev, true, 570 mlx5_hrxq_create_cb, mlx5_hrxq_match_cb, 571 mlx5_hrxq_remove_cb, mlx5_hrxq_clone_cb, 572 mlx5_hrxq_clone_free_cb); 573 /* Query availability of metadata reg_c's. */ 574 if (!priv->sh->metadata_regc_check_flag) { 575 err = mlx5_flow_discover_mreg_c(eth_dev); 576 if (err < 0) { 577 err = -err; 578 goto error; 579 } 580 } 581 if (!mlx5_flow_ext_mreg_supported(eth_dev)) { 582 DRV_LOG(DEBUG, 583 "port %u extensive metadata register is not supported.", 584 eth_dev->data->port_id); 585 if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 586 DRV_LOG(ERR, "metadata mode %u is not supported " 587 "(no metadata registers available).", 588 sh->config.dv_xmeta_en); 589 err = ENOTSUP; 590 goto error; 591 } 592 } 593 if (sh->cdev->config.devx) { 594 priv->obj_ops = devx_obj_ops; 595 } else { 596 DRV_LOG(ERR, "Windows flow must be DevX."); 597 err = ENOTSUP; 598 goto error; 599 } 600 mlx5_flow_counter_mode_config(eth_dev); 601 mlx5_queue_counter_id_prepare(eth_dev); 602 return eth_dev; 603 error: 604 if (priv) { 605 if (priv->mtr_profile_tbl) 606 mlx5_l3t_destroy(priv->mtr_profile_tbl); 607 if (own_domain_id) 608 claim_zero(rte_eth_switch_domain_free(priv->domain_id)); 609 mlx5_free(priv); 610 if (eth_dev != NULL) 611 eth_dev->data->dev_private = NULL; 612 } 613 if (eth_dev != NULL) { 614 /* mac_addrs must not be freed alone because part of 615 * dev_private 616 **/ 617 eth_dev->data->mac_addrs = NULL; 618 rte_eth_dev_release_port(eth_dev); 619 } 620 if (sh) 621 mlx5_free_shared_dev_ctx(sh); 622 MLX5_ASSERT(err > 0); 623 rte_errno = err; 624 return NULL; 625 } 626 627 /** 628 * This function should share events between multiple ports of single IB 629 * device. Currently it has no support under Windows. 630 * 631 * @param sh 632 * Pointer to mlx5_dev_ctx_shared object. 633 */ 634 void 635 mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) 636 { 637 (void)sh; 638 DRV_LOG(WARNING, "%s: is not supported", __func__); 639 } 640 641 /** 642 * This function should share events between multiple ports of single IB 643 * device. Currently it has no support under Windows. 644 * 645 * @param dev 646 * Pointer to mlx5_dev_ctx_shared object. 647 */ 648 void 649 mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh) 650 { 651 (void)sh; 652 DRV_LOG(WARNING, "%s: is not supported", __func__); 653 } 654 655 /** 656 * Read statistics by a named counter. 657 * 658 * @param[in] priv 659 * Pointer to the private device data structure. 660 * @param[in] ctr_name 661 * Pointer to the name of the statistic counter to read 662 * @param[out] stat 663 * Pointer to read statistic value. 664 * @return 665 * 0 on success and stat is valid, non-zero if failed to read the value 666 * or counter is not supported. 667 * rte_errno is set. 668 * 669 */ 670 int 671 mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, 672 uint64_t *stat) 673 { 674 if (priv->q_counters != NULL && strcmp(ctr_name, "out_of_buffer") == 0) 675 return mlx5_devx_cmd_queue_counter_query 676 (priv->q_counters, 0, (uint32_t *)stat); 677 DRV_LOG(WARNING, "%s: is not supported for the %s counter", 678 __func__, ctr_name); 679 return -ENOTSUP; 680 } 681 682 /** 683 * Flush device MAC addresses 684 * Currently it has no support under Windows. 685 * 686 * @param dev 687 * Pointer to Ethernet device structure. 688 * 689 */ 690 void 691 mlx5_os_mac_addr_flush(struct rte_eth_dev *dev) 692 { 693 (void)dev; 694 DRV_LOG(WARNING, "%s: is not supported", __func__); 695 } 696 697 /** 698 * Remove a MAC address from device 699 * Currently it has no support under Windows. 700 * 701 * @param dev 702 * Pointer to Ethernet device structure. 703 * @param index 704 * MAC address index. 705 */ 706 void 707 mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 708 { 709 (void)dev; 710 (void)(index); 711 DRV_LOG(WARNING, "%s: is not supported", __func__); 712 } 713 714 /** 715 * Adds a MAC address to the device 716 * Currently it has no support under Windows. 717 * 718 * @param dev 719 * Pointer to Ethernet device structure. 720 * @param mac_addr 721 * MAC address to register. 722 * @param index 723 * MAC address index. 724 * 725 * @return 726 * 0 on success, a negative errno value otherwise 727 */ 728 int 729 mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 730 uint32_t index) 731 { 732 (void)index; 733 struct rte_ether_addr lmac; 734 735 if (mlx5_get_mac(dev, &lmac.addr_bytes)) { 736 DRV_LOG(ERR, 737 "port %u cannot get MAC address, is mlx5_en" 738 " loaded? (errno: %s)", 739 dev->data->port_id, strerror(rte_errno)); 740 return rte_errno; 741 } 742 if (!rte_is_same_ether_addr(&lmac, mac)) { 743 DRV_LOG(ERR, 744 "adding new mac address to device is unsupported"); 745 return -ENOTSUP; 746 } 747 return 0; 748 } 749 750 /** 751 * Modify a VF MAC address 752 * Currently it has no support under Windows. 753 * 754 * @param priv 755 * Pointer to device private data. 756 * @param mac_addr 757 * MAC address to modify into. 758 * @param iface_idx 759 * Net device interface index 760 * @param vf_index 761 * VF index 762 * 763 * @return 764 * 0 on success, a negative errno value otherwise 765 */ 766 int 767 mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, 768 unsigned int iface_idx, 769 struct rte_ether_addr *mac_addr, 770 int vf_index) 771 { 772 (void)priv; 773 (void)iface_idx; 774 (void)mac_addr; 775 (void)vf_index; 776 DRV_LOG(WARNING, "%s: is not supported", __func__); 777 return -ENOTSUP; 778 } 779 780 /** 781 * Set device promiscuous mode 782 * 783 * @param dev 784 * Pointer to Ethernet device structure. 785 * @param enable 786 * 0 - promiscuous is disabled, otherwise - enabled 787 * 788 * @return 789 * 0 on success, a negative error value otherwise 790 */ 791 int 792 mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable) 793 { 794 struct mlx5_priv *priv = dev->data->dev_private; 795 796 return mlx5_glue->devx_set_promisc_vport(priv->sh->cdev->ctx, ALL_PROMISC, enable); 797 } 798 799 /** 800 * Set device allmulti mode 801 * 802 * @param dev 803 * Pointer to Ethernet device structure. 804 * @param enable 805 * 0 - all multicase is disabled, otherwise - enabled 806 * 807 * @return 808 * 0 on success, a negative error value otherwise 809 */ 810 int 811 mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable) 812 { 813 struct mlx5_priv *priv = dev->data->dev_private; 814 815 return mlx5_glue->devx_set_promisc_vport(priv->sh->cdev->ctx, MC_PROMISC, enable); 816 } 817 818 /** 819 * DPDK callback to register a PCI device. 820 * 821 * This function spawns Ethernet devices out of a given device. 822 * 823 * @param[in] cdev 824 * Pointer to the common device. 825 * @param[in, out] mkvlist 826 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs. 827 * 828 * @return 829 * 0 on success, a negative errno value otherwise and rte_errno is set. 830 */ 831 int 832 mlx5_os_net_probe(struct mlx5_common_device *cdev, 833 struct mlx5_kvargs_ctrl *mkvlist) 834 { 835 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev); 836 struct mlx5_dev_spawn_data spawn = { 837 .pf_bond = -1, 838 .max_port = 1, 839 .phys_port = 1, 840 .phys_dev_name = mlx5_os_get_ctx_device_name(cdev->ctx), 841 .pci_dev = pci_dev, 842 .cdev = cdev, 843 .ifindex = -1, /* Spawn will assign */ 844 .info = (struct mlx5_switch_info){ 845 .name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK, 846 }, 847 }; 848 int ret; 849 uint32_t restore; 850 851 if (rte_eal_process_type() == RTE_PROC_SECONDARY) { 852 DRV_LOG(ERR, "Secondary process is not supported on Windows."); 853 return -ENOTSUP; 854 } 855 ret = mlx5_init_once(); 856 if (ret) { 857 DRV_LOG(ERR, "unable to init PMD global data: %s", 858 strerror(rte_errno)); 859 return -rte_errno; 860 } 861 spawn.eth_dev = mlx5_dev_spawn(cdev->dev, &spawn, mkvlist); 862 if (!spawn.eth_dev) 863 return -rte_errno; 864 restore = spawn.eth_dev->data->dev_flags; 865 rte_eth_copy_pci_info(spawn.eth_dev, pci_dev); 866 /* Restore non-PCI flags cleared by the above call. */ 867 spawn.eth_dev->data->dev_flags |= restore; 868 rte_eth_dev_probing_finish(spawn.eth_dev); 869 return 0; 870 } 871 872 /** 873 * Cleanup resources when the last device is closed. 874 */ 875 void 876 mlx5_os_net_cleanup(void) 877 { 878 } 879 880 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {0}; 881