]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/include/socketcan/can/dev.h
Add modifiers for sampling-point and sjw to can_if start/stop script.
[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         u32 ctrlmode_supported;
48
49         int restart_ms;
50         struct timer_list restart_timer;
51
52         int (*do_set_bittiming)(struct net_device *dev);
53         int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
54         int (*do_get_state)(const struct net_device *dev,
55                             enum can_state *state);
56         int (*do_get_berr_counter)(const struct net_device *dev,
57                                    struct can_berr_counter *bec);
58
59         unsigned int echo_skb_max;
60         struct sk_buff **echo_skb;
61 };
62
63 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
64 #define ND2D(_ndev)     (_ndev->class_dev.dev)
65 #else
66 #define ND2D(_ndev)     (_ndev->dev.parent)
67 #endif
68
69 /*
70  * get_can_dlc(value) - helper macro to cast a given data length code (dlc)
71  * to __u8 and ensure the dlc value to be max. 8 bytes.
72  *
73  * To be used in the CAN netdriver receive path to ensure conformance with
74  * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
75  */
76 #define get_can_dlc(i)  (min_t(__u8, (i), 8))
77
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
79 #define IFF_ECHO IFF_LOOPBACK
80 #endif
81
82 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
83 struct net_device_stats *can_get_stats(struct net_device *dev);
84 #endif
85
86 /* Drop a given socketbuffer if it does not contain a valid CAN frame. */
87 static inline int can_dropped_invalid_skb(struct net_device *dev,
88                                           struct sk_buff *skb)
89 {
90         const struct can_frame *cf = (struct can_frame *)skb->data;
91
92         if (unlikely(skb->len != sizeof(*cf) || cf->can_dlc > 8)) {
93                 kfree_skb(skb);
94                 dev->stats.tx_dropped++;
95                 return 1;
96         }
97
98         return 0;
99 }
100
101 struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
102 void free_candev(struct net_device *dev);
103
104 int open_candev(struct net_device *dev);
105 void close_candev(struct net_device *dev);
106
107 int register_candev(struct net_device *dev);
108 void unregister_candev(struct net_device *dev);
109
110 int can_restart_now(struct net_device *dev);
111 void can_bus_off(struct net_device *dev);
112
113 void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
114                       unsigned int idx);
115 void can_get_echo_skb(struct net_device *dev, unsigned int idx);
116 void can_free_echo_skb(struct net_device *dev, unsigned int idx);
117
118 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf);
119 struct sk_buff *alloc_can_err_skb(struct net_device *dev,
120                                   struct can_frame **cf);
121
122 #endif /* CAN_DEV_H */