From patchwork Sun Jan 26 11:56:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950653 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D5CC13AA3E for ; Sun, 26 Jan 2025 11:57:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892634; cv=fail; b=kMr19XhfUvEIvWszwoVWWvrbqOwRzH8HPRGh3o2VG/MbHVMaGfu7ckbBn0dBAl/weGgXh/EiNXN4L8yCz4C+jEz7EI4MbxHXgS7mruZQFEY84eABdGZLt+FCcuIIkk46L4vYkAdIcNVxKBA1/GwcRY8ep3IExV0K4g/Ue1hnRrw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892634; c=relaxed/simple; bh=QHmENA3v1z9r1OlXlOPbRFoLyiFBK93HzPbcKz6dmpQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ojXxJ2sKoMAcq9QHhPVWDWF2kQM3nrS/b0qIXVP9b7df1WlgaOPuTYSrCzw5o3ZrXNLXVgQoqgOW9pw+Em+PJInSYe3TlRKOYdloDkUrepRDmHqYOoDziONotF78PoTFh5ZUTDarejxY3tSGktkuIrhm1Bqg3odj/nhpK2ReOl0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RZglcDXP; arc=fail smtp.client-ip=40.107.92.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RZglcDXP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=axh6CEyRc1NQB9JEQsR33UN7Uepe37vYzODdQc8C01vCZHnhhuPpWu1E5+LDFh3qPd1xiizNCBZWI+j5B3TwCVaFkZyd+8Q4w93sVssonXxMW28GNzdny0flth6btovyptMWe3GBhmnNKOUvVoQko3DUQOXY83bi4pFhAwTqoD22iG0gp7wlHzYd5T1QTwqywzc19d5fTyWsfky75C4VxZrjK6cg7nvPSQwMAFejFfI5ftgM6hvXdrnCwYeRiRc6+QoAHrgTub4pkNPcGnB9i4Z7F+6V0lytV5HDtLtx6q8yWtCsxrV8GmveG1IJscgldxrXcIAJCgO9UDxV306kiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Smdmj4VmD1nNuQJ0+g0y9NtQqD1W326RhPvJsDcYOa0=; b=E60rsHNFQRa6bgnng4g68kou0ZmSvRFRMVqH7JDJODrQWAR++bOMPqwYrJieqZCSbi3KJdvnZ9LvdDgEM9vSF4U78IXOlX9XS+taafkqWEfwMnZjMfaj/j4jNGjuq3yT+XZtPrULPJ1aRfnu6lTbi4mRD3KgZSQ/nJQx+929qevwdct9796Yp6Zxc+3luBlFCL7Y3+xjiccxiQrUwFlc46UJp8mmu0OTA5wjmsonSZeKNirykNz8CnxYkrJvd+NQxhIZPURqBOiBO/QBn3BUpfzceMcN0HA1omivPhgSagJdxbXiA/no7fgV04Z/0Wdh9IZQkIk+qe6p71CX3FJmEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Smdmj4VmD1nNuQJ0+g0y9NtQqD1W326RhPvJsDcYOa0=; b=RZglcDXPxxvTfsZfCi1touFu/PMWYkDqCOtj5GDeYU3V83GXowZclpLw812KyyXYa0e+fOaXJG1WrD3mVuAMye68d3iV86srEB6/GJGrXS21fmqmpYFSSVBo/muYMWoZeg2l8la29oJVreR40xFfGzRnsLJ+xx9vM2BPyX51mUid85mCsw04z7Lb4hF3gbwJsIK8ZtoP8TLUEIs65L7Y1xL519TSQ/lAM8DH/0h+dbHQhDw50y8csTXI3CAAG/LtPd334oDVRr3/ba31KGOb2JD4C3S2eg2PEmapre4HsMn+K6gkR0XW00LPWTJU3N1JIBLYkILRdoZLyinkFshwgw== Received: from PH8PR07CA0002.namprd07.prod.outlook.com (2603:10b6:510:2cd::9) by DS0PR12MB8415.namprd12.prod.outlook.com (2603:10b6:8:fc::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.20; Sun, 26 Jan 2025 11:57:02 +0000 Received: from CY4PEPF0000EE39.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::26) by PH8PR07CA0002.outlook.office365.com (2603:10b6:510:2cd::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE39.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:02 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:53 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:50 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 01/14] module_common: Add a new file to all the common code for all module types Date: Sun, 26 Jan 2025 13:56:22 +0200 Message-ID: <20250126115635.801935-2-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE39:EE_|DS0PR12MB8415:EE_ X-MS-Office365-Filtering-Correlation-Id: 7c42a632-b567-4336-728b-08dd3e008bd4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: afMkIBtw9qh1u0bjBptCqF0DjnLzvnR8v/iQ3bRUCWDEo8nrUaHR0MXnezne5o5gDpAFJL2NPmDQli98pLbY/8yyRsU30nBqqAmaDX4Zpyp4yCTxk2Nwf/Eag3qTU1fqKvmJ99yZISoUXzGhlPECQ+9CUViT3FKXwKMxEDOFk8Ar5u2XSycfBWfpjGmjOXfgDDkqMsADv5Ei7Vfa1yru6hoOzVNMF7X64GiGq7xJpnikzWOLb8vjDgokwXIjr0MEMPFVuMsE8oDU6Bc8plVDRFe9hyW1F5hogPlzqN3+SxGH8JOSYkwP1K7ApYpJjgGmJ8BvLIAv3ehv6C1N4q8aAv+mQYxOgpIjeh1IdVzs+XXn161D5tFLJRVpPFiPNChBaV3eBSwfp9bN+siDwx/pogTGzBJIy/kn3LAUr8sMhHapev41cwocNi+eFpUxPL2+x7qyeaciCNJf/G3p+AbUj5dwb3GAJc8dBAFzkD3IZYrI1JofEO5HKsW0Bi0fW3/pM+TCqUOIYOF73wY5AkZW7SxmvF2Kg9xnnvzAuhXwj+iVHDI/hv4B6y9z+RBbdOeZOMPzyIrI9RcCdCT7R4YgFOKt5PYCk1q6O8FsjqLNoRA2APdcf/KOSfnaO95Kt8uOr3lzujVSPW4hLrbUm/LcD4eLG5xiUuJFUIGn5Vj+Jv/L8ht0dPMyogfMAEaFX+DQXuaNcR6cAI754WccBE04rkEYQvF5yCp8ZAlpBZd42FK2l44XC+IQ+pauqKTAwJyzgHd0OH9ZaDBdGiGktJi8SvNeBggX8sWROnC8tohSpzmY+Rv7oGIiotS3QYDM9EvN/SxMc9TStzzkm8E5YgEaP9bMQTfw8t/UIaQ3uwgPmP0Xv2XSHFUM6hy+bQ5wnG28VVOJL4iTCtVYs5vjhCswVs+seT2rE4zPweLAc6nvwBQV+ANvgPPo29xOUX/jfZLkW9NSaSf0UTv/ZHpyar8AfYl5WXd7oQsRFilD2DePEIjBGSolVQENha7HclelCbNU5tIlazyoPtCivXmzM0PmCRAxJE1ocm94TZoYw/EGknApiEa7UB1o6fprlM6ql8v4ffn7hiiYuScOd/M38NTW/PAWLB7oXh+w3DmLjI5SkrlBlCxahi24ScjcNlP45Axd4scl8ZphAdZSonEFaqg6rnrSTR02ieEgm3Ec8CQOxp3scxWaXkHMl3lXwmtapVpEgh1ScT7CGRExhXThZA8cnXhjmhGff4apmueidHyOJv0ktkqthPIwGwicYf7A2mnll1cVDwmAONFuO/CtbNY0hVGOtmk9ZDbH5npu1z7vMB7B2wWvAiskHbKSmkhRdMgbcvu/Tf+a93r/3R4lOtFbMcGIR5PtsZHuDfoXP7pNYYe/8+sRckiqRUi6mwiYMcNsBVN6QeEKkXNTaenW/1r6ssURkrZ6iAfKOVcagkRP25nLSAoQboU2qtWnVT5P5bjuQXFORWiq69K36hGe+MyKEg== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:02.1794 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7c42a632-b567-4336-728b-08dd3e008bd4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE39.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8415 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Currently, a significant amount of repetitive code exists across different module type files. Consolidate shared functions and definitions into a single, dedicated file to improve organization and maintainability. Signed-off-by: Danielle Ratson --- Makefile.am | 7 +- cmis.c | 212 ++++------------- cmis.h | 65 ------ module-common.c | 506 ++++++++++++++++++++++++++++++++++++++++ module-common.h | 281 ++++++++++++++++++++++ netlink/module-eeprom.c | 26 +-- qsfp.c | 301 +++++------------------- qsfp.h | 108 --------- sff-common.c | 227 ------------------ sff-common.h | 77 ------ sfpdiag.c | 5 +- sfpid.c | 62 ++--- 12 files changed, 924 insertions(+), 953 deletions(-) create mode 100644 module-common.c create mode 100644 module-common.h diff --git a/Makefile.am b/Makefile.am index 5a61a9a..41290b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,9 +21,10 @@ ethtool_SOURCES += \ fec.c fec_8xx.c fsl_enetc.c ibm_emac.c ixgb.c ixgbe.c \ natsemi.c pcnet32.c realtek.c tg3.c marvell.c vioc.c \ smsc911x.c at76c50x-usb.c sfc.c stmmac.c \ - sff-common.c sff-common.h sfpid.c sfpdiag.c \ - ixgbevf.c tse.c vmxnet3.c qsfp.c qsfp.h fjes.c lan78xx.c \ - igc.c cmis.c cmis.h bnxt.c cpsw.c lan743x.c hns3.c + sff-common.c sff-common.h module-common.c module-common.h \ + sfpid.c sfpdiag.c ixgbevf.c tse.c vmxnet3.c qsfp.c qsfp.h \ + fjes.c lan78xx.c igc.c cmis.c cmis.h bnxt.c cpsw.c lan743x.c \ + hns3.c endif if ENABLE_BASH_COMPLETION diff --git a/cmis.c b/cmis.c index 6fe5dfb..71f0745 100644 --- a/cmis.c +++ b/cmis.c @@ -11,7 +11,7 @@ #include #include #include "internal.h" -#include "sff-common.h" +#include "module-common.h" #include "cmis.h" #include "netlink/extapi.h" @@ -36,93 +36,19 @@ struct cmis_memory_map { #define CMIS_PAGE_SIZE 0x80 #define CMIS_I2C_ADDRESS 0x50 -static struct { - const char *str; - int offset; - __u8 value; /* Alarm is on if (offset & value) != 0. */ -} cmis_aw_mod_flags[] = { - { "Module temperature high alarm", - CMIS_TEMP_AW_OFFSET, CMIS_TEMP_HALARM_STATUS }, - { "Module temperature low alarm", - CMIS_TEMP_AW_OFFSET, CMIS_TEMP_LALARM_STATUS }, - { "Module temperature high warning", - CMIS_TEMP_AW_OFFSET, CMIS_TEMP_HWARN_STATUS }, - { "Module temperature low warning", - CMIS_TEMP_AW_OFFSET, CMIS_TEMP_LWARN_STATUS }, - - { "Module voltage high alarm", - CMIS_VCC_AW_OFFSET, CMIS_VCC_HALARM_STATUS }, - { "Module voltage low alarm", - CMIS_VCC_AW_OFFSET, CMIS_VCC_LALARM_STATUS }, - { "Module voltage high warning", - CMIS_VCC_AW_OFFSET, CMIS_VCC_HWARN_STATUS }, - { "Module voltage low warning", - CMIS_VCC_AW_OFFSET, CMIS_VCC_LWARN_STATUS }, - - { NULL, 0, 0 }, -}; - -static struct { - const char *fmt_str; - int offset; - int adver_offset; /* In Page 01h. */ - __u8 adver_value; /* Supported if (offset & value) != 0. */ -} cmis_aw_chan_flags[] = { - { "Laser bias current high alarm (Chan %d)", - CMIS_TX_BIAS_AW_HALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_BIAS_MON_MASK }, - { "Laser bias current low alarm (Chan %d)", - CMIS_TX_BIAS_AW_LALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_BIAS_MON_MASK }, - { "Laser bias current high warning (Chan %d)", - CMIS_TX_BIAS_AW_HWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_BIAS_MON_MASK }, - { "Laser bias current low warning (Chan %d)", - CMIS_TX_BIAS_AW_LWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_BIAS_MON_MASK }, - - { "Laser tx power high alarm (Channel %d)", - CMIS_TX_PWR_AW_HALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_PWR_MON_MASK }, - { "Laser tx power low alarm (Channel %d)", - CMIS_TX_PWR_AW_LALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_PWR_MON_MASK }, - { "Laser tx power high warning (Channel %d)", - CMIS_TX_PWR_AW_HWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_PWR_MON_MASK }, - { "Laser tx power low warning (Channel %d)", - CMIS_TX_PWR_AW_LWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_TX_PWR_MON_MASK }, - - { "Laser rx power high alarm (Channel %d)", - CMIS_RX_PWR_AW_HALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_RX_PWR_MON_MASK }, - { "Laser rx power low alarm (Channel %d)", - CMIS_RX_PWR_AW_LALARM_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_RX_PWR_MON_MASK }, - { "Laser rx power high warning (Channel %d)", - CMIS_RX_PWR_AW_HWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_RX_PWR_MON_MASK }, - { "Laser rx power low warning (Channel %d)", - CMIS_RX_PWR_AW_LWARN_OFFSET, - CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_RX_PWR_MON_MASK }, - - { NULL, 0, 0, 0 }, -}; - static void cmis_show_identifier(const struct cmis_memory_map *map) { - sff8024_show_identifier(map->lower_memory, CMIS_ID_OFFSET); + module_show_identifier(map->lower_memory, CMIS_ID_OFFSET); } static void cmis_show_connector(const struct cmis_memory_map *map) { - sff8024_show_connector(map->page_00h, CMIS_CTOR_OFFSET); + module_show_connector(map->page_00h, CMIS_CTOR_OFFSET); } static void cmis_show_oui(const struct cmis_memory_map *map) { - sff8024_show_oui(map->page_00h, CMIS_VENDOR_OUI_OFFSET); + module_show_oui(map->page_00h, CMIS_VENDOR_OUI_OFFSET); } /** @@ -154,7 +80,7 @@ cmis_show_signals_one(const struct cmis_memory_map *map, const char *name, v |= map->upper_memory[i][0x11][off] << (i * 8); if (map->page_01h[ioff] & imask) - sff_show_lane_status(name, i * 8, "Yes", "No", v); + module_show_lane_status(name, i * 8, "Yes", "No", v); } static void cmis_show_signals(const struct cmis_memory_map *map) @@ -316,63 +242,11 @@ static void cmis_show_sig_integrity(const struct cmis_memory_map *map) */ static void cmis_show_mit_compliance(const struct cmis_memory_map *map) { - static const char *cc = " (Copper cable,"; + u16 value = map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET]; - printf("\t%-41s : 0x%02x", "Transmitter technology", - map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET]); - - switch (map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET]) { - case CMIS_850_VCSEL: - printf(" (850 nm VCSEL)\n"); - break; - case CMIS_1310_VCSEL: - printf(" (1310 nm VCSEL)\n"); - break; - case CMIS_1550_VCSEL: - printf(" (1550 nm VCSEL)\n"); - break; - case CMIS_1310_FP: - printf(" (1310 nm FP)\n"); - break; - case CMIS_1310_DFB: - printf(" (1310 nm DFB)\n"); - break; - case CMIS_1550_DFB: - printf(" (1550 nm DFB)\n"); - break; - case CMIS_1310_EML: - printf(" (1310 nm EML)\n"); - break; - case CMIS_1550_EML: - printf(" (1550 nm EML)\n"); - break; - case CMIS_OTHERS: - printf(" (Others/Undefined)\n"); - break; - case CMIS_1490_DFB: - printf(" (1490 nm DFB)\n"); - break; - case CMIS_COPPER_UNEQUAL: - printf("%s unequalized)\n", cc); - break; - case CMIS_COPPER_PASS_EQUAL: - printf("%s passive equalized)\n", cc); - break; - case CMIS_COPPER_NF_EQUAL: - printf("%s near and far end limiting active equalizers)\n", cc); - break; - case CMIS_COPPER_F_EQUAL: - printf("%s far end limiting active equalizers)\n", cc); - break; - case CMIS_COPPER_N_EQUAL: - printf("%s near end limiting active equalizers)\n", cc); - break; - case CMIS_COPPER_LINEAR_EQUAL: - printf("%s linear active equalizers)\n", cc); - break; - } + module_show_mit_compliance(value); - if (map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET] >= CMIS_COPPER_UNEQUAL) { + if (value >= CMIS_COPPER_UNEQUAL) { printf("\t%-41s : %udb\n", "Attenuation at 5GHz", map->page_00h[CMIS_COPPER_ATT_5GHZ]); printf("\t%-41s : %udb\n", "Attenuation at 7GHz", @@ -403,14 +277,14 @@ static void cmis_show_link_len(const struct cmis_memory_map *map) cmis_print_smf_cbl_len(map); if (!map->page_01h) return; - sff_show_value_with_unit(map->page_01h, CMIS_OM5_LEN_OFFSET, - "Length (OM5)", 2, "m"); - sff_show_value_with_unit(map->page_01h, CMIS_OM4_LEN_OFFSET, - "Length (OM4)", 2, "m"); - sff_show_value_with_unit(map->page_01h, CMIS_OM3_LEN_OFFSET, - "Length (OM3 50/125um)", 2, "m"); - sff_show_value_with_unit(map->page_01h, CMIS_OM2_LEN_OFFSET, - "Length (OM2 50/125um)", 1, "m"); + module_show_value_with_unit(map->page_01h, CMIS_OM5_LEN_OFFSET, + "Length (OM5)", 2, "m"); + module_show_value_with_unit(map->page_01h, CMIS_OM4_LEN_OFFSET, + "Length (OM4)", 2, "m"); + module_show_value_with_unit(map->page_01h, CMIS_OM3_LEN_OFFSET, + "Length (OM3 50/125um)", 2, "m"); + module_show_value_with_unit(map->page_01h, CMIS_OM2_LEN_OFFSET, + "Length (OM2 50/125um)", 1, "m"); } /** @@ -422,22 +296,22 @@ static void cmis_show_vendor_info(const struct cmis_memory_map *map) { const char *clei; - sff_show_ascii(map->page_00h, CMIS_VENDOR_NAME_START_OFFSET, - CMIS_VENDOR_NAME_END_OFFSET, "Vendor name"); + module_show_ascii(map->page_00h, CMIS_VENDOR_NAME_START_OFFSET, + CMIS_VENDOR_NAME_END_OFFSET, "Vendor name"); cmis_show_oui(map); - sff_show_ascii(map->page_00h, CMIS_VENDOR_PN_START_OFFSET, - CMIS_VENDOR_PN_END_OFFSET, "Vendor PN"); - sff_show_ascii(map->page_00h, CMIS_VENDOR_REV_START_OFFSET, - CMIS_VENDOR_REV_END_OFFSET, "Vendor rev"); - sff_show_ascii(map->page_00h, CMIS_VENDOR_SN_START_OFFSET, - CMIS_VENDOR_SN_END_OFFSET, "Vendor SN"); - sff_show_ascii(map->page_00h, CMIS_DATE_YEAR_OFFSET, - CMIS_DATE_VENDOR_LOT_OFFSET + 1, "Date code"); + module_show_ascii(map->page_00h, CMIS_VENDOR_PN_START_OFFSET, + CMIS_VENDOR_PN_END_OFFSET, "Vendor PN"); + module_show_ascii(map->page_00h, CMIS_VENDOR_REV_START_OFFSET, + CMIS_VENDOR_REV_END_OFFSET, "Vendor rev"); + module_show_ascii(map->page_00h, CMIS_VENDOR_SN_START_OFFSET, + CMIS_VENDOR_SN_END_OFFSET, "Vendor SN"); + module_show_ascii(map->page_00h, CMIS_DATE_YEAR_OFFSET, + CMIS_DATE_VENDOR_LOT_OFFSET + 1, "Date code"); clei = (const char *)(map->page_00h + CMIS_CLEI_START_OFFSET); if (*clei && strncmp(clei, CMIS_CLEI_BLANK, CMIS_CLEI_LEN)) - sff_show_ascii(map->page_00h, CMIS_CLEI_START_OFFSET, - CMIS_CLEI_END_OFFSET, "CLEI code"); + module_show_ascii(map->page_00h, CMIS_CLEI_START_OFFSET, + CMIS_CLEI_END_OFFSET, "CLEI code"); } /* Print the current Module State. Relevant documents: @@ -670,15 +544,6 @@ static void cmis_parse_dom(const struct cmis_memory_map *map, cmis_parse_dom_chan_lvl_thresh(map, sd); } -/* Print module-level monitoring values. Relevant documents: - * [1] CMIS Rev. 5, page 110, section 8.2.5, Table 8-9 - */ -static void cmis_show_dom_mod_lvl_monitors(const struct sff_diags *sd) -{ - PRINT_TEMP("Module temperature", sd->sfp_temp[MCURR]); - PRINT_VCC("Module voltage", sd->sfp_voltage[MCURR]); -} - /* Print channel Tx laser bias current. Relevant documents: * [1] CMIS Rev. 5, page 165, section 8.9.4, Table 8-79 */ @@ -806,10 +671,11 @@ static void cmis_show_dom_mod_lvl_flags(const struct cmis_memory_map *map) { int i; - for (i = 0; cmis_aw_mod_flags[i].str; i++) { - printf("\t%-41s : %s\n", cmis_aw_mod_flags[i].str, - map->lower_memory[cmis_aw_mod_flags[i].offset] & - cmis_aw_mod_flags[i].value ? "On" : "Off"); + for (i = 0; module_aw_mod_flags[i].str; i++) { + if (module_aw_mod_flags[i].type == MODULE_TYPE_CMIS) + printf("\t%-41s : %s\n", module_aw_mod_flags[i].str, + map->lower_memory[module_aw_mod_flags[i].offset] & + module_aw_mod_flags[i].value ? "On" : "Off"); } } @@ -823,16 +689,16 @@ static void cmis_show_dom_chan_lvl_flags_chan(const struct cmis_memory_map *map, const __u8 *page_11h = map->upper_memory[bank][0x11]; int i; - for (i = 0; cmis_aw_chan_flags[i].fmt_str; i++) { + for (i = 0; module_aw_chan_flags[i].fmt_str; i++) { char str[80]; - if (!(map->page_01h[cmis_aw_chan_flags[i].adver_offset] & - cmis_aw_chan_flags[i].adver_value)) + if (!(map->page_01h[module_aw_chan_flags[i].adver_offset] & + module_aw_chan_flags[i].adver_value)) continue; - snprintf(str, 80, cmis_aw_chan_flags[i].fmt_str, chan + 1); + snprintf(str, 80, module_aw_chan_flags[i].fmt_str, chan + 1); printf("\t%-41s : %s\n", str, - page_11h[cmis_aw_chan_flags[i].offset] & chan ? + page_11h[module_aw_chan_flags[i].offset] & chan ? "On" : "Off"); } } @@ -876,7 +742,7 @@ static void cmis_show_dom(const struct cmis_memory_map *map) cmis_parse_dom(map, &sd); - cmis_show_dom_mod_lvl_monitors(&sd); + module_show_dom_mod_lvl_monitors(&sd); cmis_show_dom_chan_lvl_monitors(map, &sd); cmis_show_dom_mod_lvl_flags(map); cmis_show_dom_chan_lvl_flags(map); diff --git a/cmis.h b/cmis.h index cee2a38..007632a 100644 --- a/cmis.h +++ b/cmis.h @@ -16,18 +16,6 @@ #define CMIS_MODULE_STATE_MODULE_PWR_DN 0x04 #define CMIS_MODULE_STATE_MODULE_FAULT 0x05 -/* Module Flags (Page 0) */ -#define CMIS_VCC_AW_OFFSET 0x09 -#define CMIS_VCC_LWARN_STATUS 0x80 -#define CMIS_VCC_HWARN_STATUS 0x40 -#define CMIS_VCC_LALARM_STATUS 0x20 -#define CMIS_VCC_HALARM_STATUS 0x10 -#define CMIS_TEMP_AW_OFFSET 0x09 -#define CMIS_TEMP_LWARN_STATUS 0x08 -#define CMIS_TEMP_HWARN_STATUS 0x04 -#define CMIS_TEMP_LALARM_STATUS 0x02 -#define CMIS_TEMP_HALARM_STATUS 0x01 - #define CMIS_MODULE_TYPE_OFFSET 0x55 #define CMIS_MT_MMF 0x01 #define CMIS_MT_SMF 0x02 @@ -115,22 +103,6 @@ /* Media interface technology */ #define CMIS_MEDIA_INTF_TECH_OFFSET 0xD4 -#define CMIS_850_VCSEL 0x00 -#define CMIS_1310_VCSEL 0x01 -#define CMIS_1550_VCSEL 0x02 -#define CMIS_1310_FP 0x03 -#define CMIS_1310_DFB 0x04 -#define CMIS_1550_DFB 0x05 -#define CMIS_1310_EML 0x06 -#define CMIS_1550_EML 0x07 -#define CMIS_OTHERS 0x08 -#define CMIS_1490_DFB 0x09 -#define CMIS_COPPER_UNEQUAL 0x0A -#define CMIS_COPPER_PASS_EQUAL 0x0B -#define CMIS_COPPER_NF_EQUAL 0x0C -#define CMIS_COPPER_F_EQUAL 0x0D -#define CMIS_COPPER_N_EQUAL 0x0E -#define CMIS_COPPER_LINEAR_EQUAL 0x0F /*----------------------------------------------------------------------- * Upper Memory Page 0x01: contains advertising fields that define properties @@ -178,10 +150,6 @@ #define CMIS_DIAG_FL_RX_LOS (1 << 1) /* Supported Monitors Advertisement (Page 1) */ -#define CMIS_DIAG_CHAN_ADVER_OFFSET 0xA0 -#define CMIS_TX_BIAS_MON_MASK 0x01 -#define CMIS_TX_PWR_MON_MASK 0x02 -#define CMIS_RX_PWR_MON_MASK 0x04 #define CMIS_TX_BIAS_MUL_MASK 0x18 #define CMIS_TX_BIAS_MUL_1 0x00 #define CMIS_TX_BIAS_MUL_2 0x08 @@ -231,39 +199,6 @@ #define CMIS_RX_PWR_HWARN_OFFSET 0xC4 #define CMIS_RX_PWR_LWARN_OFFSET 0xC6 -/*----------------------------------------------------------------------- - * Upper Memory Page 0x11: Optional Page that contains lane dynamic status - * bytes. - */ - -/* Media Lane-Specific Flags (Page 0x11) */ -#define CMIS_TX_FAIL_OFFSET 0x87 -#define CMIS_TX_LOS_OFFSET 0x88 -#define CMIS_TX_LOL_OFFSET 0x89 -#define CMIS_TX_EQ_FAIL_OFFSET 0x8a -#define CMIS_TX_PWR_AW_HALARM_OFFSET 0x8B -#define CMIS_TX_PWR_AW_LALARM_OFFSET 0x8C -#define CMIS_TX_PWR_AW_HWARN_OFFSET 0x8D -#define CMIS_TX_PWR_AW_LWARN_OFFSET 0x8E -#define CMIS_TX_BIAS_AW_HALARM_OFFSET 0x8F -#define CMIS_TX_BIAS_AW_LALARM_OFFSET 0x90 -#define CMIS_TX_BIAS_AW_HWARN_OFFSET 0x91 -#define CMIS_TX_BIAS_AW_LWARN_OFFSET 0x92 -#define CMIS_RX_LOS_OFFSET 0x93 -#define CMIS_RX_LOL_OFFSET 0x94 -#define CMIS_RX_PWR_AW_HALARM_OFFSET 0x95 -#define CMIS_RX_PWR_AW_LALARM_OFFSET 0x96 -#define CMIS_RX_PWR_AW_HWARN_OFFSET 0x97 -#define CMIS_RX_PWR_AW_LWARN_OFFSET 0x98 - -/* Media Lane-Specific Monitors (Page 0x11) */ -#define CMIS_TX_PWR_OFFSET 0x9A -#define CMIS_TX_BIAS_OFFSET 0xAA -#define CMIS_RX_PWR_OFFSET 0xBA - -#define YESNO(x) (((x) != 0) ? "Yes" : "No") -#define ONOFF(x) (((x) != 0) ? "On" : "Off") - void cmis_show_all_ioctl(const __u8 *id); int cmis_show_all_nl(struct cmd_context *ctx); diff --git a/module-common.c b/module-common.c new file mode 100644 index 0000000..ec61b1e --- /dev/null +++ b/module-common.c @@ -0,0 +1,506 @@ +/* + * module-common.c: Implements common utilities across CMIS, SFF-8436/8636 + * and SFF-8472/8079. + */ + +#include +#include +#include "module-common.h" + +const struct module_aw_mod module_aw_mod_flags[] = { + { MODULE_TYPE_CMIS, "Module temperature high alarm", + CMIS_TEMP_AW_OFFSET, CMIS_TEMP_HALARM_STATUS }, + { MODULE_TYPE_CMIS, "Module temperature low alarm", + CMIS_TEMP_AW_OFFSET, CMIS_TEMP_LALARM_STATUS }, + { MODULE_TYPE_CMIS, "Module temperature high warning", + CMIS_TEMP_AW_OFFSET, CMIS_TEMP_HWARN_STATUS }, + { MODULE_TYPE_CMIS, "Module temperature low warning", + CMIS_TEMP_AW_OFFSET, CMIS_TEMP_LWARN_STATUS }, + + { MODULE_TYPE_CMIS, "Module voltage high alarm", + CMIS_VCC_AW_OFFSET, CMIS_VCC_HALARM_STATUS }, + { MODULE_TYPE_CMIS, "Module voltage low alarm", + CMIS_VCC_AW_OFFSET, CMIS_VCC_LALARM_STATUS }, + { MODULE_TYPE_CMIS, "Module voltage high warning", + CMIS_VCC_AW_OFFSET, CMIS_VCC_HWARN_STATUS }, + { MODULE_TYPE_CMIS, "Module voltage low warning", + CMIS_VCC_AW_OFFSET, CMIS_VCC_LWARN_STATUS }, + + { MODULE_TYPE_SFF8636, "Module temperature high alarm", + SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_HALARM_STATUS) }, + { MODULE_TYPE_SFF8636, "Module temperature low alarm", + SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_LALARM_STATUS) }, + { MODULE_TYPE_SFF8636, "Module temperature high warning", + SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_HWARN_STATUS) }, + { MODULE_TYPE_SFF8636, "Module temperature low warning", + SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_LWARN_STATUS) }, + + { MODULE_TYPE_SFF8636, "Module voltage high alarm", + SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_HALARM_STATUS) }, + { MODULE_TYPE_SFF8636, "Module voltage low alarm", + SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_LALARM_STATUS) }, + { MODULE_TYPE_SFF8636, "Module voltage high warning", + SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_HWARN_STATUS) }, + { MODULE_TYPE_SFF8636, "Module voltage low warning", + SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_LWARN_STATUS) }, + + { 0, NULL, 0, 0 }, +}; + +const struct module_aw_chan module_aw_chan_flags[] = { + { MODULE_TYPE_CMIS, "Laser bias current high alarm", + CMIS_TX_BIAS_AW_HALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_BIAS_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser bias current low alarm", + CMIS_TX_BIAS_AW_LALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_BIAS_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser bias current high warning", + CMIS_TX_BIAS_AW_HWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_BIAS_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser bias current low warning", + CMIS_TX_BIAS_AW_LWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_BIAS_MON_MASK }, + + { MODULE_TYPE_CMIS, "Laser tx power high alarm", + CMIS_TX_PWR_AW_HALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser tx power low alarm", + CMIS_TX_PWR_AW_LALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser tx power high warning", + CMIS_TX_PWR_AW_HWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser tx power low warning", + CMIS_TX_PWR_AW_LWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_TX_PWR_MON_MASK }, + + { MODULE_TYPE_CMIS, "Laser rx power high alarm", + CMIS_RX_PWR_AW_HALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_RX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser rx power low alarm", + CMIS_RX_PWR_AW_LALARM_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_RX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser rx power high warning", + CMIS_RX_PWR_AW_HWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_RX_PWR_MON_MASK }, + { MODULE_TYPE_CMIS, "Laser rx power low warning", + CMIS_RX_PWR_AW_LWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, + CMIS_RX_PWR_MON_MASK }, + + { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 1)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 1)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0,(SFF8636_TX_BIAS_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 1)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 1)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 2)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 2)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 2)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 2)", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 3)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 3)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 3)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 3)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 4)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 4)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 4)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 4)", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 1)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 1)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 1)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 1)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 2)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 2)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 2)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 2)", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 3)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 3)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 3)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 3)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 4)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 4)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 4)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 4)", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 1)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 1)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 1)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 1)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 2)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 2)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 2)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 2)", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 3)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 3)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 3)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 3)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LWARN) }, + + { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 4)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_HALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 4)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 4)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 4)", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_LWARN) }, + + { 0, NULL, 0, 0, 0 }, +}; + +void module_show_value_with_unit(const __u8 *id, unsigned int reg, + const char *name, unsigned int mult, + const char *unit) +{ + unsigned int val = id[reg]; + + printf("\t%-41s : %u%s\n", name, val * mult, unit); +} + +void module_show_ascii(const __u8 *id, unsigned int first_reg, + unsigned int last_reg, const char *name) +{ + unsigned int reg, val; + + printf("\t%-41s : ", name); + while (first_reg <= last_reg && id[last_reg] == ' ') + last_reg--; + for (reg = first_reg; reg <= last_reg; reg++) { + val = id[reg]; + putchar(((val >= 32) && (val <= 126)) ? val : '_'); + } + printf("\n"); +} + +void module_show_lane_status(const char *name, unsigned int lane_cnt, + const char *yes, const char *no, + unsigned int value) +{ + printf("\t%-41s : ", name); + if (!value) { + printf("None\n"); + return; + } + + printf("["); + while (lane_cnt--) { + printf(" %s%c", value & 1 ? yes : no, lane_cnt ? ',': ' '); + value >>= 1; + } + printf("]\n"); +} + +void module_show_oui(const __u8 *id, int id_offset) +{ + printf("\t%-41s : %02x:%02x:%02x\n", "Vendor OUI", + id[id_offset], id[(id_offset) + 1], + id[(id_offset) + 2]); +} + +void module_show_identifier(const __u8 *id, int id_offset) +{ + printf("\t%-41s : 0x%02x", "Identifier", id[id_offset]); + switch (id[id_offset]) { + case MODULE_ID_UNKNOWN: + printf(" (no module present, unknown, or unspecified)\n"); + break; + case MODULE_ID_GBIC: + printf(" (GBIC)\n"); + break; + case MODULE_ID_SOLDERED_MODULE: + printf(" (module soldered to motherboard)\n"); + break; + case MODULE_ID_SFP: + printf(" (SFP)\n"); + break; + case MODULE_ID_300_PIN_XBI: + printf(" (300 pin XBI)\n"); + break; + case MODULE_ID_XENPAK: + printf(" (XENPAK)\n"); + break; + case MODULE_ID_XFP: + printf(" (XFP)\n"); + break; + case MODULE_ID_XFF: + printf(" (XFF)\n"); + break; + case MODULE_ID_XFP_E: + printf(" (XFP-E)\n"); + break; + case MODULE_ID_XPAK: + printf(" (XPAK)\n"); + break; + case MODULE_ID_X2: + printf(" (X2)\n"); + break; + case MODULE_ID_DWDM_SFP: + printf(" (DWDM-SFP)\n"); + break; + case MODULE_ID_QSFP: + printf(" (QSFP)\n"); + break; + case MODULE_ID_QSFP_PLUS: + printf(" (QSFP+)\n"); + break; + case MODULE_ID_CXP: + printf(" (CXP)\n"); + break; + case MODULE_ID_HD4X: + printf(" (Shielded Mini Multilane HD 4X)\n"); + break; + case MODULE_ID_HD8X: + printf(" (Shielded Mini Multilane HD 8X)\n"); + break; + case MODULE_ID_QSFP28: + printf(" (QSFP28)\n"); + break; + case MODULE_ID_CXP2: + printf(" (CXP2/CXP28)\n"); + break; + case MODULE_ID_CDFP: + printf(" (CDFP Style 1/Style 2)\n"); + break; + case MODULE_ID_HD4X_FANOUT: + printf(" (Shielded Mini Multilane HD 4X Fanout Cable)\n"); + break; + case MODULE_ID_HD8X_FANOUT: + printf(" (Shielded Mini Multilane HD 8X Fanout Cable)\n"); + break; + case MODULE_ID_CDFP_S3: + printf(" (CDFP Style 3)\n"); + break; + case MODULE_ID_MICRO_QSFP: + printf(" (microQSFP)\n"); + break; + case MODULE_ID_QSFP_DD: + printf(" (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))\n"); + break; + case MODULE_ID_OSFP: + printf(" (OSFP 8X Pluggable Transceiver)\n"); + break; + case MODULE_ID_DSFP: + printf(" (DSFP Dual Small Form Factor Pluggable Transceiver)\n"); + break; + case MODULE_ID_QSFP_PLUS_CMIS: + printf(" (QSFP+ or later with Common Management Interface Specification (CMIS))\n"); + break; + case MODULE_ID_SFP_DD_CMIS: + printf(" (SFP-DD Double Density 2X Pluggable Transceiver with Common Management Interface Specification (CMIS))\n"); + break; + case MODULE_ID_SFP_PLUS_CMIS: + printf(" (SFP+ and later with Common Management Interface Specification (CMIS))\n"); + break; + default: + printf(" (reserved or unknown)\n"); + break; + } +} + +void module_show_connector(const __u8 *id, int ctor_offset) +{ + printf("\t%-41s : 0x%02x", "Connector", id[ctor_offset]); + switch (id[ctor_offset]) { + case MODULE_CTOR_UNKNOWN: + printf(" (unknown or unspecified)\n"); + break; + case MODULE_CTOR_SC: + printf(" (SC)\n"); + break; + case MODULE_CTOR_FC_STYLE_1: + printf(" (Fibre Channel Style 1 copper)\n"); + break; + case MODULE_CTOR_FC_STYLE_2: + printf(" (Fibre Channel Style 2 copper)\n"); + break; + case MODULE_CTOR_BNC_TNC: + printf(" (BNC/TNC)\n"); + break; + case MODULE_CTOR_FC_COAX: + printf(" (Fibre Channel coaxial headers)\n"); + break; + case MODULE_CTOR_FIBER_JACK: + printf(" (FibreJack)\n"); + break; + case MODULE_CTOR_LC: + printf(" (LC)\n"); + break; + case MODULE_CTOR_MT_RJ: + printf(" (MT-RJ)\n"); + break; + case MODULE_CTOR_MU: + printf(" (MU)\n"); + break; + case MODULE_CTOR_SG: + printf(" (SG)\n"); + break; + case MODULE_CTOR_OPT_PT: + printf(" (Optical pigtail)\n"); + break; + case MODULE_CTOR_MPO: + printf(" (MPO Parallel Optic)\n"); + break; + case MODULE_CTOR_MPO_2: + printf(" (MPO Parallel Optic - 2x16)\n"); + break; + case MODULE_CTOR_HSDC_II: + printf(" (HSSDC II)\n"); + break; + case MODULE_CTOR_COPPER_PT: + printf(" (Copper pigtail)\n"); + break; + case MODULE_CTOR_RJ45: + printf(" (RJ45)\n"); + break; + case MODULE_CTOR_NO_SEPARABLE: + printf(" (No separable connector)\n"); + break; + case MODULE_CTOR_MXC_2x16: + printf(" (MXC 2x16)\n"); + break; + case MODULE_CTOR_CS_OPTICAL: + printf(" (CS optical connector)\n"); + break; + case MODULE_CTOR_CS_OPTICAL_MINI: + printf(" (Mini CS optical connector)\n"); + break; + case MODULE_CTOR_MPO_2X12: + printf(" (MPO 2x12)\n"); + break; + case MODULE_CTOR_MPO_1X16: + printf(" (MPO 1x16)\n"); + break; + default: + printf(" (reserved or unknown)\n"); + break; + } +} + +void module_show_mit_compliance(u16 value) +{ + static const char *cc = " (Copper cable,"; + + printf("\t%-41s : 0x%02x", "Transmitter technology", value); + + switch (value) { + case MODULE_850_VCSEL: + printf(" (850 nm VCSEL)\n"); + break; + case CMIS_1310_VCSEL: + case SFF8636_TRANS_1310_VCSEL: + printf(" (1310 nm VCSEL)\n"); + break; + case CMIS_1550_VCSEL: + case SFF8636_TRANS_1550_VCSEL: + printf(" (1550 nm VCSEL)\n"); + break; + case CMIS_1310_FP: + case SFF8636_TRANS_1310_FP: + printf(" (1310 nm FP)\n"); + break; + case CMIS_1310_DFB: + case SFF8636_TRANS_1310_DFB: + printf(" (1310 nm DFB)\n"); + break; + case CMIS_1550_DFB: + case SFF8636_TRANS_1550_DFB: + printf(" (1550 nm DFB)\n"); + break; + case CMIS_1310_EML: + case SFF8636_TRANS_1310_EML: + printf(" (1310 nm EML)\n"); + break; + case CMIS_1550_EML: + case SFF8636_TRANS_1550_EML: + printf(" (1550 nm EML)\n"); + break; + case CMIS_OTHERS: + case SFF8636_TRANS_OTHERS: + printf(" (Others/Undefined)\n"); + break; + case CMIS_1490_DFB: + case SFF8636_TRANS_1490_DFB: + printf(" (1490 nm DFB)\n"); + break; + case CMIS_COPPER_UNEQUAL: + case SFF8636_TRANS_COPPER_PAS_UNEQUAL: + printf("%s unequalized)\n", cc); + break; + case CMIS_COPPER_PASS_EQUAL: + case SFF8636_TRANS_COPPER_PAS_EQUAL: + printf("%s passive equalized)\n", cc); + break; + case CMIS_COPPER_NF_EQUAL: + case SFF8636_TRANS_COPPER_LNR_FAR_EQUAL: + printf("%s near and far end limiting active equalizers)\n", cc); + break; + case CMIS_COPPER_F_EQUAL: + case SFF8636_TRANS_COPPER_FAR_EQUAL: + printf("%s far end limiting active equalizers)\n", cc); + break; + case CMIS_COPPER_N_EQUAL: + case SFF8636_TRANS_COPPER_NEAR_EQUAL: + printf("%s near end limiting active equalizers)\n", cc); + break; + case CMIS_COPPER_LINEAR_EQUAL: + case SFF8636_TRANS_COPPER_LNR_EQUAL: + printf("%s linear active equalizers)\n", cc); + break; + } +} + +void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd) +{ + PRINT_TEMP("Module temperature", sd->sfp_temp[MCURR]); + PRINT_VCC("Module voltage", sd->sfp_voltage[MCURR]); +} diff --git a/module-common.h b/module-common.h new file mode 100644 index 0000000..8c34779 --- /dev/null +++ b/module-common.h @@ -0,0 +1,281 @@ +/* + * module-common.h: Declares common utilities across CMIS, SFF-8436/8636 + * and SFF-8472/8079. + */ + +#ifndef MODULE_COMMON_H__ +#define MODULE_COMMON_H__ + +#include +#include "internal.h" +#include "sff-common.h" + +enum module_type { + MODULE_TYPE_SFF8636, + MODULE_TYPE_CMIS, +}; + +#define MODULE_ID_OFFSET 0x00 +#define MODULE_ID_UNKNOWN 0x00 +#define MODULE_ID_GBIC 0x01 +#define MODULE_ID_SOLDERED_MODULE 0x02 +#define MODULE_ID_SFP 0x03 +#define MODULE_ID_300_PIN_XBI 0x04 +#define MODULE_ID_XENPAK 0x05 +#define MODULE_ID_XFP 0x06 +#define MODULE_ID_XFF 0x07 +#define MODULE_ID_XFP_E 0x08 +#define MODULE_ID_XPAK 0x09 +#define MODULE_ID_X2 0x0A +#define MODULE_ID_DWDM_SFP 0x0B +#define MODULE_ID_QSFP 0x0C +#define MODULE_ID_QSFP_PLUS 0x0D +#define MODULE_ID_CXP 0x0E +#define MODULE_ID_HD4X 0x0F +#define MODULE_ID_HD8X 0x10 +#define MODULE_ID_QSFP28 0x11 +#define MODULE_ID_CXP2 0x12 +#define MODULE_ID_CDFP 0x13 +#define MODULE_ID_HD4X_FANOUT 0x14 +#define MODULE_ID_HD8X_FANOUT 0x15 +#define MODULE_ID_CDFP_S3 0x16 +#define MODULE_ID_MICRO_QSFP 0x17 +#define MODULE_ID_QSFP_DD 0x18 +#define MODULE_ID_OSFP 0x19 +#define MODULE_ID_DSFP 0x1B +#define MODULE_ID_QSFP_PLUS_CMIS 0x1E +#define MODULE_ID_SFP_DD_CMIS 0x1F +#define MODULE_ID_SFP_PLUS_CMIS 0x20 +#define MODULE_ID_LAST MODULE_ID_SFP_PLUS_CMIS +#define MODULE_ID_UNALLOCATED_LAST 0x7F +#define MODULE_ID_VENDOR_START 0x80 +#define MODULE_ID_VENDOR_LAST 0xFF + +#define MODULE_CTOR_UNKNOWN 0x00 +#define MODULE_CTOR_SC 0x01 +#define MODULE_CTOR_FC_STYLE_1 0x02 +#define MODULE_CTOR_FC_STYLE_2 0x03 +#define MODULE_CTOR_BNC_TNC 0x04 +#define MODULE_CTOR_FC_COAX 0x05 +#define MODULE_CTOR_FIBER_JACK 0x06 +#define MODULE_CTOR_LC 0x07 +#define MODULE_CTOR_MT_RJ 0x08 +#define MODULE_CTOR_MU 0x09 +#define MODULE_CTOR_SG 0x0A +#define MODULE_CTOR_OPT_PT 0x0B +#define MODULE_CTOR_MPO 0x0C +#define MODULE_CTOR_MPO_2 0x0D +/* 0E-1Fh --- Reserved */ +#define MODULE_CTOR_HSDC_II 0x20 +#define MODULE_CTOR_COPPER_PT 0x21 +#define MODULE_CTOR_RJ45 0x22 +#define MODULE_CTOR_NO_SEPARABLE 0x23 +#define MODULE_CTOR_MXC_2x16 0x24 +#define MODULE_CTOR_CS_OPTICAL 0x25 +#define MODULE_CTOR_CS_OPTICAL_MINI 0x26 +#define MODULE_CTOR_MPO_2X12 0x27 +#define MODULE_CTOR_MPO_1X16 0x28 +#define MODULE_CTOR_LAST MODULE_CTOR_MPO_1X16 + +#define MODULE_CTOR_NO_SEP_QSFP_DD 0x6F +#define MODULE_CTOR_UNALLOCATED_LAST 0x7F +#define MODULE_CTOR_VENDOR_START 0x80 +#define MODULE_CTOR_VENDOR_LAST 0xFF + +/* Transmitter Technology */ +#define MODULE_850_VCSEL 0x00 + +/* SFF8636 */ +#define SFF8636_TRANS_TECH_MASK 0xF0 +#define SFF8636_TRANS_COPPER_LNR_EQUAL (15 << 4) +#define SFF8636_TRANS_COPPER_NEAR_EQUAL (14 << 4) +#define SFF8636_TRANS_COPPER_FAR_EQUAL (13 << 4) +#define SFF8636_TRANS_COPPER_LNR_FAR_EQUAL (12 << 4) +#define SFF8636_TRANS_COPPER_PAS_EQUAL (11 << 4) +#define SFF8636_TRANS_COPPER_PAS_UNEQUAL (10 << 4) +#define SFF8636_TRANS_1490_DFB (9 << 4) +#define SFF8636_TRANS_OTHERS (8 << 4) +#define SFF8636_TRANS_1550_EML (7 << 4) +#define SFF8636_TRANS_1310_EML (6 << 4) +#define SFF8636_TRANS_1550_DFB (5 << 4) +#define SFF8636_TRANS_1310_DFB (4 << 4) +#define SFF8636_TRANS_1310_FP (3 << 4) +#define SFF8636_TRANS_1550_VCSEL (2 << 4) +#define SFF8636_TRANS_1310_VCSEL (1 << 4) + +/* CMIS */ +#define CMIS_1310_VCSEL 0x01 +#define CMIS_1550_VCSEL 0x02 +#define CMIS_1310_FP 0x03 +#define CMIS_1310_DFB 0x04 +#define CMIS_1550_DFB 0x05 +#define CMIS_1310_EML 0x06 +#define CMIS_1550_EML 0x07 +#define CMIS_OTHERS 0x08 +#define CMIS_1490_DFB 0x09 +#define CMIS_COPPER_UNEQUAL 0x0A +#define CMIS_COPPER_PASS_EQUAL 0x0B +#define CMIS_COPPER_NF_EQUAL 0x0C +#define CMIS_COPPER_F_EQUAL 0x0D +#define CMIS_COPPER_N_EQUAL 0x0E +#define CMIS_COPPER_LINEAR_EQUAL 0x0F + +/* Module Flags (Page 0) */ +#define CMIS_VCC_AW_OFFSET 0x09 +#define CMIS_VCC_LWARN_STATUS 0x80 +#define CMIS_VCC_HWARN_STATUS 0x40 +#define CMIS_VCC_LALARM_STATUS 0x20 +#define CMIS_VCC_HALARM_STATUS 0x10 +#define CMIS_TEMP_AW_OFFSET 0x09 +#define CMIS_TEMP_LWARN_STATUS 0x08 +#define CMIS_TEMP_HWARN_STATUS 0x04 +#define CMIS_TEMP_LALARM_STATUS 0x02 +#define CMIS_TEMP_HALARM_STATUS 0x01 + +/* Supported Monitors Advertisement (Page 1) */ +#define CMIS_DIAG_CHAN_ADVER_OFFSET 0xA0 + +/* Module Monitor Interrupt Flags - 6-8 */ +#define SFF8636_TEMP_AW_OFFSET 0x06 +#define SFF8636_TEMP_HALARM_STATUS (1 << 7) +#define SFF8636_TEMP_LALARM_STATUS (1 << 6) +#define SFF8636_TEMP_HWARN_STATUS (1 << 5) +#define SFF8636_TEMP_LWARN_STATUS (1 << 4) + +#define SFF8636_VCC_AW_OFFSET 0x07 +#define SFF8636_VCC_HALARM_STATUS (1 << 7) +#define SFF8636_VCC_LALARM_STATUS (1 << 6) +#define SFF8636_VCC_HWARN_STATUS (1 << 5) +#define SFF8636_VCC_LWARN_STATUS (1 << 4) + +/* Channel Monitor Interrupt Flags - 9-21 */ +#define SFF8636_RX_PWR_12_AW_OFFSET 0x09 +#define SFF8636_RX_PWR_1_HALARM (1 << 7) +#define SFF8636_RX_PWR_1_LALARM (1 << 6) +#define SFF8636_RX_PWR_1_HWARN (1 << 5) +#define SFF8636_RX_PWR_1_LWARN (1 << 4) +#define SFF8636_RX_PWR_2_HALARM (1 << 3) +#define SFF8636_RX_PWR_2_LALARM (1 << 2) +#define SFF8636_RX_PWR_2_HWARN (1 << 1) +#define SFF8636_RX_PWR_2_LWARN (1 << 0) + +#define SFF8636_RX_PWR_34_AW_OFFSET 0x0A +#define SFF8636_RX_PWR_3_HALARM (1 << 7) +#define SFF8636_RX_PWR_3_LALARM (1 << 6) +#define SFF8636_RX_PWR_3_HWARN (1 << 5) +#define SFF8636_RX_PWR_3_LWARN (1 << 4) +#define SFF8636_RX_PWR_4_HALARM (1 << 3) +#define SFF8636_RX_PWR_4_LALARM (1 << 2) +#define SFF8636_RX_PWR_4_HWARN (1 << 1) +#define SFF8636_RX_PWR_4_LWARN (1 << 0) + +#define SFF8636_TX_BIAS_12_AW_OFFSET 0x0B +#define SFF8636_TX_BIAS_1_HALARM (1 << 7) +#define SFF8636_TX_BIAS_1_LALARM (1 << 6) +#define SFF8636_TX_BIAS_1_HWARN (1 << 5) +#define SFF8636_TX_BIAS_1_LWARN (1 << 4) +#define SFF8636_TX_BIAS_2_HALARM (1 << 3) +#define SFF8636_TX_BIAS_2_LALARM (1 << 2) +#define SFF8636_TX_BIAS_2_HWARN (1 << 1) +#define SFF8636_TX_BIAS_2_LWARN (1 << 0) + +#define SFF8636_TX_BIAS_34_AW_OFFSET 0xC +#define SFF8636_TX_BIAS_3_HALARM (1 << 7) +#define SFF8636_TX_BIAS_3_LALARM (1 << 6) +#define SFF8636_TX_BIAS_3_HWARN (1 << 5) +#define SFF8636_TX_BIAS_3_LWARN (1 << 4) +#define SFF8636_TX_BIAS_4_HALARM (1 << 3) +#define SFF8636_TX_BIAS_4_LALARM (1 << 2) +#define SFF8636_TX_BIAS_4_HWARN (1 << 1) +#define SFF8636_TX_BIAS_4_LWARN (1 << 0) + +#define SFF8636_TX_PWR_12_AW_OFFSET 0x0D +#define SFF8636_TX_PWR_1_HALARM (1 << 7) +#define SFF8636_TX_PWR_1_LALARM (1 << 6) +#define SFF8636_TX_PWR_1_HWARN (1 << 5) +#define SFF8636_TX_PWR_1_LWARN (1 << 4) +#define SFF8636_TX_PWR_2_HALARM (1 << 3) +#define SFF8636_TX_PWR_2_LALARM (1 << 2) +#define SFF8636_TX_PWR_2_HWARN (1 << 1) +#define SFF8636_TX_PWR_2_LWARN (1 << 0) + +#define SFF8636_TX_PWR_34_AW_OFFSET 0x0E +#define SFF8636_TX_PWR_3_HALARM (1 << 7) +#define SFF8636_TX_PWR_3_LALARM (1 << 6) +#define SFF8636_TX_PWR_3_HWARN (1 << 5) +#define SFF8636_TX_PWR_3_LWARN (1 << 4) +#define SFF8636_TX_PWR_4_HALARM (1 << 3) +#define SFF8636_TX_PWR_4_LALARM (1 << 2) +#define SFF8636_TX_PWR_4_HWARN (1 << 1) +#define SFF8636_TX_PWR_4_LWARN (1 << 0) + +/*----------------------------------------------------------------------- + * Upper Memory Page 0x11: Optional Page that contains lane dynamic status + * bytes. + */ + +/* Media Lane-Specific Flags (Page 0x11) */ +#define CMIS_TX_FAIL_OFFSET 0x87 +#define CMIS_TX_LOS_OFFSET 0x88 +#define CMIS_TX_LOL_OFFSET 0x89 +#define CMIS_TX_EQ_FAIL_OFFSET 0x8a +#define CMIS_TX_PWR_AW_HALARM_OFFSET 0x8B +#define CMIS_TX_PWR_AW_LALARM_OFFSET 0x8C +#define CMIS_TX_PWR_AW_HWARN_OFFSET 0x8D +#define CMIS_TX_PWR_AW_LWARN_OFFSET 0x8E +#define CMIS_TX_BIAS_AW_HALARM_OFFSET 0x8F +#define CMIS_TX_BIAS_AW_LALARM_OFFSET 0x90 +#define CMIS_TX_BIAS_AW_HWARN_OFFSET 0x91 +#define CMIS_TX_BIAS_AW_LWARN_OFFSET 0x92 +#define CMIS_RX_LOS_OFFSET 0x93 +#define CMIS_RX_LOL_OFFSET 0x94 +#define CMIS_RX_PWR_AW_HALARM_OFFSET 0x95 +#define CMIS_RX_PWR_AW_LALARM_OFFSET 0x96 +#define CMIS_RX_PWR_AW_HWARN_OFFSET 0x97 +#define CMIS_RX_PWR_AW_LWARN_OFFSET 0x98 + +/* Media Lane-Specific Monitors (Page 0x11) */ +#define CMIS_TX_PWR_OFFSET 0x9A +#define CMIS_TX_BIAS_OFFSET 0xAA +#define CMIS_RX_PWR_OFFSET 0xBA + +#define CMIS_TX_BIAS_MON_MASK 0x01 +#define CMIS_TX_PWR_MON_MASK 0x02 +#define CMIS_RX_PWR_MON_MASK 0x04 + +#define YESNO(x) (((x) != 0) ? "Yes" : "No") +#define ONOFF(x) (((x) != 0) ? "On" : "Off") + +struct module_aw_mod { + enum module_type type; + const char *str; /* Human-readable string, null at the end */ + int offset; + __u8 value; /* Alarm is on if (offset & value) != 0. */ +}; + +struct module_aw_chan { + enum module_type type; + const char *fmt_str; + int offset; + int adver_offset; /* In Page 01h. */ + __u8 adver_value; /* Supported if (offset & value) != 0. */ +}; + +extern const struct module_aw_mod module_aw_mod_flags[]; +extern const struct module_aw_chan module_aw_chan_flags[]; + +void module_show_value_with_unit(const __u8 *id, unsigned int reg, + const char *name, unsigned int mult, + const char *unit); +void module_show_ascii(const __u8 *id, unsigned int first_reg, + unsigned int last_reg, const char *name); +void module_show_lane_status(const char *name, unsigned int lane_cnt, + const char *yes, const char *no, + unsigned int value); +void module_show_oui(const __u8 *id, int id_offset); +void module_show_identifier(const __u8 *id, int id_offset); +void module_show_connector(const __u8 *id, int ctor_offset); +void module_show_mit_compliance(u16 value); +void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd); + +#endif /* MODULE_COMMON_H__ */ diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c index 2b30d04..ce6a7d9 100644 --- a/netlink/module-eeprom.c +++ b/netlink/module-eeprom.c @@ -9,7 +9,7 @@ #include #include -#include "../sff-common.h" +#include "../module-common.h" #include "../qsfp.h" #include "../cmis.h" #include "../internal.h" @@ -225,20 +225,20 @@ static int eeprom_parse(struct cmd_context *ctx) switch (request.data[0]) { #ifdef ETHTOOL_ENABLE_PRETTY_DUMP - case SFF8024_ID_GBIC: - case SFF8024_ID_SOLDERED_MODULE: - case SFF8024_ID_SFP: + case MODULE_ID_GBIC: + case MODULE_ID_SOLDERED_MODULE: + case MODULE_ID_SFP: return sff8079_show_all_nl(ctx); - case SFF8024_ID_QSFP: - case SFF8024_ID_QSFP28: - case SFF8024_ID_QSFP_PLUS: + case MODULE_ID_QSFP: + case MODULE_ID_QSFP28: + case MODULE_ID_QSFP_PLUS: return sff8636_show_all_nl(ctx); - case SFF8024_ID_QSFP_DD: - case SFF8024_ID_OSFP: - case SFF8024_ID_DSFP: - case SFF8024_ID_QSFP_PLUS_CMIS: - case SFF8024_ID_SFP_DD_CMIS: - case SFF8024_ID_SFP_PLUS_CMIS: + case MODULE_ID_QSFP_DD: + case MODULE_ID_OSFP: + case MODULE_ID_DSFP: + case MODULE_ID_QSFP_PLUS_CMIS: + case MODULE_ID_SFP_DD_CMIS: + case MODULE_ID_SFP_PLUS_CMIS: return cmis_show_all_nl(ctx); #endif default: diff --git a/qsfp.c b/qsfp.c index a3a919d..6d774f8 100644 --- a/qsfp.c +++ b/qsfp.c @@ -57,7 +57,7 @@ #include #include #include "internal.h" -#include "sff-common.h" +#include "module-common.h" #include "qsfp.h" #include "cmis.h" #include "netlink/extapi.h" @@ -75,143 +75,9 @@ struct sff8636_memory_map { #define MAX_DESC_SIZE 42 -static struct sff8636_aw_flags { - const char *str; /* Human-readable string, null at the end */ - int offset; - __u8 value; /* Alarm is on if (offset & value) != 0. */ -} sff8636_aw_flags[] = { - { "Laser bias current high alarm (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_1_HALARM) }, - { "Laser bias current low alarm (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_1_LALARM) }, - { "Laser bias current high warning (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_1_HWARN) }, - { "Laser bias current low warning (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_1_LWARN) }, - - { "Laser bias current high alarm (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_2_HALARM) }, - { "Laser bias current low alarm (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_2_LALARM) }, - { "Laser bias current high warning (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_2_HWARN) }, - { "Laser bias current low warning (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, (SFF8636_TX_BIAS_2_LWARN) }, - - { "Laser bias current high alarm (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_3_HALARM) }, - { "Laser bias current low alarm (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_3_LALARM) }, - { "Laser bias current high warning (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_3_HWARN) }, - { "Laser bias current low warning (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_3_LWARN) }, - - { "Laser bias current high alarm (Chan 4)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_4_HALARM) }, - { "Laser bias current low alarm (Chan 4)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_4_LALARM) }, - { "Laser bias current high warning (Chan 4)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_4_HWARN) }, - { "Laser bias current low warning (Chan 4)", - SFF8636_TX_BIAS_34_AW_OFFSET, (SFF8636_TX_BIAS_4_LWARN) }, - - { "Module temperature high alarm", - SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_HALARM_STATUS) }, - { "Module temperature low alarm", - SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_LALARM_STATUS) }, - { "Module temperature high warning", - SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_HWARN_STATUS) }, - { "Module temperature low warning", - SFF8636_TEMP_AW_OFFSET, (SFF8636_TEMP_LWARN_STATUS) }, - - { "Module voltage high alarm", - SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_HALARM_STATUS) }, - { "Module voltage low alarm", - SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_LALARM_STATUS) }, - { "Module voltage high warning", - SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_HWARN_STATUS) }, - { "Module voltage low warning", - SFF8636_VCC_AW_OFFSET, (SFF8636_VCC_LWARN_STATUS) }, - - { "Laser tx power high alarm (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_1_HALARM) }, - { "Laser tx power low alarm (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_1_LALARM) }, - { "Laser tx power high warning (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_1_HWARN) }, - { "Laser tx power low warning (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_1_LWARN) }, - - { "Laser tx power high alarm (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_2_HALARM) }, - { "Laser tx power low alarm (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_2_LALARM) }, - { "Laser tx power high warning (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_2_HWARN) }, - { "Laser tx power low warning (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, (SFF8636_TX_PWR_2_LWARN) }, - - { "Laser tx power high alarm (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_3_HALARM) }, - { "Laser tx power low alarm (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_3_LALARM) }, - { "Laser tx power high warning (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_3_HWARN) }, - { "Laser tx power low warning (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_3_LWARN) }, - - { "Laser tx power high alarm (Channel 4)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_4_HALARM) }, - { "Laser tx power low alarm (Channel 4)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_4_LALARM) }, - { "Laser tx power high warning (Channel 4)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_4_HWARN) }, - { "Laser tx power low warning (Channel 4)", - SFF8636_TX_PWR_34_AW_OFFSET, (SFF8636_TX_PWR_4_LWARN) }, - - { "Laser rx power high alarm (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_1_HALARM) }, - { "Laser rx power low alarm (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_1_LALARM) }, - { "Laser rx power high warning (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_1_HWARN) }, - { "Laser rx power low warning (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_1_LWARN) }, - - { "Laser rx power high alarm (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_2_HALARM) }, - { "Laser rx power low alarm (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_2_LALARM) }, - { "Laser rx power high warning (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_2_HWARN) }, - { "Laser rx power low warning (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, (SFF8636_RX_PWR_2_LWARN) }, - - { "Laser rx power high alarm (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_3_HALARM) }, - { "Laser rx power low alarm (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_3_LALARM) }, - { "Laser rx power high warning (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_3_HWARN) }, - { "Laser rx power low warning (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_3_LWARN) }, - - { "Laser rx power high alarm (Channel 4)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_4_HALARM) }, - { "Laser rx power low alarm (Channel 4)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_4_LALARM) }, - { "Laser rx power high warning (Channel 4)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_4_HWARN) }, - { "Laser rx power low warning (Channel 4)", - SFF8636_RX_PWR_34_AW_OFFSET, (SFF8636_RX_PWR_4_LWARN) }, - - { NULL, 0, 0 }, -}; - static void sff8636_show_identifier(const struct sff8636_memory_map *map) { - sff8024_show_identifier(map->lower_memory, SFF8636_ID_OFFSET); + module_show_identifier(map->lower_memory, SFF8636_ID_OFFSET); } static void sff8636_show_ext_identifier(const struct sff8636_memory_map *map) @@ -278,7 +144,7 @@ static void sff8636_show_ext_identifier(const struct sff8636_memory_map *map) static void sff8636_show_connector(const struct sff8636_memory_map *map) { - sff8024_show_connector(map->page_00h, SFF8636_CTOR_OFFSET); + module_show_connector(map->page_00h, SFF8636_CTOR_OFFSET); } static void sff8636_show_transceiver(const struct sff8636_memory_map *map) @@ -624,64 +490,12 @@ static void sff8636_show_rate_identifier(const struct sff8636_memory_map *map) static void sff8636_show_wavelength_or_copper_compliance(const struct sff8636_memory_map *map) { - printf("\t%-41s : 0x%02x", "Transmitter technology", - map->page_00h[SFF8636_DEVICE_TECH_OFFSET] & - SFF8636_TRANS_TECH_MASK); - - switch (map->page_00h[SFF8636_DEVICE_TECH_OFFSET] & - SFF8636_TRANS_TECH_MASK) { - case SFF8636_TRANS_850_VCSEL: - printf(" (850 nm VCSEL)\n"); - break; - case SFF8636_TRANS_1310_VCSEL: - printf(" (1310 nm VCSEL)\n"); - break; - case SFF8636_TRANS_1550_VCSEL: - printf(" (1550 nm VCSEL)\n"); - break; - case SFF8636_TRANS_1310_FP: - printf(" (1310 nm FP)\n"); - break; - case SFF8636_TRANS_1310_DFB: - printf(" (1310 nm DFB)\n"); - break; - case SFF8636_TRANS_1550_DFB: - printf(" (1550 nm DFB)\n"); - break; - case SFF8636_TRANS_1310_EML: - printf(" (1310 nm EML)\n"); - break; - case SFF8636_TRANS_1550_EML: - printf(" (1550 nm EML)\n"); - break; - case SFF8636_TRANS_OTHERS: - printf(" (Others/Undefined)\n"); - break; - case SFF8636_TRANS_1490_DFB: - printf(" (1490 nm DFB)\n"); - break; - case SFF8636_TRANS_COPPER_PAS_UNEQUAL: - printf(" (Copper cable unequalized)\n"); - break; - case SFF8636_TRANS_COPPER_PAS_EQUAL: - printf(" (Copper cable passive equalized)\n"); - break; - case SFF8636_TRANS_COPPER_LNR_FAR_EQUAL: - printf(" (Copper cable, near and far end limiting active equalizers)\n"); - break; - case SFF8636_TRANS_COPPER_FAR_EQUAL: - printf(" (Copper cable, far end limiting active equalizers)\n"); - break; - case SFF8636_TRANS_COPPER_NEAR_EQUAL: - printf(" (Copper cable, near end limiting active equalizers)\n"); - break; - case SFF8636_TRANS_COPPER_LNR_EQUAL: - printf(" (Copper cable, linear active equalizers)\n"); - break; - } + u16 value = map->page_00h[SFF8636_DEVICE_TECH_OFFSET] & + SFF8636_TRANS_TECH_MASK; - if ((map->page_00h[SFF8636_DEVICE_TECH_OFFSET] & - SFF8636_TRANS_TECH_MASK) >= SFF8636_TRANS_COPPER_PAS_UNEQUAL) { + module_show_mit_compliance(value); + + if (value >= SFF8636_TRANS_COPPER_PAS_UNEQUAL) { printf("\t%-41s : %udb\n", "Attenuation at 2.5GHz", map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET]); printf("\t%-41s : %udb\n", "Attenuation at 5.0GHz", @@ -823,8 +637,7 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) sff8636_dom_parse(map, &sd); - PRINT_TEMP("Module temperature", sd.sfp_temp[MCURR]); - PRINT_VCC("Module voltage", sd.sfp_voltage[MCURR]); + module_show_dom_mod_lvl_monitors(&sd); /* * SFF-8636/8436 spec is not clear whether RX power/ TX bias @@ -862,10 +675,21 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) } if (sd.supports_alarms) { - for (i = 0; sff8636_aw_flags[i].str; ++i) { - printf("\t%-41s : %s\n", sff8636_aw_flags[i].str, - map->lower_memory[sff8636_aw_flags[i].offset] - & sff8636_aw_flags[i].value ? "On" : "Off"); + for (i = 0; module_aw_chan_flags[i].fmt_str; ++i) { + if (module_aw_chan_flags[i].type == MODULE_TYPE_SFF8636) + printf("\t%-41s : %s\n", + module_aw_chan_flags[i].fmt_str, + (map->lower_memory[module_aw_chan_flags[i].offset] + & module_aw_chan_flags[i].adver_value) ? + "On" : "Off"); + } + for (i = 0; module_aw_mod_flags[i].str; ++i) { + if (module_aw_mod_flags[i].type == MODULE_TYPE_SFF8636) + printf("\t%-41s : %s\n", + module_aw_mod_flags[i].str, + (map->lower_memory[module_aw_mod_flags[i].offset] + & module_aw_mod_flags[i].value) ? + "On" : "Off"); } sff_show_thresholds(sd); @@ -879,26 +703,27 @@ static void sff8636_show_signals(const struct sff8636_memory_map *map) /* There appears to be no Rx LOS support bit, use Tx for both */ if (map->page_00h[SFF8636_OPTION_4_OFFSET] & SFF8636_O4_TX_LOS) { v = map->lower_memory[SFF8636_LOS_AW_OFFSET] & 0xf; - sff_show_lane_status("Rx loss of signal", 4, "Yes", "No", v); + module_show_lane_status("Rx loss of signal", 4, "Yes", "No", v); v = map->lower_memory[SFF8636_LOS_AW_OFFSET] >> 4; - sff_show_lane_status("Tx loss of signal", 4, "Yes", "No", v); + module_show_lane_status("Tx loss of signal", 4, "Yes", "No", v); } v = map->lower_memory[SFF8636_LOL_AW_OFFSET] & 0xf; if (map->page_00h[SFF8636_OPTION_3_OFFSET] & SFF8636_O3_RX_LOL) - sff_show_lane_status("Rx loss of lock", 4, "Yes", "No", v); + module_show_lane_status("Rx loss of lock", 4, "Yes", "No", v); v = map->lower_memory[SFF8636_LOL_AW_OFFSET] >> 4; if (map->page_00h[SFF8636_OPTION_3_OFFSET] & SFF8636_O3_TX_LOL) - sff_show_lane_status("Tx loss of lock", 4, "Yes", "No", v); + module_show_lane_status("Tx loss of lock", 4, "Yes", "No", v); v = map->lower_memory[SFF8636_FAULT_AW_OFFSET] & 0xf; if (map->page_00h[SFF8636_OPTION_4_OFFSET] & SFF8636_O4_TX_FAULT) - sff_show_lane_status("Tx fault", 4, "Yes", "No", v); + module_show_lane_status("Tx fault", 4, "Yes", "No", v); v = map->lower_memory[SFF8636_FAULT_AW_OFFSET] >> 4; if (map->page_00h[SFF8636_OPTION_2_OFFSET] & SFF8636_O2_TX_EQ_AUTO) - sff_show_lane_status("Tx adaptive eq fault", 4, "Yes", "No", v); + module_show_lane_status("Tx adaptive eq fault", 4, "Yes", "No", + v); } static void sff8636_show_page_zero(const struct sff8636_memory_map *map) @@ -907,31 +732,31 @@ static void sff8636_show_page_zero(const struct sff8636_memory_map *map) sff8636_show_connector(map); sff8636_show_transceiver(map); sff8636_show_encoding(map); - sff_show_value_with_unit(map->page_00h, SFF8636_BR_NOMINAL_OFFSET, - "BR, Nominal", 100, "Mbps"); + module_show_value_with_unit(map->page_00h, SFF8636_BR_NOMINAL_OFFSET, + "BR, Nominal", 100, "Mbps"); sff8636_show_rate_identifier(map); - sff_show_value_with_unit(map->page_00h, SFF8636_SM_LEN_OFFSET, - "Length (SMF,km)", 1, "km"); - sff_show_value_with_unit(map->page_00h, SFF8636_OM3_LEN_OFFSET, - "Length (OM3 50um)", 2, "m"); - sff_show_value_with_unit(map->page_00h, SFF8636_OM2_LEN_OFFSET, - "Length (OM2 50um)", 1, "m"); - sff_show_value_with_unit(map->page_00h, SFF8636_OM1_LEN_OFFSET, - "Length (OM1 62.5um)", 1, "m"); - sff_show_value_with_unit(map->page_00h, SFF8636_CBL_LEN_OFFSET, - "Length (Copper or Active cable)", 1, "m"); + module_show_value_with_unit(map->page_00h, SFF8636_SM_LEN_OFFSET, + "Length (SMF,km)", 1, "km"); + module_show_value_with_unit(map->page_00h, SFF8636_OM3_LEN_OFFSET, + "Length (OM3 50um)", 2, "m"); + module_show_value_with_unit(map->page_00h, SFF8636_OM2_LEN_OFFSET, + "Length (OM2 50um)", 1, "m"); + module_show_value_with_unit(map->page_00h, SFF8636_OM1_LEN_OFFSET, + "Length (OM1 62.5um)", 1, "m"); + module_show_value_with_unit(map->page_00h, SFF8636_CBL_LEN_OFFSET, + "Length (Copper or Active cable)", 1, "m"); sff8636_show_wavelength_or_copper_compliance(map); - sff_show_ascii(map->page_00h, SFF8636_VENDOR_NAME_START_OFFSET, - SFF8636_VENDOR_NAME_END_OFFSET, "Vendor name"); - sff8024_show_oui(map->page_00h, SFF8636_VENDOR_OUI_OFFSET); - sff_show_ascii(map->page_00h, SFF8636_VENDOR_PN_START_OFFSET, - SFF8636_VENDOR_PN_END_OFFSET, "Vendor PN"); - sff_show_ascii(map->page_00h, SFF8636_VENDOR_REV_START_OFFSET, - SFF8636_VENDOR_REV_END_OFFSET, "Vendor rev"); - sff_show_ascii(map->page_00h, SFF8636_VENDOR_SN_START_OFFSET, - SFF8636_VENDOR_SN_END_OFFSET, "Vendor SN"); - sff_show_ascii(map->page_00h, SFF8636_DATE_YEAR_OFFSET, - SFF8636_DATE_VENDOR_LOT_OFFSET + 1, "Date code"); + module_show_ascii(map->page_00h, SFF8636_VENDOR_NAME_START_OFFSET, + SFF8636_VENDOR_NAME_END_OFFSET, "Vendor name"); + module_show_oui(map->page_00h, SFF8636_VENDOR_OUI_OFFSET); + module_show_ascii(map->page_00h, SFF8636_VENDOR_PN_START_OFFSET, + SFF8636_VENDOR_PN_END_OFFSET, "Vendor PN"); + module_show_ascii(map->page_00h, SFF8636_VENDOR_REV_START_OFFSET, + SFF8636_VENDOR_REV_END_OFFSET, "Vendor rev"); + module_show_ascii(map->page_00h, SFF8636_VENDOR_SN_START_OFFSET, + SFF8636_VENDOR_SN_END_OFFSET, "Vendor SN"); + module_show_ascii(map->page_00h, SFF8636_DATE_YEAR_OFFSET, + SFF8636_DATE_VENDOR_LOT_OFFSET + 1, "Date code"); sff_show_revision_compliance(map->lower_memory, SFF8636_REV_COMPLIANCE_OFFSET); sff8636_show_signals(map); @@ -941,9 +766,9 @@ static void sff8636_show_all_common(const struct sff8636_memory_map *map) { sff8636_show_identifier(map); switch (map->lower_memory[SFF8636_ID_OFFSET]) { - case SFF8024_ID_QSFP: - case SFF8024_ID_QSFP_PLUS: - case SFF8024_ID_QSFP28: + case MODULE_ID_QSFP: + case MODULE_ID_QSFP_PLUS: + case MODULE_ID_QSFP28: sff8636_show_page_zero(map); sff8636_show_dom(map); break; @@ -978,12 +803,12 @@ void sff8636_show_all_ioctl(const __u8 *id, __u32 eeprom_len) struct sff8636_memory_map map = {}; switch (id[SFF8636_ID_OFFSET]) { - case SFF8024_ID_QSFP_DD: - case SFF8024_ID_OSFP: - case SFF8024_ID_DSFP: - case SFF8024_ID_QSFP_PLUS_CMIS: - case SFF8024_ID_SFP_DD_CMIS: - case SFF8024_ID_SFP_PLUS_CMIS: + case MODULE_ID_QSFP_DD: + case MODULE_ID_OSFP: + case MODULE_ID_DSFP: + case MODULE_ID_QSFP_PLUS_CMIS: + case MODULE_ID_SFP_DD_CMIS: + case MODULE_ID_SFP_PLUS_CMIS: cmis_show_all_ioctl(id); break; default: diff --git a/qsfp.h b/qsfp.h index 9f0cb0f..b899d4a 100644 --- a/qsfp.h +++ b/qsfp.h @@ -57,80 +57,6 @@ #define SFF8636_LOL_AW_OFFSET 0x05 -/* Module Monitor Interrupt Flags - 6-8 */ -#define SFF8636_TEMP_AW_OFFSET 0x06 -#define SFF8636_TEMP_HALARM_STATUS (1 << 7) -#define SFF8636_TEMP_LALARM_STATUS (1 << 6) -#define SFF8636_TEMP_HWARN_STATUS (1 << 5) -#define SFF8636_TEMP_LWARN_STATUS (1 << 4) - -#define SFF8636_VCC_AW_OFFSET 0x07 -#define SFF8636_VCC_HALARM_STATUS (1 << 7) -#define SFF8636_VCC_LALARM_STATUS (1 << 6) -#define SFF8636_VCC_HWARN_STATUS (1 << 5) -#define SFF8636_VCC_LWARN_STATUS (1 << 4) - -/* Channel Monitor Interrupt Flags - 9-21 */ -#define SFF8636_RX_PWR_12_AW_OFFSET 0x09 -#define SFF8636_RX_PWR_1_HALARM (1 << 7) -#define SFF8636_RX_PWR_1_LALARM (1 << 6) -#define SFF8636_RX_PWR_1_HWARN (1 << 5) -#define SFF8636_RX_PWR_1_LWARN (1 << 4) -#define SFF8636_RX_PWR_2_HALARM (1 << 3) -#define SFF8636_RX_PWR_2_LALARM (1 << 2) -#define SFF8636_RX_PWR_2_HWARN (1 << 1) -#define SFF8636_RX_PWR_2_LWARN (1 << 0) - -#define SFF8636_RX_PWR_34_AW_OFFSET 0x0A -#define SFF8636_RX_PWR_3_HALARM (1 << 7) -#define SFF8636_RX_PWR_3_LALARM (1 << 6) -#define SFF8636_RX_PWR_3_HWARN (1 << 5) -#define SFF8636_RX_PWR_3_LWARN (1 << 4) -#define SFF8636_RX_PWR_4_HALARM (1 << 3) -#define SFF8636_RX_PWR_4_LALARM (1 << 2) -#define SFF8636_RX_PWR_4_HWARN (1 << 1) -#define SFF8636_RX_PWR_4_LWARN (1 << 0) - -#define SFF8636_TX_BIAS_12_AW_OFFSET 0x0B -#define SFF8636_TX_BIAS_1_HALARM (1 << 7) -#define SFF8636_TX_BIAS_1_LALARM (1 << 6) -#define SFF8636_TX_BIAS_1_HWARN (1 << 5) -#define SFF8636_TX_BIAS_1_LWARN (1 << 4) -#define SFF8636_TX_BIAS_2_HALARM (1 << 3) -#define SFF8636_TX_BIAS_2_LALARM (1 << 2) -#define SFF8636_TX_BIAS_2_HWARN (1 << 1) -#define SFF8636_TX_BIAS_2_LWARN (1 << 0) - -#define SFF8636_TX_BIAS_34_AW_OFFSET 0xC -#define SFF8636_TX_BIAS_3_HALARM (1 << 7) -#define SFF8636_TX_BIAS_3_LALARM (1 << 6) -#define SFF8636_TX_BIAS_3_HWARN (1 << 5) -#define SFF8636_TX_BIAS_3_LWARN (1 << 4) -#define SFF8636_TX_BIAS_4_HALARM (1 << 3) -#define SFF8636_TX_BIAS_4_LALARM (1 << 2) -#define SFF8636_TX_BIAS_4_HWARN (1 << 1) -#define SFF8636_TX_BIAS_4_LWARN (1 << 0) - -#define SFF8636_TX_PWR_12_AW_OFFSET 0x0D -#define SFF8636_TX_PWR_1_HALARM (1 << 7) -#define SFF8636_TX_PWR_1_LALARM (1 << 6) -#define SFF8636_TX_PWR_1_HWARN (1 << 5) -#define SFF8636_TX_PWR_1_LWARN (1 << 4) -#define SFF8636_TX_PWR_2_HALARM (1 << 3) -#define SFF8636_TX_PWR_2_LALARM (1 << 2) -#define SFF8636_TX_PWR_2_HWARN (1 << 1) -#define SFF8636_TX_PWR_2_LWARN (1 << 0) - -#define SFF8636_TX_PWR_34_AW_OFFSET 0x0E -#define SFF8636_TX_PWR_3_HALARM (1 << 7) -#define SFF8636_TX_PWR_3_LALARM (1 << 6) -#define SFF8636_TX_PWR_3_HWARN (1 << 5) -#define SFF8636_TX_PWR_3_LWARN (1 << 4) -#define SFF8636_TX_PWR_4_HALARM (1 << 3) -#define SFF8636_TX_PWR_4_LALARM (1 << 2) -#define SFF8636_TX_PWR_4_HWARN (1 << 1) -#define SFF8636_TX_PWR_4_LWARN (1 << 0) - /* Module Monitoring Values - 22-33 */ #define SFF8636_TEMP_CURR 0x16 #define SFF8636_TEMP_MSB_OFFSET 0x16 @@ -381,40 +307,6 @@ /* Device Technology - 147 */ #define SFF8636_DEVICE_TECH_OFFSET 0x93 -/* Transmitter Technology */ -#define SFF8636_TRANS_TECH_MASK 0xF0 -/* Copper cable, linear active equalizers */ -#define SFF8636_TRANS_COPPER_LNR_EQUAL (15 << 4) -/* Copper cable, near end limiting active equalizers */ -#define SFF8636_TRANS_COPPER_NEAR_EQUAL (14 << 4) -/* Copper cable, far end limiting active equalizers */ -#define SFF8636_TRANS_COPPER_FAR_EQUAL (13 << 4) -/* Copper cable, near & far end limiting active equalizers */ -#define SFF8636_TRANS_COPPER_LNR_FAR_EQUAL (12 << 4) -/* Copper cable, passive equalized */ -#define SFF8636_TRANS_COPPER_PAS_EQUAL (11 << 4) -/* Copper cable, unequalized */ -#define SFF8636_TRANS_COPPER_PAS_UNEQUAL (10 << 4) -/* 1490 nm DFB */ -#define SFF8636_TRANS_1490_DFB (9 << 4) -/* Others */ -#define SFF8636_TRANS_OTHERS (8 << 4) -/* 1550 nm EML */ -#define SFF8636_TRANS_1550_EML (7 << 4) -/* 1310 nm EML */ -#define SFF8636_TRANS_1310_EML (6 << 4) -/* 1550 nm DFB */ -#define SFF8636_TRANS_1550_DFB (5 << 4) -/* 1310 nm DFB */ -#define SFF8636_TRANS_1310_DFB (4 << 4) -/* 1310 nm FP */ -#define SFF8636_TRANS_1310_FP (3 << 4) -/* 1550 nm VCSEL */ -#define SFF8636_TRANS_1550_VCSEL (2 << 4) -/* 1310 nm VCSEL */ -#define SFF8636_TRANS_1310_VCSEL (1 << 4) -/* 850 nm VCSEL */ -#define SFF8636_TRANS_850_VCSEL (0 << 4) /* Active/No wavelength control */ #define SFF8636_DEV_TECH_ACTIVE_WAVE_LEN (1 << 3) diff --git a/sff-common.c b/sff-common.c index a412a6e..6712b3e 100644 --- a/sff-common.c +++ b/sff-common.c @@ -29,233 +29,6 @@ double convert_mw_to_dbm(double mw) return (10. * log10(mw / 1000.)) + 30.; } -void sff_show_value_with_unit(const __u8 *id, unsigned int reg, - const char *name, unsigned int mult, - const char *unit) -{ - unsigned int val = id[reg]; - - printf("\t%-41s : %u%s\n", name, val * mult, unit); -} - -void sff_show_ascii(const __u8 *id, unsigned int first_reg, - unsigned int last_reg, const char *name) -{ - unsigned int reg, val; - - printf("\t%-41s : ", name); - while (first_reg <= last_reg && id[last_reg] == ' ') - last_reg--; - for (reg = first_reg; reg <= last_reg; reg++) { - val = id[reg]; - putchar(((val >= 32) && (val <= 126)) ? val : '_'); - } - printf("\n"); -} - -void sff_show_lane_status(const char *name, unsigned int lane_cnt, - const char *yes, const char *no, unsigned int value) -{ - printf("\t%-41s : ", name); - if (!value) { - printf("None\n"); - return; - } - - printf("["); - while (lane_cnt--) { - printf(" %s%c", value & 1 ? yes : no, lane_cnt ? ',': ' '); - value >>= 1; - } - printf("]\n"); -} - -void sff8024_show_oui(const __u8 *id, int id_offset) -{ - printf("\t%-41s : %02x:%02x:%02x\n", "Vendor OUI", - id[id_offset], id[(id_offset) + 1], - id[(id_offset) + 2]); -} - -void sff8024_show_identifier(const __u8 *id, int id_offset) -{ - printf("\t%-41s : 0x%02x", "Identifier", id[id_offset]); - switch (id[id_offset]) { - case SFF8024_ID_UNKNOWN: - printf(" (no module present, unknown, or unspecified)\n"); - break; - case SFF8024_ID_GBIC: - printf(" (GBIC)\n"); - break; - case SFF8024_ID_SOLDERED_MODULE: - printf(" (module soldered to motherboard)\n"); - break; - case SFF8024_ID_SFP: - printf(" (SFP)\n"); - break; - case SFF8024_ID_300_PIN_XBI: - printf(" (300 pin XBI)\n"); - break; - case SFF8024_ID_XENPAK: - printf(" (XENPAK)\n"); - break; - case SFF8024_ID_XFP: - printf(" (XFP)\n"); - break; - case SFF8024_ID_XFF: - printf(" (XFF)\n"); - break; - case SFF8024_ID_XFP_E: - printf(" (XFP-E)\n"); - break; - case SFF8024_ID_XPAK: - printf(" (XPAK)\n"); - break; - case SFF8024_ID_X2: - printf(" (X2)\n"); - break; - case SFF8024_ID_DWDM_SFP: - printf(" (DWDM-SFP)\n"); - break; - case SFF8024_ID_QSFP: - printf(" (QSFP)\n"); - break; - case SFF8024_ID_QSFP_PLUS: - printf(" (QSFP+)\n"); - break; - case SFF8024_ID_CXP: - printf(" (CXP)\n"); - break; - case SFF8024_ID_HD4X: - printf(" (Shielded Mini Multilane HD 4X)\n"); - break; - case SFF8024_ID_HD8X: - printf(" (Shielded Mini Multilane HD 8X)\n"); - break; - case SFF8024_ID_QSFP28: - printf(" (QSFP28)\n"); - break; - case SFF8024_ID_CXP2: - printf(" (CXP2/CXP28)\n"); - break; - case SFF8024_ID_CDFP: - printf(" (CDFP Style 1/Style 2)\n"); - break; - case SFF8024_ID_HD4X_FANOUT: - printf(" (Shielded Mini Multilane HD 4X Fanout Cable)\n"); - break; - case SFF8024_ID_HD8X_FANOUT: - printf(" (Shielded Mini Multilane HD 8X Fanout Cable)\n"); - break; - case SFF8024_ID_CDFP_S3: - printf(" (CDFP Style 3)\n"); - break; - case SFF8024_ID_MICRO_QSFP: - printf(" (microQSFP)\n"); - break; - case SFF8024_ID_QSFP_DD: - printf(" (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))\n"); - break; - case SFF8024_ID_OSFP: - printf(" (OSFP 8X Pluggable Transceiver)\n"); - break; - case SFF8024_ID_DSFP: - printf(" (DSFP Dual Small Form Factor Pluggable Transceiver)\n"); - break; - case SFF8024_ID_QSFP_PLUS_CMIS: - printf(" (QSFP+ or later with Common Management Interface Specification (CMIS))\n"); - break; - case SFF8024_ID_SFP_DD_CMIS: - printf(" (SFP-DD Double Density 2X Pluggable Transceiver with Common Management Interface Specification (CMIS))\n"); - break; - case SFF8024_ID_SFP_PLUS_CMIS: - printf(" (SFP+ and later with Common Management Interface Specification (CMIS))\n"); - break; - default: - printf(" (reserved or unknown)\n"); - break; - } -} - -void sff8024_show_connector(const __u8 *id, int ctor_offset) -{ - printf("\t%-41s : 0x%02x", "Connector", id[ctor_offset]); - switch (id[ctor_offset]) { - case SFF8024_CTOR_UNKNOWN: - printf(" (unknown or unspecified)\n"); - break; - case SFF8024_CTOR_SC: - printf(" (SC)\n"); - break; - case SFF8024_CTOR_FC_STYLE_1: - printf(" (Fibre Channel Style 1 copper)\n"); - break; - case SFF8024_CTOR_FC_STYLE_2: - printf(" (Fibre Channel Style 2 copper)\n"); - break; - case SFF8024_CTOR_BNC_TNC: - printf(" (BNC/TNC)\n"); - break; - case SFF8024_CTOR_FC_COAX: - printf(" (Fibre Channel coaxial headers)\n"); - break; - case SFF8024_CTOR_FIBER_JACK: - printf(" (FibreJack)\n"); - break; - case SFF8024_CTOR_LC: - printf(" (LC)\n"); - break; - case SFF8024_CTOR_MT_RJ: - printf(" (MT-RJ)\n"); - break; - case SFF8024_CTOR_MU: - printf(" (MU)\n"); - break; - case SFF8024_CTOR_SG: - printf(" (SG)\n"); - break; - case SFF8024_CTOR_OPT_PT: - printf(" (Optical pigtail)\n"); - break; - case SFF8024_CTOR_MPO: - printf(" (MPO Parallel Optic)\n"); - break; - case SFF8024_CTOR_MPO_2: - printf(" (MPO Parallel Optic - 2x16)\n"); - break; - case SFF8024_CTOR_HSDC_II: - printf(" (HSSDC II)\n"); - break; - case SFF8024_CTOR_COPPER_PT: - printf(" (Copper pigtail)\n"); - break; - case SFF8024_CTOR_RJ45: - printf(" (RJ45)\n"); - break; - case SFF8024_CTOR_NO_SEPARABLE: - printf(" (No separable connector)\n"); - break; - case SFF8024_CTOR_MXC_2x16: - printf(" (MXC 2x16)\n"); - break; - case SFF8024_CTOR_CS_OPTICAL: - printf(" (CS optical connector)\n"); - break; - case SFF8024_CTOR_CS_OPTICAL_MINI: - printf(" (Mini CS optical connector)\n"); - break; - case SFF8024_CTOR_MPO_2X12: - printf(" (MPO 2x12)\n"); - break; - case SFF8024_CTOR_MPO_1X16: - printf(" (MPO 1x16)\n"); - break; - default: - printf(" (reserved or unknown)\n"); - break; - } -} - void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type) { printf("\t%-41s : 0x%02x", "Encoding", id[encoding_offset]); diff --git a/sff-common.h b/sff-common.h index 899dc5b..34f1275 100644 --- a/sff-common.h +++ b/sff-common.h @@ -36,73 +36,6 @@ #define SFF8636_REV_8636_20 0x06 #define SFF8636_REV_8636_27 0x07 -#define SFF8024_ID_OFFSET 0x00 -#define SFF8024_ID_UNKNOWN 0x00 -#define SFF8024_ID_GBIC 0x01 -#define SFF8024_ID_SOLDERED_MODULE 0x02 -#define SFF8024_ID_SFP 0x03 -#define SFF8024_ID_300_PIN_XBI 0x04 -#define SFF8024_ID_XENPAK 0x05 -#define SFF8024_ID_XFP 0x06 -#define SFF8024_ID_XFF 0x07 -#define SFF8024_ID_XFP_E 0x08 -#define SFF8024_ID_XPAK 0x09 -#define SFF8024_ID_X2 0x0A -#define SFF8024_ID_DWDM_SFP 0x0B -#define SFF8024_ID_QSFP 0x0C -#define SFF8024_ID_QSFP_PLUS 0x0D -#define SFF8024_ID_CXP 0x0E -#define SFF8024_ID_HD4X 0x0F -#define SFF8024_ID_HD8X 0x10 -#define SFF8024_ID_QSFP28 0x11 -#define SFF8024_ID_CXP2 0x12 -#define SFF8024_ID_CDFP 0x13 -#define SFF8024_ID_HD4X_FANOUT 0x14 -#define SFF8024_ID_HD8X_FANOUT 0x15 -#define SFF8024_ID_CDFP_S3 0x16 -#define SFF8024_ID_MICRO_QSFP 0x17 -#define SFF8024_ID_QSFP_DD 0x18 -#define SFF8024_ID_OSFP 0x19 -#define SFF8024_ID_DSFP 0x1B -#define SFF8024_ID_QSFP_PLUS_CMIS 0x1E -#define SFF8024_ID_SFP_DD_CMIS 0x1F -#define SFF8024_ID_SFP_PLUS_CMIS 0x20 -#define SFF8024_ID_LAST SFF8024_ID_SFP_PLUS_CMIS -#define SFF8024_ID_UNALLOCATED_LAST 0x7F -#define SFF8024_ID_VENDOR_START 0x80 -#define SFF8024_ID_VENDOR_LAST 0xFF - -#define SFF8024_CTOR_UNKNOWN 0x00 -#define SFF8024_CTOR_SC 0x01 -#define SFF8024_CTOR_FC_STYLE_1 0x02 -#define SFF8024_CTOR_FC_STYLE_2 0x03 -#define SFF8024_CTOR_BNC_TNC 0x04 -#define SFF8024_CTOR_FC_COAX 0x05 -#define SFF8024_CTOR_FIBER_JACK 0x06 -#define SFF8024_CTOR_LC 0x07 -#define SFF8024_CTOR_MT_RJ 0x08 -#define SFF8024_CTOR_MU 0x09 -#define SFF8024_CTOR_SG 0x0A -#define SFF8024_CTOR_OPT_PT 0x0B -#define SFF8024_CTOR_MPO 0x0C -#define SFF8024_CTOR_MPO_2 0x0D -/* 0E-1Fh --- Reserved */ -#define SFF8024_CTOR_HSDC_II 0x20 -#define SFF8024_CTOR_COPPER_PT 0x21 -#define SFF8024_CTOR_RJ45 0x22 -#define SFF8024_CTOR_NO_SEPARABLE 0x23 -#define SFF8024_CTOR_MXC_2x16 0x24 -#define SFF8024_CTOR_CS_OPTICAL 0x25 -#define SFF8024_CTOR_CS_OPTICAL_MINI 0x26 -#define SFF8024_CTOR_MPO_2X12 0x27 -#define SFF8024_CTOR_MPO_1X16 0x28 -#define SFF8024_CTOR_LAST SFF8024_CTOR_MPO_1X16 - -#define SFF8024_CTOR_NO_SEP_QSFP_DD 0x6F -#define SFF8024_CTOR_UNALLOCATED_LAST 0x7F -#define SFF8024_CTOR_VENDOR_START 0x80 -#define SFF8024_CTOR_VENDOR_LAST 0xFF - /* ENCODING Values */ #define SFF8024_ENCODING_UNSPEC 0x00 #define SFF8024_ENCODING_8B10B 0x01 @@ -196,18 +129,8 @@ struct sff_diags { }; double convert_mw_to_dbm(double mw); -void sff_show_value_with_unit(const __u8 *id, unsigned int reg, - const char *name, unsigned int mult, - const char *unit); -void sff_show_ascii(const __u8 *id, unsigned int first_reg, - unsigned int last_reg, const char *name); -void sff_show_lane_status(const char *name, unsigned int lane_cnt, - const char *yes, const char *no, unsigned int value); void sff_show_thresholds(struct sff_diags sd); -void sff8024_show_oui(const __u8 *id, int id_offset); -void sff8024_show_identifier(const __u8 *id, int id_offset); -void sff8024_show_connector(const __u8 *id, int ctor_offset); void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type); void sff_show_revision_compliance(const __u8 *id, int rev_offset); diff --git a/sfpdiag.c b/sfpdiag.c index 1fa8b7b..bbca91e 100644 --- a/sfpdiag.c +++ b/sfpdiag.c @@ -12,7 +12,7 @@ #include #include #include "internal.h" -#include "sff-common.h" +#include "module-common.h" /* Offsets in decimal, for direct comparison with the SFF specs */ @@ -263,8 +263,7 @@ void sff8472_show_all(const __u8 *id) PRINT_xX_PWR(rx_power_string, sd.rx_power[MCURR]); - PRINT_TEMP("Module temperature", sd.sfp_temp[MCURR]); - PRINT_VCC("Module voltage", sd.sfp_voltage[MCURR]); + module_show_dom_mod_lvl_monitors(&sd); printf("\t%-41s : %s\n", "Alarm/warning flags implemented", (sd.supports_alarms ? "Yes" : "No")); diff --git a/sfpid.c b/sfpid.c index 1bc45c1..3c126b4 100644 --- a/sfpid.c +++ b/sfpid.c @@ -10,7 +10,7 @@ #include #include #include "internal.h" -#include "sff-common.h" +#include "module-common.h" #include "netlink/extapi.h" #define SFF8079_PAGE_SIZE 0x80 @@ -19,7 +19,7 @@ static void sff8079_show_identifier(const __u8 *id) { - sff8024_show_identifier(id, 0); + module_show_identifier(id, 0); } static void sff8079_show_ext_identifier(const __u8 *id) @@ -37,7 +37,7 @@ static void sff8079_show_ext_identifier(const __u8 *id) static void sff8079_show_connector(const __u8 *id) { - sff8024_show_connector(id, 2); + module_show_connector(id, 2); } static void sff8079_show_transceiver(const __u8 *id) @@ -299,12 +299,6 @@ static void sff8079_show_rate_identifier(const __u8 *id) } } -static void sff8079_show_oui(const __u8 *id) -{ - printf("\t%-41s : %02x:%02x:%02x\n", "Vendor OUI", - id[37], id[38], id[39]); -} - static void sff8079_show_wavelength_or_copper_compliance(const __u8 *id) { if (id[8] & (1 << 2)) { @@ -344,30 +338,6 @@ static void sff8079_show_wavelength_or_copper_compliance(const __u8 *id) } } -static void sff8079_show_value_with_unit(const __u8 *id, unsigned int reg, - const char *name, unsigned int mult, - const char *unit) -{ - unsigned int val = id[reg]; - - printf("\t%-41s : %u%s\n", name, val * mult, unit); -} - -static void sff8079_show_ascii(const __u8 *id, unsigned int first_reg, - unsigned int last_reg, const char *name) -{ - unsigned int reg, val; - - printf("\t%-41s : ", name); - while (first_reg <= last_reg && id[last_reg] == ' ') - last_reg--; - for (reg = first_reg; reg <= last_reg; reg++) { - val = id[reg]; - putchar(((val >= 32) && (val <= 126)) ? val : '_'); - } - printf("\n"); -} - static void sff8079_show_options(const __u8 *id) { static const char *pfx = @@ -425,24 +395,24 @@ static void sff8079_show_all_common(const __u8 *id) sff8079_show_encoding(id); printf("\t%-41s : %u%s\n", "BR, Nominal", br_nom, "MBd"); sff8079_show_rate_identifier(id); - sff8079_show_value_with_unit(id, 14, - "Length (SMF,km)", 1, "km"); - sff8079_show_value_with_unit(id, 15, "Length (SMF)", 100, "m"); - sff8079_show_value_with_unit(id, 16, "Length (50um)", 10, "m"); - sff8079_show_value_with_unit(id, 17, + module_show_value_with_unit(id, 14, + "Length (SMF,km)", 1, "km"); + module_show_value_with_unit(id, 15, "Length (SMF)", 100, "m"); + module_show_value_with_unit(id, 16, "Length (50um)", 10, "m"); + module_show_value_with_unit(id, 17, "Length (62.5um)", 10, "m"); - sff8079_show_value_with_unit(id, 18, "Length (Copper)", 1, "m"); - sff8079_show_value_with_unit(id, 19, "Length (OM3)", 10, "m"); + module_show_value_with_unit(id, 18, "Length (Copper)", 1, "m"); + module_show_value_with_unit(id, 19, "Length (OM3)", 10, "m"); sff8079_show_wavelength_or_copper_compliance(id); - sff8079_show_ascii(id, 20, 35, "Vendor name"); - sff8079_show_oui(id); - sff8079_show_ascii(id, 40, 55, "Vendor PN"); - sff8079_show_ascii(id, 56, 59, "Vendor rev"); + module_show_ascii(id, 20, 35, "Vendor name"); + module_show_oui(id, 37); + module_show_ascii(id, 40, 55, "Vendor PN"); + module_show_ascii(id, 56, 59, "Vendor rev"); sff8079_show_options(id); printf("\t%-41s : %u%s\n", "BR margin, max", br_max, "%"); printf("\t%-41s : %u%s\n", "BR margin, min", br_min, "%"); - sff8079_show_ascii(id, 68, 83, "Vendor SN"); - sff8079_show_ascii(id, 84, 91, "Date code"); + module_show_ascii(id, 68, 83, "Vendor SN"); + module_show_ascii(id, 84, 91, "Date code"); } } From patchwork Sun Jan 26 11:56:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950652 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2066.outbound.protection.outlook.com [40.107.212.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF9E86358 for ; Sun, 26 Jan 2025 11:57:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892631; cv=fail; b=ksZlcoL511ZK2Z/VO4eSeSxf5HhcyWh6gwgI5BGJpZC72CSl3siQod7wSTKn6qf2gdx0qoW1P3lHNfjke8lLOg9K9B4bfUxlPQdgPWuWCjbvr/G7Cfw55g4ijWYPi7WrVPd4y1P4fKJZcsAzQ/wgQNtXDKI7UeZmKWkX3q5kWjA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892631; c=relaxed/simple; bh=Rdi8yJnk7TU6tRWoMU82KfsEckLWh0qojsotTZ6zi58=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=brp4SEY1nT8qs96ywRXImUj9WL34smXbQZkt5WoYDgT7eB0ltECg+O4PlOE7ljeCIhYksLZRyoXm5J/X94NqxoMnZ4LcwBLUI9kvyfn+Rw9LJuOCecRxn6cMlQTPRO/Bh7pfw9wcbofs1CzkjareCxNP38oT9CRJ9tdn0/uDGJU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=jDoCt9/s; arc=fail smtp.client-ip=40.107.212.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="jDoCt9/s" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RezitWl6oNB7FHHu/gAoOBy8xg7p9IaIs+G7cn/IIUrwixQRbQ+bQUFJKizO9kbg40S4IMOo1wcByLEP29SaibkHG9gDYJeSwRMfReZ+fZYEBfySpVVfoiWTMfHhMuW/elyocmX6fXBhlxzTPcnULmlU1wlfNnvhGq5RJAjbnP4OZwZwg+0iJMh4j4fj0IGoNtBZf22R5wxB8y9gmVXc47ycQBRs6eoz09Uc0ZqTFeaM5Tqnw5LmX6WNnsxI/lB5esCDafhtlRZn9FpeSvCjCrY3bGIs5RDMGIe6LJXRmVSZGz0i80ZpvJY07SUZagcdA5TePw39nOtoFs5s9KPAMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/9JGit/uADGkyZmnxHHYXj9eBsYH8wNHIAhvnezfx3s=; b=H29QY7u9fLblOaU5PyI8wJRVeX/n5cW0GzKVws5gz2rNKvhJSI3ksd8tAqh1BgNYyZ01Xtv5WROChvwBe9CQB0kPlR5EYOYwDdyEF3qGwIZWKCowbcOskXujopiI9atSM5draB+If60QjUgpnA+3Ztvp0oyO8EEgfHV/gZQJ/VDklPuzltD9PjlAXBRMybMxG3bXXOnMyWUHaMZSTgEGNod2lYbYkwUQPohdZan7k07PMCMs/VeBxHWzaa60i29Zf8aCTA1PGvBIGSFb8/JmmvBuvrdahcJ8UxXvIuw6cgy7xTPs6GyHCrY6BVcsJMsluIx/5WePwHmOEvrohWlacQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/9JGit/uADGkyZmnxHHYXj9eBsYH8wNHIAhvnezfx3s=; b=jDoCt9/sqtFgcJiByOHI2q0VEa+oEHxqi8ipfsouSd+p3Dc41F6mcy4Pig3MPQC+tnjcGZFGqrKmuV4Z7kmuEb0Kd+JNJ0aMsoeR5nUJ5Nyr5qtLAwPZJKtZiakfoTaH1X5is+KiiWYJxDOBlyyBkW9fteU4HCBflL6I0oAitj6F+qCKo+xXgj4+Cmmj7UWY7Mc1BtEZInm3cZJ7D8tpYEkRhEFzQH1gvxrxeoJbHsjh37uV4C5AIg5D9enkRy028yhAHv3WUdZQQcZeSximDNGjs6n64FrsCaZH6yW7H7HidPxgEDakEOF5yu0DTx41ummSyWcJ7gXE0P95aWwM+g== Received: from DM6PR14CA0056.namprd14.prod.outlook.com (2603:10b6:5:18f::33) by PH7PR12MB7161.namprd12.prod.outlook.com (2603:10b6:510:200::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.17; Sun, 26 Jan 2025 11:57:05 +0000 Received: from CY4PEPF0000E9CE.namprd03.prod.outlook.com (2603:10b6:5:18f:cafe::4c) by DM6PR14CA0056.outlook.office365.com (2603:10b6:5:18f::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9CE.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:04 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:55 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:53 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 02/14] sff_common: Move sff_show_revision_compliance() to qsfp.c Date: Sun, 26 Jan 2025 13:56:23 +0200 Message-ID: <20250126115635.801935-3-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CE:EE_|PH7PR12MB7161:EE_ X-MS-Office365-Filtering-Correlation-Id: d85b688b-716c-4cf6-b41e-08dd3e008d4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: UuC5EB4Lp6ZWkqfE4Y83smU/hwvU8gIsZavIu8byM0XCWcjSkIc2S7PnaP1UQVXl8RUbyQrDW5kyAoeNI7Oq9A9NinO1DPUrRNkyiOV2Nt7M9hBUfGsu1Rh+/nN2bIW6xECSHK+EsOIwoscKME9Ouao3HTkaXKfMvJFSLvELLQFPj1BNIdjtYBfbk6aJMscrIbbdTiV4oIoM6bKL7tSG6iyrOUCYUC2GkfqETTw+V3FTCZlI5c4qo1+Hig8n8O648kR4q4AfD+gxUhEKhAcVEuTg4S4Hm6MSw6kq9HJEwkxTbY+BBwsbROLPrU6RqyKQI+K6M+S21pOPyPozc6dyCRqPZOzDoot3z7f971r3/P1YoOeM2XkGOQ8HTCFcyjqCnmBQRo9hjXC/uxye5pX95/ZfGLkub8lujNWzZ61DgQMp7rRT3C//g+6y6IIbPa/n/8Y6OlefdU+L0A1M/SurML/xlayXwicT2B79uTUW73KvbWlZC/ZqtknEoSWwUtmF2AwRO9adDY8F49ySpmoMkI1O2ZY2L01CCoce1Z/76vwwO3o05TNCuarcJzIF4wn/ipYhFeM3kCIsAJ3hnPGAurxagP0UkIHN4GpGqxk7hrKZg8G3wTYdYlCbA5g6UF5S7HxWGop8tAQH34KkfD/GN8BSWx/HNGgHru70nSH+bWWQDjLAU7bhmuRqvarPxRg6Opl+v4XvMqLwHFOclawV0NIx/ho6AuamWkKTqcn2M2seSGx1TzaHDypLvEyaIKBEovWe+TerbtsgM3AK3ytNXaJOZWVycBYOO2mGSQKPryiGhSGbe1FWGyJhGBY2Zs79YtS84LLWXckZng6GLUkWQltF+VVZuaL+xE6sMlRADg0xkH1MKQ2DweYyzahoH7eFB7BdR5Ffoc5QVmJyrVlFttD1qgD4aRnoPfyt4/M1nm988mwFTYNXOtTzQm4OzBUW5W9eoNf8s+IBzo7oWp8czqydmXtvdLi9GWw6y618AFUln0VEgpurdJBEKTDg5SMu2U69w6UuYFq1xza88xO9Prohtqg1W4P0ZTF0mDsNtuWMjnfe7r7D1TWKtP53qhSxzAjlq8SvlbZMleoe1lV4QVphhcEZ1xBEbjE+4yQPJiaJ6YRf5/HAueH0d9wjsR16Ux9xrwJynUzRnKnvLY5Us53I0MCEuo5w7FV8ViWfEFFwm7cn1JStzyNw0/VQkxUskpKSGKfwLj1u8Z22Dp0Oq4g5vQciKrY7edv3SfQdbP9iOxY48AqL8xSh9cwqCphyWNPvmH3Wh83quc71WZ/OBZGopnEF1JuyGR5RIl1cpzpheiyHi5zQu5hdmOOZyvXIWMPe1zNfatf5DvHGOAJiVipejD2I5hb90sTppMXrYbOVxEc2ADQtGMszvOgxuEl8T4L3HOx5szLJnzecCAKdrR6wF7mJkit9jyNjDEOVxzSk4UHHvIXgTbN6jb7cxhgfCnYnm5M95TvYuUFO3+F7UXB94qgkR1WASN0OtmX7KeM= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:04.6739 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d85b688b-716c-4cf6-b41e-08dd3e008d4e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7161 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz The only use of the function sff_show_revision_compliance() is in qsfp.c file. Therefore, it doesn't belong to sff_common.c file but it can simply be a static function in qsfp.c. Move sff_show_revision_compliance() function to qsfp.c. Signed-off-by: Danielle Ratson --- qsfp.c | 40 ++++++++++++++++++++++++++++++++++++++-- sff-common.c | 36 ------------------------------------ sff-common.h | 1 - 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/qsfp.c b/qsfp.c index 6d774f8..6c7e72c 100644 --- a/qsfp.c +++ b/qsfp.c @@ -514,6 +514,42 @@ sff8636_show_wavelength_or_copper_compliance(const struct sff8636_memory_map *ma } } +static void sff8636_show_revision_compliance(const __u8 *id, int rev_offset) +{ + static const char *pfx = + "\tRevision Compliance :"; + + switch (id[rev_offset]) { + case SFF8636_REV_UNSPECIFIED: + printf("%s Revision not specified\n", pfx); + break; + case SFF8636_REV_8436_48: + printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); + break; + case SFF8636_REV_8436_8636: + printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); + break; + case SFF8636_REV_8636_13: + printf("%s SFF-8636 Rev 1.3 or earlier\n", pfx); + break; + case SFF8636_REV_8636_14: + printf("%s SFF-8636 Rev 1.4\n", pfx); + break; + case SFF8636_REV_8636_15: + printf("%s SFF-8636 Rev 1.5\n", pfx); + break; + case SFF8636_REV_8636_20: + printf("%s SFF-8636 Rev 2.0\n", pfx); + break; + case SFF8636_REV_8636_27: + printf("%s SFF-8636 Rev 2.5/2.6/2.7\n", pfx); + break; + default: + printf("%s Unallocated\n", pfx); + break; + } +} + /* * 2-byte internal temperature conversions: * First byte is a signed 8-bit integer, which is the temp decimal part @@ -757,8 +793,8 @@ static void sff8636_show_page_zero(const struct sff8636_memory_map *map) SFF8636_VENDOR_SN_END_OFFSET, "Vendor SN"); module_show_ascii(map->page_00h, SFF8636_DATE_YEAR_OFFSET, SFF8636_DATE_VENDOR_LOT_OFFSET + 1, "Date code"); - sff_show_revision_compliance(map->lower_memory, - SFF8636_REV_COMPLIANCE_OFFSET); + sff8636_show_revision_compliance(map->lower_memory, + SFF8636_REV_COMPLIANCE_OFFSET); sff8636_show_signals(map); } diff --git a/sff-common.c b/sff-common.c index 6712b3e..e2f2463 100644 --- a/sff-common.c +++ b/sff-common.c @@ -122,39 +122,3 @@ void sff_show_thresholds(struct sff_diags sd) PRINT_xX_PWR("Laser rx power low warning threshold", sd.rx_power[LWARN]); } - -void sff_show_revision_compliance(const __u8 *id, int rev_offset) -{ - static const char *pfx = - "\tRevision Compliance :"; - - switch (id[rev_offset]) { - case SFF8636_REV_UNSPECIFIED: - printf("%s Revision not specified\n", pfx); - break; - case SFF8636_REV_8436_48: - printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); - break; - case SFF8636_REV_8436_8636: - printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); - break; - case SFF8636_REV_8636_13: - printf("%s SFF-8636 Rev 1.3 or earlier\n", pfx); - break; - case SFF8636_REV_8636_14: - printf("%s SFF-8636 Rev 1.4\n", pfx); - break; - case SFF8636_REV_8636_15: - printf("%s SFF-8636 Rev 1.5\n", pfx); - break; - case SFF8636_REV_8636_20: - printf("%s SFF-8636 Rev 2.0\n", pfx); - break; - case SFF8636_REV_8636_27: - printf("%s SFF-8636 Rev 2.5/2.6/2.7\n", pfx); - break; - default: - printf("%s Unallocated\n", pfx); - break; - } -} diff --git a/sff-common.h b/sff-common.h index 34f1275..161860c 100644 --- a/sff-common.h +++ b/sff-common.h @@ -132,6 +132,5 @@ double convert_mw_to_dbm(double mw); void sff_show_thresholds(struct sff_diags sd); void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type); -void sff_show_revision_compliance(const __u8 *id, int rev_offset); #endif /* SFF_COMMON_H__ */ From patchwork Sun Jan 26 11:56:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950654 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2074.outbound.protection.outlook.com [40.107.243.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 875A186358 for ; Sun, 26 Jan 2025 11:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892635; cv=fail; b=g/sYlYz+VNxV09+OV9NBqSNCEKfC5hc75bamB5fI7C9kmxpTm7aql5qaSXCWs2lOaxPS6TAGOPekYrnN8k5g4R1zsm+ORkG50NDk0bIdyHl5wTRdGgbP3WkF/DuZ7aQD+DOCNlRTjCeZNkcYHWTBKmbQtUZ1ncqI5r4dkZ4yd6Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892635; c=relaxed/simple; bh=lVS4SeviKbJm0VG/e+Kog3uSiZci4PeEb6vgfDuxC4s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TBWm+yOEAYu8Se3eWPmHDMQjtjg02NwC02JQPQbJuEkHQUALj+S74AVrfT6CBmWJZOQptbP1o7Awd+0MJQ0MnYjjUnWSVBfiB31JtCqZx9gu1iGMUA61CIDo3qiYApib8osPf+NfKWU0+aW1/NckWr/11Wi7Tr9M4a+7Rxj93lU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=twaIjk4Y; arc=fail smtp.client-ip=40.107.243.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="twaIjk4Y" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eegdacFnEF23flFu5qCEFsKxXBccASURGfuepTl9Tt7j92VMVGbPU2rQaYoAKuHtJYeqhXq0leqoudBag/MHlSG8zJGYUFDGD1S52BlxOi4fj/V4qlt8005x6fl3Ooqs5cD/88vEYET58cLKiNQXDty9DqoAK6Yak7mx7w0z9+A2Ubmy5qFKw1YCXScN7YNK/eUZvu0YYoJMgcatamA8PEROEwt+sWGxSC2wBd+CGe7APwT5gCuwWQvhRE9URcxumwTPT2b7jvW1xtrEDezSmHoGydB2zmAw0uY2cepruNTx3ltdt61zU3P1Wm4rySySXh/X9Kpx15CIsAXr3Jx4Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7OApf7K1DXNYI+jI9X2cxb1NdTwYn2HDIBypGCKm0BY=; b=ohfgPOOItcpV9T2MyNt6I2/5h2gD96fCT+jqyWKRGz4GMqYDUo9+X5DiYarjCWfcBKGLR/ubbJ9F2GUv00B8SrjFlNeIEmgBLojq3x2om8LtGVgSqeWzGUtm1QmrZplOcffUa3HP0KPLYrtAIljqYOK8en+WYyN2FQq4rsfXS4oDzBCCj6WDt4jWWPwbAluegYXe6xl8LAuTn85bmvVQ6Fg/mFKs++k4DBsM6B1/ttmNsRqc4Zm556w2LhbZUKBKpKmkJvR46rMWdhvmrFP38vk0FXxKfmn9MYzZzLn1YN8D0xLZjuzffY04xF0LAjMhh6p2gGP8I6VCjbNcN/gzZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7OApf7K1DXNYI+jI9X2cxb1NdTwYn2HDIBypGCKm0BY=; b=twaIjk4Yz7s5BHdat0kJaJ4xuJOI6eOuIQiBXxlOMdEYwTyxzD/RkNnorHRcZtd4HosNFotSwR9poON3zTmt+6wYA2WBvVscFVfgXxeW5aL/NFKpulHCJS1EzQQwK5ES20SxGoipTdbz00u/v/jmKAuGblLZUj/f1aIIdKYjik2OqxP/RgLMU/EZ86Xyn+24mszEpQjcSoXmbhsfH6lpSWhkbPR5D9IpUJ1oyOnTpzW8Mc8B72ZzTOwlsQ7vDEE36rdijnF3keXoR48W15TSeUwrUW1AiAUHo6j+35zEyqzVuHbh7lbMFjv8drppEWzRSbL4a5vptKQGpMNmG9LP/Q== Received: from DM6PR14CA0038.namprd14.prod.outlook.com (2603:10b6:5:18f::15) by IA0PR12MB9012.namprd12.prod.outlook.com (2603:10b6:208:485::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:09 +0000 Received: from CY4PEPF0000E9CE.namprd03.prod.outlook.com (2603:10b6:5:18f:cafe::4e) by DM6PR14CA0038.outlook.office365.com (2603:10b6:5:18f::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9CE.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:58 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:55 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 03/14] cmis: Change loop order in cmis_show_dom_chan_lvl_flags() Date: Sun, 26 Jan 2025 13:56:24 +0200 Message-ID: <20250126115635.801935-4-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CE:EE_|IA0PR12MB9012:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c3bf699-7721-4de5-c0be-08dd3e008fa2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: ZWZhQEnXaLHpevg1sdEX2st7mlWPrRQpyGtKFnYuwni3RXbV1v5qszJQI8mMy24fkvyXuGKcuwMNSgsnPmyfB5dMGGA0Hleanbi4C7TDOqjXblQZVRRbPqjSinYYkk6YBeVS4mXwEbwOB4C8cDwiu4SKh2gUe2Md9SN8Xm+CCpjGdvFedH2fCS54ZQpESTKLr1hcxoJAdU0jxo5VkfYhSMoej79PvI5+OYytifMEFQrOapQxo0DrN91LibHrjzauWAUXhL4f3B/6XMSV45H0WMoDZ/cFH3ihwkKvaFhhVOoCkmUutn6+FehuKWqx9VB0UgBuZ5XW46L6suj5zTz4NqYfj4IxU9ig2h2UKIURzpzsRMZNujXUkoUF1fDklcNuWPTUqDvIYHE8zPiZ/ydO/Rdf2XufHw0s02fSH3o2ZsSx91DHSgp18K5abUo4SyJ3+6wXHfbsjhYEJZFtDAF94CRUEVF9Ul1+WwD3ve5L8tLf6933pOd3o49/SpKoRy5PHZmWdxlu4JLk4mL+URzUQ7ZICAGQbcVvO3WIgVsLye9j9N8J2Qx8tFW7ih8mKANC3V5zpGj7VLGYuYthmHW/ndToecwbeBBg+bhEh2KCyhbvU+2aIzax91mAW8HWMia6/pvwJv/EUVVM/ImciebMfpDvwQYlq8/KDCy8mIVOqel70ZIRSPyIRyPrCXLabQ59iqpoqT2fL1iPpKO7lVOcTYpWmhKdXiAuvVoYOde7eJ/p1hYrrDOddVfF0YysHyIbJBIumPoHrholFxLjg1WCULZua9Scb2aMWx8OGstiTmMmL45UIr8ZQKszpvP/ZlAKA2Fpe9FWfz3dpaKhcW5Tym9jFIlKp9qPJSYORfMf6dA0rt0bNf5DfcEP6W+Qj1YnrsIJA6E0mJIt9yghHnKSaCj8Rv7+utCQPhXfYYryzA84plr1XJssyOAMuUT8IZYlKQNcyczd1UiX82c+qWtOv+uWIfB8SKtAlpICTO93mOOzr4miLKIykpxHLsppkKrRSZv6otUPUhQg7s5G0IZdChsQRRQpjsrqARsO5vCy4gWZYbQytL6sH3klE3n8dWatCTZk0BbESV/v/2/l/Disct6ftav2YYuwy8ldHIRN8a2/7hd3DPY/083UI99tAFrWQUIZLMEy/6L+mszhS8DoFKow7iu6a6000xZG55rQocf2BKKsJNBrlH/T6O+sYj6LK1z0UmEUVJNe70L0q72hDoA9gd1YX9NcwcFlW7U6JbP5nutSFAata/KXQMe+UUsjzpgtXkXfwgi0pFeXhIfhCEhLpsEkzmQvkNaZw48FIGiDqGWzxCsvJbVjfH+vBFZy8HJptTlL+Cv9xiqWo1I1+i1pLvyFmNEjA1zQPcuJ1O+PfpdB8S9z7gDV8RjPcwRPvJxP42L4/o++rYhbrT1bECiqRxOWQpUDGaN11bV+7NzTsTPbpGM+1Mx8z5I1KEn9sIhCsb/ETFjBJyVMhZ5URLaHFwcjbtbk8AU3vh2PaLI= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:08.5802 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0c3bf699-7721-4de5-c0be-08dd3e008fa2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB9012 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Currently, when printing channel-level flags in ethtool dump, we are going over the banks, and for each bank, we are printing all the flags. When JSON support will be added, in per-channel fields we would like to have an array that each of its elements represents a channel. Therefore, change the loop order so first we loop over the flags, and for each one, we print all its channels. Signed-off-by: Danielle Ratson Reviewed-by: Amit Cohen --- cmis.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cmis.c b/cmis.c index 71f0745..9d89a5e 100644 --- a/cmis.c +++ b/cmis.c @@ -683,22 +683,19 @@ static void cmis_show_dom_mod_lvl_flags(const struct cmis_memory_map *map) * [1] CMIS Rev. 5, page 162, section 8.9.3, Table 8-77 * [1] CMIS Rev. 5, page 164, section 8.9.3, Table 8-78 */ -static void cmis_show_dom_chan_lvl_flags_chan(const struct cmis_memory_map *map, - int bank, int chan) +static void cmis_show_dom_chan_lvl_flag(const struct cmis_memory_map *map, + int bank, int flag) { const __u8 *page_11h = map->upper_memory[bank][0x11]; int i; - for (i = 0; module_aw_chan_flags[i].fmt_str; i++) { + for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { + int chan = bank * CMIS_CHANNELS_PER_BANK + i; char str[80]; - if (!(map->page_01h[module_aw_chan_flags[i].adver_offset] & - module_aw_chan_flags[i].adver_value)) - continue; - - snprintf(str, 80, module_aw_chan_flags[i].fmt_str, chan + 1); + snprintf(str, 80, module_aw_chan_flags[flag].fmt_str, chan + 1); printf("\t%-41s : %s\n", str, - page_11h[module_aw_chan_flags[i].offset] & chan ? + page_11h[module_aw_chan_flags[flag].offset] & chan ? "On" : "Off"); } } @@ -708,15 +705,17 @@ cmis_show_dom_chan_lvl_flags_bank(const struct cmis_memory_map *map, int bank) { const __u8 *page_11h = map->upper_memory[bank][0x11]; - int i; + int flag; if (!page_11h) return; - for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { - int chan = bank * CMIS_CHANNELS_PER_BANK + i; + for (flag = 0; module_aw_chan_flags[flag].fmt_str; flag++) { + if (!(map->page_01h[module_aw_chan_flags[flag].adver_offset] & + module_aw_chan_flags[flag].adver_value)) + continue; - cmis_show_dom_chan_lvl_flags_chan(map, bank, chan); + cmis_show_dom_chan_lvl_flag(map, bank, flag); } } From patchwork Sun Jan 26 11:56:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950655 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2055.outbound.protection.outlook.com [40.107.220.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6085D13AA3E for ; Sun, 26 Jan 2025 11:57:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892640; cv=fail; b=dHDp/6pjM427ThymLrtBQmqLv9FIp9S5jN3V5N42yP9gfgULM2WqvyxI6c0FGUOIq0eSEPZ+y2Mn4fJ3b/SxbVCmy6tNECmpAJInD3oD1wMU9tvKDb9j2BNEgummM66BvgyDg8TKc/Fz6JCpXK8q/8tmkXduQYlkUk1l77J8sjQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892640; c=relaxed/simple; bh=5jjhUQySOxqB+WCj5Xvl7141BGtmNuM7+Yuit05ksJE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RU29W7cN7AGoQmsFbJwRt8/5+brMBxP0IRpfOqbh677XvDQnJqvRaaEmk2O4/dKfYXebrFNKM0uASgqplLao33sYgzCXzjsUwm51xMjQePUcZjTcU4HWGuPwzPSNDBokPM7CQIYIlG+rIagR3sBPuvSWCsDQl4nO+g6jJcng2GI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=NyYXLYXD; arc=fail smtp.client-ip=40.107.220.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="NyYXLYXD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vyt4CrVUj71gEBJf1eGT2V1BiNRli3TqqiP8nHQapn6iuG7+koeVt09KAUJZycO20YgPEjg/5F19leW7FZIItbE5OoyPuSikBdZJmPFwpM1CTy8yoTWOilsEsLz3uB2N0/G+RxKvOQiVfdwQcG4qXEwIK6zyL4LHI1gNoo8cNy17hKhd68ChBao5lwe4f3SPjsTP+NDJZrxJsI62QGv84lOPOdTlypgyctkJQ2vsV6/d0L3vPfpdJr3MmJsuvELjjmbNOL5BmeRNDi6QrVjjyzepfT4OM7gShTpw7YtuRvoP3S+oKpD9jpSsJqlmT7jEl1fvJ1ffh2bbDkaAlxZr6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SQJXW8Kzd+ioqgzM19ubv25ilEsllvYPH/d8MWps8RU=; b=MAMGOIpSZpHWkVHEWss7OuWulbI1CZxOP/f2U3YgmhXaVJ2uW4EnR9ogYgTf4wHMUP7F6qmaFCpLcl09FNBNKEERFNYc26ttNwteHSsryYKFYKpr7CL6nqG8hU+XBNEuEUMVj2bp8/WPMEkwjyKid8LF+9mZd8haBPA1V3bcFXfgHCR76dvZ+TRpoGdyWmZfCchQ+Es63ZRVfsC65BmSMfEPWrBoQT2BI8UhNJg5pWmkZ0BFP8UqpxJQqMO9YE1p5hwoqm059uREiM/z1qJsTYC3MhFJqi9bYWSULE9qS0yBkWqpsySwcO3yoIUMU3sBe827aYHILD0ZPUnbXQD9aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SQJXW8Kzd+ioqgzM19ubv25ilEsllvYPH/d8MWps8RU=; b=NyYXLYXDfO/uqIdVNEm0eOdPx6wvm9snhV/pTztn7K9AF/0vn3ZvpI4MLENW86P9m9zqI9lKUqx5XD6TX9PCsJpCl2hDsTMfqRx2vFEOpIJqJ/iR+PCvB+uCTHcdor8KdHifE4r+UvL8UJCng8dOTL+e7AJPyFPJuXN6AVmuiehNrvBMtgOPMiGXig22mhOSMd+NqqYq9wT3AOnFkOjk99tLu6+jTiHZjfMhttnVemGSDjpobTqWUj3HeHr+qMe4kiN9CfrVTZ9Y1YLT/acYvIT7UHexj+XL5FDimMu7WtC1NRLo9Pwwbu6cumZkejkQ7c5trRxUHagQIApaoJJaew== Received: from PH7PR17CA0061.namprd17.prod.outlook.com (2603:10b6:510:325::11) by CYYPR12MB8749.namprd12.prod.outlook.com (2603:10b6:930:c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.20; Sun, 26 Jan 2025 11:57:12 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:510:325:cafe::48) by PH7PR17CA0061.outlook.office365.com (2603:10b6:510:325::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:00 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:56:58 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 04/14] qsfp: Reorder the channel-level flags list for SFF8636 module type Date: Sun, 26 Jan 2025 13:56:25 +0200 Message-ID: <20250126115635.801935-5-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D1:EE_|CYYPR12MB8749:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ac751cf-6caf-4e3a-9d45-08dd3e00917a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: 4hajbkSUjiDALVZrWZMyo2lmkUTgn415QP0fxrx2yA+7omGdWOsGGReBVeLuH7WIORRAODO3IugkiQNOgdY1Uv3tR5+KIWdWE8pWRzmOP+xLXioIGTBKafSPvxdMK5LCBLnUAAKmOwsmJ1Fckxkow4UGi/MT+DVAMkeIL6tbzvxDkIQdgCLQN7ayDRSMWg5/auAvULGiUUZHd2fCFyF5VO4FMaUQD6DXB7mzYBp7LXDMQbs8WjiVFeBFo8USZ6/Qld7NaaHhXYh4Agktw7wGv51vAiGKWNeJxZ3ILH9ZeubYGxc0SM5+IIVaVy9DCYdUAnlt2rcL/8mkrgUxUiz9C94aUgzYNwfX1++8lwprxgugEAWutpUGEyHZySKr8gbLn19uytfI2ueF2ZoxaNS/VxX+QQ5gTIBecAD3Jgy7Izs5Wx6HNngV0/qzVjsbGAzZz+fDfBF1A6EU6zZpeQqlcUkvyMXIS5I39OYsGCqOKxyVmiKZzLRk5e+y0ZvOucKYPE85oCsAp9wNv8J9RfIfXYKDBff9Q3NWC5PQr5rHrFuRlncGbMSyeurTbm6rGywqc/wgTPacvk+bkOiDf/txinsvoQHHtZpAAk5OueZu7Y+L8unn0AciUshXXbMrhVq2/w3uMh00qtqEa80d1uQdTXtx4udb54AFynz+b1vdRf+VRqv+01ZJcy57weecMuzh9K3kB+EVaK9rAvfXST5AxtmGuaHhDfdL789mlABNtjgupMZJp+FEm88slwws6Tdgatn8iP7RoVYbPcY+0Ck+KazDeb/mizMxCULSOmTxMuqmNjjSXJCiQrldHorXlguXSzM21I+NtdCtxGRcgVLk1xmL40+FSizoIuyEg3UfWdmd+JFHQDVL7RtlO2yM45lHQ6t2WZFRqsBHBukuMR6RVMF4vHUEqKVqg7UKU3HmMBrByhOy/UCYxdOVucfne3CaiKcWq+O826hf5+EMWqxD/mU6hJ3ufYjlcivWfJt5rYkRDUUfhzUpk7+62RYia8RGkH79IhiGoO4HiNoPjLxYfFbLiwC+LdqugXNsYFWPVmwQoGpaRlgroTDMlOj39qpR1s6NdlrLpFC0Lct0IXNMXiym18ZnRhRRV2X0YKnvtzMIHK7xJYws+8H0Pu+iMLmADBZLnziAQc5/t4JvHd8djzOxWrBvGVH+i7vZ2UygznSqu0qHRrm6vLnjpm8q6gaMZGAHH6AONzIYpB0PZW00jAYnNRAlbYohxakp4n8QJJBSn8knaIh9OfZqdxfj3uktNDxRitfLzjRvNvdANivoz8cBy4fqog3SUwFKtE8kosFqS3+rvgHV2JOSzRGvfEo/gCopxhqZkMFxUNdlI08rmv08V6rYOomXYZR61nFGGQC5mtE+FKTfuT0+fyor7nNNKtma6+T37KwMKePkVMC1iX2DP07cImYYuGhW9Gm9bwMpJ5H7Iyu515DeNcBqTPuwgk9zfLORI1PQUtWJiTVpgg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:11.6726 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ac751cf-6caf-4e3a-9d45-08dd3e00917a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8749 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Currently, when printing channel-level flags in the ethtool dump, we iterate over a list where each element represents a flag and a channel. The list is structured such that, for each channel, all elements with the same flag are grouped together. To accommodate future JSON support, where per-channel fields will be represented as an array (with each element corresponding to a specific channel), the presentation order needs to change. Additionally, the hard-coded channel numbers in the flag names should be removed. Signed-off-by: Danielle Ratson --- module-common.c | 168 ++++++++++++++++++++++++------------------------ qsfp.c | 26 ++++++-- 2 files changed, 104 insertions(+), 90 deletions(-) diff --git a/module-common.c b/module-common.c index ec61b1e..4146a84 100644 --- a/module-common.c +++ b/module-common.c @@ -87,112 +87,112 @@ const struct module_aw_chan module_aw_chan_flags[] = { CMIS_RX_PWR_AW_LWARN_OFFSET, CMIS_DIAG_CHAN_ADVER_OFFSET, CMIS_RX_PWR_MON_MASK }, - { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 1)", + { MODULE_TYPE_SFF8636, "Laser bias current high alarm", SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0,(SFF8636_TX_BIAS_1_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 1)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 2)", + { MODULE_TYPE_SFF8636, "Laser bias current high alarm", SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 2)", - SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 3)", + { MODULE_TYPE_SFF8636, "Laser bias current high alarm", SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 3)", - SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser bias current high alarm (Chan 4)", + { MODULE_TYPE_SFF8636, "Laser bias current high alarm", SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current low alarm (Chan 4)", + + { MODULE_TYPE_SFF8636, "Laser bias current low alarm", + SFF8636_TX_BIAS_12_AW_OFFSET, 0,(SFF8636_TX_BIAS_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser bias current low alarm", SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser bias current high warning (Chan 4)", + + { MODULE_TYPE_SFF8636, "Laser bias current high warning", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current high warning", SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser bias current low warning (Chan 4)", + + { MODULE_TYPE_SFF8636, "Laser bias current low warning", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_1_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning", + SFF8636_TX_BIAS_12_AW_OFFSET, 0, (SFF8636_TX_BIAS_2_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning", + SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_3_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser bias current low warning", SFF8636_TX_BIAS_34_AW_OFFSET, 0, (SFF8636_TX_BIAS_4_LWARN) }, - { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 1)", + { MODULE_TYPE_SFF8636, "Laser tx power high alarm", SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 1)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 2)", + { MODULE_TYPE_SFF8636, "Laser tx power high alarm", SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 2)", - SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 3)", + { MODULE_TYPE_SFF8636, "Laser tx power high alarm", SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 3)", - SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser tx power high alarm (Channel 4)", + { MODULE_TYPE_SFF8636, "Laser tx power high alarm", SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power low alarm (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser tx power low alarm", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser tx power low alarm", SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser tx power high warning (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser tx power high warning", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power high warning", SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser tx power low warning (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser tx power low warning", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_1_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning", + SFF8636_TX_PWR_12_AW_OFFSET, 0, (SFF8636_TX_PWR_2_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning", + SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_3_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser tx power low warning", SFF8636_TX_PWR_34_AW_OFFSET, 0, (SFF8636_TX_PWR_4_LWARN) }, - { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 1)", + { MODULE_TYPE_SFF8636, "Laser rx power high alarm", SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 1)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 2)", + { MODULE_TYPE_SFF8636, "Laser rx power high alarm", SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 2)", - SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 3)", + { MODULE_TYPE_SFF8636, "Laser rx power high alarm", SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 3)", - SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LWARN) }, - - { MODULE_TYPE_SFF8636, "Laser rx power high alarm (Channel 4)", + { MODULE_TYPE_SFF8636, "Laser rx power high alarm", SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_HALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power low alarm (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser rx power low alarm", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LALARM) }, + { MODULE_TYPE_SFF8636, "Laser rx power low alarm", SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_LALARM) }, - { MODULE_TYPE_SFF8636, "Laser rx power high warning (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser rx power high warning", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_HWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power high warning", SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_HWARN) }, - { MODULE_TYPE_SFF8636, "Laser rx power low warning (Channel 4)", + + { MODULE_TYPE_SFF8636, "Laser rx power low warning", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_1_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning", + SFF8636_RX_PWR_12_AW_OFFSET, 0, (SFF8636_RX_PWR_2_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning", + SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_3_LWARN) }, + { MODULE_TYPE_SFF8636, "Laser rx power low warning", SFF8636_RX_PWR_34_AW_OFFSET, 0, (SFF8636_RX_PWR_4_LWARN) }, { 0, NULL, 0, 0, 0 }, diff --git a/qsfp.c b/qsfp.c index 6c7e72c..674242c 100644 --- a/qsfp.c +++ b/qsfp.c @@ -711,13 +711,27 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) } if (sd.supports_alarms) { + bool value; + for (i = 0; module_aw_chan_flags[i].fmt_str; ++i) { - if (module_aw_chan_flags[i].type == MODULE_TYPE_SFF8636) - printf("\t%-41s : %s\n", - module_aw_chan_flags[i].fmt_str, - (map->lower_memory[module_aw_chan_flags[i].offset] - & module_aw_chan_flags[i].adver_value) ? - "On" : "Off"); + int j = 1; + + if (module_aw_chan_flags[i].type != MODULE_TYPE_SFF8636) + continue; + + do { + value = map->lower_memory[module_aw_chan_flags[i].offset] & + module_aw_chan_flags[i].adver_value; + printf("\t%-41s (Chan %d) : %s\n", + module_aw_chan_flags[i].fmt_str, j, + value ? "On" : "Off"); + j++; + i++; + } + while (module_aw_chan_flags[i].fmt_str && + strcmp(module_aw_chan_flags[i].fmt_str, + module_aw_chan_flags[i-1].fmt_str) == 0); + i--; } for (i = 0; module_aw_mod_flags[i].str; ++i) { if (module_aw_mod_flags[i].type == MODULE_TYPE_SFF8636) From patchwork Sun Jan 26 11:56:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950656 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2089.outbound.protection.outlook.com [40.107.243.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18F80156887 for ; Sun, 26 Jan 2025 11:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892641; cv=fail; b=GXmsMFzcWjAxWqS4qsPvllOUWYByr0z1cMUeTRbegPBZp5b9K+Y4B75ucSF6GuYaC3Hg8gb+NVPMPYA0KAv2UGYIElYi62EFP38NCyRrgELr+xQg61xpvWTlp2rb9n380UZJ3L5xIToMhG0xgcZJtzNMGaQTSHc9bAAaKXPjQwQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892641; c=relaxed/simple; bh=B9b1KRk8vbF2cPb+/ZmQHQkWE3WSmy7CrEpGg4Ttwr0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sYWOiYMP5z0zqGhdA2rJWmRX8Dv0ol3bMQI5aXE/Np/Bh+u4HhXJcWr52aQhzIXo/ZkFVv6z3Nk6QA9zggzd3a+vFUGzri7zmRjV3JGEzQOA5aKt9OU8szf8OpRJOf40ePWCGdodOLYc7m5vK57Bg+gUNy1p5lRGUxUicDQf7JQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=AKRO593+; arc=fail smtp.client-ip=40.107.243.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="AKRO593+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sn7MXKQe0yJdBlsYUkybFw1jc/kBOP+o+dJ+EILP/TGx49DvFZ3ArftaU8jiFC32rkppbCmVzQmgWFaZdu1Gy4oV/iA978GVyrE76RJLfdCAivt1v0h74nKcMRFkFT0yLVXWhDRvJrlH2ON1funUV8T5yOcX7ZIYLh1J5f3cH1cnP7qXgOnTVElUPoRU5507Ip14PQfbVP2cVQA9N+lMAsrrMqsOaOx5vxSY076ytBdeM8K5ULP6wsnZ5imkkpWDYoh2t/LEARZnTUwmo1uVC+HiLBYIDFcELYEF6jdAZMl9SZEauBO1OzUFtTN745QAtg+5BOSfpPe0NI5s1aeM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lNnf+WwWCcayBUN7V1Cv5Zvszg/6IYfXYvXWdFMM0AQ=; b=JDlu9TzAVjqYNOD2tT3QRf1HWHUIrzYhnr/Z7jqK3/g1u1qSnENGQpdOp64VZb28ORg3WsxPPCkl/Yk4uY3HAyMmIhgSJCy1V2GgWvaSgwXyMZ5NGyM0rMqPu5pRu59U8ufX/afGLO3xjrIKkfetWvnkUMPMGzbn1kYS4i24tXD/M8VoG0Uc0oHq61IpxGNNdBEWcCiPGs5su7wIGNi20xcdhcLdjUAUyd5in3nCKkDvV0fQf+gA8G+cdb6s05t+wQNw4YJSCvYkXuaPOxr951WXb6aKVTvyBoCWVZJ9aTYeq+s25fu3CWyMOqlhl09ia8PsQqK3ugcpymlihBzLXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lNnf+WwWCcayBUN7V1Cv5Zvszg/6IYfXYvXWdFMM0AQ=; b=AKRO593+50DsPzk1yK8Qk5XaTWPbayPczykp42d/yznOMJB6G7N2tFj5fjNwpuRaK/Wa+Rw+0B39tCEGqrbjlrT+pQ8gpZkLOF/CHRbq7vJ+/NFGjIhKJzG7dWzwFw3+XfBILUOHDg8K7GC2XDEW4nMYBS36SgPupJ4AQ/Q305e89/dEWMpWIWXhfjF3OvlW3MLWxYNu5aWUCnAE/zjPawE43e21bMvRGQZ4PrelfyS3zPPqtjA/xEsN5fRz2eOnX2EIn7rwl3Y8nckUcIz7wBf9atD5gUGFuu1jmxveyc1cCkYBRGMSTUKmgaaIZOnKrN2H/PKU2IRP6lcfJYqTgw== Received: from DM5PR08CA0041.namprd08.prod.outlook.com (2603:10b6:4:60::30) by MW4PR12MB7143.namprd12.prod.outlook.com (2603:10b6:303:222::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:15 +0000 Received: from CY4PEPF0000E9D0.namprd03.prod.outlook.com (2603:10b6:4:60:cafe::c2) by DM5PR08CA0041.outlook.office365.com (2603:10b6:4:60::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.18 via Frontend Transport; Sun, 26 Jan 2025 11:57:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9D0.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:02 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:00 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 05/14] qsfp: Refactor sff8636_show_dom() by moving code into separate functions Date: Sun, 26 Jan 2025 13:56:26 +0200 Message-ID: <20250126115635.801935-6-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D0:EE_|MW4PR12MB7143:EE_ X-MS-Office365-Filtering-Correlation-Id: a535135f-8a8f-43a4-28ec-08dd3e009377 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: OJ1dmFbUXwGU1eYbf8tphydYeRLPuBz8Jq1Yk9roKe5f7/oLXG60lcdFT1rwAHMFH0avSrme8ZXHtyTc3BaPZwvdpxCwnP3Pl3CIrU9KIzvZzDkFTQwwicW3Uom/aAYSUPZeCqABJQqOkXlI29Ubd1wHF2hZ76/N4zxO0q4jENO70LHgRNHY0w3tIgbVkOiqcC/zWheSanlpfeLRRUz8eMdYuWmcr1bJrEbriZPO+HUfr6zHYYBZUsUGb1+RN4ZOJ7w0zjt4Mai72+K1f9yjnGzeBIfWwmQoeFw5r3+Adbiwk4sqPfcJQXTER85xpNSx40RoqNis2eo9JaSJEFbsRJ0yUagNxqmtmZCx93GZBYOqShDddES/pf+T7GFXFe9qGno5S5xkquun/+OzvIkvnPjLyut3sRDjlTTwUyxJhbxfcxPZm3oCHQ22edZaYiTeNYQXTXfe8ReC1yqLzKXvGr7CVCFxEt2/QRc1M1+G43vnRRI5h+u6QQsbQwXoZ1Otv4s+Z88zSKFvGOyYqzQJITA11ecazMq1rC+FEy818bu5VpEA2yXeA2VrT7wFfsVtgphaAeXlpFqkzjI+Ssp6ZUKPJHcSu9Hpa0PVqYPfMlipQa6ngTcqMXmxHlN8yeXKA1w6yZrU5a1Ak0sq3NXItHsG7yqP23aCMVkPwBCRuu1ivvob5JpmZp2TtqEP025BL5TcUnR1MYnd+p5c9ljErbLv1/TyzWulyFdhQV5QhMSp1JXXNYhQIeXL3vd2XeVXNQB2LN18mDQ0wFaDHEi98XlCdjjQMO5WC4h+OyrOV4XncWMi4gbUlcQTbtVu5vJnulIFrYbDZjb5bN8BOC5ALc8UJYCj3Gc5PYl6lUYCcyPchpYT0HL+1I5v71I63oJ4kMANnfXvkwumOVFGIloxppwyUBKRbGc7Ok5LnC2s4xT+zayv5M5LIykPw0jtolmMs7hNLOX0LJTqvwOr6lhjnBSkP1CZP5dJIuoB7ykra/tLzttcRnJuKIwATGmxGg5wPNCUo0O+4vlP7humKHS+j82gk8/ocoxcLMbal4DzEzBbjTmmH3SQXj/HCSCsEXh+i8u3kYFaHK3Yed6YKgel91l2jJPB7vzjBxw0i+w8GJPgnPD1YRJS8L/UJ17nnp3CbnPHI/qyAvj7ez0F+qGkaUvBw8r60+/4orQ7FLa2mgSC288XzNH7dJEayQq0vxl4ExXwuAatXjoCXE27GiUvR3tBQUZdek3YQ/NU3q/Kg5WtFHdvX8AXoPDQJSTu3Vhm7fwGn5MNtrX7TPYErzPstAfO4BdUvLzlmSxuvMWg2Xt6W364UY71gj+33ud4FqC2tfk/W3hhrS/S3scLmHWwTJJAeSTLf1SpTvLgvElIho9zdzHBiSkXCfnbVoZnwOymrJRNw6nL4ClEc5WlWl3S3VLY/L01ZIcizsZaguzI1O2PE0qDrYCkcwRSCbyQcAxCJe8MGrs/H8QwllQnHR5ZCGNYfLFXmRbCAn5NBQI37h8= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:15.0054 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a535135f-8a8f-43a4-28ec-08dd3e009377 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7143 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz The sff8636_show_dom() function is quite lengthy, and with the planned addition of JSON support, it will become even longer and more complex. To improve readability and maintainability, refactor the function by moving portions of the code into separate functions, following the approach used in the cmis.c module. Signed-off-by: Danielle Ratson --- qsfp.c | 144 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 89 insertions(+), 55 deletions(-) diff --git a/qsfp.c b/qsfp.c index 674242c..13d8fb7 100644 --- a/qsfp.c +++ b/qsfp.c @@ -649,13 +649,94 @@ out: } } -static void sff8636_show_dom(const struct sff8636_memory_map *map) +static void sff8636_show_dom_chan_lvl_tx_bias(const struct sff_diags *sd) +{ + char power_string[MAX_DESC_SIZE]; + int i; + + for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + "Laser tx bias current", i+1); + PRINT_BIAS(power_string, sd->scd[i].bias_cur); + } +} + +static void sff8636_show_dom_chan_lvl_tx_power(const struct sff_diags *sd) +{ + char power_string[MAX_DESC_SIZE]; + int i; + + for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + "Transmit avg optical power", i+1); + PRINT_xX_PWR(power_string, sd->scd[i].tx_power); + } +} + +static void sff8636_show_dom_chan_lvl_rx_power(const struct sff_diags *sd) { - struct sff_diags sd = {0}; - char *rx_power_string = NULL; char power_string[MAX_DESC_SIZE]; + char *rx_power_string = NULL; + int i; + + if (!sd->rx_power_type) + rx_power_string = "Receiver signal OMA"; + else + rx_power_string = "Rcvr signal avg optical power"; + + for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + rx_power_string, i+1); + PRINT_xX_PWR(power_string, sd->scd[i].rx_power); + } +} + +static void +sff8636_show_dom_chan_lvl_flags(const struct sff8636_memory_map *map) +{ + bool value; int i; + for (i = 0; module_aw_chan_flags[i].fmt_str; ++i) { + int j = 1; + + if (module_aw_chan_flags[i].type != MODULE_TYPE_SFF8636) + continue; + + do { + value = map->lower_memory[module_aw_chan_flags[i].offset] & + module_aw_chan_flags[i].adver_value; + printf("\t%-41s (Chan %d) : %s\n", + module_aw_chan_flags[i].fmt_str, j, + ONOFF(value)); + j++; + i++; + } + while (module_aw_chan_flags[i].fmt_str && + strcmp(module_aw_chan_flags[i].fmt_str, + module_aw_chan_flags[i-1].fmt_str) == 0); + i--; + } +} + +static void +sff8636_show_dom_mod_lvl_flags(const struct sff8636_memory_map *map) +{ + int i; + + for (i = 0; module_aw_mod_flags[i].str; ++i) { + if (module_aw_mod_flags[i].type == MODULE_TYPE_SFF8636) + printf("\t%-41s : %s\n", + module_aw_mod_flags[i].str, + ONOFF(map->lower_memory[module_aw_mod_flags[i].offset] + & module_aw_mod_flags[i].value)); + } +} + +static void sff8636_show_dom(const struct sff8636_memory_map *map) +{ + struct sff_diags sd = {0}; + /* * There is no clear identifier to signify the existence of * optical diagnostics similar to SFF-8472. So checking existence @@ -687,60 +768,13 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) printf("\t%-41s : %s\n", "Alarm/warning flags implemented", (sd.supports_alarms ? "Yes" : "No")); - for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", - "Laser tx bias current", i+1); - PRINT_BIAS(power_string, sd.scd[i].bias_cur); - } - - for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", - "Transmit avg optical power", i+1); - PRINT_xX_PWR(power_string, sd.scd[i].tx_power); - } - - if (!sd.rx_power_type) - rx_power_string = "Receiver signal OMA"; - else - rx_power_string = "Rcvr signal avg optical power"; - - for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s(Channel %d)", - rx_power_string, i+1); - PRINT_xX_PWR(power_string, sd.scd[i].rx_power); - } + sff8636_show_dom_chan_lvl_tx_bias(&sd); + sff8636_show_dom_chan_lvl_tx_power(&sd); + sff8636_show_dom_chan_lvl_rx_power(&sd); if (sd.supports_alarms) { - bool value; - - for (i = 0; module_aw_chan_flags[i].fmt_str; ++i) { - int j = 1; - - if (module_aw_chan_flags[i].type != MODULE_TYPE_SFF8636) - continue; - - do { - value = map->lower_memory[module_aw_chan_flags[i].offset] & - module_aw_chan_flags[i].adver_value; - printf("\t%-41s (Chan %d) : %s\n", - module_aw_chan_flags[i].fmt_str, j, - value ? "On" : "Off"); - j++; - i++; - } - while (module_aw_chan_flags[i].fmt_str && - strcmp(module_aw_chan_flags[i].fmt_str, - module_aw_chan_flags[i-1].fmt_str) == 0); - i--; - } - for (i = 0; module_aw_mod_flags[i].str; ++i) { - if (module_aw_mod_flags[i].type == MODULE_TYPE_SFF8636) - printf("\t%-41s : %s\n", - module_aw_mod_flags[i].str, - (map->lower_memory[module_aw_mod_flags[i].offset] - & module_aw_mod_flags[i].value) ? - "On" : "Off"); - } + sff8636_show_dom_chan_lvl_flags(map); + sff8636_show_dom_mod_lvl_flags(map); sff_show_thresholds(sd); } From patchwork Sun Jan 26 11:56:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950657 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2054.outbound.protection.outlook.com [40.107.243.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 045F1156C6F for ; Sun, 26 Jan 2025 11:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892648; cv=fail; b=LTKxqwpIu3gxFFLk88WgE/dwhIyMSrBCf2MSt3MmzqoiauGh0nDSnvIpIv3MQoZbFfbBzroOUMVptB9oHxmNz9Ta0zgSQTQx/N1obZvWncqVqXBDB/oa6iWCUlxEP1BBK1X85PkzOnyLVCdOX7CRir0P96InFgl8WIxPHW5HME4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892648; c=relaxed/simple; bh=1nEktTpVz7IrCEybBH8GyMY3kGTwiZVWFjZP1ZqlcDE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VwnjWEfrralaIQS23i6OFjPEahSuJYPsPjBw7xxxZ8v0YMyYkdQKOIw00tFknajElnzPhC9aonN53+21taYG/qryKWnydlJdSQAgTYlCpgpKoyumnSWmRVqWgyVdhGhj1ZEIXHzwUfT+FU6HM4qoA8pPi/H4vx6VST5JRlnQmpY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=pdiPzRxf; arc=fail smtp.client-ip=40.107.243.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="pdiPzRxf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=glUG64xVavuCh4zpvbDCe+p/tqF1jlOtrVTbvFku8ysZ8tU6rp1tT76QeKoGzNMQmSEzzEpp5Q3+7oB9nHcrPe8GEc6aUL9i3IrpaXnVh4LMOWg7Pbc+KZTrHO061aTWHFn9lcEBOoxlT9tuuQlHLg1Mbw3kIpOzAEcyL0m6w8OCH05hh5pkBIpfP7fdQSSGPtAw3Hpo3TJgVjfaXD+kTWarNaKuQEuSokSzB4m0UnI28Y14Wo8WzV7yWeftphxawPtCuMdv8yRVNS2+eq+1pNVYqgCy3uJuQC+/V7aDP0BLJ/pmRvSRCzRXZdS/7BqLO1npzOoqCb3vEnjvIlO1TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FC6dvvx5mRKHvoXcOQVZPTlnMPRhfjKfGgjK+JtWd7Y=; b=tdwABiU7XWs0OUCINaYYhOdkeBsf1G+1jX/Oe1hnJ0hdEaxw5mgJBU/kwFI0MLkyu08I44PNyYfF5CKvWyfkhCFmN+K3r6Jo5ngDAxB8NpntGo52GR9oU3EbvUwJFWjrRi6C+Y/wu+fxCKGzQXSyGnvUzr5XCDx5Lyy6p2ephD8cDVwxXbzJmXLkCf3vJw7Yc4wsfPvb3IyR4XUzzNgoLtI9XJHKZsphlCyDFXVP5Q0HnOAGjrIchgOKc2XGfh1uWr0UpAi5KRoGpvN1JH/39ilDb/bfBFRqW78nirM7kX/abZ8cZax+cjaI1bK2SJ+ZAKZBfDyYapteonrb2+b+MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FC6dvvx5mRKHvoXcOQVZPTlnMPRhfjKfGgjK+JtWd7Y=; b=pdiPzRxfXkli8VUnTa9aTSCQTbE/PXcrIZ7431uph3PF/jmlKaXCHDJgxDOg5CPqxBQfWpSoboD9tvYOGmeijvoU8vwF21NWpPFIc+uf7tfFvPHO/kr50UVztNj3baBZsbZnSFFiFEfD2d/2Ysj/PgnJnh9KHIp/uOyxEejdLpyPxhNGbWiooV9pW8YGbxHg60MX1zvglRx95ASBqexVPCQdqJQhsfPgieyS2K0h8B8pYoe+X9FEwMMEH/6aMT0zu/H2+ncubRC4WU7FSWJ0Vcv3avBEa1Z6WfRBqe4Ks5F2TWrZZbI5PKjOOwsNc97zl/w/t0pmOtIZy0ZudorY3w== Received: from CYZPR11CA0001.namprd11.prod.outlook.com (2603:10b6:930:8d::28) by MW4PR12MB6999.namprd12.prod.outlook.com (2603:10b6:303:20a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:20 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:930:8d:cafe::27) by CYZPR11CA0001.outlook.office365.com (2603:10b6:930:8d::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:20 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:05 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:02 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 06/14] module_common: Add helpers to support JSON printing for common value types Date: Sun, 26 Jan 2025 13:56:27 +0200 Message-ID: <20250126115635.801935-7-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|MW4PR12MB6999:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b744070-507b-4495-cb63-08dd3e009684 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: GA5e0/WR5VyhwvaBS1CiRLLQJ5+Nxc9/QRpmMC1WCwhTrmfh4XkoOD62dPESDTU1ZD2G5Y1QJ/Gz//b15dXl0HS9jIfjFRvKwHGs2ycbbuUX9RioposGOydWIT1k2Kx5hqrr8fHjUMig3JGUFNKHXUIsHs5L2TBjGif8YE06guw/9hiBZUvsiFzlbv7OX1nxAPu8eUd3oOLK+OES8/yiMOw8kz25s+9j9dng4vLajQ37/RkXrC4fU2jfoYMY6Gj99w12BiJ5snll26xsoZb2MnOfrivcA+5ramUDJiCu0rNJjaM7p99wuNlwhG0GWWMA0CHC0AF8q6+RwOb6AoT0eO3I8gwcLbv9swvfJJqcGwW1Ol7kdSDcoFzSwBJzLffSOXbrUrm+YT1m5l7Cdyk37nS+fkX0RSDO/QGygHtygI6KuM5BDQCW0oqFGA7uMtiffi/1Tcgdw1XmUHLBm4yvtcQs5uEheQ9ZPA2RVdIq7L+vYy9shI4NEv/YBfQCiZw9/2voErPs+u1cu5Bf8TNpLSJX6JsS9iN8T6uipozaFqJOl3y/3iwyzUiqNeEKetIBTJP3WZWJLj9XFGEBR3tBBtwokgbRzvfMezX4GFn6APWpL1LnC+9pG5REoUBRK7cIQUf/5N5WvxAxFv1DVSTYg6MEHsmn903cTLPamCbMOCo+/+3dUWBSaEg9lcKSvcqFesdoxz2+p1nyP5qNw0zoA004aG5WM6kRru+nseAQn1jJDk4U48aeZSzGj7h1+TjP/1qjpQE0LTmUzrHdl+jyMxW6ckzU108fNxSA3NrElcIjld9CqUtnnIX0i88fMnYL01zcDS88YbhFeQfc9OEjfQcpghtligEQIRPKHqWhCPbnKqndvV39mflBiaCq/urNyOylUXqgQTYTmyP2eVxwM+o4iBua+XkFGuFDsQnTQ2f6sb7tnyIzLr8rW2+WzuDKWwSLW2X6GRITV3esxFecLGSj/ITI+vBWp6JC6gFhLcl8TsLl84ZlWRvhWdYlUQzaERii8QrE8zNHt1NHmxOt9BXtBNdl3bmex6RfU7TXHk0ZJZvHHTUui+jBU8USN8Ay+oRMv7TYltUbyUH3ZirHFbV0Un/twQRJ3t/ri6Cz2t/K3NEzQpjkys0UVCq868vYSNtMr7y53xIxSHSWfaZqMljHwUg6YK+IPJdkS6h1uBiLM7D3VBaeXDeJK7U7YSEGHX120wle2u2ZOXXLy8GhBdENOoVEQrvRLykiHb3yN+dDQtuzyBLxcafgpgTm1w1CHan99kdMQ1FTFk8Bwd2jb/qwVDCSpsbB12KCErz0oAf86M5uUVWw2GwzVxizPfCKzYKmcPFh/It64Zmo7qKfuW4W/xbOJLijB7TwIN4Kt0NbTgPoAcMj58whYU4NQ0n3mSpj/bEtrjf4TnJUtiyj2X0KDPosvabjkX9/Rboanxvc2+VTWY7aM0bAHBcjAjiHptNtKndoRtalMz08fodCcSZ2gi9iLSUJ1RbxlL16BTg= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:20.1124 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b744070-507b-4495-cb63-08dd3e009684 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6999 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Upcoming patches will introduce JSON support to the ethtool dump. The ethtool dump currently handles various field types, including strings, unsigned integers, floats, etc. To facilitate this transition, implement helper functions for commonly used types. These helpers will enable consistent printing for both JSON and regular dump formats. In addition, add JSON support for common functions and defines to use in the upcoming patches. Signed-off-by: Danielle Ratson --- module-common.c | 367 ++++++++++++++++++++++++++++++++++++------------ module-common.h | 7 + sff-common.c | 98 +++++++++++-- sff-common.h | 41 ++++++ 4 files changed, 407 insertions(+), 106 deletions(-) diff --git a/module-common.c b/module-common.c index 4146a84..e6fbbb2 100644 --- a/module-common.c +++ b/module-common.c @@ -5,6 +5,7 @@ #include #include +#include #include "module-common.h" const struct module_aw_mod module_aw_mod_flags[] = { @@ -198,309 +199,491 @@ const struct module_aw_chan module_aw_chan_flags[] = { { 0, NULL, 0, 0, 0 }, }; +void convert_json_field_name(const char *str, char *json_str) +{ + for (size_t i = 0; i < strlen(str); i++) + json_str[i] = (str[i] == ' ') ? + '_' : tolower((unsigned char)str[i]); +} + +void module_print_any_units(const char *json_fn, const char *unit) +{ + char units_fn[64]; + + sprintf(units_fn, "%s_units", json_fn); + + if (is_json_context()) { + if (unit) + print_string(PRINT_JSON, units_fn, "%s", unit); + } else { + if (unit) + printf("%s", unit); + } +} + +void module_print_any_uint(const char *fn, int value, const char *unit) +{ + char json_fn[100] = ""; + + if (is_json_context()) { + convert_json_field_name(fn, json_fn); + print_uint(PRINT_JSON, json_fn, "%u", value); + } else { + printf("\t%-41s : %u", fn, value); + } + + if (unit) + module_print_any_units(json_fn, unit); + print_nl(); +} + +void module_print_any_string(const char *fn, const char *value) +{ + char json_fn[100] = ""; + + if (is_json_context()) { + convert_json_field_name(fn, json_fn); + print_string(PRINT_JSON, json_fn, "%s", value); + } else { + printf("\t%-41s : %s\n", fn, value); + } +} + +void module_print_any_float(const char *fn, float value, const char *unit) +{ + char json_fn[100] = ""; + + if (is_json_context()) { + convert_json_field_name(fn, json_fn); + print_float(PRINT_JSON, json_fn, "%.04f", value); + } else { + printf("\t%-41s : %.04f", fn, value); + } + + if (unit) + module_print_any_units(json_fn, unit); + print_nl(); +} + +void module_print_any_bool(const char *fn, char *given_json_fn, bool value, + const char *str_value) +{ + char json_fn[100] = ""; + + if (!given_json_fn) + convert_json_field_name(fn, json_fn); + else + strcpy(json_fn, given_json_fn); + + if (is_json_context()) + print_bool(PRINT_JSON, json_fn, NULL, value); + else + printf("\t%-41s : %s\n", fn, str_value); +} + void module_show_value_with_unit(const __u8 *id, unsigned int reg, const char *name, unsigned int mult, const char *unit) { unsigned int val = id[reg]; - printf("\t%-41s : %u%s\n", name, val * mult, unit); + module_print_any_uint(name, val * mult, unit); } void module_show_ascii(const __u8 *id, unsigned int first_reg, unsigned int last_reg, const char *name) { + char json_fn[100] = ""; + char val_str[32] = ""; unsigned int reg, val; - printf("\t%-41s : ", name); + if (is_json_context()) + convert_json_field_name(name, json_fn); + else + printf("\t%-41s : ", name); + while (first_reg <= last_reg && id[last_reg] == ' ') last_reg--; for (reg = first_reg; reg <= last_reg; reg++) { + char val_char; + val = id[reg]; - putchar(((val >= 32) && (val <= 126)) ? val : '_'); + val_char = (char)val; + + if (is_json_context()) + val_str[reg - first_reg] = (((val >= 32) && (val <= 126)) ? + val_char : '_'); + else + putchar(((val >= 32) && (val <= 126)) ? val : '_'); } - printf("\n"); + + if (is_json_context()) + print_string(PRINT_JSON, json_fn, "%s", val_str); + else + printf("\n"); } void module_show_lane_status(const char *name, unsigned int lane_cnt, const char *yes, const char *no, unsigned int value) { - printf("\t%-41s : ", name); + char json_fn[100] = ""; + + convert_json_field_name(name, json_fn); + if (!value) { - printf("None\n"); + if (is_json_context()) + print_string(PRINT_JSON, json_fn, NULL, "None"); + else + printf("\t%-41s : None\n", name); return; } - printf("["); - while (lane_cnt--) { - printf(" %s%c", value & 1 ? yes : no, lane_cnt ? ',': ' '); - value >>= 1; + if (is_json_context()) { + open_json_array(json_fn, ""); + + while (lane_cnt--) { + print_string(PRINT_JSON, NULL, "%s", + value & 1 ? yes : no); + value >>= 1; + } + close_json_array(""); + } else { + printf("\t%-41s : [", name); + while (lane_cnt--) { + printf(" %s%c", value & 1 ? yes : no, lane_cnt ? ',': ' '); + value >>= 1; + } + printf("]\n"); } - printf("]\n"); } void module_show_oui(const __u8 *id, int id_offset) { - printf("\t%-41s : %02x:%02x:%02x\n", "Vendor OUI", - id[id_offset], id[(id_offset) + 1], - id[(id_offset) + 2]); + char oui_value[16]; + + if (is_json_context()) { + open_json_array("vendor_oui", ""); + print_int(PRINT_JSON, NULL, NULL, id[id_offset]); + print_int(PRINT_JSON, NULL, NULL, id[(id_offset) + 1]); + print_int(PRINT_JSON, NULL, NULL, id[(id_offset) + 2]); + close_json_array(""); + } else { + snprintf(oui_value, 16, "%02x:%02x:%02x", id[id_offset], + id[(id_offset) + 1], id[(id_offset) + 2]); + printf("\t%-41s : %s\n", "Vendor OUI", oui_value); + } } void module_show_identifier(const __u8 *id, int id_offset) { - printf("\t%-41s : 0x%02x", "Identifier", id[id_offset]); + char id_description[SFF_MAX_DESC_LEN]; + switch (id[id_offset]) { case MODULE_ID_UNKNOWN: - printf(" (no module present, unknown, or unspecified)\n"); + strncpy(id_description, + "no module present, unknown, or unspecified", + SFF_MAX_DESC_LEN); break; case MODULE_ID_GBIC: - printf(" (GBIC)\n"); + strncpy(id_description, "GBIC", SFF_MAX_DESC_LEN); break; case MODULE_ID_SOLDERED_MODULE: - printf(" (module soldered to motherboard)\n"); + strncpy(id_description, + "module soldered to motherboard", SFF_MAX_DESC_LEN); break; case MODULE_ID_SFP: - printf(" (SFP)\n"); + strncpy(id_description, "SFP", SFF_MAX_DESC_LEN); break; case MODULE_ID_300_PIN_XBI: - printf(" (300 pin XBI)\n"); + strncpy(id_description, "300 pin XBI", SFF_MAX_DESC_LEN); break; case MODULE_ID_XENPAK: - printf(" (XENPAK)\n"); + strncpy(id_description, "XENPAK", SFF_MAX_DESC_LEN); break; case MODULE_ID_XFP: - printf(" (XFP)\n"); + strncpy(id_description, "XFP", SFF_MAX_DESC_LEN); break; case MODULE_ID_XFF: - printf(" (XFF)\n"); + strncpy(id_description, "XFF", SFF_MAX_DESC_LEN); break; case MODULE_ID_XFP_E: - printf(" (XFP-E)\n"); + strncpy(id_description, "XFP-E", SFF_MAX_DESC_LEN); break; case MODULE_ID_XPAK: - printf(" (XPAK)\n"); + strncpy(id_description, "XPAK", SFF_MAX_DESC_LEN); break; case MODULE_ID_X2: - printf(" (X2)\n"); + strncpy(id_description, "X2", SFF_MAX_DESC_LEN); break; case MODULE_ID_DWDM_SFP: - printf(" (DWDM-SFP)\n"); + strncpy(id_description, "DWDM-SFP", SFF_MAX_DESC_LEN); break; case MODULE_ID_QSFP: - printf(" (QSFP)\n"); + strncpy(id_description, "QSFP", SFF_MAX_DESC_LEN); break; case MODULE_ID_QSFP_PLUS: - printf(" (QSFP+)\n"); + strncpy(id_description, "QSFP+", SFF_MAX_DESC_LEN); break; case MODULE_ID_CXP: - printf(" (CXP)\n"); + strncpy(id_description, "CXP", SFF_MAX_DESC_LEN); break; case MODULE_ID_HD4X: - printf(" (Shielded Mini Multilane HD 4X)\n"); + strncpy(id_description, "Shielded Mini Multilane HD 4X", + SFF_MAX_DESC_LEN); break; case MODULE_ID_HD8X: - printf(" (Shielded Mini Multilane HD 8X)\n"); + strncpy(id_description, "Shielded Mini Multilane HD 8X", + SFF_MAX_DESC_LEN); break; case MODULE_ID_QSFP28: - printf(" (QSFP28)\n"); + strncpy(id_description, "QSFP28", SFF_MAX_DESC_LEN); break; case MODULE_ID_CXP2: - printf(" (CXP2/CXP28)\n"); + strncpy(id_description, "CXP2/CXP28", SFF_MAX_DESC_LEN); break; case MODULE_ID_CDFP: - printf(" (CDFP Style 1/Style 2)\n"); + strncpy(id_description, "CDFP Style 1/Style 2", + SFF_MAX_DESC_LEN); break; case MODULE_ID_HD4X_FANOUT: - printf(" (Shielded Mini Multilane HD 4X Fanout Cable)\n"); + strncpy(id_description, + "Shielded Mini Multilane HD 4X Fanout Cable", + SFF_MAX_DESC_LEN); break; case MODULE_ID_HD8X_FANOUT: - printf(" (Shielded Mini Multilane HD 8X Fanout Cable)\n"); + strncpy(id_description, + "Shielded Mini Multilane HD 8X Fanout Cable", + SFF_MAX_DESC_LEN); break; case MODULE_ID_CDFP_S3: - printf(" (CDFP Style 3)\n"); + strncpy(id_description, "CDFP Style 3", SFF_MAX_DESC_LEN); break; case MODULE_ID_MICRO_QSFP: - printf(" (microQSFP)\n"); + strncpy(id_description, "microQSFP", SFF_MAX_DESC_LEN); break; case MODULE_ID_QSFP_DD: - printf(" (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))\n"); + strncpy(id_description, + "QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628)", + SFF_MAX_DESC_LEN); break; case MODULE_ID_OSFP: - printf(" (OSFP 8X Pluggable Transceiver)\n"); + strncpy(id_description, "OSFP 8X Pluggable Transceiver", + SFF_MAX_DESC_LEN); break; case MODULE_ID_DSFP: - printf(" (DSFP Dual Small Form Factor Pluggable Transceiver)\n"); + strncpy(id_description, + "DSFP Dual Small Form Factor Pluggable Transceiver", + SFF_MAX_DESC_LEN); break; case MODULE_ID_QSFP_PLUS_CMIS: - printf(" (QSFP+ or later with Common Management Interface Specification (CMIS))\n"); + strncpy(id_description, + "QSFP+ or later with Common Management Interface Specification (CMIS)", + SFF_MAX_DESC_LEN); break; case MODULE_ID_SFP_DD_CMIS: - printf(" (SFP-DD Double Density 2X Pluggable Transceiver with Common Management Interface Specification (CMIS))\n"); + strncpy(id_description, + "SFP-DD Double Density 2X Pluggable Transceiver with Common Management Interface Specification (CMIS)", + SFF_MAX_DESC_LEN); break; case MODULE_ID_SFP_PLUS_CMIS: - printf(" (SFP+ and later with Common Management Interface Specification (CMIS))\n"); + strncpy(id_description, + "SFP+ and later with Common Management Interface Specification (CMIS)", + SFF_MAX_DESC_LEN); break; default: - printf(" (reserved or unknown)\n"); + strncpy(id_description, "reserved or unknown", + SFF_MAX_DESC_LEN); break; } + + sff_print_any_hex_field("Identifier", "identifier", id[id_offset], + id_description); } void module_show_connector(const __u8 *id, int ctor_offset) { - printf("\t%-41s : 0x%02x", "Connector", id[ctor_offset]); + char ctor_description[SFF_MAX_DESC_LEN]; + switch (id[ctor_offset]) { case MODULE_CTOR_UNKNOWN: - printf(" (unknown or unspecified)\n"); + strncpy(ctor_description, "unknown or unspecified", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_SC: - printf(" (SC)\n"); + strncpy(ctor_description, "SC", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_FC_STYLE_1: - printf(" (Fibre Channel Style 1 copper)\n"); + strncpy(ctor_description, "Fibre Channel Style 1 copper", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_FC_STYLE_2: - printf(" (Fibre Channel Style 2 copper)\n"); + strncpy(ctor_description, "Fibre Channel Style 2 copper", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_BNC_TNC: - printf(" (BNC/TNC)\n"); + strncpy(ctor_description, "BNC/TNC", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_FC_COAX: - printf(" (Fibre Channel coaxial headers)\n"); + strncpy(ctor_description, "Fibre Channel coaxial headers", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_FIBER_JACK: - printf(" (FibreJack)\n"); + strncpy(ctor_description, "FibreJack", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_LC: - printf(" (LC)\n"); + strncpy(ctor_description, "LC", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MT_RJ: - printf(" (MT-RJ)\n"); + strncpy(ctor_description, "MT-RJ", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MU: - printf(" (MU)\n"); + strncpy(ctor_description, "MU", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_SG: - printf(" (SG)\n"); + strncpy(ctor_description, "SG", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_OPT_PT: - printf(" (Optical pigtail)\n"); + strncpy(ctor_description, "Optical pigtail", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MPO: - printf(" (MPO Parallel Optic)\n"); + strncpy(ctor_description, "MPO Parallel Optic", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MPO_2: - printf(" (MPO Parallel Optic - 2x16)\n"); + strncpy(ctor_description, "MPO Parallel Optic - 2x16", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_HSDC_II: - printf(" (HSSDC II)\n"); + strncpy(ctor_description, "HSSDC II", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_COPPER_PT: - printf(" (Copper pigtail)\n"); + strncpy(ctor_description, "Copper pigtail", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_RJ45: - printf(" (RJ45)\n"); + strncpy(ctor_description, "RJ45", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_NO_SEPARABLE: - printf(" (No separable connector)\n"); + strncpy(ctor_description, "No separable connector", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MXC_2x16: - printf(" (MXC 2x16)\n"); + strncpy(ctor_description, "MXC 2x16", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_CS_OPTICAL: - printf(" (CS optical connector)\n"); + strncpy(ctor_description, "CS optical connector", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_CS_OPTICAL_MINI: - printf(" (Mini CS optical connector)\n"); + strncpy(ctor_description, "Mini CS optical connector", + SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MPO_2X12: - printf(" (MPO 2x12)\n"); + strncpy(ctor_description, "MPO 2x12", SFF_MAX_DESC_LEN); break; case MODULE_CTOR_MPO_1X16: - printf(" (MPO 1x16)\n"); + strncpy(ctor_description, "MPO 1x16", SFF_MAX_DESC_LEN); break; default: - printf(" (reserved or unknown)\n"); + strncpy(ctor_description, "reserved or unknown", + SFF_MAX_DESC_LEN); break; } + + sff_print_any_hex_field("Connector", "connector", id[ctor_offset], + ctor_description); } void module_show_mit_compliance(u16 value) { - static const char *cc = " (Copper cable,"; - - printf("\t%-41s : 0x%02x", "Transmitter technology", value); + static const char *cc = "Copper cable,"; + char description[SFF_MAX_DESC_LEN]; switch (value) { case MODULE_850_VCSEL: - printf(" (850 nm VCSEL)\n"); + strncpy(description, "850 nm VCSEL", SFF_MAX_DESC_LEN); break; case CMIS_1310_VCSEL: case SFF8636_TRANS_1310_VCSEL: - printf(" (1310 nm VCSEL)\n"); + strncpy(description, "1310 nm VCSEL", SFF_MAX_DESC_LEN); break; case CMIS_1550_VCSEL: case SFF8636_TRANS_1550_VCSEL: - printf(" (1550 nm VCSEL)\n"); + strncpy(description, "1550 nm VCSEL", SFF_MAX_DESC_LEN); break; case CMIS_1310_FP: case SFF8636_TRANS_1310_FP: - printf(" (1310 nm FP)\n"); + strncpy(description, "1310 nm FP", SFF_MAX_DESC_LEN); break; case CMIS_1310_DFB: case SFF8636_TRANS_1310_DFB: - printf(" (1310 nm DFB)\n"); + strncpy(description, "1310 nm DFB", SFF_MAX_DESC_LEN); break; case CMIS_1550_DFB: case SFF8636_TRANS_1550_DFB: - printf(" (1550 nm DFB)\n"); + strncpy(description, "1550 nm DFB", SFF_MAX_DESC_LEN); break; case CMIS_1310_EML: case SFF8636_TRANS_1310_EML: - printf(" (1310 nm EML)\n"); + strncpy(description, "1310 nm EML", SFF_MAX_DESC_LEN); break; case CMIS_1550_EML: case SFF8636_TRANS_1550_EML: - printf(" (1550 nm EML)\n"); + strncpy(description, "1550 nm EML", SFF_MAX_DESC_LEN); break; case CMIS_OTHERS: case SFF8636_TRANS_OTHERS: - printf(" (Others/Undefined)\n"); + strncpy(description, "Others/Undefined", SFF_MAX_DESC_LEN); break; case CMIS_1490_DFB: case SFF8636_TRANS_1490_DFB: - printf(" (1490 nm DFB)\n"); + strncpy(description, "1490 nm DFB", SFF_MAX_DESC_LEN); break; case CMIS_COPPER_UNEQUAL: case SFF8636_TRANS_COPPER_PAS_UNEQUAL: - printf("%s unequalized)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, "%s unequalized", cc); break; case CMIS_COPPER_PASS_EQUAL: case SFF8636_TRANS_COPPER_PAS_EQUAL: - printf("%s passive equalized)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, "%s passive equalized", + cc); break; case CMIS_COPPER_NF_EQUAL: case SFF8636_TRANS_COPPER_LNR_FAR_EQUAL: - printf("%s near and far end limiting active equalizers)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, + "%s near and far end limiting active equalizers", cc); break; case CMIS_COPPER_F_EQUAL: case SFF8636_TRANS_COPPER_FAR_EQUAL: - printf("%s far end limiting active equalizers)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, + "%s far end limiting active equalizers", cc); break; case CMIS_COPPER_N_EQUAL: case SFF8636_TRANS_COPPER_NEAR_EQUAL: - printf("%s near end limiting active equalizers)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, + "%s near end limiting active equalizers", cc); break; case CMIS_COPPER_LINEAR_EQUAL: case SFF8636_TRANS_COPPER_LNR_EQUAL: - printf("%s linear active equalizers)\n", cc); + snprintf(description, SFF_MAX_DESC_LEN, "%s linear active equalizers", + cc); break; } + + sff_print_any_hex_field("Transmitter technology", + "transmitter_technology", value, description); } void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd) { - PRINT_TEMP("Module temperature", sd->sfp_temp[MCURR]); - PRINT_VCC("Module voltage", sd->sfp_voltage[MCURR]); + PRINT_TEMP_ALL("Module temperature", "module_temperature", + sd->sfp_temp[MCURR]); + print_string(PRINT_JSON, "module_temperature_units", "%s", "degrees C"); + + + PRINT_VCC_ALL("Module voltage", "module_voltage", + sd->sfp_voltage[MCURR]); + print_string(PRINT_JSON, "module_voltage_units", "%s", "V"); } diff --git a/module-common.h b/module-common.h index 8c34779..9c0adbb 100644 --- a/module-common.h +++ b/module-common.h @@ -264,6 +264,13 @@ struct module_aw_chan { extern const struct module_aw_mod module_aw_mod_flags[]; extern const struct module_aw_chan module_aw_chan_flags[]; +void convert_json_field_name(const char *str, char *json_str); +void module_print_any_units(const char *json_fn, const char *unit); +void module_print_any_uint(const char *fn, int value, const char *unit); +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_show_value_with_unit(const __u8 *id, unsigned int reg, const char *name, unsigned int mult, const char *unit); diff --git a/sff-common.c b/sff-common.c index e2f2463..fb3945c 100644 --- a/sff-common.c +++ b/sff-common.c @@ -29,50 +29,120 @@ double convert_mw_to_dbm(double mw) return (10. * log10(mw / 1000.)) + 30.; } +void sff_print_any_hex_field(const char *field_name, + const char *json_field_name, u8 value, + const char *desc) +{ + char desc_name[SFF_MAX_FIELD_LEN]; + + if (is_json_context()) { + print_int(PRINT_JSON, json_field_name, "0x%02x", value); + if (desc) { + snprintf(desc_name, SFF_MAX_FIELD_LEN, + "%s_description", json_field_name); + print_string(PRINT_JSON, desc_name, "%s", desc); + } + } else { + printf("\t%-41s : 0x%02x", field_name, value); + if (desc) + printf(" (%s)", desc); + print_nl(); + } +} + void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type) { - printf("\t%-41s : 0x%02x", "Encoding", id[encoding_offset]); + char encoding_desc[64]; + switch (id[encoding_offset]) { case SFF8024_ENCODING_UNSPEC: - printf(" (unspecified)\n"); + strncpy(encoding_desc, "unspecified", 64); break; case SFF8024_ENCODING_8B10B: - printf(" (8B/10B)\n"); + strncpy(encoding_desc, "8B/10B", 64); break; case SFF8024_ENCODING_4B5B: - printf(" (4B/5B)\n"); + strncpy(encoding_desc, "4B/5B", 64); break; case SFF8024_ENCODING_NRZ: - printf(" (NRZ)\n"); + strncpy(encoding_desc, "NRZ", 64); break; case SFF8024_ENCODING_4h: if (sff_type == ETH_MODULE_SFF_8472) - printf(" (Manchester)\n"); + strncpy(encoding_desc, "Manchester", 64); else if (sff_type == ETH_MODULE_SFF_8636) - printf(" (SONET Scrambled)\n"); + strncpy(encoding_desc, "SONET Scrambled", 64); break; case SFF8024_ENCODING_5h: if (sff_type == ETH_MODULE_SFF_8472) - printf(" (SONET Scrambled)\n"); + strncpy(encoding_desc, "SONET Scrambled", 64); else if (sff_type == ETH_MODULE_SFF_8636) - printf(" (64B/66B)\n"); + strncpy(encoding_desc, "64B/66B", 64); break; case SFF8024_ENCODING_6h: if (sff_type == ETH_MODULE_SFF_8472) - printf(" (64B/66B)\n"); + strncpy(encoding_desc, "64B/66B", 64); else if (sff_type == ETH_MODULE_SFF_8636) - printf(" (Manchester)\n"); + strncpy(encoding_desc, "Manchester", 64); break; case SFF8024_ENCODING_256B: - printf(" ((256B/257B (transcoded FEC-enabled data))\n"); + strncpy(encoding_desc, + "256B/257B (transcoded FEC-enabled data)", 64); break; case SFF8024_ENCODING_PAM4: - printf(" (PAM4)\n"); + strncpy(encoding_desc, "PAM4", 64); break; default: - printf(" (reserved or unknown)\n"); + strncpy(encoding_desc, "reserved or unknown", 64); break; } + + sff_print_any_hex_field("Encoding", "encoding", id[encoding_offset], + encoding_desc); +} + + +void sff_show_thresholds_json(struct sff_diags sd) +{ + open_json_object("laser_bias_current"); + PRINT_BIAS_JSON("high_alarm_threshold", sd.bias_cur[HALRM]); + PRINT_BIAS_JSON("low_alarm_threshold", sd.bias_cur[LALRM]); + PRINT_BIAS_JSON("high_warning_threshold", sd.bias_cur[HWARN]); + PRINT_BIAS_JSON("low_warning_threshold", sd.bias_cur[LWARN]); + print_string(PRINT_JSON, "units", "%s", "mA"); + close_json_object(); + + open_json_object("laser_output_power"); + PRINT_xX_PWR_JSON("high_alarm_threshold", sd.tx_power[HALRM]); + PRINT_xX_PWR_JSON("low_alarm_threshold", sd.tx_power[LALRM]); + PRINT_xX_PWR_JSON("high_warning_threshold", sd.tx_power[HWARN]); + PRINT_xX_PWR_JSON("low_warning_threshold", sd.tx_power[LWARN]); + print_string(PRINT_JSON, "units", "%s", "mW"); + close_json_object(); + + open_json_object("module_temperature"); + PRINT_TEMP_JSON("high_alarm_threshold", sd.sfp_temp[HALRM]); + PRINT_TEMP_JSON("low_alarm_threshold", sd.sfp_temp[LALRM]); + PRINT_TEMP_JSON("high_warning_threshold", sd.sfp_temp[HWARN]); + PRINT_TEMP_JSON("low_warning_threshold", sd.sfp_temp[LWARN]); + print_string(PRINT_JSON, "units", "%s", "degrees C"); + close_json_object(); + + open_json_object("module_voltage"); + PRINT_VCC_JSON("high_alarm_threshold", sd.sfp_voltage[HALRM]); + PRINT_VCC_JSON("low_alarm_threshold", sd.sfp_voltage[LALRM]); + PRINT_VCC_JSON("high_warning_threshold", sd.sfp_voltage[HWARN]); + PRINT_VCC_JSON("low_warning_threshold", sd.sfp_voltage[LWARN]); + print_string(PRINT_JSON, "units", "%s", "V"); + close_json_object(); + + open_json_object("laser_rx_power"); + PRINT_xX_PWR_JSON("high_alarm_threshold", sd.rx_power[HALRM]); + PRINT_xX_PWR_JSON("low_alarm_threshold", sd.rx_power[LALRM]); + PRINT_xX_PWR_JSON("high_warning_threshold", sd.rx_power[HWARN]); + PRINT_xX_PWR_JSON("low_warning_threshold", sd.rx_power[LWARN]); + print_string(PRINT_JSON, "units", "%s", "mW"); + close_json_object(); } void sff_show_thresholds(struct sff_diags sd) diff --git a/sff-common.h b/sff-common.h index 161860c..3c02a69 100644 --- a/sff-common.h +++ b/sff-common.h @@ -26,6 +26,9 @@ #include #include "internal.h" +#define SFF_MAX_DESC_LEN 120 +#define SFF_MAX_FIELD_LEN 64 + /* Revision compliance */ #define SFF8636_REV_UNSPECIFIED 0x00 #define SFF8636_REV_8436_48 0x01 @@ -71,19 +74,53 @@ (double)((var) / 10000.), \ convert_mw_to_dbm((double)((var) / 10000.))) +#define PRINT_xX_PWR_JSON(string, var) \ + print_float(PRINT_JSON, string, "%.2f", \ + (double)((var) / 10000.)) + +#define PRINT_xX_PWR_ALL(string, json_string, var) \ + is_json_context() ? \ + PRINT_xX_PWR_JSON(json_string, var) : \ + PRINT_xX_PWR(string, var) + #define PRINT_BIAS(string, bias_cur) \ printf("\t%-41s : %.3f mA\n", (string), \ (double)(bias_cur / 500.)) +#define PRINT_BIAS_JSON(string, bias_cur) \ + print_float(PRINT_JSON, string, "%.3f", \ + (double)(bias_cur / 500.)) + +#define PRINT_BIAS_ALL(string, json_string, bias_cur) \ + is_json_context() ? \ + PRINT_BIAS_JSON(json_string, bias_cur) : \ + PRINT_BIAS(string, bias_cur) + #define PRINT_TEMP(string, temp) \ printf("\t%-41s : %.2f degrees C / %.2f degrees F\n", \ (string), (double)(temp / 256.), \ (double)(temp / 256. * 1.8 + 32.)) +#define PRINT_TEMP_JSON(string, temp) \ + print_float(PRINT_JSON, string, "%.2f", (double)(temp / 256.)) + +#define PRINT_TEMP_ALL(string, json_string, temp) \ + is_json_context() ? \ + PRINT_TEMP_JSON(json_string, temp) : PRINT_TEMP(string, temp) + #define PRINT_VCC(string, sfp_voltage) \ printf("\t%-41s : %.4f V\n", (string), \ (double)(sfp_voltage / 10000.)) +#define PRINT_VCC_JSON(string, sfp_voltage) \ + print_float(PRINT_JSON, string, "%.4f", \ + (double)(sfp_voltage / 10000.)) + +#define PRINT_VCC_ALL(string, json_string, sfp_voltage) \ + is_json_context() ? \ + PRINT_VCC_JSON(json_string, sfp_voltage) : \ + PRINT_VCC(string, sfp_voltage) + # define PRINT_xX_THRESH_PWR(string, var, index) \ PRINT_xX_PWR(string, (var)[(index)]) @@ -129,7 +166,11 @@ struct sff_diags { }; double convert_mw_to_dbm(double mw); +void sff_print_any_hex_field(const char *field_name, + const char *json_field_name, u8 value, + const char *desc); void sff_show_thresholds(struct sff_diags sd); +void sff_show_thresholds_json(struct sff_diags sd); void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type); From patchwork Sun Jan 26 11:56:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950658 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2051.outbound.protection.outlook.com [40.107.223.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E98B7156F39 for ; Sun, 26 Jan 2025 11:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892649; cv=fail; b=i9ZuA8m33nm7V3dLGKlB+yuVkMUSXmLMPOMQMKBcl53WIDbB/OXjC7d6HtiDDeRDU4sg5DvxWo8bbL9N0M4d7AOquOD0NmzkwM8rphXyVuHVM6kF9X4VvKIMS1ZHdZuxNzCTA2PWu4a0gSw5lb5vQiIuIsKRtRpxyzZ2H1AjUR0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892649; c=relaxed/simple; bh=bjKen3qQ3QTMcd5TYDd051eRv9ZRCBcyqkPhJ6f4mDU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XG+qOnAEEFbj9XMaisVSP/Zx5JlRk9zfn8EToM+Jv0KzSSjw9OfacyjddapxYMMJfJiNhPSi4IutspBmSPOimlMFl8DZj5h5oxsRlVpM/S++r7qrG9DCJwf3JqttZ5q5ADbU2N9f4U4KL9RxvYp1kHVBOoVm8O81kuaXbuDfXt0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=oHSil/YT; arc=fail smtp.client-ip=40.107.223.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="oHSil/YT" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tY5usZNDuSb8vUvY6sJdQSD0QmHcXu3hsRrBhnX6V45TcPrXdxaXFqeDusikUUWR8aQaZfGx6m8A+80Zc8InCESKfIOr4IRd7dWQov7fGFnOpGd8uQg9LFSC36EanOpus/Ced/ylXSd8OWTDoCm68c1xGy96pV3Cl+nqksmcJSseLHSqwHyjFUkNQKjWkMu2KxwyNkMpKalBN6cF0Wrquc7tza6P/9UxON0gt3ZJhyt09G7DqZ4bmbQpiBOZmrSfpG7gBAa87UEX+bX+Q7jCjwiM0ME/cw17CQC+0vCIoSBGG8qz+5W3jNRSE3/daBGkVZ8XUzZM8NjEfZVRdNzjFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CWN+TXB5m18+0Gknfc6z455q1phIF5e+6tS7BcYOxec=; b=dEE0oCBvJQi4Eu2oiDdEg6Ra0nsPkd2zRwxiAYMHDm/M3K5C9YtwD/HsBr+x3ZTPOr4w6eMFp9JEvVBzhVD+iiF8higqOS/bR97WewiyTnOQt4dzmh8RGV9cc0vzXj5475qMpaRIxQ6rSc4jlyEcswg0MLVUO6KGEue1jFd1uwKjCeHETySS1WqGx8w/u1PDcItxlCjJ2IgySFhmJOBs5OsCurU0DBOoBA3hTkI5/tuRpMQtl+cyF7f/zJM0Dxx9Kbe8F10HRwqWQi3n1D1Uknu3fDIMdpf+tVf+4MhotuBMM4HaCyAUefzNYpgoZfotYIbMmm167Uav3eavVbajtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CWN+TXB5m18+0Gknfc6z455q1phIF5e+6tS7BcYOxec=; b=oHSil/YTcxIxduWmpYzsbU/7FgPHcgAEdroLfrRwKw8g+/zWhtWnCDse94julUXpfT7Ccw0Sm+XqH/VrxA/Z0vE3qjp4OuEDk/xUna697jXwHzO/IBFEcKKWl+UH7174DUj1bRsc+vDBewXJ0dDOspT1k96kA/X3ABgQLcvyw2+eRpOotw6Olis+QFQsEfjotV4/2Z3FAsH8ci6rtfl7Y0/SQE/kyGmJx0877Np52JuFbLYt/zs5UGaf90OtLbUTwHNaka4CpZrfhRPnC2YhLMBQ+Yodt8Z2p1fU54kKwb0ZBLgoj1vCQbwBd0PbX1Is8JABg9Y+axLuQJbb3xAlAA== Received: from DS7PR03CA0088.namprd03.prod.outlook.com (2603:10b6:5:3bb::33) by SJ0PR12MB6686.namprd12.prod.outlook.com (2603:10b6:a03:479::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.22; Sun, 26 Jan 2025 11:57:21 +0000 Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com (2603:10b6:5:3bb:cafe::43) by DS7PR03CA0088.outlook.office365.com (2603:10b6:5:3bb::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:20 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:07 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:05 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 07/14] cmis: Add JSON output handling to --module-info in CMIS modules Date: Sun, 26 Jan 2025 13:56:28 +0200 Message-ID: <20250126115635.801935-8-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D2:EE_|SJ0PR12MB6686:EE_ X-MS-Office365-Filtering-Correlation-Id: ea2b4649-8b4f-44fa-2269-08dd3e0096c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: iBB03dd6pEPCn1G7S/Yof0WdivoxrLlRdKWJT6SHT01JOgQOkEj6jfWlE8a/GDruuX7G3uDsNvW44YMnqP6hERecSIRMCc8MUZk7CMsHD+OGRTUdZmvGlN6VzFcB/7RePutx+Nvo0xQ7Qbbdr7cTEC4oWB6SINfeuHpLnluk+cMmMlznJF8+hrMwYJQ5EFQ4AgvEXu2+kTrsucgC6awwyLsTi87pKXhwCaWOcoGamgUOKDokThc97IdClEojImyt8voEXV/B8d5ogBwuEKAbAmnjk/kVYqlct4i328C+SjmXuPFLlTCec+PzEgax7UdHRPTHN7e/oXFZOCqWrB/T5uMz68MjrCFqj+IgenoJEn7JG7zC8YLkDrK0eNQYlZX4MnubUZ59voF05mIdTwb6XHWWwwG0I7qqRg+g+clOLgFvgiuRXPWLzrVS/Zz0gk+VljM15qbEhCG9v0M5EsHSE0FQENwEAoid9mGEsmVM2W9hMOt03qmNvjMsBhERk0P5Kyd06aa/oTbgCmwh6F0kj6DZx9JNMLpe8LcEd41Xp0+DVYoQIWJNABbNT2xwjy+tV3JbUEZsaW/TMspYEBja0oULt9bqgt8GjPkME3Bklb1XY8ma5+d5g9mQ7mqIeOJjjhGmDWkzsdxNBRtK/NGEIxZy9WSj+r0l1O9JdKoGEr6FdbpwX2Av0VX+MREZiXEtlqNB2owhey6aglsPold3IofsfctG/x2H9IYBa8/qYuT+BQzOWfU6K2KWly0TeOqMWpNt17Qce0X4xWHpeSmoj4/FWHeGloQsSK+BCnbXQK7dlWqMmteVIVsRKsTJo0CAoGRE9xkv+Zb3Vzxj+p9RMIuWmTSWRuH2MGTxbJIxMJXEBM977hah8K/9d4hAubqsCJkxvTKTI71jhhWEOVA1W6BFz9w/qG84XOWRTIQ4Q3tBPJ97TqU232a+kBlEu6+g290xo1NG2lN17LkhYqismPktKhoeDaAUUSeCiN5eEzw+KBzHDV9F3/Ay/zjqWHnyL/VTYDa7NG/DFvsSfaV9F68ZwBXMUv1wtH6KTO4QNjBv7KMTYEN6GO2S1U+DlAGIeFp5pReRkn5ydG9uX5zkz5hrzzn2OCNT5WxYxRaWe8nfnL1WMWUuRL8cywmg7wUB63KQ9Pu2TvSabGZjx4PIBYHO1QhyByJGePPYoa+xaWM4AECe9AFME5Kdmp1U9t3cC2MJmbnhIAAoEQYeJkRDaYP/OA1qqM/f5rdEG2kJoKj4KC0yyQBgmA8HbCPZuSE6IAtoMSs7UmuctZs2lyjRu0EmqJHPoC1Hme/zdbmHWjEQv+O5sk8vASv7uHNuJu4JbJTJ0QEwHio5UjoW1/JQsnij9xjtud1GknWs2S4YDlxn9mjdSaeqFKFFgHsHI+uQrdRpu/eQKFYDi/hixbvDXs+WO3+NP7m7TIhfg1UlrXzwD1eTE8jyiz3rZse1rgmJTXnVP5nTooadslGz+ZRpJX9T2NTBT0lo0I+iMxWjwUU= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:20.5233 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea2b4649-8b4f-44fa-2269-08dd3e0096c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6686 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz 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 --- cmis.c | 285 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 196 insertions(+), 89 deletions(-) diff --git a/cmis.c b/cmis.c index 9d89a5e..4901f57 100644 --- a/cmis.c +++ b/cmis.c @@ -62,7 +62,15 @@ static void cmis_show_rev_compliance(const struct cmis_memory_map *map) int major = (rev >> 4) & 0x0F; int minor = rev & 0x0F; - printf("\t%-41s : Rev. %d.%d\n", "Revision compliance", major, minor); + if (is_json_context()) { + open_json_object("revision_compliance"); + print_uint(PRINT_JSON, "major", "%u", major); + print_uint(PRINT_JSON, "minor", "%u", minor); + close_json_object(); + } else { + printf("\t%-41s : Rev. %d.%d\n", "Revision compliance", major, + minor); + } } static void @@ -123,8 +131,8 @@ static void cmis_show_power_info(const struct cmis_memory_map *map) base_power = map->page_00h[CMIS_PWR_MAX_POWER_OFFSET]; max_power = base_power * 0.25f; - printf("\t%-41s : %d\n", "Power class", power_class + 1); - printf("\t%-41s : %.02fW\n", "Max power", max_power); + module_print_any_uint("Power class", power_class + 1, NULL); + module_print_any_float("Max power", max_power, "W"); } /** @@ -143,7 +151,7 @@ static void cmis_show_cbl_asm_len(const struct cmis_memory_map *map) /* Check if max length */ if (map->page_00h[CMIS_CBL_ASM_LEN_OFFSET] == CMIS_6300M_MAX_LEN) { - printf("\t%-41s : > 6.3km\n", fn); + module_print_any_string(fn, "> 6.3km"); return; } @@ -168,7 +176,7 @@ static void cmis_show_cbl_asm_len(const struct cmis_memory_map *map) /* Get base value from first 6 bits and multiply by mul */ val = (map->page_00h[CMIS_CBL_ASM_LEN_OFFSET] & CMIS_LEN_VAL_MASK); val = (float)val * mul; - printf("\t%-41s : %0.2fm\n", fn, val); + module_print_any_float(fn, val, "m"); } /** @@ -202,7 +210,7 @@ static void cmis_print_smf_cbl_len(const struct cmis_memory_map *map) /* Get base value from first 6 bits and multiply by mul */ val = (map->page_01h[CMIS_SMF_LEN_OFFSET] & CMIS_LEN_VAL_MASK); val = (float)val * mul; - printf("\t%-41s : %0.2fkm\n", fn, val); + module_print_any_float(fn, val, "km"); } /** @@ -212,22 +220,26 @@ static void cmis_print_smf_cbl_len(const struct cmis_memory_map *map) */ static void cmis_show_sig_integrity(const struct cmis_memory_map *map) { + bool value; + if (!map->page_01h) return; /* CDR Bypass control: 2nd bit from each byte */ - printf("\t%-41s : ", "Tx CDR bypass control"); - printf("%s\n", YESNO(map->page_01h[CMIS_SIG_INTEG_TX_OFFSET] & 0x02)); + value = map->page_01h[CMIS_SIG_INTEG_TX_OFFSET] & 0x02; + module_print_any_bool("Tx CDR bypass control", NULL, value, + YESNO(value)); - printf("\t%-41s : ", "Rx CDR bypass control"); - printf("%s\n", YESNO(map->page_01h[CMIS_SIG_INTEG_RX_OFFSET] & 0x02)); + value = map->page_01h[CMIS_SIG_INTEG_RX_OFFSET] & 0x02; + module_print_any_bool("Rx CDR bypass control", NULL, value, + YESNO(value)); /* CDR Implementation: 1st bit from each byte */ - printf("\t%-41s : ", "Tx CDR"); - printf("%s\n", YESNO(map->page_01h[CMIS_SIG_INTEG_TX_OFFSET] & 0x01)); + value = map->page_01h[CMIS_SIG_INTEG_TX_OFFSET] & 0x01; + module_print_any_bool("Tx CDR", NULL, value, YESNO(value)); - printf("\t%-41s : ", "Rx CDR"); - printf("%s\n", YESNO(map->page_01h[CMIS_SIG_INTEG_RX_OFFSET] & 0x01)); + value = map->page_01h[CMIS_SIG_INTEG_RX_OFFSET] & 0x01; + module_print_any_bool("Rx CDR", NULL, value, YESNO(value)); } /** @@ -247,21 +259,25 @@ static void cmis_show_mit_compliance(const struct cmis_memory_map *map) module_show_mit_compliance(value); if (value >= CMIS_COPPER_UNEQUAL) { - printf("\t%-41s : %udb\n", "Attenuation at 5GHz", - map->page_00h[CMIS_COPPER_ATT_5GHZ]); - printf("\t%-41s : %udb\n", "Attenuation at 7GHz", - map->page_00h[CMIS_COPPER_ATT_7GHZ]); - printf("\t%-41s : %udb\n", "Attenuation at 12.9GHz", - map->page_00h[CMIS_COPPER_ATT_12P9GHZ]); - printf("\t%-41s : %udb\n", "Attenuation at 25.8GHz", - map->page_00h[CMIS_COPPER_ATT_25P8GHZ]); + module_print_any_uint("Attenuation at 5GHz", + map->page_00h[CMIS_COPPER_ATT_5GHZ], "db"); + module_print_any_uint("Attenuation at 7GHz", + map->page_00h[CMIS_COPPER_ATT_7GHZ], "db"); + module_print_any_uint("Attenuation at 12.9GHz", + map->page_00h[CMIS_COPPER_ATT_12P9GHZ], + "db"); + module_print_any_uint("Attenuation at 25.8GHz", + map->page_00h[CMIS_COPPER_ATT_25P8GHZ], + "db"); } else if (map->page_01h) { - printf("\t%-41s : %.3lfnm\n", "Laser wavelength", - (((map->page_01h[CMIS_NOM_WAVELENGTH_MSB] << 8) | - map->page_01h[CMIS_NOM_WAVELENGTH_LSB]) * 0.05)); - printf("\t%-41s : %.3lfnm\n", "Laser wavelength tolerance", - (((map->page_01h[CMIS_WAVELENGTH_TOL_MSB] << 8) | - map->page_01h[CMIS_WAVELENGTH_TOL_LSB]) * 0.005)); + module_print_any_float("Laser wavelength", + (((map->page_01h[CMIS_NOM_WAVELENGTH_MSB] << 8) | + map->page_01h[CMIS_NOM_WAVELENGTH_LSB]) * 0.05), + "nm"); + module_print_any_float("Laser wavelength tolerance", + (((map->page_01h[CMIS_WAVELENGTH_TOL_MSB] << 8) | + map->page_01h[CMIS_NOM_WAVELENGTH_LSB]) * 0.05), + "nm"); } } @@ -314,6 +330,8 @@ static void cmis_show_vendor_info(const struct cmis_memory_map *map) CMIS_CLEI_END_OFFSET, "CLEI code"); } +#define CMIS_MAX_DESC_LEN 64 + /* Print the current Module State. Relevant documents: * [1] CMIS Rev. 5, pag. 57, section 6.3.2.2, Figure 6-3 * [2] CMIS Rev. 5, pag. 60, section 6.3.2.3, Figure 6-4 @@ -321,31 +339,40 @@ static void cmis_show_vendor_info(const struct cmis_memory_map *map) */ static void cmis_show_mod_state(const struct cmis_memory_map *map) { + char mod_state_description[CMIS_MAX_DESC_LEN]; __u8 mod_state; mod_state = (map->lower_memory[CMIS_MODULE_STATE_OFFSET] & CMIS_MODULE_STATE_MASK) >> 1; - printf("\t%-41s : 0x%02x", "Module State", mod_state); switch (mod_state) { case CMIS_MODULE_STATE_MODULE_LOW_PWR: - printf(" (ModuleLowPwr)\n"); + strncpy(mod_state_description, "ModuleLowPwr", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_STATE_MODULE_PWR_UP: - printf(" (ModulePwrUp)\n"); + strncpy(mod_state_description, "ModulePwrUp", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_STATE_MODULE_READY: - printf(" (ModuleReady)\n"); + strncpy(mod_state_description, "ModuleReady", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_STATE_MODULE_PWR_DN: - printf(" (ModulePwrDn)\n"); + strncpy(mod_state_description, "ModulePwrDn", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_STATE_MODULE_FAULT: - printf(" (ModuleFault)\n"); + strncpy(mod_state_description, "ModuleFault", + CMIS_MAX_DESC_LEN); break; default: - printf(" (reserved or unknown)\n"); + strncpy(mod_state_description, "reserved or unknown", + CMIS_MAX_DESC_LEN); break; } + + sff_print_any_hex_field("Module state", "module_state", + mod_state, mod_state_description); } /* Print the Module Fault Information. Relevant documents: @@ -354,6 +381,7 @@ static void cmis_show_mod_state(const struct cmis_memory_map *map) */ static void cmis_show_mod_fault_cause(const struct cmis_memory_map *map) { + char fault_cause_description[CMIS_MAX_DESC_LEN]; __u8 mod_state, fault_cause; mod_state = (map->lower_memory[CMIS_MODULE_STATE_OFFSET] & @@ -362,24 +390,31 @@ static void cmis_show_mod_fault_cause(const struct cmis_memory_map *map) return; fault_cause = map->lower_memory[CMIS_MODULE_FAULT_OFFSET]; - printf("\t%-41s : 0x%02x", "Module Fault Cause", fault_cause); switch (fault_cause) { case CMIS_MODULE_FAULT_NO_FAULT: - printf(" (No fault detected / not supported)\n"); + strncpy(fault_cause_description, + "No fault detected / not supported", CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_FAULT_TEC_RUNAWAY: - printf(" (TEC runaway)\n"); + strncpy(fault_cause_description, "TEC runaway", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_FAULT_DATA_MEM_CORRUPTED: - printf(" (Data memory corrupted)\n"); + strncpy(fault_cause_description, "Data memory corrupted", + CMIS_MAX_DESC_LEN); break; case CMIS_MODULE_FAULT_PROG_MEM_CORRUPTED: - printf(" (Program memory corrupted)\n"); + strncpy(fault_cause_description, "Program memory corrupted", + CMIS_MAX_DESC_LEN); break; default: - printf(" (reserved or unknown)\n"); + strncpy(fault_cause_description, "reserved or unknown", + CMIS_MAX_DESC_LEN); break; } + + sff_print_any_hex_field("Module Fault Cause", "module_fault_cause", + fault_cause, fault_cause_description); } /* Print the current Module-Level Controls. Relevant documents: @@ -388,12 +423,17 @@ static void cmis_show_mod_fault_cause(const struct cmis_memory_map *map) */ static void cmis_show_mod_lvl_controls(const struct cmis_memory_map *map) { - printf("\t%-41s : ", "LowPwrAllowRequestHW"); - printf("%s\n", ONOFF(map->lower_memory[CMIS_MODULE_CONTROL_OFFSET] & - CMIS_LOW_PWR_ALLOW_REQUEST_HW_MASK)); - printf("\t%-41s : ", "LowPwrRequestSW"); - printf("%s\n", ONOFF(map->lower_memory[CMIS_MODULE_CONTROL_OFFSET] & - CMIS_LOW_PWR_REQUEST_SW_MASK)); + bool value; + + value = map->lower_memory[CMIS_MODULE_CONTROL_OFFSET] & + CMIS_LOW_PWR_ALLOW_REQUEST_HW_MASK; + module_print_any_bool("LowPwrAllowRequestHW", "low_pwr_allow_request_hw", + value, ONOFF(value)); + + value = map->lower_memory[CMIS_MODULE_CONTROL_OFFSET] & + CMIS_LOW_PWR_REQUEST_SW_MASK; + module_print_any_bool("LowPwrRequestSW", "low_pwr_request_sw", value, + ONOFF(value)); } static void cmis_parse_dom_power_type(const struct cmis_memory_map *map, @@ -557,14 +597,25 @@ cmis_show_dom_chan_lvl_tx_bias_bank(const struct cmis_memory_map *map, if (!page_11h) return; + open_json_array("laser_tx_bias_current", ""); + for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { int chan = bank * CMIS_CHANNELS_PER_BANK + i; char fmt_str[80]; - snprintf(fmt_str, 80, "%s (Channel %d)", - "Laser tx bias current", chan + 1); - PRINT_BIAS(fmt_str, sd->scd[chan].bias_cur); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.3f", + (double)sd->scd[chan].bias_cur / 500.); + } else { + snprintf(fmt_str, 80, "%s (Channel %d)", + "Laser tx bias current", chan + 1); + PRINT_BIAS(fmt_str, sd->scd[chan].bias_cur); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units("laser_tx_bias_current", "mA"); } static void cmis_show_dom_chan_lvl_tx_bias(const struct cmis_memory_map *map, @@ -593,14 +644,25 @@ cmis_show_dom_chan_lvl_tx_power_bank(const struct cmis_memory_map *map, if (!page_11h) return; + open_json_array("transmit_avg_optical_power", ""); + for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { int chan = bank * CMIS_CHANNELS_PER_BANK + i; char fmt_str[80]; - snprintf(fmt_str, 80, "%s (Channel %d)", - "Transmit avg optical power", chan + 1); - PRINT_xX_PWR(fmt_str, sd->scd[chan].tx_power); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.4f", + (double)sd->scd[chan].tx_power / 10000.); + } else { + snprintf(fmt_str, 80, "%s (Channel %d)", + "Transmit avg optical power", chan + 1); + PRINT_xX_PWR(fmt_str, sd->scd[chan].tx_power); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units("transmit_avg_optical_power", "mW"); } static void cmis_show_dom_chan_lvl_tx_power(const struct cmis_memory_map *map, @@ -623,25 +685,39 @@ cmis_show_dom_chan_lvl_rx_power_bank(const struct cmis_memory_map *map, const struct sff_diags *sd, int bank) { const __u8 *page_11h = map->upper_memory[bank][0x11]; + char *rx_power_str; int i; if (!page_11h) return; + if (!sd->rx_power_type) + rx_power_str = "Receiver signal OMA"; + else + rx_power_str = "Rcvr signal avg optical power"; + + char rx_power_json_str[strlen(rx_power_str)]; + + convert_json_field_name(rx_power_str, rx_power_json_str); + open_json_array(rx_power_json_str, ""); + for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { int chan = bank * CMIS_CHANNELS_PER_BANK + i; - char *rx_power_str; char fmt_str[80]; - if (!sd->rx_power_type) - rx_power_str = "Receiver signal OMA"; - else - rx_power_str = "Rcvr signal avg optical power"; - - snprintf(fmt_str, 80, "%s (Channel %d)", rx_power_str, - chan + 1); - PRINT_xX_PWR(fmt_str, sd->scd[chan].rx_power); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.4f", + (double)sd->scd[chan].rx_power / 10000.); + } else { + snprintf(fmt_str, 80, "%s (Channel %d)", rx_power_str, + chan + 1); + PRINT_xX_PWR(fmt_str, sd->scd[chan].rx_power); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units(rx_power_json_str, "mW"); } static void cmis_show_dom_chan_lvl_rx_power(const struct cmis_memory_map *map, @@ -672,10 +748,13 @@ static void cmis_show_dom_mod_lvl_flags(const struct cmis_memory_map *map) int i; for (i = 0; module_aw_mod_flags[i].str; i++) { - if (module_aw_mod_flags[i].type == MODULE_TYPE_CMIS) - printf("\t%-41s : %s\n", module_aw_mod_flags[i].str, - map->lower_memory[module_aw_mod_flags[i].offset] & - module_aw_mod_flags[i].value ? "On" : "Off"); + if (module_aw_mod_flags[i].type == MODULE_TYPE_CMIS) { + bool value = map->lower_memory[module_aw_mod_flags[i].offset] & + module_aw_mod_flags[i].value; + + module_print_any_bool(module_aw_mod_flags[i].str, NULL, + value, ONOFF(value)); + } } } @@ -692,11 +771,16 @@ static void cmis_show_dom_chan_lvl_flag(const struct cmis_memory_map *map, for (i = 0; i < CMIS_CHANNELS_PER_BANK; i++) { int chan = bank * CMIS_CHANNELS_PER_BANK + i; char str[80]; - - snprintf(str, 80, module_aw_chan_flags[flag].fmt_str, chan + 1); - printf("\t%-41s : %s\n", str, - page_11h[module_aw_chan_flags[flag].offset] & chan ? - "On" : "Off"); + bool value; + + value = page_11h[module_aw_chan_flags[flag].offset] & chan; + if (is_json_context()) { + print_bool(PRINT_JSON, NULL, NULL, value); + } else { + snprintf(str, 80, "%s (Chan %d)", + module_aw_chan_flags[flag].fmt_str, chan + 1); + printf("\t%-41s : %s\n", str, ONOFF(value)); + } } } @@ -711,11 +795,19 @@ cmis_show_dom_chan_lvl_flags_bank(const struct cmis_memory_map *map, return; for (flag = 0; module_aw_chan_flags[flag].fmt_str; flag++) { - if (!(map->page_01h[module_aw_chan_flags[flag].adver_offset] & - module_aw_chan_flags[flag].adver_value)) - continue; - - cmis_show_dom_chan_lvl_flag(map, bank, flag); + char json_str[80] = {}; + + if (module_aw_chan_flags[flag].type == MODULE_TYPE_CMIS) { + if (!(map->page_01h[module_aw_chan_flags[flag].adver_offset] & + module_aw_chan_flags[flag].adver_value)) + continue; + + convert_json_field_name(module_aw_chan_flags[flag].fmt_str, + json_str); + open_json_array(json_str, ""); + cmis_show_dom_chan_lvl_flag(map, bank, flag); + close_json_array(""); + } } } @@ -745,8 +837,12 @@ static void cmis_show_dom(const struct cmis_memory_map *map) cmis_show_dom_chan_lvl_monitors(map, &sd); cmis_show_dom_mod_lvl_flags(map); cmis_show_dom_chan_lvl_flags(map); - if (sd.supports_alarms) - sff_show_thresholds(sd); + if (sd.supports_alarms) { + if (is_json_context()) + sff_show_thresholds_json(sd); + else + sff_show_thresholds(sd); + } } /* Print active and inactive firmware versions. Relevant documents: @@ -756,14 +852,24 @@ static void cmis_show_dom(const struct cmis_memory_map *map) static void cmis_show_fw_version_common(const char *name, __u8 major, __u8 minor) { + char json_fn[32] = ""; + if (major == 0 && minor == 0) { return; } else if (major == 0xFF && minor == 0xFF) { - printf("\t%-41s : Invalid\n", name); + module_print_any_string(name, "Invalid"); return; } - printf("\t%-41s : %d.%d\n", name, major, minor); + if (is_json_context()) { + convert_json_field_name(name, json_fn); + open_json_object(json_fn); + print_uint(PRINT_JSON, "major", "%u", major); + print_uint(PRINT_JSON, "minor", "%u", minor); + close_json_object(); + } else { + printf("\t%-41s : %d.%d\n", name, major, minor); + } } static void cmis_show_fw_active_version(const struct cmis_memory_map *map) @@ -811,7 +917,7 @@ static void cmis_show_cdb_instances(const struct cmis_memory_map *map) { __u8 cdb_instances = cmis_cdb_instances_get(map); - printf("\t%-41s : %u\n", "CDB instances", cdb_instances); + module_print_any_uint("CDB instances", cdb_instances, NULL); } static void cmis_show_cdb_mode(const struct cmis_memory_map *map) @@ -819,8 +925,8 @@ static void cmis_show_cdb_mode(const struct cmis_memory_map *map) __u8 mode = map->page_01h[CMIS_CDB_ADVER_OFFSET] & CMIS_CDB_ADVER_MODE_MASK; - printf("\t%-41s : %s\n", "CDB background mode", - mode ? "Supported" : "Not supported"); + module_print_any_string("CDB background mode", + mode ? "Supported" : "Not supported"); } static void cmis_show_cdb_epl_pages(const struct cmis_memory_map *map) @@ -828,7 +934,7 @@ static void cmis_show_cdb_epl_pages(const struct cmis_memory_map *map) __u8 epl_pages = map->page_01h[CMIS_CDB_ADVER_OFFSET] & CMIS_CDB_ADVER_EPL_MASK; - printf("\t%-41s : %u\n", "CDB EPL pages", epl_pages); + module_print_any_uint("CDB EPL pages", epl_pages, NULL); } static void cmis_show_cdb_rw_len(const struct cmis_memory_map *map) @@ -839,9 +945,10 @@ static void cmis_show_cdb_rw_len(const struct cmis_memory_map *map) * units of 8 bytes, in addition to the minimum 8 bytes. */ rw_len = (rw_len + 1) * 8; - printf("\t%-41s : %u\n", "CDB Maximum EPL RW length", rw_len); - printf("\t%-41s : %u\n", "CDB Maximum LPL RW length", - rw_len > CMIS_PAGE_SIZE ? CMIS_PAGE_SIZE : rw_len); + module_print_any_uint("CDB Maximum EPL RW length", rw_len, NULL); + module_print_any_uint("CDB Maximum LPL RW length", + rw_len > CMIS_PAGE_SIZE ? CMIS_PAGE_SIZE : rw_len, + NULL); } static void cmis_show_cdb_trigger(const struct cmis_memory_map *map) @@ -853,8 +960,8 @@ static void cmis_show_cdb_trigger(const struct cmis_memory_map *map) * page, or by multiple writes ending with the writing of the CDB * Command Code (CMDID). */ - printf("\t%-41s : %s\n", "CDB trigger method", - trigger ? "Single write" : "Multiple writes"); + module_print_any_string("CDB trigger method", + trigger ? "Single write" : "Multiple writes"); } /* Print CDB messaging support advertisement. Relevant documents: From patchwork Sun Jan 26 11:56:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950659 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2049.outbound.protection.outlook.com [40.107.94.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F9C1156C74 for ; Sun, 26 Jan 2025 11:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892649; cv=fail; b=NwRxs5QxxrHfabAah2L2xLZv5Hy/MzfNtZaX3SVT5fyG3ASWDrfb1orXt2C7sNGvecrVHx5APqrmtKbCWRRQsWkSfDSqZ8X+Mk7tH5Y46o/LPVexGjOzdBNaMwiCZQQA+otkHFqzUvGbLc6mziVaYpyDhzqZGSUn+G/9PfM4aE0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892649; c=relaxed/simple; bh=+s27ckSxv5R4b5IXEyTeaLoK8A+EmA/6gnpXd08gpkg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BKbDJFRUk37S2lvj3r1V/l2v9XcC7r+a60iv+s7o8VlYPIBvnwF02oCfp9qYWiUqIc193m2Da+7UXSV6dn7RNeZNScBFmgpUv8xFGWK6G3C5WPkYCjF6PrVLm2MQ0GzT3oJtNQjGp8iMbl2qPxz66oZ2UL9TYEjS9ZD2lekuOcY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Cs4NChS5; arc=fail smtp.client-ip=40.107.94.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Cs4NChS5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wB7OJVMjlcejBj/93NNyn7zyF2VTCjsl/FzaTHNECMHlHrDlccPA7B0PYpE3VNIRIgWf4jddk5bjrft2AS2vPCv8aEz71w+ku3B7ZhF6vSxbHcwpmAMKr3B0eM+ZgenvHe9OvSAczLgAkBi3hrJQrwalqtS80KmSskCArH34m9kgWC88r93GY7BnOVszVhwc9Nit04UbMGHR+JhNdf5q/SgSl5rn0Cuw8qIMb6jUkeaCApRW/lclOaBKknn1YaNZTL4C2IhDOBNoFEhOwSyrjlvvYR5wkXIxk2Pk+f8vfbZ6Y2L+JWlR295m2RyO5j/6sCkKQuFVG5GM47PDTrFYTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sKngEn9AaMNgYYCf05Vro7CLiYOiYY1CNnKdPACSSxc=; b=jx0RXnLEIMexnTRkmTuIhr1aKri/qcxmopwYM9/xn7oke9XwaRmpMLoahgoQ/rRr3TAoRHt8chkO98fkMy09/JRxTO9syZOEZb92x1rG43T0SQeIJ3eD8puwsN3iKabgGPfn145fUfjZ09TcdjDl+dP/0Dc0+8OBakUQ3UW2zXe0kFU1Onje+Q7NXOh+WOk0pzc4eiqFk2+WKBhc8PBN0d0RhOTHG8bX455A9vVIbnhOcLmdxna8AufZ4a4VVVAwGTn097QYjFh+hBxCMJ0WWL6Iz8WXxJgMjC/Ff+LPPyRtlUL9KalE7Lb+p9UjrJjFW5NG50jqYKt3FS62+ipi4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sKngEn9AaMNgYYCf05Vro7CLiYOiYY1CNnKdPACSSxc=; b=Cs4NChS5VxxveS0ZPlGL/GKvP1ZE5wJ+cE6F89a9bUHX3JTpxpBxGxSHg5Z0A77voBDpQ+gal3cY1u5FP4nltHyk9su9MQj9/7/M15z/TT1S263oOS8I1s4D1aAe6DrD/5kBjN85D17DvOphVpnstY9ysEtnetzWzhzMlKuR0VcuEqp8wPR+ch5HBSQvNfs6HIVnRIHLL+PEvMXhRedIDWwNQFKzYGS860wfY/pJZE0tpn3AVu2TMC4jcKC1g1/QK1x2Im62Vmpe8S7LGgjfXFKJ8rZfpmPJlH0QCAe41TDBZKX0yqv/dsplhDoK4xcd+09jfQwP1Gcdf3FhKe0AOA== Received: from PH7PR17CA0063.namprd17.prod.outlook.com (2603:10b6:510:325::27) by CYYPR12MB8750.namprd12.prod.outlook.com (2603:10b6:930:be::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.20; Sun, 26 Jan 2025 11:57:24 +0000 Received: from CY4PEPF0000E9D1.namprd03.prod.outlook.com (2603:10b6:510:325:cafe::c2) by PH7PR17CA0063.outlook.office365.com (2603:10b6:510:325::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9D1.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:23 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:09 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:07 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 08/14] cmis: Enable JSON output support in CMIS modules Date: Sun, 26 Jan 2025 13:56:29 +0200 Message-ID: <20250126115635.801935-9-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D1:EE_|CYYPR12MB8750:EE_ X-MS-Office365-Filtering-Correlation-Id: a4f6186b-44b7-4525-a833-08dd3e0098c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: tc/3NNSBA4nXR8bxpZCQs1IxrQH91sOmw0dBbsf982FY8tZBBqFBtP9xjFfFmIE1T20Fj8WAwJmKnQZygcDYMLwaskdiYCQT2cpJfM9OreMgFtO+8AWkt9oJy6eAUOjLK25M04MXazXfWTZJgPnPlSVZNOu4tEt9tMFBLhIC3e8i6F0K+NPXeHIlxcVYTVRcIGDMkaydyJv7BKzUziqHza9m8yN2NIgAn/OZm6rDycA93C4dfGQxw088hkGhaoeBg42NxQgqVHHcitSTcyVKIN3wcD62aiDkpLfmn88ulzKkXeX0FCHeYTNz1wwauBlvBKwmJQfAi6fWNep67OTU6YB+Dkhfz8mE7TNAXrpB09C+BnGkNGpxgFXobmalS2VZoMd1Wegszqvs1oBc0pyfFqTKWiiG1RYim3BflZZofEmKyKDY6gKUeVCgpHWN2db4ZGFKqla/BZLkuLGtFFJYM6qB/Jb9v9cPh5RTAPyOCIxzm69AzsULZ3UIjvl24jwJszSjAzM3s/EhUdh0vZFzJ7Z9QJsPbLbd5HEIN6Y7K/u3yhExQr0hXSfC5GBCB3z1V9KYmgwyc+X5E3m8pffUCYnUtWv6tMCpCBgxEaFvowvB+2Tv7Ih25srWoQHml3tqHUZtRgmqvxyz/3Fx/Su68U+3BZcdT/oTkw4L4zbSV6Qh8zabPp+36fGz5XVNTwz1IjFTp8OIuE5cImvekfdZjB+QyNFY/TXa9MFY+GA1Kx0fc2Dvquaun0JaeD1cXiP4HC0qIQV9aRrfgZ5xPqe0WuDB4NOkbOyo8Sn9vQaxbTN1n7DqY5mVpWIo8H5jjo3acXr9I4zNesfp9ab0pv9GC4AY2AhWH6+O0ljFXv/llzhmM12Hd+gUowmTnjB+739kRzBMg+FfYi3Km2rI4xFgEATR91f2Zy14rv5mbHk5oejj6wQpYahSPDwdRkGsChhqaoxuZJABTurnbcYOSiSwzNuVVW7X79aSQ0FMBrBSpwHsJrrJ9fXd8NVS4XdALFQw1eM1anDvGvGoCnwtwSjV7yRJMDI/1N3L2u6QymLVQmEt4fMhVgN9G/dAoDv2Nf3kfM9FkLuashn3kHYAZ2IxLOzbBrZjS9RY5kK2dW1E8OsdihQ/RspvUPasxc5gdaaGGk6Dl7D/tBuAWNwvwcjMr0tFtX1qBBtPm9OyJH3m5ffuP2vu3fjGdr/IkewxafqadJ9qjwNYz/DIutxGS06aMUkpUqjVQDaD7RG3Luk9KXtBN95mCUj3aopg9m6yxLOeIj56JwcQAtUtxP5kbWCIwtI/aGKxRPbAncHB53QXe1EfxDH12jEjRmhVs0iuQskW3mbr6BdoWSWXGzCj3s60TEDdGLSSQEXayrJL/S9/AgXVzVwwIQR/0vk0crnCFsXSICTRTbWBHChe39DWu9w7Dc1g07ibVN+YLQabdqtQ1Ymjh0nxWF9yCqO5YMCh0Oiyp8+HOKXiTp0vZww5eXlYdxmoSF9cl7a+HGcN+5I7U70= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:23.8757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a4f6186b-44b7-4525-a833-08dd3e0098c0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8750 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz A sample output: $ ethtool --json -m swp23 [ { "identifier": 24, "identifier_description": "QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628)", "power_class": 5, "max_power": 10.0000, "max_power_units": "W", "connector": 40, "connector_description": "MPO 1x16", "cable_assembly_length": 0.0000, "cable_assembly_length_units": "m", "tx_cdr_bypass_control": false, "rx_cdr_bypass_control": false, "tx_cdr": true, "rx_cdr": true, "transmitter_technology": 0, "transmitter_technology_description": "850 nm VCSEL", "laser_wavelength": 850.0000, "laser_wavelength_units": "nm", "laser_wavelength_tolerance": 94.8000, "laser_wavelength_tolerance_units": "nm", "length_(smf)": 0.0000, "length_(smf)_units": "km", "length_(om5)": 0, "length_(om5)_units": "m", "length_(om4)": 100, "length_(om4)_units": "m", "length_(om3_50/125um)": 70, "length_(om3_50/125um)_units": "m", "length_(om2_50/125um)": 0, "length_(om2_50/125um)_units": "m", "vendor_name": "FINISAR CORP.", "vendor_oui": [ 0,144,101 ], "vendor_pn": "FTCD8613E1PCM", "vendor_rev": "A0", "vendor_sn": "X6LBE6H", "date_code": "211229__", "revision_compliance": { "major": 4, "minor": 0 }, "rx_loss_of_signal": [ "Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes" ], "tx_loss_of_signal": "None", "rx_loss_of_lock": "None", "tx_loss_of_lock": "None", "tx_fault": "None", "module_state": 3, "module_state_description": "ModuleReady", "low_pwr_allow_request_hw": false, "low_pwr_request_sw": false, "module_temperature": 36.8203, "module_temperature_units": "degrees C", "module_voltage": 3.3385, "module_voltage_units": "V", "laser_tx_bias_current": [ 0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000 ], "laser_tx_bias_current_units": "mA", "transmit_avg_optical_power": [ 0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001 ], "transmit_avg_optical_power_units": "mW", "rcvr_signal_avg_optical_power": [ 0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001 ], "rcvr_signal_avg_optical_power_units": "mW", "module_temperature_high_alarm": false, "module_temperature_low_alarm": false, "module_temperature_high_warning": false, "module_temperature_low_warning": false, "module_voltage_high_alarm": false, "module_voltage_low_alarm": false, "module_voltage_high_warning": false, "module_voltage_low_warning": false, "laser_bias_current_high_alarm": [ false,false,false,false,false,false,false,false ], "laser_bias_current_low_alarm": [ false,false,false,false,false,false,false,false ], "laser_bias_current_high_warning": [ false,false,false,false,false,false,false,false ], "laser_bias_current_low_warning": [ false,false,false,false,false,false,false,false ], "laser_tx_power_high_alarm": [ false,false,false,false,false,false,false,false ], "laser_tx_power_low_alarm": [ false,false,false,false,false,false,false,false ], "laser_tx_power_high_warning": [ false,false,false,false,false,false,false,false ], "laser_tx_power_low_warning": [ false,false,false,false,false,false,false,false ], "laser_rx_power_high_alarm": [ false,false,false,false,false,false,false,false ], "laser_rx_power_low_alarm": [ false,false,false,false,false,false,false,false ], "laser_rx_power_high_warning": [ false,false,false,false,false,false,false,false ], "laser_rx_power_low_warning": [ false,false,false,false,false,false,false,false ], "laser_bias_current": { "high_alarm_threshold": 13.0000, "low_alarm_threshold": 3.0000, "high_warning_threshold": 11.0000, "low_warning_threshold": 5.0000, "units": "mA" }, "laser_output_power": { "high_alarm_threshold": 3.1623, "low_alarm_threshold": 0.1000, "high_warning_threshold": 1.9953, "low_warning_threshold": 0.1585, "units": "mW" }, "module_temperature": { "high_alarm_threshold": 75.0000, "low_alarm_threshold": -5.0000, "high_warning_threshold": 70.0000, "low_warning_threshold": 0.0000, "units": "degrees C" }, "module_voltage": { "high_alarm_threshold": 3.4650, "low_alarm_threshold": 3.1350, "high_warning_threshold": 3.4500, "low_warning_threshold": 3.1500, "units": "V" }, "laser_rx_power": { "high_alarm_threshold": 3.1623, "low_alarm_threshold": 0.0398, "high_warning_threshold": 2.5119, "low_warning_threshold": 0.0794, "units": "mW" }, "active_firmware_version": { "major": 2, "minor": 7 }, "inactive_firmware_version": { "major": 2, "minor": 7 }, "cdb_instances": 1, "cdb_background_mode": "Supported", "cdb_epl_pages": 0, "cdb_maximum_epl_rw_length": 128, "cdb_maximum_lpl_rw_length": 128, "cdb_trigger_method": "Single write" } ] Signed-off-by: Danielle Ratson Reviewed-by: Amit Cohen --- cmis.c | 6 ++++++ ethtool.c | 1 + 2 files changed, 7 insertions(+) diff --git a/cmis.c b/cmis.c index 4901f57..f12548e 100644 --- a/cmis.c +++ b/cmis.c @@ -1129,10 +1129,16 @@ int cmis_show_all_nl(struct cmd_context *ctx) struct cmis_memory_map map = {}; int ret; + new_json_obj(ctx->json); + open_json_object(NULL); + ret = cmis_memory_map_init_pages(ctx, &map); if (ret < 0) return ret; cmis_show_all_common(&map); + close_json_object(); + delete_json_obj(); + return 0; } diff --git a/ethtool.c b/ethtool.c index 225f3aa..2818206 100644 --- a/ethtool.c +++ b/ethtool.c @@ -6044,6 +6044,7 @@ static const struct option args[] = { }, { .opts = "-m|--dump-module-eeprom|--module-info", + .json = true, .func = do_getmodule, .nlfunc = nl_getmodule, .help = "Query/Decode Module EEPROM information and optical diagnostics if available", From patchwork Sun Jan 26 11:56:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950660 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2076.outbound.protection.outlook.com [40.107.93.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C2FB157493 for ; Sun, 26 Jan 2025 11:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892652; cv=fail; b=hm09YMcnRAnt9RkzlmapMRGZyr9M5DgoUnBw1mX3WsugeMsVnlqsY0CdBPKBQPIfFbhsgyI949/OWIcRDsYEZ5GaJvWjl0v4CuMsamvVFAyjJlMjW0eT9NK2CKifN2NW+qRl4JknhyHqIMoYrLxj55So8rzZbZMChxo3i1p+rPM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892652; c=relaxed/simple; bh=qiL370fx02dCG+/05WkbVy/cy44tDZ69m2+s+pQdAnU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N4YkCe7CQCo22SEsCtJ8BfcjKMcHoemsammGjO6ISBIBxyIJL4IGNqtBL4qzyUym1bhEyc0n2pLcV4iQF23v6Z2+D214LdUwLKixHVNzMg1lrJ2SIwdDivTc3i5TdLT95OcZnCKtRrQMR2tWpnvmnbyTaMSmEZ6dXUOytrzMtgY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gZud4QLy; arc=fail smtp.client-ip=40.107.93.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gZud4QLy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dgz2kDWmpsUMp5iG5gvIFly7ndnRv03qgaZyR1Sv0wDykE3uvxnqhqyyFVdIwqy086GIW/WnbIbX6nict62SlZfjdR781Wu+nHZAromaMt0IJiDcrMa9ewHVYnQuUk3NOR7B7qaLkx4kpwSbvmtcpZ9Cxm2h2xzFOe8BlPJxjT0w+MODLPfY6jwZV/v1FU4h8uMBj0t8tL0yEgEbn/l0qx4iqwVkmBvvpDNKEJQdg0jPqEp8BocHYZEf2YJJZkQsphAQH6mQDwhvZmNzjnhyJeH/aIVKYCp3OaBXvqgWY5SmF5Txh3UC9l70m1yhIfmcEeKWWvkl0VB8sqCnopwsEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JI8a9cM84q3HGm0vPb6il/Nj+3l1m476W5yF1HUBEtw=; b=n+4hcjuFaLYRMFTlcQvObHkcZFjBDHkyj/WkVYB8snLAOEEyVULSQX7gUz4xozHpLJ2rL6TReblN05r4+TwIjouNWfn8cUobSgN7USDh1/p+l48tQgJsrGjtfDe5fwOVDyIaGtG9HcZ44D4w2RdnY/r7Aajm9dZbWcPCi2JeQuLUFFpxETJXwZv6nSJfDUzfS83WEiYm77N3eCj7C9wWKkWlDn3hrVGNsBpXKsMncunf+2KXPoO1i/UrmQiXlocvkJp+ZNlHjplImdUdzxBqyz+2QBLi7k0YGe1MYThEOSJPzB1thrk8alWFLDZ04JzZVj5ZdTtjT3c7bEs8+OFj8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JI8a9cM84q3HGm0vPb6il/Nj+3l1m476W5yF1HUBEtw=; b=gZud4QLybTs6l/9rmNFDHi+Ayq10NN0xH25MRa8EccfnTnnLILlOJmQ4yHwDCey0am4g1VZzQkxBUw+/ZpbWyvChdIxnO/tyQp/WkZpuqjk9kMpfQJhhoT4DRlkGP/7I2lgQntSUQJ0xcZdo7aBMX3xWldeFPqUH1XRTEvDBOuIMsc5lKf5gT4RiaSUbkKm0q3TvU4Iyn+0lsQ9n6Pfsb46KpIcCcZ19YQDMSG+V7E1Q/sl+S0YHRyzM4bF6RANenNxMSgac8uFN8kxXaxpscPzEXknBbp0OmVgJubor5qH4wnz4Ngl6bnD7cvB9Nsvu/PCdBtd1vq7BNZEvdKtcCw== Received: from CYZPR11CA0016.namprd11.prod.outlook.com (2603:10b6:930:8d::21) by SA1PR12MB7173.namprd12.prod.outlook.com (2603:10b6:806:2b4::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:23 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:930:8d:cafe::ee) by CYZPR11CA0016.outlook.office365.com (2603:10b6:930:8d::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:23 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:12 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:09 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 09/14] qsfp: Add JSON output handling to --module-info in SFF8636 modules Date: Sun, 26 Jan 2025 13:56:30 +0200 Message-ID: <20250126115635.801935-10-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|SA1PR12MB7173:EE_ X-MS-Office365-Filtering-Correlation-Id: 3efd8949-826f-4383-04f4-08dd3e009845 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: BBhbKIn1CU8tbS7UhRyRWtp7KMcFq6HipLgJ8oEgPe0WQqbgM15U22ex6sOvQXZHd0lV5hoX9rhCnmquYB8ikaaoN/BiUb8Q1ZuAg9eQkFmxiOMgR1lC93RZft+Y2arevsub5J+rQWMtCFuJAPv1QieNqejp3Y3QtyRjYlj7C5CFn1CZZ20KtS20c4lYcjVjcNBEbtbLz4jPnbeTeko3V8oJ3zDxvMGxzXkNWMopBtRWdSvPwnLBdmht6MEpbfkMUWEA2JCnze6NV58txjvoEE//uukLY8iOLb9gzL4gBkpbkFnuVFtHf0NkzogYawzNxbhNIxOdxHeE6l3d/zEcm50pF/BmSByuiNBO443Qo2Ez7+4o0ay0IvQa7IHFrBKvMkMgx112QtYYZQyet+aC1lMZoJJuySt0gEkJvk0Tz6lYXzK0fqp4gKZ0MVbVpa1tVkfxBFZ8uiBNc/ETnx37dIMaN2wqoTCQicS+mnXRlfTujubLW4lU9w7VkZVMhQ8CzoKel/y/S2SBP8vCYkI22odpWrGWB8D6jXlE8lSdYyB1+M/coM9ts8yeN4tHMVEmO4nAGEX4Yb/5XRVXiz5hafWM4/feTMzWOehCKjWxfa7BLxKJrGKDweAdRgHLiipF7WX0+iEcw3nrD4qA/5HTKoANKsO7CQKFI5JZl+Akb6m7UdtioCjmejkj1OrEE+4mAr1XmFqS4OU8VeJvKs0JVzIMY7OLcgxyGJE61Ps1PcC9BAqtgihz+vvs3D4Afzriwnhh/kTFgRE72+G5tDa1WFvHNIpeaT18Rl5hvdh2QdILRMExEgOyyfzpHnHLqHBA0Prx+63Lg3Afy59XI3EVn2HAqEyuIX434gb0vGtOgvLrY/pEeNHvMDx1sfIlwMtZdTqSntBSOLWDk53z1GxApb5ujF99zk7frvsem2vlx+HUSRsnpfSALsvhvcoilQanCyaHD8ncnMjUX/t5zObS7g1vTNsaaEIt/hx/drknfi3afIkk6thrRKYLcvNn3r6eogBR1bLLYt572w3sNpe3mqTsRIHduwSXuCPAZAEUtT8d6RQGdXL7xgGc/3h78b/jMvnheyJhRS7SIpIC6jmrE60NoSQLwtUAsYL8ZjCkAsQfFF3NwS0Ww7H6+sFph+Tfs2P64wmcYgerkGLv/GwlkMrb2WPATqxxF/KNx6CKk9D/pPup6nsNhFPV4ywQ3uqkcINBzmbP6YgZxjoIb/oLktJW/hHveK7eMpJrSyGJnlPrYxKL8K0P6fpL9WPEs4NBiU7ErMOo0QWGkPDi5Ydi+6a4CmV3MdflRyP+JHmLmv49BiX153ITV/MiVdOnIJOb7g06skVsDtuA9kGtG1XMGr/k0OSsZeOKnj1GivAN5vYW+S2hKZ2rz1zMjwBeSxp8vkjDmTFbVvi38O8AyTAxdH82Zxl81cMC8N2XY5lHTlD3d6HqoSFkp//MGwl99rlofvocgqOfB1hsTyJQJb98tfs4Kow/2mROyXhKlIubilM= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:23.0654 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3efd8949-826f-4383-04f4-08dd3e009845 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7173 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz 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 --- cmis.h | 3 + qsfp.c | 538 +++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 337 insertions(+), 204 deletions(-) diff --git a/cmis.h b/cmis.h index 007632a..d2b3d24 100644 --- a/cmis.h +++ b/cmis.h @@ -199,6 +199,9 @@ #define CMIS_RX_PWR_HWARN_OFFSET 0xC4 #define CMIS_RX_PWR_LWARN_OFFSET 0xC6 +#define YESNO(x) (((x) != 0) ? "Yes" : "No") +#define ONOFF(x) (((x) != 0) ? "On" : "Off") + void cmis_show_all_ioctl(const __u8 *id); int cmis_show_all_nl(struct cmd_context *ctx); diff --git a/qsfp.c b/qsfp.c index 13d8fb7..d835067 100644 --- a/qsfp.c +++ b/qsfp.c @@ -82,64 +82,92 @@ static void sff8636_show_identifier(const struct sff8636_memory_map *map) static void sff8636_show_ext_identifier(const struct sff8636_memory_map *map) { - printf("\t%-41s : 0x%02x\n", "Extended identifier", - map->page_00h[SFF8636_EXT_ID_OFFSET]); - static const char *pfx = "\tExtended identifier description :"; + char description[64]; + + if (is_json_context()) { + open_json_object("extended_identifier"); + print_int(PRINT_JSON, "value", "0x%02x", + map->page_00h[SFF8636_EXT_ID_OFFSET]); + } else { + printf("\t%-41s : 0x%02x\n", "Extended identifier", + map->page_00h[SFF8636_EXT_ID_OFFSET]); + } switch (map->page_00h[SFF8636_EXT_ID_OFFSET] & SFF8636_EXT_ID_PWR_CLASS_MASK) { case SFF8636_EXT_ID_PWR_CLASS_1: - printf("%s 1.5W max. Power consumption\n", pfx); + strncpy(description, "1.5W max. Power consumption", 64); break; case SFF8636_EXT_ID_PWR_CLASS_2: - printf("%s 2.0W max. Power consumption\n", pfx); + strncpy(description, "1.5W max. Power consumption", 64); break; case SFF8636_EXT_ID_PWR_CLASS_3: - printf("%s 2.5W max. Power consumption\n", pfx); + strncpy(description, "2.5W max. Power consumption", 64); break; case SFF8636_EXT_ID_PWR_CLASS_4: - printf("%s 3.5W max. Power consumption\n", pfx); + strncpy(description, "3.5W max. Power consumption", 64); break; } + if (is_json_context()) + print_string(PRINT_JSON, "description", "%s", description); + else + printf("%s %s\n", pfx, description); + if (map->page_00h[SFF8636_EXT_ID_OFFSET] & SFF8636_EXT_ID_CDR_TX_MASK) - printf("%s CDR present in TX,", pfx); + strncpy(description, "CDR present in TX,", 64); else - printf("%s No CDR in TX,", pfx); + strncpy(description, "No CDR in TX,", 64); if (map->page_00h[SFF8636_EXT_ID_OFFSET] & SFF8636_EXT_ID_CDR_RX_MASK) - printf(" CDR present in RX\n"); + strcat(description, " CDR present in RX"); + else + strcat(description, " No CDR in RX"); + + if (is_json_context()) + print_string(PRINT_JSON, "description", "%s", description); else - printf(" No CDR in RX\n"); + printf("%s %s\n", pfx, description); switch (map->page_00h[SFF8636_EXT_ID_OFFSET] & SFF8636_EXT_ID_EPWR_CLASS_MASK) { case SFF8636_EXT_ID_PWR_CLASS_LEGACY: - printf("%s", pfx); + strncpy(description, "", 64); break; case SFF8636_EXT_ID_PWR_CLASS_5: - printf("%s 4.0W max. Power consumption,", pfx); + strncpy(description, "4.0W max. Power consumption,", 64); break; case SFF8636_EXT_ID_PWR_CLASS_6: - printf("%s 4.5W max. Power consumption, ", pfx); + strncpy(description, "4.5W max. Power consumption,", 64); break; case SFF8636_EXT_ID_PWR_CLASS_7: - printf("%s 5.0W max. Power consumption, ", pfx); + strncpy(description, "5.0W max. Power consumption,", 64); break; } + if (map->lower_memory[SFF8636_PWR_MODE_OFFSET] & SFF8636_HIGH_PWR_ENABLE) - printf(" High Power Class (> 3.5 W) enabled\n"); + strcat(description, " High Power Class (> 3.5 W) enabled"); else - printf(" High Power Class (> 3.5 W) not enabled\n"); - printf("\t%-41s : ", "Power set"); - printf("%s\n", ONOFF(map->lower_memory[SFF8636_PWR_MODE_OFFSET] & - SFF8636_LOW_PWR_SET)); - printf("\t%-41s : ", "Power override"); - printf("%s\n", ONOFF(map->lower_memory[SFF8636_PWR_MODE_OFFSET] & - SFF8636_PWR_OVERRIDE)); + strcat(description, + " High Power Class (> 3.5 W) not enabled"); + + if (is_json_context()) + print_string(PRINT_JSON, "description", "%s", description); + else + printf("%s %s\n", pfx, description); + + close_json_object(); + + bool value = map->lower_memory[SFF8636_PWR_MODE_OFFSET] & + SFF8636_LOW_PWR_SET; + module_print_any_bool("Power set", "power_set", value, ONOFF(value)); + value = map->lower_memory[SFF8636_PWR_MODE_OFFSET] & + SFF8636_PWR_OVERRIDE; + module_print_any_bool("Power override", "power_override", value, + ONOFF(value)); } static void sff8636_show_connector(const struct sff8636_memory_map *map) @@ -149,232 +177,262 @@ static void sff8636_show_connector(const struct sff8636_memory_map *map) static void sff8636_show_transceiver(const struct sff8636_memory_map *map) { - static const char *pfx = - "\tTransceiver type :"; - - printf("\t%-41s : 0x%02x 0x%02x 0x%02x " \ - "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", - "Transceiver codes", - map->page_00h[SFF8636_ETHERNET_COMP_OFFSET], - map->page_00h[SFF8636_SONET_COMP_OFFSET], - map->page_00h[SFF8636_SAS_COMP_OFFSET], - map->page_00h[SFF8636_GIGE_COMP_OFFSET], - map->page_00h[SFF8636_FC_LEN_OFFSET], - map->page_00h[SFF8636_FC_TECH_OFFSET], - map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET], - map->page_00h[SFF8636_FC_SPEED_OFFSET]); + static const char *pfx = "Transceiver type"; + char value[140] = ""; + + if (is_json_context()) { + open_json_array("transceiver_codes", ""); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_ETHERNET_COMP_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_SONET_COMP_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_SAS_COMP_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_GIGE_COMP_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_FC_LEN_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_FC_TECH_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET]); + print_int(PRINT_JSON, NULL, "0x%02x", + map->page_00h[SFF8636_FC_SPEED_OFFSET]); + close_json_array(""); + } else { + printf("\t%-41s : 0x%02x 0x%02x 0x%02x " \ + "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + "Transceiver codes", + map->page_00h[SFF8636_ETHERNET_COMP_OFFSET], + map->page_00h[SFF8636_SONET_COMP_OFFSET], + map->page_00h[SFF8636_SAS_COMP_OFFSET], + map->page_00h[SFF8636_GIGE_COMP_OFFSET], + map->page_00h[SFF8636_FC_LEN_OFFSET], + map->page_00h[SFF8636_FC_TECH_OFFSET], + map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET], + map->page_00h[SFF8636_FC_SPEED_OFFSET]); + } /* 10G/40G Ethernet Compliance Codes */ if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_10G_LRM) - printf("%s 10G Ethernet: 10G Base-LRM\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-LRM"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_10G_LR) - printf("%s 10G Ethernet: 10G Base-LR\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-LR"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_10G_SR) - printf("%s 10G Ethernet: 10G Base-SR\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-SR"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_40G_CR4) - printf("%s 40G Ethernet: 40G Base-CR4\n", pfx); + sprintf(value, "%s", "40G Ethernet: 40G Base-CR4"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_40G_SR4) - printf("%s 40G Ethernet: 40G Base-SR4\n", pfx); + sprintf(value, "%s", "40G Ethernet: 40G Base-SR4"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_40G_LR4) - printf("%s 40G Ethernet: 40G Base-LR4\n", pfx); + sprintf(value, "%s", "40G Ethernet: 40G Base-LR4"); if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_40G_ACTIVE) - printf("%s 40G Ethernet: 40G Active Cable (XLPPI)\n", pfx); + sprintf(value, "%s", "40G Ethernet: 40G Active Cable (XLPPI)"); /* Extended Specification Compliance Codes from SFF-8024 */ if (map->page_00h[SFF8636_ETHERNET_COMP_OFFSET] & SFF8636_ETHERNET_RSRVD) { switch (map->page_00h[SFF8636_OPTION_1_OFFSET]) { case SFF8636_ETHERNET_UNSPECIFIED: - printf("%s (reserved or unknown)\n", pfx); + sprintf(value, "%s", "(reserved or unknown)"); break; case SFF8636_ETHERNET_100G_AOC: - printf("%s 100G Ethernet: 100G AOC or 25GAUI C2M AOC with worst BER of 5x10^(-5)\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G AOC or 25GAUI C2M AOC with worst BER of 5x10^(-5)"); break; case SFF8636_ETHERNET_100G_SR4: - printf("%s 100G Ethernet: 100G Base-SR4 or 25GBase-SR\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G Base-SR4 or 25GBase-SR"); break; case SFF8636_ETHERNET_100G_LR4: - printf("%s 100G Ethernet: 100G Base-LR4\n", pfx); + sprintf(value, "%s", "100G Ethernet: 100G Base-LR4"); break; case SFF8636_ETHERNET_100G_ER4: - printf("%s 100G Ethernet: 100G Base-ER4\n", pfx); + sprintf(value, "%s", "100G Ethernet: 100G Base-ER4"); break; case SFF8636_ETHERNET_100G_SR10: - printf("%s 100G Ethernet: 100G Base-SR10\n", pfx); + sprintf(value, "%s", "100G Ethernet: 100G Base-SR10"); break; case SFF8636_ETHERNET_100G_CWDM4_FEC: - printf("%s 100G Ethernet: 100G CWDM4 MSA with FEC\n", pfx); + sprintf(value, "%s", + "100G Ethernet: 100G CWDM4 MSA with FEC"); break; case SFF8636_ETHERNET_100G_PSM4: - printf("%s 100G Ethernet: 100G PSM4 Parallel SMF\n", pfx); + sprintf(value, "%s", + "100G Ethernet: 100G PSM4 Parallel SMF"); break; case SFF8636_ETHERNET_100G_ACC: - printf("%s 100G Ethernet: 100G ACC or 25GAUI C2M ACC with worst BER of 5x10^(-5)\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G ACC or 25GAUI C2M ACC with worst BER of 5x10^(-5)"); break; case SFF8636_ETHERNET_100G_CWDM4_NO_FEC: - printf("%s 100G Ethernet: 100G CWDM4 MSA without FEC\n", pfx); + sprintf(value, "%s", + "100G Ethernet: 100G CWDM4 MSA without FEC"); break; case SFF8636_ETHERNET_100G_RSVD1: - printf("%s (reserved or unknown)\n", pfx); + sprintf(value, "%s", "(reserved or unknown)"); break; case SFF8636_ETHERNET_100G_CR4: - printf("%s 100G Ethernet: 100G Base-CR4 or 25G Base-CR CA-L\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G Base-CR4 or 25G Base-CR CA-L"); break; case SFF8636_ETHERNET_25G_CR_CA_S: - printf("%s 25G Ethernet: 25G Base-CR CA-S\n", pfx); + sprintf(value, "%s", "25G Ethernet: 25G Base-CR CA-S"); break; case SFF8636_ETHERNET_25G_CR_CA_N: - printf("%s 25G Ethernet: 25G Base-CR CA-N\n", pfx); + sprintf(value, "%s", "25G Ethernet: 25G Base-CR CA-N"); break; case SFF8636_ETHERNET_40G_ER4: - printf("%s 40G Ethernet: 40G Base-ER4\n", pfx); + sprintf(value, "%s", "40G Ethernet: 40G Base-ER4"); break; case SFF8636_ETHERNET_4X10_SR: - printf("%s 4x10G Ethernet: 10G Base-SR\n", pfx); + sprintf(value, "%s", "4x10G Ethernet: 10G Base-SR"); break; case SFF8636_ETHERNET_40G_PSM4: - printf("%s 40G Ethernet: 40G PSM4 Parallel SMF\n", pfx); + sprintf(value, "%s", + "40G Ethernet: 40G PSM4 Parallel SMF"); break; case SFF8636_ETHERNET_G959_P1I1_2D1: - printf("%s Ethernet: G959.1 profile P1I1-2D1 (10709 MBd, 2km, 1310nm SM)\n", - pfx); + sprintf(value, "%s", + "Ethernet: G959.1 profile P1I1-2D1 (10709 MBd, 2km, 1310nm SM)"); break; case SFF8636_ETHERNET_G959_P1S1_2D2: - printf("%s Ethernet: G959.1 profile P1S1-2D2 (10709 MBd, 40km, 1550nm SM)\n", - pfx); + sprintf(value, "%s", + "Ethernet: G959.1 profile P1S1-2D2 (10709 MBd, 40km, 1550nm SM)"); break; case SFF8636_ETHERNET_G959_P1L1_2D2: - printf("%s Ethernet: G959.1 profile P1L1-2D2 (10709 MBd, 80km, 1550nm SM)\n", - pfx); + sprintf(value, "%s", + "Ethernet: G959.1 profile P1L1-2D2 (10709 MBd, 80km, 1550nm SM)"); break; case SFF8636_ETHERNET_10GT_SFI: - printf("%s 10G Ethernet: 10G Base-T with SFI electrical interface\n", - pfx); + sprintf(value, "%s", + "10G Ethernet: 10G Base-T with SFI electrical interface"); break; case SFF8636_ETHERNET_100G_CLR4: - printf("%s 100G Ethernet: 100G CLR4\n", pfx); + sprintf(value, "%s", "100G Ethernet: 100G CLR4"); break; case SFF8636_ETHERNET_100G_AOC2: - printf("%s 100G Ethernet: 100G AOC or 25GAUI C2M AOC with worst BER of 10^(-12)\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G AOC or 25GAUI C2M AOC with worst BER of 10^(-12)"); break; case SFF8636_ETHERNET_100G_ACC2: - printf("%s 100G Ethernet: 100G ACC or 25GAUI C2M ACC with worst BER of 10^(-12)\n", - pfx); + sprintf(value, "%s", + "100G Ethernet: 100G ACC or 25GAUI C2M ACC with worst BER of 10^(-12)"); break; case SFF8636_ETHERNET_100GE_DWDM2: - printf("%s 100GE-DWDM2 (DWDM transceiver using 2 wavelengths on a 1550 nm DWDM grid with a reach up to 80 km)\n", - pfx); + sprintf(value, "%s", + "100GE-DWDM2 (DWDM transceiver using 2 wavelengths on a 1550 nm DWDM grid with a reach up to 80 km)"); break; case SFF8636_ETHERNET_100G_1550NM_WDM: - printf("%s 100G 1550nm WDM (4 wavelengths)\n", pfx); + sprintf(value, "%s", "100G 1550nm WDM (4 wavelengths)"); break; case SFF8636_ETHERNET_10G_BASET_SR: - printf("%s 10GBASE-T Short Reach (30 meters)\n", pfx); + sprintf(value, "%s", + "10GBASE-T Short Reach (30 meters)"); break; case SFF8636_ETHERNET_5G_BASET: - printf("%s 5GBASE-T\n", pfx); + sprintf(value, "%s", "5GBASE-T"); break; case SFF8636_ETHERNET_2HALFG_BASET: - printf("%s 2.5GBASE-T\n", pfx); + sprintf(value, "%s", "2.5GBASE-T"); break; case SFF8636_ETHERNET_40G_SWDM4: - printf("%s 40G SWDM4\n", pfx); + sprintf(value, "%s", "40G SWDM4"); break; case SFF8636_ETHERNET_100G_SWDM4: - printf("%s 100G SWDM4\n", pfx); + sprintf(value, "%s", "100G SWDM4"); break; case SFF8636_ETHERNET_100G_PAM4_BIDI: - printf("%s 100G PAM4 BiDi\n", pfx); + sprintf(value, "%s", "100G PAM4 BiDi"); break; case SFF8636_ETHERNET_4WDM10_MSA: - printf("%s 4WDM-10 MSA (10km version of 100G CWDM4 with same RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", + "4WDM-10 MSA (10km version of 100G CWDM4 with same RS(528,514) FEC in host system)"); break; case SFF8636_ETHERNET_4WDM20_MSA: - printf("%s 4WDM-20 MSA (20km version of 100GBASE-LR4 with RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", "4WDM-20 MSA (20km version of 100GBASE-LR4 with RS(528,514) FEC in host system)"); break; case SFF8636_ETHERNET_4WDM40_MSA: - printf("%s 4WDM-40 MSA (40km reach with APD receiver and RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", + "4WDM-40 MSA (40km reach with APD receiver and RS(528,514) FEC in host system)"); break; case SFF8636_ETHERNET_100G_DR: - printf("%s 100GBASE-DR (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "100GBASE-DR (clause 140), CAUI-4 (no FEC)"); break; case SFF8636_ETHERNET_100G_FR_NOFEC: - printf("%s 100G-FR or 100GBASE-FR1 (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "100G-FR or 100GBASE-FR1 (clause 140), CAUI-4 (no FEC)"); break; case SFF8636_ETHERNET_100G_LR_NOFEC: - printf("%s 100G-LR or 100GBASE-LR1 (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "100G-LR or 100GBASE-LR1 (clause 140), CAUI-4 (no FEC)"); break; case SFF8636_ETHERNET_200G_ACC1: - printf("%s Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n", - pfx); + sprintf(value, "%s", + "Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below"); break; case SFF8636_ETHERNET_200G_AOC1: - printf("%s Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n", - pfx); + sprintf(value, "%s", + "Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below"); break; case SFF8636_ETHERNET_200G_ACC2: - printf("%s Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n", - pfx); + sprintf(value, "%s", + "Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below"); break; case SFF8636_ETHERNET_200G_A0C2: - printf("%s Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n", - pfx); + sprintf(value, "%s", + "Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below"); break; case SFF8636_ETHERNET_200G_CR4: - printf("%s 50GBASE-CR, 100GBASE-CR2, or 200GBASE-CR4\n", pfx); + sprintf(value, "%s", + "50GBASE-CR, 100GBASE-CR2, or 200GBASE-CR4"); break; case SFF8636_ETHERNET_200G_SR4: - printf("%s 50GBASE-SR, 100GBASE-SR2, or 200GBASE-SR4\n", pfx); + sprintf(value, "%s", + "50GBASE-SR, 100GBASE-SR2, or 200GBASE-SR4"); break; case SFF8636_ETHERNET_200G_DR4: - printf("%s 50GBASE-FR or 200GBASE-DR4\n", pfx); + sprintf(value, "%s", "50GBASE-FR or 200GBASE-DR4"); break; case SFF8636_ETHERNET_200G_FR4: - printf("%s 200GBASE-FR4\n", pfx); + sprintf(value, "%s", "200GBASE-FR4"); break; case SFF8636_ETHERNET_200G_PSM4: - printf("%s 200G 1550 nm PSM4\n", pfx); + sprintf(value, "%s", "200G 1550 nm PSM4"); break; case SFF8636_ETHERNET_50G_LR: - printf("%s 50GBASE-LR\n", pfx); + sprintf(value, "%s", "50GBASE-LR"); break; case SFF8636_ETHERNET_200G_LR4: - printf("%s 200GBASE-LR4\n", pfx); + sprintf(value, "%s", "200GBASE-LR4"); break; case SFF8636_ETHERNET_64G_EA: - printf("%s 64GFC EA\n", pfx); + sprintf(value, "%s", "64GFC EA"); break; case SFF8636_ETHERNET_64G_SW: - printf("%s 64GFC SW\n", pfx); + sprintf(value, "%s", "64GFC SW"); break; case SFF8636_ETHERNET_64G_LW: - printf("%s 64GFC LW\n", pfx); + sprintf(value, "%s", "64GFC LW"); break; case SFF8636_ETHERNET_128FC_EA: - printf("%s 128GFC EA\n", pfx); + sprintf(value, "%s", "128GFC EA"); break; case SFF8636_ETHERNET_128FC_SW: - printf("%s 128GFC SW\n", pfx); + sprintf(value, "%s", "128GFC SW"); break; case SFF8636_ETHERNET_128FC_LW: - printf("%s 128GFC LW\n", pfx); + sprintf(value, "%s", "128GFC LW"); break; default: - printf("%s (reserved or unknown)\n", pfx); + sprintf(value, "%s", "(reserved or unknown)"); break; } } @@ -382,96 +440,98 @@ static void sff8636_show_transceiver(const struct sff8636_memory_map *map) /* SONET Compliance Codes */ if (map->page_00h[SFF8636_SONET_COMP_OFFSET] & (SFF8636_SONET_40G_OTN)) - printf("%s 40G OTN (OTU3B/OTU3C)\n", pfx); + sprintf(value, "%s", "40G OTN (OTU3B/OTU3C)"); if (map->page_00h[SFF8636_SONET_COMP_OFFSET] & (SFF8636_SONET_OC48_LR)) - printf("%s SONET: OC-48, long reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, long reach"); if (map->page_00h[SFF8636_SONET_COMP_OFFSET] & (SFF8636_SONET_OC48_IR)) - printf("%s SONET: OC-48, intermediate reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, intermediate reach"); if (map->page_00h[SFF8636_SONET_COMP_OFFSET] & (SFF8636_SONET_OC48_SR)) - printf("%s SONET: OC-48, short reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, short reach"); /* SAS/SATA Compliance Codes */ if (map->page_00h[SFF8636_SAS_COMP_OFFSET] & (SFF8636_SAS_6G)) - printf("%s SAS 6.0G\n", pfx); + sprintf(value, "%s", "SAS 6.0G"); if (map->page_00h[SFF8636_SAS_COMP_OFFSET] & (SFF8636_SAS_3G)) - printf("%s SAS 3.0G\n", pfx); + sprintf(value, "%s", "SAS 3.0G"); /* Ethernet Compliance Codes */ if (map->page_00h[SFF8636_GIGE_COMP_OFFSET] & SFF8636_GIGE_1000_BASE_T) - printf("%s Ethernet: 1000BASE-T\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-T"); if (map->page_00h[SFF8636_GIGE_COMP_OFFSET] & SFF8636_GIGE_1000_BASE_CX) - printf("%s Ethernet: 1000BASE-CX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-CX"); if (map->page_00h[SFF8636_GIGE_COMP_OFFSET] & SFF8636_GIGE_1000_BASE_LX) - printf("%s Ethernet: 1000BASE-LX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-LX"); if (map->page_00h[SFF8636_GIGE_COMP_OFFSET] & SFF8636_GIGE_1000_BASE_SX) - printf("%s Ethernet: 1000BASE-SX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-SX"); /* Fibre Channel link length */ if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_LEN_VERY_LONG) - printf("%s FC: very long distance (V)\n", pfx); + sprintf(value, "%s", "FC: very long distance (V)"); if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_LEN_SHORT) - printf("%s FC: short distance (S)\n", pfx); + sprintf(value, "%s", "FC: short distance (S)"); if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_LEN_INT) - printf("%s FC: intermediate distance (I)\n", pfx); + sprintf(value, "%s", "FC: intermediate distance (I)"); if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_LEN_LONG) - printf("%s FC: long distance (L)\n", pfx); + sprintf(value, "%s", "FC: long distance (L)"); if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_LEN_MED) - printf("%s FC: medium distance (M)\n", pfx); + sprintf(value, "%s", "FC: medium distance (M)"); /* Fibre Channel transmitter technology */ if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_TECH_LONG_LC) - printf("%s FC: Longwave laser (LC)\n", pfx); + sprintf(value, "%s", "FC: Longwave laser (LC)"); if (map->page_00h[SFF8636_FC_LEN_OFFSET] & SFF8636_FC_TECH_ELEC_INTER) - printf("%s FC: Electrical inter-enclosure (EL)\n", pfx); + sprintf(value, "%s", "FC: Electrical inter-enclosure (EL)"); if (map->page_00h[SFF8636_FC_TECH_OFFSET] & SFF8636_FC_TECH_ELEC_INTRA) - printf("%s FC: Electrical intra-enclosure (EL)\n", pfx); + sprintf(value, "%s", "FC: Electrical intra-enclosure (EL)"); if (map->page_00h[SFF8636_FC_TECH_OFFSET] & SFF8636_FC_TECH_SHORT_WO_OFC) - printf("%s FC: Shortwave laser w/o OFC (SN)\n", pfx); + sprintf(value, "%s", "FC: Shortwave laser w/o OFC (SN)"); if (map->page_00h[SFF8636_FC_TECH_OFFSET] & SFF8636_FC_TECH_SHORT_W_OFC) - printf("%s FC: Shortwave laser with OFC (SL)\n", pfx); + sprintf(value, "%s", "FC: Shortwave laser with OFC (SL)"); if (map->page_00h[SFF8636_FC_TECH_OFFSET] & SFF8636_FC_TECH_LONG_LL) - printf("%s FC: Longwave laser (LL)\n", pfx); + sprintf(value, "%s", "FC: Longwave laser (LL)"); /* Fibre Channel transmission media */ if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_TW) - printf("%s FC: Twin Axial Pair (TW)\n", pfx); + sprintf(value, "%s", "FC: Twin Axial Pair (TW)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_TP) - printf("%s FC: Twisted Pair (TP)\n", pfx); + sprintf(value, "%s", "FC: Twisted Pair (TP)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_MI) - printf("%s FC: Miniature Coax (MI)\n", pfx); + sprintf(value, "%s", "FC: Miniature Coax (MI)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_TV) - printf("%s FC: Video Coax (TV)\n", pfx); + sprintf(value, "%s", "FC: Video Coax (TV)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_M6) - printf("%s FC: Multimode, 62.5m (M6)\n", pfx); + sprintf(value, "%s", "FC: Multimode, 62.5m (M6)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_M5) - printf("%s FC: Multimode, 50m (M5)\n", pfx); + sprintf(value, "%s", "FC: Multimode, 50m (M5)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_OM3) - printf("%s FC: Multimode, 50um (OM3)\n", pfx); + sprintf(value, "%s", "FC: Multimode, 50um (OM3)"); if (map->page_00h[SFF8636_FC_TRANS_MEDIA_OFFSET] & SFF8636_FC_TRANS_MEDIA_SM) - printf("%s FC: Single Mode (SM)\n", pfx); + sprintf(value, "%s", "FC: Single Mode (SM)"); /* Fibre Channel speed */ if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_1200_MBPS) - printf("%s FC: 1200 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 1200 MBytes/sec"); if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_800_MBPS) - printf("%s FC: 800 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 800 MBytes/sec"); if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_1600_MBPS) - printf("%s FC: 1600 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 1600 MBytes/sec"); if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_400_MBPS) - printf("%s FC: 400 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 400 MBytes/sec"); if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_200_MBPS) - printf("%s FC: 200 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 200 MBytes/sec"); if (map->page_00h[SFF8636_FC_SPEED_OFFSET] & SFF8636_FC_SPEED_100_MBPS) - printf("%s FC: 100 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 100 MBytes/sec"); + + module_print_any_string(pfx, value); } static void sff8636_show_encoding(const struct sff8636_memory_map *map) @@ -483,8 +543,10 @@ static void sff8636_show_encoding(const struct sff8636_memory_map *map) static void sff8636_show_rate_identifier(const struct sff8636_memory_map *map) { /* TODO: Need to fix rate select logic */ - printf("\t%-41s : 0x%02x\n", "Rate identifier", - map->page_00h[SFF8636_EXT_RS_OFFSET]); + sff_print_any_hex_field("Rate identifier", "rate_identifier", + map->page_00h[SFF8636_EXT_RS_OFFSET], NULL); + + } static void @@ -496,58 +558,65 @@ sff8636_show_wavelength_or_copper_compliance(const struct sff8636_memory_map *ma module_show_mit_compliance(value); if (value >= SFF8636_TRANS_COPPER_PAS_UNEQUAL) { - printf("\t%-41s : %udb\n", "Attenuation at 2.5GHz", - map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET]); - printf("\t%-41s : %udb\n", "Attenuation at 5.0GHz", - map->page_00h[SFF8636_WAVELEN_LOW_BYTE_OFFSET]); - printf("\t%-41s : %udb\n", "Attenuation at 7.0GHz", - map->page_00h[SFF8636_WAVE_TOL_HIGH_BYTE_OFFSET]); - printf("\t%-41s : %udb\n", "Attenuation at 12.9GHz", - map->page_00h[SFF8636_WAVE_TOL_LOW_BYTE_OFFSET]); + module_print_any_uint("Attenuation at 2.5GHz", + map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET], + "db"); + module_print_any_uint("Attenuation at 5.0GHz", + map->page_00h[SFF8636_WAVELEN_LOW_BYTE_OFFSET], + "db"); + module_print_any_uint("Attenuation at 7.0GHz", + map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET], + "db"); + module_print_any_uint("Attenuation at 12.9GHz", + map->page_00h[SFF8636_WAVELEN_LOW_BYTE_OFFSET], + "db"); } else { - printf("\t%-41s : %.3lfnm\n", "Laser wavelength", - (((map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET] << 8) | - map->page_00h[SFF8636_WAVELEN_LOW_BYTE_OFFSET]) * 0.05)); - printf("\t%-41s : %.3lfnm\n", "Laser wavelength tolerance", - (((map->page_00h[SFF8636_WAVE_TOL_HIGH_BYTE_OFFSET] << 8) | - map->page_00h[SFF8636_WAVE_TOL_LOW_BYTE_OFFSET]) * 0.005)); + module_print_any_float("Laser wavelength", + (((map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET] << 8) | + map->page_00h[SFF8636_WAVELEN_LOW_BYTE_OFFSET]) * 0.05), + "nm"); + module_print_any_float("Laser wavelength tolerance", + (((map->page_00h[SFF8636_WAVE_TOL_HIGH_BYTE_OFFSET] << 8) | + map->page_00h[SFF8636_WAVE_TOL_LOW_BYTE_OFFSET]) * 0.05), + "nm"); } } static void sff8636_show_revision_compliance(const __u8 *id, int rev_offset) { - static const char *pfx = - "\tRevision Compliance :"; + const char *pfx = "Revision Compliance"; + char value[64] = ""; switch (id[rev_offset]) { case SFF8636_REV_UNSPECIFIED: - printf("%s Revision not specified\n", pfx); + sprintf(value, "%s", "Revision not specified"); break; case SFF8636_REV_8436_48: - printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); + sprintf(value, "%s", "SFF-8436 Rev 4.8 or earlier"); break; case SFF8636_REV_8436_8636: - printf("%s SFF-8436 Rev 4.8 or earlier\n", pfx); + sprintf(value, "%s", "SFF-8436 Rev 4.8 or earlier"); break; case SFF8636_REV_8636_13: - printf("%s SFF-8636 Rev 1.3 or earlier\n", pfx); + sprintf(value, "%s", "SFF-8636 Rev 1.3 or earlier"); break; case SFF8636_REV_8636_14: - printf("%s SFF-8636 Rev 1.4\n", pfx); + sprintf(value, "%s", "SFF-8636 Rev 1.4"); break; case SFF8636_REV_8636_15: - printf("%s SFF-8636 Rev 1.5\n", pfx); + sprintf(value, "%s", "SFF-8636 Rev 1.5"); break; case SFF8636_REV_8636_20: - printf("%s SFF-8636 Rev 2.0\n", pfx); + sprintf(value, "%s", "SFF-8636 Rev 2.0"); break; case SFF8636_REV_8636_27: - printf("%s SFF-8636 Rev 2.5/2.6/2.7\n", pfx); + sprintf(value, "%s", "SFF-8636 Rev 2.5/2.6/2.7"); break; default: - printf("%s Unallocated\n", pfx); + sprintf(value, "%s", "Unallocated"); break; } + module_print_any_string(pfx, value); } /* @@ -654,11 +723,21 @@ static void sff8636_show_dom_chan_lvl_tx_bias(const struct sff_diags *sd) char power_string[MAX_DESC_SIZE]; int i; + open_json_array("laser_tx_bias_current", ""); for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", - "Laser tx bias current", i+1); - PRINT_BIAS(power_string, sd->scd[i].bias_cur); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.3f", + (double)sd->scd[i].bias_cur / 500.); + } else { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + "Laser tx bias current", i+1); + PRINT_BIAS(power_string, sd->scd[i].bias_cur); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units("laser_tx_bias_current", "mA"); } static void sff8636_show_dom_chan_lvl_tx_power(const struct sff_diags *sd) @@ -666,11 +745,21 @@ static void sff8636_show_dom_chan_lvl_tx_power(const struct sff_diags *sd) char power_string[MAX_DESC_SIZE]; int i; + open_json_array("transmit_avg_optical_power", ""); for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", - "Transmit avg optical power", i+1); - PRINT_xX_PWR(power_string, sd->scd[i].tx_power); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.4f", + (double)sd->scd[i].tx_power / 10000.); + } else { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + "Transmit avg optical power", i+1); + PRINT_xX_PWR(power_string, sd->scd[i].tx_power); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units("transmit_avg_optical_power", "mW"); } static void sff8636_show_dom_chan_lvl_rx_power(const struct sff_diags *sd) @@ -684,11 +773,25 @@ static void sff8636_show_dom_chan_lvl_rx_power(const struct sff_diags *sd) else rx_power_string = "Rcvr signal avg optical power"; + char rx_power_json_str[strlen(rx_power_string)]; + + convert_json_field_name(rx_power_string, rx_power_json_str); + + open_json_array(rx_power_json_str, ""); for (i = 0; i < SFF8636_MAX_CHANNEL_NUM; i++) { - snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", - rx_power_string, i+1); - PRINT_xX_PWR(power_string, sd->scd[i].rx_power); + if (is_json_context()) { + print_float(PRINT_JSON, NULL, "%.4f", + (double)sd->scd[i].rx_power / 10000.); + } else { + snprintf(power_string, MAX_DESC_SIZE, "%s (Channel %d)", + rx_power_string, i+1); + PRINT_xX_PWR(power_string, sd->scd[i].rx_power); + } } + close_json_array(""); + + if (is_json_context()) + module_print_any_units(rx_power_json_str, "mW"); } static void @@ -698,38 +801,61 @@ sff8636_show_dom_chan_lvl_flags(const struct sff8636_memory_map *map) int i; for (i = 0; module_aw_chan_flags[i].fmt_str; ++i) { + char json_str[80] = {}; + char str[80] = {}; int j = 1; if (module_aw_chan_flags[i].type != MODULE_TYPE_SFF8636) continue; + convert_json_field_name(module_aw_chan_flags[i].fmt_str, + json_str); + + open_json_array(json_str, ""); do { value = map->lower_memory[module_aw_chan_flags[i].offset] & module_aw_chan_flags[i].adver_value; - printf("\t%-41s (Chan %d) : %s\n", - module_aw_chan_flags[i].fmt_str, j, - ONOFF(value)); + if (is_json_context()) { + print_bool(PRINT_JSON, NULL, NULL, value); + } else { + snprintf(str, 80, "%s (Chan %d)", + module_aw_chan_flags[i].fmt_str, j); + printf("\t%-41s : %s\n", str, ONOFF(value)); + } j++; i++; - } - while (module_aw_chan_flags[i].fmt_str && - strcmp(module_aw_chan_flags[i].fmt_str, - module_aw_chan_flags[i-1].fmt_str) == 0); + } while (module_aw_chan_flags[i].fmt_str && + strcmp(module_aw_chan_flags[i].fmt_str, + module_aw_chan_flags[i-1].fmt_str) == 0); i--; + close_json_array(""); } } static void sff8636_show_dom_mod_lvl_flags(const struct sff8636_memory_map *map) { + bool value; int i; for (i = 0; module_aw_mod_flags[i].str; ++i) { - if (module_aw_mod_flags[i].type == MODULE_TYPE_SFF8636) + char str[80] = {}; + + if (module_aw_mod_flags[i].type != MODULE_TYPE_SFF8636) + continue; + + value = map->lower_memory[module_aw_mod_flags[i].offset] & + module_aw_mod_flags[i].value; + + if (is_json_context()) { + print_bool(PRINT_JSON, module_aw_mod_flags[i].str, + NULL, value); + } else { + snprintf(str, 80, "%s (Chan %d)", + module_aw_mod_flags[i].str, i+1); printf("\t%-41s : %s\n", - module_aw_mod_flags[i].str, - ONOFF(map->lower_memory[module_aw_mod_flags[i].offset] - & module_aw_mod_flags[i].value)); + module_aw_mod_flags[i].str, ONOFF(value)); + } } } @@ -765,8 +891,9 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) (sd.sfp_temp[MCURR] == (__s16)0xFFFF)) return; - 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)); sff8636_show_dom_chan_lvl_tx_bias(&sd); sff8636_show_dom_chan_lvl_tx_power(&sd); @@ -776,7 +903,10 @@ static void sff8636_show_dom(const struct sff8636_memory_map *map) sff8636_show_dom_chan_lvl_flags(map); sff8636_show_dom_mod_lvl_flags(map); - sff_show_thresholds(sd); + if (is_json_context()) + sff_show_thresholds_json(sd); + else + sff_show_thresholds(sd); } } @@ -817,7 +947,7 @@ static void sff8636_show_page_zero(const struct sff8636_memory_map *map) sff8636_show_transceiver(map); sff8636_show_encoding(map); module_show_value_with_unit(map->page_00h, SFF8636_BR_NOMINAL_OFFSET, - "BR, Nominal", 100, "Mbps"); + "BR Nominal", 100, "Mbps"); sff8636_show_rate_identifier(map); module_show_value_with_unit(map->page_00h, SFF8636_SM_LEN_OFFSET, "Length (SMF,km)", 1, "km"); From patchwork Sun Jan 26 11:56:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950661 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B220715854A for ; Sun, 26 Jan 2025 11:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892654; cv=fail; b=KOozVsQU45Di5yIkmWEtPaFLDAhySzUn35+T4Prj5aNHEWJPeAVourY8KtgnYNNbUqbx/sZDs5f9t++33lYO8UrbZgzHrQ2JgYuUixu8Hu/ta1CvtqZk7qfrb1EKMscRIiAJSzBGLukls9UMXzL224rSwLXycjfnIo92BTxGoTc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892654; c=relaxed/simple; bh=VU9yMe2SnOtyfKDzjUpoUHdPcRi9ou7SAgi5WbPAuXk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pwifrxt20XnOS9/BN+Dji3AqoPJP4+hXmcUVgaMtpxkQYbgQD12CAFOTiVHQ0NtBMFabmXI43CTdLRsw1rG5badDuqv+cFwZ5YSUebDPoMlNcFND9QYhD8gK8JYSPW61/eCxXmOe++UpDhFyoOUWUJLskoLbB9pdLSxUGm7UBuc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Q5eQovSU; arc=fail smtp.client-ip=40.107.94.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Q5eQovSU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tuyt7CNWawHy8Sds/5E2ZA5mWi2cHztB7GnZgutid//Pt5FIBShNIOZUHLvHpGGIBAsfWKi6M+0cl5Kxa1t/9RjLtWHukKlLGKvYXi/OS65KPHIwtW7XNkHIPgq1aclqLWSK7q15lurYQBkM7cq422CTto/xk6zeOgh//E9Ne6NPzMzmxpTqIlM8tlL+3AM3wbfcXa8TE6uR7Vsj0X2YafZL4+xpOVETTczU4S8InX2Sx9ugEf3Sg8h92/qTS1T1hrIzH7hbu7flMoa+DKQ6dPDkaFQhgH/A86SCzU8YUDmSi13fIDwBn6osB8MItcZ6LMexzfOPOATwAIDU2mbHnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VdAlAIaAPYjH/FT30sZFnC9O3BIcem9L2U78exkc1XI=; b=i62tU+gLOu3AIt0OJhQdbGnAjCyhdSDe6e3NWM9X+Q0yMOsk46uxoYgKX1fQOBJPzomNXBbKyQvtCJ4T+OH9ZFQB6baw1cU3NFONefN4+4yn2R0JU+q9k8EohZzWfNt1VZLvcG1GFGpi/uYn3d6/Uv3dXaD9Ed7haeWe6NXxNETsYOgUUq2FW76oXUeAm8dGMrmUBKtueplhA3kBGahHXGA6MjDkivARChes++6w1dixdaqJUa37lw1lkT3skmEnucmY2imi35Tjv5JGiy158c7dkl3Ec4mAr3qcD5QA634/xnw0/xOB9K6nFeWnvnBO3AC/N4zJDRzoYK0NcL+lmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VdAlAIaAPYjH/FT30sZFnC9O3BIcem9L2U78exkc1XI=; b=Q5eQovSUOr/1/SFMS8bQpPW6S0oBKyNw+zLgoSuY9eF5wjb2No9FA+0AcbK7CBxpDoeMTvDdvyaQwYMEPXkgSUOy29ew7t+4sbLbyIjaX+P9AvpNK9WkNTdlcejVb9jajc305nJ7iOZDAwTY1x945v8kSZE6pvKiS/2ng5C8XR2WAsS41/CA5b94tIM6FFX8w16UiIgGO4ahdLu193k8X84xuYl8kOpCdioSDsxEvKsutqBWj74gGbPMN7aEDk0RkiaYMYRQnzOpAfbKM/HpL/6Zv7VXV0j8/ylWQkgN3vWkDt+8qiLDrcDXp//fQCHqYx4KLBrTeGsjtIdBwj7t4g== Received: from CY5PR15CA0121.namprd15.prod.outlook.com (2603:10b6:930:68::12) by CY5PR12MB6574.namprd12.prod.outlook.com (2603:10b6:930:42::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.17; Sun, 26 Jan 2025 11:57:27 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:68:cafe::ec) by CY5PR15CA0121.outlook.office365.com (2603:10b6:930:68::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:27 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:14 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:12 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 10/14] qsfp: Enable JSON output support for SFF8636 modules Date: Sun, 26 Jan 2025 13:56:31 +0200 Message-ID: <20250126115635.801935-11-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CD:EE_|CY5PR12MB6574:EE_ X-MS-Office365-Filtering-Correlation-Id: 9bfe1a12-656f-402b-1d13-08dd3e009af0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: b10TZUcNhTcoDZjBqe4f+fhEEysKciA56duOyn8MBgs8IFEZ9nuYnfyWt0OxwnUFVqNJDQkqGro4ZSj7hAJxvz/GHWvOMZ+zu7eI7MRlMWHEwrob67xyTLjnJVqsZbcbAwlFGkHmdjWXJo5WLUd82KCqydkXloOsXbaX62jR42MjPFb5tsLDCWKW/X77pt1xtpQ6WstpqwXeXUSHXmqBcbPo3sPx7D8tQWtZIgzyZ8eKfWfZX0I84XDCF7Ge4nUMa8La9AAy+RqgKsDeppWIKb4Ie98Z95hMtd+Ln9acDtzCxwIV9qRzT429tGV6tvid7YkWED5pXaOrT1dpWZFxAq+yOJObokhpYMRYEWLde9v4FnAsqibgImJPqNKayyuWU/wYsDQ3Xg12xWK6pvRviCuxmissk2WDEckOsYvUrqKoNcfp0oKVFKlw0qko9wk+wmW9m0Qs/Q7g0MPCIdgdIPFs9ZqQw50Pzu6+3qw53pWf4zXzL9WwORDqrmxS3ev1i3pfZSd2WGPWdNL+eXJlHW5gLpygKVzxLtce9KoxRmSf+riY2m0bZcwPYForViOtHkYqG2MwJi5qidV+Wsor1ZnFsHo4csPuTR94yworJaPFubuDKvrYlyaxXX4Mn3flU+dkZau+b22TnZaeGl62X5qBzt2s/tw16LtPbG3I5oNMU7q+GRQ1ubqzoIO1Vor8e9IdsSvX7/iEUHpuD8xdnFf4afFju0UsnqN6QmpqmPlf1zwtJtgGvD0deGPKLbC+c+XEZsYR2poFy+sjqtUM2WnE0jhh04MSQ1mElBGDplgWoS4G2Kwy1dGjHOHOWli5fV3N8cQNEypFiAW8czbe4ULCq7E0J3PUpI9TuHlXj+TP5kRYFdcDlrUy3cnd9+L1jC3WP07ejqgGVqHsfwG+AN/TNudG0iuHKEL6g3r7QvxgqOlr/JV14UydaxTN3D/oNObTfgyLwkpbH9aSwIswfOnLhbAy2+Lg1KALB2aPv7IUKe0a+rvK12NhEIw3aLASXY3einv8pg6arWzCglsa0ke2TNRDmK6F1efZhUTbpVsYCw3QfgtJ/C3BF1XMCtsq42Uag9qg6ptWYsrvYzNmYa7UsBUpt69yl3qelxH5co1jhRZ5JPk347ycFJ/JVuujjxmpHntvO5PrJbn+zOaRJQD3i6q3Ev6vKwvH2Ss3WAsjl3iGC+U0WZR9atZSxc7phQWUHzYgjShI8Qqwbp+pg6u3Ld4lQfusIaX1VzCHeAnxMynawqAnZWlxenCbF9AxcVCjJjKN1ILdmPKrZLXHLYTjSyatNrbQGGZz/B0b1IEpGi+8GFOAADCQYTM6D25PCYybWN2WjbBQMnI+gXVPJ6fOXoLc03bYcUVG8kE74pXyqFx2D4+UnCxBuNyTwVrvVIUYELnO56njlMH87Bq1bcH09Q0K1788pK9q7sONdRO3z61QAqPjTL76ZK8ZVwJmoqt5YjLdbMeLJAUvJdYVHMeEsU9krLSNfZkwmrNGmDM= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:27.5421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9bfe1a12-656f-402b-1d13-08dd3e009af0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6574 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz A sample output: $ ethtool --json -m swp13 [ { "identifier": 17, "identifier_description": "QSFP28", "extended_identifier": { "value": 207, "description": "3.5W max. Power consumption", "description": "CDR present in TX, CDR present in RX", "description": "5.0W max. Power consumption, High Power Class (> 3.5 W) enabled" }, "power_set": false, "power_override": true, "connector": 35, "connector_description": "No separable connector", "transceiver_codes": [ 128,0,0,0,0,0,0,0 ], "transceiver_type": "Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below", "encoding": 8, "encoding_description": "PAM4", "br_nominal": 25500, "br_nominal_units": "Mbps", "rate_identifier": 2, "length_(smf,km)": 0, "length_(smf,km)_units": "km", "length_(om3_50um)": 0, "length_(om3_50um)_units": "m", "length_(om2_50um)": 0, "length_(om2_50um)_units": "m", "length_(om1_62.5um)": 0, "length_(om1_62.5um)_units": "m", "length_(copper_or_active_cable)": 3, "length_(copper_or_active_cable)_units": "m", "transmitter_technology": 0, "transmitter_technology_description": "850 nm VCSEL", "laser_wavelength": 850, "laser_wavelength_units": "nm", "laser_wavelength_tolerance": 150, "laser_wavelength_tolerance_units": "nm", "vendor_name": "Mellanox", "vendor_oui": [ 0,2,201 ], "vendor_pn": "MFS1S00-V003E", "vendor_rev": "A6", "vendor_sn": "MT1915FT03913", "date_code": "190412", "revision_compliance": "Unallocated", "rx_loss_of_signal": [ "Yes","Yes","Yes","Yes" ], "tx_loss_of_signal": "None", "rx_loss_of_lock": [ "Yes","Yes","Yes","Yes" ], "tx_loss_of_lock": "None", "tx_adaptive_eq_fault": "None", "module_temperature": 56.75, "module_temperature_units": "degrees C", "module_voltage": 3.261, "module_voltage_units": "V", "alarm/warning_flags_implemented": true, "laser_tx_bias_current": [ 0,0,0,0 ], "laser_tx_bias_current_units": "mA", "transmit_avg_optical_power": [ 0,0,0,0 ], "transmit_avg_optical_power_units": "mW", "rcvr_signal_avg_optical_power": [ 0.0388,0.041,0.0417,0.0392 ], "rcvr_signal_avg_optical_power_units": "mW", "laser_bias_current_high_alarm": [ false,false,false,false ], "laser_bias_current_low_alarm": [ false,false,false,false ], "laser_bias_current_high_warning": [ false,false,false,false ], "laser_bias_current_low_warning": [ false,false,false,false ], "laser_tx_power_high_alarm": [ false,false,false,false ], "laser_tx_power_low_alarm": [ false,false,false,false ], "laser_tx_power_high_warning": [ false,false,false,false ], "laser_tx_power_low_warning": [ false,false,false,false ], "laser_rx_power_high_alarm": [ false,false,false,false ], "laser_rx_power_low_alarm": [ true,true,true,true ], "laser_rx_power_high_warning": [ false,false,false,false ], "laser_rx_power_low_warning": [ true,true,true,true ], "Module temperature high alarm": false, "Module temperature low alarm": false, "Module temperature high warning": false, "Module temperature low warning": false, "Module voltage high alarm": false, "Module voltage low alarm": false, "Module voltage high warning": false, "Module voltage low warning": false, "laser_bias_current": { "high_alarm_threshold": 8.5, "low_alarm_threshold": 5.492, "high_warning_threshold": 8, "low_warning_threshold": 6, "units": "mA" }, "laser_output_power": { "high_alarm_threshold": 3.4673, "low_alarm_threshold": 0.0724, "high_warning_threshold": 1.7378, "low_warning_threshold": 0.1445, "units": "mW" }, "module_temperature": { "high_alarm_threshold": 80, "low_alarm_threshold": -10, "high_warning_threshold": 70, "low_warning_threshold": 0, "units": "degrees C" }, "module_voltage": { "high_alarm_threshold": 3.5, "low_alarm_threshold": 3.1, "high_warning_threshold": 3.465, "low_warning_threshold": 3.135, "units": "V" }, "laser_rx_power": { "high_alarm_threshold": 3.4673, "low_alarm_threshold": 0.0467, "high_warning_threshold": 1.7378, "low_warning_threshold": 0.0933, "units": "mW" } } ] Signed-off-by: Danielle Ratson --- qsfp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qsfp.c b/qsfp.c index d835067..6f95377 100644 --- a/qsfp.c +++ b/qsfp.c @@ -1096,10 +1096,16 @@ int sff8636_show_all_nl(struct cmd_context *ctx) struct sff8636_memory_map map = {}; int ret; + new_json_obj(ctx->json); + open_json_object(NULL); + ret = sff8636_memory_map_init_pages(ctx, &map); if (ret < 0) return ret; sff8636_show_all_common(&map); + close_json_object(); + delete_json_obj(); + return 0; } From patchwork Sun Jan 26 11:56:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950662 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2068.outbound.protection.outlook.com [40.107.93.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC40158558 for ; Sun, 26 Jan 2025 11:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892656; cv=fail; b=U5DAXerL6GViDAT/e6Tuhx1BaHHismJ5L801gMYCyxplneRTBSG9CPjcran5ITRBbBq+ujGDlpFa/zSBzEmdyu+Eq1jKg6P0jWW4ArzeaUHKSMnAdwStIVL2Q3XZquiLCUDy1L+3RfoSaGqcPOhO4J+lqhAfqxLKCgJNhOcBDxY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892656; c=relaxed/simple; bh=pAQddRXhKVtFn0wwFxGSsn0NiyQV0JKzMuB8SLGHx6U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L//MSRojWWtooDZ0H5d+rrZ1AMYllFAo0xN90s6XrSai/O0yG3Baa0GhkN8jk53BsV8s0jKFuYARxe4aztCIx4M0djcfq352xVN8FlrX+osXhCBvb9v3XrenulkirUoWIMG0JWBvmvcyzi4TnzfvA6L7sCd2NPR/UUuLfbK+Iyw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Vi8ZkXGg; arc=fail smtp.client-ip=40.107.93.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Vi8ZkXGg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FiwapTzO6Zi04FSR+23jDAw23A4mDkRnlFq3pwsZVCoGVugWI9WgiBHXIbORL4pfsaPxw381kacKAVHUz3kU1xZbf7kuHbLsxUpRGlbNh0bM+jbmHNZ5DE0p0mUY4VVeJBkViPlmQHfm0jja6DCnFD30BeNUGncD8MZFq0QLSibMk7r/70DzXv8nDEbDuQwMQn4jLdPgSW+UX2Jah5AtD44ZHTbcHVyapBKm63kIoTCSsIaTtK1FdPA62IfpN/P0Tb8osLOWJKt29cX1T0LVWJFtVTHqQ/3UM7OvvS9psmD4M/JltvI93TygQlaBPPAk8sLbftZ6LmFP1NdSeA+WtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L9QKYSkc4/R3IbR+3bemXTfhzEbhjR1oO/sLdUmFQEE=; b=UEEYY8XwwH/Urjq1eeau5VugEEthaqiZ/8O930Kjm+WjOGXkS86/wcq0C/ENLxku29TRZMwcYcny7u6LSBOw2MkT4WNfTT/Kd1OGknvuRTazarGfSUX5JobR1RYD+yH1eNZyKBsXsaDkgmzlLYkXpO0kk3cYrX1oMm7SyJPuxWfygrvIWEdPx7mMvdS/IRrIY0YVsvgn/Jd0Fc0MwL4GjJquymXkJBzluIAMDZrKCcrvpX9jasOgy4kyC/OMwbuR9ZJ6jBMqvDoQjr9iH2INo1QsUxL7K5z56d5ykAIcvYKmHIuxzo2Ba9VvyLsfE/ORu8xnJoZFjvwa8N8UDOYr+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L9QKYSkc4/R3IbR+3bemXTfhzEbhjR1oO/sLdUmFQEE=; b=Vi8ZkXGg81B5Rxrfa4fU8rF9ljGRzQWvnbIE5upnVa0F6nG4Og7eNcfTpBNZJPtB+pB4LK48J4EDfFyBekAgZa3LJX2d6txEHh3YVl/+fMMlurhW7cZ7WuczLw4JCtClPPVpASp3adJyaumtpAhqxBZykao3NwDPookL30zcNduUI73ClqLKOTmO3n0VcO3IvmqyBrm9svq3Vo5KYyKzGAnKjfBrh42wnMBfYQG0tDTnDtyjjOM2dsf99ruW4IkV+xWl2m7hXVIO3dgd2JMkMqpqlCj4wRyYIlDpEnEZl2hs8THI0WtzYRfbJezUIMTPIO7l4sRs9JRWY1FGSskReg== Received: from CY3P220CA0006.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:fb::8) by CYYPR12MB8921.namprd12.prod.outlook.com (2603:10b6:930:c7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:28 +0000 Received: from CY4PEPF0000EE38.namprd03.prod.outlook.com (2603:10b6:930:fb:cafe::2f) by CY3P220CA0006.outlook.office365.com (2603:10b6:930:fb::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE38.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:28 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:17 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:14 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 11/14] sfpid: Add JSON output handling to --module-info in SFF8079 modules Date: Sun, 26 Jan 2025 13:56:32 +0200 Message-ID: <20250126115635.801935-12-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE38:EE_|CYYPR12MB8921:EE_ X-MS-Office365-Filtering-Correlation-Id: e1438dc6-2f52-4b29-6a68-08dd3e009b8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: W/rkBwcPhYC68XK5QkzWnaWjpmNds5p+cgX/00kCqd6Ea0s5hd/tCCpDhfM74S78ksWTGAolkpsNw29f1u1wxnhR2ZASkZA12CFjfeY7No4jrW1oZk1Qs86rA8i7MsJpx6kbzaBJfO3a0I1WjkusX1wDe8uqkbZ5JcyNJZPNcGGc9AvoJlXb8FlAWtbgyC8TOxuGKvJYg4uzuKvcJVX+K7x5Bb2BVqIuE5/LdZxzGm0h9d7mSXB8/dJ9Neo5yU9ylsxQMusxPszXFdf+76GsriSYPe2D/uhra1jRIhOajMdI1nB3MN55RlrfvIKDTn/PvqhpZKwv/owJYkAQwI2R+fjbpTtTWkZmOgpqUb2Gz24U41gM3Z5tzoa+QDbe3QIdobyU1B3Mgb2x88SoGIieUXBTPvvOzjZmBPsU1hcSf/XflnQSoLXHtKLp0eGDUFXd6S9o7g8n+tqPkoGt03vjire2snXGD6Fs2o+HTskAPReUId/7gqlt3tXo0ZZvhm8whSfkM7lJ23OmkymhEC1xoZIYmzq2BuHvNsqggF1Z+r0sC8mau1LbQ0QIrDw4H7zaks9nOEo5z4phdA+jUb01uBGHwa5P4gKCdOBE73tXb5RBr8CKH4UXbOv89jI5CYvbUUgjJcl5kmITXElkkBRCWwztNPr6MHh4Fw4J7LSiTjNVQiVmBsSe8DZmtSSKcZwQQBq6EkrH00zDFfetm0EQyeBtXisXfJOX5zClDPct2uFjZ0NU8XFhoAH5couxL03kzCmErVzmQXOV21NqqwMNRNYyBjow9b72bjkSFQC6fLB6Yhm20sf3B5iitoqFCQrdVlAZWUEYUm93C0RoF4VnPuWyHD/rdFOrcgVkcIm1lWxz7R+1trM+mBYJfl/yVUaRzwfVo8Izfb1HQDRKeppDDDpSoUVPFs1zOwla14V5Y/fpaaLOvUKlPSmapH0GCRBujHctdRres1BrkzPo1UL/lW7u1NFdoSoc5+SVQr7QzvbhdFgVmKQV4s72XdRygeRug1Lbb2pM5Y6U0di+ul1ZiS9eGKoy2B2TTMUBq5s1baY/ogds1cJZo/eTE7NoAXR+f92r1O67A8MUiPzVpmj5a+meNKSv15n5zpwOiIG8CfPIfkBKnUrpmhKwSOtc/zmwhOSbixgrqGVo4sTLaCXs1/eE2S/MEIWQoOEFCmmfJQY0kFjwkkjWq8MUZMYhw5hpkyLo9xwSkGL3jTKj0Tl8i0aKgJp7amb3ezrFIPcNFKHc/uvOqFU+otMoXrRuvIu/uR/w11wklX8gXSKfK6RrSZFK93m01+/GMO3fXN3yQp1HpB45P85T8omH/9h03HFsXqM5b8tgkNkUNlw+ElANWb2nL8/wYMhFlx7pRMfqM8N7bwhrFQwsPVSZk0I9PG3znmEzQ2dfgdR7iViBmGefdnaMvgiSi2/9HvgWJAcmXICyk2pw/91iWWzA7ka6m/biwCXV1m52eWocMDuZSGYdnq0gsYBvluFeY4DUlzLTBvM= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:28.4727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1438dc6-2f52-4b29-6a68-08dd3e009b8c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE38.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8921 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz 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 --- sfpid.c | 360 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 207 insertions(+), 153 deletions(-) diff --git a/sfpid.c b/sfpid.c index 3c126b4..f97e2b3 100644 --- a/sfpid.c +++ b/sfpid.c @@ -42,231 +42,258 @@ static void sff8079_show_connector(const __u8 *id) static void sff8079_show_transceiver(const __u8 *id) { - static const char *pfx = - "\tTransceiver type :"; + static const char *pfx = "Transceiver type"; + char value[140] = ""; - printf("\t%-41s : 0x%02x 0x%02x 0x%02x " \ - "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", - "Transceiver codes", - id[3], id[4], id[5], id[6], - id[7], id[8], id[9], id[10], id[36]); + if (is_json_context()) { + open_json_array("transceiver_codes", ""); + print_int(PRINT_JSON, NULL, "0x%02x", id[3]); + print_int(PRINT_JSON, NULL, "0x%02x", id[4]); + print_int(PRINT_JSON, NULL, "0x%02x", id[5]); + print_int(PRINT_JSON, NULL, "0x%02x", id[6]); + print_int(PRINT_JSON, NULL, "0x%02x", id[7]); + print_int(PRINT_JSON, NULL, "0x%02x", id[8]); + print_int(PRINT_JSON, NULL, "0x%02x", id[9]); + print_int(PRINT_JSON, NULL, "0x%02x", id[10]); + print_int(PRINT_JSON, NULL, "0x%02x", id[36]); + close_json_array(""); + } else { + printf("\t%-41s : 0x%02x 0x%02x 0x%02x " \ + "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", + "Transceiver codes", id[3], id[4], id[5], id[6], + id[7], id[8], id[9], id[10], id[36]); + } /* 10G Ethernet Compliance Codes */ if (id[3] & (1 << 7)) - printf("%s 10G Ethernet: 10G Base-ER" \ - " [SFF-8472 rev10.4 onwards]\n", pfx); + sprintf(value, "%s", + "10G Ethernet: 10G Base-LRM [SFF-8472 rev10.4 onwards]"); if (id[3] & (1 << 6)) - printf("%s 10G Ethernet: 10G Base-LRM\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-LRM"); if (id[3] & (1 << 5)) - printf("%s 10G Ethernet: 10G Base-LR\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-LR"); if (id[3] & (1 << 4)) - printf("%s 10G Ethernet: 10G Base-SR\n", pfx); + sprintf(value, "%s", "10G Ethernet: 10G Base-SR"); /* Infiniband Compliance Codes */ if (id[3] & (1 << 3)) - printf("%s Infiniband: 1X SX\n", pfx); + sprintf(value, "%s", "Infiniband: 1X SX"); if (id[3] & (1 << 2)) - printf("%s Infiniband: 1X LX\n", pfx); + sprintf(value, "%s", "Infiniband: 1X LX"); if (id[3] & (1 << 1)) - printf("%s Infiniband: 1X Copper Active\n", pfx); + sprintf(value, "%s", "Infiniband: 1X Copper Active"); if (id[3] & (1 << 0)) - printf("%s Infiniband: 1X Copper Passive\n", pfx); + sprintf(value, "%s", "Infiniband: 1X Copper Passive"); /* ESCON Compliance Codes */ if (id[4] & (1 << 7)) - printf("%s ESCON: ESCON MMF, 1310nm LED\n", pfx); + sprintf(value, "%s", "ESCON: ESCON MMF, 1310nm LED"); if (id[4] & (1 << 6)) - printf("%s ESCON: ESCON SMF, 1310nm Laser\n", pfx); + sprintf(value, "%s", "ESCON: ESCON SMF, 1310nm Laser"); /* SONET Compliance Codes */ if (id[4] & (1 << 5)) - printf("%s SONET: OC-192, short reach\n", pfx); + sprintf(value, "%s", "SONET: OC-192, short reach"); if (id[4] & (1 << 4)) - printf("%s SONET: SONET reach specifier bit 1\n", pfx); + sprintf(value, "%s", "SONET: SONET reach specifier bit 1"); if (id[4] & (1 << 3)) - printf("%s SONET: SONET reach specifier bit 2\n", pfx); + sprintf(value, "%s", "SONET: SONET reach specifier bit 2"); if (id[4] & (1 << 2)) - printf("%s SONET: OC-48, long reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, long reach"); if (id[4] & (1 << 1)) - printf("%s SONET: OC-48, intermediate reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, intermediate reach"); if (id[4] & (1 << 0)) - printf("%s SONET: OC-48, short reach\n", pfx); + sprintf(value, "%s", "SONET: OC-48, short reach"); if (id[5] & (1 << 6)) - printf("%s SONET: OC-12, single mode, long reach\n", pfx); + sprintf(value, "%s", "SONET: OC-12, single mode, long reach"); if (id[5] & (1 << 5)) - printf("%s SONET: OC-12, single mode, inter. reach\n", pfx); + sprintf(value, "%s", "SONET: OC-12, single mode, inter. reach"); if (id[5] & (1 << 4)) - printf("%s SONET: OC-12, short reach\n", pfx); + sprintf(value, "%s", "SONET: OC-12, short reach"); if (id[5] & (1 << 2)) - printf("%s SONET: OC-3, single mode, long reach\n", pfx); + sprintf(value, "%s", "SONET: OC-3, single mode, long reach"); if (id[5] & (1 << 1)) - printf("%s SONET: OC-3, single mode, inter. reach\n", pfx); + sprintf(value, "%s", "SONET: OC-3, single mode, inter. reach"); if (id[5] & (1 << 0)) - printf("%s SONET: OC-3, short reach\n", pfx); + sprintf(value, "%s", "SONET: OC-3, short reach"); /* Ethernet Compliance Codes */ if (id[6] & (1 << 7)) - printf("%s Ethernet: BASE-PX\n", pfx); + sprintf(value, "%s", "Ethernet: BASE-PX"); if (id[6] & (1 << 6)) - printf("%s Ethernet: BASE-BX10\n", pfx); + sprintf(value, "%s", "Ethernet: BASE-BX10"); if (id[6] & (1 << 5)) - printf("%s Ethernet: 100BASE-FX\n", pfx); + sprintf(value, "%s", "Ethernet: 100BASE-FX"); if (id[6] & (1 << 4)) - printf("%s Ethernet: 100BASE-LX/LX10\n", pfx); + sprintf(value, "%s", "Ethernet: 100BASE-LX/LX10"); if (id[6] & (1 << 3)) - printf("%s Ethernet: 1000BASE-T\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-T"); if (id[6] & (1 << 2)) - printf("%s Ethernet: 1000BASE-CX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-CX"); if (id[6] & (1 << 1)) - printf("%s Ethernet: 1000BASE-LX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-LX"); if (id[6] & (1 << 0)) - printf("%s Ethernet: 1000BASE-SX\n", pfx); + sprintf(value, "%s", "Ethernet: 1000BASE-SX"); /* Fibre Channel link length */ if (id[7] & (1 << 7)) - printf("%s FC: very long distance (V)\n", pfx); + sprintf(value, "%s", "FC: very long distance (V)"); if (id[7] & (1 << 6)) - printf("%s FC: short distance (S)\n", pfx); + sprintf(value, "%s", "FC: short distance (S)"); if (id[7] & (1 << 5)) - printf("%s FC: intermediate distance (I)\n", pfx); + sprintf(value, "%s", "FC: intermediate distance (I)"); if (id[7] & (1 << 4)) - printf("%s FC: long distance (L)\n", pfx); + sprintf(value, "%s", "FC: long distance (L)"); if (id[7] & (1 << 3)) - printf("%s FC: medium distance (M)\n", pfx); + sprintf(value, "%s", "FC: medium distance (M)"); /* Fibre Channel transmitter technology */ if (id[7] & (1 << 2)) - printf("%s FC: Shortwave laser, linear Rx (SA)\n", pfx); + sprintf(value, "%s", "FC: Shortwave laser, linear Rx (SA)"); if (id[7] & (1 << 1)) - printf("%s FC: Longwave laser (LC)\n", pfx); + sprintf(value, "%s", "FC: Longwave laser (LC)"); if (id[7] & (1 << 0)) - printf("%s FC: Electrical inter-enclosure (EL)\n", pfx); + sprintf(value, "%s", "FC: Electrical inter-enclosure (EL)"); if (id[8] & (1 << 7)) - printf("%s FC: Electrical intra-enclosure (EL)\n", pfx); + sprintf(value, "%s", "FC: Electrical intra-enclosure (EL)"); if (id[8] & (1 << 6)) - printf("%s FC: Shortwave laser w/o OFC (SN)\n", pfx); + sprintf(value, "%s", "FC: Shortwave laser w/o OFC (SN)"); if (id[8] & (1 << 5)) - printf("%s FC: Shortwave laser with OFC (SL)\n", pfx); + sprintf(value, "%s", "FC: Shortwave laser with OFC (SL)"); if (id[8] & (1 << 4)) - printf("%s FC: Longwave laser (LL)\n", pfx); + sprintf(value, "%s", "FC: Longwave laser (LL)"); if (id[8] & (1 << 3)) - printf("%s Active Cable\n", pfx); + sprintf(value, "%s", "Active Cable"); if (id[8] & (1 << 2)) - printf("%s Passive Cable\n", pfx); + sprintf(value, "%s", "Passive Cable"); if (id[8] & (1 << 1)) - printf("%s FC: Copper FC-BaseT\n", pfx); + sprintf(value, "%s", "FC: Copper FC-BaseT"); /* Fibre Channel transmission media */ if (id[9] & (1 << 7)) - printf("%s FC: Twin Axial Pair (TW)\n", pfx); + sprintf(value, "%s", "FC: Twin Axial Pair (TW)"); if (id[9] & (1 << 6)) - printf("%s FC: Twisted Pair (TP)\n", pfx); + sprintf(value, "%s", "FC: Twisted Pair (TP)"); if (id[9] & (1 << 5)) - printf("%s FC: Miniature Coax (MI)\n", pfx); + sprintf(value, "%s", "FC: Miniature Coax (MI)"); if (id[9] & (1 << 4)) - printf("%s FC: Video Coax (TV)\n", pfx); + sprintf(value, "%s", "FC: Video Coax (TV)"); if (id[9] & (1 << 3)) - printf("%s FC: Multimode, 62.5um (M6)\n", pfx); + sprintf(value, "%s", "FC: Multimode, 62.5um (M6)"); if (id[9] & (1 << 2)) - printf("%s FC: Multimode, 50um (M5)\n", pfx); + sprintf(value, "%s", "FC: Multimode, 50um (M5)"); if (id[9] & (1 << 0)) - printf("%s FC: Single Mode (SM)\n", pfx); + sprintf(value, "%s", "FC: Single Mode (SM)"); /* Fibre Channel speed */ if (id[10] & (1 << 7)) - printf("%s FC: 1200 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 1200 MBytes/sec"); if (id[10] & (1 << 6)) - printf("%s FC: 800 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 800 MBytes/sec"); if (id[10] & (1 << 4)) - printf("%s FC: 400 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 400 MBytes/sec"); if (id[10] & (1 << 2)) - printf("%s FC: 200 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 200 MBytes/sec"); if (id[10] & (1 << 0)) - printf("%s FC: 100 MBytes/sec\n", pfx); + sprintf(value, "%s", "FC: 100 MBytes/sec"); /* Extended Specification Compliance Codes from SFF-8024 */ if (id[36] == 0x1) - printf("%s Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 5x10^(-5)\n", pfx); + sprintf(value, "%s", + "Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 5x10^(-5)"); if (id[36] == 0x2) - printf("%s Extended: 100G Base-SR4 or 25GBase-SR\n", pfx); + sprintf(value, "%s", "Extended: 100G Base-SR4 or 25GBase-SR"); if (id[36] == 0x3) - printf("%s Extended: 100G Base-LR4 or 25GBase-LR\n", pfx); + sprintf(value, "%s", "Extended: 100G Base-LR4 or 25GBase-LR"); if (id[36] == 0x4) - printf("%s Extended: 100G Base-ER4 or 25GBase-ER\n", pfx); + sprintf(value, "%s", "Extended: 100G Base-ER4 or 25GBase-ER"); if (id[36] == 0x8) - printf("%s Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 5x10^(-5)\n", pfx); + sprintf(value, "%s", + "Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 5x10^(-5)"); if (id[36] == 0xb) - printf("%s Extended: 100G Base-CR4 or 25G Base-CR CA-L\n", pfx); + sprintf(value, "%s", + "Extended: 100G Base-CR4 or 25G Base-CR CA-L"); if (id[36] == 0xc) - printf("%s Extended: 25G Base-CR CA-S\n", pfx); + sprintf(value, "%s", "Extended: 25G Base-CR CA-S"); if (id[36] == 0xd) - printf("%s Extended: 25G Base-CR CA-N\n", pfx); + sprintf(value, "%s", "Extended: 25G Base-CR CA-N"); if (id[36] == 0x16) - printf("%s Extended: 10Gbase-T with SFI electrical interface\n", pfx); + sprintf(value, "%s", + "Extended: 10Gbase-T with SFI electrical interface"); if (id[36] == 0x18) - printf("%s Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 10^(-12)\n", pfx); + sprintf(value, "%s", + "Extended: 100G AOC or 25GAUI C2M AOC with worst BER of 10^(-12)"); if (id[36] == 0x19) - printf("%s Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 10^(-12)\n", pfx); + sprintf(value, "%s", + "Extended: 100G ACC or 25GAUI C2M ACC with worst BER of 10^(-12)"); if (id[36] == 0x1a) - printf("%s Extended: 100GE-DWDM2 (DWDM transceiver using 2 wavelengths on a 1550 nm DWDM grid with a reach up to 80 km)\n", - pfx); + sprintf(value, "%s", + "Extended: 100GE-DWDM2 (DWDM transceiver using 2 wavelengths on a 1550 nm DWDM grid with a reach up to 80 km)"); if (id[36] == 0x1b) - printf("%s Extended: 100G 1550nm WDM (4 wavelengths)\n", pfx); + sprintf(value, "%s", + "Extended: 100G 1550nm WDM (4 wavelengths)"); if (id[36] == 0x1c) - printf("%s Extended: 10Gbase-T Short Reach\n", pfx); + sprintf(value, "%s", "Extended: 10Gbase-T Short Reach"); if (id[36] == 0x1d) - printf("%s Extended: 5GBASE-T\n", pfx); + sprintf(value, "%s", "Extended: 5GBASE-T"); if (id[36] == 0x1e) - printf("%s Extended: 2.5GBASE-T\n", pfx); + sprintf(value, "%s", "Extended: 2.5GBASE-T"); if (id[36] == 0x1f) - printf("%s Extended: 40G SWDM4\n", pfx); + sprintf(value, "%s", "Extended: 40G SWDM4"); if (id[36] == 0x20) - printf("%s Extended: 100G SWDM4\n", pfx); + sprintf(value, "%s", "Extended: 100G SWDM4"); if (id[36] == 0x21) - printf("%s Extended: 100G PAM4 BiDi\n", pfx); + sprintf(value, "%s", "Extended: 100G PAM4 BiDi"); if (id[36] == 0x22) - printf("%s Extended: 4WDM-10 MSA (10km version of 100G CWDM4 with same RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", + "Extended: 4WDM-10 MSA (10km version of 100G CWDM4 with same RS(528,514) FEC in host system)"); if (id[36] == 0x23) - printf("%s Extended: 4WDM-20 MSA (20km version of 100GBASE-LR4 with RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", + "Extended: 4WDM-20 MSA (20km version of 100GBASE-LR4 with RS(528,514) FEC in host system)"); if (id[36] == 0x24) - printf("%s Extended: 4WDM-40 MSA (40km reach with APD receiver and RS(528,514) FEC in host system)\n", - pfx); + sprintf(value, "%s", + "Extended: 4WDM-40 MSA (40km reach with APD receiver and RS(528,514) FEC in host system)"); if (id[36] == 0x25) - printf("%s Extended: 100GBASE-DR (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "Extended: 100GBASE-DR (clause 140), CAUI-4 (no FEC)"); if (id[36] == 0x26) - printf("%s Extended: 100G-FR or 100GBASE-FR1 (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "Extended: 100G-FR or 100GBASE-FR1 (clause 140), CAUI-4 (no FEC)"); if (id[36] == 0x27) - printf("%s Extended: 100G-LR or 100GBASE-LR1 (clause 140), CAUI-4 (no FEC)\n", pfx); + sprintf(value, "%s", + "Extended: 100G-LR or 100GBASE-LR1 (clause 140), CAUI-4 (no FEC)"); if (id[36] == 0x30) - printf("%s Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n", - pfx); + sprintf(value, "%s", + "Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below"); if (id[36] == 0x31) - printf("%s Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below\n", - pfx); + sprintf(value, "%s", + "Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below"); if (id[36] == 0x32) - printf("%s Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n", - pfx); + sprintf(value, "%s", + "Extended: Active Copper Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below"); if (id[36] == 0x33) - printf("%s Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below\n", - pfx); + sprintf(value, "%s", + "Extended: Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 2.6x10-4 for ACC, 10-5 for AUI, or below"); if (id[36] == 0x40) - printf("%s Extended: 50GBASE-CR, 100GBASE-CR2, or 200GBASE-CR4\n", pfx); + sprintf(value, "%s", + "Extended: 50GBASE-CR, 100GBASE-CR2, or 200GBASE-CR4"); if (id[36] == 0x41) - printf("%s Extended: 50GBASE-SR, 100GBASE-SR2, or 200GBASE-SR4\n", pfx); + sprintf(value, "%s", + "Extended: 50GBASE-SR, 100GBASE-SR2, or 200GBASE-SR4"); if (id[36] == 0x42) - printf("%s Extended: 50GBASE-FR or 200GBASE-DR4\n", pfx); + sprintf(value, "%s", "Extended: 50GBASE-FR or 200GBASE-DR4"); if (id[36] == 0x43) - printf("%s Extended: 200GBASE-FR4\n", pfx); + sprintf(value, "%s", "Extended: 200GBASE-FR4"); if (id[36] == 0x44) - printf("%s Extended: 200G 1550 nm PSM4\n", pfx); + sprintf(value, "%s", "Extended: 200G 1550 nm PSM4"); if (id[36] == 0x45) - printf("%s Extended: 50GBASE-LR\n", pfx); + sprintf(value, "%s", "Extended: 50GBASE-LR"); if (id[36] == 0x46) - printf("%s Extended: 200GBASE-LR4\n", pfx); + sprintf(value, "%s", "Extended: 200GBASE-LR4"); if (id[36] == 0x50) - printf("%s Extended: 64GFC EA\n", pfx); + sprintf(value, "%s", "Extended: 64GFC EA"); if (id[36] == 0x51) - printf("%s Extended: 64GFC SW\n", pfx); + sprintf(value, "%s", "Extended: 64GFC SW"); if (id[36] == 0x52) - printf("%s Extended: 64GFC LW\n", pfx); + sprintf(value, "%s", "Extended: 64GFC LW"); if (id[36] == 0x53) - printf("%s Extended: 128GFC EA\n", pfx); + sprintf(value, "%s", "Extended: 128GFC EA"); if (id[36] == 0x54) - printf("%s Extended: 128GFC SW\n", pfx); + sprintf(value, "%s", "Extended: 128GFC SW"); if (id[36] == 0x55) - printf("%s Extended: 128GFC LW\n", pfx); + sprintf(value, "%s", "Extended: 128GFC LW"); + + module_print_any_string(pfx, value); } static void sff8079_show_encoding(const __u8 *id) @@ -276,100 +303,127 @@ static void sff8079_show_encoding(const __u8 *id) static void sff8079_show_rate_identifier(const __u8 *id) { - printf("\t%-41s : 0x%02x", "Rate identifier", id[13]); + char description[SFF_MAX_DESC_LEN]; + switch (id[13]) { case 0x00: - printf(" (unspecified)\n"); + sprintf(description, "%s", "unspecified"); break; case 0x01: - printf(" (4/2/1G Rate_Select & AS0/AS1)\n"); + sprintf(description, "%s", "4/2/1G Rate_Select & AS0/AS1"); break; case 0x02: - printf(" (8/4/2G Rx Rate_Select only)\n"); + sprintf(description, "%s", "8/4/2G Rx Rate_Select only"); break; case 0x03: - printf(" (8/4/2G Independent Rx & Tx Rate_Select)\n"); + sprintf(description, "%s", + "8/4/2G Independent Rx & Tx Rate_Select"); break; case 0x04: - printf(" (8/4/2G Tx Rate_Select only)\n"); + sprintf(description, "%s", "8/4/2G Tx Rate_Select only"); break; default: - printf(" (reserved or unknown)\n"); + sprintf(description, "%s", "reserved or unknown"); break; } + + sff_print_any_hex_field("Rate identifier", "rate_identifier", id[13], + description); } static void sff8079_show_wavelength_or_copper_compliance(const __u8 *id) { + char description[SFF_MAX_DESC_LEN]; + if (id[8] & (1 << 2)) { - printf("\t%-41s : 0x%02x", "Passive Cu cmplnce.", id[60]); switch (id[60]) { case 0x00: - printf(" (unspecified)"); + strncpy(description, "unspecified", + SFF_MAX_DESC_LEN); break; case 0x01: - printf(" (SFF-8431 appendix E)"); + strncpy(description, "SFF-8431 appendix E", + SFF_MAX_DESC_LEN); break; default: - printf(" (unknown)"); + strncpy(description, "unknown", SFF_MAX_DESC_LEN); break; } - printf(" [SFF-8472 rev10.4 only]\n"); + strcat(description, " [SFF-8472 rev10.4 only]"); + sff_print_any_hex_field("Passive Cu cmplnce.", + "passive_cu_cmplnce.", + id[60], description); } else if (id[8] & (1 << 3)) { printf("\t%-41s : 0x%02x", "Active Cu cmplnce.", id[60]); switch (id[60]) { case 0x00: - printf(" (unspecified)"); + strncpy(description, "unspecified", + SFF_MAX_DESC_LEN); break; case 0x01: - printf(" (SFF-8431 appendix E)"); + strncpy(description, "SFF-8431 appendix E", + SFF_MAX_DESC_LEN); break; case 0x04: - printf(" (SFF-8431 limiting)"); + strncpy(description, "SFF-8431 limiting", + SFF_MAX_DESC_LEN); break; default: - printf(" (unknown)"); + strncpy(description, "unknown", SFF_MAX_DESC_LEN); break; } - printf(" [SFF-8472 rev10.4 only]\n"); + strcat(description, " [SFF-8472 rev10.4 only]"); + sff_print_any_hex_field("Active Cu cmplnce.", + "active_cu_cmplnce.", + id[60], description); } else { - printf("\t%-41s : %unm\n", "Laser wavelength", - (id[60] << 8) | id[61]); + module_print_any_uint("Laser wavelength", + (id[60] << 8) | id[61], "nm"); } } static void sff8079_show_options(const __u8 *id) { - static const char *pfx = - "\tOption :"; + static const char *pfx = "Option"; + char value[64] = ""; - printf("\t%-41s : 0x%02x 0x%02x\n", "Option values", id[64], id[65]); + if (is_json_context()) { + open_json_array("option_values", ""); + print_int(PRINT_JSON, NULL, "0x%02x", id[64]); + print_int(PRINT_JSON, NULL, "0x%02x", id[65]); + close_json_array(""); + } else { + printf("\t%-41s : 0x%02x 0x%02x\n", "Option values", id[64], + id[65]); + } if (id[65] & (1 << 1)) - printf("%s RX_LOS implemented\n", pfx); + sprintf(value, "%s", "RX_LOS implemented"); if (id[65] & (1 << 2)) - printf("%s RX_LOS implemented, inverted\n", pfx); + sprintf(value, "%s", "RX_LOS implemented, inverted"); if (id[65] & (1 << 3)) - printf("%s TX_FAULT implemented\n", pfx); + sprintf(value, "%s", "TX_FAULT implemented"); if (id[65] & (1 << 4)) - printf("%s TX_DISABLE implemented\n", pfx); + sprintf(value, "%s", "TX_DISABLE implemented"); if (id[65] & (1 << 5)) - printf("%s RATE_SELECT implemented\n", pfx); + sprintf(value, "%s", "RATE_SELECT implemented"); if (id[65] & (1 << 6)) - printf("%s Tunable transmitter technology\n", pfx); + sprintf(value, "%s", "Tunable transmitter technology"); if (id[65] & (1 << 7)) - printf("%s Receiver decision threshold implemented\n", pfx); + sprintf(value, "%s", "Receiver decision threshold implemented"); if (id[64] & (1 << 0)) - printf("%s Linear receiver output implemented\n", pfx); + sprintf(value, "%s", "Linear receiver output implemented"); if (id[64] & (1 << 1)) - printf("%s Power level 2 requirement\n", pfx); + sprintf(value, "%s", "Power level 2 requirement"); if (id[64] & (1 << 2)) - printf("%s Cooled transceiver implemented\n", pfx); + sprintf(value, "%s", "Cooled transceiver implemented"); if (id[64] & (1 << 3)) - printf("%s Retimer or CDR implemented\n", pfx); + sprintf(value, "%s", "Retimer or CDR implemented"); if (id[64] & (1 << 4)) - printf("%s Paging implemented\n", pfx); + sprintf(value, "%s", "Paging implemented"); if (id[64] & (1 << 5)) - printf("%s Power level 3 requirement\n", pfx); + sprintf(value, "%s", "Power level 3 requirement"); + + module_print_any_string(pfx, value); } static void sff8079_show_all_common(const __u8 *id) @@ -393,7 +447,7 @@ static void sff8079_show_all_common(const __u8 *id) sff8079_show_connector(id); sff8079_show_transceiver(id); sff8079_show_encoding(id); - printf("\t%-41s : %u%s\n", "BR, Nominal", br_nom, "MBd"); + module_print_any_uint("BR Nominal", br_nom, "MBd"); sff8079_show_rate_identifier(id); module_show_value_with_unit(id, 14, "Length (SMF,km)", 1, "km"); @@ -409,8 +463,8 @@ static void sff8079_show_all_common(const __u8 *id) module_show_ascii(id, 40, 55, "Vendor PN"); module_show_ascii(id, 56, 59, "Vendor rev"); sff8079_show_options(id); - printf("\t%-41s : %u%s\n", "BR margin, max", br_max, "%"); - printf("\t%-41s : %u%s\n", "BR margin, min", br_min, "%"); + module_print_any_uint("BR margin max", br_max, "%"); + module_print_any_uint("BR margin min", br_min, "%"); module_show_ascii(id, 68, 83, "Vendor SN"); module_show_ascii(id, 84, 91, "Date code"); } From patchwork Sun Jan 26 11:56:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950663 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2071.outbound.protection.outlook.com [40.107.236.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C41185B76 for ; Sun, 26 Jan 2025 11:57:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892658; cv=fail; b=YQAyI4X+7TMXzZuuouyRc+rS54NpbUfaUl568oZQzbGAP+qouL+DfYYUEbnWcJjGwOquQVP0Sl5zcUe9cEz59xObdcb5wxy65yzivmiryqZBuvD6Nxg+/XzDqveM1QBuS4GLNzpXDkL0DrqFWiMNzMYgnC9AUv0/QOIKFfVqHQk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892658; c=relaxed/simple; bh=9LmqxUqUzEtUZHfdwOW3B6AP3N/CK5Ym86SpM3rNlnU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rQUnGWuZfancvf03TWbWh+nCi9r0AnEW4KjOJ+bF2ve+uIS2uY9LJWuwF6Z98ycPCCw72sIt0Ow8zv535lNERrsXZeytlswD6Ac7wnhUknd5KlzXtEeLwVrLAqzQQdKcRil7Vw2DblN57U/G28Ovx8sxAbSoso1JYyGxNp2HgM0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=IBXtIl0V; arc=fail smtp.client-ip=40.107.236.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="IBXtIl0V" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LscndD7t68MWMwyl9yXxTp9sbBgIYq86/lm1c2dQfnxbScMw7k4t/ofLkcYPqsqA1W0hMSeCvFLqQhPg4b5MOK69IIsTQtkJIBTuWrjYtfUd9Wv/9ZiEUX4bv35YigGV8qbXtpgIq0KfTCj9VH6grRF6lkaBrws0MA6kfc3ztMPMxM9cSvhgv6c1QK44oD6CTwzWw2+SeeF0EJkwN0cwPzVkGTmZ/Pw91eFUyFTJEpDdzka/o+V5d9cO/KgzsWmgRhJl3pTj9q0hGA0BlIkZfIAJt4rnm1whDtAEX/SRtV8dwApi3Sn948uDggknVR9fj6opP7tF0FXXtIMt/b2ROA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tz+ovAn3jXR4UyhHy5F7C54yl0rxnjvog6d23DT4lDk=; b=Su+MSCsf9Yw/7/E7p4A/8mLpsoX7hHLCrpo5JkS8FOoFNVizbVojbMrUBZOrkSyDldVPpHF9SNiEmbPO5QPq64YIDe2XKXjohWM5P5qIz4hNqzTiEa0RQzMH41u2HsHTd/mV6qf5fyOLSU1gDHwgIXdkWecjYl1OX2fOl74eWcR8KAvuNURsDWxWaeJmeDu5iYjoDv1/M6dT/PRKRDqgXDcmuj2FIQZqVNNNaxtCM+hoN82nzPr3VxZ6cV+goLCYeDOwPOvI+ekgsNVP204btbyBh3JSMHWHmr84tEOo4wMdfFmgYrv4haqn2VlWXHN7qA74fB3X0KJwy7QmB1dsUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tz+ovAn3jXR4UyhHy5F7C54yl0rxnjvog6d23DT4lDk=; b=IBXtIl0VZdMS9gXlroSujZMbdKer+xB+lyijOibB2lTOx+IUwCrhPfpckO6yOKYxq2u2KClVhdlUG1ANWrqvJGyx3DlHRk5tBLptFkjRp/+GD4vnKtzJxA9gvT4Do7NC/fnhK36EwcaLq9pPCyo4pVV2ftPIdW6MsiJfL6StgvNUPH15utXPMWZ+3Fxm0i4efsWfL0HYNfqxyDu6/F/2wLbFNElLgkkubtWfU4so9qt74apEScr3ocmFs76QTljXPvb4vJdYS1lkGdTvkgquvWlcSmkcN1X+aRAU0BF76/8eA2DIskHnlSZnsIhOR9jVewzXR+inQXy2TRcIL808nQ== Received: from PH8PR07CA0012.namprd07.prod.outlook.com (2603:10b6:510:2cd::6) by IA1PR12MB9467.namprd12.prod.outlook.com (2603:10b6:208:594::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:33 +0000 Received: from CY4PEPF0000EE39.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::84) by PH8PR07CA0012.outlook.office365.com (2603:10b6:510:2cd::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.21 via Frontend Transport; Sun, 26 Jan 2025 11:57:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE39.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:32 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:19 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:17 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 12/14] sfpdiag: Add JSON output handling to --module-info in SFF8472 modules Date: Sun, 26 Jan 2025 13:56:33 +0200 Message-ID: <20250126115635.801935-13-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE39:EE_|IA1PR12MB9467:EE_ X-MS-Office365-Filtering-Correlation-Id: 018de756-32ce-4e0a-218f-08dd3e009e07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: Pb85p9EBFQ5EyKyZ5inTB2/G6ol0PXMeTYTfs7LSenZP5UUifKXGhMcjcPySsRXIfGUs7CUpyLs8O/QfIIT47Ea6uZm6zCB+BjAvx0BtbGCEY+PhXXpaGp+wi2Dfx3+cMOhHbAtwjo9BYFcyLPKJDcxMOMsk2Uoho6hg6KbhJgkvcqjJjgnezRrFBEcnhNRbhzMRdatl3C7P3zHX66XTaM22uPMTtb6gj43lBKKzhaHWRL/LUBN3yLHTLIyDi3dpgPRGSzGIN+UBKkW31suey3MpZmbI2jZBew5byj7/vio+q1eRBT89U580k8EI3NjMsndVhZQKG4QS8oaNQs0IomKGzGCm8Cb4skvlDUQfiVEp/AjEKEmeMf4hJz6JMLd165Q1tgZ9pjaUtbgi5lKUjrU8OF/k5HtG3ROW/th0KYBmrKB/fVg3VKe7f0gNIm21X65m2NEvcJkGePGaFfOFjReqKIfGm+PVbffCh8H1fWoreMC6Yqh/7Mny4BtJk2hEfliZzcyAQTT2tPD11W1nIftjqe+NKtokZwI589HlTtwGV1sjFVSxs6YRazp3vkun9gV1/Qnte50ckdl5qoJWycUwa5QrtXzcrG7KsE0SbblDzEOZqR2tQH4WEdm/YxfarZRCS6YaS89KHhtHx9jgzuSSFoTXjEk+vUB0JSVEjp6jyZ0QWqTETxe83kEAEwvLLbYUOuRZ6Zq5710QSCpLsl5yRP1qBzYR+n1fBMho2Ug/IWb/c6yflxi9IiCt+tRG82yYcKN3/M7EFmyps5dHZceoOUdmXO3RCREt8L6WRzxTL+1P5xZTGyZCriC+ypLVQKQQpFYCzdQVQePwdMlDBc2g61sMHBDTKITPSqxHW2d895pFAsdq+3S51Dt2rgnyLJRMSzrEhgIEgClqJfOnw4RWljHwOFMYm/v+vUsBvB48dFdgWyQYMuvKUnNSBuC1Vyu5DZkaOYGdpSMYqt42o78vETSKGepsbAQkWvjLMF39xbfTC7WCPE0oxjKIppFHJfKxXznqeY+yrCsX8xlp2HIS7+adTo7aErosGnykiu8SJfuPZiMM8WDzkYtAkUU1kwcJrZlmhMcGr/LOe2JMSoicgIEWC9VPICbIGTg/EHFT6QenxGqIBbLN0dTF8jdwpxaZCWFuwx8ypYMfWhHVN0rKNAnI+qq+RxGxBculiXVyfIitbbUDIr4r3DEVrAqg+T9clj8GLidPv7eQ9hMN1NAvYbHIDihBbEXrymKUWbbYDDt+2sBqsNcNxvB9DUDgEDe9AGj0VbyoTqIojKo0JanRoOtTmcM6voqJTb1eP7VEZksysHGgzIPn5HjveglIXVQ3jubEy49+g3QBNNOR+GdiafpKT+rETVzigmtyUpj0yjkeoky6dfBxCqdQPD//LSjfdrlpQgpdCtIkSVbUFOIIGIeFstLSN4V5vKK1BqIt7vtVxpV5zkODlzuzvHauVReanv35ckx63PTmC1J9xgUXpPNbi6harRhys5Vuo1M= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:32.7261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 018de756-32ce-4e0a-218f-08dd3e009e07 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE39.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB9467 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz 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 --- 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); } } From patchwork Sun Jan 26 11:56:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950664 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2052.outbound.protection.outlook.com [40.107.95.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CED0D86358 for ; Sun, 26 Jan 2025 11:57:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892660; cv=fail; b=ed6rP75yDF9u5bAzftSI+t5YqHBzj177uJ1Z7msMt0qwo+q3eSOdSRDLnI3X1NzlugVpY4pPrklT6fqOBWoAqOzYqf7bYR+6mLqr3iVwzUbKjYCPATZvxmz8qiTUHUTSwN+7h470sLaKRjxjIMsw4z8wSiI2Jk1YLfdWqs8m+S0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892660; c=relaxed/simple; bh=8lBHbJoR8YjaQmqDIZBmLL2tvr0Et/Cl9MMjgM9+LvA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YIRZJthmWtdNNCLM4Wj7JZ2MDjoYTEEy+zFjv9eGdIwl4Sno+7LQ27UJq4J7cCOZmITOaoLTD+81VMzUX2Mltg38rRxqi4mtQFGp+gP/XzS1qQd/2GLrtEDaohMGJMqq1Em3qfn9B7YRRK1MbUNCbiZxgHMln0vURaA0XjOCLpU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Tje5dAON; arc=fail smtp.client-ip=40.107.95.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Tje5dAON" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RCGSxQkIdD1qM7NnX16/TWV9p7U+ru1EnfxfsMi4AeR3jUfGwa9ZFQ0930dkJmx0aqgu/m47aW/vx0RjBg1qvcU4H0d1CSv3VcnSaUgqD43SJX0Nn87k10qO/6r2dx2rusyAJ7fy9TNOrKNOX2pkNh6OQ4z89Bm+vErLdPaFNpHrlErE7zC0ygYhxF05XCIorLnrmMevLOD4f8aZfOi7raNF+MYs4bTBHfNjPNVt9hj7LXE+CgudM6b+NnaLudXS+FLNO1er57+rcEMLgY7WISpSNswoK+LfaQGxHJNSnSWoL6lQWR8NkRnXoSv3khGtlncv/cDa3/4WwflF9iEOHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0aObE+Mhe3cyUDQtIR0MeA5LF/jkMmYK1+zK0ENU5tI=; b=TO+S//GKxNyYo9faRivdyOF4dnDnh4tQ26x+AkUxez5EOqEMSX/9LU+dyLejtMBk8m0WErphIaxmOMvPdXwypSRSVomcfVNJjQlHb0taMOkHUMeco58X1P1lebF6fpkLbTId8SbLQv6MPJeoqCnnFqhJBeJA4OqAlLFkMopbVomYJ4EBySZYgXfLFu/MNexYc47qo0+xbVCf8/+5p5LYW0s208UjEHn4U6SdRkM/NxZO1NrCEXKwMkD4kqeiAXvyyHuuKoZEmD40MYJbxi2T0OtiFl0E6Wp+kzL6BtJTiiN7Orzcko7MJu4auNh8xYFbWirz+F1JesVJ0p+oOr077A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0aObE+Mhe3cyUDQtIR0MeA5LF/jkMmYK1+zK0ENU5tI=; b=Tje5dAONrmYUNbQlZE5vEzVeQh3Hu3DwhyQEVxLeGhBQ+njR25BXzFKYSNxfMvJlkPWXZ/MCRAdXf+s9txHVmCvX9VM9zMF+Fj3uKzPR13SNu3F9e57PrMbykSMaV1zANq6/DJZT/OKM7b4gKR+G3JA09PhFiButEStSakZnOrWN1k2R3yg8JjfVA1z3XumGaNgxcByl+ydwyB+BNB7+QtMtrQNawGcYQiIu14mpCZR5M+7j5eiWPp8+QT25TUUneb8Zv7ZmA5XrjdvA2fDzQIqQTkva7vdYdK07aJapagkLNndjYK/sHT2jx5a0ZdZQsbOBSUZEgeHr8YAGvsgt0g== Received: from CY5PR15CA0138.namprd15.prod.outlook.com (2603:10b6:930:68::20) by LV8PR12MB9084.namprd12.prod.outlook.com (2603:10b6:408:18e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:35 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:930:68:cafe::bc) by CY5PR15CA0138.outlook.office365.com (2603:10b6:930:68::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:21 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:19 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 13/14] ethtool: Enable JSON output support for SFF8079 and SFF8472 modules Date: Sun, 26 Jan 2025 13:56:34 +0200 Message-ID: <20250126115635.801935-14-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CD:EE_|LV8PR12MB9084:EE_ X-MS-Office365-Filtering-Correlation-Id: ff2b5503-b54c-4183-0292-08dd3e009f21 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: WP0/Ojtt2anAo35XKbsEp63bdjSBDMAengdb6VARgJGQC88Kap8vTJhg8uB8dFcNZlwj5tbf34oOPuJt0dR7Y3iTXcE160rUe8oz2XQ/hVcGrywcgMRup132dWSrdbgTuTDAdAFPyMO9Uaf4ISQPM59AHYqjoA3y/51CpQDO5qJtnT6A+TAqzVyHZ81jRWLTNnxZUiQmdnyQsjRbsHOEC0BzpTcOLvXprZ0a4j1R5qivdGQlaijBzIiYAh4ueqKXewDZUQvIQHIR0R/AQtcQkPf2TbelUfayknhRO3Xpdst/ObgZt6AgI0vKeeOAUYdhMqCnA5BHrPCQocIvK4SMrfiHJtGfbsXGV1a6DGncpx0okAJKx7t6n83CnLkACpWAIqymuNj9DssSe40Bgk3ZCFOdnyLMn3ToxiSVUgssMUCoePcQTnkc5d+Ea8w4BgnhOjrPvkFAN9CQ/e9jkYPbzVAhK4hnP7c1jeQMEz1CqaugWzpIqPfv9PJ1lOvpgJx4n8FFmfgVAyyOzvwYjrc+ACRHYzTL6B39Uk17DMiexMFs/CI18ep4OiL8Z5Bz/Z5dF7Pq+dxv1j3ydVfdoE/YTef0m8eE2QwSFN8O+WmwYFaTZbHW4g+BxHbID/dd7/4ox/lLFL6O1qlxj5NldGllCAqS7dNYVEJqi+HDFfyEwcXL6hkm4xQeQ0dWhx2KxcIk3RtjifDLt8xuTX2C3GMHblKgCRNEhvI8MrnrSGe+ebHkKTD1I6wM07U64H7ewl0v7soklu8iqdI2LzsonQucgQMCwzuI2g6imtCXVCmCahyu0E/lAtIzWh6yCg1QxcOY5yiT1YBb+AtbUpGXo0rPRJvzzAradFpATS9KJtQuxK5q7oueVIWiNrKZ09HFgVlRdywNVZT95RD1009dw95aRuM2UMiq2Hc9B6Bi7jky8LmGsvkl4yT7Q5QmCjJxXHS2XBeTYfoyoBCvh1h8ZWVw06R8hWo2xl7befIvUNYTGd2P6NrqP36cweaggns/6LYeJRRMXFxNB/RTX0Jg5hYDAHqkNQK3xn2qVdnmpQeEduEp9SKHbk7vmH4y7zbecW2YqDjpuQV4M/rhkir/2237azfRmhgS5QK0kLJ1evYLK1FrIcGgmrncXovIKXtnz/ONhyBuzIr70O5zLeT7k0wtUYGFXaHKzAjs9wfECFaziCEmYkuZziz3VEWy3v1fW14+Odq6cKacmr6nlJ9YsXfGtxnIDcbCpsJftp0ZZKX/7xXJobG0m8Y1UKfbtRuX0evahAWqZ4NlIA+Apln0xdxGOU0LdySp0/7OpMHlqnqaXgQFlNtg3nNQ5N0KMtcGQ2I1dUdkCcABgDKgAu3Wd0KxVdjmeaRGtqmWFCrBpU1+rA17xp+SWnWc/IHKD6ZXi5yoYudYuuByye66d1wLawCY2vf9K1NYYC39qF5jTAFsUAqHtkPckoXPWB/QmyYliKsIT7e3iISUYpom1eOSqq6XfFANrZLM9kmac6aG8XQktD4= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:34.5734 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff2b5503-b54c-4183-0292-08dd3e009f21 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9084 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz A sample output: $ ethtool --json -m swp13 [ { "identifier": 17, "identifier_description": "QSFP28", "extended_identifier": { "value": 207, "description": "3.5W max. Power consumption", "description": "CDR present in TX, CDR present in RX", "description": "5.0W max. Power consumption, High Power Class (> 3.5 W) enabled" }, "power_set": false, "power_override": true, "connector": 35, "connector_description": "No separable connector", "transceiver_codes": [ 128,0,0,0,0,0,0,0 ], "transceiver_type": "Active Optical Cable with 50GAUI, 100GAUI-2 or 200GAUI-4 C2M. Providing a worst BER of 10-6 or below", "encoding": 8, "encoding_description": "PAM4", "br_nominal": 25500, "br_nominal_units": "Mbps", "rate_identifier": 2, "length_(smf,km)": 0, "length_(smf,km)_units": "km", "length_(om3_50um)": 0, "length_(om3_50um)_units": "m", "length_(om2_50um)": 0, "length_(om2_50um)_units": "m", "length_(om1_62.5um)": 0, "length_(om1_62.5um)_units": "m", "length_(copper_or_active_cable)": 3, "length_(copper_or_active_cable)_units": "m", "transmitter_technology": 0, "transmitter_technology_description": "850 nm VCSEL", "laser_wavelength": 850, "laser_wavelength_units": "nm", "laser_wavelength_tolerance": 150, "laser_wavelength_tolerance_units": "nm", "vendor_name": "Mellanox", "vendor_oui": [ 0,2,201 ], "vendor_pn": "MFS1S00-V003E", "vendor_rev": "A6", "vendor_sn": "MT1915FT03913", "date_code": "190412", "revision_compliance": "Unallocated", "rx_loss_of_signal": [ "Yes","Yes","Yes","Yes" ], "tx_loss_of_signal": "None", "rx_loss_of_lock": [ "Yes","Yes","Yes","Yes" ], "tx_loss_of_lock": "None", "tx_adaptive_eq_fault": "None", "module_temperature": 56.75, "module_temperature_units": "degrees C", "module_voltage": 3.261, "module_voltage_units": "V", "alarm/warning_flags_implemented": true, "laser_tx_bias_current": [ 0,0,0,0 ], "laser_tx_bias_current_units": "mA", "transmit_avg_optical_power": [ 0,0,0,0 ], "transmit_avg_optical_power_units": "mW", "rcvr_signal_avg_optical_power": [ 0.0388,0.041,0.0417,0.0392 ], "rcvr_signal_avg_optical_power_units": "mW", "laser_bias_current_high_alarm": [ false,false,false,false ], "laser_bias_current_low_alarm": [ false,false,false,false ], "laser_bias_current_high_warning": [ false,false,false,false ], "laser_bias_current_low_warning": [ false,false,false,false ], "laser_tx_power_high_alarm": [ false,false,false,false ], "laser_tx_power_low_alarm": [ false,false,false,false ], "laser_tx_power_high_warning": [ false,false,false,false ], "laser_tx_power_low_warning": [ false,false,false,false ], "laser_rx_power_high_alarm": [ false,false,false,false ], "laser_rx_power_low_alarm": [ true,true,true,true ], "laser_rx_power_high_warning": [ false,false,false,false ], "laser_rx_power_low_warning": [ true,true,true,true ], "Module temperature high alarm": false, "Module temperature low alarm": false, "Module temperature high warning": false, "Module temperature low warning": false, "Module voltage high alarm": false, "Module voltage low alarm": false, "Module voltage high warning": false, "Module voltage low warning": false, "laser_bias_current": { "high_alarm_threshold": 8.5, "low_alarm_threshold": 5.492, "high_warning_threshold": 8, "low_warning_threshold": 6, "units": "mA" }, "laser_output_power": { "high_alarm_threshold": 3.4673, "low_alarm_threshold": 0.0724, "high_warning_threshold": 1.7378, "low_warning_threshold": 0.1445, "units": "mW" }, "module_temperature": { "high_alarm_threshold": 80, "low_alarm_threshold": -10, "high_warning_threshold": 70, "low_warning_threshold": 0, "units": "degrees C" }, "module_voltage": { "high_alarm_threshold": 3.5, "low_alarm_threshold": 3.1, "high_warning_threshold": 3.465, "low_warning_threshold": 3.135, "units": "V" }, "laser_rx_power": { "high_alarm_threshold": 3.4673, "low_alarm_threshold": 0.0467, "high_warning_threshold": 1.7378, "low_warning_threshold": 0.0933, "units": "mW" } } ] Signed-off-by: Danielle Ratson --- ethtool.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ethtool.c b/ethtool.c index 2818206..51c9a46 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5002,6 +5002,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: @@ -5021,6 +5023,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, From patchwork Sun Jan 26 11:56:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danielle Ratson X-Patchwork-Id: 13950665 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2048.outbound.protection.outlook.com [40.107.236.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0100F188736 for ; Sun, 26 Jan 2025 11:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892662; cv=fail; b=W0av7NCpuctKJESTIoXVPH8Ou5J+hK/3rp7YKVgBH1qx9o0vlFVFYVJKkRFwO6GLu8p794OvjYzQNJDwrLvkv8ATR9EtT1h1X/uDzmeyHQ7489OIHdxT10m+5oyKkeJy72uY+Zq8K7uVBGK1vrI1D08ffWjwyKFjkY8FHGgv0Oo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737892662; c=relaxed/simple; bh=20pu5d8OSE8JWlZfO3PUBTZhCfRUuqlX+pPQGlkUGbk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fE/m0MQNrZz1l11y4J+7+Q/E0JDF5iwuBftAhmGoF7ITDjeGLaDPs9AubBVlOxTGgh7sMRBNSRJxbDXC53GzrI5ce4ZNj84cKu+BeFaHY2LseI50A2C4P9NC5CXD10DvG7q1qLiVu+g/Li40JZXh74AMkgr7PQxQCI4taM4WMJM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=W8bfLn0O; arc=fail smtp.client-ip=40.107.236.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="W8bfLn0O" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=owFCD6iMhfp/A7G760ARSsRpx6jhN+/ah83bf88ukOkvcu0iqcRaRh6FtzG2LjlZmtYRDfeM3WNLY82bq0Qt/6IXwDVW1yVd4Gtrmx9iR21N8Jqua5mcu70J3YM4fw63lpIHzjWKHnEnSV1zrEDueSy+yHA1ORGyEAKDA3keJXWfTaTF0xcDW/OuoFLOU+sAUma+5UFMafzGrHRG5gMYvCtbZOOs3fTNKV2f6qtitQqXFLju6E3UJXUcjaReF8gkFZMr7CnB7iYVcUTwztnL7psacMUUj59NtxJrVrT0zaXaEGSJoTZdtI10vfmMtCKkJI3OKX4vYni3K707lQapaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TOFVb/jAkvIaJAf8N74yON0yoTiDjZ4XTFEgK1fWFLE=; b=zKsoISfowPiDH/ejVIbDgT7MyriPdCIOZ1mXt27R25veGW/p4I1SRJ/JyOC8xtGQqCThenqLLX7vjnOH0AP2qi3KmtR0q4TkWvskiMAAM7XFVETRTuMePVQzMpYYAl/eDrtt5NI3znK9F2Kkd79nWdqWVyRL82559z32pPsutmeQHSAqJPk2RgrXuo4M8FewRl5hgTDHwNttIVsRquJAWgbHP1r62sH2CuirVAMBW/mtdUs4iVmZywiY37zeI43iqkAzaDFpAPo40xa5Wo4vV1SjMdi8EWXECmTjv/nuagjsUVzV8dupJI37P8LVfr6r45LPMoa/I7j5qkxROQqvjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TOFVb/jAkvIaJAf8N74yON0yoTiDjZ4XTFEgK1fWFLE=; b=W8bfLn0OfkEStLVpUGNoSbbHb7TUi98GPvoS9C6UEA109qCcr6s+7qhADIwGsAcOIaw6Q9dnM/uE/HzoYFHjCNtocXCYKkvlDg0f17g1ilU9iaC9qkIdNxw071PUaB8Z7lEcuRowYJWMwHDUSsvSaIufQaGa2QgugB/OhVQAPKgPSAUFhvUluqrx81RcWw/YvcNQbpO2afY10DgBEoEYy/pE+tyINmx+KpHzq7+AQSvhSdyN/2dZ2jJC3Tf6S2JmKF/CYpT/UDcdWMGTW8t2vnniLuX6UPy6sKEzQk0/s55YombcGtd+Ysk81nQMdMLQbp6TpEqukfG6jv8iJ61Mqg== Received: from PH8PR07CA0016.namprd07.prod.outlook.com (2603:10b6:510:2cd::24) by PH8PR12MB6771.namprd12.prod.outlook.com (2603:10b6:510:1c6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.21; Sun, 26 Jan 2025 11:57:35 +0000 Received: from CY4PEPF0000EE39.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::50) by PH8PR07CA0016.outlook.office365.com (2603:10b6:510:2cd::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8377.22 via Frontend Transport; Sun, 26 Jan 2025 11:57:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000EE39.mail.protection.outlook.com (10.167.242.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.8 via Frontend Transport; Sun, 26 Jan 2025 11:57:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:24 -0800 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Sun, 26 Jan 2025 03:57:21 -0800 From: Danielle Ratson To: CC: , , , , , Danielle Ratson Subject: [PATCH ethtool-next 14/14] ethtool: Add '-j' support to ethtool Date: Sun, 26 Jan 2025 13:56:35 +0200 Message-ID: <20250126115635.801935-15-danieller@nvidia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com> References: <20250126115635.801935-1-danieller@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE39:EE_|PH8PR12MB6771:EE_ X-MS-Office365-Filtering-Correlation-Id: 79eb00c6-eee8-4747-c35f-08dd3e009f4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: 8k5fCIKzjNAFO2WJtzSwvy3/6KeFlQDg4ItmqyHS3dzsmSEr8uMZzef/yuFZ8uPx/xaXpadY1KQ3j+ww1V+6sSSWnKsgfbqoGhC/FntBqFMTz55JmWYBQjtzq+lszmou9Lb7Us0C3rhgz2sF+HFleQQaye5S16O7io1fKuRLm68qMpal+GT/MwhomoILvtaYUaDm/S2d+ejdGOu1Nr4Ce8TWuv3DygTxSuriVFY7QgAIzhUo9WYeGxH/0BiyA6uFGIG8BPKaP4fn66Y5yvVtcaQZd1Pbn1w4XwkkuObsppXxffBYBpgQji3bmMbCwOrh3CeBYeDFO3bsEGR27/XhO3JOE24M0qPt+5bZp6HV3/Tw0ebFIjSaLKs52nCoQs/Cw4Giy9cnc97SDKCJ89eYdLO8IceGZNelrJqzEb16jcLIek6SLpRwc5070ZVNajQ02z3LuKsLOCyA2DlrvD1cUrRkZfVTfefY+F5FJWp8yfQkcFu2f3R3PBtkq46n8Ez2pvLa8smtfbmVj0T7SJVA3YKyJscXsOak6Jkkb3YCxM5BIx0ghpdAEe06m98K2v+IGbcBkVHEkZmIKQgCP/3I8wRVeXVjNj/YeUBeSIGbYyRjJYAdWiAc3Ed02lLcE//jiIvCqynXjb+R+iNECKyfW3iwECZea5ow6c8+rIh4vzUELWNin26cLR0+OVjOKeefRkE2WGC27YhXumCwFXwR5ZtY9cLSMswhQ+IttUOYm+hMm2VZq7MM+Mytnvc2FNyL/sDtFTZSP/xp+7GnO3FtOLe9Aqr0kwCxcSM9Z3KnBH6N4gLDu6PiCjsKgerCnHeqeBEq0WD7AaRGelQMrCAd9JkHtwe6Ipn84PTeVJjwhMoEoWkuSczUA5dt6bK/LElmdJLREHlXlaAm7689dNt+mXOeYhq4vrjDXjdmKwviyc2s/RnuXsyfSQPVwHCCcK7T9uEe7bOUih3pUAUV24ESEG4UcsvSpLPDLBsb7/xN8fnQl612Uakntsn+O0qAhqqdHrvsECaoTn7KXuf51+n+AnT59OmBGm9yOZQ5JAJel5FKdX1BPGR3x4YmaF2BqXE64VWdF7pZWzrLOkMLW6nJmf6Lii4EsyfkncggzqvPQwZ354YK6Ed8eBaBDNeVTGwrJjyfVxOTFbNhXIXLlfbrtWaG0ZtWTxOzRcu4wTmNuoDjhBpNLKCVoB7YyQV4KkK/6gLyHCiRNGOyBdZOCUWxZkDJRDHJjTo92WIwiRu9nyszgNXG9ucI8XVWS5kRfxjBVeo6rKlfbQLpNJbby/GgffbseRFH0rz9YLqMwIeRy9QQ5wmqPJWd4JhARRDn854hKhMDz+C9eQGU1gUa3Y9FXRnWL8LdXXTBmYYtF2hog+2nQdpeBAnVr7Ir7Adc/7D0uAYr5tWmTBDYX+YBVlBjXG7IvPlnsMrdHQnEWm7/1bN4NpPF/3p7O/+408zNG0AbOtKvLIiB/tGQncLlBZeWe+jUEsEUOB1rdygdwv6Hou4= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2025 11:57:34.8511 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79eb00c6-eee8-4747-c35f-08dd3e009f4d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE39.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6771 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Currently, only '--json' flag is supported for JSON output in the ethtool commands. Add support for the shorter '-j' flag also. Signed-off-by: Danielle Ratson --- ethtool.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ethtool.c b/ethtool.c index 51c9a46..ae17d49 100644 --- a/ethtool.c +++ b/ethtool.c @@ -6283,7 +6283,7 @@ static int show_usage(struct cmd_context *ctx __maybe_unused) fprintf(stdout, "\n"); fprintf(stdout, "FLAGS:\n"); fprintf(stdout, " --debug MASK turn on debugging messages\n"); - fprintf(stdout, " --json enable JSON output format (not supported by all commands)\n"); + fprintf(stdout, " -j|--json enable JSON output format (not supported by all commands)\n"); fprintf(stdout, " -I|--include-statistics request device statistics related to the command (not supported by all commands)\n"); return 0; @@ -6539,7 +6539,8 @@ int main(int argc, char **argp) argc -= 2; continue; } - if (*argp && !strcmp(*argp, "--json")) { + if (*argp && (!strcmp(*argp, "--json") || + !strcmp(*argp, "-j"))) { ctx.json = true; argp += 1; argc -= 1;