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