1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2020 Mellanox Technologies Ltd. */
4 #include <linux/module.h>
5 #include <linux/mlx5/driver.h>
6 #include <linux/mlx5/device.h>
7 #include "mlx5_vdpa_ifc.h"
10 MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
11 MODULE_DESCRIPTION("Mellanox VDPA driver");
12 MODULE_LICENSE("Dual BSD/GPL");
14 static bool required_caps_supported(struct mlx5_core_dev *mdev)
19 got = MLX5_CAP_GEN_64(mdev, general_obj_types);
21 if (!(got & MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q))
24 event_mode = MLX5_CAP_DEV_VDPA_EMULATION(mdev, event_mode);
25 if (!(event_mode & MLX5_VIRTIO_Q_EVENT_MODE_QP_MODE))
28 if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, eth_frame_offload_type))
34 static void *mlx5_vdpa_add(struct mlx5_core_dev *mdev)
36 struct mlx5_vdpa_dev *vdev;
38 if (mlx5_core_is_pf(mdev))
41 if (!required_caps_supported(mdev)) {
42 dev_info(mdev->device, "virtio net emulation not supported\n");
45 vdev = mlx5_vdpa_add_dev(mdev);
52 static void mlx5_vdpa_remove(struct mlx5_core_dev *mdev, void *context)
54 struct mlx5_vdpa_dev *vdev = context;
56 mlx5_vdpa_remove_dev(vdev);
59 static struct mlx5_interface mlx5_vdpa_interface = {
61 .remove = mlx5_vdpa_remove,
62 .protocol = MLX5_INTERFACE_PROTOCOL_VDPA,
65 static int __init mlx5_vdpa_init(void)
67 return mlx5_register_interface(&mlx5_vdpa_interface);
70 static void __exit mlx5_vdpa_exit(void)
72 mlx5_unregister_interface(&mlx5_vdpa_interface);
75 module_init(mlx5_vdpa_init);
76 module_exit(mlx5_vdpa_exit);