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