blob: 95a76a5f9eeb692c044dddaf0661ad8fb5a78d15 [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,
Arik Nemtsovd7b63b92012-02-28 00:41:34 +0200249 .dynamic_ps_timeout = 200,
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
Eliad Peller9fd6f212012-03-04 10:55:48 +0200395static int wl12xx_set_authorized(struct wl1271 *wl,
396 struct wl12xx_vif *wlvif)
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300397{
398 int ret;
Eliad Peller0603d892011-10-05 11:55:51 +0200399
Eliad Peller9fd6f212012-03-04 10:55:48 +0200400 if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
401 return -EINVAL;
402
403 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300404 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 +0300418
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100419static int wl1271_reg_notify(struct wiphy *wiphy,
Luciano Coelho573c67c2010-11-26 13:44:59 +0200420 struct regulatory_request *request)
421{
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100422 struct ieee80211_supported_band *band;
423 struct ieee80211_channel *ch;
424 int i;
425
426 band = wiphy->bands[IEEE80211_BAND_5GHZ];
427 for (i = 0; i < band->n_channels; i++) {
428 ch = &band->channels[i];
429 if (ch->flags & IEEE80211_CHAN_DISABLED)
430 continue;
431
432 if (ch->flags & IEEE80211_CHAN_RADAR)
433 ch->flags |= IEEE80211_CHAN_NO_IBSS |
434 IEEE80211_CHAN_PASSIVE_SCAN;
435
436 }
437
438 return 0;
439}
440
Eliad Peller9eb599e2011-10-10 10:12:59 +0200441static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
442 bool enable)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300443{
444 int ret = 0;
445
446 /* we should hold wl->mutex */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200447 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300448 if (ret < 0)
449 goto out;
450
451 if (enable)
Eliad Peller0744bdb2011-10-10 10:13:05 +0200452 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300453 else
Eliad Peller0744bdb2011-10-10 10:13:05 +0200454 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300455out:
456 return ret;
457}
458
459/*
460 * this function is being called when the rx_streaming interval
461 * has beed changed or rx_streaming should be disabled
462 */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200463int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300464{
465 int ret = 0;
466 int period = wl->conf.rx_streaming.interval;
467
468 /* don't reconfigure if rx_streaming is disabled */
Eliad Peller0744bdb2011-10-10 10:13:05 +0200469 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300470 goto out;
471
472 /* reconfigure/disable according to new streaming_period */
473 if (period &&
Eliad Pellerba8447f2011-10-10 10:13:00 +0200474 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eliad Peller77ddaa12011-05-15 11:10:29 +0300475 (wl->conf.rx_streaming.always ||
476 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
Eliad Peller9eb599e2011-10-10 10:12:59 +0200477 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300478 else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200479 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300480 /* don't cancel_work_sync since we might deadlock */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200481 del_timer_sync(&wlvif->rx_streaming_timer);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300482 }
483out:
484 return ret;
485}
486
487static void wl1271_rx_streaming_enable_work(struct work_struct *work)
488{
489 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200490 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
491 rx_streaming_enable_work);
492 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300493
494 mutex_lock(&wl->mutex);
495
Eliad Peller0744bdb2011-10-10 10:13:05 +0200496 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
Eliad Pellerba8447f2011-10-10 10:13:00 +0200497 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller77ddaa12011-05-15 11:10:29 +0300498 (!wl->conf.rx_streaming.always &&
499 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
500 goto out;
501
502 if (!wl->conf.rx_streaming.interval)
503 goto out;
504
505 ret = wl1271_ps_elp_wakeup(wl);
506 if (ret < 0)
507 goto out;
508
Eliad Peller9eb599e2011-10-10 10:12:59 +0200509 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300510 if (ret < 0)
511 goto out_sleep;
512
513 /* stop it after some time of inactivity */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200514 mod_timer(&wlvif->rx_streaming_timer,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300515 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
516
517out_sleep:
518 wl1271_ps_elp_sleep(wl);
519out:
520 mutex_unlock(&wl->mutex);
521}
522
523static void wl1271_rx_streaming_disable_work(struct work_struct *work)
524{
525 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200526 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
527 rx_streaming_disable_work);
528 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300529
530 mutex_lock(&wl->mutex);
531
Eliad Peller0744bdb2011-10-10 10:13:05 +0200532 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300533 goto out;
534
535 ret = wl1271_ps_elp_wakeup(wl);
536 if (ret < 0)
537 goto out;
538
Eliad Peller9eb599e2011-10-10 10:12:59 +0200539 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300540 if (ret)
541 goto out_sleep;
542
543out_sleep:
544 wl1271_ps_elp_sleep(wl);
545out:
546 mutex_unlock(&wl->mutex);
547}
548
549static void wl1271_rx_streaming_timer(unsigned long data)
550{
Eliad Peller9eb599e2011-10-10 10:12:59 +0200551 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
552 struct wl1271 *wl = wlvif->wl;
553 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300554}
555
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300556static void wl1271_conf_init(struct wl1271 *wl)
557{
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300558
559 /*
560 * This function applies the default configuration to the driver. This
561 * function is invoked upon driver load (spi probe.)
562 *
563 * The configuration is stored in a run-time structure in order to
564 * facilitate for run-time adjustment of any of the parameters. Making
565 * changes to the configuration structure will apply the new values on
566 * the next interface up (wl1271_op_start.)
567 */
568
569 /* apply driver default configuration */
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300570 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300571
Ido Yariv95dac04f2011-06-06 14:57:06 +0300572 /* Adjust settings according to optional module parameters */
573 if (fwlog_param) {
574 if (!strcmp(fwlog_param, "continuous")) {
575 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
576 } else if (!strcmp(fwlog_param, "ondemand")) {
577 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
578 } else if (!strcmp(fwlog_param, "dbgpins")) {
579 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
580 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
581 } else if (!strcmp(fwlog_param, "disable")) {
582 wl->conf.fwlog.mem_blocks = 0;
583 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
584 } else {
585 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
586 }
587 }
588}
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300589
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300590static int wl1271_plt_init(struct wl1271 *wl)
591{
Eliad Peller188e7f52011-12-06 12:15:06 +0200592 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300593
Shahar Levi49d750ca2011-03-06 16:32:09 +0200594 if (wl->chip.id == CHIP_ID_1283_PG20)
595 ret = wl128x_cmd_general_parms(wl);
596 else
597 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200598 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200599 return ret;
600
Shahar Levi49d750ca2011-03-06 16:32:09 +0200601 if (wl->chip.id == CHIP_ID_1283_PG20)
602 ret = wl128x_cmd_radio_parms(wl);
603 else
604 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200605 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200606 return ret;
607
Shahar Levi49d750ca2011-03-06 16:32:09 +0200608 if (wl->chip.id != CHIP_ID_1283_PG20) {
609 ret = wl1271_cmd_ext_radio_parms(wl);
610 if (ret < 0)
611 return ret;
612 }
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200613
Shahar Levi48a61472011-03-06 16:32:08 +0200614 /* Chip-specific initializations */
615 ret = wl1271_chip_specific_init(wl);
616 if (ret < 0)
617 return ret;
618
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300619 ret = wl1271_acx_init_mem_config(wl);
620 if (ret < 0)
621 return ret;
622
Eliad Peller7f0979882011-08-14 13:17:06 +0300623 ret = wl12xx_acx_mem_cfg(wl);
Gery Kahn1ec610e2011-02-01 03:03:08 -0600624 if (ret < 0)
625 goto out_free_memmap;
626
Luciano Coelho12419cc2010-02-18 13:25:44 +0200627 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200628 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300629 if (ret < 0)
Luciano Coelho12419cc2010-02-18 13:25:44 +0200630 goto out_free_memmap;
631
632 /* Configure for CAM power saving (ie. always active) */
633 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
634 if (ret < 0)
635 goto out_free_memmap;
636
637 /* configure PM */
638 ret = wl1271_acx_pm_config(wl);
639 if (ret < 0)
640 goto out_free_memmap;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300641
642 return 0;
Luciano Coelho12419cc2010-02-18 13:25:44 +0200643
644 out_free_memmap:
645 kfree(wl->target_mem_map);
646 wl->target_mem_map = NULL;
647
648 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300649}
650
Eliad Peller6e8cd332011-10-10 10:13:13 +0200651static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
652 struct wl12xx_vif *wlvif,
653 u8 hlid, u8 tx_pkts)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200654{
Arik Nemtsovda032092011-08-25 12:43:15 +0300655 bool fw_ps, single_sta;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200656
Arik Nemtsovb622d992011-02-23 00:22:31 +0200657 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Arik Nemtsovda032092011-08-25 12:43:15 +0300658 single_sta = (wl->active_sta_count == 1);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200659
660 /*
661 * Wake up from high level PS if the STA is asleep with too little
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300662 * packets in FW or if the STA is awake.
Arik Nemtsovb622d992011-02-23 00:22:31 +0200663 */
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300664 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200665 wl12xx_ps_link_end(wl, wlvif, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200666
Arik Nemtsovda032092011-08-25 12:43:15 +0300667 /*
668 * Start high-level PS if the STA is asleep with enough blocks in FW.
669 * Make an exception if this is the only connected station. In this
670 * case FW-memory congestion is not a problem.
671 */
672 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200673 wl12xx_ps_link_start(wl, wlvif, hlid, true);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200674}
675
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300676static void wl12xx_irq_update_links_status(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200677 struct wl12xx_vif *wlvif,
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300678 struct wl12xx_fw_status *status)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200679{
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200680 struct wl1271_link *lnk;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200681 u32 cur_fw_ps_map;
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300682 u8 hlid, cnt;
683
684 /* TODO: also use link_fast_bitmap here */
Arik Nemtsovb622d992011-02-23 00:22:31 +0200685
686 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
687 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
688 wl1271_debug(DEBUG_PSM,
689 "link ps prev 0x%x cur 0x%x changed 0x%x",
690 wl->ap_fw_ps_map, cur_fw_ps_map,
691 wl->ap_fw_ps_map ^ cur_fw_ps_map);
692
693 wl->ap_fw_ps_map = cur_fw_ps_map;
694 }
695
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200696 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
697 lnk = &wl->links[hlid];
698 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200699
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200700 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
701 lnk->allocated_pkts -= cnt;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200702
Eliad Peller6e8cd332011-10-10 10:13:13 +0200703 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
704 lnk->allocated_pkts);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200705 }
706}
707
Eliad Peller4d56ad92011-08-14 13:17:05 +0300708static void wl12xx_fw_status(struct wl1271 *wl,
709 struct wl12xx_fw_status *status)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300710{
Eliad Peller6e8cd332011-10-10 10:13:13 +0200711 struct wl12xx_vif *wlvif;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200712 struct timespec ts;
Shahar Levi13b107d2011-03-06 16:32:12 +0200713 u32 old_tx_blk_count = wl->tx_blocks_available;
Eliad Peller4d56ad92011-08-14 13:17:05 +0300714 int avail, freed_blocks;
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300715 int i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300716
Eliad Peller4d56ad92011-08-14 13:17:05 +0300717 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
Shahar Levi13b107d2011-03-06 16:32:12 +0200718
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300719 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
720 "drv_rx_counter = %d, tx_results_counter = %d)",
721 status->intr,
722 status->fw_rx_counter,
723 status->drv_rx_counter,
724 status->tx_results_counter);
725
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300726 for (i = 0; i < NUM_TX_QUEUES; i++) {
727 /* prevent wrap-around in freed-packets counter */
Arik Nemtsov742246f2011-08-14 13:17:33 +0300728 wl->tx_allocated_pkts[i] -=
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300729 (status->tx_released_pkts[i] -
730 wl->tx_pkts_freed[i]) & 0xff;
731
732 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
733 }
734
Arik Nemtsovbdf91cf2011-08-14 13:17:34 +0300735 /* prevent wrap-around in total blocks counter */
736 if (likely(wl->tx_blocks_freed <=
737 le32_to_cpu(status->total_released_blks)))
738 freed_blocks = le32_to_cpu(status->total_released_blks) -
739 wl->tx_blocks_freed;
740 else
741 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
742 le32_to_cpu(status->total_released_blks);
743
Eliad Peller4d56ad92011-08-14 13:17:05 +0300744 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
Shahar Levi13b107d2011-03-06 16:32:12 +0200745
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300746 wl->tx_allocated_blocks -= freed_blocks;
747
Eliad Peller4d56ad92011-08-14 13:17:05 +0300748 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200749
Eliad Peller4d56ad92011-08-14 13:17:05 +0300750 /*
751 * The FW might change the total number of TX memblocks before
752 * we get a notification about blocks being released. Thus, the
753 * available blocks calculation might yield a temporary result
754 * which is lower than the actual available blocks. Keeping in
755 * mind that only blocks that were allocated can be moved from
756 * TX to RX, tx_blocks_available should never decrease here.
757 */
758 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
759 avail);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300760
Ido Yariva5225502010-10-12 14:49:10 +0200761 /* if more blocks are available now, tx work can be scheduled */
Shahar Levi13b107d2011-03-06 16:32:12 +0200762 if (wl->tx_blocks_available > old_tx_blk_count)
Ido Yariva5225502010-10-12 14:49:10 +0200763 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300764
Eliad Peller4d56ad92011-08-14 13:17:05 +0300765 /* for AP update num of allocated TX blocks per link and ps status */
Eliad Peller6e8cd332011-10-10 10:13:13 +0200766 wl12xx_for_each_wlvif_ap(wl, wlvif) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200767 wl12xx_irq_update_links_status(wl, wlvif, status);
Eliad Peller6e8cd332011-10-10 10:13:13 +0200768 }
Eliad Peller4d56ad92011-08-14 13:17:05 +0300769
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300770 /* update the host-chipset time offset */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200771 getnstimeofday(&ts);
772 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
773 (s64)le32_to_cpu(status->fw_localtime);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300774}
775
Ido Yariva6208652011-03-01 15:14:41 +0200776static void wl1271_flush_deferred_work(struct wl1271 *wl)
777{
778 struct sk_buff *skb;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200779
Ido Yariva6208652011-03-01 15:14:41 +0200780 /* Pass all received frames to the network stack */
781 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
782 ieee80211_rx_ni(wl->hw, skb);
783
784 /* Return sent skbs to the network stack */
785 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300786 ieee80211_tx_status_ni(wl->hw, skb);
Ido Yariva6208652011-03-01 15:14:41 +0200787}
788
789static void wl1271_netstack_work(struct work_struct *work)
790{
791 struct wl1271 *wl =
792 container_of(work, struct wl1271, netstack_work);
793
794 do {
795 wl1271_flush_deferred_work(wl);
796 } while (skb_queue_len(&wl->deferred_rx_queue));
797}
798
799#define WL1271_IRQ_MAX_LOOPS 256
800
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300801static irqreturn_t wl1271_irq(int irq, void *cookie)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300802{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300803 int ret;
Juuso Oikarinenc15f63b2009-10-12 15:08:50 +0300804 u32 intr;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200805 int loopcount = WL1271_IRQ_MAX_LOOPS;
Ido Yariva6208652011-03-01 15:14:41 +0200806 struct wl1271 *wl = (struct wl1271 *)cookie;
807 bool done = false;
808 unsigned int defer_count;
Ido Yarivb07d4032011-03-01 15:14:43 +0200809 unsigned long flags;
810
811 /* TX might be handled here, avoid redundant work */
812 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
813 cancel_work_sync(&wl->tx_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300814
Ido Yariv341b7cd2011-03-31 10:07:01 +0200815 /*
816 * In case edge triggered interrupt must be used, we cannot iterate
817 * more than once without introducing race conditions with the hardirq.
818 */
819 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
820 loopcount = 1;
821
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822 mutex_lock(&wl->mutex);
823
824 wl1271_debug(DEBUG_IRQ, "IRQ work");
825
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200826 if (unlikely(wl->state == WL1271_STATE_OFF))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300827 goto out;
828
Ido Yariva6208652011-03-01 15:14:41 +0200829 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300830 if (ret < 0)
831 goto out;
832
Ido Yariva6208652011-03-01 15:14:41 +0200833 while (!done && loopcount--) {
834 /*
835 * In order to avoid a race with the hardirq, clear the flag
836 * before acknowledging the chip. Since the mutex is held,
837 * wl1271_ps_elp_wakeup cannot be called concurrently.
838 */
839 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
840 smp_mb__after_clear_bit();
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200841
Eliad Peller4d56ad92011-08-14 13:17:05 +0300842 wl12xx_fw_status(wl, wl->fw_status);
843 intr = le32_to_cpu(wl->fw_status->intr);
Ido Yariva6208652011-03-01 15:14:41 +0200844 intr &= WL1271_INTR_MASK;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200845 if (!intr) {
Ido Yariva6208652011-03-01 15:14:41 +0200846 done = true;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200847 continue;
848 }
849
Eliad Pellerccc83b02010-10-27 14:09:57 +0200850 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
851 wl1271_error("watchdog interrupt received! "
852 "starting recovery.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300853 wl12xx_queue_recovery_work(wl);
Eliad Pellerccc83b02010-10-27 14:09:57 +0200854
855 /* restarting the chip. ignore any other interrupt. */
856 goto out;
857 }
858
Ido Yariva6208652011-03-01 15:14:41 +0200859 if (likely(intr & WL1271_ACX_INTR_DATA)) {
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200860 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
861
Eliad Peller4d56ad92011-08-14 13:17:05 +0300862 wl12xx_rx(wl, wl->fw_status);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200863
Ido Yariva5225502010-10-12 14:49:10 +0200864 /* Check if any tx blocks were freed */
Ido Yarivb07d4032011-03-01 15:14:43 +0200865 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200866 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300867 wl1271_tx_total_queue_count(wl) > 0) {
Ido Yarivb07d4032011-03-01 15:14:43 +0200868 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200869 /*
870 * In order to avoid starvation of the TX path,
871 * call the work function directly.
872 */
Eliad Pellera32d0cd2011-10-10 10:12:55 +0200873 wl1271_tx_work_locked(wl);
Ido Yarivb07d4032011-03-01 15:14:43 +0200874 } else {
875 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200876 }
877
Ido Yariv8aad2462011-03-01 15:14:38 +0200878 /* check for tx results */
Eliad Peller4d56ad92011-08-14 13:17:05 +0300879 if (wl->fw_status->tx_results_counter !=
Ido Yariv8aad2462011-03-01 15:14:38 +0200880 (wl->tx_results_count & 0xff))
881 wl1271_tx_complete(wl);
Ido Yariva6208652011-03-01 15:14:41 +0200882
883 /* Make sure the deferred queues don't get too long */
884 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
885 skb_queue_len(&wl->deferred_rx_queue);
886 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
887 wl1271_flush_deferred_work(wl);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200888 }
889
890 if (intr & WL1271_ACX_INTR_EVENT_A) {
891 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
892 wl1271_event_handle(wl, 0);
893 }
894
895 if (intr & WL1271_ACX_INTR_EVENT_B) {
896 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
897 wl1271_event_handle(wl, 1);
898 }
899
900 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
901 wl1271_debug(DEBUG_IRQ,
902 "WL1271_ACX_INTR_INIT_COMPLETE");
903
904 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
905 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300906 }
907
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300908 wl1271_ps_elp_sleep(wl);
909
910out:
Ido Yarivb07d4032011-03-01 15:14:43 +0200911 spin_lock_irqsave(&wl->wl_lock, flags);
912 /* In case TX was not handled here, queue TX work */
913 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
914 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300915 wl1271_tx_total_queue_count(wl) > 0)
Ido Yarivb07d4032011-03-01 15:14:43 +0200916 ieee80211_queue_work(wl->hw, &wl->tx_work);
917 spin_unlock_irqrestore(&wl->wl_lock, flags);
918
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300919 mutex_unlock(&wl->mutex);
Ido Yariva6208652011-03-01 15:14:41 +0200920
921 return IRQ_HANDLED;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300922}
923
Eliad Peller4549d092012-02-06 13:07:52 +0200924struct vif_counter_data {
925 u8 counter;
926
927 struct ieee80211_vif *cur_vif;
928 bool cur_vif_running;
929};
930
931static void wl12xx_vif_count_iter(void *data, u8 *mac,
932 struct ieee80211_vif *vif)
933{
934 struct vif_counter_data *counter = data;
935
936 counter->counter++;
937 if (counter->cur_vif == vif)
938 counter->cur_vif_running = true;
939}
940
941/* caller must not hold wl->mutex, as it might deadlock */
942static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
943 struct ieee80211_vif *cur_vif,
944 struct vif_counter_data *data)
945{
946 memset(data, 0, sizeof(*data));
947 data->cur_vif = cur_vif;
948
949 ieee80211_iterate_active_interfaces(hw,
950 wl12xx_vif_count_iter, data);
951}
952
Eliad Peller3fcdab72012-02-06 12:47:54 +0200953static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300954{
955 const struct firmware *fw;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200956 const char *fw_name;
Eliad Peller3fcdab72012-02-06 12:47:54 +0200957 enum wl12xx_fw_type fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300958 int ret;
959
Eliad Peller3fcdab72012-02-06 12:47:54 +0200960 if (plt) {
961 fw_type = WL12XX_FW_TYPE_PLT;
962 if (wl->chip.id == CHIP_ID_1283_PG20)
963 fw_name = WL128X_PLT_FW_NAME;
964 else
965 fw_name = WL127X_PLT_FW_NAME;
966 } else {
Eliad Peller4549d092012-02-06 13:07:52 +0200967 /*
968 * we can't call wl12xx_get_vif_count() here because
969 * wl->mutex is taken, so use the cached last_vif_count value
970 */
971 if (wl->last_vif_count > 1) {
972 fw_type = WL12XX_FW_TYPE_MULTI;
973 if (wl->chip.id == CHIP_ID_1283_PG20)
974 fw_name = WL128X_FW_NAME_MULTI;
975 else
976 fw_name = WL127X_FW_NAME_MULTI;
977 } else {
978 fw_type = WL12XX_FW_TYPE_NORMAL;
979 if (wl->chip.id == CHIP_ID_1283_PG20)
980 fw_name = WL128X_FW_NAME_SINGLE;
981 else
982 fw_name = WL127X_FW_NAME_SINGLE;
983 }
Eliad Peller3fcdab72012-02-06 12:47:54 +0200984 }
985
986 if (wl->fw_type == fw_type)
987 return 0;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200988
989 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
990
Felipe Balbia390e852011-10-06 10:07:44 +0300991 ret = request_firmware(&fw, fw_name, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300992
993 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +0100994 wl1271_error("could not get firmware %s: %d", fw_name, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300995 return ret;
996 }
997
998 if (fw->size % 4) {
999 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1000 fw->size);
1001 ret = -EILSEQ;
1002 goto out;
1003 }
1004
Arik Nemtsov166d5042010-10-16 21:44:57 +02001005 vfree(wl->fw);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001006 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001007 wl->fw_len = fw->size;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +03001008 wl->fw = vmalloc(wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001009
1010 if (!wl->fw) {
1011 wl1271_error("could not allocate memory for the firmware");
1012 ret = -ENOMEM;
1013 goto out;
1014 }
1015
1016 memcpy(wl->fw, fw->data, wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001017 ret = 0;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001018 wl->fw_type = fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001019out:
1020 release_firmware(fw);
1021
1022 return ret;
1023}
1024
1025static int wl1271_fetch_nvs(struct wl1271 *wl)
1026{
1027 const struct firmware *fw;
1028 int ret;
1029
Felipe Balbia390e852011-10-06 10:07:44 +03001030 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001031
1032 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001033 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1034 ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001035 return ret;
1036 }
1037
Shahar Levibc765bf2011-03-06 16:32:10 +02001038 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001039
1040 if (!wl->nvs) {
1041 wl1271_error("could not allocate memory for the nvs file");
1042 ret = -ENOMEM;
1043 goto out;
1044 }
1045
Juuso Oikarinen02fabb02010-08-19 04:41:15 +02001046 wl->nvs_len = fw->size;
1047
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001048out:
1049 release_firmware(fw);
1050
1051 return ret;
1052}
1053
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001054void wl12xx_queue_recovery_work(struct wl1271 *wl)
1055{
1056 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1057 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1058}
1059
Ido Yariv95dac04f2011-06-06 14:57:06 +03001060size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1061{
1062 size_t len = 0;
1063
1064 /* The FW log is a length-value list, find where the log end */
1065 while (len < maxlen) {
1066 if (memblock[len] == 0)
1067 break;
1068 if (len + memblock[len] + 1 > maxlen)
1069 break;
1070 len += memblock[len] + 1;
1071 }
1072
1073 /* Make sure we have enough room */
1074 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1075
1076 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1077 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1078 wl->fwlog_size += len;
1079
1080 return len;
1081}
1082
1083static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1084{
1085 u32 addr;
1086 u32 first_addr;
1087 u8 *block;
1088
1089 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1090 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1091 (wl->conf.fwlog.mem_blocks == 0))
1092 return;
1093
1094 wl1271_info("Reading FW panic log");
1095
1096 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1097 if (!block)
1098 return;
1099
1100 /*
1101 * Make sure the chip is awake and the logger isn't active.
1102 * This might fail if the firmware hanged.
1103 */
1104 if (!wl1271_ps_elp_wakeup(wl))
1105 wl12xx_cmd_stop_fwlog(wl);
1106
1107 /* Read the first memory block address */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001108 wl12xx_fw_status(wl, wl->fw_status);
1109 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001110 if (!first_addr)
1111 goto out;
1112
1113 /* Traverse the memory blocks linked list */
1114 addr = first_addr;
1115 do {
1116 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1117 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1118 false);
1119
1120 /*
1121 * Memory blocks are linked to one another. The first 4 bytes
1122 * of each memory block hold the hardware address of the next
1123 * one. The last memory block points to the first one.
1124 */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001125 addr = le32_to_cpup((__le32 *)block);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001126 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1127 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1128 break;
1129 } while (addr && (addr != first_addr));
1130
1131 wake_up_interruptible(&wl->fwlog_waitq);
1132
1133out:
1134 kfree(block);
1135}
1136
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001137static void wl1271_recovery_work(struct work_struct *work)
1138{
1139 struct wl1271 *wl =
1140 container_of(work, struct wl1271, recovery_work);
Eliad Peller48e93e42011-10-10 10:12:58 +02001141 struct wl12xx_vif *wlvif;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001142 struct ieee80211_vif *vif;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001143
1144 mutex_lock(&wl->mutex);
1145
Eliad Peller3fcdab72012-02-06 12:47:54 +02001146 if (wl->state != WL1271_STATE_ON || wl->plt)
Eliad Pellerf0277432011-10-10 10:13:14 +02001147 goto out_unlock;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001148
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001149 /* Avoid a recursive recovery */
1150 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1151
Ido Yariv95dac04f2011-06-06 14:57:06 +03001152 wl12xx_read_fwlog_panic(wl);
1153
Arik Nemtsov52dcaf52011-04-18 14:15:24 +03001154 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1155 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001156
Eliad Pellere9ba7152012-03-04 10:55:54 +02001157 BUG_ON(bug_on_recovery &&
1158 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
Eliad Peller2a5bff02011-08-25 18:10:59 +03001159
Oz Krakowskib992c682011-06-26 10:36:02 +03001160 /*
1161 * Advance security sequence number to overcome potential progress
1162 * in the firmware during recovery. This doens't hurt if the network is
1163 * not encrypted.
1164 */
Eliad Peller48e93e42011-10-10 10:12:58 +02001165 wl12xx_for_each_wlvif(wl, wlvif) {
Eliad Pellerba8447f2011-10-10 10:13:00 +02001166 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller53d40d02011-10-10 10:13:02 +02001167 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Peller48e93e42011-10-10 10:12:58 +02001168 wlvif->tx_security_seq +=
1169 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1170 }
Oz Krakowskib992c682011-06-26 10:36:02 +03001171
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001172 /* Prevent spurious TX during FW restart */
1173 ieee80211_stop_queues(wl->hw);
1174
Luciano Coelho33c2c062011-05-10 14:46:02 +03001175 if (wl->sched_scanning) {
1176 ieee80211_sched_scan_stopped(wl->hw);
1177 wl->sched_scanning = false;
1178 }
1179
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001180 /* reboot the chipset */
Eliad Peller6e8cd332011-10-10 10:13:13 +02001181 while (!list_empty(&wl->wlvif_list)) {
1182 wlvif = list_first_entry(&wl->wlvif_list,
1183 struct wl12xx_vif, list);
1184 vif = wl12xx_wlvif_to_vif(wlvif);
1185 __wl1271_op_remove_interface(wl, vif, false);
1186 }
Eliad Pellerf0277432011-10-10 10:13:14 +02001187 mutex_unlock(&wl->mutex);
1188 wl1271_op_stop(wl->hw);
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001189
1190 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1191
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001192 ieee80211_restart_hw(wl->hw);
1193
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001194 /*
1195 * Its safe to enable TX now - the queues are stopped after a request
1196 * to restart the HW.
1197 */
1198 ieee80211_wake_queues(wl->hw);
Eliad Pellerf0277432011-10-10 10:13:14 +02001199 return;
1200out_unlock:
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001201 mutex_unlock(&wl->mutex);
1202}
1203
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001204static void wl1271_fw_wakeup(struct wl1271 *wl)
1205{
1206 u32 elp_reg;
1207
1208 elp_reg = ELPCTRL_WAKE_UP;
Juuso Oikarinen74621412009-10-12 15:08:54 +03001209 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001210}
1211
1212static int wl1271_setup(struct wl1271 *wl)
1213{
1214 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1215 if (!wl->fw_status)
1216 return -ENOMEM;
1217
1218 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1219 if (!wl->tx_res_if) {
1220 kfree(wl->fw_status);
1221 return -ENOMEM;
1222 }
1223
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001224 return 0;
1225}
1226
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001227static int wl12xx_set_power_on(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001228{
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001229 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001230
Juuso Oikarinen01ac17e2009-12-11 15:41:02 +02001231 msleep(WL1271_PRE_POWER_ON_SLEEP);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +02001232 ret = wl1271_power_on(wl);
1233 if (ret < 0)
1234 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001235 msleep(WL1271_POWER_ON_SLEEP);
Teemu Paasikivi9b280722010-02-18 13:25:56 +02001236 wl1271_io_reset(wl);
1237 wl1271_io_init(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001238
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001239 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001240
1241 /* ELP module wake up */
1242 wl1271_fw_wakeup(wl);
1243
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001244out:
1245 return ret;
1246}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001247
Eliad Peller3fcdab72012-02-06 12:47:54 +02001248static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001249{
1250 int ret = 0;
1251
1252 ret = wl12xx_set_power_on(wl);
1253 if (ret < 0)
1254 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001255
Luciano Coelhoe62c9ce2011-11-03 08:44:42 +02001256 /*
1257 * For wl127x based devices we could use the default block
1258 * size (512 bytes), but due to a bug in the sdio driver, we
1259 * need to set it explicitly after the chip is powered on. To
1260 * simplify the code and since the performance impact is
1261 * negligible, we use the same block size for all different
1262 * chip types.
1263 */
1264 if (!wl1271_set_block_size(wl))
1265 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001266
1267 switch (wl->chip.id) {
1268 case CHIP_ID_1271_PG10:
1269 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1270 wl->chip.id);
1271
1272 ret = wl1271_setup(wl);
1273 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001274 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001275 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001276 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001277
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001278 case CHIP_ID_1271_PG20:
1279 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1280 wl->chip.id);
1281
1282 ret = wl1271_setup(wl);
1283 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001284 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001285 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001286 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001287
Shahar Levi0830cee2011-03-06 16:32:20 +02001288 case CHIP_ID_1283_PG20:
1289 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1290 wl->chip.id);
1291
1292 ret = wl1271_setup(wl);
1293 if (ret < 0)
1294 goto out;
1295 break;
1296 case CHIP_ID_1283_PG10:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001297 default:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001298 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001299 ret = -ENODEV;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001300 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001301 }
1302
Eliad Peller3fcdab72012-02-06 12:47:54 +02001303 ret = wl12xx_fetch_firmware(wl, plt);
1304 if (ret < 0)
1305 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001306
1307 /* No NVS from netlink, try to get it from the filesystem */
1308 if (wl->nvs == NULL) {
1309 ret = wl1271_fetch_nvs(wl);
1310 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001311 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001312 }
1313
1314out:
1315 return ret;
1316}
1317
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001318int wl1271_plt_start(struct wl1271 *wl)
1319{
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001320 int retries = WL1271_BOOT_RETRIES;
Gery Kahn6f07b722011-07-18 14:21:49 +03001321 struct wiphy *wiphy = wl->hw->wiphy;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001322 int ret;
1323
1324 mutex_lock(&wl->mutex);
1325
1326 wl1271_notice("power up");
1327
1328 if (wl->state != WL1271_STATE_OFF) {
1329 wl1271_error("cannot go into PLT state because not "
1330 "in off state: %d", wl->state);
1331 ret = -EBUSY;
1332 goto out;
1333 }
1334
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001335 while (retries) {
1336 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001337 ret = wl12xx_chip_wakeup(wl, true);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001338 if (ret < 0)
1339 goto power_off;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001340
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001341 ret = wl1271_boot(wl);
1342 if (ret < 0)
1343 goto power_off;
1344
1345 ret = wl1271_plt_init(wl);
1346 if (ret < 0)
1347 goto irq_disable;
1348
Eliad Peller3fcdab72012-02-06 12:47:54 +02001349 wl->plt = true;
1350 wl->state = WL1271_STATE_ON;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001351 wl1271_notice("firmware booted in PLT mode (%s)",
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001352 wl->chip.fw_ver_str);
Luciano Coelhoe7ddf542011-03-10 15:24:57 +02001353
Gery Kahn6f07b722011-07-18 14:21:49 +03001354 /* update hw/fw version info in wiphy struct */
1355 wiphy->hw_version = wl->chip.id;
1356 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1357 sizeof(wiphy->fw_version));
1358
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001359 goto out;
1360
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001361irq_disable:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001362 mutex_unlock(&wl->mutex);
1363 /* Unlocking the mutex in the middle of handling is
1364 inherently unsafe. In this case we deem it safe to do,
1365 because we need to let any possibly pending IRQ out of
1366 the system (and while we are WL1271_STATE_OFF the IRQ
1367 work function will not do anything.) Also, any other
1368 possible concurrent operations will fail due to the
1369 current state, hence the wl1271 struct should be safe. */
Ido Yariva6208652011-03-01 15:14:41 +02001370 wl1271_disable_interrupts(wl);
1371 wl1271_flush_deferred_work(wl);
1372 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001373 mutex_lock(&wl->mutex);
1374power_off:
1375 wl1271_power_off(wl);
1376 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001377
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001378 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1379 WL1271_BOOT_RETRIES);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001380out:
1381 mutex_unlock(&wl->mutex);
1382
1383 return ret;
1384}
1385
Ido Yarivf3df1332012-01-11 09:42:39 +02001386int wl1271_plt_stop(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001387{
1388 int ret = 0;
1389
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001390 wl1271_notice("power down");
1391
Ido Yariv46b0cc92012-01-11 09:42:41 +02001392 /*
1393 * Interrupts must be disabled before setting the state to OFF.
1394 * Otherwise, the interrupt handler might be called and exit without
1395 * reading the interrupt status.
1396 */
1397 wl1271_disable_interrupts(wl);
Ido Yarivf3df1332012-01-11 09:42:39 +02001398 mutex_lock(&wl->mutex);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001399 if (!wl->plt) {
Ido Yarivf3df1332012-01-11 09:42:39 +02001400 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001401
1402 /*
1403 * This will not necessarily enable interrupts as interrupts
1404 * may have been disabled when op_stop was called. It will,
1405 * however, balance the above call to disable_interrupts().
1406 */
1407 wl1271_enable_interrupts(wl);
1408
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001409 wl1271_error("cannot power down because not in PLT "
1410 "state: %d", wl->state);
1411 ret = -EBUSY;
1412 goto out;
1413 }
1414
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001415 mutex_unlock(&wl->mutex);
Ido Yarivf3df1332012-01-11 09:42:39 +02001416
Ido Yariva6208652011-03-01 15:14:41 +02001417 wl1271_flush_deferred_work(wl);
1418 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001419 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001420 cancel_delayed_work_sync(&wl->elp_work);
Ido Yariva4549692012-01-11 09:42:40 +02001421
1422 mutex_lock(&wl->mutex);
1423 wl1271_power_off(wl);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001424 wl->flags = 0;
1425 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001426 wl->plt = false;
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001427 wl->rx_counter = 0;
Ido Yariva4549692012-01-11 09:42:40 +02001428 mutex_unlock(&wl->mutex);
1429
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01001430out:
1431 return ret;
1432}
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +02001433
Johannes Berg7bb45682011-02-24 14:42:06 +01001434static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001435{
1436 struct wl1271 *wl = hw->priv;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001437 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1438 struct ieee80211_vif *vif = info->control.vif;
Eliad Peller0f168012011-10-11 13:52:25 +02001439 struct wl12xx_vif *wlvif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001440 unsigned long flags;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001441 int q, mapping;
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001442 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001443
Eliad Peller0f168012011-10-11 13:52:25 +02001444 if (vif)
1445 wlvif = wl12xx_vif_to_data(vif);
1446
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001447 mapping = skb_get_queue_mapping(skb);
1448 q = wl1271_tx_get_queue(mapping);
Ido Yarivb07d4032011-03-01 15:14:43 +02001449
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001450 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
Ido Yarivb07d4032011-03-01 15:14:43 +02001451
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001452 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yarivb07d4032011-03-01 15:14:43 +02001453
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001454 /* queue the packet */
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001455 if (hlid == WL12XX_INVALID_LINK_ID ||
Eliad Peller0f168012011-10-11 13:52:25 +02001456 (wlvif && !test_bit(hlid, wlvif->links_map))) {
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001457 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
Eliad Peller5de8eef2011-12-13 15:26:38 +02001458 ieee80211_free_txskb(hw, skb);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001459 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02001460 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001461
Eliad Peller8ccd16e2012-03-04 10:55:55 +02001462 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d",
1463 hlid, q, skb->len);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001464 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1465
Arik Nemtsov04b4d692011-08-14 13:17:39 +03001466 wl->tx_queue_count[q]++;
1467
1468 /*
1469 * The workqueue is slow to process the tx_queue and we need stop
1470 * the queue here, otherwise the queue will get too long.
1471 */
1472 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1473 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1474 ieee80211_stop_queue(wl->hw, mapping);
1475 set_bit(q, &wl->stopped_queues_map);
1476 }
1477
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001478 /*
1479 * The chip specific setup must run before the first TX packet -
1480 * before that, the tx_work will not be initialized!
1481 */
1482
Ido Yarivb07d4032011-03-01 15:14:43 +02001483 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1484 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
Ido Yariva5225502010-10-12 14:49:10 +02001485 ieee80211_queue_work(wl->hw, &wl->tx_work);
Ido Yarivb07d4032011-03-01 15:14:43 +02001486
Arik Nemtsov04216da2011-08-14 13:17:38 +03001487out:
Ido Yarivb07d4032011-03-01 15:14:43 +02001488 spin_unlock_irqrestore(&wl->wl_lock, flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001489}
1490
Shahar Leviae47c452011-03-06 16:32:14 +02001491int wl1271_tx_dummy_packet(struct wl1271 *wl)
1492{
Ido Yariv990f5de2011-03-31 10:06:59 +02001493 unsigned long flags;
Arik Nemtsov14623782011-08-28 15:11:57 +03001494 int q;
1495
1496 /* no need to queue a new dummy packet if one is already pending */
1497 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1498 return 0;
1499
1500 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
Shahar Leviae47c452011-03-06 16:32:14 +02001501
Ido Yariv990f5de2011-03-31 10:06:59 +02001502 spin_lock_irqsave(&wl->wl_lock, flags);
1503 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +03001504 wl->tx_queue_count[q]++;
Ido Yariv990f5de2011-03-31 10:06:59 +02001505 spin_unlock_irqrestore(&wl->wl_lock, flags);
1506
1507 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1508 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
Eliad Pellera32d0cd2011-10-10 10:12:55 +02001509 wl1271_tx_work_locked(wl);
Ido Yariv990f5de2011-03-31 10:06:59 +02001510
1511 /*
1512 * If the FW TX is busy, TX work will be scheduled by the threaded
1513 * interrupt handler function
1514 */
1515 return 0;
1516}
1517
1518/*
1519 * The size of the dummy packet should be at least 1400 bytes. However, in
1520 * order to minimize the number of bus transactions, aligning it to 512 bytes
1521 * boundaries could be beneficial, performance wise
1522 */
1523#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1524
Luciano Coelhocf27d862011-04-01 21:08:23 +03001525static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
Ido Yariv990f5de2011-03-31 10:06:59 +02001526{
1527 struct sk_buff *skb;
1528 struct ieee80211_hdr_3addr *hdr;
1529 unsigned int dummy_packet_size;
1530
1531 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1532 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1533
1534 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
Shahar Leviae47c452011-03-06 16:32:14 +02001535 if (!skb) {
Ido Yariv990f5de2011-03-31 10:06:59 +02001536 wl1271_warning("Failed to allocate a dummy packet skb");
1537 return NULL;
Shahar Leviae47c452011-03-06 16:32:14 +02001538 }
1539
1540 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1541
1542 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1543 memset(hdr, 0, sizeof(*hdr));
1544 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
Ido Yariv990f5de2011-03-31 10:06:59 +02001545 IEEE80211_STYPE_NULLFUNC |
1546 IEEE80211_FCTL_TODS);
Shahar Leviae47c452011-03-06 16:32:14 +02001547
Ido Yariv990f5de2011-03-31 10:06:59 +02001548 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
Shahar Leviae47c452011-03-06 16:32:14 +02001549
Luciano Coelho18b92ff2011-03-21 16:35:21 +02001550 /* Dummy packets require the TID to be management */
1551 skb->priority = WL1271_TID_MGMT;
Ido Yariv990f5de2011-03-31 10:06:59 +02001552
1553 /* Initialize all fields that might be used */
Hauke Mehrtens86c438f2011-04-26 23:27:44 +02001554 skb_set_queue_mapping(skb, 0);
Ido Yariv990f5de2011-03-31 10:06:59 +02001555 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
Shahar Leviae47c452011-03-06 16:32:14 +02001556
Ido Yariv990f5de2011-03-31 10:06:59 +02001557 return skb;
Shahar Leviae47c452011-03-06 16:32:14 +02001558}
1559
Ido Yariv990f5de2011-03-31 10:06:59 +02001560
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001561#ifdef CONFIG_PM
Eyal Shapiradae728f2012-02-02 12:03:39 +02001562static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1563 struct wl12xx_vif *wlvif)
1564{
1565 int ret = 0;
1566
1567 mutex_lock(&wl->mutex);
1568
1569 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1570 goto out_unlock;
1571
1572 ret = wl1271_ps_elp_wakeup(wl);
1573 if (ret < 0)
1574 goto out_unlock;
1575
1576 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1577 wl->conf.conn.suspend_wake_up_event,
1578 wl->conf.conn.suspend_listen_interval);
1579
1580 if (ret < 0)
1581 wl1271_error("suspend: set wake up conditions failed: %d", ret);
1582
1583
1584 wl1271_ps_elp_sleep(wl);
1585
1586out_unlock:
1587 mutex_unlock(&wl->mutex);
1588 return ret;
1589
1590}
Eliad Peller94390642011-05-13 11:57:13 +03001591
Eliad Peller0603d892011-10-05 11:55:51 +02001592static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1593 struct wl12xx_vif *wlvif)
Eliad Peller94390642011-05-13 11:57:13 +03001594{
Eliad Pellere85d1622011-06-27 13:06:43 +03001595 int ret = 0;
Eliad Peller94390642011-05-13 11:57:13 +03001596
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001597 mutex_lock(&wl->mutex);
1598
Eliad Peller53d40d02011-10-10 10:13:02 +02001599 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Pellere85d1622011-06-27 13:06:43 +03001600 goto out_unlock;
1601
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001602 ret = wl1271_ps_elp_wakeup(wl);
1603 if (ret < 0)
1604 goto out_unlock;
1605
Eliad Peller0603d892011-10-05 11:55:51 +02001606 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001607
1608 wl1271_ps_elp_sleep(wl);
1609out_unlock:
1610 mutex_unlock(&wl->mutex);
1611 return ret;
1612
1613}
1614
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001615static int wl1271_configure_suspend(struct wl1271 *wl,
1616 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001617{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001618 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1619 return wl1271_configure_suspend_sta(wl, wlvif);
Eliad Peller536129c2011-10-05 11:55:45 +02001620 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
Eliad Peller0603d892011-10-05 11:55:51 +02001621 return wl1271_configure_suspend_ap(wl, wlvif);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001622 return 0;
1623}
1624
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001625static void wl1271_configure_resume(struct wl1271 *wl,
1626 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001627{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001628 int ret = 0;
Eliad Peller536129c2011-10-05 11:55:45 +02001629 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
Eyal Shapiradae728f2012-02-02 12:03:39 +02001630 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001631
Eyal Shapiradae728f2012-02-02 12:03:39 +02001632 if ((!is_ap) && (!is_sta))
Eliad Peller94390642011-05-13 11:57:13 +03001633 return;
1634
1635 mutex_lock(&wl->mutex);
1636 ret = wl1271_ps_elp_wakeup(wl);
1637 if (ret < 0)
1638 goto out;
1639
Eyal Shapiradae728f2012-02-02 12:03:39 +02001640 if (is_sta) {
1641 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1642 wl->conf.conn.wake_up_event,
1643 wl->conf.conn.listen_interval);
1644
1645 if (ret < 0)
1646 wl1271_error("resume: wake up conditions failed: %d",
1647 ret);
1648
1649 } else if (is_ap) {
1650 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1651 }
Eliad Peller94390642011-05-13 11:57:13 +03001652
1653 wl1271_ps_elp_sleep(wl);
1654out:
1655 mutex_unlock(&wl->mutex);
1656}
1657
Eliad Peller402e48612011-05-13 11:57:09 +03001658static int wl1271_op_suspend(struct ieee80211_hw *hw,
1659 struct cfg80211_wowlan *wow)
1660{
1661 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001662 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001663 int ret;
1664
Eliad Peller402e48612011-05-13 11:57:09 +03001665 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
Eliad Peller4a859df2011-06-06 12:21:52 +03001666 WARN_ON(!wow || !wow->any);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001667
Arik Nemtsovb9239b62012-02-28 00:41:33 +02001668 wl1271_tx_flush(wl);
1669
Eliad Peller4a859df2011-06-06 12:21:52 +03001670 wl->wow_enabled = true;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001671 wl12xx_for_each_wlvif(wl, wlvif) {
1672 ret = wl1271_configure_suspend(wl, wlvif);
1673 if (ret < 0) {
1674 wl1271_warning("couldn't prepare device to suspend");
1675 return ret;
1676 }
Eliad Pellerf44e5862011-05-13 11:57:11 +03001677 }
Eliad Peller4a859df2011-06-06 12:21:52 +03001678 /* flush any remaining work */
1679 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
Eliad Peller4a859df2011-06-06 12:21:52 +03001680
1681 /*
1682 * disable and re-enable interrupts in order to flush
1683 * the threaded_irq
1684 */
1685 wl1271_disable_interrupts(wl);
1686
1687 /*
1688 * set suspended flag to avoid triggering a new threaded_irq
1689 * work. no need for spinlock as interrupts are disabled.
1690 */
1691 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1692
1693 wl1271_enable_interrupts(wl);
1694 flush_work(&wl->tx_work);
Eliad Peller4a859df2011-06-06 12:21:52 +03001695 flush_delayed_work(&wl->elp_work);
1696
Eliad Peller402e48612011-05-13 11:57:09 +03001697 return 0;
1698}
1699
1700static int wl1271_op_resume(struct ieee80211_hw *hw)
1701{
1702 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001703 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001704 unsigned long flags;
1705 bool run_irq_work = false;
1706
Eliad Peller402e48612011-05-13 11:57:09 +03001707 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1708 wl->wow_enabled);
Eliad Peller4a859df2011-06-06 12:21:52 +03001709 WARN_ON(!wl->wow_enabled);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001710
1711 /*
1712 * re-enable irq_work enqueuing, and call irq_work directly if
1713 * there is a pending work.
1714 */
Eliad Peller4a859df2011-06-06 12:21:52 +03001715 spin_lock_irqsave(&wl->wl_lock, flags);
1716 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1717 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1718 run_irq_work = true;
1719 spin_unlock_irqrestore(&wl->wl_lock, flags);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001720
Eliad Peller4a859df2011-06-06 12:21:52 +03001721 if (run_irq_work) {
1722 wl1271_debug(DEBUG_MAC80211,
1723 "run postponed irq_work directly");
1724 wl1271_irq(0, wl);
1725 wl1271_enable_interrupts(wl);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001726 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02001727 wl12xx_for_each_wlvif(wl, wlvif) {
1728 wl1271_configure_resume(wl, wlvif);
1729 }
Eliad Pellerff91afc2011-06-06 12:21:53 +03001730 wl->wow_enabled = false;
Eliad Pellerf44e5862011-05-13 11:57:11 +03001731
Eliad Peller402e48612011-05-13 11:57:09 +03001732 return 0;
1733}
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001734#endif
Eliad Peller402e48612011-05-13 11:57:09 +03001735
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001736static int wl1271_op_start(struct ieee80211_hw *hw)
1737{
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001738 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1739
1740 /*
1741 * We have to delay the booting of the hardware because
1742 * we need to know the local MAC address before downloading and
1743 * initializing the firmware. The MAC address cannot be changed
1744 * after boot, and without the proper MAC address, the firmware
1745 * will not function properly.
1746 *
1747 * The MAC address is first known when the corresponding interface
1748 * is added. That is where we will initialize the hardware.
1749 */
1750
Eyal Shapirad18da7f2012-01-31 11:57:25 +02001751 return 0;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001752}
1753
1754static void wl1271_op_stop(struct ieee80211_hw *hw)
1755{
Eliad Pellerbaf62772011-10-10 10:12:52 +02001756 struct wl1271 *wl = hw->priv;
1757 int i;
1758
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001759 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
Eliad Pellerbaf62772011-10-10 10:12:52 +02001760
Ido Yariv46b0cc92012-01-11 09:42:41 +02001761 /*
1762 * Interrupts must be disabled before setting the state to OFF.
1763 * Otherwise, the interrupt handler might be called and exit without
1764 * reading the interrupt status.
1765 */
1766 wl1271_disable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001767 mutex_lock(&wl->mutex);
1768 if (wl->state == WL1271_STATE_OFF) {
1769 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001770
1771 /*
1772 * This will not necessarily enable interrupts as interrupts
1773 * may have been disabled when op_stop was called. It will,
1774 * however, balance the above call to disable_interrupts().
1775 */
1776 wl1271_enable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001777 return;
1778 }
Ido Yariv46b0cc92012-01-11 09:42:41 +02001779
Eliad Pellerbaf62772011-10-10 10:12:52 +02001780 /*
1781 * this must be before the cancel_work calls below, so that the work
1782 * functions don't perform further work.
1783 */
1784 wl->state = WL1271_STATE_OFF;
Eliad Peller10c8cd02011-10-10 10:13:06 +02001785 mutex_unlock(&wl->mutex);
1786
Eliad Pellerbaf62772011-10-10 10:12:52 +02001787 wl1271_flush_deferred_work(wl);
1788 cancel_delayed_work_sync(&wl->scan_complete_work);
1789 cancel_work_sync(&wl->netstack_work);
1790 cancel_work_sync(&wl->tx_work);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001791 cancel_delayed_work_sync(&wl->elp_work);
1792
1793 /* let's notify MAC80211 about the remaining pending TX frames */
1794 wl12xx_tx_reset(wl, true);
1795 mutex_lock(&wl->mutex);
1796
1797 wl1271_power_off(wl);
1798
1799 wl->band = IEEE80211_BAND_2GHZ;
1800
1801 wl->rx_counter = 0;
1802 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1803 wl->tx_blocks_available = 0;
1804 wl->tx_allocated_blocks = 0;
1805 wl->tx_results_count = 0;
1806 wl->tx_packets_count = 0;
1807 wl->time_offset = 0;
Eliad Pellerbaf62772011-10-10 10:12:52 +02001808 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1809 wl->ap_fw_ps_map = 0;
1810 wl->ap_ps_map = 0;
1811 wl->sched_scanning = false;
1812 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1813 memset(wl->links_map, 0, sizeof(wl->links_map));
1814 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1815 wl->active_sta_count = 0;
1816
1817 /* The system link is always allocated */
1818 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1819
1820 /*
1821 * this is performed after the cancel_work calls and the associated
1822 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1823 * get executed before all these vars have been reset.
1824 */
1825 wl->flags = 0;
1826
1827 wl->tx_blocks_freed = 0;
1828
1829 for (i = 0; i < NUM_TX_QUEUES; i++) {
1830 wl->tx_pkts_freed[i] = 0;
1831 wl->tx_allocated_pkts[i] = 0;
1832 }
1833
1834 wl1271_debugfs_reset(wl);
1835
1836 kfree(wl->fw_status);
1837 wl->fw_status = NULL;
1838 kfree(wl->tx_res_if);
1839 wl->tx_res_if = NULL;
1840 kfree(wl->target_mem_map);
1841 wl->target_mem_map = NULL;
1842
1843 mutex_unlock(&wl->mutex);
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001844}
1845
Eliad Pellere5a359f2011-10-10 10:13:15 +02001846static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1847{
1848 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1849 WL12XX_MAX_RATE_POLICIES);
1850 if (policy >= WL12XX_MAX_RATE_POLICIES)
1851 return -EBUSY;
1852
1853 __set_bit(policy, wl->rate_policies_map);
1854 *idx = policy;
1855 return 0;
1856}
1857
1858static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1859{
1860 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1861 return;
1862
1863 __clear_bit(*idx, wl->rate_policies_map);
1864 *idx = WL12XX_MAX_RATE_POLICIES;
1865}
1866
Eliad Peller536129c2011-10-05 11:55:45 +02001867static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001868{
Eliad Peller536129c2011-10-05 11:55:45 +02001869 switch (wlvif->bss_type) {
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001870 case BSS_TYPE_AP_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001871 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001872 return WL1271_ROLE_P2P_GO;
1873 else
1874 return WL1271_ROLE_AP;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001875
1876 case BSS_TYPE_STA_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001877 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001878 return WL1271_ROLE_P2P_CL;
1879 else
1880 return WL1271_ROLE_STA;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001881
Eliad Peller227e81e2011-08-14 13:17:26 +03001882 case BSS_TYPE_IBSS:
1883 return WL1271_ROLE_IBSS;
1884
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001885 default:
Eliad Peller536129c2011-10-05 11:55:45 +02001886 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001887 }
1888 return WL12XX_INVALID_ROLE_TYPE;
1889}
1890
Eliad Peller83587502011-10-10 10:12:53 +02001891static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Eliad Peller87fbcb02011-10-05 11:55:41 +02001892{
Eliad Pellere936bbe2011-10-05 11:55:56 +02001893 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02001894 int i;
Eliad Pellere936bbe2011-10-05 11:55:56 +02001895
Eliad Peller48e93e42011-10-10 10:12:58 +02001896 /* clear everything but the persistent data */
1897 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
Eliad Pellere936bbe2011-10-05 11:55:56 +02001898
1899 switch (ieee80211_vif_type_p2p(vif)) {
1900 case NL80211_IFTYPE_P2P_CLIENT:
1901 wlvif->p2p = 1;
1902 /* fall-through */
1903 case NL80211_IFTYPE_STATION:
1904 wlvif->bss_type = BSS_TYPE_STA_BSS;
1905 break;
1906 case NL80211_IFTYPE_ADHOC:
1907 wlvif->bss_type = BSS_TYPE_IBSS;
1908 break;
1909 case NL80211_IFTYPE_P2P_GO:
1910 wlvif->p2p = 1;
1911 /* fall-through */
1912 case NL80211_IFTYPE_AP:
1913 wlvif->bss_type = BSS_TYPE_AP_BSS;
1914 break;
1915 default:
1916 wlvif->bss_type = MAX_BSS_TYPE;
1917 return -EOPNOTSUPP;
1918 }
1919
Eliad Peller0603d892011-10-05 11:55:51 +02001920 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02001921 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02001922 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001923
Eliad Pellere936bbe2011-10-05 11:55:56 +02001924 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1925 wlvif->bss_type == BSS_TYPE_IBSS) {
1926 /* init sta/ibss data */
1927 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001928 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1929 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1930 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001931 } else {
1932 /* init ap data */
1933 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1934 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001935 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1936 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1937 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1938 wl12xx_allocate_rate_policy(wl,
1939 &wlvif->ap.ucast_rate_idx[i]);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001940 }
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001941
Eliad Peller83587502011-10-10 10:12:53 +02001942 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1943 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001944 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001945 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
Eliad Peller30d0c8f2011-10-05 11:55:42 +02001946 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Peller6a899792011-10-05 11:55:58 +02001947 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1948
Eliad Peller1b92f152011-10-10 10:13:09 +02001949 /*
1950 * mac80211 configures some values globally, while we treat them
1951 * per-interface. thus, on init, we have to copy them from wl
1952 */
1953 wlvif->band = wl->band;
Eliad Peller61f845f2011-10-10 10:13:10 +02001954 wlvif->channel = wl->channel;
Eliad Peller6bd65022011-10-10 10:13:11 +02001955 wlvif->power_level = wl->power_level;
Eliad Peller1b92f152011-10-10 10:13:09 +02001956
Eliad Peller9eb599e2011-10-10 10:12:59 +02001957 INIT_WORK(&wlvif->rx_streaming_enable_work,
1958 wl1271_rx_streaming_enable_work);
1959 INIT_WORK(&wlvif->rx_streaming_disable_work,
1960 wl1271_rx_streaming_disable_work);
Eliad Peller87627212011-10-10 10:12:54 +02001961 INIT_LIST_HEAD(&wlvif->list);
Eliad Peller252efa42011-10-05 11:56:00 +02001962
Eliad Peller9eb599e2011-10-10 10:12:59 +02001963 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1964 (unsigned long) wlvif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001965 return 0;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001966}
1967
Eliad Peller1d095472011-10-10 10:12:49 +02001968static bool wl12xx_init_fw(struct wl1271 *wl)
1969{
1970 int retries = WL1271_BOOT_RETRIES;
1971 bool booted = false;
1972 struct wiphy *wiphy = wl->hw->wiphy;
1973 int ret;
1974
1975 while (retries) {
1976 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001977 ret = wl12xx_chip_wakeup(wl, false);
Eliad Peller1d095472011-10-10 10:12:49 +02001978 if (ret < 0)
1979 goto power_off;
1980
1981 ret = wl1271_boot(wl);
1982 if (ret < 0)
1983 goto power_off;
1984
1985 ret = wl1271_hw_init(wl);
1986 if (ret < 0)
1987 goto irq_disable;
1988
1989 booted = true;
1990 break;
1991
1992irq_disable:
1993 mutex_unlock(&wl->mutex);
1994 /* Unlocking the mutex in the middle of handling is
1995 inherently unsafe. In this case we deem it safe to do,
1996 because we need to let any possibly pending IRQ out of
1997 the system (and while we are WL1271_STATE_OFF the IRQ
1998 work function will not do anything.) Also, any other
1999 possible concurrent operations will fail due to the
2000 current state, hence the wl1271 struct should be safe. */
2001 wl1271_disable_interrupts(wl);
2002 wl1271_flush_deferred_work(wl);
2003 cancel_work_sync(&wl->netstack_work);
2004 mutex_lock(&wl->mutex);
2005power_off:
2006 wl1271_power_off(wl);
2007 }
2008
2009 if (!booted) {
2010 wl1271_error("firmware boot failed despite %d retries",
2011 WL1271_BOOT_RETRIES);
2012 goto out;
2013 }
2014
2015 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
2016
2017 /* update hw/fw version info in wiphy struct */
2018 wiphy->hw_version = wl->chip.id;
2019 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
2020 sizeof(wiphy->fw_version));
2021
2022 /*
2023 * Now we know if 11a is supported (info from the NVS), so disable
2024 * 11a channels if not supported
2025 */
2026 if (!wl->enable_11a)
2027 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2028
2029 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2030 wl->enable_11a ? "" : "not ");
2031
2032 wl->state = WL1271_STATE_ON;
2033out:
2034 return booted;
2035}
2036
Eliad Peller92e712d2011-12-18 20:25:43 +02002037static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2038{
2039 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2040}
2041
Eliad Peller4549d092012-02-06 13:07:52 +02002042/*
2043 * Check whether a fw switch (i.e. moving from one loaded
2044 * fw to another) is needed. This function is also responsible
2045 * for updating wl->last_vif_count, so it must be called before
2046 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2047 * will be used).
2048 */
2049static bool wl12xx_need_fw_change(struct wl1271 *wl,
2050 struct vif_counter_data vif_counter_data,
2051 bool add)
2052{
2053 enum wl12xx_fw_type current_fw = wl->fw_type;
2054 u8 vif_count = vif_counter_data.counter;
2055
2056 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
2057 return false;
2058
2059 /* increase the vif count if this is a new vif */
2060 if (add && !vif_counter_data.cur_vif_running)
2061 vif_count++;
2062
2063 wl->last_vif_count = vif_count;
2064
2065 /* no need for fw change if the device is OFF */
2066 if (wl->state == WL1271_STATE_OFF)
2067 return false;
2068
2069 if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
2070 return true;
2071 if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
2072 return true;
2073
2074 return false;
2075}
2076
Eliad Peller3dee4392012-02-06 12:47:56 +02002077/*
2078 * Enter "forced psm". Make sure the sta is in psm against the ap,
2079 * to make the fw switch a bit more disconnection-persistent.
2080 */
2081static void wl12xx_force_active_psm(struct wl1271 *wl)
2082{
2083 struct wl12xx_vif *wlvif;
2084
2085 wl12xx_for_each_wlvif_sta(wl, wlvif) {
2086 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
2087 }
2088}
2089
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002090static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2091 struct ieee80211_vif *vif)
2092{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002093 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002094 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller4549d092012-02-06 13:07:52 +02002095 struct vif_counter_data vif_count;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002096 int ret = 0;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002097 u8 role_type;
Eliad Peller71125ab2010-10-28 21:46:43 +02002098 bool booted = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002099
Johannes Bergea086352012-01-19 09:29:58 +01002100 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2101 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Johannes Bergc1288b12012-01-19 09:29:57 +01002102
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002103 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
Eliad Peller045c7452011-08-28 15:23:01 +03002104 ieee80211_vif_type_p2p(vif), vif->addr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002105
Eliad Peller4549d092012-02-06 13:07:52 +02002106 wl12xx_get_vif_count(hw, vif, &vif_count);
2107
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002108 mutex_lock(&wl->mutex);
Eliad Pellerf750c822011-10-10 10:13:16 +02002109 ret = wl1271_ps_elp_wakeup(wl);
2110 if (ret < 0)
2111 goto out_unlock;
2112
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002113 /*
2114 * in some very corner case HW recovery scenarios its possible to
2115 * get here before __wl1271_op_remove_interface is complete, so
2116 * opt out if that is the case.
2117 */
Eliad Peller10c8cd02011-10-10 10:13:06 +02002118 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2119 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002120 ret = -EBUSY;
2121 goto out;
2122 }
2123
Eliad Peller3fcdab72012-02-06 12:47:54 +02002124
Eliad Peller83587502011-10-10 10:12:53 +02002125 ret = wl12xx_init_vif_data(wl, vif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002126 if (ret < 0)
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002127 goto out;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002128
Eliad Peller252efa42011-10-05 11:56:00 +02002129 wlvif->wl = wl;
Eliad Peller536129c2011-10-05 11:55:45 +02002130 role_type = wl12xx_get_role_type(wl, wlvif);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002131 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2132 ret = -EINVAL;
2133 goto out;
2134 }
Eliad Peller1d095472011-10-10 10:12:49 +02002135
Eliad Peller4549d092012-02-06 13:07:52 +02002136 if (wl12xx_need_fw_change(wl, vif_count, true)) {
Eliad Peller3dee4392012-02-06 12:47:56 +02002137 wl12xx_force_active_psm(wl);
Eliad Pellere9ba7152012-03-04 10:55:54 +02002138 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
Eliad Peller4549d092012-02-06 13:07:52 +02002139 mutex_unlock(&wl->mutex);
2140 wl1271_recovery_work(&wl->recovery_work);
2141 return 0;
2142 }
2143
Eliad Peller784f6942011-10-05 11:55:39 +02002144 /*
Eliad Peller1d095472011-10-10 10:12:49 +02002145 * TODO: after the nvs issue will be solved, move this block
2146 * to start(), and make sure here the driver is ON.
Eliad Peller784f6942011-10-05 11:55:39 +02002147 */
Eliad Peller1d095472011-10-10 10:12:49 +02002148 if (wl->state == WL1271_STATE_OFF) {
2149 /*
2150 * we still need this in order to configure the fw
2151 * while uploading the nvs
2152 */
Luciano Coelho5e037e72011-12-23 09:32:17 +02002153 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002154
Eliad Peller1d095472011-10-10 10:12:49 +02002155 booted = wl12xx_init_fw(wl);
2156 if (!booted) {
2157 ret = -EINVAL;
2158 goto out;
Eliad Peller04e80792011-08-14 13:17:09 +03002159 }
Eliad Peller1d095472011-10-10 10:12:49 +02002160 }
Eliad Peller04e80792011-08-14 13:17:09 +03002161
Eliad Peller1d095472011-10-10 10:12:49 +02002162 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2163 wlvif->bss_type == BSS_TYPE_IBSS) {
2164 /*
2165 * The device role is a special role used for
2166 * rx and tx frames prior to association (as
2167 * the STA role can get packets only from
2168 * its associated bssid)
2169 */
Eliad Peller784f6942011-10-05 11:55:39 +02002170 ret = wl12xx_cmd_role_enable(wl, vif->addr,
Eliad Peller1d095472011-10-10 10:12:49 +02002171 WL1271_ROLE_DEVICE,
2172 &wlvif->dev_role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002173 if (ret < 0)
Eliad Peller1d095472011-10-10 10:12:49 +02002174 goto out;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02002175 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002176
Eliad Peller1d095472011-10-10 10:12:49 +02002177 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2178 role_type, &wlvif->role_id);
2179 if (ret < 0)
Eliad Peller71125ab2010-10-28 21:46:43 +02002180 goto out;
Eliad Peller1d095472011-10-10 10:12:49 +02002181
2182 ret = wl1271_init_vif_specific(wl, vif);
2183 if (ret < 0)
2184 goto out;
Eliad Peller71125ab2010-10-28 21:46:43 +02002185
Eliad Peller87627212011-10-10 10:12:54 +02002186 list_add(&wlvif->list, &wl->wlvif_list);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002187 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
Eliad Pellera4e41302011-10-11 11:49:15 +02002188
2189 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2190 wl->ap_count++;
2191 else
2192 wl->sta_count++;
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +03002193out:
Eliad Pellerf750c822011-10-10 10:13:16 +02002194 wl1271_ps_elp_sleep(wl);
2195out_unlock:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002196 mutex_unlock(&wl->mutex);
2197
2198 return ret;
2199}
2200
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002201static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +02002202 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002203 bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002204{
Eliad Peller536129c2011-10-05 11:55:45 +02002205 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02002206 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002207
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002208 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002209
Eliad Peller10c8cd02011-10-10 10:13:06 +02002210 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2211 return;
2212
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002213 /* because of hardware recovery, we may get here twice */
2214 if (wl->state != WL1271_STATE_ON)
2215 return;
2216
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002217 wl1271_info("down");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002218
Eliad Pellerbaf62772011-10-10 10:12:52 +02002219 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2220 wl->scan_vif == vif) {
Luciano Coelho08688d62010-07-08 17:50:07 +03002221 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +02002222 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02002223 wl->scan_vif = NULL;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002224 wl->scan.req = NULL;
Juuso Oikarinen76a029f2010-07-29 04:54:45 +03002225 ieee80211_scan_completed(wl->hw, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002226 }
2227
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002228 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2229 /* disable active roles */
2230 ret = wl1271_ps_elp_wakeup(wl);
2231 if (ret < 0)
2232 goto deinit;
2233
Eliad Pellerb890f4c2011-12-18 20:25:44 +02002234 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2235 wlvif->bss_type == BSS_TYPE_IBSS) {
2236 if (wl12xx_dev_role_started(wlvif))
2237 wl12xx_stop_dev(wl, wlvif);
2238
Eliad Peller7edebf52011-10-05 11:55:52 +02002239 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +03002240 if (ret < 0)
2241 goto deinit;
2242 }
2243
Eliad Peller0603d892011-10-05 11:55:51 +02002244 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002245 if (ret < 0)
2246 goto deinit;
2247
2248 wl1271_ps_elp_sleep(wl);
2249 }
2250deinit:
Arik Nemtsove51ae9b2011-08-14 13:17:21 +03002251 /* clear all hlids (except system_hlid) */
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02002252 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002253
2254 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2255 wlvif->bss_type == BSS_TYPE_IBSS) {
2256 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2257 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2258 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2259 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2260 } else {
2261 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2262 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2263 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2264 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2265 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2266 wl12xx_free_rate_policy(wl,
2267 &wlvif->ap.ucast_rate_idx[i]);
2268 }
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002269
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02002270 wl12xx_tx_reset_wlvif(wl, wlvif);
Eliad Peller170d0e62011-10-05 11:56:06 +02002271 wl1271_free_ap_keys(wl, wlvif);
Eliad Pellere4120df2011-10-10 10:13:17 +02002272 if (wl->last_wlvif == wlvif)
2273 wl->last_wlvif = NULL;
Eliad Peller87627212011-10-10 10:12:54 +02002274 list_del(&wlvif->list);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02002275 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
Eliad Peller0603d892011-10-05 11:55:51 +02002276 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02002277 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Luciano Coelhod6e19d12009-10-12 15:08:43 +03002278
Eliad Pellera4e41302011-10-11 11:49:15 +02002279 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2280 wl->ap_count--;
2281 else
2282 wl->sta_count--;
2283
Eliad Pellerbaf62772011-10-10 10:12:52 +02002284 mutex_unlock(&wl->mutex);
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02002285
Eliad Peller9eb599e2011-10-10 10:12:59 +02002286 del_timer_sync(&wlvif->rx_streaming_timer);
2287 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2288 cancel_work_sync(&wlvif->rx_streaming_disable_work);
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03002289
Eliad Pellerbaf62772011-10-10 10:12:52 +02002290 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002291}
Juuso Oikarinenbd9dc492010-04-09 11:07:26 +03002292
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002293static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2294 struct ieee80211_vif *vif)
2295{
2296 struct wl1271 *wl = hw->priv;
Eliad Peller10c8cd02011-10-10 10:13:06 +02002297 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002298 struct wl12xx_vif *iter;
Eliad Peller4549d092012-02-06 13:07:52 +02002299 struct vif_counter_data vif_count;
2300 bool cancel_recovery = true;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002301
Eliad Peller4549d092012-02-06 13:07:52 +02002302 wl12xx_get_vif_count(hw, vif, &vif_count);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002303 mutex_lock(&wl->mutex);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002304
2305 if (wl->state == WL1271_STATE_OFF ||
2306 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2307 goto out;
2308
Juuso Oikarinen67353292010-11-18 15:19:02 +02002309 /*
2310 * wl->vif can be null here if someone shuts down the interface
2311 * just when hardware recovery has been started.
2312 */
Eliad Peller6e8cd332011-10-10 10:13:13 +02002313 wl12xx_for_each_wlvif(wl, iter) {
2314 if (iter != wlvif)
2315 continue;
2316
Eliad Peller536129c2011-10-05 11:55:45 +02002317 __wl1271_op_remove_interface(wl, vif, true);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002318 break;
Juuso Oikarinen67353292010-11-18 15:19:02 +02002319 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02002320 WARN_ON(iter != wlvif);
Eliad Peller4549d092012-02-06 13:07:52 +02002321 if (wl12xx_need_fw_change(wl, vif_count, false)) {
Eliad Peller3dee4392012-02-06 12:47:56 +02002322 wl12xx_force_active_psm(wl);
Eliad Pellere9ba7152012-03-04 10:55:54 +02002323 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
Eliad Peller4549d092012-02-06 13:07:52 +02002324 wl12xx_queue_recovery_work(wl);
2325 cancel_recovery = false;
2326 }
Eliad Peller10c8cd02011-10-10 10:13:06 +02002327out:
Juuso Oikarinen67353292010-11-18 15:19:02 +02002328 mutex_unlock(&wl->mutex);
Eliad Peller4549d092012-02-06 13:07:52 +02002329 if (cancel_recovery)
2330 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002331}
2332
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002333static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2334 struct ieee80211_vif *vif,
2335 enum nl80211_iftype new_type, bool p2p)
2336{
Eliad Peller4549d092012-02-06 13:07:52 +02002337 struct wl1271 *wl = hw->priv;
2338 int ret;
2339
2340 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002341 wl1271_op_remove_interface(hw, vif);
2342
Eliad Peller249e9692012-03-04 10:55:50 +02002343 vif->type = new_type;
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002344 vif->p2p = p2p;
Eliad Peller4549d092012-02-06 13:07:52 +02002345 ret = wl1271_op_add_interface(hw, vif);
2346
2347 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2348 return ret;
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002349}
2350
Eliad Peller87fbcb02011-10-05 11:55:41 +02002351static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2352 bool set_assoc)
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002353{
2354 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002355 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002356
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002357 /*
2358 * One of the side effects of the JOIN command is that is clears
2359 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2360 * to a WPA/WPA2 access point will therefore kill the data-path.
Ohad Ben-Cohen8bf69aa2011-03-30 19:18:31 +02002361 * Currently the only valid scenario for JOIN during association
2362 * is on roaming, in which case we will also be given new keys.
2363 * Keep the below message for now, unless it starts bothering
2364 * users who really like to roam a lot :)
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002365 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002366 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002367 wl1271_info("JOIN while associated.");
2368
Eliad Peller5ec8a442012-02-02 12:22:09 +02002369 /* clear encryption type */
2370 wlvif->encryption_type = KEY_NONE;
2371
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002372 if (set_assoc)
Eliad Pellerba8447f2011-10-10 10:13:00 +02002373 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002374
Eliad Peller227e81e2011-08-14 13:17:26 +03002375 if (is_ibss)
Eliad Peller87fbcb02011-10-05 11:55:41 +02002376 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03002377 else
Eliad Peller87fbcb02011-10-05 11:55:41 +02002378 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002379 if (ret < 0)
2380 goto out;
2381
Eliad Pellerba8447f2011-10-10 10:13:00 +02002382 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002383 goto out;
2384
2385 /*
2386 * The join command disable the keep-alive mode, shut down its process,
2387 * and also clear the template config, so we need to reset it all after
2388 * the join. The acx_aid starts the keep-alive process, and the order
2389 * of the commands below is relevant.
2390 */
Eliad Peller0603d892011-10-05 11:55:51 +02002391 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002392 if (ret < 0)
2393 goto out;
2394
Eliad Peller0603d892011-10-05 11:55:51 +02002395 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002396 if (ret < 0)
2397 goto out;
2398
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002399 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002400 if (ret < 0)
2401 goto out;
2402
Eliad Peller0603d892011-10-05 11:55:51 +02002403 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2404 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002405 ACX_KEEP_ALIVE_TPL_VALID);
2406 if (ret < 0)
2407 goto out;
2408
2409out:
2410 return ret;
2411}
2412
Eliad Peller0603d892011-10-05 11:55:51 +02002413static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002414{
2415 int ret;
2416
Eliad Peller52630c52011-10-10 10:13:08 +02002417 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02002418 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2419
Shahar Levi6d158ff2011-09-08 13:01:33 +03002420 wl12xx_cmd_stop_channel_switch(wl);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002421 ieee80211_chswitch_done(vif, false);
Shahar Levi6d158ff2011-09-08 13:01:33 +03002422 }
2423
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002424 /* to stop listening to a channel, we disconnect */
Eliad Peller0603d892011-10-05 11:55:51 +02002425 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002426 if (ret < 0)
2427 goto out;
2428
Oz Krakowskib992c682011-06-26 10:36:02 +03002429 /* reset TX security counters on a clean disconnect */
Eliad Peller48e93e42011-10-10 10:12:58 +02002430 wlvif->tx_security_last_seq_lsb = 0;
2431 wlvif->tx_security_seq = 0;
Oz Krakowskib992c682011-06-26 10:36:02 +03002432
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002433out:
2434 return ret;
2435}
2436
Eliad Peller87fbcb02011-10-05 11:55:41 +02002437static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002438{
Eliad Peller1b92f152011-10-10 10:13:09 +02002439 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002440 wlvif->rate_set = wlvif->basic_rate_set;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002441}
2442
Eliad Peller87fbcb02011-10-05 11:55:41 +02002443static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2444 bool idle)
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002445{
2446 int ret;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002447 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2448
2449 if (idle == cur_idle)
2450 return 0;
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002451
2452 if (idle) {
Eliad Peller251c1772011-08-14 13:17:17 +03002453 /* no need to croc if we weren't busy (e.g. during boot) */
Eliad Peller92e712d2011-12-18 20:25:43 +02002454 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002455 ret = wl12xx_stop_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002456 if (ret < 0)
2457 goto out;
2458 }
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002459 wlvif->rate_set =
2460 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2461 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002462 if (ret < 0)
2463 goto out;
2464 ret = wl1271_acx_keep_alive_config(
Eliad Peller0603d892011-10-05 11:55:51 +02002465 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002466 ACX_KEEP_ALIVE_TPL_INVALID);
2467 if (ret < 0)
2468 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002469 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002470 } else {
Luciano Coelho33c2c062011-05-10 14:46:02 +03002471 /* The current firmware only supports sched_scan in idle */
2472 if (wl->sched_scanning) {
2473 wl1271_scan_sched_scan_stop(wl);
2474 ieee80211_sched_scan_stopped(wl->hw);
2475 }
2476
Eliad Peller679a6732011-10-11 11:55:44 +02002477 ret = wl12xx_start_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002478 if (ret < 0)
2479 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002480 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002481 }
2482
2483out:
2484 return ret;
2485}
2486
Eliad Peller9f259c42011-10-10 10:13:12 +02002487static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2488 struct ieee80211_conf *conf, u32 changed)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002489{
Eliad Peller9f259c42011-10-10 10:13:12 +02002490 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2491 int channel, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002492
2493 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2494
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002495 /* if the channel changes while joined, join again */
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002496 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
Eliad Peller1b92f152011-10-10 10:13:09 +02002497 ((wlvif->band != conf->channel->band) ||
Eliad Peller61f845f2011-10-10 10:13:10 +02002498 (wlvif->channel != channel))) {
Eliad Pellerc6930b02011-09-15 13:00:01 +03002499 /* send all pending packets */
Eliad Pellera32d0cd2011-10-10 10:12:55 +02002500 wl1271_tx_work_locked(wl);
Eliad Peller61f845f2011-10-10 10:13:10 +02002501 wlvif->band = conf->channel->band;
2502 wlvif->channel = channel;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002503
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002504 if (!is_ap) {
2505 /*
2506 * FIXME: the mac80211 should really provide a fixed
2507 * rate to use here. for now, just use the smallest
2508 * possible rate for the band as a fixed rate for
2509 * association frames and other control messages.
2510 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002511 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Peller87fbcb02011-10-05 11:55:41 +02002512 wl1271_set_band_rate(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002513
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002514 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02002515 wl1271_tx_min_rate_get(wl,
2516 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002517 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002518 if (ret < 0)
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002519 wl1271_warning("rate policy for channel "
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002520 "failed %d", ret);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002521
Eliad Peller121af042012-03-04 10:55:51 +02002522 /*
2523 * change the ROC channel. do it only if we are
2524 * not idle. otherwise, CROC will be called
2525 * anyway.
2526 */
2527 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2528 &wlvif->flags) &&
2529 wl12xx_dev_role_started(wlvif) &&
2530 !(conf->flags & IEEE80211_CONF_IDLE)) {
2531 ret = wl12xx_stop_dev(wl, wlvif);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002532 if (ret < 0)
Eliad Peller121af042012-03-04 10:55:51 +02002533 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002534
Eliad Peller121af042012-03-04 10:55:51 +02002535 ret = wl12xx_start_dev(wl, wlvif);
2536 if (ret < 0)
2537 return ret;
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002538 }
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002539 }
2540 }
2541
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002542 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002543
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002544 if ((conf->flags & IEEE80211_CONF_PS) &&
2545 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002546 !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002547
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002548 int ps_mode;
2549 char *ps_mode_str;
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002550
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002551 if (wl->conf.conn.forced_ps) {
2552 ps_mode = STATION_POWER_SAVE_MODE;
2553 ps_mode_str = "forced";
2554 } else {
2555 ps_mode = STATION_AUTO_PS_MODE;
2556 ps_mode_str = "auto";
2557 }
2558
2559 wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
2560
2561 ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
2562
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002563 if (ret < 0)
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002564 wl1271_warning("enter %s ps failed %d",
2565 ps_mode_str, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002566
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002567 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002568 test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002569
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002570 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2571
Eliad Peller0603d892011-10-05 11:55:51 +02002572 ret = wl1271_ps_set_mode(wl, wlvif,
Eyal Shapira248a0012012-01-31 11:57:23 +02002573 STATION_ACTIVE_MODE);
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002574 if (ret < 0)
2575 wl1271_warning("exit auto ps failed %d", ret);
2576 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002577 }
2578
Eliad Peller6bd65022011-10-10 10:13:11 +02002579 if (conf->power_level != wlvif->power_level) {
Eliad Peller0603d892011-10-05 11:55:51 +02002580 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002581 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002582 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002583
Eliad Peller6bd65022011-10-10 10:13:11 +02002584 wlvif->power_level = conf->power_level;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002585 }
2586
Eliad Peller9f259c42011-10-10 10:13:12 +02002587 return 0;
2588}
2589
2590static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2591{
2592 struct wl1271 *wl = hw->priv;
2593 struct wl12xx_vif *wlvif;
2594 struct ieee80211_conf *conf = &hw->conf;
2595 int channel, ret = 0;
2596
2597 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2598
2599 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2600 " changed 0x%x",
2601 channel,
2602 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2603 conf->power_level,
2604 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2605 changed);
2606
2607 /*
2608 * mac80211 will go to idle nearly immediately after transmitting some
2609 * frames, such as the deauth. To make sure those frames reach the air,
2610 * wait here until the TX queue is fully flushed.
2611 */
2612 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2613 (conf->flags & IEEE80211_CONF_IDLE))
2614 wl1271_tx_flush(wl);
2615
2616 mutex_lock(&wl->mutex);
2617
2618 /* we support configuring the channel and band even while off */
2619 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2620 wl->band = conf->channel->band;
2621 wl->channel = channel;
2622 }
2623
2624 if (changed & IEEE80211_CONF_CHANGE_POWER)
2625 wl->power_level = conf->power_level;
2626
2627 if (unlikely(wl->state == WL1271_STATE_OFF))
2628 goto out;
2629
2630 ret = wl1271_ps_elp_wakeup(wl);
2631 if (ret < 0)
2632 goto out;
2633
2634 /* configure each interface */
2635 wl12xx_for_each_wlvif(wl, wlvif) {
2636 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2637 if (ret < 0)
2638 goto out_sleep;
2639 }
2640
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002641out_sleep:
2642 wl1271_ps_elp_sleep(wl);
2643
2644out:
2645 mutex_unlock(&wl->mutex);
2646
2647 return ret;
2648}
2649
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002650struct wl1271_filter_params {
2651 bool enabled;
2652 int mc_list_length;
2653 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2654};
2655
Jiri Pirko22bedad2010-04-01 21:22:57 +00002656static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2657 struct netdev_hw_addr_list *mc_list)
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002658{
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002659 struct wl1271_filter_params *fp;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002660 struct netdev_hw_addr *ha;
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002661 struct wl1271 *wl = hw->priv;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002662
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002663 if (unlikely(wl->state == WL1271_STATE_OFF))
2664 return 0;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002665
Juuso Oikarinen74441132009-10-13 12:47:53 +03002666 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002667 if (!fp) {
2668 wl1271_error("Out of memory setting filters.");
2669 return 0;
2670 }
2671
2672 /* update multicast filtering parameters */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002673 fp->mc_list_length = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002674 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2675 fp->enabled = false;
2676 } else {
2677 fp->enabled = true;
2678 netdev_hw_addr_list_for_each(ha, mc_list) {
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002679 memcpy(fp->mc_list[fp->mc_list_length],
Jiri Pirko22bedad2010-04-01 21:22:57 +00002680 ha->addr, ETH_ALEN);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002681 fp->mc_list_length++;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002682 }
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002683 }
2684
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002685 return (u64)(unsigned long)fp;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002686}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002687
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002688#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2689 FIF_ALLMULTI | \
2690 FIF_FCSFAIL | \
2691 FIF_BCN_PRBRESP_PROMISC | \
2692 FIF_CONTROL | \
2693 FIF_OTHER_BSS)
2694
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002695static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2696 unsigned int changed,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002697 unsigned int *total, u64 multicast)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002698{
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002699 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002700 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02002701 struct wl12xx_vif *wlvif;
Eliad Peller536129c2011-10-05 11:55:45 +02002702
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002703 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002704
Arik Nemtsov7d057862010-10-16 19:25:35 +02002705 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2706 " total %x", changed, *total);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002707
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002708 mutex_lock(&wl->mutex);
2709
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002710 *total &= WL1271_SUPPORTED_FILTERS;
2711 changed &= WL1271_SUPPORTED_FILTERS;
2712
2713 if (unlikely(wl->state == WL1271_STATE_OFF))
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002714 goto out;
2715
Ido Yariva6208652011-03-01 15:14:41 +02002716 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002717 if (ret < 0)
2718 goto out;
2719
Eliad Peller6e8cd332011-10-10 10:13:13 +02002720 wl12xx_for_each_wlvif(wl, wlvif) {
2721 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2722 if (*total & FIF_ALLMULTI)
2723 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2724 false,
2725 NULL, 0);
2726 else if (fp)
2727 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2728 fp->enabled,
2729 fp->mc_list,
2730 fp->mc_list_length);
2731 if (ret < 0)
2732 goto out_sleep;
2733 }
Arik Nemtsov7d057862010-10-16 19:25:35 +02002734 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002735
Eliad Peller08c1d1c2011-08-14 13:17:04 +03002736 /*
2737 * the fw doesn't provide an api to configure the filters. instead,
2738 * the filters configuration is based on the active roles / ROC
2739 * state.
2740 */
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002741
2742out_sleep:
2743 wl1271_ps_elp_sleep(wl);
2744
2745out:
2746 mutex_unlock(&wl->mutex);
Juuso Oikarinen14b228a2010-03-18 12:26:43 +02002747 kfree(fp);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002748}
2749
Eliad Peller170d0e62011-10-05 11:56:06 +02002750static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2751 u8 id, u8 key_type, u8 key_size,
2752 const u8 *key, u8 hlid, u32 tx_seq_32,
2753 u16 tx_seq_16)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002754{
2755 struct wl1271_ap_key *ap_key;
2756 int i;
2757
2758 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2759
2760 if (key_size > MAX_KEY_SIZE)
2761 return -EINVAL;
2762
2763 /*
2764 * Find next free entry in ap_keys. Also check we are not replacing
2765 * an existing key.
2766 */
2767 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002768 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002769 break;
2770
Eliad Peller170d0e62011-10-05 11:56:06 +02002771 if (wlvif->ap.recorded_keys[i]->id == id) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002772 wl1271_warning("trying to record key replacement");
2773 return -EINVAL;
2774 }
2775 }
2776
2777 if (i == MAX_NUM_KEYS)
2778 return -EBUSY;
2779
2780 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2781 if (!ap_key)
2782 return -ENOMEM;
2783
2784 ap_key->id = id;
2785 ap_key->key_type = key_type;
2786 ap_key->key_size = key_size;
2787 memcpy(ap_key->key, key, key_size);
2788 ap_key->hlid = hlid;
2789 ap_key->tx_seq_32 = tx_seq_32;
2790 ap_key->tx_seq_16 = tx_seq_16;
2791
Eliad Peller170d0e62011-10-05 11:56:06 +02002792 wlvif->ap.recorded_keys[i] = ap_key;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002793 return 0;
2794}
2795
Eliad Peller170d0e62011-10-05 11:56:06 +02002796static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002797{
2798 int i;
2799
2800 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002801 kfree(wlvif->ap.recorded_keys[i]);
2802 wlvif->ap.recorded_keys[i] = NULL;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002803 }
2804}
2805
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002806static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002807{
2808 int i, ret = 0;
2809 struct wl1271_ap_key *key;
2810 bool wep_key_added = false;
2811
2812 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller7f97b482011-08-14 13:17:30 +03002813 u8 hlid;
Eliad Peller170d0e62011-10-05 11:56:06 +02002814 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002815 break;
2816
Eliad Peller170d0e62011-10-05 11:56:06 +02002817 key = wlvif->ap.recorded_keys[i];
Eliad Peller7f97b482011-08-14 13:17:30 +03002818 hlid = key->hlid;
2819 if (hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002820 hlid = wlvif->ap.bcast_hlid;
Eliad Peller7f97b482011-08-14 13:17:30 +03002821
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002822 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002823 key->id, key->key_type,
2824 key->key_size, key->key,
Eliad Peller7f97b482011-08-14 13:17:30 +03002825 hlid, key->tx_seq_32,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002826 key->tx_seq_16);
2827 if (ret < 0)
2828 goto out;
2829
2830 if (key->key_type == KEY_WEP)
2831 wep_key_added = true;
2832 }
2833
2834 if (wep_key_added) {
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002835 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002836 wlvif->ap.bcast_hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002837 if (ret < 0)
2838 goto out;
2839 }
2840
2841out:
Eliad Peller170d0e62011-10-05 11:56:06 +02002842 wl1271_free_ap_keys(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002843 return ret;
2844}
2845
Eliad Peller536129c2011-10-05 11:55:45 +02002846static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2847 u16 action, u8 id, u8 key_type,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002848 u8 key_size, const u8 *key, u32 tx_seq_32,
2849 u16 tx_seq_16, struct ieee80211_sta *sta)
2850{
2851 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002852 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002853
2854 if (is_ap) {
2855 struct wl1271_station *wl_sta;
2856 u8 hlid;
2857
2858 if (sta) {
2859 wl_sta = (struct wl1271_station *)sta->drv_priv;
2860 hlid = wl_sta->hlid;
2861 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002862 hlid = wlvif->ap.bcast_hlid;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002863 }
2864
Eliad Peller53d40d02011-10-10 10:13:02 +02002865 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002866 /*
2867 * We do not support removing keys after AP shutdown.
2868 * Pretend we do to make mac80211 happy.
2869 */
2870 if (action != KEY_ADD_OR_REPLACE)
2871 return 0;
2872
Eliad Peller170d0e62011-10-05 11:56:06 +02002873 ret = wl1271_record_ap_key(wl, wlvif, id,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002874 key_type, key_size,
2875 key, hlid, tx_seq_32,
2876 tx_seq_16);
2877 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002878 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002879 id, key_type, key_size,
2880 key, hlid, tx_seq_32,
2881 tx_seq_16);
2882 }
2883
2884 if (ret < 0)
2885 return ret;
2886 } else {
2887 const u8 *addr;
2888 static const u8 bcast_addr[ETH_ALEN] = {
2889 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2890 };
2891
Guy Eilame9eb8cb2011-08-16 19:49:12 +03002892 /*
2893 * A STA set to GEM cipher requires 2 tx spare blocks.
2894 * Return to default value when GEM cipher key is removed
2895 */
2896 if (key_type == KEY_GEM) {
2897 if (action == KEY_ADD_OR_REPLACE)
2898 wl->tx_spare_blocks = 2;
2899 else if (action == KEY_REMOVE)
2900 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2901 }
2902
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002903 addr = sta ? sta->addr : bcast_addr;
2904
2905 if (is_zero_ether_addr(addr)) {
2906 /* We dont support TX only encryption */
2907 return -EOPNOTSUPP;
2908 }
2909
2910 /* The wl1271 does not allow to remove unicast keys - they
2911 will be cleared automatically on next CMD_JOIN. Ignore the
2912 request silently, as we dont want the mac80211 to emit
2913 an error message. */
2914 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2915 return 0;
2916
Eliad Peller010d3d32011-08-14 13:17:31 +03002917 /* don't remove key if hlid was already deleted */
2918 if (action == KEY_REMOVE &&
Eliad Peller154da672011-10-05 11:55:53 +02002919 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Peller010d3d32011-08-14 13:17:31 +03002920 return 0;
2921
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002922 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002923 id, key_type, key_size,
2924 key, addr, tx_seq_32,
2925 tx_seq_16);
2926 if (ret < 0)
2927 return ret;
2928
2929 /* the default WEP key needs to be configured at least once */
2930 if (key_type == KEY_WEP) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03002931 ret = wl12xx_cmd_set_default_wep_key(wl,
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002932 wlvif->default_key,
2933 wlvif->sta.hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002934 if (ret < 0)
2935 return ret;
2936 }
2937 }
2938
2939 return 0;
2940}
2941
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002942static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2943 struct ieee80211_vif *vif,
2944 struct ieee80211_sta *sta,
2945 struct ieee80211_key_conf *key_conf)
2946{
2947 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002948 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002949 int ret;
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03002950 u32 tx_seq_32 = 0;
2951 u16 tx_seq_16 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002952 u8 key_type;
2953
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002954 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2955
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002956 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002957 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Johannes Berg97359d12010-08-10 09:46:38 +02002958 key_conf->cipher, key_conf->keyidx,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002959 key_conf->keylen, key_conf->flags);
2960 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2961
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002962 mutex_lock(&wl->mutex);
2963
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02002964 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2965 ret = -EAGAIN;
2966 goto out_unlock;
2967 }
2968
Ido Yariva6208652011-03-01 15:14:41 +02002969 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002970 if (ret < 0)
2971 goto out_unlock;
2972
Johannes Berg97359d12010-08-10 09:46:38 +02002973 switch (key_conf->cipher) {
2974 case WLAN_CIPHER_SUITE_WEP40:
2975 case WLAN_CIPHER_SUITE_WEP104:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002976 key_type = KEY_WEP;
2977
2978 key_conf->hw_key_idx = key_conf->keyidx;
2979 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002980 case WLAN_CIPHER_SUITE_TKIP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002981 key_type = KEY_TKIP;
2982
2983 key_conf->hw_key_idx = key_conf->keyidx;
Eliad Peller48e93e42011-10-10 10:12:58 +02002984 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2985 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002986 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002987 case WLAN_CIPHER_SUITE_CCMP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002988 key_type = KEY_AES;
2989
Arik Nemtsov12d4b972011-10-23 08:21:54 +02002990 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Eliad Peller48e93e42011-10-10 10:12:58 +02002991 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2992 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002993 break;
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002994 case WL1271_CIPHER_SUITE_GEM:
2995 key_type = KEY_GEM;
Eliad Peller48e93e42011-10-10 10:12:58 +02002996 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2997 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002998 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002999 default:
Johannes Berg97359d12010-08-10 09:46:38 +02003000 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003001
3002 ret = -EOPNOTSUPP;
3003 goto out_sleep;
3004 }
3005
3006 switch (cmd) {
3007 case SET_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003008 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003009 key_conf->keyidx, key_type,
3010 key_conf->keylen, key_conf->key,
3011 tx_seq_32, tx_seq_16, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003012 if (ret < 0) {
3013 wl1271_error("Could not add or replace key");
3014 goto out_sleep;
3015 }
Eliad Peller5ec8a442012-02-02 12:22:09 +02003016
3017 /*
3018 * reconfiguring arp response if the unicast (or common)
3019 * encryption key type was changed
3020 */
3021 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
3022 (sta || key_type == KEY_WEP) &&
3023 wlvif->encryption_type != key_type) {
3024 wlvif->encryption_type = key_type;
3025 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3026 if (ret < 0) {
3027 wl1271_warning("build arp rsp failed: %d", ret);
3028 goto out_sleep;
3029 }
3030 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003031 break;
3032
3033 case DISABLE_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003034 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003035 key_conf->keyidx, key_type,
3036 key_conf->keylen, key_conf->key,
3037 0, 0, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003038 if (ret < 0) {
3039 wl1271_error("Could not remove key");
3040 goto out_sleep;
3041 }
3042 break;
3043
3044 default:
3045 wl1271_error("Unsupported key cmd 0x%x", cmd);
3046 ret = -EOPNOTSUPP;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003047 break;
3048 }
3049
3050out_sleep:
3051 wl1271_ps_elp_sleep(wl);
3052
3053out_unlock:
3054 mutex_unlock(&wl->mutex);
3055
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003056 return ret;
3057}
3058
3059static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
Johannes Berga060bbf2010-04-27 11:59:34 +02003060 struct ieee80211_vif *vif,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003061 struct cfg80211_scan_request *req)
3062{
3063 struct wl1271 *wl = hw->priv;
3064 int ret;
3065 u8 *ssid = NULL;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003066 size_t len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003067
3068 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
3069
3070 if (req->n_ssids) {
3071 ssid = req->ssids[0].ssid;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003072 len = req->ssids[0].ssid_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003073 }
3074
3075 mutex_lock(&wl->mutex);
3076
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003077 if (wl->state == WL1271_STATE_OFF) {
3078 /*
3079 * We cannot return -EBUSY here because cfg80211 will expect
3080 * a call to ieee80211_scan_completed if we do - in this case
3081 * there won't be any call.
3082 */
3083 ret = -EAGAIN;
3084 goto out;
3085 }
3086
Ido Yariva6208652011-03-01 15:14:41 +02003087 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003088 if (ret < 0)
3089 goto out;
3090
Eliad Peller97fd3112012-03-04 10:55:52 +02003091 /* fail if there is any role in ROC */
3092 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
Eliad Peller92e712d2011-12-18 20:25:43 +02003093 /* don't allow scanning right now */
3094 ret = -EBUSY;
3095 goto out_sleep;
Eliad Peller251c1772011-08-14 13:17:17 +03003096 }
3097
Eliad Peller784f6942011-10-05 11:55:39 +02003098 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
Eliad Peller251c1772011-08-14 13:17:17 +03003099out_sleep:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003100 wl1271_ps_elp_sleep(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003101out:
3102 mutex_unlock(&wl->mutex);
3103
3104 return ret;
3105}
3106
Eliad Peller73ecce32011-06-27 13:06:45 +03003107static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3108 struct ieee80211_vif *vif)
3109{
3110 struct wl1271 *wl = hw->priv;
3111 int ret;
3112
3113 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3114
3115 mutex_lock(&wl->mutex);
3116
3117 if (wl->state == WL1271_STATE_OFF)
3118 goto out;
3119
3120 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3121 goto out;
3122
3123 ret = wl1271_ps_elp_wakeup(wl);
3124 if (ret < 0)
3125 goto out;
3126
3127 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3128 ret = wl1271_scan_stop(wl);
3129 if (ret < 0)
3130 goto out_sleep;
3131 }
3132 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3133 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02003134 wl->scan_vif = NULL;
Eliad Peller73ecce32011-06-27 13:06:45 +03003135 wl->scan.req = NULL;
3136 ieee80211_scan_completed(wl->hw, true);
3137
3138out_sleep:
3139 wl1271_ps_elp_sleep(wl);
3140out:
3141 mutex_unlock(&wl->mutex);
3142
3143 cancel_delayed_work_sync(&wl->scan_complete_work);
3144}
3145
Luciano Coelho33c2c062011-05-10 14:46:02 +03003146static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3147 struct ieee80211_vif *vif,
3148 struct cfg80211_sched_scan_request *req,
3149 struct ieee80211_sched_scan_ies *ies)
3150{
3151 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003152 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003153 int ret;
3154
3155 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3156
3157 mutex_lock(&wl->mutex);
3158
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003159 if (wl->state == WL1271_STATE_OFF) {
3160 ret = -EAGAIN;
3161 goto out;
3162 }
3163
Luciano Coelho33c2c062011-05-10 14:46:02 +03003164 ret = wl1271_ps_elp_wakeup(wl);
3165 if (ret < 0)
3166 goto out;
3167
Eliad Peller536129c2011-10-05 11:55:45 +02003168 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003169 if (ret < 0)
3170 goto out_sleep;
3171
Eliad Peller536129c2011-10-05 11:55:45 +02003172 ret = wl1271_scan_sched_scan_start(wl, wlvif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003173 if (ret < 0)
3174 goto out_sleep;
3175
3176 wl->sched_scanning = true;
3177
3178out_sleep:
3179 wl1271_ps_elp_sleep(wl);
3180out:
3181 mutex_unlock(&wl->mutex);
3182 return ret;
3183}
3184
3185static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3186 struct ieee80211_vif *vif)
3187{
3188 struct wl1271 *wl = hw->priv;
3189 int ret;
3190
3191 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3192
3193 mutex_lock(&wl->mutex);
3194
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003195 if (wl->state == WL1271_STATE_OFF)
3196 goto out;
3197
Luciano Coelho33c2c062011-05-10 14:46:02 +03003198 ret = wl1271_ps_elp_wakeup(wl);
3199 if (ret < 0)
3200 goto out;
3201
3202 wl1271_scan_sched_scan_stop(wl);
3203
3204 wl1271_ps_elp_sleep(wl);
3205out:
3206 mutex_unlock(&wl->mutex);
3207}
3208
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003209static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3210{
3211 struct wl1271 *wl = hw->priv;
3212 int ret = 0;
3213
3214 mutex_lock(&wl->mutex);
3215
3216 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3217 ret = -EAGAIN;
3218 goto out;
3219 }
3220
Ido Yariva6208652011-03-01 15:14:41 +02003221 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003222 if (ret < 0)
3223 goto out;
3224
Arik Nemtsov5f704d12011-04-18 14:15:21 +03003225 ret = wl1271_acx_frag_threshold(wl, value);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003226 if (ret < 0)
3227 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3228
3229 wl1271_ps_elp_sleep(wl);
3230
3231out:
3232 mutex_unlock(&wl->mutex);
3233
3234 return ret;
3235}
3236
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003237static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3238{
3239 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02003240 struct wl12xx_vif *wlvif;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003241 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003242
3243 mutex_lock(&wl->mutex);
3244
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003245 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3246 ret = -EAGAIN;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003247 goto out;
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003248 }
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003249
Ido Yariva6208652011-03-01 15:14:41 +02003250 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003251 if (ret < 0)
3252 goto out;
3253
Eliad Peller6e8cd332011-10-10 10:13:13 +02003254 wl12xx_for_each_wlvif(wl, wlvif) {
3255 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3256 if (ret < 0)
3257 wl1271_warning("set rts threshold failed: %d", ret);
3258 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003259 wl1271_ps_elp_sleep(wl);
3260
3261out:
3262 mutex_unlock(&wl->mutex);
3263
3264 return ret;
3265}
3266
Eliad Peller1fe9f162011-10-05 11:55:48 +02003267static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003268 int offset)
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003269{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003270 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller889cb362011-05-01 09:56:45 +03003271 u8 ssid_len;
3272 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3273 skb->len - offset);
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003274
Eliad Peller889cb362011-05-01 09:56:45 +03003275 if (!ptr) {
3276 wl1271_error("No SSID in IEs!");
3277 return -ENOENT;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003278 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003279
Eliad Peller889cb362011-05-01 09:56:45 +03003280 ssid_len = ptr[1];
3281 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3282 wl1271_error("SSID is too long!");
3283 return -EINVAL;
3284 }
3285
Eliad Peller1fe9f162011-10-05 11:55:48 +02003286 wlvif->ssid_len = ssid_len;
3287 memcpy(wlvif->ssid, ptr+2, ssid_len);
Eliad Peller889cb362011-05-01 09:56:45 +03003288 return 0;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003289}
3290
Eliad Pellerd48055d2011-09-15 12:07:04 +03003291static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3292{
3293 int len;
3294 const u8 *next, *end = skb->data + skb->len;
3295 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3296 skb->len - ieoffset);
3297 if (!ie)
3298 return;
3299 len = ie[1] + 2;
3300 next = ie + len;
3301 memmove(ie, next, end - next);
3302 skb_trim(skb, skb->len - len);
3303}
3304
Eliad Peller26b4bf22011-09-15 12:07:05 +03003305static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3306 unsigned int oui, u8 oui_type,
3307 int ieoffset)
3308{
3309 int len;
3310 const u8 *next, *end = skb->data + skb->len;
3311 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3312 skb->data + ieoffset,
3313 skb->len - ieoffset);
3314 if (!ie)
3315 return;
3316 len = ie[1] + 2;
3317 next = ie + len;
3318 memmove(ie, next, end - next);
3319 skb_trim(skb, skb->len - len);
3320}
3321
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003322static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3323 struct ieee80211_vif *vif)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003324{
Eliad Pellercdaac622012-01-31 11:57:16 +02003325 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003326 struct sk_buff *skb;
3327 int ret;
3328
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003329 skb = ieee80211_proberesp_get(wl->hw, vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003330 if (!skb)
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003331 return -EOPNOTSUPP;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003332
Eliad Pellercdaac622012-01-31 11:57:16 +02003333 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov560f0022011-11-08 18:46:54 +02003334 CMD_TEMPL_AP_PROBE_RESPONSE,
3335 skb->data,
3336 skb->len, 0,
3337 rates);
3338
3339 dev_kfree_skb(skb);
3340 return ret;
3341}
3342
3343static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3344 struct ieee80211_vif *vif,
3345 u8 *probe_rsp_data,
3346 size_t probe_rsp_len,
3347 u32 rates)
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003348{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003349 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3350 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003351 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3352 int ssid_ie_offset, ie_offset, templ_len;
3353 const u8 *ptr;
3354
3355 /* no need to change probe response if the SSID is set correctly */
Eliad Peller1fe9f162011-10-05 11:55:48 +02003356 if (wlvif->ssid_len > 0)
Eliad Pellercdaac622012-01-31 11:57:16 +02003357 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003358 CMD_TEMPL_AP_PROBE_RESPONSE,
3359 probe_rsp_data,
3360 probe_rsp_len, 0,
3361 rates);
3362
3363 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3364 wl1271_error("probe_rsp template too big");
3365 return -EINVAL;
3366 }
3367
3368 /* start searching from IE offset */
3369 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3370
3371 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3372 probe_rsp_len - ie_offset);
3373 if (!ptr) {
3374 wl1271_error("No SSID in beacon!");
3375 return -EINVAL;
3376 }
3377
3378 ssid_ie_offset = ptr - probe_rsp_data;
3379 ptr += (ptr[1] + 2);
3380
3381 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3382
3383 /* insert SSID from bss_conf */
3384 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3385 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3386 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3387 bss_conf->ssid, bss_conf->ssid_len);
3388 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3389
3390 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3391 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3392 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3393
Eliad Pellercdaac622012-01-31 11:57:16 +02003394 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003395 CMD_TEMPL_AP_PROBE_RESPONSE,
3396 probe_rsp_templ,
3397 templ_len, 0,
3398 rates);
3399}
3400
Arik Nemtsove78a2872010-10-16 19:07:21 +02003401static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
Eliad Peller0603d892011-10-05 11:55:51 +02003402 struct ieee80211_vif *vif,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003403 struct ieee80211_bss_conf *bss_conf,
3404 u32 changed)
3405{
Eliad Peller0603d892011-10-05 11:55:51 +02003406 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003407 int ret = 0;
3408
3409 if (changed & BSS_CHANGED_ERP_SLOT) {
3410 if (bss_conf->use_short_slot)
Eliad Peller0603d892011-10-05 11:55:51 +02003411 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003412 else
Eliad Peller0603d892011-10-05 11:55:51 +02003413 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003414 if (ret < 0) {
3415 wl1271_warning("Set slot time failed %d", ret);
3416 goto out;
3417 }
3418 }
3419
3420 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3421 if (bss_conf->use_short_preamble)
Eliad Peller0603d892011-10-05 11:55:51 +02003422 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003423 else
Eliad Peller0603d892011-10-05 11:55:51 +02003424 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003425 }
3426
3427 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3428 if (bss_conf->use_cts_prot)
Eliad Peller0603d892011-10-05 11:55:51 +02003429 ret = wl1271_acx_cts_protect(wl, wlvif,
3430 CTSPROTECT_ENABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003431 else
Eliad Peller0603d892011-10-05 11:55:51 +02003432 ret = wl1271_acx_cts_protect(wl, wlvif,
3433 CTSPROTECT_DISABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003434 if (ret < 0) {
3435 wl1271_warning("Set ctsprotect failed %d", ret);
3436 goto out;
3437 }
3438 }
3439
3440out:
3441 return ret;
3442}
3443
3444static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3445 struct ieee80211_vif *vif,
3446 struct ieee80211_bss_conf *bss_conf,
3447 u32 changed)
3448{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003449 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller536129c2011-10-05 11:55:45 +02003450 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003451 int ret = 0;
3452
3453 if ((changed & BSS_CHANGED_BEACON_INT)) {
3454 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3455 bss_conf->beacon_int);
3456
Eliad Peller6a899792011-10-05 11:55:58 +02003457 wlvif->beacon_int = bss_conf->beacon_int;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003458 }
3459
Arik Nemtsov560f0022011-11-08 18:46:54 +02003460 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3461 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003462 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3463 wl1271_debug(DEBUG_AP, "probe response updated");
3464 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3465 }
Arik Nemtsov560f0022011-11-08 18:46:54 +02003466 }
3467
Arik Nemtsove78a2872010-10-16 19:07:21 +02003468 if ((changed & BSS_CHANGED_BEACON)) {
3469 struct ieee80211_hdr *hdr;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003470 u32 min_rate;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003471 int ieoffset = offsetof(struct ieee80211_mgmt,
3472 u.beacon.variable);
3473 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3474 u16 tmpl_id;
3475
Arik Nemtsov560f0022011-11-08 18:46:54 +02003476 if (!beacon) {
3477 ret = -EINVAL;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003478 goto out;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003479 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003480
3481 wl1271_debug(DEBUG_MASTER, "beacon updated");
3482
Eliad Peller1fe9f162011-10-05 11:55:48 +02003483 ret = wl1271_ssid_set(vif, beacon, ieoffset);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003484 if (ret < 0) {
3485 dev_kfree_skb(beacon);
3486 goto out;
3487 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02003488 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003489 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3490 CMD_TEMPL_BEACON;
Eliad Pellercdaac622012-01-31 11:57:16 +02003491 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003492 beacon->data,
3493 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003494 min_rate);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003495 if (ret < 0) {
3496 dev_kfree_skb(beacon);
3497 goto out;
3498 }
3499
Arik Nemtsov560f0022011-11-08 18:46:54 +02003500 /*
3501 * In case we already have a probe-resp beacon set explicitly
3502 * by usermode, don't use the beacon data.
3503 */
3504 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3505 goto end_bcn;
3506
Eliad Pellerd48055d2011-09-15 12:07:04 +03003507 /* remove TIM ie from probe response */
3508 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3509
Eliad Peller26b4bf22011-09-15 12:07:05 +03003510 /*
3511 * remove p2p ie from probe response.
3512 * the fw reponds to probe requests that don't include
3513 * the p2p ie. probe requests with p2p ie will be passed,
3514 * and will be responded by the supplicant (the spec
3515 * forbids including the p2p ie when responding to probe
3516 * requests that didn't include it).
3517 */
3518 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3519 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3520
Arik Nemtsove78a2872010-10-16 19:07:21 +02003521 hdr = (struct ieee80211_hdr *) beacon->data;
3522 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3523 IEEE80211_STYPE_PROBE_RESP);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003524 if (is_ap)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003525 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003526 beacon->data,
3527 beacon->len,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003528 min_rate);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003529 else
Eliad Pellercdaac622012-01-31 11:57:16 +02003530 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003531 CMD_TEMPL_PROBE_RESPONSE,
3532 beacon->data,
3533 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003534 min_rate);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003535end_bcn:
Arik Nemtsove78a2872010-10-16 19:07:21 +02003536 dev_kfree_skb(beacon);
3537 if (ret < 0)
3538 goto out;
3539 }
3540
3541out:
Arik Nemtsov560f0022011-11-08 18:46:54 +02003542 if (ret != 0)
3543 wl1271_error("beacon info change failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003544 return ret;
3545}
3546
3547/* AP mode changes */
3548static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003549 struct ieee80211_vif *vif,
3550 struct ieee80211_bss_conf *bss_conf,
3551 u32 changed)
3552{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003553 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003554 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003555
Arik Nemtsove78a2872010-10-16 19:07:21 +02003556 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3557 u32 rates = bss_conf->basic_rates;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003558
Eliad Peller87fbcb02011-10-05 11:55:41 +02003559 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003560 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003561 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
Eliad Peller87fbcb02011-10-05 11:55:41 +02003562 wlvif->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003563
Eliad Peller87fbcb02011-10-05 11:55:41 +02003564 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003565 if (ret < 0) {
Arik Nemtsov70f47422011-04-18 14:15:25 +03003566 wl1271_error("AP rate policy change failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003567 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003568 }
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003569
Eliad Peller784f6942011-10-05 11:55:39 +02003570 ret = wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003571 if (ret < 0)
3572 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003573 }
3574
Arik Nemtsove78a2872010-10-16 19:07:21 +02003575 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3576 if (ret < 0)
3577 goto out;
3578
3579 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3580 if (bss_conf->enable_beacon) {
Eliad Peller53d40d02011-10-10 10:13:02 +02003581 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003582 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003583 if (ret < 0)
3584 goto out;
3585
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003586 ret = wl1271_ap_init_hwenc(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003587 if (ret < 0)
3588 goto out;
Arik Nemtsovcf420392011-08-14 13:17:37 +03003589
Eliad Peller53d40d02011-10-10 10:13:02 +02003590 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsovcf420392011-08-14 13:17:37 +03003591 wl1271_debug(DEBUG_AP, "started AP");
Arik Nemtsove78a2872010-10-16 19:07:21 +02003592 }
3593 } else {
Eliad Peller53d40d02011-10-10 10:13:02 +02003594 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003595 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003596 if (ret < 0)
3597 goto out;
3598
Eliad Peller53d40d02011-10-10 10:13:02 +02003599 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003600 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3601 &wlvif->flags);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003602 wl1271_debug(DEBUG_AP, "stopped AP");
3603 }
3604 }
3605 }
3606
Eliad Peller0603d892011-10-05 11:55:51 +02003607 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003608 if (ret < 0)
3609 goto out;
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003610
3611 /* Handle HT information change */
3612 if ((changed & BSS_CHANGED_HT) &&
3613 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003614 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003615 bss_conf->ht_operation_mode);
3616 if (ret < 0) {
3617 wl1271_warning("Set ht information failed %d", ret);
3618 goto out;
3619 }
3620 }
3621
Arik Nemtsove78a2872010-10-16 19:07:21 +02003622out:
3623 return;
3624}
3625
3626/* STA/IBSS mode changes */
3627static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3628 struct ieee80211_vif *vif,
3629 struct ieee80211_bss_conf *bss_conf,
3630 u32 changed)
3631{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003632 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003633 bool do_join = false, set_assoc = false;
Eliad Peller536129c2011-10-05 11:55:45 +02003634 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Eliad Peller227e81e2011-08-14 13:17:26 +03003635 bool ibss_joined = false;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003636 u32 sta_rate_set = 0;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003637 int ret;
Luciano Coelho2d6e4e762011-01-11 19:07:21 +01003638 struct ieee80211_sta *sta;
Arik Nemtsova1008852011-02-12 23:24:20 +02003639 bool sta_exists = false;
3640 struct ieee80211_sta_ht_cap sta_ht_cap;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003641
3642 if (is_ibss) {
3643 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3644 changed);
3645 if (ret < 0)
3646 goto out;
3647 }
3648
Eliad Peller227e81e2011-08-14 13:17:26 +03003649 if (changed & BSS_CHANGED_IBSS) {
3650 if (bss_conf->ibss_joined) {
Eliad Pellereee514e2011-10-10 10:13:01 +02003651 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
Eliad Peller227e81e2011-08-14 13:17:26 +03003652 ibss_joined = true;
3653 } else {
Eliad Pellereee514e2011-10-10 10:13:01 +02003654 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
Eliad Peller349345a2012-03-04 10:55:45 +02003655 &wlvif->flags))
Eliad Peller0603d892011-10-05 11:55:51 +02003656 wl1271_unjoin(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03003657 }
3658 }
3659
3660 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003661 do_join = true;
3662
3663 /* Need to update the SSID (for filtering etc) */
Eliad Peller227e81e2011-08-14 13:17:26 +03003664 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003665 do_join = true;
3666
Eliad Peller227e81e2011-08-14 13:17:26 +03003667 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003668 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3669 bss_conf->enable_beacon ? "enabled" : "disabled");
3670
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003671 do_join = true;
3672 }
3673
Eliad Peller349345a2012-03-04 10:55:45 +02003674 if (changed & BSS_CHANGED_IDLE && !is_ibss) {
Eliad Pellerc31e4942011-10-23 08:21:55 +02003675 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3676 if (ret < 0)
3677 wl1271_warning("idle mode change failed %d", ret);
3678 }
3679
Arik Nemtsove78a2872010-10-16 19:07:21 +02003680 if ((changed & BSS_CHANGED_CQM)) {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003681 bool enable = false;
3682 if (bss_conf->cqm_rssi_thold)
3683 enable = true;
Eliad Peller0603d892011-10-05 11:55:51 +02003684 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003685 bss_conf->cqm_rssi_thold,
3686 bss_conf->cqm_rssi_hyst);
3687 if (ret < 0)
3688 goto out;
Eliad Peller04324d92011-10-05 11:56:03 +02003689 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003690 }
3691
Eliad Peller7db4ee62012-01-24 18:18:42 +02003692 if (changed & BSS_CHANGED_BSSID &&
3693 (is_ibss || bss_conf->assoc))
Eliad Pellercdf09492011-10-05 11:55:44 +02003694 if (!is_zero_ether_addr(bss_conf->bssid)) {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003695 ret = wl12xx_cmd_build_null_data(wl, wlvif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003696 if (ret < 0)
3697 goto out;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003698
Eliad Peller784f6942011-10-05 11:55:39 +02003699 ret = wl1271_build_qos_null_data(wl, vif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003700 if (ret < 0)
3701 goto out;
Saravanan Dhanabal141418c2010-04-28 09:50:00 +03003702
Eliad Pellerfa287b82010-12-26 09:27:50 +01003703 /* Need to update the BSSID (for filtering etc) */
3704 do_join = true;
3705 }
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003706
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003707 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3708 rcu_read_lock();
3709 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3710 if (!sta)
3711 goto sta_not_found;
3712
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003713 /* save the supp_rates of the ap */
3714 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3715 if (sta->ht_cap.ht_supported)
3716 sta_rate_set |=
3717 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
Arik Nemtsova1008852011-02-12 23:24:20 +02003718 sta_ht_cap = sta->ht_cap;
3719 sta_exists = true;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003720
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003721sta_not_found:
3722 rcu_read_unlock();
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003723 }
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003724
Arik Nemtsove78a2872010-10-16 19:07:21 +02003725 if ((changed & BSS_CHANGED_ASSOC)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003726 if (bss_conf->assoc) {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003727 u32 rates;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003728 int ieoffset;
Eliad Peller6840e372011-10-05 11:55:50 +02003729 wlvif->aid = bss_conf->aid;
Eliad Peller66677762012-03-04 10:55:53 +02003730 wlvif->beacon_int = bss_conf->beacon_int;
Juuso Oikarinen69e54342010-05-07 11:39:00 +03003731 set_assoc = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003732
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003733 /*
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003734 * use basic rates from AP, and determine lowest rate
3735 * to use with control frames.
3736 */
3737 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003738 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003739 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003740 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003741 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003742 wl1271_tx_min_rate_get(wl,
3743 wlvif->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003744 if (sta_rate_set)
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003745 wlvif->rate_set =
3746 wl1271_tx_enabled_rates_get(wl,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003747 sta_rate_set,
Eliad Peller1b92f152011-10-10 10:13:09 +02003748 wlvif->band);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003749 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003750 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003751 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003752
3753 /*
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003754 * with wl1271, we don't need to update the
3755 * beacon_int and dtim_period, because the firmware
3756 * updates it by itself when the first beacon is
3757 * received after a join.
3758 */
Eliad Peller6840e372011-10-05 11:55:50 +02003759 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003760 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003761 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003762
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003763 /*
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003764 * Get a template for hardware connection maintenance
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003765 */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003766 dev_kfree_skb(wlvif->probereq);
3767 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
Eliad Peller83587502011-10-10 10:12:53 +02003768 wlvif,
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003769 NULL);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003770 ieoffset = offsetof(struct ieee80211_mgmt,
3771 u.probe_req.variable);
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003772 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003773
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003774 /* enable the connection monitoring feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003775 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003776 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003777 goto out;
Juuso Oikarinend94cd292009-10-08 21:56:25 +03003778 } else {
3779 /* use defaults when not associated */
Eliad Peller30df14d2011-04-05 19:13:28 +03003780 bool was_assoc =
Eliad Pellerba8447f2011-10-10 10:13:00 +02003781 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3782 &wlvif->flags);
Eliad Peller251c1772011-08-14 13:17:17 +03003783 bool was_ifup =
Eliad Peller8181aec2011-10-10 10:13:04 +02003784 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3785 &wlvif->flags);
Eliad Peller6840e372011-10-05 11:55:50 +02003786 wlvif->aid = 0;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003787
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003788 /* free probe-request template */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003789 dev_kfree_skb(wlvif->probereq);
3790 wlvif->probereq = NULL;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003791
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003792 /* revert back to minimum rates for the current band */
Eliad Peller87fbcb02011-10-05 11:55:41 +02003793 wl1271_set_band_rate(wl, wlvif);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003794 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003795 wl1271_tx_min_rate_get(wl,
3796 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003797 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003798 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003799 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003800
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003801 /* disable connection monitor features */
Eliad Peller0603d892011-10-05 11:55:51 +02003802 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003803
3804 /* Disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003805 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003806 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003807 goto out;
Juuso Oikarinenb84a7d32010-11-22 12:59:08 +02003808
3809 /* restore the bssid filter and go to dummy bssid */
Eliad Peller30df14d2011-04-05 19:13:28 +03003810 if (was_assoc) {
Eliad Peller251c1772011-08-14 13:17:17 +03003811 /*
3812 * we might have to disable roc, if there was
3813 * no IF_OPER_UP notification.
3814 */
3815 if (!was_ifup) {
Eliad Peller0603d892011-10-05 11:55:51 +02003816 ret = wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003817 if (ret < 0)
3818 goto out;
3819 }
3820 /*
3821 * (we also need to disable roc in case of
3822 * roaming on the same channel. until we will
3823 * have a better flow...)
3824 */
Eliad Peller7edebf52011-10-05 11:55:52 +02003825 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3826 ret = wl12xx_croc(wl,
3827 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003828 if (ret < 0)
3829 goto out;
3830 }
3831
Eliad Peller0603d892011-10-05 11:55:51 +02003832 wl1271_unjoin(wl, wlvif);
Eliad Peller8a6a84a2012-03-04 10:55:46 +02003833 if (!bss_conf->idle)
Eliad Peller679a6732011-10-11 11:55:44 +02003834 wl12xx_start_dev(wl, wlvif);
Eliad Peller30df14d2011-04-05 19:13:28 +03003835 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003836 }
3837 }
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03003838
Eliad Pellerd192d262011-05-24 14:33:08 +03003839 if (changed & BSS_CHANGED_IBSS) {
3840 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3841 bss_conf->ibss_joined);
3842
3843 if (bss_conf->ibss_joined) {
3844 u32 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003845 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003846 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003847 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003848 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003849 wl1271_tx_min_rate_get(wl,
3850 wlvif->basic_rate_set);
Eliad Pellerd192d262011-05-24 14:33:08 +03003851
Shahar Levi06b660e2011-09-05 13:54:36 +03003852 /* by default, use 11b + OFDM rates */
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003853 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3854 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Eliad Pellerd192d262011-05-24 14:33:08 +03003855 if (ret < 0)
3856 goto out;
3857 }
3858 }
3859
Eliad Peller0603d892011-10-05 11:55:51 +02003860 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003861 if (ret < 0)
3862 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003863
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003864 if (do_join) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003865 ret = wl1271_join(wl, wlvif, set_assoc);
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003866 if (ret < 0) {
3867 wl1271_warning("cmd join failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003868 goto out;
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003869 }
Eliad Peller251c1772011-08-14 13:17:17 +03003870
3871 /* ROC until connected (after EAPOL exchange) */
3872 if (!is_ibss) {
Eliad Peller1b92f152011-10-10 10:13:09 +02003873 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003874 if (ret < 0)
3875 goto out;
3876
Eliad Peller9fd6f212012-03-04 10:55:48 +02003877 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
3878 wl12xx_set_authorized(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003879 }
3880 /*
3881 * stop device role if started (we might already be in
Eliad Peller92e712d2011-12-18 20:25:43 +02003882 * STA/IBSS role).
Eliad Peller251c1772011-08-14 13:17:17 +03003883 */
Eliad Peller92e712d2011-12-18 20:25:43 +02003884 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02003885 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003886 if (ret < 0)
3887 goto out;
3888 }
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003889 }
3890
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003891 /* Handle new association with HT. Do this after join. */
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003892 if (sta_exists) {
3893 if ((changed & BSS_CHANGED_HT) &&
3894 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003895 ret = wl1271_acx_set_ht_capabilities(wl,
3896 &sta_ht_cap,
3897 true,
Eliad Peller154da672011-10-05 11:55:53 +02003898 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003899 if (ret < 0) {
3900 wl1271_warning("Set ht cap true failed %d",
3901 ret);
3902 goto out;
3903 }
3904 }
3905 /* handle new association without HT and disassociation */
3906 else if (changed & BSS_CHANGED_ASSOC) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003907 ret = wl1271_acx_set_ht_capabilities(wl,
3908 &sta_ht_cap,
3909 false,
Eliad Peller154da672011-10-05 11:55:53 +02003910 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003911 if (ret < 0) {
3912 wl1271_warning("Set ht cap false failed %d",
3913 ret);
3914 goto out;
3915 }
3916 }
3917 }
3918
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003919 /* Handle HT information change. Done after join. */
3920 if ((changed & BSS_CHANGED_HT) &&
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003921 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003922 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003923 bss_conf->ht_operation_mode);
3924 if (ret < 0) {
3925 wl1271_warning("Set ht information failed %d", ret);
3926 goto out;
3927 }
3928 }
3929
Eliad Peller76a74c82012-02-02 12:22:11 +02003930 /* Handle arp filtering. Done after join. */
3931 if ((changed & BSS_CHANGED_ARP_FILTER) ||
3932 (!is_ibss && (changed & BSS_CHANGED_QOS))) {
3933 __be32 addr = bss_conf->arp_addr_list[0];
3934 wlvif->sta.qos = bss_conf->qos;
3935 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
3936
3937 if (bss_conf->arp_addr_cnt == 1 &&
3938 bss_conf->arp_filter_enabled) {
3939 wlvif->ip_addr = addr;
3940 /*
3941 * The template should have been configured only upon
3942 * association. however, it seems that the correct ip
3943 * isn't being set (when sending), so we have to
3944 * reconfigure the template upon every ip change.
3945 */
3946 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3947 if (ret < 0) {
3948 wl1271_warning("build arp rsp failed: %d", ret);
3949 goto out;
3950 }
3951
3952 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
3953 (ACX_ARP_FILTER_ARP_FILTERING |
3954 ACX_ARP_FILTER_AUTO_ARP),
3955 addr);
3956 } else {
3957 wlvif->ip_addr = 0;
3958 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
3959 }
3960
3961 if (ret < 0)
3962 goto out;
3963 }
3964
Arik Nemtsove78a2872010-10-16 19:07:21 +02003965out:
3966 return;
3967}
3968
3969static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3970 struct ieee80211_vif *vif,
3971 struct ieee80211_bss_conf *bss_conf,
3972 u32 changed)
3973{
3974 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003975 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3976 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003977 int ret;
3978
3979 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3980 (int)changed);
3981
3982 mutex_lock(&wl->mutex);
3983
3984 if (unlikely(wl->state == WL1271_STATE_OFF))
3985 goto out;
3986
Eliad Peller10c8cd02011-10-10 10:13:06 +02003987 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3988 goto out;
3989
Ido Yariva6208652011-03-01 15:14:41 +02003990 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003991 if (ret < 0)
3992 goto out;
3993
3994 if (is_ap)
3995 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3996 else
3997 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3998
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003999 wl1271_ps_elp_sleep(wl);
4000
4001out:
4002 mutex_unlock(&wl->mutex);
4003}
4004
Eliad Peller8a3a3c82011-10-02 10:15:52 +02004005static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
4006 struct ieee80211_vif *vif, u16 queue,
Kalle Valoc6999d82010-02-18 13:25:41 +02004007 const struct ieee80211_tx_queue_params *params)
4008{
4009 struct wl1271 *wl = hw->priv;
Eliad Peller0603d892011-10-05 11:55:51 +02004010 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo4695dc92010-03-18 12:26:38 +02004011 u8 ps_scheme;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004012 int ret = 0;
Kalle Valoc6999d82010-02-18 13:25:41 +02004013
4014 mutex_lock(&wl->mutex);
4015
4016 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
4017
Kalle Valo4695dc92010-03-18 12:26:38 +02004018 if (params->uapsd)
4019 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
4020 else
4021 ps_scheme = CONF_PS_SCHEME_LEGACY;
4022
Eliad Peller5b37ddf2011-12-18 20:25:40 +02004023 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004024 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004025
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004026 ret = wl1271_ps_elp_wakeup(wl);
4027 if (ret < 0)
4028 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004029
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004030 /*
4031 * the txop is confed in units of 32us by the mac80211,
4032 * we need us
4033 */
Eliad Peller0603d892011-10-05 11:55:51 +02004034 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004035 params->cw_min, params->cw_max,
4036 params->aifs, params->txop << 5);
4037 if (ret < 0)
4038 goto out_sleep;
4039
Eliad Peller0603d892011-10-05 11:55:51 +02004040 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004041 CONF_CHANNEL_TYPE_EDCF,
4042 wl1271_tx_get_queue(queue),
4043 ps_scheme, CONF_ACK_POLICY_LEGACY,
4044 0, 0);
Kalle Valoc82c1dd2010-02-18 13:25:47 +02004045
4046out_sleep:
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004047 wl1271_ps_elp_sleep(wl);
Kalle Valoc6999d82010-02-18 13:25:41 +02004048
4049out:
4050 mutex_unlock(&wl->mutex);
4051
4052 return ret;
4053}
4054
Eliad Peller37a41b42011-09-21 14:06:11 +03004055static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
4056 struct ieee80211_vif *vif)
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004057{
4058
4059 struct wl1271 *wl = hw->priv;
Eliad Peller9c531142012-01-31 11:57:18 +02004060 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004061 u64 mactime = ULLONG_MAX;
4062 int ret;
4063
4064 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
4065
4066 mutex_lock(&wl->mutex);
4067
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02004068 if (unlikely(wl->state == WL1271_STATE_OFF))
4069 goto out;
4070
Ido Yariva6208652011-03-01 15:14:41 +02004071 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004072 if (ret < 0)
4073 goto out;
4074
Eliad Peller9c531142012-01-31 11:57:18 +02004075 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004076 if (ret < 0)
4077 goto out_sleep;
4078
4079out_sleep:
4080 wl1271_ps_elp_sleep(wl);
4081
4082out:
4083 mutex_unlock(&wl->mutex);
4084 return mactime;
4085}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004086
John W. Linvilleece550d2010-07-28 16:41:06 -04004087static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
4088 struct survey_info *survey)
4089{
4090 struct wl1271 *wl = hw->priv;
4091 struct ieee80211_conf *conf = &hw->conf;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004092
John W. Linvilleece550d2010-07-28 16:41:06 -04004093 if (idx != 0)
4094 return -ENOENT;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004095
John W. Linvilleece550d2010-07-28 16:41:06 -04004096 survey->channel = conf->channel;
4097 survey->filled = SURVEY_INFO_NOISE_DBM;
4098 survey->noise = wl->noise;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004099
John W. Linvilleece550d2010-07-28 16:41:06 -04004100 return 0;
4101}
4102
Arik Nemtsov409622e2011-02-23 00:22:29 +02004103static int wl1271_allocate_sta(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004104 struct wl12xx_vif *wlvif,
4105 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004106{
4107 struct wl1271_station *wl_sta;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004108 int ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004109
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004110
4111 if (wl->active_sta_count >= AP_MAX_STATIONS) {
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004112 wl1271_warning("could not allocate HLID - too much stations");
4113 return -EBUSY;
4114 }
4115
4116 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004117 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4118 if (ret < 0) {
4119 wl1271_warning("could not allocate HLID - too many links");
4120 return -EBUSY;
4121 }
4122
4123 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004124 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
Arik Nemtsovda032092011-08-25 12:43:15 +03004125 wl->active_sta_count++;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004126 return 0;
4127}
4128
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004129void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004130{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004131 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
Arik Nemtsovf1acea92011-08-25 12:43:17 +03004132 return;
4133
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004134 clear_bit(hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004135 memset(wl->links[hlid].addr, 0, ETH_ALEN);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004136 wl->links[hlid].ba_bitmap = 0;
Arik Nemtsovb622d992011-02-23 00:22:31 +02004137 __clear_bit(hlid, &wl->ap_ps_map);
4138 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004139 wl12xx_free_link(wl, wlvif, &hlid);
Arik Nemtsovda032092011-08-25 12:43:15 +03004140 wl->active_sta_count--;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004141}
4142
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004143static int wl12xx_sta_add(struct wl1271 *wl,
4144 struct wl12xx_vif *wlvif,
4145 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004146{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004147 struct wl1271_station *wl_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004148 int ret = 0;
4149 u8 hlid;
4150
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004151 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4152
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004153 ret = wl1271_allocate_sta(wl, wlvif, sta);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004154 if (ret < 0)
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004155 return ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004156
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004157 wl_sta = (struct wl1271_station *)sta->drv_priv;
4158 hlid = wl_sta->hlid;
4159
Eliad Peller1b92f152011-10-10 10:13:09 +02004160 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004161 if (ret < 0)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004162 wl1271_free_sta(wl, wlvif, hlid);
Arik Nemtsov409622e2011-02-23 00:22:29 +02004163
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004164 return ret;
4165}
4166
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004167static int wl12xx_sta_remove(struct wl1271 *wl,
4168 struct wl12xx_vif *wlvif,
4169 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004170{
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004171 struct wl1271_station *wl_sta;
4172 int ret = 0, id;
4173
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004174 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4175
4176 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004177 id = wl_sta->hlid;
4178 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004179 return -EINVAL;
4180
4181 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
4182 if (ret < 0)
4183 return ret;
4184
4185 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
4186 return ret;
4187}
4188
4189static int wl12xx_update_sta_state(struct wl1271 *wl,
4190 struct wl12xx_vif *wlvif,
4191 struct ieee80211_sta *sta,
4192 enum ieee80211_sta_state old_state,
4193 enum ieee80211_sta_state new_state)
4194{
4195 struct wl1271_station *wl_sta;
4196 u8 hlid;
4197 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
4198 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
4199 int ret;
4200
4201 wl_sta = (struct wl1271_station *)sta->drv_priv;
4202 hlid = wl_sta->hlid;
4203
4204 /* Add station (AP mode) */
4205 if (is_ap &&
4206 old_state == IEEE80211_STA_NOTEXIST &&
4207 new_state == IEEE80211_STA_NONE)
4208 return wl12xx_sta_add(wl, wlvif, sta);
4209
4210 /* Remove station (AP mode) */
4211 if (is_ap &&
4212 old_state == IEEE80211_STA_NONE &&
4213 new_state == IEEE80211_STA_NOTEXIST) {
4214 /* must not fail */
4215 wl12xx_sta_remove(wl, wlvif, sta);
4216 return 0;
4217 }
4218
4219 /* Authorize station (AP mode) */
4220 if (is_ap &&
4221 new_state == IEEE80211_STA_AUTHORIZED) {
4222 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4223 if (ret < 0)
4224 return ret;
4225
4226 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
4227 hlid);
4228 return ret;
4229 }
4230
Eliad Peller9fd6f212012-03-04 10:55:48 +02004231 /* Authorize station */
4232 if (is_sta &&
4233 new_state == IEEE80211_STA_AUTHORIZED) {
4234 set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4235 return wl12xx_set_authorized(wl, wlvif);
4236 }
4237
4238 if (is_sta &&
4239 old_state == IEEE80211_STA_AUTHORIZED &&
4240 new_state == IEEE80211_STA_ASSOC) {
4241 clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4242 return 0;
4243 }
4244
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004245 return 0;
4246}
4247
4248static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
4249 struct ieee80211_vif *vif,
4250 struct ieee80211_sta *sta,
4251 enum ieee80211_sta_state old_state,
4252 enum ieee80211_sta_state new_state)
4253{
4254 struct wl1271 *wl = hw->priv;
4255 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4256 int ret;
4257
4258 wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
4259 sta->aid, old_state, new_state);
4260
4261 mutex_lock(&wl->mutex);
4262
4263 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4264 ret = -EBUSY;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004265 goto out;
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004266 }
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004267
Ido Yariva6208652011-03-01 15:14:41 +02004268 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004269 if (ret < 0)
4270 goto out;
4271
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004272 ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004273
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004274 wl1271_ps_elp_sleep(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004275out:
4276 mutex_unlock(&wl->mutex);
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004277 if (new_state < old_state)
4278 return 0;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004279 return ret;
4280}
4281
Luciano Coelho4623ec72011-03-21 19:26:41 +02004282static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4283 struct ieee80211_vif *vif,
4284 enum ieee80211_ampdu_mlme_action action,
4285 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4286 u8 buf_size)
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004287{
4288 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004289 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004290 int ret;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004291 u8 hlid, *ba_bitmap;
4292
4293 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4294 tid);
4295
4296 /* sanity check - the fields in FW are only 8bits wide */
4297 if (WARN_ON(tid > 0xFF))
4298 return -ENOTSUPP;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004299
4300 mutex_lock(&wl->mutex);
4301
4302 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4303 ret = -EAGAIN;
4304 goto out;
4305 }
4306
Eliad Peller536129c2011-10-05 11:55:45 +02004307 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
Eliad Peller154da672011-10-05 11:55:53 +02004308 hlid = wlvif->sta.hlid;
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004309 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
Eliad Peller536129c2011-10-05 11:55:45 +02004310 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004311 struct wl1271_station *wl_sta;
4312
4313 wl_sta = (struct wl1271_station *)sta->drv_priv;
4314 hlid = wl_sta->hlid;
4315 ba_bitmap = &wl->links[hlid].ba_bitmap;
4316 } else {
4317 ret = -EINVAL;
4318 goto out;
4319 }
4320
Ido Yariva6208652011-03-01 15:14:41 +02004321 ret = wl1271_ps_elp_wakeup(wl);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004322 if (ret < 0)
4323 goto out;
4324
Shahar Levi70559a02011-05-22 16:10:22 +03004325 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4326 tid, action);
4327
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004328 switch (action) {
4329 case IEEE80211_AMPDU_RX_START:
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004330 if (!wlvif->ba_support || !wlvif->ba_allowed) {
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004331 ret = -ENOTSUPP;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004332 break;
4333 }
4334
4335 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4336 ret = -EBUSY;
4337 wl1271_error("exceeded max RX BA sessions");
4338 break;
4339 }
4340
4341 if (*ba_bitmap & BIT(tid)) {
4342 ret = -EINVAL;
4343 wl1271_error("cannot enable RX BA session on active "
4344 "tid: %d", tid);
4345 break;
4346 }
4347
4348 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4349 hlid);
4350 if (!ret) {
4351 *ba_bitmap |= BIT(tid);
4352 wl->ba_rx_session_count++;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004353 }
4354 break;
4355
4356 case IEEE80211_AMPDU_RX_STOP:
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004357 if (!(*ba_bitmap & BIT(tid))) {
4358 ret = -EINVAL;
4359 wl1271_error("no active RX BA session on tid: %d",
4360 tid);
4361 break;
4362 }
4363
4364 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4365 hlid);
4366 if (!ret) {
4367 *ba_bitmap &= ~BIT(tid);
4368 wl->ba_rx_session_count--;
4369 }
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004370 break;
4371
4372 /*
4373 * The BA initiator session management in FW independently.
4374 * Falling break here on purpose for all TX APDU commands.
4375 */
4376 case IEEE80211_AMPDU_TX_START:
4377 case IEEE80211_AMPDU_TX_STOP:
4378 case IEEE80211_AMPDU_TX_OPERATIONAL:
4379 ret = -EINVAL;
4380 break;
4381
4382 default:
4383 wl1271_error("Incorrect ampdu action id=%x\n", action);
4384 ret = -EINVAL;
4385 }
4386
4387 wl1271_ps_elp_sleep(wl);
4388
4389out:
4390 mutex_unlock(&wl->mutex);
4391
4392 return ret;
4393}
4394
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004395static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4396 struct ieee80211_vif *vif,
4397 const struct cfg80211_bitrate_mask *mask)
4398{
Eliad Peller83587502011-10-10 10:12:53 +02004399 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004400 struct wl1271 *wl = hw->priv;
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004401 int i, ret = 0;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004402
4403 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4404 mask->control[NL80211_BAND_2GHZ].legacy,
4405 mask->control[NL80211_BAND_5GHZ].legacy);
4406
4407 mutex_lock(&wl->mutex);
4408
4409 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Eliad Peller83587502011-10-10 10:12:53 +02004410 wlvif->bitrate_masks[i] =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004411 wl1271_tx_enabled_rates_get(wl,
4412 mask->control[i].legacy,
4413 i);
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004414
4415 if (unlikely(wl->state == WL1271_STATE_OFF))
4416 goto out;
4417
4418 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4419 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4420
4421 ret = wl1271_ps_elp_wakeup(wl);
4422 if (ret < 0)
4423 goto out;
4424
4425 wl1271_set_band_rate(wl, wlvif);
4426 wlvif->basic_rate =
4427 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4428 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4429
4430 wl1271_ps_elp_sleep(wl);
4431 }
4432out:
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004433 mutex_unlock(&wl->mutex);
4434
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004435 return ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004436}
4437
Shahar Levi6d158ff2011-09-08 13:01:33 +03004438static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4439 struct ieee80211_channel_switch *ch_switch)
4440{
4441 struct wl1271 *wl = hw->priv;
Eliad Peller52630c52011-10-10 10:13:08 +02004442 struct wl12xx_vif *wlvif;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004443 int ret;
4444
4445 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4446
Arik Nemtsovb9239b62012-02-28 00:41:33 +02004447 wl1271_tx_flush(wl);
4448
Shahar Levi6d158ff2011-09-08 13:01:33 +03004449 mutex_lock(&wl->mutex);
4450
4451 if (unlikely(wl->state == WL1271_STATE_OFF)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02004452 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4453 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4454 ieee80211_chswitch_done(vif, false);
4455 }
4456 goto out;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004457 }
4458
4459 ret = wl1271_ps_elp_wakeup(wl);
4460 if (ret < 0)
4461 goto out;
4462
Eliad Peller52630c52011-10-10 10:13:08 +02004463 /* TODO: change mac80211 to pass vif as param */
4464 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller8332f0f2012-01-31 11:57:19 +02004465 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
Shahar Levi6d158ff2011-09-08 13:01:33 +03004466
Eliad Peller52630c52011-10-10 10:13:08 +02004467 if (!ret)
4468 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4469 }
Shahar Levi6d158ff2011-09-08 13:01:33 +03004470
4471 wl1271_ps_elp_sleep(wl);
4472
4473out:
4474 mutex_unlock(&wl->mutex);
4475}
4476
Arik Nemtsov33437892011-04-26 23:35:39 +03004477static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4478{
4479 struct wl1271 *wl = hw->priv;
4480 bool ret = false;
4481
4482 mutex_lock(&wl->mutex);
4483
4484 if (unlikely(wl->state == WL1271_STATE_OFF))
4485 goto out;
4486
4487 /* packets are considered pending if in the TX queue or the FW */
Arik Nemtsovf1a46382011-07-07 14:25:23 +03004488 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
Arik Nemtsov33437892011-04-26 23:35:39 +03004489out:
4490 mutex_unlock(&wl->mutex);
4491
4492 return ret;
4493}
4494
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004495/* can't be const, mac80211 writes to this */
4496static struct ieee80211_rate wl1271_rates[] = {
4497 { .bitrate = 10,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004498 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4499 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004500 { .bitrate = 20,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004501 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4502 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004503 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4504 { .bitrate = 55,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004505 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4506 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004507 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4508 { .bitrate = 110,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004509 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4510 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004511 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4512 { .bitrate = 60,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004513 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4514 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004515 { .bitrate = 90,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004516 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4517 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004518 { .bitrate = 120,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004519 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4520 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004521 { .bitrate = 180,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004522 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4523 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004524 { .bitrate = 240,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004525 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4526 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004527 { .bitrate = 360,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004528 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4529 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004530 { .bitrate = 480,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004531 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4532 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004533 { .bitrate = 540,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004534 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4535 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004536};
4537
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004538/* can't be const, mac80211 writes to this */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004539static struct ieee80211_channel wl1271_channels[] = {
Luciano Coelhoa2d0e3f2009-12-11 15:40:46 +02004540 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004541 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004542 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4543 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4544 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004545 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004546 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4547 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4548 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004549 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004550 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4551 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4552 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
Arik Nemtsov6c89b7b2011-01-18 20:39:52 +01004553 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004554};
4555
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004556/* mapping to indexes for wl1271_rates */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004557static const u8 wl1271_rate_to_idx_2ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004558 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004559 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004560 7, /* CONF_HW_RXTX_RATE_MCS7 */
4561 6, /* CONF_HW_RXTX_RATE_MCS6 */
4562 5, /* CONF_HW_RXTX_RATE_MCS5 */
4563 4, /* CONF_HW_RXTX_RATE_MCS4 */
4564 3, /* CONF_HW_RXTX_RATE_MCS3 */
4565 2, /* CONF_HW_RXTX_RATE_MCS2 */
4566 1, /* CONF_HW_RXTX_RATE_MCS1 */
4567 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004568
4569 11, /* CONF_HW_RXTX_RATE_54 */
4570 10, /* CONF_HW_RXTX_RATE_48 */
4571 9, /* CONF_HW_RXTX_RATE_36 */
4572 8, /* CONF_HW_RXTX_RATE_24 */
4573
4574 /* TI-specific rate */
4575 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4576
4577 7, /* CONF_HW_RXTX_RATE_18 */
4578 6, /* CONF_HW_RXTX_RATE_12 */
4579 3, /* CONF_HW_RXTX_RATE_11 */
4580 5, /* CONF_HW_RXTX_RATE_9 */
4581 4, /* CONF_HW_RXTX_RATE_6 */
4582 2, /* CONF_HW_RXTX_RATE_5_5 */
4583 1, /* CONF_HW_RXTX_RATE_2 */
4584 0 /* CONF_HW_RXTX_RATE_1 */
4585};
4586
Shahar Levie8b03a22010-10-13 16:09:39 +02004587/* 11n STA capabilities */
4588#define HW_RX_HIGHEST_RATE 72
4589
Shahar Levi00d20102010-11-08 11:20:10 +00004590#define WL12XX_HT_CAP { \
Shahar Levi871d0c32011-03-13 11:24:40 +02004591 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4592 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
Shahar Levie8b03a22010-10-13 16:09:39 +02004593 .ht_supported = true, \
4594 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4595 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4596 .mcs = { \
4597 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4598 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4599 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4600 }, \
4601}
4602
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004603/* can't be const, mac80211 writes to this */
4604static struct ieee80211_supported_band wl1271_band_2ghz = {
4605 .channels = wl1271_channels,
4606 .n_channels = ARRAY_SIZE(wl1271_channels),
4607 .bitrates = wl1271_rates,
4608 .n_bitrates = ARRAY_SIZE(wl1271_rates),
Shahar Levi00d20102010-11-08 11:20:10 +00004609 .ht_cap = WL12XX_HT_CAP,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004610};
4611
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004612/* 5 GHz data rates for WL1273 */
4613static struct ieee80211_rate wl1271_rates_5ghz[] = {
4614 { .bitrate = 60,
4615 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4616 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4617 { .bitrate = 90,
4618 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4619 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4620 { .bitrate = 120,
4621 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4622 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4623 { .bitrate = 180,
4624 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4625 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4626 { .bitrate = 240,
4627 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4628 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4629 { .bitrate = 360,
4630 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4631 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4632 { .bitrate = 480,
4633 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4634 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4635 { .bitrate = 540,
4636 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4637 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4638};
4639
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004640/* 5 GHz band channels for WL1273 */
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004641static struct ieee80211_channel wl1271_channels_5ghz[] = {
Arik Nemtsov6cfa5cf2011-06-27 22:06:33 +03004642 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4643 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4644 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4645 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4646 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4647 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4648 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4649 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4650 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4651 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4652 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4653 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4654 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4655 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4656 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4657 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4658 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4659 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4660 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4661 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4662 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4663 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4664 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4665 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4666 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4667 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4668 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4669 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4670 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4671 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4672 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4673 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4674 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4675 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004676};
4677
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004678/* mapping to indexes for wl1271_rates_5ghz */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004679static const u8 wl1271_rate_to_idx_5ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004680 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004681 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004682 7, /* CONF_HW_RXTX_RATE_MCS7 */
4683 6, /* CONF_HW_RXTX_RATE_MCS6 */
4684 5, /* CONF_HW_RXTX_RATE_MCS5 */
4685 4, /* CONF_HW_RXTX_RATE_MCS4 */
4686 3, /* CONF_HW_RXTX_RATE_MCS3 */
4687 2, /* CONF_HW_RXTX_RATE_MCS2 */
4688 1, /* CONF_HW_RXTX_RATE_MCS1 */
4689 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004690
4691 7, /* CONF_HW_RXTX_RATE_54 */
4692 6, /* CONF_HW_RXTX_RATE_48 */
4693 5, /* CONF_HW_RXTX_RATE_36 */
4694 4, /* CONF_HW_RXTX_RATE_24 */
4695
4696 /* TI-specific rate */
4697 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4698
4699 3, /* CONF_HW_RXTX_RATE_18 */
4700 2, /* CONF_HW_RXTX_RATE_12 */
4701 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4702 1, /* CONF_HW_RXTX_RATE_9 */
4703 0, /* CONF_HW_RXTX_RATE_6 */
4704 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4705 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4706 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4707};
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004708
4709static struct ieee80211_supported_band wl1271_band_5ghz = {
4710 .channels = wl1271_channels_5ghz,
4711 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4712 .bitrates = wl1271_rates_5ghz,
4713 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
Shahar Levi00d20102010-11-08 11:20:10 +00004714 .ht_cap = WL12XX_HT_CAP,
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004715};
4716
Tobias Klausera0ea9492010-05-20 10:38:11 +02004717static const u8 *wl1271_band_rate_to_idx[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004718 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4719 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4720};
4721
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004722static const struct ieee80211_ops wl1271_ops = {
4723 .start = wl1271_op_start,
4724 .stop = wl1271_op_stop,
4725 .add_interface = wl1271_op_add_interface,
4726 .remove_interface = wl1271_op_remove_interface,
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02004727 .change_interface = wl12xx_op_change_interface,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004728#ifdef CONFIG_PM
Eliad Peller402e48612011-05-13 11:57:09 +03004729 .suspend = wl1271_op_suspend,
4730 .resume = wl1271_op_resume,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004731#endif
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004732 .config = wl1271_op_config,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03004733 .prepare_multicast = wl1271_op_prepare_multicast,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004734 .configure_filter = wl1271_op_configure_filter,
4735 .tx = wl1271_op_tx,
4736 .set_key = wl1271_op_set_key,
4737 .hw_scan = wl1271_op_hw_scan,
Eliad Peller73ecce32011-06-27 13:06:45 +03004738 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
Luciano Coelho33c2c062011-05-10 14:46:02 +03004739 .sched_scan_start = wl1271_op_sched_scan_start,
4740 .sched_scan_stop = wl1271_op_sched_scan_stop,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004741 .bss_info_changed = wl1271_op_bss_info_changed,
Arik Nemtsov68d069c2010-11-08 10:51:07 +01004742 .set_frag_threshold = wl1271_op_set_frag_threshold,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004743 .set_rts_threshold = wl1271_op_set_rts_threshold,
Kalle Valoc6999d82010-02-18 13:25:41 +02004744 .conf_tx = wl1271_op_conf_tx,
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004745 .get_tsf = wl1271_op_get_tsf,
John W. Linvilleece550d2010-07-28 16:41:06 -04004746 .get_survey = wl1271_op_get_survey,
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004747 .sta_state = wl12xx_op_sta_state,
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004748 .ampdu_action = wl1271_op_ampdu_action,
Arik Nemtsov33437892011-04-26 23:35:39 +03004749 .tx_frames_pending = wl1271_tx_frames_pending,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004750 .set_bitrate_mask = wl12xx_set_bitrate_mask,
Shahar Levi6d158ff2011-09-08 13:01:33 +03004751 .channel_switch = wl12xx_op_channel_switch,
Kalle Valoc8c90872010-02-18 13:25:53 +02004752 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004753};
4754
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004755
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004756u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004757{
4758 u8 idx;
4759
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004760 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004761
4762 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4763 wl1271_error("Illegal RX rate from HW: %d", rate);
4764 return 0;
4765 }
4766
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004767 idx = wl1271_band_rate_to_idx[band][rate];
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004768 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4769 wl1271_error("Unsupported RX rate from HW: %d", rate);
4770 return 0;
4771 }
4772
4773 return idx;
4774}
4775
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004776static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4777 struct device_attribute *attr,
4778 char *buf)
4779{
4780 struct wl1271 *wl = dev_get_drvdata(dev);
4781 ssize_t len;
4782
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004783 len = PAGE_SIZE;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004784
4785 mutex_lock(&wl->mutex);
4786 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4787 wl->sg_enabled);
4788 mutex_unlock(&wl->mutex);
4789
4790 return len;
4791
4792}
4793
4794static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4795 struct device_attribute *attr,
4796 const char *buf, size_t count)
4797{
4798 struct wl1271 *wl = dev_get_drvdata(dev);
4799 unsigned long res;
4800 int ret;
4801
Luciano Coelho6277ed62011-04-01 17:49:54 +03004802 ret = kstrtoul(buf, 10, &res);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004803 if (ret < 0) {
4804 wl1271_warning("incorrect value written to bt_coex_mode");
4805 return count;
4806 }
4807
4808 mutex_lock(&wl->mutex);
4809
4810 res = !!res;
4811
4812 if (res == wl->sg_enabled)
4813 goto out;
4814
4815 wl->sg_enabled = res;
4816
4817 if (wl->state == WL1271_STATE_OFF)
4818 goto out;
4819
Ido Yariva6208652011-03-01 15:14:41 +02004820 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004821 if (ret < 0)
4822 goto out;
4823
4824 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4825 wl1271_ps_elp_sleep(wl);
4826
4827 out:
4828 mutex_unlock(&wl->mutex);
4829 return count;
4830}
4831
4832static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4833 wl1271_sysfs_show_bt_coex_state,
4834 wl1271_sysfs_store_bt_coex_state);
4835
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004836static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4837 struct device_attribute *attr,
4838 char *buf)
4839{
4840 struct wl1271 *wl = dev_get_drvdata(dev);
4841 ssize_t len;
4842
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004843 len = PAGE_SIZE;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004844
4845 mutex_lock(&wl->mutex);
4846 if (wl->hw_pg_ver >= 0)
4847 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4848 else
4849 len = snprintf(buf, len, "n/a\n");
4850 mutex_unlock(&wl->mutex);
4851
4852 return len;
4853}
4854
Gery Kahn6f07b722011-07-18 14:21:49 +03004855static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004856 wl1271_sysfs_show_hw_pg_ver, NULL);
4857
Ido Yariv95dac04f2011-06-06 14:57:06 +03004858static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4859 struct bin_attribute *bin_attr,
4860 char *buffer, loff_t pos, size_t count)
4861{
4862 struct device *dev = container_of(kobj, struct device, kobj);
4863 struct wl1271 *wl = dev_get_drvdata(dev);
4864 ssize_t len;
4865 int ret;
4866
4867 ret = mutex_lock_interruptible(&wl->mutex);
4868 if (ret < 0)
4869 return -ERESTARTSYS;
4870
4871 /* Let only one thread read the log at a time, blocking others */
4872 while (wl->fwlog_size == 0) {
4873 DEFINE_WAIT(wait);
4874
4875 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4876 &wait,
4877 TASK_INTERRUPTIBLE);
4878
4879 if (wl->fwlog_size != 0) {
4880 finish_wait(&wl->fwlog_waitq, &wait);
4881 break;
4882 }
4883
4884 mutex_unlock(&wl->mutex);
4885
4886 schedule();
4887 finish_wait(&wl->fwlog_waitq, &wait);
4888
4889 if (signal_pending(current))
4890 return -ERESTARTSYS;
4891
4892 ret = mutex_lock_interruptible(&wl->mutex);
4893 if (ret < 0)
4894 return -ERESTARTSYS;
4895 }
4896
4897 /* Check if the fwlog is still valid */
4898 if (wl->fwlog_size < 0) {
4899 mutex_unlock(&wl->mutex);
4900 return 0;
4901 }
4902
4903 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4904 len = min(count, (size_t)wl->fwlog_size);
4905 wl->fwlog_size -= len;
4906 memcpy(buffer, wl->fwlog, len);
4907
4908 /* Make room for new messages */
4909 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4910
4911 mutex_unlock(&wl->mutex);
4912
4913 return len;
4914}
4915
4916static struct bin_attribute fwlog_attr = {
4917 .attr = {.name = "fwlog", .mode = S_IRUSR},
4918 .read = wl1271_sysfs_read_fwlog,
4919};
4920
Luciano Coelho5e037e72011-12-23 09:32:17 +02004921static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4922{
4923 bool supported = false;
4924 u8 major, minor;
4925
4926 if (wl->chip.id == CHIP_ID_1283_PG20) {
4927 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
4928 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
4929
4930 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
4931 if (major > 2 || (major == 2 && minor >= 1))
4932 supported = true;
4933 } else {
4934 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
4935 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
4936
4937 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
4938 if (major == 3 && minor >= 1)
4939 supported = true;
4940 }
4941
4942 wl1271_debug(DEBUG_PROBE,
4943 "PG Ver major = %d minor = %d, MAC %s present",
4944 major, minor, supported ? "is" : "is not");
4945
4946 return supported;
4947}
4948
4949static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4950 u32 oui, u32 nic, int n)
4951{
4952 int i;
4953
4954 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
4955 oui, nic, n);
4956
4957 if (nic + n - 1 > 0xffffff)
4958 wl1271_warning("NIC part of the MAC address wraps around!");
4959
4960 for (i = 0; i < n; i++) {
4961 wl->addresses[i].addr[0] = (u8)(oui >> 16);
4962 wl->addresses[i].addr[1] = (u8)(oui >> 8);
4963 wl->addresses[i].addr[2] = (u8) oui;
4964 wl->addresses[i].addr[3] = (u8)(nic >> 16);
4965 wl->addresses[i].addr[4] = (u8)(nic >> 8);
4966 wl->addresses[i].addr[5] = (u8) nic;
4967 nic++;
4968 }
4969
4970 wl->hw->wiphy->n_addresses = n;
4971 wl->hw->wiphy->addresses = wl->addresses;
4972}
4973
4974static void wl12xx_get_fuse_mac(struct wl1271 *wl)
4975{
4976 u32 mac1, mac2;
4977
4978 wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
4979
4980 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
4981 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
4982
4983 /* these are the two parts of the BD_ADDR */
4984 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
4985 ((mac1 & 0xff000000) >> 24);
4986 wl->fuse_nic_addr = mac1 & 0xffffff;
4987
4988 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
4989}
4990
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004991static int wl12xx_get_hw_info(struct wl1271 *wl)
4992{
4993 int ret;
4994 u32 die_info;
4995
4996 ret = wl12xx_set_power_on(wl);
4997 if (ret < 0)
4998 goto out;
4999
5000 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
5001
5002 if (wl->chip.id == CHIP_ID_1283_PG20)
5003 die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
5004 else
5005 die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
5006
5007 wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
5008
Luciano Coelho5e037e72011-12-23 09:32:17 +02005009 if (!wl12xx_mac_in_fuse(wl)) {
5010 wl->fuse_oui_addr = 0;
5011 wl->fuse_nic_addr = 0;
5012 } else {
5013 wl12xx_get_fuse_mac(wl);
5014 }
5015
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005016 wl1271_power_off(wl);
5017out:
5018 return ret;
5019}
5020
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005021static int wl1271_register_hw(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005022{
5023 int ret;
Luciano Coelho5e037e72011-12-23 09:32:17 +02005024 u32 oui_addr = 0, nic_addr = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005025
5026 if (wl->mac80211_registered)
5027 return 0;
5028
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005029 ret = wl12xx_get_hw_info(wl);
5030 if (ret < 0) {
5031 wl1271_error("couldn't get hw info");
5032 goto out;
5033 }
5034
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005035 ret = wl1271_fetch_nvs(wl);
5036 if (ret == 0) {
Shahar Levibc765bf2011-03-06 16:32:10 +02005037 /* NOTE: The wl->nvs->nvs element must be first, in
5038 * order to simplify the casting, we assume it is at
5039 * the beginning of the wl->nvs structure.
5040 */
5041 u8 *nvs_ptr = (u8 *)wl->nvs;
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005042
Luciano Coelho5e037e72011-12-23 09:32:17 +02005043 oui_addr =
5044 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
5045 nic_addr =
5046 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005047 }
5048
Luciano Coelho5e037e72011-12-23 09:32:17 +02005049 /* if the MAC address is zeroed in the NVS derive from fuse */
5050 if (oui_addr == 0 && nic_addr == 0) {
5051 oui_addr = wl->fuse_oui_addr;
5052 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5053 nic_addr = wl->fuse_nic_addr + 1;
5054 }
5055
5056 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005057
5058 ret = ieee80211_register_hw(wl->hw);
5059 if (ret < 0) {
5060 wl1271_error("unable to register mac80211 hw: %d", ret);
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005061 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005062 }
5063
5064 wl->mac80211_registered = true;
5065
Eliad Pellerd60080a2010-11-24 12:53:16 +02005066 wl1271_debugfs_init(wl);
5067
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005068 wl1271_notice("loaded");
5069
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005070out:
5071 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005072}
5073
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005074static void wl1271_unregister_hw(struct wl1271 *wl)
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005075{
Eliad Peller3fcdab72012-02-06 12:47:54 +02005076 if (wl->plt)
Ido Yarivf3df1332012-01-11 09:42:39 +02005077 wl1271_plt_stop(wl);
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01005078
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005079 ieee80211_unregister_hw(wl->hw);
5080 wl->mac80211_registered = false;
5081
5082}
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005083
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005084static int wl1271_init_ieee80211(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005085{
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005086 static const u32 cipher_suites[] = {
5087 WLAN_CIPHER_SUITE_WEP40,
5088 WLAN_CIPHER_SUITE_WEP104,
5089 WLAN_CIPHER_SUITE_TKIP,
5090 WLAN_CIPHER_SUITE_CCMP,
5091 WL1271_CIPHER_SUITE_GEM,
5092 };
5093
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005094 /* The tx descriptor buffer and the TKIP space. */
Eliad Peller5ec8a442012-02-02 12:22:09 +02005095 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005096 sizeof(struct wl1271_tx_hw_descr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005097
5098 /* unit us */
5099 /* FIXME: find a proper value */
5100 wl->hw->channel_change_time = 10000;
Juuso Oikarinen50c500a2010-04-01 11:38:22 +03005101 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005102
5103 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
Juuso Oikarinen0a343322010-02-22 08:38:41 +02005104 IEEE80211_HW_SUPPORTS_PS |
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02005105 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo4695dc92010-03-18 12:26:38 +02005106 IEEE80211_HW_SUPPORTS_UAPSD |
Juuso Oikarinena9af0922010-03-26 12:53:30 +02005107 IEEE80211_HW_HAS_RATE_CONTROL |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03005108 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelho25eaea302011-05-02 12:37:33 +03005109 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Shahar Levifcd23b62011-05-11 12:12:56 +03005110 IEEE80211_HW_SPECTRUM_MGMT |
Arik Nemtsov93f8c8e2011-08-30 09:34:01 +03005111 IEEE80211_HW_AP_LINK_PS |
5112 IEEE80211_HW_AMPDU_AGGREGATION |
Eliad Peller79aba1b2012-02-02 13:15:35 +02005113 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
5114 IEEE80211_HW_SCAN_WHILE_IDLE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005115
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005116 wl->hw->wiphy->cipher_suites = cipher_suites;
5117 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5118
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02005119 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Eliad Peller045c7452011-08-28 15:23:01 +03005120 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
5121 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005122 wl->hw->wiphy->max_scan_ssids = 1;
Luciano Coelho221737d2011-09-02 14:28:22 +03005123 wl->hw->wiphy->max_sched_scan_ssids = 16;
5124 wl->hw->wiphy->max_match_sets = 16;
Guy Eilamea559b42010-12-09 16:54:59 +02005125 /*
5126 * Maximum length of elements in scanning probe request templates
5127 * should be the maximum length possible for a template, without
5128 * the IEEE80211 header of the template
5129 */
Ido Reisc08e3712012-02-02 13:54:27 +02005130 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Guy Eilamea559b42010-12-09 16:54:59 +02005131 sizeof(struct ieee80211_header);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005132
Ido Reisc08e3712012-02-02 13:54:27 +02005133 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Luciano Coelhoc9e79a42011-09-27 16:22:35 +03005134 sizeof(struct ieee80211_header);
5135
Eliad Peller1ec23f72011-08-25 14:26:54 +03005136 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5137
Luciano Coelho4a31c112011-03-21 23:16:14 +02005138 /* make sure all our channels fit in the scanned_ch bitmask */
5139 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
5140 ARRAY_SIZE(wl1271_channels_5ghz) >
5141 WL1271_MAX_CHANNELS);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005142 /*
5143 * We keep local copies of the band structs because we need to
5144 * modify them on a per-device basis.
5145 */
5146 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5147 sizeof(wl1271_band_2ghz));
5148 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5149 sizeof(wl1271_band_5ghz));
5150
5151 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5152 &wl->bands[IEEE80211_BAND_2GHZ];
5153 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5154 &wl->bands[IEEE80211_BAND_5GHZ];
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03005155
Kalle Valo12bd8942010-03-18 12:26:33 +02005156 wl->hw->queues = 4;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +02005157 wl->hw->max_rates = 1;
Kalle Valo12bd8942010-03-18 12:26:33 +02005158
Juuso Oikarinenb7417d92010-11-10 11:27:19 +01005159 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5160
Arik Nemtsov9c1b1902011-11-08 18:46:55 +02005161 /* the FW answers probe-requests in AP-mode */
5162 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5163 wl->hw->wiphy->probe_resp_offload =
5164 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5165 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5166 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5167
Felipe Balbia390e852011-10-06 10:07:44 +03005168 SET_IEEE80211_DEV(wl->hw, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005169
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005170 wl->hw->sta_data_size = sizeof(struct wl1271_station);
Eliad Peller87fbcb02011-10-05 11:55:41 +02005171 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005172
Luciano Coelho4c9cfa72011-01-12 14:27:03 +01005173 wl->hw->max_rx_aggregation_subframes = 8;
5174
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005175 return 0;
5176}
5177
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005178#define WL1271_DEFAULT_CHANNEL 0
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005179
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005180static struct ieee80211_hw *wl1271_alloc_hw(void)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005181{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005182 struct ieee80211_hw *hw;
5183 struct wl1271 *wl;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005184 int i, j, ret;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005185 unsigned int order;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005186
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005187 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
Arik Nemtsovf80c2d12011-09-22 09:52:05 +03005188
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005189 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5190 if (!hw) {
5191 wl1271_error("could not alloc ieee80211_hw");
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005192 ret = -ENOMEM;
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005193 goto err_hw_alloc;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005194 }
5195
5196 wl = hw->priv;
5197 memset(wl, 0, sizeof(*wl));
5198
Eliad Peller87627212011-10-10 10:12:54 +02005199 INIT_LIST_HEAD(&wl->wlvif_list);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005200
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005201 wl->hw = hw;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005202
Juuso Oikarinen6742f552010-12-13 09:52:37 +02005203 for (i = 0; i < NUM_TX_QUEUES; i++)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005204 for (j = 0; j < WL12XX_MAX_LINKS; j++)
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005205 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5206
Ido Yariva6208652011-03-01 15:14:41 +02005207 skb_queue_head_init(&wl->deferred_rx_queue);
5208 skb_queue_head_init(&wl->deferred_tx_queue);
5209
Juuso Oikarinen37b70a82009-10-08 21:56:21 +03005210 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
Ido Yariva6208652011-03-01 15:14:41 +02005211 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
Juuso Oikarinen117b38d2010-09-30 10:43:28 +02005212 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5213 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5214 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +03005215
Eliad Peller92ef8962011-06-07 12:50:46 +03005216 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5217 if (!wl->freezable_wq) {
5218 ret = -ENOMEM;
5219 goto err_hw;
5220 }
5221
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005222 wl->channel = WL1271_DEFAULT_CHANNEL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005223 wl->rx_counter = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005224 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03005225 wl->band = IEEE80211_BAND_2GHZ;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02005226 wl->flags = 0;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02005227 wl->sg_enabled = true;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03005228 wl->hw_pg_ver = -1;
Arik Nemtsovb622d992011-02-23 00:22:31 +02005229 wl->ap_ps_map = 0;
5230 wl->ap_fw_ps_map = 0;
Ido Yariv606ea9f2011-03-01 15:14:39 +02005231 wl->quirks = 0;
Ido Yariv341b7cd2011-03-31 10:07:01 +02005232 wl->platform_quirks = 0;
Luciano Coelho33c2c062011-05-10 14:46:02 +03005233 wl->sched_scanning = false;
Guy Eilame9eb8cb2011-08-16 19:49:12 +03005234 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005235 wl->system_hlid = WL12XX_SYSTEM_HLID;
Arik Nemtsovda032092011-08-25 12:43:15 +03005236 wl->active_sta_count = 0;
Ido Yariv95dac04f2011-06-06 14:57:06 +03005237 wl->fwlog_size = 0;
5238 init_waitqueue_head(&wl->fwlog_waitq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005239
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005240 /* The system link is always allocated */
5241 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5242
Ido Yariv25eeb9e2010-10-12 16:20:06 +02005243 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +03005244 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005245 wl->tx_frames[i] = NULL;
5246
5247 spin_lock_init(&wl->wl_lock);
5248
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005249 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005250 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005251 mutex_init(&wl->mutex);
5252
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005253 /* Apply default driver configuration. */
5254 wl1271_conf_init(wl);
5255
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005256 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5257 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5258 if (!wl->aggr_buf) {
5259 ret = -ENOMEM;
Eliad Peller92ef8962011-06-07 12:50:46 +03005260 goto err_wq;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005261 }
5262
Ido Yariv990f5de2011-03-31 10:06:59 +02005263 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5264 if (!wl->dummy_packet) {
5265 ret = -ENOMEM;
5266 goto err_aggr;
5267 }
5268
Ido Yariv95dac04f2011-06-06 14:57:06 +03005269 /* Allocate one page for the FW log */
5270 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5271 if (!wl->fwlog) {
5272 ret = -ENOMEM;
5273 goto err_dummy_packet;
5274 }
5275
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005276 return hw;
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005277
Ido Yariv990f5de2011-03-31 10:06:59 +02005278err_dummy_packet:
5279 dev_kfree_skb(wl->dummy_packet);
5280
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005281err_aggr:
5282 free_pages((unsigned long)wl->aggr_buf, order);
5283
Eliad Peller92ef8962011-06-07 12:50:46 +03005284err_wq:
5285 destroy_workqueue(wl->freezable_wq);
5286
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005287err_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005288 wl1271_debugfs_exit(wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005289 ieee80211_free_hw(hw);
5290
5291err_hw_alloc:
5292
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005293 return ERR_PTR(ret);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005294}
5295
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005296static int wl1271_free_hw(struct wl1271 *wl)
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005297{
Ido Yariv95dac04f2011-06-06 14:57:06 +03005298 /* Unblock any fwlog readers */
5299 mutex_lock(&wl->mutex);
5300 wl->fwlog_size = -1;
5301 wake_up_interruptible_all(&wl->fwlog_waitq);
5302 mutex_unlock(&wl->mutex);
5303
Felipe Balbif79f8902011-10-06 13:05:25 +03005304 device_remove_bin_file(wl->dev, &fwlog_attr);
Gery Kahn6f07b722011-07-18 14:21:49 +03005305
Felipe Balbif79f8902011-10-06 13:05:25 +03005306 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
Gery Kahn6f07b722011-07-18 14:21:49 +03005307
Felipe Balbif79f8902011-10-06 13:05:25 +03005308 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
Ido Yariv95dac04f2011-06-06 14:57:06 +03005309 free_page((unsigned long)wl->fwlog);
Ido Yariv990f5de2011-03-31 10:06:59 +02005310 dev_kfree_skb(wl->dummy_packet);
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005311 free_pages((unsigned long)wl->aggr_buf,
5312 get_order(WL1271_AGGR_BUFFER_SIZE));
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005313
5314 wl1271_debugfs_exit(wl);
5315
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005316 vfree(wl->fw);
5317 wl->fw = NULL;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005318 wl->fw_type = WL12XX_FW_TYPE_NONE;
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005319 kfree(wl->nvs);
5320 wl->nvs = NULL;
5321
5322 kfree(wl->fw_status);
5323 kfree(wl->tx_res_if);
Eliad Peller92ef8962011-06-07 12:50:46 +03005324 destroy_workqueue(wl->freezable_wq);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005325
5326 ieee80211_free_hw(wl->hw);
5327
5328 return 0;
5329}
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005330
Felipe Balbia390e852011-10-06 10:07:44 +03005331static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5332{
5333 struct wl1271 *wl = cookie;
5334 unsigned long flags;
5335
5336 wl1271_debug(DEBUG_IRQ, "IRQ");
5337
5338 /* complete the ELP completion */
5339 spin_lock_irqsave(&wl->wl_lock, flags);
5340 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5341 if (wl->elp_compl) {
5342 complete(wl->elp_compl);
5343 wl->elp_compl = NULL;
5344 }
5345
5346 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5347 /* don't enqueue a work right now. mark it as pending */
5348 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5349 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5350 disable_irq_nosync(wl->irq);
5351 pm_wakeup_event(wl->dev, 0);
5352 spin_unlock_irqrestore(&wl->wl_lock, flags);
5353 return IRQ_HANDLED;
5354 }
5355 spin_unlock_irqrestore(&wl->wl_lock, flags);
5356
5357 return IRQ_WAKE_THREAD;
5358}
5359
Felipe Balbice2a2172011-10-05 14:12:55 +03005360static int __devinit wl12xx_probe(struct platform_device *pdev)
5361{
Felipe Balbia390e852011-10-06 10:07:44 +03005362 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5363 struct ieee80211_hw *hw;
5364 struct wl1271 *wl;
5365 unsigned long irqflags;
5366 int ret = -ENODEV;
5367
5368 hw = wl1271_alloc_hw();
5369 if (IS_ERR(hw)) {
5370 wl1271_error("can't allocate hw");
5371 ret = PTR_ERR(hw);
5372 goto out;
5373 }
5374
5375 wl = hw->priv;
5376 wl->irq = platform_get_irq(pdev, 0);
5377 wl->ref_clock = pdata->board_ref_clock;
5378 wl->tcxo_clock = pdata->board_tcxo_clock;
5379 wl->platform_quirks = pdata->platform_quirks;
5380 wl->set_power = pdata->set_power;
5381 wl->dev = &pdev->dev;
5382 wl->if_ops = pdata->ops;
5383
5384 platform_set_drvdata(pdev, wl);
5385
5386 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5387 irqflags = IRQF_TRIGGER_RISING;
5388 else
5389 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5390
5391 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5392 irqflags,
5393 pdev->name, wl);
5394 if (ret < 0) {
5395 wl1271_error("request_irq() failed: %d", ret);
5396 goto out_free_hw;
5397 }
5398
5399 ret = enable_irq_wake(wl->irq);
5400 if (!ret) {
5401 wl->irq_wake_enabled = true;
5402 device_init_wakeup(wl->dev, 1);
5403 if (pdata->pwr_in_suspend)
5404 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5405
5406 }
5407 disable_irq(wl->irq);
5408
5409 ret = wl1271_init_ieee80211(wl);
5410 if (ret)
5411 goto out_irq;
5412
5413 ret = wl1271_register_hw(wl);
5414 if (ret)
5415 goto out_irq;
5416
Felipe Balbif79f8902011-10-06 13:05:25 +03005417 /* Create sysfs file to control bt coex state */
5418 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5419 if (ret < 0) {
5420 wl1271_error("failed to create sysfs file bt_coex_state");
5421 goto out_irq;
5422 }
5423
5424 /* Create sysfs file to get HW PG version */
5425 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5426 if (ret < 0) {
5427 wl1271_error("failed to create sysfs file hw_pg_ver");
5428 goto out_bt_coex_state;
5429 }
5430
5431 /* Create sysfs file for the FW log */
5432 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5433 if (ret < 0) {
5434 wl1271_error("failed to create sysfs file fwlog");
5435 goto out_hw_pg_ver;
5436 }
5437
Felipe Balbice2a2172011-10-05 14:12:55 +03005438 return 0;
Felipe Balbia390e852011-10-06 10:07:44 +03005439
Felipe Balbif79f8902011-10-06 13:05:25 +03005440out_hw_pg_ver:
5441 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5442
5443out_bt_coex_state:
5444 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5445
Felipe Balbia390e852011-10-06 10:07:44 +03005446out_irq:
5447 free_irq(wl->irq, wl);
5448
5449out_free_hw:
5450 wl1271_free_hw(wl);
5451
5452out:
5453 return ret;
Felipe Balbice2a2172011-10-05 14:12:55 +03005454}
5455
5456static int __devexit wl12xx_remove(struct platform_device *pdev)
5457{
Felipe Balbia390e852011-10-06 10:07:44 +03005458 struct wl1271 *wl = platform_get_drvdata(pdev);
5459
5460 if (wl->irq_wake_enabled) {
5461 device_init_wakeup(wl->dev, 0);
5462 disable_irq_wake(wl->irq);
5463 }
5464 wl1271_unregister_hw(wl);
5465 free_irq(wl->irq, wl);
5466 wl1271_free_hw(wl);
5467
Felipe Balbice2a2172011-10-05 14:12:55 +03005468 return 0;
5469}
5470
5471static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005472 { "wl12xx", 0 },
Felipe Balbice2a2172011-10-05 14:12:55 +03005473 { } /* Terminating Entry */
5474};
5475MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5476
5477static struct platform_driver wl12xx_driver = {
5478 .probe = wl12xx_probe,
5479 .remove = __devexit_p(wl12xx_remove),
5480 .id_table = wl12xx_id_table,
5481 .driver = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005482 .name = "wl12xx_driver",
Felipe Balbice2a2172011-10-05 14:12:55 +03005483 .owner = THIS_MODULE,
5484 }
5485};
5486
5487static int __init wl12xx_init(void)
5488{
5489 return platform_driver_register(&wl12xx_driver);
5490}
5491module_init(wl12xx_init);
5492
5493static void __exit wl12xx_exit(void)
5494{
5495 platform_driver_unregister(&wl12xx_driver);
5496}
5497module_exit(wl12xx_exit);
5498
Guy Eilam491bbd62011-01-12 10:33:29 +01005499u32 wl12xx_debug_level = DEBUG_NONE;
Eliad Peller17c17552010-12-12 12:15:35 +02005500EXPORT_SYMBOL_GPL(wl12xx_debug_level);
Guy Eilam491bbd62011-01-12 10:33:29 +01005501module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
Eliad Peller17c17552010-12-12 12:15:35 +02005502MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5503
Ido Yariv95dac04f2011-06-06 14:57:06 +03005504module_param_named(fwlog, fwlog_param, charp, 0);
Luciano Coelho2c882fa2012-02-07 12:37:33 +02005505MODULE_PARM_DESC(fwlog,
Ido Yariv95dac04f2011-06-06 14:57:06 +03005506 "FW logger options: continuous, ondemand, dbgpins or disable");
5507
Eliad Peller2a5bff02011-08-25 18:10:59 +03005508module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5509MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5510
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005511MODULE_LICENSE("GPL");
Luciano Coelhob1a48ca2011-02-22 14:19:28 +02005512MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005513MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");