1139749Simp/*-
2123474Swpaul * Copyright (c) 2003
3123474Swpaul *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
4123474Swpaul *
5123474Swpaul * Redistribution and use in source and binary forms, with or without
6123474Swpaul * modification, are permitted provided that the following conditions
7123474Swpaul * are met:
8123474Swpaul * 1. Redistributions of source code must retain the above copyright
9123474Swpaul *    notice, this list of conditions and the following disclaimer.
10123474Swpaul * 2. Redistributions in binary form must reproduce the above copyright
11123474Swpaul *    notice, this list of conditions and the following disclaimer in the
12123474Swpaul *    documentation and/or other materials provided with the distribution.
13123474Swpaul * 3. All advertising materials mentioning features or use of this software
14123474Swpaul *    must display the following acknowledgement:
15123474Swpaul *	This product includes software developed by Bill Paul.
16123474Swpaul * 4. Neither the name of the author nor the names of any co-contributors
17123474Swpaul *    may be used to endorse or promote products derived from this software
18123474Swpaul *    without specific prior written permission.
19123474Swpaul *
20123474Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21123474Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22123474Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23123474Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24123474Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25123474Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26123474Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27123474Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28123474Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29123474Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30123474Swpaul * THE POSSIBILITY OF SUCH DAMAGE.
31123474Swpaul *
32123474Swpaul * $FreeBSD$
33123474Swpaul */
34123474Swpaul
35128229Swpaul#define NDIS_DEFAULT_NODENAME	"FreeBSD NDIS node"
36128229Swpaul#define NDIS_NODENAME_LEN	32
37128229Swpaul
38151207Swpaul/* For setting/getting OIDs from userspace. */
39151207Swpaul
40151207Swpaulstruct ndis_oid_data {
41151207Swpaul	uint32_t		oid;
42151207Swpaul	uint32_t		len;
43151207Swpaul#ifdef notdef
44151207Swpaul	uint8_t			data[1];
45151207Swpaul#endif
46151207Swpaul};
47151207Swpaul
48126706Swpaulstruct ndis_pci_type {
49123474Swpaul	uint16_t		ndis_vid;
50123474Swpaul	uint16_t		ndis_did;
51123620Swpaul	uint32_t		ndis_subsys;
52123474Swpaul	char			*ndis_name;
53123474Swpaul};
54123474Swpaul
55126706Swpaulstruct ndis_pccard_type {
56126706Swpaul	const char		*ndis_vid;
57126706Swpaul	const char		*ndis_did;
58126706Swpaul	char			*ndis_name;
59126706Swpaul};
60126706Swpaul
61186507Sweongyostruct ndis_usb_type {
62186507Sweongyo	uint16_t		ndis_vid;
63186507Sweongyo	uint16_t		ndis_did;
64186507Sweongyo	char			*ndis_name;
65186507Sweongyo};
66186507Sweongyo
67123474Swpaulstruct ndis_shmem {
68151207Swpaul	list_entry		ndis_list;
69123474Swpaul	bus_dma_tag_t		ndis_stag;
70123474Swpaul	bus_dmamap_t		ndis_smap;
71123474Swpaul	void			*ndis_saddr;
72145895Swpaul	ndis_physaddr		ndis_paddr;
73123474Swpaul};
74123474Swpaul
75123474Swpaulstruct ndis_cfglist {
76123474Swpaul	ndis_cfg		ndis_cfg;
77151207Swpaul	struct sysctl_oid	*ndis_oid;
78123474Swpaul        TAILQ_ENTRY(ndis_cfglist)	link;
79123474Swpaul};
80123474Swpaul
81151207Swpaul/*
82151207Swpaul * Helper struct to make parsing information
83151207Swpaul * elements easier.
84151207Swpaul */
85151207Swpaulstruct ndis_ie {
86151207Swpaul	uint8_t		ni_oui[3];
87151207Swpaul	uint8_t		ni_val;
88151207Swpaul};
89151207Swpaul
90123474SwpaulTAILQ_HEAD(nch, ndis_cfglist);
91123474Swpaul
92151207Swpaul#define NDIS_INITIALIZED(sc)	(sc->ndis_block->nmb_devicectx != NULL)
93131750Swpaul
94151451Swpaul#define NDIS_TXPKTS 64
95123474Swpaul#define NDIS_INC(x)		\
96183587Sweongyo	(x)->ndis_txidx = ((x)->ndis_txidx + 1) % (x)->ndis_maxpkts
97123474Swpaul
98151207Swpaul
99151207Swpaul#define NDIS_EVENTS 4
100151207Swpaul#define NDIS_EVTINC(x)	(x) = ((x) + 1) % NDIS_EVENTS
101151207Swpaul
102151207Swpaulstruct ndis_evt {
103151207Swpaul	uint32_t		ne_sts;
104151207Swpaul	uint32_t		ne_len;
105151207Swpaul	char			*ne_buf;
106151207Swpaul};
107151207Swpaul
108178354Ssamstruct ndis_vap {
109178354Ssam	struct ieee80211vap	vap;
110178354Ssam
111178354Ssam	int			(*newstate)(struct ieee80211vap *,
112178354Ssam				    enum ieee80211_state, int);
113178354Ssam};
114178354Ssam#define	NDIS_VAP(vap)	((struct ndis_vap *)(vap))
115178354Ssam
116189488Sweongyo#define	NDISUSB_CONFIG_NO			0
117186507Sweongyo#define	NDISUSB_IFACE_INDEX			0
118189488Sweongyo/* XXX at USB2 there's no USBD_NO_TIMEOUT macro anymore  */
119189488Sweongyo#define	NDISUSB_NO_TIMEOUT			0
120186507Sweongyo#define	NDISUSB_INTR_TIMEOUT			1000
121186507Sweongyo#define	NDISUSB_TX_TIMEOUT			10000
122189488Sweongyostruct ndisusb_xfer;
123189488Sweongyostruct ndisusb_ep {
124192984Sthompsa	struct usb_xfer	*ne_xfer[1];
125189488Sweongyo	list_entry		ne_active;
126189488Sweongyo	list_entry		ne_pending;
127189488Sweongyo	kspin_lock		ne_lock;
128189488Sweongyo	uint8_t			ne_dirin;
129189488Sweongyo};
130186507Sweongyostruct ndisusb_xfer {
131189488Sweongyo	struct ndisusb_ep	*nx_ep;
132189488Sweongyo	void			*nx_priv;
133189488Sweongyo	uint8_t			*nx_urbbuf;
134189488Sweongyo	uint32_t		nx_urbactlen;
135189488Sweongyo	uint32_t		nx_urblen;
136189488Sweongyo	uint8_t			nx_shortxfer;
137189488Sweongyo	list_entry		nx_next;
138186507Sweongyo};
139189488Sweongyostruct ndisusb_xferdone {
140189488Sweongyo	struct ndisusb_xfer	*nd_xfer;
141193045Sthompsa	usb_error_t		nd_status;
142189488Sweongyo	list_entry		nd_donelist;
143189488Sweongyo};
144186507Sweongyo
145189719Sweongyostruct ndisusb_task {
146189719Sweongyo	unsigned		nt_type;
147189719Sweongyo#define	NDISUSB_TASK_TSTART	0
148189719Sweongyo#define	NDISUSB_TASK_IRPCANCEL	1
149189950Sweongyo#define	NDISUSB_TASK_VENDOR	2
150189719Sweongyo	void			*nt_ctx;
151189719Sweongyo	list_entry		nt_tasklist;
152189719Sweongyo};
153189719Sweongyo
154123474Swpaulstruct ndis_softc {
155147256Sbrooks	struct ifnet		*ifp;
156123474Swpaul	struct ifmedia		ifmedia;	/* media info */
157124821Swpaul	u_long			ndis_hwassist;
158124821Swpaul	uint32_t		ndis_v4tx;
159124821Swpaul	uint32_t		ndis_v4rx;
160123474Swpaul	bus_space_handle_t	ndis_bhandle;
161123474Swpaul	bus_space_tag_t		ndis_btag;
162123474Swpaul	void			*ndis_intrhand;
163123474Swpaul	struct resource		*ndis_irq;
164123474Swpaul	struct resource		*ndis_res;
165123474Swpaul	struct resource		*ndis_res_io;
166123474Swpaul	int			ndis_io_rid;
167123474Swpaul	struct resource		*ndis_res_mem;
168123474Swpaul	int			ndis_mem_rid;
169123474Swpaul	struct resource		*ndis_res_altmem;
170123474Swpaul	int			ndis_altmem_rid;
171123474Swpaul	struct resource		*ndis_res_am;	/* attribute mem (pccard) */
172131953Swpaul	int			ndis_am_rid;
173123474Swpaul	struct resource		*ndis_res_cm;	/* common mem (pccard) */
174131953Swpaul	struct resource_list	ndis_rl;
175123474Swpaul	int			ndis_rescnt;
176179723Scokane	struct mtx		ndis_mtx;
177151207Swpaul	uint8_t			ndis_irql;
178123474Swpaul	device_t		ndis_dev;
179123474Swpaul	int			ndis_unit;
180141524Swpaul	ndis_miniport_block	*ndis_block;
181141524Swpaul	ndis_miniport_characteristics	*ndis_chars;
182123474Swpaul	interface_type		ndis_type;
183191746Sthompsa	struct callout		ndis_scan_callout;
184178286Scokane	struct callout		ndis_stat_callout;
185123474Swpaul	int			ndis_maxpkts;
186123474Swpaul	ndis_oid		*ndis_oids;
187123474Swpaul	int			ndis_oidcnt;
188123474Swpaul	int			ndis_txidx;
189123474Swpaul	int			ndis_txpending;
190123474Swpaul	ndis_packet		**ndis_txarray;
191141963Swpaul	ndis_handle		ndis_txpool;
192123474Swpaul	int			ndis_sc;
193123474Swpaul	ndis_cfg		*ndis_regvals;
194123474Swpaul	struct nch		ndis_cfglist_head;
195123695Swpaul	int			ndis_80211;
196123695Swpaul	int			ndis_link;
197151207Swpaul	uint32_t		ndis_sts;
198123695Swpaul	uint32_t		ndis_filter;
199123695Swpaul	int			ndis_if_flags;
200125076Swpaul	int			ndis_skip;
201123474Swpaul
202123620Swpaul	int			ndis_devidx;
203123474Swpaul	interface_type		ndis_iftype;
204145485Swpaul	driver_object		*ndis_dobj;
205151207Swpaul	io_workitem		*ndis_tickitem;
206151207Swpaul	io_workitem		*ndis_startitem;
207151207Swpaul	io_workitem		*ndis_resetitem;
208151451Swpaul	io_workitem		*ndis_inputitem;
209146230Swpaul	kdpc			ndis_rxdpc;
210123474Swpaul	bus_dma_tag_t		ndis_parent_tag;
211151207Swpaul	list_entry		ndis_shlist;
212123474Swpaul	bus_dma_tag_t		ndis_mtag;
213123474Swpaul	bus_dma_tag_t		ndis_ttag;
214123474Swpaul	bus_dmamap_t		*ndis_mmaps;
215123474Swpaul	bus_dmamap_t		*ndis_tmaps;
216123474Swpaul	int			ndis_mmapcnt;
217151207Swpaul	struct ndis_evt		ndis_evt[NDIS_EVENTS];
218151207Swpaul	int			ndis_evtpidx;
219151207Swpaul	int			ndis_evtcidx;
220151451Swpaul	struct ifqueue		ndis_rxqueue;
221151451Swpaul	kspin_lock		ndis_rxlock;
222171390Sthompsa
223171390Sthompsa	int			(*ndis_newstate)(struct ieee80211com *,
224171390Sthompsa				    enum ieee80211_state, int);
225179498Scokane	int			ndis_tx_timer;
226179498Scokane	int			ndis_hang_timer;
227186507Sweongyo
228192984Sthompsa	struct usb_device	*ndisusb_dev;
229189719Sweongyo	struct mtx		ndisusb_mtx;
230189950Sweongyo	struct ndisusb_ep	ndisusb_dread_ep;
231189950Sweongyo	struct ndisusb_ep	ndisusb_dwrite_ep;
232189488Sweongyo#define	NDISUSB_GET_ENDPT(addr) \
233189488Sweongyo	((UE_GET_DIR(addr) >> 7) | (UE_GET_ADDR(addr) << 1))
234189488Sweongyo#define	NDISUSB_ENDPT_MAX	((UE_ADDR + 1) * 2)
235189488Sweongyo	struct ndisusb_ep	ndisusb_ep[NDISUSB_ENDPT_MAX];
236189488Sweongyo	io_workitem		*ndisusb_xferdoneitem;
237189488Sweongyo	list_entry		ndisusb_xferdonelist;
238189488Sweongyo	kspin_lock		ndisusb_xferdonelock;
239189719Sweongyo	io_workitem		*ndisusb_taskitem;
240189719Sweongyo	list_entry		ndisusb_tasklist;
241189719Sweongyo	kspin_lock		ndisusb_tasklock;
242186507Sweongyo	int			ndisusb_status;
243186507Sweongyo#define NDISUSB_STATUS_DETACH	0x1
244189950Sweongyo#define	NDISUSB_STATUS_SETUP_EP	0x2
245123474Swpaul};
246123474Swpaul
247189488Sweongyo#define	NDIS_LOCK(_sc)		mtx_lock(&(_sc)->ndis_mtx)
248189488Sweongyo#define	NDIS_UNLOCK(_sc)	mtx_unlock(&(_sc)->ndis_mtx)
249189488Sweongyo#define	NDIS_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->ndis_mtx, t)
250189719Sweongyo#define	NDISUSB_LOCK(_sc)	mtx_lock(&(_sc)->ndisusb_mtx)
251189719Sweongyo#define	NDISUSB_UNLOCK(_sc)	mtx_unlock(&(_sc)->ndisusb_mtx)
252189719Sweongyo#define	NDISUSB_LOCK_ASSERT(_sc, t)	mtx_assert(&(_sc)->ndisusb_mtx, t)
253189719Sweongyo
254