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