netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Danielle Ratson <danieller@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: <mkubecek@suse.cz>, <matt@traverse.com.au>,
	<daniel.zahka@gmail.com>, <amcohen@nvidia.com>,
	<nbu-mlxsw@exchange.nvidia.com>,
	Danielle Ratson <danieller@nvidia.com>
Subject: [PATCH ethtool-next v2 12/14] sfpdiag: Add JSON output handling to --module-info in SFF8472 modules
Date: Wed, 29 Jan 2025 15:15:45 +0200	[thread overview]
Message-ID: <20250129131547.964711-13-danieller@nvidia.com> (raw)
In-Reply-To: <20250129131547.964711-1-danieller@nvidia.com>

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@nvidia.com>
---

Notes:
    v2:
    	* In rx_power JSON field, add a type field to let the user know
    	  what type is printed in "value".

 sfpdiag.c | 49 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 16 deletions(-)

diff --git a/sfpdiag.c b/sfpdiag.c
index bbca91e..58023c9 100644
--- a/sfpdiag.c
+++ b/sfpdiag.c
@@ -241,40 +241,57 @@ static void sff8472_parse_eeprom(const __u8 *id, struct sff_diags *sd)
 
 void sff8472_show_all(const __u8 *id)
 {
+	char *rx_power_type_string = NULL;
 	struct sff_diags sd = {0};
-	char *rx_power_string = NULL;
 	int i;
 
 	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";
+		rx_power_type_string = "Receiver signal OMA";
 	else
-		rx_power_string = "Receiver signal average optical power";
+		rx_power_type_string = "Receiver signal average optical power";
 
-	PRINT_xX_PWR(rx_power_string, sd.rx_power[MCURR]);
+	open_json_object("rx_power");
+	PRINT_xX_PWR_ALL(rx_power_type_string, "value", sd.rx_power[MCURR]);
+	if (is_json_context()) {
+		print_string(PRINT_JSON, "units", "%s", "mW");
+		module_print_any_string("type", rx_power_type_string);
+	}
+	close_json_object();
 
 	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


  parent reply	other threads:[~2025-01-29 13:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-29 13:15 [PATCH ethtool-next v2 00/14] Add JSON output to --module-info Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 01/14] module_common: Add a new file to all the common code for all module types Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 02/14] sff_common: Move sff_show_revision_compliance() to qsfp.c Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 03/14] cmis: Change loop order in cmis_show_dom_chan_lvl_flags() Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 04/14] qsfp: Reorder the channel-level flags list for SFF8636 module type Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 05/14] qsfp: Refactor sff8636_show_dom() by moving code into separate functions Danielle Ratson
2025-01-30 12:26   ` Vadim Fedorenko
2025-01-30 13:03     ` Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 06/14] module_common: Add helpers to support JSON printing for common value types Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 07/14] cmis: Add JSON output handling to --module-info in CMIS modules Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 08/14] cmis: Enable JSON output support " Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 09/14] qsfp: Add JSON output handling to --module-info in SFF8636 modules Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 10/14] qsfp: Enable JSON output support for " Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 11/14] sfpid: Add JSON output handling to --module-info in SFF8079 modules Danielle Ratson
2025-01-29 13:15 ` Danielle Ratson [this message]
2025-01-29 13:15 ` [PATCH ethtool-next v2 13/14] ethtool: Enable JSON output support for SFF8079 and SFF8472 modules Danielle Ratson
2025-01-29 13:15 ` [PATCH ethtool-next v2 14/14] ethtool: Add '-j' support to ethtool Danielle Ratson

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=20250129131547.964711-13-danieller@nvidia.com \
    --to=danieller@nvidia.com \
    --cc=amcohen@nvidia.com \
    --cc=daniel.zahka@gmail.com \
    --cc=matt@traverse.com.au \
    --cc=mkubecek@suse.cz \
    --cc=nbu-mlxsw@exchange.nvidia.com \
    --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 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).