Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96d971e

Browse files
Hoommusdavem330
authored andcommitted
ethtool: Add fallback to get_module_eeprom from netlink command
In case netlink get_module_eeprom_by_page() callback is not implemented by the driver, try to call old get_module_info() and get_module_eeprom() pair. Recalculate parameters to get_module_eeprom() offset and len using page number and their sizes. Return error if this can't be done. Signed-off-by: Vladyslav Tarasiuk <[email protected]> Signed-off-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 95dfc7e commit 96d971e

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

net/ethtool/eeprom.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,66 @@ struct eeprom_reply_data {
2525
#define MODULE_EEPROM_REPDATA(__reply_base) \
2626
container_of(__reply_base, struct eeprom_reply_data, base)
2727

28+
static int fallback_set_params(struct eeprom_req_info *request,
29+
struct ethtool_modinfo *modinfo,
30+
struct ethtool_eeprom *eeprom)
31+
{
32+
u32 offset = request->offset;
33+
u32 length = request->length;
34+
35+
if (request->page)
36+
offset = request->page * ETH_MODULE_EEPROM_PAGE_LEN + offset;
37+
38+
if (modinfo->type == ETH_MODULE_SFF_8079 &&
39+
request->i2c_address == 0x51)
40+
offset += ETH_MODULE_EEPROM_PAGE_LEN * 2;
41+
42+
if (offset >= modinfo->eeprom_len)
43+
return -EINVAL;
44+
45+
eeprom->cmd = ETHTOOL_GMODULEEEPROM;
46+
eeprom->len = length;
47+
eeprom->offset = offset;
48+
49+
return 0;
50+
}
51+
52+
static int eeprom_fallback(struct eeprom_req_info *request,
53+
struct eeprom_reply_data *reply,
54+
struct genl_info *info)
55+
{
56+
struct net_device *dev = reply->base.dev;
57+
struct ethtool_modinfo modinfo = {0};
58+
struct ethtool_eeprom eeprom = {0};
59+
u8 *data;
60+
int err;
61+
62+
modinfo.cmd = ETHTOOL_GMODULEINFO;
63+
err = ethtool_get_module_info_call(dev, &modinfo);
64+
if (err < 0)
65+
return err;
66+
67+
err = fallback_set_params(request, &modinfo, &eeprom);
68+
if (err < 0)
69+
return err;
70+
71+
data = kmalloc(eeprom.len, GFP_KERNEL);
72+
if (!data)
73+
return -ENOMEM;
74+
err = ethtool_get_module_eeprom_call(dev, &eeprom, data);
75+
if (err < 0)
76+
goto err_out;
77+
78+
reply->data = data;
79+
reply->length = eeprom.len;
80+
81+
return 0;
82+
83+
err_out:
84+
kfree(data);
85+
return err;
86+
}
87+
2888
static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
2989
struct ethnl_reply_data *reply_base,
3090
struct genl_info *info)
@@ -36,7 +96,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,
3696
int ret;
3797

3898
if (!dev->ethtool_ops->get_module_eeprom_by_page)
39-
return -EOPNOTSUPP;
99+
return eeprom_fallback(request, reply, info);
40100

41101
page_data.offset = request->offset;
42102
page_data.length = request->length;

0 commit comments

Comments
 (0)