1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2020 Mellanox Technologies Ltd. */
4 #ifndef __MLX5_VDPA_H__
5 #define __MLX5_VDPA_H__
7 #include <linux/etherdevice.h>
8 #include <linux/vdpa.h>
9 #include <linux/mlx5/driver.h>
11 #define MLX5V_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
13 struct mlx5_vdpa_direct_mr {
17 struct mlx5_core_mkey mr;
18 struct sg_table sg_head;
22 struct list_head list;
27 struct mlx5_core_mkey mkey;
29 /* list of direct MRs descendants of this indirect mr */
30 struct list_head head;
31 unsigned long num_directs;
32 unsigned long num_klms;
35 /* serialize mkey creation and destruction */
36 struct mutex mkey_mtx;
40 struct mlx5_vdpa_resources {
42 struct mlx5_uars_page *uar;
43 void __iomem *kick_addr;
50 struct mlx5_vdpa_dev {
51 struct vdpa_device vdev;
52 struct mlx5_core_dev *mdev;
53 struct mlx5_vdpa_resources res;
62 struct mlx5_vdpa_mr mr;
65 int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid);
66 int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid);
67 int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey);
68 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn);
69 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn);
70 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
71 void mlx5_vdpa_destroy_rqt(struct mlx5_vdpa_dev *mvdev, u32 rqtn);
72 int mlx5_vdpa_create_tir(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tirn);
73 void mlx5_vdpa_destroy_tir(struct mlx5_vdpa_dev *mvdev, u32 tirn);
74 int mlx5_vdpa_alloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 *tdn);
75 void mlx5_vdpa_dealloc_transport_domain(struct mlx5_vdpa_dev *mvdev, u32 tdn);
76 int mlx5_vdpa_alloc_resources(struct mlx5_vdpa_dev *mvdev);
77 void mlx5_vdpa_free_resources(struct mlx5_vdpa_dev *mvdev);
78 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey, u32 *in,
80 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, struct mlx5_core_mkey *mkey);
81 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
83 int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
84 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
86 #define mlx5_vdpa_warn(__dev, format, ...) \
87 dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
88 current->pid, ##__VA_ARGS__)
90 #define mlx5_vdpa_info(__dev, format, ...) \
91 dev_info((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
92 current->pid, ##__VA_ARGS__)
94 #define mlx5_vdpa_dbg(__dev, format, ...) \
95 dev_debug((__dev)->mdev->device, "%s:%d:(pid %d): " format, __func__, __LINE__, \
96 current->pid, ##__VA_ARGS__)
98 #endif /* __MLX5_VDPA_H__ */