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