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