From patchwork Tue Jun 7 09:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2024 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7FB853F08A for ; Tue, 7 Jun 2022 11:48:33 +0200 (CEST) Received: by mail-wr1-f71.google.com with SMTP id d9-20020adfe849000000b00213375a746asf3206053wrn.18 for ; Tue, 07 Jun 2022 02:48:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654595313; cv=pass; d=google.com; s=arc-20160816; b=NqFmqo7LAz17P2FvI47cEYBNWeZJ8/LgK7Q9OpqeQvJL6KvUOd/2NtxdlPVynmLax6 Ex2m9t0BSZ2WfbgtsjKsw/gj8AUOxmHxWrLpchCRQE2gOTKJPEjQlt5MdMw/t7obtvDq Sv0zViusqdpAdbTFfZxIODNqCV+fjQi7BApnVofiXwiWy7Pms4oDZjBTrp66nDXm1FaI Sr63KYZXotM8zqVCfPMKMl3rMxCiVAuxOmjZMPcX6Y4YPsrNswg/r4rokIbaGsJNT7l7 b0WPPTtawAIbK1cukhfloYb97diZbJZzoyoo+PqZyooKLoYCuXCFzHoAUbjNTcQwBOqQ pXzg== 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=U30IsEAfRAn2xuIBl/FW9hsurzj27LDbkTRGDlH0v/s=; b=SmzRNyY1ddbm/TKTjzNyNjFOr4kBYmaaZqM+t7Yxxnn3/qRvt5yh3j1q6ljUVz6Pgc 4dSHTA9m0NKbnKefoZe4DBjTKxX3Rg7koHqG4u7LNOn5mIL55p2y2DbuX1swCsINGtvd JAnZUQ3lJh59R1hsFXfKP2G7sTX7u4dqAIUaELuiKvgrkQyY0IItco/Xg0nrzaZG1dB9 qPvwHfyr+RwBQZvHIGZSadSY3fhx9baxWSlxzElSDPFi95EZnT9pUsE80PNjAHitgij2 TNQTAmlMmTX0ALHu8Zw/ddBrJKnsYBfp3nD/UddZwJjbvh2T14Ya8O7N86I/qf7tG7fp YJwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Lk0XjM6q; 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=U30IsEAfRAn2xuIBl/FW9hsurzj27LDbkTRGDlH0v/s=; b=n19xbzlxm22+CPeUAhA5hPmqMonetN2SPSkHZI8XfxqekqKHlS7vnou4Si5sRfBSgi OO0N/GEGTFmgml/jQXa9zc7EKv94vUionwTSVXWXBIOLZGPQRv5oh6xeJ1EJOjfCSJ6q gLH1XFBH79sHogD1xoh2tRaqYkakmlTgq7FSs= 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=U30IsEAfRAn2xuIBl/FW9hsurzj27LDbkTRGDlH0v/s=; b=H4qfewTvJqsJdVw7KNZj3cPcWgh/nXiRmdj7nnyGPXDTNb0VdFUSj+G1rjTh9+SBhS s2m/DHe3LYGMkASTeKhIVqbKeSCYQgI6GUh3bMEXWjgt3uKp3FoojI72bX1y5M4AgHbJ eisH+uXwyjLJ8RxY127U4mfIrUOHCt3R2wBwMMPcXTPBrhfDOqbBEx2pxCCNTzf9rfV9 S5mZPoWMZDjtZPcz8B1OaD6RxDz81LTW02hIPzn1xcGOeGCqhGVVQ6iHJhfJonxa1e2Y q2rZi3lT0hoTtMyTvl97u7RJqEspwW6aSZjMdPxFIvVJyDSvqRS3xf76tYzLBEBeExNW aVuA== X-Gm-Message-State: AOAM531a8l1qtCrCTfdI3+fVRY8NBmTl9K4/cjsOEUO6tdKGpzWzK285 j5TPVKDXci3j8BSDvLhHd9WetXrX X-Google-Smtp-Source: ABdhPJxgceFQaL6EMlr1NT9qP66YjpofsX5G4tmJYRhJ3dJs1zoa182iOlJ2OyQvAME8KSC+aG15BQ== X-Received: by 2002:a5d:47cc:0:b0:20f:e246:d7d with SMTP id o12-20020a5d47cc000000b0020fe2460d7dmr27839323wrc.2.1654595313299; Tue, 07 Jun 2022 02:48:33 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:144a:b0:20f:f1e7:c71c with SMTP id v10-20020a056000144a00b0020ff1e7c71cls4153345wrx.0.gmail; Tue, 07 Jun 2022 02:48:32 -0700 (PDT) X-Received: by 2002:a5d:58c2:0:b0:210:2baa:52b8 with SMTP id o2-20020a5d58c2000000b002102baa52b8mr26745222wrf.20.1654595312280; Tue, 07 Jun 2022 02:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654595312; cv=none; d=google.com; s=arc-20160816; b=U6jCfl3S4w6slbz8Jb+Zqa+ehf9WreBkjaWzXDePCstThFt5mW2h+2fMcD0m8zi24X jQQFklKpbnth1aZOvjJ06L52JIIQA+Ko974rPV+wMRje4fgCeD85y2Y2cFYOA+qfx0hB 7cHY/WFX6ONa3itgH+huZW4zaOFCUvadn7wY2tj7ELLHwOHimFDlv0rJlgv4pwm7ellL 9h4bEEktbS8YVFCZAbzyGfnxRElHQ7lvg+mnU9imFpMrREu/lIARY8uygHBRt09dtFog y+RongkwfzzucuIPNjlkAhnDIGGq+XqOviexXIiSOqc/15FqxrpasVV49f3lnUQhrAoT UPTw== 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=sRVCV675gnSBUjquD4ODK0/V3BjHMt/6L2aovdLYzzw=; b=elMFDAjq9BuPG7BrHvUMoDUOjisgm+EuLXYCpwsRe+DJfhbdZDctswLaci/WRj1Et6 O6H0NhuCPVnOJBJFeyTlq6GY4YJ4JQVWnEQQW/b1I0LArxIh01JEi7egxRlZMgzQY25G JC/+rHeGfY0OMx3862kLA0jjE1XHKvyyLnR8sAufKs70hK/Nmlp89VgOTPA3EWaSFGca uoa9kiPD+AK18EH+I7go2dDxaZCOiI5BN4IW43wNNkdpl6xG9cDSHmBiiri18+vW3oWm rO+kDk5KQyuuDMdl7Z8AWtLml0C5bJH4jd6wXoclLcWXAOflC4tUR3Hi2iXbWEaKj0+O Hiuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Lk0XjM6q; 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 a1-20020a05600c348100b003970658cad3sor6746014wmq.6.2022.06.07.02.48.32 for (Google Transport Security); Tue, 07 Jun 2022 02:48:32 -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:600c:4f85:b0:398:54fc:ea9b with SMTP id n5-20020a05600c4f8500b0039854fcea9bmr27579229wmq.17.1654595312019; Tue, 07 Jun 2022 02:48:32 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-137-51.net.vodafone.it. [5.90.137.51]) by smtp.gmail.com with ESMTPSA id o4-20020a05600c510400b0039748be12dbsm23200547wms.47.2022.06.07.02.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:48:31 -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: [RFC PATCH 11/13] can: slcan: add ethtool support to reset adapter errors Date: Tue, 7 Jun 2022 11:47:50 +0200 Message-Id: <20220607094752.1029295-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607094752.1029295-1-dario.binacchi@amarulasolutions.com> References: <20220607094752.1029295-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=Lk0XjM6q; 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 --- 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 d63d270d21da..b813a59534a3 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 */ }; @@ -117,6 +121,28 @@ static const struct can_bittiming_const slcan_bittiming_const = { .brp_inc = 1, }; +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 * ************************************************************************/ @@ -483,6 +509,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"); @@ -645,6 +680,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 */