xref: /openbsd-src/sys/dev/pci/if_iwnvar.h (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: if_iwnvar.h,v 1.9 2009/02/15 08:58:22 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 #define IWN_RBUF_COUNT	(IWN_RX_RING_COUNT + 32)
83 
84 struct iwn_softc;
85 
86 struct iwn_rbuf {
87 	struct iwn_softc	*sc;
88 	caddr_t			vaddr;
89 	bus_addr_t		paddr;
90 	SLIST_ENTRY(iwn_rbuf)	next;
91 };
92 
93 struct iwn_rx_data {
94 	struct mbuf	*m;
95 };
96 
97 struct iwn_rx_ring {
98 	struct iwn_dma_info	desc_dma;
99 	struct iwn_dma_info	stat_dma;
100 	struct iwn_dma_info	buf_dma;
101 	uint32_t		*desc;
102 	struct iwn_rx_status	*stat;
103 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
104 	struct iwn_rbuf		rbuf[IWN_RBUF_COUNT];
105 	SLIST_HEAD(, iwn_rbuf)	freelist;
106 	int			cur;
107 };
108 
109 struct iwn_node {
110 	struct	ieee80211_node		ni;	/* must be the first */
111 	struct	ieee80211_amrr_node	amn;
112 	uint16_t			disable_tid;
113 	uint8_t				id;
114 	uint8_t				ridx[IEEE80211_RATE_MAXSIZE];
115 };
116 
117 struct iwn_calib_state {
118 	uint8_t		state;
119 #define IWN_CALIB_STATE_INIT	0
120 #define IWN_CALIB_STATE_ASSOC	1
121 #define IWN_CALIB_STATE_RUN	2
122 
123 	u_int		nbeacons;
124 	uint32_t	noise[3];
125 	uint32_t	rssi[3];
126 	uint32_t	ofdm_x1;
127 	uint32_t	ofdm_mrc_x1;
128 	uint32_t	ofdm_x4;
129 	uint32_t	ofdm_mrc_x4;
130 	uint32_t	cck_x4;
131 	uint32_t	cck_mrc_x4;
132 	uint32_t	bad_plcp_ofdm;
133 	uint32_t	fa_ofdm;
134 	uint32_t	bad_plcp_cck;
135 	uint32_t	fa_cck;
136 	uint32_t	low_fa;
137 	uint8_t		cck_state;
138 #define IWN_CCK_STATE_INIT	0
139 #define IWN_CCK_STATE_LOFA	1
140 #define IWN_CCK_STATE_HIFA	2
141 
142 	uint8_t		noise_samples[20];
143 	u_int		cur_noise_sample;
144 	uint8_t		noise_ref;
145 	uint32_t	energy_samples[10];
146 	u_int		cur_energy_sample;
147 	uint32_t	energy_cck;
148 };
149 
150 struct iwn_calib_info {
151 	uint8_t		*buf;
152 	u_int		len;
153 };
154 
155 struct iwn_fw_part {
156 	const uint8_t	*text;
157 	uint32_t	textsz;
158 	const uint8_t	*data;
159 	uint32_t	datasz;
160 };
161 
162 struct iwn_fw_info {
163 	u_char			*data;
164 	struct iwn_fw_part	init;
165 	struct iwn_fw_part	main;
166 	struct iwn_fw_part	boot;
167 };
168 
169 struct iwn_hal {
170 	int		(*load_firmware)(struct iwn_softc *);
171 	void		(*read_eeprom)(struct iwn_softc *);
172 	int		(*post_alive)(struct iwn_softc *);
173 	int		(*apm_init)(struct iwn_softc *);
174 	int		(*nic_config)(struct iwn_softc *);
175 	void		(*update_sched)(struct iwn_softc *, int, int, uint8_t,
176 			    uint16_t);
177 	int		(*get_temperature)(struct iwn_softc *);
178 	int		(*get_rssi)(const struct iwn_rx_stat *);
179 	int		(*set_txpower)(struct iwn_softc *, int);
180 	int		(*init_gains)(struct iwn_softc *);
181 	int		(*set_gains)(struct iwn_softc *);
182 	int		(*add_node)(struct iwn_softc *, struct iwn_node_info *,
183 			    int);
184 	void		(*tx_done)(struct iwn_softc *, struct iwn_rx_desc *);
185 #ifndef IEEE80211_NO_HT
186 	void		(*ampdu_tx_start)(struct iwn_softc *,
187 			    struct ieee80211_node *, uint8_t, uint16_t);
188 	void		(*ampdu_tx_stop)(struct iwn_softc *, uint8_t,
189 			    uint16_t);
190 #endif
191 	const struct	iwn_sensitivity_limits *limits;
192 	int		ntxqs;
193 	uint8_t		broadcast_id;
194 	int		rxonsz;
195 	int		schedsz;
196 	uint32_t	fw_text_maxsz;
197 	uint32_t	fw_data_maxsz;
198 	uint32_t	fwsz;
199 	bus_size_t	sched_txfact_addr;
200 };
201 
202 struct iwn_softc {
203 	struct device		sc_dev;
204 
205 	struct ieee80211com	sc_ic;
206 	int			(*sc_newstate)(struct ieee80211com *,
207 				    enum ieee80211_state, int);
208 
209 	struct ieee80211_amrr	amrr;
210 	uint8_t			fixed_ridx;
211 
212 	bus_dma_tag_t		sc_dmat;
213 
214 	u_int			sc_flags;
215 #define IWN_FLAG_HAS_5GHZ	(1 << 0)
216 #define IWN_FLAG_FIRST_BOOT	(1 << 1)
217 
218 	uint8_t 		hw_type;
219 	const struct iwn_hal	*sc_hal;
220 	const char		*fwname;
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 	/* TX/RX rings. */
234 	struct iwn_tx_ring	txq[IWN5000_NTXQUEUES];
235 	struct iwn_rx_ring	rxq;
236 
237 	bus_space_tag_t		sc_st;
238 	bus_space_handle_t	sc_sh;
239 	void 			*sc_ih;
240 	pci_chipset_tag_t	sc_pct;
241 	pcitag_t		sc_pcitag;
242 	bus_size_t		sc_sz;
243 	int			sc_cap_off;	/* PCIe Capabilities. */
244 
245 	struct ksensordev	sensordev;
246 	struct ksensor		sensor;
247 	struct timeout		calib_to;
248 	int			calib_cnt;
249 	struct iwn_calib_state	calib;
250 
251 	struct iwn_fw_info	fw;
252 	struct iwn_calib_info	calibcmd[5];
253 	uint32_t		errptr;
254 
255 	struct iwn_rx_stat	last_rx_stat;
256 	int			last_rx_valid;
257 	struct iwn_ucode_info	ucode_info;
258 	struct iwn_rxon		rxon;
259 	uint32_t		rawtemp;
260 	int			temp;
261 	int			noise;
262 	uint32_t		qfullmsk;
263 
264 	struct iwn4965_eeprom_band
265 				bands[IWN_NBANDS];
266 	uint16_t		rfcfg;
267 	char			eeprom_domain[4];
268 	uint32_t		eeprom_crystal;
269 	int16_t			eeprom_voltage;
270 	int8_t			maxpwr2GHz;
271 	int8_t			maxpwr5GHz;
272 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
273 
274 	uint32_t		critical_temp;
275 	uint8_t			ntxchains;
276 	uint8_t			nrxchains;
277 	uint8_t			txantmsk;
278 	uint8_t			rxantmsk;
279 	uint8_t			antmsk;
280 
281 	int			sc_tx_timer;
282 	void			*powerhook;
283 
284 #if NBPFILTER > 0
285 	caddr_t			sc_drvbpf;
286 
287 	union {
288 		struct iwn_rx_radiotap_header th;
289 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
290 	} sc_rxtapu;
291 #define sc_rxtap	sc_rxtapu.th
292 	int			sc_rxtap_len;
293 
294 	union {
295 		struct iwn_tx_radiotap_header th;
296 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
297 	} sc_txtapu;
298 #define sc_txtap	sc_txtapu.th
299 	int			sc_txtap_len;
300 #endif
301 };
302