4 * Definitions for the CAN network device driver interface
8 * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
11 * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
13 * Send feedback to <socketcan-users@lists.berlios.de>
19 #include <linux/version.h>
20 #include <socketcan/can/netlink.h>
21 #include <socketcan/can/error.h>
33 * CAN common private data
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
37 struct net_device_stats net_stats;
39 struct can_device_stats can_stats;
41 struct can_bittiming bittiming;
42 struct can_bittiming_const *bittiming_const;
43 struct can_clock clock;
49 struct timer_list restart_timer;
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);
56 unsigned int echo_skb_max;
57 struct sk_buff **echo_skb;
60 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
61 #define ND2D(_ndev) (_ndev->class_dev.dev)
63 #define ND2D(_ndev) (_ndev->dev.parent)
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.
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)
73 #define get_can_dlc(i) (min_t(__u8, (i), 8))
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
76 #define IFF_ECHO IFF_LOOPBACK
79 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
80 struct net_device_stats *can_get_stats(struct net_device *dev);
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,
87 const struct can_frame *cf = (struct can_frame *)skb->data;
89 if (unlikely(skb->len != sizeof(*cf) || cf->can_dlc > 8)) {
91 dev->stats.tx_dropped++;
98 struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
99 void free_candev(struct net_device *dev);
101 int open_candev(struct net_device *dev);
102 void close_candev(struct net_device *dev);
104 int register_candev(struct net_device *dev);
105 void unregister_candev(struct net_device *dev);
107 int can_restart_now(struct net_device *dev);
108 void can_bus_off(struct net_device *dev);
110 void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
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);
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);
119 #endif /* CAN_DEV_H */