1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2019 Mellanox Technologies, Ltd
6 #include <sys/socket.h>
9 #include <netinet/in.h>
11 #include <rte_malloc.h>
13 #include <rte_errno.h>
15 #include <rte_string_fns.h>
17 #include <mlx5_glue.h>
18 #include <mlx5_common.h>
19 #include <mlx5_common_pci.h>
20 #include <mlx5_devx_cmds.h>
24 #include "mlx5_vdpa_utils.h"
25 #include "mlx5_vdpa.h"
27 #define MLX5_VDPA_DRIVER_NAME vdpa_mlx5
29 #define MLX5_VDPA_DEFAULT_FEATURES ((1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
30 (1ULL << VIRTIO_F_ANY_LAYOUT) | \
31 (1ULL << VIRTIO_NET_F_MQ) | \
32 (1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
33 (1ULL << VIRTIO_F_ORDER_PLATFORM) | \
34 (1ULL << VHOST_F_LOG_ALL) | \
35 (1ULL << VIRTIO_NET_F_MTU))
37 #define MLX5_VDPA_PROTOCOL_FEATURES \
38 ((1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
39 (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \
40 (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \
41 (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) | \
42 (1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
43 (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU) | \
44 (1ULL << VHOST_USER_PROTOCOL_F_STATUS))
46 #define MLX5_VDPA_MAX_RETRIES 20
47 #define MLX5_VDPA_USEC 1000
48 #define MLX5_VDPA_DEFAULT_NO_TRAFFIC_MAX 16LLU
50 TAILQ_HEAD(mlx5_vdpa_privs, mlx5_vdpa_priv) priv_list =
51 TAILQ_HEAD_INITIALIZER(priv_list);
52 static pthread_mutex_t priv_list_lock = PTHREAD_MUTEX_INITIALIZER;
54 static struct mlx5_vdpa_priv *
55 mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev)
57 struct mlx5_vdpa_priv *priv;
60 pthread_mutex_lock(&priv_list_lock);
61 TAILQ_FOREACH(priv, &priv_list, next) {
62 if (vdev == priv->vdev) {
67 pthread_mutex_unlock(&priv_list_lock);
69 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
77 mlx5_vdpa_get_queue_num(struct rte_vdpa_device *vdev, uint32_t *queue_num)
79 struct mlx5_vdpa_priv *priv =
80 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
83 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
86 *queue_num = priv->caps.max_num_virtio_queues;
91 mlx5_vdpa_get_vdpa_features(struct rte_vdpa_device *vdev, uint64_t *features)
93 struct mlx5_vdpa_priv *priv =
94 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
97 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
100 *features = MLX5_VDPA_DEFAULT_FEATURES;
101 if (priv->caps.virtio_queue_type & (1 << MLX5_VIRTQ_TYPE_PACKED))
102 *features |= (1ULL << VIRTIO_F_RING_PACKED);
103 if (priv->caps.tso_ipv4)
104 *features |= (1ULL << VIRTIO_NET_F_HOST_TSO4);
105 if (priv->caps.tso_ipv6)
106 *features |= (1ULL << VIRTIO_NET_F_HOST_TSO6);
107 if (priv->caps.tx_csum)
108 *features |= (1ULL << VIRTIO_NET_F_CSUM);
109 if (priv->caps.rx_csum)
110 *features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
111 if (priv->caps.virtio_version_1_0)
112 *features |= (1ULL << VIRTIO_F_VERSION_1);
117 mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev,
120 struct mlx5_vdpa_priv *priv =
121 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
124 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
127 *features = MLX5_VDPA_PROTOCOL_FEATURES;
132 mlx5_vdpa_set_vring_state(int vid, int vring, int state)
134 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
135 struct mlx5_vdpa_priv *priv =
136 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
140 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
143 if (vring >= (int)priv->caps.max_num_virtio_queues * 2) {
144 DRV_LOG(ERR, "Too big vring id: %d.", vring);
147 pthread_mutex_lock(&priv->vq_config_lock);
148 ret = mlx5_vdpa_virtq_enable(priv, vring, state);
149 pthread_mutex_unlock(&priv->vq_config_lock);
154 mlx5_vdpa_features_set(int vid)
156 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
157 struct mlx5_vdpa_priv *priv =
158 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
159 uint64_t log_base, log_size;
164 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
167 ret = rte_vhost_get_negotiated_features(vid, &features);
169 DRV_LOG(ERR, "Failed to get negotiated features.");
172 if (RTE_VHOST_NEED_LOG(features)) {
173 ret = rte_vhost_get_log_base(vid, &log_base, &log_size);
175 DRV_LOG(ERR, "Failed to get log base.");
178 ret = mlx5_vdpa_dirty_bitmap_set(priv, log_base, log_size);
180 DRV_LOG(ERR, "Failed to set dirty bitmap.");
183 DRV_LOG(INFO, "mlx5 vdpa: enabling dirty logging...");
184 ret = mlx5_vdpa_logging_enable(priv, 1);
186 DRV_LOG(ERR, "Failed t enable dirty logging.");
194 mlx5_vdpa_pd_create(struct mlx5_vdpa_priv *priv)
196 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
197 priv->pd = mlx5_glue->alloc_pd(priv->ctx);
198 if (priv->pd == NULL) {
199 DRV_LOG(ERR, "Failed to allocate PD.");
200 return errno ? -errno : -ENOMEM;
202 struct mlx5dv_obj obj;
203 struct mlx5dv_pd pd_info;
206 obj.pd.in = priv->pd;
207 obj.pd.out = &pd_info;
208 ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD);
210 DRV_LOG(ERR, "Fail to get PD object info.");
211 mlx5_glue->dealloc_pd(priv->pd);
215 priv->pdn = pd_info.pdn;
219 DRV_LOG(ERR, "Cannot get pdn - no DV support.");
221 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
225 mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv)
227 struct ifreq request;
228 uint16_t vhost_mtu = 0;
229 uint16_t kern_mtu = 0;
230 int ret = rte_vhost_get_mtu(priv->vid, &vhost_mtu);
232 int retries = MLX5_VDPA_MAX_RETRIES;
235 DRV_LOG(DEBUG, "Cannot get vhost MTU - %d.", ret);
239 DRV_LOG(DEBUG, "Vhost MTU is 0.");
242 ret = mlx5_get_ifname_sysfs(priv->ctx->device->ibdev_path,
245 DRV_LOG(DEBUG, "Cannot get kernel IF name - %d.", ret);
248 sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
250 DRV_LOG(DEBUG, "Cannot open IF socket.");
254 ret = ioctl(sock, SIOCGIFMTU, &request);
257 kern_mtu = request.ifr_mtu;
258 DRV_LOG(DEBUG, "MTU: current %d requested %d.", (int)kern_mtu,
260 if (kern_mtu == vhost_mtu)
262 request.ifr_mtu = vhost_mtu;
263 ret = ioctl(sock, SIOCSIFMTU, &request);
267 usleep(MLX5_VDPA_USEC);
270 return kern_mtu == vhost_mtu ? 0 : -1;
274 mlx5_vdpa_dev_close(int vid)
276 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
277 struct mlx5_vdpa_priv *priv =
278 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
282 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
285 if (priv->configured)
286 ret |= mlx5_vdpa_lm_log(priv);
287 mlx5_vdpa_err_event_unset(priv);
288 mlx5_vdpa_cqe_event_unset(priv);
289 mlx5_vdpa_steer_unset(priv);
290 mlx5_vdpa_virtqs_release(priv);
291 mlx5_vdpa_event_qp_global_release(priv);
292 mlx5_vdpa_mem_dereg(priv);
294 claim_zero(mlx5_glue->dealloc_pd(priv->pd));
297 priv->configured = 0;
299 /* The mutex may stay locked after event thread cancel - initiate it. */
300 pthread_mutex_init(&priv->vq_config_lock, NULL);
301 DRV_LOG(INFO, "vDPA device %d was closed.", vid);
306 mlx5_vdpa_dev_config(int vid)
308 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
309 struct mlx5_vdpa_priv *priv =
310 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
313 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
316 if (priv->configured && mlx5_vdpa_dev_close(vid)) {
317 DRV_LOG(ERR, "Failed to reconfigure vid %d.", vid);
321 if (mlx5_vdpa_mtu_set(priv))
322 DRV_LOG(WARNING, "MTU cannot be set on device %s.",
324 if (mlx5_vdpa_pd_create(priv) || mlx5_vdpa_mem_register(priv) ||
325 mlx5_vdpa_err_event_setup(priv) ||
326 mlx5_vdpa_virtqs_prepare(priv) || mlx5_vdpa_steer_setup(priv) ||
327 mlx5_vdpa_cqe_event_setup(priv)) {
328 mlx5_vdpa_dev_close(vid);
331 priv->configured = 1;
332 DRV_LOG(INFO, "vDPA device %d was configured.", vid);
337 mlx5_vdpa_get_device_fd(int vid)
339 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
340 struct mlx5_vdpa_priv *priv =
341 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
344 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
347 return priv->ctx->cmd_fd;
351 mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
353 struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid);
354 struct mlx5_vdpa_priv *priv =
355 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
359 DRV_LOG(ERR, "Invalid vDPA device: %s.", vdev->device->name);
363 DRV_LOG(ERR, "VAR was not created for device %s, is the device"
364 " configured?.", vdev->device->name);
367 *offset = priv->var->mmap_off;
368 *size = priv->var->length;
373 mlx5_vdpa_get_stats_names(struct rte_vdpa_device *vdev,
374 struct rte_vdpa_stat_name *stats_names,
377 static const char *mlx5_vdpa_stats_names[MLX5_VDPA_STATS_MAX] = {
378 "received_descriptors",
379 "completed_descriptors",
380 "bad descriptor errors",
385 struct mlx5_vdpa_priv *priv =
386 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
390 DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
394 return MLX5_VDPA_STATS_MAX;
395 size = RTE_MIN(size, (unsigned int)MLX5_VDPA_STATS_MAX);
396 for (i = 0; i < size; ++i)
397 strlcpy(stats_names[i].name, mlx5_vdpa_stats_names[i],
398 RTE_VDPA_STATS_NAME_SIZE);
403 mlx5_vdpa_get_stats(struct rte_vdpa_device *vdev, int qid,
404 struct rte_vdpa_stat *stats, unsigned int n)
406 struct mlx5_vdpa_priv *priv =
407 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
410 DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
413 if (!priv->configured) {
414 DRV_LOG(ERR, "Device %s was not configured.",
418 if (qid >= (int)priv->nr_virtqs) {
419 DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid,
423 if (!priv->caps.queue_counters_valid) {
424 DRV_LOG(ERR, "Virtq statistics is not supported for device %s.",
428 return mlx5_vdpa_virtq_stats_get(priv, qid, stats, n);
432 mlx5_vdpa_reset_stats(struct rte_vdpa_device *vdev, int qid)
434 struct mlx5_vdpa_priv *priv =
435 mlx5_vdpa_find_priv_resource_by_vdev(vdev);
438 DRV_LOG(ERR, "Invalid device: %s.", vdev->device->name);
441 if (!priv->configured) {
442 DRV_LOG(ERR, "Device %s was not configured.",
446 if (qid >= (int)priv->nr_virtqs) {
447 DRV_LOG(ERR, "Too big vring id: %d for device %s.", qid,
451 if (!priv->caps.queue_counters_valid) {
452 DRV_LOG(ERR, "Virtq statistics is not supported for device %s.",
456 return mlx5_vdpa_virtq_stats_reset(priv, qid);
459 static struct rte_vdpa_dev_ops mlx5_vdpa_ops = {
460 .get_queue_num = mlx5_vdpa_get_queue_num,
461 .get_features = mlx5_vdpa_get_vdpa_features,
462 .get_protocol_features = mlx5_vdpa_get_protocol_features,
463 .dev_conf = mlx5_vdpa_dev_config,
464 .dev_close = mlx5_vdpa_dev_close,
465 .set_vring_state = mlx5_vdpa_set_vring_state,
466 .set_features = mlx5_vdpa_features_set,
467 .migration_done = NULL,
468 .get_vfio_group_fd = NULL,
469 .get_vfio_device_fd = mlx5_vdpa_get_device_fd,
470 .get_notify_area = mlx5_vdpa_get_notify_area,
471 .get_stats_names = mlx5_vdpa_get_stats_names,
472 .get_stats = mlx5_vdpa_get_stats,
473 .reset_stats = mlx5_vdpa_reset_stats,
476 /* Try to disable ROCE by Netlink\Devlink. */
478 mlx5_vdpa_nl_roce_disable(const char *addr)
480 int nlsk_fd = mlx5_nl_init(NETLINK_GENERIC);
487 devlink_id = mlx5_nl_devlink_family_id_get(nlsk_fd);
488 if (devlink_id < 0) {
490 DRV_LOG(DEBUG, "Failed to get devlink id for ROCE operations by"
494 ret = mlx5_nl_enable_roce_get(nlsk_fd, devlink_id, addr, &enable);
496 DRV_LOG(DEBUG, "Failed to get ROCE enable by Netlink: %d.",
499 } else if (!enable) {
500 DRV_LOG(INFO, "ROCE has already disabled(Netlink).");
503 ret = mlx5_nl_enable_roce_set(nlsk_fd, devlink_id, addr, 0);
505 DRV_LOG(DEBUG, "Failed to disable ROCE by Netlink: %d.", ret);
507 DRV_LOG(INFO, "ROCE is disabled by Netlink successfully.");
513 /* Try to disable ROCE by sysfs. */
515 mlx5_vdpa_sys_roce_disable(const char *addr)
521 MKSTR(file_p, "/sys/bus/pci/devices/%s/roce_enable", addr);
522 file_o = fopen(file_p, "rb");
527 ret = fscanf(file_o, "%d", &enable);
532 } else if (!enable) {
534 DRV_LOG(INFO, "ROCE has already disabled(sysfs).");
538 file_o = fopen(file_p, "wb");
543 fprintf(file_o, "0\n");
547 DRV_LOG(DEBUG, "Failed to disable ROCE by sysfs: %d.", ret);
549 DRV_LOG(INFO, "ROCE is disabled by sysfs successfully.");
555 mlx5_vdpa_roce_disable(struct rte_pci_addr *addr, struct ibv_device **ibv)
557 char addr_name[64] = {0};
559 rte_pci_device_name(addr, addr_name, sizeof(addr_name));
560 /* Firstly try to disable ROCE by Netlink and fallback to sysfs. */
561 if (mlx5_vdpa_nl_roce_disable(addr_name) == 0 ||
562 mlx5_vdpa_sys_roce_disable(addr_name) == 0) {
564 * Succeed to disable ROCE, wait for the IB device to appear
565 * again after reload.
568 struct ibv_device *ibv_new;
570 for (r = MLX5_VDPA_MAX_RETRIES; r; r--) {
571 ibv_new = mlx5_os_get_ibv_device(addr);
576 usleep(MLX5_VDPA_USEC);
578 DRV_LOG(ERR, "Cannot much device %s after ROCE disable, "
579 "retries exceed %d", addr_name, MLX5_VDPA_MAX_RETRIES);
586 mlx5_vdpa_args_check_handler(const char *key, const char *val, void *opaque)
588 struct mlx5_vdpa_priv *priv = opaque;
590 int n_cores = sysconf(_SC_NPROCESSORS_ONLN);
592 if (strcmp(key, RTE_DEVARGS_KEY_CLASS) == 0)
595 tmp = strtoul(val, NULL, 0);
597 DRV_LOG(WARNING, "%s: \"%s\" is an invalid integer.", key, val);
600 if (strcmp(key, "event_mode") == 0) {
601 if (tmp <= MLX5_VDPA_EVENT_MODE_ONLY_INTERRUPT)
602 priv->event_mode = (int)tmp;
604 DRV_LOG(WARNING, "Invalid event_mode %s.", val);
605 } else if (strcmp(key, "event_us") == 0) {
606 priv->event_us = (uint32_t)tmp;
607 } else if (strcmp(key, "no_traffic_time") == 0) {
608 priv->no_traffic_max = (uint32_t)tmp;
609 } else if (strcmp(key, "event_core") == 0) {
610 if (tmp >= (unsigned long)n_cores)
611 DRV_LOG(WARNING, "Invalid event_core %s.", val);
613 priv->event_core = tmp;
614 } else if (strcmp(key, "hw_latency_mode") == 0) {
615 priv->hw_latency_mode = (uint32_t)tmp;
616 } else if (strcmp(key, "hw_max_latency_us") == 0) {
617 priv->hw_max_latency_us = (uint32_t)tmp;
618 } else if (strcmp(key, "hw_max_pending_comp") == 0) {
619 priv->hw_max_pending_comp = (uint32_t)tmp;
621 DRV_LOG(WARNING, "Invalid key %s.", key);
627 mlx5_vdpa_config_get(struct rte_devargs *devargs, struct mlx5_vdpa_priv *priv)
629 struct rte_kvargs *kvlist;
631 priv->event_mode = MLX5_VDPA_EVENT_MODE_FIXED_TIMER;
633 priv->event_core = -1;
634 priv->no_traffic_max = MLX5_VDPA_DEFAULT_NO_TRAFFIC_MAX;
637 kvlist = rte_kvargs_parse(devargs->args, NULL);
640 rte_kvargs_process(kvlist, NULL, mlx5_vdpa_args_check_handler, priv);
641 rte_kvargs_free(kvlist);
642 if (!priv->event_us &&
643 priv->event_mode == MLX5_VDPA_EVENT_MODE_DYNAMIC_TIMER)
644 priv->event_us = MLX5_VDPA_DEFAULT_TIMER_STEP_US;
645 DRV_LOG(DEBUG, "event mode is %d.", priv->event_mode);
646 DRV_LOG(DEBUG, "event_us is %u us.", priv->event_us);
647 DRV_LOG(DEBUG, "no traffic max is %u.", priv->no_traffic_max);
651 * DPDK callback to register a mlx5 PCI device.
653 * This function spawns vdpa device out of a given PCI device.
656 * PCI driver structure (mlx5_vpda_driver).
658 * PCI device information.
661 * 0 on success, 1 to skip this driver, a negative errno value otherwise
662 * and rte_errno is set.
665 mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
666 struct rte_pci_device *pci_dev __rte_unused)
668 struct ibv_device *ibv;
669 struct mlx5_vdpa_priv *priv = NULL;
670 struct ibv_context *ctx = NULL;
671 struct mlx5_hca_attr attr;
674 ibv = mlx5_os_get_ibv_device(&pci_dev->addr);
676 DRV_LOG(ERR, "No matching IB device for PCI slot "
677 PCI_PRI_FMT ".", pci_dev->addr.domain,
678 pci_dev->addr.bus, pci_dev->addr.devid,
679 pci_dev->addr.function);
682 DRV_LOG(INFO, "PCI information matches for device \"%s\".",
685 if (mlx5_vdpa_roce_disable(&pci_dev->addr, &ibv) != 0) {
686 DRV_LOG(WARNING, "Failed to disable ROCE for \"%s\".",
690 ctx = mlx5_glue->dv_open_device(ibv);
692 DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name);
696 ret = mlx5_devx_cmd_query_hca_attr(ctx, &attr);
698 DRV_LOG(ERR, "Unable to read HCA capabilities.");
701 } else if (!attr.vdpa.valid || !attr.vdpa.max_num_virtio_queues) {
702 DRV_LOG(ERR, "Not enough capabilities to support vdpa, maybe "
703 "old FW/OFED version?");
707 if (!attr.vdpa.queue_counters_valid)
708 DRV_LOG(DEBUG, "No capability to support virtq statistics.");
709 priv = rte_zmalloc("mlx5 vDPA device private", sizeof(*priv) +
710 sizeof(struct mlx5_vdpa_virtq) *
711 attr.vdpa.max_num_virtio_queues * 2,
712 RTE_CACHE_LINE_SIZE);
714 DRV_LOG(ERR, "Failed to allocate private memory.");
718 priv->caps = attr.vdpa;
719 priv->log_max_rqt_size = attr.log_max_rqt_size;
720 priv->num_lag_ports = attr.num_lag_ports;
721 priv->qp_ts_format = attr.qp_ts_format;
722 if (attr.num_lag_ports == 0)
723 priv->num_lag_ports = 1;
725 priv->pci_dev = pci_dev;
726 priv->var = mlx5_glue->dv_alloc_var(ctx, 0);
728 DRV_LOG(ERR, "Failed to allocate VAR %u.", errno);
731 priv->vdev = rte_vdpa_register_device(&pci_dev->device,
733 if (priv->vdev == NULL) {
734 DRV_LOG(ERR, "Failed to register vDPA device.");
735 rte_errno = rte_errno ? rte_errno : EINVAL;
738 mlx5_vdpa_config_get(pci_dev->device.devargs, priv);
739 SLIST_INIT(&priv->mr_list);
740 pthread_mutex_init(&priv->vq_config_lock, NULL);
741 pthread_mutex_lock(&priv_list_lock);
742 TAILQ_INSERT_TAIL(&priv_list, priv, next);
743 pthread_mutex_unlock(&priv_list_lock);
749 mlx5_glue->dv_free_var(priv->var);
753 mlx5_glue->close_device(ctx);
758 * DPDK callback to remove a PCI device.
760 * This function removes all vDPA devices belong to a given PCI device.
763 * Pointer to the PCI device.
766 * 0 on success, the function cannot fail.
769 mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev)
771 struct mlx5_vdpa_priv *priv = NULL;
774 pthread_mutex_lock(&priv_list_lock);
775 TAILQ_FOREACH(priv, &priv_list, next) {
776 if (!rte_pci_addr_cmp(&priv->pci_dev->addr, &pci_dev->addr)) {
782 TAILQ_REMOVE(&priv_list, priv, next);
783 pthread_mutex_unlock(&priv_list_lock);
785 if (priv->configured)
786 mlx5_vdpa_dev_close(priv->vid);
788 mlx5_glue->dv_free_var(priv->var);
792 rte_vdpa_unregister_device(priv->vdev);
793 mlx5_glue->close_device(priv->ctx);
794 pthread_mutex_destroy(&priv->vq_config_lock);
800 static const struct rte_pci_id mlx5_vdpa_pci_id_map[] = {
802 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
803 PCI_DEVICE_ID_MELLANOX_CONNECTX6)
806 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
807 PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
810 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
811 PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
814 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
815 PCI_DEVICE_ID_MELLANOX_CONNECTXVF)
818 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
819 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
822 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
823 PCI_DEVICE_ID_MELLANOX_CONNECTX7)
826 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
827 PCI_DEVICE_ID_MELLANOX_CONNECTX7BF)
834 static struct mlx5_pci_driver mlx5_vdpa_driver = {
835 .driver_class = MLX5_CLASS_VDPA,
838 .name = RTE_STR(MLX5_VDPA_DRIVER_NAME),
840 .id_table = mlx5_vdpa_pci_id_map,
841 .probe = mlx5_vdpa_pci_probe,
842 .remove = mlx5_vdpa_pci_remove,
847 RTE_LOG_REGISTER_DEFAULT(mlx5_vdpa_logtype, NOTICE)
850 * Driver initialization routine.
852 RTE_INIT(rte_mlx5_vdpa_init)
856 mlx5_pci_driver_register(&mlx5_vdpa_driver);
859 RTE_PMD_EXPORT_NAME(MLX5_VDPA_DRIVER_NAME, __COUNTER__);
860 RTE_PMD_REGISTER_PCI_TABLE(MLX5_VDPA_DRIVER_NAME, mlx5_vdpa_pci_id_map);
861 RTE_PMD_REGISTER_KMOD_DEP(MLX5_VDPA_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");