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 968B1424E7; Mon, 4 Sep 2023 07:00:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 43DFE4111C; Mon, 4 Sep 2023 06:58:14 +0200 (CEST) Received: from VLXDG1SPAM1.ramaxel.com (email.unionmem.com [221.4.138.186]) by mails.dpdk.org (Postfix) with ESMTP id C195E40EF1 for ; Mon, 4 Sep 2023 06:58:05 +0200 (CEST) Received: from V12DG1MBS03.ramaxel.local ([172.26.18.33]) by VLXDG1SPAM1.ramaxel.com with ESMTP id 3844vK54054299; 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:19 +0800 From: To: CC: , Renyong Wan , Steven Song Subject: [PATCH v5 29/32] net/sssnic: add dev flow control ops Date: Mon, 4 Sep 2023 12:56:55 +0800 Message-ID: <20230904045658.238185-30-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 3844vK54054299 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 | 1 + drivers/net/sssnic/base/sssnic_api.c | 68 ++++++++++++++++++++++++++++ drivers/net/sssnic/base/sssnic_api.h | 4 ++ drivers/net/sssnic/base/sssnic_cmd.h | 11 +++++ drivers/net/sssnic/sssnic_ethdev.c | 65 ++++++++++++++++++++++++++ 5 files changed, 149 insertions(+) diff --git a/doc/guides/nics/features/sssnic.ini b/doc/guides/nics/features/sssnic.ini index a40b509558..9bf05cb968 100644 --- a/doc/guides/nics/features/sssnic.ini +++ b/doc/guides/nics/features/sssnic.ini @@ -26,6 +26,7 @@ Inner L4 checksum = Y Basic stats = Y Extended stats = Y Stats per queue = Y +Flow control = P FW version = Y Linux = Y ARMv8 = Y diff --git a/drivers/net/sssnic/base/sssnic_api.c b/drivers/net/sssnic/base/sssnic_api.c index 12aca16995..d91896cdd2 100644 --- a/drivers/net/sssnic/base/sssnic_api.c +++ b/drivers/net/sssnic/base/sssnic_api.c @@ -1533,3 +1533,71 @@ sssnic_fw_version_get(struct sssnic_hw *hw, struct sssnic_fw_version *version) return 0; } + +int +sssnic_flow_ctrl_set(struct sssnic_hw *hw, bool autoneg, bool rx_en, bool tx_en) +{ + int ret; + struct sssnic_msg msg; + struct sssnic_flow_ctrl_cmd cmd; + uint32_t cmdlen = sizeof(cmd); + + memset(&cmd, 0, sizeof(cmd)); + cmd.auto_neg = autoneg ? 1 : 0; + cmd.rx_en = rx_en ? 1 : 0; + cmd.tx_en = tx_en ? 1 : 0; + cmd.opcode = SSSNIC_CMD_OPCODE_SET; + + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmdlen, + SSSNIC_PORT_FLOW_CTRL_CMD, SSSNIC_MPU_FUNC_IDX, + SSSNIC_LAN_MODULE, SSSNIC_MSG_TYPE_REQ); + ret = sssnic_mbox_send(hw, &msg, (uint8_t *)&cmd, &cmdlen, 0); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to send mbox message, ret=%d", ret); + return ret; + } + + if (cmdlen == 0 || cmd.common.status != 0) { + PMD_DRV_LOG(ERR, + "Bad response to SSSNIC_PORT_FLOW_CTRL_CMD, len=%u, status=%u", + cmdlen, cmd.common.status); + return -EIO; + } + + return 0; +} + +int +sssnic_flow_ctrl_get(struct sssnic_hw *hw, bool *autoneg, bool *rx_en, + bool *tx_en) +{ + int ret; + struct sssnic_msg msg; + struct sssnic_flow_ctrl_cmd cmd; + uint32_t cmdlen = sizeof(cmd); + + memset(&cmd, 0, sizeof(cmd)); + cmd.opcode = SSSNIC_CMD_OPCODE_GET; + + sssnic_msg_init(&msg, (uint8_t *)&cmd, cmdlen, + SSSNIC_PORT_FLOW_CTRL_CMD, SSSNIC_MPU_FUNC_IDX, + SSSNIC_LAN_MODULE, SSSNIC_MSG_TYPE_REQ); + ret = sssnic_mbox_send(hw, &msg, (uint8_t *)&cmd, &cmdlen, 0); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to send mbox message, ret=%d", ret); + return ret; + } + + if (cmdlen == 0 || cmd.common.status != 0) { + PMD_DRV_LOG(ERR, + "Bad response to SSSNIC_PORT_FLOW_CTRL_CMD, len=%u, status=%u", + cmdlen, cmd.common.status); + return -EIO; + } + + *autoneg = cmd.auto_neg; + *rx_en = cmd.rx_en; + *tx_en = cmd.tx_en; + + return 0; +} diff --git a/drivers/net/sssnic/base/sssnic_api.h b/drivers/net/sssnic/base/sssnic_api.h index bd4f01d388..36544a5dc3 100644 --- a/drivers/net/sssnic/base/sssnic_api.h +++ b/drivers/net/sssnic/base/sssnic_api.h @@ -465,5 +465,9 @@ int sssnic_rss_indir_table_get(struct sssnic_hw *hw, uint16_t *entry, uint32_t num_entries); int sssnic_fw_version_get(struct sssnic_hw *hw, struct sssnic_fw_version *version); +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); #endif /* _SSSNIC_API_H_ */ diff --git a/drivers/net/sssnic/base/sssnic_cmd.h b/drivers/net/sssnic/base/sssnic_cmd.h index 9da07770b1..d2054fad5a 100644 --- a/drivers/net/sssnic/base/sssnic_cmd.h +++ b/drivers/net/sssnic/base/sssnic_cmd.h @@ -414,4 +414,15 @@ struct sssnic_fw_version_get_cmd { uint8_t time[20]; }; +struct sssnic_flow_ctrl_cmd { + struct sssnic_cmd_common common; + uint8_t port; + uint8_t opcode; + uint16_t resvd0; + uint8_t auto_neg; + uint8_t rx_en; + uint8_t tx_en; + uint8_t resvd1[5]; +}; + #endif /* _SSSNIC_CMD_H_ */ diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c index cceaa5c8be..8999693027 100644 --- a/drivers/net/sssnic/sssnic_ethdev.c +++ b/drivers/net/sssnic/sssnic_ethdev.c @@ -758,6 +758,69 @@ sssnic_ethdev_fw_version_get(struct rte_eth_dev *ethdev, char *fw_version, return 0; } +static int +sssnic_ethdev_flow_ctrl_set(struct rte_eth_dev *ethdev, + struct rte_eth_fc_conf *fc_conf) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + bool autoneg, rx_en, tx_en; + int ret; + + if (fc_conf->autoneg != 0) + autoneg = true; + else + autoneg = false; + + if (fc_conf->mode == RTE_ETH_FC_FULL || + fc_conf->mode == RTE_ETH_FC_RX_PAUSE) + rx_en = true; + else + rx_en = false; + + if (fc_conf->mode == RTE_ETH_FC_FULL || + fc_conf->mode == RTE_ETH_FC_TX_PAUSE) + tx_en = true; + else + tx_en = false; + + ret = sssnic_flow_ctrl_set(hw, autoneg, rx_en, tx_en); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to set flow conctrol"); + return ret; + } + + return 0; +} + +static int +sssnic_ethdev_flow_ctrl_get(struct rte_eth_dev *ethdev, + struct rte_eth_fc_conf *fc_conf) +{ + struct sssnic_hw *hw = SSSNIC_ETHDEV_TO_HW(ethdev); + bool autoneg, rx_en, tx_en; + int ret; + + ret = sssnic_flow_ctrl_get(hw, &autoneg, &rx_en, &tx_en); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to get flow conctrol"); + return ret; + } + + if (autoneg) + fc_conf->autoneg = true; + + if (rx_en && tx_en) + fc_conf->mode = RTE_ETH_FC_FULL; + else if (rx_en) + fc_conf->mode = RTE_ETH_FC_RX_PAUSE; + else if (tx_en) + fc_conf->mode = RTE_ETH_FC_TX_PAUSE; + else + fc_conf->mode = RTE_ETH_FC_NONE; + + return 0; +} + static const struct eth_dev_ops sssnic_ethdev_ops = { .dev_start = sssnic_ethdev_start, .dev_stop = sssnic_ethdev_stop, @@ -799,6 +862,8 @@ static const struct eth_dev_ops sssnic_ethdev_ops = { .rxq_info_get = sssnic_ethdev_rx_queue_info_get, .txq_info_get = sssnic_ethdev_tx_queue_info_get, .fw_version_get = sssnic_ethdev_fw_version_get, + .flow_ctrl_set = sssnic_ethdev_flow_ctrl_set, + .flow_ctrl_get = sssnic_ethdev_flow_ctrl_get, }; static int -- 2.27.0