d2fcf016078626e9efaa471d2c6f4e15967d3311
[dragonfly.git] / sys / dev / netif / ndis / if_ndisvar.h
1 /*-
2  * Copyright (c) 2003
3  *      Bill Paul <wpaul@windriver.com>.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Bill Paul.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30  * THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * $FreeBSD: src/sys/dev/if_ndis/if_ndisvar.h,v 1.39 2009/05/02 15:14:18 thompsa Exp $
33  */
34
35 #include "use_usb4bsd.h"
36
37 #define NDIS_DEFAULT_NODENAME   "FreeBSD NDIS node"
38 #define NDIS_NODENAME_LEN       32
39
40 /* For setting/getting OIDs from userspace. */
41
42 struct ndis_oid_data {
43         uint32_t                oid;
44         uint32_t                len;
45 #ifdef notdef
46         uint8_t                 data[1];
47 #endif
48 };
49
50 struct ndis_pci_type {
51         uint16_t                ndis_vid;
52         uint16_t                ndis_did;
53         uint32_t                ndis_subsys;
54         char                    *ndis_name;
55 };
56
57 struct ndis_pccard_type {
58         const char              *ndis_vid;
59         const char              *ndis_did;
60         char                    *ndis_name;
61 };
62
63 struct ndis_usb_type {
64         uint16_t                ndis_vid;
65         uint16_t                ndis_did;
66         char                    *ndis_name;
67 };
68
69 struct ndis_shmem {
70         list_entry              ndis_list;
71         bus_dma_tag_t           ndis_stag;
72         bus_dmamap_t            ndis_smap;
73         void                    *ndis_saddr;
74         ndis_physaddr           ndis_paddr;
75 };
76
77 struct ndis_cfglist {
78         ndis_cfg                ndis_cfg;
79         struct sysctl_oid       *ndis_oid;
80         TAILQ_ENTRY(ndis_cfglist)       link;
81 };
82
83 /*
84  * Helper struct to make parsing information
85  * elements easier.
86  */
87 struct ndis_ie {
88         uint8_t         ni_oui[3];
89         uint8_t         ni_val;
90 };
91
92 TAILQ_HEAD(nch, ndis_cfglist);
93
94 #define NDIS_INITIALIZED(sc)    (sc->ndis_block->nmb_devicectx != NULL)
95
96 #define NDIS_TXPKTS 64
97 #define NDIS_INC(x)             \
98         (x)->ndis_txidx = ((x)->ndis_txidx + 1) % (x)->ndis_maxpkts
99
100
101 #define NDIS_EVENTS 4
102 #define NDIS_EVTINC(x)  (x) = ((x) + 1) % NDIS_EVENTS
103
104 struct ndis_evt {
105         uint32_t                ne_sts;
106         uint32_t                ne_len;
107         char                    *ne_buf;
108 };
109
110 struct ndis_vap {
111         struct ieee80211vap     vap;
112
113         int                     (*newstate)(struct ieee80211vap *,
114                                     enum ieee80211_state, int);
115 };
116 #define NDIS_VAP(vap)   ((struct ndis_vap *)(vap))
117
118 #if NUSB4BSD > 0
119 #define NDISUSB_CONFIG_NO                       0
120 #define NDISUSB_IFACE_INDEX                     0
121 /* XXX at USB2 there's no USBD_NO_TIMEOUT macro anymore  */
122 #define NDISUSB_NO_TIMEOUT                      0
123 #define NDISUSB_INTR_TIMEOUT                    1000
124 #define NDISUSB_TX_TIMEOUT                      10000
125 struct ndisusb_xfer;
126 struct ndisusb_ep {
127         struct usb_xfer *ne_xfer[1];
128         list_entry              ne_active;
129         list_entry              ne_pending;
130         kspin_lock              ne_lock;
131         uint8_t                 ne_dirin;
132 };
133 struct ndisusb_xfer {
134         struct ndisusb_ep       *nx_ep;
135         void                    *nx_priv;
136         uint8_t                 *nx_urbbuf;
137         uint32_t                nx_urbactlen;
138         uint32_t                nx_urblen;
139         uint8_t                 nx_shortxfer;
140         list_entry              nx_next;
141 };
142 struct ndisusb_xferdone {
143         struct ndisusb_xfer     *nd_xfer;
144         usb_error_t             nd_status;
145         list_entry              nd_donelist;
146 };
147
148 struct ndisusb_task {
149         unsigned                nt_type;
150 #define NDISUSB_TASK_TSTART     0
151 #define NDISUSB_TASK_IRPCANCEL  1
152 #define NDISUSB_TASK_VENDOR     2
153         void                    *nt_ctx;
154         list_entry              nt_tasklist;
155 };
156 #else /* !NUSB4BSD > 0 */
157 #define NDISUSB_CONFIG_NO                       1
158 #define NDISUSB_IFACE_INDEX                     0
159 #define NDISUSB_INTR_TIMEOUT                    1000
160 #define NDISUSB_TX_TIMEOUT                      10000
161 struct ndisusb_xfer {
162         usbd_xfer_handle        nx_xfer;
163         usbd_private_handle     nx_priv;
164         usbd_status             nx_status;
165         list_entry              nx_xferlist;
166 };
167 #endif
168
169 struct ndis_softc {
170         struct ifnet            *ifp;
171         struct ifmedia          ifmedia;        /* media info */
172         u_long                  ndis_hwassist;
173         uint32_t                ndis_v4tx;
174         uint32_t                ndis_v4rx;
175         bus_space_handle_t      ndis_bhandle;
176         bus_space_tag_t         ndis_btag;
177         void                    *ndis_intrhand;
178         struct resource         *ndis_irq;
179         struct resource         *ndis_res;
180         struct resource         *ndis_res_io;
181         int                     ndis_io_rid;
182         struct resource         *ndis_res_mem;
183         int                     ndis_mem_rid;
184         struct resource         *ndis_res_altmem;
185         int                     ndis_altmem_rid;
186         struct resource         *ndis_res_am;   /* attribute mem (pccard) */
187         int                     ndis_am_rid;
188         struct resource         *ndis_res_cm;   /* common mem (pccard) */
189         struct resource_list    ndis_rl;
190         int                     ndis_rescnt;
191         struct lock             ndis_lock;
192         uint8_t                 ndis_irql;
193         device_t                ndis_dev;
194         int                     ndis_unit;
195         ndis_miniport_block     *ndis_block;
196         ndis_miniport_characteristics   *ndis_chars;
197         interface_type          ndis_type;
198         struct callout          ndis_scan_callout;
199         struct callout          ndis_stat_callout;
200         int                     ndis_maxpkts;
201         ndis_oid                *ndis_oids;
202         int                     ndis_oidcnt;
203         int                     ndis_txidx;
204         int                     ndis_txpending;
205         ndis_packet             **ndis_txarray;
206         ndis_handle             ndis_txpool;
207         int                     ndis_sc;
208         ndis_cfg                *ndis_regvals;
209         struct nch              ndis_cfglist_head;
210         int                     ndis_80211;
211         int                     ndis_link;
212         uint32_t                ndis_sts;
213         uint32_t                ndis_filter;
214         int                     ndis_if_flags;
215         int                     ndis_skip;
216
217         struct sysctl_ctx_list  ndis_ctx;
218         struct sysctl_oid       *ndis_tree;
219         int                     ndis_devidx;
220         interface_type          ndis_iftype;
221         driver_object           *ndis_dobj;
222         io_workitem             *ndis_tickitem;
223         io_workitem             *ndis_startitem;
224         io_workitem             *ndis_resetitem;
225         io_workitem             *ndis_inputitem;
226         kdpc                    ndis_rxdpc;
227         bus_dma_tag_t           ndis_parent_tag;
228         list_entry              ndis_shlist;
229         bus_dma_tag_t           ndis_mtag;
230         bus_dma_tag_t           ndis_ttag;
231         bus_dmamap_t            *ndis_mmaps;
232         bus_dmamap_t            *ndis_tmaps;
233         int                     ndis_mmapcnt;
234         struct ndis_evt         ndis_evt[NDIS_EVENTS];
235         int                     ndis_evtpidx;
236         int                     ndis_evtcidx;
237         struct ifqueue          ndis_rxqueue;
238         kspin_lock              ndis_rxlock;
239
240         int                     (*ndis_newstate)(struct ieee80211com *,
241                                     enum ieee80211_state, int);
242         int                     ndis_tx_timer;
243         int                     ndis_hang_timer;
244
245 #if NUSB4BSD > 0
246         struct usb_device       *ndisusb_dev;
247         struct lock             ndisusb_lock;
248         struct ndisusb_ep       ndisusb_dread_ep;
249         struct ndisusb_ep       ndisusb_dwrite_ep;
250 #define NDISUSB_GET_ENDPT(addr) \
251         ((UE_GET_DIR(addr) >> 7) | (UE_GET_ADDR(addr) << 1))
252 #define NDISUSB_ENDPT_MAX       ((UE_ADDR + 1) * 2)
253         struct ndisusb_ep       ndisusb_ep[NDISUSB_ENDPT_MAX];
254         io_workitem             *ndisusb_xferdoneitem;
255         list_entry              ndisusb_xferdonelist;
256         kspin_lock              ndisusb_xferdonelock;
257         io_workitem             *ndisusb_taskitem;
258         list_entry              ndisusb_tasklist;
259         kspin_lock              ndisusb_tasklock;
260         int                     ndisusb_status;
261 #define NDISUSB_STATUS_DETACH   0x1
262 #define NDISUSB_STATUS_SETUP_EP 0x2
263 };
264
265 #define NDIS_LOCK(_sc)          lockmgr(&(_sc)->ndis_lock, LK_EXCLUSIVE)
266 #define NDIS_UNLOCK(_sc)        lockmgr(&(_sc)->ndis_lock, LK_RELEASE)
267 #define NDISMTX_LOCK            NDIS_LOCK
268 #define NDISMTX_UNLOCK          NDIS_UNLOCK
269 #define NDIS_LOCK_ASSERT(_sc, t)        KKASSERT(lockstatus(&(_sc)->ndis_lock, curthread) != 0)
270 #define NDISUSB_LOCK(_sc)       lockmgr(&(_sc)->ndisusb_lock, LK_EXCLUSIVE)
271 #define NDISUSB_UNLOCK(_sc)     lockmgr(&(_sc)->ndisusb_lock, LK_RELEASE)
272 #define NDISUSB_LOCK_ASSERT(_sc, t)     KKASSERT(lockstatus(&(_sc)->ndisusb_lock, curthread) != 0)
273 #else /* !NUSB4BSD > 0 */
274         io_workitem             *ndisusb_xferitem;
275         list_entry              ndisusb_xferlist;
276         kspin_lock              ndisusb_xferlock;
277 #define NDISUSB_ENDPT_BOUT      0
278 #define NDISUSB_ENDPT_BIN       1
279 #define NDISUSB_ENDPT_IIN       2
280 #define NDISUSB_ENDPT_IOUT      3
281 #define NDISUSB_ENDPT_MAX       4
282         usbd_pipe_handle        ndisusb_ep[NDISUSB_ENDPT_MAX];
283         char                    *ndisusb_iin_buf;
284         int                     ndisusb_status;
285 #define NDISUSB_STATUS_DETACH   0x1
286 };
287
288 #define NDISMTX_LOCK(_sc)       lockmgr(&(_sc)->ndis_lock, LK_EXCLUSIVE)
289 #define NDISMTX_UNLOCK(_sc)     lockmgr(&(_sc)->ndis_lock, LK_RELEASE)
290 #define NDISUSB_LOCK(_sc)       get_mplock()
291 #define NDISUSB_UNLOCK(_sc)     rel_mplock()
292 #define NDIS_LOCK(_sc) do {                                             \
293         if ((_sc)->ndis_iftype == PNPBus)                               \
294                 NDISUSB_LOCK(_sc);                                      \
295         NDISMTX_LOCK(_sc);                                              \
296 } while (0)
297 #define NDIS_UNLOCK(_sc) do {                                           \
298         if ((_sc)->ndis_iftype == PNPBus)                               \
299                 NDISUSB_UNLOCK(_sc);                                    \
300         NDISMTX_UNLOCK(_sc);                                            \
301 } while (0)
302 #endif