Sync ndis(4) and tools with FreeBSD and hook it all back into the build.
[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 #define NDIS_DEFAULT_NODENAME   "FreeBSD NDIS node"
36 #define NDIS_NODENAME_LEN       32
37
38 /* For setting/getting OIDs from userspace. */
39
40 struct ndis_oid_data {
41         uint32_t                oid;
42         uint32_t                len;
43 #ifdef notdef
44         uint8_t                 data[1];
45 #endif
46 };
47
48 struct ndis_pci_type {
49         uint16_t                ndis_vid;
50         uint16_t                ndis_did;
51         uint32_t                ndis_subsys;
52         char                    *ndis_name;
53 };
54
55 struct ndis_pccard_type {
56         const char              *ndis_vid;
57         const char              *ndis_did;
58         char                    *ndis_name;
59 };
60
61 struct ndis_usb_type {
62         uint16_t                ndis_vid;
63         uint16_t                ndis_did;
64         char                    *ndis_name;
65 };
66
67 struct ndis_shmem {
68         list_entry              ndis_list;
69         bus_dma_tag_t           ndis_stag;
70         bus_dmamap_t            ndis_smap;
71         void                    *ndis_saddr;
72         ndis_physaddr           ndis_paddr;
73 };
74
75 struct ndis_cfglist {
76         ndis_cfg                ndis_cfg;
77         struct sysctl_oid       *ndis_oid;
78         TAILQ_ENTRY(ndis_cfglist)       link;
79 };
80
81 /*
82  * Helper struct to make parsing information
83  * elements easier.
84  */
85 struct ndis_ie {
86         uint8_t         ni_oui[3];
87         uint8_t         ni_val;
88 };
89
90 TAILQ_HEAD(nch, ndis_cfglist);
91
92 #define NDIS_INITIALIZED(sc)    (sc->ndis_block->nmb_devicectx != NULL)
93
94 #define NDIS_TXPKTS 64
95 #define NDIS_INC(x)             \
96         (x)->ndis_txidx = ((x)->ndis_txidx + 1) % (x)->ndis_maxpkts
97
98
99 #define NDIS_EVENTS 4
100 #define NDIS_EVTINC(x)  (x) = ((x) + 1) % NDIS_EVENTS
101
102 struct ndis_evt {
103         uint32_t                ne_sts;
104         uint32_t                ne_len;
105         char                    *ne_buf;
106 };
107
108 struct ndis_vap {
109         struct ieee80211vap     vap;
110
111         int                     (*newstate)(struct ieee80211vap *,
112                                     enum ieee80211_state, int);
113 };
114 #define NDIS_VAP(vap)   ((struct ndis_vap *)(vap))
115
116 #define NDISUSB_CONFIG_NO                       1
117 #define NDISUSB_IFACE_INDEX                     0
118 #define NDISUSB_INTR_TIMEOUT                    1000
119 #define NDISUSB_TX_TIMEOUT                      10000
120 struct ndisusb_xfer {
121         usbd_xfer_handle        nx_xfer;
122         usbd_private_handle     nx_priv;
123         usbd_status             nx_status;
124         list_entry              nx_xferlist;
125 };
126
127 struct ndis_softc {
128         struct ifnet            *ifp;
129         struct ifmedia          ifmedia;        /* media info */
130         u_long                  ndis_hwassist;
131         uint32_t                ndis_v4tx;
132         uint32_t                ndis_v4rx;
133         bus_space_handle_t      ndis_bhandle;
134         bus_space_tag_t         ndis_btag;
135         void                    *ndis_intrhand;
136         struct resource         *ndis_irq;
137         struct resource         *ndis_res;
138         struct resource         *ndis_res_io;
139         int                     ndis_io_rid;
140         struct resource         *ndis_res_mem;
141         int                     ndis_mem_rid;
142         struct resource         *ndis_res_altmem;
143         int                     ndis_altmem_rid;
144         struct resource         *ndis_res_am;   /* attribute mem (pccard) */
145         int                     ndis_am_rid;
146         struct resource         *ndis_res_cm;   /* common mem (pccard) */
147         struct resource_list    ndis_rl;
148         int                     ndis_rescnt;
149         struct lock             ndis_lock;
150         uint8_t                 ndis_irql;
151         device_t                ndis_dev;
152         int                     ndis_unit;
153         ndis_miniport_block     *ndis_block;
154         ndis_miniport_characteristics   *ndis_chars;
155         interface_type          ndis_type;
156         struct callout          ndis_scan_callout;
157         struct callout          ndis_stat_callout;
158         int                     ndis_maxpkts;
159         ndis_oid                *ndis_oids;
160         int                     ndis_oidcnt;
161         int                     ndis_txidx;
162         int                     ndis_txpending;
163         ndis_packet             **ndis_txarray;
164         ndis_handle             ndis_txpool;
165         int                     ndis_sc;
166         ndis_cfg                *ndis_regvals;
167         struct nch              ndis_cfglist_head;
168         int                     ndis_80211;
169         int                     ndis_link;
170         uint32_t                ndis_sts;
171         uint32_t                ndis_filter;
172         int                     ndis_if_flags;
173         int                     ndis_skip;
174
175 #if __FreeBSD_version < 502113
176         struct sysctl_ctx_list  ndis_ctx;
177         struct sysctl_oid       *ndis_tree;
178 #endif
179         int                     ndis_devidx;
180         interface_type          ndis_iftype;
181         driver_object           *ndis_dobj;
182         io_workitem             *ndis_tickitem;
183         io_workitem             *ndis_startitem;
184         io_workitem             *ndis_resetitem;
185         io_workitem             *ndis_inputitem;
186         kdpc                    ndis_rxdpc;
187         bus_dma_tag_t           ndis_parent_tag;
188         list_entry              ndis_shlist;
189         bus_dma_tag_t           ndis_mtag;
190         bus_dma_tag_t           ndis_ttag;
191         bus_dmamap_t            *ndis_mmaps;
192         bus_dmamap_t            *ndis_tmaps;
193         int                     ndis_mmapcnt;
194         struct ndis_evt         ndis_evt[NDIS_EVENTS];
195         int                     ndis_evtpidx;
196         int                     ndis_evtcidx;
197         struct ifqueue          ndis_rxqueue;
198         kspin_lock              ndis_rxlock;
199
200         int                     (*ndis_newstate)(struct ieee80211com *,
201                                     enum ieee80211_state, int);
202         int                     ndis_tx_timer;
203         int                     ndis_hang_timer;
204
205         io_workitem             *ndisusb_xferitem;
206         list_entry              ndisusb_xferlist;
207         kspin_lock              ndisusb_xferlock;
208 #define NDISUSB_ENDPT_BOUT      0
209 #define NDISUSB_ENDPT_BIN       1
210 #define NDISUSB_ENDPT_IIN       2
211 #define NDISUSB_ENDPT_IOUT      3
212 #define NDISUSB_ENDPT_MAX       4
213         usbd_pipe_handle        ndisusb_ep[NDISUSB_ENDPT_MAX];
214         char                    *ndisusb_iin_buf;
215         int                     ndisusb_status;
216 #define NDISUSB_STATUS_DETACH   0x1
217 };
218
219 #define NDISMTX_LOCK(_sc)       lockmgr(&(_sc)->ndis_lock, LK_EXCLUSIVE)
220 #define NDISMTX_UNLOCK(_sc)     lockmgr(&(_sc)->ndis_lock, LK_RELEASE)
221 #define NDISUSB_LOCK(_sc)       get_mplock()
222 #define NDISUSB_UNLOCK(_sc)     rel_mplock()
223 #define NDIS_LOCK(_sc) do {                                             \
224         if ((_sc)->ndis_iftype == PNPBus)                               \
225                 NDISUSB_LOCK(_sc);                                      \
226         NDISMTX_LOCK(_sc);                                              \
227 } while (0)
228 #define NDIS_UNLOCK(_sc) do {                                           \
229         if ((_sc)->ndis_iftype == PNPBus)                               \
230                 NDISUSB_UNLOCK(_sc);                                    \
231         NDISMTX_UNLOCK(_sc);                                            \
232 } while (0)