can: dev: move length related code into seperate file
This patch moves all CAN frame length related code of the CAN device infrastructure into a separate file. Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Link: https://lore.kernel.org/r/20210111141930.693847-5-mkl@pengutronix.de Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <linux/can/bittiming.h>
|
||||
#include <linux/can/error.h>
|
||||
#include <linux/can/led.h>
|
||||
#include <linux/can/length.h>
|
||||
#include <linux/can/netlink.h>
|
||||
#include <linux/can/skb.h>
|
||||
#include <linux/netdevice.h>
|
||||
@@ -83,15 +84,6 @@ struct can_priv {
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* can_cc_dlc2len(value) - convert a given data length code (dlc) of a
|
||||
* Classical CAN frame into a valid data length of max. 8 bytes.
|
||||
*
|
||||
* To be used in the CAN netdriver receive path to ensure conformance with
|
||||
* ISO 11898-1 Chapter 8.4.2.3 (DLC field)
|
||||
*/
|
||||
#define can_cc_dlc2len(dlc) (min_t(u8, (dlc), CAN_MAX_DLEN))
|
||||
|
||||
/* Check for outgoing skbs that have not been created by the CAN subsystem */
|
||||
static inline bool can_skb_headroom_valid(struct net_device *dev,
|
||||
struct sk_buff *skb)
|
||||
@@ -156,31 +148,6 @@ static inline bool can_is_canfd_skb(const struct sk_buff *skb)
|
||||
return skb->len == CANFD_MTU;
|
||||
}
|
||||
|
||||
/* helper to get the data length code (DLC) for Classical CAN raw DLC access */
|
||||
static inline u8 can_get_cc_dlc(const struct can_frame *cf, const u32 ctrlmode)
|
||||
{
|
||||
/* return len8_dlc as dlc value only if all conditions apply */
|
||||
if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) &&
|
||||
(cf->len == CAN_MAX_DLEN) &&
|
||||
(cf->len8_dlc > CAN_MAX_DLEN && cf->len8_dlc <= CAN_MAX_RAW_DLC))
|
||||
return cf->len8_dlc;
|
||||
|
||||
/* return the payload length as dlc value */
|
||||
return cf->len;
|
||||
}
|
||||
|
||||
/* helper to set len and len8_dlc value for Classical CAN raw DLC access */
|
||||
static inline void can_frame_set_cc_len(struct can_frame *cf, const u8 dlc,
|
||||
const u32 ctrlmode)
|
||||
{
|
||||
/* the caller already ensured that dlc is a value from 0 .. 15 */
|
||||
if (ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC && dlc > CAN_MAX_DLEN)
|
||||
cf->len8_dlc = dlc;
|
||||
|
||||
/* limit the payload length 'len' to CAN_MAX_DLEN */
|
||||
cf->len = can_cc_dlc2len(dlc);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
@@ -196,12 +163,6 @@ static inline void can_set_static_ctrlmode(struct net_device *dev,
|
||||
dev->mtu = CANFD_MTU;
|
||||
}
|
||||
|
||||
/* get data length from raw data length code (DLC) */
|
||||
u8 can_fd_dlc2len(u8 dlc);
|
||||
|
||||
/* map the sanitized data length to an appropriate data length code */
|
||||
u8 can_fd_len2dlc(u8 len);
|
||||
|
||||
struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
|
||||
unsigned int txqs, unsigned int rxqs);
|
||||
#define alloc_candev(sizeof_priv, echo_skb_max) \
|
||||
|
||||
Reference in New Issue
Block a user