diff mbox series

[net-next,8/8] ethtool: wire in generic SFP module access

Message ID 1617955601-21055-9-git-send-email-moshe@nvidia.com (mailing list archive)
State Accepted
Commit c97a31f66ebcab54c006878142fb683c6116bed1
Delegated to: Netdev Maintainers
Headers show
Series ethtool: Extend module EEPROM dump API | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link

Commit Message

Moshe Shemesh April 9, 2021, 8:06 a.m. UTC
From: Andrew Lunn <andrew@lunn.ch>

If the device has a sfp bus attached, call its
sfp_get_module_eeprom_by_page() function, otherwise use the ethtool op
for the device. This follows how the IOCTL works.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/ethtool/eeprom.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/net/ethtool/eeprom.c b/net/ethtool/eeprom.c
index 1a49c133d401..2a6733a6449a 100644
--- a/net/ethtool/eeprom.c
+++ b/net/ethtool/eeprom.c
@@ -1,6 +1,7 @@ 
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/ethtool.h>
+#include <linux/sfp.h>
 #include "netlink.h"
 #include "common.h"
 
@@ -85,6 +86,21 @@  static int eeprom_fallback(struct eeprom_req_info *request,
 	return err;
 }
 
+static int get_module_eeprom_by_page(struct net_device *dev,
+				     struct ethtool_module_eeprom *page_data,
+				     struct netlink_ext_ack *extack)
+{
+	const struct ethtool_ops *ops = dev->ethtool_ops;
+
+	if (dev->sfp_bus)
+		return sfp_get_module_eeprom_by_page(dev->sfp_bus, page_data, extack);
+
+	if (ops->get_module_info)
+		return ops->get_module_eeprom_by_page(dev, page_data, extack);
+
+	return -EOPNOTSUPP;
+}
+
 static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
 			       struct ethnl_reply_data *reply_base,
 			       struct genl_info *info)
@@ -95,9 +111,6 @@  static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
 	struct net_device *dev = reply_base->dev;
 	int ret;
 
-	if (!dev->ethtool_ops->get_module_eeprom_by_page)
-		return eeprom_fallback(request, reply, info);
-
 	page_data.offset = request->offset;
 	page_data.length = request->length;
 	page_data.i2c_address = request->i2c_address;
@@ -111,8 +124,7 @@  static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
 	if (ret)
 		goto err_free;
 
-	ret = dev->ethtool_ops->get_module_eeprom_by_page(dev, &page_data,
-							  info->extack);
+	ret = get_module_eeprom_by_page(dev, &page_data, info->extack);
 	if (ret < 0)
 		goto err_ops;
 
@@ -126,6 +138,9 @@  static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
 	ethnl_ops_complete(dev);
 err_free:
 	kfree(page_data.data);
+
+	if (ret == -EOPNOTSUPP)
+		return eeprom_fallback(request, reply, info);
 	return ret;
 }