Skip to content

Commit c97a31f

Browse files
lunndavem330
authored andcommitted
ethtool: wire in generic SFP module access
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d740513 commit c97a31f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

net/ethtool/eeprom.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

33
#include <linux/ethtool.h>
4+
#include <linux/sfp.h>
45
#include "netlink.h"
56
#include "common.h"
67

@@ -85,6 +86,21 @@ static int eeprom_fallback(struct eeprom_req_info *request,
8586
return err;
8687
}
8788

89+
static int get_module_eeprom_by_page(struct net_device *dev,
90+
struct ethtool_module_eeprom *page_data,
91+
struct netlink_ext_ack *extack)
92+
{
93+
const struct ethtool_ops *ops = dev->ethtool_ops;
94+
95+
if (dev->sfp_bus)
96+
return sfp_get_module_eeprom_by_page(dev->sfp_bus, page_data, extack);
97+
98+
if (ops->get_module_info)
99+
return ops->get_module_eeprom_by_page(dev, page_data, extack);
100+
101+
return -EOPNOTSUPP;
102+
}
103+
88104
static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
89105
struct ethnl_reply_data *reply_base,
90106
struct genl_info *info)
@@ -95,9 +111,6 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
95111
struct net_device *dev = reply_base->dev;
96112
int ret;
97113

98-
if (!dev->ethtool_ops->get_module_eeprom_by_page)
99-
return eeprom_fallback(request, reply, info);
100-
101114
page_data.offset = request->offset;
102115
page_data.length = request->length;
103116
page_data.i2c_address = request->i2c_address;
@@ -111,8 +124,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
111124
if (ret)
112125
goto err_free;
113126

114-
ret = dev->ethtool_ops->get_module_eeprom_by_page(dev, &page_data,
115-
info->extack);
127+
ret = get_module_eeprom_by_page(dev, &page_data, info->extack);
116128
if (ret < 0)
117129
goto err_ops;
118130

@@ -126,6 +138,9 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
126138
ethnl_ops_complete(dev);
127139
err_free:
128140
kfree(page_data.data);
141+
142+
if (ret == -EOPNOTSUPP)
143+
return eeprom_fallback(request, reply, info);
129144
return ret;
130145
}
131146

0 commit comments

Comments
 (0)