From patchwork Sun Jun 12 21:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2058 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id CBE0D3F1DD for ; Sun, 12 Jun 2022 23:40:24 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id o2-20020a056402438200b00434ec3efc03sf921293edc.9 for ; Sun, 12 Jun 2022 14:40:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655070024; cv=pass; d=google.com; s=arc-20160816; b=FTtQ/vKPDgAxgY/AgAclcE3xmm8/36jVDm/9nsBB/imklz12Ly14S9mebgwPexRNJn nZqcdK7naaq2Ze6ru3zrfMNms/YpLiBhrxQMrObgrndcnnI/bSdonb+Utdt5kxtsFa30 Zoth+rjcWvl8HLM5P5soGooj7jI33W8l2Z/2Z9kglvCu72IppsikX7RVbKZ6Vlg1A9rj Ezcijz+bFrKtvPmKxc00AorXZ2ETfj3MTXhSGv970mMrfwEIXJQp57LTWQee/EB42WhD ZUe7VWcFcHfuK/icJxFM/tISByN9uUWiK5IRKSfZcfUGF8jzszkb2qu1kDQu3gsriWwX yYWw== 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=vcwfIua+37YBUfFbM57XT8pHEj43rpoiTX6Bh5mnSVhVoO9s8m2xM6oQiHTmYnNQVG tmzjxDVQ0d//vCSc+pi7bZlNbt1YjZUmkteyNNKfGyIhCbqG/JUO7djP6BaDbKNoxfIm lYaPDZ6i7V/vDeLmBD8sS0qqAGbWuDqxf8DfW3n8G/v5NjjDmHsmj4N2/5w2n1wrJ+AW I5wlwf2pOxw/37IKfleIO9DadOuAr1S4BeQyoGFYnH3CZQbIQ5767waEPF9D5CC53jmv kbQ649WTqaHa/tD4HErp43EKoMV8qzYf1BRNMYY7s+B4fzudvO1OLAtj0ulwgsi9cNPh 84nw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZHd42I9X; 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=WFHnKfKU0C4lIP0siBY9H0syY013TI848OcDni039axkVQH6jz/3qgfcf5ZerBo9pV iLWj3uBJseHa5iE+qe89ryeV3Z0ncqTDcGpGh8thv9uVy/m2ex8Aihl0N113PaKuL6ni 42rJhbNqSNz7+6FS4KabACQd4W5OHPdVZ3cJw= 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=8uOt1GeGNeWpFgZjq1jnARH8+Q5D0ILWmIf0yrCExAg=; b=NwNUcmoZS6tJMvKKhUKI3qUHS0umJBP5orBqZgG4zWMwnkBM4GOgBYy7L0PLaBT7/F iOb5s/JOddrEXMGx5FUDhZI5UKCpN6fOpjXhF1LGl/72KcWOkerksebpPT7OvER5YjEX qHjVtAOeciYs1d0DVxugQcxaHvQNdJw/nxB37sv8wfnJG9bAdxLDdRuS31KIpKZ5jrxb Opuht7g2TyBeHU3qssI28zro+Hi9lxatRnrQASHPQozn9tWCKZk9Dni1obEkhMCby7f4 kG6PVRlAnQwIU1//pgrAMmMk1xIbtHTw193nlzHSXDoLX/Ne+XEbDAntgVyBZB/kiXfJ Xx8A== X-Gm-Message-State: AOAM532OKX+16krqff8G50yLRF92OLPq5c38CUk+shpY0cNDgYBYOyct c/2PdmckJgAKFtKFPOUTp443FoZ0 X-Google-Smtp-Source: ABdhPJzIRu1WjZhV52bGfF43IpHG9AMbcz0GKkMCB0vJ7+3nh8DC76aV8vJBGSUqXTbvTrAP+g+dlw== X-Received: by 2002:a05:6402:61a:b0:433:406a:8d25 with SMTP id n26-20020a056402061a00b00433406a8d25mr20056109edv.276.1655070024678; Sun, 12 Jun 2022 14:40:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:97c4:b0:711:d2c2:9fa4 with SMTP id js4-20020a17090797c400b00711d2c29fa4ls1011135ejc.9.gmail; Sun, 12 Jun 2022 14:40:23 -0700 (PDT) X-Received: by 2002:a17:907:2161:b0:70f:5db6:1ff2 with SMTP id rl1-20020a170907216100b0070f5db61ff2mr40894216ejb.249.1655070023714; Sun, 12 Jun 2022 14:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655070023; cv=none; d=google.com; s=arc-20160816; b=jjeC/EzWDN5xVhX+3Tnd04Zy5b+x948j/gf4CrSr0HP807BnPSfHXy3rjkK2lNKxDQ hSnX7hgLCDyg9/tUete4dnDiaCeBTioEsZQH1UmRd68qpooEhm7T2JIn5LxGNVdruFcS Un1b8a4v4bvJYCweSKiGSc3mRRjUB0MdjU6vCA0s6nhzoPVhBPE/h+UqynmyLMIXvIRQ ErmpJaQpYByp9LAdNQeCTPxMAzfq5FlLmtRkkJJRoLjwAx++LzBsXN0N8HFVsy6Rfrm3 Qlly5b8rn8c2M8uTrn++FlKMZqyQFkDnBOAxfIgKv//UUPYv2BCZVbdPGglCpLgDT66H pbZw== 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=z9lGb6dxRaekyRJ4swSwg3PwLJAGarCfZ2Xmy0z62Lo=; b=fM9/ghzX0FU8z5JP2sXIByLn6/GjbwHCTrZaXfrx6RSMeSCts/j42g28SWz7qgtH1+ dhsyg92x32a6cNJUL/ROlSzRCYB72DqMpTT87HkcVpSD66rHNcBd9e4I2hY0lVaguXsK yA+3pkxVGPYSKi1MUTdoPmtRFIMammcnYKWSYQZiyOBCfmMCdu8GWL+0lv/XGoftCBYy JIMibQFa1+5BChCHKyWuKAejPcUKLgnZdcq2iKmcfeXzuZJtaTP2VjQ5aicZtpBX7aH6 h/UqbXCwsU4i+ngLkaokL1Dx8P0A57ydLbgMokpzZR5TptKQemT9DaPqWiyLagZQR1G5 N2uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZHd42I9X; 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 r5-20020a508d85000000b00425e6e44fe7sor1620847edh.2.2022.06.12.14.40.23 for (Google Transport Security); Sun, 12 Jun 2022 14:40:23 -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:51d4:b0:42f:b38d:dbb9 with SMTP id r20-20020a05640251d400b0042fb38ddbb9mr51327514edd.255.1655070023483; Sun, 12 Jun 2022 14:40:23 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-116-90-174.pool80116.interbusiness.it. [80.116.90.174]) by smtp.gmail.com with ESMTPSA id u10-20020a1709061daa00b00711d546f8a8sm2909398ejh.139.2022.06.12.14.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 14:40:23 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Oliver Hartkopp , 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 v3 11/13] can: slcan: add ethtool support to reset adapter errors Date: Sun, 12 Jun 2022 23:39:25 +0200 Message-Id: <20220612213927.3004444-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220612213927.3004444-1-dario.binacchi@amarulasolutions.com> References: <20220612213927.3004444-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=ZHd42I9X; 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 82a42cec52d3..3df35ae8f040 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 * ************************************************************************/ @@ -509,6 +535,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"); @@ -629,6 +664,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 */