1 /* $NetBSD: usbdi.h,v 1.15 1999/01/03 01:00:56 augustss Exp $ */ 2 /* FreeBSD $Id$ */ 3 4 /* 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Lennart Augustsson (augustss@carlstedt.se) at 10 * Carlstedt Research & Technology. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the NetBSD 23 * Foundation, Inc. and its contributors. 24 * 4. Neither the name of The NetBSD Foundation nor the names of its 25 * contributors may be used to endorse or promote products derived 26 * from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41 typedef struct usbd_bus *usbd_bus_handle; 42 typedef struct usbd_device *usbd_device_handle; 43 typedef struct usbd_interface *usbd_interface_handle; 44 typedef struct usbd_pipe *usbd_pipe_handle; 45 typedef struct usbd_request *usbd_request_handle; 46 typedef void *usbd_private_handle; 47 48 typedef enum { 49 USBD_ENDPOINT_ACTIVE, 50 USBD_ENDPOINT_STALLED, 51 } usbd_endpoint_state; 52 53 typedef enum { 54 USBD_PIPE_ACTIVE, 55 USBD_PIPE_STALLED, 56 USBD_PIPE_IDLE, 57 } usbd_pipe_state; 58 59 typedef enum { 60 USBD_INTERFACE_ACTIVE, 61 USBD_INTERFACE_STALLED, 62 USBD_INTERFACE_IDLE, 63 } usbd_interface_state; 64 65 typedef enum { 66 USBD_DEVICE_ATTACHED, 67 USBD_DEVICE_POWERED, 68 USBD_DEVICE_DEFAULT, 69 USBD_DEVICE_ADDRESSED, 70 USBD_DEVICE_CONFIGURED, 71 USBD_DEVICE_SUSPENDED, 72 } usbd_device_state; 73 74 typedef enum { 75 USBD_NORMAL_COMPLETION = 0, 76 USBD_IN_PROGRESS, 77 /* errors */ 78 USBD_PENDING_REQUESTS, 79 USBD_NOT_STARTED, 80 USBD_INVAL, 81 USBD_IS_IDLE, 82 USBD_NOMEM, 83 USBD_CANCELLED, 84 USBD_BAD_ADDRESS, 85 USBD_IN_USE, 86 USBD_INTERFACE_NOT_ACTIVE, 87 USBD_NO_ADDR, 88 USBD_SET_ADDR_FAILED, 89 USBD_NO_POWER, 90 USBD_TOO_DEEP, 91 USBD_IOERROR, 92 USBD_NOT_CONFIGURED, 93 USBD_TIMEOUT, 94 USBD_SHORT_XFER, 95 USBD_STALLED, 96 USBD_INTERRUPTED, 97 98 USBD_XXX, 99 } usbd_status; 100 101 typedef int usbd_lock_token; 102 103 typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle, 104 usbd_status)); 105 106 /* Open flags */ 107 #define USBD_EXCLUSIVE_USE 0x01 108 109 /* Request flags */ 110 #define USBD_XFER_OUT 0x01 111 #define USBD_XFER_IN 0x02 112 #define USBD_SHORT_XFER_OK 0x04 113 114 #define USBD_NO_TIMEOUT 0 115 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */ 116 117 usbd_status usbd_open_pipe 118 __P((usbd_interface_handle iface, u_int8_t address, 119 u_int8_t flags, usbd_pipe_handle *pipe)); 120 usbd_status usbd_close_pipe __P((usbd_pipe_handle pipe)); 121 usbd_status usbd_transfer __P((usbd_request_handle req)); 122 usbd_request_handle usbd_alloc_request __P((void)); 123 usbd_status usbd_free_request __P((usbd_request_handle reqh)); 124 usbd_status usbd_setup_request 125 __P((usbd_request_handle reqh, usbd_pipe_handle pipe, 126 usbd_private_handle priv, void *buffer, 127 u_int32_t length, u_int16_t flags, u_int32_t timeout, 128 usbd_callback)); 129 usbd_status usbd_setup_device_request 130 __P((usbd_request_handle reqh, usb_device_request_t *req)); 131 usbd_status usbd_setup_default_request 132 __P((usbd_request_handle reqh, usbd_device_handle dev, 133 usbd_private_handle priv, u_int32_t timeout, 134 usb_device_request_t *req, void *buffer, 135 u_int32_t length, u_int16_t flags, usbd_callback)); 136 usbd_status usbd_set_request_timeout 137 __P((usbd_request_handle reqh, u_int32_t timeout)); 138 usbd_status usbd_get_request_status 139 __P((usbd_request_handle reqh, usbd_private_handle *priv, 140 void **buffer, u_int32_t *count, usbd_status *status)); 141 usbd_status usbd_request_device_data 142 __P((usbd_request_handle reqh, usb_device_request_t *req)); 143 usb_descriptor_t *usbd_get_descriptor 144 __P((usbd_interface_handle *iface, u_int8_t desc_type)); 145 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor 146 __P((usbd_interface_handle iface, u_int8_t address)); 147 usbd_status usbd_set_configuration 148 __P((usbd_device_handle dev, u_int8_t conf)); 149 usbd_status usbd_retry_request 150 __P((usbd_request_handle reqh, u_int32_t retry_count)); 151 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe)); 152 usbd_status usbd_abort_interface __P((usbd_interface_handle iface)); 153 usbd_status usbd_reset_pipe __P((usbd_pipe_handle pipe)); 154 usbd_status usbd_reset_interface __P((usbd_interface_handle iface)); 155 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe)); 156 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe)); 157 usbd_status usbd_set_pipe_state 158 __P((usbd_pipe_handle pipe, usbd_pipe_state state)); 159 usbd_status usbd_get_pipe_state 160 __P((usbd_pipe_handle pipe, usbd_pipe_state *state, 161 u_int32_t *endpoint_state, u_int32_t *request_count)); 162 usbd_status usbd_set_interface_state 163 __P((usbd_interface_handle iface, usbd_interface_state state)); 164 usbd_status usbd_get_interface_state 165 __P((usbd_interface_handle iface, usbd_interface_state *state)); 166 usbd_status usbd_get_device_state 167 __P((usbd_device_handle dev, usbd_device_state *state)); 168 usbd_status usbd_set_device_state 169 __P((usbd_device_handle dev, usbd_device_state state)); 170 usbd_status usbd_device_address 171 __P((usbd_device_handle dev, u_int8_t *address)); 172 usbd_status usbd_endpoint_address 173 __P((usbd_pipe_handle dev, u_int8_t *address)); 174 usbd_status usbd_endpoint_count 175 __P((usbd_interface_handle dev, u_int8_t *count)); 176 usbd_status usbd_interface_count 177 __P((usbd_device_handle dev, u_int8_t *count)); 178 u_int8_t usbd_bus_count __P((void)); 179 usbd_status usbd_get_bus_handle __P((u_int8_t index, usbd_bus_handle *bus)); 180 usbd_status usbd_get_root_hub 181 __P((usbd_bus_handle bus, usbd_device_handle *dev)); 182 usbd_status usbd_port_count __P((usbd_device_handle hub, u_int8_t *nports)); 183 usbd_status usbd_hub2device_handle 184 __P((usbd_device_handle hub, u_int8_t port, usbd_device_handle *dev)); 185 usbd_status usbd_request2pipe_handle 186 __P((usbd_request_handle reqh, usbd_pipe_handle *pipe)); 187 usbd_status usbd_pipe2interface_handle 188 __P((usbd_pipe_handle pipe, usbd_interface_handle *iface)); 189 usbd_status usbd_interface2device_handle 190 __P((usbd_interface_handle iface, usbd_device_handle *dev)); 191 usbd_status usbd_device2bus_handle 192 __P((usbd_device_handle dev, usbd_bus_handle *bus)); 193 usbd_status usbd_device2interface_handle 194 __P((usbd_device_handle dev, u_int8_t ifaceno, 195 usbd_interface_handle *iface)); 196 usbd_status usbd_set_interface_private_handle 197 __P((usbd_interface_handle iface, usbd_private_handle priv)); 198 usbd_status usbd_get_interface_private_handle 199 __P((usbd_interface_handle iface, usbd_private_handle *priv)); 200 usbd_status usbd_reference_pipe __P((usbd_pipe_handle pipe)); 201 usbd_status usbd_dereference_pipe __P((usbd_pipe_handle pipe)); 202 usbd_lock_token usbd_lock __P((void)); 203 void usbd_unlock __P((usbd_lock_token tok)); 204 205 /* Non-standard */ 206 usbd_status usbd_sync_transfer __P((usbd_request_handle req)); 207 usbd_status usbd_open_pipe_intr 208 __P((usbd_interface_handle iface, u_int8_t address, 209 u_int8_t flags, usbd_pipe_handle *pipe, 210 usbd_private_handle priv, void *buffer, 211 u_int32_t length, usbd_callback)); 212 usbd_status usbd_open_pipe_iso 213 __P((usbd_interface_handle iface, u_int8_t address, 214 u_int8_t flags, usbd_pipe_handle *pipe, 215 usbd_private_handle priv, u_int32_t bufsize, u_int32_t nbuf, 216 usbd_callback)); 217 usbd_status usbd_do_request 218 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data)); 219 usbd_status usbd_do_request_async 220 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data)); 221 usbd_status usbd_do_request_flags 222 __P((usbd_device_handle pipe, usb_device_request_t *req, 223 void *data, u_int16_t flags, int *)); 224 usb_interface_descriptor_t *usbd_get_interface_descriptor 225 __P((usbd_interface_handle iface)); 226 usb_config_descriptor_t *usbd_get_config_descriptor 227 __P((usbd_device_handle dev)); 228 usb_device_descriptor_t *usbd_get_device_descriptor 229 __P((usbd_device_handle dev)); 230 usbd_status usbd_set_interface __P((usbd_interface_handle, int)); 231 int usbd_get_no_alts __P((usb_config_descriptor_t *, int)); 232 usbd_status usbd_get_interface 233 __P((usbd_interface_handle iface, u_int8_t *aiface)); 234 void usbd_fill_deviceinfo 235 __P((usbd_device_handle dev, struct usb_device_info *di)); 236 int usbd_get_interface_altindex __P((usbd_interface_handle iface)); 237 238 usb_interface_descriptor_t *usbd_find_idesc 239 __P((usb_config_descriptor_t *cd, int iindex, int ano)); 240 usb_endpoint_descriptor_t *usbd_find_edesc 241 __P((usb_config_descriptor_t *cd, int ifaceidx, int altidx, 242 int endptidx)); 243 244 void usbd_dopoll __P((usbd_interface_handle)); 245 void usbd_set_polling __P((usbd_interface_handle iface, int on)); 246 247 /* NetBSD attachment information */ 248 249 /* Attach data */ 250 struct usb_attach_arg { 251 int port; 252 int configno; 253 int ifaceno; 254 usbd_device_handle device; /* current device */ 255 usbd_interface_handle iface; /* current interface */ 256 int usegeneric; 257 usbd_interface_handle *ifaces; /* all interfaces */ 258 int nifaces; /* number of interfaces */ 259 }; 260 261 #if defined(__NetBSD__) 262 /* Match codes. */ 263 /* First five codes is for a whole device. */ 264 #define UMATCH_VENDOR_PRODUCT_REV 14 265 #define UMATCH_VENDOR_PRODUCT 13 266 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12 267 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11 268 #define UMATCH_DEVCLASS_DEVSUBCLASS 10 269 /* Next six codes are for interfaces. */ 270 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9 271 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8 272 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7 273 #define UMATCH_VENDOR_IFACESUBCLASS 6 274 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5 275 #define UMATCH_IFACECLASS_IFACESUBCLASS 4 276 #define UMATCH_IFACECLASS 3 277 #define UMATCH_IFACECLASS_GENERIC 2 278 /* Generic driver */ 279 #define UMATCH_GENERIC 1 280 /* No match */ 281 #define UMATCH_NONE 0 282 283 #elif defined(__FreeBSD__) 284 /* FreeBSD needs values less than zero */ 285 /* for the moment disabled 286 #define UMATCH_VENDOR_PRODUCT_REV -14 287 #define UMATCH_VENDOR_PRODUCT -13 288 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO -12 289 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO -11 290 #define UMATCH_DEVCLASS_DEVSUBCLASS -10 291 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE -9 292 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE -8 293 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO -7 294 #define UMATCH_VENDOR_IFACESUBCLASS -6 295 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO -5 296 #define UMATCH_IFACECLASS_IFACESUBCLASS -4 297 #define UMATCH_IFACECLASS -3 298 #define UMATCH_IFACECLASS_GENERIC -2 299 #define UMATCH_GENERIC -1 300 #define UMATCH_NONE ENXIO 301 302 * For the moment we use Yes/No answers with appropriate 303 * sorting in the config file 304 */ 305 #define UMATCH_VENDOR_PRODUCT_REV 0 306 #define UMATCH_VENDOR_PRODUCT 0 307 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 0 308 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 0 309 #define UMATCH_DEVCLASS_DEVSUBCLASS 0 310 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 0 311 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 0 312 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 0 313 #define UMATCH_VENDOR_IFACESUBCLASS 0 314 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 0 315 #define UMATCH_IFACECLASS_IFACESUBCLASS 0 316 #define UMATCH_IFACECLASS 0 317 #define UMATCH_IFACECLASS_GENERIC 0 318 #define UMATCH_GENERIC 0 319 #define UMATCH_NONE ENXIO 320 321 322 #endif 323 324 void usbd_devinfo __P((usbd_device_handle, int, char *)); 325 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle)); 326 void usbd_set_disco __P((usbd_pipe_handle, void (*)(void *), void *)); 327 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor 328 __P((usbd_interface_handle iface, u_int8_t address)); 329 330 #if defined(__FreeBSD__) 331 int usbd_driver_load __P((module_t mod, int what, void *arg)); 332 void usbd_device_set_desc __P((device_t device, char *devinfo)); 333 char *usbd_devname(bdevice *bdev); 334 bus_print_child_t usbd_print_child; 335 #endif 336 337 /* XXX */ 338 #define splusb splbio 339 #define IPL_USB IPL_BIO 340 /* XXX */ 341 342