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 23A21424E7; Mon, 4 Sep 2023 06:59:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B690040A7A; Mon, 4 Sep 2023 06:57:49 +0200 (CEST) Received: from VLXDG1SPAM1.ramaxel.com (email.unionmem.com [221.4.138.186]) by mails.dpdk.org (Postfix) with ESMTP id 196B34064E for ; Mon, 4 Sep 2023 06:57:42 +0200 (CEST) Received: from V12DG1MBS03.ramaxel.local ([172.26.18.33]) by VLXDG1SPAM1.ramaxel.com with ESMTP id 3844vDRG054257; Mon, 4 Sep 2023 12:57:14 +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:12 +0800 From: To: CC: , Renyong Wan , Steven Song Subject: [PATCH v5 12/32] net/sssnic: support dev link status Date: Mon, 4 Sep 2023 12:56:38 +0800 Message-ID: <20230904045658.238185-13-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 3844vDRG054257 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 --- v2: * Removed error.h from including files. --- doc/guides/nics/features/sssnic.ini | 1 + drivers/net/sssnic/base/sssnic_api.c | 127 ++++++++++++++++++++++++ drivers/net/sssnic/base/sssnic_api.h | 14 +++ drivers/net/sssnic/base/sssnic_cmd.h | 37 +++++++ drivers/net/sssnic/meson.build | 1 + drivers/net/sssnic/sssnic_ethdev.c | 4 + drivers/net/sssnic/sssnic_ethdev_link.c | 111 +++++++++++++++++++++ drivers/net/sssnic/sssnic_ethdev_link.h | 12 +++ 8 files changed, 307 insertions(+) create mode 100644 drivers/net/sssnic/sssnic_ethdev_link.c create mode 100644 drivers/net/sssnic/sssnic_ethdev_link.h diff --git a/doc/guides/nics/features/sssnic.ini b/doc/guides/nics/features/sssnic.ini index 602839d301..a0688e70ef 100644 --- a/doc/guides/nics/features/sssnic.ini +++ b/doc/guides/nics/features/sssnic.ini @@ -4,6 +4,7 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +Link status = Y Unicast MAC filter = Y Multicast MAC filter = Y Linux = Y diff --git a/drivers/net/sssnic/base/sssnic_api.c b/drivers/net/sssnic/base/sssnic_api.c index 76266dfbae..3bb31009c5 100644 --- a/drivers/net/sssnic/base/sssnic_api.c +++ b/drivers/net/sssnic/base/sssnic_api.c @@ -307,3 +307,130 @@ sssnic_mac_addr_del(struct sssnic_hw *hw, uint8_t *addr) return 0; } + +int +sssnic_netif_link_status_get(struct sssnic_hw *hw, uint8_t *status) +{ + int ret; + struct sssnic_netif_link_status_get_cmd cmd; + struct sssnic_msg msg; + uint32_t cmd_len; + uint16_t func; + + if (hw == NULL || status == NULL) + return -EINVAL; + + if (SSSNIC_FUNC_TYPE(hw) == SSSNIC_FUNC_TYPE_VF) + func = SSSNIC_PF_FUNC_IDX(hw); + else + func = SSSNIC_MPU_FUNC_IDX; + + memset(&cmd, 0, sizeof(cmd)); + cmd.port = SSSNIC_PHY_PORT(hw); + cmd_len = sizeof(cmd); + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmd_len, + SSSNIC_GET_NETIF_LINK_STATUS_CMD, func, SSSNIC_NETIF_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_GET_NETIF_LINK_STATUS_CMD, len=%u, status=%u", + cmd_len, cmd.common.status); + return -EIO; + } + + *status = cmd.status; + + return 0; +} + +int +sssnic_netif_link_info_get(struct sssnic_hw *hw, + struct sssnic_netif_link_info *info) +{ + int ret; + struct sssnic_netif_link_info_get_cmd cmd; + struct sssnic_msg msg; + uint32_t cmd_len; + + if (hw == NULL || info == NULL) + return -EINVAL; + + ret = sssnic_netif_link_status_get(hw, &info->status); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to get netif link state!"); + return ret; + } + + memset(&cmd, 0, sizeof(cmd)); + cmd.port = SSSNIC_PHY_PORT(hw); + cmd_len = sizeof(cmd); + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmd_len, + SSSNIC_GET_NETIF_LINK_INFO_CMD, SSSNIC_MPU_FUNC_IDX, + SSSNIC_NETIF_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_GET_NETIF_LINK_INFO_CMD, len=%u, status=%u", + cmd_len, cmd.common.status); + return -EIO; + } + + info->speed = cmd.speed; + info->duplex = cmd.duplex; + info->fec = cmd.fec; + info->type = cmd.type; + info->autoneg_capa = cmd.autoneg_capa; + info->autoneg = cmd.autoneg; + + return 0; +} + +int +sssnic_netif_enable_set(struct sssnic_hw *hw, uint8_t state) +{ + int ret; + struct sssnic_netif_enable_set_cmd cmd; + struct sssnic_msg msg; + uint32_t cmd_len; + + if (hw == NULL) + return -EINVAL; + + if (SSSNIC_FUNC_TYPE(hw) == SSSNIC_FUNC_TYPE_VF) + return 0; + + memset(&cmd, 0, sizeof(cmd)); + cmd.function = SSSNIC_FUNC_IDX(hw); + if (state != 0) + cmd.flag = SSSNIC_SET_NETIF_ENABLE_CMD_FLAG_RX_EN | + SSSNIC_SET_NETIF_ENABLE_CMD_FLAG_TX_EN; + cmd_len = sizeof(cmd); + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmd_len, + SSSNIC_SET_NETIF_ENABLE_CMD, SSSNIC_MPU_FUNC_IDX, + SSSNIC_NETIF_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_NETIF_ENABLE_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 b985230595..168aa152b9 100644 --- a/drivers/net/sssnic/base/sssnic_api.h +++ b/drivers/net/sssnic/base/sssnic_api.h @@ -22,6 +22,16 @@ struct sssnic_capability { uint8_t cos; }; +struct sssnic_netif_link_info { + uint8_t status; + uint8_t type; + uint8_t autoneg_capa; + uint8_t autoneg; + uint8_t duplex; + uint8_t speed; + uint8_t fec; +}; + int sssnic_msix_attr_get(struct sssnic_hw *hw, uint16_t msix_idx, struct sssnic_msix_attr *attr); int sssnic_msix_attr_set(struct sssnic_hw *hw, uint16_t msix_idx, @@ -31,5 +41,9 @@ int sssnic_mac_addr_get(struct sssnic_hw *hw, uint8_t *addr); int sssnic_mac_addr_update(struct sssnic_hw *hw, uint8_t *new, uint8_t *old); int sssnic_mac_addr_add(struct sssnic_hw *hw, uint8_t *addr); int sssnic_mac_addr_del(struct sssnic_hw *hw, uint8_t *addr); +int sssnic_netif_link_status_get(struct sssnic_hw *hw, uint8_t *status); +int sssnic_netif_link_info_get(struct sssnic_hw *hw, + struct sssnic_netif_link_info *info); +int sssnic_netif_enable_set(struct sssnic_hw *hw, uint8_t state); #endif /* _SSSNIC_API_H_ */ diff --git a/drivers/net/sssnic/base/sssnic_cmd.h b/drivers/net/sssnic/base/sssnic_cmd.h index e70184866e..6957b742fc 100644 --- a/drivers/net/sssnic/base/sssnic_cmd.h +++ b/drivers/net/sssnic/base/sssnic_cmd.h @@ -27,6 +27,13 @@ enum sssnic_mac_addr_cmd_id { SSSNIC_DEL_MAC_ADDR_CMD, SSSNIC_UPDATE_MAC_ADDR_CMD, }; +enum sssnic_netif_cmd_id { + SSSNIC_SET_NETIF_ENABLE_CMD = 6, + SSSNIC_GET_NETIF_LINK_STATUS_CMD = 7, + SSSNIC_GET_NETIF_MAC_STATS_CMD = 151, + SSSNIC_CLEAR_NETIF_MAC_STATS_CMD = 152, + SSSNIC_GET_NETIF_LINK_INFO_CMD = 153, +}; struct sssnic_cmd_common { uint8_t status; @@ -150,4 +157,34 @@ struct sssnic_mac_addr_update_cmd { uint16_t resvd1; uint8_t new_addr[6]; }; +struct sssnic_netif_link_status_get_cmd { + struct sssnic_cmd_common common; + uint8_t port; + uint8_t status; + uint16_t rsvd; +}; + +struct sssnic_netif_link_info_get_cmd { + struct sssnic_cmd_common common; + uint8_t port; + uint8_t resvd0[3]; + uint8_t type; + uint8_t autoneg_capa; + uint8_t autoneg; + uint8_t duplex; + uint8_t speed; + uint8_t fec; + uint8_t resvd1[18]; +}; + +#define SSSNIC_SET_NETIF_ENABLE_CMD_FLAG_TX_EN 0x1 +#define SSSNIC_SET_NETIF_ENABLE_CMD_FLAG_RX_EN 0x2 +struct sssnic_netif_enable_set_cmd { + struct sssnic_cmd_common common; + uint16_t function; + uint16_t resvd0; + uint8_t flag; + uint8_t resvd1[3]; +}; + #endif /* _SSSNIC_CMD_H_ */ diff --git a/drivers/net/sssnic/meson.build b/drivers/net/sssnic/meson.build index 328bb41436..12e967722a 100644 --- a/drivers/net/sssnic/meson.build +++ b/drivers/net/sssnic/meson.build @@ -18,4 +18,5 @@ objs = [base_objs] sources = files( 'sssnic_ethdev.c', + 'sssnic_ethdev_link.c', ) diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c index 92a20649fc..4e546cca66 100644 --- a/drivers/net/sssnic/sssnic_ethdev.c +++ b/drivers/net/sssnic/sssnic_ethdev.c @@ -9,6 +9,7 @@ #include "base/sssnic_hw.h" #include "base/sssnic_api.h" #include "sssnic_ethdev.h" +#include "sssnic_ethdev_link.h" static int sssnic_ethdev_infos_get(struct rte_eth_dev *ethdev, @@ -339,6 +340,9 @@ sssnic_ethdev_release(struct rte_eth_dev *ethdev) } static const struct eth_dev_ops sssnic_ethdev_ops = { + .dev_set_link_up = sssnic_ethdev_set_link_up, + .dev_set_link_down = sssnic_ethdev_set_link_down, + .link_update = sssnic_ethdev_link_update, .dev_configure = sssnic_ethdev_configure, .dev_infos_get = sssnic_ethdev_infos_get, .mac_addr_set = sssnic_ethdev_mac_addr_set, diff --git a/drivers/net/sssnic/sssnic_ethdev_link.c b/drivers/net/sssnic/sssnic_ethdev_link.c new file mode 100644 index 0000000000..04e2d2e5d2 --- /dev/null +++ b/drivers/net/sssnic/sssnic_ethdev_link.c @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018-2022 Shenzhen 3SNIC Information Technology Co., Ltd. + */ + +#include +#include + +#include "sssnic_log.h" +#include "sssnic_ethdev.h" +#include "sssnic_ethdev_link.h" +#include "base/sssnic_hw.h" +#include "base/sssnic_api.h" + +static const uint32_t sssnic_ethdev_speed_map[] = { RTE_ETH_SPEED_NUM_NONE, + RTE_ETH_SPEED_NUM_10M, RTE_ETH_SPEED_NUM_100M, RTE_ETH_SPEED_NUM_1G, + RTE_ETH_SPEED_NUM_10G, RTE_ETH_SPEED_NUM_25G, RTE_ETH_SPEED_NUM_40G, + RTE_ETH_SPEED_NUM_50G, RTE_ETH_SPEED_NUM_100G, RTE_ETH_SPEED_NUM_200G }; + +#define SSSNIC_ETHDEV_NUM_SPEED_TYPE RTE_DIM(sssnic_ethdev_speed_map) + +static int +sssnic_ethdev_link_get(struct rte_eth_dev *ethdev, struct rte_eth_link *link) +{ + int ret; + struct sssnic_netif_link_info info; + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + + memset(&info, 0, sizeof(info)); + ret = sssnic_netif_link_info_get(hw, &info); + if (ret != 0) { + link->link_status = RTE_ETH_LINK_DOWN; + link->link_speed = RTE_ETH_SPEED_NUM_NONE; + link->link_duplex = RTE_ETH_LINK_HALF_DUPLEX; + link->link_autoneg = RTE_ETH_LINK_FIXED; + PMD_DRV_LOG(ERR, "Failed to get netif link info"); + return ret; + } + + if (!info.status) { + link->link_status = RTE_ETH_LINK_DOWN; + link->link_speed = RTE_ETH_SPEED_NUM_NONE; + link->link_duplex = RTE_ETH_LINK_HALF_DUPLEX; + link->link_autoneg = RTE_ETH_LINK_FIXED; + } else { + link->link_status = RTE_ETH_LINK_UP; + link->link_duplex = info.duplex; + link->link_autoneg = info.autoneg; + if (info.speed >= SSSNIC_ETHDEV_NUM_SPEED_TYPE) + link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN; + else + link->link_speed = sssnic_ethdev_speed_map[info.speed]; + } + + return 0; +} + +int +sssnic_ethdev_set_link_up(struct rte_eth_dev *ethdev) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + int ret; + + ret = sssnic_netif_enable_set(hw, 1); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to enable netif"); + return ret; + } + + return 0; +} + +int +sssnic_ethdev_set_link_down(struct rte_eth_dev *ethdev) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + int ret; + + ret = sssnic_netif_enable_set(hw, 0); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to disable netif"); + return ret; + } + + return 0; +} + +int +sssnic_ethdev_link_update(struct rte_eth_dev *ethdev, int wait_to_complete) +{ +#define CHECK_INTERVAL 100 /* 100ms */ +#define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */ + int ret; + struct rte_eth_link link; + unsigned int rep_cnt = MAX_REPEAT_TIME; + + memset(&link, 0, sizeof(link)); + do { + ret = sssnic_ethdev_link_get(ethdev, &link); + if (ret != 0) + goto out; + + if (!wait_to_complete || link.link_status) + goto out; + + rte_delay_ms(CHECK_INTERVAL); + + } while (--rep_cnt); + +out: + return rte_eth_linkstatus_set(ethdev, &link); +} diff --git a/drivers/net/sssnic/sssnic_ethdev_link.h b/drivers/net/sssnic/sssnic_ethdev_link.h new file mode 100644 index 0000000000..00ad13fe9b --- /dev/null +++ b/drivers/net/sssnic/sssnic_ethdev_link.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018-2022 Shenzhen 3SNIC Information Technology Co., Ltd. + */ + +#ifndef _SSSNIC_ETHDEV_LINK_H_ +#define _SSSNIC_ETHDEV_LINK_H_ + +int sssnic_ethdev_set_link_up(struct rte_eth_dev *ethdev); +int sssnic_ethdev_set_link_down(struct rte_eth_dev *ethdev); +int sssnic_ethdev_link_update(struct rte_eth_dev *ethdev, int wait_to_complete); + +#endif /* _SSSNIC_ETHDEV_LINK_H_ */ -- 2.27.0