1/*-
2 * Copyright (c) 1990, 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from the Stanford/CMU enet packet filter,
6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8 * Berkeley Laboratory.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * $FreeBSD$
35 */
36
37#ifndef _DEV_USB_PF_H
38#define	_DEV_USB_PF_H
39
40struct usbpf_pkthdr {
41	uint32_t	up_totlen;	/* Total length including all headers */
42	uint32_t	up_busunit;	/* Host controller unit number */
43	uint8_t		up_address;	/* USB device index */
44	uint8_t		up_mode;	/* Mode of transfer */
45#define	USBPF_MODE_HOST		0
46#define	USBPF_MODE_DEVICE	1
47	uint8_t		up_type;	/* points SUBMIT / DONE */
48	uint8_t		up_xfertype;	/* Transfer type, see USB2.0 spec. */
49	uint32_t	up_flags;	/* Transfer flags */
50#define	USBPF_FLAG_FORCE_SHORT_XFER	(1 << 0)
51#define	USBPF_FLAG_SHORT_XFER_OK	(1 << 1)
52#define	USBPF_FLAG_SHORT_FRAMES_OK	(1 << 2)
53#define	USBPF_FLAG_PIPE_BOF		(1 << 3)
54#define	USBPF_FLAG_PROXY_BUFFER		(1 << 4)
55#define	USBPF_FLAG_EXT_BUFFER		(1 << 5)
56#define	USBPF_FLAG_MANUAL_STATUS	(1 << 6)
57#define	USBPF_FLAG_NO_PIPE_OK		(1 << 7)
58#define	USBPF_FLAG_STALL_PIPE		(1 << 8)
59	uint32_t	up_status;	/* Transfer status */
60#define	USBPF_STATUS_OPEN		(1 << 0)
61#define	USBPF_STATUS_TRANSFERRING	(1 << 1)
62#define	USBPF_STATUS_DID_DMA_DELAY	(1 << 2)
63#define	USBPF_STATUS_DID_CLOSE		(1 << 3)
64#define	USBPF_STATUS_DRAINING		(1 << 4)
65#define	USBPF_STATUS_STARTED		(1 << 5)
66#define	USBPF_STATUS_BW_RECLAIMED	(1 << 6)
67#define	USBPF_STATUS_CONTROL_XFR	(1 << 7)
68#define	USBPF_STATUS_CONTROL_HDR	(1 << 8)
69#define	USBPF_STATUS_CONTROL_ACT	(1 << 9)
70#define	USBPF_STATUS_CONTROL_STALL	(1 << 10)
71#define	USBPF_STATUS_SHORT_FRAMES_OK	(1 << 11)
72#define	USBPF_STATUS_SHORT_XFER_OK	(1 << 12)
73#define	USBPF_STATUS_BDMA_ENABLE	(1 << 13)
74#define	USBPF_STATUS_BDMA_NO_POST_SYNC	(1 << 14)
75#define	USBPF_STATUS_BDMA_SETUP		(1 << 15)
76#define	USBPF_STATUS_ISOCHRONOUS_XFR	(1 << 16)
77#define	USBPF_STATUS_CURR_DMA_SET	(1 << 17)
78#define	USBPF_STATUS_CAN_CANCEL_IMMED	(1 << 18)
79#define	USBPF_STATUS_DOING_CALLBACK	(1 << 19)
80	uint32_t	up_error;	/* USB error, see USB_ERR_XXX */
81	uint32_t	up_interval;	/* For interrupt and isoc (ms) */
82	uint32_t	up_frames;	/* Number of following frames */
83	uint32_t	up_packet_size;	/* Packet size used */
84	uint32_t	up_packet_count;	/* Packet count used */
85	uint32_t	up_endpoint;	/* USB endpoint / stream ID */
86	uint8_t		up_speed;	/* USB speed, see USB_SPEED_XXX */
87	/* sizeof(struct usbpf_pkthdr) == 128 bytes */
88	uint8_t		up_reserved[83];
89};
90
91struct usbpf_framehdr {
92	/*
93	 * The frame length field excludes length of frame header and
94	 * any alignment.
95	 */
96	uint32_t length;
97#define	USBPF_FRAME_ALIGN(x)		(((x) + 3) & ~3)
98	uint32_t flags;
99#define	USBPF_FRAMEFLAG_READ		(1 << 0)
100#define	USBPF_FRAMEFLAG_DATA_FOLLOWS	(1 << 1)
101};
102
103#define	USBPF_HDR_LEN		128	/* bytes */
104#define	USBPF_FRAME_HDR_LEN	8	/* bytes */
105
106extern uint8_t usbpf_pkthdr_size_ok[
107    (sizeof(struct usbpf_pkthdr) == USBPF_HDR_LEN) ? 1 : -1];
108extern uint8_t usbpf_framehdr_size_ok[
109    (sizeof(struct usbpf_framehdr) == USBPF_FRAME_HDR_LEN) ? 1 : -1];
110
111#define	USBPF_XFERTAP_SUBMIT	0
112#define	USBPF_XFERTAP_DONE	1
113
114#ifdef _KERNEL
115void	usbpf_attach(struct usb_bus *);
116void	usbpf_detach(struct usb_bus *);
117void	usbpf_xfertap(struct usb_xfer *, int);
118#endif
119
120#endif
121