From patchwork Fri Feb 3 09:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xing, Beilei" X-Patchwork-Id: 123020 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2CE8B41BBB; Fri, 3 Feb 2023 11:10:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 698F542D40; Fri, 3 Feb 2023 11:10:26 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id ABC6940A79 for ; Fri, 3 Feb 2023 11:10:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675419021; x=1706955021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UJCrMw+JfAzM2fTqjX3mFl2xSweHYvj5dyFPQdeovjw=; b=B8KSZWqP70KF2jZrYUNq7uUtAlpmoeCOC65IzYXwL/ziBYRKCgmoR16f SvBnE45aQ+drvt4C7bpMx1a3FjkKR5klFTzaivhy2vo1C91zmhoOJapBi VSwsPEPEjaBxezxnQcT+bLY2ofi/o1ZAv9FgyB4pSO3VGNH1hBcUE/XxV XCiNX0JuX4tya1MS5skK1sY9QGPMFgiaj7USQU8Qp5Nrw05SG85vT2ssH AI6Usv1JZ3/fu/ylxNg+vm/71/HRWFAWfoK/2FLbDVkEAWb2M8dE8OSrE hRsqvV4V2XAbStUeOth+PLxRDsCgvAWOIr+SuBkKHBW/SChSlJ2drAMqS A==; X-IronPort-AV: E=McAfee;i="6500,9779,10609"; a="356052787" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="356052787" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2023 02:10:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10609"; a="659047778" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="659047778" Received: from dpdk-beileix-3.sh.intel.com ([10.67.110.253]) by orsmga007.jf.intel.com with ESMTP; 03 Feb 2023 02:10:10 -0800 From: beilei.xing@intel.com To: jingjing.wu@intel.com Cc: dev@dpdk.org, qi.z.zhang@intel.com, Beilei Xing , Wenjun Wu Subject: [PATCH v6 03/19] common/idpf: add virtual channel functions Date: Fri, 3 Feb 2023 09:43:24 +0000 Message-Id: <20230203094340.8103-4-beilei.xing@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20230203094340.8103-1-beilei.xing@intel.com> References: <20230202095357.37929-1-beilei.xing@intel.com> <20230203094340.8103-1-beilei.xing@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Beilei Xing Move most of the virtual channel functions to idpf common module. Signed-off-by: Wenjun Wu Signed-off-by: Beilei Xing --- drivers/common/idpf/base/idpf_controlq_api.h | 4 - drivers/common/idpf/base/meson.build | 2 +- drivers/common/idpf/idpf_common_device.c | 8 + drivers/common/idpf/idpf_common_device.h | 61 ++ drivers/common/idpf/idpf_common_logs.h | 23 + drivers/common/idpf/idpf_common_virtchnl.c | 815 ++++++++++++++++++ drivers/common/idpf/idpf_common_virtchnl.h | 48 ++ drivers/common/idpf/meson.build | 5 + drivers/common/idpf/version.map | 20 +- drivers/net/idpf/idpf_ethdev.c | 9 +- drivers/net/idpf/idpf_ethdev.h | 85 +- drivers/net/idpf/idpf_rxtx.c | 8 +- drivers/net/idpf/idpf_vchnl.c | 817 +------------------ 13 files changed, 986 insertions(+), 919 deletions(-) create mode 100644 drivers/common/idpf/idpf_common_device.c create mode 100644 drivers/common/idpf/idpf_common_logs.h create mode 100644 drivers/common/idpf/idpf_common_virtchnl.c create mode 100644 drivers/common/idpf/idpf_common_virtchnl.h diff --git a/drivers/common/idpf/base/idpf_controlq_api.h b/drivers/common/idpf/base/idpf_controlq_api.h index 68ac0cfe70..891a0f10f6 100644 --- a/drivers/common/idpf/base/idpf_controlq_api.h +++ b/drivers/common/idpf/base/idpf_controlq_api.h @@ -177,7 +177,6 @@ void idpf_ctlq_remove(struct idpf_hw *hw, struct idpf_ctlq_info *cq); /* Sends messages to HW and will also free the buffer*/ -__rte_internal int idpf_ctlq_send(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg, @@ -186,17 +185,14 @@ int idpf_ctlq_send(struct idpf_hw *hw, /* Receives messages and called by interrupt handler/polling * initiated by app/process. Also caller is supposed to free the buffers */ -__rte_internal int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg, struct idpf_ctlq_msg *q_msg); /* Reclaims send descriptors on HW write back */ -__rte_internal int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count, struct idpf_ctlq_msg *msg_status[]); /* Indicate RX buffers are done being processed */ -__rte_internal int idpf_ctlq_post_rx_buffs(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 *buff_count, diff --git a/drivers/common/idpf/base/meson.build b/drivers/common/idpf/base/meson.build index 183587b51a..dc4b93c198 100644 --- a/drivers/common/idpf/base/meson.build +++ b/drivers/common/idpf/base/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2022 Intel Corporation -sources = files( +sources += files( 'idpf_common.c', 'idpf_controlq.c', 'idpf_controlq_setup.c', diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c new file mode 100644 index 0000000000..5062780362 --- /dev/null +++ b/drivers/common/idpf/idpf_common_device.c @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#include +#include + +RTE_LOG_REGISTER_SUFFIX(idpf_common_logtype, common, NOTICE); diff --git a/drivers/common/idpf/idpf_common_device.h b/drivers/common/idpf/idpf_common_device.h index b7fff84b25..a7537281d1 100644 --- a/drivers/common/idpf/idpf_common_device.h +++ b/drivers/common/idpf/idpf_common_device.h @@ -7,6 +7,12 @@ #include #include +#include + +#define IDPF_CTLQ_LEN 64 +#define IDPF_DFLT_MBX_BUF_SIZE 4096 + +#define IDPF_MAX_PKT_TYPE 1024 struct idpf_adapter { struct idpf_hw hw; @@ -76,4 +82,59 @@ struct idpf_vport { bool stopped; }; +/* Message type read in virtual channel from PF */ +enum idpf_vc_result { + IDPF_MSG_ERR = -1, /* Meet error when accessing admin queue */ + IDPF_MSG_NON, /* Read nothing from admin queue */ + IDPF_MSG_SYS, /* Read system msg from admin queue */ + IDPF_MSG_CMD, /* Read async command result */ +}; + +/* structure used for sending and checking response of virtchnl ops */ +struct idpf_cmd_info { + uint32_t ops; + uint8_t *in_args; /* buffer for sending */ + uint32_t in_args_size; /* buffer size for sending */ + uint8_t *out_buffer; /* buffer for response */ + uint32_t out_size; /* buffer size for response */ +}; + +/* notify current command done. Only call in case execute + * _atomic_set_cmd successfully. + */ +static inline void +notify_cmd(struct idpf_adapter *adapter, int msg_ret) +{ + adapter->cmd_retval = msg_ret; + /* Return value may be checked in anither thread, need to ensure the coherence. */ + rte_wmb(); + adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; +} + +/* clear current command. Only call in case execute + * _atomic_set_cmd successfully. + */ +static inline void +clear_cmd(struct idpf_adapter *adapter) +{ + /* Return value may be checked in anither thread, need to ensure the coherence. */ + rte_wmb(); + adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; + adapter->cmd_retval = VIRTCHNL_STATUS_SUCCESS; +} + +/* Check there is pending cmd in execution. If none, set new command. */ +static inline bool +atomic_set_cmd(struct idpf_adapter *adapter, uint32_t ops) +{ + uint32_t op_unk = VIRTCHNL2_OP_UNKNOWN; + bool ret = __atomic_compare_exchange(&adapter->pend_cmd, &op_unk, &ops, + 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); + + if (!ret) + DRV_LOG(ERR, "There is incomplete cmd %d", adapter->pend_cmd); + + return !ret; +} + #endif /* _IDPF_COMMON_DEVICE_H_ */ diff --git a/drivers/common/idpf/idpf_common_logs.h b/drivers/common/idpf/idpf_common_logs.h new file mode 100644 index 0000000000..fe36562769 --- /dev/null +++ b/drivers/common/idpf/idpf_common_logs.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#ifndef _IDPF_COMMON_LOGS_H_ +#define _IDPF_COMMON_LOGS_H_ + +#include + +extern int idpf_common_logtype; + +#define DRV_LOG_RAW(level, ...) \ + rte_log(RTE_LOG_ ## level, \ + idpf_common_logtype, \ + RTE_FMT("%s(): " \ + RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ + __func__, \ + RTE_FMT_TAIL(__VA_ARGS__,))) + +#define DRV_LOG(level, fmt, args...) \ + DRV_LOG_RAW(level, fmt "\n", ## args) + +#endif /* _IDPF_COMMON_LOGS_H_ */ diff --git a/drivers/common/idpf/idpf_common_virtchnl.c b/drivers/common/idpf/idpf_common_virtchnl.c new file mode 100644 index 0000000000..f86c1abf0f --- /dev/null +++ b/drivers/common/idpf/idpf_common_virtchnl.c @@ -0,0 +1,815 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#include +#include + +static int +idpf_vc_clean(struct idpf_adapter *adapter) +{ + struct idpf_ctlq_msg *q_msg[IDPF_CTLQ_LEN]; + uint16_t num_q_msg = IDPF_CTLQ_LEN; + struct idpf_dma_mem *dma_mem; + int err; + uint32_t i; + + for (i = 0; i < 10; i++) { + err = idpf_ctlq_clean_sq(adapter->hw.asq, &num_q_msg, q_msg); + msleep(20); + if (num_q_msg > 0) + break; + } + if (err != 0) + return err; + + /* Empty queue is not an error */ + for (i = 0; i < num_q_msg; i++) { + dma_mem = q_msg[i]->ctx.indirect.payload; + if (dma_mem != NULL) { + idpf_free_dma_mem(&adapter->hw, dma_mem); + rte_free(dma_mem); + } + rte_free(q_msg[i]); + } + + return 0; +} + +static int +idpf_send_vc_msg(struct idpf_adapter *adapter, uint32_t op, + uint16_t msg_size, uint8_t *msg) +{ + struct idpf_ctlq_msg *ctlq_msg; + struct idpf_dma_mem *dma_mem; + int err; + + err = idpf_vc_clean(adapter); + if (err != 0) + goto err; + + ctlq_msg = rte_zmalloc(NULL, sizeof(struct idpf_ctlq_msg), 0); + if (ctlq_msg == NULL) { + err = -ENOMEM; + goto err; + } + + dma_mem = rte_zmalloc(NULL, sizeof(struct idpf_dma_mem), 0); + if (dma_mem == NULL) { + err = -ENOMEM; + goto dma_mem_error; + } + + dma_mem->size = IDPF_DFLT_MBX_BUF_SIZE; + idpf_alloc_dma_mem(&adapter->hw, dma_mem, dma_mem->size); + if (dma_mem->va == NULL) { + err = -ENOMEM; + goto dma_alloc_error; + } + + memcpy(dma_mem->va, msg, msg_size); + + ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_pf; + ctlq_msg->func_id = 0; + ctlq_msg->data_len = msg_size; + ctlq_msg->cookie.mbx.chnl_opcode = op; + ctlq_msg->cookie.mbx.chnl_retval = VIRTCHNL_STATUS_SUCCESS; + ctlq_msg->ctx.indirect.payload = dma_mem; + + err = idpf_ctlq_send(&adapter->hw, adapter->hw.asq, 1, ctlq_msg); + if (err != 0) + goto send_error; + + return 0; + +send_error: + idpf_free_dma_mem(&adapter->hw, dma_mem); +dma_alloc_error: + rte_free(dma_mem); +dma_mem_error: + rte_free(ctlq_msg); +err: + return err; +} + +static enum idpf_vc_result +idpf_read_msg_from_cp(struct idpf_adapter *adapter, uint16_t buf_len, + uint8_t *buf) +{ + struct idpf_hw *hw = &adapter->hw; + struct idpf_ctlq_msg ctlq_msg; + struct idpf_dma_mem *dma_mem = NULL; + enum idpf_vc_result result = IDPF_MSG_NON; + uint32_t opcode; + uint16_t pending = 1; + int ret; + + ret = idpf_ctlq_recv(hw->arq, &pending, &ctlq_msg); + if (ret != 0) { + DRV_LOG(DEBUG, "Can't read msg from AQ"); + if (ret != -ENOMSG) + result = IDPF_MSG_ERR; + return result; + } + + rte_memcpy(buf, ctlq_msg.ctx.indirect.payload->va, buf_len); + + opcode = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_opcode); + adapter->cmd_retval = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_retval); + + DRV_LOG(DEBUG, "CQ from CP carries opcode %u, retval %d", + opcode, adapter->cmd_retval); + + if (opcode == VIRTCHNL2_OP_EVENT) { + struct virtchnl2_event *ve = ctlq_msg.ctx.indirect.payload->va; + + result = IDPF_MSG_SYS; + switch (ve->event) { + case VIRTCHNL2_EVENT_LINK_CHANGE: + /* TBD */ + break; + default: + DRV_LOG(ERR, "%s: Unknown event %d from CP", + __func__, ve->event); + break; + } + } else { + /* async reply msg on command issued by pf previously */ + result = IDPF_MSG_CMD; + if (opcode != adapter->pend_cmd) { + DRV_LOG(WARNING, "command mismatch, expect %u, get %u", + adapter->pend_cmd, opcode); + result = IDPF_MSG_ERR; + } + } + + if (ctlq_msg.data_len != 0) + dma_mem = ctlq_msg.ctx.indirect.payload; + else + pending = 0; + + ret = idpf_ctlq_post_rx_buffs(hw, hw->arq, &pending, &dma_mem); + if (ret != 0 && dma_mem != NULL) + idpf_free_dma_mem(hw, dma_mem); + + return result; +} + +#define MAX_TRY_TIMES 200 +#define ASQ_DELAY_MS 10 + +int +idpf_vc_read_one_msg(struct idpf_adapter *adapter, uint32_t ops, uint16_t buf_len, + uint8_t *buf) +{ + int err = 0; + int i = 0; + int ret; + + do { + ret = idpf_read_msg_from_cp(adapter, buf_len, buf); + if (ret == IDPF_MSG_CMD) + break; + rte_delay_ms(ASQ_DELAY_MS); + } while (i++ < MAX_TRY_TIMES); + if (i >= MAX_TRY_TIMES || + adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) { + err = -EBUSY; + DRV_LOG(ERR, "No response or return failure (%d) for cmd %d", + adapter->cmd_retval, ops); + } + + return err; +} + +int +idpf_execute_vc_cmd(struct idpf_adapter *adapter, struct idpf_cmd_info *args) +{ + int err = 0; + int i = 0; + int ret; + + if (atomic_set_cmd(adapter, args->ops)) + return -EINVAL; + + ret = idpf_send_vc_msg(adapter, args->ops, args->in_args_size, args->in_args); + if (ret != 0) { + DRV_LOG(ERR, "fail to send cmd %d", args->ops); + clear_cmd(adapter); + return ret; + } + + switch (args->ops) { + case VIRTCHNL_OP_VERSION: + case VIRTCHNL2_OP_GET_CAPS: + case VIRTCHNL2_OP_CREATE_VPORT: + case VIRTCHNL2_OP_DESTROY_VPORT: + case VIRTCHNL2_OP_SET_RSS_KEY: + case VIRTCHNL2_OP_SET_RSS_LUT: + case VIRTCHNL2_OP_SET_RSS_HASH: + case VIRTCHNL2_OP_CONFIG_RX_QUEUES: + case VIRTCHNL2_OP_CONFIG_TX_QUEUES: + case VIRTCHNL2_OP_ENABLE_QUEUES: + case VIRTCHNL2_OP_DISABLE_QUEUES: + case VIRTCHNL2_OP_ENABLE_VPORT: + case VIRTCHNL2_OP_DISABLE_VPORT: + case VIRTCHNL2_OP_MAP_QUEUE_VECTOR: + case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR: + case VIRTCHNL2_OP_ALLOC_VECTORS: + case VIRTCHNL2_OP_DEALLOC_VECTORS: + /* for init virtchnl ops, need to poll the response */ + err = idpf_vc_read_one_msg(adapter, args->ops, args->out_size, args->out_buffer); + clear_cmd(adapter); + break; + case VIRTCHNL2_OP_GET_PTYPE_INFO: + /* for multuple response message, + * do not handle the response here. + */ + break; + default: + /* For other virtchnl ops in running time, + * wait for the cmd done flag. + */ + do { + if (adapter->pend_cmd == VIRTCHNL_OP_UNKNOWN) + break; + rte_delay_ms(ASQ_DELAY_MS); + /* If don't read msg or read sys event, continue */ + } while (i++ < MAX_TRY_TIMES); + /* If there's no response is received, clear command */ + if (i >= MAX_TRY_TIMES || + adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) { + err = -EBUSY; + DRV_LOG(ERR, "No response or return failure (%d) for cmd %d", + adapter->cmd_retval, args->ops); + clear_cmd(adapter); + } + break; + } + + return err; +} + +int +idpf_vc_check_api_version(struct idpf_adapter *adapter) +{ + struct virtchnl2_version_info version, *pver; + struct idpf_cmd_info args; + int err; + + memset(&version, 0, sizeof(struct virtchnl_version_info)); + version.major = VIRTCHNL2_VERSION_MAJOR_2; + version.minor = VIRTCHNL2_VERSION_MINOR_0; + + args.ops = VIRTCHNL_OP_VERSION; + args.in_args = (uint8_t *)&version; + args.in_args_size = sizeof(version); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) { + DRV_LOG(ERR, + "Failed to execute command of VIRTCHNL_OP_VERSION"); + return err; + } + + pver = (struct virtchnl2_version_info *)args.out_buffer; + adapter->virtchnl_version = *pver; + + if (adapter->virtchnl_version.major != VIRTCHNL2_VERSION_MAJOR_2 || + adapter->virtchnl_version.minor != VIRTCHNL2_VERSION_MINOR_0) { + DRV_LOG(ERR, "VIRTCHNL API version mismatch:(%u.%u)-(%u.%u)", + adapter->virtchnl_version.major, + adapter->virtchnl_version.minor, + VIRTCHNL2_VERSION_MAJOR_2, + VIRTCHNL2_VERSION_MINOR_0); + return -EINVAL; + } + + return 0; +} + +int +idpf_vc_get_caps(struct idpf_adapter *adapter) +{ + struct virtchnl2_get_capabilities caps_msg; + struct idpf_cmd_info args; + int err; + + memset(&caps_msg, 0, sizeof(struct virtchnl2_get_capabilities)); + + caps_msg.csum_caps = + VIRTCHNL2_CAP_TX_CSUM_L3_IPV4 | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP | + VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP | + VIRTCHNL2_CAP_TX_CSUM_GENERIC | + VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP | + VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP | + VIRTCHNL2_CAP_RX_CSUM_GENERIC; + + caps_msg.rss_caps = + VIRTCHNL2_CAP_RSS_IPV4_TCP | + VIRTCHNL2_CAP_RSS_IPV4_UDP | + VIRTCHNL2_CAP_RSS_IPV4_SCTP | + VIRTCHNL2_CAP_RSS_IPV4_OTHER | + VIRTCHNL2_CAP_RSS_IPV6_TCP | + VIRTCHNL2_CAP_RSS_IPV6_UDP | + VIRTCHNL2_CAP_RSS_IPV6_SCTP | + VIRTCHNL2_CAP_RSS_IPV6_OTHER | + VIRTCHNL2_CAP_RSS_IPV4_AH | + VIRTCHNL2_CAP_RSS_IPV4_ESP | + VIRTCHNL2_CAP_RSS_IPV4_AH_ESP | + VIRTCHNL2_CAP_RSS_IPV6_AH | + VIRTCHNL2_CAP_RSS_IPV6_ESP | + VIRTCHNL2_CAP_RSS_IPV6_AH_ESP; + + caps_msg.other_caps = VIRTCHNL2_CAP_WB_ON_ITR; + + args.ops = VIRTCHNL2_OP_GET_CAPS; + args.in_args = (uint8_t *)&caps_msg; + args.in_args_size = sizeof(caps_msg); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) { + DRV_LOG(ERR, + "Failed to execute command of VIRTCHNL2_OP_GET_CAPS"); + return err; + } + + rte_memcpy(&adapter->caps, args.out_buffer, sizeof(caps_msg)); + + return 0; +} + +int +idpf_vc_create_vport(struct idpf_vport *vport, + struct virtchnl2_create_vport *vport_req_info) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_create_vport vport_msg; + struct idpf_cmd_info args; + int err = -1; + + memset(&vport_msg, 0, sizeof(struct virtchnl2_create_vport)); + vport_msg.vport_type = vport_req_info->vport_type; + vport_msg.txq_model = vport_req_info->txq_model; + vport_msg.rxq_model = vport_req_info->rxq_model; + vport_msg.num_tx_q = vport_req_info->num_tx_q; + vport_msg.num_tx_complq = vport_req_info->num_tx_complq; + vport_msg.num_rx_q = vport_req_info->num_rx_q; + vport_msg.num_rx_bufq = vport_req_info->num_rx_bufq; + + memset(&args, 0, sizeof(args)); + args.ops = VIRTCHNL2_OP_CREATE_VPORT; + args.in_args = (uint8_t *)&vport_msg; + args.in_args_size = sizeof(vport_msg); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) { + DRV_LOG(ERR, + "Failed to execute command of VIRTCHNL2_OP_CREATE_VPORT"); + return err; + } + + rte_memcpy(vport->vport_info, args.out_buffer, IDPF_DFLT_MBX_BUF_SIZE); + return 0; +} + +int +idpf_vc_destroy_vport(struct idpf_vport *vport) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_vport vc_vport; + struct idpf_cmd_info args; + int err; + + vc_vport.vport_id = vport->vport_id; + + memset(&args, 0, sizeof(args)); + args.ops = VIRTCHNL2_OP_DESTROY_VPORT; + args.in_args = (uint8_t *)&vc_vport; + args.in_args_size = sizeof(vc_vport); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_DESTROY_VPORT"); + + return err; +} + +int +idpf_vc_set_rss_key(struct idpf_vport *vport) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_rss_key *rss_key; + struct idpf_cmd_info args; + int len, err; + + len = sizeof(*rss_key) + sizeof(rss_key->key[0]) * + (vport->rss_key_size - 1); + rss_key = rte_zmalloc("rss_key", len, 0); + if (rss_key == NULL) + return -ENOMEM; + + rss_key->vport_id = vport->vport_id; + rss_key->key_len = vport->rss_key_size; + rte_memcpy(rss_key->key, vport->rss_key, + sizeof(rss_key->key[0]) * vport->rss_key_size); + + memset(&args, 0, sizeof(args)); + args.ops = VIRTCHNL2_OP_SET_RSS_KEY; + args.in_args = (uint8_t *)rss_key; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_KEY"); + + rte_free(rss_key); + return err; +} + +int +idpf_vc_set_rss_lut(struct idpf_vport *vport) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_rss_lut *rss_lut; + struct idpf_cmd_info args; + int len, err; + + len = sizeof(*rss_lut) + sizeof(rss_lut->lut[0]) * + (vport->rss_lut_size - 1); + rss_lut = rte_zmalloc("rss_lut", len, 0); + if (rss_lut == NULL) + return -ENOMEM; + + rss_lut->vport_id = vport->vport_id; + rss_lut->lut_entries = vport->rss_lut_size; + rte_memcpy(rss_lut->lut, vport->rss_lut, + sizeof(rss_lut->lut[0]) * vport->rss_lut_size); + + memset(&args, 0, sizeof(args)); + args.ops = VIRTCHNL2_OP_SET_RSS_LUT; + args.in_args = (uint8_t *)rss_lut; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_LUT"); + + rte_free(rss_lut); + return err; +} + +int +idpf_vc_set_rss_hash(struct idpf_vport *vport) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_rss_hash rss_hash; + struct idpf_cmd_info args; + int err; + + memset(&rss_hash, 0, sizeof(rss_hash)); + rss_hash.ptype_groups = vport->rss_hf; + rss_hash.vport_id = vport->vport_id; + + memset(&args, 0, sizeof(args)); + args.ops = VIRTCHNL2_OP_SET_RSS_HASH; + args.in_args = (uint8_t *)&rss_hash; + args.in_args_size = sizeof(rss_hash); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of OP_SET_RSS_HASH"); + + return err; +} + +int +idpf_vc_config_irq_map_unmap(struct idpf_vport *vport, uint16_t nb_rxq, bool map) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_queue_vector_maps *map_info; + struct virtchnl2_queue_vector *vecmap; + struct idpf_cmd_info args; + int len, i, err = 0; + + len = sizeof(struct virtchnl2_queue_vector_maps) + + (nb_rxq - 1) * sizeof(struct virtchnl2_queue_vector); + + map_info = rte_zmalloc("map_info", len, 0); + if (map_info == NULL) + return -ENOMEM; + + map_info->vport_id = vport->vport_id; + map_info->num_qv_maps = nb_rxq; + for (i = 0; i < nb_rxq; i++) { + vecmap = &map_info->qv_maps[i]; + vecmap->queue_id = vport->qv_map[i].queue_id; + vecmap->vector_id = vport->qv_map[i].vector_id; + vecmap->itr_idx = VIRTCHNL2_ITR_IDX_0; + vecmap->queue_type = VIRTCHNL2_QUEUE_TYPE_RX; + } + + args.ops = map ? VIRTCHNL2_OP_MAP_QUEUE_VECTOR : + VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR; + args.in_args = (uint8_t *)map_info; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUE_VECTOR", + map ? "MAP" : "UNMAP"); + + rte_free(map_info); + return err; +} + +int +idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_alloc_vectors *alloc_vec; + struct idpf_cmd_info args; + int err, len; + + len = sizeof(struct virtchnl2_alloc_vectors) + + (num_vectors - 1) * sizeof(struct virtchnl2_vector_chunk); + alloc_vec = rte_zmalloc("alloc_vec", len, 0); + if (alloc_vec == NULL) + return -ENOMEM; + + alloc_vec->num_vectors = num_vectors; + + args.ops = VIRTCHNL2_OP_ALLOC_VECTORS; + args.in_args = (uint8_t *)alloc_vec; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_ALLOC_VECTORS"); + + if (vport->recv_vectors == NULL) { + vport->recv_vectors = rte_zmalloc("recv_vectors", len, 0); + if (vport->recv_vectors == NULL) { + rte_free(alloc_vec); + return -ENOMEM; + } + } + + rte_memcpy(vport->recv_vectors, args.out_buffer, len); + rte_free(alloc_vec); + return err; +} + +int +idpf_vc_dealloc_vectors(struct idpf_vport *vport) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_alloc_vectors *alloc_vec; + struct virtchnl2_vector_chunks *vcs; + struct idpf_cmd_info args; + int err, len; + + alloc_vec = vport->recv_vectors; + vcs = &alloc_vec->vchunks; + + len = sizeof(struct virtchnl2_vector_chunks) + + (vcs->num_vchunks - 1) * sizeof(struct virtchnl2_vector_chunk); + + args.ops = VIRTCHNL2_OP_DEALLOC_VECTORS; + args.in_args = (uint8_t *)vcs; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_DEALLOC_VECTORS"); + + return err; +} + +static int +idpf_vc_ena_dis_one_queue(struct idpf_vport *vport, uint16_t qid, + uint32_t type, bool on) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_del_ena_dis_queues *queue_select; + struct virtchnl2_queue_chunk *queue_chunk; + struct idpf_cmd_info args; + int err, len; + + len = sizeof(struct virtchnl2_del_ena_dis_queues); + queue_select = rte_zmalloc("queue_select", len, 0); + if (queue_select == NULL) + return -ENOMEM; + + queue_chunk = queue_select->chunks.chunks; + queue_select->chunks.num_chunks = 1; + queue_select->vport_id = vport->vport_id; + + queue_chunk->type = type; + queue_chunk->start_queue_id = qid; + queue_chunk->num_queues = 1; + + args.ops = on ? VIRTCHNL2_OP_ENABLE_QUEUES : + VIRTCHNL2_OP_DISABLE_QUEUES; + args.in_args = (uint8_t *)queue_select; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES", + on ? "ENABLE" : "DISABLE"); + + rte_free(queue_select); + return err; +} + +int +idpf_vc_switch_queue(struct idpf_vport *vport, uint16_t qid, + bool rx, bool on) +{ + uint32_t type; + int err, queue_id; + + /* switch txq/rxq */ + type = rx ? VIRTCHNL2_QUEUE_TYPE_RX : VIRTCHNL2_QUEUE_TYPE_TX; + + if (type == VIRTCHNL2_QUEUE_TYPE_RX) + queue_id = vport->chunks_info.rx_start_qid + qid; + else + queue_id = vport->chunks_info.tx_start_qid + qid; + err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); + if (err != 0) + return err; + + /* switch tx completion queue */ + if (!rx && vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { + type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; + queue_id = vport->chunks_info.tx_compl_start_qid + qid; + err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); + if (err != 0) + return err; + } + + /* switch rx buffer queue */ + if (rx && vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { + type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER; + queue_id = vport->chunks_info.rx_buf_start_qid + 2 * qid; + err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); + if (err != 0) + return err; + queue_id++; + err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); + if (err != 0) + return err; + } + + return err; +} + +#define IDPF_RXTX_QUEUE_CHUNKS_NUM 2 +int +idpf_vc_ena_dis_queues(struct idpf_vport *vport, bool enable) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_del_ena_dis_queues *queue_select; + struct virtchnl2_queue_chunk *queue_chunk; + uint32_t type; + struct idpf_cmd_info args; + uint16_t num_chunks; + int err, len; + + num_chunks = IDPF_RXTX_QUEUE_CHUNKS_NUM; + if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) + num_chunks++; + if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) + num_chunks++; + + len = sizeof(struct virtchnl2_del_ena_dis_queues) + + sizeof(struct virtchnl2_queue_chunk) * (num_chunks - 1); + queue_select = rte_zmalloc("queue_select", len, 0); + if (queue_select == NULL) + return -ENOMEM; + + queue_chunk = queue_select->chunks.chunks; + queue_select->chunks.num_chunks = num_chunks; + queue_select->vport_id = vport->vport_id; + + type = VIRTCHNL_QUEUE_TYPE_RX; + queue_chunk[type].type = type; + queue_chunk[type].start_queue_id = vport->chunks_info.rx_start_qid; + queue_chunk[type].num_queues = vport->num_rx_q; + + type = VIRTCHNL2_QUEUE_TYPE_TX; + queue_chunk[type].type = type; + queue_chunk[type].start_queue_id = vport->chunks_info.tx_start_qid; + queue_chunk[type].num_queues = vport->num_tx_q; + + if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { + type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER; + queue_chunk[type].type = type; + queue_chunk[type].start_queue_id = + vport->chunks_info.rx_buf_start_qid; + queue_chunk[type].num_queues = vport->num_rx_bufq; + } + + if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { + type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; + queue_chunk[type].type = type; + queue_chunk[type].start_queue_id = + vport->chunks_info.tx_compl_start_qid; + queue_chunk[type].num_queues = vport->num_tx_complq; + } + + args.ops = enable ? VIRTCHNL2_OP_ENABLE_QUEUES : + VIRTCHNL2_OP_DISABLE_QUEUES; + args.in_args = (uint8_t *)queue_select; + args.in_args_size = len; + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES", + enable ? "ENABLE" : "DISABLE"); + + rte_free(queue_select); + return err; +} + +int +idpf_vc_ena_dis_vport(struct idpf_vport *vport, bool enable) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_vport vc_vport; + struct idpf_cmd_info args; + int err; + + vc_vport.vport_id = vport->vport_id; + args.ops = enable ? VIRTCHNL2_OP_ENABLE_VPORT : + VIRTCHNL2_OP_DISABLE_VPORT; + args.in_args = (uint8_t *)&vc_vport; + args.in_args_size = sizeof(vc_vport); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) { + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_VPORT", + enable ? "ENABLE" : "DISABLE"); + } + + return err; +} + +int +idpf_vc_query_ptype_info(struct idpf_adapter *adapter) +{ + struct virtchnl2_get_ptype_info *ptype_info; + struct idpf_cmd_info args; + int len, err; + + len = sizeof(struct virtchnl2_get_ptype_info); + ptype_info = rte_zmalloc("ptype_info", len, 0); + if (ptype_info == NULL) + return -ENOMEM; + + ptype_info->start_ptype_id = 0; + ptype_info->num_ptypes = IDPF_MAX_PKT_TYPE; + args.ops = VIRTCHNL2_OP_GET_PTYPE_INFO; + args.in_args = (uint8_t *)ptype_info; + args.in_args_size = len; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err != 0) + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_PTYPE_INFO"); + + rte_free(ptype_info); + return err; +} diff --git a/drivers/common/idpf/idpf_common_virtchnl.h b/drivers/common/idpf/idpf_common_virtchnl.h new file mode 100644 index 0000000000..e05619f4b4 --- /dev/null +++ b/drivers/common/idpf/idpf_common_virtchnl.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#ifndef _IDPF_COMMON_VIRTCHNL_H_ +#define _IDPF_COMMON_VIRTCHNL_H_ + +#include + +__rte_internal +int idpf_vc_check_api_version(struct idpf_adapter *adapter); +__rte_internal +int idpf_vc_get_caps(struct idpf_adapter *adapter); +__rte_internal +int idpf_vc_create_vport(struct idpf_vport *vport, + struct virtchnl2_create_vport *vport_info); +__rte_internal +int idpf_vc_destroy_vport(struct idpf_vport *vport); +__rte_internal +int idpf_vc_set_rss_key(struct idpf_vport *vport); +__rte_internal +int idpf_vc_set_rss_lut(struct idpf_vport *vport); +__rte_internal +int idpf_vc_set_rss_hash(struct idpf_vport *vport); +__rte_internal +int idpf_vc_switch_queue(struct idpf_vport *vport, uint16_t qid, + bool rx, bool on); +__rte_internal +int idpf_vc_ena_dis_queues(struct idpf_vport *vport, bool enable); +__rte_internal +int idpf_vc_ena_dis_vport(struct idpf_vport *vport, bool enable); +__rte_internal +int idpf_vc_config_irq_map_unmap(struct idpf_vport *vport, + uint16_t nb_rxq, bool map); +__rte_internal +int idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors); +__rte_internal +int idpf_vc_dealloc_vectors(struct idpf_vport *vport); +__rte_internal +int idpf_vc_query_ptype_info(struct idpf_adapter *adapter); +__rte_internal +int idpf_vc_read_one_msg(struct idpf_adapter *adapter, uint32_t ops, + uint16_t buf_len, uint8_t *buf); +__rte_internal +int idpf_execute_vc_cmd(struct idpf_adapter *adapter, + struct idpf_cmd_info *args); + +#endif /* _IDPF_COMMON_VIRTCHNL_H_ */ diff --git a/drivers/common/idpf/meson.build b/drivers/common/idpf/meson.build index 77d997b4a7..d1578641ba 100644 --- a/drivers/common/idpf/meson.build +++ b/drivers/common/idpf/meson.build @@ -1,4 +1,9 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2022 Intel Corporation +sources = files( + 'idpf_common_device.c', + 'idpf_common_virtchnl.c', +) + subdir('base') diff --git a/drivers/common/idpf/version.map b/drivers/common/idpf/version.map index bfb246c752..9bc0d2a909 100644 --- a/drivers/common/idpf/version.map +++ b/drivers/common/idpf/version.map @@ -3,10 +3,22 @@ INTERNAL { idpf_ctlq_deinit; idpf_ctlq_init; - idpf_ctlq_clean_sq; - idpf_ctlq_recv; - idpf_ctlq_send; - idpf_ctlq_post_rx_buffs; + idpf_execute_vc_cmd; + idpf_vc_alloc_vectors; + idpf_vc_check_api_version; + idpf_vc_config_irq_map_unmap; + idpf_vc_create_vport; + idpf_vc_dealloc_vectors; + idpf_vc_destroy_vport; + idpf_vc_ena_dis_queues; + idpf_vc_ena_dis_vport; + idpf_vc_get_caps; + idpf_vc_query_ptype_info; + idpf_vc_read_one_msg; + idpf_vc_set_rss_hash; + idpf_vc_set_rss_key; + idpf_vc_set_rss_lut; + idpf_vc_switch_queue; local: *; }; diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c index 72a5c9f39b..759fc981d7 100644 --- a/drivers/net/idpf/idpf_ethdev.c +++ b/drivers/net/idpf/idpf_ethdev.c @@ -942,13 +942,6 @@ idpf_adapter_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *adapt goto err_api; } - adapter->max_rxq_per_msg = (IDPF_DFLT_MBX_BUF_SIZE - - sizeof(struct virtchnl2_config_rx_queues)) / - sizeof(struct virtchnl2_rxq_info); - adapter->max_txq_per_msg = (IDPF_DFLT_MBX_BUF_SIZE - - sizeof(struct virtchnl2_config_tx_queues)) / - sizeof(struct virtchnl2_txq_info); - adapter->cur_vports = 0; adapter->cur_vport_nb = 0; @@ -1075,7 +1068,7 @@ static const struct rte_pci_id pci_id_idpf_map[] = { { .vendor_id = 0, /* sentinel */ }, }; -struct idpf_adapter_ext * +static struct idpf_adapter_ext * idpf_find_adapter_ext(struct rte_pci_device *pci_dev) { struct idpf_adapter_ext *adapter; diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h index 8c29019667..efc540fa32 100644 --- a/drivers/net/idpf/idpf_ethdev.h +++ b/drivers/net/idpf/idpf_ethdev.h @@ -16,6 +16,7 @@ #include "idpf_logs.h" #include +#include #include #include @@ -31,8 +32,6 @@ #define IDPF_RX_BUFQ_PER_GRP 2 #define IDPF_CTLQ_ID -1 -#define IDPF_CTLQ_LEN 64 -#define IDPF_DFLT_MBX_BUF_SIZE 4096 #define IDPF_DFLT_Q_VEC_NUM 1 #define IDPF_DFLT_INTERVAL 16 @@ -44,8 +43,6 @@ #define IDPF_NUM_MACADDR_MAX 64 -#define IDPF_MAX_PKT_TYPE 1024 - #define IDPF_VLAN_TAG_SIZE 4 #define IDPF_ETH_OVERHEAD \ (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + IDPF_VLAN_TAG_SIZE * 2) @@ -66,14 +63,6 @@ #define IDPF_ADAPTER_NAME_LEN (PCI_PRI_STR_SIZE + 1) -/* Message type read in virtual channel from PF */ -enum idpf_vc_result { - IDPF_MSG_ERR = -1, /* Meet error when accessing admin queue */ - IDPF_MSG_NON, /* Read nothing from admin queue */ - IDPF_MSG_SYS, /* Read system msg from admin queue */ - IDPF_MSG_CMD, /* Read async command result */ -}; - struct idpf_vport_param { struct idpf_adapter_ext *adapter; uint16_t devarg_id; /* arg id from user */ @@ -103,10 +92,6 @@ struct idpf_adapter_ext { uint16_t used_vecs_num; - /* Max config queue number per VC message */ - uint32_t max_rxq_per_msg; - uint32_t max_txq_per_msg; - uint32_t ptype_tbl[IDPF_MAX_PKT_TYPE] __rte_cache_min_aligned; bool rx_vec_allowed; @@ -125,74 +110,6 @@ TAILQ_HEAD(idpf_adapter_list, idpf_adapter_ext); #define IDPF_ADAPTER_TO_EXT(p) \ container_of((p), struct idpf_adapter_ext, base) -/* structure used for sending and checking response of virtchnl ops */ -struct idpf_cmd_info { - uint32_t ops; - uint8_t *in_args; /* buffer for sending */ - uint32_t in_args_size; /* buffer size for sending */ - uint8_t *out_buffer; /* buffer for response */ - uint32_t out_size; /* buffer size for response */ -}; - -/* notify current command done. Only call in case execute - * _atomic_set_cmd successfully. - */ -static inline void -notify_cmd(struct idpf_adapter *adapter, int msg_ret) -{ - adapter->cmd_retval = msg_ret; - /* Return value may be checked in anither thread, need to ensure the coherence. */ - rte_wmb(); - adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; -} - -/* clear current command. Only call in case execute - * _atomic_set_cmd successfully. - */ -static inline void -clear_cmd(struct idpf_adapter *adapter) -{ - /* Return value may be checked in anither thread, need to ensure the coherence. */ - rte_wmb(); - adapter->pend_cmd = VIRTCHNL2_OP_UNKNOWN; - adapter->cmd_retval = VIRTCHNL_STATUS_SUCCESS; -} - -/* Check there is pending cmd in execution. If none, set new command. */ -static inline bool -atomic_set_cmd(struct idpf_adapter *adapter, uint32_t ops) -{ - uint32_t op_unk = VIRTCHNL2_OP_UNKNOWN; - bool ret = __atomic_compare_exchange(&adapter->pend_cmd, &op_unk, &ops, - 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); - - if (!ret) - PMD_DRV_LOG(ERR, "There is incomplete cmd %d", adapter->pend_cmd); - - return !ret; -} - -struct idpf_adapter_ext *idpf_find_adapter_ext(struct rte_pci_device *pci_dev); -void idpf_handle_virtchnl_msg(struct rte_eth_dev *dev); -int idpf_vc_check_api_version(struct idpf_adapter *adapter); int idpf_get_pkt_type(struct idpf_adapter_ext *adapter); -int idpf_vc_get_caps(struct idpf_adapter *adapter); -int idpf_vc_create_vport(struct idpf_vport *vport, - struct virtchnl2_create_vport *vport_info); -int idpf_vc_destroy_vport(struct idpf_vport *vport); -int idpf_vc_set_rss_key(struct idpf_vport *vport); -int idpf_vc_set_rss_lut(struct idpf_vport *vport); -int idpf_vc_set_rss_hash(struct idpf_vport *vport); -int idpf_switch_queue(struct idpf_vport *vport, uint16_t qid, - bool rx, bool on); -int idpf_vc_ena_dis_queues(struct idpf_vport *vport, bool enable); -int idpf_vc_ena_dis_vport(struct idpf_vport *vport, bool enable); -int idpf_vc_config_irq_map_unmap(struct idpf_vport *vport, - uint16_t nb_rxq, bool map); -int idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors); -int idpf_vc_dealloc_vectors(struct idpf_vport *vport); -int idpf_vc_query_ptype_info(struct idpf_adapter *adapter); -int idpf_read_one_msg(struct idpf_adapter *adapter, uint32_t ops, - uint16_t buf_len, uint8_t *buf); #endif /* _IDPF_ETHDEV_H_ */ diff --git a/drivers/net/idpf/idpf_rxtx.c b/drivers/net/idpf/idpf_rxtx.c index 918d156e03..ad3e31208d 100644 --- a/drivers/net/idpf/idpf_rxtx.c +++ b/drivers/net/idpf/idpf_rxtx.c @@ -1080,7 +1080,7 @@ idpf_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id) } /* Ready to switch the queue on */ - err = idpf_switch_queue(vport, rx_queue_id, true, true); + err = idpf_vc_switch_queue(vport, rx_queue_id, true, true); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on", rx_queue_id); @@ -1131,7 +1131,7 @@ idpf_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) } /* Ready to switch the queue on */ - err = idpf_switch_queue(vport, tx_queue_id, false, true); + err = idpf_vc_switch_queue(vport, tx_queue_id, false, true); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on", tx_queue_id); @@ -1154,7 +1154,7 @@ idpf_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id) if (rx_queue_id >= dev->data->nb_rx_queues) return -EINVAL; - err = idpf_switch_queue(vport, rx_queue_id, true, false); + err = idpf_vc_switch_queue(vport, rx_queue_id, true, false); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off", rx_queue_id); @@ -1185,7 +1185,7 @@ idpf_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id) if (tx_queue_id >= dev->data->nb_tx_queues) return -EINVAL; - err = idpf_switch_queue(vport, tx_queue_id, false, false); + err = idpf_vc_switch_queue(vport, tx_queue_id, false, false); if (err != 0) { PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off", tx_queue_id); diff --git a/drivers/net/idpf/idpf_vchnl.c b/drivers/net/idpf/idpf_vchnl.c index 633d3295d3..6f4eb52beb 100644 --- a/drivers/net/idpf/idpf_vchnl.c +++ b/drivers/net/idpf/idpf_vchnl.c @@ -23,293 +23,6 @@ #include "idpf_ethdev.h" #include "idpf_rxtx.h" -static int -idpf_vc_clean(struct idpf_adapter *adapter) -{ - struct idpf_ctlq_msg *q_msg[IDPF_CTLQ_LEN]; - uint16_t num_q_msg = IDPF_CTLQ_LEN; - struct idpf_dma_mem *dma_mem; - int err; - uint32_t i; - - for (i = 0; i < 10; i++) { - err = idpf_ctlq_clean_sq(adapter->hw.asq, &num_q_msg, q_msg); - msleep(20); - if (num_q_msg > 0) - break; - } - if (err != 0) - return err; - - /* Empty queue is not an error */ - for (i = 0; i < num_q_msg; i++) { - dma_mem = q_msg[i]->ctx.indirect.payload; - if (dma_mem != NULL) { - idpf_free_dma_mem(&adapter->hw, dma_mem); - rte_free(dma_mem); - } - rte_free(q_msg[i]); - } - - return 0; -} - -static int -idpf_send_vc_msg(struct idpf_adapter *adapter, uint32_t op, - uint16_t msg_size, uint8_t *msg) -{ - struct idpf_ctlq_msg *ctlq_msg; - struct idpf_dma_mem *dma_mem; - int err; - - err = idpf_vc_clean(adapter); - if (err != 0) - goto err; - - ctlq_msg = rte_zmalloc(NULL, sizeof(struct idpf_ctlq_msg), 0); - if (ctlq_msg == NULL) { - err = -ENOMEM; - goto err; - } - - dma_mem = rte_zmalloc(NULL, sizeof(struct idpf_dma_mem), 0); - if (dma_mem == NULL) { - err = -ENOMEM; - goto dma_mem_error; - } - - dma_mem->size = IDPF_DFLT_MBX_BUF_SIZE; - idpf_alloc_dma_mem(&adapter->hw, dma_mem, dma_mem->size); - if (dma_mem->va == NULL) { - err = -ENOMEM; - goto dma_alloc_error; - } - - memcpy(dma_mem->va, msg, msg_size); - - ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_pf; - ctlq_msg->func_id = 0; - ctlq_msg->data_len = msg_size; - ctlq_msg->cookie.mbx.chnl_opcode = op; - ctlq_msg->cookie.mbx.chnl_retval = VIRTCHNL_STATUS_SUCCESS; - ctlq_msg->ctx.indirect.payload = dma_mem; - - err = idpf_ctlq_send(&adapter->hw, adapter->hw.asq, 1, ctlq_msg); - if (err != 0) - goto send_error; - - return 0; - -send_error: - idpf_free_dma_mem(&adapter->hw, dma_mem); -dma_alloc_error: - rte_free(dma_mem); -dma_mem_error: - rte_free(ctlq_msg); -err: - return err; -} - -static enum idpf_vc_result -idpf_read_msg_from_cp(struct idpf_adapter *adapter, uint16_t buf_len, - uint8_t *buf) -{ - struct idpf_hw *hw = &adapter->hw; - struct idpf_ctlq_msg ctlq_msg; - struct idpf_dma_mem *dma_mem = NULL; - enum idpf_vc_result result = IDPF_MSG_NON; - uint32_t opcode; - uint16_t pending = 1; - int ret; - - ret = idpf_ctlq_recv(hw->arq, &pending, &ctlq_msg); - if (ret != 0) { - PMD_DRV_LOG(DEBUG, "Can't read msg from AQ"); - if (ret != -ENOMSG) - result = IDPF_MSG_ERR; - return result; - } - - rte_memcpy(buf, ctlq_msg.ctx.indirect.payload->va, buf_len); - - opcode = rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_opcode); - adapter->cmd_retval = - (enum virtchnl_status_code)rte_le_to_cpu_32(ctlq_msg.cookie.mbx.chnl_retval); - - PMD_DRV_LOG(DEBUG, "CQ from CP carries opcode %u, retval %d", - opcode, adapter->cmd_retval); - - if (opcode == VIRTCHNL2_OP_EVENT) { - struct virtchnl2_event *ve = - (struct virtchnl2_event *)ctlq_msg.ctx.indirect.payload->va; - - result = IDPF_MSG_SYS; - switch (ve->event) { - case VIRTCHNL2_EVENT_LINK_CHANGE: - /* TBD */ - break; - default: - PMD_DRV_LOG(ERR, "%s: Unknown event %d from CP", - __func__, ve->event); - break; - } - } else { - /* async reply msg on command issued by pf previously */ - result = IDPF_MSG_CMD; - if (opcode != adapter->pend_cmd) { - PMD_DRV_LOG(WARNING, "command mismatch, expect %u, get %u", - adapter->pend_cmd, opcode); - result = IDPF_MSG_ERR; - } - } - - if (ctlq_msg.data_len != 0) - dma_mem = ctlq_msg.ctx.indirect.payload; - else - pending = 0; - - ret = idpf_ctlq_post_rx_buffs(hw, hw->arq, &pending, &dma_mem); - if (ret != 0 && dma_mem != NULL) - idpf_free_dma_mem(hw, dma_mem); - - return result; -} - -#define MAX_TRY_TIMES 200 -#define ASQ_DELAY_MS 10 - -int -idpf_read_one_msg(struct idpf_adapter *adapter, uint32_t ops, uint16_t buf_len, - uint8_t *buf) -{ - int err = 0; - int i = 0; - int ret; - - do { - ret = idpf_read_msg_from_cp(adapter, buf_len, buf); - if (ret == IDPF_MSG_CMD) - break; - rte_delay_ms(ASQ_DELAY_MS); - } while (i++ < MAX_TRY_TIMES); - if (i >= MAX_TRY_TIMES || - adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) { - err = -EBUSY; - PMD_DRV_LOG(ERR, "No response or return failure (%d) for cmd %d", - adapter->cmd_retval, ops); - } - - return err; -} - -static int -idpf_execute_vc_cmd(struct idpf_adapter *adapter, struct idpf_cmd_info *args) -{ - int err = 0; - int i = 0; - int ret; - - if (atomic_set_cmd(adapter, args->ops)) - return -EINVAL; - - ret = idpf_send_vc_msg(adapter, args->ops, args->in_args_size, args->in_args); - if (ret != 0) { - PMD_DRV_LOG(ERR, "fail to send cmd %d", args->ops); - clear_cmd(adapter); - return ret; - } - - switch (args->ops) { - case VIRTCHNL_OP_VERSION: - case VIRTCHNL2_OP_GET_CAPS: - case VIRTCHNL2_OP_CREATE_VPORT: - case VIRTCHNL2_OP_DESTROY_VPORT: - case VIRTCHNL2_OP_SET_RSS_KEY: - case VIRTCHNL2_OP_SET_RSS_LUT: - case VIRTCHNL2_OP_SET_RSS_HASH: - case VIRTCHNL2_OP_CONFIG_RX_QUEUES: - case VIRTCHNL2_OP_CONFIG_TX_QUEUES: - case VIRTCHNL2_OP_ENABLE_QUEUES: - case VIRTCHNL2_OP_DISABLE_QUEUES: - case VIRTCHNL2_OP_ENABLE_VPORT: - case VIRTCHNL2_OP_DISABLE_VPORT: - case VIRTCHNL2_OP_MAP_QUEUE_VECTOR: - case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR: - case VIRTCHNL2_OP_ALLOC_VECTORS: - case VIRTCHNL2_OP_DEALLOC_VECTORS: - /* for init virtchnl ops, need to poll the response */ - err = idpf_read_one_msg(adapter, args->ops, args->out_size, args->out_buffer); - clear_cmd(adapter); - break; - case VIRTCHNL2_OP_GET_PTYPE_INFO: - /* for multuple response message, - * do not handle the response here. - */ - break; - default: - /* For other virtchnl ops in running time, - * wait for the cmd done flag. - */ - do { - if (adapter->pend_cmd == VIRTCHNL_OP_UNKNOWN) - break; - rte_delay_ms(ASQ_DELAY_MS); - /* If don't read msg or read sys event, continue */ - } while (i++ < MAX_TRY_TIMES); - /* If there's no response is received, clear command */ - if (i >= MAX_TRY_TIMES || - adapter->cmd_retval != VIRTCHNL_STATUS_SUCCESS) { - err = -EBUSY; - PMD_DRV_LOG(ERR, "No response or return failure (%d) for cmd %d", - adapter->cmd_retval, args->ops); - clear_cmd(adapter); - } - break; - } - - return err; -} - -int -idpf_vc_check_api_version(struct idpf_adapter *adapter) -{ - struct virtchnl2_version_info version, *pver; - struct idpf_cmd_info args; - int err; - - memset(&version, 0, sizeof(struct virtchnl_version_info)); - version.major = VIRTCHNL2_VERSION_MAJOR_2; - version.minor = VIRTCHNL2_VERSION_MINOR_0; - - args.ops = VIRTCHNL_OP_VERSION; - args.in_args = (uint8_t *)&version; - args.in_args_size = sizeof(version); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) { - PMD_DRV_LOG(ERR, - "Failed to execute command of VIRTCHNL_OP_VERSION"); - return err; - } - - pver = (struct virtchnl2_version_info *)args.out_buffer; - adapter->virtchnl_version = *pver; - - if (adapter->virtchnl_version.major != VIRTCHNL2_VERSION_MAJOR_2 || - adapter->virtchnl_version.minor != VIRTCHNL2_VERSION_MINOR_0) { - PMD_INIT_LOG(ERR, "VIRTCHNL API version mismatch:(%u.%u)-(%u.%u)", - adapter->virtchnl_version.major, - adapter->virtchnl_version.minor, - VIRTCHNL2_VERSION_MAJOR_2, - VIRTCHNL2_VERSION_MINOR_0); - return -EINVAL; - } - - return 0; -} - int __rte_cold idpf_get_pkt_type(struct idpf_adapter_ext *adapter) { @@ -332,8 +45,8 @@ idpf_get_pkt_type(struct idpf_adapter_ext *adapter) return -ENOMEM; while (ptype_recvd < IDPF_MAX_PKT_TYPE) { - ret = idpf_read_one_msg(base, VIRTCHNL2_OP_GET_PTYPE_INFO, - IDPF_DFLT_MBX_BUF_SIZE, (u8 *)ptype_info); + ret = idpf_vc_read_one_msg(base, VIRTCHNL2_OP_GET_PTYPE_INFO, + IDPF_DFLT_MBX_BUF_SIZE, (uint8_t *)ptype_info); if (ret != 0) { PMD_DRV_LOG(ERR, "Fail to get packet type information"); goto free_ptype_info; @@ -349,7 +62,7 @@ idpf_get_pkt_type(struct idpf_adapter_ext *adapter) uint32_t proto_hdr = 0; ptype = (struct virtchnl2_ptype *) - ((u8 *)ptype_info + ptype_offset); + ((uint8_t *)ptype_info + ptype_offset); ptype_offset += IDPF_GET_PTYPE_SIZE(ptype); if (ptype_offset > IDPF_DFLT_MBX_BUF_SIZE) { ret = -EINVAL; @@ -523,223 +236,6 @@ idpf_get_pkt_type(struct idpf_adapter_ext *adapter) return ret; } -int -idpf_vc_get_caps(struct idpf_adapter *adapter) -{ - struct virtchnl2_get_capabilities caps_msg; - struct idpf_cmd_info args; - int err; - - memset(&caps_msg, 0, sizeof(struct virtchnl2_get_capabilities)); - - caps_msg.csum_caps = - VIRTCHNL2_CAP_TX_CSUM_L3_IPV4 | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_TCP | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_UDP | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV4_SCTP | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_TCP | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_UDP | - VIRTCHNL2_CAP_TX_CSUM_L4_IPV6_SCTP | - VIRTCHNL2_CAP_TX_CSUM_GENERIC | - VIRTCHNL2_CAP_RX_CSUM_L3_IPV4 | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_TCP | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_UDP | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV4_SCTP | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_TCP | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_UDP | - VIRTCHNL2_CAP_RX_CSUM_L4_IPV6_SCTP | - VIRTCHNL2_CAP_RX_CSUM_GENERIC; - - caps_msg.rss_caps = - VIRTCHNL2_CAP_RSS_IPV4_TCP | - VIRTCHNL2_CAP_RSS_IPV4_UDP | - VIRTCHNL2_CAP_RSS_IPV4_SCTP | - VIRTCHNL2_CAP_RSS_IPV4_OTHER | - VIRTCHNL2_CAP_RSS_IPV6_TCP | - VIRTCHNL2_CAP_RSS_IPV6_UDP | - VIRTCHNL2_CAP_RSS_IPV6_SCTP | - VIRTCHNL2_CAP_RSS_IPV6_OTHER | - VIRTCHNL2_CAP_RSS_IPV4_AH | - VIRTCHNL2_CAP_RSS_IPV4_ESP | - VIRTCHNL2_CAP_RSS_IPV4_AH_ESP | - VIRTCHNL2_CAP_RSS_IPV6_AH | - VIRTCHNL2_CAP_RSS_IPV6_ESP | - VIRTCHNL2_CAP_RSS_IPV6_AH_ESP; - - caps_msg.other_caps = VIRTCHNL2_CAP_WB_ON_ITR; - - args.ops = VIRTCHNL2_OP_GET_CAPS; - args.in_args = (uint8_t *)&caps_msg; - args.in_args_size = sizeof(caps_msg); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) { - PMD_DRV_LOG(ERR, - "Failed to execute command of VIRTCHNL2_OP_GET_CAPS"); - return err; - } - - rte_memcpy(&adapter->caps, args.out_buffer, sizeof(caps_msg)); - - return 0; -} - -int -idpf_vc_create_vport(struct idpf_vport *vport, - struct virtchnl2_create_vport *vport_req_info) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_create_vport vport_msg; - struct idpf_cmd_info args; - int err = -1; - - memset(&vport_msg, 0, sizeof(struct virtchnl2_create_vport)); - vport_msg.vport_type = vport_req_info->vport_type; - vport_msg.txq_model = vport_req_info->txq_model; - vport_msg.rxq_model = vport_req_info->rxq_model; - vport_msg.num_tx_q = vport_req_info->num_tx_q; - vport_msg.num_tx_complq = vport_req_info->num_tx_complq; - vport_msg.num_rx_q = vport_req_info->num_rx_q; - vport_msg.num_rx_bufq = vport_req_info->num_rx_bufq; - - memset(&args, 0, sizeof(args)); - args.ops = VIRTCHNL2_OP_CREATE_VPORT; - args.in_args = (uint8_t *)&vport_msg; - args.in_args_size = sizeof(vport_msg); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) { - PMD_DRV_LOG(ERR, - "Failed to execute command of VIRTCHNL2_OP_CREATE_VPORT"); - return err; - } - - rte_memcpy(vport->vport_info, args.out_buffer, IDPF_DFLT_MBX_BUF_SIZE); - return 0; -} - -int -idpf_vc_destroy_vport(struct idpf_vport *vport) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_vport vc_vport; - struct idpf_cmd_info args; - int err; - - vc_vport.vport_id = vport->vport_id; - - memset(&args, 0, sizeof(args)); - args.ops = VIRTCHNL2_OP_DESTROY_VPORT; - args.in_args = (uint8_t *)&vc_vport; - args.in_args_size = sizeof(vc_vport); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_DESTROY_VPORT"); - - return err; -} - -int -idpf_vc_set_rss_key(struct idpf_vport *vport) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_rss_key *rss_key; - struct idpf_cmd_info args; - int len, err; - - len = sizeof(*rss_key) + sizeof(rss_key->key[0]) * - (vport->rss_key_size - 1); - rss_key = rte_zmalloc("rss_key", len, 0); - if (rss_key == NULL) - return -ENOMEM; - - rss_key->vport_id = vport->vport_id; - rss_key->key_len = vport->rss_key_size; - rte_memcpy(rss_key->key, vport->rss_key, - sizeof(rss_key->key[0]) * vport->rss_key_size); - - memset(&args, 0, sizeof(args)); - args.ops = VIRTCHNL2_OP_SET_RSS_KEY; - args.in_args = (uint8_t *)rss_key; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_KEY"); - - rte_free(rss_key); - return err; -} - -int -idpf_vc_set_rss_lut(struct idpf_vport *vport) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_rss_lut *rss_lut; - struct idpf_cmd_info args; - int len, err; - - len = sizeof(*rss_lut) + sizeof(rss_lut->lut[0]) * - (vport->rss_lut_size - 1); - rss_lut = rte_zmalloc("rss_lut", len, 0); - if (rss_lut == NULL) - return -ENOMEM; - - rss_lut->vport_id = vport->vport_id; - rss_lut->lut_entries = vport->rss_lut_size; - rte_memcpy(rss_lut->lut, vport->rss_lut, - sizeof(rss_lut->lut[0]) * vport->rss_lut_size); - - memset(&args, 0, sizeof(args)); - args.ops = VIRTCHNL2_OP_SET_RSS_LUT; - args.in_args = (uint8_t *)rss_lut; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_SET_RSS_LUT"); - - rte_free(rss_lut); - return err; -} - -int -idpf_vc_set_rss_hash(struct idpf_vport *vport) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_rss_hash rss_hash; - struct idpf_cmd_info args; - int err; - - memset(&rss_hash, 0, sizeof(rss_hash)); - rss_hash.ptype_groups = vport->rss_hf; - rss_hash.vport_id = vport->vport_id; - - memset(&args, 0, sizeof(args)); - args.ops = VIRTCHNL2_OP_SET_RSS_HASH; - args.in_args = (uint8_t *)&rss_hash; - args.in_args_size = sizeof(rss_hash); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of OP_SET_RSS_HASH"); - - return err; -} - #define IDPF_RX_BUF_STRIDE 64 int idpf_vc_config_rxq(struct idpf_vport *vport, struct idpf_rx_queue *rxq) @@ -899,310 +395,3 @@ idpf_vc_config_txq(struct idpf_vport *vport, struct idpf_tx_queue *txq) return err; } - -int -idpf_vc_config_irq_map_unmap(struct idpf_vport *vport, uint16_t nb_rxq, bool map) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_queue_vector_maps *map_info; - struct virtchnl2_queue_vector *vecmap; - struct idpf_cmd_info args; - int len, i, err = 0; - - len = sizeof(struct virtchnl2_queue_vector_maps) + - (nb_rxq - 1) * sizeof(struct virtchnl2_queue_vector); - - map_info = rte_zmalloc("map_info", len, 0); - if (map_info == NULL) - return -ENOMEM; - - map_info->vport_id = vport->vport_id; - map_info->num_qv_maps = nb_rxq; - for (i = 0; i < nb_rxq; i++) { - vecmap = &map_info->qv_maps[i]; - vecmap->queue_id = vport->qv_map[i].queue_id; - vecmap->vector_id = vport->qv_map[i].vector_id; - vecmap->itr_idx = VIRTCHNL2_ITR_IDX_0; - vecmap->queue_type = VIRTCHNL2_QUEUE_TYPE_RX; - } - - args.ops = map ? VIRTCHNL2_OP_MAP_QUEUE_VECTOR : - VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR; - args.in_args = (u8 *)map_info; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUE_VECTOR", - map ? "MAP" : "UNMAP"); - - rte_free(map_info); - return err; -} - -int -idpf_vc_alloc_vectors(struct idpf_vport *vport, uint16_t num_vectors) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_alloc_vectors *alloc_vec; - struct idpf_cmd_info args; - int err, len; - - len = sizeof(struct virtchnl2_alloc_vectors) + - (num_vectors - 1) * sizeof(struct virtchnl2_vector_chunk); - alloc_vec = rte_zmalloc("alloc_vec", len, 0); - if (alloc_vec == NULL) - return -ENOMEM; - - alloc_vec->num_vectors = num_vectors; - - args.ops = VIRTCHNL2_OP_ALLOC_VECTORS; - args.in_args = (u8 *)alloc_vec; - args.in_args_size = sizeof(struct virtchnl2_alloc_vectors); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_ALLOC_VECTORS"); - - if (vport->recv_vectors == NULL) { - vport->recv_vectors = rte_zmalloc("recv_vectors", len, 0); - if (vport->recv_vectors == NULL) { - rte_free(alloc_vec); - return -ENOMEM; - } - } - - rte_memcpy(vport->recv_vectors, args.out_buffer, len); - rte_free(alloc_vec); - return err; -} - -int -idpf_vc_dealloc_vectors(struct idpf_vport *vport) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_alloc_vectors *alloc_vec; - struct virtchnl2_vector_chunks *vcs; - struct idpf_cmd_info args; - int err, len; - - alloc_vec = vport->recv_vectors; - vcs = &alloc_vec->vchunks; - - len = sizeof(struct virtchnl2_vector_chunks) + - (vcs->num_vchunks - 1) * sizeof(struct virtchnl2_vector_chunk); - - args.ops = VIRTCHNL2_OP_DEALLOC_VECTORS; - args.in_args = (u8 *)vcs; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command VIRTCHNL2_OP_DEALLOC_VECTORS"); - - return err; -} - -static int -idpf_vc_ena_dis_one_queue(struct idpf_vport *vport, uint16_t qid, - uint32_t type, bool on) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_del_ena_dis_queues *queue_select; - struct virtchnl2_queue_chunk *queue_chunk; - struct idpf_cmd_info args; - int err, len; - - len = sizeof(struct virtchnl2_del_ena_dis_queues); - queue_select = rte_zmalloc("queue_select", len, 0); - if (queue_select == NULL) - return -ENOMEM; - - queue_chunk = queue_select->chunks.chunks; - queue_select->chunks.num_chunks = 1; - queue_select->vport_id = vport->vport_id; - - queue_chunk->type = type; - queue_chunk->start_queue_id = qid; - queue_chunk->num_queues = 1; - - args.ops = on ? VIRTCHNL2_OP_ENABLE_QUEUES : - VIRTCHNL2_OP_DISABLE_QUEUES; - args.in_args = (u8 *)queue_select; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES", - on ? "ENABLE" : "DISABLE"); - - rte_free(queue_select); - return err; -} - -int -idpf_switch_queue(struct idpf_vport *vport, uint16_t qid, - bool rx, bool on) -{ - uint32_t type; - int err, queue_id; - - /* switch txq/rxq */ - type = rx ? VIRTCHNL2_QUEUE_TYPE_RX : VIRTCHNL2_QUEUE_TYPE_TX; - - if (type == VIRTCHNL2_QUEUE_TYPE_RX) - queue_id = vport->chunks_info.rx_start_qid + qid; - else - queue_id = vport->chunks_info.tx_start_qid + qid; - err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); - if (err != 0) - return err; - - /* switch tx completion queue */ - if (!rx && vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { - type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; - queue_id = vport->chunks_info.tx_compl_start_qid + qid; - err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); - if (err != 0) - return err; - } - - /* switch rx buffer queue */ - if (rx && vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { - type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER; - queue_id = vport->chunks_info.rx_buf_start_qid + 2 * qid; - err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); - if (err != 0) - return err; - queue_id++; - err = idpf_vc_ena_dis_one_queue(vport, queue_id, type, on); - if (err != 0) - return err; - } - - return err; -} - -#define IDPF_RXTX_QUEUE_CHUNKS_NUM 2 -int -idpf_vc_ena_dis_queues(struct idpf_vport *vport, bool enable) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_del_ena_dis_queues *queue_select; - struct virtchnl2_queue_chunk *queue_chunk; - uint32_t type; - struct idpf_cmd_info args; - uint16_t num_chunks; - int err, len; - - num_chunks = IDPF_RXTX_QUEUE_CHUNKS_NUM; - if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) - num_chunks++; - if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) - num_chunks++; - - len = sizeof(struct virtchnl2_del_ena_dis_queues) + - sizeof(struct virtchnl2_queue_chunk) * (num_chunks - 1); - queue_select = rte_zmalloc("queue_select", len, 0); - if (queue_select == NULL) - return -ENOMEM; - - queue_chunk = queue_select->chunks.chunks; - queue_select->chunks.num_chunks = num_chunks; - queue_select->vport_id = vport->vport_id; - - type = VIRTCHNL_QUEUE_TYPE_RX; - queue_chunk[type].type = type; - queue_chunk[type].start_queue_id = vport->chunks_info.rx_start_qid; - queue_chunk[type].num_queues = vport->num_rx_q; - - type = VIRTCHNL2_QUEUE_TYPE_TX; - queue_chunk[type].type = type; - queue_chunk[type].start_queue_id = vport->chunks_info.tx_start_qid; - queue_chunk[type].num_queues = vport->num_tx_q; - - if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { - type = VIRTCHNL2_QUEUE_TYPE_RX_BUFFER; - queue_chunk[type].type = type; - queue_chunk[type].start_queue_id = - vport->chunks_info.rx_buf_start_qid; - queue_chunk[type].num_queues = vport->num_rx_bufq; - } - - if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT) { - type = VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION; - queue_chunk[type].type = type; - queue_chunk[type].start_queue_id = - vport->chunks_info.tx_compl_start_qid; - queue_chunk[type].num_queues = vport->num_tx_complq; - } - - args.ops = enable ? VIRTCHNL2_OP_ENABLE_QUEUES : - VIRTCHNL2_OP_DISABLE_QUEUES; - args.in_args = (u8 *)queue_select; - args.in_args_size = len; - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_QUEUES", - enable ? "ENABLE" : "DISABLE"); - - rte_free(queue_select); - return err; -} - -int -idpf_vc_ena_dis_vport(struct idpf_vport *vport, bool enable) -{ - struct idpf_adapter *adapter = vport->adapter; - struct virtchnl2_vport vc_vport; - struct idpf_cmd_info args; - int err; - - vc_vport.vport_id = vport->vport_id; - args.ops = enable ? VIRTCHNL2_OP_ENABLE_VPORT : - VIRTCHNL2_OP_DISABLE_VPORT; - args.in_args = (uint8_t *)&vc_vport; - args.in_args_size = sizeof(vc_vport); - args.out_buffer = adapter->mbx_resp; - args.out_size = IDPF_DFLT_MBX_BUF_SIZE; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) { - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_%s_VPORT", - enable ? "ENABLE" : "DISABLE"); - } - - return err; -} - -int -idpf_vc_query_ptype_info(struct idpf_adapter *adapter) -{ - struct virtchnl2_get_ptype_info *ptype_info; - struct idpf_cmd_info args; - int len, err; - - len = sizeof(struct virtchnl2_get_ptype_info); - ptype_info = rte_zmalloc("ptype_info", len, 0); - if (ptype_info == NULL) - return -ENOMEM; - - ptype_info->start_ptype_id = 0; - ptype_info->num_ptypes = IDPF_MAX_PKT_TYPE; - args.ops = VIRTCHNL2_OP_GET_PTYPE_INFO; - args.in_args = (u8 *)ptype_info; - args.in_args_size = len; - - err = idpf_execute_vc_cmd(adapter, &args); - if (err != 0) - PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_PTYPE_INFO"); - - rte_free(ptype_info); - return err; -}