| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-15 20:31:56 +02:00
										 |  |  | #ifndef _CAN_DEV_H
 | 
					
						
							|  |  |  | #define _CAN_DEV_H
 | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 00:03:25 +00:00
										 |  |  | #include <linux/can.h>
 | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | #include <linux/can/netlink.h>
 | 
					
						
							|  |  |  | #include <linux/can/error.h>
 | 
					
						
							| 
									
										
										
										
											2012-12-18 18:50:55 +01:00
										 |  |  | #include <linux/can/led.h>
 | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * CAN mode | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum can_mode { | 
					
						
							|  |  |  | 	CAN_MODE_STOP = 0, | 
					
						
							|  |  |  | 	CAN_MODE_START, | 
					
						
							|  |  |  | 	CAN_MODE_SLEEP | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * CAN common private data | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct can_priv { | 
					
						
							|  |  |  | 	struct can_device_stats can_stats; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 16:36:23 +01:00
										 |  |  | 	struct can_bittiming bittiming, data_bittiming; | 
					
						
							|  |  |  | 	const struct can_bittiming_const *bittiming_const, | 
					
						
							|  |  |  | 		*data_bittiming_const; | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 	struct can_clock clock; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	enum can_state state; | 
					
						
							|  |  |  | 	u32 ctrlmode; | 
					
						
							| 
									
										
										
										
											2010-01-14 07:08:34 +00:00
										 |  |  | 	u32 ctrlmode_supported; | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int restart_ms; | 
					
						
							|  |  |  | 	struct timer_list restart_timer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int (*do_set_bittiming)(struct net_device *dev); | 
					
						
							| 
									
										
										
										
											2014-02-28 16:36:23 +01:00
										 |  |  | 	int (*do_set_data_bittiming)(struct net_device *dev); | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2010-02-22 22:21:17 +00:00
										 |  |  | 	int (*do_get_berr_counter)(const struct net_device *dev, | 
					
						
							|  |  |  | 				   struct can_berr_counter *bec); | 
					
						
							| 
									
										
										
										
											2009-10-08 22:17:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	unsigned int echo_skb_max; | 
					
						
							|  |  |  | 	struct sk_buff **echo_skb; | 
					
						
							| 
									
										
										
										
											2012-12-18 18:50:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_CAN_LEDS
 | 
					
						
							|  |  |  | 	struct led_trigger *tx_led_trig; | 
					
						
							|  |  |  | 	char tx_led_trig_name[CAN_LED_NAME_SZ]; | 
					
						
							|  |  |  | 	struct led_trigger *rx_led_trig; | 
					
						
							|  |  |  | 	char rx_led_trig_name[CAN_LED_NAME_SZ]; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-12 04:13:21 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * get_can_dlc(value) - helper macro to cast a given data length code (dlc) | 
					
						
							|  |  |  |  * to __u8 and ensure the dlc value to be max. 8 bytes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * To be used in the CAN netdriver receive path to ensure conformance with | 
					
						
							|  |  |  |  * ISO 11898-1 Chapter 8.4.2.3 (DLC field) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-06-13 20:48:21 +02:00
										 |  |  | #define get_can_dlc(i)		(min_t(__u8, (i), CAN_MAX_DLC))
 | 
					
						
							|  |  |  | #define get_canfd_dlc(i)	(min_t(__u8, (i), CANFD_MAX_DLC))
 | 
					
						
							| 
									
										
										
										
											2009-12-12 04:13:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-12 02:00:46 -08:00
										 |  |  | /* Drop a given socketbuffer if it does not contain a valid CAN frame. */ | 
					
						
							|  |  |  | static inline int can_dropped_invalid_skb(struct net_device *dev, | 
					
						
							|  |  |  | 					  struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-13 20:48:21 +02:00
										 |  |  | 	const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (skb->protocol == htons(ETH_P_CAN)) { | 
					
						
							|  |  |  | 		if (unlikely(skb->len != CAN_MTU || | 
					
						
							|  |  |  | 			     cfd->len > CAN_MAX_DLEN)) | 
					
						
							|  |  |  | 			goto inval_skb; | 
					
						
							|  |  |  | 	} else if (skb->protocol == htons(ETH_P_CANFD)) { | 
					
						
							|  |  |  | 		if (unlikely(skb->len != CANFD_MTU || | 
					
						
							|  |  |  | 			     cfd->len > CANFD_MAX_DLEN)) | 
					
						
							|  |  |  | 			goto inval_skb; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		goto inval_skb; | 
					
						
							| 
									
										
										
										
											2010-01-12 02:00:46 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2012-06-13 20:48:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | inval_skb: | 
					
						
							|  |  |  | 	kfree_skb(skb); | 
					
						
							|  |  |  | 	dev->stats.tx_dropped++; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2010-01-12 02:00:46 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 16:45:12 +08:00
										 |  |  | static inline bool can_is_canfd_skb(const struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* the CAN specific type of skb is identified by its data length */ | 
					
						
							|  |  |  | 	return skb->len == CANFD_MTU; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-13 20:48:21 +02:00
										 |  |  | /* get data length from can_dlc with sanitized can_dlc */ | 
					
						
							|  |  |  | u8 can_dlc2len(u8 can_dlc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* map the sanitized data length to an appropriate data length code */ | 
					
						
							|  |  |  | u8 can_len2dlc(u8 len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-08 22:17:11 +00:00
										 |  |  | struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max); | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | void free_candev(struct net_device *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-18 18:50:56 +01:00
										 |  |  | /* a candev safe wrapper around netdev_priv */ | 
					
						
							|  |  |  | struct can_priv *safe_candev_priv(struct net_device *dev); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | int open_candev(struct net_device *dev); | 
					
						
							|  |  |  | void close_candev(struct net_device *dev); | 
					
						
							| 
									
										
										
										
											2014-02-28 16:36:24 +01:00
										 |  |  | int can_change_mtu(struct net_device *dev, int new_mtu); | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 17:54:13 +00:00
										 |  |  | void can_change_state(struct net_device *dev, struct can_frame *cf, | 
					
						
							|  |  |  | 		      enum can_state tx_state, enum can_state rx_state); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-08 22:17:11 +00:00
										 |  |  | void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, | 
					
						
							|  |  |  | 		      unsigned int idx); | 
					
						
							| 
									
										
										
										
											2011-10-10 23:43:53 +02:00
										 |  |  | unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx); | 
					
						
							| 
									
										
										
										
											2009-10-08 22:17:11 +00:00
										 |  |  | void can_free_echo_skb(struct net_device *dev, unsigned int idx); | 
					
						
							| 
									
										
										
										
											2009-05-15 23:39:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 00:08:01 -07:00
										 |  |  | struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:50:13 +01:00
										 |  |  | struct sk_buff *alloc_canfd_skb(struct net_device *dev, | 
					
						
							|  |  |  | 				struct canfd_frame **cfd); | 
					
						
							| 
									
										
										
										
											2009-10-20 00:08:01 -07:00
										 |  |  | struct sk_buff *alloc_can_err_skb(struct net_device *dev, | 
					
						
							|  |  |  | 				  struct can_frame **cf); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-15 20:31:56 +02:00
										 |  |  | #endif /* !_CAN_DEV_H */
 |