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