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