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