xref: /linux/include/uapi/linux/can/netlink.h (revision 8f7aa3d3c7323f4ca2768a9e74ebbe359c4f8f88)
1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2 /*
3  * linux/can/netlink.h
4  *
5  * Definitions for the CAN netlink interface
6  *
7  * Copyright (c) 2009 Wolfgang Grandegger <wg@grandegger.com>
8  * Copyright (c) 2021-2025 Vincent Mailhol <mailhol@kernel.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the version 2 of the GNU General Public License
12  * as published by the Free Software Foundation
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  */
19 
20 #ifndef _UAPI_CAN_NETLINK_H
21 #define _UAPI_CAN_NETLINK_H
22 
23 #include <linux/types.h>
24 
25 /*
26  * CAN bit-timing parameters
27  *
28  * For further information, please read chapter "8 BIT TIMING
29  * REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
30  * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
31  */
32 struct can_bittiming {
33 	__u32 bitrate;		/* Bit-rate in bits/second */
34 	__u32 sample_point;	/* Sample point in one-tenth of a percent */
35 	__u32 tq;		/* Time quanta (TQ) in nanoseconds */
36 	__u32 prop_seg;		/* Propagation segment in TQs */
37 	__u32 phase_seg1;	/* Phase buffer segment 1 in TQs */
38 	__u32 phase_seg2;	/* Phase buffer segment 2 in TQs */
39 	__u32 sjw;		/* Synchronisation jump width in TQs */
40 	__u32 brp;		/* Bit-rate prescaler */
41 };
42 
43 /*
44  * CAN hardware-dependent bit-timing constant
45  *
46  * Used for calculating and checking bit-timing parameters
47  */
48 struct can_bittiming_const {
49 	char name[16];		/* Name of the CAN controller hardware */
50 	__u32 tseg1_min;	/* Time segment 1 = prop_seg + phase_seg1 */
51 	__u32 tseg1_max;
52 	__u32 tseg2_min;	/* Time segment 2 = phase_seg2 */
53 	__u32 tseg2_max;
54 	__u32 sjw_max;		/* Synchronisation jump width */
55 	__u32 brp_min;		/* Bit-rate prescaler */
56 	__u32 brp_max;
57 	__u32 brp_inc;
58 };
59 
60 /*
61  * CAN clock parameters
62  */
63 struct can_clock {
64 	__u32 freq;		/* CAN system clock frequency in Hz */
65 };
66 
67 /*
68  * CAN operational and error states
69  */
70 enum can_state {
71 	CAN_STATE_ERROR_ACTIVE = 0,	/* RX/TX error count < 96 */
72 	CAN_STATE_ERROR_WARNING,	/* RX/TX error count < 128 */
73 	CAN_STATE_ERROR_PASSIVE,	/* RX/TX error count < 256 */
74 	CAN_STATE_BUS_OFF,		/* RX/TX error count >= 256 */
75 	CAN_STATE_STOPPED,		/* Device is stopped */
76 	CAN_STATE_SLEEPING,		/* Device is sleeping */
77 	CAN_STATE_MAX
78 };
79 
80 /*
81  * CAN bus error counters
82  */
83 struct can_berr_counter {
84 	__u16 txerr;
85 	__u16 rxerr;
86 };
87 
88 /*
89  * CAN controller mode
90  */
91 struct can_ctrlmode {
92 	__u32 mask;
93 	__u32 flags;
94 };
95 
96 #define CAN_CTRLMODE_LOOPBACK		0x01	/* Loopback mode */
97 #define CAN_CTRLMODE_LISTENONLY		0x02	/* Listen-only mode */
98 #define CAN_CTRLMODE_3_SAMPLES		0x04	/* Triple sampling mode */
99 #define CAN_CTRLMODE_ONE_SHOT		0x08	/* One-Shot mode */
100 #define CAN_CTRLMODE_BERR_REPORTING	0x10	/* Bus-error reporting */
101 #define CAN_CTRLMODE_FD			0x20	/* CAN FD mode */
102 #define CAN_CTRLMODE_PRESUME_ACK	0x40	/* Ignore missing CAN ACKs */
103 #define CAN_CTRLMODE_FD_NON_ISO		0x80	/* CAN FD in non-ISO mode */
104 #define CAN_CTRLMODE_CC_LEN8_DLC	0x100	/* Classic CAN DLC option */
105 #define CAN_CTRLMODE_TDC_AUTO		0x200	/* FD transceiver automatically calculates TDCV */
106 #define CAN_CTRLMODE_TDC_MANUAL		0x400	/* FD TDCV is manually set up by user */
107 #define CAN_CTRLMODE_RESTRICTED		0x800	/* Restricted operation mode */
108 #define CAN_CTRLMODE_XL			0x1000	/* CAN XL mode */
109 #define CAN_CTRLMODE_XL_TDC_AUTO	0x2000	/* XL transceiver automatically calculates TDCV */
110 #define CAN_CTRLMODE_XL_TDC_MANUAL	0x4000	/* XL TDCV is manually set up by user */
111 #define CAN_CTRLMODE_XL_TMS		0x8000	/* Transceiver Mode Switching */
112 
113 /*
114  * CAN device statistics
115  */
116 struct can_device_stats {
117 	__u32 bus_error;	/* Bus errors */
118 	__u32 error_warning;	/* Changes to error warning state */
119 	__u32 error_passive;	/* Changes to error passive state */
120 	__u32 bus_off;		/* Changes to bus off state */
121 	__u32 arbitration_lost; /* Arbitration lost errors */
122 	__u32 restarts;		/* CAN controller re-starts */
123 };
124 
125 /*
126  * CAN netlink interface
127  */
128 enum {
129 	IFLA_CAN_UNSPEC,
130 	IFLA_CAN_BITTIMING,
131 	IFLA_CAN_BITTIMING_CONST,
132 	IFLA_CAN_CLOCK,
133 	IFLA_CAN_STATE,
134 	IFLA_CAN_CTRLMODE,
135 	IFLA_CAN_RESTART_MS,
136 	IFLA_CAN_RESTART,
137 	IFLA_CAN_BERR_COUNTER,
138 	IFLA_CAN_DATA_BITTIMING, /* FD */
139 	IFLA_CAN_DATA_BITTIMING_CONST, /* FD */
140 	IFLA_CAN_TERMINATION,
141 	IFLA_CAN_TERMINATION_CONST,
142 	IFLA_CAN_BITRATE_CONST,
143 	IFLA_CAN_DATA_BITRATE_CONST, /* FD */
144 	IFLA_CAN_BITRATE_MAX,
145 	IFLA_CAN_TDC, /* FD */
146 	IFLA_CAN_CTRLMODE_EXT,
147 	IFLA_CAN_XL_DATA_BITTIMING,
148 	IFLA_CAN_XL_DATA_BITTIMING_CONST,
149 	IFLA_CAN_XL_DATA_BITRATE_CONST,
150 	IFLA_CAN_XL_TDC,
151 	IFLA_CAN_XL_PWM,
152 
153 	/* add new constants above here */
154 	__IFLA_CAN_MAX,
155 	IFLA_CAN_MAX = __IFLA_CAN_MAX - 1
156 };
157 
158 /*
159  * CAN FD/XL Transmitter Delay Compensation (TDC)
160  *
161  * Please refer to struct can_tdc_const and can_tdc in
162  * include/linux/can/bittiming.h for further details.
163  */
164 enum {
165 	IFLA_CAN_TDC_UNSPEC,
166 	IFLA_CAN_TDC_TDCV_MIN,	/* u32 */
167 	IFLA_CAN_TDC_TDCV_MAX,	/* u32 */
168 	IFLA_CAN_TDC_TDCO_MIN,	/* u32 */
169 	IFLA_CAN_TDC_TDCO_MAX,	/* u32 */
170 	IFLA_CAN_TDC_TDCF_MIN,	/* u32 */
171 	IFLA_CAN_TDC_TDCF_MAX,	/* u32 */
172 	IFLA_CAN_TDC_TDCV,	/* u32 */
173 	IFLA_CAN_TDC_TDCO,	/* u32 */
174 	IFLA_CAN_TDC_TDCF,	/* u32 */
175 
176 	/* add new constants above here */
177 	__IFLA_CAN_TDC,
178 	IFLA_CAN_TDC_MAX = __IFLA_CAN_TDC - 1
179 };
180 
181 /*
182  * IFLA_CAN_CTRLMODE_EXT nest: controller mode extended parameters
183  */
184 enum {
185 	IFLA_CAN_CTRLMODE_UNSPEC,
186 	IFLA_CAN_CTRLMODE_SUPPORTED,	/* u32 */
187 
188 	/* add new constants above here */
189 	__IFLA_CAN_CTRLMODE,
190 	IFLA_CAN_CTRLMODE_MAX = __IFLA_CAN_CTRLMODE - 1
191 };
192 
193 /*
194  * CAN FD/XL Pulse-Width Modulation (PWM)
195  *
196  * Please refer to struct can_pwm_const and can_pwm in
197  * include/linux/can/bittiming.h for further details.
198  */
199 enum {
200 	IFLA_CAN_PWM_UNSPEC,
201 	IFLA_CAN_PWM_PWMS_MIN,	/* u32 */
202 	IFLA_CAN_PWM_PWMS_MAX,	/* u32 */
203 	IFLA_CAN_PWM_PWML_MIN,	/* u32 */
204 	IFLA_CAN_PWM_PWML_MAX,	/* u32 */
205 	IFLA_CAN_PWM_PWMO_MIN,	/* u32 */
206 	IFLA_CAN_PWM_PWMO_MAX,	/* u32 */
207 	IFLA_CAN_PWM_PWMS,	/* u32 */
208 	IFLA_CAN_PWM_PWML,	/* u32 */
209 	IFLA_CAN_PWM_PWMO,	/* u32 */
210 
211 	/* add new constants above here */
212 	__IFLA_CAN_PWM,
213 	IFLA_CAN_PWM_MAX = __IFLA_CAN_PWM - 1
214 };
215 
216 /* u16 termination range: 1..65535 Ohms */
217 #define CAN_TERMINATION_DISABLED 0
218 
219 #endif /* !_UAPI_CAN_NETLINK_H */
220