From patchwork Fri Oct 11 16:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3566 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 570733F332 for ; Fri, 11 Oct 2024 18:23:47 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5c934295846sf1586105a12.1 for ; Fri, 11 Oct 2024 09:23:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1728663827; cv=pass; d=google.com; s=arc-20240605; b=LJKiSuA3Z+vfLGa3pZ+btKuXHyXSBGXn2aPD6pDnC9gAPb2fByYvJ4HVWHXYQFF91g CItuWOx/Iky3jc1dhvyrDGT609Psyh4a9FXvSJ6NWqJphbkfNgjx5YgJys68JzFdO3g6 ptXrUHLCf8jl3d4Mq66jq1crP3SIsZgb28ToF/7jUgzgE+Z8w0ppDS/h2T9mZ19UeTJY pkwV7xWMNWDwBohGHKUUJZxYSyjfSJ4oFE42EnZVn0InoWmRAG41H1GwIDLEaZuP/qlm 8IqFyfRhQFBGtmWjTQbxChQPsaol9QoiS2at60t5G/gmoxi4FJXE5cN4K0rlRt/i2K5M xQSA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=eHcixfgDs0PzmOQj2jmSse6ycU/j4yhgVhQtNY3gYcA=; fh=omSvidafdeU+aiIAVzsKuMweeU4e/kTnIRYX/mYCrQY=; b=hEtdgEg1qpUY5MrFY+XY+WgWmzWedL2n74+MIEKGUS42lB2U7IA3V+Ux8VYuW3nbbA jtDkqWo+D75oKkt68VtUVBYeiviTfb9j2znfVUh5vRJ1bxj5P7ue1pTeVIC6bvQ25QxY +NAUJbfFv6slUsZV5ao6Z0XwIRgDO/J6TLmBliw4o8bWswiw8OA44j/aY1njolbBReq4 4OK/+xwAA5uRUATD2Ok5lQQk1TyYe8qx2apJAnnk90p1+UhwDcA3Yg5IiT8zw8D5hHDJ LnYFIkDTD53iY7K5ZOsu/s15TTJqRcoAXYbVmIbgfDkCObkyIcW6se3GIw8sO5Dh+zT+ ffdA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=X19hJhkY; 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=1728663827; x=1729268627; 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:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=eHcixfgDs0PzmOQj2jmSse6ycU/j4yhgVhQtNY3gYcA=; b=JbJ+78q2/0UIDPqzMYxaax4+f0cAfPFjB31g/i36oFBvH6iM2ti7w1o2aQSoYhjDz8 AnT19CwA1iRol0B/qMgFAU22SXfSFH2kuYFAxf9/H8BlA/+VMjW+kHE781k08agqEEyl NYCHVvK3G2QM5OuG/qnv6rnVTWeJIosODQGoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728663827; x=1729268627; 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 :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=eHcixfgDs0PzmOQj2jmSse6ycU/j4yhgVhQtNY3gYcA=; b=Bdlu0QyiJl4CxNXCe/am4tpk0TxFtT8qGoNzzXBJaWSdUfnHck+nv3b+5GLt1d3FMI ByJw7hbkiN6EJjpzNctMYFFehCC1LL8oAIig2z+nvYflyVnbCVyK/3T/1A7Kbvv8e0Pp WIy+1b4adMBmbwjpAhfxi6r4tslHM2PBVjbG9QrbM1+2C+A2eqguwm1DJFG+wbzH3sNs 4v6iLd3HzDF25JIbxxWjZ0/FuWTwMKLsUG/g9iF65MX2nMPhOiyynsT4Dk5p1hWSt2ia MDJpZuMnWOKmJz6NDGpYeE4hr4D+PMl/PiUhyRR+mZRM0GxJR0uZPAjY003RCPV6MnH4 lckw== X-Forwarded-Encrypted: i=2; AJvYcCWou4s58oiWM3DquQQapgtLCXhcDe2Ic+enorDph/cQNN6Ug+/kS++9pV2LUffl5fz3ZWaaGzBy8HUePnRS@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YyRmljWvRQ4y70TtTwQh2AsB9J4RRXcljINLrkeDC/kNSSP/0Po t4gpTzEnWqdxRgIgQmpZ+iBnjNGn41xN8igmvAsXGH2PoJxaudAKqGx6Y3MMeJ6Q2Q== X-Google-Smtp-Source: AGHT+IG4Xl86E1N0jeJCogX3ZH4VD8AkQ43cvZloNLAI9tgk56CmGO0AYUbejUtbqXFw576EuuEnTQ== X-Received: by 2002:a05:6402:274b:b0:5c9:2a8c:8950 with SMTP id 4fb4d7f45d1cf-5c948cc83f6mr2090620a12.15.1728663826454; Fri, 11 Oct 2024 09:23:46 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:2683:b0:5c4:6c19:f74f with SMTP id 4fb4d7f45d1cf-5c933d3ebeals415451a12.2.-pod-prod-04-eu; Fri, 11 Oct 2024 09:23:45 -0700 (PDT) X-Received: by 2002:a17:907:f78e:b0:a99:ccab:8a8 with SMTP id a640c23a62f3a-a99e3cfdeb6mr19060466b.39.1728663824619; Fri, 11 Oct 2024 09:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728663824; cv=none; d=google.com; s=arc-20240605; b=DWv5uErlASMcMHMj8CEmh5yPBFwY4nUwf+jZDXPePr1x6u7xzNUM21AXquJx2RV6Sf w97O9YMpJIPxGhXoY5gBifHS1+WS7/7PsrAAOQ6ZrZct5iRPVfQ1zguS3ET5+N8sewOX VijoYgBzxDPiFFqOn3drMl6cn79PGminrw/4xkmHJtU0CPpB0Y/of9G13UWZclbW0C3p YeUktaTRwdhcslAt7CClzCVt3Db7JyY336LdkyESNcGOJZfEKUlSGlpf/jUTH2vuqx9X 3MjC1qH/ouvHKvGlxNkwUx8jAiG5vG0CvUz/NUy0Ci+ljtBScswYv46cCanvE5FtwGp+ VqBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=SMNtp1bFBYMSj01ryYWUuajoWQ0fWID7a5OmlHE1F0U=; fh=bW3oFOv0XHBefUz3obU0AkR4GIxgTUcq9BdItYoBfi8=; b=O32sTyMSBOOY46NGpxtYzRH8i6yFxEWkUk2tRhEwaLCMn/EBxHPMV3JvfZqSg3aTpq tiitU89rj5ASSUaFZQlwqzbs/XQOBNDhv5D0njOXu1stTdXs+Kd4TVVZwq6HYdaq/w06 +p7nJ64OHOsdRuOuXFsEnbuOyFsn78Fqi8ryouN8kz3QZJIZa6tKV37WPticrfTdGLdm fs03DGSvJJJpmlDdJ7tVlNbBP9TfRbdyfhsKA2lMqUHi2IN2SfxKyGDxKfzmenKRl7wl ESl0PI4jZpKBvMz1RQW0aEAkUCQTSqLk004iZ+tM3IFtlKrgh+EMu4ivLp46LcEYDXZ8 Agbw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=X19hJhkY; 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-a99a808b9a1sor152575366b.12.2024.10.11.09.23.44 for (Google Transport Security); Fri, 11 Oct 2024 09:23: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:a17:907:e685:b0:a99:491d:20ee with SMTP id a640c23a62f3a-a99e3b5e571mr21408066b.19.1728663823886; Fri, 11 Oct 2024 09:23:43 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.40.11]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80c0222sm229891266b.140.2024.10.11.09.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 09:23:43 -0700 (PDT) From: Dario Binacchi To: linux-amarula@amarulasolutions.com Cc: michael@amarulasolutions.com Subject: [PATCH 1/6] can: dev: add generic function can_update_bus_error_stats() Date: Fri, 11 Oct 2024 18:23:36 +0200 Message-ID: <20241011162341.606443-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 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=X19hJhkY; 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: , Signed-off-by: Dario Binacchi Change-Id: I55e0d86725475fed08e00afaa494973632bba850 --- 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 3797d4de254d..c153015435fe 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -325,6 +325,36 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt, return err; } +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 73199facd5a4..374b6121ea3e 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -200,6 +200,7 @@ void can_bus_off(struct net_device *dev); 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); void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, unsigned int idx);