From patchwork Wed Sep 5 17:54:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Cree X-Patchwork-Id: 966605 X-Patchwork-Delegate: linville@tuxdriver.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=solarflare.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 425BF83dZ2z9s5c for ; Thu, 6 Sep 2018 03:55:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727592AbeIEW0g (ORCPT ); Wed, 5 Sep 2018 18:26:36 -0400 Received: from dispatch1-us1.ppe-hosted.com ([67.231.154.164]:44086 "EHLO dispatch1-us1.ppe-hosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbeIEW0g (ORCPT ); Wed, 5 Sep 2018 18:26:36 -0400 X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us3.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id 3FFDDB8005A; Wed, 5 Sep 2018 17:55:19 +0000 (UTC) Received: from ec-desktop.uk.solarflarecom.com (10.17.20.45) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 5 Sep 2018 10:54:59 -0700 From: Edward Cree Subject: [PATCH ethtool] ethtool: support combinations of FEC modes To: "John W. Linville" , netdev CC: Ganesh Goudar , Jakub Kicinski , Dustin Byford , Dirk van der Merwe Message-ID: <518b8b8b-0151-1053-3798-6009044ed53a@solarflare.com> Date: Wed, 5 Sep 2018 18:54:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-GB X-Originating-IP: [10.17.20.45] X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-24074.004 X-TM-AS-Result: No-6.436000-4.000000-10 X-TMASE-MatchedRID: 44Oe4Yka/HLs0qN1TlHQvNsfd0p6MYVXhV0srjoqtx+NxFb0yp4mrzO+ sIxDA42KqOyY/u7ajs1HY8G1Pkp8igHn+odtc9qQNDFopLoM9OL4h+uI7dxXxAFbHA9TqNLQcHj giTON9jJtoWjVt1YIZpLiv6y4vDKVPUtyIkHfnjWk3yyn4uPtLb4kZYg1dp8su6qThyrnanOvek lZ9sa6cQ48nMzZz++J+o8Uli1+5Sh9qWc29kNCfBNEPNwNrw/r7f6JAS2hKPhUFL8kNivfsPBYR o06eVj3i4cqUEexecqJWb/nLuJNUeztpCSqSkXKHcQQBuf4ZFu+PvV96SZIY5soi2XrUn/JyeMt MD9QOgBJeFvFlVDkf46HM5rqDwqtKDOj8CCZLCSM8mWRHcVEZD+2T9n7Iv/6txbzWkK55u6B2SW UCMfuMUMMprcbiest X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--6.436000-4.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-24074.004 X-MDID: 1536170120-e5r5uqrNu4fu Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Of the three drivers that currently support FEC configuration, two (sfc and cxgb4[vf]) accept configurations with more than one bit set in the feccmd.fec bitmask. (The precise semantics of these combinations vary.) Thus, this patch adds the ability to specify such combinations through a comma-separated list of FEC modes in the 'encoding' argument on the command line. Also adds --set-fec tests to test-cmdline.c, and corrects the man page (the encoding argument is not optional) while updating it. Signed-off-by: Edward Cree --- I've CCed the maintainers of the other drivers (cxgb4, nfp) that support --set-fec, in case they have opinions on this. I'm not totally happy with the man page changebar; it might be clearer just to leave the comma-less version in the syntax synopsis and only mention the commas in the running-text. ethtool.8.in | 11 ++++++++--- ethtool.c | 50 +++++++++++++++++++++++++++++++++++++++----------- test-cmdline.c | 9 +++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/ethtool.8.in b/ethtool.8.in index c8a902a..414eaa1 100644 --- a/ethtool.8.in +++ b/ethtool.8.in @@ -389,7 +389,8 @@ ethtool \- query or control network driver and hardware settings .HP .B ethtool \-\-set\-fec .I devname -.B4 encoding auto off rs baser +.B encoding +.BR auto | off | rs | baser [ , ...] . .\" Adjust lines (i.e. full justification) and hyphenate. .ad @@ -1119,8 +1120,12 @@ current FEC mode, the driver or firmware must take the link down administratively and report the problem in the system logs for users to correct. .RS 4 .TP -.A4 encoding auto off rs baser -Sets the FEC encoding for the device. +.BR encoding\ auto | off | rs | baser [ , ...] + +Sets the FEC encoding for the device. Combinations of options are specified as +e.g. +.B auto,rs +; the semantics of such combinations vary between drivers. .TS nokeep; lB l. diff --git a/ethtool.c b/ethtool.c index e8b7703..9997930 100644 --- a/ethtool.c +++ b/ethtool.c @@ -4967,20 +4967,48 @@ static int do_set_phy_tunable(struct cmd_context *ctx) static int fecmode_str_to_type(const char *str) { + if (!strcasecmp(str, "auto")) + return ETHTOOL_FEC_AUTO; + if (!strcasecmp(str, "off")) + return ETHTOOL_FEC_OFF; + if (!strcasecmp(str, "rs")) + return ETHTOOL_FEC_RS; + if (!strcasecmp(str, "baser")) + return ETHTOOL_FEC_BASER; + + return 0; +} + +/* Takes a comma-separated list of FEC modes, returns the bitwise OR of their + * corresponding ETHTOOL_FEC_* constants. + * Accepts repetitions (e.g. 'auto,auto') and trailing comma (e.g. 'off,'). + */ +static int parse_fecmode(const char *str) +{ int fecmode = 0; + char buf[6]; if (!str) - return fecmode; - - if (!strcasecmp(str, "auto")) - fecmode |= ETHTOOL_FEC_AUTO; - else if (!strcasecmp(str, "off")) - fecmode |= ETHTOOL_FEC_OFF; - else if (!strcasecmp(str, "rs")) - fecmode |= ETHTOOL_FEC_RS; - else if (!strcasecmp(str, "baser")) - fecmode |= ETHTOOL_FEC_BASER; + return 0; + while (*str) { + size_t next; + int mode; + next = strcspn(str, ","); + if (next >= 6) /* Bad mode, longest name is 5 chars */ + return 0; + /* Copy into temp buffer and nul-terminate */ + memcpy(buf, str, next); + buf[next] = 0; + mode = fecmode_str_to_type(buf); + if (!mode) /* Bad mode encountered */ + return 0; + fecmode |= mode; + str += next; + /* Skip over ',' (but not nul) */ + if (*str) + str++; + } return fecmode; } @@ -5028,7 +5056,7 @@ static int do_sfec(struct cmd_context *ctx) if (!fecmode_str) exit_bad_args(); - fecmode = fecmode_str_to_type(fecmode_str); + fecmode = parse_fecmode(fecmode_str); if (!fecmode) exit_bad_args(); diff --git a/test-cmdline.c b/test-cmdline.c index a94edea..9c51cca 100644 --- a/test-cmdline.c +++ b/test-cmdline.c @@ -266,6 +266,15 @@ static struct test_case { { 0, "--set-eee devname tx-timer 42 advertise 0x4321" }, { 1, "--set-eee devname tx-timer foo" }, { 1, "--set-eee devname advertise foo" }, + { 1, "--set-fec devname" }, + { 0, "--set-fec devname encoding auto" }, + { 0, "--set-fec devname encoding off," }, + { 0, "--set-fec devname encoding baser,rs" }, + { 0, "--set-fec devname encoding auto,auto," }, + { 1, "--set-fec devname encoding foo" }, + { 1, "--set-fec devname encoding auto,foo" }, + { 1, "--set-fec devname encoding auto,," }, + { 1, "--set-fec devname auto" }, /* can't test --set-priv-flags yet */ { 0, "-h" }, { 0, "--help" },