From: Aleksander Jan Bajkowski <olek2@wp.pl>
To: mkubecek@suse.cz, andrew@lunn.ch, danieller@nvidia.com,
kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
pabeni@redhat.com, netdev@vger.kernel.org
Cc: Aleksander Jan Bajkowski <olek2@wp.pl>
Subject: [PATCH ethtool-next 1/2] sfpid: print all implemented options
Date: Sun, 5 Jul 2026 22:06:25 +0200 [thread overview]
Message-ID: <20260705200637.2092534-1-olek2@wp.pl> (raw)
SFP modules implement multiple options. Before the “json” option was
instroduced, all options were listed. Currently, only the last option
is listed. This commit fixes this bug. Options are represented as array.
Before:
$ ethtool -m sfp-wan
...
Option values : 0x00 0x32
Option : RATE_SELECT implemented
...
$ ethtool --json -m sfp-wan
[ {
...
"option_values": [ 0,50 ],
"option": "RATE_SELECT implemented",
...
} ]
After:
$ ethtool -m sfp-lan
...
Option values : 0x00 0x32
Option : RX_LOS implemented
Option : TX_DISABLE implemented
Option : RATE_SELECT implemented
...
$ ethtool --json -m sfp-lan
[ {
..
"option_values": [ 0,50 ],
"option": [ "RX_LOS implemented","TX_DISABLE implemented","RATE_SELECT implemented" ],
} ]
..
Fixes: 4071862f58d8 ("sfpid: Add JSON output handling to --module-info in SFF8079 modules")
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
---
module-common.c | 8 ++++++++
module-common.h | 1 +
sfpid.c | 39 +++++++++++++++++++++++----------------
3 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/module-common.c b/module-common.c
index 42fccf6..d736c7c 100644
--- a/module-common.c
+++ b/module-common.c
@@ -258,6 +258,14 @@ void module_print_any_bool(const char *fn, char *given_json_fn, bool value,
printf("\t%-41s : %s\n", fn, str_value);
}
+void module_print_array_string(const char *fn, const char *value)
+{
+ if (is_json_context())
+ print_string(PRINT_JSON, NULL, "%s", value);
+ else
+ printf("\t%-41s : %s\n", fn, value);
+}
+
void module_show_value_with_unit(const __u8 *id, unsigned int reg,
const char *name, unsigned int mult,
const char *unit)
diff --git a/module-common.h b/module-common.h
index 4063448..6f9da5f 100644
--- a/module-common.h
+++ b/module-common.h
@@ -281,6 +281,7 @@ void module_print_any_string(const char *fn, const char *value);
void module_print_any_float(const char *fn, float value, const char *unit);
void module_print_any_bool(const char *fn, char *given_json_fn, bool value,
const char *str_value);
+void module_print_array_string(const char *fn, const char *value);
void module_show_value_with_unit(const __u8 *id, unsigned int reg,
const char *name, unsigned int mult,
const char *unit);
diff --git a/sfpid.c b/sfpid.c
index 74a6f51..d6636ba 100644
--- a/sfpid.c
+++ b/sfpid.c
@@ -396,7 +396,6 @@ static void sff8079_show_wavelength_or_copper_compliance(const __u8 *id)
static void sff8079_show_options(const __u8 *id)
{
static const char *pfx = "Option";
- char value[64] = "";
if (is_json_context()) {
open_json_array("option_values", "");
@@ -407,35 +406,43 @@ static void sff8079_show_options(const __u8 *id)
printf("\t%-41s : 0x%02x 0x%02x\n", "Option values", id[64],
id[65]);
}
+
+ if (is_json_context())
+ open_json_array("option", "");
+
if (id[65] & (1 << 1))
- sprintf(value, "%s", "RX_LOS implemented");
+ module_print_array_string(pfx, "RX_LOS implemented");
if (id[65] & (1 << 2))
- sprintf(value, "%s", "RX_LOS implemented, inverted");
+ module_print_array_string(pfx, "RX_LOS implemented, inverted");
if (id[65] & (1 << 3))
- sprintf(value, "%s", "TX_FAULT implemented");
+ module_print_array_string(pfx, "TX_FAULT implemented");
if (id[65] & (1 << 4))
- sprintf(value, "%s", "TX_DISABLE implemented");
+ module_print_array_string(pfx, "TX_DISABLE implemented");
if (id[65] & (1 << 5))
- sprintf(value, "%s", "RATE_SELECT implemented");
+ module_print_array_string(pfx, "RATE_SELECT implemented");
if (id[65] & (1 << 6))
- sprintf(value, "%s", "Tunable transmitter technology");
+ module_print_array_string(pfx,
+ "Tunable transmitter technology");
if (id[65] & (1 << 7))
- sprintf(value, "%s", "Receiver decision threshold implemented");
+ module_print_array_string(pfx,
+ "Receiver decision threshold implemented");
if (id[64] & (1 << 0))
- sprintf(value, "%s", "Linear receiver output implemented");
+ module_print_array_string(pfx,
+ "Linear receiver output implemented");
if (id[64] & (1 << 1))
- sprintf(value, "%s", "Power level 2 requirement");
+ module_print_array_string(pfx, "Power level 2 requirement");
if (id[64] & (1 << 2))
- sprintf(value, "%s", "Cooled transceiver implemented");
+ module_print_array_string(pfx,
+ "Cooled transceiver implemented");
if (id[64] & (1 << 3))
- sprintf(value, "%s", "Retimer or CDR implemented");
+ module_print_array_string(pfx, "Retimer or CDR implemented");
if (id[64] & (1 << 4))
- sprintf(value, "%s", "Paging implemented");
+ module_print_array_string(pfx, "Paging implemented");
if (id[64] & (1 << 5))
- sprintf(value, "%s", "Power level 3 requirement");
+ module_print_array_string(pfx, "Power level 3 requirement");
- if (value[0] != '\0')
- module_print_any_string(pfx, value);
+ if (is_json_context())
+ close_json_array("");
}
static void sff8079_show_all_common(const __u8 *id)
--
2.53.0
next reply other threads:[~2026-07-05 20:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 20:06 Aleksander Jan Bajkowski [this message]
2026-07-05 20:06 ` [PATCH ethtool-next 2/2] sfpid: print all compliance codes Aleksander Jan Bajkowski
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=20260705200637.2092534-1-olek2@wp.pl \
--to=olek2@wp.pl \
--cc=andrew@lunn.ch \
--cc=danieller@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox