xref: /linux-6.15/include/uapi/linux/usb/functionfs.h (revision 1df22b4e)
15e1ddb48SDavid Howells #ifndef _UAPI__LINUX_FUNCTIONFS_H__
25e1ddb48SDavid Howells #define _UAPI__LINUX_FUNCTIONFS_H__
35e1ddb48SDavid Howells 
45e1ddb48SDavid Howells 
55e1ddb48SDavid Howells #include <linux/types.h>
65e1ddb48SDavid Howells #include <linux/ioctl.h>
75e1ddb48SDavid Howells 
85e1ddb48SDavid Howells #include <linux/usb/ch9.h>
95e1ddb48SDavid Howells 
105e1ddb48SDavid Howells 
115e1ddb48SDavid Howells enum {
125e1ddb48SDavid Howells 	FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13ac8dde11SMichal Nazarewicz 	FUNCTIONFS_STRINGS_MAGIC = 2,
14ac8dde11SMichal Nazarewicz 	FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
155e1ddb48SDavid Howells };
165e1ddb48SDavid Howells 
17ac8dde11SMichal Nazarewicz enum functionfs_flags {
18ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_FS_DESC = 1,
19ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_HS_DESC = 2,
20ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_SS_DESC = 4,
21f0175ab5SAndrzej Pietrasiewicz 	FUNCTIONFS_HAS_MS_OS_DESC = 8,
22ac8dde11SMichal Nazarewicz };
235e1ddb48SDavid Howells 
245e1ddb48SDavid Howells /* Descriptor of an non-audio endpoint */
255e1ddb48SDavid Howells struct usb_endpoint_descriptor_no_audio {
265e1ddb48SDavid Howells 	__u8  bLength;
275e1ddb48SDavid Howells 	__u8  bDescriptorType;
285e1ddb48SDavid Howells 
295e1ddb48SDavid Howells 	__u8  bEndpointAddress;
305e1ddb48SDavid Howells 	__u8  bmAttributes;
315e1ddb48SDavid Howells 	__le16 wMaxPacketSize;
325e1ddb48SDavid Howells 	__u8  bInterval;
335e1ddb48SDavid Howells } __attribute__((packed));
345e1ddb48SDavid Howells 
35*1df22b4eSMichal Nazarewicz struct usb_functionfs_descs_head_v2 {
36*1df22b4eSMichal Nazarewicz 	__le32 magic;
37*1df22b4eSMichal Nazarewicz 	__le32 length;
38*1df22b4eSMichal Nazarewicz 	__le32 flags;
39*1df22b4eSMichal Nazarewicz 	/*
40*1df22b4eSMichal Nazarewicz 	 * __le32 fs_count, hs_count, fs_count; must be included manually in
41*1df22b4eSMichal Nazarewicz 	 * the structure taking flags into consideration.
42*1df22b4eSMichal Nazarewicz 	 */
43*1df22b4eSMichal Nazarewicz } __attribute__((packed));
44*1df22b4eSMichal Nazarewicz 
4509122141SMichal Nazarewicz /* Legacy format, deprecated as of 3.14. */
4609122141SMichal Nazarewicz struct usb_functionfs_descs_head {
4709122141SMichal Nazarewicz 	__le32 magic;
4809122141SMichal Nazarewicz 	__le32 length;
4909122141SMichal Nazarewicz 	__le32 fs_count;
5009122141SMichal Nazarewicz 	__le32 hs_count;
5109122141SMichal Nazarewicz } __attribute__((packed, deprecated));
525e1ddb48SDavid Howells 
53f0175ab5SAndrzej Pietrasiewicz /* MS OS Descriptor header */
54f0175ab5SAndrzej Pietrasiewicz struct usb_os_desc_header {
55f0175ab5SAndrzej Pietrasiewicz 	__u8	interface;
56f0175ab5SAndrzej Pietrasiewicz 	__le32	dwLength;
57f0175ab5SAndrzej Pietrasiewicz 	__le16	bcdVersion;
58f0175ab5SAndrzej Pietrasiewicz 	__le16	wIndex;
59f0175ab5SAndrzej Pietrasiewicz 	union {
60f0175ab5SAndrzej Pietrasiewicz 		struct {
61f0175ab5SAndrzej Pietrasiewicz 			__u8	bCount;
62f0175ab5SAndrzej Pietrasiewicz 			__u8	Reserved;
63f0175ab5SAndrzej Pietrasiewicz 		};
64f0175ab5SAndrzej Pietrasiewicz 		__le16	wCount;
65f0175ab5SAndrzej Pietrasiewicz 	};
66f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed));
67f0175ab5SAndrzej Pietrasiewicz 
68f0175ab5SAndrzej Pietrasiewicz struct usb_ext_compat_desc {
69f0175ab5SAndrzej Pietrasiewicz 	__u8	bFirstInterfaceNumber;
70f0175ab5SAndrzej Pietrasiewicz 	__u8	Reserved1;
71f0175ab5SAndrzej Pietrasiewicz 	__u8	CompatibleID[8];
72f0175ab5SAndrzej Pietrasiewicz 	__u8	SubCompatibleID[8];
73f0175ab5SAndrzej Pietrasiewicz 	__u8	Reserved2[6];
74f0175ab5SAndrzej Pietrasiewicz };
75f0175ab5SAndrzej Pietrasiewicz 
76f0175ab5SAndrzej Pietrasiewicz struct usb_ext_prop_desc {
77f0175ab5SAndrzej Pietrasiewicz 	__le32	dwSize;
78f0175ab5SAndrzej Pietrasiewicz 	__le32	dwPropertyDataType;
79f0175ab5SAndrzej Pietrasiewicz 	__le16	wPropertyNameLength;
80f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed));
81f0175ab5SAndrzej Pietrasiewicz 
82f0175ab5SAndrzej Pietrasiewicz #ifndef __KERNEL__
835e1ddb48SDavid Howells 
845e1ddb48SDavid Howells /*
855e1ddb48SDavid Howells  * Descriptors format:
865e1ddb48SDavid Howells  *
875e1ddb48SDavid Howells  * | off | name      | type         | description                          |
885e1ddb48SDavid Howells  * |-----+-----------+--------------+--------------------------------------|
89ac8dde11SMichal Nazarewicz  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
90ac8dde11SMichal Nazarewicz  * |   4 | length    | LE32         | length of the whole data chunk       |
91ac8dde11SMichal Nazarewicz  * |   8 | flags     | LE32         | combination of functionfs_flags      |
92ac8dde11SMichal Nazarewicz  * |     | fs_count  | LE32         | number of full-speed descriptors     |
93ac8dde11SMichal Nazarewicz  * |     | hs_count  | LE32         | number of high-speed descriptors     |
94ac8dde11SMichal Nazarewicz  * |     | ss_count  | LE32         | number of super-speed descriptors    |
95f0175ab5SAndrzej Pietrasiewicz  * |     | os_count  | LE32         | number of MS OS descriptors          |
96ac8dde11SMichal Nazarewicz  * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
97ac8dde11SMichal Nazarewicz  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
98ac8dde11SMichal Nazarewicz  * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
99f0175ab5SAndrzej Pietrasiewicz  * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
100ac8dde11SMichal Nazarewicz  *
101ac8dde11SMichal Nazarewicz  * Depending on which flags are set, various fields may be missing in the
102ac8dde11SMichal Nazarewicz  * structure.  Any flags that are not recognised cause the whole block to be
103ac8dde11SMichal Nazarewicz  * rejected with -ENOSYS.
104ac8dde11SMichal Nazarewicz  *
1059ad78604SFelipe Balbi  * Legacy descriptors format:
106ac8dde11SMichal Nazarewicz  *
107ac8dde11SMichal Nazarewicz  * | off | name      | type         | description                          |
108ac8dde11SMichal Nazarewicz  * |-----+-----------+--------------+--------------------------------------|
109ac8dde11SMichal Nazarewicz  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
1105e1ddb48SDavid Howells  * |   4 | length    | LE32         | length of the whole data chunk       |
1115e1ddb48SDavid Howells  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
1125e1ddb48SDavid Howells  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
1135e1ddb48SDavid Howells  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
1145e1ddb48SDavid Howells  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
1155e1ddb48SDavid Howells  *
116ac8dde11SMichal Nazarewicz  * All numbers must be in little endian order.
117ac8dde11SMichal Nazarewicz  *
118ac8dde11SMichal Nazarewicz  * Descriptor[] is an array of valid USB descriptors which have the following
119ac8dde11SMichal Nazarewicz  * format:
1205e1ddb48SDavid Howells  *
1215e1ddb48SDavid Howells  * | off | name            | type | description              |
1225e1ddb48SDavid Howells  * |-----+-----------------+------+--------------------------|
1235e1ddb48SDavid Howells  * |   0 | bLength         | U8   | length of the descriptor |
1245e1ddb48SDavid Howells  * |   1 | bDescriptorType | U8   | descriptor type          |
1255e1ddb48SDavid Howells  * |   2 | payload         |      | descriptor's payload     |
126f0175ab5SAndrzej Pietrasiewicz  *
127f0175ab5SAndrzej Pietrasiewicz  * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
128f0175ab5SAndrzej Pietrasiewicz  * the following formats:
129f0175ab5SAndrzej Pietrasiewicz  *
130f0175ab5SAndrzej Pietrasiewicz  * | off | name            | type | description              |
131f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------+------+--------------------------|
132f0175ab5SAndrzej Pietrasiewicz  * |   0 | inteface        | U8   | related interface number |
133f0175ab5SAndrzej Pietrasiewicz  * |   1 | dwLength        | U32  | length of the descriptor |
134f0175ab5SAndrzej Pietrasiewicz  * |   5 | bcdVersion      | U16  | currently supported: 1   |
135f0175ab5SAndrzej Pietrasiewicz  * |   7 | wIndex          | U16  | currently supported: 4   |
136f0175ab5SAndrzej Pietrasiewicz  * |   9 | bCount          | U8   | number of ext. compat.   |
137f0175ab5SAndrzej Pietrasiewicz  * |  10 | Reserved        | U8   | 0                        |
138f0175ab5SAndrzej Pietrasiewicz  * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
139f0175ab5SAndrzej Pietrasiewicz  *
140f0175ab5SAndrzej Pietrasiewicz  * | off | name            | type | description              |
141f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------+------+--------------------------|
142f0175ab5SAndrzej Pietrasiewicz  * |   0 | inteface        | U8   | related interface number |
143f0175ab5SAndrzej Pietrasiewicz  * |   1 | dwLength        | U32  | length of the descriptor |
144f0175ab5SAndrzej Pietrasiewicz  * |   5 | bcdVersion      | U16  | currently supported: 1   |
145f0175ab5SAndrzej Pietrasiewicz  * |   7 | wIndex          | U16  | currently supported: 5   |
146f0175ab5SAndrzej Pietrasiewicz  * |   9 | wCount          | U16  | number of ext. compat.   |
147f0175ab5SAndrzej Pietrasiewicz  * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
148f0175ab5SAndrzej Pietrasiewicz  *
149f0175ab5SAndrzej Pietrasiewicz  * ExtCompat[] is an array of valid Extended Compatiblity descriptors
150f0175ab5SAndrzej Pietrasiewicz  * which have the following format:
151f0175ab5SAndrzej Pietrasiewicz  *
152f0175ab5SAndrzej Pietrasiewicz  * | off | name                  | type | description                         |
153f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------------+------+-------------------------------------|
154f0175ab5SAndrzej Pietrasiewicz  * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
155f0175ab5SAndrzej Pietrasiewicz  * |     |                       |      | interface in an IAD group           |
156f0175ab5SAndrzej Pietrasiewicz  * |   1 | Reserved              | U8   | 0                                   |
157f0175ab5SAndrzej Pietrasiewicz  * |   2 | CompatibleID          | U8[8]| compatible ID string                |
158f0175ab5SAndrzej Pietrasiewicz  * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
159f0175ab5SAndrzej Pietrasiewicz  * |  18 | Reserved              | U8[6]| 0                                   |
160f0175ab5SAndrzej Pietrasiewicz  *
161f0175ab5SAndrzej Pietrasiewicz  * ExtProp[] is an array of valid Extended Properties descriptors
162f0175ab5SAndrzej Pietrasiewicz  * which have the following format:
163f0175ab5SAndrzej Pietrasiewicz  *
164f0175ab5SAndrzej Pietrasiewicz  * | off | name                  | type | description                         |
165f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------------+------+-------------------------------------|
166f0175ab5SAndrzej Pietrasiewicz  * |   0 | dwSize                | U32  | length of the descriptor            |
167f0175ab5SAndrzej Pietrasiewicz  * |   4 | dwPropertyDataType    | U32  | 1..7                                |
168f0175ab5SAndrzej Pietrasiewicz  * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
169f0175ab5SAndrzej Pietrasiewicz  * |  10 | bPropertyName         |U8[NL]| name of this property               |
170f0175ab5SAndrzej Pietrasiewicz  * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
171f0175ab5SAndrzej Pietrasiewicz  * |14+NL| bProperty             |U8[DL]| payload of this property            |
1725e1ddb48SDavid Howells  */
1735e1ddb48SDavid Howells 
1745e1ddb48SDavid Howells struct usb_functionfs_strings_head {
1755e1ddb48SDavid Howells 	__le32 magic;
1765e1ddb48SDavid Howells 	__le32 length;
1775e1ddb48SDavid Howells 	__le32 str_count;
1785e1ddb48SDavid Howells 	__le32 lang_count;
1795e1ddb48SDavid Howells } __attribute__((packed));
1805e1ddb48SDavid Howells 
1815e1ddb48SDavid Howells /*
1825e1ddb48SDavid Howells  * Strings format:
1835e1ddb48SDavid Howells  *
1845e1ddb48SDavid Howells  * | off | name       | type                  | description                |
1855e1ddb48SDavid Howells  * |-----+------------+-----------------------+----------------------------|
1865e1ddb48SDavid Howells  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
1875e1ddb48SDavid Howells  * |   4 | length     | LE32                  | length of the data chunk   |
1885e1ddb48SDavid Howells  * |   8 | str_count  | LE32                  | number of strings          |
1895e1ddb48SDavid Howells  * |  12 | lang_count | LE32                  | number of languages        |
1905e1ddb48SDavid Howells  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
1915e1ddb48SDavid Howells  *
1925e1ddb48SDavid Howells  * For each language there is one stringtab entry (ie. there are lang_count
1935e1ddb48SDavid Howells  * stringtab entires).  Each StringTab has following format:
1945e1ddb48SDavid Howells  *
1955e1ddb48SDavid Howells  * | off | name    | type              | description                        |
1965e1ddb48SDavid Howells  * |-----+---------+-------------------+------------------------------------|
1975e1ddb48SDavid Howells  * |   0 | lang    | LE16              | language code                      |
1985e1ddb48SDavid Howells  * |   2 | strings | String[str_count] | array of strings in given language |
1995e1ddb48SDavid Howells  *
2005e1ddb48SDavid Howells  * For each string there is one strings entry (ie. there are str_count
2015e1ddb48SDavid Howells  * string entries).  Each String is a NUL terminated string encoded in
2025e1ddb48SDavid Howells  * UTF-8.
2035e1ddb48SDavid Howells  */
2045e1ddb48SDavid Howells 
2055e1ddb48SDavid Howells #endif
2065e1ddb48SDavid Howells 
2075e1ddb48SDavid Howells 
2085e1ddb48SDavid Howells /*
2095e1ddb48SDavid Howells  * Events are delivered on the ep0 file descriptor, when the user mode driver
2105e1ddb48SDavid Howells  * reads from this file descriptor after writing the descriptors.  Don't
2115e1ddb48SDavid Howells  * stop polling this descriptor.
2125e1ddb48SDavid Howells  */
2135e1ddb48SDavid Howells 
2145e1ddb48SDavid Howells enum usb_functionfs_event_type {
2155e1ddb48SDavid Howells 	FUNCTIONFS_BIND,
2165e1ddb48SDavid Howells 	FUNCTIONFS_UNBIND,
2175e1ddb48SDavid Howells 
2185e1ddb48SDavid Howells 	FUNCTIONFS_ENABLE,
2195e1ddb48SDavid Howells 	FUNCTIONFS_DISABLE,
2205e1ddb48SDavid Howells 
2215e1ddb48SDavid Howells 	FUNCTIONFS_SETUP,
2225e1ddb48SDavid Howells 
2235e1ddb48SDavid Howells 	FUNCTIONFS_SUSPEND,
2245e1ddb48SDavid Howells 	FUNCTIONFS_RESUME
2255e1ddb48SDavid Howells };
2265e1ddb48SDavid Howells 
2275e1ddb48SDavid Howells /* NOTE:  this structure must stay the same size and layout on
2285e1ddb48SDavid Howells  * both 32-bit and 64-bit kernels.
2295e1ddb48SDavid Howells  */
2305e1ddb48SDavid Howells struct usb_functionfs_event {
2315e1ddb48SDavid Howells 	union {
2325e1ddb48SDavid Howells 		/* SETUP: packet; DATA phase i/o precedes next event
2335e1ddb48SDavid Howells 		 *(setup.bmRequestType & USB_DIR_IN) flags direction */
2345e1ddb48SDavid Howells 		struct usb_ctrlrequest	setup;
2355e1ddb48SDavid Howells 	} __attribute__((packed)) u;
2365e1ddb48SDavid Howells 
2375e1ddb48SDavid Howells 	/* enum usb_functionfs_event_type */
2385e1ddb48SDavid Howells 	__u8				type;
2395e1ddb48SDavid Howells 	__u8				_pad[3];
2405e1ddb48SDavid Howells } __attribute__((packed));
2415e1ddb48SDavid Howells 
2425e1ddb48SDavid Howells 
2435e1ddb48SDavid Howells /* Endpoint ioctls */
2445e1ddb48SDavid Howells /* The same as in gadgetfs */
2455e1ddb48SDavid Howells 
2465e1ddb48SDavid Howells /* IN transfers may be reported to the gadget driver as complete
2475e1ddb48SDavid Howells  *	when the fifo is loaded, before the host reads the data;
2485e1ddb48SDavid Howells  * OUT transfers may be reported to the host's "client" driver as
2495e1ddb48SDavid Howells  *	complete when they're sitting in the FIFO unread.
2505e1ddb48SDavid Howells  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
2515e1ddb48SDavid Howells  * (needed for precise fault handling, when the hardware allows it)
2525e1ddb48SDavid Howells  */
2535e1ddb48SDavid Howells #define	FUNCTIONFS_FIFO_STATUS	_IO('g', 1)
2545e1ddb48SDavid Howells 
2555e1ddb48SDavid Howells /* discards any unclaimed data in the fifo. */
2565e1ddb48SDavid Howells #define	FUNCTIONFS_FIFO_FLUSH	_IO('g', 2)
2575e1ddb48SDavid Howells 
2585e1ddb48SDavid Howells /* resets endpoint halt+toggle; used to implement set_interface.
2595e1ddb48SDavid Howells  * some hardware (like pxa2xx) can't support this.
2605e1ddb48SDavid Howells  */
2615e1ddb48SDavid Howells #define	FUNCTIONFS_CLEAR_HALT	_IO('g', 3)
2625e1ddb48SDavid Howells 
2635e1ddb48SDavid Howells /* Specific for functionfs */
2645e1ddb48SDavid Howells 
2655e1ddb48SDavid Howells /*
2665e1ddb48SDavid Howells  * Returns reverse mapping of an interface.  Called on EP0.  If there
2675e1ddb48SDavid Howells  * is no such interface returns -EDOM.  If function is not active
2685e1ddb48SDavid Howells  * returns -ENODEV.
2695e1ddb48SDavid Howells  */
2705e1ddb48SDavid Howells #define	FUNCTIONFS_INTERFACE_REVMAP	_IO('g', 128)
2715e1ddb48SDavid Howells 
2725e1ddb48SDavid Howells /*
2735e1ddb48SDavid Howells  * Returns real bEndpointAddress of an endpoint.  If function is not
2745e1ddb48SDavid Howells  * active returns -ENODEV.
2755e1ddb48SDavid Howells  */
2765e1ddb48SDavid Howells #define	FUNCTIONFS_ENDPOINT_REVMAP	_IO('g', 129)
2775e1ddb48SDavid Howells 
2785e1ddb48SDavid Howells 
2795e1ddb48SDavid Howells 
2805e1ddb48SDavid Howells #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
281