DPDK patches and discussions
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, <linuxarm@openeuler.org>
Subject: [dpdk-dev] [PATCH V2 01/14] net/hns3: support module EEPROM dump
Date: Tue, 2 Mar 2021 21:58:41 +0800	[thread overview]
Message-ID: <1614693534-27620-2-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1614693534-27620-1-git-send-email-oulijun@huawei.com>

From: Chengchang Tang <tangchengchang@huawei.com>

This patch add support for dumping module EEPROM.

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 doc/guides/rel_notes/release_21_05.rst |   4 +
 drivers/net/hns3/hns3_cmd.h            |  16 ++++
 drivers/net/hns3/hns3_ethdev.c         | 159 +++++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+)

diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index ca28d05..67a0daa 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -64,6 +64,10 @@ New Features
   * Added command to display Rx queue used descriptor count.
     ``show port (port_id) rxq (queue_id) desc used count``
 
+* **Updated Hisilicon hns3 driver.**
+
+  * Added support for module EEPROM dumping.
+
 
 Removed Items
 -------------
diff --git a/drivers/net/hns3/hns3_cmd.h b/drivers/net/hns3/hns3_cmd.h
index 5010278..ff424a0 100644
--- a/drivers/net/hns3/hns3_cmd.h
+++ b/drivers/net/hns3/hns3_cmd.h
@@ -211,6 +211,8 @@ enum hns3_opcode_type {
 	HNS3_OPC_FIRMWARE_COMPAT_CFG    = 0x701A,
 
 	/* SFP command */
+	HNS3_OPC_GET_SFP_EEPROM         = 0x7100,
+	HNS3_OPC_GET_SFP_EXIST          = 0x7101,
 	HNS3_OPC_SFP_GET_SPEED          = 0x7104,
 
 	/* Interrupts commands */
@@ -714,6 +716,20 @@ struct hns3_config_auto_neg_cmd {
 #define HNS3_MAC_FEC_BASER		1
 #define HNS3_MAC_FEC_RS			2
 
+#define HNS3_SFP_INFO_BD0_LEN  20UL
+#define HNS3_SFP_INFO_BDX_LEN  24UL
+
+struct hns3_sfp_info_bd0_cmd {
+	uint16_t offset;
+	uint16_t read_len;
+	uint8_t data[HNS3_SFP_INFO_BD0_LEN];
+};
+
+struct hns3_sfp_type {
+	uint8_t type;
+	uint8_t ext_type;
+};
+
 struct hns3_sfp_speed_cmd {
 	uint32_t  sfp_speed;
 	uint8_t   query_type; /* 0: sfp speed, 1: active fec */
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index dbd48de..e02a7ec 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -6172,6 +6172,163 @@ hns3_query_dev_fec_info(struct hns3_hw *hw)
 	return ret;
 }
 
+static bool
+hns3_optical_module_existed(struct hns3_hw *hw)
+{
+	struct hns3_cmd_desc desc;
+	bool existed;
+	int ret;
+
+	hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GET_SFP_EXIST, true);
+	ret = hns3_cmd_send(hw, &desc, 1);
+	if (ret) {
+		hns3_err(hw,
+			 "fail to get optical module exist state, ret = %d.\n",
+			 ret);
+		return false;
+	}
+	existed = !!desc.data[0];
+
+	return existed;
+}
+
+static int
+hns3_get_module_eeprom_data(struct hns3_hw *hw, uint32_t offset,
+				uint32_t len, uint8_t *data)
+{
+#define HNS3_SFP_INFO_CMD_NUM 6
+#define HNS3_SFP_INFO_MAX_LEN \
+	(HNS3_SFP_INFO_BD0_LEN + \
+	(HNS3_SFP_INFO_CMD_NUM - 1) * HNS3_SFP_INFO_BDX_LEN)
+	struct hns3_cmd_desc desc[HNS3_SFP_INFO_CMD_NUM];
+	struct hns3_sfp_info_bd0_cmd *sfp_info_bd0;
+	uint16_t read_len;
+	uint16_t copy_len;
+	int ret;
+	int i;
+
+	for (i = 0; i < HNS3_SFP_INFO_CMD_NUM; i++) {
+		hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_GET_SFP_EEPROM,
+					  true);
+		if (i < HNS3_SFP_INFO_CMD_NUM - 1)
+			desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
+	}
+
+	sfp_info_bd0 = (struct hns3_sfp_info_bd0_cmd *)desc[0].data;
+	sfp_info_bd0->offset = rte_cpu_to_le_16((uint16_t)offset);
+	read_len = RTE_MIN(len, HNS3_SFP_INFO_MAX_LEN);
+	sfp_info_bd0->read_len = rte_cpu_to_le_16((uint16_t)read_len);
+
+	ret = hns3_cmd_send(hw, desc, HNS3_SFP_INFO_CMD_NUM);
+	if (ret) {
+		hns3_err(hw, "fail to get module EEPROM info, ret = %d.\n",
+				ret);
+		return ret;
+	}
+
+	/* The data format in BD0 is different with the others. */
+	copy_len = RTE_MIN(len, HNS3_SFP_INFO_BD0_LEN);
+	memcpy(data, sfp_info_bd0->data, copy_len);
+	read_len = copy_len;
+
+	for (i = 1; i < HNS3_SFP_INFO_CMD_NUM; i++) {
+		if (read_len >= len)
+			break;
+
+		copy_len = RTE_MIN(len - read_len, HNS3_SFP_INFO_BDX_LEN);
+		memcpy(data + read_len, desc[i].data, copy_len);
+		read_len += copy_len;
+	}
+
+	return (int)read_len;
+}
+
+static int
+hns3_get_module_eeprom(struct rte_eth_dev *dev,
+		       struct rte_dev_eeprom_info *info)
+{
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
+	uint32_t offset = info->offset;
+	uint32_t len = info->length;
+	uint8_t *data = info->data;
+	uint32_t read_len = 0;
+
+	if (hw->mac.media_type != HNS3_MEDIA_TYPE_FIBER)
+		return -ENOTSUP;
+
+	if (!hns3_optical_module_existed(hw)) {
+		hns3_err(hw, "fail to read module EEPROM: no module is connected.\n");
+		return -EIO;
+	}
+
+	while (read_len < len) {
+		int ret;
+		ret = hns3_get_module_eeprom_data(hw, offset + read_len,
+						  len - read_len,
+						  data + read_len);
+		if (ret < 0)
+			return -EIO;
+		read_len += ret;
+	}
+
+	return 0;
+}
+
+static int
+hns3_get_module_info(struct rte_eth_dev *dev,
+		     struct rte_eth_dev_module_info *modinfo)
+{
+#define HNS3_SFF8024_ID_SFP		0x03
+#define HNS3_SFF8024_ID_QSFP_8438	0x0c
+#define HNS3_SFF8024_ID_QSFP_8436_8636	0x0d
+#define HNS3_SFF8024_ID_QSFP28_8636	0x11
+#define HNS3_SFF_8636_V1_3		0x03
+	struct hns3_adapter *hns = dev->data->dev_private;
+	struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(hns);
+	struct rte_dev_eeprom_info info;
+	struct hns3_sfp_type sfp_type;
+	int ret;
+
+	memset(&sfp_type, 0, sizeof(sfp_type));
+	memset(&info, 0, sizeof(info));
+	info.data = (uint8_t *)&sfp_type;
+	info.length = sizeof(sfp_type);
+	ret = hns3_get_module_eeprom(dev, &info);
+	if (ret)
+		return ret;
+
+	switch (sfp_type.type) {
+	case HNS3_SFF8024_ID_SFP:
+		modinfo->type = RTE_ETH_MODULE_SFF_8472;
+		modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
+		break;
+	case HNS3_SFF8024_ID_QSFP_8438:
+		modinfo->type = RTE_ETH_MODULE_SFF_8436;
+		modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_MAX_LEN;
+		break;
+	case HNS3_SFF8024_ID_QSFP_8436_8636:
+		if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
+			modinfo->type = RTE_ETH_MODULE_SFF_8436;
+			modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_MAX_LEN;
+		} else {
+			modinfo->type = RTE_ETH_MODULE_SFF_8636;
+			modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
+		}
+		break;
+	case HNS3_SFF8024_ID_QSFP28_8636:
+		modinfo->type = RTE_ETH_MODULE_SFF_8636;
+		modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
+		break;
+	default:
+		hns3_err(hw, "unknown module, type = %u, extra_type = %u.\n",
+			 sfp_type.type, sfp_type.ext_type);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static const struct eth_dev_ops hns3_eth_dev_ops = {
 	.dev_configure      = hns3_dev_configure,
 	.dev_start          = hns3_dev_start,
@@ -6223,6 +6380,8 @@ static const struct eth_dev_ops hns3_eth_dev_ops = {
 	.vlan_offload_set       = hns3_vlan_offload_set,
 	.vlan_pvid_set          = hns3_vlan_pvid_set,
 	.get_reg                = hns3_get_regs,
+	.get_module_info        = hns3_get_module_info,
+	.get_module_eeprom      = hns3_get_module_eeprom,
 	.get_dcb_info           = hns3_get_dcb_info,
 	.dev_supported_ptypes_get = hns3_dev_supported_ptypes_get,
 	.fec_get_capability     = hns3_fec_get_capability,
-- 
2.7.4


  reply	other threads:[~2021-03-02 13:59 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24  1:28 [dpdk-dev] [PATCH 00/13] Features and bugfixes for hns3 Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 01/13] net/hns3: support module EEPROM dump Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 02/13] net/hns3: add more registers to dump Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 03/13] net/hns3: implement cleanup for Tx done Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 04/13] net/hns3: add Rx and Tx bytes stats Lijun Ou
2021-02-26 15:25   ` Ferruh Yigit
2021-02-24  1:28 ` [dpdk-dev] [PATCH 05/13] net/hns3: add imissed packet stats Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 06/13] net/hns3: encapsulate a port shaping interface Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 07/13] net/hns3: support PF on electrical net device Lijun Ou
2021-02-26 15:25   ` Ferruh Yigit
2021-03-01 14:17     ` oulijun
2021-03-01 14:44       ` Ferruh Yigit
2021-02-24  1:28 ` [dpdk-dev] [PATCH 08/13] net/hns3: support RXD advanced layout Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 09/13] net/hns3: fix maximum frame size update after buffer alloc Lijun Ou
2021-02-26 15:25   ` Ferruh Yigit
2021-02-27  3:56     ` oulijun
2021-03-03 13:27   ` Ferruh Yigit
2021-02-24  1:28 ` [dpdk-dev] [PATCH 10/13] net/hns3: remove unused parameter from func declaration Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 11/13] net/hns3: fix memory leakage for mbuf Lijun Ou
2021-02-24  1:28 ` [dpdk-dev] [PATCH 12/13] net/hns3: add process for MAC interrupt Lijun Ou
2021-02-26 15:26   ` Ferruh Yigit
2021-02-27  9:24     ` oulijun
2021-02-24  1:28 ` [dpdk-dev] [PATCH 13/13] net/hns3: fix imprecise statistics Lijun Ou
2021-03-02 13:58 ` [dpdk-dev] [PATCH V2 00/14] Features and bugfixes for hns3 Lijun Ou
2021-03-02 13:58   ` Lijun Ou [this message]
2021-03-03 13:26     ` [dpdk-dev] [PATCH V2 01/14] net/hns3: support module EEPROM dump Ferruh Yigit
2021-03-03 13:38       ` oulijun
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 02/14] net/hns3: add more registers to dump Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 03/14] net/hns3: implement cleanup for Tx done Lijun Ou
2021-03-03 13:27     ` Ferruh Yigit
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 04/14] net/hns3: add Rx and Tx bytes stats Lijun Ou
2021-03-03 13:28     ` Ferruh Yigit
2021-03-03 14:08       ` [dpdk-dev] [Linuxarm] " oulijun
2021-03-03 14:24         ` Ferruh Yigit
2021-03-04  1:36           ` oulijun
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 05/14] net/hns3: add imissed packet stats Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 06/14] net/hns3: encapsulate a port shaping interface Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 07/14] net/hns3: fix device capabilities for copper media type Lijun Ou
2021-03-03 13:27     ` Ferruh Yigit
2021-03-03 13:51       ` oulijun
2021-03-03 13:58         ` Ferruh Yigit
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 08/14] net/hns3: support PF device with copper phys Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 09/14] net/hns3: support RXD advanced layout Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 10/14] net/hns3: fix maximum frame size update after buffer alloc Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 11/14] net/hns3: remove unused parameter from func declaration Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 12/14] net/hns3: fix memory leakage for mbuf Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 13/14] net/hns3: add process for MAC interrupt Lijun Ou
2021-03-02 13:58   ` [dpdk-dev] [PATCH V2 14/14] net/hns3: fix imprecise statistics Lijun Ou
2021-03-04  7:44   ` [dpdk-dev] [PATCH V3 00/14] Features and bugfixes for hns3 Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 01/14] net/hns3: support module EEPROM dump Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 02/14] net/hns3: add more registers to dump Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 03/14] net/hns3: implement Tx mbuf free on demand Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 04/14] net/hns3: add Rx and Tx bytes stats Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 05/14] net/hns3: add imissed packet stats Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 06/14] net/hns3: encapsulate a port shaping interface Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 07/14] net/hns3: fix device capabilities for copper media type Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 08/14] net/hns3: support PF device with copper phys Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 09/14] net/hns3: support RXD advanced layout Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 10/14] net/hns3: fix HW buffer size on MTU update Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 11/14] net/hns3: remove unused parameter from func declaration Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 12/14] net/hns3: fix memory leakage for mbuf Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 13/14] net/hns3: add process for MAC interrupt Lijun Ou
2021-03-04  7:44     ` [dpdk-dev] [PATCH V3 14/14] net/hns3: fix imprecise statistics Lijun Ou
2021-03-04 14:10     ` [dpdk-dev] [PATCH V3 00/14] Features and bugfixes for hns3 Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1614693534-27620-2-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=linuxarm@openeuler.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).