xref: /openbsd/sys/dev/pci/if_iwnvar.h (revision cca36db2)
1 /*	$OpenBSD: if_iwnvar.h,v 1.22 2011/01/09 15:45:37 damien 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 
205 	uint8_t 		hw_type;
206 
207 	struct iwn_ops		ops;
208 	const char		*fwname;
209 	const struct iwn_sensitivity_limits
210 				*limits;
211 	int			ntxqs;
212 	int			ndmachnls;
213 	uint8_t			broadcast_id;
214 	int			rxonsz;
215 	int			schedsz;
216 	uint32_t		fw_text_maxsz;
217 	uint32_t		fw_data_maxsz;
218 	uint32_t		fwsz;
219 	bus_size_t		sched_txfact_addr;
220 
221 	/* TX scheduler rings. */
222 	struct iwn_dma_info	sched_dma;
223 	uint16_t		*sched;
224 	uint32_t		sched_base;
225 
226 	/* "Keep Warm" page. */
227 	struct iwn_dma_info	kw_dma;
228 
229 	/* Firmware DMA transfer. */
230 	struct iwn_dma_info	fw_dma;
231 
232 	/* ICT table. */
233 	struct iwn_dma_info	ict_dma;
234 	uint32_t		*ict;
235 	int			ict_cur;
236 
237 	/* TX/RX rings. */
238 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
239 	struct iwn_rx_ring	rxq;
240 
241 	bus_space_tag_t		sc_st;
242 	bus_space_handle_t	sc_sh;
243 	void 			*sc_ih;
244 	pci_chipset_tag_t	sc_pct;
245 	pcitag_t		sc_pcitag;
246 	bus_size_t		sc_sz;
247 	int			sc_cap_off;	/* PCIe Capabilities. */
248 
249 	struct timeout		calib_to;
250 	int			calib_cnt;
251 	struct iwn_calib_state	calib;
252 
253 	struct iwn_fw_info	fw;
254 	struct iwn_calib_info	calibcmd[5];
255 	uint32_t		errptr;
256 
257 	struct iwn_rx_stat	last_rx_stat;
258 	int			last_rx_valid;
259 	struct iwn_ucode_info	ucode_info;
260 	struct iwn_rxon		rxon;
261 	uint32_t		rawtemp;
262 	int			temp;
263 	int			noise;
264 	uint32_t		qfullmsk;
265 
266 	uint32_t		prom_base;
267 	struct iwn4965_eeprom_band
268 				bands[IWN_NBANDS];
269 	uint16_t		rfcfg;
270 	uint8_t			calib_ver;
271 	char			eeprom_domain[4];
272 	uint32_t		eeprom_crystal;
273 	int16_t			eeprom_temp;
274 	int16_t			eeprom_voltage;
275 	int8_t			maxpwr2GHz;
276 	int8_t			maxpwr5GHz;
277 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
278 	int8_t			enh_maxpwr[35];
279 
280 	int32_t			temp_off;
281 	uint32_t		int_mask;
282 	uint8_t			ntxchains;
283 	uint8_t			nrxchains;
284 	uint8_t			txchainmask;
285 	uint8_t			rxchainmask;
286 	uint8_t			chainmask;
287 
288 	int			sc_tx_timer;
289 	struct workq_task	sc_resume_wqt;
290 
291 #if NBPFILTER > 0
292 	caddr_t			sc_drvbpf;
293 
294 	union {
295 		struct iwn_rx_radiotap_header th;
296 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
297 	} sc_rxtapu;
298 #define sc_rxtap	sc_rxtapu.th
299 	int			sc_rxtap_len;
300 
301 	union {
302 		struct iwn_tx_radiotap_header th;
303 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
304 	} sc_txtapu;
305 #define sc_txtap	sc_txtapu.th
306 	int			sc_txtap_len;
307 #endif
308 };
309