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, 221b0bf88fSRobert Baldyga FUNCTIONFS_VIRTUAL_ADDR = 16, 235e33f6fdSRobert Baldyga FUNCTIONFS_EVENTFD = 32, 2454dfce6dSFelix Hädicke FUNCTIONFS_ALL_CTRL_RECIP = 64, 254368c28aSFelix Hädicke FUNCTIONFS_CONFIG0_SETUP = 128, 26ac8dde11SMichal Nazarewicz }; 275e1ddb48SDavid Howells 285e1ddb48SDavid Howells /* Descriptor of an non-audio endpoint */ 295e1ddb48SDavid Howells struct usb_endpoint_descriptor_no_audio { 305e1ddb48SDavid Howells __u8 bLength; 315e1ddb48SDavid Howells __u8 bDescriptorType; 325e1ddb48SDavid Howells 335e1ddb48SDavid Howells __u8 bEndpointAddress; 345e1ddb48SDavid Howells __u8 bmAttributes; 355e1ddb48SDavid Howells __le16 wMaxPacketSize; 365e1ddb48SDavid Howells __u8 bInterval; 375e1ddb48SDavid Howells } __attribute__((packed)); 385e1ddb48SDavid Howells 391df22b4eSMichal Nazarewicz struct usb_functionfs_descs_head_v2 { 401df22b4eSMichal Nazarewicz __le32 magic; 411df22b4eSMichal Nazarewicz __le32 length; 421df22b4eSMichal Nazarewicz __le32 flags; 431df22b4eSMichal Nazarewicz /* 441df22b4eSMichal Nazarewicz * __le32 fs_count, hs_count, fs_count; must be included manually in 451df22b4eSMichal Nazarewicz * the structure taking flags into consideration. 461df22b4eSMichal Nazarewicz */ 471df22b4eSMichal Nazarewicz } __attribute__((packed)); 481df22b4eSMichal Nazarewicz 4909122141SMichal Nazarewicz /* Legacy format, deprecated as of 3.14. */ 5009122141SMichal Nazarewicz struct usb_functionfs_descs_head { 5109122141SMichal Nazarewicz __le32 magic; 5209122141SMichal Nazarewicz __le32 length; 5309122141SMichal Nazarewicz __le32 fs_count; 5409122141SMichal Nazarewicz __le32 hs_count; 5509122141SMichal Nazarewicz } __attribute__((packed, deprecated)); 565e1ddb48SDavid Howells 57f0175ab5SAndrzej Pietrasiewicz /* MS OS Descriptor header */ 58f0175ab5SAndrzej Pietrasiewicz struct usb_os_desc_header { 59f0175ab5SAndrzej Pietrasiewicz __u8 interface; 60f0175ab5SAndrzej Pietrasiewicz __le32 dwLength; 61f0175ab5SAndrzej Pietrasiewicz __le16 bcdVersion; 62f0175ab5SAndrzej Pietrasiewicz __le16 wIndex; 63f0175ab5SAndrzej Pietrasiewicz union { 64f0175ab5SAndrzej Pietrasiewicz struct { 65f0175ab5SAndrzej Pietrasiewicz __u8 bCount; 66f0175ab5SAndrzej Pietrasiewicz __u8 Reserved; 67f0175ab5SAndrzej Pietrasiewicz }; 68f0175ab5SAndrzej Pietrasiewicz __le16 wCount; 69f0175ab5SAndrzej Pietrasiewicz }; 70f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed)); 71f0175ab5SAndrzej Pietrasiewicz 72f0175ab5SAndrzej Pietrasiewicz struct usb_ext_compat_desc { 73f0175ab5SAndrzej Pietrasiewicz __u8 bFirstInterfaceNumber; 74f0175ab5SAndrzej Pietrasiewicz __u8 Reserved1; 75f0175ab5SAndrzej Pietrasiewicz __u8 CompatibleID[8]; 76f0175ab5SAndrzej Pietrasiewicz __u8 SubCompatibleID[8]; 77f0175ab5SAndrzej Pietrasiewicz __u8 Reserved2[6]; 78f0175ab5SAndrzej Pietrasiewicz }; 79f0175ab5SAndrzej Pietrasiewicz 80f0175ab5SAndrzej Pietrasiewicz struct usb_ext_prop_desc { 81f0175ab5SAndrzej Pietrasiewicz __le32 dwSize; 82f0175ab5SAndrzej Pietrasiewicz __le32 dwPropertyDataType; 83f0175ab5SAndrzej Pietrasiewicz __le16 wPropertyNameLength; 84f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed)); 85f0175ab5SAndrzej Pietrasiewicz 86f0175ab5SAndrzej Pietrasiewicz #ifndef __KERNEL__ 875e1ddb48SDavid Howells 885e1ddb48SDavid Howells /* 895e1ddb48SDavid Howells * Descriptors format: 905e1ddb48SDavid Howells * 915e1ddb48SDavid Howells * | off | name | type | description | 925e1ddb48SDavid Howells * |-----+-----------+--------------+--------------------------------------| 93ac8dde11SMichal Nazarewicz * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 | 94ac8dde11SMichal Nazarewicz * | 4 | length | LE32 | length of the whole data chunk | 95ac8dde11SMichal Nazarewicz * | 8 | flags | LE32 | combination of functionfs_flags | 9696a420d2SVincent Pelletier * | | eventfd | LE32 | eventfd file descriptor | 97ac8dde11SMichal Nazarewicz * | | fs_count | LE32 | number of full-speed descriptors | 98ac8dde11SMichal Nazarewicz * | | hs_count | LE32 | number of high-speed descriptors | 99ac8dde11SMichal Nazarewicz * | | ss_count | LE32 | number of super-speed descriptors | 100f0175ab5SAndrzej Pietrasiewicz * | | os_count | LE32 | number of MS OS descriptors | 101ac8dde11SMichal Nazarewicz * | | fs_descrs | Descriptor[] | list of full-speed descriptors | 102ac8dde11SMichal Nazarewicz * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 103ac8dde11SMichal Nazarewicz * | | ss_descrs | Descriptor[] | list of super-speed descriptors | 104f0175ab5SAndrzej Pietrasiewicz * | | os_descrs | OSDesc[] | list of MS OS descriptors | 105ac8dde11SMichal Nazarewicz * 106ac8dde11SMichal Nazarewicz * Depending on which flags are set, various fields may be missing in the 107ac8dde11SMichal Nazarewicz * structure. Any flags that are not recognised cause the whole block to be 108ac8dde11SMichal Nazarewicz * rejected with -ENOSYS. 109ac8dde11SMichal Nazarewicz * 11051c208c7SMichal Nazarewicz * Legacy descriptors format (deprecated as of 3.14): 111ac8dde11SMichal Nazarewicz * 112ac8dde11SMichal Nazarewicz * | off | name | type | description | 113ac8dde11SMichal Nazarewicz * |-----+-----------+--------------+--------------------------------------| 114ac8dde11SMichal Nazarewicz * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC | 1155e1ddb48SDavid Howells * | 4 | length | LE32 | length of the whole data chunk | 1165e1ddb48SDavid Howells * | 8 | fs_count | LE32 | number of full-speed descriptors | 1175e1ddb48SDavid Howells * | 12 | hs_count | LE32 | number of high-speed descriptors | 1185e1ddb48SDavid Howells * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors | 1195e1ddb48SDavid Howells * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 1205e1ddb48SDavid Howells * 121ac8dde11SMichal Nazarewicz * All numbers must be in little endian order. 122ac8dde11SMichal Nazarewicz * 123ac8dde11SMichal Nazarewicz * Descriptor[] is an array of valid USB descriptors which have the following 124ac8dde11SMichal Nazarewicz * format: 1255e1ddb48SDavid Howells * 1265e1ddb48SDavid Howells * | off | name | type | description | 1275e1ddb48SDavid Howells * |-----+-----------------+------+--------------------------| 1285e1ddb48SDavid Howells * | 0 | bLength | U8 | length of the descriptor | 1295e1ddb48SDavid Howells * | 1 | bDescriptorType | U8 | descriptor type | 1305e1ddb48SDavid Howells * | 2 | payload | | descriptor's payload | 131f0175ab5SAndrzej Pietrasiewicz * 132f0175ab5SAndrzej Pietrasiewicz * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of 133f0175ab5SAndrzej Pietrasiewicz * the following formats: 134f0175ab5SAndrzej Pietrasiewicz * 135f0175ab5SAndrzej Pietrasiewicz * | off | name | type | description | 136f0175ab5SAndrzej Pietrasiewicz * |-----+-----------------+------+--------------------------| 137f0175ab5SAndrzej Pietrasiewicz * | 0 | inteface | U8 | related interface number | 138f0175ab5SAndrzej Pietrasiewicz * | 1 | dwLength | U32 | length of the descriptor | 139f0175ab5SAndrzej Pietrasiewicz * | 5 | bcdVersion | U16 | currently supported: 1 | 140f0175ab5SAndrzej Pietrasiewicz * | 7 | wIndex | U16 | currently supported: 4 | 141f0175ab5SAndrzej Pietrasiewicz * | 9 | bCount | U8 | number of ext. compat. | 142f0175ab5SAndrzej Pietrasiewicz * | 10 | Reserved | U8 | 0 | 143f0175ab5SAndrzej Pietrasiewicz * | 11 | ExtCompat[] | | list of ext. compat. d. | 144f0175ab5SAndrzej Pietrasiewicz * 145f0175ab5SAndrzej Pietrasiewicz * | off | name | type | description | 146f0175ab5SAndrzej Pietrasiewicz * |-----+-----------------+------+--------------------------| 147f0175ab5SAndrzej Pietrasiewicz * | 0 | inteface | U8 | related interface number | 148f0175ab5SAndrzej Pietrasiewicz * | 1 | dwLength | U32 | length of the descriptor | 149f0175ab5SAndrzej Pietrasiewicz * | 5 | bcdVersion | U16 | currently supported: 1 | 150f0175ab5SAndrzej Pietrasiewicz * | 7 | wIndex | U16 | currently supported: 5 | 151f0175ab5SAndrzej Pietrasiewicz * | 9 | wCount | U16 | number of ext. compat. | 152f0175ab5SAndrzej Pietrasiewicz * | 11 | ExtProp[] | | list of ext. prop. d. | 153f0175ab5SAndrzej Pietrasiewicz * 154f0175ab5SAndrzej Pietrasiewicz * ExtCompat[] is an array of valid Extended Compatiblity descriptors 155f0175ab5SAndrzej Pietrasiewicz * which have the following format: 156f0175ab5SAndrzej Pietrasiewicz * 157f0175ab5SAndrzej Pietrasiewicz * | off | name | type | description | 158f0175ab5SAndrzej Pietrasiewicz * |-----+-----------------------+------+-------------------------------------| 159f0175ab5SAndrzej Pietrasiewicz * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st| 160f0175ab5SAndrzej Pietrasiewicz * | | | | interface in an IAD group | 1611f7da4f8SVincent Pelletier * | 1 | Reserved | U8 | 1 | 162f0175ab5SAndrzej Pietrasiewicz * | 2 | CompatibleID | U8[8]| compatible ID string | 163f0175ab5SAndrzej Pietrasiewicz * | 10 | SubCompatibleID | U8[8]| subcompatible ID string | 164f0175ab5SAndrzej Pietrasiewicz * | 18 | Reserved | U8[6]| 0 | 165f0175ab5SAndrzej Pietrasiewicz * 166f0175ab5SAndrzej Pietrasiewicz * ExtProp[] is an array of valid Extended Properties descriptors 167f0175ab5SAndrzej Pietrasiewicz * which have the following format: 168f0175ab5SAndrzej Pietrasiewicz * 169f0175ab5SAndrzej Pietrasiewicz * | off | name | type | description | 170f0175ab5SAndrzej Pietrasiewicz * |-----+-----------------------+------+-------------------------------------| 171f0175ab5SAndrzej Pietrasiewicz * | 0 | dwSize | U32 | length of the descriptor | 172f0175ab5SAndrzej Pietrasiewicz * | 4 | dwPropertyDataType | U32 | 1..7 | 173f0175ab5SAndrzej Pietrasiewicz * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) | 174f0175ab5SAndrzej Pietrasiewicz * | 10 | bPropertyName |U8[NL]| name of this property | 175f0175ab5SAndrzej Pietrasiewicz * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) | 176f0175ab5SAndrzej Pietrasiewicz * |14+NL| bProperty |U8[DL]| payload of this property | 1775e1ddb48SDavid Howells */ 1785e1ddb48SDavid Howells 1795e1ddb48SDavid Howells struct usb_functionfs_strings_head { 1805e1ddb48SDavid Howells __le32 magic; 1815e1ddb48SDavid Howells __le32 length; 1825e1ddb48SDavid Howells __le32 str_count; 1835e1ddb48SDavid Howells __le32 lang_count; 1845e1ddb48SDavid Howells } __attribute__((packed)); 1855e1ddb48SDavid Howells 1865e1ddb48SDavid Howells /* 1875e1ddb48SDavid Howells * Strings format: 1885e1ddb48SDavid Howells * 1895e1ddb48SDavid Howells * | off | name | type | description | 1905e1ddb48SDavid Howells * |-----+------------+-----------------------+----------------------------| 1915e1ddb48SDavid Howells * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC | 1925e1ddb48SDavid Howells * | 4 | length | LE32 | length of the data chunk | 1935e1ddb48SDavid Howells * | 8 | str_count | LE32 | number of strings | 1945e1ddb48SDavid Howells * | 12 | lang_count | LE32 | number of languages | 1955e1ddb48SDavid Howells * | 16 | stringtab | StringTab[lang_count] | table of strings per lang | 1965e1ddb48SDavid Howells * 1975e1ddb48SDavid Howells * For each language there is one stringtab entry (ie. there are lang_count 1985e1ddb48SDavid Howells * stringtab entires). Each StringTab has following format: 1995e1ddb48SDavid Howells * 2005e1ddb48SDavid Howells * | off | name | type | description | 2015e1ddb48SDavid Howells * |-----+---------+-------------------+------------------------------------| 2025e1ddb48SDavid Howells * | 0 | lang | LE16 | language code | 2035e1ddb48SDavid Howells * | 2 | strings | String[str_count] | array of strings in given language | 2045e1ddb48SDavid Howells * 2055e1ddb48SDavid Howells * For each string there is one strings entry (ie. there are str_count 2065e1ddb48SDavid Howells * string entries). Each String is a NUL terminated string encoded in 2075e1ddb48SDavid Howells * UTF-8. 2085e1ddb48SDavid Howells */ 2095e1ddb48SDavid Howells 2105e1ddb48SDavid Howells #endif 2115e1ddb48SDavid Howells 2125e1ddb48SDavid Howells 2135e1ddb48SDavid Howells /* 2145e1ddb48SDavid Howells * Events are delivered on the ep0 file descriptor, when the user mode driver 2155e1ddb48SDavid Howells * reads from this file descriptor after writing the descriptors. Don't 2165e1ddb48SDavid Howells * stop polling this descriptor. 2175e1ddb48SDavid Howells */ 2185e1ddb48SDavid Howells 2195e1ddb48SDavid Howells enum usb_functionfs_event_type { 2205e1ddb48SDavid Howells FUNCTIONFS_BIND, 2215e1ddb48SDavid Howells FUNCTIONFS_UNBIND, 2225e1ddb48SDavid Howells 2235e1ddb48SDavid Howells FUNCTIONFS_ENABLE, 2245e1ddb48SDavid Howells FUNCTIONFS_DISABLE, 2255e1ddb48SDavid Howells 2265e1ddb48SDavid Howells FUNCTIONFS_SETUP, 2275e1ddb48SDavid Howells 2285e1ddb48SDavid Howells FUNCTIONFS_SUSPEND, 2295e1ddb48SDavid Howells FUNCTIONFS_RESUME 2305e1ddb48SDavid Howells }; 2315e1ddb48SDavid Howells 2325e1ddb48SDavid Howells /* NOTE: this structure must stay the same size and layout on 2335e1ddb48SDavid Howells * both 32-bit and 64-bit kernels. 2345e1ddb48SDavid Howells */ 2355e1ddb48SDavid Howells struct usb_functionfs_event { 2365e1ddb48SDavid Howells union { 2375e1ddb48SDavid Howells /* SETUP: packet; DATA phase i/o precedes next event 2385e1ddb48SDavid Howells *(setup.bmRequestType & USB_DIR_IN) flags direction */ 2395e1ddb48SDavid Howells struct usb_ctrlrequest setup; 2405e1ddb48SDavid Howells } __attribute__((packed)) u; 2415e1ddb48SDavid Howells 2425e1ddb48SDavid Howells /* enum usb_functionfs_event_type */ 2435e1ddb48SDavid Howells __u8 type; 2445e1ddb48SDavid Howells __u8 _pad[3]; 2455e1ddb48SDavid Howells } __attribute__((packed)); 2465e1ddb48SDavid Howells 2475e1ddb48SDavid Howells 2485e1ddb48SDavid Howells /* Endpoint ioctls */ 2495e1ddb48SDavid Howells /* The same as in gadgetfs */ 2505e1ddb48SDavid Howells 2515e1ddb48SDavid Howells /* IN transfers may be reported to the gadget driver as complete 2525e1ddb48SDavid Howells * when the fifo is loaded, before the host reads the data; 2535e1ddb48SDavid Howells * OUT transfers may be reported to the host's "client" driver as 2545e1ddb48SDavid Howells * complete when they're sitting in the FIFO unread. 2555e1ddb48SDavid Howells * THIS returns how many bytes are "unclaimed" in the endpoint fifo 2565e1ddb48SDavid Howells * (needed for precise fault handling, when the hardware allows it) 2575e1ddb48SDavid Howells */ 2585e1ddb48SDavid Howells #define FUNCTIONFS_FIFO_STATUS _IO('g', 1) 2595e1ddb48SDavid Howells 2605e1ddb48SDavid Howells /* discards any unclaimed data in the fifo. */ 2615e1ddb48SDavid Howells #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2) 2625e1ddb48SDavid Howells 2635e1ddb48SDavid Howells /* resets endpoint halt+toggle; used to implement set_interface. 2645e1ddb48SDavid Howells * some hardware (like pxa2xx) can't support this. 2655e1ddb48SDavid Howells */ 2665e1ddb48SDavid Howells #define FUNCTIONFS_CLEAR_HALT _IO('g', 3) 2675e1ddb48SDavid Howells 2685e1ddb48SDavid Howells /* Specific for functionfs */ 2695e1ddb48SDavid Howells 2705e1ddb48SDavid Howells /* 2715e1ddb48SDavid Howells * Returns reverse mapping of an interface. Called on EP0. If there 2725e1ddb48SDavid Howells * is no such interface returns -EDOM. If function is not active 2735e1ddb48SDavid Howells * returns -ENODEV. 2745e1ddb48SDavid Howells */ 2755e1ddb48SDavid Howells #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128) 2765e1ddb48SDavid Howells 2775e1ddb48SDavid Howells /* 278*222155deSJerry Zhang * Returns real bEndpointAddress of an endpoint. If endpoint shuts down 279*222155deSJerry Zhang * during the call, returns -ESHUTDOWN. 2805e1ddb48SDavid Howells */ 2815e1ddb48SDavid Howells #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129) 2825e1ddb48SDavid Howells 283c559a353SRobert Baldyga /* 284*222155deSJerry Zhang * Returns endpoint descriptor. If endpoint shuts down during the call, 285*222155deSJerry Zhang * returns -ESHUTDOWN. 286c559a353SRobert Baldyga */ 287c559a353SRobert Baldyga #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \ 288c559a353SRobert Baldyga struct usb_endpoint_descriptor) 289c559a353SRobert Baldyga 2905e1ddb48SDavid Howells 2915e1ddb48SDavid Howells 2925e1ddb48SDavid Howells #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */ 293