ethtool: Extend module EEPROM dump API
Subsystems (7)
v5 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 half page boundary, which size is currently limited to 128 bytes.
As for drivers that support legacy get_module_info() and get_module_eeprom() pair, the series addresses it by implementing a fallback mechanism. As mentioned earlier, such 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:
v4 ->v5:
- Limited KAPI to only read 1/2 page at once.
- Redefined ETH_MODULE_EEPROM_PAGE_LEN as 128.
- Made page number mandatory for any request.
- Added extack messages for invalid parameters failures.
v3 -> v4:
- Renamed many identifiers to use 'eeprom' instead of 'eeprom_data'.
- Renamed netlink enums and defines to use 'MODULE_EEPROM' instead of 'EEPROM_DATA'.
- Renamed struct ethtool_eeprom_data to ethtool_module_eeprom.
- Added MODULE_EEPROM_MAX_OFFSET (257 * 256) macro and check global offset against it to avoid overflow.
- Removed ndo pointer check from _parse_request().
- Removed separate length element from netlink response.
- Limited reads to 128 bytes without crossing half page bound.
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_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 | 36 ++- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 44 ++++ .../net/ethernet/mellanox/mlx5/core/port.c | 101 +++++--- include/linux/ethtool.h | 33 ++- include/linux/mlx5/port.h | 12 + include/uapi/linux/ethtool_netlink.h | 19 ++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 234 ++++++++++++++++++ net/ethtool/netlink.c | 10 + net/ethtool/netlink.h | 2 + 10 files changed, 461 insertions(+), 32 deletions(-) create mode 100644 net/ethtool/eeprom.c
Signature · 1 line
2.18.2
RFC PATCH v5 1/5 ethtool: Allow network drivers to dump arbitrary EEPROM data
From: Vladyslav Tarasiuk <[email protected]>
Define get_module_eeprom_by_page() ethtool callback and implement netlink infrastructure.
get_module_eeprom_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 | 36 +++- include/linux/ethtool.h | 33 +++- include/uapi/linux/ethtool_netlink.h | 19 +++ net/ethtool/Makefile | 2 +- net/ethtool/eeprom.c | 170 +++++++++++++++++++ net/ethtool/netlink.c | 10 ++ net/ethtool/netlink.h | 2 + 7 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/eeprom.c
Documentation/networking/ethtool-netlink.rst +34 -2
@@ -1280,6 +1280,38 @@ 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. +MODULE_EEPROM +=========== + +Fetch module EEPROM data dump. +This interface is designed to allow dumps of at most 1/2 page at once. This +means only dumps of 128 (or less) bytes are allowed, without crossing half page +boundary located at offset 128. For pages other than 0 only high 128 bytes are +accessible. + +Request contents: + + ======================================= ====== ========================== + ``ETHTOOL_A_MODULE_EEPROM_HEADER`` nested request header + ``ETHTOOL_A_MODULE_EEPROM_OFFSET`` u32 offset within a page + ``ETHTOOL_A_MODULE_EEPROM_LENGTH`` u32 amount of bytes to read + ``ETHTOOL_A_MODULE_EEPROM_PAGE`` u8 page number + ``ETHTOOL_A_MODULE_EEPROM_BANK`` u8 bank number + ``ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS`` u8 page I2C address + ======================================= ====== ========================== + +Kernel response contents: + + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_MODULE_EEPROM_HEADER`` | nested | reply header | + +---------------------------------------------+--------+---------------------+ + | ``ETHTOOL_A_MODULE_EEPROM_DATA`` | nested | array of bytes from | + | | | module EEPROM | + +---------------------------------------------+--------+---------------------+ + +``ETHTOOL_A_MODULE_EEPROM_DATA`` has an attribute length equal to the amount of +bytes driver actually read. + Request translation ===================
@@ -1357,8 +1389,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 +32 -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);
@@ -265,6 +266,31 @@ struct ethtool_pause_stats {u64 rx_pause_frames; }; +#define ETH_MODULE_EEPROM_PAGE_LEN 128 +#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f + +/** +* 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_module_eeprom { +__u32 offset; +__u32 length; +__u8 page; +__u8 bank; +__u8 i2c_address; +__u8 *data; +}; +/** * struct ethtool_ops - optional netdev operations * @cap_link_lanes_supported: indicates if the driver supports lanes
@@ -410,6 +436,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_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 +544,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_by_page)(struct net_device *dev, +const struct ethtool_module_eeprom *page, +struct netlink_ext_ack *extack); };int ethtool_check_ops (const struct ethtool_ops *ops);
@@ -538,7 +570,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_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_MODULE_EEPROM_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_MODULE_EEPROM_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 */ + +enum { +ETHTOOL_A_MODULE_EEPROM_UNSPEC , +ETHTOOL_A_MODULE_EEPROM_HEADER ,/* nest - _A_HEADER_* */ + +ETHTOOL_A_MODULE_EEPROM_OFFSET ,/* u32 */ +ETHTOOL_A_MODULE_EEPROM_LENGTH ,/* u32 */ +ETHTOOL_A_MODULE_EEPROM_PAGE ,/* u8 */ +ETHTOOL_A_MODULE_EEPROM_BANK ,/* u8 */ +ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS ,/* u8 */ +ETHTOOL_A_MODULE_EEPROM_DATA ,/* nested */ + + __ETHTOOL_A_MODULE_EEPROM_CNT, +ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_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 +170 -0
170 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_MODULE_EEPROM_GET] = ðnl_module_eeprom_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_MODULE_EEPROM_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_module_eeprom_get_policy, + .maxattr = ARRAY_SIZE(ethnl_module_eeprom_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_module_eeprom_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_module_eeprom_get_policy[ETHTOOL_A_MODULE_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.18.2
RFC PATCH v5 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.18.2
RFC PATCH v5 3/5 net/mlx5: Implement get_module_eeprom_by_page()
In reply to Moshe ShemeshFrom: Vladyslav Tarasiuk <[email protected]>
Implement ethtool_ops::get_module_eeprom_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_by_page (struct net_device *netdev, +const struct ethtool_module_eeprom *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_by_page (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_by_page 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_by_page = mlx5e_get_module_eeprom_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_by_page (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_by_page); +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_by_page (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.18.2
RFC PATCH v5 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_by_page(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.18.2
RFC PATCH v5 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_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 | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
net/ethtool/eeprom.c +65 -1
@@ -25,6 +25,70 @@ struct eeprom_reply_data {#define MODULE_EEPROM_REPDATA (__reply_base) \ container_of(__reply_base, struct eeprom_reply_data, base) +static int fallback_set_params (struct eeprom_req_info *request, +struct ethtool_modinfo *modinfo, +struct ethtool_eeprom *eeprom) +{ +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) + offset = request->page *ETH_MODULE_EEPROM_PAGE_LEN + offset; + +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 ) + offset +=ETH_MODULE_EEPROM_PAGE_LEN ; + +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_fallback (struct eeprom_req_info *request, +struct eeprom_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_prepare_data (const struct ethnl_req_info *req_base,struct ethnl_reply_data *reply_base,struct genl_info *info)
@@ -36,7 +100,7 @@ static int eeprom_prepare_data(const struct ethnl_req_info *req_base,int ret;if (!dev->ethtool_ops->get_module_eeprom_by_page) -return -EOPNOTSUPP ; +return eeprom_fallback (request, reply, info); page_data.offset = request->offset; page_data.length = request->length;
Signature · 1 line
2.18.2
RE: [RFC PATCH V5 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command
Quoted 20 lines
From: Vladyslav Tarasiuk <[email protected]>
In case netlink
get_module_eeprom_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 | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)net/ethtool/eeprom.c index renamed from net/ethtool/eeprom.c +0
-0
10d5f6b34f2f..9f773b778bbe100644net/ethtool/eeprom.c +0
-0@@ -25,6 +25,70 @@ struct eeprom_reply_data { #defineMODULE_EEPROM_REPDATA (__reply_base) \container_of (__reply_base,struct eeprom_reply_data , base)
net/ethtool/eeprom.c struct eeprom_reply_data { #define · line 36
Quoted 10 lines
net/ethtool/eeprom.c +8
-0+static int fallback_set_params (struct eeprom_req_info *request, +struct ethtool_modinfo *modinfo, +struct ethtool_eeprom *eeprom) { +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) + offset = request->page *ETH_MODULE_EEPROM_PAGE_LEN + offset;
The test 'if (request->page)' is not necessary, the math works with page 0 as well. Keep it if you like the style.
net/ethtool/eeprom.c struct eeprom_reply_data { · line 40
Quoted 4 lines
net/ethtool/eeprom.c +4
-0+ +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 ) + offset +=ETH_MODULE_EEPROM_PAGE_LEN ;
offset += ETH_MODULE_EEPROM_PAGE_LEN * 2;
Now that PAGE_LEN is 128, you need two of them to account for both low memory and high memory at 0x50.
Quoted 67 lines
net/ethtool/eeprom.c +52
-1+ +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_fallback (struct eeprom_req_info *request, +struct eeprom_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_prepare_data (const struct ethnl_req_info *req_base,struct ethnl_reply_data *reply_base,struct genl_info *info)@@ -36,7 +100,7 @@ static int eeprom_prepare_data(const structethnl_req_info *req_base, int ret;if (!dev->ethtool_ops->get_module_eeprom_by_page) -return -EOPNOTSUPP ; +return eeprom_fallback (request, reply, info); page_data.offset = request->offset;page_data.length =
request->length;
--
2.18.2
Re: [RFC PATCH V5 net-next 5/5] ethtool: Add fallback to get_module_eeprom from netlink command
Quoted 21 lines · Don Bollinger
Quoted 21 lines
From: Vladyslav Tarasiuk <[email protected]>
In case netlink
get_module_eeprom_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 | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)net/ethtool/eeprom.c index renamed from net/ethtool/eeprom.c +0
-0
10d5f6b34f2f..9f773b778bbe100644net/ethtool/eeprom.c +0
-0@@ -25,6 +25,70 @@ struct eeprom_reply_data { #defineMODULE_EEPROM_REPDATA (__reply_base) \container_of (__reply_base,struct eeprom_reply_data , base)
Quoted 11 lines
net/ethtool/eeprom.c struct eeprom_reply_data {
Quoted 9 lines
net/ethtool/eeprom.c +8
-0+static int fallback_set_params (struct eeprom_req_info *request, +struct ethtool_modinfo *modinfo, +struct ethtool_eeprom *eeprom) { +u32 offset = request->offset; +u32 length = request->length; + +if (request->page) + offset = request->page *ETH_MODULE_EEPROM_PAGE_LEN + offset;The test 'if (
request->page)' is not necessary, the math works with page 0 as well. Keep it if you like the style.
OK.
Quoted 8 lines
net/ethtool/eeprom.c struct eeprom_reply_data { · line 40
Quoted 4 lines
net/ethtool/eeprom.c +4
-0+ +if (modinfo->type ==ETH_MODULE_SFF_8079 && + request->i2c_address ==0x51 ) + offset +=ETH_MODULE_EEPROM_PAGE_LEN ;offset +=
ETH_MODULE_EEPROM_PAGE_LEN* 2;Now that
PAGE_LENis 128, you need two of them to account for both low memory and high memory at0x50.
Right, thanks.
Quoted 67 lines
Quoted 67 lines
net/ethtool/eeprom.c +52
-1+ +if (offset >= modinfo->eeprom_len) +return -EINVAL ; + + eeprom->cmd =ETHTOOL_GMODULEEEPROM ; + eeprom->len = length; + eeprom->offset = offset; + +return 0 ; +} + +static int eeprom_fallback (struct eeprom_req_info *request, +struct eeprom_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_prepare_data (const struct ethnl_req_info *req_base,struct ethnl_reply_data *reply_base,struct genl_info *info)@@ -36,7 +100,7 @@ static int eeprom_prepare_data(const structethnl_req_info *req_base, int ret;if (!dev->ethtool_ops->get_module_eeprom_by_page) -return -EOPNOTSUPP ; +return eeprom_fallback (request, reply, info); page_data.offset = request->offset;page_data.length = request->length;--
2.18.2
Andrew Lunn
maintainerQuoted 7 lines · Moshe Shemesh
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.
This is looking much better.
Do you have a version of ethtool using this new API? WIP code is O.K. I will add basic support to sfp.c and test it out on the devices i have.
Andrew
Quoted 11 lines · Andrew Lunn
External email: Use caution opening links or attachments
Quoted 7 lines · Moshe Shemesh
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.
Quoted 5 lines
This is looking much better.
Do you have a version of ethtool using this new API? WIP code is O.K. I will add basic support to
sfp.cand test it out on the devices i have.
Sure.
Quoted 1 line
Andrew