Home | History | Annotate | Line # | Download | only in usb
usbdi.h revision 1.37
      1 /*	$NetBSD: usbdi.h,v 1.37 2000/01/16 13:12:05 augustss Exp $	*/
      2 /*	$FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $	*/
      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 (at) 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_xfer	*usbd_xfer_handle;
     46 typedef void			*usbd_private_handle;
     47 
     48 typedef enum {		/* keep in sync with usbd_status_msgs */
     49 	USBD_NORMAL_COMPLETION = 0, /* must be 0 */
     50 	USBD_IN_PROGRESS,
     51 	/* errors */
     52 	USBD_PENDING_REQUESTS,
     53 	USBD_NOT_STARTED,
     54 	USBD_INVAL,
     55 	USBD_NOMEM,
     56 	USBD_CANCELLED,
     57 	USBD_BAD_ADDRESS,
     58 	USBD_IN_USE,
     59 	USBD_NO_ADDR,
     60 	USBD_SET_ADDR_FAILED,
     61 	USBD_NO_POWER,
     62 	USBD_TOO_DEEP,
     63 	USBD_IOERROR,
     64 	USBD_NOT_CONFIGURED,
     65 	USBD_TIMEOUT,
     66 	USBD_SHORT_XFER,
     67 	USBD_STALLED,
     68 	USBD_INTERRUPTED,
     69 
     70 	USBD_ERROR_MAX,		/* must be last */
     71 } usbd_status;
     72 
     73 typedef void (*usbd_callback) __P((usbd_xfer_handle, usbd_private_handle,
     74 				   usbd_status));
     75 
     76 /* Open flags */
     77 #define USBD_EXCLUSIVE_USE	0x01
     78 
     79 /* Request flags */
     80 #define USBD_NO_COPY		0x01	/* do not copy data to DMA buffer */
     81 #define USBD_SYNCHRONOUS	0x02	/* wait for completion */
     82 /* in usb.h #define USBD_SHORT_XFER_OK	0x04*/	/* allow short reads */
     83 #define USBD_FORCE_SHORT_XFER	0x08	/* force last short packet on write */
     84 
     85 /* XXX Temporary hack XXX */
     86 #define USBD_NO_TSLEEP		0x80	/* XXX use busy wait */
     87 
     88 #define USBD_NO_TIMEOUT 0
     89 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
     90 
     91 #if defined(__FreeBSD__)
     92 #define USB_CDEV_MAJOR 108
     93 #endif
     94 
     95 usbd_status usbd_open_pipe
     96 	__P((usbd_interface_handle iface, u_int8_t address,
     97 	     u_int8_t flags, usbd_pipe_handle *pipe));
     98 usbd_status usbd_close_pipe	__P((usbd_pipe_handle pipe));
     99 usbd_status usbd_transfer	__P((usbd_xfer_handle req));
    100 usbd_xfer_handle usbd_alloc_xfer __P((usbd_device_handle));
    101 usbd_status usbd_free_xfer	__P((usbd_xfer_handle xfer));
    102 void usbd_setup_xfer
    103 	__P((usbd_xfer_handle xfer, usbd_pipe_handle pipe,
    104 	     usbd_private_handle priv, void *buffer,
    105 	     u_int32_t length, u_int16_t flags, u_int32_t timeout,
    106 	     usbd_callback));
    107 void usbd_setup_default_xfer
    108 	__P((usbd_xfer_handle xfer, usbd_device_handle dev,
    109 	     usbd_private_handle priv, u_int32_t timeout,
    110 	     usb_device_request_t *req,  void *buffer,
    111 	     u_int32_t length, u_int16_t flags, usbd_callback));
    112 void usbd_setup_isoc_xfer
    113 	__P((usbd_xfer_handle xfer, usbd_pipe_handle pipe,
    114 	     usbd_private_handle priv, u_int16_t *frlengths,
    115 	     u_int32_t nframes, u_int16_t flags, usbd_callback));
    116 void usbd_get_xfer_status
    117 	__P((usbd_xfer_handle xfer, usbd_private_handle *priv,
    118 	     void **buffer, u_int32_t *count, usbd_status *status));
    119 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
    120 	__P((usbd_interface_handle iface, u_int8_t address));
    121 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
    122 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
    123 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe));
    124 usbd_status usbd_endpoint_count
    125 	__P((usbd_interface_handle dev, u_int8_t *count));
    126 usbd_status usbd_interface_count
    127 	__P((usbd_device_handle dev, u_int8_t *count));
    128 usbd_status usbd_interface2device_handle
    129 	__P((usbd_interface_handle iface, usbd_device_handle *dev));
    130 usbd_status usbd_device2interface_handle
    131 	__P((usbd_device_handle dev, u_int8_t ifaceno, usbd_interface_handle *iface));
    132 
    133 usbd_device_handle usbd_pipe2device_handle __P((usbd_pipe_handle));
    134 void *usbd_alloc_buffer __P((usbd_xfer_handle req, u_int32_t size));
    135 void usbd_free_buffer __P((usbd_xfer_handle req));
    136 void *usbd_get_buffer __P((usbd_xfer_handle xfer));
    137 usbd_status usbd_sync_transfer	__P((usbd_xfer_handle req));
    138 usbd_status usbd_open_pipe_intr
    139 	__P((usbd_interface_handle iface, u_int8_t address,
    140 	     u_int8_t flags, usbd_pipe_handle *pipe,
    141 	     usbd_private_handle priv, void *buffer,
    142 	     u_int32_t length, usbd_callback));
    143 usbd_status usbd_do_request
    144 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    145 usbd_status usbd_do_request_async
    146 	__P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
    147 usbd_status usbd_do_request_flags
    148 	__P((usbd_device_handle pipe, usb_device_request_t *req,
    149 	     void *data, u_int16_t flags, int *));
    150 usb_interface_descriptor_t *usbd_get_interface_descriptor
    151 	__P((usbd_interface_handle iface));
    152 usb_config_descriptor_t *usbd_get_config_descriptor
    153 	__P((usbd_device_handle dev));
    154 usb_device_descriptor_t *usbd_get_device_descriptor
    155 	__P((usbd_device_handle dev));
    156 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
    157 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
    158 usbd_status	usbd_get_interface
    159 	__P((usbd_interface_handle iface, u_int8_t *aiface));
    160 void usbd_fill_deviceinfo
    161 	__P((usbd_device_handle dev, struct usb_device_info *di));
    162 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
    163 
    164 usb_interface_descriptor_t *usbd_find_idesc
    165 	__P((usb_config_descriptor_t *cd, int iindex, int ano));
    166 usb_endpoint_descriptor_t *usbd_find_edesc
    167 	__P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
    168 	     int endptidx));
    169 
    170 void usbd_dopoll __P((usbd_interface_handle));
    171 void usbd_set_polling __P((usbd_device_handle iface, int on));
    172 
    173 const char *usbd_errstr __P((usbd_status err));
    174 
    175 void usbd_add_event __P((int, usbd_device_handle));
    176 
    177 /* NetBSD attachment information */
    178 
    179 /* Attach data */
    180 struct usb_attach_arg {
    181 	int			port;
    182 	int			configno;
    183 	int			ifaceno;
    184 	int			vendor;
    185 	int			product;
    186 	int			release;
    187 	usbd_device_handle	device;	/* current device */
    188 	usbd_interface_handle	iface; /* current interface */
    189 	int			usegeneric;
    190 	usbd_interface_handle  *ifaces;	/* all interfaces */
    191 	int			nifaces; /* number of interfaces */
    192 };
    193 
    194 #if defined(__NetBSD__) || defined(__OpenBSD__)
    195 /* Match codes. */
    196 /* First five codes is for a whole device. */
    197 #define UMATCH_VENDOR_PRODUCT_REV			14
    198 #define UMATCH_VENDOR_PRODUCT				13
    199 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
    200 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
    201 #define UMATCH_DEVCLASS_DEVSUBCLASS			10
    202 /* Next six codes are for interfaces. */
    203 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
    204 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
    205 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
    206 #define UMATCH_VENDOR_IFACESUBCLASS			 6
    207 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
    208 #define UMATCH_IFACECLASS_IFACESUBCLASS			 4
    209 #define UMATCH_IFACECLASS				 3
    210 #define UMATCH_IFACECLASS_GENERIC			 2
    211 /* Generic driver */
    212 #define UMATCH_GENERIC					 1
    213 /* No match */
    214 #define UMATCH_NONE					 0
    215 
    216 #elif defined(__FreeBSD__)
    217 /* FreeBSD needs values less than zero */
    218 #define UMATCH_VENDOR_PRODUCT_REV			(-10)
    219 #define UMATCH_VENDOR_PRODUCT				(-20)
    220 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			(-30)
    221 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		(-40)
    222 #define UMATCH_DEVCLASS_DEVSUBCLASS			(-50)
    223 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		(-60)
    224 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		(-70)
    225 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		(-80)
    226 #define UMATCH_VENDOR_IFACESUBCLASS			(-90)
    227 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	(-100)
    228 #define UMATCH_IFACECLASS_IFACESUBCLASS			(-110)
    229 #define UMATCH_IFACECLASS				(-120)
    230 #define UMATCH_IFACECLASS_GENERIC			(-130)
    231 #define UMATCH_GENERIC					(-140)
    232 #define UMATCH_NONE					(ENXIO)
    233 
    234 #endif
    235 
    236 void usbd_devinfo __P((usbd_device_handle, int, char *));
    237 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
    238 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
    239 	__P((usbd_interface_handle iface, u_int8_t address));
    240 
    241 #if defined(__FreeBSD__)
    242 int usbd_driver_load    __P((module_t mod, int what, void *arg));
    243 #endif
    244 
    245 /*
    246  * XXX
    247  * splusb MUST be the lowest level interrupt so that within USB callbacks
    248  * the level can be raised the appropriate level.
    249  * XXX Should probably use a softsplusb.
    250  */
    251 /* XXX */
    252 #define splusb splbio
    253 #define IPL_USB IPL_BIO
    254 /* XXX */
    255