1 // SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
2 /*
3  * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved.
4  */
5 
6 #include "efa_com.h"
7 #include "efa_com_cmd.h"
8 
9 void efa_com_set_dma_addr(dma_addr_t addr, u32 *addr_high, u32 *addr_low)
10 {
11 	*addr_low = lower_32_bits(addr);
12 	*addr_high = upper_32_bits(addr);
13 }
14 
15 int efa_com_create_qp(struct efa_com_dev *edev,
16 		      struct efa_com_create_qp_params *params,
17 		      struct efa_com_create_qp_result *res)
18 {
19 	struct efa_admin_create_qp_cmd create_qp_cmd = {};
20 	struct efa_admin_create_qp_resp cmd_completion;
21 	struct efa_com_admin_queue *aq = &edev->aq;
22 	int err;
23 
24 	create_qp_cmd.aq_common_desc.opcode = EFA_ADMIN_CREATE_QP;
25 
26 	create_qp_cmd.pd = params->pd;
27 	create_qp_cmd.qp_type = params->qp_type;
28 	create_qp_cmd.rq_base_addr = params->rq_base_addr;
29 	create_qp_cmd.send_cq_idx = params->send_cq_idx;
30 	create_qp_cmd.recv_cq_idx = params->recv_cq_idx;
31 	create_qp_cmd.qp_alloc_size.send_queue_ring_size =
32 		params->sq_ring_size_in_bytes;
33 	create_qp_cmd.qp_alloc_size.send_queue_depth =
34 			params->sq_depth;
35 	create_qp_cmd.qp_alloc_size.recv_queue_ring_size =
36 			params->rq_ring_size_in_bytes;
37 	create_qp_cmd.qp_alloc_size.recv_queue_depth =
38 			params->rq_depth;
39 	create_qp_cmd.uar = params->uarn;
40 
41 	err = efa_com_cmd_exec(aq,
42 			       (struct efa_admin_aq_entry *)&create_qp_cmd,
43 			       sizeof(create_qp_cmd),
44 			       (struct efa_admin_acq_entry *)&cmd_completion,
45 			       sizeof(cmd_completion));
46 	if (err) {
47 		ibdev_err(edev->efa_dev, "Failed to create qp [%d]\n", err);
48 		return err;
49 	}
50 
51 	res->qp_handle = cmd_completion.qp_handle;
52 	res->qp_num = cmd_completion.qp_num;
53 	res->sq_db_offset = cmd_completion.sq_db_offset;
54 	res->rq_db_offset = cmd_completion.rq_db_offset;
55 	res->llq_descriptors_offset = cmd_completion.llq_descriptors_offset;
56 	res->send_sub_cq_idx = cmd_completion.send_sub_cq_idx;
57 	res->recv_sub_cq_idx = cmd_completion.recv_sub_cq_idx;
58 
59 	return 0;
60 }
61 
62 int efa_com_modify_qp(struct efa_com_dev *edev,
63 		      struct efa_com_modify_qp_params *params)
64 {
65 	struct efa_com_admin_queue *aq = &edev->aq;
66 	struct efa_admin_modify_qp_cmd cmd = {};
67 	struct efa_admin_modify_qp_resp resp;
68 	int err;
69 
70 	cmd.aq_common_desc.opcode = EFA_ADMIN_MODIFY_QP;
71 	cmd.modify_mask = params->modify_mask;
72 	cmd.qp_handle = params->qp_handle;
73 	cmd.qp_state = params->qp_state;
74 	cmd.cur_qp_state = params->cur_qp_state;
75 	cmd.qkey = params->qkey;
76 	cmd.sq_psn = params->sq_psn;
77 	cmd.sq_drained_async_notify = params->sq_drained_async_notify;
78 
79 	err = efa_com_cmd_exec(aq,
80 			       (struct efa_admin_aq_entry *)&cmd,
81 			       sizeof(cmd),
82 			       (struct efa_admin_acq_entry *)&resp,
83 			       sizeof(resp));
84 	if (err) {
85 		ibdev_err(edev->efa_dev,
86 			  "Failed to modify qp-%u modify_mask[%#x] [%d]\n",
87 			  cmd.qp_handle, cmd.modify_mask, err);
88 		return err;
89 	}
90 
91 	return 0;
92 }
93 
94 int efa_com_query_qp(struct efa_com_dev *edev,
95 		     struct efa_com_query_qp_params *params,
96 		     struct efa_com_query_qp_result *result)
97 {
98 	struct efa_com_admin_queue *aq = &edev->aq;
99 	struct efa_admin_query_qp_cmd cmd = {};
100 	struct efa_admin_query_qp_resp resp;
101 	int err;
102 
103 	cmd.aq_common_desc.opcode = EFA_ADMIN_QUERY_QP;
104 	cmd.qp_handle = params->qp_handle;
105 
106 	err = efa_com_cmd_exec(aq,
107 			       (struct efa_admin_aq_entry *)&cmd,
108 			       sizeof(cmd),
109 			       (struct efa_admin_acq_entry *)&resp,
110 			       sizeof(resp));
111 	if (err) {
112 		ibdev_err(edev->efa_dev, "Failed to query qp-%u [%d]\n",
113 			  cmd.qp_handle, err);
114 		return err;
115 	}
116 
117 	result->qp_state = resp.qp_state;
118 	result->qkey = resp.qkey;
119 	result->sq_draining = resp.sq_draining;
120 	result->sq_psn = resp.sq_psn;
121 
122 	return 0;
123 }
124 
125 int efa_com_destroy_qp(struct efa_com_dev *edev,
126 		       struct efa_com_destroy_qp_params *params)
127 {
128 	struct efa_admin_destroy_qp_resp cmd_completion;
129 	struct efa_admin_destroy_qp_cmd qp_cmd = {};
130 	struct efa_com_admin_queue *aq = &edev->aq;
131 	int err;
132 
133 	qp_cmd.aq_common_desc.opcode = EFA_ADMIN_DESTROY_QP;
134 	qp_cmd.qp_handle = params->qp_handle;
135 
136 	err = efa_com_cmd_exec(aq,
137 			       (struct efa_admin_aq_entry *)&qp_cmd,
138 			       sizeof(qp_cmd),
139 			       (struct efa_admin_acq_entry *)&cmd_completion,
140 			       sizeof(cmd_completion));
141 	if (err) {
142 		ibdev_err(edev->efa_dev, "Failed to destroy qp-%u [%d]\n",
143 			  qp_cmd.qp_handle, err);
144 		return err;
145 	}
146 
147 	return 0;
148 }
149 
150 int efa_com_create_cq(struct efa_com_dev *edev,
151 		      struct efa_com_create_cq_params *params,
152 		      struct efa_com_create_cq_result *result)
153 {
154 	struct efa_admin_create_cq_resp cmd_completion;
155 	struct efa_admin_create_cq_cmd create_cmd = {};
156 	struct efa_com_admin_queue *aq = &edev->aq;
157 	int err;
158 
159 	create_cmd.aq_common_desc.opcode = EFA_ADMIN_CREATE_CQ;
160 	create_cmd.cq_caps_2 = (params->entry_size_in_bytes / 4) &
161 				EFA_ADMIN_CREATE_CQ_CMD_CQ_ENTRY_SIZE_WORDS_MASK;
162 	create_cmd.cq_depth = params->cq_depth;
163 	create_cmd.num_sub_cqs = params->num_sub_cqs;
164 	create_cmd.uar = params->uarn;
165 
166 	efa_com_set_dma_addr(params->dma_addr,
167 			     &create_cmd.cq_ba.mem_addr_high,
168 			     &create_cmd.cq_ba.mem_addr_low);
169 
170 	err = efa_com_cmd_exec(aq,
171 			       (struct efa_admin_aq_entry *)&create_cmd,
172 			       sizeof(create_cmd),
173 			       (struct efa_admin_acq_entry *)&cmd_completion,
174 			       sizeof(cmd_completion));
175 	if (err) {
176 		ibdev_err(edev->efa_dev, "Failed to create cq[%d]\n", err);
177 		return err;
178 	}
179 
180 	result->cq_idx = cmd_completion.cq_idx;
181 	result->actual_depth = params->cq_depth;
182 
183 	return 0;
184 }
185 
186 int efa_com_destroy_cq(struct efa_com_dev *edev,
187 		       struct efa_com_destroy_cq_params *params)
188 {
189 	struct efa_admin_destroy_cq_cmd destroy_cmd = {};
190 	struct efa_admin_destroy_cq_resp destroy_resp;
191 	struct efa_com_admin_queue *aq = &edev->aq;
192 	int err;
193 
194 	destroy_cmd.cq_idx = params->cq_idx;
195 	destroy_cmd.aq_common_desc.opcode = EFA_ADMIN_DESTROY_CQ;
196 
197 	err = efa_com_cmd_exec(aq,
198 			       (struct efa_admin_aq_entry *)&destroy_cmd,
199 			       sizeof(destroy_cmd),
200 			       (struct efa_admin_acq_entry *)&destroy_resp,
201 			       sizeof(destroy_resp));
202 
203 	if (err) {
204 		ibdev_err(edev->efa_dev, "Failed to destroy CQ-%u [%d]\n",
205 			  params->cq_idx, err);
206 		return err;
207 	}
208 
209 	return 0;
210 }
211 
212 int efa_com_register_mr(struct efa_com_dev *edev,
213 			struct efa_com_reg_mr_params *params,
214 			struct efa_com_reg_mr_result *result)
215 {
216 	struct efa_admin_reg_mr_resp cmd_completion;
217 	struct efa_com_admin_queue *aq = &edev->aq;
218 	struct efa_admin_reg_mr_cmd mr_cmd = {};
219 	int err;
220 
221 	mr_cmd.aq_common_desc.opcode = EFA_ADMIN_REG_MR;
222 	mr_cmd.pd = params->pd;
223 	mr_cmd.mr_length = params->mr_length_in_bytes;
224 	mr_cmd.flags |= params->page_shift &
225 		EFA_ADMIN_REG_MR_CMD_PHYS_PAGE_SIZE_SHIFT_MASK;
226 	mr_cmd.iova = params->iova;
227 	mr_cmd.permissions |= params->permissions &
228 			      EFA_ADMIN_REG_MR_CMD_LOCAL_WRITE_ENABLE_MASK;
229 
230 	if (params->inline_pbl) {
231 		memcpy(mr_cmd.pbl.inline_pbl_array,
232 		       params->pbl.inline_pbl_array,
233 		       sizeof(mr_cmd.pbl.inline_pbl_array));
234 	} else {
235 		mr_cmd.pbl.pbl.length = params->pbl.pbl.length;
236 		mr_cmd.pbl.pbl.address.mem_addr_low =
237 			params->pbl.pbl.address.mem_addr_low;
238 		mr_cmd.pbl.pbl.address.mem_addr_high =
239 			params->pbl.pbl.address.mem_addr_high;
240 		mr_cmd.aq_common_desc.flags |=
241 			EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_MASK;
242 		if (params->indirect)
243 			mr_cmd.aq_common_desc.flags |=
244 				EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK;
245 	}
246 
247 	err = efa_com_cmd_exec(aq,
248 			       (struct efa_admin_aq_entry *)&mr_cmd,
249 			       sizeof(mr_cmd),
250 			       (struct efa_admin_acq_entry *)&cmd_completion,
251 			       sizeof(cmd_completion));
252 	if (err) {
253 		ibdev_err(edev->efa_dev, "Failed to register mr [%d]\n", err);
254 		return err;
255 	}
256 
257 	result->l_key = cmd_completion.l_key;
258 	result->r_key = cmd_completion.r_key;
259 
260 	return 0;
261 }
262 
263 int efa_com_dereg_mr(struct efa_com_dev *edev,
264 		     struct efa_com_dereg_mr_params *params)
265 {
266 	struct efa_admin_dereg_mr_resp cmd_completion;
267 	struct efa_com_admin_queue *aq = &edev->aq;
268 	struct efa_admin_dereg_mr_cmd mr_cmd = {};
269 	int err;
270 
271 	mr_cmd.aq_common_desc.opcode = EFA_ADMIN_DEREG_MR;
272 	mr_cmd.l_key = params->l_key;
273 
274 	err = efa_com_cmd_exec(aq,
275 			       (struct efa_admin_aq_entry *)&mr_cmd,
276 			       sizeof(mr_cmd),
277 			       (struct efa_admin_acq_entry *)&cmd_completion,
278 			       sizeof(cmd_completion));
279 	if (err) {
280 		ibdev_err(edev->efa_dev,
281 			  "Failed to de-register mr(lkey-%u) [%d]\n",
282 			  mr_cmd.l_key, err);
283 		return err;
284 	}
285 
286 	return 0;
287 }
288 
289 int efa_com_create_ah(struct efa_com_dev *edev,
290 		      struct efa_com_create_ah_params *params,
291 		      struct efa_com_create_ah_result *result)
292 {
293 	struct efa_admin_create_ah_resp cmd_completion;
294 	struct efa_com_admin_queue *aq = &edev->aq;
295 	struct efa_admin_create_ah_cmd ah_cmd = {};
296 	int err;
297 
298 	ah_cmd.aq_common_desc.opcode = EFA_ADMIN_CREATE_AH;
299 
300 	memcpy(ah_cmd.dest_addr, params->dest_addr, sizeof(ah_cmd.dest_addr));
301 	ah_cmd.pd = params->pdn;
302 
303 	err = efa_com_cmd_exec(aq,
304 			       (struct efa_admin_aq_entry *)&ah_cmd,
305 			       sizeof(ah_cmd),
306 			       (struct efa_admin_acq_entry *)&cmd_completion,
307 			       sizeof(cmd_completion));
308 	if (err) {
309 		ibdev_err(edev->efa_dev, "Failed to create ah for %pI6 [%d]\n",
310 			  ah_cmd.dest_addr, err);
311 		return err;
312 	}
313 
314 	result->ah = cmd_completion.ah;
315 
316 	return 0;
317 }
318 
319 int efa_com_destroy_ah(struct efa_com_dev *edev,
320 		       struct efa_com_destroy_ah_params *params)
321 {
322 	struct efa_admin_destroy_ah_resp cmd_completion;
323 	struct efa_admin_destroy_ah_cmd ah_cmd = {};
324 	struct efa_com_admin_queue *aq = &edev->aq;
325 	int err;
326 
327 	ah_cmd.aq_common_desc.opcode = EFA_ADMIN_DESTROY_AH;
328 	ah_cmd.ah = params->ah;
329 	ah_cmd.pd = params->pdn;
330 
331 	err = efa_com_cmd_exec(aq,
332 			       (struct efa_admin_aq_entry *)&ah_cmd,
333 			       sizeof(ah_cmd),
334 			       (struct efa_admin_acq_entry *)&cmd_completion,
335 			       sizeof(cmd_completion));
336 	if (err) {
337 		ibdev_err(edev->efa_dev, "Failed to destroy ah-%d pd-%d [%d]\n",
338 			  ah_cmd.ah, ah_cmd.pd, err);
339 		return err;
340 	}
341 
342 	return 0;
343 }
344 
345 static bool
346 efa_com_check_supported_feature_id(struct efa_com_dev *edev,
347 				   enum efa_admin_aq_feature_id feature_id)
348 {
349 	u32 feature_mask = 1 << feature_id;
350 
351 	/* Device attributes is always supported */
352 	if (feature_id != EFA_ADMIN_DEVICE_ATTR &&
353 	    !(edev->supported_features & feature_mask))
354 		return false;
355 
356 	return true;
357 }
358 
359 static int efa_com_get_feature_ex(struct efa_com_dev *edev,
360 				  struct efa_admin_get_feature_resp *get_resp,
361 				  enum efa_admin_aq_feature_id feature_id,
362 				  dma_addr_t control_buf_dma_addr,
363 				  u32 control_buff_size)
364 {
365 	struct efa_admin_get_feature_cmd get_cmd = {};
366 	struct efa_com_admin_queue *aq;
367 	int err;
368 
369 	if (!efa_com_check_supported_feature_id(edev, feature_id)) {
370 		ibdev_err(edev->efa_dev, "Feature %d isn't supported\n",
371 			  feature_id);
372 		return -EOPNOTSUPP;
373 	}
374 
375 	aq = &edev->aq;
376 
377 	get_cmd.aq_common_descriptor.opcode = EFA_ADMIN_GET_FEATURE;
378 
379 	if (control_buff_size)
380 		get_cmd.aq_common_descriptor.flags =
381 			EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK;
382 
383 
384 	efa_com_set_dma_addr(control_buf_dma_addr,
385 			     &get_cmd.control_buffer.address.mem_addr_high,
386 			     &get_cmd.control_buffer.address.mem_addr_low);
387 
388 	get_cmd.control_buffer.length = control_buff_size;
389 	get_cmd.feature_common.feature_id = feature_id;
390 	err = efa_com_cmd_exec(aq,
391 			       (struct efa_admin_aq_entry *)
392 			       &get_cmd,
393 			       sizeof(get_cmd),
394 			       (struct efa_admin_acq_entry *)
395 			       get_resp,
396 			       sizeof(*get_resp));
397 
398 	if (err) {
399 		ibdev_err(edev->efa_dev,
400 			  "Failed to submit get_feature command %d [%d]\n",
401 			  feature_id, err);
402 		return err;
403 	}
404 
405 	return 0;
406 }
407 
408 static int efa_com_get_feature(struct efa_com_dev *edev,
409 			       struct efa_admin_get_feature_resp *get_resp,
410 			       enum efa_admin_aq_feature_id feature_id)
411 {
412 	return efa_com_get_feature_ex(edev, get_resp, feature_id, 0, 0);
413 }
414 
415 int efa_com_get_network_attr(struct efa_com_dev *edev,
416 			     struct efa_com_get_network_attr_result *result)
417 {
418 	struct efa_admin_get_feature_resp resp;
419 	int err;
420 
421 	err = efa_com_get_feature(edev, &resp,
422 				  EFA_ADMIN_NETWORK_ATTR);
423 	if (err) {
424 		ibdev_err(edev->efa_dev,
425 			  "Failed to get network attributes %d\n", err);
426 		return err;
427 	}
428 
429 	memcpy(result->addr, resp.u.network_attr.addr,
430 	       sizeof(resp.u.network_attr.addr));
431 	result->mtu = resp.u.network_attr.mtu;
432 
433 	return 0;
434 }
435 
436 int efa_com_get_device_attr(struct efa_com_dev *edev,
437 			    struct efa_com_get_device_attr_result *result)
438 {
439 	struct efa_admin_get_feature_resp resp;
440 	int err;
441 
442 	err = efa_com_get_feature(edev, &resp, EFA_ADMIN_DEVICE_ATTR);
443 	if (err) {
444 		ibdev_err(edev->efa_dev, "Failed to get device attributes %d\n",
445 			  err);
446 		return err;
447 	}
448 
449 	result->page_size_cap = resp.u.device_attr.page_size_cap;
450 	result->fw_version = resp.u.device_attr.fw_version;
451 	result->admin_api_version = resp.u.device_attr.admin_api_version;
452 	result->device_version = resp.u.device_attr.device_version;
453 	result->supported_features = resp.u.device_attr.supported_features;
454 	result->phys_addr_width = resp.u.device_attr.phys_addr_width;
455 	result->virt_addr_width = resp.u.device_attr.virt_addr_width;
456 	result->db_bar = resp.u.device_attr.db_bar;
457 
458 	if (result->admin_api_version < 1) {
459 		ibdev_err(edev->efa_dev,
460 			  "Failed to get device attr api version [%u < 1]\n",
461 			  result->admin_api_version);
462 		return -EINVAL;
463 	}
464 
465 	edev->supported_features = resp.u.device_attr.supported_features;
466 	err = efa_com_get_feature(edev, &resp,
467 				  EFA_ADMIN_QUEUE_ATTR);
468 	if (err) {
469 		ibdev_err(edev->efa_dev,
470 			  "Failed to get network attributes %d\n", err);
471 		return err;
472 	}
473 
474 	result->max_qp = resp.u.queue_attr.max_qp;
475 	result->max_sq_depth = resp.u.queue_attr.max_sq_depth;
476 	result->max_rq_depth = resp.u.queue_attr.max_rq_depth;
477 	result->max_cq = resp.u.queue_attr.max_cq;
478 	result->max_cq_depth = resp.u.queue_attr.max_cq_depth;
479 	result->inline_buf_size = resp.u.queue_attr.inline_buf_size;
480 	result->max_sq_sge = resp.u.queue_attr.max_wr_send_sges;
481 	result->max_rq_sge = resp.u.queue_attr.max_wr_recv_sges;
482 	result->max_mr = resp.u.queue_attr.max_mr;
483 	result->max_mr_pages = resp.u.queue_attr.max_mr_pages;
484 	result->max_pd = resp.u.queue_attr.max_pd;
485 	result->max_ah = resp.u.queue_attr.max_ah;
486 	result->max_llq_size = resp.u.queue_attr.max_llq_size;
487 	result->sub_cqs_per_cq = resp.u.queue_attr.sub_cqs_per_cq;
488 
489 	return 0;
490 }
491 
492 int efa_com_get_hw_hints(struct efa_com_dev *edev,
493 			 struct efa_com_get_hw_hints_result *result)
494 {
495 	struct efa_admin_get_feature_resp resp;
496 	int err;
497 
498 	err = efa_com_get_feature(edev, &resp, EFA_ADMIN_HW_HINTS);
499 	if (err) {
500 		ibdev_err(edev->efa_dev, "Failed to get hw hints %d\n", err);
501 		return err;
502 	}
503 
504 	result->admin_completion_timeout = resp.u.hw_hints.admin_completion_timeout;
505 	result->driver_watchdog_timeout = resp.u.hw_hints.driver_watchdog_timeout;
506 	result->mmio_read_timeout = resp.u.hw_hints.mmio_read_timeout;
507 	result->poll_interval = resp.u.hw_hints.poll_interval;
508 
509 	return 0;
510 }
511 
512 static int efa_com_set_feature_ex(struct efa_com_dev *edev,
513 				  struct efa_admin_set_feature_resp *set_resp,
514 				  struct efa_admin_set_feature_cmd *set_cmd,
515 				  enum efa_admin_aq_feature_id feature_id,
516 				  dma_addr_t control_buf_dma_addr,
517 				  u32 control_buff_size)
518 {
519 	struct efa_com_admin_queue *aq;
520 	int err;
521 
522 	if (!efa_com_check_supported_feature_id(edev, feature_id)) {
523 		ibdev_err(edev->efa_dev, "Feature %d isn't supported\n",
524 			  feature_id);
525 		return -EOPNOTSUPP;
526 	}
527 
528 	aq = &edev->aq;
529 
530 	set_cmd->aq_common_descriptor.opcode = EFA_ADMIN_SET_FEATURE;
531 	if (control_buff_size) {
532 		set_cmd->aq_common_descriptor.flags =
533 			EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK;
534 		efa_com_set_dma_addr(control_buf_dma_addr,
535 				     &set_cmd->control_buffer.address.mem_addr_high,
536 				     &set_cmd->control_buffer.address.mem_addr_low);
537 	}
538 
539 	set_cmd->control_buffer.length = control_buff_size;
540 	set_cmd->feature_common.feature_id = feature_id;
541 	err = efa_com_cmd_exec(aq,
542 			       (struct efa_admin_aq_entry *)set_cmd,
543 			       sizeof(*set_cmd),
544 			       (struct efa_admin_acq_entry *)set_resp,
545 			       sizeof(*set_resp));
546 
547 	if (err) {
548 		ibdev_err(edev->efa_dev,
549 			  "Failed to submit set_feature command %d error: %d\n",
550 			  feature_id, err);
551 		return err;
552 	}
553 
554 	return 0;
555 }
556 
557 static int efa_com_set_feature(struct efa_com_dev *edev,
558 			       struct efa_admin_set_feature_resp *set_resp,
559 			       struct efa_admin_set_feature_cmd *set_cmd,
560 			       enum efa_admin_aq_feature_id feature_id)
561 {
562 	return efa_com_set_feature_ex(edev, set_resp, set_cmd, feature_id,
563 				      0, 0);
564 }
565 
566 int efa_com_set_aenq_config(struct efa_com_dev *edev, u32 groups)
567 {
568 	struct efa_admin_get_feature_resp get_resp;
569 	struct efa_admin_set_feature_resp set_resp;
570 	struct efa_admin_set_feature_cmd cmd = {};
571 	int err;
572 
573 	ibdev_dbg(edev->efa_dev, "Configuring aenq with groups[%#x]\n", groups);
574 
575 	err = efa_com_get_feature(edev, &get_resp, EFA_ADMIN_AENQ_CONFIG);
576 	if (err) {
577 		ibdev_err(edev->efa_dev, "Failed to get aenq attributes: %d\n",
578 			  err);
579 		return err;
580 	}
581 
582 	ibdev_dbg(edev->efa_dev,
583 		  "Get aenq groups: supported[%#x] enabled[%#x]\n",
584 		  get_resp.u.aenq.supported_groups,
585 		  get_resp.u.aenq.enabled_groups);
586 
587 	if ((get_resp.u.aenq.supported_groups & groups) != groups) {
588 		ibdev_err(edev->efa_dev,
589 			  "Trying to set unsupported aenq groups[%#x] supported[%#x]\n",
590 			  groups, get_resp.u.aenq.supported_groups);
591 		return -EOPNOTSUPP;
592 	}
593 
594 	cmd.u.aenq.enabled_groups = groups;
595 	err = efa_com_set_feature(edev, &set_resp, &cmd,
596 				  EFA_ADMIN_AENQ_CONFIG);
597 	if (err) {
598 		ibdev_err(edev->efa_dev, "Failed to set aenq attributes: %d\n",
599 			  err);
600 		return err;
601 	}
602 
603 	return 0;
604 }
605 
606 int efa_com_alloc_pd(struct efa_com_dev *edev,
607 		     struct efa_com_alloc_pd_result *result)
608 {
609 	struct efa_com_admin_queue *aq = &edev->aq;
610 	struct efa_admin_alloc_pd_cmd cmd = {};
611 	struct efa_admin_alloc_pd_resp resp;
612 	int err;
613 
614 	cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_PD;
615 
616 	err = efa_com_cmd_exec(aq,
617 			       (struct efa_admin_aq_entry *)&cmd,
618 			       sizeof(cmd),
619 			       (struct efa_admin_acq_entry *)&resp,
620 			       sizeof(resp));
621 	if (err) {
622 		ibdev_err(edev->efa_dev, "Failed to allocate pd[%d]\n", err);
623 		return err;
624 	}
625 
626 	result->pdn = resp.pd;
627 
628 	return 0;
629 }
630 
631 int efa_com_dealloc_pd(struct efa_com_dev *edev,
632 		       struct efa_com_dealloc_pd_params *params)
633 {
634 	struct efa_com_admin_queue *aq = &edev->aq;
635 	struct efa_admin_dealloc_pd_cmd cmd = {};
636 	struct efa_admin_dealloc_pd_resp resp;
637 	int err;
638 
639 	cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_PD;
640 	cmd.pd = params->pdn;
641 
642 	err = efa_com_cmd_exec(aq,
643 			       (struct efa_admin_aq_entry *)&cmd,
644 			       sizeof(cmd),
645 			       (struct efa_admin_acq_entry *)&resp,
646 			       sizeof(resp));
647 	if (err) {
648 		ibdev_err(edev->efa_dev, "Failed to deallocate pd-%u [%d]\n",
649 			  cmd.pd, err);
650 		return err;
651 	}
652 
653 	return 0;
654 }
655 
656 int efa_com_alloc_uar(struct efa_com_dev *edev,
657 		      struct efa_com_alloc_uar_result *result)
658 {
659 	struct efa_com_admin_queue *aq = &edev->aq;
660 	struct efa_admin_alloc_uar_cmd cmd = {};
661 	struct efa_admin_alloc_uar_resp resp;
662 	int err;
663 
664 	cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_UAR;
665 
666 	err = efa_com_cmd_exec(aq,
667 			       (struct efa_admin_aq_entry *)&cmd,
668 			       sizeof(cmd),
669 			       (struct efa_admin_acq_entry *)&resp,
670 			       sizeof(resp));
671 	if (err) {
672 		ibdev_err(edev->efa_dev, "Failed to allocate uar[%d]\n", err);
673 		return err;
674 	}
675 
676 	result->uarn = resp.uar;
677 
678 	return 0;
679 }
680 
681 int efa_com_dealloc_uar(struct efa_com_dev *edev,
682 			struct efa_com_dealloc_uar_params *params)
683 {
684 	struct efa_com_admin_queue *aq = &edev->aq;
685 	struct efa_admin_dealloc_uar_cmd cmd = {};
686 	struct efa_admin_dealloc_uar_resp resp;
687 	int err;
688 
689 	cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_UAR;
690 	cmd.uar = params->uarn;
691 
692 	err = efa_com_cmd_exec(aq,
693 			       (struct efa_admin_aq_entry *)&cmd,
694 			       sizeof(cmd),
695 			       (struct efa_admin_acq_entry *)&resp,
696 			       sizeof(resp));
697 	if (err) {
698 		ibdev_err(edev->efa_dev, "Failed to deallocate uar-%u [%d]\n",
699 			  cmd.uar, err);
700 		return err;
701 	}
702 
703 	return 0;
704 }
705