1 /* $NetBSD: usbdi.h,v 1.16 1999/01/08 11:58:26 augustss Exp $ */ 2 /* $FreeBSD$ */ 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 #define USBD_ERROR_MAX 21 /* used for usbd_error_strs */ 100 } usbd_status; 101 102 typedef int usbd_lock_token; 103 104 typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle, 105 usbd_status)); 106 107 /* Open flags */ 108 #define USBD_EXCLUSIVE_USE 0x01 109 110 /* XXX broken, should not use the same value */ 111 /* Request flags */ 112 #define USBD_XFER_OUT 0x01 113 #define USBD_XFER_IN 0x02 114 #define USBD_SHORT_XFER_OK 0x04 115 116 #define USBD_NO_TIMEOUT 0 117 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */ 118 119 #if defined(__FreeBSD__) 120 #define USB_CDEV_MAJOR 108 121 122 extern struct cdevsw usb_cdevsw; 123 #endif 124 125 usbd_status usbd_open_pipe 126 __P((usbd_interface_handle iface, u_int8_t address, 127 u_int8_t flags, usbd_pipe_handle *pipe)); 128 usbd_status usbd_close_pipe __P((usbd_pipe_handle pipe)); 129 usbd_status usbd_transfer __P((usbd_request_handle req)); 130 usbd_request_handle usbd_alloc_request __P((void)); 131 usbd_status usbd_free_request __P((usbd_request_handle reqh)); 132 usbd_status usbd_setup_request 133 __P((usbd_request_handle reqh, usbd_pipe_handle pipe, 134 usbd_private_handle priv, void *buffer, 135 u_int32_t length, u_int16_t flags, u_int32_t timeout, 136 usbd_callback)); 137 usbd_status usbd_setup_device_request 138 __P((usbd_request_handle reqh, usb_device_request_t *req)); 139 usbd_status usbd_setup_default_request 140 __P((usbd_request_handle reqh, usbd_device_handle dev, 141 usbd_private_handle priv, u_int32_t timeout, 142 usb_device_request_t *req, void *buffer, 143 u_int32_t length, u_int16_t flags, usbd_callback)); 144 usbd_status usbd_set_request_timeout 145 __P((usbd_request_handle reqh, u_int32_t timeout)); 146 usbd_status usbd_get_request_status 147 __P((usbd_request_handle reqh, usbd_private_handle *priv, 148 void **buffer, u_int32_t *count, usbd_status *status)); 149 usbd_status usbd_request_device_data 150 __P((usbd_request_handle reqh, usb_device_request_t *req)); 151 usb_descriptor_t *usbd_get_descriptor 152 __P((usbd_interface_handle *iface, u_int8_t desc_type)); 153 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor 154 __P((usbd_interface_handle iface, u_int8_t address)); 155 usbd_status usbd_set_configuration 156 __P((usbd_device_handle dev, u_int8_t conf)); 157 usbd_status usbd_retry_request 158 __P((usbd_request_handle reqh, u_int32_t retry_count)); 159 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe)); 160 usbd_status usbd_abort_interface __P((usbd_interface_handle iface)); 161 usbd_status usbd_reset_pipe __P((usbd_pipe_handle pipe)); 162 usbd_status usbd_reset_interface __P((usbd_interface_handle iface)); 163 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe)); 164 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe)); 165 usbd_status usbd_set_pipe_state 166 __P((usbd_pipe_handle pipe, usbd_pipe_state state)); 167 usbd_status usbd_get_pipe_state 168 __P((usbd_pipe_handle pipe, usbd_pipe_state *state, 169 u_int32_t *endpoint_state, u_int32_t *request_count)); 170 usbd_status usbd_set_interface_state 171 __P((usbd_interface_handle iface, usbd_interface_state state)); 172 usbd_status usbd_get_interface_state 173 __P((usbd_interface_handle iface, usbd_interface_state *state)); 174 usbd_status usbd_get_device_state 175 __P((usbd_device_handle dev, usbd_device_state *state)); 176 usbd_status usbd_set_device_state 177 __P((usbd_device_handle dev, usbd_device_state state)); 178 usbd_status usbd_device_address 179 __P((usbd_device_handle dev, u_int8_t *address)); 180 usbd_status usbd_endpoint_address 181 __P((usbd_pipe_handle dev, u_int8_t *address)); 182 usbd_status usbd_endpoint_count 183 __P((usbd_interface_handle dev, u_int8_t *count)); 184 usbd_status usbd_interface_count 185 __P((usbd_device_handle dev, u_int8_t *count)); 186 #if 0 187 u_int8_t usbd_bus_count __P((void)); 188 usbd_status usbd_get_bus_handle __P((u_int8_t index, usbd_bus_handle *bus)); 189 usbd_status usbd_get_root_hub 190 __P((usbd_bus_handle bus, usbd_device_handle *dev)); 191 usbd_status usbd_port_count __P((usbd_device_handle hub, u_int8_t *nports)); 192 usbd_status usbd_hub2device_handle 193 __P((usbd_device_handle hub, u_int8_t port, usbd_device_handle *dev)); 194 #endif 195 usbd_status usbd_request2pipe_handle 196 __P((usbd_request_handle reqh, usbd_pipe_handle *pipe)); 197 usbd_status usbd_pipe2interface_handle 198 __P((usbd_pipe_handle pipe, usbd_interface_handle *iface)); 199 usbd_status usbd_interface2device_handle 200 __P((usbd_interface_handle iface, usbd_device_handle *dev)); 201 usbd_status usbd_device2bus_handle 202 __P((usbd_device_handle dev, usbd_bus_handle *bus)); 203 usbd_status usbd_device2interface_handle 204 __P((usbd_device_handle dev, u_int8_t ifaceno, 205 usbd_interface_handle *iface)); 206 usbd_status usbd_set_interface_private_handle 207 __P((usbd_interface_handle iface, usbd_private_handle priv)); 208 usbd_status usbd_get_interface_private_handle 209 __P((usbd_interface_handle iface, usbd_private_handle *priv)); 210 usbd_status usbd_reference_pipe __P((usbd_pipe_handle pipe)); 211 usbd_status usbd_dereference_pipe __P((usbd_pipe_handle pipe)); 212 usbd_lock_token usbd_lock __P((void)); 213 void usbd_unlock __P((usbd_lock_token tok)); 214 215 /* Non-standard */ 216 usbd_status usbd_sync_transfer __P((usbd_request_handle req)); 217 usbd_status usbd_open_pipe_intr 218 __P((usbd_interface_handle iface, u_int8_t address, 219 u_int8_t flags, usbd_pipe_handle *pipe, 220 usbd_private_handle priv, void *buffer, 221 u_int32_t length, usbd_callback)); 222 usbd_status usbd_open_pipe_iso 223 __P((usbd_interface_handle iface, u_int8_t address, 224 u_int8_t flags, usbd_pipe_handle *pipe, 225 usbd_private_handle priv, u_int32_t bufsize, u_int32_t nbuf, 226 usbd_callback)); 227 usbd_status usbd_do_request 228 __P((usbd_device_handle dev, usb_device_request_t *req, void *data)); 229 usbd_status usbd_do_request_async 230 __P((usbd_device_handle dev, usb_device_request_t *req, void *data)); 231 usbd_status usbd_do_request_flags 232 __P((usbd_device_handle dev, usb_device_request_t *req, 233 void *data, u_int16_t flags, int *)); 234 usb_interface_descriptor_t *usbd_get_interface_descriptor 235 __P((usbd_interface_handle iface)); 236 usb_config_descriptor_t *usbd_get_config_descriptor 237 __P((usbd_device_handle dev)); 238 usb_device_descriptor_t *usbd_get_device_descriptor 239 __P((usbd_device_handle dev)); 240 usbd_status usbd_set_interface __P((usbd_interface_handle, int)); 241 int usbd_get_no_alts __P((usb_config_descriptor_t *, int)); 242 usbd_status usbd_get_interface 243 __P((usbd_interface_handle iface, u_int8_t *aiface)); 244 void usbd_fill_deviceinfo 245 __P((usbd_device_handle dev, struct usb_device_info *di)); 246 int usbd_get_interface_altindex __P((usbd_interface_handle iface)); 247 248 usb_interface_descriptor_t *usbd_find_idesc 249 __P((usb_config_descriptor_t *cd, int iindex, int ano)); 250 usb_endpoint_descriptor_t *usbd_find_edesc 251 __P((usb_config_descriptor_t *cd, int ifaceidx, int altidx, 252 int endptidx)); 253 254 char * usbd_errstr(usbd_status err); 255 256 257 void usbd_dopoll __P((usbd_interface_handle)); 258 void usbd_set_polling __P((usbd_interface_handle iface, int on)); 259 260 /* NetBSD attachment information */ 261 262 /* Attach data */ 263 struct usb_attach_arg { 264 int port; 265 int configno; 266 int ifaceno; 267 usbd_device_handle device; /* current device */ 268 usbd_interface_handle iface; /* current interface */ 269 int usegeneric; 270 usbd_interface_handle *ifaces; /* all interfaces */ 271 int nifaces; /* number of interfaces */ 272 }; 273 274 #if defined(__NetBSD__) 275 /* Match codes. */ 276 /* First five codes is for a whole device. */ 277 #define UMATCH_VENDOR_PRODUCT_REV 14 278 #define UMATCH_VENDOR_PRODUCT 13 279 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12 280 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11 281 #define UMATCH_DEVCLASS_DEVSUBCLASS 10 282 /* Next six codes are for interfaces. */ 283 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9 284 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8 285 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7 286 #define UMATCH_VENDOR_IFACESUBCLASS 6 287 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5 288 #define UMATCH_IFACECLASS_IFACESUBCLASS 4 289 #define UMATCH_IFACECLASS 3 290 #define UMATCH_IFACECLASS_GENERIC 2 291 /* Generic driver */ 292 #define UMATCH_GENERIC 1 293 /* No match */ 294 #define UMATCH_NONE 0 295 296 #elif defined(__FreeBSD__) 297 /* FreeBSD needs values less than zero */ 298 #define UMATCH_VENDOR_PRODUCT_REV (-10) 299 #define UMATCH_VENDOR_PRODUCT (-20) 300 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO (-30) 301 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO (-40) 302 #define UMATCH_DEVCLASS_DEVSUBCLASS (-50) 303 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE (-60) 304 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE (-70) 305 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO (-80) 306 #define UMATCH_VENDOR_IFACESUBCLASS (-90) 307 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO (-100) 308 #define UMATCH_IFACECLASS_IFACESUBCLASS (-110) 309 #define UMATCH_IFACECLASS (-120) 310 #define UMATCH_IFACECLASS_GENERIC (-130) 311 #define UMATCH_GENERIC (-140) 312 #define UMATCH_NONE (ENXIO) 313 #endif 314 315 316 void usbd_devinfo __P((usbd_device_handle, int, char *)); 317 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle)); 318 void usbd_set_disco __P((usbd_pipe_handle, void (*)(void *), void *)); 319 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor 320 __P((usbd_interface_handle iface, u_int8_t address)); 321 322 #if defined(__FreeBSD__) 323 int usbd_driver_load __P((module_t mod, int what, void *arg)); 324 bus_print_child_t usbd_print_child; 325 #endif 326 327 /* XXX */ 328 #define splusb splbio 329 #define IPL_USB IPL_BIO 330 /* XXX */ 331 332