[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250126115635.801935-13-danieller@nvidia.com>
Date: Sun, 26 Jan 2025 13:56:33 +0200
From: Danielle Ratson <danieller@...dia.com>
To: <netdev@...r.kernel.org>
CC: <mkubecek@...e.cz>, <matt@...verse.com.au>, <daniel.zahka@...il.com>,
<amcohen@...dia.com>, <nbu-mlxsw@...hange.nvidia.com>, Danielle Ratson
<danieller@...dia.com>
Subject: [PATCH ethtool-next 12/14] sfpdiag: Add JSON output handling to --module-info in SFF8472 modules
Add JSON output handling for 'ethtool -m' / --module-info, following
the guideline below:
1. Fields with description, will have a separate description field.
2. Fields with units, will have a separate unit field.
3. ASCII fields will be presented as strings.
4. On/Off is rendered as true/false.
5. Yes/no is rendered as true/false.
6. Per-channel fields will be presented as array, when each element
represents a channel.
7. Fields that hold version, will be split to major and minor sub fields.
Signed-off-by: Danielle Ratson <danieller@...dia.com>
---
sfpdiag.c | 42 +++++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 13 deletions(-)
diff --git a/sfpdiag.c b/sfpdiag.c
index bbca91e..4b40bc8 100644
--- a/sfpdiag.c
+++ b/sfpdiag.c
@@ -247,34 +247,50 @@ void sff8472_show_all(const __u8 *id)
sff8472_parse_eeprom(id, &sd);
- if (!sd.supports_dom) {
- printf("\t%-41s : No\n", "Optical diagnostics support");
+ module_print_any_bool("Optical diagnostics support",
+ "optical_diagnostics_support",
+ sd.supports_dom, YESNO(sd.supports_dom));
+
+ if (!sd.supports_dom)
return;
- }
- printf("\t%-41s : Yes\n", "Optical diagnostics support");
- PRINT_BIAS("Laser bias current", sd.bias_cur[MCURR]);
- PRINT_xX_PWR("Laser output power", sd.tx_power[MCURR]);
+ PRINT_BIAS_ALL("Laser bias current", "laser_bias_current",
+ sd.bias_cur[MCURR]);
+ PRINT_xX_PWR_ALL("Laser output power", "laser_output_power",
+ sd.tx_power[MCURR]);
if (!sd.rx_power_type)
rx_power_string = "Receiver signal OMA";
else
rx_power_string = "Receiver signal average optical power";
- PRINT_xX_PWR(rx_power_string, sd.rx_power[MCURR]);
+ char rx_power_json_str[strlen(rx_power_string)];
+
+ convert_json_field_name(rx_power_string, rx_power_json_str);
+
+ PRINT_xX_PWR_ALL(rx_power_string, rx_power_json_str,
+ sd.rx_power[MCURR]);
module_show_dom_mod_lvl_monitors(&sd);
- printf("\t%-41s : %s\n", "Alarm/warning flags implemented",
- (sd.supports_alarms ? "Yes" : "No"));
+ module_print_any_bool("Alarm/warning flags implemented",
+ "alarm/warning_flags_implemented",
+ sd.supports_alarms, YESNO(sd.supports_alarms));
+
if (sd.supports_alarms) {
for (i = 0; sff8472_aw_flags[i].str; ++i) {
- printf("\t%-41s : %s\n", sff8472_aw_flags[i].str,
- id[SFF_A2_BASE + sff8472_aw_flags[i].offset]
- & sff8472_aw_flags[i].value ? "On" : "Off");
+ bool value;
+
+ value = id[SFF_A2_BASE + sff8472_aw_flags[i].offset] &
+ sff8472_aw_flags[i].value;
+ module_print_any_bool(sff8472_aw_flags[i].str, NULL,
+ value, ONOFF(value));
}
- sff_show_thresholds(sd);
+ if (is_json_context())
+ sff_show_thresholds_json(sd);
+ else
+ sff_show_thresholds(sd);
}
}
--
2.47.0
Powered by blists - more mailing lists