4 * Copyright (c) 2006,2007
5 * Damien Bergamini <damien.bergamini@free.fr>
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.
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.
19 #if ( __FreeBSD_version > 700000 )
20 #include <net80211/ieee80211_amrr.h>
22 #include <dev/wpi/ieee80211_amrr.h>
28 bus_dma_segment_t segs[WPI_MAX_SCATTER];
31 struct wpi_rx_radiotap_header {
32 struct ieee80211_radiotap_header wr_ihdr;
36 uint16_t wr_chan_freq;
37 uint16_t wr_chan_flags;
38 int8_t wr_dbm_antsignal;
39 int8_t wr_dbm_antnoise;
43 #define WPI_RX_RADIOTAP_PRESENT \
44 ((1 << IEEE80211_RADIOTAP_TSFT) | \
45 (1 << IEEE80211_RADIOTAP_FLAGS) | \
46 (1 << IEEE80211_RADIOTAP_RATE) | \
47 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
48 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
49 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
50 (1 << IEEE80211_RADIOTAP_ANTENNA))
52 struct wpi_tx_radiotap_header {
53 struct ieee80211_radiotap_header wt_ihdr;
56 uint16_t wt_chan_freq;
57 uint16_t wt_chan_flags;
61 #define WPI_TX_RADIOTAP_PRESENT \
62 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
63 (1 << IEEE80211_RADIOTAP_RATE) | \
64 (1 << IEEE80211_RADIOTAP_CHANNEL))
77 struct ieee80211_node *ni;
81 struct wpi_dma_info desc_dma;
82 struct wpi_dma_info cmd_dma;
83 struct wpi_tx_desc *desc;
84 struct wpi_tx_cmd *cmd;
85 struct wpi_tx_data *data;
86 bus_dma_tag_t data_dmat;
93 #define WPI_RBUF_COUNT ( WPI_RX_RING_COUNT + 16 )
101 SLIST_ENTRY(wpi_rbuf) next;
109 struct wpi_dma_info desc_dma;
110 struct wpi_dma_info buf_dma;
112 struct wpi_rx_data data[WPI_RX_RING_COUNT];
113 struct wpi_rbuf rbuf[WPI_RBUF_COUNT];
114 SLIST_HEAD(, wpi_rbuf) freelist;
119 struct ieee80211_node ni; /* must be the first */
123 int success_threshold;
128 struct ieee80211_node ni; /* must be the first */
129 struct ieee80211_amrr_node amn;
132 struct wpi_power_sample {
137 struct wpi_power_group {
138 #define WPI_SAMPLES_COUNT 5
139 struct wpi_power_sample samples[WPI_SAMPLES_COUNT];
147 struct ifnet *sc_ifp;
149 /* net80211 driver specifics */
150 struct ieee80211com sc_ic;
151 int (*sc_newstate)(struct ieee80211com *,
152 enum ieee80211_state, int);
153 unsigned long maxdwell; /* Max dwell time whilst scanning */
157 struct ieee80211_amrr amrr;
159 /* Flags indicating the current state the driver
160 * expects the hardware to be in
163 #define WPI_FLAG_HW_RADIO_OFF (1 << 0)
164 #define WPI_FLAG_SCANNING (1 << 1)
165 #define WPI_FLAG_BUSY (1 << 2)
166 #define WPI_FLAG_AUTH (1 << 3)
168 /* Flags indicating the state of the firmware */
170 #define WPI_FW_IDLE (1 << 0 )
173 struct wpi_dma_info shared_dma;
174 struct wpi_shared *shared;
176 struct wpi_tx_ring txq[WME_NUM_AC];
177 struct wpi_tx_ring cmdq;
178 struct wpi_rx_ring rxq;
180 /* TX Thermal Callibration */
181 struct callout calib_to;
184 /* Watch dog timer */
185 struct callout watchdog_to;
188 struct resource *irq;
189 struct resource *mem;
190 bus_space_tag_t sc_st;
191 bus_space_handle_t sc_sh;
196 struct wpi_config config;
202 struct bpf_if *sc_drvbpf;
204 struct wpi_rx_radiotap_header sc_rxtap;
206 struct wpi_tx_radiotap_header sc_txtap;
210 const struct firmware *fw_fp;
212 /* firmware DMA transfer */
213 struct wpi_dma_info fw_dma;
215 /* command queue related variables */
216 #define WPI_CMD_MAXOPS 10
217 #define WPI_SCAN_START (1<<0)
218 #define WPI_SCAN_CURCHAN (1<<1)
219 #define WPI_SCAN_STOP (1<<2)
220 #define WPI_SET_CHAN (1<<3)
221 #define WPI_AUTH (1<<4)
222 #define WPI_SCAN_NEXT (1<<5)
223 int sc_cmd[WPI_CMD_MAXOPS];
224 int sc_cmd_cur; /* current queued scan task */
225 int sc_cmd_next; /* last queued scan task */
226 struct mtx sc_cmdlock;
228 /* Task queues used to control the driver */
229 struct taskqueue *sc_tq; /* Main command task queue */
230 struct taskqueue *sc_tq2;/* firmware reset task queue */
232 /* Tasks used by the driver */
233 struct task sc_radioontask; /* enable rf transmitter task*/
234 struct task sc_radioofftask;/* disable rf transmitter task*/
235 struct task sc_opstask; /* operation handling task */
236 struct task sc_restarttask; /* reset firmware task */
242 struct wpi_power_group groups[WPI_POWER_GROUPS_COUNT];
243 int8_t maxpwr[IEEE80211_CHAN_MAX];
244 char domain[4]; //reglatory domain //XXX
246 #define WPI_LOCK_INIT(_sc) \
247 mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
248 MTX_NETWORK_LOCK, MTX_DEF)
249 #define WPI_LOCK_DECL int __waslocked = 0
250 #define WPI_LOCK(_sc) do {\
251 if (!(__waslocked = mtx_owned(&(_sc)->sc_mtx))) \
252 mtx_lock(&(_sc)->sc_mtx); \
254 #define WPI_UNLOCK(_sc) do { \
256 mtx_unlock(&(_sc)->sc_mtx); \
259 #define WPI_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
260 #define WPI_CMD_LOCK_INIT(_sc) \
261 mtx_init(&(_sc)->sc_cmdlock, device_get_nameunit((_sc)->sc_dev), NULL, MTX_DEF);
262 #define WPI_CMD_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_cmdlock)
263 #define WPI_CMD_LOCK(_sc) mtx_lock(&(_sc)->sc_cmdlock)
264 #define WPI_CMD_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_cmdlock)
265 #if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
266 #define WPI_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED)
268 #define WPI_LOCK_ASSERT(sc)