Re: [net-next 04/13] can: dev: move length related code into seperate file
- From
- Marc Kleine-Budde <mkl@pengutronix.de>
- Date
- 2021-01-11 09:59:36
- Reply to
- Oliver Hartkopp, 2021-01-11
On 1/11/21 9:49 AM, Oliver Hartkopp wrote:
quoted
diff --git a/drivers/net/can/dev/length.c b/drivers/net/can/dev/length.c new file mode 100644 index 000000000000..540d40dc0bc2 --- /dev/null +++ b/drivers/net/can/dev/length.c@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2005 Marc Kleine-Budde, Pengutronix + * Copyright (C) 2006 Andrey Volkov, Varma Electronics + * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com> + */See comment below ...quoted
+ +#include <linux/can/dev.h> + +/* CAN DLC to real data length conversion helpers */ + +static const u8 dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7, + 8, 12, 16, 20, 24, 32, 48, 64}; + +/* get data length from raw data length code (DLC) */ +u8 can_fd_dlc2len(u8 dlc) +{ + return dlc2len[dlc & 0x0F]; +} +EXPORT_SYMBOL_GPL(can_fd_dlc2len); + +static const u8 len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ + 9, 9, 9, 9, /* 9 - 12 */ + 10, 10, 10, 10, /* 13 - 16 */ + 11, 11, 11, 11, /* 17 - 20 */ + 12, 12, 12, 12, /* 21 - 24 */ + 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */ + 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */ + 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */ + 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */ + 15, 15, 15, 15, 15, 15, 15, 15}; /* 57 - 64 */ + +/* map the sanitized data length to an appropriate data length code */ +u8 can_fd_len2dlc(u8 len) +{ + if (unlikely(len > 64)) + return 0xF; + + return len2dlc[len]; +} +EXPORT_SYMBOL_GPL(can_fd_len2dlc);diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 054c3bed190b..d75fba1d030a 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h@@ -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 {(..)quoted
diff --git a/include/linux/can/length.h b/include/linux/can/length.h new file mode 100644 index 000000000000..fabd93bcde3e --- /dev/null +++ b/include/linux/can/length.h@@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com> + * Varma Electronics Oy + * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>The CAN FD and len8_dlc length stuff was completely contributed by myself. So if this code is now moved to a separate file the former Copyrights should be replaced with Copyright (C) 2020 Oliver Hartkopp [off-list ref]
Ok. I carried the copyrights from the files I move the from forward to the new file. For dev.c -> length.c the code was added with:
commit 1e0625facab2e871472472b7df87d8fbe6caf75a
Author: Oliver Hartkopp [off-list ref]
Date: Wed Jun 13 20:48:21 2012 +0200
candev: add/update helpers for CAN FD
- update sanity checks
- add DLC to length conversion helpers
- can_dlc2len() - get data length from can_dlc with sanitized can_dlc
- can_len2dlc() - map the sanitized data length to an appropriate DLC
Signed-off-by: Oliver Hartkopp [off-list ref]
Signed-off-by: Marc Kleine-Budde [off-list ref]and then updated with:
commit c7b74967799b1af52b3045d69d4c26836b2d41de
Author: Oliver Hartkopp [off-list ref]
Date: Fri Nov 20 11:04:44 2020 +0100
can: replace can_dlc as variable/element for payload length
The naming of can_dlc as element of struct can_frame and also as variable
name is misleading as it claims to be a 'data length CODE' but in reality
it always was a plain data length.
With the indroduction of a new 'len' element in struct can_frame we can now
remove can_dlc as name and make clear which of the former uses was a plain
length (-> 'len') or a data length code (-> 'dlc') value.
Signed-off-by: Oliver Hartkopp [off-list ref]
Link: https://lore.kernel.org/r/20201120100444.3199-1-socketcan@hartkopp.net (local)
[mkl: gs_usb: keep struct gs_host_frame::can_dlc as is]
Signed-off-by: Marc Kleine-Budde [off-list ref]commit 3ab4ce0d6fa8c93d41df4a74ec8d2c9198be2109
Author: Oliver Hartkopp [off-list ref]
Date: Tue Nov 10 11:18:49 2020 +0100
can: rename CAN FD related can_len2dlc and can_dlc2len helpers
The helper functions can_len2dlc and can_dlc2len are only relevant for
CAN FD data length code (DLC) conversion.
To fit the introduced can_cc_dlc2len for Classical CAN we rename:
can_dlc2len -> can_fd_dlc2len to get the payload length from the DLC
can_len2dlc -> can_fd_len2dlc to get the DLC from the payload length
Suggested-by: Vincent Mailhol [off-list ref]
Signed-off-by: Oliver Hartkopp [off-list ref]
Link: https://lore.kernel.org/r/20201110101852.1973-6-socketcan@hartkopp.net (local)
Signed-off-by: Marc Kleine-Budde [off-list ref]So I'll make copyright: Copyright (C) 2012, 2020 Oliver Hartkopp [off-list ref] The changes in dev.h -> length.h were in 2020 only, using that year only. regards. Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Attachments
- signature.asc [application/pgp-signature] 488 bytes