xref: /openbsd-src/sys/dev/pci/if_iwnvar.h (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: if_iwnvar.h,v 1.27 2014/02/10 19:08:58 kettenis Exp $	*/
2 
3 /*-
4  * Copyright (c) 2007, 2008
5  *	Damien Bergamini <damien.bergamini@free.fr>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 struct iwn_rx_radiotap_header {
21 	struct ieee80211_radiotap_header wr_ihdr;
22 	uint64_t	wr_tsft;
23 	uint8_t		wr_flags;
24 	uint8_t		wr_rate;
25 	uint16_t	wr_chan_freq;
26 	uint16_t	wr_chan_flags;
27 	int8_t		wr_dbm_antsignal;
28 	int8_t		wr_dbm_antnoise;
29 } __packed;
30 
31 #define IWN_RX_RADIOTAP_PRESENT						\
32 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
33 	 (1 << IEEE80211_RADIOTAP_FLAGS) |				\
34 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
35 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
36 	 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
37 	 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
38 
39 struct iwn_tx_radiotap_header {
40 	struct ieee80211_radiotap_header wt_ihdr;
41 	uint8_t		wt_flags;
42 	uint8_t		wt_rate;
43 	uint16_t	wt_chan_freq;
44 	uint16_t	wt_chan_flags;
45 	uint8_t		wt_hwqueue;
46 } __packed;
47 
48 #define IWN_TX_RADIOTAP_PRESENT						\
49 	((1 << IEEE80211_RADIOTAP_FLAGS) |				\
50 	 (1 << IEEE80211_RADIOTAP_RATE) |				\
51 	 (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
52 	 (1 << IEEE80211_RADIOTAP_HWQUEUE))
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 	int			qid;
78 	int			queued;
79 	int			cur;
80 };
81 
82 struct iwn_softc;
83 
84 struct iwn_rx_data {
85 	struct mbuf	*m;
86 	bus_dmamap_t	map;
87 };
88 
89 struct iwn_rx_ring {
90 	struct iwn_dma_info	desc_dma;
91 	struct iwn_dma_info	stat_dma;
92 	uint32_t		*desc;
93 	struct iwn_rx_status	*stat;
94 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
95 	int			cur;
96 };
97 
98 struct iwn_node {
99 	struct	ieee80211_node		ni;	/* must be the first */
100 	struct	ieee80211_amrr_node	amn;
101 	uint16_t			disable_tid;
102 	uint8_t				id;
103 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
104 };
105 
106 struct iwn_calib_state {
107 	uint8_t		state;
108 #define IWN_CALIB_STATE_INIT	0
109 #define IWN_CALIB_STATE_ASSOC	1
110 #define IWN_CALIB_STATE_RUN	2
111 
112 	u_int		nbeacons;
113 	uint32_t	noise[3];
114 	uint32_t	rssi[3];
115 	uint32_t	ofdm_x1;
116 	uint32_t	ofdm_mrc_x1;
117 	uint32_t	ofdm_x4;
118 	uint32_t	ofdm_mrc_x4;
119 	uint32_t	cck_x4;
120 	uint32_t	cck_mrc_x4;
121 	uint32_t	bad_plcp_ofdm;
122 	uint32_t	fa_ofdm;
123 	uint32_t	bad_plcp_cck;
124 	uint32_t	fa_cck;
125 	uint32_t	low_fa;
126 	uint8_t		cck_state;
127 #define IWN_CCK_STATE_INIT	0
128 #define IWN_CCK_STATE_LOFA	1
129 #define IWN_CCK_STATE_HIFA	2
130 
131 	uint8_t		noise_samples[20];
132 	u_int		cur_noise_sample;
133 	uint8_t		noise_ref;
134 	uint32_t	energy_samples[10];
135 	u_int		cur_energy_sample;
136 	uint32_t	energy_cck;
137 };
138 
139 struct iwn_calib_info {
140 	uint8_t		*buf;
141 	u_int		len;
142 };
143 
144 struct iwn_fw_part {
145 	const uint8_t	*text;
146 	uint32_t	textsz;
147 	const uint8_t	*data;
148 	uint32_t	datasz;
149 };
150 
151 struct iwn_fw_info {
152 	u_char			*data;
153 	size_t			size;
154 	struct iwn_fw_part	init;
155 	struct iwn_fw_part	main;
156 	struct iwn_fw_part	boot;
157 };
158 
159 struct iwn_ops {
160 	int		(*load_firmware)(struct iwn_softc *);
161 	void		(*read_eeprom)(struct iwn_softc *);
162 	int		(*post_alive)(struct iwn_softc *);
163 	int		(*nic_config)(struct iwn_softc *);
164 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
165 			    uint16_t);
166 	int		(*get_temperature)(struct iwn_softc *);
167 	int		(*get_rssi)(const struct iwn_rx_stat *);
168 	int		(*set_txpower)(struct iwn_softc *, int);
169 	int		(*init_gains)(struct iwn_softc *);
170 	int		(*set_gains)(struct iwn_softc *);
171 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
172 			    int);
173 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *,
174 			    struct iwn_rx_data *);
175 #ifndef IEEE80211_NO_HT
176 	void		(*ampdu_tx_start)(struct iwn_softc *,
177 			    struct ieee80211_node *, uint8_t, uint16_t);
178 	void		(*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
179 			    uint16_t);
180 #endif
181 };
182 
183 struct iwn_softc {
184 	struct device		sc_dev;
185 
186 	struct ieee80211com	sc_ic;
187 	int			(*sc_newstate)(struct ieee80211com *,
188 				    enum ieee80211_state, int);
189 
190 	struct ieee80211_amrr	amrr;
191 	uint8_t			fixed_ridx;
192 
193 	bus_dma_tag_t		sc_dmat;
194 
195 	u_int			sc_flags;
196 #define IWN_FLAG_HAS_5GHZ	(1 << 0)
197 #define IWN_FLAG_HAS_OTPROM	(1 << 1)
198 #define IWN_FLAG_CALIB_DONE	(1 << 2)
199 #define IWN_FLAG_USE_ICT	(1 << 3)
200 #define IWN_FLAG_INTERNAL_PA	(1 << 4)
201 #define IWN_FLAG_BUSY		(1 << 5)
202 #define IWN_FLAG_HAS_11N	(1 << 6)
203 #define IWN_FLAG_ENH_SENS	(1 << 7)
204 #define IWN_FLAG_ADV_BT_COEX	(1 << 8)
205 
206 	uint8_t 		hw_type;
207 
208 	struct iwn_ops		ops;
209 	const char		*fwname;
210 	const struct iwn_sensitivity_limits
211 				*limits;
212 	int			ntxqs;
213 	int			ndmachnls;
214 	uint8_t			broadcast_id;
215 	int			rxonsz;
216 	int			schedsz;
217 	uint32_t		fw_text_maxsz;
218 	uint32_t		fw_data_maxsz;
219 	uint32_t		fwsz;
220 	bus_size_t		sched_txfact_addr;
221 
222 	/* TX scheduler rings. */
223 	struct iwn_dma_info	sched_dma;
224 	uint16_t		*sched;
225 	uint32_t		sched_base;
226 
227 	/* "Keep Warm" page. */
228 	struct iwn_dma_info	kw_dma;
229 
230 	/* Firmware DMA transfer. */
231 	struct iwn_dma_info	fw_dma;
232 
233 	/* ICT table. */
234 	struct iwn_dma_info	ict_dma;
235 	uint32_t		*ict;
236 	int			ict_cur;
237 
238 	/* TX/RX rings. */
239 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
240 	struct iwn_rx_ring	rxq;
241 
242 	bus_space_tag_t		sc_st;
243 	bus_space_handle_t	sc_sh;
244 	void 			*sc_ih;
245 	pci_chipset_tag_t	sc_pct;
246 	pcitag_t		sc_pcitag;
247 	bus_size_t		sc_sz;
248 	int			sc_cap_off;	/* PCIe Capabilities. */
249 
250 	struct timeout		calib_to;
251 	int			calib_cnt;
252 	struct iwn_calib_state	calib;
253 
254 	struct task		init_task;
255 
256 	struct iwn_fw_info	fw;
257 	struct iwn_calib_info	calibcmd[5];
258 	uint32_t		errptr;
259 
260 	struct iwn_rx_stat	last_rx_stat;
261 	int			last_rx_valid;
262 	struct iwn_ucode_info	ucode_info;
263 	struct iwn_rxon		rxon;
264 	uint32_t		rawtemp;
265 	int			temp;
266 	int			noise;
267 	uint32_t		qfullmsk;
268 
269 	uint32_t		prom_base;
270 	struct iwn4965_eeprom_band
271 				bands[IWN_NBANDS];
272 	uint16_t		rfcfg;
273 	uint8_t			calib_ver;
274 	char			eeprom_domain[4];
275 	uint32_t		eeprom_crystal;
276 	int16_t			eeprom_temp;
277 	int16_t			eeprom_voltage;
278 	int16_t			eeprom_rawtemp;
279 	int8_t			maxpwr2GHz;
280 	int8_t			maxpwr5GHz;
281 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
282 	int8_t			enh_maxpwr[35];
283 
284 	uint8_t			reset_noise_gain;
285 	uint8_t			noise_gain;
286 
287 	int32_t			temp_off;
288 	uint32_t		int_mask;
289 	uint8_t			ntxchains;
290 	uint8_t			nrxchains;
291 	uint8_t			txchainmask;
292 	uint8_t			rxchainmask;
293 	uint8_t			chainmask;
294 
295 	int			sc_tx_timer;
296 
297 #if NBPFILTER > 0
298 	caddr_t			sc_drvbpf;
299 
300 	union {
301 		struct iwn_rx_radiotap_header th;
302 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
303 	} sc_rxtapu;
304 #define sc_rxtap	sc_rxtapu.th
305 	int			sc_rxtap_len;
306 
307 	union {
308 		struct iwn_tx_radiotap_header th;
309 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
310 	} sc_txtapu;
311 #define sc_txtap	sc_txtapu.th
312 	int			sc_txtap_len;
313 #endif
314 };
315