From: Jakub Kicinski <kuba@kernel.org>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, andrew@lunn.ch,
Jakub Kicinski <kuba@kernel.org>,
idosch@nvidia.com, danieller@nvidia.com
Subject: [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump
Date: Fri, 12 Jul 2024 11:07:06 -0700 [thread overview]
Message-ID: <20240712180706.466124-1-kuba@kernel.org> (raw)
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
next reply other threads:[~2024-07-12 18:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 18:07 Jakub Kicinski [this message]
2024-07-14 8:39 ` [PATCH ethtool-next] module-eeprom: treat zero arguments like any other arguments for hex dump Ido Schimmel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240712180706.466124-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=danieller@nvidia.com \
--cc=idosch@nvidia.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.