You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
can: CAN Network device driver and Netlink interface
The CAN network device driver interface provides a generic interface to setup, configure and monitor CAN network devices. It exports a set of common data structures and functions, which all real CAN network device drivers should use. Please have a look to the SJA1000 or MSCAN driver to understand how to use them. The name of the module is can-dev.ko. Furthermore, it adds a Netlink interface allowing to configure the CAN device using the program "ip" from the iproute2 utility suite. For further information please check "Documentation/networking/can.txt" 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>
This commit is contained in:
committed by
David S. Miller
parent
4261a2043f
commit
39549eef35
@@ -12,6 +12,29 @@ config CAN_VCAN
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called vcan.
|
||||
|
||||
config CAN_DEV
|
||||
tristate "Platform CAN drivers with Netlink support"
|
||||
depends on CAN
|
||||
default Y
|
||||
---help---
|
||||
Enables the common framework for platform CAN drivers with Netlink
|
||||
support. This is the standard library for CAN drivers.
|
||||
If unsure, say Y.
|
||||
|
||||
config CAN_CALC_BITTIMING
|
||||
bool "CAN bit-timing calculation"
|
||||
depends on CAN_DEV
|
||||
default Y
|
||||
---help---
|
||||
If enabled, CAN bit-timing parameters will be calculated for the
|
||||
bit-rate specified via Netlink argument "bitrate" when the device
|
||||
get started. This works fine for the most common CAN controllers
|
||||
with standard bit-rates but may fail for exotic bit-rates or CAN
|
||||
source clock frequencies. Disabling saves some space, but then the
|
||||
bit-timing parameters must be specified directly using the Netlink
|
||||
arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw".
|
||||
If unsure, say Y.
|
||||
|
||||
config CAN_DEBUG_DEVICES
|
||||
bool "CAN devices debugging messages"
|
||||
depends on CAN
|
||||
|
||||
@@ -3,3 +3,8 @@
|
||||
#
|
||||
|
||||
obj-$(CONFIG_CAN_VCAN) += vcan.o
|
||||
|
||||
obj-$(CONFIG_CAN_DEV) += can-dev.o
|
||||
can-dev-y := dev.o
|
||||
|
||||
ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
|
||||
|
||||
657
drivers/net/can/dev.c
Normal file
657
drivers/net/can/dev.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
header-y += raw.h
|
||||
header-y += bcm.h
|
||||
header-y += error.h
|
||||
header-y += netlink.h
|
||||
|
||||
70
include/linux/can/dev.h
Normal file
70
include/linux/can/dev.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* linux/can/dev.h
|
||||
*
|
||||
* Definitions for the CAN network device driver interface
|
||||
*
|
||||
* Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
|
||||
* Varma Electronics Oy
|
||||
*
|
||||
* Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
|
||||
*
|
||||
* Send feedback to <socketcan-users@lists.berlios.de>
|
||||
*/
|
||||
|
||||
#ifndef CAN_DEV_H
|
||||
#define CAN_DEV_H
|
||||
|
||||
#include <linux/can/netlink.h>
|
||||
#include <linux/can/error.h>
|
||||
|
||||
/*
|
||||
* CAN mode
|
||||
*/
|
||||
enum can_mode {
|
||||
CAN_MODE_STOP = 0,
|
||||
CAN_MODE_START,
|
||||
CAN_MODE_SLEEP
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN common private data
|
||||
*/
|
||||
#define CAN_ECHO_SKB_MAX 4
|
||||
|
||||
struct can_priv {
|
||||
struct can_device_stats can_stats;
|
||||
|
||||
struct can_bittiming bittiming;
|
||||
struct can_bittiming_const *bittiming_const;
|
||||
struct can_clock clock;
|
||||
|
||||
enum can_state state;
|
||||
u32 ctrlmode;
|
||||
|
||||
int restart_ms;
|
||||
struct timer_list restart_timer;
|
||||
|
||||
struct sk_buff *echo_skb[CAN_ECHO_SKB_MAX];
|
||||
|
||||
int (*do_set_bittiming)(struct net_device *dev);
|
||||
int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
|
||||
int (*do_get_state)(const struct net_device *dev,
|
||||
enum can_state *state);
|
||||
};
|
||||
|
||||
struct net_device *alloc_candev(int sizeof_priv);
|
||||
void free_candev(struct net_device *dev);
|
||||
|
||||
int open_candev(struct net_device *dev);
|
||||
void close_candev(struct net_device *dev);
|
||||
|
||||
int register_candev(struct net_device *dev);
|
||||
void unregister_candev(struct net_device *dev);
|
||||
|
||||
int can_restart_now(struct net_device *dev);
|
||||
void can_bus_off(struct net_device *dev);
|
||||
|
||||
void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, int idx);
|
||||
void can_get_echo_skb(struct net_device *dev, int idx);
|
||||
|
||||
#endif /* CAN_DEV_H */
|
||||
113
include/linux/can/netlink.h
Normal file
113
include/linux/can/netlink.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* linux/can/netlink.h
|
||||
*
|
||||
* Definitions for the CAN netlink interface
|
||||
*
|
||||
* Copyright (c) 2009 Wolfgang Grandegger <wg@grandegger.com>
|
||||
*
|
||||
* Send feedback to <socketcan-users@lists.berlios.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CAN_NETLINK_H
|
||||
#define CAN_NETLINK_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/*
|
||||
* CAN bit-timing parameters
|
||||
*
|
||||
* For futher information, please read chapter "8 BIT TIMING
|
||||
* REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
|
||||
* at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
|
||||
*/
|
||||
struct can_bittiming {
|
||||
__u32 bitrate; /* Bit-rate in bits/second */
|
||||
__u32 sample_point; /* Sample point in one-tenth of a percent */
|
||||
__u32 tq; /* Time quanta (TQ) in nanoseconds */
|
||||
__u32 prop_seg; /* Propagation segment in TQs */
|
||||
__u32 phase_seg1; /* Phase buffer segment 1 in TQs */
|
||||
__u32 phase_seg2; /* Phase buffer segment 2 in TQs */
|
||||
__u32 sjw; /* Synchronisation jump width in TQs */
|
||||
__u32 brp; /* Bit-rate prescaler */
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN harware-dependent bit-timing constant
|
||||
*
|
||||
* Used for calculating and checking bit-timing parameters
|
||||
*/
|
||||
struct can_bittiming_const {
|
||||
char name[16]; /* Name of the CAN controller hardware */
|
||||
__u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
|
||||
__u32 tseg1_max;
|
||||
__u32 tseg2_min; /* Time segement 2 = phase_seg2 */
|
||||
__u32 tseg2_max;
|
||||
__u32 sjw_max; /* Synchronisation jump width */
|
||||
__u32 brp_min; /* Bit-rate prescaler */
|
||||
__u32 brp_max;
|
||||
__u32 brp_inc;
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN clock parameters
|
||||
*/
|
||||
struct can_clock {
|
||||
__u32 freq; /* CAN system clock frequency in Hz */
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN operational and error states
|
||||
*/
|
||||
enum can_state {
|
||||
CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */
|
||||
CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */
|
||||
CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */
|
||||
CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */
|
||||
CAN_STATE_STOPPED, /* Device is stopped */
|
||||
CAN_STATE_SLEEPING, /* Device is sleeping */
|
||||
CAN_STATE_MAX
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN controller mode
|
||||
*/
|
||||
struct can_ctrlmode {
|
||||
__u32 mask;
|
||||
__u32 flags;
|
||||
};
|
||||
|
||||
#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */
|
||||
#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */
|
||||
#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */
|
||||
|
||||
/*
|
||||
* CAN device statistics
|
||||
*/
|
||||
struct can_device_stats {
|
||||
__u32 bus_error; /* Bus errors */
|
||||
__u32 error_warning; /* Changes to error warning state */
|
||||
__u32 error_passive; /* Changes to error passive state */
|
||||
__u32 bus_off; /* Changes to bus off state */
|
||||
__u32 arbitration_lost; /* Arbitration lost errors */
|
||||
__u32 restarts; /* CAN controller re-starts */
|
||||
};
|
||||
|
||||
/*
|
||||
* CAN netlink interface
|
||||
*/
|
||||
enum {
|
||||
IFLA_CAN_UNSPEC,
|
||||
IFLA_CAN_BITTIMING,
|
||||
IFLA_CAN_BITTIMING_CONST,
|
||||
IFLA_CAN_CLOCK,
|
||||
IFLA_CAN_STATE,
|
||||
IFLA_CAN_CTRLMODE,
|
||||
IFLA_CAN_RESTART_MS,
|
||||
IFLA_CAN_RESTART,
|
||||
__IFLA_CAN_MAX
|
||||
};
|
||||
|
||||
#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1)
|
||||
|
||||
#endif /* CAN_NETLINK_H */
|
||||
Reference in New Issue
Block a user