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