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