4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2004, 2005
7 * Damien Bergamini <damien.bergamini@free.fr>. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice unmodified, this list of conditions, and the following
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 struct iwi_rx_radiotap_header {
33 struct ieee80211_radiotap_header wr_ihdr;
36 uint16_t wr_chan_freq;
37 uint16_t wr_chan_flags;
43 #define IWI_RX_RADIOTAP_PRESENT \
44 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
45 (1 << IEEE80211_RADIOTAP_RATE) | \
46 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
47 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
48 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | \
49 (1 << IEEE80211_RADIOTAP_ANTENNA))
51 struct iwi_tx_radiotap_header {
52 struct ieee80211_radiotap_header wt_ihdr;
54 uint16_t wt_chan_freq;
55 uint16_t wt_chan_flags;
58 #define IWI_TX_RADIOTAP_PRESENT \
59 ((1 << IEEE80211_RADIOTAP_FLAGS) | \
60 (1 << IEEE80211_RADIOTAP_CHANNEL))
63 bus_dma_tag_t desc_dmat;
64 bus_dmamap_t desc_map;
66 struct iwi_cmd_desc *desc;
76 struct ieee80211_node *ni;
80 bus_dma_tag_t desc_dmat;
81 bus_dma_tag_t data_dmat;
82 bus_dmamap_t desc_map;
86 struct iwi_tx_desc *desc;
87 struct iwi_tx_data *data;
102 bus_dma_tag_t data_dmat;
103 struct iwi_rx_data *data;
109 struct ieee80211_node in_node;
111 #define IWI_MAX_IBSSNODE 32
115 const struct firmware *fp; /* image handle */
116 const char *data; /* firmware image data */
117 size_t size; /* firmware image size */
118 const char *name; /* associated image name */
122 struct ieee80211vap iwi_vap;
124 int (*iwi_newstate)(struct ieee80211vap *,
125 enum ieee80211_state, int);
127 #define IWI_VAP(vap) ((struct iwi_vap *)(vap))
131 struct ieee80211com sc_ic;
135 void (*sc_node_free)(struct ieee80211_node *);
137 uint8_t sc_mcast[IEEE80211_ADDR_LEN];
138 struct unrhdr *sc_unr;
141 #define IWI_FLAG_FW_INITED (1 << 0)
142 #define IWI_FLAG_BUSY (1 << 3) /* busy sending a command */
143 #define IWI_FLAG_ASSOCIATED (1 << 4) /* currently associated */
144 #define IWI_FLAG_CHANNEL_SCAN (1 << 5)
146 #define IWI_FW_IDLE 0
147 #define IWI_FW_LOADING 1
148 #define IWI_FW_ASSOCIATING 2
149 #define IWI_FW_DISASSOCIATING 3
150 #define IWI_FW_SCANNING 4
151 struct iwi_cmd_ring cmdq;
152 struct iwi_tx_ring txq[WME_NUM_AC];
153 struct iwi_rx_ring rxq;
155 struct resource *irq;
156 struct resource *mem;
157 bus_space_tag_t sc_st;
158 bus_space_handle_t sc_sh;
162 * The card needs external firmware images to work, which is made of a
163 * bootloader, microcode and firmware proper. In version 3.00 and
164 * above, all pieces are contained in a single image, preceded by a
165 * struct iwi_firmware_hdr indicating the size of the 3 pieces.
166 * Old firmware < 3.0 has separate boot and ucode, so we need to
167 * load all of them explicitly.
168 * To avoid issues related to fragmentation, we keep the block of
169 * dma-ble memory around until detach time, and reallocate it when
170 * it becomes too small. fw_dma_size is the size currently allocated.
173 uint32_t fw_flags; /* allocation status */
174 #define IWI_FW_HAVE_DMAT 0x01
175 #define IWI_FW_HAVE_MAP 0x02
176 #define IWI_FW_HAVE_PHY 0x04
177 bus_dma_tag_t fw_dmat;
179 bus_addr_t fw_physaddr;
181 enum ieee80211_opmode fw_mode; /* mode of current firmware */
182 struct iwi_fw fw_boot; /* boot firmware */
183 struct iwi_fw fw_uc; /* microcode */
184 struct iwi_fw fw_fw; /* operating mode support */
186 int curchan; /* current h/w channel # */
189 struct iwi_associate assoc;
190 struct iwi_wme_params wme[3];
193 struct task sc_radiontask; /* radio on processing */
194 struct task sc_radiofftask; /* radio off processing */
195 struct task sc_restarttask; /* restart adapter processing */
196 struct task sc_disassoctask;
197 struct task sc_monitortask;
199 unsigned int sc_running : 1, /* initialized */
200 sc_softled : 1, /* enable LED gpio status */
201 sc_ledstate: 1, /* LED on/off state */
202 sc_blinking: 1; /* LED blink operation active */
203 u_int sc_nictype; /* NIC type from EEPROM */
204 u_int sc_ledpin; /* mask for activity LED */
205 u_int sc_ledidle; /* idle polling interval */
206 int sc_ledevent; /* time of last LED event */
207 u_int8_t sc_rxrate; /* current rx rate for LED */
209 u_int8_t sc_txrate; /* current tx rate for LED */
211 u_int16_t sc_ledoff; /* off time for current blink */
212 struct callout sc_ledtimer; /* led off timer */
213 struct callout sc_wdtimer; /* watchdog timer */
214 struct callout sc_rftimer; /* rfkill timer */
217 int sc_state_timer; /* firmware state timer */
218 int sc_busy_timer; /* firmware cmd timer */
220 struct iwi_rx_radiotap_header sc_rxtap;
221 struct iwi_tx_radiotap_header sc_txtap;
223 struct iwi_notif_link_quality sc_linkqual;
224 int sc_linkqual_valid;
227 #define IWI_STATE_BEGIN(_sc, _state) do { \
228 KASSERT(_sc->fw_state == IWI_FW_IDLE, \
229 ("iwi firmware not idle, state %s", iwi_fw_states[_sc->fw_state]));\
230 _sc->fw_state = _state; \
231 _sc->sc_state_timer = 5; \
232 DPRINTF(("enter %s state\n", iwi_fw_states[_state])); \
235 #define IWI_STATE_END(_sc, _state) do { \
236 if (_sc->fw_state == _state) \
237 DPRINTF(("exit %s state\n", iwi_fw_states[_state])); \
239 DPRINTF(("expected %s state, got %s\n", \
240 iwi_fw_states[_state], iwi_fw_states[_sc->fw_state])); \
241 _sc->fw_state = IWI_FW_IDLE; \
243 _sc->sc_state_timer = 0; \
246 * NB.: This models the only instance of async locking in iwi_init_locked
247 * and must be kept in sync.
249 #define IWI_LOCK_INIT(sc) \
250 mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \
251 MTX_NETWORK_LOCK, MTX_DEF)
252 #define IWI_LOCK_DESTROY(sc) mtx_destroy(&(sc)->sc_mtx)
253 #define IWI_LOCK_DECL int __waslocked = 0
254 #define IWI_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED)
255 #define IWI_LOCK(sc) do { \
256 if (!(__waslocked = mtx_owned(&(sc)->sc_mtx))) \
257 mtx_lock(&(sc)->sc_mtx); \
259 #define IWI_UNLOCK(sc) do { \
261 mtx_unlock(&(sc)->sc_mtx); \