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