From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: linux-kernel@vger.kernel.org
Cc: linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
linux-can@vger.kernel.org
Subject: [RFC PATCH v2 3/6] can: dev: add helpers to setup an error frame
Date: Tue, 29 Oct 2024 09:44:47 +0100 [thread overview]
Message-ID: <20241029084525.2858224-4-dario.binacchi@amarulasolutions.com> (raw)
In-Reply-To: <20241029084525.2858224-1-dario.binacchi@amarulasolutions.com>
These helpers can prevent errors and code duplication when setting up a
CAN error frame.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v2:
- Replace macros with static inline functions
- Update the commit message
include/linux/can/dev.h | 46 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 0977656b366d..1b09d30dae32 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -168,6 +168,52 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s
return can_dropped_invalid_skb(dev, skb);
}
+static inline void can_frame_error_init(struct can_frame *cf)
+{
+ if (cf)
+ cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
+}
+
+static inline void can_frame_set_err_bit0(struct can_frame *cf)
+{
+ if (cf)
+ cf->data[2] |= CAN_ERR_PROT_BIT0;
+}
+
+static inline void can_frame_set_err_bit1(struct can_frame *cf)
+{
+ if (cf)
+ cf->data[2] |= CAN_ERR_PROT_BIT1;
+}
+
+static inline void can_frame_set_err_ack(struct can_frame *cf)
+{
+ if (cf) {
+ cf->can_id |= CAN_ERR_ACK;
+ cf->data[3] = CAN_ERR_PROT_LOC_ACK;
+ }
+}
+
+static inline void can_frame_set_err_crc(struct can_frame *cf)
+{
+ if (cf) {
+ cf->data[2] |= CAN_ERR_PROT_BIT;
+ cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
+ }
+}
+
+static inline void can_frame_set_err_form(struct can_frame *cf)
+{
+ if (cf)
+ cf->data[2] |= CAN_ERR_PROT_FORM;
+}
+
+static inline void can_frame_set_err_stuff(struct can_frame *cf)
+{
+ if (cf)
+ cf->data[2] |= CAN_ERR_PROT_STUFF;
+}
+
void can_setup(struct net_device *dev);
struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
--
2.43.0
next prev parent reply other threads:[~2024-10-29 8:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 8:44 [RFC PATCH v2 0/6] can: dev: add generic function can_update_bus_error_stats() Dario Binacchi
2024-10-29 8:44 ` [RFC PATCH v2 1/6] " Dario Binacchi
2024-10-29 8:49 ` Marc Kleine-Budde
2024-10-29 8:44 ` [RFC PATCH v2 2/6] can: flexcan: use can_update_bus_error_stats() Dario Binacchi
2024-10-29 8:44 ` Dario Binacchi [this message]
2024-10-29 8:57 ` [RFC PATCH v2 3/6] can: dev: add helpers to setup an error frame Marc Kleine-Budde
2024-10-29 8:44 ` [RFC PATCH v2 4/6] can: flexcan: use helpers to setup the " Dario Binacchi
2024-10-29 8:44 ` [RFC PATCH v2 5/6] can: netlink: extend stats to the error types (ack, CRC, form, ...) Dario Binacchi
2024-10-29 8:44 ` [RFC PATCH v2 6/6] can: dev: update the error types stats " Dario Binacchi
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=20241029084525.2858224-4-dario.binacchi@amarulasolutions.com \
--to=dario.binacchi@amarulasolutions.com \
--cc=linux-amarula@amarulasolutions.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®