[3/6] can: dev: add helper macros to setup an error frame

Message ID 20241011162341.606443-3-dario.binacchi@amarulasolutions.com
State New
Headers show
Series
  • [1/6] can: dev: add generic function can_update_bus_error_stats()
Related show

Commit Message

Dario Binacchi Oct. 11, 2024, 4:23 p.m. UTC
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Change-Id: I27a5eebfb6ee74d2af3e8455d96af9dc317bca24
---
 include/linux/can/dev.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch

diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 374b6121ea3e..018b9e942ed9 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -21,6 +21,29 @@ 
 #include <linux/can/skb.h>
 #include <linux/netdevice.h>
 
+#define CAN_FRAME_ERROR_INIT(cf) \
+	cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR
+
+#define CAN_FRAME_SET_ERR_BIT0(cf) \
+	cf->data[2] |= CAN_ERR_PROT_BIT0
+
+#define CAN_FRAME_SET_ERR_BIT1(cf) \
+	cf->data[2] |= CAN_ERR_PROT_BIT1
+
+#define CAN_FRAME_SET_ERR_ACK(cf)  \
+	cf->can_id |= CAN_ERR_ACK; \
+	cf->data[3] = CAN_ERR_PROT_LOC_ACK
+
+#define CAN_FRAME_SET_ERR_CRC(cf) \
+	cf->data[2] |= CAN_ERR_PROT_BIT; \
+	cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
+
+#define CAN_FRAME_SET_ERR_FORM(cf) \
+	cf->data[2] |= CAN_ERR_PROT_FORM;
+
+#define CAN_FRAME_SET_ERR_STUFF(cf)	\
+	cf->data[2] |= CAN_ERR_PROT_STUFF;
+
 /*
  * CAN mode
  */