blob: 6b240868ac754da73aa4ddce497f23ab2ca0eca5 [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,
Arik Nemtsov801f8702011-04-18 14:15:20 +0300119 },
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200120 .state = CONF_SG_PROTECTIVE,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300121 },
122 .rx = {
123 .rx_msdu_life_time = 512000,
124 .packet_detection_threshold = 0,
125 .ps_poll_timeout = 15,
126 .upsd_timeout = 15,
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300127 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200128 .rx_cca_threshold = 0,
129 .irq_blk_threshold = 0xFFFF,
130 .irq_pkt_threshold = 0,
131 .irq_timeout = 600,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300132 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
133 },
134 .tx = {
135 .tx_energy_detection = 0,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200136 .sta_rc_conf = {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300137 .enabled_rates = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300138 .short_retry_limit = 10,
139 .long_retry_limit = 10,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200140 .aflags = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300141 },
142 .ac_conf_count = 4,
143 .ac_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200144 [CONF_TX_AC_BE] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300145 .ac = CONF_TX_AC_BE,
146 .cw_min = 15,
147 .cw_max = 63,
148 .aifsn = 3,
149 .tx_op_limit = 0,
150 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200151 [CONF_TX_AC_BK] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300152 .ac = CONF_TX_AC_BK,
153 .cw_min = 15,
154 .cw_max = 63,
155 .aifsn = 7,
156 .tx_op_limit = 0,
157 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200158 [CONF_TX_AC_VI] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300159 .ac = CONF_TX_AC_VI,
160 .cw_min = 15,
161 .cw_max = 63,
162 .aifsn = CONF_TX_AIFS_PIFS,
163 .tx_op_limit = 3008,
164 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200165 [CONF_TX_AC_VO] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300166 .ac = CONF_TX_AC_VO,
167 .cw_min = 15,
168 .cw_max = 63,
169 .aifsn = CONF_TX_AIFS_PIFS,
170 .tx_op_limit = 1504,
171 },
172 },
Arik Nemtsov3618f302011-06-26 10:36:03 +0300173 .max_tx_retries = 100,
174 .ap_aging_period = 300,
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200175 .tid_conf_count = 4,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300176 .tid_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200177 [CONF_TX_AC_BE] = {
178 .queue_id = CONF_TX_AC_BE,
179 .channel_type = CONF_CHANNEL_TYPE_EDCF,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300180 .tsid = CONF_TX_AC_BE,
181 .ps_scheme = CONF_PS_SCHEME_LEGACY,
182 .ack_policy = CONF_ACK_POLICY_LEGACY,
183 .apsd_conf = {0, 0},
184 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200185 [CONF_TX_AC_BK] = {
186 .queue_id = CONF_TX_AC_BK,
187 .channel_type = CONF_CHANNEL_TYPE_EDCF,
188 .tsid = CONF_TX_AC_BK,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300189 .ps_scheme = CONF_PS_SCHEME_LEGACY,
190 .ack_policy = CONF_ACK_POLICY_LEGACY,
191 .apsd_conf = {0, 0},
192 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200193 [CONF_TX_AC_VI] = {
194 .queue_id = CONF_TX_AC_VI,
195 .channel_type = CONF_CHANNEL_TYPE_EDCF,
196 .tsid = CONF_TX_AC_VI,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300197 .ps_scheme = CONF_PS_SCHEME_LEGACY,
198 .ack_policy = CONF_ACK_POLICY_LEGACY,
199 .apsd_conf = {0, 0},
200 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200201 [CONF_TX_AC_VO] = {
202 .queue_id = CONF_TX_AC_VO,
203 .channel_type = CONF_CHANNEL_TYPE_EDCF,
204 .tsid = CONF_TX_AC_VO,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300205 .ps_scheme = CONF_PS_SCHEME_LEGACY,
206 .ack_policy = CONF_ACK_POLICY_LEGACY,
207 .apsd_conf = {0, 0},
208 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300209 },
210 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200211 .tx_compl_timeout = 700,
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300212 .tx_compl_threshold = 4,
213 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
214 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200215 .tmpl_short_retry_limit = 10,
216 .tmpl_long_retry_limit = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300217 },
218 .conn = {
219 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300220 .listen_interval = 1,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300221 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
Shahar Levibc76b942011-05-11 11:14:22 +0300222 .bcn_filt_ie_count = 2,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300223 .bcn_filt_ie = {
224 [0] = {
225 .ie = WLAN_EID_CHANNEL_SWITCH,
226 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
Shahar Levibc76b942011-05-11 11:14:22 +0300227 },
228 [1] = {
229 .ie = WLAN_EID_HT_INFORMATION,
230 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
231 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300232 },
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200233 .synch_fail_thold = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300234 .bss_lose_timeout = 100,
235 .beacon_rx_timeout = 10000,
236 .broadcast_timeout = 20000,
237 .rx_broadcast_in_ps = 1,
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300238 .ps_poll_threshold = 10,
Juuso Oikarinen11f70f92009-10-13 12:47:46 +0300239 .bet_enable = CONF_BET_MODE_ENABLE,
Ohad Ben-Cohen958b20e2011-03-14 18:53:10 +0200240 .bet_max_consecutive = 50,
Eliad Pellera879ed72011-08-23 16:37:02 +0300241 .psm_entry_retries = 8,
Shahar Levi23708412011-04-13 14:52:50 +0300242 .psm_exit_retries = 16,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200243 .psm_entry_nullfunc_retries = 3,
Eyal Shapiraf1d63a52012-01-31 11:57:21 +0200244 .dynamic_ps_timeout = 100,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300245 .keep_alive_interval = 55000,
246 .max_listen_interval = 20,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300247 },
Luciano Coelho6e92b412009-12-11 15:40:50 +0200248 .itrim = {
249 .enable = false,
250 .timeout = 50000,
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200251 },
252 .pm_config = {
253 .host_clk_settling_time = 5000,
254 .host_fast_wakeup_support = false
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300255 },
256 .roam_trigger = {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300257 .trigger_pacing = 1,
258 .avg_weight_rssi_beacon = 20,
259 .avg_weight_rssi_data = 10,
260 .avg_weight_snr_beacon = 20,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100261 .avg_weight_snr_data = 10,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200262 },
263 .scan = {
264 .min_dwell_time_active = 7500,
265 .max_dwell_time_active = 30000,
Juuso Oikarinenea45b2c2011-01-24 07:01:54 +0100266 .min_dwell_time_passive = 100000,
267 .max_dwell_time_passive = 100000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200268 .num_probe_reqs = 2,
269 },
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300270 .sched_scan = {
271 /* sched_scan requires dwell times in TU instead of TU/1000 */
Luciano Coelho221737d2011-09-02 14:28:22 +0300272 .min_dwell_time_active = 30,
273 .max_dwell_time_active = 60,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300274 .dwell_time_passive = 100,
Luciano Coelho50a66d72011-05-27 15:34:47 +0300275 .dwell_time_dfs = 150,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300276 .num_probe_reqs = 2,
277 .rssi_threshold = -90,
278 .snr_threshold = 0,
279 },
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200280 .rf = {
281 .tx_per_channel_power_compensation_2 = {
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 },
284 .tx_per_channel_power_compensation_5 = {
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 },
289 },
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100290 .ht = {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300291 .rx_ba_win_size = 8,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100292 .tx_ba_win_size = 64,
293 .inactivity_timeout = 10000,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300294 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100295 },
Shahar Levi13b107d2011-03-06 16:32:12 +0200296 .mem_wl127x = {
Eliad Pellerfe5ef092011-02-02 09:59:36 +0200297 .num_stations = 1,
298 .ssid_profiles = 1,
299 .rx_block_num = 70,
300 .tx_min_block_num = 40,
Ido Yariv4cf557f2011-04-18 16:45:10 +0300301 .dynamic_memory = 1,
Ido Yarivb16d4b62011-03-01 15:14:44 +0200302 .min_req_tx_blocks = 100,
Eliad Pellerc8bde242011-02-02 09:59:35 +0200303 .min_req_rx_blocks = 22,
304 .tx_min = 27,
Shahar Levi13b107d2011-03-06 16:32:12 +0200305 },
306 .mem_wl128x = {
307 .num_stations = 1,
308 .ssid_profiles = 1,
309 .rx_block_num = 40,
310 .tx_min_block_num = 40,
311 .dynamic_memory = 1,
312 .min_req_tx_blocks = 45,
313 .min_req_rx_blocks = 22,
314 .tx_min = 27,
315 },
Shahar Leviff868432011-04-11 15:41:46 +0300316 .fm_coex = {
317 .enable = true,
318 .swallow_period = 5,
319 .n_divider_fref_set_1 = 0xff, /* default */
320 .n_divider_fref_set_2 = 12,
321 .m_divider_fref_set_1 = 148,
322 .m_divider_fref_set_2 = 0xffff, /* default */
323 .coex_pll_stabilization_time = 0xffffffff, /* default */
324 .ldo_stabilization_time = 0xffff, /* default */
325 .fm_disturbed_band_margin = 0xff, /* default */
326 .swallow_clk_diff = 0xff, /* default */
327 },
Eliad Pellerf84673d2011-05-15 11:10:28 +0300328 .rx_streaming = {
329 .duration = 150,
330 .queues = 0x1,
331 .interval = 20,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300332 .always = 0,
Eliad Pellerf84673d2011-05-15 11:10:28 +0300333 },
Ido Yariv95dac04f2011-06-06 14:57:06 +0300334 .fwlog = {
335 .mode = WL12XX_FWLOG_ON_DEMAND,
336 .mem_blocks = 2,
337 .severity = 0,
338 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
339 .output = WL12XX_FWLOG_OUTPUT_HOST,
340 .threshold = 0,
341 },
Luciano Coelhoafb7d3c2011-04-01 20:48:02 +0300342 .hci_io_ds = HCI_IO_DS_6MA,
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300343 .rate = {
344 .rate_retry_score = 32000,
345 .per_add = 8192,
346 .per_th1 = 2048,
347 .per_th2 = 4096,
348 .max_per = 8100,
349 .inverse_curiosity_factor = 5,
350 .tx_fail_low_th = 4,
351 .tx_fail_high_th = 10,
352 .per_alpha_shift = 4,
353 .per_add_shift = 13,
354 .per_beta1_shift = 10,
355 .per_beta2_shift = 8,
356 .rate_check_up = 2,
357 .rate_check_down = 12,
358 .rate_retry_policy = {
359 0x00, 0x00, 0x00, 0x00, 0x00,
360 0x00, 0x00, 0x00, 0x00, 0x00,
361 0x00, 0x00, 0x00,
362 },
363 },
Eliad Peller94877752011-08-28 15:11:56 +0300364 .hangover = {
365 .recover_time = 0,
366 .hangover_period = 20,
367 .dynamic_mode = 1,
368 .early_termination_mode = 1,
369 .max_period = 20,
370 .min_period = 1,
371 .increase_delta = 1,
372 .decrease_delta = 2,
373 .quiet_time = 4,
374 .increase_time = 1,
375 .window_size = 16,
376 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300377};
378
Ido Yariv95dac04f2011-06-06 14:57:06 +0300379static char *fwlog_param;
Eliad Peller2a5bff02011-08-25 18:10:59 +0300380static bool bug_on_recovery;
Ido Yariv95dac04f2011-06-06 14:57:06 +0300381
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300382static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +0200383 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300384 bool reset_tx_queues);
Eliad Pellerf0277432011-10-10 10:13:14 +0200385static void wl1271_op_stop(struct ieee80211_hw *hw);
Eliad Peller170d0e62011-10-05 11:56:06 +0200386static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200387
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200388static DEFINE_MUTEX(wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +0300389static LIST_HEAD(wl_list);
390
Eliad Pellerba8447f2011-10-10 10:13:00 +0200391static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
392 unsigned char operstate)
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300393{
394 int ret;
Eliad Peller0603d892011-10-05 11:55:51 +0200395
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300396 if (operstate != IF_OPER_UP)
397 return 0;
398
Eliad Peller8181aec2011-10-10 10:13:04 +0200399 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300400 return 0;
401
Eliad Peller154da672011-10-05 11:55:53 +0200402 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300403 if (ret < 0)
404 return ret;
405
Eliad Peller0603d892011-10-05 11:55:51 +0200406 wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +0300407
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300408 wl1271_info("Association completed.");
409 return 0;
410}
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300411static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
412 void *arg)
413{
414 struct net_device *dev = arg;
415 struct wireless_dev *wdev;
416 struct wiphy *wiphy;
417 struct ieee80211_hw *hw;
418 struct wl1271 *wl;
419 struct wl1271 *wl_temp;
Eliad Pellerba8447f2011-10-10 10:13:00 +0200420 struct wl12xx_vif *wlvif;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300421 int ret = 0;
422
423 /* Check that this notification is for us. */
424 if (what != NETDEV_CHANGE)
425 return NOTIFY_DONE;
426
427 wdev = dev->ieee80211_ptr;
428 if (wdev == NULL)
429 return NOTIFY_DONE;
430
431 wiphy = wdev->wiphy;
432 if (wiphy == NULL)
433 return NOTIFY_DONE;
434
435 hw = wiphy_priv(wiphy);
436 if (hw == NULL)
437 return NOTIFY_DONE;
438
439 wl_temp = hw->priv;
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200440 mutex_lock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300441 list_for_each_entry(wl, &wl_list, list) {
442 if (wl == wl_temp)
443 break;
444 }
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +0200445 mutex_unlock(&wl_list_mutex);
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300446 if (wl != wl_temp)
447 return NOTIFY_DONE;
448
449 mutex_lock(&wl->mutex);
450
451 if (wl->state == WL1271_STATE_OFF)
452 goto out;
453
Eliad Peller6ab70912011-12-18 20:25:45 +0200454 if (dev->operstate != IF_OPER_UP)
455 goto out;
456 /*
457 * The correct behavior should be just getting the appropriate wlvif
458 * from the given dev, but currently we don't have a mac80211
459 * interface for it.
460 */
Eliad Pellerba8447f2011-10-10 10:13:00 +0200461 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller6ab70912011-12-18 20:25:45 +0200462 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
463
Eliad Pellerba8447f2011-10-10 10:13:00 +0200464 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
465 continue;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300466
Eliad Pellerba8447f2011-10-10 10:13:00 +0200467 ret = wl1271_ps_elp_wakeup(wl);
468 if (ret < 0)
469 goto out;
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300470
Eliad Peller6ab70912011-12-18 20:25:45 +0200471 wl1271_check_operstate(wl, wlvif,
472 ieee80211_get_operstate(vif));
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300473
Eliad Pellerba8447f2011-10-10 10:13:00 +0200474 wl1271_ps_elp_sleep(wl);
475 }
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300476out:
477 mutex_unlock(&wl->mutex);
478
479 return NOTIFY_OK;
480}
481
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100482static int wl1271_reg_notify(struct wiphy *wiphy,
Luciano Coelho573c67c2010-11-26 13:44:59 +0200483 struct regulatory_request *request)
484{
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100485 struct ieee80211_supported_band *band;
486 struct ieee80211_channel *ch;
487 int i;
488
489 band = wiphy->bands[IEEE80211_BAND_5GHZ];
490 for (i = 0; i < band->n_channels; i++) {
491 ch = &band->channels[i];
492 if (ch->flags & IEEE80211_CHAN_DISABLED)
493 continue;
494
495 if (ch->flags & IEEE80211_CHAN_RADAR)
496 ch->flags |= IEEE80211_CHAN_NO_IBSS |
497 IEEE80211_CHAN_PASSIVE_SCAN;
498
499 }
500
501 return 0;
502}
503
Eliad Peller9eb599e2011-10-10 10:12:59 +0200504static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
505 bool enable)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300506{
507 int ret = 0;
508
509 /* we should hold wl->mutex */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200510 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300511 if (ret < 0)
512 goto out;
513
514 if (enable)
Eliad Peller0744bdb2011-10-10 10:13:05 +0200515 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300516 else
Eliad Peller0744bdb2011-10-10 10:13:05 +0200517 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300518out:
519 return ret;
520}
521
522/*
523 * this function is being called when the rx_streaming interval
524 * has beed changed or rx_streaming should be disabled
525 */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200526int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300527{
528 int ret = 0;
529 int period = wl->conf.rx_streaming.interval;
530
531 /* don't reconfigure if rx_streaming is disabled */
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 /* reconfigure/disable according to new streaming_period */
536 if (period &&
Eliad Pellerba8447f2011-10-10 10:13:00 +0200537 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eliad Peller77ddaa12011-05-15 11:10:29 +0300538 (wl->conf.rx_streaming.always ||
539 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
Eliad Peller9eb599e2011-10-10 10:12:59 +0200540 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300541 else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200542 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300543 /* don't cancel_work_sync since we might deadlock */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200544 del_timer_sync(&wlvif->rx_streaming_timer);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300545 }
546out:
547 return ret;
548}
549
550static void wl1271_rx_streaming_enable_work(struct work_struct *work)
551{
552 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200553 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
554 rx_streaming_enable_work);
555 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300556
557 mutex_lock(&wl->mutex);
558
Eliad Peller0744bdb2011-10-10 10:13:05 +0200559 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
Eliad Pellerba8447f2011-10-10 10:13:00 +0200560 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller77ddaa12011-05-15 11:10:29 +0300561 (!wl->conf.rx_streaming.always &&
562 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
563 goto out;
564
565 if (!wl->conf.rx_streaming.interval)
566 goto out;
567
568 ret = wl1271_ps_elp_wakeup(wl);
569 if (ret < 0)
570 goto out;
571
Eliad Peller9eb599e2011-10-10 10:12:59 +0200572 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300573 if (ret < 0)
574 goto out_sleep;
575
576 /* stop it after some time of inactivity */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200577 mod_timer(&wlvif->rx_streaming_timer,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300578 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
579
580out_sleep:
581 wl1271_ps_elp_sleep(wl);
582out:
583 mutex_unlock(&wl->mutex);
584}
585
586static void wl1271_rx_streaming_disable_work(struct work_struct *work)
587{
588 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200589 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
590 rx_streaming_disable_work);
591 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300592
593 mutex_lock(&wl->mutex);
594
Eliad Peller0744bdb2011-10-10 10:13:05 +0200595 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300596 goto out;
597
598 ret = wl1271_ps_elp_wakeup(wl);
599 if (ret < 0)
600 goto out;
601
Eliad Peller9eb599e2011-10-10 10:12:59 +0200602 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300603 if (ret)
604 goto out_sleep;
605
606out_sleep:
607 wl1271_ps_elp_sleep(wl);
608out:
609 mutex_unlock(&wl->mutex);
610}
611
612static void wl1271_rx_streaming_timer(unsigned long data)
613{
Eliad Peller9eb599e2011-10-10 10:12:59 +0200614 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
615 struct wl1271 *wl = wlvif->wl;
616 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300617}
618
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300619static void wl1271_conf_init(struct wl1271 *wl)
620{
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300621
622 /*
623 * This function applies the default configuration to the driver. This
624 * function is invoked upon driver load (spi probe.)
625 *
626 * The configuration is stored in a run-time structure in order to
627 * facilitate for run-time adjustment of any of the parameters. Making
628 * changes to the configuration structure will apply the new values on
629 * the next interface up (wl1271_op_start.)
630 */
631
632 /* apply driver default configuration */
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300633 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300634
Ido Yariv95dac04f2011-06-06 14:57:06 +0300635 /* Adjust settings according to optional module parameters */
636 if (fwlog_param) {
637 if (!strcmp(fwlog_param, "continuous")) {
638 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
639 } else if (!strcmp(fwlog_param, "ondemand")) {
640 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
641 } else if (!strcmp(fwlog_param, "dbgpins")) {
642 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
643 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
644 } else if (!strcmp(fwlog_param, "disable")) {
645 wl->conf.fwlog.mem_blocks = 0;
646 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
647 } else {
648 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
649 }
650 }
651}
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300652
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300653static int wl1271_plt_init(struct wl1271 *wl)
654{
Eliad Peller188e7f52011-12-06 12:15:06 +0200655 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300656
Shahar Levi49d750ca2011-03-06 16:32:09 +0200657 if (wl->chip.id == CHIP_ID_1283_PG20)
658 ret = wl128x_cmd_general_parms(wl);
659 else
660 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200661 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200662 return ret;
663
Shahar Levi49d750ca2011-03-06 16:32:09 +0200664 if (wl->chip.id == CHIP_ID_1283_PG20)
665 ret = wl128x_cmd_radio_parms(wl);
666 else
667 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200668 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200669 return ret;
670
Shahar Levi49d750ca2011-03-06 16:32:09 +0200671 if (wl->chip.id != CHIP_ID_1283_PG20) {
672 ret = wl1271_cmd_ext_radio_parms(wl);
673 if (ret < 0)
674 return ret;
675 }
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200676 if (ret < 0)
677 return ret;
678
Shahar Levi48a61472011-03-06 16:32:08 +0200679 /* Chip-specific initializations */
680 ret = wl1271_chip_specific_init(wl);
681 if (ret < 0)
682 return ret;
683
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300684 ret = wl1271_acx_init_mem_config(wl);
685 if (ret < 0)
686 return ret;
687
Eliad Peller7f0979882011-08-14 13:17:06 +0300688 ret = wl12xx_acx_mem_cfg(wl);
Gery Kahn1ec610e2011-02-01 03:03:08 -0600689 if (ret < 0)
690 goto out_free_memmap;
691
Luciano Coelho12419cc2010-02-18 13:25:44 +0200692 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200693 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300694 if (ret < 0)
Luciano Coelho12419cc2010-02-18 13:25:44 +0200695 goto out_free_memmap;
696
697 /* Configure for CAM power saving (ie. always active) */
698 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
699 if (ret < 0)
700 goto out_free_memmap;
701
702 /* configure PM */
703 ret = wl1271_acx_pm_config(wl);
704 if (ret < 0)
705 goto out_free_memmap;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300706
707 return 0;
Luciano Coelho12419cc2010-02-18 13:25:44 +0200708
709 out_free_memmap:
710 kfree(wl->target_mem_map);
711 wl->target_mem_map = NULL;
712
713 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300714}
715
Eliad Peller6e8cd332011-10-10 10:13:13 +0200716static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
717 struct wl12xx_vif *wlvif,
718 u8 hlid, u8 tx_pkts)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200719{
Arik Nemtsovda032092011-08-25 12:43:15 +0300720 bool fw_ps, single_sta;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200721
Arik Nemtsovb622d992011-02-23 00:22:31 +0200722 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Arik Nemtsovda032092011-08-25 12:43:15 +0300723 single_sta = (wl->active_sta_count == 1);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200724
725 /*
726 * Wake up from high level PS if the STA is asleep with too little
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300727 * packets in FW or if the STA is awake.
Arik Nemtsovb622d992011-02-23 00:22:31 +0200728 */
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300729 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200730 wl12xx_ps_link_end(wl, wlvif, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200731
Arik Nemtsovda032092011-08-25 12:43:15 +0300732 /*
733 * Start high-level PS if the STA is asleep with enough blocks in FW.
734 * Make an exception if this is the only connected station. In this
735 * case FW-memory congestion is not a problem.
736 */
737 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200738 wl12xx_ps_link_start(wl, wlvif, hlid, true);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200739}
740
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300741static void wl12xx_irq_update_links_status(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200742 struct wl12xx_vif *wlvif,
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300743 struct wl12xx_fw_status *status)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200744{
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200745 struct wl1271_link *lnk;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200746 u32 cur_fw_ps_map;
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300747 u8 hlid, cnt;
748
749 /* TODO: also use link_fast_bitmap here */
Arik Nemtsovb622d992011-02-23 00:22:31 +0200750
751 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
752 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
753 wl1271_debug(DEBUG_PSM,
754 "link ps prev 0x%x cur 0x%x changed 0x%x",
755 wl->ap_fw_ps_map, cur_fw_ps_map,
756 wl->ap_fw_ps_map ^ cur_fw_ps_map);
757
758 wl->ap_fw_ps_map = cur_fw_ps_map;
759 }
760
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200761 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
762 lnk = &wl->links[hlid];
763 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200764
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200765 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
766 lnk->allocated_pkts -= cnt;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200767
Eliad Peller6e8cd332011-10-10 10:13:13 +0200768 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
769 lnk->allocated_pkts);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200770 }
771}
772
Eliad Peller4d56ad92011-08-14 13:17:05 +0300773static void wl12xx_fw_status(struct wl1271 *wl,
774 struct wl12xx_fw_status *status)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300775{
Eliad Peller6e8cd332011-10-10 10:13:13 +0200776 struct wl12xx_vif *wlvif;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200777 struct timespec ts;
Shahar Levi13b107d2011-03-06 16:32:12 +0200778 u32 old_tx_blk_count = wl->tx_blocks_available;
Eliad Peller4d56ad92011-08-14 13:17:05 +0300779 int avail, freed_blocks;
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300780 int i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300781
Eliad Peller4d56ad92011-08-14 13:17:05 +0300782 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
Shahar Levi13b107d2011-03-06 16:32:12 +0200783
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300784 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
785 "drv_rx_counter = %d, tx_results_counter = %d)",
786 status->intr,
787 status->fw_rx_counter,
788 status->drv_rx_counter,
789 status->tx_results_counter);
790
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300791 for (i = 0; i < NUM_TX_QUEUES; i++) {
792 /* prevent wrap-around in freed-packets counter */
Arik Nemtsov742246f2011-08-14 13:17:33 +0300793 wl->tx_allocated_pkts[i] -=
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300794 (status->tx_released_pkts[i] -
795 wl->tx_pkts_freed[i]) & 0xff;
796
797 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
798 }
799
Arik Nemtsovbdf91cf2011-08-14 13:17:34 +0300800 /* prevent wrap-around in total blocks counter */
801 if (likely(wl->tx_blocks_freed <=
802 le32_to_cpu(status->total_released_blks)))
803 freed_blocks = le32_to_cpu(status->total_released_blks) -
804 wl->tx_blocks_freed;
805 else
806 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
807 le32_to_cpu(status->total_released_blks);
808
Eliad Peller4d56ad92011-08-14 13:17:05 +0300809 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
Shahar Levi13b107d2011-03-06 16:32:12 +0200810
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300811 wl->tx_allocated_blocks -= freed_blocks;
812
Eliad Peller4d56ad92011-08-14 13:17:05 +0300813 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200814
Eliad Peller4d56ad92011-08-14 13:17:05 +0300815 /*
816 * The FW might change the total number of TX memblocks before
817 * we get a notification about blocks being released. Thus, the
818 * available blocks calculation might yield a temporary result
819 * which is lower than the actual available blocks. Keeping in
820 * mind that only blocks that were allocated can be moved from
821 * TX to RX, tx_blocks_available should never decrease here.
822 */
823 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
824 avail);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300825
Ido Yariva5225502010-10-12 14:49:10 +0200826 /* if more blocks are available now, tx work can be scheduled */
Shahar Levi13b107d2011-03-06 16:32:12 +0200827 if (wl->tx_blocks_available > old_tx_blk_count)
Ido Yariva5225502010-10-12 14:49:10 +0200828 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300829
Eliad Peller4d56ad92011-08-14 13:17:05 +0300830 /* for AP update num of allocated TX blocks per link and ps status */
Eliad Peller6e8cd332011-10-10 10:13:13 +0200831 wl12xx_for_each_wlvif_ap(wl, wlvif) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200832 wl12xx_irq_update_links_status(wl, wlvif, status);
Eliad Peller6e8cd332011-10-10 10:13:13 +0200833 }
Eliad Peller4d56ad92011-08-14 13:17:05 +0300834
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300835 /* update the host-chipset time offset */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200836 getnstimeofday(&ts);
837 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
838 (s64)le32_to_cpu(status->fw_localtime);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300839}
840
Ido Yariva6208652011-03-01 15:14:41 +0200841static void wl1271_flush_deferred_work(struct wl1271 *wl)
842{
843 struct sk_buff *skb;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200844
Ido Yariva6208652011-03-01 15:14:41 +0200845 /* Pass all received frames to the network stack */
846 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
847 ieee80211_rx_ni(wl->hw, skb);
848
849 /* Return sent skbs to the network stack */
850 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300851 ieee80211_tx_status_ni(wl->hw, skb);
Ido Yariva6208652011-03-01 15:14:41 +0200852}
853
854static void wl1271_netstack_work(struct work_struct *work)
855{
856 struct wl1271 *wl =
857 container_of(work, struct wl1271, netstack_work);
858
859 do {
860 wl1271_flush_deferred_work(wl);
861 } while (skb_queue_len(&wl->deferred_rx_queue));
862}
863
864#define WL1271_IRQ_MAX_LOOPS 256
865
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300866static irqreturn_t wl1271_irq(int irq, void *cookie)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300867{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300868 int ret;
Juuso Oikarinenc15f63b2009-10-12 15:08:50 +0300869 u32 intr;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200870 int loopcount = WL1271_IRQ_MAX_LOOPS;
Ido Yariva6208652011-03-01 15:14:41 +0200871 struct wl1271 *wl = (struct wl1271 *)cookie;
872 bool done = false;
873 unsigned int defer_count;
Ido Yarivb07d4032011-03-01 15:14:43 +0200874 unsigned long flags;
875
876 /* TX might be handled here, avoid redundant work */
877 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
878 cancel_work_sync(&wl->tx_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300879
Ido Yariv341b7cd2011-03-31 10:07:01 +0200880 /*
881 * In case edge triggered interrupt must be used, we cannot iterate
882 * more than once without introducing race conditions with the hardirq.
883 */
884 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
885 loopcount = 1;
886
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300887 mutex_lock(&wl->mutex);
888
889 wl1271_debug(DEBUG_IRQ, "IRQ work");
890
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200891 if (unlikely(wl->state == WL1271_STATE_OFF))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300892 goto out;
893
Ido Yariva6208652011-03-01 15:14:41 +0200894 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300895 if (ret < 0)
896 goto out;
897
Ido Yariva6208652011-03-01 15:14:41 +0200898 while (!done && loopcount--) {
899 /*
900 * In order to avoid a race with the hardirq, clear the flag
901 * before acknowledging the chip. Since the mutex is held,
902 * wl1271_ps_elp_wakeup cannot be called concurrently.
903 */
904 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
905 smp_mb__after_clear_bit();
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200906
Eliad Peller4d56ad92011-08-14 13:17:05 +0300907 wl12xx_fw_status(wl, wl->fw_status);
908 intr = le32_to_cpu(wl->fw_status->intr);
Ido Yariva6208652011-03-01 15:14:41 +0200909 intr &= WL1271_INTR_MASK;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200910 if (!intr) {
Ido Yariva6208652011-03-01 15:14:41 +0200911 done = true;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200912 continue;
913 }
914
Eliad Pellerccc83b02010-10-27 14:09:57 +0200915 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
916 wl1271_error("watchdog interrupt received! "
917 "starting recovery.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300918 wl12xx_queue_recovery_work(wl);
Eliad Pellerccc83b02010-10-27 14:09:57 +0200919
920 /* restarting the chip. ignore any other interrupt. */
921 goto out;
922 }
923
Ido Yariva6208652011-03-01 15:14:41 +0200924 if (likely(intr & WL1271_ACX_INTR_DATA)) {
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200925 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
926
Eliad Peller4d56ad92011-08-14 13:17:05 +0300927 wl12xx_rx(wl, wl->fw_status);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200928
Ido Yariva5225502010-10-12 14:49:10 +0200929 /* Check if any tx blocks were freed */
Ido Yarivb07d4032011-03-01 15:14:43 +0200930 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200931 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300932 wl1271_tx_total_queue_count(wl) > 0) {
Ido Yarivb07d4032011-03-01 15:14:43 +0200933 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200934 /*
935 * In order to avoid starvation of the TX path,
936 * call the work function directly.
937 */
Eliad Pellera32d0cd2011-10-10 10:12:55 +0200938 wl1271_tx_work_locked(wl);
Ido Yarivb07d4032011-03-01 15:14:43 +0200939 } else {
940 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200941 }
942
Ido Yariv8aad2462011-03-01 15:14:38 +0200943 /* check for tx results */
Eliad Peller4d56ad92011-08-14 13:17:05 +0300944 if (wl->fw_status->tx_results_counter !=
Ido Yariv8aad2462011-03-01 15:14:38 +0200945 (wl->tx_results_count & 0xff))
946 wl1271_tx_complete(wl);
Ido Yariva6208652011-03-01 15:14:41 +0200947
948 /* Make sure the deferred queues don't get too long */
949 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
950 skb_queue_len(&wl->deferred_rx_queue);
951 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
952 wl1271_flush_deferred_work(wl);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200953 }
954
955 if (intr & WL1271_ACX_INTR_EVENT_A) {
956 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
957 wl1271_event_handle(wl, 0);
958 }
959
960 if (intr & WL1271_ACX_INTR_EVENT_B) {
961 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
962 wl1271_event_handle(wl, 1);
963 }
964
965 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
966 wl1271_debug(DEBUG_IRQ,
967 "WL1271_ACX_INTR_INIT_COMPLETE");
968
969 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
970 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300971 }
972
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300973 wl1271_ps_elp_sleep(wl);
974
975out:
Ido Yarivb07d4032011-03-01 15:14:43 +0200976 spin_lock_irqsave(&wl->wl_lock, flags);
977 /* In case TX was not handled here, queue TX work */
978 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
979 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300980 wl1271_tx_total_queue_count(wl) > 0)
Ido Yarivb07d4032011-03-01 15:14:43 +0200981 ieee80211_queue_work(wl->hw, &wl->tx_work);
982 spin_unlock_irqrestore(&wl->wl_lock, flags);
983
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300984 mutex_unlock(&wl->mutex);
Ido Yariva6208652011-03-01 15:14:41 +0200985
986 return IRQ_HANDLED;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300987}
988
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300989static int wl1271_fetch_firmware(struct wl1271 *wl)
990{
991 const struct firmware *fw;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200992 const char *fw_name;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300993 int ret;
994
Arik Nemtsovc302b2c2011-08-17 10:45:48 +0300995 if (wl->chip.id == CHIP_ID_1283_PG20)
996 fw_name = WL128X_FW_NAME;
997 else
998 fw_name = WL127X_FW_NAME;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200999
1000 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1001
Felipe Balbia390e852011-10-06 10:07:44 +03001002 ret = request_firmware(&fw, fw_name, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001003
1004 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001005 wl1271_error("could not get firmware %s: %d", fw_name, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001006 return ret;
1007 }
1008
1009 if (fw->size % 4) {
1010 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1011 fw->size);
1012 ret = -EILSEQ;
1013 goto out;
1014 }
1015
Arik Nemtsov166d5042010-10-16 21:44:57 +02001016 vfree(wl->fw);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001017 wl->fw_len = fw->size;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +03001018 wl->fw = vmalloc(wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001019
1020 if (!wl->fw) {
1021 wl1271_error("could not allocate memory for the firmware");
1022 ret = -ENOMEM;
1023 goto out;
1024 }
1025
1026 memcpy(wl->fw, fw->data, wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001027 ret = 0;
1028
1029out:
1030 release_firmware(fw);
1031
1032 return ret;
1033}
1034
1035static int wl1271_fetch_nvs(struct wl1271 *wl)
1036{
1037 const struct firmware *fw;
1038 int ret;
1039
Felipe Balbia390e852011-10-06 10:07:44 +03001040 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001041
1042 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001043 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1044 ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001045 return ret;
1046 }
1047
Shahar Levibc765bf2011-03-06 16:32:10 +02001048 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001049
1050 if (!wl->nvs) {
1051 wl1271_error("could not allocate memory for the nvs file");
1052 ret = -ENOMEM;
1053 goto out;
1054 }
1055
Juuso Oikarinen02fabb02010-08-19 04:41:15 +02001056 wl->nvs_len = fw->size;
1057
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001058out:
1059 release_firmware(fw);
1060
1061 return ret;
1062}
1063
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001064void wl12xx_queue_recovery_work(struct wl1271 *wl)
1065{
1066 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1067 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1068}
1069
Ido Yariv95dac04f2011-06-06 14:57:06 +03001070size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1071{
1072 size_t len = 0;
1073
1074 /* The FW log is a length-value list, find where the log end */
1075 while (len < maxlen) {
1076 if (memblock[len] == 0)
1077 break;
1078 if (len + memblock[len] + 1 > maxlen)
1079 break;
1080 len += memblock[len] + 1;
1081 }
1082
1083 /* Make sure we have enough room */
1084 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1085
1086 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1087 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1088 wl->fwlog_size += len;
1089
1090 return len;
1091}
1092
1093static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1094{
1095 u32 addr;
1096 u32 first_addr;
1097 u8 *block;
1098
1099 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1100 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1101 (wl->conf.fwlog.mem_blocks == 0))
1102 return;
1103
1104 wl1271_info("Reading FW panic log");
1105
1106 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1107 if (!block)
1108 return;
1109
1110 /*
1111 * Make sure the chip is awake and the logger isn't active.
1112 * This might fail if the firmware hanged.
1113 */
1114 if (!wl1271_ps_elp_wakeup(wl))
1115 wl12xx_cmd_stop_fwlog(wl);
1116
1117 /* Read the first memory block address */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001118 wl12xx_fw_status(wl, wl->fw_status);
1119 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001120 if (!first_addr)
1121 goto out;
1122
1123 /* Traverse the memory blocks linked list */
1124 addr = first_addr;
1125 do {
1126 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1127 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1128 false);
1129
1130 /*
1131 * Memory blocks are linked to one another. The first 4 bytes
1132 * of each memory block hold the hardware address of the next
1133 * one. The last memory block points to the first one.
1134 */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001135 addr = le32_to_cpup((__le32 *)block);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001136 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1137 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1138 break;
1139 } while (addr && (addr != first_addr));
1140
1141 wake_up_interruptible(&wl->fwlog_waitq);
1142
1143out:
1144 kfree(block);
1145}
1146
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001147static void wl1271_recovery_work(struct work_struct *work)
1148{
1149 struct wl1271 *wl =
1150 container_of(work, struct wl1271, recovery_work);
Eliad Peller48e93e42011-10-10 10:12:58 +02001151 struct wl12xx_vif *wlvif;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001152 struct ieee80211_vif *vif;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001153
1154 mutex_lock(&wl->mutex);
1155
1156 if (wl->state != WL1271_STATE_ON)
Eliad Pellerf0277432011-10-10 10:13:14 +02001157 goto out_unlock;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001158
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001159 /* Avoid a recursive recovery */
1160 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1161
Ido Yariv95dac04f2011-06-06 14:57:06 +03001162 wl12xx_read_fwlog_panic(wl);
1163
Arik Nemtsov52dcaf52011-04-18 14:15:24 +03001164 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1165 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001166
Eliad Peller2a5bff02011-08-25 18:10:59 +03001167 BUG_ON(bug_on_recovery);
1168
Oz Krakowskib992c682011-06-26 10:36:02 +03001169 /*
1170 * Advance security sequence number to overcome potential progress
1171 * in the firmware during recovery. This doens't hurt if the network is
1172 * not encrypted.
1173 */
Eliad Peller48e93e42011-10-10 10:12:58 +02001174 wl12xx_for_each_wlvif(wl, wlvif) {
Eliad Pellerba8447f2011-10-10 10:13:00 +02001175 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller53d40d02011-10-10 10:13:02 +02001176 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Peller48e93e42011-10-10 10:12:58 +02001177 wlvif->tx_security_seq +=
1178 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1179 }
Oz Krakowskib992c682011-06-26 10:36:02 +03001180
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001181 /* Prevent spurious TX during FW restart */
1182 ieee80211_stop_queues(wl->hw);
1183
Luciano Coelho33c2c062011-05-10 14:46:02 +03001184 if (wl->sched_scanning) {
1185 ieee80211_sched_scan_stopped(wl->hw);
1186 wl->sched_scanning = false;
1187 }
1188
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001189 /* reboot the chipset */
Eliad Peller6e8cd332011-10-10 10:13:13 +02001190 while (!list_empty(&wl->wlvif_list)) {
1191 wlvif = list_first_entry(&wl->wlvif_list,
1192 struct wl12xx_vif, list);
1193 vif = wl12xx_wlvif_to_vif(wlvif);
1194 __wl1271_op_remove_interface(wl, vif, false);
1195 }
Eliad Pellerf0277432011-10-10 10:13:14 +02001196 mutex_unlock(&wl->mutex);
1197 wl1271_op_stop(wl->hw);
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001198
1199 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1200
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001201 ieee80211_restart_hw(wl->hw);
1202
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001203 /*
1204 * Its safe to enable TX now - the queues are stopped after a request
1205 * to restart the HW.
1206 */
1207 ieee80211_wake_queues(wl->hw);
Eliad Pellerf0277432011-10-10 10:13:14 +02001208 return;
1209out_unlock:
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001210 mutex_unlock(&wl->mutex);
1211}
1212
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001213static void wl1271_fw_wakeup(struct wl1271 *wl)
1214{
1215 u32 elp_reg;
1216
1217 elp_reg = ELPCTRL_WAKE_UP;
Juuso Oikarinen74621412009-10-12 15:08:54 +03001218 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001219}
1220
1221static int wl1271_setup(struct wl1271 *wl)
1222{
1223 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1224 if (!wl->fw_status)
1225 return -ENOMEM;
1226
1227 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1228 if (!wl->tx_res_if) {
1229 kfree(wl->fw_status);
1230 return -ENOMEM;
1231 }
1232
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001233 return 0;
1234}
1235
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001236static int wl12xx_set_power_on(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001237{
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001238 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001239
Juuso Oikarinen01ac17e2009-12-11 15:41:02 +02001240 msleep(WL1271_PRE_POWER_ON_SLEEP);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +02001241 ret = wl1271_power_on(wl);
1242 if (ret < 0)
1243 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001244 msleep(WL1271_POWER_ON_SLEEP);
Teemu Paasikivi9b280722010-02-18 13:25:56 +02001245 wl1271_io_reset(wl);
1246 wl1271_io_init(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001247
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001248 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001249
1250 /* ELP module wake up */
1251 wl1271_fw_wakeup(wl);
1252
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001253out:
1254 return ret;
1255}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001256
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001257static int wl1271_chip_wakeup(struct wl1271 *wl)
1258{
1259 int ret = 0;
1260
1261 ret = wl12xx_set_power_on(wl);
1262 if (ret < 0)
1263 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001264
Luciano Coelhoe62c9ce2011-11-03 08:44:42 +02001265 /*
1266 * For wl127x based devices we could use the default block
1267 * size (512 bytes), but due to a bug in the sdio driver, we
1268 * need to set it explicitly after the chip is powered on. To
1269 * simplify the code and since the performance impact is
1270 * negligible, we use the same block size for all different
1271 * chip types.
1272 */
1273 if (!wl1271_set_block_size(wl))
1274 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001275
1276 switch (wl->chip.id) {
1277 case CHIP_ID_1271_PG10:
1278 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1279 wl->chip.id);
1280
1281 ret = wl1271_setup(wl);
1282 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001283 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001284 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001285 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001286
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001287 case CHIP_ID_1271_PG20:
1288 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1289 wl->chip.id);
1290
1291 ret = wl1271_setup(wl);
1292 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001293 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001294 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001295 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001296
Shahar Levi0830cee2011-03-06 16:32:20 +02001297 case CHIP_ID_1283_PG20:
1298 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1299 wl->chip.id);
1300
1301 ret = wl1271_setup(wl);
1302 if (ret < 0)
1303 goto out;
1304 break;
1305 case CHIP_ID_1283_PG10:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001306 default:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001307 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001308 ret = -ENODEV;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001309 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001310 }
1311
Arik Nemtsovc302b2c2011-08-17 10:45:48 +03001312 if (wl->fw == NULL) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001313 ret = wl1271_fetch_firmware(wl);
1314 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001315 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001316 }
1317
1318 /* No NVS from netlink, try to get it from the filesystem */
1319 if (wl->nvs == NULL) {
1320 ret = wl1271_fetch_nvs(wl);
1321 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001322 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001323 }
1324
1325out:
1326 return ret;
1327}
1328
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001329int wl1271_plt_start(struct wl1271 *wl)
1330{
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001331 int retries = WL1271_BOOT_RETRIES;
Gery Kahn6f07b722011-07-18 14:21:49 +03001332 struct wiphy *wiphy = wl->hw->wiphy;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001333 int ret;
1334
1335 mutex_lock(&wl->mutex);
1336
1337 wl1271_notice("power up");
1338
1339 if (wl->state != WL1271_STATE_OFF) {
1340 wl1271_error("cannot go into PLT state because not "
1341 "in off state: %d", wl->state);
1342 ret = -EBUSY;
1343 goto out;
1344 }
1345
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001346 while (retries) {
1347 retries--;
1348 ret = wl1271_chip_wakeup(wl);
1349 if (ret < 0)
1350 goto power_off;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001351
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001352 ret = wl1271_boot(wl);
1353 if (ret < 0)
1354 goto power_off;
1355
1356 ret = wl1271_plt_init(wl);
1357 if (ret < 0)
1358 goto irq_disable;
1359
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001360 wl->state = WL1271_STATE_PLT;
1361 wl1271_notice("firmware booted in PLT mode (%s)",
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001362 wl->chip.fw_ver_str);
Luciano Coelhoe7ddf542011-03-10 15:24:57 +02001363
Gery Kahn6f07b722011-07-18 14:21:49 +03001364 /* update hw/fw version info in wiphy struct */
1365 wiphy->hw_version = wl->chip.id;
1366 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1367 sizeof(wiphy->fw_version));
1368
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001369 goto out;
1370
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001371irq_disable:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001372 mutex_unlock(&wl->mutex);
1373 /* Unlocking the mutex in the middle of handling is
1374 inherently unsafe. In this case we deem it safe to do,
1375 because we need to let any possibly pending IRQ out of
1376 the system (and while we are WL1271_STATE_OFF the IRQ
1377 work function will not do anything.) Also, any other
1378 possible concurrent operations will fail due to the
1379 current state, hence the wl1271 struct should be safe. */
Ido Yariva6208652011-03-01 15:14:41 +02001380 wl1271_disable_interrupts(wl);
1381 wl1271_flush_deferred_work(wl);
1382 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001383 mutex_lock(&wl->mutex);
1384power_off:
1385 wl1271_power_off(wl);
1386 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001387
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001388 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1389 WL1271_BOOT_RETRIES);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001390out:
1391 mutex_unlock(&wl->mutex);
1392
1393 return ret;
1394}
1395
Ido Yarivf3df1332012-01-11 09:42:39 +02001396int wl1271_plt_stop(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001397{
1398 int ret = 0;
1399
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001400 wl1271_notice("power down");
1401
Ido Yariv46b0cc92012-01-11 09:42:41 +02001402 /*
1403 * Interrupts must be disabled before setting the state to OFF.
1404 * Otherwise, the interrupt handler might be called and exit without
1405 * reading the interrupt status.
1406 */
1407 wl1271_disable_interrupts(wl);
Ido Yarivf3df1332012-01-11 09:42:39 +02001408 mutex_lock(&wl->mutex);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001409 if (wl->state != WL1271_STATE_PLT) {
Ido Yarivf3df1332012-01-11 09:42:39 +02001410 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001411
1412 /*
1413 * This will not necessarily enable interrupts as interrupts
1414 * may have been disabled when op_stop was called. It will,
1415 * however, balance the above call to disable_interrupts().
1416 */
1417 wl1271_enable_interrupts(wl);
1418
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001419 wl1271_error("cannot power down because not in PLT "
1420 "state: %d", wl->state);
1421 ret = -EBUSY;
1422 goto out;
1423 }
1424
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001425 mutex_unlock(&wl->mutex);
Ido Yarivf3df1332012-01-11 09:42:39 +02001426
Ido Yariva6208652011-03-01 15:14:41 +02001427 wl1271_flush_deferred_work(wl);
1428 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001429 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001430 cancel_delayed_work_sync(&wl->elp_work);
Ido Yariva4549692012-01-11 09:42:40 +02001431
1432 mutex_lock(&wl->mutex);
1433 wl1271_power_off(wl);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001434 wl->flags = 0;
1435 wl->state = WL1271_STATE_OFF;
1436 wl->rx_counter = 0;
Ido Yariva4549692012-01-11 09:42:40 +02001437 mutex_unlock(&wl->mutex);
1438
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01001439out:
1440 return ret;
1441}
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +02001442
Johannes Berg7bb45682011-02-24 14:42:06 +01001443static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001444{
1445 struct wl1271 *wl = hw->priv;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001446 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1447 struct ieee80211_vif *vif = info->control.vif;
Eliad Peller0f168012011-10-11 13:52:25 +02001448 struct wl12xx_vif *wlvif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001449 unsigned long flags;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001450 int q, mapping;
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001451 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001452
Eliad Peller0f168012011-10-11 13:52:25 +02001453 if (vif)
1454 wlvif = wl12xx_vif_to_data(vif);
1455
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001456 mapping = skb_get_queue_mapping(skb);
1457 q = wl1271_tx_get_queue(mapping);
Ido Yarivb07d4032011-03-01 15:14:43 +02001458
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001459 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
Ido Yarivb07d4032011-03-01 15:14:43 +02001460
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001461 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yarivb07d4032011-03-01 15:14:43 +02001462
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001463 /* queue the packet */
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001464 if (hlid == WL12XX_INVALID_LINK_ID ||
Eliad Peller0f168012011-10-11 13:52:25 +02001465 (wlvif && !test_bit(hlid, wlvif->links_map))) {
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001466 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
Eliad Peller5de8eef2011-12-13 15:26:38 +02001467 ieee80211_free_txskb(hw, skb);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001468 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02001469 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001470
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001471 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1472 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1473
Arik Nemtsov04b4d692011-08-14 13:17:39 +03001474 wl->tx_queue_count[q]++;
1475
1476 /*
1477 * The workqueue is slow to process the tx_queue and we need stop
1478 * the queue here, otherwise the queue will get too long.
1479 */
1480 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1481 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1482 ieee80211_stop_queue(wl->hw, mapping);
1483 set_bit(q, &wl->stopped_queues_map);
1484 }
1485
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001486 /*
1487 * The chip specific setup must run before the first TX packet -
1488 * before that, the tx_work will not be initialized!
1489 */
1490
Ido Yarivb07d4032011-03-01 15:14:43 +02001491 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1492 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
Ido Yariva5225502010-10-12 14:49:10 +02001493 ieee80211_queue_work(wl->hw, &wl->tx_work);
Ido Yarivb07d4032011-03-01 15:14:43 +02001494
Arik Nemtsov04216da2011-08-14 13:17:38 +03001495out:
Ido Yarivb07d4032011-03-01 15:14:43 +02001496 spin_unlock_irqrestore(&wl->wl_lock, flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001497}
1498
Shahar Leviae47c452011-03-06 16:32:14 +02001499int wl1271_tx_dummy_packet(struct wl1271 *wl)
1500{
Ido Yariv990f5de2011-03-31 10:06:59 +02001501 unsigned long flags;
Arik Nemtsov14623782011-08-28 15:11:57 +03001502 int q;
1503
1504 /* no need to queue a new dummy packet if one is already pending */
1505 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1506 return 0;
1507
1508 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
Shahar Leviae47c452011-03-06 16:32:14 +02001509
Ido Yariv990f5de2011-03-31 10:06:59 +02001510 spin_lock_irqsave(&wl->wl_lock, flags);
1511 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +03001512 wl->tx_queue_count[q]++;
Ido Yariv990f5de2011-03-31 10:06:59 +02001513 spin_unlock_irqrestore(&wl->wl_lock, flags);
1514
1515 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1516 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
Eliad Pellera32d0cd2011-10-10 10:12:55 +02001517 wl1271_tx_work_locked(wl);
Ido Yariv990f5de2011-03-31 10:06:59 +02001518
1519 /*
1520 * If the FW TX is busy, TX work will be scheduled by the threaded
1521 * interrupt handler function
1522 */
1523 return 0;
1524}
1525
1526/*
1527 * The size of the dummy packet should be at least 1400 bytes. However, in
1528 * order to minimize the number of bus transactions, aligning it to 512 bytes
1529 * boundaries could be beneficial, performance wise
1530 */
1531#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1532
Luciano Coelhocf27d862011-04-01 21:08:23 +03001533static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
Ido Yariv990f5de2011-03-31 10:06:59 +02001534{
1535 struct sk_buff *skb;
1536 struct ieee80211_hdr_3addr *hdr;
1537 unsigned int dummy_packet_size;
1538
1539 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1540 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1541
1542 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
Shahar Leviae47c452011-03-06 16:32:14 +02001543 if (!skb) {
Ido Yariv990f5de2011-03-31 10:06:59 +02001544 wl1271_warning("Failed to allocate a dummy packet skb");
1545 return NULL;
Shahar Leviae47c452011-03-06 16:32:14 +02001546 }
1547
1548 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1549
1550 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1551 memset(hdr, 0, sizeof(*hdr));
1552 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
Ido Yariv990f5de2011-03-31 10:06:59 +02001553 IEEE80211_STYPE_NULLFUNC |
1554 IEEE80211_FCTL_TODS);
Shahar Leviae47c452011-03-06 16:32:14 +02001555
Ido Yariv990f5de2011-03-31 10:06:59 +02001556 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
Shahar Leviae47c452011-03-06 16:32:14 +02001557
Luciano Coelho18b92ff2011-03-21 16:35:21 +02001558 /* Dummy packets require the TID to be management */
1559 skb->priority = WL1271_TID_MGMT;
Ido Yariv990f5de2011-03-31 10:06:59 +02001560
1561 /* Initialize all fields that might be used */
Hauke Mehrtens86c438f2011-04-26 23:27:44 +02001562 skb_set_queue_mapping(skb, 0);
Ido Yariv990f5de2011-03-31 10:06:59 +02001563 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
Shahar Leviae47c452011-03-06 16:32:14 +02001564
Ido Yariv990f5de2011-03-31 10:06:59 +02001565 return skb;
Shahar Leviae47c452011-03-06 16:32:14 +02001566}
1567
Ido Yariv990f5de2011-03-31 10:06:59 +02001568
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03001569static struct notifier_block wl1271_dev_notifier = {
1570 .notifier_call = wl1271_dev_notify,
1571};
1572
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001573#ifdef CONFIG_PM
Eliad Peller94390642011-05-13 11:57:13 +03001574
Eliad Peller0603d892011-10-05 11:55:51 +02001575static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1576 struct wl12xx_vif *wlvif)
Eliad Peller94390642011-05-13 11:57:13 +03001577{
Eliad Pellere85d1622011-06-27 13:06:43 +03001578 int ret = 0;
Eliad Peller94390642011-05-13 11:57:13 +03001579
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001580 mutex_lock(&wl->mutex);
1581
Eliad Peller53d40d02011-10-10 10:13:02 +02001582 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Pellere85d1622011-06-27 13:06:43 +03001583 goto out_unlock;
1584
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001585 ret = wl1271_ps_elp_wakeup(wl);
1586 if (ret < 0)
1587 goto out_unlock;
1588
Eliad Peller0603d892011-10-05 11:55:51 +02001589 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001590
1591 wl1271_ps_elp_sleep(wl);
1592out_unlock:
1593 mutex_unlock(&wl->mutex);
1594 return ret;
1595
1596}
1597
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001598static int wl1271_configure_suspend(struct wl1271 *wl,
1599 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001600{
Eliad Peller536129c2011-10-05 11:55:45 +02001601 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
Eliad Peller0603d892011-10-05 11:55:51 +02001602 return wl1271_configure_suspend_ap(wl, wlvif);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001603 return 0;
1604}
1605
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001606static void wl1271_configure_resume(struct wl1271 *wl,
1607 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001608{
1609 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02001610 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001611
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02001612 if (!is_ap)
Eliad Peller94390642011-05-13 11:57:13 +03001613 return;
1614
1615 mutex_lock(&wl->mutex);
1616 ret = wl1271_ps_elp_wakeup(wl);
1617 if (ret < 0)
1618 goto out;
1619
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02001620 wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Eliad Peller94390642011-05-13 11:57:13 +03001621
1622 wl1271_ps_elp_sleep(wl);
1623out:
1624 mutex_unlock(&wl->mutex);
1625}
1626
Eliad Peller402e48612011-05-13 11:57:09 +03001627static int wl1271_op_suspend(struct ieee80211_hw *hw,
1628 struct cfg80211_wowlan *wow)
1629{
1630 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001631 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001632 int ret;
1633
Eliad Peller402e48612011-05-13 11:57:09 +03001634 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
Eliad Peller4a859df2011-06-06 12:21:52 +03001635 WARN_ON(!wow || !wow->any);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001636
Eliad Peller4a859df2011-06-06 12:21:52 +03001637 wl->wow_enabled = true;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001638 wl12xx_for_each_wlvif(wl, wlvif) {
1639 ret = wl1271_configure_suspend(wl, wlvif);
1640 if (ret < 0) {
1641 wl1271_warning("couldn't prepare device to suspend");
1642 return ret;
1643 }
Eliad Pellerf44e5862011-05-13 11:57:11 +03001644 }
Eliad Peller4a859df2011-06-06 12:21:52 +03001645 /* flush any remaining work */
1646 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
Eliad Peller4a859df2011-06-06 12:21:52 +03001647
1648 /*
1649 * disable and re-enable interrupts in order to flush
1650 * the threaded_irq
1651 */
1652 wl1271_disable_interrupts(wl);
1653
1654 /*
1655 * set suspended flag to avoid triggering a new threaded_irq
1656 * work. no need for spinlock as interrupts are disabled.
1657 */
1658 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1659
1660 wl1271_enable_interrupts(wl);
1661 flush_work(&wl->tx_work);
Eliad Peller4a859df2011-06-06 12:21:52 +03001662 flush_delayed_work(&wl->elp_work);
1663
Eliad Peller402e48612011-05-13 11:57:09 +03001664 return 0;
1665}
1666
1667static int wl1271_op_resume(struct ieee80211_hw *hw)
1668{
1669 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001670 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001671 unsigned long flags;
1672 bool run_irq_work = false;
1673
Eliad Peller402e48612011-05-13 11:57:09 +03001674 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1675 wl->wow_enabled);
Eliad Peller4a859df2011-06-06 12:21:52 +03001676 WARN_ON(!wl->wow_enabled);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001677
1678 /*
1679 * re-enable irq_work enqueuing, and call irq_work directly if
1680 * there is a pending work.
1681 */
Eliad Peller4a859df2011-06-06 12:21:52 +03001682 spin_lock_irqsave(&wl->wl_lock, flags);
1683 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1684 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1685 run_irq_work = true;
1686 spin_unlock_irqrestore(&wl->wl_lock, flags);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001687
Eliad Peller4a859df2011-06-06 12:21:52 +03001688 if (run_irq_work) {
1689 wl1271_debug(DEBUG_MAC80211,
1690 "run postponed irq_work directly");
1691 wl1271_irq(0, wl);
1692 wl1271_enable_interrupts(wl);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001693 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02001694 wl12xx_for_each_wlvif(wl, wlvif) {
1695 wl1271_configure_resume(wl, wlvif);
1696 }
Eliad Pellerff91afc2011-06-06 12:21:53 +03001697 wl->wow_enabled = false;
Eliad Pellerf44e5862011-05-13 11:57:11 +03001698
Eliad Peller402e48612011-05-13 11:57:09 +03001699 return 0;
1700}
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001701#endif
Eliad Peller402e48612011-05-13 11:57:09 +03001702
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001703static int wl1271_op_start(struct ieee80211_hw *hw)
1704{
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001705 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1706
1707 /*
1708 * We have to delay the booting of the hardware because
1709 * we need to know the local MAC address before downloading and
1710 * initializing the firmware. The MAC address cannot be changed
1711 * after boot, and without the proper MAC address, the firmware
1712 * will not function properly.
1713 *
1714 * The MAC address is first known when the corresponding interface
1715 * is added. That is where we will initialize the hardware.
1716 */
1717
Eliad Pellercdaac622012-01-31 11:57:16 +02001718 wl1271_error("wl12xx is in an ustable state (fw api update is "
1719 "taking place). skip this commit when bisecting");
1720 return -EBUSY;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001721}
1722
1723static void wl1271_op_stop(struct ieee80211_hw *hw)
1724{
Eliad Pellerbaf62772011-10-10 10:12:52 +02001725 struct wl1271 *wl = hw->priv;
1726 int i;
1727
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001728 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
Eliad Pellerbaf62772011-10-10 10:12:52 +02001729
Ido Yariv46b0cc92012-01-11 09:42:41 +02001730 /*
1731 * Interrupts must be disabled before setting the state to OFF.
1732 * Otherwise, the interrupt handler might be called and exit without
1733 * reading the interrupt status.
1734 */
1735 wl1271_disable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001736 mutex_lock(&wl->mutex);
1737 if (wl->state == WL1271_STATE_OFF) {
1738 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001739
1740 /*
1741 * This will not necessarily enable interrupts as interrupts
1742 * may have been disabled when op_stop was called. It will,
1743 * however, balance the above call to disable_interrupts().
1744 */
1745 wl1271_enable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001746 return;
1747 }
Ido Yariv46b0cc92012-01-11 09:42:41 +02001748
Eliad Pellerbaf62772011-10-10 10:12:52 +02001749 /*
1750 * this must be before the cancel_work calls below, so that the work
1751 * functions don't perform further work.
1752 */
1753 wl->state = WL1271_STATE_OFF;
Eliad Peller10c8cd02011-10-10 10:13:06 +02001754 mutex_unlock(&wl->mutex);
1755
1756 mutex_lock(&wl_list_mutex);
1757 list_del(&wl->list);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001758 mutex_unlock(&wl_list_mutex);
1759
Eliad Pellerbaf62772011-10-10 10:12:52 +02001760 wl1271_flush_deferred_work(wl);
1761 cancel_delayed_work_sync(&wl->scan_complete_work);
1762 cancel_work_sync(&wl->netstack_work);
1763 cancel_work_sync(&wl->tx_work);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001764 cancel_delayed_work_sync(&wl->elp_work);
1765
1766 /* let's notify MAC80211 about the remaining pending TX frames */
1767 wl12xx_tx_reset(wl, true);
1768 mutex_lock(&wl->mutex);
1769
1770 wl1271_power_off(wl);
1771
1772 wl->band = IEEE80211_BAND_2GHZ;
1773
1774 wl->rx_counter = 0;
1775 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1776 wl->tx_blocks_available = 0;
1777 wl->tx_allocated_blocks = 0;
1778 wl->tx_results_count = 0;
1779 wl->tx_packets_count = 0;
1780 wl->time_offset = 0;
Eliad Pellerbaf62772011-10-10 10:12:52 +02001781 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1782 wl->ap_fw_ps_map = 0;
1783 wl->ap_ps_map = 0;
1784 wl->sched_scanning = false;
1785 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1786 memset(wl->links_map, 0, sizeof(wl->links_map));
1787 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1788 wl->active_sta_count = 0;
1789
1790 /* The system link is always allocated */
1791 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1792
1793 /*
1794 * this is performed after the cancel_work calls and the associated
1795 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1796 * get executed before all these vars have been reset.
1797 */
1798 wl->flags = 0;
1799
1800 wl->tx_blocks_freed = 0;
1801
1802 for (i = 0; i < NUM_TX_QUEUES; i++) {
1803 wl->tx_pkts_freed[i] = 0;
1804 wl->tx_allocated_pkts[i] = 0;
1805 }
1806
1807 wl1271_debugfs_reset(wl);
1808
1809 kfree(wl->fw_status);
1810 wl->fw_status = NULL;
1811 kfree(wl->tx_res_if);
1812 wl->tx_res_if = NULL;
1813 kfree(wl->target_mem_map);
1814 wl->target_mem_map = NULL;
1815
1816 mutex_unlock(&wl->mutex);
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001817}
1818
Eliad Pellere5a359f2011-10-10 10:13:15 +02001819static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1820{
1821 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1822 WL12XX_MAX_RATE_POLICIES);
1823 if (policy >= WL12XX_MAX_RATE_POLICIES)
1824 return -EBUSY;
1825
1826 __set_bit(policy, wl->rate_policies_map);
1827 *idx = policy;
1828 return 0;
1829}
1830
1831static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1832{
1833 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1834 return;
1835
1836 __clear_bit(*idx, wl->rate_policies_map);
1837 *idx = WL12XX_MAX_RATE_POLICIES;
1838}
1839
Eliad Peller536129c2011-10-05 11:55:45 +02001840static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001841{
Eliad Peller536129c2011-10-05 11:55:45 +02001842 switch (wlvif->bss_type) {
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001843 case BSS_TYPE_AP_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001844 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001845 return WL1271_ROLE_P2P_GO;
1846 else
1847 return WL1271_ROLE_AP;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001848
1849 case BSS_TYPE_STA_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001850 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001851 return WL1271_ROLE_P2P_CL;
1852 else
1853 return WL1271_ROLE_STA;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001854
Eliad Peller227e81e2011-08-14 13:17:26 +03001855 case BSS_TYPE_IBSS:
1856 return WL1271_ROLE_IBSS;
1857
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001858 default:
Eliad Peller536129c2011-10-05 11:55:45 +02001859 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001860 }
1861 return WL12XX_INVALID_ROLE_TYPE;
1862}
1863
Eliad Peller83587502011-10-10 10:12:53 +02001864static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Eliad Peller87fbcb02011-10-05 11:55:41 +02001865{
Eliad Pellere936bbe2011-10-05 11:55:56 +02001866 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02001867 int i;
Eliad Pellere936bbe2011-10-05 11:55:56 +02001868
Eliad Peller48e93e42011-10-10 10:12:58 +02001869 /* clear everything but the persistent data */
1870 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
Eliad Pellere936bbe2011-10-05 11:55:56 +02001871
1872 switch (ieee80211_vif_type_p2p(vif)) {
1873 case NL80211_IFTYPE_P2P_CLIENT:
1874 wlvif->p2p = 1;
1875 /* fall-through */
1876 case NL80211_IFTYPE_STATION:
1877 wlvif->bss_type = BSS_TYPE_STA_BSS;
1878 break;
1879 case NL80211_IFTYPE_ADHOC:
1880 wlvif->bss_type = BSS_TYPE_IBSS;
1881 break;
1882 case NL80211_IFTYPE_P2P_GO:
1883 wlvif->p2p = 1;
1884 /* fall-through */
1885 case NL80211_IFTYPE_AP:
1886 wlvif->bss_type = BSS_TYPE_AP_BSS;
1887 break;
1888 default:
1889 wlvif->bss_type = MAX_BSS_TYPE;
1890 return -EOPNOTSUPP;
1891 }
1892
Eliad Peller0603d892011-10-05 11:55:51 +02001893 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02001894 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02001895 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001896
Eliad Pellere936bbe2011-10-05 11:55:56 +02001897 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1898 wlvif->bss_type == BSS_TYPE_IBSS) {
1899 /* init sta/ibss data */
1900 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001901 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1902 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1903 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001904 } else {
1905 /* init ap data */
1906 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1907 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001908 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1909 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1910 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1911 wl12xx_allocate_rate_policy(wl,
1912 &wlvif->ap.ucast_rate_idx[i]);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001913 }
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001914
Eliad Peller83587502011-10-10 10:12:53 +02001915 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1916 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001917 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001918 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
Eliad Peller30d0c8f2011-10-05 11:55:42 +02001919 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Peller6a899792011-10-05 11:55:58 +02001920 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1921
Eliad Peller1b92f152011-10-10 10:13:09 +02001922 /*
1923 * mac80211 configures some values globally, while we treat them
1924 * per-interface. thus, on init, we have to copy them from wl
1925 */
1926 wlvif->band = wl->band;
Eliad Peller61f845f2011-10-10 10:13:10 +02001927 wlvif->channel = wl->channel;
Eliad Peller6bd65022011-10-10 10:13:11 +02001928 wlvif->power_level = wl->power_level;
Eliad Peller1b92f152011-10-10 10:13:09 +02001929
Eliad Peller9eb599e2011-10-10 10:12:59 +02001930 INIT_WORK(&wlvif->rx_streaming_enable_work,
1931 wl1271_rx_streaming_enable_work);
1932 INIT_WORK(&wlvif->rx_streaming_disable_work,
1933 wl1271_rx_streaming_disable_work);
Eliad Peller87627212011-10-10 10:12:54 +02001934 INIT_LIST_HEAD(&wlvif->list);
Eliad Peller252efa42011-10-05 11:56:00 +02001935
Eliad Peller9eb599e2011-10-10 10:12:59 +02001936 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1937 (unsigned long) wlvif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001938 return 0;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001939}
1940
Eliad Peller1d095472011-10-10 10:12:49 +02001941static bool wl12xx_init_fw(struct wl1271 *wl)
1942{
1943 int retries = WL1271_BOOT_RETRIES;
1944 bool booted = false;
1945 struct wiphy *wiphy = wl->hw->wiphy;
1946 int ret;
1947
1948 while (retries) {
1949 retries--;
1950 ret = wl1271_chip_wakeup(wl);
1951 if (ret < 0)
1952 goto power_off;
1953
1954 ret = wl1271_boot(wl);
1955 if (ret < 0)
1956 goto power_off;
1957
1958 ret = wl1271_hw_init(wl);
1959 if (ret < 0)
1960 goto irq_disable;
1961
1962 booted = true;
1963 break;
1964
1965irq_disable:
1966 mutex_unlock(&wl->mutex);
1967 /* Unlocking the mutex in the middle of handling is
1968 inherently unsafe. In this case we deem it safe to do,
1969 because we need to let any possibly pending IRQ out of
1970 the system (and while we are WL1271_STATE_OFF the IRQ
1971 work function will not do anything.) Also, any other
1972 possible concurrent operations will fail due to the
1973 current state, hence the wl1271 struct should be safe. */
1974 wl1271_disable_interrupts(wl);
1975 wl1271_flush_deferred_work(wl);
1976 cancel_work_sync(&wl->netstack_work);
1977 mutex_lock(&wl->mutex);
1978power_off:
1979 wl1271_power_off(wl);
1980 }
1981
1982 if (!booted) {
1983 wl1271_error("firmware boot failed despite %d retries",
1984 WL1271_BOOT_RETRIES);
1985 goto out;
1986 }
1987
1988 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1989
1990 /* update hw/fw version info in wiphy struct */
1991 wiphy->hw_version = wl->chip.id;
1992 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1993 sizeof(wiphy->fw_version));
1994
1995 /*
1996 * Now we know if 11a is supported (info from the NVS), so disable
1997 * 11a channels if not supported
1998 */
1999 if (!wl->enable_11a)
2000 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2001
2002 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2003 wl->enable_11a ? "" : "not ");
2004
2005 wl->state = WL1271_STATE_ON;
2006out:
2007 return booted;
2008}
2009
Eliad Peller92e712d2011-12-18 20:25:43 +02002010static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2011{
2012 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2013}
2014
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002015static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2016 struct ieee80211_vif *vif)
2017{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002018 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002019 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002020 int ret = 0;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002021 u8 role_type;
Eliad Peller71125ab2010-10-28 21:46:43 +02002022 bool booted = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002023
Johannes Bergea086352012-01-19 09:29:58 +01002024 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2025 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Johannes Bergc1288b12012-01-19 09:29:57 +01002026
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002027 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
Eliad Peller045c7452011-08-28 15:23:01 +03002028 ieee80211_vif_type_p2p(vif), vif->addr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002029
2030 mutex_lock(&wl->mutex);
Eliad Pellerf750c822011-10-10 10:13:16 +02002031 ret = wl1271_ps_elp_wakeup(wl);
2032 if (ret < 0)
2033 goto out_unlock;
2034
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002035 if (wl->vif) {
Eliad Peller71125ab2010-10-28 21:46:43 +02002036 wl1271_debug(DEBUG_MAC80211,
2037 "multiple vifs are not supported yet");
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002038 ret = -EBUSY;
2039 goto out;
2040 }
2041
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002042 /*
2043 * in some very corner case HW recovery scenarios its possible to
2044 * get here before __wl1271_op_remove_interface is complete, so
2045 * opt out if that is the case.
2046 */
Eliad Peller10c8cd02011-10-10 10:13:06 +02002047 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2048 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002049 ret = -EBUSY;
2050 goto out;
2051 }
2052
Eliad Peller83587502011-10-10 10:12:53 +02002053 ret = wl12xx_init_vif_data(wl, vif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002054 if (ret < 0)
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002055 goto out;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002056
Eliad Peller252efa42011-10-05 11:56:00 +02002057 wlvif->wl = wl;
Eliad Peller536129c2011-10-05 11:55:45 +02002058 role_type = wl12xx_get_role_type(wl, wlvif);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002059 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2060 ret = -EINVAL;
2061 goto out;
2062 }
Eliad Peller1d095472011-10-10 10:12:49 +02002063
Eliad Peller784f6942011-10-05 11:55:39 +02002064 /*
Eliad Peller1d095472011-10-10 10:12:49 +02002065 * TODO: after the nvs issue will be solved, move this block
2066 * to start(), and make sure here the driver is ON.
Eliad Peller784f6942011-10-05 11:55:39 +02002067 */
Eliad Peller1d095472011-10-10 10:12:49 +02002068 if (wl->state == WL1271_STATE_OFF) {
2069 /*
2070 * we still need this in order to configure the fw
2071 * while uploading the nvs
2072 */
Luciano Coelho5e037e72011-12-23 09:32:17 +02002073 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002074
Eliad Peller1d095472011-10-10 10:12:49 +02002075 booted = wl12xx_init_fw(wl);
2076 if (!booted) {
2077 ret = -EINVAL;
2078 goto out;
Eliad Peller04e80792011-08-14 13:17:09 +03002079 }
Eliad Peller1d095472011-10-10 10:12:49 +02002080 }
Eliad Peller04e80792011-08-14 13:17:09 +03002081
Eliad Peller1d095472011-10-10 10:12:49 +02002082 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2083 wlvif->bss_type == BSS_TYPE_IBSS) {
2084 /*
2085 * The device role is a special role used for
2086 * rx and tx frames prior to association (as
2087 * the STA role can get packets only from
2088 * its associated bssid)
2089 */
Eliad Peller784f6942011-10-05 11:55:39 +02002090 ret = wl12xx_cmd_role_enable(wl, vif->addr,
Eliad Peller1d095472011-10-10 10:12:49 +02002091 WL1271_ROLE_DEVICE,
2092 &wlvif->dev_role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002093 if (ret < 0)
Eliad Peller1d095472011-10-10 10:12:49 +02002094 goto out;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02002095 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002096
Eliad Peller1d095472011-10-10 10:12:49 +02002097 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2098 role_type, &wlvif->role_id);
2099 if (ret < 0)
Eliad Peller71125ab2010-10-28 21:46:43 +02002100 goto out;
Eliad Peller1d095472011-10-10 10:12:49 +02002101
2102 ret = wl1271_init_vif_specific(wl, vif);
2103 if (ret < 0)
2104 goto out;
Eliad Peller71125ab2010-10-28 21:46:43 +02002105
2106 wl->vif = vif;
Eliad Peller87627212011-10-10 10:12:54 +02002107 list_add(&wlvif->list, &wl->wlvif_list);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002108 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
Eliad Pellera4e41302011-10-11 11:49:15 +02002109
2110 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2111 wl->ap_count++;
2112 else
2113 wl->sta_count++;
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +03002114out:
Eliad Pellerf750c822011-10-10 10:13:16 +02002115 wl1271_ps_elp_sleep(wl);
2116out_unlock:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002117 mutex_unlock(&wl->mutex);
2118
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002119 mutex_lock(&wl_list_mutex);
Juuso Oikarineneb887df2010-07-08 17:49:58 +03002120 if (!ret)
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002121 list_add(&wl->list, &wl_list);
Juuso Oikarinenf9f774c2011-03-21 10:43:36 +02002122 mutex_unlock(&wl_list_mutex);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03002123
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002124 return ret;
2125}
2126
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002127static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +02002128 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002129 bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002130{
Eliad Peller536129c2011-10-05 11:55:45 +02002131 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02002132 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002133
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002134 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002135
Eliad Peller10c8cd02011-10-10 10:13:06 +02002136 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2137 return;
2138
Eliad Peller2f8e81a2011-11-01 15:12:50 +02002139 wl->vif = NULL;
2140
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002141 /* because of hardware recovery, we may get here twice */
2142 if (wl->state != WL1271_STATE_ON)
2143 return;
2144
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002145 wl1271_info("down");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002146
Eliad Pellerbaf62772011-10-10 10:12:52 +02002147 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2148 wl->scan_vif == vif) {
Luciano Coelho08688d62010-07-08 17:50:07 +03002149 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +02002150 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02002151 wl->scan_vif = NULL;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002152 wl->scan.req = NULL;
Juuso Oikarinen76a029f2010-07-29 04:54:45 +03002153 ieee80211_scan_completed(wl->hw, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002154 }
2155
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002156 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2157 /* disable active roles */
2158 ret = wl1271_ps_elp_wakeup(wl);
2159 if (ret < 0)
2160 goto deinit;
2161
Eliad Pellerb890f4c2011-12-18 20:25:44 +02002162 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2163 wlvif->bss_type == BSS_TYPE_IBSS) {
2164 if (wl12xx_dev_role_started(wlvif))
2165 wl12xx_stop_dev(wl, wlvif);
2166
Eliad Peller7edebf52011-10-05 11:55:52 +02002167 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +03002168 if (ret < 0)
2169 goto deinit;
2170 }
2171
Eliad Peller0603d892011-10-05 11:55:51 +02002172 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002173 if (ret < 0)
2174 goto deinit;
2175
2176 wl1271_ps_elp_sleep(wl);
2177 }
2178deinit:
Arik Nemtsove51ae9b2011-08-14 13:17:21 +03002179 /* clear all hlids (except system_hlid) */
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02002180 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002181
2182 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2183 wlvif->bss_type == BSS_TYPE_IBSS) {
2184 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2185 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2186 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2187 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2188 } else {
2189 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2190 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2191 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2192 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2193 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2194 wl12xx_free_rate_policy(wl,
2195 &wlvif->ap.ucast_rate_idx[i]);
2196 }
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002197
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02002198 wl12xx_tx_reset_wlvif(wl, wlvif);
Eliad Peller170d0e62011-10-05 11:56:06 +02002199 wl1271_free_ap_keys(wl, wlvif);
Eliad Pellere4120df2011-10-10 10:13:17 +02002200 if (wl->last_wlvif == wlvif)
2201 wl->last_wlvif = NULL;
Eliad Peller87627212011-10-10 10:12:54 +02002202 list_del(&wlvif->list);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02002203 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
Eliad Peller0603d892011-10-05 11:55:51 +02002204 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02002205 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Luciano Coelhod6e19d12009-10-12 15:08:43 +03002206
Eliad Pellera4e41302011-10-11 11:49:15 +02002207 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2208 wl->ap_count--;
2209 else
2210 wl->sta_count--;
2211
Eliad Pellerbaf62772011-10-10 10:12:52 +02002212 mutex_unlock(&wl->mutex);
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02002213
Eliad Peller9eb599e2011-10-10 10:12:59 +02002214 del_timer_sync(&wlvif->rx_streaming_timer);
2215 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2216 cancel_work_sync(&wlvif->rx_streaming_disable_work);
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03002217
Eliad Pellerbaf62772011-10-10 10:12:52 +02002218 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002219}
Juuso Oikarinenbd9dc492010-04-09 11:07:26 +03002220
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002221static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2222 struct ieee80211_vif *vif)
2223{
2224 struct wl1271 *wl = hw->priv;
Eliad Peller10c8cd02011-10-10 10:13:06 +02002225 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002226 struct wl12xx_vif *iter;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002227
2228 mutex_lock(&wl->mutex);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002229
2230 if (wl->state == WL1271_STATE_OFF ||
2231 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2232 goto out;
2233
Juuso Oikarinen67353292010-11-18 15:19:02 +02002234 /*
2235 * wl->vif can be null here if someone shuts down the interface
2236 * just when hardware recovery has been started.
2237 */
Eliad Peller6e8cd332011-10-10 10:13:13 +02002238 wl12xx_for_each_wlvif(wl, iter) {
2239 if (iter != wlvif)
2240 continue;
2241
Eliad Peller536129c2011-10-05 11:55:45 +02002242 __wl1271_op_remove_interface(wl, vif, true);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002243 break;
Juuso Oikarinen67353292010-11-18 15:19:02 +02002244 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02002245 WARN_ON(iter != wlvif);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002246out:
Juuso Oikarinen67353292010-11-18 15:19:02 +02002247 mutex_unlock(&wl->mutex);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02002248 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002249}
2250
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002251static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2252 struct ieee80211_vif *vif,
2253 enum nl80211_iftype new_type, bool p2p)
2254{
2255 wl1271_op_remove_interface(hw, vif);
2256
2257 vif->type = ieee80211_iftype_p2p(new_type, p2p);
2258 vif->p2p = p2p;
2259 return wl1271_op_add_interface(hw, vif);
2260}
2261
Eliad Peller87fbcb02011-10-05 11:55:41 +02002262static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2263 bool set_assoc)
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002264{
2265 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002266 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002267
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002268 /*
2269 * One of the side effects of the JOIN command is that is clears
2270 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2271 * to a WPA/WPA2 access point will therefore kill the data-path.
Ohad Ben-Cohen8bf69aa2011-03-30 19:18:31 +02002272 * Currently the only valid scenario for JOIN during association
2273 * is on roaming, in which case we will also be given new keys.
2274 * Keep the below message for now, unless it starts bothering
2275 * users who really like to roam a lot :)
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002276 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002277 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002278 wl1271_info("JOIN while associated.");
2279
2280 if (set_assoc)
Eliad Pellerba8447f2011-10-10 10:13:00 +02002281 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002282
Eliad Peller227e81e2011-08-14 13:17:26 +03002283 if (is_ibss)
Eliad Peller87fbcb02011-10-05 11:55:41 +02002284 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03002285 else
Eliad Peller87fbcb02011-10-05 11:55:41 +02002286 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002287 if (ret < 0)
2288 goto out;
2289
Eliad Pellerba8447f2011-10-10 10:13:00 +02002290 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002291 goto out;
2292
2293 /*
2294 * The join command disable the keep-alive mode, shut down its process,
2295 * and also clear the template config, so we need to reset it all after
2296 * the join. The acx_aid starts the keep-alive process, and the order
2297 * of the commands below is relevant.
2298 */
Eliad Peller0603d892011-10-05 11:55:51 +02002299 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002300 if (ret < 0)
2301 goto out;
2302
Eliad Peller0603d892011-10-05 11:55:51 +02002303 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002304 if (ret < 0)
2305 goto out;
2306
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002307 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002308 if (ret < 0)
2309 goto out;
2310
Eliad Peller0603d892011-10-05 11:55:51 +02002311 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2312 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002313 ACX_KEEP_ALIVE_TPL_VALID);
2314 if (ret < 0)
2315 goto out;
2316
2317out:
2318 return ret;
2319}
2320
Eliad Peller0603d892011-10-05 11:55:51 +02002321static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002322{
2323 int ret;
2324
Eliad Peller52630c52011-10-10 10:13:08 +02002325 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02002326 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2327
Shahar Levi6d158ff2011-09-08 13:01:33 +03002328 wl12xx_cmd_stop_channel_switch(wl);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002329 ieee80211_chswitch_done(vif, false);
Shahar Levi6d158ff2011-09-08 13:01:33 +03002330 }
2331
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002332 /* to stop listening to a channel, we disconnect */
Eliad Peller0603d892011-10-05 11:55:51 +02002333 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002334 if (ret < 0)
2335 goto out;
2336
Oz Krakowskib992c682011-06-26 10:36:02 +03002337 /* reset TX security counters on a clean disconnect */
Eliad Peller48e93e42011-10-10 10:12:58 +02002338 wlvif->tx_security_last_seq_lsb = 0;
2339 wlvif->tx_security_seq = 0;
Oz Krakowskib992c682011-06-26 10:36:02 +03002340
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002341out:
2342 return ret;
2343}
2344
Eliad Peller87fbcb02011-10-05 11:55:41 +02002345static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002346{
Eliad Peller1b92f152011-10-10 10:13:09 +02002347 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002348 wlvif->rate_set = wlvif->basic_rate_set;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002349}
2350
Eliad Peller87fbcb02011-10-05 11:55:41 +02002351static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2352 bool idle)
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002353{
2354 int ret;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002355 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2356
2357 if (idle == cur_idle)
2358 return 0;
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002359
2360 if (idle) {
Eliad Peller251c1772011-08-14 13:17:17 +03002361 /* no need to croc if we weren't busy (e.g. during boot) */
Eliad Peller92e712d2011-12-18 20:25:43 +02002362 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002363 ret = wl12xx_stop_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002364 if (ret < 0)
2365 goto out;
2366 }
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002367 wlvif->rate_set =
2368 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2369 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002370 if (ret < 0)
2371 goto out;
2372 ret = wl1271_acx_keep_alive_config(
Eliad Peller0603d892011-10-05 11:55:51 +02002373 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002374 ACX_KEEP_ALIVE_TPL_INVALID);
2375 if (ret < 0)
2376 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002377 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002378 } else {
Luciano Coelho33c2c062011-05-10 14:46:02 +03002379 /* The current firmware only supports sched_scan in idle */
2380 if (wl->sched_scanning) {
2381 wl1271_scan_sched_scan_stop(wl);
2382 ieee80211_sched_scan_stopped(wl->hw);
2383 }
2384
Eliad Peller679a6732011-10-11 11:55:44 +02002385 ret = wl12xx_start_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002386 if (ret < 0)
2387 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002388 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002389 }
2390
2391out:
2392 return ret;
2393}
2394
Eliad Peller9f259c42011-10-10 10:13:12 +02002395static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2396 struct ieee80211_conf *conf, u32 changed)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002397{
Eliad Peller9f259c42011-10-10 10:13:12 +02002398 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2399 int channel, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002400
2401 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2402
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002403 /* if the channel changes while joined, join again */
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002404 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
Eliad Peller1b92f152011-10-10 10:13:09 +02002405 ((wlvif->band != conf->channel->band) ||
Eliad Peller61f845f2011-10-10 10:13:10 +02002406 (wlvif->channel != channel))) {
Eliad Pellerc6930b02011-09-15 13:00:01 +03002407 /* send all pending packets */
Eliad Pellera32d0cd2011-10-10 10:12:55 +02002408 wl1271_tx_work_locked(wl);
Eliad Peller61f845f2011-10-10 10:13:10 +02002409 wlvif->band = conf->channel->band;
2410 wlvif->channel = channel;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002411
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002412 if (!is_ap) {
2413 /*
2414 * FIXME: the mac80211 should really provide a fixed
2415 * rate to use here. for now, just use the smallest
2416 * possible rate for the band as a fixed rate for
2417 * association frames and other control messages.
2418 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002419 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Peller87fbcb02011-10-05 11:55:41 +02002420 wl1271_set_band_rate(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002421
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002422 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02002423 wl1271_tx_min_rate_get(wl,
2424 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002425 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002426 if (ret < 0)
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002427 wl1271_warning("rate policy for channel "
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002428 "failed %d", ret);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002429
Eliad Pellerba8447f2011-10-10 10:13:00 +02002430 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2431 &wlvif->flags)) {
Eliad Peller92e712d2011-12-18 20:25:43 +02002432 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller251c1772011-08-14 13:17:17 +03002433 /* roaming */
Eliad Peller7edebf52011-10-05 11:55:52 +02002434 ret = wl12xx_croc(wl,
2435 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03002436 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002437 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002438 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02002439 ret = wl1271_join(wl, wlvif, false);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002440 if (ret < 0)
2441 wl1271_warning("cmd join on channel "
2442 "failed %d", ret);
Eliad Peller251c1772011-08-14 13:17:17 +03002443 } else {
2444 /*
2445 * change the ROC channel. do it only if we are
2446 * not idle. otherwise, CROC will be called
2447 * anyway.
2448 */
Eliad Peller92e712d2011-12-18 20:25:43 +02002449 if (wl12xx_dev_role_started(wlvif) &&
Eliad Peller251c1772011-08-14 13:17:17 +03002450 !(conf->flags & IEEE80211_CONF_IDLE)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002451 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002452 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002453 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002454
Eliad Peller679a6732011-10-11 11:55:44 +02002455 ret = wl12xx_start_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03002456 if (ret < 0)
Eliad Peller679a6732011-10-11 11:55:44 +02002457 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002458 }
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002459 }
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002460 }
2461 }
2462
Juuso Oikarinen71449f82009-12-11 15:41:07 +02002463 if (conf->flags & IEEE80211_CONF_PS &&
Eliad Pellerc29bb002011-10-10 10:13:03 +02002464 !test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
2465 set_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002466
2467 /*
2468 * We enter PSM only if we're already associated.
2469 * If we're not, we'll enter it when joining an SSID,
2470 * through the bss_info_changed() hook.
2471 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002472 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
Juuso Oikarinen18f8d462010-02-22 08:38:34 +02002473 wl1271_debug(DEBUG_PSM, "psm enabled");
Eliad Peller0603d892011-10-05 11:55:51 +02002474 ret = wl1271_ps_set_mode(wl, wlvif,
2475 STATION_POWER_SAVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002476 wlvif->basic_rate, true);
Juuso Oikarinenaf5e0842009-12-11 15:41:00 +02002477 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002478 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
Eliad Pellerc29bb002011-10-10 10:13:03 +02002479 test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
Juuso Oikarinen18f8d462010-02-22 08:38:34 +02002480 wl1271_debug(DEBUG_PSM, "psm disabled");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002481
Eliad Pellerc29bb002011-10-10 10:13:03 +02002482 clear_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002483
Eliad Pellerc29bb002011-10-10 10:13:03 +02002484 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags))
Eliad Peller0603d892011-10-05 11:55:51 +02002485 ret = wl1271_ps_set_mode(wl, wlvif,
2486 STATION_ACTIVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002487 wlvif->basic_rate, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002488 }
2489
Eliad Peller6bd65022011-10-10 10:13:11 +02002490 if (conf->power_level != wlvif->power_level) {
Eliad Peller0603d892011-10-05 11:55:51 +02002491 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002492 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002493 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002494
Eliad Peller6bd65022011-10-10 10:13:11 +02002495 wlvif->power_level = conf->power_level;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002496 }
2497
Eliad Peller9f259c42011-10-10 10:13:12 +02002498 return 0;
2499}
2500
2501static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2502{
2503 struct wl1271 *wl = hw->priv;
2504 struct wl12xx_vif *wlvif;
2505 struct ieee80211_conf *conf = &hw->conf;
2506 int channel, ret = 0;
2507
2508 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2509
2510 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2511 " changed 0x%x",
2512 channel,
2513 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2514 conf->power_level,
2515 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2516 changed);
2517
2518 /*
2519 * mac80211 will go to idle nearly immediately after transmitting some
2520 * frames, such as the deauth. To make sure those frames reach the air,
2521 * wait here until the TX queue is fully flushed.
2522 */
2523 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2524 (conf->flags & IEEE80211_CONF_IDLE))
2525 wl1271_tx_flush(wl);
2526
2527 mutex_lock(&wl->mutex);
2528
2529 /* we support configuring the channel and band even while off */
2530 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2531 wl->band = conf->channel->band;
2532 wl->channel = channel;
2533 }
2534
2535 if (changed & IEEE80211_CONF_CHANGE_POWER)
2536 wl->power_level = conf->power_level;
2537
2538 if (unlikely(wl->state == WL1271_STATE_OFF))
2539 goto out;
2540
2541 ret = wl1271_ps_elp_wakeup(wl);
2542 if (ret < 0)
2543 goto out;
2544
2545 /* configure each interface */
2546 wl12xx_for_each_wlvif(wl, wlvif) {
2547 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2548 if (ret < 0)
2549 goto out_sleep;
2550 }
2551
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002552out_sleep:
2553 wl1271_ps_elp_sleep(wl);
2554
2555out:
2556 mutex_unlock(&wl->mutex);
2557
2558 return ret;
2559}
2560
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002561struct wl1271_filter_params {
2562 bool enabled;
2563 int mc_list_length;
2564 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2565};
2566
Jiri Pirko22bedad2010-04-01 21:22:57 +00002567static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2568 struct netdev_hw_addr_list *mc_list)
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002569{
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002570 struct wl1271_filter_params *fp;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002571 struct netdev_hw_addr *ha;
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002572 struct wl1271 *wl = hw->priv;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002573
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002574 if (unlikely(wl->state == WL1271_STATE_OFF))
2575 return 0;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002576
Juuso Oikarinen74441132009-10-13 12:47:53 +03002577 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002578 if (!fp) {
2579 wl1271_error("Out of memory setting filters.");
2580 return 0;
2581 }
2582
2583 /* update multicast filtering parameters */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002584 fp->mc_list_length = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002585 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2586 fp->enabled = false;
2587 } else {
2588 fp->enabled = true;
2589 netdev_hw_addr_list_for_each(ha, mc_list) {
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002590 memcpy(fp->mc_list[fp->mc_list_length],
Jiri Pirko22bedad2010-04-01 21:22:57 +00002591 ha->addr, ETH_ALEN);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002592 fp->mc_list_length++;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002593 }
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002594 }
2595
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002596 return (u64)(unsigned long)fp;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002597}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002598
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002599#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2600 FIF_ALLMULTI | \
2601 FIF_FCSFAIL | \
2602 FIF_BCN_PRBRESP_PROMISC | \
2603 FIF_CONTROL | \
2604 FIF_OTHER_BSS)
2605
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002606static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2607 unsigned int changed,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002608 unsigned int *total, u64 multicast)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002609{
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002610 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002611 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02002612 struct wl12xx_vif *wlvif;
Eliad Peller536129c2011-10-05 11:55:45 +02002613
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002614 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002615
Arik Nemtsov7d057862010-10-16 19:25:35 +02002616 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2617 " total %x", changed, *total);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002618
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002619 mutex_lock(&wl->mutex);
2620
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002621 *total &= WL1271_SUPPORTED_FILTERS;
2622 changed &= WL1271_SUPPORTED_FILTERS;
2623
2624 if (unlikely(wl->state == WL1271_STATE_OFF))
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002625 goto out;
2626
Ido Yariva6208652011-03-01 15:14:41 +02002627 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002628 if (ret < 0)
2629 goto out;
2630
Eliad Peller6e8cd332011-10-10 10:13:13 +02002631 wl12xx_for_each_wlvif(wl, wlvif) {
2632 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2633 if (*total & FIF_ALLMULTI)
2634 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2635 false,
2636 NULL, 0);
2637 else if (fp)
2638 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2639 fp->enabled,
2640 fp->mc_list,
2641 fp->mc_list_length);
2642 if (ret < 0)
2643 goto out_sleep;
2644 }
Arik Nemtsov7d057862010-10-16 19:25:35 +02002645 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002646
Eliad Peller08c1d1c2011-08-14 13:17:04 +03002647 /*
2648 * the fw doesn't provide an api to configure the filters. instead,
2649 * the filters configuration is based on the active roles / ROC
2650 * state.
2651 */
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002652
2653out_sleep:
2654 wl1271_ps_elp_sleep(wl);
2655
2656out:
2657 mutex_unlock(&wl->mutex);
Juuso Oikarinen14b228a2010-03-18 12:26:43 +02002658 kfree(fp);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002659}
2660
Eliad Peller170d0e62011-10-05 11:56:06 +02002661static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2662 u8 id, u8 key_type, u8 key_size,
2663 const u8 *key, u8 hlid, u32 tx_seq_32,
2664 u16 tx_seq_16)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002665{
2666 struct wl1271_ap_key *ap_key;
2667 int i;
2668
2669 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2670
2671 if (key_size > MAX_KEY_SIZE)
2672 return -EINVAL;
2673
2674 /*
2675 * Find next free entry in ap_keys. Also check we are not replacing
2676 * an existing key.
2677 */
2678 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002679 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002680 break;
2681
Eliad Peller170d0e62011-10-05 11:56:06 +02002682 if (wlvif->ap.recorded_keys[i]->id == id) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002683 wl1271_warning("trying to record key replacement");
2684 return -EINVAL;
2685 }
2686 }
2687
2688 if (i == MAX_NUM_KEYS)
2689 return -EBUSY;
2690
2691 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2692 if (!ap_key)
2693 return -ENOMEM;
2694
2695 ap_key->id = id;
2696 ap_key->key_type = key_type;
2697 ap_key->key_size = key_size;
2698 memcpy(ap_key->key, key, key_size);
2699 ap_key->hlid = hlid;
2700 ap_key->tx_seq_32 = tx_seq_32;
2701 ap_key->tx_seq_16 = tx_seq_16;
2702
Eliad Peller170d0e62011-10-05 11:56:06 +02002703 wlvif->ap.recorded_keys[i] = ap_key;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002704 return 0;
2705}
2706
Eliad Peller170d0e62011-10-05 11:56:06 +02002707static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002708{
2709 int i;
2710
2711 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002712 kfree(wlvif->ap.recorded_keys[i]);
2713 wlvif->ap.recorded_keys[i] = NULL;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002714 }
2715}
2716
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002717static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002718{
2719 int i, ret = 0;
2720 struct wl1271_ap_key *key;
2721 bool wep_key_added = false;
2722
2723 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller7f97b482011-08-14 13:17:30 +03002724 u8 hlid;
Eliad Peller170d0e62011-10-05 11:56:06 +02002725 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002726 break;
2727
Eliad Peller170d0e62011-10-05 11:56:06 +02002728 key = wlvif->ap.recorded_keys[i];
Eliad Peller7f97b482011-08-14 13:17:30 +03002729 hlid = key->hlid;
2730 if (hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002731 hlid = wlvif->ap.bcast_hlid;
Eliad Peller7f97b482011-08-14 13:17:30 +03002732
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002733 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002734 key->id, key->key_type,
2735 key->key_size, key->key,
Eliad Peller7f97b482011-08-14 13:17:30 +03002736 hlid, key->tx_seq_32,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002737 key->tx_seq_16);
2738 if (ret < 0)
2739 goto out;
2740
2741 if (key->key_type == KEY_WEP)
2742 wep_key_added = true;
2743 }
2744
2745 if (wep_key_added) {
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002746 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002747 wlvif->ap.bcast_hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002748 if (ret < 0)
2749 goto out;
2750 }
2751
2752out:
Eliad Peller170d0e62011-10-05 11:56:06 +02002753 wl1271_free_ap_keys(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002754 return ret;
2755}
2756
Eliad Peller536129c2011-10-05 11:55:45 +02002757static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2758 u16 action, u8 id, u8 key_type,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002759 u8 key_size, const u8 *key, u32 tx_seq_32,
2760 u16 tx_seq_16, struct ieee80211_sta *sta)
2761{
2762 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002763 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002764
2765 if (is_ap) {
2766 struct wl1271_station *wl_sta;
2767 u8 hlid;
2768
2769 if (sta) {
2770 wl_sta = (struct wl1271_station *)sta->drv_priv;
2771 hlid = wl_sta->hlid;
2772 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002773 hlid = wlvif->ap.bcast_hlid;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002774 }
2775
Eliad Peller53d40d02011-10-10 10:13:02 +02002776 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002777 /*
2778 * We do not support removing keys after AP shutdown.
2779 * Pretend we do to make mac80211 happy.
2780 */
2781 if (action != KEY_ADD_OR_REPLACE)
2782 return 0;
2783
Eliad Peller170d0e62011-10-05 11:56:06 +02002784 ret = wl1271_record_ap_key(wl, wlvif, id,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002785 key_type, key_size,
2786 key, hlid, tx_seq_32,
2787 tx_seq_16);
2788 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002789 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002790 id, key_type, key_size,
2791 key, hlid, tx_seq_32,
2792 tx_seq_16);
2793 }
2794
2795 if (ret < 0)
2796 return ret;
2797 } else {
2798 const u8 *addr;
2799 static const u8 bcast_addr[ETH_ALEN] = {
2800 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2801 };
2802
Guy Eilame9eb8cb2011-08-16 19:49:12 +03002803 /*
2804 * A STA set to GEM cipher requires 2 tx spare blocks.
2805 * Return to default value when GEM cipher key is removed
2806 */
2807 if (key_type == KEY_GEM) {
2808 if (action == KEY_ADD_OR_REPLACE)
2809 wl->tx_spare_blocks = 2;
2810 else if (action == KEY_REMOVE)
2811 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2812 }
2813
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002814 addr = sta ? sta->addr : bcast_addr;
2815
2816 if (is_zero_ether_addr(addr)) {
2817 /* We dont support TX only encryption */
2818 return -EOPNOTSUPP;
2819 }
2820
2821 /* The wl1271 does not allow to remove unicast keys - they
2822 will be cleared automatically on next CMD_JOIN. Ignore the
2823 request silently, as we dont want the mac80211 to emit
2824 an error message. */
2825 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2826 return 0;
2827
Eliad Peller010d3d32011-08-14 13:17:31 +03002828 /* don't remove key if hlid was already deleted */
2829 if (action == KEY_REMOVE &&
Eliad Peller154da672011-10-05 11:55:53 +02002830 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Peller010d3d32011-08-14 13:17:31 +03002831 return 0;
2832
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002833 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002834 id, key_type, key_size,
2835 key, addr, tx_seq_32,
2836 tx_seq_16);
2837 if (ret < 0)
2838 return ret;
2839
2840 /* the default WEP key needs to be configured at least once */
2841 if (key_type == KEY_WEP) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03002842 ret = wl12xx_cmd_set_default_wep_key(wl,
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002843 wlvif->default_key,
2844 wlvif->sta.hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002845 if (ret < 0)
2846 return ret;
2847 }
2848 }
2849
2850 return 0;
2851}
2852
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002853static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2854 struct ieee80211_vif *vif,
2855 struct ieee80211_sta *sta,
2856 struct ieee80211_key_conf *key_conf)
2857{
2858 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002859 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002860 int ret;
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03002861 u32 tx_seq_32 = 0;
2862 u16 tx_seq_16 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002863 u8 key_type;
2864
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002865 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2866
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002867 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002868 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Johannes Berg97359d12010-08-10 09:46:38 +02002869 key_conf->cipher, key_conf->keyidx,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002870 key_conf->keylen, key_conf->flags);
2871 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2872
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002873 mutex_lock(&wl->mutex);
2874
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02002875 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2876 ret = -EAGAIN;
2877 goto out_unlock;
2878 }
2879
Ido Yariva6208652011-03-01 15:14:41 +02002880 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002881 if (ret < 0)
2882 goto out_unlock;
2883
Johannes Berg97359d12010-08-10 09:46:38 +02002884 switch (key_conf->cipher) {
2885 case WLAN_CIPHER_SUITE_WEP40:
2886 case WLAN_CIPHER_SUITE_WEP104:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002887 key_type = KEY_WEP;
2888
2889 key_conf->hw_key_idx = key_conf->keyidx;
2890 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002891 case WLAN_CIPHER_SUITE_TKIP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002892 key_type = KEY_TKIP;
2893
2894 key_conf->hw_key_idx = key_conf->keyidx;
Eliad Peller48e93e42011-10-10 10:12:58 +02002895 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2896 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002897 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002898 case WLAN_CIPHER_SUITE_CCMP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002899 key_type = KEY_AES;
2900
Arik Nemtsov12d4b972011-10-23 08:21:54 +02002901 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Eliad Peller48e93e42011-10-10 10:12:58 +02002902 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2903 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002904 break;
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002905 case WL1271_CIPHER_SUITE_GEM:
2906 key_type = KEY_GEM;
Eliad Peller48e93e42011-10-10 10:12:58 +02002907 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2908 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002909 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002910 default:
Johannes Berg97359d12010-08-10 09:46:38 +02002911 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002912
2913 ret = -EOPNOTSUPP;
2914 goto out_sleep;
2915 }
2916
2917 switch (cmd) {
2918 case SET_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02002919 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002920 key_conf->keyidx, key_type,
2921 key_conf->keylen, key_conf->key,
2922 tx_seq_32, tx_seq_16, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002923 if (ret < 0) {
2924 wl1271_error("Could not add or replace key");
2925 goto out_sleep;
2926 }
2927 break;
2928
2929 case DISABLE_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02002930 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002931 key_conf->keyidx, key_type,
2932 key_conf->keylen, key_conf->key,
2933 0, 0, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002934 if (ret < 0) {
2935 wl1271_error("Could not remove key");
2936 goto out_sleep;
2937 }
2938 break;
2939
2940 default:
2941 wl1271_error("Unsupported key cmd 0x%x", cmd);
2942 ret = -EOPNOTSUPP;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002943 break;
2944 }
2945
2946out_sleep:
2947 wl1271_ps_elp_sleep(wl);
2948
2949out_unlock:
2950 mutex_unlock(&wl->mutex);
2951
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002952 return ret;
2953}
2954
2955static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
Johannes Berga060bbf2010-04-27 11:59:34 +02002956 struct ieee80211_vif *vif,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002957 struct cfg80211_scan_request *req)
2958{
2959 struct wl1271 *wl = hw->priv;
Eliad Peller7edebf52011-10-05 11:55:52 +02002960 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2961
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002962 int ret;
2963 u8 *ssid = NULL;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03002964 size_t len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002965
2966 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
2967
2968 if (req->n_ssids) {
2969 ssid = req->ssids[0].ssid;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03002970 len = req->ssids[0].ssid_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002971 }
2972
2973 mutex_lock(&wl->mutex);
2974
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002975 if (wl->state == WL1271_STATE_OFF) {
2976 /*
2977 * We cannot return -EBUSY here because cfg80211 will expect
2978 * a call to ieee80211_scan_completed if we do - in this case
2979 * there won't be any call.
2980 */
2981 ret = -EAGAIN;
2982 goto out;
2983 }
2984
Ido Yariva6208652011-03-01 15:14:41 +02002985 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002986 if (ret < 0)
2987 goto out;
2988
Eliad Peller92e712d2011-12-18 20:25:43 +02002989 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
2990 test_bit(wlvif->role_id, wl->roc_map)) {
2991 /* don't allow scanning right now */
2992 ret = -EBUSY;
2993 goto out_sleep;
Eliad Peller251c1772011-08-14 13:17:17 +03002994 }
2995
Eliad Peller92e712d2011-12-18 20:25:43 +02002996 /* cancel ROC before scanning */
2997 if (wl12xx_dev_role_started(wlvif))
Eliad Pellerc059beb2012-01-31 11:57:17 +02002998 wl12xx_croc(wl, wlvif->dev_role_id);
Eliad Peller92e712d2011-12-18 20:25:43 +02002999
Eliad Peller784f6942011-10-05 11:55:39 +02003000 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
Eliad Peller251c1772011-08-14 13:17:17 +03003001out_sleep:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003002 wl1271_ps_elp_sleep(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003003out:
3004 mutex_unlock(&wl->mutex);
3005
3006 return ret;
3007}
3008
Eliad Peller73ecce32011-06-27 13:06:45 +03003009static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3010 struct ieee80211_vif *vif)
3011{
3012 struct wl1271 *wl = hw->priv;
3013 int ret;
3014
3015 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3016
3017 mutex_lock(&wl->mutex);
3018
3019 if (wl->state == WL1271_STATE_OFF)
3020 goto out;
3021
3022 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3023 goto out;
3024
3025 ret = wl1271_ps_elp_wakeup(wl);
3026 if (ret < 0)
3027 goto out;
3028
3029 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3030 ret = wl1271_scan_stop(wl);
3031 if (ret < 0)
3032 goto out_sleep;
3033 }
3034 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3035 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02003036 wl->scan_vif = NULL;
Eliad Peller73ecce32011-06-27 13:06:45 +03003037 wl->scan.req = NULL;
3038 ieee80211_scan_completed(wl->hw, true);
3039
3040out_sleep:
3041 wl1271_ps_elp_sleep(wl);
3042out:
3043 mutex_unlock(&wl->mutex);
3044
3045 cancel_delayed_work_sync(&wl->scan_complete_work);
3046}
3047
Luciano Coelho33c2c062011-05-10 14:46:02 +03003048static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3049 struct ieee80211_vif *vif,
3050 struct cfg80211_sched_scan_request *req,
3051 struct ieee80211_sched_scan_ies *ies)
3052{
3053 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003054 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003055 int ret;
3056
3057 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3058
3059 mutex_lock(&wl->mutex);
3060
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003061 if (wl->state == WL1271_STATE_OFF) {
3062 ret = -EAGAIN;
3063 goto out;
3064 }
3065
Luciano Coelho33c2c062011-05-10 14:46:02 +03003066 ret = wl1271_ps_elp_wakeup(wl);
3067 if (ret < 0)
3068 goto out;
3069
Eliad Peller536129c2011-10-05 11:55:45 +02003070 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003071 if (ret < 0)
3072 goto out_sleep;
3073
Eliad Peller536129c2011-10-05 11:55:45 +02003074 ret = wl1271_scan_sched_scan_start(wl, wlvif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003075 if (ret < 0)
3076 goto out_sleep;
3077
3078 wl->sched_scanning = true;
3079
3080out_sleep:
3081 wl1271_ps_elp_sleep(wl);
3082out:
3083 mutex_unlock(&wl->mutex);
3084 return ret;
3085}
3086
3087static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3088 struct ieee80211_vif *vif)
3089{
3090 struct wl1271 *wl = hw->priv;
3091 int ret;
3092
3093 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3094
3095 mutex_lock(&wl->mutex);
3096
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003097 if (wl->state == WL1271_STATE_OFF)
3098 goto out;
3099
Luciano Coelho33c2c062011-05-10 14:46:02 +03003100 ret = wl1271_ps_elp_wakeup(wl);
3101 if (ret < 0)
3102 goto out;
3103
3104 wl1271_scan_sched_scan_stop(wl);
3105
3106 wl1271_ps_elp_sleep(wl);
3107out:
3108 mutex_unlock(&wl->mutex);
3109}
3110
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003111static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3112{
3113 struct wl1271 *wl = hw->priv;
3114 int ret = 0;
3115
3116 mutex_lock(&wl->mutex);
3117
3118 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3119 ret = -EAGAIN;
3120 goto out;
3121 }
3122
Ido Yariva6208652011-03-01 15:14:41 +02003123 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003124 if (ret < 0)
3125 goto out;
3126
Arik Nemtsov5f704d12011-04-18 14:15:21 +03003127 ret = wl1271_acx_frag_threshold(wl, value);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003128 if (ret < 0)
3129 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3130
3131 wl1271_ps_elp_sleep(wl);
3132
3133out:
3134 mutex_unlock(&wl->mutex);
3135
3136 return ret;
3137}
3138
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003139static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3140{
3141 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02003142 struct wl12xx_vif *wlvif;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003143 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003144
3145 mutex_lock(&wl->mutex);
3146
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003147 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3148 ret = -EAGAIN;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003149 goto out;
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003150 }
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003151
Ido Yariva6208652011-03-01 15:14:41 +02003152 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003153 if (ret < 0)
3154 goto out;
3155
Eliad Peller6e8cd332011-10-10 10:13:13 +02003156 wl12xx_for_each_wlvif(wl, wlvif) {
3157 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3158 if (ret < 0)
3159 wl1271_warning("set rts threshold failed: %d", ret);
3160 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003161 wl1271_ps_elp_sleep(wl);
3162
3163out:
3164 mutex_unlock(&wl->mutex);
3165
3166 return ret;
3167}
3168
Eliad Peller1fe9f162011-10-05 11:55:48 +02003169static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003170 int offset)
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003171{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003172 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller889cb362011-05-01 09:56:45 +03003173 u8 ssid_len;
3174 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3175 skb->len - offset);
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003176
Eliad Peller889cb362011-05-01 09:56:45 +03003177 if (!ptr) {
3178 wl1271_error("No SSID in IEs!");
3179 return -ENOENT;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003180 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003181
Eliad Peller889cb362011-05-01 09:56:45 +03003182 ssid_len = ptr[1];
3183 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3184 wl1271_error("SSID is too long!");
3185 return -EINVAL;
3186 }
3187
Eliad Peller1fe9f162011-10-05 11:55:48 +02003188 wlvif->ssid_len = ssid_len;
3189 memcpy(wlvif->ssid, ptr+2, ssid_len);
Eliad Peller889cb362011-05-01 09:56:45 +03003190 return 0;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003191}
3192
Eliad Pellerd48055d2011-09-15 12:07:04 +03003193static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3194{
3195 int len;
3196 const u8 *next, *end = skb->data + skb->len;
3197 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3198 skb->len - ieoffset);
3199 if (!ie)
3200 return;
3201 len = ie[1] + 2;
3202 next = ie + len;
3203 memmove(ie, next, end - next);
3204 skb_trim(skb, skb->len - len);
3205}
3206
Eliad Peller26b4bf22011-09-15 12:07:05 +03003207static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3208 unsigned int oui, u8 oui_type,
3209 int ieoffset)
3210{
3211 int len;
3212 const u8 *next, *end = skb->data + skb->len;
3213 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3214 skb->data + ieoffset,
3215 skb->len - ieoffset);
3216 if (!ie)
3217 return;
3218 len = ie[1] + 2;
3219 next = ie + len;
3220 memmove(ie, next, end - next);
3221 skb_trim(skb, skb->len - len);
3222}
3223
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003224static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3225 struct ieee80211_vif *vif)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003226{
Eliad Pellercdaac622012-01-31 11:57:16 +02003227 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003228 struct sk_buff *skb;
3229 int ret;
3230
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003231 skb = ieee80211_proberesp_get(wl->hw, vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003232 if (!skb)
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003233 return -EOPNOTSUPP;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003234
Eliad Pellercdaac622012-01-31 11:57:16 +02003235 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov560f0022011-11-08 18:46:54 +02003236 CMD_TEMPL_AP_PROBE_RESPONSE,
3237 skb->data,
3238 skb->len, 0,
3239 rates);
3240
3241 dev_kfree_skb(skb);
3242 return ret;
3243}
3244
3245static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3246 struct ieee80211_vif *vif,
3247 u8 *probe_rsp_data,
3248 size_t probe_rsp_len,
3249 u32 rates)
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003250{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003251 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3252 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003253 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3254 int ssid_ie_offset, ie_offset, templ_len;
3255 const u8 *ptr;
3256
3257 /* no need to change probe response if the SSID is set correctly */
Eliad Peller1fe9f162011-10-05 11:55:48 +02003258 if (wlvif->ssid_len > 0)
Eliad Pellercdaac622012-01-31 11:57:16 +02003259 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003260 CMD_TEMPL_AP_PROBE_RESPONSE,
3261 probe_rsp_data,
3262 probe_rsp_len, 0,
3263 rates);
3264
3265 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3266 wl1271_error("probe_rsp template too big");
3267 return -EINVAL;
3268 }
3269
3270 /* start searching from IE offset */
3271 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3272
3273 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3274 probe_rsp_len - ie_offset);
3275 if (!ptr) {
3276 wl1271_error("No SSID in beacon!");
3277 return -EINVAL;
3278 }
3279
3280 ssid_ie_offset = ptr - probe_rsp_data;
3281 ptr += (ptr[1] + 2);
3282
3283 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3284
3285 /* insert SSID from bss_conf */
3286 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3287 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3288 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3289 bss_conf->ssid, bss_conf->ssid_len);
3290 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3291
3292 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3293 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3294 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3295
Eliad Pellercdaac622012-01-31 11:57:16 +02003296 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003297 CMD_TEMPL_AP_PROBE_RESPONSE,
3298 probe_rsp_templ,
3299 templ_len, 0,
3300 rates);
3301}
3302
Arik Nemtsove78a2872010-10-16 19:07:21 +02003303static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
Eliad Peller0603d892011-10-05 11:55:51 +02003304 struct ieee80211_vif *vif,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003305 struct ieee80211_bss_conf *bss_conf,
3306 u32 changed)
3307{
Eliad Peller0603d892011-10-05 11:55:51 +02003308 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003309 int ret = 0;
3310
3311 if (changed & BSS_CHANGED_ERP_SLOT) {
3312 if (bss_conf->use_short_slot)
Eliad Peller0603d892011-10-05 11:55:51 +02003313 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003314 else
Eliad Peller0603d892011-10-05 11:55:51 +02003315 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003316 if (ret < 0) {
3317 wl1271_warning("Set slot time failed %d", ret);
3318 goto out;
3319 }
3320 }
3321
3322 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3323 if (bss_conf->use_short_preamble)
Eliad Peller0603d892011-10-05 11:55:51 +02003324 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003325 else
Eliad Peller0603d892011-10-05 11:55:51 +02003326 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003327 }
3328
3329 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3330 if (bss_conf->use_cts_prot)
Eliad Peller0603d892011-10-05 11:55:51 +02003331 ret = wl1271_acx_cts_protect(wl, wlvif,
3332 CTSPROTECT_ENABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003333 else
Eliad Peller0603d892011-10-05 11:55:51 +02003334 ret = wl1271_acx_cts_protect(wl, wlvif,
3335 CTSPROTECT_DISABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003336 if (ret < 0) {
3337 wl1271_warning("Set ctsprotect failed %d", ret);
3338 goto out;
3339 }
3340 }
3341
3342out:
3343 return ret;
3344}
3345
3346static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3347 struct ieee80211_vif *vif,
3348 struct ieee80211_bss_conf *bss_conf,
3349 u32 changed)
3350{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003351 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller536129c2011-10-05 11:55:45 +02003352 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003353 int ret = 0;
3354
3355 if ((changed & BSS_CHANGED_BEACON_INT)) {
3356 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3357 bss_conf->beacon_int);
3358
Eliad Peller6a899792011-10-05 11:55:58 +02003359 wlvif->beacon_int = bss_conf->beacon_int;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003360 }
3361
Arik Nemtsov560f0022011-11-08 18:46:54 +02003362 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3363 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003364 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3365 wl1271_debug(DEBUG_AP, "probe response updated");
3366 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3367 }
Arik Nemtsov560f0022011-11-08 18:46:54 +02003368 }
3369
Arik Nemtsove78a2872010-10-16 19:07:21 +02003370 if ((changed & BSS_CHANGED_BEACON)) {
3371 struct ieee80211_hdr *hdr;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003372 u32 min_rate;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003373 int ieoffset = offsetof(struct ieee80211_mgmt,
3374 u.beacon.variable);
3375 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3376 u16 tmpl_id;
3377
Arik Nemtsov560f0022011-11-08 18:46:54 +02003378 if (!beacon) {
3379 ret = -EINVAL;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003380 goto out;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003381 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003382
3383 wl1271_debug(DEBUG_MASTER, "beacon updated");
3384
Eliad Peller1fe9f162011-10-05 11:55:48 +02003385 ret = wl1271_ssid_set(vif, beacon, ieoffset);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003386 if (ret < 0) {
3387 dev_kfree_skb(beacon);
3388 goto out;
3389 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02003390 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003391 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3392 CMD_TEMPL_BEACON;
Eliad Pellercdaac622012-01-31 11:57:16 +02003393 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003394 beacon->data,
3395 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003396 min_rate);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003397 if (ret < 0) {
3398 dev_kfree_skb(beacon);
3399 goto out;
3400 }
3401
Arik Nemtsov560f0022011-11-08 18:46:54 +02003402 /*
3403 * In case we already have a probe-resp beacon set explicitly
3404 * by usermode, don't use the beacon data.
3405 */
3406 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3407 goto end_bcn;
3408
Eliad Pellerd48055d2011-09-15 12:07:04 +03003409 /* remove TIM ie from probe response */
3410 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3411
Eliad Peller26b4bf22011-09-15 12:07:05 +03003412 /*
3413 * remove p2p ie from probe response.
3414 * the fw reponds to probe requests that don't include
3415 * the p2p ie. probe requests with p2p ie will be passed,
3416 * and will be responded by the supplicant (the spec
3417 * forbids including the p2p ie when responding to probe
3418 * requests that didn't include it).
3419 */
3420 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3421 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3422
Arik Nemtsove78a2872010-10-16 19:07:21 +02003423 hdr = (struct ieee80211_hdr *) beacon->data;
3424 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3425 IEEE80211_STYPE_PROBE_RESP);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003426 if (is_ap)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003427 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003428 beacon->data,
3429 beacon->len,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003430 min_rate);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003431 else
Eliad Pellercdaac622012-01-31 11:57:16 +02003432 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003433 CMD_TEMPL_PROBE_RESPONSE,
3434 beacon->data,
3435 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003436 min_rate);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003437end_bcn:
Arik Nemtsove78a2872010-10-16 19:07:21 +02003438 dev_kfree_skb(beacon);
3439 if (ret < 0)
3440 goto out;
3441 }
3442
3443out:
Arik Nemtsov560f0022011-11-08 18:46:54 +02003444 if (ret != 0)
3445 wl1271_error("beacon info change failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003446 return ret;
3447}
3448
3449/* AP mode changes */
3450static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003451 struct ieee80211_vif *vif,
3452 struct ieee80211_bss_conf *bss_conf,
3453 u32 changed)
3454{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003455 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003456 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003457
Arik Nemtsove78a2872010-10-16 19:07:21 +02003458 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3459 u32 rates = bss_conf->basic_rates;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003460
Eliad Peller87fbcb02011-10-05 11:55:41 +02003461 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003462 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003463 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
Eliad Peller87fbcb02011-10-05 11:55:41 +02003464 wlvif->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003465
Eliad Peller87fbcb02011-10-05 11:55:41 +02003466 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003467 if (ret < 0) {
Arik Nemtsov70f47422011-04-18 14:15:25 +03003468 wl1271_error("AP rate policy change failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003469 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003470 }
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003471
Eliad Peller784f6942011-10-05 11:55:39 +02003472 ret = wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003473 if (ret < 0)
3474 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003475 }
3476
Arik Nemtsove78a2872010-10-16 19:07:21 +02003477 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3478 if (ret < 0)
3479 goto out;
3480
3481 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3482 if (bss_conf->enable_beacon) {
Eliad Peller53d40d02011-10-10 10:13:02 +02003483 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003484 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003485 if (ret < 0)
3486 goto out;
3487
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003488 ret = wl1271_ap_init_hwenc(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003489 if (ret < 0)
3490 goto out;
Arik Nemtsovcf420392011-08-14 13:17:37 +03003491
Eliad Peller53d40d02011-10-10 10:13:02 +02003492 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsovcf420392011-08-14 13:17:37 +03003493 wl1271_debug(DEBUG_AP, "started AP");
Arik Nemtsove78a2872010-10-16 19:07:21 +02003494 }
3495 } else {
Eliad Peller53d40d02011-10-10 10:13:02 +02003496 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003497 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003498 if (ret < 0)
3499 goto out;
3500
Eliad Peller53d40d02011-10-10 10:13:02 +02003501 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003502 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3503 &wlvif->flags);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003504 wl1271_debug(DEBUG_AP, "stopped AP");
3505 }
3506 }
3507 }
3508
Eliad Peller0603d892011-10-05 11:55:51 +02003509 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003510 if (ret < 0)
3511 goto out;
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003512
3513 /* Handle HT information change */
3514 if ((changed & BSS_CHANGED_HT) &&
3515 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003516 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003517 bss_conf->ht_operation_mode);
3518 if (ret < 0) {
3519 wl1271_warning("Set ht information failed %d", ret);
3520 goto out;
3521 }
3522 }
3523
Arik Nemtsove78a2872010-10-16 19:07:21 +02003524out:
3525 return;
3526}
3527
3528/* STA/IBSS mode changes */
3529static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3530 struct ieee80211_vif *vif,
3531 struct ieee80211_bss_conf *bss_conf,
3532 u32 changed)
3533{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003534 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003535 bool do_join = false, set_assoc = false;
Eliad Peller536129c2011-10-05 11:55:45 +02003536 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Eliad Peller227e81e2011-08-14 13:17:26 +03003537 bool ibss_joined = false;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003538 u32 sta_rate_set = 0;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003539 int ret;
Luciano Coelho2d6e4e762011-01-11 19:07:21 +01003540 struct ieee80211_sta *sta;
Arik Nemtsova1008852011-02-12 23:24:20 +02003541 bool sta_exists = false;
3542 struct ieee80211_sta_ht_cap sta_ht_cap;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003543
3544 if (is_ibss) {
3545 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3546 changed);
3547 if (ret < 0)
3548 goto out;
3549 }
3550
Eliad Peller227e81e2011-08-14 13:17:26 +03003551 if (changed & BSS_CHANGED_IBSS) {
3552 if (bss_conf->ibss_joined) {
Eliad Pellereee514e2011-10-10 10:13:01 +02003553 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
Eliad Peller227e81e2011-08-14 13:17:26 +03003554 ibss_joined = true;
3555 } else {
Eliad Pellereee514e2011-10-10 10:13:01 +02003556 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3557 &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003558 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003559 wl12xx_start_dev(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03003560 }
3561 }
3562 }
3563
3564 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003565 do_join = true;
3566
3567 /* Need to update the SSID (for filtering etc) */
Eliad Peller227e81e2011-08-14 13:17:26 +03003568 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003569 do_join = true;
3570
Eliad Peller227e81e2011-08-14 13:17:26 +03003571 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003572 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3573 bss_conf->enable_beacon ? "enabled" : "disabled");
3574
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003575 do_join = true;
3576 }
3577
Eliad Pellerc31e4942011-10-23 08:21:55 +02003578 if (changed & BSS_CHANGED_IDLE) {
3579 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3580 if (ret < 0)
3581 wl1271_warning("idle mode change failed %d", ret);
3582 }
3583
Arik Nemtsove78a2872010-10-16 19:07:21 +02003584 if ((changed & BSS_CHANGED_CQM)) {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003585 bool enable = false;
3586 if (bss_conf->cqm_rssi_thold)
3587 enable = true;
Eliad Peller0603d892011-10-05 11:55:51 +02003588 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003589 bss_conf->cqm_rssi_thold,
3590 bss_conf->cqm_rssi_hyst);
3591 if (ret < 0)
3592 goto out;
Eliad Peller04324d92011-10-05 11:56:03 +02003593 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003594 }
3595
Eliad Peller7db4ee62012-01-24 18:18:42 +02003596 if (changed & BSS_CHANGED_BSSID &&
3597 (is_ibss || bss_conf->assoc))
Eliad Pellercdf09492011-10-05 11:55:44 +02003598 if (!is_zero_ether_addr(bss_conf->bssid)) {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003599 ret = wl12xx_cmd_build_null_data(wl, wlvif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003600 if (ret < 0)
3601 goto out;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003602
Eliad Peller784f6942011-10-05 11:55:39 +02003603 ret = wl1271_build_qos_null_data(wl, vif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003604 if (ret < 0)
3605 goto out;
Saravanan Dhanabal141418c2010-04-28 09:50:00 +03003606
Eliad Pellerfa287b82010-12-26 09:27:50 +01003607 /* Need to update the BSSID (for filtering etc) */
3608 do_join = true;
3609 }
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003610
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003611 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3612 rcu_read_lock();
3613 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3614 if (!sta)
3615 goto sta_not_found;
3616
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003617 /* save the supp_rates of the ap */
3618 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3619 if (sta->ht_cap.ht_supported)
3620 sta_rate_set |=
3621 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
Arik Nemtsova1008852011-02-12 23:24:20 +02003622 sta_ht_cap = sta->ht_cap;
3623 sta_exists = true;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003624
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003625sta_not_found:
3626 rcu_read_unlock();
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003627 }
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003628
Arik Nemtsove78a2872010-10-16 19:07:21 +02003629 if ((changed & BSS_CHANGED_ASSOC)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003630 if (bss_conf->assoc) {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003631 u32 rates;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003632 int ieoffset;
Eliad Peller6840e372011-10-05 11:55:50 +02003633 wlvif->aid = bss_conf->aid;
Juuso Oikarinen69e54342010-05-07 11:39:00 +03003634 set_assoc = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003635
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003636 /*
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003637 * use basic rates from AP, and determine lowest rate
3638 * to use with control frames.
3639 */
3640 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003641 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003642 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003643 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003644 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003645 wl1271_tx_min_rate_get(wl,
3646 wlvif->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003647 if (sta_rate_set)
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003648 wlvif->rate_set =
3649 wl1271_tx_enabled_rates_get(wl,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003650 sta_rate_set,
Eliad Peller1b92f152011-10-10 10:13:09 +02003651 wlvif->band);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003652 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003653 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003654 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003655
3656 /*
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003657 * with wl1271, we don't need to update the
3658 * beacon_int and dtim_period, because the firmware
3659 * updates it by itself when the first beacon is
3660 * received after a join.
3661 */
Eliad Peller6840e372011-10-05 11:55:50 +02003662 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003663 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003664 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003665
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003666 /*
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003667 * Get a template for hardware connection maintenance
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003668 */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003669 dev_kfree_skb(wlvif->probereq);
3670 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
Eliad Peller83587502011-10-10 10:12:53 +02003671 wlvif,
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003672 NULL);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003673 ieoffset = offsetof(struct ieee80211_mgmt,
3674 u.probe_req.variable);
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003675 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003676
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003677 /* enable the connection monitoring feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003678 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003679 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003680 goto out;
Juuso Oikarinend94cd292009-10-08 21:56:25 +03003681 } else {
3682 /* use defaults when not associated */
Eliad Peller30df14d2011-04-05 19:13:28 +03003683 bool was_assoc =
Eliad Pellerba8447f2011-10-10 10:13:00 +02003684 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3685 &wlvif->flags);
Eliad Peller251c1772011-08-14 13:17:17 +03003686 bool was_ifup =
Eliad Peller8181aec2011-10-10 10:13:04 +02003687 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3688 &wlvif->flags);
Eliad Peller6840e372011-10-05 11:55:50 +02003689 wlvif->aid = 0;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003690
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003691 /* free probe-request template */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003692 dev_kfree_skb(wlvif->probereq);
3693 wlvif->probereq = NULL;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003694
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003695 /* revert back to minimum rates for the current band */
Eliad Peller87fbcb02011-10-05 11:55:41 +02003696 wl1271_set_band_rate(wl, wlvif);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003697 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003698 wl1271_tx_min_rate_get(wl,
3699 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003700 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003701 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003702 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003703
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003704 /* disable connection monitor features */
Eliad Peller0603d892011-10-05 11:55:51 +02003705 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003706
3707 /* Disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003708 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003709 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003710 goto out;
Juuso Oikarinenb84a7d32010-11-22 12:59:08 +02003711
3712 /* restore the bssid filter and go to dummy bssid */
Eliad Peller30df14d2011-04-05 19:13:28 +03003713 if (was_assoc) {
Eliad Peller251c1772011-08-14 13:17:17 +03003714 u32 conf_flags = wl->hw->conf.flags;
3715 /*
3716 * we might have to disable roc, if there was
3717 * no IF_OPER_UP notification.
3718 */
3719 if (!was_ifup) {
Eliad Peller0603d892011-10-05 11:55:51 +02003720 ret = wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003721 if (ret < 0)
3722 goto out;
3723 }
3724 /*
3725 * (we also need to disable roc in case of
3726 * roaming on the same channel. until we will
3727 * have a better flow...)
3728 */
Eliad Peller7edebf52011-10-05 11:55:52 +02003729 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3730 ret = wl12xx_croc(wl,
3731 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003732 if (ret < 0)
3733 goto out;
3734 }
3735
Eliad Peller0603d892011-10-05 11:55:51 +02003736 wl1271_unjoin(wl, wlvif);
Eliad Peller679a6732011-10-11 11:55:44 +02003737 if (!(conf_flags & IEEE80211_CONF_IDLE))
3738 wl12xx_start_dev(wl, wlvif);
Eliad Peller30df14d2011-04-05 19:13:28 +03003739 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003740 }
3741 }
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03003742
Eliad Pellerd192d262011-05-24 14:33:08 +03003743 if (changed & BSS_CHANGED_IBSS) {
3744 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3745 bss_conf->ibss_joined);
3746
3747 if (bss_conf->ibss_joined) {
3748 u32 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003749 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003750 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003751 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003752 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003753 wl1271_tx_min_rate_get(wl,
3754 wlvif->basic_rate_set);
Eliad Pellerd192d262011-05-24 14:33:08 +03003755
Shahar Levi06b660e2011-09-05 13:54:36 +03003756 /* by default, use 11b + OFDM rates */
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003757 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3758 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Eliad Pellerd192d262011-05-24 14:33:08 +03003759 if (ret < 0)
3760 goto out;
3761 }
3762 }
3763
Eliad Peller0603d892011-10-05 11:55:51 +02003764 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003765 if (ret < 0)
3766 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003767
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003768 if (changed & BSS_CHANGED_ARP_FILTER) {
3769 __be32 addr = bss_conf->arp_addr_list[0];
Eliad Peller536129c2011-10-05 11:55:45 +02003770 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003771
Eliad Pellerc5312772010-12-09 11:31:27 +02003772 if (bss_conf->arp_addr_cnt == 1 &&
3773 bss_conf->arp_filter_enabled) {
3774 /*
3775 * The template should have been configured only upon
3776 * association. however, it seems that the correct ip
3777 * isn't being set (when sending), so we have to
3778 * reconfigure the template upon every ip change.
3779 */
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003780 ret = wl1271_cmd_build_arp_rsp(wl, wlvif, addr);
Eliad Pellerc5312772010-12-09 11:31:27 +02003781 if (ret < 0) {
3782 wl1271_warning("build arp rsp failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003783 goto out;
Eliad Pellerc5312772010-12-09 11:31:27 +02003784 }
3785
Eliad Peller0603d892011-10-05 11:55:51 +02003786 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
Eliad Pellere5e2f242011-01-24 19:19:03 +01003787 ACX_ARP_FILTER_ARP_FILTERING,
Eliad Pellerc5312772010-12-09 11:31:27 +02003788 addr);
3789 } else
Eliad Peller0603d892011-10-05 11:55:51 +02003790 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003791
3792 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003793 goto out;
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03003794 }
3795
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003796 if (do_join) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003797 ret = wl1271_join(wl, wlvif, set_assoc);
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003798 if (ret < 0) {
3799 wl1271_warning("cmd join failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003800 goto out;
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003801 }
Eliad Peller251c1772011-08-14 13:17:17 +03003802
3803 /* ROC until connected (after EAPOL exchange) */
3804 if (!is_ibss) {
Eliad Peller1b92f152011-10-10 10:13:09 +02003805 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003806 if (ret < 0)
3807 goto out;
3808
Eliad Pellerba8447f2011-10-10 10:13:00 +02003809 wl1271_check_operstate(wl, wlvif,
Eliad Peller251c1772011-08-14 13:17:17 +03003810 ieee80211_get_operstate(vif));
3811 }
3812 /*
3813 * stop device role if started (we might already be in
Eliad Peller92e712d2011-12-18 20:25:43 +02003814 * STA/IBSS role).
Eliad Peller251c1772011-08-14 13:17:17 +03003815 */
Eliad Peller92e712d2011-12-18 20:25:43 +02003816 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02003817 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003818 if (ret < 0)
3819 goto out;
3820 }
Eliad Peller05dba352011-08-23 16:37:01 +03003821
3822 /* If we want to go in PSM but we're not there yet */
Eliad Pellerc29bb002011-10-10 10:13:03 +02003823 if (test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags) &&
3824 !test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
Eliad Peller05dba352011-08-23 16:37:01 +03003825
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02003826 ret = wl1271_ps_set_mode(wl, wlvif,
3827 STATION_AUTO_PS_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003828 wlvif->basic_rate,
Eliad Peller05dba352011-08-23 16:37:01 +03003829 true);
3830 if (ret < 0)
3831 goto out;
3832 }
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003833 }
3834
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003835 /* Handle new association with HT. Do this after join. */
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003836 if (sta_exists) {
3837 if ((changed & BSS_CHANGED_HT) &&
3838 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003839 ret = wl1271_acx_set_ht_capabilities(wl,
3840 &sta_ht_cap,
3841 true,
Eliad Peller154da672011-10-05 11:55:53 +02003842 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003843 if (ret < 0) {
3844 wl1271_warning("Set ht cap true failed %d",
3845 ret);
3846 goto out;
3847 }
3848 }
3849 /* handle new association without HT and disassociation */
3850 else if (changed & BSS_CHANGED_ASSOC) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003851 ret = wl1271_acx_set_ht_capabilities(wl,
3852 &sta_ht_cap,
3853 false,
Eliad Peller154da672011-10-05 11:55:53 +02003854 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003855 if (ret < 0) {
3856 wl1271_warning("Set ht cap false failed %d",
3857 ret);
3858 goto out;
3859 }
3860 }
3861 }
3862
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003863 /* Handle HT information change. Done after join. */
3864 if ((changed & BSS_CHANGED_HT) &&
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003865 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003866 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003867 bss_conf->ht_operation_mode);
3868 if (ret < 0) {
3869 wl1271_warning("Set ht information failed %d", ret);
3870 goto out;
3871 }
3872 }
3873
Arik Nemtsove78a2872010-10-16 19:07:21 +02003874out:
3875 return;
3876}
3877
3878static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3879 struct ieee80211_vif *vif,
3880 struct ieee80211_bss_conf *bss_conf,
3881 u32 changed)
3882{
3883 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003884 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3885 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003886 int ret;
3887
3888 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3889 (int)changed);
3890
3891 mutex_lock(&wl->mutex);
3892
3893 if (unlikely(wl->state == WL1271_STATE_OFF))
3894 goto out;
3895
Eliad Peller10c8cd02011-10-10 10:13:06 +02003896 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3897 goto out;
3898
Ido Yariva6208652011-03-01 15:14:41 +02003899 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003900 if (ret < 0)
3901 goto out;
3902
3903 if (is_ap)
3904 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3905 else
3906 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3907
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003908 wl1271_ps_elp_sleep(wl);
3909
3910out:
3911 mutex_unlock(&wl->mutex);
3912}
3913
Eliad Peller8a3a3c82011-10-02 10:15:52 +02003914static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3915 struct ieee80211_vif *vif, u16 queue,
Kalle Valoc6999d82010-02-18 13:25:41 +02003916 const struct ieee80211_tx_queue_params *params)
3917{
3918 struct wl1271 *wl = hw->priv;
Eliad Peller0603d892011-10-05 11:55:51 +02003919 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo4695dc92010-03-18 12:26:38 +02003920 u8 ps_scheme;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003921 int ret = 0;
Kalle Valoc6999d82010-02-18 13:25:41 +02003922
3923 mutex_lock(&wl->mutex);
3924
3925 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
3926
Kalle Valo4695dc92010-03-18 12:26:38 +02003927 if (params->uapsd)
3928 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
3929 else
3930 ps_scheme = CONF_PS_SCHEME_LEGACY;
3931
Eliad Peller5b37ddf2011-12-18 20:25:40 +02003932 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003933 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003934
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003935 ret = wl1271_ps_elp_wakeup(wl);
3936 if (ret < 0)
3937 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02003938
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003939 /*
3940 * the txop is confed in units of 32us by the mac80211,
3941 * we need us
3942 */
Eliad Peller0603d892011-10-05 11:55:51 +02003943 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003944 params->cw_min, params->cw_max,
3945 params->aifs, params->txop << 5);
3946 if (ret < 0)
3947 goto out_sleep;
3948
Eliad Peller0603d892011-10-05 11:55:51 +02003949 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003950 CONF_CHANNEL_TYPE_EDCF,
3951 wl1271_tx_get_queue(queue),
3952 ps_scheme, CONF_ACK_POLICY_LEGACY,
3953 0, 0);
Kalle Valoc82c1dd2010-02-18 13:25:47 +02003954
3955out_sleep:
Eliad Pellerc1b193e2011-03-23 22:22:15 +02003956 wl1271_ps_elp_sleep(wl);
Kalle Valoc6999d82010-02-18 13:25:41 +02003957
3958out:
3959 mutex_unlock(&wl->mutex);
3960
3961 return ret;
3962}
3963
Eliad Peller37a41b42011-09-21 14:06:11 +03003964static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
3965 struct ieee80211_vif *vif)
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003966{
3967
3968 struct wl1271 *wl = hw->priv;
Eliad Peller9c531142012-01-31 11:57:18 +02003969 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003970 u64 mactime = ULLONG_MAX;
3971 int ret;
3972
3973 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
3974
3975 mutex_lock(&wl->mutex);
3976
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003977 if (unlikely(wl->state == WL1271_STATE_OFF))
3978 goto out;
3979
Ido Yariva6208652011-03-01 15:14:41 +02003980 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003981 if (ret < 0)
3982 goto out;
3983
Eliad Peller9c531142012-01-31 11:57:18 +02003984 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03003985 if (ret < 0)
3986 goto out_sleep;
3987
3988out_sleep:
3989 wl1271_ps_elp_sleep(wl);
3990
3991out:
3992 mutex_unlock(&wl->mutex);
3993 return mactime;
3994}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003995
John W. Linvilleece550d2010-07-28 16:41:06 -04003996static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3997 struct survey_info *survey)
3998{
3999 struct wl1271 *wl = hw->priv;
4000 struct ieee80211_conf *conf = &hw->conf;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004001
John W. Linvilleece550d2010-07-28 16:41:06 -04004002 if (idx != 0)
4003 return -ENOENT;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004004
John W. Linvilleece550d2010-07-28 16:41:06 -04004005 survey->channel = conf->channel;
4006 survey->filled = SURVEY_INFO_NOISE_DBM;
4007 survey->noise = wl->noise;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004008
John W. Linvilleece550d2010-07-28 16:41:06 -04004009 return 0;
4010}
4011
Arik Nemtsov409622e2011-02-23 00:22:29 +02004012static int wl1271_allocate_sta(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004013 struct wl12xx_vif *wlvif,
4014 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004015{
4016 struct wl1271_station *wl_sta;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004017 int ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004018
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004019
4020 if (wl->active_sta_count >= AP_MAX_STATIONS) {
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004021 wl1271_warning("could not allocate HLID - too much stations");
4022 return -EBUSY;
4023 }
4024
4025 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004026 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4027 if (ret < 0) {
4028 wl1271_warning("could not allocate HLID - too many links");
4029 return -EBUSY;
4030 }
4031
4032 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004033 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
Arik Nemtsovda032092011-08-25 12:43:15 +03004034 wl->active_sta_count++;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004035 return 0;
4036}
4037
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004038void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004039{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004040 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
Arik Nemtsovf1acea92011-08-25 12:43:17 +03004041 return;
4042
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004043 clear_bit(hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004044 memset(wl->links[hlid].addr, 0, ETH_ALEN);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004045 wl->links[hlid].ba_bitmap = 0;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02004046 wl1271_tx_reset_link_queues(wl, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004047 __clear_bit(hlid, &wl->ap_ps_map);
4048 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004049 wl12xx_free_link(wl, wlvif, &hlid);
Arik Nemtsovda032092011-08-25 12:43:15 +03004050 wl->active_sta_count--;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004051}
4052
4053static int wl1271_op_sta_add(struct ieee80211_hw *hw,
4054 struct ieee80211_vif *vif,
4055 struct ieee80211_sta *sta)
4056{
4057 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004058 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004059 struct wl1271_station *wl_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004060 int ret = 0;
4061 u8 hlid;
4062
4063 mutex_lock(&wl->mutex);
4064
4065 if (unlikely(wl->state == WL1271_STATE_OFF))
4066 goto out;
4067
Eliad Peller536129c2011-10-05 11:55:45 +02004068 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004069 goto out;
4070
4071 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4072
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004073 ret = wl1271_allocate_sta(wl, wlvif, sta);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004074 if (ret < 0)
4075 goto out;
4076
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004077 wl_sta = (struct wl1271_station *)sta->drv_priv;
4078 hlid = wl_sta->hlid;
4079
Ido Yariva6208652011-03-01 15:14:41 +02004080 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004081 if (ret < 0)
Arik Nemtsov409622e2011-02-23 00:22:29 +02004082 goto out_free_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004083
Eliad Peller1b92f152011-10-10 10:13:09 +02004084 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004085 if (ret < 0)
4086 goto out_sleep;
4087
Eliad Pellerb67476e2011-08-14 13:17:23 +03004088 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4089 if (ret < 0)
4090 goto out_sleep;
4091
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03004092 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, hlid);
4093 if (ret < 0)
4094 goto out_sleep;
4095
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004096out_sleep:
4097 wl1271_ps_elp_sleep(wl);
4098
Arik Nemtsov409622e2011-02-23 00:22:29 +02004099out_free_sta:
4100 if (ret < 0)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004101 wl1271_free_sta(wl, wlvif, hlid);
Arik Nemtsov409622e2011-02-23 00:22:29 +02004102
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004103out:
4104 mutex_unlock(&wl->mutex);
4105 return ret;
4106}
4107
4108static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
4109 struct ieee80211_vif *vif,
4110 struct ieee80211_sta *sta)
4111{
4112 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004113 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004114 struct wl1271_station *wl_sta;
4115 int ret = 0, id;
4116
4117 mutex_lock(&wl->mutex);
4118
4119 if (unlikely(wl->state == WL1271_STATE_OFF))
4120 goto out;
4121
Eliad Peller536129c2011-10-05 11:55:45 +02004122 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004123 goto out;
4124
4125 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4126
4127 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004128 id = wl_sta->hlid;
4129 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004130 goto out;
4131
Ido Yariva6208652011-03-01 15:14:41 +02004132 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004133 if (ret < 0)
4134 goto out;
4135
Eliad Pellerc690ec82011-08-14 13:17:07 +03004136 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004137 if (ret < 0)
4138 goto out_sleep;
4139
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004140 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004141
4142out_sleep:
4143 wl1271_ps_elp_sleep(wl);
4144
4145out:
4146 mutex_unlock(&wl->mutex);
4147 return ret;
4148}
4149
Luciano Coelho4623ec72011-03-21 19:26:41 +02004150static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4151 struct ieee80211_vif *vif,
4152 enum ieee80211_ampdu_mlme_action action,
4153 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4154 u8 buf_size)
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004155{
4156 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004157 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004158 int ret;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004159 u8 hlid, *ba_bitmap;
4160
4161 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4162 tid);
4163
4164 /* sanity check - the fields in FW are only 8bits wide */
4165 if (WARN_ON(tid > 0xFF))
4166 return -ENOTSUPP;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004167
4168 mutex_lock(&wl->mutex);
4169
4170 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4171 ret = -EAGAIN;
4172 goto out;
4173 }
4174
Eliad Peller536129c2011-10-05 11:55:45 +02004175 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
Eliad Peller154da672011-10-05 11:55:53 +02004176 hlid = wlvif->sta.hlid;
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004177 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
Eliad Peller536129c2011-10-05 11:55:45 +02004178 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004179 struct wl1271_station *wl_sta;
4180
4181 wl_sta = (struct wl1271_station *)sta->drv_priv;
4182 hlid = wl_sta->hlid;
4183 ba_bitmap = &wl->links[hlid].ba_bitmap;
4184 } else {
4185 ret = -EINVAL;
4186 goto out;
4187 }
4188
Ido Yariva6208652011-03-01 15:14:41 +02004189 ret = wl1271_ps_elp_wakeup(wl);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004190 if (ret < 0)
4191 goto out;
4192
Shahar Levi70559a02011-05-22 16:10:22 +03004193 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4194 tid, action);
4195
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004196 switch (action) {
4197 case IEEE80211_AMPDU_RX_START:
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004198 if (!wlvif->ba_support || !wlvif->ba_allowed) {
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004199 ret = -ENOTSUPP;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004200 break;
4201 }
4202
4203 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4204 ret = -EBUSY;
4205 wl1271_error("exceeded max RX BA sessions");
4206 break;
4207 }
4208
4209 if (*ba_bitmap & BIT(tid)) {
4210 ret = -EINVAL;
4211 wl1271_error("cannot enable RX BA session on active "
4212 "tid: %d", tid);
4213 break;
4214 }
4215
4216 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4217 hlid);
4218 if (!ret) {
4219 *ba_bitmap |= BIT(tid);
4220 wl->ba_rx_session_count++;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004221 }
4222 break;
4223
4224 case IEEE80211_AMPDU_RX_STOP:
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004225 if (!(*ba_bitmap & BIT(tid))) {
4226 ret = -EINVAL;
4227 wl1271_error("no active RX BA session on tid: %d",
4228 tid);
4229 break;
4230 }
4231
4232 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4233 hlid);
4234 if (!ret) {
4235 *ba_bitmap &= ~BIT(tid);
4236 wl->ba_rx_session_count--;
4237 }
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004238 break;
4239
4240 /*
4241 * The BA initiator session management in FW independently.
4242 * Falling break here on purpose for all TX APDU commands.
4243 */
4244 case IEEE80211_AMPDU_TX_START:
4245 case IEEE80211_AMPDU_TX_STOP:
4246 case IEEE80211_AMPDU_TX_OPERATIONAL:
4247 ret = -EINVAL;
4248 break;
4249
4250 default:
4251 wl1271_error("Incorrect ampdu action id=%x\n", action);
4252 ret = -EINVAL;
4253 }
4254
4255 wl1271_ps_elp_sleep(wl);
4256
4257out:
4258 mutex_unlock(&wl->mutex);
4259
4260 return ret;
4261}
4262
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004263static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4264 struct ieee80211_vif *vif,
4265 const struct cfg80211_bitrate_mask *mask)
4266{
Eliad Peller83587502011-10-10 10:12:53 +02004267 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004268 struct wl1271 *wl = hw->priv;
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004269 int i, ret = 0;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004270
4271 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4272 mask->control[NL80211_BAND_2GHZ].legacy,
4273 mask->control[NL80211_BAND_5GHZ].legacy);
4274
4275 mutex_lock(&wl->mutex);
4276
4277 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Eliad Peller83587502011-10-10 10:12:53 +02004278 wlvif->bitrate_masks[i] =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004279 wl1271_tx_enabled_rates_get(wl,
4280 mask->control[i].legacy,
4281 i);
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004282
4283 if (unlikely(wl->state == WL1271_STATE_OFF))
4284 goto out;
4285
4286 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4287 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4288
4289 ret = wl1271_ps_elp_wakeup(wl);
4290 if (ret < 0)
4291 goto out;
4292
4293 wl1271_set_band_rate(wl, wlvif);
4294 wlvif->basic_rate =
4295 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4296 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4297
4298 wl1271_ps_elp_sleep(wl);
4299 }
4300out:
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004301 mutex_unlock(&wl->mutex);
4302
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004303 return ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004304}
4305
Shahar Levi6d158ff2011-09-08 13:01:33 +03004306static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4307 struct ieee80211_channel_switch *ch_switch)
4308{
4309 struct wl1271 *wl = hw->priv;
Eliad Peller52630c52011-10-10 10:13:08 +02004310 struct wl12xx_vif *wlvif;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004311 int ret;
4312
4313 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4314
4315 mutex_lock(&wl->mutex);
4316
4317 if (unlikely(wl->state == WL1271_STATE_OFF)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02004318 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4319 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4320 ieee80211_chswitch_done(vif, false);
4321 }
4322 goto out;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004323 }
4324
4325 ret = wl1271_ps_elp_wakeup(wl);
4326 if (ret < 0)
4327 goto out;
4328
Eliad Peller52630c52011-10-10 10:13:08 +02004329 /* TODO: change mac80211 to pass vif as param */
4330 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller8332f0f2012-01-31 11:57:19 +02004331 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
Shahar Levi6d158ff2011-09-08 13:01:33 +03004332
Eliad Peller52630c52011-10-10 10:13:08 +02004333 if (!ret)
4334 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4335 }
Shahar Levi6d158ff2011-09-08 13:01:33 +03004336
4337 wl1271_ps_elp_sleep(wl);
4338
4339out:
4340 mutex_unlock(&wl->mutex);
4341}
4342
Arik Nemtsov33437892011-04-26 23:35:39 +03004343static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4344{
4345 struct wl1271 *wl = hw->priv;
4346 bool ret = false;
4347
4348 mutex_lock(&wl->mutex);
4349
4350 if (unlikely(wl->state == WL1271_STATE_OFF))
4351 goto out;
4352
4353 /* packets are considered pending if in the TX queue or the FW */
Arik Nemtsovf1a46382011-07-07 14:25:23 +03004354 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
Arik Nemtsov33437892011-04-26 23:35:39 +03004355out:
4356 mutex_unlock(&wl->mutex);
4357
4358 return ret;
4359}
4360
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004361/* can't be const, mac80211 writes to this */
4362static struct ieee80211_rate wl1271_rates[] = {
4363 { .bitrate = 10,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004364 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4365 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004366 { .bitrate = 20,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004367 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4368 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004369 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4370 { .bitrate = 55,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004371 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4372 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004373 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4374 { .bitrate = 110,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004375 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4376 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004377 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4378 { .bitrate = 60,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004379 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4380 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004381 { .bitrate = 90,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004382 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4383 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004384 { .bitrate = 120,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004385 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4386 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004387 { .bitrate = 180,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004388 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4389 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004390 { .bitrate = 240,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004391 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4392 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004393 { .bitrate = 360,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004394 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4395 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004396 { .bitrate = 480,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004397 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4398 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004399 { .bitrate = 540,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004400 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4401 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004402};
4403
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004404/* can't be const, mac80211 writes to this */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004405static struct ieee80211_channel wl1271_channels[] = {
Luciano Coelhoa2d0e3f2009-12-11 15:40:46 +02004406 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004407 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004408 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4409 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4410 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004411 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004412 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4413 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4414 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004415 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004416 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4417 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4418 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
Arik Nemtsov6c89b7b2011-01-18 20:39:52 +01004419 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004420};
4421
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004422/* mapping to indexes for wl1271_rates */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004423static const u8 wl1271_rate_to_idx_2ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004424 /* MCS rates are used only with 11n */
Shahar Levi18357852010-10-13 16:09:41 +02004425 7, /* CONF_HW_RXTX_RATE_MCS7 */
4426 6, /* CONF_HW_RXTX_RATE_MCS6 */
4427 5, /* CONF_HW_RXTX_RATE_MCS5 */
4428 4, /* CONF_HW_RXTX_RATE_MCS4 */
4429 3, /* CONF_HW_RXTX_RATE_MCS3 */
4430 2, /* CONF_HW_RXTX_RATE_MCS2 */
4431 1, /* CONF_HW_RXTX_RATE_MCS1 */
4432 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004433
4434 11, /* CONF_HW_RXTX_RATE_54 */
4435 10, /* CONF_HW_RXTX_RATE_48 */
4436 9, /* CONF_HW_RXTX_RATE_36 */
4437 8, /* CONF_HW_RXTX_RATE_24 */
4438
4439 /* TI-specific rate */
4440 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4441
4442 7, /* CONF_HW_RXTX_RATE_18 */
4443 6, /* CONF_HW_RXTX_RATE_12 */
4444 3, /* CONF_HW_RXTX_RATE_11 */
4445 5, /* CONF_HW_RXTX_RATE_9 */
4446 4, /* CONF_HW_RXTX_RATE_6 */
4447 2, /* CONF_HW_RXTX_RATE_5_5 */
4448 1, /* CONF_HW_RXTX_RATE_2 */
4449 0 /* CONF_HW_RXTX_RATE_1 */
4450};
4451
Shahar Levie8b03a22010-10-13 16:09:39 +02004452/* 11n STA capabilities */
4453#define HW_RX_HIGHEST_RATE 72
4454
Shahar Levi00d20102010-11-08 11:20:10 +00004455#define WL12XX_HT_CAP { \
Shahar Levi871d0c32011-03-13 11:24:40 +02004456 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4457 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
Shahar Levie8b03a22010-10-13 16:09:39 +02004458 .ht_supported = true, \
4459 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4460 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4461 .mcs = { \
4462 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4463 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4464 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4465 }, \
4466}
4467
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004468/* can't be const, mac80211 writes to this */
4469static struct ieee80211_supported_band wl1271_band_2ghz = {
4470 .channels = wl1271_channels,
4471 .n_channels = ARRAY_SIZE(wl1271_channels),
4472 .bitrates = wl1271_rates,
4473 .n_bitrates = ARRAY_SIZE(wl1271_rates),
Shahar Levi00d20102010-11-08 11:20:10 +00004474 .ht_cap = WL12XX_HT_CAP,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004475};
4476
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004477/* 5 GHz data rates for WL1273 */
4478static struct ieee80211_rate wl1271_rates_5ghz[] = {
4479 { .bitrate = 60,
4480 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4481 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4482 { .bitrate = 90,
4483 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4484 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4485 { .bitrate = 120,
4486 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4487 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4488 { .bitrate = 180,
4489 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4490 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4491 { .bitrate = 240,
4492 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4493 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4494 { .bitrate = 360,
4495 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4496 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4497 { .bitrate = 480,
4498 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4499 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4500 { .bitrate = 540,
4501 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4502 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4503};
4504
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004505/* 5 GHz band channels for WL1273 */
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004506static struct ieee80211_channel wl1271_channels_5ghz[] = {
Arik Nemtsov6cfa5cf2011-06-27 22:06:33 +03004507 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4508 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4509 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4510 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4511 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4512 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4513 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4514 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4515 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4516 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4517 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4518 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4519 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4520 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4521 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4522 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4523 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4524 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4525 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4526 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4527 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4528 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4529 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4530 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4531 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4532 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4533 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4534 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4535 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4536 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4537 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4538 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4539 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4540 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004541};
4542
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004543/* mapping to indexes for wl1271_rates_5ghz */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004544static const u8 wl1271_rate_to_idx_5ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004545 /* MCS rates are used only with 11n */
Shahar Levi18357852010-10-13 16:09:41 +02004546 7, /* CONF_HW_RXTX_RATE_MCS7 */
4547 6, /* CONF_HW_RXTX_RATE_MCS6 */
4548 5, /* CONF_HW_RXTX_RATE_MCS5 */
4549 4, /* CONF_HW_RXTX_RATE_MCS4 */
4550 3, /* CONF_HW_RXTX_RATE_MCS3 */
4551 2, /* CONF_HW_RXTX_RATE_MCS2 */
4552 1, /* CONF_HW_RXTX_RATE_MCS1 */
4553 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004554
4555 7, /* CONF_HW_RXTX_RATE_54 */
4556 6, /* CONF_HW_RXTX_RATE_48 */
4557 5, /* CONF_HW_RXTX_RATE_36 */
4558 4, /* CONF_HW_RXTX_RATE_24 */
4559
4560 /* TI-specific rate */
4561 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4562
4563 3, /* CONF_HW_RXTX_RATE_18 */
4564 2, /* CONF_HW_RXTX_RATE_12 */
4565 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4566 1, /* CONF_HW_RXTX_RATE_9 */
4567 0, /* CONF_HW_RXTX_RATE_6 */
4568 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4569 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4570 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4571};
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004572
4573static struct ieee80211_supported_band wl1271_band_5ghz = {
4574 .channels = wl1271_channels_5ghz,
4575 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4576 .bitrates = wl1271_rates_5ghz,
4577 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
Shahar Levi00d20102010-11-08 11:20:10 +00004578 .ht_cap = WL12XX_HT_CAP,
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004579};
4580
Tobias Klausera0ea9492010-05-20 10:38:11 +02004581static const u8 *wl1271_band_rate_to_idx[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004582 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4583 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4584};
4585
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004586static const struct ieee80211_ops wl1271_ops = {
4587 .start = wl1271_op_start,
4588 .stop = wl1271_op_stop,
4589 .add_interface = wl1271_op_add_interface,
4590 .remove_interface = wl1271_op_remove_interface,
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02004591 .change_interface = wl12xx_op_change_interface,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004592#ifdef CONFIG_PM
Eliad Peller402e48612011-05-13 11:57:09 +03004593 .suspend = wl1271_op_suspend,
4594 .resume = wl1271_op_resume,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004595#endif
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004596 .config = wl1271_op_config,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03004597 .prepare_multicast = wl1271_op_prepare_multicast,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004598 .configure_filter = wl1271_op_configure_filter,
4599 .tx = wl1271_op_tx,
4600 .set_key = wl1271_op_set_key,
4601 .hw_scan = wl1271_op_hw_scan,
Eliad Peller73ecce32011-06-27 13:06:45 +03004602 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
Luciano Coelho33c2c062011-05-10 14:46:02 +03004603 .sched_scan_start = wl1271_op_sched_scan_start,
4604 .sched_scan_stop = wl1271_op_sched_scan_stop,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004605 .bss_info_changed = wl1271_op_bss_info_changed,
Arik Nemtsov68d069c2010-11-08 10:51:07 +01004606 .set_frag_threshold = wl1271_op_set_frag_threshold,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004607 .set_rts_threshold = wl1271_op_set_rts_threshold,
Kalle Valoc6999d82010-02-18 13:25:41 +02004608 .conf_tx = wl1271_op_conf_tx,
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004609 .get_tsf = wl1271_op_get_tsf,
John W. Linvilleece550d2010-07-28 16:41:06 -04004610 .get_survey = wl1271_op_get_survey,
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004611 .sta_add = wl1271_op_sta_add,
4612 .sta_remove = wl1271_op_sta_remove,
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004613 .ampdu_action = wl1271_op_ampdu_action,
Arik Nemtsov33437892011-04-26 23:35:39 +03004614 .tx_frames_pending = wl1271_tx_frames_pending,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004615 .set_bitrate_mask = wl12xx_set_bitrate_mask,
Shahar Levi6d158ff2011-09-08 13:01:33 +03004616 .channel_switch = wl12xx_op_channel_switch,
Kalle Valoc8c90872010-02-18 13:25:53 +02004617 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004618};
4619
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004620
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004621u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004622{
4623 u8 idx;
4624
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004625 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004626
4627 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4628 wl1271_error("Illegal RX rate from HW: %d", rate);
4629 return 0;
4630 }
4631
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004632 idx = wl1271_band_rate_to_idx[band][rate];
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004633 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4634 wl1271_error("Unsupported RX rate from HW: %d", rate);
4635 return 0;
4636 }
4637
4638 return idx;
4639}
4640
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004641static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4642 struct device_attribute *attr,
4643 char *buf)
4644{
4645 struct wl1271 *wl = dev_get_drvdata(dev);
4646 ssize_t len;
4647
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004648 len = PAGE_SIZE;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004649
4650 mutex_lock(&wl->mutex);
4651 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4652 wl->sg_enabled);
4653 mutex_unlock(&wl->mutex);
4654
4655 return len;
4656
4657}
4658
4659static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4660 struct device_attribute *attr,
4661 const char *buf, size_t count)
4662{
4663 struct wl1271 *wl = dev_get_drvdata(dev);
4664 unsigned long res;
4665 int ret;
4666
Luciano Coelho6277ed62011-04-01 17:49:54 +03004667 ret = kstrtoul(buf, 10, &res);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004668 if (ret < 0) {
4669 wl1271_warning("incorrect value written to bt_coex_mode");
4670 return count;
4671 }
4672
4673 mutex_lock(&wl->mutex);
4674
4675 res = !!res;
4676
4677 if (res == wl->sg_enabled)
4678 goto out;
4679
4680 wl->sg_enabled = res;
4681
4682 if (wl->state == WL1271_STATE_OFF)
4683 goto out;
4684
Ido Yariva6208652011-03-01 15:14:41 +02004685 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004686 if (ret < 0)
4687 goto out;
4688
4689 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4690 wl1271_ps_elp_sleep(wl);
4691
4692 out:
4693 mutex_unlock(&wl->mutex);
4694 return count;
4695}
4696
4697static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4698 wl1271_sysfs_show_bt_coex_state,
4699 wl1271_sysfs_store_bt_coex_state);
4700
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004701static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4702 struct device_attribute *attr,
4703 char *buf)
4704{
4705 struct wl1271 *wl = dev_get_drvdata(dev);
4706 ssize_t len;
4707
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004708 len = PAGE_SIZE;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004709
4710 mutex_lock(&wl->mutex);
4711 if (wl->hw_pg_ver >= 0)
4712 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4713 else
4714 len = snprintf(buf, len, "n/a\n");
4715 mutex_unlock(&wl->mutex);
4716
4717 return len;
4718}
4719
Gery Kahn6f07b722011-07-18 14:21:49 +03004720static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004721 wl1271_sysfs_show_hw_pg_ver, NULL);
4722
Ido Yariv95dac04f2011-06-06 14:57:06 +03004723static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4724 struct bin_attribute *bin_attr,
4725 char *buffer, loff_t pos, size_t count)
4726{
4727 struct device *dev = container_of(kobj, struct device, kobj);
4728 struct wl1271 *wl = dev_get_drvdata(dev);
4729 ssize_t len;
4730 int ret;
4731
4732 ret = mutex_lock_interruptible(&wl->mutex);
4733 if (ret < 0)
4734 return -ERESTARTSYS;
4735
4736 /* Let only one thread read the log at a time, blocking others */
4737 while (wl->fwlog_size == 0) {
4738 DEFINE_WAIT(wait);
4739
4740 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4741 &wait,
4742 TASK_INTERRUPTIBLE);
4743
4744 if (wl->fwlog_size != 0) {
4745 finish_wait(&wl->fwlog_waitq, &wait);
4746 break;
4747 }
4748
4749 mutex_unlock(&wl->mutex);
4750
4751 schedule();
4752 finish_wait(&wl->fwlog_waitq, &wait);
4753
4754 if (signal_pending(current))
4755 return -ERESTARTSYS;
4756
4757 ret = mutex_lock_interruptible(&wl->mutex);
4758 if (ret < 0)
4759 return -ERESTARTSYS;
4760 }
4761
4762 /* Check if the fwlog is still valid */
4763 if (wl->fwlog_size < 0) {
4764 mutex_unlock(&wl->mutex);
4765 return 0;
4766 }
4767
4768 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4769 len = min(count, (size_t)wl->fwlog_size);
4770 wl->fwlog_size -= len;
4771 memcpy(buffer, wl->fwlog, len);
4772
4773 /* Make room for new messages */
4774 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4775
4776 mutex_unlock(&wl->mutex);
4777
4778 return len;
4779}
4780
4781static struct bin_attribute fwlog_attr = {
4782 .attr = {.name = "fwlog", .mode = S_IRUSR},
4783 .read = wl1271_sysfs_read_fwlog,
4784};
4785
Luciano Coelho5e037e72011-12-23 09:32:17 +02004786static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4787{
4788 bool supported = false;
4789 u8 major, minor;
4790
4791 if (wl->chip.id == CHIP_ID_1283_PG20) {
4792 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
4793 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
4794
4795 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
4796 if (major > 2 || (major == 2 && minor >= 1))
4797 supported = true;
4798 } else {
4799 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
4800 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
4801
4802 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
4803 if (major == 3 && minor >= 1)
4804 supported = true;
4805 }
4806
4807 wl1271_debug(DEBUG_PROBE,
4808 "PG Ver major = %d minor = %d, MAC %s present",
4809 major, minor, supported ? "is" : "is not");
4810
4811 return supported;
4812}
4813
4814static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4815 u32 oui, u32 nic, int n)
4816{
4817 int i;
4818
4819 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
4820 oui, nic, n);
4821
4822 if (nic + n - 1 > 0xffffff)
4823 wl1271_warning("NIC part of the MAC address wraps around!");
4824
4825 for (i = 0; i < n; i++) {
4826 wl->addresses[i].addr[0] = (u8)(oui >> 16);
4827 wl->addresses[i].addr[1] = (u8)(oui >> 8);
4828 wl->addresses[i].addr[2] = (u8) oui;
4829 wl->addresses[i].addr[3] = (u8)(nic >> 16);
4830 wl->addresses[i].addr[4] = (u8)(nic >> 8);
4831 wl->addresses[i].addr[5] = (u8) nic;
4832 nic++;
4833 }
4834
4835 wl->hw->wiphy->n_addresses = n;
4836 wl->hw->wiphy->addresses = wl->addresses;
4837}
4838
4839static void wl12xx_get_fuse_mac(struct wl1271 *wl)
4840{
4841 u32 mac1, mac2;
4842
4843 wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
4844
4845 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
4846 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
4847
4848 /* these are the two parts of the BD_ADDR */
4849 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
4850 ((mac1 & 0xff000000) >> 24);
4851 wl->fuse_nic_addr = mac1 & 0xffffff;
4852
4853 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
4854}
4855
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004856static int wl12xx_get_hw_info(struct wl1271 *wl)
4857{
4858 int ret;
4859 u32 die_info;
4860
4861 ret = wl12xx_set_power_on(wl);
4862 if (ret < 0)
4863 goto out;
4864
4865 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
4866
4867 if (wl->chip.id == CHIP_ID_1283_PG20)
4868 die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
4869 else
4870 die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
4871
4872 wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
4873
Luciano Coelho5e037e72011-12-23 09:32:17 +02004874 if (!wl12xx_mac_in_fuse(wl)) {
4875 wl->fuse_oui_addr = 0;
4876 wl->fuse_nic_addr = 0;
4877 } else {
4878 wl12xx_get_fuse_mac(wl);
4879 }
4880
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004881 wl1271_power_off(wl);
4882out:
4883 return ret;
4884}
4885
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004886static int wl1271_register_hw(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004887{
4888 int ret;
Luciano Coelho5e037e72011-12-23 09:32:17 +02004889 u32 oui_addr = 0, nic_addr = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004890
4891 if (wl->mac80211_registered)
4892 return 0;
4893
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004894 ret = wl12xx_get_hw_info(wl);
4895 if (ret < 0) {
4896 wl1271_error("couldn't get hw info");
4897 goto out;
4898 }
4899
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004900 ret = wl1271_fetch_nvs(wl);
4901 if (ret == 0) {
Shahar Levibc765bf2011-03-06 16:32:10 +02004902 /* NOTE: The wl->nvs->nvs element must be first, in
4903 * order to simplify the casting, we assume it is at
4904 * the beginning of the wl->nvs structure.
4905 */
4906 u8 *nvs_ptr = (u8 *)wl->nvs;
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004907
Luciano Coelho5e037e72011-12-23 09:32:17 +02004908 oui_addr =
4909 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
4910 nic_addr =
4911 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02004912 }
4913
Luciano Coelho5e037e72011-12-23 09:32:17 +02004914 /* if the MAC address is zeroed in the NVS derive from fuse */
4915 if (oui_addr == 0 && nic_addr == 0) {
4916 oui_addr = wl->fuse_oui_addr;
4917 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
4918 nic_addr = wl->fuse_nic_addr + 1;
4919 }
4920
4921 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004922
4923 ret = ieee80211_register_hw(wl->hw);
4924 if (ret < 0) {
4925 wl1271_error("unable to register mac80211 hw: %d", ret);
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004926 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004927 }
4928
4929 wl->mac80211_registered = true;
4930
Eliad Pellerd60080a2010-11-24 12:53:16 +02004931 wl1271_debugfs_init(wl);
4932
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03004933 register_netdevice_notifier(&wl1271_dev_notifier);
4934
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004935 wl1271_notice("loaded");
4936
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004937out:
4938 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004939}
4940
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004941static void wl1271_unregister_hw(struct wl1271 *wl)
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004942{
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01004943 if (wl->state == WL1271_STATE_PLT)
Ido Yarivf3df1332012-01-11 09:42:39 +02004944 wl1271_plt_stop(wl);
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01004945
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +03004946 unregister_netdevice_notifier(&wl1271_dev_notifier);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004947 ieee80211_unregister_hw(wl->hw);
4948 wl->mac80211_registered = false;
4949
4950}
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02004951
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03004952static int wl1271_init_ieee80211(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004953{
Juuso Oikarinen7a557242010-09-27 12:42:07 +02004954 static const u32 cipher_suites[] = {
4955 WLAN_CIPHER_SUITE_WEP40,
4956 WLAN_CIPHER_SUITE_WEP104,
4957 WLAN_CIPHER_SUITE_TKIP,
4958 WLAN_CIPHER_SUITE_CCMP,
4959 WL1271_CIPHER_SUITE_GEM,
4960 };
4961
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03004962 /* The tx descriptor buffer and the TKIP space. */
4963 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
4964 sizeof(struct wl1271_tx_hw_descr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004965
4966 /* unit us */
4967 /* FIXME: find a proper value */
4968 wl->hw->channel_change_time = 10000;
Juuso Oikarinen50c500a2010-04-01 11:38:22 +03004969 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004970
4971 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
Juuso Oikarinen0a343322010-02-22 08:38:41 +02004972 IEEE80211_HW_SUPPORTS_PS |
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02004973 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo4695dc92010-03-18 12:26:38 +02004974 IEEE80211_HW_SUPPORTS_UAPSD |
Juuso Oikarinena9af0922010-03-26 12:53:30 +02004975 IEEE80211_HW_HAS_RATE_CONTROL |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03004976 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelho25eaea302011-05-02 12:37:33 +03004977 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Shahar Levifcd23b62011-05-11 12:12:56 +03004978 IEEE80211_HW_SPECTRUM_MGMT |
Arik Nemtsov93f8c8e2011-08-30 09:34:01 +03004979 IEEE80211_HW_AP_LINK_PS |
4980 IEEE80211_HW_AMPDU_AGGREGATION |
4981 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004982
Juuso Oikarinen7a557242010-09-27 12:42:07 +02004983 wl->hw->wiphy->cipher_suites = cipher_suites;
4984 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
4985
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02004986 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Eliad Peller045c7452011-08-28 15:23:01 +03004987 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
4988 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004989 wl->hw->wiphy->max_scan_ssids = 1;
Luciano Coelho221737d2011-09-02 14:28:22 +03004990 wl->hw->wiphy->max_sched_scan_ssids = 16;
4991 wl->hw->wiphy->max_match_sets = 16;
Guy Eilamea559b42010-12-09 16:54:59 +02004992 /*
4993 * Maximum length of elements in scanning probe request templates
4994 * should be the maximum length possible for a template, without
4995 * the IEEE80211 header of the template
4996 */
Eliad Peller154037d2011-08-14 13:17:12 +03004997 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_DFLT_SIZE -
Guy Eilamea559b42010-12-09 16:54:59 +02004998 sizeof(struct ieee80211_header);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01004999
Luciano Coelhoc9e79a42011-09-27 16:22:35 +03005000 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_DFLT_SIZE -
5001 sizeof(struct ieee80211_header);
5002
Eliad Peller1ec23f72011-08-25 14:26:54 +03005003 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5004
Luciano Coelho4a31c112011-03-21 23:16:14 +02005005 /* make sure all our channels fit in the scanned_ch bitmask */
5006 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
5007 ARRAY_SIZE(wl1271_channels_5ghz) >
5008 WL1271_MAX_CHANNELS);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005009 /*
5010 * We keep local copies of the band structs because we need to
5011 * modify them on a per-device basis.
5012 */
5013 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5014 sizeof(wl1271_band_2ghz));
5015 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5016 sizeof(wl1271_band_5ghz));
5017
5018 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5019 &wl->bands[IEEE80211_BAND_2GHZ];
5020 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5021 &wl->bands[IEEE80211_BAND_5GHZ];
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03005022
Kalle Valo12bd8942010-03-18 12:26:33 +02005023 wl->hw->queues = 4;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +02005024 wl->hw->max_rates = 1;
Kalle Valo12bd8942010-03-18 12:26:33 +02005025
Juuso Oikarinenb7417d92010-11-10 11:27:19 +01005026 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5027
Arik Nemtsov9c1b1902011-11-08 18:46:55 +02005028 /* the FW answers probe-requests in AP-mode */
5029 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5030 wl->hw->wiphy->probe_resp_offload =
5031 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5032 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5033 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5034
Felipe Balbia390e852011-10-06 10:07:44 +03005035 SET_IEEE80211_DEV(wl->hw, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005036
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005037 wl->hw->sta_data_size = sizeof(struct wl1271_station);
Eliad Peller87fbcb02011-10-05 11:55:41 +02005038 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005039
Luciano Coelho4c9cfa72011-01-12 14:27:03 +01005040 wl->hw->max_rx_aggregation_subframes = 8;
5041
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005042 return 0;
5043}
5044
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005045#define WL1271_DEFAULT_CHANNEL 0
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005046
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005047static struct ieee80211_hw *wl1271_alloc_hw(void)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005048{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005049 struct ieee80211_hw *hw;
5050 struct wl1271 *wl;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005051 int i, j, ret;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005052 unsigned int order;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005053
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005054 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
Arik Nemtsovf80c2d12011-09-22 09:52:05 +03005055
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005056 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5057 if (!hw) {
5058 wl1271_error("could not alloc ieee80211_hw");
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005059 ret = -ENOMEM;
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005060 goto err_hw_alloc;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005061 }
5062
5063 wl = hw->priv;
5064 memset(wl, 0, sizeof(*wl));
5065
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005066 INIT_LIST_HEAD(&wl->list);
Eliad Peller87627212011-10-10 10:12:54 +02005067 INIT_LIST_HEAD(&wl->wlvif_list);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005068
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005069 wl->hw = hw;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005070
Juuso Oikarinen6742f552010-12-13 09:52:37 +02005071 for (i = 0; i < NUM_TX_QUEUES; i++)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005072 for (j = 0; j < WL12XX_MAX_LINKS; j++)
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005073 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5074
Ido Yariva6208652011-03-01 15:14:41 +02005075 skb_queue_head_init(&wl->deferred_rx_queue);
5076 skb_queue_head_init(&wl->deferred_tx_queue);
5077
Juuso Oikarinen37b70a82009-10-08 21:56:21 +03005078 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
Ido Yariva6208652011-03-01 15:14:41 +02005079 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
Juuso Oikarinen117b38d2010-09-30 10:43:28 +02005080 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5081 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5082 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +03005083
Eliad Peller92ef8962011-06-07 12:50:46 +03005084 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5085 if (!wl->freezable_wq) {
5086 ret = -ENOMEM;
5087 goto err_hw;
5088 }
5089
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005090 wl->channel = WL1271_DEFAULT_CHANNEL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005091 wl->rx_counter = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005092 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03005093 wl->band = IEEE80211_BAND_2GHZ;
Juuso Oikarinenb771eee2009-10-08 21:56:34 +03005094 wl->vif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02005095 wl->flags = 0;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02005096 wl->sg_enabled = true;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03005097 wl->hw_pg_ver = -1;
Arik Nemtsovb622d992011-02-23 00:22:31 +02005098 wl->ap_ps_map = 0;
5099 wl->ap_fw_ps_map = 0;
Ido Yariv606ea9f2011-03-01 15:14:39 +02005100 wl->quirks = 0;
Ido Yariv341b7cd2011-03-31 10:07:01 +02005101 wl->platform_quirks = 0;
Luciano Coelho33c2c062011-05-10 14:46:02 +03005102 wl->sched_scanning = false;
Guy Eilame9eb8cb2011-08-16 19:49:12 +03005103 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005104 wl->system_hlid = WL12XX_SYSTEM_HLID;
Arik Nemtsovda032092011-08-25 12:43:15 +03005105 wl->active_sta_count = 0;
Ido Yariv95dac04f2011-06-06 14:57:06 +03005106 wl->fwlog_size = 0;
5107 init_waitqueue_head(&wl->fwlog_waitq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005108
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005109 /* The system link is always allocated */
5110 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5111
Ido Yariv25eeb9e2010-10-12 16:20:06 +02005112 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +03005113 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005114 wl->tx_frames[i] = NULL;
5115
5116 spin_lock_init(&wl->wl_lock);
5117
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005118 wl->state = WL1271_STATE_OFF;
5119 mutex_init(&wl->mutex);
5120
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005121 /* Apply default driver configuration. */
5122 wl1271_conf_init(wl);
5123
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005124 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5125 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5126 if (!wl->aggr_buf) {
5127 ret = -ENOMEM;
Eliad Peller92ef8962011-06-07 12:50:46 +03005128 goto err_wq;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005129 }
5130
Ido Yariv990f5de2011-03-31 10:06:59 +02005131 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5132 if (!wl->dummy_packet) {
5133 ret = -ENOMEM;
5134 goto err_aggr;
5135 }
5136
Ido Yariv95dac04f2011-06-06 14:57:06 +03005137 /* Allocate one page for the FW log */
5138 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5139 if (!wl->fwlog) {
5140 ret = -ENOMEM;
5141 goto err_dummy_packet;
5142 }
5143
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005144 return hw;
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005145
Ido Yariv990f5de2011-03-31 10:06:59 +02005146err_dummy_packet:
5147 dev_kfree_skb(wl->dummy_packet);
5148
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005149err_aggr:
5150 free_pages((unsigned long)wl->aggr_buf, order);
5151
Eliad Peller92ef8962011-06-07 12:50:46 +03005152err_wq:
5153 destroy_workqueue(wl->freezable_wq);
5154
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005155err_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005156 wl1271_debugfs_exit(wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005157 ieee80211_free_hw(hw);
5158
5159err_hw_alloc:
5160
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005161 return ERR_PTR(ret);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005162}
5163
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005164static int wl1271_free_hw(struct wl1271 *wl)
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005165{
Ido Yariv95dac04f2011-06-06 14:57:06 +03005166 /* Unblock any fwlog readers */
5167 mutex_lock(&wl->mutex);
5168 wl->fwlog_size = -1;
5169 wake_up_interruptible_all(&wl->fwlog_waitq);
5170 mutex_unlock(&wl->mutex);
5171
Felipe Balbif79f8902011-10-06 13:05:25 +03005172 device_remove_bin_file(wl->dev, &fwlog_attr);
Gery Kahn6f07b722011-07-18 14:21:49 +03005173
Felipe Balbif79f8902011-10-06 13:05:25 +03005174 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
Gery Kahn6f07b722011-07-18 14:21:49 +03005175
Felipe Balbif79f8902011-10-06 13:05:25 +03005176 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
Ido Yariv95dac04f2011-06-06 14:57:06 +03005177 free_page((unsigned long)wl->fwlog);
Ido Yariv990f5de2011-03-31 10:06:59 +02005178 dev_kfree_skb(wl->dummy_packet);
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005179 free_pages((unsigned long)wl->aggr_buf,
5180 get_order(WL1271_AGGR_BUFFER_SIZE));
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005181
5182 wl1271_debugfs_exit(wl);
5183
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005184 vfree(wl->fw);
5185 wl->fw = NULL;
5186 kfree(wl->nvs);
5187 wl->nvs = NULL;
5188
5189 kfree(wl->fw_status);
5190 kfree(wl->tx_res_if);
Eliad Peller92ef8962011-06-07 12:50:46 +03005191 destroy_workqueue(wl->freezable_wq);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005192
5193 ieee80211_free_hw(wl->hw);
5194
5195 return 0;
5196}
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005197
Felipe Balbia390e852011-10-06 10:07:44 +03005198static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5199{
5200 struct wl1271 *wl = cookie;
5201 unsigned long flags;
5202
5203 wl1271_debug(DEBUG_IRQ, "IRQ");
5204
5205 /* complete the ELP completion */
5206 spin_lock_irqsave(&wl->wl_lock, flags);
5207 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5208 if (wl->elp_compl) {
5209 complete(wl->elp_compl);
5210 wl->elp_compl = NULL;
5211 }
5212
5213 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5214 /* don't enqueue a work right now. mark it as pending */
5215 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5216 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5217 disable_irq_nosync(wl->irq);
5218 pm_wakeup_event(wl->dev, 0);
5219 spin_unlock_irqrestore(&wl->wl_lock, flags);
5220 return IRQ_HANDLED;
5221 }
5222 spin_unlock_irqrestore(&wl->wl_lock, flags);
5223
5224 return IRQ_WAKE_THREAD;
5225}
5226
Felipe Balbice2a2172011-10-05 14:12:55 +03005227static int __devinit wl12xx_probe(struct platform_device *pdev)
5228{
Felipe Balbia390e852011-10-06 10:07:44 +03005229 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5230 struct ieee80211_hw *hw;
5231 struct wl1271 *wl;
5232 unsigned long irqflags;
5233 int ret = -ENODEV;
5234
5235 hw = wl1271_alloc_hw();
5236 if (IS_ERR(hw)) {
5237 wl1271_error("can't allocate hw");
5238 ret = PTR_ERR(hw);
5239 goto out;
5240 }
5241
5242 wl = hw->priv;
5243 wl->irq = platform_get_irq(pdev, 0);
5244 wl->ref_clock = pdata->board_ref_clock;
5245 wl->tcxo_clock = pdata->board_tcxo_clock;
5246 wl->platform_quirks = pdata->platform_quirks;
5247 wl->set_power = pdata->set_power;
5248 wl->dev = &pdev->dev;
5249 wl->if_ops = pdata->ops;
5250
5251 platform_set_drvdata(pdev, wl);
5252
5253 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5254 irqflags = IRQF_TRIGGER_RISING;
5255 else
5256 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5257
5258 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5259 irqflags,
5260 pdev->name, wl);
5261 if (ret < 0) {
5262 wl1271_error("request_irq() failed: %d", ret);
5263 goto out_free_hw;
5264 }
5265
5266 ret = enable_irq_wake(wl->irq);
5267 if (!ret) {
5268 wl->irq_wake_enabled = true;
5269 device_init_wakeup(wl->dev, 1);
5270 if (pdata->pwr_in_suspend)
5271 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5272
5273 }
5274 disable_irq(wl->irq);
5275
5276 ret = wl1271_init_ieee80211(wl);
5277 if (ret)
5278 goto out_irq;
5279
5280 ret = wl1271_register_hw(wl);
5281 if (ret)
5282 goto out_irq;
5283
Felipe Balbif79f8902011-10-06 13:05:25 +03005284 /* Create sysfs file to control bt coex state */
5285 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5286 if (ret < 0) {
5287 wl1271_error("failed to create sysfs file bt_coex_state");
5288 goto out_irq;
5289 }
5290
5291 /* Create sysfs file to get HW PG version */
5292 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5293 if (ret < 0) {
5294 wl1271_error("failed to create sysfs file hw_pg_ver");
5295 goto out_bt_coex_state;
5296 }
5297
5298 /* Create sysfs file for the FW log */
5299 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5300 if (ret < 0) {
5301 wl1271_error("failed to create sysfs file fwlog");
5302 goto out_hw_pg_ver;
5303 }
5304
Felipe Balbice2a2172011-10-05 14:12:55 +03005305 return 0;
Felipe Balbia390e852011-10-06 10:07:44 +03005306
Felipe Balbif79f8902011-10-06 13:05:25 +03005307out_hw_pg_ver:
5308 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5309
5310out_bt_coex_state:
5311 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5312
Felipe Balbia390e852011-10-06 10:07:44 +03005313out_irq:
5314 free_irq(wl->irq, wl);
5315
5316out_free_hw:
5317 wl1271_free_hw(wl);
5318
5319out:
5320 return ret;
Felipe Balbice2a2172011-10-05 14:12:55 +03005321}
5322
5323static int __devexit wl12xx_remove(struct platform_device *pdev)
5324{
Felipe Balbia390e852011-10-06 10:07:44 +03005325 struct wl1271 *wl = platform_get_drvdata(pdev);
5326
5327 if (wl->irq_wake_enabled) {
5328 device_init_wakeup(wl->dev, 0);
5329 disable_irq_wake(wl->irq);
5330 }
5331 wl1271_unregister_hw(wl);
5332 free_irq(wl->irq, wl);
5333 wl1271_free_hw(wl);
5334
Felipe Balbice2a2172011-10-05 14:12:55 +03005335 return 0;
5336}
5337
5338static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005339 { "wl12xx", 0 },
Felipe Balbice2a2172011-10-05 14:12:55 +03005340 { } /* Terminating Entry */
5341};
5342MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5343
5344static struct platform_driver wl12xx_driver = {
5345 .probe = wl12xx_probe,
5346 .remove = __devexit_p(wl12xx_remove),
5347 .id_table = wl12xx_id_table,
5348 .driver = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005349 .name = "wl12xx_driver",
Felipe Balbice2a2172011-10-05 14:12:55 +03005350 .owner = THIS_MODULE,
5351 }
5352};
5353
5354static int __init wl12xx_init(void)
5355{
5356 return platform_driver_register(&wl12xx_driver);
5357}
5358module_init(wl12xx_init);
5359
5360static void __exit wl12xx_exit(void)
5361{
5362 platform_driver_unregister(&wl12xx_driver);
5363}
5364module_exit(wl12xx_exit);
5365
Guy Eilam491bbd62011-01-12 10:33:29 +01005366u32 wl12xx_debug_level = DEBUG_NONE;
Eliad Peller17c17552010-12-12 12:15:35 +02005367EXPORT_SYMBOL_GPL(wl12xx_debug_level);
Guy Eilam491bbd62011-01-12 10:33:29 +01005368module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
Eliad Peller17c17552010-12-12 12:15:35 +02005369MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5370
Ido Yariv95dac04f2011-06-06 14:57:06 +03005371module_param_named(fwlog, fwlog_param, charp, 0);
Luciano Coelho2c882fa2012-02-07 12:37:33 +02005372MODULE_PARM_DESC(fwlog,
Ido Yariv95dac04f2011-06-06 14:57:06 +03005373 "FW logger options: continuous, ondemand, dbgpins or disable");
5374
Eliad Peller2a5bff02011-08-25 18:10:59 +03005375module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5376MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5377
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005378MODULE_LICENSE("GPL");
Luciano Coelhob1a48ca2011-02-22 14:19:28 +02005379MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005380MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");