summaryrefslogtreecommitdiffstats
path: root/drivers/net/can/dev.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-06-19 14:47:13 -0700
committerDavid S. Miller <davem@davemloft.net>2012-06-19 14:47:13 -0700
commit3879d4e3977329607a2a8042483140af3581b5c3 (patch)
treec9e8cd2b3a99ddc917bced812fa2265150d45c44 /drivers/net/can/dev.c
parenta77f4b4acf5b77f038bc11d3ca9b3af6f0124015 (diff)
parentea53fe0c667ad3cae61d4d71d2be41908ac5c0a4 (diff)
downloadlinux-3879d4e3977329607a2a8042483140af3581b5c3.tar.gz
linux-3879d4e3977329607a2a8042483140af3581b5c3.tar.bz2
linux-3879d4e3977329607a2a8042483140af3581b5c3.zip
Merge branch 'master' of git://gitorious.org/linux-can/linux-can-next
Marc Kleine-Budde says: ==================== here is our second pull request for net-next. In this series Federico Vaga adds a pci driver for c_can/d_can hardware using the existing generic c_can driver. The remaining 6 patches are by Oliver Hartkopp. He adds CANFD support to the CAN stack while keeping binary compatibility for existing applications. CANFD is an extension to the existing CAN standard, it allows longer CAN frames and/or higher data rates. There's no real hardware available yet, but this series adds CANFD support to the vcan driver. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/can/dev.c')
-rw-r--r--drivers/net/can/dev.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index f03d7a481a80..239e4dd92ca1 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -33,6 +33,39 @@ MODULE_DESCRIPTION(MOD_DESC);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
+/* 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 can_dlc with sanitized can_dlc */
+u8 can_dlc2len(u8 can_dlc)
+{
+ return dlc2len[can_dlc & 0x0F];
+}
+EXPORT_SYMBOL_GPL(can_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_len2dlc(u8 len)
+{
+ if (unlikely(len > 64))
+ return 0xF;
+
+ return len2dlc[len];
+}
+EXPORT_SYMBOL_GPL(can_len2dlc);
+
#ifdef CONFIG_CAN_CALC_BITTIMING
#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
@@ -454,7 +487,7 @@ EXPORT_SYMBOL_GPL(can_bus_off);
static void can_setup(struct net_device *dev)
{
dev->type = ARPHRD_CAN;
- dev->mtu = sizeof(struct can_frame);
+ dev->mtu = CAN_MTU;
dev->hard_header_len = 0;
dev->addr_len = 0;
dev->tx_queue_len = 10;