From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A05B2424E7; Mon, 4 Sep 2023 07:00:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 564F8402CF; Mon, 4 Sep 2023 06:58:09 +0200 (CEST) Received: from VLXDG1SPAM1.ramaxel.com (email.ramaxel.com [221.4.138.186]) by mails.dpdk.org (Postfix) with ESMTP id AFA40402BD for ; Mon, 4 Sep 2023 06:58:04 +0200 (CEST) Received: from V12DG1MBS03.ramaxel.local ([172.26.18.33]) by VLXDG1SPAM1.ramaxel.com with ESMTP id 3844vKxw054301; Mon, 4 Sep 2023 12:57:20 +0800 (GMT-8) (envelope-from wanry@3snic.com) Received: from localhost.localdomain (10.64.136.151) by V12DG1MBS03.ramaxel.local (172.26.18.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.17; Mon, 4 Sep 2023 12:57:20 +0800 From: To: CC: , Renyong Wan , Steven Song Subject: [PATCH v5 30/32] net/sssnic: support VLAN offload and filter Date: Mon, 4 Sep 2023 12:56:56 +0800 Message-ID: <20230904045658.238185-31-wanry@3snic.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230904045658.238185-1-wanry@3snic.com> References: <20230904045658.238185-1-wanry@3snic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Originating-IP: [10.64.136.151] X-ClientProxiedBy: V12DG1MBS03.ramaxel.local (172.26.18.33) To V12DG1MBS03.ramaxel.local (172.26.18.33) X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: VLXDG1SPAM1.ramaxel.com 3844vKxw054301 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: Renyong Wan Signed-off-by: Steven Song Signed-off-by: Renyong Wan --- doc/guides/nics/features/sssnic.ini | 2 + drivers/net/sssnic/base/sssnic_api.c | 34 +++++++++++ drivers/net/sssnic/base/sssnic_api.h | 1 + drivers/net/sssnic/base/sssnic_cmd.h | 9 +++ drivers/net/sssnic/sssnic_ethdev.c | 87 ++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) diff --git a/doc/guides/nics/features/sssnic.ini b/doc/guides/nics/features/sssnic.ini index 9bf05cb968..f5738ac934 100644 --- a/doc/guides/nics/features/sssnic.ini +++ b/doc/guides/nics/features/sssnic.ini @@ -19,6 +19,8 @@ RSS hash = Y RSS key update = Y RSS reta update = Y Inner RSS = Y +VLAN filter = Y +VLAN offload = Y L3 checksum offload = Y L4 checksum offload = Y Inner L3 checksum = Y diff --git a/drivers/net/sssnic/base/sssnic_api.c b/drivers/net/sssnic/base/sssnic_api.c index d91896cdd2..68c16c9c1e 100644 --- a/drivers/net/sssnic/base/sssnic_api.c +++ b/drivers/net/sssnic/base/sssnic_api.c @@ -1601,3 +1601,37 @@ sssnic_flow_ctrl_get(struct sssnic_hw *hw, bool *autoneg, bool *rx_en, return 0; } + +int +sssnic_vlan_filter_set(struct sssnic_hw *hw, uint16_t vid, bool add) +{ + int ret; + struct sssnic_vlan_filter_set_cmd cmd; + struct sssnic_msg msg; + uint32_t cmd_len; + + memset(&cmd, 0, sizeof(cmd)); + cmd.function = SSSNIC_FUNC_IDX(hw); + cmd.add = add ? 1 : 0; + cmd.vid = vid; + cmd_len = sizeof(cmd); + + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmd_len, + SSSNIC_SET_PORT_VLAN_FILTER_CMD, SSSNIC_MPU_FUNC_IDX, + SSSNIC_LAN_MODULE, SSSNIC_MSG_TYPE_REQ); + + ret = sssnic_mbox_send(hw, &msg, (uint8_t *)&cmd, &cmd_len, 0); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to send mbox message, ret=%d", ret); + return ret; + } + + if (cmd_len == 0 || cmd.common.status != 0) { + PMD_DRV_LOG(ERR, + "Bad response to SSSNIC_SET_PORT_VLAN_FILTER_CMD, len=%u, status=%u", + cmd_len, cmd.common.status); + return -EIO; + } + + return 0; +} diff --git a/drivers/net/sssnic/base/sssnic_api.h b/drivers/net/sssnic/base/sssnic_api.h index 36544a5dc3..28b235dda2 100644 --- a/drivers/net/sssnic/base/sssnic_api.h +++ b/drivers/net/sssnic/base/sssnic_api.h @@ -469,5 +469,6 @@ int sssnic_flow_ctrl_set(struct sssnic_hw *hw, bool autoneg, bool rx_en, bool tx_en); int sssnic_flow_ctrl_get(struct sssnic_hw *hw, bool *autoneg, bool *rx_en, bool *tx_en); +int sssnic_vlan_filter_set(struct sssnic_hw *hw, uint16_t vid, bool add); #endif /* _SSSNIC_API_H_ */ diff --git a/drivers/net/sssnic/base/sssnic_cmd.h b/drivers/net/sssnic/base/sssnic_cmd.h index d2054fad5a..3e70d0e223 100644 --- a/drivers/net/sssnic/base/sssnic_cmd.h +++ b/drivers/net/sssnic/base/sssnic_cmd.h @@ -425,4 +425,13 @@ struct sssnic_flow_ctrl_cmd { uint8_t resvd1[5]; }; +struct sssnic_vlan_filter_set_cmd { + struct sssnic_cmd_common common; + uint16_t function; + uint8_t add; + uint8_t resvd0; + uint16_t vid; + uint16_t resvd1; +}; + #endif /* _SSSNIC_CMD_H_ */ diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c index 8999693027..8a1ccff70b 100644 --- a/drivers/net/sssnic/sssnic_ethdev.c +++ b/drivers/net/sssnic/sssnic_ethdev.c @@ -16,6 +16,7 @@ #include "sssnic_ethdev_rss.h" static int sssnic_ethdev_init(struct rte_eth_dev *ethdev); +static void sssnic_ethdev_vlan_filter_clean(struct rte_eth_dev *ethdev); static int sssnic_ethdev_infos_get(struct rte_eth_dev *ethdev, @@ -340,6 +341,7 @@ sssnic_ethdev_release(struct rte_eth_dev *ethdev) { struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + sssnic_ethdev_vlan_filter_clean(ethdev); sssnic_ethdev_link_intr_disable(ethdev); sssnic_ethdev_tx_queue_all_release(ethdev); sssnic_ethdev_rx_queue_all_release(ethdev); @@ -821,6 +823,89 @@ sssnic_ethdev_flow_ctrl_get(struct rte_eth_dev *ethdev, return 0; } +static int +sssnic_ethdev_vlan_offload_set(struct rte_eth_dev *ethdev, int mask) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + struct rte_eth_conf *dev_conf = ðdev->data->dev_conf; + uint8_t vlan_strip_en; + uint32_t vlan_filter_en; + int ret; + + if (mask & RTE_ETH_VLAN_STRIP_MASK) { + if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) + vlan_strip_en = 1; + else + vlan_strip_en = 0; + + ret = sssnic_vlan_strip_enable_set(hw, vlan_strip_en); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to %s vlan strip offload", + vlan_strip_en ? "enable" : "disable"); + return ret; + } + } + + if (mask & RTE_ETH_VLAN_FILTER_MASK) { + if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) + vlan_filter_en = 1; + else + vlan_filter_en = 0; + + ret = sssnic_vlan_filter_enable_set(hw, vlan_filter_en); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to %s vlan filter offload", + vlan_filter_en ? "enable" : "disable"); + return ret; + } + } + + return 0; +} + +static int +sssnic_ethdev_vlan_filter_get(struct rte_eth_dev *ethdev, uint16_t vlan_id) +{ + struct rte_vlan_filter_conf *vfc = ðdev->data->vlan_filter_conf; + int vidx = vlan_id / 64; + int vbit = vlan_id % 64; + + return !!(vfc->ids[vidx] & RTE_BIT64(vbit)); +} + +static int +sssnic_ethdev_vlan_filter_set(struct rte_eth_dev *ethdev, uint16_t vlan_id, + int on) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + int ret; + + if (sssnic_ethdev_vlan_filter_get(ethdev, vlan_id) == !!on) + return 0; + + ret = sssnic_vlan_filter_set(hw, vlan_id, !!on); + if (ret) { + PMD_DRV_LOG(ERR, + "Failed to %s VLAN filter, vlan_id: %u, port: %u", + on ? "add" : "remove", vlan_id, ethdev->data->port_id); + return ret; + } + + PMD_DRV_LOG(DEBUG, "%s VLAN %u filter to port %u", + on ? "Added" : "Removed", vlan_id, ethdev->data->port_id); + + return 0; +} + +static void +sssnic_ethdev_vlan_filter_clean(struct rte_eth_dev *ethdev) +{ + uint16_t vlan_id; + + for (vlan_id = 0; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) + sssnic_ethdev_vlan_filter_set(ethdev, vlan_id, 0); +} + static const struct eth_dev_ops sssnic_ethdev_ops = { .dev_start = sssnic_ethdev_start, .dev_stop = sssnic_ethdev_stop, @@ -864,6 +949,8 @@ static const struct eth_dev_ops sssnic_ethdev_ops = { .fw_version_get = sssnic_ethdev_fw_version_get, .flow_ctrl_set = sssnic_ethdev_flow_ctrl_set, .flow_ctrl_get = sssnic_ethdev_flow_ctrl_get, + .vlan_offload_set = sssnic_ethdev_vlan_offload_set, + .vlan_filter_set = sssnic_ethdev_vlan_filter_set, }; static int -- 2.27.0