Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
1 | /* |
2 | * This file is part of wl1271 | |
3 | * | |
8bf29b0e | 4 | * Copyright (C) 2008-2010 Nokia Corporation |
f5fc0f86 LC |
5 | * |
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License | |
10 | * version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA | |
21 | * | |
22 | */ | |
23 | ||
24 | #include <linux/module.h> | |
f5fc0f86 LC |
25 | #include <linux/firmware.h> |
26 | #include <linux/delay.h> | |
f5fc0f86 LC |
27 | #include <linux/spi/spi.h> |
28 | #include <linux/crc32.h> | |
29 | #include <linux/etherdevice.h> | |
1fba4974 | 30 | #include <linux/vmalloc.h> |
a1dd8187 | 31 | #include <linux/platform_device.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
f5fc0f86 | 33 | |
00d20100 | 34 | #include "wl12xx.h" |
f5fc0f86 | 35 | #include "wl12xx_80211.h" |
00d20100 SL |
36 | #include "reg.h" |
37 | #include "io.h" | |
38 | #include "event.h" | |
39 | #include "tx.h" | |
40 | #include "rx.h" | |
41 | #include "ps.h" | |
42 | #include "init.h" | |
43 | #include "debugfs.h" | |
44 | #include "cmd.h" | |
45 | #include "boot.h" | |
46 | #include "testmode.h" | |
47 | #include "scan.h" | |
f5fc0f86 | 48 | |
9ccd9217 JO |
49 | #define WL1271_BOOT_RETRIES 3 |
50 | ||
8a08048a JO |
51 | static struct conf_drv_settings default_conf = { |
52 | .sg = { | |
1b00f546 JO |
53 | .params = { |
54 | [CONF_SG_BT_PER_THRESHOLD] = 7500, | |
55 | [CONF_SG_HV3_MAX_OVERRIDE] = 0, | |
56 | [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400, | |
57 | [CONF_SG_BT_LOAD_RATIO] = 50, | |
8d2ef7bd | 58 | [CONF_SG_AUTO_PS_MODE] = 1, |
1b00f546 JO |
59 | [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170, |
60 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50, | |
61 | [CONF_SG_ANTENNA_CONFIGURATION] = 0, | |
62 | [CONF_SG_BEACON_MISS_PERCENT] = 60, | |
63 | [CONF_SG_RATE_ADAPT_THRESH] = 12, | |
64 | [CONF_SG_RATE_ADAPT_SNR] = 0, | |
65 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10, | |
66 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 30, | |
67 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 8, | |
68 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20, | |
69 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 50, | |
70 | /* Note: with UPSD, this should be 4 */ | |
71 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 8, | |
72 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7, | |
73 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25, | |
74 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 20, | |
75 | /* Note: with UPDS, this should be 15 */ | |
76 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8, | |
77 | /* Note: with UPDS, this should be 50 */ | |
78 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 40, | |
79 | /* Note: with UPDS, this should be 10 */ | |
80 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 20, | |
81 | [CONF_SG_RXT] = 1200, | |
82 | [CONF_SG_TXT] = 1000, | |
83 | [CONF_SG_ADAPTIVE_RXT_TXT] = 1, | |
84 | [CONF_SG_PS_POLL_TIMEOUT] = 10, | |
85 | [CONF_SG_UPSD_TIMEOUT] = 10, | |
86 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7, | |
87 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15, | |
88 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15, | |
89 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8, | |
90 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20, | |
91 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15, | |
92 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20, | |
93 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50, | |
94 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10, | |
95 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200, | |
96 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800, | |
97 | [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75, | |
98 | [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15, | |
99 | [CONF_SG_HV3_MAX_SERVED] = 6, | |
100 | [CONF_SG_DHCP_TIME] = 5000, | |
101 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100, | |
102 | }, | |
103 | .state = CONF_SG_PROTECTIVE, | |
8a08048a JO |
104 | }, |
105 | .rx = { | |
106 | .rx_msdu_life_time = 512000, | |
107 | .packet_detection_threshold = 0, | |
108 | .ps_poll_timeout = 15, | |
109 | .upsd_timeout = 15, | |
110 | .rts_threshold = 2347, | |
3ed8f2c6 LC |
111 | .rx_cca_threshold = 0, |
112 | .irq_blk_threshold = 0xFFFF, | |
113 | .irq_pkt_threshold = 0, | |
114 | .irq_timeout = 600, | |
8a08048a JO |
115 | .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY, |
116 | }, | |
117 | .tx = { | |
118 | .tx_energy_detection = 0, | |
1e05a818 | 119 | .sta_rc_conf = { |
ebba60c6 | 120 | .enabled_rates = 0, |
8a08048a JO |
121 | .short_retry_limit = 10, |
122 | .long_retry_limit = 10, | |
1e05a818 | 123 | .aflags = 0, |
45b531a8 | 124 | }, |
8a08048a JO |
125 | .ac_conf_count = 4, |
126 | .ac_conf = { | |
9987a9da | 127 | [CONF_TX_AC_BE] = { |
8a08048a JO |
128 | .ac = CONF_TX_AC_BE, |
129 | .cw_min = 15, | |
130 | .cw_max = 63, | |
131 | .aifsn = 3, | |
132 | .tx_op_limit = 0, | |
45b531a8 | 133 | }, |
9987a9da | 134 | [CONF_TX_AC_BK] = { |
8a08048a JO |
135 | .ac = CONF_TX_AC_BK, |
136 | .cw_min = 15, | |
137 | .cw_max = 63, | |
138 | .aifsn = 7, | |
139 | .tx_op_limit = 0, | |
45b531a8 | 140 | }, |
9987a9da | 141 | [CONF_TX_AC_VI] = { |
8a08048a JO |
142 | .ac = CONF_TX_AC_VI, |
143 | .cw_min = 15, | |
144 | .cw_max = 63, | |
145 | .aifsn = CONF_TX_AIFS_PIFS, | |
146 | .tx_op_limit = 3008, | |
147 | }, | |
9987a9da | 148 | [CONF_TX_AC_VO] = { |
8a08048a JO |
149 | .ac = CONF_TX_AC_VO, |
150 | .cw_min = 15, | |
151 | .cw_max = 63, | |
152 | .aifsn = CONF_TX_AIFS_PIFS, | |
153 | .tx_op_limit = 1504, | |
45b531a8 | 154 | }, |
51f2be24 | 155 | }, |
1e05a818 AN |
156 | .ap_rc_conf = { |
157 | [0] = { | |
158 | .enabled_rates = CONF_TX_AP_ENABLED_RATES, | |
159 | .short_retry_limit = 10, | |
160 | .long_retry_limit = 10, | |
161 | .aflags = 0, | |
162 | }, | |
163 | [1] = { | |
164 | .enabled_rates = CONF_TX_AP_ENABLED_RATES, | |
165 | .short_retry_limit = 10, | |
166 | .long_retry_limit = 10, | |
167 | .aflags = 0, | |
168 | }, | |
169 | [2] = { | |
170 | .enabled_rates = CONF_TX_AP_ENABLED_RATES, | |
171 | .short_retry_limit = 10, | |
172 | .long_retry_limit = 10, | |
173 | .aflags = 0, | |
174 | }, | |
175 | [3] = { | |
176 | .enabled_rates = CONF_TX_AP_ENABLED_RATES, | |
177 | .short_retry_limit = 10, | |
178 | .long_retry_limit = 10, | |
179 | .aflags = 0, | |
180 | }, | |
181 | }, | |
182 | .ap_mgmt_conf = { | |
183 | .enabled_rates = CONF_TX_AP_DEFAULT_MGMT_RATES, | |
184 | .short_retry_limit = 10, | |
185 | .long_retry_limit = 10, | |
186 | .aflags = 0, | |
187 | }, | |
188 | .ap_bcst_conf = { | |
189 | .enabled_rates = CONF_HW_BIT_RATE_1MBPS, | |
190 | .short_retry_limit = 10, | |
191 | .long_retry_limit = 10, | |
192 | .aflags = 0, | |
193 | }, | |
79b223f4 | 194 | .ap_max_tx_retries = 100, |
9987a9da | 195 | .tid_conf_count = 4, |
8a08048a | 196 | .tid_conf = { |
9987a9da JO |
197 | [CONF_TX_AC_BE] = { |
198 | .queue_id = CONF_TX_AC_BE, | |
199 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | |
8a08048a JO |
200 | .tsid = CONF_TX_AC_BE, |
201 | .ps_scheme = CONF_PS_SCHEME_LEGACY, | |
202 | .ack_policy = CONF_ACK_POLICY_LEGACY, | |
203 | .apsd_conf = {0, 0}, | |
51f2be24 | 204 | }, |
9987a9da JO |
205 | [CONF_TX_AC_BK] = { |
206 | .queue_id = CONF_TX_AC_BK, | |
207 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | |
208 | .tsid = CONF_TX_AC_BK, | |
8a08048a JO |
209 | .ps_scheme = CONF_PS_SCHEME_LEGACY, |
210 | .ack_policy = CONF_ACK_POLICY_LEGACY, | |
211 | .apsd_conf = {0, 0}, | |
212 | }, | |
9987a9da JO |
213 | [CONF_TX_AC_VI] = { |
214 | .queue_id = CONF_TX_AC_VI, | |
215 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | |
216 | .tsid = CONF_TX_AC_VI, | |
8a08048a JO |
217 | .ps_scheme = CONF_PS_SCHEME_LEGACY, |
218 | .ack_policy = CONF_ACK_POLICY_LEGACY, | |
219 | .apsd_conf = {0, 0}, | |
220 | }, | |
9987a9da JO |
221 | [CONF_TX_AC_VO] = { |
222 | .queue_id = CONF_TX_AC_VO, | |
223 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | |
224 | .tsid = CONF_TX_AC_VO, | |
8a08048a JO |
225 | .ps_scheme = CONF_PS_SCHEME_LEGACY, |
226 | .ack_policy = CONF_ACK_POLICY_LEGACY, | |
227 | .apsd_conf = {0, 0}, | |
228 | }, | |
8a08048a JO |
229 | }, |
230 | .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD, | |
3ed8f2c6 | 231 | .tx_compl_timeout = 700, |
ebba60c6 JO |
232 | .tx_compl_threshold = 4, |
233 | .basic_rate = CONF_HW_BIT_RATE_1MBPS, | |
234 | .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS, | |
1e05a818 AN |
235 | .tmpl_short_retry_limit = 10, |
236 | .tmpl_long_retry_limit = 10, | |
8a08048a JO |
237 | }, |
238 | .conn = { | |
239 | .wake_up_event = CONF_WAKE_UP_EVENT_DTIM, | |
50c500ad | 240 | .listen_interval = 1, |
8a08048a JO |
241 | .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED, |
242 | .bcn_filt_ie_count = 1, | |
243 | .bcn_filt_ie = { | |
244 | [0] = { | |
245 | .ie = WLAN_EID_CHANNEL_SWITCH, | |
246 | .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE, | |
51f2be24 | 247 | } |
47fab7d5 | 248 | }, |
3ed8f2c6 | 249 | .synch_fail_thold = 10, |
8a08048a JO |
250 | .bss_lose_timeout = 100, |
251 | .beacon_rx_timeout = 10000, | |
252 | .broadcast_timeout = 20000, | |
253 | .rx_broadcast_in_ps = 1, | |
90494a90 JO |
254 | .ps_poll_threshold = 10, |
255 | .ps_poll_recovery_period = 700, | |
11f70f97 | 256 | .bet_enable = CONF_BET_MODE_ENABLE, |
84502563 | 257 | .bet_max_consecutive = 10, |
8eab7b47 JO |
258 | .psm_entry_retries = 5, |
259 | .psm_entry_nullfunc_retries = 3, | |
260 | .psm_entry_hangover_period = 1, | |
50c500ad JO |
261 | .keep_alive_interval = 55000, |
262 | .max_listen_interval = 20, | |
8a08048a | 263 | }, |
6e92b416 LC |
264 | .itrim = { |
265 | .enable = false, | |
266 | .timeout = 50000, | |
38ad2d87 JO |
267 | }, |
268 | .pm_config = { | |
269 | .host_clk_settling_time = 5000, | |
270 | .host_fast_wakeup_support = false | |
00236aed JO |
271 | }, |
272 | .roam_trigger = { | |
00236aed JO |
273 | .trigger_pacing = 1, |
274 | .avg_weight_rssi_beacon = 20, | |
275 | .avg_weight_rssi_data = 10, | |
276 | .avg_weight_snr_beacon = 20, | |
4b7fac77 | 277 | .avg_weight_snr_data = 10, |
bea39d6a JO |
278 | }, |
279 | .scan = { | |
280 | .min_dwell_time_active = 7500, | |
281 | .max_dwell_time_active = 30000, | |
282 | .min_dwell_time_passive = 30000, | |
283 | .max_dwell_time_passive = 60000, | |
284 | .num_probe_reqs = 2, | |
285 | }, | |
644a4860 JO |
286 | .rf = { |
287 | .tx_per_channel_power_compensation_2 = { | |
288 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
289 | }, | |
290 | .tx_per_channel_power_compensation_5 = { | |
291 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
292 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
293 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
294 | }, | |
295 | }, | |
4b7fac77 LS |
296 | .ht = { |
297 | .tx_ba_win_size = 64, | |
298 | .inactivity_timeout = 10000, | |
299 | }, | |
8a08048a JO |
300 | }; |
301 | ||
52b0e7a6 | 302 | static void __wl1271_op_remove_interface(struct wl1271 *wl); |
7f179b46 | 303 | static void wl1271_free_ap_keys(struct wl1271 *wl); |
52b0e7a6 JO |
304 | |
305 | ||
a1dd8187 JO |
306 | static void wl1271_device_release(struct device *dev) |
307 | { | |
308 | ||
309 | } | |
310 | ||
311 | static struct platform_device wl1271_device = { | |
312 | .name = "wl1271", | |
313 | .id = -1, | |
314 | ||
315 | /* device model insists to have a release function */ | |
316 | .dev = { | |
317 | .release = wl1271_device_release, | |
318 | }, | |
319 | }; | |
320 | ||
01c09162 JO |
321 | static LIST_HEAD(wl_list); |
322 | ||
c2c192ac JO |
323 | static int wl1271_dev_notify(struct notifier_block *me, unsigned long what, |
324 | void *arg) | |
325 | { | |
326 | struct net_device *dev = arg; | |
327 | struct wireless_dev *wdev; | |
328 | struct wiphy *wiphy; | |
329 | struct ieee80211_hw *hw; | |
330 | struct wl1271 *wl; | |
331 | struct wl1271 *wl_temp; | |
332 | int ret = 0; | |
333 | ||
334 | /* Check that this notification is for us. */ | |
335 | if (what != NETDEV_CHANGE) | |
336 | return NOTIFY_DONE; | |
337 | ||
338 | wdev = dev->ieee80211_ptr; | |
339 | if (wdev == NULL) | |
340 | return NOTIFY_DONE; | |
341 | ||
342 | wiphy = wdev->wiphy; | |
343 | if (wiphy == NULL) | |
344 | return NOTIFY_DONE; | |
345 | ||
346 | hw = wiphy_priv(wiphy); | |
347 | if (hw == NULL) | |
348 | return NOTIFY_DONE; | |
349 | ||
350 | wl_temp = hw->priv; | |
351 | list_for_each_entry(wl, &wl_list, list) { | |
352 | if (wl == wl_temp) | |
353 | break; | |
354 | } | |
355 | if (wl != wl_temp) | |
356 | return NOTIFY_DONE; | |
357 | ||
358 | mutex_lock(&wl->mutex); | |
359 | ||
360 | if (wl->state == WL1271_STATE_OFF) | |
361 | goto out; | |
362 | ||
363 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | |
364 | goto out; | |
365 | ||
366 | ret = wl1271_ps_elp_wakeup(wl, false); | |
367 | if (ret < 0) | |
368 | goto out; | |
369 | ||
370 | if ((dev->operstate == IF_OPER_UP) && | |
371 | !test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) { | |
372 | wl1271_cmd_set_sta_state(wl); | |
373 | wl1271_info("Association completed."); | |
374 | } | |
375 | ||
376 | wl1271_ps_elp_sleep(wl); | |
377 | ||
378 | out: | |
379 | mutex_unlock(&wl->mutex); | |
380 | ||
381 | return NOTIFY_OK; | |
382 | } | |
383 | ||
b7417d93 | 384 | static int wl1271_reg_notify(struct wiphy *wiphy, |
573c67cf LC |
385 | struct regulatory_request *request) |
386 | { | |
b7417d93 JO |
387 | struct ieee80211_supported_band *band; |
388 | struct ieee80211_channel *ch; | |
389 | int i; | |
390 | ||
391 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | |
392 | for (i = 0; i < band->n_channels; i++) { | |
393 | ch = &band->channels[i]; | |
394 | if (ch->flags & IEEE80211_CHAN_DISABLED) | |
395 | continue; | |
396 | ||
397 | if (ch->flags & IEEE80211_CHAN_RADAR) | |
398 | ch->flags |= IEEE80211_CHAN_NO_IBSS | | |
399 | IEEE80211_CHAN_PASSIVE_SCAN; | |
400 | ||
401 | } | |
402 | ||
403 | return 0; | |
404 | } | |
405 | ||
8a08048a JO |
406 | static void wl1271_conf_init(struct wl1271 *wl) |
407 | { | |
2b60100b JO |
408 | |
409 | /* | |
410 | * This function applies the default configuration to the driver. This | |
411 | * function is invoked upon driver load (spi probe.) | |
412 | * | |
413 | * The configuration is stored in a run-time structure in order to | |
414 | * facilitate for run-time adjustment of any of the parameters. Making | |
415 | * changes to the configuration structure will apply the new values on | |
416 | * the next interface up (wl1271_op_start.) | |
417 | */ | |
418 | ||
419 | /* apply driver default configuration */ | |
8a08048a | 420 | memcpy(&wl->conf, &default_conf, sizeof(default_conf)); |
2b60100b JO |
421 | } |
422 | ||
423 | ||
f5fc0f86 LC |
424 | static int wl1271_plt_init(struct wl1271 *wl) |
425 | { | |
12419cce LC |
426 | struct conf_tx_ac_category *conf_ac; |
427 | struct conf_tx_tid *conf_tid; | |
428 | int ret, i; | |
f5fc0f86 | 429 | |
98b5dd5d | 430 | ret = wl1271_cmd_general_parms(wl); |
4a90406b | 431 | if (ret < 0) |
cc7defa3 LC |
432 | return ret; |
433 | ||
98b5dd5d | 434 | ret = wl1271_cmd_radio_parms(wl); |
4a90406b | 435 | if (ret < 0) |
cc7defa3 LC |
436 | return ret; |
437 | ||
644a4860 JO |
438 | ret = wl1271_cmd_ext_radio_parms(wl); |
439 | if (ret < 0) | |
440 | return ret; | |
441 | ||
e0fe371b | 442 | ret = wl1271_sta_init_templates_config(wl); |
12419cce LC |
443 | if (ret < 0) |
444 | return ret; | |
445 | ||
f5fc0f86 LC |
446 | ret = wl1271_acx_init_mem_config(wl); |
447 | if (ret < 0) | |
448 | return ret; | |
449 | ||
12419cce LC |
450 | /* PHY layer config */ |
451 | ret = wl1271_init_phy_config(wl); | |
452 | if (ret < 0) | |
453 | goto out_free_memmap; | |
454 | ||
455 | ret = wl1271_acx_dco_itrim_params(wl); | |
456 | if (ret < 0) | |
457 | goto out_free_memmap; | |
458 | ||
459 | /* Initialize connection monitoring thresholds */ | |
6ccbb92e | 460 | ret = wl1271_acx_conn_monit_params(wl, false); |
12419cce LC |
461 | if (ret < 0) |
462 | goto out_free_memmap; | |
463 | ||
464 | /* Bluetooth WLAN coexistence */ | |
465 | ret = wl1271_init_pta(wl); | |
466 | if (ret < 0) | |
467 | goto out_free_memmap; | |
468 | ||
469 | /* Energy detection */ | |
470 | ret = wl1271_init_energy_detection(wl); | |
471 | if (ret < 0) | |
472 | goto out_free_memmap; | |
473 | ||
474 | /* Default fragmentation threshold */ | |
68d069c4 | 475 | ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold); |
12419cce LC |
476 | if (ret < 0) |
477 | goto out_free_memmap; | |
478 | ||
9987a9da JO |
479 | /* Default TID/AC configuration */ |
480 | BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count); | |
12419cce | 481 | for (i = 0; i < wl->conf.tx.tid_conf_count; i++) { |
9987a9da JO |
482 | conf_ac = &wl->conf.tx.ac_conf[i]; |
483 | ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min, | |
484 | conf_ac->cw_max, conf_ac->aifsn, | |
485 | conf_ac->tx_op_limit); | |
486 | if (ret < 0) | |
487 | goto out_free_memmap; | |
488 | ||
12419cce LC |
489 | conf_tid = &wl->conf.tx.tid_conf[i]; |
490 | ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id, | |
491 | conf_tid->channel_type, | |
492 | conf_tid->tsid, | |
493 | conf_tid->ps_scheme, | |
494 | conf_tid->ack_policy, | |
495 | conf_tid->apsd_conf[0], | |
496 | conf_tid->apsd_conf[1]); | |
497 | if (ret < 0) | |
498 | goto out_free_memmap; | |
499 | } | |
500 | ||
12419cce | 501 | /* Enable data path */ |
94210897 | 502 | ret = wl1271_cmd_data_path(wl, 1); |
f5fc0f86 | 503 | if (ret < 0) |
12419cce LC |
504 | goto out_free_memmap; |
505 | ||
506 | /* Configure for CAM power saving (ie. always active) */ | |
507 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); | |
508 | if (ret < 0) | |
509 | goto out_free_memmap; | |
510 | ||
511 | /* configure PM */ | |
512 | ret = wl1271_acx_pm_config(wl); | |
513 | if (ret < 0) | |
514 | goto out_free_memmap; | |
f5fc0f86 LC |
515 | |
516 | return 0; | |
12419cce LC |
517 | |
518 | out_free_memmap: | |
519 | kfree(wl->target_mem_map); | |
520 | wl->target_mem_map = NULL; | |
521 | ||
522 | return ret; | |
f5fc0f86 LC |
523 | } |
524 | ||
c15f63bf JO |
525 | static void wl1271_fw_status(struct wl1271 *wl, |
526 | struct wl1271_fw_status *status) | |
f5fc0f86 | 527 | { |
ac5e1e39 | 528 | struct timespec ts; |
f5fc0f86 LC |
529 | u32 total = 0; |
530 | int i; | |
531 | ||
09a9c2b3 | 532 | wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false); |
f5fc0f86 LC |
533 | |
534 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " | |
535 | "drv_rx_counter = %d, tx_results_counter = %d)", | |
536 | status->intr, | |
537 | status->fw_rx_counter, | |
538 | status->drv_rx_counter, | |
539 | status->tx_results_counter); | |
540 | ||
541 | /* update number of available TX blocks */ | |
542 | for (i = 0; i < NUM_TX_QUEUES; i++) { | |
d0f63b20 LC |
543 | u32 cnt = le32_to_cpu(status->tx_released_blks[i]) - |
544 | wl->tx_blocks_freed[i]; | |
545 | ||
546 | wl->tx_blocks_freed[i] = | |
547 | le32_to_cpu(status->tx_released_blks[i]); | |
f5fc0f86 LC |
548 | wl->tx_blocks_available += cnt; |
549 | total += cnt; | |
550 | } | |
551 | ||
a522550a IY |
552 | /* if more blocks are available now, tx work can be scheduled */ |
553 | if (total) | |
554 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | |
f5fc0f86 LC |
555 | |
556 | /* update the host-chipset time offset */ | |
ac5e1e39 JO |
557 | getnstimeofday(&ts); |
558 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - | |
559 | (s64)le32_to_cpu(status->fw_localtime); | |
f5fc0f86 LC |
560 | } |
561 | ||
1e73eb62 JO |
562 | #define WL1271_IRQ_MAX_LOOPS 10 |
563 | ||
f5fc0f86 LC |
564 | static void wl1271_irq_work(struct work_struct *work) |
565 | { | |
f5fc0f86 | 566 | int ret; |
c15f63bf | 567 | u32 intr; |
1e73eb62 JO |
568 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
569 | unsigned long flags; | |
f5fc0f86 LC |
570 | struct wl1271 *wl = |
571 | container_of(work, struct wl1271, irq_work); | |
572 | ||
573 | mutex_lock(&wl->mutex); | |
574 | ||
575 | wl1271_debug(DEBUG_IRQ, "IRQ work"); | |
576 | ||
1e73eb62 | 577 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
f5fc0f86 LC |
578 | goto out; |
579 | ||
580 | ret = wl1271_ps_elp_wakeup(wl, true); | |
581 | if (ret < 0) | |
582 | goto out; | |
583 | ||
1e73eb62 JO |
584 | spin_lock_irqsave(&wl->wl_lock, flags); |
585 | while (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags) && loopcount) { | |
586 | clear_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags); | |
587 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
588 | loopcount--; | |
589 | ||
590 | wl1271_fw_status(wl, wl->fw_status); | |
591 | intr = le32_to_cpu(wl->fw_status->intr); | |
592 | if (!intr) { | |
593 | wl1271_debug(DEBUG_IRQ, "Zero interrupt received."); | |
cdd0864a | 594 | spin_lock_irqsave(&wl->wl_lock, flags); |
1e73eb62 JO |
595 | continue; |
596 | } | |
f5fc0f86 | 597 | |
1e73eb62 | 598 | intr &= WL1271_INTR_MASK; |
f5fc0f86 | 599 | |
ccc83b04 EP |
600 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
601 | wl1271_error("watchdog interrupt received! " | |
602 | "starting recovery."); | |
603 | ieee80211_queue_work(wl->hw, &wl->recovery_work); | |
604 | ||
605 | /* restarting the chip. ignore any other interrupt. */ | |
606 | goto out; | |
607 | } | |
608 | ||
1e73eb62 JO |
609 | if (intr & WL1271_ACX_INTR_DATA) { |
610 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); | |
1fd2794f | 611 | |
1e73eb62 JO |
612 | /* check for tx results */ |
613 | if (wl->fw_status->tx_results_counter != | |
614 | (wl->tx_results_count & 0xff)) | |
615 | wl1271_tx_complete(wl); | |
f5fc0f86 | 616 | |
a522550a IY |
617 | /* Check if any tx blocks were freed */ |
618 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | |
6742f554 | 619 | wl->tx_queue_count) { |
a522550a IY |
620 | /* |
621 | * In order to avoid starvation of the TX path, | |
622 | * call the work function directly. | |
623 | */ | |
624 | wl1271_tx_work_locked(wl); | |
625 | } | |
626 | ||
1e73eb62 JO |
627 | wl1271_rx(wl, wl->fw_status); |
628 | } | |
f5fc0f86 | 629 | |
1e73eb62 JO |
630 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
631 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); | |
632 | wl1271_event_handle(wl, 0); | |
633 | } | |
f5fc0f86 | 634 | |
1e73eb62 JO |
635 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
636 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); | |
637 | wl1271_event_handle(wl, 1); | |
638 | } | |
f5fc0f86 | 639 | |
1e73eb62 JO |
640 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
641 | wl1271_debug(DEBUG_IRQ, | |
642 | "WL1271_ACX_INTR_INIT_COMPLETE"); | |
f5fc0f86 | 643 | |
1e73eb62 JO |
644 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
645 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); | |
646 | ||
647 | spin_lock_irqsave(&wl->wl_lock, flags); | |
c15f63bf | 648 | } |
f5fc0f86 | 649 | |
1e73eb62 JO |
650 | if (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags)) |
651 | ieee80211_queue_work(wl->hw, &wl->irq_work); | |
652 | else | |
653 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | |
654 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
655 | ||
f5fc0f86 LC |
656 | wl1271_ps_elp_sleep(wl); |
657 | ||
658 | out: | |
659 | mutex_unlock(&wl->mutex); | |
660 | } | |
661 | ||
f5fc0f86 LC |
662 | static int wl1271_fetch_firmware(struct wl1271 *wl) |
663 | { | |
664 | const struct firmware *fw; | |
166d504e | 665 | const char *fw_name; |
f5fc0f86 LC |
666 | int ret; |
667 | ||
166d504e AN |
668 | switch (wl->bss_type) { |
669 | case BSS_TYPE_AP_BSS: | |
670 | fw_name = WL1271_AP_FW_NAME; | |
671 | break; | |
672 | case BSS_TYPE_IBSS: | |
673 | case BSS_TYPE_STA_BSS: | |
674 | fw_name = WL1271_FW_NAME; | |
675 | break; | |
676 | default: | |
677 | wl1271_error("no compatible firmware for bss_type %d", | |
678 | wl->bss_type); | |
679 | return -EINVAL; | |
680 | } | |
681 | ||
682 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); | |
683 | ||
684 | ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl)); | |
f5fc0f86 LC |
685 | |
686 | if (ret < 0) { | |
687 | wl1271_error("could not get firmware: %d", ret); | |
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); |
f5fc0f86 | 699 | wl->fw_len = fw->size; |
1fba4974 | 700 | wl->fw = vmalloc(wl->fw_len); |
f5fc0f86 LC |
701 | |
702 | if (!wl->fw) { | |
703 | wl1271_error("could not allocate memory for the firmware"); | |
704 | ret = -ENOMEM; | |
705 | goto out; | |
706 | } | |
707 | ||
708 | memcpy(wl->fw, fw->data, wl->fw_len); | |
166d504e | 709 | wl->fw_bss_type = wl->bss_type; |
f5fc0f86 LC |
710 | ret = 0; |
711 | ||
712 | out: | |
713 | release_firmware(fw); | |
714 | ||
715 | return ret; | |
716 | } | |
717 | ||
718 | static int wl1271_fetch_nvs(struct wl1271 *wl) | |
719 | { | |
720 | const struct firmware *fw; | |
721 | int ret; | |
722 | ||
8197b711 | 723 | ret = request_firmware(&fw, WL1271_NVS_NAME, wl1271_wl_to_dev(wl)); |
f5fc0f86 LC |
724 | |
725 | if (ret < 0) { | |
726 | wl1271_error("could not get nvs file: %d", ret); | |
727 | return ret; | |
728 | } | |
729 | ||
929ebd30 | 730 | wl->nvs = kmemdup(fw->data, sizeof(struct wl1271_nvs_file), GFP_KERNEL); |
f5fc0f86 LC |
731 | |
732 | if (!wl->nvs) { | |
733 | wl1271_error("could not allocate memory for the nvs file"); | |
734 | ret = -ENOMEM; | |
735 | goto out; | |
736 | } | |
737 | ||
02fabb0e JO |
738 | wl->nvs_len = fw->size; |
739 | ||
f5fc0f86 LC |
740 | out: |
741 | release_firmware(fw); | |
742 | ||
743 | return ret; | |
744 | } | |
745 | ||
52b0e7a6 JO |
746 | static void wl1271_recovery_work(struct work_struct *work) |
747 | { | |
748 | struct wl1271 *wl = | |
749 | container_of(work, struct wl1271, recovery_work); | |
750 | ||
751 | mutex_lock(&wl->mutex); | |
752 | ||
753 | if (wl->state != WL1271_STATE_ON) | |
754 | goto out; | |
755 | ||
756 | wl1271_info("Hardware recovery in progress."); | |
757 | ||
d25611da JO |
758 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) |
759 | ieee80211_connection_loss(wl->vif); | |
760 | ||
52b0e7a6 JO |
761 | /* reboot the chipset */ |
762 | __wl1271_op_remove_interface(wl); | |
763 | ieee80211_restart_hw(wl->hw); | |
764 | ||
765 | out: | |
766 | mutex_unlock(&wl->mutex); | |
767 | } | |
768 | ||
f5fc0f86 LC |
769 | static void wl1271_fw_wakeup(struct wl1271 *wl) |
770 | { | |
771 | u32 elp_reg; | |
772 | ||
773 | elp_reg = ELPCTRL_WAKE_UP; | |
74621417 | 774 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); |
f5fc0f86 LC |
775 | } |
776 | ||
777 | static int wl1271_setup(struct wl1271 *wl) | |
778 | { | |
779 | wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); | |
780 | if (!wl->fw_status) | |
781 | return -ENOMEM; | |
782 | ||
783 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); | |
784 | if (!wl->tx_res_if) { | |
785 | kfree(wl->fw_status); | |
786 | return -ENOMEM; | |
787 | } | |
788 | ||
f5fc0f86 LC |
789 | return 0; |
790 | } | |
791 | ||
792 | static int wl1271_chip_wakeup(struct wl1271 *wl) | |
793 | { | |
451de97a | 794 | struct wl1271_partition_set partition; |
f5fc0f86 LC |
795 | int ret = 0; |
796 | ||
01ac17ec | 797 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
2cc78ff7 OBC |
798 | ret = wl1271_power_on(wl); |
799 | if (ret < 0) | |
800 | goto out; | |
f5fc0f86 | 801 | msleep(WL1271_POWER_ON_SLEEP); |
9b280722 TP |
802 | wl1271_io_reset(wl); |
803 | wl1271_io_init(wl); | |
f5fc0f86 LC |
804 | |
805 | /* We don't need a real memory partition here, because we only want | |
806 | * to use the registers at this point. */ | |
451de97a JO |
807 | memset(&partition, 0, sizeof(partition)); |
808 | partition.reg.start = REGISTERS_BASE; | |
809 | partition.reg.size = REGISTERS_DOWN_SIZE; | |
810 | wl1271_set_partition(wl, &partition); | |
f5fc0f86 LC |
811 | |
812 | /* ELP module wake up */ | |
813 | wl1271_fw_wakeup(wl); | |
814 | ||
815 | /* whal_FwCtrl_BootSm() */ | |
816 | ||
817 | /* 0. read chip id from CHIP_ID */ | |
7b048c52 | 818 | wl->chip.id = wl1271_read32(wl, CHIP_ID_B); |
f5fc0f86 LC |
819 | |
820 | /* 1. check if chip id is valid */ | |
821 | ||
822 | switch (wl->chip.id) { | |
823 | case CHIP_ID_1271_PG10: | |
824 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", | |
825 | wl->chip.id); | |
826 | ||
827 | ret = wl1271_setup(wl); | |
828 | if (ret < 0) | |
9ccd9217 | 829 | goto out; |
f5fc0f86 LC |
830 | break; |
831 | case CHIP_ID_1271_PG20: | |
832 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", | |
833 | wl->chip.id); | |
834 | ||
835 | ret = wl1271_setup(wl); | |
836 | if (ret < 0) | |
9ccd9217 | 837 | goto out; |
f5fc0f86 LC |
838 | break; |
839 | default: | |
9ccd9217 | 840 | wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); |
f5fc0f86 | 841 | ret = -ENODEV; |
9ccd9217 | 842 | goto out; |
f5fc0f86 LC |
843 | } |
844 | ||
166d504e AN |
845 | /* Make sure the firmware type matches the BSS type */ |
846 | if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) { | |
f5fc0f86 LC |
847 | ret = wl1271_fetch_firmware(wl); |
848 | if (ret < 0) | |
9ccd9217 | 849 | goto out; |
f5fc0f86 LC |
850 | } |
851 | ||
852 | /* No NVS from netlink, try to get it from the filesystem */ | |
853 | if (wl->nvs == NULL) { | |
854 | ret = wl1271_fetch_nvs(wl); | |
855 | if (ret < 0) | |
9ccd9217 | 856 | goto out; |
f5fc0f86 LC |
857 | } |
858 | ||
859 | out: | |
860 | return ret; | |
861 | } | |
862 | ||
f5fc0f86 LC |
863 | int wl1271_plt_start(struct wl1271 *wl) |
864 | { | |
9ccd9217 | 865 | int retries = WL1271_BOOT_RETRIES; |
f5fc0f86 LC |
866 | int ret; |
867 | ||
868 | mutex_lock(&wl->mutex); | |
869 | ||
870 | wl1271_notice("power up"); | |
871 | ||
872 | if (wl->state != WL1271_STATE_OFF) { | |
873 | wl1271_error("cannot go into PLT state because not " | |
874 | "in off state: %d", wl->state); | |
875 | ret = -EBUSY; | |
876 | goto out; | |
877 | } | |
878 | ||
166d504e AN |
879 | wl->bss_type = BSS_TYPE_STA_BSS; |
880 | ||
9ccd9217 JO |
881 | while (retries) { |
882 | retries--; | |
883 | ret = wl1271_chip_wakeup(wl); | |
884 | if (ret < 0) | |
885 | goto power_off; | |
f5fc0f86 | 886 | |
9ccd9217 JO |
887 | ret = wl1271_boot(wl); |
888 | if (ret < 0) | |
889 | goto power_off; | |
eb5b28d0 | 890 | |
9ccd9217 JO |
891 | ret = wl1271_plt_init(wl); |
892 | if (ret < 0) | |
893 | goto irq_disable; | |
bd5ea18f | 894 | |
9ccd9217 JO |
895 | wl->state = WL1271_STATE_PLT; |
896 | wl1271_notice("firmware booted in PLT mode (%s)", | |
4b7fac77 | 897 | wl->chip.fw_ver_str); |
9ccd9217 | 898 | goto out; |
eb5b28d0 | 899 | |
9ccd9217 JO |
900 | irq_disable: |
901 | wl1271_disable_interrupts(wl); | |
902 | mutex_unlock(&wl->mutex); | |
903 | /* Unlocking the mutex in the middle of handling is | |
904 | inherently unsafe. In this case we deem it safe to do, | |
905 | because we need to let any possibly pending IRQ out of | |
906 | the system (and while we are WL1271_STATE_OFF the IRQ | |
907 | work function will not do anything.) Also, any other | |
908 | possible concurrent operations will fail due to the | |
909 | current state, hence the wl1271 struct should be safe. */ | |
910 | cancel_work_sync(&wl->irq_work); | |
911 | mutex_lock(&wl->mutex); | |
912 | power_off: | |
913 | wl1271_power_off(wl); | |
914 | } | |
f5fc0f86 | 915 | |
9ccd9217 JO |
916 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
917 | WL1271_BOOT_RETRIES); | |
f5fc0f86 LC |
918 | out: |
919 | mutex_unlock(&wl->mutex); | |
920 | ||
921 | return ret; | |
922 | } | |
923 | ||
4ae3fa87 | 924 | int __wl1271_plt_stop(struct wl1271 *wl) |
f5fc0f86 LC |
925 | { |
926 | int ret = 0; | |
927 | ||
f5fc0f86 LC |
928 | wl1271_notice("power down"); |
929 | ||
930 | if (wl->state != WL1271_STATE_PLT) { | |
931 | wl1271_error("cannot power down because not in PLT " | |
932 | "state: %d", wl->state); | |
933 | ret = -EBUSY; | |
934 | goto out; | |
935 | } | |
936 | ||
937 | wl1271_disable_interrupts(wl); | |
938 | wl1271_power_off(wl); | |
939 | ||
940 | wl->state = WL1271_STATE_OFF; | |
bd5ea18f | 941 | wl->rx_counter = 0; |
f5fc0f86 | 942 | |
f5fc0f86 | 943 | mutex_unlock(&wl->mutex); |
8c7f4f31 | 944 | cancel_work_sync(&wl->irq_work); |
52b0e7a6 | 945 | cancel_work_sync(&wl->recovery_work); |
4ae3fa87 JO |
946 | mutex_lock(&wl->mutex); |
947 | out: | |
948 | return ret; | |
949 | } | |
950 | ||
951 | int wl1271_plt_stop(struct wl1271 *wl) | |
952 | { | |
953 | int ret; | |
8c7f4f31 | 954 | |
4ae3fa87 JO |
955 | mutex_lock(&wl->mutex); |
956 | ret = __wl1271_plt_stop(wl); | |
957 | mutex_unlock(&wl->mutex); | |
f5fc0f86 LC |
958 | return ret; |
959 | } | |
960 | ||
f5fc0f86 LC |
961 | static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
962 | { | |
963 | struct wl1271 *wl = hw->priv; | |
830fb67b JO |
964 | struct ieee80211_conf *conf = &hw->conf; |
965 | struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb); | |
966 | struct ieee80211_sta *sta = txinfo->control.sta; | |
967 | unsigned long flags; | |
6742f554 | 968 | int q; |
f5fc0f86 | 969 | |
18357850 SL |
970 | /* |
971 | * peek into the rates configured in the STA entry. | |
972 | * The rates set after connection stage, The first block only BG sets: | |
973 | * the compare is for bit 0-16 of sta_rate_set. The second block add | |
974 | * HT rates in case of HT supported. | |
975 | */ | |
830fb67b | 976 | spin_lock_irqsave(&wl->wl_lock, flags); |
18357850 SL |
977 | if (sta && |
978 | (sta->supp_rates[conf->channel->band] != | |
c6c8a65d AN |
979 | (wl->sta_rate_set & HW_BG_RATES_MASK)) && |
980 | wl->bss_type != BSS_TYPE_AP_BSS) { | |
830fb67b JO |
981 | wl->sta_rate_set = sta->supp_rates[conf->channel->band]; |
982 | set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags); | |
983 | } | |
18357850 | 984 | |
00d20100 | 985 | #ifdef CONFIG_WL12XX_HT |
18357850 SL |
986 | if (sta && |
987 | sta->ht_cap.ht_supported && | |
988 | ((wl->sta_rate_set >> HW_HT_RATES_OFFSET) != | |
989 | sta->ht_cap.mcs.rx_mask[0])) { | |
990 | /* Clean MCS bits before setting them */ | |
991 | wl->sta_rate_set &= HW_BG_RATES_MASK; | |
992 | wl->sta_rate_set |= | |
993 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET); | |
994 | set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags); | |
995 | } | |
996 | #endif | |
6742f554 | 997 | wl->tx_queue_count++; |
830fb67b JO |
998 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
999 | ||
1000 | /* queue the packet */ | |
6742f554 JO |
1001 | q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
1002 | skb_queue_tail(&wl->tx_queue[q], skb); | |
f5fc0f86 LC |
1003 | |
1004 | /* | |
1005 | * The chip specific setup must run before the first TX packet - | |
1006 | * before that, the tx_work will not be initialized! | |
1007 | */ | |
1008 | ||
a522550a IY |
1009 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) |
1010 | ieee80211_queue_work(wl->hw, &wl->tx_work); | |
f5fc0f86 LC |
1011 | |
1012 | /* | |
1013 | * The workqueue is slow to process the tx_queue and we need stop | |
1014 | * the queue here, otherwise the queue will get too long. | |
1015 | */ | |
6742f554 | 1016 | if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) { |
06f7bc7d | 1017 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues"); |
f5fc0f86 | 1018 | |
06f7bc7d JO |
1019 | spin_lock_irqsave(&wl->wl_lock, flags); |
1020 | ieee80211_stop_queues(wl->hw); | |
71449f8d | 1021 | set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags); |
06f7bc7d | 1022 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
f5fc0f86 LC |
1023 | } |
1024 | ||
1025 | return NETDEV_TX_OK; | |
1026 | } | |
1027 | ||
c2c192ac JO |
1028 | static struct notifier_block wl1271_dev_notifier = { |
1029 | .notifier_call = wl1271_dev_notify, | |
1030 | }; | |
1031 | ||
f5fc0f86 | 1032 | static int wl1271_op_start(struct ieee80211_hw *hw) |
1b72aecd JO |
1033 | { |
1034 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); | |
1035 | ||
1036 | /* | |
1037 | * We have to delay the booting of the hardware because | |
1038 | * we need to know the local MAC address before downloading and | |
1039 | * initializing the firmware. The MAC address cannot be changed | |
1040 | * after boot, and without the proper MAC address, the firmware | |
1041 | * will not function properly. | |
1042 | * | |
1043 | * The MAC address is first known when the corresponding interface | |
1044 | * is added. That is where we will initialize the hardware. | |
166d504e AN |
1045 | * |
1046 | * In addition, we currently have different firmwares for AP and managed | |
1047 | * operation. We will know which to boot according to interface type. | |
1b72aecd JO |
1048 | */ |
1049 | ||
1050 | return 0; | |
1051 | } | |
1052 | ||
1053 | static void wl1271_op_stop(struct ieee80211_hw *hw) | |
1054 | { | |
1055 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); | |
1056 | } | |
1057 | ||
1058 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, | |
1059 | struct ieee80211_vif *vif) | |
f5fc0f86 LC |
1060 | { |
1061 | struct wl1271 *wl = hw->priv; | |
ac01e948 | 1062 | struct wiphy *wiphy = hw->wiphy; |
9ccd9217 | 1063 | int retries = WL1271_BOOT_RETRIES; |
f5fc0f86 | 1064 | int ret = 0; |
71125abd | 1065 | bool booted = false; |
f5fc0f86 | 1066 | |
1b72aecd JO |
1067 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
1068 | vif->type, vif->addr); | |
f5fc0f86 LC |
1069 | |
1070 | mutex_lock(&wl->mutex); | |
1b72aecd | 1071 | if (wl->vif) { |
71125abd EP |
1072 | wl1271_debug(DEBUG_MAC80211, |
1073 | "multiple vifs are not supported yet"); | |
1b72aecd JO |
1074 | ret = -EBUSY; |
1075 | goto out; | |
1076 | } | |
1077 | ||
1b72aecd JO |
1078 | switch (vif->type) { |
1079 | case NL80211_IFTYPE_STATION: | |
1080 | wl->bss_type = BSS_TYPE_STA_BSS; | |
5da11dcd | 1081 | wl->set_bss_type = BSS_TYPE_STA_BSS; |
1b72aecd JO |
1082 | break; |
1083 | case NL80211_IFTYPE_ADHOC: | |
1084 | wl->bss_type = BSS_TYPE_IBSS; | |
5da11dcd | 1085 | wl->set_bss_type = BSS_TYPE_STA_BSS; |
1b72aecd | 1086 | break; |
038d925b AN |
1087 | case NL80211_IFTYPE_AP: |
1088 | wl->bss_type = BSS_TYPE_AP_BSS; | |
1089 | break; | |
1b72aecd JO |
1090 | default: |
1091 | ret = -EOPNOTSUPP; | |
1092 | goto out; | |
1093 | } | |
1094 | ||
1095 | memcpy(wl->mac_addr, vif->addr, ETH_ALEN); | |
f5fc0f86 LC |
1096 | |
1097 | if (wl->state != WL1271_STATE_OFF) { | |
1098 | wl1271_error("cannot start because not in off state: %d", | |
1099 | wl->state); | |
1100 | ret = -EBUSY; | |
1101 | goto out; | |
1102 | } | |
1103 | ||
9ccd9217 JO |
1104 | while (retries) { |
1105 | retries--; | |
1106 | ret = wl1271_chip_wakeup(wl); | |
1107 | if (ret < 0) | |
1108 | goto power_off; | |
f5fc0f86 | 1109 | |
9ccd9217 JO |
1110 | ret = wl1271_boot(wl); |
1111 | if (ret < 0) | |
1112 | goto power_off; | |
f5fc0f86 | 1113 | |
9ccd9217 JO |
1114 | ret = wl1271_hw_init(wl); |
1115 | if (ret < 0) | |
1116 | goto irq_disable; | |
f5fc0f86 | 1117 | |
71125abd EP |
1118 | booted = true; |
1119 | break; | |
eb5b28d0 | 1120 | |
9ccd9217 JO |
1121 | irq_disable: |
1122 | wl1271_disable_interrupts(wl); | |
1123 | mutex_unlock(&wl->mutex); | |
1124 | /* Unlocking the mutex in the middle of handling is | |
1125 | inherently unsafe. In this case we deem it safe to do, | |
1126 | because we need to let any possibly pending IRQ out of | |
1127 | the system (and while we are WL1271_STATE_OFF the IRQ | |
1128 | work function will not do anything.) Also, any other | |
1129 | possible concurrent operations will fail due to the | |
1130 | current state, hence the wl1271 struct should be safe. */ | |
1131 | cancel_work_sync(&wl->irq_work); | |
1132 | mutex_lock(&wl->mutex); | |
1133 | power_off: | |
1134 | wl1271_power_off(wl); | |
1135 | } | |
eb5b28d0 | 1136 | |
71125abd EP |
1137 | if (!booted) { |
1138 | wl1271_error("firmware boot failed despite %d retries", | |
1139 | WL1271_BOOT_RETRIES); | |
1140 | goto out; | |
1141 | } | |
1142 | ||
1143 | wl->vif = vif; | |
1144 | wl->state = WL1271_STATE_ON; | |
4b7fac77 | 1145 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
71125abd EP |
1146 | |
1147 | /* update hw/fw version info in wiphy struct */ | |
1148 | wiphy->hw_version = wl->chip.id; | |
4b7fac77 | 1149 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
71125abd EP |
1150 | sizeof(wiphy->fw_version)); |
1151 | ||
fb6a6819 LC |
1152 | /* |
1153 | * Now we know if 11a is supported (info from the NVS), so disable | |
1154 | * 11a channels if not supported | |
1155 | */ | |
1156 | if (!wl->enable_11a) | |
1157 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; | |
1158 | ||
1159 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", | |
1160 | wl->enable_11a ? "" : "not "); | |
1161 | ||
eb5b28d0 | 1162 | out: |
f5fc0f86 LC |
1163 | mutex_unlock(&wl->mutex); |
1164 | ||
eb887dfd | 1165 | if (!ret) |
01c09162 | 1166 | list_add(&wl->list, &wl_list); |
01c09162 | 1167 | |
f5fc0f86 LC |
1168 | return ret; |
1169 | } | |
1170 | ||
52a2a375 | 1171 | static void __wl1271_op_remove_interface(struct wl1271 *wl) |
f5fc0f86 | 1172 | { |
f5fc0f86 LC |
1173 | int i; |
1174 | ||
1b72aecd | 1175 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
f5fc0f86 | 1176 | |
1b72aecd | 1177 | wl1271_info("down"); |
f5fc0f86 | 1178 | |
01c09162 JO |
1179 | list_del(&wl->list); |
1180 | ||
f5fc0f86 LC |
1181 | WARN_ON(wl->state != WL1271_STATE_ON); |
1182 | ||
8d2ef7bd | 1183 | /* enable dyn ps just in case (if left on due to fw crash etc) */ |
9a547bf9 | 1184 | if (wl->bss_type == BSS_TYPE_STA_BSS) |
f532be6d | 1185 | ieee80211_enable_dyn_ps(wl->vif); |
8d2ef7bd | 1186 | |
08688d6b | 1187 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { |
08688d6b LC |
1188 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
1189 | kfree(wl->scan.scanned_ch); | |
1190 | wl->scan.scanned_ch = NULL; | |
b739a42c | 1191 | wl->scan.req = NULL; |
76a029fb | 1192 | ieee80211_scan_completed(wl->hw, true); |
f5fc0f86 LC |
1193 | } |
1194 | ||
1195 | wl->state = WL1271_STATE_OFF; | |
1196 | ||
1197 | wl1271_disable_interrupts(wl); | |
1198 | ||
1199 | mutex_unlock(&wl->mutex); | |
1200 | ||
78abd320 | 1201 | cancel_delayed_work_sync(&wl->scan_complete_work); |
f5fc0f86 LC |
1202 | cancel_work_sync(&wl->irq_work); |
1203 | cancel_work_sync(&wl->tx_work); | |
90494a90 | 1204 | cancel_delayed_work_sync(&wl->pspoll_work); |
8c7f4f31 | 1205 | cancel_delayed_work_sync(&wl->elp_work); |
f5fc0f86 LC |
1206 | |
1207 | mutex_lock(&wl->mutex); | |
1208 | ||
1209 | /* let's notify MAC80211 about the remaining pending TX frames */ | |
781608c4 | 1210 | wl1271_tx_reset(wl); |
f5fc0f86 LC |
1211 | wl1271_power_off(wl); |
1212 | ||
1213 | memset(wl->bssid, 0, ETH_ALEN); | |
1214 | memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1); | |
1215 | wl->ssid_len = 0; | |
f5fc0f86 | 1216 | wl->bss_type = MAX_BSS_TYPE; |
5da11dcd | 1217 | wl->set_bss_type = MAX_BSS_TYPE; |
8a5a37a6 | 1218 | wl->band = IEEE80211_BAND_2GHZ; |
f5fc0f86 LC |
1219 | |
1220 | wl->rx_counter = 0; | |
19ad0715 | 1221 | wl->psm_entry_retry = 0; |
f5fc0f86 LC |
1222 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
1223 | wl->tx_blocks_available = 0; | |
1224 | wl->tx_results_count = 0; | |
1225 | wl->tx_packets_count = 0; | |
ac4e4ce5 | 1226 | wl->tx_security_last_seq = 0; |
04e36fc5 | 1227 | wl->tx_security_seq = 0; |
f5fc0f86 LC |
1228 | wl->time_offset = 0; |
1229 | wl->session_counter = 0; | |
830fb67b JO |
1230 | wl->rate_set = CONF_TX_RATE_MASK_BASIC; |
1231 | wl->sta_rate_set = 0; | |
1232 | wl->flags = 0; | |
1b72aecd | 1233 | wl->vif = NULL; |
14b228a0 | 1234 | wl->filters = 0; |
7f179b46 | 1235 | wl1271_free_ap_keys(wl); |
f84f7d78 | 1236 | memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map)); |
d6e19d13 | 1237 | |
f5fc0f86 LC |
1238 | for (i = 0; i < NUM_TX_QUEUES; i++) |
1239 | wl->tx_blocks_freed[i] = 0; | |
1240 | ||
1241 | wl1271_debugfs_reset(wl); | |
bd9dc49c JO |
1242 | |
1243 | kfree(wl->fw_status); | |
1244 | wl->fw_status = NULL; | |
1245 | kfree(wl->tx_res_if); | |
1246 | wl->tx_res_if = NULL; | |
1247 | kfree(wl->target_mem_map); | |
1248 | wl->target_mem_map = NULL; | |
52a2a375 | 1249 | } |
bd9dc49c | 1250 | |
52a2a375 JO |
1251 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
1252 | struct ieee80211_vif *vif) | |
1253 | { | |
1254 | struct wl1271 *wl = hw->priv; | |
1255 | ||
1256 | mutex_lock(&wl->mutex); | |
67353299 JO |
1257 | /* |
1258 | * wl->vif can be null here if someone shuts down the interface | |
1259 | * just when hardware recovery has been started. | |
1260 | */ | |
1261 | if (wl->vif) { | |
1262 | WARN_ON(wl->vif != vif); | |
1263 | __wl1271_op_remove_interface(wl); | |
1264 | } | |
52b0e7a6 | 1265 | |
67353299 | 1266 | mutex_unlock(&wl->mutex); |
52b0e7a6 | 1267 | cancel_work_sync(&wl->recovery_work); |
f5fc0f86 LC |
1268 | } |
1269 | ||
14b228a0 JO |
1270 | static void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters) |
1271 | { | |
ae113b57 | 1272 | wl1271_set_default_filters(wl); |
14b228a0 JO |
1273 | |
1274 | /* combine requested filters with current filter config */ | |
1275 | filters = wl->filters | filters; | |
1276 | ||
1277 | wl1271_debug(DEBUG_FILTERS, "RX filters set: "); | |
1278 | ||
1279 | if (filters & FIF_PROMISC_IN_BSS) { | |
1280 | wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS"); | |
1281 | wl->rx_config &= ~CFG_UNI_FILTER_EN; | |
1282 | wl->rx_config |= CFG_BSSID_FILTER_EN; | |
1283 | } | |
1284 | if (filters & FIF_BCN_PRBRESP_PROMISC) { | |
1285 | wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC"); | |
1286 | wl->rx_config &= ~CFG_BSSID_FILTER_EN; | |
1287 | wl->rx_config &= ~CFG_SSID_FILTER_EN; | |
1288 | } | |
1289 | if (filters & FIF_OTHER_BSS) { | |
1290 | wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS"); | |
1291 | wl->rx_config &= ~CFG_BSSID_FILTER_EN; | |
1292 | } | |
1293 | if (filters & FIF_CONTROL) { | |
1294 | wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL"); | |
1295 | wl->rx_filter |= CFG_RX_CTL_EN; | |
1296 | } | |
1297 | if (filters & FIF_FCSFAIL) { | |
1298 | wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL"); | |
1299 | wl->rx_filter |= CFG_RX_FCS_ERROR; | |
1300 | } | |
1301 | } | |
1302 | ||
82429d32 | 1303 | static int wl1271_dummy_join(struct wl1271 *wl) |
c7f43e45 | 1304 | { |
e0d8bbf0 | 1305 | int ret = 0; |
c7f43e45 LC |
1306 | /* we need to use a dummy BSSID for now */ |
1307 | static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde, | |
1308 | 0xad, 0xbe, 0xef }; | |
1309 | ||
c7f43e45 LC |
1310 | memcpy(wl->bssid, dummy_bssid, ETH_ALEN); |
1311 | ||
14b228a0 JO |
1312 | /* pass through frames from all BSS */ |
1313 | wl1271_configure_filters(wl, FIF_OTHER_BSS); | |
1314 | ||
5da11dcd | 1315 | ret = wl1271_cmd_join(wl, wl->set_bss_type); |
c7f43e45 LC |
1316 | if (ret < 0) |
1317 | goto out; | |
1318 | ||
71449f8d | 1319 | set_bit(WL1271_FLAG_JOINED, &wl->flags); |
c7f43e45 LC |
1320 | |
1321 | out: | |
1322 | return ret; | |
1323 | } | |
1324 | ||
69e5434c | 1325 | static int wl1271_join(struct wl1271 *wl, bool set_assoc) |
82429d32 JO |
1326 | { |
1327 | int ret; | |
1328 | ||
69e5434c JO |
1329 | /* |
1330 | * One of the side effects of the JOIN command is that is clears | |
1331 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated | |
1332 | * to a WPA/WPA2 access point will therefore kill the data-path. | |
1333 | * Currently there is no supported scenario for JOIN during | |
1334 | * association - if it becomes a supported scenario, the WPA/WPA2 keys | |
1335 | * must be handled somehow. | |
1336 | * | |
1337 | */ | |
1338 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | |
1339 | wl1271_info("JOIN while associated."); | |
1340 | ||
1341 | if (set_assoc) | |
1342 | set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags); | |
1343 | ||
82429d32 JO |
1344 | ret = wl1271_cmd_join(wl, wl->set_bss_type); |
1345 | if (ret < 0) | |
1346 | goto out; | |
1347 | ||
1348 | set_bit(WL1271_FLAG_JOINED, &wl->flags); | |
1349 | ||
1350 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | |
1351 | goto out; | |
1352 | ||
1353 | /* | |
1354 | * The join command disable the keep-alive mode, shut down its process, | |
1355 | * and also clear the template config, so we need to reset it all after | |
1356 | * the join. The acx_aid starts the keep-alive process, and the order | |
1357 | * of the commands below is relevant. | |
1358 | */ | |
1359 | ret = wl1271_acx_keep_alive_mode(wl, true); | |
1360 | if (ret < 0) | |
1361 | goto out; | |
1362 | ||
1363 | ret = wl1271_acx_aid(wl, wl->aid); | |
1364 | if (ret < 0) | |
1365 | goto out; | |
1366 | ||
1367 | ret = wl1271_cmd_build_klv_null_data(wl); | |
1368 | if (ret < 0) | |
1369 | goto out; | |
1370 | ||
1371 | ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA, | |
1372 | ACX_KEEP_ALIVE_TPL_VALID); | |
1373 | if (ret < 0) | |
1374 | goto out; | |
1375 | ||
1376 | out: | |
1377 | return ret; | |
1378 | } | |
1379 | ||
1380 | static int wl1271_unjoin(struct wl1271 *wl) | |
c7f43e45 LC |
1381 | { |
1382 | int ret; | |
1383 | ||
1384 | /* to stop listening to a channel, we disconnect */ | |
1385 | ret = wl1271_cmd_disconnect(wl); | |
1386 | if (ret < 0) | |
1387 | goto out; | |
1388 | ||
71449f8d | 1389 | clear_bit(WL1271_FLAG_JOINED, &wl->flags); |
c7f43e45 | 1390 | memset(wl->bssid, 0, ETH_ALEN); |
14b228a0 JO |
1391 | |
1392 | /* stop filterting packets based on bssid */ | |
1393 | wl1271_configure_filters(wl, FIF_OTHER_BSS); | |
c7f43e45 LC |
1394 | |
1395 | out: | |
1396 | return ret; | |
1397 | } | |
1398 | ||
ebba60c6 JO |
1399 | static void wl1271_set_band_rate(struct wl1271 *wl) |
1400 | { | |
1401 | if (wl->band == IEEE80211_BAND_2GHZ) | |
1402 | wl->basic_rate_set = wl->conf.tx.basic_rate; | |
1403 | else | |
1404 | wl->basic_rate_set = wl->conf.tx.basic_rate_5; | |
1405 | } | |
1406 | ||
bee0ffec | 1407 | static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle) |
0d58cbff JO |
1408 | { |
1409 | int ret; | |
1410 | ||
1411 | if (idle) { | |
1412 | if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) { | |
1413 | ret = wl1271_unjoin(wl); | |
1414 | if (ret < 0) | |
1415 | goto out; | |
1416 | } | |
e0fe371b | 1417 | wl->rate_set = wl1271_tx_min_rate_get(wl); |
0d58cbff | 1418 | wl->sta_rate_set = 0; |
79b223f4 | 1419 | ret = wl1271_acx_sta_rate_policies(wl); |
0d58cbff JO |
1420 | if (ret < 0) |
1421 | goto out; | |
1422 | ret = wl1271_acx_keep_alive_config( | |
1423 | wl, CMD_TEMPL_KLV_IDX_NULL_DATA, | |
1424 | ACX_KEEP_ALIVE_TPL_INVALID); | |
1425 | if (ret < 0) | |
1426 | goto out; | |
1427 | set_bit(WL1271_FLAG_IDLE, &wl->flags); | |
1428 | } else { | |
1429 | /* increment the session counter */ | |
1430 | wl->session_counter++; | |
1431 | if (wl->session_counter >= SESSION_COUNTER_MAX) | |
1432 | wl->session_counter = 0; | |
1433 | ret = wl1271_dummy_join(wl); | |
1434 | if (ret < 0) | |
1435 | goto out; | |
1436 | clear_bit(WL1271_FLAG_IDLE, &wl->flags); | |
1437 | } | |
1438 | ||
1439 | out: | |
1440 | return ret; | |
1441 | } | |
1442 | ||
f5fc0f86 LC |
1443 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) |
1444 | { | |
1445 | struct wl1271 *wl = hw->priv; | |
1446 | struct ieee80211_conf *conf = &hw->conf; | |
1447 | int channel, ret = 0; | |
bee0ffec | 1448 | bool is_ap; |
f5fc0f86 LC |
1449 | |
1450 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); | |
1451 | ||
bee0ffec AN |
1452 | wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s" |
1453 | " changed 0x%x", | |
f5fc0f86 LC |
1454 | channel, |
1455 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", | |
c7f43e45 | 1456 | conf->power_level, |
bee0ffec AN |
1457 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", |
1458 | changed); | |
f5fc0f86 | 1459 | |
781608c4 JO |
1460 | /* |
1461 | * mac80211 will go to idle nearly immediately after transmitting some | |
1462 | * frames, such as the deauth. To make sure those frames reach the air, | |
1463 | * wait here until the TX queue is fully flushed. | |
1464 | */ | |
1465 | if ((changed & IEEE80211_CONF_CHANGE_IDLE) && | |
1466 | (conf->flags & IEEE80211_CONF_IDLE)) | |
1467 | wl1271_tx_flush(wl); | |
1468 | ||
f5fc0f86 LC |
1469 | mutex_lock(&wl->mutex); |
1470 | ||
f8d9802f JO |
1471 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
1472 | ret = -EAGAIN; | |
2c10bb9c | 1473 | goto out; |
f8d9802f | 1474 | } |
8a5a37a6 | 1475 | |
bee0ffec AN |
1476 | is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); |
1477 | ||
f5fc0f86 LC |
1478 | ret = wl1271_ps_elp_wakeup(wl, false); |
1479 | if (ret < 0) | |
1480 | goto out; | |
1481 | ||
ebba60c6 | 1482 | /* if the channel changes while joined, join again */ |
69e5434c JO |
1483 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && |
1484 | ((wl->band != conf->channel->band) || | |
1485 | (wl->channel != channel))) { | |
ebba60c6 JO |
1486 | wl->band = conf->channel->band; |
1487 | wl->channel = channel; | |
1488 | ||
bee0ffec AN |
1489 | if (!is_ap) { |
1490 | /* | |
1491 | * FIXME: the mac80211 should really provide a fixed | |
1492 | * rate to use here. for now, just use the smallest | |
1493 | * possible rate for the band as a fixed rate for | |
1494 | * association frames and other control messages. | |
1495 | */ | |
1496 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | |
1497 | wl1271_set_band_rate(wl); | |
1498 | ||
1499 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | |
1500 | ret = wl1271_acx_sta_rate_policies(wl); | |
ebba60c6 | 1501 | if (ret < 0) |
bee0ffec | 1502 | wl1271_warning("rate policy for channel " |
ebba60c6 | 1503 | "failed %d", ret); |
bee0ffec AN |
1504 | |
1505 | if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) { | |
1506 | ret = wl1271_join(wl, false); | |
1507 | if (ret < 0) | |
1508 | wl1271_warning("cmd join on channel " | |
1509 | "failed %d", ret); | |
1510 | } | |
ebba60c6 JO |
1511 | } |
1512 | } | |
1513 | ||
bee0ffec AN |
1514 | if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) { |
1515 | ret = wl1271_sta_handle_idle(wl, | |
1516 | conf->flags & IEEE80211_CONF_IDLE); | |
0d58cbff JO |
1517 | if (ret < 0) |
1518 | wl1271_warning("idle mode change failed %d", ret); | |
f5fc0f86 LC |
1519 | } |
1520 | ||
90494a90 JO |
1521 | /* |
1522 | * if mac80211 changes the PSM mode, make sure the mode is not | |
1523 | * incorrectly changed after the pspoll failure active window. | |
1524 | */ | |
1525 | if (changed & IEEE80211_CONF_CHANGE_PS) | |
1526 | clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); | |
1527 | ||
71449f8d JO |
1528 | if (conf->flags & IEEE80211_CONF_PS && |
1529 | !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { | |
1530 | set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); | |
f5fc0f86 LC |
1531 | |
1532 | /* | |
1533 | * We enter PSM only if we're already associated. | |
1534 | * If we're not, we'll enter it when joining an SSID, | |
1535 | * through the bss_info_changed() hook. | |
1536 | */ | |
830fb67b | 1537 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { |
18f8d468 | 1538 | wl1271_debug(DEBUG_PSM, "psm enabled"); |
d8c42c0c | 1539 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, |
8eab7b47 | 1540 | wl->basic_rate, true); |
af5e084b | 1541 | } |
f5fc0f86 | 1542 | } else if (!(conf->flags & IEEE80211_CONF_PS) && |
71449f8d | 1543 | test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { |
18f8d468 | 1544 | wl1271_debug(DEBUG_PSM, "psm disabled"); |
f5fc0f86 | 1545 | |
71449f8d | 1546 | clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); |
f5fc0f86 | 1547 | |
71449f8d | 1548 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) |
d8c42c0c | 1549 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, |
8eab7b47 | 1550 | wl->basic_rate, true); |
f5fc0f86 LC |
1551 | } |
1552 | ||
1553 | if (conf->power_level != wl->power_level) { | |
1554 | ret = wl1271_acx_tx_power(wl, conf->power_level); | |
1555 | if (ret < 0) | |
c6317a54 | 1556 | goto out_sleep; |
f5fc0f86 LC |
1557 | |
1558 | wl->power_level = conf->power_level; | |
1559 | } | |
1560 | ||
1561 | out_sleep: | |
1562 | wl1271_ps_elp_sleep(wl); | |
1563 | ||
1564 | out: | |
1565 | mutex_unlock(&wl->mutex); | |
1566 | ||
1567 | return ret; | |
1568 | } | |
1569 | ||
b54853f1 JO |
1570 | struct wl1271_filter_params { |
1571 | bool enabled; | |
1572 | int mc_list_length; | |
1573 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; | |
1574 | }; | |
1575 | ||
22bedad3 JP |
1576 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
1577 | struct netdev_hw_addr_list *mc_list) | |
c87dec9f | 1578 | { |
c87dec9f | 1579 | struct wl1271_filter_params *fp; |
22bedad3 | 1580 | struct netdev_hw_addr *ha; |
2c10bb9c | 1581 | struct wl1271 *wl = hw->priv; |
c87dec9f | 1582 | |
2c10bb9c SD |
1583 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
1584 | return 0; | |
c87dec9f | 1585 | |
74441130 | 1586 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
c87dec9f JO |
1587 | if (!fp) { |
1588 | wl1271_error("Out of memory setting filters."); | |
1589 | return 0; | |
1590 | } | |
1591 | ||
1592 | /* update multicast filtering parameters */ | |
c87dec9f | 1593 | fp->mc_list_length = 0; |
22bedad3 JP |
1594 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
1595 | fp->enabled = false; | |
1596 | } else { | |
1597 | fp->enabled = true; | |
1598 | netdev_hw_addr_list_for_each(ha, mc_list) { | |
c87dec9f | 1599 | memcpy(fp->mc_list[fp->mc_list_length], |
22bedad3 | 1600 | ha->addr, ETH_ALEN); |
c87dec9f | 1601 | fp->mc_list_length++; |
22bedad3 | 1602 | } |
c87dec9f JO |
1603 | } |
1604 | ||
b54853f1 | 1605 | return (u64)(unsigned long)fp; |
c87dec9f | 1606 | } |
f5fc0f86 | 1607 | |
b54853f1 JO |
1608 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
1609 | FIF_ALLMULTI | \ | |
1610 | FIF_FCSFAIL | \ | |
1611 | FIF_BCN_PRBRESP_PROMISC | \ | |
1612 | FIF_CONTROL | \ | |
1613 | FIF_OTHER_BSS) | |
1614 | ||
f5fc0f86 LC |
1615 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
1616 | unsigned int changed, | |
c87dec9f | 1617 | unsigned int *total, u64 multicast) |
f5fc0f86 | 1618 | { |
b54853f1 | 1619 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
f5fc0f86 | 1620 | struct wl1271 *wl = hw->priv; |
b54853f1 | 1621 | int ret; |
f5fc0f86 | 1622 | |
7d057869 AN |
1623 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
1624 | " total %x", changed, *total); | |
f5fc0f86 | 1625 | |
b54853f1 JO |
1626 | mutex_lock(&wl->mutex); |
1627 | ||
2c10bb9c SD |
1628 | *total &= WL1271_SUPPORTED_FILTERS; |
1629 | changed &= WL1271_SUPPORTED_FILTERS; | |
1630 | ||
1631 | if (unlikely(wl->state == WL1271_STATE_OFF)) | |
b54853f1 JO |
1632 | goto out; |
1633 | ||
1634 | ret = wl1271_ps_elp_wakeup(wl, false); | |
1635 | if (ret < 0) | |
1636 | goto out; | |
1637 | ||
7d057869 AN |
1638 | if (wl->bss_type != BSS_TYPE_AP_BSS) { |
1639 | if (*total & FIF_ALLMULTI) | |
1640 | ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0); | |
1641 | else if (fp) | |
1642 | ret = wl1271_acx_group_address_tbl(wl, fp->enabled, | |
1643 | fp->mc_list, | |
1644 | fp->mc_list_length); | |
1645 | if (ret < 0) | |
1646 | goto out_sleep; | |
1647 | } | |
f5fc0f86 | 1648 | |
b54853f1 JO |
1649 | /* determine, whether supported filter values have changed */ |
1650 | if (changed == 0) | |
1651 | goto out_sleep; | |
c87dec9f | 1652 | |
14b228a0 JO |
1653 | /* configure filters */ |
1654 | wl->filters = *total; | |
1655 | wl1271_configure_filters(wl, 0); | |
1656 | ||
b54853f1 JO |
1657 | /* apply configured filters */ |
1658 | ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter); | |
1659 | if (ret < 0) | |
1660 | goto out_sleep; | |
1661 | ||
1662 | out_sleep: | |
1663 | wl1271_ps_elp_sleep(wl); | |
1664 | ||
1665 | out: | |
1666 | mutex_unlock(&wl->mutex); | |
14b228a0 | 1667 | kfree(fp); |
f5fc0f86 LC |
1668 | } |
1669 | ||
7f179b46 AN |
1670 | static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type, |
1671 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, | |
1672 | u16 tx_seq_16) | |
1673 | { | |
1674 | struct wl1271_ap_key *ap_key; | |
1675 | int i; | |
1676 | ||
1677 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); | |
1678 | ||
1679 | if (key_size > MAX_KEY_SIZE) | |
1680 | return -EINVAL; | |
1681 | ||
1682 | /* | |
1683 | * Find next free entry in ap_keys. Also check we are not replacing | |
1684 | * an existing key. | |
1685 | */ | |
1686 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
1687 | if (wl->recorded_ap_keys[i] == NULL) | |
1688 | break; | |
1689 | ||
1690 | if (wl->recorded_ap_keys[i]->id == id) { | |
1691 | wl1271_warning("trying to record key replacement"); | |
1692 | return -EINVAL; | |
1693 | } | |
1694 | } | |
1695 | ||
1696 | if (i == MAX_NUM_KEYS) | |
1697 | return -EBUSY; | |
1698 | ||
1699 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); | |
1700 | if (!ap_key) | |
1701 | return -ENOMEM; | |
1702 | ||
1703 | ap_key->id = id; | |
1704 | ap_key->key_type = key_type; | |
1705 | ap_key->key_size = key_size; | |
1706 | memcpy(ap_key->key, key, key_size); | |
1707 | ap_key->hlid = hlid; | |
1708 | ap_key->tx_seq_32 = tx_seq_32; | |
1709 | ap_key->tx_seq_16 = tx_seq_16; | |
1710 | ||
1711 | wl->recorded_ap_keys[i] = ap_key; | |
1712 | return 0; | |
1713 | } | |
1714 | ||
1715 | static void wl1271_free_ap_keys(struct wl1271 *wl) | |
1716 | { | |
1717 | int i; | |
1718 | ||
1719 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
1720 | kfree(wl->recorded_ap_keys[i]); | |
1721 | wl->recorded_ap_keys[i] = NULL; | |
1722 | } | |
1723 | } | |
1724 | ||
1725 | static int wl1271_ap_init_hwenc(struct wl1271 *wl) | |
1726 | { | |
1727 | int i, ret = 0; | |
1728 | struct wl1271_ap_key *key; | |
1729 | bool wep_key_added = false; | |
1730 | ||
1731 | for (i = 0; i < MAX_NUM_KEYS; i++) { | |
1732 | if (wl->recorded_ap_keys[i] == NULL) | |
1733 | break; | |
1734 | ||
1735 | key = wl->recorded_ap_keys[i]; | |
1736 | ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE, | |
1737 | key->id, key->key_type, | |
1738 | key->key_size, key->key, | |
1739 | key->hlid, key->tx_seq_32, | |
1740 | key->tx_seq_16); | |
1741 | if (ret < 0) | |
1742 | goto out; | |
1743 | ||
1744 | if (key->key_type == KEY_WEP) | |
1745 | wep_key_added = true; | |
1746 | } | |
1747 | ||
1748 | if (wep_key_added) { | |
1749 | ret = wl1271_cmd_set_ap_default_wep_key(wl, wl->default_key); | |
1750 | if (ret < 0) | |
1751 | goto out; | |
1752 | } | |
1753 | ||
1754 | out: | |
1755 | wl1271_free_ap_keys(wl); | |
1756 | return ret; | |
1757 | } | |
1758 | ||
1759 | static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | |
1760 | u8 key_size, const u8 *key, u32 tx_seq_32, | |
1761 | u16 tx_seq_16, struct ieee80211_sta *sta) | |
1762 | { | |
1763 | int ret; | |
1764 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | |
1765 | ||
1766 | if (is_ap) { | |
1767 | struct wl1271_station *wl_sta; | |
1768 | u8 hlid; | |
1769 | ||
1770 | if (sta) { | |
1771 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
1772 | hlid = wl_sta->hlid; | |
1773 | } else { | |
1774 | hlid = WL1271_AP_BROADCAST_HLID; | |
1775 | } | |
1776 | ||
1777 | if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | |
1778 | /* | |
1779 | * We do not support removing keys after AP shutdown. | |
1780 | * Pretend we do to make mac80211 happy. | |
1781 | */ | |
1782 | if (action != KEY_ADD_OR_REPLACE) | |
1783 | return 0; | |
1784 | ||
1785 | ret = wl1271_record_ap_key(wl, id, | |
1786 | key_type, key_size, | |
1787 | key, hlid, tx_seq_32, | |
1788 | tx_seq_16); | |
1789 | } else { | |
1790 | ret = wl1271_cmd_set_ap_key(wl, action, | |
1791 | id, key_type, key_size, | |
1792 | key, hlid, tx_seq_32, | |
1793 | tx_seq_16); | |
1794 | } | |
1795 | ||
1796 | if (ret < 0) | |
1797 | return ret; | |
1798 | } else { | |
1799 | const u8 *addr; | |
1800 | static const u8 bcast_addr[ETH_ALEN] = { | |
1801 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
1802 | }; | |
1803 | ||
1804 | addr = sta ? sta->addr : bcast_addr; | |
1805 | ||
1806 | if (is_zero_ether_addr(addr)) { | |
1807 | /* We dont support TX only encryption */ | |
1808 | return -EOPNOTSUPP; | |
1809 | } | |
1810 | ||
1811 | /* The wl1271 does not allow to remove unicast keys - they | |
1812 | will be cleared automatically on next CMD_JOIN. Ignore the | |
1813 | request silently, as we dont want the mac80211 to emit | |
1814 | an error message. */ | |
1815 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) | |
1816 | return 0; | |
1817 | ||
1818 | ret = wl1271_cmd_set_sta_key(wl, action, | |
1819 | id, key_type, key_size, | |
1820 | key, addr, tx_seq_32, | |
1821 | tx_seq_16); | |
1822 | if (ret < 0) | |
1823 | return ret; | |
1824 | ||
1825 | /* the default WEP key needs to be configured at least once */ | |
1826 | if (key_type == KEY_WEP) { | |
1827 | ret = wl1271_cmd_set_sta_default_wep_key(wl, | |
1828 | wl->default_key); | |
1829 | if (ret < 0) | |
1830 | return ret; | |
1831 | } | |
1832 | } | |
1833 | ||
1834 | return 0; | |
1835 | } | |
1836 | ||
f5fc0f86 LC |
1837 | static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
1838 | struct ieee80211_vif *vif, | |
1839 | struct ieee80211_sta *sta, | |
1840 | struct ieee80211_key_conf *key_conf) | |
1841 | { | |
1842 | struct wl1271 *wl = hw->priv; | |
f5fc0f86 | 1843 | int ret; |
ac4e4ce5 JO |
1844 | u32 tx_seq_32 = 0; |
1845 | u16 tx_seq_16 = 0; | |
f5fc0f86 LC |
1846 | u8 key_type; |
1847 | ||
f5fc0f86 LC |
1848 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
1849 | ||
7f179b46 | 1850 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
f5fc0f86 | 1851 | wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", |
97359d12 | 1852 | key_conf->cipher, key_conf->keyidx, |
f5fc0f86 LC |
1853 | key_conf->keylen, key_conf->flags); |
1854 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); | |
1855 | ||
f5fc0f86 LC |
1856 | mutex_lock(&wl->mutex); |
1857 | ||
f8d9802f JO |
1858 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
1859 | ret = -EAGAIN; | |
1860 | goto out_unlock; | |
1861 | } | |
1862 | ||
f5fc0f86 LC |
1863 | ret = wl1271_ps_elp_wakeup(wl, false); |
1864 | if (ret < 0) | |
1865 | goto out_unlock; | |
1866 | ||
97359d12 JB |
1867 | switch (key_conf->cipher) { |
1868 | case WLAN_CIPHER_SUITE_WEP40: | |
1869 | case WLAN_CIPHER_SUITE_WEP104: | |
f5fc0f86 LC |
1870 | key_type = KEY_WEP; |
1871 | ||
1872 | key_conf->hw_key_idx = key_conf->keyidx; | |
1873 | break; | |
97359d12 | 1874 | case WLAN_CIPHER_SUITE_TKIP: |
f5fc0f86 LC |
1875 | key_type = KEY_TKIP; |
1876 | ||
1877 | key_conf->hw_key_idx = key_conf->keyidx; | |
04e36fc5 JO |
1878 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); |
1879 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | |
f5fc0f86 | 1880 | break; |
97359d12 | 1881 | case WLAN_CIPHER_SUITE_CCMP: |
f5fc0f86 LC |
1882 | key_type = KEY_AES; |
1883 | ||
1884 | key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | |
04e36fc5 JO |
1885 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); |
1886 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | |
f5fc0f86 | 1887 | break; |
7a55724e JO |
1888 | case WL1271_CIPHER_SUITE_GEM: |
1889 | key_type = KEY_GEM; | |
1890 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); | |
1891 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | |
1892 | break; | |
f5fc0f86 | 1893 | default: |
97359d12 | 1894 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
f5fc0f86 LC |
1895 | |
1896 | ret = -EOPNOTSUPP; | |
1897 | goto out_sleep; | |
1898 | } | |
1899 | ||
1900 | switch (cmd) { | |
1901 | case SET_KEY: | |
7f179b46 AN |
1902 | ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE, |
1903 | key_conf->keyidx, key_type, | |
1904 | key_conf->keylen, key_conf->key, | |
1905 | tx_seq_32, tx_seq_16, sta); | |
f5fc0f86 LC |
1906 | if (ret < 0) { |
1907 | wl1271_error("Could not add or replace key"); | |
1908 | goto out_sleep; | |
1909 | } | |
1910 | break; | |
1911 | ||
1912 | case DISABLE_KEY: | |
7f179b46 AN |
1913 | ret = wl1271_set_key(wl, KEY_REMOVE, |
1914 | key_conf->keyidx, key_type, | |
1915 | key_conf->keylen, key_conf->key, | |
1916 | 0, 0, sta); | |
f5fc0f86 LC |
1917 | if (ret < 0) { |
1918 | wl1271_error("Could not remove key"); | |
1919 | goto out_sleep; | |
1920 | } | |
1921 | break; | |
1922 | ||
1923 | default: | |
1924 | wl1271_error("Unsupported key cmd 0x%x", cmd); | |
1925 | ret = -EOPNOTSUPP; | |
f5fc0f86 LC |
1926 | break; |
1927 | } | |
1928 | ||
1929 | out_sleep: | |
1930 | wl1271_ps_elp_sleep(wl); | |
1931 | ||
1932 | out_unlock: | |
1933 | mutex_unlock(&wl->mutex); | |
1934 | ||
f5fc0f86 LC |
1935 | return ret; |
1936 | } | |
1937 | ||
1938 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, | |
a060bbfe | 1939 | struct ieee80211_vif *vif, |
f5fc0f86 LC |
1940 | struct cfg80211_scan_request *req) |
1941 | { | |
1942 | struct wl1271 *wl = hw->priv; | |
1943 | int ret; | |
1944 | u8 *ssid = NULL; | |
abb0b3bf | 1945 | size_t len = 0; |
f5fc0f86 LC |
1946 | |
1947 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); | |
1948 | ||
1949 | if (req->n_ssids) { | |
1950 | ssid = req->ssids[0].ssid; | |
abb0b3bf | 1951 | len = req->ssids[0].ssid_len; |
f5fc0f86 LC |
1952 | } |
1953 | ||
1954 | mutex_lock(&wl->mutex); | |
1955 | ||
b739a42c JO |
1956 | if (wl->state == WL1271_STATE_OFF) { |
1957 | /* | |
1958 | * We cannot return -EBUSY here because cfg80211 will expect | |
1959 | * a call to ieee80211_scan_completed if we do - in this case | |
1960 | * there won't be any call. | |
1961 | */ | |
1962 | ret = -EAGAIN; | |
1963 | goto out; | |
1964 | } | |
1965 | ||
f5fc0f86 LC |
1966 | ret = wl1271_ps_elp_wakeup(wl, false); |
1967 | if (ret < 0) | |
1968 | goto out; | |
1969 | ||
5924f89d | 1970 | ret = wl1271_scan(hw->priv, ssid, len, req); |
f5fc0f86 LC |
1971 | |
1972 | wl1271_ps_elp_sleep(wl); | |
1973 | ||
1974 | out: | |
1975 | mutex_unlock(&wl->mutex); | |
1976 | ||
1977 | return ret; | |
1978 | } | |
1979 | ||
68d069c4 AN |
1980 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
1981 | { | |
1982 | struct wl1271 *wl = hw->priv; | |
1983 | int ret = 0; | |
1984 | ||
1985 | mutex_lock(&wl->mutex); | |
1986 | ||
1987 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | |
1988 | ret = -EAGAIN; | |
1989 | goto out; | |
1990 | } | |
1991 | ||
1992 | ret = wl1271_ps_elp_wakeup(wl, false); | |
1993 | if (ret < 0) | |
1994 | goto out; | |
1995 | ||
1996 | ret = wl1271_acx_frag_threshold(wl, (u16)value); | |
1997 | if (ret < 0) | |
1998 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); | |
1999 | ||
2000 | wl1271_ps_elp_sleep(wl); | |
2001 | ||
2002 | out: | |
2003 | mutex_unlock(&wl->mutex); | |
2004 | ||
2005 | return ret; | |
2006 | } | |
2007 | ||
f5fc0f86 LC |
2008 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
2009 | { | |
2010 | struct wl1271 *wl = hw->priv; | |
aecb0565 | 2011 | int ret = 0; |
f5fc0f86 LC |
2012 | |
2013 | mutex_lock(&wl->mutex); | |
2014 | ||
f8d9802f JO |
2015 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
2016 | ret = -EAGAIN; | |
aecb0565 | 2017 | goto out; |
f8d9802f | 2018 | } |
aecb0565 | 2019 | |
f5fc0f86 LC |
2020 | ret = wl1271_ps_elp_wakeup(wl, false); |
2021 | if (ret < 0) | |
2022 | goto out; | |
2023 | ||
2024 | ret = wl1271_acx_rts_threshold(wl, (u16) value); | |
2025 | if (ret < 0) | |
2026 | wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret); | |
2027 | ||
2028 | wl1271_ps_elp_sleep(wl); | |
2029 | ||
2030 | out: | |
2031 | mutex_unlock(&wl->mutex); | |
2032 | ||
2033 | return ret; | |
2034 | } | |
2035 | ||
e78a287a | 2036 | static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb, |
2f6724b2 | 2037 | int offset) |
30240fc7 | 2038 | { |
2f6724b2 | 2039 | u8 *ptr = skb->data + offset; |
30240fc7 JO |
2040 | |
2041 | /* find the location of the ssid in the beacon */ | |
2f6724b2 | 2042 | while (ptr < skb->data + skb->len) { |
30240fc7 JO |
2043 | if (ptr[0] == WLAN_EID_SSID) { |
2044 | wl->ssid_len = ptr[1]; | |
2045 | memcpy(wl->ssid, ptr+2, wl->ssid_len); | |
e78a287a | 2046 | return 0; |
30240fc7 | 2047 | } |
2f6724b2 | 2048 | ptr += (ptr[1] + 2); |
30240fc7 | 2049 | } |
e78a287a | 2050 | |
2f6724b2 | 2051 | wl1271_error("No SSID in IEs!\n"); |
e78a287a | 2052 | return -ENOENT; |
30240fc7 JO |
2053 | } |
2054 | ||
e78a287a | 2055 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
f5fc0f86 LC |
2056 | struct ieee80211_bss_conf *bss_conf, |
2057 | u32 changed) | |
2058 | { | |
e78a287a | 2059 | int ret = 0; |
f5fc0f86 | 2060 | |
e78a287a AN |
2061 | if (changed & BSS_CHANGED_ERP_SLOT) { |
2062 | if (bss_conf->use_short_slot) | |
2063 | ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); | |
2064 | else | |
2065 | ret = wl1271_acx_slot(wl, SLOT_TIME_LONG); | |
2066 | if (ret < 0) { | |
2067 | wl1271_warning("Set slot time failed %d", ret); | |
2068 | goto out; | |
2069 | } | |
2070 | } | |
f5fc0f86 | 2071 | |
e78a287a AN |
2072 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
2073 | if (bss_conf->use_short_preamble) | |
2074 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); | |
2075 | else | |
2076 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG); | |
2077 | } | |
f5fc0f86 | 2078 | |
e78a287a AN |
2079 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
2080 | if (bss_conf->use_cts_prot) | |
2081 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE); | |
2082 | else | |
2083 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE); | |
2084 | if (ret < 0) { | |
2085 | wl1271_warning("Set ctsprotect failed %d", ret); | |
2086 | goto out; | |
2087 | } | |
2088 | } | |
f8d9802f | 2089 | |
e78a287a AN |
2090 | out: |
2091 | return ret; | |
2092 | } | |
f5fc0f86 | 2093 | |
e78a287a AN |
2094 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
2095 | struct ieee80211_vif *vif, | |
2096 | struct ieee80211_bss_conf *bss_conf, | |
2097 | u32 changed) | |
2098 | { | |
2099 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | |
2100 | int ret = 0; | |
2101 | ||
2102 | if ((changed & BSS_CHANGED_BEACON_INT)) { | |
2103 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", | |
60e84c2e JO |
2104 | bss_conf->beacon_int); |
2105 | ||
2106 | wl->beacon_int = bss_conf->beacon_int; | |
60e84c2e JO |
2107 | } |
2108 | ||
e78a287a AN |
2109 | if ((changed & BSS_CHANGED_BEACON)) { |
2110 | struct ieee80211_hdr *hdr; | |
2111 | int ieoffset = offsetof(struct ieee80211_mgmt, | |
2112 | u.beacon.variable); | |
2113 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); | |
2114 | u16 tmpl_id; | |
2115 | ||
2116 | if (!beacon) | |
2117 | goto out; | |
2118 | ||
2119 | wl1271_debug(DEBUG_MASTER, "beacon updated"); | |
2120 | ||
2121 | ret = wl1271_ssid_set(wl, beacon, ieoffset); | |
2122 | if (ret < 0) { | |
2123 | dev_kfree_skb(beacon); | |
2124 | goto out; | |
2125 | } | |
2126 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : | |
2127 | CMD_TEMPL_BEACON; | |
2128 | ret = wl1271_cmd_template_set(wl, tmpl_id, | |
2129 | beacon->data, | |
2130 | beacon->len, 0, | |
2131 | wl1271_tx_min_rate_get(wl)); | |
2132 | if (ret < 0) { | |
2133 | dev_kfree_skb(beacon); | |
2134 | goto out; | |
2135 | } | |
2136 | ||
2137 | hdr = (struct ieee80211_hdr *) beacon->data; | |
2138 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
2139 | IEEE80211_STYPE_PROBE_RESP); | |
2140 | ||
2141 | tmpl_id = is_ap ? CMD_TEMPL_AP_PROBE_RESPONSE : | |
2142 | CMD_TEMPL_PROBE_RESPONSE; | |
2143 | ret = wl1271_cmd_template_set(wl, | |
2144 | tmpl_id, | |
2145 | beacon->data, | |
2146 | beacon->len, 0, | |
2147 | wl1271_tx_min_rate_get(wl)); | |
2148 | dev_kfree_skb(beacon); | |
2149 | if (ret < 0) | |
2150 | goto out; | |
2151 | } | |
2152 | ||
2153 | out: | |
2154 | return ret; | |
2155 | } | |
2156 | ||
2157 | /* AP mode changes */ | |
2158 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, | |
2159 | struct ieee80211_vif *vif, | |
2160 | struct ieee80211_bss_conf *bss_conf, | |
2161 | u32 changed) | |
2162 | { | |
2163 | int ret = 0; | |
e0d8bbf0 | 2164 | |
e78a287a AN |
2165 | if ((changed & BSS_CHANGED_BASIC_RATES)) { |
2166 | u32 rates = bss_conf->basic_rates; | |
2167 | struct conf_tx_rate_class mgmt_rc; | |
5da11dcd | 2168 | |
e78a287a AN |
2169 | wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates); |
2170 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | |
2171 | wl1271_debug(DEBUG_AP, "basic rates: 0x%x", | |
2172 | wl->basic_rate_set); | |
2173 | ||
2174 | /* update the AP management rate policy with the new rates */ | |
2175 | mgmt_rc.enabled_rates = wl->basic_rate_set; | |
2176 | mgmt_rc.long_retry_limit = 10; | |
2177 | mgmt_rc.short_retry_limit = 10; | |
2178 | mgmt_rc.aflags = 0; | |
2179 | ret = wl1271_acx_ap_rate_policy(wl, &mgmt_rc, | |
2180 | ACX_TX_AP_MODE_MGMT_RATE); | |
2181 | if (ret < 0) { | |
2182 | wl1271_error("AP mgmt policy change failed %d", ret); | |
2183 | goto out; | |
2184 | } | |
2185 | } | |
2f6724b2 | 2186 | |
e78a287a AN |
2187 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
2188 | if (ret < 0) | |
2189 | goto out; | |
30240fc7 | 2190 | |
e78a287a AN |
2191 | if ((changed & BSS_CHANGED_BEACON_ENABLED)) { |
2192 | if (bss_conf->enable_beacon) { | |
2193 | if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | |
2194 | ret = wl1271_cmd_start_bss(wl); | |
2195 | if (ret < 0) | |
2196 | goto out; | |
e0d8bbf0 | 2197 | |
e78a287a AN |
2198 | set_bit(WL1271_FLAG_AP_STARTED, &wl->flags); |
2199 | wl1271_debug(DEBUG_AP, "started AP"); | |
7f179b46 AN |
2200 | |
2201 | ret = wl1271_ap_init_hwenc(wl); | |
2202 | if (ret < 0) | |
2203 | goto out; | |
e0d8bbf0 | 2204 | } |
e78a287a AN |
2205 | } else { |
2206 | if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | |
2207 | ret = wl1271_cmd_stop_bss(wl); | |
2208 | if (ret < 0) | |
2209 | goto out; | |
e0d8bbf0 | 2210 | |
e78a287a AN |
2211 | clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags); |
2212 | wl1271_debug(DEBUG_AP, "stopped AP"); | |
2213 | } | |
2214 | } | |
2215 | } | |
e0d8bbf0 | 2216 | |
e78a287a AN |
2217 | ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); |
2218 | if (ret < 0) | |
2219 | goto out; | |
2220 | out: | |
2221 | return; | |
2222 | } | |
8bf29b0e | 2223 | |
e78a287a AN |
2224 | /* STA/IBSS mode changes */ |
2225 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, | |
2226 | struct ieee80211_vif *vif, | |
2227 | struct ieee80211_bss_conf *bss_conf, | |
2228 | u32 changed) | |
2229 | { | |
2230 | bool do_join = false, set_assoc = false; | |
2231 | bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); | |
2232 | int ret; | |
2d6e4e76 | 2233 | struct ieee80211_sta *sta; |
e78a287a AN |
2234 | |
2235 | if (is_ibss) { | |
2236 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, | |
2237 | changed); | |
2238 | if (ret < 0) | |
2239 | goto out; | |
e0d8bbf0 JO |
2240 | } |
2241 | ||
e78a287a AN |
2242 | if ((changed & BSS_CHANGED_BEACON_INT) && is_ibss) |
2243 | do_join = true; | |
2244 | ||
2245 | /* Need to update the SSID (for filtering etc) */ | |
2246 | if ((changed & BSS_CHANGED_BEACON) && is_ibss) | |
2247 | do_join = true; | |
2248 | ||
2249 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && is_ibss) { | |
5da11dcd JO |
2250 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
2251 | bss_conf->enable_beacon ? "enabled" : "disabled"); | |
2252 | ||
2253 | if (bss_conf->enable_beacon) | |
2254 | wl->set_bss_type = BSS_TYPE_IBSS; | |
2255 | else | |
2256 | wl->set_bss_type = BSS_TYPE_STA_BSS; | |
2257 | do_join = true; | |
2258 | } | |
2259 | ||
e78a287a | 2260 | if ((changed & BSS_CHANGED_CQM)) { |
00236aed JO |
2261 | bool enable = false; |
2262 | if (bss_conf->cqm_rssi_thold) | |
2263 | enable = true; | |
2264 | ret = wl1271_acx_rssi_snr_trigger(wl, enable, | |
2265 | bss_conf->cqm_rssi_thold, | |
2266 | bss_conf->cqm_rssi_hyst); | |
2267 | if (ret < 0) | |
2268 | goto out; | |
2269 | wl->rssi_thold = bss_conf->cqm_rssi_thold; | |
2270 | } | |
2271 | ||
30240fc7 JO |
2272 | if ((changed & BSS_CHANGED_BSSID) && |
2273 | /* | |
2274 | * Now we know the correct bssid, so we send a new join command | |
2275 | * and enable the BSSID filter | |
2276 | */ | |
2277 | memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) { | |
e78a287a | 2278 | memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN); |
a0cb7be4 | 2279 | |
fa287b8f EP |
2280 | if (!is_zero_ether_addr(wl->bssid)) { |
2281 | ret = wl1271_cmd_build_null_data(wl); | |
2282 | if (ret < 0) | |
2283 | goto out; | |
30240fc7 | 2284 | |
fa287b8f EP |
2285 | ret = wl1271_build_qos_null_data(wl); |
2286 | if (ret < 0) | |
2287 | goto out; | |
30240fc7 | 2288 | |
fa287b8f EP |
2289 | /* filter out all packets not from this BSSID */ |
2290 | wl1271_configure_filters(wl, 0); | |
14b228a0 | 2291 | |
fa287b8f EP |
2292 | /* Need to update the BSSID (for filtering etc) */ |
2293 | do_join = true; | |
2294 | } | |
30240fc7 JO |
2295 | } |
2296 | ||
e78a287a | 2297 | if ((changed & BSS_CHANGED_ASSOC)) { |
f5fc0f86 | 2298 | if (bss_conf->assoc) { |
ebba60c6 | 2299 | u32 rates; |
2f6724b2 | 2300 | int ieoffset; |
f5fc0f86 | 2301 | wl->aid = bss_conf->aid; |
69e5434c | 2302 | set_assoc = true; |
f5fc0f86 | 2303 | |
90494a90 JO |
2304 | wl->ps_poll_failures = 0; |
2305 | ||
ebba60c6 JO |
2306 | /* |
2307 | * use basic rates from AP, and determine lowest rate | |
2308 | * to use with control frames. | |
2309 | */ | |
2310 | rates = bss_conf->basic_rates; | |
2311 | wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, | |
2312 | rates); | |
e0fe371b | 2313 | wl->basic_rate = wl1271_tx_min_rate_get(wl); |
79b223f4 | 2314 | ret = wl1271_acx_sta_rate_policies(wl); |
ebba60c6 | 2315 | if (ret < 0) |
e78a287a | 2316 | goto out; |
ebba60c6 | 2317 | |
ae751bab LC |
2318 | /* |
2319 | * with wl1271, we don't need to update the | |
2320 | * beacon_int and dtim_period, because the firmware | |
2321 | * updates it by itself when the first beacon is | |
2322 | * received after a join. | |
2323 | */ | |
f5fc0f86 LC |
2324 | ret = wl1271_cmd_build_ps_poll(wl, wl->aid); |
2325 | if (ret < 0) | |
e78a287a | 2326 | goto out; |
f5fc0f86 | 2327 | |
c2b2d99b | 2328 | /* |
2f6724b2 | 2329 | * Get a template for hardware connection maintenance |
c2b2d99b | 2330 | */ |
2f6724b2 JO |
2331 | dev_kfree_skb(wl->probereq); |
2332 | wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL); | |
2333 | ieoffset = offsetof(struct ieee80211_mgmt, | |
2334 | u.probe_req.variable); | |
2335 | wl1271_ssid_set(wl, wl->probereq, ieoffset); | |
c2b2d99b | 2336 | |
6ccbb92e JO |
2337 | /* enable the connection monitoring feature */ |
2338 | ret = wl1271_acx_conn_monit_params(wl, true); | |
f5fc0f86 | 2339 | if (ret < 0) |
e78a287a | 2340 | goto out; |
f5fc0f86 LC |
2341 | |
2342 | /* If we want to go in PSM but we're not there yet */ | |
71449f8d JO |
2343 | if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) && |
2344 | !test_bit(WL1271_FLAG_PSM, &wl->flags)) { | |
e78a287a AN |
2345 | enum wl1271_cmd_ps_mode mode; |
2346 | ||
f5fc0f86 | 2347 | mode = STATION_POWER_SAVE_MODE; |
65cddbf1 | 2348 | ret = wl1271_ps_set_mode(wl, mode, |
8eab7b47 | 2349 | wl->basic_rate, |
65cddbf1 | 2350 | true); |
f5fc0f86 | 2351 | if (ret < 0) |
e78a287a | 2352 | goto out; |
f5fc0f86 | 2353 | } |
d94cd297 JO |
2354 | } else { |
2355 | /* use defaults when not associated */ | |
c2c192ac | 2356 | clear_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags); |
830fb67b | 2357 | clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags); |
d94cd297 | 2358 | wl->aid = 0; |
6ccbb92e | 2359 | |
2f6724b2 JO |
2360 | /* free probe-request template */ |
2361 | dev_kfree_skb(wl->probereq); | |
2362 | wl->probereq = NULL; | |
2363 | ||
8d2ef7bd | 2364 | /* re-enable dynamic ps - just in case */ |
f532be6d | 2365 | ieee80211_enable_dyn_ps(wl->vif); |
8d2ef7bd | 2366 | |
ebba60c6 JO |
2367 | /* revert back to minimum rates for the current band */ |
2368 | wl1271_set_band_rate(wl); | |
e0fe371b | 2369 | wl->basic_rate = wl1271_tx_min_rate_get(wl); |
79b223f4 | 2370 | ret = wl1271_acx_sta_rate_policies(wl); |
ebba60c6 | 2371 | if (ret < 0) |
e78a287a | 2372 | goto out; |
ebba60c6 | 2373 | |
6ccbb92e JO |
2374 | /* disable connection monitor features */ |
2375 | ret = wl1271_acx_conn_monit_params(wl, false); | |
c1899554 JO |
2376 | |
2377 | /* Disable the keep-alive feature */ | |
2378 | ret = wl1271_acx_keep_alive_mode(wl, false); | |
6ccbb92e | 2379 | if (ret < 0) |
e78a287a | 2380 | goto out; |
b84a7d3d JO |
2381 | |
2382 | /* restore the bssid filter and go to dummy bssid */ | |
2383 | wl1271_unjoin(wl); | |
2384 | wl1271_dummy_join(wl); | |
f5fc0f86 | 2385 | } |
f5fc0f86 LC |
2386 | } |
2387 | ||
e78a287a AN |
2388 | ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); |
2389 | if (ret < 0) | |
2390 | goto out; | |
f5fc0f86 | 2391 | |
2d6e4e76 LC |
2392 | rcu_read_lock(); |
2393 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
2394 | if (sta) { | |
2395 | /* handle new association with HT and HT information change */ | |
2396 | if ((changed & BSS_CHANGED_HT) && | |
2397 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | |
2398 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, | |
2399 | true); | |
2400 | if (ret < 0) { | |
2401 | wl1271_warning("Set ht cap true failed %d", | |
2402 | ret); | |
2403 | rcu_read_unlock(); | |
2404 | goto out; | |
2405 | } | |
18357850 | 2406 | ret = wl1271_acx_set_ht_information(wl, |
2d6e4e76 LC |
2407 | bss_conf->ht_operation_mode); |
2408 | if (ret < 0) { | |
2409 | wl1271_warning("Set ht information failed %d", | |
2410 | ret); | |
2411 | rcu_read_unlock(); | |
2412 | goto out; | |
2413 | } | |
18357850 | 2414 | } |
2d6e4e76 LC |
2415 | /* handle new association without HT and disassociation */ |
2416 | else if (changed & BSS_CHANGED_ASSOC) { | |
2417 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, | |
2418 | false); | |
2419 | if (ret < 0) { | |
2420 | wl1271_warning("Set ht cap false failed %d", | |
2421 | ret); | |
2422 | rcu_read_unlock(); | |
2423 | goto out; | |
2424 | } | |
18357850 SL |
2425 | } |
2426 | } | |
2d6e4e76 | 2427 | rcu_read_unlock(); |
18357850 | 2428 | |
ca52a5eb JO |
2429 | if (changed & BSS_CHANGED_ARP_FILTER) { |
2430 | __be32 addr = bss_conf->arp_addr_list[0]; | |
2431 | WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS); | |
2432 | ||
c5312772 EP |
2433 | if (bss_conf->arp_addr_cnt == 1 && |
2434 | bss_conf->arp_filter_enabled) { | |
2435 | /* | |
2436 | * The template should have been configured only upon | |
2437 | * association. however, it seems that the correct ip | |
2438 | * isn't being set (when sending), so we have to | |
2439 | * reconfigure the template upon every ip change. | |
2440 | */ | |
2441 | ret = wl1271_cmd_build_arp_rsp(wl, addr); | |
2442 | if (ret < 0) { | |
2443 | wl1271_warning("build arp rsp failed: %d", ret); | |
e78a287a | 2444 | goto out; |
c5312772 EP |
2445 | } |
2446 | ||
2447 | ret = wl1271_acx_arp_ip_filter(wl, | |
2448 | (ACX_ARP_FILTER_ARP_FILTERING | | |
2449 | ACX_ARP_FILTER_AUTO_ARP), | |
2450 | addr); | |
2451 | } else | |
2452 | ret = wl1271_acx_arp_ip_filter(wl, 0, addr); | |
ca52a5eb JO |
2453 | |
2454 | if (ret < 0) | |
e78a287a | 2455 | goto out; |
ca52a5eb JO |
2456 | } |
2457 | ||
8bf29b0e | 2458 | if (do_join) { |
69e5434c | 2459 | ret = wl1271_join(wl, set_assoc); |
8bf29b0e JO |
2460 | if (ret < 0) { |
2461 | wl1271_warning("cmd join failed %d", ret); | |
e78a287a | 2462 | goto out; |
8bf29b0e | 2463 | } |
c1899554 JO |
2464 | } |
2465 | ||
e78a287a AN |
2466 | out: |
2467 | return; | |
2468 | } | |
2469 | ||
2470 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, | |
2471 | struct ieee80211_vif *vif, | |
2472 | struct ieee80211_bss_conf *bss_conf, | |
2473 | u32 changed) | |
2474 | { | |
2475 | struct wl1271 *wl = hw->priv; | |
2476 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | |
2477 | int ret; | |
2478 | ||
2479 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", | |
2480 | (int)changed); | |
2481 | ||
2482 | mutex_lock(&wl->mutex); | |
2483 | ||
2484 | if (unlikely(wl->state == WL1271_STATE_OFF)) | |
2485 | goto out; | |
2486 | ||
2487 | ret = wl1271_ps_elp_wakeup(wl, false); | |
2488 | if (ret < 0) | |
2489 | goto out; | |
2490 | ||
2491 | if (is_ap) | |
2492 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); | |
2493 | else | |
2494 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); | |
2495 | ||
f5fc0f86 LC |
2496 | wl1271_ps_elp_sleep(wl); |
2497 | ||
2498 | out: | |
2499 | mutex_unlock(&wl->mutex); | |
2500 | } | |
2501 | ||
c6999d83 KV |
2502 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue, |
2503 | const struct ieee80211_tx_queue_params *params) | |
2504 | { | |
2505 | struct wl1271 *wl = hw->priv; | |
4695dc91 | 2506 | u8 ps_scheme; |
488fc540 | 2507 | int ret = 0; |
c6999d83 KV |
2508 | |
2509 | mutex_lock(&wl->mutex); | |
2510 | ||
2511 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); | |
2512 | ||
4695dc91 KV |
2513 | if (params->uapsd) |
2514 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; | |
2515 | else | |
2516 | ps_scheme = CONF_PS_SCHEME_LEGACY; | |
2517 | ||
488fc540 AN |
2518 | if (wl->state == WL1271_STATE_OFF) { |
2519 | /* | |
2520 | * If the state is off, the parameters will be recorded and | |
2521 | * configured on init. This happens in AP-mode. | |
2522 | */ | |
2523 | struct conf_tx_ac_category *conf_ac = | |
2524 | &wl->conf.tx.ac_conf[wl1271_tx_get_queue(queue)]; | |
2525 | struct conf_tx_tid *conf_tid = | |
2526 | &wl->conf.tx.tid_conf[wl1271_tx_get_queue(queue)]; | |
2527 | ||
2528 | conf_ac->ac = wl1271_tx_get_queue(queue); | |
2529 | conf_ac->cw_min = (u8)params->cw_min; | |
2530 | conf_ac->cw_max = params->cw_max; | |
2531 | conf_ac->aifsn = params->aifs; | |
2532 | conf_ac->tx_op_limit = params->txop << 5; | |
2533 | ||
2534 | conf_tid->queue_id = wl1271_tx_get_queue(queue); | |
2535 | conf_tid->channel_type = CONF_CHANNEL_TYPE_EDCF; | |
2536 | conf_tid->tsid = wl1271_tx_get_queue(queue); | |
2537 | conf_tid->ps_scheme = ps_scheme; | |
2538 | conf_tid->ack_policy = CONF_ACK_POLICY_LEGACY; | |
2539 | conf_tid->apsd_conf[0] = 0; | |
2540 | conf_tid->apsd_conf[1] = 0; | |
2541 | } else { | |
2542 | ret = wl1271_ps_elp_wakeup(wl, false); | |
2543 | if (ret < 0) | |
2544 | goto out; | |
2545 | ||
2546 | /* | |
2547 | * the txop is confed in units of 32us by the mac80211, | |
2548 | * we need us | |
2549 | */ | |
2550 | ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue), | |
2551 | params->cw_min, params->cw_max, | |
2552 | params->aifs, params->txop << 5); | |
2553 | if (ret < 0) | |
2554 | goto out_sleep; | |
2555 | ||
2556 | ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue), | |
2557 | CONF_CHANNEL_TYPE_EDCF, | |
2558 | wl1271_tx_get_queue(queue), | |
2559 | ps_scheme, CONF_ACK_POLICY_LEGACY, | |
2560 | 0, 0); | |
2561 | if (ret < 0) | |
2562 | goto out_sleep; | |
c82c1dde KV |
2563 | |
2564 | out_sleep: | |
488fc540 AN |
2565 | wl1271_ps_elp_sleep(wl); |
2566 | } | |
c6999d83 KV |
2567 | |
2568 | out: | |
2569 | mutex_unlock(&wl->mutex); | |
2570 | ||
2571 | return ret; | |
2572 | } | |
2573 | ||
bbbb538e JO |
2574 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw) |
2575 | { | |
2576 | ||
2577 | struct wl1271 *wl = hw->priv; | |
2578 | u64 mactime = ULLONG_MAX; | |
2579 | int ret; | |
2580 | ||
2581 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); | |
2582 | ||
2583 | mutex_lock(&wl->mutex); | |
2584 | ||
f8d9802f JO |
2585 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
2586 | goto out; | |
2587 | ||
bbbb538e JO |
2588 | ret = wl1271_ps_elp_wakeup(wl, false); |
2589 | if (ret < 0) | |
2590 | goto out; | |
2591 | ||
2592 | ret = wl1271_acx_tsf_info(wl, &mactime); | |
2593 | if (ret < 0) | |
2594 | goto out_sleep; | |
2595 | ||
2596 | out_sleep: | |
2597 | wl1271_ps_elp_sleep(wl); | |
2598 | ||
2599 | out: | |
2600 | mutex_unlock(&wl->mutex); | |
2601 | return mactime; | |
2602 | } | |
f5fc0f86 | 2603 | |
ece550d0 JL |
2604 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
2605 | struct survey_info *survey) | |
2606 | { | |
2607 | struct wl1271 *wl = hw->priv; | |
2608 | struct ieee80211_conf *conf = &hw->conf; | |
b739a42c | 2609 | |
ece550d0 JL |
2610 | if (idx != 0) |
2611 | return -ENOENT; | |
b739a42c | 2612 | |
ece550d0 JL |
2613 | survey->channel = conf->channel; |
2614 | survey->filled = SURVEY_INFO_NOISE_DBM; | |
2615 | survey->noise = wl->noise; | |
b739a42c | 2616 | |
ece550d0 JL |
2617 | return 0; |
2618 | } | |
2619 | ||
f84f7d78 AN |
2620 | static int wl1271_allocate_hlid(struct wl1271 *wl, |
2621 | struct ieee80211_sta *sta, | |
2622 | u8 *hlid) | |
2623 | { | |
2624 | struct wl1271_station *wl_sta; | |
2625 | int id; | |
2626 | ||
2627 | id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS); | |
2628 | if (id >= AP_MAX_STATIONS) { | |
2629 | wl1271_warning("could not allocate HLID - too much stations"); | |
2630 | return -EBUSY; | |
2631 | } | |
2632 | ||
2633 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
2634 | ||
2635 | __set_bit(id, wl->ap_hlid_map); | |
2636 | wl_sta->hlid = WL1271_AP_STA_HLID_START + id; | |
2637 | *hlid = wl_sta->hlid; | |
2638 | return 0; | |
2639 | } | |
2640 | ||
2641 | static void wl1271_free_hlid(struct wl1271 *wl, u8 hlid) | |
2642 | { | |
2643 | int id = hlid - WL1271_AP_STA_HLID_START; | |
2644 | ||
2645 | __clear_bit(id, wl->ap_hlid_map); | |
2646 | } | |
2647 | ||
2648 | static int wl1271_op_sta_add(struct ieee80211_hw *hw, | |
2649 | struct ieee80211_vif *vif, | |
2650 | struct ieee80211_sta *sta) | |
2651 | { | |
2652 | struct wl1271 *wl = hw->priv; | |
2653 | int ret = 0; | |
2654 | u8 hlid; | |
2655 | ||
2656 | mutex_lock(&wl->mutex); | |
2657 | ||
2658 | if (unlikely(wl->state == WL1271_STATE_OFF)) | |
2659 | goto out; | |
2660 | ||
2661 | if (wl->bss_type != BSS_TYPE_AP_BSS) | |
2662 | goto out; | |
2663 | ||
2664 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); | |
2665 | ||
2666 | ret = wl1271_allocate_hlid(wl, sta, &hlid); | |
2667 | if (ret < 0) | |
2668 | goto out; | |
2669 | ||
2670 | ret = wl1271_ps_elp_wakeup(wl, false); | |
2671 | if (ret < 0) | |
2672 | goto out; | |
2673 | ||
2674 | ret = wl1271_cmd_add_sta(wl, sta, hlid); | |
2675 | if (ret < 0) | |
2676 | goto out_sleep; | |
2677 | ||
2678 | out_sleep: | |
2679 | wl1271_ps_elp_sleep(wl); | |
2680 | ||
2681 | out: | |
2682 | mutex_unlock(&wl->mutex); | |
2683 | return ret; | |
2684 | } | |
2685 | ||
2686 | static int wl1271_op_sta_remove(struct ieee80211_hw *hw, | |
2687 | struct ieee80211_vif *vif, | |
2688 | struct ieee80211_sta *sta) | |
2689 | { | |
2690 | struct wl1271 *wl = hw->priv; | |
2691 | struct wl1271_station *wl_sta; | |
2692 | int ret = 0, id; | |
2693 | ||
2694 | mutex_lock(&wl->mutex); | |
2695 | ||
2696 | if (unlikely(wl->state == WL1271_STATE_OFF)) | |
2697 | goto out; | |
2698 | ||
2699 | if (wl->bss_type != BSS_TYPE_AP_BSS) | |
2700 | goto out; | |
2701 | ||
2702 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); | |
2703 | ||
2704 | wl_sta = (struct wl1271_station *)sta->drv_priv; | |
2705 | id = wl_sta->hlid - WL1271_AP_STA_HLID_START; | |
2706 | if (WARN_ON(!test_bit(id, wl->ap_hlid_map))) | |
2707 | goto out; | |
2708 | ||
2709 | ret = wl1271_ps_elp_wakeup(wl, false); | |
2710 | if (ret < 0) | |
2711 | goto out; | |
2712 | ||
2713 | ret = wl1271_cmd_remove_sta(wl, wl_sta->hlid); | |
2714 | if (ret < 0) | |
2715 | goto out_sleep; | |
2716 | ||
2717 | wl1271_free_hlid(wl, wl_sta->hlid); | |
2718 | ||
2719 | out_sleep: | |
2720 | wl1271_ps_elp_sleep(wl); | |
2721 | ||
2722 | out: | |
2723 | mutex_unlock(&wl->mutex); | |
2724 | return ret; | |
2725 | } | |
2726 | ||
bbba3e68 LS |
2727 | int wl1271_op_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
2728 | enum ieee80211_ampdu_mlme_action action, | |
2729 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | |
2730 | { | |
2731 | struct wl1271 *wl = hw->priv; | |
2732 | int ret; | |
2733 | ||
2734 | mutex_lock(&wl->mutex); | |
2735 | ||
2736 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | |
2737 | ret = -EAGAIN; | |
2738 | goto out; | |
2739 | } | |
2740 | ||
2741 | ret = wl1271_ps_elp_wakeup(wl, false); | |
2742 | if (ret < 0) | |
2743 | goto out; | |
2744 | ||
2745 | switch (action) { | |
2746 | case IEEE80211_AMPDU_RX_START: | |
2747 | if (wl->ba_support) { | |
2748 | ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn, | |
2749 | true); | |
2750 | if (!ret) | |
2751 | wl->ba_rx_bitmap |= BIT(tid); | |
2752 | } else { | |
2753 | ret = -ENOTSUPP; | |
2754 | } | |
2755 | break; | |
2756 | ||
2757 | case IEEE80211_AMPDU_RX_STOP: | |
2758 | ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false); | |
2759 | if (!ret) | |
2760 | wl->ba_rx_bitmap &= ~BIT(tid); | |
2761 | break; | |
2762 | ||
2763 | /* | |
2764 | * The BA initiator session management in FW independently. | |
2765 | * Falling break here on purpose for all TX APDU commands. | |
2766 | */ | |
2767 | case IEEE80211_AMPDU_TX_START: | |
2768 | case IEEE80211_AMPDU_TX_STOP: | |
2769 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
2770 | ret = -EINVAL; | |
2771 | break; | |
2772 | ||
2773 | default: | |
2774 | wl1271_error("Incorrect ampdu action id=%x\n", action); | |
2775 | ret = -EINVAL; | |
2776 | } | |
2777 | ||
2778 | wl1271_ps_elp_sleep(wl); | |
2779 | ||
2780 | out: | |
2781 | mutex_unlock(&wl->mutex); | |
2782 | ||
2783 | return ret; | |
2784 | } | |
2785 | ||
f5fc0f86 LC |
2786 | /* can't be const, mac80211 writes to this */ |
2787 | static struct ieee80211_rate wl1271_rates[] = { | |
2788 | { .bitrate = 10, | |
2b60100b JO |
2789 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
2790 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, | |
f5fc0f86 | 2791 | { .bitrate = 20, |
2b60100b JO |
2792 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
2793 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, | |
f5fc0f86 LC |
2794 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
2795 | { .bitrate = 55, | |
2b60100b JO |
2796 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
2797 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, | |
f5fc0f86 LC |
2798 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
2799 | { .bitrate = 110, | |
2b60100b JO |
2800 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
2801 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, | |
f5fc0f86 LC |
2802 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
2803 | { .bitrate = 60, | |
2b60100b JO |
2804 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
2805 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | |
f5fc0f86 | 2806 | { .bitrate = 90, |
2b60100b JO |
2807 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
2808 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | |
f5fc0f86 | 2809 | { .bitrate = 120, |
2b60100b JO |
2810 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
2811 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | |
f5fc0f86 | 2812 | { .bitrate = 180, |
2b60100b JO |
2813 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
2814 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | |
f5fc0f86 | 2815 | { .bitrate = 240, |
2b60100b JO |
2816 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
2817 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | |
f5fc0f86 | 2818 | { .bitrate = 360, |
2b60100b JO |
2819 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
2820 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | |
f5fc0f86 | 2821 | { .bitrate = 480, |
2b60100b JO |
2822 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
2823 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | |
f5fc0f86 | 2824 | { .bitrate = 540, |
2b60100b JO |
2825 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
2826 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | |
f5fc0f86 LC |
2827 | }; |
2828 | ||
fa97f46b | 2829 | /* can't be const, mac80211 writes to this */ |
f5fc0f86 | 2830 | static struct ieee80211_channel wl1271_channels[] = { |
a2d0e3f1 | 2831 | { .hw_value = 1, .center_freq = 2412, .max_power = 25 }, |
fa21c7a9 | 2832 | { .hw_value = 2, .center_freq = 2417, .max_power = 25 }, |
fa97f46b JO |
2833 | { .hw_value = 3, .center_freq = 2422, .max_power = 25 }, |
2834 | { .hw_value = 4, .center_freq = 2427, .max_power = 25 }, | |
2835 | { .hw_value = 5, .center_freq = 2432, .max_power = 25 }, | |
fa21c7a9 | 2836 | { .hw_value = 6, .center_freq = 2437, .max_power = 25 }, |
fa97f46b JO |
2837 | { .hw_value = 7, .center_freq = 2442, .max_power = 25 }, |
2838 | { .hw_value = 8, .center_freq = 2447, .max_power = 25 }, | |
2839 | { .hw_value = 9, .center_freq = 2452, .max_power = 25 }, | |
fa21c7a9 | 2840 | { .hw_value = 10, .center_freq = 2457, .max_power = 25 }, |
fa97f46b JO |
2841 | { .hw_value = 11, .center_freq = 2462, .max_power = 25 }, |
2842 | { .hw_value = 12, .center_freq = 2467, .max_power = 25 }, | |
2843 | { .hw_value = 13, .center_freq = 2472, .max_power = 25 }, | |
6c89b7b2 | 2844 | { .hw_value = 14, .center_freq = 2484, .max_power = 25 }, |
f5fc0f86 LC |
2845 | }; |
2846 | ||
f876bb9a | 2847 | /* mapping to indexes for wl1271_rates */ |
a0ea9493 | 2848 | static const u8 wl1271_rate_to_idx_2ghz[] = { |
f876bb9a | 2849 | /* MCS rates are used only with 11n */ |
18357850 SL |
2850 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ |
2851 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ | |
2852 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ | |
2853 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ | |
2854 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ | |
2855 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ | |
2856 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ | |
2857 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ | |
f876bb9a JO |
2858 | |
2859 | 11, /* CONF_HW_RXTX_RATE_54 */ | |
2860 | 10, /* CONF_HW_RXTX_RATE_48 */ | |
2861 | 9, /* CONF_HW_RXTX_RATE_36 */ | |
2862 | 8, /* CONF_HW_RXTX_RATE_24 */ | |
2863 | ||
2864 | /* TI-specific rate */ | |
2865 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ | |
2866 | ||
2867 | 7, /* CONF_HW_RXTX_RATE_18 */ | |
2868 | 6, /* CONF_HW_RXTX_RATE_12 */ | |
2869 | 3, /* CONF_HW_RXTX_RATE_11 */ | |
2870 | 5, /* CONF_HW_RXTX_RATE_9 */ | |
2871 | 4, /* CONF_HW_RXTX_RATE_6 */ | |
2872 | 2, /* CONF_HW_RXTX_RATE_5_5 */ | |
2873 | 1, /* CONF_HW_RXTX_RATE_2 */ | |
2874 | 0 /* CONF_HW_RXTX_RATE_1 */ | |
2875 | }; | |
2876 | ||
e8b03a2b SL |
2877 | /* 11n STA capabilities */ |
2878 | #define HW_RX_HIGHEST_RATE 72 | |
2879 | ||
00d20100 SL |
2880 | #ifdef CONFIG_WL12XX_HT |
2881 | #define WL12XX_HT_CAP { \ | |
e8b03a2b SL |
2882 | .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20, \ |
2883 | .ht_supported = true, \ | |
2884 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \ | |
2885 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \ | |
2886 | .mcs = { \ | |
2887 | .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \ | |
2888 | .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \ | |
2889 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \ | |
2890 | }, \ | |
2891 | } | |
18357850 | 2892 | #else |
00d20100 | 2893 | #define WL12XX_HT_CAP { \ |
18357850 SL |
2894 | .ht_supported = false, \ |
2895 | } | |
2896 | #endif | |
e8b03a2b | 2897 | |
f5fc0f86 LC |
2898 | /* can't be const, mac80211 writes to this */ |
2899 | static struct ieee80211_supported_band wl1271_band_2ghz = { | |
2900 | .channels = wl1271_channels, | |
2901 | .n_channels = ARRAY_SIZE(wl1271_channels), | |
2902 | .bitrates = wl1271_rates, | |
2903 | .n_bitrates = ARRAY_SIZE(wl1271_rates), | |
00d20100 | 2904 | .ht_cap = WL12XX_HT_CAP, |
f5fc0f86 LC |
2905 | }; |
2906 | ||
1ebec3d7 TP |
2907 | /* 5 GHz data rates for WL1273 */ |
2908 | static struct ieee80211_rate wl1271_rates_5ghz[] = { | |
2909 | { .bitrate = 60, | |
2910 | .hw_value = CONF_HW_BIT_RATE_6MBPS, | |
2911 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | |
2912 | { .bitrate = 90, | |
2913 | .hw_value = CONF_HW_BIT_RATE_9MBPS, | |
2914 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | |
2915 | { .bitrate = 120, | |
2916 | .hw_value = CONF_HW_BIT_RATE_12MBPS, | |
2917 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | |
2918 | { .bitrate = 180, | |
2919 | .hw_value = CONF_HW_BIT_RATE_18MBPS, | |
2920 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | |
2921 | { .bitrate = 240, | |
2922 | .hw_value = CONF_HW_BIT_RATE_24MBPS, | |
2923 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | |
2924 | { .bitrate = 360, | |
2925 | .hw_value = CONF_HW_BIT_RATE_36MBPS, | |
2926 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | |
2927 | { .bitrate = 480, | |
2928 | .hw_value = CONF_HW_BIT_RATE_48MBPS, | |
2929 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | |
2930 | { .bitrate = 540, | |
2931 | .hw_value = CONF_HW_BIT_RATE_54MBPS, | |
2932 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | |
2933 | }; | |
2934 | ||
fa97f46b | 2935 | /* 5 GHz band channels for WL1273 */ |
1ebec3d7 | 2936 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
fa21c7a9 | 2937 | { .hw_value = 7, .center_freq = 5035}, |
fa97f46b JO |
2938 | { .hw_value = 8, .center_freq = 5040}, |
2939 | { .hw_value = 9, .center_freq = 5045}, | |
2940 | { .hw_value = 11, .center_freq = 5055}, | |
2941 | { .hw_value = 12, .center_freq = 5060}, | |
fa21c7a9 | 2942 | { .hw_value = 16, .center_freq = 5080}, |
fa97f46b JO |
2943 | { .hw_value = 34, .center_freq = 5170}, |
2944 | { .hw_value = 36, .center_freq = 5180}, | |
2945 | { .hw_value = 38, .center_freq = 5190}, | |
2946 | { .hw_value = 40, .center_freq = 5200}, | |
fa21c7a9 | 2947 | { .hw_value = 42, .center_freq = 5210}, |
fa97f46b JO |
2948 | { .hw_value = 44, .center_freq = 5220}, |
2949 | { .hw_value = 46, .center_freq = 5230}, | |
2950 | { .hw_value = 48, .center_freq = 5240}, | |
2951 | { .hw_value = 52, .center_freq = 5260}, | |
fa21c7a9 | 2952 | { .hw_value = 56, .center_freq = 5280}, |
fa97f46b JO |
2953 | { .hw_value = 60, .center_freq = 5300}, |
2954 | { .hw_value = 64, .center_freq = 5320}, | |
2955 | { .hw_value = 100, .center_freq = 5500}, | |
2956 | { .hw_value = 104, .center_freq = 5520}, | |
fa21c7a9 | 2957 | { .hw_value = 108, .center_freq = 5540}, |
fa97f46b JO |
2958 | { .hw_value = 112, .center_freq = 5560}, |
2959 | { .hw_value = 116, .center_freq = 5580}, | |
2960 | { .hw_value = 120, .center_freq = 5600}, | |
2961 | { .hw_value = 124, .center_freq = 5620}, | |
fa21c7a9 | 2962 | { .hw_value = 128, .center_freq = 5640}, |
fa97f46b JO |
2963 | { .hw_value = 132, .center_freq = 5660}, |
2964 | { .hw_value = 136, .center_freq = 5680}, | |
2965 | { .hw_value = 140, .center_freq = 5700}, | |
2966 | { .hw_value = 149, .center_freq = 5745}, | |
fa21c7a9 | 2967 | { .hw_value = 153, .center_freq = 5765}, |
fa97f46b JO |
2968 | { .hw_value = 157, .center_freq = 5785}, |
2969 | { .hw_value = 161, .center_freq = 5805}, | |
1ebec3d7 TP |
2970 | { .hw_value = 165, .center_freq = 5825}, |
2971 | }; | |
2972 | ||
f876bb9a | 2973 | /* mapping to indexes for wl1271_rates_5ghz */ |
a0ea9493 | 2974 | static const u8 wl1271_rate_to_idx_5ghz[] = { |
f876bb9a | 2975 | /* MCS rates are used only with 11n */ |
18357850 SL |
2976 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ |
2977 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ | |
2978 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ | |
2979 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ | |
2980 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ | |
2981 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ | |
2982 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ | |
2983 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ | |
f876bb9a JO |
2984 | |
2985 | 7, /* CONF_HW_RXTX_RATE_54 */ | |
2986 | 6, /* CONF_HW_RXTX_RATE_48 */ | |
2987 | 5, /* CONF_HW_RXTX_RATE_36 */ | |
2988 | 4, /* CONF_HW_RXTX_RATE_24 */ | |
2989 | ||
2990 | /* TI-specific rate */ | |
2991 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ | |
2992 | ||
2993 | 3, /* CONF_HW_RXTX_RATE_18 */ | |
2994 | 2, /* CONF_HW_RXTX_RATE_12 */ | |
2995 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */ | |
2996 | 1, /* CONF_HW_RXTX_RATE_9 */ | |
2997 | 0, /* CONF_HW_RXTX_RATE_6 */ | |
2998 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */ | |
2999 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */ | |
3000 | CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */ | |
3001 | }; | |
1ebec3d7 TP |
3002 | |
3003 | static struct ieee80211_supported_band wl1271_band_5ghz = { | |
3004 | .channels = wl1271_channels_5ghz, | |
3005 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), | |
3006 | .bitrates = wl1271_rates_5ghz, | |
3007 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), | |
00d20100 | 3008 | .ht_cap = WL12XX_HT_CAP, |
1ebec3d7 TP |
3009 | }; |
3010 | ||
a0ea9493 | 3011 | static const u8 *wl1271_band_rate_to_idx[] = { |
f876bb9a JO |
3012 | [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz, |
3013 | [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz | |
3014 | }; | |
3015 | ||
f5fc0f86 LC |
3016 | static const struct ieee80211_ops wl1271_ops = { |
3017 | .start = wl1271_op_start, | |
3018 | .stop = wl1271_op_stop, | |
3019 | .add_interface = wl1271_op_add_interface, | |
3020 | .remove_interface = wl1271_op_remove_interface, | |
3021 | .config = wl1271_op_config, | |
c87dec9f | 3022 | .prepare_multicast = wl1271_op_prepare_multicast, |
f5fc0f86 LC |
3023 | .configure_filter = wl1271_op_configure_filter, |
3024 | .tx = wl1271_op_tx, | |
3025 | .set_key = wl1271_op_set_key, | |
3026 | .hw_scan = wl1271_op_hw_scan, | |
3027 | .bss_info_changed = wl1271_op_bss_info_changed, | |
68d069c4 | 3028 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
f5fc0f86 | 3029 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
c6999d83 | 3030 | .conf_tx = wl1271_op_conf_tx, |
bbbb538e | 3031 | .get_tsf = wl1271_op_get_tsf, |
ece550d0 | 3032 | .get_survey = wl1271_op_get_survey, |
f84f7d78 AN |
3033 | .sta_add = wl1271_op_sta_add, |
3034 | .sta_remove = wl1271_op_sta_remove, | |
bbba3e68 | 3035 | .ampdu_action = wl1271_op_ampdu_action, |
c8c90873 | 3036 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
f5fc0f86 LC |
3037 | }; |
3038 | ||
f876bb9a | 3039 | |
6a2de93b | 3040 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band) |
f876bb9a JO |
3041 | { |
3042 | u8 idx; | |
3043 | ||
6a2de93b | 3044 | BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *)); |
f876bb9a JO |
3045 | |
3046 | if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) { | |
3047 | wl1271_error("Illegal RX rate from HW: %d", rate); | |
3048 | return 0; | |
3049 | } | |
3050 | ||
6a2de93b | 3051 | idx = wl1271_band_rate_to_idx[band][rate]; |
f876bb9a JO |
3052 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
3053 | wl1271_error("Unsupported RX rate from HW: %d", rate); | |
3054 | return 0; | |
3055 | } | |
3056 | ||
3057 | return idx; | |
3058 | } | |
3059 | ||
7fc3a864 JO |
3060 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, |
3061 | struct device_attribute *attr, | |
3062 | char *buf) | |
3063 | { | |
3064 | struct wl1271 *wl = dev_get_drvdata(dev); | |
3065 | ssize_t len; | |
3066 | ||
2f63b011 | 3067 | len = PAGE_SIZE; |
7fc3a864 JO |
3068 | |
3069 | mutex_lock(&wl->mutex); | |
3070 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", | |
3071 | wl->sg_enabled); | |
3072 | mutex_unlock(&wl->mutex); | |
3073 | ||
3074 | return len; | |
3075 | ||
3076 | } | |
3077 | ||
3078 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, | |
3079 | struct device_attribute *attr, | |
3080 | const char *buf, size_t count) | |
3081 | { | |
3082 | struct wl1271 *wl = dev_get_drvdata(dev); | |
3083 | unsigned long res; | |
3084 | int ret; | |
3085 | ||
3086 | ret = strict_strtoul(buf, 10, &res); | |
3087 | ||
3088 | if (ret < 0) { | |
3089 | wl1271_warning("incorrect value written to bt_coex_mode"); | |
3090 | return count; | |
3091 | } | |
3092 | ||
3093 | mutex_lock(&wl->mutex); | |
3094 | ||
3095 | res = !!res; | |
3096 | ||
3097 | if (res == wl->sg_enabled) | |
3098 | goto out; | |
3099 | ||
3100 | wl->sg_enabled = res; | |
3101 | ||
3102 | if (wl->state == WL1271_STATE_OFF) | |
3103 | goto out; | |
3104 | ||
3105 | ret = wl1271_ps_elp_wakeup(wl, false); | |
3106 | if (ret < 0) | |
3107 | goto out; | |
3108 | ||
3109 | wl1271_acx_sg_enable(wl, wl->sg_enabled); | |
3110 | wl1271_ps_elp_sleep(wl); | |
3111 | ||
3112 | out: | |
3113 | mutex_unlock(&wl->mutex); | |
3114 | return count; | |
3115 | } | |
3116 | ||
3117 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, | |
3118 | wl1271_sysfs_show_bt_coex_state, | |
3119 | wl1271_sysfs_store_bt_coex_state); | |
3120 | ||
d717fd61 JO |
3121 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, |
3122 | struct device_attribute *attr, | |
3123 | char *buf) | |
3124 | { | |
3125 | struct wl1271 *wl = dev_get_drvdata(dev); | |
3126 | ssize_t len; | |
3127 | ||
2f63b011 | 3128 | len = PAGE_SIZE; |
d717fd61 JO |
3129 | |
3130 | mutex_lock(&wl->mutex); | |
3131 | if (wl->hw_pg_ver >= 0) | |
3132 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); | |
3133 | else | |
3134 | len = snprintf(buf, len, "n/a\n"); | |
3135 | mutex_unlock(&wl->mutex); | |
3136 | ||
3137 | return len; | |
3138 | } | |
3139 | ||
3140 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO | S_IWUSR, | |
3141 | wl1271_sysfs_show_hw_pg_ver, NULL); | |
3142 | ||
2d5e82b8 | 3143 | int wl1271_register_hw(struct wl1271 *wl) |
f5fc0f86 LC |
3144 | { |
3145 | int ret; | |
3146 | ||
3147 | if (wl->mac80211_registered) | |
3148 | return 0; | |
3149 | ||
31d26ec6 AN |
3150 | ret = wl1271_fetch_nvs(wl); |
3151 | if (ret == 0) { | |
3152 | u8 *nvs_ptr = (u8 *)wl->nvs->nvs; | |
3153 | ||
3154 | wl->mac_addr[0] = nvs_ptr[11]; | |
3155 | wl->mac_addr[1] = nvs_ptr[10]; | |
3156 | wl->mac_addr[2] = nvs_ptr[6]; | |
3157 | wl->mac_addr[3] = nvs_ptr[5]; | |
3158 | wl->mac_addr[4] = nvs_ptr[4]; | |
3159 | wl->mac_addr[5] = nvs_ptr[3]; | |
3160 | } | |
3161 | ||
f5fc0f86 LC |
3162 | SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); |
3163 | ||
3164 | ret = ieee80211_register_hw(wl->hw); | |
3165 | if (ret < 0) { | |
3166 | wl1271_error("unable to register mac80211 hw: %d", ret); | |
3167 | return ret; | |
3168 | } | |
3169 | ||
3170 | wl->mac80211_registered = true; | |
3171 | ||
d60080ae EP |
3172 | wl1271_debugfs_init(wl); |
3173 | ||
c2c192ac JO |
3174 | register_netdevice_notifier(&wl1271_dev_notifier); |
3175 | ||
f5fc0f86 LC |
3176 | wl1271_notice("loaded"); |
3177 | ||
3178 | return 0; | |
3179 | } | |
50b3eb4b | 3180 | EXPORT_SYMBOL_GPL(wl1271_register_hw); |
f5fc0f86 | 3181 | |
3b56dd6a TP |
3182 | void wl1271_unregister_hw(struct wl1271 *wl) |
3183 | { | |
4ae3fa87 JO |
3184 | if (wl->state == WL1271_STATE_PLT) |
3185 | __wl1271_plt_stop(wl); | |
3186 | ||
c2c192ac | 3187 | unregister_netdevice_notifier(&wl1271_dev_notifier); |
3b56dd6a TP |
3188 | ieee80211_unregister_hw(wl->hw); |
3189 | wl->mac80211_registered = false; | |
3190 | ||
3191 | } | |
3192 | EXPORT_SYMBOL_GPL(wl1271_unregister_hw); | |
3193 | ||
2d5e82b8 | 3194 | int wl1271_init_ieee80211(struct wl1271 *wl) |
f5fc0f86 | 3195 | { |
7a55724e JO |
3196 | static const u32 cipher_suites[] = { |
3197 | WLAN_CIPHER_SUITE_WEP40, | |
3198 | WLAN_CIPHER_SUITE_WEP104, | |
3199 | WLAN_CIPHER_SUITE_TKIP, | |
3200 | WLAN_CIPHER_SUITE_CCMP, | |
3201 | WL1271_CIPHER_SUITE_GEM, | |
3202 | }; | |
3203 | ||
1e2b7976 JO |
3204 | /* The tx descriptor buffer and the TKIP space. */ |
3205 | wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE + | |
3206 | sizeof(struct wl1271_tx_hw_descr); | |
f5fc0f86 LC |
3207 | |
3208 | /* unit us */ | |
3209 | /* FIXME: find a proper value */ | |
3210 | wl->hw->channel_change_time = 10000; | |
50c500ad | 3211 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
f5fc0f86 LC |
3212 | |
3213 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | | |
03442a33 | 3214 | IEEE80211_HW_BEACON_FILTER | |
0a34332f | 3215 | IEEE80211_HW_SUPPORTS_PS | |
4695dc91 | 3216 | IEEE80211_HW_SUPPORTS_UAPSD | |
a9af092b | 3217 | IEEE80211_HW_HAS_RATE_CONTROL | |
00236aed JO |
3218 | IEEE80211_HW_CONNECTION_MONITOR | |
3219 | IEEE80211_HW_SUPPORTS_CQM_RSSI; | |
f5fc0f86 | 3220 | |
7a55724e JO |
3221 | wl->hw->wiphy->cipher_suites = cipher_suites; |
3222 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | |
3223 | ||
e0d8bbf0 | 3224 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
038d925b | 3225 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP); |
f5fc0f86 | 3226 | wl->hw->wiphy->max_scan_ssids = 1; |
ea559b46 GE |
3227 | /* |
3228 | * Maximum length of elements in scanning probe request templates | |
3229 | * should be the maximum length possible for a template, without | |
3230 | * the IEEE80211 header of the template | |
3231 | */ | |
3232 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - | |
3233 | sizeof(struct ieee80211_header); | |
a8aaaf53 LC |
3234 | |
3235 | /* | |
3236 | * We keep local copies of the band structs because we need to | |
3237 | * modify them on a per-device basis. | |
3238 | */ | |
3239 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, | |
3240 | sizeof(wl1271_band_2ghz)); | |
3241 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, | |
3242 | sizeof(wl1271_band_5ghz)); | |
3243 | ||
3244 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | |
3245 | &wl->bands[IEEE80211_BAND_2GHZ]; | |
3246 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | |
3247 | &wl->bands[IEEE80211_BAND_5GHZ]; | |
1ebec3d7 | 3248 | |
12bd8949 | 3249 | wl->hw->queues = 4; |
31627dc5 | 3250 | wl->hw->max_rates = 1; |
12bd8949 | 3251 | |
b7417d93 JO |
3252 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
3253 | ||
8197b711 | 3254 | SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); |
f5fc0f86 | 3255 | |
f84f7d78 AN |
3256 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
3257 | ||
4c9cfa78 LC |
3258 | wl->hw->max_rx_aggregation_subframes = 8; |
3259 | ||
f5fc0f86 LC |
3260 | return 0; |
3261 | } | |
50b3eb4b | 3262 | EXPORT_SYMBOL_GPL(wl1271_init_ieee80211); |
f5fc0f86 | 3263 | |
f5fc0f86 | 3264 | #define WL1271_DEFAULT_CHANNEL 0 |
c332a4b8 | 3265 | |
2d5e82b8 | 3266 | struct ieee80211_hw *wl1271_alloc_hw(void) |
f5fc0f86 | 3267 | { |
f5fc0f86 | 3268 | struct ieee80211_hw *hw; |
3b56dd6a | 3269 | struct platform_device *plat_dev = NULL; |
f5fc0f86 | 3270 | struct wl1271 *wl; |
a1dd8187 | 3271 | int i, ret; |
1f37cbc9 | 3272 | unsigned int order; |
f5fc0f86 LC |
3273 | |
3274 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); | |
3275 | if (!hw) { | |
3276 | wl1271_error("could not alloc ieee80211_hw"); | |
a1dd8187 | 3277 | ret = -ENOMEM; |
3b56dd6a TP |
3278 | goto err_hw_alloc; |
3279 | } | |
3280 | ||
929ebd30 | 3281 | plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL); |
3b56dd6a TP |
3282 | if (!plat_dev) { |
3283 | wl1271_error("could not allocate platform_device"); | |
3284 | ret = -ENOMEM; | |
3285 | goto err_plat_alloc; | |
f5fc0f86 LC |
3286 | } |
3287 | ||
3288 | wl = hw->priv; | |
3289 | memset(wl, 0, sizeof(*wl)); | |
3290 | ||
01c09162 JO |
3291 | INIT_LIST_HEAD(&wl->list); |
3292 | ||
f5fc0f86 | 3293 | wl->hw = hw; |
3b56dd6a | 3294 | wl->plat_dev = plat_dev; |
f5fc0f86 | 3295 | |
6742f554 JO |
3296 | for (i = 0; i < NUM_TX_QUEUES; i++) |
3297 | skb_queue_head_init(&wl->tx_queue[i]); | |
f5fc0f86 | 3298 | |
37b70a81 | 3299 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
90494a90 | 3300 | INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work); |
117b38d0 JO |
3301 | INIT_WORK(&wl->irq_work, wl1271_irq_work); |
3302 | INIT_WORK(&wl->tx_work, wl1271_tx_work); | |
3303 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); | |
3304 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); | |
f5fc0f86 | 3305 | wl->channel = WL1271_DEFAULT_CHANNEL; |
60e84c2e | 3306 | wl->beacon_int = WL1271_DEFAULT_BEACON_INT; |
f5fc0f86 | 3307 | wl->default_key = 0; |
f5fc0f86 | 3308 | wl->rx_counter = 0; |
ae113b57 AN |
3309 | wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG; |
3310 | wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER; | |
19ad0715 | 3311 | wl->psm_entry_retry = 0; |
f5fc0f86 | 3312 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
a6fe2313 | 3313 | wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
ebba60c6 | 3314 | wl->basic_rate = CONF_TX_RATE_MASK_BASIC; |
830fb67b JO |
3315 | wl->rate_set = CONF_TX_RATE_MASK_BASIC; |
3316 | wl->sta_rate_set = 0; | |
8a5a37a6 | 3317 | wl->band = IEEE80211_BAND_2GHZ; |
b771eee5 | 3318 | wl->vif = NULL; |
830fb67b | 3319 | wl->flags = 0; |
7fc3a864 | 3320 | wl->sg_enabled = true; |
d717fd61 | 3321 | wl->hw_pg_ver = -1; |
166d504e AN |
3322 | wl->bss_type = MAX_BSS_TYPE; |
3323 | wl->set_bss_type = MAX_BSS_TYPE; | |
3324 | wl->fw_bss_type = MAX_BSS_TYPE; | |
f5fc0f86 | 3325 | |
25eeb9e3 | 3326 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
be7078c2 | 3327 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
f5fc0f86 LC |
3328 | wl->tx_frames[i] = NULL; |
3329 | ||
3330 | spin_lock_init(&wl->wl_lock); | |
3331 | ||
f5fc0f86 LC |
3332 | wl->state = WL1271_STATE_OFF; |
3333 | mutex_init(&wl->mutex); | |
3334 | ||
c332a4b8 TP |
3335 | /* Apply default driver configuration. */ |
3336 | wl1271_conf_init(wl); | |
3337 | ||
1f37cbc9 IY |
3338 | order = get_order(WL1271_AGGR_BUFFER_SIZE); |
3339 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); | |
3340 | if (!wl->aggr_buf) { | |
3341 | ret = -ENOMEM; | |
3342 | goto err_hw; | |
3343 | } | |
3344 | ||
a1dd8187 | 3345 | /* Register platform device */ |
3b56dd6a | 3346 | ret = platform_device_register(wl->plat_dev); |
a1dd8187 JO |
3347 | if (ret) { |
3348 | wl1271_error("couldn't register platform device"); | |
1f37cbc9 | 3349 | goto err_aggr; |
a1dd8187 | 3350 | } |
3b56dd6a | 3351 | dev_set_drvdata(&wl->plat_dev->dev, wl); |
a1dd8187 | 3352 | |
7fc3a864 | 3353 | /* Create sysfs file to control bt coex state */ |
3b56dd6a | 3354 | ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); |
7fc3a864 JO |
3355 | if (ret < 0) { |
3356 | wl1271_error("failed to create sysfs file bt_coex_state"); | |
3357 | goto err_platform; | |
3358 | } | |
a1dd8187 | 3359 | |
d717fd61 JO |
3360 | /* Create sysfs file to get HW PG version */ |
3361 | ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver); | |
3362 | if (ret < 0) { | |
3363 | wl1271_error("failed to create sysfs file hw_pg_ver"); | |
3364 | goto err_bt_coex_state; | |
3365 | } | |
3366 | ||
c332a4b8 | 3367 | return hw; |
a1dd8187 | 3368 | |
d717fd61 JO |
3369 | err_bt_coex_state: |
3370 | device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); | |
3371 | ||
7fc3a864 | 3372 | err_platform: |
3b56dd6a | 3373 | platform_device_unregister(wl->plat_dev); |
7fc3a864 | 3374 | |
1f37cbc9 IY |
3375 | err_aggr: |
3376 | free_pages((unsigned long)wl->aggr_buf, order); | |
3377 | ||
a1dd8187 | 3378 | err_hw: |
3b56dd6a TP |
3379 | wl1271_debugfs_exit(wl); |
3380 | kfree(plat_dev); | |
3381 | ||
3382 | err_plat_alloc: | |
3383 | ieee80211_free_hw(hw); | |
3384 | ||
3385 | err_hw_alloc: | |
a1dd8187 | 3386 | |
a1dd8187 | 3387 | return ERR_PTR(ret); |
c332a4b8 | 3388 | } |
50b3eb4b | 3389 | EXPORT_SYMBOL_GPL(wl1271_alloc_hw); |
c332a4b8 TP |
3390 | |
3391 | int wl1271_free_hw(struct wl1271 *wl) | |
3392 | { | |
3b56dd6a | 3393 | platform_device_unregister(wl->plat_dev); |
1f37cbc9 IY |
3394 | free_pages((unsigned long)wl->aggr_buf, |
3395 | get_order(WL1271_AGGR_BUFFER_SIZE)); | |
3b56dd6a | 3396 | kfree(wl->plat_dev); |
c332a4b8 TP |
3397 | |
3398 | wl1271_debugfs_exit(wl); | |
3399 | ||
c332a4b8 TP |
3400 | vfree(wl->fw); |
3401 | wl->fw = NULL; | |
3402 | kfree(wl->nvs); | |
3403 | wl->nvs = NULL; | |
3404 | ||
3405 | kfree(wl->fw_status); | |
3406 | kfree(wl->tx_res_if); | |
3407 | ||
3408 | ieee80211_free_hw(wl->hw); | |
3409 | ||
3410 | return 0; | |
3411 | } | |
50b3eb4b TP |
3412 | EXPORT_SYMBOL_GPL(wl1271_free_hw); |
3413 | ||
491bbd6b | 3414 | u32 wl12xx_debug_level = DEBUG_NONE; |
17c1755c | 3415 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
491bbd6b | 3416 | module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR); |
17c1755c EP |
3417 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
3418 | ||
50b3eb4b TP |
3419 | MODULE_LICENSE("GPL"); |
3420 | MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); | |
3421 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |