[net-next,PatchV2] octeontx2-pf: Add support to read eeprom information

Message ID 20240222171542.12995-1-hkelam@marvell.com
State New
Headers
Series [net-next,PatchV2] octeontx2-pf: Add support to read eeprom information |

Commit Message

Hariprasad Kelam Feb. 22, 2024, 5:15 p.m. UTC
  Add support to read/decode EEPROM module information using ethtool.
Usage: ethtool -m <interface>

Signed-off-by: Hariprasad Kelam <hkelam@marvell.com>
Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
---
V2 * consider length and offset fields while copying
     the eeprom data.

 .../marvell/octeontx2/nic/otx2_ethtool.c      | 37 +++++++++++++++++++
 1 file changed, 37 insertions(+)

--
2.17.1
  

Comments

Jakub Kicinski Feb. 27, 2024, 1 a.m. UTC | #1
On Thu, 22 Feb 2024 22:45:42 +0530 Hariprasad Kelam wrote:
> +	if (!ee->len || ((ee->len + ee->offset) > SFP_EEPROM_SIZE))
> +		return -EINVAL;

Are you sure there's a path thru the core to the driver which would
allow len == 0 or the size being larger than when info put in
eeprom_len?
  
Hariprasad Kelam Feb. 27, 2024, 7:36 a.m. UTC | #2
> On Thu, 22 Feb 2024 22:45:42 +0530 Hariprasad Kelam wrote:
> > +	if (!ee->len || ((ee->len + ee->offset) > SFP_EEPROM_SIZE))
> > +		return -EINVAL;
> 
> Are you sure there's a path thru the core to the driver which would allow len
> == 0 or the size being larger than when info put in eeprom_len?

 Seems these checks are not necessary,  will remove these checks in next version.

Thanks,
Hariprasad k
> --
> pw-bot: cr
  

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
index 7f786de61014..7f66d18e8a4e 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
@@ -1184,6 +1184,41 @@  static void otx2_get_link_mode_info(u64 link_mode_bmap,
 			      otx2_link_modes);
 }

+static int otx2_get_module_info(struct net_device *netdev,
+				struct ethtool_modinfo *modinfo)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	struct cgx_fw_data *rsp;
+
+	rsp = otx2_get_fwdata(pfvf);
+	if (IS_ERR(rsp))
+		return PTR_ERR(rsp);
+
+	modinfo->type = rsp->fwdata.sfp_eeprom.sff_id;
+	modinfo->eeprom_len = SFP_EEPROM_SIZE;
+	return 0;
+}
+
+static int otx2_get_module_eeprom(struct net_device *netdev,
+				  struct ethtool_eeprom *ee,
+				  u8 *data)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	struct cgx_fw_data *rsp;
+
+	if (!ee->len || ((ee->len + ee->offset) > SFP_EEPROM_SIZE))
+		return -EINVAL;
+
+	memset(data, 0, ee->len);
+
+	rsp = otx2_get_fwdata(pfvf);
+	if (IS_ERR(rsp))
+		return PTR_ERR(rsp);
+
+	memcpy(data, &rsp->fwdata.sfp_eeprom.buf + ee->offset, ee->len);
+	return 0;
+}
+
 static int otx2_get_link_ksettings(struct net_device *netdev,
 				   struct ethtool_link_ksettings *cmd)
 {
@@ -1342,6 +1377,8 @@  static const struct ethtool_ops otx2_ethtool_ops = {
 	.set_fecparam		= otx2_set_fecparam,
 	.get_link_ksettings     = otx2_get_link_ksettings,
 	.set_link_ksettings     = otx2_set_link_ksettings,
+	.get_module_info	= otx2_get_module_info,
+	.get_module_eeprom	= otx2_get_module_eeprom,
 };

 void otx2_set_ethtool_ops(struct net_device *netdev)