[v1] net/axgbe: support sfp module EEPROM

Message ID 20200514134302.29118-1-asomalap@amd.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series [v1] net/axgbe: support sfp module EEPROM |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/travis-robot warning Travis build: failed
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues

Commit Message

AMARANATH SOMALAPURAM May 14, 2020, 1:43 p.m. UTC
  From: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>

Adding API for get_module_eeprom and get_module_info.

Signed-off-by: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
---
 doc/guides/nics/features/axgbe.ini |   1 +
 drivers/net/axgbe/axgbe_ethdev.c   |   2 +
 drivers/net/axgbe/axgbe_phy.h      |   4 ++
 drivers/net/axgbe/axgbe_phy_impl.c | 107 +++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
  

Comments

Ferruh Yigit May 14, 2020, 4:35 p.m. UTC | #1
On 5/14/2020 2:43 PM, asomalap@amd.com wrote:
> From: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
> 
> Adding API for get_module_eeprom and get_module_info.
>
> Signed-off-by: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>

Hi Amaranath,

I guess this is v3 of the patch, can you please use the version info and keep
the all versions in same thread (using --in-reply-to), this helps us to trace
the status or previous comments of the patch.

There are multiple change requests and comments to previous version, same seems
sent in this version, can you please addresss them first?
http://inbox.dpdk.org/dev/67d7272a-29fc-885f-ad8e-e865687e1267@intel.com/

> ---
>  doc/guides/nics/features/axgbe.ini |   1 +
>  drivers/net/axgbe/axgbe_ethdev.c   |   2 +
>  drivers/net/axgbe/axgbe_phy.h      |   4 ++
>  drivers/net/axgbe/axgbe_phy_impl.c | 107 +++++++++++++++++++++++++++++
>  4 files changed, 114 insertions(+)
> 
> diff --git a/doc/guides/nics/features/axgbe.ini b/doc/guides/nics/features/axgbe.ini
> index 0becaa097..80a3bcee1 100644
> --- a/doc/guides/nics/features/axgbe.ini
> +++ b/doc/guides/nics/features/axgbe.ini
> @@ -18,3 +18,4 @@ Basic stats          = Y
>  Linux UIO            = Y
>  x86-32               = Y
>  x86-64               = Y
> +Module EEPROM dump   = Y

Can you please add the items with same order as 'default.ini'
  

Patch

diff --git a/doc/guides/nics/features/axgbe.ini b/doc/guides/nics/features/axgbe.ini
index 0becaa097..80a3bcee1 100644
--- a/doc/guides/nics/features/axgbe.ini
+++ b/doc/guides/nics/features/axgbe.ini
@@ -18,3 +18,4 @@  Basic stats          = Y
 Linux UIO            = Y
 x86-32               = Y
 x86-64               = Y
+Module EEPROM dump   = Y
diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 867058845..ea2f9bba1 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -214,6 +214,8 @@  static const struct eth_dev_ops axgbe_eth_dev_ops = {
 	.dev_supported_ptypes_get     = axgbe_dev_supported_ptypes_get,
 	.rx_descriptor_status         = axgbe_dev_rx_descriptor_status,
 	.tx_descriptor_status         = axgbe_dev_tx_descriptor_status,
+	.get_module_info              = axgbe_get_module_info,
+	.get_module_eeprom            = axgbe_get_module_eeprom,
 };
 
 static int axgbe_phy_reset(struct axgbe_port *pdata)
diff --git a/drivers/net/axgbe/axgbe_phy.h b/drivers/net/axgbe/axgbe_phy.h
index 77ee20a31..d9d7fde41 100644
--- a/drivers/net/axgbe/axgbe_phy.h
+++ b/drivers/net/axgbe/axgbe_phy.h
@@ -188,5 +188,9 @@ 
 #define DUPLEX_FULL             0x01
 #define DUPLEX_UNKNOWN          0xff
 
+int axgbe_get_module_info(struct rte_eth_dev *dev,
+				struct rte_eth_dev_module_info *modinfo);
+int axgbe_get_module_eeprom(struct rte_eth_dev *dev,
+				  struct rte_dev_eeprom_info *info);
 #endif
 /* PHY */
diff --git a/drivers/net/axgbe/axgbe_phy_impl.c b/drivers/net/axgbe/axgbe_phy_impl.c
index 02236ec19..53716071f 100644
--- a/drivers/net/axgbe/axgbe_phy_impl.c
+++ b/drivers/net/axgbe/axgbe_phy_impl.c
@@ -141,12 +141,18 @@  enum axgbe_sfp_speed {
 
 #define AXGBE_SFP_EXTD_CC			31
 
+#define AXGBE_SFP_EEPROM_PAGE_SIZE		256
+
 struct axgbe_sfp_eeprom {
 	u8 base[64];
 	u8 extd[32];
 	u8 vendor[32];
 };
 
+struct axgbe_sfp_eeprom_module {
+	u8 base[256];
+};
+
 #define AXGBE_BEL_FUSE_VENDOR	"BEL-FUSE"
 #define AXGBE_BEL_FUSE_PARTNO	"1GBT-SFP06"
 
@@ -734,6 +740,106 @@  static int axgbe_phy_sfp_read_eeprom(struct axgbe_port *pdata)
 	return ret;
 }
 
+int axgbe_get_module_info(struct rte_eth_dev *dev,
+				struct rte_eth_dev_module_info *modinfo)
+{
+	struct axgbe_port *pdata = dev->data->dev_private;
+	struct axgbe_sfp_eeprom sfp_eeprom;
+	uint8_t eeprom_addr;
+	int ret;
+
+	ret = axgbe_phy_get_comm_ownership(pdata);
+
+	if (ret)
+		return -EIO;
+
+	ret = axgbe_phy_sfp_get_mux(pdata);
+
+	if (ret) {
+		PMD_DRV_LOG(ERR, "I2C error setting SFP MUX\n");
+		return ret;
+	}
+
+	eeprom_addr = 0;
+	ret = axgbe_phy_i2c_read(pdata, AXGBE_SFP_SERIAL_ID_ADDRESS,
+			&eeprom_addr, sizeof(eeprom_addr),
+			 &sfp_eeprom, sizeof(sfp_eeprom));
+
+	if (ret) {
+		PMD_DRV_LOG(ERR, "I2C error reading SFP EEPROM\n");
+		goto put;
+	}
+
+	if (sfp_eeprom.extd[AXGBE_SFP_EXTD_SFF_8472] != 0xff) {
+		if (sfp_eeprom.extd[AXGBE_SFP_EXTD_SFF_8472] == 0) {
+			modinfo->type = RTE_ETH_MODULE_SFF_8079;
+			modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
+		} else {
+			modinfo->type = RTE_ETH_MODULE_SFF_8472;
+			modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
+		}
+	}
+
+
+put:
+	axgbe_phy_sfp_put_mux(pdata);
+	axgbe_phy_put_comm_ownership(pdata);
+	return 0;
+}
+
+int axgbe_get_module_eeprom(struct rte_eth_dev *dev,
+				struct rte_dev_eeprom_info *info)
+{
+	struct axgbe_port *pdata = dev->data->dev_private;
+	struct axgbe_sfp_eeprom_module sfp_eeprom;
+	uint8_t eeprom_addr;
+	uint8_t *data;
+	uint32_t i;
+	int ret;
+
+	ret = axgbe_phy_get_comm_ownership(pdata);
+
+	if (ret)
+		return -EIO;
+
+	if (!info || !info->length || !info->data)
+		return -EINVAL;
+
+	ret = axgbe_phy_sfp_get_mux(pdata);
+	if (ret) {
+		PMD_DRV_LOG(ERR, "I2C error setting SFP MUX\n");
+		return ret;
+	}
+
+	eeprom_addr = 0;
+	ret = axgbe_phy_i2c_read(pdata, AXGBE_SFP_SERIAL_ID_ADDRESS,
+			&eeprom_addr, sizeof(eeprom_addr),
+			&sfp_eeprom, sizeof(sfp_eeprom));
+	if (ret) {
+		PMD_DRV_LOG(ERR, "I2C error reading SFP EEPROM\n");
+		goto put;
+	}
+	data = info->data;
+
+	/* for AXGBE_SFP_SERIAL_ID_ADDRESS */
+	for (i = 0; i < AXGBE_SFP_EEPROM_PAGE_SIZE; i++)
+		data[i] = sfp_eeprom.base[i];
+
+	eeprom_addr = 0;
+	ret = axgbe_phy_i2c_read(pdata, AXGBE_SFP_DIAG_INFO_ADDRESS,
+			&eeprom_addr, sizeof(eeprom_addr),
+			&sfp_eeprom, sizeof(sfp_eeprom));
+
+	/* for AXGBE_SFP_DIAG_INFO_ADDRESS */
+	for (i = 0; i < info->length - AXGBE_SFP_EEPROM_PAGE_SIZE; i++)
+		data[i + AXGBE_SFP_EEPROM_PAGE_SIZE] = sfp_eeprom.base[i];
+
+put:
+	axgbe_phy_sfp_put_mux(pdata);
+	axgbe_phy_put_comm_ownership(pdata);
+	return 0;
+}
+
 static void axgbe_phy_sfp_signals(struct axgbe_port *pdata)
 {
 	struct axgbe_phy_data *phy_data = pdata->phy_data;
@@ -741,6 +847,7 @@  static void axgbe_phy_sfp_signals(struct axgbe_port *pdata)
 	u8 gpio_reg, gpio_ports[2];
 	int ret;
 
+
 	/* Read the input port registers */
 	gpio_reg = 0;
 	ret = axgbe_phy_i2c_read(pdata, phy_data->sfp_gpio_address,