From patchwork Wed Oct 11 22:12:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13418012 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACAB2249EA for ; Wed, 11 Oct 2023 22:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="KcHd3z+6" Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0510691 for ; Wed, 11 Oct 2023 15:13:17 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7740cedd4baso20621785a.2 for ; Wed, 11 Oct 2023 15:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1697062396; x=1697667196; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=QMXs2ZjdP060taxzGMradMjobe3Z68DmqtrSkLKr6f8=; b=KcHd3z+6wK33Y+w9uHSpwOjleX8U7At4jCNqEpxwQTpJth/NJCEWEDxFrU286MSa26 CtxHbTcbwbXpPRacx6ZxamIT7zWz1TB83vJcaAGDQyIXe19TPuImfiMzjvVrnXgP+hEk Dxx+arZslaFTbM74V6ndJ/3PVFugaHMpY6Buc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697062396; x=1697667196; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QMXs2ZjdP060taxzGMradMjobe3Z68DmqtrSkLKr6f8=; b=M7KIBLX7C/eelYTxGWyj/rCShSEuTu3+WRkGUya7BKuWoX+1yf1BZJCZUi0LNsWjLc Rc45U7LKfvGnIlSYnD1sSkDyVzpRfAMGbpKZJVg33QIB++DiHPzuGUWSmtf7RJU8Ux3g xJTOp0+rq16lat1dQLrddpsw3bzKI++ELTcHVLjArQF052A6vFxnWft7wmdmJxwE+nd3 4WB/RjYXP8WZUeum7q4CCHwk8MgYIfwzGFZVFZiXya9RpVNoy8T5dJB+Vdl8RK63t7pc o07js+HBJiSqEKcy2d+DFI6XKGwfdKLPZ1NqLuFQqEe8itKVnI2nObrm4kER739ZEFtU E4hA== X-Gm-Message-State: AOJu0YzwmqqNPP0dKIOwMFl18YPEfeGf9JX3PieSIIijuR+AM7Hi+Q0E VWa3aZt0e7DBokVuibCU+5MuOHjZJIAzgIh5Fxc3/wm5sCfXF50zQJNUs+zdi9SpGohdPsi/AOu UnSUHrm/EAmvNEVy2MvR2mccCWMB3Y6KSv1Sjig/kGUdO+LShF4Mhvv0uFfkBUHhoLkNiRDdMBu 1hCsO2RSUQMg== X-Google-Smtp-Source: AGHT+IFh6a4ASUnCVQKjMFdtZB9oDTb2zRgY09MeWCeKP04VRZH9EuZ5OzTOemMaqpPr+qdKRIYcDg== X-Received: by 2002:a05:620a:47ae:b0:775:967e:3307 with SMTP id dt46-20020a05620a47ae00b00775967e3307mr22715640qkb.1.1697062395628; Wed, 11 Oct 2023 15:13:15 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id a12-20020a05620a102c00b007759a81d88esm5505705qkk.50.2023.10.11.15.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 15:13:15 -0700 (PDT) From: Florian Fainelli To: netdev@vger.kernel.org Cc: Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , opendmb@gmail.com, justin.chen@broadcom.com, Michal Kubecek Subject: [PATCH ethtool 2/2] wol: Add support for WAKE_MDA Date: Wed, 11 Oct 2023 15:12:42 -0700 Message-Id: <20231011221242.4180589-5-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231011221242.4180589-1-florian.fainelli@broadcom.com> References: <20231011221242.4180589-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_BOUND_DIGITS_15,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Allow waking-up from a specific MAC destination address, this is particularly useful with a number of Ethernet PHYs that have limited buffering and packet matching abilities. Example: ethtool -s eth0 wol e mac-da 01:00:5e:00:00:fb Signed-off-by: Florian Fainelli --- common.c | 16 ++++++++++++++-- ethtool.8.in | 15 +++++++++++---- ethtool.c | 26 +++++++++++++++++++++----- netlink/desc-ethtool.c | 1 + netlink/settings.c | 25 ++++++++++++++++++++++--- test-cmdline.c | 4 ++++ 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/common.c b/common.c index b8fd4d5bc0f4..a42d00fe3c0c 100644 --- a/common.c +++ b/common.c @@ -120,6 +120,8 @@ static char *unparse_wolopts(int wolopts) *p++ = 's'; if (wolopts & WAKE_FILTER) *p++ = 'f'; + if (wolopts & WAKE_MDA) + *p++ = 'e'; } else { *p = 'd'; } @@ -129,13 +131,13 @@ static char *unparse_wolopts(int wolopts) int dump_wol(struct ethtool_wolinfo *wol) { + int i; + int delim = 0; fprintf(stdout, " Supports Wake-on: %s\n", unparse_wolopts(wol->supported)); fprintf(stdout, " Wake-on: %s\n", unparse_wolopts(wol->wolopts)); if (wol->supported & WAKE_MAGICSECURE) { - int i; - int delim = 0; fprintf(stdout, " SecureOn password: "); for (i = 0; i < SOPASS_MAX; i++) { @@ -145,6 +147,16 @@ int dump_wol(struct ethtool_wolinfo *wol) } fprintf(stdout, "\n"); } + delim = 0; + if (wol->supported & WAKE_MDA) { + fprintf(stdout, " Destination MAC: "); + for (i = 0; i < ETH_ALEN; i++) { + fprintf(stdout, "%s%02x", delim ? ":" : "", + wol->mac_da[i]); + delim = 1; + } + fprintf(stdout, "\n"); + } return 0; } diff --git a/ethtool.8.in b/ethtool.8.in index c0c37a427715..c7f457b9b739 100644 --- a/ethtool.8.in +++ b/ethtool.8.in @@ -62,7 +62,7 @@ .\" .\" \(*WO - wol flags .\" -.ds WO \fBp\fP|\fBu\fP|\fBm\fP|\fBb\fP|\fBa\fP|\fBg\fP|\fBs\fP|\fBf|\fBd\fP... +.ds WO \fBp\fP|\fBu\fP|\fBm\fP|\fBb\fP|\fBa\fP|\fBg\fP|\fBs\fP|\fBf|\fBe|\fBd\fP... .\" .\" \(*FL - flow type values .\" @@ -281,7 +281,7 @@ ethtool \- query or control network driver and hardware settings .B2 xcvr internal external .RB [ wol \ \fIN\fP[\fB/\fP\fIM\fP] .RB | \ wol \ \*(WO] -.RB [ sopass \ \*(MA] +.RB [ sopass \ \*(MA | mac-da \ \*(MA ] .RB [ master-slave \ \*(MS] .RB [ msglvl .IR N\fP[/\fIM\fP] \ | @@ -949,14 +949,21 @@ a Wake on ARP g Wake on MagicPacket\[tm] s Enable SecureOn\[tm] password for MagicPacket\[tm] f Wake on filter(s) +e Wake on specific MAC destination address d T{ Disable (wake on nothing). This option clears all previous options. T} .TE .TP .B sopass \*(MA -Sets the SecureOn\[tm] password. The argument to this option must be 6 -bytes in Ethernet MAC hex format (\*(MA). +Sets the secureon\[tm] password. The argument to this option must be 6 +bytes in ethernet mac hex format (\*(MA). +.PP +.TE +.TP +.B mac-da \*(MA +Sets the destination MAC address to match against. The argument to this option +must be 6 bytes in ethernet mac hex format (\*(MA). .PP .BI msglvl \ N .br diff --git a/ethtool.c b/ethtool.c index af51220b63cc..513b4ed11623 100644 --- a/ethtool.c +++ b/ethtool.c @@ -973,6 +973,9 @@ static int parse_wolopts(char *optstr, u32 *data) case 'f': *data |= WAKE_FILTER; break; + case 'e': + *data |= WAKE_MDA; + break; case 'd': *data = 0; break; @@ -2971,8 +2974,8 @@ static int do_sset(struct cmd_context *ctx) int gset_changed = 0; /* did anything in GSET change? */ u32 wol_wanted = 0; int wol_change = 0; - u8 sopass_wanted[SOPASS_MAX]; - int sopass_change = 0; + u8 sopass_wanted[SOPASS_MAX], mda_wanted[ETH_ALEN]; + int sopass_change = 0, mda_change = 0; int gwol_changed = 0; /* did anything in GWOL change? */ int msglvl_changed = 0; u32 msglvl_wanted = 0; @@ -3093,6 +3096,13 @@ static int do_sset(struct cmd_context *ctx) exit_bad_args(); get_mac_addr(argp[i], sopass_wanted); sopass_change = 1; + } else if (!strcmp(argp[i], "mac-da")) { + gwol_changed = 1; + i++; + if (i >= argc) + exit_bad_args(); + get_mac_addr(argp[i], mda_wanted); + mda_change = 1; } else if (!strcmp(argp[i], "msglvl")) { i++; if (i >= argc) @@ -3295,14 +3305,18 @@ static int do_sset(struct cmd_context *ctx) if (err < 0) { perror("Cannot get current wake-on-lan settings"); } else { + int i; /* Change everything the user specified. */ if (wol_change) wol.wolopts = wol_wanted; if (sopass_change) { - int i; for (i = 0; i < SOPASS_MAX; i++) wol.sopass[i] = sopass_wanted[i]; } + if (mda_change) { + for (i = 0; i < ETH_ALEN; i++) + wol.mac_da[i] = mda_wanted[i]; + } /* Try to perform the update. */ wol.cmd = ETHTOOL_SWOL; @@ -3315,6 +3329,8 @@ static int do_sset(struct cmd_context *ctx) fprintf(stderr, " not setting wol\n"); if (sopass_change) fprintf(stderr, " not setting sopass\n"); + if (mda_change) + fprintf(stderr, " not setting mac-da\n"); } } @@ -5669,8 +5685,8 @@ static const struct option args[] = { " [ advertise %x[/%x] | mode on|off ... [--] ]\n" " [ phyad %d ]\n" " [ xcvr internal|external ]\n" - " [ wol %d[/%d] | p|u|m|b|a|g|s|f|d... ]\n" - " [ sopass %x:%x:%x:%x:%x:%x ]\n" + " [ wol %d[/%d] | p|u|m|b|a|g|s|f|e|d... ]\n" + " [ sopass %x:%x:%x:%x:%x:%x | mac-da %x:%x:%x:%x:%x:%x ]\n" " [ msglvl %d[/%d] | type on|off ... [--] ]\n" " [ master-slave preferred-master|preferred-slave|forced-master|forced-slave ]\n" }, diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c index 661de267262f..78732bc2719c 100644 --- a/netlink/desc-ethtool.c +++ b/netlink/desc-ethtool.c @@ -120,6 +120,7 @@ static const struct pretty_nla_desc __wol_desc[] = { NLATTR_DESC_NESTED(ETHTOOL_A_WOL_HEADER, header), NLATTR_DESC_NESTED(ETHTOOL_A_WOL_MODES, bitset), NLATTR_DESC_BINARY(ETHTOOL_A_WOL_SOPASS), + NLATTR_DESC_BINARY(ETHTOOL_A_WOL_MAC_DA), }; static const struct pretty_nla_desc __features_desc[] = { diff --git a/netlink/settings.c b/netlink/settings.c index a506618ba0a4..a13251863af1 100644 --- a/netlink/settings.c +++ b/netlink/settings.c @@ -810,6 +810,7 @@ int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data) DECLARE_ATTR_TB_INFO(tb); struct nl_context *nlctx = data; struct ethtool_wolinfo wol = {}; + unsigned int len; int ret; if (nlctx->is_dump || nlctx->is_monitor) @@ -824,8 +825,6 @@ int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data) if (tb[ETHTOOL_A_WOL_MODES]) walk_bitset(tb[ETHTOOL_A_WOL_MODES], NULL, wol_modes_cb, &wol); if (tb[ETHTOOL_A_WOL_SOPASS]) { - unsigned int len; - len = mnl_attr_get_payload_len(tb[ETHTOOL_A_WOL_SOPASS]); if (len != SOPASS_MAX) fprintf(stderr, "invalid SecureOn password length %u (should be %u)\n", @@ -835,6 +834,16 @@ int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data) mnl_attr_get_payload(tb[ETHTOOL_A_WOL_SOPASS]), SOPASS_MAX); } + if (tb[ETHTOOL_A_WOL_MAC_DA]) { + len = mnl_attr_get_payload_len(tb[ETHTOOL_A_WOL_SOPASS]); + if (len != ETH_ALEN) + fprintf(stderr, "invalid destinatino MAC address length %u (should be %u)\n", + len, ETH_ALEN); + else + memcpy(wol.mac_da, + mnl_attr_get_payload(tb[ETHTOOL_A_WOL_MAC_DA]), + ETH_ALEN); + } print_banner(nlctx); dump_wol(&wol); @@ -1050,10 +1059,11 @@ enum { WAKE_MAGIC_BIT = 5, WAKE_MAGICSECURE_BIT = 6, WAKE_FILTER_BIT = 7, + WAKE_MDA_BIT = 8, }; #define WAKE_ALL (WAKE_PHY | WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_ARP | \ - WAKE_MAGIC | WAKE_MAGICSECURE) + WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_MDA) static const struct lookup_entry_u8 port_values[] = { { .arg = "tp", .val = PORT_TP }, @@ -1112,6 +1122,7 @@ char wol_bit_chars[WOL_MODE_COUNT] = { [WAKE_MAGIC_BIT] = 'g', [WAKE_MAGICSECURE_BIT] = 's', [WAKE_FILTER_BIT] = 'f', + [WAKE_MDA_BIT] = 'e', }; const struct char_bitset_parser_data wol_parser_data = { @@ -1224,6 +1235,14 @@ static const struct param_parser sset_params[] = { .handler_data = &sopass_parser_data, .min_argc = 1, }, + { + .arg = "mac-da", + .group = ETHTOOL_MSG_WOL_SET, + .type = ETHTOOL_A_WOL_MAC_DA, + .handler = nl_parse_byte_str, + .handler_data = &sopass_parser_data, + .min_argc = 1, + }, { .arg = "msglvl", .group = ETHTOOL_MSG_DEBUG_SET, diff --git a/test-cmdline.c b/test-cmdline.c index cb803ed1a93d..cfe7d24c065f 100644 --- a/test-cmdline.c +++ b/test-cmdline.c @@ -74,6 +74,10 @@ static struct test_case { { 1, "--change devname sopass 01:23:45:67:89:" }, { 1, "-s devname sopass 01:23:45:67:89" }, { 1, "--change devname sopass" }, + { 0, "-s devname mac-da 01:23:45:67:89:ab" }, + { 1, "--change devname mac-da 01:23:45:67:89:" }, + { 1, "-s devname mac-da 01:23:45:67:89" }, + { 1, "--change devname mac-da" }, { 0, "-s devname msglvl 1" }, { 1, "--change devname msglvl" }, { 0, "-s devname msglvl hw on rx_status off" },