Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

can: drivers: introduce helpers to access Classical CAN DLC values

This patch adds the following helper to functions to access Classical CAN DLC
values.

can_get_cc_dlc(): get the data length code for Classical CAN raw DLC access
can_frame_set_cc_len(): set len and len8_dlc value for Classical CAN raw DLC access

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/r/20201110154913.1404582-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Oliver Hartkopp and committed by
Marc Kleine-Budde
e8e73562 75191707

+25
+25
include/linux/can/dev.h
··· 170 170 return skb->len == CANFD_MTU; 171 171 } 172 172 173 + /* helper to get the data length code (DLC) for Classical CAN raw DLC access */ 174 + static inline u8 can_get_cc_dlc(const struct can_frame *cf, const u32 ctrlmode) 175 + { 176 + /* return len8_dlc as dlc value only if all conditions apply */ 177 + if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) && 178 + (cf->len == CAN_MAX_DLEN) && 179 + (cf->len8_dlc > CAN_MAX_DLEN && cf->len8_dlc <= CAN_MAX_RAW_DLC)) 180 + return cf->len8_dlc; 181 + 182 + /* return the payload length as dlc value */ 183 + return cf->len; 184 + } 185 + 186 + /* helper to set len and len8_dlc value for Classical CAN raw DLC access */ 187 + static inline void can_frame_set_cc_len(struct can_frame *cf, const u8 dlc, 188 + const u32 ctrlmode) 189 + { 190 + /* the caller already ensured that dlc is a value from 0 .. 15 */ 191 + if (ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC && dlc > CAN_MAX_DLEN) 192 + cf->len8_dlc = dlc; 193 + 194 + /* limit the payload length 'len' to CAN_MAX_DLEN */ 195 + cf->len = can_cc_dlc2len(dlc); 196 + } 197 + 173 198 /* helper to define static CAN controller features at device creation time */ 174 199 static inline void can_set_static_ctrlmode(struct net_device *dev, 175 200 u32 static_mode)