xref: /freebsd/sys/dev/ipw/if_ipwvar.h (revision b1f9167f94059fd55c630891d359bcff987bd7eb)
1 /*      $FreeBSD$	*/
2 
3 /*-
4  * Copyright (c) 2004-2006
5  *      Damien Bergamini <damien.bergamini@free.fr>. 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 unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #define IPW_MAX_NSEG	1
31 
32 struct ipw_soft_bd {
33 	struct ipw_bd	*bd;
34 	int		type;
35 #define IPW_SBD_TYPE_NOASSOC	0
36 #define IPW_SBD_TYPE_COMMAND	1
37 #define IPW_SBD_TYPE_HEADER	2
38 #define IPW_SBD_TYPE_DATA	3
39 	void		*priv;
40 };
41 
42 struct ipw_soft_hdr {
43 	struct ipw_hdr			hdr;
44 	bus_dmamap_t			map;
45 	SLIST_ENTRY(ipw_soft_hdr)	next;
46 };
47 
48 struct ipw_soft_buf {
49 	struct mbuf			*m;
50 	struct ieee80211_node		*ni;
51 	bus_dmamap_t			map;
52 	SLIST_ENTRY(ipw_soft_buf)	next;
53 };
54 
55 struct ipw_rx_radiotap_header {
56 	struct ieee80211_radiotap_header wr_ihdr;
57 	uint8_t		wr_flags;
58 	uint16_t	wr_chan_freq;
59 	uint16_t	wr_chan_flags;
60 	int8_t		wr_antsignal;
61 	int8_t		wr_antnoise;
62 };
63 
64 #define IPW_RX_RADIOTAP_PRESENT						\
65 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
66 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
67 	 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |			\
68 	 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
69 
70 struct ipw_tx_radiotap_header {
71 	struct ieee80211_radiotap_header wt_ihdr;
72 	uint8_t		wt_flags;
73 	uint16_t	wt_chan_freq;
74 	uint16_t	wt_chan_flags;
75 };
76 
77 #define IPW_TX_RADIOTAP_PRESENT						\
78 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
79 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
80 
81 struct ipw_vap {
82 	struct ieee80211vap	vap;
83 
84 	int			(*newstate)(struct ieee80211vap *,
85 				    enum ieee80211_state, int);
86 };
87 #define	IPW_VAP(vap)	((struct ipw_vap *)(vap))
88 
89 struct ipw_softc {
90 	struct ifnet			*sc_ifp;
91 	device_t			sc_dev;
92 
93 	struct mtx			sc_mtx;
94 	struct task			sc_init_task;
95 	struct callout			sc_wdtimer;	/* watchdog timer */
96 
97 	uint32_t			flags;
98 #define IPW_FLAG_FW_INITED		0x0001
99 #define IPW_FLAG_INIT_LOCKED		0x0002
100 #define IPW_FLAG_HAS_RADIO_SWITCH	0x0004
101 #define	IPW_FLAG_HACK			0x0008
102 #define	IPW_FLAG_SCANNING		0x0010
103 #define	IPW_FLAG_ENABLED		0x0020
104 #define	IPW_FLAG_BUSY			0x0040
105 #define	IPW_FLAG_ASSOCIATING		0x0080
106 #define	IPW_FLAG_ASSOCIATED		0x0100
107 
108 	struct resource			*irq;
109 	struct resource			*mem;
110 	bus_space_tag_t			sc_st;
111 	bus_space_handle_t		sc_sh;
112 	void 				*sc_ih;
113 	const struct firmware		*sc_firmware;
114 
115 	int				sc_tx_timer;
116 	int				sc_scan_timer;
117 
118 	bus_dma_tag_t			parent_dmat;
119 	bus_dma_tag_t			tbd_dmat;
120 	bus_dma_tag_t			rbd_dmat;
121 	bus_dma_tag_t			status_dmat;
122 	bus_dma_tag_t			cmd_dmat;
123 	bus_dma_tag_t			hdr_dmat;
124 	bus_dma_tag_t			txbuf_dmat;
125 	bus_dma_tag_t			rxbuf_dmat;
126 
127 	bus_dmamap_t			tbd_map;
128 	bus_dmamap_t			rbd_map;
129 	bus_dmamap_t			status_map;
130 	bus_dmamap_t			cmd_map;
131 
132 	bus_addr_t			tbd_phys;
133 	bus_addr_t			rbd_phys;
134 	bus_addr_t			status_phys;
135 
136 	struct ipw_bd			*tbd_list;
137 	struct ipw_bd			*rbd_list;
138 	struct ipw_status		*status_list;
139 
140 	struct ipw_cmd			cmd;
141 	struct ipw_soft_bd		stbd_list[IPW_NTBD];
142 	struct ipw_soft_buf		tx_sbuf_list[IPW_NDATA];
143 	struct ipw_soft_hdr		shdr_list[IPW_NDATA];
144 	struct ipw_soft_bd		srbd_list[IPW_NRBD];
145 	struct ipw_soft_buf		rx_sbuf_list[IPW_NRBD];
146 
147 	SLIST_HEAD(, ipw_soft_hdr)	free_shdr;
148 	SLIST_HEAD(, ipw_soft_buf)	free_sbuf;
149 
150 	uint32_t			table1_base;
151 	uint32_t			table2_base;
152 
153 	uint32_t			txcur;
154 	uint32_t			txold;
155 	uint32_t			rxcur;
156 	int				txfree;
157 
158 	struct ipw_rx_radiotap_header	sc_rxtap;
159 	struct ipw_tx_radiotap_header	sc_txtap;
160 };
161 
162 /*
163  * NB.: This models the only instance of async locking in ipw_init_locked
164  *	and must be kept in sync.
165  */
166 #define IPW_LOCK(sc)		mtx_lock(&sc->sc_mtx);
167 #define IPW_UNLOCK(sc)		mtx_unlock(&sc->sc_mtx);
168 #define IPW_LOCK_ASSERT(sc)	mtx_assert(&(sc)->sc_mtx, MA_OWNED)
169