xref: /freebsd/sys/dev/usb/controller/ehci.h (revision 30b22abe403bbdfaff8d284da85a60352c71a47d)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
302ac6454SAndrew Thompson  * Copyright (c) 2001 The NetBSD Foundation, Inc.
402ac6454SAndrew Thompson  * All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * This code is derived from software contributed to The NetBSD Foundation
702ac6454SAndrew Thompson  * by Lennart Augustsson (lennart@augustsson.net).
802ac6454SAndrew Thompson  *
902ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1002ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1102ac6454SAndrew Thompson  * are met:
1202ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1402ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1502ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1602ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1702ac6454SAndrew Thompson  * 3. All advertising materials mentioning features or use of this software
1802ac6454SAndrew Thompson  *    must display the following acknowledgement:
1902ac6454SAndrew Thompson  *        This product includes software developed by the NetBSD
2002ac6454SAndrew Thompson  *        Foundation, Inc. and its contributors.
2102ac6454SAndrew Thompson  * 4. Neither the name of The NetBSD Foundation nor the names of its
2202ac6454SAndrew Thompson  *    contributors may be used to endorse or promote products derived
2302ac6454SAndrew Thompson  *    from this software without specific prior written permission.
2402ac6454SAndrew Thompson  *
2502ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2602ac6454SAndrew Thompson  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2702ac6454SAndrew Thompson  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2802ac6454SAndrew Thompson  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2902ac6454SAndrew Thompson  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3002ac6454SAndrew Thompson  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3102ac6454SAndrew Thompson  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3202ac6454SAndrew Thompson  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3302ac6454SAndrew Thompson  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3402ac6454SAndrew Thompson  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3502ac6454SAndrew Thompson  * POSSIBILITY OF SUCH DAMAGE.
3602ac6454SAndrew Thompson  */
3702ac6454SAndrew Thompson 
3802ac6454SAndrew Thompson #ifndef _EHCI_H_
3902ac6454SAndrew Thompson #define	_EHCI_H_
4002ac6454SAndrew Thompson 
41ab42e8b2SAndrew Thompson #define	EHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128)
4202ac6454SAndrew Thompson 
4302ac6454SAndrew Thompson /*
4402ac6454SAndrew Thompson  * Alignment NOTE: structures must be aligned so that the hardware can index
4502ac6454SAndrew Thompson  * without performing addition.
4602ac6454SAndrew Thompson  */
4702ac6454SAndrew Thompson #define	EHCI_FRAMELIST_ALIGN          0x1000	/* bytes */
4802ac6454SAndrew Thompson #define	EHCI_FRAMELIST_COUNT            1024	/* units */
4902ac6454SAndrew Thompson #define	EHCI_VIRTUAL_FRAMELIST_COUNT     128	/* units */
5002ac6454SAndrew Thompson 
5102ac6454SAndrew Thompson #if ((8*EHCI_VIRTUAL_FRAMELIST_COUNT) < USB_MAX_HS_ISOC_FRAMES_PER_XFER)
5202ac6454SAndrew Thompson #error "maximum number of high-speed isochronous frames is higher than supported!"
5302ac6454SAndrew Thompson #endif
5402ac6454SAndrew Thompson 
5502ac6454SAndrew Thompson #if (EHCI_VIRTUAL_FRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER)
5602ac6454SAndrew Thompson #error "maximum number of full-speed isochronous frames is higher than supported!"
5702ac6454SAndrew Thompson #endif
5802ac6454SAndrew Thompson 
5902ac6454SAndrew Thompson /* Link types */
6002ac6454SAndrew Thompson #define	EHCI_LINK_TERMINATE	0x00000001
6102ac6454SAndrew Thompson #define	EHCI_LINK_TYPE(x)	((x) & 0x00000006)
6202ac6454SAndrew Thompson #define	EHCI_LINK_ITD		0x0
6302ac6454SAndrew Thompson #define	EHCI_LINK_QH		0x2
6402ac6454SAndrew Thompson #define	EHCI_LINK_SITD		0x4
6502ac6454SAndrew Thompson #define	EHCI_LINK_FSTN		0x6
6602ac6454SAndrew Thompson #define	EHCI_LINK_ADDR(x)	((x) &~ 0x1f)
6702ac6454SAndrew Thompson 
6802ac6454SAndrew Thompson /* Structures alignment (bytes) */
6902ac6454SAndrew Thompson #define	EHCI_ITD_ALIGN	128
7002ac6454SAndrew Thompson #define	EHCI_SITD_ALIGN	64
7102ac6454SAndrew Thompson #define	EHCI_QTD_ALIGN	64
7202ac6454SAndrew Thompson #define	EHCI_QH_ALIGN	128
7302ac6454SAndrew Thompson #define	EHCI_FSTN_ALIGN	32
7402ac6454SAndrew Thompson /* Data buffers are divided into one or more pages */
7502ac6454SAndrew Thompson #define	EHCI_PAGE_SIZE	0x1000
7602ac6454SAndrew Thompson #if	((USB_PAGE_SIZE < EHCI_PAGE_SIZE) || (EHCI_PAGE_SIZE == 0) ||	\
7702ac6454SAndrew Thompson 	(USB_PAGE_SIZE < EHCI_ITD_ALIGN) || (EHCI_ITD_ALIGN == 0) ||	\
7802ac6454SAndrew Thompson 	(USB_PAGE_SIZE < EHCI_SITD_ALIGN) || (EHCI_SITD_ALIGN == 0) ||	\
7902ac6454SAndrew Thompson 	(USB_PAGE_SIZE < EHCI_QTD_ALIGN) || (EHCI_QTD_ALIGN == 0) ||	\
8002ac6454SAndrew Thompson 	(USB_PAGE_SIZE < EHCI_QH_ALIGN) || (EHCI_QH_ALIGN == 0) ||	\
8102ac6454SAndrew Thompson 	(USB_PAGE_SIZE < EHCI_FSTN_ALIGN) || (EHCI_FSTN_ALIGN == 0))
8202ac6454SAndrew Thompson #error	"Invalid USB page size!"
8302ac6454SAndrew Thompson #endif
8402ac6454SAndrew Thompson 
8502ac6454SAndrew Thompson 
8602ac6454SAndrew Thompson /*
8702ac6454SAndrew Thompson  * Isochronous Transfer Descriptor.  This descriptor is used for high speed
8802ac6454SAndrew Thompson  * transfers only.
8902ac6454SAndrew Thompson  */
9002ac6454SAndrew Thompson struct ehci_itd {
9102ac6454SAndrew Thompson 	volatile uint32_t itd_next;
9202ac6454SAndrew Thompson 	volatile uint32_t itd_status[8];
9302ac6454SAndrew Thompson #define	EHCI_ITD_SET_LEN(x)	((x) << 16)
9402ac6454SAndrew Thompson #define	EHCI_ITD_GET_LEN(x)	(((x) >> 16) & 0xFFF)
9502ac6454SAndrew Thompson #define	EHCI_ITD_IOC		(1 << 15)
9602ac6454SAndrew Thompson #define	EHCI_ITD_SET_PG(x)	((x) << 12)
9702ac6454SAndrew Thompson #define	EHCI_ITD_GET_PG(x)	(((x) >> 12) & 0x7)
9802ac6454SAndrew Thompson #define	EHCI_ITD_SET_OFFS(x)	(x)
9902ac6454SAndrew Thompson #define	EHCI_ITD_GET_OFFS(x)	(((x) >> 0) & 0xFFF)
10002ac6454SAndrew Thompson #define	EHCI_ITD_ACTIVE		(1 << 31)
10102ac6454SAndrew Thompson #define	EHCI_ITD_DATABUFERR	(1 << 30)
10202ac6454SAndrew Thompson #define	EHCI_ITD_BABBLE		(1 << 29)
10302ac6454SAndrew Thompson #define	EHCI_ITD_XACTERR	(1 << 28)
10402ac6454SAndrew Thompson 	volatile uint32_t itd_bp[7];
10502ac6454SAndrew Thompson 	/* itd_bp[0] */
10602ac6454SAndrew Thompson #define	EHCI_ITD_SET_ADDR(x)	(x)
10702ac6454SAndrew Thompson #define	EHCI_ITD_GET_ADDR(x)	(((x) >> 0) & 0x7F)
10802ac6454SAndrew Thompson #define	EHCI_ITD_SET_ENDPT(x)	((x) << 8)
10902ac6454SAndrew Thompson #define	EHCI_ITD_GET_ENDPT(x)	(((x) >> 8) & 0xF)
11002ac6454SAndrew Thompson 	/* itd_bp[1] */
11102ac6454SAndrew Thompson #define	EHCI_ITD_SET_DIR_IN	(1 << 11)
11202ac6454SAndrew Thompson #define	EHCI_ITD_SET_DIR_OUT	(0 << 11)
11302ac6454SAndrew Thompson #define	EHCI_ITD_SET_MPL(x)	(x)
11402ac6454SAndrew Thompson #define	EHCI_ITD_GET_MPL(x)	(((x) >> 0) & 0x7FF)
11502ac6454SAndrew Thompson 	volatile uint32_t itd_bp_hi[7];
11602ac6454SAndrew Thompson /*
11702ac6454SAndrew Thompson  * Extra information needed:
11802ac6454SAndrew Thompson  */
11902ac6454SAndrew Thompson 	uint32_t itd_self;
12002ac6454SAndrew Thompson 	struct ehci_itd *next;
12102ac6454SAndrew Thompson 	struct ehci_itd *prev;
12202ac6454SAndrew Thompson 	struct ehci_itd *obj_next;
123760bc48eSAndrew Thompson 	struct usb_page_cache *page_cache;
12402ac6454SAndrew Thompson } __aligned(EHCI_ITD_ALIGN);
12502ac6454SAndrew Thompson 
12602ac6454SAndrew Thompson typedef struct ehci_itd ehci_itd_t;
12702ac6454SAndrew Thompson 
12802ac6454SAndrew Thompson /*
12902ac6454SAndrew Thompson  * Split Transaction Isochronous Transfer Descriptor.  This descriptor is used
13002ac6454SAndrew Thompson  * for full speed transfers only.
13102ac6454SAndrew Thompson  */
13202ac6454SAndrew Thompson struct ehci_sitd {
13302ac6454SAndrew Thompson 	volatile uint32_t sitd_next;
13402ac6454SAndrew Thompson 	volatile uint32_t sitd_portaddr;
13502ac6454SAndrew Thompson #define	EHCI_SITD_SET_DIR_OUT	(0 << 31)
13602ac6454SAndrew Thompson #define	EHCI_SITD_SET_DIR_IN	(1 << 31)
13702ac6454SAndrew Thompson #define	EHCI_SITD_SET_ADDR(x)	(x)
13802ac6454SAndrew Thompson #define	EHCI_SITD_GET_ADDR(x)	((x) & 0x7F)
13902ac6454SAndrew Thompson #define	EHCI_SITD_SET_ENDPT(x)	((x) << 8)
14002ac6454SAndrew Thompson #define	EHCI_SITD_GET_ENDPT(x)	(((x) >> 8) & 0xF)
14102ac6454SAndrew Thompson #define	EHCI_SITD_GET_DIR(x)	((x) >> 31)
14202ac6454SAndrew Thompson #define	EHCI_SITD_SET_PORT(x)	((x) << 24)
14302ac6454SAndrew Thompson #define	EHCI_SITD_GET_PORT(x)	(((x) >> 24) & 0x7F)
14402ac6454SAndrew Thompson #define	EHCI_SITD_SET_HUBA(x)	((x) << 16)
14502ac6454SAndrew Thompson #define	EHCI_SITD_GET_HUBA(x)	(((x) >> 16) & 0x7F)
14602ac6454SAndrew Thompson 	volatile uint32_t sitd_mask;
14702ac6454SAndrew Thompson #define	EHCI_SITD_SET_SMASK(x)	(x)
14802ac6454SAndrew Thompson #define	EHCI_SITD_SET_CMASK(x)	((x) << 8)
14902ac6454SAndrew Thompson 	volatile uint32_t sitd_status;
15002ac6454SAndrew Thompson #define	EHCI_SITD_COMPLETE_SPLIT	(1<<1)
15102ac6454SAndrew Thompson #define	EHCI_SITD_START_SPLIT		(0<<1)
15202ac6454SAndrew Thompson #define	EHCI_SITD_MISSED_MICRO_FRAME	(1<<2)
15302ac6454SAndrew Thompson #define	EHCI_SITD_XACTERR		(1<<3)
15402ac6454SAndrew Thompson #define	EHCI_SITD_BABBLE		(1<<4)
15502ac6454SAndrew Thompson #define	EHCI_SITD_DATABUFERR		(1<<5)
15602ac6454SAndrew Thompson #define	EHCI_SITD_ERROR			(1<<6)
15702ac6454SAndrew Thompson #define	EHCI_SITD_ACTIVE		(1<<7)
15802ac6454SAndrew Thompson #define	EHCI_SITD_IOC			(1<<31)
15902ac6454SAndrew Thompson #define	EHCI_SITD_SET_LEN(len)		((len)<<16)
16002ac6454SAndrew Thompson #define	EHCI_SITD_GET_LEN(x)		(((x)>>16) & 0x3FF)
16102ac6454SAndrew Thompson 	volatile uint32_t sitd_bp[2];
16202ac6454SAndrew Thompson 	volatile uint32_t sitd_back;
16302ac6454SAndrew Thompson 	volatile uint32_t sitd_bp_hi[2];
16402ac6454SAndrew Thompson /*
16502ac6454SAndrew Thompson  * Extra information needed:
16602ac6454SAndrew Thompson  */
16702ac6454SAndrew Thompson 	uint32_t sitd_self;
16802ac6454SAndrew Thompson 	struct ehci_sitd *next;
16902ac6454SAndrew Thompson 	struct ehci_sitd *prev;
17002ac6454SAndrew Thompson 	struct ehci_sitd *obj_next;
171760bc48eSAndrew Thompson 	struct usb_page_cache *page_cache;
17202ac6454SAndrew Thompson } __aligned(EHCI_SITD_ALIGN);
17302ac6454SAndrew Thompson 
17402ac6454SAndrew Thompson typedef struct ehci_sitd ehci_sitd_t;
17502ac6454SAndrew Thompson 
17602ac6454SAndrew Thompson /* Queue Element Transfer Descriptor */
17702ac6454SAndrew Thompson struct ehci_qtd {
17802ac6454SAndrew Thompson 	volatile uint32_t qtd_next;
17902ac6454SAndrew Thompson 	volatile uint32_t qtd_altnext;
18002ac6454SAndrew Thompson 	volatile uint32_t qtd_status;
18102ac6454SAndrew Thompson #define	EHCI_QTD_GET_STATUS(x)	(((x) >>  0) & 0xff)
18202ac6454SAndrew Thompson #define	EHCI_QTD_SET_STATUS(x)  ((x) << 0)
18302ac6454SAndrew Thompson #define	EHCI_QTD_ACTIVE		0x80
18402ac6454SAndrew Thompson #define	EHCI_QTD_HALTED		0x40
18502ac6454SAndrew Thompson #define	EHCI_QTD_BUFERR		0x20
18602ac6454SAndrew Thompson #define	EHCI_QTD_BABBLE		0x10
18702ac6454SAndrew Thompson #define	EHCI_QTD_XACTERR	0x08
18802ac6454SAndrew Thompson #define	EHCI_QTD_MISSEDMICRO	0x04
18902ac6454SAndrew Thompson #define	EHCI_QTD_SPLITXSTATE	0x02
19002ac6454SAndrew Thompson #define	EHCI_QTD_PINGSTATE	0x01
19102ac6454SAndrew Thompson #define	EHCI_QTD_STATERRS	0x74
19202ac6454SAndrew Thompson #define	EHCI_QTD_GET_PID(x)	(((x) >>  8) & 0x3)
19302ac6454SAndrew Thompson #define	EHCI_QTD_SET_PID(x)	((x) <<  8)
19402ac6454SAndrew Thompson #define	EHCI_QTD_PID_OUT	0x0
19502ac6454SAndrew Thompson #define	EHCI_QTD_PID_IN		0x1
19602ac6454SAndrew Thompson #define	EHCI_QTD_PID_SETUP	0x2
19702ac6454SAndrew Thompson #define	EHCI_QTD_GET_CERR(x)	(((x) >> 10) &  0x3)
19802ac6454SAndrew Thompson #define	EHCI_QTD_SET_CERR(x)	((x) << 10)
19902ac6454SAndrew Thompson #define	EHCI_QTD_GET_C_PAGE(x)	(((x) >> 12) &  0x7)
20002ac6454SAndrew Thompson #define	EHCI_QTD_SET_C_PAGE(x)	((x) << 12)
20102ac6454SAndrew Thompson #define	EHCI_QTD_GET_IOC(x)	(((x) >> 15) &  0x1)
20202ac6454SAndrew Thompson #define	EHCI_QTD_IOC		0x00008000
20302ac6454SAndrew Thompson #define	EHCI_QTD_GET_BYTES(x)	(((x) >> 16) &  0x7fff)
20402ac6454SAndrew Thompson #define	EHCI_QTD_SET_BYTES(x)	((x) << 16)
20502ac6454SAndrew Thompson #define	EHCI_QTD_GET_TOGGLE(x)	(((x) >> 31) &  0x1)
20602ac6454SAndrew Thompson #define	EHCI_QTD_SET_TOGGLE(x)	((x) << 31)
20702ac6454SAndrew Thompson #define	EHCI_QTD_TOGGLE_MASK	0x80000000
20802ac6454SAndrew Thompson #define	EHCI_QTD_NBUFFERS	5
20902ac6454SAndrew Thompson #define	EHCI_QTD_PAYLOAD_MAX ((EHCI_QTD_NBUFFERS-1)*EHCI_PAGE_SIZE)
21002ac6454SAndrew Thompson 	volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS];
21102ac6454SAndrew Thompson 	volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
21202ac6454SAndrew Thompson /*
21302ac6454SAndrew Thompson  * Extra information needed:
21402ac6454SAndrew Thompson  */
21502ac6454SAndrew Thompson 	struct ehci_qtd *alt_next;
21602ac6454SAndrew Thompson 	struct ehci_qtd *obj_next;
217760bc48eSAndrew Thompson 	struct usb_page_cache *page_cache;
21802ac6454SAndrew Thompson 	uint32_t qtd_self;
21902ac6454SAndrew Thompson 	uint16_t len;
22002ac6454SAndrew Thompson } __aligned(EHCI_QTD_ALIGN);
22102ac6454SAndrew Thompson 
22202ac6454SAndrew Thompson typedef struct ehci_qtd ehci_qtd_t;
22302ac6454SAndrew Thompson 
22402ac6454SAndrew Thompson /* Queue Head Sub Structure */
22502ac6454SAndrew Thompson struct ehci_qh_sub {
22602ac6454SAndrew Thompson 	volatile uint32_t qtd_next;
22702ac6454SAndrew Thompson 	volatile uint32_t qtd_altnext;
22802ac6454SAndrew Thompson 	volatile uint32_t qtd_status;
22902ac6454SAndrew Thompson 	volatile uint32_t qtd_buffer[EHCI_QTD_NBUFFERS];
23002ac6454SAndrew Thompson 	volatile uint32_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
23102ac6454SAndrew Thompson } __aligned(4);
23202ac6454SAndrew Thompson 
23302ac6454SAndrew Thompson /* Queue Head */
23402ac6454SAndrew Thompson struct ehci_qh {
23502ac6454SAndrew Thompson 	volatile uint32_t qh_link;
23602ac6454SAndrew Thompson 	volatile uint32_t qh_endp;
23702ac6454SAndrew Thompson #define	EHCI_QH_GET_ADDR(x)	(((x) >>  0) & 0x7f)	/* endpoint addr */
23802ac6454SAndrew Thompson #define	EHCI_QH_SET_ADDR(x)	(x)
23902ac6454SAndrew Thompson #define	EHCI_QH_ADDRMASK	0x0000007f
24002ac6454SAndrew Thompson #define	EHCI_QH_GET_INACT(x)	(((x) >>  7) & 0x01)	/* inactivate on next */
24102ac6454SAndrew Thompson #define	EHCI_QH_INACT		0x00000080
24202ac6454SAndrew Thompson #define	EHCI_QH_GET_ENDPT(x)	(((x) >>  8) & 0x0f)	/* endpoint no */
24302ac6454SAndrew Thompson #define	EHCI_QH_SET_ENDPT(x)	((x) <<  8)
24402ac6454SAndrew Thompson #define	EHCI_QH_GET_EPS(x)	(((x) >> 12) & 0x03)	/* endpoint speed */
24502ac6454SAndrew Thompson #define	EHCI_QH_SET_EPS(x)	((x) << 12)
24602ac6454SAndrew Thompson #define	EHCI_QH_SPEED_FULL	0x0
24702ac6454SAndrew Thompson #define	EHCI_QH_SPEED_LOW	0x1
24802ac6454SAndrew Thompson #define	EHCI_QH_SPEED_HIGH	0x2
24902ac6454SAndrew Thompson #define	EHCI_QH_GET_DTC(x)	(((x) >> 14) & 0x01)	/* data toggle control */
25002ac6454SAndrew Thompson #define	EHCI_QH_DTC		0x00004000
25102ac6454SAndrew Thompson #define	EHCI_QH_GET_HRECL(x)	(((x) >> 15) & 0x01)	/* head of reclamation */
25202ac6454SAndrew Thompson #define	EHCI_QH_HRECL		0x00008000
25302ac6454SAndrew Thompson #define	EHCI_QH_GET_MPL(x)	(((x) >> 16) & 0x7ff)	/* max packet len */
25402ac6454SAndrew Thompson #define	EHCI_QH_SET_MPL(x)	((x) << 16)
25502ac6454SAndrew Thompson #define	EHCI_QH_MPLMASK		0x07ff0000
25602ac6454SAndrew Thompson #define	EHCI_QH_GET_CTL(x)	(((x) >> 27) & 0x01)	/* control endpoint */
25702ac6454SAndrew Thompson #define	EHCI_QH_CTL		0x08000000
25802ac6454SAndrew Thompson #define	EHCI_QH_GET_NRL(x)	(((x) >> 28) & 0x0f)	/* NAK reload */
25902ac6454SAndrew Thompson #define	EHCI_QH_SET_NRL(x)	((x) << 28)
26002ac6454SAndrew Thompson 	volatile uint32_t qh_endphub;
26102ac6454SAndrew Thompson #define	EHCI_QH_GET_SMASK(x)	(((x) >>  0) & 0xff)	/* intr sched mask */
26202ac6454SAndrew Thompson #define	EHCI_QH_SET_SMASK(x)	((x) <<  0)
26302ac6454SAndrew Thompson #define	EHCI_QH_GET_CMASK(x)	(((x) >>  8) & 0xff)	/* split completion mask */
26402ac6454SAndrew Thompson #define	EHCI_QH_SET_CMASK(x)	((x) <<  8)
26502ac6454SAndrew Thompson #define	EHCI_QH_GET_HUBA(x)	(((x) >> 16) & 0x7f)	/* hub address */
26602ac6454SAndrew Thompson #define	EHCI_QH_SET_HUBA(x)	((x) << 16)
26702ac6454SAndrew Thompson #define	EHCI_QH_GET_PORT(x)	(((x) >> 23) & 0x7f)	/* hub port */
26802ac6454SAndrew Thompson #define	EHCI_QH_SET_PORT(x)	((x) << 23)
26902ac6454SAndrew Thompson #define	EHCI_QH_GET_MULT(x)	(((x) >> 30) & 0x03)	/* pipe multiplier */
27002ac6454SAndrew Thompson #define	EHCI_QH_SET_MULT(x)	((x) << 30)
27102ac6454SAndrew Thompson 	volatile uint32_t qh_curqtd;
27202ac6454SAndrew Thompson 	struct ehci_qh_sub qh_qtd;
27302ac6454SAndrew Thompson /*
27402ac6454SAndrew Thompson  * Extra information needed:
27502ac6454SAndrew Thompson  */
27602ac6454SAndrew Thompson 	struct ehci_qh *next;
27702ac6454SAndrew Thompson 	struct ehci_qh *prev;
27802ac6454SAndrew Thompson 	struct ehci_qh *obj_next;
279760bc48eSAndrew Thompson 	struct usb_page_cache *page_cache;
28002ac6454SAndrew Thompson 	uint32_t qh_self;
28102ac6454SAndrew Thompson } __aligned(EHCI_QH_ALIGN);
28202ac6454SAndrew Thompson 
28302ac6454SAndrew Thompson typedef struct ehci_qh ehci_qh_t;
28402ac6454SAndrew Thompson 
28502ac6454SAndrew Thompson /* Periodic Frame Span Traversal Node */
28602ac6454SAndrew Thompson struct ehci_fstn {
28702ac6454SAndrew Thompson 	volatile uint32_t fstn_link;
28802ac6454SAndrew Thompson 	volatile uint32_t fstn_back;
28902ac6454SAndrew Thompson } __aligned(EHCI_FSTN_ALIGN);
29002ac6454SAndrew Thompson 
29102ac6454SAndrew Thompson typedef struct ehci_fstn ehci_fstn_t;
29202ac6454SAndrew Thompson 
29302ac6454SAndrew Thompson struct ehci_hw_softc {
294760bc48eSAndrew Thompson 	struct usb_page_cache pframes_pc;
295760bc48eSAndrew Thompson 	struct usb_page_cache async_start_pc;
296760bc48eSAndrew Thompson 	struct usb_page_cache intr_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
297760bc48eSAndrew Thompson 	struct usb_page_cache isoc_hs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
298760bc48eSAndrew Thompson 	struct usb_page_cache isoc_fs_start_pc[EHCI_VIRTUAL_FRAMELIST_COUNT];
29902ac6454SAndrew Thompson 
300760bc48eSAndrew Thompson 	struct usb_page pframes_pg;
301760bc48eSAndrew Thompson 	struct usb_page async_start_pg;
302760bc48eSAndrew Thompson 	struct usb_page intr_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
303760bc48eSAndrew Thompson 	struct usb_page isoc_hs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
304760bc48eSAndrew Thompson 	struct usb_page isoc_fs_start_pg[EHCI_VIRTUAL_FRAMELIST_COUNT];
30502ac6454SAndrew Thompson };
30602ac6454SAndrew Thompson 
30702ac6454SAndrew Thompson struct ehci_config_desc {
308760bc48eSAndrew Thompson 	struct usb_config_descriptor confd;
309760bc48eSAndrew Thompson 	struct usb_interface_descriptor ifcd;
310760bc48eSAndrew Thompson 	struct usb_endpoint_descriptor endpd;
31102ac6454SAndrew Thompson } __packed;
31202ac6454SAndrew Thompson 
31302ac6454SAndrew Thompson union ehci_hub_desc {
314760bc48eSAndrew Thompson 	struct usb_status stat;
315760bc48eSAndrew Thompson 	struct usb_port_status ps;
316760bc48eSAndrew Thompson 	struct usb_hub_descriptor hubd;
31702ac6454SAndrew Thompson 	uint8_t	temp[128];
31802ac6454SAndrew Thompson };
31902ac6454SAndrew Thompson 
32002ac6454SAndrew Thompson typedef struct ehci_softc {
32102ac6454SAndrew Thompson 	struct ehci_hw_softc sc_hw;
322760bc48eSAndrew Thompson 	struct usb_bus sc_bus;		/* base device */
323760bc48eSAndrew Thompson 	struct usb_callout sc_tmo_pcd;
32430b22abeSAndrew Thompson 	struct usb_callout sc_tmo_poll;
32502ac6454SAndrew Thompson 	union ehci_hub_desc sc_hub_desc;
32602ac6454SAndrew Thompson 
327760bc48eSAndrew Thompson 	struct usb_device *sc_devices[EHCI_MAX_DEVICES];
32802ac6454SAndrew Thompson 	struct resource *sc_io_res;
32902ac6454SAndrew Thompson 	struct resource *sc_irq_res;
33002ac6454SAndrew Thompson 	struct ehci_qh *sc_async_p_last;
33102ac6454SAndrew Thompson 	struct ehci_qh *sc_intr_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
33202ac6454SAndrew Thompson 	struct ehci_sitd *sc_isoc_fs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
33302ac6454SAndrew Thompson 	struct ehci_itd *sc_isoc_hs_p_last[EHCI_VIRTUAL_FRAMELIST_COUNT];
33402ac6454SAndrew Thompson 	void   *sc_intr_hdl;
33502ac6454SAndrew Thompson 	bus_size_t sc_io_size;
33602ac6454SAndrew Thompson 	bus_space_tag_t sc_io_tag;
33702ac6454SAndrew Thompson 	bus_space_handle_t sc_io_hdl;
33802ac6454SAndrew Thompson 
33902ac6454SAndrew Thompson 	uint32_t sc_eintrs;
34002ac6454SAndrew Thompson 	uint32_t sc_cmd;		/* shadow of cmd register during
34102ac6454SAndrew Thompson 					 * suspend */
34202ac6454SAndrew Thompson 
34302ac6454SAndrew Thompson 	uint16_t sc_intr_stat[EHCI_VIRTUAL_FRAMELIST_COUNT];
34402ac6454SAndrew Thompson 	uint16_t sc_id_vendor;		/* vendor ID for root hub */
34502ac6454SAndrew Thompson 	uint16_t sc_flags;		/* chip specific flags */
34602ac6454SAndrew Thompson #define	EHCI_SCFLG_SETMODE	0x0001	/* set bridge mode again after init */
34702ac6454SAndrew Thompson #define	EHCI_SCFLG_FORCESPEED	0x0002	/* force speed */
34802ac6454SAndrew Thompson #define	EHCI_SCFLG_NORESTERM	0x0004	/* don't terminate reset sequence */
34902ac6454SAndrew Thompson #define	EHCI_SCFLG_BIGEDESC	0x0008	/* big-endian byte order descriptors */
35002ac6454SAndrew Thompson #define	EHCI_SCFLG_BIGEMMIO	0x0010	/* big-endian byte order MMIO */
35102ac6454SAndrew Thompson #define	EHCI_SCFLG_TT		0x0020	/* transaction translator present */
35230b22abeSAndrew Thompson #define	EHCI_SCFLG_LOSTINTRBUG	0x0040	/* workaround for VIA / ATI chipsets */
35302ac6454SAndrew Thompson 
35402ac6454SAndrew Thompson 	uint8_t	sc_offs;		/* offset to operational registers */
35502ac6454SAndrew Thompson 	uint8_t	sc_doorbell_disable;	/* set on doorbell failure */
35602ac6454SAndrew Thompson 	uint8_t	sc_noport;
35702ac6454SAndrew Thompson 	uint8_t	sc_addr;		/* device address */
35802ac6454SAndrew Thompson 	uint8_t	sc_conf;		/* device configuration */
35902ac6454SAndrew Thompson 	uint8_t	sc_isreset;
36002ac6454SAndrew Thompson 	uint8_t	sc_hub_idata[8];
36102ac6454SAndrew Thompson 
36202ac6454SAndrew Thompson 	char	sc_vendor[16];		/* vendor string for root hub */
36302ac6454SAndrew Thompson 
36402ac6454SAndrew Thompson } ehci_softc_t;
36502ac6454SAndrew Thompson 
36602ac6454SAndrew Thompson #define	EREAD1(sc, a)	bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
36702ac6454SAndrew Thompson #define	EREAD2(sc, a)	bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
36802ac6454SAndrew Thompson #define	EREAD4(sc, a)	bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a))
36902ac6454SAndrew Thompson #define	EWRITE1(sc, a, x)						\
37002ac6454SAndrew Thompson 	    bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
37102ac6454SAndrew Thompson #define	EWRITE2(sc, a, x)						\
37202ac6454SAndrew Thompson 	    bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
37302ac6454SAndrew Thompson #define	EWRITE4(sc, a, x)						\
37402ac6454SAndrew Thompson 	    bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (a), (x))
37502ac6454SAndrew Thompson #define	EOREAD1(sc, a)							\
37602ac6454SAndrew Thompson 	    bus_space_read_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
37702ac6454SAndrew Thompson #define	EOREAD2(sc, a)							\
37802ac6454SAndrew Thompson 	    bus_space_read_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
37902ac6454SAndrew Thompson #define	EOREAD4(sc, a)							\
38002ac6454SAndrew Thompson 	    bus_space_read_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a))
38102ac6454SAndrew Thompson #define	EOWRITE1(sc, a, x)						\
38202ac6454SAndrew Thompson 	    bus_space_write_1((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
38302ac6454SAndrew Thompson #define	EOWRITE2(sc, a, x)						\
38402ac6454SAndrew Thompson 	    bus_space_write_2((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
38502ac6454SAndrew Thompson #define	EOWRITE4(sc, a, x)						\
38602ac6454SAndrew Thompson 	    bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x))
38702ac6454SAndrew Thompson 
388e55e1ebcSAndrew Thompson #ifdef USB_EHCI_BIG_ENDIAN_DESC
389e55e1ebcSAndrew Thompson /*
390e55e1ebcSAndrew Thompson  * Handle byte order conversion between host and ``host controller''.
391e55e1ebcSAndrew Thompson  * Typically the latter is little-endian but some controllers require
392e55e1ebcSAndrew Thompson  * big-endian in which case we may need to manually swap.
393e55e1ebcSAndrew Thompson  */
394e55e1ebcSAndrew Thompson static __inline uint32_t
395e55e1ebcSAndrew Thompson htohc32(const struct ehci_softc *sc, const uint32_t v)
396e55e1ebcSAndrew Thompson {
397e55e1ebcSAndrew Thompson 	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe32(v) : htole32(v);
398e55e1ebcSAndrew Thompson }
399e55e1ebcSAndrew Thompson 
400e55e1ebcSAndrew Thompson static __inline uint16_t
401e55e1ebcSAndrew Thompson htohc16(const struct ehci_softc *sc, const uint16_t v)
402e55e1ebcSAndrew Thompson {
403e55e1ebcSAndrew Thompson 	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? htobe16(v) : htole16(v);
404e55e1ebcSAndrew Thompson }
405e55e1ebcSAndrew Thompson 
406e55e1ebcSAndrew Thompson static __inline uint32_t
407e55e1ebcSAndrew Thompson hc32toh(const struct ehci_softc *sc, const uint32_t v)
408e55e1ebcSAndrew Thompson {
409e55e1ebcSAndrew Thompson 	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be32toh(v) : le32toh(v);
410e55e1ebcSAndrew Thompson }
411e55e1ebcSAndrew Thompson 
412e55e1ebcSAndrew Thompson static __inline uint16_t
413e55e1ebcSAndrew Thompson hc16toh(const struct ehci_softc *sc, const uint16_t v)
414e55e1ebcSAndrew Thompson {
415e55e1ebcSAndrew Thompson 	return sc->sc_flags & EHCI_SCFLG_BIGEDESC ? be16toh(v) : le16toh(v);
416e55e1ebcSAndrew Thompson }
417e55e1ebcSAndrew Thompson #else
418e55e1ebcSAndrew Thompson /*
419e55e1ebcSAndrew Thompson  * Normal little-endian only conversion routines.
420e55e1ebcSAndrew Thompson  */
421e55e1ebcSAndrew Thompson static __inline uint32_t
422e55e1ebcSAndrew Thompson htohc32(const struct ehci_softc *sc, const uint32_t v)
423e55e1ebcSAndrew Thompson {
424e55e1ebcSAndrew Thompson 	return htole32(v);
425e55e1ebcSAndrew Thompson }
426e55e1ebcSAndrew Thompson 
427e55e1ebcSAndrew Thompson static __inline uint16_t
428e55e1ebcSAndrew Thompson htohc16(const struct ehci_softc *sc, const uint16_t v)
429e55e1ebcSAndrew Thompson {
430e55e1ebcSAndrew Thompson 	return htole16(v);
431e55e1ebcSAndrew Thompson }
432e55e1ebcSAndrew Thompson 
433e55e1ebcSAndrew Thompson static __inline uint32_t
434e55e1ebcSAndrew Thompson hc32toh(const struct ehci_softc *sc, const uint32_t v)
435e55e1ebcSAndrew Thompson {
436e55e1ebcSAndrew Thompson 	return le32toh(v);
437e55e1ebcSAndrew Thompson }
438e55e1ebcSAndrew Thompson 
439e55e1ebcSAndrew Thompson static __inline uint16_t
440e55e1ebcSAndrew Thompson hc16toh(const struct ehci_softc *sc, const uint16_t v)
441e55e1ebcSAndrew Thompson {
442e55e1ebcSAndrew Thompson 	return le16toh(v);
443e55e1ebcSAndrew Thompson }
444e55e1ebcSAndrew Thompson #endif
445e55e1ebcSAndrew Thompson 
446e0a69b51SAndrew Thompson usb_bus_mem_cb_t ehci_iterate_hw_softc;
44702ac6454SAndrew Thompson 
448e0a69b51SAndrew Thompson usb_error_t ehci_reset(ehci_softc_t *sc);
449e0a69b51SAndrew Thompson usb_error_t ehci_init(ehci_softc_t *sc);
45002ac6454SAndrew Thompson void	ehci_detach(struct ehci_softc *sc);
45102ac6454SAndrew Thompson void	ehci_suspend(struct ehci_softc *sc);
45202ac6454SAndrew Thompson void	ehci_resume(struct ehci_softc *sc);
45302ac6454SAndrew Thompson void	ehci_shutdown(ehci_softc_t *sc);
45402ac6454SAndrew Thompson void	ehci_interrupt(ehci_softc_t *sc);
45502ac6454SAndrew Thompson 
45602ac6454SAndrew Thompson #endif					/* _EHCI_H_ */
457