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