From patchwork Wed Jun 8 16:51:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2038 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 1403A3F1F7 for ; Wed, 8 Jun 2022 18:51:41 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id x15-20020a05640226cf00b004318eab9feasf3995564edd.12 for ; Wed, 08 Jun 2022 09:51:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654707101; cv=pass; d=google.com; s=arc-20160816; b=r0SFP3L0fULC0oqOgL8VbqFyfkjNwKYWamHiUDTVaif3jP5kw94oatjvO/9/hz4uTS hNbf9MGKLS2me3SftgJf5MFW4N7Ymn5wPaMH4tGRSzhBFQOz8kq6UPaK2JYQ2u/mFr64 2iMctmFj98gRfftQbkD0wob67GSqSGpW8x0/CCIC7ZjmGK7eA/prNj8A1GWuSchU+goe DLii02GxZZXT99ZmGShf3fHxTwYjHf2dcEqnI3Be40q0l4Z1spy/S2pfTRBLZ0B5iM14 L6L0FPAj/DtfR46s2bhXEZOjLdYfiDcXVUw0E9jk7oC0g2IU7MKi7U1rLzYNKZSaAx/d h5iA== 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=mv3vyWmla8wF3ruVTiHZGQNWSIQ97B4444wE7bxyXB0LyLzEGaIzMI6xjfZGNTF6Eh XexHYV4DIsFNq6p+xTArMSO1mdsZctBoZfzhunzoo1mmMOEjuZJ470zWtJ2Pr5xRw7vP v99BoiPm411CyURlkmn/BfQRurdtro5XpfgFjcb2QQ0uyuWfvcQXNupRulLASzrM+ewS L+FspVy+sYd2VlWKePsJgGKru3ymYQAVdVYbQvrFYOimPhW3tJD62VitptUywsK3AjPV 2U4+fyUaZsx8q2RvZrb76dJBN+M8eBBo85b2XAeg9vaIpA+uHclBzZuHFXgsx2PmLlk9 Hx+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=G6FtfoTZ; 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=Qtfnzz/lIyL+HHTWCc2cM8aw940gQMJGybXFZSvKEYrbSBiZDUZxNSMS/baANM8B3M JCwFue03XlRu7BDgtgeQpkWOK59Eh+rjAzAgqlWLZKlzSVoywXscE+1gQsvVHx55u4pj 3NLTw9LC3+y1wFrhaPpuMqHjnV1pmXfQAub7Y= 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=Ot/rAEftvwCpvOTALQIAtnw9leN+HTOd2dvkSZstnOk=; b=jyMoeKIqGNwMDiIY5claHoJTZBswbDpNd04GkYqlrb/dUCj3GfOZHiTIHLlSGpyaIf SccllpFbE/K/K7/LIQEmJ4R5fZUjTjW4iJ0Sij2Ss4n9mj7C6anQQLSrMeJqkBP5SrTD H0v7hTY/YuwZ6AHVwhK/dMeYt3PD5wOeuIDo68EZnfSqEfNkFtisdm17xrw8ZPJZ18lh /+d15KqbV+FvbjTpBC3cSgHiJ/kTKhtnubV/9ccvTs/RijeV0vyfAwcjjHW63Z49NWC6 Ta+YoTpfJXxEkSsm0v0ZaaZLU/o9acfO9UqWIXFKd9i2zWHcFDMLa1Rg5QxixWQo9aMy QCbQ== X-Gm-Message-State: AOAM532JaRXoHz8LAqlbAbSaucG5mNeoFZnJ/NiOay5zi8KTe9MYrZco C276PPBmiobHfQsSlK6ExKD9nssO X-Google-Smtp-Source: ABdhPJymN/0ppay7nVgZu3i1PSK8GJlaNNwFi7540vemwnnaBF02C1IxhmLzvCow4oqyVUBSeJAnIQ== X-Received: by 2002:a05:6402:2804:b0:431:7dde:6fb5 with SMTP id h4-20020a056402280400b004317dde6fb5mr13082731ede.379.1654707100896; Wed, 08 Jun 2022 09:51:40 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:294a:b0:42b:31b9:2087 with SMTP id ed10-20020a056402294a00b0042b31b92087ls189616edb.2.gmail; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) X-Received: by 2002:a05:6402:31ec:b0:432:dd71:c7 with SMTP id dy12-20020a05640231ec00b00432dd7100c7mr4020842edb.118.1654707099724; Wed, 08 Jun 2022 09:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707099; cv=none; d=google.com; s=arc-20160816; b=g/He4+0Me5L0X6H7+EOz92xXivSMtlh6Oss+riYPGF2dt1dRvowb+rfBMx0kSKr8hT UTfmegTA1bLoZ36knipr7uvat8vZW6ZI1sP32wIG0zxGPVSbdotb8OE42R9BFvkzJ8uM LhuF+qLGcDQ7EGEy2IpnQxt4W/8rBcQGvgDaBWwVs8QMJ8LT9eWy5HqUWKwWbKkuPcgu 6PBlREaVnyS4GR6oC6mat/aEE8TwOGlzANro/MAOCjIYKNAYOF6iopFVFD71WtRafD1m E10DwLNAWqj2TlncOXLnHEElL2p+i2sgkfXb+U/iWp2za9LTqIwSTeEV1AkhVdZ3J5ad YNjg== 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=D347QqdRdrFNo4P9Em/ayvZ1ba87O9qPIqi6sUOPlwQ=; b=T+0i4+QMihNgKOY48FRXiFXecp3zRsLlU7xnBNvhN/kkkE/81ZKuorrRpritQy7dEz irFcmPZO9L7dh/BFbF9+tADJsaNa2+9s1BeSEs1U+mv+ngJRmR0K/sDjnHhtkzbFK7Zp Scwv6TRaQZpnP1PYlhlC2MgQqsELnpxa2a1HC4OwEv9syGLMl0hQjfv+h5sJx66iBXOD 88ad97bbEgwAfWiLLsdGok+c/vOH3iRda3yqHCdmQ8PogD/6sjuLn+EjKArKCmy/9ZW0 0WPDMw2jGMKg4wAkxSbU3LL2m/sNpr7E++i5Kb5+QZhuBuD+2kBUSkUJaThj3JkTMuKB cJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=G6FtfoTZ; 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 a17-20020a170906245100b00707ab1f34ccsor9717977ejb.111.2022.06.08.09.51.39 for (Google Transport Security); Wed, 08 Jun 2022 09:51:39 -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:a17:907:2cc7:b0:709:f1e1:7b17 with SMTP id hg7-20020a1709072cc700b00709f1e17b17mr31394072ejc.498.1654707099497; Wed, 08 Jun 2022 09:51:39 -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 c22-20020a17090654d600b0070587f81bcfsm9569071ejp.19.2022.06.08.09.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:51:39 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Amarula patchwork , 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 v2 11/13] can: slcan: add ethtool support to reset adapter errors Date: Wed, 8 Jun 2022 18:51:14 +0200 Message-Id: <20220608165116.1575390-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220608165116.1575390-1-dario.binacchi@amarulasolutions.com> References: <20220608165116.1575390-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=G6FtfoTZ; 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 0722e7820564..038ce7c25d42 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 */ }; @@ -105,6 +109,28 @@ struct slcan { static struct net_device **slcan_devs; static DEFINE_SPINLOCK(slcan_lock); +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 * ************************************************************************/ @@ -475,6 +501,15 @@ static int slc_open(struct net_device *dev) if (sl->can.bittiming.bitrate == 0) { sl->can.bittiming.bitrate = -1UL; } else { + if (test_bit(CF_ERR_RST, &sl->cmd_flags)) { + err = slcan_transmit_cmd(sl, "F\r"); + if (err) { + netdev_err(sl->dev, + "failed to send error command 'F\\r'\n"); + return err; + } + } + err = slcan_transmit_cmd(sl, "O\r"); if (err) { netdev_err(dev, "failed to send open command 'O\\r'\n"); @@ -634,6 +669,7 @@ static struct slcan *slc_alloc(void) snprintf(dev->name, sizeof(dev->name), "slcan%d", i); dev->netdev_ops = &slc_netdev_ops; + 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 */