^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Copyright (c) 2020 Mellanox Technologies Ltd. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/mlx5/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/mlx5/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "mlx5_vdpa_ifc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "mlx5_vnet.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) MODULE_DESCRIPTION("Mellanox VDPA driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static bool required_caps_supported(struct mlx5_core_dev *mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) u8 event_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) u64 got;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) got = MLX5_CAP_GEN_64(mdev, general_obj_types);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) if (!(got & MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) event_mode = MLX5_CAP_DEV_VDPA_EMULATION(mdev, event_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (!(event_mode & MLX5_VIRTIO_Q_EVENT_MODE_QP_MODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, eth_frame_offload_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static void *mlx5_vdpa_add(struct mlx5_core_dev *mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct mlx5_vdpa_dev *vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (mlx5_core_is_pf(mdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!required_caps_supported(mdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) dev_info(mdev->device, "virtio net emulation not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) vdev = mlx5_vdpa_add_dev(mdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (IS_ERR(vdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void mlx5_vdpa_remove(struct mlx5_core_dev *mdev, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct mlx5_vdpa_dev *vdev = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mlx5_vdpa_remove_dev(vdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct mlx5_interface mlx5_vdpa_interface = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .add = mlx5_vdpa_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .remove = mlx5_vdpa_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .protocol = MLX5_INTERFACE_PROTOCOL_VDPA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int __init mlx5_vdpa_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return mlx5_register_interface(&mlx5_vdpa_interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static void __exit mlx5_vdpa_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mlx5_unregister_interface(&mlx5_vdpa_interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) module_init(mlx5_vdpa_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) module_exit(mlx5_vdpa_exit);