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 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 EFA_SET(&get_cmd.aq_common_descriptor.flags, 391 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT, 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 484 err = efa_com_get_feature(edev, &resp, EFA_ADMIN_NETWORK_ATTR); 485 if (err) { 486 ibdev_err_ratelimited(edev->efa_dev, 487 "Failed to get network attributes %d\n", 488 err); 489 return err; 490 } 491 492 memcpy(result->addr, resp.u.network_attr.addr, 493 sizeof(resp.u.network_attr.addr)); 494 result->mtu = resp.u.network_attr.mtu; 495 496 return 0; 497 } 498 499 int efa_com_get_hw_hints(struct efa_com_dev *edev, 500 struct efa_com_get_hw_hints_result *result) 501 { 502 struct efa_admin_get_feature_resp resp; 503 int err; 504 505 err = efa_com_get_feature(edev, &resp, EFA_ADMIN_HW_HINTS); 506 if (err) { 507 ibdev_err_ratelimited(edev->efa_dev, 508 "Failed to get hw hints %d\n", err); 509 return err; 510 } 511 512 result->admin_completion_timeout = resp.u.hw_hints.admin_completion_timeout; 513 result->driver_watchdog_timeout = resp.u.hw_hints.driver_watchdog_timeout; 514 result->mmio_read_timeout = resp.u.hw_hints.mmio_read_timeout; 515 result->poll_interval = resp.u.hw_hints.poll_interval; 516 517 return 0; 518 } 519 520 static int efa_com_set_feature_ex(struct efa_com_dev *edev, 521 struct efa_admin_set_feature_resp *set_resp, 522 struct efa_admin_set_feature_cmd *set_cmd, 523 enum efa_admin_aq_feature_id feature_id, 524 dma_addr_t control_buf_dma_addr, 525 u32 control_buff_size) 526 { 527 struct efa_com_admin_queue *aq; 528 int err; 529 530 if (!efa_com_check_supported_feature_id(edev, feature_id)) { 531 ibdev_err_ratelimited(edev->efa_dev, 532 "Feature %d isn't supported\n", 533 feature_id); 534 return -EOPNOTSUPP; 535 } 536 537 aq = &edev->aq; 538 539 set_cmd->aq_common_descriptor.opcode = EFA_ADMIN_SET_FEATURE; 540 if (control_buff_size) { 541 set_cmd->aq_common_descriptor.flags = 0; 542 EFA_SET(&set_cmd->aq_common_descriptor.flags, 543 EFA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT, 1); 544 efa_com_set_dma_addr(control_buf_dma_addr, 545 &set_cmd->control_buffer.address.mem_addr_high, 546 &set_cmd->control_buffer.address.mem_addr_low); 547 } 548 549 set_cmd->control_buffer.length = control_buff_size; 550 set_cmd->feature_common.feature_id = feature_id; 551 err = efa_com_cmd_exec(aq, 552 (struct efa_admin_aq_entry *)set_cmd, 553 sizeof(*set_cmd), 554 (struct efa_admin_acq_entry *)set_resp, 555 sizeof(*set_resp)); 556 557 if (err) { 558 ibdev_err_ratelimited( 559 edev->efa_dev, 560 "Failed to submit set_feature command %d error: %d\n", 561 feature_id, err); 562 return err; 563 } 564 565 return 0; 566 } 567 568 static int efa_com_set_feature(struct efa_com_dev *edev, 569 struct efa_admin_set_feature_resp *set_resp, 570 struct efa_admin_set_feature_cmd *set_cmd, 571 enum efa_admin_aq_feature_id feature_id) 572 { 573 return efa_com_set_feature_ex(edev, set_resp, set_cmd, feature_id, 574 0, 0); 575 } 576 577 int efa_com_set_aenq_config(struct efa_com_dev *edev, u32 groups) 578 { 579 struct efa_admin_get_feature_resp get_resp; 580 struct efa_admin_set_feature_resp set_resp; 581 struct efa_admin_set_feature_cmd cmd = {}; 582 int err; 583 584 ibdev_dbg(edev->efa_dev, "Configuring aenq with groups[%#x]\n", groups); 585 586 err = efa_com_get_feature(edev, &get_resp, EFA_ADMIN_AENQ_CONFIG); 587 if (err) { 588 ibdev_err_ratelimited(edev->efa_dev, 589 "Failed to get aenq attributes: %d\n", 590 err); 591 return err; 592 } 593 594 ibdev_dbg(edev->efa_dev, 595 "Get aenq groups: supported[%#x] enabled[%#x]\n", 596 get_resp.u.aenq.supported_groups, 597 get_resp.u.aenq.enabled_groups); 598 599 if ((get_resp.u.aenq.supported_groups & groups) != groups) { 600 ibdev_err_ratelimited( 601 edev->efa_dev, 602 "Trying to set unsupported aenq groups[%#x] supported[%#x]\n", 603 groups, get_resp.u.aenq.supported_groups); 604 return -EOPNOTSUPP; 605 } 606 607 cmd.u.aenq.enabled_groups = groups; 608 err = efa_com_set_feature(edev, &set_resp, &cmd, 609 EFA_ADMIN_AENQ_CONFIG); 610 if (err) { 611 ibdev_err_ratelimited(edev->efa_dev, 612 "Failed to set aenq attributes: %d\n", 613 err); 614 return err; 615 } 616 617 return 0; 618 } 619 620 int efa_com_alloc_pd(struct efa_com_dev *edev, 621 struct efa_com_alloc_pd_result *result) 622 { 623 struct efa_com_admin_queue *aq = &edev->aq; 624 struct efa_admin_alloc_pd_cmd cmd = {}; 625 struct efa_admin_alloc_pd_resp resp; 626 int err; 627 628 cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_PD; 629 630 err = efa_com_cmd_exec(aq, 631 (struct efa_admin_aq_entry *)&cmd, 632 sizeof(cmd), 633 (struct efa_admin_acq_entry *)&resp, 634 sizeof(resp)); 635 if (err) { 636 ibdev_err_ratelimited(edev->efa_dev, 637 "Failed to allocate pd[%d]\n", err); 638 return err; 639 } 640 641 result->pdn = resp.pd; 642 643 return 0; 644 } 645 646 int efa_com_dealloc_pd(struct efa_com_dev *edev, 647 struct efa_com_dealloc_pd_params *params) 648 { 649 struct efa_com_admin_queue *aq = &edev->aq; 650 struct efa_admin_dealloc_pd_cmd cmd = {}; 651 struct efa_admin_dealloc_pd_resp resp; 652 int err; 653 654 cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_PD; 655 cmd.pd = params->pdn; 656 657 err = efa_com_cmd_exec(aq, 658 (struct efa_admin_aq_entry *)&cmd, 659 sizeof(cmd), 660 (struct efa_admin_acq_entry *)&resp, 661 sizeof(resp)); 662 if (err) { 663 ibdev_err_ratelimited(edev->efa_dev, 664 "Failed to deallocate pd-%u [%d]\n", 665 cmd.pd, err); 666 return err; 667 } 668 669 return 0; 670 } 671 672 int efa_com_alloc_uar(struct efa_com_dev *edev, 673 struct efa_com_alloc_uar_result *result) 674 { 675 struct efa_com_admin_queue *aq = &edev->aq; 676 struct efa_admin_alloc_uar_cmd cmd = {}; 677 struct efa_admin_alloc_uar_resp resp; 678 int err; 679 680 cmd.aq_common_descriptor.opcode = EFA_ADMIN_ALLOC_UAR; 681 682 err = efa_com_cmd_exec(aq, 683 (struct efa_admin_aq_entry *)&cmd, 684 sizeof(cmd), 685 (struct efa_admin_acq_entry *)&resp, 686 sizeof(resp)); 687 if (err) { 688 ibdev_err_ratelimited(edev->efa_dev, 689 "Failed to allocate uar[%d]\n", err); 690 return err; 691 } 692 693 result->uarn = resp.uar; 694 695 return 0; 696 } 697 698 int efa_com_dealloc_uar(struct efa_com_dev *edev, 699 struct efa_com_dealloc_uar_params *params) 700 { 701 struct efa_com_admin_queue *aq = &edev->aq; 702 struct efa_admin_dealloc_uar_cmd cmd = {}; 703 struct efa_admin_dealloc_uar_resp resp; 704 int err; 705 706 cmd.aq_common_descriptor.opcode = EFA_ADMIN_DEALLOC_UAR; 707 cmd.uar = params->uarn; 708 709 err = efa_com_cmd_exec(aq, 710 (struct efa_admin_aq_entry *)&cmd, 711 sizeof(cmd), 712 (struct efa_admin_acq_entry *)&resp, 713 sizeof(resp)); 714 if (err) { 715 ibdev_err_ratelimited(edev->efa_dev, 716 "Failed to deallocate uar-%u [%d]\n", 717 cmd.uar, err); 718 return err; 719 } 720 721 return 0; 722 } 723 724 int efa_com_get_stats(struct efa_com_dev *edev, 725 struct efa_com_get_stats_params *params, 726 union efa_com_get_stats_result *result) 727 { 728 struct efa_com_admin_queue *aq = &edev->aq; 729 struct efa_admin_aq_get_stats_cmd cmd = {}; 730 struct efa_admin_acq_get_stats_resp resp; 731 int err; 732 733 cmd.aq_common_descriptor.opcode = EFA_ADMIN_GET_STATS; 734 cmd.type = params->type; 735 cmd.scope = params->scope; 736 cmd.scope_modifier = params->scope_modifier; 737 738 err = efa_com_cmd_exec(aq, 739 (struct efa_admin_aq_entry *)&cmd, 740 sizeof(cmd), 741 (struct efa_admin_acq_entry *)&resp, 742 sizeof(resp)); 743 if (err) { 744 ibdev_err_ratelimited( 745 edev->efa_dev, 746 "Failed to get stats type-%u scope-%u.%u [%d]\n", 747 cmd.type, cmd.scope, cmd.scope_modifier, err); 748 return err; 749 } 750 751 result->basic_stats.tx_bytes = resp.basic_stats.tx_bytes; 752 result->basic_stats.tx_pkts = resp.basic_stats.tx_pkts; 753 result->basic_stats.rx_bytes = resp.basic_stats.rx_bytes; 754 result->basic_stats.rx_pkts = resp.basic_stats.rx_pkts; 755 result->basic_stats.rx_drops = resp.basic_stats.rx_drops; 756 757 return 0; 758 } 759