xref: /linux/drivers/infiniband/hw/efa/efa_com_cmd.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
2 /*
3  * Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
4  */
5 
6 #ifndef _EFA_COM_CMD_H_
7 #define _EFA_COM_CMD_H_
8 
9 #include "efa_com.h"
10 
11 #define EFA_GID_SIZE 16
12 
13 struct efa_com_create_qp_params {
14 	u64 rq_base_addr;
15 	u32 send_cq_idx;
16 	u32 recv_cq_idx;
17 	/*
18 	 * Send descriptor ring size in bytes,
19 	 * sufficient for user-provided number of WQEs and SGL size
20 	 */
21 	u32 sq_ring_size_in_bytes;
22 	/* Max number of WQEs that will be posted on send queue */
23 	u32 sq_depth;
24 	/* Recv descriptor ring size in bytes */
25 	u32 rq_ring_size_in_bytes;
26 	u32 rq_depth;
27 	u16 pd;
28 	u16 uarn;
29 	u8 qp_type;
30 	u8 unsolicited_write_recv : 1;
31 };
32 
33 struct efa_com_create_qp_result {
34 	u32 qp_handle;
35 	u32 qp_num;
36 	u32 sq_db_offset;
37 	u32 rq_db_offset;
38 	u32 llq_descriptors_offset;
39 	u16 send_sub_cq_idx;
40 	u16 recv_sub_cq_idx;
41 };
42 
43 struct efa_com_modify_qp_params {
44 	u32 modify_mask;
45 	u32 qp_handle;
46 	u32 qp_state;
47 	u32 cur_qp_state;
48 	u32 qkey;
49 	u32 sq_psn;
50 	u8 sq_drained_async_notify;
51 	u8 rnr_retry;
52 };
53 
54 struct efa_com_query_qp_params {
55 	u32 qp_handle;
56 };
57 
58 struct efa_com_query_qp_result {
59 	u32 qp_state;
60 	u32 qkey;
61 	u32 sq_draining;
62 	u32 sq_psn;
63 	u8 rnr_retry;
64 };
65 
66 struct efa_com_destroy_qp_params {
67 	u32 qp_handle;
68 };
69 
70 struct efa_com_create_cq_params {
71 	/* cq physical base address in OS memory */
72 	dma_addr_t dma_addr;
73 	/* completion queue depth in # of entries */
74 	u16 cq_depth;
75 	u16 num_sub_cqs;
76 	u16 uarn;
77 	u16 eqn;
78 	u8 entry_size_in_bytes;
79 	u8 interrupt_mode_enabled : 1;
80 	u8 set_src_addr : 1;
81 };
82 
83 struct efa_com_create_cq_result {
84 	/* cq identifier */
85 	u16 cq_idx;
86 	/* actual cq depth in # of entries */
87 	u16 actual_depth;
88 	u32 db_off;
89 	bool db_valid;
90 };
91 
92 struct efa_com_destroy_cq_params {
93 	u16 cq_idx;
94 };
95 
96 struct efa_com_create_ah_params {
97 	u16 pdn;
98 	/* Destination address in network byte order */
99 	u8 dest_addr[EFA_GID_SIZE];
100 };
101 
102 struct efa_com_create_ah_result {
103 	u16 ah;
104 };
105 
106 struct efa_com_destroy_ah_params {
107 	u16 ah;
108 	u16 pdn;
109 };
110 
111 struct efa_com_get_device_attr_result {
112 	u8 addr[EFA_GID_SIZE];
113 	u64 page_size_cap;
114 	u64 max_mr_pages;
115 	u64 guid;
116 	u32 mtu;
117 	u32 fw_version;
118 	u32 admin_api_version;
119 	u32 device_version;
120 	u32 supported_features;
121 	u32 phys_addr_width;
122 	u32 virt_addr_width;
123 	u32 max_qp;
124 	u32 max_sq_depth; /* wqes */
125 	u32 max_rq_depth; /* wqes */
126 	u32 max_cq;
127 	u32 max_cq_depth; /* cqes */
128 	u32 inline_buf_size;
129 	u32 max_mr;
130 	u32 max_pd;
131 	u32 max_ah;
132 	u32 max_llq_size;
133 	u32 max_rdma_size;
134 	u32 device_caps;
135 	u32 max_eq;
136 	u32 max_eq_depth;
137 	u32 event_bitmask; /* EQ events bitmask */
138 	u16 sub_cqs_per_cq;
139 	u16 max_sq_sge;
140 	u16 max_rq_sge;
141 	u16 max_wr_rdma_sge;
142 	u16 max_tx_batch;
143 	u16 min_sq_depth;
144 	u8 db_bar;
145 };
146 
147 struct efa_com_get_hw_hints_result {
148 	u16 mmio_read_timeout;
149 	u16 driver_watchdog_timeout;
150 	u16 admin_completion_timeout;
151 	u16 poll_interval;
152 	u32 reserved[4];
153 };
154 
155 struct efa_com_mem_addr {
156 	u32 mem_addr_low;
157 	u32 mem_addr_high;
158 };
159 
160 /* Used at indirect mode page list chunks for chaining */
161 struct efa_com_ctrl_buff_info {
162 	/* indicates length of the buffer pointed by control_buffer_address. */
163 	u32 length;
164 	/* points to control buffer (direct or indirect) */
165 	struct efa_com_mem_addr address;
166 };
167 
168 struct efa_com_reg_mr_params {
169 	/* Memory region length, in bytes. */
170 	u64 mr_length_in_bytes;
171 	/* IO Virtual Address associated with this MR. */
172 	u64 iova;
173 	/* words 8:15: Physical Buffer List, each element is page-aligned. */
174 	union {
175 		/*
176 		 * Inline array of physical addresses of app pages
177 		 * (optimization for short region reservations)
178 		 */
179 		u64 inline_pbl_array[4];
180 		/*
181 		 * Describes the next physically contiguous chunk of indirect
182 		 * page list. A page list contains physical addresses of command
183 		 * data pages. Data pages are 4KB; page list chunks are
184 		 * variable-sized.
185 		 */
186 		struct efa_com_ctrl_buff_info pbl;
187 	} pbl;
188 	/* number of pages in PBL (redundant, could be calculated) */
189 	u32 page_num;
190 	/* Protection Domain */
191 	u16 pd;
192 	/*
193 	 * phys_page_size_shift - page size is (1 << phys_page_size_shift)
194 	 * Page size is used for building the Virtual to Physical
195 	 * address mapping
196 	 */
197 	u8 page_shift;
198 	/* see permissions field of struct efa_admin_reg_mr_cmd */
199 	u8 permissions;
200 	u8 inline_pbl;
201 	u8 indirect;
202 };
203 
204 struct efa_com_mr_interconnect_info {
205 	u16 recv_ic_id;
206 	u16 rdma_read_ic_id;
207 	u16 rdma_recv_ic_id;
208 	u8 recv_ic_id_valid : 1;
209 	u8 rdma_read_ic_id_valid : 1;
210 	u8 rdma_recv_ic_id_valid : 1;
211 };
212 
213 struct efa_com_reg_mr_result {
214 	/*
215 	 * To be used in conjunction with local buffers references in SQ and
216 	 * RQ WQE
217 	 */
218 	u32 l_key;
219 	/*
220 	 * To be used in incoming RDMA semantics messages to refer to remotely
221 	 * accessed memory region
222 	 */
223 	u32 r_key;
224 	struct efa_com_mr_interconnect_info ic_info;
225 };
226 
227 struct efa_com_dereg_mr_params {
228 	u32 l_key;
229 };
230 
231 struct efa_com_alloc_pd_result {
232 	u16 pdn;
233 };
234 
235 struct efa_com_dealloc_pd_params {
236 	u16 pdn;
237 };
238 
239 struct efa_com_alloc_uar_result {
240 	u16 uarn;
241 };
242 
243 struct efa_com_dealloc_uar_params {
244 	u16 uarn;
245 };
246 
247 struct efa_com_get_stats_params {
248 	/* see enum efa_admin_get_stats_type */
249 	u8 type;
250 	/* see enum efa_admin_get_stats_scope */
251 	u8 scope;
252 	u16 scope_modifier;
253 };
254 
255 struct efa_com_basic_stats {
256 	u64 tx_bytes;
257 	u64 tx_pkts;
258 	u64 rx_bytes;
259 	u64 rx_pkts;
260 	u64 rx_drops;
261 };
262 
263 struct efa_com_messages_stats {
264 	u64 send_bytes;
265 	u64 send_wrs;
266 	u64 recv_bytes;
267 	u64 recv_wrs;
268 };
269 
270 struct efa_com_rdma_read_stats {
271 	u64 read_wrs;
272 	u64 read_bytes;
273 	u64 read_wr_err;
274 	u64 read_resp_bytes;
275 };
276 
277 struct efa_com_rdma_write_stats {
278 	u64 write_wrs;
279 	u64 write_bytes;
280 	u64 write_wr_err;
281 	u64 write_recv_bytes;
282 };
283 
284 union efa_com_get_stats_result {
285 	struct efa_com_basic_stats basic_stats;
286 	struct efa_com_messages_stats messages_stats;
287 	struct efa_com_rdma_read_stats rdma_read_stats;
288 	struct efa_com_rdma_write_stats rdma_write_stats;
289 };
290 
291 int efa_com_create_qp(struct efa_com_dev *edev,
292 		      struct efa_com_create_qp_params *params,
293 		      struct efa_com_create_qp_result *res);
294 int efa_com_modify_qp(struct efa_com_dev *edev,
295 		      struct efa_com_modify_qp_params *params);
296 int efa_com_query_qp(struct efa_com_dev *edev,
297 		     struct efa_com_query_qp_params *params,
298 		     struct efa_com_query_qp_result *result);
299 int efa_com_destroy_qp(struct efa_com_dev *edev,
300 		       struct efa_com_destroy_qp_params *params);
301 int efa_com_create_cq(struct efa_com_dev *edev,
302 		      struct efa_com_create_cq_params *params,
303 		      struct efa_com_create_cq_result *result);
304 int efa_com_destroy_cq(struct efa_com_dev *edev,
305 		       struct efa_com_destroy_cq_params *params);
306 int efa_com_register_mr(struct efa_com_dev *edev,
307 			struct efa_com_reg_mr_params *params,
308 			struct efa_com_reg_mr_result *result);
309 int efa_com_dereg_mr(struct efa_com_dev *edev,
310 		     struct efa_com_dereg_mr_params *params);
311 int efa_com_create_ah(struct efa_com_dev *edev,
312 		      struct efa_com_create_ah_params *params,
313 		      struct efa_com_create_ah_result *result);
314 int efa_com_destroy_ah(struct efa_com_dev *edev,
315 		       struct efa_com_destroy_ah_params *params);
316 int efa_com_get_device_attr(struct efa_com_dev *edev,
317 			    struct efa_com_get_device_attr_result *result);
318 int efa_com_get_hw_hints(struct efa_com_dev *edev,
319 			 struct efa_com_get_hw_hints_result *result);
320 bool
321 efa_com_check_supported_feature_id(struct efa_com_dev *edev,
322 				   enum efa_admin_aq_feature_id feature_id);
323 int efa_com_set_feature_ex(struct efa_com_dev *edev,
324 			   struct efa_admin_set_feature_resp *set_resp,
325 			   struct efa_admin_set_feature_cmd *set_cmd,
326 			   enum efa_admin_aq_feature_id feature_id,
327 			   dma_addr_t control_buf_dma_addr,
328 			   u32 control_buff_size);
329 int efa_com_set_aenq_config(struct efa_com_dev *edev, u32 groups);
330 int efa_com_alloc_pd(struct efa_com_dev *edev,
331 		     struct efa_com_alloc_pd_result *result);
332 int efa_com_dealloc_pd(struct efa_com_dev *edev,
333 		       struct efa_com_dealloc_pd_params *params);
334 int efa_com_alloc_uar(struct efa_com_dev *edev,
335 		      struct efa_com_alloc_uar_result *result);
336 int efa_com_dealloc_uar(struct efa_com_dev *edev,
337 			struct efa_com_dealloc_uar_params *params);
338 int efa_com_get_stats(struct efa_com_dev *edev,
339 		      struct efa_com_get_stats_params *params,
340 		      union efa_com_get_stats_result *result);
341 
342 #endif /* _EFA_COM_CMD_H_ */
343