blob: aa5d512c8f82a2ce2b6c03373c60b13491b48e18 [file] [log] [blame]
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02001
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002/*
3 * This file is part of wl1271
4 *
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02005 * Copyright (C) 2008-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03006 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/module.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030026#include <linux/firmware.h>
27#include <linux/delay.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030028#include <linux/spi/spi.h>
29#include <linux/crc32.h>
30#include <linux/etherdevice.h>
Juuso Oikarinen1fba4972009-10-08 21:56:32 +030031#include <linux/vmalloc.h>
Juuso Oikarinena1dd8182010-03-18 12:26:31 +020032#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Ido Yariv341b7cd2011-03-31 10:07:01 +020034#include <linux/wl12xx.h>
Ido Yariv95dac04f2011-06-06 14:57:06 +030035#include <linux/sched.h>
Felipe Balbia390e852011-10-06 10:07:44 +030036#include <linux/interrupt.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030037
Shahar Levi00d20102010-11-08 11:20:10 +000038#include "wl12xx.h"
Luciano Coelho0f4e3122011-10-07 11:02:42 +030039#include "debug.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030040#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000041#include "reg.h"
42#include "io.h"
43#include "event.h"
44#include "tx.h"
45#include "rx.h"
46#include "ps.h"
47#include "init.h"
48#include "debugfs.h"
49#include "cmd.h"
50#include "boot.h"
51#include "testmode.h"
52#include "scan.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +020054#define WL1271_BOOT_RETRIES 3
55
Juuso Oikarinen8a080482009-10-13 12:47:44 +030056static struct conf_drv_settings default_conf = {
57 .sg = {
Eliad Peller3be41122011-08-14 13:17:19 +030058 .params = {
59 [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
60 [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
61 [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
62 [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
63 [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
64 [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
65 [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
66 [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
67 [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
68 [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
69 [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
70 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
71 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
72 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
73 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
74 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
75 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
76 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
77 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
78 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
79 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
80 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
81 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
82 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
83 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
84 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
85 /* active scan params */
86 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
87 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
88 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
89 /* passive scan params */
90 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
91 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
92 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
93 /* passive scan in dual antenna params */
94 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
95 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
96 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
97 /* general params */
98 [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
99 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
100 [CONF_SG_BEACON_MISS_PERCENT] = 60,
101 [CONF_SG_DHCP_TIME] = 5000,
102 [CONF_SG_RXT] = 1200,
103 [CONF_SG_TXT] = 1000,
104 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
105 [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
106 [CONF_SG_HV3_MAX_SERVED] = 6,
107 [CONF_SG_PS_POLL_TIMEOUT] = 10,
108 [CONF_SG_UPSD_TIMEOUT] = 10,
109 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
110 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
111 [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
112 /* AP params */
113 [CONF_AP_BEACON_MISS_TX] = 3,
114 [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
115 [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
116 [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
117 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
118 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
Eliad Peller26612c42012-01-31 17:54:43 +0200119 /* CTS Diluting params */
120 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
121 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
Arik Nemtsov801f8702011-04-18 14:15:20 +0300122 },
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200123 .state = CONF_SG_PROTECTIVE,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300124 },
125 .rx = {
126 .rx_msdu_life_time = 512000,
127 .packet_detection_threshold = 0,
128 .ps_poll_timeout = 15,
129 .upsd_timeout = 15,
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300130 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200131 .rx_cca_threshold = 0,
132 .irq_blk_threshold = 0xFFFF,
133 .irq_pkt_threshold = 0,
134 .irq_timeout = 600,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300135 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
136 },
137 .tx = {
138 .tx_energy_detection = 0,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200139 .sta_rc_conf = {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300140 .enabled_rates = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300141 .short_retry_limit = 10,
142 .long_retry_limit = 10,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200143 .aflags = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300144 },
145 .ac_conf_count = 4,
146 .ac_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200147 [CONF_TX_AC_BE] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300148 .ac = CONF_TX_AC_BE,
149 .cw_min = 15,
150 .cw_max = 63,
151 .aifsn = 3,
152 .tx_op_limit = 0,
153 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200154 [CONF_TX_AC_BK] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300155 .ac = CONF_TX_AC_BK,
156 .cw_min = 15,
157 .cw_max = 63,
158 .aifsn = 7,
159 .tx_op_limit = 0,
160 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200161 [CONF_TX_AC_VI] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300162 .ac = CONF_TX_AC_VI,
163 .cw_min = 15,
164 .cw_max = 63,
165 .aifsn = CONF_TX_AIFS_PIFS,
166 .tx_op_limit = 3008,
167 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200168 [CONF_TX_AC_VO] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300169 .ac = CONF_TX_AC_VO,
170 .cw_min = 15,
171 .cw_max = 63,
172 .aifsn = CONF_TX_AIFS_PIFS,
173 .tx_op_limit = 1504,
174 },
175 },
Arik Nemtsov3618f302011-06-26 10:36:03 +0300176 .max_tx_retries = 100,
177 .ap_aging_period = 300,
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200178 .tid_conf_count = 4,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300179 .tid_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200180 [CONF_TX_AC_BE] = {
181 .queue_id = CONF_TX_AC_BE,
182 .channel_type = CONF_CHANNEL_TYPE_EDCF,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300183 .tsid = CONF_TX_AC_BE,
184 .ps_scheme = CONF_PS_SCHEME_LEGACY,
185 .ack_policy = CONF_ACK_POLICY_LEGACY,
186 .apsd_conf = {0, 0},
187 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200188 [CONF_TX_AC_BK] = {
189 .queue_id = CONF_TX_AC_BK,
190 .channel_type = CONF_CHANNEL_TYPE_EDCF,
191 .tsid = CONF_TX_AC_BK,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300192 .ps_scheme = CONF_PS_SCHEME_LEGACY,
193 .ack_policy = CONF_ACK_POLICY_LEGACY,
194 .apsd_conf = {0, 0},
195 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200196 [CONF_TX_AC_VI] = {
197 .queue_id = CONF_TX_AC_VI,
198 .channel_type = CONF_CHANNEL_TYPE_EDCF,
199 .tsid = CONF_TX_AC_VI,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300200 .ps_scheme = CONF_PS_SCHEME_LEGACY,
201 .ack_policy = CONF_ACK_POLICY_LEGACY,
202 .apsd_conf = {0, 0},
203 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200204 [CONF_TX_AC_VO] = {
205 .queue_id = CONF_TX_AC_VO,
206 .channel_type = CONF_CHANNEL_TYPE_EDCF,
207 .tsid = CONF_TX_AC_VO,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300208 .ps_scheme = CONF_PS_SCHEME_LEGACY,
209 .ack_policy = CONF_ACK_POLICY_LEGACY,
210 .apsd_conf = {0, 0},
211 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300212 },
213 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200214 .tx_compl_timeout = 700,
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300215 .tx_compl_threshold = 4,
216 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
217 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200218 .tmpl_short_retry_limit = 10,
219 .tmpl_long_retry_limit = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300220 },
221 .conn = {
222 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300223 .listen_interval = 1,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300224 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
Shahar Levibc76b942011-05-11 11:14:22 +0300225 .bcn_filt_ie_count = 2,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300226 .bcn_filt_ie = {
227 [0] = {
228 .ie = WLAN_EID_CHANNEL_SWITCH,
229 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
Shahar Levibc76b942011-05-11 11:14:22 +0300230 },
231 [1] = {
232 .ie = WLAN_EID_HT_INFORMATION,
233 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
234 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300235 },
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200236 .synch_fail_thold = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300237 .bss_lose_timeout = 100,
238 .beacon_rx_timeout = 10000,
239 .broadcast_timeout = 20000,
240 .rx_broadcast_in_ps = 1,
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300241 .ps_poll_threshold = 10,
Juuso Oikarinen11f70f92009-10-13 12:47:46 +0300242 .bet_enable = CONF_BET_MODE_ENABLE,
Ohad Ben-Cohen958b20e02011-03-14 18:53:10 +0200243 .bet_max_consecutive = 50,
Eliad Pellera879ed72011-08-23 16:37:02 +0300244 .psm_entry_retries = 8,
Shahar Levi23708412011-04-13 14:52:50 +0300245 .psm_exit_retries = 16,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200246 .psm_entry_nullfunc_retries = 3,
Eyal Shapiraf1d63a52012-01-31 11:57:21 +0200247 .dynamic_ps_timeout = 100,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300248 .keep_alive_interval = 55000,
249 .max_listen_interval = 20,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300250 },
Luciano Coelho6e92b412009-12-11 15:40:50 +0200251 .itrim = {
252 .enable = false,
253 .timeout = 50000,
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200254 },
255 .pm_config = {
256 .host_clk_settling_time = 5000,
257 .host_fast_wakeup_support = false
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300258 },
259 .roam_trigger = {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300260 .trigger_pacing = 1,
261 .avg_weight_rssi_beacon = 20,
262 .avg_weight_rssi_data = 10,
263 .avg_weight_snr_beacon = 20,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100264 .avg_weight_snr_data = 10,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200265 },
266 .scan = {
267 .min_dwell_time_active = 7500,
268 .max_dwell_time_active = 30000,
Juuso Oikarinenea45b2c2011-01-24 07:01:54 +0100269 .min_dwell_time_passive = 100000,
270 .max_dwell_time_passive = 100000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200271 .num_probe_reqs = 2,
272 },
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300273 .sched_scan = {
274 /* sched_scan requires dwell times in TU instead of TU/1000 */
Luciano Coelho221737d2011-09-02 14:28:22 +0300275 .min_dwell_time_active = 30,
276 .max_dwell_time_active = 60,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300277 .dwell_time_passive = 100,
Luciano Coelho50a66d72011-05-27 15:34:47 +0300278 .dwell_time_dfs = 150,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300279 .num_probe_reqs = 2,
280 .rssi_threshold = -90,
281 .snr_threshold = 0,
282 },
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200283 .rf = {
284 .tx_per_channel_power_compensation_2 = {
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 },
287 .tx_per_channel_power_compensation_5 = {
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 },
292 },
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100293 .ht = {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300294 .rx_ba_win_size = 8,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100295 .tx_ba_win_size = 64,
296 .inactivity_timeout = 10000,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300297 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100298 },
Shahar Levi13b107d2011-03-06 16:32:12 +0200299 .mem_wl127x = {
Eliad Pellerfe5ef092011-02-02 09:59:36 +0200300 .num_stations = 1,
301 .ssid_profiles = 1,
302 .rx_block_num = 70,
303 .tx_min_block_num = 40,
Ido Yariv4cf557f2011-04-18 16:45:10 +0300304 .dynamic_memory = 1,
Ido Yarivb16d4b62011-03-01 15:14:44 +0200305 .min_req_tx_blocks = 100,
Eliad Pellerc8bde242011-02-02 09:59:35 +0200306 .min_req_rx_blocks = 22,
307 .tx_min = 27,
Shahar Levi13b107d2011-03-06 16:32:12 +0200308 },
309 .mem_wl128x = {
310 .num_stations = 1,
311 .ssid_profiles = 1,
312 .rx_block_num = 40,
313 .tx_min_block_num = 40,
314 .dynamic_memory = 1,
315 .min_req_tx_blocks = 45,
316 .min_req_rx_blocks = 22,
317 .tx_min = 27,
318 },
Shahar Leviff868432011-04-11 15:41:46 +0300319 .fm_coex = {
320 .enable = true,
321 .swallow_period = 5,
322 .n_divider_fref_set_1 = 0xff, /* default */
323 .n_divider_fref_set_2 = 12,
324 .m_divider_fref_set_1 = 148,
325 .m_divider_fref_set_2 = 0xffff, /* default */
326 .coex_pll_stabilization_time = 0xffffffff, /* default */
327 .ldo_stabilization_time = 0xffff, /* default */
328 .fm_disturbed_band_margin = 0xff, /* default */
329 .swallow_clk_diff = 0xff, /* default */
330 },
Eliad Pellerf84673d2011-05-15 11:10:28 +0300331 .rx_streaming = {
332 .duration = 150,
333 .queues = 0x1,
334 .interval = 20,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300335 .always = 0,
Eliad Pellerf84673d2011-05-15 11:10:28 +0300336 },
Ido Yariv95dac04f2011-06-06 14:57:06 +0300337 .fwlog = {
338 .mode = WL12XX_FWLOG_ON_DEMAND,
339 .mem_blocks = 2,
340 .severity = 0,
341 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
342 .output = WL12XX_FWLOG_OUTPUT_HOST,
343 .threshold = 0,
344 },
Luciano Coelhoafb7d3c2011-04-01 20:48:02 +0300345 .hci_io_ds = HCI_IO_DS_6MA,
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300346 .rate = {
347 .rate_retry_score = 32000,
348 .per_add = 8192,
349 .per_th1 = 2048,
350 .per_th2 = 4096,
351 .max_per = 8100,
352 .inverse_curiosity_factor = 5,
353 .tx_fail_low_th = 4,
354 .tx_fail_high_th = 10,
355 .per_alpha_shift = 4,
356 .per_add_shift = 13,
357 .per_beta1_shift = 10,
358 .per_beta2_shift = 8,
359 .rate_check_up = 2,
360 .rate_check_down = 12,
361 .rate_retry_policy = {
362 0x00, 0x00, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x00,
364 0x00, 0x00, 0x00,
365 },
366 },
Eliad Peller94877752011-08-28 15:11:56 +0300367 .hangover = {
368 .recover_time = 0,
369 .hangover_period = 20,
370 .dynamic_mode = 1,
371 .early_termination_mode = 1,
372 .max_period = 20,
373 .min_period = 1,
374 .increase_delta = 1,
375 .decrease_delta = 2,
376 .quiet_time = 4,
377 .increase_time = 1,
378 .window_size = 16,
379 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300380};
381
Ido Yariv95dac04f2011-06-06 14:57:06 +0300382static char *fwlog_param;
Eliad Peller2a5bff02011-08-25 18:10:59 +0300383static bool bug_on_recovery;
Ido Yariv95dac04f2011-06-06 14:57:06 +0300384
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300385static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +0200386 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300387 bool reset_tx_queues);
Eliad Pellerf0277432011-10-10 10:13:14 +0200388static void wl1271_op_stop(struct ieee80211_hw *hw);
Eliad Peller170d0e62011-10-05 11:56:06 +0200389static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200390
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200391static DEFINE_MUTEX(wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +0300392static LIST_HEAD(wl_list);
393
Eliad Pellerba8447f2011-10-10 10:13:00 +0200394static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
395 unsigned char operstate)
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300396{
397 int ret;
Eliad Peller0603d892011-10-05 11:55:51 +0200398
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300399 if (operstate != IF_OPER_UP)
400 return 0;
401
Eliad Peller8181aec2011-10-10 10:13:04 +0200402 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300403 return 0;
404
Eliad Peller154da672011-10-05 11:55:53 +0200405 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300406 if (ret < 0)
407 return ret;
408
Eliad Peller0603d892011-10-05 11:55:51 +0200409 wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +0300410
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300411 wl1271_info("Association completed.");
412 return 0;
413}
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300414static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
415 void *arg)
416{
417 struct net_device *dev = arg;
418 struct wireless_dev *wdev;
419 struct wiphy *wiphy;
420 struct ieee80211_hw *hw;
421 struct wl1271 *wl;
422 struct wl1271 *wl_temp;
Eliad Pellerba8447f2011-10-10 10:13:00 +0200423 struct wl12xx_vif *wlvif;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300424 int ret = 0;
425
426 /* Check that this notification is for us. */
427 if (what != NETDEV_CHANGE)
428 return NOTIFY_DONE;
429
430 wdev = dev->ieee80211_ptr;
431 if (wdev == NULL)
432 return NOTIFY_DONE;
433
434 wiphy = wdev->wiphy;
435 if (wiphy == NULL)
436 return NOTIFY_DONE;
437
438 hw = wiphy_priv(wiphy);
439 if (hw == NULL)
440 return NOTIFY_DONE;
441
442 wl_temp = hw->priv;
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200443 mutex_lock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300444 list_for_each_entry(wl, &wl_list, list) {
445 if (wl == wl_temp)
446 break;
447 }
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200448 mutex_unlock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300449 if (wl != wl_temp)
450 return NOTIFY_DONE;
451
452 mutex_lock(&wl->mutex);
453
454 if (wl->state == WL1271_STATE_OFF)
455 goto out;
456
Eliad Peller6ab70912011-12-18 20:25:45 +0200457 if (dev->operstate != IF_OPER_UP)
458 goto out;
459 /*
460 * The correct behavior should be just getting the appropriate wlvif
461 * from the given dev, but currently we don't have a mac80211
462 * interface for it.
463 */
Eliad Pellerba8447f2011-10-10 10:13:00 +0200464 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller6ab70912011-12-18 20:25:45 +0200465 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
466
Eliad Pellerba8447f2011-10-10 10:13:00 +0200467 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
468 continue;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300469
Eliad Pellerba8447f2011-10-10 10:13:00 +0200470 ret = wl1271_ps_elp_wakeup(wl);
471 if (ret < 0)
472 goto out;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300473
Eliad Peller6ab70912011-12-18 20:25:45 +0200474 wl1271_check_operstate(wl, wlvif,
475 ieee80211_get_operstate(vif));
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300476
Eliad Pellerba8447f2011-10-10 10:13:00 +0200477 wl1271_ps_elp_sleep(wl);
478 }
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300479out:
480 mutex_unlock(&wl->mutex);
481
482 return NOTIFY_OK;
483}
484
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100485static int wl1271_reg_notify(struct wiphy *wiphy,
Luciano Coelho573c67c2010-11-26 13:44:59 +0200486 struct regulatory_request *request)
487{
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100488 struct ieee80211_supported_band *band;
489 struct ieee80211_channel *ch;
490 int i;
491
492 band = wiphy->bands[IEEE80211_BAND_5GHZ];
493 for (i = 0; i < band->n_channels; i++) {
494 ch = &band->channels[i];
495 if (ch->flags & IEEE80211_CHAN_DISABLED)
496 continue;
497
498 if (ch->flags & IEEE80211_CHAN_RADAR)
499 ch->flags |= IEEE80211_CHAN_NO_IBSS |
500 IEEE80211_CHAN_PASSIVE_SCAN;
501
502 }
503
504 return 0;
505}
506
Eliad Peller9eb599e2011-10-10 10:12:59 +0200507static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
508 bool enable)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300509{
510 int ret = 0;
511
512 /* we should hold wl->mutex */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200513 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300514 if (ret < 0)
515 goto out;
516
517 if (enable)
Eliad Peller0744bdb2011-10-10 10:13:05 +0200518 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300519 else
Eliad Peller0744bdb2011-10-10 10:13:05 +0200520 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300521out:
522 return ret;
523}
524
525/*
526 * this function is being called when the rx_streaming interval
527 * has beed changed or rx_streaming should be disabled
528 */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200529int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300530{
531 int ret = 0;
532 int period = wl->conf.rx_streaming.interval;
533
534 /* don't reconfigure if rx_streaming is disabled */
Eliad Peller0744bdb2011-10-10 10:13:05 +0200535 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300536 goto out;
537
538 /* reconfigure/disable according to new streaming_period */
539 if (period &&
Eliad Pellerba8447f2011-10-10 10:13:00 +0200540 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eliad Peller77ddaa12011-05-15 11:10:29 +0300541 (wl->conf.rx_streaming.always ||
542 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
Eliad Peller9eb599e2011-10-10 10:12:59 +0200543 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300544 else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200545 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300546 /* don't cancel_work_sync since we might deadlock */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200547 del_timer_sync(&wlvif->rx_streaming_timer);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300548 }
549out:
550 return ret;
551}
552
553static void wl1271_rx_streaming_enable_work(struct work_struct *work)
554{
555 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200556 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
557 rx_streaming_enable_work);
558 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300559
560 mutex_lock(&wl->mutex);
561
Eliad Peller0744bdb2011-10-10 10:13:05 +0200562 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
Eliad Pellerba8447f2011-10-10 10:13:00 +0200563 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller77ddaa12011-05-15 11:10:29 +0300564 (!wl->conf.rx_streaming.always &&
565 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
566 goto out;
567
568 if (!wl->conf.rx_streaming.interval)
569 goto out;
570
571 ret = wl1271_ps_elp_wakeup(wl);
572 if (ret < 0)
573 goto out;
574
Eliad Peller9eb599e2011-10-10 10:12:59 +0200575 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300576 if (ret < 0)
577 goto out_sleep;
578
579 /* stop it after some time of inactivity */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200580 mod_timer(&wlvif->rx_streaming_timer,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300581 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
582
583out_sleep:
584 wl1271_ps_elp_sleep(wl);
585out:
586 mutex_unlock(&wl->mutex);
587}
588
589static void wl1271_rx_streaming_disable_work(struct work_struct *work)
590{
591 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200592 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
593 rx_streaming_disable_work);
594 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300595
596 mutex_lock(&wl->mutex);
597
Eliad Peller0744bdb2011-10-10 10:13:05 +0200598 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300599 goto out;
600
601 ret = wl1271_ps_elp_wakeup(wl);
602 if (ret < 0)
603 goto out;
604
Eliad Peller9eb599e2011-10-10 10:12:59 +0200605 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300606 if (ret)
607 goto out_sleep;
608
609out_sleep:
610 wl1271_ps_elp_sleep(wl);
611out:
612 mutex_unlock(&wl->mutex);
613}
614
615static void wl1271_rx_streaming_timer(unsigned long data)
616{
Eliad Peller9eb599e2011-10-10 10:12:59 +0200617 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
618 struct wl1271 *wl = wlvif->wl;
619 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300620}
621
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300622static void wl1271_conf_init(struct wl1271 *wl)
623{
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300624
625 /*
626 * This function applies the default configuration to the driver. This
627 * function is invoked upon driver load (spi probe.)
628 *
629 * The configuration is stored in a run-time structure in order to
630 * facilitate for run-time adjustment of any of the parameters. Making
631 * changes to the configuration structure will apply the new values on
632 * the next interface up (wl1271_op_start.)
633 */
634
635 /* apply driver default configuration */
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300636 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300637
Ido Yariv95dac04f2011-06-06 14:57:06 +0300638 /* Adjust settings according to optional module parameters */
639 if (fwlog_param) {
640 if (!strcmp(fwlog_param, "continuous")) {
641 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
642 } else if (!strcmp(fwlog_param, "ondemand")) {
643 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
644 } else if (!strcmp(fwlog_param, "dbgpins")) {
645 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
646 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
647 } else if (!strcmp(fwlog_param, "disable")) {
648 wl->conf.fwlog.mem_blocks = 0;
649 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
650 } else {
651 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
652 }
653 }
654}
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300655
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300656static int wl1271_plt_init(struct wl1271 *wl)
657{
Eliad Peller188e7f52011-12-06 12:15:06 +0200658 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300659
Shahar Levi49d750ca2011-03-06 16:32:09 +0200660 if (wl->chip.id == CHIP_ID_1283_PG20)
661 ret = wl128x_cmd_general_parms(wl);
662 else
663 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200664 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200665 return ret;
666
Shahar Levi49d750ca2011-03-06 16:32:09 +0200667 if (wl->chip.id == CHIP_ID_1283_PG20)
668 ret = wl128x_cmd_radio_parms(wl);
669 else
670 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200671 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200672 return ret;
673
Shahar Levi49d750ca2011-03-06 16:32:09 +0200674 if (wl->chip.id != CHIP_ID_1283_PG20) {
675 ret = wl1271_cmd_ext_radio_parms(wl);
676 if (ret < 0)
677 return ret;
678 }
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200679 if (ret < 0)
680 return ret;
681
Shahar Levi48a61472011-03-06 16:32:08 +0200682 /* Chip-specific initializations */
683 ret = wl1271_chip_specific_init(wl);
684 if (ret < 0)
685 return ret;
686
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300687 ret = wl1271_acx_init_mem_config(wl);
688 if (ret < 0)
689 return ret;
690
Eliad Peller7f0979882011-08-14 13:17:06 +0300691 ret = wl12xx_acx_mem_cfg(wl);
Gery Kahn1ec610e2011-02-01 03:03:08 -0600692 if (ret < 0)
693 goto out_free_memmap;
694
Luciano Coelho12419cc2010-02-18 13:25:44 +0200695 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200696 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300697 if (ret < 0)
Luciano Coelho12419cc2010-02-18 13:25:44 +0200698 goto out_free_memmap;
699
700 /* Configure for CAM power saving (ie. always active) */
701 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
702 if (ret < 0)
703 goto out_free_memmap;
704
705 /* configure PM */
706 ret = wl1271_acx_pm_config(wl);
707 if (ret < 0)
708 goto out_free_memmap;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300709
710 return 0;
Luciano Coelho12419cc2010-02-18 13:25:44 +0200711
712 out_free_memmap:
713 kfree(wl->target_mem_map);
714 wl->target_mem_map = NULL;
715
716 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300717}
718
Eliad Peller6e8cd332011-10-10 10:13:13 +0200719static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
720 struct wl12xx_vif *wlvif,
721 u8 hlid, u8 tx_pkts)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200722{
Arik Nemtsovda032092011-08-25 12:43:15 +0300723 bool fw_ps, single_sta;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200724
Arik Nemtsovb622d992011-02-23 00:22:31 +0200725 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Arik Nemtsovda032092011-08-25 12:43:15 +0300726 single_sta = (wl->active_sta_count == 1);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200727
728 /*
729 * Wake up from high level PS if the STA is asleep with too little
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300730 * packets in FW or if the STA is awake.
Arik Nemtsovb622d992011-02-23 00:22:31 +0200731 */
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300732 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200733 wl12xx_ps_link_end(wl, wlvif, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200734
Arik Nemtsovda032092011-08-25 12:43:15 +0300735 /*
736 * Start high-level PS if the STA is asleep with enough blocks in FW.
737 * Make an exception if this is the only connected station. In this
738 * case FW-memory congestion is not a problem.
739 */
740 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200741 wl12xx_ps_link_start(wl, wlvif, hlid, true);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200742}
743
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300744static void wl12xx_irq_update_links_status(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200745 struct wl12xx_vif *wlvif,
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300746 struct wl12xx_fw_status *status)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200747{
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200748 struct wl1271_link *lnk;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200749 u32 cur_fw_ps_map;
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300750 u8 hlid, cnt;
751
752 /* TODO: also use link_fast_bitmap here */
Arik Nemtsovb622d992011-02-23 00:22:31 +0200753
754 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
755 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
756 wl1271_debug(DEBUG_PSM,
757 "link ps prev 0x%x cur 0x%x changed 0x%x",
758 wl->ap_fw_ps_map, cur_fw_ps_map,
759 wl->ap_fw_ps_map ^ cur_fw_ps_map);
760
761 wl->ap_fw_ps_map = cur_fw_ps_map;
762 }
763
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200764 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
765 lnk = &wl->links[hlid];
766 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200767
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200768 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
769 lnk->allocated_pkts -= cnt;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200770
Eliad Peller6e8cd332011-10-10 10:13:13 +0200771 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
772 lnk->allocated_pkts);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200773 }
774}
775
Eliad Peller4d56ad92011-08-14 13:17:05 +0300776static void wl12xx_fw_status(struct wl1271 *wl,
777 struct wl12xx_fw_status *status)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300778{
Eliad Peller6e8cd332011-10-10 10:13:13 +0200779 struct wl12xx_vif *wlvif;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200780 struct timespec ts;
Shahar Levi13b107d2011-03-06 16:32:12 +0200781 u32 old_tx_blk_count = wl->tx_blocks_available;
Eliad Peller4d56ad92011-08-14 13:17:05 +0300782 int avail, freed_blocks;
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300783 int i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300784
Eliad Peller4d56ad92011-08-14 13:17:05 +0300785 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
Shahar Levi13b107d2011-03-06 16:32:12 +0200786
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300787 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
788 "drv_rx_counter = %d, tx_results_counter = %d)",
789 status->intr,
790 status->fw_rx_counter,
791 status->drv_rx_counter,
792 status->tx_results_counter);
793
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300794 for (i = 0; i < NUM_TX_QUEUES; i++) {
795 /* prevent wrap-around in freed-packets counter */
Arik Nemtsov742246f2011-08-14 13:17:33 +0300796 wl->tx_allocated_pkts[i] -=
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300797 (status->tx_released_pkts[i] -
798 wl->tx_pkts_freed[i]) & 0xff;
799
800 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
801 }
802
Arik Nemtsovbdf91cf2011-08-14 13:17:34 +0300803 /* prevent wrap-around in total blocks counter */
804 if (likely(wl->tx_blocks_freed <=
805 le32_to_cpu(status->total_released_blks)))
806 freed_blocks = le32_to_cpu(status->total_released_blks) -
807 wl->tx_blocks_freed;
808 else
809 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
810 le32_to_cpu(status->total_released_blks);
811
Eliad Peller4d56ad92011-08-14 13:17:05 +0300812 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
Shahar Levi13b107d2011-03-06 16:32:12 +0200813
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300814 wl->tx_allocated_blocks -= freed_blocks;
815
Eliad Peller4d56ad92011-08-14 13:17:05 +0300816 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200817
Eliad Peller4d56ad92011-08-14 13:17:05 +0300818 /*
819 * The FW might change the total number of TX memblocks before
820 * we get a notification about blocks being released. Thus, the
821 * available blocks calculation might yield a temporary result
822 * which is lower than the actual available blocks. Keeping in
823 * mind that only blocks that were allocated can be moved from
824 * TX to RX, tx_blocks_available should never decrease here.
825 */
826 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
827 avail);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300828
Ido Yariva5225502010-10-12 14:49:10 +0200829 /* if more blocks are available now, tx work can be scheduled */
Shahar Levi13b107d2011-03-06 16:32:12 +0200830 if (wl->tx_blocks_available > old_tx_blk_count)
Ido Yariva5225502010-10-12 14:49:10 +0200831 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300832
Eliad Peller4d56ad92011-08-14 13:17:05 +0300833 /* for AP update num of allocated TX blocks per link and ps status */
Eliad Peller6e8cd332011-10-10 10:13:13 +0200834 wl12xx_for_each_wlvif_ap(wl, wlvif) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200835 wl12xx_irq_update_links_status(wl, wlvif, status);
Eliad Peller6e8cd332011-10-10 10:13:13 +0200836 }
Eliad Peller4d56ad92011-08-14 13:17:05 +0300837
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300838 /* update the host-chipset time offset */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200839 getnstimeofday(&ts);
840 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
841 (s64)le32_to_cpu(status->fw_localtime);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300842}
843
Ido Yariva6208652011-03-01 15:14:41 +0200844static void wl1271_flush_deferred_work(struct wl1271 *wl)
845{
846 struct sk_buff *skb;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200847
Ido Yariva6208652011-03-01 15:14:41 +0200848 /* Pass all received frames to the network stack */
849 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
850 ieee80211_rx_ni(wl->hw, skb);
851
852 /* Return sent skbs to the network stack */
853 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300854 ieee80211_tx_status_ni(wl->hw, skb);
Ido Yariva6208652011-03-01 15:14:41 +0200855}
856
857static void wl1271_netstack_work(struct work_struct *work)
858{
859 struct wl1271 *wl =
860 container_of(work, struct wl1271, netstack_work);
861
862 do {
863 wl1271_flush_deferred_work(wl);
864 } while (skb_queue_len(&wl->deferred_rx_queue));
865}
866
867#define WL1271_IRQ_MAX_LOOPS 256
868
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300869static irqreturn_t wl1271_irq(int irq, void *cookie)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300870{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300871 int ret;
Juuso Oikarinenc15f63b2009-10-12 15:08:50 +0300872 u32 intr;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200873 int loopcount = WL1271_IRQ_MAX_LOOPS;
Ido Yariva6208652011-03-01 15:14:41 +0200874 struct wl1271 *wl = (struct wl1271 *)cookie;
875 bool done = false;
876 unsigned int defer_count;
Ido Yarivb07d4032011-03-01 15:14:43 +0200877 unsigned long flags;
878
879 /* TX might be handled here, avoid redundant work */
880 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
881 cancel_work_sync(&wl->tx_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300882
Ido Yariv341b7cd2011-03-31 10:07:01 +0200883 /*
884 * In case edge triggered interrupt must be used, we cannot iterate
885 * more than once without introducing race conditions with the hardirq.
886 */
887 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
888 loopcount = 1;
889
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300890 mutex_lock(&wl->mutex);
891
892 wl1271_debug(DEBUG_IRQ, "IRQ work");
893
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200894 if (unlikely(wl->state == WL1271_STATE_OFF))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300895 goto out;
896
Ido Yariva6208652011-03-01 15:14:41 +0200897 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300898 if (ret < 0)
899 goto out;
900
Ido Yariva6208652011-03-01 15:14:41 +0200901 while (!done && loopcount--) {
902 /*
903 * In order to avoid a race with the hardirq, clear the flag
904 * before acknowledging the chip. Since the mutex is held,
905 * wl1271_ps_elp_wakeup cannot be called concurrently.
906 */
907 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
908 smp_mb__after_clear_bit();
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200909
Eliad Peller4d56ad92011-08-14 13:17:05 +0300910 wl12xx_fw_status(wl, wl->fw_status);
911 intr = le32_to_cpu(wl->fw_status->intr);
Ido Yariva6208652011-03-01 15:14:41 +0200912 intr &= WL1271_INTR_MASK;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200913 if (!intr) {
Ido Yariva6208652011-03-01 15:14:41 +0200914 done = true;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200915 continue;
916 }
917
Eliad Pellerccc83b02010-10-27 14:09:57 +0200918 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
919 wl1271_error("watchdog interrupt received! "
920 "starting recovery.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300921 wl12xx_queue_recovery_work(wl);
Eliad Pellerccc83b02010-10-27 14:09:57 +0200922
923 /* restarting the chip. ignore any other interrupt. */
924 goto out;
925 }
926
Ido Yariva6208652011-03-01 15:14:41 +0200927 if (likely(intr & WL1271_ACX_INTR_DATA)) {
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200928 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
929
Eliad Peller4d56ad92011-08-14 13:17:05 +0300930 wl12xx_rx(wl, wl->fw_status);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200931
Ido Yariva5225502010-10-12 14:49:10 +0200932 /* Check if any tx blocks were freed */
Ido Yarivb07d4032011-03-01 15:14:43 +0200933 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200934 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300935 wl1271_tx_total_queue_count(wl) > 0) {
Ido Yarivb07d4032011-03-01 15:14:43 +0200936 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200937 /*
938 * In order to avoid starvation of the TX path,
939 * call the work function directly.
940 */
Eliad Pellera32d0cd2011-10-10 10:12:55 +0200941 wl1271_tx_work_locked(wl);
Ido Yarivb07d4032011-03-01 15:14:43 +0200942 } else {
943 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200944 }
945
Ido Yariv8aad2462011-03-01 15:14:38 +0200946 /* check for tx results */
Eliad Peller4d56ad92011-08-14 13:17:05 +0300947 if (wl->fw_status->tx_results_counter !=
Ido Yariv8aad2462011-03-01 15:14:38 +0200948 (wl->tx_results_count & 0xff))
949 wl1271_tx_complete(wl);
Ido Yariva6208652011-03-01 15:14:41 +0200950
951 /* Make sure the deferred queues don't get too long */
952 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
953 skb_queue_len(&wl->deferred_rx_queue);
954 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
955 wl1271_flush_deferred_work(wl);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200956 }
957
958 if (intr & WL1271_ACX_INTR_EVENT_A) {
959 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
960 wl1271_event_handle(wl, 0);
961 }
962
963 if (intr & WL1271_ACX_INTR_EVENT_B) {
964 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
965 wl1271_event_handle(wl, 1);
966 }
967
968 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
969 wl1271_debug(DEBUG_IRQ,
970 "WL1271_ACX_INTR_INIT_COMPLETE");
971
972 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
973 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300974 }
975
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300976 wl1271_ps_elp_sleep(wl);
977
978out:
Ido Yarivb07d4032011-03-01 15:14:43 +0200979 spin_lock_irqsave(&wl->wl_lock, flags);
980 /* In case TX was not handled here, queue TX work */
981 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
982 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300983 wl1271_tx_total_queue_count(wl) > 0)
Ido Yarivb07d4032011-03-01 15:14:43 +0200984 ieee80211_queue_work(wl->hw, &wl->tx_work);
985 spin_unlock_irqrestore(&wl->wl_lock, flags);
986
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300987 mutex_unlock(&wl->mutex);
Ido Yariva6208652011-03-01 15:14:41 +0200988
989 return IRQ_HANDLED;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300990}
991
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300992static int wl1271_fetch_firmware(struct wl1271 *wl)
993{
994 const struct firmware *fw;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200995 const char *fw_name;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300996 int ret;
997
Arik Nemtsovc302b2c2011-08-17 10:45:48 +0300998 if (wl->chip.id == CHIP_ID_1283_PG20)
999 fw_name = WL128X_FW_NAME;
1000 else
1001 fw_name = WL127X_FW_NAME;
Arik Nemtsov166d5042010-10-16 21:44:57 +02001002
1003 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1004
Felipe Balbia390e852011-10-06 10:07:44 +03001005 ret = request_firmware(&fw, fw_name, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001006
1007 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001008 wl1271_error("could not get firmware %s: %d", fw_name, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001009 return ret;
1010 }
1011
1012 if (fw->size % 4) {
1013 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1014 fw->size);
1015 ret = -EILSEQ;
1016 goto out;
1017 }
1018
Arik Nemtsov166d5042010-10-16 21:44:57 +02001019 vfree(wl->fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001020 wl->fw_len = fw->size;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +03001021 wl->fw = vmalloc(wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001022
1023 if (!wl->fw) {
1024 wl1271_error("could not allocate memory for the firmware");
1025 ret = -ENOMEM;
1026 goto out;
1027 }
1028
1029 memcpy(wl->fw, fw->data, wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001030 ret = 0;
1031
1032out:
1033 release_firmware(fw);
1034
1035 return ret;
1036}
1037
1038static int wl1271_fetch_nvs(struct wl1271 *wl)
1039{
1040 const struct firmware *fw;
1041 int ret;
1042
Felipe Balbia390e852011-10-06 10:07:44 +03001043 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001044
1045 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001046 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1047 ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001048 return ret;
1049 }
1050
Shahar Levibc765bf2011-03-06 16:32:10 +02001051 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001052
1053 if (!wl->nvs) {
1054 wl1271_error("could not allocate memory for the nvs file");
1055 ret = -ENOMEM;
1056 goto out;
1057 }
1058
Juuso Oikarinen02fabb02010-08-19 04:41:15 +02001059 wl->nvs_len = fw->size;
1060
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001061out:
1062 release_firmware(fw);
1063
1064 return ret;
1065}
1066
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001067void wl12xx_queue_recovery_work(struct wl1271 *wl)
1068{
1069 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1070 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1071}
1072
Ido Yariv95dac04f2011-06-06 14:57:06 +03001073size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1074{
1075 size_t len = 0;
1076
1077 /* The FW log is a length-value list, find where the log end */
1078 while (len < maxlen) {
1079 if (memblock[len] == 0)
1080 break;
1081 if (len + memblock[len] + 1 > maxlen)
1082 break;
1083 len += memblock[len] + 1;
1084 }
1085
1086 /* Make sure we have enough room */
1087 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1088
1089 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1090 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1091 wl->fwlog_size += len;
1092
1093 return len;
1094}
1095
1096static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1097{
1098 u32 addr;
1099 u32 first_addr;
1100 u8 *block;
1101
1102 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1103 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1104 (wl->conf.fwlog.mem_blocks == 0))
1105 return;
1106
1107 wl1271_info("Reading FW panic log");
1108
1109 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1110 if (!block)
1111 return;
1112
1113 /*
1114 * Make sure the chip is awake and the logger isn't active.
1115 * This might fail if the firmware hanged.
1116 */
1117 if (!wl1271_ps_elp_wakeup(wl))
1118 wl12xx_cmd_stop_fwlog(wl);
1119
1120 /* Read the first memory block address */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001121 wl12xx_fw_status(wl, wl->fw_status);
1122 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001123 if (!first_addr)
1124 goto out;
1125
1126 /* Traverse the memory blocks linked list */
1127 addr = first_addr;
1128 do {
1129 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1130 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1131 false);
1132
1133 /*
1134 * Memory blocks are linked to one another. The first 4 bytes
1135 * of each memory block hold the hardware address of the next
1136 * one. The last memory block points to the first one.
1137 */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001138 addr = le32_to_cpup((__le32 *)block);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001139 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1140 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1141 break;
1142 } while (addr && (addr != first_addr));
1143
1144 wake_up_interruptible(&wl->fwlog_waitq);
1145
1146out:
1147 kfree(block);
1148}
1149
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001150static void wl1271_recovery_work(struct work_struct *work)
1151{
1152 struct wl1271 *wl =
1153 container_of(work, struct wl1271, recovery_work);
Eliad Peller48e93e42011-10-10 10:12:58 +02001154 struct wl12xx_vif *wlvif;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001155 struct ieee80211_vif *vif;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001156
1157 mutex_lock(&wl->mutex);
1158
1159 if (wl->state != WL1271_STATE_ON)
Eliad Pellerf0277432011-10-10 10:13:14 +02001160 goto out_unlock;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001161
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001162 /* Avoid a recursive recovery */
1163 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1164
Ido Yariv95dac04f2011-06-06 14:57:06 +03001165 wl12xx_read_fwlog_panic(wl);
1166
Arik Nemtsov52dcaf52011-04-18 14:15:24 +03001167 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1168 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001169
Eliad Peller2a5bff02011-08-25 18:10:59 +03001170 BUG_ON(bug_on_recovery);
1171
Oz Krakowskib992c682011-06-26 10:36:02 +03001172 /*
1173 * Advance security sequence number to overcome potential progress
1174 * in the firmware during recovery. This doens't hurt if the network is
1175 * not encrypted.
1176 */
Eliad Peller48e93e42011-10-10 10:12:58 +02001177 wl12xx_for_each_wlvif(wl, wlvif) {
Eliad Pellerba8447f2011-10-10 10:13:00 +02001178 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller53d40d02011-10-10 10:13:02 +02001179 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Peller48e93e42011-10-10 10:12:58 +02001180 wlvif->tx_security_seq +=
1181 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1182 }
Oz Krakowskib992c682011-06-26 10:36:02 +03001183
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001184 /* Prevent spurious TX during FW restart */
1185 ieee80211_stop_queues(wl->hw);
1186
Luciano Coelho33c2c062011-05-10 14:46:02 +03001187 if (wl->sched_scanning) {
1188 ieee80211_sched_scan_stopped(wl->hw);
1189 wl->sched_scanning = false;
1190 }
1191
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001192 /* reboot the chipset */
Eliad Peller6e8cd332011-10-10 10:13:13 +02001193 while (!list_empty(&wl->wlvif_list)) {
1194 wlvif = list_first_entry(&wl->wlvif_list,
1195 struct wl12xx_vif, list);
1196 vif = wl12xx_wlvif_to_vif(wlvif);
1197 __wl1271_op_remove_interface(wl, vif, false);
1198 }
Eliad Pellerf0277432011-10-10 10:13:14 +02001199 mutex_unlock(&wl->mutex);
1200 wl1271_op_stop(wl->hw);
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001201
1202 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1203
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001204 ieee80211_restart_hw(wl->hw);
1205
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001206 /*
1207 * Its safe to enable TX now - the queues are stopped after a request
1208 * to restart the HW.
1209 */
1210 ieee80211_wake_queues(wl->hw);
Eliad Pellerf0277432011-10-10 10:13:14 +02001211 return;
1212out_unlock:
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001213 mutex_unlock(&wl->mutex);
1214}
1215
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001216static void wl1271_fw_wakeup(struct wl1271 *wl)
1217{
1218 u32 elp_reg;
1219
1220 elp_reg = ELPCTRL_WAKE_UP;
Juuso Oikarinen74621412009-10-12 15:08:54 +03001221 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001222}
1223
1224static int wl1271_setup(struct wl1271 *wl)
1225{
1226 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1227 if (!wl->fw_status)
1228 return -ENOMEM;
1229
1230 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1231 if (!wl->tx_res_if) {
1232 kfree(wl->fw_status);
1233 return -ENOMEM;
1234 }
1235
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001236 return 0;
1237}
1238
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001239static int wl12xx_set_power_on(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001240{
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001241 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001242
Juuso Oikarinen01ac17ec2009-12-11 15:41:02 +02001243 msleep(WL1271_PRE_POWER_ON_SLEEP);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +02001244 ret = wl1271_power_on(wl);
1245 if (ret < 0)
1246 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001247 msleep(WL1271_POWER_ON_SLEEP);
Teemu Paasikivi9b280722010-02-18 13:25:56 +02001248 wl1271_io_reset(wl);
1249 wl1271_io_init(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001250
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001251 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001252
1253 /* ELP module wake up */
1254 wl1271_fw_wakeup(wl);
1255
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001256out:
1257 return ret;
1258}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001259
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001260static int wl1271_chip_wakeup(struct wl1271 *wl)
1261{
1262 int ret = 0;
1263
1264 ret = wl12xx_set_power_on(wl);
1265 if (ret < 0)
1266 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001267
Luciano Coelhoe62c9ce2011-11-03 08:44:42 +02001268 /*
1269 * For wl127x based devices we could use the default block
1270 * size (512 bytes), but due to a bug in the sdio driver, we
1271 * need to set it explicitly after the chip is powered on. To
1272 * simplify the code and since the performance impact is
1273 * negligible, we use the same block size for all different
1274 * chip types.
1275 */
1276 if (!wl1271_set_block_size(wl))
1277 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001278
1279 switch (wl->chip.id) {
1280 case CHIP_ID_1271_PG10:
1281 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1282 wl->chip.id);
1283
1284 ret = wl1271_setup(wl);
1285 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001286 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001287 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001288 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001289
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001290 case CHIP_ID_1271_PG20:
1291 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1292 wl->chip.id);
1293
1294 ret = wl1271_setup(wl);
1295 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001296 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001297 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001298 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001299
Shahar Levi0830cee2011-03-06 16:32:20 +02001300 case CHIP_ID_1283_PG20:
1301 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1302 wl->chip.id);
1303
1304 ret = wl1271_setup(wl);
1305 if (ret < 0)
1306 goto out;
1307 break;
1308 case CHIP_ID_1283_PG10:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001309 default:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001310 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001311 ret = -ENODEV;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001312 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001313 }
1314
Arik Nemtsovc302b2c2011-08-17 10:45:48 +03001315 if (wl->fw == NULL) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001316 ret = wl1271_fetch_firmware(wl);
1317 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001318 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001319 }
1320
1321 /* No NVS from netlink, try to get it from the filesystem */
1322 if (wl->nvs == NULL) {
1323 ret = wl1271_fetch_nvs(wl);
1324 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001325 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001326 }
1327
1328out:
1329 return ret;
1330}
1331
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001332int wl1271_plt_start(struct wl1271 *wl)
1333{
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001334 int retries = WL1271_BOOT_RETRIES;
Gery Kahn6f07b722011-07-18 14:21:49 +03001335 struct wiphy *wiphy = wl->hw->wiphy;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001336 int ret;
1337
1338 mutex_lock(&wl->mutex);
1339
1340 wl1271_notice("power up");
1341
1342 if (wl->state != WL1271_STATE_OFF) {
1343 wl1271_error("cannot go into PLT state because not "
1344 "in off state: %d", wl->state);
1345 ret = -EBUSY;
1346 goto out;
1347 }
1348
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001349 while (retries) {
1350 retries--;
1351 ret = wl1271_chip_wakeup(wl);
1352 if (ret < 0)
1353 goto power_off;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001354
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001355 ret = wl1271_boot(wl);
1356 if (ret < 0)
1357 goto power_off;
1358
1359 ret = wl1271_plt_init(wl);
1360 if (ret < 0)
1361 goto irq_disable;
1362
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001363 wl->state = WL1271_STATE_PLT;
1364 wl1271_notice("firmware booted in PLT mode (%s)",
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001365 wl->chip.fw_ver_str);
Luciano Coelhoe7ddf542011-03-10 15:24:57 +02001366
Gery Kahn6f07b722011-07-18 14:21:49 +03001367 /* update hw/fw version info in wiphy struct */
1368 wiphy->hw_version = wl->chip.id;
1369 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1370 sizeof(wiphy->fw_version));
1371
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001372 goto out;
1373
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001374irq_disable:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001375 mutex_unlock(&wl->mutex);
1376 /* Unlocking the mutex in the middle of handling is
1377 inherently unsafe. In this case we deem it safe to do,
1378 because we need to let any possibly pending IRQ out of
1379 the system (and while we are WL1271_STATE_OFF the IRQ
1380 work function will not do anything.) Also, any other
1381 possible concurrent operations will fail due to the
1382 current state, hence the wl1271 struct should be safe. */
Ido Yariva6208652011-03-01 15:14:41 +02001383 wl1271_disable_interrupts(wl);
1384 wl1271_flush_deferred_work(wl);
1385 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001386 mutex_lock(&wl->mutex);
1387power_off:
1388 wl1271_power_off(wl);
1389 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001390
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001391 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1392 WL1271_BOOT_RETRIES);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001393out:
1394 mutex_unlock(&wl->mutex);
1395
1396 return ret;
1397}
1398
Ido Yarivf3df1332012-01-11 09:42:39 +02001399int wl1271_plt_stop(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001400{
1401 int ret = 0;
1402
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001403 wl1271_notice("power down");
1404
Ido Yariv46b0cc92012-01-11 09:42:41 +02001405 /*
1406 * Interrupts must be disabled before setting the state to OFF.
1407 * Otherwise, the interrupt handler might be called and exit without
1408 * reading the interrupt status.
1409 */
1410 wl1271_disable_interrupts(wl);
Ido Yarivf3df1332012-01-11 09:42:39 +02001411 mutex_lock(&wl->mutex);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001412 if (wl->state != WL1271_STATE_PLT) {
Ido Yarivf3df1332012-01-11 09:42:39 +02001413 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001414
1415 /*
1416 * This will not necessarily enable interrupts as interrupts
1417 * may have been disabled when op_stop was called. It will,
1418 * however, balance the above call to disable_interrupts().
1419 */
1420 wl1271_enable_interrupts(wl);
1421
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001422 wl1271_error("cannot power down because not in PLT "
1423 "state: %d", wl->state);
1424 ret = -EBUSY;
1425 goto out;
1426 }
1427
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001428 mutex_unlock(&wl->mutex);
Ido Yarivf3df1332012-01-11 09:42:39 +02001429
Ido Yariva6208652011-03-01 15:14:41 +02001430 wl1271_flush_deferred_work(wl);
1431 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001432 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001433 cancel_delayed_work_sync(&wl->elp_work);
Ido Yariva4549692012-01-11 09:42:40 +02001434
1435 mutex_lock(&wl->mutex);
1436 wl1271_power_off(wl);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001437 wl->flags = 0;
1438 wl->state = WL1271_STATE_OFF;
1439 wl->rx_counter = 0;
Ido Yariva4549692012-01-11 09:42:40 +02001440 mutex_unlock(&wl->mutex);
1441
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01001442out:
1443 return ret;
1444}
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +02001445
Johannes Berg7bb45682011-02-24 14:42:06 +01001446static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001447{
1448 struct wl1271 *wl = hw->priv;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001449 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1450 struct ieee80211_vif *vif = info->control.vif;
Eliad Peller0f168012011-10-11 13:52:25 +02001451 struct wl12xx_vif *wlvif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001452 unsigned long flags;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001453 int q, mapping;
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001454 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001455
Eliad Peller0f168012011-10-11 13:52:25 +02001456 if (vif)
1457 wlvif = wl12xx_vif_to_data(vif);
1458
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001459 mapping = skb_get_queue_mapping(skb);
1460 q = wl1271_tx_get_queue(mapping);
Ido Yarivb07d4032011-03-01 15:14:43 +02001461
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001462 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
Ido Yarivb07d4032011-03-01 15:14:43 +02001463
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001464 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yarivb07d4032011-03-01 15:14:43 +02001465
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001466 /* queue the packet */
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001467 if (hlid == WL12XX_INVALID_LINK_ID ||
Eliad Peller0f168012011-10-11 13:52:25 +02001468 (wlvif && !test_bit(hlid, wlvif->links_map))) {
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001469 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
Eliad Peller5de8eef2011-12-13 15:26:38 +02001470 ieee80211_free_txskb(hw, skb);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001471 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02001472 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001473
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001474 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1475 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1476
Arik Nemtsov04b4d692011-08-14 13:17:39 +03001477 wl->tx_queue_count[q]++;
1478
1479 /*
1480 * The workqueue is slow to process the tx_queue and we need stop
1481 * the queue here, otherwise the queue will get too long.
1482 */
1483 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1484 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1485 ieee80211_stop_queue(wl->hw, mapping);
1486 set_bit(q, &wl->stopped_queues_map);
1487 }
1488
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001489 /*
1490 * The chip specific setup must run before the first TX packet -
1491 * before that, the tx_work will not be initialized!
1492 */
1493
Ido Yarivb07d4032011-03-01 15:14:43 +02001494 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1495 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
Ido Yariva5225502010-10-12 14:49:10 +02001496 ieee80211_queue_work(wl->hw, &wl->tx_work);
Ido Yarivb07d4032011-03-01 15:14:43 +02001497
Arik Nemtsov04216da2011-08-14 13:17:38 +03001498out:
Ido Yarivb07d4032011-03-01 15:14:43 +02001499 spin_unlock_irqrestore(&wl->wl_lock, flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001500}
1501
Shahar Leviae47c452011-03-06 16:32:14 +02001502int wl1271_tx_dummy_packet(struct wl1271 *wl)
1503{
Ido Yariv990f5de2011-03-31 10:06:59 +02001504 unsigned long flags;
Arik Nemtsov14623782011-08-28 15:11:57 +03001505 int q;
1506
1507 /* no need to queue a new dummy packet if one is already pending */
1508 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1509 return 0;
1510
1511 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
Shahar Leviae47c452011-03-06 16:32:14 +02001512
Ido Yariv990f5de2011-03-31 10:06:59 +02001513 spin_lock_irqsave(&wl->wl_lock, flags);
1514 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +03001515 wl->tx_queue_count[q]++;
Ido Yariv990f5de2011-03-31 10:06:59 +02001516 spin_unlock_irqrestore(&wl->wl_lock, flags);
1517
1518 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1519 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
Eliad Pellera32d0cd2011-10-10 10:12:55 +02001520 wl1271_tx_work_locked(wl);
Ido Yariv990f5de2011-03-31 10:06:59 +02001521
1522 /*
1523 * If the FW TX is busy, TX work will be scheduled by the threaded
1524 * interrupt handler function
1525 */
1526 return 0;
1527}
1528
1529/*
1530 * The size of the dummy packet should be at least 1400 bytes. However, in
1531 * order to minimize the number of bus transactions, aligning it to 512 bytes
1532 * boundaries could be beneficial, performance wise
1533 */
1534#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1535
Luciano Coelhocf27d862011-04-01 21:08:23 +03001536static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
Ido Yariv990f5de2011-03-31 10:06:59 +02001537{
1538 struct sk_buff *skb;
1539 struct ieee80211_hdr_3addr *hdr;
1540 unsigned int dummy_packet_size;
1541
1542 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1543 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1544
1545 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
Shahar Leviae47c452011-03-06 16:32:14 +02001546 if (!skb) {
Ido Yariv990f5de2011-03-31 10:06:59 +02001547 wl1271_warning("Failed to allocate a dummy packet skb");
1548 return NULL;
Shahar Leviae47c452011-03-06 16:32:14 +02001549 }
1550
1551 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1552
1553 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1554 memset(hdr, 0, sizeof(*hdr));
1555 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
Ido Yariv990f5de2011-03-31 10:06:59 +02001556 IEEE80211_STYPE_NULLFUNC |
1557 IEEE80211_FCTL_TODS);
Shahar Leviae47c452011-03-06 16:32:14 +02001558
Ido Yariv990f5de2011-03-31 10:06:59 +02001559 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
Shahar Leviae47c452011-03-06 16:32:14 +02001560
Luciano Coelho18b92ff2011-03-21 16:35:21 +02001561 /* Dummy packets require the TID to be management */
1562 skb->priority = WL1271_TID_MGMT;
Ido Yariv990f5de2011-03-31 10:06:59 +02001563
1564 /* Initialize all fields that might be used */
Hauke Mehrtens86c438f2011-04-26 23:27:44 +02001565 skb_set_queue_mapping(skb, 0);
Ido Yariv990f5de2011-03-31 10:06:59 +02001566 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
Shahar Leviae47c452011-03-06 16:32:14 +02001567
Ido Yariv990f5de2011-03-31 10:06:59 +02001568 return skb;
Shahar Leviae47c452011-03-06 16:32:14 +02001569}
1570
Ido Yariv990f5de2011-03-31 10:06:59 +02001571
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03001572static struct notifier_block wl1271_dev_notifier = {
1573 .notifier_call = wl1271_dev_notify,
1574};
1575
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001576#ifdef CONFIG_PM
Eliad Peller94390642011-05-13 11:57:13 +03001577
Eliad Peller0603d892011-10-05 11:55:51 +02001578static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1579 struct wl12xx_vif *wlvif)
Eliad Peller94390642011-05-13 11:57:13 +03001580{
Eliad Pellere85d1622011-06-27 13:06:43 +03001581 int ret = 0;
Eliad Peller94390642011-05-13 11:57:13 +03001582
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001583 mutex_lock(&wl->mutex);
1584
Eliad Peller53d40d02011-10-10 10:13:02 +02001585 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Pellere85d1622011-06-27 13:06:43 +03001586 goto out_unlock;
1587
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001588 ret = wl1271_ps_elp_wakeup(wl);
1589 if (ret < 0)
1590 goto out_unlock;
1591
Eliad Peller0603d892011-10-05 11:55:51 +02001592 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001593
1594 wl1271_ps_elp_sleep(wl);
1595out_unlock:
1596 mutex_unlock(&wl->mutex);
1597 return ret;
1598
1599}
1600
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001601static int wl1271_configure_suspend(struct wl1271 *wl,
1602 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001603{
Eliad Peller536129c2011-10-05 11:55:45 +02001604 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
Eliad Peller0603d892011-10-05 11:55:51 +02001605 return wl1271_configure_suspend_ap(wl, wlvif);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001606 return 0;
1607}
1608
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001609static void wl1271_configure_resume(struct wl1271 *wl,
1610 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001611{
1612 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02001613 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001614
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02001615 if (!is_ap)
Eliad Peller94390642011-05-13 11:57:13 +03001616 return;
1617
1618 mutex_lock(&wl->mutex);
1619 ret = wl1271_ps_elp_wakeup(wl);
1620 if (ret < 0)
1621 goto out;
1622
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02001623 wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Eliad Peller94390642011-05-13 11:57:13 +03001624
1625 wl1271_ps_elp_sleep(wl);
1626out:
1627 mutex_unlock(&wl->mutex);
1628}
1629
Eliad Peller402e48612011-05-13 11:57:09 +03001630static int wl1271_op_suspend(struct ieee80211_hw *hw,
1631 struct cfg80211_wowlan *wow)
1632{
1633 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001634 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001635 int ret;
1636
Eliad Peller402e48612011-05-13 11:57:09 +03001637 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
Eliad Peller4a859df2011-06-06 12:21:52 +03001638 WARN_ON(!wow || !wow->any);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001639
Eliad Peller4a859df2011-06-06 12:21:52 +03001640 wl->wow_enabled = true;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001641 wl12xx_for_each_wlvif(wl, wlvif) {
1642 ret = wl1271_configure_suspend(wl, wlvif);
1643 if (ret < 0) {
1644 wl1271_warning("couldn't prepare device to suspend");
1645 return ret;
1646 }
Eliad Pellerf44e5862011-05-13 11:57:11 +03001647 }
Eliad Peller4a859df2011-06-06 12:21:52 +03001648 /* flush any remaining work */
1649 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
Eliad Peller4a859df2011-06-06 12:21:52 +03001650
1651 /*
1652 * disable and re-enable interrupts in order to flush
1653 * the threaded_irq
1654 */
1655 wl1271_disable_interrupts(wl);
1656
1657 /*
1658 * set suspended flag to avoid triggering a new threaded_irq
1659 * work. no need for spinlock as interrupts are disabled.
1660 */
1661 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1662
1663 wl1271_enable_interrupts(wl);
1664 flush_work(&wl->tx_work);
Eliad Peller4a859df2011-06-06 12:21:52 +03001665 flush_delayed_work(&wl->elp_work);
1666
Eliad Peller402e48612011-05-13 11:57:09 +03001667 return 0;
1668}
1669
1670static int wl1271_op_resume(struct ieee80211_hw *hw)
1671{
1672 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001673 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001674 unsigned long flags;
1675 bool run_irq_work = false;
1676
Eliad Peller402e48612011-05-13 11:57:09 +03001677 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1678 wl->wow_enabled);
Eliad Peller4a859df2011-06-06 12:21:52 +03001679 WARN_ON(!wl->wow_enabled);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001680
1681 /*
1682 * re-enable irq_work enqueuing, and call irq_work directly if
1683 * there is a pending work.
1684 */
Eliad Peller4a859df2011-06-06 12:21:52 +03001685 spin_lock_irqsave(&wl->wl_lock, flags);
1686 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1687 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1688 run_irq_work = true;
1689 spin_unlock_irqrestore(&wl->wl_lock, flags);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001690
Eliad Peller4a859df2011-06-06 12:21:52 +03001691 if (run_irq_work) {
1692 wl1271_debug(DEBUG_MAC80211,
1693 "run postponed irq_work directly");
1694 wl1271_irq(0, wl);
1695 wl1271_enable_interrupts(wl);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001696 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02001697 wl12xx_for_each_wlvif(wl, wlvif) {
1698 wl1271_configure_resume(wl, wlvif);
1699 }
Eliad Pellerff91afc2011-06-06 12:21:53 +03001700 wl->wow_enabled = false;
Eliad Pellerf44e5862011-05-13 11:57:11 +03001701
Eliad Peller402e48612011-05-13 11:57:09 +03001702 return 0;
1703}
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001704#endif
Eliad Peller402e48612011-05-13 11:57:09 +03001705
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001706static int wl1271_op_start(struct ieee80211_hw *hw)
1707{
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001708 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1709
1710 /*
1711 * We have to delay the booting of the hardware because
1712 * we need to know the local MAC address before downloading and
1713 * initializing the firmware. The MAC address cannot be changed
1714 * after boot, and without the proper MAC address, the firmware
1715 * will not function properly.
1716 *
1717 * The MAC address is first known when the corresponding interface
1718 * is added. That is where we will initialize the hardware.
1719 */
1720
Eyal Shapirad18da7f2012-01-31 11:57:25 +02001721 return 0;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001722}
1723
1724static void wl1271_op_stop(struct ieee80211_hw *hw)
1725{
Eliad Pellerbaf62772011-10-10 10:12:52 +02001726 struct wl1271 *wl = hw->priv;
1727 int i;
1728
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001729 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
Eliad Pellerbaf62772011-10-10 10:12:52 +02001730
Ido Yariv46b0cc92012-01-11 09:42:41 +02001731 /*
1732 * Interrupts must be disabled before setting the state to OFF.
1733 * Otherwise, the interrupt handler might be called and exit without
1734 * reading the interrupt status.
1735 */
1736 wl1271_disable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001737 mutex_lock(&wl->mutex);
1738 if (wl->state == WL1271_STATE_OFF) {
1739 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001740
1741 /*
1742 * This will not necessarily enable interrupts as interrupts
1743 * may have been disabled when op_stop was called. It will,
1744 * however, balance the above call to disable_interrupts().
1745 */
1746 wl1271_enable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001747 return;
1748 }
Ido Yariv46b0cc92012-01-11 09:42:41 +02001749
Eliad Pellerbaf62772011-10-10 10:12:52 +02001750 /*
1751 * this must be before the cancel_work calls below, so that the work
1752 * functions don't perform further work.
1753 */
1754 wl->state = WL1271_STATE_OFF;
Eliad Peller10c8cd02011-10-10 10:13:06 +02001755 mutex_unlock(&wl->mutex);
1756
1757 mutex_lock(&wl_list_mutex);
1758 list_del(&wl->list);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001759 mutex_unlock(&wl_list_mutex);
1760
Eliad Pellerbaf62772011-10-10 10:12:52 +02001761 wl1271_flush_deferred_work(wl);
1762 cancel_delayed_work_sync(&wl->scan_complete_work);
1763 cancel_work_sync(&wl->netstack_work);
1764 cancel_work_sync(&wl->tx_work);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001765 cancel_delayed_work_sync(&wl->elp_work);
1766
1767 /* let's notify MAC80211 about the remaining pending TX frames */
1768 wl12xx_tx_reset(wl, true);
1769 mutex_lock(&wl->mutex);
1770
1771 wl1271_power_off(wl);
1772
1773 wl->band = IEEE80211_BAND_2GHZ;
1774
1775 wl->rx_counter = 0;
1776 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1777 wl->tx_blocks_available = 0;
1778 wl->tx_allocated_blocks = 0;
1779 wl->tx_results_count = 0;
1780 wl->tx_packets_count = 0;
1781 wl->time_offset = 0;
Eliad Pellerbaf62772011-10-10 10:12:52 +02001782 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1783 wl->ap_fw_ps_map = 0;
1784 wl->ap_ps_map = 0;
1785 wl->sched_scanning = false;
1786 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1787 memset(wl->links_map, 0, sizeof(wl->links_map));
1788 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1789 wl->active_sta_count = 0;
1790
1791 /* The system link is always allocated */
1792 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1793
1794 /*
1795 * this is performed after the cancel_work calls and the associated
1796 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1797 * get executed before all these vars have been reset.
1798 */
1799 wl->flags = 0;
1800
1801 wl->tx_blocks_freed = 0;
1802
1803 for (i = 0; i < NUM_TX_QUEUES; i++) {
1804 wl->tx_pkts_freed[i] = 0;
1805 wl->tx_allocated_pkts[i] = 0;
1806 }
1807
1808 wl1271_debugfs_reset(wl);
1809
1810 kfree(wl->fw_status);
1811 wl->fw_status = NULL;
1812 kfree(wl->tx_res_if);
1813 wl->tx_res_if = NULL;
1814 kfree(wl->target_mem_map);
1815 wl->target_mem_map = NULL;
1816
1817 mutex_unlock(&wl->mutex);
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001818}
1819
Eliad Pellere5a359f2011-10-10 10:13:15 +02001820static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1821{
1822 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1823 WL12XX_MAX_RATE_POLICIES);
1824 if (policy >= WL12XX_MAX_RATE_POLICIES)
1825 return -EBUSY;
1826
1827 __set_bit(policy, wl->rate_policies_map);
1828 *idx = policy;
1829 return 0;
1830}
1831
1832static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1833{
1834 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1835 return;
1836
1837 __clear_bit(*idx, wl->rate_policies_map);
1838 *idx = WL12XX_MAX_RATE_POLICIES;
1839}
1840
Eliad Peller536129c2011-10-05 11:55:45 +02001841static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001842{
Eliad Peller536129c2011-10-05 11:55:45 +02001843 switch (wlvif->bss_type) {
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001844 case BSS_TYPE_AP_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001845 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001846 return WL1271_ROLE_P2P_GO;
1847 else
1848 return WL1271_ROLE_AP;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001849
1850 case BSS_TYPE_STA_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001851 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001852 return WL1271_ROLE_P2P_CL;
1853 else
1854 return WL1271_ROLE_STA;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001855
Eliad Peller227e81e2011-08-14 13:17:26 +03001856 case BSS_TYPE_IBSS:
1857 return WL1271_ROLE_IBSS;
1858
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001859 default:
Eliad Peller536129c2011-10-05 11:55:45 +02001860 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001861 }
1862 return WL12XX_INVALID_ROLE_TYPE;
1863}
1864
Eliad Peller83587502011-10-10 10:12:53 +02001865static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Eliad Peller87fbcb02011-10-05 11:55:41 +02001866{
Eliad Pellere936bbe2011-10-05 11:55:56 +02001867 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02001868 int i;
Eliad Pellere936bbe2011-10-05 11:55:56 +02001869
Eliad Peller48e93e42011-10-10 10:12:58 +02001870 /* clear everything but the persistent data */
1871 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
Eliad Pellere936bbe2011-10-05 11:55:56 +02001872
1873 switch (ieee80211_vif_type_p2p(vif)) {
1874 case NL80211_IFTYPE_P2P_CLIENT:
1875 wlvif->p2p = 1;
1876 /* fall-through */
1877 case NL80211_IFTYPE_STATION:
1878 wlvif->bss_type = BSS_TYPE_STA_BSS;
1879 break;
1880 case NL80211_IFTYPE_ADHOC:
1881 wlvif->bss_type = BSS_TYPE_IBSS;
1882 break;
1883 case NL80211_IFTYPE_P2P_GO:
1884 wlvif->p2p = 1;
1885 /* fall-through */
1886 case NL80211_IFTYPE_AP:
1887 wlvif->bss_type = BSS_TYPE_AP_BSS;
1888 break;
1889 default:
1890 wlvif->bss_type = MAX_BSS_TYPE;
1891 return -EOPNOTSUPP;
1892 }
1893
Eliad Peller0603d892011-10-05 11:55:51 +02001894 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02001895 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02001896 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001897
Eliad Pellere936bbe2011-10-05 11:55:56 +02001898 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1899 wlvif->bss_type == BSS_TYPE_IBSS) {
1900 /* init sta/ibss data */
1901 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001902 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1903 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1904 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001905 } else {
1906 /* init ap data */
1907 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1908 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001909 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1910 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1911 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1912 wl12xx_allocate_rate_policy(wl,
1913 &wlvif->ap.ucast_rate_idx[i]);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001914 }
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001915
Eliad Peller83587502011-10-10 10:12:53 +02001916 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1917 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001918 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001919 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
Eliad Peller30d0c8f2011-10-05 11:55:42 +02001920 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Peller6a899792011-10-05 11:55:58 +02001921 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1922
Eliad Peller1b92f152011-10-10 10:13:09 +02001923 /*
1924 * mac80211 configures some values globally, while we treat them
1925 * per-interface. thus, on init, we have to copy them from wl
1926 */
1927 wlvif->band = wl->band;
Eliad Peller61f845f2011-10-10 10:13:10 +02001928 wlvif->channel = wl->channel;
Eliad Peller6bd65022011-10-10 10:13:11 +02001929 wlvif->power_level = wl->power_level;
Eliad Peller1b92f152011-10-10 10:13:09 +02001930
Eliad Peller9eb599e2011-10-10 10:12:59 +02001931 INIT_WORK(&wlvif->rx_streaming_enable_work,
1932 wl1271_rx_streaming_enable_work);
1933 INIT_WORK(&wlvif->rx_streaming_disable_work,
1934 wl1271_rx_streaming_disable_work);
Eliad Peller87627212011-10-10 10:12:54 +02001935 INIT_LIST_HEAD(&wlvif->list);
Eliad Peller252efa42011-10-05 11:56:00 +02001936
Eliad Peller9eb599e2011-10-10 10:12:59 +02001937 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1938 (unsigned long) wlvif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001939 return 0;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001940}
1941
Eliad Peller1d095472011-10-10 10:12:49 +02001942static bool wl12xx_init_fw(struct wl1271 *wl)
1943{
1944 int retries = WL1271_BOOT_RETRIES;
1945 bool booted = false;
1946 struct wiphy *wiphy = wl->hw->wiphy;
1947 int ret;
1948
1949 while (retries) {
1950 retries--;
1951 ret = wl1271_chip_wakeup(wl);
1952 if (ret < 0)
1953 goto power_off;
1954
1955 ret = wl1271_boot(wl);
1956 if (ret < 0)
1957 goto power_off;
1958
1959 ret = wl1271_hw_init(wl);
1960 if (ret < 0)
1961 goto irq_disable;
1962
1963 booted = true;
1964 break;
1965
1966irq_disable:
1967 mutex_unlock(&wl->mutex);
1968 /* Unlocking the mutex in the middle of handling is
1969 inherently unsafe. In this case we deem it safe to do,
1970 because we need to let any possibly pending IRQ out of
1971 the system (and while we are WL1271_STATE_OFF the IRQ
1972 work function will not do anything.) Also, any other
1973 possible concurrent operations will fail due to the
1974 current state, hence the wl1271 struct should be safe. */
1975 wl1271_disable_interrupts(wl);
1976 wl1271_flush_deferred_work(wl);
1977 cancel_work_sync(&wl->netstack_work);
1978 mutex_lock(&wl->mutex);
1979power_off:
1980 wl1271_power_off(wl);
1981 }
1982
1983 if (!booted) {
1984 wl1271_error("firmware boot failed despite %d retries",
1985 WL1271_BOOT_RETRIES);
1986 goto out;
1987 }
1988
1989 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1990
1991 /* update hw/fw version info in wiphy struct */
1992 wiphy->hw_version = wl->chip.id;
1993 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1994 sizeof(wiphy->fw_version));
1995
1996 /*
1997 * Now we know if 11a is supported (info from the NVS), so disable
1998 * 11a channels if not supported
1999 */
2000 if (!wl->enable_11a)
2001 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2002
2003 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2004 wl->enable_11a ? "" : "not ");
2005
2006 wl->state = WL1271_STATE_ON;
2007out:
2008 return booted;
2009}
2010
Eliad Peller92e712d2011-12-18 20:25:43 +02002011static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2012{
2013 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2014}
2015
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002016static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2017 struct ieee80211_vif *vif)
2018{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002019 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002020 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002021 int ret = 0;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002022 u8 role_type;
Eliad Peller71125ab2010-10-28 21:46:43 +02002023 bool booted = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002024
Johannes Bergea086352012-01-19 09:29:58 +01002025 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2026 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Johannes Bergc1288b12012-01-19 09:29:57 +01002027
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002028 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
Eliad Peller045c7452011-08-28 15:23:01 +03002029 ieee80211_vif_type_p2p(vif), vif->addr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002030
2031 mutex_lock(&wl->mutex);
Eliad Pellerf750c822011-10-10 10:13:16 +02002032 ret = wl1271_ps_elp_wakeup(wl);
2033 if (ret < 0)
2034 goto out_unlock;
2035
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002036 if (wl->vif) {
Eliad Peller71125ab2010-10-28 21:46:43 +02002037 wl1271_debug(DEBUG_MAC80211,
2038 "multiple vifs are not supported yet");
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002039 ret = -EBUSY;
2040 goto out;
2041 }
2042
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002043 /*
2044 * in some very corner case HW recovery scenarios its possible to
2045 * get here before __wl1271_op_remove_interface is complete, so
2046 * opt out if that is the case.
2047 */
Eliad Peller10c8cd02011-10-10 10:13:06 +02002048 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2049 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002050 ret = -EBUSY;
2051 goto out;
2052 }
2053
Eliad Peller83587502011-10-10 10:12:53 +02002054 ret = wl12xx_init_vif_data(wl, vif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002055 if (ret < 0)
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002056 goto out;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002057
Eliad Peller252efa42011-10-05 11:56:00 +02002058 wlvif->wl = wl;
Eliad Peller536129c2011-10-05 11:55:45 +02002059 role_type = wl12xx_get_role_type(wl, wlvif);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002060 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2061 ret = -EINVAL;
2062 goto out;
2063 }
Eliad Peller1d095472011-10-10 10:12:49 +02002064
Eliad Peller784f6942011-10-05 11:55:39 +02002065 /*
Eliad Peller1d095472011-10-10 10:12:49 +02002066 * TODO: after the nvs issue will be solved, move this block
2067 * to start(), and make sure here the driver is ON.
Eliad Peller784f6942011-10-05 11:55:39 +02002068 */
Eliad Peller1d095472011-10-10 10:12:49 +02002069 if (wl->state == WL1271_STATE_OFF) {
2070 /*
2071 * we still need this in order to configure the fw
2072 * while uploading the nvs
2073 */
Luciano Coelho5e037e72011-12-23 09:32:17 +02002074 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002075
Eliad Peller1d095472011-10-10 10:12:49 +02002076 booted = wl12xx_init_fw(wl);
2077 if (!booted) {
2078 ret = -EINVAL;
2079 goto out;
Eliad Peller04e80792011-08-14 13:17:09 +03002080 }
Eliad Peller1d095472011-10-10 10:12:49 +02002081 }
Eliad Peller04e80792011-08-14 13:17:09 +03002082
Eliad Peller1d095472011-10-10 10:12:49 +02002083 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2084 wlvif->bss_type == BSS_TYPE_IBSS) {
2085 /*
2086 * The device role is a special role used for
2087 * rx and tx frames prior to association (as
2088 * the STA role can get packets only from
2089 * its associated bssid)
2090 */
Eliad Peller784f6942011-10-05 11:55:39 +02002091 ret = wl12xx_cmd_role_enable(wl, vif->addr,
Eliad Peller1d095472011-10-10 10:12:49 +02002092 WL1271_ROLE_DEVICE,
2093 &wlvif->dev_role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002094 if (ret < 0)
Eliad Peller1d095472011-10-10 10:12:49 +02002095 goto out;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02002096 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002097
Eliad Peller1d095472011-10-10 10:12:49 +02002098 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2099 role_type, &wlvif->role_id);
2100 if (ret < 0)
Eliad Peller71125ab2010-10-28 21:46:43 +02002101 goto out;
Eliad Peller1d095472011-10-10 10:12:49 +02002102
2103 ret = wl1271_init_vif_specific(wl, vif);
2104 if (ret < 0)
2105 goto out;
Eliad Peller71125ab2010-10-28 21:46:43 +02002106
2107 wl->vif = vif;
Eliad Peller87627212011-10-10 10:12:54 +02002108 list_add(&wlvif->list, &wl->wlvif_list);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002109 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
Eliad Pellera4e41302011-10-11 11:49:15 +02002110
2111 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2112 wl->ap_count++;
2113 else
2114 wl->sta_count++;
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +03002115out:
Eliad Pellerf750c822011-10-10 10:13:16 +02002116 wl1271_ps_elp_sleep(wl);
2117out_unlock:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002118 mutex_unlock(&wl->mutex);
2119
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002120 mutex_lock(&wl_list_mutex);
Juuso Oikarineneb887df2010-07-08 17:49:58 +03002121 if (!ret)
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002122 list_add(&wl->list, &wl_list);
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002123 mutex_unlock(&wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002124
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002125 return ret;
2126}
2127
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002128static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +02002129 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002130 bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002131{
Eliad Peller536129c2011-10-05 11:55:45 +02002132 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02002133 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002134
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002135 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002136
Eliad Peller10c8cd02011-10-10 10:13:06 +02002137 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2138 return;
2139
Eliad Peller2f8e81a2011-11-01 15:12:50 +02002140 wl->vif = NULL;
2141
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002142 /* because of hardware recovery, we may get here twice */
2143 if (wl->state != WL1271_STATE_ON)
2144 return;
2145
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002146 wl1271_info("down");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002147
Eliad Pellerbaf62772011-10-10 10:12:52 +02002148 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2149 wl->scan_vif == vif) {
Luciano Coelho08688d62010-07-08 17:50:07 +03002150 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +02002151 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02002152 wl->scan_vif = NULL;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002153 wl->scan.req = NULL;
Juuso Oikarinen76a029f2010-07-29 04:54:45 +03002154 ieee80211_scan_completed(wl->hw, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002155 }
2156
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002157 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2158 /* disable active roles */
2159 ret = wl1271_ps_elp_wakeup(wl);
2160 if (ret < 0)
2161 goto deinit;
2162
Eliad Pellerb890f4c2011-12-18 20:25:44 +02002163 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2164 wlvif->bss_type == BSS_TYPE_IBSS) {
2165 if (wl12xx_dev_role_started(wlvif))
2166 wl12xx_stop_dev(wl, wlvif);
2167
Eliad Peller7edebf52011-10-05 11:55:52 +02002168 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +03002169 if (ret < 0)
2170 goto deinit;
2171 }
2172
Eliad Peller0603d892011-10-05 11:55:51 +02002173 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002174 if (ret < 0)
2175 goto deinit;
2176
2177 wl1271_ps_elp_sleep(wl);
2178 }
2179deinit:
Arik Nemtsove51ae9b2011-08-14 13:17:21 +03002180 /* clear all hlids (except system_hlid) */
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02002181 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002182
2183 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2184 wlvif->bss_type == BSS_TYPE_IBSS) {
2185 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2186 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2187 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2188 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2189 } else {
2190 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2191 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2192 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2193 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2194 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2195 wl12xx_free_rate_policy(wl,
2196 &wlvif->ap.ucast_rate_idx[i]);
2197 }
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002198
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02002199 wl12xx_tx_reset_wlvif(wl, wlvif);
Eliad Peller170d0e62011-10-05 11:56:06 +02002200 wl1271_free_ap_keys(wl, wlvif);
Eliad Pellere4120df2011-10-10 10:13:17 +02002201 if (wl->last_wlvif == wlvif)
2202 wl->last_wlvif = NULL;
Eliad Peller87627212011-10-10 10:12:54 +02002203 list_del(&wlvif->list);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02002204 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
Eliad Peller0603d892011-10-05 11:55:51 +02002205 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02002206 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Luciano Coelhod6e19d12009-10-12 15:08:43 +03002207
Eliad Pellera4e41302011-10-11 11:49:15 +02002208 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2209 wl->ap_count--;
2210 else
2211 wl->sta_count--;
2212
Eliad Pellerbaf62772011-10-10 10:12:52 +02002213 mutex_unlock(&wl->mutex);
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02002214
Eliad Peller9eb599e2011-10-10 10:12:59 +02002215 del_timer_sync(&wlvif->rx_streaming_timer);
2216 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2217 cancel_work_sync(&wlvif->rx_streaming_disable_work);
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03002218
Eliad Pellerbaf62772011-10-10 10:12:52 +02002219 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002220}
Juuso Oikarinenbd9dc492010-04-09 11:07:26 +03002221
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002222static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2223 struct ieee80211_vif *vif)
2224{
2225 struct wl1271 *wl = hw->priv;
Eliad Peller10c8cd02011-10-10 10:13:06 +02002226 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002227 struct wl12xx_vif *iter;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002228
2229 mutex_lock(&wl->mutex);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002230
2231 if (wl->state == WL1271_STATE_OFF ||
2232 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2233 goto out;
2234
Juuso Oikarinen67353292010-11-18 15:19:02 +02002235 /*
2236 * wl->vif can be null here if someone shuts down the interface
2237 * just when hardware recovery has been started.
2238 */
Eliad Peller6e8cd332011-10-10 10:13:13 +02002239 wl12xx_for_each_wlvif(wl, iter) {
2240 if (iter != wlvif)
2241 continue;
2242
Eliad Peller536129c2011-10-05 11:55:45 +02002243 __wl1271_op_remove_interface(wl, vif, true);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002244 break;
Juuso Oikarinen67353292010-11-18 15:19:02 +02002245 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02002246 WARN_ON(iter != wlvif);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002247out:
Juuso Oikarinen67353292010-11-18 15:19:02 +02002248 mutex_unlock(&wl->mutex);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02002249 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002250}
2251
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002252static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2253 struct ieee80211_vif *vif,
2254 enum nl80211_iftype new_type, bool p2p)
2255{
2256 wl1271_op_remove_interface(hw, vif);
2257
2258 vif->type = ieee80211_iftype_p2p(new_type, p2p);
2259 vif->p2p = p2p;
2260 return wl1271_op_add_interface(hw, vif);
2261}
2262
Eliad Peller87fbcb02011-10-05 11:55:41 +02002263static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2264 bool set_assoc)
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002265{
2266 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002267 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002268
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002269 /*
2270 * One of the side effects of the JOIN command is that is clears
2271 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2272 * to a WPA/WPA2 access point will therefore kill the data-path.
Ohad Ben-Cohen8bf69aa2011-03-30 19:18:31 +02002273 * Currently the only valid scenario for JOIN during association
2274 * is on roaming, in which case we will also be given new keys.
2275 * Keep the below message for now, unless it starts bothering
2276 * users who really like to roam a lot :)
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002277 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002278 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002279 wl1271_info("JOIN while associated.");
2280
2281 if (set_assoc)
Eliad Pellerba8447f2011-10-10 10:13:00 +02002282 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002283
Eliad Peller227e81e2011-08-14 13:17:26 +03002284 if (is_ibss)
Eliad Peller87fbcb02011-10-05 11:55:41 +02002285 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03002286 else
Eliad Peller87fbcb02011-10-05 11:55:41 +02002287 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002288 if (ret < 0)
2289 goto out;
2290
Eliad Pellerba8447f2011-10-10 10:13:00 +02002291 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002292 goto out;
2293
2294 /*
2295 * The join command disable the keep-alive mode, shut down its process,
2296 * and also clear the template config, so we need to reset it all after
2297 * the join. The acx_aid starts the keep-alive process, and the order
2298 * of the commands below is relevant.
2299 */
Eliad Peller0603d892011-10-05 11:55:51 +02002300 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002301 if (ret < 0)
2302 goto out;
2303
Eliad Peller0603d892011-10-05 11:55:51 +02002304 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002305 if (ret < 0)
2306 goto out;
2307
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002308 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002309 if (ret < 0)
2310 goto out;
2311
Eliad Peller0603d892011-10-05 11:55:51 +02002312 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2313 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002314 ACX_KEEP_ALIVE_TPL_VALID);
2315 if (ret < 0)
2316 goto out;
2317
2318out:
2319 return ret;
2320}
2321
Eliad Peller0603d892011-10-05 11:55:51 +02002322static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002323{
2324 int ret;
2325
Eliad Peller52630c52011-10-10 10:13:08 +02002326 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02002327 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2328
Shahar Levi6d158ff2011-09-08 13:01:33 +03002329 wl12xx_cmd_stop_channel_switch(wl);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002330 ieee80211_chswitch_done(vif, false);
Shahar Levi6d158ff2011-09-08 13:01:33 +03002331 }
2332
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002333 /* to stop listening to a channel, we disconnect */
Eliad Peller0603d892011-10-05 11:55:51 +02002334 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002335 if (ret < 0)
2336 goto out;
2337
Oz Krakowskib992c682011-06-26 10:36:02 +03002338 /* reset TX security counters on a clean disconnect */
Eliad Peller48e93e42011-10-10 10:12:58 +02002339 wlvif->tx_security_last_seq_lsb = 0;
2340 wlvif->tx_security_seq = 0;
Oz Krakowskib992c682011-06-26 10:36:02 +03002341
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002342out:
2343 return ret;
2344}
2345
Eliad Peller87fbcb02011-10-05 11:55:41 +02002346static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002347{
Eliad Peller1b92f152011-10-10 10:13:09 +02002348 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002349 wlvif->rate_set = wlvif->basic_rate_set;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002350}
2351
Eliad Peller87fbcb02011-10-05 11:55:41 +02002352static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2353 bool idle)
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002354{
2355 int ret;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002356 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2357
2358 if (idle == cur_idle)
2359 return 0;
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002360
2361 if (idle) {
Eliad Peller251c1772011-08-14 13:17:17 +03002362 /* no need to croc if we weren't busy (e.g. during boot) */
Eliad Peller92e712d2011-12-18 20:25:43 +02002363 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002364 ret = wl12xx_stop_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002365 if (ret < 0)
2366 goto out;
2367 }
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002368 wlvif->rate_set =
2369 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2370 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002371 if (ret < 0)
2372 goto out;
2373 ret = wl1271_acx_keep_alive_config(
Eliad Peller0603d892011-10-05 11:55:51 +02002374 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002375 ACX_KEEP_ALIVE_TPL_INVALID);
2376 if (ret < 0)
2377 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002378 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002379 } else {
Luciano Coelho33c2c062011-05-10 14:46:02 +03002380 /* The current firmware only supports sched_scan in idle */
2381 if (wl->sched_scanning) {
2382 wl1271_scan_sched_scan_stop(wl);
2383 ieee80211_sched_scan_stopped(wl->hw);
2384 }
2385
Eliad Peller679a6732011-10-11 11:55:44 +02002386 ret = wl12xx_start_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002387 if (ret < 0)
2388 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002389 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002390 }
2391
2392out:
2393 return ret;
2394}
2395
Eliad Peller9f259c42011-10-10 10:13:12 +02002396static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2397 struct ieee80211_conf *conf, u32 changed)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002398{
Eliad Peller9f259c42011-10-10 10:13:12 +02002399 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2400 int channel, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002401
2402 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2403
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002404 /* if the channel changes while joined, join again */
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002405 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
Eliad Peller1b92f152011-10-10 10:13:09 +02002406 ((wlvif->band != conf->channel->band) ||
Eliad Peller61f845f2011-10-10 10:13:10 +02002407 (wlvif->channel != channel))) {
Eliad Pellerc6930b02011-09-15 13:00:01 +03002408 /* send all pending packets */
Eliad Pellera32d0cd2011-10-10 10:12:55 +02002409 wl1271_tx_work_locked(wl);
Eliad Peller61f845f2011-10-10 10:13:10 +02002410 wlvif->band = conf->channel->band;
2411 wlvif->channel = channel;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002412
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002413 if (!is_ap) {
2414 /*
2415 * FIXME: the mac80211 should really provide a fixed
2416 * rate to use here. for now, just use the smallest
2417 * possible rate for the band as a fixed rate for
2418 * association frames and other control messages.
2419 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002420 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Peller87fbcb02011-10-05 11:55:41 +02002421 wl1271_set_band_rate(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002422
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002423 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02002424 wl1271_tx_min_rate_get(wl,
2425 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002426 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002427 if (ret < 0)
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002428 wl1271_warning("rate policy for channel "
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002429 "failed %d", ret);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002430
Eliad Pellerba8447f2011-10-10 10:13:00 +02002431 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2432 &wlvif->flags)) {
Eliad Peller92e712d2011-12-18 20:25:43 +02002433 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller251c1772011-08-14 13:17:17 +03002434 /* roaming */
Eliad Peller7edebf52011-10-05 11:55:52 +02002435 ret = wl12xx_croc(wl,
2436 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03002437 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002438 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002439 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02002440 ret = wl1271_join(wl, wlvif, false);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002441 if (ret < 0)
2442 wl1271_warning("cmd join on channel "
2443 "failed %d", ret);
Eliad Peller251c1772011-08-14 13:17:17 +03002444 } else {
2445 /*
2446 * change the ROC channel. do it only if we are
2447 * not idle. otherwise, CROC will be called
2448 * anyway.
2449 */
Eliad Peller92e712d2011-12-18 20:25:43 +02002450 if (wl12xx_dev_role_started(wlvif) &&
Eliad Peller251c1772011-08-14 13:17:17 +03002451 !(conf->flags & IEEE80211_CONF_IDLE)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002452 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002453 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002454 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002455
Eliad Peller679a6732011-10-11 11:55:44 +02002456 ret = wl12xx_start_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002457 if (ret < 0)
Eliad Peller679a6732011-10-11 11:55:44 +02002458 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002459 }
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002460 }
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002461 }
2462 }
2463
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002464 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002465
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002466 if ((conf->flags & IEEE80211_CONF_PS) &&
2467 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
2468 !test_bit(WLVIF_FLAG_IN_AUTO_PS, &wlvif->flags)) {
2469
2470 wl1271_debug(DEBUG_PSM, "auto ps enabled");
2471
Eliad Peller0603d892011-10-05 11:55:51 +02002472 ret = wl1271_ps_set_mode(wl, wlvif,
Eyal Shapira248a0012012-01-31 11:57:23 +02002473 STATION_AUTO_PS_MODE);
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002474 if (ret < 0)
2475 wl1271_warning("enter auto ps failed %d", ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002476
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002477 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2478 test_bit(WLVIF_FLAG_IN_AUTO_PS, &wlvif->flags)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002479
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002480 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2481
Eliad Peller0603d892011-10-05 11:55:51 +02002482 ret = wl1271_ps_set_mode(wl, wlvif,
Eyal Shapira248a0012012-01-31 11:57:23 +02002483 STATION_ACTIVE_MODE);
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002484 if (ret < 0)
2485 wl1271_warning("exit auto ps failed %d", ret);
2486 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002487 }
2488
Eliad Peller6bd65022011-10-10 10:13:11 +02002489 if (conf->power_level != wlvif->power_level) {
Eliad Peller0603d892011-10-05 11:55:51 +02002490 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002491 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002492 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002493
Eliad Peller6bd65022011-10-10 10:13:11 +02002494 wlvif->power_level = conf->power_level;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002495 }
2496
Eliad Peller9f259c42011-10-10 10:13:12 +02002497 return 0;
2498}
2499
2500static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2501{
2502 struct wl1271 *wl = hw->priv;
2503 struct wl12xx_vif *wlvif;
2504 struct ieee80211_conf *conf = &hw->conf;
2505 int channel, ret = 0;
2506
2507 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2508
2509 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2510 " changed 0x%x",
2511 channel,
2512 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2513 conf->power_level,
2514 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2515 changed);
2516
2517 /*
2518 * mac80211 will go to idle nearly immediately after transmitting some
2519 * frames, such as the deauth. To make sure those frames reach the air,
2520 * wait here until the TX queue is fully flushed.
2521 */
2522 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2523 (conf->flags & IEEE80211_CONF_IDLE))
2524 wl1271_tx_flush(wl);
2525
2526 mutex_lock(&wl->mutex);
2527
2528 /* we support configuring the channel and band even while off */
2529 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2530 wl->band = conf->channel->band;
2531 wl->channel = channel;
2532 }
2533
2534 if (changed & IEEE80211_CONF_CHANGE_POWER)
2535 wl->power_level = conf->power_level;
2536
2537 if (unlikely(wl->state == WL1271_STATE_OFF))
2538 goto out;
2539
2540 ret = wl1271_ps_elp_wakeup(wl);
2541 if (ret < 0)
2542 goto out;
2543
2544 /* configure each interface */
2545 wl12xx_for_each_wlvif(wl, wlvif) {
2546 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2547 if (ret < 0)
2548 goto out_sleep;
2549 }
2550
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002551out_sleep:
2552 wl1271_ps_elp_sleep(wl);
2553
2554out:
2555 mutex_unlock(&wl->mutex);
2556
2557 return ret;
2558}
2559
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002560struct wl1271_filter_params {
2561 bool enabled;
2562 int mc_list_length;
2563 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2564};
2565
Jiri Pirko22bedad2010-04-01 21:22:57 +00002566static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2567 struct netdev_hw_addr_list *mc_list)
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002568{
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002569 struct wl1271_filter_params *fp;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002570 struct netdev_hw_addr *ha;
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002571 struct wl1271 *wl = hw->priv;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002572
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002573 if (unlikely(wl->state == WL1271_STATE_OFF))
2574 return 0;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002575
Juuso Oikarinen74441132009-10-13 12:47:53 +03002576 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002577 if (!fp) {
2578 wl1271_error("Out of memory setting filters.");
2579 return 0;
2580 }
2581
2582 /* update multicast filtering parameters */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002583 fp->mc_list_length = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002584 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2585 fp->enabled = false;
2586 } else {
2587 fp->enabled = true;
2588 netdev_hw_addr_list_for_each(ha, mc_list) {
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002589 memcpy(fp->mc_list[fp->mc_list_length],
Jiri Pirko22bedad2010-04-01 21:22:57 +00002590 ha->addr, ETH_ALEN);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002591 fp->mc_list_length++;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002592 }
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002593 }
2594
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002595 return (u64)(unsigned long)fp;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002596}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002597
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002598#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2599 FIF_ALLMULTI | \
2600 FIF_FCSFAIL | \
2601 FIF_BCN_PRBRESP_PROMISC | \
2602 FIF_CONTROL | \
2603 FIF_OTHER_BSS)
2604
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002605static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2606 unsigned int changed,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002607 unsigned int *total, u64 multicast)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002608{
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002609 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002610 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02002611 struct wl12xx_vif *wlvif;
Eliad Peller536129c2011-10-05 11:55:45 +02002612
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002613 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002614
Arik Nemtsov7d057862010-10-16 19:25:35 +02002615 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2616 " total %x", changed, *total);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002617
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002618 mutex_lock(&wl->mutex);
2619
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002620 *total &= WL1271_SUPPORTED_FILTERS;
2621 changed &= WL1271_SUPPORTED_FILTERS;
2622
2623 if (unlikely(wl->state == WL1271_STATE_OFF))
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002624 goto out;
2625
Ido Yariva6208652011-03-01 15:14:41 +02002626 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002627 if (ret < 0)
2628 goto out;
2629
Eliad Peller6e8cd332011-10-10 10:13:13 +02002630 wl12xx_for_each_wlvif(wl, wlvif) {
2631 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2632 if (*total & FIF_ALLMULTI)
2633 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2634 false,
2635 NULL, 0);
2636 else if (fp)
2637 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2638 fp->enabled,
2639 fp->mc_list,
2640 fp->mc_list_length);
2641 if (ret < 0)
2642 goto out_sleep;
2643 }
Arik Nemtsov7d057862010-10-16 19:25:35 +02002644 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002645
Eliad Peller08c1d1c2011-08-14 13:17:04 +03002646 /*
2647 * the fw doesn't provide an api to configure the filters. instead,
2648 * the filters configuration is based on the active roles / ROC
2649 * state.
2650 */
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002651
2652out_sleep:
2653 wl1271_ps_elp_sleep(wl);
2654
2655out:
2656 mutex_unlock(&wl->mutex);
Juuso Oikarinen14b228a2010-03-18 12:26:43 +02002657 kfree(fp);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002658}
2659
Eliad Peller170d0e62011-10-05 11:56:06 +02002660static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2661 u8 id, u8 key_type, u8 key_size,
2662 const u8 *key, u8 hlid, u32 tx_seq_32,
2663 u16 tx_seq_16)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002664{
2665 struct wl1271_ap_key *ap_key;
2666 int i;
2667
2668 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2669
2670 if (key_size > MAX_KEY_SIZE)
2671 return -EINVAL;
2672
2673 /*
2674 * Find next free entry in ap_keys. Also check we are not replacing
2675 * an existing key.
2676 */
2677 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002678 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002679 break;
2680
Eliad Peller170d0e62011-10-05 11:56:06 +02002681 if (wlvif->ap.recorded_keys[i]->id == id) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002682 wl1271_warning("trying to record key replacement");
2683 return -EINVAL;
2684 }
2685 }
2686
2687 if (i == MAX_NUM_KEYS)
2688 return -EBUSY;
2689
2690 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2691 if (!ap_key)
2692 return -ENOMEM;
2693
2694 ap_key->id = id;
2695 ap_key->key_type = key_type;
2696 ap_key->key_size = key_size;
2697 memcpy(ap_key->key, key, key_size);
2698 ap_key->hlid = hlid;
2699 ap_key->tx_seq_32 = tx_seq_32;
2700 ap_key->tx_seq_16 = tx_seq_16;
2701
Eliad Peller170d0e62011-10-05 11:56:06 +02002702 wlvif->ap.recorded_keys[i] = ap_key;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002703 return 0;
2704}
2705
Eliad Peller170d0e62011-10-05 11:56:06 +02002706static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002707{
2708 int i;
2709
2710 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002711 kfree(wlvif->ap.recorded_keys[i]);
2712 wlvif->ap.recorded_keys[i] = NULL;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002713 }
2714}
2715
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002716static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002717{
2718 int i, ret = 0;
2719 struct wl1271_ap_key *key;
2720 bool wep_key_added = false;
2721
2722 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller7f97b482011-08-14 13:17:30 +03002723 u8 hlid;
Eliad Peller170d0e62011-10-05 11:56:06 +02002724 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002725 break;
2726
Eliad Peller170d0e62011-10-05 11:56:06 +02002727 key = wlvif->ap.recorded_keys[i];
Eliad Peller7f97b482011-08-14 13:17:30 +03002728 hlid = key->hlid;
2729 if (hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002730 hlid = wlvif->ap.bcast_hlid;
Eliad Peller7f97b482011-08-14 13:17:30 +03002731
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002732 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002733 key->id, key->key_type,
2734 key->key_size, key->key,
Eliad Peller7f97b482011-08-14 13:17:30 +03002735 hlid, key->tx_seq_32,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002736 key->tx_seq_16);
2737 if (ret < 0)
2738 goto out;
2739
2740 if (key->key_type == KEY_WEP)
2741 wep_key_added = true;
2742 }
2743
2744 if (wep_key_added) {
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002745 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002746 wlvif->ap.bcast_hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002747 if (ret < 0)
2748 goto out;
2749 }
2750
2751out:
Eliad Peller170d0e62011-10-05 11:56:06 +02002752 wl1271_free_ap_keys(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002753 return ret;
2754}
2755
Eliad Peller536129c2011-10-05 11:55:45 +02002756static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2757 u16 action, u8 id, u8 key_type,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002758 u8 key_size, const u8 *key, u32 tx_seq_32,
2759 u16 tx_seq_16, struct ieee80211_sta *sta)
2760{
2761 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002762 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002763
2764 if (is_ap) {
2765 struct wl1271_station *wl_sta;
2766 u8 hlid;
2767
2768 if (sta) {
2769 wl_sta = (struct wl1271_station *)sta->drv_priv;
2770 hlid = wl_sta->hlid;
2771 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002772 hlid = wlvif->ap.bcast_hlid;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002773 }
2774
Eliad Peller53d40d02011-10-10 10:13:02 +02002775 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002776 /*
2777 * We do not support removing keys after AP shutdown.
2778 * Pretend we do to make mac80211 happy.
2779 */
2780 if (action != KEY_ADD_OR_REPLACE)
2781 return 0;
2782
Eliad Peller170d0e62011-10-05 11:56:06 +02002783 ret = wl1271_record_ap_key(wl, wlvif, id,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002784 key_type, key_size,
2785 key, hlid, tx_seq_32,
2786 tx_seq_16);
2787 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002788 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002789 id, key_type, key_size,
2790 key, hlid, tx_seq_32,
2791 tx_seq_16);
2792 }
2793
2794 if (ret < 0)
2795 return ret;
2796 } else {
2797 const u8 *addr;
2798 static const u8 bcast_addr[ETH_ALEN] = {
2799 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2800 };
2801
Guy Eilame9eb8cb2011-08-16 19:49:12 +03002802 /*
2803 * A STA set to GEM cipher requires 2 tx spare blocks.
2804 * Return to default value when GEM cipher key is removed
2805 */
2806 if (key_type == KEY_GEM) {
2807 if (action == KEY_ADD_OR_REPLACE)
2808 wl->tx_spare_blocks = 2;
2809 else if (action == KEY_REMOVE)
2810 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2811 }
2812
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002813 addr = sta ? sta->addr : bcast_addr;
2814
2815 if (is_zero_ether_addr(addr)) {
2816 /* We dont support TX only encryption */
2817 return -EOPNOTSUPP;
2818 }
2819
2820 /* The wl1271 does not allow to remove unicast keys - they
2821 will be cleared automatically on next CMD_JOIN. Ignore the
2822 request silently, as we dont want the mac80211 to emit
2823 an error message. */
2824 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2825 return 0;
2826
Eliad Peller010d3d32011-08-14 13:17:31 +03002827 /* don't remove key if hlid was already deleted */
2828 if (action == KEY_REMOVE &&
Eliad Peller154da672011-10-05 11:55:53 +02002829 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Peller010d3d32011-08-14 13:17:31 +03002830 return 0;
2831
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002832 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002833 id, key_type, key_size,
2834 key, addr, tx_seq_32,
2835 tx_seq_16);
2836 if (ret < 0)
2837 return ret;
2838
2839 /* the default WEP key needs to be configured at least once */
2840 if (key_type == KEY_WEP) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03002841 ret = wl12xx_cmd_set_default_wep_key(wl,
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002842 wlvif->default_key,
2843 wlvif->sta.hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002844 if (ret < 0)
2845 return ret;
2846 }
2847 }
2848
2849 return 0;
2850}
2851
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002852static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2853 struct ieee80211_vif *vif,
2854 struct ieee80211_sta *sta,
2855 struct ieee80211_key_conf *key_conf)
2856{
2857 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002858 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002859 int ret;
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03002860 u32 tx_seq_32 = 0;
2861 u16 tx_seq_16 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002862 u8 key_type;
2863
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002864 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2865
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002866 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002867 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Johannes Berg97359d12010-08-10 09:46:38 +02002868 key_conf->cipher, key_conf->keyidx,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002869 key_conf->keylen, key_conf->flags);
2870 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2871
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002872 mutex_lock(&wl->mutex);
2873
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02002874 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2875 ret = -EAGAIN;
2876 goto out_unlock;
2877 }
2878
Ido Yariva6208652011-03-01 15:14:41 +02002879 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002880 if (ret < 0)
2881 goto out_unlock;
2882
Johannes Berg97359d12010-08-10 09:46:38 +02002883 switch (key_conf->cipher) {
2884 case WLAN_CIPHER_SUITE_WEP40:
2885 case WLAN_CIPHER_SUITE_WEP104:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002886 key_type = KEY_WEP;
2887
2888 key_conf->hw_key_idx = key_conf->keyidx;
2889 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002890 case WLAN_CIPHER_SUITE_TKIP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002891 key_type = KEY_TKIP;
2892
2893 key_conf->hw_key_idx = key_conf->keyidx;
Eliad Peller48e93e42011-10-10 10:12:58 +02002894 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2895 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002896 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002897 case WLAN_CIPHER_SUITE_CCMP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002898 key_type = KEY_AES;
2899
Arik Nemtsov12d4b972011-10-23 08:21:54 +02002900 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Eliad Peller48e93e42011-10-10 10:12:58 +02002901 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2902 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002903 break;
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002904 case WL1271_CIPHER_SUITE_GEM:
2905 key_type = KEY_GEM;
Eliad Peller48e93e42011-10-10 10:12:58 +02002906 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2907 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002908 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002909 default:
Johannes Berg97359d12010-08-10 09:46:38 +02002910 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002911
2912 ret = -EOPNOTSUPP;
2913 goto out_sleep;
2914 }
2915
2916 switch (cmd) {
2917 case SET_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02002918 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002919 key_conf->keyidx, key_type,
2920 key_conf->keylen, key_conf->key,
2921 tx_seq_32, tx_seq_16, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002922 if (ret < 0) {
2923 wl1271_error("Could not add or replace key");
2924 goto out_sleep;
2925 }
2926 break;
2927
2928 case DISABLE_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02002929 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002930 key_conf->keyidx, key_type,
2931 key_conf->keylen, key_conf->key,
2932 0, 0, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002933 if (ret < 0) {
2934 wl1271_error("Could not remove key");
2935 goto out_sleep;
2936 }
2937 break;
2938
2939 default:
2940 wl1271_error("Unsupported key cmd 0x%x", cmd);
2941 ret = -EOPNOTSUPP;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002942 break;
2943 }
2944
2945out_sleep:
2946 wl1271_ps_elp_sleep(wl);
2947
2948out_unlock:
2949 mutex_unlock(&wl->mutex);
2950
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002951 return ret;
2952}
2953
2954static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
Johannes Berga060bbf2010-04-27 11:59:34 +02002955 struct ieee80211_vif *vif,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002956 struct cfg80211_scan_request *req)
2957{
2958 struct wl1271 *wl = hw->priv;
Eliad Peller7edebf52011-10-05 11:55:52 +02002959 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2960
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002961 int ret;
2962 u8 *ssid = NULL;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03002963 size_t len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002964
2965 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
2966
2967 if (req->n_ssids) {
2968 ssid = req->ssids[0].ssid;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03002969 len = req->ssids[0].ssid_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002970 }
2971
2972 mutex_lock(&wl->mutex);
2973
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002974 if (wl->state == WL1271_STATE_OFF) {
2975 /*
2976 * We cannot return -EBUSY here because cfg80211 will expect
2977 * a call to ieee80211_scan_completed if we do - in this case
2978 * there won't be any call.
2979 */
2980 ret = -EAGAIN;
2981 goto out;
2982 }
2983
Ido Yariva6208652011-03-01 15:14:41 +02002984 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002985 if (ret < 0)
2986 goto out;
2987
Eliad Peller92e712d2011-12-18 20:25:43 +02002988 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
2989 test_bit(wlvif->role_id, wl->roc_map)) {
2990 /* don't allow scanning right now */
2991 ret = -EBUSY;
2992 goto out_sleep;
Eliad Peller251c1772011-08-14 13:17:17 +03002993 }
2994
Eliad Peller92e712d2011-12-18 20:25:43 +02002995 /* cancel ROC before scanning */
2996 if (wl12xx_dev_role_started(wlvif))
Eliad Pellerc059beb2012-01-31 11:57:17 +02002997 wl12xx_croc(wl, wlvif->dev_role_id);
Eliad Peller92e712d2011-12-18 20:25:43 +02002998
Eliad Peller784f6942011-10-05 11:55:39 +02002999 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
Eliad Peller251c1772011-08-14 13:17:17 +03003000out_sleep:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003001 wl1271_ps_elp_sleep(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003002out:
3003 mutex_unlock(&wl->mutex);
3004
3005 return ret;
3006}
3007
Eliad Peller73ecce32011-06-27 13:06:45 +03003008static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3009 struct ieee80211_vif *vif)
3010{
3011 struct wl1271 *wl = hw->priv;
3012 int ret;
3013
3014 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3015
3016 mutex_lock(&wl->mutex);
3017
3018 if (wl->state == WL1271_STATE_OFF)
3019 goto out;
3020
3021 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3022 goto out;
3023
3024 ret = wl1271_ps_elp_wakeup(wl);
3025 if (ret < 0)
3026 goto out;
3027
3028 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3029 ret = wl1271_scan_stop(wl);
3030 if (ret < 0)
3031 goto out_sleep;
3032 }
3033 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3034 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02003035 wl->scan_vif = NULL;
Eliad Peller73ecce32011-06-27 13:06:45 +03003036 wl->scan.req = NULL;
3037 ieee80211_scan_completed(wl->hw, true);
3038
3039out_sleep:
3040 wl1271_ps_elp_sleep(wl);
3041out:
3042 mutex_unlock(&wl->mutex);
3043
3044 cancel_delayed_work_sync(&wl->scan_complete_work);
3045}
3046
Luciano Coelho33c2c062011-05-10 14:46:02 +03003047static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3048 struct ieee80211_vif *vif,
3049 struct cfg80211_sched_scan_request *req,
3050 struct ieee80211_sched_scan_ies *ies)
3051{
3052 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003053 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003054 int ret;
3055
3056 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3057
3058 mutex_lock(&wl->mutex);
3059
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003060 if (wl->state == WL1271_STATE_OFF) {
3061 ret = -EAGAIN;
3062 goto out;
3063 }
3064
Luciano Coelho33c2c062011-05-10 14:46:02 +03003065 ret = wl1271_ps_elp_wakeup(wl);
3066 if (ret < 0)
3067 goto out;
3068
Eliad Peller536129c2011-10-05 11:55:45 +02003069 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003070 if (ret < 0)
3071 goto out_sleep;
3072
Eliad Peller536129c2011-10-05 11:55:45 +02003073 ret = wl1271_scan_sched_scan_start(wl, wlvif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003074 if (ret < 0)
3075 goto out_sleep;
3076
3077 wl->sched_scanning = true;
3078
3079out_sleep:
3080 wl1271_ps_elp_sleep(wl);
3081out:
3082 mutex_unlock(&wl->mutex);
3083 return ret;
3084}
3085
3086static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3087 struct ieee80211_vif *vif)
3088{
3089 struct wl1271 *wl = hw->priv;
3090 int ret;
3091
3092 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3093
3094 mutex_lock(&wl->mutex);
3095
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003096 if (wl->state == WL1271_STATE_OFF)
3097 goto out;
3098
Luciano Coelho33c2c062011-05-10 14:46:02 +03003099 ret = wl1271_ps_elp_wakeup(wl);
3100 if (ret < 0)
3101 goto out;
3102
3103 wl1271_scan_sched_scan_stop(wl);
3104
3105 wl1271_ps_elp_sleep(wl);
3106out:
3107 mutex_unlock(&wl->mutex);
3108}
3109
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003110static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3111{
3112 struct wl1271 *wl = hw->priv;
3113 int ret = 0;
3114
3115 mutex_lock(&wl->mutex);
3116
3117 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3118 ret = -EAGAIN;
3119 goto out;
3120 }
3121
Ido Yariva6208652011-03-01 15:14:41 +02003122 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003123 if (ret < 0)
3124 goto out;
3125
Arik Nemtsov5f704d12011-04-18 14:15:21 +03003126 ret = wl1271_acx_frag_threshold(wl, value);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003127 if (ret < 0)
3128 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3129
3130 wl1271_ps_elp_sleep(wl);
3131
3132out:
3133 mutex_unlock(&wl->mutex);
3134
3135 return ret;
3136}
3137
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003138static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3139{
3140 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02003141 struct wl12xx_vif *wlvif;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003142 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003143
3144 mutex_lock(&wl->mutex);
3145
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003146 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3147 ret = -EAGAIN;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003148 goto out;
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003149 }
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003150
Ido Yariva6208652011-03-01 15:14:41 +02003151 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003152 if (ret < 0)
3153 goto out;
3154
Eliad Peller6e8cd332011-10-10 10:13:13 +02003155 wl12xx_for_each_wlvif(wl, wlvif) {
3156 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3157 if (ret < 0)
3158 wl1271_warning("set rts threshold failed: %d", ret);
3159 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003160 wl1271_ps_elp_sleep(wl);
3161
3162out:
3163 mutex_unlock(&wl->mutex);
3164
3165 return ret;
3166}
3167
Eliad Peller1fe9f162011-10-05 11:55:48 +02003168static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003169 int offset)
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003170{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003171 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller889cb362011-05-01 09:56:45 +03003172 u8 ssid_len;
3173 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3174 skb->len - offset);
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003175
Eliad Peller889cb362011-05-01 09:56:45 +03003176 if (!ptr) {
3177 wl1271_error("No SSID in IEs!");
3178 return -ENOENT;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003179 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003180
Eliad Peller889cb362011-05-01 09:56:45 +03003181 ssid_len = ptr[1];
3182 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3183 wl1271_error("SSID is too long!");
3184 return -EINVAL;
3185 }
3186
Eliad Peller1fe9f162011-10-05 11:55:48 +02003187 wlvif->ssid_len = ssid_len;
3188 memcpy(wlvif->ssid, ptr+2, ssid_len);
Eliad Peller889cb362011-05-01 09:56:45 +03003189 return 0;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003190}
3191
Eliad Pellerd48055d2011-09-15 12:07:04 +03003192static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3193{
3194 int len;
3195 const u8 *next, *end = skb->data + skb->len;
3196 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3197 skb->len - ieoffset);
3198 if (!ie)
3199 return;
3200 len = ie[1] + 2;
3201 next = ie + len;
3202 memmove(ie, next, end - next);
3203 skb_trim(skb, skb->len - len);
3204}
3205
Eliad Peller26b4bf22011-09-15 12:07:05 +03003206static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3207 unsigned int oui, u8 oui_type,
3208 int ieoffset)
3209{
3210 int len;
3211 const u8 *next, *end = skb->data + skb->len;
3212 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3213 skb->data + ieoffset,
3214 skb->len - ieoffset);
3215 if (!ie)
3216 return;
3217 len = ie[1] + 2;
3218 next = ie + len;
3219 memmove(ie, next, end - next);
3220 skb_trim(skb, skb->len - len);
3221}
3222
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003223static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3224 struct ieee80211_vif *vif)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003225{
Eliad Pellercdaac622012-01-31 11:57:16 +02003226 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003227 struct sk_buff *skb;
3228 int ret;
3229
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003230 skb = ieee80211_proberesp_get(wl->hw, vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003231 if (!skb)
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003232 return -EOPNOTSUPP;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003233
Eliad Pellercdaac622012-01-31 11:57:16 +02003234 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov560f0022011-11-08 18:46:54 +02003235 CMD_TEMPL_AP_PROBE_RESPONSE,
3236 skb->data,
3237 skb->len, 0,
3238 rates);
3239
3240 dev_kfree_skb(skb);
3241 return ret;
3242}
3243
3244static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3245 struct ieee80211_vif *vif,
3246 u8 *probe_rsp_data,
3247 size_t probe_rsp_len,
3248 u32 rates)
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003249{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003250 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3251 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003252 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3253 int ssid_ie_offset, ie_offset, templ_len;
3254 const u8 *ptr;
3255
3256 /* no need to change probe response if the SSID is set correctly */
Eliad Peller1fe9f162011-10-05 11:55:48 +02003257 if (wlvif->ssid_len > 0)
Eliad Pellercdaac622012-01-31 11:57:16 +02003258 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003259 CMD_TEMPL_AP_PROBE_RESPONSE,
3260 probe_rsp_data,
3261 probe_rsp_len, 0,
3262 rates);
3263
3264 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3265 wl1271_error("probe_rsp template too big");
3266 return -EINVAL;
3267 }
3268
3269 /* start searching from IE offset */
3270 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3271
3272 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3273 probe_rsp_len - ie_offset);
3274 if (!ptr) {
3275 wl1271_error("No SSID in beacon!");
3276 return -EINVAL;
3277 }
3278
3279 ssid_ie_offset = ptr - probe_rsp_data;
3280 ptr += (ptr[1] + 2);
3281
3282 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3283
3284 /* insert SSID from bss_conf */
3285 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3286 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3287 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3288 bss_conf->ssid, bss_conf->ssid_len);
3289 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3290
3291 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3292 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3293 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3294
Eliad Pellercdaac622012-01-31 11:57:16 +02003295 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003296 CMD_TEMPL_AP_PROBE_RESPONSE,
3297 probe_rsp_templ,
3298 templ_len, 0,
3299 rates);
3300}
3301
Arik Nemtsove78a2872010-10-16 19:07:21 +02003302static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
Eliad Peller0603d892011-10-05 11:55:51 +02003303 struct ieee80211_vif *vif,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003304 struct ieee80211_bss_conf *bss_conf,
3305 u32 changed)
3306{
Eliad Peller0603d892011-10-05 11:55:51 +02003307 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003308 int ret = 0;
3309
3310 if (changed & BSS_CHANGED_ERP_SLOT) {
3311 if (bss_conf->use_short_slot)
Eliad Peller0603d892011-10-05 11:55:51 +02003312 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003313 else
Eliad Peller0603d892011-10-05 11:55:51 +02003314 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003315 if (ret < 0) {
3316 wl1271_warning("Set slot time failed %d", ret);
3317 goto out;
3318 }
3319 }
3320
3321 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3322 if (bss_conf->use_short_preamble)
Eliad Peller0603d892011-10-05 11:55:51 +02003323 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003324 else
Eliad Peller0603d892011-10-05 11:55:51 +02003325 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003326 }
3327
3328 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3329 if (bss_conf->use_cts_prot)
Eliad Peller0603d892011-10-05 11:55:51 +02003330 ret = wl1271_acx_cts_protect(wl, wlvif,
3331 CTSPROTECT_ENABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003332 else
Eliad Peller0603d892011-10-05 11:55:51 +02003333 ret = wl1271_acx_cts_protect(wl, wlvif,
3334 CTSPROTECT_DISABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003335 if (ret < 0) {
3336 wl1271_warning("Set ctsprotect failed %d", ret);
3337 goto out;
3338 }
3339 }
3340
3341out:
3342 return ret;
3343}
3344
3345static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3346 struct ieee80211_vif *vif,
3347 struct ieee80211_bss_conf *bss_conf,
3348 u32 changed)
3349{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003350 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller536129c2011-10-05 11:55:45 +02003351 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003352 int ret = 0;
3353
3354 if ((changed & BSS_CHANGED_BEACON_INT)) {
3355 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3356 bss_conf->beacon_int);
3357
Eliad Peller6a899792011-10-05 11:55:58 +02003358 wlvif->beacon_int = bss_conf->beacon_int;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003359 }
3360
Arik Nemtsov560f0022011-11-08 18:46:54 +02003361 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3362 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003363 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3364 wl1271_debug(DEBUG_AP, "probe response updated");
3365 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3366 }
Arik Nemtsov560f0022011-11-08 18:46:54 +02003367 }
3368
Arik Nemtsove78a2872010-10-16 19:07:21 +02003369 if ((changed & BSS_CHANGED_BEACON)) {
3370 struct ieee80211_hdr *hdr;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003371 u32 min_rate;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003372 int ieoffset = offsetof(struct ieee80211_mgmt,
3373 u.beacon.variable);
3374 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3375 u16 tmpl_id;
3376
Arik Nemtsov560f0022011-11-08 18:46:54 +02003377 if (!beacon) {
3378 ret = -EINVAL;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003379 goto out;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003380 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003381
3382 wl1271_debug(DEBUG_MASTER, "beacon updated");
3383
Eliad Peller1fe9f162011-10-05 11:55:48 +02003384 ret = wl1271_ssid_set(vif, beacon, ieoffset);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003385 if (ret < 0) {
3386 dev_kfree_skb(beacon);
3387 goto out;
3388 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02003389 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003390 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3391 CMD_TEMPL_BEACON;
Eliad Pellercdaac622012-01-31 11:57:16 +02003392 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003393 beacon->data,
3394 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003395 min_rate);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003396 if (ret < 0) {
3397 dev_kfree_skb(beacon);
3398 goto out;
3399 }
3400
Arik Nemtsov560f0022011-11-08 18:46:54 +02003401 /*
3402 * In case we already have a probe-resp beacon set explicitly
3403 * by usermode, don't use the beacon data.
3404 */
3405 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3406 goto end_bcn;
3407
Eliad Pellerd48055d2011-09-15 12:07:04 +03003408 /* remove TIM ie from probe response */
3409 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3410
Eliad Peller26b4bf22011-09-15 12:07:05 +03003411 /*
3412 * remove p2p ie from probe response.
3413 * the fw reponds to probe requests that don't include
3414 * the p2p ie. probe requests with p2p ie will be passed,
3415 * and will be responded by the supplicant (the spec
3416 * forbids including the p2p ie when responding to probe
3417 * requests that didn't include it).
3418 */
3419 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3420 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3421
Arik Nemtsove78a2872010-10-16 19:07:21 +02003422 hdr = (struct ieee80211_hdr *) beacon->data;
3423 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3424 IEEE80211_STYPE_PROBE_RESP);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003425 if (is_ap)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003426 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003427 beacon->data,
3428 beacon->len,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003429 min_rate);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003430 else
Eliad Pellercdaac622012-01-31 11:57:16 +02003431 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003432 CMD_TEMPL_PROBE_RESPONSE,
3433 beacon->data,
3434 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003435 min_rate);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003436end_bcn:
Arik Nemtsove78a2872010-10-16 19:07:21 +02003437 dev_kfree_skb(beacon);
3438 if (ret < 0)
3439 goto out;
3440 }
3441
3442out:
Arik Nemtsov560f0022011-11-08 18:46:54 +02003443 if (ret != 0)
3444 wl1271_error("beacon info change failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003445 return ret;
3446}
3447
3448/* AP mode changes */
3449static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003450 struct ieee80211_vif *vif,
3451 struct ieee80211_bss_conf *bss_conf,
3452 u32 changed)
3453{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003454 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003455 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003456
Arik Nemtsove78a2872010-10-16 19:07:21 +02003457 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3458 u32 rates = bss_conf->basic_rates;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003459
Eliad Peller87fbcb02011-10-05 11:55:41 +02003460 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003461 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003462 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
Eliad Peller87fbcb02011-10-05 11:55:41 +02003463 wlvif->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003464
Eliad Peller87fbcb02011-10-05 11:55:41 +02003465 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003466 if (ret < 0) {
Arik Nemtsov70f47422011-04-18 14:15:25 +03003467 wl1271_error("AP rate policy change failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003468 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003469 }
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003470
Eliad Peller784f6942011-10-05 11:55:39 +02003471 ret = wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003472 if (ret < 0)
3473 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003474 }
3475
Arik Nemtsove78a2872010-10-16 19:07:21 +02003476 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3477 if (ret < 0)
3478 goto out;
3479
3480 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3481 if (bss_conf->enable_beacon) {
Eliad Peller53d40d02011-10-10 10:13:02 +02003482 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003483 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003484 if (ret < 0)
3485 goto out;
3486
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003487 ret = wl1271_ap_init_hwenc(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003488 if (ret < 0)
3489 goto out;
Arik Nemtsovcf420392011-08-14 13:17:37 +03003490
Eliad Peller53d40d02011-10-10 10:13:02 +02003491 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsovcf420392011-08-14 13:17:37 +03003492 wl1271_debug(DEBUG_AP, "started AP");
Arik Nemtsove78a2872010-10-16 19:07:21 +02003493 }
3494 } else {
Eliad Peller53d40d02011-10-10 10:13:02 +02003495 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003496 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003497 if (ret < 0)
3498 goto out;
3499
Eliad Peller53d40d02011-10-10 10:13:02 +02003500 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003501 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3502 &wlvif->flags);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003503 wl1271_debug(DEBUG_AP, "stopped AP");
3504 }
3505 }
3506 }
3507
Eliad Peller0603d892011-10-05 11:55:51 +02003508 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003509 if (ret < 0)
3510 goto out;
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003511
3512 /* Handle HT information change */
3513 if ((changed & BSS_CHANGED_HT) &&
3514 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003515 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003516 bss_conf->ht_operation_mode);
3517 if (ret < 0) {
3518 wl1271_warning("Set ht information failed %d", ret);
3519 goto out;
3520 }
3521 }
3522
Arik Nemtsove78a2872010-10-16 19:07:21 +02003523out:
3524 return;
3525}
3526
3527/* STA/IBSS mode changes */
3528static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3529 struct ieee80211_vif *vif,
3530 struct ieee80211_bss_conf *bss_conf,
3531 u32 changed)
3532{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003533 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003534 bool do_join = false, set_assoc = false;
Eliad Peller536129c2011-10-05 11:55:45 +02003535 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Eliad Peller227e81e2011-08-14 13:17:26 +03003536 bool ibss_joined = false;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003537 u32 sta_rate_set = 0;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003538 int ret;
Luciano Coelho2d6e4e762011-01-11 19:07:21 +01003539 struct ieee80211_sta *sta;
Arik Nemtsova1008852011-02-12 23:24:20 +02003540 bool sta_exists = false;
3541 struct ieee80211_sta_ht_cap sta_ht_cap;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003542
3543 if (is_ibss) {
3544 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3545 changed);
3546 if (ret < 0)
3547 goto out;
3548 }
3549
Eliad Peller227e81e2011-08-14 13:17:26 +03003550 if (changed & BSS_CHANGED_IBSS) {
3551 if (bss_conf->ibss_joined) {
Eliad Pellereee514e2011-10-10 10:13:01 +02003552 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
Eliad Peller227e81e2011-08-14 13:17:26 +03003553 ibss_joined = true;
3554 } else {
Eliad Pellereee514e2011-10-10 10:13:01 +02003555 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3556 &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003557 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003558 wl12xx_start_dev(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03003559 }
3560 }
3561 }
3562
3563 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003564 do_join = true;
3565
3566 /* Need to update the SSID (for filtering etc) */
Eliad Peller227e81e2011-08-14 13:17:26 +03003567 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003568 do_join = true;
3569
Eliad Peller227e81e2011-08-14 13:17:26 +03003570 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003571 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3572 bss_conf->enable_beacon ? "enabled" : "disabled");
3573
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003574 do_join = true;
3575 }
3576
Eliad Pellerc31e4942011-10-23 08:21:55 +02003577 if (changed & BSS_CHANGED_IDLE) {
3578 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3579 if (ret < 0)
3580 wl1271_warning("idle mode change failed %d", ret);
3581 }
3582
Arik Nemtsove78a2872010-10-16 19:07:21 +02003583 if ((changed & BSS_CHANGED_CQM)) {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003584 bool enable = false;
3585 if (bss_conf->cqm_rssi_thold)
3586 enable = true;
Eliad Peller0603d892011-10-05 11:55:51 +02003587 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003588 bss_conf->cqm_rssi_thold,
3589 bss_conf->cqm_rssi_hyst);
3590 if (ret < 0)
3591 goto out;
Eliad Peller04324d92011-10-05 11:56:03 +02003592 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003593 }
3594
Eliad Peller7db4ee62012-01-24 18:18:42 +02003595 if (changed & BSS_CHANGED_BSSID &&
3596 (is_ibss || bss_conf->assoc))
Eliad Pellercdf09492011-10-05 11:55:44 +02003597 if (!is_zero_ether_addr(bss_conf->bssid)) {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003598 ret = wl12xx_cmd_build_null_data(wl, wlvif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003599 if (ret < 0)
3600 goto out;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003601
Eliad Peller784f6942011-10-05 11:55:39 +02003602 ret = wl1271_build_qos_null_data(wl, vif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003603 if (ret < 0)
3604 goto out;
Saravanan Dhanabal141418c2010-04-28 09:50:00 +03003605
Eliad Pellerfa287b82010-12-26 09:27:50 +01003606 /* Need to update the BSSID (for filtering etc) */
3607 do_join = true;
3608 }
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003609
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003610 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3611 rcu_read_lock();
3612 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3613 if (!sta)
3614 goto sta_not_found;
3615
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003616 /* save the supp_rates of the ap */
3617 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3618 if (sta->ht_cap.ht_supported)
3619 sta_rate_set |=
3620 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
Arik Nemtsova1008852011-02-12 23:24:20 +02003621 sta_ht_cap = sta->ht_cap;
3622 sta_exists = true;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003623
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003624sta_not_found:
3625 rcu_read_unlock();
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003626 }
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003627
Arik Nemtsove78a2872010-10-16 19:07:21 +02003628 if ((changed & BSS_CHANGED_ASSOC)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003629 if (bss_conf->assoc) {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003630 u32 rates;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003631 int ieoffset;
Eliad Peller6840e372011-10-05 11:55:50 +02003632 wlvif->aid = bss_conf->aid;
Juuso Oikarinen69e54342010-05-07 11:39:00 +03003633 set_assoc = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003634
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003635 /*
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003636 * use basic rates from AP, and determine lowest rate
3637 * to use with control frames.
3638 */
3639 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003640 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003641 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003642 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003643 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003644 wl1271_tx_min_rate_get(wl,
3645 wlvif->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003646 if (sta_rate_set)
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003647 wlvif->rate_set =
3648 wl1271_tx_enabled_rates_get(wl,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003649 sta_rate_set,
Eliad Peller1b92f152011-10-10 10:13:09 +02003650 wlvif->band);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003651 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003652 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003653 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003654
3655 /*
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003656 * with wl1271, we don't need to update the
3657 * beacon_int and dtim_period, because the firmware
3658 * updates it by itself when the first beacon is
3659 * received after a join.
3660 */
Eliad Peller6840e372011-10-05 11:55:50 +02003661 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003662 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003663 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003664
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003665 /*
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003666 * Get a template for hardware connection maintenance
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003667 */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003668 dev_kfree_skb(wlvif->probereq);
3669 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
Eliad Peller83587502011-10-10 10:12:53 +02003670 wlvif,
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003671 NULL);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003672 ieoffset = offsetof(struct ieee80211_mgmt,
3673 u.probe_req.variable);
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003674 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003675
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003676 /* enable the connection monitoring feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003677 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003678 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003679 goto out;
Juuso Oikarinend94cd292009-10-08 21:56:25 +03003680 } else {
3681 /* use defaults when not associated */
Eliad Peller30df14d2011-04-05 19:13:28 +03003682 bool was_assoc =
Eliad Pellerba8447f2011-10-10 10:13:00 +02003683 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3684 &wlvif->flags);
Eliad Peller251c1772011-08-14 13:17:17 +03003685 bool was_ifup =
Eliad Peller8181aec2011-10-10 10:13:04 +02003686 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3687 &wlvif->flags);
Eliad Peller6840e372011-10-05 11:55:50 +02003688 wlvif->aid = 0;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003689
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003690 /* free probe-request template */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003691 dev_kfree_skb(wlvif->probereq);
3692 wlvif->probereq = NULL;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003693
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003694 /* revert back to minimum rates for the current band */
Eliad Peller87fbcb02011-10-05 11:55:41 +02003695 wl1271_set_band_rate(wl, wlvif);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003696 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003697 wl1271_tx_min_rate_get(wl,
3698 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003699 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003700 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003701 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003702
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003703 /* disable connection monitor features */
Eliad Peller0603d892011-10-05 11:55:51 +02003704 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003705
3706 /* Disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003707 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003708 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003709 goto out;
Juuso Oikarinenb84a7d32010-11-22 12:59:08 +02003710
3711 /* restore the bssid filter and go to dummy bssid */
Eliad Peller30df14d2011-04-05 19:13:28 +03003712 if (was_assoc) {
Eliad Peller251c1772011-08-14 13:17:17 +03003713 u32 conf_flags = wl->hw->conf.flags;
3714 /*
3715 * we might have to disable roc, if there was
3716 * no IF_OPER_UP notification.
3717 */
3718 if (!was_ifup) {
Eliad Peller0603d892011-10-05 11:55:51 +02003719 ret = wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003720 if (ret < 0)
3721 goto out;
3722 }
3723 /*
3724 * (we also need to disable roc in case of
3725 * roaming on the same channel. until we will
3726 * have a better flow...)
3727 */
Eliad Peller7edebf52011-10-05 11:55:52 +02003728 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3729 ret = wl12xx_croc(wl,
3730 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003731 if (ret < 0)
3732 goto out;
3733 }
3734
Eliad Peller0603d892011-10-05 11:55:51 +02003735 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003736 if (!(conf_flags & IEEE80211_CONF_IDLE))
3737 wl12xx_start_dev(wl, wlvif);
Eliad Peller30df14d2011-04-05 19:13:28 +03003738 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003739 }
3740 }
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03003741
Eliad Pellerd192d262011-05-24 14:33:08 +03003742 if (changed & BSS_CHANGED_IBSS) {
3743 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3744 bss_conf->ibss_joined);
3745
3746 if (bss_conf->ibss_joined) {
3747 u32 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003748 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003749 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003750 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003751 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003752 wl1271_tx_min_rate_get(wl,
3753 wlvif->basic_rate_set);
Eliad Pellerd192d262011-05-24 14:33:08 +03003754
Shahar Levi06b660e2011-09-05 13:54:36 +03003755 /* by default, use 11b + OFDM rates */
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003756 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3757 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Eliad Pellerd192d262011-05-24 14:33:08 +03003758 if (ret < 0)
3759 goto out;
3760 }
3761 }
3762
Eliad Peller0603d892011-10-05 11:55:51 +02003763 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003764 if (ret < 0)
3765 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003766
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003767 if (changed & BSS_CHANGED_ARP_FILTER) {
3768 __be32 addr = bss_conf->arp_addr_list[0];
Eliad Peller536129c2011-10-05 11:55:45 +02003769 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003770
Eliad Pellerc5312772010-12-09 11:31:27 +02003771 if (bss_conf->arp_addr_cnt == 1 &&
3772 bss_conf->arp_filter_enabled) {
3773 /*
3774 * The template should have been configured only upon
3775 * association. however, it seems that the correct ip
3776 * isn't being set (when sending), so we have to
3777 * reconfigure the template upon every ip change.
3778 */
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003779 ret = wl1271_cmd_build_arp_rsp(wl, wlvif, addr);
Eliad Pellerc5312772010-12-09 11:31:27 +02003780 if (ret < 0) {
3781 wl1271_warning("build arp rsp failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003782 goto out;
Eliad Pellerc5312772010-12-09 11:31:27 +02003783 }
3784
Eliad Peller0603d892011-10-05 11:55:51 +02003785 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
Eliad Pellere5e2f242011-01-24 19:19:03 +01003786 ACX_ARP_FILTER_ARP_FILTERING,
Eliad Pellerc5312772010-12-09 11:31:27 +02003787 addr);
3788 } else
Eliad Peller0603d892011-10-05 11:55:51 +02003789 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003790
3791 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003792 goto out;
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003793 }
3794
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003795 if (do_join) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003796 ret = wl1271_join(wl, wlvif, set_assoc);
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003797 if (ret < 0) {
3798 wl1271_warning("cmd join failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003799 goto out;
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003800 }
Eliad Peller251c1772011-08-14 13:17:17 +03003801
3802 /* ROC until connected (after EAPOL exchange) */
3803 if (!is_ibss) {
Eliad Peller1b92f152011-10-10 10:13:09 +02003804 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003805 if (ret < 0)
3806 goto out;
3807
Eliad Pellerba8447f2011-10-10 10:13:00 +02003808 wl1271_check_operstate(wl, wlvif,
Eliad Peller251c1772011-08-14 13:17:17 +03003809 ieee80211_get_operstate(vif));
3810 }
3811 /*
3812 * stop device role if started (we might already be in
Eliad Peller92e712d2011-12-18 20:25:43 +02003813 * STA/IBSS role).
Eliad Peller251c1772011-08-14 13:17:17 +03003814 */
Eliad Peller92e712d2011-12-18 20:25:43 +02003815 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02003816 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003817 if (ret < 0)
3818 goto out;
3819 }
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003820 }
3821
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003822 /* Handle new association with HT. Do this after join. */
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003823 if (sta_exists) {
3824 if ((changed & BSS_CHANGED_HT) &&
3825 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003826 ret = wl1271_acx_set_ht_capabilities(wl,
3827 &sta_ht_cap,
3828 true,
Eliad Peller154da672011-10-05 11:55:53 +02003829 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003830 if (ret < 0) {
3831 wl1271_warning("Set ht cap true failed %d",
3832 ret);
3833 goto out;
3834 }
3835 }
3836 /* handle new association without HT and disassociation */
3837 else if (changed & BSS_CHANGED_ASSOC) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003838 ret = wl1271_acx_set_ht_capabilities(wl,
3839 &sta_ht_cap,
3840 false,
Eliad Peller154da672011-10-05 11:55:53 +02003841 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003842 if (ret < 0) {
3843 wl1271_warning("Set ht cap false failed %d",
3844 ret);
3845 goto out;
3846 }
3847 }
3848 }
3849
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003850 /* Handle HT information change. Done after join. */
3851 if ((changed & BSS_CHANGED_HT) &&
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003852 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003853 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003854 bss_conf->ht_operation_mode);
3855 if (ret < 0) {
3856 wl1271_warning("Set ht information failed %d", ret);
3857 goto out;
3858 }
3859 }
3860
Arik Nemtsove78a2872010-10-16 19:07:21 +02003861out:
3862 return;
3863}
3864
3865static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3866 struct ieee80211_vif *vif,
3867 struct ieee80211_bss_conf *bss_conf,
3868 u32 changed)
3869{
3870 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003871 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3872 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003873 int ret;
3874
3875 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3876 (int)changed);
3877
3878 mutex_lock(&wl->mutex);
3879
3880 if (unlikely(wl->state == WL1271_STATE_OFF))
3881 goto out;
3882
Eliad Peller10c8cd02011-10-10 10:13:06 +02003883 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3884 goto out;
3885
Ido Yariva6208652011-03-01 15:14:41 +02003886 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003887 if (ret < 0)
3888 goto out;
3889
3890 if (is_ap)
3891 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3892 else
3893 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3894
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003895 wl1271_ps_elp_sleep(wl);
3896
3897out:
3898 mutex_unlock(&wl->mutex);
3899}
3900
Eliad Peller8a3a3c82011-10-02 10:15:52 +02003901static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3902 struct ieee80211_vif *vif, u16 queue,
Kalle Valoc6999d82010-02-18 13:25:41 +02003903 const struct ieee80211_tx_queue_params *params)
3904{
3905 struct wl1271 *wl = hw->priv;
Eliad Peller0603d892011-10-05 11:55:51 +02003906 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo4695dc92010-03-18 12:26:38 +02003907 u8 ps_scheme;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003908 int ret = 0;
Kalle Valoc6999d82010-02-18 13:25:41 +02003909
3910 mutex_lock(&wl->mutex);
3911
3912 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
3913
Kalle Valo4695dc92010-03-18 12:26:38 +02003914 if (params->uapsd)
3915 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
3916 else
3917 ps_scheme = CONF_PS_SCHEME_LEGACY;
3918
Eliad Peller5b37ddf2011-12-18 20:25:40 +02003919 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003920 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003921
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003922 ret = wl1271_ps_elp_wakeup(wl);
3923 if (ret < 0)
3924 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003925
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003926 /*
3927 * the txop is confed in units of 32us by the mac80211,
3928 * we need us
3929 */
Eliad Peller0603d892011-10-05 11:55:51 +02003930 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003931 params->cw_min, params->cw_max,
3932 params->aifs, params->txop << 5);
3933 if (ret < 0)
3934 goto out_sleep;
3935
Eliad Peller0603d892011-10-05 11:55:51 +02003936 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003937 CONF_CHANNEL_TYPE_EDCF,
3938 wl1271_tx_get_queue(queue),
3939 ps_scheme, CONF_ACK_POLICY_LEGACY,
3940 0, 0);
Kalle Valoc82c1dd2010-02-18 13:25:47 +02003941
3942out_sleep:
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003943 wl1271_ps_elp_sleep(wl);
Kalle Valoc6999d82010-02-18 13:25:41 +02003944
3945out:
3946 mutex_unlock(&wl->mutex);
3947
3948 return ret;
3949}
3950
Eliad Peller37a41b42011-09-21 14:06:11 +03003951static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
3952 struct ieee80211_vif *vif)
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003953{
3954
3955 struct wl1271 *wl = hw->priv;
Eliad Peller9c531142012-01-31 11:57:18 +02003956 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003957 u64 mactime = ULLONG_MAX;
3958 int ret;
3959
3960 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
3961
3962 mutex_lock(&wl->mutex);
3963
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003964 if (unlikely(wl->state == WL1271_STATE_OFF))
3965 goto out;
3966
Ido Yariva6208652011-03-01 15:14:41 +02003967 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003968 if (ret < 0)
3969 goto out;
3970
Eliad Peller9c531142012-01-31 11:57:18 +02003971 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003972 if (ret < 0)
3973 goto out_sleep;
3974
3975out_sleep:
3976 wl1271_ps_elp_sleep(wl);
3977
3978out:
3979 mutex_unlock(&wl->mutex);
3980 return mactime;
3981}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003982
John W. Linvilleece550d2010-07-28 16:41:06 -04003983static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3984 struct survey_info *survey)
3985{
3986 struct wl1271 *wl = hw->priv;
3987 struct ieee80211_conf *conf = &hw->conf;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003988
John W. Linvilleece550d2010-07-28 16:41:06 -04003989 if (idx != 0)
3990 return -ENOENT;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003991
John W. Linvilleece550d2010-07-28 16:41:06 -04003992 survey->channel = conf->channel;
3993 survey->filled = SURVEY_INFO_NOISE_DBM;
3994 survey->noise = wl->noise;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003995
John W. Linvilleece550d2010-07-28 16:41:06 -04003996 return 0;
3997}
3998
Arik Nemtsov409622e2011-02-23 00:22:29 +02003999static int wl1271_allocate_sta(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004000 struct wl12xx_vif *wlvif,
4001 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004002{
4003 struct wl1271_station *wl_sta;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004004 int ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004005
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004006
4007 if (wl->active_sta_count >= AP_MAX_STATIONS) {
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004008 wl1271_warning("could not allocate HLID - too much stations");
4009 return -EBUSY;
4010 }
4011
4012 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004013 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4014 if (ret < 0) {
4015 wl1271_warning("could not allocate HLID - too many links");
4016 return -EBUSY;
4017 }
4018
4019 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004020 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
Arik Nemtsovda032092011-08-25 12:43:15 +03004021 wl->active_sta_count++;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004022 return 0;
4023}
4024
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004025void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004026{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004027 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
Arik Nemtsovf1acea92011-08-25 12:43:17 +03004028 return;
4029
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004030 clear_bit(hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004031 memset(wl->links[hlid].addr, 0, ETH_ALEN);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004032 wl->links[hlid].ba_bitmap = 0;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02004033 wl1271_tx_reset_link_queues(wl, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004034 __clear_bit(hlid, &wl->ap_ps_map);
4035 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004036 wl12xx_free_link(wl, wlvif, &hlid);
Arik Nemtsovda032092011-08-25 12:43:15 +03004037 wl->active_sta_count--;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004038}
4039
4040static int wl1271_op_sta_add(struct ieee80211_hw *hw,
4041 struct ieee80211_vif *vif,
4042 struct ieee80211_sta *sta)
4043{
4044 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004045 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004046 struct wl1271_station *wl_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004047 int ret = 0;
4048 u8 hlid;
4049
4050 mutex_lock(&wl->mutex);
4051
4052 if (unlikely(wl->state == WL1271_STATE_OFF))
4053 goto out;
4054
Eliad Peller536129c2011-10-05 11:55:45 +02004055 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004056 goto out;
4057
4058 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4059
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004060 ret = wl1271_allocate_sta(wl, wlvif, sta);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004061 if (ret < 0)
4062 goto out;
4063
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004064 wl_sta = (struct wl1271_station *)sta->drv_priv;
4065 hlid = wl_sta->hlid;
4066
Ido Yariva6208652011-03-01 15:14:41 +02004067 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004068 if (ret < 0)
Arik Nemtsov409622e2011-02-23 00:22:29 +02004069 goto out_free_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004070
Eliad Peller1b92f152011-10-10 10:13:09 +02004071 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004072 if (ret < 0)
4073 goto out_sleep;
4074
Eliad Pellerb67476e2011-08-14 13:17:23 +03004075 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4076 if (ret < 0)
4077 goto out_sleep;
4078
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03004079 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, hlid);
4080 if (ret < 0)
4081 goto out_sleep;
4082
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004083out_sleep:
4084 wl1271_ps_elp_sleep(wl);
4085
Arik Nemtsov409622e2011-02-23 00:22:29 +02004086out_free_sta:
4087 if (ret < 0)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004088 wl1271_free_sta(wl, wlvif, hlid);
Arik Nemtsov409622e2011-02-23 00:22:29 +02004089
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004090out:
4091 mutex_unlock(&wl->mutex);
4092 return ret;
4093}
4094
4095static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
4096 struct ieee80211_vif *vif,
4097 struct ieee80211_sta *sta)
4098{
4099 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004100 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004101 struct wl1271_station *wl_sta;
4102 int ret = 0, id;
4103
4104 mutex_lock(&wl->mutex);
4105
4106 if (unlikely(wl->state == WL1271_STATE_OFF))
4107 goto out;
4108
Eliad Peller536129c2011-10-05 11:55:45 +02004109 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004110 goto out;
4111
4112 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4113
4114 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004115 id = wl_sta->hlid;
4116 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004117 goto out;
4118
Ido Yariva6208652011-03-01 15:14:41 +02004119 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004120 if (ret < 0)
4121 goto out;
4122
Eliad Pellerc690ec82011-08-14 13:17:07 +03004123 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004124 if (ret < 0)
4125 goto out_sleep;
4126
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004127 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004128
4129out_sleep:
4130 wl1271_ps_elp_sleep(wl);
4131
4132out:
4133 mutex_unlock(&wl->mutex);
4134 return ret;
4135}
4136
Luciano Coelho4623ec72011-03-21 19:26:41 +02004137static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4138 struct ieee80211_vif *vif,
4139 enum ieee80211_ampdu_mlme_action action,
4140 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4141 u8 buf_size)
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004142{
4143 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004144 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004145 int ret;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004146 u8 hlid, *ba_bitmap;
4147
4148 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4149 tid);
4150
4151 /* sanity check - the fields in FW are only 8bits wide */
4152 if (WARN_ON(tid > 0xFF))
4153 return -ENOTSUPP;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004154
4155 mutex_lock(&wl->mutex);
4156
4157 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4158 ret = -EAGAIN;
4159 goto out;
4160 }
4161
Eliad Peller536129c2011-10-05 11:55:45 +02004162 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
Eliad Peller154da672011-10-05 11:55:53 +02004163 hlid = wlvif->sta.hlid;
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004164 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
Eliad Peller536129c2011-10-05 11:55:45 +02004165 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004166 struct wl1271_station *wl_sta;
4167
4168 wl_sta = (struct wl1271_station *)sta->drv_priv;
4169 hlid = wl_sta->hlid;
4170 ba_bitmap = &wl->links[hlid].ba_bitmap;
4171 } else {
4172 ret = -EINVAL;
4173 goto out;
4174 }
4175
Ido Yariva6208652011-03-01 15:14:41 +02004176 ret = wl1271_ps_elp_wakeup(wl);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004177 if (ret < 0)
4178 goto out;
4179
Shahar Levi70559a02011-05-22 16:10:22 +03004180 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4181 tid, action);
4182
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004183 switch (action) {
4184 case IEEE80211_AMPDU_RX_START:
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004185 if (!wlvif->ba_support || !wlvif->ba_allowed) {
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004186 ret = -ENOTSUPP;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004187 break;
4188 }
4189
4190 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4191 ret = -EBUSY;
4192 wl1271_error("exceeded max RX BA sessions");
4193 break;
4194 }
4195
4196 if (*ba_bitmap & BIT(tid)) {
4197 ret = -EINVAL;
4198 wl1271_error("cannot enable RX BA session on active "
4199 "tid: %d", tid);
4200 break;
4201 }
4202
4203 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4204 hlid);
4205 if (!ret) {
4206 *ba_bitmap |= BIT(tid);
4207 wl->ba_rx_session_count++;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004208 }
4209 break;
4210
4211 case IEEE80211_AMPDU_RX_STOP:
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004212 if (!(*ba_bitmap & BIT(tid))) {
4213 ret = -EINVAL;
4214 wl1271_error("no active RX BA session on tid: %d",
4215 tid);
4216 break;
4217 }
4218
4219 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4220 hlid);
4221 if (!ret) {
4222 *ba_bitmap &= ~BIT(tid);
4223 wl->ba_rx_session_count--;
4224 }
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004225 break;
4226
4227 /*
4228 * The BA initiator session management in FW independently.
4229 * Falling break here on purpose for all TX APDU commands.
4230 */
4231 case IEEE80211_AMPDU_TX_START:
4232 case IEEE80211_AMPDU_TX_STOP:
4233 case IEEE80211_AMPDU_TX_OPERATIONAL:
4234 ret = -EINVAL;
4235 break;
4236
4237 default:
4238 wl1271_error("Incorrect ampdu action id=%x\n", action);
4239 ret = -EINVAL;
4240 }
4241
4242 wl1271_ps_elp_sleep(wl);
4243
4244out:
4245 mutex_unlock(&wl->mutex);
4246
4247 return ret;
4248}
4249
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004250static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4251 struct ieee80211_vif *vif,
4252 const struct cfg80211_bitrate_mask *mask)
4253{
Eliad Peller83587502011-10-10 10:12:53 +02004254 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004255 struct wl1271 *wl = hw->priv;
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004256 int i, ret = 0;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004257
4258 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4259 mask->control[NL80211_BAND_2GHZ].legacy,
4260 mask->control[NL80211_BAND_5GHZ].legacy);
4261
4262 mutex_lock(&wl->mutex);
4263
4264 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Eliad Peller83587502011-10-10 10:12:53 +02004265 wlvif->bitrate_masks[i] =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004266 wl1271_tx_enabled_rates_get(wl,
4267 mask->control[i].legacy,
4268 i);
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004269
4270 if (unlikely(wl->state == WL1271_STATE_OFF))
4271 goto out;
4272
4273 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4274 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4275
4276 ret = wl1271_ps_elp_wakeup(wl);
4277 if (ret < 0)
4278 goto out;
4279
4280 wl1271_set_band_rate(wl, wlvif);
4281 wlvif->basic_rate =
4282 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4283 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4284
4285 wl1271_ps_elp_sleep(wl);
4286 }
4287out:
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004288 mutex_unlock(&wl->mutex);
4289
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004290 return ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004291}
4292
Shahar Levi6d158ff2011-09-08 13:01:33 +03004293static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4294 struct ieee80211_channel_switch *ch_switch)
4295{
4296 struct wl1271 *wl = hw->priv;
Eliad Peller52630c52011-10-10 10:13:08 +02004297 struct wl12xx_vif *wlvif;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004298 int ret;
4299
4300 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4301
4302 mutex_lock(&wl->mutex);
4303
4304 if (unlikely(wl->state == WL1271_STATE_OFF)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02004305 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4306 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4307 ieee80211_chswitch_done(vif, false);
4308 }
4309 goto out;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004310 }
4311
4312 ret = wl1271_ps_elp_wakeup(wl);
4313 if (ret < 0)
4314 goto out;
4315
Eliad Peller52630c52011-10-10 10:13:08 +02004316 /* TODO: change mac80211 to pass vif as param */
4317 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller8332f0f2012-01-31 11:57:19 +02004318 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
Shahar Levi6d158ff2011-09-08 13:01:33 +03004319
Eliad Peller52630c52011-10-10 10:13:08 +02004320 if (!ret)
4321 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4322 }
Shahar Levi6d158ff2011-09-08 13:01:33 +03004323
4324 wl1271_ps_elp_sleep(wl);
4325
4326out:
4327 mutex_unlock(&wl->mutex);
4328}
4329
Arik Nemtsov33437892011-04-26 23:35:39 +03004330static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4331{
4332 struct wl1271 *wl = hw->priv;
4333 bool ret = false;
4334
4335 mutex_lock(&wl->mutex);
4336
4337 if (unlikely(wl->state == WL1271_STATE_OFF))
4338 goto out;
4339
4340 /* packets are considered pending if in the TX queue or the FW */
Arik Nemtsovf1a46382011-07-07 14:25:23 +03004341 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
Arik Nemtsov33437892011-04-26 23:35:39 +03004342out:
4343 mutex_unlock(&wl->mutex);
4344
4345 return ret;
4346}
4347
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004348/* can't be const, mac80211 writes to this */
4349static struct ieee80211_rate wl1271_rates[] = {
4350 { .bitrate = 10,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004351 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4352 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004353 { .bitrate = 20,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004354 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4355 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004356 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4357 { .bitrate = 55,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004358 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4359 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004360 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4361 { .bitrate = 110,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004362 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4363 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004364 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4365 { .bitrate = 60,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004366 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4367 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004368 { .bitrate = 90,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004369 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4370 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004371 { .bitrate = 120,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004372 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4373 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004374 { .bitrate = 180,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004375 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4376 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004377 { .bitrate = 240,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004378 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4379 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004380 { .bitrate = 360,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004381 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4382 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004383 { .bitrate = 480,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004384 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4385 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004386 { .bitrate = 540,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004387 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4388 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004389};
4390
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004391/* can't be const, mac80211 writes to this */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004392static struct ieee80211_channel wl1271_channels[] = {
Luciano Coelhoa2d0e3f2009-12-11 15:40:46 +02004393 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004394 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004395 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4396 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4397 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004398 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004399 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4400 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4401 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004402 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004403 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4404 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4405 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
Arik Nemtsov6c89b7b2011-01-18 20:39:52 +01004406 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004407};
4408
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004409/* mapping to indexes for wl1271_rates */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004410static const u8 wl1271_rate_to_idx_2ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004411 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004412 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004413 7, /* CONF_HW_RXTX_RATE_MCS7 */
4414 6, /* CONF_HW_RXTX_RATE_MCS6 */
4415 5, /* CONF_HW_RXTX_RATE_MCS5 */
4416 4, /* CONF_HW_RXTX_RATE_MCS4 */
4417 3, /* CONF_HW_RXTX_RATE_MCS3 */
4418 2, /* CONF_HW_RXTX_RATE_MCS2 */
4419 1, /* CONF_HW_RXTX_RATE_MCS1 */
4420 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004421
4422 11, /* CONF_HW_RXTX_RATE_54 */
4423 10, /* CONF_HW_RXTX_RATE_48 */
4424 9, /* CONF_HW_RXTX_RATE_36 */
4425 8, /* CONF_HW_RXTX_RATE_24 */
4426
4427 /* TI-specific rate */
4428 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4429
4430 7, /* CONF_HW_RXTX_RATE_18 */
4431 6, /* CONF_HW_RXTX_RATE_12 */
4432 3, /* CONF_HW_RXTX_RATE_11 */
4433 5, /* CONF_HW_RXTX_RATE_9 */
4434 4, /* CONF_HW_RXTX_RATE_6 */
4435 2, /* CONF_HW_RXTX_RATE_5_5 */
4436 1, /* CONF_HW_RXTX_RATE_2 */
4437 0 /* CONF_HW_RXTX_RATE_1 */
4438};
4439
Shahar Levie8b03a22010-10-13 16:09:39 +02004440/* 11n STA capabilities */
4441#define HW_RX_HIGHEST_RATE 72
4442
Shahar Levi00d20102010-11-08 11:20:10 +00004443#define WL12XX_HT_CAP { \
Shahar Levi871d0c32011-03-13 11:24:40 +02004444 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4445 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
Shahar Levie8b03a22010-10-13 16:09:39 +02004446 .ht_supported = true, \
4447 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4448 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4449 .mcs = { \
4450 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4451 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4452 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4453 }, \
4454}
4455
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004456/* can't be const, mac80211 writes to this */
4457static struct ieee80211_supported_band wl1271_band_2ghz = {
4458 .channels = wl1271_channels,
4459 .n_channels = ARRAY_SIZE(wl1271_channels),
4460 .bitrates = wl1271_rates,
4461 .n_bitrates = ARRAY_SIZE(wl1271_rates),
Shahar Levi00d20102010-11-08 11:20:10 +00004462 .ht_cap = WL12XX_HT_CAP,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004463};
4464
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004465/* 5 GHz data rates for WL1273 */
4466static struct ieee80211_rate wl1271_rates_5ghz[] = {
4467 { .bitrate = 60,
4468 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4469 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4470 { .bitrate = 90,
4471 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4472 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4473 { .bitrate = 120,
4474 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4475 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4476 { .bitrate = 180,
4477 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4478 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4479 { .bitrate = 240,
4480 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4481 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4482 { .bitrate = 360,
4483 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4484 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4485 { .bitrate = 480,
4486 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4487 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4488 { .bitrate = 540,
4489 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4490 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4491};
4492
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004493/* 5 GHz band channels for WL1273 */
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004494static struct ieee80211_channel wl1271_channels_5ghz[] = {
Arik Nemtsov6cfa5cf2011-06-27 22:06:33 +03004495 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4496 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4497 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4498 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4499 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4500 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4501 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4502 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4503 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4504 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4505 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4506 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4507 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4508 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4509 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4510 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4511 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4512 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4513 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4514 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4515 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4516 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4517 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4518 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4519 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4520 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4521 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4522 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4523 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4524 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4525 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4526 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4527 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4528 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004529};
4530
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004531/* mapping to indexes for wl1271_rates_5ghz */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004532static const u8 wl1271_rate_to_idx_5ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004533 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004534 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004535 7, /* CONF_HW_RXTX_RATE_MCS7 */
4536 6, /* CONF_HW_RXTX_RATE_MCS6 */
4537 5, /* CONF_HW_RXTX_RATE_MCS5 */
4538 4, /* CONF_HW_RXTX_RATE_MCS4 */
4539 3, /* CONF_HW_RXTX_RATE_MCS3 */
4540 2, /* CONF_HW_RXTX_RATE_MCS2 */
4541 1, /* CONF_HW_RXTX_RATE_MCS1 */
4542 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004543
4544 7, /* CONF_HW_RXTX_RATE_54 */
4545 6, /* CONF_HW_RXTX_RATE_48 */
4546 5, /* CONF_HW_RXTX_RATE_36 */
4547 4, /* CONF_HW_RXTX_RATE_24 */
4548
4549 /* TI-specific rate */
4550 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4551
4552 3, /* CONF_HW_RXTX_RATE_18 */
4553 2, /* CONF_HW_RXTX_RATE_12 */
4554 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4555 1, /* CONF_HW_RXTX_RATE_9 */
4556 0, /* CONF_HW_RXTX_RATE_6 */
4557 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4558 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4559 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4560};
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004561
4562static struct ieee80211_supported_band wl1271_band_5ghz = {
4563 .channels = wl1271_channels_5ghz,
4564 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4565 .bitrates = wl1271_rates_5ghz,
4566 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
Shahar Levi00d20102010-11-08 11:20:10 +00004567 .ht_cap = WL12XX_HT_CAP,
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004568};
4569
Tobias Klausera0ea9492010-05-20 10:38:11 +02004570static const u8 *wl1271_band_rate_to_idx[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004571 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4572 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4573};
4574
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004575static const struct ieee80211_ops wl1271_ops = {
4576 .start = wl1271_op_start,
4577 .stop = wl1271_op_stop,
4578 .add_interface = wl1271_op_add_interface,
4579 .remove_interface = wl1271_op_remove_interface,
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02004580 .change_interface = wl12xx_op_change_interface,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004581#ifdef CONFIG_PM
Eliad Peller402e48612011-05-13 11:57:09 +03004582 .suspend = wl1271_op_suspend,
4583 .resume = wl1271_op_resume,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004584#endif
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004585 .config = wl1271_op_config,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03004586 .prepare_multicast = wl1271_op_prepare_multicast,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004587 .configure_filter = wl1271_op_configure_filter,
4588 .tx = wl1271_op_tx,
4589 .set_key = wl1271_op_set_key,
4590 .hw_scan = wl1271_op_hw_scan,
Eliad Peller73ecce32011-06-27 13:06:45 +03004591 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
Luciano Coelho33c2c062011-05-10 14:46:02 +03004592 .sched_scan_start = wl1271_op_sched_scan_start,
4593 .sched_scan_stop = wl1271_op_sched_scan_stop,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004594 .bss_info_changed = wl1271_op_bss_info_changed,
Arik Nemtsov68d069c2010-11-08 10:51:07 +01004595 .set_frag_threshold = wl1271_op_set_frag_threshold,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004596 .set_rts_threshold = wl1271_op_set_rts_threshold,
Kalle Valoc6999d82010-02-18 13:25:41 +02004597 .conf_tx = wl1271_op_conf_tx,
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004598 .get_tsf = wl1271_op_get_tsf,
John W. Linvilleece550d2010-07-28 16:41:06 -04004599 .get_survey = wl1271_op_get_survey,
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004600 .sta_add = wl1271_op_sta_add,
4601 .sta_remove = wl1271_op_sta_remove,
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004602 .ampdu_action = wl1271_op_ampdu_action,
Arik Nemtsov33437892011-04-26 23:35:39 +03004603 .tx_frames_pending = wl1271_tx_frames_pending,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004604 .set_bitrate_mask = wl12xx_set_bitrate_mask,
Shahar Levi6d158ff2011-09-08 13:01:33 +03004605 .channel_switch = wl12xx_op_channel_switch,
Kalle Valoc8c90872010-02-18 13:25:53 +02004606 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004607};
4608
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004609
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004610u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004611{
4612 u8 idx;
4613
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004614 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004615
4616 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4617 wl1271_error("Illegal RX rate from HW: %d", rate);
4618 return 0;
4619 }
4620
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004621 idx = wl1271_band_rate_to_idx[band][rate];
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004622 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4623 wl1271_error("Unsupported RX rate from HW: %d", rate);
4624 return 0;
4625 }
4626
4627 return idx;
4628}
4629
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004630static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4631 struct device_attribute *attr,
4632 char *buf)
4633{
4634 struct wl1271 *wl = dev_get_drvdata(dev);
4635 ssize_t len;
4636
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004637 len = PAGE_SIZE;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004638
4639 mutex_lock(&wl->mutex);
4640 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4641 wl->sg_enabled);
4642 mutex_unlock(&wl->mutex);
4643
4644 return len;
4645
4646}
4647
4648static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4649 struct device_attribute *attr,
4650 const char *buf, size_t count)
4651{
4652 struct wl1271 *wl = dev_get_drvdata(dev);
4653 unsigned long res;
4654 int ret;
4655
Luciano Coelho6277ed62011-04-01 17:49:54 +03004656 ret = kstrtoul(buf, 10, &res);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004657 if (ret < 0) {
4658 wl1271_warning("incorrect value written to bt_coex_mode");
4659 return count;
4660 }
4661
4662 mutex_lock(&wl->mutex);
4663
4664 res = !!res;
4665
4666 if (res == wl->sg_enabled)
4667 goto out;
4668
4669 wl->sg_enabled = res;
4670
4671 if (wl->state == WL1271_STATE_OFF)
4672 goto out;
4673
Ido Yariva6208652011-03-01 15:14:41 +02004674 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004675 if (ret < 0)
4676 goto out;
4677
4678 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4679 wl1271_ps_elp_sleep(wl);
4680
4681 out:
4682 mutex_unlock(&wl->mutex);
4683 return count;
4684}
4685
4686static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4687 wl1271_sysfs_show_bt_coex_state,
4688 wl1271_sysfs_store_bt_coex_state);
4689
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004690static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4691 struct device_attribute *attr,
4692 char *buf)
4693{
4694 struct wl1271 *wl = dev_get_drvdata(dev);
4695 ssize_t len;
4696
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004697 len = PAGE_SIZE;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004698
4699 mutex_lock(&wl->mutex);
4700 if (wl->hw_pg_ver >= 0)
4701 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4702 else
4703 len = snprintf(buf, len, "n/a\n");
4704 mutex_unlock(&wl->mutex);
4705
4706 return len;
4707}
4708
Gery Kahn6f07b722011-07-18 14:21:49 +03004709static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004710 wl1271_sysfs_show_hw_pg_ver, NULL);
4711
Ido Yariv95dac04f2011-06-06 14:57:06 +03004712static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4713 struct bin_attribute *bin_attr,
4714 char *buffer, loff_t pos, size_t count)
4715{
4716 struct device *dev = container_of(kobj, struct device, kobj);
4717 struct wl1271 *wl = dev_get_drvdata(dev);
4718 ssize_t len;
4719 int ret;
4720
4721 ret = mutex_lock_interruptible(&wl->mutex);
4722 if (ret < 0)
4723 return -ERESTARTSYS;
4724
4725 /* Let only one thread read the log at a time, blocking others */
4726 while (wl->fwlog_size == 0) {
4727 DEFINE_WAIT(wait);
4728
4729 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4730 &wait,
4731 TASK_INTERRUPTIBLE);
4732
4733 if (wl->fwlog_size != 0) {
4734 finish_wait(&wl->fwlog_waitq, &wait);
4735 break;
4736 }
4737
4738 mutex_unlock(&wl->mutex);
4739
4740 schedule();
4741 finish_wait(&wl->fwlog_waitq, &wait);
4742
4743 if (signal_pending(current))
4744 return -ERESTARTSYS;
4745
4746 ret = mutex_lock_interruptible(&wl->mutex);
4747 if (ret < 0)
4748 return -ERESTARTSYS;
4749 }
4750
4751 /* Check if the fwlog is still valid */
4752 if (wl->fwlog_size < 0) {
4753 mutex_unlock(&wl->mutex);
4754 return 0;
4755 }
4756
4757 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4758 len = min(count, (size_t)wl->fwlog_size);
4759 wl->fwlog_size -= len;
4760 memcpy(buffer, wl->fwlog, len);
4761
4762 /* Make room for new messages */
4763 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4764
4765 mutex_unlock(&wl->mutex);
4766
4767 return len;
4768}
4769
4770static struct bin_attribute fwlog_attr = {
4771 .attr = {.name = "fwlog", .mode = S_IRUSR},
4772 .read = wl1271_sysfs_read_fwlog,
4773};
4774
Luciano Coelho5e037e72011-12-23 09:32:17 +02004775static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4776{
4777 bool supported = false;
4778 u8 major, minor;
4779
4780 if (wl->chip.id == CHIP_ID_1283_PG20) {
4781 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
4782 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
4783
4784 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
4785 if (major > 2 || (major == 2 && minor >= 1))
4786 supported = true;
4787 } else {
4788 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
4789 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
4790
4791 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
4792 if (major == 3 && minor >= 1)
4793 supported = true;
4794 }
4795
4796 wl1271_debug(DEBUG_PROBE,
4797 "PG Ver major = %d minor = %d, MAC %s present",
4798 major, minor, supported ? "is" : "is not");
4799
4800 return supported;
4801}
4802
4803static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4804 u32 oui, u32 nic, int n)
4805{
4806 int i;
4807
4808 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
4809 oui, nic, n);
4810
4811 if (nic + n - 1 > 0xffffff)
4812 wl1271_warning("NIC part of the MAC address wraps around!");
4813
4814 for (i = 0; i < n; i++) {
4815 wl->addresses[i].addr[0] = (u8)(oui >> 16);
4816 wl->addresses[i].addr[1] = (u8)(oui >> 8);
4817 wl->addresses[i].addr[2] = (u8) oui;
4818 wl->addresses[i].addr[3] = (u8)(nic >> 16);
4819 wl->addresses[i].addr[4] = (u8)(nic >> 8);
4820 wl->addresses[i].addr[5] = (u8) nic;
4821 nic++;
4822 }
4823
4824 wl->hw->wiphy->n_addresses = n;
4825 wl->hw->wiphy->addresses = wl->addresses;
4826}
4827
4828static void wl12xx_get_fuse_mac(struct wl1271 *wl)
4829{
4830 u32 mac1, mac2;
4831
4832 wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
4833
4834 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
4835 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
4836
4837 /* these are the two parts of the BD_ADDR */
4838 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
4839 ((mac1 & 0xff000000) >> 24);
4840 wl->fuse_nic_addr = mac1 & 0xffffff;
4841
4842 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
4843}
4844
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004845static int wl12xx_get_hw_info(struct wl1271 *wl)
4846{
4847 int ret;
4848 u32 die_info;
4849
4850 ret = wl12xx_set_power_on(wl);
4851 if (ret < 0)
4852 goto out;
4853
4854 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
4855
4856 if (wl->chip.id == CHIP_ID_1283_PG20)
4857 die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
4858 else
4859 die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
4860
4861 wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
4862
Luciano Coelho5e037e72011-12-23 09:32:17 +02004863 if (!wl12xx_mac_in_fuse(wl)) {
4864 wl->fuse_oui_addr = 0;
4865 wl->fuse_nic_addr = 0;
4866 } else {
4867 wl12xx_get_fuse_mac(wl);
4868 }
4869
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004870 wl1271_power_off(wl);
4871out:
4872 return ret;
4873}
4874
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004875static int wl1271_register_hw(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004876{
4877 int ret;
Luciano Coelho5e037e72011-12-23 09:32:17 +02004878 u32 oui_addr = 0, nic_addr = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004879
4880 if (wl->mac80211_registered)
4881 return 0;
4882
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004883 ret = wl12xx_get_hw_info(wl);
4884 if (ret < 0) {
4885 wl1271_error("couldn't get hw info");
4886 goto out;
4887 }
4888
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004889 ret = wl1271_fetch_nvs(wl);
4890 if (ret == 0) {
Shahar Levibc765bf2011-03-06 16:32:10 +02004891 /* NOTE: The wl->nvs->nvs element must be first, in
4892 * order to simplify the casting, we assume it is at
4893 * the beginning of the wl->nvs structure.
4894 */
4895 u8 *nvs_ptr = (u8 *)wl->nvs;
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004896
Luciano Coelho5e037e72011-12-23 09:32:17 +02004897 oui_addr =
4898 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
4899 nic_addr =
4900 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004901 }
4902
Luciano Coelho5e037e72011-12-23 09:32:17 +02004903 /* if the MAC address is zeroed in the NVS derive from fuse */
4904 if (oui_addr == 0 && nic_addr == 0) {
4905 oui_addr = wl->fuse_oui_addr;
4906 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
4907 nic_addr = wl->fuse_nic_addr + 1;
4908 }
4909
4910 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004911
4912 ret = ieee80211_register_hw(wl->hw);
4913 if (ret < 0) {
4914 wl1271_error("unable to register mac80211 hw: %d", ret);
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004915 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004916 }
4917
4918 wl->mac80211_registered = true;
4919
Eliad Pellerd60080a2010-11-24 12:53:16 +02004920 wl1271_debugfs_init(wl);
4921
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03004922 register_netdevice_notifier(&wl1271_dev_notifier);
4923
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004924 wl1271_notice("loaded");
4925
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004926out:
4927 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004928}
4929
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004930static void wl1271_unregister_hw(struct wl1271 *wl)
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004931{
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01004932 if (wl->state == WL1271_STATE_PLT)
Ido Yarivf3df1332012-01-11 09:42:39 +02004933 wl1271_plt_stop(wl);
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01004934
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03004935 unregister_netdevice_notifier(&wl1271_dev_notifier);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004936 ieee80211_unregister_hw(wl->hw);
4937 wl->mac80211_registered = false;
4938
4939}
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004940
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004941static int wl1271_init_ieee80211(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004942{
Juuso Oikarinen7a557242010-09-27 12:42:07 +02004943 static const u32 cipher_suites[] = {
4944 WLAN_CIPHER_SUITE_WEP40,
4945 WLAN_CIPHER_SUITE_WEP104,
4946 WLAN_CIPHER_SUITE_TKIP,
4947 WLAN_CIPHER_SUITE_CCMP,
4948 WL1271_CIPHER_SUITE_GEM,
4949 };
4950
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03004951 /* The tx descriptor buffer and the TKIP space. */
4952 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
4953 sizeof(struct wl1271_tx_hw_descr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004954
4955 /* unit us */
4956 /* FIXME: find a proper value */
4957 wl->hw->channel_change_time = 10000;
Juuso Oikarinen50c500a2010-04-01 11:38:22 +03004958 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004959
4960 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
Juuso Oikarinen0a343322010-02-22 08:38:41 +02004961 IEEE80211_HW_SUPPORTS_PS |
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02004962 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo4695dc92010-03-18 12:26:38 +02004963 IEEE80211_HW_SUPPORTS_UAPSD |
Juuso Oikarinena9af0922010-03-26 12:53:30 +02004964 IEEE80211_HW_HAS_RATE_CONTROL |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03004965 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelho25eaea302011-05-02 12:37:33 +03004966 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Shahar Levifcd23b62011-05-11 12:12:56 +03004967 IEEE80211_HW_SPECTRUM_MGMT |
Arik Nemtsov93f8c8e2011-08-30 09:34:01 +03004968 IEEE80211_HW_AP_LINK_PS |
4969 IEEE80211_HW_AMPDU_AGGREGATION |
4970 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004971
Juuso Oikarinen7a557242010-09-27 12:42:07 +02004972 wl->hw->wiphy->cipher_suites = cipher_suites;
4973 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
4974
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02004975 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Eliad Peller045c7452011-08-28 15:23:01 +03004976 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
4977 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004978 wl->hw->wiphy->max_scan_ssids = 1;
Luciano Coelho221737d2011-09-02 14:28:22 +03004979 wl->hw->wiphy->max_sched_scan_ssids = 16;
4980 wl->hw->wiphy->max_match_sets = 16;
Guy Eilamea559b42010-12-09 16:54:59 +02004981 /*
4982 * Maximum length of elements in scanning probe request templates
4983 * should be the maximum length possible for a template, without
4984 * the IEEE80211 header of the template
4985 */
Eliad Peller154037d2011-08-14 13:17:12 +03004986 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_DFLT_SIZE -
Guy Eilamea559b42010-12-09 16:54:59 +02004987 sizeof(struct ieee80211_header);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01004988
Luciano Coelhoc9e79a42011-09-27 16:22:35 +03004989 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_DFLT_SIZE -
4990 sizeof(struct ieee80211_header);
4991
Eliad Peller1ec23f72011-08-25 14:26:54 +03004992 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4993
Luciano Coelho4a31c112011-03-21 23:16:14 +02004994 /* make sure all our channels fit in the scanned_ch bitmask */
4995 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
4996 ARRAY_SIZE(wl1271_channels_5ghz) >
4997 WL1271_MAX_CHANNELS);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01004998 /*
4999 * We keep local copies of the band structs because we need to
5000 * modify them on a per-device basis.
5001 */
5002 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5003 sizeof(wl1271_band_2ghz));
5004 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5005 sizeof(wl1271_band_5ghz));
5006
5007 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5008 &wl->bands[IEEE80211_BAND_2GHZ];
5009 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5010 &wl->bands[IEEE80211_BAND_5GHZ];
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03005011
Kalle Valo12bd8942010-03-18 12:26:33 +02005012 wl->hw->queues = 4;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +02005013 wl->hw->max_rates = 1;
Kalle Valo12bd8942010-03-18 12:26:33 +02005014
Juuso Oikarinenb7417d92010-11-10 11:27:19 +01005015 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5016
Arik Nemtsov9c1b1902011-11-08 18:46:55 +02005017 /* the FW answers probe-requests in AP-mode */
5018 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5019 wl->hw->wiphy->probe_resp_offload =
5020 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5021 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5022 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5023
Felipe Balbia390e852011-10-06 10:07:44 +03005024 SET_IEEE80211_DEV(wl->hw, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005025
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005026 wl->hw->sta_data_size = sizeof(struct wl1271_station);
Eliad Peller87fbcb02011-10-05 11:55:41 +02005027 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005028
Luciano Coelho4c9cfa72011-01-12 14:27:03 +01005029 wl->hw->max_rx_aggregation_subframes = 8;
5030
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005031 return 0;
5032}
5033
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005034#define WL1271_DEFAULT_CHANNEL 0
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005035
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005036static struct ieee80211_hw *wl1271_alloc_hw(void)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005037{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005038 struct ieee80211_hw *hw;
5039 struct wl1271 *wl;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005040 int i, j, ret;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005041 unsigned int order;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005042
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005043 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
Arik Nemtsovf80c2d12011-09-22 09:52:05 +03005044
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005045 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5046 if (!hw) {
5047 wl1271_error("could not alloc ieee80211_hw");
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005048 ret = -ENOMEM;
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005049 goto err_hw_alloc;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005050 }
5051
5052 wl = hw->priv;
5053 memset(wl, 0, sizeof(*wl));
5054
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005055 INIT_LIST_HEAD(&wl->list);
Eliad Peller87627212011-10-10 10:12:54 +02005056 INIT_LIST_HEAD(&wl->wlvif_list);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005057
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005058 wl->hw = hw;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005059
Juuso Oikarinen6742f552010-12-13 09:52:37 +02005060 for (i = 0; i < NUM_TX_QUEUES; i++)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005061 for (j = 0; j < WL12XX_MAX_LINKS; j++)
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005062 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5063
Ido Yariva6208652011-03-01 15:14:41 +02005064 skb_queue_head_init(&wl->deferred_rx_queue);
5065 skb_queue_head_init(&wl->deferred_tx_queue);
5066
Juuso Oikarinen37b70a82009-10-08 21:56:21 +03005067 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
Ido Yariva6208652011-03-01 15:14:41 +02005068 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
Juuso Oikarinen117b38d2010-09-30 10:43:28 +02005069 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5070 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5071 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +03005072
Eliad Peller92ef8962011-06-07 12:50:46 +03005073 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5074 if (!wl->freezable_wq) {
5075 ret = -ENOMEM;
5076 goto err_hw;
5077 }
5078
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005079 wl->channel = WL1271_DEFAULT_CHANNEL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005080 wl->rx_counter = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005081 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03005082 wl->band = IEEE80211_BAND_2GHZ;
Juuso Oikarinenb771eee2009-10-08 21:56:34 +03005083 wl->vif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02005084 wl->flags = 0;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02005085 wl->sg_enabled = true;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03005086 wl->hw_pg_ver = -1;
Arik Nemtsovb622d992011-02-23 00:22:31 +02005087 wl->ap_ps_map = 0;
5088 wl->ap_fw_ps_map = 0;
Ido Yariv606ea9f2011-03-01 15:14:39 +02005089 wl->quirks = 0;
Ido Yariv341b7cd2011-03-31 10:07:01 +02005090 wl->platform_quirks = 0;
Luciano Coelho33c2c062011-05-10 14:46:02 +03005091 wl->sched_scanning = false;
Guy Eilame9eb8cb2011-08-16 19:49:12 +03005092 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005093 wl->system_hlid = WL12XX_SYSTEM_HLID;
Arik Nemtsovda032092011-08-25 12:43:15 +03005094 wl->active_sta_count = 0;
Ido Yariv95dac04f2011-06-06 14:57:06 +03005095 wl->fwlog_size = 0;
5096 init_waitqueue_head(&wl->fwlog_waitq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005097
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005098 /* The system link is always allocated */
5099 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5100
Ido Yariv25eeb9e2010-10-12 16:20:06 +02005101 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +03005102 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005103 wl->tx_frames[i] = NULL;
5104
5105 spin_lock_init(&wl->wl_lock);
5106
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005107 wl->state = WL1271_STATE_OFF;
5108 mutex_init(&wl->mutex);
5109
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005110 /* Apply default driver configuration. */
5111 wl1271_conf_init(wl);
5112
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005113 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5114 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5115 if (!wl->aggr_buf) {
5116 ret = -ENOMEM;
Eliad Peller92ef8962011-06-07 12:50:46 +03005117 goto err_wq;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005118 }
5119
Ido Yariv990f5de2011-03-31 10:06:59 +02005120 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5121 if (!wl->dummy_packet) {
5122 ret = -ENOMEM;
5123 goto err_aggr;
5124 }
5125
Ido Yariv95dac04f2011-06-06 14:57:06 +03005126 /* Allocate one page for the FW log */
5127 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5128 if (!wl->fwlog) {
5129 ret = -ENOMEM;
5130 goto err_dummy_packet;
5131 }
5132
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005133 return hw;
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005134
Ido Yariv990f5de2011-03-31 10:06:59 +02005135err_dummy_packet:
5136 dev_kfree_skb(wl->dummy_packet);
5137
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005138err_aggr:
5139 free_pages((unsigned long)wl->aggr_buf, order);
5140
Eliad Peller92ef8962011-06-07 12:50:46 +03005141err_wq:
5142 destroy_workqueue(wl->freezable_wq);
5143
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005144err_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005145 wl1271_debugfs_exit(wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005146 ieee80211_free_hw(hw);
5147
5148err_hw_alloc:
5149
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005150 return ERR_PTR(ret);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005151}
5152
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005153static int wl1271_free_hw(struct wl1271 *wl)
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005154{
Ido Yariv95dac04f2011-06-06 14:57:06 +03005155 /* Unblock any fwlog readers */
5156 mutex_lock(&wl->mutex);
5157 wl->fwlog_size = -1;
5158 wake_up_interruptible_all(&wl->fwlog_waitq);
5159 mutex_unlock(&wl->mutex);
5160
Felipe Balbif79f8902011-10-06 13:05:25 +03005161 device_remove_bin_file(wl->dev, &fwlog_attr);
Gery Kahn6f07b722011-07-18 14:21:49 +03005162
Felipe Balbif79f8902011-10-06 13:05:25 +03005163 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
Gery Kahn6f07b722011-07-18 14:21:49 +03005164
Felipe Balbif79f8902011-10-06 13:05:25 +03005165 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
Ido Yariv95dac04f2011-06-06 14:57:06 +03005166 free_page((unsigned long)wl->fwlog);
Ido Yariv990f5de2011-03-31 10:06:59 +02005167 dev_kfree_skb(wl->dummy_packet);
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005168 free_pages((unsigned long)wl->aggr_buf,
5169 get_order(WL1271_AGGR_BUFFER_SIZE));
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005170
5171 wl1271_debugfs_exit(wl);
5172
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005173 vfree(wl->fw);
5174 wl->fw = NULL;
5175 kfree(wl->nvs);
5176 wl->nvs = NULL;
5177
5178 kfree(wl->fw_status);
5179 kfree(wl->tx_res_if);
Eliad Peller92ef8962011-06-07 12:50:46 +03005180 destroy_workqueue(wl->freezable_wq);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005181
5182 ieee80211_free_hw(wl->hw);
5183
5184 return 0;
5185}
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005186
Felipe Balbia390e852011-10-06 10:07:44 +03005187static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5188{
5189 struct wl1271 *wl = cookie;
5190 unsigned long flags;
5191
5192 wl1271_debug(DEBUG_IRQ, "IRQ");
5193
5194 /* complete the ELP completion */
5195 spin_lock_irqsave(&wl->wl_lock, flags);
5196 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5197 if (wl->elp_compl) {
5198 complete(wl->elp_compl);
5199 wl->elp_compl = NULL;
5200 }
5201
5202 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5203 /* don't enqueue a work right now. mark it as pending */
5204 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5205 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5206 disable_irq_nosync(wl->irq);
5207 pm_wakeup_event(wl->dev, 0);
5208 spin_unlock_irqrestore(&wl->wl_lock, flags);
5209 return IRQ_HANDLED;
5210 }
5211 spin_unlock_irqrestore(&wl->wl_lock, flags);
5212
5213 return IRQ_WAKE_THREAD;
5214}
5215
Felipe Balbice2a2172011-10-05 14:12:55 +03005216static int __devinit wl12xx_probe(struct platform_device *pdev)
5217{
Felipe Balbia390e852011-10-06 10:07:44 +03005218 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5219 struct ieee80211_hw *hw;
5220 struct wl1271 *wl;
5221 unsigned long irqflags;
5222 int ret = -ENODEV;
5223
5224 hw = wl1271_alloc_hw();
5225 if (IS_ERR(hw)) {
5226 wl1271_error("can't allocate hw");
5227 ret = PTR_ERR(hw);
5228 goto out;
5229 }
5230
5231 wl = hw->priv;
5232 wl->irq = platform_get_irq(pdev, 0);
5233 wl->ref_clock = pdata->board_ref_clock;
5234 wl->tcxo_clock = pdata->board_tcxo_clock;
5235 wl->platform_quirks = pdata->platform_quirks;
5236 wl->set_power = pdata->set_power;
5237 wl->dev = &pdev->dev;
5238 wl->if_ops = pdata->ops;
5239
5240 platform_set_drvdata(pdev, wl);
5241
5242 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5243 irqflags = IRQF_TRIGGER_RISING;
5244 else
5245 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5246
5247 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5248 irqflags,
5249 pdev->name, wl);
5250 if (ret < 0) {
5251 wl1271_error("request_irq() failed: %d", ret);
5252 goto out_free_hw;
5253 }
5254
5255 ret = enable_irq_wake(wl->irq);
5256 if (!ret) {
5257 wl->irq_wake_enabled = true;
5258 device_init_wakeup(wl->dev, 1);
5259 if (pdata->pwr_in_suspend)
5260 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5261
5262 }
5263 disable_irq(wl->irq);
5264
5265 ret = wl1271_init_ieee80211(wl);
5266 if (ret)
5267 goto out_irq;
5268
5269 ret = wl1271_register_hw(wl);
5270 if (ret)
5271 goto out_irq;
5272
Felipe Balbif79f8902011-10-06 13:05:25 +03005273 /* Create sysfs file to control bt coex state */
5274 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5275 if (ret < 0) {
5276 wl1271_error("failed to create sysfs file bt_coex_state");
5277 goto out_irq;
5278 }
5279
5280 /* Create sysfs file to get HW PG version */
5281 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5282 if (ret < 0) {
5283 wl1271_error("failed to create sysfs file hw_pg_ver");
5284 goto out_bt_coex_state;
5285 }
5286
5287 /* Create sysfs file for the FW log */
5288 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5289 if (ret < 0) {
5290 wl1271_error("failed to create sysfs file fwlog");
5291 goto out_hw_pg_ver;
5292 }
5293
Felipe Balbice2a2172011-10-05 14:12:55 +03005294 return 0;
Felipe Balbia390e852011-10-06 10:07:44 +03005295
Felipe Balbif79f8902011-10-06 13:05:25 +03005296out_hw_pg_ver:
5297 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5298
5299out_bt_coex_state:
5300 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5301
Felipe Balbia390e852011-10-06 10:07:44 +03005302out_irq:
5303 free_irq(wl->irq, wl);
5304
5305out_free_hw:
5306 wl1271_free_hw(wl);
5307
5308out:
5309 return ret;
Felipe Balbice2a2172011-10-05 14:12:55 +03005310}
5311
5312static int __devexit wl12xx_remove(struct platform_device *pdev)
5313{
Felipe Balbia390e852011-10-06 10:07:44 +03005314 struct wl1271 *wl = platform_get_drvdata(pdev);
5315
5316 if (wl->irq_wake_enabled) {
5317 device_init_wakeup(wl->dev, 0);
5318 disable_irq_wake(wl->irq);
5319 }
5320 wl1271_unregister_hw(wl);
5321 free_irq(wl->irq, wl);
5322 wl1271_free_hw(wl);
5323
Felipe Balbice2a2172011-10-05 14:12:55 +03005324 return 0;
5325}
5326
5327static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005328 { "wl12xx", 0 },
Felipe Balbice2a2172011-10-05 14:12:55 +03005329 { } /* Terminating Entry */
5330};
5331MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5332
5333static struct platform_driver wl12xx_driver = {
5334 .probe = wl12xx_probe,
5335 .remove = __devexit_p(wl12xx_remove),
5336 .id_table = wl12xx_id_table,
5337 .driver = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005338 .name = "wl12xx_driver",
Felipe Balbice2a2172011-10-05 14:12:55 +03005339 .owner = THIS_MODULE,
5340 }
5341};
5342
5343static int __init wl12xx_init(void)
5344{
5345 return platform_driver_register(&wl12xx_driver);
5346}
5347module_init(wl12xx_init);
5348
5349static void __exit wl12xx_exit(void)
5350{
5351 platform_driver_unregister(&wl12xx_driver);
5352}
5353module_exit(wl12xx_exit);
5354
Guy Eilam491bbd62011-01-12 10:33:29 +01005355u32 wl12xx_debug_level = DEBUG_NONE;
Eliad Peller17c17552010-12-12 12:15:35 +02005356EXPORT_SYMBOL_GPL(wl12xx_debug_level);
Guy Eilam491bbd62011-01-12 10:33:29 +01005357module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
Eliad Peller17c17552010-12-12 12:15:35 +02005358MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5359
Ido Yariv95dac04f2011-06-06 14:57:06 +03005360module_param_named(fwlog, fwlog_param, charp, 0);
Luciano Coelho2c882fa2012-02-07 12:37:33 +02005361MODULE_PARM_DESC(fwlog,
Ido Yariv95dac04f2011-06-06 14:57:06 +03005362 "FW logger options: continuous, ondemand, dbgpins or disable");
5363
Eliad Peller2a5bff02011-08-25 18:10:59 +03005364module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5365MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5366
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005367MODULE_LICENSE("GPL");
Luciano Coelhob1a48ca2011-02-22 14:19:28 +02005368MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005369MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");