xref: /freebsd-12.1/sys/dev/if_ndis/if_ndisvar.h (revision df57947f)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 2003
5  *	Bill Paul <[email protected]>.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Bill Paul.
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
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 #define	NDISUSB_CONFIG_NO			0
119 #define	NDISUSB_IFACE_INDEX			0
120 /* XXX at USB2 there's no USBD_NO_TIMEOUT macro anymore  */
121 #define	NDISUSB_NO_TIMEOUT			0
122 #define	NDISUSB_INTR_TIMEOUT			1000
123 #define	NDISUSB_TX_TIMEOUT			10000
124 struct ndisusb_xfer;
125 struct ndisusb_ep {
126 	struct usb_xfer	*ne_xfer[1];
127 	list_entry		ne_active;
128 	list_entry		ne_pending;
129 	kspin_lock		ne_lock;
130 	uint8_t			ne_dirin;
131 };
132 struct ndisusb_xfer {
133 	struct ndisusb_ep	*nx_ep;
134 	void			*nx_priv;
135 	uint8_t			*nx_urbbuf;
136 	uint32_t		nx_urbactlen;
137 	uint32_t		nx_urblen;
138 	uint8_t			nx_shortxfer;
139 	list_entry		nx_next;
140 };
141 struct ndisusb_xferdone {
142 	struct ndisusb_xfer	*nd_xfer;
143 	usb_error_t		nd_status;
144 	list_entry		nd_donelist;
145 };
146 
147 struct ndisusb_task {
148 	unsigned		nt_type;
149 #define	NDISUSB_TASK_TSTART	0
150 #define	NDISUSB_TASK_IRPCANCEL	1
151 #define	NDISUSB_TASK_VENDOR	2
152 	void			*nt_ctx;
153 	list_entry		nt_tasklist;
154 };
155 
156 struct ndis_softc {
157 #define        NDISUSB_GET_IFNET(ndis_softc) ( (ndis_softc)->ndis_80211 ? NULL : (ndis_softc)->ifp )
158 	u_int			ndis_80211:1,
159 				ndis_link:1,
160 				ndis_running:1;
161 	union {
162 		struct {		/* Ethernet */
163 			struct ifnet		*ifp;
164 			struct ifmedia		ifmedia;
165 			int			ndis_if_flags;
166 		};
167 		struct {		/* Wireless */
168 			struct ieee80211com	ndis_ic;
169 			struct callout		ndis_scan_callout;
170 			int	(*ndis_newstate)(struct ieee80211com *,
171 				    enum ieee80211_state, int);
172 		};
173 	};
174 	u_long			ndis_hwassist;
175 	uint32_t		ndis_v4tx;
176 	uint32_t		ndis_v4rx;
177 	bus_space_handle_t	ndis_bhandle;
178 	bus_space_tag_t		ndis_btag;
179 	void			*ndis_intrhand;
180 	struct resource		*ndis_irq;
181 	struct resource		*ndis_res;
182 	struct resource		*ndis_res_io;
183 	int			ndis_io_rid;
184 	struct resource		*ndis_res_mem;
185 	int			ndis_mem_rid;
186 	struct resource		*ndis_res_altmem;
187 	int			ndis_altmem_rid;
188 	struct resource		*ndis_res_am;	/* attribute mem (pccard) */
189 	int			ndis_am_rid;
190 	struct resource		*ndis_res_cm;	/* common mem (pccard) */
191 	struct resource_list	ndis_rl;
192 	int			ndis_rescnt;
193 	struct mtx		ndis_mtx;
194 	uint8_t			ndis_irql;
195 	device_t		ndis_dev;
196 	int			ndis_unit;
197 	ndis_miniport_block	*ndis_block;
198 	ndis_miniport_characteristics	*ndis_chars;
199 	interface_type		ndis_type;
200 	struct callout		ndis_stat_callout;
201 	int			ndis_maxpkts;
202 	ndis_oid		*ndis_oids;
203 	int			ndis_oidcnt;
204 	int			ndis_txidx;
205 	int			ndis_txpending;
206 	ndis_packet		**ndis_txarray;
207 	ndis_handle		ndis_txpool;
208 	int			ndis_sc;
209 	ndis_cfg		*ndis_regvals;
210 	struct nch		ndis_cfglist_head;
211 	uint32_t		ndis_sts;
212 	uint32_t		ndis_filter;
213 	int			ndis_skip;
214 	int			ndis_devidx;
215 	interface_type		ndis_iftype;
216 	driver_object		*ndis_dobj;
217 	io_workitem		*ndis_tickitem;
218 	io_workitem		*ndis_startitem;
219 	io_workitem		*ndis_resetitem;
220 	io_workitem		*ndis_inputitem;
221 	kdpc			ndis_rxdpc;
222 	bus_dma_tag_t		ndis_parent_tag;
223 	list_entry		ndis_shlist;
224 	bus_dma_tag_t		ndis_mtag;
225 	bus_dma_tag_t		ndis_ttag;
226 	bus_dmamap_t		*ndis_mmaps;
227 	bus_dmamap_t		*ndis_tmaps;
228 	int			ndis_mmapcnt;
229 	struct ndis_evt		ndis_evt[NDIS_EVENTS];
230 	int			ndis_evtpidx;
231 	int			ndis_evtcidx;
232 	struct mbufq		ndis_rxqueue;
233 	kspin_lock		ndis_rxlock;
234 
235 	int			ndis_tx_timer;
236 	int			ndis_hang_timer;
237 
238 	struct usb_device	*ndisusb_dev;
239 	struct mtx		ndisusb_mtx;
240 	struct ndisusb_ep	ndisusb_dread_ep;
241 	struct ndisusb_ep	ndisusb_dwrite_ep;
242 #define	NDISUSB_GET_ENDPT(addr) \
243 	((UE_GET_DIR(addr) >> 7) | (UE_GET_ADDR(addr) << 1))
244 #define	NDISUSB_ENDPT_MAX	((UE_ADDR + 1) * 2)
245 	struct ndisusb_ep	ndisusb_ep[NDISUSB_ENDPT_MAX];
246 	io_workitem		*ndisusb_xferdoneitem;
247 	list_entry		ndisusb_xferdonelist;
248 	kspin_lock		ndisusb_xferdonelock;
249 	io_workitem		*ndisusb_taskitem;
250 	list_entry		ndisusb_tasklist;
251 	kspin_lock		ndisusb_tasklock;
252 	int			ndisusb_status;
253 #define NDISUSB_STATUS_DETACH	0x1
254 #define	NDISUSB_STATUS_SETUP_EP	0x2
255 };
256 
257 #define	NDIS_LOCK(_sc)		mtx_lock(&(_sc)->ndis_mtx)
258 #define	NDIS_UNLOCK(_sc)	mtx_unlock(&(_sc)->ndis_mtx)
259 #define	NDIS_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->ndis_mtx, t)
260 #define	NDISUSB_LOCK(_sc)	mtx_lock(&(_sc)->ndisusb_mtx)
261 #define	NDISUSB_UNLOCK(_sc)	mtx_unlock(&(_sc)->ndisusb_mtx)
262 #define	NDISUSB_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->ndisusb_mtx, t)
263 
264