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