Home | History | Annotate | Line # | Download | only in usb
usbdi.h revision 1.15
      1 /*	$NetBSD: usbdi.h,v 1.15 1999/01/03 01:00:56 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 u_int8_t usbd_bus_count __P((void));
    178 usbd_status usbd_get_bus_handle __P((u_int8_t index, usbd_bus_handle *bus));
    179 usbd_status usbd_get_root_hub
    180 	__P((usbd_bus_handle bus, usbd_device_handle *dev));
    181 usbd_status usbd_port_count __P((usbd_device_handle hub, u_int8_t *nports));
    182 usbd_status usbd_hub2device_handle
    183 	__P((usbd_device_handle hub, u_int8_t port, usbd_device_handle *dev));
    184 usbd_status usbd_request2pipe_handle
    185 	__P((usbd_request_handle reqh, usbd_pipe_handle *pipe));
    186 usbd_status usbd_pipe2interface_handle
    187 	__P((usbd_pipe_handle pipe, usbd_interface_handle *iface));
    188 usbd_status usbd_interface2device_handle
    189 	__P((usbd_interface_handle iface, usbd_device_handle *dev));
    190 usbd_status usbd_device2bus_handle
    191 	__P((usbd_device_handle dev, usbd_bus_handle *bus));
    192 usbd_status usbd_device2interface_handle
    193 	__P((usbd_device_handle dev, u_int8_t ifaceno,
    194 	     usbd_interface_handle *iface));
    195 usbd_status usbd_set_interface_private_handle
    196 	__P((usbd_interface_handle iface, usbd_private_handle priv));
    197 usbd_status usbd_get_interface_private_handle
    198 	__P((usbd_interface_handle iface, usbd_private_handle *priv));
    199 usbd_status usbd_reference_pipe __P((usbd_pipe_handle pipe));
    200 usbd_status usbd_dereference_pipe __P((usbd_pipe_handle pipe));
    201 usbd_lock_token usbd_lock __P((void));
    202 void usbd_unlock __P((usbd_lock_token tok));
    203 
    204 /* Non-standard */
    205 usbd_status usbd_sync_transfer	__P((usbd_request_handle req));
    206 usbd_status usbd_open_pipe_intr
    207 	__P((usbd_interface_handle iface, u_int8_t address,
    208 	     u_int8_t flags, usbd_pipe_handle *pipe,
    209 	     usbd_private_handle priv, void *buffer,
    210 	     u_int32_t length, usbd_callback));
    211 usbd_status usbd_open_pipe_iso
    212 	__P((usbd_interface_handle iface, u_int8_t address,
    213 	     u_int8_t flags, usbd_pipe_handle *pipe,
    214 	     usbd_private_handle priv, u_int32_t bufsize, u_int32_t nbuf,
    215 	     usbd_callback));
    216 usbd_status usbd_do_request
    217 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    218 usbd_status usbd_do_request_async
    219 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    220 usbd_status usbd_do_request_flags
    221 	__P((usbd_device_handle pipe, usb_device_request_t *req,
    222 	     void *data, u_int16_t flags, int *));
    223 usb_interface_descriptor_t *usbd_get_interface_descriptor
    224 	__P((usbd_interface_handle iface));
    225 usb_config_descriptor_t *usbd_get_config_descriptor
    226 	__P((usbd_device_handle dev));
    227 usb_device_descriptor_t *usbd_get_device_descriptor
    228 	__P((usbd_device_handle dev));
    229 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
    230 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
    231 usbd_status	usbd_get_interface
    232 	__P((usbd_interface_handle iface, u_int8_t *aiface));
    233 void usbd_fill_deviceinfo
    234 	__P((usbd_device_handle dev, struct usb_device_info *di));
    235 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
    236 
    237 usb_interface_descriptor_t *usbd_find_idesc
    238 	__P((usb_config_descriptor_t *cd, int iindex, int ano));
    239 usb_endpoint_descriptor_t *usbd_find_edesc
    240 	__P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
    241 	     int endptidx));
    242 
    243 void usbd_dopoll __P((usbd_interface_handle));
    244 void usbd_set_polling __P((usbd_interface_handle iface, int on));
    245 
    246 /* NetBSD attachment information */
    247 
    248 /* Attach data */
    249 struct usb_attach_arg {
    250 	int			port;
    251 	int			configno;
    252 	int			ifaceno;
    253 	usbd_device_handle	device;	/* current device */
    254 	usbd_interface_handle	iface; /* current interface */
    255 	int			usegeneric;
    256 	usbd_interface_handle  *ifaces;	/* all interfaces */
    257 	int			nifaces; /* number of interfaces */
    258 };
    259 
    260 #if defined(__NetBSD__)
    261 /* Match codes. */
    262 /* First five codes is for a whole device. */
    263 #define UMATCH_VENDOR_PRODUCT_REV			14
    264 #define UMATCH_VENDOR_PRODUCT				13
    265 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
    266 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
    267 #define UMATCH_DEVCLASS_DEVSUBCLASS			10
    268 /* Next six codes are for interfaces. */
    269 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
    270 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
    271 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
    272 #define UMATCH_VENDOR_IFACESUBCLASS			 6
    273 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
    274 #define UMATCH_IFACECLASS_IFACESUBCLASS			 4
    275 #define UMATCH_IFACECLASS				 3
    276 #define UMATCH_IFACECLASS_GENERIC			 2
    277 /* Generic driver */
    278 #define UMATCH_GENERIC					 1
    279 /* No match */
    280 #define UMATCH_NONE					 0
    281 
    282 #elif defined(__FreeBSD__)
    283 /* FreeBSD needs values less than zero */
    284 /* for the moment disabled
    285 #define UMATCH_VENDOR_PRODUCT_REV			-14
    286 #define UMATCH_VENDOR_PRODUCT				-13
    287 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			-12
    288 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		-11
    289 #define UMATCH_DEVCLASS_DEVSUBCLASS			-10
    290 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 -9
    291 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 -8
    292 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 -7
    293 #define UMATCH_VENDOR_IFACESUBCLASS			 -6
    294 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 -5
    295 #define UMATCH_IFACECLASS_IFACESUBCLASS			 -4
    296 #define UMATCH_IFACECLASS				 -3
    297 #define UMATCH_IFACECLASS_GENERIC			 -2
    298 #define UMATCH_GENERIC					 -1
    299 #define UMATCH_NONE				      ENXIO
    300 
    301 * For the moment we use Yes/No answers with appropriate
    302 * sorting in the config file
    303 */
    304 #define UMATCH_VENDOR_PRODUCT_REV			0
    305 #define UMATCH_VENDOR_PRODUCT				0
    306 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			0
    307 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		0
    308 #define UMATCH_DEVCLASS_DEVSUBCLASS			0
    309 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		0
    310 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		0
    311 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		0
    312 #define UMATCH_VENDOR_IFACESUBCLASS			0
    313 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	0
    314 #define UMATCH_IFACECLASS_IFACESUBCLASS			0
    315 #define UMATCH_IFACECLASS				0
    316 #define UMATCH_IFACECLASS_GENERIC			0
    317 #define UMATCH_GENERIC					0
    318 #define UMATCH_NONE				      ENXIO
    319 
    320 
    321 #endif
    322 
    323 void usbd_devinfo __P((usbd_device_handle, int, char *));
    324 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
    325 void usbd_set_disco __P((usbd_pipe_handle, void (*)(void *), void *));
    326 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
    327 	__P((usbd_interface_handle iface, u_int8_t address));
    328 
    329 /* XXX */
    330 #define splusb splbio
    331 #define IPL_USB IPL_BIO
    332 /* XXX */
    333 
    334