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