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