From: Kory Maincent (Dent Project) Add support for PSE (Power Sourcing Equipment) event monitoring capabilities through the monitor command. Signed-off-by: Kory Maincent --- netlink/monitor.c | 9 ++++++++- netlink/netlink.h | 1 + netlink/pse-pd.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/netlink/monitor.c b/netlink/monitor.c index c511389..a16cb97 100644 --- a/netlink/monitor.c +++ b/netlink/monitor.c @@ -79,6 +79,10 @@ static struct { .cmd = ETHTOOL_MSG_PLCA_NTF, .cb = plca_get_cfg_reply_cb, }, + { + .cmd = ETHTOOL_MSG_PSE_NTF, + .cb = pse_ntf_cb, + }, }; static void clear_filter(struct nl_context *nlctx) @@ -194,7 +198,10 @@ static struct monitor_option monitor_opts[] = { .pattern = "--get-plca-cfg|--set-plca-cfg", .cmd = ETHTOOL_MSG_PLCA_NTF, }, - + { + .pattern = "--pse-event", + .cmd = ETHTOOL_MSG_PSE_NTF, + }, }; static bool pattern_match(const char *s, const char *pattern) diff --git a/netlink/netlink.h b/netlink/netlink.h index 290592b..eefedf7 100644 --- a/netlink/netlink.h +++ b/netlink/netlink.h @@ -93,6 +93,7 @@ int cable_test_tdr_ntf_cb(const struct nlmsghdr *nlhdr, void *data); int fec_reply_cb(const struct nlmsghdr *nlhdr, void *data); int module_reply_cb(const struct nlmsghdr *nlhdr, void *data); int plca_get_cfg_reply_cb(const struct nlmsghdr *nlhdr, void *data); +int pse_ntf_cb(const struct nlmsghdr *nlhdr, void *data); /* dump helpers */ diff --git a/netlink/pse-pd.c b/netlink/pse-pd.c index 5bde176..3fb0616 100644 --- a/netlink/pse-pd.c +++ b/netlink/pse-pd.c @@ -475,6 +475,64 @@ int nl_gpse(struct cmd_context *ctx) return ret; } +static const char *pse_events_name(u64 val) +{ + switch (val) { + case ETHTOOL_PSE_EVENT_OVER_CURRENT: + return "over-current"; + case ETHTOOL_PSE_EVENT_OVER_TEMP: + return "over-temperature"; + case ETHTOOL_C33_PSE_EVENT_DETECTION: + return "detection"; + case ETHTOOL_C33_PSE_EVENT_CLASSIFICATION: + return "classification"; + case ETHTOOL_C33_PSE_EVENT_DISCONNECTION: + return "disconnection"; + case ETHTOOL_PSE_EVENT_OVER_BUDGET: + return "over-budget"; + case ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR: + return "software power control error"; + default: + return "unknown"; + } +} + +int pse_ntf_cb(const struct nlmsghdr *nlhdr, void *data) +{ + const struct nlattr *tb[ETHTOOL_A_PSE_MAX + 1] = {}; + struct nl_context *nlctx = data; + DECLARE_ATTR_TB_INFO(tb); + u64 val; + int ret, i; + + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return MNL_CB_OK; + + if (!tb[ETHTOOL_A_PSE_NTF_EVENTS]) + return MNL_CB_OK; + + nlctx->devname = get_dev_name(tb[ETHTOOL_A_PSE_HEADER]); + if (!dev_ok(nlctx)) + return MNL_CB_OK; + + open_json_object(NULL); + print_string(PRINT_ANY, "ifname", "PSE event for %s:\n", + nlctx->devname); + open_json_array("events", "Events:"); + val = attr_get_uint(tb[ETHTOOL_A_PSE_NTF_EVENTS]); + for (i = 0; 1 << i <= ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR; i++) + if (val & 1 << i) + print_string(PRINT_ANY, NULL, " %s", + pse_events_name(val & 1 << i)); + close_json_array("\n"); + if (ret < 0) + return MNL_CB_OK; + + close_json_object(); + return MNL_CB_OK; +} + /* PSE_SET */ static const struct lookup_entry_u32 podl_pse_admin_control_values[] = { -- 2.43.0