Skip to contentSkip to conversation

module-eeprom: treat zero arguments like any other arguments for hex dump

PATCH In review Jakub Kicinski 2 participants 2 messages Jul 12, 2024 – Jul 14, 2024

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 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.

---
CC: [email protected]
CC: [email protected]

---
 netlink/module-eeprom.c | 30 +++++++++++++++++++++---------
 netlink/parser.c        | 11 +++++++++--
 2 files changed, 30 insertions(+), 11 deletions(-)
netlink/module-eeprom.c +21 -9
index fe02c5ab2b65..2b30d042c00a 100644
@@ -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;
 
netlink/parser.c +9 -2
index 6f863610a490..cd32752a9ddb 100644
@@ -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)
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Jakub Kicinski

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.

Quoted 6 lines

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.