usb_pf.h revision 330897
11556Srgrimes/*-
21556Srgrimes * SPDX-License-Identifier: BSD-3-Clause
31556Srgrimes *
41556Srgrimes * Copyright (c) 1990, 1991, 1993
51556Srgrimes *	The Regents of the University of California.  All rights reserved.
61556Srgrimes *
71556Srgrimes * This code is derived from the Stanford/CMU enet packet filter,
81556Srgrimes * (net/enet.c) distributed as part of 4.3BSD, and code contributed
91556Srgrimes * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
101556Srgrimes * Berkeley Laboratory.
111556Srgrimes *
121556Srgrimes * Redistribution and use in source and binary forms, with or without
131556Srgrimes * modification, are permitted provided that the following conditions
141556Srgrimes * are met:
151556Srgrimes * 1. Redistributions of source code must retain the above copyright
161556Srgrimes *    notice, this list of conditions and the following disclaimer.
171556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
181556Srgrimes *    notice, this list of conditions and the following disclaimer in the
191556Srgrimes *    documentation and/or other materials provided with the distribution.
201556Srgrimes * 4. Neither the name of the University nor the names of its contributors
211556Srgrimes *    may be used to endorse or promote products derived from this software
221556Srgrimes *    without specific prior written permission.
231556Srgrimes *
241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341556Srgrimes * SUCH DAMAGE.
3536152Scharnier *
3636152Scharnier * $FreeBSD: stable/11/sys/dev/usb/usb_pf.h 330897 2018-03-14 03:19:51Z eadler $
3736152Scharnier */
3836152Scharnier
3936152Scharnier#ifndef _DEV_USB_PF_H
401556Srgrimes#define	_DEV_USB_PF_H
411556Srgrimes
421556Srgrimesstruct usbpf_pkthdr {
431556Srgrimes	uint32_t	up_totlen;	/* Total length including all headers */
441556Srgrimes	uint32_t	up_busunit;	/* Host controller unit number */
451556Srgrimes	uint8_t		up_address;	/* USB device index */
461556Srgrimes	uint8_t		up_mode;	/* Mode of transfer */
471556Srgrimes#define	USBPF_MODE_HOST		0
481556Srgrimes#define	USBPF_MODE_DEVICE	1
491556Srgrimes	uint8_t		up_type;	/* points SUBMIT / DONE */
501556Srgrimes	uint8_t		up_xfertype;	/* Transfer type, see USB2.0 spec. */
511556Srgrimes	uint32_t	up_flags;	/* Transfer flags */
521556Srgrimes#define	USBPF_FLAG_FORCE_SHORT_XFER	(1 << 0)
531556Srgrimes#define	USBPF_FLAG_SHORT_XFER_OK	(1 << 1)
541556Srgrimes#define	USBPF_FLAG_SHORT_FRAMES_OK	(1 << 2)
551556Srgrimes#define	USBPF_FLAG_PIPE_BOF		(1 << 3)
561556Srgrimes#define	USBPF_FLAG_PROXY_BUFFER		(1 << 4)
571556Srgrimes#define	USBPF_FLAG_EXT_BUFFER		(1 << 5)
581556Srgrimes#define	USBPF_FLAG_MANUAL_STATUS	(1 << 6)
591556Srgrimes#define	USBPF_FLAG_NO_PIPE_OK		(1 << 7)
601556Srgrimes#define	USBPF_FLAG_STALL_PIPE		(1 << 8)
611556Srgrimes	uint32_t	up_status;	/* Transfer status */
621556Srgrimes#define	USBPF_STATUS_OPEN		(1 << 0)
631556Srgrimes#define	USBPF_STATUS_TRANSFERRING	(1 << 1)
641556Srgrimes#define	USBPF_STATUS_DID_DMA_DELAY	(1 << 2)
651556Srgrimes#define	USBPF_STATUS_DID_CLOSE		(1 << 3)
661556Srgrimes#define	USBPF_STATUS_DRAINING		(1 << 4)
671556Srgrimes#define	USBPF_STATUS_STARTED		(1 << 5)
681556Srgrimes#define	USBPF_STATUS_BW_RECLAIMED	(1 << 6)
691556Srgrimes#define	USBPF_STATUS_CONTROL_XFR	(1 << 7)
701556Srgrimes#define	USBPF_STATUS_CONTROL_HDR	(1 << 8)
711556Srgrimes#define	USBPF_STATUS_CONTROL_ACT	(1 << 9)
721556Srgrimes#define	USBPF_STATUS_CONTROL_STALL	(1 << 10)
731556Srgrimes#define	USBPF_STATUS_SHORT_FRAMES_OK	(1 << 11)
741556Srgrimes#define	USBPF_STATUS_SHORT_XFER_OK	(1 << 12)
751556Srgrimes#define	USBPF_STATUS_BDMA_ENABLE	(1 << 13)
761556Srgrimes#define	USBPF_STATUS_BDMA_NO_POST_SYNC	(1 << 14)
771556Srgrimes#define	USBPF_STATUS_BDMA_SETUP		(1 << 15)
781556Srgrimes#define	USBPF_STATUS_ISOCHRONOUS_XFR	(1 << 16)
791556Srgrimes#define	USBPF_STATUS_CURR_DMA_SET	(1 << 17)
801556Srgrimes#define	USBPF_STATUS_CAN_CANCEL_IMMED	(1 << 18)
811556Srgrimes#define	USBPF_STATUS_DOING_CALLBACK	(1 << 19)
821556Srgrimes	uint32_t	up_error;	/* USB error, see USB_ERR_XXX */
831556Srgrimes	uint32_t	up_interval;	/* For interrupt and isoc (ms) */
841556Srgrimes	uint32_t	up_frames;	/* Number of following frames */
851556Srgrimes	uint32_t	up_packet_size;	/* Packet size used */
868170Sbde	uint32_t	up_packet_count;	/* Packet count used */
878170Sbde	uint32_t	up_endpoint;	/* USB endpoint / stream ID */
888170Sbde	uint8_t		up_speed;	/* USB speed, see USB_SPEED_XXX */
898170Sbde	/* sizeof(struct usbpf_pkthdr) == 128 bytes */
908170Sbde	uint8_t		up_reserved[83];
918170Sbde};
928170Sbde
938170Sbdestruct usbpf_framehdr {
941556Srgrimes	/*
951556Srgrimes	 * The frame length field excludes length of frame header and
961556Srgrimes	 * any alignment.
971556Srgrimes	 */
981556Srgrimes	uint32_t length;
991556Srgrimes#define	USBPF_FRAME_ALIGN(x)		(((x) + 3) & ~3)
1001556Srgrimes	uint32_t flags;
1011556Srgrimes#define	USBPF_FRAMEFLAG_READ		(1 << 0)
1021556Srgrimes#define	USBPF_FRAMEFLAG_DATA_FOLLOWS	(1 << 1)
1031556Srgrimes};
1041556Srgrimes
1051556Srgrimes#define	USBPF_HDR_LEN		128	/* bytes */
1061556Srgrimes#define	USBPF_FRAME_HDR_LEN	8	/* bytes */
1071556Srgrimes
1081556Srgrimesextern uint8_t usbpf_pkthdr_size_ok[
1091556Srgrimes    (sizeof(struct usbpf_pkthdr) == USBPF_HDR_LEN) ? 1 : -1];
1101556Srgrimesextern uint8_t usbpf_framehdr_size_ok[
1111556Srgrimes    (sizeof(struct usbpf_framehdr) == USBPF_FRAME_HDR_LEN) ? 1 : -1];
1121556Srgrimes
1131556Srgrimes#define	USBPF_XFERTAP_SUBMIT	0
1141556Srgrimes#define	USBPF_XFERTAP_DONE	1
1151556Srgrimes
1161556Srgrimes#ifdef _KERNEL
1171556Srgrimesvoid	usbpf_attach(struct usb_bus *);
1181556Srgrimesvoid	usbpf_detach(struct usb_bus *);
1191556Srgrimesvoid	usbpf_xfertap(struct usb_xfer *, int);
1201556Srgrimes#endif
1211556Srgrimes
1221556Srgrimes#endif
1231556Srgrimes