Home | History | Annotate | Line # | Download | only in usb
usbdi.h revision 1.94
      1  1.94   khorben /*	$NetBSD: usbdi.h,v 1.94 2018/07/31 16:44:30 khorben Exp $	*/
      2  1.34  augustss /*	$FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $	*/
      3   1.1  augustss 
      4   1.1  augustss /*
      5   1.1  augustss  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      6   1.1  augustss  * All rights reserved.
      7   1.1  augustss  *
      8   1.7  augustss  * This code is derived from software contributed to The NetBSD Foundation
      9  1.42  augustss  * by Lennart Augustsson (lennart (at) augustsson.net) at
     10   1.7  augustss  * Carlstedt Research & Technology.
     11   1.1  augustss  *
     12   1.1  augustss  * Redistribution and use in source and binary forms, with or without
     13   1.1  augustss  * modification, are permitted provided that the following conditions
     14   1.1  augustss  * are met:
     15   1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     16   1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     17   1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     19   1.1  augustss  *    documentation and/or other materials provided with the distribution.
     20   1.1  augustss  *
     21   1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22   1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23   1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24   1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25   1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26   1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27   1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28   1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29   1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30   1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31   1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     32   1.1  augustss  */
     33   1.1  augustss 
     34  1.74  drochner #ifndef _USBDI_H_
     35  1.74  drochner #define _USBDI_H_
     36  1.74  drochner 
     37  1.91     skrll struct usbd_bus;
     38  1.91     skrll struct usbd_device;
     39  1.91     skrll struct usbd_interface;
     40  1.91     skrll struct usbd_pipe;
     41  1.91     skrll struct usbd_xfer;
     42   1.1  augustss 
     43  1.82  jakllsch typedef enum {		/* keep in sync with usbd_error_strs */
     44  1.23  augustss 	USBD_NORMAL_COMPLETION = 0, /* must be 0 */
     45  1.58  augustss 	USBD_IN_PROGRESS,	/* 1 */
     46   1.1  augustss 	/* errors */
     47  1.58  augustss 	USBD_PENDING_REQUESTS,	/* 2 */
     48  1.58  augustss 	USBD_NOT_STARTED,	/* 3 */
     49  1.58  augustss 	USBD_INVAL,		/* 4 */
     50  1.58  augustss 	USBD_NOMEM,		/* 5 */
     51  1.58  augustss 	USBD_CANCELLED,		/* 6 */
     52  1.58  augustss 	USBD_BAD_ADDRESS,	/* 7 */
     53  1.58  augustss 	USBD_IN_USE,		/* 8 */
     54  1.58  augustss 	USBD_NO_ADDR,		/* 9 */
     55  1.58  augustss 	USBD_SET_ADDR_FAILED,	/* 10 */
     56  1.58  augustss 	USBD_NO_POWER,		/* 11 */
     57  1.58  augustss 	USBD_TOO_DEEP,		/* 12 */
     58  1.58  augustss 	USBD_IOERROR,		/* 13 */
     59  1.58  augustss 	USBD_NOT_CONFIGURED,	/* 14 */
     60  1.58  augustss 	USBD_TIMEOUT,		/* 15 */
     61  1.58  augustss 	USBD_SHORT_XFER,	/* 16 */
     62  1.58  augustss 	USBD_STALLED,		/* 17 */
     63  1.58  augustss 	USBD_INTERRUPTED,	/* 18 */
     64   1.1  augustss 
     65  1.52     lukem 	USBD_ERROR_MAX		/* must be last */
     66   1.1  augustss } usbd_status;
     67   1.1  augustss 
     68  1.91     skrll typedef void (*usbd_callback)(struct usbd_xfer *, void *, usbd_status);
     69  1.91     skrll 
     70  1.91     skrll /* Use default (specified by ep. desc.) interval on interrupt pipe */
     71  1.91     skrll #define USBD_DEFAULT_INTERVAL	(-1)
     72   1.1  augustss 
     73   1.1  augustss /* Open flags */
     74   1.1  augustss #define USBD_EXCLUSIVE_USE	0x01
     75  1.87  jmcneill #define USBD_MPSAFE		0x80
     76   1.1  augustss 
     77   1.1  augustss /* Request flags */
     78  1.29  augustss #define USBD_SYNCHRONOUS	0x02	/* wait for completion */
     79  1.28  augustss /* in usb.h #define USBD_SHORT_XFER_OK	0x04*/	/* allow short reads */
     80  1.37  augustss #define USBD_FORCE_SHORT_XFER	0x08	/* force last short packet on write */
     81  1.83       mrg #define USBD_SYNCHRONOUS_SIG	0x10	/* if waiting for completion,
     82  1.83       mrg 					 * also take signals */
     83   1.1  augustss 
     84   1.1  augustss #define USBD_NO_TIMEOUT 0
     85   1.1  augustss #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
     86  1.78    martin #define	USBD_CONFIG_TIMEOUT  (3*USBD_DEFAULT_TIMEOUT)
     87   1.1  augustss 
     88  1.66     soren #define DEVINFOSIZE 1024
     89  1.66     soren 
     90  1.91     skrll usbd_status usbd_open_pipe_intr(struct usbd_interface *, uint8_t, uint8_t,
     91  1.91     skrll     struct usbd_pipe **, void *, void *, uint32_t, usbd_callback, int);
     92  1.91     skrll usbd_status usbd_open_pipe(struct usbd_interface *, uint8_t, uint8_t,
     93  1.91     skrll      struct usbd_pipe **);
     94  1.91     skrll usbd_status usbd_close_pipe(struct usbd_pipe *);
     95  1.91     skrll 
     96  1.91     skrll usbd_status usbd_transfer(struct usbd_xfer *);
     97  1.91     skrll 
     98  1.91     skrll void *usbd_get_buffer(struct usbd_xfer *);
     99  1.91     skrll struct usbd_pipe *usbd_get_pipe0(struct usbd_device *);
    100  1.91     skrll 
    101  1.91     skrll int usbd_create_xfer(struct usbd_pipe *, size_t, unsigned int, unsigned int,
    102  1.91     skrll     struct usbd_xfer **);
    103  1.91     skrll void usbd_destroy_xfer(struct usbd_xfer *);
    104  1.91     skrll 
    105  1.91     skrll void usbd_setup_xfer(struct usbd_xfer *, void *, void *,
    106  1.91     skrll     uint32_t, uint16_t, uint32_t, usbd_callback);
    107  1.91     skrll 
    108  1.91     skrll void usbd_setup_default_xfer(struct usbd_xfer *, struct usbd_device *,
    109  1.91     skrll     void *, uint32_t, usb_device_request_t *, void *,
    110  1.91     skrll     uint32_t, uint16_t, usbd_callback);
    111  1.91     skrll 
    112  1.91     skrll void usbd_setup_isoc_xfer(struct usbd_xfer *, void *, uint16_t *,
    113  1.91     skrll     uint32_t, uint16_t, usbd_callback);
    114  1.91     skrll 
    115  1.91     skrll void usbd_get_xfer_status(struct usbd_xfer *, void **,
    116  1.91     skrll     void **, uint32_t *, usbd_status *);
    117  1.91     skrll 
    118   1.1  augustss usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
    119  1.91     skrll     (struct usbd_interface *, uint8_t);
    120  1.91     skrll 
    121  1.91     skrll usbd_status usbd_abort_pipe(struct usbd_pipe *);
    122  1.91     skrll usbd_status usbd_abort_default_pipe(struct usbd_device *);
    123  1.91     skrll 
    124  1.91     skrll usbd_status usbd_clear_endpoint_stall(struct usbd_pipe *);
    125  1.91     skrll void usbd_clear_endpoint_stall_async(struct usbd_pipe *);
    126  1.91     skrll 
    127  1.91     skrll void usbd_clear_endpoint_toggle(struct usbd_pipe *);
    128  1.91     skrll usbd_status usbd_endpoint_count(struct usbd_interface *, uint8_t *);
    129  1.91     skrll 
    130  1.91     skrll usbd_status usbd_interface_count(struct usbd_device *, uint8_t *);
    131  1.91     skrll 
    132  1.91     skrll void usbd_interface2device_handle(struct usbd_interface *, struct usbd_device **);
    133  1.91     skrll usbd_status usbd_device2interface_handle(struct usbd_device *,
    134  1.91     skrll     uint8_t, struct usbd_interface **);
    135  1.91     skrll 
    136  1.91     skrll struct usbd_device *usbd_pipe2device_handle(struct usbd_pipe *);
    137  1.91     skrll 
    138  1.91     skrll usbd_status usbd_sync_transfer(struct usbd_xfer *);
    139  1.91     skrll usbd_status usbd_sync_transfer_sig(struct usbd_xfer *);
    140  1.91     skrll 
    141  1.91     skrll usbd_status usbd_do_request(struct usbd_device *, usb_device_request_t *, void *);
    142  1.94   khorben usbd_status usbd_request_async(struct usbd_device *, struct usbd_xfer *,
    143  1.94   khorben     usb_device_request_t *, void *, usbd_callback);
    144  1.91     skrll usbd_status usbd_do_request_flags(struct usbd_device *, usb_device_request_t *,
    145  1.91     skrll     void *, uint16_t, int *, uint32_t);
    146  1.91     skrll 
    147  1.91     skrll usb_interface_descriptor_t *
    148  1.91     skrll     usbd_get_interface_descriptor(struct usbd_interface *);
    149  1.91     skrll usb_endpoint_descriptor_t *
    150  1.91     skrll     usbd_get_endpoint_descriptor(struct usbd_interface *, uint8_t);
    151  1.91     skrll 
    152  1.91     skrll usb_config_descriptor_t *usbd_get_config_descriptor(struct usbd_device *);
    153  1.91     skrll usb_device_descriptor_t *usbd_get_device_descriptor(struct usbd_device *);
    154  1.91     skrll 
    155  1.91     skrll usbd_status usbd_set_interface(struct usbd_interface *, int);
    156  1.91     skrll usbd_status usbd_get_interface(struct usbd_interface *, uint8_t *);
    157  1.91     skrll 
    158  1.43  augustss int usbd_get_no_alts(usb_config_descriptor_t *, int);
    159  1.91     skrll 
    160  1.91     skrll void usbd_fill_deviceinfo(struct usbd_device *, struct usb_device_info *, int);
    161  1.72  christos #ifdef COMPAT_30
    162  1.91     skrll void usbd_fill_deviceinfo_old(struct usbd_device *, struct usb_device_info_old *,
    163  1.72  christos     int);
    164  1.72  christos #endif
    165  1.91     skrll int usbd_get_interface_altindex(struct usbd_interface *);
    166  1.43  augustss 
    167  1.63    itojun usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
    168  1.91     skrll     int, int);
    169  1.63    itojun usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *,
    170  1.91     skrll     int, int, int);
    171  1.43  augustss 
    172  1.91     skrll void usbd_dopoll(struct usbd_interface *);
    173  1.91     skrll void usbd_set_polling(struct usbd_device *, int);
    174  1.23  augustss 
    175  1.63    itojun const char *usbd_errstr(usbd_status);
    176  1.30  augustss 
    177  1.91     skrll void usbd_add_dev_event(int, struct usbd_device *);
    178  1.91     skrll void usbd_add_drv_event(int, struct usbd_device *, device_t);
    179   1.1  augustss 
    180  1.91     skrll char *usbd_devinfo_alloc(struct usbd_device *, int);
    181  1.67  christos void usbd_devinfo_free(char *);
    182  1.65  augustss 
    183  1.91     skrll const struct usbd_quirks *usbd_get_quirks(struct usbd_device *);
    184  1.38  augustss 
    185  1.91     skrll usbd_status usbd_reload_device_desc(struct usbd_device *);
    186  1.41  augustss 
    187  1.67  christos int usbd_ratecheck(struct timeval *);
    188  1.48  augustss 
    189  1.91     skrll usbd_status usbd_get_string(struct usbd_device *, int, char *);
    190  1.91     skrll usbd_status usbd_get_string0(struct usbd_device *, int, char *, int);
    191  1.64  augustss 
    192  1.64  augustss /* An iterator for descriptors. */
    193  1.64  augustss typedef struct {
    194  1.64  augustss 	const uByte *cur;
    195  1.64  augustss 	const uByte *end;
    196  1.64  augustss } usbd_desc_iter_t;
    197  1.91     skrll void usb_desc_iter_init(struct usbd_device *, usbd_desc_iter_t *);
    198  1.67  christos const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
    199  1.64  augustss 
    200  1.84       mrg /* Used to clear endpoint stalls from the softint */
    201  1.89     skrll void usbd_clear_endpoint_stall_task(void *);
    202  1.84       mrg 
    203  1.48  augustss /*
    204  1.48  augustss  * The usb_task structs form a queue of things to run in the USB event
    205  1.48  augustss  * thread.  Normally this is just device discovery when a connect/disconnect
    206  1.48  augustss  * has been detected.  But it may also be used by drivers that need to
    207  1.48  augustss  * perform (short) tasks that must have a process context.
    208  1.48  augustss  */
    209  1.48  augustss struct usb_task {
    210  1.49  augustss 	TAILQ_ENTRY(usb_task) next;
    211  1.48  augustss 	void (*fun)(void *);
    212  1.48  augustss 	void *arg;
    213  1.90  riastrad 	volatile unsigned queue;
    214  1.85  jmcneill 	int flags;
    215  1.48  augustss };
    216  1.70     joerg #define	USB_TASKQ_HC		0
    217  1.70     joerg #define	USB_TASKQ_DRIVER	1
    218  1.70     joerg #define	USB_NUM_TASKQS		2
    219  1.70     joerg #define	USB_TASKQ_NAMES		{"usbtask-hc", "usbtask-dr"}
    220  1.87  jmcneill #define	USB_TASKQ_MPSAFE	0x80
    221  1.48  augustss 
    222  1.91     skrll void usb_add_task(struct usbd_device *, struct usb_task *, int);
    223  1.91     skrll void usb_rem_task(struct usbd_device *, struct usb_task *);
    224  1.93  riastrad void usb_rem_task_wait(struct usbd_device *, struct usb_task *, int);
    225  1.90  riastrad #define usb_init_task(t, f, a, fl) ((t)->fun = (f), (t)->arg = (a), (t)->queue = USB_NUM_TASKQS, (t)->flags = (fl))
    226  1.55  augustss 
    227  1.55  augustss struct usb_devno {
    228  1.91     skrll 	uint16_t ud_vendor;
    229  1.91     skrll 	uint16_t ud_product;
    230  1.55  augustss };
    231  1.63    itojun const struct usb_devno *usb_match_device(const struct usb_devno *,
    232  1.91     skrll 	u_int, u_int, uint16_t, uint16_t);
    233  1.56  augustss #define usb_lookup(tbl, vendor, product) \
    234  1.91     skrll 	usb_match_device((const struct usb_devno *)(tbl), sizeof(tbl) / sizeof((tbl)[0]), sizeof((tbl)[0]), (vendor), (product))
    235  1.59  augustss #define	USB_PRODUCT_ANY		0xffff
    236  1.38  augustss 
    237   1.1  augustss /* NetBSD attachment information */
    238   1.1  augustss 
    239   1.1  augustss /* Attach data */
    240   1.1  augustss struct usb_attach_arg {
    241  1.91     skrll 	int			uaa_port;
    242  1.91     skrll 	int			uaa_vendor;
    243  1.91     skrll 	int			uaa_product;
    244  1.91     skrll 	int			uaa_release;
    245  1.91     skrll 	struct usbd_device *	uaa_device;	/* current device */
    246  1.91     skrll 	int			uaa_class;
    247  1.91     skrll 	int			uaa_subclass;
    248  1.91     skrll 	int			uaa_proto;
    249  1.91     skrll 	int			uaa_usegeneric;
    250  1.73  drochner };
    251  1.73  drochner 
    252  1.73  drochner struct usbif_attach_arg {
    253  1.91     skrll 	int			uiaa_port;
    254  1.91     skrll 	int			uiaa_configno;
    255  1.91     skrll 	int			uiaa_ifaceno;
    256  1.91     skrll 	int			uiaa_vendor;
    257  1.91     skrll 	int			uiaa_product;
    258  1.91     skrll 	int			uiaa_release;
    259  1.91     skrll 	struct usbd_device *	uiaa_device;	/* current device */
    260  1.91     skrll 
    261  1.91     skrll 	struct usbd_interface *	uiaa_iface;	/* current interface */
    262  1.91     skrll 	int			uiaa_class;
    263  1.91     skrll 	int			uiaa_subclass;
    264  1.91     skrll 	int			uiaa_proto;
    265  1.73  drochner 
    266  1.73  drochner 	/* XXX need accounting for interfaces not matched to */
    267  1.73  drochner 
    268  1.91     skrll 	struct usbd_interface **uiaa_ifaces;	/* all interfaces */
    269  1.91     skrll 	int			uiaa_nifaces;	/* number of interfaces */
    270   1.1  augustss };
    271   1.1  augustss 
    272   1.1  augustss /* Match codes. */
    273  1.69  augustss #define UMATCH_HIGHEST					15
    274   1.1  augustss /* First five codes is for a whole device. */
    275   1.1  augustss #define UMATCH_VENDOR_PRODUCT_REV			14
    276   1.1  augustss #define UMATCH_VENDOR_PRODUCT				13
    277   1.1  augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO			12
    278   1.1  augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO		11
    279   1.1  augustss #define UMATCH_DEVCLASS_DEVSUBCLASS			10
    280   1.1  augustss /* Next six codes are for interfaces. */
    281   1.1  augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE		 9
    282   1.1  augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE		 8
    283   1.1  augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO		 7
    284   1.1  augustss #define UMATCH_VENDOR_IFACESUBCLASS			 6
    285   1.1  augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO	 5
    286   1.1  augustss #define UMATCH_IFACECLASS_IFACESUBCLASS			 4
    287   1.1  augustss #define UMATCH_IFACECLASS				 3
    288   1.1  augustss #define UMATCH_IFACECLASS_GENERIC			 2
    289   1.1  augustss /* Generic driver */
    290   1.1  augustss #define UMATCH_GENERIC					 1
    291   1.1  augustss /* No match */
    292   1.1  augustss #define UMATCH_NONE					 0
    293  1.12  augustss 
    294  1.88     skrll 
    295  1.88     skrll /*
    296  1.88     skrll  * IPL_USB is defined as IPL_VM for drivers that have not been made MP safe.
    297  1.88     skrll  * IPL_VM (currently) takes the kernel lock.
    298  1.88     skrll  *
    299  1.88     skrll  * Eventually, IPL_USB can/should be changed
    300  1.88     skrll  */
    301  1.92     skrll #define IPL_USB IPL_VM
    302  1.88     skrll #define splhardusb splvm
    303  1.92     skrll 
    304  1.92     skrll #define SOFTINT_USB SOFTINT_SERIAL
    305  1.92     skrll #define IPL_SOFTUSB IPL_SOFTSERIAL
    306  1.92     skrll #define splusb splsoftserial
    307  1.74  drochner 
    308  1.74  drochner #endif /* _USBDI_H_ */
    309