102ac6454SAndrew Thompson /* $FreeBSD$ */ 202ac6454SAndrew Thompson /*- 302ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 602ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 702ac6454SAndrew Thompson * are met: 802ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 902ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1002ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1202ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1302ac6454SAndrew Thompson * 1402ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1502ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1602ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1702ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1802ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1902ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2002ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2102ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2202ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2302ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2402ac6454SAndrew Thompson * SUCH DAMAGE. 2502ac6454SAndrew Thompson */ 2602ac6454SAndrew Thompson 2775973647SAndrew Thompson #ifndef _USB_DEV_H_ 2875973647SAndrew Thompson #define _USB_DEV_H_ 2902ac6454SAndrew Thompson 3002ac6454SAndrew Thompson #include <sys/file.h> 31ed6d949aSAndrew Thompson #include <sys/selinfo.h> 3202ac6454SAndrew Thompson #include <sys/poll.h> 3302ac6454SAndrew Thompson #include <sys/signalvar.h> 3402ac6454SAndrew Thompson #include <sys/proc.h> 3502ac6454SAndrew Thompson 36760bc48eSAndrew Thompson struct usb_fifo; 37760bc48eSAndrew Thompson struct usb_mbuf; 3802ac6454SAndrew Thompson 39760bc48eSAndrew Thompson struct usb_symlink { 40760bc48eSAndrew Thompson TAILQ_ENTRY(usb_symlink) sym_entry; 4102ac6454SAndrew Thompson char src_path[32]; /* Source path - including terminating 4202ac6454SAndrew Thompson * zero */ 4302ac6454SAndrew Thompson char dst_path[32]; /* Destination path - including 4402ac6454SAndrew Thompson * terminating zero */ 4502ac6454SAndrew Thompson uint8_t src_len; /* String length */ 4602ac6454SAndrew Thompson uint8_t dst_len; /* String length */ 4702ac6454SAndrew Thompson }; 4802ac6454SAndrew Thompson 4902ac6454SAndrew Thompson /* 50ee3e3ff5SAndrew Thompson * Private per-device information. 51ee3e3ff5SAndrew Thompson */ 52760bc48eSAndrew Thompson struct usb_cdev_privdata { 53760bc48eSAndrew Thompson struct usb_bus *bus; 54760bc48eSAndrew Thompson struct usb_device *udev; 55760bc48eSAndrew Thompson struct usb_interface *iface; 56ee3e3ff5SAndrew Thompson int bus_index; /* bus index */ 57ee3e3ff5SAndrew Thompson int dev_index; /* device index */ 58ee3e3ff5SAndrew Thompson int ep_addr; /* endpoint address */ 597214348fSAndrew Thompson int fflags; 60ee3e3ff5SAndrew Thompson uint8_t fifo_index; /* FIFO index */ 61e13e19faSAndrew Thompson }; 62e13e19faSAndrew Thompson 63e13e19faSAndrew Thompson /* 64ed6d949aSAndrew Thompson * The following structure defines a minimum re-implementation of the 65ed6d949aSAndrew Thompson * ifqueue structure in the kernel. 66ed6d949aSAndrew Thompson */ 67ed6d949aSAndrew Thompson struct usb_ifqueue { 68ed6d949aSAndrew Thompson struct usb_mbuf *ifq_head; 69ed6d949aSAndrew Thompson struct usb_mbuf *ifq_tail; 70ed6d949aSAndrew Thompson 71ed6d949aSAndrew Thompson usb_size_t ifq_len; 72ed6d949aSAndrew Thompson usb_size_t ifq_maxlen; 73ed6d949aSAndrew Thompson }; 74ed6d949aSAndrew Thompson 75ed6d949aSAndrew Thompson /* 76e13e19faSAndrew Thompson * Private per-device and per-thread reference information 77e13e19faSAndrew Thompson */ 78e13e19faSAndrew Thompson struct usb_cdev_refdata { 79e13e19faSAndrew Thompson struct usb_fifo *rxfifo; 80e13e19faSAndrew Thompson struct usb_fifo *txfifo; 81ee3e3ff5SAndrew Thompson uint8_t is_read; /* location has read access */ 82ee3e3ff5SAndrew Thompson uint8_t is_write; /* location has write access */ 83ee3e3ff5SAndrew Thompson uint8_t is_uref; /* USB refcount decr. needed */ 84ee3e3ff5SAndrew Thompson uint8_t is_usbfs; /* USB-FS is active */ 85ee3e3ff5SAndrew Thompson }; 86ee3e3ff5SAndrew Thompson 87760bc48eSAndrew Thompson struct usb_fs_privdata { 88ee3e3ff5SAndrew Thompson int bus_index; 89ee3e3ff5SAndrew Thompson int dev_index; 90ee3e3ff5SAndrew Thompson int ep_addr; 91ee3e3ff5SAndrew Thompson int mode; 92ee3e3ff5SAndrew Thompson int fifo_index; 93ee3e3ff5SAndrew Thompson struct cdev *cdev; 94ee3e3ff5SAndrew Thompson 95760bc48eSAndrew Thompson LIST_ENTRY(usb_fs_privdata) pd_next; 96ee3e3ff5SAndrew Thompson }; 97ee3e3ff5SAndrew Thompson 98ee3e3ff5SAndrew Thompson /* 99760bc48eSAndrew Thompson * Most of the fields in the "usb_fifo" structure are used by the 10002ac6454SAndrew Thompson * generic USB access layer. 10102ac6454SAndrew Thompson */ 102760bc48eSAndrew Thompson struct usb_fifo { 103760bc48eSAndrew Thompson struct usb_ifqueue free_q; 104760bc48eSAndrew Thompson struct usb_ifqueue used_q; 10502ac6454SAndrew Thompson struct selinfo selinfo; 10602ac6454SAndrew Thompson struct cv cv_io; 10702ac6454SAndrew Thompson struct cv cv_drain; 108760bc48eSAndrew Thompson struct usb_fifo_methods *methods; 109760bc48eSAndrew Thompson struct usb_symlink *symlink[2];/* our symlinks */ 11002ac6454SAndrew Thompson struct proc *async_p; /* process that wants SIGIO */ 111760bc48eSAndrew Thompson struct usb_fs_endpoint *fs_ep_ptr; 112760bc48eSAndrew Thompson struct usb_device *udev; 113760bc48eSAndrew Thompson struct usb_xfer *xfer[2]; 114760bc48eSAndrew Thompson struct usb_xfer **fs_xfer; 11502ac6454SAndrew Thompson struct mtx *priv_mtx; /* client data */ 1167214348fSAndrew Thompson /* set if FIFO is opened by a FILE: */ 117760bc48eSAndrew Thompson struct usb_cdev_privdata *curr_cpd; 11802ac6454SAndrew Thompson void *priv_sc0; /* client data */ 11902ac6454SAndrew Thompson void *priv_sc1; /* client data */ 12002ac6454SAndrew Thompson void *queue_data; 121e0a69b51SAndrew Thompson usb_timeout_t timeout; /* timeout in milliseconds */ 122e0a69b51SAndrew Thompson usb_frlength_t bufsize; /* BULK and INTERRUPT buffer size */ 123e0a69b51SAndrew Thompson usb_frcount_t nframes; /* for isochronous mode */ 12402ac6454SAndrew Thompson uint16_t dev_ep_index; /* our device endpoint index */ 12502ac6454SAndrew Thompson uint8_t flag_sleeping; /* set if FIFO is sleeping */ 12602ac6454SAndrew Thompson uint8_t flag_iscomplete; /* set if a USB transfer is complete */ 12702ac6454SAndrew Thompson uint8_t flag_iserror; /* set if FIFO error happened */ 12802ac6454SAndrew Thompson uint8_t flag_isselect; /* set if FIFO is selected */ 12902ac6454SAndrew Thompson uint8_t flag_flushing; /* set if FIFO is flushing data */ 13002ac6454SAndrew Thompson uint8_t flag_short; /* set if short_ok or force_short 13102ac6454SAndrew Thompson * transfer flags should be set */ 13202ac6454SAndrew Thompson uint8_t flag_stall; /* set if clear stall should be run */ 13302ac6454SAndrew Thompson uint8_t iface_index; /* set to the interface we belong to */ 13402ac6454SAndrew Thompson uint8_t fifo_index; /* set to the FIFO index in "struct 135760bc48eSAndrew Thompson * usb_device" */ 13602ac6454SAndrew Thompson uint8_t fs_ep_max; 13702ac6454SAndrew Thompson uint8_t fifo_zlp; /* zero length packet count */ 13802ac6454SAndrew Thompson uint8_t refcount; 13902ac6454SAndrew Thompson #define USB_FIFO_REF_MAX 0xFF 14002ac6454SAndrew Thompson }; 14102ac6454SAndrew Thompson 142a593f6b8SAndrew Thompson extern struct cdevsw usb_devsw; 143ee3e3ff5SAndrew Thompson 144a593f6b8SAndrew Thompson int usb_fifo_wait(struct usb_fifo *fifo); 145a593f6b8SAndrew Thompson void usb_fifo_signal(struct usb_fifo *fifo); 146a593f6b8SAndrew Thompson uint8_t usb_fifo_opened(struct usb_fifo *fifo); 147a593f6b8SAndrew Thompson void usb_fifo_free(struct usb_fifo *f); 148a593f6b8SAndrew Thompson struct usb_symlink *usb_alloc_symlink(const char *target); 149a593f6b8SAndrew Thompson void usb_free_symlink(struct usb_symlink *ps); 150a593f6b8SAndrew Thompson int usb_read_symlink(uint8_t *user_ptr, uint32_t startentry, 15102ac6454SAndrew Thompson uint32_t user_len); 152a593f6b8SAndrew Thompson void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t); 15302ac6454SAndrew Thompson 15475973647SAndrew Thompson #endif /* _USB_DEV_H_ */ 155