Home | History | Annotate | Line # | Download | only in usb
      1  1.41     skrll /*	$NetBSD: ehcireg.h,v 1.41 2024/09/23 10:07:26 skrll Exp $	*/
      2   1.1  augustss 
      3   1.1  augustss /*
      4  1.20   mycroft  * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
      5   1.1  augustss  * All rights reserved.
      6   1.1  augustss  *
      7   1.1  augustss  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  augustss  * by Lennart Augustsson (lennart (at) augustsson.net).
      9   1.1  augustss  *
     10   1.1  augustss  * Redistribution and use in source and binary forms, with or without
     11   1.1  augustss  * modification, are permitted provided that the following conditions
     12   1.1  augustss  * are met:
     13   1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     14   1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     15   1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  augustss  *    documentation and/or other materials provided with the distribution.
     18   1.1  augustss  *
     19   1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2  augustss  */
     31   1.2  augustss 
     32   1.2  augustss /*
     33   1.7  augustss  * The EHCI 0.96 spec can be found at
     34   1.3   gehenna  * http://developer.intel.com/technology/usb/download/ehci-r096.pdf
     35   1.7  augustss  * and the USB 2.0 spec at
     36   1.7  augustss  * http://www.usb.org/developers/data/usb_20.zip
     37   1.1  augustss  */
     38   1.1  augustss 
     39  1.35     skrll #ifndef _DEV_USB_EHCIREG_H_
     40  1.35     skrll #define _DEV_USB_EHCIREG_H_
     41   1.1  augustss 
     42   1.1  augustss /*** PCI config registers ***/
     43   1.1  augustss 
     44   1.4  augustss #define PCI_CBMEM		0x10	/* configuration base MEM */
     45   1.4  augustss 
     46   1.4  augustss #define PCI_INTERFACE_EHCI	0x20
     47   1.4  augustss 
     48   1.4  augustss #define PCI_USBREV		0x60	/* RO USB protocol revision */
     49   1.1  augustss #define  PCI_USBREV_MASK	0xff
     50   1.1  augustss #define  PCI_USBREV_PRE_1_0	0x00
     51   1.1  augustss #define  PCI_USBREV_1_0		0x10
     52   1.1  augustss #define  PCI_USBREV_1_1		0x11
     53   1.1  augustss #define  PCI_USBREV_2_0		0x20
     54   1.1  augustss 
     55   1.4  augustss #define PCI_EHCI_FLADJ		0x61	/*RW Frame len adj, SOF=59488+6*fladj */
     56   1.1  augustss 
     57   1.4  augustss #define PCI_EHCI_PORTWAKECAP	0x62	/* RW Port wake caps (opt)  */
     58   1.1  augustss 
     59  1.22  augustss /* Regs at EECP + offset */
     60   1.4  augustss #define PCI_EHCI_USBLEGSUP	0x00
     61  1.23  augustss #define  EHCI_LEG_HC_OS_OWNED		0x01000000
     62  1.23  augustss #define  EHCI_LEG_HC_BIOS_OWNED		0x00010000
     63   1.4  augustss #define PCI_EHCI_USBLEGCTLSTS	0x04
     64  1.26  jmcneill #define  EHCI_LEG_EXT_SMI_BAR		0x80000000
     65  1.26  jmcneill #define  EHCI_LEG_EXT_SMI_PCICMD	0x40000000
     66  1.26  jmcneill #define  EHCI_LEG_EXT_SMI_OS_CHANGE	0x20000000
     67   1.4  augustss 
     68  1.23  augustss #define EHCI_CAP_GET_ID(cap) ((cap) & 0xff)
     69  1.23  augustss #define EHCI_CAP_GET_NEXT(cap) (((cap) >> 8) & 0xff)
     70  1.23  augustss #define EHCI_CAP_ID_LEGACY 1
     71  1.23  augustss 
     72   1.4  augustss /*** EHCI capability registers ***/
     73   1.4  augustss 
     74   1.4  augustss #define EHCI_CAPLENGTH		0x00	/*RO Capability register length field */
     75   1.4  augustss /* reserved			0x01 */
     76   1.4  augustss #define EHCI_HCIVERSION		0x02	/* RO Interface version number */
     77   1.4  augustss 
     78   1.4  augustss #define EHCI_HCSPARAMS		0x04	/* RO Structural parameters */
     79  1.32      matt #define  EHCI_HCS_N_TT(x)	(((x) >> 20) & 0xf) /* # of xacts xlater ETTF */
     80  1.32      matt #define  EHCI_HCS_N_PTT(x)	(((x) >> 20) & 0xf) /* ports per xlater ETTF */
     81   1.4  augustss #define  EHCI_HCS_DEBUGPORT(x)	(((x) >> 20) & 0xf)
     82  1.18  augustss #define  EHCI_HCS_P_INDICATOR(x) ((x) & 0x10000)
     83   1.4  augustss #define  EHCI_HCS_N_CC(x)	(((x) >> 12) & 0xf) /* # of companion ctlrs */
     84   1.4  augustss #define  EHCI_HCS_N_PCC(x)	(((x) >> 8) & 0xf) /* # of ports per comp. */
     85   1.4  augustss #define  EHCI_HCS_PPC(x)	((x) & 0x10) /* port power control */
     86   1.4  augustss #define  EHCI_HCS_N_PORTS(x)	((x) & 0xf) /* # of ports */
     87   1.4  augustss 
     88   1.4  augustss #define EHCI_HCCPARAMS		0x08	/* RO Capability parameters */
     89  1.37     skrll #define  EHCI_HCC_EECP(x)		(((x) >> 8) & 0xff) /* extended ports caps */
     90  1.37     skrll #define  EHCI_HCC_IST_FULLFRAME		__BIT(7)
     91  1.37     skrll #define  EHCI_HCC_IST_THRESHOLD_MASK	__BITS(6,4)	/* isoc sched threshold */
     92  1.37     skrll #define  EHCI_HCC_GET_IST_THRESHOLD(x)	__SHIFTOUT((x), EHCI_HCC_IST_THRESHOLD_MASK)
     93   1.4  augustss #define  EHCI_HCC_ASPC(x)	((x) & 0x4) /* async sched park cap */
     94   1.4  augustss #define  EHCI_HCC_PFLF(x)	((x) & 0x2) /* prog frame list flag */
     95   1.4  augustss #define  EHCI_HCC_64BIT(x)	((x) & 0x1) /* 64 bit address cap */
     96   1.4  augustss 
     97   1.4  augustss #define EHCI_HCSP_PORTROUTE	0x0c	/*RO Companion port route description */
     98   1.4  augustss 
     99   1.4  augustss /* EHCI operational registers.  Offset given by EHCI_CAPLENGTH register */
    100   1.4  augustss #define EHCI_USBCMD		0x00	/* RO, RW, WO Command register */
    101   1.4  augustss #define  EHCI_CMD_ITC_M		0x00ff0000 /* RW interrupt threshold ctrl */
    102   1.6  augustss #define   EHCI_CMD_ITC_1	0x00010000
    103   1.6  augustss #define   EHCI_CMD_ITC_2	0x00020000
    104   1.6  augustss #define   EHCI_CMD_ITC_4	0x00040000
    105   1.6  augustss #define   EHCI_CMD_ITC_8	0x00080000
    106   1.6  augustss #define   EHCI_CMD_ITC_16	0x00100000
    107   1.6  augustss #define   EHCI_CMD_ITC_32	0x00200000
    108   1.6  augustss #define   EHCI_CMD_ITC_64	0x00400000
    109   1.4  augustss #define  EHCI_CMD_ASPME		0x00000800 /* RW/RO async park enable */
    110   1.4  augustss #define  EHCI_CMD_ASPMC		0x00000300 /* RW/RO async park count */
    111   1.4  augustss #define  EHCI_CMD_LHCR		0x00000080 /* RW light host ctrl reset */
    112   1.4  augustss #define  EHCI_CMD_IAAD		0x00000040 /* RW intr on async adv door bell */
    113   1.4  augustss #define  EHCI_CMD_ASE		0x00000020 /* RW async sched enable */
    114   1.4  augustss #define  EHCI_CMD_PSE		0x00000010 /* RW periodic sched enable */
    115   1.6  augustss #define  EHCI_CMD_FLS_M		0x0000000c /* RW/RO frame list size */
    116   1.4  augustss #define  EHCI_CMD_FLS(x)	(((x) >> 2) & 3) /* RW/RO frame list size */
    117   1.4  augustss #define  EHCI_CMD_HCRESET	0x00000002 /* RW reset */
    118   1.4  augustss #define  EHCI_CMD_RS		0x00000001 /* RW run/stop */
    119   1.4  augustss 
    120   1.4  augustss #define EHCI_USBSTS		0x04	/* RO, RW, RWC Status register */
    121   1.4  augustss #define  EHCI_STS_ASS		0x00008000 /* RO async sched status */
    122   1.4  augustss #define  EHCI_STS_PSS		0x00004000 /* RO periodic sched status */
    123   1.4  augustss #define  EHCI_STS_REC		0x00002000 /* RO reclamation */
    124   1.4  augustss #define  EHCI_STS_HCH		0x00001000 /* RO host controller halted */
    125   1.4  augustss #define  EHCI_STS_IAA		0x00000020 /* RWC interrupt on async adv */
    126   1.4  augustss #define  EHCI_STS_HSE		0x00000010 /* RWC host system error */
    127   1.4  augustss #define  EHCI_STS_FLR		0x00000008 /* RWC frame list rollover */
    128   1.4  augustss #define  EHCI_STS_PCD		0x00000004 /* RWC port change detect */
    129   1.4  augustss #define  EHCI_STS_ERRINT	0x00000002 /* RWC error interrupt */
    130   1.4  augustss #define  EHCI_STS_INT		0x00000001 /* RWC interrupt */
    131  1.10  augustss #define  EHCI_STS_INTRS(x)	((x) & 0x3f)
    132   1.6  augustss 
    133   1.6  augustss #define EHCI_NORMAL_INTRS (EHCI_STS_IAA | EHCI_STS_HSE | EHCI_STS_PCD | EHCI_STS_ERRINT | EHCI_STS_INT)
    134   1.4  augustss 
    135   1.4  augustss #define EHCI_USBINTR		0x08	/* RW Interrupt register */
    136   1.4  augustss #define EHCI_INTR_IAAE		0x00000020 /* interrupt on async advance ena */
    137   1.4  augustss #define EHCI_INTR_HSEE		0x00000010 /* host system error ena */
    138   1.4  augustss #define EHCI_INTR_FLRE		0x00000008 /* frame list rollover ena */
    139   1.4  augustss #define EHCI_INTR_PCIE		0x00000004 /* port change ena */
    140   1.4  augustss #define EHCI_INTR_UEIE		0x00000002 /* USB error intr ena */
    141   1.4  augustss #define EHCI_INTR_UIE		0x00000001 /* USB intr ena */
    142   1.4  augustss 
    143   1.4  augustss #define EHCI_FRINDEX		0x0c	/* RW Frame Index register */
    144   1.4  augustss 
    145   1.4  augustss #define EHCI_CTRLDSSEGMENT	0x10	/* RW Control Data Structure Segment */
    146   1.4  augustss 
    147   1.4  augustss #define EHCI_PERIODICLISTBASE	0x14	/* RW Periodic List Base */
    148   1.4  augustss #define EHCI_ASYNCLISTADDR	0x18	/* RW Async List Base */
    149   1.4  augustss 
    150   1.4  augustss #define EHCI_CONFIGFLAG		0x40	/* RW Configure Flag register */
    151   1.4  augustss #define  EHCI_CONF_CF		0x00000001 /* RW configure flag */
    152   1.4  augustss 
    153   1.4  augustss #define EHCI_PORTSC(n)		(0x40+4*(n)) /* RO, RW, RWC Port Status reg */
    154  1.34      matt #define  EHCI_PS_PSPD		0x0C000000 /* RO port speed (ETTF) */
    155  1.32      matt #define  EHCI_PS_PSPD_FS	0x00000000 /* Full speed (ETTF) */
    156  1.34      matt #define  EHCI_PS_PSPD_LS	0x04000000 /* Low speed (ETTF) */
    157  1.34      matt #define  EHCI_PS_PSPD_HS	0x08000000 /* High speed (ETTF) */
    158   1.4  augustss #define  EHCI_PS_WKOC_E		0x00400000 /* RW wake on over current ena */
    159   1.4  augustss #define  EHCI_PS_WKDSCNNT_E	0x00200000 /* RW wake on disconnect ena */
    160   1.4  augustss #define  EHCI_PS_WKCNNT_E	0x00100000 /* RW wake on connect ena */
    161   1.4  augustss #define  EHCI_PS_PTC		0x000f0000 /* RW port test control */
    162   1.4  augustss #define  EHCI_PS_PIC		0x0000c000 /* RW port indicator control */
    163   1.4  augustss #define  EHCI_PS_PO		0x00002000 /* RW port owner */
    164   1.4  augustss #define  EHCI_PS_PP		0x00001000 /* RW,RO port power */
    165   1.4  augustss #define  EHCI_PS_LS		0x00000c00 /* RO line status */
    166   1.6  augustss #define  EHCI_PS_IS_LOWSPEED(x)	(((x) & EHCI_PS_LS) == 0x00000400)
    167   1.4  augustss #define  EHCI_PS_PR		0x00000100 /* RW port reset */
    168   1.4  augustss #define  EHCI_PS_SUSP		0x00000080 /* RW suspend */
    169   1.4  augustss #define  EHCI_PS_FPR		0x00000040 /* RW force port resume */
    170   1.4  augustss #define  EHCI_PS_OCC		0x00000020 /* RWC over current change */
    171   1.4  augustss #define  EHCI_PS_OCA		0x00000010 /* RO over current active */
    172   1.4  augustss #define  EHCI_PS_PEC		0x00000008 /* RWC port enable change */
    173   1.5  augustss #define  EHCI_PS_PE		0x00000004 /* RW port enable */
    174   1.4  augustss #define  EHCI_PS_CSC		0x00000002 /* RWC connect status change */
    175   1.4  augustss #define  EHCI_PS_CS		0x00000001 /* RO connect status */
    176   1.5  augustss #define  EHCI_PS_CLEAR		(EHCI_PS_OCC|EHCI_PS_PEC|EHCI_PS_CSC)
    177   1.8  augustss 
    178   1.8  augustss #define EHCI_PORT_RESET_COMPLETE 2 /* ms */
    179   1.1  augustss 
    180   1.4  augustss #define EHCI_FLALIGN_ALIGN	0x1000
    181  1.22  augustss #define EHCI_MAX_PORTS		16 /* only 4 bits available in EHCI_HCS_N_PORTS */
    182   1.7  augustss 
    183   1.9  augustss /* No data structure may cross a page boundary. */
    184  1.37     skrll #define EHCI_PAGE_SHIFT		12
    185  1.37     skrll #define EHCI_PAGE_SIZE		(1 << EHCI_PAGE_SHIFT)
    186  1.37     skrll #define EHCI_PAGE_MASK		(EHCI_PAGE_SIZE - 1)
    187  1.37     skrll #define EHCI_PAGE(x)		((x) & ~EHCI_PAGE_MASK)
    188  1.37     skrll #define EHCI_PAGE_OFFSET(x)	((x) & EHCI_PAGE_MASK)
    189  1.37     skrll #define EHCI_NPAGES(x)		(((x) + EHCI_PAGE_MASK) >> EHCI_PAGE_SHIFT)
    190   1.9  augustss 
    191  1.37     skrll typedef uint32_t ehci_link_t;
    192  1.37     skrll #define EHCI_LINK_TERMINATE	__BIT(0)
    193   1.7  augustss #define EHCI_LINK_TYPE(x)	((x) & 0x00000006)
    194   1.7  augustss #define  EHCI_LINK_ITD		0x0
    195   1.7  augustss #define  EHCI_LINK_QH		0x2
    196   1.7  augustss #define  EHCI_LINK_SITD		0x4
    197   1.7  augustss #define  EHCI_LINK_FSTN		0x6
    198  1.13  augustss #define EHCI_LINK_ADDR(x)	((x) &~ 0x1f)
    199   1.7  augustss 
    200  1.37     skrll typedef uint32_t ehci_physaddr_t;
    201   1.7  augustss 
    202  1.37     skrll typedef uint32_t ehci_isoc_trans_t;
    203  1.37     skrll typedef uint32_t ehci_isoc_bufr_ptr_t;
    204  1.28  jmcneill 
    205   1.7  augustss /* Isochronous Transfer Descriptor */
    206  1.38  jmcneill #define EHCI_ITD_ALIGN 32
    207  1.31  jakllsch #define EHCI_ITD_NUFRAMES USB_UFRAMES_PER_FRAME
    208  1.31  jakllsch #define EHCI_ITD_NBUFFERS 7
    209  1.40       mrg typedef struct ehci_itd_t {
    210  1.28  jmcneill 	volatile ehci_link_t		itd_next;
    211  1.31  jakllsch 	volatile ehci_isoc_trans_t	itd_ctl[EHCI_ITD_NUFRAMES];
    212  1.37     skrll #define EHCI_ITD_STATUS_MASK	__BITS(31,28)
    213  1.37     skrll #define EHCI_ITD_GET_STATUS(x)	__SHIFTOUT((x), EHCI_ITD_STATUS_MASK)
    214  1.37     skrll #define EHCI_ITD_SET_STATUS(x)	__SHIFTIN((x), EHCI_ITD_STATUS_MASK)
    215  1.37     skrll #define EHCI_ITD_ACTIVE		__BIT(31)
    216  1.37     skrll #define EHCI_ITD_BUF_ERR	__BIT(30)
    217  1.37     skrll #define EHCI_ITD_BABBLE		__BIT(29)
    218  1.37     skrll #define EHCI_ITD_ERROR		__BIT(28)
    219  1.37     skrll #define EHCI_ITD_LEN_MASK	__BITS(27,16)
    220  1.37     skrll #define EHCI_ITD_GET_LEN(x)	__SHIFTOUT((x), EHCI_ITD_LEN_MASK)
    221  1.37     skrll #define EHCI_ITD_SET_LEN(x)	__SHIFTIN((x), EHCI_ITD_LEN_MASK)
    222  1.37     skrll #define EHCI_ITD_IOC		__BIT(15)
    223  1.37     skrll #define EHCI_ITD_GET_IOC(x)	__SHIFTOUT((x), EHCI_ITD_IOC)
    224  1.37     skrll #define EHCI_ITD_SET_IOC(x)	__SHIFTIN((x), EHCI_ITD_IOC)
    225  1.37     skrll #define EHCI_ITD_PG_MASK	__BITS(14,12)
    226  1.37     skrll #define EHCI_ITD_GET_PG(x)	__SHIFTOUT((x), EHCI_ITD_PG_MASK)
    227  1.37     skrll #define EHCI_ITD_SET_PG(x)	__SHIFTIN((x), EHCI_ITD_PG_MASK)
    228  1.37     skrll #define EHCI_ITD_OFFSET_MASK	__BITS(11,0)
    229  1.37     skrll #define EHCI_ITD_GET_OFFS(x)	__SHIFTOUT((x), EHCI_ITD_OFFSET_MASK)
    230  1.37     skrll #define EHCI_ITD_SET_OFFS(x)	__SHIFTIN((x), EHCI_ITD_OFFSET_MASK)
    231  1.31  jakllsch 	volatile ehci_isoc_bufr_ptr_t	itd_bufr[EHCI_ITD_NBUFFERS];
    232  1.37     skrll #define EHCI_ITD_BPTR_MASK	__BITS(31,12)
    233  1.37     skrll #define EHCI_ITD_GET_BPTR(x)	((x) & EHCI_ITD_BPTR_MASK)
    234  1.37     skrll #define EHCI_ITD_SET_BPTR(x)	((x) & EHCI_ITD_BPTR_MASK)
    235  1.37     skrll #define EHCI_ITD_EP_MASK	__BITS(11,8)
    236  1.37     skrll #define EHCI_ITD_GET_EP(x)	__SHIFTOUT((x), EHCI_ITD_EP_MASK)
    237  1.37     skrll #define EHCI_ITD_SET_EP(x)	__SHIFTIN((x), EHCI_ITD_EP_MASK)
    238  1.37     skrll #define EHCI_ITD_DADDR_MASK	__BITS(6,0)
    239  1.37     skrll #define EHCI_ITD_GET_DADDR(x)	__SHIFTOUT((x), EHCI_ITD_DADDR_MASK)
    240  1.37     skrll #define EHCI_ITD_SET_DADDR(x)	__SHIFTIN((x), EHCI_ITD_DADDR_MASK)
    241  1.37     skrll #define EHCI_ITD_DIR_MASK	__BIT(11)
    242  1.37     skrll #define EHCI_ITD_GET_DIR(x)	__SHIFTOUT((x), EHCI_ITD_DIR_MASK)
    243  1.37     skrll #define EHCI_ITD_SET_DIR(x)	__SHIFTIN((x), EHCI_ITD_DIR_MASK)
    244  1.37     skrll #define EHCI_ITD_MAXPKT_MASK	__BITS(10,0)
    245  1.37     skrll #define EHCI_ITD_GET_MAXPKT(x)	__SHIFTOUT((x), EHCI_ITD_MAXPKT_MASK)
    246  1.37     skrll #define EHCI_ITD_SET_MAXPKT(x)	__SHIFTIN((x), EHCI_ITD_MAXPKT_MASK)
    247  1.37     skrll #define EHCI_ITD_MULTI_MASK	__BITS(1,0)
    248  1.37     skrll #define EHCI_ITD_GET_MULTI(x)	__SHIFTOUT((x), EHCI_ITD_MULTI_MASK)
    249  1.37     skrll #define EHCI_ITD_SET_MULTI(x)	__SHIFTIN((x), EHCI_ITD_MULTI_MASK)
    250  1.31  jakllsch 	volatile ehci_isoc_bufr_ptr_t	itd_bufr_hi[EHCI_ITD_NBUFFERS];
    251  1.41     skrll } ehci_itd_t;
    252  1.41     skrll #define EHCI_ITD_ALLOC_ALIGN	MAX(EHCI_ITD_ALIGN, CACHE_LINE_SIZE)
    253  1.41     skrll #define EHCI_ITD_SIZE		(roundup(sizeof(ehci_itd_t), EHCI_ITD_ALLOC_ALIGN))
    254  1.41     skrll #define EHCI_ITD_CHUNK		(EHCI_PAGE_SIZE / EHCI_ITD_SIZE)
    255   1.7  augustss 
    256   1.7  augustss /* Split Transaction Isochronous Transfer Descriptor */
    257  1.38  jmcneill #define EHCI_SITD_ALIGN 32
    258  1.40       mrg typedef struct ehci_sitd_t {
    259  1.24       scw 	volatile ehci_link_t	sitd_next;
    260  1.37     skrll 	volatile uint32_t	sitd_endp;
    261  1.37     skrll #define EHCI_SITD_DIR_MASK	__BIT(31)
    262  1.37     skrll #define EHCI_SITD_PORT_MASK	__BITS(30,24)
    263  1.37     skrll #define EHCI_SITD_HUBA_MASK	__BITS(22,16)
    264  1.37     skrll #define EHCI_SITD_ENDPT_MASK	__BITS(11,8)
    265  1.37     skrll #define EHCI_SITD_DADDR_MASK	__BITS(6,0)
    266  1.37     skrll #define EHCI_SITD_SET_DIR(x)	__SHIFTIN((x), EHCI_SITD_DIR_MASK)
    267  1.37     skrll #define EHCI_SITD_SET_PORT(x)	__SHIFTIN((x), EHCI_SITD_PORT_MASK)
    268  1.37     skrll #define EHCI_SITD_SET_HUBA(x)	__SHIFTIN((x), EHCI_SITD_HUBA_MASK)
    269  1.37     skrll #define EHCI_SITD_SET_ENDPT(x)	__SHIFTIN((x), EHCI_SITD_ENDPT_MASK)
    270  1.37     skrll #define EHCI_SITD_SET_DADDR(x)	__SHIFTIN((x), EHCI_SITD_DADDR_MASK)
    271  1.37     skrll 	volatile uint32_t	sitd_sched;
    272  1.37     skrll #define EHCI_SITD_SMASK_MASK	__BITS(7,0)
    273  1.37     skrll #define EHCI_SITD_CMASK_MASK	__BITS(15,8)
    274  1.37     skrll #define EHCI_SITD_SET_SMASK(x)	__SHIFTIN((x), EHCI_SITD_SMASK_MASK)
    275  1.37     skrll #define EHCI_SITD_SET_CMASK(x)	__SHIFTIN((x), EHCI_SITD_CMASK_MASK)
    276  1.37     skrll 	volatile uint32_t	sitd_trans;
    277  1.37     skrll #define EHCI_SITD_IOC		__BIT(31)
    278  1.37     skrll #define EHCI_SITD_P		__BIT(30)
    279  1.37     skrll #define EHCI_SITD_LENGTH_MASK	__BITS(25,16)
    280  1.37     skrll #define EHCI_SITD_GET_LEN(x)	__SHIFTOUT((x), EHCI_SITD_LENGTH_MASK)
    281  1.37     skrll #define EHCI_SITD_SET_LEN(x)	__SHIFTIN((x), EHCI_SITD_LENGTH_MASK)
    282  1.37     skrll #define EHCI_SITD_STATUS_MASK	__BITS(7,0)
    283  1.37     skrll #define EHCI_SITD_ACTIVE	0x00000080
    284  1.37     skrll #define EHCI_SITD_ERR		0x00000040
    285  1.37     skrll #define EHCI_SITD_BUFERR	0x00000020
    286  1.37     skrll #define EHCI_SITD_BABBLE	0x00000010
    287  1.37     skrll #define EHCI_SITD_XACTERR	0x00000008
    288  1.37     skrll #define EHCI_SITD_MISS		0x00000004
    289  1.37     skrll #define EHCI_SITD_SPLITXSTATE	0x00000002
    290  1.37     skrll 
    291  1.37     skrll #define EHCI_SITD_BUFFERS	2
    292  1.37     skrll 
    293  1.37     skrll 	volatile uint32_t	sitd_buffer[EHCI_SITD_BUFFERS];
    294  1.37     skrll #define EHCI_SITD_SET_BPTR(x)	((x) & 0xfffff000)
    295  1.37     skrll #define EHCI_SITD_SET_OFFS(x)	((x) & 0xfff)
    296  1.37     skrll #define EHCI_SITD_TP_MASK	__BITS(4,3)
    297  1.37     skrll #define EHCI_SITD_TCOUNT_MASK	__BITS(2,0)
    298  1.37     skrll 
    299  1.37     skrll 	volatile ehci_link_t	sitd_back;
    300  1.37     skrll 	volatile uint32_t	sitd_buffer_hi[EHCI_SITD_BUFFERS];
    301  1.41     skrll } ehci_sitd_t;
    302   1.7  augustss 
    303   1.7  augustss /* Queue Element Transfer Descriptor */
    304  1.37     skrll #define EHCI_QTD_NBUFFERS	5
    305  1.37     skrll #define EHCI_QTD_MAXTRANSFER	(EHCI_QTD_NBUFFERS * EHCI_PAGE_SIZE)
    306  1.38  jmcneill #define EHCI_QTD_ALIGN 32
    307  1.40       mrg typedef struct ehci_qtd_t {
    308  1.24       scw 	volatile ehci_link_t	qtd_next;
    309  1.24       scw 	volatile ehci_link_t	qtd_altnext;
    310  1.37     skrll 	volatile uint32_t	qtd_status;
    311  1.37     skrll #define EHCI_QTD_STATUS_MASK	__BITS(7,0)
    312  1.37     skrll #define EHCI_QTD_GET_STATUS(x)	__SHIFTOUT((x), EHCI_QTD_STATUS_MASK)
    313  1.37     skrll #define EHCI_QTD_SET_STATUS(x)	__SHIFTIN((x), EHCI_QTD_STATUS_MASK)
    314   1.7  augustss #define  EHCI_QTD_ACTIVE	0x80
    315   1.7  augustss #define  EHCI_QTD_HALTED	0x40
    316   1.7  augustss #define  EHCI_QTD_BUFERR	0x20
    317   1.7  augustss #define  EHCI_QTD_BABBLE	0x10
    318   1.7  augustss #define  EHCI_QTD_XACTERR	0x08
    319   1.7  augustss #define  EHCI_QTD_MISSEDMICRO	0x04
    320   1.7  augustss #define  EHCI_QTD_SPLITXSTATE	0x02
    321   1.7  augustss #define  EHCI_QTD_PINGSTATE	0x01
    322  1.21  augustss #define  EHCI_QTD_STATERRS	0x3c
    323  1.37     skrll #define EHCI_QTD_PID_MASK	__BITS(9,8)
    324  1.37     skrll #define EHCI_QTD_GET_PID(x)	__SHIFTOUT((x), EHCI_QTD_PID_MASK)
    325  1.37     skrll #define EHCI_QTD_SET_PID(x)	__SHIFTIN((x), EHCI_QTD_PID_MASK)
    326   1.7  augustss #define  EHCI_QTD_PID_OUT	0x0
    327   1.7  augustss #define  EHCI_QTD_PID_IN	0x1
    328   1.7  augustss #define  EHCI_QTD_PID_SETUP	0x2
    329  1.37     skrll #define EHCI_QTD_CERR_MASK	__BITS(11,10)
    330  1.37     skrll #define EHCI_QTD_GET_CERR(x)	__SHIFTOUT((x), EHCI_QTD_CERR_MASK)
    331  1.37     skrll #define EHCI_QTD_SET_CERR(x)	__SHIFTIN((x), EHCI_QTD_CERR_MASK)
    332  1.37     skrll #define EHCI_QTD_C_PAGE_MASK	__BITS(14,12)
    333  1.37     skrll #define EHCI_QTD_GET_C_PAGE(x)	__SHIFTOUT((x), EHCI_QTD_C_PAGE_MASK)
    334  1.37     skrll #define EHCI_QTD_SET_C_PAGE(x)	__SHIFTIN((x), EHCI_QTD_C_PAGE_MASK)
    335  1.37     skrll #define EHCI_QTD_IOC		__BIT(15)
    336  1.37     skrll #define EHCI_QTD_GET_IOC(x)	__SHIFTOUT((x), EHCI_QTD_IOC)
    337  1.37     skrll #define EHCI_QTD_BYTES_MASK	__BITS(30,16)
    338  1.37     skrll #define EHCI_QTD_GET_BYTES(x)	__SHIFTOUT((x), EHCI_QTD_BYTES_MASK)
    339  1.37     skrll #define EHCI_QTD_SET_BYTES(x)	__SHIFTIN((x), EHCI_QTD_BYTES_MASK)
    340  1.37     skrll #define EHCI_QTD_TOGGLE_MASK	__BIT(31)
    341  1.37     skrll #define EHCI_QTD_GET_TOGGLE(x)	__SHIFTOUT((x), EHCI_QTD_TOGGLE_MASK)
    342  1.37     skrll #define	EHCI_QTD_SET_TOGGLE(x)	__SHIFTIN((x), EHCI_QTD_TOGGLE_MASK)
    343  1.24       scw 	volatile ehci_physaddr_t qtd_buffer[EHCI_QTD_NBUFFERS];
    344  1.24       scw 	volatile ehci_physaddr_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
    345  1.41     skrll } ehci_qtd_t;
    346  1.41     skrll #define EHCI_QTD_ALLOC_ALIGN	MAX(EHCI_QTD_ALIGN, CACHE_LINE_SIZE)
    347  1.41     skrll #define EHCI_QTD_SIZE		(roundup(sizeof(ehci_qtd_t), EHCI_QTD_ALLOC_ALIGN))
    348  1.41     skrll #define EHCI_QTD_CHUNK		(EHCI_PAGE_SIZE / EHCI_QTD_SIZE)
    349   1.7  augustss 
    350   1.7  augustss /* Queue Head */
    351  1.38  jmcneill #define EHCI_QH_ALIGN 32
    352  1.40       mrg typedef struct ehci_qh_t {
    353  1.24       scw 	volatile ehci_link_t	qh_link;
    354  1.37     skrll 	volatile uint32_t	qh_endp;
    355  1.37     skrll #define EHCI_QH_ADDR_MASK	__BITS(6,0)	/* endpoint addr */
    356  1.37     skrll #define EHCI_QH_GET_ADDR(x)	__SHIFTOUT((x), EHCI_QH_ADDR_MASK)
    357  1.37     skrll #define EHCI_QH_SET_ADDR(x)	__SHIFTIN((x), EHCI_QH_ADDR_MASK)
    358  1.37     skrll #define EHCI_QH_INACT		__BIT(7)	/* inactivate on next */
    359  1.37     skrll #define EHCI_QH_GET_INACT(x)	__SHIFTOUT((x), EHCI_QH_INACT)
    360  1.37     skrll #define EHCI_QH_ENDPT_MASK	__BITS(11,8)	 /* endpoint no */
    361  1.37     skrll #define EHCI_QH_GET_ENDPT(x)	__SHIFTOUT((x), EHCI_QH_ENDPT_MASK)
    362  1.37     skrll #define EHCI_QH_SET_ENDPT(x)	__SHIFTIN((x), EHCI_QH_ENDPT_MASK)
    363  1.37     skrll #define EHCI_QH_EPS_MASK	__BITS(13,12)	/* endpoint speed */
    364  1.37     skrll #define EHCI_QH_GET_EPS(x)	__SHIFTOUT((x), EHCI_QH_EPS_MASK)
    365  1.37     skrll #define EHCI_QH_SET_EPS(x)	__SHIFTIN((x), EHCI_QH_EPS_MASK)
    366   1.9  augustss #define  EHCI_QH_SPEED_FULL	0x0
    367   1.9  augustss #define  EHCI_QH_SPEED_LOW	0x1
    368   1.9  augustss #define  EHCI_QH_SPEED_HIGH	0x2
    369  1.37     skrll #define EHCI_QH_DTC		__BIT(14)	 /* data toggle control */
    370  1.37     skrll #define EHCI_QH_GET_DTC(x)	__SHIFTOUT((x), EHCI_QH_DTC)
    371  1.37     skrll #define EHCI_QH_HRECL		__BIT(15)	/* head of reclamation */
    372  1.37     skrll #define EHCI_QH_GET_HRECL(x)	__SHIFTOUT((x), EHCI_QH_HRECL)
    373  1.37     skrll #define EHCI_QH_MPL_MASK	__BITS(26,16)	/* max packet len */
    374  1.37     skrll #define EHCI_QH_GET_MPL(x)	__SHIFTOUT((x), EHCI_QH_MPL_MASK)
    375  1.37     skrll #define EHCI_QH_SET_MPL(x)	__SHIFTIN((x), EHCI_QH_MPL_MASK)
    376  1.37     skrll #define EHCI_QH_CTL		__BIT(27)	/* control endpoint */
    377  1.37     skrll #define EHCI_QH_GET_CTL(x)	__SHIFTOUT((x), EHCI_QH_CTL)
    378  1.37     skrll #define EHCI_QH_NRL_MASK	__BITS(31,28)	/* NAK reload */
    379  1.37     skrll #define EHCI_QH_GET_NRL(x)	__SHIFTOUT((x), EHCI_QH_NRL_MASK)
    380  1.37     skrll #define EHCI_QH_SET_NRL(x)	__SHIFTIN((x), EHCI_QH_NRL_MASK)
    381  1.37     skrll 	volatile uint32_t	qh_endphub;
    382  1.37     skrll #define EHCI_QH_SMASK_MASK	__BITS(7,0)	 /* intr sched mask */
    383  1.37     skrll #define EHCI_QH_GET_SMASK(x)	__SHIFTOUT((x), EHCI_QH_SMASK_MASK)
    384  1.37     skrll #define EHCI_QH_SET_SMASK(x)	__SHIFTIN((x), EHCI_QH_SMASK_MASK)
    385  1.37     skrll #define EHCI_QH_CMASK_MASK	__BITS(15,8)	 /* split completion mask */
    386  1.37     skrll #define EHCI_QH_GET_CMASK(x)	__SHIFTOUT((x), EHCI_QH_CMASK_MASK)
    387  1.37     skrll #define EHCI_QH_SET_CMASK(x)	__SHIFTIN((x), EHCI_QH_CMASK_MASK)
    388  1.37     skrll #define EHCI_QH_HUBA_MASK	__BITS(22,16)	/* hub address */
    389  1.37     skrll #define EHCI_QH_GET_HUBA(x)	__SHIFTOUT((x), EHCI_QH_HUBA_MASK)
    390  1.37     skrll #define EHCI_QH_SET_HUBA(x)	__SHIFTIN((x), EHCI_QH_HUBA_MASK)
    391  1.37     skrll #define EHCI_QH_PORT_MASK	__BITS(29,23)	 /* hub port */
    392  1.37     skrll #define EHCI_QH_GET_PORT(x)	__SHIFTOUT((x), EHCI_QH_PORT_MASK)
    393  1.37     skrll #define EHCI_QH_SET_PORT(x)	__SHIFTIN((x), EHCI_QH_PORT_MASK)
    394  1.37     skrll #define EHCI_QH_MULTI_MASK	__BITS(31,30)	/* pipe multiplier */
    395  1.37     skrll #define EHCI_QH_GET_MULT(x)	__SHIFTOUT((x), EHCI_QH_MULTI_MASK)
    396  1.37     skrll #define EHCI_QH_SET_MULT(x)	__SHIFTIN((x), EHCI_QH_MULTI_MASK)
    397  1.24       scw 	volatile ehci_link_t	qh_curqtd;
    398  1.41     skrll 	ehci_qtd_t		qh_qtd;
    399  1.41     skrll } ehci_qh_t;
    400  1.41     skrll #define EHCI_QH_ALLOC_ALIGN	MAX(EHCI_QH_ALIGN, CACHE_LINE_SIZE)
    401  1.41     skrll #define EHCI_QH_SIZE		(roundup(sizeof(ehci_qh_t), EHCI_QH_ALLOC_ALIGN))
    402  1.41     skrll #define EHCI_QH_CHUNK		(EHCI_PAGE_SIZE / EHCI_QH_SIZE)
    403   1.7  augustss 
    404   1.7  augustss /* Periodic Frame Span Traversal Node */
    405  1.38  jmcneill #define EHCI_FSTN_ALIGN 32
    406  1.40       mrg typedef struct ehci_fstn_t {
    407  1.24       scw 	volatile ehci_link_t	fstn_link;
    408  1.24       scw 	volatile ehci_link_t	fstn_back;
    409  1.41     skrll } ehci_fstn_t;
    410   1.1  augustss 
    411  1.30  jakllsch /* Debug Port */
    412  1.30  jakllsch #define PCI_CAP_DEBUGPORT_OFFSET __BITS(28,16)
    413  1.30  jakllsch #define PCI_CAP_DEBUGPORT_BAR	__BITS(31,29)
    414  1.30  jakllsch /* Debug Port Registers, offset into DEBUGPORT_BAR at DEBUGPORT_OFFSET */
    415  1.30  jakllsch #define EHCI_DEBUG_SC		0x00
    416  1.30  jakllsch /* Status/Control Register */
    417  1.30  jakllsch #define  EHCI_DSC_DATA_LENGTH	__BITS(3,0)
    418  1.30  jakllsch #define  EHCI_DSC_WRITE		__BIT(4)
    419  1.30  jakllsch #define  EHCI_DSC_GO		__BIT(5)
    420  1.30  jakllsch #define  EHCI_DSC_ERROR		__BIT(6)
    421  1.30  jakllsch #define  EHCI_DSC_EXCEPTION	__BITS(9,7)
    422  1.30  jakllsch #define   EHCI_DSC_EXCEPTION_NONE	0
    423  1.30  jakllsch #define   EHCI_DSC_EXCEPTION_XACT	1
    424  1.30  jakllsch #define   EHCI_DSC_EXCEPTION_HW		2
    425  1.30  jakllsch #define  EHCI_DSC_IN_USE	__BIT(10)
    426  1.30  jakllsch #define  EHCI_DSC_DONE		__BIT(16)
    427  1.30  jakllsch #define  EHCI_DSC_ENABLED	__BIT(28)
    428  1.30  jakllsch #define  EHCI_DSC_OWNER		__BIT(30)
    429  1.30  jakllsch #define EHCI_DEBUG_UPR		0x04
    430  1.30  jakllsch /* USB PIDs Register */
    431  1.30  jakllsch #define  EHCI_DPR_TOKEN		__BITS(7,0)
    432  1.30  jakllsch #define  EHCI_DPR_SEND		__BITS(15,8)
    433  1.33   mbalmer #define  EHCI_DPR_RECEIVED	__BITS(23,16)
    434  1.30  jakllsch /* Data Registers */
    435  1.30  jakllsch #define EHCI_DEBUG_DATA0123	0x08
    436  1.30  jakllsch #define EHCI_DEBUG_DATA4567	0x0c
    437  1.30  jakllsch #define EHCI_DEBUG_DAR		0x10
    438  1.30  jakllsch /* Device Address Register */
    439  1.30  jakllsch #define  EHCI_DAR_ENDPOINT	__BITS(3,0)
    440  1.30  jakllsch #define  EHCI_DAR_ADDRESS	__BITS(14,8)
    441  1.30  jakllsch 
    442  1.35     skrll #endif /* _DEV_USB_EHCIREG_H_ */
    443