]>
Commit | Line | Data |
---|---|---|
f1d63a59 | 1 | |
f5fc0f86 LC |
2 | /* |
3 | * This file is part of wl1271 | |
4 | * | |
8bf29b0e | 5 | * Copyright (C) 2008-2010 Nokia Corporation |
f5fc0f86 LC |
6 | * |
7 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * version 2 as published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
21 | * 02110-1301 USA | |
22 | * | |
23 | */ | |
24 | ||
25 | #include <linux/module.h> | |
f5fc0f86 LC |
26 | #include <linux/firmware.h> |
27 | #include <linux/delay.h> | |
f5fc0f86 LC |
28 | #include <linux/spi/spi.h> |
29 | #include <linux/crc32.h> | |
30 | #include <linux/etherdevice.h> | |
1fba4974 | 31 | #include <linux/vmalloc.h> |
a1dd8187 | 32 | #include <linux/platform_device.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
341b7cde | 34 | #include <linux/wl12xx.h> |
95dac04f | 35 | #include <linux/sched.h> |
a390e85c | 36 | #include <linux/interrupt.h> |
f5fc0f86 | 37 | |
c31be25a | 38 | #include "wlcore.h" |
0f4e3122 | 39 | #include "debug.h" |
f5fc0f86 | 40 | #include "wl12xx_80211.h" |
00d20100 SL |
41 | #include "io.h" |
42 | #include "event.h" | |
43 | #include "tx.h" | |
44 | #include "rx.h" | |
45 | #include "ps.h" | |
46 | #include "init.h" | |
47 | #include "debugfs.h" | |
48 | #include "cmd.h" | |
49 | #include "boot.h" | |
50 | #include "testmode.h" | |
51 | #include "scan.h" | |
53d67a50 | 52 | #include "hw_ops.h" |
f5fc0f86 | 53 | |
9ccd9217 JO |
54 | #define WL1271_BOOT_RETRIES 3 |
55 | ||
e87288f0 | 56 | #define WL1271_BOOT_RETRIES 3 |
8a08048a | 57 | |
95dac04f | 58 | static char *fwlog_param; |
2a5bff09 | 59 | static bool bug_on_recovery; |
34785be5 | 60 | static bool no_recovery; |
95dac04f | 61 | |
7dece1c8 | 62 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
536129c8 | 63 | struct ieee80211_vif *vif, |
7dece1c8 | 64 | bool reset_tx_queues); |
c24ec83b | 65 | static void wlcore_op_stop_locked(struct wl1271 *wl); |
170d0e67 | 66 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif); |
52b0e7a6 | 67 | |
9fd6f21b EP |
68 | static int wl12xx_set_authorized(struct wl1271 *wl, |
69 | struct wl12xx_vif *wlvif) | |
ef4b29e9 EP |
70 | { |
71 | int ret; | |
0603d891 | 72 | |
9fd6f21b EP |
73 | if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS)) |
74 | return -EINVAL; | |
75 | ||
76 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | |
ef4b29e9 EP |
77 | return 0; |
78 | ||
8181aecc | 79 | if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) |
ef4b29e9 EP |
80 | return 0; |
81 | ||
d50529c0 | 82 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, wlvif->sta.hlid); |
ef4b29e9 EP |
83 | if (ret < 0) |
84 | return ret; | |
85 | ||
86 | wl1271_info("Association completed."); | |
87 | return 0; | |
88 | } | |
c2c192ac | 89 | |
b7417d93 | 90 | static int wl1271_reg_notify(struct wiphy *wiphy, |
573c67cf LC |
91 | struct regulatory_request *request) |
92 | { | |
b7417d93 JO |
93 | struct ieee80211_supported_band *band; |
94 | struct ieee80211_channel *ch; | |
95 | int i; | |
6b70e7eb VG |
96 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
97 | struct wl1271 *wl = hw->priv; | |
b7417d93 JO |
98 | |
99 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
100 | for (i = 0; i < band->n_channels; i++) { | |
101 | ch = &band->channels[i]; | |
102 | if (ch->flags & IEEE80211_CHAN_DISABLED) | |
103 | continue; | |
104 | ||
105 | if (ch->flags & IEEE80211_CHAN_RADAR) | |
106 | ch->flags |= IEEE80211_CHAN_NO_IBSS | | |
107 | IEEE80211_CHAN_PASSIVE_SCAN; | |
108 | ||
109 | } | |
110 | ||
6b70e7eb VG |
111 | if (likely(wl->state == WLCORE_STATE_ON)) |
112 | wlcore_regdomain_config(wl); | |
113 | ||
b7417d93 JO |
114 | return 0; |
115 | } | |
116 | ||
9eb599e9 EP |
117 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
118 | bool enable) | |
77ddaa10 EP |
119 | { |
120 | int ret = 0; | |
121 | ||
122 | /* we should hold wl->mutex */ | |
9eb599e9 | 123 | ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); |
77ddaa10 EP |
124 | if (ret < 0) |
125 | goto out; | |
126 | ||
127 | if (enable) | |
0744bdb6 | 128 | set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
77ddaa10 | 129 | else |
0744bdb6 | 130 | clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
77ddaa10 EP |
131 | out: |
132 | return ret; | |
133 | } | |
134 | ||
135 | /* | |
136 | * this function is being called when the rx_streaming interval | |
137 | * has beed changed or rx_streaming should be disabled | |
138 | */ | |
9eb599e9 | 139 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
77ddaa10 EP |
140 | { |
141 | int ret = 0; | |
142 | int period = wl->conf.rx_streaming.interval; | |
143 | ||
144 | /* don't reconfigure if rx_streaming is disabled */ | |
0744bdb6 | 145 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
77ddaa10 EP |
146 | goto out; |
147 | ||
148 | /* reconfigure/disable according to new streaming_period */ | |
149 | if (period && | |
ba8447f6 | 150 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
77ddaa10 EP |
151 | (wl->conf.rx_streaming.always || |
152 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | |
9eb599e9 | 153 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
77ddaa10 | 154 | else { |
9eb599e9 | 155 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
77ddaa10 | 156 | /* don't cancel_work_sync since we might deadlock */ |
9eb599e9 | 157 | del_timer_sync(&wlvif->rx_streaming_timer); |
77ddaa10 EP |
158 | } |
159 | out: | |
160 | return ret; | |
161 | } | |
162 | ||
163 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) | |
164 | { | |
165 | int ret; | |
9eb599e9 EP |
166 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
167 | rx_streaming_enable_work); | |
168 | struct wl1271 *wl = wlvif->wl; | |
77ddaa10 EP |
169 | |
170 | mutex_lock(&wl->mutex); | |
171 | ||
0744bdb6 | 172 | if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || |
ba8447f6 | 173 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
77ddaa10 EP |
174 | (!wl->conf.rx_streaming.always && |
175 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | |
176 | goto out; | |
177 | ||
178 | if (!wl->conf.rx_streaming.interval) | |
179 | goto out; | |
180 | ||
181 | ret = wl1271_ps_elp_wakeup(wl); | |
182 | if (ret < 0) | |
183 | goto out; | |
184 | ||
9eb599e9 | 185 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
77ddaa10 EP |
186 | if (ret < 0) |
187 | goto out_sleep; | |
188 | ||
189 | /* stop it after some time of inactivity */ | |
9eb599e9 | 190 | mod_timer(&wlvif->rx_streaming_timer, |
77ddaa10 EP |
191 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); |
192 | ||
193 | out_sleep: | |
194 | wl1271_ps_elp_sleep(wl); | |
195 | out: | |
196 | mutex_unlock(&wl->mutex); | |
197 | } | |
198 | ||
199 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) | |
200 | { | |
201 | int ret; | |
9eb599e9 EP |
202 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
203 | rx_streaming_disable_work); | |
204 | struct wl1271 *wl = wlvif->wl; | |
77ddaa10 EP |
205 | |
206 | mutex_lock(&wl->mutex); | |
207 | ||
0744bdb6 | 208 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
77ddaa10 EP |
209 | goto out; |
210 | ||
211 | ret = wl1271_ps_elp_wakeup(wl); | |
212 | if (ret < 0) | |
213 | goto out; | |
214 | ||
9eb599e9 | 215 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
77ddaa10 EP |
216 | if (ret) |
217 | goto out_sleep; | |
218 | ||
219 | out_sleep: | |
220 | wl1271_ps_elp_sleep(wl); | |
221 | out: | |
222 | mutex_unlock(&wl->mutex); | |
223 | } | |
224 | ||
225 | static void wl1271_rx_streaming_timer(unsigned long data) | |
226 | { | |
9eb599e9 EP |
227 | struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; |
228 | struct wl1271 *wl = wlvif->wl; | |
229 | ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); | |
77ddaa10 EP |
230 | } |
231 | ||
55df5afb AN |
232 | /* wl->mutex must be taken */ |
233 | void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl) | |
234 | { | |
235 | /* if the watchdog is not armed, don't do anything */ | |
236 | if (wl->tx_allocated_blocks == 0) | |
237 | return; | |
238 | ||
239 | cancel_delayed_work(&wl->tx_watchdog_work); | |
240 | ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work, | |
241 | msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout)); | |
242 | } | |
243 | ||
244 | static void wl12xx_tx_watchdog_work(struct work_struct *work) | |
245 | { | |
246 | struct delayed_work *dwork; | |
247 | struct wl1271 *wl; | |
248 | ||
249 | dwork = container_of(work, struct delayed_work, work); | |
250 | wl = container_of(dwork, struct wl1271, tx_watchdog_work); | |
251 | ||
252 | mutex_lock(&wl->mutex); | |
253 | ||
4cc53383 | 254 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
55df5afb AN |
255 | goto out; |
256 | ||
257 | /* Tx went out in the meantime - everything is ok */ | |
258 | if (unlikely(wl->tx_allocated_blocks == 0)) | |
259 | goto out; | |
260 | ||
261 | /* | |
262 | * if a ROC is in progress, we might not have any Tx for a long | |
263 | * time (e.g. pending Tx on the non-ROC channels) | |
264 | */ | |
265 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { | |
266 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC", | |
267 | wl->conf.tx.tx_watchdog_timeout); | |
268 | wl12xx_rearm_tx_watchdog_locked(wl); | |
269 | goto out; | |
270 | } | |
271 | ||
272 | /* | |
273 | * if a scan is in progress, we might not have any Tx for a long | |
274 | * time | |
275 | */ | |
276 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { | |
277 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan", | |
278 | wl->conf.tx.tx_watchdog_timeout); | |
279 | wl12xx_rearm_tx_watchdog_locked(wl); | |
280 | goto out; | |
281 | } | |
282 | ||
283 | /* | |
284 | * AP might cache a frame for a long time for a sleeping station, | |
285 | * so rearm the timer if there's an AP interface with stations. If | |
286 | * Tx is genuinely stuck we will most hopefully discover it when all | |
287 | * stations are removed due to inactivity. | |
288 | */ | |
289 | if (wl->active_sta_count) { | |
290 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has " | |
291 | " %d stations", | |
292 | wl->conf.tx.tx_watchdog_timeout, | |
293 | wl->active_sta_count); | |
294 | wl12xx_rearm_tx_watchdog_locked(wl); | |
295 | goto out; | |
296 | } | |
297 | ||
298 | wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery", | |
299 | wl->conf.tx.tx_watchdog_timeout); | |
300 | wl12xx_queue_recovery_work(wl); | |
301 | ||
302 | out: | |
303 | mutex_unlock(&wl->mutex); | |
304 | } | |
305 | ||
e87288f0 | 306 | static void wlcore_adjust_conf(struct wl1271 *wl) |
8a08048a | 307 | { |
95dac04f IY |
308 | /* Adjust settings according to optional module parameters */ |
309 | if (fwlog_param) { | |
310 | if (!strcmp(fwlog_param, "continuous")) { | |
311 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | |
312 | } else if (!strcmp(fwlog_param, "ondemand")) { | |
313 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; | |
314 | } else if (!strcmp(fwlog_param, "dbgpins")) { | |
315 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | |
316 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; | |
317 | } else if (!strcmp(fwlog_param, "disable")) { | |
318 | wl->conf.fwlog.mem_blocks = 0; | |
319 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; | |
320 | } else { | |
321 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); | |
322 | } | |
323 | } | |
324 | } | |
2b60100b | 325 | |
6e8cd331 EP |
326 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, |
327 | struct wl12xx_vif *wlvif, | |
328 | u8 hlid, u8 tx_pkts) | |
b622d992 | 329 | { |
da03209e | 330 | bool fw_ps, single_sta; |
b622d992 | 331 | |
b622d992 | 332 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
da03209e | 333 | single_sta = (wl->active_sta_count == 1); |
b622d992 AN |
334 | |
335 | /* | |
336 | * Wake up from high level PS if the STA is asleep with too little | |
9b17f1b3 | 337 | * packets in FW or if the STA is awake. |
b622d992 | 338 | */ |
9b17f1b3 | 339 | if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) |
6e8cd331 | 340 | wl12xx_ps_link_end(wl, wlvif, hlid); |
b622d992 | 341 | |
da03209e AN |
342 | /* |
343 | * Start high-level PS if the STA is asleep with enough blocks in FW. | |
344 | * Make an exception if this is the only connected station. In this | |
345 | * case FW-memory congestion is not a problem. | |
346 | */ | |
347 | else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) | |
6e8cd331 | 348 | wl12xx_ps_link_start(wl, wlvif, hlid, true); |
b622d992 AN |
349 | } |
350 | ||
9b17f1b3 | 351 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, |
c7ffb902 | 352 | struct wl12xx_vif *wlvif, |
0afd04e5 | 353 | struct wl_fw_status_2 *status) |
b622d992 | 354 | { |
c7ffb902 | 355 | struct wl1271_link *lnk; |
b622d992 | 356 | u32 cur_fw_ps_map; |
9b17f1b3 AN |
357 | u8 hlid, cnt; |
358 | ||
359 | /* TODO: also use link_fast_bitmap here */ | |
b622d992 AN |
360 | |
361 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); | |
362 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { | |
363 | wl1271_debug(DEBUG_PSM, | |
364 | "link ps prev 0x%x cur 0x%x changed 0x%x", | |
365 | wl->ap_fw_ps_map, cur_fw_ps_map, | |
366 | wl->ap_fw_ps_map ^ cur_fw_ps_map); | |
367 | ||
368 | wl->ap_fw_ps_map = cur_fw_ps_map; | |
369 | } | |
370 | ||
c7ffb902 EP |
371 | for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) { |
372 | lnk = &wl->links[hlid]; | |
6bac40a6 AN |
373 | cnt = status->counters.tx_lnk_free_pkts[hlid] - |
374 | lnk->prev_freed_pkts; | |
b622d992 | 375 | |
6bac40a6 | 376 | lnk->prev_freed_pkts = status->counters.tx_lnk_free_pkts[hlid]; |
c7ffb902 | 377 | lnk->allocated_pkts -= cnt; |
9b17f1b3 | 378 | |
6e8cd331 EP |
379 | wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, |
380 | lnk->allocated_pkts); | |
b622d992 AN |
381 | } |
382 | } | |
383 | ||
8b7c0fc3 IY |
384 | static int wlcore_fw_status(struct wl1271 *wl, |
385 | struct wl_fw_status_1 *status_1, | |
386 | struct wl_fw_status_2 *status_2) | |
f5fc0f86 | 387 | { |
6e8cd331 | 388 | struct wl12xx_vif *wlvif; |
ac5e1e39 | 389 | struct timespec ts; |
13b107dd | 390 | u32 old_tx_blk_count = wl->tx_blocks_available; |
4d56ad9c | 391 | int avail, freed_blocks; |
bf54e301 | 392 | int i; |
6bac40a6 | 393 | size_t status_len; |
8b7c0fc3 | 394 | int ret; |
6bac40a6 | 395 | |
0afd04e5 AN |
396 | status_len = WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
397 | sizeof(*status_2) + wl->fw_status_priv_len; | |
f5fc0f86 | 398 | |
8b7c0fc3 IY |
399 | ret = wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status_1, |
400 | status_len, false); | |
401 | if (ret < 0) | |
402 | return ret; | |
13b107dd | 403 | |
f5fc0f86 LC |
404 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " |
405 | "drv_rx_counter = %d, tx_results_counter = %d)", | |
0afd04e5 AN |
406 | status_1->intr, |
407 | status_1->fw_rx_counter, | |
408 | status_1->drv_rx_counter, | |
409 | status_1->tx_results_counter); | |
f5fc0f86 | 410 | |
bf54e301 AN |
411 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
412 | /* prevent wrap-around in freed-packets counter */ | |
742246f8 | 413 | wl->tx_allocated_pkts[i] -= |
0afd04e5 | 414 | (status_2->counters.tx_released_pkts[i] - |
bf54e301 AN |
415 | wl->tx_pkts_freed[i]) & 0xff; |
416 | ||
0afd04e5 | 417 | wl->tx_pkts_freed[i] = status_2->counters.tx_released_pkts[i]; |
bf54e301 AN |
418 | } |
419 | ||
bdf91cfa AN |
420 | /* prevent wrap-around in total blocks counter */ |
421 | if (likely(wl->tx_blocks_freed <= | |
0afd04e5 AN |
422 | le32_to_cpu(status_2->total_released_blks))) |
423 | freed_blocks = le32_to_cpu(status_2->total_released_blks) - | |
bdf91cfa AN |
424 | wl->tx_blocks_freed; |
425 | else | |
426 | freed_blocks = 0x100000000LL - wl->tx_blocks_freed + | |
0afd04e5 | 427 | le32_to_cpu(status_2->total_released_blks); |
bdf91cfa | 428 | |
0afd04e5 | 429 | wl->tx_blocks_freed = le32_to_cpu(status_2->total_released_blks); |
13b107dd | 430 | |
7bb5d6ce AN |
431 | wl->tx_allocated_blocks -= freed_blocks; |
432 | ||
55df5afb AN |
433 | /* |
434 | * If the FW freed some blocks: | |
435 | * If we still have allocated blocks - re-arm the timer, Tx is | |
436 | * not stuck. Otherwise, cancel the timer (no Tx currently). | |
437 | */ | |
438 | if (freed_blocks) { | |
439 | if (wl->tx_allocated_blocks) | |
440 | wl12xx_rearm_tx_watchdog_locked(wl); | |
441 | else | |
442 | cancel_delayed_work(&wl->tx_watchdog_work); | |
443 | } | |
444 | ||
0afd04e5 | 445 | avail = le32_to_cpu(status_2->tx_total) - wl->tx_allocated_blocks; |
13b107dd | 446 | |
4d56ad9c EP |
447 | /* |
448 | * The FW might change the total number of TX memblocks before | |
449 | * we get a notification about blocks being released. Thus, the | |
450 | * available blocks calculation might yield a temporary result | |
451 | * which is lower than the actual available blocks. Keeping in | |
452 | * mind that only blocks that were allocated can be moved from | |
453 | * TX to RX, tx_blocks_available should never decrease here. | |
454 | */ | |
455 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, | |
456 | avail); | |
f5fc0f86 | 457 | |
a522550a | 458 | /* if more blocks are available now, tx work can be scheduled */ |
13b107dd | 459 | if (wl->tx_blocks_available > old_tx_blk_count) |
a522550a | 460 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
f5fc0f86 | 461 | |
4d56ad9c | 462 | /* for AP update num of allocated TX blocks per link and ps status */ |
6e8cd331 | 463 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
0afd04e5 | 464 | wl12xx_irq_update_links_status(wl, wlvif, status_2); |
6e8cd331 | 465 | } |
4d56ad9c | 466 | |
f5fc0f86 | 467 | /* update the host-chipset time offset */ |
ac5e1e39 JO |
468 | getnstimeofday(&ts); |
469 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - | |
0afd04e5 | 470 | (s64)le32_to_cpu(status_2->fw_localtime); |
8b7c0fc3 IY |
471 | |
472 | return 0; | |
f5fc0f86 LC |
473 | } |
474 | ||
a620865e IY |
475 | static void wl1271_flush_deferred_work(struct wl1271 *wl) |
476 | { | |
477 | struct sk_buff *skb; | |
478 | ||
479 | /* Pass all received frames to the network stack */ | |
480 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) | |
481 | ieee80211_rx_ni(wl->hw, skb); | |
482 | ||
483 | /* Return sent skbs to the network stack */ | |
484 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) | |
c27d3acc | 485 | ieee80211_tx_status_ni(wl->hw, skb); |
a620865e IY |
486 | } |
487 | ||
488 | static void wl1271_netstack_work(struct work_struct *work) | |
489 | { | |
490 | struct wl1271 *wl = | |
491 | container_of(work, struct wl1271, netstack_work); | |
492 | ||
493 | do { | |
494 | wl1271_flush_deferred_work(wl); | |
495 | } while (skb_queue_len(&wl->deferred_rx_queue)); | |
496 | } | |
1e73eb62 | 497 | |
a620865e IY |
498 | #define WL1271_IRQ_MAX_LOOPS 256 |
499 | ||
b5b45b3c | 500 | static int wlcore_irq_locked(struct wl1271 *wl) |
f5fc0f86 | 501 | { |
b5b45b3c | 502 | int ret = 0; |
c15f63bf | 503 | u32 intr; |
1e73eb62 | 504 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
a620865e IY |
505 | bool done = false; |
506 | unsigned int defer_count; | |
b07d4037 IY |
507 | unsigned long flags; |
508 | ||
341b7cde IY |
509 | /* |
510 | * In case edge triggered interrupt must be used, we cannot iterate | |
511 | * more than once without introducing race conditions with the hardirq. | |
512 | */ | |
513 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | |
514 | loopcount = 1; | |
515 | ||
f5fc0f86 LC |
516 | wl1271_debug(DEBUG_IRQ, "IRQ work"); |
517 | ||
4cc53383 | 518 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
f5fc0f86 LC |
519 | goto out; |
520 | ||
a620865e | 521 | ret = wl1271_ps_elp_wakeup(wl); |
f5fc0f86 LC |
522 | if (ret < 0) |
523 | goto out; | |
524 | ||
a620865e IY |
525 | while (!done && loopcount--) { |
526 | /* | |
527 | * In order to avoid a race with the hardirq, clear the flag | |
528 | * before acknowledging the chip. Since the mutex is held, | |
529 | * wl1271_ps_elp_wakeup cannot be called concurrently. | |
530 | */ | |
531 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | |
532 | smp_mb__after_clear_bit(); | |
1e73eb62 | 533 | |
8b7c0fc3 | 534 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
b5b45b3c | 535 | if (ret < 0) |
8b7c0fc3 | 536 | goto out; |
53d67a50 AN |
537 | |
538 | wlcore_hw_tx_immediate_compl(wl); | |
539 | ||
0afd04e5 | 540 | intr = le32_to_cpu(wl->fw_status_1->intr); |
f5755fe9 | 541 | intr &= WLCORE_ALL_INTR_MASK; |
1e73eb62 | 542 | if (!intr) { |
a620865e | 543 | done = true; |
1e73eb62 JO |
544 | continue; |
545 | } | |
f5fc0f86 | 546 | |
ccc83b04 | 547 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
f5755fe9 IR |
548 | wl1271_error("HW watchdog interrupt received! starting recovery."); |
549 | wl->watchdog_recovery = true; | |
b5b45b3c | 550 | ret = -EIO; |
f5755fe9 IR |
551 | |
552 | /* restarting the chip. ignore any other interrupt. */ | |
553 | goto out; | |
554 | } | |
555 | ||
556 | if (unlikely(intr & WL1271_ACX_SW_INTR_WATCHDOG)) { | |
557 | wl1271_error("SW watchdog interrupt received! " | |
ccc83b04 | 558 | "starting recovery."); |
afbe3718 | 559 | wl->watchdog_recovery = true; |
b5b45b3c | 560 | ret = -EIO; |
ccc83b04 EP |
561 | |
562 | /* restarting the chip. ignore any other interrupt. */ | |
563 | goto out; | |
564 | } | |
565 | ||
a620865e | 566 | if (likely(intr & WL1271_ACX_INTR_DATA)) { |
1e73eb62 | 567 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
1fd2794f | 568 | |
045b9b5f | 569 | ret = wlcore_rx(wl, wl->fw_status_1); |
b5b45b3c | 570 | if (ret < 0) |
045b9b5f | 571 | goto out; |
f5fc0f86 | 572 | |
a522550a | 573 | /* Check if any tx blocks were freed */ |
b07d4037 | 574 | spin_lock_irqsave(&wl->wl_lock, flags); |
a522550a | 575 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
f1a46384 | 576 | wl1271_tx_total_queue_count(wl) > 0) { |
b07d4037 | 577 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
a522550a IY |
578 | /* |
579 | * In order to avoid starvation of the TX path, | |
580 | * call the work function directly. | |
581 | */ | |
eb96f841 | 582 | ret = wlcore_tx_work_locked(wl); |
b5b45b3c | 583 | if (ret < 0) |
eb96f841 | 584 | goto out; |
b07d4037 IY |
585 | } else { |
586 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
a522550a IY |
587 | } |
588 | ||
8aad2464 | 589 | /* check for tx results */ |
045b9b5f | 590 | ret = wlcore_hw_tx_delayed_compl(wl); |
b5b45b3c | 591 | if (ret < 0) |
045b9b5f | 592 | goto out; |
a620865e IY |
593 | |
594 | /* Make sure the deferred queues don't get too long */ | |
595 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + | |
596 | skb_queue_len(&wl->deferred_rx_queue); | |
597 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) | |
598 | wl1271_flush_deferred_work(wl); | |
1e73eb62 | 599 | } |
f5fc0f86 | 600 | |
1e73eb62 JO |
601 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
602 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); | |
045b9b5f | 603 | ret = wl1271_event_handle(wl, 0); |
b5b45b3c | 604 | if (ret < 0) |
045b9b5f | 605 | goto out; |
1e73eb62 | 606 | } |
f5fc0f86 | 607 | |
1e73eb62 JO |
608 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
609 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); | |
045b9b5f | 610 | ret = wl1271_event_handle(wl, 1); |
b5b45b3c | 611 | if (ret < 0) |
045b9b5f | 612 | goto out; |
1e73eb62 | 613 | } |
f5fc0f86 | 614 | |
1e73eb62 JO |
615 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
616 | wl1271_debug(DEBUG_IRQ, | |
617 | "WL1271_ACX_INTR_INIT_COMPLETE"); | |
f5fc0f86 | 618 | |
1e73eb62 JO |
619 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
620 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); | |
c15f63bf | 621 | } |
f5fc0f86 | 622 | |
f5fc0f86 LC |
623 | wl1271_ps_elp_sleep(wl); |
624 | ||
625 | out: | |
b5b45b3c AN |
626 | return ret; |
627 | } | |
628 | ||
629 | static irqreturn_t wlcore_irq(int irq, void *cookie) | |
630 | { | |
631 | int ret; | |
632 | unsigned long flags; | |
633 | struct wl1271 *wl = cookie; | |
634 | ||
635 | /* TX might be handled here, avoid redundant work */ | |
636 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | |
637 | cancel_work_sync(&wl->tx_work); | |
638 | ||
639 | mutex_lock(&wl->mutex); | |
640 | ||
641 | ret = wlcore_irq_locked(wl); | |
642 | if (ret) | |
643 | wl12xx_queue_recovery_work(wl); | |
644 | ||
b07d4037 IY |
645 | spin_lock_irqsave(&wl->wl_lock, flags); |
646 | /* In case TX was not handled here, queue TX work */ | |
647 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | |
648 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | |
f1a46384 | 649 | wl1271_tx_total_queue_count(wl) > 0) |
b07d4037 IY |
650 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
651 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
652 | ||
f5fc0f86 | 653 | mutex_unlock(&wl->mutex); |
a620865e IY |
654 | |
655 | return IRQ_HANDLED; | |
f5fc0f86 LC |
656 | } |
657 | ||
4549d09c EP |
658 | struct vif_counter_data { |
659 | u8 counter; | |
660 | ||
661 | struct ieee80211_vif *cur_vif; | |
662 | bool cur_vif_running; | |
663 | }; | |
664 | ||
665 | static void wl12xx_vif_count_iter(void *data, u8 *mac, | |
666 | struct ieee80211_vif *vif) | |
667 | { | |
668 | struct vif_counter_data *counter = data; | |
669 | ||
670 | counter->counter++; | |
671 | if (counter->cur_vif == vif) | |
672 | counter->cur_vif_running = true; | |
673 | } | |
674 | ||
675 | /* caller must not hold wl->mutex, as it might deadlock */ | |
676 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, | |
677 | struct ieee80211_vif *cur_vif, | |
678 | struct vif_counter_data *data) | |
679 | { | |
680 | memset(data, 0, sizeof(*data)); | |
681 | data->cur_vif = cur_vif; | |
682 | ||
683 | ieee80211_iterate_active_interfaces(hw, | |
684 | wl12xx_vif_count_iter, data); | |
685 | } | |
686 | ||
3fcdab70 | 687 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) |
f5fc0f86 LC |
688 | { |
689 | const struct firmware *fw; | |
166d504e | 690 | const char *fw_name; |
3fcdab70 | 691 | enum wl12xx_fw_type fw_type; |
f5fc0f86 LC |
692 | int ret; |
693 | ||
3fcdab70 EP |
694 | if (plt) { |
695 | fw_type = WL12XX_FW_TYPE_PLT; | |
6f7dd16c | 696 | fw_name = wl->plt_fw_name; |
3fcdab70 | 697 | } else { |
4549d09c EP |
698 | /* |
699 | * we can't call wl12xx_get_vif_count() here because | |
700 | * wl->mutex is taken, so use the cached last_vif_count value | |
701 | */ | |
9b1a0a77 | 702 | if (wl->last_vif_count > 1 && wl->mr_fw_name) { |
4549d09c | 703 | fw_type = WL12XX_FW_TYPE_MULTI; |
6f7dd16c | 704 | fw_name = wl->mr_fw_name; |
4549d09c EP |
705 | } else { |
706 | fw_type = WL12XX_FW_TYPE_NORMAL; | |
6f7dd16c | 707 | fw_name = wl->sr_fw_name; |
4549d09c | 708 | } |
3fcdab70 EP |
709 | } |
710 | ||
711 | if (wl->fw_type == fw_type) | |
712 | return 0; | |
166d504e AN |
713 | |
714 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); | |
715 | ||
a390e85c | 716 | ret = request_firmware(&fw, fw_name, wl->dev); |
f5fc0f86 LC |
717 | |
718 | if (ret < 0) { | |
35898935 | 719 | wl1271_error("could not get firmware %s: %d", fw_name, ret); |
f5fc0f86 LC |
720 | return ret; |
721 | } | |
722 | ||
723 | if (fw->size % 4) { | |
724 | wl1271_error("firmware size is not multiple of 32 bits: %zu", | |
725 | fw->size); | |
726 | ret = -EILSEQ; | |
727 | goto out; | |
728 | } | |
729 | ||
166d504e | 730 | vfree(wl->fw); |
3fcdab70 | 731 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
f5fc0f86 | 732 | wl->fw_len = fw->size; |
1fba4974 | 733 | wl->fw = vmalloc(wl->fw_len); |
f5fc0f86 LC |
734 | |
735 | if (!wl->fw) { | |
736 | wl1271_error("could not allocate memory for the firmware"); | |
737 | ret = -ENOMEM; | |
738 | goto out; | |
739 | } | |
740 | ||
741 | memcpy(wl->fw, fw->data, wl->fw_len); | |
f5fc0f86 | 742 | ret = 0; |
3fcdab70 | 743 | wl->fw_type = fw_type; |
f5fc0f86 LC |
744 | out: |
745 | release_firmware(fw); | |
746 | ||
747 | return ret; | |
748 | } | |
749 | ||
baacb9ae IY |
750 | void wl12xx_queue_recovery_work(struct wl1271 *wl) |
751 | { | |
680c6055 ES |
752 | WARN_ON(!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
753 | ||
b666bb7f | 754 | /* Avoid a recursive recovery */ |
792a58a8 | 755 | if (wl->state == WLCORE_STATE_ON) { |
4cc53383 | 756 | wl->state = WLCORE_STATE_RESTARTING; |
792a58a8 | 757 | set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
b666bb7f | 758 | wlcore_disable_interrupts_nosync(wl); |
baacb9ae | 759 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
b666bb7f | 760 | } |
baacb9ae IY |
761 | } |
762 | ||
95dac04f IY |
763 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) |
764 | { | |
765 | size_t len = 0; | |
766 | ||
767 | /* The FW log is a length-value list, find where the log end */ | |
768 | while (len < maxlen) { | |
769 | if (memblock[len] == 0) | |
770 | break; | |
771 | if (len + memblock[len] + 1 > maxlen) | |
772 | break; | |
773 | len += memblock[len] + 1; | |
774 | } | |
775 | ||
776 | /* Make sure we have enough room */ | |
777 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); | |
778 | ||
779 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ | |
780 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); | |
781 | wl->fwlog_size += len; | |
782 | ||
783 | return len; | |
784 | } | |
785 | ||
1e41213f IC |
786 | #define WLCORE_FW_LOG_END 0x2000000 |
787 | ||
95dac04f IY |
788 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) |
789 | { | |
790 | u32 addr; | |
1e41213f IC |
791 | u32 offset; |
792 | u32 end_of_log; | |
95dac04f | 793 | u8 *block; |
8b7c0fc3 | 794 | int ret; |
95dac04f | 795 | |
6f7dd16c | 796 | if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) || |
95dac04f IY |
797 | (wl->conf.fwlog.mem_blocks == 0)) |
798 | return; | |
799 | ||
800 | wl1271_info("Reading FW panic log"); | |
801 | ||
802 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); | |
803 | if (!block) | |
804 | return; | |
805 | ||
806 | /* | |
807 | * Make sure the chip is awake and the logger isn't active. | |
847cbebd EP |
808 | * Do not send a stop fwlog command if the fw is hanged or if |
809 | * dbgpins are used (due to some fw bug). | |
95dac04f | 810 | */ |
1e41213f | 811 | if (wl1271_ps_elp_wakeup(wl)) |
afbe3718 | 812 | goto out; |
847cbebd EP |
813 | if (!wl->watchdog_recovery && |
814 | wl->conf.fwlog.output != WL12XX_FWLOG_OUTPUT_DBG_PINS) | |
1e41213f | 815 | wl12xx_cmd_stop_fwlog(wl); |
95dac04f IY |
816 | |
817 | /* Read the first memory block address */ | |
8b7c0fc3 IY |
818 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
819 | if (ret < 0) | |
95dac04f IY |
820 | goto out; |
821 | ||
1e41213f IC |
822 | addr = le32_to_cpu(wl->fw_status_2->log_start_addr); |
823 | if (!addr) | |
95dac04f IY |
824 | goto out; |
825 | ||
1e41213f IC |
826 | if (wl->conf.fwlog.mode == WL12XX_FWLOG_CONTINUOUS) { |
827 | offset = sizeof(addr) + sizeof(struct wl1271_rx_descriptor); | |
828 | end_of_log = WLCORE_FW_LOG_END; | |
829 | } else { | |
830 | offset = sizeof(addr); | |
831 | end_of_log = addr; | |
832 | } | |
833 | ||
95dac04f | 834 | /* Traverse the memory blocks linked list */ |
95dac04f IY |
835 | do { |
836 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); | |
2b800407 IY |
837 | ret = wlcore_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, |
838 | false); | |
839 | if (ret < 0) | |
840 | goto out; | |
95dac04f IY |
841 | |
842 | /* | |
843 | * Memory blocks are linked to one another. The first 4 bytes | |
844 | * of each memory block hold the hardware address of the next | |
1e41213f IC |
845 | * one. The last memory block points to the first one in |
846 | * on demand mode and is equal to 0x2000000 in continuous mode. | |
95dac04f | 847 | */ |
4d56ad9c | 848 | addr = le32_to_cpup((__le32 *)block); |
1e41213f IC |
849 | if (!wl12xx_copy_fwlog(wl, block + offset, |
850 | WL12XX_HW_BLOCK_SIZE - offset)) | |
95dac04f | 851 | break; |
1e41213f | 852 | } while (addr && (addr != end_of_log)); |
95dac04f IY |
853 | |
854 | wake_up_interruptible(&wl->fwlog_waitq); | |
855 | ||
856 | out: | |
857 | kfree(block); | |
858 | } | |
859 | ||
6134323f IY |
860 | static void wlcore_print_recovery(struct wl1271 *wl) |
861 | { | |
862 | u32 pc = 0; | |
863 | u32 hint_sts = 0; | |
864 | int ret; | |
865 | ||
866 | wl1271_info("Hardware recovery in progress. FW ver: %s", | |
867 | wl->chip.fw_ver_str); | |
868 | ||
869 | /* change partitions momentarily so we can read the FW pc */ | |
b0f0ad39 IY |
870 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
871 | if (ret < 0) | |
872 | return; | |
6134323f IY |
873 | |
874 | ret = wlcore_read_reg(wl, REG_PC_ON_RECOVERY, &pc); | |
875 | if (ret < 0) | |
876 | return; | |
877 | ||
878 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &hint_sts); | |
879 | if (ret < 0) | |
880 | return; | |
881 | ||
882 | wl1271_info("pc: 0x%x, hint_sts: 0x%08x", pc, hint_sts); | |
883 | ||
884 | wlcore_set_partition(wl, &wl->ptable[PART_WORK]); | |
885 | } | |
886 | ||
887 | ||
52b0e7a6 JO |
888 | static void wl1271_recovery_work(struct work_struct *work) |
889 | { | |
890 | struct wl1271 *wl = | |
891 | container_of(work, struct wl1271, recovery_work); | |
48e93e40 | 892 | struct wl12xx_vif *wlvif; |
6e8cd331 | 893 | struct ieee80211_vif *vif; |
52b0e7a6 JO |
894 | |
895 | mutex_lock(&wl->mutex); | |
896 | ||
4cc53383 | 897 | if (wl->state == WLCORE_STATE_OFF || wl->plt) |
f0277434 | 898 | goto out_unlock; |
52b0e7a6 | 899 | |
aafec111 AN |
900 | if (!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) { |
901 | wl12xx_read_fwlog_panic(wl); | |
902 | wlcore_print_recovery(wl); | |
903 | } | |
52b0e7a6 | 904 | |
e9ba7152 EP |
905 | BUG_ON(bug_on_recovery && |
906 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); | |
2a5bff09 | 907 | |
34785be5 AN |
908 | if (no_recovery) { |
909 | wl1271_info("No recovery (chosen on module load). Fw will remain stuck."); | |
34785be5 AN |
910 | goto out_unlock; |
911 | } | |
912 | ||
b992c682 OK |
913 | /* |
914 | * Advance security sequence number to overcome potential progress | |
915 | * in the firmware during recovery. This doens't hurt if the network is | |
916 | * not encrypted. | |
917 | */ | |
48e93e40 | 918 | wl12xx_for_each_wlvif(wl, wlvif) { |
ba8447f6 | 919 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
53d40d0b | 920 | test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
48e93e40 EP |
921 | wlvif->tx_security_seq += |
922 | WL1271_TX_SQN_POST_RECOVERY_PADDING; | |
923 | } | |
b992c682 | 924 | |
7dece1c8 | 925 | /* Prevent spurious TX during FW restart */ |
66396114 | 926 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
7dece1c8 | 927 | |
52b0e7a6 | 928 | /* reboot the chipset */ |
6e8cd331 EP |
929 | while (!list_empty(&wl->wlvif_list)) { |
930 | wlvif = list_first_entry(&wl->wlvif_list, | |
931 | struct wl12xx_vif, list); | |
932 | vif = wl12xx_wlvif_to_vif(wlvif); | |
933 | __wl1271_op_remove_interface(wl, vif, false); | |
934 | } | |
c24ec83b IY |
935 | |
936 | wlcore_op_stop_locked(wl); | |
baacb9ae | 937 | |
52b0e7a6 JO |
938 | ieee80211_restart_hw(wl->hw); |
939 | ||
7dece1c8 AN |
940 | /* |
941 | * Its safe to enable TX now - the queues are stopped after a request | |
942 | * to restart the HW. | |
943 | */ | |
66396114 | 944 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
c24ec83b | 945 | |
f0277434 | 946 | out_unlock: |
b034fd6f AN |
947 | wl->watchdog_recovery = false; |
948 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); | |
52b0e7a6 JO |
949 | mutex_unlock(&wl->mutex); |
950 | } | |
951 | ||
b0f0ad39 | 952 | static int wlcore_fw_wakeup(struct wl1271 *wl) |
f5fc0f86 | 953 | { |
b0f0ad39 | 954 | return wlcore_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP); |
f5fc0f86 LC |
955 | } |
956 | ||
957 | static int wl1271_setup(struct wl1271 *wl) | |
958 | { | |
0afd04e5 | 959 | wl->fw_status_1 = kmalloc(WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
4f64a1e9 LC |
960 | sizeof(*wl->fw_status_2) + |
961 | wl->fw_status_priv_len, GFP_KERNEL); | |
0afd04e5 | 962 | if (!wl->fw_status_1) |
f5fc0f86 LC |
963 | return -ENOMEM; |
964 | ||
0afd04e5 AN |
965 | wl->fw_status_2 = (struct wl_fw_status_2 *) |
966 | (((u8 *) wl->fw_status_1) + | |
967 | WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc)); | |
968 | ||
f5fc0f86 LC |
969 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); |
970 | if (!wl->tx_res_if) { | |
0afd04e5 | 971 | kfree(wl->fw_status_1); |
f5fc0f86 LC |
972 | return -ENOMEM; |
973 | } | |
974 | ||
f5fc0f86 LC |
975 | return 0; |
976 | } | |
977 | ||
30c5dbd1 | 978 | static int wl12xx_set_power_on(struct wl1271 *wl) |
f5fc0f86 | 979 | { |
30c5dbd1 | 980 | int ret; |
f5fc0f86 | 981 | |
01ac17ec | 982 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
2cc78ff7 OBC |
983 | ret = wl1271_power_on(wl); |
984 | if (ret < 0) | |
985 | goto out; | |
f5fc0f86 | 986 | msleep(WL1271_POWER_ON_SLEEP); |
9b280722 TP |
987 | wl1271_io_reset(wl); |
988 | wl1271_io_init(wl); | |
f5fc0f86 | 989 | |
b0f0ad39 IY |
990 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
991 | if (ret < 0) | |
992 | goto fail; | |
f5fc0f86 LC |
993 | |
994 | /* ELP module wake up */ | |
b0f0ad39 IY |
995 | ret = wlcore_fw_wakeup(wl); |
996 | if (ret < 0) | |
997 | goto fail; | |
f5fc0f86 | 998 | |
30c5dbd1 LC |
999 | out: |
1000 | return ret; | |
b0f0ad39 IY |
1001 | |
1002 | fail: | |
1003 | wl1271_power_off(wl); | |
1004 | return ret; | |
30c5dbd1 | 1005 | } |
f5fc0f86 | 1006 | |
3fcdab70 | 1007 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) |
30c5dbd1 LC |
1008 | { |
1009 | int ret = 0; | |
1010 | ||
1011 | ret = wl12xx_set_power_on(wl); | |
1012 | if (ret < 0) | |
1013 | goto out; | |
f5fc0f86 | 1014 | |
e62c9ce4 LC |
1015 | /* |
1016 | * For wl127x based devices we could use the default block | |
1017 | * size (512 bytes), but due to a bug in the sdio driver, we | |
1018 | * need to set it explicitly after the chip is powered on. To | |
1019 | * simplify the code and since the performance impact is | |
1020 | * negligible, we use the same block size for all different | |
1021 | * chip types. | |
b5d6d9b2 LC |
1022 | * |
1023 | * Check if the bus supports blocksize alignment and, if it | |
1024 | * doesn't, make sure we don't have the quirk. | |
e62c9ce4 | 1025 | */ |
b5d6d9b2 LC |
1026 | if (!wl1271_set_block_size(wl)) |
1027 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; | |
f5fc0f86 | 1028 | |
6f7dd16c | 1029 | /* TODO: make sure the lower driver has set things up correctly */ |
0830ceed | 1030 | |
6f7dd16c LC |
1031 | ret = wl1271_setup(wl); |
1032 | if (ret < 0) | |
9ccd9217 | 1033 | goto out; |
f5fc0f86 | 1034 | |
3fcdab70 EP |
1035 | ret = wl12xx_fetch_firmware(wl, plt); |
1036 | if (ret < 0) | |
1037 | goto out; | |
f5fc0f86 | 1038 | |
f5fc0f86 LC |
1039 | out: |
1040 | return ret; | |
1041 | } | |
1042 | ||
7019c80e | 1043 | int wl1271_plt_start(struct wl1271 *wl, const enum plt_mode plt_mode) |
f5fc0f86 | 1044 | { |
9ccd9217 | 1045 | int retries = WL1271_BOOT_RETRIES; |
6f07b72a | 1046 | struct wiphy *wiphy = wl->hw->wiphy; |
7019c80e YS |
1047 | |
1048 | static const char* const PLT_MODE[] = { | |
1049 | "PLT_OFF", | |
1050 | "PLT_ON", | |
1051 | "PLT_FEM_DETECT" | |
1052 | }; | |
1053 | ||
f5fc0f86 LC |
1054 | int ret; |
1055 | ||
1056 | mutex_lock(&wl->mutex); | |
1057 | ||
1058 | wl1271_notice("power up"); | |
1059 | ||
4cc53383 | 1060 | if (wl->state != WLCORE_STATE_OFF) { |
f5fc0f86 LC |
1061 | wl1271_error("cannot go into PLT state because not " |
1062 | "in off state: %d", wl->state); | |
1063 | ret = -EBUSY; | |
1064 | goto out; | |
1065 | } | |
1066 | ||
7019c80e YS |
1067 | /* Indicate to lower levels that we are now in PLT mode */ |
1068 | wl->plt = true; | |
1069 | wl->plt_mode = plt_mode; | |
1070 | ||
9ccd9217 JO |
1071 | while (retries) { |
1072 | retries--; | |
3fcdab70 | 1073 | ret = wl12xx_chip_wakeup(wl, true); |
9ccd9217 JO |
1074 | if (ret < 0) |
1075 | goto power_off; | |
f5fc0f86 | 1076 | |
c331b344 | 1077 | ret = wl->ops->plt_init(wl); |
9ccd9217 JO |
1078 | if (ret < 0) |
1079 | goto power_off; | |
eb5b28d0 | 1080 | |
4cc53383 | 1081 | wl->state = WLCORE_STATE_ON; |
7019c80e YS |
1082 | wl1271_notice("firmware booted in PLT mode %s (%s)", |
1083 | PLT_MODE[plt_mode], | |
4b7fac77 | 1084 | wl->chip.fw_ver_str); |
e7ddf549 | 1085 | |
6f07b72a GK |
1086 | /* update hw/fw version info in wiphy struct */ |
1087 | wiphy->hw_version = wl->chip.id; | |
1088 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, | |
1089 | sizeof(wiphy->fw_version)); | |
1090 | ||
9ccd9217 | 1091 | goto out; |
eb5b28d0 | 1092 | |
9ccd9217 JO |
1093 | power_off: |
1094 | wl1271_power_off(wl); | |
1095 | } | |
f5fc0f86 | 1096 | |
7019c80e YS |
1097 | wl->plt = false; |
1098 | wl->plt_mode = PLT_OFF; | |
1099 | ||
9ccd9217 JO |
1100 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
1101 | WL1271_BOOT_RETRIES); | |
f5fc0f86 LC |
1102 | out: |
1103 | mutex_unlock(&wl->mutex); | |
1104 | ||
1105 | return ret; | |
1106 | } | |
1107 | ||
f3df1331 | 1108 | int wl1271_plt_stop(struct wl1271 *wl) |
f5fc0f86 LC |
1109 | { |
1110 | int ret = 0; | |
1111 | ||
f5fc0f86 LC |
1112 | wl1271_notice("power down"); |
1113 | ||
46b0cc9f IY |
1114 | /* |
1115 | * Interrupts must be disabled before setting the state to OFF. | |
1116 | * Otherwise, the interrupt handler might be called and exit without | |
1117 | * reading the interrupt status. | |
1118 | */ | |
dd5512eb | 1119 | wlcore_disable_interrupts(wl); |
f3df1331 | 1120 | mutex_lock(&wl->mutex); |
3fcdab70 | 1121 | if (!wl->plt) { |
f3df1331 | 1122 | mutex_unlock(&wl->mutex); |
46b0cc9f IY |
1123 | |
1124 | /* | |
1125 | * This will not necessarily enable interrupts as interrupts | |
1126 | * may have been disabled when op_stop was called. It will, | |
1127 | * however, balance the above call to disable_interrupts(). | |
1128 | */ | |
dd5512eb | 1129 | wlcore_enable_interrupts(wl); |
46b0cc9f | 1130 | |
f5fc0f86 LC |
1131 | wl1271_error("cannot power down because not in PLT " |
1132 | "state: %d", wl->state); | |
1133 | ret = -EBUSY; | |
1134 | goto out; | |
1135 | } | |
1136 | ||
f5fc0f86 | 1137 | mutex_unlock(&wl->mutex); |
f3df1331 | 1138 | |
a620865e IY |
1139 | wl1271_flush_deferred_work(wl); |
1140 | cancel_work_sync(&wl->netstack_work); | |
52b0e7a6 | 1141 | cancel_work_sync(&wl->recovery_work); |
f6fbeccd | 1142 | cancel_delayed_work_sync(&wl->elp_work); |
55df5afb | 1143 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
a454969e IY |
1144 | |
1145 | mutex_lock(&wl->mutex); | |
1146 | wl1271_power_off(wl); | |
f6fbeccd | 1147 | wl->flags = 0; |
2f18cf7c | 1148 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
4cc53383 | 1149 | wl->state = WLCORE_STATE_OFF; |
3fcdab70 | 1150 | wl->plt = false; |
7019c80e | 1151 | wl->plt_mode = PLT_OFF; |
f6fbeccd | 1152 | wl->rx_counter = 0; |
a454969e IY |
1153 | mutex_unlock(&wl->mutex); |
1154 | ||
4ae3fa87 JO |
1155 | out: |
1156 | return ret; | |
1157 | } | |
1158 | ||
36323f81 TH |
1159 | static void wl1271_op_tx(struct ieee80211_hw *hw, |
1160 | struct ieee80211_tx_control *control, | |
1161 | struct sk_buff *skb) | |
f5fc0f86 LC |
1162 | { |
1163 | struct wl1271 *wl = hw->priv; | |
a8ab39a4 EP |
1164 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
1165 | struct ieee80211_vif *vif = info->control.vif; | |
0f168014 | 1166 | struct wl12xx_vif *wlvif = NULL; |
830fb67b | 1167 | unsigned long flags; |
708bb3cf | 1168 | int q, mapping; |
d6a3cc2e | 1169 | u8 hlid; |
f5fc0f86 | 1170 | |
0f168014 EP |
1171 | if (vif) |
1172 | wlvif = wl12xx_vif_to_data(vif); | |
1173 | ||
708bb3cf AN |
1174 | mapping = skb_get_queue_mapping(skb); |
1175 | q = wl1271_tx_get_queue(mapping); | |
b07d4037 | 1176 | |
36323f81 | 1177 | hlid = wl12xx_tx_get_hlid(wl, wlvif, skb, control->sta); |
b07d4037 | 1178 | |
830fb67b | 1179 | spin_lock_irqsave(&wl->wl_lock, flags); |
b07d4037 | 1180 | |
66396114 AN |
1181 | /* |
1182 | * drop the packet if the link is invalid or the queue is stopped | |
1183 | * for any reason but watermark. Watermark is a "soft"-stop so we | |
1184 | * allow these packets through. | |
1185 | */ | |
d6a3cc2e | 1186 | if (hlid == WL12XX_INVALID_LINK_ID || |
66396114 AN |
1187 | (wlvif && !test_bit(hlid, wlvif->links_map)) || |
1188 | (wlcore_is_queue_stopped(wl, q) && | |
1189 | !wlcore_is_queue_stopped_by_reason(wl, q, | |
1190 | WLCORE_QUEUE_STOP_REASON_WATERMARK))) { | |
d6a3cc2e | 1191 | wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); |
5de8eef4 | 1192 | ieee80211_free_txskb(hw, skb); |
d6a3cc2e | 1193 | goto out; |
a8c0ddb5 | 1194 | } |
f5fc0f86 | 1195 | |
8ccd16e6 EP |
1196 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d", |
1197 | hlid, q, skb->len); | |
d6a3cc2e EP |
1198 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); |
1199 | ||
04b4d69c AN |
1200 | wl->tx_queue_count[q]++; |
1201 | ||
1202 | /* | |
1203 | * The workqueue is slow to process the tx_queue and we need stop | |
1204 | * the queue here, otherwise the queue will get too long. | |
1205 | */ | |
8cdc44aa AN |
1206 | if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK && |
1207 | !wlcore_is_queue_stopped_by_reason(wl, q, | |
1208 | WLCORE_QUEUE_STOP_REASON_WATERMARK)) { | |
04b4d69c | 1209 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); |
66396114 AN |
1210 | wlcore_stop_queue_locked(wl, q, |
1211 | WLCORE_QUEUE_STOP_REASON_WATERMARK); | |
04b4d69c AN |
1212 | } |
1213 | ||
f5fc0f86 LC |
1214 | /* |
1215 | * The chip specific setup must run before the first TX packet - | |
1216 | * before that, the tx_work will not be initialized! | |
1217 | */ | |
1218 | ||
b07d4037 IY |
1219 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
1220 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) | |
a522550a | 1221 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
b07d4037 | 1222 | |
04216da3 | 1223 | out: |
b07d4037 | 1224 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
f5fc0f86 LC |
1225 | } |
1226 | ||
ae47c45f SL |
1227 | int wl1271_tx_dummy_packet(struct wl1271 *wl) |
1228 | { | |
990f5de7 | 1229 | unsigned long flags; |
14623787 AN |
1230 | int q; |
1231 | ||
1232 | /* no need to queue a new dummy packet if one is already pending */ | |
1233 | if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) | |
1234 | return 0; | |
1235 | ||
1236 | q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); | |
990f5de7 IY |
1237 | |
1238 | spin_lock_irqsave(&wl->wl_lock, flags); | |
1239 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); | |
f1a46384 | 1240 | wl->tx_queue_count[q]++; |
990f5de7 IY |
1241 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
1242 | ||
1243 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ | |
1244 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) | |
eb96f841 | 1245 | return wlcore_tx_work_locked(wl); |
990f5de7 IY |
1246 | |
1247 | /* | |
1248 | * If the FW TX is busy, TX work will be scheduled by the threaded | |
1249 | * interrupt handler function | |
1250 | */ | |
1251 | return 0; | |
1252 | } | |
1253 | ||
1254 | /* | |
1255 | * The size of the dummy packet should be at least 1400 bytes. However, in | |
1256 | * order to minimize the number of bus transactions, aligning it to 512 bytes | |
1257 | * boundaries could be beneficial, performance wise | |
1258 | */ | |
1259 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) | |
1260 | ||
cf27d867 | 1261 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) |
990f5de7 IY |
1262 | { |
1263 | struct sk_buff *skb; | |
ae47c45f | 1264 | struct ieee80211_hdr_3addr *hdr; |
990f5de7 IY |
1265 | unsigned int dummy_packet_size; |
1266 | ||
1267 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - | |
1268 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); | |
ae47c45f | 1269 | |
990f5de7 | 1270 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); |
ae47c45f | 1271 | if (!skb) { |
990f5de7 IY |
1272 | wl1271_warning("Failed to allocate a dummy packet skb"); |
1273 | return NULL; | |
ae47c45f SL |
1274 | } |
1275 | ||
1276 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); | |
1277 | ||
1278 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); | |
1279 | memset(hdr, 0, sizeof(*hdr)); | |
1280 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
990f5de7 IY |
1281 | IEEE80211_STYPE_NULLFUNC | |
1282 | IEEE80211_FCTL_TODS); | |
ae47c45f | 1283 | |
990f5de7 | 1284 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); |
ae47c45f | 1285 | |
18b92ffa LC |
1286 | /* Dummy packets require the TID to be management */ |
1287 | skb->priority = WL1271_TID_MGMT; | |
ae47c45f | 1288 | |
990f5de7 | 1289 | /* Initialize all fields that might be used */ |
86c438f4 | 1290 | skb_set_queue_mapping(skb, 0); |
990f5de7 | 1291 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); |
ae47c45f | 1292 | |
990f5de7 | 1293 | return skb; |
ae47c45f SL |
1294 | } |
1295 | ||
990f5de7 | 1296 | |
f634a4e7 | 1297 | #ifdef CONFIG_PM |
22479972 LC |
1298 | static int |
1299 | wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p) | |
b95d7cef ES |
1300 | { |
1301 | int num_fields = 0, in_field = 0, fields_size = 0; | |
1302 | int i, pattern_len = 0; | |
1303 | ||
1304 | if (!p->mask) { | |
1305 | wl1271_warning("No mask in WoWLAN pattern"); | |
1306 | return -EINVAL; | |
1307 | } | |
1308 | ||
1309 | /* | |
1310 | * The pattern is broken up into segments of bytes at different offsets | |
1311 | * that need to be checked by the FW filter. Each segment is called | |
1312 | * a field in the FW API. We verify that the total number of fields | |
1313 | * required for this pattern won't exceed FW limits (8) | |
1314 | * as well as the total fields buffer won't exceed the FW limit. | |
1315 | * Note that if there's a pattern which crosses Ethernet/IP header | |
1316 | * boundary a new field is required. | |
1317 | */ | |
1318 | for (i = 0; i < p->pattern_len; i++) { | |
1319 | if (test_bit(i, (unsigned long *)p->mask)) { | |
1320 | if (!in_field) { | |
1321 | in_field = 1; | |
1322 | pattern_len = 1; | |
1323 | } else { | |
1324 | if (i == WL1271_RX_FILTER_ETH_HEADER_SIZE) { | |
1325 | num_fields++; | |
1326 | fields_size += pattern_len + | |
1327 | RX_FILTER_FIELD_OVERHEAD; | |
1328 | pattern_len = 1; | |
1329 | } else | |
1330 | pattern_len++; | |
1331 | } | |
1332 | } else { | |
1333 | if (in_field) { | |
1334 | in_field = 0; | |
1335 | fields_size += pattern_len + | |
1336 | RX_FILTER_FIELD_OVERHEAD; | |
1337 | num_fields++; | |
1338 | } | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | if (in_field) { | |
1343 | fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD; | |
1344 | num_fields++; | |
1345 | } | |
1346 | ||
1347 | if (num_fields > WL1271_RX_FILTER_MAX_FIELDS) { | |
1348 | wl1271_warning("RX Filter too complex. Too many segments"); | |
1349 | return -EINVAL; | |
1350 | } | |
1351 | ||
1352 | if (fields_size > WL1271_RX_FILTER_MAX_FIELDS_SIZE) { | |
1353 | wl1271_warning("RX filter pattern is too big"); | |
1354 | return -E2BIG; | |
1355 | } | |
1356 | ||
1357 | return 0; | |
1358 | } | |
1359 | ||
a6eab0c8 ES |
1360 | struct wl12xx_rx_filter *wl1271_rx_filter_alloc(void) |
1361 | { | |
1362 | return kzalloc(sizeof(struct wl12xx_rx_filter), GFP_KERNEL); | |
1363 | } | |
1364 | ||
1365 | void wl1271_rx_filter_free(struct wl12xx_rx_filter *filter) | |
1366 | { | |
1367 | int i; | |
1368 | ||
1369 | if (filter == NULL) | |
1370 | return; | |
1371 | ||
1372 | for (i = 0; i < filter->num_fields; i++) | |
1373 | kfree(filter->fields[i].pattern); | |
1374 | ||
1375 | kfree(filter); | |
1376 | } | |
1377 | ||
1378 | int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter *filter, | |
1379 | u16 offset, u8 flags, | |
1380 | u8 *pattern, u8 len) | |
1381 | { | |
1382 | struct wl12xx_rx_filter_field *field; | |
1383 | ||
1384 | if (filter->num_fields == WL1271_RX_FILTER_MAX_FIELDS) { | |
1385 | wl1271_warning("Max fields per RX filter. can't alloc another"); | |
1386 | return -EINVAL; | |
1387 | } | |
1388 | ||
1389 | field = &filter->fields[filter->num_fields]; | |
1390 | ||
1391 | field->pattern = kzalloc(len, GFP_KERNEL); | |
1392 | if (!field->pattern) { | |
1393 | wl1271_warning("Failed to allocate RX filter pattern"); | |
1394 | return -ENOMEM; | |
1395 | } | |
1396 | ||
1397 | filter->num_fields++; | |
1398 | ||
1399 | field->offset = cpu_to_le16(offset); | |
1400 | field->flags = flags; | |
1401 | field->len = len; | |
1402 | memcpy(field->pattern, pattern, len); | |
1403 | ||
1404 | return 0; | |
1405 | } | |
1406 | ||
1407 | int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter *filter) | |
1408 | { | |
1409 | int i, fields_size = 0; | |
1410 | ||
1411 | for (i = 0; i < filter->num_fields; i++) | |
1412 | fields_size += filter->fields[i].len + | |
1413 | sizeof(struct wl12xx_rx_filter_field) - | |
1414 | sizeof(u8 *); | |
1415 | ||
1416 | return fields_size; | |
1417 | } | |
1418 | ||
1419 | void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter, | |
1420 | u8 *buf) | |
1421 | { | |
1422 | int i; | |
1423 | struct wl12xx_rx_filter_field *field; | |
1424 | ||
1425 | for (i = 0; i < filter->num_fields; i++) { | |
1426 | field = (struct wl12xx_rx_filter_field *)buf; | |
1427 | ||
1428 | field->offset = filter->fields[i].offset; | |
1429 | field->flags = filter->fields[i].flags; | |
1430 | field->len = filter->fields[i].len; | |
1431 | ||
1432 | memcpy(&field->pattern, filter->fields[i].pattern, field->len); | |
1433 | buf += sizeof(struct wl12xx_rx_filter_field) - | |
1434 | sizeof(u8 *) + field->len; | |
1435 | } | |
1436 | } | |
1437 | ||
b95d7cef ES |
1438 | /* |
1439 | * Allocates an RX filter returned through f | |
1440 | * which needs to be freed using rx_filter_free() | |
1441 | */ | |
22479972 | 1442 | static int wl1271_convert_wowlan_pattern_to_rx_filter( |
b95d7cef ES |
1443 | struct cfg80211_wowlan_trig_pkt_pattern *p, |
1444 | struct wl12xx_rx_filter **f) | |
1445 | { | |
1446 | int i, j, ret = 0; | |
1447 | struct wl12xx_rx_filter *filter; | |
1448 | u16 offset; | |
1449 | u8 flags, len; | |
1450 | ||
1451 | filter = wl1271_rx_filter_alloc(); | |
1452 | if (!filter) { | |
1453 | wl1271_warning("Failed to alloc rx filter"); | |
1454 | ret = -ENOMEM; | |
1455 | goto err; | |
1456 | } | |
1457 | ||
1458 | i = 0; | |
1459 | while (i < p->pattern_len) { | |
1460 | if (!test_bit(i, (unsigned long *)p->mask)) { | |
1461 | i++; | |
1462 | continue; | |
1463 | } | |
1464 | ||
1465 | for (j = i; j < p->pattern_len; j++) { | |
1466 | if (!test_bit(j, (unsigned long *)p->mask)) | |
1467 | break; | |
1468 | ||
1469 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE && | |
1470 | j >= WL1271_RX_FILTER_ETH_HEADER_SIZE) | |
1471 | break; | |
1472 | } | |
1473 | ||
1474 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE) { | |
1475 | offset = i; | |
1476 | flags = WL1271_RX_FILTER_FLAG_ETHERNET_HEADER; | |
1477 | } else { | |
1478 | offset = i - WL1271_RX_FILTER_ETH_HEADER_SIZE; | |
1479 | flags = WL1271_RX_FILTER_FLAG_IP_HEADER; | |
1480 | } | |
1481 | ||
1482 | len = j - i; | |
1483 | ||
1484 | ret = wl1271_rx_filter_alloc_field(filter, | |
1485 | offset, | |
1486 | flags, | |
1487 | &p->pattern[i], len); | |
1488 | if (ret) | |
1489 | goto err; | |
1490 | ||
1491 | i = j; | |
1492 | } | |
1493 | ||
1494 | filter->action = FILTER_SIGNAL; | |
1495 | ||
1496 | *f = filter; | |
1497 | return 0; | |
1498 | ||
1499 | err: | |
1500 | wl1271_rx_filter_free(filter); | |
1501 | *f = NULL; | |
1502 | ||
1503 | return ret; | |
1504 | } | |
1505 | ||
1506 | static int wl1271_configure_wowlan(struct wl1271 *wl, | |
1507 | struct cfg80211_wowlan *wow) | |
1508 | { | |
1509 | int i, ret; | |
1510 | ||
1511 | if (!wow || wow->any || !wow->n_patterns) { | |
c439a1ca AN |
1512 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, |
1513 | FILTER_SIGNAL); | |
1514 | if (ret) | |
1515 | goto out; | |
1516 | ||
1517 | ret = wl1271_rx_filter_clear_all(wl); | |
1518 | if (ret) | |
1519 | goto out; | |
1520 | ||
b95d7cef ES |
1521 | return 0; |
1522 | } | |
1523 | ||
1524 | if (WARN_ON(wow->n_patterns > WL1271_MAX_RX_FILTERS)) | |
1525 | return -EINVAL; | |
1526 | ||
1527 | /* Validate all incoming patterns before clearing current FW state */ | |
1528 | for (i = 0; i < wow->n_patterns; i++) { | |
1529 | ret = wl1271_validate_wowlan_pattern(&wow->patterns[i]); | |
1530 | if (ret) { | |
1531 | wl1271_warning("Bad wowlan pattern %d", i); | |
1532 | return ret; | |
1533 | } | |
1534 | } | |
1535 | ||
c439a1ca AN |
1536 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, FILTER_SIGNAL); |
1537 | if (ret) | |
1538 | goto out; | |
1539 | ||
1540 | ret = wl1271_rx_filter_clear_all(wl); | |
1541 | if (ret) | |
1542 | goto out; | |
b95d7cef ES |
1543 | |
1544 | /* Translate WoWLAN patterns into filters */ | |
1545 | for (i = 0; i < wow->n_patterns; i++) { | |
1546 | struct cfg80211_wowlan_trig_pkt_pattern *p; | |
1547 | struct wl12xx_rx_filter *filter = NULL; | |
1548 | ||
1549 | p = &wow->patterns[i]; | |
1550 | ||
1551 | ret = wl1271_convert_wowlan_pattern_to_rx_filter(p, &filter); | |
1552 | if (ret) { | |
1553 | wl1271_warning("Failed to create an RX filter from " | |
1554 | "wowlan pattern %d", i); | |
1555 | goto out; | |
1556 | } | |
1557 | ||
1558 | ret = wl1271_rx_filter_enable(wl, i, 1, filter); | |
1559 | ||
1560 | wl1271_rx_filter_free(filter); | |
1561 | if (ret) | |
1562 | goto out; | |
1563 | } | |
1564 | ||
1565 | ret = wl1271_acx_default_rx_filter_enable(wl, 1, FILTER_DROP); | |
1566 | ||
1567 | out: | |
1568 | return ret; | |
1569 | } | |
1570 | ||
dae728fe | 1571 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, |
b95d7cef ES |
1572 | struct wl12xx_vif *wlvif, |
1573 | struct cfg80211_wowlan *wow) | |
dae728fe ES |
1574 | { |
1575 | int ret = 0; | |
1576 | ||
dae728fe | 1577 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
c56dbd57 | 1578 | goto out; |
dae728fe ES |
1579 | |
1580 | ret = wl1271_ps_elp_wakeup(wl); | |
1581 | if (ret < 0) | |
c56dbd57 | 1582 | goto out; |
dae728fe | 1583 | |
c439a1ca AN |
1584 | ret = wl1271_configure_wowlan(wl, wow); |
1585 | if (ret < 0) | |
1586 | goto out_sleep; | |
1587 | ||
11bc97eb ES |
1588 | if ((wl->conf.conn.suspend_wake_up_event == |
1589 | wl->conf.conn.wake_up_event) && | |
1590 | (wl->conf.conn.suspend_listen_interval == | |
1591 | wl->conf.conn.listen_interval)) | |
1592 | goto out_sleep; | |
1593 | ||
dae728fe ES |
1594 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
1595 | wl->conf.conn.suspend_wake_up_event, | |
1596 | wl->conf.conn.suspend_listen_interval); | |
1597 | ||
1598 | if (ret < 0) | |
1599 | wl1271_error("suspend: set wake up conditions failed: %d", ret); | |
1600 | ||
c439a1ca | 1601 | out_sleep: |
dae728fe | 1602 | wl1271_ps_elp_sleep(wl); |
c56dbd57 | 1603 | out: |
dae728fe ES |
1604 | return ret; |
1605 | ||
1606 | } | |
9439064c | 1607 | |
0603d891 EP |
1608 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, |
1609 | struct wl12xx_vif *wlvif) | |
8a7cf3fe | 1610 | { |
e85d1629 | 1611 | int ret = 0; |
8a7cf3fe | 1612 | |
53d40d0b | 1613 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
c56dbd57 | 1614 | goto out; |
e85d1629 | 1615 | |
8a7cf3fe EP |
1616 | ret = wl1271_ps_elp_wakeup(wl); |
1617 | if (ret < 0) | |
c56dbd57 | 1618 | goto out; |
8a7cf3fe | 1619 | |
0603d891 | 1620 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
8a7cf3fe EP |
1621 | |
1622 | wl1271_ps_elp_sleep(wl); | |
c56dbd57 | 1623 | out: |
8a7cf3fe EP |
1624 | return ret; |
1625 | ||
1626 | } | |
1627 | ||
d2d66c56 | 1628 | static int wl1271_configure_suspend(struct wl1271 *wl, |
b95d7cef ES |
1629 | struct wl12xx_vif *wlvif, |
1630 | struct cfg80211_wowlan *wow) | |
8a7cf3fe | 1631 | { |
dae728fe | 1632 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
b95d7cef | 1633 | return wl1271_configure_suspend_sta(wl, wlvif, wow); |
536129c8 | 1634 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
0603d891 | 1635 | return wl1271_configure_suspend_ap(wl, wlvif); |
8a7cf3fe EP |
1636 | return 0; |
1637 | } | |
1638 | ||
d2d66c56 EP |
1639 | static void wl1271_configure_resume(struct wl1271 *wl, |
1640 | struct wl12xx_vif *wlvif) | |
9439064c | 1641 | { |
dae728fe | 1642 | int ret = 0; |
536129c8 | 1643 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
dae728fe | 1644 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
9439064c | 1645 | |
dae728fe | 1646 | if ((!is_ap) && (!is_sta)) |
9439064c EP |
1647 | return; |
1648 | ||
d49524d3 EP |
1649 | if (is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
1650 | return; | |
1651 | ||
9439064c EP |
1652 | ret = wl1271_ps_elp_wakeup(wl); |
1653 | if (ret < 0) | |
c56dbd57 | 1654 | return; |
9439064c | 1655 | |
dae728fe | 1656 | if (is_sta) { |
b95d7cef ES |
1657 | wl1271_configure_wowlan(wl, NULL); |
1658 | ||
11bc97eb ES |
1659 | if ((wl->conf.conn.suspend_wake_up_event == |
1660 | wl->conf.conn.wake_up_event) && | |
1661 | (wl->conf.conn.suspend_listen_interval == | |
1662 | wl->conf.conn.listen_interval)) | |
1663 | goto out_sleep; | |
1664 | ||
dae728fe ES |
1665 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
1666 | wl->conf.conn.wake_up_event, | |
1667 | wl->conf.conn.listen_interval); | |
1668 | ||
1669 | if (ret < 0) | |
1670 | wl1271_error("resume: wake up conditions failed: %d", | |
1671 | ret); | |
1672 | ||
1673 | } else if (is_ap) { | |
1674 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); | |
1675 | } | |
9439064c | 1676 | |
11bc97eb | 1677 | out_sleep: |
9439064c | 1678 | wl1271_ps_elp_sleep(wl); |
9439064c EP |
1679 | } |
1680 | ||
402e4861 EP |
1681 | static int wl1271_op_suspend(struct ieee80211_hw *hw, |
1682 | struct cfg80211_wowlan *wow) | |
1683 | { | |
1684 | struct wl1271 *wl = hw->priv; | |
6e8cd331 | 1685 | struct wl12xx_vif *wlvif; |
4a859df8 EP |
1686 | int ret; |
1687 | ||
402e4861 | 1688 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); |
b95d7cef | 1689 | WARN_ON(!wow); |
f44e5868 | 1690 | |
96caded8 AN |
1691 | /* we want to perform the recovery before suspending */ |
1692 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { | |
1693 | wl1271_warning("postponing suspend to perform recovery"); | |
1694 | return -EBUSY; | |
1695 | } | |
1696 | ||
b9239b66 AN |
1697 | wl1271_tx_flush(wl); |
1698 | ||
c56dbd57 | 1699 | mutex_lock(&wl->mutex); |
4a859df8 | 1700 | wl->wow_enabled = true; |
6e8cd331 | 1701 | wl12xx_for_each_wlvif(wl, wlvif) { |
b95d7cef | 1702 | ret = wl1271_configure_suspend(wl, wlvif, wow); |
6e8cd331 | 1703 | if (ret < 0) { |
cd840f6a | 1704 | mutex_unlock(&wl->mutex); |
6e8cd331 EP |
1705 | wl1271_warning("couldn't prepare device to suspend"); |
1706 | return ret; | |
1707 | } | |
4a859df8 | 1708 | } |
c56dbd57 | 1709 | mutex_unlock(&wl->mutex); |
4a859df8 EP |
1710 | /* flush any remaining work */ |
1711 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); | |
f44e5868 | 1712 | |
4a859df8 EP |
1713 | /* |
1714 | * disable and re-enable interrupts in order to flush | |
1715 | * the threaded_irq | |
1716 | */ | |
dd5512eb | 1717 | wlcore_disable_interrupts(wl); |
4a859df8 EP |
1718 | |
1719 | /* | |
1720 | * set suspended flag to avoid triggering a new threaded_irq | |
1721 | * work. no need for spinlock as interrupts are disabled. | |
1722 | */ | |
1723 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | |
1724 | ||
dd5512eb | 1725 | wlcore_enable_interrupts(wl); |
4a859df8 | 1726 | flush_work(&wl->tx_work); |
4a859df8 | 1727 | flush_delayed_work(&wl->elp_work); |
f44e5868 | 1728 | |
402e4861 EP |
1729 | return 0; |
1730 | } | |
1731 | ||
1732 | static int wl1271_op_resume(struct ieee80211_hw *hw) | |
1733 | { | |
1734 | struct wl1271 *wl = hw->priv; | |
6e8cd331 | 1735 | struct wl12xx_vif *wlvif; |
4a859df8 | 1736 | unsigned long flags; |
ea0a3cf9 | 1737 | bool run_irq_work = false, pending_recovery; |
725b8277 | 1738 | int ret; |
4a859df8 | 1739 | |
402e4861 EP |
1740 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", |
1741 | wl->wow_enabled); | |
4a859df8 | 1742 | WARN_ON(!wl->wow_enabled); |
f44e5868 EP |
1743 | |
1744 | /* | |
1745 | * re-enable irq_work enqueuing, and call irq_work directly if | |
1746 | * there is a pending work. | |
1747 | */ | |
4a859df8 EP |
1748 | spin_lock_irqsave(&wl->wl_lock, flags); |
1749 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | |
1750 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) | |
1751 | run_irq_work = true; | |
1752 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
9439064c | 1753 | |
725b8277 AN |
1754 | mutex_lock(&wl->mutex); |
1755 | ||
ea0a3cf9 AN |
1756 | /* test the recovery flag before calling any SDIO functions */ |
1757 | pending_recovery = test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, | |
1758 | &wl->flags); | |
1759 | ||
4a859df8 EP |
1760 | if (run_irq_work) { |
1761 | wl1271_debug(DEBUG_MAC80211, | |
1762 | "run postponed irq_work directly"); | |
ea0a3cf9 AN |
1763 | |
1764 | /* don't talk to the HW if recovery is pending */ | |
725b8277 AN |
1765 | if (!pending_recovery) { |
1766 | ret = wlcore_irq_locked(wl); | |
1767 | if (ret) | |
1768 | wl12xx_queue_recovery_work(wl); | |
1769 | } | |
ea0a3cf9 | 1770 | |
dd5512eb | 1771 | wlcore_enable_interrupts(wl); |
f44e5868 | 1772 | } |
c56dbd57 | 1773 | |
ea0a3cf9 AN |
1774 | if (pending_recovery) { |
1775 | wl1271_warning("queuing forgotten recovery on resume"); | |
1776 | ieee80211_queue_work(wl->hw, &wl->recovery_work); | |
1777 | goto out; | |
1778 | } | |
1779 | ||
6e8cd331 EP |
1780 | wl12xx_for_each_wlvif(wl, wlvif) { |
1781 | wl1271_configure_resume(wl, wlvif); | |
1782 | } | |
ea0a3cf9 AN |
1783 | |
1784 | out: | |
ff91afc9 | 1785 | wl->wow_enabled = false; |
c56dbd57 | 1786 | mutex_unlock(&wl->mutex); |
f44e5868 | 1787 | |
402e4861 EP |
1788 | return 0; |
1789 | } | |
f634a4e7 | 1790 | #endif |
402e4861 | 1791 | |
f5fc0f86 | 1792 | static int wl1271_op_start(struct ieee80211_hw *hw) |
1b72aecd JO |
1793 | { |
1794 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); | |
1795 | ||
1796 | /* | |
1797 | * We have to delay the booting of the hardware because | |
1798 | * we need to know the local MAC address before downloading and | |
1799 | * initializing the firmware. The MAC address cannot be changed | |
1800 | * after boot, and without the proper MAC address, the firmware | |
1801 | * will not function properly. | |
1802 | * | |
1803 | * The MAC address is first known when the corresponding interface | |
1804 | * is added. That is where we will initialize the hardware. | |
1805 | */ | |
1806 | ||
d18da7fc | 1807 | return 0; |
1b72aecd JO |
1808 | } |
1809 | ||
c24ec83b | 1810 | static void wlcore_op_stop_locked(struct wl1271 *wl) |
1b72aecd | 1811 | { |
baf6277a EP |
1812 | int i; |
1813 | ||
4cc53383 | 1814 | if (wl->state == WLCORE_STATE_OFF) { |
b666bb7f IY |
1815 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
1816 | &wl->flags)) | |
1817 | wlcore_enable_interrupts(wl); | |
1818 | ||
10c8cd01 EP |
1819 | return; |
1820 | } | |
46b0cc9f | 1821 | |
baf6277a EP |
1822 | /* |
1823 | * this must be before the cancel_work calls below, so that the work | |
1824 | * functions don't perform further work. | |
1825 | */ | |
4cc53383 | 1826 | wl->state = WLCORE_STATE_OFF; |
c24ec83b IY |
1827 | |
1828 | /* | |
1829 | * Use the nosync variant to disable interrupts, so the mutex could be | |
1830 | * held while doing so without deadlocking. | |
1831 | */ | |
1832 | wlcore_disable_interrupts_nosync(wl); | |
1833 | ||
10c8cd01 EP |
1834 | mutex_unlock(&wl->mutex); |
1835 | ||
c24ec83b | 1836 | wlcore_synchronize_interrupts(wl); |
6dbc5fc2 EP |
1837 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
1838 | cancel_work_sync(&wl->recovery_work); | |
baf6277a EP |
1839 | wl1271_flush_deferred_work(wl); |
1840 | cancel_delayed_work_sync(&wl->scan_complete_work); | |
1841 | cancel_work_sync(&wl->netstack_work); | |
1842 | cancel_work_sync(&wl->tx_work); | |
baf6277a | 1843 | cancel_delayed_work_sync(&wl->elp_work); |
55df5afb | 1844 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
baf6277a EP |
1845 | |
1846 | /* let's notify MAC80211 about the remaining pending TX frames */ | |
66396114 | 1847 | wl12xx_tx_reset(wl); |
baf6277a EP |
1848 | mutex_lock(&wl->mutex); |
1849 | ||
1850 | wl1271_power_off(wl); | |
b666bb7f IY |
1851 | /* |
1852 | * In case a recovery was scheduled, interrupts were disabled to avoid | |
1853 | * an interrupt storm. Now that the power is down, it is safe to | |
1854 | * re-enable interrupts to balance the disable depth | |
1855 | */ | |
1856 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) | |
1857 | wlcore_enable_interrupts(wl); | |
baf6277a EP |
1858 | |
1859 | wl->band = IEEE80211_BAND_2GHZ; | |
1860 | ||
1861 | wl->rx_counter = 0; | |
1862 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | |
83d08d3f | 1863 | wl->channel_type = NL80211_CHAN_NO_HT; |
baf6277a EP |
1864 | wl->tx_blocks_available = 0; |
1865 | wl->tx_allocated_blocks = 0; | |
1866 | wl->tx_results_count = 0; | |
1867 | wl->tx_packets_count = 0; | |
1868 | wl->time_offset = 0; | |
baf6277a EP |
1869 | wl->ap_fw_ps_map = 0; |
1870 | wl->ap_ps_map = 0; | |
2f18cf7c | 1871 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
baf6277a EP |
1872 | memset(wl->roles_map, 0, sizeof(wl->roles_map)); |
1873 | memset(wl->links_map, 0, sizeof(wl->links_map)); | |
1874 | memset(wl->roc_map, 0, sizeof(wl->roc_map)); | |
978cd3a0 | 1875 | memset(wl->session_ids, 0, sizeof(wl->session_ids)); |
baf6277a EP |
1876 | wl->active_sta_count = 0; |
1877 | ||
1878 | /* The system link is always allocated */ | |
1879 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); | |
1880 | ||
1881 | /* | |
1882 | * this is performed after the cancel_work calls and the associated | |
1883 | * mutex_lock, so that wl1271_op_add_interface does not accidentally | |
1884 | * get executed before all these vars have been reset. | |
1885 | */ | |
1886 | wl->flags = 0; | |
1887 | ||
1888 | wl->tx_blocks_freed = 0; | |
1889 | ||
1890 | for (i = 0; i < NUM_TX_QUEUES; i++) { | |
1891 | wl->tx_pkts_freed[i] = 0; | |
1892 | wl->tx_allocated_pkts[i] = 0; | |
1893 | } | |
1894 | ||
1895 | wl1271_debugfs_reset(wl); | |
1896 | ||
0afd04e5 AN |
1897 | kfree(wl->fw_status_1); |
1898 | wl->fw_status_1 = NULL; | |
1899 | wl->fw_status_2 = NULL; | |
baf6277a EP |
1900 | kfree(wl->tx_res_if); |
1901 | wl->tx_res_if = NULL; | |
1902 | kfree(wl->target_mem_map); | |
1903 | wl->target_mem_map = NULL; | |
6b70e7eb VG |
1904 | |
1905 | /* | |
1906 | * FW channels must be re-calibrated after recovery, | |
1907 | * clear the last Reg-Domain channel configuration. | |
1908 | */ | |
1909 | memset(wl->reg_ch_conf_last, 0, sizeof(wl->reg_ch_conf_last)); | |
c24ec83b IY |
1910 | } |
1911 | ||
1912 | static void wlcore_op_stop(struct ieee80211_hw *hw) | |
1913 | { | |
1914 | struct wl1271 *wl = hw->priv; | |
1915 | ||
1916 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); | |
1917 | ||
1918 | mutex_lock(&wl->mutex); | |
1919 | ||
1920 | wlcore_op_stop_locked(wl); | |
baf6277a EP |
1921 | |
1922 | mutex_unlock(&wl->mutex); | |
1b72aecd JO |
1923 | } |
1924 | ||
c50a2825 EP |
1925 | static void wlcore_channel_switch_work(struct work_struct *work) |
1926 | { | |
1927 | struct delayed_work *dwork; | |
1928 | struct wl1271 *wl; | |
1929 | struct ieee80211_vif *vif; | |
1930 | struct wl12xx_vif *wlvif; | |
1931 | int ret; | |
1932 | ||
1933 | dwork = container_of(work, struct delayed_work, work); | |
1934 | wlvif = container_of(dwork, struct wl12xx_vif, channel_switch_work); | |
1935 | wl = wlvif->wl; | |
1936 | ||
1937 | wl1271_info("channel switch failed (role_id: %d).", wlvif->role_id); | |
1938 | ||
1939 | mutex_lock(&wl->mutex); | |
1940 | ||
1941 | if (unlikely(wl->state != WLCORE_STATE_ON)) | |
1942 | goto out; | |
1943 | ||
1944 | /* check the channel switch is still ongoing */ | |
1945 | if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) | |
1946 | goto out; | |
1947 | ||
1948 | vif = wl12xx_wlvif_to_vif(wlvif); | |
1949 | ieee80211_chswitch_done(vif, false); | |
1950 | ||
1951 | ret = wl1271_ps_elp_wakeup(wl); | |
1952 | if (ret < 0) | |
1953 | goto out; | |
1954 | ||
1955 | wl12xx_cmd_stop_channel_switch(wl, wlvif); | |
1956 | ||
1957 | wl1271_ps_elp_sleep(wl); | |
1958 | out: | |
1959 | mutex_unlock(&wl->mutex); | |
1960 | } | |
1961 | ||
1962 | static void wlcore_connection_loss_work(struct work_struct *work) | |
1963 | { | |
1964 | struct delayed_work *dwork; | |
1965 | struct wl1271 *wl; | |
1966 | struct ieee80211_vif *vif; | |
1967 | struct wl12xx_vif *wlvif; | |
1968 | ||
1969 | dwork = container_of(work, struct delayed_work, work); | |
1970 | wlvif = container_of(dwork, struct wl12xx_vif, connection_loss_work); | |
1971 | wl = wlvif->wl; | |
1972 | ||
1973 | wl1271_info("Connection loss work (role_id: %d).", wlvif->role_id); | |
1974 | ||
1975 | mutex_lock(&wl->mutex); | |
1976 | ||
1977 | if (unlikely(wl->state != WLCORE_STATE_ON)) | |
1978 | goto out; | |
1979 | ||
1980 | /* Call mac80211 connection loss */ | |
1981 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | |
1982 | goto out; | |
1983 | ||
1984 | vif = wl12xx_wlvif_to_vif(wlvif); | |
1985 | ieee80211_connection_loss(vif); | |
1986 | out: | |
1987 | mutex_unlock(&wl->mutex); | |
1988 | } | |
1989 | ||
e5a359f8 EP |
1990 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) |
1991 | { | |
1992 | u8 policy = find_first_zero_bit(wl->rate_policies_map, | |
1993 | WL12XX_MAX_RATE_POLICIES); | |
1994 | if (policy >= WL12XX_MAX_RATE_POLICIES) | |
1995 | return -EBUSY; | |
1996 | ||
1997 | __set_bit(policy, wl->rate_policies_map); | |
1998 | *idx = policy; | |
1999 | return 0; | |
2000 | } | |
2001 | ||
2002 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) | |
2003 | { | |
2004 | if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) | |
2005 | return; | |
2006 | ||
2007 | __clear_bit(*idx, wl->rate_policies_map); | |
2008 | *idx = WL12XX_MAX_RATE_POLICIES; | |
2009 | } | |
2010 | ||
001e39a8 EP |
2011 | static int wlcore_allocate_klv_template(struct wl1271 *wl, u8 *idx) |
2012 | { | |
2013 | u8 policy = find_first_zero_bit(wl->klv_templates_map, | |
2014 | WLCORE_MAX_KLV_TEMPLATES); | |
2015 | if (policy >= WLCORE_MAX_KLV_TEMPLATES) | |
2016 | return -EBUSY; | |
2017 | ||
2018 | __set_bit(policy, wl->klv_templates_map); | |
2019 | *idx = policy; | |
2020 | return 0; | |
2021 | } | |
2022 | ||
2023 | static void wlcore_free_klv_template(struct wl1271 *wl, u8 *idx) | |
2024 | { | |
2025 | if (WARN_ON(*idx >= WLCORE_MAX_KLV_TEMPLATES)) | |
2026 | return; | |
2027 | ||
2028 | __clear_bit(*idx, wl->klv_templates_map); | |
2029 | *idx = WLCORE_MAX_KLV_TEMPLATES; | |
2030 | } | |
2031 | ||
536129c8 | 2032 | static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
b78b47eb | 2033 | { |
536129c8 | 2034 | switch (wlvif->bss_type) { |
b78b47eb | 2035 | case BSS_TYPE_AP_BSS: |
fb0e707c | 2036 | if (wlvif->p2p) |
045c745f EP |
2037 | return WL1271_ROLE_P2P_GO; |
2038 | else | |
2039 | return WL1271_ROLE_AP; | |
b78b47eb EP |
2040 | |
2041 | case BSS_TYPE_STA_BSS: | |
fb0e707c | 2042 | if (wlvif->p2p) |
045c745f EP |
2043 | return WL1271_ROLE_P2P_CL; |
2044 | else | |
2045 | return WL1271_ROLE_STA; | |
b78b47eb | 2046 | |
227e81e1 EP |
2047 | case BSS_TYPE_IBSS: |
2048 | return WL1271_ROLE_IBSS; | |
2049 | ||
b78b47eb | 2050 | default: |
536129c8 | 2051 | wl1271_error("invalid bss_type: %d", wlvif->bss_type); |
b78b47eb EP |
2052 | } |
2053 | return WL12XX_INVALID_ROLE_TYPE; | |
2054 | } | |
2055 | ||
83587505 | 2056 | static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif) |
87fbcb0f | 2057 | { |
e936bbe0 | 2058 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
e5a359f8 | 2059 | int i; |
e936bbe0 | 2060 | |
48e93e40 EP |
2061 | /* clear everything but the persistent data */ |
2062 | memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); | |
e936bbe0 EP |
2063 | |
2064 | switch (ieee80211_vif_type_p2p(vif)) { | |
2065 | case NL80211_IFTYPE_P2P_CLIENT: | |
2066 | wlvif->p2p = 1; | |
2067 | /* fall-through */ | |
2068 | case NL80211_IFTYPE_STATION: | |
2069 | wlvif->bss_type = BSS_TYPE_STA_BSS; | |
2070 | break; | |
2071 | case NL80211_IFTYPE_ADHOC: | |
2072 | wlvif->bss_type = BSS_TYPE_IBSS; | |
2073 | break; | |
2074 | case NL80211_IFTYPE_P2P_GO: | |
2075 | wlvif->p2p = 1; | |
2076 | /* fall-through */ | |
2077 | case NL80211_IFTYPE_AP: | |
2078 | wlvif->bss_type = BSS_TYPE_AP_BSS; | |
2079 | break; | |
2080 | default: | |
2081 | wlvif->bss_type = MAX_BSS_TYPE; | |
2082 | return -EOPNOTSUPP; | |
2083 | } | |
2084 | ||
0603d891 | 2085 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
7edebf56 | 2086 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
afaf8bdb | 2087 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
a8ab39a4 | 2088 | |
e936bbe0 EP |
2089 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
2090 | wlvif->bss_type == BSS_TYPE_IBSS) { | |
2091 | /* init sta/ibss data */ | |
2092 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; | |
e5a359f8 EP |
2093 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
2094 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); | |
2095 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); | |
001e39a8 | 2096 | wlcore_allocate_klv_template(wl, &wlvif->sta.klv_template_id); |
15e05bc0 LC |
2097 | wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
2098 | wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; | |
2099 | wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; | |
e936bbe0 EP |
2100 | } else { |
2101 | /* init ap data */ | |
2102 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; | |
2103 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; | |
e5a359f8 EP |
2104 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
2105 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); | |
2106 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) | |
2107 | wl12xx_allocate_rate_policy(wl, | |
2108 | &wlvif->ap.ucast_rate_idx[i]); | |
42ec1f82 | 2109 | wlvif->basic_rate_set = CONF_TX_ENABLED_RATES; |
15e05bc0 LC |
2110 | /* |
2111 | * TODO: check if basic_rate shouldn't be | |
2112 | * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | |
2113 | * instead (the same thing for STA above). | |
2114 | */ | |
42ec1f82 | 2115 | wlvif->basic_rate = CONF_TX_ENABLED_RATES; |
15e05bc0 | 2116 | /* TODO: this seems to be used only for STA, check it */ |
42ec1f82 | 2117 | wlvif->rate_set = CONF_TX_ENABLED_RATES; |
e936bbe0 | 2118 | } |
a8ab39a4 | 2119 | |
83587505 EP |
2120 | wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; |
2121 | wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; | |
6a899796 EP |
2122 | wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; |
2123 | ||
1b92f15e EP |
2124 | /* |
2125 | * mac80211 configures some values globally, while we treat them | |
2126 | * per-interface. thus, on init, we have to copy them from wl | |
2127 | */ | |
2128 | wlvif->band = wl->band; | |
61f845f4 | 2129 | wlvif->channel = wl->channel; |
6bd65029 | 2130 | wlvif->power_level = wl->power_level; |
83d08d3f | 2131 | wlvif->channel_type = wl->channel_type; |
1b92f15e | 2132 | |
9eb599e9 EP |
2133 | INIT_WORK(&wlvif->rx_streaming_enable_work, |
2134 | wl1271_rx_streaming_enable_work); | |
2135 | INIT_WORK(&wlvif->rx_streaming_disable_work, | |
2136 | wl1271_rx_streaming_disable_work); | |
c50a2825 EP |
2137 | INIT_DELAYED_WORK(&wlvif->channel_switch_work, |
2138 | wlcore_channel_switch_work); | |
2139 | INIT_DELAYED_WORK(&wlvif->connection_loss_work, | |
2140 | wlcore_connection_loss_work); | |
87627214 | 2141 | INIT_LIST_HEAD(&wlvif->list); |
252efa4f | 2142 | |
9eb599e9 EP |
2143 | setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, |
2144 | (unsigned long) wlvif); | |
e936bbe0 | 2145 | return 0; |
87fbcb0f EP |
2146 | } |
2147 | ||
1d095475 | 2148 | static bool wl12xx_init_fw(struct wl1271 *wl) |
f5fc0f86 | 2149 | { |
9ccd9217 | 2150 | int retries = WL1271_BOOT_RETRIES; |
71125abd | 2151 | bool booted = false; |
1d095475 EP |
2152 | struct wiphy *wiphy = wl->hw->wiphy; |
2153 | int ret; | |
f5fc0f86 | 2154 | |
9ccd9217 JO |
2155 | while (retries) { |
2156 | retries--; | |
3fcdab70 | 2157 | ret = wl12xx_chip_wakeup(wl, false); |
9ccd9217 JO |
2158 | if (ret < 0) |
2159 | goto power_off; | |
f5fc0f86 | 2160 | |
dd5512eb | 2161 | ret = wl->ops->boot(wl); |
9ccd9217 JO |
2162 | if (ret < 0) |
2163 | goto power_off; | |
f5fc0f86 | 2164 | |
92c77c73 EP |
2165 | ret = wl1271_hw_init(wl); |
2166 | if (ret < 0) | |
2167 | goto irq_disable; | |
2168 | ||
71125abd EP |
2169 | booted = true; |
2170 | break; | |
eb5b28d0 | 2171 | |
9ccd9217 | 2172 | irq_disable: |
9ccd9217 JO |
2173 | mutex_unlock(&wl->mutex); |
2174 | /* Unlocking the mutex in the middle of handling is | |
2175 | inherently unsafe. In this case we deem it safe to do, | |
2176 | because we need to let any possibly pending IRQ out of | |
4cc53383 | 2177 | the system (and while we are WLCORE_STATE_OFF the IRQ |
9ccd9217 JO |
2178 | work function will not do anything.) Also, any other |
2179 | possible concurrent operations will fail due to the | |
2180 | current state, hence the wl1271 struct should be safe. */ | |
dd5512eb | 2181 | wlcore_disable_interrupts(wl); |
a620865e IY |
2182 | wl1271_flush_deferred_work(wl); |
2183 | cancel_work_sync(&wl->netstack_work); | |
9ccd9217 JO |
2184 | mutex_lock(&wl->mutex); |
2185 | power_off: | |
2186 | wl1271_power_off(wl); | |
2187 | } | |
eb5b28d0 | 2188 | |
71125abd EP |
2189 | if (!booted) { |
2190 | wl1271_error("firmware boot failed despite %d retries", | |
2191 | WL1271_BOOT_RETRIES); | |
2192 | goto out; | |
2193 | } | |
2194 | ||
4b7fac77 | 2195 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
71125abd EP |
2196 | |
2197 | /* update hw/fw version info in wiphy struct */ | |
2198 | wiphy->hw_version = wl->chip.id; | |
4b7fac77 | 2199 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
71125abd EP |
2200 | sizeof(wiphy->fw_version)); |
2201 | ||
fb6a6819 LC |
2202 | /* |
2203 | * Now we know if 11a is supported (info from the NVS), so disable | |
2204 | * 11a channels if not supported | |
2205 | */ | |
2206 | if (!wl->enable_11a) | |
2207 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; | |
2208 | ||
2209 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", | |
2210 | wl->enable_11a ? "" : "not "); | |
2211 | ||
4cc53383 | 2212 | wl->state = WLCORE_STATE_ON; |
1d095475 EP |
2213 | out: |
2214 | return booted; | |
2215 | } | |
2216 | ||
92e712da EP |
2217 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) |
2218 | { | |
2219 | return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; | |
2220 | } | |
2221 | ||
4549d09c EP |
2222 | /* |
2223 | * Check whether a fw switch (i.e. moving from one loaded | |
2224 | * fw to another) is needed. This function is also responsible | |
2225 | * for updating wl->last_vif_count, so it must be called before | |
2226 | * loading a non-plt fw (so the correct fw (single-role/multi-role) | |
2227 | * will be used). | |
2228 | */ | |
2229 | static bool wl12xx_need_fw_change(struct wl1271 *wl, | |
2230 | struct vif_counter_data vif_counter_data, | |
2231 | bool add) | |
2232 | { | |
2233 | enum wl12xx_fw_type current_fw = wl->fw_type; | |
2234 | u8 vif_count = vif_counter_data.counter; | |
2235 | ||
2236 | if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) | |
2237 | return false; | |
2238 | ||
2239 | /* increase the vif count if this is a new vif */ | |
2240 | if (add && !vif_counter_data.cur_vif_running) | |
2241 | vif_count++; | |
2242 | ||
2243 | wl->last_vif_count = vif_count; | |
2244 | ||
2245 | /* no need for fw change if the device is OFF */ | |
4cc53383 | 2246 | if (wl->state == WLCORE_STATE_OFF) |
4549d09c EP |
2247 | return false; |
2248 | ||
9b1a0a77 EP |
2249 | /* no need for fw change if a single fw is used */ |
2250 | if (!wl->mr_fw_name) | |
2251 | return false; | |
2252 | ||
4549d09c EP |
2253 | if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) |
2254 | return true; | |
2255 | if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) | |
2256 | return true; | |
2257 | ||
2258 | return false; | |
2259 | } | |
2260 | ||
3dee4393 EP |
2261 | /* |
2262 | * Enter "forced psm". Make sure the sta is in psm against the ap, | |
2263 | * to make the fw switch a bit more disconnection-persistent. | |
2264 | */ | |
2265 | static void wl12xx_force_active_psm(struct wl1271 *wl) | |
2266 | { | |
2267 | struct wl12xx_vif *wlvif; | |
2268 | ||
2269 | wl12xx_for_each_wlvif_sta(wl, wlvif) { | |
2270 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); | |
2271 | } | |
2272 | } | |
2273 | ||
1d095475 EP |
2274 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, |
2275 | struct ieee80211_vif *vif) | |
2276 | { | |
2277 | struct wl1271 *wl = hw->priv; | |
2278 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4549d09c | 2279 | struct vif_counter_data vif_count; |
1d095475 EP |
2280 | int ret = 0; |
2281 | u8 role_type; | |
2282 | bool booted = false; | |
2283 | ||
ea086359 JB |
2284 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
2285 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; | |
c1288b12 | 2286 | |
1d095475 EP |
2287 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
2288 | ieee80211_vif_type_p2p(vif), vif->addr); | |
2289 | ||
4549d09c EP |
2290 | wl12xx_get_vif_count(hw, vif, &vif_count); |
2291 | ||
1d095475 | 2292 | mutex_lock(&wl->mutex); |
f750c820 EP |
2293 | ret = wl1271_ps_elp_wakeup(wl); |
2294 | if (ret < 0) | |
2295 | goto out_unlock; | |
2296 | ||
1d095475 EP |
2297 | /* |
2298 | * in some very corner case HW recovery scenarios its possible to | |
2299 | * get here before __wl1271_op_remove_interface is complete, so | |
2300 | * opt out if that is the case. | |
2301 | */ | |
10c8cd01 EP |
2302 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || |
2303 | test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { | |
1d095475 EP |
2304 | ret = -EBUSY; |
2305 | goto out; | |
2306 | } | |
2307 | ||
3fcdab70 | 2308 | |
83587505 | 2309 | ret = wl12xx_init_vif_data(wl, vif); |
1d095475 EP |
2310 | if (ret < 0) |
2311 | goto out; | |
2312 | ||
2313 | wlvif->wl = wl; | |
2314 | role_type = wl12xx_get_role_type(wl, wlvif); | |
2315 | if (role_type == WL12XX_INVALID_ROLE_TYPE) { | |
2316 | ret = -EINVAL; | |
2317 | goto out; | |
2318 | } | |
2319 | ||
4549d09c | 2320 | if (wl12xx_need_fw_change(wl, vif_count, true)) { |
3dee4393 | 2321 | wl12xx_force_active_psm(wl); |
e9ba7152 | 2322 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
4549d09c EP |
2323 | mutex_unlock(&wl->mutex); |
2324 | wl1271_recovery_work(&wl->recovery_work); | |
2325 | return 0; | |
2326 | } | |
2327 | ||
1d095475 EP |
2328 | /* |
2329 | * TODO: after the nvs issue will be solved, move this block | |
2330 | * to start(), and make sure here the driver is ON. | |
2331 | */ | |
4cc53383 | 2332 | if (wl->state == WLCORE_STATE_OFF) { |
1d095475 EP |
2333 | /* |
2334 | * we still need this in order to configure the fw | |
2335 | * while uploading the nvs | |
2336 | */ | |
5e037e74 | 2337 | memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); |
1d095475 EP |
2338 | |
2339 | booted = wl12xx_init_fw(wl); | |
2340 | if (!booted) { | |
2341 | ret = -EINVAL; | |
2342 | goto out; | |
2343 | } | |
2344 | } | |
2345 | ||
1d095475 EP |
2346 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
2347 | role_type, &wlvif->role_id); | |
2348 | if (ret < 0) | |
2349 | goto out; | |
2350 | ||
2351 | ret = wl1271_init_vif_specific(wl, vif); | |
2352 | if (ret < 0) | |
2353 | goto out; | |
2354 | ||
87627214 | 2355 | list_add(&wlvif->list, &wl->wlvif_list); |
10c8cd01 | 2356 | set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); |
a4e4130d EP |
2357 | |
2358 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) | |
2359 | wl->ap_count++; | |
2360 | else | |
2361 | wl->sta_count++; | |
eb5b28d0 | 2362 | out: |
f750c820 EP |
2363 | wl1271_ps_elp_sleep(wl); |
2364 | out_unlock: | |
f5fc0f86 LC |
2365 | mutex_unlock(&wl->mutex); |
2366 | ||
2367 | return ret; | |
2368 | } | |
2369 | ||
7dece1c8 | 2370 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
536129c8 | 2371 | struct ieee80211_vif *vif, |
7dece1c8 | 2372 | bool reset_tx_queues) |
f5fc0f86 | 2373 | { |
536129c8 | 2374 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
e5a359f8 | 2375 | int i, ret; |
2f18cf7c | 2376 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
f5fc0f86 | 2377 | |
1b72aecd | 2378 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
f5fc0f86 | 2379 | |
10c8cd01 EP |
2380 | if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
2381 | return; | |
2382 | ||
13026dec | 2383 | /* because of hardware recovery, we may get here twice */ |
4cc53383 | 2384 | if (wl->state == WLCORE_STATE_OFF) |
13026dec JO |
2385 | return; |
2386 | ||
1b72aecd | 2387 | wl1271_info("down"); |
f5fc0f86 | 2388 | |
baf6277a | 2389 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE && |
c50a2825 | 2390 | wl->scan_wlvif == wlvif) { |
55df5afb AN |
2391 | /* |
2392 | * Rearm the tx watchdog just before idling scan. This | |
2393 | * prevents just-finished scans from triggering the watchdog | |
2394 | */ | |
2395 | wl12xx_rearm_tx_watchdog_locked(wl); | |
2396 | ||
08688d6b | 2397 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
4a31c11c | 2398 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
c50a2825 | 2399 | wl->scan_wlvif = NULL; |
b739a42c | 2400 | wl->scan.req = NULL; |
76a029fb | 2401 | ieee80211_scan_completed(wl->hw, true); |
f5fc0f86 LC |
2402 | } |
2403 | ||
10199756 EP |
2404 | if (wl->sched_vif == wlvif) { |
2405 | ieee80211_sched_scan_stopped(wl->hw); | |
2406 | wl->sched_vif = NULL; | |
2407 | } | |
2408 | ||
b78b47eb EP |
2409 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
2410 | /* disable active roles */ | |
2411 | ret = wl1271_ps_elp_wakeup(wl); | |
2412 | if (ret < 0) | |
2413 | goto deinit; | |
2414 | ||
b890f4c3 EP |
2415 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
2416 | wlvif->bss_type == BSS_TYPE_IBSS) { | |
2417 | if (wl12xx_dev_role_started(wlvif)) | |
2418 | wl12xx_stop_dev(wl, wlvif); | |
04e8079c EP |
2419 | } |
2420 | ||
0603d891 | 2421 | ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); |
b78b47eb EP |
2422 | if (ret < 0) |
2423 | goto deinit; | |
2424 | ||
2425 | wl1271_ps_elp_sleep(wl); | |
2426 | } | |
2427 | deinit: | |
e51ae9be | 2428 | /* clear all hlids (except system_hlid) */ |
afaf8bdb | 2429 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
e5a359f8 EP |
2430 | |
2431 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || | |
2432 | wlvif->bss_type == BSS_TYPE_IBSS) { | |
2433 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; | |
2434 | wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); | |
2435 | wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); | |
2436 | wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); | |
001e39a8 | 2437 | wlcore_free_klv_template(wl, &wlvif->sta.klv_template_id); |
e5a359f8 EP |
2438 | } else { |
2439 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; | |
2440 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; | |
2441 | wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); | |
2442 | wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); | |
2443 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) | |
2444 | wl12xx_free_rate_policy(wl, | |
2445 | &wlvif->ap.ucast_rate_idx[i]); | |
830be7e0 | 2446 | wl1271_free_ap_keys(wl, wlvif); |
e5a359f8 | 2447 | } |
b78b47eb | 2448 | |
3eba4a0e ES |
2449 | dev_kfree_skb(wlvif->probereq); |
2450 | wlvif->probereq = NULL; | |
d6a3cc2e | 2451 | wl12xx_tx_reset_wlvif(wl, wlvif); |
e4120df9 EP |
2452 | if (wl->last_wlvif == wlvif) |
2453 | wl->last_wlvif = NULL; | |
87627214 | 2454 | list_del(&wlvif->list); |
c7ffb902 | 2455 | memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map)); |
0603d891 | 2456 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
7edebf56 | 2457 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
d6e19d13 | 2458 | |
2f18cf7c | 2459 | if (is_ap) |
a4e4130d EP |
2460 | wl->ap_count--; |
2461 | else | |
2462 | wl->sta_count--; | |
2463 | ||
42066f9a AN |
2464 | /* |
2465 | * Last AP, have more stations. Configure sleep auth according to STA. | |
2466 | * Don't do thin on unintended recovery. | |
2467 | */ | |
2468 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) && | |
2469 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) | |
2470 | goto unlock; | |
2471 | ||
2f18cf7c AN |
2472 | if (wl->ap_count == 0 && is_ap && wl->sta_count) { |
2473 | u8 sta_auth = wl->conf.conn.sta_sleep_auth; | |
2474 | /* Configure for power according to debugfs */ | |
2475 | if (sta_auth != WL1271_PSM_ILLEGAL) | |
2476 | wl1271_acx_sleep_auth(wl, sta_auth); | |
2477 | /* Configure for power always on */ | |
2478 | else if (wl->quirks & WLCORE_QUIRK_NO_ELP) | |
2479 | wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); | |
2480 | /* Configure for ELP power saving */ | |
2481 | else | |
2482 | wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); | |
2483 | } | |
2484 | ||
42066f9a | 2485 | unlock: |
baf6277a | 2486 | mutex_unlock(&wl->mutex); |
d6bf9ada | 2487 | |
9eb599e9 EP |
2488 | del_timer_sync(&wlvif->rx_streaming_timer); |
2489 | cancel_work_sync(&wlvif->rx_streaming_enable_work); | |
2490 | cancel_work_sync(&wlvif->rx_streaming_disable_work); | |
c50a2825 | 2491 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
bd9dc49c | 2492 | |
baf6277a | 2493 | mutex_lock(&wl->mutex); |
52a2a375 | 2494 | } |
bd9dc49c | 2495 | |
52a2a375 JO |
2496 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
2497 | struct ieee80211_vif *vif) | |
2498 | { | |
2499 | struct wl1271 *wl = hw->priv; | |
10c8cd01 | 2500 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
6e8cd331 | 2501 | struct wl12xx_vif *iter; |
4549d09c | 2502 | struct vif_counter_data vif_count; |
52a2a375 | 2503 | |
4549d09c | 2504 | wl12xx_get_vif_count(hw, vif, &vif_count); |
52a2a375 | 2505 | mutex_lock(&wl->mutex); |
10c8cd01 | 2506 | |
4cc53383 | 2507 | if (wl->state == WLCORE_STATE_OFF || |
10c8cd01 EP |
2508 | !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
2509 | goto out; | |
2510 | ||
67353299 JO |
2511 | /* |
2512 | * wl->vif can be null here if someone shuts down the interface | |
2513 | * just when hardware recovery has been started. | |
2514 | */ | |
6e8cd331 EP |
2515 | wl12xx_for_each_wlvif(wl, iter) { |
2516 | if (iter != wlvif) | |
2517 | continue; | |
2518 | ||
536129c8 | 2519 | __wl1271_op_remove_interface(wl, vif, true); |
6e8cd331 | 2520 | break; |
67353299 | 2521 | } |
6e8cd331 | 2522 | WARN_ON(iter != wlvif); |
4549d09c | 2523 | if (wl12xx_need_fw_change(wl, vif_count, false)) { |
3dee4393 | 2524 | wl12xx_force_active_psm(wl); |
e9ba7152 | 2525 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
4549d09c | 2526 | wl12xx_queue_recovery_work(wl); |
4549d09c | 2527 | } |
10c8cd01 | 2528 | out: |
67353299 | 2529 | mutex_unlock(&wl->mutex); |
f5fc0f86 LC |
2530 | } |
2531 | ||
c0fad1b7 EP |
2532 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, |
2533 | struct ieee80211_vif *vif, | |
2534 | enum nl80211_iftype new_type, bool p2p) | |
2535 | { | |
4549d09c EP |
2536 | struct wl1271 *wl = hw->priv; |
2537 | int ret; | |
2538 | ||
2539 | set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); | |
c0fad1b7 EP |
2540 | wl1271_op_remove_interface(hw, vif); |
2541 | ||
249e9698 | 2542 | vif->type = new_type; |
c0fad1b7 | 2543 | vif->p2p = p2p; |
4549d09c EP |
2544 | ret = wl1271_op_add_interface(hw, vif); |
2545 | ||
2546 | clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); | |
2547 | return ret; | |
c0fad1b7 EP |
2548 | } |
2549 | ||
3230f35e | 2550 | static int wlcore_join(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
82429d32 JO |
2551 | { |
2552 | int ret; | |
536129c8 | 2553 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
82429d32 | 2554 | |
69e5434c JO |
2555 | /* |
2556 | * One of the side effects of the JOIN command is that is clears | |
2557 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated | |
2558 | * to a WPA/WPA2 access point will therefore kill the data-path. | |
8bf69aae OBC |
2559 | * Currently the only valid scenario for JOIN during association |
2560 | * is on roaming, in which case we will also be given new keys. | |
2561 | * Keep the below message for now, unless it starts bothering | |
2562 | * users who really like to roam a lot :) | |
69e5434c | 2563 | */ |
ba8447f6 | 2564 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
69e5434c JO |
2565 | wl1271_info("JOIN while associated."); |
2566 | ||
5ec8a448 EP |
2567 | /* clear encryption type */ |
2568 | wlvif->encryption_type = KEY_NONE; | |
2569 | ||
227e81e1 | 2570 | if (is_ibss) |
87fbcb0f | 2571 | ret = wl12xx_cmd_role_start_ibss(wl, wlvif); |
18eab430 EP |
2572 | else { |
2573 | if (wl->quirks & WLCORE_QUIRK_START_STA_FAILS) { | |
2574 | /* | |
2575 | * TODO: this is an ugly workaround for wl12xx fw | |
2576 | * bug - we are not able to tx/rx after the first | |
2577 | * start_sta, so make dummy start+stop calls, | |
2578 | * and then call start_sta again. | |
2579 | * this should be fixed in the fw. | |
2580 | */ | |
2581 | wl12xx_cmd_role_start_sta(wl, wlvif); | |
2582 | wl12xx_cmd_role_stop_sta(wl, wlvif); | |
2583 | } | |
2584 | ||
87fbcb0f | 2585 | ret = wl12xx_cmd_role_start_sta(wl, wlvif); |
18eab430 | 2586 | } |
3230f35e EP |
2587 | |
2588 | return ret; | |
2589 | } | |
2590 | ||
2591 | static int wl1271_ssid_set(struct wl12xx_vif *wlvif, struct sk_buff *skb, | |
2592 | int offset) | |
2593 | { | |
2594 | u8 ssid_len; | |
2595 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, | |
2596 | skb->len - offset); | |
2597 | ||
2598 | if (!ptr) { | |
2599 | wl1271_error("No SSID in IEs!"); | |
2600 | return -ENOENT; | |
2601 | } | |
2602 | ||
2603 | ssid_len = ptr[1]; | |
2604 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { | |
2605 | wl1271_error("SSID is too long!"); | |
2606 | return -EINVAL; | |
2607 | } | |
2608 | ||
2609 | wlvif->ssid_len = ssid_len; | |
2610 | memcpy(wlvif->ssid, ptr+2, ssid_len); | |
2611 | return 0; | |
2612 | } | |
2613 | ||
2614 | static int wlcore_set_ssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) | |
2615 | { | |
2616 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); | |
2617 | struct sk_buff *skb; | |
2618 | int ieoffset; | |
2619 | ||
2620 | /* we currently only support setting the ssid from the ap probe req */ | |
2621 | if (wlvif->bss_type != BSS_TYPE_STA_BSS) | |
2622 | return -EINVAL; | |
2623 | ||
2624 | skb = ieee80211_ap_probereq_get(wl->hw, vif); | |
2625 | if (!skb) | |
2626 | return -EINVAL; | |
2627 | ||
2628 | ieoffset = offsetof(struct ieee80211_mgmt, | |
2629 | u.probe_req.variable); | |
2630 | wl1271_ssid_set(wlvif, skb, ieoffset); | |
2631 | dev_kfree_skb(skb); | |
2632 | ||
2633 | return 0; | |
2634 | } | |
2635 | ||
2636 | static int wlcore_set_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif, | |
ec87011a EP |
2637 | struct ieee80211_bss_conf *bss_conf, |
2638 | u32 sta_rate_set) | |
3230f35e EP |
2639 | { |
2640 | int ieoffset; | |
2641 | int ret; | |
2642 | ||
2643 | wlvif->aid = bss_conf->aid; | |
2644 | wlvif->channel_type = bss_conf->channel_type; | |
2645 | wlvif->beacon_int = bss_conf->beacon_int; | |
d50529c0 | 2646 | wlvif->wmm_enabled = bss_conf->qos; |
3230f35e EP |
2647 | |
2648 | set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); | |
2649 | ||
2650 | /* | |
2651 | * with wl1271, we don't need to update the | |
2652 | * beacon_int and dtim_period, because the firmware | |
2653 | * updates it by itself when the first beacon is | |
2654 | * received after a join. | |
2655 | */ | |
2656 | ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); | |
82429d32 | 2657 | if (ret < 0) |
3230f35e | 2658 | return ret; |
82429d32 | 2659 | |
3230f35e EP |
2660 | /* |
2661 | * Get a template for hardware connection maintenance | |
2662 | */ | |
2663 | dev_kfree_skb(wlvif->probereq); | |
2664 | wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, | |
2665 | wlvif, | |
2666 | NULL); | |
2667 | ieoffset = offsetof(struct ieee80211_mgmt, | |
2668 | u.probe_req.variable); | |
2669 | wl1271_ssid_set(wlvif, wlvif->probereq, ieoffset); | |
2670 | ||
2671 | /* enable the connection monitoring feature */ | |
2672 | ret = wl1271_acx_conn_monit_params(wl, wlvif, true); | |
2673 | if (ret < 0) | |
2674 | return ret; | |
82429d32 JO |
2675 | |
2676 | /* | |
2677 | * The join command disable the keep-alive mode, shut down its process, | |
2678 | * and also clear the template config, so we need to reset it all after | |
2679 | * the join. The acx_aid starts the keep-alive process, and the order | |
2680 | * of the commands below is relevant. | |
2681 | */ | |
0603d891 | 2682 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); |
82429d32 | 2683 | if (ret < 0) |
3230f35e | 2684 | return ret; |
82429d32 | 2685 | |
0603d891 | 2686 | ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); |
82429d32 | 2687 | if (ret < 0) |
3230f35e | 2688 | return ret; |
82429d32 | 2689 | |
d2d66c56 | 2690 | ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); |
82429d32 | 2691 | if (ret < 0) |
3230f35e | 2692 | return ret; |
82429d32 | 2693 | |
0603d891 | 2694 | ret = wl1271_acx_keep_alive_config(wl, wlvif, |
001e39a8 | 2695 | wlvif->sta.klv_template_id, |
82429d32 JO |
2696 | ACX_KEEP_ALIVE_TPL_VALID); |
2697 | if (ret < 0) | |
3230f35e | 2698 | return ret; |
82429d32 | 2699 | |
6c7b5194 EP |
2700 | /* |
2701 | * The default fw psm configuration is AUTO, while mac80211 default | |
2702 | * setting is off (ACTIVE), so sync the fw with the correct value. | |
2703 | */ | |
2704 | ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE); | |
ec87011a EP |
2705 | if (ret < 0) |
2706 | return ret; | |
2707 | ||
2708 | if (sta_rate_set) { | |
2709 | wlvif->rate_set = | |
2710 | wl1271_tx_enabled_rates_get(wl, | |
2711 | sta_rate_set, | |
2712 | wlvif->band); | |
2713 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); | |
2714 | if (ret < 0) | |
2715 | return ret; | |
2716 | } | |
6c7b5194 | 2717 | |
82429d32 JO |
2718 | return ret; |
2719 | } | |
2720 | ||
3230f35e | 2721 | static int wlcore_unset_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c7f43e45 LC |
2722 | { |
2723 | int ret; | |
3230f35e EP |
2724 | bool sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
2725 | ||
2726 | /* make sure we are connected (sta) joined */ | |
2727 | if (sta && | |
2728 | !test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) | |
2729 | return false; | |
2730 | ||
2731 | /* make sure we are joined (ibss) */ | |
2732 | if (!sta && | |
2733 | test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) | |
2734 | return false; | |
2735 | ||
2736 | if (sta) { | |
2737 | /* use defaults when not associated */ | |
2738 | wlvif->aid = 0; | |
2739 | ||
2740 | /* free probe-request template */ | |
2741 | dev_kfree_skb(wlvif->probereq); | |
2742 | wlvif->probereq = NULL; | |
2743 | ||
2744 | /* disable connection monitor features */ | |
2745 | ret = wl1271_acx_conn_monit_params(wl, wlvif, false); | |
2746 | if (ret < 0) | |
2747 | return ret; | |
2748 | ||
2749 | /* Disable the keep-alive feature */ | |
2750 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); | |
2751 | if (ret < 0) | |
2752 | return ret; | |
2753 | } | |
c7f43e45 | 2754 | |
52630c5d | 2755 | if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { |
6e8cd331 EP |
2756 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
2757 | ||
fcab1890 | 2758 | wl12xx_cmd_stop_channel_switch(wl, wlvif); |
6e8cd331 | 2759 | ieee80211_chswitch_done(vif, false); |
c50a2825 | 2760 | cancel_delayed_work(&wlvif->channel_switch_work); |
6d158ff3 SL |
2761 | } |
2762 | ||
4137c17c EP |
2763 | /* invalidate keep-alive template */ |
2764 | wl1271_acx_keep_alive_config(wl, wlvif, | |
001e39a8 | 2765 | wlvif->sta.klv_template_id, |
4137c17c EP |
2766 | ACX_KEEP_ALIVE_TPL_INVALID); |
2767 | ||
b992c682 | 2768 | /* reset TX security counters on a clean disconnect */ |
48e93e40 EP |
2769 | wlvif->tx_security_last_seq_lsb = 0; |
2770 | wlvif->tx_security_seq = 0; | |
b992c682 | 2771 | |
3230f35e | 2772 | return 0; |
c7f43e45 LC |
2773 | } |
2774 | ||
87fbcb0f | 2775 | static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
ebba60c6 | 2776 | { |
1b92f15e | 2777 | wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; |
30d0c8fd | 2778 | wlvif->rate_set = wlvif->basic_rate_set; |
ebba60c6 JO |
2779 | } |
2780 | ||
9f259c4e EP |
2781 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
2782 | struct ieee80211_conf *conf, u32 changed) | |
f5fc0f86 | 2783 | { |
9f259c4e | 2784 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
b6970ee5 | 2785 | int ret; |
ebba60c6 | 2786 | |
d18da7fc ES |
2787 | if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) { |
2788 | ||
2789 | if ((conf->flags & IEEE80211_CONF_PS) && | |
2790 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && | |
5c0dc2fc | 2791 | !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
d18da7fc | 2792 | |
5c0dc2fc ES |
2793 | int ps_mode; |
2794 | char *ps_mode_str; | |
2795 | ||
2796 | if (wl->conf.conn.forced_ps) { | |
2797 | ps_mode = STATION_POWER_SAVE_MODE; | |
2798 | ps_mode_str = "forced"; | |
2799 | } else { | |
2800 | ps_mode = STATION_AUTO_PS_MODE; | |
2801 | ps_mode_str = "auto"; | |
2802 | } | |
2803 | ||
2804 | wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); | |
2805 | ||
2806 | ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); | |
f5fc0f86 | 2807 | |
d18da7fc | 2808 | if (ret < 0) |
5c0dc2fc ES |
2809 | wl1271_warning("enter %s ps failed %d", |
2810 | ps_mode_str, ret); | |
f5fc0f86 | 2811 | |
d18da7fc | 2812 | } else if (!(conf->flags & IEEE80211_CONF_PS) && |
5c0dc2fc | 2813 | test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
d18da7fc ES |
2814 | |
2815 | wl1271_debug(DEBUG_PSM, "auto ps disabled"); | |
f5fc0f86 | 2816 | |
0603d891 | 2817 | ret = wl1271_ps_set_mode(wl, wlvif, |
248a0018 | 2818 | STATION_ACTIVE_MODE); |
d18da7fc ES |
2819 | if (ret < 0) |
2820 | wl1271_warning("exit auto ps failed %d", ret); | |
2821 | } | |
f5fc0f86 LC |
2822 | } |
2823 | ||
6bd65029 | 2824 | if (conf->power_level != wlvif->power_level) { |
0603d891 | 2825 | ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); |
f5fc0f86 | 2826 | if (ret < 0) |
9f259c4e | 2827 | return ret; |
f5fc0f86 | 2828 | |
6bd65029 | 2829 | wlvif->power_level = conf->power_level; |
f5fc0f86 LC |
2830 | } |
2831 | ||
9f259c4e EP |
2832 | return 0; |
2833 | } | |
2834 | ||
2835 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) | |
2836 | { | |
2837 | struct wl1271 *wl = hw->priv; | |
2838 | struct wl12xx_vif *wlvif; | |
2839 | struct ieee80211_conf *conf = &hw->conf; | |
b6970ee5 | 2840 | int ret = 0; |
9f259c4e | 2841 | |
b6970ee5 | 2842 | wl1271_debug(DEBUG_MAC80211, "mac80211 config psm %s power %d %s" |
9f259c4e | 2843 | " changed 0x%x", |
9f259c4e EP |
2844 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", |
2845 | conf->power_level, | |
2846 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", | |
2847 | changed); | |
2848 | ||
9f259c4e EP |
2849 | mutex_lock(&wl->mutex); |
2850 | ||
9f259c4e EP |
2851 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
2852 | wl->power_level = conf->power_level; | |
2853 | ||
4cc53383 | 2854 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
9f259c4e EP |
2855 | goto out; |
2856 | ||
2857 | ret = wl1271_ps_elp_wakeup(wl); | |
2858 | if (ret < 0) | |
2859 | goto out; | |
2860 | ||
2861 | /* configure each interface */ | |
2862 | wl12xx_for_each_wlvif(wl, wlvif) { | |
2863 | ret = wl12xx_config_vif(wl, wlvif, conf, changed); | |
2864 | if (ret < 0) | |
2865 | goto out_sleep; | |
2866 | } | |
2867 | ||
f5fc0f86 LC |
2868 | out_sleep: |
2869 | wl1271_ps_elp_sleep(wl); | |
2870 | ||
2871 | out: | |
2872 | mutex_unlock(&wl->mutex); | |
2873 | ||
2874 | return ret; | |
2875 | } | |
2876 | ||
b54853f1 JO |
2877 | struct wl1271_filter_params { |
2878 | bool enabled; | |
2879 | int mc_list_length; | |
2880 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; | |
2881 | }; | |
2882 | ||
22bedad3 JP |
2883 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
2884 | struct netdev_hw_addr_list *mc_list) | |
c87dec9f | 2885 | { |
c87dec9f | 2886 | struct wl1271_filter_params *fp; |
22bedad3 | 2887 | struct netdev_hw_addr *ha; |
c87dec9f | 2888 | |
74441130 | 2889 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
c87dec9f JO |
2890 | if (!fp) { |
2891 | wl1271_error("Out of memory setting filters."); | |
2892 | return 0; | |
2893 | } | |
2894 | ||
2895 | /* update multicast filtering parameters */ | |
c87dec9f | 2896 | fp->mc_list_length = 0; |
22bedad3 JP |
2897 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
2898 | fp->enabled = false; | |
2899 | } else { | |
2900 | fp->enabled = true; | |
2901 | netdev_hw_addr_list_for_each(ha, mc_list) { | |
c87dec9f | 2902 | memcpy(fp->mc_list[fp->mc_list_length], |
22bedad3 | 2903 | ha->addr, ETH_ALEN); |
c87dec9f | 2904 | fp->mc_list_length++; |
22bedad3 | 2905 | } |
c87dec9f JO |
2906 | } |
2907 | ||
b54853f1 | 2908 | return (u64)(unsigned long)fp; |
c87dec9f | 2909 | } |
f5fc0f86 | 2910 | |
b54853f1 JO |
2911 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
2912 | FIF_ALLMULTI | \ | |
2913 | FIF_FCSFAIL | \ | |
2914 | FIF_BCN_PRBRESP_PROMISC | \ | |
2915 | FIF_CONTROL | \ | |
2916 | FIF_OTHER_BSS) | |
2917 | ||
f5fc0f86 LC |
2918 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
2919 | unsigned int changed, | |
c87dec9f | 2920 | unsigned int *total, u64 multicast) |
f5fc0f86 | 2921 | { |
b54853f1 | 2922 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
f5fc0f86 | 2923 | struct wl1271 *wl = hw->priv; |
6e8cd331 | 2924 | struct wl12xx_vif *wlvif; |
536129c8 | 2925 | |
b54853f1 | 2926 | int ret; |
f5fc0f86 | 2927 | |
7d057869 AN |
2928 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
2929 | " total %x", changed, *total); | |
f5fc0f86 | 2930 | |
b54853f1 JO |
2931 | mutex_lock(&wl->mutex); |
2932 | ||
2c10bb9c SD |
2933 | *total &= WL1271_SUPPORTED_FILTERS; |
2934 | changed &= WL1271_SUPPORTED_FILTERS; | |
2935 | ||
4cc53383 | 2936 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
b54853f1 JO |
2937 | goto out; |
2938 | ||
a620865e | 2939 | ret = wl1271_ps_elp_wakeup(wl); |
b54853f1 JO |
2940 | if (ret < 0) |
2941 | goto out; | |
2942 | ||
6e8cd331 EP |
2943 | wl12xx_for_each_wlvif(wl, wlvif) { |
2944 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { | |
2945 | if (*total & FIF_ALLMULTI) | |
2946 | ret = wl1271_acx_group_address_tbl(wl, wlvif, | |
2947 | false, | |
2948 | NULL, 0); | |
2949 | else if (fp) | |
2950 | ret = wl1271_acx_group_address_tbl(wl, wlvif, | |
2951 | fp->enabled, | |
2952 | fp->mc_list, | |
2953 | fp->mc_list_length); | |
2954 | if (ret < 0) | |
2955 | goto out_sleep; | |
2956 | } | |
7d057869 | 2957 | } |
f5fc0f86 | 2958 | |
08c1d1c7 EP |
2959 | /* |
2960 | * the fw doesn't provide an api to configure the filters. instead, | |
2961 | * the filters configuration is based on the active roles / ROC | |
2962 | * state. | |
2963 | */ | |
b54853f1 JO |
2964 | |
2965 | out_sleep: | |
2966 | wl1271_ps_elp_sleep(wl); | |
2967 | ||
2968 | out: | |
2969 | mutex_unlock(&wl->mutex); | |
14b228a0 | 2970 | kfree(fp); |
f5fc0f86 LC |
2971 | } |
2972 | ||
170d0e67 EP |
2973 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
2974 | u8 id, u8 key_type, u8 key_size, | |
2975 | const u8 *key, u8 hlid, u32 tx_seq_32, | |
2976 | u16 tx_seq_16) | |
7f179b46 AN |
2977 | { |
2978 | struct wl1271_ap_key *ap_key; | |
2979 | int i; | |
2980 | ||
2981 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); | |
2982 | ||
2983 | if (key_size > MAX_KEY_SIZE) | |
2984 | return -EINVAL; | |
2985 | ||
2986 | /* | |
2987 | * Find next free entry in ap_keys. Also check we are not replacing | |
2988 | * an existing key. | |
2989 | */ | |
2990 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
170d0e67 | 2991 | if (wlvif->ap.recorded_keys[i] == NULL) |
7f179b46 AN |
2992 | break; |
2993 | ||
170d0e67 | 2994 | if (wlvif->ap.recorded_keys[i]->id == id) { |
7f179b46 AN |
2995 | wl1271_warning("trying to record key replacement"); |
2996 | return -EINVAL; | |
2997 | } | |
2998 | } | |
2999 | ||
3000 | if (i == MAX_NUM_KEYS) | |
3001 | return -EBUSY; | |
3002 | ||
3003 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); | |
3004 | if (!ap_key) | |
3005 | return -ENOMEM; | |
3006 | ||
3007 | ap_key->id = id; | |
3008 | ap_key->key_type = key_type; | |
3009 | ap_key->key_size = key_size; | |
3010 | memcpy(ap_key->key, key, key_size); | |
3011 | ap_key->hlid = hlid; | |
3012 | ap_key->tx_seq_32 = tx_seq_32; | |
3013 | ap_key->tx_seq_16 = tx_seq_16; | |
3014 | ||
170d0e67 | 3015 | wlvif->ap.recorded_keys[i] = ap_key; |
7f179b46 AN |
3016 | return 0; |
3017 | } | |
3018 | ||
170d0e67 | 3019 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
7f179b46 AN |
3020 | { |
3021 | int i; | |
3022 | ||
3023 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
170d0e67 EP |
3024 | kfree(wlvif->ap.recorded_keys[i]); |
3025 | wlvif->ap.recorded_keys[i] = NULL; | |
7f179b46 AN |
3026 | } |
3027 | } | |
3028 | ||
a8ab39a4 | 3029 | static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
7f179b46 AN |
3030 | { |
3031 | int i, ret = 0; | |
3032 | struct wl1271_ap_key *key; | |
3033 | bool wep_key_added = false; | |
3034 | ||
3035 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
7f97b487 | 3036 | u8 hlid; |
170d0e67 | 3037 | if (wlvif->ap.recorded_keys[i] == NULL) |
7f179b46 AN |
3038 | break; |
3039 | ||
170d0e67 | 3040 | key = wlvif->ap.recorded_keys[i]; |
7f97b487 EP |
3041 | hlid = key->hlid; |
3042 | if (hlid == WL12XX_INVALID_LINK_ID) | |
a8ab39a4 | 3043 | hlid = wlvif->ap.bcast_hlid; |
7f97b487 | 3044 | |
a8ab39a4 | 3045 | ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
7f179b46 AN |
3046 | key->id, key->key_type, |
3047 | key->key_size, key->key, | |
7f97b487 | 3048 | hlid, key->tx_seq_32, |
7f179b46 AN |
3049 | key->tx_seq_16); |
3050 | if (ret < 0) | |
3051 | goto out; | |
3052 | ||
3053 | if (key->key_type == KEY_WEP) | |
3054 | wep_key_added = true; | |
3055 | } | |
3056 | ||
3057 | if (wep_key_added) { | |
f75c753f | 3058 | ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, |
a8ab39a4 | 3059 | wlvif->ap.bcast_hlid); |
7f179b46 AN |
3060 | if (ret < 0) |
3061 | goto out; | |
3062 | } | |
3063 | ||
3064 | out: | |
170d0e67 | 3065 | wl1271_free_ap_keys(wl, wlvif); |
7f179b46 AN |
3066 | return ret; |
3067 | } | |
3068 | ||
536129c8 EP |
3069 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
3070 | u16 action, u8 id, u8 key_type, | |
7f179b46 AN |
3071 | u8 key_size, const u8 *key, u32 tx_seq_32, |
3072 | u16 tx_seq_16, struct ieee80211_sta *sta) | |
3073 | { | |
3074 | int ret; | |
536129c8 | 3075 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
7f179b46 AN |
3076 | |
3077 | if (is_ap) { | |
3078 | struct wl1271_station *wl_sta; | |
3079 | u8 hlid; | |
3080 | ||
3081 | if (sta) { | |
3082 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
3083 | hlid = wl_sta->hlid; | |
3084 | } else { | |
a8ab39a4 | 3085 | hlid = wlvif->ap.bcast_hlid; |
7f179b46 AN |
3086 | } |
3087 | ||
53d40d0b | 3088 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
7f179b46 AN |
3089 | /* |
3090 | * We do not support removing keys after AP shutdown. | |
3091 | * Pretend we do to make mac80211 happy. | |
3092 | */ | |
3093 | if (action != KEY_ADD_OR_REPLACE) | |
3094 | return 0; | |
3095 | ||
170d0e67 | 3096 | ret = wl1271_record_ap_key(wl, wlvif, id, |
7f179b46 AN |
3097 | key_type, key_size, |
3098 | key, hlid, tx_seq_32, | |
3099 | tx_seq_16); | |
3100 | } else { | |
a8ab39a4 | 3101 | ret = wl1271_cmd_set_ap_key(wl, wlvif, action, |
7f179b46 AN |
3102 | id, key_type, key_size, |
3103 | key, hlid, tx_seq_32, | |
3104 | tx_seq_16); | |
3105 | } | |
3106 | ||
3107 | if (ret < 0) | |
3108 | return ret; | |
3109 | } else { | |
3110 | const u8 *addr; | |
3111 | static const u8 bcast_addr[ETH_ALEN] = { | |
3112 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
3113 | }; | |
3114 | ||
3115 | addr = sta ? sta->addr : bcast_addr; | |
3116 | ||
3117 | if (is_zero_ether_addr(addr)) { | |
3118 | /* We dont support TX only encryption */ | |
3119 | return -EOPNOTSUPP; | |
3120 | } | |
3121 | ||
3122 | /* The wl1271 does not allow to remove unicast keys - they | |
3123 | will be cleared automatically on next CMD_JOIN. Ignore the | |
3124 | request silently, as we dont want the mac80211 to emit | |
3125 | an error message. */ | |
3126 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) | |
3127 | return 0; | |
3128 | ||
010d3d30 EP |
3129 | /* don't remove key if hlid was already deleted */ |
3130 | if (action == KEY_REMOVE && | |
154da67c | 3131 | wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
010d3d30 EP |
3132 | return 0; |
3133 | ||
a8ab39a4 | 3134 | ret = wl1271_cmd_set_sta_key(wl, wlvif, action, |
7f179b46 AN |
3135 | id, key_type, key_size, |
3136 | key, addr, tx_seq_32, | |
3137 | tx_seq_16); | |
3138 | if (ret < 0) | |
3139 | return ret; | |
3140 | ||
3141 | /* the default WEP key needs to be configured at least once */ | |
3142 | if (key_type == KEY_WEP) { | |
c690ec81 | 3143 | ret = wl12xx_cmd_set_default_wep_key(wl, |
f75c753f EP |
3144 | wlvif->default_key, |
3145 | wlvif->sta.hlid); | |
7f179b46 AN |
3146 | if (ret < 0) |
3147 | return ret; | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | return 0; | |
3152 | } | |
3153 | ||
a1c597f2 | 3154 | static int wlcore_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
f5fc0f86 LC |
3155 | struct ieee80211_vif *vif, |
3156 | struct ieee80211_sta *sta, | |
3157 | struct ieee80211_key_conf *key_conf) | |
3158 | { | |
3159 | struct wl1271 *wl = hw->priv; | |
af390f4d EP |
3160 | int ret; |
3161 | bool might_change_spare = | |
3162 | key_conf->cipher == WL1271_CIPHER_SUITE_GEM || | |
3163 | key_conf->cipher == WLAN_CIPHER_SUITE_TKIP; | |
3164 | ||
3165 | if (might_change_spare) { | |
3166 | /* | |
3167 | * stop the queues and flush to ensure the next packets are | |
3168 | * in sync with FW spare block accounting | |
3169 | */ | |
3170 | mutex_lock(&wl->mutex); | |
3171 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); | |
3172 | mutex_unlock(&wl->mutex); | |
3173 | ||
3174 | wl1271_tx_flush(wl); | |
3175 | } | |
3176 | ||
3177 | mutex_lock(&wl->mutex); | |
3178 | ||
3179 | if (unlikely(wl->state != WLCORE_STATE_ON)) { | |
3180 | ret = -EAGAIN; | |
3181 | goto out_wake_queues; | |
3182 | } | |
a1c597f2 | 3183 | |
af390f4d EP |
3184 | ret = wl1271_ps_elp_wakeup(wl); |
3185 | if (ret < 0) | |
3186 | goto out_wake_queues; | |
3187 | ||
3188 | ret = wlcore_hw_set_key(wl, cmd, vif, sta, key_conf); | |
3189 | ||
3190 | wl1271_ps_elp_sleep(wl); | |
3191 | ||
3192 | out_wake_queues: | |
3193 | if (might_change_spare) | |
3194 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); | |
3195 | ||
3196 | mutex_unlock(&wl->mutex); | |
3197 | ||
3198 | return ret; | |
a1c597f2 AN |
3199 | } |
3200 | ||
3201 | int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd, | |
3202 | struct ieee80211_vif *vif, | |
3203 | struct ieee80211_sta *sta, | |
3204 | struct ieee80211_key_conf *key_conf) | |
3205 | { | |
536129c8 | 3206 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
f5fc0f86 | 3207 | int ret; |
ac4e4ce5 JO |
3208 | u32 tx_seq_32 = 0; |
3209 | u16 tx_seq_16 = 0; | |
f5fc0f86 LC |
3210 | u8 key_type; |
3211 | ||
f5fc0f86 LC |
3212 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
3213 | ||
7f179b46 | 3214 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
f5fc0f86 | 3215 | wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", |
97359d12 | 3216 | key_conf->cipher, key_conf->keyidx, |
f5fc0f86 LC |
3217 | key_conf->keylen, key_conf->flags); |
3218 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); | |
3219 | ||
97359d12 JB |
3220 | switch (key_conf->cipher) { |
3221 | case WLAN_CIPHER_SUITE_WEP40: | |
3222 | case WLAN_CIPHER_SUITE_WEP104: | |
f5fc0f86 LC |
3223 | key_type = KEY_WEP; |
3224 | ||
3225 | key_conf->hw_key_idx = key_conf->keyidx; | |
3226 | break; | |
97359d12 | 3227 | case WLAN_CIPHER_SUITE_TKIP: |
f5fc0f86 LC |
3228 | key_type = KEY_TKIP; |
3229 | ||
3230 | key_conf->hw_key_idx = key_conf->keyidx; | |
48e93e40 EP |
3231 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
3232 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | |
f5fc0f86 | 3233 | break; |
97359d12 | 3234 | case WLAN_CIPHER_SUITE_CCMP: |
f5fc0f86 LC |
3235 | key_type = KEY_AES; |
3236 | ||
12d4b975 | 3237 | key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
48e93e40 EP |
3238 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
3239 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | |
f5fc0f86 | 3240 | break; |
7a55724e JO |
3241 | case WL1271_CIPHER_SUITE_GEM: |
3242 | key_type = KEY_GEM; | |
48e93e40 EP |
3243 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
3244 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); | |
7a55724e | 3245 | break; |
f5fc0f86 | 3246 | default: |
97359d12 | 3247 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
f5fc0f86 | 3248 | |
af390f4d | 3249 | return -EOPNOTSUPP; |
f5fc0f86 LC |
3250 | } |
3251 | ||
3252 | switch (cmd) { | |
3253 | case SET_KEY: | |
536129c8 | 3254 | ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
7f179b46 AN |
3255 | key_conf->keyidx, key_type, |
3256 | key_conf->keylen, key_conf->key, | |
3257 | tx_seq_32, tx_seq_16, sta); | |
f5fc0f86 LC |
3258 | if (ret < 0) { |
3259 | wl1271_error("Could not add or replace key"); | |
af390f4d | 3260 | return ret; |
f5fc0f86 | 3261 | } |
5ec8a448 EP |
3262 | |
3263 | /* | |
3264 | * reconfiguring arp response if the unicast (or common) | |
3265 | * encryption key type was changed | |
3266 | */ | |
3267 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && | |
3268 | (sta || key_type == KEY_WEP) && | |
3269 | wlvif->encryption_type != key_type) { | |
3270 | wlvif->encryption_type = key_type; | |
3271 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); | |
3272 | if (ret < 0) { | |
3273 | wl1271_warning("build arp rsp failed: %d", ret); | |
af390f4d | 3274 | return ret; |
5ec8a448 EP |
3275 | } |
3276 | } | |
f5fc0f86 LC |
3277 | break; |
3278 | ||
3279 | case DISABLE_KEY: | |
536129c8 | 3280 | ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, |
7f179b46 AN |
3281 | key_conf->keyidx, key_type, |
3282 | key_conf->keylen, key_conf->key, | |
3283 | 0, 0, sta); | |
f5fc0f86 LC |
3284 | if (ret < 0) { |
3285 | wl1271_error("Could not remove key"); | |
af390f4d | 3286 | return ret; |
f5fc0f86 LC |
3287 | } |
3288 | break; | |
3289 | ||
3290 | default: | |
3291 | wl1271_error("Unsupported key cmd 0x%x", cmd); | |
af390f4d | 3292 | return -EOPNOTSUPP; |
f5fc0f86 LC |
3293 | } |
3294 | ||
f5fc0f86 LC |
3295 | return ret; |
3296 | } | |
a1c597f2 | 3297 | EXPORT_SYMBOL_GPL(wlcore_set_key); |
f5fc0f86 | 3298 | |
6b70e7eb VG |
3299 | void wlcore_regdomain_config(struct wl1271 *wl) |
3300 | { | |
3301 | int ret; | |
3302 | ||
3303 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) | |
3304 | return; | |
3305 | ||
3306 | mutex_lock(&wl->mutex); | |
3307 | ret = wl1271_ps_elp_wakeup(wl); | |
3308 | if (ret < 0) | |
3309 | goto out; | |
3310 | ||
3311 | ret = wlcore_cmd_regdomain_config_locked(wl); | |
3312 | if (ret < 0) { | |
3313 | wl12xx_queue_recovery_work(wl); | |
3314 | goto out; | |
3315 | } | |
3316 | ||
3317 | wl1271_ps_elp_sleep(wl); | |
3318 | out: | |
3319 | mutex_unlock(&wl->mutex); | |
3320 | } | |
3321 | ||
f5fc0f86 | 3322 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, |
a060bbfe | 3323 | struct ieee80211_vif *vif, |
f5fc0f86 LC |
3324 | struct cfg80211_scan_request *req) |
3325 | { | |
3326 | struct wl1271 *wl = hw->priv; | |
3327 | int ret; | |
3328 | u8 *ssid = NULL; | |
abb0b3bf | 3329 | size_t len = 0; |
f5fc0f86 LC |
3330 | |
3331 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); | |
3332 | ||
3333 | if (req->n_ssids) { | |
3334 | ssid = req->ssids[0].ssid; | |
abb0b3bf | 3335 | len = req->ssids[0].ssid_len; |
f5fc0f86 LC |
3336 | } |
3337 | ||
3338 | mutex_lock(&wl->mutex); | |
3339 | ||
4cc53383 | 3340 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
b739a42c JO |
3341 | /* |
3342 | * We cannot return -EBUSY here because cfg80211 will expect | |
3343 | * a call to ieee80211_scan_completed if we do - in this case | |
3344 | * there won't be any call. | |
3345 | */ | |
3346 | ret = -EAGAIN; | |
3347 | goto out; | |
3348 | } | |
3349 | ||
a620865e | 3350 | ret = wl1271_ps_elp_wakeup(wl); |
f5fc0f86 LC |
3351 | if (ret < 0) |
3352 | goto out; | |
3353 | ||
97fd311a EP |
3354 | /* fail if there is any role in ROC */ |
3355 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { | |
92e712da EP |
3356 | /* don't allow scanning right now */ |
3357 | ret = -EBUSY; | |
3358 | goto out_sleep; | |
3359 | } | |
3360 | ||
78e28062 | 3361 | ret = wlcore_scan(hw->priv, vif, ssid, len, req); |
251c177f | 3362 | out_sleep: |
f5fc0f86 | 3363 | wl1271_ps_elp_sleep(wl); |
f5fc0f86 LC |
3364 | out: |
3365 | mutex_unlock(&wl->mutex); | |
3366 | ||
3367 | return ret; | |
3368 | } | |
3369 | ||
73ecce31 EP |
3370 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, |
3371 | struct ieee80211_vif *vif) | |
3372 | { | |
3373 | struct wl1271 *wl = hw->priv; | |
78e28062 | 3374 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
73ecce31 EP |
3375 | int ret; |
3376 | ||
3377 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); | |
3378 | ||
3379 | mutex_lock(&wl->mutex); | |
3380 | ||
4cc53383 | 3381 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
73ecce31 EP |
3382 | goto out; |
3383 | ||
3384 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) | |
3385 | goto out; | |
3386 | ||
3387 | ret = wl1271_ps_elp_wakeup(wl); | |
3388 | if (ret < 0) | |
3389 | goto out; | |
3390 | ||
3391 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { | |
78e28062 | 3392 | ret = wl->ops->scan_stop(wl, wlvif); |
73ecce31 EP |
3393 | if (ret < 0) |
3394 | goto out_sleep; | |
3395 | } | |
55df5afb AN |
3396 | |
3397 | /* | |
3398 | * Rearm the tx watchdog just before idling scan. This | |
3399 | * prevents just-finished scans from triggering the watchdog | |
3400 | */ | |
3401 | wl12xx_rearm_tx_watchdog_locked(wl); | |
3402 | ||
73ecce31 EP |
3403 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
3404 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | |
c50a2825 | 3405 | wl->scan_wlvif = NULL; |
73ecce31 EP |
3406 | wl->scan.req = NULL; |
3407 | ieee80211_scan_completed(wl->hw, true); | |
3408 | ||
3409 | out_sleep: | |
3410 | wl1271_ps_elp_sleep(wl); | |
3411 | out: | |
3412 | mutex_unlock(&wl->mutex); | |
3413 | ||
3414 | cancel_delayed_work_sync(&wl->scan_complete_work); | |
3415 | } | |
3416 | ||
33c2c06c LC |
3417 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, |
3418 | struct ieee80211_vif *vif, | |
3419 | struct cfg80211_sched_scan_request *req, | |
3420 | struct ieee80211_sched_scan_ies *ies) | |
3421 | { | |
3422 | struct wl1271 *wl = hw->priv; | |
536129c8 | 3423 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
33c2c06c LC |
3424 | int ret; |
3425 | ||
3426 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); | |
3427 | ||
3428 | mutex_lock(&wl->mutex); | |
3429 | ||
4cc53383 | 3430 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
9e0dc890 PF |
3431 | ret = -EAGAIN; |
3432 | goto out; | |
3433 | } | |
3434 | ||
33c2c06c LC |
3435 | ret = wl1271_ps_elp_wakeup(wl); |
3436 | if (ret < 0) | |
3437 | goto out; | |
3438 | ||
78e28062 | 3439 | ret = wl->ops->sched_scan_start(wl, wlvif, req, ies); |
33c2c06c LC |
3440 | if (ret < 0) |
3441 | goto out_sleep; | |
3442 | ||
10199756 | 3443 | wl->sched_vif = wlvif; |
33c2c06c LC |
3444 | |
3445 | out_sleep: | |
3446 | wl1271_ps_elp_sleep(wl); | |
3447 | out: | |
3448 | mutex_unlock(&wl->mutex); | |
3449 | return ret; | |
3450 | } | |
3451 | ||
3452 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, | |
3453 | struct ieee80211_vif *vif) | |
3454 | { | |
3455 | struct wl1271 *wl = hw->priv; | |
78f85f50 | 3456 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
33c2c06c LC |
3457 | int ret; |
3458 | ||
3459 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); | |
3460 | ||
3461 | mutex_lock(&wl->mutex); | |
3462 | ||
4cc53383 | 3463 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
9e0dc890 PF |
3464 | goto out; |
3465 | ||
33c2c06c LC |
3466 | ret = wl1271_ps_elp_wakeup(wl); |
3467 | if (ret < 0) | |
3468 | goto out; | |
3469 | ||
78e28062 | 3470 | wl->ops->sched_scan_stop(wl, wlvif); |
33c2c06c LC |
3471 | |
3472 | wl1271_ps_elp_sleep(wl); | |
3473 | out: | |
3474 | mutex_unlock(&wl->mutex); | |
3475 | } | |
3476 | ||
68d069c4 AN |
3477 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
3478 | { | |
3479 | struct wl1271 *wl = hw->priv; | |
3480 | int ret = 0; | |
3481 | ||
3482 | mutex_lock(&wl->mutex); | |
3483 | ||
4cc53383 | 3484 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
68d069c4 AN |
3485 | ret = -EAGAIN; |
3486 | goto out; | |
3487 | } | |
3488 | ||
a620865e | 3489 | ret = wl1271_ps_elp_wakeup(wl); |
68d069c4 AN |
3490 | if (ret < 0) |
3491 | goto out; | |
3492 | ||
5f704d18 | 3493 | ret = wl1271_acx_frag_threshold(wl, value); |
68d069c4 AN |
3494 | if (ret < 0) |
3495 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); | |
3496 | ||
3497 | wl1271_ps_elp_sleep(wl); | |
3498 | ||
3499 | out: | |
3500 | mutex_unlock(&wl->mutex); | |
3501 | ||
3502 | return ret; | |
3503 | } | |
3504 | ||
f5fc0f86 LC |
3505 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
3506 | { | |
3507 | struct wl1271 *wl = hw->priv; | |
6e8cd331 | 3508 | struct wl12xx_vif *wlvif; |
aecb0565 | 3509 | int ret = 0; |
f5fc0f86 LC |
3510 | |
3511 | mutex_lock(&wl->mutex); | |
3512 | ||
4cc53383 | 3513 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
f8d9802f | 3514 | ret = -EAGAIN; |
aecb0565 | 3515 | goto out; |
f8d9802f | 3516 | } |
aecb0565 | 3517 | |
a620865e | 3518 | ret = wl1271_ps_elp_wakeup(wl); |
f5fc0f86 LC |
3519 | if (ret < 0) |
3520 | goto out; | |
3521 | ||
6e8cd331 EP |
3522 | wl12xx_for_each_wlvif(wl, wlvif) { |
3523 | ret = wl1271_acx_rts_threshold(wl, wlvif, value); | |
3524 | if (ret < 0) | |
3525 | wl1271_warning("set rts threshold failed: %d", ret); | |
3526 | } | |
f5fc0f86 LC |
3527 | wl1271_ps_elp_sleep(wl); |
3528 | ||
3529 | out: | |
3530 | mutex_unlock(&wl->mutex); | |
3531 | ||
3532 | return ret; | |
3533 | } | |
3534 | ||
d48055d9 EP |
3535 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) |
3536 | { | |
3537 | int len; | |
3538 | const u8 *next, *end = skb->data + skb->len; | |
3539 | u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, | |
3540 | skb->len - ieoffset); | |
3541 | if (!ie) | |
3542 | return; | |
3543 | len = ie[1] + 2; | |
3544 | next = ie + len; | |
3545 | memmove(ie, next, end - next); | |
3546 | skb_trim(skb, skb->len - len); | |
3547 | } | |
3548 | ||
26b4bf2e EP |
3549 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, |
3550 | unsigned int oui, u8 oui_type, | |
3551 | int ieoffset) | |
3552 | { | |
3553 | int len; | |
3554 | const u8 *next, *end = skb->data + skb->len; | |
3555 | u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, | |
3556 | skb->data + ieoffset, | |
3557 | skb->len - ieoffset); | |
3558 | if (!ie) | |
3559 | return; | |
3560 | len = ie[1] + 2; | |
3561 | next = ie + len; | |
3562 | memmove(ie, next, end - next); | |
3563 | skb_trim(skb, skb->len - len); | |
3564 | } | |
3565 | ||
341f2c11 AN |
3566 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, |
3567 | struct ieee80211_vif *vif) | |
560f0024 | 3568 | { |
cdaac628 | 3569 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
560f0024 AN |
3570 | struct sk_buff *skb; |
3571 | int ret; | |
3572 | ||
341f2c11 | 3573 | skb = ieee80211_proberesp_get(wl->hw, vif); |
560f0024 | 3574 | if (!skb) |
341f2c11 | 3575 | return -EOPNOTSUPP; |
560f0024 | 3576 | |
cdaac628 | 3577 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
560f0024 AN |
3578 | CMD_TEMPL_AP_PROBE_RESPONSE, |
3579 | skb->data, | |
3580 | skb->len, 0, | |
3581 | rates); | |
560f0024 | 3582 | dev_kfree_skb(skb); |
62c2e579 LC |
3583 | |
3584 | if (ret < 0) | |
3585 | goto out; | |
3586 | ||
3587 | wl1271_debug(DEBUG_AP, "probe response updated"); | |
3588 | set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); | |
3589 | ||
3590 | out: | |
560f0024 AN |
3591 | return ret; |
3592 | } | |
3593 | ||
3594 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, | |
3595 | struct ieee80211_vif *vif, | |
3596 | u8 *probe_rsp_data, | |
3597 | size_t probe_rsp_len, | |
3598 | u32 rates) | |
68eaaf6e | 3599 | { |
1fe9f161 EP |
3600 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
3601 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
68eaaf6e AN |
3602 | u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; |
3603 | int ssid_ie_offset, ie_offset, templ_len; | |
3604 | const u8 *ptr; | |
3605 | ||
3606 | /* no need to change probe response if the SSID is set correctly */ | |
1fe9f161 | 3607 | if (wlvif->ssid_len > 0) |
cdaac628 | 3608 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
68eaaf6e AN |
3609 | CMD_TEMPL_AP_PROBE_RESPONSE, |
3610 | probe_rsp_data, | |
3611 | probe_rsp_len, 0, | |
3612 | rates); | |
3613 | ||
3614 | if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { | |
3615 | wl1271_error("probe_rsp template too big"); | |
3616 | return -EINVAL; | |
3617 | } | |
3618 | ||
3619 | /* start searching from IE offset */ | |
3620 | ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
3621 | ||
3622 | ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, | |
3623 | probe_rsp_len - ie_offset); | |
3624 | if (!ptr) { | |
3625 | wl1271_error("No SSID in beacon!"); | |
3626 | return -EINVAL; | |
3627 | } | |
3628 | ||
3629 | ssid_ie_offset = ptr - probe_rsp_data; | |
3630 | ptr += (ptr[1] + 2); | |
3631 | ||
3632 | memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); | |
3633 | ||
3634 | /* insert SSID from bss_conf */ | |
3635 | probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; | |
3636 | probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; | |
3637 | memcpy(probe_rsp_templ + ssid_ie_offset + 2, | |
3638 | bss_conf->ssid, bss_conf->ssid_len); | |
3639 | templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; | |
3640 | ||
3641 | memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, | |
3642 | ptr, probe_rsp_len - (ptr - probe_rsp_data)); | |
3643 | templ_len += probe_rsp_len - (ptr - probe_rsp_data); | |
3644 | ||
cdaac628 | 3645 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
68eaaf6e AN |
3646 | CMD_TEMPL_AP_PROBE_RESPONSE, |
3647 | probe_rsp_templ, | |
3648 | templ_len, 0, | |
3649 | rates); | |
3650 | } | |
3651 | ||
e78a287a | 3652 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
0603d891 | 3653 | struct ieee80211_vif *vif, |
f5fc0f86 LC |
3654 | struct ieee80211_bss_conf *bss_conf, |
3655 | u32 changed) | |
3656 | { | |
0603d891 | 3657 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
e78a287a | 3658 | int ret = 0; |
f5fc0f86 | 3659 | |
e78a287a AN |
3660 | if (changed & BSS_CHANGED_ERP_SLOT) { |
3661 | if (bss_conf->use_short_slot) | |
0603d891 | 3662 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); |
e78a287a | 3663 | else |
0603d891 | 3664 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); |
e78a287a AN |
3665 | if (ret < 0) { |
3666 | wl1271_warning("Set slot time failed %d", ret); | |
3667 | goto out; | |
3668 | } | |
3669 | } | |
f5fc0f86 | 3670 | |
e78a287a AN |
3671 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
3672 | if (bss_conf->use_short_preamble) | |
0603d891 | 3673 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); |
e78a287a | 3674 | else |
0603d891 | 3675 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); |
e78a287a | 3676 | } |
f5fc0f86 | 3677 | |
e78a287a AN |
3678 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
3679 | if (bss_conf->use_cts_prot) | |
0603d891 EP |
3680 | ret = wl1271_acx_cts_protect(wl, wlvif, |
3681 | CTSPROTECT_ENABLE); | |
e78a287a | 3682 | else |
0603d891 EP |
3683 | ret = wl1271_acx_cts_protect(wl, wlvif, |
3684 | CTSPROTECT_DISABLE); | |
e78a287a AN |
3685 | if (ret < 0) { |
3686 | wl1271_warning("Set ctsprotect failed %d", ret); | |
3687 | goto out; | |
3688 | } | |
3689 | } | |
f8d9802f | 3690 | |
e78a287a AN |
3691 | out: |
3692 | return ret; | |
3693 | } | |
f5fc0f86 | 3694 | |
62c2e579 LC |
3695 | static int wlcore_set_beacon_template(struct wl1271 *wl, |
3696 | struct ieee80211_vif *vif, | |
3697 | bool is_ap) | |
3698 | { | |
3699 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
3700 | struct ieee80211_hdr *hdr; | |
3701 | u32 min_rate; | |
3702 | int ret; | |
3703 | int ieoffset = offsetof(struct ieee80211_mgmt, | |
3704 | u.beacon.variable); | |
3705 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); | |
3706 | u16 tmpl_id; | |
3707 | ||
3708 | if (!beacon) { | |
3709 | ret = -EINVAL; | |
3710 | goto out; | |
3711 | } | |
3712 | ||
3713 | wl1271_debug(DEBUG_MASTER, "beacon updated"); | |
3714 | ||
3230f35e | 3715 | ret = wl1271_ssid_set(wlvif, beacon, ieoffset); |
62c2e579 LC |
3716 | if (ret < 0) { |
3717 | dev_kfree_skb(beacon); | |
3718 | goto out; | |
3719 | } | |
3720 | min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | |
3721 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : | |
3722 | CMD_TEMPL_BEACON; | |
3723 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, | |
3724 | beacon->data, | |
3725 | beacon->len, 0, | |
3726 | min_rate); | |
3727 | if (ret < 0) { | |
3728 | dev_kfree_skb(beacon); | |
3729 | goto out; | |
3730 | } | |
3731 | ||
d50529c0 EP |
3732 | wlvif->wmm_enabled = |
3733 | cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, | |
3734 | WLAN_OUI_TYPE_MICROSOFT_WMM, | |
3735 | beacon->data + ieoffset, | |
3736 | beacon->len - ieoffset); | |
3737 | ||
62c2e579 LC |
3738 | /* |
3739 | * In case we already have a probe-resp beacon set explicitly | |
3740 | * by usermode, don't use the beacon data. | |
3741 | */ | |
3742 | if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) | |
3743 | goto end_bcn; | |
3744 | ||
3745 | /* remove TIM ie from probe response */ | |
3746 | wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); | |
3747 | ||
3748 | /* | |
3749 | * remove p2p ie from probe response. | |
3750 | * the fw reponds to probe requests that don't include | |
3751 | * the p2p ie. probe requests with p2p ie will be passed, | |
3752 | * and will be responded by the supplicant (the spec | |
3753 | * forbids including the p2p ie when responding to probe | |
3754 | * requests that didn't include it). | |
3755 | */ | |
3756 | wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, | |
3757 | WLAN_OUI_TYPE_WFA_P2P, ieoffset); | |
3758 | ||
3759 | hdr = (struct ieee80211_hdr *) beacon->data; | |
3760 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
3761 | IEEE80211_STYPE_PROBE_RESP); | |
3762 | if (is_ap) | |
3763 | ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, | |
3764 | beacon->data, | |
3765 | beacon->len, | |
3766 | min_rate); | |
3767 | else | |
3768 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, | |
3769 | CMD_TEMPL_PROBE_RESPONSE, | |
3770 | beacon->data, | |
3771 | beacon->len, 0, | |
3772 | min_rate); | |
3773 | end_bcn: | |
3774 | dev_kfree_skb(beacon); | |
3775 | if (ret < 0) | |
3776 | goto out; | |
3777 | ||
3778 | out: | |
3779 | return ret; | |
3780 | } | |
3781 | ||
e78a287a AN |
3782 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
3783 | struct ieee80211_vif *vif, | |
3784 | struct ieee80211_bss_conf *bss_conf, | |
3785 | u32 changed) | |
3786 | { | |
87fbcb0f | 3787 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
536129c8 | 3788 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
e78a287a AN |
3789 | int ret = 0; |
3790 | ||
48af2eb0 | 3791 | if (changed & BSS_CHANGED_BEACON_INT) { |
e78a287a | 3792 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", |
60e84c2e JO |
3793 | bss_conf->beacon_int); |
3794 | ||
6a899796 | 3795 | wlvif->beacon_int = bss_conf->beacon_int; |
60e84c2e JO |
3796 | } |
3797 | ||
560f0024 AN |
3798 | if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { |
3799 | u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | |
62c2e579 LC |
3800 | |
3801 | wl1271_ap_set_probe_resp_tmpl(wl, rate, vif); | |
560f0024 AN |
3802 | } |
3803 | ||
48af2eb0 | 3804 | if (changed & BSS_CHANGED_BEACON) { |
62c2e579 | 3805 | ret = wlcore_set_beacon_template(wl, vif, is_ap); |
e78a287a AN |
3806 | if (ret < 0) |
3807 | goto out; | |
3808 | } | |
3809 | ||
3810 | out: | |
560f0024 AN |
3811 | if (ret != 0) |
3812 | wl1271_error("beacon info change failed: %d", ret); | |
e78a287a AN |
3813 | return ret; |
3814 | } | |
3815 | ||
3816 | /* AP mode changes */ | |
3817 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, | |
3818 | struct ieee80211_vif *vif, | |
3819 | struct ieee80211_bss_conf *bss_conf, | |
3820 | u32 changed) | |
3821 | { | |
87fbcb0f | 3822 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
e78a287a | 3823 | int ret = 0; |
e0d8bbf0 | 3824 | |
b6970ee5 | 3825 | if (changed & BSS_CHANGED_BASIC_RATES) { |
e78a287a | 3826 | u32 rates = bss_conf->basic_rates; |
5da11dcd | 3827 | |
87fbcb0f | 3828 | wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, |
1b92f15e | 3829 | wlvif->band); |
d2d66c56 | 3830 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, |
87fbcb0f | 3831 | wlvif->basic_rate_set); |
70f47424 | 3832 | |
87fbcb0f | 3833 | ret = wl1271_init_ap_rates(wl, wlvif); |
e78a287a | 3834 | if (ret < 0) { |
70f47424 | 3835 | wl1271_error("AP rate policy change failed %d", ret); |
e78a287a AN |
3836 | goto out; |
3837 | } | |
c45a85b5 | 3838 | |
784f694d | 3839 | ret = wl1271_ap_init_templates(wl, vif); |
c45a85b5 AN |
3840 | if (ret < 0) |
3841 | goto out; | |
62c2e579 LC |
3842 | |
3843 | ret = wl1271_ap_set_probe_resp_tmpl(wl, wlvif->basic_rate, vif); | |
3844 | if (ret < 0) | |
3845 | goto out; | |
3846 | ||
3847 | ret = wlcore_set_beacon_template(wl, vif, true); | |
3848 | if (ret < 0) | |
3849 | goto out; | |
e78a287a | 3850 | } |
2f6724b2 | 3851 | |
e78a287a AN |
3852 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
3853 | if (ret < 0) | |
3854 | goto out; | |
30240fc7 | 3855 | |
48af2eb0 | 3856 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
e78a287a | 3857 | if (bss_conf->enable_beacon) { |
53d40d0b | 3858 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
87fbcb0f | 3859 | ret = wl12xx_cmd_role_start_ap(wl, wlvif); |
e78a287a AN |
3860 | if (ret < 0) |
3861 | goto out; | |
e0d8bbf0 | 3862 | |
a8ab39a4 | 3863 | ret = wl1271_ap_init_hwenc(wl, wlvif); |
7f179b46 AN |
3864 | if (ret < 0) |
3865 | goto out; | |
cf42039f | 3866 | |
53d40d0b | 3867 | set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
cf42039f | 3868 | wl1271_debug(DEBUG_AP, "started AP"); |
e0d8bbf0 | 3869 | } |
e78a287a | 3870 | } else { |
53d40d0b | 3871 | if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
0603d891 | 3872 | ret = wl12xx_cmd_role_stop_ap(wl, wlvif); |
e78a287a AN |
3873 | if (ret < 0) |
3874 | goto out; | |
e0d8bbf0 | 3875 | |
53d40d0b | 3876 | clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
560f0024 AN |
3877 | clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, |
3878 | &wlvif->flags); | |
e78a287a AN |
3879 | wl1271_debug(DEBUG_AP, "stopped AP"); |
3880 | } | |
3881 | } | |
3882 | } | |
e0d8bbf0 | 3883 | |
0603d891 | 3884 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
e78a287a AN |
3885 | if (ret < 0) |
3886 | goto out; | |
0b932ab9 AN |
3887 | |
3888 | /* Handle HT information change */ | |
3889 | if ((changed & BSS_CHANGED_HT) && | |
3890 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | |
0603d891 | 3891 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
0b932ab9 AN |
3892 | bss_conf->ht_operation_mode); |
3893 | if (ret < 0) { | |
3894 | wl1271_warning("Set ht information failed %d", ret); | |
3895 | goto out; | |
3896 | } | |
3897 | } | |
3898 | ||
e78a287a AN |
3899 | out: |
3900 | return; | |
3901 | } | |
8bf29b0e | 3902 | |
3230f35e EP |
3903 | static int wlcore_set_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
3904 | struct ieee80211_bss_conf *bss_conf, | |
3905 | u32 sta_rate_set) | |
3906 | { | |
3907 | u32 rates; | |
3908 | int ret; | |
3909 | ||
3910 | wl1271_debug(DEBUG_MAC80211, | |
3911 | "changed_bssid: %pM, aid: %d, bcn_int: %d, brates: 0x%x sta_rate_set: 0x%x", | |
3912 | bss_conf->bssid, bss_conf->aid, | |
3913 | bss_conf->beacon_int, | |
3914 | bss_conf->basic_rates, sta_rate_set); | |
3915 | ||
3916 | wlvif->beacon_int = bss_conf->beacon_int; | |
3917 | rates = bss_conf->basic_rates; | |
3918 | wlvif->basic_rate_set = | |
3919 | wl1271_tx_enabled_rates_get(wl, rates, | |
3920 | wlvif->band); | |
3921 | wlvif->basic_rate = | |
3922 | wl1271_tx_min_rate_get(wl, | |
3923 | wlvif->basic_rate_set); | |
3924 | ||
3925 | if (sta_rate_set) | |
3926 | wlvif->rate_set = | |
3927 | wl1271_tx_enabled_rates_get(wl, | |
3928 | sta_rate_set, | |
3929 | wlvif->band); | |
3930 | ||
3931 | /* we only support sched_scan while not connected */ | |
10199756 | 3932 | if (wl->sched_vif == wlvif) |
78e28062 | 3933 | wl->ops->sched_scan_stop(wl, wlvif); |
3230f35e EP |
3934 | |
3935 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); | |
3936 | if (ret < 0) | |
3937 | return ret; | |
3938 | ||
3939 | ret = wl12xx_cmd_build_null_data(wl, wlvif); | |
3940 | if (ret < 0) | |
3941 | return ret; | |
3942 | ||
3943 | ret = wl1271_build_qos_null_data(wl, wl12xx_wlvif_to_vif(wlvif)); | |
3944 | if (ret < 0) | |
3945 | return ret; | |
3946 | ||
3947 | wlcore_set_ssid(wl, wlvif); | |
3948 | ||
3949 | set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); | |
3950 | ||
3951 | return 0; | |
3952 | } | |
3953 | ||
3954 | static int wlcore_clear_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) | |
3955 | { | |
3956 | int ret; | |
3957 | ||
3958 | /* revert back to minimum rates for the current band */ | |
3959 | wl1271_set_band_rate(wl, wlvif); | |
3960 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | |
3961 | ||
3962 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); | |
3963 | if (ret < 0) | |
3964 | return ret; | |
3965 | ||
3966 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && | |
3967 | test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags)) { | |
3968 | ret = wl12xx_cmd_role_stop_sta(wl, wlvif); | |
3969 | if (ret < 0) | |
3970 | return ret; | |
3971 | } | |
3972 | ||
3973 | clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); | |
3974 | return 0; | |
3975 | } | |
e78a287a AN |
3976 | /* STA/IBSS mode changes */ |
3977 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, | |
3978 | struct ieee80211_vif *vif, | |
3979 | struct ieee80211_bss_conf *bss_conf, | |
3980 | u32 changed) | |
3981 | { | |
87fbcb0f | 3982 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
3230f35e | 3983 | bool do_join = false; |
536129c8 | 3984 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
227e81e1 | 3985 | bool ibss_joined = false; |
72c2d9e5 | 3986 | u32 sta_rate_set = 0; |
e78a287a | 3987 | int ret; |
2d6e4e76 | 3988 | struct ieee80211_sta *sta; |
a100885d AN |
3989 | bool sta_exists = false; |
3990 | struct ieee80211_sta_ht_cap sta_ht_cap; | |
e78a287a AN |
3991 | |
3992 | if (is_ibss) { | |
3993 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, | |
3994 | changed); | |
3995 | if (ret < 0) | |
3996 | goto out; | |
e0d8bbf0 JO |
3997 | } |
3998 | ||
227e81e1 EP |
3999 | if (changed & BSS_CHANGED_IBSS) { |
4000 | if (bss_conf->ibss_joined) { | |
eee514e3 | 4001 | set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); |
227e81e1 EP |
4002 | ibss_joined = true; |
4003 | } else { | |
3230f35e EP |
4004 | wlcore_unset_assoc(wl, wlvif); |
4005 | wl12xx_cmd_role_stop_sta(wl, wlvif); | |
227e81e1 EP |
4006 | } |
4007 | } | |
4008 | ||
4009 | if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) | |
e78a287a AN |
4010 | do_join = true; |
4011 | ||
4012 | /* Need to update the SSID (for filtering etc) */ | |
227e81e1 | 4013 | if ((changed & BSS_CHANGED_BEACON) && ibss_joined) |
e78a287a AN |
4014 | do_join = true; |
4015 | ||
227e81e1 | 4016 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { |
5da11dcd JO |
4017 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
4018 | bss_conf->enable_beacon ? "enabled" : "disabled"); | |
4019 | ||
5da11dcd JO |
4020 | do_join = true; |
4021 | } | |
4022 | ||
48af2eb0 | 4023 | if (changed & BSS_CHANGED_CQM) { |
00236aed JO |
4024 | bool enable = false; |
4025 | if (bss_conf->cqm_rssi_thold) | |
4026 | enable = true; | |
0603d891 | 4027 | ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, |
00236aed JO |
4028 | bss_conf->cqm_rssi_thold, |
4029 | bss_conf->cqm_rssi_hyst); | |
4030 | if (ret < 0) | |
4031 | goto out; | |
04324d99 | 4032 | wlvif->rssi_thold = bss_conf->cqm_rssi_thold; |
00236aed JO |
4033 | } |
4034 | ||
ec87011a EP |
4035 | if (changed & (BSS_CHANGED_BSSID | BSS_CHANGED_HT | |
4036 | BSS_CHANGED_ASSOC)) { | |
0f9c8250 AN |
4037 | rcu_read_lock(); |
4038 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
ef08d028 LC |
4039 | if (sta) { |
4040 | u8 *rx_mask = sta->ht_cap.mcs.rx_mask; | |
4041 | ||
4042 | /* save the supp_rates of the ap */ | |
4043 | sta_rate_set = sta->supp_rates[wlvif->band]; | |
4044 | if (sta->ht_cap.ht_supported) | |
4045 | sta_rate_set |= | |
4046 | (rx_mask[0] << HW_HT_RATES_OFFSET) | | |
4047 | (rx_mask[1] << HW_MIMO_RATES_OFFSET); | |
4048 | sta_ht_cap = sta->ht_cap; | |
4049 | sta_exists = true; | |
4050 | } | |
4051 | ||
0f9c8250 | 4052 | rcu_read_unlock(); |
72c2d9e5 | 4053 | } |
72c2d9e5 | 4054 | |
3230f35e EP |
4055 | if (changed & BSS_CHANGED_BSSID) { |
4056 | if (!is_zero_ether_addr(bss_conf->bssid)) { | |
4057 | ret = wlcore_set_bssid(wl, wlvif, bss_conf, | |
4058 | sta_rate_set); | |
f5fc0f86 | 4059 | if (ret < 0) |
e78a287a | 4060 | goto out; |
f5fc0f86 | 4061 | |
3230f35e EP |
4062 | /* Need to update the BSSID (for filtering etc) */ |
4063 | do_join = true; | |
d94cd297 | 4064 | } else { |
3230f35e | 4065 | ret = wlcore_clear_bssid(wl, wlvif); |
6ccbb92e | 4066 | if (ret < 0) |
e78a287a | 4067 | goto out; |
f5fc0f86 | 4068 | } |
f5fc0f86 LC |
4069 | } |
4070 | ||
d192d268 EP |
4071 | if (changed & BSS_CHANGED_IBSS) { |
4072 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", | |
4073 | bss_conf->ibss_joined); | |
4074 | ||
4075 | if (bss_conf->ibss_joined) { | |
4076 | u32 rates = bss_conf->basic_rates; | |
87fbcb0f | 4077 | wlvif->basic_rate_set = |
af7fbb28 | 4078 | wl1271_tx_enabled_rates_get(wl, rates, |
1b92f15e | 4079 | wlvif->band); |
d2d66c56 | 4080 | wlvif->basic_rate = |
87fbcb0f EP |
4081 | wl1271_tx_min_rate_get(wl, |
4082 | wlvif->basic_rate_set); | |
d192d268 | 4083 | |
06b660e1 | 4084 | /* by default, use 11b + OFDM rates */ |
30d0c8fd EP |
4085 | wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; |
4086 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); | |
d192d268 EP |
4087 | if (ret < 0) |
4088 | goto out; | |
4089 | } | |
4090 | } | |
4091 | ||
0603d891 | 4092 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
e78a287a AN |
4093 | if (ret < 0) |
4094 | goto out; | |
f5fc0f86 | 4095 | |
8bf29b0e | 4096 | if (do_join) { |
3230f35e | 4097 | ret = wlcore_join(wl, wlvif); |
8bf29b0e JO |
4098 | if (ret < 0) { |
4099 | wl1271_warning("cmd join failed %d", ret); | |
e78a287a | 4100 | goto out; |
8bf29b0e | 4101 | } |
3230f35e EP |
4102 | } |
4103 | ||
4104 | if (changed & BSS_CHANGED_ASSOC) { | |
4105 | if (bss_conf->assoc) { | |
ec87011a EP |
4106 | ret = wlcore_set_assoc(wl, wlvif, bss_conf, |
4107 | sta_rate_set); | |
251c177f EP |
4108 | if (ret < 0) |
4109 | goto out; | |
3230f35e EP |
4110 | |
4111 | if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags)) | |
4112 | wl12xx_set_authorized(wl, wlvif); | |
4113 | } else { | |
4114 | wlcore_unset_assoc(wl, wlvif); | |
251c177f | 4115 | } |
c1899554 JO |
4116 | } |
4117 | ||
0b932ab9 | 4118 | /* Handle new association with HT. Do this after join. */ |
58321b29 EP |
4119 | if (sta_exists && |
4120 | (changed & BSS_CHANGED_HT)) { | |
4121 | bool enabled = | |
4122 | bss_conf->channel_type != NL80211_CHAN_NO_HT; | |
4123 | ||
4124 | ret = wl1271_acx_set_ht_capabilities(wl, | |
4125 | &sta_ht_cap, | |
4126 | enabled, | |
4127 | wlvif->sta.hlid); | |
4128 | if (ret < 0) { | |
4129 | wl1271_warning("Set ht cap failed %d", ret); | |
4130 | goto out; | |
4131 | ||
0f9c8250 | 4132 | } |
58321b29 EP |
4133 | |
4134 | if (enabled) { | |
4135 | ret = wl1271_acx_set_ht_information(wl, wlvif, | |
4136 | bss_conf->ht_operation_mode); | |
0f9c8250 | 4137 | if (ret < 0) { |
58321b29 | 4138 | wl1271_warning("Set ht information failed %d", |
0f9c8250 AN |
4139 | ret); |
4140 | goto out; | |
4141 | } | |
4142 | } | |
4143 | } | |
4144 | ||
76a74c8a EP |
4145 | /* Handle arp filtering. Done after join. */ |
4146 | if ((changed & BSS_CHANGED_ARP_FILTER) || | |
4147 | (!is_ibss && (changed & BSS_CHANGED_QOS))) { | |
4148 | __be32 addr = bss_conf->arp_addr_list[0]; | |
4149 | wlvif->sta.qos = bss_conf->qos; | |
4150 | WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); | |
4151 | ||
4152 | if (bss_conf->arp_addr_cnt == 1 && | |
4153 | bss_conf->arp_filter_enabled) { | |
4154 | wlvif->ip_addr = addr; | |
4155 | /* | |
4156 | * The template should have been configured only upon | |
4157 | * association. however, it seems that the correct ip | |
4158 | * isn't being set (when sending), so we have to | |
4159 | * reconfigure the template upon every ip change. | |
4160 | */ | |
4161 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); | |
4162 | if (ret < 0) { | |
4163 | wl1271_warning("build arp rsp failed: %d", ret); | |
4164 | goto out; | |
4165 | } | |
4166 | ||
4167 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, | |
4168 | (ACX_ARP_FILTER_ARP_FILTERING | | |
4169 | ACX_ARP_FILTER_AUTO_ARP), | |
4170 | addr); | |
4171 | } else { | |
4172 | wlvif->ip_addr = 0; | |
4173 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); | |
4174 | } | |
4175 | ||
4176 | if (ret < 0) | |
4177 | goto out; | |
4178 | } | |
4179 | ||
e78a287a AN |
4180 | out: |
4181 | return; | |
4182 | } | |
4183 | ||
4184 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, | |
4185 | struct ieee80211_vif *vif, | |
4186 | struct ieee80211_bss_conf *bss_conf, | |
4187 | u32 changed) | |
4188 | { | |
4189 | struct wl1271 *wl = hw->priv; | |
536129c8 EP |
4190 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
4191 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); | |
e78a287a AN |
4192 | int ret; |
4193 | ||
d3f5a1b5 EP |
4194 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info role %d changed 0x%x", |
4195 | wlvif->role_id, (int)changed); | |
e78a287a | 4196 | |
6b8bf5bc AN |
4197 | /* |
4198 | * make sure to cancel pending disconnections if our association | |
4199 | * state changed | |
4200 | */ | |
4201 | if (!is_ap && (changed & BSS_CHANGED_ASSOC)) | |
c50a2825 | 4202 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
6b8bf5bc | 4203 | |
b515d83a EP |
4204 | if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) && |
4205 | !bss_conf->enable_beacon) | |
4206 | wl1271_tx_flush(wl); | |
4207 | ||
e78a287a AN |
4208 | mutex_lock(&wl->mutex); |
4209 | ||
4cc53383 | 4210 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
e78a287a AN |
4211 | goto out; |
4212 | ||
10c8cd01 EP |
4213 | if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) |
4214 | goto out; | |
4215 | ||
a620865e | 4216 | ret = wl1271_ps_elp_wakeup(wl); |
e78a287a AN |
4217 | if (ret < 0) |
4218 | goto out; | |
4219 | ||
4220 | if (is_ap) | |
4221 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); | |
4222 | else | |
4223 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); | |
4224 | ||
f5fc0f86 LC |
4225 | wl1271_ps_elp_sleep(wl); |
4226 | ||
4227 | out: | |
4228 | mutex_unlock(&wl->mutex); | |
4229 | } | |
4230 | ||
b6970ee5 EP |
4231 | static int wlcore_op_add_chanctx(struct ieee80211_hw *hw, |
4232 | struct ieee80211_chanctx_conf *ctx) | |
4233 | { | |
4234 | wl1271_debug(DEBUG_MAC80211, "mac80211 add chanctx %d (type %d)", | |
4235 | ieee80211_frequency_to_channel(ctx->channel->center_freq), | |
4236 | ctx->channel_type); | |
4237 | return 0; | |
4238 | } | |
4239 | ||
4240 | static void wlcore_op_remove_chanctx(struct ieee80211_hw *hw, | |
4241 | struct ieee80211_chanctx_conf *ctx) | |
4242 | { | |
4243 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove chanctx %d (type %d)", | |
4244 | ieee80211_frequency_to_channel(ctx->channel->center_freq), | |
4245 | ctx->channel_type); | |
4246 | } | |
4247 | ||
4248 | static void wlcore_op_change_chanctx(struct ieee80211_hw *hw, | |
4249 | struct ieee80211_chanctx_conf *ctx, | |
4250 | u32 changed) | |
4251 | { | |
4252 | wl1271_debug(DEBUG_MAC80211, | |
4253 | "mac80211 change chanctx %d (type %d) changed 0x%x", | |
4254 | ieee80211_frequency_to_channel(ctx->channel->center_freq), | |
4255 | ctx->channel_type, changed); | |
4256 | } | |
4257 | ||
4258 | static int wlcore_op_assign_vif_chanctx(struct ieee80211_hw *hw, | |
4259 | struct ieee80211_vif *vif, | |
4260 | struct ieee80211_chanctx_conf *ctx) | |
4261 | { | |
4262 | struct wl1271 *wl = hw->priv; | |
4263 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4264 | int channel = ieee80211_frequency_to_channel( | |
4265 | ctx->channel->center_freq); | |
4266 | ||
4267 | wl1271_debug(DEBUG_MAC80211, | |
4268 | "mac80211 assign chanctx (role %d) %d (type %d)", | |
4269 | wlvif->role_id, channel, ctx->channel_type); | |
4270 | ||
4271 | mutex_lock(&wl->mutex); | |
4272 | ||
4273 | wlvif->band = ctx->channel->band; | |
4274 | wlvif->channel = channel; | |
4275 | wlvif->channel_type = ctx->channel_type; | |
4276 | ||
4277 | /* update default rates according to the band */ | |
4278 | wl1271_set_band_rate(wl, wlvif); | |
4279 | ||
4280 | mutex_unlock(&wl->mutex); | |
4281 | ||
4282 | return 0; | |
4283 | } | |
4284 | ||
4285 | static void wlcore_op_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
4286 | struct ieee80211_vif *vif, | |
4287 | struct ieee80211_chanctx_conf *ctx) | |
4288 | { | |
4289 | struct wl1271 *wl = hw->priv; | |
4290 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4291 | ||
4292 | wl1271_debug(DEBUG_MAC80211, | |
4293 | "mac80211 unassign chanctx (role %d) %d (type %d)", | |
4294 | wlvif->role_id, | |
4295 | ieee80211_frequency_to_channel(ctx->channel->center_freq), | |
4296 | ctx->channel_type); | |
4297 | ||
4298 | wl1271_tx_flush(wl); | |
4299 | } | |
4300 | ||
8a3a3c85 EP |
4301 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, |
4302 | struct ieee80211_vif *vif, u16 queue, | |
c6999d83 KV |
4303 | const struct ieee80211_tx_queue_params *params) |
4304 | { | |
4305 | struct wl1271 *wl = hw->priv; | |
0603d891 | 4306 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
4695dc91 | 4307 | u8 ps_scheme; |
488fc540 | 4308 | int ret = 0; |
c6999d83 KV |
4309 | |
4310 | mutex_lock(&wl->mutex); | |
4311 | ||
4312 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); | |
4313 | ||
4695dc91 KV |
4314 | if (params->uapsd) |
4315 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; | |
4316 | else | |
4317 | ps_scheme = CONF_PS_SCHEME_LEGACY; | |
4318 | ||
5b37ddfe | 4319 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
c1b193eb | 4320 | goto out; |
488fc540 | 4321 | |
c1b193eb EP |
4322 | ret = wl1271_ps_elp_wakeup(wl); |
4323 | if (ret < 0) | |
4324 | goto out; | |
488fc540 | 4325 | |
c1b193eb EP |
4326 | /* |
4327 | * the txop is confed in units of 32us by the mac80211, | |
4328 | * we need us | |
4329 | */ | |
0603d891 | 4330 | ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
c1b193eb EP |
4331 | params->cw_min, params->cw_max, |
4332 | params->aifs, params->txop << 5); | |
4333 | if (ret < 0) | |
4334 | goto out_sleep; | |
4335 | ||
0603d891 | 4336 | ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
c1b193eb EP |
4337 | CONF_CHANNEL_TYPE_EDCF, |
4338 | wl1271_tx_get_queue(queue), | |
4339 | ps_scheme, CONF_ACK_POLICY_LEGACY, | |
4340 | 0, 0); | |
c82c1dde KV |
4341 | |
4342 | out_sleep: | |
c1b193eb | 4343 | wl1271_ps_elp_sleep(wl); |
c6999d83 KV |
4344 | |
4345 | out: | |
4346 | mutex_unlock(&wl->mutex); | |
4347 | ||
4348 | return ret; | |
4349 | } | |
4350 | ||
37a41b4a EP |
4351 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, |
4352 | struct ieee80211_vif *vif) | |
bbbb538e JO |
4353 | { |
4354 | ||
4355 | struct wl1271 *wl = hw->priv; | |
9c531149 | 4356 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
bbbb538e JO |
4357 | u64 mactime = ULLONG_MAX; |
4358 | int ret; | |
4359 | ||
4360 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); | |
4361 | ||
4362 | mutex_lock(&wl->mutex); | |
4363 | ||
4cc53383 | 4364 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
f8d9802f JO |
4365 | goto out; |
4366 | ||
a620865e | 4367 | ret = wl1271_ps_elp_wakeup(wl); |
bbbb538e JO |
4368 | if (ret < 0) |
4369 | goto out; | |
4370 | ||
9c531149 | 4371 | ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); |
bbbb538e JO |
4372 | if (ret < 0) |
4373 | goto out_sleep; | |
4374 | ||
4375 | out_sleep: | |
4376 | wl1271_ps_elp_sleep(wl); | |
4377 | ||
4378 | out: | |
4379 | mutex_unlock(&wl->mutex); | |
4380 | return mactime; | |
4381 | } | |
f5fc0f86 | 4382 | |
ece550d0 JL |
4383 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
4384 | struct survey_info *survey) | |
4385 | { | |
ece550d0 | 4386 | struct ieee80211_conf *conf = &hw->conf; |
b739a42c | 4387 | |
ece550d0 JL |
4388 | if (idx != 0) |
4389 | return -ENOENT; | |
b739a42c | 4390 | |
ece550d0 | 4391 | survey->channel = conf->channel; |
add779a0 | 4392 | survey->filled = 0; |
ece550d0 JL |
4393 | return 0; |
4394 | } | |
4395 | ||
409622ec | 4396 | static int wl1271_allocate_sta(struct wl1271 *wl, |
c7ffb902 EP |
4397 | struct wl12xx_vif *wlvif, |
4398 | struct ieee80211_sta *sta) | |
f84f7d78 AN |
4399 | { |
4400 | struct wl1271_station *wl_sta; | |
c7ffb902 | 4401 | int ret; |
f84f7d78 | 4402 | |
c7ffb902 EP |
4403 | |
4404 | if (wl->active_sta_count >= AP_MAX_STATIONS) { | |
f84f7d78 AN |
4405 | wl1271_warning("could not allocate HLID - too much stations"); |
4406 | return -EBUSY; | |
4407 | } | |
4408 | ||
4409 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
c7ffb902 EP |
4410 | ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); |
4411 | if (ret < 0) { | |
4412 | wl1271_warning("could not allocate HLID - too many links"); | |
4413 | return -EBUSY; | |
4414 | } | |
4415 | ||
4416 | set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); | |
b622d992 | 4417 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); |
da03209e | 4418 | wl->active_sta_count++; |
f84f7d78 AN |
4419 | return 0; |
4420 | } | |
4421 | ||
c7ffb902 | 4422 | void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid) |
f84f7d78 | 4423 | { |
c7ffb902 | 4424 | if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) |
f1acea9a AN |
4425 | return; |
4426 | ||
c7ffb902 | 4427 | clear_bit(hlid, wlvif->ap.sta_hlid_map); |
b622d992 | 4428 | memset(wl->links[hlid].addr, 0, ETH_ALEN); |
0f9c8250 | 4429 | wl->links[hlid].ba_bitmap = 0; |
b622d992 AN |
4430 | __clear_bit(hlid, &wl->ap_ps_map); |
4431 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | |
c7ffb902 | 4432 | wl12xx_free_link(wl, wlvif, &hlid); |
da03209e | 4433 | wl->active_sta_count--; |
55df5afb AN |
4434 | |
4435 | /* | |
4436 | * rearm the tx watchdog when the last STA is freed - give the FW a | |
4437 | * chance to return STA-buffered packets before complaining. | |
4438 | */ | |
4439 | if (wl->active_sta_count == 0) | |
4440 | wl12xx_rearm_tx_watchdog_locked(wl); | |
f84f7d78 AN |
4441 | } |
4442 | ||
2d6cf2b5 EP |
4443 | static int wl12xx_sta_add(struct wl1271 *wl, |
4444 | struct wl12xx_vif *wlvif, | |
4445 | struct ieee80211_sta *sta) | |
f84f7d78 | 4446 | { |
c7ffb902 | 4447 | struct wl1271_station *wl_sta; |
f84f7d78 AN |
4448 | int ret = 0; |
4449 | u8 hlid; | |
4450 | ||
f84f7d78 AN |
4451 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); |
4452 | ||
c7ffb902 | 4453 | ret = wl1271_allocate_sta(wl, wlvif, sta); |
f84f7d78 | 4454 | if (ret < 0) |
2d6cf2b5 | 4455 | return ret; |
f84f7d78 | 4456 | |
c7ffb902 EP |
4457 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
4458 | hlid = wl_sta->hlid; | |
4459 | ||
1b92f15e | 4460 | ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); |
f84f7d78 | 4461 | if (ret < 0) |
2d6cf2b5 | 4462 | wl1271_free_sta(wl, wlvif, hlid); |
f84f7d78 | 4463 | |
2d6cf2b5 EP |
4464 | return ret; |
4465 | } | |
b67476ef | 4466 | |
2d6cf2b5 EP |
4467 | static int wl12xx_sta_remove(struct wl1271 *wl, |
4468 | struct wl12xx_vif *wlvif, | |
4469 | struct ieee80211_sta *sta) | |
4470 | { | |
4471 | struct wl1271_station *wl_sta; | |
4472 | int ret = 0, id; | |
0b932ab9 | 4473 | |
2d6cf2b5 EP |
4474 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); |
4475 | ||
4476 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
4477 | id = wl_sta->hlid; | |
4478 | if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) | |
4479 | return -EINVAL; | |
f84f7d78 | 4480 | |
2d6cf2b5 | 4481 | ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); |
409622ec | 4482 | if (ret < 0) |
2d6cf2b5 | 4483 | return ret; |
409622ec | 4484 | |
2d6cf2b5 | 4485 | wl1271_free_sta(wl, wlvif, wl_sta->hlid); |
f84f7d78 AN |
4486 | return ret; |
4487 | } | |
4488 | ||
2d6cf2b5 EP |
4489 | static int wl12xx_update_sta_state(struct wl1271 *wl, |
4490 | struct wl12xx_vif *wlvif, | |
4491 | struct ieee80211_sta *sta, | |
4492 | enum ieee80211_sta_state old_state, | |
4493 | enum ieee80211_sta_state new_state) | |
f84f7d78 | 4494 | { |
f84f7d78 | 4495 | struct wl1271_station *wl_sta; |
2d6cf2b5 EP |
4496 | u8 hlid; |
4497 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; | |
4498 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; | |
4499 | int ret; | |
f84f7d78 | 4500 | |
2d6cf2b5 EP |
4501 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
4502 | hlid = wl_sta->hlid; | |
f84f7d78 | 4503 | |
2d6cf2b5 EP |
4504 | /* Add station (AP mode) */ |
4505 | if (is_ap && | |
4506 | old_state == IEEE80211_STA_NOTEXIST && | |
29936266 EP |
4507 | new_state == IEEE80211_STA_NONE) { |
4508 | ret = wl12xx_sta_add(wl, wlvif, sta); | |
4509 | if (ret) | |
4510 | return ret; | |
4511 | } | |
2d6cf2b5 EP |
4512 | |
4513 | /* Remove station (AP mode) */ | |
4514 | if (is_ap && | |
4515 | old_state == IEEE80211_STA_NONE && | |
4516 | new_state == IEEE80211_STA_NOTEXIST) { | |
4517 | /* must not fail */ | |
4518 | wl12xx_sta_remove(wl, wlvif, sta); | |
2d6cf2b5 | 4519 | } |
f84f7d78 | 4520 | |
2d6cf2b5 EP |
4521 | /* Authorize station (AP mode) */ |
4522 | if (is_ap && | |
4523 | new_state == IEEE80211_STA_AUTHORIZED) { | |
d50529c0 | 4524 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, hlid); |
2d6cf2b5 EP |
4525 | if (ret < 0) |
4526 | return ret; | |
f84f7d78 | 4527 | |
2d6cf2b5 EP |
4528 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, |
4529 | hlid); | |
29936266 EP |
4530 | if (ret) |
4531 | return ret; | |
2d6cf2b5 | 4532 | } |
f84f7d78 | 4533 | |
9fd6f21b EP |
4534 | /* Authorize station */ |
4535 | if (is_sta && | |
4536 | new_state == IEEE80211_STA_AUTHORIZED) { | |
4537 | set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); | |
29936266 EP |
4538 | ret = wl12xx_set_authorized(wl, wlvif); |
4539 | if (ret) | |
4540 | return ret; | |
9fd6f21b EP |
4541 | } |
4542 | ||
4543 | if (is_sta && | |
4544 | old_state == IEEE80211_STA_AUTHORIZED && | |
4545 | new_state == IEEE80211_STA_ASSOC) { | |
4546 | clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); | |
3230f35e | 4547 | clear_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags); |
9fd6f21b EP |
4548 | } |
4549 | ||
29936266 EP |
4550 | /* clear ROCs on failure or authorization */ |
4551 | if (is_sta && | |
4552 | (new_state == IEEE80211_STA_AUTHORIZED || | |
4553 | new_state == IEEE80211_STA_NOTEXIST)) { | |
4554 | if (test_bit(wlvif->role_id, wl->roc_map)) | |
4555 | wl12xx_croc(wl, wlvif->role_id); | |
4556 | } | |
4557 | ||
4558 | if (is_sta && | |
4559 | old_state == IEEE80211_STA_NOTEXIST && | |
4560 | new_state == IEEE80211_STA_NONE) { | |
4561 | if (find_first_bit(wl->roc_map, | |
4562 | WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) { | |
4563 | WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID); | |
4564 | wl12xx_roc(wl, wlvif, wlvif->role_id, | |
4565 | wlvif->band, wlvif->channel); | |
4566 | } | |
4567 | } | |
2d6cf2b5 EP |
4568 | return 0; |
4569 | } | |
4570 | ||
4571 | static int wl12xx_op_sta_state(struct ieee80211_hw *hw, | |
4572 | struct ieee80211_vif *vif, | |
4573 | struct ieee80211_sta *sta, | |
4574 | enum ieee80211_sta_state old_state, | |
4575 | enum ieee80211_sta_state new_state) | |
4576 | { | |
4577 | struct wl1271 *wl = hw->priv; | |
4578 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4579 | int ret; | |
4580 | ||
4581 | wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d", | |
4582 | sta->aid, old_state, new_state); | |
4583 | ||
4584 | mutex_lock(&wl->mutex); | |
4585 | ||
4cc53383 | 4586 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
2d6cf2b5 | 4587 | ret = -EBUSY; |
f84f7d78 | 4588 | goto out; |
2d6cf2b5 | 4589 | } |
f84f7d78 | 4590 | |
a620865e | 4591 | ret = wl1271_ps_elp_wakeup(wl); |
f84f7d78 AN |
4592 | if (ret < 0) |
4593 | goto out; | |
4594 | ||
2d6cf2b5 | 4595 | ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state); |
f84f7d78 | 4596 | |
f84f7d78 | 4597 | wl1271_ps_elp_sleep(wl); |
f84f7d78 AN |
4598 | out: |
4599 | mutex_unlock(&wl->mutex); | |
2d6cf2b5 EP |
4600 | if (new_state < old_state) |
4601 | return 0; | |
f84f7d78 AN |
4602 | return ret; |
4603 | } | |
4604 | ||
4623ec7d LC |
4605 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, |
4606 | struct ieee80211_vif *vif, | |
4607 | enum ieee80211_ampdu_mlme_action action, | |
4608 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | |
4609 | u8 buf_size) | |
bbba3e68 LS |
4610 | { |
4611 | struct wl1271 *wl = hw->priv; | |
536129c8 | 4612 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
bbba3e68 | 4613 | int ret; |
0f9c8250 AN |
4614 | u8 hlid, *ba_bitmap; |
4615 | ||
4616 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, | |
4617 | tid); | |
4618 | ||
4619 | /* sanity check - the fields in FW are only 8bits wide */ | |
4620 | if (WARN_ON(tid > 0xFF)) | |
4621 | return -ENOTSUPP; | |
bbba3e68 LS |
4622 | |
4623 | mutex_lock(&wl->mutex); | |
4624 | ||
4cc53383 | 4625 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
bbba3e68 LS |
4626 | ret = -EAGAIN; |
4627 | goto out; | |
4628 | } | |
4629 | ||
536129c8 | 4630 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) { |
154da67c | 4631 | hlid = wlvif->sta.hlid; |
d0802abd | 4632 | ba_bitmap = &wlvif->sta.ba_rx_bitmap; |
536129c8 | 4633 | } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { |
0f9c8250 AN |
4634 | struct wl1271_station *wl_sta; |
4635 | ||
4636 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
4637 | hlid = wl_sta->hlid; | |
4638 | ba_bitmap = &wl->links[hlid].ba_bitmap; | |
4639 | } else { | |
4640 | ret = -EINVAL; | |
4641 | goto out; | |
4642 | } | |
4643 | ||
a620865e | 4644 | ret = wl1271_ps_elp_wakeup(wl); |
bbba3e68 LS |
4645 | if (ret < 0) |
4646 | goto out; | |
4647 | ||
70559a06 SL |
4648 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", |
4649 | tid, action); | |
4650 | ||
bbba3e68 LS |
4651 | switch (action) { |
4652 | case IEEE80211_AMPDU_RX_START: | |
d0802abd | 4653 | if (!wlvif->ba_support || !wlvif->ba_allowed) { |
bbba3e68 | 4654 | ret = -ENOTSUPP; |
0f9c8250 AN |
4655 | break; |
4656 | } | |
4657 | ||
4658 | if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) { | |
4659 | ret = -EBUSY; | |
4660 | wl1271_error("exceeded max RX BA sessions"); | |
4661 | break; | |
4662 | } | |
4663 | ||
4664 | if (*ba_bitmap & BIT(tid)) { | |
4665 | ret = -EINVAL; | |
4666 | wl1271_error("cannot enable RX BA session on active " | |
4667 | "tid: %d", tid); | |
4668 | break; | |
4669 | } | |
4670 | ||
4671 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, | |
4672 | hlid); | |
4673 | if (!ret) { | |
4674 | *ba_bitmap |= BIT(tid); | |
4675 | wl->ba_rx_session_count++; | |
bbba3e68 LS |
4676 | } |
4677 | break; | |
4678 | ||
4679 | case IEEE80211_AMPDU_RX_STOP: | |
0f9c8250 | 4680 | if (!(*ba_bitmap & BIT(tid))) { |
c954910b AN |
4681 | /* |
4682 | * this happens on reconfig - so only output a debug | |
4683 | * message for now, and don't fail the function. | |
4684 | */ | |
4685 | wl1271_debug(DEBUG_MAC80211, | |
4686 | "no active RX BA session on tid: %d", | |
0f9c8250 | 4687 | tid); |
c954910b | 4688 | ret = 0; |
0f9c8250 AN |
4689 | break; |
4690 | } | |
4691 | ||
4692 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, | |
4693 | hlid); | |
4694 | if (!ret) { | |
4695 | *ba_bitmap &= ~BIT(tid); | |
4696 | wl->ba_rx_session_count--; | |
4697 | } | |
bbba3e68 LS |
4698 | break; |
4699 | ||
4700 | /* | |
4701 | * The BA initiator session management in FW independently. | |
4702 | * Falling break here on purpose for all TX APDU commands. | |
4703 | */ | |
4704 | case IEEE80211_AMPDU_TX_START: | |
4705 | case IEEE80211_AMPDU_TX_STOP: | |
4706 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
4707 | ret = -EINVAL; | |
4708 | break; | |
4709 | ||
4710 | default: | |
4711 | wl1271_error("Incorrect ampdu action id=%x\n", action); | |
4712 | ret = -EINVAL; | |
4713 | } | |
4714 | ||
4715 | wl1271_ps_elp_sleep(wl); | |
4716 | ||
4717 | out: | |
4718 | mutex_unlock(&wl->mutex); | |
4719 | ||
4720 | return ret; | |
4721 | } | |
4722 | ||
af7fbb28 EP |
4723 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, |
4724 | struct ieee80211_vif *vif, | |
4725 | const struct cfg80211_bitrate_mask *mask) | |
4726 | { | |
83587505 | 4727 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
af7fbb28 | 4728 | struct wl1271 *wl = hw->priv; |
d6fa37c9 | 4729 | int i, ret = 0; |
af7fbb28 EP |
4730 | |
4731 | wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", | |
4732 | mask->control[NL80211_BAND_2GHZ].legacy, | |
4733 | mask->control[NL80211_BAND_5GHZ].legacy); | |
4734 | ||
4735 | mutex_lock(&wl->mutex); | |
4736 | ||
091185d6 | 4737 | for (i = 0; i < WLCORE_NUM_BANDS; i++) |
83587505 | 4738 | wlvif->bitrate_masks[i] = |
af7fbb28 EP |
4739 | wl1271_tx_enabled_rates_get(wl, |
4740 | mask->control[i].legacy, | |
4741 | i); | |
d6fa37c9 | 4742 | |
4cc53383 | 4743 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
d6fa37c9 EP |
4744 | goto out; |
4745 | ||
4746 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && | |
4747 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { | |
4748 | ||
4749 | ret = wl1271_ps_elp_wakeup(wl); | |
4750 | if (ret < 0) | |
4751 | goto out; | |
4752 | ||
4753 | wl1271_set_band_rate(wl, wlvif); | |
4754 | wlvif->basic_rate = | |
4755 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); | |
4756 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); | |
4757 | ||
4758 | wl1271_ps_elp_sleep(wl); | |
4759 | } | |
4760 | out: | |
af7fbb28 EP |
4761 | mutex_unlock(&wl->mutex); |
4762 | ||
d6fa37c9 | 4763 | return ret; |
af7fbb28 EP |
4764 | } |
4765 | ||
6d158ff3 SL |
4766 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, |
4767 | struct ieee80211_channel_switch *ch_switch) | |
4768 | { | |
4769 | struct wl1271 *wl = hw->priv; | |
52630c5d | 4770 | struct wl12xx_vif *wlvif; |
6d158ff3 SL |
4771 | int ret; |
4772 | ||
4773 | wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); | |
4774 | ||
b9239b66 AN |
4775 | wl1271_tx_flush(wl); |
4776 | ||
6d158ff3 SL |
4777 | mutex_lock(&wl->mutex); |
4778 | ||
4cc53383 | 4779 | if (unlikely(wl->state == WLCORE_STATE_OFF)) { |
6e8cd331 EP |
4780 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
4781 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); | |
4782 | ieee80211_chswitch_done(vif, false); | |
4783 | } | |
4784 | goto out; | |
4cc53383 IY |
4785 | } else if (unlikely(wl->state != WLCORE_STATE_ON)) { |
4786 | goto out; | |
6d158ff3 SL |
4787 | } |
4788 | ||
4789 | ret = wl1271_ps_elp_wakeup(wl); | |
4790 | if (ret < 0) | |
4791 | goto out; | |
4792 | ||
52630c5d EP |
4793 | /* TODO: change mac80211 to pass vif as param */ |
4794 | wl12xx_for_each_wlvif_sta(wl, wlvif) { | |
c50a2825 EP |
4795 | unsigned long delay_usec; |
4796 | ||
fcab1890 | 4797 | ret = wl->ops->channel_switch(wl, wlvif, ch_switch); |
c50a2825 EP |
4798 | if (ret) |
4799 | goto out_sleep; | |
4800 | ||
4801 | set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); | |
4802 | ||
4803 | /* indicate failure 5 seconds after channel switch time */ | |
4804 | delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) * | |
4805 | ch_switch->count; | |
4806 | ieee80211_queue_delayed_work(hw, &wlvif->channel_switch_work, | |
4807 | usecs_to_jiffies(delay_usec) + | |
4808 | msecs_to_jiffies(5000)); | |
52630c5d | 4809 | } |
6d158ff3 | 4810 | |
c50a2825 | 4811 | out_sleep: |
6d158ff3 SL |
4812 | wl1271_ps_elp_sleep(wl); |
4813 | ||
4814 | out: | |
4815 | mutex_unlock(&wl->mutex); | |
4816 | } | |
4817 | ||
d8ae5a25 EP |
4818 | static void wlcore_op_flush(struct ieee80211_hw *hw, bool drop) |
4819 | { | |
4820 | struct wl1271 *wl = hw->priv; | |
4821 | ||
4822 | wl1271_tx_flush(wl); | |
4823 | } | |
4824 | ||
dabf37db EP |
4825 | static int wlcore_op_remain_on_channel(struct ieee80211_hw *hw, |
4826 | struct ieee80211_vif *vif, | |
4827 | struct ieee80211_channel *chan, | |
4828 | enum nl80211_channel_type channel_type, | |
4829 | int duration) | |
4830 | { | |
4831 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4832 | struct wl1271 *wl = hw->priv; | |
4833 | int channel, ret = 0; | |
4834 | ||
4835 | channel = ieee80211_frequency_to_channel(chan->center_freq); | |
4836 | ||
4837 | wl1271_debug(DEBUG_MAC80211, "mac80211 roc %d (%d)", | |
4838 | channel, wlvif->role_id); | |
4839 | ||
4840 | mutex_lock(&wl->mutex); | |
4841 | ||
4842 | if (unlikely(wl->state != WLCORE_STATE_ON)) | |
4843 | goto out; | |
4844 | ||
4845 | /* return EBUSY if we can't ROC right now */ | |
4846 | if (WARN_ON(wl->roc_vif || | |
4847 | find_first_bit(wl->roc_map, | |
4848 | WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES)) { | |
4849 | ret = -EBUSY; | |
4850 | goto out; | |
4851 | } | |
4852 | ||
4853 | ret = wl1271_ps_elp_wakeup(wl); | |
4854 | if (ret < 0) | |
4855 | goto out; | |
4856 | ||
4857 | ret = wl12xx_start_dev(wl, wlvif, chan->band, channel); | |
4858 | if (ret < 0) | |
4859 | goto out_sleep; | |
4860 | ||
4861 | wl->roc_vif = vif; | |
4862 | ieee80211_queue_delayed_work(hw, &wl->roc_complete_work, | |
4863 | msecs_to_jiffies(duration)); | |
4864 | out_sleep: | |
4865 | wl1271_ps_elp_sleep(wl); | |
4866 | out: | |
4867 | mutex_unlock(&wl->mutex); | |
4868 | return ret; | |
4869 | } | |
4870 | ||
4871 | static int __wlcore_roc_completed(struct wl1271 *wl) | |
4872 | { | |
4873 | struct wl12xx_vif *wlvif; | |
4874 | int ret; | |
4875 | ||
4876 | /* already completed */ | |
4877 | if (unlikely(!wl->roc_vif)) | |
4878 | return 0; | |
4879 | ||
4880 | wlvif = wl12xx_vif_to_data(wl->roc_vif); | |
4881 | ||
4882 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) | |
4883 | return -EBUSY; | |
4884 | ||
4885 | ret = wl12xx_stop_dev(wl, wlvif); | |
4886 | if (ret < 0) | |
4887 | return ret; | |
4888 | ||
4889 | wl->roc_vif = NULL; | |
4890 | ||
4891 | return 0; | |
4892 | } | |
4893 | ||
4894 | static int wlcore_roc_completed(struct wl1271 *wl) | |
4895 | { | |
4896 | int ret; | |
4897 | ||
4898 | wl1271_debug(DEBUG_MAC80211, "roc complete"); | |
4899 | ||
4900 | mutex_lock(&wl->mutex); | |
4901 | ||
4902 | if (unlikely(wl->state != WLCORE_STATE_ON)) { | |
4903 | ret = -EBUSY; | |
4904 | goto out; | |
4905 | } | |
4906 | ||
4907 | ret = wl1271_ps_elp_wakeup(wl); | |
4908 | if (ret < 0) | |
4909 | goto out; | |
4910 | ||
4911 | ret = __wlcore_roc_completed(wl); | |
4912 | ||
4913 | wl1271_ps_elp_sleep(wl); | |
4914 | out: | |
4915 | mutex_unlock(&wl->mutex); | |
4916 | ||
4917 | return ret; | |
4918 | } | |
4919 | ||
4920 | static void wlcore_roc_complete_work(struct work_struct *work) | |
4921 | { | |
4922 | struct delayed_work *dwork; | |
4923 | struct wl1271 *wl; | |
4924 | int ret; | |
4925 | ||
4926 | dwork = container_of(work, struct delayed_work, work); | |
4927 | wl = container_of(dwork, struct wl1271, roc_complete_work); | |
4928 | ||
4929 | ret = wlcore_roc_completed(wl); | |
4930 | if (!ret) | |
4931 | ieee80211_remain_on_channel_expired(wl->hw); | |
4932 | } | |
4933 | ||
4934 | static int wlcore_op_cancel_remain_on_channel(struct ieee80211_hw *hw) | |
4935 | { | |
4936 | struct wl1271 *wl = hw->priv; | |
4937 | ||
4938 | wl1271_debug(DEBUG_MAC80211, "mac80211 croc"); | |
4939 | ||
4940 | /* TODO: per-vif */ | |
4941 | wl1271_tx_flush(wl); | |
4942 | ||
4943 | /* | |
4944 | * we can't just flush_work here, because it might deadlock | |
4945 | * (as we might get called from the same workqueue) | |
4946 | */ | |
4947 | cancel_delayed_work_sync(&wl->roc_complete_work); | |
4948 | wlcore_roc_completed(wl); | |
4949 | ||
4950 | return 0; | |
4951 | } | |
4952 | ||
5f9b6777 AN |
4953 | static void wlcore_op_sta_rc_update(struct ieee80211_hw *hw, |
4954 | struct ieee80211_vif *vif, | |
4955 | struct ieee80211_sta *sta, | |
4956 | u32 changed) | |
4957 | { | |
4958 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); | |
4959 | struct wl1271 *wl = hw->priv; | |
4960 | ||
4961 | wlcore_hw_sta_rc_update(wl, wlvif, sta, changed); | |
4962 | } | |
4963 | ||
33437893 AN |
4964 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) |
4965 | { | |
4966 | struct wl1271 *wl = hw->priv; | |
4967 | bool ret = false; | |
4968 | ||
4969 | mutex_lock(&wl->mutex); | |
4970 | ||
4cc53383 | 4971 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
33437893 AN |
4972 | goto out; |
4973 | ||
4974 | /* packets are considered pending if in the TX queue or the FW */ | |
f1a46384 | 4975 | ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); |
33437893 AN |
4976 | out: |
4977 | mutex_unlock(&wl->mutex); | |
4978 | ||
4979 | return ret; | |
4980 | } | |
4981 | ||
f5fc0f86 LC |
4982 | /* can't be const, mac80211 writes to this */ |
4983 | static struct ieee80211_rate wl1271_rates[] = { | |
4984 | { .bitrate = 10, | |
2b60100b JO |
4985 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
4986 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, | |
f5fc0f86 | 4987 | { .bitrate = 20, |
2b60100b JO |
4988 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
4989 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, | |
f5fc0f86 LC |
4990 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
4991 | { .bitrate = 55, | |
2b60100b JO |
4992 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
4993 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, | |
f5fc0f86 LC |
4994 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
4995 | { .bitrate = 110, | |
2b60100b JO |
4996 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
4997 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, | |
f5fc0f86 LC |
4998 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
4999 | { .bitrate = 60, | |
2b60100b JO |
5000 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
5001 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | |
f5fc0f86 | 5002 | { .bitrate = 90, |
2b60100b JO |
5003 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
5004 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | |
f5fc0f86 | 5005 | { .bitrate = 120, |
2b60100b JO |
5006 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
5007 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | |
f5fc0f86 | 5008 | { .bitrate = 180, |
2b60100b JO |
5009 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
5010 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | |
f5fc0f86 | 5011 | { .bitrate = 240, |
2b60100b JO |
5012 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
5013 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | |
f5fc0f86 | 5014 | { .bitrate = 360, |
2b60100b JO |
5015 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
5016 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | |
f5fc0f86 | 5017 | { .bitrate = 480, |
2b60100b JO |
5018 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
5019 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | |
f5fc0f86 | 5020 | { .bitrate = 540, |
2b60100b JO |
5021 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
5022 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | |
f5fc0f86 LC |
5023 | }; |
5024 | ||
fa97f46b | 5025 | /* can't be const, mac80211 writes to this */ |
f5fc0f86 | 5026 | static struct ieee80211_channel wl1271_channels[] = { |
a2d0e3f1 | 5027 | { .hw_value = 1, .center_freq = 2412, .max_power = 25 }, |
fa21c7a9 | 5028 | { .hw_value = 2, .center_freq = 2417, .max_power = 25 }, |
fa97f46b JO |
5029 | { .hw_value = 3, .center_freq = 2422, .max_power = 25 }, |
5030 | { .hw_value = 4, .center_freq = 2427, .max_power = 25 }, | |
5031 | { .hw_value = 5, .center_freq = 2432, .max_power = 25 }, | |
fa21c7a9 | 5032 | { .hw_value = 6, .center_freq = 2437, .max_power = 25 }, |
fa97f46b JO |
5033 | { .hw_value = 7, .center_freq = 2442, .max_power = 25 }, |
5034 | { .hw_value = 8, .center_freq = 2447, .max_power = 25 }, | |
5035 | { .hw_value = 9, .center_freq = 2452, .max_power = 25 }, | |
fa21c7a9 | 5036 | { .hw_value = 10, .center_freq = 2457, .max_power = 25 }, |
fa97f46b JO |
5037 | { .hw_value = 11, .center_freq = 2462, .max_power = 25 }, |
5038 | { .hw_value = 12, .center_freq = 2467, .max_power = 25 }, | |
5039 | { .hw_value = 13, .center_freq = 2472, .max_power = 25 }, | |
6c89b7b2 | 5040 | { .hw_value = 14, .center_freq = 2484, .max_power = 25 }, |
f5fc0f86 LC |
5041 | }; |
5042 | ||
5043 | /* can't be const, mac80211 writes to this */ | |
5044 | static struct ieee80211_supported_band wl1271_band_2ghz = { | |
5045 | .channels = wl1271_channels, | |
5046 | .n_channels = ARRAY_SIZE(wl1271_channels), | |
5047 | .bitrates = wl1271_rates, | |
5048 | .n_bitrates = ARRAY_SIZE(wl1271_rates), | |
5049 | }; | |
5050 | ||
1ebec3d7 TP |
5051 | /* 5 GHz data rates for WL1273 */ |
5052 | static struct ieee80211_rate wl1271_rates_5ghz[] = { | |
5053 | { .bitrate = 60, | |
5054 | .hw_value = CONF_HW_BIT_RATE_6MBPS, | |
5055 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | |
5056 | { .bitrate = 90, | |
5057 | .hw_value = CONF_HW_BIT_RATE_9MBPS, | |
5058 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | |
5059 | { .bitrate = 120, | |
5060 | .hw_value = CONF_HW_BIT_RATE_12MBPS, | |
5061 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | |
5062 | { .bitrate = 180, | |
5063 | .hw_value = CONF_HW_BIT_RATE_18MBPS, | |
5064 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | |
5065 | { .bitrate = 240, | |
5066 | .hw_value = CONF_HW_BIT_RATE_24MBPS, | |
5067 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | |
5068 | { .bitrate = 360, | |
5069 | .hw_value = CONF_HW_BIT_RATE_36MBPS, | |
5070 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | |
5071 | { .bitrate = 480, | |
5072 | .hw_value = CONF_HW_BIT_RATE_48MBPS, | |
5073 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | |
5074 | { .bitrate = 540, | |
5075 | .hw_value = CONF_HW_BIT_RATE_54MBPS, | |
5076 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | |
5077 | }; | |
5078 | ||
fa97f46b | 5079 | /* 5 GHz band channels for WL1273 */ |
1ebec3d7 | 5080 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
6cfa5cff AN |
5081 | { .hw_value = 7, .center_freq = 5035, .max_power = 25 }, |
5082 | { .hw_value = 8, .center_freq = 5040, .max_power = 25 }, | |
5083 | { .hw_value = 9, .center_freq = 5045, .max_power = 25 }, | |
5084 | { .hw_value = 11, .center_freq = 5055, .max_power = 25 }, | |
5085 | { .hw_value = 12, .center_freq = 5060, .max_power = 25 }, | |
5086 | { .hw_value = 16, .center_freq = 5080, .max_power = 25 }, | |
5087 | { .hw_value = 34, .center_freq = 5170, .max_power = 25 }, | |
5088 | { .hw_value = 36, .center_freq = 5180, .max_power = 25 }, | |
5089 | { .hw_value = 38, .center_freq = 5190, .max_power = 25 }, | |
5090 | { .hw_value = 40, .center_freq = 5200, .max_power = 25 }, | |
5091 | { .hw_value = 42, .center_freq = 5210, .max_power = 25 }, | |
5092 | { .hw_value = 44, .center_freq = 5220, .max_power = 25 }, | |
5093 | { .hw_value = 46, .center_freq = 5230, .max_power = 25 }, | |
5094 | { .hw_value = 48, .center_freq = 5240, .max_power = 25 }, | |
5095 | { .hw_value = 52, .center_freq = 5260, .max_power = 25 }, | |
5096 | { .hw_value = 56, .center_freq = 5280, .max_power = 25 }, | |
5097 | { .hw_value = 60, .center_freq = 5300, .max_power = 25 }, | |
5098 | { .hw_value = 64, .center_freq = 5320, .max_power = 25 }, | |
5099 | { .hw_value = 100, .center_freq = 5500, .max_power = 25 }, | |
5100 | { .hw_value = 104, .center_freq = 5520, .max_power = 25 }, | |
5101 | { .hw_value = 108, .center_freq = 5540, .max_power = 25 }, | |
5102 | { .hw_value = 112, .center_freq = 5560, .max_power = 25 }, | |
5103 | { .hw_value = 116, .center_freq = 5580, .max_power = 25 }, | |
5104 | { .hw_value = 120, .center_freq = 5600, .max_power = 25 }, | |
5105 | { .hw_value = 124, .center_freq = 5620, .max_power = 25 }, | |
5106 | { .hw_value = 128, .center_freq = 5640, .max_power = 25 }, | |
5107 | { .hw_value = 132, .center_freq = 5660, .max_power = 25 }, | |
5108 | { .hw_value = 136, .center_freq = 5680, .max_power = 25 }, | |
5109 | { .hw_value = 140, .center_freq = 5700, .max_power = 25 }, | |
5110 | { .hw_value = 149, .center_freq = 5745, .max_power = 25 }, | |
5111 | { .hw_value = 153, .center_freq = 5765, .max_power = 25 }, | |
5112 | { .hw_value = 157, .center_freq = 5785, .max_power = 25 }, | |
5113 | { .hw_value = 161, .center_freq = 5805, .max_power = 25 }, | |
5114 | { .hw_value = 165, .center_freq = 5825, .max_power = 25 }, | |
1ebec3d7 TP |
5115 | }; |
5116 | ||
1ebec3d7 TP |
5117 | static struct ieee80211_supported_band wl1271_band_5ghz = { |
5118 | .channels = wl1271_channels_5ghz, | |
5119 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), | |
5120 | .bitrates = wl1271_rates_5ghz, | |
5121 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), | |
f876bb9a JO |
5122 | }; |
5123 | ||
f5fc0f86 LC |
5124 | static const struct ieee80211_ops wl1271_ops = { |
5125 | .start = wl1271_op_start, | |
c24ec83b | 5126 | .stop = wlcore_op_stop, |
f5fc0f86 LC |
5127 | .add_interface = wl1271_op_add_interface, |
5128 | .remove_interface = wl1271_op_remove_interface, | |
c0fad1b7 | 5129 | .change_interface = wl12xx_op_change_interface, |
f634a4e7 | 5130 | #ifdef CONFIG_PM |
402e4861 EP |
5131 | .suspend = wl1271_op_suspend, |
5132 | .resume = wl1271_op_resume, | |
f634a4e7 | 5133 | #endif |
f5fc0f86 | 5134 | .config = wl1271_op_config, |
c87dec9f | 5135 | .prepare_multicast = wl1271_op_prepare_multicast, |
f5fc0f86 LC |
5136 | .configure_filter = wl1271_op_configure_filter, |
5137 | .tx = wl1271_op_tx, | |
a1c597f2 | 5138 | .set_key = wlcore_op_set_key, |
f5fc0f86 | 5139 | .hw_scan = wl1271_op_hw_scan, |
73ecce31 | 5140 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, |
33c2c06c LC |
5141 | .sched_scan_start = wl1271_op_sched_scan_start, |
5142 | .sched_scan_stop = wl1271_op_sched_scan_stop, | |
f5fc0f86 | 5143 | .bss_info_changed = wl1271_op_bss_info_changed, |
68d069c4 | 5144 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
f5fc0f86 | 5145 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
c6999d83 | 5146 | .conf_tx = wl1271_op_conf_tx, |
bbbb538e | 5147 | .get_tsf = wl1271_op_get_tsf, |
ece550d0 | 5148 | .get_survey = wl1271_op_get_survey, |
2d6cf2b5 | 5149 | .sta_state = wl12xx_op_sta_state, |
bbba3e68 | 5150 | .ampdu_action = wl1271_op_ampdu_action, |
33437893 | 5151 | .tx_frames_pending = wl1271_tx_frames_pending, |
af7fbb28 | 5152 | .set_bitrate_mask = wl12xx_set_bitrate_mask, |
6d158ff3 | 5153 | .channel_switch = wl12xx_op_channel_switch, |
d8ae5a25 | 5154 | .flush = wlcore_op_flush, |
dabf37db EP |
5155 | .remain_on_channel = wlcore_op_remain_on_channel, |
5156 | .cancel_remain_on_channel = wlcore_op_cancel_remain_on_channel, | |
b6970ee5 EP |
5157 | .add_chanctx = wlcore_op_add_chanctx, |
5158 | .remove_chanctx = wlcore_op_remove_chanctx, | |
5159 | .change_chanctx = wlcore_op_change_chanctx, | |
5160 | .assign_vif_chanctx = wlcore_op_assign_vif_chanctx, | |
5161 | .unassign_vif_chanctx = wlcore_op_unassign_vif_chanctx, | |
5f9b6777 | 5162 | .sta_rc_update = wlcore_op_sta_rc_update, |
c8c90873 | 5163 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
f5fc0f86 LC |
5164 | }; |
5165 | ||
f876bb9a | 5166 | |
43a8bc5a | 5167 | u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band) |
f876bb9a JO |
5168 | { |
5169 | u8 idx; | |
5170 | ||
43a8bc5a | 5171 | BUG_ON(band >= 2); |
f876bb9a | 5172 | |
43a8bc5a | 5173 | if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) { |
f876bb9a JO |
5174 | wl1271_error("Illegal RX rate from HW: %d", rate); |
5175 | return 0; | |
5176 | } | |
5177 | ||
43a8bc5a | 5178 | idx = wl->band_rate_to_idx[band][rate]; |
f876bb9a JO |
5179 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
5180 | wl1271_error("Unsupported RX rate from HW: %d", rate); | |
5181 | return 0; | |
5182 | } | |
5183 | ||
5184 | return idx; | |
5185 | } | |
5186 | ||
7fc3a864 JO |
5187 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, |
5188 | struct device_attribute *attr, | |
5189 | char *buf) | |
5190 | { | |
5191 | struct wl1271 *wl = dev_get_drvdata(dev); | |
5192 | ssize_t len; | |
5193 | ||
2f63b011 | 5194 | len = PAGE_SIZE; |
7fc3a864 JO |
5195 | |
5196 | mutex_lock(&wl->mutex); | |
5197 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", | |
5198 | wl->sg_enabled); | |
5199 | mutex_unlock(&wl->mutex); | |
5200 | ||
5201 | return len; | |
5202 | ||
5203 | } | |
5204 | ||
5205 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, | |
5206 | struct device_attribute *attr, | |
5207 | const char *buf, size_t count) | |
5208 | { | |
5209 | struct wl1271 *wl = dev_get_drvdata(dev); | |
5210 | unsigned long res; | |
5211 | int ret; | |
5212 | ||
6277ed65 | 5213 | ret = kstrtoul(buf, 10, &res); |
7fc3a864 JO |
5214 | if (ret < 0) { |
5215 | wl1271_warning("incorrect value written to bt_coex_mode"); | |
5216 | return count; | |
5217 | } | |
5218 | ||
5219 | mutex_lock(&wl->mutex); | |
5220 | ||
5221 | res = !!res; | |
5222 | ||
5223 | if (res == wl->sg_enabled) | |
5224 | goto out; | |
5225 | ||
5226 | wl->sg_enabled = res; | |
5227 | ||
4cc53383 | 5228 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
7fc3a864 JO |
5229 | goto out; |
5230 | ||
a620865e | 5231 | ret = wl1271_ps_elp_wakeup(wl); |
7fc3a864 JO |
5232 | if (ret < 0) |
5233 | goto out; | |
5234 | ||
5235 | wl1271_acx_sg_enable(wl, wl->sg_enabled); | |
5236 | wl1271_ps_elp_sleep(wl); | |
5237 | ||
5238 | out: | |
5239 | mutex_unlock(&wl->mutex); | |
5240 | return count; | |
5241 | } | |
5242 | ||
5243 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, | |
5244 | wl1271_sysfs_show_bt_coex_state, | |
5245 | wl1271_sysfs_store_bt_coex_state); | |
5246 | ||
d717fd61 JO |
5247 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, |
5248 | struct device_attribute *attr, | |
5249 | char *buf) | |
5250 | { | |
5251 | struct wl1271 *wl = dev_get_drvdata(dev); | |
5252 | ssize_t len; | |
5253 | ||
2f63b011 | 5254 | len = PAGE_SIZE; |
d717fd61 JO |
5255 | |
5256 | mutex_lock(&wl->mutex); | |
5257 | if (wl->hw_pg_ver >= 0) | |
5258 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); | |
5259 | else | |
5260 | len = snprintf(buf, len, "n/a\n"); | |
5261 | mutex_unlock(&wl->mutex); | |
5262 | ||
5263 | return len; | |
5264 | } | |
5265 | ||
6f07b72a | 5266 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO, |
d717fd61 JO |
5267 | wl1271_sysfs_show_hw_pg_ver, NULL); |
5268 | ||
95dac04f IY |
5269 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, |
5270 | struct bin_attribute *bin_attr, | |
5271 | char *buffer, loff_t pos, size_t count) | |
5272 | { | |
5273 | struct device *dev = container_of(kobj, struct device, kobj); | |
5274 | struct wl1271 *wl = dev_get_drvdata(dev); | |
5275 | ssize_t len; | |
5276 | int ret; | |
5277 | ||
5278 | ret = mutex_lock_interruptible(&wl->mutex); | |
5279 | if (ret < 0) | |
5280 | return -ERESTARTSYS; | |
5281 | ||
5282 | /* Let only one thread read the log at a time, blocking others */ | |
5283 | while (wl->fwlog_size == 0) { | |
5284 | DEFINE_WAIT(wait); | |
5285 | ||
5286 | prepare_to_wait_exclusive(&wl->fwlog_waitq, | |
5287 | &wait, | |
5288 | TASK_INTERRUPTIBLE); | |
5289 | ||
5290 | if (wl->fwlog_size != 0) { | |
5291 | finish_wait(&wl->fwlog_waitq, &wait); | |
5292 | break; | |
5293 | } | |
5294 | ||
5295 | mutex_unlock(&wl->mutex); | |
5296 | ||
5297 | schedule(); | |
5298 | finish_wait(&wl->fwlog_waitq, &wait); | |
5299 | ||
5300 | if (signal_pending(current)) | |
5301 | return -ERESTARTSYS; | |
5302 | ||
5303 | ret = mutex_lock_interruptible(&wl->mutex); | |
5304 | if (ret < 0) | |
5305 | return -ERESTARTSYS; | |
5306 | } | |
5307 | ||
5308 | /* Check if the fwlog is still valid */ | |
5309 | if (wl->fwlog_size < 0) { | |
5310 | mutex_unlock(&wl->mutex); | |
5311 | return 0; | |
5312 | } | |
5313 | ||
5314 | /* Seeking is not supported - old logs are not kept. Disregard pos. */ | |
5315 | len = min(count, (size_t)wl->fwlog_size); | |
5316 | wl->fwlog_size -= len; | |
5317 | memcpy(buffer, wl->fwlog, len); | |
5318 | ||
5319 | /* Make room for new messages */ | |
5320 | memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); | |
5321 | ||
5322 | mutex_unlock(&wl->mutex); | |
5323 | ||
5324 | return len; | |
5325 | } | |
5326 | ||
5327 | static struct bin_attribute fwlog_attr = { | |
5328 | .attr = {.name = "fwlog", .mode = S_IRUSR}, | |
5329 | .read = wl1271_sysfs_read_fwlog, | |
5330 | }; | |
5331 | ||
f4afbed9 | 5332 | static void wl12xx_derive_mac_addresses(struct wl1271 *wl, u32 oui, u32 nic) |
5e037e74 LC |
5333 | { |
5334 | int i; | |
5335 | ||
f4afbed9 AN |
5336 | wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x", |
5337 | oui, nic); | |
5e037e74 | 5338 | |
f4afbed9 | 5339 | if (nic + WLCORE_NUM_MAC_ADDRESSES - wl->num_mac_addr > 0xffffff) |
5e037e74 LC |
5340 | wl1271_warning("NIC part of the MAC address wraps around!"); |
5341 | ||
f4afbed9 | 5342 | for (i = 0; i < wl->num_mac_addr; i++) { |
5e037e74 LC |
5343 | wl->addresses[i].addr[0] = (u8)(oui >> 16); |
5344 | wl->addresses[i].addr[1] = (u8)(oui >> 8); | |
5345 | wl->addresses[i].addr[2] = (u8) oui; | |
5346 | wl->addresses[i].addr[3] = (u8)(nic >> 16); | |
5347 | wl->addresses[i].addr[4] = (u8)(nic >> 8); | |
5348 | wl->addresses[i].addr[5] = (u8) nic; | |
5349 | nic++; | |
5350 | } | |
5351 | ||
f4afbed9 AN |
5352 | /* we may be one address short at the most */ |
5353 | WARN_ON(wl->num_mac_addr + 1 < WLCORE_NUM_MAC_ADDRESSES); | |
5354 | ||
5355 | /* | |
5356 | * turn on the LAA bit in the first address and use it as | |
5357 | * the last address. | |
5358 | */ | |
5359 | if (wl->num_mac_addr < WLCORE_NUM_MAC_ADDRESSES) { | |
5360 | int idx = WLCORE_NUM_MAC_ADDRESSES - 1; | |
5361 | memcpy(&wl->addresses[idx], &wl->addresses[0], | |
5362 | sizeof(wl->addresses[0])); | |
5363 | /* LAA bit */ | |
5364 | wl->addresses[idx].addr[2] |= BIT(1); | |
5365 | } | |
5366 | ||
5367 | wl->hw->wiphy->n_addresses = WLCORE_NUM_MAC_ADDRESSES; | |
5e037e74 LC |
5368 | wl->hw->wiphy->addresses = wl->addresses; |
5369 | } | |
5370 | ||
30c5dbd1 LC |
5371 | static int wl12xx_get_hw_info(struct wl1271 *wl) |
5372 | { | |
5373 | int ret; | |
30c5dbd1 LC |
5374 | |
5375 | ret = wl12xx_set_power_on(wl); | |
5376 | if (ret < 0) | |
4fb4e0be | 5377 | return ret; |
30c5dbd1 | 5378 | |
6134323f IY |
5379 | ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &wl->chip.id); |
5380 | if (ret < 0) | |
5381 | goto out; | |
30c5dbd1 | 5382 | |
00782136 LC |
5383 | wl->fuse_oui_addr = 0; |
5384 | wl->fuse_nic_addr = 0; | |
30c5dbd1 | 5385 | |
6134323f IY |
5386 | ret = wl->ops->get_pg_ver(wl, &wl->hw_pg_ver); |
5387 | if (ret < 0) | |
5388 | goto out; | |
30c5dbd1 | 5389 | |
30d9b4a5 | 5390 | if (wl->ops->get_mac) |
6134323f | 5391 | ret = wl->ops->get_mac(wl); |
5e037e74 | 5392 | |
30c5dbd1 | 5393 | out: |
6134323f | 5394 | wl1271_power_off(wl); |
30c5dbd1 LC |
5395 | return ret; |
5396 | } | |
5397 | ||
4b32a2c9 | 5398 | static int wl1271_register_hw(struct wl1271 *wl) |
f5fc0f86 LC |
5399 | { |
5400 | int ret; | |
5e037e74 | 5401 | u32 oui_addr = 0, nic_addr = 0; |
f5fc0f86 LC |
5402 | |
5403 | if (wl->mac80211_registered) | |
5404 | return 0; | |
5405 | ||
6f8d6b20 | 5406 | if (wl->nvs_len >= 12) { |
bc765bf3 SL |
5407 | /* NOTE: The wl->nvs->nvs element must be first, in |
5408 | * order to simplify the casting, we assume it is at | |
5409 | * the beginning of the wl->nvs structure. | |
5410 | */ | |
5411 | u8 *nvs_ptr = (u8 *)wl->nvs; | |
31d26ec6 | 5412 | |
5e037e74 LC |
5413 | oui_addr = |
5414 | (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; | |
5415 | nic_addr = | |
5416 | (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; | |
5417 | } | |
5418 | ||
5419 | /* if the MAC address is zeroed in the NVS derive from fuse */ | |
5420 | if (oui_addr == 0 && nic_addr == 0) { | |
5421 | oui_addr = wl->fuse_oui_addr; | |
5422 | /* fuse has the BD_ADDR, the WLAN addresses are the next two */ | |
5423 | nic_addr = wl->fuse_nic_addr + 1; | |
31d26ec6 AN |
5424 | } |
5425 | ||
f4afbed9 | 5426 | wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr); |
f5fc0f86 LC |
5427 | |
5428 | ret = ieee80211_register_hw(wl->hw); | |
5429 | if (ret < 0) { | |
5430 | wl1271_error("unable to register mac80211 hw: %d", ret); | |
30c5dbd1 | 5431 | goto out; |
f5fc0f86 LC |
5432 | } |
5433 | ||
5434 | wl->mac80211_registered = true; | |
5435 | ||
d60080ae EP |
5436 | wl1271_debugfs_init(wl); |
5437 | ||
f5fc0f86 LC |
5438 | wl1271_notice("loaded"); |
5439 | ||
30c5dbd1 LC |
5440 | out: |
5441 | return ret; | |
f5fc0f86 LC |
5442 | } |
5443 | ||
4b32a2c9 | 5444 | static void wl1271_unregister_hw(struct wl1271 *wl) |
3b56dd6a | 5445 | { |
3fcdab70 | 5446 | if (wl->plt) |
f3df1331 | 5447 | wl1271_plt_stop(wl); |
4ae3fa87 | 5448 | |
3b56dd6a TP |
5449 | ieee80211_unregister_hw(wl->hw); |
5450 | wl->mac80211_registered = false; | |
5451 | ||
5452 | } | |
3b56dd6a | 5453 | |
bcab320b EP |
5454 | static const struct ieee80211_iface_limit wlcore_iface_limits[] = { |
5455 | { | |
e7a6ba29 | 5456 | .max = 3, |
bcab320b EP |
5457 | .types = BIT(NL80211_IFTYPE_STATION), |
5458 | }, | |
5459 | { | |
5460 | .max = 1, | |
5461 | .types = BIT(NL80211_IFTYPE_AP) | | |
5462 | BIT(NL80211_IFTYPE_P2P_GO) | | |
5463 | BIT(NL80211_IFTYPE_P2P_CLIENT), | |
5464 | }, | |
5465 | }; | |
5466 | ||
de40750f | 5467 | static struct ieee80211_iface_combination |
bcab320b EP |
5468 | wlcore_iface_combinations[] = { |
5469 | { | |
e7a6ba29 | 5470 | .max_interfaces = 3, |
bcab320b EP |
5471 | .limits = wlcore_iface_limits, |
5472 | .n_limits = ARRAY_SIZE(wlcore_iface_limits), | |
5473 | }, | |
5474 | }; | |
5475 | ||
4b32a2c9 | 5476 | static int wl1271_init_ieee80211(struct wl1271 *wl) |
f5fc0f86 | 5477 | { |
7a55724e JO |
5478 | static const u32 cipher_suites[] = { |
5479 | WLAN_CIPHER_SUITE_WEP40, | |
5480 | WLAN_CIPHER_SUITE_WEP104, | |
5481 | WLAN_CIPHER_SUITE_TKIP, | |
5482 | WLAN_CIPHER_SUITE_CCMP, | |
5483 | WL1271_CIPHER_SUITE_GEM, | |
5484 | }; | |
5485 | ||
2c0133a4 AN |
5486 | /* The tx descriptor buffer */ |
5487 | wl->hw->extra_tx_headroom = sizeof(struct wl1271_tx_hw_descr); | |
5488 | ||
5489 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) | |
5490 | wl->hw->extra_tx_headroom += WL1271_EXTRA_SPACE_TKIP; | |
f5fc0f86 LC |
5491 | |
5492 | /* unit us */ | |
5493 | /* FIXME: find a proper value */ | |
5494 | wl->hw->channel_change_time = 10000; | |
50c500ad | 5495 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
f5fc0f86 LC |
5496 | |
5497 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | | |
0a34332f | 5498 | IEEE80211_HW_SUPPORTS_PS | |
f1d63a59 | 5499 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
4695dc91 | 5500 | IEEE80211_HW_SUPPORTS_UAPSD | |
a9af092b | 5501 | IEEE80211_HW_HAS_RATE_CONTROL | |
00236aed | 5502 | IEEE80211_HW_CONNECTION_MONITOR | |
25eaea30 | 5503 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
fcd23b63 | 5504 | IEEE80211_HW_SPECTRUM_MGMT | |
93f8c8e0 AN |
5505 | IEEE80211_HW_AP_LINK_PS | |
5506 | IEEE80211_HW_AMPDU_AGGREGATION | | |
79aba1ba EP |
5507 | IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | |
5508 | IEEE80211_HW_SCAN_WHILE_IDLE; | |
f5fc0f86 | 5509 | |
7a55724e JO |
5510 | wl->hw->wiphy->cipher_suites = cipher_suites; |
5511 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
5512 | ||
e0d8bbf0 | 5513 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
045c745f EP |
5514 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | |
5515 | BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); | |
f5fc0f86 | 5516 | wl->hw->wiphy->max_scan_ssids = 1; |
221737d2 LC |
5517 | wl->hw->wiphy->max_sched_scan_ssids = 16; |
5518 | wl->hw->wiphy->max_match_sets = 16; | |
ea559b46 GE |
5519 | /* |
5520 | * Maximum length of elements in scanning probe request templates | |
5521 | * should be the maximum length possible for a template, without | |
5522 | * the IEEE80211 header of the template | |
5523 | */ | |
c08e371a | 5524 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
ea559b46 | 5525 | sizeof(struct ieee80211_header); |
a8aaaf53 | 5526 | |
c08e371a | 5527 | wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
c9e79a47 LC |
5528 | sizeof(struct ieee80211_header); |
5529 | ||
dabf37db EP |
5530 | wl->hw->wiphy->max_remain_on_channel_duration = 5000; |
5531 | ||
81ddbb5c JB |
5532 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD | |
5533 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; | |
1ec23f7f | 5534 | |
4a31c11c LC |
5535 | /* make sure all our channels fit in the scanned_ch bitmask */ |
5536 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + | |
5537 | ARRAY_SIZE(wl1271_channels_5ghz) > | |
5538 | WL1271_MAX_CHANNELS); | |
a8aaaf53 LC |
5539 | /* |
5540 | * We keep local copies of the band structs because we need to | |
5541 | * modify them on a per-device basis. | |
5542 | */ | |
5543 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, | |
5544 | sizeof(wl1271_band_2ghz)); | |
bfb92ca1 EP |
5545 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, |
5546 | &wl->ht_cap[IEEE80211_BAND_2GHZ], | |
5547 | sizeof(*wl->ht_cap)); | |
a8aaaf53 LC |
5548 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, |
5549 | sizeof(wl1271_band_5ghz)); | |
bfb92ca1 EP |
5550 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, |
5551 | &wl->ht_cap[IEEE80211_BAND_5GHZ], | |
5552 | sizeof(*wl->ht_cap)); | |
a8aaaf53 LC |
5553 | |
5554 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | |
5555 | &wl->bands[IEEE80211_BAND_2GHZ]; | |
5556 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | |
5557 | &wl->bands[IEEE80211_BAND_5GHZ]; | |
1ebec3d7 | 5558 | |
12bd8949 | 5559 | wl->hw->queues = 4; |
31627dc5 | 5560 | wl->hw->max_rates = 1; |
12bd8949 | 5561 | |
b7417d93 JO |
5562 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
5563 | ||
9c1b190b AN |
5564 | /* the FW answers probe-requests in AP-mode */ |
5565 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; | |
5566 | wl->hw->wiphy->probe_resp_offload = | |
5567 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | | |
5568 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | | |
5569 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; | |
5570 | ||
bcab320b | 5571 | /* allowed interface combinations */ |
de40750f | 5572 | wlcore_iface_combinations[0].num_different_channels = wl->num_channels; |
bcab320b EP |
5573 | wl->hw->wiphy->iface_combinations = wlcore_iface_combinations; |
5574 | wl->hw->wiphy->n_iface_combinations = | |
5575 | ARRAY_SIZE(wlcore_iface_combinations); | |
5576 | ||
a390e85c | 5577 | SET_IEEE80211_DEV(wl->hw, wl->dev); |
f5fc0f86 | 5578 | |
f84f7d78 | 5579 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
87fbcb0f | 5580 | wl->hw->vif_data_size = sizeof(struct wl12xx_vif); |
f84f7d78 | 5581 | |
ba421f8f | 5582 | wl->hw->max_rx_aggregation_subframes = wl->conf.ht.rx_ba_win_size; |
4c9cfa78 | 5583 | |
f5fc0f86 LC |
5584 | return 0; |
5585 | } | |
5586 | ||
f5fc0f86 | 5587 | #define WL1271_DEFAULT_CHANNEL 0 |
c332a4b8 | 5588 | |
c50a2825 EP |
5589 | struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size, u32 aggr_buf_size, |
5590 | u32 mbox_size) | |
f5fc0f86 | 5591 | { |
f5fc0f86 LC |
5592 | struct ieee80211_hw *hw; |
5593 | struct wl1271 *wl; | |
a8c0ddb5 | 5594 | int i, j, ret; |
1f37cbc9 | 5595 | unsigned int order; |
f5fc0f86 | 5596 | |
c7ffb902 | 5597 | BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); |
f80c2d12 | 5598 | |
f5fc0f86 LC |
5599 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); |
5600 | if (!hw) { | |
5601 | wl1271_error("could not alloc ieee80211_hw"); | |
a1dd8187 | 5602 | ret = -ENOMEM; |
3b56dd6a TP |
5603 | goto err_hw_alloc; |
5604 | } | |
5605 | ||
f5fc0f86 LC |
5606 | wl = hw->priv; |
5607 | memset(wl, 0, sizeof(*wl)); | |
5608 | ||
96e0c683 AN |
5609 | wl->priv = kzalloc(priv_size, GFP_KERNEL); |
5610 | if (!wl->priv) { | |
5611 | wl1271_error("could not alloc wl priv"); | |
5612 | ret = -ENOMEM; | |
5613 | goto err_priv_alloc; | |
5614 | } | |
5615 | ||
87627214 | 5616 | INIT_LIST_HEAD(&wl->wlvif_list); |
01c09162 | 5617 | |
f5fc0f86 | 5618 | wl->hw = hw; |
f5fc0f86 | 5619 | |
a8c0ddb5 | 5620 | for (i = 0; i < NUM_TX_QUEUES; i++) |
c7ffb902 | 5621 | for (j = 0; j < WL12XX_MAX_LINKS; j++) |
a8c0ddb5 AN |
5622 | skb_queue_head_init(&wl->links[j].tx_queue[i]); |
5623 | ||
a620865e IY |
5624 | skb_queue_head_init(&wl->deferred_rx_queue); |
5625 | skb_queue_head_init(&wl->deferred_tx_queue); | |
5626 | ||
37b70a81 | 5627 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
a620865e | 5628 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); |
117b38d0 JO |
5629 | INIT_WORK(&wl->tx_work, wl1271_tx_work); |
5630 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); | |
5631 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); | |
dabf37db | 5632 | INIT_DELAYED_WORK(&wl->roc_complete_work, wlcore_roc_complete_work); |
55df5afb | 5633 | INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work); |
77ddaa10 | 5634 | |
92ef8960 EP |
5635 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); |
5636 | if (!wl->freezable_wq) { | |
5637 | ret = -ENOMEM; | |
5638 | goto err_hw; | |
5639 | } | |
5640 | ||
f5fc0f86 | 5641 | wl->channel = WL1271_DEFAULT_CHANNEL; |
f5fc0f86 | 5642 | wl->rx_counter = 0; |
f5fc0f86 | 5643 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
8a5a37a6 | 5644 | wl->band = IEEE80211_BAND_2GHZ; |
83d08d3f | 5645 | wl->channel_type = NL80211_CHAN_NO_HT; |
830fb67b | 5646 | wl->flags = 0; |
7fc3a864 | 5647 | wl->sg_enabled = true; |
66340e5b | 5648 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
d717fd61 | 5649 | wl->hw_pg_ver = -1; |
b622d992 AN |
5650 | wl->ap_ps_map = 0; |
5651 | wl->ap_fw_ps_map = 0; | |
606ea9fa | 5652 | wl->quirks = 0; |
341b7cde | 5653 | wl->platform_quirks = 0; |
f4df1bd5 | 5654 | wl->system_hlid = WL12XX_SYSTEM_HLID; |
da03209e | 5655 | wl->active_sta_count = 0; |
95dac04f IY |
5656 | wl->fwlog_size = 0; |
5657 | init_waitqueue_head(&wl->fwlog_waitq); | |
f5fc0f86 | 5658 | |
f4df1bd5 EP |
5659 | /* The system link is always allocated */ |
5660 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); | |
5661 | ||
25eeb9e3 | 5662 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
72b0624f | 5663 | for (i = 0; i < wl->num_tx_desc; i++) |
f5fc0f86 LC |
5664 | wl->tx_frames[i] = NULL; |
5665 | ||
5666 | spin_lock_init(&wl->wl_lock); | |
5667 | ||
4cc53383 | 5668 | wl->state = WLCORE_STATE_OFF; |
3fcdab70 | 5669 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
f5fc0f86 | 5670 | mutex_init(&wl->mutex); |
2c38849f | 5671 | mutex_init(&wl->flush_mutex); |
6f8d6b20 | 5672 | init_completion(&wl->nvs_loading_complete); |
f5fc0f86 | 5673 | |
26a309c7 | 5674 | order = get_order(aggr_buf_size); |
1f37cbc9 IY |
5675 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); |
5676 | if (!wl->aggr_buf) { | |
5677 | ret = -ENOMEM; | |
92ef8960 | 5678 | goto err_wq; |
1f37cbc9 | 5679 | } |
26a309c7 | 5680 | wl->aggr_buf_size = aggr_buf_size; |
1f37cbc9 | 5681 | |
990f5de7 IY |
5682 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); |
5683 | if (!wl->dummy_packet) { | |
5684 | ret = -ENOMEM; | |
5685 | goto err_aggr; | |
5686 | } | |
5687 | ||
95dac04f IY |
5688 | /* Allocate one page for the FW log */ |
5689 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); | |
5690 | if (!wl->fwlog) { | |
5691 | ret = -ENOMEM; | |
5692 | goto err_dummy_packet; | |
5693 | } | |
5694 | ||
c50a2825 EP |
5695 | wl->mbox_size = mbox_size; |
5696 | wl->mbox = kmalloc(wl->mbox_size, GFP_KERNEL | GFP_DMA); | |
690142e9 MG |
5697 | if (!wl->mbox) { |
5698 | ret = -ENOMEM; | |
5699 | goto err_fwlog; | |
5700 | } | |
5701 | ||
c332a4b8 | 5702 | return hw; |
a1dd8187 | 5703 | |
690142e9 MG |
5704 | err_fwlog: |
5705 | free_page((unsigned long)wl->fwlog); | |
5706 | ||
990f5de7 IY |
5707 | err_dummy_packet: |
5708 | dev_kfree_skb(wl->dummy_packet); | |
5709 | ||
1f37cbc9 IY |
5710 | err_aggr: |
5711 | free_pages((unsigned long)wl->aggr_buf, order); | |
5712 | ||
92ef8960 EP |
5713 | err_wq: |
5714 | destroy_workqueue(wl->freezable_wq); | |
5715 | ||
a1dd8187 | 5716 | err_hw: |
3b56dd6a | 5717 | wl1271_debugfs_exit(wl); |
96e0c683 AN |
5718 | kfree(wl->priv); |
5719 | ||
5720 | err_priv_alloc: | |
3b56dd6a TP |
5721 | ieee80211_free_hw(hw); |
5722 | ||
5723 | err_hw_alloc: | |
a1dd8187 | 5724 | |
a1dd8187 | 5725 | return ERR_PTR(ret); |
c332a4b8 | 5726 | } |
ffeb501c | 5727 | EXPORT_SYMBOL_GPL(wlcore_alloc_hw); |
c332a4b8 | 5728 | |
ffeb501c | 5729 | int wlcore_free_hw(struct wl1271 *wl) |
c332a4b8 | 5730 | { |
95dac04f IY |
5731 | /* Unblock any fwlog readers */ |
5732 | mutex_lock(&wl->mutex); | |
5733 | wl->fwlog_size = -1; | |
5734 | wake_up_interruptible_all(&wl->fwlog_waitq); | |
5735 | mutex_unlock(&wl->mutex); | |
5736 | ||
f79f890c | 5737 | device_remove_bin_file(wl->dev, &fwlog_attr); |
6f07b72a | 5738 | |
f79f890c | 5739 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
6f07b72a | 5740 | |
f79f890c | 5741 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
a8e27820 | 5742 | kfree(wl->mbox); |
95dac04f | 5743 | free_page((unsigned long)wl->fwlog); |
990f5de7 | 5744 | dev_kfree_skb(wl->dummy_packet); |
26a309c7 | 5745 | free_pages((unsigned long)wl->aggr_buf, get_order(wl->aggr_buf_size)); |
c332a4b8 TP |
5746 | |
5747 | wl1271_debugfs_exit(wl); | |
5748 | ||
c332a4b8 TP |
5749 | vfree(wl->fw); |
5750 | wl->fw = NULL; | |
3fcdab70 | 5751 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
c332a4b8 TP |
5752 | kfree(wl->nvs); |
5753 | wl->nvs = NULL; | |
5754 | ||
0afd04e5 | 5755 | kfree(wl->fw_status_1); |
c332a4b8 | 5756 | kfree(wl->tx_res_if); |
92ef8960 | 5757 | destroy_workqueue(wl->freezable_wq); |
c332a4b8 | 5758 | |
96e0c683 | 5759 | kfree(wl->priv); |
c332a4b8 TP |
5760 | ieee80211_free_hw(wl->hw); |
5761 | ||
5762 | return 0; | |
5763 | } | |
ffeb501c | 5764 | EXPORT_SYMBOL_GPL(wlcore_free_hw); |
50b3eb4b | 5765 | |
a390e85c FB |
5766 | static irqreturn_t wl12xx_hardirq(int irq, void *cookie) |
5767 | { | |
5768 | struct wl1271 *wl = cookie; | |
5769 | unsigned long flags; | |
5770 | ||
5771 | wl1271_debug(DEBUG_IRQ, "IRQ"); | |
5772 | ||
5773 | /* complete the ELP completion */ | |
5774 | spin_lock_irqsave(&wl->wl_lock, flags); | |
5775 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | |
5776 | if (wl->elp_compl) { | |
5777 | complete(wl->elp_compl); | |
5778 | wl->elp_compl = NULL; | |
5779 | } | |
5780 | ||
5781 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { | |
5782 | /* don't enqueue a work right now. mark it as pending */ | |
5783 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); | |
5784 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); | |
5785 | disable_irq_nosync(wl->irq); | |
5786 | pm_wakeup_event(wl->dev, 0); | |
5787 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
5788 | return IRQ_HANDLED; | |
5789 | } | |
5790 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
5791 | ||
5792 | return IRQ_WAKE_THREAD; | |
5793 | } | |
5794 | ||
6f8d6b20 | 5795 | static void wlcore_nvs_cb(const struct firmware *fw, void *context) |
ce2a217c | 5796 | { |
6f8d6b20 IY |
5797 | struct wl1271 *wl = context; |
5798 | struct platform_device *pdev = wl->pdev; | |
a390e85c | 5799 | struct wl12xx_platform_data *pdata = pdev->dev.platform_data; |
a390e85c | 5800 | unsigned long irqflags; |
ffeb501c | 5801 | int ret; |
a390e85c | 5802 | |
6f8d6b20 IY |
5803 | if (fw) { |
5804 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); | |
5805 | if (!wl->nvs) { | |
5806 | wl1271_error("Could not allocate nvs data"); | |
5807 | goto out; | |
5808 | } | |
5809 | wl->nvs_len = fw->size; | |
5810 | } else { | |
5811 | wl1271_debug(DEBUG_BOOT, "Could not get nvs file %s", | |
5812 | WL12XX_NVS_NAME); | |
5813 | wl->nvs = NULL; | |
5814 | wl->nvs_len = 0; | |
a390e85c FB |
5815 | } |
5816 | ||
3992eb2b IY |
5817 | ret = wl->ops->setup(wl); |
5818 | if (ret < 0) | |
6f8d6b20 | 5819 | goto out_free_nvs; |
3992eb2b | 5820 | |
72b0624f AN |
5821 | BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS); |
5822 | ||
e87288f0 LC |
5823 | /* adjust some runtime configuration parameters */ |
5824 | wlcore_adjust_conf(wl); | |
5825 | ||
a390e85c | 5826 | wl->irq = platform_get_irq(pdev, 0); |
a390e85c FB |
5827 | wl->platform_quirks = pdata->platform_quirks; |
5828 | wl->set_power = pdata->set_power; | |
a390e85c FB |
5829 | wl->if_ops = pdata->ops; |
5830 | ||
a390e85c FB |
5831 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
5832 | irqflags = IRQF_TRIGGER_RISING; | |
5833 | else | |
5834 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; | |
5835 | ||
b5b45b3c | 5836 | ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wlcore_irq, |
a390e85c FB |
5837 | irqflags, |
5838 | pdev->name, wl); | |
5839 | if (ret < 0) { | |
5840 | wl1271_error("request_irq() failed: %d", ret); | |
6f8d6b20 | 5841 | goto out_free_nvs; |
a390e85c FB |
5842 | } |
5843 | ||
dfb89c56 | 5844 | #ifdef CONFIG_PM |
a390e85c FB |
5845 | ret = enable_irq_wake(wl->irq); |
5846 | if (!ret) { | |
5847 | wl->irq_wake_enabled = true; | |
5848 | device_init_wakeup(wl->dev, 1); | |
b95d7cef | 5849 | if (pdata->pwr_in_suspend) { |
ffeb501c | 5850 | wl->hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; |
b95d7cef ES |
5851 | wl->hw->wiphy->wowlan.n_patterns = |
5852 | WL1271_MAX_RX_FILTERS; | |
5853 | wl->hw->wiphy->wowlan.pattern_min_len = 1; | |
5854 | wl->hw->wiphy->wowlan.pattern_max_len = | |
5855 | WL1271_RX_FILTER_MAX_PATTERN_SIZE; | |
5856 | } | |
a390e85c | 5857 | } |
dfb89c56 | 5858 | #endif |
a390e85c FB |
5859 | disable_irq(wl->irq); |
5860 | ||
4afc37a0 LC |
5861 | ret = wl12xx_get_hw_info(wl); |
5862 | if (ret < 0) { | |
5863 | wl1271_error("couldn't get hw info"); | |
8b425e62 | 5864 | goto out_irq; |
4afc37a0 LC |
5865 | } |
5866 | ||
5867 | ret = wl->ops->identify_chip(wl); | |
5868 | if (ret < 0) | |
8b425e62 | 5869 | goto out_irq; |
4afc37a0 | 5870 | |
a390e85c FB |
5871 | ret = wl1271_init_ieee80211(wl); |
5872 | if (ret) | |
5873 | goto out_irq; | |
5874 | ||
5875 | ret = wl1271_register_hw(wl); | |
5876 | if (ret) | |
5877 | goto out_irq; | |
5878 | ||
f79f890c FB |
5879 | /* Create sysfs file to control bt coex state */ |
5880 | ret = device_create_file(wl->dev, &dev_attr_bt_coex_state); | |
5881 | if (ret < 0) { | |
5882 | wl1271_error("failed to create sysfs file bt_coex_state"); | |
8b425e62 | 5883 | goto out_unreg; |
f79f890c FB |
5884 | } |
5885 | ||
5886 | /* Create sysfs file to get HW PG version */ | |
5887 | ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver); | |
5888 | if (ret < 0) { | |
5889 | wl1271_error("failed to create sysfs file hw_pg_ver"); | |
5890 | goto out_bt_coex_state; | |
5891 | } | |
5892 | ||
5893 | /* Create sysfs file for the FW log */ | |
5894 | ret = device_create_bin_file(wl->dev, &fwlog_attr); | |
5895 | if (ret < 0) { | |
5896 | wl1271_error("failed to create sysfs file fwlog"); | |
5897 | goto out_hw_pg_ver; | |
5898 | } | |
5899 | ||
6f8d6b20 | 5900 | wl->initialized = true; |
ffeb501c | 5901 | goto out; |
a390e85c | 5902 | |
f79f890c FB |
5903 | out_hw_pg_ver: |
5904 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); | |
5905 | ||
5906 | out_bt_coex_state: | |
5907 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); | |
5908 | ||
8b425e62 LC |
5909 | out_unreg: |
5910 | wl1271_unregister_hw(wl); | |
5911 | ||
a390e85c FB |
5912 | out_irq: |
5913 | free_irq(wl->irq, wl); | |
5914 | ||
6f8d6b20 IY |
5915 | out_free_nvs: |
5916 | kfree(wl->nvs); | |
5917 | ||
a390e85c | 5918 | out: |
6f8d6b20 IY |
5919 | release_firmware(fw); |
5920 | complete_all(&wl->nvs_loading_complete); | |
5921 | } | |
5922 | ||
5923 | int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev) | |
5924 | { | |
5925 | int ret; | |
5926 | ||
5927 | if (!wl->ops || !wl->ptable) | |
5928 | return -EINVAL; | |
5929 | ||
5930 | wl->dev = &pdev->dev; | |
5931 | wl->pdev = pdev; | |
5932 | platform_set_drvdata(pdev, wl); | |
5933 | ||
5934 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, | |
5935 | WL12XX_NVS_NAME, &pdev->dev, GFP_KERNEL, | |
5936 | wl, wlcore_nvs_cb); | |
5937 | if (ret < 0) { | |
5938 | wl1271_error("request_firmware_nowait failed: %d", ret); | |
5939 | complete_all(&wl->nvs_loading_complete); | |
5940 | } | |
5941 | ||
a390e85c | 5942 | return ret; |
ce2a217c | 5943 | } |
b2ba99ff | 5944 | EXPORT_SYMBOL_GPL(wlcore_probe); |
ce2a217c | 5945 | |
b2ba99ff | 5946 | int __devexit wlcore_remove(struct platform_device *pdev) |
ce2a217c | 5947 | { |
a390e85c FB |
5948 | struct wl1271 *wl = platform_get_drvdata(pdev); |
5949 | ||
6f8d6b20 IY |
5950 | wait_for_completion(&wl->nvs_loading_complete); |
5951 | if (!wl->initialized) | |
5952 | return 0; | |
5953 | ||
a390e85c FB |
5954 | if (wl->irq_wake_enabled) { |
5955 | device_init_wakeup(wl->dev, 0); | |
5956 | disable_irq_wake(wl->irq); | |
5957 | } | |
5958 | wl1271_unregister_hw(wl); | |
5959 | free_irq(wl->irq, wl); | |
ffeb501c | 5960 | wlcore_free_hw(wl); |
a390e85c | 5961 | |
ce2a217c FB |
5962 | return 0; |
5963 | } | |
b2ba99ff | 5964 | EXPORT_SYMBOL_GPL(wlcore_remove); |
ce2a217c | 5965 | |
491bbd6b | 5966 | u32 wl12xx_debug_level = DEBUG_NONE; |
17c1755c | 5967 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
491bbd6b | 5968 | module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR); |
17c1755c EP |
5969 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
5970 | ||
95dac04f | 5971 | module_param_named(fwlog, fwlog_param, charp, 0); |
2c882fa4 | 5972 | MODULE_PARM_DESC(fwlog, |
95dac04f IY |
5973 | "FW logger options: continuous, ondemand, dbgpins or disable"); |
5974 | ||
2a5bff09 EP |
5975 | module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR); |
5976 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); | |
5977 | ||
34785be5 AN |
5978 | module_param(no_recovery, bool, S_IRUSR | S_IWUSR); |
5979 | MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck."); | |
5980 | ||
50b3eb4b | 5981 | MODULE_LICENSE("GPL"); |
b1a48cab | 5982 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
50b3eb4b | 5983 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |
0635ad45 | 5984 | MODULE_FIRMWARE(WL12XX_NVS_NAME); |