]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/usb/ehcivar.h
reclaim node reference when ieee80211_encap fails
[FreeBSD/FreeBSD.git] / sys / dev / usb / ehcivar.h
1 /*      $NetBSD: ehcivar.h,v 1.12 2001/12/31 12:16:57 augustss Exp $    */
2 /*      $FreeBSD$       */
3
4 /*-
5  * Copyright (c) 2001 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net).
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39
40 typedef struct ehci_soft_qtd {
41         ehci_qtd_t qtd;
42         struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
43         ehci_physaddr_t physaddr;
44         usbd_xfer_handle xfer;
45         LIST_ENTRY(ehci_soft_qtd) hnext;
46         u_int16_t len;
47 } ehci_soft_qtd_t;
48 #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_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_qh *prev;
55         struct ehci_soft_qtd *sqtd;
56         ehci_physaddr_t physaddr;
57         int islot;              /* Interrupt list slot. */
58 } ehci_soft_qh_t;
59 #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
60 #define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE)
61
62 struct ehci_xfer {
63         struct usbd_xfer xfer;
64         struct usb_task abort_task;
65         LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
66         ehci_soft_qtd_t *sqtdstart;
67         ehci_soft_qtd_t *sqtdend;
68         u_int32_t ehci_xfer_flags;
69 #ifdef DIAGNOSTIC
70         int isdone;
71 #endif
72 };
73 #define EHCI_XFER_ABORTING      0x0001  /* xfer is aborting. */
74 #define EHCI_XFER_ABORTWAIT     0x0002  /* abort completion is being awaited. */
75
76 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
77
78 /*
79  * Information about an entry in the interrupt list.
80  */
81 struct ehci_soft_islot {
82         ehci_soft_qh_t *sqh;            /* Queue Head. */
83 };
84
85 #define EHCI_FRAMELIST_MAXCOUNT 1024
86 #define EHCI_IPOLLRATES         8       /* Poll rates (1ms, 2, 4, 8 ... 128) */
87 #define EHCI_INTRQHS            ((1 << EHCI_IPOLLRATES) - 1)
88 #define EHCI_IQHIDX(lev, pos)   \
89     ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
90 #define EHCI_ILEV_IVAL(lev)     (1 << (lev))
91
92 #define EHCI_HASH_SIZE 128
93 #define EHCI_COMPANION_MAX 8
94
95 #define EHCI_SCFLG_DONEINIT     0x0001  /* ehci_init() has been called. */
96
97 typedef struct ehci_softc {
98         struct usbd_bus sc_bus;         /* base device */
99         int sc_flags;
100         bus_space_tag_t iot;
101         bus_space_handle_t ioh;
102         bus_size_t sc_size;
103 #if defined(__FreeBSD__)
104         void *ih;
105
106         struct resource *io_res;
107         struct resource *irq_res;
108 #endif
109         u_int sc_offs;                  /* offset to operational regs */
110
111         char sc_vendor[16];             /* vendor string for root hub */
112         int sc_id_vendor;               /* vendor ID for root hub */
113
114         u_int32_t sc_cmd;               /* shadow of cmd reg during suspend */
115 #if defined(__NetBSD__) || defined(__OpenBSD__)
116         void *sc_powerhook;             /* cookie from power hook */
117         void *sc_shutdownhook;          /* cookie from shutdown hook */
118 #endif
119
120         u_int sc_ncomp;
121         u_int sc_npcomp;
122         struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
123
124         usb_dma_t sc_fldma;
125         ehci_link_t *sc_flist;
126         u_int sc_flsize;
127
128         struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
129
130         LIST_HEAD(, ehci_xfer) sc_intrhead;
131
132         ehci_soft_qh_t *sc_freeqhs;
133         ehci_soft_qtd_t *sc_freeqtds;
134
135         int sc_noport;
136         u_int8_t sc_addr;               /* device address */
137         u_int8_t sc_conf;               /* device configuration */
138         usbd_xfer_handle sc_intrxfer;
139         char sc_isreset;
140 #ifdef USB_USE_SOFTINTR
141         char sc_softwake;
142 #endif /* USB_USE_SOFTINTR */
143
144         u_int32_t sc_eintrs;
145         ehci_soft_qh_t *sc_async_head;
146
147         SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
148
149         struct lock sc_doorbell_lock;
150
151         usb_callout_t sc_tmo_pcd;
152
153 #if defined(__NetBSD__) || defined(__OpenBSD__)
154         device_ptr_t sc_child;          /* /dev/usb# device */
155 #endif
156         char sc_dying;
157 } ehci_softc_t;
158
159 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
160 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
161 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
162 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
163 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
164 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
165 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
166 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
167 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
168 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
169 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
170 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
171
172 usbd_status     ehci_init(ehci_softc_t *);
173 int             ehci_intr(void *);
174 int             ehci_detach(ehci_softc_t *, int);
175 #if defined(__NetBSD__) || defined(__OpenBSD__)
176 int             ehci_activate(device_ptr_t, enum devact);
177 #endif
178 void            ehci_power(int state, void *priv);
179 void            ehci_shutdown(void *v);
180
181 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
182