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