From patchwork Tue Oct 29 11:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3610 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id DA41C3F382 for ; Tue, 29 Oct 2024 12:46:31 +0100 (CET) Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5c94a70a3f5sf3688229a12.0 for ; Tue, 29 Oct 2024 04:46:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730202391; cv=pass; d=google.com; s=arc-20240605; b=jvrjL1wXnA4MD3obW8hkXy2+inPGr1Q1QkYz+rb6UZbVeK5pirR8nLblxosTzhih5K p1yT7gxZUcaF6KchWHilpx4cwcDG+dtMDrfHfBgKfBnm22wpxQFlqqL+nE2FkkTSDIn1 uLChbuoiOedC9ymLYcMW61UjZ9ZB5Qp1C0pwD+s/nWh4MFtLywA3/ZHaiSmGdE0jg5xa C22ZxSntXtxZg9NU96aPcZ6zqhokLOqDxhHQ7GHfUJb4Tah5pMIOrGpBKmmU8G3SiGzJ A1/sy5/geKrPC2MRWr98Ri6p/dMV9Q+7SG/MmsXXP7iFvHJO3eBV7UHROUa80pfPdr9A fvwA== 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=6sywNy10mW3ybxaebe3mVFSQccRgKx6T/gQajvn5QXs=; fh=QTBCpPAxyyTsBhOgCl9jJHYyV7HmBM5I8VH3qX5yYf8=; b=avE4/h/IIZgnLYADcQF7lwDBBekKmjCOk/fkVZPZOIVQfAXTw1/E4DbQ44WajvmwSr jWTsD5SWKUMheqY3PwVUxQ0LSY52ArvIANSi/3q9eRPy8yU2FrvPF85O7FzdLN1pKciM huXfuixxTx7IZJC926r8lppLhuoa1LW5pzXRycVgT3Gw+oiaEBfq3Pg8m3mnQMqSpxS/ LWfgXob1pc0sc0JvbOEIet31ljKAKOyruzzoK5g/HsAFK3afs+nUfkfPHiZBZrfpLapv jpH86TOTVt2W5JqKzh6DWF62wTuCOvryIAcWy/2iq7LT5CcEcYGAVn77sqYmxQxHUyaz iI9g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NDBbY+ix; 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=1730202391; x=1730807191; 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=6sywNy10mW3ybxaebe3mVFSQccRgKx6T/gQajvn5QXs=; b=hoK04VMOSOwqQulYOZEz+ua5xlvduVtpMJV1GW1w5QTszDdO/KXe0sK7e5J/3YnxqF pCRYbuUQOyNI55azucQYubCrflgD6ltMDLBF18AgCwindhS+Vg3418Wdr9ZBlFqrhZC2 nhcF0Jo9cGRcGCbW9lDRdIm4r/mUPwxcwFPOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730202391; x=1730807191; 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=6sywNy10mW3ybxaebe3mVFSQccRgKx6T/gQajvn5QXs=; b=PlWN5Kxg7EvDDCcTVMfYcLcvrPkk5OfiPY3K93q2J9mtUeNh1M4mHcAT/uDvKApKwz N87JWjnHuT9vOQukcdfeC5gM0rZiAywdk1ErMjjoNEkPKrQ4BUNmhroTb/v9Ux+SnR5Z NfYfQgERwtebpP3Sr5l5V7fN7hW+q/u9kKdKIg1IYgXALSfEVbg0IJdPfCC6yLZggpON hphduhq/xtPZXz5aImilUBtaG7BWSjpya/OXp25uAeHHpQH8fTWv5BW9z1RsJu1mlDFP m8rhczyxcdRJi+8ECzfpMGp92/a1CsA33O1TotyuC80CpjA0q+eYHi4xogF2V031UVfn PRsg== X-Forwarded-Encrypted: i=2; AJvYcCW5dRK1Y+rtwqS+9Gty3W7ljFPCPNkfF8BSsOSvhndyaPIb41W97ThT60wRygVXWa7AML+WY6D4c9kBRQ/U@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yxp4Z0g1hpJm0B0HIb3pBSm0eupgupRftNn9IsoyPE0ZPaKkY9O 6cW35dH49wvrFTFxMndpn/OXGcb1jtCyXwJA2wSixXO4pnsKfv/BRxBjhxzcbv7/cQ== X-Google-Smtp-Source: AGHT+IG6KinGnwxzSHzcBfQFJZiTyr2zznV9L5q7tDyicJqkwooOuxZpQZ/9vRDCKSYVGFKQxcOvKw== X-Received: by 2002:a05:6402:42ca:b0:5cb:dd06:96d6 with SMTP id 4fb4d7f45d1cf-5cbdd06977emr6013014a12.11.1730202391214; Tue, 29 Oct 2024 04:46:31 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:524d:b0:5cb:73a6:e040 with SMTP id 4fb4d7f45d1cf-5cb9987a67els766086a12.0.-pod-prod-03-eu; Tue, 29 Oct 2024 04:46:30 -0700 (PDT) X-Received: by 2002:a05:6402:529b:b0:5c9:5a96:2869 with SMTP id 4fb4d7f45d1cf-5cbbf8b1ceamr8937782a12.10.1730202389683; Tue, 29 Oct 2024 04:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730202389; cv=none; d=google.com; s=arc-20240605; b=Lbig1L/3O3ZxWIVjRn2A6Kzxve/4a5Bl1VTM03pRoyNGpXKkzFLeqGLOaAG9t3Qhjw 50kcZqPltzhh16uJvwtvYufHSdh9MbJH/hutEguna1uXqPX8OHQLeBaJTtFfeLXr8UCA Kg4Kgqd5ZkTVOgaKwoECaul81iMw2qGnZDnY1OtFmmlMNn+yK5ZJY9TI/zmm5dDKTTXY PnF/IiUJIEdAXgzUtZCSOyBHipxosYPap177zQObl/hM7Ku9awdA4nJ0GvTqfqkD5+jr qpwp4x9kOwmf6EFz4hOR3P8c+5VdUmOhIJGt/XJa/GAxQZTCBzp0vaHjoay4Gz/yy22+ LxHg== 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=QeZLl8zUuEL6V9/kOSR2k3pEjiYcKf6aSxS5b01tjs0=; fh=y29f59UM50SX5sXYLtfDcG4k/2fOYCXC2xF+eD0qj1I=; b=HOygobfYlHhSqyCdiiXEK4wqMJ8Cnrs9wPZy4imInK7gbObJUceuNFp8PxNkuOpnWR P+qwvZsbhi9dqrdUb5KuMONnAx5phmLeXHf/pG01Xe9AzRJycflsbEkIYtpVdGeMwsrU RZNcrlSwyYVmIEWREzdNl6Fy3N07EvVz2w4JhX20dMFMZ0ffNerm5sWZro5rZiMcorkd E1qzXgNmrViEfFq9AmpEWooPCXEHsVrjHw8y/WO+PdmxCzSWVRimHSIy8GaoFyjc8rP+ bYlC4QsAX21V3nDW/GUAXGgBk6+IvvOPm8GTBJZaasAChqw1zSO6wccCchdAJkj0AvHZ +33A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NDBbY+ix; 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 4fb4d7f45d1cf-5cbb621ec81sor2839889a12.3.2024.10.29.04.46.29 for (Google Transport Security); Tue, 29 Oct 2024 04:46:29 -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:6402:5215:b0:5cb:ee14:d08d with SMTP id 4fb4d7f45d1cf-5cbee14d13fmr3714450a12.15.1730202389145; Tue, 29 Oct 2024 04:46:29 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.. ([2.196.41.207]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb6297a09sm3869301a12.21.2024.10.29.04.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 04:46:28 -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 , Vincent Mailhol , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [RFC PATCH v3 1/6] can: dev: add generic function can_update_bus_error_stats() Date: Tue, 29 Oct 2024 12:45:25 +0100 Message-ID: <20241029114622.2989827-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241029114622.2989827-1-dario.binacchi@amarulasolutions.com> References: <20241029114622.2989827-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=NDBbY+ix; 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 --- Changes in v3: - Drop double assignement of "priv" variable. - Check "dev" parameter is not NULL. 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..4ad0698b0a74 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; + bool rx_errors = false, tx_errors = false; + + if (!dev || !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);