From patchwork Thu Jun 2 16:04:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 1996 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id AFA5A3F06D for ; Thu, 2 Jun 2022 18:04:51 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id n2-20020a170906724200b006fed87ccbb8sf2709561ejk.7 for ; Thu, 02 Jun 2022 09:04:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1654185891; cv=pass; d=google.com; s=arc-20160816; b=z2y39dK7hASd8b1/86AXslAGJ2OJPbW19jioyZx7XKyU2AUPBNueanQDWjPTl3WdoE B/SOExy89HnYg0l4ynL07uYaQ7FCWhK0q1qYkL5a2SMOw2LTzmqC5upCoxJTcrxdtVUS r0G2RTyueSrSM5RCO7JsC4U37dVMSQkqXv/1DHkHNizq/QlEjcf1IzcaL+TH+Kl6YOdB EKSVs+lnxSl2p/+9NKr2SdPDXtTgGS5OFQ/ebfJmHcfFta9PfTLhLQVpTHmuPwVwEf7H 3ucWbwj32f551WnaBfHqaEG9omr3++15JA7JgPkR0S5ysHNsmp+NJeTss+SZhTRXB0Su DVFg== 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=OhBEf5j3aS1DhLbNB2XUHSZu/PVvt/Cek1XJWgSSpzo=; b=ZN2NLlHh2+BdaFSd+5ZifN6lGqHLyFrD/Pr+Y++TqH3iBdYePGqPAlhNXg5PL6QoBB hibCI3KFcO8IfCFNz9B6HIqZh6sZ1l/3igLtqkHO260zCwwV8H+qW/9WO002MyGSoKi5 2VUhEa6h+7o6csDCunpyoaE+u07DMt2tbDGC3ET7nKPFl6tCNoYPUANc/sCRrJLJoFIE W6CCYEA2Y5vfaJwKQkblgsuc57qlCJ57DzXTDP1rVZQ84QMW3wHH6FK632H9avo5LFWg iBN2clzbLt0UUP47VOqBXagR0aa2zXd2SiW0iSNfQjjVts6G15auXfCOOdQ6/9g5TnH4 g9kQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=A4z4RYnS; 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=OhBEf5j3aS1DhLbNB2XUHSZu/PVvt/Cek1XJWgSSpzo=; b=pRjiU3oq33DVC14IDfAIkITX/zKHw0Fdg6Xla6kgAi2FGYjoTub5Pj0CZcoN2LzQcc 9EC1Nca6idG34xSOmiUDh+dkiaTNsotsBm3n0Zc6JtFTt11Y0nydEWvVhXvoz9TpqngP OOtUqKJ0lJQa5POf8bZVBJEeUb022hXdnyEDs= 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=OhBEf5j3aS1DhLbNB2XUHSZu/PVvt/Cek1XJWgSSpzo=; b=GRbxu8nv8gXbWMxKY5ezat2HgyIYPu3zAYS5uPeFF8mRyzJgHyGCwr72zHHGFvQ3RE 1LVuTErxKSTvtOMd2DBj2ZvwHzCQdyg7l3+bflgFGFDXqqWbBvGsMQd+mrjV1ungBLt2 a3KMrgCytTrlCOVXK0jPybyJt/D38gwNLHyq2fuWhZnTGadrkKMxV9W6OkT3KYL+0Joz nvbrirHatGfYAZjWIrBS8vLW5zxU+ZLd1uYBaE/jnTlAkJ3Yz1+SkXyDKklLJJSbgkg9 3URS9fVQk8wiaHyAqiex4m7phjNSpa6rkaL/b45U1kWBXTTEOOHgVSj+vt7bxaFyEG7V 89rQ== X-Gm-Message-State: AOAM5331tQDQy2iEMVOjGbPuL5IxNmAS0xCfevIDlVCGCZq7CUS7Hfuz 1JuAhIlYRglP8vbmqbbJBl820eHY X-Google-Smtp-Source: ABdhPJxeJOLg0NHCdvIUCdwW/SLtw1M6qmajhTrmdjkVFirUVf/1rs+QN/cCfGvun2eopaXSWTy9Og== X-Received: by 2002:a17:907:9721:b0:70c:65e7:2aa5 with SMTP id jg33-20020a170907972100b0070c65e72aa5mr1691105ejc.132.1654185891594; Thu, 02 Jun 2022 09:04:51 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:6e11:b0:6ff:232a:2406 with SMTP id sd17-20020a1709076e1100b006ff232a2406ls2157572ejc.0.gmail; Thu, 02 Jun 2022 09:04:50 -0700 (PDT) X-Received: by 2002:a17:906:2cc8:b0:6fd:d8d8:b8f3 with SMTP id r8-20020a1709062cc800b006fdd8d8b8f3mr5002010ejr.384.1654185890540; Thu, 02 Jun 2022 09:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654185890; cv=none; d=google.com; s=arc-20160816; b=1F2QJDpgEGeOUJbwH3f+NZd0N2T5tyxkRd9Th7J2ylmvF4G7z5tXFwiJ7iOEfD7o2Q 9kP1h1r+CipTX1Dw9LMiXgvXqqc3Zk0fcT1wIpWtvUPDzg/qMUoDLj2UPSfokF/OzSGt 3bY6Itu1c1cB9yAFysqZBv17GpTQ53VrOAyhZnefBvFITCgO3inACCojpUCwe6bheybU Z0t2hj66t7oRJRBYXY0ONGIIWhn9m+zU4iAEQ4Bdj2ITlx00YsBQyYDF6CWux3rRM13t GyigVvYCCD4V+qcoHPDXG0e1MutCHFuG3iUGdehcE8BBf8R4rLNKwqaFW7ku8OTTrq9f JFJg== 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=feLSmY8BBn9mdJGH0Zp+/FP9G8mj2HRnAEuisSq/n68=; b=uT3cwpudQO7/+IpZrC2nNuUFPevdytVYNMXE4CRGN6iILsJ05Ktz/bntwo0g1lrdg5 3vlwpjBiWjxiOtCOo+A1m63dsITlNwHObUVC5UwSX58h2weDpmhEU1ffmC+Ejd4n/YmB kpEIE+3JJ4qYC3uIT0DjL1NypPdxJA425XjOSCPRESLHmQsoIzTLfjSu2EID1gQIcDDg rNHZCCA45jQFRc3B1XhXmB8O/0lTbLyTVvc0NRWAufOXFmfU5/9bGp4x/fPU+x+snGBt 5BXb9oGfYzrRMIMqV8wz7qw1rF0794MlpUr0WUXQtLbvsNbsbBYvPQ+jdDlaVSWUxr0H VAoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=A4z4RYnS; 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 wn15-20020a170907068f00b006f3ee8da511sor2585284ejb.48.2022.06.02.09.04.50 for (Google Transport Security); Thu, 02 Jun 2022 09:04:50 -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:1b0c:b0:6fe:25bf:b3e5 with SMTP id mp12-20020a1709071b0c00b006fe25bfb3e5mr5001433ejc.689.1654185890053; Thu, 02 Jun 2022 09:04:50 -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 f3-20020a056402150300b0042dd3bf1403sm2637095edw.54.2022.06.02.09.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 09:04:49 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Cc: dario.binacchi@amarulasolutions.com, michael@amarulasolutions.com, tommaso.merciai@amarulasolutions.com Subject: [RFC PATCH v2 11/13] can: slcan: add ethtool support to reset adapter errors Date: Thu, 2 Jun 2022 18:04:32 +0200 Message-Id: <20220602160434.225417-12-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220602160434.225417-1-dario.binacchi@amarulasolutions.com> References: <20220602160434.225417-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=A4z4RYnS; 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 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 */