Cc: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx> Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> --- drivers/net/can/dev.c | 21 +++++++++++++++++++++ include/linux/can/dev.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 68f37ac54327..fa81e3067b3b 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -60,6 +60,27 @@ u8 can_len2dlc(u8 len) } EXPORT_SYMBOL_GPL(can_len2dlc); +static const u8 len2dll_len[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ + 12, 12, 12, 12, /* 9 - 12 */ + 16, 16, 16, 16, /* 13 - 16 */ + 20, 20, 20, 20, /* 17 - 20 */ + 24, 24, 24, 24, /* 21 - 24 */ + 32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */ + 40, 40, 40, 40, 40, 40, 40, 40, /* 33 - 40 */ + 48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */ +}; + +/* map the sanitized data length to an appropriate data link layer length */ +u8 can_len2dll_len(u8 len) +{ + if (len > ARRAY_SIZE(len2dll_len)) + return CANFD_MAX_DLEN; + + return len2dll_len[len]; +} +EXPORT_SYMBOL_GPL(can_len2dll_len); + #ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 41ff31795320..27c359a00203 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -192,6 +192,9 @@ u8 can_dlc2len(u8 can_dlc); /* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc(u8 len); +/* map the sanitized data length to an appropriate data link layer length */ +u8 can_len2dll_len(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) \ -- 2.29.2