From patchwork Tue Oct 29 08:44:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3603 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6E0FD3F360 for ; Tue, 29 Oct 2024 09:46:27 +0100 (CET) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5c9452d6321sf3781097a12.3 for ; Tue, 29 Oct 2024 01:46:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730191587; cv=pass; d=google.com; s=arc-20240605; b=GzOnTlaNR5tkvltg36yzu/XwU9RUz+v5GcbanVNWFST5FIkn9IdqoKZ48oo4A1Ku+6 BWPcCrbgySyiZpwFwlKVLIfVTnV/hEErqtbSdyFWV7dXAqvWCV3/x5puEOxy0b52yoy4 yZCsd1itR7jXpwtR1E2a8g1nJys59TJYObjbjjHWqfhMIdTyLr/nXwKuU+MUbnqEUztp B0P/YN1lHlzLtKPbHECqE7OMVfXH8Cg6LoYqLAl8b8UIuOygb8pH1uVTpgU0PkftA0PZ lKu7fRkY/GXtGEaEI60x0UE8XHlTMc7Hg2D6dUapk0MKDgEaOAzSQEiB+6ObvOjAzCz8 QdWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=HQsCXBIlvezkKhqkM9RWVaVb2iiSTABHmcD4r4ilE+0=; fh=tPc/hxcTAtjSQUikGbELCbvtErE7V14C0AMkrIAFbXU=; b=f1U8njaxp9R609nc50y9pkmNToIUK/xlt7JeVFguOrHFa7Ebp3CJ90RvrDfkh/oe+l ZML5cRJncW/isX5x6XCebBzQbl3fXZFT+hT892ZSnCU3ye32ysRi7ZT7I1pDOoJyQYal Ood7lwdChdUUeuf0Ty2qKDuLSpJMhcElzdkq9t9qKo2tbh2DhIHaGkSLmSo60xMWfGMI Chcq/rEKuK337Wd0wqzjgKEITZiuAXSxdL7wOfQH9eikBNgf9MwHxhFT5lhnSWfdE2h8 p8DP5GfBXwxdugD8EWKbuVZIob4I0Gql6HGI3wzPiaAVun51hhlozr2kRkfLu74rVHpB anRA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=aVgLC8MH; 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; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1730191587; x=1730796387; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=HQsCXBIlvezkKhqkM9RWVaVb2iiSTABHmcD4r4ilE+0=; b=Naq5v5m3Zfi7AFsy+TWmSaWpF0qEA+P1ZOWoC6A57HYDZLCBqso1u85SlXmSQTSzmh oqMvMBbajVe1vXuhE8EHFHTM9xeoNqoGIsfesoYmbOv35VPcekyR/wYn8CQz9LeYoOt4 74+aYdK4RuFruJ5mzPBDit4thEZY0AZ7xaNsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730191587; x=1730796387; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HQsCXBIlvezkKhqkM9RWVaVb2iiSTABHmcD4r4ilE+0=; b=r8r2ksYVRAoutDWmD/ZnATPGw7LRnlaBkk1ENrxhKvPLs0u6+wMh7+HVG+eEE0TLzS FH/y4qgBsEE1WU7gSjJmdgUyQ01YdIE+UtWLJjXsnl+tSzpqBcljLbCM/BzpxpwYhIuK s35/pqeISjz7StkDej8RH1fwk6r8F0K2ZUz0LI17uXjPvOTXJp/Urw/s5vjSPYmprMsW tPobKTtDFTnJJ1wUfrKlHeWcVWOy2M4pfR/2QlMH9O3wkwZF2viAmZfxWOZeN49EAJhS nBOIVQID28NhjqDrxl7ILiKSl0Zm6u4/OO24D8HRQj6pFCJ3Gb8SHwcErqqNPN+Tle9/ nkew== X-Forwarded-Encrypted: i=2; AJvYcCWmb7vTKueTTv/g9RwRUhttprrkbKtMakjpZHwYSnFKXO2JubwNpuqI1ydDNzGk84ggZH4tN4Ry+Wh19h1q@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YxrDkkOA7gcwkVZaLMjA5IpMgj3bk/ZZHXgQy4vlaDanSClsgPb 6Brm6RqQZmP+YDg1xoiv84coNr5TOLHzSaE8jq6fJTsTGYtGWBp4eoY0EoaeaGEvgA== X-Google-Smtp-Source: AGHT+IG+vJYF3519c+4+TOsNoz7l6nqDYKAOuO1FIWjwy2J6vN4HpL7Gw4+eUevy8T5Ee4anTfy74Q== X-Received: by 2002:a05:6402:268a:b0:5c3:cd88:a0a with SMTP id 4fb4d7f45d1cf-5cbbf8c3928mr8973321a12.18.1730191586819; Tue, 29 Oct 2024 01:46:26 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:1645:b0:5cb:dcf8:ff45 with SMTP id 4fb4d7f45d1cf-5cbdcf900c8ls163831a12.1.-pod-prod-04-eu; Tue, 29 Oct 2024 01:46:24 -0700 (PDT) X-Received: by 2002:a17:907:97c6:b0:a9a:4158:494a with SMTP id a640c23a62f3a-a9de615bc4emr971705166b.41.1730191584104; Tue, 29 Oct 2024 01:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730191584; cv=none; d=google.com; s=arc-20240605; b=Uboi6EYK20DUKD2iWi3cYzX3B0I2IdFCPCqasObsMhwcao1cRHi4OCDTPwCZxMYf5H KsceFE6FRQWPc/DGb3BZ8FZK1xbAuRHdf9Dk2DNHB+W5XFr6nPqWY3400KdQKfJyTx8M 87/o0FkNb3IvJWTVniWNSUPJBj1VY3ZuzmPKdSVCSjJuVBwAc7RPM3lwtfP/gtbR8qEJ WV2hEJicsqvRHLfikTOyQ9W6P8Aa+QmlgQC9dcO/4NywT3db8rWaffO3YOBhzOm/cknM R56nXJa7h69viIBgjx17wmwBrOZugJV2oJybjL9iDMyD8jxTfndT8Im36/vr8xGxxZJf 48RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=zDcquMlQbBV3XN4Io8qW6xdqDAgSIub1vLoIuhz6Z10=; fh=ToPqDL27+92lHdmiCPBOvKBiGHlqSsm18pRt+HBl4X4=; b=DVVpilN3VhmppBXCgHvRH7b9aVzdjLejujgmgQn8JInbjn5a5e26hqMy8oQFh40/Wj 8bQ9BDF4kIUFlpQIILmgUqbtUny759fGIeGpKfLk9TANo0VCtfGsg1Z0QmdcrqNqYAXd Krc3yzrBPNQaqiVeX45IdGAcvfJectrhHoTB1otGZ5LEMISfTDo5K80/wPc7mb4K7G5s 9mqZqwcP0CbPHrH70+s9cvydbxuezLyZQkt6lMCFgDafAIFTg9m5gc5cxwGDkNSdPXQ3 Xy2s8xF8MVnAeHEso9inwq6bnFmRc0yRkrNWY2PflSGnSxd2fh+wT+9fTOnycEuoTird c9yQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=aVgLC8MH; 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; dara=pass header.i=@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 a640c23a62f3a-a9b1dec772csor353434366b.4.2024.10.29.01.46.24 for (Google Transport Security); Tue, 29 Oct 2024 01:46:24 -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:906:c10d:b0:a9a:37fe:e7d0 with SMTP id a640c23a62f3a-a9de6199186mr1046662666b.64.1730191583525; Tue, 29 Oct 2024 01:46:23 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-79-40-68-117.business.telecomitalia.it. [79.40.68.117]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9b1dec7dacsm450134166b.9.2024.10.29.01.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 01:46:23 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Andrew Lunn , "David S. Miller" , Eric Dumazet , Gal Pressman , Jakub Kicinski , Kory Maincent , Marc Kleine-Budde , Paolo Abeni , Sabrina Dubroca , Shannon Nelson , Simon Horman , Vincent Mailhol , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC PATCH v2 1/6] can: dev: add generic function can_update_bus_error_stats() Date: Tue, 29 Oct 2024 09:44:45 +0100 Message-ID: <20241029084525.2858224-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241029084525.2858224-1-dario.binacchi@amarulasolutions.com> References: <20241029084525.2858224-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=aVgLC8MH; 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; dara=pass header.i=@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: , The function aims to generalize the statistics update by centralizing the related code, thus avoiding code duplication. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/net/can/dev/dev.c | 30 ++++++++++++++++++++++++++++++ include/linux/can/dev.h | 1 + 2 files changed, 31 insertions(+) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index 6792c14fd7eb..0a3b1aad405b 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -16,6 +16,36 @@ #include #include +void can_update_bus_error_stats(struct net_device *dev, struct can_frame *cf) +{ + struct can_priv *priv = netdev_priv(dev); + bool rx_errors = false, tx_errors = false; + + if (!cf || !(cf->can_id & (CAN_ERR_PROT | CAN_ERR_BUSERROR))) + return; + + priv = netdev_priv(dev); + priv->can_stats.bus_error++; + + if ((cf->can_id & CAN_ERR_ACK) && cf->data[3] == CAN_ERR_PROT_LOC_ACK) + tx_errors = true; + else if (cf->data[2] & (CAN_ERR_PROT_BIT1 | CAN_ERR_PROT_BIT0)) + tx_errors = true; + + if (cf->data[2] & (CAN_ERR_PROT_FORM | CAN_ERR_PROT_STUFF)) + rx_errors = true; + else if ((cf->data[2] & CAN_ERR_PROT_BIT) && + (cf->data[3] == CAN_ERR_PROT_LOC_CRC_SEQ)) + rx_errors = true; + + if (rx_errors) + dev->stats.rx_errors++; + + if (tx_errors) + dev->stats.tx_errors++; +} +EXPORT_SYMBOL_GPL(can_update_bus_error_stats); + static void can_update_state_error_stats(struct net_device *dev, enum can_state new_state) { diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 23492213ea35..0977656b366d 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -201,6 +201,7 @@ void can_state_get_by_berr_counter(const struct net_device *dev, enum can_state *rx_state); void can_change_state(struct net_device *dev, struct can_frame *cf, enum can_state tx_state, enum can_state rx_state); +void can_update_bus_error_stats(struct net_device *dev, struct can_frame *cf); #ifdef CONFIG_OF void of_can_transceiver(struct net_device *dev);