diff mbox series

[ethtool-next,v4,14/16] ethtool: Enable JSON output support for SFF8079 and SFF8472 modules

Message ID 20250205155436.1276904-15-danieller@nvidia.com (mailing list archive)
State New
Delegated to: Michal Kubecek
Headers show
Series Add JSON output to --module-info | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Danielle Ratson Feb. 5, 2025, 3:54 p.m. UTC
A sample output:

$ ethtool --json -m swp1
[ {
        "identifier": 3,
        "identifier_description": "SFP",
        "extended_identifier": 4,
        "extended_identifier_description": "GBIC/SFP defined by 2-wire
interface ID",
        "connector": 33,
        "connector_description": "Copper pigtail",
        "transceiver_codes": [ 1,0,0,4,0,4,128,213,0 ],
        "transceiver_type": "FC: 100 MBytes/sec",
        "encoding": 0,
        "encoding_description": "unspecified",
        "br_nominal": 10300,
        "rate_identifier": 0,
        "rate_identifier_description": "unspecified",
        "length_(smf)": 0,
        "length_(om2)": 0,
        "length_(om1)": 0,
        "length_(copper_or_active_cable)": 2,
        "length_(om3)": 0,
        "passive_cu_cmplnce.": 1,
        "passive_cu_cmplnce._description": "SFF-8431 appendix E
[SFF-8472 rev10.4 only]",
        "vendor_name": "Mellanox",
        "vendor_oui": [ 0,2,201 ],
        "vendor_pn": "MC2309130-002",
        "vendor_rev": "A2",
        "option_values": [ 0,0 ],
        "br_margin_max": 0,
        "br_margin_min": 0,
        "vendor_sn": "MT1146VS00060",
        "date_code": "111110"
} ]

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
---

Notes:
    v3:
    	* Enable JSON output support for SFF8079.
    	* Reword commit message.

 ethtool.c | 4 ++++
 sfpid.c   | 4 ++++
 2 files changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/ethtool.c b/ethtool.c
index 0b876e8..8a81001 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5007,6 +5007,8 @@  static int do_getmodule(struct cmd_context *ctx)
 		    (eeprom->len != modinfo.eeprom_len)) {
 			geeprom_dump_hex = 1;
 		} else if (!geeprom_dump_hex) {
+			new_json_obj(ctx->json);
+			open_json_object(NULL);
 			switch (modinfo.type) {
 #ifdef ETHTOOL_ENABLE_PRETTY_DUMP
 			case ETH_MODULE_SFF_8079:
@@ -5026,6 +5028,8 @@  static int do_getmodule(struct cmd_context *ctx)
 				geeprom_dump_hex = 1;
 				break;
 			}
+			close_json_object();
+			delete_json_obj();
 		}
 		if (geeprom_dump_hex)
 			dump_hex(stdout, eeprom->data,
diff --git a/sfpid.c b/sfpid.c
index 0ccf9ad..62acb4f 100644
--- a/sfpid.c
+++ b/sfpid.c
@@ -517,7 +517,11 @@  int sff8079_show_all_nl(struct cmd_context *ctx)
 	if (ret)
 		goto out;
 
+	new_json_obj(ctx->json);
+	open_json_object(NULL);
 	sff8079_show_all_common(buf);
+	close_json_object();
+	delete_json_obj();
 
 	/* Finish if A2h page is not present */
 	if (!(buf[92] & (1 << 6)))