netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump
@ 2024-07-12 18:07 Jakub Kicinski
  2024-07-14  8:39 ` Ido Schimmel
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Kicinski @ 2024-07-12 18:07 UTC (permalink / raw)
  To: mkubecek; +Cc: netdev, andrew, Jakub Kicinski, idosch, danieller

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 <kuba@kernel.org>
---
CC: idosch@nvidia.com
CC: danieller@nvidia.com
---
 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 fe02c5ab2b65..2b30d042c00a 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 6f863610a490..cd32752a9ddb 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)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump
  2024-07-12 18:07 [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump Jakub Kicinski
@ 2024-07-14  8:39 ` Ido Schimmel
  0 siblings, 0 replies; 2+ messages in thread
From: Ido Schimmel @ 2024-07-14  8:39 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: mkubecek, netdev, andrew, danieller

On Fri, Jul 12, 2024 at 11:07:06AM -0700, Jakub Kicinski wrote:
> 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 <kuba@kernel.org>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-14  8:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 18:07 [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump Jakub Kicinski
2024-07-14  8:39 ` Ido Schimmel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).