1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
From c810d56d96d87d1db1cadf899238cee2e70f0cfd Mon Sep 17 00:00:00 2001
From: Jakub Kicinski <kuba@kernel.org>
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 <kuba@kernel.org>
Reviewed-by: Ido Schimmel <idosch@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 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
|