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