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