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