]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - patch-series/net-2.6.29/03-dev-interface.patch
Added missing inclusion of linux/types.h
[socketcan-devel.git] / patch-series / net-2.6.29 / 03-dev-interface.patch
1 [PATCH 3/9] Socket-CAN: add network device driver interface
2
3 The CAN network device driver interface provides a generic interface to
4 setup, configure and monitor CAN network devices. It exports a set of
5 common data structures and functions, which all real CAN network device
6 drivers should use. Please have a look to the SJA1000 or MSCAN driver
7 to understand how to use them. The name of the module is can-dev.ko.
8
9 For further information please check "Documentation/networking/can.txt"
10 provided by the first patch of this series.
11
12 Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
13 ---
14  drivers/net/can/Kconfig  |   23 ++
15  drivers/net/can/Makefile |    5 
16  drivers/net/can/dev.c    |  523 +++++++++++++++++++++++++++++++++++++++++++++++
17  include/linux/can/dev.h  |  136 ++++++++++++
18  4 files changed, 687 insertions(+)
19
20 Index: net-next-2.6/drivers/net/can/Makefile
21 ===================================================================
22 --- net-next-2.6.orig/drivers/net/can/Makefile
23 +++ net-next-2.6/drivers/net/can/Makefile
24 @@ -3,3 +3,8 @@
25  #
26  
27  obj-$(CONFIG_CAN_VCAN)         += vcan.o
28 +
29 +obj-$(CONFIG_CAN_DEV)          += can-dev.o
30 +can-dev-y                      := dev.o
31 +
32 +ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
33 Index: net-next-2.6/drivers/net/can/dev.c
34 ===================================================================
35 --- /dev/null
36 +++ net-next-2.6/drivers/net/can/dev.c
37 @@ -0,0 +1,523 @@
38 +/*
39 + * Copyright (C) 2005 Marc Kleine-Budde, Pengutronix
40 + * Copyright (C) 2006 Andrey Volkov, Varma Electronics
41 + * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
42 + *
43 + * This program is free software; you can redistribute it and/or modify
44 + * it under the terms of the version 2 of the GNU General Public License
45 + * as published by the Free Software Foundation
46 + *
47 + * This program is distributed in the hope that it will be useful,
48 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 + * GNU General Public License for more details.
51 + *
52 + * You should have received a copy of the GNU General Public License
53 + * along with this program; if not, write to the Free Software
54 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
55 + */
56 +
57 +#include <linux/module.h>
58 +#include <linux/netdevice.h>
59 +#include <linux/if_arp.h>
60 +#include <linux/can.h>
61 +#include <linux/can/dev.h>
62 +#include <net/rtnetlink.h>
63 +
64 +#define MOD_DESC "CAN device driver interface"
65 +
66 +MODULE_DESCRIPTION(MOD_DESC);
67 +MODULE_LICENSE("GPL v2");
68 +MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
69 +
70 +#ifdef CONFIG_CAN_CALC_BITTIMING
71 +#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
72 +
73 +/*
74 + * Bit-timing calculation derived from:
75 + *
76 + * Code based on LinCAN sources and H8S2638 project
77 + * Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz
78 + * Copyright 2005      Stanislav Marek
79 + * email: pisa@cmp.felk.cvut.cz
80 + */
81 +static int can_update_spt(const struct can_bittiming_const *btc,
82 +                         int sampl_pt, int tseg, int *tseg1, int *tseg2)
83 +{
84 +       *tseg2 = tseg + 1 - (sampl_pt * (tseg + 1)) / 1000;
85 +       if (*tseg2 < btc->tseg2_min)
86 +               *tseg2 = btc->tseg2_min;
87 +       if (*tseg2 > btc->tseg2_max)
88 +               *tseg2 = btc->tseg2_max;
89 +       *tseg1 = tseg - *tseg2;
90 +       if (*tseg1 > btc->tseg1_max) {
91 +               *tseg1 = btc->tseg1_max;
92 +               *tseg2 = tseg - *tseg1;
93 +       }
94 +       return 1000 * (tseg + 1 - *tseg2) / (tseg + 1);
95 +}
96 +
97 +static int can_calc_bittiming(struct net_device *dev)
98 +{
99 +       struct can_priv *priv = netdev_priv(dev);
100 +       struct can_bittiming *bt = &priv->bittiming;
101 +       const struct can_bittiming_const *btc = priv->bittiming_const;
102 +       long rate, best_rate = 0;
103 +       long best_error = 1000000000, error = 0;
104 +       int best_tseg = 0, best_brp = 0, brp = 0;
105 +       int tsegall, tseg = 0, tseg1 = 0, tseg2 = 0;
106 +       int spt_error = 1000, spt = 0, sampl_pt;
107 +       uint64_t v64;
108 +
109 +       if (!priv->bittiming_const)
110 +               return -ENOTSUPP;
111 +
112 +       /* Use CIA recommended sample points */
113 +       if (bt->sample_point) {
114 +               sampl_pt = bt->sample_point;
115 +       } else {
116 +               if (bt->bitrate > 800000)
117 +                       sampl_pt = 750;
118 +               else if (bt->bitrate > 500000)
119 +                       sampl_pt = 800;
120 +               else
121 +                       sampl_pt = 875;
122 +       }
123 +
124 +       /* tseg even = round down, odd = round up */
125 +       for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
126 +            tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) {
127 +               tsegall = 1 + tseg / 2;
128 +               /* Compute all possible tseg choices (tseg=tseg1+tseg2) */
129 +               brp = bt->clock / (tsegall * bt->bitrate) + tseg % 2;
130 +               /* chose brp step which is possible in system */
131 +               brp = (brp / btc->brp_inc) * btc->brp_inc;
132 +               if ((brp < btc->brp_min) || (brp > btc->brp_max))
133 +                       continue;
134 +               rate = bt->clock / (brp * tsegall);
135 +               error = bt->bitrate - rate;
136 +               /* tseg brp biterror */
137 +               if (error < 0)
138 +                       error = -error;
139 +               if (error > best_error)
140 +                       continue;
141 +               best_error = error;
142 +               if (error == 0) {
143 +                       spt = can_update_spt(btc, sampl_pt, tseg / 2,
144 +                                            &tseg1, &tseg2);
145 +                       error = sampl_pt - spt;
146 +                       if (error < 0)
147 +                               error = -error;
148 +                       if (error > spt_error)
149 +                               continue;
150 +                       spt_error = error;
151 +               }
152 +               best_tseg = tseg / 2;
153 +               best_brp = brp;
154 +               best_rate = rate;
155 +               if (error == 0)
156 +                       break;
157 +       }
158 +
159 +       if (best_error) {
160 +               /* Error in one-tenth of a percent */
161 +               error = (best_error * 1000) / bt->bitrate;
162 +               if (error > CAN_CALC_MAX_ERROR) {
163 +                       dev_err(ND2D(dev), "bitrate error %ld.%ld%% too high\n",
164 +                               error / 10, error % 10);
165 +                       return -EDOM;
166 +               } else {
167 +                       dev_warn(ND2D(dev), "bitrate error %ld.%ld%%\n",
168 +                                error / 10, error % 10);
169 +               }
170 +       }
171 +
172 +       spt = can_update_spt(btc, sampl_pt, best_tseg, &tseg1, &tseg2);
173 +
174 +       v64 = (u64)best_brp * 1000000000UL;
175 +       do_div(v64, bt->clock);
176 +       bt->tq = (u32)v64;
177 +       bt->prop_seg = tseg1 / 2;
178 +       bt->phase_seg1 = tseg1 - bt->prop_seg;
179 +       bt->phase_seg2 = tseg2;
180 +       bt->sjw = 1;
181 +       bt->brp = best_brp;
182 +
183 +       return 0;
184 +}
185 +#else /* !CONFIG_CAN_CALC_BITTIMING */
186 +static int can_calc_bittiming(struct net_device *dev)
187 +{
188 +       dev_err(ND2D(dev), "bit-timing calculation not available\n");
189 +       return -EINVAL;
190 +}
191 +#endif /* CONFIG_CAN_CALC_BITTIMING */
192 +
193 +int can_sample_point(struct can_bittiming *bt)
194 +{
195 +       return ((bt->prop_seg + bt->phase_seg1 + 1) * 1000) /
196 +               (bt->prop_seg + bt->phase_seg1 + bt->phase_seg2 + 1);
197 +}
198 +
199 +int can_fixup_bittiming(struct net_device *dev)
200 +{
201 +       struct can_priv *priv = netdev_priv(dev);
202 +       struct can_bittiming *bt = &priv->bittiming;
203 +       const struct can_bittiming_const *btc = priv->bittiming_const;
204 +       int tseg1, alltseg;
205 +       u32 bitrate;
206 +       u64 brp64;
207 +
208 +       if (!priv->bittiming_const)
209 +               return -ENOTSUPP;
210 +
211 +       tseg1 = bt->prop_seg + bt->phase_seg1;
212 +       if (bt->sjw > btc->sjw_max ||
213 +           tseg1 < btc->tseg1_min || tseg1 > btc->tseg1_max ||
214 +           bt->phase_seg2 < btc->tseg2_min || bt->phase_seg2 > btc->tseg2_max)
215 +               return -EINVAL;
216 +
217 +       brp64 = (u64)bt->clock * (u64)bt->tq;
218 +       if (btc->brp_inc > 1)
219 +               do_div(brp64, btc->brp_inc);
220 +       brp64 += 500000000UL - 1;
221 +       do_div(brp64, 1000000000UL); /* the practicable BRP */
222 +       if (btc->brp_inc > 1)
223 +               brp64 *= btc->brp_inc;
224 +       bt->brp = (u32)brp64;
225 +
226 +       if (bt->brp < btc->brp_min || bt->brp > btc->brp_max)
227 +               return -EINVAL;
228 +
229 +       alltseg = bt->prop_seg + bt->phase_seg1 + bt->phase_seg2 + 1;
230 +       bitrate = bt->clock / (bt->brp * alltseg);
231 +       bt->bitrate = bitrate;
232 +
233 +       return 0;
234 +}
235 +
236 +/*
237 + * Set CAN bit-timing for the device
238 + *
239 + * This functions should be called in the open function of the device
240 + * driver to determine, check and set appropriate bit-timing parameters.
241 + */
242 +int can_set_bittiming(struct net_device *dev)
243 +{
244 +       struct can_priv *priv = netdev_priv(dev);
245 +       int err;
246 +
247 +       /* Check if bit-timing parameters have been pre-defined */
248 +       if (!priv->bittiming.tq && !priv->bittiming.bitrate) {
249 +               dev_err(ND2D(dev), "bit-timing not yet defined\n");
250 +               return -EINVAL;
251 +       }
252 +
253 +       /* Check if the CAN device has bit-timing parameters */
254 +       if (priv->bittiming_const) {
255 +
256 +               /* Check if bit-timing parameters have already been set */
257 +               if (priv->bittiming.tq && priv->bittiming.bitrate)
258 +                       return 0;
259 +
260 +               /* Non-expert mode? Check if the bitrate has been pre-defined */
261 +               if (!priv->bittiming.tq)
262 +                       /* Determine bit-timing parameters */
263 +                       err = can_calc_bittiming(dev);
264 +               else
265 +                       /* Check bit-timing params and calculate proper brp */
266 +                       err = can_fixup_bittiming(dev);
267 +               if (err)
268 +                       return err;
269 +       }
270 +
271 +       if (priv->do_set_bittiming) {
272 +               /* Finally, set the bit-timing registers */
273 +               err = priv->do_set_bittiming(dev);
274 +               if (err)
275 +                       return err;
276 +       }
277 +
278 +       return 0;
279 +}
280 +EXPORT_SYMBOL(can_set_bittiming);
281 +
282 +static void can_setup(struct net_device *dev)
283 +{
284 +       dev->type = ARPHRD_CAN;
285 +       dev->mtu = sizeof(struct can_frame);
286 +       dev->hard_header_len = 0;
287 +       dev->addr_len = 0;
288 +       dev->tx_queue_len = 10;
289 +
290 +       /* New-style flags. */
291 +       dev->flags = IFF_NOARP;
292 +       dev->features = NETIF_F_NO_CSUM;
293 +}
294 +
295 +/*
296 + * Allocate and setup space for the CAN network device
297 + */
298 +struct net_device *alloc_candev(int sizeof_priv)
299 +{
300 +       struct net_device *dev;
301 +       struct can_priv *priv;
302 +
303 +       dev = alloc_netdev(sizeof_priv, "can%d", can_setup);
304 +       if (!dev)
305 +               return NULL;
306 +
307 +       priv = netdev_priv(dev);
308 +
309 +       priv->state = CAN_STATE_STOPPED;
310 +       spin_lock_init(&priv->irq_lock);
311 +
312 +       init_timer(&priv->timer);
313 +       priv->timer.expires = 0;
314 +
315 +       return dev;
316 +}
317 +EXPORT_SYMBOL(alloc_candev);
318 +
319 +/*
320 + * Allocate space of the CAN network device
321 + */
322 +void free_candev(struct net_device *dev)
323 +{
324 +       free_netdev(dev);
325 +}
326 +EXPORT_SYMBOL(free_candev);
327 +
328 +/*
329 + * Register the CAN network device
330 + */
331 +int register_candev(struct net_device *dev)
332 +{
333 +       int err;
334 +
335 +       err = register_netdev(dev);
336 +       if (err)
337 +               return err;
338 +
339 +       return 0;
340 +}
341 +EXPORT_SYMBOL(register_candev);
342 +
343 +/*
344 + * Unregister the CAN network device
345 + */
346 +void unregister_candev(struct net_device *dev)
347 +{
348 +       unregister_netdev(dev);
349 +}
350 +EXPORT_SYMBOL(unregister_candev);
351 +
352 +/*
353 + * Local echo of CAN messages
354 + *
355 + * CAN network devices *should* support a local echo functionality
356 + * (see Documentation/networking/can.txt). To test the handling of CAN
357 + * interfaces that do not support the local echo both driver types are
358 + * implemented. In the case that the driver does not support the echo
359 + * the IFF_ECHO remains clear in dev->flags. This causes the PF_CAN core
360 + * to perform the echo as a fallback solution.
361 + */
362 +
363 +void can_flush_echo_skb(struct net_device *dev)
364 +{
365 +       struct can_priv *priv = netdev_priv(dev);
366 +       struct net_device_stats *stats = &dev->stats;
367 +       int i;
368 +
369 +       for (i = 0; i < CAN_ECHO_SKB_MAX; i++) {
370 +               if (priv->echo_skb[i]) {
371 +                       kfree_skb(priv->echo_skb[i]);
372 +                       priv->echo_skb[i] = NULL;
373 +                       stats->tx_dropped++;
374 +                       stats->tx_aborted_errors++;
375 +               }
376 +       }
377 +}
378 +
379 +/*
380 + * Put the skb on the stack to be looped backed locally lateron
381 + *
382 + * The function is typically called in the start_xmit function
383 + * of the device driver.
384 + */
385 +void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, int idx)
386 +{
387 +       struct can_priv *priv = netdev_priv(dev);
388 +
389 +       /* set flag whether this packet has to be looped back */
390 +       if (!(dev->flags & IFF_ECHO) || skb->pkt_type != PACKET_LOOPBACK) {
391 +               kfree_skb(skb);
392 +               return;
393 +       }
394 +
395 +       if (!priv->echo_skb[idx]) {
396 +               struct sock *srcsk = skb->sk;
397 +
398 +               if (atomic_read(&skb->users) != 1) {
399 +                       struct sk_buff *old_skb = skb;
400 +
401 +                       skb = skb_clone(old_skb, GFP_ATOMIC);
402 +                       kfree_skb(old_skb);
403 +                       if (!skb)
404 +                               return;
405 +               } else
406 +                       skb_orphan(skb);
407 +
408 +               skb->sk = srcsk;
409 +
410 +               /* make settings for echo to reduce code in irq context */
411 +               skb->protocol = htons(ETH_P_CAN);
412 +               skb->pkt_type = PACKET_BROADCAST;
413 +               skb->ip_summed = CHECKSUM_UNNECESSARY;
414 +               skb->dev = dev;
415 +
416 +               /* save this skb for tx interrupt echo handling */
417 +               priv->echo_skb[idx] = skb;
418 +       } else {
419 +               /* locking problem with netif_stop_queue() ?? */
420 +               printk(KERN_ERR "%s: %s: BUG! echo_skb is occupied!\n",
421 +                      dev->name, __func__);
422 +               kfree_skb(skb);
423 +       }
424 +}
425 +EXPORT_SYMBOL(can_put_echo_skb);
426 +
427 +/*
428 + * Get the skb from the stack and loop it back locally
429 + *
430 + * The function is typically called when the TX done interrupt
431 + * is handled in the device driver.
432 + */
433 +void can_get_echo_skb(struct net_device *dev, int idx)
434 +{
435 +       struct can_priv *priv = netdev_priv(dev);
436 +
437 +       if ((dev->flags & IFF_ECHO) && priv->echo_skb[idx]) {
438 +               netif_rx(priv->echo_skb[idx]);
439 +               priv->echo_skb[idx] = NULL;
440 +       }
441 +}
442 +EXPORT_SYMBOL(can_get_echo_skb);
443 +
444 +/*
445 + * CAN device restart for bus-off recovery
446 + */
447 +int can_restart_now(struct net_device *dev)
448 +{
449 +       struct can_priv *priv = netdev_priv(dev);
450 +       struct net_device_stats *stats = &dev->stats;
451 +       struct sk_buff *skb;
452 +       struct can_frame *cf;
453 +       int err;
454 +
455 +       if (netif_carrier_ok(dev))
456 +               netif_carrier_off(dev);
457 +
458 +       /* Cancel restart in progress */
459 +       if (priv->timer.expires) {
460 +               del_timer(&priv->timer);
461 +               priv->timer.expires = 0; /* mark inactive timer */
462 +       }
463 +
464 +       can_flush_echo_skb(dev);
465 +
466 +       err = priv->do_set_mode(dev, CAN_MODE_START);
467 +       if (err)
468 +               return err;
469 +
470 +       netif_carrier_on(dev);
471 +
472 +       dev_dbg(ND2D(dev), "restarted\n");
473 +       priv->can_stats.restarts++;
474 +
475 +       /* send restart message upstream */
476 +       skb = dev_alloc_skb(sizeof(struct can_frame));
477 +       if (skb == NULL)
478 +               return -ENOMEM;
479 +       skb->dev = dev;
480 +       skb->protocol = htons(ETH_P_CAN);
481 +       cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
482 +       memset(cf, 0, sizeof(struct can_frame));
483 +       cf->can_id = CAN_ERR_FLAG | CAN_ERR_RESTARTED;
484 +       cf->can_dlc = CAN_ERR_DLC;
485 +
486 +       netif_rx(skb);
487 +
488 +       dev->last_rx = jiffies;
489 +       stats->rx_packets++;
490 +       stats->rx_bytes += cf->can_dlc;
491 +
492 +       return 0;
493 +}
494 +
495 +static void can_restart_after(unsigned long data)
496 +{
497 +       struct net_device *dev = (struct net_device *)data;
498 +       struct can_priv *priv = netdev_priv(dev);
499 +
500 +       priv->timer.expires = 0; /* mark inactive timer */
501 +       can_restart_now(dev);
502 +}
503 +
504 +/*
505 + * CAN bus-off
506 + *
507 + * This functions should be called when the device goes bus-off to
508 + * tell the netif layer that no more packets can be sent or received.
509 + * If enabled, a timer is started to trigger bus-off recovery.
510 + */
511 +void can_bus_off(struct net_device *dev)
512 +{
513 +       struct can_priv *priv = netdev_priv(dev);
514 +
515 +       dev_dbg(ND2D(dev), "bus-off\n");
516 +
517 +       netif_carrier_off(dev);
518 +
519 +       if (priv->restart_ms > 0 && !priv->timer.expires) {
520 +
521 +               priv->timer.function = can_restart_after;
522 +               priv->timer.data = (unsigned long)dev;
523 +               priv->timer.expires =
524 +                       jiffies + (priv->restart_ms * HZ) / 1000;
525 +               add_timer(&priv->timer);
526 +       }
527 +}
528 +EXPORT_SYMBOL(can_bus_off);
529 +
530 +/*
531 + * Cleanup function before the device gets closed.
532 + *
533 + * This functions should be called in the close function of the device
534 + * driver.
535 + */
536 +void can_close_cleanup(struct net_device *dev)
537 +{
538 +       struct can_priv *priv = netdev_priv(dev);
539 +
540 +       if (priv->timer.expires) {
541 +               del_timer(&priv->timer);
542 +               priv->timer.expires = 0;
543 +       }
544 +
545 +       can_flush_echo_skb(dev);
546 +}
547 +EXPORT_SYMBOL(can_close_cleanup);
548 +
549 +static __init int can_dev_init(void)
550 +{
551 +       printk(KERN_INFO MOD_DESC "\n");
552 +
553 +       return 0;
554 +}
555 +module_init(can_dev_init);
556 +
557 +static __exit void can_dev_exit(void)
558 +{
559 +}
560 +module_exit(can_dev_exit);
561 Index: net-next-2.6/include/linux/can/dev.h
562 ===================================================================
563 --- /dev/null
564 +++ net-next-2.6/include/linux/can/dev.h
565 @@ -0,0 +1,136 @@
566 +/*
567 + * linux/can/dev.h
568 + *
569 + * Definitions for the CAN network device driver interface
570 + *
571 + * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
572 + *               Varma Electronics Oy
573 + *
574 + * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
575 + *
576 + * Send feedback to <socketcan-users@lists.berlios.de>
577 + */
578 +
579 +#ifndef CAN_DEV_H
580 +#define CAN_DEV_H
581 +
582 +#include <linux/can/error.h>
583 +
584 +/*
585 + * CAN bitrate and bit-timing
586 + */
587 +struct can_bittiming {
588 +       u32 bitrate;
589 +       u32 sample_point;
590 +       u32 tq;
591 +       u32 prop_seg;
592 +       u32 phase_seg1;
593 +       u32 phase_seg2;
594 +       u32 sjw;
595 +       u32 clock;
596 +       u32 brp;
597 +};
598 +
599 +struct can_bittiming_const {
600 +       u32 tseg1_min;
601 +       u32 tseg1_max;
602 +       u32 tseg2_min;
603 +       u32 tseg2_max;
604 +       u32 sjw_max;
605 +       u32 brp_min;
606 +       u32 brp_max;
607 +       u32 brp_inc;
608 +};
609 +
610 +/*
611 + * CAN mode
612 + */
613 +enum can_mode {
614 +       CAN_MODE_STOP = 0,
615 +       CAN_MODE_START,
616 +       CAN_MODE_SLEEP
617 +};
618 +
619 +/*
620 + * CAN controller mode
621 + */
622 +#define CAN_CTRLMODE_LOOPBACK  0x1
623 +#define CAN_CTRLMODE_LISTENONLY        0x2
624 +#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */
625 +
626 +/*
627 + * CAN operational and error states
628 + */
629 +enum can_state {
630 +       CAN_STATE_ACTIVE = 0,
631 +       CAN_STATE_BUS_WARNING,
632 +       CAN_STATE_BUS_PASSIVE,
633 +       CAN_STATE_BUS_OFF,
634 +       CAN_STATE_STOPPED,
635 +       CAN_STATE_SLEEPING
636 +};
637 +
638 +/*
639 + * CAN device statistics
640 + */
641 +struct can_device_stats {
642 +       unsigned long error_warning;
643 +       unsigned long data_overrun;
644 +       unsigned long wakeup;
645 +       unsigned long bus_error;
646 +       unsigned long error_passive;
647 +       unsigned long arbitration_lost;
648 +       unsigned long restarts;
649 +       unsigned long bus_error_at_init;
650 +};
651 +
652 +/*
653 + * CAN common private data
654 + */
655 +#define CAN_ECHO_SKB_MAX  4
656 +
657 +struct can_priv {
658 +       struct can_device_stats can_stats;
659 +
660 +       struct can_bittiming bittiming;
661 +       struct can_bittiming_const *bittiming_const;
662 +
663 +       spinlock_t irq_lock;
664 +
665 +       enum can_state state;
666 +       u32 ctrlmode;
667 +
668 +       int restart_ms;
669 +       struct timer_list timer;
670 +
671 +       struct sk_buff *echo_skb[CAN_ECHO_SKB_MAX];
672 +
673 +       int (*do_set_bittiming)(struct net_device *dev);
674 +       int (*do_get_state)(struct net_device *dev, enum can_state *state);
675 +       int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
676 +       int (*do_set_ctrlmode)(struct net_device *dev, u32 ctrlmode);
677 +       int (*do_get_ctrlmode)(struct net_device *dev, u32 *ctrlmode);
678 +};
679 +
680 +#define ND2D(_ndev)    (_ndev->dev.parent)
681 +
682 +
683 +struct net_device *alloc_candev(int sizeof_priv);
684 +void free_candev(struct net_device *dev);
685 +int register_candev(struct net_device *dev);
686 +void unregister_candev(struct net_device *dev);
687 +
688 +int can_set_bittiming(struct net_device *dev);
689 +
690 +int can_restart_now(struct net_device *dev);
691 +
692 +void can_bus_off(struct net_device *dev);
693 +
694 +void can_close_cleanup(struct net_device *dev);
695 +
696 +void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, int idx);
697 +void can_get_echo_skb(struct net_device *dev, int idx);
698 +
699 +int can_sample_point(struct can_bittiming *bt);
700 +
701 +#endif /* CAN_DEV_H */
702 Index: net-next-2.6/drivers/net/can/Kconfig
703 ===================================================================
704 --- net-next-2.6.orig/drivers/net/can/Kconfig
705 +++ net-next-2.6/drivers/net/can/Kconfig
706 @@ -12,6 +12,29 @@ config CAN_VCAN
707           This driver can also be built as a module.  If so, the module
708           will be called vcan.
709  
710 +config CAN_DEV
711 +       tristate "Platform CAN drivers with SYSFS support"
712 +       depends on CAN
713 +       default Y
714 +       ---help---
715 +         Enables the common framework for platform CAN drivers with SYSFS
716 +         support. This is the standard library for CAN drivers.
717 +         If unsure, say Y.
718 +
719 +config CAN_CALC_BITTIMING
720 +       bool "CAN bit-timing calculation"
721 +       depends on CAN_DEV
722 +       default Y
723 +       ---help---
724 +         If enabled, CAN bit-timing parameters will be calculated for the
725 +         bit-rate specified via SYSFS file "bitrate" when the device gets
726 +         started. This works fine for the most common CAN controllers
727 +         with standard bit-rates but may fail for exotic bit-rates or CAN
728 +         source clock frequencies. Disabling saves some space, but then the
729 +         bit-timing parameters must be specified directly using the SYSFS
730 +         files "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw".
731 +         If unsure, say Y.
732 +
733  config CAN_DEBUG_DEVICES
734         bool "CAN devices debugging messages"
735         depends on CAN