aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-06-19 17:47:13 -0400
committerDavid S. Miller <davem@davemloft.net>2012-06-19 17:47:13 -0400
commit3879d4e3977329607a2a8042483140af3581b5c3 (patch)
treec9e8cd2b3a99ddc917bced812fa2265150d45c44 /include
parenta77f4b4acf5b77f038bc11d3ca9b3af6f0124015 (diff)
parentea53fe0c667ad3cae61d4d71d2be41908ac5c0a4 (diff)
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 'include')
-rw-r--r--include/linux/can.h59
-rw-r--r--include/linux/can/core.h4
-rw-r--r--include/linux/can/dev.h33
-rw-r--r--include/linux/can/raw.h3
-rw-r--r--include/linux/if_ether.h3
5 files changed, 85 insertions, 17 deletions
diff --git a/include/linux/can.h b/include/linux/can.h
index 17334c09bd9..1a66cf6112a 100644
--- a/include/linux/can.h
+++ b/include/linux/can.h
@@ -46,18 +46,67 @@ typedef __u32 canid_t;
46 */ 46 */
47typedef __u32 can_err_mask_t; 47typedef __u32 can_err_mask_t;
48 48
49/* CAN payload length and DLC definitions according to ISO 11898-1 */
50#define CAN_MAX_DLC 8
51#define CAN_MAX_DLEN 8
52
53/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
54#define CANFD_MAX_DLC 15
55#define CANFD_MAX_DLEN 64
56
49/** 57/**
50 * struct can_frame - basic CAN frame structure 58 * struct can_frame - basic CAN frame structure
51 * @can_id: the CAN ID of the frame and CAN_*_FLAG flags, see above. 59 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
52 * @can_dlc: the data length field of the CAN frame 60 * @can_dlc: frame payload length in byte (0 .. 8) aka data length code
53 * @data: the CAN frame payload. 61 * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1
62 * mapping of the 'data length code' to the real payload length
63 * @data: CAN frame payload (up to 8 byte)
54 */ 64 */
55struct can_frame { 65struct can_frame {
56 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 66 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
57 __u8 can_dlc; /* data length code: 0 .. 8 */ 67 __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
58 __u8 data[8] __attribute__((aligned(8))); 68 __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));
59}; 69};
60 70
71/*
72 * defined bits for canfd_frame.flags
73 *
74 * As the default for CAN FD should be to support the high data rate in the
75 * payload section of the frame (HDR) and to support up to 64 byte in the
76 * data section (EDL) the bits are only set in the non-default case.
77 * Btw. as long as there's no real implementation for CAN FD network driver
78 * these bits are only preliminary.
79 *
80 * RX: NOHDR/NOEDL - info about received CAN FD frame
81 * ESI - bit from originating CAN controller
82 * TX: NOHDR/NOEDL - control per-frame settings if supported by CAN controller
83 * ESI - bit is set by local CAN controller
84 */
85#define CANFD_NOHDR 0x01 /* frame without high data rate */
86#define CANFD_NOEDL 0x02 /* frame without extended data length */
87#define CANFD_ESI 0x04 /* error state indicator */
88
89/**
90 * struct canfd_frame - CAN flexible data rate frame structure
91 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
92 * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN)
93 * @flags: additional flags for CAN FD
94 * @__res0: reserved / padding
95 * @__res1: reserved / padding
96 * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte)
97 */
98struct canfd_frame {
99 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
100 __u8 len; /* frame payload length in byte */
101 __u8 flags; /* additional flags for CAN FD */
102 __u8 __res0; /* reserved / padding */
103 __u8 __res1; /* reserved / padding */
104 __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
105};
106
107#define CAN_MTU (sizeof(struct can_frame))
108#define CANFD_MTU (sizeof(struct canfd_frame))
109
61/* particular protocols of the protocol family PF_CAN */ 110/* particular protocols of the protocol family PF_CAN */
62#define CAN_RAW 1 /* RAW sockets */ 111#define CAN_RAW 1 /* RAW sockets */
63#define CAN_BCM 2 /* Broadcast Manager */ 112#define CAN_BCM 2 /* Broadcast Manager */
diff --git a/include/linux/can/core.h b/include/linux/can/core.h
index 0ccc1cd28b9..78c6c52073a 100644
--- a/include/linux/can/core.h
+++ b/include/linux/can/core.h
@@ -17,10 +17,10 @@
17#include <linux/skbuff.h> 17#include <linux/skbuff.h>
18#include <linux/netdevice.h> 18#include <linux/netdevice.h>
19 19
20#define CAN_VERSION "20090105" 20#define CAN_VERSION "20120528"
21 21
22/* increment this number each time you change some user-space interface */ 22/* increment this number each time you change some user-space interface */
23#define CAN_ABI_VERSION "8" 23#define CAN_ABI_VERSION "9"
24 24
25#define CAN_VERSION_STRING "rev " CAN_VERSION " abi " CAN_ABI_VERSION 25#define CAN_VERSION_STRING "rev " CAN_VERSION " abi " CAN_ABI_VERSION
26 26
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 5d2efe7e3f1..ee5a771fb20 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -61,23 +61,40 @@ struct can_priv {
61 * To be used in the CAN netdriver receive path to ensure conformance with 61 * To be used in the CAN netdriver receive path to ensure conformance with
62 * ISO 11898-1 Chapter 8.4.2.3 (DLC field) 62 * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
63 */ 63 */
64#define get_can_dlc(i) (min_t(__u8, (i), 8)) 64#define get_can_dlc(i) (min_t(__u8, (i), CAN_MAX_DLC))
65#define get_canfd_dlc(i) (min_t(__u8, (i), CANFD_MAX_DLC))
65 66
66/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ 67/* Drop a given socketbuffer if it does not contain a valid CAN frame. */
67static inline int can_dropped_invalid_skb(struct net_device *dev, 68static inline int can_dropped_invalid_skb(struct net_device *dev,
68 struct sk_buff *skb) 69 struct sk_buff *skb)
69{ 70{
70 const struct can_frame *cf = (struct can_frame *)skb->data; 71 const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
71 72
72 if (unlikely(skb->len != sizeof(*cf) || cf->can_dlc > 8)) { 73 if (skb->protocol == htons(ETH_P_CAN)) {
73 kfree_skb(skb); 74 if (unlikely(skb->len != CAN_MTU ||
74 dev->stats.tx_dropped++; 75 cfd->len > CAN_MAX_DLEN))
75 return 1; 76 goto inval_skb;
76 } 77 } else if (skb->protocol == htons(ETH_P_CANFD)) {
78 if (unlikely(skb->len != CANFD_MTU ||
79 cfd->len > CANFD_MAX_DLEN))
80 goto inval_skb;
81 } else
82 goto inval_skb;
77 83
78 return 0; 84 return 0;
85
86inval_skb:
87 kfree_skb(skb);
88 dev->stats.tx_dropped++;
89 return 1;
79} 90}
80 91
92/* get data length from can_dlc with sanitized can_dlc */
93u8 can_dlc2len(u8 can_dlc);
94
95/* map the sanitized data length to an appropriate data length code */
96u8 can_len2dlc(u8 len);
97
81struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max); 98struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
82void free_candev(struct net_device *dev); 99void free_candev(struct net_device *dev);
83 100
diff --git a/include/linux/can/raw.h b/include/linux/can/raw.h
index 781f3a3701b..a814062b071 100644
--- a/include/linux/can/raw.h
+++ b/include/linux/can/raw.h
@@ -23,7 +23,8 @@ enum {
23 CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s) */ 23 CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s) */
24 CAN_RAW_ERR_FILTER, /* set filter for error frames */ 24 CAN_RAW_ERR_FILTER, /* set filter for error frames */
25 CAN_RAW_LOOPBACK, /* local loopback (default:on) */ 25 CAN_RAW_LOOPBACK, /* local loopback (default:on) */
26 CAN_RAW_RECV_OWN_MSGS /* receive my own msgs (default:off) */ 26 CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */
27 CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */
27}; 28};
28 29
29#endif 30#endif
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index 56d907a2c80..167ce5b363d 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -105,7 +105,8 @@
105#define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/ 105#define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/
106#define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */ 106#define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */
107#define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */ 107#define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */
108#define ETH_P_CAN 0x000C /* Controller Area Network */ 108#define ETH_P_CAN 0x000C /* CAN: Controller Area Network */
109#define ETH_P_CANFD 0x000D /* CANFD: CAN flexible data rate*/
109#define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/ 110#define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/
110#define ETH_P_TR_802_2 0x0011 /* 802.2 frames */ 111#define ETH_P_TR_802_2 0x0011 /* 802.2 frames */
111#define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */ 112#define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */