diff options
author | Wolfgang Grandegger <wg@grandegger.com> | 2009-05-15 19:39:27 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-05-18 18:41:39 -0400 |
commit | e20dad964aeac229a204e298c563b6ea7ff1e987 (patch) | |
tree | b1a139c42f1930fa11befce7f1af07e296cdc0fc /Documentation/networking/can.txt | |
parent | a6286ee630f6d95f8466e19d7f1ae38d677028ae (diff) |
can: Documentation for the CAN device driver interface
This patch documents the CAN netowrk device drivers interface, removes
obsolete documentation and adds some useful links to CAN resources.
Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation/networking/can.txt')
-rw-r--r-- | Documentation/networking/can.txt | 235 |
1 files changed, 197 insertions, 38 deletions
diff --git a/Documentation/networking/can.txt b/Documentation/networking/can.txt index 2035bc4932f2..6cd6627c3293 100644 --- a/Documentation/networking/can.txt +++ b/Documentation/networking/can.txt | |||
@@ -36,10 +36,15 @@ This file contains | |||
36 | 6.2 local loopback of sent frames | 36 | 6.2 local loopback of sent frames |
37 | 6.3 CAN controller hardware filters | 37 | 6.3 CAN controller hardware filters |
38 | 6.4 The virtual CAN driver (vcan) | 38 | 6.4 The virtual CAN driver (vcan) |
39 | 6.5 currently supported CAN hardware | 39 | 6.5 The CAN network device driver interface |
40 | 6.6 todo | 40 | 6.5.1 Netlink interface to set/get devices properties |
41 | 6.5.2 Setting the CAN bit-timing | ||
42 | 6.5.3 Starting and stopping the CAN network device | ||
43 | 6.6 supported CAN hardware | ||
41 | 44 | ||
42 | 7 Credits | 45 | 7 Socket CAN resources |
46 | |||
47 | 8 Credits | ||
43 | 48 | ||
44 | ============================================================================ | 49 | ============================================================================ |
45 | 50 | ||
@@ -234,6 +239,8 @@ solution for a couple of reasons: | |||
234 | the user application using the common CAN filter mechanisms. Inside | 239 | the user application using the common CAN filter mechanisms. Inside |
235 | this filter definition the (interested) type of errors may be | 240 | this filter definition the (interested) type of errors may be |
236 | selected. The reception of error frames is disabled by default. | 241 | selected. The reception of error frames is disabled by default. |
242 | The format of the CAN error frame is briefly decribed in the Linux | ||
243 | header file "include/linux/can/error.h". | ||
237 | 244 | ||
238 | 4. How to use Socket CAN | 245 | 4. How to use Socket CAN |
239 | ------------------------ | 246 | ------------------------ |
@@ -605,61 +612,213 @@ solution for a couple of reasons: | |||
605 | removal of vcan network devices can be managed with the ip(8) tool: | 612 | removal of vcan network devices can be managed with the ip(8) tool: |
606 | 613 | ||
607 | - Create a virtual CAN network interface: | 614 | - Create a virtual CAN network interface: |
608 | ip link add type vcan | 615 | $ ip link add type vcan |
609 | 616 | ||
610 | - Create a virtual CAN network interface with a specific name 'vcan42': | 617 | - Create a virtual CAN network interface with a specific name 'vcan42': |
611 | ip link add dev vcan42 type vcan | 618 | $ ip link add dev vcan42 type vcan |
612 | 619 | ||
613 | - Remove a (virtual CAN) network interface 'vcan42': | 620 | - Remove a (virtual CAN) network interface 'vcan42': |
614 | ip link del vcan42 | 621 | $ ip link del vcan42 |
615 | 622 | ||
616 | The tool 'vcan' from the SocketCAN SVN repository on BerliOS is obsolete. | 623 | 6.5 The CAN network device driver interface |
617 | 624 | ||
618 | Virtual CAN network device creation in older Kernels: | 625 | The CAN network device driver interface provides a generic interface |
619 | In Linux Kernel versions < 2.6.24 the vcan driver creates 4 vcan | 626 | to setup, configure and monitor CAN network devices. The user can then |
620 | netdevices at module load time by default. This value can be changed | 627 | configure the CAN device, like setting the bit-timing parameters, via |
621 | with the module parameter 'numdev'. E.g. 'modprobe vcan numdev=8' | 628 | the netlink interface using the program "ip" from the "IPROUTE2" |
622 | 629 | utility suite. The following chapter describes briefly how to use it. | |
623 | 6.5 currently supported CAN hardware | 630 | Furthermore, the interface uses a common data structure and exports a |
631 | set of common functions, which all real CAN network device drivers | ||
632 | should use. Please have a look to the SJA1000 or MSCAN driver to | ||
633 | understand how to use them. The name of the module is can-dev.ko. | ||
634 | |||
635 | 6.5.1 Netlink interface to set/get devices properties | ||
636 | |||
637 | The CAN device must be configured via netlink interface. The supported | ||
638 | netlink message types are defined and briefly described in | ||
639 | "include/linux/can/netlink.h". CAN link support for the program "ip" | ||
640 | of the IPROUTE2 utility suite is avaiable and it can be used as shown | ||
641 | below: | ||
642 | |||
643 | - Setting CAN device properties: | ||
644 | |||
645 | $ ip link set can0 type can help | ||
646 | Usage: ip link set DEVICE type can | ||
647 | [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | | ||
648 | [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1 | ||
649 | phase-seg2 PHASE-SEG2 [ sjw SJW ] ] | ||
650 | |||
651 | [ loopback { on | off } ] | ||
652 | [ listen-only { on | off } ] | ||
653 | [ triple-sampling { on | off } ] | ||
654 | |||
655 | [ restart-ms TIME-MS ] | ||
656 | [ restart ] | ||
657 | |||
658 | Where: BITRATE := { 1..1000000 } | ||
659 | SAMPLE-POINT := { 0.000..0.999 } | ||
660 | TQ := { NUMBER } | ||
661 | PROP-SEG := { 1..8 } | ||
662 | PHASE-SEG1 := { 1..8 } | ||
663 | PHASE-SEG2 := { 1..8 } | ||
664 | SJW := { 1..4 } | ||
665 | RESTART-MS := { 0 | NUMBER } | ||
666 | |||
667 | - Display CAN device details and statistics: | ||
668 | |||
669 | $ ip -details -statistics link show can0 | ||
670 | 2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP qlen 10 | ||
671 | link/can | ||
672 | can <TRIPLE-SAMPLING> state ERROR-ACTIVE restart-ms 100 | ||
673 | bitrate 125000 sample_point 0.875 | ||
674 | tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 | ||
675 | sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 | ||
676 | clock 8000000 | ||
677 | re-started bus-errors arbit-lost error-warn error-pass bus-off | ||
678 | 41 17457 0 41 42 41 | ||
679 | RX: bytes packets errors dropped overrun mcast | ||
680 | 140859 17608 17457 0 0 0 | ||
681 | TX: bytes packets errors dropped carrier collsns | ||
682 | 861 112 0 41 0 0 | ||
683 | |||
684 | More info to the above output: | ||
685 | |||
686 | "<TRIPLE-SAMPLING>" | ||
687 | Shows the list of selected CAN controller modes: LOOPBACK, | ||
688 | LISTEN-ONLY, or TRIPLE-SAMPLING. | ||
689 | |||
690 | "state ERROR-ACTIVE" | ||
691 | The current state of the CAN controller: "ERROR-ACTIVE", | ||
692 | "ERROR-WARNING", "ERROR-PASSIVE", "BUS-OFF" or "STOPPED" | ||
693 | |||
694 | "restart-ms 100" | ||
695 | Automatic restart delay time. If set to a non-zero value, a | ||
696 | restart of the CAN controller will be triggered automatically | ||
697 | in case of a bus-off condition after the specified delay time | ||
698 | in milliseconds. By default it's off. | ||
699 | |||
700 | "bitrate 125000 sample_point 0.875" | ||
701 | Shows the real bit-rate in bits/sec and the sample-point in the | ||
702 | range 0.000..0.999. If the calculation of bit-timing parameters | ||
703 | is enabled in the kernel (CONFIG_CAN_CALC_BITTIMING=y), the | ||
704 | bit-timing can be defined by setting the "bitrate" argument. | ||
705 | Optionally the "sample-point" can be specified. By default it's | ||
706 | 0.000 assuming CIA-recommended sample-points. | ||
707 | |||
708 | "tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1" | ||
709 | Shows the time quanta in ns, propagation segment, phase buffer | ||
710 | segment 1 and 2 and the synchronisation jump width in units of | ||
711 | tq. They allow to define the CAN bit-timing in a hardware | ||
712 | independent format as proposed by the Bosch CAN 2.0 spec (see | ||
713 | chapter 8 of http://www.semiconductors.bosch.de/pdf/can2spec.pdf). | ||
714 | |||
715 | "sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 | ||
716 | clock 8000000" | ||
717 | Shows the bit-timing constants of the CAN controller, here the | ||
718 | "sja1000". The minimum and maximum values of the time segment 1 | ||
719 | and 2, the synchronisation jump width in units of tq, the | ||
720 | bitrate pre-scaler and the CAN system clock frequency in Hz. | ||
721 | These constants could be used for user-defined (non-standard) | ||
722 | bit-timing calculation algorithms in user-space. | ||
723 | |||
724 | "re-started bus-errors arbit-lost error-warn error-pass bus-off" | ||
725 | Shows the number of restarts, bus and arbitration lost errors, | ||
726 | and the state changes to the error-warning, error-passive and | ||
727 | bus-off state. RX overrun errors are listed in the "overrun" | ||
728 | field of the standard network statistics. | ||
729 | |||
730 | 6.5.2 Setting the CAN bit-timing | ||
731 | |||
732 | The CAN bit-timing parameters can always be defined in a hardware | ||
733 | independent format as proposed in the Bosch CAN 2.0 specification | ||
734 | specifying the arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" | ||
735 | and "sjw": | ||
736 | |||
737 | $ ip link set canX type can tq 125 prop-seg 6 \ | ||
738 | phase-seg1 7 phase-seg2 2 sjw 1 | ||
739 | |||
740 | If the kernel option CONFIG_CAN_CALC_BITTIMING is enabled, CIA | ||
741 | recommended CAN bit-timing parameters will be calculated if the bit- | ||
742 | rate is specified with the argument "bitrate": | ||
743 | |||
744 | $ ip link set canX type can bitrate 125000 | ||
745 | |||
746 | Note that this works fine for the most common CAN controllers with | ||
747 | standard bit-rates but may *fail* for exotic bit-rates or CAN system | ||
748 | clock frequencies. Disabling CONFIG_CAN_CALC_BITTIMING saves some | ||
749 | space and allows user-space tools to solely determine and set the | ||
750 | bit-timing parameters. The CAN controller specific bit-timing | ||
751 | constants can be used for that purpose. They are listed by the | ||
752 | following command: | ||
753 | |||
754 | $ ip -details link show can0 | ||
755 | ... | ||
756 | sja1000: clock 8000000 tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 | ||
757 | |||
758 | 6.5.3 Starting and stopping the CAN network device | ||
759 | |||
760 | A CAN network device is started or stopped as usual with the command | ||
761 | "ifconfig canX up/down" or "ip link set canX up/down". Be aware that | ||
762 | you *must* define proper bit-timing parameters for real CAN devices | ||
763 | before you can start it to avoid error-prone default settings: | ||
764 | |||
765 | $ ip link set canX up type can bitrate 125000 | ||
766 | |||
767 | A device may enter the "bus-off" state if too much errors occurred on | ||
768 | the CAN bus. Then no more messages are received or sent. An automatic | ||
769 | bus-off recovery can be enabled by setting the "restart-ms" to a | ||
770 | non-zero value, e.g.: | ||
771 | |||
772 | $ ip link set canX type can restart-ms 100 | ||
773 | |||
774 | Alternatively, the application may realize the "bus-off" condition | ||
775 | by monitoring CAN error frames and do a restart when appropriate with | ||
776 | the command: | ||
777 | |||
778 | $ ip link set canX type can restart | ||
779 | |||
780 | Note that a restart will also create a CAN error frame (see also | ||
781 | chapter 3.4). | ||
624 | 782 | ||
625 | On the project website http://developer.berlios.de/projects/socketcan | 783 | 6.6 Supported CAN hardware |
626 | there are different drivers available: | ||
627 | 784 | ||
628 | vcan: Virtual CAN interface driver (if no real hardware is available) | 785 | Please check the "Kconfig" file in "drivers/net/can" to get an actual |
629 | sja1000: Philips SJA1000 CAN controller (recommended) | 786 | list of the support CAN hardware. On the Socket CAN project website |
630 | i82527: Intel i82527 CAN controller | 787 | (see chapter 7) there might be further drivers available, also for |
631 | mscan: Motorola/Freescale CAN controller (e.g. inside SOC MPC5200) | 788 | older kernel versions. |
632 | ccan: CCAN controller core (e.g. inside SOC h7202) | ||
633 | slcan: For a bunch of CAN adaptors that are attached via a | ||
634 | serial line ASCII protocol (for serial / USB adaptors) | ||
635 | 789 | ||
636 | Additionally the different CAN adaptors (ISA/PCI/PCMCIA/USB/Parport) | 790 | 7. Socket CAN resources |
637 | from PEAK Systemtechnik support the CAN netdevice driver model | 791 | ----------------------- |
638 | since Linux driver v6.0: http://www.peak-system.com/linux/index.htm | ||
639 | 792 | ||
640 | Please check the Mailing Lists on the berlios OSS project website. | 793 | You can find further resources for Socket CAN like user space tools, |
794 | support for old kernel versions, more drivers, mailing lists, etc. | ||
795 | at the BerliOS OSS project website for Socket CAN: | ||
641 | 796 | ||
642 | 6.6 todo | 797 | http://developer.berlios.de/projects/socketcan |
643 | 798 | ||
644 | The configuration interface for CAN network drivers is still an open | 799 | If you have questions, bug fixes, etc., don't hesitate to post them to |
645 | issue that has not been finalized in the socketcan project. Also the | 800 | the Socketcan-Users mailing list. But please search the archives first. |
646 | idea of having a library module (candev.ko) that holds functions | ||
647 | that are needed by all CAN netdevices is not ready to ship. | ||
648 | Your contribution is welcome. | ||
649 | 801 | ||
650 | 7. Credits | 802 | 8. Credits |
651 | ---------- | 803 | ---------- |
652 | 804 | ||
653 | Oliver Hartkopp (PF_CAN core, filters, drivers, bcm) | 805 | Oliver Hartkopp (PF_CAN core, filters, drivers, bcm, SJA1000 driver) |
654 | Urs Thuermann (PF_CAN core, kernel integration, socket interfaces, raw, vcan) | 806 | Urs Thuermann (PF_CAN core, kernel integration, socket interfaces, raw, vcan) |
655 | Jan Kizka (RT-SocketCAN core, Socket-API reconciliation) | 807 | Jan Kizka (RT-SocketCAN core, Socket-API reconciliation) |
656 | Wolfgang Grandegger (RT-SocketCAN core & drivers, Raw Socket-API reviews) | 808 | Wolfgang Grandegger (RT-SocketCAN core & drivers, Raw Socket-API reviews, |
809 | CAN device driver interface, MSCAN driver) | ||
657 | Robert Schwebel (design reviews, PTXdist integration) | 810 | Robert Schwebel (design reviews, PTXdist integration) |
658 | Marc Kleine-Budde (design reviews, Kernel 2.6 cleanups, drivers) | 811 | Marc Kleine-Budde (design reviews, Kernel 2.6 cleanups, drivers) |
659 | Benedikt Spranger (reviews) | 812 | Benedikt Spranger (reviews) |
660 | Thomas Gleixner (LKML reviews, coding style, posting hints) | 813 | Thomas Gleixner (LKML reviews, coding style, posting hints) |
661 | Andrey Volkov (kernel subtree structure, ioctls, mscan driver) | 814 | Andrey Volkov (kernel subtree structure, ioctls, MSCAN driver) |
662 | Matthias Brukner (first SJA1000 CAN netdevice implementation Q2/2003) | 815 | Matthias Brukner (first SJA1000 CAN netdevice implementation Q2/2003) |
663 | Klaus Hitschler (PEAK driver integration) | 816 | Klaus Hitschler (PEAK driver integration) |
664 | Uwe Koppe (CAN netdevices with PF_PACKET approach) | 817 | Uwe Koppe (CAN netdevices with PF_PACKET approach) |
665 | Michael Schulze (driver layer loopback requirement, RT CAN drivers review) | 818 | Michael Schulze (driver layer loopback requirement, RT CAN drivers review) |
819 | Pavel Pisa (Bit-timing calculation) | ||
820 | Sascha Hauer (SJA1000 platform driver) | ||
821 | Sebastian Haas (SJA1000 EMS PCI driver) | ||
822 | Markus Plessing (SJA1000 EMS PCI driver) | ||
823 | Per Dalen (SJA1000 Kvaser PCI driver) | ||
824 | Sam Ravnborg (reviews, coding style, kbuild help) | ||