From patchwork Mon Oct 14 15:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3576 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6E28D3FA1A for ; Mon, 14 Oct 2024 17:24:46 +0200 (CEST) Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43114c476c2sf29255385e9.1 for ; Mon, 14 Oct 2024 08:24:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1728919486; cv=pass; d=google.com; s=arc-20240605; b=Lkp1JgjGUnGhu/aIzxcn4InGxa/daOPclY8eH9lhjuvZVnIZyArBILOAJKEKKQMfz5 DMHGUBMIREeSW2FpjGOW81cB7nLZM6Osv0aoHlb5r4O2Dl8XIKeHib4aaqThLWRavQ0y VqdqzyO8hLXNfQAHKvhvJ5nRUJ0ut6p+t3OozWviT8N1BhLx0l781Gyv/vGne/ca/0Xn LHFvglpITcERBoBFNLaNJkF1aYS5wcqIP4nFk4sM6ZgHNQ1QAzHn4nu3m4/zD9M5W3+Y VVI2S3vl9XMhsjNFi2ADxkVuckeEGXn7uwJDxQVXqSODry5JLbZzNr6muwcHhlixO6l+ CYrg== 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=OtvvQtw9bfKAUQR6uLRUJnqD4YPG6foJ7RuJdWf9byc=; fh=R6+9XWuE1lZjFlcVM8NmM4Ke7LIhkSceirIUqDzSJcA=; b=Q7pejquemh17kJfB9TS4SvzUSwNZPYMEbzgAr0RWPicfkJebh5R7L/xR23qT65Gymq z9vFh5TrK+yFh/tPy9koukpBjmWa9l4BQZIjf8W5gFRTVd4ibUARntltUGB3YkdBq17o BrK5jyrAVlyOLQKtYzlFXtD2tuveK9Ux67yxTbZnHgHegvqCqaT6v4TVPypTfMZqHekI 5Cwhr+uA6N+U6Ns4e48hmyeBVo19ncyiT+IaIYxyIgmpJKgvCVN8i2irHtznmDF4ANH3 SKn/GvGy0WDxnmiZFLdHWj+uWR9Rz8ZSEV0SwssNHHnJtAfeXvW9cGqUbQ8CmYJ0+yk6 DkGA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OdwqQKh2; 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=1728919486; x=1729524286; 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=OtvvQtw9bfKAUQR6uLRUJnqD4YPG6foJ7RuJdWf9byc=; b=axPeQYVIbGn4b8fWSn6wk5lW93kPiKmgnhyMqRWNuG5wLXE8UniMJ54XHPwrnv4s6A hNpAaRIJVST3S1RqU2NTthtQGHiAJYRro+K1hTy5Hs2BE3YprojdwNV9PgEb0L9jHcNr wb4aKCHmGIw39Oc63iqltBA4OmYGSfztbQn+4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728919486; x=1729524286; 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=OtvvQtw9bfKAUQR6uLRUJnqD4YPG6foJ7RuJdWf9byc=; b=aIR90qb89BqozYj2g3u6Bz/51+e4jNtywumVdwMs4ImvrGPF56nlbgiyWqzF/VC+5c N05wbeR82FthdR01QTjBmCIpbnW0yDe5kJJR2BBrOT1xGf6X5mdMIHSBq8GkiZMtrmP9 NI5t+F7SkWHQ7ipgaezikpX7M3fg6FdnPTTBDeNxYe/JRYce369fwcZmqFjPoVJVaFzy WpRV1xQ25WlGkIOsYoXayFI+8WtVQ7wB8VUwHEsSap8U4eXUDVuS/La7adBR1yLhlaUH R1eSe1YYdlu21QZPl90Gu/blIO7PDWPHOWR8CBmQ2XUt0irpZiDXEfm1pG59vuzgrObI ORsA== X-Forwarded-Encrypted: i=2; AJvYcCUOCZPYDKgy/cxX1b1sJNMM6jJIuZUlPqZ++S0HpsR474hlGK7JYUFoGr+uCYCwLv8vEDFpDiEkhbxpDbaH@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YzEK6LFx+hwhFE7hznpAC/7QTUm07IeaR9cepBocR51/iFxI6Jr GftLGKYvo0BSnl2kf+nEji4QxXE+RegFgxXnXcqfdh4LzR19Ea9ftfoTjMAxdslO0g== X-Google-Smtp-Source: AGHT+IHo7sNTBIERmUDe+Yrd1qJU7jV6qWCgdCPcZ1s2WZfE02q2Eea/qQ2kTKrK/sGWusAIVNR9Zw== X-Received: by 2002:a05:600c:4f8e:b0:42f:8515:e490 with SMTP id 5b1f17b1804b1-4311dea3cebmr123774315e9.5.1728919485864; Mon, 14 Oct 2024 08:24:45 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:1c9f:b0:431:155e:348e with SMTP id 5b1f17b1804b1-43115f179e2ls10747115e9.0.-pod-prod-02-eu; Mon, 14 Oct 2024 08:24:44 -0700 (PDT) X-Received: by 2002:a05:600c:1e07:b0:42c:b950:680b with SMTP id 5b1f17b1804b1-4311dee6f4cmr96448275e9.20.1728919484384; Mon, 14 Oct 2024 08:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728919484; cv=none; d=google.com; s=arc-20240605; b=W3988eG7m+6P2Bvwdsb5Md7Jok3MscV13kUhsM5u8N8Luq888f4n1lCfSy6hOvz4/X 3ZDFvX4S7ZqccCdpPToUhmrpBAelqd1V81LaicfoIP5StKXHRUE2cJ4vtJpQfe3QCLSe 2C9JdNVBCQKsyVWs5sE55LWPCJCQ6koV/GB6Mx4PmE100mtQxEP7d1UKZX9NxgQ4l38L NDd/k27dZliIdkvp0q67DJ3/6YLy9zgaH6nZc2gIP+zeqftFC6Vsb9gW+p9MuUKR/qAJ LZ162HOO40b0zhfMFyzqoxfPBMHYSgHNxm9mKIrigOeWZApuiWk0EKvVFL8SmCIKvOK6 9p+Q== 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=gvkSVt8VpmX4gMY6ZJ043PHdZhz1ZoH+BaE3ci1zs5w=; fh=GfKZgcJmDxhv0Km7SY1mUOBGy7WMd5fDMbaQLiwxr+E=; b=Nk4OopLZRCdS+2dEGHLoIPpsKqg8o+ECnqGfBwumM8AIhTDoTYuZJ3g6jvgCatdNtk Kims2T9LQSvURGe3d0oIRwrlGLIq4OckjXKuH7ye8ppcgwmGgNvlCCIz785stF7oXKRa pieU9tJmAmeqAATa3WW2f2eT7OtvqyQBTTJ8YAqDS+2HvLAE0rurEEO3IZT+8WzRNY6c QfjVrFD5JLcxp7z3P3BOBY+ESSmnF3xIVKItJrhcV4bxDUzq/pSLv8Zol/2/CN49tlRE yPdeeEaPLRU4NXJkMk2a8ht+BNK3ZfFv3rdcyzcn+7FfLmL6VsDirghuiVA/lndLs+iz nzOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OdwqQKh2; 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 5b1f17b1804b1-4311861d607sor30003845e9.12.2024.10.14.08.24.44 for (Google Transport Security); Mon, 14 Oct 2024 08:24:44 -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:adf:e88b:0:b0:37d:4cd6:6f2b with SMTP id ffacd0b85a97d-37d551d2566mr7314184f8f.14.1728919483907; Mon, 14 Oct 2024 08:24:43 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.40.133]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d4b6bd1b7sm11629911f8f.37.2024.10.14.08.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 08:24:43 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, michael@amarulasolutions.com, Dario Binacchi , Alexandra Winter , "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 1/6] can: dev: add generic function can_update_bus_error_stats() Date: Mon, 14 Oct 2024 17:24:16 +0200 Message-ID: <20241014152431.2045377-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014152431.2045377-1-dario.binacchi@amarulasolutions.com> References: <20241014152431.2045377-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=OdwqQKh2; 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 --- 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);