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_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 create_cmd.cq_caps_2 = (params->entry_size_in_bytes / 4) & 165 EFA_ADMIN_CREATE_CQ_CMD_CQ_ENTRY_SIZE_WORDS_MASK; 166 create_cmd.cq_depth = params->cq_depth; 167 create_cmd.num_sub_cqs = params->num_sub_cqs; 168 create_cmd.uar = params->uarn; 169 170 efa_com_set_dma_addr(params->dma_addr, 171 &create_cmd.cq_ba.mem_addr_high, 172 &create_cmd.cq_ba.mem_addr_low); 173 174 err = efa_com_cmd_exec(aq, 175 (struct efa_admin_aq_entry *)&create_cmd, 176 sizeof(create_cmd), 177 (struct efa_admin_acq_entry *)&cmd_completion, 178 sizeof(cmd_completion)); 179 if (err) { 180 ibdev_err_ratelimited(edev->efa_dev, 181 "Failed to create cq[%d]\n", err); 182 return err; 183 } 184 185 result->cq_idx = cmd_completion.cq_idx; 186 result->actual_depth = params->cq_depth; 187 188 return 0; 189 } 190 191 int efa_com_destroy_cq(struct efa_com_dev *edev, 192 struct efa_com_destroy_cq_params *params) 193 { 194 struct efa_admin_destroy_cq_cmd destroy_cmd = {}; 195 struct efa_admin_destroy_cq_resp destroy_resp; 196 struct efa_com_admin_queue *aq = &edev->aq; 197 int err; 198 199 destroy_cmd.cq_idx = params->cq_idx; 200 destroy_cmd.aq_common_desc.opcode = EFA_ADMIN_DESTROY_CQ; 201 202 err = efa_com_cmd_exec(aq, 203 (struct efa_admin_aq_entry *)&destroy_cmd, 204 sizeof(destroy_cmd), 205 (struct efa_admin_acq_entry *)&destroy_resp, 206 sizeof(destroy_resp)); 207 208 if (err) { 209 ibdev_err_ratelimited(edev->efa_dev, 210 "Failed to destroy CQ-%u [%d]\n", 211 params->cq_idx, err); 212 return err; 213 } 214 215 return 0; 216 } 217 218 int efa_com_register_mr(struct efa_com_dev *edev, 219 struct efa_com_reg_mr_params *params, 220 struct efa_com_reg_mr_result *result) 221 { 222 struct efa_admin_reg_mr_resp cmd_completion; 223 struct efa_com_admin_queue *aq = &edev->aq; 224 struct efa_admin_reg_mr_cmd mr_cmd = {}; 225 int err; 226 227 mr_cmd.aq_common_desc.opcode = EFA_ADMIN_REG_MR; 228 mr_cmd.pd = params->pd; 229 mr_cmd.mr_length = params->mr_length_in_bytes; 230 mr_cmd.flags |= params->page_shift & 231 EFA_ADMIN_REG_MR_CMD_PHYS_PAGE_SIZE_SHIFT_MASK; 232 mr_cmd.iova = params->iova; 233 mr_cmd.permissions |= params->permissions & 234 EFA_ADMIN_REG_MR_CMD_LOCAL_WRITE_ENABLE_MASK; 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 mr_cmd.aq_common_desc.flags |= 247 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_MASK; 248 if (params->indirect) 249 mr_cmd.aq_common_desc.flags |= 250 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; 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 static 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 get_cmd.aq_common_descriptor.flags = 391 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; 392 393 394 efa_com_set_dma_addr(control_buf_dma_addr, 395 &get_cmd.control_buffer.address.mem_addr_high, 396 &get_cmd.control_buffer.address.mem_addr_low); 397 398 get_cmd.control_buffer.length = control_buff_size; 399 get_cmd.feature_common.feature_id = feature_id; 400 err = efa_com_cmd_exec(aq, 401 (struct efa_admin_aq_entry *) 402 &get_cmd, 403 sizeof(get_cmd), 404 (struct efa_admin_acq_entry *) 405 get_resp, 406 sizeof(*get_resp)); 407 408 if (err) { 409 ibdev_err_ratelimited( 410 edev->efa_dev, 411 "Failed to submit get_feature command %d [%d]\n", 412 feature_id, err); 413 return err; 414 } 415 416 return 0; 417 } 418 419 static int efa_com_get_feature(struct efa_com_dev *edev, 420 struct efa_admin_get_feature_resp *get_resp, 421 enum efa_admin_aq_feature_id feature_id) 422 { 423 return efa_com_get_feature_ex(edev, get_resp, feature_id, 0, 0); 424 } 425 426 int efa_com_get_network_attr(struct efa_com_dev *edev, 427 struct efa_com_get_network_attr_result *result) 428 { 429 struct efa_admin_get_feature_resp resp; 430 int err; 431 432 err = efa_com_get_feature(edev, &resp, 433 EFA_ADMIN_NETWORK_ATTR); 434 if (err) { 435 ibdev_err_ratelimited(edev->efa_dev, 436 "Failed to get network attributes %d\n", 437 err); 438 return err; 439 } 440 441 memcpy(result->addr, resp.u.network_attr.addr, 442 sizeof(resp.u.network_attr.addr)); 443 result->mtu = resp.u.network_attr.mtu; 444 445 return 0; 446 } 447 448 int efa_com_get_device_attr(struct efa_com_dev *edev, 449 struct efa_com_get_device_attr_result *result) 450 { 451 struct efa_admin_get_feature_resp resp; 452 int err; 453 454 err = efa_com_get_feature(edev, &resp, EFA_ADMIN_DEVICE_ATTR); 455 if (err) { 456 ibdev_err_ratelimited(edev->efa_dev, 457 "Failed to get device attributes %d\n", 458 err); 459 return err; 460 } 461 462 result->page_size_cap = resp.u.device_attr.page_size_cap; 463 result->fw_version = resp.u.device_attr.fw_version; 464 result->admin_api_version = resp.u.device_attr.admin_api_version; 465 result->device_version = resp.u.device_attr.device_version; 466 result->supported_features = resp.u.device_attr.supported_features; 467 result->phys_addr_width = resp.u.device_attr.phys_addr_width; 468 result->virt_addr_width = resp.u.device_attr.virt_addr_width; 469 result->db_bar = resp.u.device_attr.db_bar; 470 471 if (result->admin_api_version < 1) { 472 ibdev_err_ratelimited( 473 edev->efa_dev, 474 "Failed to get device attr api version [%u < 1]\n", 475 result->admin_api_version); 476 return -EINVAL; 477 } 478 479 edev->supported_features = resp.u.device_attr.supported_features; 480 err = efa_com_get_feature(edev, &resp, 481 EFA_ADMIN_QUEUE_ATTR); 482 if (err) { 483 ibdev_err_ratelimited(edev->efa_dev, 484 "Failed to get queue attributes %d\n", 485 err); 486 return err; 487 } 488 489 result->max_qp = resp.u.queue_attr.max_qp; 490 result->max_sq_depth = resp.u.queue_attr.max_sq_depth; 491 result->max_rq_depth = resp.u.queue_attr.max_rq_depth; 492 result->max_cq = resp.u.queue_attr.max_cq; 493 result->max_cq_depth = resp.u.queue_attr.max_cq_depth; 494 result->inline_buf_size = resp.u.queue_attr.inline_buf_size; 495 result->max_sq_sge = resp.u.queue_attr.max_wr_send_sges; 496 result->max_rq_sge = resp.u.queue_attr.max_wr_recv_sges; 497 result->max_mr = resp.u.queue_attr.max_mr; 498 result->max_mr_pages = resp.u.queue_attr.max_mr_pages; 499 result->max_pd = resp.u.queue_attr.max_pd; 500 result->max_ah = resp.u.queue_attr.max_ah; 501 result->max_llq_size = resp.u.queue_attr.max_llq_size; 502 result->sub_cqs_per_cq = resp.u.queue_attr.sub_cqs_per_cq; 503 504 return 0; 505 } 506 507 int efa_com_get_hw_hints(struct efa_com_dev *edev, 508 struct efa_com_get_hw_hints_result *result) 509 { 510 struct efa_admin_get_feature_resp resp; 511 int err; 512 513 err = efa_com_get_feature(edev, &resp, EFA_ADMIN_HW_HINTS); 514 if (err) { 515 ibdev_err_ratelimited(edev->efa_dev, 516 "Failed to get hw hints %d\n", err); 517 return err; 518 } 519 520 result->admin_completion_timeout = resp.u.hw_hints.admin_completion_timeout; 521 result->driver_watchdog_timeout = resp.u.hw_hints.driver_watchdog_timeout; 522 result->mmio_read_timeout = resp.u.hw_hints.mmio_read_timeout; 523 result->poll_interval = resp.u.hw_hints.poll_interval; 524 525 return 0; 526 } 527 528 static int efa_com_set_feature_ex(struct efa_com_dev *edev, 529 struct efa_admin_set_feature_resp *set_resp, 530 struct efa_admin_set_feature_cmd *set_cmd, 531 enum efa_admin_aq_feature_id feature_id, 532 dma_addr_t control_buf_dma_addr, 533 u32 control_buff_size) 534 { 535 struct efa_com_admin_queue *aq; 536 int err; 537 538 if (!efa_com_check_supported_feature_id(edev, feature_id)) { 539 ibdev_err_ratelimited(edev->efa_dev, 540 "Feature %d isn't supported\n", 541 feature_id); 542 return -EOPNOTSUPP; 543 } 544 545 aq = &edev->aq; 546 547 set_cmd->aq_common_descriptor.opcode = EFA_ADMIN_SET_FEATURE; 548 if (control_buff_size) { 549 set_cmd->aq_common_descriptor.flags = 550 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; 551 efa_com_set_dma_addr(control_buf_dma_addr, 552 &set_cmd->control_buffer.address.mem_addr_high, 553 &set_cmd->control_buffer.address.mem_addr_low); 554 } 555 556 set_cmd->control_buffer.length = control_buff_size; 557 set_cmd->feature_common.feature_id = feature_id; 558 err = efa_com_cmd_exec(aq, 559 (struct efa_admin_aq_entry *)set_cmd, 560 sizeof(*set_cmd), 561 (struct efa_admin_acq_entry *)set_resp, 562 sizeof(*set_resp)); 563 564 if (err) { 565 ibdev_err_ratelimited( 566 edev->efa_dev, 567 "Failed to submit set_feature command %d error: %d\n", 568 feature_id, err); 569 return err; 570 } 571 572 return 0; 573 } 574 575 static int efa_com_set_feature(struct efa_com_dev *edev, 576 struct efa_admin_set_feature_resp *set_resp, 577 struct efa_admin_set_feature_cmd *set_cmd, 578 enum efa_admin_aq_feature_id feature_id) 579 { 580 return efa_com_set_feature_ex(edev, set_resp, set_cmd, feature_id, 581 0, 0); 582 } 583 584 int efa_com_set_aenq_config(struct efa_com_dev *edev, u32 groups) 585 { 586 struct efa_admin_get_feature_resp get_resp; 587 struct efa_admin_set_feature_resp set_resp; 588 struct efa_admin_set_feature_cmd cmd = {}; 589 int err; 590 591 ibdev_dbg(edev->efa_dev, "Configuring aenq with groups[%#x]\n", groups); 592 593 err = efa_com_get_feature(edev, &get_resp, EFA_ADMIN_AENQ_CONFIG); 594 if (err) { 595 ibdev_err_ratelimited(edev->efa_dev, 596 "Failed to get aenq attributes: %d\n", 597 err); 598 return err; 599 } 600 601 ibdev_dbg(edev->efa_dev, 602 "Get aenq groups: supported[%#x] enabled[%#x]\n", 603 get_resp.u.aenq.supported_groups, 604 get_resp.u.aenq.enabled_groups); 605 606 if ((get_resp.u.aenq.supported_groups & groups) != groups) { 607 ibdev_err_ratelimited( 608 edev->efa_dev, 609 "Trying to set unsupported aenq groups[%#x] supported[%#x]\n", 610 groups, get_resp.u.aenq.supported_groups); 611 return -EOPNOTSUPP; 612 } 613 614 cmd.u.aenq.enabled_groups = groups; 615 err = efa_com_set_feature(edev, &set_resp, &cmd, 616 EFA_ADMIN_AENQ_CONFIG); 617 if (err) { 618 ibdev_err_ratelimited(edev->efa_dev, 619 "Failed to set aenq attributes: %d\n", 620 err); 621 return err; 622 } 623 624 return 0; 625 } 626 627 int efa_com_alloc_pd(struct efa_com_dev *edev, 628 struct efa_com_alloc_pd_result *result) 629 { 630 struct efa_com_admin_queue *aq = &edev->aq; 631 struct efa_admin_alloc_pd_cmd cmd = {}; 632 struct efa_admin_alloc_pd_resp resp; 633 int err; 634 635 cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_PD; 636 637 err = efa_com_cmd_exec(aq, 638 (struct efa_admin_aq_entry *)&cmd, 639 sizeof(cmd), 640 (struct efa_admin_acq_entry *)&resp, 641 sizeof(resp)); 642 if (err) { 643 ibdev_err_ratelimited(edev->efa_dev, 644 "Failed to allocate pd[%d]\n", err); 645 return err; 646 } 647 648 result->pdn = resp.pd; 649 650 return 0; 651 } 652 653 int efa_com_dealloc_pd(struct efa_com_dev *edev, 654 struct efa_com_dealloc_pd_params *params) 655 { 656 struct efa_com_admin_queue *aq = &edev->aq; 657 struct efa_admin_dealloc_pd_cmd cmd = {}; 658 struct efa_admin_dealloc_pd_resp resp; 659 int err; 660 661 cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_PD; 662 cmd.pd = params->pdn; 663 664 err = efa_com_cmd_exec(aq, 665 (struct efa_admin_aq_entry *)&cmd, 666 sizeof(cmd), 667 (struct efa_admin_acq_entry *)&resp, 668 sizeof(resp)); 669 if (err) { 670 ibdev_err_ratelimited(edev->efa_dev, 671 "Failed to deallocate pd-%u [%d]\n", 672 cmd.pd, err); 673 return err; 674 } 675 676 return 0; 677 } 678 679 int efa_com_alloc_uar(struct efa_com_dev *edev, 680 struct efa_com_alloc_uar_result *result) 681 { 682 struct efa_com_admin_queue *aq = &edev->aq; 683 struct efa_admin_alloc_uar_cmd cmd = {}; 684 struct efa_admin_alloc_uar_resp resp; 685 int err; 686 687 cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_UAR; 688 689 err = efa_com_cmd_exec(aq, 690 (struct efa_admin_aq_entry *)&cmd, 691 sizeof(cmd), 692 (struct efa_admin_acq_entry *)&resp, 693 sizeof(resp)); 694 if (err) { 695 ibdev_err_ratelimited(edev->efa_dev, 696 "Failed to allocate uar[%d]\n", err); 697 return err; 698 } 699 700 result->uarn = resp.uar; 701 702 return 0; 703 } 704 705 int efa_com_dealloc_uar(struct efa_com_dev *edev, 706 struct efa_com_dealloc_uar_params *params) 707 { 708 struct efa_com_admin_queue *aq = &edev->aq; 709 struct efa_admin_dealloc_uar_cmd cmd = {}; 710 struct efa_admin_dealloc_uar_resp resp; 711 int err; 712 713 cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_UAR; 714 cmd.uar = params->uarn; 715 716 err = efa_com_cmd_exec(aq, 717 (struct efa_admin_aq_entry *)&cmd, 718 sizeof(cmd), 719 (struct efa_admin_acq_entry *)&resp, 720 sizeof(resp)); 721 if (err) { 722 ibdev_err_ratelimited(edev->efa_dev, 723 "Failed to deallocate uar-%u [%d]\n", 724 cmd.uar, err); 725 return err; 726 } 727 728 return 0; 729 } 730 731 int efa_com_get_stats(struct efa_com_dev *edev, 732 struct efa_com_get_stats_params *params, 733 union efa_com_get_stats_result *result) 734 { 735 struct efa_com_admin_queue *aq = &edev->aq; 736 struct efa_admin_aq_get_stats_cmd cmd = {}; 737 struct efa_admin_acq_get_stats_resp resp; 738 int err; 739 740 cmd.aq_common_descriptor.opcode = EFA_ADMIN_GET_STATS; 741 cmd.type = params->type; 742 cmd.scope = params->scope; 743 cmd.scope_modifier = params->scope_modifier; 744 745 err = efa_com_cmd_exec(aq, 746 (struct efa_admin_aq_entry *)&cmd, 747 sizeof(cmd), 748 (struct efa_admin_acq_entry *)&resp, 749 sizeof(resp)); 750 if (err) { 751 ibdev_err_ratelimited( 752 edev->efa_dev, 753 "Failed to get stats type-%u scope-%u.%u [%d]\n", 754 cmd.type, cmd.scope, cmd.scope_modifier, err); 755 return err; 756 } 757 758 result->basic_stats.tx_bytes = resp.basic_stats.tx_bytes; 759 result->basic_stats.tx_pkts = resp.basic_stats.tx_pkts; 760 result->basic_stats.rx_bytes = resp.basic_stats.rx_bytes; 761 result->basic_stats.rx_pkts = resp.basic_stats.rx_pkts; 762 result->basic_stats.rx_drops = resp.basic_stats.rx_drops; 763 764 return 0; 765 } 766