usb_dev.h revision 196219
11638Srgrimes/* $FreeBSD: head/sys/dev/usb/usb_dev.h 196219 2009-08-14 20:03:53Z jhb $ */
21638Srgrimes/*-
31638Srgrimes * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
41638Srgrimes *
51638Srgrimes * Redistribution and use in source and binary forms, with or without
61638Srgrimes * modification, are permitted provided that the following conditions
71638Srgrimes * are met:
81638Srgrimes * 1. Redistributions of source code must retain the above copyright
91638Srgrimes *    notice, this list of conditions and the following disclaimer.
101638Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111638Srgrimes *    notice, this list of conditions and the following disclaimer in the
12263142Seadler *    documentation and/or other materials provided with the distribution.
131638Srgrimes *
141638Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151638Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161638Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171638Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181638Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191638Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201638Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211638Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221638Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231638Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241638Srgrimes * SUCH DAMAGE.
251638Srgrimes */
261638Srgrimes
271638Srgrimes#ifndef _USB_DEV_H_
281638Srgrimes#define	_USB_DEV_H_
291638Srgrimes
301638Srgrimes#include <sys/file.h>
311638Srgrimes#include <sys/selinfo.h>
321638Srgrimes#include <sys/poll.h>
331638Srgrimes#include <sys/signalvar.h>
341638Srgrimes#include <sys/proc.h>
351638Srgrimes
361638Srgrimesstruct usb_fifo;
371638Srgrimesstruct usb_mbuf;
381638Srgrimes
391638Srgrimesstruct usb_symlink {
401638Srgrimes	TAILQ_ENTRY(usb_symlink) sym_entry;
411638Srgrimes	char	src_path[32];		/* Source path - including terminating
421638Srgrimes					 * zero */
431638Srgrimes	char	dst_path[32];		/* Destination path - including
441638Srgrimes					 * terminating zero */
451638Srgrimes	uint8_t	src_len;		/* String length */
461638Srgrimes	uint8_t	dst_len;		/* String length */
471638Srgrimes};
481638Srgrimes
491638Srgrimes/*
501638Srgrimes * Private per-device information.
511638Srgrimes */
521638Srgrimesstruct usb_cdev_privdata {
531638Srgrimes	struct usb_bus		*bus;
541638Srgrimes	struct usb_device	*udev;
551638Srgrimes	struct usb_interface	*iface;
561638Srgrimes	int			bus_index;	/* bus index */
571638Srgrimes	int			dev_index;	/* device index */
581638Srgrimes	int			ep_addr;	/* endpoint address */
591638Srgrimes	int			fflags;
601638Srgrimes	uint8_t			fifo_index;	/* FIFO index */
611638Srgrimes};
621638Srgrimes
631638Srgrimes/*
641638Srgrimes * The following structure defines a minimum re-implementation of the
651638Srgrimes * ifqueue structure in the kernel.
661638Srgrimes */
671638Srgrimesstruct usb_ifqueue {
681638Srgrimes	struct usb_mbuf *ifq_head;
691638Srgrimes	struct usb_mbuf *ifq_tail;
701638Srgrimes
711638Srgrimes	usb_size_t ifq_len;
721638Srgrimes	usb_size_t ifq_maxlen;
731638Srgrimes};
741638Srgrimes
751638Srgrimes/*
761638Srgrimes * Private per-device and per-thread reference information
771638Srgrimes */
781638Srgrimesstruct usb_cdev_refdata {
791638Srgrimes	struct usb_fifo		*rxfifo;
801638Srgrimes	struct usb_fifo		*txfifo;
811638Srgrimes	uint8_t			is_read;	/* location has read access */
821638Srgrimes	uint8_t			is_write;	/* location has write access */
831638Srgrimes	uint8_t			is_uref;	/* USB refcount decr. needed */
841638Srgrimes	uint8_t			is_usbfs;	/* USB-FS is active */
851638Srgrimes};
861638Srgrimes
871638Srgrimesstruct usb_fs_privdata {
881638Srgrimes	int bus_index;
891638Srgrimes	int dev_index;
901638Srgrimes	int ep_addr;
911638Srgrimes	int mode;
921638Srgrimes	int fifo_index;
931638Srgrimes	struct cdev *cdev;
941638Srgrimes
951638Srgrimes	LIST_ENTRY(usb_fs_privdata) pd_next;
961638Srgrimes};
971638Srgrimes
981638Srgrimes/*
991638Srgrimes * Most of the fields in the "usb_fifo" structure are used by the
1001638Srgrimes * generic USB access layer.
1011638Srgrimes */
1021638Srgrimesstruct usb_fifo {
1031638Srgrimes	struct usb_ifqueue free_q;
1041638Srgrimes	struct usb_ifqueue used_q;
1051638Srgrimes	struct selinfo selinfo;
1061638Srgrimes	struct cv cv_io;
1071638Srgrimes	struct cv cv_drain;
1081638Srgrimes	struct usb_fifo_methods *methods;
1091638Srgrimes	struct usb_symlink *symlink[2];/* our symlinks */
1101638Srgrimes	struct proc *async_p;		/* process that wants SIGIO */
1111638Srgrimes	struct usb_fs_endpoint *fs_ep_ptr;
1121638Srgrimes	struct usb_device *udev;
1131638Srgrimes	struct usb_xfer *xfer[2];
1141638Srgrimes	struct usb_xfer **fs_xfer;
1151638Srgrimes	struct mtx *priv_mtx;		/* client data */
1161638Srgrimes	/* set if FIFO is opened by a FILE: */
1171638Srgrimes	struct usb_cdev_privdata *curr_cpd;
1181638Srgrimes	void   *priv_sc0;		/* client data */
1191638Srgrimes	void   *priv_sc1;		/* client data */
1201638Srgrimes	void   *queue_data;
1211638Srgrimes	usb_timeout_t timeout;		/* timeout in milliseconds */
1221638Srgrimes	usb_frlength_t bufsize;		/* BULK and INTERRUPT buffer size */
1231638Srgrimes	usb_frcount_t nframes;		/* for isochronous mode */
1241638Srgrimes	uint16_t dev_ep_index;		/* our device endpoint index */
1251638Srgrimes	uint8_t	flag_sleeping;		/* set if FIFO is sleeping */
1261638Srgrimes	uint8_t	flag_iscomplete;	/* set if a USB transfer is complete */
1271638Srgrimes	uint8_t	flag_iserror;		/* set if FIFO error happened */
1281638Srgrimes	uint8_t	flag_isselect;		/* set if FIFO is selected */
1291638Srgrimes	uint8_t	flag_flushing;		/* set if FIFO is flushing data */
1301638Srgrimes	uint8_t	flag_short;		/* set if short_ok or force_short
1311638Srgrimes					 * transfer flags should be set */
1321638Srgrimes	uint8_t	flag_stall;		/* set if clear stall should be run */
1331638Srgrimes	uint8_t	flag_write_defrag;	/* set to defrag written data */
1341638Srgrimes	uint8_t	flag_have_fragment;	/* set if defragging */
1351638Srgrimes	uint8_t	iface_index;		/* set to the interface we belong to */
1361638Srgrimes	uint8_t	fifo_index;		/* set to the FIFO index in "struct
1371638Srgrimes					 * usb_device" */
1381638Srgrimes	uint8_t	fs_ep_max;
1391638Srgrimes	uint8_t	fifo_zlp;		/* zero length packet count */
1401638Srgrimes	uint8_t	refcount;
1411638Srgrimes#define	USB_FIFO_REF_MAX 0xFF
1421638Srgrimes};
1431638Srgrimes
1441638Srgrimesextern struct cdevsw usb_devsw;
1451638Srgrimes
1461638Srgrimesint	usb_fifo_wait(struct usb_fifo *fifo);
1471638Srgrimesvoid	usb_fifo_signal(struct usb_fifo *fifo);
1481638Srgrimesuint8_t	usb_fifo_opened(struct usb_fifo *fifo);
1491638Srgrimesstruct usb_symlink *usb_alloc_symlink(const char *target);
1501638Srgrimesvoid	usb_free_symlink(struct usb_symlink *ps);
1511638Srgrimesint	usb_read_symlink(uint8_t *user_ptr, uint32_t startentry,
1521638Srgrimes	    uint32_t user_len);
1531638Srgrimes
1541638Srgrimes#endif					/* _USB_DEV_H_ */
1551638Srgrimes