From: Danielle Ratson <danieller@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: <mkubecek@suse.cz>, <matt@traverse.com.au>,
<daniel.zahka@gmail.com>, <amcohen@nvidia.com>,
<nbu-mlxsw@exchange.nvidia.com>,
Danielle Ratson <danieller@nvidia.com>
Subject: [PATCH ethtool-next 05/14] qsfp: Refactor sff8636_show_dom() by moving code into separate functions
Date: Sun, 26 Jan 2025 13:56:26 +0200 [thread overview]
Message-ID: <20250126115635.801935-6-danieller@nvidia.com> (raw)
In-Reply-To: <20250126115635.801935-1-danieller@nvidia.com>
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 <danieller@nvidia.com>
---
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);
}
--
2.47.0
next prev parent reply other threads:[~2025-01-26 11:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-26 11:56 [PATCH ethtool-next 00/14] Add JSON output to --module-info Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 01/14] module_common: Add a new file to all the common code for all module types Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 02/14] sff_common: Move sff_show_revision_compliance() to qsfp.c Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 03/14] cmis: Change loop order in cmis_show_dom_chan_lvl_flags() Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 04/14] qsfp: Reorder the channel-level flags list for SFF8636 module type Danielle Ratson
2025-01-26 11:56 ` Danielle Ratson [this message]
2025-01-27 19:44 ` [PATCH ethtool-next 05/14] qsfp: Refactor sff8636_show_dom() by moving code into separate functions Vadim Fedorenko
2025-01-28 13:17 ` Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 06/14] module_common: Add helpers to support JSON printing for common value types Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 07/14] cmis: Add JSON output handling to --module-info in CMIS modules Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 08/14] cmis: Enable JSON output support " Danielle Ratson
2025-01-27 20:12 ` Jakub Kicinski
2025-01-28 13:18 ` Danielle Ratson
2025-01-28 22:09 ` Jakub Kicinski
2025-01-29 7:06 ` Danielle Ratson
2025-01-30 1:17 ` Jakub Kicinski
2025-01-30 12:38 ` Danielle Ratson
2025-01-30 16:24 ` Jakub Kicinski
2025-01-30 17:20 ` Andrew Lunn
2025-02-02 18:22 ` Danielle Ratson
2025-02-02 19:40 ` Andrew Lunn
2025-02-03 9:58 ` Danielle Ratson
2025-02-03 20:59 ` Jakub Kicinski
2025-01-29 9:40 ` Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 09/14] qsfp: Add JSON output handling to --module-info in SFF8636 modules Danielle Ratson
2025-01-27 20:16 ` Jakub Kicinski
2025-01-28 13:23 ` Danielle Ratson
2025-01-28 22:13 ` Jakub Kicinski
2025-01-29 11:37 ` Gal Pressman
2025-01-29 11:53 ` Danielle Ratson
2025-01-29 16:21 ` Petr Machata
2025-01-29 12:50 ` Danielle Ratson
2025-01-29 10:44 ` Petr Machata
2025-01-29 11:53 ` Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 10/14] qsfp: Enable JSON output support for " Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 11/14] sfpid: Add JSON output handling to --module-info in SFF8079 modules Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 12/14] sfpdiag: Add JSON output handling to --module-info in SFF8472 modules Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 13/14] ethtool: Enable JSON output support for SFF8079 and " Danielle Ratson
2025-01-26 11:56 ` [PATCH ethtool-next 14/14] ethtool: Add '-j' support to ethtool Danielle Ratson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250126115635.801935-6-danieller@nvidia.com \
--to=danieller@nvidia.com \
--cc=amcohen@nvidia.com \
--cc=daniel.zahka@gmail.com \
--cc=matt@traverse.com.au \
--cc=mkubecek@suse.cz \
--cc=nbu-mlxsw@exchange.nvidia.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).