Skip to content

Commit

Permalink
Merge branch 'ethtool-eeprom'
Browse files Browse the repository at this point in the history
Ido Schimmel says:

====================
ethtool: Module EEPROM API improvements

This patchset contains various improvements to recently introduced
module EEPROM netlink API. Noticed these while adding module EEPROM
write support.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jun 22, 2021
2 parents 98534fc + 88f9a87 commit a4bdf76
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
8 changes: 5 additions & 3 deletions Documentation/networking/ethtool-netlink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1363,8 +1363,8 @@ in an implementation specific way.
``ETHTOOL_A_FEC_AUTO`` requests the driver to choose FEC mode based on SFP
module parameters. This does not mean autonegotiation.

MODULE_EEPROM
=============
MODULE_EEPROM_GET
=================

Fetch module EEPROM data dump.
This interface is designed to allow dumps of at most 1/2 page at once. This
Expand All @@ -1383,12 +1383,14 @@ Request contents:
``ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS`` u8 page I2C address
======================================= ====== ==========================

If ``ETHTOOL_A_MODULE_EEPROM_BANK`` is not specified, bank 0 is assumed.

Kernel response contents:

+---------------------------------------------+--------+---------------------+
| ``ETHTOOL_A_MODULE_EEPROM_HEADER`` | nested | reply header |
+---------------------------------------------+--------+---------------------+
| ``ETHTOOL_A_MODULE_EEPROM_DATA`` | nested | array of bytes from |
| ``ETHTOOL_A_MODULE_EEPROM_DATA`` | binary | array of bytes from |
| | | module EEPROM |
+---------------------------------------------+--------+---------------------+

Expand Down
12 changes: 6 additions & 6 deletions include/linux/ethtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ struct ethtool_rmon_stats {
* required information to the driver.
*/
struct ethtool_module_eeprom {
__u32 offset;
__u32 length;
__u8 page;
__u8 bank;
__u8 i2c_address;
__u8 *data;
u32 offset;
u32 length;
u8 page;
u8 bank;
u8 i2c_address;
u8 *data;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion include/uapi/linux/ethtool_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ enum {
ETHTOOL_A_MODULE_EEPROM_PAGE, /* u8 */
ETHTOOL_A_MODULE_EEPROM_BANK, /* u8 */
ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS, /* u8 */
ETHTOOL_A_MODULE_EEPROM_DATA, /* nested */
ETHTOOL_A_MODULE_EEPROM_DATA, /* binary */

__ETHTOOL_A_MODULE_EEPROM_CNT,
ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_CNT - 1)
Expand Down
13 changes: 4 additions & 9 deletions net/ethtool/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
request->offset = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_OFFSET]);
request->length = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_LENGTH]);

if (!request->length)
return -EINVAL;

/* The following set of conditions limit the API to only dump 1/2
* EEPROM page without crossing low page boundary located at offset 128.
* This means user may only request dumps of length limited to 128 from
Expand All @@ -180,10 +177,6 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
"reading cross half page boundary is illegal");
return -EINVAL;
} else if (request->offset >= ETH_MODULE_EEPROM_PAGE_LEN * 2) {
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_OFFSET],
"offset is out of bounds");
return -EINVAL;
} else if (request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN * 2) {
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
"reading cross page boundary is illegal");
Expand Down Expand Up @@ -236,8 +229,10 @@ const struct ethnl_request_ops ethnl_module_eeprom_request_ops = {

const struct nla_policy ethnl_module_eeprom_get_policy[] = {
[ETHTOOL_A_MODULE_EEPROM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
[ETHTOOL_A_MODULE_EEPROM_OFFSET] = { .type = NLA_U32 },
[ETHTOOL_A_MODULE_EEPROM_LENGTH] = { .type = NLA_U32 },
[ETHTOOL_A_MODULE_EEPROM_OFFSET] =
NLA_POLICY_MAX(NLA_U32, ETH_MODULE_EEPROM_PAGE_LEN * 2 - 1),
[ETHTOOL_A_MODULE_EEPROM_LENGTH] =
NLA_POLICY_RANGE(NLA_U32, 1, ETH_MODULE_EEPROM_PAGE_LEN),
[ETHTOOL_A_MODULE_EEPROM_PAGE] = { .type = NLA_U8 },
[ETHTOOL_A_MODULE_EEPROM_BANK] = { .type = NLA_U8 },
[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS] =
Expand Down
2 changes: 1 addition & 1 deletion net/ethtool/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_T
extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];
extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1];
extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1];
extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_DATA + 1];
extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS + 1];
extern const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_GROUPS + 1];

int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info);
Expand Down

0 comments on commit a4bdf76

Please sign in to comment.