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 struct mlx5_indexed_pool_config 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 356 /* Build device name. */ 357 strlcpy(name, dpdk_dev->name, sizeof(name)); 358 /* check if the device is already spawned */ 359 if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) { 360 rte_errno = EEXIST; 361 return NULL; 362 } 363 DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name); 364 sh = mlx5_alloc_shared_dev_ctx(spawn, mkvlist); 365 if (!sh) 366 return NULL; 367 if (!sh->config.dv_flow_en) { 368 DRV_LOG(ERR, "Windows flow mode must be DV flow enable."); 369 err = ENOTSUP; 370 goto error; 371 } 372 if (sh->config.vf_nl_en) { 373 DRV_LOG(DEBUG, "VF netlink isn't supported."); 374 sh->config.vf_nl_en = 0; 375 } 376 /* Initialize the shutdown event in mlx5_dev_spawn to 377 * support mlx5_is_removed for Windows. 378 */ 379 err = mlx5_glue->devx_init_showdown_event(sh->cdev->ctx); 380 if (err) { 381 DRV_LOG(ERR, "failed to init showdown event: %s", 382 strerror(errno)); 383 goto error; 384 } 385 /* Allocate private eth device data. */ 386 priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, 387 sizeof(*priv), 388 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); 389 if (priv == NULL) { 390 DRV_LOG(ERR, "priv allocation failure"); 391 err = ENOMEM; 392 goto error; 393 } 394 priv->sh = sh; 395 priv->dev_port = spawn->phys_port; 396 priv->pci_dev = spawn->pci_dev; 397 priv->mtu = RTE_ETHER_MTU; 398 priv->mp_id.port_id = port_id; 399 strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN); 400 priv->representor = !!switch_info->representor; 401 priv->master = !!switch_info->master; 402 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 403 priv->vport_meta_tag = 0; 404 priv->vport_meta_mask = 0; 405 priv->pf_bond = spawn->pf_bond; 406 priv->vport_id = -1; 407 /* representor_id field keeps the unmodified VF index. */ 408 priv->representor_id = -1; 409 /* 410 * Look for sibling devices in order to reuse their switch domain 411 * if any, otherwise allocate one. 412 */ 413 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 414 const struct mlx5_priv *opriv = 415 rte_eth_devices[port_id].data->dev_private; 416 417 if (!opriv || 418 opriv->sh != priv->sh || 419 opriv->domain_id == 420 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) 421 continue; 422 priv->domain_id = opriv->domain_id; 423 break; 424 } 425 if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { 426 err = rte_eth_switch_domain_alloc(&priv->domain_id); 427 if (err) { 428 err = rte_errno; 429 DRV_LOG(ERR, "unable to allocate switch domain: %s", 430 strerror(rte_errno)); 431 goto error; 432 } 433 own_domain_id = 1; 434 } 435 /* Process parameters and store port configuration on priv structure. */ 436 err = mlx5_port_args_config(priv, mkvlist, &priv->config); 437 if (err) { 438 err = rte_errno; 439 DRV_LOG(ERR, "Failed to process port configure: %s", 440 strerror(rte_errno)); 441 goto error; 442 } 443 eth_dev = rte_eth_dev_allocate(name); 444 if (eth_dev == NULL) { 445 DRV_LOG(ERR, "can not allocate rte ethdev"); 446 err = ENOMEM; 447 goto error; 448 } 449 if (priv->representor) { 450 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; 451 eth_dev->data->representor_id = priv->representor_id; 452 MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) { 453 struct mlx5_priv *opriv = 454 rte_eth_devices[port_id].data->dev_private; 455 if (opriv && 456 opriv->master && 457 opriv->domain_id == priv->domain_id && 458 opriv->sh == priv->sh) { 459 eth_dev->data->backer_port_id = port_id; 460 break; 461 } 462 } 463 if (port_id >= RTE_MAX_ETHPORTS) 464 eth_dev->data->backer_port_id = eth_dev->data->port_id; 465 } 466 /* 467 * Store associated network device interface index. This index 468 * is permanent throughout the lifetime of device. So, we may store 469 * the ifindex here and use the cached value further. 470 */ 471 MLX5_ASSERT(spawn->ifindex); 472 priv->if_index = spawn->ifindex; 473 eth_dev->data->dev_private = priv; 474 priv->dev_data = eth_dev->data; 475 eth_dev->data->mac_addrs = priv->mac; 476 eth_dev->device = dpdk_dev; 477 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 478 /* Configure the first MAC address by default. */ 479 if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) { 480 DRV_LOG(ERR, 481 "port %u cannot get MAC address, is mlx5_en" 482 " loaded? (errno: %s).", 483 eth_dev->data->port_id, strerror(rte_errno)); 484 err = ENODEV; 485 goto error; 486 } 487 DRV_LOG(INFO, 488 "port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT, 489 eth_dev->data->port_id, RTE_ETHER_ADDR_BYTES(&mac)); 490 #ifdef RTE_LIBRTE_MLX5_DEBUG 491 { 492 char ifname[MLX5_NAMESIZE]; 493 494 if (mlx5_get_ifname(eth_dev, &ifname) == 0) 495 DRV_LOG(DEBUG, "port %u ifname is \"%s\"", 496 eth_dev->data->port_id, ifname); 497 else 498 DRV_LOG(DEBUG, "port %u ifname is unknown.", 499 eth_dev->data->port_id); 500 } 501 #endif 502 /* Get actual MTU if possible. */ 503 err = mlx5_get_mtu(eth_dev, &priv->mtu); 504 if (err) { 505 err = rte_errno; 506 goto error; 507 } 508 DRV_LOG(DEBUG, "port %u MTU is %u.", eth_dev->data->port_id, 509 priv->mtu); 510 /* Initialize burst functions to prevent crashes before link-up. */ 511 eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; 512 eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; 513 eth_dev->dev_ops = &mlx5_dev_ops; 514 eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status; 515 eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status; 516 eth_dev->rx_queue_count = mlx5_rx_queue_count; 517 /* Register MAC address. */ 518 claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0)); 519 priv->ctrl_flows = 0; 520 TAILQ_INIT(&priv->flow_meters); 521 priv->mtr_profile_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_PTR); 522 if (!priv->mtr_profile_tbl) 523 goto error; 524 /* Bring Ethernet device up. */ 525 DRV_LOG(DEBUG, "port %u forcing Ethernet interface up.", 526 eth_dev->data->port_id); 527 /* nl calls are unsupported - set to -1 not to fail on release */ 528 priv->nl_socket_rdma = -1; 529 priv->nl_socket_route = -1; 530 mlx5_set_link_up(eth_dev); 531 /* 532 * Even though the interrupt handler is not installed yet, 533 * interrupts will still trigger on the async_fd from 534 * Verbs context returned by ibv_open_device(). 535 */ 536 mlx5_link_update(eth_dev, 0); 537 for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) { 538 icfg[i].release_mem_en = !!sh->config.reclaim_mode; 539 if (sh->config.reclaim_mode) 540 icfg[i].per_core_cache = 0; 541 priv->flows[i] = mlx5_ipool_create(&icfg[i]); 542 if (!priv->flows[i]) 543 goto error; 544 } 545 /* Create context for virtual machine VLAN workaround. */ 546 priv->vmwa_context = NULL; 547 if (sh->config.dv_flow_en) { 548 err = mlx5_alloc_shared_dr(priv); 549 if (err) 550 goto error; 551 } 552 /* No supported flow priority number detection. */ 553 priv->sh->flow_max_priority = -1; 554 mlx5_set_metadata_mask(eth_dev); 555 if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY && 556 !priv->sh->dv_regc0_mask) { 557 DRV_LOG(ERR, "metadata mode %u is not supported " 558 "(no metadata reg_c[0] is available).", 559 sh->config.dv_xmeta_en); 560 err = ENOTSUP; 561 goto error; 562 } 563 priv->hrxqs = mlx5_list_create("hrxq", eth_dev, true, 564 mlx5_hrxq_create_cb, mlx5_hrxq_match_cb, 565 mlx5_hrxq_remove_cb, mlx5_hrxq_clone_cb, 566 mlx5_hrxq_clone_free_cb); 567 /* Query availability of metadata reg_c's. */ 568 if (!priv->sh->metadata_regc_check_flag) { 569 err = mlx5_flow_discover_mreg_c(eth_dev); 570 if (err < 0) { 571 err = -err; 572 goto error; 573 } 574 } 575 if (!mlx5_flow_ext_mreg_supported(eth_dev)) { 576 DRV_LOG(DEBUG, 577 "port %u extensive metadata register is not supported.", 578 eth_dev->data->port_id); 579 if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) { 580 DRV_LOG(ERR, "metadata mode %u is not supported " 581 "(no metadata registers available).", 582 sh->config.dv_xmeta_en); 583 err = ENOTSUP; 584 goto error; 585 } 586 } 587 if (sh->cdev->config.devx) { 588 priv->obj_ops = devx_obj_ops; 589 } else { 590 DRV_LOG(ERR, "Windows flow must be DevX."); 591 err = ENOTSUP; 592 goto error; 593 } 594 mlx5_flow_counter_mode_config(eth_dev); 595 mlx5_queue_counter_id_prepare(eth_dev); 596 return eth_dev; 597 error: 598 if (priv) { 599 if (priv->mtr_profile_tbl) 600 mlx5_l3t_destroy(priv->mtr_profile_tbl); 601 if (own_domain_id) 602 claim_zero(rte_eth_switch_domain_free(priv->domain_id)); 603 mlx5_free(priv); 604 if (eth_dev != NULL) 605 eth_dev->data->dev_private = NULL; 606 } 607 if (eth_dev != NULL) { 608 /* mac_addrs must not be freed alone because part of 609 * dev_private 610 **/ 611 eth_dev->data->mac_addrs = NULL; 612 rte_eth_dev_release_port(eth_dev); 613 } 614 if (sh) 615 mlx5_free_shared_dev_ctx(sh); 616 MLX5_ASSERT(err > 0); 617 rte_errno = err; 618 return NULL; 619 } 620 621 /** 622 * This function should share events between multiple ports of single IB 623 * device. Currently it has no support under Windows. 624 * 625 * @param sh 626 * Pointer to mlx5_dev_ctx_shared object. 627 */ 628 void 629 mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh) 630 { 631 (void)sh; 632 DRV_LOG(WARNING, "%s: is not supported", __func__); 633 } 634 635 /** 636 * This function should share events between multiple ports of single IB 637 * device. Currently it has no support under Windows. 638 * 639 * @param dev 640 * Pointer to mlx5_dev_ctx_shared object. 641 */ 642 void 643 mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh) 644 { 645 (void)sh; 646 DRV_LOG(WARNING, "%s: is not supported", __func__); 647 } 648 649 /** 650 * Read statistics by a named counter. 651 * 652 * @param[in] priv 653 * Pointer to the private device data structure. 654 * @param[in] ctr_name 655 * Pointer to the name of the statistic counter to read 656 * @param[out] stat 657 * Pointer to read statistic value. 658 * @return 659 * 0 on success and stat is valid, non-zero if failed to read the value 660 * or counter is not supported. 661 * rte_errno is set. 662 * 663 */ 664 int 665 mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, 666 uint64_t *stat) 667 { 668 if (priv->q_counters != NULL && strcmp(ctr_name, "out_of_buffer") == 0) 669 return mlx5_devx_cmd_queue_counter_query 670 (priv->q_counters, 0, (uint32_t *)stat); 671 DRV_LOG(WARNING, "%s: is not supported for the %s counter", 672 __func__, ctr_name); 673 return -ENOTSUP; 674 } 675 676 /** 677 * Flush device MAC addresses 678 * Currently it has no support under Windows. 679 * 680 * @param dev 681 * Pointer to Ethernet device structure. 682 * 683 */ 684 void 685 mlx5_os_mac_addr_flush(struct rte_eth_dev *dev) 686 { 687 (void)dev; 688 DRV_LOG(WARNING, "%s: is not supported", __func__); 689 } 690 691 /** 692 * Remove a MAC address from device 693 * Currently it has no support under Windows. 694 * 695 * @param dev 696 * Pointer to Ethernet device structure. 697 * @param index 698 * MAC address index. 699 */ 700 void 701 mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 702 { 703 (void)dev; 704 (void)(index); 705 DRV_LOG(WARNING, "%s: is not supported", __func__); 706 } 707 708 /** 709 * Adds a MAC address to the device 710 * Currently it has no support under Windows. 711 * 712 * @param dev 713 * Pointer to Ethernet device structure. 714 * @param mac_addr 715 * MAC address to register. 716 * @param index 717 * MAC address index. 718 * 719 * @return 720 * 0 on success, a negative errno value otherwise 721 */ 722 int 723 mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 724 uint32_t index) 725 { 726 (void)index; 727 struct rte_ether_addr lmac; 728 729 if (mlx5_get_mac(dev, &lmac.addr_bytes)) { 730 DRV_LOG(ERR, 731 "port %u cannot get MAC address, is mlx5_en" 732 " loaded? (errno: %s)", 733 dev->data->port_id, strerror(rte_errno)); 734 return rte_errno; 735 } 736 if (!rte_is_same_ether_addr(&lmac, mac)) { 737 DRV_LOG(ERR, 738 "adding new mac address to device is unsupported"); 739 return -ENOTSUP; 740 } 741 return 0; 742 } 743 744 /** 745 * Modify a VF MAC address 746 * Currently it has no support under Windows. 747 * 748 * @param priv 749 * Pointer to device private data. 750 * @param mac_addr 751 * MAC address to modify into. 752 * @param iface_idx 753 * Net device interface index 754 * @param vf_index 755 * VF index 756 * 757 * @return 758 * 0 on success, a negative errno value otherwise 759 */ 760 int 761 mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, 762 unsigned int iface_idx, 763 struct rte_ether_addr *mac_addr, 764 int vf_index) 765 { 766 (void)priv; 767 (void)iface_idx; 768 (void)mac_addr; 769 (void)vf_index; 770 DRV_LOG(WARNING, "%s: is not supported", __func__); 771 return -ENOTSUP; 772 } 773 774 /** 775 * Set device promiscuous mode 776 * 777 * @param dev 778 * Pointer to Ethernet device structure. 779 * @param enable 780 * 0 - promiscuous is disabled, otherwise - enabled 781 * 782 * @return 783 * 0 on success, a negative error value otherwise 784 */ 785 int 786 mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable) 787 { 788 struct mlx5_priv *priv = dev->data->dev_private; 789 790 return mlx5_glue->devx_set_promisc_vport(priv->sh->cdev->ctx, ALL_PROMISC, enable); 791 } 792 793 /** 794 * Set device allmulti mode 795 * 796 * @param dev 797 * Pointer to Ethernet device structure. 798 * @param enable 799 * 0 - all multicase is disabled, otherwise - enabled 800 * 801 * @return 802 * 0 on success, a negative error value otherwise 803 */ 804 int 805 mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable) 806 { 807 struct mlx5_priv *priv = dev->data->dev_private; 808 809 return mlx5_glue->devx_set_promisc_vport(priv->sh->cdev->ctx, MC_PROMISC, enable); 810 } 811 812 /** 813 * DPDK callback to register a PCI device. 814 * 815 * This function spawns Ethernet devices out of a given device. 816 * 817 * @param[in] cdev 818 * Pointer to the common device. 819 * @param[in, out] mkvlist 820 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs. 821 * 822 * @return 823 * 0 on success, a negative errno value otherwise and rte_errno is set. 824 */ 825 int 826 mlx5_os_net_probe(struct mlx5_common_device *cdev, 827 struct mlx5_kvargs_ctrl *mkvlist) 828 { 829 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev); 830 struct mlx5_dev_spawn_data spawn = { 831 .pf_bond = -1, 832 .max_port = 1, 833 .phys_port = 1, 834 .phys_dev_name = mlx5_os_get_ctx_device_name(cdev->ctx), 835 .pci_dev = pci_dev, 836 .cdev = cdev, 837 .ifindex = -1, /* Spawn will assign */ 838 .info = (struct mlx5_switch_info){ 839 .name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK, 840 }, 841 }; 842 int ret; 843 uint32_t restore; 844 845 if (rte_eal_process_type() == RTE_PROC_SECONDARY) { 846 DRV_LOG(ERR, "Secondary process is not supported on Windows."); 847 return -ENOTSUP; 848 } 849 ret = mlx5_init_once(); 850 if (ret) { 851 DRV_LOG(ERR, "unable to init PMD global data: %s", 852 strerror(rte_errno)); 853 return -rte_errno; 854 } 855 spawn.eth_dev = mlx5_dev_spawn(cdev->dev, &spawn, mkvlist); 856 if (!spawn.eth_dev) 857 return -rte_errno; 858 restore = spawn.eth_dev->data->dev_flags; 859 rte_eth_copy_pci_info(spawn.eth_dev, pci_dev); 860 /* Restore non-PCI flags cleared by the above call. */ 861 spawn.eth_dev->data->dev_flags |= restore; 862 rte_eth_dev_probing_finish(spawn.eth_dev); 863 return 0; 864 } 865 866 /** 867 * Cleanup resources when the last device is closed. 868 */ 869 void 870 mlx5_os_net_cleanup(void) 871 { 872 } 873 874 const struct mlx5_flow_driver_ops mlx5_flow_verbs_drv_ops = {0}; 875