xref: /linux/drivers/infiniband/hw/mana/mana_ib.h (revision 2672031b20f6681514bef14ddcfe8c62c2757d11)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2022 Microsoft Corporation. All rights reserved.
4  */
5 
6 #ifndef _MANA_IB_H_
7 #define _MANA_IB_H_
8 
9 #include <rdma/ib_verbs.h>
10 #include <rdma/ib_mad.h>
11 #include <rdma/ib_umem.h>
12 #include <rdma/mana-abi.h>
13 #include <rdma/uverbs_ioctl.h>
14 
15 #include <net/mana/mana.h>
16 
17 #define PAGE_SZ_BM                                                             \
18 	(SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K |        \
19 	 SZ_512K | SZ_1M | SZ_2M)
20 
21 /* MANA doesn't have any limit for MR size */
22 #define MANA_IB_MAX_MR_SIZE	U64_MAX
23 
24 /*
25  * The hardware limit of number of MRs is greater than maximum number of MRs
26  * that can possibly represent in 24 bits
27  */
28 #define MANA_IB_MAX_MR		0xFFFFFFu
29 
30 struct mana_ib_adapter_caps {
31 	u32 max_sq_id;
32 	u32 max_rq_id;
33 	u32 max_cq_id;
34 	u32 max_qp_count;
35 	u32 max_cq_count;
36 	u32 max_mr_count;
37 	u32 max_pd_count;
38 	u32 max_inbound_read_limit;
39 	u32 max_outbound_read_limit;
40 	u32 mw_count;
41 	u32 max_srq_count;
42 	u32 max_qp_wr;
43 	u32 max_send_sge_count;
44 	u32 max_recv_sge_count;
45 	u32 max_inline_data_size;
46 };
47 
48 struct mana_ib_dev {
49 	struct ib_device ib_dev;
50 	struct gdma_dev *gdma_dev;
51 	struct mana_ib_adapter_caps adapter_caps;
52 };
53 
54 struct mana_ib_wq {
55 	struct ib_wq ibwq;
56 	struct ib_umem *umem;
57 	int wqe;
58 	u32 wq_buf_size;
59 	u64 gdma_region;
60 	u64 id;
61 	mana_handle_t rx_object;
62 };
63 
64 struct mana_ib_pd {
65 	struct ib_pd ibpd;
66 	u32 pdn;
67 	mana_handle_t pd_handle;
68 
69 	/* Mutex for sharing access to vport_use_count */
70 	struct mutex vport_mutex;
71 	int vport_use_count;
72 
73 	bool tx_shortform_allowed;
74 	u32 tx_vp_offset;
75 };
76 
77 struct mana_ib_mr {
78 	struct ib_mr ibmr;
79 	struct ib_umem *umem;
80 	mana_handle_t mr_handle;
81 };
82 
83 struct mana_ib_cq {
84 	struct ib_cq ibcq;
85 	struct ib_umem *umem;
86 	int cqe;
87 	u64 gdma_region;
88 	u64 id;
89 	u32 comp_vector;
90 };
91 
92 struct mana_ib_qp {
93 	struct ib_qp ibqp;
94 
95 	/* Work queue info */
96 	struct ib_umem *sq_umem;
97 	int sqe;
98 	u64 sq_gdma_region;
99 	u64 sq_id;
100 	mana_handle_t tx_object;
101 
102 	/* The port on the IB device, starting with 1 */
103 	u32 port;
104 };
105 
106 struct mana_ib_ucontext {
107 	struct ib_ucontext ibucontext;
108 	u32 doorbell;
109 };
110 
111 struct mana_ib_rwq_ind_table {
112 	struct ib_rwq_ind_table ib_ind_table;
113 };
114 
115 enum mana_ib_command_code {
116 	MANA_IB_GET_ADAPTER_CAP = 0x30001,
117 };
118 
119 struct mana_ib_query_adapter_caps_req {
120 	struct gdma_req_hdr hdr;
121 }; /*HW Data */
122 
123 struct mana_ib_query_adapter_caps_resp {
124 	struct gdma_resp_hdr hdr;
125 	u32 max_sq_id;
126 	u32 max_rq_id;
127 	u32 max_cq_id;
128 	u32 max_qp_count;
129 	u32 max_cq_count;
130 	u32 max_mr_count;
131 	u32 max_pd_count;
132 	u32 max_inbound_read_limit;
133 	u32 max_outbound_read_limit;
134 	u32 mw_count;
135 	u32 max_srq_count;
136 	u32 max_requester_sq_size;
137 	u32 max_responder_sq_size;
138 	u32 max_requester_rq_size;
139 	u32 max_responder_rq_size;
140 	u32 max_send_sge_count;
141 	u32 max_recv_sge_count;
142 	u32 max_inline_data_size;
143 }; /* HW Data */
144 
145 int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
146 				 mana_handle_t *gdma_region);
147 
148 int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev,
149 				  mana_handle_t gdma_region);
150 
151 struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
152 				struct ib_wq_init_attr *init_attr,
153 				struct ib_udata *udata);
154 
155 int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
156 		      u32 wq_attr_mask, struct ib_udata *udata);
157 
158 int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata);
159 
160 int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table,
161 				 struct ib_rwq_ind_table_init_attr *init_attr,
162 				 struct ib_udata *udata);
163 
164 int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl);
165 
166 struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags);
167 
168 struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
169 				  u64 iova, int access_flags,
170 				  struct ib_udata *udata);
171 
172 int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
173 
174 int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr,
175 		      struct ib_udata *udata);
176 
177 int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
178 		      int attr_mask, struct ib_udata *udata);
179 
180 int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
181 
182 int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id,
183 		      struct mana_ib_pd *pd, u32 doorbell_id);
184 void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd,
185 			 u32 port);
186 
187 int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
188 		      struct ib_udata *udata);
189 
190 int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata);
191 
192 int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
193 int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
194 
195 int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext,
196 			   struct ib_udata *udata);
197 void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext);
198 
199 int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma);
200 
201 int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num,
202 			       struct ib_port_immutable *immutable);
203 int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
204 			 struct ib_udata *uhw);
205 int mana_ib_query_port(struct ib_device *ibdev, u32 port,
206 		       struct ib_port_attr *props);
207 int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index,
208 		      union ib_gid *gid);
209 
210 void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);
211 
212 int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev);
213 
214 void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq);
215 #endif
216