All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: linux-can@vger.kernel.org
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
	Frank Jungclaus <frank.jungclaus@esd.eu>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: [PATCH v1 12/12] can: error: add definitions for the different CAN error thresholds
Date: Wed, 13 Jul 2022 00:31:57 +0900	[thread overview]
Message-ID: <20220712153157.83847-13-mailhol.vincent@wanadoo.fr> (raw)
In-Reply-To: <20220712153157.83847-1-mailhol.vincent@wanadoo.fr>

Currently, drivers are using magic numbers to derive the CAN error
states from the error counter. Add three macro declarations to
remediate this.

For reference, the error-active, error-passive and bus-off are defined
in ISO 11898, section 12.1.4.2 "Error counting". Although ISO 11898
does not define error-warning state, this extra value is also commonly
used and is thus also added.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---

Strictly speaking, this does not need to be part of the uapi but I
still think it is beneficial to have it here. Thank you for your
comments.

Also, if anyone knows which standard originally defined the
error-warning, let me know.
---
 include/uapi/linux/can/error.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/uapi/linux/can/error.h b/include/uapi/linux/can/error.h
index a17ad25a01f9..5c0639134f96 100644
--- a/include/uapi/linux/can/error.h
+++ b/include/uapi/linux/can/error.h
@@ -127,4 +127,17 @@
 /* TX error counter / data[6] */
 /* TX error counter / data[7] */
 
+/* CAN state thresholds
+ *
+ * Error counter	Error state
+ * -----------------------------------
+ * 0 -  95		Error-active
+ * 96 - 127		Error-warning
+ * 128 - 255		Error-passive
+ * 256 and greater	Bus-off
+ */
+#define CAN_ERROR_WARNING_THRESHOLD 96
+#define CAN_ERROR_PASSIVE_THRESHOLD 128
+#define CAN_BUS_OFF_THRESHOLD 256
+
 #endif /* _UAPI_CAN_ERROR_H */
-- 
2.35.1


  parent reply	other threads:[~2022-07-12 15:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 15:31 [PATCH v1 00/12] can: error: set of fixes and improvement on txerr and rxerr reporting Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 01/12] can: pch_can: do not report txerr and rxerr during bus-off Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 02/12] can: rcar_can: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 03/12] can: sja1000: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 04/12] can: slcan: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 05/12] can: hi311x: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 06/12] can: sun4i_can: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 07/12] can: kvaser_usb_hydra: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 08/12] can: kvaser_usb_leaf: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 09/12] can: usb_8dev: " Vincent Mailhol
2022-07-12 15:31 ` [PATCH v1 10/12] can: error: specify the values of data[5..7] of CAN error frames Vincent Mailhol
2022-07-19 10:44   ` Stefan Mätje
2022-07-19 14:14     ` Vincent MAILHOL
2022-07-12 15:31 ` [PATCH v1 11/12] can: add CAN_ERR_CNT flag to notify availability of error counter Vincent Mailhol
2022-07-12 15:31 ` Vincent Mailhol [this message]
2022-07-19 14:35 ` [PATCH v2 00/12] can: error: set of fixes and improvement on txerr and rxerr reporting Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 01/12] can: pch_can: do not report txerr and rxerr during bus-off Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 02/12] can: rcar_can: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 03/12] can: sja1000: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 04/12] can: slcan: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 05/12] can: hi311x: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 06/12] can: sun4i_can: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 07/12] can: kvaser_usb_hydra: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 08/12] can: kvaser_usb_leaf: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 09/12] can: usb_8dev: " Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 10/12] can: error: specify the values of data[5..7] of CAN error frames Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 11/12] can: add CAN_ERR_CNT flag to notify availability of error counter Vincent Mailhol
2022-07-19 14:35   ` [PATCH v2 12/12] can: error: add definitions for the different CAN error thresholds Vincent Mailhol
2022-07-20  7:17   ` [PATCH v2 00/12] can: error: set of fixes and improvement on txerr and rxerr reporting Marc Kleine-Budde
2022-07-20  7:24     ` Vincent MAILHOL

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712153157.83847-13-mailhol.vincent@wanadoo.fr \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=frank.jungclaus@esd.eu \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.