xref: /linux-6.15/include/uapi/linux/usb/functionfs.h (revision 09122141)
1 #ifndef _UAPI__LINUX_FUNCTIONFS_H__
2 #define _UAPI__LINUX_FUNCTIONFS_H__
3 
4 
5 #include <linux/types.h>
6 #include <linux/ioctl.h>
7 
8 #include <linux/usb/ch9.h>
9 
10 
11 enum {
12 	FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13 	FUNCTIONFS_STRINGS_MAGIC = 2,
14 	FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
15 };
16 
17 enum functionfs_flags {
18 	FUNCTIONFS_HAS_FS_DESC = 1,
19 	FUNCTIONFS_HAS_HS_DESC = 2,
20 	FUNCTIONFS_HAS_SS_DESC = 4,
21 };
22 
23 #ifndef __KERNEL__
24 
25 /* Descriptor of an non-audio endpoint */
26 struct usb_endpoint_descriptor_no_audio {
27 	__u8  bLength;
28 	__u8  bDescriptorType;
29 
30 	__u8  bEndpointAddress;
31 	__u8  bmAttributes;
32 	__le16 wMaxPacketSize;
33 	__u8  bInterval;
34 } __attribute__((packed));
35 
36 /* Legacy format, deprecated as of 3.14. */
37 struct usb_functionfs_descs_head {
38 	__le32 magic;
39 	__le32 length;
40 	__le32 fs_count;
41 	__le32 hs_count;
42 } __attribute__((packed, deprecated));
43 
44 /*
45  * Descriptors format:
46  *
47  * | off | name      | type         | description                          |
48  * |-----+-----------+--------------+--------------------------------------|
49  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
50  * |   4 | length    | LE32         | length of the whole data chunk       |
51  * |   8 | flags     | LE32         | combination of functionfs_flags      |
52  * |     | fs_count  | LE32         | number of full-speed descriptors     |
53  * |     | hs_count  | LE32         | number of high-speed descriptors     |
54  * |     | ss_count  | LE32         | number of super-speed descriptors    |
55  * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
56  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
57  * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
58  *
59  * Depending on which flags are set, various fields may be missing in the
60  * structure.  Any flags that are not recognised cause the whole block to be
61  * rejected with -ENOSYS.
62  *
63  * Legacy descriptors format:
64  *
65  * | off | name      | type         | description                          |
66  * |-----+-----------+--------------+--------------------------------------|
67  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
68  * |   4 | length    | LE32         | length of the whole data chunk       |
69  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
70  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
71  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
72  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
73  *
74  * All numbers must be in little endian order.
75  *
76  * Descriptor[] is an array of valid USB descriptors which have the following
77  * format:
78  *
79  * | off | name            | type | description              |
80  * |-----+-----------------+------+--------------------------|
81  * |   0 | bLength         | U8   | length of the descriptor |
82  * |   1 | bDescriptorType | U8   | descriptor type          |
83  * |   2 | payload         |      | descriptor's payload     |
84  */
85 
86 struct usb_functionfs_strings_head {
87 	__le32 magic;
88 	__le32 length;
89 	__le32 str_count;
90 	__le32 lang_count;
91 } __attribute__((packed));
92 
93 /*
94  * Strings format:
95  *
96  * | off | name       | type                  | description                |
97  * |-----+------------+-----------------------+----------------------------|
98  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
99  * |   4 | length     | LE32                  | length of the data chunk   |
100  * |   8 | str_count  | LE32                  | number of strings          |
101  * |  12 | lang_count | LE32                  | number of languages        |
102  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
103  *
104  * For each language there is one stringtab entry (ie. there are lang_count
105  * stringtab entires).  Each StringTab has following format:
106  *
107  * | off | name    | type              | description                        |
108  * |-----+---------+-------------------+------------------------------------|
109  * |   0 | lang    | LE16              | language code                      |
110  * |   2 | strings | String[str_count] | array of strings in given language |
111  *
112  * For each string there is one strings entry (ie. there are str_count
113  * string entries).  Each String is a NUL terminated string encoded in
114  * UTF-8.
115  */
116 
117 #endif
118 
119 
120 /*
121  * Events are delivered on the ep0 file descriptor, when the user mode driver
122  * reads from this file descriptor after writing the descriptors.  Don't
123  * stop polling this descriptor.
124  */
125 
126 enum usb_functionfs_event_type {
127 	FUNCTIONFS_BIND,
128 	FUNCTIONFS_UNBIND,
129 
130 	FUNCTIONFS_ENABLE,
131 	FUNCTIONFS_DISABLE,
132 
133 	FUNCTIONFS_SETUP,
134 
135 	FUNCTIONFS_SUSPEND,
136 	FUNCTIONFS_RESUME
137 };
138 
139 /* NOTE:  this structure must stay the same size and layout on
140  * both 32-bit and 64-bit kernels.
141  */
142 struct usb_functionfs_event {
143 	union {
144 		/* SETUP: packet; DATA phase i/o precedes next event
145 		 *(setup.bmRequestType & USB_DIR_IN) flags direction */
146 		struct usb_ctrlrequest	setup;
147 	} __attribute__((packed)) u;
148 
149 	/* enum usb_functionfs_event_type */
150 	__u8				type;
151 	__u8				_pad[3];
152 } __attribute__((packed));
153 
154 
155 /* Endpoint ioctls */
156 /* The same as in gadgetfs */
157 
158 /* IN transfers may be reported to the gadget driver as complete
159  *	when the fifo is loaded, before the host reads the data;
160  * OUT transfers may be reported to the host's "client" driver as
161  *	complete when they're sitting in the FIFO unread.
162  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
163  * (needed for precise fault handling, when the hardware allows it)
164  */
165 #define	FUNCTIONFS_FIFO_STATUS	_IO('g', 1)
166 
167 /* discards any unclaimed data in the fifo. */
168 #define	FUNCTIONFS_FIFO_FLUSH	_IO('g', 2)
169 
170 /* resets endpoint halt+toggle; used to implement set_interface.
171  * some hardware (like pxa2xx) can't support this.
172  */
173 #define	FUNCTIONFS_CLEAR_HALT	_IO('g', 3)
174 
175 /* Specific for functionfs */
176 
177 /*
178  * Returns reverse mapping of an interface.  Called on EP0.  If there
179  * is no such interface returns -EDOM.  If function is not active
180  * returns -ENODEV.
181  */
182 #define	FUNCTIONFS_INTERFACE_REVMAP	_IO('g', 128)
183 
184 /*
185  * Returns real bEndpointAddress of an endpoint.  If function is not
186  * active returns -ENODEV.
187  */
188 #define	FUNCTIONFS_ENDPOINT_REVMAP	_IO('g', 129)
189 
190 
191 
192 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
193