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