ethtool: Extend module EEPROM dump API
Subsystems (7)
v3 cover ethtool: Extend module EEPROM dump API
Ethtool supports module EEPROM dumps via the ethtool -m <dev> command. But in current state its functionality is limited - offset and length parameters, which are used to specify a linear desired region of EEPROM data to dump, is not enough, considering emergence of complex module EEPROM layouts such as CMIS 4.0.
Moreover, CMIS 4.0 extends the amount of pages that may be accessible by introducing another parameter for page addressing - banks.
Besides, currently module EEPROM is represented as a chunk of concatenated pages, where lower 128 bytes of all pages, except page 00h, are omitted. Offset and length are used to address parts of this fake linear memory. But in practice drivers, which implement get_module_info() and get_module_eeprom() ethtool ops still calculate page number and set I2C address on their own.
This series tackles these issues by adding ethtool op, which allows to pass page number, bank number and I2C address in addition to offset and length parameters to the driver, adds corresponding netlink infrastructure and implements the new interface in mlx5 driver.
This allows to extend userspace 'ethtool -m' CLI by adding new
parameters - page, bank and i2c. New command line format:
ethtool -m <dev> [hex on|off] [raw on|off] [offset N] [length N] [page N] [bank N] [i2c N]
The consequence of this series is a possibility to dump arbitrary EEPROM page at a time, in contrast to dumps of concatenated pages. Therefore, offset and length change their semantics and may be used only to specify a part of data within a page, which size is currently limited to 256 bytes.
As for backwards compatibility with get_module_info() and get_module_eeprom() pair, the series addresses it as well by implementing a fallback mechanism. As mentioned earlier, drivers derive a page number from 'global' offset, so this can be done vice versa without their involvement thanks to standardization. If kernel netlink handler of 'ethtool -m' command detects that new ethtool op is not supported by the driver, it calculates offset from given page number and page offset and calls old ndos, if they are available.
Change log:
v2 -> v3:
- Removed page number limitations
- Added length limit when page is present in fallback
- Changed page, bank and i2c_address type to u8 all over the patchset
- Added 0x51 I2C address usage increasing offset by 256 for SFP
v1 -> v2:
- Limited i2c_address values by 127
- Added page bound check for offset and length
- Added defines for these two points
- Added extack to ndo parameters
- Moved ethnl_ops_begin(dev) and set error path accordingly
Vladyslav Tarasiuk (5):
ethtool: Allow network drivers to dump arbitrary EEPROM data net/mlx5: Refactor module EEPROM query
net/mlx5: Implement get_module_eeprom_data_by_page() net/mlx5: Add support for DSFP module EEPROM dumps
ethtool: Add fallback to get_module_eeprom from netlink command
Documentation/networking/ethtool-netlink.rst | 34 ++- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 44 ++++ .../net/ethernet/mellanox/mlx5/core/port.c | 101 +++++--- include/linux/ethtool.h | 8 +- include/linux/mlx5/port.h | 12 + include/uapi/linux/ethtool.h | 25 ++ include/uapi/linux/ethtool_netlink.h | 19 ++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 226 ++++++++++++++++++ net/ethtool/netlink.c | 10 + net/ethtool/netlink.h | 2 + 11 files changed, 451 insertions(+), 32 deletions(-) create mode 100644 net/ethtool/eeprom.c
Signature · 1 line
2.26.2
RFC PATCH v3 1/5 ethtool: Allow network drivers to dump arbitrary EEPROM data
From: Vladyslav Tarasiuk <[email protected]>
Define get_module_eeprom_data_by_page() ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page() allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement for get_module_info() and get_module_eeprom() pair, which is needed due to emergence of complex non-linear EEPROM layouts.
--- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/eeprom.c
Documentation/networking/ethtool-netlink.rst +32 -2
@@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that the table contains static entries, hard-coded by the NIC. +EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_EEPROM_DATA_PAGE`` u8 page number + ``ETHTOOL_A_EEPROM_DATA_BANK`` u8 bank number + ``ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS`` u8 page I2C address + ===================================== ====== ========================== + +Kernel response contents: + + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA_HEADER`` | nested | reply header | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA_LENGTH`` | u32 | amount of bytes read| + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_EEPROM_DATA`` | nested | array of bytes from | + | | | module EEPROM | + +---------------------------------------------+--------+---------------------+ + +``ETHTOOL_A_EEPROM_DATA`` has an attribute length equal to the amount of bytes +driver actually read. + Request translation ===================
@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` + ``ETHTOOL_GMODULEEEPROM`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` ``ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/a
include/linux/ethtool.h +7 -1
@@ -81,6 +81,7 @@ enum {#define ETH_RSS_HASH_NO_CHANGE 0struct net_device ; +struct netlink_ext_ack ;/* Some generic methods drivers may use in their ethtool_ops */ u32 ethtool_op_get_link (struct net_device *dev);
@@ -410,6 +411,9 @@ struct ethtool_pause_stats {* @get_ethtool_phy_stats: Return extended statistics about the PHY device. * This is only useful if the device maintains PHY statistics and * cannot use the standard PHY library helpers. +* @get_module_eeprom_data_by_page: Get a region of plug-in module EEPROM data +* from specified page. Returns a negative error code or the amount of +* bytes read. * * All operations are optional (i.e. the function pointer may be set * to %NULL) and callers must take this into account. Callers must
@@ -515,6 +519,9 @@ struct ethtool_ops { const struct ethtool_tunable *, void *);int (*set_phy_tunable)(struct net_device *,const struct ethtool_tunable *,const void *); +int (*get_module_eeprom_data_by_page)(struct net_device *dev, +const struct ethtool_eeprom_data *page, +struct netlink_ext_ack *extack); };int ethtool_check_ops (const struct ethtool_ops *ops);
@@ -538,7 +545,6 @@ int ethtool_virtdev_set_link_ksettings(struct net_device *dev,const struct ethtool_link_ksettings *cmd, u32 *dev_speed, u8 *dev_duplex); -struct netlink_ext_ack ;struct phy_device ;struct phy_tdr_config ;
include/uapi/linux/ethtool.h +25 -0
@@ -340,6 +340,28 @@ struct ethtool_eeprom {__u8 data[0 ]; }; +/** +* struct ethtool_eeprom_data - EEPROM dump from specified page +* @offset: Offset within the specified EEPROM page to begin read, in bytes. +* @length: Number of bytes to read. +* @page: Page number to read from. +* @bank: Page bank number to read from, if applicable by EEPROM spec. +* @i2c_address: I2C address of a page. Value less than 0x7f expected. Most +* EEPROMs use 0x50 or 0x51. +* @data: Pointer to buffer with EEPROM data of @length size. +* +* This can be used to manage pages during EEPROM dump in ethtool and pass +* required information to the driver. +*/ +struct ethtool_eeprom_data { +__u32 offset; +__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +/** * struct ethtool_eee - Energy Efficient Ethernet information * @cmd: ETHTOOL_{G,S}EEE
@@ -1865,6 +1887,9 @@ static inline int ethtool_validate_duplex(__u8 duplex)#define ETH_MODULE_SFF_8636_MAX_LEN 640#define ETH_MODULE_SFF_8436_MAX_LEN 640 +#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f +/* Reset flags */ /* The reset() operation must clear the flags for the components which * were actually reset. On successful return, the flags indicate the
include/uapi/linux/ethtool_netlink.h +19 -0
@@ -42,6 +42,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_ACT ,ETHTOOL_MSG_CABLE_TEST_TDR_ACT ,ETHTOOL_MSG_TUNNEL_INFO_GET , +ETHTOOL_MSG_EEPROM_DATA_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -80,6 +81,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_NTF ,ETHTOOL_MSG_CABLE_TEST_TDR_NTF ,ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY , +ETHTOOL_MSG_EEPROM_DATA_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
@@ -629,6 +631,23 @@ enum { ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* MODULE EEPROM DATA */ + +enum { +ETHTOOL_A_EEPROM_DATA_UNSPEC , +ETHTOOL_A_EEPROM_DATA_HEADER ,/* nest - _A_HEADER_* */ + +ETHTOOL_A_EEPROM_DATA_OFFSET ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_LENGTH ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_PAGE ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_BANK ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ,/* u8 */ +ETHTOOL_A_EEPROM_DATA ,/* nested */ + + __ETHTOOL_A_EEPROM_DATA_CNT, +ETHTOOL_A_EEPROM_DATA_MAX = (__ETHTOOL_A_EEPROM_DATA_CNT -1 ) +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
@@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ - tunnels.o + tunnels.o eeprom.o
net/ethtool/eeprom.c new file +153 -0
153 lines not on this page · raw message
net/ethtool/netlink.c +10 -0
@@ -245,6 +245,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_EEPROM_DATA_GET] = ðnl_eeprom_data_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -912,6 +913,15 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_tunnel_info_get_policy, .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_EEPROM_DATA_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_eeprom_data_get_policy, + .maxattr = ARRAY_SIZE(ethnl_eeprom_data_get_policy) - 1, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +2 -0
@@ -344,6 +344,7 @@ extern const struct ethnl_request_ops ethnl_coalesce_request_ops;extern const struct ethnl_request_ops ethnl_pause_request_ops;extern const struct ethnl_request_ops ethnl_eee_request_ops;extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; +extern const struct ethnl_request_ops ethnl_eeprom_data_request_ops;extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS +1 ];extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS +1 ];
@@ -375,6 +376,7 @@ extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER +extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER +1 ];extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG +1 ];extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER +1 ]; +extern const struct nla_policy ethnl_eeprom_data_get_policy[ETHTOOL_A_EEPROM_DATA +1 ];int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info);int ethnl_set_linkmodes (struct sk_buff *skb,struct genl_info *info);
Signature · 1 line
2.26.2
RFC PATCH v3 2/5 net/mlx5: Refactor module EEPROM query
In reply to Moshe ShemeshFrom: Vladyslav Tarasiuk <[email protected]>
Prepare for ethtool_ops::get_module_eeprom_data() implementation by extracting common part of mlx5_query_module_eeprom() into a separate function.
--- .../net/ethernet/mellanox/mlx5/core/port.c | 79 +++++++++++-------- include/linux/mlx5/port.h | 9 +++ 2 files changed, 54 insertions(+), 34 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/port.c +45 -34
@@ -353,67 +353,78 @@ static void mlx5_sfp_eeprom_params_set(u16 *i2c_addr, int *page_num, u16 *offset *offset -=MLX5_EEPROM_PAGE_LENGTH ; } -int mlx5_query_module_eeprom (struct mlx5_core_dev *dev, -u16 offset,u16 size,u8 *data) +static int mlx5_query_mcia (struct mlx5_core_dev *dev, +struct mlx5_module_eeprom_query_params *params,u8 *data) { -int module_num, status, err, page_num =0 ;u32 in[MLX5_ST_SZ_DW (mcia_reg)] = {};u32 out[MLX5_ST_SZ_DW (mcia_reg)]; -u16 i2c_addr =0 ; -u8 module_id; +int status, err;void *ptr; +u16 size; + + size =min_t (int, params->size,MLX5_EEPROM_MAX_BYTES ); + +MLX5_SET (mcia_reg, in, l,0 ); +MLX5_SET (mcia_reg, in, size, size); +MLX5_SET (mcia_reg, in, module, params->module_number); +MLX5_SET (mcia_reg, in, device_address, params->offset); +MLX5_SET (mcia_reg, in, page_number, params->page); +MLX5_SET (mcia_reg, in, i2c_device_address, params->i2c_address); - err =mlx5_query_module_num (dev, &module_num); + err =mlx5_core_access_reg (dev, in,sizeof (in), out, +sizeof (out),MLX5_REG_MCIA ,0 ,0 );if (err)return err; - err =mlx5_query_module_id (dev, module_num, &module_id); + status =MLX5_GET (mcia_reg, out, status); +if (status) { +mlx5_core_err (dev,"query_mcia_reg failed: status: 0x%x\n" , + status); +return -EIO ; + } + + ptr =MLX5_ADDR_OF (mcia_reg, out, dword_0); +memcpy (data, ptr, size); + +return size; +} + +int mlx5_query_module_eeprom (struct mlx5_core_dev *dev, +u16 offset,u16 size,u8 *data) +{ +struct mlx5_module_eeprom_query_params query = {0 }; +u8 module_id; +int err; + + err =mlx5_query_module_num (dev, &query.module_number); +if (err) +return err; + + err =mlx5_query_module_id (dev, query.module_number, &module_id);if (err)return err;switch (module_id) {case MLX5_MODULE_ID_SFP : -mlx5_sfp_eeprom_params_set (&i2c_addr, &page_num, &offset); +mlx5_sfp_eeprom_params_set (&query.i2c_address, &query.page, &query.offset);break ;case MLX5_MODULE_ID_QSFP :case MLX5_MODULE_ID_QSFP_PLUS :case MLX5_MODULE_ID_QSFP28 : -mlx5_qsfp_eeprom_params_set (&i2c_addr, &page_num, &offset); +mlx5_qsfp_eeprom_params_set (&query.i2c_address, &query.page, &query.offset);break ;default :mlx5_core_err (dev,"Module ID not recognized: 0x%x\n" , module_id);return -EINVAL ; } -if (offset + size >MLX5_EEPROM_PAGE_LENGTH ) +if (query.offset + size >MLX5_EEPROM_PAGE_LENGTH )/* Cross pages read, read until offset 256 in low page */ size -= offset + size -MLX5_EEPROM_PAGE_LENGTH ; - size =min_t (int, size,MLX5_EEPROM_MAX_BYTES ); + query.size = size; -MLX5_SET (mcia_reg, in, l,0 ); -MLX5_SET (mcia_reg, in, module, module_num); -MLX5_SET (mcia_reg, in, i2c_device_address, i2c_addr); -MLX5_SET (mcia_reg, in, page_number, page_num); -MLX5_SET (mcia_reg, in, device_address, offset); -MLX5_SET (mcia_reg, in, size, size); - - err =mlx5_core_access_reg (dev, in,sizeof (in), out, -sizeof (out),MLX5_REG_MCIA ,0 ,0 ); -if (err) -return err; - - status =MLX5_GET (mcia_reg, out, status); -if (status) { -mlx5_core_err (dev,"query_mcia_reg failed: status: 0x%x\n" , - status); -return -EIO ; - } - - ptr =MLX5_ADDR_OF (mcia_reg, out, dword_0); -memcpy (data, ptr, size); - -return size; +return mlx5_query_mcia (dev, &query, data); }EXPORT_SYMBOL_GPL (mlx5_query_module_eeprom);
include/linux/mlx5/port.h +9 -0
@@ -62,6 +62,15 @@ enum mlx5_an_status {#define MLX5_EEPROM_PAGE_LENGTH 256#define MLX5_EEPROM_HIGH_PAGE_LENGTH 128 +struct mlx5_module_eeprom_query_params { +u16 size; +u16 offset; +u16 i2c_address; +u32 page; +u32 bank; +u32 module_number; +}; +enum mlx5e_link_mode {MLX5E_1000BASE_CX_SGMII =0 ,MLX5E_1000BASE_KX =1 ,
Signature · 1 line
2.26.2
RFC PATCH v3 3/5 net/mlx5: Implement get_module_eeprom_data_by_page()
In reply to Moshe ShemeshFrom: Vladyslav Tarasiuk <[email protected]>
Implement ethtool_ops::get_module_eeprom_data_by_page() to enable support of new SFP standards.
--- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 44 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/port.c | 33 ++++++++++++++ include/linux/mlx5/port.h | 2 + 3 files changed, 79 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +44 -0
@@ -1769,6 +1769,49 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev,return 0 ; } +static int mlx5e_get_module_eeprom_data_by_page (struct net_device *netdev, +const struct ethtool_eeprom_data *page_data, +struct netlink_ext_ack *extack) +{ +struct mlx5e_priv *priv =netdev_priv (netdev); +struct mlx5_module_eeprom_query_params query; +struct mlx5_core_dev *mdev = priv->mdev; +u8 *data = page_data->data; +int size_read; +int i =0 ; + +if (!page_data->length) +return -EINVAL ; + +memset (data,0 , page_data->length); + + query.offset = page_data->offset; + query.i2c_address = page_data->i2c_address; + query.bank = page_data->bank; + query.page = page_data->page; +while (i < page_data->length) { + query.size = page_data->length - i; + size_read =mlx5_query_module_eeprom_data (mdev, &query, data + i); + +/* Done reading, return how many bytes was read */ +if (!size_read) +return i; + +if (size_read == -EINVAL ) +return -EINVAL ; +if (size_read <0 ) { +netdev_err (priv->netdev,"%s: mlx5_query_module_eeprom_data failed:0x%x\n" , + __func__, size_read); +return i; + } + + i += size_read; + query.offset += size_read; + } + +return i; +} +int mlx5e_ethtool_flash_device (struct mlx5e_priv *priv,struct ethtool_flash *flash) {
@@ -2148,6 +2191,7 @@ const struct ethtool_ops mlx5e_ethtool_ops = { .set_wol = mlx5e_set_wol, .get_module_info = mlx5e_get_module_info, .get_module_eeprom = mlx5e_get_module_eeprom, + .get_module_eeprom_data_by_page = mlx5e_get_module_eeprom_data_by_page, .flash_device = mlx5e_flash_device, .get_priv_flags = mlx5e_get_priv_flags, .set_priv_flags = mlx5e_set_priv_flags,
drivers/net/ethernet/mellanox/mlx5/core/port.c +33 -0
@@ -428,6 +428,39 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev, }EXPORT_SYMBOL_GPL (mlx5_query_module_eeprom); +int mlx5_query_module_eeprom_data (struct mlx5_core_dev *dev, +struct mlx5_module_eeprom_query_params *params, +u8 *data) +{ +u8 module_id; +int err; + + err =mlx5_query_module_num (dev, ¶ms->module_number); +if (err) +return err; + + err =mlx5_query_module_id (dev, params->module_number, &module_id); +if (err) +return err; + +if (module_id !=MLX5_MODULE_ID_SFP && + module_id !=MLX5_MODULE_ID_QSFP && + module_id !=MLX5_MODULE_ID_QSFP28 && + module_id !=MLX5_MODULE_ID_QSFP_PLUS ) { +mlx5_core_err (dev,"Module ID not recognized: 0x%x\n" , module_id); +return -EINVAL ; + } + +if (params->i2c_address !=MLX5_I2C_ADDR_HIGH && + params->i2c_address !=MLX5_I2C_ADDR_LOW ) { +mlx5_core_err (dev,"I2C address not recognized: 0x%x\n" , params->i2c_address); +return -EINVAL ; + } + +return mlx5_query_mcia (dev, params, data); +} +EXPORT_SYMBOL_GPL (mlx5_query_module_eeprom_data); +static int mlx5_query_port_pvlc (struct mlx5_core_dev *dev,u32 *pvlc,int pvlc_size,u8 local_port) {
include/linux/mlx5/port.h +2 -0
@@ -209,6 +209,8 @@ void mlx5_query_port_fcs(struct mlx5_core_dev *mdev, bool *supported, bool *enabled);int mlx5_query_module_eeprom (struct mlx5_core_dev *dev,u16 offset,u16 size,u8 *data); +int mlx5_query_module_eeprom_data (struct mlx5_core_dev *dev, +struct mlx5_module_eeprom_query_params *params,u8 *data);int mlx5_query_port_dcbx_param (struct mlx5_core_dev *mdev,u32 *out);int mlx5_set_port_dcbx_param (struct mlx5_core_dev *mdev,u32 *in);
Signature · 1 line
2.26.2
RFC PATCH v3 4/5 net/mlx5: Add support for DSFP module EEPROM dumps
In reply to Moshe ShemeshFrom: Vladyslav Tarasiuk <[email protected]>
Allow the driver to recognise DSFP transceiver module ID and therefore allow its EEPROM dumps using ethtool.
--- drivers/net/ethernet/mellanox/mlx5/core/port.c | 3 ++- include/linux/mlx5/port.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/port.c +2 -1
@@ -446,7 +446,8 @@ int mlx5_query_module_eeprom_data(struct mlx5_core_dev *dev,if (module_id !=MLX5_MODULE_ID_SFP && module_id !=MLX5_MODULE_ID_QSFP && module_id !=MLX5_MODULE_ID_QSFP28 && - module_id !=MLX5_MODULE_ID_QSFP_PLUS ) { + module_id !=MLX5_MODULE_ID_QSFP_PLUS && + module_id !=MLX5_MODULE_ID_DSFP ) {mlx5_core_err (dev,"Module ID not recognized: 0x%x\n" , module_id);return -EINVAL ; }
include/linux/mlx5/port.h +1 -0
@@ -45,6 +45,7 @@ enum mlx5_module_id {MLX5_MODULE_ID_QSFP =0xC ,MLX5_MODULE_ID_QSFP_PLUS =0xD ,MLX5_MODULE_ID_QSFP28 =0x11 , + MLX5_MODULE_ID_DSFP = 0x1B, }; enum mlx5_an_status {
Signature · 1 line
2.26.2
RFC PATCH v3 5/5 ethtool: Add fallback to get_module_eeprom from netlink command
In reply to Moshe ShemeshFrom: Vladyslav Tarasiuk <[email protected]>
In case netlink get_module_eeprom_data_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.
--- net/ethtool/eeprom.c | 75 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-)
net/ethtool/eeprom.c +74 -1
@@ -25,6 +25,79 @@ struct eeprom_data_reply_data {#define EEPROM_DATA_REPDATA (__reply_base) \ container_of(__reply_base, struct eeprom_data_reply_data, base) +static int fallback_set_params (struct eeprom_data_req_info *request, +struct ethtool_modinfo *modinfo, +struct ethtool_eeprom *eeprom) +{ +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) { +if (offset <128 || offset + length >ETH_MODULE_EEPROM_PAGE_LEN ) +return -EINVAL ; + offset = request->page *128 + offset; + } + +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 ) + offset +=ETH_MODULE_EEPROM_PAGE_LEN ; + +if (!length) + length = modinfo->eeprom_len; + +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + +if (modinfo->eeprom_len < offset + length) + length = modinfo->eeprom_len - offset; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_data_fallback (struct eeprom_data_req_info *request, +struct eeprom_data_reply_data *reply, +struct genl_info *info) +{ +struct net_device *dev = reply->base.dev; +struct ethtool_modinfo modinfo = {0 }; +struct ethtool_eeprom eeprom = {0 }; +u8 *data; +int err; + +if ((!dev->ethtool_ops->get_module_info && + !dev->ethtool_ops->get_module_eeprom) || request->bank) { +return -EOPNOTSUPP ; + } + modinfo.cmd =ETHTOOL_GMODULEINFO ; + err = dev->ethtool_ops->get_module_info (dev, &modinfo); +if (err <0 ) +return err; + + err =fallback_set_params (request, &modinfo, &eeprom); +if (err <0 ) +return err; + + data =kmalloc (eeprom.len,GFP_KERNEL ); +if (!data) +return -ENOMEM ; + err = dev->ethtool_ops->get_module_eeprom (dev, &eeprom, data); +if (err <0 ) + goto err_out; + + reply->data = data; + reply->length = eeprom.len; + +return 0 ; + +err_out: +kfree (data); +return err; +} +static int eeprom_data_prepare_data (const struct ethnl_req_info *req_base,struct ethnl_reply_data *reply_base,struct genl_info *info)
@@ -36,7 +109,7 @@ static int eeprom_data_prepare_data(const struct ethnl_req_info *req_base,int ret;if (!dev->ethtool_ops->get_module_eeprom_data_by_page) -return -EOPNOTSUPP ; +return eeprom_data_fallback (request, reply, info); page_data.offset = request->offset; page_data.length = request->length;
Signature · 1 line
2.26.2
Jakub Kicinski
maintainerRe: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 5 lines · On Mon, 15 Mar 2021 19:12:39 +0200 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
Quoted 7 lines
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.Signed-off-by Vladyslav Tarasiuk <[email protected]>
s/eeprom_data/eeprom/ everywhere?
Otherwise some of your identifiers are over 30 characters long.
Quoted 20 lines
include/uapi/linux/ethtool.h +12
-0@@ -340,6 +340,28 @@ struct ethtool_eeprom {__u8 data[0 ]; }; +/** +* struct ethtool_eeprom_data - EEPROM dump from specified page +* @offset: Offset within the specified EEPROM page to begin read, in bytes. +* @length: Number of bytes to read. +* @page: Page number to read from. +* @bank: Page bank number to read from, if applicable by EEPROM spec. +* @i2c_address: I2C address of a page. Value less than 0x7f expected. Most +* EEPROMs use 0x50 or 0x51. +* @data: Pointer to buffer with EEPROM data of @length size. +* +* This can be used to manage pages during EEPROM dump in ethtool and pass +* required information to the driver.
include/uapi/linux/ethtool.h struct ethtool_eeprom { · line 364
Quoted 10 lines
include/uapi/linux/ethtool.h +10
-0+*/ +struct ethtool_eeprom_data { +__u32 offset; +__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +
This structure does not have to be part of uAPI, right?
include/uapi/linux/ethtool.h static inline int ethtool_validate_duplex(__u8 duplex) · line 1891
Quoted 2 lines
include/uapi/linux/ethtool.h +2
-0+#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f
Not sure about these defines either.
Quoted 11 lines
include/uapi/linux/ethtool.h +11
-0+static int eeprom_data_prepare_data (const struct ethnl_req_info *req_base, +struct ethnl_reply_data *reply_base, +struct genl_info *info) +{ +struct eeprom_data_reply_data *reply =EEPROM_DATA_REPDATA (reply_base); +struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_base); +struct ethtool_eeprom_data page_data = {0 }; +struct net_device *dev = reply_base->dev; +int ret; + +if (!dev->ethtool_ops->get_module_eeprom_data_by_page)
include/uapi/linux/ethtool.h struct ethtool_eeprom {
Quoted 10 lines
include/uapi/linux/ethtool.h +10
-0+return -EOPNOTSUPP ; + + page_data.offset = request->offset; + page_data.length = request->length; + page_data.i2c_address = request->i2c_address; + page_data.page = request->page; + page_data.bank = request->bank; + page_data.data =kmalloc (page_data.length,GFP_KERNEL ); +if (!page_data.data) +return -ENOMEM ;
nit: new line?
Quoted 26 lines
include/uapi/linux/ethtool.h +26
-0+ ret =ethnl_ops_begin (dev); +if (ret) + goto err_free; + + ret = dev->ethtool_ops->get_module_eeprom_data_by_page (dev, &page_data, + info->extack); +if (ret <0 ) + goto err_ops; + + reply->length = ret; + reply->data = page_data.data; + +ethnl_ops_complete (dev); +return 0 ; + +err_ops: +ethnl_ops_complete (dev); +err_free: +kfree (page_data.data); +return ret; +} + +static int eeprom_data_parse_request (struct ethnl_req_info *req_info,struct nlattr **tb, +struct netlink_ext_ack *extack) +{ +struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_info);
include/uapi/linux/ethtool.h
Quoted 10 lines
include/uapi/linux/ethtool.h +10
-0+struct net_device *dev = req_info->dev; + +if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET ] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH ] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ]) +return -EINVAL ; + + request->i2c_address =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ]); +if (request->i2c_address >ETH_MODULE_MAX_I2C_ADDRESS ) +return -EINVAL ;
Max value should be set in the netlink policy.
include/uapi/linux/ethtool.h
Quoted 4 lines
include/uapi/linux/ethtool.h +4
-0+ request->offset =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_OFFSET ]); + request->length =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_LENGTH ]); + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE] && + dev->ethtool_ops->get_module_eeprom_data_by_page &&
Why check dev->ethtool_ops->get_module_eeprom_data_by_page here?
Quoted 9 lines
include/uapi/linux/ethtool.h +9
-0+ request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) +return -EINVAL ; + +if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]) + request->page =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]); +if (tb[ETHTOOL_A_EEPROM_DATA_BANK ]) + request->bank =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_BANK ]); + +return 0 ;
include/uapi/linux/ethtool.h
Quoted 10 lines
include/uapi/linux/ethtool.h +10
-0+} + +static int eeprom_data_reply_size (const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base) +{ +const struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_base); + +return nla_total_size (sizeof (u32)) +/* _EEPROM_DATA_LENGTH */ +nla_total_size (sizeof (u8) * request->length);/* _EEPROM_DATA */ +}
Why report length? Is the netlink length of the DATA attribute not sufficient?
Should we echo back offset in case driver wants to report re-aligned data?
include/uapi/linux/ethtool.h
Quoted 8 lines
include/uapi/linux/ethtool.h +8
-0+const struct nla_policy ethnl_eeprom_data_get_policy[] = { + [ETHTOOL_A_EEPROM_DATA_HEADER ] =NLA_POLICY_NESTED (ethnl_header_policy), + [ETHTOOL_A_EEPROM_DATA_OFFSET ] = { .type =NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_LENGTH ] = { .type =NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_PAGE ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_BANK ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA ] = { .type =NLA_BINARY },
This is a policy for inputs, DATA should not be allowed on input, right?
RE: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 44 lines · On Mon, 15 Mar 2021 10:12:39 +0700 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.Signed-off-by Vladyslav Tarasiuk <[email protected]>--- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-) create mode 100644
net/ethtool/eeprom.cDocumentation/networking/ethtool-netlink.rst +0
-0@@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES``indicates that the table contains static entries, hard-coded by the NIC.
Documentation/networking/ethtool-netlink.rst +8
-0+EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ================================
Documentation/networking/ethtool-netlink.rst +2
-0+ ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page
Documentation/networking/ethtool-netlink.rst Kernel response contents: · line 1309
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +10
-0+ ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_EEPROM_DATA_PAGE`` u8 page number + ``ETHTOOL_A_EEPROM_DATA_BANK`` u8 bank number + ``ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS`` u8 page I2C address + ===================================== ====== + ========================== + +Kernel response contents: + +
+---------------------------------------------+--------+--------------------
-+
Quoted 3 lines
+ | ``ETHTOOL_A_EEPROM_DATA_HEADER`` | nested | reply header
|
+
+---------------------------------------------+--------+--------------------
-+
Quoted 3 lines
+ | ``ETHTOOL_A_EEPROM_DATA_LENGTH`` | u32 | amount of bytes
read|
+
+---------------------------------------------+--------+--------------------
-+
Quoted 1 line
+ | ``ETHTOOL_A_EEPROM_DATA`` | nested | array of bytes
from |
Quoted 1 line
+ | | | module EEPROM
|
Quoted 1 line
+
+---------------------------------------------+--------+--------------------
-+
Quoted 36 lines
Documentation/networking/ethtool-netlink.rst +5
-2+ +``ETHTOOL_A_EEPROM_DATA`` has an attribute length equal to the amount +of bytes driver actually read. + Request translation ===================@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO````ETHTOOL_MSG_MODULE_EEPROM_GET``
+ ``ETHTOOL_GMODULEEEPROM``
``ETHTOOL_MSG_MODULE_EEPROM_GET````ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/ainclude/linux/ethtool.h index renamed from include/linux/ethtool.h +0
-0
ec4cd3921c67..9551005b350a100644include/linux/ethtool.h +1
-0@@ -81,6 +81,7 @@ enum {#define ETH_RSS_HASH_NO_CHANGE 0struct net_device ; +struct netlink_ext_ack ;/* Some generic methods drivers may use in their ethtool_ops */ u32 ethtool_op_get_link(struct net_device *dev); @@ -410,6 +411,9 @@struct
ethtool_pause_stats{
* @get_ethtool_phy_stats: Return extended statistics about the PHY
device.
* This is only useful if the device maintains PHY statistics and
Quoted 8 lines
* cannot use the standard PHY library helpers.
+ * @get_module_eeprom_data_by_page: Get a region of plug-in module EEPROM data
+ * from specified page. Returns a negative error code or the amount of
+ * bytes read.
*
* All operations are optional (i.e. the function pointer may be set
* to %NULL) and callers must take this into account. Callers must @@
-515,6
include/linux/ethtool.h struct ethtool_ops {
Quoted 4 lines
+519,9 @@ struct
ethtool_ops{include/linux/ethtool.h +0
-0const struct ethtool_tunable *, void *); int (*set_phy_tunable)(struct net_device *, const struct ethtool_tunable *, const
void
Quoted 9 lines
*);
include/linux/ethtool.h +1
-0+ int (*get_module_eeprom_data_by_page)(struct net_device*dev,
include/linux/ethtool.h +1
-0+ const struct
ethtool_eeprom_data*page,include/linux/ethtool.h +1
-0+struct netlink_ext_ack *extack);
};
Quoted 3 lines
int
ethtool_check_ops(const struct ethtool_ops *ops); @@ -538,7 +545,6
@@ int ethtool_virtdev_set_link_ksettings(structnet_device*dev,
const structethtool_link_ksettings
*cmd,
include/uapi/linux/ethtool.h
Quoted 7 lines
include/linux/ethtool.h +0
-1u32 *dev_speed, u8 *dev_duplex); -struct netlink_ext_ack ;struct phy_device ;struct phy_tdr_config ;include/uapi/linux/ethtool.h +0
-0
index
Quoted 45 lines
cde753bb2093..b3e92db3ad37100644include/uapi/linux/ethtool.h +3
-0@@ -340,6 +340,28 @@ struct ethtool_eeprom {__u8 data[0 ]; }; +/** +* struct ethtool_eeprom_data - EEPROM dump from specified page +* @offset: Offset within the specified EEPROM page to begin read, in bytes.
+ * @length: Number of bytes to read.
+ * @page: Page number to read from.
+ * @bank: Page bank number to read from, if applicable by EEPROM spec.
+ * @i2c_address: I2C address of a page. Value less than0x7fexpected. Most
+ * EEPROMs use0x50or0x51.
+ * @data: Pointer to buffer with EEPROM data of @length size.
+ *
+ * This can be used to manage pages during EEPROM dump in ethtool andinclude/uapi/linux/ethtool.h +15
-0+pass +* required information to the driver. +*/ +struct ethtool_eeprom_data { +__u32 offset; +__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +/** * struct ethtool_eee - Energy Efficient Ethernet information * @cmd: ETHTOOL_{G,S}EEE @@ -1865,6 +1887,9 @@ static inline int ethtool_validate_duplex(__u8 duplex)#define ETH_MODULE_SFF_8636_MAX_LEN 640#define ETH_MODULE_SFF_8436_MAX_LEN 640 +#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f +/* Reset flags */ /* The reset() operation must clear the flags for the components which
Quoted 1 line
* were actually reset. On successful return, the flags indicate the
diff --git
Quoted 51 lines
a/include/uapi/linux/ethtool_netlink.hb/include/uapi/linux/ethtool_netlink.h
indexa286635ac9b8..e1b1b962f3da100644include/uapi/linux/ethtool_netlink.h +7
-0@@ -42,6 +42,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_ACT ,ETHTOOL_MSG_CABLE_TEST_TDR_ACT ,ETHTOOL_MSG_TUNNEL_INFO_GET , +ETHTOOL_MSG_EEPROM_DATA_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,@@ -80,6 +81,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_NTF ,ETHTOOL_MSG_CABLE_TEST_TDR_NTF ,ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY , +ETHTOOL_MSG_EEPROM_DATA_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,@@ -629,6 +631,23 @@ enum {ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* MODULE EEPROM DATA */ + +enum { +ETHTOOL_A_EEPROM_DATA_UNSPEC , +ETHTOOL_A_EEPROM_DATA_HEADER ,/* nest - _A_HEADER_* */
include/uapi/linux/ethtool_netlink.h +10
-0+ +ETHTOOL_A_EEPROM_DATA_OFFSET ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_LENGTH ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_PAGE ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_BANK ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ,/* u8 */ +ETHTOOL_A_EEPROM_DATA ,/* nested */ + + __ETHTOOL_A_EEPROM_DATA_CNT, + ETHTOOL_A_EEPROM_DATA_MAX =(
__ETHTOOL_A_EEPROM_DATA_CNT- 1) };include/uapi/linux/ethtool_netlink.h +1
-0+/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1net/ethtool/Makefile index renamed from net/ethtool/Makefile +0
-0
7a849ff22dad..d604346bc074100644
net/ethtool/Makefile obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o · line 8
Quoted 2 lines
net/ethtool/Makefile +0
-0@@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o
\
net/ethtool/Makefile obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o · line 9
Quoted 1 line
net/ethtool/Makefile +0
-0channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o
\
Quoted 63 lines
net/ethtool/Makefile +1
-1- tunnels.o + tunnels.o eeprom.onet/ethtool/eeprom.c new file mode renamed from net/ethtool/eeprom.c +0
-0100644 index 000000000000..e110336dc231
net/ethtool/eeprom.c new file +28
-0@@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/ethtool.h> +#include "netlink.h" +#include "common.h" + +struct eeprom_data_req_info { +struct ethnl_req_info base; +u32 offset; +u32 length; +u8 page; +u8 bank; +u8 i2c_address; +}; + +struct eeprom_data_reply_data { +struct ethnl_reply_data base; +u32 length; +u8 *data; +}; + +#define EEPROM_DATA_REQINFO (__req_base) \ + container_of(__req_base, struct eeprom_data_req_info, base) + +#define EEPROM_DATA_REPDATA (__reply_base) \ + container_of(__reply_base, struct eeprom_data_reply_data, base) + +static int eeprom_data_prepare_data(const struct ethnl_req_info
*req_base,net/ethtool/eeprom.c new file +4
-0+struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct eeprom_data_reply_data *reply =
EEPROM_DATA_REPDATA(reply_base);net/ethtool/eeprom.c new file +1
-0+ struct eeprom_data_req_info *request =
EEPROM_DATA_REQINFO(req_base);net/ethtool/eeprom.c new file +20
-0+struct ethtool_eeprom_data page_data = {0 }; +struct net_device *dev = reply_base->dev; +int ret; + +if (!dev->ethtool_ops->get_module_eeprom_data_by_page) +return -EOPNOTSUPP ; + + page_data.offset = request->offset; + page_data.length = request->length; + page_data.i2c_address = request->i2c_address; + page_data.page = request->page; + page_data.bank = request->bank; + page_data.data =kmalloc (page_data.length,GFP_KERNEL ); +if (!page_data.data) +return -ENOMEM ; + ret =ethnl_ops_begin (dev); +if (ret) + goto err_free; + + ret = dev->ethtool_ops->get_module_eeprom_data_by_page(dev,
Quoted 2 lines
&page_data,
+
info->extack);
Quoted 21 lines
net/ethtool/eeprom.c new file +17
-0+if (ret <0 ) + goto err_ops; + + reply->length = ret; + reply->data = page_data.data; + +ethnl_ops_complete (dev); +return 0 ; + +err_ops: +ethnl_ops_complete (dev); +err_free: +kfree (page_data.data); +return ret; +} + +static int eeprom_data_parse_request(struct ethnl_req_info *req_info,struct nlattr **tb,
net/ethtool/eeprom.c new file +2
-0+ struct netlink_ext_ack *extack) { + struct eeprom_data_req_info *request =
EEPROM_DATA_REQINFO(req_info);
net/ethtool/eeprom.c line 80
Quoted 6 lines
net/ethtool/eeprom.c new file +6
-0+struct net_device *dev = req_info->dev; + +if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET ] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH ] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ]) +return -EINVAL ;
Suggestion: Consider using i2c address 0x50 as a default if none is given. 0x50 is the first 256 bytes of SFP, and all of QSFP and CMIS EEPROM. If there is a page given on an SFP device, then you know i2c address is 0x51. The only thing that REQUIRES 0x51 is legacy offset 256-511 on SFP. Keep the i2c address, but make it optional for the non-standard devices that Andrew has mentioned, and for that one section of SFP data that requires it. And document it for the user.
Note also, legacy does not have an i2c address, so passing this along allows the fallback to legacy to cover more cases. (Legacy ethtool addresses this part of SFP as offset 256-511.)
Quoted 14 lines
net/ethtool/eeprom.c new file +2
-0+ + request->i2c_address =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]);net/ethtool/eeprom.c new file +4
-0+if (request->i2c_address >ETH_MODULE_MAX_I2C_ADDRESS ) +return -EINVAL ; + + request->offset =
nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]);net/ethtool/eeprom.c new file +1
-0+ request->length =
nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]);net/ethtool/eeprom.c new file +3
-0+if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length >
ETH_MODULE_EEPROM_PAGE_LEN)
net/ethtool/eeprom.c
Quoted 1 line
net/ethtool/eeprom.c new file +1
-0+return -EINVAL ;
If a request exceeds the length of EEPROM (in legacy), we truncate it to EEPROM length. I suggest if a request exceeds the length of the page (in the new KAPI), then we truncate at the end of the page. Thus rather than 'return -EINVAL;' I suggest
request->length = ETH_MODULE_EEPROM_PAGE_LEN - request->offset;
net/ethtool/eeprom.c line 102
Quoted 13 lines
net/ethtool/eeprom.c new file +3
-0+ +if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]) + request->page =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_PAGE]);net/ethtool/eeprom.c new file +2
-0+if (tb[ETHTOOL_A_EEPROM_DATA_BANK ]) + request->bank =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_BANK]);net/ethtool/eeprom.c new file +6
-0+ +return 0 ; +} + +static int eeprom_data_reply_size (const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base)
{
net/ethtool/eeprom.c line 112
Quoted 10 lines
net/ethtool/eeprom.c new file +10
-0+const struct eeprom_data_req_info *request = +EEPROM_DATA_REQINFO (req_base); + +return nla_total_size (sizeof (u32)) +/* _EEPROM_DATA_LENGTH */ +nla_total_size (sizeof (u8) * request->length);/* _EEPROM_DATA +*/ } + +static int eeprom_data_fill_reply (struct sk_buff *skb, +const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base)
{
Quoted 71 lines
net/ethtool/eeprom.c new file +4
-0+struct eeprom_data_reply_data *reply = +EEPROM_DATA_REPDATA (reply_base); + + if (nla_put_u32(skb, ETHTOOL_A_EEPROM_DATA_LENGTH, reply-Quoted 1 line
length) ||
net/ethtool/eeprom.c new file +1
-0+ nla_put(skb, ETHTOOL_A_EEPROM_DATA, reply->length, reply-Quoted 1 line
data))
net/ethtool/eeprom.c new file +16
-0+return -EMSGSIZE ; + +return 0 ; +} + +static void eeprom_data_cleanup_data (struct ethnl_reply_data +*reply_base) { +struct eeprom_data_reply_data *reply = +EEPROM_DATA_REPDATA (reply_base); + +kfree (reply->data); +} + +const struct ethnl_request_ops ethnl_eeprom_data_request_ops = { + .request_cmd =ETHTOOL_MSG_EEPROM_DATA_GET , + .reply_cmd =
ETHTOOL_MSG_EEPROM_DATA_GET_REPLY,net/ethtool/eeprom.c new file +13
-0+ .hdr_attr = ETHTOOL_A_EEPROM_DATA_HEADER, + .req_info_size = sizeof(struct eeprom_data_req_info), + .reply_data_size = sizeof(struct eeprom_data_reply_data), + + .parse_request = eeprom_data_parse_request, + .prepare_data = eeprom_data_prepare_data, + .reply_size = eeprom_data_reply_size, + .fill_reply = eeprom_data_fill_reply, + .cleanup_data = eeprom_data_cleanup_data, +}; + +const struct nla_policy ethnl_eeprom_data_get_policy[] = { + [ETHTOOL_A_EEPROM_DATA_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy),net/ethtool/eeprom.c new file +1
-0+ [ETHTOOL_A_EEPROM_DATA_OFFSET] = { .type =
NLA_U32},net/ethtool/eeprom.c new file +1
-0+ [ETHTOOL_A_EEPROM_DATA_LENGTH] = { .type =
NLA_U32},net/ethtool/eeprom.c new file +4
-0+ [ETHTOOL_A_EEPROM_DATA_PAGE] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_BANK] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA] = { .type =
NLA_BINARY},net/ethtool/eeprom.c new file +2
-0+}; +net/ethtool/netlink.c index renamed from net/ethtool/netlink.c +0
-0
50d3c8896f91..ff2528bee192100644net/ethtool/netlink.c +1
-0@@ -245,6 +245,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PAUSE_GET ] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_EEPROM_DATA_GET ] = ðnl_eeprom_data_request_ops,};
static struct
ethnl_dump_ctx*ethnl_dump_context(structnetlink_callback
*cb) @@ -912,6 +913,15 @@ static const structgenl_opsethtool_genl_ops[] = {net/ethtool/netlink.c +2
-0.policy = ethnl_tunnel_info_get_policy, .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_EEPROM_DATA_GET,
net/ethtool/netlink.c static const struct genl_ops ethtool_genl_ops[] = {
Quoted 10 lines
net/ethtool/netlink.c +7
-0+ .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_eeprom_data_get_policy, + .maxattr = ARRAY_SIZE(ethnl_eeprom_data_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff
--git
Quoted 28 lines
a/net/ethtool/netlink.hb/net/ethtool/netlink.hindex6eabd58d81bf..60954c7b4dfe100644net/ethtool/netlink.h +0
-0@@ -344,6 +344,7 @@ extern const struct ethnl_request_ops
ethnl_coalesce_request_ops; extern const structethnl_request_opsethnl_pause_request_ops; extern const structethnl_request_opsethnl_eee_request_ops; extern const structethnl_request_opsethnl_tsinfo_request_ops;
+extern const structethnl_request_opsethnl_eeprom_data_request_ops;extern const struct
nla_policy
ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const structnla_policyethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -375,6 +376,7 @@ extern const structnla_policyethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + extern const structnla_policyethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1]; extern const structnla_policyethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1]; extern const structnla_policyethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];net/ethtool/netlink.h +2
-0+extern const struct nla_policy +ethnl_eeprom_data_get_policy[ETHTOOL_A_EEPROM_DATA +1 ];int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info);int
ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info); --
2.26.2
RE: [RFC PATCH V3 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command
In reply to Moshe ShemeshQuoted 31 lines · On Mon, 15 Mar 2021 10:12:39 +0700 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
In case netlink
get_module_eeprom_data_by_page()callback is not implemented by the driver, try to call oldget_module_info()andget_module_eeprom()pair. Recalculate parameters toget_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]>--- net/ethtool/eeprom.c | 75 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-)net/ethtool/eeprom.c index renamed from net/ethtool/eeprom.c +0
-0
e110336dc231..33ba9ecc36cb100644net/ethtool/eeprom.c +8
-0@@ -25,6 +25,79 @@ struct eeprom_data_reply_data { #defineEEPROM_DATA_REPDATA (__reply_base) \container_of (__reply_base ,struct eeprom_data_reply_data ,base ) +static int fallback_set_params(struct eeprom_data_req_info *request, + struct ethtool_modinfo *modinfo, + struct ethtool_eeprom *eeprom) { +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) { +if (offset <128 || offset + length >ETH_MODULE_EEPROM_PAGE_LEN )
net/ethtool/eeprom.c struct eeprom_data_reply_data { #define · line 46
Quoted 10 lines
net/ethtool/eeprom.c +10
-0+return -EINVAL ; + offset = request->page *128 + offset; + } + +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 ) + offset +=ETH_MODULE_EEPROM_PAGE_LEN ; + +if (!length) + length = modinfo->eeprom_len;
Need to move this check up 11 lines, before the 'if (request->page)...' stanza. You need to be doing that check against the final length. Otherwise you could have a request that includes a page, and a length of 0, which becomes a length of modinfo->eeprom_len.
Quoted 71 lines
net/ethtool/eeprom.c +54
-0+ +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + +if (modinfo->eeprom_len < offset + length) + length = modinfo->eeprom_len - offset; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_data_fallback (struct eeprom_data_req_info *request, +struct eeprom_data_reply_data *reply, +struct genl_info *info) +{ +struct net_device *dev = reply->base.dev; +struct ethtool_modinfo modinfo = {0 }; +struct ethtool_eeprom eeprom = {0 }; +u8 *data; +int err; + +if ((!dev->ethtool_ops->get_module_info && + !dev->ethtool_ops->get_module_eeprom) || request->bank) { +return -EOPNOTSUPP ; + } + modinfo.cmd =ETHTOOL_GMODULEINFO ; + err = dev->ethtool_ops->get_module_info (dev, &modinfo); +if (err <0 ) +return err; + + err =fallback_set_params (request, &modinfo, &eeprom); +if (err <0 ) +return err; + + data =kmalloc (eeprom.len,GFP_KERNEL ); +if (!data) +return -ENOMEM ; + err = dev->ethtool_ops->get_module_eeprom (dev, &eeprom, data); +if (err <0 ) + goto err_out; + + reply->data = data; + reply->length = eeprom.len; + +return 0 ; + +err_out: +kfree (data); +return err; +} + static int eeprom_data_prepare_data(const struct ethnl_req_info
*req_base,net/ethtool/eeprom.c +1
-1struct ethnl_reply_data *reply_base, struct genl_info *info)@@ -36,7 +109,7 @@ static int eeprom_data_prepare_data(const structethnl_req_info *req_base, int ret;if (!dev->ethtool_ops->get_module_eeprom_data_by_page) -return -EOPNOTSUPP ; +return eeprom_data_fallback (request, reply, info); page_data.offset = request->offset;page_data.length =
request->length;
--
2.26.2
Re: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Jakub KicinskiQuoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 15 Mar 2021 19:12:39 +0200 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.
Quoted 4 lines
Quoted 1 line
Signed-off-by Vladyslav Tarasiuk <[email protected]>s/eeprom_data/eeprom/ everywhere?
Otherwise some of your identifiers are over 30 characters long.
That can work part to one struct on the uapi file that can conflict with previous old KAPI struct, but we can figure it too.
Will fix.
Quoted 23 lines
Quoted 23 lines
include/uapi/linux/ethtool.h +15
-0@@ -340,6 +340,28 @@ struct ethtool_eeprom {__u8 data[0 ]; }; +/** +* struct ethtool_eeprom_data - EEPROM dump from specified page +* @offset: Offset within the specified EEPROM page to begin read, in bytes. +* @length: Number of bytes to read. +* @page: Page number to read from. +* @bank: Page bank number to read from, if applicable by EEPROM spec. +* @i2c_address: I2C address of a page. Value less than 0x7f expected. Most +* EEPROMs use 0x50 or 0x51. +* @data: Pointer to buffer with EEPROM data of @length size. +* +* This can be used to manage pages during EEPROM dump in ethtool and pass +* required information to the driver. +*/ +struct ethtool_eeprom_data { +__u32 offset;
Quoted 8 lines
include/uapi/linux/ethtool.h struct ethtool_eeprom { · line 364
Quoted 7 lines
include/uapi/linux/ethtool.h +7
-0+__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +This structure does not have to be part of uAPI, right?
Right, will fix.
Quoted 3 lines
include/uapi/linux/ethtool.h static inline int ethtool_validate_duplex(__u8 duplex) · line 1891
Quoted 2 lines
include/uapi/linux/ethtool.h +2
-0+#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7fNot sure about these defines either.
Probably.
Quoted 14 lines
Quoted 14 lines
include/uapi/linux/ethtool.h +14
-0+static int eeprom_data_prepare_data (const struct ethnl_req_info *req_base, +struct ethnl_reply_data *reply_base, +struct genl_info *info) +{ +struct eeprom_data_reply_data *reply =EEPROM_DATA_REPDATA (reply_base); +struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_base); +struct ethtool_eeprom_data page_data = {0 }; +struct net_device *dev = reply_base->dev; +int ret; + +if (!dev->ethtool_ops->get_module_eeprom_data_by_page) +return -EOPNOTSUPP ; + + page_data.offset = request->offset;
Quoted 8 lines
include/uapi/linux/ethtool.h
Quoted 7 lines
include/uapi/linux/ethtool.h +7
-0+ page_data.length = request->length; + page_data.i2c_address = request->i2c_address; + page_data.page = request->page; + page_data.bank = request->bank; + page_data.data =kmalloc (page_data.length,GFP_KERNEL ); +if (!page_data.data) +return -ENOMEM ;nit: new line?
Ack.
Quoted 29 lines
Quoted 29 lines
include/uapi/linux/ethtool.h +29
-0+ ret =ethnl_ops_begin (dev); +if (ret) + goto err_free; + + ret = dev->ethtool_ops->get_module_eeprom_data_by_page (dev, &page_data, + info->extack); +if (ret <0 ) + goto err_ops; + + reply->length = ret; + reply->data = page_data.data; + +ethnl_ops_complete (dev); +return 0 ; + +err_ops: +ethnl_ops_complete (dev); +err_free: +kfree (page_data.data); +return ret; +} + +static int eeprom_data_parse_request (struct ethnl_req_info *req_info,struct nlattr **tb, +struct netlink_ext_ack *extack) +{ +struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_info); +struct net_device *dev = req_info->dev; + + if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET] ||
Quoted 8 lines
include/uapi/linux/ethtool.h
Quoted 7 lines
include/uapi/linux/ethtool.h +7
-0+ !tb[ETHTOOL_A_EEPROM_DATA_LENGTH ] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]) + return -EINVAL; + + request->i2c_address =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ]); +if (request->i2c_address >ETH_MODULE_MAX_I2C_ADDRESS ) +return -EINVAL ;Max value should be set in the netlink policy.
Ack
Quoted 5 lines
include/uapi/linux/ethtool.h
Quoted 4 lines
include/uapi/linux/ethtool.h +4
-0+ request->offset =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_OFFSET ]); + request->length =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_LENGTH ]); + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE] && + dev->ethtool_ops->get_module_eeprom_data_by_page &&Why check
dev->ethtool_ops->get_module_eeprom_data_by_pagehere?
Right, actually not needed here, thanks.
Quoted 13 lines
Quoted 13 lines
include/uapi/linux/ethtool.h +13
-0+ request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) + return -EINVAL; + +if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]) + request->page =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]); +if (tb[ETHTOOL_A_EEPROM_DATA_BANK ]) + request->bank =nla_get_u8 (tb[ETHTOOL_A_EEPROM_DATA_BANK ]); + +return 0 ; +} + +static int eeprom_data_reply_size (const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base)
Quoted 8 lines
include/uapi/linux/ethtool.h
Quoted 6 lines
include/uapi/linux/ethtool.h +6
-0+{ +const struct eeprom_data_req_info *request =EEPROM_DATA_REQINFO (req_base); + +return nla_total_size (sizeof (u32)) +/* _EEPROM_DATA_LENGTH */ +nla_total_size (sizeof (u8) * request->length);/* _EEPROM_DATA */ +}Why report length? Is the netlink length of the DATA attribute not sufficient?
Right, thanks.
Quoted 2 lines
Should we echo back offset in case driver wants to report re-aligned data?
The driver knows the requested offset and data has to be from that offset.
Quoted 9 lines
include/uapi/linux/ethtool.h
Quoted 8 lines
include/uapi/linux/ethtool.h +8
-0+const struct nla_policy ethnl_eeprom_data_get_policy[] = { + [ETHTOOL_A_EEPROM_DATA_HEADER ] =NLA_POLICY_NESTED (ethnl_header_policy), + [ETHTOOL_A_EEPROM_DATA_OFFSET ] = { .type =NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_LENGTH ] = { .type =NLA_U32 }, + [ETHTOOL_A_EEPROM_DATA_PAGE ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_BANK ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ] = { .type =NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA ] = { .type =NLA_BINARY },This is a policy for inputs, DATA should not be allowed on input, right?
Right, thanks.
Re: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Don BollingerQuoted 340 lines · Don Bollinger
Quoted 44 lines · On Mon, 15 Mar 2021 10:12:39 +0700 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.Signed-off-by Vladyslav Tarasiuk <[email protected]>--- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-) create mode 100644
net/ethtool/eeprom.cDocumentation/networking/ethtool-netlink.rst +0
-0@@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES``indicates that the table contains static entries, hard-coded by the NIC.
Documentation/networking/ethtool-netlink.rst +8
-0+EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ================================
Documentation/networking/ethtool-netlink.rst +2
-0+ ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a pageDocumentation/networking/ethtool-netlink.rst Kernel response contents: · line 1309
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +10
-0+ ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_EEPROM_DATA_PAGE`` u8 page number + ``ETHTOOL_A_EEPROM_DATA_BANK`` u8 bank number + ``ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS`` u8 page I2C address + ===================================== ====== + ========================== + +Kernel response contents: + ++---------------------------------------------+--------+--------------------
-+Quoted 3 lines
+ | ``ETHTOOL_A_EEPROM_DATA_HEADER`` | nested | reply header
|
++---------------------------------------------+--------+--------------------
-+Quoted 3 lines
+ | ``ETHTOOL_A_EEPROM_DATA_LENGTH`` | u32 | amount of bytes
read|
++---------------------------------------------+--------+--------------------
-+Quoted 1 line
+ | ``ETHTOOL_A_EEPROM_DATA`` | nested | array of bytes
from |
Quoted 1 line
+ | | | module EEPROM
|
Quoted 1 line
+
+---------------------------------------------+--------+--------------------
-+Quoted 36 lines
Documentation/networking/ethtool-netlink.rst +5
-2+ +``ETHTOOL_A_EEPROM_DATA`` has an attribute length equal to the amount +of bytes driver actually read. + Request translation ===================@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO````ETHTOOL_MSG_MODULE_EEPROM_GET``
+ ``ETHTOOL_GMODULEEEPROM``
``ETHTOOL_MSG_MODULE_EEPROM_GET````ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/ainclude/linux/ethtool.h index renamed from include/linux/ethtool.h +0
-0
ec4cd3921c67..9551005b350a100644include/linux/ethtool.h +1
-0@@ -81,6 +81,7 @@ enum {#define ETH_RSS_HASH_NO_CHANGE 0struct net_device ; +struct netlink_ext_ack ;/* Some generic methods drivers may use in their ethtool_ops */ u32 ethtool_op_get_link(struct net_device *dev); @@ -410,6 +411,9 @@struct
ethtool_pause_stats{
* @get_ethtool_phy_stats: Return extended statistics about the PHY
device.
* This is only useful if the device maintains PHY statistics andQuoted 8 lines
* cannot use the standard PHY library helpers.
+ * @get_module_eeprom_data_by_page: Get a region of plug-in module EEPROM data
+ * from specified page. Returns a negative error code or the amount of
+ * bytes read.
*
* All operations are optional (i.e. the function pointer may be set
* to %NULL) and callers must take this into account. Callers must @@-515,6
Quoted 4 lines
+519,9 @@ struct
ethtool_ops{
const structethtool_tunable*, void *);
int (*set_phy_tunable)(structnet_device*,
const structethtool_tunable*, constvoid
Quoted 9 lines
*);
+ int (*get_module_eeprom_data_by_page)(structnet_device
*dev,
+ const structethtool_eeprom_data*page,
+ structnetlink_ext_ack
*extack);
};Quoted 3 lines
int
ethtool_check_ops(const struct ethtool_ops *ops); @@ -538,7 +545,6
@@ int ethtool_virtdev_set_link_ksettings(structnet_device*dev,
const structethtool_link_ksettings*cmd,
include/uapi/linux/ethtool.h
Quoted 7 lines
u32 *dev_speed, u8 *dev_duplex);include/linux/ethtool.h +0
-1-struct netlink_ext_ack ;struct phy_device ;struct phy_tdr_config ;include/uapi/linux/ethtool.h +0
-0index
Quoted 45 lines
cde753bb2093..b3e92db3ad37100644include/uapi/linux/ethtool.h +3
-0@@ -340,6 +340,28 @@ struct ethtool_eeprom {__u8 data[0 ]; }; +/** +* struct ethtool_eeprom_data - EEPROM dump from specified page +* @offset: Offset within the specified EEPROM page to begin read, in bytes.
+ * @length: Number of bytes to read.
+ * @page: Page number to read from.
+ * @bank: Page bank number to read from, if applicable by EEPROM spec.
+ * @i2c_address: I2C address of a page. Value less than0x7fexpected. Most
+ * EEPROMs use0x50or0x51.
+ * @data: Pointer to buffer with EEPROM data of @length size.
+ *
+ * This can be used to manage pages during EEPROM dump in ethtool andinclude/uapi/linux/ethtool.h +15
-0+pass +* required information to the driver. +*/ +struct ethtool_eeprom_data { +__u32 offset; +__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +/** * struct ethtool_eee - Energy Efficient Ethernet information * @cmd: ETHTOOL_{G,S}EEE @@ -1865,6 +1887,9 @@ static inline int ethtool_validate_duplex(__u8 duplex)#define ETH_MODULE_SFF_8636_MAX_LEN 640#define ETH_MODULE_SFF_8436_MAX_LEN 640 +#define ETH_MODULE_EEPROM_PAGE_LEN 256 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f +/* Reset flags */ /* The reset() operation must clear the flags for the components which Quoted 1 line
* were actually reset. On successful return, the flags indicate the
diff --git
Quoted 51 lines
a/include/uapi/linux/ethtool_netlink.hb/include/uapi/linux/ethtool_netlink.h
indexa286635ac9b8..e1b1b962f3da100644include/uapi/linux/ethtool_netlink.h +7
-0@@ -42,6 +42,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_ACT ,ETHTOOL_MSG_CABLE_TEST_TDR_ACT ,ETHTOOL_MSG_TUNNEL_INFO_GET , +ETHTOOL_MSG_EEPROM_DATA_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,@@ -80,6 +81,7 @@ enum {ETHTOOL_MSG_CABLE_TEST_NTF ,ETHTOOL_MSG_CABLE_TEST_TDR_NTF ,ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY , +ETHTOOL_MSG_EEPROM_DATA_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,@@ -629,6 +631,23 @@ enum {ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* MODULE EEPROM DATA */ + +enum { +ETHTOOL_A_EEPROM_DATA_UNSPEC , +ETHTOOL_A_EEPROM_DATA_HEADER ,/* nest - _A_HEADER_* */
include/uapi/linux/ethtool_netlink.h +10
-0+ +ETHTOOL_A_EEPROM_DATA_OFFSET ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_LENGTH ,/* u32 */ +ETHTOOL_A_EEPROM_DATA_PAGE ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_BANK ,/* u8 */ +ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ,/* u8 */ +ETHTOOL_A_EEPROM_DATA ,/* nested */ + + __ETHTOOL_A_EEPROM_DATA_CNT, + ETHTOOL_A_EEPROM_DATA_MAX =(
__ETHTOOL_A_EEPROM_DATA_CNT- 1) };include/uapi/linux/ethtool_netlink.h +1
-0+/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1net/ethtool/Makefile index renamed from net/ethtool/Makefile +0
-0
7a849ff22dad..d604346bc074100644net/ethtool/Makefile obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o · line 8
Quoted 2 lines
net/ethtool/Makefile +0
-0@@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o\
net/ethtool/Makefile obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o · line 9
Quoted 1 line
net/ethtool/Makefile +0
-0channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o\
Quoted 63 lines
net/ethtool/Makefile +1
-1- tunnels.o + tunnels.o eeprom.onet/ethtool/eeprom.c new file mode renamed from net/ethtool/eeprom.c +0
-0100644 index 000000000000..e110336dc231
net/ethtool/eeprom.c new file +28
-0@@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/ethtool.h> +#include "netlink.h" +#include "common.h" + +struct eeprom_data_req_info { +struct ethnl_req_info base; +u32 offset; +u32 length; +u8 page; +u8 bank; +u8 i2c_address; +}; + +struct eeprom_data_reply_data { +struct ethnl_reply_data base; +u32 length; +u8 *data; +}; + +#define EEPROM_DATA_REQINFO (__req_base) \ + container_of(__req_base, struct eeprom_data_req_info, base) + +#define EEPROM_DATA_REPDATA (__reply_base) \ + container_of(__reply_base, struct eeprom_data_reply_data, base) + +static int eeprom_data_prepare_data(const struct ethnl_req_info
*req_base,net/ethtool/eeprom.c new file +4
-0+struct ethnl_reply_data *reply_base, + struct genl_info *info) +{ + struct eeprom_data_reply_data *reply =
EEPROM_DATA_REPDATA(reply_base);
+ structeeprom_data_req_info*request =EEPROM_DATA_REQINFO(req_base);net/ethtool/eeprom.c new file +20
-0+struct ethtool_eeprom_data page_data = {0 }; +struct net_device *dev = reply_base->dev; +int ret; + +if (!dev->ethtool_ops->get_module_eeprom_data_by_page) +return -EOPNOTSUPP ; + + page_data.offset = request->offset; + page_data.length = request->length; + page_data.i2c_address = request->i2c_address; + page_data.page = request->page; + page_data.bank = request->bank; + page_data.data =kmalloc (page_data.length,GFP_KERNEL ); +if (!page_data.data) +return -ENOMEM ; + ret =ethnl_ops_begin (dev); +if (ret) + goto err_free; + + ret = dev->ethtool_ops->get_module_eeprom_data_by_page(dev,Quoted 2 lines
&page_data,
+
info->extack);Quoted 26 lines
net/ethtool/eeprom.c new file +17
-0+if (ret <0 ) + goto err_ops; + + reply->length = ret; + reply->data = page_data.data; + +ethnl_ops_complete (dev); +return 0 ; + +err_ops: +ethnl_ops_complete (dev); +err_free: +kfree (page_data.data); +return ret; +} + +static int eeprom_data_parse_request(struct ethnl_req_info *req_info,struct nlattr **tb,
net/ethtool/eeprom.c new file +2
-0+ struct netlink_ext_ack *extack) { + struct eeprom_data_req_info *request =
EEPROM_DATA_REQINFO(req_info);net/ethtool/eeprom.c new file +5
-0+struct net_device *dev = req_info->dev; + +if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET ] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH ] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ])
Quoted 8 lines
Quoted 1 line
+ return
-EINVAL;Suggestion: Consider using i2c address
0x50as a default if none is given.0x50is the first 256 bytes of SFP, and all of QSFP and CMIS EEPROM. If there is a page given on an SFP device, then you know i2c address is0x51. The only thing that REQUIRES0x51is legacy offset 256-511 on SFP. Keep the i2c address, but make it optional for the non-standard devices that Andrew has mentioned, and for that one section of SFP data that requires it. And document it for the user.
Agree, but thought to have that i2c address default set on userspace, so here we expect it.
Quoted 24 lines
Note also, legacy does not have an i2c address, so passing this along allows the fallback to legacy to cover more cases. (Legacy ethtool addresses this part of SFP as offset 256-511.)
Quoted 13 lines
net/ethtool/eeprom.c new file +2
-0+ + request->i2c_address =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]);net/ethtool/eeprom.c new file +4
-0+if (request->i2c_address >ETH_MODULE_MAX_I2C_ADDRESS ) +return -EINVAL ; + + request->offset =
nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]);
+request->length=nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]);net/ethtool/eeprom.c new file +3
-0+if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length >Quoted 2 lines
ETH_MODULE_EEPROM_PAGE_LEN)
+ return-EINVAL;If a request exceeds the length of EEPROM (in legacy), we truncate it to EEPROM length. I suggest if a request exceeds the length of the page (in the new KAPI), then we truncate at the end of the page. Thus rather than 'return
-EINVAL;' I suggest
Quoted 1 line
request->length = ETH_MODULE_EEPROM_PAGE_LEN - request->offset;
I was not sure about that, isn't it better that once user specified page he has to be in the page boundary and let him know the command failed ?
Quoted 135 lines
net/ethtool/eeprom.c line 102
Quoted 13 lines
net/ethtool/eeprom.c new file +3
-0+ +if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ]) + request->page =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_PAGE]);net/ethtool/eeprom.c new file +2
-0+if (tb[ETHTOOL_A_EEPROM_DATA_BANK ]) + request->bank =
nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_BANK]);net/ethtool/eeprom.c new file +6
-0+ +return 0 ; +} + +static int eeprom_data_reply_size (const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base){
net/ethtool/eeprom.c line 112
Quoted 10 lines
net/ethtool/eeprom.c new file +10
-0+const struct eeprom_data_req_info *request = +EEPROM_DATA_REQINFO (req_base); + +return nla_total_size (sizeof (u32)) +/* _EEPROM_DATA_LENGTH */ +nla_total_size (sizeof (u8) * request->length);/* _EEPROM_DATA +*/ } + +static int eeprom_data_fill_reply (struct sk_buff *skb, +const struct ethnl_req_info *req_base, +const struct ethnl_reply_data *reply_base){
Quoted 71 lines
net/ethtool/eeprom.c new file +4
-0+struct eeprom_data_reply_data *reply = +EEPROM_DATA_REPDATA (reply_base); + + if (nla_put_u32(skb, ETHTOOL_A_EEPROM_DATA_LENGTH, reply-Quoted 1 line
length) ||
+ nla_put(skb,
ETHTOOL_A_EEPROM_DATA,reply->length, reply-Quoted 1 line
data))
net/ethtool/eeprom.c new file +16
-0+return -EMSGSIZE ; + +return 0 ; +} + +static void eeprom_data_cleanup_data (struct ethnl_reply_data +*reply_base) { +struct eeprom_data_reply_data *reply = +EEPROM_DATA_REPDATA (reply_base); + +kfree (reply->data); +} + +const struct ethnl_request_ops ethnl_eeprom_data_request_ops = { + .request_cmd =ETHTOOL_MSG_EEPROM_DATA_GET , + .reply_cmd =
ETHTOOL_MSG_EEPROM_DATA_GET_REPLY,net/ethtool/eeprom.c new file +13
-0+ .hdr_attr = ETHTOOL_A_EEPROM_DATA_HEADER, + .req_info_size = sizeof(struct eeprom_data_req_info), + .reply_data_size = sizeof(struct eeprom_data_reply_data), + + .parse_request = eeprom_data_parse_request, + .prepare_data = eeprom_data_prepare_data, + .reply_size = eeprom_data_reply_size, + .fill_reply = eeprom_data_fill_reply, + .cleanup_data = eeprom_data_cleanup_data, +}; + +const struct nla_policy ethnl_eeprom_data_get_policy[] = { + [ETHTOOL_A_EEPROM_DATA_HEADER] =
NLA_POLICY_NESTED(ethnl_header_policy),
+ [ETHTOOL_A_EEPROM_DATA_OFFSET] = { .type =NLA_U32},
+ [ETHTOOL_A_EEPROM_DATA_LENGTH] = { .type =NLA_U32},net/ethtool/eeprom.c new file +4
-0+ [ETHTOOL_A_EEPROM_DATA_PAGE] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_BANK] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS] = { .type = NLA_U8 }, + [ETHTOOL_A_EEPROM_DATA] = { .type =
NLA_BINARY},net/ethtool/eeprom.c new file +2
-0+}; +net/ethtool/netlink.c index renamed from net/ethtool/netlink.c +0
-0
50d3c8896f91..ff2528bee192100644net/ethtool/netlink.c +1
-0@@ -245,6 +245,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PAUSE_GET ] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, + [ETHTOOL_MSG_EEPROM_DATA_GET ] = ðnl_eeprom_data_request_ops,};static struct
ethnl_dump_ctx*ethnl_dump_context(structnetlink_callback
*cb) @@ -912,6 +913,15 @@ static const structgenl_opsethtool_genl_ops[] = {
.policy =ethnl_tunnel_info_get_policy, .maxattr =ARRAY_SIZE(ethnl_tunnel_info_get_policy)- 1,
},net/ethtool/netlink.c +2
-0+ { + .cmd = ETHTOOL_MSG_EEPROM_DATA_GET,net/ethtool/netlink.c static const struct genl_ops ethtool_genl_ops[] = {
Quoted 10 lines
net/ethtool/netlink.c +7
-0+ .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_eeprom_data_get_policy, + .maxattr = ARRAY_SIZE(ethnl_eeprom_data_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff--git
Quoted 28 lines
a/net/ethtool/netlink.hb/net/ethtool/netlink.hindex6eabd58d81bf..60954c7b4dfe100644net/ethtool/netlink.h +0
-0@@ -344,6 +344,7 @@ extern const struct ethnl_request_ops
ethnl_coalesce_request_ops; extern const structethnl_request_opsethnl_pause_request_ops; extern const structethnl_request_opsethnl_eee_request_ops; extern const structethnl_request_opsethnl_tsinfo_request_ops;
+extern const structethnl_request_opsethnl_eeprom_data_request_ops;extern const struct
nla_policy
ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1]; extern const structnla_policyethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1]; @@ -375,6 +376,7 @@ extern const structnla_policyethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + extern const structnla_policyethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1]; extern const structnla_policyethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1]; extern const structnla_policyethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];net/ethtool/netlink.h +2
-0+extern const struct nla_policy +ethnl_eeprom_data_get_policy[ETHTOOL_A_EEPROM_DATA +1 ];int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info);int
ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info); --
2.26.2
Re: [RFC PATCH V3 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command
In reply to Don BollingerQuoted 39 lines · Don Bollinger
Quoted 37 lines · On Mon, 15 Mar 2021 10:12:39 +0700 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
In case netlink
get_module_eeprom_data_by_page()callback is not implemented by the driver, try to call oldget_module_info()andget_module_eeprom()pair. Recalculate parameters toget_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]>--- net/ethtool/eeprom.c | 75 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-)net/ethtool/eeprom.c index renamed from net/ethtool/eeprom.c +0
-0
e110336dc231..33ba9ecc36cb100644net/ethtool/eeprom.c +14
-0@@ -25,6 +25,79 @@ struct eeprom_data_reply_data { #defineEEPROM_DATA_REPDATA (__reply_base) \container_of (__reply_base ,struct eeprom_data_reply_data ,base ) +static int fallback_set_params(struct eeprom_data_req_info *request, + struct ethtool_modinfo *modinfo, + struct ethtool_eeprom *eeprom) { +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) { +if (offset <128 || offset + length >ETH_MODULE_EEPROM_PAGE_LEN ) +return -EINVAL ; + offset = request->page *128 + offset; + } + +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 )
Quoted 8 lines
net/ethtool/eeprom.c struct eeprom_data_reply_data { · line 46
Quoted 4 lines
net/ethtool/eeprom.c +4
-0+ offset +=ETH_MODULE_EEPROM_PAGE_LEN ; + +if (!length) + length = modinfo->eeprom_len;Need to move this check up 11 lines, before the 'if (
request->page)...' stanza. You need to be doing that check against the final length. Otherwise you could have a request that includes a page, and a length of 0, which becomes a length ofmodinfo->eeprom_len.
Right, thanks.
Quoted 71 lines
Quoted 71 lines
net/ethtool/eeprom.c +54
-0+ +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + +if (modinfo->eeprom_len < offset + length) + length = modinfo->eeprom_len - offset; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_data_fallback (struct eeprom_data_req_info *request, +struct eeprom_data_reply_data *reply, +struct genl_info *info) +{ +struct net_device *dev = reply->base.dev; +struct ethtool_modinfo modinfo = {0 }; +struct ethtool_eeprom eeprom = {0 }; +u8 *data; +int err; + +if ((!dev->ethtool_ops->get_module_info && + !dev->ethtool_ops->get_module_eeprom) || request->bank) { +return -EOPNOTSUPP ; + } + modinfo.cmd =ETHTOOL_GMODULEINFO ; + err = dev->ethtool_ops->get_module_info (dev, &modinfo); +if (err <0 ) +return err; + + err =fallback_set_params (request, &modinfo, &eeprom); +if (err <0 ) +return err; + + data =kmalloc (eeprom.len,GFP_KERNEL ); +if (!data) +return -ENOMEM ; + err = dev->ethtool_ops->get_module_eeprom (dev, &eeprom, data); +if (err <0 ) + goto err_out; + + reply->data = data; + reply->length = eeprom.len; + +return 0 ; + +err_out: +kfree (data); +return err; +} + static int eeprom_data_prepare_data(const struct ethnl_req_info
*req_base,
structethnl_reply_data*reply_base, structgenl_info*info)net/ethtool/eeprom.c +1
-1@@ -36,7 +109,7 @@ static int eeprom_data_prepare_data(const structethnl_req_info *req_base, int ret;if (!dev->ethtool_ops->get_module_eeprom_data_by_page) -return -EOPNOTSUPP ; +return eeprom_data_fallback (request, reply, info); page_data.offset = request->offset;page_data.length = request->length;--
2.26.2
RE: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 7 lines · Moshe Shemesh
Quoted 6 lines · Don Bollinger
Quoted 5 lines · On Mon, 15 Mar 2021 10:12:39 +0700 Moshe Shemesh wrote:
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
<snip>
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
+
request->offset=nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]);
+request->length=nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]);net/ethtool/eeprom.c new file +3
-0+if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length >
ETH_MODULE_EEPROM_PAGE_LEN)
+ return-EINVAL;If a request exceeds the length of EEPROM (in legacy), we truncate it to EEPROM length. I suggest if a request exceeds the length of the page (in the new KAPI), then we truncate at the end of the page. Thus rather than 'return
-EINVAL;' I suggest
Quoted 5 lines
Quoted 2 lines
request->length = ETH_MODULE_EEPROM_PAGE_LEN -
request->offset;I was not sure about that, isn't it better that once user specified page he has to be in the page boundary and let him know the command failed ?
On further review, I agree with your original code. Reading across a page boundary will require explicit tracking of offset and page to read from. If you get a short read, you *might* have to update the page on the next read. If you have to keep track of where the page boundary is and adjust the offset and page together, then you should be explicitly managing not to try to read across a page boundary. Put another way, if you try to read across a page boundary you probably have a bug in your code and will appreciate an immediate error.
I withdraw my previous suggestion, don't change it.
Don
Andrew Lunn
maintainerRe: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 33 lines · Moshe Shemesh
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.Signed-off-by Vladyslav Tarasiuk <[email protected]>--- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/eeprom.cDocumentation/networking/ethtool-netlink.rst +1
-0@@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that the table contains static entries, hard-coded by the NIC. +EEPROM_DATA
Documentation/networking/ethtool-netlink.rst Kernel response contents: · line 1293
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +10
-0+=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to read
I wonder if offset and length should be u8. At most, we should only be returning a 1/2 page, so 128 bytes. We don't need a u32.
Quoted 4 lines
Documentation/networking/ethtool-netlink.rst +0
-0Request translation ===================
Documentation/networking/ethtool-netlink.rst are netlink only. · line 1394
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +2
-2@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` + ``ETHTOOL_GMODULEEEPROM`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` ``ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/a
We should check with Michal about this. It is not a direct replacement of the old IOCTL API, it is new API. He may want it documented differently.
Quoted 12 lines
Documentation/networking/ethtool-netlink.rst +12
-0+static int eeprom_data_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + struct eeprom_data_req_info *request = EEPROM_DATA_REQINFO(req_info); + struct net_device *dev = req_info->dev; + + if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]) + return -EINVAL; + + request->i2c_address = nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]);
Documentation/networking/ethtool-netlink.rst
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +9
-0+ if (request->i2c_address > ETH_MODULE_MAX_I2C_ADDRESS) + return -EINVAL; + + request->offset = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]); + request->length = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]); + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) + return -EINVAL;
You need to watch out for overflows here. 0xfffffff0 + 0x20 is less than ETH_MODULE_EEPROM_PAGE_LEN when it wraps around, but will cause bad things to happen.
Andrew
Re: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
Quoted 34 lines · Andrew Lunn
Quoted 32 lines · Moshe Shemesh
From: Vladyslav Tarasiuk <[email protected]>
Define
get_module_eeprom_data_by_page()ethtool callback and implement netlink infrastructure.
get_module_eeprom_data_by_page()allows network drivers to dump a part of module's EEPROM specified by page and bank numbers along with offset and length. It is effectively a netlink replacement forget_module_info()andget_module_eeprom()pair, which is needed due to emergence of complex non-linear EEPROM layouts.Signed-off-by Vladyslav Tarasiuk <[email protected]>--- Documentation/networking/ethtool-netlink.rst | 34 ++++- include/linux/ethtool.h | 8 +- include/uapi/linux/ethtool.h | 25 +++ include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 153 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 8 files changed, 249 insertions(+), 4 deletions(-)create mode 100644
net/ethtool/eeprom.cDocumentation/networking/ethtool-netlink.rst +0
-0@@ -1280,6 +1280,36 @@ Kernel response contents: For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that the table contains static entries, hard-coded by the NIC.
Quoted 13 lines
Documentation/networking/ethtool-netlink.rst Kernel response contents: · line 1293
Quoted 11 lines
Documentation/networking/ethtool-netlink.rst +11
-0+EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to readI wonder if offset and length should be u8. At most, we should only be returning a 1/2 page, so 128 bytes. We don't need a u32.
That's right when page is given, but user may have commands that used to work on the ioctl KAPI with offset higher than one page.
Quoted 17 lines
Quoted 4 lines
Documentation/networking/ethtool-netlink.rst +0
-0Request translation ===================Documentation/networking/ethtool-netlink.rst are netlink only. · line 1394
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +2
-2@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` + ``ETHTOOL_GMODULEEEPROM`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` ``ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/aWe should check with Michal about this. It is not a direct replacement of the old IOCTL API, it is new API. He may want it documented differently.
Michal, please comment on where it should be.
Quoted 16 lines
Quoted 16 lines
Documentation/networking/ethtool-netlink.rst +16
-0+static int eeprom_data_parse_request(struct ethnl_req_info *req_info, struct nlattr **tb, + struct netlink_ext_ack *extack) +{ + struct eeprom_data_req_info *request = EEPROM_DATA_REQINFO(req_info); + struct net_device *dev = req_info->dev; + + if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]) + return -EINVAL; + + request->i2c_address = nla_get_u8(tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS]); + if (request->i2c_address > ETH_MODULE_MAX_I2C_ADDRESS) + return -EINVAL; + + request->offset = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_OFFSET]);
Quoted 8 lines
Documentation/networking/ethtool-netlink.rst
Quoted 5 lines
Documentation/networking/ethtool-netlink.rst +5
-0+ request->length = nla_get_u32(tb[ETHTOOL_A_EEPROM_DATA_LENGTH]); + if (tb[ETHTOOL_A_EEPROM_DATA_PAGE] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN) + return -EINVAL;You need to watch out for overflows here.
0xfffffff0+0x20is less thanETH_MODULE_EEPROM_PAGE_LENwhen it wraps around, but will cause bad things to happen.
Ack.
Quoted 1 line
Andrew
Re: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Andrew LunnQuoted 16 lines · Andrew Lunn
Documentation/networking/ethtool-netlink.rst Kernel response contents: · line 1293
Quoted 12 lines · Moshe Shemesh
Documentation/networking/ethtool-netlink.rst +11
-0+EEPROM_DATA +=========== + +Fetch module EEPROM data dump. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to readI wonder if offset and length should be u8. At most, we should only be returning a 1/2 page, so 128 bytes. We don't need a u32.
There is no actual gain using NLA_U8 due to padding. Out of the interfaces used here, kernel-userspace API is the least flexible so I would generally prefer NLA_U32, except for bools or enumerated values where it's absolutely obvious the number of possible values cannot grow too much. In this case, I can't really say it's impossible we could have devices with bigger pages in something like 20 years.
Quoted 18 lines
Quoted 4 lines
Request translation
===================Documentation/networking/ethtool-netlink.rst are netlink only. · line 1394
Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +2
-2@@ -1357,8 +1387,8 @@ are netlink only. ``ETHTOOL_GET_DUMP_FLAG`` n/a ``ETHTOOL_GET_DUMP_DATA`` n/a ``ETHTOOL_GET_TS_INFO`` ``ETHTOOL_MSG_TSINFO_GET`` - ``ETHTOOL_GMODULEINFO`` n/a - ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GMODULEINFO`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` + ``ETHTOOL_GMODULEEEPROM`` ``ETHTOOL_MSG_MODULE_EEPROM_GET`` ``ETHTOOL_GEEE`` ``ETHTOOL_MSG_EEE_GET`` ``ETHTOOL_SEEE`` ``ETHTOOL_MSG_EEE_SET`` ``ETHTOOL_GRSSH`` n/aWe should check with Michal about this. It is not a direct replacement of the old IOCTL API, it is new API. He may want it documented differently.
This table is meant to give a hint in the sense "for what you used ioctl command in left column, use now netlink request in the right". So IMHO it's appropriate. Perhaps it would deserve a comment explaining this.
Quoted 10 lines
net/ethtool/eeprom.c line 91
Quoted 6 lines
net/ethtool/eeprom.c new file +6
-0+ request->offset =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_OFFSET ]); + request->length =nla_get_u32 (tb[ETHTOOL_A_EEPROM_DATA_LENGTH ]); +if (tb[ETHTOOL_A_EEPROM_DATA_PAGE ] && + dev->ethtool_ops->get_module_eeprom_data_by_page && + request->offset + request->length >ETH_MODULE_EEPROM_PAGE_LEN ) +return -EINVAL ;You need to watch out for overflows here.
0xfffffff0+0x20is less thanETH_MODULE_EEPROM_PAGE_LENwhen it wraps around, but will cause bad things to happen.
BtW, the ioctl code also suffers from this problem and we recently had a report from customer (IIRC the effect was ethtool trying to allocate ~4GB of memory), upstream fix should follow soon.
Michal
Andrew Lunn
maintainerRe: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 10 lines
Quoted 8 lines
Documentation/networking/ethtool-netlink.rst Kernel response contents: · line 1293
Quoted 6 lines
Documentation/networking/ethtool-netlink.rst +6
-0+Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_EEPROM_DATA_HEADER`` nested request header + ``ETHTOOL_A_EEPROM_DATA_OFFSET`` u32 offset within a page + ``ETHTOOL_A_EEPROM_DATA_LENGTH`` u32 amount of bytes to readI wonder if offset and length should be u8. At most, we should only be returning a 1/2 page, so 128 bytes. We don't need a u32.
Quoted 2 lines
That's right when page is given, but user may have commands that used to work on the ioctl KAPI with offset higher than one page.
CMIS section 5.4.1 says:
The slave maintains an internal current byte address counter containing the byte address accessed during the latest read or write operation incremented by one with roll-over as follows: The current byte address counter rolls-over after a read or write operation at the last byte address of the current 128-byte memory page (127 or
255) to the first byte address (0 or 128) of the same 128-byte memory page.
This wrapping is somewhat unexpected. If the user access is for a read starting at 120 and a length of 20, they get bytes 120-127 followed by 0-11. The user is more likely to be expecting 120-139.
We have two ways to address this:
1) We limit reads to a maximum of a 1/2 page, and the start and end point needs to be within that 1/2 page.
2) We detect that the read is going to go across a 1/2 page boarder, and perform two reads to the MAC driver, and glue the data back together again in the ethtool core.
What i don't want is to leave the individual drivers to solve this, because i expect some of them will get it wrong.
Andrew
Andrew Lunn
maintainerRe: [RFC PATCH V3 net-next 1/5] ethtool: Allow network drivers to dump arbitrary EEPROM data
In reply to Moshe ShemeshQuoted 18 lines
Quoted 10 lines
Quoted 10 lines
+static int eeprom_data_parse_request(struct
ethnl_req_info*req_info, struct nlattr **tb,(quoted diff) +2
-0+ struct netlink_ext_ack *extack) { + struct eeprom_data_req_info *request =
EEPROM_DATA_REQINFO(req_info);net/ethtool/eeprom.c new file +5
-0+struct net_device *dev = req_info->dev; + +if (!tb[ETHTOOL_A_EEPROM_DATA_OFFSET ] || + !tb[ETHTOOL_A_EEPROM_DATA_LENGTH ] || + !tb[ETHTOOL_A_EEPROM_DATA_I2C_ADDRESS ])Quoted 8 lines
Quoted 1 line
+ return
-EINVAL;Suggestion: Consider using i2c address
0x50as a default if none is given.0x50is the first 256 bytes of SFP, and all of QSFP and CMIS EEPROM. If there is a page given on an SFP device, then you know i2c address is0x51. The only thing that REQUIRES0x51is legacy offset 256-511 on SFP. Keep the i2c address, but make it optional for the non-standard devices that Andrew has mentioned, and for that one section of SFP data that requires it. And document it for the user.
Quoted 2 lines
Agree, but thought to have that i2c address default set on userspace, so here we expect it.
I would make it mandatory. If you default it to 0x50, the current message structure has no way of including this information in the reply. So user space gets some data, but it has no idea from where?
Andrew