blob: b3b4c40197878d29b6d88c72ac872b24c352092e [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,
Eyal Shapiradae728f2012-02-02 12:03:39 +0200224 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
225 .suspend_listen_interval = 3,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300226 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
Shahar Levibc76b942011-05-11 11:14:22 +0300227 .bcn_filt_ie_count = 2,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300228 .bcn_filt_ie = {
229 [0] = {
230 .ie = WLAN_EID_CHANNEL_SWITCH,
231 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
Shahar Levibc76b942011-05-11 11:14:22 +0300232 },
233 [1] = {
234 .ie = WLAN_EID_HT_INFORMATION,
235 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
236 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300237 },
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200238 .synch_fail_thold = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300239 .bss_lose_timeout = 100,
240 .beacon_rx_timeout = 10000,
241 .broadcast_timeout = 20000,
242 .rx_broadcast_in_ps = 1,
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300243 .ps_poll_threshold = 10,
Juuso Oikarinen11f70f92009-10-13 12:47:46 +0300244 .bet_enable = CONF_BET_MODE_ENABLE,
Ohad Ben-Cohen958b20e2011-03-14 18:53:10 +0200245 .bet_max_consecutive = 50,
Eliad Pellera879ed72011-08-23 16:37:02 +0300246 .psm_entry_retries = 8,
Shahar Levi23708412011-04-13 14:52:50 +0300247 .psm_exit_retries = 16,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200248 .psm_entry_nullfunc_retries = 3,
Eyal Shapiraf1d63a52012-01-31 11:57:21 +0200249 .dynamic_ps_timeout = 100,
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +0200250 .forced_ps = false,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300251 .keep_alive_interval = 55000,
252 .max_listen_interval = 20,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300253 },
Luciano Coelho6e92b412009-12-11 15:40:50 +0200254 .itrim = {
255 .enable = false,
256 .timeout = 50000,
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200257 },
258 .pm_config = {
259 .host_clk_settling_time = 5000,
260 .host_fast_wakeup_support = false
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300261 },
262 .roam_trigger = {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300263 .trigger_pacing = 1,
264 .avg_weight_rssi_beacon = 20,
265 .avg_weight_rssi_data = 10,
266 .avg_weight_snr_beacon = 20,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100267 .avg_weight_snr_data = 10,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200268 },
269 .scan = {
270 .min_dwell_time_active = 7500,
271 .max_dwell_time_active = 30000,
Juuso Oikarinenea45b2c2011-01-24 07:01:54 +0100272 .min_dwell_time_passive = 100000,
273 .max_dwell_time_passive = 100000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200274 .num_probe_reqs = 2,
Eyal Shapirad647f2d2012-02-02 13:54:28 +0200275 .split_scan_timeout = 50000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200276 },
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300277 .sched_scan = {
278 /* sched_scan requires dwell times in TU instead of TU/1000 */
Luciano Coelho221737d2011-09-02 14:28:22 +0300279 .min_dwell_time_active = 30,
280 .max_dwell_time_active = 60,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300281 .dwell_time_passive = 100,
Luciano Coelho50a66d72011-05-27 15:34:47 +0300282 .dwell_time_dfs = 150,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300283 .num_probe_reqs = 2,
284 .rssi_threshold = -90,
285 .snr_threshold = 0,
286 },
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200287 .rf = {
288 .tx_per_channel_power_compensation_2 = {
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 },
291 .tx_per_channel_power_compensation_5 = {
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 },
296 },
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100297 .ht = {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300298 .rx_ba_win_size = 8,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100299 .tx_ba_win_size = 64,
300 .inactivity_timeout = 10000,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300301 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100302 },
Shahar Levi13b107d2011-03-06 16:32:12 +0200303 .mem_wl127x = {
Eliad Pellerfe5ef092011-02-02 09:59:36 +0200304 .num_stations = 1,
305 .ssid_profiles = 1,
306 .rx_block_num = 70,
307 .tx_min_block_num = 40,
Ido Yariv4cf557f2011-04-18 16:45:10 +0300308 .dynamic_memory = 1,
Ido Yarivb16d4b62011-03-01 15:14:44 +0200309 .min_req_tx_blocks = 100,
Eliad Pellerc8bde242011-02-02 09:59:35 +0200310 .min_req_rx_blocks = 22,
311 .tx_min = 27,
Shahar Levi13b107d2011-03-06 16:32:12 +0200312 },
313 .mem_wl128x = {
314 .num_stations = 1,
315 .ssid_profiles = 1,
316 .rx_block_num = 40,
317 .tx_min_block_num = 40,
318 .dynamic_memory = 1,
319 .min_req_tx_blocks = 45,
320 .min_req_rx_blocks = 22,
321 .tx_min = 27,
322 },
Shahar Leviff868432011-04-11 15:41:46 +0300323 .fm_coex = {
324 .enable = true,
325 .swallow_period = 5,
326 .n_divider_fref_set_1 = 0xff, /* default */
327 .n_divider_fref_set_2 = 12,
328 .m_divider_fref_set_1 = 148,
329 .m_divider_fref_set_2 = 0xffff, /* default */
330 .coex_pll_stabilization_time = 0xffffffff, /* default */
331 .ldo_stabilization_time = 0xffff, /* default */
332 .fm_disturbed_band_margin = 0xff, /* default */
333 .swallow_clk_diff = 0xff, /* default */
334 },
Eliad Pellerf84673d2011-05-15 11:10:28 +0300335 .rx_streaming = {
336 .duration = 150,
337 .queues = 0x1,
338 .interval = 20,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300339 .always = 0,
Eliad Pellerf84673d2011-05-15 11:10:28 +0300340 },
Ido Yariv95dac04f2011-06-06 14:57:06 +0300341 .fwlog = {
342 .mode = WL12XX_FWLOG_ON_DEMAND,
343 .mem_blocks = 2,
344 .severity = 0,
345 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
346 .output = WL12XX_FWLOG_OUTPUT_HOST,
347 .threshold = 0,
348 },
Luciano Coelhoafb7d3c2011-04-01 20:48:02 +0300349 .hci_io_ds = HCI_IO_DS_6MA,
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300350 .rate = {
351 .rate_retry_score = 32000,
352 .per_add = 8192,
353 .per_th1 = 2048,
354 .per_th2 = 4096,
355 .max_per = 8100,
356 .inverse_curiosity_factor = 5,
357 .tx_fail_low_th = 4,
358 .tx_fail_high_th = 10,
359 .per_alpha_shift = 4,
360 .per_add_shift = 13,
361 .per_beta1_shift = 10,
362 .per_beta2_shift = 8,
363 .rate_check_up = 2,
364 .rate_check_down = 12,
365 .rate_retry_policy = {
366 0x00, 0x00, 0x00, 0x00, 0x00,
367 0x00, 0x00, 0x00, 0x00, 0x00,
368 0x00, 0x00, 0x00,
369 },
370 },
Eliad Peller94877752011-08-28 15:11:56 +0300371 .hangover = {
372 .recover_time = 0,
373 .hangover_period = 20,
374 .dynamic_mode = 1,
375 .early_termination_mode = 1,
376 .max_period = 20,
377 .min_period = 1,
378 .increase_delta = 1,
379 .decrease_delta = 2,
380 .quiet_time = 4,
381 .increase_time = 1,
382 .window_size = 16,
383 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300384};
385
Ido Yariv95dac04f2011-06-06 14:57:06 +0300386static char *fwlog_param;
Eliad Peller2a5bff02011-08-25 18:10:59 +0300387static bool bug_on_recovery;
Ido Yariv95dac04f2011-06-06 14:57:06 +0300388
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300389static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +0200390 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300391 bool reset_tx_queues);
Eliad Pellerf0277432011-10-10 10:13:14 +0200392static void wl1271_op_stop(struct ieee80211_hw *hw);
Eliad Peller170d0e62011-10-05 11:56:06 +0200393static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200394
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200395static DEFINE_MUTEX(wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +0300396static LIST_HEAD(wl_list);
397
Eliad Pellerba8447f2011-10-10 10:13:00 +0200398static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
399 unsigned char operstate)
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300400{
401 int ret;
Eliad Peller0603d892011-10-05 11:55:51 +0200402
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300403 if (operstate != IF_OPER_UP)
404 return 0;
405
Eliad Peller8181aec2011-10-10 10:13:04 +0200406 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300407 return 0;
408
Eliad Peller154da672011-10-05 11:55:53 +0200409 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300410 if (ret < 0)
411 return ret;
412
Eliad Peller0603d892011-10-05 11:55:51 +0200413 wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +0300414
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300415 wl1271_info("Association completed.");
416 return 0;
417}
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300418static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
419 void *arg)
420{
421 struct net_device *dev = arg;
422 struct wireless_dev *wdev;
423 struct wiphy *wiphy;
424 struct ieee80211_hw *hw;
425 struct wl1271 *wl;
426 struct wl1271 *wl_temp;
Eliad Pellerba8447f2011-10-10 10:13:00 +0200427 struct wl12xx_vif *wlvif;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300428 int ret = 0;
429
430 /* Check that this notification is for us. */
431 if (what != NETDEV_CHANGE)
432 return NOTIFY_DONE;
433
434 wdev = dev->ieee80211_ptr;
435 if (wdev == NULL)
436 return NOTIFY_DONE;
437
438 wiphy = wdev->wiphy;
439 if (wiphy == NULL)
440 return NOTIFY_DONE;
441
442 hw = wiphy_priv(wiphy);
443 if (hw == NULL)
444 return NOTIFY_DONE;
445
446 wl_temp = hw->priv;
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200447 mutex_lock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300448 list_for_each_entry(wl, &wl_list, list) {
449 if (wl == wl_temp)
450 break;
451 }
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200452 mutex_unlock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300453 if (wl != wl_temp)
454 return NOTIFY_DONE;
455
456 mutex_lock(&wl->mutex);
457
458 if (wl->state == WL1271_STATE_OFF)
459 goto out;
460
Eliad Peller6ab70912011-12-18 20:25:45 +0200461 if (dev->operstate != IF_OPER_UP)
462 goto out;
463 /*
464 * The correct behavior should be just getting the appropriate wlvif
465 * from the given dev, but currently we don't have a mac80211
466 * interface for it.
467 */
Eliad Pellerba8447f2011-10-10 10:13:00 +0200468 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller6ab70912011-12-18 20:25:45 +0200469 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
470
Eliad Pellerba8447f2011-10-10 10:13:00 +0200471 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
472 continue;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300473
Eliad Pellerba8447f2011-10-10 10:13:00 +0200474 ret = wl1271_ps_elp_wakeup(wl);
475 if (ret < 0)
476 goto out;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300477
Eliad Peller6ab70912011-12-18 20:25:45 +0200478 wl1271_check_operstate(wl, wlvif,
479 ieee80211_get_operstate(vif));
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300480
Eliad Pellerba8447f2011-10-10 10:13:00 +0200481 wl1271_ps_elp_sleep(wl);
482 }
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300483out:
484 mutex_unlock(&wl->mutex);
485
486 return NOTIFY_OK;
487}
488
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100489static int wl1271_reg_notify(struct wiphy *wiphy,
Luciano Coelho573c67c2010-11-26 13:44:59 +0200490 struct regulatory_request *request)
491{
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100492 struct ieee80211_supported_band *band;
493 struct ieee80211_channel *ch;
494 int i;
495
496 band = wiphy->bands[IEEE80211_BAND_5GHZ];
497 for (i = 0; i < band->n_channels; i++) {
498 ch = &band->channels[i];
499 if (ch->flags & IEEE80211_CHAN_DISABLED)
500 continue;
501
502 if (ch->flags & IEEE80211_CHAN_RADAR)
503 ch->flags |= IEEE80211_CHAN_NO_IBSS |
504 IEEE80211_CHAN_PASSIVE_SCAN;
505
506 }
507
508 return 0;
509}
510
Eliad Peller9eb599e2011-10-10 10:12:59 +0200511static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
512 bool enable)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300513{
514 int ret = 0;
515
516 /* we should hold wl->mutex */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200517 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300518 if (ret < 0)
519 goto out;
520
521 if (enable)
Eliad Peller0744bdb2011-10-10 10:13:05 +0200522 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300523 else
Eliad Peller0744bdb2011-10-10 10:13:05 +0200524 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300525out:
526 return ret;
527}
528
529/*
530 * this function is being called when the rx_streaming interval
531 * has beed changed or rx_streaming should be disabled
532 */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200533int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300534{
535 int ret = 0;
536 int period = wl->conf.rx_streaming.interval;
537
538 /* don't reconfigure if rx_streaming is disabled */
Eliad Peller0744bdb2011-10-10 10:13:05 +0200539 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300540 goto out;
541
542 /* reconfigure/disable according to new streaming_period */
543 if (period &&
Eliad Pellerba8447f2011-10-10 10:13:00 +0200544 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eliad Peller77ddaa12011-05-15 11:10:29 +0300545 (wl->conf.rx_streaming.always ||
546 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
Eliad Peller9eb599e2011-10-10 10:12:59 +0200547 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300548 else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200549 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300550 /* don't cancel_work_sync since we might deadlock */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200551 del_timer_sync(&wlvif->rx_streaming_timer);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300552 }
553out:
554 return ret;
555}
556
557static void wl1271_rx_streaming_enable_work(struct work_struct *work)
558{
559 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200560 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
561 rx_streaming_enable_work);
562 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300563
564 mutex_lock(&wl->mutex);
565
Eliad Peller0744bdb2011-10-10 10:13:05 +0200566 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
Eliad Pellerba8447f2011-10-10 10:13:00 +0200567 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller77ddaa12011-05-15 11:10:29 +0300568 (!wl->conf.rx_streaming.always &&
569 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
570 goto out;
571
572 if (!wl->conf.rx_streaming.interval)
573 goto out;
574
575 ret = wl1271_ps_elp_wakeup(wl);
576 if (ret < 0)
577 goto out;
578
Eliad Peller9eb599e2011-10-10 10:12:59 +0200579 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300580 if (ret < 0)
581 goto out_sleep;
582
583 /* stop it after some time of inactivity */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200584 mod_timer(&wlvif->rx_streaming_timer,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300585 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
586
587out_sleep:
588 wl1271_ps_elp_sleep(wl);
589out:
590 mutex_unlock(&wl->mutex);
591}
592
593static void wl1271_rx_streaming_disable_work(struct work_struct *work)
594{
595 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200596 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
597 rx_streaming_disable_work);
598 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300599
600 mutex_lock(&wl->mutex);
601
Eliad Peller0744bdb2011-10-10 10:13:05 +0200602 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300603 goto out;
604
605 ret = wl1271_ps_elp_wakeup(wl);
606 if (ret < 0)
607 goto out;
608
Eliad Peller9eb599e2011-10-10 10:12:59 +0200609 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300610 if (ret)
611 goto out_sleep;
612
613out_sleep:
614 wl1271_ps_elp_sleep(wl);
615out:
616 mutex_unlock(&wl->mutex);
617}
618
619static void wl1271_rx_streaming_timer(unsigned long data)
620{
Eliad Peller9eb599e2011-10-10 10:12:59 +0200621 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
622 struct wl1271 *wl = wlvif->wl;
623 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300624}
625
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300626static void wl1271_conf_init(struct wl1271 *wl)
627{
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300628
629 /*
630 * This function applies the default configuration to the driver. This
631 * function is invoked upon driver load (spi probe.)
632 *
633 * The configuration is stored in a run-time structure in order to
634 * facilitate for run-time adjustment of any of the parameters. Making
635 * changes to the configuration structure will apply the new values on
636 * the next interface up (wl1271_op_start.)
637 */
638
639 /* apply driver default configuration */
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300640 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300641
Ido Yariv95dac04f2011-06-06 14:57:06 +0300642 /* Adjust settings according to optional module parameters */
643 if (fwlog_param) {
644 if (!strcmp(fwlog_param, "continuous")) {
645 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
646 } else if (!strcmp(fwlog_param, "ondemand")) {
647 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
648 } else if (!strcmp(fwlog_param, "dbgpins")) {
649 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
650 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
651 } else if (!strcmp(fwlog_param, "disable")) {
652 wl->conf.fwlog.mem_blocks = 0;
653 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
654 } else {
655 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
656 }
657 }
658}
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300659
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300660static int wl1271_plt_init(struct wl1271 *wl)
661{
Eliad Peller188e7f52011-12-06 12:15:06 +0200662 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300663
Shahar Levi49d750ca2011-03-06 16:32:09 +0200664 if (wl->chip.id == CHIP_ID_1283_PG20)
665 ret = wl128x_cmd_general_parms(wl);
666 else
667 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200668 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200669 return ret;
670
Shahar Levi49d750ca2011-03-06 16:32:09 +0200671 if (wl->chip.id == CHIP_ID_1283_PG20)
672 ret = wl128x_cmd_radio_parms(wl);
673 else
674 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200675 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200676 return ret;
677
Shahar Levi49d750ca2011-03-06 16:32:09 +0200678 if (wl->chip.id != CHIP_ID_1283_PG20) {
679 ret = wl1271_cmd_ext_radio_parms(wl);
680 if (ret < 0)
681 return ret;
682 }
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200683 if (ret < 0)
684 return ret;
685
Shahar Levi48a61472011-03-06 16:32:08 +0200686 /* Chip-specific initializations */
687 ret = wl1271_chip_specific_init(wl);
688 if (ret < 0)
689 return ret;
690
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691 ret = wl1271_acx_init_mem_config(wl);
692 if (ret < 0)
693 return ret;
694
Eliad Peller7f0979882011-08-14 13:17:06 +0300695 ret = wl12xx_acx_mem_cfg(wl);
Gery Kahn1ec610e2011-02-01 03:03:08 -0600696 if (ret < 0)
697 goto out_free_memmap;
698
Luciano Coelho12419cc2010-02-18 13:25:44 +0200699 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200700 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300701 if (ret < 0)
Luciano Coelho12419cc2010-02-18 13:25:44 +0200702 goto out_free_memmap;
703
704 /* Configure for CAM power saving (ie. always active) */
705 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
706 if (ret < 0)
707 goto out_free_memmap;
708
709 /* configure PM */
710 ret = wl1271_acx_pm_config(wl);
711 if (ret < 0)
712 goto out_free_memmap;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300713
714 return 0;
Luciano Coelho12419cc2010-02-18 13:25:44 +0200715
716 out_free_memmap:
717 kfree(wl->target_mem_map);
718 wl->target_mem_map = NULL;
719
720 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300721}
722
Eliad Peller6e8cd332011-10-10 10:13:13 +0200723static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
724 struct wl12xx_vif *wlvif,
725 u8 hlid, u8 tx_pkts)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200726{
Arik Nemtsovda032092011-08-25 12:43:15 +0300727 bool fw_ps, single_sta;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200728
Arik Nemtsovb622d992011-02-23 00:22:31 +0200729 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Arik Nemtsovda032092011-08-25 12:43:15 +0300730 single_sta = (wl->active_sta_count == 1);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200731
732 /*
733 * Wake up from high level PS if the STA is asleep with too little
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300734 * packets in FW or if the STA is awake.
Arik Nemtsovb622d992011-02-23 00:22:31 +0200735 */
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300736 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200737 wl12xx_ps_link_end(wl, wlvif, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200738
Arik Nemtsovda032092011-08-25 12:43:15 +0300739 /*
740 * Start high-level PS if the STA is asleep with enough blocks in FW.
741 * Make an exception if this is the only connected station. In this
742 * case FW-memory congestion is not a problem.
743 */
744 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200745 wl12xx_ps_link_start(wl, wlvif, hlid, true);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200746}
747
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300748static void wl12xx_irq_update_links_status(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200749 struct wl12xx_vif *wlvif,
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300750 struct wl12xx_fw_status *status)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200751{
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200752 struct wl1271_link *lnk;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200753 u32 cur_fw_ps_map;
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300754 u8 hlid, cnt;
755
756 /* TODO: also use link_fast_bitmap here */
Arik Nemtsovb622d992011-02-23 00:22:31 +0200757
758 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
759 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
760 wl1271_debug(DEBUG_PSM,
761 "link ps prev 0x%x cur 0x%x changed 0x%x",
762 wl->ap_fw_ps_map, cur_fw_ps_map,
763 wl->ap_fw_ps_map ^ cur_fw_ps_map);
764
765 wl->ap_fw_ps_map = cur_fw_ps_map;
766 }
767
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200768 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
769 lnk = &wl->links[hlid];
770 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200771
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200772 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
773 lnk->allocated_pkts -= cnt;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200774
Eliad Peller6e8cd332011-10-10 10:13:13 +0200775 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
776 lnk->allocated_pkts);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200777 }
778}
779
Eliad Peller4d56ad92011-08-14 13:17:05 +0300780static void wl12xx_fw_status(struct wl1271 *wl,
781 struct wl12xx_fw_status *status)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300782{
Eliad Peller6e8cd332011-10-10 10:13:13 +0200783 struct wl12xx_vif *wlvif;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200784 struct timespec ts;
Shahar Levi13b107d2011-03-06 16:32:12 +0200785 u32 old_tx_blk_count = wl->tx_blocks_available;
Eliad Peller4d56ad92011-08-14 13:17:05 +0300786 int avail, freed_blocks;
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300787 int i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300788
Eliad Peller4d56ad92011-08-14 13:17:05 +0300789 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
Shahar Levi13b107d2011-03-06 16:32:12 +0200790
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300791 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
792 "drv_rx_counter = %d, tx_results_counter = %d)",
793 status->intr,
794 status->fw_rx_counter,
795 status->drv_rx_counter,
796 status->tx_results_counter);
797
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300798 for (i = 0; i < NUM_TX_QUEUES; i++) {
799 /* prevent wrap-around in freed-packets counter */
Arik Nemtsov742246f2011-08-14 13:17:33 +0300800 wl->tx_allocated_pkts[i] -=
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300801 (status->tx_released_pkts[i] -
802 wl->tx_pkts_freed[i]) & 0xff;
803
804 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
805 }
806
Arik Nemtsovbdf91cf2011-08-14 13:17:34 +0300807 /* prevent wrap-around in total blocks counter */
808 if (likely(wl->tx_blocks_freed <=
809 le32_to_cpu(status->total_released_blks)))
810 freed_blocks = le32_to_cpu(status->total_released_blks) -
811 wl->tx_blocks_freed;
812 else
813 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
814 le32_to_cpu(status->total_released_blks);
815
Eliad Peller4d56ad92011-08-14 13:17:05 +0300816 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
Shahar Levi13b107d2011-03-06 16:32:12 +0200817
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300818 wl->tx_allocated_blocks -= freed_blocks;
819
Eliad Peller4d56ad92011-08-14 13:17:05 +0300820 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200821
Eliad Peller4d56ad92011-08-14 13:17:05 +0300822 /*
823 * The FW might change the total number of TX memblocks before
824 * we get a notification about blocks being released. Thus, the
825 * available blocks calculation might yield a temporary result
826 * which is lower than the actual available blocks. Keeping in
827 * mind that only blocks that were allocated can be moved from
828 * TX to RX, tx_blocks_available should never decrease here.
829 */
830 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
831 avail);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300832
Ido Yariva5225502010-10-12 14:49:10 +0200833 /* if more blocks are available now, tx work can be scheduled */
Shahar Levi13b107d2011-03-06 16:32:12 +0200834 if (wl->tx_blocks_available > old_tx_blk_count)
Ido Yariva5225502010-10-12 14:49:10 +0200835 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300836
Eliad Peller4d56ad92011-08-14 13:17:05 +0300837 /* for AP update num of allocated TX blocks per link and ps status */
Eliad Peller6e8cd332011-10-10 10:13:13 +0200838 wl12xx_for_each_wlvif_ap(wl, wlvif) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200839 wl12xx_irq_update_links_status(wl, wlvif, status);
Eliad Peller6e8cd332011-10-10 10:13:13 +0200840 }
Eliad Peller4d56ad92011-08-14 13:17:05 +0300841
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300842 /* update the host-chipset time offset */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200843 getnstimeofday(&ts);
844 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
845 (s64)le32_to_cpu(status->fw_localtime);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300846}
847
Ido Yariva6208652011-03-01 15:14:41 +0200848static void wl1271_flush_deferred_work(struct wl1271 *wl)
849{
850 struct sk_buff *skb;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200851
Ido Yariva6208652011-03-01 15:14:41 +0200852 /* Pass all received frames to the network stack */
853 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
854 ieee80211_rx_ni(wl->hw, skb);
855
856 /* Return sent skbs to the network stack */
857 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300858 ieee80211_tx_status_ni(wl->hw, skb);
Ido Yariva6208652011-03-01 15:14:41 +0200859}
860
861static void wl1271_netstack_work(struct work_struct *work)
862{
863 struct wl1271 *wl =
864 container_of(work, struct wl1271, netstack_work);
865
866 do {
867 wl1271_flush_deferred_work(wl);
868 } while (skb_queue_len(&wl->deferred_rx_queue));
869}
870
871#define WL1271_IRQ_MAX_LOOPS 256
872
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300873static irqreturn_t wl1271_irq(int irq, void *cookie)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300874{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300875 int ret;
Juuso Oikarinenc15f63b2009-10-12 15:08:50 +0300876 u32 intr;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200877 int loopcount = WL1271_IRQ_MAX_LOOPS;
Ido Yariva6208652011-03-01 15:14:41 +0200878 struct wl1271 *wl = (struct wl1271 *)cookie;
879 bool done = false;
880 unsigned int defer_count;
Ido Yarivb07d4032011-03-01 15:14:43 +0200881 unsigned long flags;
882
883 /* TX might be handled here, avoid redundant work */
884 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
885 cancel_work_sync(&wl->tx_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300886
Ido Yariv341b7cd2011-03-31 10:07:01 +0200887 /*
888 * In case edge triggered interrupt must be used, we cannot iterate
889 * more than once without introducing race conditions with the hardirq.
890 */
891 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
892 loopcount = 1;
893
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300894 mutex_lock(&wl->mutex);
895
896 wl1271_debug(DEBUG_IRQ, "IRQ work");
897
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200898 if (unlikely(wl->state == WL1271_STATE_OFF))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300899 goto out;
900
Ido Yariva6208652011-03-01 15:14:41 +0200901 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300902 if (ret < 0)
903 goto out;
904
Ido Yariva6208652011-03-01 15:14:41 +0200905 while (!done && loopcount--) {
906 /*
907 * In order to avoid a race with the hardirq, clear the flag
908 * before acknowledging the chip. Since the mutex is held,
909 * wl1271_ps_elp_wakeup cannot be called concurrently.
910 */
911 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
912 smp_mb__after_clear_bit();
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200913
Eliad Peller4d56ad92011-08-14 13:17:05 +0300914 wl12xx_fw_status(wl, wl->fw_status);
915 intr = le32_to_cpu(wl->fw_status->intr);
Ido Yariva6208652011-03-01 15:14:41 +0200916 intr &= WL1271_INTR_MASK;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200917 if (!intr) {
Ido Yariva6208652011-03-01 15:14:41 +0200918 done = true;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200919 continue;
920 }
921
Eliad Pellerccc83b02010-10-27 14:09:57 +0200922 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
923 wl1271_error("watchdog interrupt received! "
924 "starting recovery.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300925 wl12xx_queue_recovery_work(wl);
Eliad Pellerccc83b02010-10-27 14:09:57 +0200926
927 /* restarting the chip. ignore any other interrupt. */
928 goto out;
929 }
930
Ido Yariva6208652011-03-01 15:14:41 +0200931 if (likely(intr & WL1271_ACX_INTR_DATA)) {
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200932 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
933
Eliad Peller4d56ad92011-08-14 13:17:05 +0300934 wl12xx_rx(wl, wl->fw_status);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200935
Ido Yariva5225502010-10-12 14:49:10 +0200936 /* Check if any tx blocks were freed */
Ido Yarivb07d4032011-03-01 15:14:43 +0200937 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200938 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300939 wl1271_tx_total_queue_count(wl) > 0) {
Ido Yarivb07d4032011-03-01 15:14:43 +0200940 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200941 /*
942 * In order to avoid starvation of the TX path,
943 * call the work function directly.
944 */
Eliad Pellera32d0cd2011-10-10 10:12:55 +0200945 wl1271_tx_work_locked(wl);
Ido Yarivb07d4032011-03-01 15:14:43 +0200946 } else {
947 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200948 }
949
Ido Yariv8aad2462011-03-01 15:14:38 +0200950 /* check for tx results */
Eliad Peller4d56ad92011-08-14 13:17:05 +0300951 if (wl->fw_status->tx_results_counter !=
Ido Yariv8aad2462011-03-01 15:14:38 +0200952 (wl->tx_results_count & 0xff))
953 wl1271_tx_complete(wl);
Ido Yariva6208652011-03-01 15:14:41 +0200954
955 /* Make sure the deferred queues don't get too long */
956 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
957 skb_queue_len(&wl->deferred_rx_queue);
958 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
959 wl1271_flush_deferred_work(wl);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200960 }
961
962 if (intr & WL1271_ACX_INTR_EVENT_A) {
963 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
964 wl1271_event_handle(wl, 0);
965 }
966
967 if (intr & WL1271_ACX_INTR_EVENT_B) {
968 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
969 wl1271_event_handle(wl, 1);
970 }
971
972 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
973 wl1271_debug(DEBUG_IRQ,
974 "WL1271_ACX_INTR_INIT_COMPLETE");
975
976 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
977 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300978 }
979
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300980 wl1271_ps_elp_sleep(wl);
981
982out:
Ido Yarivb07d4032011-03-01 15:14:43 +0200983 spin_lock_irqsave(&wl->wl_lock, flags);
984 /* In case TX was not handled here, queue TX work */
985 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
986 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300987 wl1271_tx_total_queue_count(wl) > 0)
Ido Yarivb07d4032011-03-01 15:14:43 +0200988 ieee80211_queue_work(wl->hw, &wl->tx_work);
989 spin_unlock_irqrestore(&wl->wl_lock, flags);
990
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300991 mutex_unlock(&wl->mutex);
Ido Yariva6208652011-03-01 15:14:41 +0200992
993 return IRQ_HANDLED;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300994}
995
Eliad Peller4549d092012-02-06 13:07:52 +0200996struct vif_counter_data {
997 u8 counter;
998
999 struct ieee80211_vif *cur_vif;
1000 bool cur_vif_running;
1001};
1002
1003static void wl12xx_vif_count_iter(void *data, u8 *mac,
1004 struct ieee80211_vif *vif)
1005{
1006 struct vif_counter_data *counter = data;
1007
1008 counter->counter++;
1009 if (counter->cur_vif == vif)
1010 counter->cur_vif_running = true;
1011}
1012
1013/* caller must not hold wl->mutex, as it might deadlock */
1014static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
1015 struct ieee80211_vif *cur_vif,
1016 struct vif_counter_data *data)
1017{
1018 memset(data, 0, sizeof(*data));
1019 data->cur_vif = cur_vif;
1020
1021 ieee80211_iterate_active_interfaces(hw,
1022 wl12xx_vif_count_iter, data);
1023}
1024
Eliad Peller3fcdab72012-02-06 12:47:54 +02001025static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001026{
1027 const struct firmware *fw;
Arik Nemtsov166d5042010-10-16 21:44:57 +02001028 const char *fw_name;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001029 enum wl12xx_fw_type fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001030 int ret;
1031
Eliad Peller3fcdab72012-02-06 12:47:54 +02001032 if (plt) {
1033 fw_type = WL12XX_FW_TYPE_PLT;
1034 if (wl->chip.id == CHIP_ID_1283_PG20)
1035 fw_name = WL128X_PLT_FW_NAME;
1036 else
1037 fw_name = WL127X_PLT_FW_NAME;
1038 } else {
Eliad Peller4549d092012-02-06 13:07:52 +02001039 /*
1040 * we can't call wl12xx_get_vif_count() here because
1041 * wl->mutex is taken, so use the cached last_vif_count value
1042 */
1043 if (wl->last_vif_count > 1) {
1044 fw_type = WL12XX_FW_TYPE_MULTI;
1045 if (wl->chip.id == CHIP_ID_1283_PG20)
1046 fw_name = WL128X_FW_NAME_MULTI;
1047 else
1048 fw_name = WL127X_FW_NAME_MULTI;
1049 } else {
1050 fw_type = WL12XX_FW_TYPE_NORMAL;
1051 if (wl->chip.id == CHIP_ID_1283_PG20)
1052 fw_name = WL128X_FW_NAME_SINGLE;
1053 else
1054 fw_name = WL127X_FW_NAME_SINGLE;
1055 }
Eliad Peller3fcdab72012-02-06 12:47:54 +02001056 }
1057
1058 if (wl->fw_type == fw_type)
1059 return 0;
Arik Nemtsov166d5042010-10-16 21:44:57 +02001060
1061 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1062
Felipe Balbia390e852011-10-06 10:07:44 +03001063 ret = request_firmware(&fw, fw_name, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001064
1065 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001066 wl1271_error("could not get firmware %s: %d", fw_name, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001067 return ret;
1068 }
1069
1070 if (fw->size % 4) {
1071 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1072 fw->size);
1073 ret = -EILSEQ;
1074 goto out;
1075 }
1076
Arik Nemtsov166d5042010-10-16 21:44:57 +02001077 vfree(wl->fw);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001078 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001079 wl->fw_len = fw->size;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +03001080 wl->fw = vmalloc(wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001081
1082 if (!wl->fw) {
1083 wl1271_error("could not allocate memory for the firmware");
1084 ret = -ENOMEM;
1085 goto out;
1086 }
1087
1088 memcpy(wl->fw, fw->data, wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001089 ret = 0;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001090 wl->fw_type = fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001091out:
1092 release_firmware(fw);
1093
1094 return ret;
1095}
1096
1097static int wl1271_fetch_nvs(struct wl1271 *wl)
1098{
1099 const struct firmware *fw;
1100 int ret;
1101
Felipe Balbia390e852011-10-06 10:07:44 +03001102 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001103
1104 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001105 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1106 ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001107 return ret;
1108 }
1109
Shahar Levibc765bf2011-03-06 16:32:10 +02001110 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001111
1112 if (!wl->nvs) {
1113 wl1271_error("could not allocate memory for the nvs file");
1114 ret = -ENOMEM;
1115 goto out;
1116 }
1117
Juuso Oikarinen02fabb02010-08-19 04:41:15 +02001118 wl->nvs_len = fw->size;
1119
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001120out:
1121 release_firmware(fw);
1122
1123 return ret;
1124}
1125
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001126void wl12xx_queue_recovery_work(struct wl1271 *wl)
1127{
1128 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1129 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1130}
1131
Ido Yariv95dac04f2011-06-06 14:57:06 +03001132size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1133{
1134 size_t len = 0;
1135
1136 /* The FW log is a length-value list, find where the log end */
1137 while (len < maxlen) {
1138 if (memblock[len] == 0)
1139 break;
1140 if (len + memblock[len] + 1 > maxlen)
1141 break;
1142 len += memblock[len] + 1;
1143 }
1144
1145 /* Make sure we have enough room */
1146 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1147
1148 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1149 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1150 wl->fwlog_size += len;
1151
1152 return len;
1153}
1154
1155static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1156{
1157 u32 addr;
1158 u32 first_addr;
1159 u8 *block;
1160
1161 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1162 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1163 (wl->conf.fwlog.mem_blocks == 0))
1164 return;
1165
1166 wl1271_info("Reading FW panic log");
1167
1168 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1169 if (!block)
1170 return;
1171
1172 /*
1173 * Make sure the chip is awake and the logger isn't active.
1174 * This might fail if the firmware hanged.
1175 */
1176 if (!wl1271_ps_elp_wakeup(wl))
1177 wl12xx_cmd_stop_fwlog(wl);
1178
1179 /* Read the first memory block address */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001180 wl12xx_fw_status(wl, wl->fw_status);
1181 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001182 if (!first_addr)
1183 goto out;
1184
1185 /* Traverse the memory blocks linked list */
1186 addr = first_addr;
1187 do {
1188 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1189 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1190 false);
1191
1192 /*
1193 * Memory blocks are linked to one another. The first 4 bytes
1194 * of each memory block hold the hardware address of the next
1195 * one. The last memory block points to the first one.
1196 */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001197 addr = le32_to_cpup((__le32 *)block);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001198 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1199 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1200 break;
1201 } while (addr && (addr != first_addr));
1202
1203 wake_up_interruptible(&wl->fwlog_waitq);
1204
1205out:
1206 kfree(block);
1207}
1208
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001209static void wl1271_recovery_work(struct work_struct *work)
1210{
1211 struct wl1271 *wl =
1212 container_of(work, struct wl1271, recovery_work);
Eliad Peller48e93e42011-10-10 10:12:58 +02001213 struct wl12xx_vif *wlvif;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001214 struct ieee80211_vif *vif;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001215
1216 mutex_lock(&wl->mutex);
1217
Eliad Peller3fcdab72012-02-06 12:47:54 +02001218 if (wl->state != WL1271_STATE_ON || wl->plt)
Eliad Pellerf0277432011-10-10 10:13:14 +02001219 goto out_unlock;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001220
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001221 /* Avoid a recursive recovery */
1222 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1223
Ido Yariv95dac04f2011-06-06 14:57:06 +03001224 wl12xx_read_fwlog_panic(wl);
1225
Arik Nemtsov52dcaf52011-04-18 14:15:24 +03001226 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1227 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001228
Eliad Peller2a5bff02011-08-25 18:10:59 +03001229 BUG_ON(bug_on_recovery);
1230
Oz Krakowskib992c682011-06-26 10:36:02 +03001231 /*
1232 * Advance security sequence number to overcome potential progress
1233 * in the firmware during recovery. This doens't hurt if the network is
1234 * not encrypted.
1235 */
Eliad Peller48e93e42011-10-10 10:12:58 +02001236 wl12xx_for_each_wlvif(wl, wlvif) {
Eliad Pellerba8447f2011-10-10 10:13:00 +02001237 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller53d40d02011-10-10 10:13:02 +02001238 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Peller48e93e42011-10-10 10:12:58 +02001239 wlvif->tx_security_seq +=
1240 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1241 }
Oz Krakowskib992c682011-06-26 10:36:02 +03001242
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001243 /* Prevent spurious TX during FW restart */
1244 ieee80211_stop_queues(wl->hw);
1245
Luciano Coelho33c2c062011-05-10 14:46:02 +03001246 if (wl->sched_scanning) {
1247 ieee80211_sched_scan_stopped(wl->hw);
1248 wl->sched_scanning = false;
1249 }
1250
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001251 /* reboot the chipset */
Eliad Peller6e8cd332011-10-10 10:13:13 +02001252 while (!list_empty(&wl->wlvif_list)) {
1253 wlvif = list_first_entry(&wl->wlvif_list,
1254 struct wl12xx_vif, list);
1255 vif = wl12xx_wlvif_to_vif(wlvif);
1256 __wl1271_op_remove_interface(wl, vif, false);
1257 }
Eliad Pellerf0277432011-10-10 10:13:14 +02001258 mutex_unlock(&wl->mutex);
1259 wl1271_op_stop(wl->hw);
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001260
1261 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1262
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001263 ieee80211_restart_hw(wl->hw);
1264
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001265 /*
1266 * Its safe to enable TX now - the queues are stopped after a request
1267 * to restart the HW.
1268 */
1269 ieee80211_wake_queues(wl->hw);
Eliad Pellerf0277432011-10-10 10:13:14 +02001270 return;
1271out_unlock:
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001272 mutex_unlock(&wl->mutex);
1273}
1274
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001275static void wl1271_fw_wakeup(struct wl1271 *wl)
1276{
1277 u32 elp_reg;
1278
1279 elp_reg = ELPCTRL_WAKE_UP;
Juuso Oikarinen74621412009-10-12 15:08:54 +03001280 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001281}
1282
1283static int wl1271_setup(struct wl1271 *wl)
1284{
1285 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1286 if (!wl->fw_status)
1287 return -ENOMEM;
1288
1289 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1290 if (!wl->tx_res_if) {
1291 kfree(wl->fw_status);
1292 return -ENOMEM;
1293 }
1294
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001295 return 0;
1296}
1297
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001298static int wl12xx_set_power_on(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001299{
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001300 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001301
Juuso Oikarinen01ac17e2009-12-11 15:41:02 +02001302 msleep(WL1271_PRE_POWER_ON_SLEEP);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +02001303 ret = wl1271_power_on(wl);
1304 if (ret < 0)
1305 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001306 msleep(WL1271_POWER_ON_SLEEP);
Teemu Paasikivi9b280722010-02-18 13:25:56 +02001307 wl1271_io_reset(wl);
1308 wl1271_io_init(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001309
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001310 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001311
1312 /* ELP module wake up */
1313 wl1271_fw_wakeup(wl);
1314
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001315out:
1316 return ret;
1317}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001318
Eliad Peller3fcdab72012-02-06 12:47:54 +02001319static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001320{
1321 int ret = 0;
1322
1323 ret = wl12xx_set_power_on(wl);
1324 if (ret < 0)
1325 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001326
Luciano Coelhoe62c9ce2011-11-03 08:44:42 +02001327 /*
1328 * For wl127x based devices we could use the default block
1329 * size (512 bytes), but due to a bug in the sdio driver, we
1330 * need to set it explicitly after the chip is powered on. To
1331 * simplify the code and since the performance impact is
1332 * negligible, we use the same block size for all different
1333 * chip types.
1334 */
1335 if (!wl1271_set_block_size(wl))
1336 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001337
1338 switch (wl->chip.id) {
1339 case CHIP_ID_1271_PG10:
1340 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1341 wl->chip.id);
1342
1343 ret = wl1271_setup(wl);
1344 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001345 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001346 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001347 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001348
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001349 case CHIP_ID_1271_PG20:
1350 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1351 wl->chip.id);
1352
1353 ret = wl1271_setup(wl);
1354 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001355 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001356 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001357 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001358
Shahar Levi0830cee2011-03-06 16:32:20 +02001359 case CHIP_ID_1283_PG20:
1360 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1361 wl->chip.id);
1362
1363 ret = wl1271_setup(wl);
1364 if (ret < 0)
1365 goto out;
1366 break;
1367 case CHIP_ID_1283_PG10:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001368 default:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001369 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001370 ret = -ENODEV;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001371 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001372 }
1373
Eliad Peller3fcdab72012-02-06 12:47:54 +02001374 ret = wl12xx_fetch_firmware(wl, plt);
1375 if (ret < 0)
1376 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001377
1378 /* No NVS from netlink, try to get it from the filesystem */
1379 if (wl->nvs == NULL) {
1380 ret = wl1271_fetch_nvs(wl);
1381 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001382 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001383 }
1384
1385out:
1386 return ret;
1387}
1388
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001389int wl1271_plt_start(struct wl1271 *wl)
1390{
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001391 int retries = WL1271_BOOT_RETRIES;
Gery Kahn6f07b722011-07-18 14:21:49 +03001392 struct wiphy *wiphy = wl->hw->wiphy;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001393 int ret;
1394
1395 mutex_lock(&wl->mutex);
1396
1397 wl1271_notice("power up");
1398
1399 if (wl->state != WL1271_STATE_OFF) {
1400 wl1271_error("cannot go into PLT state because not "
1401 "in off state: %d", wl->state);
1402 ret = -EBUSY;
1403 goto out;
1404 }
1405
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001406 while (retries) {
1407 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001408 ret = wl12xx_chip_wakeup(wl, true);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001409 if (ret < 0)
1410 goto power_off;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001411
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001412 ret = wl1271_boot(wl);
1413 if (ret < 0)
1414 goto power_off;
1415
1416 ret = wl1271_plt_init(wl);
1417 if (ret < 0)
1418 goto irq_disable;
1419
Eliad Peller3fcdab72012-02-06 12:47:54 +02001420 wl->plt = true;
1421 wl->state = WL1271_STATE_ON;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001422 wl1271_notice("firmware booted in PLT mode (%s)",
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001423 wl->chip.fw_ver_str);
Luciano Coelhoe7ddf542011-03-10 15:24:57 +02001424
Gery Kahn6f07b722011-07-18 14:21:49 +03001425 /* update hw/fw version info in wiphy struct */
1426 wiphy->hw_version = wl->chip.id;
1427 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1428 sizeof(wiphy->fw_version));
1429
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001430 goto out;
1431
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001432irq_disable:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001433 mutex_unlock(&wl->mutex);
1434 /* Unlocking the mutex in the middle of handling is
1435 inherently unsafe. In this case we deem it safe to do,
1436 because we need to let any possibly pending IRQ out of
1437 the system (and while we are WL1271_STATE_OFF the IRQ
1438 work function will not do anything.) Also, any other
1439 possible concurrent operations will fail due to the
1440 current state, hence the wl1271 struct should be safe. */
Ido Yariva6208652011-03-01 15:14:41 +02001441 wl1271_disable_interrupts(wl);
1442 wl1271_flush_deferred_work(wl);
1443 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001444 mutex_lock(&wl->mutex);
1445power_off:
1446 wl1271_power_off(wl);
1447 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001448
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001449 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1450 WL1271_BOOT_RETRIES);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001451out:
1452 mutex_unlock(&wl->mutex);
1453
1454 return ret;
1455}
1456
Ido Yarivf3df1332012-01-11 09:42:39 +02001457int wl1271_plt_stop(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001458{
1459 int ret = 0;
1460
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001461 wl1271_notice("power down");
1462
Ido Yariv46b0cc92012-01-11 09:42:41 +02001463 /*
1464 * Interrupts must be disabled before setting the state to OFF.
1465 * Otherwise, the interrupt handler might be called and exit without
1466 * reading the interrupt status.
1467 */
1468 wl1271_disable_interrupts(wl);
Ido Yarivf3df1332012-01-11 09:42:39 +02001469 mutex_lock(&wl->mutex);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001470 if (!wl->plt) {
Ido Yarivf3df1332012-01-11 09:42:39 +02001471 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001472
1473 /*
1474 * This will not necessarily enable interrupts as interrupts
1475 * may have been disabled when op_stop was called. It will,
1476 * however, balance the above call to disable_interrupts().
1477 */
1478 wl1271_enable_interrupts(wl);
1479
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001480 wl1271_error("cannot power down because not in PLT "
1481 "state: %d", wl->state);
1482 ret = -EBUSY;
1483 goto out;
1484 }
1485
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001486 mutex_unlock(&wl->mutex);
Ido Yarivf3df1332012-01-11 09:42:39 +02001487
Ido Yariva6208652011-03-01 15:14:41 +02001488 wl1271_flush_deferred_work(wl);
1489 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001490 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001491 cancel_delayed_work_sync(&wl->elp_work);
Ido Yariva4549692012-01-11 09:42:40 +02001492
1493 mutex_lock(&wl->mutex);
1494 wl1271_power_off(wl);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001495 wl->flags = 0;
1496 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001497 wl->plt = false;
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001498 wl->rx_counter = 0;
Ido Yariva4549692012-01-11 09:42:40 +02001499 mutex_unlock(&wl->mutex);
1500
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01001501out:
1502 return ret;
1503}
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +02001504
Johannes Berg7bb45682011-02-24 14:42:06 +01001505static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001506{
1507 struct wl1271 *wl = hw->priv;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001508 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1509 struct ieee80211_vif *vif = info->control.vif;
Eliad Peller0f168012011-10-11 13:52:25 +02001510 struct wl12xx_vif *wlvif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001511 unsigned long flags;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001512 int q, mapping;
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001513 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001514
Eliad Peller0f168012011-10-11 13:52:25 +02001515 if (vif)
1516 wlvif = wl12xx_vif_to_data(vif);
1517
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001518 mapping = skb_get_queue_mapping(skb);
1519 q = wl1271_tx_get_queue(mapping);
Ido Yarivb07d4032011-03-01 15:14:43 +02001520
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001521 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
Ido Yarivb07d4032011-03-01 15:14:43 +02001522
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001523 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yarivb07d4032011-03-01 15:14:43 +02001524
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001525 /* queue the packet */
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001526 if (hlid == WL12XX_INVALID_LINK_ID ||
Eliad Peller0f168012011-10-11 13:52:25 +02001527 (wlvif && !test_bit(hlid, wlvif->links_map))) {
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001528 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
Eliad Peller5de8eef2011-12-13 15:26:38 +02001529 ieee80211_free_txskb(hw, skb);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001530 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02001531 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001532
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001533 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1534 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1535
Arik Nemtsov04b4d692011-08-14 13:17:39 +03001536 wl->tx_queue_count[q]++;
1537
1538 /*
1539 * The workqueue is slow to process the tx_queue and we need stop
1540 * the queue here, otherwise the queue will get too long.
1541 */
1542 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1543 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1544 ieee80211_stop_queue(wl->hw, mapping);
1545 set_bit(q, &wl->stopped_queues_map);
1546 }
1547
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001548 /*
1549 * The chip specific setup must run before the first TX packet -
1550 * before that, the tx_work will not be initialized!
1551 */
1552
Ido Yarivb07d4032011-03-01 15:14:43 +02001553 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1554 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
Ido Yariva5225502010-10-12 14:49:10 +02001555 ieee80211_queue_work(wl->hw, &wl->tx_work);
Ido Yarivb07d4032011-03-01 15:14:43 +02001556
Arik Nemtsov04216da2011-08-14 13:17:38 +03001557out:
Ido Yarivb07d4032011-03-01 15:14:43 +02001558 spin_unlock_irqrestore(&wl->wl_lock, flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001559}
1560
Shahar Leviae47c452011-03-06 16:32:14 +02001561int wl1271_tx_dummy_packet(struct wl1271 *wl)
1562{
Ido Yariv990f5de2011-03-31 10:06:59 +02001563 unsigned long flags;
Arik Nemtsov14623782011-08-28 15:11:57 +03001564 int q;
1565
1566 /* no need to queue a new dummy packet if one is already pending */
1567 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1568 return 0;
1569
1570 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
Shahar Leviae47c452011-03-06 16:32:14 +02001571
Ido Yariv990f5de2011-03-31 10:06:59 +02001572 spin_lock_irqsave(&wl->wl_lock, flags);
1573 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +03001574 wl->tx_queue_count[q]++;
Ido Yariv990f5de2011-03-31 10:06:59 +02001575 spin_unlock_irqrestore(&wl->wl_lock, flags);
1576
1577 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1578 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
Eliad Pellera32d0cd2011-10-10 10:12:55 +02001579 wl1271_tx_work_locked(wl);
Ido Yariv990f5de2011-03-31 10:06:59 +02001580
1581 /*
1582 * If the FW TX is busy, TX work will be scheduled by the threaded
1583 * interrupt handler function
1584 */
1585 return 0;
1586}
1587
1588/*
1589 * The size of the dummy packet should be at least 1400 bytes. However, in
1590 * order to minimize the number of bus transactions, aligning it to 512 bytes
1591 * boundaries could be beneficial, performance wise
1592 */
1593#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1594
Luciano Coelhocf27d862011-04-01 21:08:23 +03001595static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
Ido Yariv990f5de2011-03-31 10:06:59 +02001596{
1597 struct sk_buff *skb;
1598 struct ieee80211_hdr_3addr *hdr;
1599 unsigned int dummy_packet_size;
1600
1601 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1602 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1603
1604 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
Shahar Leviae47c452011-03-06 16:32:14 +02001605 if (!skb) {
Ido Yariv990f5de2011-03-31 10:06:59 +02001606 wl1271_warning("Failed to allocate a dummy packet skb");
1607 return NULL;
Shahar Leviae47c452011-03-06 16:32:14 +02001608 }
1609
1610 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1611
1612 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1613 memset(hdr, 0, sizeof(*hdr));
1614 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
Ido Yariv990f5de2011-03-31 10:06:59 +02001615 IEEE80211_STYPE_NULLFUNC |
1616 IEEE80211_FCTL_TODS);
Shahar Leviae47c452011-03-06 16:32:14 +02001617
Ido Yariv990f5de2011-03-31 10:06:59 +02001618 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
Shahar Leviae47c452011-03-06 16:32:14 +02001619
Luciano Coelho18b92ff2011-03-21 16:35:21 +02001620 /* Dummy packets require the TID to be management */
1621 skb->priority = WL1271_TID_MGMT;
Ido Yariv990f5de2011-03-31 10:06:59 +02001622
1623 /* Initialize all fields that might be used */
Hauke Mehrtens86c438f2011-04-26 23:27:44 +02001624 skb_set_queue_mapping(skb, 0);
Ido Yariv990f5de2011-03-31 10:06:59 +02001625 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
Shahar Leviae47c452011-03-06 16:32:14 +02001626
Ido Yariv990f5de2011-03-31 10:06:59 +02001627 return skb;
Shahar Leviae47c452011-03-06 16:32:14 +02001628}
1629
Ido Yariv990f5de2011-03-31 10:06:59 +02001630
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03001631static struct notifier_block wl1271_dev_notifier = {
1632 .notifier_call = wl1271_dev_notify,
1633};
1634
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001635#ifdef CONFIG_PM
Eyal Shapiradae728f2012-02-02 12:03:39 +02001636static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1637 struct wl12xx_vif *wlvif)
1638{
1639 int ret = 0;
1640
1641 mutex_lock(&wl->mutex);
1642
1643 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1644 goto out_unlock;
1645
1646 ret = wl1271_ps_elp_wakeup(wl);
1647 if (ret < 0)
1648 goto out_unlock;
1649
1650 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1651 wl->conf.conn.suspend_wake_up_event,
1652 wl->conf.conn.suspend_listen_interval);
1653
1654 if (ret < 0)
1655 wl1271_error("suspend: set wake up conditions failed: %d", ret);
1656
1657
1658 wl1271_ps_elp_sleep(wl);
1659
1660out_unlock:
1661 mutex_unlock(&wl->mutex);
1662 return ret;
1663
1664}
Eliad Peller94390642011-05-13 11:57:13 +03001665
Eliad Peller0603d892011-10-05 11:55:51 +02001666static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1667 struct wl12xx_vif *wlvif)
Eliad Peller94390642011-05-13 11:57:13 +03001668{
Eliad Pellere85d1622011-06-27 13:06:43 +03001669 int ret = 0;
Eliad Peller94390642011-05-13 11:57:13 +03001670
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001671 mutex_lock(&wl->mutex);
1672
Eliad Peller53d40d02011-10-10 10:13:02 +02001673 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Pellere85d1622011-06-27 13:06:43 +03001674 goto out_unlock;
1675
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001676 ret = wl1271_ps_elp_wakeup(wl);
1677 if (ret < 0)
1678 goto out_unlock;
1679
Eliad Peller0603d892011-10-05 11:55:51 +02001680 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001681
1682 wl1271_ps_elp_sleep(wl);
1683out_unlock:
1684 mutex_unlock(&wl->mutex);
1685 return ret;
1686
1687}
1688
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001689static int wl1271_configure_suspend(struct wl1271 *wl,
1690 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001691{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001692 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1693 return wl1271_configure_suspend_sta(wl, wlvif);
Eliad Peller536129c2011-10-05 11:55:45 +02001694 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
Eliad Peller0603d892011-10-05 11:55:51 +02001695 return wl1271_configure_suspend_ap(wl, wlvif);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001696 return 0;
1697}
1698
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001699static void wl1271_configure_resume(struct wl1271 *wl,
1700 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001701{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001702 int ret = 0;
Eliad Peller536129c2011-10-05 11:55:45 +02001703 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
Eyal Shapiradae728f2012-02-02 12:03:39 +02001704 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001705
Eyal Shapiradae728f2012-02-02 12:03:39 +02001706 if ((!is_ap) && (!is_sta))
Eliad Peller94390642011-05-13 11:57:13 +03001707 return;
1708
1709 mutex_lock(&wl->mutex);
1710 ret = wl1271_ps_elp_wakeup(wl);
1711 if (ret < 0)
1712 goto out;
1713
Eyal Shapiradae728f2012-02-02 12:03:39 +02001714 if (is_sta) {
1715 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1716 wl->conf.conn.wake_up_event,
1717 wl->conf.conn.listen_interval);
1718
1719 if (ret < 0)
1720 wl1271_error("resume: wake up conditions failed: %d",
1721 ret);
1722
1723 } else if (is_ap) {
1724 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1725 }
Eliad Peller94390642011-05-13 11:57:13 +03001726
1727 wl1271_ps_elp_sleep(wl);
1728out:
1729 mutex_unlock(&wl->mutex);
1730}
1731
Eliad Peller402e48612011-05-13 11:57:09 +03001732static int wl1271_op_suspend(struct ieee80211_hw *hw,
1733 struct cfg80211_wowlan *wow)
1734{
1735 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001736 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001737 int ret;
1738
Eliad Peller402e48612011-05-13 11:57:09 +03001739 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
Eliad Peller4a859df2011-06-06 12:21:52 +03001740 WARN_ON(!wow || !wow->any);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001741
Eliad Peller4a859df2011-06-06 12:21:52 +03001742 wl->wow_enabled = true;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001743 wl12xx_for_each_wlvif(wl, wlvif) {
1744 ret = wl1271_configure_suspend(wl, wlvif);
1745 if (ret < 0) {
1746 wl1271_warning("couldn't prepare device to suspend");
1747 return ret;
1748 }
Eliad Pellerf44e5862011-05-13 11:57:11 +03001749 }
Eliad Peller4a859df2011-06-06 12:21:52 +03001750 /* flush any remaining work */
1751 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
Eliad Peller4a859df2011-06-06 12:21:52 +03001752
1753 /*
1754 * disable and re-enable interrupts in order to flush
1755 * the threaded_irq
1756 */
1757 wl1271_disable_interrupts(wl);
1758
1759 /*
1760 * set suspended flag to avoid triggering a new threaded_irq
1761 * work. no need for spinlock as interrupts are disabled.
1762 */
1763 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1764
1765 wl1271_enable_interrupts(wl);
1766 flush_work(&wl->tx_work);
Eliad Peller4a859df2011-06-06 12:21:52 +03001767 flush_delayed_work(&wl->elp_work);
1768
Eliad Peller402e48612011-05-13 11:57:09 +03001769 return 0;
1770}
1771
1772static int wl1271_op_resume(struct ieee80211_hw *hw)
1773{
1774 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001775 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001776 unsigned long flags;
1777 bool run_irq_work = false;
1778
Eliad Peller402e48612011-05-13 11:57:09 +03001779 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1780 wl->wow_enabled);
Eliad Peller4a859df2011-06-06 12:21:52 +03001781 WARN_ON(!wl->wow_enabled);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001782
1783 /*
1784 * re-enable irq_work enqueuing, and call irq_work directly if
1785 * there is a pending work.
1786 */
Eliad Peller4a859df2011-06-06 12:21:52 +03001787 spin_lock_irqsave(&wl->wl_lock, flags);
1788 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1789 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1790 run_irq_work = true;
1791 spin_unlock_irqrestore(&wl->wl_lock, flags);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001792
Eliad Peller4a859df2011-06-06 12:21:52 +03001793 if (run_irq_work) {
1794 wl1271_debug(DEBUG_MAC80211,
1795 "run postponed irq_work directly");
1796 wl1271_irq(0, wl);
1797 wl1271_enable_interrupts(wl);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001798 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02001799 wl12xx_for_each_wlvif(wl, wlvif) {
1800 wl1271_configure_resume(wl, wlvif);
1801 }
Eliad Pellerff91afc2011-06-06 12:21:53 +03001802 wl->wow_enabled = false;
Eliad Pellerf44e5862011-05-13 11:57:11 +03001803
Eliad Peller402e48612011-05-13 11:57:09 +03001804 return 0;
1805}
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001806#endif
Eliad Peller402e48612011-05-13 11:57:09 +03001807
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001808static int wl1271_op_start(struct ieee80211_hw *hw)
1809{
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001810 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1811
1812 /*
1813 * We have to delay the booting of the hardware because
1814 * we need to know the local MAC address before downloading and
1815 * initializing the firmware. The MAC address cannot be changed
1816 * after boot, and without the proper MAC address, the firmware
1817 * will not function properly.
1818 *
1819 * The MAC address is first known when the corresponding interface
1820 * is added. That is where we will initialize the hardware.
1821 */
1822
Eyal Shapirad18da7f2012-01-31 11:57:25 +02001823 return 0;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001824}
1825
1826static void wl1271_op_stop(struct ieee80211_hw *hw)
1827{
Eliad Pellerbaf62772011-10-10 10:12:52 +02001828 struct wl1271 *wl = hw->priv;
1829 int i;
1830
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001831 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
Eliad Pellerbaf62772011-10-10 10:12:52 +02001832
Ido Yariv46b0cc92012-01-11 09:42:41 +02001833 /*
1834 * Interrupts must be disabled before setting the state to OFF.
1835 * Otherwise, the interrupt handler might be called and exit without
1836 * reading the interrupt status.
1837 */
1838 wl1271_disable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001839 mutex_lock(&wl->mutex);
1840 if (wl->state == WL1271_STATE_OFF) {
1841 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001842
1843 /*
1844 * This will not necessarily enable interrupts as interrupts
1845 * may have been disabled when op_stop was called. It will,
1846 * however, balance the above call to disable_interrupts().
1847 */
1848 wl1271_enable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001849 return;
1850 }
Ido Yariv46b0cc92012-01-11 09:42:41 +02001851
Eliad Pellerbaf62772011-10-10 10:12:52 +02001852 /*
1853 * this must be before the cancel_work calls below, so that the work
1854 * functions don't perform further work.
1855 */
1856 wl->state = WL1271_STATE_OFF;
Eliad Peller10c8cd02011-10-10 10:13:06 +02001857 mutex_unlock(&wl->mutex);
1858
1859 mutex_lock(&wl_list_mutex);
1860 list_del(&wl->list);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001861 mutex_unlock(&wl_list_mutex);
1862
Eliad Pellerbaf62772011-10-10 10:12:52 +02001863 wl1271_flush_deferred_work(wl);
1864 cancel_delayed_work_sync(&wl->scan_complete_work);
1865 cancel_work_sync(&wl->netstack_work);
1866 cancel_work_sync(&wl->tx_work);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001867 cancel_delayed_work_sync(&wl->elp_work);
1868
1869 /* let's notify MAC80211 about the remaining pending TX frames */
1870 wl12xx_tx_reset(wl, true);
1871 mutex_lock(&wl->mutex);
1872
1873 wl1271_power_off(wl);
1874
1875 wl->band = IEEE80211_BAND_2GHZ;
1876
1877 wl->rx_counter = 0;
1878 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1879 wl->tx_blocks_available = 0;
1880 wl->tx_allocated_blocks = 0;
1881 wl->tx_results_count = 0;
1882 wl->tx_packets_count = 0;
1883 wl->time_offset = 0;
Eliad Pellerbaf62772011-10-10 10:12:52 +02001884 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1885 wl->ap_fw_ps_map = 0;
1886 wl->ap_ps_map = 0;
1887 wl->sched_scanning = false;
1888 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1889 memset(wl->links_map, 0, sizeof(wl->links_map));
1890 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1891 wl->active_sta_count = 0;
1892
1893 /* The system link is always allocated */
1894 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1895
1896 /*
1897 * this is performed after the cancel_work calls and the associated
1898 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1899 * get executed before all these vars have been reset.
1900 */
1901 wl->flags = 0;
1902
1903 wl->tx_blocks_freed = 0;
1904
1905 for (i = 0; i < NUM_TX_QUEUES; i++) {
1906 wl->tx_pkts_freed[i] = 0;
1907 wl->tx_allocated_pkts[i] = 0;
1908 }
1909
1910 wl1271_debugfs_reset(wl);
1911
1912 kfree(wl->fw_status);
1913 wl->fw_status = NULL;
1914 kfree(wl->tx_res_if);
1915 wl->tx_res_if = NULL;
1916 kfree(wl->target_mem_map);
1917 wl->target_mem_map = NULL;
1918
1919 mutex_unlock(&wl->mutex);
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001920}
1921
Eliad Pellere5a359f2011-10-10 10:13:15 +02001922static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1923{
1924 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1925 WL12XX_MAX_RATE_POLICIES);
1926 if (policy >= WL12XX_MAX_RATE_POLICIES)
1927 return -EBUSY;
1928
1929 __set_bit(policy, wl->rate_policies_map);
1930 *idx = policy;
1931 return 0;
1932}
1933
1934static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1935{
1936 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1937 return;
1938
1939 __clear_bit(*idx, wl->rate_policies_map);
1940 *idx = WL12XX_MAX_RATE_POLICIES;
1941}
1942
Eliad Peller536129c2011-10-05 11:55:45 +02001943static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001944{
Eliad Peller536129c2011-10-05 11:55:45 +02001945 switch (wlvif->bss_type) {
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001946 case BSS_TYPE_AP_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001947 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001948 return WL1271_ROLE_P2P_GO;
1949 else
1950 return WL1271_ROLE_AP;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001951
1952 case BSS_TYPE_STA_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001953 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001954 return WL1271_ROLE_P2P_CL;
1955 else
1956 return WL1271_ROLE_STA;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001957
Eliad Peller227e81e2011-08-14 13:17:26 +03001958 case BSS_TYPE_IBSS:
1959 return WL1271_ROLE_IBSS;
1960
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001961 default:
Eliad Peller536129c2011-10-05 11:55:45 +02001962 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001963 }
1964 return WL12XX_INVALID_ROLE_TYPE;
1965}
1966
Eliad Peller83587502011-10-10 10:12:53 +02001967static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Eliad Peller87fbcb02011-10-05 11:55:41 +02001968{
Eliad Pellere936bbe2011-10-05 11:55:56 +02001969 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02001970 int i;
Eliad Pellere936bbe2011-10-05 11:55:56 +02001971
Eliad Peller48e93e42011-10-10 10:12:58 +02001972 /* clear everything but the persistent data */
1973 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
Eliad Pellere936bbe2011-10-05 11:55:56 +02001974
1975 switch (ieee80211_vif_type_p2p(vif)) {
1976 case NL80211_IFTYPE_P2P_CLIENT:
1977 wlvif->p2p = 1;
1978 /* fall-through */
1979 case NL80211_IFTYPE_STATION:
1980 wlvif->bss_type = BSS_TYPE_STA_BSS;
1981 break;
1982 case NL80211_IFTYPE_ADHOC:
1983 wlvif->bss_type = BSS_TYPE_IBSS;
1984 break;
1985 case NL80211_IFTYPE_P2P_GO:
1986 wlvif->p2p = 1;
1987 /* fall-through */
1988 case NL80211_IFTYPE_AP:
1989 wlvif->bss_type = BSS_TYPE_AP_BSS;
1990 break;
1991 default:
1992 wlvif->bss_type = MAX_BSS_TYPE;
1993 return -EOPNOTSUPP;
1994 }
1995
Eliad Peller0603d892011-10-05 11:55:51 +02001996 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02001997 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02001998 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001999
Eliad Pellere936bbe2011-10-05 11:55:56 +02002000 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2001 wlvif->bss_type == BSS_TYPE_IBSS) {
2002 /* init sta/ibss data */
2003 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002004 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2005 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2006 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002007 } else {
2008 /* init ap data */
2009 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2010 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002011 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2012 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2013 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2014 wl12xx_allocate_rate_policy(wl,
2015 &wlvif->ap.ucast_rate_idx[i]);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002016 }
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002017
Eliad Peller83587502011-10-10 10:12:53 +02002018 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
2019 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
Eliad Peller87fbcb02011-10-05 11:55:41 +02002020 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002021 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002022 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Peller6a899792011-10-05 11:55:58 +02002023 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
2024
Eliad Peller1b92f152011-10-10 10:13:09 +02002025 /*
2026 * mac80211 configures some values globally, while we treat them
2027 * per-interface. thus, on init, we have to copy them from wl
2028 */
2029 wlvif->band = wl->band;
Eliad Peller61f845f2011-10-10 10:13:10 +02002030 wlvif->channel = wl->channel;
Eliad Peller6bd65022011-10-10 10:13:11 +02002031 wlvif->power_level = wl->power_level;
Eliad Peller1b92f152011-10-10 10:13:09 +02002032
Eliad Peller9eb599e2011-10-10 10:12:59 +02002033 INIT_WORK(&wlvif->rx_streaming_enable_work,
2034 wl1271_rx_streaming_enable_work);
2035 INIT_WORK(&wlvif->rx_streaming_disable_work,
2036 wl1271_rx_streaming_disable_work);
Eliad Peller87627212011-10-10 10:12:54 +02002037 INIT_LIST_HEAD(&wlvif->list);
Eliad Peller252efa42011-10-05 11:56:00 +02002038
Eliad Peller9eb599e2011-10-10 10:12:59 +02002039 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
2040 (unsigned long) wlvif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002041 return 0;
Eliad Peller87fbcb02011-10-05 11:55:41 +02002042}
2043
Eliad Peller1d095472011-10-10 10:12:49 +02002044static bool wl12xx_init_fw(struct wl1271 *wl)
2045{
2046 int retries = WL1271_BOOT_RETRIES;
2047 bool booted = false;
2048 struct wiphy *wiphy = wl->hw->wiphy;
2049 int ret;
2050
2051 while (retries) {
2052 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02002053 ret = wl12xx_chip_wakeup(wl, false);
Eliad Peller1d095472011-10-10 10:12:49 +02002054 if (ret < 0)
2055 goto power_off;
2056
2057 ret = wl1271_boot(wl);
2058 if (ret < 0)
2059 goto power_off;
2060
2061 ret = wl1271_hw_init(wl);
2062 if (ret < 0)
2063 goto irq_disable;
2064
2065 booted = true;
2066 break;
2067
2068irq_disable:
2069 mutex_unlock(&wl->mutex);
2070 /* Unlocking the mutex in the middle of handling is
2071 inherently unsafe. In this case we deem it safe to do,
2072 because we need to let any possibly pending IRQ out of
2073 the system (and while we are WL1271_STATE_OFF the IRQ
2074 work function will not do anything.) Also, any other
2075 possible concurrent operations will fail due to the
2076 current state, hence the wl1271 struct should be safe. */
2077 wl1271_disable_interrupts(wl);
2078 wl1271_flush_deferred_work(wl);
2079 cancel_work_sync(&wl->netstack_work);
2080 mutex_lock(&wl->mutex);
2081power_off:
2082 wl1271_power_off(wl);
2083 }
2084
2085 if (!booted) {
2086 wl1271_error("firmware boot failed despite %d retries",
2087 WL1271_BOOT_RETRIES);
2088 goto out;
2089 }
2090
2091 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
2092
2093 /* update hw/fw version info in wiphy struct */
2094 wiphy->hw_version = wl->chip.id;
2095 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
2096 sizeof(wiphy->fw_version));
2097
2098 /*
2099 * Now we know if 11a is supported (info from the NVS), so disable
2100 * 11a channels if not supported
2101 */
2102 if (!wl->enable_11a)
2103 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2104
2105 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2106 wl->enable_11a ? "" : "not ");
2107
2108 wl->state = WL1271_STATE_ON;
2109out:
2110 return booted;
2111}
2112
Eliad Peller92e712d2011-12-18 20:25:43 +02002113static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2114{
2115 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2116}
2117
Eliad Peller4549d092012-02-06 13:07:52 +02002118/*
2119 * Check whether a fw switch (i.e. moving from one loaded
2120 * fw to another) is needed. This function is also responsible
2121 * for updating wl->last_vif_count, so it must be called before
2122 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2123 * will be used).
2124 */
2125static bool wl12xx_need_fw_change(struct wl1271 *wl,
2126 struct vif_counter_data vif_counter_data,
2127 bool add)
2128{
2129 enum wl12xx_fw_type current_fw = wl->fw_type;
2130 u8 vif_count = vif_counter_data.counter;
2131
2132 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
2133 return false;
2134
2135 /* increase the vif count if this is a new vif */
2136 if (add && !vif_counter_data.cur_vif_running)
2137 vif_count++;
2138
2139 wl->last_vif_count = vif_count;
2140
2141 /* no need for fw change if the device is OFF */
2142 if (wl->state == WL1271_STATE_OFF)
2143 return false;
2144
2145 if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
2146 return true;
2147 if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
2148 return true;
2149
2150 return false;
2151}
2152
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002153static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2154 struct ieee80211_vif *vif)
2155{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002156 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002157 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller4549d092012-02-06 13:07:52 +02002158 struct vif_counter_data vif_count;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002159 int ret = 0;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002160 u8 role_type;
Eliad Peller71125ab2010-10-28 21:46:43 +02002161 bool booted = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002162
Johannes Bergea086352012-01-19 09:29:58 +01002163 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2164 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Johannes Bergc1288b12012-01-19 09:29:57 +01002165
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002166 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
Eliad Peller045c7452011-08-28 15:23:01 +03002167 ieee80211_vif_type_p2p(vif), vif->addr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002168
Eliad Peller4549d092012-02-06 13:07:52 +02002169 wl12xx_get_vif_count(hw, vif, &vif_count);
2170
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002171 mutex_lock(&wl->mutex);
Eliad Pellerf750c822011-10-10 10:13:16 +02002172 ret = wl1271_ps_elp_wakeup(wl);
2173 if (ret < 0)
2174 goto out_unlock;
2175
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002176 if (wl->vif) {
Eliad Peller71125ab2010-10-28 21:46:43 +02002177 wl1271_debug(DEBUG_MAC80211,
2178 "multiple vifs are not supported yet");
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002179 ret = -EBUSY;
2180 goto out;
2181 }
2182
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002183 /*
2184 * in some very corner case HW recovery scenarios its possible to
2185 * get here before __wl1271_op_remove_interface is complete, so
2186 * opt out if that is the case.
2187 */
Eliad Peller10c8cd02011-10-10 10:13:06 +02002188 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2189 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002190 ret = -EBUSY;
2191 goto out;
2192 }
2193
Eliad Peller3fcdab72012-02-06 12:47:54 +02002194
Eliad Peller83587502011-10-10 10:12:53 +02002195 ret = wl12xx_init_vif_data(wl, vif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002196 if (ret < 0)
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002197 goto out;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002198
Eliad Peller252efa42011-10-05 11:56:00 +02002199 wlvif->wl = wl;
Eliad Peller536129c2011-10-05 11:55:45 +02002200 role_type = wl12xx_get_role_type(wl, wlvif);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002201 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2202 ret = -EINVAL;
2203 goto out;
2204 }
Eliad Peller1d095472011-10-10 10:12:49 +02002205
Eliad Peller4549d092012-02-06 13:07:52 +02002206 if (wl12xx_need_fw_change(wl, vif_count, true)) {
2207 mutex_unlock(&wl->mutex);
2208 wl1271_recovery_work(&wl->recovery_work);
2209 return 0;
2210 }
2211
Eliad Peller784f6942011-10-05 11:55:39 +02002212 /*
Eliad Peller1d095472011-10-10 10:12:49 +02002213 * TODO: after the nvs issue will be solved, move this block
2214 * to start(), and make sure here the driver is ON.
Eliad Peller784f6942011-10-05 11:55:39 +02002215 */
Eliad Peller1d095472011-10-10 10:12:49 +02002216 if (wl->state == WL1271_STATE_OFF) {
2217 /*
2218 * we still need this in order to configure the fw
2219 * while uploading the nvs
2220 */
Luciano Coelho5e037e72011-12-23 09:32:17 +02002221 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002222
Eliad Peller1d095472011-10-10 10:12:49 +02002223 booted = wl12xx_init_fw(wl);
2224 if (!booted) {
2225 ret = -EINVAL;
2226 goto out;
Eliad Peller04e80792011-08-14 13:17:09 +03002227 }
Eliad Peller1d095472011-10-10 10:12:49 +02002228 }
Eliad Peller04e80792011-08-14 13:17:09 +03002229
Eliad Peller1d095472011-10-10 10:12:49 +02002230 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2231 wlvif->bss_type == BSS_TYPE_IBSS) {
2232 /*
2233 * The device role is a special role used for
2234 * rx and tx frames prior to association (as
2235 * the STA role can get packets only from
2236 * its associated bssid)
2237 */
Eliad Peller784f6942011-10-05 11:55:39 +02002238 ret = wl12xx_cmd_role_enable(wl, vif->addr,
Eliad Peller1d095472011-10-10 10:12:49 +02002239 WL1271_ROLE_DEVICE,
2240 &wlvif->dev_role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002241 if (ret < 0)
Eliad Peller1d095472011-10-10 10:12:49 +02002242 goto out;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02002243 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002244
Eliad Peller1d095472011-10-10 10:12:49 +02002245 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2246 role_type, &wlvif->role_id);
2247 if (ret < 0)
Eliad Peller71125ab2010-10-28 21:46:43 +02002248 goto out;
Eliad Peller1d095472011-10-10 10:12:49 +02002249
2250 ret = wl1271_init_vif_specific(wl, vif);
2251 if (ret < 0)
2252 goto out;
Eliad Peller71125ab2010-10-28 21:46:43 +02002253
2254 wl->vif = vif;
Eliad Peller87627212011-10-10 10:12:54 +02002255 list_add(&wlvif->list, &wl->wlvif_list);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002256 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
Eliad Pellera4e41302011-10-11 11:49:15 +02002257
2258 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2259 wl->ap_count++;
2260 else
2261 wl->sta_count++;
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +03002262out:
Eliad Pellerf750c822011-10-10 10:13:16 +02002263 wl1271_ps_elp_sleep(wl);
2264out_unlock:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002265 mutex_unlock(&wl->mutex);
2266
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002267 mutex_lock(&wl_list_mutex);
Juuso Oikarineneb887df2010-07-08 17:49:58 +03002268 if (!ret)
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002269 list_add(&wl->list, &wl_list);
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002270 mutex_unlock(&wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002271
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002272 return ret;
2273}
2274
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002275static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +02002276 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002277 bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002278{
Eliad Peller536129c2011-10-05 11:55:45 +02002279 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02002280 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002281
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002282 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002283
Eliad Peller10c8cd02011-10-10 10:13:06 +02002284 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2285 return;
2286
Eliad Peller2f8e81a2011-11-01 15:12:50 +02002287 wl->vif = NULL;
2288
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002289 /* because of hardware recovery, we may get here twice */
2290 if (wl->state != WL1271_STATE_ON)
2291 return;
2292
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002293 wl1271_info("down");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002294
Eliad Pellerbaf62772011-10-10 10:12:52 +02002295 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2296 wl->scan_vif == vif) {
Luciano Coelho08688d62010-07-08 17:50:07 +03002297 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +02002298 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02002299 wl->scan_vif = NULL;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002300 wl->scan.req = NULL;
Juuso Oikarinen76a029f2010-07-29 04:54:45 +03002301 ieee80211_scan_completed(wl->hw, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002302 }
2303
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002304 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2305 /* disable active roles */
2306 ret = wl1271_ps_elp_wakeup(wl);
2307 if (ret < 0)
2308 goto deinit;
2309
Eliad Pellerb890f4c2011-12-18 20:25:44 +02002310 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2311 wlvif->bss_type == BSS_TYPE_IBSS) {
2312 if (wl12xx_dev_role_started(wlvif))
2313 wl12xx_stop_dev(wl, wlvif);
2314
Eliad Peller7edebf52011-10-05 11:55:52 +02002315 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +03002316 if (ret < 0)
2317 goto deinit;
2318 }
2319
Eliad Peller0603d892011-10-05 11:55:51 +02002320 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002321 if (ret < 0)
2322 goto deinit;
2323
2324 wl1271_ps_elp_sleep(wl);
2325 }
2326deinit:
Arik Nemtsove51ae9b2011-08-14 13:17:21 +03002327 /* clear all hlids (except system_hlid) */
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02002328 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002329
2330 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2331 wlvif->bss_type == BSS_TYPE_IBSS) {
2332 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2333 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2334 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2335 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2336 } else {
2337 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2338 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2339 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2340 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2341 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2342 wl12xx_free_rate_policy(wl,
2343 &wlvif->ap.ucast_rate_idx[i]);
2344 }
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002345
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02002346 wl12xx_tx_reset_wlvif(wl, wlvif);
Eliad Peller170d0e62011-10-05 11:56:06 +02002347 wl1271_free_ap_keys(wl, wlvif);
Eliad Pellere4120df2011-10-10 10:13:17 +02002348 if (wl->last_wlvif == wlvif)
2349 wl->last_wlvif = NULL;
Eliad Peller87627212011-10-10 10:12:54 +02002350 list_del(&wlvif->list);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02002351 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
Eliad Peller0603d892011-10-05 11:55:51 +02002352 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02002353 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Luciano Coelhod6e19d12009-10-12 15:08:43 +03002354
Eliad Pellera4e41302011-10-11 11:49:15 +02002355 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2356 wl->ap_count--;
2357 else
2358 wl->sta_count--;
2359
Eliad Pellerbaf62772011-10-10 10:12:52 +02002360 mutex_unlock(&wl->mutex);
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02002361
Eliad Peller9eb599e2011-10-10 10:12:59 +02002362 del_timer_sync(&wlvif->rx_streaming_timer);
2363 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2364 cancel_work_sync(&wlvif->rx_streaming_disable_work);
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03002365
Eliad Pellerbaf62772011-10-10 10:12:52 +02002366 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002367}
Juuso Oikarinenbd9dc492010-04-09 11:07:26 +03002368
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002369static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2370 struct ieee80211_vif *vif)
2371{
2372 struct wl1271 *wl = hw->priv;
Eliad Peller10c8cd02011-10-10 10:13:06 +02002373 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002374 struct wl12xx_vif *iter;
Eliad Peller4549d092012-02-06 13:07:52 +02002375 struct vif_counter_data vif_count;
2376 bool cancel_recovery = true;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002377
Eliad Peller4549d092012-02-06 13:07:52 +02002378 wl12xx_get_vif_count(hw, vif, &vif_count);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002379 mutex_lock(&wl->mutex);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002380
2381 if (wl->state == WL1271_STATE_OFF ||
2382 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2383 goto out;
2384
Juuso Oikarinen67353292010-11-18 15:19:02 +02002385 /*
2386 * wl->vif can be null here if someone shuts down the interface
2387 * just when hardware recovery has been started.
2388 */
Eliad Peller6e8cd332011-10-10 10:13:13 +02002389 wl12xx_for_each_wlvif(wl, iter) {
2390 if (iter != wlvif)
2391 continue;
2392
Eliad Peller536129c2011-10-05 11:55:45 +02002393 __wl1271_op_remove_interface(wl, vif, true);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002394 break;
Juuso Oikarinen67353292010-11-18 15:19:02 +02002395 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02002396 WARN_ON(iter != wlvif);
Eliad Peller4549d092012-02-06 13:07:52 +02002397 if (wl12xx_need_fw_change(wl, vif_count, false)) {
2398 wl12xx_queue_recovery_work(wl);
2399 cancel_recovery = false;
2400 }
Eliad Peller10c8cd02011-10-10 10:13:06 +02002401out:
Juuso Oikarinen67353292010-11-18 15:19:02 +02002402 mutex_unlock(&wl->mutex);
Eliad Peller4549d092012-02-06 13:07:52 +02002403 if (cancel_recovery)
2404 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002405}
2406
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002407static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2408 struct ieee80211_vif *vif,
2409 enum nl80211_iftype new_type, bool p2p)
2410{
Eliad Peller4549d092012-02-06 13:07:52 +02002411 struct wl1271 *wl = hw->priv;
2412 int ret;
2413
2414 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002415 wl1271_op_remove_interface(hw, vif);
2416
2417 vif->type = ieee80211_iftype_p2p(new_type, p2p);
2418 vif->p2p = p2p;
Eliad Peller4549d092012-02-06 13:07:52 +02002419 ret = wl1271_op_add_interface(hw, vif);
2420
2421 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2422 return ret;
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002423}
2424
Eliad Peller87fbcb02011-10-05 11:55:41 +02002425static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2426 bool set_assoc)
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002427{
2428 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002429 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002430
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002431 /*
2432 * One of the side effects of the JOIN command is that is clears
2433 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2434 * to a WPA/WPA2 access point will therefore kill the data-path.
Ohad Ben-Cohen8bf69aa2011-03-30 19:18:31 +02002435 * Currently the only valid scenario for JOIN during association
2436 * is on roaming, in which case we will also be given new keys.
2437 * Keep the below message for now, unless it starts bothering
2438 * users who really like to roam a lot :)
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002439 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002440 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002441 wl1271_info("JOIN while associated.");
2442
Eliad Peller5ec8a442012-02-02 12:22:09 +02002443 /* clear encryption type */
2444 wlvif->encryption_type = KEY_NONE;
2445
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002446 if (set_assoc)
Eliad Pellerba8447f2011-10-10 10:13:00 +02002447 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002448
Eliad Peller227e81e2011-08-14 13:17:26 +03002449 if (is_ibss)
Eliad Peller87fbcb02011-10-05 11:55:41 +02002450 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03002451 else
Eliad Peller87fbcb02011-10-05 11:55:41 +02002452 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002453 if (ret < 0)
2454 goto out;
2455
Eliad Pellerba8447f2011-10-10 10:13:00 +02002456 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002457 goto out;
2458
2459 /*
2460 * The join command disable the keep-alive mode, shut down its process,
2461 * and also clear the template config, so we need to reset it all after
2462 * the join. The acx_aid starts the keep-alive process, and the order
2463 * of the commands below is relevant.
2464 */
Eliad Peller0603d892011-10-05 11:55:51 +02002465 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002466 if (ret < 0)
2467 goto out;
2468
Eliad Peller0603d892011-10-05 11:55:51 +02002469 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002470 if (ret < 0)
2471 goto out;
2472
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002473 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002474 if (ret < 0)
2475 goto out;
2476
Eliad Peller0603d892011-10-05 11:55:51 +02002477 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2478 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002479 ACX_KEEP_ALIVE_TPL_VALID);
2480 if (ret < 0)
2481 goto out;
2482
2483out:
2484 return ret;
2485}
2486
Eliad Peller0603d892011-10-05 11:55:51 +02002487static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002488{
2489 int ret;
2490
Eliad Peller52630c52011-10-10 10:13:08 +02002491 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02002492 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2493
Shahar Levi6d158ff2011-09-08 13:01:33 +03002494 wl12xx_cmd_stop_channel_switch(wl);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002495 ieee80211_chswitch_done(vif, false);
Shahar Levi6d158ff2011-09-08 13:01:33 +03002496 }
2497
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002498 /* to stop listening to a channel, we disconnect */
Eliad Peller0603d892011-10-05 11:55:51 +02002499 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002500 if (ret < 0)
2501 goto out;
2502
Oz Krakowskib992c682011-06-26 10:36:02 +03002503 /* reset TX security counters on a clean disconnect */
Eliad Peller48e93e42011-10-10 10:12:58 +02002504 wlvif->tx_security_last_seq_lsb = 0;
2505 wlvif->tx_security_seq = 0;
Oz Krakowskib992c682011-06-26 10:36:02 +03002506
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002507out:
2508 return ret;
2509}
2510
Eliad Peller87fbcb02011-10-05 11:55:41 +02002511static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002512{
Eliad Peller1b92f152011-10-10 10:13:09 +02002513 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002514 wlvif->rate_set = wlvif->basic_rate_set;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002515}
2516
Eliad Peller87fbcb02011-10-05 11:55:41 +02002517static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2518 bool idle)
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002519{
2520 int ret;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002521 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2522
2523 if (idle == cur_idle)
2524 return 0;
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002525
2526 if (idle) {
Eliad Peller251c1772011-08-14 13:17:17 +03002527 /* no need to croc if we weren't busy (e.g. during boot) */
Eliad Peller92e712d2011-12-18 20:25:43 +02002528 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002529 ret = wl12xx_stop_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002530 if (ret < 0)
2531 goto out;
2532 }
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002533 wlvif->rate_set =
2534 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2535 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002536 if (ret < 0)
2537 goto out;
2538 ret = wl1271_acx_keep_alive_config(
Eliad Peller0603d892011-10-05 11:55:51 +02002539 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002540 ACX_KEEP_ALIVE_TPL_INVALID);
2541 if (ret < 0)
2542 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002543 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002544 } else {
Luciano Coelho33c2c062011-05-10 14:46:02 +03002545 /* The current firmware only supports sched_scan in idle */
2546 if (wl->sched_scanning) {
2547 wl1271_scan_sched_scan_stop(wl);
2548 ieee80211_sched_scan_stopped(wl->hw);
2549 }
2550
Eliad Peller679a6732011-10-11 11:55:44 +02002551 ret = wl12xx_start_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002552 if (ret < 0)
2553 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002554 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002555 }
2556
2557out:
2558 return ret;
2559}
2560
Eliad Peller9f259c42011-10-10 10:13:12 +02002561static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2562 struct ieee80211_conf *conf, u32 changed)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002563{
Eliad Peller9f259c42011-10-10 10:13:12 +02002564 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2565 int channel, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002566
2567 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2568
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002569 /* if the channel changes while joined, join again */
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002570 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
Eliad Peller1b92f152011-10-10 10:13:09 +02002571 ((wlvif->band != conf->channel->band) ||
Eliad Peller61f845f2011-10-10 10:13:10 +02002572 (wlvif->channel != channel))) {
Eliad Pellerc6930b02011-09-15 13:00:01 +03002573 /* send all pending packets */
Eliad Pellera32d0cd2011-10-10 10:12:55 +02002574 wl1271_tx_work_locked(wl);
Eliad Peller61f845f2011-10-10 10:13:10 +02002575 wlvif->band = conf->channel->band;
2576 wlvif->channel = channel;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002577
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002578 if (!is_ap) {
2579 /*
2580 * FIXME: the mac80211 should really provide a fixed
2581 * rate to use here. for now, just use the smallest
2582 * possible rate for the band as a fixed rate for
2583 * association frames and other control messages.
2584 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002585 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Peller87fbcb02011-10-05 11:55:41 +02002586 wl1271_set_band_rate(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002587
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002588 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02002589 wl1271_tx_min_rate_get(wl,
2590 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002591 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002592 if (ret < 0)
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002593 wl1271_warning("rate policy for channel "
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002594 "failed %d", ret);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002595
Eliad Pellerba8447f2011-10-10 10:13:00 +02002596 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2597 &wlvif->flags)) {
Eliad Peller92e712d2011-12-18 20:25:43 +02002598 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller251c1772011-08-14 13:17:17 +03002599 /* roaming */
Eliad Peller7edebf52011-10-05 11:55:52 +02002600 ret = wl12xx_croc(wl,
2601 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03002602 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002603 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002604 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02002605 ret = wl1271_join(wl, wlvif, false);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002606 if (ret < 0)
2607 wl1271_warning("cmd join on channel "
2608 "failed %d", ret);
Eliad Peller251c1772011-08-14 13:17:17 +03002609 } else {
2610 /*
2611 * change the ROC channel. do it only if we are
2612 * not idle. otherwise, CROC will be called
2613 * anyway.
2614 */
Eliad Peller92e712d2011-12-18 20:25:43 +02002615 if (wl12xx_dev_role_started(wlvif) &&
Eliad Peller251c1772011-08-14 13:17:17 +03002616 !(conf->flags & IEEE80211_CONF_IDLE)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002617 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002618 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002619 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002620
Eliad Peller679a6732011-10-11 11:55:44 +02002621 ret = wl12xx_start_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002622 if (ret < 0)
Eliad Peller679a6732011-10-11 11:55:44 +02002623 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002624 }
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002625 }
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002626 }
2627 }
2628
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002629 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002630
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002631 if ((conf->flags & IEEE80211_CONF_PS) &&
2632 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002633 !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002634
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002635 int ps_mode;
2636 char *ps_mode_str;
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002637
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002638 if (wl->conf.conn.forced_ps) {
2639 ps_mode = STATION_POWER_SAVE_MODE;
2640 ps_mode_str = "forced";
2641 } else {
2642 ps_mode = STATION_AUTO_PS_MODE;
2643 ps_mode_str = "auto";
2644 }
2645
2646 wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
2647
2648 ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
2649
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002650 if (ret < 0)
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002651 wl1271_warning("enter %s ps failed %d",
2652 ps_mode_str, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002653
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002654 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002655 test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002656
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002657 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2658
Eliad Peller0603d892011-10-05 11:55:51 +02002659 ret = wl1271_ps_set_mode(wl, wlvif,
Eyal Shapira248a0012012-01-31 11:57:23 +02002660 STATION_ACTIVE_MODE);
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002661 if (ret < 0)
2662 wl1271_warning("exit auto ps failed %d", ret);
2663 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002664 }
2665
Eliad Peller6bd65022011-10-10 10:13:11 +02002666 if (conf->power_level != wlvif->power_level) {
Eliad Peller0603d892011-10-05 11:55:51 +02002667 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002668 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002669 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002670
Eliad Peller6bd65022011-10-10 10:13:11 +02002671 wlvif->power_level = conf->power_level;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002672 }
2673
Eliad Peller9f259c42011-10-10 10:13:12 +02002674 return 0;
2675}
2676
2677static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2678{
2679 struct wl1271 *wl = hw->priv;
2680 struct wl12xx_vif *wlvif;
2681 struct ieee80211_conf *conf = &hw->conf;
2682 int channel, ret = 0;
2683
2684 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2685
2686 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2687 " changed 0x%x",
2688 channel,
2689 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2690 conf->power_level,
2691 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2692 changed);
2693
2694 /*
2695 * mac80211 will go to idle nearly immediately after transmitting some
2696 * frames, such as the deauth. To make sure those frames reach the air,
2697 * wait here until the TX queue is fully flushed.
2698 */
2699 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2700 (conf->flags & IEEE80211_CONF_IDLE))
2701 wl1271_tx_flush(wl);
2702
2703 mutex_lock(&wl->mutex);
2704
2705 /* we support configuring the channel and band even while off */
2706 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2707 wl->band = conf->channel->band;
2708 wl->channel = channel;
2709 }
2710
2711 if (changed & IEEE80211_CONF_CHANGE_POWER)
2712 wl->power_level = conf->power_level;
2713
2714 if (unlikely(wl->state == WL1271_STATE_OFF))
2715 goto out;
2716
2717 ret = wl1271_ps_elp_wakeup(wl);
2718 if (ret < 0)
2719 goto out;
2720
2721 /* configure each interface */
2722 wl12xx_for_each_wlvif(wl, wlvif) {
2723 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2724 if (ret < 0)
2725 goto out_sleep;
2726 }
2727
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002728out_sleep:
2729 wl1271_ps_elp_sleep(wl);
2730
2731out:
2732 mutex_unlock(&wl->mutex);
2733
2734 return ret;
2735}
2736
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002737struct wl1271_filter_params {
2738 bool enabled;
2739 int mc_list_length;
2740 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2741};
2742
Jiri Pirko22bedad2010-04-01 21:22:57 +00002743static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2744 struct netdev_hw_addr_list *mc_list)
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002745{
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002746 struct wl1271_filter_params *fp;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002747 struct netdev_hw_addr *ha;
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002748 struct wl1271 *wl = hw->priv;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002749
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002750 if (unlikely(wl->state == WL1271_STATE_OFF))
2751 return 0;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002752
Juuso Oikarinen74441132009-10-13 12:47:53 +03002753 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002754 if (!fp) {
2755 wl1271_error("Out of memory setting filters.");
2756 return 0;
2757 }
2758
2759 /* update multicast filtering parameters */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002760 fp->mc_list_length = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002761 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2762 fp->enabled = false;
2763 } else {
2764 fp->enabled = true;
2765 netdev_hw_addr_list_for_each(ha, mc_list) {
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002766 memcpy(fp->mc_list[fp->mc_list_length],
Jiri Pirko22bedad2010-04-01 21:22:57 +00002767 ha->addr, ETH_ALEN);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002768 fp->mc_list_length++;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002769 }
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002770 }
2771
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002772 return (u64)(unsigned long)fp;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002773}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002774
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002775#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2776 FIF_ALLMULTI | \
2777 FIF_FCSFAIL | \
2778 FIF_BCN_PRBRESP_PROMISC | \
2779 FIF_CONTROL | \
2780 FIF_OTHER_BSS)
2781
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002782static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2783 unsigned int changed,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002784 unsigned int *total, u64 multicast)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002785{
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002786 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002787 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02002788 struct wl12xx_vif *wlvif;
Eliad Peller536129c2011-10-05 11:55:45 +02002789
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002790 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002791
Arik Nemtsov7d057862010-10-16 19:25:35 +02002792 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2793 " total %x", changed, *total);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002794
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002795 mutex_lock(&wl->mutex);
2796
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002797 *total &= WL1271_SUPPORTED_FILTERS;
2798 changed &= WL1271_SUPPORTED_FILTERS;
2799
2800 if (unlikely(wl->state == WL1271_STATE_OFF))
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002801 goto out;
2802
Ido Yariva6208652011-03-01 15:14:41 +02002803 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002804 if (ret < 0)
2805 goto out;
2806
Eliad Peller6e8cd332011-10-10 10:13:13 +02002807 wl12xx_for_each_wlvif(wl, wlvif) {
2808 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2809 if (*total & FIF_ALLMULTI)
2810 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2811 false,
2812 NULL, 0);
2813 else if (fp)
2814 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2815 fp->enabled,
2816 fp->mc_list,
2817 fp->mc_list_length);
2818 if (ret < 0)
2819 goto out_sleep;
2820 }
Arik Nemtsov7d057862010-10-16 19:25:35 +02002821 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002822
Eliad Peller08c1d1c2011-08-14 13:17:04 +03002823 /*
2824 * the fw doesn't provide an api to configure the filters. instead,
2825 * the filters configuration is based on the active roles / ROC
2826 * state.
2827 */
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002828
2829out_sleep:
2830 wl1271_ps_elp_sleep(wl);
2831
2832out:
2833 mutex_unlock(&wl->mutex);
Juuso Oikarinen14b228a2010-03-18 12:26:43 +02002834 kfree(fp);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002835}
2836
Eliad Peller170d0e62011-10-05 11:56:06 +02002837static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2838 u8 id, u8 key_type, u8 key_size,
2839 const u8 *key, u8 hlid, u32 tx_seq_32,
2840 u16 tx_seq_16)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002841{
2842 struct wl1271_ap_key *ap_key;
2843 int i;
2844
2845 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2846
2847 if (key_size > MAX_KEY_SIZE)
2848 return -EINVAL;
2849
2850 /*
2851 * Find next free entry in ap_keys. Also check we are not replacing
2852 * an existing key.
2853 */
2854 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002855 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002856 break;
2857
Eliad Peller170d0e62011-10-05 11:56:06 +02002858 if (wlvif->ap.recorded_keys[i]->id == id) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002859 wl1271_warning("trying to record key replacement");
2860 return -EINVAL;
2861 }
2862 }
2863
2864 if (i == MAX_NUM_KEYS)
2865 return -EBUSY;
2866
2867 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2868 if (!ap_key)
2869 return -ENOMEM;
2870
2871 ap_key->id = id;
2872 ap_key->key_type = key_type;
2873 ap_key->key_size = key_size;
2874 memcpy(ap_key->key, key, key_size);
2875 ap_key->hlid = hlid;
2876 ap_key->tx_seq_32 = tx_seq_32;
2877 ap_key->tx_seq_16 = tx_seq_16;
2878
Eliad Peller170d0e62011-10-05 11:56:06 +02002879 wlvif->ap.recorded_keys[i] = ap_key;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002880 return 0;
2881}
2882
Eliad Peller170d0e62011-10-05 11:56:06 +02002883static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002884{
2885 int i;
2886
2887 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002888 kfree(wlvif->ap.recorded_keys[i]);
2889 wlvif->ap.recorded_keys[i] = NULL;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002890 }
2891}
2892
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002893static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002894{
2895 int i, ret = 0;
2896 struct wl1271_ap_key *key;
2897 bool wep_key_added = false;
2898
2899 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller7f97b482011-08-14 13:17:30 +03002900 u8 hlid;
Eliad Peller170d0e62011-10-05 11:56:06 +02002901 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002902 break;
2903
Eliad Peller170d0e62011-10-05 11:56:06 +02002904 key = wlvif->ap.recorded_keys[i];
Eliad Peller7f97b482011-08-14 13:17:30 +03002905 hlid = key->hlid;
2906 if (hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002907 hlid = wlvif->ap.bcast_hlid;
Eliad Peller7f97b482011-08-14 13:17:30 +03002908
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002909 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002910 key->id, key->key_type,
2911 key->key_size, key->key,
Eliad Peller7f97b482011-08-14 13:17:30 +03002912 hlid, key->tx_seq_32,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002913 key->tx_seq_16);
2914 if (ret < 0)
2915 goto out;
2916
2917 if (key->key_type == KEY_WEP)
2918 wep_key_added = true;
2919 }
2920
2921 if (wep_key_added) {
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002922 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002923 wlvif->ap.bcast_hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002924 if (ret < 0)
2925 goto out;
2926 }
2927
2928out:
Eliad Peller170d0e62011-10-05 11:56:06 +02002929 wl1271_free_ap_keys(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002930 return ret;
2931}
2932
Eliad Peller536129c2011-10-05 11:55:45 +02002933static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2934 u16 action, u8 id, u8 key_type,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002935 u8 key_size, const u8 *key, u32 tx_seq_32,
2936 u16 tx_seq_16, struct ieee80211_sta *sta)
2937{
2938 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002939 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002940
2941 if (is_ap) {
2942 struct wl1271_station *wl_sta;
2943 u8 hlid;
2944
2945 if (sta) {
2946 wl_sta = (struct wl1271_station *)sta->drv_priv;
2947 hlid = wl_sta->hlid;
2948 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002949 hlid = wlvif->ap.bcast_hlid;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002950 }
2951
Eliad Peller53d40d02011-10-10 10:13:02 +02002952 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002953 /*
2954 * We do not support removing keys after AP shutdown.
2955 * Pretend we do to make mac80211 happy.
2956 */
2957 if (action != KEY_ADD_OR_REPLACE)
2958 return 0;
2959
Eliad Peller170d0e62011-10-05 11:56:06 +02002960 ret = wl1271_record_ap_key(wl, wlvif, id,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002961 key_type, key_size,
2962 key, hlid, tx_seq_32,
2963 tx_seq_16);
2964 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002965 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002966 id, key_type, key_size,
2967 key, hlid, tx_seq_32,
2968 tx_seq_16);
2969 }
2970
2971 if (ret < 0)
2972 return ret;
2973 } else {
2974 const u8 *addr;
2975 static const u8 bcast_addr[ETH_ALEN] = {
2976 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2977 };
2978
Guy Eilame9eb8cb2011-08-16 19:49:12 +03002979 /*
2980 * A STA set to GEM cipher requires 2 tx spare blocks.
2981 * Return to default value when GEM cipher key is removed
2982 */
2983 if (key_type == KEY_GEM) {
2984 if (action == KEY_ADD_OR_REPLACE)
2985 wl->tx_spare_blocks = 2;
2986 else if (action == KEY_REMOVE)
2987 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2988 }
2989
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002990 addr = sta ? sta->addr : bcast_addr;
2991
2992 if (is_zero_ether_addr(addr)) {
2993 /* We dont support TX only encryption */
2994 return -EOPNOTSUPP;
2995 }
2996
2997 /* The wl1271 does not allow to remove unicast keys - they
2998 will be cleared automatically on next CMD_JOIN. Ignore the
2999 request silently, as we dont want the mac80211 to emit
3000 an error message. */
3001 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
3002 return 0;
3003
Eliad Peller010d3d32011-08-14 13:17:31 +03003004 /* don't remove key if hlid was already deleted */
3005 if (action == KEY_REMOVE &&
Eliad Peller154da672011-10-05 11:55:53 +02003006 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Peller010d3d32011-08-14 13:17:31 +03003007 return 0;
3008
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003009 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003010 id, key_type, key_size,
3011 key, addr, tx_seq_32,
3012 tx_seq_16);
3013 if (ret < 0)
3014 return ret;
3015
3016 /* the default WEP key needs to be configured at least once */
3017 if (key_type == KEY_WEP) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03003018 ret = wl12xx_cmd_set_default_wep_key(wl,
Eliad Pellerf75c753f2011-10-05 11:55:59 +02003019 wlvif->default_key,
3020 wlvif->sta.hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003021 if (ret < 0)
3022 return ret;
3023 }
3024 }
3025
3026 return 0;
3027}
3028
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003029static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3030 struct ieee80211_vif *vif,
3031 struct ieee80211_sta *sta,
3032 struct ieee80211_key_conf *key_conf)
3033{
3034 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003035 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003036 int ret;
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03003037 u32 tx_seq_32 = 0;
3038 u16 tx_seq_16 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003039 u8 key_type;
3040
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003041 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
3042
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003043 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003044 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Johannes Berg97359d12010-08-10 09:46:38 +02003045 key_conf->cipher, key_conf->keyidx,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003046 key_conf->keylen, key_conf->flags);
3047 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
3048
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003049 mutex_lock(&wl->mutex);
3050
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003051 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3052 ret = -EAGAIN;
3053 goto out_unlock;
3054 }
3055
Ido Yariva6208652011-03-01 15:14:41 +02003056 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003057 if (ret < 0)
3058 goto out_unlock;
3059
Johannes Berg97359d12010-08-10 09:46:38 +02003060 switch (key_conf->cipher) {
3061 case WLAN_CIPHER_SUITE_WEP40:
3062 case WLAN_CIPHER_SUITE_WEP104:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003063 key_type = KEY_WEP;
3064
3065 key_conf->hw_key_idx = key_conf->keyidx;
3066 break;
Johannes Berg97359d12010-08-10 09:46:38 +02003067 case WLAN_CIPHER_SUITE_TKIP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003068 key_type = KEY_TKIP;
3069
3070 key_conf->hw_key_idx = key_conf->keyidx;
Eliad Peller48e93e42011-10-10 10:12:58 +02003071 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3072 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003073 break;
Johannes Berg97359d12010-08-10 09:46:38 +02003074 case WLAN_CIPHER_SUITE_CCMP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003075 key_type = KEY_AES;
3076
Arik Nemtsov12d4b972011-10-23 08:21:54 +02003077 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Eliad Peller48e93e42011-10-10 10:12:58 +02003078 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3079 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003080 break;
Juuso Oikarinen7a557242010-09-27 12:42:07 +02003081 case WL1271_CIPHER_SUITE_GEM:
3082 key_type = KEY_GEM;
Eliad Peller48e93e42011-10-10 10:12:58 +02003083 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3084 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Juuso Oikarinen7a557242010-09-27 12:42:07 +02003085 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003086 default:
Johannes Berg97359d12010-08-10 09:46:38 +02003087 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003088
3089 ret = -EOPNOTSUPP;
3090 goto out_sleep;
3091 }
3092
3093 switch (cmd) {
3094 case SET_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003095 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003096 key_conf->keyidx, key_type,
3097 key_conf->keylen, key_conf->key,
3098 tx_seq_32, tx_seq_16, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003099 if (ret < 0) {
3100 wl1271_error("Could not add or replace key");
3101 goto out_sleep;
3102 }
Eliad Peller5ec8a442012-02-02 12:22:09 +02003103
3104 /*
3105 * reconfiguring arp response if the unicast (or common)
3106 * encryption key type was changed
3107 */
3108 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
3109 (sta || key_type == KEY_WEP) &&
3110 wlvif->encryption_type != key_type) {
3111 wlvif->encryption_type = key_type;
3112 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3113 if (ret < 0) {
3114 wl1271_warning("build arp rsp failed: %d", ret);
3115 goto out_sleep;
3116 }
3117 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003118 break;
3119
3120 case DISABLE_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003121 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003122 key_conf->keyidx, key_type,
3123 key_conf->keylen, key_conf->key,
3124 0, 0, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003125 if (ret < 0) {
3126 wl1271_error("Could not remove key");
3127 goto out_sleep;
3128 }
3129 break;
3130
3131 default:
3132 wl1271_error("Unsupported key cmd 0x%x", cmd);
3133 ret = -EOPNOTSUPP;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003134 break;
3135 }
3136
3137out_sleep:
3138 wl1271_ps_elp_sleep(wl);
3139
3140out_unlock:
3141 mutex_unlock(&wl->mutex);
3142
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003143 return ret;
3144}
3145
3146static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
Johannes Berga060bbf2010-04-27 11:59:34 +02003147 struct ieee80211_vif *vif,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003148 struct cfg80211_scan_request *req)
3149{
3150 struct wl1271 *wl = hw->priv;
Eliad Peller7edebf52011-10-05 11:55:52 +02003151 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3152
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003153 int ret;
3154 u8 *ssid = NULL;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003155 size_t len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003156
3157 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
3158
3159 if (req->n_ssids) {
3160 ssid = req->ssids[0].ssid;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003161 len = req->ssids[0].ssid_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003162 }
3163
3164 mutex_lock(&wl->mutex);
3165
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003166 if (wl->state == WL1271_STATE_OFF) {
3167 /*
3168 * We cannot return -EBUSY here because cfg80211 will expect
3169 * a call to ieee80211_scan_completed if we do - in this case
3170 * there won't be any call.
3171 */
3172 ret = -EAGAIN;
3173 goto out;
3174 }
3175
Ido Yariva6208652011-03-01 15:14:41 +02003176 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003177 if (ret < 0)
3178 goto out;
3179
Eliad Peller92e712d2011-12-18 20:25:43 +02003180 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
3181 test_bit(wlvif->role_id, wl->roc_map)) {
3182 /* don't allow scanning right now */
3183 ret = -EBUSY;
3184 goto out_sleep;
Eliad Peller251c1772011-08-14 13:17:17 +03003185 }
3186
Eliad Peller784f6942011-10-05 11:55:39 +02003187 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
Eliad Peller251c1772011-08-14 13:17:17 +03003188out_sleep:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003189 wl1271_ps_elp_sleep(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003190out:
3191 mutex_unlock(&wl->mutex);
3192
3193 return ret;
3194}
3195
Eliad Peller73ecce32011-06-27 13:06:45 +03003196static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3197 struct ieee80211_vif *vif)
3198{
3199 struct wl1271 *wl = hw->priv;
3200 int ret;
3201
3202 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3203
3204 mutex_lock(&wl->mutex);
3205
3206 if (wl->state == WL1271_STATE_OFF)
3207 goto out;
3208
3209 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3210 goto out;
3211
3212 ret = wl1271_ps_elp_wakeup(wl);
3213 if (ret < 0)
3214 goto out;
3215
3216 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3217 ret = wl1271_scan_stop(wl);
3218 if (ret < 0)
3219 goto out_sleep;
3220 }
3221 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3222 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02003223 wl->scan_vif = NULL;
Eliad Peller73ecce32011-06-27 13:06:45 +03003224 wl->scan.req = NULL;
3225 ieee80211_scan_completed(wl->hw, true);
3226
3227out_sleep:
3228 wl1271_ps_elp_sleep(wl);
3229out:
3230 mutex_unlock(&wl->mutex);
3231
3232 cancel_delayed_work_sync(&wl->scan_complete_work);
3233}
3234
Luciano Coelho33c2c062011-05-10 14:46:02 +03003235static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3236 struct ieee80211_vif *vif,
3237 struct cfg80211_sched_scan_request *req,
3238 struct ieee80211_sched_scan_ies *ies)
3239{
3240 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003241 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003242 int ret;
3243
3244 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3245
3246 mutex_lock(&wl->mutex);
3247
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003248 if (wl->state == WL1271_STATE_OFF) {
3249 ret = -EAGAIN;
3250 goto out;
3251 }
3252
Luciano Coelho33c2c062011-05-10 14:46:02 +03003253 ret = wl1271_ps_elp_wakeup(wl);
3254 if (ret < 0)
3255 goto out;
3256
Eliad Peller536129c2011-10-05 11:55:45 +02003257 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003258 if (ret < 0)
3259 goto out_sleep;
3260
Eliad Peller536129c2011-10-05 11:55:45 +02003261 ret = wl1271_scan_sched_scan_start(wl, wlvif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003262 if (ret < 0)
3263 goto out_sleep;
3264
3265 wl->sched_scanning = true;
3266
3267out_sleep:
3268 wl1271_ps_elp_sleep(wl);
3269out:
3270 mutex_unlock(&wl->mutex);
3271 return ret;
3272}
3273
3274static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3275 struct ieee80211_vif *vif)
3276{
3277 struct wl1271 *wl = hw->priv;
3278 int ret;
3279
3280 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3281
3282 mutex_lock(&wl->mutex);
3283
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003284 if (wl->state == WL1271_STATE_OFF)
3285 goto out;
3286
Luciano Coelho33c2c062011-05-10 14:46:02 +03003287 ret = wl1271_ps_elp_wakeup(wl);
3288 if (ret < 0)
3289 goto out;
3290
3291 wl1271_scan_sched_scan_stop(wl);
3292
3293 wl1271_ps_elp_sleep(wl);
3294out:
3295 mutex_unlock(&wl->mutex);
3296}
3297
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003298static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3299{
3300 struct wl1271 *wl = hw->priv;
3301 int ret = 0;
3302
3303 mutex_lock(&wl->mutex);
3304
3305 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3306 ret = -EAGAIN;
3307 goto out;
3308 }
3309
Ido Yariva6208652011-03-01 15:14:41 +02003310 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003311 if (ret < 0)
3312 goto out;
3313
Arik Nemtsov5f704d12011-04-18 14:15:21 +03003314 ret = wl1271_acx_frag_threshold(wl, value);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003315 if (ret < 0)
3316 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3317
3318 wl1271_ps_elp_sleep(wl);
3319
3320out:
3321 mutex_unlock(&wl->mutex);
3322
3323 return ret;
3324}
3325
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003326static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3327{
3328 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02003329 struct wl12xx_vif *wlvif;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003330 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003331
3332 mutex_lock(&wl->mutex);
3333
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003334 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3335 ret = -EAGAIN;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003336 goto out;
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003337 }
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003338
Ido Yariva6208652011-03-01 15:14:41 +02003339 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003340 if (ret < 0)
3341 goto out;
3342
Eliad Peller6e8cd332011-10-10 10:13:13 +02003343 wl12xx_for_each_wlvif(wl, wlvif) {
3344 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3345 if (ret < 0)
3346 wl1271_warning("set rts threshold failed: %d", ret);
3347 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003348 wl1271_ps_elp_sleep(wl);
3349
3350out:
3351 mutex_unlock(&wl->mutex);
3352
3353 return ret;
3354}
3355
Eliad Peller1fe9f162011-10-05 11:55:48 +02003356static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003357 int offset)
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003358{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003359 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller889cb362011-05-01 09:56:45 +03003360 u8 ssid_len;
3361 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3362 skb->len - offset);
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003363
Eliad Peller889cb362011-05-01 09:56:45 +03003364 if (!ptr) {
3365 wl1271_error("No SSID in IEs!");
3366 return -ENOENT;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003367 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003368
Eliad Peller889cb362011-05-01 09:56:45 +03003369 ssid_len = ptr[1];
3370 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3371 wl1271_error("SSID is too long!");
3372 return -EINVAL;
3373 }
3374
Eliad Peller1fe9f162011-10-05 11:55:48 +02003375 wlvif->ssid_len = ssid_len;
3376 memcpy(wlvif->ssid, ptr+2, ssid_len);
Eliad Peller889cb362011-05-01 09:56:45 +03003377 return 0;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003378}
3379
Eliad Pellerd48055d2011-09-15 12:07:04 +03003380static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3381{
3382 int len;
3383 const u8 *next, *end = skb->data + skb->len;
3384 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3385 skb->len - ieoffset);
3386 if (!ie)
3387 return;
3388 len = ie[1] + 2;
3389 next = ie + len;
3390 memmove(ie, next, end - next);
3391 skb_trim(skb, skb->len - len);
3392}
3393
Eliad Peller26b4bf22011-09-15 12:07:05 +03003394static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3395 unsigned int oui, u8 oui_type,
3396 int ieoffset)
3397{
3398 int len;
3399 const u8 *next, *end = skb->data + skb->len;
3400 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3401 skb->data + ieoffset,
3402 skb->len - ieoffset);
3403 if (!ie)
3404 return;
3405 len = ie[1] + 2;
3406 next = ie + len;
3407 memmove(ie, next, end - next);
3408 skb_trim(skb, skb->len - len);
3409}
3410
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003411static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3412 struct ieee80211_vif *vif)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003413{
Eliad Pellercdaac622012-01-31 11:57:16 +02003414 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003415 struct sk_buff *skb;
3416 int ret;
3417
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003418 skb = ieee80211_proberesp_get(wl->hw, vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003419 if (!skb)
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003420 return -EOPNOTSUPP;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003421
Eliad Pellercdaac622012-01-31 11:57:16 +02003422 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov560f0022011-11-08 18:46:54 +02003423 CMD_TEMPL_AP_PROBE_RESPONSE,
3424 skb->data,
3425 skb->len, 0,
3426 rates);
3427
3428 dev_kfree_skb(skb);
3429 return ret;
3430}
3431
3432static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3433 struct ieee80211_vif *vif,
3434 u8 *probe_rsp_data,
3435 size_t probe_rsp_len,
3436 u32 rates)
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003437{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003438 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3439 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003440 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3441 int ssid_ie_offset, ie_offset, templ_len;
3442 const u8 *ptr;
3443
3444 /* no need to change probe response if the SSID is set correctly */
Eliad Peller1fe9f162011-10-05 11:55:48 +02003445 if (wlvif->ssid_len > 0)
Eliad Pellercdaac622012-01-31 11:57:16 +02003446 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003447 CMD_TEMPL_AP_PROBE_RESPONSE,
3448 probe_rsp_data,
3449 probe_rsp_len, 0,
3450 rates);
3451
3452 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3453 wl1271_error("probe_rsp template too big");
3454 return -EINVAL;
3455 }
3456
3457 /* start searching from IE offset */
3458 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3459
3460 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3461 probe_rsp_len - ie_offset);
3462 if (!ptr) {
3463 wl1271_error("No SSID in beacon!");
3464 return -EINVAL;
3465 }
3466
3467 ssid_ie_offset = ptr - probe_rsp_data;
3468 ptr += (ptr[1] + 2);
3469
3470 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3471
3472 /* insert SSID from bss_conf */
3473 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3474 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3475 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3476 bss_conf->ssid, bss_conf->ssid_len);
3477 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3478
3479 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3480 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3481 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3482
Eliad Pellercdaac622012-01-31 11:57:16 +02003483 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003484 CMD_TEMPL_AP_PROBE_RESPONSE,
3485 probe_rsp_templ,
3486 templ_len, 0,
3487 rates);
3488}
3489
Arik Nemtsove78a2872010-10-16 19:07:21 +02003490static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
Eliad Peller0603d892011-10-05 11:55:51 +02003491 struct ieee80211_vif *vif,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003492 struct ieee80211_bss_conf *bss_conf,
3493 u32 changed)
3494{
Eliad Peller0603d892011-10-05 11:55:51 +02003495 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003496 int ret = 0;
3497
3498 if (changed & BSS_CHANGED_ERP_SLOT) {
3499 if (bss_conf->use_short_slot)
Eliad Peller0603d892011-10-05 11:55:51 +02003500 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003501 else
Eliad Peller0603d892011-10-05 11:55:51 +02003502 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003503 if (ret < 0) {
3504 wl1271_warning("Set slot time failed %d", ret);
3505 goto out;
3506 }
3507 }
3508
3509 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3510 if (bss_conf->use_short_preamble)
Eliad Peller0603d892011-10-05 11:55:51 +02003511 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003512 else
Eliad Peller0603d892011-10-05 11:55:51 +02003513 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003514 }
3515
3516 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3517 if (bss_conf->use_cts_prot)
Eliad Peller0603d892011-10-05 11:55:51 +02003518 ret = wl1271_acx_cts_protect(wl, wlvif,
3519 CTSPROTECT_ENABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003520 else
Eliad Peller0603d892011-10-05 11:55:51 +02003521 ret = wl1271_acx_cts_protect(wl, wlvif,
3522 CTSPROTECT_DISABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003523 if (ret < 0) {
3524 wl1271_warning("Set ctsprotect failed %d", ret);
3525 goto out;
3526 }
3527 }
3528
3529out:
3530 return ret;
3531}
3532
3533static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3534 struct ieee80211_vif *vif,
3535 struct ieee80211_bss_conf *bss_conf,
3536 u32 changed)
3537{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003538 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller536129c2011-10-05 11:55:45 +02003539 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003540 int ret = 0;
3541
3542 if ((changed & BSS_CHANGED_BEACON_INT)) {
3543 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3544 bss_conf->beacon_int);
3545
Eliad Peller6a899792011-10-05 11:55:58 +02003546 wlvif->beacon_int = bss_conf->beacon_int;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003547 }
3548
Arik Nemtsov560f0022011-11-08 18:46:54 +02003549 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3550 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003551 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3552 wl1271_debug(DEBUG_AP, "probe response updated");
3553 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3554 }
Arik Nemtsov560f0022011-11-08 18:46:54 +02003555 }
3556
Arik Nemtsove78a2872010-10-16 19:07:21 +02003557 if ((changed & BSS_CHANGED_BEACON)) {
3558 struct ieee80211_hdr *hdr;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003559 u32 min_rate;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003560 int ieoffset = offsetof(struct ieee80211_mgmt,
3561 u.beacon.variable);
3562 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3563 u16 tmpl_id;
3564
Arik Nemtsov560f0022011-11-08 18:46:54 +02003565 if (!beacon) {
3566 ret = -EINVAL;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003567 goto out;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003568 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003569
3570 wl1271_debug(DEBUG_MASTER, "beacon updated");
3571
Eliad Peller1fe9f162011-10-05 11:55:48 +02003572 ret = wl1271_ssid_set(vif, beacon, ieoffset);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003573 if (ret < 0) {
3574 dev_kfree_skb(beacon);
3575 goto out;
3576 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02003577 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003578 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3579 CMD_TEMPL_BEACON;
Eliad Pellercdaac622012-01-31 11:57:16 +02003580 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003581 beacon->data,
3582 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003583 min_rate);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003584 if (ret < 0) {
3585 dev_kfree_skb(beacon);
3586 goto out;
3587 }
3588
Arik Nemtsov560f0022011-11-08 18:46:54 +02003589 /*
3590 * In case we already have a probe-resp beacon set explicitly
3591 * by usermode, don't use the beacon data.
3592 */
3593 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3594 goto end_bcn;
3595
Eliad Pellerd48055d2011-09-15 12:07:04 +03003596 /* remove TIM ie from probe response */
3597 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3598
Eliad Peller26b4bf22011-09-15 12:07:05 +03003599 /*
3600 * remove p2p ie from probe response.
3601 * the fw reponds to probe requests that don't include
3602 * the p2p ie. probe requests with p2p ie will be passed,
3603 * and will be responded by the supplicant (the spec
3604 * forbids including the p2p ie when responding to probe
3605 * requests that didn't include it).
3606 */
3607 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3608 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3609
Arik Nemtsove78a2872010-10-16 19:07:21 +02003610 hdr = (struct ieee80211_hdr *) beacon->data;
3611 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3612 IEEE80211_STYPE_PROBE_RESP);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003613 if (is_ap)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003614 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003615 beacon->data,
3616 beacon->len,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003617 min_rate);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003618 else
Eliad Pellercdaac622012-01-31 11:57:16 +02003619 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003620 CMD_TEMPL_PROBE_RESPONSE,
3621 beacon->data,
3622 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003623 min_rate);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003624end_bcn:
Arik Nemtsove78a2872010-10-16 19:07:21 +02003625 dev_kfree_skb(beacon);
3626 if (ret < 0)
3627 goto out;
3628 }
3629
3630out:
Arik Nemtsov560f0022011-11-08 18:46:54 +02003631 if (ret != 0)
3632 wl1271_error("beacon info change failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003633 return ret;
3634}
3635
3636/* AP mode changes */
3637static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003638 struct ieee80211_vif *vif,
3639 struct ieee80211_bss_conf *bss_conf,
3640 u32 changed)
3641{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003642 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003643 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003644
Arik Nemtsove78a2872010-10-16 19:07:21 +02003645 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3646 u32 rates = bss_conf->basic_rates;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003647
Eliad Peller87fbcb02011-10-05 11:55:41 +02003648 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003649 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003650 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
Eliad Peller87fbcb02011-10-05 11:55:41 +02003651 wlvif->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003652
Eliad Peller87fbcb02011-10-05 11:55:41 +02003653 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003654 if (ret < 0) {
Arik Nemtsov70f47422011-04-18 14:15:25 +03003655 wl1271_error("AP rate policy change failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003656 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003657 }
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003658
Eliad Peller784f6942011-10-05 11:55:39 +02003659 ret = wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003660 if (ret < 0)
3661 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003662 }
3663
Arik Nemtsove78a2872010-10-16 19:07:21 +02003664 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3665 if (ret < 0)
3666 goto out;
3667
3668 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3669 if (bss_conf->enable_beacon) {
Eliad Peller53d40d02011-10-10 10:13:02 +02003670 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003671 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003672 if (ret < 0)
3673 goto out;
3674
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003675 ret = wl1271_ap_init_hwenc(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003676 if (ret < 0)
3677 goto out;
Arik Nemtsovcf420392011-08-14 13:17:37 +03003678
Eliad Peller53d40d02011-10-10 10:13:02 +02003679 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsovcf420392011-08-14 13:17:37 +03003680 wl1271_debug(DEBUG_AP, "started AP");
Arik Nemtsove78a2872010-10-16 19:07:21 +02003681 }
3682 } else {
Eliad Peller53d40d02011-10-10 10:13:02 +02003683 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003684 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003685 if (ret < 0)
3686 goto out;
3687
Eliad Peller53d40d02011-10-10 10:13:02 +02003688 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003689 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3690 &wlvif->flags);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003691 wl1271_debug(DEBUG_AP, "stopped AP");
3692 }
3693 }
3694 }
3695
Eliad Peller0603d892011-10-05 11:55:51 +02003696 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003697 if (ret < 0)
3698 goto out;
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003699
3700 /* Handle HT information change */
3701 if ((changed & BSS_CHANGED_HT) &&
3702 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003703 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003704 bss_conf->ht_operation_mode);
3705 if (ret < 0) {
3706 wl1271_warning("Set ht information failed %d", ret);
3707 goto out;
3708 }
3709 }
3710
Arik Nemtsove78a2872010-10-16 19:07:21 +02003711out:
3712 return;
3713}
3714
3715/* STA/IBSS mode changes */
3716static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3717 struct ieee80211_vif *vif,
3718 struct ieee80211_bss_conf *bss_conf,
3719 u32 changed)
3720{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003721 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003722 bool do_join = false, set_assoc = false;
Eliad Peller536129c2011-10-05 11:55:45 +02003723 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Eliad Peller227e81e2011-08-14 13:17:26 +03003724 bool ibss_joined = false;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003725 u32 sta_rate_set = 0;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003726 int ret;
Luciano Coelho2d6e4e762011-01-11 19:07:21 +01003727 struct ieee80211_sta *sta;
Arik Nemtsova1008852011-02-12 23:24:20 +02003728 bool sta_exists = false;
3729 struct ieee80211_sta_ht_cap sta_ht_cap;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003730
3731 if (is_ibss) {
3732 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3733 changed);
3734 if (ret < 0)
3735 goto out;
3736 }
3737
Eliad Peller227e81e2011-08-14 13:17:26 +03003738 if (changed & BSS_CHANGED_IBSS) {
3739 if (bss_conf->ibss_joined) {
Eliad Pellereee514e2011-10-10 10:13:01 +02003740 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
Eliad Peller227e81e2011-08-14 13:17:26 +03003741 ibss_joined = true;
3742 } else {
Eliad Pellereee514e2011-10-10 10:13:01 +02003743 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3744 &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003745 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003746 wl12xx_start_dev(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03003747 }
3748 }
3749 }
3750
3751 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003752 do_join = true;
3753
3754 /* Need to update the SSID (for filtering etc) */
Eliad Peller227e81e2011-08-14 13:17:26 +03003755 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003756 do_join = true;
3757
Eliad Peller227e81e2011-08-14 13:17:26 +03003758 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003759 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3760 bss_conf->enable_beacon ? "enabled" : "disabled");
3761
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003762 do_join = true;
3763 }
3764
Eliad Pellerc31e4942011-10-23 08:21:55 +02003765 if (changed & BSS_CHANGED_IDLE) {
3766 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3767 if (ret < 0)
3768 wl1271_warning("idle mode change failed %d", ret);
3769 }
3770
Arik Nemtsove78a2872010-10-16 19:07:21 +02003771 if ((changed & BSS_CHANGED_CQM)) {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003772 bool enable = false;
3773 if (bss_conf->cqm_rssi_thold)
3774 enable = true;
Eliad Peller0603d892011-10-05 11:55:51 +02003775 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003776 bss_conf->cqm_rssi_thold,
3777 bss_conf->cqm_rssi_hyst);
3778 if (ret < 0)
3779 goto out;
Eliad Peller04324d92011-10-05 11:56:03 +02003780 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003781 }
3782
Eliad Peller7db4ee62012-01-24 18:18:42 +02003783 if (changed & BSS_CHANGED_BSSID &&
3784 (is_ibss || bss_conf->assoc))
Eliad Pellercdf09492011-10-05 11:55:44 +02003785 if (!is_zero_ether_addr(bss_conf->bssid)) {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003786 ret = wl12xx_cmd_build_null_data(wl, wlvif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003787 if (ret < 0)
3788 goto out;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003789
Eliad Peller784f6942011-10-05 11:55:39 +02003790 ret = wl1271_build_qos_null_data(wl, vif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003791 if (ret < 0)
3792 goto out;
Saravanan Dhanabal141418c2010-04-28 09:50:00 +03003793
Eliad Pellerfa287b82010-12-26 09:27:50 +01003794 /* Need to update the BSSID (for filtering etc) */
3795 do_join = true;
3796 }
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003797
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003798 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3799 rcu_read_lock();
3800 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3801 if (!sta)
3802 goto sta_not_found;
3803
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003804 /* save the supp_rates of the ap */
3805 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3806 if (sta->ht_cap.ht_supported)
3807 sta_rate_set |=
3808 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
Arik Nemtsova1008852011-02-12 23:24:20 +02003809 sta_ht_cap = sta->ht_cap;
3810 sta_exists = true;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003811
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003812sta_not_found:
3813 rcu_read_unlock();
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003814 }
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003815
Arik Nemtsove78a2872010-10-16 19:07:21 +02003816 if ((changed & BSS_CHANGED_ASSOC)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003817 if (bss_conf->assoc) {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003818 u32 rates;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003819 int ieoffset;
Eliad Peller6840e372011-10-05 11:55:50 +02003820 wlvif->aid = bss_conf->aid;
Juuso Oikarinen69e54342010-05-07 11:39:00 +03003821 set_assoc = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003822
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003823 /*
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003824 * use basic rates from AP, and determine lowest rate
3825 * to use with control frames.
3826 */
3827 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003828 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003829 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003830 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003831 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003832 wl1271_tx_min_rate_get(wl,
3833 wlvif->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003834 if (sta_rate_set)
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003835 wlvif->rate_set =
3836 wl1271_tx_enabled_rates_get(wl,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003837 sta_rate_set,
Eliad Peller1b92f152011-10-10 10:13:09 +02003838 wlvif->band);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003839 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003840 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003841 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003842
3843 /*
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003844 * with wl1271, we don't need to update the
3845 * beacon_int and dtim_period, because the firmware
3846 * updates it by itself when the first beacon is
3847 * received after a join.
3848 */
Eliad Peller6840e372011-10-05 11:55:50 +02003849 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003850 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003851 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003852
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003853 /*
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003854 * Get a template for hardware connection maintenance
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003855 */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003856 dev_kfree_skb(wlvif->probereq);
3857 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
Eliad Peller83587502011-10-10 10:12:53 +02003858 wlvif,
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003859 NULL);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003860 ieoffset = offsetof(struct ieee80211_mgmt,
3861 u.probe_req.variable);
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003862 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003863
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003864 /* enable the connection monitoring feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003865 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003866 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003867 goto out;
Juuso Oikarinend94cd292009-10-08 21:56:25 +03003868 } else {
3869 /* use defaults when not associated */
Eliad Peller30df14d2011-04-05 19:13:28 +03003870 bool was_assoc =
Eliad Pellerba8447f2011-10-10 10:13:00 +02003871 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3872 &wlvif->flags);
Eliad Peller251c1772011-08-14 13:17:17 +03003873 bool was_ifup =
Eliad Peller8181aec2011-10-10 10:13:04 +02003874 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3875 &wlvif->flags);
Eliad Peller6840e372011-10-05 11:55:50 +02003876 wlvif->aid = 0;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003877
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003878 /* free probe-request template */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003879 dev_kfree_skb(wlvif->probereq);
3880 wlvif->probereq = NULL;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003881
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003882 /* revert back to minimum rates for the current band */
Eliad Peller87fbcb02011-10-05 11:55:41 +02003883 wl1271_set_band_rate(wl, wlvif);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003884 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003885 wl1271_tx_min_rate_get(wl,
3886 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003887 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003888 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003889 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003890
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003891 /* disable connection monitor features */
Eliad Peller0603d892011-10-05 11:55:51 +02003892 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003893
3894 /* Disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003895 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003896 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003897 goto out;
Juuso Oikarinenb84a7d32010-11-22 12:59:08 +02003898
3899 /* restore the bssid filter and go to dummy bssid */
Eliad Peller30df14d2011-04-05 19:13:28 +03003900 if (was_assoc) {
Eliad Peller251c1772011-08-14 13:17:17 +03003901 u32 conf_flags = wl->hw->conf.flags;
3902 /*
3903 * we might have to disable roc, if there was
3904 * no IF_OPER_UP notification.
3905 */
3906 if (!was_ifup) {
Eliad Peller0603d892011-10-05 11:55:51 +02003907 ret = wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003908 if (ret < 0)
3909 goto out;
3910 }
3911 /*
3912 * (we also need to disable roc in case of
3913 * roaming on the same channel. until we will
3914 * have a better flow...)
3915 */
Eliad Peller7edebf52011-10-05 11:55:52 +02003916 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3917 ret = wl12xx_croc(wl,
3918 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003919 if (ret < 0)
3920 goto out;
3921 }
3922
Eliad Peller0603d892011-10-05 11:55:51 +02003923 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003924 if (!(conf_flags & IEEE80211_CONF_IDLE))
3925 wl12xx_start_dev(wl, wlvif);
Eliad Peller30df14d2011-04-05 19:13:28 +03003926 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003927 }
3928 }
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03003929
Eliad Pellerd192d262011-05-24 14:33:08 +03003930 if (changed & BSS_CHANGED_IBSS) {
3931 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3932 bss_conf->ibss_joined);
3933
3934 if (bss_conf->ibss_joined) {
3935 u32 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003936 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003937 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003938 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003939 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003940 wl1271_tx_min_rate_get(wl,
3941 wlvif->basic_rate_set);
Eliad Pellerd192d262011-05-24 14:33:08 +03003942
Shahar Levi06b660e2011-09-05 13:54:36 +03003943 /* by default, use 11b + OFDM rates */
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003944 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3945 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Eliad Pellerd192d262011-05-24 14:33:08 +03003946 if (ret < 0)
3947 goto out;
3948 }
3949 }
3950
Eliad Peller0603d892011-10-05 11:55:51 +02003951 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003952 if (ret < 0)
3953 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003954
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003955 if (do_join) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003956 ret = wl1271_join(wl, wlvif, set_assoc);
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003957 if (ret < 0) {
3958 wl1271_warning("cmd join failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003959 goto out;
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003960 }
Eliad Peller251c1772011-08-14 13:17:17 +03003961
3962 /* ROC until connected (after EAPOL exchange) */
3963 if (!is_ibss) {
Eliad Peller1b92f152011-10-10 10:13:09 +02003964 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003965 if (ret < 0)
3966 goto out;
3967
Eliad Pellerba8447f2011-10-10 10:13:00 +02003968 wl1271_check_operstate(wl, wlvif,
Eliad Peller251c1772011-08-14 13:17:17 +03003969 ieee80211_get_operstate(vif));
3970 }
3971 /*
3972 * stop device role if started (we might already be in
Eliad Peller92e712d2011-12-18 20:25:43 +02003973 * STA/IBSS role).
Eliad Peller251c1772011-08-14 13:17:17 +03003974 */
Eliad Peller92e712d2011-12-18 20:25:43 +02003975 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02003976 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003977 if (ret < 0)
3978 goto out;
3979 }
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003980 }
3981
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003982 /* Handle new association with HT. Do this after join. */
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003983 if (sta_exists) {
3984 if ((changed & BSS_CHANGED_HT) &&
3985 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003986 ret = wl1271_acx_set_ht_capabilities(wl,
3987 &sta_ht_cap,
3988 true,
Eliad Peller154da672011-10-05 11:55:53 +02003989 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003990 if (ret < 0) {
3991 wl1271_warning("Set ht cap true failed %d",
3992 ret);
3993 goto out;
3994 }
3995 }
3996 /* handle new association without HT and disassociation */
3997 else if (changed & BSS_CHANGED_ASSOC) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003998 ret = wl1271_acx_set_ht_capabilities(wl,
3999 &sta_ht_cap,
4000 false,
Eliad Peller154da672011-10-05 11:55:53 +02004001 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004002 if (ret < 0) {
4003 wl1271_warning("Set ht cap false failed %d",
4004 ret);
4005 goto out;
4006 }
4007 }
4008 }
4009
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03004010 /* Handle HT information change. Done after join. */
4011 if ((changed & BSS_CHANGED_HT) &&
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004012 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02004013 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004014 bss_conf->ht_operation_mode);
4015 if (ret < 0) {
4016 wl1271_warning("Set ht information failed %d", ret);
4017 goto out;
4018 }
4019 }
4020
Eliad Peller76a74c82012-02-02 12:22:11 +02004021 /* Handle arp filtering. Done after join. */
4022 if ((changed & BSS_CHANGED_ARP_FILTER) ||
4023 (!is_ibss && (changed & BSS_CHANGED_QOS))) {
4024 __be32 addr = bss_conf->arp_addr_list[0];
4025 wlvif->sta.qos = bss_conf->qos;
4026 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
4027
4028 if (bss_conf->arp_addr_cnt == 1 &&
4029 bss_conf->arp_filter_enabled) {
4030 wlvif->ip_addr = addr;
4031 /*
4032 * The template should have been configured only upon
4033 * association. however, it seems that the correct ip
4034 * isn't being set (when sending), so we have to
4035 * reconfigure the template upon every ip change.
4036 */
4037 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
4038 if (ret < 0) {
4039 wl1271_warning("build arp rsp failed: %d", ret);
4040 goto out;
4041 }
4042
4043 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
4044 (ACX_ARP_FILTER_ARP_FILTERING |
4045 ACX_ARP_FILTER_AUTO_ARP),
4046 addr);
4047 } else {
4048 wlvif->ip_addr = 0;
4049 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
4050 }
4051
4052 if (ret < 0)
4053 goto out;
4054 }
4055
Arik Nemtsove78a2872010-10-16 19:07:21 +02004056out:
4057 return;
4058}
4059
4060static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
4061 struct ieee80211_vif *vif,
4062 struct ieee80211_bss_conf *bss_conf,
4063 u32 changed)
4064{
4065 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004066 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4067 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02004068 int ret;
4069
4070 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
4071 (int)changed);
4072
4073 mutex_lock(&wl->mutex);
4074
4075 if (unlikely(wl->state == WL1271_STATE_OFF))
4076 goto out;
4077
Eliad Peller10c8cd02011-10-10 10:13:06 +02004078 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
4079 goto out;
4080
Ido Yariva6208652011-03-01 15:14:41 +02004081 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsove78a2872010-10-16 19:07:21 +02004082 if (ret < 0)
4083 goto out;
4084
4085 if (is_ap)
4086 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
4087 else
4088 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
4089
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004090 wl1271_ps_elp_sleep(wl);
4091
4092out:
4093 mutex_unlock(&wl->mutex);
4094}
4095
Eliad Peller8a3a3c82011-10-02 10:15:52 +02004096static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
4097 struct ieee80211_vif *vif, u16 queue,
Kalle Valoc6999d82010-02-18 13:25:41 +02004098 const struct ieee80211_tx_queue_params *params)
4099{
4100 struct wl1271 *wl = hw->priv;
Eliad Peller0603d892011-10-05 11:55:51 +02004101 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo4695dc92010-03-18 12:26:38 +02004102 u8 ps_scheme;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004103 int ret = 0;
Kalle Valoc6999d82010-02-18 13:25:41 +02004104
4105 mutex_lock(&wl->mutex);
4106
4107 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
4108
Kalle Valo4695dc92010-03-18 12:26:38 +02004109 if (params->uapsd)
4110 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
4111 else
4112 ps_scheme = CONF_PS_SCHEME_LEGACY;
4113
Eliad Peller5b37ddf2011-12-18 20:25:40 +02004114 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004115 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004116
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004117 ret = wl1271_ps_elp_wakeup(wl);
4118 if (ret < 0)
4119 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004120
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004121 /*
4122 * the txop is confed in units of 32us by the mac80211,
4123 * we need us
4124 */
Eliad Peller0603d892011-10-05 11:55:51 +02004125 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004126 params->cw_min, params->cw_max,
4127 params->aifs, params->txop << 5);
4128 if (ret < 0)
4129 goto out_sleep;
4130
Eliad Peller0603d892011-10-05 11:55:51 +02004131 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004132 CONF_CHANNEL_TYPE_EDCF,
4133 wl1271_tx_get_queue(queue),
4134 ps_scheme, CONF_ACK_POLICY_LEGACY,
4135 0, 0);
Kalle Valoc82c1dd2010-02-18 13:25:47 +02004136
4137out_sleep:
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004138 wl1271_ps_elp_sleep(wl);
Kalle Valoc6999d82010-02-18 13:25:41 +02004139
4140out:
4141 mutex_unlock(&wl->mutex);
4142
4143 return ret;
4144}
4145
Eliad Peller37a41b42011-09-21 14:06:11 +03004146static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
4147 struct ieee80211_vif *vif)
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004148{
4149
4150 struct wl1271 *wl = hw->priv;
Eliad Peller9c531142012-01-31 11:57:18 +02004151 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004152 u64 mactime = ULLONG_MAX;
4153 int ret;
4154
4155 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
4156
4157 mutex_lock(&wl->mutex);
4158
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02004159 if (unlikely(wl->state == WL1271_STATE_OFF))
4160 goto out;
4161
Ido Yariva6208652011-03-01 15:14:41 +02004162 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004163 if (ret < 0)
4164 goto out;
4165
Eliad Peller9c531142012-01-31 11:57:18 +02004166 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004167 if (ret < 0)
4168 goto out_sleep;
4169
4170out_sleep:
4171 wl1271_ps_elp_sleep(wl);
4172
4173out:
4174 mutex_unlock(&wl->mutex);
4175 return mactime;
4176}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004177
John W. Linvilleece550d2010-07-28 16:41:06 -04004178static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
4179 struct survey_info *survey)
4180{
4181 struct wl1271 *wl = hw->priv;
4182 struct ieee80211_conf *conf = &hw->conf;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004183
John W. Linvilleece550d2010-07-28 16:41:06 -04004184 if (idx != 0)
4185 return -ENOENT;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004186
John W. Linvilleece550d2010-07-28 16:41:06 -04004187 survey->channel = conf->channel;
4188 survey->filled = SURVEY_INFO_NOISE_DBM;
4189 survey->noise = wl->noise;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004190
John W. Linvilleece550d2010-07-28 16:41:06 -04004191 return 0;
4192}
4193
Arik Nemtsov409622e2011-02-23 00:22:29 +02004194static int wl1271_allocate_sta(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004195 struct wl12xx_vif *wlvif,
4196 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004197{
4198 struct wl1271_station *wl_sta;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004199 int ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004200
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004201
4202 if (wl->active_sta_count >= AP_MAX_STATIONS) {
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004203 wl1271_warning("could not allocate HLID - too much stations");
4204 return -EBUSY;
4205 }
4206
4207 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004208 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4209 if (ret < 0) {
4210 wl1271_warning("could not allocate HLID - too many links");
4211 return -EBUSY;
4212 }
4213
4214 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004215 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
Arik Nemtsovda032092011-08-25 12:43:15 +03004216 wl->active_sta_count++;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004217 return 0;
4218}
4219
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004220void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004221{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004222 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
Arik Nemtsovf1acea92011-08-25 12:43:17 +03004223 return;
4224
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004225 clear_bit(hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004226 memset(wl->links[hlid].addr, 0, ETH_ALEN);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004227 wl->links[hlid].ba_bitmap = 0;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02004228 wl1271_tx_reset_link_queues(wl, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004229 __clear_bit(hlid, &wl->ap_ps_map);
4230 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004231 wl12xx_free_link(wl, wlvif, &hlid);
Arik Nemtsovda032092011-08-25 12:43:15 +03004232 wl->active_sta_count--;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004233}
4234
4235static int wl1271_op_sta_add(struct ieee80211_hw *hw,
4236 struct ieee80211_vif *vif,
4237 struct ieee80211_sta *sta)
4238{
4239 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004240 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004241 struct wl1271_station *wl_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004242 int ret = 0;
4243 u8 hlid;
4244
4245 mutex_lock(&wl->mutex);
4246
4247 if (unlikely(wl->state == WL1271_STATE_OFF))
4248 goto out;
4249
Eliad Peller536129c2011-10-05 11:55:45 +02004250 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004251 goto out;
4252
4253 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4254
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004255 ret = wl1271_allocate_sta(wl, wlvif, sta);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004256 if (ret < 0)
4257 goto out;
4258
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004259 wl_sta = (struct wl1271_station *)sta->drv_priv;
4260 hlid = wl_sta->hlid;
4261
Ido Yariva6208652011-03-01 15:14:41 +02004262 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004263 if (ret < 0)
Arik Nemtsov409622e2011-02-23 00:22:29 +02004264 goto out_free_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004265
Eliad Peller1b92f152011-10-10 10:13:09 +02004266 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004267 if (ret < 0)
4268 goto out_sleep;
4269
Eliad Pellerb67476e2011-08-14 13:17:23 +03004270 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4271 if (ret < 0)
4272 goto out_sleep;
4273
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03004274 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, hlid);
4275 if (ret < 0)
4276 goto out_sleep;
4277
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004278out_sleep:
4279 wl1271_ps_elp_sleep(wl);
4280
Arik Nemtsov409622e2011-02-23 00:22:29 +02004281out_free_sta:
4282 if (ret < 0)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004283 wl1271_free_sta(wl, wlvif, hlid);
Arik Nemtsov409622e2011-02-23 00:22:29 +02004284
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004285out:
4286 mutex_unlock(&wl->mutex);
4287 return ret;
4288}
4289
4290static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
4291 struct ieee80211_vif *vif,
4292 struct ieee80211_sta *sta)
4293{
4294 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004295 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004296 struct wl1271_station *wl_sta;
4297 int ret = 0, id;
4298
4299 mutex_lock(&wl->mutex);
4300
4301 if (unlikely(wl->state == WL1271_STATE_OFF))
4302 goto out;
4303
Eliad Peller536129c2011-10-05 11:55:45 +02004304 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004305 goto out;
4306
4307 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4308
4309 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004310 id = wl_sta->hlid;
4311 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004312 goto out;
4313
Ido Yariva6208652011-03-01 15:14:41 +02004314 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004315 if (ret < 0)
4316 goto out;
4317
Eliad Pellerc690ec82011-08-14 13:17:07 +03004318 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004319 if (ret < 0)
4320 goto out_sleep;
4321
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004322 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004323
4324out_sleep:
4325 wl1271_ps_elp_sleep(wl);
4326
4327out:
4328 mutex_unlock(&wl->mutex);
4329 return ret;
4330}
4331
Luciano Coelho4623ec72011-03-21 19:26:41 +02004332static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4333 struct ieee80211_vif *vif,
4334 enum ieee80211_ampdu_mlme_action action,
4335 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4336 u8 buf_size)
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004337{
4338 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004339 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004340 int ret;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004341 u8 hlid, *ba_bitmap;
4342
4343 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4344 tid);
4345
4346 /* sanity check - the fields in FW are only 8bits wide */
4347 if (WARN_ON(tid > 0xFF))
4348 return -ENOTSUPP;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004349
4350 mutex_lock(&wl->mutex);
4351
4352 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4353 ret = -EAGAIN;
4354 goto out;
4355 }
4356
Eliad Peller536129c2011-10-05 11:55:45 +02004357 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
Eliad Peller154da672011-10-05 11:55:53 +02004358 hlid = wlvif->sta.hlid;
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004359 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
Eliad Peller536129c2011-10-05 11:55:45 +02004360 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004361 struct wl1271_station *wl_sta;
4362
4363 wl_sta = (struct wl1271_station *)sta->drv_priv;
4364 hlid = wl_sta->hlid;
4365 ba_bitmap = &wl->links[hlid].ba_bitmap;
4366 } else {
4367 ret = -EINVAL;
4368 goto out;
4369 }
4370
Ido Yariva6208652011-03-01 15:14:41 +02004371 ret = wl1271_ps_elp_wakeup(wl);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004372 if (ret < 0)
4373 goto out;
4374
Shahar Levi70559a02011-05-22 16:10:22 +03004375 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4376 tid, action);
4377
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004378 switch (action) {
4379 case IEEE80211_AMPDU_RX_START:
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004380 if (!wlvif->ba_support || !wlvif->ba_allowed) {
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004381 ret = -ENOTSUPP;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004382 break;
4383 }
4384
4385 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4386 ret = -EBUSY;
4387 wl1271_error("exceeded max RX BA sessions");
4388 break;
4389 }
4390
4391 if (*ba_bitmap & BIT(tid)) {
4392 ret = -EINVAL;
4393 wl1271_error("cannot enable RX BA session on active "
4394 "tid: %d", tid);
4395 break;
4396 }
4397
4398 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4399 hlid);
4400 if (!ret) {
4401 *ba_bitmap |= BIT(tid);
4402 wl->ba_rx_session_count++;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004403 }
4404 break;
4405
4406 case IEEE80211_AMPDU_RX_STOP:
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004407 if (!(*ba_bitmap & BIT(tid))) {
4408 ret = -EINVAL;
4409 wl1271_error("no active RX BA session on tid: %d",
4410 tid);
4411 break;
4412 }
4413
4414 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4415 hlid);
4416 if (!ret) {
4417 *ba_bitmap &= ~BIT(tid);
4418 wl->ba_rx_session_count--;
4419 }
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004420 break;
4421
4422 /*
4423 * The BA initiator session management in FW independently.
4424 * Falling break here on purpose for all TX APDU commands.
4425 */
4426 case IEEE80211_AMPDU_TX_START:
4427 case IEEE80211_AMPDU_TX_STOP:
4428 case IEEE80211_AMPDU_TX_OPERATIONAL:
4429 ret = -EINVAL;
4430 break;
4431
4432 default:
4433 wl1271_error("Incorrect ampdu action id=%x\n", action);
4434 ret = -EINVAL;
4435 }
4436
4437 wl1271_ps_elp_sleep(wl);
4438
4439out:
4440 mutex_unlock(&wl->mutex);
4441
4442 return ret;
4443}
4444
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004445static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4446 struct ieee80211_vif *vif,
4447 const struct cfg80211_bitrate_mask *mask)
4448{
Eliad Peller83587502011-10-10 10:12:53 +02004449 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004450 struct wl1271 *wl = hw->priv;
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004451 int i, ret = 0;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004452
4453 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4454 mask->control[NL80211_BAND_2GHZ].legacy,
4455 mask->control[NL80211_BAND_5GHZ].legacy);
4456
4457 mutex_lock(&wl->mutex);
4458
4459 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Eliad Peller83587502011-10-10 10:12:53 +02004460 wlvif->bitrate_masks[i] =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004461 wl1271_tx_enabled_rates_get(wl,
4462 mask->control[i].legacy,
4463 i);
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004464
4465 if (unlikely(wl->state == WL1271_STATE_OFF))
4466 goto out;
4467
4468 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4469 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4470
4471 ret = wl1271_ps_elp_wakeup(wl);
4472 if (ret < 0)
4473 goto out;
4474
4475 wl1271_set_band_rate(wl, wlvif);
4476 wlvif->basic_rate =
4477 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4478 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4479
4480 wl1271_ps_elp_sleep(wl);
4481 }
4482out:
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004483 mutex_unlock(&wl->mutex);
4484
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004485 return ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004486}
4487
Shahar Levi6d158ff2011-09-08 13:01:33 +03004488static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4489 struct ieee80211_channel_switch *ch_switch)
4490{
4491 struct wl1271 *wl = hw->priv;
Eliad Peller52630c52011-10-10 10:13:08 +02004492 struct wl12xx_vif *wlvif;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004493 int ret;
4494
4495 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4496
4497 mutex_lock(&wl->mutex);
4498
4499 if (unlikely(wl->state == WL1271_STATE_OFF)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02004500 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4501 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4502 ieee80211_chswitch_done(vif, false);
4503 }
4504 goto out;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004505 }
4506
4507 ret = wl1271_ps_elp_wakeup(wl);
4508 if (ret < 0)
4509 goto out;
4510
Eliad Peller52630c52011-10-10 10:13:08 +02004511 /* TODO: change mac80211 to pass vif as param */
4512 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller8332f0f2012-01-31 11:57:19 +02004513 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
Shahar Levi6d158ff2011-09-08 13:01:33 +03004514
Eliad Peller52630c52011-10-10 10:13:08 +02004515 if (!ret)
4516 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4517 }
Shahar Levi6d158ff2011-09-08 13:01:33 +03004518
4519 wl1271_ps_elp_sleep(wl);
4520
4521out:
4522 mutex_unlock(&wl->mutex);
4523}
4524
Arik Nemtsov33437892011-04-26 23:35:39 +03004525static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4526{
4527 struct wl1271 *wl = hw->priv;
4528 bool ret = false;
4529
4530 mutex_lock(&wl->mutex);
4531
4532 if (unlikely(wl->state == WL1271_STATE_OFF))
4533 goto out;
4534
4535 /* packets are considered pending if in the TX queue or the FW */
Arik Nemtsovf1a46382011-07-07 14:25:23 +03004536 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
Arik Nemtsov33437892011-04-26 23:35:39 +03004537out:
4538 mutex_unlock(&wl->mutex);
4539
4540 return ret;
4541}
4542
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004543/* can't be const, mac80211 writes to this */
4544static struct ieee80211_rate wl1271_rates[] = {
4545 { .bitrate = 10,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004546 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4547 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004548 { .bitrate = 20,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004549 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4550 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004551 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4552 { .bitrate = 55,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004553 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4554 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004555 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4556 { .bitrate = 110,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004557 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4558 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004559 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4560 { .bitrate = 60,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004561 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4562 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004563 { .bitrate = 90,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004564 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4565 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004566 { .bitrate = 120,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004567 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4568 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004569 { .bitrate = 180,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004570 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4571 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004572 { .bitrate = 240,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004573 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4574 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004575 { .bitrate = 360,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004576 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4577 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004578 { .bitrate = 480,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004579 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4580 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004581 { .bitrate = 540,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004582 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4583 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004584};
4585
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004586/* can't be const, mac80211 writes to this */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004587static struct ieee80211_channel wl1271_channels[] = {
Luciano Coelhoa2d0e3f2009-12-11 15:40:46 +02004588 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004589 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004590 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4591 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4592 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004593 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004594 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4595 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4596 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004597 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004598 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4599 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4600 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
Arik Nemtsov6c89b7b2011-01-18 20:39:52 +01004601 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004602};
4603
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004604/* mapping to indexes for wl1271_rates */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004605static const u8 wl1271_rate_to_idx_2ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004606 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004607 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004608 7, /* CONF_HW_RXTX_RATE_MCS7 */
4609 6, /* CONF_HW_RXTX_RATE_MCS6 */
4610 5, /* CONF_HW_RXTX_RATE_MCS5 */
4611 4, /* CONF_HW_RXTX_RATE_MCS4 */
4612 3, /* CONF_HW_RXTX_RATE_MCS3 */
4613 2, /* CONF_HW_RXTX_RATE_MCS2 */
4614 1, /* CONF_HW_RXTX_RATE_MCS1 */
4615 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004616
4617 11, /* CONF_HW_RXTX_RATE_54 */
4618 10, /* CONF_HW_RXTX_RATE_48 */
4619 9, /* CONF_HW_RXTX_RATE_36 */
4620 8, /* CONF_HW_RXTX_RATE_24 */
4621
4622 /* TI-specific rate */
4623 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4624
4625 7, /* CONF_HW_RXTX_RATE_18 */
4626 6, /* CONF_HW_RXTX_RATE_12 */
4627 3, /* CONF_HW_RXTX_RATE_11 */
4628 5, /* CONF_HW_RXTX_RATE_9 */
4629 4, /* CONF_HW_RXTX_RATE_6 */
4630 2, /* CONF_HW_RXTX_RATE_5_5 */
4631 1, /* CONF_HW_RXTX_RATE_2 */
4632 0 /* CONF_HW_RXTX_RATE_1 */
4633};
4634
Shahar Levie8b03a22010-10-13 16:09:39 +02004635/* 11n STA capabilities */
4636#define HW_RX_HIGHEST_RATE 72
4637
Shahar Levi00d20102010-11-08 11:20:10 +00004638#define WL12XX_HT_CAP { \
Shahar Levi871d0c32011-03-13 11:24:40 +02004639 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4640 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
Shahar Levie8b03a22010-10-13 16:09:39 +02004641 .ht_supported = true, \
4642 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4643 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4644 .mcs = { \
4645 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4646 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4647 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4648 }, \
4649}
4650
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004651/* can't be const, mac80211 writes to this */
4652static struct ieee80211_supported_band wl1271_band_2ghz = {
4653 .channels = wl1271_channels,
4654 .n_channels = ARRAY_SIZE(wl1271_channels),
4655 .bitrates = wl1271_rates,
4656 .n_bitrates = ARRAY_SIZE(wl1271_rates),
Shahar Levi00d20102010-11-08 11:20:10 +00004657 .ht_cap = WL12XX_HT_CAP,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004658};
4659
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004660/* 5 GHz data rates for WL1273 */
4661static struct ieee80211_rate wl1271_rates_5ghz[] = {
4662 { .bitrate = 60,
4663 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4664 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4665 { .bitrate = 90,
4666 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4667 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4668 { .bitrate = 120,
4669 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4670 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4671 { .bitrate = 180,
4672 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4673 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4674 { .bitrate = 240,
4675 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4676 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4677 { .bitrate = 360,
4678 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4679 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4680 { .bitrate = 480,
4681 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4682 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4683 { .bitrate = 540,
4684 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4685 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4686};
4687
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004688/* 5 GHz band channels for WL1273 */
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004689static struct ieee80211_channel wl1271_channels_5ghz[] = {
Arik Nemtsov6cfa5cf2011-06-27 22:06:33 +03004690 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4691 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4692 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4693 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4694 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4695 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4696 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4697 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4698 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4699 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4700 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4701 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4702 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4703 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4704 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4705 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4706 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4707 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4708 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4709 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4710 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4711 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4712 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4713 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4714 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4715 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4716 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4717 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4718 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4719 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4720 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4721 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4722 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4723 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004724};
4725
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004726/* mapping to indexes for wl1271_rates_5ghz */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004727static const u8 wl1271_rate_to_idx_5ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004728 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004729 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004730 7, /* CONF_HW_RXTX_RATE_MCS7 */
4731 6, /* CONF_HW_RXTX_RATE_MCS6 */
4732 5, /* CONF_HW_RXTX_RATE_MCS5 */
4733 4, /* CONF_HW_RXTX_RATE_MCS4 */
4734 3, /* CONF_HW_RXTX_RATE_MCS3 */
4735 2, /* CONF_HW_RXTX_RATE_MCS2 */
4736 1, /* CONF_HW_RXTX_RATE_MCS1 */
4737 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004738
4739 7, /* CONF_HW_RXTX_RATE_54 */
4740 6, /* CONF_HW_RXTX_RATE_48 */
4741 5, /* CONF_HW_RXTX_RATE_36 */
4742 4, /* CONF_HW_RXTX_RATE_24 */
4743
4744 /* TI-specific rate */
4745 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4746
4747 3, /* CONF_HW_RXTX_RATE_18 */
4748 2, /* CONF_HW_RXTX_RATE_12 */
4749 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4750 1, /* CONF_HW_RXTX_RATE_9 */
4751 0, /* CONF_HW_RXTX_RATE_6 */
4752 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4753 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4754 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4755};
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004756
4757static struct ieee80211_supported_band wl1271_band_5ghz = {
4758 .channels = wl1271_channels_5ghz,
4759 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4760 .bitrates = wl1271_rates_5ghz,
4761 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
Shahar Levi00d20102010-11-08 11:20:10 +00004762 .ht_cap = WL12XX_HT_CAP,
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004763};
4764
Tobias Klausera0ea9492010-05-20 10:38:11 +02004765static const u8 *wl1271_band_rate_to_idx[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004766 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4767 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4768};
4769
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004770static const struct ieee80211_ops wl1271_ops = {
4771 .start = wl1271_op_start,
4772 .stop = wl1271_op_stop,
4773 .add_interface = wl1271_op_add_interface,
4774 .remove_interface = wl1271_op_remove_interface,
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02004775 .change_interface = wl12xx_op_change_interface,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004776#ifdef CONFIG_PM
Eliad Peller402e48612011-05-13 11:57:09 +03004777 .suspend = wl1271_op_suspend,
4778 .resume = wl1271_op_resume,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004779#endif
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004780 .config = wl1271_op_config,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03004781 .prepare_multicast = wl1271_op_prepare_multicast,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004782 .configure_filter = wl1271_op_configure_filter,
4783 .tx = wl1271_op_tx,
4784 .set_key = wl1271_op_set_key,
4785 .hw_scan = wl1271_op_hw_scan,
Eliad Peller73ecce32011-06-27 13:06:45 +03004786 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
Luciano Coelho33c2c062011-05-10 14:46:02 +03004787 .sched_scan_start = wl1271_op_sched_scan_start,
4788 .sched_scan_stop = wl1271_op_sched_scan_stop,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004789 .bss_info_changed = wl1271_op_bss_info_changed,
Arik Nemtsov68d069c2010-11-08 10:51:07 +01004790 .set_frag_threshold = wl1271_op_set_frag_threshold,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004791 .set_rts_threshold = wl1271_op_set_rts_threshold,
Kalle Valoc6999d82010-02-18 13:25:41 +02004792 .conf_tx = wl1271_op_conf_tx,
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004793 .get_tsf = wl1271_op_get_tsf,
John W. Linvilleece550d2010-07-28 16:41:06 -04004794 .get_survey = wl1271_op_get_survey,
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004795 .sta_add = wl1271_op_sta_add,
4796 .sta_remove = wl1271_op_sta_remove,
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004797 .ampdu_action = wl1271_op_ampdu_action,
Arik Nemtsov33437892011-04-26 23:35:39 +03004798 .tx_frames_pending = wl1271_tx_frames_pending,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004799 .set_bitrate_mask = wl12xx_set_bitrate_mask,
Shahar Levi6d158ff2011-09-08 13:01:33 +03004800 .channel_switch = wl12xx_op_channel_switch,
Kalle Valoc8c90872010-02-18 13:25:53 +02004801 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004802};
4803
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004804
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004805u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004806{
4807 u8 idx;
4808
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004809 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004810
4811 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4812 wl1271_error("Illegal RX rate from HW: %d", rate);
4813 return 0;
4814 }
4815
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004816 idx = wl1271_band_rate_to_idx[band][rate];
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004817 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4818 wl1271_error("Unsupported RX rate from HW: %d", rate);
4819 return 0;
4820 }
4821
4822 return idx;
4823}
4824
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004825static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4826 struct device_attribute *attr,
4827 char *buf)
4828{
4829 struct wl1271 *wl = dev_get_drvdata(dev);
4830 ssize_t len;
4831
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004832 len = PAGE_SIZE;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004833
4834 mutex_lock(&wl->mutex);
4835 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4836 wl->sg_enabled);
4837 mutex_unlock(&wl->mutex);
4838
4839 return len;
4840
4841}
4842
4843static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4844 struct device_attribute *attr,
4845 const char *buf, size_t count)
4846{
4847 struct wl1271 *wl = dev_get_drvdata(dev);
4848 unsigned long res;
4849 int ret;
4850
Luciano Coelho6277ed62011-04-01 17:49:54 +03004851 ret = kstrtoul(buf, 10, &res);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004852 if (ret < 0) {
4853 wl1271_warning("incorrect value written to bt_coex_mode");
4854 return count;
4855 }
4856
4857 mutex_lock(&wl->mutex);
4858
4859 res = !!res;
4860
4861 if (res == wl->sg_enabled)
4862 goto out;
4863
4864 wl->sg_enabled = res;
4865
4866 if (wl->state == WL1271_STATE_OFF)
4867 goto out;
4868
Ido Yariva6208652011-03-01 15:14:41 +02004869 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004870 if (ret < 0)
4871 goto out;
4872
4873 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4874 wl1271_ps_elp_sleep(wl);
4875
4876 out:
4877 mutex_unlock(&wl->mutex);
4878 return count;
4879}
4880
4881static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4882 wl1271_sysfs_show_bt_coex_state,
4883 wl1271_sysfs_store_bt_coex_state);
4884
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004885static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4886 struct device_attribute *attr,
4887 char *buf)
4888{
4889 struct wl1271 *wl = dev_get_drvdata(dev);
4890 ssize_t len;
4891
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004892 len = PAGE_SIZE;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004893
4894 mutex_lock(&wl->mutex);
4895 if (wl->hw_pg_ver >= 0)
4896 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4897 else
4898 len = snprintf(buf, len, "n/a\n");
4899 mutex_unlock(&wl->mutex);
4900
4901 return len;
4902}
4903
Gery Kahn6f07b722011-07-18 14:21:49 +03004904static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004905 wl1271_sysfs_show_hw_pg_ver, NULL);
4906
Ido Yariv95dac04f2011-06-06 14:57:06 +03004907static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4908 struct bin_attribute *bin_attr,
4909 char *buffer, loff_t pos, size_t count)
4910{
4911 struct device *dev = container_of(kobj, struct device, kobj);
4912 struct wl1271 *wl = dev_get_drvdata(dev);
4913 ssize_t len;
4914 int ret;
4915
4916 ret = mutex_lock_interruptible(&wl->mutex);
4917 if (ret < 0)
4918 return -ERESTARTSYS;
4919
4920 /* Let only one thread read the log at a time, blocking others */
4921 while (wl->fwlog_size == 0) {
4922 DEFINE_WAIT(wait);
4923
4924 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4925 &wait,
4926 TASK_INTERRUPTIBLE);
4927
4928 if (wl->fwlog_size != 0) {
4929 finish_wait(&wl->fwlog_waitq, &wait);
4930 break;
4931 }
4932
4933 mutex_unlock(&wl->mutex);
4934
4935 schedule();
4936 finish_wait(&wl->fwlog_waitq, &wait);
4937
4938 if (signal_pending(current))
4939 return -ERESTARTSYS;
4940
4941 ret = mutex_lock_interruptible(&wl->mutex);
4942 if (ret < 0)
4943 return -ERESTARTSYS;
4944 }
4945
4946 /* Check if the fwlog is still valid */
4947 if (wl->fwlog_size < 0) {
4948 mutex_unlock(&wl->mutex);
4949 return 0;
4950 }
4951
4952 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4953 len = min(count, (size_t)wl->fwlog_size);
4954 wl->fwlog_size -= len;
4955 memcpy(buffer, wl->fwlog, len);
4956
4957 /* Make room for new messages */
4958 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4959
4960 mutex_unlock(&wl->mutex);
4961
4962 return len;
4963}
4964
4965static struct bin_attribute fwlog_attr = {
4966 .attr = {.name = "fwlog", .mode = S_IRUSR},
4967 .read = wl1271_sysfs_read_fwlog,
4968};
4969
Luciano Coelho5e037e72011-12-23 09:32:17 +02004970static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4971{
4972 bool supported = false;
4973 u8 major, minor;
4974
4975 if (wl->chip.id == CHIP_ID_1283_PG20) {
4976 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
4977 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
4978
4979 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
4980 if (major > 2 || (major == 2 && minor >= 1))
4981 supported = true;
4982 } else {
4983 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
4984 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
4985
4986 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
4987 if (major == 3 && minor >= 1)
4988 supported = true;
4989 }
4990
4991 wl1271_debug(DEBUG_PROBE,
4992 "PG Ver major = %d minor = %d, MAC %s present",
4993 major, minor, supported ? "is" : "is not");
4994
4995 return supported;
4996}
4997
4998static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4999 u32 oui, u32 nic, int n)
5000{
5001 int i;
5002
5003 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
5004 oui, nic, n);
5005
5006 if (nic + n - 1 > 0xffffff)
5007 wl1271_warning("NIC part of the MAC address wraps around!");
5008
5009 for (i = 0; i < n; i++) {
5010 wl->addresses[i].addr[0] = (u8)(oui >> 16);
5011 wl->addresses[i].addr[1] = (u8)(oui >> 8);
5012 wl->addresses[i].addr[2] = (u8) oui;
5013 wl->addresses[i].addr[3] = (u8)(nic >> 16);
5014 wl->addresses[i].addr[4] = (u8)(nic >> 8);
5015 wl->addresses[i].addr[5] = (u8) nic;
5016 nic++;
5017 }
5018
5019 wl->hw->wiphy->n_addresses = n;
5020 wl->hw->wiphy->addresses = wl->addresses;
5021}
5022
5023static void wl12xx_get_fuse_mac(struct wl1271 *wl)
5024{
5025 u32 mac1, mac2;
5026
5027 wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
5028
5029 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
5030 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
5031
5032 /* these are the two parts of the BD_ADDR */
5033 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
5034 ((mac1 & 0xff000000) >> 24);
5035 wl->fuse_nic_addr = mac1 & 0xffffff;
5036
5037 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
5038}
5039
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005040static int wl12xx_get_hw_info(struct wl1271 *wl)
5041{
5042 int ret;
5043 u32 die_info;
5044
5045 ret = wl12xx_set_power_on(wl);
5046 if (ret < 0)
5047 goto out;
5048
5049 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
5050
5051 if (wl->chip.id == CHIP_ID_1283_PG20)
5052 die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
5053 else
5054 die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
5055
5056 wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
5057
Luciano Coelho5e037e72011-12-23 09:32:17 +02005058 if (!wl12xx_mac_in_fuse(wl)) {
5059 wl->fuse_oui_addr = 0;
5060 wl->fuse_nic_addr = 0;
5061 } else {
5062 wl12xx_get_fuse_mac(wl);
5063 }
5064
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005065 wl1271_power_off(wl);
5066out:
5067 return ret;
5068}
5069
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005070static int wl1271_register_hw(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005071{
5072 int ret;
Luciano Coelho5e037e72011-12-23 09:32:17 +02005073 u32 oui_addr = 0, nic_addr = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005074
5075 if (wl->mac80211_registered)
5076 return 0;
5077
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005078 ret = wl12xx_get_hw_info(wl);
5079 if (ret < 0) {
5080 wl1271_error("couldn't get hw info");
5081 goto out;
5082 }
5083
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005084 ret = wl1271_fetch_nvs(wl);
5085 if (ret == 0) {
Shahar Levibc765bf2011-03-06 16:32:10 +02005086 /* NOTE: The wl->nvs->nvs element must be first, in
5087 * order to simplify the casting, we assume it is at
5088 * the beginning of the wl->nvs structure.
5089 */
5090 u8 *nvs_ptr = (u8 *)wl->nvs;
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005091
Luciano Coelho5e037e72011-12-23 09:32:17 +02005092 oui_addr =
5093 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
5094 nic_addr =
5095 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005096 }
5097
Luciano Coelho5e037e72011-12-23 09:32:17 +02005098 /* if the MAC address is zeroed in the NVS derive from fuse */
5099 if (oui_addr == 0 && nic_addr == 0) {
5100 oui_addr = wl->fuse_oui_addr;
5101 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5102 nic_addr = wl->fuse_nic_addr + 1;
5103 }
5104
5105 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005106
5107 ret = ieee80211_register_hw(wl->hw);
5108 if (ret < 0) {
5109 wl1271_error("unable to register mac80211 hw: %d", ret);
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005110 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005111 }
5112
5113 wl->mac80211_registered = true;
5114
Eliad Pellerd60080a2010-11-24 12:53:16 +02005115 wl1271_debugfs_init(wl);
5116
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03005117 register_netdevice_notifier(&wl1271_dev_notifier);
5118
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005119 wl1271_notice("loaded");
5120
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005121out:
5122 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005123}
5124
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005125static void wl1271_unregister_hw(struct wl1271 *wl)
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005126{
Eliad Peller3fcdab72012-02-06 12:47:54 +02005127 if (wl->plt)
Ido Yarivf3df1332012-01-11 09:42:39 +02005128 wl1271_plt_stop(wl);
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01005129
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03005130 unregister_netdevice_notifier(&wl1271_dev_notifier);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005131 ieee80211_unregister_hw(wl->hw);
5132 wl->mac80211_registered = false;
5133
5134}
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005135
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005136static int wl1271_init_ieee80211(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005137{
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005138 static const u32 cipher_suites[] = {
5139 WLAN_CIPHER_SUITE_WEP40,
5140 WLAN_CIPHER_SUITE_WEP104,
5141 WLAN_CIPHER_SUITE_TKIP,
5142 WLAN_CIPHER_SUITE_CCMP,
5143 WL1271_CIPHER_SUITE_GEM,
5144 };
5145
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005146 /* The tx descriptor buffer and the TKIP space. */
Eliad Peller5ec8a442012-02-02 12:22:09 +02005147 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005148 sizeof(struct wl1271_tx_hw_descr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005149
5150 /* unit us */
5151 /* FIXME: find a proper value */
5152 wl->hw->channel_change_time = 10000;
Juuso Oikarinen50c500a2010-04-01 11:38:22 +03005153 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005154
5155 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
Juuso Oikarinen0a343322010-02-22 08:38:41 +02005156 IEEE80211_HW_SUPPORTS_PS |
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02005157 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo4695dc92010-03-18 12:26:38 +02005158 IEEE80211_HW_SUPPORTS_UAPSD |
Juuso Oikarinena9af0922010-03-26 12:53:30 +02005159 IEEE80211_HW_HAS_RATE_CONTROL |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03005160 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelho25eaea302011-05-02 12:37:33 +03005161 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Shahar Levifcd23b62011-05-11 12:12:56 +03005162 IEEE80211_HW_SPECTRUM_MGMT |
Arik Nemtsov93f8c8e2011-08-30 09:34:01 +03005163 IEEE80211_HW_AP_LINK_PS |
5164 IEEE80211_HW_AMPDU_AGGREGATION |
Eliad Peller79aba1b2012-02-02 13:15:35 +02005165 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
5166 IEEE80211_HW_SCAN_WHILE_IDLE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005167
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005168 wl->hw->wiphy->cipher_suites = cipher_suites;
5169 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5170
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02005171 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Eliad Peller045c7452011-08-28 15:23:01 +03005172 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
5173 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005174 wl->hw->wiphy->max_scan_ssids = 1;
Luciano Coelho221737d2011-09-02 14:28:22 +03005175 wl->hw->wiphy->max_sched_scan_ssids = 16;
5176 wl->hw->wiphy->max_match_sets = 16;
Guy Eilamea559b42010-12-09 16:54:59 +02005177 /*
5178 * Maximum length of elements in scanning probe request templates
5179 * should be the maximum length possible for a template, without
5180 * the IEEE80211 header of the template
5181 */
Ido Reisc08e3712012-02-02 13:54:27 +02005182 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Guy Eilamea559b42010-12-09 16:54:59 +02005183 sizeof(struct ieee80211_header);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005184
Ido Reisc08e3712012-02-02 13:54:27 +02005185 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Luciano Coelhoc9e79a42011-09-27 16:22:35 +03005186 sizeof(struct ieee80211_header);
5187
Eliad Peller1ec23f72011-08-25 14:26:54 +03005188 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5189
Luciano Coelho4a31c112011-03-21 23:16:14 +02005190 /* make sure all our channels fit in the scanned_ch bitmask */
5191 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
5192 ARRAY_SIZE(wl1271_channels_5ghz) >
5193 WL1271_MAX_CHANNELS);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005194 /*
5195 * We keep local copies of the band structs because we need to
5196 * modify them on a per-device basis.
5197 */
5198 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5199 sizeof(wl1271_band_2ghz));
5200 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5201 sizeof(wl1271_band_5ghz));
5202
5203 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5204 &wl->bands[IEEE80211_BAND_2GHZ];
5205 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5206 &wl->bands[IEEE80211_BAND_5GHZ];
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03005207
Kalle Valo12bd8942010-03-18 12:26:33 +02005208 wl->hw->queues = 4;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +02005209 wl->hw->max_rates = 1;
Kalle Valo12bd8942010-03-18 12:26:33 +02005210
Juuso Oikarinenb7417d92010-11-10 11:27:19 +01005211 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5212
Arik Nemtsov9c1b1902011-11-08 18:46:55 +02005213 /* the FW answers probe-requests in AP-mode */
5214 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5215 wl->hw->wiphy->probe_resp_offload =
5216 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5217 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5218 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5219
Felipe Balbia390e852011-10-06 10:07:44 +03005220 SET_IEEE80211_DEV(wl->hw, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005221
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005222 wl->hw->sta_data_size = sizeof(struct wl1271_station);
Eliad Peller87fbcb02011-10-05 11:55:41 +02005223 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005224
Luciano Coelho4c9cfa72011-01-12 14:27:03 +01005225 wl->hw->max_rx_aggregation_subframes = 8;
5226
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005227 return 0;
5228}
5229
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005230#define WL1271_DEFAULT_CHANNEL 0
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005231
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005232static struct ieee80211_hw *wl1271_alloc_hw(void)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005233{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005234 struct ieee80211_hw *hw;
5235 struct wl1271 *wl;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005236 int i, j, ret;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005237 unsigned int order;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005238
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005239 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
Arik Nemtsovf80c2d12011-09-22 09:52:05 +03005240
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005241 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5242 if (!hw) {
5243 wl1271_error("could not alloc ieee80211_hw");
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005244 ret = -ENOMEM;
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005245 goto err_hw_alloc;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005246 }
5247
5248 wl = hw->priv;
5249 memset(wl, 0, sizeof(*wl));
5250
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005251 INIT_LIST_HEAD(&wl->list);
Eliad Peller87627212011-10-10 10:12:54 +02005252 INIT_LIST_HEAD(&wl->wlvif_list);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005253
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005254 wl->hw = hw;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005255
Juuso Oikarinen6742f552010-12-13 09:52:37 +02005256 for (i = 0; i < NUM_TX_QUEUES; i++)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005257 for (j = 0; j < WL12XX_MAX_LINKS; j++)
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005258 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5259
Ido Yariva6208652011-03-01 15:14:41 +02005260 skb_queue_head_init(&wl->deferred_rx_queue);
5261 skb_queue_head_init(&wl->deferred_tx_queue);
5262
Juuso Oikarinen37b70a82009-10-08 21:56:21 +03005263 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
Ido Yariva6208652011-03-01 15:14:41 +02005264 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
Juuso Oikarinen117b38d2010-09-30 10:43:28 +02005265 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5266 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5267 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +03005268
Eliad Peller92ef8962011-06-07 12:50:46 +03005269 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5270 if (!wl->freezable_wq) {
5271 ret = -ENOMEM;
5272 goto err_hw;
5273 }
5274
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005275 wl->channel = WL1271_DEFAULT_CHANNEL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005276 wl->rx_counter = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005277 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03005278 wl->band = IEEE80211_BAND_2GHZ;
Juuso Oikarinenb771eee2009-10-08 21:56:34 +03005279 wl->vif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02005280 wl->flags = 0;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02005281 wl->sg_enabled = true;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03005282 wl->hw_pg_ver = -1;
Arik Nemtsovb622d992011-02-23 00:22:31 +02005283 wl->ap_ps_map = 0;
5284 wl->ap_fw_ps_map = 0;
Ido Yariv606ea9f2011-03-01 15:14:39 +02005285 wl->quirks = 0;
Ido Yariv341b7cd2011-03-31 10:07:01 +02005286 wl->platform_quirks = 0;
Luciano Coelho33c2c062011-05-10 14:46:02 +03005287 wl->sched_scanning = false;
Guy Eilame9eb8cb2011-08-16 19:49:12 +03005288 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005289 wl->system_hlid = WL12XX_SYSTEM_HLID;
Arik Nemtsovda032092011-08-25 12:43:15 +03005290 wl->active_sta_count = 0;
Ido Yariv95dac04f2011-06-06 14:57:06 +03005291 wl->fwlog_size = 0;
5292 init_waitqueue_head(&wl->fwlog_waitq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005293
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005294 /* The system link is always allocated */
5295 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5296
Ido Yariv25eeb9e2010-10-12 16:20:06 +02005297 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +03005298 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005299 wl->tx_frames[i] = NULL;
5300
5301 spin_lock_init(&wl->wl_lock);
5302
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005303 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005304 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005305 mutex_init(&wl->mutex);
5306
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005307 /* Apply default driver configuration. */
5308 wl1271_conf_init(wl);
5309
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005310 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5311 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5312 if (!wl->aggr_buf) {
5313 ret = -ENOMEM;
Eliad Peller92ef8962011-06-07 12:50:46 +03005314 goto err_wq;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005315 }
5316
Ido Yariv990f5de2011-03-31 10:06:59 +02005317 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5318 if (!wl->dummy_packet) {
5319 ret = -ENOMEM;
5320 goto err_aggr;
5321 }
5322
Ido Yariv95dac04f2011-06-06 14:57:06 +03005323 /* Allocate one page for the FW log */
5324 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5325 if (!wl->fwlog) {
5326 ret = -ENOMEM;
5327 goto err_dummy_packet;
5328 }
5329
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005330 return hw;
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005331
Ido Yariv990f5de2011-03-31 10:06:59 +02005332err_dummy_packet:
5333 dev_kfree_skb(wl->dummy_packet);
5334
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005335err_aggr:
5336 free_pages((unsigned long)wl->aggr_buf, order);
5337
Eliad Peller92ef8962011-06-07 12:50:46 +03005338err_wq:
5339 destroy_workqueue(wl->freezable_wq);
5340
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005341err_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005342 wl1271_debugfs_exit(wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005343 ieee80211_free_hw(hw);
5344
5345err_hw_alloc:
5346
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005347 return ERR_PTR(ret);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005348}
5349
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005350static int wl1271_free_hw(struct wl1271 *wl)
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005351{
Ido Yariv95dac04f2011-06-06 14:57:06 +03005352 /* Unblock any fwlog readers */
5353 mutex_lock(&wl->mutex);
5354 wl->fwlog_size = -1;
5355 wake_up_interruptible_all(&wl->fwlog_waitq);
5356 mutex_unlock(&wl->mutex);
5357
Felipe Balbif79f8902011-10-06 13:05:25 +03005358 device_remove_bin_file(wl->dev, &fwlog_attr);
Gery Kahn6f07b722011-07-18 14:21:49 +03005359
Felipe Balbif79f8902011-10-06 13:05:25 +03005360 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
Gery Kahn6f07b722011-07-18 14:21:49 +03005361
Felipe Balbif79f8902011-10-06 13:05:25 +03005362 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
Ido Yariv95dac04f2011-06-06 14:57:06 +03005363 free_page((unsigned long)wl->fwlog);
Ido Yariv990f5de2011-03-31 10:06:59 +02005364 dev_kfree_skb(wl->dummy_packet);
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005365 free_pages((unsigned long)wl->aggr_buf,
5366 get_order(WL1271_AGGR_BUFFER_SIZE));
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005367
5368 wl1271_debugfs_exit(wl);
5369
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005370 vfree(wl->fw);
5371 wl->fw = NULL;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005372 wl->fw_type = WL12XX_FW_TYPE_NONE;
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005373 kfree(wl->nvs);
5374 wl->nvs = NULL;
5375
5376 kfree(wl->fw_status);
5377 kfree(wl->tx_res_if);
Eliad Peller92ef8962011-06-07 12:50:46 +03005378 destroy_workqueue(wl->freezable_wq);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005379
5380 ieee80211_free_hw(wl->hw);
5381
5382 return 0;
5383}
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005384
Felipe Balbia390e852011-10-06 10:07:44 +03005385static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5386{
5387 struct wl1271 *wl = cookie;
5388 unsigned long flags;
5389
5390 wl1271_debug(DEBUG_IRQ, "IRQ");
5391
5392 /* complete the ELP completion */
5393 spin_lock_irqsave(&wl->wl_lock, flags);
5394 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5395 if (wl->elp_compl) {
5396 complete(wl->elp_compl);
5397 wl->elp_compl = NULL;
5398 }
5399
5400 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5401 /* don't enqueue a work right now. mark it as pending */
5402 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5403 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5404 disable_irq_nosync(wl->irq);
5405 pm_wakeup_event(wl->dev, 0);
5406 spin_unlock_irqrestore(&wl->wl_lock, flags);
5407 return IRQ_HANDLED;
5408 }
5409 spin_unlock_irqrestore(&wl->wl_lock, flags);
5410
5411 return IRQ_WAKE_THREAD;
5412}
5413
Felipe Balbice2a2172011-10-05 14:12:55 +03005414static int __devinit wl12xx_probe(struct platform_device *pdev)
5415{
Felipe Balbia390e852011-10-06 10:07:44 +03005416 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5417 struct ieee80211_hw *hw;
5418 struct wl1271 *wl;
5419 unsigned long irqflags;
5420 int ret = -ENODEV;
5421
5422 hw = wl1271_alloc_hw();
5423 if (IS_ERR(hw)) {
5424 wl1271_error("can't allocate hw");
5425 ret = PTR_ERR(hw);
5426 goto out;
5427 }
5428
5429 wl = hw->priv;
5430 wl->irq = platform_get_irq(pdev, 0);
5431 wl->ref_clock = pdata->board_ref_clock;
5432 wl->tcxo_clock = pdata->board_tcxo_clock;
5433 wl->platform_quirks = pdata->platform_quirks;
5434 wl->set_power = pdata->set_power;
5435 wl->dev = &pdev->dev;
5436 wl->if_ops = pdata->ops;
5437
5438 platform_set_drvdata(pdev, wl);
5439
5440 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5441 irqflags = IRQF_TRIGGER_RISING;
5442 else
5443 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5444
5445 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5446 irqflags,
5447 pdev->name, wl);
5448 if (ret < 0) {
5449 wl1271_error("request_irq() failed: %d", ret);
5450 goto out_free_hw;
5451 }
5452
5453 ret = enable_irq_wake(wl->irq);
5454 if (!ret) {
5455 wl->irq_wake_enabled = true;
5456 device_init_wakeup(wl->dev, 1);
5457 if (pdata->pwr_in_suspend)
5458 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5459
5460 }
5461 disable_irq(wl->irq);
5462
5463 ret = wl1271_init_ieee80211(wl);
5464 if (ret)
5465 goto out_irq;
5466
5467 ret = wl1271_register_hw(wl);
5468 if (ret)
5469 goto out_irq;
5470
Felipe Balbif79f8902011-10-06 13:05:25 +03005471 /* Create sysfs file to control bt coex state */
5472 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5473 if (ret < 0) {
5474 wl1271_error("failed to create sysfs file bt_coex_state");
5475 goto out_irq;
5476 }
5477
5478 /* Create sysfs file to get HW PG version */
5479 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5480 if (ret < 0) {
5481 wl1271_error("failed to create sysfs file hw_pg_ver");
5482 goto out_bt_coex_state;
5483 }
5484
5485 /* Create sysfs file for the FW log */
5486 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5487 if (ret < 0) {
5488 wl1271_error("failed to create sysfs file fwlog");
5489 goto out_hw_pg_ver;
5490 }
5491
Felipe Balbice2a2172011-10-05 14:12:55 +03005492 return 0;
Felipe Balbia390e852011-10-06 10:07:44 +03005493
Felipe Balbif79f8902011-10-06 13:05:25 +03005494out_hw_pg_ver:
5495 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5496
5497out_bt_coex_state:
5498 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5499
Felipe Balbia390e852011-10-06 10:07:44 +03005500out_irq:
5501 free_irq(wl->irq, wl);
5502
5503out_free_hw:
5504 wl1271_free_hw(wl);
5505
5506out:
5507 return ret;
Felipe Balbice2a2172011-10-05 14:12:55 +03005508}
5509
5510static int __devexit wl12xx_remove(struct platform_device *pdev)
5511{
Felipe Balbia390e852011-10-06 10:07:44 +03005512 struct wl1271 *wl = platform_get_drvdata(pdev);
5513
5514 if (wl->irq_wake_enabled) {
5515 device_init_wakeup(wl->dev, 0);
5516 disable_irq_wake(wl->irq);
5517 }
5518 wl1271_unregister_hw(wl);
5519 free_irq(wl->irq, wl);
5520 wl1271_free_hw(wl);
5521
Felipe Balbice2a2172011-10-05 14:12:55 +03005522 return 0;
5523}
5524
5525static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005526 { "wl12xx", 0 },
Felipe Balbice2a2172011-10-05 14:12:55 +03005527 { } /* Terminating Entry */
5528};
5529MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5530
5531static struct platform_driver wl12xx_driver = {
5532 .probe = wl12xx_probe,
5533 .remove = __devexit_p(wl12xx_remove),
5534 .id_table = wl12xx_id_table,
5535 .driver = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005536 .name = "wl12xx_driver",
Felipe Balbice2a2172011-10-05 14:12:55 +03005537 .owner = THIS_MODULE,
5538 }
5539};
5540
5541static int __init wl12xx_init(void)
5542{
5543 return platform_driver_register(&wl12xx_driver);
5544}
5545module_init(wl12xx_init);
5546
5547static void __exit wl12xx_exit(void)
5548{
5549 platform_driver_unregister(&wl12xx_driver);
5550}
5551module_exit(wl12xx_exit);
5552
Guy Eilam491bbd62011-01-12 10:33:29 +01005553u32 wl12xx_debug_level = DEBUG_NONE;
Eliad Peller17c17552010-12-12 12:15:35 +02005554EXPORT_SYMBOL_GPL(wl12xx_debug_level);
Guy Eilam491bbd62011-01-12 10:33:29 +01005555module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
Eliad Peller17c17552010-12-12 12:15:35 +02005556MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5557
Ido Yariv95dac04f2011-06-06 14:57:06 +03005558module_param_named(fwlog, fwlog_param, charp, 0);
Luciano Coelho2c882fa2012-02-07 12:37:33 +02005559MODULE_PARM_DESC(fwlog,
Ido Yariv95dac04f2011-06-06 14:57:06 +03005560 "FW logger options: continuous, ondemand, dbgpins or disable");
5561
Eliad Peller2a5bff02011-08-25 18:10:59 +03005562module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5563MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5564
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005565MODULE_LICENSE("GPL");
Luciano Coelhob1a48ca2011-02-22 14:19:28 +02005566MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005567MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");