~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/can/dev.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/can/dev.h (Version linux-6.11.5) and /include/linux/can/dev.h (Version linux-5.11.22)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*                                                  2 /*
  3  * linux/can/dev.h                                  3  * linux/can/dev.h
  4  *                                                  4  *
  5  * Definitions for the CAN network device driv      5  * Definitions for the CAN network device driver interface
  6  *                                                  6  *
  7  * Copyright (C) 2006 Andrey Volkov <avolkov@v      7  * Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
  8  *               Varma Electronics Oy               8  *               Varma Electronics Oy
  9  *                                                  9  *
 10  * Copyright (C) 2008 Wolfgang Grandegger <wg@     10  * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
 11  *                                                 11  *
 12  */                                                12  */
 13                                                    13 
 14 #ifndef _CAN_DEV_H                                 14 #ifndef _CAN_DEV_H
 15 #define _CAN_DEV_H                                 15 #define _CAN_DEV_H
 16                                                    16 
 17 #include <linux/can.h>                             17 #include <linux/can.h>
 18 #include <linux/can/bittiming.h>               << 
 19 #include <linux/can/error.h>                       18 #include <linux/can/error.h>
 20 #include <linux/can/length.h>                  !!  19 #include <linux/can/led.h>
 21 #include <linux/can/netlink.h>                     20 #include <linux/can/netlink.h>
 22 #include <linux/can/skb.h>                         21 #include <linux/can/skb.h>
 23 #include <linux/ethtool.h>                     << 
 24 #include <linux/netdevice.h>                       22 #include <linux/netdevice.h>
 25                                                    23 
 26 /*                                                 24 /*
 27  * CAN mode                                        25  * CAN mode
 28  */                                                26  */
 29 enum can_mode {                                    27 enum can_mode {
 30         CAN_MODE_STOP = 0,                         28         CAN_MODE_STOP = 0,
 31         CAN_MODE_START,                            29         CAN_MODE_START,
 32         CAN_MODE_SLEEP                             30         CAN_MODE_SLEEP
 33 };                                                 31 };
 34                                                    32 
 35 enum can_termination_gpio {                    << 
 36         CAN_TERMINATION_GPIO_DISABLED = 0,     << 
 37         CAN_TERMINATION_GPIO_ENABLED,          << 
 38         CAN_TERMINATION_GPIO_MAX,              << 
 39 };                                             << 
 40                                                << 
 41 /*                                                 33 /*
 42  * CAN common private data                         34  * CAN common private data
 43  */                                                35  */
 44 struct can_priv {                                  36 struct can_priv {
 45         struct net_device *dev;                    37         struct net_device *dev;
 46         struct can_device_stats can_stats;         38         struct can_device_stats can_stats;
 47                                                    39 
                                                   >>  40         struct can_bittiming bittiming, data_bittiming;
 48         const struct can_bittiming_const *bitt     41         const struct can_bittiming_const *bittiming_const,
 49                 *data_bittiming_const;             42                 *data_bittiming_const;
 50         struct can_bittiming bittiming, data_b !!  43         const u16 *termination_const;
 51         const struct can_tdc_const *tdc_const; !!  44         unsigned int termination_const_cnt;
 52         struct can_tdc tdc;                    !!  45         u16 termination;
 53                                                << 
 54         unsigned int bitrate_const_cnt;        << 
 55         const u32 *bitrate_const;                  46         const u32 *bitrate_const;
                                                   >>  47         unsigned int bitrate_const_cnt;
 56         const u32 *data_bitrate_const;             48         const u32 *data_bitrate_const;
 57         unsigned int data_bitrate_const_cnt;       49         unsigned int data_bitrate_const_cnt;
 58         u32 bitrate_max;                           50         u32 bitrate_max;
 59         struct can_clock clock;                    51         struct can_clock clock;
 60                                                    52 
 61         unsigned int termination_const_cnt;    << 
 62         const u16 *termination_const;          << 
 63         u16 termination;                       << 
 64         struct gpio_desc *termination_gpio;    << 
 65         u16 termination_gpio_ohms[CAN_TERMINAT << 
 66                                                << 
 67         unsigned int echo_skb_max;             << 
 68         struct sk_buff **echo_skb;             << 
 69                                                << 
 70         enum can_state state;                      53         enum can_state state;
 71                                                    54 
 72         /* CAN controller features - see inclu     55         /* CAN controller features - see include/uapi/linux/can/netlink.h */
 73         u32 ctrlmode;           /* current opt     56         u32 ctrlmode;           /* current options setting */
 74         u32 ctrlmode_supported; /* options tha     57         u32 ctrlmode_supported; /* options that can be modified by netlink */
                                                   >>  58         u32 ctrlmode_static;    /* static enabled options for driver/hardware */
 75                                                    59 
 76         int restart_ms;                            60         int restart_ms;
 77         struct delayed_work restart_work;          61         struct delayed_work restart_work;
 78                                                    62 
 79         int (*do_set_bittiming)(struct net_dev     63         int (*do_set_bittiming)(struct net_device *dev);
 80         int (*do_set_data_bittiming)(struct ne     64         int (*do_set_data_bittiming)(struct net_device *dev);
 81         int (*do_set_mode)(struct net_device *     65         int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
 82         int (*do_set_termination)(struct net_d     66         int (*do_set_termination)(struct net_device *dev, u16 term);
 83         int (*do_get_state)(const struct net_d     67         int (*do_get_state)(const struct net_device *dev,
 84                             enum can_state *st     68                             enum can_state *state);
 85         int (*do_get_berr_counter)(const struc     69         int (*do_get_berr_counter)(const struct net_device *dev,
 86                                    struct can_     70                                    struct can_berr_counter *bec);
 87         int (*do_get_auto_tdcv)(const struct n !!  71 
                                                   >>  72         unsigned int echo_skb_max;
                                                   >>  73         struct sk_buff **echo_skb;
                                                   >>  74 
                                                   >>  75 #ifdef CONFIG_CAN_LEDS
                                                   >>  76         struct led_trigger *tx_led_trig;
                                                   >>  77         char tx_led_trig_name[CAN_LED_NAME_SZ];
                                                   >>  78         struct led_trigger *rx_led_trig;
                                                   >>  79         char rx_led_trig_name[CAN_LED_NAME_SZ];
                                                   >>  80         struct led_trigger *rxtx_led_trig;
                                                   >>  81         char rxtx_led_trig_name[CAN_LED_NAME_SZ];
                                                   >>  82 #endif
 88 };                                                 83 };
 89                                                    84 
 90 static inline bool can_tdc_is_enabled(const st !!  85 #define CAN_SYNC_SEG 1
 91 {                                              << 
 92         return !!(priv->ctrlmode & CAN_CTRLMOD << 
 93 }                                              << 
 94                                                    86 
 95 /*                                                 87 /*
 96  * can_get_relative_tdco() - TDCO relative to  !!  88  * can_bit_time() - Duration of one bit
 97  *                                             << 
 98  * struct can_tdc::tdco represents the absolut << 
 99  * controllers use instead an offset relative  << 
100  * such that:                                  << 
101  *                                                 89  *
102  * SSP = TDCV + absolute TDCO                  !!  90  * Please refer to ISO 11898-1:2015, section 11.3.1.1 "Bit time" for
103  *     = TDCV + SP + relative TDCO             !!  91  * additional information.
104  *                                                 92  *
105  * -+----------- one bit ----------+-- TX pin  !!  93  * Return: the number of time quanta in one bit.
106  *  |<--- Sample Point --->|                   << 
107  *                                             << 
108  *                         --+----------- one  << 
109  *  |<-------- TDCV -------->|                 << 
110  *                           |<--------------- << 
111  *                           |<--- Sample Poin << 
112  *                           |                 << 
113  *  |<------------- Secondary Sample Point --- << 
114  */                                                94  */
115 static inline s32 can_get_relative_tdco(const  !!  95 static inline unsigned int can_bit_time(const struct can_bittiming *bt)
116 {                                                  96 {
117         const struct can_bittiming *dbt = &pri !!  97         return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2;
118         s32 sample_point_in_tc = (CAN_SYNC_SEG !!  98 }
119                                   dbt->phase_s !!  99 
                                                   >> 100 /*
                                                   >> 101  * can_cc_dlc2len(value) - convert a given data length code (dlc) of a
                                                   >> 102  * Classical CAN frame into a valid data length of max. 8 bytes.
                                                   >> 103  *
                                                   >> 104  * To be used in the CAN netdriver receive path to ensure conformance with
                                                   >> 105  * ISO 11898-1 Chapter 8.4.2.3 (DLC field)
                                                   >> 106  */
                                                   >> 107 #define can_cc_dlc2len(dlc)     (min_t(u8, (dlc), CAN_MAX_DLEN))
120                                                   108 
121         return (s32)priv->tdc.tdco - sample_po !! 109 /* Check for outgoing skbs that have not been created by the CAN subsystem */
                                                   >> 110 static inline bool can_skb_headroom_valid(struct net_device *dev,
                                                   >> 111                                           struct sk_buff *skb)
                                                   >> 112 {
                                                   >> 113         /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
                                                   >> 114         if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
                                                   >> 115                 return false;
                                                   >> 116 
                                                   >> 117         /* af_packet does not apply CAN skb specific settings */
                                                   >> 118         if (skb->ip_summed == CHECKSUM_NONE) {
                                                   >> 119                 /* init headroom */
                                                   >> 120                 can_skb_prv(skb)->ifindex = dev->ifindex;
                                                   >> 121                 can_skb_prv(skb)->skbcnt = 0;
                                                   >> 122 
                                                   >> 123                 skb->ip_summed = CHECKSUM_UNNECESSARY;
                                                   >> 124 
                                                   >> 125                 /* perform proper loopback on capable devices */
                                                   >> 126                 if (dev->flags & IFF_ECHO)
                                                   >> 127                         skb->pkt_type = PACKET_LOOPBACK;
                                                   >> 128                 else
                                                   >> 129                         skb->pkt_type = PACKET_HOST;
                                                   >> 130 
                                                   >> 131                 skb_reset_mac_header(skb);
                                                   >> 132                 skb_reset_network_header(skb);
                                                   >> 133                 skb_reset_transport_header(skb);
                                                   >> 134         }
                                                   >> 135 
                                                   >> 136         return true;
122 }                                                 137 }
123                                                   138 
124 /* helper to define static CAN controller feat !! 139 /* Drop a given socketbuffer if it does not contain a valid CAN frame. */
125 static inline int __must_check can_set_static_ !! 140 static inline bool can_dropped_invalid_skb(struct net_device *dev,
126                                                !! 141                                           struct sk_buff *skb)
127 {                                                 142 {
128         struct can_priv *priv = netdev_priv(de !! 143         const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
129                                                   144 
130         /* alloc_candev() succeeded => netdev_ !! 145         if (skb->protocol == htons(ETH_P_CAN)) {
131         if (priv->ctrlmode_supported & static_ !! 146                 if (unlikely(skb->len != CAN_MTU ||
132                 netdev_warn(dev,               !! 147                              cfd->len > CAN_MAX_DLEN))
133                             "Controller featur !! 148                         goto inval_skb;
134                 return -EINVAL;                !! 149         } else if (skb->protocol == htons(ETH_P_CANFD)) {
135         }                                      !! 150                 if (unlikely(skb->len != CANFD_MTU ||
136         priv->ctrlmode = static_mode;          !! 151                              cfd->len > CANFD_MAX_DLEN))
                                                   >> 152                         goto inval_skb;
                                                   >> 153         } else
                                                   >> 154                 goto inval_skb;
137                                                   155 
138         /* override MTU which was set by defau !! 156         if (!can_skb_headroom_valid(dev, skb))
139         if (static_mode & CAN_CTRLMODE_FD)     !! 157                 goto inval_skb;
140                 dev->mtu = CANFD_MTU;          !! 158 
                                                   >> 159         return false;
141                                                   160 
142         return 0;                              !! 161 inval_skb:
                                                   >> 162         kfree_skb(skb);
                                                   >> 163         dev->stats.tx_dropped++;
                                                   >> 164         return true;
143 }                                                 165 }
144                                                   166 
145 static inline u32 can_get_static_ctrlmode(stru !! 167 static inline bool can_is_canfd_skb(const struct sk_buff *skb)
146 {                                                 168 {
147         return priv->ctrlmode & ~priv->ctrlmod !! 169         /* the CAN specific type of skb is identified by its data length */
                                                   >> 170         return skb->len == CANFD_MTU;
148 }                                                 171 }
149                                                   172 
150 static inline bool can_is_canxl_dev_mtu(unsign !! 173 /* helper to get the data length code (DLC) for Classical CAN raw DLC access */
                                                   >> 174 static inline u8 can_get_cc_dlc(const struct can_frame *cf, const u32 ctrlmode)
151 {                                                 175 {
152         return (mtu >= CANXL_MIN_MTU && mtu <= !! 176         /* return len8_dlc as dlc value only if all conditions apply */
                                                   >> 177         if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) &&
                                                   >> 178             (cf->len == CAN_MAX_DLEN) &&
                                                   >> 179             (cf->len8_dlc > CAN_MAX_DLEN && cf->len8_dlc <= CAN_MAX_RAW_DLC))
                                                   >> 180                 return cf->len8_dlc;
                                                   >> 181 
                                                   >> 182         /* return the payload length as dlc value */
                                                   >> 183         return cf->len;
153 }                                                 184 }
154                                                   185 
155 /* drop skb if it does not contain a valid CAN !! 186 /* helper to set len and len8_dlc value for Classical CAN raw DLC access */
156 static inline bool can_dev_dropped_skb(struct  !! 187 static inline void can_frame_set_cc_len(struct can_frame *cf, const u8 dlc,
                                                   >> 188                                         const u32 ctrlmode)
                                                   >> 189 {
                                                   >> 190         /* the caller already ensured that dlc is a value from 0 .. 15 */
                                                   >> 191         if (ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC && dlc > CAN_MAX_DLEN)
                                                   >> 192                 cf->len8_dlc = dlc;
                                                   >> 193 
                                                   >> 194         /* limit the payload length 'len' to CAN_MAX_DLEN */
                                                   >> 195         cf->len = can_cc_dlc2len(dlc);
                                                   >> 196 }
                                                   >> 197 
                                                   >> 198 /* helper to define static CAN controller features at device creation time */
                                                   >> 199 static inline void can_set_static_ctrlmode(struct net_device *dev,
                                                   >> 200                                            u32 static_mode)
157 {                                                 201 {
158         struct can_priv *priv = netdev_priv(de    202         struct can_priv *priv = netdev_priv(dev);
159                                                   203 
160         if (priv->ctrlmode & CAN_CTRLMODE_LIST !! 204         /* alloc_candev() succeeded => netdev_priv() is valid at this point */
161                 netdev_info_once(dev,          !! 205         priv->ctrlmode = static_mode;
162                                  "interface in !! 206         priv->ctrlmode_static = static_mode;
163                 kfree_skb(skb);                << 
164                 dev->stats.tx_dropped++;       << 
165                 return true;                   << 
166         }                                      << 
167                                                   207 
168         return can_dropped_invalid_skb(dev, sk !! 208         /* override MTU which was set by default in can_setup()? */
                                                   >> 209         if (static_mode & CAN_CTRLMODE_FD)
                                                   >> 210                 dev->mtu = CANFD_MTU;
169 }                                                 211 }
170                                                   212 
171 void can_setup(struct net_device *dev);        !! 213 /* get data length from raw data length code (DLC) */
                                                   >> 214 u8 can_fd_dlc2len(u8 dlc);
                                                   >> 215 
                                                   >> 216 /* map the sanitized data length to an appropriate data length code */
                                                   >> 217 u8 can_fd_len2dlc(u8 len);
172                                                   218 
173 struct net_device *alloc_candev_mqs(int sizeof    219 struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
174                                     unsigned i    220                                     unsigned int txqs, unsigned int rxqs);
175 #define alloc_candev(sizeof_priv, echo_skb_max    221 #define alloc_candev(sizeof_priv, echo_skb_max) \
176         alloc_candev_mqs(sizeof_priv, echo_skb    222         alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1)
177 #define alloc_candev_mq(sizeof_priv, echo_skb_    223 #define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \
178         alloc_candev_mqs(sizeof_priv, echo_skb    224         alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count)
179 void free_candev(struct net_device *dev);         225 void free_candev(struct net_device *dev);
180                                                   226 
181 /* a candev safe wrapper around netdev_priv */    227 /* a candev safe wrapper around netdev_priv */
182 struct can_priv *safe_candev_priv(struct net_d    228 struct can_priv *safe_candev_priv(struct net_device *dev);
183                                                   229 
184 int open_candev(struct net_device *dev);          230 int open_candev(struct net_device *dev);
185 void close_candev(struct net_device *dev);        231 void close_candev(struct net_device *dev);
186 int can_change_mtu(struct net_device *dev, int    232 int can_change_mtu(struct net_device *dev, int new_mtu);
187 int can_eth_ioctl_hwts(struct net_device *netd << 
188 int can_ethtool_op_get_ts_info_hwts(struct net << 
189                                     struct ker << 
190                                                   233 
191 int register_candev(struct net_device *dev);      234 int register_candev(struct net_device *dev);
192 void unregister_candev(struct net_device *dev)    235 void unregister_candev(struct net_device *dev);
193                                                   236 
194 int can_restart_now(struct net_device *dev);      237 int can_restart_now(struct net_device *dev);
195 void can_bus_off(struct net_device *dev);         238 void can_bus_off(struct net_device *dev);
196                                                   239 
197 const char *can_get_state_str(const enum can_s << 
198 void can_state_get_by_berr_counter(const struc << 
199                                    const struc << 
200                                    enum can_st << 
201                                    enum can_st << 
202 void can_change_state(struct net_device *dev,     240 void can_change_state(struct net_device *dev, struct can_frame *cf,
203                       enum can_state tx_state,    241                       enum can_state tx_state, enum can_state rx_state);
204                                                   242 
                                                   >> 243 int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
                                                   >> 244                      unsigned int idx);
                                                   >> 245 struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx,
                                                   >> 246                                    u8 *len_ptr);
                                                   >> 247 unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
                                                   >> 248 void can_free_echo_skb(struct net_device *dev, unsigned int idx);
                                                   >> 249 
205 #ifdef CONFIG_OF                                  250 #ifdef CONFIG_OF
206 void of_can_transceiver(struct net_device *dev    251 void of_can_transceiver(struct net_device *dev);
207 #else                                             252 #else
208 static inline void of_can_transceiver(struct n    253 static inline void of_can_transceiver(struct net_device *dev) { }
209 #endif                                            254 #endif
210                                                   255 
211 extern struct rtnl_link_ops can_link_ops;      !! 256 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf);
212 int can_netlink_register(void);                !! 257 struct sk_buff *alloc_canfd_skb(struct net_device *dev,
213 void can_netlink_unregister(void);             !! 258                                 struct canfd_frame **cfd);
                                                   >> 259 struct sk_buff *alloc_can_err_skb(struct net_device *dev,
                                                   >> 260                                   struct can_frame **cf);
214                                                   261 
215 #endif /* !_CAN_DEV_H */                          262 #endif /* !_CAN_DEV_H */
216                                                   263 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php