]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/include/socketcan/can/dev.h
4e6da7f6cf2627a1dc12f32fb9a3b84879e25233
[socketcan-devel.git] / kernel / 2.6 / include / socketcan / can / dev.h
1 /*
2  * socketcan/can/dev.h
3  *
4  * Definitions for the CAN network device driver interface
5  *
6  * $Id$
7  *
8  * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
9  *               Varma Electronics Oy
10  *
11  * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
12  *
13  * Send feedback to <socketcan-users@lists.berlios.de>
14  */
15
16 #ifndef CAN_DEV_H
17 #define CAN_DEV_H
18
19 #include <linux/version.h>
20 #include <socketcan/can/netlink.h>
21 #include <socketcan/can/error.h>
22
23 /*
24  * CAN mode
25  */
26 enum can_mode {
27         CAN_MODE_STOP = 0,
28         CAN_MODE_START,
29         CAN_MODE_SLEEP
30 };
31
32 /*
33  * CAN common private data
34  */
35 struct can_priv {
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
37         struct net_device_stats net_stats;
38 #endif
39         struct can_device_stats can_stats;
40
41         struct can_bittiming bittiming;
42         struct can_bittiming_const *bittiming_const;
43         struct can_clock clock;
44
45         enum can_state state;
46         u32 ctrlmode;
47
48         int restart_ms;
49         struct timer_list restart_timer;
50
51         int (*do_set_bittiming)(struct net_device *dev);
52         int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
53         int (*do_get_state)(const struct net_device *dev,
54                             enum can_state *state);
55
56         unsigned int echo_skb_max;
57         struct sk_buff **echo_skb;
58 };
59
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
61 #define ND2D(_ndev)     (_ndev->class_dev.dev)
62 #else
63 #define ND2D(_ndev)     (_ndev->dev.parent)
64 #endif
65
66 /*
67  * get_can_dlc(value) - helper macro to cast a given data length code (dlc)
68  * to __u8 and ensure the dlc value to be max. 8 bytes.
69  *
70  * To be used in the CAN netdriver receive path to ensure conformance with
71  * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
72  */
73 #define get_can_dlc(i)  (min_t(__u8, (i), 8))
74
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
76 #define IFF_ECHO IFF_LOOPBACK
77 #endif
78
79 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
80 struct net_device_stats *can_get_stats(struct net_device *dev);
81 #endif
82
83 /* Drop a given socketbuffer if it does not contain a valid CAN frame. */
84 static inline int can_dropped_invalid_skb(struct net_device *dev,
85                                           struct sk_buff *skb)
86 {
87         const struct can_frame *cf = (struct can_frame *)skb->data;
88
89         if (unlikely(skb->len != sizeof(*cf) || cf->can_dlc > 8)) {
90                 kfree_skb(skb);
91                 dev->stats.tx_dropped++;
92                 return 1;
93         }
94
95         return 0;
96 }
97
98 struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
99 void free_candev(struct net_device *dev);
100
101 int open_candev(struct net_device *dev);
102 void close_candev(struct net_device *dev);
103
104 int register_candev(struct net_device *dev);
105 void unregister_candev(struct net_device *dev);
106
107 int can_restart_now(struct net_device *dev);
108 void can_bus_off(struct net_device *dev);
109
110 void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
111                       unsigned int idx);
112 void can_get_echo_skb(struct net_device *dev, unsigned int idx);
113 void can_free_echo_skb(struct net_device *dev, unsigned int idx);
114
115 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf);
116 struct sk_buff *alloc_can_err_skb(struct net_device *dev,
117                                   struct can_frame **cf);
118
119 #endif /* CAN_DEV_H */