From 5135a27fee4a5fcbcc064c2566adda48b4bc4b24 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 30 Jul 2025 02:29:28 +0000 Subject: [PATCH] backport some patches from upstream --- ...8472-transceiver-module-identificati.patch | 41 +++++ ...eat-zero-arguments-like-any-other-ar.patch | 149 ++++++++++++++++++ ...default-branch-to-sff8636_show_all_i.patch | 43 +++++ ...ing-of-Page-A2h-netlink-read-failure.patch | 32 ++++ ...ling-of-Page-03h-netlink-read-failur.patch | 61 +++++++ ethtool.spec | 17 +- 6 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 backport-ethtool-Fix-SFF-8472-transceiver-module-identificati.patch create mode 100644 backport-module-eeprom-treat-zero-arguments-like-any-other-ar.patch create mode 100644 backport-net-ethtool-Add-default-branch-to-sff8636_show_all_i.patch create mode 100644 backport-qsf-Better-handling-of-Page-A2h-netlink-read-failure.patch create mode 100644 backport-qsfp-Better-handling-of-Page-03h-netlink-read-failur.patch diff --git a/backport-ethtool-Fix-SFF-8472-transceiver-module-identificati.patch b/backport-ethtool-Fix-SFF-8472-transceiver-module-identificati.patch new file mode 100644 index 0000000..0927d0c --- /dev/null +++ b/backport-ethtool-Fix-SFF-8472-transceiver-module-identificati.patch @@ -0,0 +1,41 @@ +From 1a1dcfca4d670dbe01374ceb4e7c9c71ae75e15c Mon Sep 17 00:00:00 2001 +From: Ido Schimmel +Date: Wed, 29 Nov 2023 17:06:12 +0200 +Subject: ethtool: Fix SFF-8472 transceiver module identification + +According to table 5-1 in SFF-8472 Rev. 12.4, the Identifier Values for +"GBIC" (01h) and "Module soldered to motherboard (ex: SFF)" (02h) are +supported by the specification in addition to the current one. +Therefore, adjust ethtool to invoke the SFF-8079 parser for them, which +will in turn invoke the SFF-8472 parser if the transceiver module +supports digital diagnostic monitoring. + +Without this patch, the EEPROM contents of such transceiver modules will +be hex dumped instead of being parsed and printed in a human readable +format. + +Fixes: 25b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)") +Reported-by: Ivar Simensen +Closes: https://lore.kernel.org/netdev/AM0PR03MB5938EE1722EF2C75112B86F5B9B9A@AM0PR03MB5938.eurprd03.prod.outlook.com/ +Tested-by: Ivar Simensen +Signed-off-by: Ido Schimmel +--- + netlink/module-eeprom.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c +index 09ad580..fe02c5a 100644 +--- a/netlink/module-eeprom.c ++++ b/netlink/module-eeprom.c +@@ -216,6 +216,8 @@ static int eeprom_parse(struct cmd_context *ctx) + + switch (request.data[0]) { + #ifdef ETHTOOL_ENABLE_PRETTY_DUMP ++ case SFF8024_ID_GBIC: ++ case SFF8024_ID_SOLDERED_MODULE: + case SFF8024_ID_SFP: + return sff8079_show_all_nl(ctx); + case SFF8024_ID_QSFP: +-- +cgit 1.2.3-korg + diff --git a/backport-module-eeprom-treat-zero-arguments-like-any-other-ar.patch b/backport-module-eeprom-treat-zero-arguments-like-any-other-ar.patch new file mode 100644 index 0000000..11f7675 --- /dev/null +++ b/backport-module-eeprom-treat-zero-arguments-like-any-other-ar.patch @@ -0,0 +1,149 @@ +From c810d56d96d87d1db1cadf899238cee2e70f0cfd Mon Sep 17 00:00:00 2001 +From: Jakub Kicinski +Date: Fri, 12 Jul 2024 11:07:06 -0700 +Subject: module-eeprom: treat zero arguments like any other arguments for hex + dump + +The code does not differentiate between user asking for page 0 and +page not being set on the CLI at all. This is problematic because +drivers don't support old type of dumping for newer module types. +For example trying to hex dump EEPROM of a QSFP-DD on mlx5 gives +us in kernel logs: + + mlx5_query_module_eeprom[...]: Module ID not recognized: 0x18 + +We can dump all the non-zero pages, and without "hex on" ethtool +also uses the page-aware API to get the information it will print. +But hex dumping page 0 is not possible. + +Instead of using zero / non-zero to figure out whether param was +set - add a bitmap of which params got set on command line. +The nl_param()'s dest option is not used by any other command, +so we're free to change the format. + +Signed-off-by: Jakub Kicinski +Reviewed-by: Ido Schimmel +--- + netlink/module-eeprom.c | 30 +++++++++++++++++++++--------- + netlink/parser.c | 11 +++++++++-- + 2 files changed, 30 insertions(+), 11 deletions(-) + +diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c +index fe02c5a..2b30d04 100644 +--- a/netlink/module-eeprom.c ++++ b/netlink/module-eeprom.c +@@ -22,6 +22,7 @@ + #define ETH_I2C_MAX_ADDRESS 0x7F + + struct cmd_params { ++ unsigned long present; + u8 dump_hex; + u8 dump_raw; + u32 offset; +@@ -31,6 +32,14 @@ struct cmd_params { + u32 i2c_address; + }; + ++enum { ++ PARAM_OFFSET = 2, ++ PARAM_LENGTH, ++ PARAM_PAGE, ++ PARAM_BANK, ++ PARAM_I2C, ++}; ++ + static const struct param_parser getmodule_params[] = { + { + .arg = "hex", +@@ -44,31 +53,31 @@ static const struct param_parser getmodule_params[] = { + .dest_offset = offsetof(struct cmd_params, dump_raw), + .min_argc = 1, + }, +- { ++ [PARAM_OFFSET] = { + .arg = "offset", + .handler = nl_parse_direct_u32, + .dest_offset = offsetof(struct cmd_params, offset), + .min_argc = 1, + }, +- { ++ [PARAM_LENGTH] = { + .arg = "length", + .handler = nl_parse_direct_u32, + .dest_offset = offsetof(struct cmd_params, length), + .min_argc = 1, + }, +- { ++ [PARAM_PAGE] = { + .arg = "page", + .handler = nl_parse_direct_u32, + .dest_offset = offsetof(struct cmd_params, page), + .min_argc = 1, + }, +- { ++ [PARAM_BANK] = { + .arg = "bank", + .handler = nl_parse_direct_u32, + .dest_offset = offsetof(struct cmd_params, bank), + .min_argc = 1, + }, +- { ++ [PARAM_I2C] = { + .arg = "i2c", + .handler = nl_parse_direct_u32, + .dest_offset = offsetof(struct cmd_params, i2c_address), +@@ -267,15 +276,18 @@ int nl_getmodule(struct cmd_context *ctx) + * ioctl. Netlink can only request specific pages. + */ + if ((getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) && +- !getmodule_cmd_params.page && !getmodule_cmd_params.bank && +- !getmodule_cmd_params.i2c_address) { ++ !(getmodule_cmd_params.present & (1 << PARAM_PAGE | ++ 1 << PARAM_BANK | ++ 1 << PARAM_I2C))) { + nlctx->ioctl_fallback = true; + return -EOPNOTSUPP; + } + + #ifdef ETHTOOL_ENABLE_PRETTY_DUMP +- if (getmodule_cmd_params.page || getmodule_cmd_params.bank || +- getmodule_cmd_params.offset || getmodule_cmd_params.length) ++ if (getmodule_cmd_params.present & (1 << PARAM_PAGE | ++ 1 << PARAM_BANK | ++ 1 << PARAM_OFFSET | ++ 1 << PARAM_LENGTH)) + #endif + getmodule_cmd_params.dump_hex = true; + +diff --git a/netlink/parser.c b/netlink/parser.c +index 6f86361..cd32752 100644 +--- a/netlink/parser.c ++++ b/netlink/parser.c +@@ -996,7 +996,7 @@ static void tmp_buff_destroy(struct tmp_buff *head) + * and their handlers; the array must be terminated by null + * element {} + * @dest: optional destination to copy parsed data to (at +- * param_parser::offset) ++ * param_parser::offset); buffer should start with presence bitmap + * @group_style: defines if identifiers in .group represent separate messages, + * nested attributes or are not allowed + * @msgbuffs: (only used for @group_style = PARSER_GROUP_MSG) array to store +@@ -1096,7 +1096,14 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params, + buff = tmp_buff_find(buffs, parser->group); + msgbuff = buff ? buff->msgbuff : &nlsk->msgbuff; + +- param_dest = dest ? ((char *)dest + parser->dest_offset) : NULL; ++ if (dest) { ++ unsigned long index = parser - params; ++ ++ param_dest = ((char *)dest + parser->dest_offset); ++ set_bit(index, (unsigned long *)dest); ++ } else { ++ param_dest = NULL; ++ } + ret = parser->handler(nlctx, parser->type, parser->handler_data, + msgbuff, param_dest); + if (ret < 0) +-- +cgit 1.2.3-korg + diff --git a/backport-net-ethtool-Add-default-branch-to-sff8636_show_all_i.patch b/backport-net-ethtool-Add-default-branch-to-sff8636_show_all_i.patch new file mode 100644 index 0000000..bc4076f --- /dev/null +++ b/backport-net-ethtool-Add-default-branch-to-sff8636_show_all_i.patch @@ -0,0 +1,43 @@ +From 6bb620009e2e4aeaa41313247a0a5668abf393df Mon Sep 17 00:00:00 2001 +From: Hao Lan +Date: Mon, 11 Dec 2023 10:18:21 +0800 +Subject: net: ethtool: Add default branch to sff8636_show_all_ioctl switch + +The current sff8636_show_all_ioctl code uses a switch statement +to determine the module type, and exits directly with a return statement +when a match is found. However, when the module type cannot be matched, +the sff8636_memory_map_init_buf and sff8636_show_all_common functions +are executed. This writing style is not intuitive enough. +Therefore, this patch adding a default branch in the switch statement +to improve the readability of the code. + +Signed-off-by: Hao Lan +Signed-off-by: Jijie Shao +--- + qsfp.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/qsfp.c b/qsfp.c +index eedf688..a2921fb 100644 +--- a/qsfp.c ++++ b/qsfp.c +@@ -985,11 +985,12 @@ void sff8636_show_all_ioctl(const __u8 *id, __u32 eeprom_len) + case SFF8024_ID_SFP_DD_CMIS: + case SFF8024_ID_SFP_PLUS_CMIS: + cmis_show_all_ioctl(id); +- return; ++ break; ++ default: ++ sff8636_memory_map_init_buf(&map, id, eeprom_len); ++ sff8636_show_all_common(&map); ++ break; + } +- +- sff8636_memory_map_init_buf(&map, id, eeprom_len); +- sff8636_show_all_common(&map); + } + + static void sff8636_request_init(struct ethtool_module_eeprom *request, u8 page, +-- +cgit 1.2.3-korg + diff --git a/backport-qsf-Better-handling-of-Page-A2h-netlink-read-failure.patch b/backport-qsf-Better-handling-of-Page-A2h-netlink-read-failure.patch new file mode 100644 index 0000000..ee3f2e1 --- /dev/null +++ b/backport-qsf-Better-handling-of-Page-A2h-netlink-read-failure.patch @@ -0,0 +1,32 @@ +From 814980faaef11c678524a0f93856a5ed6ff8f0d2 Mon Sep 17 00:00:00 2001 +From: Krzysztof Olędzki +Date: Wed, 11 Sep 2024 23:58:42 -0700 +Subject: qsf: Better handling of Page A2h netlink read failure + +Print "Failed to read Page A2h." error message to provide more context +for "netlink error: (...)" info. + +Signed-off-by: Krzysztof Piotr Oledzki +--- + sfpid.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/sfpid.c b/sfpid.c +index 1bc45c1..d9bda70 100644 +--- a/sfpid.c ++++ b/sfpid.c +@@ -494,8 +494,10 @@ int sff8079_show_all_nl(struct cmd_context *ctx) + /* Read A2h page */ + ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_HIGH, + buf + ETH_MODULE_SFF_8079_LEN); +- if (ret) ++ if (ret) { ++ fprintf(stderr, "Failed to read Page A2h.\n"); + goto out; ++ } + + sff8472_show_all(buf); + out: +-- +cgit 1.2.3-korg + diff --git a/backport-qsfp-Better-handling-of-Page-03h-netlink-read-failur.patch b/backport-qsfp-Better-handling-of-Page-03h-netlink-read-failur.patch new file mode 100644 index 0000000..0a01537 --- /dev/null +++ b/backport-qsfp-Better-handling-of-Page-03h-netlink-read-failur.patch @@ -0,0 +1,61 @@ +From e1a65d47551f3a9276767f482d1cf9a55c2b5460 Mon Sep 17 00:00:00 2001 +From: Krzysztof Olędzki +Date: Tue, 30 Jul 2024 17:49:33 -0700 +Subject: qsfp: Better handling of Page 03h netlink read failure + +When dumping the EEPROM contents of a QSFP transceiver module, ethtool +will only ask the kernel to retrieve Upper Page 03h if the module +advertised it as supported. + +However, some kernel drivers like mlx4 are currently unable to provide +the page, resulting in the kernel returning an error. Since Upper Page +03h is optional, do not treat the error as fatal. Instead, print an +error message and allow ethtool to continue and parse / print the +contents of the other pages. + +Also, clarify potentially cryptic "netlink error: Invalid argument" message. + +Before: + # ethtool -m eth3 + netlink error: Invalid argument + +After: + # ethtool -m eth3 + netlink error: Invalid argument + Failed to read Upper Page 03h, driver error? + Identifier : 0x0d (QSFP+) + Extended identifier : 0x00 + (...) + +Fixes: 25b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)") +Signed-off-by: Krzysztof Piotr Oledzki +Reviewed-by: Ido Schimmel +--- + qsfp.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/qsfp.c b/qsfp.c +index a2921fb..a3a919d 100644 +--- a/qsfp.c ++++ b/qsfp.c +@@ -1038,8 +1038,15 @@ sff8636_memory_map_init_pages(struct cmd_context *ctx, + + sff8636_request_init(&request, 0x3, SFF8636_PAGE_SIZE); + ret = nl_get_eeprom_page(ctx, &request); +- if (ret < 0) +- return ret; ++ if (ret < 0) { ++ /* Page 03h is not available due to a bug in the driver. ++ * This is a non-fatal error and sff8636_dom_parse() ++ * handles this correctly. ++ */ ++ fprintf(stderr, "Failed to read Upper Page 03h, driver error?\n"); ++ return 0; ++ } ++ + map->page_03h = request.data - SFF8636_PAGE_SIZE; + + return 0; +-- +cgit 1.2.3-korg + diff --git a/ethtool.spec b/ethtool.spec index 93951c3..dcc65a4 100644 --- a/ethtool.spec +++ b/ethtool.spec @@ -1,13 +1,18 @@ Name: ethtool Epoch: 2 Version: 6.6 -Release: 2 +Release: 3 Summary: Settings tool for Ethernet NICs License: GPL-2.0-only AND GPL-2.0-or-later URL: https://www.kernel.org/pub/software/network/ethtool Source0: https://www.kernel.org/pub/software/network/%{name}/%{name}-%{version}.tar.xz Patch0: netlink-fix-typo.patch +Patch1: backport-ethtool-Fix-SFF-8472-transceiver-module-identificati.patch +Patch2: backport-net-ethtool-Add-default-branch-to-sff8636_show_all_i.patch +Patch3: backport-qsfp-Better-handling-of-Page-03h-netlink-read-failur.patch +Patch4: backport-module-eeprom-treat-zero-arguments-like-any-other-ar.patch +Patch5: backport-qsf-Better-handling-of-Page-A2h-netlink-read-failure.patch BuildRequires: gcc BuildRequires: libmnl-devel @@ -55,6 +60,16 @@ make check %{_mandir}/man8/%{name}.8* %changelog +* Wed Jul 30 2025 andy - 2:6.6-3 +- Type:requirement +- Id:NA +- SUG:NA +- DESC:ethtool: Fix SFF-8472 transceiver module identification + ethtool: Add default branch to sff8636_show_all_ioctl switch + qsfp: Better handling of Page 03h netlink read failure + module-eeprom: treat zero arguments like any other arguments for hex dump + qsf: Better handling of Page A2h netlink read failure + * Fri Mar 22 2024 yanglu - 2:6.6-2 - Type:bugfix - Id:NA -- Gitee