Home | History | Annotate | Line # | Download | only in usb
ehcivar.h revision 1.42
      1 /*	$NetBSD: ehcivar.h,v 1.42 2013/02/02 14:15:55 matt Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net).
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _EHCIVAR_H_
     33 #define _EHCIVAR_H_
     34 
     35 #include <sys/pool.h>
     36 
     37 typedef struct ehci_soft_qtd {
     38 	ehci_qtd_t qtd;
     39 	struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
     40 	ehci_physaddr_t physaddr;
     41 	usb_dma_t dma;                  /* qTD's DMA infos */
     42 	int offs;                       /* qTD's offset in usb_dma_t */
     43 	usbd_xfer_handle xfer;
     44 	LIST_ENTRY(ehci_soft_qtd) hnext;
     45 	u_int16_t len;
     46 } ehci_soft_qtd_t;
     47 #define EHCI_SQTD_ALIGN	MAX(EHCI_QTD_ALIGN, CACHE_LINE_SIZE)
     48 #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_SQTD_ALIGN - 1) & -EHCI_SQTD_ALIGN)
     49 #define EHCI_SQTD_CHUNK (EHCI_PAGE_SIZE / EHCI_SQTD_SIZE)
     50 
     51 typedef struct ehci_soft_qh {
     52 	ehci_qh_t qh;
     53 	struct ehci_soft_qh *next;
     54 	struct ehci_soft_qtd *sqtd;
     55 	ehci_physaddr_t physaddr;
     56 	usb_dma_t dma;                  /* QH's DMA infos */
     57 	int offs;                       /* QH's offset in usb_dma_t */
     58 	int islot;
     59 } ehci_soft_qh_t;
     60 #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
     61 #define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE)
     62 
     63 typedef struct ehci_soft_itd {
     64 	ehci_itd_t itd;
     65 	union {
     66 		struct {
     67 			/* soft_itds links in a periodic frame*/
     68 			struct ehci_soft_itd *next;
     69 			struct ehci_soft_itd *prev;
     70 		} frame_list;
     71 		/* circular list of free itds */
     72 		LIST_ENTRY(ehci_soft_itd) free_list;
     73 	} u;
     74 	struct ehci_soft_itd *xfer_next; /* Next soft_itd in xfer */
     75 	ehci_physaddr_t physaddr;
     76 	usb_dma_t dma;
     77 	int offs;
     78 	int slot;
     79 	struct timeval t; /* store free time */
     80 } ehci_soft_itd_t;
     81 #define EHCI_ITD_SIZE ((sizeof(struct ehci_soft_itd) + EHCI_QH_ALIGN - 1) / EHCI_ITD_ALIGN * EHCI_ITD_ALIGN)
     82 #define EHCI_ITD_CHUNK (EHCI_PAGE_SIZE / EHCI_ITD_SIZE)
     83 
     84 struct ehci_xfer {
     85 	struct usbd_xfer xfer;
     86 	struct usb_task	abort_task;
     87 	TAILQ_ENTRY(ehci_xfer) inext; /* list of active xfers */
     88 	ehci_soft_qtd_t *sqtdstart;
     89 	ehci_soft_qtd_t *sqtdend;
     90 	ehci_soft_itd_t *itdstart;
     91 	ehci_soft_itd_t *itdend;
     92 	u_int isoc_len;
     93 	int isdone;	/* used only when DIAGNOSTIC is defined */
     94 };
     95 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
     96 
     97 /* Information about an entry in the interrupt list. */
     98 struct ehci_soft_islot {
     99 	ehci_soft_qh_t *sqh;	/* Queue Head. */
    100 };
    101 
    102 #define EHCI_FRAMELIST_MAXCOUNT	1024
    103 #define EHCI_IPOLLRATES		8 /* Poll rates (1ms, 2, 4, 8 .. 128) */
    104 #define EHCI_INTRQHS		((1 << EHCI_IPOLLRATES) - 1)
    105 #define EHCI_MAX_POLLRATE	(1 << (EHCI_IPOLLRATES - 1))
    106 #define EHCI_IQHIDX(lev, pos) \
    107 	((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
    108 #define EHCI_ILEV_IVAL(lev)	(1 << (lev))
    109 
    110 
    111 #define EHCI_HASH_SIZE 128
    112 #define EHCI_COMPANION_MAX 8
    113 
    114 #define EHCI_FREE_LIST_INTERVAL 100
    115 
    116 typedef struct ehci_softc {
    117 	device_t sc_dev;
    118 	kmutex_t sc_lock;
    119 	kmutex_t sc_intr_lock;
    120 	kcondvar_t sc_doorbell;
    121 	void *sc_doorbell_si;
    122 	void *sc_pcd_si;
    123 	struct usbd_bus sc_bus;
    124 	bus_space_tag_t iot;
    125 	bus_space_handle_t ioh;
    126 	bus_size_t sc_size;
    127 	u_int sc_offs;			/* offset to operational regs */
    128 	int sc_flags;			/* misc flags */
    129 #define EHCIF_DROPPED_INTR_WORKAROUND	0x01
    130 #define EHCIF_ETTF			0x02 /* Emb. Transaction Translater func. */
    131 
    132 	char sc_vendor[32];		/* vendor string for root hub */
    133 	int sc_id_vendor;		/* vendor ID for root hub */
    134 
    135 	u_int32_t sc_cmd;		/* shadow of cmd reg during suspend */
    136 
    137 	u_int sc_ncomp;
    138 	u_int sc_npcomp;
    139 	device_t sc_comps[EHCI_COMPANION_MAX];
    140 
    141 	usb_dma_t sc_fldma;
    142 	ehci_link_t *sc_flist;
    143 	u_int sc_flsize;
    144 	u_int sc_rand;			/* XXX need proper intr scheduling */
    145 
    146 	struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
    147 
    148 	/* jcmm - an array matching sc_flist, but with software pointers,
    149 	 * not hardware address pointers
    150 	 */
    151 	struct ehci_soft_itd **sc_softitds;
    152 
    153 	TAILQ_HEAD(, ehci_xfer) sc_intrhead;
    154 
    155 	ehci_soft_qh_t *sc_freeqhs;
    156 	ehci_soft_qtd_t *sc_freeqtds;
    157 	LIST_HEAD(sc_freeitds, ehci_soft_itd) sc_freeitds;
    158 
    159 	int sc_noport;
    160 	u_int8_t sc_hasppc;		/* has Port Power Control */
    161 	u_int8_t sc_addr;		/* device address */
    162 	u_int8_t sc_conf;		/* device configuration */
    163 	usbd_xfer_handle sc_intrxfer;
    164 	char sc_isreset[EHCI_MAX_PORTS];
    165 	char sc_softwake;
    166 	kcondvar_t sc_softwake_cv;
    167 
    168 	u_int32_t sc_eintrs;
    169 	ehci_soft_qh_t *sc_async_head;
    170 
    171 	pool_cache_t sc_xferpool;	/* free xfer pool */
    172 
    173 	struct callout sc_tmo_intrlist;
    174 
    175 	device_t sc_child; /* /dev/usb# device */
    176 	char sc_dying;
    177 	struct usb_dma_reserve sc_dma_reserve;
    178 
    179 	void (*sc_vendor_init)(struct ehci_softc *);
    180 	int (*sc_vendor_port_status)(struct ehci_softc *, uint32_t, int);
    181 } ehci_softc_t;
    182 
    183 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
    184 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
    185 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
    186 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
    187 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
    188 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
    189 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    190 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    191 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    192 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    193 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    194 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    195 
    196 usbd_status	ehci_init(ehci_softc_t *);
    197 int		ehci_intr(void *);
    198 int		ehci_detach(ehci_softc_t *, int);
    199 int		ehci_activate(device_t, enum devact);
    200 void		ehci_childdet(device_t, device_t);
    201 bool		ehci_suspend(device_t, const pmf_qual_t *);
    202 bool		ehci_resume(device_t, const pmf_qual_t *);
    203 bool		ehci_shutdown(device_t, int);
    204 
    205 #endif /* _EHCIVAR_H_ */
    206