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