|
|
c96cf6 |
From abc33073ed6d4528d3c951cc719a155a6e1178cd Mon Sep 17 00:00:00 2001
|
|
|
c96cf6 |
From: Amit Cohen <amitc@mellanox.com>
|
|
|
c96cf6 |
Date: Thu, 2 Jul 2020 16:11:11 +0300
|
|
|
c96cf6 |
Subject: [PATCH 21/26] netlink: settings: expand linkstate_reply_cb() to
|
|
|
c96cf6 |
support link extended state
|
|
|
c96cf6 |
|
|
|
c96cf6 |
Print extended state in addition to link state.
|
|
|
c96cf6 |
|
|
|
c96cf6 |
In case that extended state is not provided, print state only.
|
|
|
c96cf6 |
If extended substate is provided in addition to the extended state,
|
|
|
c96cf6 |
print it also.
|
|
|
c96cf6 |
|
|
|
c96cf6 |
Signed-off-by: Amit Cohen <amitc@mellanox.com>
|
|
|
c96cf6 |
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
|
|
|
c96cf6 |
(cherry picked from commit ba6367d2bb32173166b91fbcc053865c99ca7c57)
|
|
|
c96cf6 |
---
|
|
|
c96cf6 |
netlink/settings.c | 147 ++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
c96cf6 |
1 file changed, 146 insertions(+), 1 deletion(-)
|
|
|
c96cf6 |
|
|
|
c96cf6 |
diff --git a/netlink/settings.c b/netlink/settings.c
|
|
|
c96cf6 |
index 3a9518a7e12b..75db15e5069c 100644
|
|
|
c96cf6 |
--- a/netlink/settings.c
|
|
|
c96cf6 |
+++ b/netlink/settings.c
|
|
|
c96cf6 |
@@ -565,6 +565,149 @@ int linkinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data)
|
|
|
c96cf6 |
return MNL_CB_OK;
|
|
|
c96cf6 |
}
|
|
|
c96cf6 |
|
|
|
c96cf6 |
+static const char *get_enum_string(const char *const *string_table, unsigned int n_string_table,
|
|
|
c96cf6 |
+ unsigned int val)
|
|
|
c96cf6 |
+{
|
|
|
c96cf6 |
+ if (val >= n_string_table || !string_table[val])
|
|
|
c96cf6 |
+ return NULL;
|
|
|
c96cf6 |
+ else
|
|
|
c96cf6 |
+ return string_table[val];
|
|
|
c96cf6 |
+}
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_link_ext_state[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_AUTONEG] = "Autoneg",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE] = "Link training failure",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH] = "Logical mismatch",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY] = "Bad signal integrity",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_NO_CABLE] = "No cable",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_CABLE_ISSUE] = "Cable issue",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_EEPROM_ISSUE] = "EEPROM issue",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_CALIBRATION_FAILURE] = "Calibration failure",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_POWER_BUDGET_EXCEEDED] = "Power budget exceeded",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_STATE_OVERHEAT] = "Overheat",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_autoneg_link_ext_substate[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_NO_PARTNER_DETECTED] =
|
|
|
c96cf6 |
+ "No partner detected",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_ACK_NOT_RECEIVED] =
|
|
|
c96cf6 |
+ "Ack not received",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_NEXT_PAGE_EXCHANGE_FAILED] =
|
|
|
c96cf6 |
+ "Next page exchange failed",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_NO_PARTNER_DETECTED_FORCE_MODE] =
|
|
|
c96cf6 |
+ "No partner detected during force mode",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_FEC_MISMATCH_DURING_OVERRIDE] =
|
|
|
c96cf6 |
+ "FEC mismatch during override",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_AN_NO_HCD] =
|
|
|
c96cf6 |
+ "No HCD",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_link_training_link_ext_substate[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_FRAME_LOCK_NOT_ACQUIRED] =
|
|
|
c96cf6 |
+ "KR frame lock not acquired",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_INHIBIT_TIMEOUT] =
|
|
|
c96cf6 |
+ "KR link inhibit timeout",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_PARTNER_DID_NOT_SET_RECEIVER_READY] =
|
|
|
c96cf6 |
+ "KR Link partner did not set receiver ready",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LT_REMOTE_FAULT] =
|
|
|
c96cf6 |
+ "Remote side is not ready yet",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_link_logical_mismatch_link_ext_substate[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LLM_PCS_DID_NOT_ACQUIRE_BLOCK_LOCK] =
|
|
|
c96cf6 |
+ "PCS did not acquire block lock",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LLM_PCS_DID_NOT_ACQUIRE_AM_LOCK] =
|
|
|
c96cf6 |
+ "PCS did not acquire AM lock",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LLM_PCS_DID_NOT_GET_ALIGN_STATUS] =
|
|
|
c96cf6 |
+ "PCS did not get align_status",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LLM_FC_FEC_IS_NOT_LOCKED] =
|
|
|
c96cf6 |
+ "FC FEC is not locked",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_LLM_RS_FEC_IS_NOT_LOCKED] =
|
|
|
c96cf6 |
+ "RS FEC is not locked",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_bad_signal_integrity_link_ext_substate[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_BSI_LARGE_NUMBER_OF_PHYSICAL_ERRORS] =
|
|
|
c96cf6 |
+ "Large number of physical errors",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_BSI_UNSUPPORTED_RATE] =
|
|
|
c96cf6 |
+ "Unsupported rate",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *const names_cable_issue_link_ext_substate[] = {
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_CI_UNSUPPORTED_CABLE] =
|
|
|
c96cf6 |
+ "Unsupported cable",
|
|
|
c96cf6 |
+ [ETHTOOL_LINK_EXT_SUBSTATE_CI_CABLE_TEST_FAILURE] =
|
|
|
c96cf6 |
+ "Cable test failure",
|
|
|
c96cf6 |
+};
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static const char *link_ext_substate_get(uint8_t link_ext_state_val, uint8_t link_ext_substate_val)
|
|
|
c96cf6 |
+{
|
|
|
c96cf6 |
+ switch (link_ext_state_val) {
|
|
|
c96cf6 |
+ case ETHTOOL_LINK_EXT_STATE_AUTONEG:
|
|
|
c96cf6 |
+ return get_enum_string(names_autoneg_link_ext_substate,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_autoneg_link_ext_substate),
|
|
|
c96cf6 |
+ link_ext_substate_val);
|
|
|
c96cf6 |
+ case ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE:
|
|
|
c96cf6 |
+ return get_enum_string(names_link_training_link_ext_substate,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_link_training_link_ext_substate),
|
|
|
c96cf6 |
+ link_ext_substate_val);
|
|
|
c96cf6 |
+ case ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH:
|
|
|
c96cf6 |
+ return get_enum_string(names_link_logical_mismatch_link_ext_substate,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_link_logical_mismatch_link_ext_substate),
|
|
|
c96cf6 |
+ link_ext_substate_val);
|
|
|
c96cf6 |
+ case ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY:
|
|
|
c96cf6 |
+ return get_enum_string(names_bad_signal_integrity_link_ext_substate,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_bad_signal_integrity_link_ext_substate),
|
|
|
c96cf6 |
+ link_ext_substate_val);
|
|
|
c96cf6 |
+ case ETHTOOL_LINK_EXT_STATE_CABLE_ISSUE:
|
|
|
c96cf6 |
+ return get_enum_string(names_cable_issue_link_ext_substate,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_cable_issue_link_ext_substate),
|
|
|
c96cf6 |
+ link_ext_substate_val);
|
|
|
c96cf6 |
+ default:
|
|
|
c96cf6 |
+ return NULL;
|
|
|
c96cf6 |
+ }
|
|
|
c96cf6 |
+}
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static void linkstate_link_ext_substate_print(const struct nlattr *tb[], struct nl_context *nlctx,
|
|
|
c96cf6 |
+ uint8_t link_ext_state_val)
|
|
|
c96cf6 |
+{
|
|
|
c96cf6 |
+ uint8_t link_ext_substate_val;
|
|
|
c96cf6 |
+ const char *link_ext_substate_str;
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ if (!tb[ETHTOOL_A_LINKSTATE_EXT_SUBSTATE])
|
|
|
c96cf6 |
+ return;
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ link_ext_substate_val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_EXT_SUBSTATE]);
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ link_ext_substate_str = link_ext_substate_get(link_ext_state_val, link_ext_substate_val);
|
|
|
c96cf6 |
+ if (!link_ext_substate_str)
|
|
|
c96cf6 |
+ printf(", %u", link_ext_substate_val);
|
|
|
c96cf6 |
+ else
|
|
|
c96cf6 |
+ printf(", %s", link_ext_substate_str);
|
|
|
c96cf6 |
+}
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+static void linkstate_link_ext_state_print(const struct nlattr *tb[], struct nl_context *nlctx)
|
|
|
c96cf6 |
+{
|
|
|
c96cf6 |
+ uint8_t link_ext_state_val;
|
|
|
c96cf6 |
+ const char *link_ext_state_str;
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ if (!tb[ETHTOOL_A_LINKSTATE_EXT_STATE])
|
|
|
c96cf6 |
+ return;
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ link_ext_state_val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_EXT_STATE]);
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ link_ext_state_str = get_enum_string(names_link_ext_state,
|
|
|
c96cf6 |
+ ARRAY_SIZE(names_link_ext_state),
|
|
|
c96cf6 |
+ link_ext_state_val);
|
|
|
c96cf6 |
+ if (!link_ext_state_str)
|
|
|
c96cf6 |
+ printf(" (%u", link_ext_state_val);
|
|
|
c96cf6 |
+ else
|
|
|
c96cf6 |
+ printf(" (%s", link_ext_state_str);
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
+ linkstate_link_ext_substate_print(tb, nlctx, link_ext_state_val);
|
|
|
c96cf6 |
+ printf(")");
|
|
|
c96cf6 |
+}
|
|
|
c96cf6 |
+
|
|
|
c96cf6 |
int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
|
|
|
c96cf6 |
{
|
|
|
c96cf6 |
const struct nlattr *tb[ETHTOOL_A_LINKSTATE_MAX + 1] = {};
|
|
|
c96cf6 |
@@ -585,7 +728,9 @@ int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
|
|
|
c96cf6 |
uint8_t val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_LINK]);
|
|
|
c96cf6 |
|
|
|
c96cf6 |
print_banner(nlctx);
|
|
|
c96cf6 |
- printf("\tLink detected: %s\n", val ? "yes" : "no");
|
|
|
c96cf6 |
+ printf("\tLink detected: %s", val ? "yes" : "no");
|
|
|
c96cf6 |
+ linkstate_link_ext_state_print(tb, nlctx);
|
|
|
c96cf6 |
+ printf("\n");
|
|
|
c96cf6 |
}
|
|
|
c96cf6 |
|
|
|
c96cf6 |
if (tb[ETHTOOL_A_LINKSTATE_SQI]) {
|
|
|
c96cf6 |
--
|
|
|
c96cf6 |
2.26.2
|
|
|
c96cf6 |
|