On 26-Feb-19 21:32, Leon Romanovsky wrote: > On Thu, Feb 21, 2019 at 05:33:10PM +0200, Gal Pressman wrote: >> Add the EFA common commands implementation. >> >> Signed-off-by: Gal Pressman <galpress@xxxxxxxxxx> >> --- >> drivers/infiniband/hw/efa/efa_com_cmd.c | 726 ++++++++++++++++++++++++++++++++ >> 1 file changed, 726 insertions(+) >> create mode 100644 drivers/infiniband/hw/efa/efa_com_cmd.c >> >> diff --git a/drivers/infiniband/hw/efa/efa_com_cmd.c b/drivers/infiniband/hw/efa/efa_com_cmd.c >> new file mode 100644 >> index 000000000000..05eb8f723197 >> --- /dev/null >> +++ b/drivers/infiniband/hw/efa/efa_com_cmd.c >> @@ -0,0 +1,726 @@ >> +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause >> +/* >> + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All rights reserved. >> + */ >> + >> +#include "efa.h" >> +#include "efa_com.h" >> +#include "efa_com_cmd.h" >> + >> +void efa_com_set_dma_addr(dma_addr_t addr, u32 *addr_high, u32 *addr_low) >> +{ >> + *addr_low = addr & GENMASK(31, 0); >> + *addr_high = (addr >> 32) & GENMASK(31, 0); >> +} >> + >> +int efa_com_create_qp(struct efa_com_dev *edev, >> + struct efa_com_create_qp_params *params, >> + struct efa_com_create_qp_result *res) >> +{ >> + struct efa_admin_create_qp_resp cmd_completion; >> + struct efa_admin_create_qp_cmd create_qp_cmd; >> + struct efa_com_admin_queue *aq = &edev->aq; >> + int err; >> + >> + memset(&create_qp_cmd, 0x0, sizeof(create_qp_cmd)); > > Prefer {} initialization over memset(). ACK. > >> + >> + create_qp_cmd.aq_common_desc.opcode = EFA_ADMIN_CREATE_QP; >> + >> + create_qp_cmd.pd = params->pd; >> + create_qp_cmd.qp_type = params->qp_type; >> + create_qp_cmd.flags = 0; >> + create_qp_cmd.sq_base_addr = 0; >> + create_qp_cmd.rq_base_addr = params->rq_base_addr; >> + create_qp_cmd.send_cq_idx = params->send_cq_idx; >> + create_qp_cmd.recv_cq_idx = params->recv_cq_idx; >> + create_qp_cmd.qp_alloc_size.send_queue_ring_size = >> + params->sq_ring_size_in_bytes; >> + create_qp_cmd.qp_alloc_size.send_queue_depth = >> + params->sq_depth; >> + create_qp_cmd.qp_alloc_size.recv_queue_ring_size = >> + params->rq_ring_size_in_bytes; >> + create_qp_cmd.qp_alloc_size.recv_queue_depth = >> + params->rq_depth; >> + create_qp_cmd.uar = params->uarn; >> + >> + err = efa_com_cmd_exec(aq, >> + (struct efa_admin_aq_entry *)&create_qp_cmd, >> + sizeof(create_qp_cmd), >> + (struct efa_admin_acq_entry *)&cmd_completion, >> + sizeof(cmd_completion)); >> + if (unlikely(err)) { > > There is no need to add likely/unlikely not in data path. Doesn't hurt though, right? > >> + efa_err(edev->dmadev, "Failed to create qp [%d]\n", err); >> + return err; >> + } >> + >> + res->qp_handle = cmd_completion.qp_handle; >> + res->qp_num = cmd_completion.qp_num; >> + res->sq_db_offset = cmd_completion.sq_db_offset; >> + res->rq_db_offset = cmd_completion.rq_db_offset; >> + res->llq_descriptors_offset = cmd_completion.llq_descriptors_offset; >> + res->send_sub_cq_idx = cmd_completion.send_sub_cq_idx; >> + res->recv_sub_cq_idx = cmd_completion.recv_sub_cq_idx; >> + >> + return err; >> +} >> + >> +int efa_com_modify_qp(struct efa_com_dev *edev, >> + struct efa_com_modify_qp_params *params) >> +{ >> + struct efa_com_admin_queue *aq = &edev->aq; >> + struct efa_admin_modify_qp_resp resp; >> + struct efa_admin_modify_qp_cmd cmd; >> + int err; >> + >> + memset(&cmd, 0, sizeof(cmd)); >> + cmd.aq_common_desc.opcode = EFA_ADMIN_MODIFY_QP; >> + cmd.modify_mask = params->modify_mask; >> + cmd.qp_handle = params->qp_handle; >> + cmd.qp_state = params->qp_state; >> + cmd.cur_qp_state = params->cur_qp_state; >> + cmd.qkey = params->qkey; >> + cmd.sq_psn = params->sq_psn; >> + cmd.sq_drained_async_notify = params->sq_drained_async_notify; >> + >> + err = efa_com_cmd_exec(aq, >> + (struct efa_admin_aq_entry *)&cmd, >> + sizeof(cmd), >> + (struct efa_admin_acq_entry *)&resp, >> + sizeof(resp)); >> + if (unlikely(err)) { >> + efa_err(edev->dmadev, "Failed to modify qp-%u modify_mask[%#x] [%d]\n", >> + cmd.qp_handle, cmd.modify_mask, err); >> + return err; >> + } >> + >> + return 0; >> +} >> + >> +int efa_com_query_qp(struct efa_com_dev *edev, >> + struct efa_com_query_qp_params *params, >> + struct efa_com_query_qp_result *result) >> +{ >> + struct efa_com_admin_queue *aq = &edev->aq; >> + struct efa_admin_query_qp_resp resp; >> + struct efa_admin_query_qp_cmd cmd; >> + int err; >> + >> + memset(&cmd, 0, sizeof(cmd)); >> + cmd.aq_common_desc.opcode = EFA_ADMIN_QUERY_QP; >> + cmd.qp_handle = params->qp_handle; >> + >> + err = efa_com_cmd_exec(aq, >> + (struct efa_admin_aq_entry *)&cmd, >> + sizeof(cmd), >> + (struct efa_admin_acq_entry *)&resp, >> + sizeof(resp)); >> + if (unlikely(err)) { >> + efa_err(edev->dmadev, "Failed to query qp-%u [%d]\n", >> + cmd.qp_handle, err); >> + return err; >> + } >> + >> + result->qp_state = resp.qp_state; >> + result->qkey = resp.qkey; >> + result->sq_draining = resp.sq_draining; >> + result->sq_psn = resp.sq_psn; >> + >> + return 0; >> +} >> + >> +int efa_com_destroy_qp(struct efa_com_dev *edev, >> + struct efa_com_destroy_qp_params *params) >> +{ >> + struct efa_admin_destroy_qp_resp cmd_completion; >> + struct efa_com_admin_queue *aq = &edev->aq; >> + struct efa_admin_destroy_qp_cmd qp_cmd; >> + int err; >> + >> + memset(&qp_cmd, 0x0, sizeof(qp_cmd)); >> + >> + qp_cmd.aq_common_desc.opcode = EFA_ADMIN_DESTROY_QP; >> + >> + qp_cmd.qp_handle = params->qp_handle; >> + >> + err = efa_com_cmd_exec(aq, >> + (struct efa_admin_aq_entry *)&qp_cmd, >> + sizeof(qp_cmd), >> + (struct efa_admin_acq_entry *)&cmd_completion, >> + sizeof(cmd_completion)); >> + if (unlikely(err)) >> + efa_err(edev->dmadev, "Failed to destroy qp-%u [%d]\n", >> + qp_cmd.qp_handle, err); >> + >> + return err; >> +} >> + >> +int efa_com_create_cq(struct efa_com_dev *edev, >> + struct efa_com_create_cq_params *params, >> + struct efa_com_create_cq_result *result) >> +{ >> + struct efa_admin_create_cq_resp cmd_completion; >> + struct efa_com_admin_queue *aq = &edev->aq; >> + struct efa_admin_create_cq_cmd create_cmd; >> + int err; >> + >> + memset(&create_cmd, 0x0, sizeof(create_cmd)); >> + create_cmd.aq_common_desc.opcode = EFA_ADMIN_CREATE_CQ; >> + create_cmd.cq_caps_2 = (params->entry_size_in_bytes / 4) & >> + EFA_ADMIN_CREATE_CQ_CMD_CQ_ENTRY_SIZE_WORDS_MASK; >> + create_cmd.msix_vector_idx = 0; > > You already initialized everything to zero. ACK.