From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org, mkl@pengutronix.de,
mailhol.vincent@wanadoo.fr
Cc: netdev@vger.kernel.org, Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [PATCH v5 7/8] can-dev: introduce helpers to access Classical CAN DLC values
Date: Mon, 9 Nov 2020 16:36:56 +0100 [thread overview]
Message-ID: <20201109153657.17897-8-socketcan@hartkopp.net> (raw)
In-Reply-To: <20201109153657.17897-1-socketcan@hartkopp.net>
can_get_len8_dlc: get value to fill len8_dlc at frame reception time
can_get_cc_dlc: get DLC value to be written into CAN controller
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
include/linux/can/dev.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index e767a96ae075..f25558609d09 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -168,10 +168,29 @@ static inline bool can_is_canfd_skb(const struct sk_buff *skb)
{
/* the CAN specific type of skb is identified by its data length */
return skb->len == CANFD_MTU;
}
+/* helper to handle len8_dlc value for Classical CAN raw DLC access */
+static inline u8 can_check_len8_dlc(u32 ctrlmode, u8 len, u8 dlc, u8 ret)
+{
+ /* return value for len8_dlc only if all conditions apply */
+ if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) &&
+ (len == CAN_MAX_DLEN) &&
+ (dlc > CAN_MAX_DLEN && dlc <= CAN_MAX_RAW_DLC))
+ ret = dlc;
+
+ /* no valid len8_dlc value -> return provided default value */
+ return ret;
+}
+
+/* get value to fill len8_dlc in struct can_frame at frame reception time */
+#define can_get_len8_dlc(cm, len, dlc) can_check_len8_dlc(cm, len, dlc, 0)
+
+/* get DLC value to be written into Classical CAN controller at tx time */
+#define can_get_cc_dlc(cm, len, dlc) can_check_len8_dlc(cm, len, dlc, len)
+
/* helper to define static CAN controller features at device creation time */
static inline void can_set_static_ctrlmode(struct net_device *dev,
u32 static_mode)
{
struct can_priv *priv = netdev_priv(dev);
--
2.28.0
next prev parent reply other threads:[~2020-11-09 15:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 15:36 [PATCH v5 0/8] Introduce optional DLC element for Classic CAN Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 1/8] can: add optional DLC element to Classical CAN frame structure Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 2/8] can: rename get_can_dlc() macro with can_cc_dlc2len() Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 3/8] can: remove obsolete get_canfd_dlc() macro Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 4/8] can: replace can_dlc as variable/element for payload length Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 5/8] can: rename CAN FD related can_len2dlc and can_dlc2len helpers Oliver Hartkopp
2020-11-09 15:36 ` [PATCH v5 6/8] can: update documentation for DLC usage in Classical CAN Oliver Hartkopp
2020-11-09 15:36 ` Oliver Hartkopp [this message]
2020-11-09 15:36 ` [PATCH v5 8/8] can-dev: add len8_dlc support for various CAN USB adapters Oliver Hartkopp
2020-11-09 20:12 ` Marc Kleine-Budde
2020-11-10 6:55 ` Oliver Hartkopp
2020-11-10 7:46 ` Marc Kleine-Budde
2020-11-10 10:18 ` Oliver Hartkopp
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=20201109153657.17897-8-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).