Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules
@ 2021-08-09 10:22 Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 1/6] Update UAPI header copies Ido Schimmel
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Patch #1 updates the UAPI headers.
Patch #2 adds the actual implementation that allows user space to set
transceiver modules' low power mode. See the commit message for example
output.
Patches #3-#5 parse more fields from SFF-8636 and CMIS EEPROMs to
provide better observability regarding the low power mode of the
modules.
Patch #6 adds the ability to reset transceiver modules. See the commit
message for example usage.
Ido Schimmel (6):
Update UAPI header copies
ethtool: Add ability to control transceiver modules' low power mode
ethtool: Print CMIS Module State
ethtool: Print CMIS Module-Level Controls
ethtool: Print SFF-8636 Power set and Power override bits
ethtool: Add ability to reset transceiver modules
Makefile.am | 2 +-
cmis.c | 52 +++++++++
cmis.h | 13 +++
ethtool.8.in | 24 +++++
ethtool.c | 16 +++
netlink/desc-ethtool.c | 12 +++
netlink/extapi.h | 6 ++
netlink/module.c | 191 ++++++++++++++++++++++++++++++++++
netlink/monitor.c | 8 ++
netlink/netlink.h | 2 +
qsfp.c | 6 ++
qsfp.h | 2 +-
shell-completion/bash/ethtool | 23 ++++
uapi/linux/ethtool.h | 4 +-
uapi/linux/ethtool_netlink.h | 35 ++++++-
uapi/linux/if_link.h | 19 ++++
uapi/linux/net_tstamp.h | 17 ++-
uapi/linux/netlink.h | 5 +-
18 files changed, 428 insertions(+), 9 deletions(-)
create mode 100644 netlink/module.c
--
2.31.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 1/6] Update UAPI header copies
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 2/6] ethtool: Add ability to control transceiver modules' low power mode Ido Schimmel
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Update to kernel commit XXX.
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
uapi/linux/ethtool.h | 4 ++--
uapi/linux/ethtool_netlink.h | 35 ++++++++++++++++++++++++++++++++++-
uapi/linux/if_link.h | 19 +++++++++++++++++++
uapi/linux/net_tstamp.h | 17 +++++++++++++++--
uapi/linux/netlink.h | 5 +++--
5 files changed, 73 insertions(+), 7 deletions(-)
diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h
index c6ec1111ffa3..f40b00d94276 100644
--- a/uapi/linux/ethtool.h
+++ b/uapi/linux/ethtool.h
@@ -231,7 +231,7 @@ enum tunable_id {
ETHTOOL_PFC_PREVENTION_TOUT, /* timeout in msecs */
/*
* Add your fresh new tunable attribute above and remember to update
- * tunable_strings[] in net/core/ethtool.c
+ * tunable_strings[] in net/ethtool/common.c
*/
__ETHTOOL_TUNABLE_COUNT,
};
@@ -295,7 +295,7 @@ enum phy_tunable_id {
ETHTOOL_PHY_EDPD,
/*
* Add your fresh new phy tunable attribute above and remember to update
- * phy_tunable_strings[] in net/core/ethtool.c
+ * phy_tunable_strings[] in net/ethtool/common.c
*/
__ETHTOOL_PHY_TUNABLE_COUNT,
};
diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h
index 4653c4c79972..32eabb5773d0 100644
--- a/uapi/linux/ethtool_netlink.h
+++ b/uapi/linux/ethtool_netlink.h
@@ -46,6 +46,10 @@ enum {
ETHTOOL_MSG_FEC_SET,
ETHTOOL_MSG_MODULE_EEPROM_GET,
ETHTOOL_MSG_STATS_GET,
+ ETHTOOL_MSG_PHC_VCLOCKS_GET,
+ ETHTOOL_MSG_MODULE_GET,
+ ETHTOOL_MSG_MODULE_SET,
+ ETHTOOL_MSG_MODULE_RESET_ACT,
/* add new constants above here */
__ETHTOOL_MSG_USER_CNT,
@@ -88,6 +92,10 @@ enum {
ETHTOOL_MSG_FEC_NTF,
ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY,
ETHTOOL_MSG_STATS_GET_REPLY,
+ ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,
+ ETHTOOL_MSG_MODULE_GET_REPLY,
+ ETHTOOL_MSG_MODULE_NTF,
+ ETHTOOL_MSG_MODULE_RESET_NTF,
/* add new constants above here */
__ETHTOOL_MSG_KERNEL_CNT,
@@ -440,6 +448,19 @@ enum {
ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
};
+/* PHC VCLOCKS */
+
+enum {
+ ETHTOOL_A_PHC_VCLOCKS_UNSPEC,
+ ETHTOOL_A_PHC_VCLOCKS_HEADER, /* nest - _A_HEADER_* */
+ ETHTOOL_A_PHC_VCLOCKS_NUM, /* u32 */
+ ETHTOOL_A_PHC_VCLOCKS_INDEX, /* array, s32 */
+
+ /* add new constants above here */
+ __ETHTOOL_A_PHC_VCLOCKS_CNT,
+ ETHTOOL_A_PHC_VCLOCKS_MAX = (__ETHTOOL_A_PHC_VCLOCKS_CNT - 1)
+};
+
/* CABLE TEST */
enum {
@@ -675,7 +696,7 @@ enum {
ETHTOOL_A_MODULE_EEPROM_PAGE, /* u8 */
ETHTOOL_A_MODULE_EEPROM_BANK, /* u8 */
ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS, /* u8 */
- ETHTOOL_A_MODULE_EEPROM_DATA, /* nested */
+ ETHTOOL_A_MODULE_EEPROM_DATA, /* binary */
__ETHTOOL_A_MODULE_EEPROM_CNT,
ETHTOOL_A_MODULE_EEPROM_MAX = (__ETHTOOL_A_MODULE_EEPROM_CNT - 1)
@@ -816,6 +837,18 @@ enum {
ETHTOOL_A_STATS_RMON_MAX = (__ETHTOOL_A_STATS_RMON_CNT - 1)
};
+/* MODULE */
+
+enum {
+ ETHTOOL_A_MODULE_UNSPEC,
+ ETHTOOL_A_MODULE_HEADER, /* nest - _A_HEADER_* */
+ ETHTOOL_A_MODULE_LOW_POWER_ENABLED, /* u8 */
+
+ /* add new constants above here */
+ __ETHTOOL_A_MODULE_CNT,
+ ETHTOOL_A_MODULE_MAX = (__ETHTOOL_A_MODULE_CNT - 1)
+};
+
/* generic netlink info */
#define ETHTOOL_GENL_NAME "ethtool"
#define ETHTOOL_GENL_VERSION 1
diff --git a/uapi/linux/if_link.h b/uapi/linux/if_link.h
index 0e81707a9637..62512efc4f73 100644
--- a/uapi/linux/if_link.h
+++ b/uapi/linux/if_link.h
@@ -341,6 +341,13 @@ enum {
IFLA_ALT_IFNAME, /* Alternative ifname */
IFLA_PERM_ADDRESS,
IFLA_PROTO_DOWN_REASON,
+
+ /* device (sysfs) name as parent, used instead
+ * of IFLA_LINK where there's no parent netdev
+ */
+ IFLA_PARENT_DEV_NAME,
+ IFLA_PARENT_DEV_BUS_NAME,
+
__IFLA_MAX
};
@@ -1234,6 +1241,8 @@ enum {
#define RMNET_FLAGS_INGRESS_MAP_COMMANDS (1U << 1)
#define RMNET_FLAGS_INGRESS_MAP_CKSUMV4 (1U << 2)
#define RMNET_FLAGS_EGRESS_MAP_CKSUMV4 (1U << 3)
+#define RMNET_FLAGS_INGRESS_MAP_CKSUMV5 (1U << 4)
+#define RMNET_FLAGS_EGRESS_MAP_CKSUMV5 (1U << 5)
enum {
IFLA_RMNET_UNSPEC,
@@ -1249,4 +1258,14 @@ struct ifla_rmnet_flags {
__u32 mask;
};
+/* MCTP section */
+
+enum {
+ IFLA_MCTP_UNSPEC,
+ IFLA_MCTP_NET,
+ __IFLA_MCTP_MAX,
+};
+
+#define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1)
+
#endif /* _LINUX_IF_LINK_H */
diff --git a/uapi/linux/net_tstamp.h b/uapi/linux/net_tstamp.h
index 7ed0b3d1c00a..fcc61c73a666 100644
--- a/uapi/linux/net_tstamp.h
+++ b/uapi/linux/net_tstamp.h
@@ -13,7 +13,7 @@
#include <linux/types.h>
#include <linux/socket.h> /* for SO_TIMESTAMPING */
-/* SO_TIMESTAMPING gets an integer bit field comprised of these values */
+/* SO_TIMESTAMPING flags */
enum {
SOF_TIMESTAMPING_TX_HARDWARE = (1<<0),
SOF_TIMESTAMPING_TX_SOFTWARE = (1<<1),
@@ -30,8 +30,9 @@ enum {
SOF_TIMESTAMPING_OPT_STATS = (1<<12),
SOF_TIMESTAMPING_OPT_PKTINFO = (1<<13),
SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14),
+ SOF_TIMESTAMPING_BIND_PHC = (1 << 15),
- SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
+ SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_BIND_PHC,
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) |
SOF_TIMESTAMPING_LAST
};
@@ -46,6 +47,18 @@ enum {
SOF_TIMESTAMPING_TX_SCHED | \
SOF_TIMESTAMPING_TX_ACK)
+/**
+ * struct so_timestamping - SO_TIMESTAMPING parameter
+ *
+ * @flags: SO_TIMESTAMPING flags
+ * @bind_phc: Index of PTP virtual clock bound to sock. This is available
+ * if flag SOF_TIMESTAMPING_BIND_PHC is set.
+ */
+struct so_timestamping {
+ int flags;
+ int bind_phc;
+};
+
/**
* struct hwtstamp_config - %SIOCGHWTSTAMP and %SIOCSHWTSTAMP parameter
*
diff --git a/uapi/linux/netlink.h b/uapi/linux/netlink.h
index 5024c5435749..e83e2e300130 100644
--- a/uapi/linux/netlink.h
+++ b/uapi/linux/netlink.h
@@ -91,9 +91,10 @@ struct nlmsghdr {
#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
#define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
-#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
+#define NLMSG_DATA(nlh) ((void *)(((char *)nlh) + NLMSG_HDRLEN))
#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
- (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
+ (struct nlmsghdr *)(((char *)(nlh)) + \
+ NLMSG_ALIGN((nlh)->nlmsg_len)))
#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
(nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
(nlh)->nlmsg_len <= (len))
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 2/6] ethtool: Add ability to control transceiver modules' low power mode
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 1/6] Update UAPI header copies Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 3/6] ethtool: Print CMIS Module State Ido Schimmel
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Add ability to control transceiver modules' low power mode over netlink.
Example output and usage:
$ ethtool --show-module swp11
Module parameters for swp11:
low-power false
$ ethtool --json --show-module swp11
[ {
"ifname": "swp11",
"low-power": false
} ]
# ethtool --set-module swp11 low-power on
$ ethtool --show-module swp11
Module parameters for swp11:
low-power true
# ethtool --set-module swp11 low-power on
# ethtool --set-module swp11 low-power off
Despite three set commands, only two notifications were emitted, as the
kernel only emits notifications when an attribute changes:
$ ethtool --monitor
listening...
Module parameters for swp11:
low-power true
Module parameters for swp11:
low-power false
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
Makefile.am | 2 +-
ethtool.8.in | 15 ++++
ethtool.c | 11 +++
netlink/desc-ethtool.c | 10 +++
netlink/extapi.h | 4 +
netlink/module.c | 139 ++++++++++++++++++++++++++++++++++
netlink/monitor.c | 4 +
netlink/netlink.h | 1 +
shell-completion/bash/ethtool | 22 ++++++
9 files changed, 207 insertions(+), 1 deletion(-)
create mode 100644 netlink/module.c
diff --git a/Makefile.am b/Makefile.am
index dd357d0a158a..dc5fbec1e09d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,7 +39,7 @@ ethtool_SOURCES += \
netlink/eee.c netlink/tsinfo.c netlink/fec.c \
netlink/stats.c \
netlink/desc-ethtool.c netlink/desc-genlctrl.c \
- netlink/module-eeprom.c \
+ netlink/module-eeprom.c netlink/module.c \
netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \
uapi/linux/ethtool_netlink.h \
uapi/linux/netlink.h uapi/linux/genetlink.h \
diff --git a/ethtool.8.in b/ethtool.8.in
index f83d6d17ae41..f9d901cdefca 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -475,6 +475,13 @@ ethtool \- query or control network driver and hardware settings
.HP
.B ethtool \-\-show\-tunnels
.I devname
+.HP
+.B ethtool \-\-show\-module
+.I devname
+.HP
+.B ethtool \-\-set\-module
+.I devname
+.B2 low-power on off
.
.\" Adjust lines (i.e. full justification) and hyphenate.
.ad
@@ -1458,6 +1465,14 @@ Show tunnel-related device capabilities and state.
List UDP ports kernel has programmed the device to parse as VxLAN,
or GENEVE tunnels.
.RE
+.TP
+.B \-\-set\-module
+Set the transceiver module's parameters.
+.RS 4
+.TP
+.A2 low-power on off
+Enable / disable forcing of low power mode by the host.
+.RE
.SH BUGS
Not supported (in part or whole) on all network drivers.
.SH AUTHOR
diff --git a/ethtool.c b/ethtool.c
index 33a0a492cb15..89ff03b18fbf 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6020,6 +6020,17 @@ static const struct option args[] = {
.nlfunc = nl_gtunnels,
.help = "Show NIC tunnel offload information",
},
+ {
+ .opts = "--show-module",
+ .nlfunc = nl_gmodule,
+ .help = "Show transceiver module settings",
+ },
+ {
+ .opts = "--set-module",
+ .nlfunc = nl_smodule,
+ .help = "Set transceiver module settings",
+ .xhelp = " [ low-power on|off ]\n"
+ },
{
.opts = "-h|--help",
.no_dev = true,
diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c
index d6fc4e2d03df..3fb31b28f288 100644
--- a/netlink/desc-ethtool.c
+++ b/netlink/desc-ethtool.c
@@ -374,6 +374,12 @@ const struct pretty_nla_desc __module_eeprom_desc[] = {
NLATTR_DESC_BINARY(ETHTOOL_A_MODULE_EEPROM_DATA)
};
+static const struct pretty_nla_desc __module_desc[] = {
+ NLATTR_DESC_INVALID(ETHTOOL_A_MODULE_UNSPEC),
+ NLATTR_DESC_NESTED(ETHTOOL_A_MODULE_HEADER, header),
+ NLATTR_DESC_BOOL(ETHTOOL_A_MODULE_LOW_POWER_ENABLED),
+};
+
const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE),
NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset),
@@ -408,6 +414,8 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
NLMSG_DESC(ETHTOOL_MSG_FEC_SET, fec),
NLMSG_DESC(ETHTOOL_MSG_STATS_GET, stats),
NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET, module_eeprom),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_GET, module),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_SET, module),
};
const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc);
@@ -447,6 +455,8 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = {
NLMSG_DESC(ETHTOOL_MSG_FEC_NTF, fec),
NLMSG_DESC(ETHTOOL_MSG_STATS_GET_REPLY, stats),
NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY, module_eeprom),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_GET_REPLY, module),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_NTF, module),
};
const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc);
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 91bf02b5e3be..2ab4c6bc2f8d 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -43,6 +43,8 @@ int nl_gfec(struct cmd_context *ctx);
int nl_sfec(struct cmd_context *ctx);
bool nl_gstats_chk(struct cmd_context *ctx);
int nl_gstats(struct cmd_context *ctx);
+int nl_gmodule(struct cmd_context *ctx);
+int nl_smodule(struct cmd_context *ctx);
int nl_monitor(struct cmd_context *ctx);
int nl_getmodule(struct cmd_context *ctx);
@@ -99,6 +101,8 @@ static inline void nl_monitor_usage(void)
#define nl_gstats_chk NULL
#define nl_gstats NULL
#define nl_getmodule NULL
+#define nl_gmodule NULL
+#define nl_smodule NULL
#endif /* ETHTOOL_ENABLE_NETLINK */
diff --git a/netlink/module.c b/netlink/module.c
new file mode 100644
index 000000000000..59a149075f0f
--- /dev/null
+++ b/netlink/module.c
@@ -0,0 +1,139 @@
+/*
+ * module.c - netlink implementation of module commands
+ *
+ * Implementation of "ethtool --show-module <dev>" and
+ * "ethtool --set-module <dev> ..."
+ */
+
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../internal.h"
+#include "../common.h"
+#include "netlink.h"
+#include "parser.h"
+
+/* MODULE_GET */
+
+int module_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_MODULE_MAX + 1] = {};
+ struct nl_context *nlctx = data;
+ DECLARE_ATTR_TB_INFO(tb);
+ bool silent;
+ int err_ret;
+ int ret;
+
+ silent = nlctx->is_dump || nlctx->is_monitor;
+ err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR;
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return err_ret;
+ nlctx->devname = get_dev_name(tb[ETHTOOL_A_MODULE_HEADER]);
+ if (!dev_ok(nlctx))
+ return err_ret;
+
+ if (silent)
+ print_nl();
+
+ open_json_object(NULL);
+
+ print_string(PRINT_ANY, "ifname", "Module parameters for %s:\n",
+ nlctx->devname);
+
+ if (tb[ETHTOOL_A_MODULE_LOW_POWER_ENABLED]) {
+ bool low_power;
+
+ low_power =
+ mnl_attr_get_u8(tb[ETHTOOL_A_MODULE_LOW_POWER_ENABLED]);
+ print_bool(PRINT_ANY, "low-power", "low-power %s\n", low_power);
+ }
+
+ close_json_object();
+
+ return MNL_CB_OK;
+}
+
+int nl_gmodule(struct cmd_context *ctx)
+{
+ struct nl_context *nlctx = ctx->nlctx;
+ struct nl_socket *nlsk;
+ int ret;
+
+ if (netlink_cmd_check(ctx, ETHTOOL_MSG_MODULE_GET, true))
+ return -EOPNOTSUPP;
+ if (ctx->argc > 0) {
+ fprintf(stderr, "ethtool: unexpected parameter '%s'\n",
+ *ctx->argp);
+ return 1;
+ }
+
+ nlsk = nlctx->ethnl_socket;
+ ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_MODULE_GET,
+ ETHTOOL_A_MODULE_HEADER, 0);
+ if (ret < 0)
+ return ret;
+
+ new_json_obj(ctx->json);
+ ret = nlsock_send_get_request(nlsk, module_reply_cb);
+ delete_json_obj();
+ return ret;
+}
+
+/* MODULE_SET */
+
+static const struct param_parser smodule_params[] = {
+ {
+ .arg = "low-power",
+ .type = ETHTOOL_A_MODULE_LOW_POWER_ENABLED,
+ .handler = nl_parse_u8bool,
+ .min_argc = 1,
+ },
+ {}
+};
+
+int nl_smodule(struct cmd_context *ctx)
+{
+ struct nl_context *nlctx = ctx->nlctx;
+ struct nl_msg_buff *msgbuff;
+ struct nl_socket *nlsk;
+ int ret;
+
+ if (netlink_cmd_check(ctx, ETHTOOL_MSG_MODULE_SET, false))
+ return -EOPNOTSUPP;
+ if (!ctx->argc) {
+ fprintf(stderr, "ethtool (--set-module): parameters missing\n");
+ return 1;
+ }
+
+ nlctx->cmd = "--set-module";
+ nlctx->argp = ctx->argp;
+ nlctx->argc = ctx->argc;
+ nlctx->devname = ctx->devname;
+ nlsk = nlctx->ethnl_socket;
+ msgbuff = &nlsk->msgbuff;
+
+ ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_MODULE_SET,
+ NLM_F_REQUEST | NLM_F_ACK);
+ if (ret < 0)
+ return 2;
+ if (ethnla_fill_header(msgbuff, ETHTOOL_A_MODULE_HEADER,
+ ctx->devname, 0))
+ return -EMSGSIZE;
+
+ ret = nl_parser(nlctx, smodule_params, NULL, PARSER_GROUP_NONE, NULL);
+ if (ret < 0)
+ return 1;
+
+ ret = nlsock_sendmsg(nlsk, NULL);
+ if (ret < 0)
+ return 83;
+ ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx);
+ if (ret == 0)
+ return 0;
+ else
+ return nlctx->exit_code ?: 83;
+}
diff --git a/netlink/monitor.c b/netlink/monitor.c
index 0c4df9e78ee3..d631907817e2 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -71,6 +71,10 @@ static struct {
.cmd = ETHTOOL_MSG_FEC_NTF,
.cb = fec_reply_cb,
},
+ {
+ .cmd = ETHTOOL_MSG_MODULE_NTF,
+ .cb = module_reply_cb,
+ },
};
static void clear_filter(struct nl_context *nlctx)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index 70fa666b20e5..f43c1bff6a58 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -91,6 +91,7 @@ int cable_test_ntf_cb(const struct nlmsghdr *nlhdr, void *data);
int cable_test_tdr_reply_cb(const struct nlmsghdr *nlhdr, void *data);
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);
/* dump helpers */
diff --git a/shell-completion/bash/ethtool b/shell-completion/bash/ethtool
index 45573413985d..5db3b4f50232 100644
--- a/shell-completion/bash/ethtool
+++ b/shell-completion/bash/ethtool
@@ -1137,6 +1137,26 @@ _ethtool_test()
fi
}
+# Completion for ethtool --set-module
+_ethtool_set_module()
+{
+ local -A settings=(
+ [low-power]=1
+ )
+
+ if [ "${settings[$prev]+set}" ]; then
+ COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) )
+ return
+ fi
+
+ # Remove settings which have been seen
+ local word
+ for word in "${words[@]:3:${#words[@]}-4}"; do
+ unset "settings[$word]"
+ done
+
+ COMPREPLY=( $( compgen -W "${!settings[*]}" -- "$cur" ) )
+}
# Complete any ethtool command
_ethtool()
@@ -1189,6 +1209,8 @@ _ethtool()
[--show-time-stamping]=devname
[--statistics]=devname
[--test]=test
+ [--set-module]=set_module
+ [--show-module]=devname
)
local -A other_funcs=(
[--config-ntuple]=config_nfc
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 3/6] ethtool: Print CMIS Module State
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 1/6] Update UAPI header copies Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 2/6] ethtool: Add ability to control transceiver modules' low power mode Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 4/6] ethtool: Print CMIS Module-Level Controls Ido Schimmel
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Print the CMIS Module State when dumping EEPROM contents via the '-m'
option. It can be used, for example, to test module low power mode
settings.
Example output:
# ethtool -m swp11
Identifier : 0x18 (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))
...
Module State : 0x03 (ModuleReady)
# ethtool --set-module swp11 low-power on
# ethtool -m swp11
Identifier : 0x18 (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))
...
Module State : 0x01 (ModuleLowPwr)
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
cmis.c | 35 +++++++++++++++++++++++++++++++++++
cmis.h | 8 ++++++++
2 files changed, 43 insertions(+)
diff --git a/cmis.c b/cmis.c
index 361b721f332f..f09219fd889d 100644
--- a/cmis.c
+++ b/cmis.c
@@ -42,6 +42,39 @@ static void cmis_show_rev_compliance(const __u8 *id)
printf("\t%-41s : Rev. %d.%d\n", "Revision compliance", major, minor);
}
+/**
+ * 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
+ * [3] CMIS Rev. 5, pag. 107, section 8.2.2, Table 8-6
+ */
+static void cmis_show_mod_state(const __u8 *id)
+{
+ __u8 mod_state = (id[CMIS_MODULE_STATE_OFFSET] >> 1) & 0x07;
+
+ printf("\t%-41s : 0x%02x", "Module State", mod_state);
+ switch (mod_state) {
+ case CMIS_MODULE_STATE_MODULE_LOW_PWR:
+ printf(" (ModuleLowPwr)\n");
+ break;
+ case CMIS_MODULE_STATE_MODULE_PWR_UP:
+ printf(" (ModulePwrUp)\n");
+ break;
+ case CMIS_MODULE_STATE_MODULE_READY:
+ printf(" (ModuleReady)\n");
+ break;
+ case CMIS_MODULE_STATE_MODULE_PWR_DN:
+ printf(" (ModulePwrDn)\n");
+ break;
+ case CMIS_MODULE_STATE_MODULE_FAULT:
+ printf(" (ModuleFault)\n");
+ break;
+ default:
+ printf(" (reserved or unknown)\n");
+ break;
+ }
+}
+
/**
* Print information about the device's power consumption.
* Relevant documents:
@@ -336,6 +369,7 @@ void qsfp_dd_show_all(const __u8 *id)
cmis_show_link_len(id);
cmis_show_vendor_info(id);
cmis_show_rev_compliance(id);
+ cmis_show_mod_state(id);
}
void cmis_show_all(const struct ethtool_module_eeprom *page_zero,
@@ -356,4 +390,5 @@ void cmis_show_all(const struct ethtool_module_eeprom *page_zero,
cmis_show_vendor_info(page_zero_data);
cmis_show_rev_compliance(page_zero_data);
+ cmis_show_mod_state(page_zero_data);
}
diff --git a/cmis.h b/cmis.h
index 78ee1495bc33..197b70a2034d 100644
--- a/cmis.h
+++ b/cmis.h
@@ -5,6 +5,14 @@
#define CMIS_ID_OFFSET 0x00
#define CMIS_REV_COMPLIANCE_OFFSET 0x01
+/* Module State (Page 0) */
+#define CMIS_MODULE_STATE_OFFSET 0x03
+#define CMIS_MODULE_STATE_MODULE_LOW_PWR 0x01
+#define CMIS_MODULE_STATE_MODULE_PWR_UP 0x02
+#define CMIS_MODULE_STATE_MODULE_READY 0x03
+#define CMIS_MODULE_STATE_MODULE_PWR_DN 0x04
+#define CMIS_MODULE_STATE_MODULE_FAULT 0x05
+
#define CMIS_MODULE_TYPE_OFFSET 0x55
#define CMIS_MT_MMF 0x01
#define CMIS_MT_SMF 0x02
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 4/6] ethtool: Print CMIS Module-Level Controls
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
` (2 preceding siblings ...)
2021-08-09 10:22 ` [RFC PATCH ethtool-next 3/6] ethtool: Print CMIS Module State Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 5/6] ethtool: Print SFF-8636 Power set and Power override bits Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 6/6] ethtool: Add ability to reset transceiver modules Ido Schimmel
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Print the CMIS Module-Level Controls when dumping EEPROM contents via
the '-m' option. It can be used to understand low power mode enforcement
by the host.
Example output:
# ethtool -m swp11
Identifier : 0x18 (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))
...
Module State : 0x03 (ModuleReady)
LowPwrAllowRequestHW : Off
LowPwrRequestSW : Off
# ethtool --set-module swp11 low-power on
# ethtool -m swp11
Identifier : 0x18 (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))
...
Module State : 0x01 (ModuleLowPwr)
LowPwrAllowRequestHW : Off
LowPwrRequestSW : On
# ethtool --set-module swp11 low-power off
# ethtool -m swp11
Identifier : 0x18 (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))
...
Module State : 0x03 (ModuleReady)
LowPwrAllowRequestHW : Off
LowPwrRequestSW : Off
In the above example, the LowPwrRequestHW signal is ignored and low
power mode is controlled via software only.
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
cmis.c | 17 +++++++++++++++++
cmis.h | 5 +++++
2 files changed, 22 insertions(+)
diff --git a/cmis.c b/cmis.c
index f09219fd889d..f9b4720e6c2c 100644
--- a/cmis.c
+++ b/cmis.c
@@ -75,6 +75,21 @@ static void cmis_show_mod_state(const __u8 *id)
}
}
+/**
+ * Print the current Module-Level Controls. Relevant documents:
+ * [1] CMIS Rev. 5, pag. 58, section 6.3.2.2, Table 6-12
+ * [2] CMIS Rev. 5, pag. 111, section 8.2.6, Table 8-10
+ */
+static void cmis_show_mod_lvl_controls(const __u8 *id)
+{
+ printf("\t%-41s : ", "LowPwrAllowRequestHW");
+ printf("%s\n", ONOFF(id[CMIS_MODULE_CONTROL_OFFSET] &
+ CMIS_LOW_PWR_ALLOW_REQUEST_HW));
+ printf("\t%-41s : ", "LowPwrRequestSW");
+ printf("%s\n", ONOFF(id[CMIS_MODULE_CONTROL_OFFSET] &
+ CMIS_LOW_PWR_REQUEST_SW));
+}
+
/**
* Print information about the device's power consumption.
* Relevant documents:
@@ -370,6 +385,7 @@ void qsfp_dd_show_all(const __u8 *id)
cmis_show_vendor_info(id);
cmis_show_rev_compliance(id);
cmis_show_mod_state(id);
+ cmis_show_mod_lvl_controls(id);
}
void cmis_show_all(const struct ethtool_module_eeprom *page_zero,
@@ -391,4 +407,5 @@ void cmis_show_all(const struct ethtool_module_eeprom *page_zero,
cmis_show_vendor_info(page_zero_data);
cmis_show_rev_compliance(page_zero_data);
cmis_show_mod_state(page_zero_data);
+ cmis_show_mod_lvl_controls(page_zero_data);
}
diff --git a/cmis.h b/cmis.h
index 197b70a2034d..5a314340eff0 100644
--- a/cmis.h
+++ b/cmis.h
@@ -21,6 +21,11 @@
#define CMIS_CURR_TEMP_OFFSET 0x0E
#define CMIS_CURR_CURR_OFFSET 0x10
+/* Module-Level Controls (Page 0) */
+#define CMIS_MODULE_CONTROL_OFFSET 0x1A
+#define CMIS_LOW_PWR_ALLOW_REQUEST_HW (1 << 6)
+#define CMIS_LOW_PWR_REQUEST_SW (1 << 4)
+
#define CMIS_CTOR_OFFSET 0xCB
/* Vendor related information (Page 0) */
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 5/6] ethtool: Print SFF-8636 Power set and Power override bits
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
` (3 preceding siblings ...)
2021-08-09 10:22 ` [RFC PATCH ethtool-next 4/6] ethtool: Print CMIS Module-Level Controls Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 6/6] ethtool: Add ability to reset transceiver modules Ido Schimmel
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Print the SFF-8636 Power set and Power override bits when dumping EEPROM
contents via the '-m' option. They can be used to understand low power
mode enforcement by the host.
The 'SFF8636_LOW_PWR_MODE' define is renamed to 'SFF8636_LOW_PWR_SET' to
reflect its naming in the standard for QSFP+/QSFP28.
Example output:
# ethtool -m swp13
Identifier : 0x11 (QSFP28)
...
Extended identifier description : 5.0W max. Power consumption, High Power Class (> 3.5 W) enabled
Power set : Off
Power override : On
...
Transmit avg optical power (Channel 1) : 0.7633 mW / -1.17 dBm
Transmit avg optical power (Channel 2) : 0.7649 mW / -1.16 dBm
Transmit avg optical power (Channel 3) : 0.7696 mW / -1.14 dBm
Transmit avg optical power (Channel 4) : 0.7739 mW / -1.11 dBm
Rcvr signal avg optical power(Channel 1) : 0.9240 mW / -0.34 dBm
Rcvr signal avg optical power(Channel 2) : 0.9129 mW / -0.40 dBm
Rcvr signal avg optical power(Channel 3) : 0.9194 mW / -0.36 dBm
Rcvr signal avg optical power(Channel 4) : 0.8708 mW / -0.60 dBm
# ethtool --set-module swp13 low-power on
# ethtool -m swp13
Identifier : 0x11 (QSFP28)
...
Extended identifier description : 5.0W max. Power consumption, High Power Class (> 3.5 W) not enabled
Power set : On
Power override : On
...
Transmit avg optical power (Channel 1) : 0.0000 mW / -inf dBm
Transmit avg optical power (Channel 2) : 0.0000 mW / -inf dBm
Transmit avg optical power (Channel 3) : 0.0000 mW / -inf dBm
Transmit avg optical power (Channel 4) : 0.0000 mW / -inf dBm
Rcvr signal avg optical power(Channel 1) : 0.0000 mW / -inf dBm
Rcvr signal avg optical power(Channel 2) : 0.0000 mW / -inf dBm
Rcvr signal avg optical power(Channel 3) : 0.0000 mW / -inf dBm
Rcvr signal avg optical power(Channel 4) : 0.0000 mW / -inf dBm
# ethtool --set-module swp13 low-power off
# ethtool -m swp13
Identifier : 0x11 (QSFP28)
...
Extended identifier description : 5.0W max. Power consumption, High Power Class (> 3.5 W) enabled
Power set : Off
Power override : On
...
Transmit avg optical power (Channel 1) : 0.7733 mW / -1.12 dBm
Transmit avg optical power (Channel 2) : 0.7754 mW / -1.10 dBm
Transmit avg optical power (Channel 3) : 0.7885 mW / -1.03 dBm
Transmit avg optical power (Channel 4) : 0.7886 mW / -1.03 dBm
Rcvr signal avg optical power(Channel 1) : 0.9248 mW / -0.34 dBm
Rcvr signal avg optical power(Channel 2) : 0.9129 mW / -0.40 dBm
Rcvr signal avg optical power(Channel 3) : 0.9187 mW / -0.37 dBm
Rcvr signal avg optical power(Channel 4) : 0.8785 mW / -0.56 dBm
In the above example, the LPMode signal is ignored (Power override is
always on) and low power mode is controlled via software only.
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
qsfp.c | 6 ++++++
qsfp.h | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/qsfp.c b/qsfp.c
index 644fe148a5aa..08ffb90447f3 100644
--- a/qsfp.c
+++ b/qsfp.c
@@ -252,6 +252,12 @@ static void sff8636_show_ext_identifier(const __u8 *id)
printf(" High Power Class (> 3.5 W) enabled\n");
else
printf(" High Power Class (> 3.5 W) not enabled\n");
+ printf("\t%-41s : ", "Power set");
+ printf("%s\n", ONOFF(id[SFF8636_PWR_MODE_OFFSET] &
+ SFF8636_LOW_PWR_SET));
+ printf("\t%-41s : ", "Power override");
+ printf("%s\n", ONOFF(id[SFF8636_PWR_MODE_OFFSET] &
+ SFF8636_PWR_OVERRIDE));
}
static void sff8636_show_connector(const __u8 *id)
diff --git a/qsfp.h b/qsfp.h
index 1d8f24b5cbc2..aabf09fdc623 100644
--- a/qsfp.h
+++ b/qsfp.h
@@ -180,7 +180,7 @@
#define SFF8636_PWR_MODE_OFFSET 0x5D
#define SFF8636_HIGH_PWR_ENABLE (1 << 2)
-#define SFF8636_LOW_PWR_MODE (1 << 1)
+#define SFF8636_LOW_PWR_SET (1 << 1)
#define SFF8636_PWR_OVERRIDE (1 << 0)
#define SFF8636_TX_APP_SELECT_4_OFFSET 0x5E
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH ethtool-next 6/6] ethtool: Add ability to reset transceiver modules
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
` (4 preceding siblings ...)
2021-08-09 10:22 ` [RFC PATCH ethtool-next 5/6] ethtool: Print SFF-8636 Power set and Power override bits Ido Schimmel
@ 2021-08-09 10:22 ` Ido Schimmel
5 siblings, 0 replies; 7+ messages in thread
From: Ido Schimmel @ 2021-08-09 10:22 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, andrew, mkubecek, pali, vadimp, mlxsw, Ido Schimmel
From: Ido Schimmel <idosch@nvidia.com>
Add ability to reset transceiver modules over netlink.
Example usage:
# ethtool --reset-module swp11
$ ethtool --monitor
listening...
Module reset done for swp11
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
ethtool.8.in | 9 ++++++
ethtool.c | 5 ++++
netlink/desc-ethtool.c | 2 ++
netlink/extapi.h | 2 ++
netlink/module.c | 52 +++++++++++++++++++++++++++++++++++
netlink/monitor.c | 4 +++
netlink/netlink.h | 1 +
shell-completion/bash/ethtool | 1 +
8 files changed, 76 insertions(+)
diff --git a/ethtool.8.in b/ethtool.8.in
index f9d901cdefca..9953289758d4 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -482,6 +482,9 @@ ethtool \- query or control network driver and hardware settings
.B ethtool \-\-set\-module
.I devname
.B2 low-power on off
+.HP
+.B ethtool \-\-reset\-module
+.I devname
.
.\" Adjust lines (i.e. full justification) and hyphenate.
.ad
@@ -1473,6 +1476,12 @@ Set the transceiver module's parameters.
.A2 low-power on off
Enable / disable forcing of low power mode by the host.
.RE
+.TP
+.B \-\-reset\-module
+Reset the transceiver module to its initial state. Reset is performed by either
+asserting the relevant hardware signal or by writing to the module's reset bit
+in its EEPROM.
+.RE
.SH BUGS
Not supported (in part or whole) on all network drivers.
.SH AUTHOR
diff --git a/ethtool.c b/ethtool.c
index 89ff03b18fbf..0ce574b62692 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6031,6 +6031,11 @@ static const struct option args[] = {
.help = "Set transceiver module settings",
.xhelp = " [ low-power on|off ]\n"
},
+ {
+ .opts = "--reset-module",
+ .nlfunc = nl_reset_module,
+ .help = "Reset transceiver module",
+ },
{
.opts = "-h|--help",
.no_dev = true,
diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c
index 3fb31b28f288..fce065fce3ae 100644
--- a/netlink/desc-ethtool.c
+++ b/netlink/desc-ethtool.c
@@ -416,6 +416,7 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET, module_eeprom),
NLMSG_DESC(ETHTOOL_MSG_MODULE_GET, module),
NLMSG_DESC(ETHTOOL_MSG_MODULE_SET, module),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_RESET_ACT, module),
};
const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc);
@@ -457,6 +458,7 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = {
NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY, module_eeprom),
NLMSG_DESC(ETHTOOL_MSG_MODULE_GET_REPLY, module),
NLMSG_DESC(ETHTOOL_MSG_MODULE_NTF, module),
+ NLMSG_DESC(ETHTOOL_MSG_MODULE_RESET_NTF, module),
};
const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc);
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 2ab4c6bc2f8d..6c294d9058ce 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -45,6 +45,7 @@ bool nl_gstats_chk(struct cmd_context *ctx);
int nl_gstats(struct cmd_context *ctx);
int nl_gmodule(struct cmd_context *ctx);
int nl_smodule(struct cmd_context *ctx);
+int nl_reset_module(struct cmd_context *ctx);
int nl_monitor(struct cmd_context *ctx);
int nl_getmodule(struct cmd_context *ctx);
@@ -103,6 +104,7 @@ static inline void nl_monitor_usage(void)
#define nl_getmodule NULL
#define nl_gmodule NULL
#define nl_smodule NULL
+#define nl_reset_module NULL
#endif /* ETHTOOL_ENABLE_NETLINK */
diff --git a/netlink/module.c b/netlink/module.c
index 59a149075f0f..ae5423ff92f6 100644
--- a/netlink/module.c
+++ b/netlink/module.c
@@ -137,3 +137,55 @@ int nl_smodule(struct cmd_context *ctx)
else
return nlctx->exit_code ?: 83;
}
+
+/* MODULE_RESET_ACT */
+
+int module_reset_ntf_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_MODULE_MAX + 1] = {};
+ struct nl_context *nlctx = data;
+ DECLARE_ATTR_TB_INFO(tb);
+ int ret;
+
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return MNL_CB_OK;
+ nlctx->devname = get_dev_name(tb[ETHTOOL_A_MODULE_HEADER]);
+ if (!dev_ok(nlctx))
+ return MNL_CB_OK;
+
+ printf("\nModule reset done for %s\n", nlctx->devname);
+
+ return MNL_CB_OK;
+}
+
+int nl_reset_module(struct cmd_context *ctx)
+{
+ struct nl_context *nlctx = ctx->nlctx;
+ struct nl_msg_buff *msgbuff;
+ struct nl_socket *nlsk;
+ int ret;
+
+ if (netlink_cmd_check(ctx, ETHTOOL_MSG_MODULE_RESET_ACT, false))
+ return -EOPNOTSUPP;
+
+ nlsk = nlctx->ethnl_socket;
+ msgbuff = &nlsk->msgbuff;
+
+ ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_MODULE_RESET_ACT,
+ NLM_F_REQUEST | NLM_F_ACK);
+ if (ret < 0)
+ return 2;
+ if (ethnla_fill_header(msgbuff, ETHTOOL_A_MODULE_HEADER,
+ ctx->devname, 0))
+ return -EMSGSIZE;
+
+ ret = nlsock_sendmsg(nlsk, NULL);
+ if (ret < 0)
+ return 83;
+ ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx);
+ if (ret == 0)
+ return 0;
+ else
+ return nlctx->exit_code ?: 83;
+}
diff --git a/netlink/monitor.c b/netlink/monitor.c
index d631907817e2..e850c3d72108 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -75,6 +75,10 @@ static struct {
.cmd = ETHTOOL_MSG_MODULE_NTF,
.cb = module_reply_cb,
},
+ {
+ .cmd = ETHTOOL_MSG_MODULE_RESET_NTF,
+ .cb = module_reset_ntf_cb,
+ },
};
static void clear_filter(struct nl_context *nlctx)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index f43c1bff6a58..1e49d7f2bab3 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -92,6 +92,7 @@ int cable_test_tdr_reply_cb(const struct nlmsghdr *nlhdr, void *data);
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 module_reset_ntf_cb(const struct nlmsghdr *nlhdr, void *data);
/* dump helpers */
diff --git a/shell-completion/bash/ethtool b/shell-completion/bash/ethtool
index 5db3b4f50232..8818985f1cd9 100644
--- a/shell-completion/bash/ethtool
+++ b/shell-completion/bash/ethtool
@@ -1211,6 +1211,7 @@ _ethtool()
[--test]=test
[--set-module]=set_module
[--show-module]=devname
+ [--reset-module]=devname
)
local -A other_funcs=(
[--config-ntuple]=config_nfc
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-08-09 10:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 10:22 [RFC PATCH ethtool-next 0/6] ethtool: Add ability to control transceiver modules Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 1/6] Update UAPI header copies Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 2/6] ethtool: Add ability to control transceiver modules' low power mode Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 3/6] ethtool: Print CMIS Module State Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 4/6] ethtool: Print CMIS Module-Level Controls Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 5/6] ethtool: Print SFF-8636 Power set and Power override bits Ido Schimmel
2021-08-09 10:22 ` [RFC PATCH ethtool-next 6/6] ethtool: Add ability to reset transceiver modules Ido Schimmel
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).