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