From patchwork Tue Jun 14 12:28:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2075 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 432013F03E for ; Tue, 14 Jun 2022 14:28:41 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id co13-20020a0564020c0d00b0042dc9ef4f01sf6048882edb.16 for ; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655209721; cv=pass; d=google.com; s=arc-20160816; b=eYYR8L5oclPiTRr8JlhT6xAOPNxauWGGEtElABC9GkG3smM5wrnq5oQiqsTVHQ5J+8 Yf01tkDI4Y8g+u2i+Sob3JAHaDWS9tuXcqNTBFGMdj52jatKIKVGdhhmxJPPFBaLLYwD adafEomJ/MaROH8VSnxhQ9FGTDMcAYgTJhosldJfXrcIdWmWVIj2wFcMwCU86z60RUC6 KHNRZj8hQhMfIvbhqzgbLfhsbEspsKUfZIqrChHumsv8LOjagWzgUWc/fvriE3mP43tq xwEnE8M9dBaDOSe466FJhxh+LYtbqB9NZMG1iN+xuSXen+FJ801Ro9pKRB752ChgJvSP 4p3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=Z5jDqXt4VWGCpTcZm4ktD/JsDaI1vmFeISLB4JzQ5iXHIXqLB4OxJyDmrmltXE8Y8P EyXv3wVT0hroLigZc514eHA6drvphYJWUU7nPbczContupqiydxYgrr7nxRPr4G9P7RX GmXr6PQ8kSgf2Lb8SY53Oqqnz4fPRSHQIEyd/9Bld/4dDC8ikEhEwo5XhNGxQGxTlukJ kvz9taArmK3CIcMoCBE31XOsd+8DHm7ty9w0kIDekmT0Jvbb08C0KcWXDDxgyAXn+YVy 6/zJwD2yB1Oy4OagEyjQi0ghoucRFSMTRCyQ1eEcu7eQASmM7BcrfgCrgf2ONWO34DhF VBKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JNHe/Rd3"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=m6BPGAXGxTfpYWTmN3CNZE3/+U3DaYpt2mQPTYWisqqysWQyudF8gJaf9JB90Kz8aL 2SdWKB2BbTDPoIxo+MNuYMc8R7HOi0vQIaJXEBN4eu4HC1+8eieOZ5qlxYBCCzEhZerf WMFxlBD4AjBz+nMjKz8Zw/ucSpAyTzDfSD/2w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=WPNEkxN/F2yauhVGaLTV5FrYDPxneebui4vcuPuYET4=; b=beRt13kUVPhiaBLPuqxKGlUJFYVTYYrkwhCT3wFpgfaQZMKCAebpor4vILH+O92hFt /ZT6LbBg+FQHMSAd/gHfl92NG3GAEOXreYFUKSwlnDOtOLDw+YPdCJlnHK1ROn8EDKwd eJv3Oa/O1a2nRdiyhtwP2BGajRIHA76wjs8RnGwueZhzbaS4urKlY5Wu2Nvq7Pq1EyA5 ydjd97ME9LTfQ49XNS9RofB5w9hiblVbEBIy1y0V2C7wqs1g7jLkFU6UdBGb26E8TaOy Nd6kv3p5xAbeL+wiwrikDMuYtClxjMc416Bcyg4+1kN9IpnTE0MQdOcexjD3ALT+cOTt xD2A== X-Gm-Message-State: AJIora/de4j/8rnSW1FgC1FskS1WQAU6vADe1Qc+Lg2Xbp3WlfAGF1tJ /S00/k92WY6XfUtArAjaun8mw8jF X-Google-Smtp-Source: ABdhPJyZAFWD5QdGTgMsf/Ub04krXQUCIGEJ38gDWTtzyLHxTncmaqoC8fWdJT+KzqMc5ciiTrZNwA== X-Received: by 2002:a05:6402:1e8b:b0:41c:59f6:2c26 with SMTP id f11-20020a0564021e8b00b0041c59f62c26mr5865657edf.156.1655209721071; Tue, 14 Jun 2022 05:28:41 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:709:b0:431:3a5e:75b3 with SMTP id w9-20020a056402070900b004313a5e75b3ls2366696edx.1.gmail; Tue, 14 Jun 2022 05:28:40 -0700 (PDT) X-Received: by 2002:aa7:c55a:0:b0:42a:adfa:9150 with SMTP id s26-20020aa7c55a000000b0042aadfa9150mr5825976edr.57.1655209720094; Tue, 14 Jun 2022 05:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655209720; cv=none; d=google.com; s=arc-20160816; b=khD7GRolXlDsf1oDQ4IPaYbQh6moLGqT+tbHSic7H+X0m/GZBeTBu49XTCrtuY1QVy MGOitp9f6r3IBawuok0WpjIs7JqJ5eImrE9pIAydzin/k/WDmPnkLCjN34aT8KPwmvfO ucFjOwwgFa2hh5oa7bqDqqy1wi2f47LTf8KDKcQBCSw2QwkjINvaWa8mxBcHKFMMmGM/ HaQEZlVZiSausKORfJjsfI/lKDv96TfOnF76lb7zGKRUpdK4/F7SJRU6jcEs+Z41igcM tTSgMpsVBrXUU42rk7mP79WsHg38cvO0CoEq8hr3EQ/brK4313Wvey2u4B1xmFE+IPK3 1F8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=XeYjdn9a4I+7ASW7s8Y7GsWrvaBO3fcqP0UZzQUkPdo=; b=CGK+VFmQGlzHRKDsH8SVsEsugRQgIjeNONs7lx11FRMPf34jMYRy1SRsckIww/eTIK bKWhdxHU8Mf1hTSDAmDF/9S7vF57SLbLjOWQi6SorEDTlxLagMOaIaAEpXtQ/tcqfX/L VqcZJyul+h+wdFFv+0ZMDNFyKEjic27Rbt5AgS0gYzN0c9GI3lmsCTzd4encvd9CvhYv g7rDQVBM1eRQ7C4nFhwYIsBXSDMNQT9P+fZX/FLp4gr1J9Zq+eo9JpEDRnYcMSL+BUDW hZ76Gnb1+TEA4i3PDFYX2+jPHcyGDkVdb1zPa0y5WtWxwzZAZI8RIXk6KoconcLlrtRg Vang== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JNHe/Rd3"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id i14-20020a056402054e00b0042a628e69a2sor4216050edx.61.2022.06.14.05.28.40 for (Google Transport Security); Tue, 14 Jun 2022 05:28:40 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:6402:2381:b0:42d:c8fe:d7fe with SMTP id j1-20020a056402238100b0042dc8fed7femr5766685eda.248.1655209719900; Tue, 14 Jun 2022 05:28:39 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id z22-20020a17090655d600b006f3ef214e2csm5087043ejp.146.2022.06.14.05.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 05:28:39 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , Oliver Hartkopp , michael@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Eric Dumazet , Greg Kroah-Hartman , Jakub Kicinski , Jiri Slaby , Marc Kleine-Budde , Paolo Abeni , Sebastian Andrzej Siewior , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 10/12] can: slcan: add ethtool support to reset adapter errors Date: Tue, 14 Jun 2022 14:28:19 +0200 Message-Id: <20220614122821.3646071-11-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> References: <20220614122821.3646071-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="JNHe/Rd3"; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds a private flag to the slcan driver to switch the "err-rst-on-open" setting on and off. "err-rst-on-open" on - Reset error states on opening command "err-rst-on-open" off - Don't reset error states on opening command (default) The setting can only be changed if the interface is down: ip link set dev can0 down ethtool --set-priv-flags can0 err-rst-on-open {off|on} ip link set dev can0 up Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/slcan/Makefile | 1 + drivers/net/can/slcan/slcan-core.c | 36 +++++++++++++++ drivers/net/can/slcan/slcan-ethtool.c | 65 +++++++++++++++++++++++++++ drivers/net/can/slcan/slcan.h | 18 ++++++++ 4 files changed, 120 insertions(+) create mode 100644 drivers/net/can/slcan/slcan-ethtool.c create mode 100644 drivers/net/can/slcan/slcan.h diff --git a/drivers/net/can/slcan/Makefile b/drivers/net/can/slcan/Makefile index 2e84f7bf7617..8a88e484ee21 100644 --- a/drivers/net/can/slcan/Makefile +++ b/drivers/net/can/slcan/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_CAN_SLCAN) += slcan.o slcan-objs := slcan-objs += slcan-core.o +slcan-objs += slcan-ethtool.o diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c index b08e63f59b8e..b4f29ab2ab72 100644 --- a/drivers/net/can/slcan/slcan-core.c +++ b/drivers/net/can/slcan/slcan-core.c @@ -57,6 +57,8 @@ #include #include +#include "slcan.h" + MODULE_ALIAS_LDISC(N_SLCAN); MODULE_DESCRIPTION("serial line CAN interface"); MODULE_LICENSE("GPL"); @@ -98,6 +100,8 @@ struct slcan { #define SLF_INUSE 0 /* Channel in use */ #define SLF_ERROR 1 /* Parity, etc. error */ #define SLF_XCMD 2 /* Command transmission */ + unsigned long cmd_flags; /* Command flags */ +#define CF_ERR_RST 0 /* Reset errors on open */ wait_queue_head_t xcmd_wait; /* Wait queue for commands */ /* transmission */ }; @@ -110,6 +114,28 @@ static const u32 slcan_bitrate_const[] = { 250000, 500000, 800000, 1000000 }; +bool slcan_err_rst_on_open(struct net_device *ndev) +{ + struct slcan *sl = netdev_priv(ndev); + + return !!test_bit(CF_ERR_RST, &sl->cmd_flags); +} + +int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on) +{ + struct slcan *sl = netdev_priv(ndev); + + if (netif_running(ndev)) + return -EBUSY; + + if (on) + set_bit(CF_ERR_RST, &sl->cmd_flags); + else + clear_bit(CF_ERR_RST, &sl->cmd_flags); + + return 0; +} + /************************************************************************ * SLCAN ENCAPSULATION FORMAT * ************************************************************************/ @@ -511,6 +537,15 @@ static int slc_open(struct net_device *dev) goto cmd_transmit_failed; } + if (test_bit(CF_ERR_RST, &sl->cmd_flags)) { + err = slcan_transmit_cmd(sl, "F\r"); + if (err) { + netdev_err(dev, + "failed to send error command 'F\\r'\n"); + goto cmd_transmit_failed; + } + } + err = slcan_transmit_cmd(sl, "O\r"); if (err) { netdev_err(dev, "failed to send open command 'O\\r'\n"); @@ -630,6 +665,7 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; dev->base_addr = i; + slcan_set_ethtool_ops(dev); sl = netdev_priv(dev); /* Initialize channel control data */ diff --git a/drivers/net/can/slcan/slcan-ethtool.c b/drivers/net/can/slcan/slcan-ethtool.c new file mode 100644 index 000000000000..bf0afdc4e49d --- /dev/null +++ b/drivers/net/can/slcan/slcan-ethtool.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2022 Amarula Solutions, Dario Binacchi + * + */ + +#include +#include +#include +#include +#include + +#include "slcan.h" + +static const char slcan_priv_flags_strings[][ETH_GSTRING_LEN] = { +#define SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN BIT(0) + "err-rst-on-open", +}; + +static void slcan_get_strings(struct net_device *ndev, u32 stringset, u8 *data) +{ + switch (stringset) { + case ETH_SS_PRIV_FLAGS: + memcpy(data, slcan_priv_flags_strings, + sizeof(slcan_priv_flags_strings)); + } +} + +static u32 slcan_get_priv_flags(struct net_device *ndev) +{ + u32 flags = 0; + + if (slcan_err_rst_on_open(ndev)) + flags |= SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN; + + return flags; +} + +static int slcan_set_priv_flags(struct net_device *ndev, u32 flags) +{ + bool err_rst_op_open = !!(flags & SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN); + + return slcan_enable_err_rst_on_open(ndev, err_rst_op_open); +} + +static int slcan_get_sset_count(struct net_device *netdev, int sset) +{ + switch (sset) { + case ETH_SS_PRIV_FLAGS: + return ARRAY_SIZE(slcan_priv_flags_strings); + default: + return -EOPNOTSUPP; + } +} + +static const struct ethtool_ops slcan_ethtool_ops = { + .get_strings = slcan_get_strings, + .get_priv_flags = slcan_get_priv_flags, + .set_priv_flags = slcan_set_priv_flags, + .get_sset_count = slcan_get_sset_count, +}; + +void slcan_set_ethtool_ops(struct net_device *netdev) +{ + netdev->ethtool_ops = &slcan_ethtool_ops; +} diff --git a/drivers/net/can/slcan/slcan.h b/drivers/net/can/slcan/slcan.h new file mode 100644 index 000000000000..d463c8d99e22 --- /dev/null +++ b/drivers/net/can/slcan/slcan.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 + * slcan.h - serial line CAN interface driver + * + * Copyright (C) Laurence Culhane + * Copyright (C) Fred N. van Kempen + * Copyright (C) Oliver Hartkopp + * Copyright (C) 2022 Amarula Solutions, Dario Binacchi + * + */ + +#ifndef _SLCAN_H +#define _SLCAN_H + +bool slcan_err_rst_on_open(struct net_device *ndev); +int slcan_enable_err_rst_on_open(struct net_device *ndev, bool on); +void slcan_set_ethtool_ops(struct net_device *ndev); + +#endif /* _SLCAN_H */