All of lore.kernel.org
 help / color / mirror / Atom feed
From: Moshe Shemesh <moshe@nvidia.com>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Adrian Pop <pop.adrian61@gmail.com>,
	"Michal Kubecek" <mkubecek@suse.cz>
Cc: <netdev@vger.kernel.org>, Vladyslav Tarasiuk <vladyslavt@nvidia.com>
Subject: [PATCH net-next 8/8] ethtool: wire in generic SFP module access
Date: Fri, 9 Apr 2021 11:06:41 +0300	[thread overview]
Message-ID: <1617955601-21055-9-git-send-email-moshe@nvidia.com> (raw)
In-Reply-To: <1617955601-21055-1-git-send-email-moshe@nvidia.com>

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 --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;
 }
 
-- 
2.26.2


  parent reply	other threads:[~2021-04-09  8:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09  8:06 [PATCH net-next 0/8] ethtool: Extend module EEPROM dump API Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 1/8] ethtool: Allow network drivers to dump arbitrary EEPROM data Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 2/8] net/mlx5: Refactor module EEPROM query Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 3/8] net/mlx5: Implement get_module_eeprom_by_page() Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 4/8] net/mlx5: Add support for DSFP module EEPROM dumps Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 5/8] net: ethtool: Export helpers for getting EEPROM info Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 6/8] ethtool: Add fallback to get_module_eeprom from netlink command Moshe Shemesh
2021-04-09  8:06 ` [PATCH net-next 7/8] phy: sfp: add netlink SFP support to generic SFP code Moshe Shemesh
2021-04-09  8:06 ` Moshe Shemesh [this message]
2021-04-12  0:10 ` [PATCH net-next 0/8] ethtool: Extend module EEPROM dump API patchwork-bot+netdevbpf

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=1617955601-21055-9-git-send-email-moshe@nvidia.com \
    --to=moshe@nvidia.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=pop.adrian61@gmail.com \
    --cc=vladyslavt@nvidia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.