[PATCH ethtool-next v4 04/16] cmis: Change loop order in cmis_show_dom_chan_lvl_flags()
From: Danielle Ratson <hidden>
Date: 2025-02-05 15:55:32
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted> Reviewed-by: Amit Cohen <redacted> --- cmis.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/cmis.c b/cmis.c
index 5efafca..9cd2bb1 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); } }
--
2.47.0