Merge tag 'drm-misc-next-fixes-2021-09-09' of git://anongit.freedesktop.org/drm/drm...
[linux-2.6-microblaze.git] / include / linux / can / dev.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * linux/can/dev.h
4  *
5  * Definitions for the CAN network device driver interface
6  *
7  * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
8  *               Varma Electronics Oy
9  *
10  * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
11  *
12  */
13
14 #ifndef _CAN_DEV_H
15 #define _CAN_DEV_H
16
17 #include <linux/can.h>
18 #include <linux/can/bittiming.h>
19 #include <linux/can/error.h>
20 #include <linux/can/led.h>
21 #include <linux/can/length.h>
22 #include <linux/can/netlink.h>
23 #include <linux/can/skb.h>
24 #include <linux/netdevice.h>
25
26 /*
27  * CAN mode
28  */
29 enum can_mode {
30         CAN_MODE_STOP = 0,
31         CAN_MODE_START,
32         CAN_MODE_SLEEP
33 };
34
35 /*
36  * CAN common private data
37  */
38 struct can_priv {
39         struct net_device *dev;
40         struct can_device_stats can_stats;
41
42         const struct can_bittiming_const *bittiming_const,
43                 *data_bittiming_const;
44         struct can_bittiming bittiming, data_bittiming;
45         const struct can_tdc_const *tdc_const;
46         struct can_tdc tdc;
47
48         unsigned int bitrate_const_cnt;
49         const u32 *bitrate_const;
50         const u32 *data_bitrate_const;
51         unsigned int data_bitrate_const_cnt;
52         u32 bitrate_max;
53         struct can_clock clock;
54
55         unsigned int termination_const_cnt;
56         const u16 *termination_const;
57         u16 termination;
58
59         enum can_state state;
60
61         /* CAN controller features - see include/uapi/linux/can/netlink.h */
62         u32 ctrlmode;           /* current options setting */
63         u32 ctrlmode_supported; /* options that can be modified by netlink */
64         u32 ctrlmode_static;    /* static enabled options for driver/hardware */
65
66         int restart_ms;
67         struct delayed_work restart_work;
68
69         int (*do_set_bittiming)(struct net_device *dev);
70         int (*do_set_data_bittiming)(struct net_device *dev);
71         int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
72         int (*do_set_termination)(struct net_device *dev, u16 term);
73         int (*do_get_state)(const struct net_device *dev,
74                             enum can_state *state);
75         int (*do_get_berr_counter)(const struct net_device *dev,
76                                    struct can_berr_counter *bec);
77
78         unsigned int echo_skb_max;
79         struct sk_buff **echo_skb;
80
81 #ifdef CONFIG_CAN_LEDS
82         struct led_trigger *tx_led_trig;
83         char tx_led_trig_name[CAN_LED_NAME_SZ];
84         struct led_trigger *rx_led_trig;
85         char rx_led_trig_name[CAN_LED_NAME_SZ];
86         struct led_trigger *rxtx_led_trig;
87         char rxtx_led_trig_name[CAN_LED_NAME_SZ];
88 #endif
89 };
90
91
92 /* helper to define static CAN controller features at device creation time */
93 static inline void can_set_static_ctrlmode(struct net_device *dev,
94                                            u32 static_mode)
95 {
96         struct can_priv *priv = netdev_priv(dev);
97
98         /* alloc_candev() succeeded => netdev_priv() is valid at this point */
99         priv->ctrlmode = static_mode;
100         priv->ctrlmode_static = static_mode;
101
102         /* override MTU which was set by default in can_setup()? */
103         if (static_mode & CAN_CTRLMODE_FD)
104                 dev->mtu = CANFD_MTU;
105 }
106
107 void can_setup(struct net_device *dev);
108
109 struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
110                                     unsigned int txqs, unsigned int rxqs);
111 #define alloc_candev(sizeof_priv, echo_skb_max) \
112         alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1)
113 #define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \
114         alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count)
115 void free_candev(struct net_device *dev);
116
117 /* a candev safe wrapper around netdev_priv */
118 struct can_priv *safe_candev_priv(struct net_device *dev);
119
120 int open_candev(struct net_device *dev);
121 void close_candev(struct net_device *dev);
122 int can_change_mtu(struct net_device *dev, int new_mtu);
123
124 int register_candev(struct net_device *dev);
125 void unregister_candev(struct net_device *dev);
126
127 int can_restart_now(struct net_device *dev);
128 void can_bus_off(struct net_device *dev);
129
130 const char *can_get_state_str(const enum can_state state);
131 void can_change_state(struct net_device *dev, struct can_frame *cf,
132                       enum can_state tx_state, enum can_state rx_state);
133
134 #ifdef CONFIG_OF
135 void of_can_transceiver(struct net_device *dev);
136 #else
137 static inline void of_can_transceiver(struct net_device *dev) { }
138 #endif
139
140 extern struct rtnl_link_ops can_link_ops;
141 int can_netlink_register(void);
142 void can_netlink_unregister(void);
143
144 #endif /* !_CAN_DEV_H */