xref: /freebsd/sys/dev/usb/controller/xhci.h (revision 33cbbf268f7d0f3daff0c2aa06836d932faf56a9)
113540260SHans Petter Selasky /* $FreeBSD$ */
213540260SHans Petter Selasky 
313540260SHans Petter Selasky /*-
4718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5718cf2ccSPedro F. Giffuni  *
6*33cbbf26SHans Petter Selasky  * Copyright (c) 2010-2022 Hans Petter Selasky
713540260SHans Petter Selasky  *
813540260SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
913540260SHans Petter Selasky  * modification, are permitted provided that the following conditions
1013540260SHans Petter Selasky  * are met:
1113540260SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
1213540260SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
1313540260SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
1413540260SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
1513540260SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
1613540260SHans Petter Selasky  *
1713540260SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1813540260SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1913540260SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2013540260SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2113540260SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2213540260SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2313540260SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2413540260SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2513540260SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2613540260SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2713540260SHans Petter Selasky  * SUCH DAMAGE.
2813540260SHans Petter Selasky  */
2913540260SHans Petter Selasky 
3013540260SHans Petter Selasky #ifndef _XHCI_H_
3113540260SHans Petter Selasky #define	_XHCI_H_
3213540260SHans Petter Selasky 
3313540260SHans Petter Selasky #define	XHCI_MAX_DEVICES	MIN(USB_MAX_DEVICES, 128)
3413540260SHans Petter Selasky #define	XHCI_MAX_ENDPOINTS	32	/* hardcoded - do not change */
35c5390e5aSHans Petter Selasky #define	XHCI_MAX_SCRATCHPADS	256	/* theoretical max is 1023 */
36e036ee6cSHans Petter Selasky #define	XHCI_MAX_EVENTS		232
3713540260SHans Petter Selasky #define	XHCI_MAX_COMMANDS	(16 * 1)
3813540260SHans Petter Selasky #define	XHCI_MAX_RSEG		1
3913540260SHans Petter Selasky #define	XHCI_MAX_TRANSFERS	4
40a5cf1aaaSHans Petter Selasky #if USB_MAX_EP_STREAMS == 8
41a5cf1aaaSHans Petter Selasky #define	XHCI_MAX_STREAMS	8
42a5cf1aaaSHans Petter Selasky #define	XHCI_MAX_STREAMS_LOG	3
43a5cf1aaaSHans Petter Selasky #elif USB_MAX_EP_STREAMS == 1
44a5cf1aaaSHans Petter Selasky #define	XHCI_MAX_STREAMS	1
45a5cf1aaaSHans Petter Selasky #define	XHCI_MAX_STREAMS_LOG	0
46a5cf1aaaSHans Petter Selasky #else
47a5cf1aaaSHans Petter Selasky #error "The USB_MAX_EP_STREAMS value is not supported."
48a5cf1aaaSHans Petter Selasky #endif
4913540260SHans Petter Selasky #define	XHCI_DEV_CTX_ADDR_ALIGN		64	/* bytes */
5013540260SHans Petter Selasky #define	XHCI_DEV_CTX_ALIGN		64	/* bytes */
5113540260SHans Petter Selasky #define	XHCI_INPUT_CTX_ALIGN		64	/* bytes */
5213540260SHans Petter Selasky #define	XHCI_SLOT_CTX_ALIGN		32	/* bytes */
5313540260SHans Petter Selasky #define	XHCI_ENDP_CTX_ALIGN		32	/* bytes */
5413540260SHans Petter Selasky #define	XHCI_STREAM_CTX_ALIGN		16	/* bytes */
5513540260SHans Petter Selasky #define	XHCI_TRANS_RING_SEG_ALIGN	16	/* bytes */
5613540260SHans Petter Selasky #define	XHCI_CMD_RING_SEG_ALIGN		64	/* bytes */
5713540260SHans Petter Selasky #define	XHCI_EVENT_RING_SEG_ALIGN	64	/* bytes */
5813540260SHans Petter Selasky #define	XHCI_SCRATCH_BUF_ARRAY_ALIGN	64	/* bytes */
5913540260SHans Petter Selasky #define	XHCI_SCRATCH_BUFFER_ALIGN	USB_PAGE_SIZE
6013540260SHans Petter Selasky #define	XHCI_TRB_ALIGN			16	/* bytes */
6113540260SHans Petter Selasky #define	XHCI_TD_ALIGN			64	/* bytes */
6213540260SHans Petter Selasky #define	XHCI_PAGE_SIZE			4096	/* bytes */
6313540260SHans Petter Selasky 
6413540260SHans Petter Selasky struct xhci_dev_ctx_addr {
6513540260SHans Petter Selasky 	volatile uint64_t	qwBaaDevCtxAddr[USB_MAX_DEVICES + 1];
6613540260SHans Petter Selasky 	struct {
6713540260SHans Petter Selasky 		volatile uint64_t dummy;
6813540260SHans Petter Selasky 	} __aligned(64) padding;
6913540260SHans Petter Selasky 	volatile uint64_t	qwSpBufPtr[XHCI_MAX_SCRATCHPADS];
7013540260SHans Petter Selasky };
7113540260SHans Petter Selasky 
7213540260SHans Petter Selasky #define	XHCI_EPNO2EPID(x) \
7313540260SHans Petter Selasky     ((((x) & UE_DIR_IN) ? 1 : 0) | (2 * ((x) & UE_ADDR)))
7413540260SHans Petter Selasky 
7513540260SHans Petter Selasky struct xhci_slot_ctx {
7613540260SHans Petter Selasky 	volatile uint32_t	dwSctx0;
7713540260SHans Petter Selasky #define	XHCI_SCTX_0_ROUTE_SET(x)		((x) & 0xFFFFF)
7813540260SHans Petter Selasky #define	XHCI_SCTX_0_ROUTE_GET(x)		((x) & 0xFFFFF)
7913540260SHans Petter Selasky #define	XHCI_SCTX_0_SPEED_SET(x)		(((x) & 0xF) << 20)
8013540260SHans Petter Selasky #define	XHCI_SCTX_0_SPEED_GET(x)		(((x) >> 20) & 0xF)
8113540260SHans Petter Selasky #define	XHCI_SCTX_0_MTT_SET(x)			(((x) & 0x1) << 25)
8213540260SHans Petter Selasky #define	XHCI_SCTX_0_MTT_GET(x)			(((x) >> 25) & 0x1)
8313540260SHans Petter Selasky #define	XHCI_SCTX_0_HUB_SET(x)			(((x) & 0x1) << 26)
8413540260SHans Petter Selasky #define	XHCI_SCTX_0_HUB_GET(x)			(((x) >> 26) & 0x1)
8513540260SHans Petter Selasky #define	XHCI_SCTX_0_CTX_NUM_SET(x)		(((x) & 0x1F) << 27)
8613540260SHans Petter Selasky #define	XHCI_SCTX_0_CTX_NUM_GET(x)		(((x) >> 27) & 0x1F)
8713540260SHans Petter Selasky 	volatile uint32_t	dwSctx1;
8813540260SHans Petter Selasky #define	XHCI_SCTX_1_MAX_EL_SET(x)		((x) & 0xFFFF)
8913540260SHans Petter Selasky #define	XHCI_SCTX_1_MAX_EL_GET(x)		((x) & 0xFFFF)
9013540260SHans Petter Selasky #define	XHCI_SCTX_1_RH_PORT_SET(x)		(((x) & 0xFF) << 16)
9113540260SHans Petter Selasky #define	XHCI_SCTX_1_RH_PORT_GET(x)		(((x) >> 16) & 0xFF)
9213540260SHans Petter Selasky #define	XHCI_SCTX_1_NUM_PORTS_SET(x)		(((x) & 0xFF) << 24)
9313540260SHans Petter Selasky #define	XHCI_SCTX_1_NUM_PORTS_GET(x)		(((x) >> 24) & 0xFF)
9413540260SHans Petter Selasky 	volatile uint32_t	dwSctx2;
9513540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_HUB_SID_SET(x)		((x) & 0xFF)
9613540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_HUB_SID_GET(x)		((x) & 0xFF)
9713540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_PORT_NUM_SET(x)		(((x) & 0xFF) << 8)
9813540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_PORT_NUM_GET(x)		(((x) >> 8) & 0xFF)
9913540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_THINK_TIME_SET(x)	(((x) & 0x3) << 16)
10013540260SHans Petter Selasky #define	XHCI_SCTX_2_TT_THINK_TIME_GET(x)	(((x) >> 16) & 0x3)
10113540260SHans Petter Selasky #define	XHCI_SCTX_2_IRQ_TARGET_SET(x)		(((x) & 0x3FF) << 22)
10213540260SHans Petter Selasky #define	XHCI_SCTX_2_IRQ_TARGET_GET(x)		(((x) >> 22) & 0x3FF)
10313540260SHans Petter Selasky 	volatile uint32_t	dwSctx3;
10413540260SHans Petter Selasky #define	XHCI_SCTX_3_DEV_ADDR_SET(x)		((x) & 0xFF)
10513540260SHans Petter Selasky #define	XHCI_SCTX_3_DEV_ADDR_GET(x)		((x) & 0xFF)
10613540260SHans Petter Selasky #define	XHCI_SCTX_3_SLOT_STATE_SET(x)		(((x) & 0x1F) << 27)
10713540260SHans Petter Selasky #define	XHCI_SCTX_3_SLOT_STATE_GET(x)		(((x) >> 27) & 0x1F)
10813540260SHans Petter Selasky 	volatile uint32_t	dwSctx4;
10913540260SHans Petter Selasky 	volatile uint32_t	dwSctx5;
11013540260SHans Petter Selasky 	volatile uint32_t	dwSctx6;
11113540260SHans Petter Selasky 	volatile uint32_t	dwSctx7;
11213540260SHans Petter Selasky };
11313540260SHans Petter Selasky 
11429863d1eSJessica Clarke struct xhci_slot_ctx64 {
11529863d1eSJessica Clarke 	struct xhci_slot_ctx	ctx;
11629863d1eSJessica Clarke 	volatile uint8_t	padding[32];
11729863d1eSJessica Clarke };
11829863d1eSJessica Clarke 
11913540260SHans Petter Selasky struct xhci_endp_ctx {
12013540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx0;
12113540260SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_SET(x)		((x) & 0x7)
12213540260SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_GET(x)		((x) & 0x7)
123b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_DISABLED		0
124b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_RUNNING		1
125b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_HALTED		2
126b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_STOPPED		3
127b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_ERROR		4
128b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_RESERVED_5		5
129b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_RESERVED_6		6
130b8ffd2d5SHans Petter Selasky #define	XHCI_EPCTX_0_EPSTATE_RESERVED_7		7
13113540260SHans Petter Selasky #define	XHCI_EPCTX_0_MULT_SET(x)		(((x) & 0x3) << 8)
13213540260SHans Petter Selasky #define	XHCI_EPCTX_0_MULT_GET(x)		(((x) >> 8) & 0x3)
13313540260SHans Petter Selasky #define	XHCI_EPCTX_0_MAXP_STREAMS_SET(x)	(((x) & 0x1F) << 10)
13413540260SHans Petter Selasky #define	XHCI_EPCTX_0_MAXP_STREAMS_GET(x)	(((x) >> 10) & 0x1F)
13513540260SHans Petter Selasky #define	XHCI_EPCTX_0_LSA_SET(x)			(((x) & 0x1) << 15)
13613540260SHans Petter Selasky #define	XHCI_EPCTX_0_LSA_GET(x)			(((x) >> 15) & 0x1)
13713540260SHans Petter Selasky #define	XHCI_EPCTX_0_IVAL_SET(x)		(((x) & 0xFF) << 16)
13813540260SHans Petter Selasky #define	XHCI_EPCTX_0_IVAL_GET(x)		(((x) >> 16) & 0xFF)
13913540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx1;
14013540260SHans Petter Selasky #define	XHCI_EPCTX_1_CERR_SET(x)		(((x) & 0x3) << 1)
14113540260SHans Petter Selasky #define	XHCI_EPCTX_1_CERR_GET(x)		(((x) >> 1) & 0x3)
14213540260SHans Petter Selasky #define	XHCI_EPCTX_1_EPTYPE_SET(x)		(((x) & 0x7) << 3)
14313540260SHans Petter Selasky #define	XHCI_EPCTX_1_EPTYPE_GET(x)		(((x) >> 3) & 0x7)
14413540260SHans Petter Selasky #define	XHCI_EPCTX_1_HID_SET(x)			(((x) & 0x1) << 7)
14513540260SHans Petter Selasky #define	XHCI_EPCTX_1_HID_GET(x)			(((x) >> 7) & 0x1)
14613540260SHans Petter Selasky #define	XHCI_EPCTX_1_MAXB_SET(x)		(((x) & 0xFF) << 8)
14713540260SHans Petter Selasky #define	XHCI_EPCTX_1_MAXB_GET(x)		(((x) >> 8) & 0xFF)
14813540260SHans Petter Selasky #define	XHCI_EPCTX_1_MAXP_SIZE_SET(x)		(((x) & 0xFFFF) << 16)
14913540260SHans Petter Selasky #define	XHCI_EPCTX_1_MAXP_SIZE_GET(x)		(((x) >> 16) & 0xFFFF)
15013540260SHans Petter Selasky 	volatile uint64_t	qwEpCtx2;
15113540260SHans Petter Selasky #define	XHCI_EPCTX_2_DCS_SET(x)			((x) & 0x1)
15213540260SHans Petter Selasky #define	XHCI_EPCTX_2_DCS_GET(x)			((x) & 0x1)
15313540260SHans Petter Selasky #define	XHCI_EPCTX_2_TR_DQ_PTR_MASK		0xFFFFFFFFFFFFFFF0U
15413540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx4;
15513540260SHans Petter Selasky #define	XHCI_EPCTX_4_AVG_TRB_LEN_SET(x)		((x) & 0xFFFF)
15613540260SHans Petter Selasky #define	XHCI_EPCTX_4_AVG_TRB_LEN_GET(x)		((x) & 0xFFFF)
15713540260SHans Petter Selasky #define	XHCI_EPCTX_4_MAX_ESIT_PAYLOAD_SET(x)	(((x) & 0xFFFF) << 16)
15813540260SHans Petter Selasky #define	XHCI_EPCTX_4_MAX_ESIT_PAYLOAD_GET(x)	(((x) >> 16) & 0xFFFF)
15913540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx5;
16013540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx6;
16113540260SHans Petter Selasky 	volatile uint32_t	dwEpCtx7;
16213540260SHans Petter Selasky };
16313540260SHans Petter Selasky 
16429863d1eSJessica Clarke struct xhci_endp_ctx64 {
16529863d1eSJessica Clarke 	struct xhci_endp_ctx	ctx;
16629863d1eSJessica Clarke 	volatile uint8_t	padding[32];
16729863d1eSJessica Clarke };
16829863d1eSJessica Clarke 
16913540260SHans Petter Selasky struct xhci_input_ctx {
17013540260SHans Petter Selasky #define	XHCI_INCTX_NON_CTRL_MASK	0xFFFFFFFCU
17113540260SHans Petter Selasky 	volatile uint32_t	dwInCtx0;
17213540260SHans Petter Selasky #define	XHCI_INCTX_0_DROP_MASK(n)	(1U << (n))
17313540260SHans Petter Selasky 	volatile uint32_t	dwInCtx1;
17413540260SHans Petter Selasky #define	XHCI_INCTX_1_ADD_MASK(n)	(1U << (n))
17513540260SHans Petter Selasky 	volatile uint32_t	dwInCtx2;
17613540260SHans Petter Selasky 	volatile uint32_t	dwInCtx3;
17713540260SHans Petter Selasky 	volatile uint32_t	dwInCtx4;
17813540260SHans Petter Selasky 	volatile uint32_t	dwInCtx5;
17913540260SHans Petter Selasky 	volatile uint32_t	dwInCtx6;
18013540260SHans Petter Selasky 	volatile uint32_t	dwInCtx7;
18113540260SHans Petter Selasky };
18213540260SHans Petter Selasky 
18329863d1eSJessica Clarke struct xhci_input_ctx64 {
18429863d1eSJessica Clarke 	struct xhci_input_ctx	ctx;
18529863d1eSJessica Clarke 	volatile uint8_t	padding[32];
18629863d1eSJessica Clarke };
18729863d1eSJessica Clarke 
18813540260SHans Petter Selasky struct xhci_input_dev_ctx {
18913540260SHans Petter Selasky 	struct xhci_input_ctx	ctx_input;
19013540260SHans Petter Selasky 	struct xhci_slot_ctx	ctx_slot;
19113540260SHans Petter Selasky 	struct xhci_endp_ctx	ctx_ep[XHCI_MAX_ENDPOINTS - 1];
19213540260SHans Petter Selasky };
19313540260SHans Petter Selasky 
19429863d1eSJessica Clarke struct xhci_input_dev_ctx64 {
19529863d1eSJessica Clarke 	struct xhci_input_ctx64	ctx_input;
19629863d1eSJessica Clarke 	struct xhci_slot_ctx64	ctx_slot;
19729863d1eSJessica Clarke 	struct xhci_endp_ctx64	ctx_ep[XHCI_MAX_ENDPOINTS - 1];
19829863d1eSJessica Clarke };
19929863d1eSJessica Clarke 
20013540260SHans Petter Selasky struct xhci_dev_ctx {
20113540260SHans Petter Selasky 	struct xhci_slot_ctx	ctx_slot;
20213540260SHans Petter Selasky 	struct xhci_endp_ctx	ctx_ep[XHCI_MAX_ENDPOINTS - 1];
20313540260SHans Petter Selasky } __aligned(XHCI_DEV_CTX_ALIGN);
20413540260SHans Petter Selasky 
20529863d1eSJessica Clarke struct xhci_dev_ctx64 {
20629863d1eSJessica Clarke 	struct xhci_slot_ctx64	ctx_slot;
20729863d1eSJessica Clarke 	struct xhci_endp_ctx64	ctx_ep[XHCI_MAX_ENDPOINTS - 1];
20829863d1eSJessica Clarke } __aligned(XHCI_DEV_CTX_ALIGN);
20929863d1eSJessica Clarke 
21013540260SHans Petter Selasky struct xhci_stream_ctx {
21113540260SHans Petter Selasky 	volatile uint64_t	qwSctx0;
21213540260SHans Petter Selasky #define	XHCI_SCTX_0_DCS_GET(x)		((x) & 0x1)
21313540260SHans Petter Selasky #define	XHCI_SCTX_0_DCS_SET(x)		((x) & 0x1)
21413540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_SET(x)		(((x) & 0x7) << 1)
21513540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_GET(x)		(((x) >> 1) & 0x7)
21613540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_SEC_TR_RING	0x0
21713540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_TR_RING	0x1
21813540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_8	0x2
21913540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_16	0x3
22013540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_32	0x4
22113540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_64	0x5
22213540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_128	0x6
22313540260SHans Petter Selasky #define	XHCI_SCTX_0_SCT_PRIM_SSA_256	0x7
22413540260SHans Petter Selasky #define	XHCI_SCTX_0_TR_DQ_PTR_MASK	0xFFFFFFFFFFFFFFF0U
22513540260SHans Petter Selasky 	volatile uint32_t	dwSctx2;
22613540260SHans Petter Selasky 	volatile uint32_t	dwSctx3;
22713540260SHans Petter Selasky };
22813540260SHans Petter Selasky 
22913540260SHans Petter Selasky struct xhci_trb {
23013540260SHans Petter Selasky 	volatile uint64_t	qwTrb0;
231c4a1e93fSHans Petter Selasky #define	XHCI_TRB_0_DIR_IN_MASK		(0x80ULL << 0)
23213540260SHans Petter Selasky #define	XHCI_TRB_0_WLENGTH_MASK		(0xFFFFULL << 48)
23313540260SHans Petter Selasky 	volatile uint32_t	dwTrb2;
23413540260SHans Petter Selasky #define	XHCI_TRB_2_ERROR_GET(x)		(((x) >> 24) & 0xFF)
23513540260SHans Petter Selasky #define	XHCI_TRB_2_ERROR_SET(x)		(((x) & 0xFF) << 24)
23613540260SHans Petter Selasky #define	XHCI_TRB_2_TDSZ_GET(x)		(((x) >> 17) & 0x1F)
23713540260SHans Petter Selasky #define	XHCI_TRB_2_TDSZ_SET(x)		(((x) & 0x1F) << 17)
23813540260SHans Petter Selasky #define	XHCI_TRB_2_REM_GET(x)		((x) & 0xFFFFFF)
23913540260SHans Petter Selasky #define	XHCI_TRB_2_REM_SET(x)		((x) & 0xFFFFFF)
24013540260SHans Petter Selasky #define	XHCI_TRB_2_BYTES_GET(x)		((x) & 0x1FFFF)
24113540260SHans Petter Selasky #define	XHCI_TRB_2_BYTES_SET(x)		((x) & 0x1FFFF)
24213540260SHans Petter Selasky #define	XHCI_TRB_2_IRQ_GET(x)		(((x) >> 22) & 0x3FF)
24313540260SHans Petter Selasky #define	XHCI_TRB_2_IRQ_SET(x)		(((x) & 0x3FF) << 22)
24413540260SHans Petter Selasky #define	XHCI_TRB_2_STREAM_GET(x)	(((x) >> 16) & 0xFFFF)
24513540260SHans Petter Selasky #define	XHCI_TRB_2_STREAM_SET(x)	(((x) & 0xFFFF) << 16)
24613540260SHans Petter Selasky 
24713540260SHans Petter Selasky 	volatile uint32_t	dwTrb3;
24813540260SHans Petter Selasky #define	XHCI_TRB_3_TYPE_GET(x)		(((x) >> 10) & 0x3F)
24913540260SHans Petter Selasky #define	XHCI_TRB_3_TYPE_SET(x)		(((x) & 0x3F) << 10)
25013540260SHans Petter Selasky #define	XHCI_TRB_3_CYCLE_BIT		(1U << 0)
25113540260SHans Petter Selasky #define	XHCI_TRB_3_TC_BIT		(1U << 1)	/* command ring only */
25213540260SHans Petter Selasky #define	XHCI_TRB_3_ENT_BIT		(1U << 1)	/* transfer ring only */
25313540260SHans Petter Selasky #define	XHCI_TRB_3_ISP_BIT		(1U << 2)
25413540260SHans Petter Selasky #define	XHCI_TRB_3_NSNOOP_BIT		(1U << 3)
25513540260SHans Petter Selasky #define	XHCI_TRB_3_CHAIN_BIT		(1U << 4)
25613540260SHans Petter Selasky #define	XHCI_TRB_3_IOC_BIT		(1U << 5)
25713540260SHans Petter Selasky #define	XHCI_TRB_3_IDT_BIT		(1U << 6)
25813540260SHans Petter Selasky #define	XHCI_TRB_3_TBC_GET(x)		(((x) >> 7) & 3)
25913540260SHans Petter Selasky #define	XHCI_TRB_3_TBC_SET(x)		(((x) & 3) << 7)
26013540260SHans Petter Selasky #define	XHCI_TRB_3_BEI_BIT		(1U << 9)
26113540260SHans Petter Selasky #define	XHCI_TRB_3_DCEP_BIT		(1U << 9)
26213540260SHans Petter Selasky #define	XHCI_TRB_3_PRSV_BIT		(1U << 9)
26313540260SHans Petter Selasky #define	XHCI_TRB_3_BSR_BIT		(1U << 9)
26413540260SHans Petter Selasky #define	XHCI_TRB_3_TRT_MASK		(3U << 16)
26513540260SHans Petter Selasky #define	XHCI_TRB_3_TRT_NONE		(0U << 16)
26613540260SHans Petter Selasky #define	XHCI_TRB_3_TRT_OUT		(2U << 16)
26713540260SHans Petter Selasky #define	XHCI_TRB_3_TRT_IN		(3U << 16)
26813540260SHans Petter Selasky #define	XHCI_TRB_3_DIR_IN		(1U << 16)
26913540260SHans Petter Selasky #define	XHCI_TRB_3_TLBPC_GET(x)		(((x) >> 16) & 0xF)
27013540260SHans Petter Selasky #define	XHCI_TRB_3_TLBPC_SET(x)		(((x) & 0xF) << 16)
27113540260SHans Petter Selasky #define	XHCI_TRB_3_EP_GET(x)		(((x) >> 16) & 0x1F)
27213540260SHans Petter Selasky #define	XHCI_TRB_3_EP_SET(x)		(((x) & 0x1F) << 16)
27313540260SHans Petter Selasky #define	XHCI_TRB_3_FRID_GET(x)		(((x) >> 20) & 0x7FF)
27413540260SHans Petter Selasky #define	XHCI_TRB_3_FRID_SET(x)		(((x) & 0x7FF) << 20)
27513540260SHans Petter Selasky #define	XHCI_TRB_3_ISO_SIA_BIT		(1U << 31)
27613540260SHans Petter Selasky #define	XHCI_TRB_3_SUSP_EP_BIT		(1U << 23)
27713540260SHans Petter Selasky #define	XHCI_TRB_3_SLOT_GET(x)		(((x) >> 24) & 0xFF)
27813540260SHans Petter Selasky #define	XHCI_TRB_3_SLOT_SET(x)		(((x) & 0xFF) << 24)
27913540260SHans Petter Selasky 
28013540260SHans Petter Selasky /* Commands */
28113540260SHans Petter Selasky #define	XHCI_TRB_TYPE_RESERVED		0x00
28213540260SHans Petter Selasky #define	XHCI_TRB_TYPE_NORMAL		0x01
28313540260SHans Petter Selasky #define	XHCI_TRB_TYPE_SETUP_STAGE	0x02
28413540260SHans Petter Selasky #define	XHCI_TRB_TYPE_DATA_STAGE	0x03
28513540260SHans Petter Selasky #define	XHCI_TRB_TYPE_STATUS_STAGE	0x04
28613540260SHans Petter Selasky #define	XHCI_TRB_TYPE_ISOCH		0x05
28713540260SHans Petter Selasky #define	XHCI_TRB_TYPE_LINK		0x06
28813540260SHans Petter Selasky #define	XHCI_TRB_TYPE_EVENT_DATA	0x07
28913540260SHans Petter Selasky #define	XHCI_TRB_TYPE_NOOP		0x08
29013540260SHans Petter Selasky #define	XHCI_TRB_TYPE_ENABLE_SLOT	0x09
29113540260SHans Petter Selasky #define	XHCI_TRB_TYPE_DISABLE_SLOT	0x0A
29213540260SHans Petter Selasky #define	XHCI_TRB_TYPE_ADDRESS_DEVICE	0x0B
29313540260SHans Petter Selasky #define	XHCI_TRB_TYPE_CONFIGURE_EP	0x0C
29413540260SHans Petter Selasky #define	XHCI_TRB_TYPE_EVALUATE_CTX	0x0D
29513540260SHans Petter Selasky #define	XHCI_TRB_TYPE_RESET_EP		0x0E
29613540260SHans Petter Selasky #define	XHCI_TRB_TYPE_STOP_EP		0x0F
29713540260SHans Petter Selasky #define	XHCI_TRB_TYPE_SET_TR_DEQUEUE	0x10
29813540260SHans Petter Selasky #define	XHCI_TRB_TYPE_RESET_DEVICE	0x11
29913540260SHans Petter Selasky #define	XHCI_TRB_TYPE_FORCE_EVENT	0x12
30013540260SHans Petter Selasky #define	XHCI_TRB_TYPE_NEGOTIATE_BW	0x13
30113540260SHans Petter Selasky #define	XHCI_TRB_TYPE_SET_LATENCY_TOL  	0x14
30213540260SHans Petter Selasky #define	XHCI_TRB_TYPE_GET_PORT_BW	0x15
30313540260SHans Petter Selasky #define	XHCI_TRB_TYPE_FORCE_HEADER	0x16
30413540260SHans Petter Selasky #define	XHCI_TRB_TYPE_NOOP_CMD		0x17
30513540260SHans Petter Selasky 
30613540260SHans Petter Selasky /* Events */
30713540260SHans Petter Selasky #define	XHCI_TRB_EVENT_TRANSFER		0x20
30813540260SHans Petter Selasky #define	XHCI_TRB_EVENT_CMD_COMPLETE	0x21
30913540260SHans Petter Selasky #define	XHCI_TRB_EVENT_PORT_STS_CHANGE  0x22
31013540260SHans Petter Selasky #define	XHCI_TRB_EVENT_BW_REQUEST      	0x23
31113540260SHans Petter Selasky #define	XHCI_TRB_EVENT_DOORBELL		0x24
31213540260SHans Petter Selasky #define	XHCI_TRB_EVENT_HOST_CTRL	0x25
31313540260SHans Petter Selasky #define	XHCI_TRB_EVENT_DEVICE_NOTIFY	0x26
31413540260SHans Petter Selasky #define	XHCI_TRB_EVENT_MFINDEX_WRAP	0x27
31513540260SHans Petter Selasky 
31613540260SHans Petter Selasky /* Error codes */
31713540260SHans Petter Selasky #define	XHCI_TRB_ERROR_INVALID		0x00
31813540260SHans Petter Selasky #define	XHCI_TRB_ERROR_SUCCESS		0x01
31913540260SHans Petter Selasky #define	XHCI_TRB_ERROR_DATA_BUF		0x02
32013540260SHans Petter Selasky #define	XHCI_TRB_ERROR_BABBLE		0x03
32113540260SHans Petter Selasky #define	XHCI_TRB_ERROR_XACT		0x04
32213540260SHans Petter Selasky #define	XHCI_TRB_ERROR_TRB		0x05
32313540260SHans Petter Selasky #define	XHCI_TRB_ERROR_STALL		0x06
32413540260SHans Petter Selasky #define	XHCI_TRB_ERROR_RESOURCE		0x07
32513540260SHans Petter Selasky #define	XHCI_TRB_ERROR_BANDWIDTH	0x08
32613540260SHans Petter Selasky #define	XHCI_TRB_ERROR_NO_SLOTS		0x09
32713540260SHans Petter Selasky #define	XHCI_TRB_ERROR_STREAM_TYPE	0x0A
32813540260SHans Petter Selasky #define	XHCI_TRB_ERROR_SLOT_NOT_ON	0x0B
32913540260SHans Petter Selasky #define	XHCI_TRB_ERROR_ENDP_NOT_ON	0x0C
33013540260SHans Petter Selasky #define	XHCI_TRB_ERROR_SHORT_PKT	0x0D
33113540260SHans Petter Selasky #define	XHCI_TRB_ERROR_RING_UNDERRUN	0x0E
33213540260SHans Petter Selasky #define	XHCI_TRB_ERROR_RING_OVERRUN	0x0F
33313540260SHans Petter Selasky #define	XHCI_TRB_ERROR_VF_RING_FULL	0x10
33413540260SHans Petter Selasky #define	XHCI_TRB_ERROR_PARAMETER	0x11
33513540260SHans Petter Selasky #define	XHCI_TRB_ERROR_BW_OVERRUN	0x12
33613540260SHans Petter Selasky #define	XHCI_TRB_ERROR_CONTEXT_STATE	0x13
33713540260SHans Petter Selasky #define	XHCI_TRB_ERROR_NO_PING_RESP	0x14
33813540260SHans Petter Selasky #define	XHCI_TRB_ERROR_EV_RING_FULL	0x15
33913540260SHans Petter Selasky #define	XHCI_TRB_ERROR_INCOMPAT_DEV	0x16
34013540260SHans Petter Selasky #define	XHCI_TRB_ERROR_MISSED_SERVICE	0x17
34113540260SHans Petter Selasky #define	XHCI_TRB_ERROR_CMD_RING_STOP	0x18
34213540260SHans Petter Selasky #define	XHCI_TRB_ERROR_CMD_ABORTED	0x19
34313540260SHans Petter Selasky #define	XHCI_TRB_ERROR_STOPPED		0x1A
34413540260SHans Petter Selasky #define	XHCI_TRB_ERROR_LENGTH		0x1B
34513540260SHans Petter Selasky #define	XHCI_TRB_ERROR_BAD_MELAT	0x1D
34613540260SHans Petter Selasky #define	XHCI_TRB_ERROR_ISOC_OVERRUN	0x1F
34713540260SHans Petter Selasky #define	XHCI_TRB_ERROR_EVENT_LOST	0x20
34813540260SHans Petter Selasky #define	XHCI_TRB_ERROR_UNDEFINED	0x21
34913540260SHans Petter Selasky #define	XHCI_TRB_ERROR_INVALID_SID	0x22
35013540260SHans Petter Selasky #define	XHCI_TRB_ERROR_SEC_BW		0x23
35113540260SHans Petter Selasky #define	XHCI_TRB_ERROR_SPLIT_XACT	0x24
35213540260SHans Petter Selasky } __aligned(4);
35313540260SHans Petter Selasky 
35413540260SHans Petter Selasky struct xhci_dev_endpoint_trbs {
35507222474SHans Petter Selasky 	struct xhci_trb		trb[(XHCI_MAX_STREAMS *
35607222474SHans Petter Selasky 	    XHCI_MAX_TRANSFERS) + XHCI_MAX_STREAMS];
35713540260SHans Petter Selasky };
35813540260SHans Petter Selasky 
359454035baSHans Petter Selasky #if (USB_PAGE_SIZE < 4096)
360f8808726SHans Petter Selasky #error "The XHCI driver needs a pagesize above or equal to 4K"
361454035baSHans Petter Selasky #endif
362454035baSHans Petter Selasky 
363454035baSHans Petter Selasky /* Define the maximum payload which we will handle in a single TRB */
364454035baSHans Petter Selasky #define	XHCI_TD_PAYLOAD_MAX	65536	/* bytes */
365454035baSHans Petter Selasky 
366454035baSHans Petter Selasky /* Define the maximum payload of a single scatter-gather list element */
367454035baSHans Petter Selasky #define	XHCI_TD_PAGE_SIZE \
368454035baSHans Petter Selasky   ((USB_PAGE_SIZE < XHCI_TD_PAYLOAD_MAX) ? USB_PAGE_SIZE : XHCI_TD_PAYLOAD_MAX)
369454035baSHans Petter Selasky 
370454035baSHans Petter Selasky /* Define the maximum length of the scatter-gather list */
371454035baSHans Petter Selasky #define	XHCI_TD_PAGE_NBUF \
372454035baSHans Petter Selasky   (((XHCI_TD_PAYLOAD_MAX + XHCI_TD_PAGE_SIZE - 1) / XHCI_TD_PAGE_SIZE) + 1)
37313540260SHans Petter Selasky 
37413540260SHans Petter Selasky struct xhci_td {
375454035baSHans Petter Selasky 	/* one LINK TRB has been added to the TRB array */
37613540260SHans Petter Selasky 	struct xhci_trb		td_trb[XHCI_TD_PAGE_NBUF + 1];
37713540260SHans Petter Selasky 
37813540260SHans Petter Selasky /*
37913540260SHans Petter Selasky  * Extra information needed:
38013540260SHans Petter Selasky  */
38113540260SHans Petter Selasky 	uint64_t		td_self;
38213540260SHans Petter Selasky 	struct xhci_td		*next;
38313540260SHans Petter Selasky 	struct xhci_td		*alt_next;
38413540260SHans Petter Selasky 	struct xhci_td		*obj_next;
38513540260SHans Petter Selasky 	struct usb_page_cache	*page_cache;
38613540260SHans Petter Selasky 	uint32_t		len;
38713540260SHans Petter Selasky 	uint32_t		remainder;
38813540260SHans Petter Selasky 	uint8_t			ntrb;
38913540260SHans Petter Selasky 	uint8_t			status;
39013540260SHans Petter Selasky } __aligned(XHCI_TRB_ALIGN);
39113540260SHans Petter Selasky 
39213540260SHans Petter Selasky struct xhci_command {
39313540260SHans Petter Selasky 	struct xhci_trb		trb;
39413540260SHans Petter Selasky 	TAILQ_ENTRY(xhci_command) entry;
39513540260SHans Petter Selasky };
39613540260SHans Petter Selasky 
39713540260SHans Petter Selasky struct xhci_event_ring_seg {
39813540260SHans Petter Selasky 	volatile uint64_t	qwEvrsTablePtr;
39913540260SHans Petter Selasky 	volatile uint32_t	dwEvrsTableSize;
40013540260SHans Petter Selasky 	volatile uint32_t	dwEvrsReserved;
40113540260SHans Petter Selasky };
40213540260SHans Petter Selasky 
40313540260SHans Petter Selasky struct xhci_hw_root {
40413540260SHans Petter Selasky 	struct xhci_event_ring_seg	hwr_ring_seg[XHCI_MAX_RSEG];
40513540260SHans Petter Selasky 	struct {
40613540260SHans Petter Selasky 		volatile uint64_t dummy;
40713540260SHans Petter Selasky 	} __aligned(64)			padding;
40813540260SHans Petter Selasky 	struct xhci_trb			hwr_events[XHCI_MAX_EVENTS];
40913540260SHans Petter Selasky 	struct xhci_trb			hwr_commands[XHCI_MAX_COMMANDS];
41013540260SHans Petter Selasky };
41113540260SHans Petter Selasky 
412e036ee6cSHans Petter Selasky CTASSERT(sizeof(struct xhci_hw_root) == XHCI_PAGE_SIZE);
413e036ee6cSHans Petter Selasky 
41413540260SHans Petter Selasky struct xhci_endpoint_ext {
41513540260SHans Petter Selasky 	struct xhci_trb		*trb;
416a5cf1aaaSHans Petter Selasky 	struct usb_xfer		*xfer[XHCI_MAX_TRANSFERS * XHCI_MAX_STREAMS];
41713540260SHans Petter Selasky 	struct usb_page_cache	*page_cache;
41813540260SHans Petter Selasky 	uint64_t		physaddr;
419a5cf1aaaSHans Petter Selasky 	uint8_t			trb_used[XHCI_MAX_STREAMS];
420a5cf1aaaSHans Petter Selasky 	uint8_t			trb_index[XHCI_MAX_STREAMS];
42113540260SHans Petter Selasky 	uint8_t			trb_halted;
42213540260SHans Petter Selasky 	uint8_t			trb_running;
423cfa00b0dSHans Petter Selasky 	uint8_t			trb_ep_mode;
42459ca674eSHans Petter Selasky 	uint8_t			trb_ep_maxp;
42513540260SHans Petter Selasky };
42613540260SHans Petter Selasky 
42713540260SHans Petter Selasky enum {
42813540260SHans Petter Selasky 	XHCI_ST_DISABLED,
42913540260SHans Petter Selasky 	XHCI_ST_ENABLED,
43013540260SHans Petter Selasky 	XHCI_ST_DEFAULT,
43113540260SHans Petter Selasky 	XHCI_ST_ADDRESSED,
43213540260SHans Petter Selasky 	XHCI_ST_CONFIGURED,
43313540260SHans Petter Selasky 	XHCI_ST_MAX
43413540260SHans Petter Selasky };
43513540260SHans Petter Selasky 
43613540260SHans Petter Selasky struct xhci_hw_dev {
43713540260SHans Petter Selasky 	struct usb_page_cache	device_pc;
43813540260SHans Petter Selasky 	struct usb_page_cache	input_pc;
43907222474SHans Petter Selasky 	struct usb_page_cache	endpoint_pc[XHCI_MAX_ENDPOINTS];
44013540260SHans Petter Selasky 
44113540260SHans Petter Selasky 	struct usb_page		device_pg;
44213540260SHans Petter Selasky 	struct usb_page		input_pg;
44307222474SHans Petter Selasky 	struct usb_page		endpoint_pg[XHCI_MAX_ENDPOINTS];
44413540260SHans Petter Selasky 
44513540260SHans Petter Selasky 	struct xhci_endpoint_ext endp[XHCI_MAX_ENDPOINTS];
44613540260SHans Petter Selasky 
4477ba6c62fSHans Petter Selasky 	uint32_t		ep_configured;
4487ba6c62fSHans Petter Selasky 
44913540260SHans Petter Selasky 	uint8_t			state;
45013540260SHans Petter Selasky 	uint8_t			nports;
45113540260SHans Petter Selasky 	uint8_t			tt;
4525e184962SHans Petter Selasky 	uint8_t			context_num;
45313540260SHans Petter Selasky };
45413540260SHans Petter Selasky 
45513540260SHans Petter Selasky struct xhci_hw_softc {
45613540260SHans Petter Selasky 	struct usb_page_cache	root_pc;
45713540260SHans Petter Selasky 	struct usb_page_cache	ctx_pc;
45813540260SHans Petter Selasky 	struct usb_page_cache	scratch_pc[XHCI_MAX_SCRATCHPADS];
45913540260SHans Petter Selasky 
46013540260SHans Petter Selasky 	struct usb_page		root_pg;
46113540260SHans Petter Selasky 	struct usb_page		ctx_pg;
46213540260SHans Petter Selasky 	struct usb_page		scratch_pg[XHCI_MAX_SCRATCHPADS];
46313540260SHans Petter Selasky 
46413540260SHans Petter Selasky 	struct xhci_hw_dev	devs[XHCI_MAX_DEVICES + 1];
46513540260SHans Petter Selasky };
46613540260SHans Petter Selasky 
46713540260SHans Petter Selasky struct xhci_config_desc {
46813540260SHans Petter Selasky 	struct usb_config_descriptor		confd;
46913540260SHans Petter Selasky 	struct usb_interface_descriptor		ifcd;
47013540260SHans Petter Selasky 	struct usb_endpoint_descriptor		endpd;
47113540260SHans Petter Selasky 	struct usb_endpoint_ss_comp_descriptor	endpcd;
47213540260SHans Petter Selasky } __packed;
47313540260SHans Petter Selasky 
47413540260SHans Petter Selasky struct xhci_bos_desc {
47513540260SHans Petter Selasky 	struct usb_bos_descriptor		bosd;
47613540260SHans Petter Selasky 	struct usb_devcap_usb2ext_descriptor	usb2extd;
47713540260SHans Petter Selasky 	struct usb_devcap_ss_descriptor		usbdcd;
47813540260SHans Petter Selasky 	struct usb_devcap_container_id_descriptor cidd;
47913540260SHans Petter Selasky } __packed;
48013540260SHans Petter Selasky 
48113540260SHans Petter Selasky union xhci_hub_desc {
48213540260SHans Petter Selasky 	struct usb_status		stat;
48313540260SHans Petter Selasky 	struct usb_port_status		ps;
48413540260SHans Petter Selasky 	struct usb_hub_ss_descriptor	hubd;
48513540260SHans Petter Selasky 	uint8_t				temp[128];
48613540260SHans Petter Selasky };
48713540260SHans Petter Selasky 
4884c5d1323SHans Petter Selasky typedef int (xhci_port_route_t)(device_t, uint32_t, uint32_t);
4894c5d1323SHans Petter Selasky 
49013540260SHans Petter Selasky struct xhci_softc {
49113540260SHans Petter Selasky 	struct xhci_hw_softc	sc_hw;
49213540260SHans Petter Selasky 	/* base device */
49313540260SHans Petter Selasky 	struct usb_bus		sc_bus;
4949b3a48eeSHans Petter Selasky 	/* configure message */
49513540260SHans Petter Selasky 	struct usb_bus_msg	sc_config_msg[2];
49613540260SHans Petter Selasky 
49797d729cfSHans Petter Selasky 	struct usb_callout	sc_callout;
49897d729cfSHans Petter Selasky 
4994c5d1323SHans Petter Selasky 	xhci_port_route_t	*sc_port_route;
5004c5d1323SHans Petter Selasky 
50113540260SHans Petter Selasky 	union xhci_hub_desc	sc_hub_desc;
50213540260SHans Petter Selasky 
50313540260SHans Petter Selasky 	struct cv		sc_cmd_cv;
50413540260SHans Petter Selasky 	struct sx		sc_cmd_sx;
50513540260SHans Petter Selasky 
50613540260SHans Petter Selasky 	struct usb_device	*sc_devices[XHCI_MAX_DEVICES];
50713540260SHans Petter Selasky 	struct resource		*sc_io_res;
50813540260SHans Petter Selasky 	struct resource		*sc_irq_res;
5092245b38fSAndrew Turner 	struct resource		*sc_msix_res;
51013540260SHans Petter Selasky 
51113540260SHans Petter Selasky 	void			*sc_intr_hdl;
51213540260SHans Petter Selasky 	bus_size_t		sc_io_size;
51313540260SHans Petter Selasky 	bus_space_tag_t		sc_io_tag;
51413540260SHans Petter Selasky 	bus_space_handle_t	sc_io_hdl;
51513540260SHans Petter Selasky 	/* last pending command address */
51613540260SHans Petter Selasky 	uint64_t		sc_cmd_addr;
51713540260SHans Petter Selasky 	/* result of command */
51813540260SHans Petter Selasky 	uint32_t		sc_cmd_result[2];
51913540260SHans Petter Selasky  	/* copy of cmd register */
52013540260SHans Petter Selasky 	uint32_t		sc_cmd;
52113540260SHans Petter Selasky 	/* worst case exit latency */
52213540260SHans Petter Selasky 	uint32_t		sc_exit_lat_max;
52313540260SHans Petter Selasky 
52413540260SHans Petter Selasky 	/* offset to operational registers */
52513540260SHans Petter Selasky 	uint32_t		sc_oper_off;
52613540260SHans Petter Selasky 	/* offset to capability registers */
52713540260SHans Petter Selasky 	uint32_t		sc_capa_off;
52813540260SHans Petter Selasky 	/* offset to runtime registers */
52913540260SHans Petter Selasky 	uint32_t		sc_runt_off;
53013540260SHans Petter Selasky 	/* offset to doorbell registers */
53113540260SHans Petter Selasky 	uint32_t		sc_door_off;
53213540260SHans Petter Selasky 
53313540260SHans Petter Selasky 	/* chip specific */
53413540260SHans Petter Selasky 	uint16_t		sc_erst_max;
53513540260SHans Petter Selasky 	uint16_t		sc_event_idx;
53613540260SHans Petter Selasky 	uint16_t		sc_command_idx;
5378237c62bSHans Petter Selasky 	uint16_t		sc_imod_default;
53813540260SHans Petter Selasky 
539bbd41717SHans Petter Selasky 	/* number of scratch pages */
540bbd41717SHans Petter Selasky 	uint16_t		sc_noscratch;
541bbd41717SHans Petter Selasky 
54213540260SHans Petter Selasky 	uint8_t			sc_event_ccs;
54313540260SHans Petter Selasky 	uint8_t			sc_command_ccs;
54413540260SHans Petter Selasky 	/* number of XHCI device slots */
54513540260SHans Petter Selasky 	uint8_t			sc_noslot;
54613540260SHans Petter Selasky 	/* number of ports on root HUB */
54713540260SHans Petter Selasky 	uint8_t			sc_noport;
54813540260SHans Petter Selasky 	/* root HUB device configuration */
54913540260SHans Petter Selasky 	uint8_t			sc_conf;
550dd7ea6c2SHans Petter Selasky 	/* step status stage of all control transfers */
551dd7ea6c2SHans Petter Selasky 	uint8_t			sc_ctlstep;
55230c6f4baSHans Petter Selasky 	/* root HUB port event bitmap, max 256 ports */
55330c6f4baSHans Petter Selasky 	uint8_t			sc_hub_idata[32];
55413540260SHans Petter Selasky 
555c1338c65SHans Petter Selasky 	/* size of context */
556c1338c65SHans Petter Selasky 	uint8_t			sc_ctx_is_64_byte;
557c1338c65SHans Petter Selasky 
558*33cbbf26SHans Petter Selasky 	/* deconfiguring USB device is not fully supported */
559*33cbbf26SHans Petter Selasky 	uint8_t			sc_no_deconfigure;
560*33cbbf26SHans Petter Selasky 
561d038463bSHans Petter Selasky 	/* Isochronous Scheduling Threshold */
562d038463bSHans Petter Selasky 	uint8_t			sc_ist;
563d038463bSHans Petter Selasky 
56413540260SHans Petter Selasky 	/* vendor string for root HUB */
56513540260SHans Petter Selasky 	char			sc_vendor[16];
56613540260SHans Petter Selasky };
56713540260SHans Petter Selasky 
56813540260SHans Petter Selasky #define	XHCI_CMD_LOCK(sc)	sx_xlock(&(sc)->sc_cmd_sx)
56913540260SHans Petter Selasky #define	XHCI_CMD_UNLOCK(sc)	sx_xunlock(&(sc)->sc_cmd_sx)
57013540260SHans Petter Selasky #define	XHCI_CMD_ASSERT_LOCKED(sc) sx_assert(&(sc)->sc_cmd_sx, SA_LOCKED)
57113540260SHans Petter Selasky 
57213540260SHans Petter Selasky /* prototypes */
57313540260SHans Petter Selasky 
57497d729cfSHans Petter Selasky uint8_t 	xhci_use_polling(void);
57513540260SHans Petter Selasky usb_error_t xhci_halt_controller(struct xhci_softc *);
576f515174bSHans Petter Selasky usb_error_t xhci_reset_controller(struct xhci_softc *);
5772ac11c11SHans Petter Selasky usb_error_t xhci_init(struct xhci_softc *, device_t, uint8_t);
57813540260SHans Petter Selasky usb_error_t xhci_start_controller(struct xhci_softc *);
57913540260SHans Petter Selasky void	xhci_interrupt(struct xhci_softc *);
58013540260SHans Petter Selasky void	xhci_uninit(struct xhci_softc *);
58131e34625SAndrew Turner int	xhci_pci_attach(device_t);
58231e34625SAndrew Turner 
58331e34625SAndrew Turner DECLARE_CLASS(xhci_pci_driver);
58413540260SHans Petter Selasky 
58513540260SHans Petter Selasky #endif					/* _XHCI_H_ */
586