xref: /freebsd/sys/dev/iwn/if_iwnvar.h (revision a98ff317388a00b992f1bf8404dee596f9383f5e)
1 /*	$FreeBSD$	*/
2 /*	$OpenBSD: if_iwnvar.h,v 1.18 2010/04/30 16:06:46 damien Exp $	*/
3 
4 /*-
5  * Copyright (c) 2007, 2008
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  * Copyright (c) 2008 Sam Leffler, Errno Consulting
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 struct iwn_rx_radiotap_header {
23 	struct ieee80211_radiotap_header wr_ihdr;
24 	uint64_t	wr_tsft;
25 	uint8_t		wr_flags;
26 	uint8_t		wr_rate;
27 	uint16_t	wr_chan_freq;
28 	uint16_t	wr_chan_flags;
29 	int8_t		wr_dbm_antsignal;
30 	int8_t		wr_dbm_antnoise;
31 } __packed;
32 
33 #define IWN_RX_RADIOTAP_PRESENT						\
34 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
35 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
36 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
37 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
38 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
39 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
40 
41 struct iwn_tx_radiotap_header {
42 	struct ieee80211_radiotap_header wt_ihdr;
43 	uint8_t		wt_flags;
44 	uint8_t		wt_rate;
45 	uint16_t	wt_chan_freq;
46 	uint16_t	wt_chan_flags;
47 } __packed;
48 
49 #define IWN_TX_RADIOTAP_PRESENT						\
50 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
51 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
52 	 (1 << IEEE80211_RADIOTAP_CHANNEL))
53 
54 struct iwn_dma_info {
55 	bus_dma_tag_t		tag;
56 	bus_dmamap_t		map;
57 	bus_dma_segment_t	seg;
58 	bus_addr_t		paddr;
59 	caddr_t			vaddr;
60 	bus_size_t		size;
61 };
62 
63 struct iwn_tx_data {
64 	bus_dmamap_t		map;
65 	bus_addr_t		cmd_paddr;
66 	bus_addr_t		scratch_paddr;
67 	struct mbuf		*m;
68 	struct ieee80211_node	*ni;
69 };
70 
71 struct iwn_tx_ring {
72 	struct iwn_dma_info	desc_dma;
73 	struct iwn_dma_info	cmd_dma;
74 	struct iwn_tx_desc	*desc;
75 	struct iwn_tx_cmd	*cmd;
76 	struct iwn_tx_data	data[IWN_TX_RING_COUNT];
77 	bus_dma_tag_t		data_dmat;
78 	int			qid;
79 	int			queued;
80 	int			cur;
81 	int			read;
82 };
83 
84 struct iwn_softc;
85 
86 struct iwn_rx_data {
87 	struct mbuf	*m;
88 	bus_dmamap_t	map;
89 };
90 
91 struct iwn_rx_ring {
92 	struct iwn_dma_info	desc_dma;
93 	struct iwn_dma_info	stat_dma;
94 	uint32_t		*desc;
95 	struct iwn_rx_status	*stat;
96 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
97 	bus_dma_tag_t		data_dmat;
98 	int			cur;
99 };
100 
101 struct iwn_node {
102 	struct	ieee80211_node		ni;	/* must be the first */
103 	uint16_t			disable_tid;
104 	uint8_t				id;
105 	struct {
106 		uint64_t		bitmap;
107 		int			startidx;
108 		int			nframes;
109 	} agg[IEEE80211_TID_SIZE];
110 };
111 
112 struct iwn_calib_state {
113 	uint8_t		state;
114 #define IWN_CALIB_STATE_INIT	0
115 #define IWN_CALIB_STATE_ASSOC	1
116 #define IWN_CALIB_STATE_RUN	2
117 
118 	u_int		nbeacons;
119 	uint32_t	noise[3];
120 	uint32_t	rssi[3];
121 	uint32_t	ofdm_x1;
122 	uint32_t	ofdm_mrc_x1;
123 	uint32_t	ofdm_x4;
124 	uint32_t	ofdm_mrc_x4;
125 	uint32_t	cck_x4;
126 	uint32_t	cck_mrc_x4;
127 	uint32_t	bad_plcp_ofdm;
128 	uint32_t	fa_ofdm;
129 	uint32_t	bad_plcp_cck;
130 	uint32_t	fa_cck;
131 	uint32_t	low_fa;
132 	uint8_t		cck_state;
133 #define IWN_CCK_STATE_INIT	0
134 #define IWN_CCK_STATE_LOFA	1
135 #define IWN_CCK_STATE_HIFA	2
136 
137 	uint8_t		noise_samples[20];
138 	u_int		cur_noise_sample;
139 	uint8_t		noise_ref;
140 	uint32_t	energy_samples[10];
141 	u_int		cur_energy_sample;
142 	uint32_t	energy_cck;
143 };
144 
145 struct iwn_calib_info {
146 	uint8_t		*buf;
147 	u_int		len;
148 };
149 
150 struct iwn_fw_part {
151 	const uint8_t	*text;
152 	uint32_t	textsz;
153 	const uint8_t	*data;
154 	uint32_t	datasz;
155 };
156 
157 struct iwn_fw_info {
158 	const uint8_t		*data;
159 	size_t			size;
160 	struct iwn_fw_part	init;
161 	struct iwn_fw_part	main;
162 	struct iwn_fw_part	boot;
163 };
164 
165 struct iwn_ops {
166 	int		(*load_firmware)(struct iwn_softc *);
167 	void		(*read_eeprom)(struct iwn_softc *);
168 	int		(*post_alive)(struct iwn_softc *);
169 	int		(*nic_config)(struct iwn_softc *);
170 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
171 			    uint16_t);
172 	int		(*get_temperature)(struct iwn_softc *);
173 	int		(*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *);
174 	int		(*set_txpower)(struct iwn_softc *,
175 			    struct ieee80211_channel *, int);
176 	int		(*init_gains)(struct iwn_softc *);
177 	int		(*set_gains)(struct iwn_softc *);
178 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
179 			    int);
180 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
181 			    struct iwn_rx_data *);
182 	void		(*ampdu_tx_start)(struct iwn_softc *,
183 			    struct ieee80211_node *, int, uint8_t, uint16_t);
184 	void		(*ampdu_tx_stop)(struct iwn_softc *, int, uint8_t,
185 			    uint16_t);
186 };
187 
188 struct iwn_vap {
189 	struct ieee80211vap	iv_vap;
190 	uint8_t			iv_ridx;
191 
192 	int			(*iv_newstate)(struct ieee80211vap *,
193 				    enum ieee80211_state, int);
194 };
195 #define	IWN_VAP(_vap)	((struct iwn_vap *)(_vap))
196 
197 struct iwn_softc {
198 	device_t		sc_dev;
199 
200 	struct ifnet		*sc_ifp;
201 	int			sc_debug;
202 
203 	struct mtx		sc_mtx;
204 
205 	u_int			sc_flags;
206 #define IWN_FLAG_HAS_OTPROM	(1 << 1)
207 #define IWN_FLAG_CALIB_DONE	(1 << 2)
208 #define IWN_FLAG_USE_ICT	(1 << 3)
209 #define IWN_FLAG_INTERNAL_PA	(1 << 4)
210 #define IWN_FLAG_HAS_11N	(1 << 6)
211 #define IWN_FLAG_ENH_SENS	(1 << 7)
212 #define IWN_FLAG_ADV_BTCOEX	(1 << 8)
213 
214 	uint8_t 		hw_type;
215 
216 	struct iwn_ops		ops;
217 	const char		*fwname;
218 	const struct iwn_sensitivity_limits
219 				*limits;
220 	int			ntxqs;
221 	int			firstaggqueue;
222 	int			ndmachnls;
223 	uint8_t			broadcast_id;
224 	int			rxonsz;
225 	int			schedsz;
226 	uint32_t		fw_text_maxsz;
227 	uint32_t		fw_data_maxsz;
228 	uint32_t		fwsz;
229 	bus_size_t		sched_txfact_addr;
230 	uint32_t		reset_noise_gain;
231 	uint32_t		noise_gain;
232 
233 	/* TX scheduler rings. */
234 	struct iwn_dma_info	sched_dma;
235 	uint16_t		*sched;
236 	uint32_t		sched_base;
237 
238 	/* "Keep Warm" page. */
239 	struct iwn_dma_info	kw_dma;
240 
241 	/* Firmware image. */
242 	const struct firmware	*fw_fp;
243 
244 	/* Firmware DMA transfer. */
245 	struct iwn_dma_info	fw_dma;
246 
247 	/* ICT table. */
248 	struct iwn_dma_info	ict_dma;
249 	uint32_t		*ict;
250 	int			ict_cur;
251 
252 	/* TX/RX rings. */
253 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
254 	struct iwn_rx_ring	rxq;
255 
256 	int			mem_rid;
257 	struct resource		*mem;
258 	bus_space_tag_t		sc_st;
259 	bus_space_handle_t	sc_sh;
260 	int			irq_rid;
261 	struct resource		*irq;
262 	void 			*sc_ih;
263 	bus_size_t		sc_sz;
264 	int			sc_cap_off;	/* PCIe Capabilities. */
265 
266 	/* Tasks used by the driver */
267 	struct task		sc_reinit_task;
268 	struct task		sc_radioon_task;
269 	struct task		sc_radiooff_task;
270 
271 	struct callout		calib_to;
272 	int			calib_cnt;
273 	struct iwn_calib_state	calib;
274 	struct callout		watchdog_to;
275 
276 	struct iwn_fw_info	fw;
277 	struct iwn_calib_info	calibcmd[5];
278 	uint32_t		errptr;
279 
280 	struct iwn_rx_stat	last_rx_stat;
281 	int			last_rx_valid;
282 	struct iwn_ucode_info	ucode_info;
283 	struct iwn_rxon		rxon;
284 	uint32_t		rawtemp;
285 	int			temp;
286 	int			noise;
287 	uint32_t		qfullmsk;
288 
289 	uint32_t		prom_base;
290 	struct iwn4965_eeprom_band
291 				bands[IWN_NBANDS];
292 	struct iwn_eeprom_chan	eeprom_channels[IWN_NBANDS][IWN_MAX_CHAN_PER_BAND];
293 	uint16_t		rfcfg;
294 	uint8_t			calib_ver;
295 	char			eeprom_domain[4];
296 	uint32_t		eeprom_crystal;
297 	int16_t			eeprom_temp;
298 	int16_t			eeprom_voltage;
299 	int8_t			maxpwr2GHz;
300 	int8_t			maxpwr5GHz;
301 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
302 
303 	int32_t			temp_off;
304 	uint32_t		int_mask;
305 	uint8_t			ntxchains;
306 	uint8_t			nrxchains;
307 	uint8_t			txchainmask;
308 	uint8_t			rxchainmask;
309 	uint8_t			chainmask;
310 
311 	int			sc_tx_timer;
312 
313 	struct ieee80211_tx_ampdu *qid2tap[IWN5000_NTXQUEUES];
314 
315 	int			(*sc_ampdu_rx_start)(struct ieee80211_node *,
316 				    struct ieee80211_rx_ampdu *, int, int, int);
317 	void			(*sc_ampdu_rx_stop)(struct ieee80211_node *,
318 				    struct ieee80211_rx_ampdu *);
319 	int			(*sc_addba_request)(struct ieee80211_node *,
320 				    struct ieee80211_tx_ampdu *, int, int, int);
321 	int			(*sc_addba_response)(struct ieee80211_node *,
322 				    struct ieee80211_tx_ampdu *, int, int, int);
323 	void			(*sc_addba_stop)(struct ieee80211_node *,
324 				    struct ieee80211_tx_ampdu *);
325 
326 
327 	struct iwn_rx_radiotap_header sc_rxtap;
328 	struct iwn_tx_radiotap_header sc_txtap;
329 };
330 
331 #define IWN_LOCK_INIT(_sc) \
332 	mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
333 	    MTX_NETWORK_LOCK, MTX_DEF)
334 #define IWN_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
335 #define IWN_LOCK_ASSERT(_sc)		mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
336 #define IWN_UNLOCK(_sc)			mtx_unlock(&(_sc)->sc_mtx)
337 #define IWN_LOCK_DESTROY(_sc)		mtx_destroy(&(_sc)->sc_mtx)
338