Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2127221iof; Tue, 7 Jun 2022 20:38:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAZo1v/GlgktCgd2doUJ9ILa92XptTN0ulrYkCEPBdBiYjSvD3CPL/XRjKwDMrypuBEFdD X-Received: by 2002:a17:902:da8b:b0:165:112b:b4e7 with SMTP id j11-20020a170902da8b00b00165112bb4e7mr32253710plx.85.1654659523359; Tue, 07 Jun 2022 20:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654659523; cv=none; d=google.com; s=arc-20160816; b=u4pRwjzYHXV6ES3cbzEyb0uEGY/dP0iRUL816wfLdz2xE/OpKCuiH8Ng0rR4NKqbo2 2giBSpjtwQKZZbSRbIx+fkVBLpCHGsHneJG2xRSPw7Ree1HaqDcW8X3Ah6SiswU0eKKk BwIy7g3pXH0CLEJtJn2c/35zS7nBI9zgeicDnNttXiThsOk5wcw+7E8zxPGnKxd39OFt byv3+iuDHFeJ03guD6l+VMopqVIHAyOJOqafo/R3yfGGARlH9uc3Ad2XQfMS3YP6sYah urD8tLHotBEgVgMBu42IlQDd/ePTw+vS58YY7WnF2Ie19gE5N4TqIDOikLODfD19Yc8N YLIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sRVCV675gnSBUjquD4ODK0/V3BjHMt/6L2aovdLYzzw=; b=xIMvDd8DUSGSw7v287RlEz1jF9cclWRK3gDNjuIwirPOGzjzBhD/kFT7p5NjUVjxF/ 72rXK87TaH/Ja6w9rP/7O6kP6yp0IG5AA5yvPoo4RDDZRTFfXmoe+P0s+kWZhNQqxSfv u+0yI9EUq5zHiJGXJfX2E8gp/D3GMiIWJLXCY4x3gqVIYAtxqk6C0mCQyQytBMav5Elb QMEnpSKyQvrym+lb3xkWoHPagJGv2veqmiD1CUM4hHmW/9oLMY/xDcP6QqF5jIs8X/Hl R5S56FrDdkF20FrKJjOy35b9eTeoeKJvDmmcMQuCnSm5tc0zbnCvJHoi131sg71VomyR rfZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Lk0XjM6q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id be7-20020a170902aa0700b00163f2f6e2desi11119734plb.131.2022.06.07.20.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:38:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Lk0XjM6q; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 617C1218AB2; Tue, 7 Jun 2022 19:56:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240152AbiFGJtt (ORCPT + 99 others); Tue, 7 Jun 2022 05:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239968AbiFGJsl (ORCPT ); Tue, 7 Jun 2022 05:48:41 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1048E8B90 for ; Tue, 7 Jun 2022 02:48:32 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id h62-20020a1c2141000000b0039aa4d054e2so11414717wmh.1 for ; Tue, 07 Jun 2022 02:48:32 -0700 (PDT) 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:content-transfer-encoding; bh=sRVCV675gnSBUjquD4ODK0/V3BjHMt/6L2aovdLYzzw=; b=Lk0XjM6q+E1tzEcGDkrVL6x2hoglan7SuEzw9HQPL7Lt082R2AeWgFfPl9bMG2med7 QX0Z82XrbchUno2FU1kHTdNs9R6Ol+r2OjVL7RhVymZshQ8s3q0TRuTAd6xXC58RTdzQ rEf6nwc080bs0VXt8vh2tvDJ/ZdSbCBBRnsto= 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:content-transfer-encoding; bh=sRVCV675gnSBUjquD4ODK0/V3BjHMt/6L2aovdLYzzw=; b=VFYTiZ2UHPLn+jLBQR4h4LqJq6KwD7SEHUVt2ZgzTNTOKO+X66gvb+ZzHw3P+jzhTD jrQmB6x7eIK1S0Mf3nT0DX4k18Ie0+dO8W2mMGeXO51MR4GIfW7/LUERT/BreKKy/4xj VYuz9vusdUzmWp+sBZkoFypJ7j5vSRlb7jh6N0Hv95kU1P3jjBZwRkMKkB17kNdEMnFh p/MeVc8igwCHupFonhQvBTaAKachKPO6ke7fQOrOnqZFET2rh9OwVoGUXSxgcF0CI9Vv OGUcakXB0bsK2OdAFZVuntgtGVuEKuzw1QE0Ir9HZ9+4iJxEm7Ws7q2FvZKwQsss4Fcj L/oA== X-Gm-Message-State: AOAM531Fn+sEVpNjoArPkn7gfYD8UOnMGI4XChtNNQre+WsCBbJMQqci bYBDH/grOWJn6R+tN+geO5ivdKWILA2hfA== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.32.0