xref: /netbsd-src/sys/dev/pci/if_iwnvar.h (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1 /*	$NetBSD: if_iwnvar.h,v 1.5 2008/12/22 11:32:04 blymn Exp $	*/
2 /*	OpenBSD: if_iwnvar.h,v 1.2 2007/11/19 19:34:25 damien Exp	*/
3 
4 /*-
5  * Copyright (c) 2007
6  *	Damien Bergamini <damien.bergamini@free.fr>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 struct iwn_rx_radiotap_header {
22 	struct ieee80211_radiotap_header wr_ihdr;
23 	uint64_t	wr_tsft;
24 	uint8_t		wr_flags;
25 	uint8_t		wr_rate;
26 	uint16_t	wr_chan_freq;
27 	uint16_t	wr_chan_flags;
28 	int8_t		wr_dbm_antsignal;
29 	int8_t		wr_dbm_antnoise;
30 } __packed;
31 
32 #define IWN_RX_RADIOTAP_PRESENT						\
33 	((1 << IEEE80211_RADIOTAP_TSFT) |				\
34 	    (1 << IEEE80211_RADIOTAP_FLAGS) |				\
35 	    (1 << IEEE80211_RADIOTAP_RATE) |				\
36 	    (1 << IEEE80211_RADIOTAP_CHANNEL) |				\
37 	    (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |			\
38 	    (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
39 
40 struct iwn_tx_radiotap_header {
41 	struct ieee80211_radiotap_header wt_ihdr;
42 	uint8_t		wt_flags;
43 	uint8_t		wt_rate;
44 	uint16_t	wt_chan_freq;
45 	uint16_t	wt_chan_flags;
46 	uint8_t		wt_hwqueue;
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 	void *			vaddr;
60 	bus_size_t		size;
61 };
62 
63 struct iwn_tx_data {
64 	bus_dmamap_t		map;
65 	struct mbuf		*m;
66 	struct ieee80211_node	*ni;
67 };
68 
69 struct iwn_tx_ring {
70 	struct iwn_dma_info	desc_dma;
71 	struct iwn_dma_info	cmd_dma;
72 	struct iwn_tx_desc	*desc;
73 	struct iwn_tx_cmd	*cmd;
74 	struct iwn_tx_data	*data;
75 	int			qid;
76 	int			queued;
77 	int			count;
78 	int			cur;
79 };
80 
81 #define IWN_RBUF_COUNT	(IWN_RX_RING_COUNT + 32)
82 
83 struct iwn_softc;
84 
85 struct iwn_rbuf {
86 	struct iwn_softc	*sc;
87 	void *			vaddr;
88 	bus_addr_t		paddr;
89 	SLIST_ENTRY(iwn_rbuf)	next;
90 };
91 
92 struct iwn_rx_data {
93 	struct mbuf	*m;
94 };
95 
96 struct iwn_rx_ring {
97 	struct iwn_dma_info	desc_dma;
98 	struct iwn_dma_info	buf_dma;
99 	uint32_t		*desc;
100 	struct iwn_rx_data	data[IWN_RX_RING_COUNT];
101 	struct iwn_rbuf		rbuf[IWN_RBUF_COUNT];
102 	SLIST_HEAD(, iwn_rbuf)	freelist;
103 	kmutex_t		freelist_mtx;
104 	int			nb_free_entries;
105 	int			cur;
106 };
107 
108 struct iwn_node {
109 	struct	ieee80211_node		ni;	/* must be the first */
110 	struct	ieee80211_amrr_node	amn;
111 };
112 
113 struct iwn_calib_state {
114 	uint8_t		state;
115 #define IWN_CALIB_STATE_INIT	0
116 #define IWN_CALIB_STATE_ASSOC	1
117 #define IWN_CALIB_STATE_RUN	2
118 
119 	u_int		nbeacons;
120 	uint32_t	noise[3];
121 	uint32_t	rssi[3];
122 	uint32_t	corr_ofdm_x1;
123 	uint32_t	corr_ofdm_mrc_x1;
124 	uint32_t	corr_ofdm_x4;
125 	uint32_t	corr_ofdm_mrc_x4;
126 	uint32_t	corr_cck_x4;
127 	uint32_t	corr_cck_mrc_x4;
128 	uint32_t	bad_plcp_ofdm;
129 	uint32_t	fa_ofdm;
130 	uint32_t	bad_plcp_cck;
131 	uint32_t	fa_cck;
132 	uint32_t	low_fa;
133 	uint8_t		cck_state;
134 #define IWN_CCK_STATE_INIT	0
135 #define IWN_CCK_STATE_LOFA	1
136 #define IWN_CCK_STATE_HIFA	2
137 
138 	uint8_t		noise_samples[20];
139 	u_int		cur_noise_sample;
140 	uint8_t		noise_ref;
141 	uint32_t	energy_samples[10];
142 	u_int		cur_energy_sample;
143 	uint32_t	energy_cck;
144 };
145 
146 struct iwn_softc {
147 	device_t			sc_dev;
148 	struct ethercom	 	sc_ec;
149 	struct ieee80211com	sc_ic;
150 	int			(*sc_newstate)(struct ieee80211com *,
151 	    enum ieee80211_state, int);
152 
153 	struct ieee80211_amrr	amrr;
154 
155 	bus_dma_tag_t		sc_dmat;
156 
157 	/* shared area */
158 	struct iwn_dma_info	shared_dma;
159 	struct iwn_shared	*shared;
160 
161 	/* "keep warm" page */
162 	struct iwn_dma_info	kw_dma;
163 
164 	/* firmware DMA transfer */
165 	struct iwn_dma_info	fw_dma;
166 
167 	/* rings */
168 	struct iwn_tx_ring	txq[IWN_NTXQUEUES];
169 	struct iwn_rx_ring	rxq;
170 
171 	bus_space_tag_t		sc_st;
172 	bus_space_handle_t	sc_sh;
173 	void 			*sc_ih;
174 	pci_chipset_tag_t	sc_pct;
175 	pcitag_t		sc_pcitag;
176 	bus_size_t		sc_sz;
177 
178 	struct callout calib_to;
179 	int			calib_cnt;
180 	struct iwn_calib_state	calib;
181 
182 	struct iwn_rx_stat	last_rx_stat;
183 	int			last_rx_valid;
184 	struct iwn_ucode_info	ucode_info;
185 	struct iwn_config	config;
186 	uint32_t		rawtemp;
187 	int			temp;
188 	int			noise;
189 	uint8_t			antmsk;
190 
191 	struct iwn_eeprom_band	bands[IWN_NBANDS];
192 	int16_t			eeprom_voltage;
193 	int8_t			maxpwr2GHz;
194 	int8_t			maxpwr5GHz;
195 	int8_t			maxpwr[IEEE80211_CHAN_MAX];
196 
197 	int			sc_tx_timer;
198 
199 #if NBPFILTER > 0
200 	void *			sc_drvbpf;
201 
202 	union {
203 		struct iwn_rx_radiotap_header th;
204 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
205 	} sc_rxtapu;
206 #define sc_rxtap	sc_rxtapu.th
207 	int			sc_rxtap_len;
208 
209 	union {
210 		struct iwn_tx_radiotap_header th;
211 		uint8_t	pad[IEEE80211_RADIOTAP_HDRLEN];
212 	} sc_txtapu;
213 #define sc_txtap	sc_txtapu.th
214 	int			sc_txtap_len;
215 #endif
216 
217 	bool		is_scanning;
218 	bool		sc_radio;
219 };
220