xref: /OK3568_Linux_fs/kernel/include/uapi/linux/usb/functionfs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun #ifndef _UAPI__LINUX_FUNCTIONFS_H__
3*4882a593Smuzhiyun #define _UAPI__LINUX_FUNCTIONFS_H__
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <linux/types.h>
7*4882a593Smuzhiyun #include <linux/ioctl.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/usb/ch9.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun enum {
13*4882a593Smuzhiyun 	FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
14*4882a593Smuzhiyun 	FUNCTIONFS_STRINGS_MAGIC = 2,
15*4882a593Smuzhiyun 	FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
16*4882a593Smuzhiyun };
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun enum functionfs_flags {
19*4882a593Smuzhiyun 	FUNCTIONFS_HAS_FS_DESC = 1,
20*4882a593Smuzhiyun 	FUNCTIONFS_HAS_HS_DESC = 2,
21*4882a593Smuzhiyun 	FUNCTIONFS_HAS_SS_DESC = 4,
22*4882a593Smuzhiyun 	FUNCTIONFS_HAS_MS_OS_DESC = 8,
23*4882a593Smuzhiyun 	FUNCTIONFS_VIRTUAL_ADDR = 16,
24*4882a593Smuzhiyun 	FUNCTIONFS_EVENTFD = 32,
25*4882a593Smuzhiyun 	FUNCTIONFS_ALL_CTRL_RECIP = 64,
26*4882a593Smuzhiyun 	FUNCTIONFS_CONFIG0_SETUP = 128,
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /* Descriptor of an non-audio endpoint */
30*4882a593Smuzhiyun struct usb_endpoint_descriptor_no_audio {
31*4882a593Smuzhiyun 	__u8  bLength;
32*4882a593Smuzhiyun 	__u8  bDescriptorType;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	__u8  bEndpointAddress;
35*4882a593Smuzhiyun 	__u8  bmAttributes;
36*4882a593Smuzhiyun 	__le16 wMaxPacketSize;
37*4882a593Smuzhiyun 	__u8  bInterval;
38*4882a593Smuzhiyun } __attribute__((packed));
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun struct usb_functionfs_descs_head_v2 {
41*4882a593Smuzhiyun 	__le32 magic;
42*4882a593Smuzhiyun 	__le32 length;
43*4882a593Smuzhiyun 	__le32 flags;
44*4882a593Smuzhiyun 	/*
45*4882a593Smuzhiyun 	 * __le32 fs_count, hs_count, fs_count; must be included manually in
46*4882a593Smuzhiyun 	 * the structure taking flags into consideration.
47*4882a593Smuzhiyun 	 */
48*4882a593Smuzhiyun } __attribute__((packed));
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* Legacy format, deprecated as of 3.14. */
51*4882a593Smuzhiyun struct usb_functionfs_descs_head {
52*4882a593Smuzhiyun 	__le32 magic;
53*4882a593Smuzhiyun 	__le32 length;
54*4882a593Smuzhiyun 	__le32 fs_count;
55*4882a593Smuzhiyun 	__le32 hs_count;
56*4882a593Smuzhiyun } __attribute__((packed, deprecated));
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* MS OS Descriptor header */
59*4882a593Smuzhiyun struct usb_os_desc_header {
60*4882a593Smuzhiyun 	__u8	interface;
61*4882a593Smuzhiyun 	__le32	dwLength;
62*4882a593Smuzhiyun 	__le16	bcdVersion;
63*4882a593Smuzhiyun 	__le16	wIndex;
64*4882a593Smuzhiyun 	union {
65*4882a593Smuzhiyun 		struct {
66*4882a593Smuzhiyun 			__u8	bCount;
67*4882a593Smuzhiyun 			__u8	Reserved;
68*4882a593Smuzhiyun 		};
69*4882a593Smuzhiyun 		__le16	wCount;
70*4882a593Smuzhiyun 	};
71*4882a593Smuzhiyun } __attribute__((packed));
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct usb_ext_compat_desc {
74*4882a593Smuzhiyun 	__u8	bFirstInterfaceNumber;
75*4882a593Smuzhiyun 	__u8	Reserved1;
76*4882a593Smuzhiyun 	__u8	CompatibleID[8];
77*4882a593Smuzhiyun 	__u8	SubCompatibleID[8];
78*4882a593Smuzhiyun 	__u8	Reserved2[6];
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun struct usb_ext_prop_desc {
82*4882a593Smuzhiyun 	__le32	dwSize;
83*4882a593Smuzhiyun 	__le32	dwPropertyDataType;
84*4882a593Smuzhiyun 	__le16	wPropertyNameLength;
85*4882a593Smuzhiyun } __attribute__((packed));
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #ifndef __KERNEL__
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /*
90*4882a593Smuzhiyun  * Descriptors format:
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * | off | name      | type         | description                          |
93*4882a593Smuzhiyun  * |-----+-----------+--------------+--------------------------------------|
94*4882a593Smuzhiyun  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
95*4882a593Smuzhiyun  * |   4 | length    | LE32         | length of the whole data chunk       |
96*4882a593Smuzhiyun  * |   8 | flags     | LE32         | combination of functionfs_flags      |
97*4882a593Smuzhiyun  * |     | eventfd   | LE32         | eventfd file descriptor              |
98*4882a593Smuzhiyun  * |     | fs_count  | LE32         | number of full-speed descriptors     |
99*4882a593Smuzhiyun  * |     | hs_count  | LE32         | number of high-speed descriptors     |
100*4882a593Smuzhiyun  * |     | ss_count  | LE32         | number of super-speed descriptors    |
101*4882a593Smuzhiyun  * |     | os_count  | LE32         | number of MS OS descriptors          |
102*4882a593Smuzhiyun  * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
103*4882a593Smuzhiyun  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
104*4882a593Smuzhiyun  * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
105*4882a593Smuzhiyun  * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  * Depending on which flags are set, various fields may be missing in the
108*4882a593Smuzhiyun  * structure.  Any flags that are not recognised cause the whole block to be
109*4882a593Smuzhiyun  * rejected with -ENOSYS.
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * Legacy descriptors format (deprecated as of 3.14):
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * | off | name      | type         | description                          |
114*4882a593Smuzhiyun  * |-----+-----------+--------------+--------------------------------------|
115*4882a593Smuzhiyun  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
116*4882a593Smuzhiyun  * |   4 | length    | LE32         | length of the whole data chunk       |
117*4882a593Smuzhiyun  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
118*4882a593Smuzhiyun  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
119*4882a593Smuzhiyun  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
120*4882a593Smuzhiyun  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
121*4882a593Smuzhiyun  *
122*4882a593Smuzhiyun  * All numbers must be in little endian order.
123*4882a593Smuzhiyun  *
124*4882a593Smuzhiyun  * Descriptor[] is an array of valid USB descriptors which have the following
125*4882a593Smuzhiyun  * format:
126*4882a593Smuzhiyun  *
127*4882a593Smuzhiyun  * | off | name            | type | description              |
128*4882a593Smuzhiyun  * |-----+-----------------+------+--------------------------|
129*4882a593Smuzhiyun  * |   0 | bLength         | U8   | length of the descriptor |
130*4882a593Smuzhiyun  * |   1 | bDescriptorType | U8   | descriptor type          |
131*4882a593Smuzhiyun  * |   2 | payload         |      | descriptor's payload     |
132*4882a593Smuzhiyun  *
133*4882a593Smuzhiyun  * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
134*4882a593Smuzhiyun  * the following formats:
135*4882a593Smuzhiyun  *
136*4882a593Smuzhiyun  * | off | name            | type | description              |
137*4882a593Smuzhiyun  * |-----+-----------------+------+--------------------------|
138*4882a593Smuzhiyun  * |   0 | inteface        | U8   | related interface number |
139*4882a593Smuzhiyun  * |   1 | dwLength        | U32  | length of the descriptor |
140*4882a593Smuzhiyun  * |   5 | bcdVersion      | U16  | currently supported: 1   |
141*4882a593Smuzhiyun  * |   7 | wIndex          | U16  | currently supported: 4   |
142*4882a593Smuzhiyun  * |   9 | bCount          | U8   | number of ext. compat.   |
143*4882a593Smuzhiyun  * |  10 | Reserved        | U8   | 0                        |
144*4882a593Smuzhiyun  * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
145*4882a593Smuzhiyun  *
146*4882a593Smuzhiyun  * | off | name            | type | description              |
147*4882a593Smuzhiyun  * |-----+-----------------+------+--------------------------|
148*4882a593Smuzhiyun  * |   0 | inteface        | U8   | related interface number |
149*4882a593Smuzhiyun  * |   1 | dwLength        | U32  | length of the descriptor |
150*4882a593Smuzhiyun  * |   5 | bcdVersion      | U16  | currently supported: 1   |
151*4882a593Smuzhiyun  * |   7 | wIndex          | U16  | currently supported: 5   |
152*4882a593Smuzhiyun  * |   9 | wCount          | U16  | number of ext. compat.   |
153*4882a593Smuzhiyun  * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
154*4882a593Smuzhiyun  *
155*4882a593Smuzhiyun  * ExtCompat[] is an array of valid Extended Compatiblity descriptors
156*4882a593Smuzhiyun  * which have the following format:
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * | off | name                  | type | description                         |
159*4882a593Smuzhiyun  * |-----+-----------------------+------+-------------------------------------|
160*4882a593Smuzhiyun  * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
161*4882a593Smuzhiyun  * |     |                       |      | interface in an IAD group           |
162*4882a593Smuzhiyun  * |   1 | Reserved              | U8   | 1                                   |
163*4882a593Smuzhiyun  * |   2 | CompatibleID          | U8[8]| compatible ID string                |
164*4882a593Smuzhiyun  * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
165*4882a593Smuzhiyun  * |  18 | Reserved              | U8[6]| 0                                   |
166*4882a593Smuzhiyun  *
167*4882a593Smuzhiyun  * ExtProp[] is an array of valid Extended Properties descriptors
168*4882a593Smuzhiyun  * which have the following format:
169*4882a593Smuzhiyun  *
170*4882a593Smuzhiyun  * | off | name                  | type | description                         |
171*4882a593Smuzhiyun  * |-----+-----------------------+------+-------------------------------------|
172*4882a593Smuzhiyun  * |   0 | dwSize                | U32  | length of the descriptor            |
173*4882a593Smuzhiyun  * |   4 | dwPropertyDataType    | U32  | 1..7                                |
174*4882a593Smuzhiyun  * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
175*4882a593Smuzhiyun  * |  10 | bPropertyName         |U8[NL]| name of this property               |
176*4882a593Smuzhiyun  * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
177*4882a593Smuzhiyun  * |14+NL| bProperty             |U8[DL]| payload of this property            |
178*4882a593Smuzhiyun  */
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun struct usb_functionfs_strings_head {
181*4882a593Smuzhiyun 	__le32 magic;
182*4882a593Smuzhiyun 	__le32 length;
183*4882a593Smuzhiyun 	__le32 str_count;
184*4882a593Smuzhiyun 	__le32 lang_count;
185*4882a593Smuzhiyun } __attribute__((packed));
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun /*
188*4882a593Smuzhiyun  * Strings format:
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * | off | name       | type                  | description                |
191*4882a593Smuzhiyun  * |-----+------------+-----------------------+----------------------------|
192*4882a593Smuzhiyun  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
193*4882a593Smuzhiyun  * |   4 | length     | LE32                  | length of the data chunk   |
194*4882a593Smuzhiyun  * |   8 | str_count  | LE32                  | number of strings          |
195*4882a593Smuzhiyun  * |  12 | lang_count | LE32                  | number of languages        |
196*4882a593Smuzhiyun  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
197*4882a593Smuzhiyun  *
198*4882a593Smuzhiyun  * For each language there is one stringtab entry (ie. there are lang_count
199*4882a593Smuzhiyun  * stringtab entires).  Each StringTab has following format:
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * | off | name    | type              | description                        |
202*4882a593Smuzhiyun  * |-----+---------+-------------------+------------------------------------|
203*4882a593Smuzhiyun  * |   0 | lang    | LE16              | language code                      |
204*4882a593Smuzhiyun  * |   2 | strings | String[str_count] | array of strings in given language |
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  * For each string there is one strings entry (ie. there are str_count
207*4882a593Smuzhiyun  * string entries).  Each String is a NUL terminated string encoded in
208*4882a593Smuzhiyun  * UTF-8.
209*4882a593Smuzhiyun  */
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun #endif
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun /*
215*4882a593Smuzhiyun  * Events are delivered on the ep0 file descriptor, when the user mode driver
216*4882a593Smuzhiyun  * reads from this file descriptor after writing the descriptors.  Don't
217*4882a593Smuzhiyun  * stop polling this descriptor.
218*4882a593Smuzhiyun  */
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun enum usb_functionfs_event_type {
221*4882a593Smuzhiyun 	FUNCTIONFS_BIND,
222*4882a593Smuzhiyun 	FUNCTIONFS_UNBIND,
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	FUNCTIONFS_ENABLE,
225*4882a593Smuzhiyun 	FUNCTIONFS_DISABLE,
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	FUNCTIONFS_SETUP,
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	FUNCTIONFS_SUSPEND,
230*4882a593Smuzhiyun 	FUNCTIONFS_RESUME
231*4882a593Smuzhiyun };
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun /* NOTE:  this structure must stay the same size and layout on
234*4882a593Smuzhiyun  * both 32-bit and 64-bit kernels.
235*4882a593Smuzhiyun  */
236*4882a593Smuzhiyun struct usb_functionfs_event {
237*4882a593Smuzhiyun 	union {
238*4882a593Smuzhiyun 		/* SETUP: packet; DATA phase i/o precedes next event
239*4882a593Smuzhiyun 		 *(setup.bmRequestType & USB_DIR_IN) flags direction */
240*4882a593Smuzhiyun 		struct usb_ctrlrequest	setup;
241*4882a593Smuzhiyun 	} __attribute__((packed)) u;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 	/* enum usb_functionfs_event_type */
244*4882a593Smuzhiyun 	__u8				type;
245*4882a593Smuzhiyun 	__u8				_pad[3];
246*4882a593Smuzhiyun } __attribute__((packed));
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun /* Endpoint ioctls */
250*4882a593Smuzhiyun /* The same as in gadgetfs */
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun /* IN transfers may be reported to the gadget driver as complete
253*4882a593Smuzhiyun  *	when the fifo is loaded, before the host reads the data;
254*4882a593Smuzhiyun  * OUT transfers may be reported to the host's "client" driver as
255*4882a593Smuzhiyun  *	complete when they're sitting in the FIFO unread.
256*4882a593Smuzhiyun  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
257*4882a593Smuzhiyun  * (needed for precise fault handling, when the hardware allows it)
258*4882a593Smuzhiyun  */
259*4882a593Smuzhiyun #define	FUNCTIONFS_FIFO_STATUS	_IO('g', 1)
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun /* discards any unclaimed data in the fifo. */
262*4882a593Smuzhiyun #define	FUNCTIONFS_FIFO_FLUSH	_IO('g', 2)
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /* resets endpoint halt+toggle; used to implement set_interface.
265*4882a593Smuzhiyun  * some hardware (like pxa2xx) can't support this.
266*4882a593Smuzhiyun  */
267*4882a593Smuzhiyun #define	FUNCTIONFS_CLEAR_HALT	_IO('g', 3)
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun /* Specific for functionfs */
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun /*
272*4882a593Smuzhiyun  * Returns reverse mapping of an interface.  Called on EP0.  If there
273*4882a593Smuzhiyun  * is no such interface returns -EDOM.  If function is not active
274*4882a593Smuzhiyun  * returns -ENODEV.
275*4882a593Smuzhiyun  */
276*4882a593Smuzhiyun #define	FUNCTIONFS_INTERFACE_REVMAP	_IO('g', 128)
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /*
279*4882a593Smuzhiyun  * Returns real bEndpointAddress of an endpoint. If endpoint shuts down
280*4882a593Smuzhiyun  * during the call, returns -ESHUTDOWN.
281*4882a593Smuzhiyun  */
282*4882a593Smuzhiyun #define	FUNCTIONFS_ENDPOINT_REVMAP	_IO('g', 129)
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun /*
285*4882a593Smuzhiyun  * Returns endpoint descriptor. If endpoint shuts down during the call,
286*4882a593Smuzhiyun  * returns -ESHUTDOWN.
287*4882a593Smuzhiyun  */
288*4882a593Smuzhiyun #define	FUNCTIONFS_ENDPOINT_DESC	_IOR('g', 130, \
289*4882a593Smuzhiyun 					     struct usb_endpoint_descriptor)
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
294