blob: 89bf9eadc840b4f266734a47e30c72cba7bf9143 [file] [log] [blame]
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02001
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002/*
3 * This file is part of wl1271
4 *
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02005 * Copyright (C) 2008-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03006 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/module.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030026#include <linux/firmware.h>
27#include <linux/delay.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030028#include <linux/spi/spi.h>
29#include <linux/crc32.h>
30#include <linux/etherdevice.h>
Juuso Oikarinen1fba4972009-10-08 21:56:32 +030031#include <linux/vmalloc.h>
Juuso Oikarinena1dd8182010-03-18 12:26:31 +020032#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Ido Yariv341b7cd2011-03-31 10:07:01 +020034#include <linux/wl12xx.h>
Ido Yariv95dac04f2011-06-06 14:57:06 +030035#include <linux/sched.h>
Felipe Balbia390e852011-10-06 10:07:44 +030036#include <linux/interrupt.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030037
Shahar Levi00d20102010-11-08 11:20:10 +000038#include "wl12xx.h"
Luciano Coelho0f4e3122011-10-07 11:02:42 +030039#include "debug.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030040#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000041#include "reg.h"
42#include "io.h"
43#include "event.h"
44#include "tx.h"
45#include "rx.h"
46#include "ps.h"
47#include "init.h"
48#include "debugfs.h"
49#include "cmd.h"
50#include "boot.h"
51#include "testmode.h"
52#include "scan.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +020054#define WL1271_BOOT_RETRIES 3
55
Juuso Oikarinen8a080482009-10-13 12:47:44 +030056static struct conf_drv_settings default_conf = {
57 .sg = {
Eliad Peller3be41122011-08-14 13:17:19 +030058 .params = {
59 [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
60 [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
61 [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
62 [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
63 [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
64 [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
65 [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
66 [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
67 [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
68 [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
69 [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
70 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
71 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
72 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
73 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
74 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
75 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
76 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
77 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
78 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
79 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
80 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
81 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
82 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
83 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
84 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
85 /* active scan params */
86 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
87 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
88 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
89 /* passive scan params */
90 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
91 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
92 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
93 /* passive scan in dual antenna params */
94 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
95 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
96 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
97 /* general params */
98 [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
99 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
100 [CONF_SG_BEACON_MISS_PERCENT] = 60,
101 [CONF_SG_DHCP_TIME] = 5000,
102 [CONF_SG_RXT] = 1200,
103 [CONF_SG_TXT] = 1000,
104 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
105 [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
106 [CONF_SG_HV3_MAX_SERVED] = 6,
107 [CONF_SG_PS_POLL_TIMEOUT] = 10,
108 [CONF_SG_UPSD_TIMEOUT] = 10,
109 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
110 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
111 [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
112 /* AP params */
113 [CONF_AP_BEACON_MISS_TX] = 3,
114 [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
115 [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
116 [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
117 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
118 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
Eliad Peller26612c42012-01-31 17:54:43 +0200119 /* CTS Diluting params */
120 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
121 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
Arik Nemtsov801f8702011-04-18 14:15:20 +0300122 },
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200123 .state = CONF_SG_PROTECTIVE,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300124 },
125 .rx = {
126 .rx_msdu_life_time = 512000,
127 .packet_detection_threshold = 0,
128 .ps_poll_timeout = 15,
129 .upsd_timeout = 15,
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300130 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200131 .rx_cca_threshold = 0,
132 .irq_blk_threshold = 0xFFFF,
133 .irq_pkt_threshold = 0,
134 .irq_timeout = 600,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300135 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
136 },
137 .tx = {
138 .tx_energy_detection = 0,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200139 .sta_rc_conf = {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300140 .enabled_rates = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300141 .short_retry_limit = 10,
142 .long_retry_limit = 10,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200143 .aflags = 0,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300144 },
145 .ac_conf_count = 4,
146 .ac_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200147 [CONF_TX_AC_BE] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300148 .ac = CONF_TX_AC_BE,
149 .cw_min = 15,
150 .cw_max = 63,
151 .aifsn = 3,
152 .tx_op_limit = 0,
153 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200154 [CONF_TX_AC_BK] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300155 .ac = CONF_TX_AC_BK,
156 .cw_min = 15,
157 .cw_max = 63,
158 .aifsn = 7,
159 .tx_op_limit = 0,
160 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200161 [CONF_TX_AC_VI] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300162 .ac = CONF_TX_AC_VI,
163 .cw_min = 15,
164 .cw_max = 63,
165 .aifsn = CONF_TX_AIFS_PIFS,
166 .tx_op_limit = 3008,
167 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200168 [CONF_TX_AC_VO] = {
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300169 .ac = CONF_TX_AC_VO,
170 .cw_min = 15,
171 .cw_max = 63,
172 .aifsn = CONF_TX_AIFS_PIFS,
173 .tx_op_limit = 1504,
174 },
175 },
Arik Nemtsov3618f302011-06-26 10:36:03 +0300176 .max_tx_retries = 100,
177 .ap_aging_period = 300,
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200178 .tid_conf_count = 4,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300179 .tid_conf = {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200180 [CONF_TX_AC_BE] = {
181 .queue_id = CONF_TX_AC_BE,
182 .channel_type = CONF_CHANNEL_TYPE_EDCF,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300183 .tsid = CONF_TX_AC_BE,
184 .ps_scheme = CONF_PS_SCHEME_LEGACY,
185 .ack_policy = CONF_ACK_POLICY_LEGACY,
186 .apsd_conf = {0, 0},
187 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200188 [CONF_TX_AC_BK] = {
189 .queue_id = CONF_TX_AC_BK,
190 .channel_type = CONF_CHANNEL_TYPE_EDCF,
191 .tsid = CONF_TX_AC_BK,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300192 .ps_scheme = CONF_PS_SCHEME_LEGACY,
193 .ack_policy = CONF_ACK_POLICY_LEGACY,
194 .apsd_conf = {0, 0},
195 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200196 [CONF_TX_AC_VI] = {
197 .queue_id = CONF_TX_AC_VI,
198 .channel_type = CONF_CHANNEL_TYPE_EDCF,
199 .tsid = CONF_TX_AC_VI,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300200 .ps_scheme = CONF_PS_SCHEME_LEGACY,
201 .ack_policy = CONF_ACK_POLICY_LEGACY,
202 .apsd_conf = {0, 0},
203 },
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200204 [CONF_TX_AC_VO] = {
205 .queue_id = CONF_TX_AC_VO,
206 .channel_type = CONF_CHANNEL_TYPE_EDCF,
207 .tsid = CONF_TX_AC_VO,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300208 .ps_scheme = CONF_PS_SCHEME_LEGACY,
209 .ack_policy = CONF_ACK_POLICY_LEGACY,
210 .apsd_conf = {0, 0},
211 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300212 },
213 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200214 .tx_compl_timeout = 700,
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300215 .tx_compl_threshold = 4,
216 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
217 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200218 .tmpl_short_retry_limit = 10,
219 .tmpl_long_retry_limit = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300220 },
221 .conn = {
222 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300223 .listen_interval = 1,
Eyal Shapiradae728f2012-02-02 12:03:39 +0200224 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
225 .suspend_listen_interval = 3,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300226 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
Shahar Levibc76b942011-05-11 11:14:22 +0300227 .bcn_filt_ie_count = 2,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300228 .bcn_filt_ie = {
229 [0] = {
230 .ie = WLAN_EID_CHANNEL_SWITCH,
231 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
Shahar Levibc76b942011-05-11 11:14:22 +0300232 },
233 [1] = {
234 .ie = WLAN_EID_HT_INFORMATION,
235 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
236 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300237 },
Luciano Coelho3ed8f2c2009-12-11 15:40:54 +0200238 .synch_fail_thold = 10,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300239 .bss_lose_timeout = 100,
240 .beacon_rx_timeout = 10000,
241 .broadcast_timeout = 20000,
242 .rx_broadcast_in_ps = 1,
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300243 .ps_poll_threshold = 10,
Juuso Oikarinen11f70f92009-10-13 12:47:46 +0300244 .bet_enable = CONF_BET_MODE_ENABLE,
Ohad Ben-Cohen958b20e02011-03-14 18:53:10 +0200245 .bet_max_consecutive = 50,
Eliad Pellera879ed72011-08-23 16:37:02 +0300246 .psm_entry_retries = 8,
Shahar Levi23708412011-04-13 14:52:50 +0300247 .psm_exit_retries = 16,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200248 .psm_entry_nullfunc_retries = 3,
Arik Nemtsovd7b63b92012-02-28 00:41:34 +0200249 .dynamic_ps_timeout = 200,
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +0200250 .forced_ps = false,
Juuso Oikarinen50c500a2010-04-01 11:38:22 +0300251 .keep_alive_interval = 55000,
252 .max_listen_interval = 20,
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300253 },
Luciano Coelho6e92b412009-12-11 15:40:50 +0200254 .itrim = {
255 .enable = false,
256 .timeout = 50000,
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200257 },
258 .pm_config = {
259 .host_clk_settling_time = 5000,
260 .host_fast_wakeup_support = false
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300261 },
262 .roam_trigger = {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300263 .trigger_pacing = 1,
264 .avg_weight_rssi_beacon = 20,
265 .avg_weight_rssi_data = 10,
266 .avg_weight_snr_beacon = 20,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100267 .avg_weight_snr_data = 10,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200268 },
269 .scan = {
270 .min_dwell_time_active = 7500,
271 .max_dwell_time_active = 30000,
Juuso Oikarinenea45b2c2011-01-24 07:01:54 +0100272 .min_dwell_time_passive = 100000,
273 .max_dwell_time_passive = 100000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200274 .num_probe_reqs = 2,
Eyal Shapirad647f2d2012-02-02 13:54:28 +0200275 .split_scan_timeout = 50000,
Juuso Oikarinenbea39d62010-09-21 08:14:31 +0200276 },
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300277 .sched_scan = {
278 /* sched_scan requires dwell times in TU instead of TU/1000 */
Luciano Coelho221737d2011-09-02 14:28:22 +0300279 .min_dwell_time_active = 30,
280 .max_dwell_time_active = 60,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300281 .dwell_time_passive = 100,
Luciano Coelho50a66d72011-05-27 15:34:47 +0300282 .dwell_time_dfs = 150,
Luciano Coelho3a9d60e2011-05-10 14:06:31 +0300283 .num_probe_reqs = 2,
284 .rssi_threshold = -90,
285 .snr_threshold = 0,
286 },
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200287 .rf = {
288 .tx_per_channel_power_compensation_2 = {
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 },
291 .tx_per_channel_power_compensation_5 = {
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 },
296 },
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100297 .ht = {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300298 .rx_ba_win_size = 8,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100299 .tx_ba_win_size = 64,
300 .inactivity_timeout = 10000,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300301 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100302 },
Shahar Levi13b107d2011-03-06 16:32:12 +0200303 .mem_wl127x = {
Eliad Pellerfe5ef092011-02-02 09:59:36 +0200304 .num_stations = 1,
305 .ssid_profiles = 1,
306 .rx_block_num = 70,
307 .tx_min_block_num = 40,
Ido Yariv4cf557f2011-04-18 16:45:10 +0300308 .dynamic_memory = 1,
Ido Yarivb16d4b62011-03-01 15:14:44 +0200309 .min_req_tx_blocks = 100,
Eliad Pellerc8bde242011-02-02 09:59:35 +0200310 .min_req_rx_blocks = 22,
311 .tx_min = 27,
Shahar Levi13b107d2011-03-06 16:32:12 +0200312 },
313 .mem_wl128x = {
314 .num_stations = 1,
315 .ssid_profiles = 1,
316 .rx_block_num = 40,
317 .tx_min_block_num = 40,
318 .dynamic_memory = 1,
319 .min_req_tx_blocks = 45,
320 .min_req_rx_blocks = 22,
321 .tx_min = 27,
322 },
Shahar Leviff868432011-04-11 15:41:46 +0300323 .fm_coex = {
324 .enable = true,
325 .swallow_period = 5,
326 .n_divider_fref_set_1 = 0xff, /* default */
327 .n_divider_fref_set_2 = 12,
328 .m_divider_fref_set_1 = 148,
329 .m_divider_fref_set_2 = 0xffff, /* default */
330 .coex_pll_stabilization_time = 0xffffffff, /* default */
331 .ldo_stabilization_time = 0xffff, /* default */
332 .fm_disturbed_band_margin = 0xff, /* default */
333 .swallow_clk_diff = 0xff, /* default */
334 },
Eliad Pellerf84673d2011-05-15 11:10:28 +0300335 .rx_streaming = {
336 .duration = 150,
337 .queues = 0x1,
338 .interval = 20,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300339 .always = 0,
Eliad Pellerf84673d2011-05-15 11:10:28 +0300340 },
Ido Yariv95dac04f2011-06-06 14:57:06 +0300341 .fwlog = {
342 .mode = WL12XX_FWLOG_ON_DEMAND,
343 .mem_blocks = 2,
344 .severity = 0,
345 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
346 .output = WL12XX_FWLOG_OUTPUT_HOST,
347 .threshold = 0,
348 },
Luciano Coelhoafb7d3c2011-04-01 20:48:02 +0300349 .hci_io_ds = HCI_IO_DS_6MA,
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300350 .rate = {
351 .rate_retry_score = 32000,
352 .per_add = 8192,
353 .per_th1 = 2048,
354 .per_th2 = 4096,
355 .max_per = 8100,
356 .inverse_curiosity_factor = 5,
357 .tx_fail_low_th = 4,
358 .tx_fail_high_th = 10,
359 .per_alpha_shift = 4,
360 .per_add_shift = 13,
361 .per_beta1_shift = 10,
362 .per_beta2_shift = 8,
363 .rate_check_up = 2,
364 .rate_check_down = 12,
365 .rate_retry_policy = {
366 0x00, 0x00, 0x00, 0x00, 0x00,
367 0x00, 0x00, 0x00, 0x00, 0x00,
368 0x00, 0x00, 0x00,
369 },
370 },
Eliad Peller94877752011-08-28 15:11:56 +0300371 .hangover = {
372 .recover_time = 0,
373 .hangover_period = 20,
374 .dynamic_mode = 1,
375 .early_termination_mode = 1,
376 .max_period = 20,
377 .min_period = 1,
378 .increase_delta = 1,
379 .decrease_delta = 2,
380 .quiet_time = 4,
381 .increase_time = 1,
382 .window_size = 16,
383 },
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300384};
385
Ido Yariv95dac04f2011-06-06 14:57:06 +0300386static char *fwlog_param;
Eliad Peller2a5bff02011-08-25 18:10:59 +0300387static bool bug_on_recovery;
Ido Yariv95dac04f2011-06-06 14:57:06 +0300388
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300389static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +0200390 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300391 bool reset_tx_queues);
Eliad Pellerf0277432011-10-10 10:13:14 +0200392static void wl1271_op_stop(struct ieee80211_hw *hw);
Eliad Peller170d0e62011-10-05 11:56:06 +0200393static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200394
Eliad Peller9fd6f212012-03-04 10:55:48 +0200395static int wl12xx_set_authorized(struct wl1271 *wl,
396 struct wl12xx_vif *wlvif)
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300397{
398 int ret;
Eliad Peller0603d892011-10-05 11:55:51 +0200399
Eliad Peller9fd6f212012-03-04 10:55:48 +0200400 if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
401 return -EINVAL;
402
403 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300404 return 0;
405
Eliad Peller8181aec2011-10-10 10:13:04 +0200406 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300407 return 0;
408
Eliad Peller154da672011-10-05 11:55:53 +0200409 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300410 if (ret < 0)
411 return ret;
412
Eliad Peller0603d892011-10-05 11:55:51 +0200413 wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +0300414
Eliad Pelleref4b29e2011-06-06 13:03:12 +0300415 wl1271_info("Association completed.");
416 return 0;
417}
Juuso Oikarinenc2c192a2010-07-27 03:30:09 +0300418
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100419static int wl1271_reg_notify(struct wiphy *wiphy,
Luciano Coelho573c67c2010-11-26 13:44:59 +0200420 struct regulatory_request *request)
421{
Juuso Oikarinenb7417d92010-11-10 11:27:19 +0100422 struct ieee80211_supported_band *band;
423 struct ieee80211_channel *ch;
424 int i;
425
426 band = wiphy->bands[IEEE80211_BAND_5GHZ];
427 for (i = 0; i < band->n_channels; i++) {
428 ch = &band->channels[i];
429 if (ch->flags & IEEE80211_CHAN_DISABLED)
430 continue;
431
432 if (ch->flags & IEEE80211_CHAN_RADAR)
433 ch->flags |= IEEE80211_CHAN_NO_IBSS |
434 IEEE80211_CHAN_PASSIVE_SCAN;
435
436 }
437
438 return 0;
439}
440
Eliad Peller9eb599e2011-10-10 10:12:59 +0200441static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
442 bool enable)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300443{
444 int ret = 0;
445
446 /* we should hold wl->mutex */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200447 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300448 if (ret < 0)
449 goto out;
450
451 if (enable)
Eliad Peller0744bdb2011-10-10 10:13:05 +0200452 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300453 else
Eliad Peller0744bdb2011-10-10 10:13:05 +0200454 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300455out:
456 return ret;
457}
458
459/*
460 * this function is being called when the rx_streaming interval
461 * has beed changed or rx_streaming should be disabled
462 */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200463int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300464{
465 int ret = 0;
466 int period = wl->conf.rx_streaming.interval;
467
468 /* don't reconfigure if rx_streaming is disabled */
Eliad Peller0744bdb2011-10-10 10:13:05 +0200469 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300470 goto out;
471
472 /* reconfigure/disable according to new streaming_period */
473 if (period &&
Eliad Pellerba8447f2011-10-10 10:13:00 +0200474 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eliad Peller77ddaa12011-05-15 11:10:29 +0300475 (wl->conf.rx_streaming.always ||
476 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
Eliad Peller9eb599e2011-10-10 10:12:59 +0200477 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300478 else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200479 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300480 /* don't cancel_work_sync since we might deadlock */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200481 del_timer_sync(&wlvif->rx_streaming_timer);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300482 }
483out:
484 return ret;
485}
486
487static void wl1271_rx_streaming_enable_work(struct work_struct *work)
488{
489 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200490 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
491 rx_streaming_enable_work);
492 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300493
494 mutex_lock(&wl->mutex);
495
Eliad Peller0744bdb2011-10-10 10:13:05 +0200496 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
Eliad Pellerba8447f2011-10-10 10:13:00 +0200497 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller77ddaa12011-05-15 11:10:29 +0300498 (!wl->conf.rx_streaming.always &&
499 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
500 goto out;
501
502 if (!wl->conf.rx_streaming.interval)
503 goto out;
504
505 ret = wl1271_ps_elp_wakeup(wl);
506 if (ret < 0)
507 goto out;
508
Eliad Peller9eb599e2011-10-10 10:12:59 +0200509 ret = wl1271_set_rx_streaming(wl, wlvif, true);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300510 if (ret < 0)
511 goto out_sleep;
512
513 /* stop it after some time of inactivity */
Eliad Peller9eb599e2011-10-10 10:12:59 +0200514 mod_timer(&wlvif->rx_streaming_timer,
Eliad Peller77ddaa12011-05-15 11:10:29 +0300515 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
516
517out_sleep:
518 wl1271_ps_elp_sleep(wl);
519out:
520 mutex_unlock(&wl->mutex);
521}
522
523static void wl1271_rx_streaming_disable_work(struct work_struct *work)
524{
525 int ret;
Eliad Peller9eb599e2011-10-10 10:12:59 +0200526 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
527 rx_streaming_disable_work);
528 struct wl1271 *wl = wlvif->wl;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300529
530 mutex_lock(&wl->mutex);
531
Eliad Peller0744bdb2011-10-10 10:13:05 +0200532 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
Eliad Peller77ddaa12011-05-15 11:10:29 +0300533 goto out;
534
535 ret = wl1271_ps_elp_wakeup(wl);
536 if (ret < 0)
537 goto out;
538
Eliad Peller9eb599e2011-10-10 10:12:59 +0200539 ret = wl1271_set_rx_streaming(wl, wlvif, false);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300540 if (ret)
541 goto out_sleep;
542
543out_sleep:
544 wl1271_ps_elp_sleep(wl);
545out:
546 mutex_unlock(&wl->mutex);
547}
548
549static void wl1271_rx_streaming_timer(unsigned long data)
550{
Eliad Peller9eb599e2011-10-10 10:12:59 +0200551 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
552 struct wl1271 *wl = wlvif->wl;
553 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +0300554}
555
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300556static void wl1271_conf_init(struct wl1271 *wl)
557{
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300558
559 /*
560 * This function applies the default configuration to the driver. This
561 * function is invoked upon driver load (spi probe.)
562 *
563 * The configuration is stored in a run-time structure in order to
564 * facilitate for run-time adjustment of any of the parameters. Making
565 * changes to the configuration structure will apply the new values on
566 * the next interface up (wl1271_op_start.)
567 */
568
569 /* apply driver default configuration */
Juuso Oikarinen8a080482009-10-13 12:47:44 +0300570 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300571
Ido Yariv95dac04f2011-06-06 14:57:06 +0300572 /* Adjust settings according to optional module parameters */
573 if (fwlog_param) {
574 if (!strcmp(fwlog_param, "continuous")) {
575 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
576 } else if (!strcmp(fwlog_param, "ondemand")) {
577 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
578 } else if (!strcmp(fwlog_param, "dbgpins")) {
579 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
580 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
581 } else if (!strcmp(fwlog_param, "disable")) {
582 wl->conf.fwlog.mem_blocks = 0;
583 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
584 } else {
585 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
586 }
587 }
588}
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300589
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300590static int wl1271_plt_init(struct wl1271 *wl)
591{
Eliad Peller188e7f52011-12-06 12:15:06 +0200592 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300593
Shahar Levi49d750ca2011-03-06 16:32:09 +0200594 if (wl->chip.id == CHIP_ID_1283_PG20)
595 ret = wl128x_cmd_general_parms(wl);
596 else
597 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200598 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200599 return ret;
600
Shahar Levi49d750ca2011-03-06 16:32:09 +0200601 if (wl->chip.id == CHIP_ID_1283_PG20)
602 ret = wl128x_cmd_radio_parms(wl);
603 else
604 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200605 if (ret < 0)
Luciano Coelhocc7defa2009-11-23 23:22:16 +0200606 return ret;
607
Shahar Levi49d750ca2011-03-06 16:32:09 +0200608 if (wl->chip.id != CHIP_ID_1283_PG20) {
609 ret = wl1271_cmd_ext_radio_parms(wl);
610 if (ret < 0)
611 return ret;
612 }
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200613
Shahar Levi48a61472011-03-06 16:32:08 +0200614 /* Chip-specific initializations */
615 ret = wl1271_chip_specific_init(wl);
616 if (ret < 0)
617 return ret;
618
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300619 ret = wl1271_acx_init_mem_config(wl);
620 if (ret < 0)
621 return ret;
622
Eliad Peller7f0979882011-08-14 13:17:06 +0300623 ret = wl12xx_acx_mem_cfg(wl);
Gery Kahn1ec610e2011-02-01 03:03:08 -0600624 if (ret < 0)
625 goto out_free_memmap;
626
Luciano Coelho12419cc2010-02-18 13:25:44 +0200627 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200628 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300629 if (ret < 0)
Luciano Coelho12419cc2010-02-18 13:25:44 +0200630 goto out_free_memmap;
631
632 /* Configure for CAM power saving (ie. always active) */
633 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
634 if (ret < 0)
635 goto out_free_memmap;
636
637 /* configure PM */
638 ret = wl1271_acx_pm_config(wl);
639 if (ret < 0)
640 goto out_free_memmap;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300641
642 return 0;
Luciano Coelho12419cc2010-02-18 13:25:44 +0200643
644 out_free_memmap:
645 kfree(wl->target_mem_map);
646 wl->target_mem_map = NULL;
647
648 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300649}
650
Eliad Peller6e8cd332011-10-10 10:13:13 +0200651static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
652 struct wl12xx_vif *wlvif,
653 u8 hlid, u8 tx_pkts)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200654{
Arik Nemtsovda032092011-08-25 12:43:15 +0300655 bool fw_ps, single_sta;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200656
Arik Nemtsovb622d992011-02-23 00:22:31 +0200657 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Arik Nemtsovda032092011-08-25 12:43:15 +0300658 single_sta = (wl->active_sta_count == 1);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200659
660 /*
661 * Wake up from high level PS if the STA is asleep with too little
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300662 * packets in FW or if the STA is awake.
Arik Nemtsovb622d992011-02-23 00:22:31 +0200663 */
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300664 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200665 wl12xx_ps_link_end(wl, wlvif, hlid);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200666
Arik Nemtsovda032092011-08-25 12:43:15 +0300667 /*
668 * Start high-level PS if the STA is asleep with enough blocks in FW.
669 * Make an exception if this is the only connected station. In this
670 * case FW-memory congestion is not a problem.
671 */
672 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
Eliad Peller6e8cd332011-10-10 10:13:13 +0200673 wl12xx_ps_link_start(wl, wlvif, hlid, true);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200674}
675
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300676static void wl12xx_irq_update_links_status(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200677 struct wl12xx_vif *wlvif,
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300678 struct wl12xx_fw_status *status)
Arik Nemtsovb622d992011-02-23 00:22:31 +0200679{
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200680 struct wl1271_link *lnk;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200681 u32 cur_fw_ps_map;
Arik Nemtsov9b17f1b2011-08-14 13:17:35 +0300682 u8 hlid, cnt;
683
684 /* TODO: also use link_fast_bitmap here */
Arik Nemtsovb622d992011-02-23 00:22:31 +0200685
686 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
687 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
688 wl1271_debug(DEBUG_PSM,
689 "link ps prev 0x%x cur 0x%x changed 0x%x",
690 wl->ap_fw_ps_map, cur_fw_ps_map,
691 wl->ap_fw_ps_map ^ cur_fw_ps_map);
692
693 wl->ap_fw_ps_map = cur_fw_ps_map;
694 }
695
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200696 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
697 lnk = &wl->links[hlid];
698 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200699
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200700 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
701 lnk->allocated_pkts -= cnt;
Arik Nemtsovb622d992011-02-23 00:22:31 +0200702
Eliad Peller6e8cd332011-10-10 10:13:13 +0200703 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
704 lnk->allocated_pkts);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200705 }
706}
707
Eliad Peller4d56ad92011-08-14 13:17:05 +0300708static void wl12xx_fw_status(struct wl1271 *wl,
709 struct wl12xx_fw_status *status)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300710{
Eliad Peller6e8cd332011-10-10 10:13:13 +0200711 struct wl12xx_vif *wlvif;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200712 struct timespec ts;
Shahar Levi13b107d2011-03-06 16:32:12 +0200713 u32 old_tx_blk_count = wl->tx_blocks_available;
Eliad Peller4d56ad92011-08-14 13:17:05 +0300714 int avail, freed_blocks;
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300715 int i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300716
Eliad Peller4d56ad92011-08-14 13:17:05 +0300717 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
Shahar Levi13b107d2011-03-06 16:32:12 +0200718
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300719 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
720 "drv_rx_counter = %d, tx_results_counter = %d)",
721 status->intr,
722 status->fw_rx_counter,
723 status->drv_rx_counter,
724 status->tx_results_counter);
725
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300726 for (i = 0; i < NUM_TX_QUEUES; i++) {
727 /* prevent wrap-around in freed-packets counter */
Arik Nemtsov742246f2011-08-14 13:17:33 +0300728 wl->tx_allocated_pkts[i] -=
Arik Nemtsovbf54e302011-08-14 13:17:32 +0300729 (status->tx_released_pkts[i] -
730 wl->tx_pkts_freed[i]) & 0xff;
731
732 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
733 }
734
Arik Nemtsovbdf91cf2011-08-14 13:17:34 +0300735 /* prevent wrap-around in total blocks counter */
736 if (likely(wl->tx_blocks_freed <=
737 le32_to_cpu(status->total_released_blks)))
738 freed_blocks = le32_to_cpu(status->total_released_blks) -
739 wl->tx_blocks_freed;
740 else
741 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
742 le32_to_cpu(status->total_released_blks);
743
Eliad Peller4d56ad92011-08-14 13:17:05 +0300744 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
Shahar Levi13b107d2011-03-06 16:32:12 +0200745
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300746 wl->tx_allocated_blocks -= freed_blocks;
747
Eliad Peller4d56ad92011-08-14 13:17:05 +0300748 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200749
Eliad Peller4d56ad92011-08-14 13:17:05 +0300750 /*
751 * The FW might change the total number of TX memblocks before
752 * we get a notification about blocks being released. Thus, the
753 * available blocks calculation might yield a temporary result
754 * which is lower than the actual available blocks. Keeping in
755 * mind that only blocks that were allocated can be moved from
756 * TX to RX, tx_blocks_available should never decrease here.
757 */
758 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
759 avail);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300760
Ido Yariva5225502010-10-12 14:49:10 +0200761 /* if more blocks are available now, tx work can be scheduled */
Shahar Levi13b107d2011-03-06 16:32:12 +0200762 if (wl->tx_blocks_available > old_tx_blk_count)
Ido Yariva5225502010-10-12 14:49:10 +0200763 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300764
Eliad Peller4d56ad92011-08-14 13:17:05 +0300765 /* for AP update num of allocated TX blocks per link and ps status */
Eliad Peller6e8cd332011-10-10 10:13:13 +0200766 wl12xx_for_each_wlvif_ap(wl, wlvif) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200767 wl12xx_irq_update_links_status(wl, wlvif, status);
Eliad Peller6e8cd332011-10-10 10:13:13 +0200768 }
Eliad Peller4d56ad92011-08-14 13:17:05 +0300769
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300770 /* update the host-chipset time offset */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200771 getnstimeofday(&ts);
772 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
773 (s64)le32_to_cpu(status->fw_localtime);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300774}
775
Ido Yariva6208652011-03-01 15:14:41 +0200776static void wl1271_flush_deferred_work(struct wl1271 *wl)
777{
778 struct sk_buff *skb;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200779
Ido Yariva6208652011-03-01 15:14:41 +0200780 /* Pass all received frames to the network stack */
781 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
782 ieee80211_rx_ni(wl->hw, skb);
783
784 /* Return sent skbs to the network stack */
785 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300786 ieee80211_tx_status_ni(wl->hw, skb);
Ido Yariva6208652011-03-01 15:14:41 +0200787}
788
789static void wl1271_netstack_work(struct work_struct *work)
790{
791 struct wl1271 *wl =
792 container_of(work, struct wl1271, netstack_work);
793
794 do {
795 wl1271_flush_deferred_work(wl);
796 } while (skb_queue_len(&wl->deferred_rx_queue));
797}
798
799#define WL1271_IRQ_MAX_LOOPS 256
800
Felipe Balbi4b32a2c2011-10-06 10:46:20 +0300801static irqreturn_t wl1271_irq(int irq, void *cookie)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300802{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300803 int ret;
Juuso Oikarinenc15f63b2009-10-12 15:08:50 +0300804 u32 intr;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200805 int loopcount = WL1271_IRQ_MAX_LOOPS;
Ido Yariva6208652011-03-01 15:14:41 +0200806 struct wl1271 *wl = (struct wl1271 *)cookie;
807 bool done = false;
808 unsigned int defer_count;
Ido Yarivb07d4032011-03-01 15:14:43 +0200809 unsigned long flags;
810
811 /* TX might be handled here, avoid redundant work */
812 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
813 cancel_work_sync(&wl->tx_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300814
Ido Yariv341b7cd2011-03-31 10:07:01 +0200815 /*
816 * In case edge triggered interrupt must be used, we cannot iterate
817 * more than once without introducing race conditions with the hardirq.
818 */
819 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
820 loopcount = 1;
821
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822 mutex_lock(&wl->mutex);
823
824 wl1271_debug(DEBUG_IRQ, "IRQ work");
825
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200826 if (unlikely(wl->state == WL1271_STATE_OFF))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300827 goto out;
828
Ido Yariva6208652011-03-01 15:14:41 +0200829 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300830 if (ret < 0)
831 goto out;
832
Ido Yariva6208652011-03-01 15:14:41 +0200833 while (!done && loopcount--) {
834 /*
835 * In order to avoid a race with the hardirq, clear the flag
836 * before acknowledging the chip. Since the mutex is held,
837 * wl1271_ps_elp_wakeup cannot be called concurrently.
838 */
839 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
840 smp_mb__after_clear_bit();
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200841
Eliad Peller4d56ad92011-08-14 13:17:05 +0300842 wl12xx_fw_status(wl, wl->fw_status);
843 intr = le32_to_cpu(wl->fw_status->intr);
Ido Yariva6208652011-03-01 15:14:41 +0200844 intr &= WL1271_INTR_MASK;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200845 if (!intr) {
Ido Yariva6208652011-03-01 15:14:41 +0200846 done = true;
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200847 continue;
848 }
849
Eliad Pellerccc83b02010-10-27 14:09:57 +0200850 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
851 wl1271_error("watchdog interrupt received! "
852 "starting recovery.");
Ido Yarivbaacb9a2011-06-06 14:57:05 +0300853 wl12xx_queue_recovery_work(wl);
Eliad Pellerccc83b02010-10-27 14:09:57 +0200854
855 /* restarting the chip. ignore any other interrupt. */
856 goto out;
857 }
858
Ido Yariva6208652011-03-01 15:14:41 +0200859 if (likely(intr & WL1271_ACX_INTR_DATA)) {
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200860 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
861
Eliad Peller4d56ad92011-08-14 13:17:05 +0300862 wl12xx_rx(wl, wl->fw_status);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200863
Ido Yariva5225502010-10-12 14:49:10 +0200864 /* Check if any tx blocks were freed */
Ido Yarivb07d4032011-03-01 15:14:43 +0200865 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200866 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300867 wl1271_tx_total_queue_count(wl) > 0) {
Ido Yarivb07d4032011-03-01 15:14:43 +0200868 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200869 /*
870 * In order to avoid starvation of the TX path,
871 * call the work function directly.
872 */
Eliad Pellera32d0cd2011-10-10 10:12:55 +0200873 wl1271_tx_work_locked(wl);
Ido Yarivb07d4032011-03-01 15:14:43 +0200874 } else {
875 spin_unlock_irqrestore(&wl->wl_lock, flags);
Ido Yariva5225502010-10-12 14:49:10 +0200876 }
877
Ido Yariv8aad2462011-03-01 15:14:38 +0200878 /* check for tx results */
Eliad Peller4d56ad92011-08-14 13:17:05 +0300879 if (wl->fw_status->tx_results_counter !=
Ido Yariv8aad2462011-03-01 15:14:38 +0200880 (wl->tx_results_count & 0xff))
881 wl1271_tx_complete(wl);
Ido Yariva6208652011-03-01 15:14:41 +0200882
883 /* Make sure the deferred queues don't get too long */
884 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
885 skb_queue_len(&wl->deferred_rx_queue);
886 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
887 wl1271_flush_deferred_work(wl);
Juuso Oikarinen1e73eb62010-02-22 08:38:37 +0200888 }
889
890 if (intr & WL1271_ACX_INTR_EVENT_A) {
891 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
892 wl1271_event_handle(wl, 0);
893 }
894
895 if (intr & WL1271_ACX_INTR_EVENT_B) {
896 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
897 wl1271_event_handle(wl, 1);
898 }
899
900 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
901 wl1271_debug(DEBUG_IRQ,
902 "WL1271_ACX_INTR_INIT_COMPLETE");
903
904 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
905 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300906 }
907
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300908 wl1271_ps_elp_sleep(wl);
909
910out:
Ido Yarivb07d4032011-03-01 15:14:43 +0200911 spin_lock_irqsave(&wl->wl_lock, flags);
912 /* In case TX was not handled here, queue TX work */
913 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
914 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300915 wl1271_tx_total_queue_count(wl) > 0)
Ido Yarivb07d4032011-03-01 15:14:43 +0200916 ieee80211_queue_work(wl->hw, &wl->tx_work);
917 spin_unlock_irqrestore(&wl->wl_lock, flags);
918
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300919 mutex_unlock(&wl->mutex);
Ido Yariva6208652011-03-01 15:14:41 +0200920
921 return IRQ_HANDLED;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300922}
923
Eliad Peller4549d092012-02-06 13:07:52 +0200924struct vif_counter_data {
925 u8 counter;
926
927 struct ieee80211_vif *cur_vif;
928 bool cur_vif_running;
929};
930
931static void wl12xx_vif_count_iter(void *data, u8 *mac,
932 struct ieee80211_vif *vif)
933{
934 struct vif_counter_data *counter = data;
935
936 counter->counter++;
937 if (counter->cur_vif == vif)
938 counter->cur_vif_running = true;
939}
940
941/* caller must not hold wl->mutex, as it might deadlock */
942static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
943 struct ieee80211_vif *cur_vif,
944 struct vif_counter_data *data)
945{
946 memset(data, 0, sizeof(*data));
947 data->cur_vif = cur_vif;
948
949 ieee80211_iterate_active_interfaces(hw,
950 wl12xx_vif_count_iter, data);
951}
952
Eliad Peller3fcdab72012-02-06 12:47:54 +0200953static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300954{
955 const struct firmware *fw;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200956 const char *fw_name;
Eliad Peller3fcdab72012-02-06 12:47:54 +0200957 enum wl12xx_fw_type fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300958 int ret;
959
Eliad Peller3fcdab72012-02-06 12:47:54 +0200960 if (plt) {
961 fw_type = WL12XX_FW_TYPE_PLT;
962 if (wl->chip.id == CHIP_ID_1283_PG20)
963 fw_name = WL128X_PLT_FW_NAME;
964 else
965 fw_name = WL127X_PLT_FW_NAME;
966 } else {
Eliad Peller4549d092012-02-06 13:07:52 +0200967 /*
968 * we can't call wl12xx_get_vif_count() here because
969 * wl->mutex is taken, so use the cached last_vif_count value
970 */
971 if (wl->last_vif_count > 1) {
972 fw_type = WL12XX_FW_TYPE_MULTI;
973 if (wl->chip.id == CHIP_ID_1283_PG20)
974 fw_name = WL128X_FW_NAME_MULTI;
975 else
976 fw_name = WL127X_FW_NAME_MULTI;
977 } else {
978 fw_type = WL12XX_FW_TYPE_NORMAL;
979 if (wl->chip.id == CHIP_ID_1283_PG20)
980 fw_name = WL128X_FW_NAME_SINGLE;
981 else
982 fw_name = WL127X_FW_NAME_SINGLE;
983 }
Eliad Peller3fcdab72012-02-06 12:47:54 +0200984 }
985
986 if (wl->fw_type == fw_type)
987 return 0;
Arik Nemtsov166d5042010-10-16 21:44:57 +0200988
989 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
990
Felipe Balbia390e852011-10-06 10:07:44 +0300991 ret = request_firmware(&fw, fw_name, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300992
993 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +0100994 wl1271_error("could not get firmware %s: %d", fw_name, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300995 return ret;
996 }
997
998 if (fw->size % 4) {
999 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1000 fw->size);
1001 ret = -EILSEQ;
1002 goto out;
1003 }
1004
Arik Nemtsov166d5042010-10-16 21:44:57 +02001005 vfree(wl->fw);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001006 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001007 wl->fw_len = fw->size;
Juuso Oikarinen1fba4972009-10-08 21:56:32 +03001008 wl->fw = vmalloc(wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001009
1010 if (!wl->fw) {
1011 wl1271_error("could not allocate memory for the firmware");
1012 ret = -ENOMEM;
1013 goto out;
1014 }
1015
1016 memcpy(wl->fw, fw->data, wl->fw_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001017 ret = 0;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001018 wl->fw_type = fw_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001019out:
1020 release_firmware(fw);
1021
1022 return ret;
1023}
1024
1025static int wl1271_fetch_nvs(struct wl1271 *wl)
1026{
1027 const struct firmware *fw;
1028 int ret;
1029
Felipe Balbia390e852011-10-06 10:07:44 +03001030 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001031
1032 if (ret < 0) {
Pontus Fuchs35898932011-11-30 15:35:09 +01001033 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1034 ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001035 return ret;
1036 }
1037
Shahar Levibc765bf2011-03-06 16:32:10 +02001038 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001039
1040 if (!wl->nvs) {
1041 wl1271_error("could not allocate memory for the nvs file");
1042 ret = -ENOMEM;
1043 goto out;
1044 }
1045
Juuso Oikarinen02fabb02010-08-19 04:41:15 +02001046 wl->nvs_len = fw->size;
1047
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001048out:
1049 release_firmware(fw);
1050
1051 return ret;
1052}
1053
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001054void wl12xx_queue_recovery_work(struct wl1271 *wl)
1055{
1056 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1057 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1058}
1059
Ido Yariv95dac04f2011-06-06 14:57:06 +03001060size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1061{
1062 size_t len = 0;
1063
1064 /* The FW log is a length-value list, find where the log end */
1065 while (len < maxlen) {
1066 if (memblock[len] == 0)
1067 break;
1068 if (len + memblock[len] + 1 > maxlen)
1069 break;
1070 len += memblock[len] + 1;
1071 }
1072
1073 /* Make sure we have enough room */
1074 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1075
1076 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1077 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1078 wl->fwlog_size += len;
1079
1080 return len;
1081}
1082
1083static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1084{
1085 u32 addr;
1086 u32 first_addr;
1087 u8 *block;
1088
1089 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1090 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1091 (wl->conf.fwlog.mem_blocks == 0))
1092 return;
1093
1094 wl1271_info("Reading FW panic log");
1095
1096 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1097 if (!block)
1098 return;
1099
1100 /*
1101 * Make sure the chip is awake and the logger isn't active.
1102 * This might fail if the firmware hanged.
1103 */
1104 if (!wl1271_ps_elp_wakeup(wl))
1105 wl12xx_cmd_stop_fwlog(wl);
1106
1107 /* Read the first memory block address */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001108 wl12xx_fw_status(wl, wl->fw_status);
1109 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001110 if (!first_addr)
1111 goto out;
1112
1113 /* Traverse the memory blocks linked list */
1114 addr = first_addr;
1115 do {
1116 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1117 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1118 false);
1119
1120 /*
1121 * Memory blocks are linked to one another. The first 4 bytes
1122 * of each memory block hold the hardware address of the next
1123 * one. The last memory block points to the first one.
1124 */
Eliad Peller4d56ad92011-08-14 13:17:05 +03001125 addr = le32_to_cpup((__le32 *)block);
Ido Yariv95dac04f2011-06-06 14:57:06 +03001126 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1127 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1128 break;
1129 } while (addr && (addr != first_addr));
1130
1131 wake_up_interruptible(&wl->fwlog_waitq);
1132
1133out:
1134 kfree(block);
1135}
1136
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001137static void wl1271_recovery_work(struct work_struct *work)
1138{
1139 struct wl1271 *wl =
1140 container_of(work, struct wl1271, recovery_work);
Eliad Peller48e93e42011-10-10 10:12:58 +02001141 struct wl12xx_vif *wlvif;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001142 struct ieee80211_vif *vif;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001143
1144 mutex_lock(&wl->mutex);
1145
Eliad Peller3fcdab72012-02-06 12:47:54 +02001146 if (wl->state != WL1271_STATE_ON || wl->plt)
Eliad Pellerf0277432011-10-10 10:13:14 +02001147 goto out_unlock;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001148
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001149 /* Avoid a recursive recovery */
1150 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1151
Ido Yariv95dac04f2011-06-06 14:57:06 +03001152 wl12xx_read_fwlog_panic(wl);
1153
Arik Nemtsov52dcaf52011-04-18 14:15:24 +03001154 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1155 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001156
Eliad Peller2a5bff02011-08-25 18:10:59 +03001157 BUG_ON(bug_on_recovery);
1158
Oz Krakowskib992c682011-06-26 10:36:02 +03001159 /*
1160 * Advance security sequence number to overcome potential progress
1161 * in the firmware during recovery. This doens't hurt if the network is
1162 * not encrypted.
1163 */
Eliad Peller48e93e42011-10-10 10:12:58 +02001164 wl12xx_for_each_wlvif(wl, wlvif) {
Eliad Pellerba8447f2011-10-10 10:13:00 +02001165 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
Eliad Peller53d40d02011-10-10 10:13:02 +02001166 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Peller48e93e42011-10-10 10:12:58 +02001167 wlvif->tx_security_seq +=
1168 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1169 }
Oz Krakowskib992c682011-06-26 10:36:02 +03001170
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001171 /* Prevent spurious TX during FW restart */
1172 ieee80211_stop_queues(wl->hw);
1173
Luciano Coelho33c2c062011-05-10 14:46:02 +03001174 if (wl->sched_scanning) {
1175 ieee80211_sched_scan_stopped(wl->hw);
1176 wl->sched_scanning = false;
1177 }
1178
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001179 /* reboot the chipset */
Eliad Peller6e8cd332011-10-10 10:13:13 +02001180 while (!list_empty(&wl->wlvif_list)) {
1181 wlvif = list_first_entry(&wl->wlvif_list,
1182 struct wl12xx_vif, list);
1183 vif = wl12xx_wlvif_to_vif(wlvif);
1184 __wl1271_op_remove_interface(wl, vif, false);
1185 }
Eliad Pellerf0277432011-10-10 10:13:14 +02001186 mutex_unlock(&wl->mutex);
1187 wl1271_op_stop(wl->hw);
Ido Yarivbaacb9a2011-06-06 14:57:05 +03001188
1189 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1190
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001191 ieee80211_restart_hw(wl->hw);
1192
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03001193 /*
1194 * Its safe to enable TX now - the queues are stopped after a request
1195 * to restart the HW.
1196 */
1197 ieee80211_wake_queues(wl->hw);
Eliad Pellerf0277432011-10-10 10:13:14 +02001198 return;
1199out_unlock:
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001200 mutex_unlock(&wl->mutex);
1201}
1202
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001203static void wl1271_fw_wakeup(struct wl1271 *wl)
1204{
1205 u32 elp_reg;
1206
1207 elp_reg = ELPCTRL_WAKE_UP;
Juuso Oikarinen74621412009-10-12 15:08:54 +03001208 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001209}
1210
1211static int wl1271_setup(struct wl1271 *wl)
1212{
1213 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1214 if (!wl->fw_status)
1215 return -ENOMEM;
1216
1217 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1218 if (!wl->tx_res_if) {
1219 kfree(wl->fw_status);
1220 return -ENOMEM;
1221 }
1222
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001223 return 0;
1224}
1225
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001226static int wl12xx_set_power_on(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001227{
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001228 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001229
Juuso Oikarinen01ac17ec2009-12-11 15:41:02 +02001230 msleep(WL1271_PRE_POWER_ON_SLEEP);
Ohad Ben-Cohen2cc78ff2010-09-16 01:22:04 +02001231 ret = wl1271_power_on(wl);
1232 if (ret < 0)
1233 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001234 msleep(WL1271_POWER_ON_SLEEP);
Teemu Paasikivi9b280722010-02-18 13:25:56 +02001235 wl1271_io_reset(wl);
1236 wl1271_io_init(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001237
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001238 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001239
1240 /* ELP module wake up */
1241 wl1271_fw_wakeup(wl);
1242
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001243out:
1244 return ret;
1245}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001246
Eliad Peller3fcdab72012-02-06 12:47:54 +02001247static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02001248{
1249 int ret = 0;
1250
1251 ret = wl12xx_set_power_on(wl);
1252 if (ret < 0)
1253 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001254
Luciano Coelhoe62c9ce2011-11-03 08:44:42 +02001255 /*
1256 * For wl127x based devices we could use the default block
1257 * size (512 bytes), but due to a bug in the sdio driver, we
1258 * need to set it explicitly after the chip is powered on. To
1259 * simplify the code and since the performance impact is
1260 * negligible, we use the same block size for all different
1261 * chip types.
1262 */
1263 if (!wl1271_set_block_size(wl))
1264 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001265
1266 switch (wl->chip.id) {
1267 case CHIP_ID_1271_PG10:
1268 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1269 wl->chip.id);
1270
1271 ret = wl1271_setup(wl);
1272 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001273 goto out;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001274 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001275 break;
Luciano Coelhoce39def2011-11-03 08:44:41 +02001276
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001277 case CHIP_ID_1271_PG20:
1278 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
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
Shahar Levi0830cee2011-03-06 16:32:20 +02001287 case CHIP_ID_1283_PG20:
1288 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1289 wl->chip.id);
1290
1291 ret = wl1271_setup(wl);
1292 if (ret < 0)
1293 goto out;
1294 break;
1295 case CHIP_ID_1283_PG10:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001296 default:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001297 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001298 ret = -ENODEV;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001299 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001300 }
1301
Eliad Peller3fcdab72012-02-06 12:47:54 +02001302 ret = wl12xx_fetch_firmware(wl, plt);
1303 if (ret < 0)
1304 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001305
1306 /* No NVS from netlink, try to get it from the filesystem */
1307 if (wl->nvs == NULL) {
1308 ret = wl1271_fetch_nvs(wl);
1309 if (ret < 0)
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001310 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001311 }
1312
1313out:
1314 return ret;
1315}
1316
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001317int wl1271_plt_start(struct wl1271 *wl)
1318{
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001319 int retries = WL1271_BOOT_RETRIES;
Gery Kahn6f07b722011-07-18 14:21:49 +03001320 struct wiphy *wiphy = wl->hw->wiphy;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001321 int ret;
1322
1323 mutex_lock(&wl->mutex);
1324
1325 wl1271_notice("power up");
1326
1327 if (wl->state != WL1271_STATE_OFF) {
1328 wl1271_error("cannot go into PLT state because not "
1329 "in off state: %d", wl->state);
1330 ret = -EBUSY;
1331 goto out;
1332 }
1333
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001334 while (retries) {
1335 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001336 ret = wl12xx_chip_wakeup(wl, true);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001337 if (ret < 0)
1338 goto power_off;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001339
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001340 ret = wl1271_boot(wl);
1341 if (ret < 0)
1342 goto power_off;
1343
1344 ret = wl1271_plt_init(wl);
1345 if (ret < 0)
1346 goto irq_disable;
1347
Eliad Peller3fcdab72012-02-06 12:47:54 +02001348 wl->plt = true;
1349 wl->state = WL1271_STATE_ON;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001350 wl1271_notice("firmware booted in PLT mode (%s)",
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001351 wl->chip.fw_ver_str);
Luciano Coelhoe7ddf542011-03-10 15:24:57 +02001352
Gery Kahn6f07b722011-07-18 14:21:49 +03001353 /* update hw/fw version info in wiphy struct */
1354 wiphy->hw_version = wl->chip.id;
1355 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1356 sizeof(wiphy->fw_version));
1357
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001358 goto out;
1359
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001360irq_disable:
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001361 mutex_unlock(&wl->mutex);
1362 /* Unlocking the mutex in the middle of handling is
1363 inherently unsafe. In this case we deem it safe to do,
1364 because we need to let any possibly pending IRQ out of
1365 the system (and while we are WL1271_STATE_OFF the IRQ
1366 work function will not do anything.) Also, any other
1367 possible concurrent operations will fail due to the
1368 current state, hence the wl1271 struct should be safe. */
Ido Yariva6208652011-03-01 15:14:41 +02001369 wl1271_disable_interrupts(wl);
1370 wl1271_flush_deferred_work(wl);
1371 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001372 mutex_lock(&wl->mutex);
1373power_off:
1374 wl1271_power_off(wl);
1375 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001376
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02001377 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1378 WL1271_BOOT_RETRIES);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001379out:
1380 mutex_unlock(&wl->mutex);
1381
1382 return ret;
1383}
1384
Ido Yarivf3df1332012-01-11 09:42:39 +02001385int wl1271_plt_stop(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001386{
1387 int ret = 0;
1388
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001389 wl1271_notice("power down");
1390
Ido Yariv46b0cc92012-01-11 09:42:41 +02001391 /*
1392 * Interrupts must be disabled before setting the state to OFF.
1393 * Otherwise, the interrupt handler might be called and exit without
1394 * reading the interrupt status.
1395 */
1396 wl1271_disable_interrupts(wl);
Ido Yarivf3df1332012-01-11 09:42:39 +02001397 mutex_lock(&wl->mutex);
Eliad Peller3fcdab72012-02-06 12:47:54 +02001398 if (!wl->plt) {
Ido Yarivf3df1332012-01-11 09:42:39 +02001399 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001400
1401 /*
1402 * This will not necessarily enable interrupts as interrupts
1403 * may have been disabled when op_stop was called. It will,
1404 * however, balance the above call to disable_interrupts().
1405 */
1406 wl1271_enable_interrupts(wl);
1407
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001408 wl1271_error("cannot power down because not in PLT "
1409 "state: %d", wl->state);
1410 ret = -EBUSY;
1411 goto out;
1412 }
1413
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001414 mutex_unlock(&wl->mutex);
Ido Yarivf3df1332012-01-11 09:42:39 +02001415
Ido Yariva6208652011-03-01 15:14:41 +02001416 wl1271_flush_deferred_work(wl);
1417 cancel_work_sync(&wl->netstack_work);
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +02001418 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001419 cancel_delayed_work_sync(&wl->elp_work);
Ido Yariva4549692012-01-11 09:42:40 +02001420
1421 mutex_lock(&wl->mutex);
1422 wl1271_power_off(wl);
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001423 wl->flags = 0;
1424 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001425 wl->plt = false;
Luciano Coelhof6fbecc2012-01-11 09:42:42 +02001426 wl->rx_counter = 0;
Ido Yariva4549692012-01-11 09:42:40 +02001427 mutex_unlock(&wl->mutex);
1428
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01001429out:
1430 return ret;
1431}
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +02001432
Johannes Berg7bb45682011-02-24 14:42:06 +01001433static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001434{
1435 struct wl1271 *wl = hw->priv;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001436 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1437 struct ieee80211_vif *vif = info->control.vif;
Eliad Peller0f168012011-10-11 13:52:25 +02001438 struct wl12xx_vif *wlvif = NULL;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001439 unsigned long flags;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001440 int q, mapping;
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001441 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001442
Eliad Peller0f168012011-10-11 13:52:25 +02001443 if (vif)
1444 wlvif = wl12xx_vif_to_data(vif);
1445
Arik Nemtsov708bb3c2011-06-24 13:03:37 +03001446 mapping = skb_get_queue_mapping(skb);
1447 q = wl1271_tx_get_queue(mapping);
Ido Yarivb07d4032011-03-01 15:14:43 +02001448
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001449 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
Ido Yarivb07d4032011-03-01 15:14:43 +02001450
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001451 spin_lock_irqsave(&wl->wl_lock, flags);
Ido Yarivb07d4032011-03-01 15:14:43 +02001452
Juuso Oikarinen830fb672009-12-11 15:41:06 +02001453 /* queue the packet */
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001454 if (hlid == WL12XX_INVALID_LINK_ID ||
Eliad Peller0f168012011-10-11 13:52:25 +02001455 (wlvif && !test_bit(hlid, wlvif->links_map))) {
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001456 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
Eliad Peller5de8eef2011-12-13 15:26:38 +02001457 ieee80211_free_txskb(hw, skb);
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001458 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02001459 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001460
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02001461 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1462 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1463
Arik Nemtsov04b4d692011-08-14 13:17:39 +03001464 wl->tx_queue_count[q]++;
1465
1466 /*
1467 * The workqueue is slow to process the tx_queue and we need stop
1468 * the queue here, otherwise the queue will get too long.
1469 */
1470 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1471 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1472 ieee80211_stop_queue(wl->hw, mapping);
1473 set_bit(q, &wl->stopped_queues_map);
1474 }
1475
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001476 /*
1477 * The chip specific setup must run before the first TX packet -
1478 * before that, the tx_work will not be initialized!
1479 */
1480
Ido Yarivb07d4032011-03-01 15:14:43 +02001481 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1482 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
Ido Yariva5225502010-10-12 14:49:10 +02001483 ieee80211_queue_work(wl->hw, &wl->tx_work);
Ido Yarivb07d4032011-03-01 15:14:43 +02001484
Arik Nemtsov04216da2011-08-14 13:17:38 +03001485out:
Ido Yarivb07d4032011-03-01 15:14:43 +02001486 spin_unlock_irqrestore(&wl->wl_lock, flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001487}
1488
Shahar Leviae47c452011-03-06 16:32:14 +02001489int wl1271_tx_dummy_packet(struct wl1271 *wl)
1490{
Ido Yariv990f5de2011-03-31 10:06:59 +02001491 unsigned long flags;
Arik Nemtsov14623782011-08-28 15:11:57 +03001492 int q;
1493
1494 /* no need to queue a new dummy packet if one is already pending */
1495 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1496 return 0;
1497
1498 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
Shahar Leviae47c452011-03-06 16:32:14 +02001499
Ido Yariv990f5de2011-03-31 10:06:59 +02001500 spin_lock_irqsave(&wl->wl_lock, flags);
1501 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +03001502 wl->tx_queue_count[q]++;
Ido Yariv990f5de2011-03-31 10:06:59 +02001503 spin_unlock_irqrestore(&wl->wl_lock, flags);
1504
1505 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1506 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
Eliad Pellera32d0cd2011-10-10 10:12:55 +02001507 wl1271_tx_work_locked(wl);
Ido Yariv990f5de2011-03-31 10:06:59 +02001508
1509 /*
1510 * If the FW TX is busy, TX work will be scheduled by the threaded
1511 * interrupt handler function
1512 */
1513 return 0;
1514}
1515
1516/*
1517 * The size of the dummy packet should be at least 1400 bytes. However, in
1518 * order to minimize the number of bus transactions, aligning it to 512 bytes
1519 * boundaries could be beneficial, performance wise
1520 */
1521#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1522
Luciano Coelhocf27d862011-04-01 21:08:23 +03001523static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
Ido Yariv990f5de2011-03-31 10:06:59 +02001524{
1525 struct sk_buff *skb;
1526 struct ieee80211_hdr_3addr *hdr;
1527 unsigned int dummy_packet_size;
1528
1529 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1530 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1531
1532 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
Shahar Leviae47c452011-03-06 16:32:14 +02001533 if (!skb) {
Ido Yariv990f5de2011-03-31 10:06:59 +02001534 wl1271_warning("Failed to allocate a dummy packet skb");
1535 return NULL;
Shahar Leviae47c452011-03-06 16:32:14 +02001536 }
1537
1538 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1539
1540 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1541 memset(hdr, 0, sizeof(*hdr));
1542 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
Ido Yariv990f5de2011-03-31 10:06:59 +02001543 IEEE80211_STYPE_NULLFUNC |
1544 IEEE80211_FCTL_TODS);
Shahar Leviae47c452011-03-06 16:32:14 +02001545
Ido Yariv990f5de2011-03-31 10:06:59 +02001546 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
Shahar Leviae47c452011-03-06 16:32:14 +02001547
Luciano Coelho18b92ff2011-03-21 16:35:21 +02001548 /* Dummy packets require the TID to be management */
1549 skb->priority = WL1271_TID_MGMT;
Ido Yariv990f5de2011-03-31 10:06:59 +02001550
1551 /* Initialize all fields that might be used */
Hauke Mehrtens86c438f2011-04-26 23:27:44 +02001552 skb_set_queue_mapping(skb, 0);
Ido Yariv990f5de2011-03-31 10:06:59 +02001553 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
Shahar Leviae47c452011-03-06 16:32:14 +02001554
Ido Yariv990f5de2011-03-31 10:06:59 +02001555 return skb;
Shahar Leviae47c452011-03-06 16:32:14 +02001556}
1557
Ido Yariv990f5de2011-03-31 10:06:59 +02001558
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001559#ifdef CONFIG_PM
Eyal Shapiradae728f2012-02-02 12:03:39 +02001560static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1561 struct wl12xx_vif *wlvif)
1562{
1563 int ret = 0;
1564
1565 mutex_lock(&wl->mutex);
1566
1567 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1568 goto out_unlock;
1569
1570 ret = wl1271_ps_elp_wakeup(wl);
1571 if (ret < 0)
1572 goto out_unlock;
1573
1574 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1575 wl->conf.conn.suspend_wake_up_event,
1576 wl->conf.conn.suspend_listen_interval);
1577
1578 if (ret < 0)
1579 wl1271_error("suspend: set wake up conditions failed: %d", ret);
1580
1581
1582 wl1271_ps_elp_sleep(wl);
1583
1584out_unlock:
1585 mutex_unlock(&wl->mutex);
1586 return ret;
1587
1588}
Eliad Peller94390642011-05-13 11:57:13 +03001589
Eliad Peller0603d892011-10-05 11:55:51 +02001590static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1591 struct wl12xx_vif *wlvif)
Eliad Peller94390642011-05-13 11:57:13 +03001592{
Eliad Pellere85d1622011-06-27 13:06:43 +03001593 int ret = 0;
Eliad Peller94390642011-05-13 11:57:13 +03001594
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001595 mutex_lock(&wl->mutex);
1596
Eliad Peller53d40d02011-10-10 10:13:02 +02001597 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
Eliad Pellere85d1622011-06-27 13:06:43 +03001598 goto out_unlock;
1599
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001600 ret = wl1271_ps_elp_wakeup(wl);
1601 if (ret < 0)
1602 goto out_unlock;
1603
Eliad Peller0603d892011-10-05 11:55:51 +02001604 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001605
1606 wl1271_ps_elp_sleep(wl);
1607out_unlock:
1608 mutex_unlock(&wl->mutex);
1609 return ret;
1610
1611}
1612
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001613static int wl1271_configure_suspend(struct wl1271 *wl,
1614 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001615{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001616 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1617 return wl1271_configure_suspend_sta(wl, wlvif);
Eliad Peller536129c2011-10-05 11:55:45 +02001618 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
Eliad Peller0603d892011-10-05 11:55:51 +02001619 return wl1271_configure_suspend_ap(wl, wlvif);
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001620 return 0;
1621}
1622
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001623static void wl1271_configure_resume(struct wl1271 *wl,
1624 struct wl12xx_vif *wlvif)
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001625{
Eyal Shapiradae728f2012-02-02 12:03:39 +02001626 int ret = 0;
Eliad Peller536129c2011-10-05 11:55:45 +02001627 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
Eyal Shapiradae728f2012-02-02 12:03:39 +02001628 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
Eliad Peller8a7cf3f2011-06-06 12:21:54 +03001629
Eyal Shapiradae728f2012-02-02 12:03:39 +02001630 if ((!is_ap) && (!is_sta))
Eliad Peller94390642011-05-13 11:57:13 +03001631 return;
1632
1633 mutex_lock(&wl->mutex);
1634 ret = wl1271_ps_elp_wakeup(wl);
1635 if (ret < 0)
1636 goto out;
1637
Eyal Shapiradae728f2012-02-02 12:03:39 +02001638 if (is_sta) {
1639 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1640 wl->conf.conn.wake_up_event,
1641 wl->conf.conn.listen_interval);
1642
1643 if (ret < 0)
1644 wl1271_error("resume: wake up conditions failed: %d",
1645 ret);
1646
1647 } else if (is_ap) {
1648 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1649 }
Eliad Peller94390642011-05-13 11:57:13 +03001650
1651 wl1271_ps_elp_sleep(wl);
1652out:
1653 mutex_unlock(&wl->mutex);
1654}
1655
Eliad Peller402e48612011-05-13 11:57:09 +03001656static int wl1271_op_suspend(struct ieee80211_hw *hw,
1657 struct cfg80211_wowlan *wow)
1658{
1659 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001660 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001661 int ret;
1662
Eliad Peller402e48612011-05-13 11:57:09 +03001663 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
Eliad Peller4a859df2011-06-06 12:21:52 +03001664 WARN_ON(!wow || !wow->any);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001665
Arik Nemtsovb9239b62012-02-28 00:41:33 +02001666 wl1271_tx_flush(wl);
1667
Eliad Peller4a859df2011-06-06 12:21:52 +03001668 wl->wow_enabled = true;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001669 wl12xx_for_each_wlvif(wl, wlvif) {
1670 ret = wl1271_configure_suspend(wl, wlvif);
1671 if (ret < 0) {
1672 wl1271_warning("couldn't prepare device to suspend");
1673 return ret;
1674 }
Eliad Pellerf44e5862011-05-13 11:57:11 +03001675 }
Eliad Peller4a859df2011-06-06 12:21:52 +03001676 /* flush any remaining work */
1677 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
Eliad Peller4a859df2011-06-06 12:21:52 +03001678
1679 /*
1680 * disable and re-enable interrupts in order to flush
1681 * the threaded_irq
1682 */
1683 wl1271_disable_interrupts(wl);
1684
1685 /*
1686 * set suspended flag to avoid triggering a new threaded_irq
1687 * work. no need for spinlock as interrupts are disabled.
1688 */
1689 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1690
1691 wl1271_enable_interrupts(wl);
1692 flush_work(&wl->tx_work);
Eliad Peller4a859df2011-06-06 12:21:52 +03001693 flush_delayed_work(&wl->elp_work);
1694
Eliad Peller402e48612011-05-13 11:57:09 +03001695 return 0;
1696}
1697
1698static int wl1271_op_resume(struct ieee80211_hw *hw)
1699{
1700 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001701 struct wl12xx_vif *wlvif;
Eliad Peller4a859df2011-06-06 12:21:52 +03001702 unsigned long flags;
1703 bool run_irq_work = false;
1704
Eliad Peller402e48612011-05-13 11:57:09 +03001705 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1706 wl->wow_enabled);
Eliad Peller4a859df2011-06-06 12:21:52 +03001707 WARN_ON(!wl->wow_enabled);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001708
1709 /*
1710 * re-enable irq_work enqueuing, and call irq_work directly if
1711 * there is a pending work.
1712 */
Eliad Peller4a859df2011-06-06 12:21:52 +03001713 spin_lock_irqsave(&wl->wl_lock, flags);
1714 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1715 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1716 run_irq_work = true;
1717 spin_unlock_irqrestore(&wl->wl_lock, flags);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001718
Eliad Peller4a859df2011-06-06 12:21:52 +03001719 if (run_irq_work) {
1720 wl1271_debug(DEBUG_MAC80211,
1721 "run postponed irq_work directly");
1722 wl1271_irq(0, wl);
1723 wl1271_enable_interrupts(wl);
Eliad Pellerf44e5862011-05-13 11:57:11 +03001724 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02001725 wl12xx_for_each_wlvif(wl, wlvif) {
1726 wl1271_configure_resume(wl, wlvif);
1727 }
Eliad Pellerff91afc2011-06-06 12:21:53 +03001728 wl->wow_enabled = false;
Eliad Pellerf44e5862011-05-13 11:57:11 +03001729
Eliad Peller402e48612011-05-13 11:57:09 +03001730 return 0;
1731}
Luciano Coelhof634a4e2011-05-18 16:51:26 -04001732#endif
Eliad Peller402e48612011-05-13 11:57:09 +03001733
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001734static int wl1271_op_start(struct ieee80211_hw *hw)
1735{
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001736 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1737
1738 /*
1739 * We have to delay the booting of the hardware because
1740 * we need to know the local MAC address before downloading and
1741 * initializing the firmware. The MAC address cannot be changed
1742 * after boot, and without the proper MAC address, the firmware
1743 * will not function properly.
1744 *
1745 * The MAC address is first known when the corresponding interface
1746 * is added. That is where we will initialize the hardware.
1747 */
1748
Eyal Shapirad18da7f2012-01-31 11:57:25 +02001749 return 0;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001750}
1751
1752static void wl1271_op_stop(struct ieee80211_hw *hw)
1753{
Eliad Pellerbaf62772011-10-10 10:12:52 +02001754 struct wl1271 *wl = hw->priv;
1755 int i;
1756
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001757 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
Eliad Pellerbaf62772011-10-10 10:12:52 +02001758
Ido Yariv46b0cc92012-01-11 09:42:41 +02001759 /*
1760 * Interrupts must be disabled before setting the state to OFF.
1761 * Otherwise, the interrupt handler might be called and exit without
1762 * reading the interrupt status.
1763 */
1764 wl1271_disable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001765 mutex_lock(&wl->mutex);
1766 if (wl->state == WL1271_STATE_OFF) {
1767 mutex_unlock(&wl->mutex);
Ido Yariv46b0cc92012-01-11 09:42:41 +02001768
1769 /*
1770 * This will not necessarily enable interrupts as interrupts
1771 * may have been disabled when op_stop was called. It will,
1772 * however, balance the above call to disable_interrupts().
1773 */
1774 wl1271_enable_interrupts(wl);
Eliad Peller10c8cd02011-10-10 10:13:06 +02001775 return;
1776 }
Ido Yariv46b0cc92012-01-11 09:42:41 +02001777
Eliad Pellerbaf62772011-10-10 10:12:52 +02001778 /*
1779 * this must be before the cancel_work calls below, so that the work
1780 * functions don't perform further work.
1781 */
1782 wl->state = WL1271_STATE_OFF;
Eliad Peller10c8cd02011-10-10 10:13:06 +02001783 mutex_unlock(&wl->mutex);
1784
Eliad Pellerbaf62772011-10-10 10:12:52 +02001785 wl1271_flush_deferred_work(wl);
1786 cancel_delayed_work_sync(&wl->scan_complete_work);
1787 cancel_work_sync(&wl->netstack_work);
1788 cancel_work_sync(&wl->tx_work);
Eliad Pellerbaf62772011-10-10 10:12:52 +02001789 cancel_delayed_work_sync(&wl->elp_work);
1790
1791 /* let's notify MAC80211 about the remaining pending TX frames */
1792 wl12xx_tx_reset(wl, true);
1793 mutex_lock(&wl->mutex);
1794
1795 wl1271_power_off(wl);
1796
1797 wl->band = IEEE80211_BAND_2GHZ;
1798
1799 wl->rx_counter = 0;
1800 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1801 wl->tx_blocks_available = 0;
1802 wl->tx_allocated_blocks = 0;
1803 wl->tx_results_count = 0;
1804 wl->tx_packets_count = 0;
1805 wl->time_offset = 0;
Eliad Pellerbaf62772011-10-10 10:12:52 +02001806 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1807 wl->ap_fw_ps_map = 0;
1808 wl->ap_ps_map = 0;
1809 wl->sched_scanning = false;
1810 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1811 memset(wl->links_map, 0, sizeof(wl->links_map));
1812 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1813 wl->active_sta_count = 0;
1814
1815 /* The system link is always allocated */
1816 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1817
1818 /*
1819 * this is performed after the cancel_work calls and the associated
1820 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1821 * get executed before all these vars have been reset.
1822 */
1823 wl->flags = 0;
1824
1825 wl->tx_blocks_freed = 0;
1826
1827 for (i = 0; i < NUM_TX_QUEUES; i++) {
1828 wl->tx_pkts_freed[i] = 0;
1829 wl->tx_allocated_pkts[i] = 0;
1830 }
1831
1832 wl1271_debugfs_reset(wl);
1833
1834 kfree(wl->fw_status);
1835 wl->fw_status = NULL;
1836 kfree(wl->tx_res_if);
1837 wl->tx_res_if = NULL;
1838 kfree(wl->target_mem_map);
1839 wl->target_mem_map = NULL;
1840
1841 mutex_unlock(&wl->mutex);
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02001842}
1843
Eliad Pellere5a359f2011-10-10 10:13:15 +02001844static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1845{
1846 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1847 WL12XX_MAX_RATE_POLICIES);
1848 if (policy >= WL12XX_MAX_RATE_POLICIES)
1849 return -EBUSY;
1850
1851 __set_bit(policy, wl->rate_policies_map);
1852 *idx = policy;
1853 return 0;
1854}
1855
1856static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1857{
1858 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1859 return;
1860
1861 __clear_bit(*idx, wl->rate_policies_map);
1862 *idx = WL12XX_MAX_RATE_POLICIES;
1863}
1864
Eliad Peller536129c2011-10-05 11:55:45 +02001865static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001866{
Eliad Peller536129c2011-10-05 11:55:45 +02001867 switch (wlvif->bss_type) {
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001868 case BSS_TYPE_AP_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001869 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001870 return WL1271_ROLE_P2P_GO;
1871 else
1872 return WL1271_ROLE_AP;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001873
1874 case BSS_TYPE_STA_BSS:
Eliad Pellerfb0e7072011-10-05 11:55:47 +02001875 if (wlvif->p2p)
Eliad Peller045c7452011-08-28 15:23:01 +03001876 return WL1271_ROLE_P2P_CL;
1877 else
1878 return WL1271_ROLE_STA;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001879
Eliad Peller227e81e2011-08-14 13:17:26 +03001880 case BSS_TYPE_IBSS:
1881 return WL1271_ROLE_IBSS;
1882
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001883 default:
Eliad Peller536129c2011-10-05 11:55:45 +02001884 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03001885 }
1886 return WL12XX_INVALID_ROLE_TYPE;
1887}
1888
Eliad Peller83587502011-10-10 10:12:53 +02001889static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Eliad Peller87fbcb02011-10-05 11:55:41 +02001890{
Eliad Pellere936bbe2011-10-05 11:55:56 +02001891 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02001892 int i;
Eliad Pellere936bbe2011-10-05 11:55:56 +02001893
Eliad Peller48e93e42011-10-10 10:12:58 +02001894 /* clear everything but the persistent data */
1895 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
Eliad Pellere936bbe2011-10-05 11:55:56 +02001896
1897 switch (ieee80211_vif_type_p2p(vif)) {
1898 case NL80211_IFTYPE_P2P_CLIENT:
1899 wlvif->p2p = 1;
1900 /* fall-through */
1901 case NL80211_IFTYPE_STATION:
1902 wlvif->bss_type = BSS_TYPE_STA_BSS;
1903 break;
1904 case NL80211_IFTYPE_ADHOC:
1905 wlvif->bss_type = BSS_TYPE_IBSS;
1906 break;
1907 case NL80211_IFTYPE_P2P_GO:
1908 wlvif->p2p = 1;
1909 /* fall-through */
1910 case NL80211_IFTYPE_AP:
1911 wlvif->bss_type = BSS_TYPE_AP_BSS;
1912 break;
1913 default:
1914 wlvif->bss_type = MAX_BSS_TYPE;
1915 return -EOPNOTSUPP;
1916 }
1917
Eliad Peller0603d892011-10-05 11:55:51 +02001918 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02001919 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02001920 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001921
Eliad Pellere936bbe2011-10-05 11:55:56 +02001922 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1923 wlvif->bss_type == BSS_TYPE_IBSS) {
1924 /* init sta/ibss data */
1925 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001926 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1927 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1928 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001929 } else {
1930 /* init ap data */
1931 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1932 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02001933 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1934 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1935 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1936 wl12xx_allocate_rate_policy(wl,
1937 &wlvif->ap.ucast_rate_idx[i]);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001938 }
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001939
Eliad Peller83587502011-10-10 10:12:53 +02001940 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1941 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001942 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001943 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
Eliad Peller30d0c8f2011-10-05 11:55:42 +02001944 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
Eliad Peller6a899792011-10-05 11:55:58 +02001945 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1946
Eliad Peller1b92f152011-10-10 10:13:09 +02001947 /*
1948 * mac80211 configures some values globally, while we treat them
1949 * per-interface. thus, on init, we have to copy them from wl
1950 */
1951 wlvif->band = wl->band;
Eliad Peller61f845f2011-10-10 10:13:10 +02001952 wlvif->channel = wl->channel;
Eliad Peller6bd65022011-10-10 10:13:11 +02001953 wlvif->power_level = wl->power_level;
Eliad Peller1b92f152011-10-10 10:13:09 +02001954
Eliad Peller9eb599e2011-10-10 10:12:59 +02001955 INIT_WORK(&wlvif->rx_streaming_enable_work,
1956 wl1271_rx_streaming_enable_work);
1957 INIT_WORK(&wlvif->rx_streaming_disable_work,
1958 wl1271_rx_streaming_disable_work);
Eliad Peller87627212011-10-10 10:12:54 +02001959 INIT_LIST_HEAD(&wlvif->list);
Eliad Peller252efa42011-10-05 11:56:00 +02001960
Eliad Peller9eb599e2011-10-10 10:12:59 +02001961 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1962 (unsigned long) wlvif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02001963 return 0;
Eliad Peller87fbcb02011-10-05 11:55:41 +02001964}
1965
Eliad Peller1d095472011-10-10 10:12:49 +02001966static bool wl12xx_init_fw(struct wl1271 *wl)
1967{
1968 int retries = WL1271_BOOT_RETRIES;
1969 bool booted = false;
1970 struct wiphy *wiphy = wl->hw->wiphy;
1971 int ret;
1972
1973 while (retries) {
1974 retries--;
Eliad Peller3fcdab72012-02-06 12:47:54 +02001975 ret = wl12xx_chip_wakeup(wl, false);
Eliad Peller1d095472011-10-10 10:12:49 +02001976 if (ret < 0)
1977 goto power_off;
1978
1979 ret = wl1271_boot(wl);
1980 if (ret < 0)
1981 goto power_off;
1982
1983 ret = wl1271_hw_init(wl);
1984 if (ret < 0)
1985 goto irq_disable;
1986
1987 booted = true;
1988 break;
1989
1990irq_disable:
1991 mutex_unlock(&wl->mutex);
1992 /* Unlocking the mutex in the middle of handling is
1993 inherently unsafe. In this case we deem it safe to do,
1994 because we need to let any possibly pending IRQ out of
1995 the system (and while we are WL1271_STATE_OFF the IRQ
1996 work function will not do anything.) Also, any other
1997 possible concurrent operations will fail due to the
1998 current state, hence the wl1271 struct should be safe. */
1999 wl1271_disable_interrupts(wl);
2000 wl1271_flush_deferred_work(wl);
2001 cancel_work_sync(&wl->netstack_work);
2002 mutex_lock(&wl->mutex);
2003power_off:
2004 wl1271_power_off(wl);
2005 }
2006
2007 if (!booted) {
2008 wl1271_error("firmware boot failed despite %d retries",
2009 WL1271_BOOT_RETRIES);
2010 goto out;
2011 }
2012
2013 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
2014
2015 /* update hw/fw version info in wiphy struct */
2016 wiphy->hw_version = wl->chip.id;
2017 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
2018 sizeof(wiphy->fw_version));
2019
2020 /*
2021 * Now we know if 11a is supported (info from the NVS), so disable
2022 * 11a channels if not supported
2023 */
2024 if (!wl->enable_11a)
2025 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2026
2027 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2028 wl->enable_11a ? "" : "not ");
2029
2030 wl->state = WL1271_STATE_ON;
2031out:
2032 return booted;
2033}
2034
Eliad Peller92e712d2011-12-18 20:25:43 +02002035static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2036{
2037 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2038}
2039
Eliad Peller4549d092012-02-06 13:07:52 +02002040/*
2041 * Check whether a fw switch (i.e. moving from one loaded
2042 * fw to another) is needed. This function is also responsible
2043 * for updating wl->last_vif_count, so it must be called before
2044 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2045 * will be used).
2046 */
2047static bool wl12xx_need_fw_change(struct wl1271 *wl,
2048 struct vif_counter_data vif_counter_data,
2049 bool add)
2050{
2051 enum wl12xx_fw_type current_fw = wl->fw_type;
2052 u8 vif_count = vif_counter_data.counter;
2053
2054 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
2055 return false;
2056
2057 /* increase the vif count if this is a new vif */
2058 if (add && !vif_counter_data.cur_vif_running)
2059 vif_count++;
2060
2061 wl->last_vif_count = vif_count;
2062
2063 /* no need for fw change if the device is OFF */
2064 if (wl->state == WL1271_STATE_OFF)
2065 return false;
2066
2067 if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
2068 return true;
2069 if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
2070 return true;
2071
2072 return false;
2073}
2074
Eliad Peller3dee4392012-02-06 12:47:56 +02002075/*
2076 * Enter "forced psm". Make sure the sta is in psm against the ap,
2077 * to make the fw switch a bit more disconnection-persistent.
2078 */
2079static void wl12xx_force_active_psm(struct wl1271 *wl)
2080{
2081 struct wl12xx_vif *wlvif;
2082
2083 wl12xx_for_each_wlvif_sta(wl, wlvif) {
2084 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
2085 }
2086}
2087
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002088static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2089 struct ieee80211_vif *vif)
2090{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002091 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002092 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller4549d092012-02-06 13:07:52 +02002093 struct vif_counter_data vif_count;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002094 int ret = 0;
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002095 u8 role_type;
Eliad Peller71125ab2010-10-28 21:46:43 +02002096 bool booted = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002097
Johannes Bergea086352012-01-19 09:29:58 +01002098 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2099 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
Johannes Bergc1288b12012-01-19 09:29:57 +01002100
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002101 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
Eliad Peller045c7452011-08-28 15:23:01 +03002102 ieee80211_vif_type_p2p(vif), vif->addr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002103
Eliad Peller4549d092012-02-06 13:07:52 +02002104 wl12xx_get_vif_count(hw, vif, &vif_count);
2105
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002106 mutex_lock(&wl->mutex);
Eliad Pellerf750c822011-10-10 10:13:16 +02002107 ret = wl1271_ps_elp_wakeup(wl);
2108 if (ret < 0)
2109 goto out_unlock;
2110
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002111 /*
2112 * in some very corner case HW recovery scenarios its possible to
2113 * get here before __wl1271_op_remove_interface is complete, so
2114 * opt out if that is the case.
2115 */
Eliad Peller10c8cd02011-10-10 10:13:06 +02002116 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2117 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002118 ret = -EBUSY;
2119 goto out;
2120 }
2121
Eliad Peller3fcdab72012-02-06 12:47:54 +02002122
Eliad Peller83587502011-10-10 10:12:53 +02002123 ret = wl12xx_init_vif_data(wl, vif);
Eliad Pellere936bbe2011-10-05 11:55:56 +02002124 if (ret < 0)
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002125 goto out;
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002126
Eliad Peller252efa42011-10-05 11:56:00 +02002127 wlvif->wl = wl;
Eliad Peller536129c2011-10-05 11:55:45 +02002128 role_type = wl12xx_get_role_type(wl, wlvif);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002129 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2130 ret = -EINVAL;
2131 goto out;
2132 }
Eliad Peller1d095472011-10-10 10:12:49 +02002133
Eliad Peller4549d092012-02-06 13:07:52 +02002134 if (wl12xx_need_fw_change(wl, vif_count, true)) {
Eliad Peller3dee4392012-02-06 12:47:56 +02002135 wl12xx_force_active_psm(wl);
Eliad Peller4549d092012-02-06 13:07:52 +02002136 mutex_unlock(&wl->mutex);
2137 wl1271_recovery_work(&wl->recovery_work);
2138 return 0;
2139 }
2140
Eliad Peller784f6942011-10-05 11:55:39 +02002141 /*
Eliad Peller1d095472011-10-10 10:12:49 +02002142 * TODO: after the nvs issue will be solved, move this block
2143 * to start(), and make sure here the driver is ON.
Eliad Peller784f6942011-10-05 11:55:39 +02002144 */
Eliad Peller1d095472011-10-10 10:12:49 +02002145 if (wl->state == WL1271_STATE_OFF) {
2146 /*
2147 * we still need this in order to configure the fw
2148 * while uploading the nvs
2149 */
Luciano Coelho5e037e72011-12-23 09:32:17 +02002150 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002151
Eliad Peller1d095472011-10-10 10:12:49 +02002152 booted = wl12xx_init_fw(wl);
2153 if (!booted) {
2154 ret = -EINVAL;
2155 goto out;
Eliad Peller04e80792011-08-14 13:17:09 +03002156 }
Eliad Peller1d095472011-10-10 10:12:49 +02002157 }
Eliad Peller04e80792011-08-14 13:17:09 +03002158
Eliad Peller1d095472011-10-10 10:12:49 +02002159 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2160 wlvif->bss_type == BSS_TYPE_IBSS) {
2161 /*
2162 * The device role is a special role used for
2163 * rx and tx frames prior to association (as
2164 * the STA role can get packets only from
2165 * its associated bssid)
2166 */
Eliad Peller784f6942011-10-05 11:55:39 +02002167 ret = wl12xx_cmd_role_enable(wl, vif->addr,
Eliad Peller1d095472011-10-10 10:12:49 +02002168 WL1271_ROLE_DEVICE,
2169 &wlvif->dev_role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002170 if (ret < 0)
Eliad Peller1d095472011-10-10 10:12:49 +02002171 goto out;
Juuso Oikarinen9ccd9212009-12-11 15:41:01 +02002172 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002173
Eliad Peller1d095472011-10-10 10:12:49 +02002174 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2175 role_type, &wlvif->role_id);
2176 if (ret < 0)
Eliad Peller71125ab2010-10-28 21:46:43 +02002177 goto out;
Eliad Peller1d095472011-10-10 10:12:49 +02002178
2179 ret = wl1271_init_vif_specific(wl, vif);
2180 if (ret < 0)
2181 goto out;
Eliad Peller71125ab2010-10-28 21:46:43 +02002182
Eliad Peller87627212011-10-10 10:12:54 +02002183 list_add(&wlvif->list, &wl->wlvif_list);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002184 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
Eliad Pellera4e41302011-10-11 11:49:15 +02002185
2186 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2187 wl->ap_count++;
2188 else
2189 wl->sta_count++;
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +03002190out:
Eliad Pellerf750c822011-10-10 10:13:16 +02002191 wl1271_ps_elp_sleep(wl);
2192out_unlock:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002193 mutex_unlock(&wl->mutex);
2194
2195 return ret;
2196}
2197
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002198static void __wl1271_op_remove_interface(struct wl1271 *wl,
Eliad Peller536129c2011-10-05 11:55:45 +02002199 struct ieee80211_vif *vif,
Arik Nemtsov7dece1c2011-04-18 14:15:28 +03002200 bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002201{
Eliad Peller536129c2011-10-05 11:55:45 +02002202 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pellere5a359f2011-10-10 10:13:15 +02002203 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002204
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002205 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002206
Eliad Peller10c8cd02011-10-10 10:13:06 +02002207 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2208 return;
2209
Juuso Oikarinen13026de2011-03-29 16:43:50 +03002210 /* because of hardware recovery, we may get here twice */
2211 if (wl->state != WL1271_STATE_ON)
2212 return;
2213
Juuso Oikarinen1b72aec2010-03-18 12:26:39 +02002214 wl1271_info("down");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002215
Eliad Pellerbaf62772011-10-10 10:12:52 +02002216 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2217 wl->scan_vif == vif) {
Luciano Coelho08688d62010-07-08 17:50:07 +03002218 wl->scan.state = WL1271_SCAN_STATE_IDLE;
Luciano Coelho4a31c112011-03-21 23:16:14 +02002219 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02002220 wl->scan_vif = NULL;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02002221 wl->scan.req = NULL;
Juuso Oikarinen76a029f2010-07-29 04:54:45 +03002222 ieee80211_scan_completed(wl->hw, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002223 }
2224
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002225 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2226 /* disable active roles */
2227 ret = wl1271_ps_elp_wakeup(wl);
2228 if (ret < 0)
2229 goto deinit;
2230
Eliad Pellerb890f4c2011-12-18 20:25:44 +02002231 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2232 wlvif->bss_type == BSS_TYPE_IBSS) {
2233 if (wl12xx_dev_role_started(wlvif))
2234 wl12xx_stop_dev(wl, wlvif);
2235
Eliad Peller7edebf52011-10-05 11:55:52 +02002236 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +03002237 if (ret < 0)
2238 goto deinit;
2239 }
2240
Eliad Peller0603d892011-10-05 11:55:51 +02002241 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002242 if (ret < 0)
2243 goto deinit;
2244
2245 wl1271_ps_elp_sleep(wl);
2246 }
2247deinit:
Arik Nemtsove51ae9b2011-08-14 13:17:21 +03002248 /* clear all hlids (except system_hlid) */
Eliad Pellerafaf8bd2011-10-05 11:55:57 +02002249 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
Eliad Pellere5a359f2011-10-10 10:13:15 +02002250
2251 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2252 wlvif->bss_type == BSS_TYPE_IBSS) {
2253 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2254 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2255 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2256 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2257 } else {
2258 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2259 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2260 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2261 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2262 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2263 wl12xx_free_rate_policy(wl,
2264 &wlvif->ap.ucast_rate_idx[i]);
2265 }
Eliad Pellerb78b47e2011-08-14 13:17:08 +03002266
Eliad Pellerd6a3cc22011-10-10 10:12:51 +02002267 wl12xx_tx_reset_wlvif(wl, wlvif);
Eliad Peller170d0e62011-10-05 11:56:06 +02002268 wl1271_free_ap_keys(wl, wlvif);
Eliad Pellere4120df2011-10-10 10:13:17 +02002269 if (wl->last_wlvif == wlvif)
2270 wl->last_wlvif = NULL;
Eliad Peller87627212011-10-10 10:12:54 +02002271 list_del(&wlvif->list);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02002272 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
Eliad Peller0603d892011-10-05 11:55:51 +02002273 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
Eliad Peller7edebf52011-10-05 11:55:52 +02002274 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
Luciano Coelhod6e19d12009-10-12 15:08:43 +03002275
Eliad Pellera4e41302011-10-11 11:49:15 +02002276 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2277 wl->ap_count--;
2278 else
2279 wl->sta_count--;
2280
Eliad Pellerbaf62772011-10-10 10:12:52 +02002281 mutex_unlock(&wl->mutex);
Eyal Shapirad6bf9ad2012-01-31 11:57:20 +02002282
Eliad Peller9eb599e2011-10-10 10:12:59 +02002283 del_timer_sync(&wlvif->rx_streaming_timer);
2284 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2285 cancel_work_sync(&wlvif->rx_streaming_disable_work);
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03002286
Eliad Pellerbaf62772011-10-10 10:12:52 +02002287 mutex_lock(&wl->mutex);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002288}
Juuso Oikarinenbd9dc492010-04-09 11:07:26 +03002289
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002290static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2291 struct ieee80211_vif *vif)
2292{
2293 struct wl1271 *wl = hw->priv;
Eliad Peller10c8cd02011-10-10 10:13:06 +02002294 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002295 struct wl12xx_vif *iter;
Eliad Peller4549d092012-02-06 13:07:52 +02002296 struct vif_counter_data vif_count;
2297 bool cancel_recovery = true;
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002298
Eliad Peller4549d092012-02-06 13:07:52 +02002299 wl12xx_get_vif_count(hw, vif, &vif_count);
Juuso Oikarinen52a2a372010-09-21 06:23:30 +02002300 mutex_lock(&wl->mutex);
Eliad Peller10c8cd02011-10-10 10:13:06 +02002301
2302 if (wl->state == WL1271_STATE_OFF ||
2303 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2304 goto out;
2305
Juuso Oikarinen67353292010-11-18 15:19:02 +02002306 /*
2307 * wl->vif can be null here if someone shuts down the interface
2308 * just when hardware recovery has been started.
2309 */
Eliad Peller6e8cd332011-10-10 10:13:13 +02002310 wl12xx_for_each_wlvif(wl, iter) {
2311 if (iter != wlvif)
2312 continue;
2313
Eliad Peller536129c2011-10-05 11:55:45 +02002314 __wl1271_op_remove_interface(wl, vif, true);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002315 break;
Juuso Oikarinen67353292010-11-18 15:19:02 +02002316 }
Eliad Peller6e8cd332011-10-10 10:13:13 +02002317 WARN_ON(iter != wlvif);
Eliad Peller4549d092012-02-06 13:07:52 +02002318 if (wl12xx_need_fw_change(wl, vif_count, false)) {
Eliad Peller3dee4392012-02-06 12:47:56 +02002319 wl12xx_force_active_psm(wl);
Eliad Peller4549d092012-02-06 13:07:52 +02002320 wl12xx_queue_recovery_work(wl);
2321 cancel_recovery = false;
2322 }
Eliad Peller10c8cd02011-10-10 10:13:06 +02002323out:
Juuso Oikarinen67353292010-11-18 15:19:02 +02002324 mutex_unlock(&wl->mutex);
Eliad Peller4549d092012-02-06 13:07:52 +02002325 if (cancel_recovery)
2326 cancel_work_sync(&wl->recovery_work);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002327}
2328
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002329static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2330 struct ieee80211_vif *vif,
2331 enum nl80211_iftype new_type, bool p2p)
2332{
Eliad Peller4549d092012-02-06 13:07:52 +02002333 struct wl1271 *wl = hw->priv;
2334 int ret;
2335
2336 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002337 wl1271_op_remove_interface(hw, vif);
2338
Eliad Peller249e9692012-03-04 10:55:50 +02002339 vif->type = new_type;
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002340 vif->p2p = p2p;
Eliad Peller4549d092012-02-06 13:07:52 +02002341 ret = wl1271_op_add_interface(hw, vif);
2342
2343 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2344 return ret;
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02002345}
2346
Eliad Peller87fbcb02011-10-05 11:55:41 +02002347static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2348 bool set_assoc)
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002349{
2350 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002351 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002352
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002353 /*
2354 * One of the side effects of the JOIN command is that is clears
2355 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2356 * to a WPA/WPA2 access point will therefore kill the data-path.
Ohad Ben-Cohen8bf69aa2011-03-30 19:18:31 +02002357 * Currently the only valid scenario for JOIN during association
2358 * is on roaming, in which case we will also be given new keys.
2359 * Keep the below message for now, unless it starts bothering
2360 * users who really like to roam a lot :)
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002361 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002362 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002363 wl1271_info("JOIN while associated.");
2364
Eliad Peller5ec8a442012-02-02 12:22:09 +02002365 /* clear encryption type */
2366 wlvif->encryption_type = KEY_NONE;
2367
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002368 if (set_assoc)
Eliad Pellerba8447f2011-10-10 10:13:00 +02002369 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002370
Eliad Peller227e81e2011-08-14 13:17:26 +03002371 if (is_ibss)
Eliad Peller87fbcb02011-10-05 11:55:41 +02002372 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03002373 else
Eliad Peller87fbcb02011-10-05 11:55:41 +02002374 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002375 if (ret < 0)
2376 goto out;
2377
Eliad Pellerba8447f2011-10-10 10:13:00 +02002378 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002379 goto out;
2380
2381 /*
2382 * The join command disable the keep-alive mode, shut down its process,
2383 * and also clear the template config, so we need to reset it all after
2384 * the join. The acx_aid starts the keep-alive process, and the order
2385 * of the commands below is relevant.
2386 */
Eliad Peller0603d892011-10-05 11:55:51 +02002387 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002388 if (ret < 0)
2389 goto out;
2390
Eliad Peller0603d892011-10-05 11:55:51 +02002391 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002392 if (ret < 0)
2393 goto out;
2394
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002395 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002396 if (ret < 0)
2397 goto out;
2398
Eliad Peller0603d892011-10-05 11:55:51 +02002399 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2400 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen82429d32010-04-28 09:50:01 +03002401 ACX_KEEP_ALIVE_TPL_VALID);
2402 if (ret < 0)
2403 goto out;
2404
2405out:
2406 return ret;
2407}
2408
Eliad Peller0603d892011-10-05 11:55:51 +02002409static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002410{
2411 int ret;
2412
Eliad Peller52630c52011-10-10 10:13:08 +02002413 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02002414 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2415
Shahar Levi6d158ff2011-09-08 13:01:33 +03002416 wl12xx_cmd_stop_channel_switch(wl);
Eliad Peller6e8cd332011-10-10 10:13:13 +02002417 ieee80211_chswitch_done(vif, false);
Shahar Levi6d158ff2011-09-08 13:01:33 +03002418 }
2419
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002420 /* to stop listening to a channel, we disconnect */
Eliad Peller0603d892011-10-05 11:55:51 +02002421 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002422 if (ret < 0)
2423 goto out;
2424
Oz Krakowskib992c682011-06-26 10:36:02 +03002425 /* reset TX security counters on a clean disconnect */
Eliad Peller48e93e42011-10-10 10:12:58 +02002426 wlvif->tx_security_last_seq_lsb = 0;
2427 wlvif->tx_security_seq = 0;
Oz Krakowskib992c682011-06-26 10:36:02 +03002428
Luciano Coelhoc7f43e42009-12-11 15:40:44 +02002429out:
2430 return ret;
2431}
2432
Eliad Peller87fbcb02011-10-05 11:55:41 +02002433static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002434{
Eliad Peller1b92f152011-10-10 10:13:09 +02002435 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002436 wlvif->rate_set = wlvif->basic_rate_set;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002437}
2438
Eliad Peller87fbcb02011-10-05 11:55:41 +02002439static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2440 bool idle)
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002441{
2442 int ret;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002443 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2444
2445 if (idle == cur_idle)
2446 return 0;
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002447
2448 if (idle) {
Eliad Peller251c1772011-08-14 13:17:17 +03002449 /* no need to croc if we weren't busy (e.g. during boot) */
Eliad Peller92e712d2011-12-18 20:25:43 +02002450 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02002451 ret = wl12xx_stop_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002452 if (ret < 0)
2453 goto out;
2454 }
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002455 wlvif->rate_set =
2456 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2457 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002458 if (ret < 0)
2459 goto out;
2460 ret = wl1271_acx_keep_alive_config(
Eliad Peller0603d892011-10-05 11:55:51 +02002461 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002462 ACX_KEEP_ALIVE_TPL_INVALID);
2463 if (ret < 0)
2464 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002465 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002466 } else {
Luciano Coelho33c2c062011-05-10 14:46:02 +03002467 /* The current firmware only supports sched_scan in idle */
2468 if (wl->sched_scanning) {
2469 wl1271_scan_sched_scan_stop(wl);
2470 ieee80211_sched_scan_stopped(wl->hw);
2471 }
2472
Eliad Peller679a6732011-10-11 11:55:44 +02002473 ret = wl12xx_start_dev(wl, wlvif);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002474 if (ret < 0)
2475 goto out;
Eliad Pellera0c7b782011-12-18 20:25:41 +02002476 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
Juuso Oikarinen0d58cbf2010-05-24 11:18:16 +03002477 }
2478
2479out:
2480 return ret;
2481}
2482
Eliad Peller9f259c42011-10-10 10:13:12 +02002483static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2484 struct ieee80211_conf *conf, u32 changed)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002485{
Eliad Peller9f259c42011-10-10 10:13:12 +02002486 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2487 int channel, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002488
2489 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2490
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002491 /* if the channel changes while joined, join again */
Juuso Oikarinen69e54342010-05-07 11:39:00 +03002492 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
Eliad Peller1b92f152011-10-10 10:13:09 +02002493 ((wlvif->band != conf->channel->band) ||
Eliad Peller61f845f2011-10-10 10:13:10 +02002494 (wlvif->channel != channel))) {
Eliad Pellerc6930b02011-09-15 13:00:01 +03002495 /* send all pending packets */
Eliad Pellera32d0cd2011-10-10 10:12:55 +02002496 wl1271_tx_work_locked(wl);
Eliad Peller61f845f2011-10-10 10:13:10 +02002497 wlvif->band = conf->channel->band;
2498 wlvif->channel = channel;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002499
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002500 if (!is_ap) {
2501 /*
2502 * FIXME: the mac80211 should really provide a fixed
2503 * rate to use here. for now, just use the smallest
2504 * possible rate for the band as a fixed rate for
2505 * association frames and other control messages.
2506 */
Eliad Pellerba8447f2011-10-10 10:13:00 +02002507 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Eliad Peller87fbcb02011-10-05 11:55:41 +02002508 wl1271_set_band_rate(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002509
Eliad Pellerd2d66c52011-10-05 11:55:43 +02002510 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02002511 wl1271_tx_min_rate_get(wl,
2512 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02002513 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002514 if (ret < 0)
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002515 wl1271_warning("rate policy for channel "
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002516 "failed %d", ret);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002517
Eliad Peller121af042012-03-04 10:55:51 +02002518 /*
2519 * change the ROC channel. do it only if we are
2520 * not idle. otherwise, CROC will be called
2521 * anyway.
2522 */
2523 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2524 &wlvif->flags) &&
2525 wl12xx_dev_role_started(wlvif) &&
2526 !(conf->flags & IEEE80211_CONF_IDLE)) {
2527 ret = wl12xx_stop_dev(wl, wlvif);
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002528 if (ret < 0)
Eliad Peller121af042012-03-04 10:55:51 +02002529 return ret;
Eliad Peller251c1772011-08-14 13:17:17 +03002530
Eliad Peller121af042012-03-04 10:55:51 +02002531 ret = wl12xx_start_dev(wl, wlvif);
2532 if (ret < 0)
2533 return ret;
Arik Nemtsovbee0ffe2010-10-16 19:17:02 +02002534 }
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03002535 }
2536 }
2537
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002538 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002539
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002540 if ((conf->flags & IEEE80211_CONF_PS) &&
2541 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002542 !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002543
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002544 int ps_mode;
2545 char *ps_mode_str;
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002546
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002547 if (wl->conf.conn.forced_ps) {
2548 ps_mode = STATION_POWER_SAVE_MODE;
2549 ps_mode_str = "forced";
2550 } else {
2551 ps_mode = STATION_AUTO_PS_MODE;
2552 ps_mode_str = "auto";
2553 }
2554
2555 wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
2556
2557 ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
2558
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002559 if (ret < 0)
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002560 wl1271_warning("enter %s ps failed %d",
2561 ps_mode_str, ret);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002562
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002563 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
Eyal Shapira5c0dc2f2012-02-02 19:06:45 +02002564 test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002565
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002566 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2567
Eliad Peller0603d892011-10-05 11:55:51 +02002568 ret = wl1271_ps_set_mode(wl, wlvif,
Eyal Shapira248a0012012-01-31 11:57:23 +02002569 STATION_ACTIVE_MODE);
Eyal Shapirad18da7f2012-01-31 11:57:25 +02002570 if (ret < 0)
2571 wl1271_warning("exit auto ps failed %d", ret);
2572 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002573 }
2574
Eliad Peller6bd65022011-10-10 10:13:11 +02002575 if (conf->power_level != wlvif->power_level) {
Eliad Peller0603d892011-10-05 11:55:51 +02002576 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002577 if (ret < 0)
Eliad Peller9f259c42011-10-10 10:13:12 +02002578 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002579
Eliad Peller6bd65022011-10-10 10:13:11 +02002580 wlvif->power_level = conf->power_level;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002581 }
2582
Eliad Peller9f259c42011-10-10 10:13:12 +02002583 return 0;
2584}
2585
2586static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2587{
2588 struct wl1271 *wl = hw->priv;
2589 struct wl12xx_vif *wlvif;
2590 struct ieee80211_conf *conf = &hw->conf;
2591 int channel, ret = 0;
2592
2593 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2594
2595 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2596 " changed 0x%x",
2597 channel,
2598 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2599 conf->power_level,
2600 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2601 changed);
2602
2603 /*
2604 * mac80211 will go to idle nearly immediately after transmitting some
2605 * frames, such as the deauth. To make sure those frames reach the air,
2606 * wait here until the TX queue is fully flushed.
2607 */
2608 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2609 (conf->flags & IEEE80211_CONF_IDLE))
2610 wl1271_tx_flush(wl);
2611
2612 mutex_lock(&wl->mutex);
2613
2614 /* we support configuring the channel and band even while off */
2615 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2616 wl->band = conf->channel->band;
2617 wl->channel = channel;
2618 }
2619
2620 if (changed & IEEE80211_CONF_CHANGE_POWER)
2621 wl->power_level = conf->power_level;
2622
2623 if (unlikely(wl->state == WL1271_STATE_OFF))
2624 goto out;
2625
2626 ret = wl1271_ps_elp_wakeup(wl);
2627 if (ret < 0)
2628 goto out;
2629
2630 /* configure each interface */
2631 wl12xx_for_each_wlvif(wl, wlvif) {
2632 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2633 if (ret < 0)
2634 goto out_sleep;
2635 }
2636
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002637out_sleep:
2638 wl1271_ps_elp_sleep(wl);
2639
2640out:
2641 mutex_unlock(&wl->mutex);
2642
2643 return ret;
2644}
2645
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002646struct wl1271_filter_params {
2647 bool enabled;
2648 int mc_list_length;
2649 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2650};
2651
Jiri Pirko22bedad2010-04-01 21:22:57 +00002652static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2653 struct netdev_hw_addr_list *mc_list)
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002654{
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002655 struct wl1271_filter_params *fp;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002656 struct netdev_hw_addr *ha;
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002657 struct wl1271 *wl = hw->priv;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002658
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002659 if (unlikely(wl->state == WL1271_STATE_OFF))
2660 return 0;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002661
Juuso Oikarinen74441132009-10-13 12:47:53 +03002662 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002663 if (!fp) {
2664 wl1271_error("Out of memory setting filters.");
2665 return 0;
2666 }
2667
2668 /* update multicast filtering parameters */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002669 fp->mc_list_length = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002670 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2671 fp->enabled = false;
2672 } else {
2673 fp->enabled = true;
2674 netdev_hw_addr_list_for_each(ha, mc_list) {
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002675 memcpy(fp->mc_list[fp->mc_list_length],
Jiri Pirko22bedad2010-04-01 21:22:57 +00002676 ha->addr, ETH_ALEN);
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002677 fp->mc_list_length++;
Jiri Pirko22bedad2010-04-01 21:22:57 +00002678 }
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002679 }
2680
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002681 return (u64)(unsigned long)fp;
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002682}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002683
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002684#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2685 FIF_ALLMULTI | \
2686 FIF_FCSFAIL | \
2687 FIF_BCN_PRBRESP_PROMISC | \
2688 FIF_CONTROL | \
2689 FIF_OTHER_BSS)
2690
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002691static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2692 unsigned int changed,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03002693 unsigned int *total, u64 multicast)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002694{
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002695 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002696 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02002697 struct wl12xx_vif *wlvif;
Eliad Peller536129c2011-10-05 11:55:45 +02002698
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002699 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002700
Arik Nemtsov7d057862010-10-16 19:25:35 +02002701 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2702 " total %x", changed, *total);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002703
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002704 mutex_lock(&wl->mutex);
2705
Saravanan Dhanabal2c10bb92010-04-09 11:07:27 +03002706 *total &= WL1271_SUPPORTED_FILTERS;
2707 changed &= WL1271_SUPPORTED_FILTERS;
2708
2709 if (unlikely(wl->state == WL1271_STATE_OFF))
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002710 goto out;
2711
Ido Yariva6208652011-03-01 15:14:41 +02002712 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002713 if (ret < 0)
2714 goto out;
2715
Eliad Peller6e8cd332011-10-10 10:13:13 +02002716 wl12xx_for_each_wlvif(wl, wlvif) {
2717 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2718 if (*total & FIF_ALLMULTI)
2719 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2720 false,
2721 NULL, 0);
2722 else if (fp)
2723 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2724 fp->enabled,
2725 fp->mc_list,
2726 fp->mc_list_length);
2727 if (ret < 0)
2728 goto out_sleep;
2729 }
Arik Nemtsov7d057862010-10-16 19:25:35 +02002730 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002731
Eliad Peller08c1d1c2011-08-14 13:17:04 +03002732 /*
2733 * the fw doesn't provide an api to configure the filters. instead,
2734 * the filters configuration is based on the active roles / ROC
2735 * state.
2736 */
Juuso Oikarinenb54853f2009-10-13 12:47:59 +03002737
2738out_sleep:
2739 wl1271_ps_elp_sleep(wl);
2740
2741out:
2742 mutex_unlock(&wl->mutex);
Juuso Oikarinen14b228a2010-03-18 12:26:43 +02002743 kfree(fp);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002744}
2745
Eliad Peller170d0e62011-10-05 11:56:06 +02002746static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2747 u8 id, u8 key_type, u8 key_size,
2748 const u8 *key, u8 hlid, u32 tx_seq_32,
2749 u16 tx_seq_16)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002750{
2751 struct wl1271_ap_key *ap_key;
2752 int i;
2753
2754 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2755
2756 if (key_size > MAX_KEY_SIZE)
2757 return -EINVAL;
2758
2759 /*
2760 * Find next free entry in ap_keys. Also check we are not replacing
2761 * an existing key.
2762 */
2763 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002764 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002765 break;
2766
Eliad Peller170d0e62011-10-05 11:56:06 +02002767 if (wlvif->ap.recorded_keys[i]->id == id) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002768 wl1271_warning("trying to record key replacement");
2769 return -EINVAL;
2770 }
2771 }
2772
2773 if (i == MAX_NUM_KEYS)
2774 return -EBUSY;
2775
2776 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2777 if (!ap_key)
2778 return -ENOMEM;
2779
2780 ap_key->id = id;
2781 ap_key->key_type = key_type;
2782 ap_key->key_size = key_size;
2783 memcpy(ap_key->key, key, key_size);
2784 ap_key->hlid = hlid;
2785 ap_key->tx_seq_32 = tx_seq_32;
2786 ap_key->tx_seq_16 = tx_seq_16;
2787
Eliad Peller170d0e62011-10-05 11:56:06 +02002788 wlvif->ap.recorded_keys[i] = ap_key;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002789 return 0;
2790}
2791
Eliad Peller170d0e62011-10-05 11:56:06 +02002792static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002793{
2794 int i;
2795
2796 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller170d0e62011-10-05 11:56:06 +02002797 kfree(wlvif->ap.recorded_keys[i]);
2798 wlvif->ap.recorded_keys[i] = NULL;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002799 }
2800}
2801
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002802static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002803{
2804 int i, ret = 0;
2805 struct wl1271_ap_key *key;
2806 bool wep_key_added = false;
2807
2808 for (i = 0; i < MAX_NUM_KEYS; i++) {
Eliad Peller7f97b482011-08-14 13:17:30 +03002809 u8 hlid;
Eliad Peller170d0e62011-10-05 11:56:06 +02002810 if (wlvif->ap.recorded_keys[i] == NULL)
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002811 break;
2812
Eliad Peller170d0e62011-10-05 11:56:06 +02002813 key = wlvif->ap.recorded_keys[i];
Eliad Peller7f97b482011-08-14 13:17:30 +03002814 hlid = key->hlid;
2815 if (hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002816 hlid = wlvif->ap.bcast_hlid;
Eliad Peller7f97b482011-08-14 13:17:30 +03002817
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002818 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002819 key->id, key->key_type,
2820 key->key_size, key->key,
Eliad Peller7f97b482011-08-14 13:17:30 +03002821 hlid, key->tx_seq_32,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002822 key->tx_seq_16);
2823 if (ret < 0)
2824 goto out;
2825
2826 if (key->key_type == KEY_WEP)
2827 wep_key_added = true;
2828 }
2829
2830 if (wep_key_added) {
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002831 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002832 wlvif->ap.bcast_hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002833 if (ret < 0)
2834 goto out;
2835 }
2836
2837out:
Eliad Peller170d0e62011-10-05 11:56:06 +02002838 wl1271_free_ap_keys(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002839 return ret;
2840}
2841
Eliad Peller536129c2011-10-05 11:55:45 +02002842static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2843 u16 action, u8 id, u8 key_type,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002844 u8 key_size, const u8 *key, u32 tx_seq_32,
2845 u16 tx_seq_16, struct ieee80211_sta *sta)
2846{
2847 int ret;
Eliad Peller536129c2011-10-05 11:55:45 +02002848 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002849
2850 if (is_ap) {
2851 struct wl1271_station *wl_sta;
2852 u8 hlid;
2853
2854 if (sta) {
2855 wl_sta = (struct wl1271_station *)sta->drv_priv;
2856 hlid = wl_sta->hlid;
2857 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002858 hlid = wlvif->ap.bcast_hlid;
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002859 }
2860
Eliad Peller53d40d02011-10-10 10:13:02 +02002861 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002862 /*
2863 * We do not support removing keys after AP shutdown.
2864 * Pretend we do to make mac80211 happy.
2865 */
2866 if (action != KEY_ADD_OR_REPLACE)
2867 return 0;
2868
Eliad Peller170d0e62011-10-05 11:56:06 +02002869 ret = wl1271_record_ap_key(wl, wlvif, id,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002870 key_type, key_size,
2871 key, hlid, tx_seq_32,
2872 tx_seq_16);
2873 } else {
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002874 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002875 id, key_type, key_size,
2876 key, hlid, tx_seq_32,
2877 tx_seq_16);
2878 }
2879
2880 if (ret < 0)
2881 return ret;
2882 } else {
2883 const u8 *addr;
2884 static const u8 bcast_addr[ETH_ALEN] = {
2885 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2886 };
2887
Guy Eilame9eb8cb2011-08-16 19:49:12 +03002888 /*
2889 * A STA set to GEM cipher requires 2 tx spare blocks.
2890 * Return to default value when GEM cipher key is removed
2891 */
2892 if (key_type == KEY_GEM) {
2893 if (action == KEY_ADD_OR_REPLACE)
2894 wl->tx_spare_blocks = 2;
2895 else if (action == KEY_REMOVE)
2896 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2897 }
2898
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002899 addr = sta ? sta->addr : bcast_addr;
2900
2901 if (is_zero_ether_addr(addr)) {
2902 /* We dont support TX only encryption */
2903 return -EOPNOTSUPP;
2904 }
2905
2906 /* The wl1271 does not allow to remove unicast keys - they
2907 will be cleared automatically on next CMD_JOIN. Ignore the
2908 request silently, as we dont want the mac80211 to emit
2909 an error message. */
2910 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2911 return 0;
2912
Eliad Peller010d3d32011-08-14 13:17:31 +03002913 /* don't remove key if hlid was already deleted */
2914 if (action == KEY_REMOVE &&
Eliad Peller154da672011-10-05 11:55:53 +02002915 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Peller010d3d32011-08-14 13:17:31 +03002916 return 0;
2917
Eliad Pellera8ab39a2011-10-05 11:55:54 +02002918 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002919 id, key_type, key_size,
2920 key, addr, tx_seq_32,
2921 tx_seq_16);
2922 if (ret < 0)
2923 return ret;
2924
2925 /* the default WEP key needs to be configured at least once */
2926 if (key_type == KEY_WEP) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03002927 ret = wl12xx_cmd_set_default_wep_key(wl,
Eliad Pellerf75c753f2011-10-05 11:55:59 +02002928 wlvif->default_key,
2929 wlvif->sta.hlid);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002930 if (ret < 0)
2931 return ret;
2932 }
2933 }
2934
2935 return 0;
2936}
2937
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002938static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2939 struct ieee80211_vif *vif,
2940 struct ieee80211_sta *sta,
2941 struct ieee80211_key_conf *key_conf)
2942{
2943 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02002944 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002945 int ret;
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03002946 u32 tx_seq_32 = 0;
2947 u16 tx_seq_16 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002948 u8 key_type;
2949
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002950 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2951
Arik Nemtsov7f179b42010-10-16 21:39:06 +02002952 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002953 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
Johannes Berg97359d12010-08-10 09:46:38 +02002954 key_conf->cipher, key_conf->keyidx,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002955 key_conf->keylen, key_conf->flags);
2956 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2957
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002958 mutex_lock(&wl->mutex);
2959
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02002960 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2961 ret = -EAGAIN;
2962 goto out_unlock;
2963 }
2964
Ido Yariva6208652011-03-01 15:14:41 +02002965 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002966 if (ret < 0)
2967 goto out_unlock;
2968
Johannes Berg97359d12010-08-10 09:46:38 +02002969 switch (key_conf->cipher) {
2970 case WLAN_CIPHER_SUITE_WEP40:
2971 case WLAN_CIPHER_SUITE_WEP104:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002972 key_type = KEY_WEP;
2973
2974 key_conf->hw_key_idx = key_conf->keyidx;
2975 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002976 case WLAN_CIPHER_SUITE_TKIP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002977 key_type = KEY_TKIP;
2978
2979 key_conf->hw_key_idx = key_conf->keyidx;
Eliad Peller48e93e42011-10-10 10:12:58 +02002980 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2981 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002982 break;
Johannes Berg97359d12010-08-10 09:46:38 +02002983 case WLAN_CIPHER_SUITE_CCMP:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002984 key_type = KEY_AES;
2985
Arik Nemtsov12d4b972011-10-23 08:21:54 +02002986 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Eliad Peller48e93e42011-10-10 10:12:58 +02002987 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2988 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002989 break;
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002990 case WL1271_CIPHER_SUITE_GEM:
2991 key_type = KEY_GEM;
Eliad Peller48e93e42011-10-10 10:12:58 +02002992 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2993 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
Juuso Oikarinen7a557242010-09-27 12:42:07 +02002994 break;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002995 default:
Johannes Berg97359d12010-08-10 09:46:38 +02002996 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03002997
2998 ret = -EOPNOTSUPP;
2999 goto out_sleep;
3000 }
3001
3002 switch (cmd) {
3003 case SET_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003004 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003005 key_conf->keyidx, key_type,
3006 key_conf->keylen, key_conf->key,
3007 tx_seq_32, tx_seq_16, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003008 if (ret < 0) {
3009 wl1271_error("Could not add or replace key");
3010 goto out_sleep;
3011 }
Eliad Peller5ec8a442012-02-02 12:22:09 +02003012
3013 /*
3014 * reconfiguring arp response if the unicast (or common)
3015 * encryption key type was changed
3016 */
3017 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
3018 (sta || key_type == KEY_WEP) &&
3019 wlvif->encryption_type != key_type) {
3020 wlvif->encryption_type = key_type;
3021 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3022 if (ret < 0) {
3023 wl1271_warning("build arp rsp failed: %d", ret);
3024 goto out_sleep;
3025 }
3026 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003027 break;
3028
3029 case DISABLE_KEY:
Eliad Peller536129c2011-10-05 11:55:45 +02003030 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003031 key_conf->keyidx, key_type,
3032 key_conf->keylen, key_conf->key,
3033 0, 0, sta);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003034 if (ret < 0) {
3035 wl1271_error("Could not remove key");
3036 goto out_sleep;
3037 }
3038 break;
3039
3040 default:
3041 wl1271_error("Unsupported key cmd 0x%x", cmd);
3042 ret = -EOPNOTSUPP;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003043 break;
3044 }
3045
3046out_sleep:
3047 wl1271_ps_elp_sleep(wl);
3048
3049out_unlock:
3050 mutex_unlock(&wl->mutex);
3051
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003052 return ret;
3053}
3054
3055static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
Johannes Berga060bbf2010-04-27 11:59:34 +02003056 struct ieee80211_vif *vif,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003057 struct cfg80211_scan_request *req)
3058{
3059 struct wl1271 *wl = hw->priv;
3060 int ret;
3061 u8 *ssid = NULL;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003062 size_t len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003063
3064 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
3065
3066 if (req->n_ssids) {
3067 ssid = req->ssids[0].ssid;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03003068 len = req->ssids[0].ssid_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003069 }
3070
3071 mutex_lock(&wl->mutex);
3072
Juuso Oikarinenb739a422010-10-26 13:24:38 +02003073 if (wl->state == WL1271_STATE_OFF) {
3074 /*
3075 * We cannot return -EBUSY here because cfg80211 will expect
3076 * a call to ieee80211_scan_completed if we do - in this case
3077 * there won't be any call.
3078 */
3079 ret = -EAGAIN;
3080 goto out;
3081 }
3082
Ido Yariva6208652011-03-01 15:14:41 +02003083 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003084 if (ret < 0)
3085 goto out;
3086
Eliad Peller97fd3112012-03-04 10:55:52 +02003087 /* fail if there is any role in ROC */
3088 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
Eliad Peller92e712d2011-12-18 20:25:43 +02003089 /* don't allow scanning right now */
3090 ret = -EBUSY;
3091 goto out_sleep;
Eliad Peller251c1772011-08-14 13:17:17 +03003092 }
3093
Eliad Peller784f6942011-10-05 11:55:39 +02003094 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
Eliad Peller251c1772011-08-14 13:17:17 +03003095out_sleep:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003096 wl1271_ps_elp_sleep(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003097out:
3098 mutex_unlock(&wl->mutex);
3099
3100 return ret;
3101}
3102
Eliad Peller73ecce32011-06-27 13:06:45 +03003103static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3104 struct ieee80211_vif *vif)
3105{
3106 struct wl1271 *wl = hw->priv;
3107 int ret;
3108
3109 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3110
3111 mutex_lock(&wl->mutex);
3112
3113 if (wl->state == WL1271_STATE_OFF)
3114 goto out;
3115
3116 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3117 goto out;
3118
3119 ret = wl1271_ps_elp_wakeup(wl);
3120 if (ret < 0)
3121 goto out;
3122
3123 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3124 ret = wl1271_scan_stop(wl);
3125 if (ret < 0)
3126 goto out_sleep;
3127 }
3128 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3129 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
Eliad Peller784f6942011-10-05 11:55:39 +02003130 wl->scan_vif = NULL;
Eliad Peller73ecce32011-06-27 13:06:45 +03003131 wl->scan.req = NULL;
3132 ieee80211_scan_completed(wl->hw, true);
3133
3134out_sleep:
3135 wl1271_ps_elp_sleep(wl);
3136out:
3137 mutex_unlock(&wl->mutex);
3138
3139 cancel_delayed_work_sync(&wl->scan_complete_work);
3140}
3141
Luciano Coelho33c2c062011-05-10 14:46:02 +03003142static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3143 struct ieee80211_vif *vif,
3144 struct cfg80211_sched_scan_request *req,
3145 struct ieee80211_sched_scan_ies *ies)
3146{
3147 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003148 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003149 int ret;
3150
3151 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3152
3153 mutex_lock(&wl->mutex);
3154
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003155 if (wl->state == WL1271_STATE_OFF) {
3156 ret = -EAGAIN;
3157 goto out;
3158 }
3159
Luciano Coelho33c2c062011-05-10 14:46:02 +03003160 ret = wl1271_ps_elp_wakeup(wl);
3161 if (ret < 0)
3162 goto out;
3163
Eliad Peller536129c2011-10-05 11:55:45 +02003164 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003165 if (ret < 0)
3166 goto out_sleep;
3167
Eliad Peller536129c2011-10-05 11:55:45 +02003168 ret = wl1271_scan_sched_scan_start(wl, wlvif);
Luciano Coelho33c2c062011-05-10 14:46:02 +03003169 if (ret < 0)
3170 goto out_sleep;
3171
3172 wl->sched_scanning = true;
3173
3174out_sleep:
3175 wl1271_ps_elp_sleep(wl);
3176out:
3177 mutex_unlock(&wl->mutex);
3178 return ret;
3179}
3180
3181static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3182 struct ieee80211_vif *vif)
3183{
3184 struct wl1271 *wl = hw->priv;
3185 int ret;
3186
3187 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3188
3189 mutex_lock(&wl->mutex);
3190
Pontus Fuchs9e0dc892012-01-11 14:22:42 +01003191 if (wl->state == WL1271_STATE_OFF)
3192 goto out;
3193
Luciano Coelho33c2c062011-05-10 14:46:02 +03003194 ret = wl1271_ps_elp_wakeup(wl);
3195 if (ret < 0)
3196 goto out;
3197
3198 wl1271_scan_sched_scan_stop(wl);
3199
3200 wl1271_ps_elp_sleep(wl);
3201out:
3202 mutex_unlock(&wl->mutex);
3203}
3204
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003205static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3206{
3207 struct wl1271 *wl = hw->priv;
3208 int ret = 0;
3209
3210 mutex_lock(&wl->mutex);
3211
3212 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3213 ret = -EAGAIN;
3214 goto out;
3215 }
3216
Ido Yariva6208652011-03-01 15:14:41 +02003217 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003218 if (ret < 0)
3219 goto out;
3220
Arik Nemtsov5f704d12011-04-18 14:15:21 +03003221 ret = wl1271_acx_frag_threshold(wl, value);
Arik Nemtsov68d069c2010-11-08 10:51:07 +01003222 if (ret < 0)
3223 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3224
3225 wl1271_ps_elp_sleep(wl);
3226
3227out:
3228 mutex_unlock(&wl->mutex);
3229
3230 return ret;
3231}
3232
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003233static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3234{
3235 struct wl1271 *wl = hw->priv;
Eliad Peller6e8cd332011-10-10 10:13:13 +02003236 struct wl12xx_vif *wlvif;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003237 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003238
3239 mutex_lock(&wl->mutex);
3240
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003241 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3242 ret = -EAGAIN;
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003243 goto out;
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02003244 }
Saravanan Dhanabalaecb0562010-04-09 11:07:28 +03003245
Ido Yariva6208652011-03-01 15:14:41 +02003246 ret = wl1271_ps_elp_wakeup(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003247 if (ret < 0)
3248 goto out;
3249
Eliad Peller6e8cd332011-10-10 10:13:13 +02003250 wl12xx_for_each_wlvif(wl, wlvif) {
3251 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3252 if (ret < 0)
3253 wl1271_warning("set rts threshold failed: %d", ret);
3254 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003255 wl1271_ps_elp_sleep(wl);
3256
3257out:
3258 mutex_unlock(&wl->mutex);
3259
3260 return ret;
3261}
3262
Eliad Peller1fe9f162011-10-05 11:55:48 +02003263static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003264 int offset)
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003265{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003266 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller889cb362011-05-01 09:56:45 +03003267 u8 ssid_len;
3268 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3269 skb->len - offset);
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003270
Eliad Peller889cb362011-05-01 09:56:45 +03003271 if (!ptr) {
3272 wl1271_error("No SSID in IEs!");
3273 return -ENOENT;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003274 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003275
Eliad Peller889cb362011-05-01 09:56:45 +03003276 ssid_len = ptr[1];
3277 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3278 wl1271_error("SSID is too long!");
3279 return -EINVAL;
3280 }
3281
Eliad Peller1fe9f162011-10-05 11:55:48 +02003282 wlvif->ssid_len = ssid_len;
3283 memcpy(wlvif->ssid, ptr+2, ssid_len);
Eliad Peller889cb362011-05-01 09:56:45 +03003284 return 0;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003285}
3286
Eliad Pellerd48055d2011-09-15 12:07:04 +03003287static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3288{
3289 int len;
3290 const u8 *next, *end = skb->data + skb->len;
3291 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3292 skb->len - ieoffset);
3293 if (!ie)
3294 return;
3295 len = ie[1] + 2;
3296 next = ie + len;
3297 memmove(ie, next, end - next);
3298 skb_trim(skb, skb->len - len);
3299}
3300
Eliad Peller26b4bf22011-09-15 12:07:05 +03003301static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3302 unsigned int oui, u8 oui_type,
3303 int ieoffset)
3304{
3305 int len;
3306 const u8 *next, *end = skb->data + skb->len;
3307 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3308 skb->data + ieoffset,
3309 skb->len - ieoffset);
3310 if (!ie)
3311 return;
3312 len = ie[1] + 2;
3313 next = ie + len;
3314 memmove(ie, next, end - next);
3315 skb_trim(skb, skb->len - len);
3316}
3317
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003318static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3319 struct ieee80211_vif *vif)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003320{
Eliad Pellercdaac622012-01-31 11:57:16 +02003321 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003322 struct sk_buff *skb;
3323 int ret;
3324
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003325 skb = ieee80211_proberesp_get(wl->hw, vif);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003326 if (!skb)
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003327 return -EOPNOTSUPP;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003328
Eliad Pellercdaac622012-01-31 11:57:16 +02003329 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov560f0022011-11-08 18:46:54 +02003330 CMD_TEMPL_AP_PROBE_RESPONSE,
3331 skb->data,
3332 skb->len, 0,
3333 rates);
3334
3335 dev_kfree_skb(skb);
3336 return ret;
3337}
3338
3339static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3340 struct ieee80211_vif *vif,
3341 u8 *probe_rsp_data,
3342 size_t probe_rsp_len,
3343 u32 rates)
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003344{
Eliad Peller1fe9f162011-10-05 11:55:48 +02003345 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3346 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003347 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3348 int ssid_ie_offset, ie_offset, templ_len;
3349 const u8 *ptr;
3350
3351 /* no need to change probe response if the SSID is set correctly */
Eliad Peller1fe9f162011-10-05 11:55:48 +02003352 if (wlvif->ssid_len > 0)
Eliad Pellercdaac622012-01-31 11:57:16 +02003353 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003354 CMD_TEMPL_AP_PROBE_RESPONSE,
3355 probe_rsp_data,
3356 probe_rsp_len, 0,
3357 rates);
3358
3359 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3360 wl1271_error("probe_rsp template too big");
3361 return -EINVAL;
3362 }
3363
3364 /* start searching from IE offset */
3365 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3366
3367 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3368 probe_rsp_len - ie_offset);
3369 if (!ptr) {
3370 wl1271_error("No SSID in beacon!");
3371 return -EINVAL;
3372 }
3373
3374 ssid_ie_offset = ptr - probe_rsp_data;
3375 ptr += (ptr[1] + 2);
3376
3377 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3378
3379 /* insert SSID from bss_conf */
3380 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3381 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3382 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3383 bss_conf->ssid, bss_conf->ssid_len);
3384 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3385
3386 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3387 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3388 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3389
Eliad Pellercdaac622012-01-31 11:57:16 +02003390 return wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003391 CMD_TEMPL_AP_PROBE_RESPONSE,
3392 probe_rsp_templ,
3393 templ_len, 0,
3394 rates);
3395}
3396
Arik Nemtsove78a2872010-10-16 19:07:21 +02003397static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
Eliad Peller0603d892011-10-05 11:55:51 +02003398 struct ieee80211_vif *vif,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003399 struct ieee80211_bss_conf *bss_conf,
3400 u32 changed)
3401{
Eliad Peller0603d892011-10-05 11:55:51 +02003402 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003403 int ret = 0;
3404
3405 if (changed & BSS_CHANGED_ERP_SLOT) {
3406 if (bss_conf->use_short_slot)
Eliad Peller0603d892011-10-05 11:55:51 +02003407 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003408 else
Eliad Peller0603d892011-10-05 11:55:51 +02003409 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003410 if (ret < 0) {
3411 wl1271_warning("Set slot time failed %d", ret);
3412 goto out;
3413 }
3414 }
3415
3416 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3417 if (bss_conf->use_short_preamble)
Eliad Peller0603d892011-10-05 11:55:51 +02003418 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003419 else
Eliad Peller0603d892011-10-05 11:55:51 +02003420 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003421 }
3422
3423 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3424 if (bss_conf->use_cts_prot)
Eliad Peller0603d892011-10-05 11:55:51 +02003425 ret = wl1271_acx_cts_protect(wl, wlvif,
3426 CTSPROTECT_ENABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003427 else
Eliad Peller0603d892011-10-05 11:55:51 +02003428 ret = wl1271_acx_cts_protect(wl, wlvif,
3429 CTSPROTECT_DISABLE);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003430 if (ret < 0) {
3431 wl1271_warning("Set ctsprotect failed %d", ret);
3432 goto out;
3433 }
3434 }
3435
3436out:
3437 return ret;
3438}
3439
3440static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3441 struct ieee80211_vif *vif,
3442 struct ieee80211_bss_conf *bss_conf,
3443 u32 changed)
3444{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003445 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Peller536129c2011-10-05 11:55:45 +02003446 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003447 int ret = 0;
3448
3449 if ((changed & BSS_CHANGED_BEACON_INT)) {
3450 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3451 bss_conf->beacon_int);
3452
Eliad Peller6a899792011-10-05 11:55:58 +02003453 wlvif->beacon_int = bss_conf->beacon_int;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003454 }
3455
Arik Nemtsov560f0022011-11-08 18:46:54 +02003456 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3457 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov341f2c12011-11-22 19:52:59 +02003458 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3459 wl1271_debug(DEBUG_AP, "probe response updated");
3460 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3461 }
Arik Nemtsov560f0022011-11-08 18:46:54 +02003462 }
3463
Arik Nemtsove78a2872010-10-16 19:07:21 +02003464 if ((changed & BSS_CHANGED_BEACON)) {
3465 struct ieee80211_hdr *hdr;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003466 u32 min_rate;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003467 int ieoffset = offsetof(struct ieee80211_mgmt,
3468 u.beacon.variable);
3469 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3470 u16 tmpl_id;
3471
Arik Nemtsov560f0022011-11-08 18:46:54 +02003472 if (!beacon) {
3473 ret = -EINVAL;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003474 goto out;
Arik Nemtsov560f0022011-11-08 18:46:54 +02003475 }
Arik Nemtsove78a2872010-10-16 19:07:21 +02003476
3477 wl1271_debug(DEBUG_MASTER, "beacon updated");
3478
Eliad Peller1fe9f162011-10-05 11:55:48 +02003479 ret = wl1271_ssid_set(vif, beacon, ieoffset);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003480 if (ret < 0) {
3481 dev_kfree_skb(beacon);
3482 goto out;
3483 }
Eliad Peller87fbcb02011-10-05 11:55:41 +02003484 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003485 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3486 CMD_TEMPL_BEACON;
Eliad Pellercdaac622012-01-31 11:57:16 +02003487 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
Arik Nemtsove78a2872010-10-16 19:07:21 +02003488 beacon->data,
3489 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003490 min_rate);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003491 if (ret < 0) {
3492 dev_kfree_skb(beacon);
3493 goto out;
3494 }
3495
Arik Nemtsov560f0022011-11-08 18:46:54 +02003496 /*
3497 * In case we already have a probe-resp beacon set explicitly
3498 * by usermode, don't use the beacon data.
3499 */
3500 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3501 goto end_bcn;
3502
Eliad Pellerd48055d2011-09-15 12:07:04 +03003503 /* remove TIM ie from probe response */
3504 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3505
Eliad Peller26b4bf22011-09-15 12:07:05 +03003506 /*
3507 * remove p2p ie from probe response.
3508 * the fw reponds to probe requests that don't include
3509 * the p2p ie. probe requests with p2p ie will be passed,
3510 * and will be responded by the supplicant (the spec
3511 * forbids including the p2p ie when responding to probe
3512 * requests that didn't include it).
3513 */
3514 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3515 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3516
Arik Nemtsove78a2872010-10-16 19:07:21 +02003517 hdr = (struct ieee80211_hdr *) beacon->data;
3518 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3519 IEEE80211_STYPE_PROBE_RESP);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003520 if (is_ap)
Arik Nemtsov560f0022011-11-08 18:46:54 +02003521 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003522 beacon->data,
3523 beacon->len,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003524 min_rate);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003525 else
Eliad Pellercdaac622012-01-31 11:57:16 +02003526 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
Arik Nemtsov68eaaf62011-09-03 20:22:03 +03003527 CMD_TEMPL_PROBE_RESPONSE,
3528 beacon->data,
3529 beacon->len, 0,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003530 min_rate);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003531end_bcn:
Arik Nemtsove78a2872010-10-16 19:07:21 +02003532 dev_kfree_skb(beacon);
3533 if (ret < 0)
3534 goto out;
3535 }
3536
3537out:
Arik Nemtsov560f0022011-11-08 18:46:54 +02003538 if (ret != 0)
3539 wl1271_error("beacon info change failed: %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003540 return ret;
3541}
3542
3543/* AP mode changes */
3544static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003545 struct ieee80211_vif *vif,
3546 struct ieee80211_bss_conf *bss_conf,
3547 u32 changed)
3548{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003549 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003550 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003551
Arik Nemtsove78a2872010-10-16 19:07:21 +02003552 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3553 u32 rates = bss_conf->basic_rates;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003554
Eliad Peller87fbcb02011-10-05 11:55:41 +02003555 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003556 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003557 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
Eliad Peller87fbcb02011-10-05 11:55:41 +02003558 wlvif->basic_rate_set);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003559
Eliad Peller87fbcb02011-10-05 11:55:41 +02003560 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003561 if (ret < 0) {
Arik Nemtsov70f47422011-04-18 14:15:25 +03003562 wl1271_error("AP rate policy change failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003563 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003564 }
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003565
Eliad Peller784f6942011-10-05 11:55:39 +02003566 ret = wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +03003567 if (ret < 0)
3568 goto out;
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02003569 }
3570
Arik Nemtsove78a2872010-10-16 19:07:21 +02003571 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3572 if (ret < 0)
3573 goto out;
3574
3575 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3576 if (bss_conf->enable_beacon) {
Eliad Peller53d40d02011-10-10 10:13:02 +02003577 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003578 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003579 if (ret < 0)
3580 goto out;
3581
Eliad Pellera8ab39a2011-10-05 11:55:54 +02003582 ret = wl1271_ap_init_hwenc(wl, wlvif);
Arik Nemtsov7f179b42010-10-16 21:39:06 +02003583 if (ret < 0)
3584 goto out;
Arik Nemtsovcf420392011-08-14 13:17:37 +03003585
Eliad Peller53d40d02011-10-10 10:13:02 +02003586 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsovcf420392011-08-14 13:17:37 +03003587 wl1271_debug(DEBUG_AP, "started AP");
Arik Nemtsove78a2872010-10-16 19:07:21 +02003588 }
3589 } else {
Eliad Peller53d40d02011-10-10 10:13:02 +02003590 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003591 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003592 if (ret < 0)
3593 goto out;
3594
Eliad Peller53d40d02011-10-10 10:13:02 +02003595 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
Arik Nemtsov560f0022011-11-08 18:46:54 +02003596 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3597 &wlvif->flags);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003598 wl1271_debug(DEBUG_AP, "stopped AP");
3599 }
3600 }
3601 }
3602
Eliad Peller0603d892011-10-05 11:55:51 +02003603 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003604 if (ret < 0)
3605 goto out;
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003606
3607 /* Handle HT information change */
3608 if ((changed & BSS_CHANGED_HT) &&
3609 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003610 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003611 bss_conf->ht_operation_mode);
3612 if (ret < 0) {
3613 wl1271_warning("Set ht information failed %d", ret);
3614 goto out;
3615 }
3616 }
3617
Arik Nemtsove78a2872010-10-16 19:07:21 +02003618out:
3619 return;
3620}
3621
3622/* STA/IBSS mode changes */
3623static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3624 struct ieee80211_vif *vif,
3625 struct ieee80211_bss_conf *bss_conf,
3626 u32 changed)
3627{
Eliad Peller87fbcb02011-10-05 11:55:41 +02003628 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003629 bool do_join = false, set_assoc = false;
Eliad Peller536129c2011-10-05 11:55:45 +02003630 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
Eliad Peller227e81e2011-08-14 13:17:26 +03003631 bool ibss_joined = false;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003632 u32 sta_rate_set = 0;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003633 int ret;
Luciano Coelho2d6e4e762011-01-11 19:07:21 +01003634 struct ieee80211_sta *sta;
Arik Nemtsova1008852011-02-12 23:24:20 +02003635 bool sta_exists = false;
3636 struct ieee80211_sta_ht_cap sta_ht_cap;
Arik Nemtsove78a2872010-10-16 19:07:21 +02003637
3638 if (is_ibss) {
3639 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3640 changed);
3641 if (ret < 0)
3642 goto out;
3643 }
3644
Eliad Peller227e81e2011-08-14 13:17:26 +03003645 if (changed & BSS_CHANGED_IBSS) {
3646 if (bss_conf->ibss_joined) {
Eliad Pellereee514e2011-10-10 10:13:01 +02003647 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
Eliad Peller227e81e2011-08-14 13:17:26 +03003648 ibss_joined = true;
3649 } else {
Eliad Pellereee514e2011-10-10 10:13:01 +02003650 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
Eliad Peller349345a2012-03-04 10:55:45 +02003651 &wlvif->flags))
Eliad Peller0603d892011-10-05 11:55:51 +02003652 wl1271_unjoin(wl, wlvif);
Eliad Peller227e81e2011-08-14 13:17:26 +03003653 }
3654 }
3655
3656 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003657 do_join = true;
3658
3659 /* Need to update the SSID (for filtering etc) */
Eliad Peller227e81e2011-08-14 13:17:26 +03003660 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003661 do_join = true;
3662
Eliad Peller227e81e2011-08-14 13:17:26 +03003663 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003664 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3665 bss_conf->enable_beacon ? "enabled" : "disabled");
3666
Juuso Oikarinen5da11dc2010-03-26 12:53:24 +02003667 do_join = true;
3668 }
3669
Eliad Peller349345a2012-03-04 10:55:45 +02003670 if (changed & BSS_CHANGED_IDLE && !is_ibss) {
Eliad Pellerc31e4942011-10-23 08:21:55 +02003671 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3672 if (ret < 0)
3673 wl1271_warning("idle mode change failed %d", ret);
3674 }
3675
Arik Nemtsove78a2872010-10-16 19:07:21 +02003676 if ((changed & BSS_CHANGED_CQM)) {
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003677 bool enable = false;
3678 if (bss_conf->cqm_rssi_thold)
3679 enable = true;
Eliad Peller0603d892011-10-05 11:55:51 +02003680 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003681 bss_conf->cqm_rssi_thold,
3682 bss_conf->cqm_rssi_hyst);
3683 if (ret < 0)
3684 goto out;
Eliad Peller04324d92011-10-05 11:56:03 +02003685 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03003686 }
3687
Eliad Peller7db4ee62012-01-24 18:18:42 +02003688 if (changed & BSS_CHANGED_BSSID &&
3689 (is_ibss || bss_conf->assoc))
Eliad Pellercdf09492011-10-05 11:55:44 +02003690 if (!is_zero_ether_addr(bss_conf->bssid)) {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003691 ret = wl12xx_cmd_build_null_data(wl, wlvif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003692 if (ret < 0)
3693 goto out;
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003694
Eliad Peller784f6942011-10-05 11:55:39 +02003695 ret = wl1271_build_qos_null_data(wl, vif);
Eliad Pellerfa287b82010-12-26 09:27:50 +01003696 if (ret < 0)
3697 goto out;
Saravanan Dhanabal141418c2010-04-28 09:50:00 +03003698
Eliad Pellerfa287b82010-12-26 09:27:50 +01003699 /* Need to update the BSSID (for filtering etc) */
3700 do_join = true;
3701 }
Juuso Oikarinen30240fc2010-02-18 13:25:38 +02003702
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003703 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3704 rcu_read_lock();
3705 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3706 if (!sta)
3707 goto sta_not_found;
3708
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003709 /* save the supp_rates of the ap */
3710 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3711 if (sta->ht_cap.ht_supported)
3712 sta_rate_set |=
3713 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
Arik Nemtsova1008852011-02-12 23:24:20 +02003714 sta_ht_cap = sta->ht_cap;
3715 sta_exists = true;
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003716
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003717sta_not_found:
3718 rcu_read_unlock();
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003719 }
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003720
Arik Nemtsove78a2872010-10-16 19:07:21 +02003721 if ((changed & BSS_CHANGED_ASSOC)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003722 if (bss_conf->assoc) {
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003723 u32 rates;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003724 int ieoffset;
Eliad Peller6840e372011-10-05 11:55:50 +02003725 wlvif->aid = bss_conf->aid;
Eliad Peller66677762012-03-04 10:55:53 +02003726 wlvif->beacon_int = bss_conf->beacon_int;
Juuso Oikarinen69e54342010-05-07 11:39:00 +03003727 set_assoc = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003728
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003729 /*
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003730 * use basic rates from AP, and determine lowest rate
3731 * to use with control frames.
3732 */
3733 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003734 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003735 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003736 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003737 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003738 wl1271_tx_min_rate_get(wl,
3739 wlvif->basic_rate_set);
Eliad Peller72c2d9e2011-02-02 09:59:37 +02003740 if (sta_rate_set)
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003741 wlvif->rate_set =
3742 wl1271_tx_enabled_rates_get(wl,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003743 sta_rate_set,
Eliad Peller1b92f152011-10-10 10:13:09 +02003744 wlvif->band);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003745 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003746 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003747 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003748
3749 /*
Luciano Coelhoae751ba2009-10-12 15:08:57 +03003750 * with wl1271, we don't need to update the
3751 * beacon_int and dtim_period, because the firmware
3752 * updates it by itself when the first beacon is
3753 * received after a join.
3754 */
Eliad Peller6840e372011-10-05 11:55:50 +02003755 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003756 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003757 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003758
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003759 /*
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003760 * Get a template for hardware connection maintenance
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003761 */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003762 dev_kfree_skb(wlvif->probereq);
3763 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
Eliad Peller83587502011-10-10 10:12:53 +02003764 wlvif,
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003765 NULL);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003766 ieoffset = offsetof(struct ieee80211_mgmt,
3767 u.probe_req.variable);
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003768 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
Juuso Oikarinenc2b2d992010-03-26 12:53:28 +02003769
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003770 /* enable the connection monitoring feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003771 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003772 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003773 goto out;
Juuso Oikarinend94cd292009-10-08 21:56:25 +03003774 } else {
3775 /* use defaults when not associated */
Eliad Peller30df14d2011-04-05 19:13:28 +03003776 bool was_assoc =
Eliad Pellerba8447f2011-10-10 10:13:00 +02003777 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3778 &wlvif->flags);
Eliad Peller251c1772011-08-14 13:17:17 +03003779 bool was_ifup =
Eliad Peller8181aec2011-10-10 10:13:04 +02003780 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3781 &wlvif->flags);
Eliad Peller6840e372011-10-05 11:55:50 +02003782 wlvif->aid = 0;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003783
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003784 /* free probe-request template */
Eliad Pellerbddb29b2011-10-05 11:55:49 +02003785 dev_kfree_skb(wlvif->probereq);
3786 wlvif->probereq = NULL;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02003787
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003788 /* revert back to minimum rates for the current band */
Eliad Peller87fbcb02011-10-05 11:55:41 +02003789 wl1271_set_band_rate(wl, wlvif);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003790 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003791 wl1271_tx_min_rate_get(wl,
3792 wlvif->basic_rate_set);
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003793 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003794 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003795 goto out;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +03003796
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003797 /* disable connection monitor features */
Eliad Peller0603d892011-10-05 11:55:51 +02003798 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003799
3800 /* Disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +02003801 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +02003802 if (ret < 0)
Arik Nemtsove78a2872010-10-16 19:07:21 +02003803 goto out;
Juuso Oikarinenb84a7d32010-11-22 12:59:08 +02003804
3805 /* restore the bssid filter and go to dummy bssid */
Eliad Peller30df14d2011-04-05 19:13:28 +03003806 if (was_assoc) {
Eliad Peller251c1772011-08-14 13:17:17 +03003807 /*
3808 * we might have to disable roc, if there was
3809 * no IF_OPER_UP notification.
3810 */
3811 if (!was_ifup) {
Eliad Peller0603d892011-10-05 11:55:51 +02003812 ret = wl12xx_croc(wl, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003813 if (ret < 0)
3814 goto out;
3815 }
3816 /*
3817 * (we also need to disable roc in case of
3818 * roaming on the same channel. until we will
3819 * have a better flow...)
3820 */
Eliad Peller7edebf52011-10-05 11:55:52 +02003821 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3822 ret = wl12xx_croc(wl,
3823 wlvif->dev_role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003824 if (ret < 0)
3825 goto out;
3826 }
3827
Eliad Peller0603d892011-10-05 11:55:51 +02003828 wl1271_unjoin(wl, wlvif);
Eliad Peller8a6a84a2012-03-04 10:55:46 +02003829 if (!bss_conf->idle)
Eliad Peller679a6732011-10-11 11:55:44 +02003830 wl12xx_start_dev(wl, wlvif);
Eliad Peller30df14d2011-04-05 19:13:28 +03003831 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003832 }
3833 }
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03003834
Eliad Pellerd192d262011-05-24 14:33:08 +03003835 if (changed & BSS_CHANGED_IBSS) {
3836 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3837 bss_conf->ibss_joined);
3838
3839 if (bss_conf->ibss_joined) {
3840 u32 rates = bss_conf->basic_rates;
Eliad Peller87fbcb02011-10-05 11:55:41 +02003841 wlvif->basic_rate_set =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03003842 wl1271_tx_enabled_rates_get(wl, rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02003843 wlvif->band);
Eliad Pellerd2d66c52011-10-05 11:55:43 +02003844 wlvif->basic_rate =
Eliad Peller87fbcb02011-10-05 11:55:41 +02003845 wl1271_tx_min_rate_get(wl,
3846 wlvif->basic_rate_set);
Eliad Pellerd192d262011-05-24 14:33:08 +03003847
Shahar Levi06b660e2011-09-05 13:54:36 +03003848 /* by default, use 11b + OFDM rates */
Eliad Peller30d0c8f2011-10-05 11:55:42 +02003849 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3850 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Eliad Pellerd192d262011-05-24 14:33:08 +03003851 if (ret < 0)
3852 goto out;
3853 }
3854 }
3855
Eliad Peller0603d892011-10-05 11:55:51 +02003856 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003857 if (ret < 0)
3858 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003859
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003860 if (do_join) {
Eliad Peller87fbcb02011-10-05 11:55:41 +02003861 ret = wl1271_join(wl, wlvif, set_assoc);
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003862 if (ret < 0) {
3863 wl1271_warning("cmd join failed %d", ret);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003864 goto out;
Juuso Oikarinen8bf29b02010-02-18 13:25:51 +02003865 }
Eliad Peller251c1772011-08-14 13:17:17 +03003866
3867 /* ROC until connected (after EAPOL exchange) */
3868 if (!is_ibss) {
Eliad Peller1b92f152011-10-10 10:13:09 +02003869 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
Eliad Peller251c1772011-08-14 13:17:17 +03003870 if (ret < 0)
3871 goto out;
3872
Eliad Peller9fd6f212012-03-04 10:55:48 +02003873 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
3874 wl12xx_set_authorized(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003875 }
3876 /*
3877 * stop device role if started (we might already be in
Eliad Peller92e712d2011-12-18 20:25:43 +02003878 * STA/IBSS role).
Eliad Peller251c1772011-08-14 13:17:17 +03003879 */
Eliad Peller92e712d2011-12-18 20:25:43 +02003880 if (wl12xx_dev_role_started(wlvif)) {
Eliad Peller679a6732011-10-11 11:55:44 +02003881 ret = wl12xx_stop_dev(wl, wlvif);
Eliad Peller251c1772011-08-14 13:17:17 +03003882 if (ret < 0)
3883 goto out;
3884 }
Juuso Oikarinenc1899552010-03-26 12:53:32 +02003885 }
3886
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003887 /* Handle new association with HT. Do this after join. */
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003888 if (sta_exists) {
3889 if ((changed & BSS_CHANGED_HT) &&
3890 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003891 ret = wl1271_acx_set_ht_capabilities(wl,
3892 &sta_ht_cap,
3893 true,
Eliad Peller154da672011-10-05 11:55:53 +02003894 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003895 if (ret < 0) {
3896 wl1271_warning("Set ht cap true failed %d",
3897 ret);
3898 goto out;
3899 }
3900 }
3901 /* handle new association without HT and disassociation */
3902 else if (changed & BSS_CHANGED_ASSOC) {
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003903 ret = wl1271_acx_set_ht_capabilities(wl,
3904 &sta_ht_cap,
3905 false,
Eliad Peller154da672011-10-05 11:55:53 +02003906 wlvif->sta.hlid);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003907 if (ret < 0) {
3908 wl1271_warning("Set ht cap false failed %d",
3909 ret);
3910 goto out;
3911 }
3912 }
3913 }
3914
Arik Nemtsov0b932ab2011-08-14 13:17:27 +03003915 /* Handle HT information change. Done after join. */
3916 if ((changed & BSS_CHANGED_HT) &&
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003917 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
Eliad Peller0603d892011-10-05 11:55:51 +02003918 ret = wl1271_acx_set_ht_information(wl, wlvif,
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03003919 bss_conf->ht_operation_mode);
3920 if (ret < 0) {
3921 wl1271_warning("Set ht information failed %d", ret);
3922 goto out;
3923 }
3924 }
3925
Eliad Peller76a74c82012-02-02 12:22:11 +02003926 /* Handle arp filtering. Done after join. */
3927 if ((changed & BSS_CHANGED_ARP_FILTER) ||
3928 (!is_ibss && (changed & BSS_CHANGED_QOS))) {
3929 __be32 addr = bss_conf->arp_addr_list[0];
3930 wlvif->sta.qos = bss_conf->qos;
3931 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
3932
3933 if (bss_conf->arp_addr_cnt == 1 &&
3934 bss_conf->arp_filter_enabled) {
3935 wlvif->ip_addr = addr;
3936 /*
3937 * The template should have been configured only upon
3938 * association. however, it seems that the correct ip
3939 * isn't being set (when sending), so we have to
3940 * reconfigure the template upon every ip change.
3941 */
3942 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3943 if (ret < 0) {
3944 wl1271_warning("build arp rsp failed: %d", ret);
3945 goto out;
3946 }
3947
3948 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
3949 (ACX_ARP_FILTER_ARP_FILTERING |
3950 ACX_ARP_FILTER_AUTO_ARP),
3951 addr);
3952 } else {
3953 wlvif->ip_addr = 0;
3954 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
3955 }
3956
3957 if (ret < 0)
3958 goto out;
3959 }
3960
Arik Nemtsove78a2872010-10-16 19:07:21 +02003961out:
3962 return;
3963}
3964
3965static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3966 struct ieee80211_vif *vif,
3967 struct ieee80211_bss_conf *bss_conf,
3968 u32 changed)
3969{
3970 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02003971 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3972 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003973 int ret;
3974
3975 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3976 (int)changed);
3977
3978 mutex_lock(&wl->mutex);
3979
3980 if (unlikely(wl->state == WL1271_STATE_OFF))
3981 goto out;
3982
Eliad Peller10c8cd02011-10-10 10:13:06 +02003983 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3984 goto out;
3985
Ido Yariva6208652011-03-01 15:14:41 +02003986 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsove78a2872010-10-16 19:07:21 +02003987 if (ret < 0)
3988 goto out;
3989
3990 if (is_ap)
3991 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3992 else
3993 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3994
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03003995 wl1271_ps_elp_sleep(wl);
3996
3997out:
3998 mutex_unlock(&wl->mutex);
3999}
4000
Eliad Peller8a3a3c82011-10-02 10:15:52 +02004001static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
4002 struct ieee80211_vif *vif, u16 queue,
Kalle Valoc6999d82010-02-18 13:25:41 +02004003 const struct ieee80211_tx_queue_params *params)
4004{
4005 struct wl1271 *wl = hw->priv;
Eliad Peller0603d892011-10-05 11:55:51 +02004006 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo4695dc92010-03-18 12:26:38 +02004007 u8 ps_scheme;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004008 int ret = 0;
Kalle Valoc6999d82010-02-18 13:25:41 +02004009
4010 mutex_lock(&wl->mutex);
4011
4012 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
4013
Kalle Valo4695dc92010-03-18 12:26:38 +02004014 if (params->uapsd)
4015 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
4016 else
4017 ps_scheme = CONF_PS_SCHEME_LEGACY;
4018
Eliad Peller5b37ddf2011-12-18 20:25:40 +02004019 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004020 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004021
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004022 ret = wl1271_ps_elp_wakeup(wl);
4023 if (ret < 0)
4024 goto out;
Arik Nemtsov488fc542010-10-16 20:33:45 +02004025
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004026 /*
4027 * the txop is confed in units of 32us by the mac80211,
4028 * we need us
4029 */
Eliad Peller0603d892011-10-05 11:55:51 +02004030 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004031 params->cw_min, params->cw_max,
4032 params->aifs, params->txop << 5);
4033 if (ret < 0)
4034 goto out_sleep;
4035
Eliad Peller0603d892011-10-05 11:55:51 +02004036 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004037 CONF_CHANNEL_TYPE_EDCF,
4038 wl1271_tx_get_queue(queue),
4039 ps_scheme, CONF_ACK_POLICY_LEGACY,
4040 0, 0);
Kalle Valoc82c1dd2010-02-18 13:25:47 +02004041
4042out_sleep:
Eliad Pellerc1b193e2011-03-23 22:22:15 +02004043 wl1271_ps_elp_sleep(wl);
Kalle Valoc6999d82010-02-18 13:25:41 +02004044
4045out:
4046 mutex_unlock(&wl->mutex);
4047
4048 return ret;
4049}
4050
Eliad Peller37a41b42011-09-21 14:06:11 +03004051static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
4052 struct ieee80211_vif *vif)
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004053{
4054
4055 struct wl1271 *wl = hw->priv;
Eliad Peller9c531142012-01-31 11:57:18 +02004056 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004057 u64 mactime = ULLONG_MAX;
4058 int ret;
4059
4060 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
4061
4062 mutex_lock(&wl->mutex);
4063
Juuso Oikarinenf8d98022010-10-26 13:24:39 +02004064 if (unlikely(wl->state == WL1271_STATE_OFF))
4065 goto out;
4066
Ido Yariva6208652011-03-01 15:14:41 +02004067 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004068 if (ret < 0)
4069 goto out;
4070
Eliad Peller9c531142012-01-31 11:57:18 +02004071 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004072 if (ret < 0)
4073 goto out_sleep;
4074
4075out_sleep:
4076 wl1271_ps_elp_sleep(wl);
4077
4078out:
4079 mutex_unlock(&wl->mutex);
4080 return mactime;
4081}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004082
John W. Linvilleece550d2010-07-28 16:41:06 -04004083static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
4084 struct survey_info *survey)
4085{
4086 struct wl1271 *wl = hw->priv;
4087 struct ieee80211_conf *conf = &hw->conf;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004088
John W. Linvilleece550d2010-07-28 16:41:06 -04004089 if (idx != 0)
4090 return -ENOENT;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004091
John W. Linvilleece550d2010-07-28 16:41:06 -04004092 survey->channel = conf->channel;
4093 survey->filled = SURVEY_INFO_NOISE_DBM;
4094 survey->noise = wl->noise;
Juuso Oikarinenb739a422010-10-26 13:24:38 +02004095
John W. Linvilleece550d2010-07-28 16:41:06 -04004096 return 0;
4097}
4098
Arik Nemtsov409622e2011-02-23 00:22:29 +02004099static int wl1271_allocate_sta(struct wl1271 *wl,
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004100 struct wl12xx_vif *wlvif,
4101 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004102{
4103 struct wl1271_station *wl_sta;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004104 int ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004105
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004106
4107 if (wl->active_sta_count >= AP_MAX_STATIONS) {
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004108 wl1271_warning("could not allocate HLID - too much stations");
4109 return -EBUSY;
4110 }
4111
4112 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004113 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4114 if (ret < 0) {
4115 wl1271_warning("could not allocate HLID - too many links");
4116 return -EBUSY;
4117 }
4118
4119 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004120 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
Arik Nemtsovda032092011-08-25 12:43:15 +03004121 wl->active_sta_count++;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004122 return 0;
4123}
4124
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004125void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004126{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004127 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
Arik Nemtsovf1acea92011-08-25 12:43:17 +03004128 return;
4129
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004130 clear_bit(hlid, wlvif->ap.sta_hlid_map);
Arik Nemtsovb622d992011-02-23 00:22:31 +02004131 memset(wl->links[hlid].addr, 0, ETH_ALEN);
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004132 wl->links[hlid].ba_bitmap = 0;
Arik Nemtsovb622d992011-02-23 00:22:31 +02004133 __clear_bit(hlid, &wl->ap_ps_map);
4134 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004135 wl12xx_free_link(wl, wlvif, &hlid);
Arik Nemtsovda032092011-08-25 12:43:15 +03004136 wl->active_sta_count--;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004137}
4138
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004139static int wl12xx_sta_add(struct wl1271 *wl,
4140 struct wl12xx_vif *wlvif,
4141 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004142{
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004143 struct wl1271_station *wl_sta;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004144 int ret = 0;
4145 u8 hlid;
4146
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004147 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4148
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004149 ret = wl1271_allocate_sta(wl, wlvif, sta);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004150 if (ret < 0)
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004151 return ret;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004152
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004153 wl_sta = (struct wl1271_station *)sta->drv_priv;
4154 hlid = wl_sta->hlid;
4155
Eliad Peller1b92f152011-10-10 10:13:09 +02004156 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004157 if (ret < 0)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004158 wl1271_free_sta(wl, wlvif, hlid);
Arik Nemtsov409622e2011-02-23 00:22:29 +02004159
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004160 return ret;
4161}
4162
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004163static int wl12xx_sta_remove(struct wl1271 *wl,
4164 struct wl12xx_vif *wlvif,
4165 struct ieee80211_sta *sta)
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004166{
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004167 struct wl1271_station *wl_sta;
4168 int ret = 0, id;
4169
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004170 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4171
4172 wl_sta = (struct wl1271_station *)sta->drv_priv;
Eliad Pellerc7ffb902011-10-05 11:56:05 +02004173 id = wl_sta->hlid;
4174 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004175 return -EINVAL;
4176
4177 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
4178 if (ret < 0)
4179 return ret;
4180
4181 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
4182 return ret;
4183}
4184
4185static int wl12xx_update_sta_state(struct wl1271 *wl,
4186 struct wl12xx_vif *wlvif,
4187 struct ieee80211_sta *sta,
4188 enum ieee80211_sta_state old_state,
4189 enum ieee80211_sta_state new_state)
4190{
4191 struct wl1271_station *wl_sta;
4192 u8 hlid;
4193 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
4194 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
4195 int ret;
4196
4197 wl_sta = (struct wl1271_station *)sta->drv_priv;
4198 hlid = wl_sta->hlid;
4199
4200 /* Add station (AP mode) */
4201 if (is_ap &&
4202 old_state == IEEE80211_STA_NOTEXIST &&
4203 new_state == IEEE80211_STA_NONE)
4204 return wl12xx_sta_add(wl, wlvif, sta);
4205
4206 /* Remove station (AP mode) */
4207 if (is_ap &&
4208 old_state == IEEE80211_STA_NONE &&
4209 new_state == IEEE80211_STA_NOTEXIST) {
4210 /* must not fail */
4211 wl12xx_sta_remove(wl, wlvif, sta);
4212 return 0;
4213 }
4214
4215 /* Authorize station (AP mode) */
4216 if (is_ap &&
4217 new_state == IEEE80211_STA_AUTHORIZED) {
4218 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4219 if (ret < 0)
4220 return ret;
4221
4222 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
4223 hlid);
4224 return ret;
4225 }
4226
Eliad Peller9fd6f212012-03-04 10:55:48 +02004227 /* Authorize station */
4228 if (is_sta &&
4229 new_state == IEEE80211_STA_AUTHORIZED) {
4230 set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4231 return wl12xx_set_authorized(wl, wlvif);
4232 }
4233
4234 if (is_sta &&
4235 old_state == IEEE80211_STA_AUTHORIZED &&
4236 new_state == IEEE80211_STA_ASSOC) {
4237 clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4238 return 0;
4239 }
4240
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004241 return 0;
4242}
4243
4244static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
4245 struct ieee80211_vif *vif,
4246 struct ieee80211_sta *sta,
4247 enum ieee80211_sta_state old_state,
4248 enum ieee80211_sta_state new_state)
4249{
4250 struct wl1271 *wl = hw->priv;
4251 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4252 int ret;
4253
4254 wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
4255 sta->aid, old_state, new_state);
4256
4257 mutex_lock(&wl->mutex);
4258
4259 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4260 ret = -EBUSY;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004261 goto out;
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004262 }
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004263
Ido Yariva6208652011-03-01 15:14:41 +02004264 ret = wl1271_ps_elp_wakeup(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004265 if (ret < 0)
4266 goto out;
4267
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004268 ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004269
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004270 wl1271_ps_elp_sleep(wl);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004271out:
4272 mutex_unlock(&wl->mutex);
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004273 if (new_state < old_state)
4274 return 0;
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02004275 return ret;
4276}
4277
Luciano Coelho4623ec72011-03-21 19:26:41 +02004278static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4279 struct ieee80211_vif *vif,
4280 enum ieee80211_ampdu_mlme_action action,
4281 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4282 u8 buf_size)
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004283{
4284 struct wl1271 *wl = hw->priv;
Eliad Peller536129c2011-10-05 11:55:45 +02004285 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004286 int ret;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004287 u8 hlid, *ba_bitmap;
4288
4289 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4290 tid);
4291
4292 /* sanity check - the fields in FW are only 8bits wide */
4293 if (WARN_ON(tid > 0xFF))
4294 return -ENOTSUPP;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004295
4296 mutex_lock(&wl->mutex);
4297
4298 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4299 ret = -EAGAIN;
4300 goto out;
4301 }
4302
Eliad Peller536129c2011-10-05 11:55:45 +02004303 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
Eliad Peller154da672011-10-05 11:55:53 +02004304 hlid = wlvif->sta.hlid;
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004305 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
Eliad Peller536129c2011-10-05 11:55:45 +02004306 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004307 struct wl1271_station *wl_sta;
4308
4309 wl_sta = (struct wl1271_station *)sta->drv_priv;
4310 hlid = wl_sta->hlid;
4311 ba_bitmap = &wl->links[hlid].ba_bitmap;
4312 } else {
4313 ret = -EINVAL;
4314 goto out;
4315 }
4316
Ido Yariva6208652011-03-01 15:14:41 +02004317 ret = wl1271_ps_elp_wakeup(wl);
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004318 if (ret < 0)
4319 goto out;
4320
Shahar Levi70559a02011-05-22 16:10:22 +03004321 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4322 tid, action);
4323
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004324 switch (action) {
4325 case IEEE80211_AMPDU_RX_START:
Eliad Pellerd0802ab2011-10-05 11:56:04 +02004326 if (!wlvif->ba_support || !wlvif->ba_allowed) {
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004327 ret = -ENOTSUPP;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004328 break;
4329 }
4330
4331 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4332 ret = -EBUSY;
4333 wl1271_error("exceeded max RX BA sessions");
4334 break;
4335 }
4336
4337 if (*ba_bitmap & BIT(tid)) {
4338 ret = -EINVAL;
4339 wl1271_error("cannot enable RX BA session on active "
4340 "tid: %d", tid);
4341 break;
4342 }
4343
4344 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4345 hlid);
4346 if (!ret) {
4347 *ba_bitmap |= BIT(tid);
4348 wl->ba_rx_session_count++;
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004349 }
4350 break;
4351
4352 case IEEE80211_AMPDU_RX_STOP:
Arik Nemtsov0f9c8252011-08-17 10:45:49 +03004353 if (!(*ba_bitmap & BIT(tid))) {
4354 ret = -EINVAL;
4355 wl1271_error("no active RX BA session on tid: %d",
4356 tid);
4357 break;
4358 }
4359
4360 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4361 hlid);
4362 if (!ret) {
4363 *ba_bitmap &= ~BIT(tid);
4364 wl->ba_rx_session_count--;
4365 }
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004366 break;
4367
4368 /*
4369 * The BA initiator session management in FW independently.
4370 * Falling break here on purpose for all TX APDU commands.
4371 */
4372 case IEEE80211_AMPDU_TX_START:
4373 case IEEE80211_AMPDU_TX_STOP:
4374 case IEEE80211_AMPDU_TX_OPERATIONAL:
4375 ret = -EINVAL;
4376 break;
4377
4378 default:
4379 wl1271_error("Incorrect ampdu action id=%x\n", action);
4380 ret = -EINVAL;
4381 }
4382
4383 wl1271_ps_elp_sleep(wl);
4384
4385out:
4386 mutex_unlock(&wl->mutex);
4387
4388 return ret;
4389}
4390
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004391static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4392 struct ieee80211_vif *vif,
4393 const struct cfg80211_bitrate_mask *mask)
4394{
Eliad Peller83587502011-10-10 10:12:53 +02004395 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004396 struct wl1271 *wl = hw->priv;
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004397 int i, ret = 0;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004398
4399 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4400 mask->control[NL80211_BAND_2GHZ].legacy,
4401 mask->control[NL80211_BAND_5GHZ].legacy);
4402
4403 mutex_lock(&wl->mutex);
4404
4405 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Eliad Peller83587502011-10-10 10:12:53 +02004406 wlvif->bitrate_masks[i] =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004407 wl1271_tx_enabled_rates_get(wl,
4408 mask->control[i].legacy,
4409 i);
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004410
4411 if (unlikely(wl->state == WL1271_STATE_OFF))
4412 goto out;
4413
4414 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4415 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4416
4417 ret = wl1271_ps_elp_wakeup(wl);
4418 if (ret < 0)
4419 goto out;
4420
4421 wl1271_set_band_rate(wl, wlvif);
4422 wlvif->basic_rate =
4423 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4424 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4425
4426 wl1271_ps_elp_sleep(wl);
4427 }
4428out:
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004429 mutex_unlock(&wl->mutex);
4430
Eliad Pellerd6fa37c2011-10-11 11:57:39 +02004431 return ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004432}
4433
Shahar Levi6d158ff2011-09-08 13:01:33 +03004434static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4435 struct ieee80211_channel_switch *ch_switch)
4436{
4437 struct wl1271 *wl = hw->priv;
Eliad Peller52630c52011-10-10 10:13:08 +02004438 struct wl12xx_vif *wlvif;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004439 int ret;
4440
4441 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4442
Arik Nemtsovb9239b62012-02-28 00:41:33 +02004443 wl1271_tx_flush(wl);
4444
Shahar Levi6d158ff2011-09-08 13:01:33 +03004445 mutex_lock(&wl->mutex);
4446
4447 if (unlikely(wl->state == WL1271_STATE_OFF)) {
Eliad Peller6e8cd332011-10-10 10:13:13 +02004448 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4449 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4450 ieee80211_chswitch_done(vif, false);
4451 }
4452 goto out;
Shahar Levi6d158ff2011-09-08 13:01:33 +03004453 }
4454
4455 ret = wl1271_ps_elp_wakeup(wl);
4456 if (ret < 0)
4457 goto out;
4458
Eliad Peller52630c52011-10-10 10:13:08 +02004459 /* TODO: change mac80211 to pass vif as param */
4460 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller8332f0f2012-01-31 11:57:19 +02004461 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
Shahar Levi6d158ff2011-09-08 13:01:33 +03004462
Eliad Peller52630c52011-10-10 10:13:08 +02004463 if (!ret)
4464 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4465 }
Shahar Levi6d158ff2011-09-08 13:01:33 +03004466
4467 wl1271_ps_elp_sleep(wl);
4468
4469out:
4470 mutex_unlock(&wl->mutex);
4471}
4472
Arik Nemtsov33437892011-04-26 23:35:39 +03004473static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4474{
4475 struct wl1271 *wl = hw->priv;
4476 bool ret = false;
4477
4478 mutex_lock(&wl->mutex);
4479
4480 if (unlikely(wl->state == WL1271_STATE_OFF))
4481 goto out;
4482
4483 /* packets are considered pending if in the TX queue or the FW */
Arik Nemtsovf1a46382011-07-07 14:25:23 +03004484 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
Arik Nemtsov33437892011-04-26 23:35:39 +03004485out:
4486 mutex_unlock(&wl->mutex);
4487
4488 return ret;
4489}
4490
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004491/* can't be const, mac80211 writes to this */
4492static struct ieee80211_rate wl1271_rates[] = {
4493 { .bitrate = 10,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004494 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4495 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004496 { .bitrate = 20,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004497 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4498 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004499 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4500 { .bitrate = 55,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004501 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4502 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004503 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4504 { .bitrate = 110,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004505 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4506 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004507 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4508 { .bitrate = 60,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004509 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4510 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004511 { .bitrate = 90,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004512 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4513 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004514 { .bitrate = 120,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004515 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4516 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004517 { .bitrate = 180,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004518 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4519 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004520 { .bitrate = 240,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004521 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4522 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004523 { .bitrate = 360,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004524 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4525 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004526 { .bitrate = 480,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004527 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4528 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004529 { .bitrate = 540,
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +03004530 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4531 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004532};
4533
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004534/* can't be const, mac80211 writes to this */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004535static struct ieee80211_channel wl1271_channels[] = {
Luciano Coelhoa2d0e3f2009-12-11 15:40:46 +02004536 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004537 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004538 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4539 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4540 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004541 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004542 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4543 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4544 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
Juuso Oikarinenfa21c7a2010-08-10 08:22:02 +02004545 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004546 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4547 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4548 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
Arik Nemtsov6c89b7b2011-01-18 20:39:52 +01004549 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004550};
4551
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004552/* mapping to indexes for wl1271_rates */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004553static const u8 wl1271_rate_to_idx_2ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004554 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004555 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004556 7, /* CONF_HW_RXTX_RATE_MCS7 */
4557 6, /* CONF_HW_RXTX_RATE_MCS6 */
4558 5, /* CONF_HW_RXTX_RATE_MCS5 */
4559 4, /* CONF_HW_RXTX_RATE_MCS4 */
4560 3, /* CONF_HW_RXTX_RATE_MCS3 */
4561 2, /* CONF_HW_RXTX_RATE_MCS2 */
4562 1, /* CONF_HW_RXTX_RATE_MCS1 */
4563 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004564
4565 11, /* CONF_HW_RXTX_RATE_54 */
4566 10, /* CONF_HW_RXTX_RATE_48 */
4567 9, /* CONF_HW_RXTX_RATE_36 */
4568 8, /* CONF_HW_RXTX_RATE_24 */
4569
4570 /* TI-specific rate */
4571 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4572
4573 7, /* CONF_HW_RXTX_RATE_18 */
4574 6, /* CONF_HW_RXTX_RATE_12 */
4575 3, /* CONF_HW_RXTX_RATE_11 */
4576 5, /* CONF_HW_RXTX_RATE_9 */
4577 4, /* CONF_HW_RXTX_RATE_6 */
4578 2, /* CONF_HW_RXTX_RATE_5_5 */
4579 1, /* CONF_HW_RXTX_RATE_2 */
4580 0 /* CONF_HW_RXTX_RATE_1 */
4581};
4582
Shahar Levie8b03a22010-10-13 16:09:39 +02004583/* 11n STA capabilities */
4584#define HW_RX_HIGHEST_RATE 72
4585
Shahar Levi00d20102010-11-08 11:20:10 +00004586#define WL12XX_HT_CAP { \
Shahar Levi871d0c32011-03-13 11:24:40 +02004587 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4588 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
Shahar Levie8b03a22010-10-13 16:09:39 +02004589 .ht_supported = true, \
4590 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4591 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4592 .mcs = { \
4593 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4594 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4595 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4596 }, \
4597}
4598
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004599/* can't be const, mac80211 writes to this */
4600static struct ieee80211_supported_band wl1271_band_2ghz = {
4601 .channels = wl1271_channels,
4602 .n_channels = ARRAY_SIZE(wl1271_channels),
4603 .bitrates = wl1271_rates,
4604 .n_bitrates = ARRAY_SIZE(wl1271_rates),
Shahar Levi00d20102010-11-08 11:20:10 +00004605 .ht_cap = WL12XX_HT_CAP,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004606};
4607
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004608/* 5 GHz data rates for WL1273 */
4609static struct ieee80211_rate wl1271_rates_5ghz[] = {
4610 { .bitrate = 60,
4611 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4612 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4613 { .bitrate = 90,
4614 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4615 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4616 { .bitrate = 120,
4617 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4618 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4619 { .bitrate = 180,
4620 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4621 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4622 { .bitrate = 240,
4623 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4624 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4625 { .bitrate = 360,
4626 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4627 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4628 { .bitrate = 480,
4629 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4630 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4631 { .bitrate = 540,
4632 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4633 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4634};
4635
Juuso Oikarinenfa97f462010-11-10 11:27:20 +01004636/* 5 GHz band channels for WL1273 */
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004637static struct ieee80211_channel wl1271_channels_5ghz[] = {
Arik Nemtsov6cfa5cf2011-06-27 22:06:33 +03004638 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4639 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4640 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4641 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4642 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4643 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4644 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4645 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4646 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4647 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4648 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4649 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4650 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4651 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4652 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4653 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4654 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4655 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4656 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4657 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4658 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4659 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4660 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4661 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4662 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4663 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4664 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4665 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4666 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4667 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4668 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4669 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4670 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4671 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004672};
4673
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004674/* mapping to indexes for wl1271_rates_5ghz */
Tobias Klausera0ea9492010-05-20 10:38:11 +02004675static const u8 wl1271_rate_to_idx_5ghz[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004676 /* MCS rates are used only with 11n */
Pontus Fuchsdefe02c2012-01-31 17:54:41 +02004677 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
Shahar Levi18357852010-10-13 16:09:41 +02004678 7, /* CONF_HW_RXTX_RATE_MCS7 */
4679 6, /* CONF_HW_RXTX_RATE_MCS6 */
4680 5, /* CONF_HW_RXTX_RATE_MCS5 */
4681 4, /* CONF_HW_RXTX_RATE_MCS4 */
4682 3, /* CONF_HW_RXTX_RATE_MCS3 */
4683 2, /* CONF_HW_RXTX_RATE_MCS2 */
4684 1, /* CONF_HW_RXTX_RATE_MCS1 */
4685 0, /* CONF_HW_RXTX_RATE_MCS0 */
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004686
4687 7, /* CONF_HW_RXTX_RATE_54 */
4688 6, /* CONF_HW_RXTX_RATE_48 */
4689 5, /* CONF_HW_RXTX_RATE_36 */
4690 4, /* CONF_HW_RXTX_RATE_24 */
4691
4692 /* TI-specific rate */
4693 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4694
4695 3, /* CONF_HW_RXTX_RATE_18 */
4696 2, /* CONF_HW_RXTX_RATE_12 */
4697 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4698 1, /* CONF_HW_RXTX_RATE_9 */
4699 0, /* CONF_HW_RXTX_RATE_6 */
4700 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4701 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4702 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4703};
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004704
4705static struct ieee80211_supported_band wl1271_band_5ghz = {
4706 .channels = wl1271_channels_5ghz,
4707 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4708 .bitrates = wl1271_rates_5ghz,
4709 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
Shahar Levi00d20102010-11-08 11:20:10 +00004710 .ht_cap = WL12XX_HT_CAP,
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03004711};
4712
Tobias Klausera0ea9492010-05-20 10:38:11 +02004713static const u8 *wl1271_band_rate_to_idx[] = {
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004714 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4715 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4716};
4717
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004718static const struct ieee80211_ops wl1271_ops = {
4719 .start = wl1271_op_start,
4720 .stop = wl1271_op_stop,
4721 .add_interface = wl1271_op_add_interface,
4722 .remove_interface = wl1271_op_remove_interface,
Eliad Pellerc0fad1b2011-12-19 12:00:03 +02004723 .change_interface = wl12xx_op_change_interface,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004724#ifdef CONFIG_PM
Eliad Peller402e48612011-05-13 11:57:09 +03004725 .suspend = wl1271_op_suspend,
4726 .resume = wl1271_op_resume,
Luciano Coelhof634a4e2011-05-18 16:51:26 -04004727#endif
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004728 .config = wl1271_op_config,
Juuso Oikarinenc87dec92009-10-08 21:56:31 +03004729 .prepare_multicast = wl1271_op_prepare_multicast,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004730 .configure_filter = wl1271_op_configure_filter,
4731 .tx = wl1271_op_tx,
4732 .set_key = wl1271_op_set_key,
4733 .hw_scan = wl1271_op_hw_scan,
Eliad Peller73ecce32011-06-27 13:06:45 +03004734 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
Luciano Coelho33c2c062011-05-10 14:46:02 +03004735 .sched_scan_start = wl1271_op_sched_scan_start,
4736 .sched_scan_stop = wl1271_op_sched_scan_stop,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004737 .bss_info_changed = wl1271_op_bss_info_changed,
Arik Nemtsov68d069c2010-11-08 10:51:07 +01004738 .set_frag_threshold = wl1271_op_set_frag_threshold,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004739 .set_rts_threshold = wl1271_op_set_rts_threshold,
Kalle Valoc6999d82010-02-18 13:25:41 +02004740 .conf_tx = wl1271_op_conf_tx,
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03004741 .get_tsf = wl1271_op_get_tsf,
John W. Linvilleece550d2010-07-28 16:41:06 -04004742 .get_survey = wl1271_op_get_survey,
Eliad Peller2d6cf2b2012-03-04 10:55:47 +02004743 .sta_state = wl12xx_op_sta_state,
Levi, Shaharbbba3e62011-01-23 07:27:23 +01004744 .ampdu_action = wl1271_op_ampdu_action,
Arik Nemtsov33437892011-04-26 23:35:39 +03004745 .tx_frames_pending = wl1271_tx_frames_pending,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03004746 .set_bitrate_mask = wl12xx_set_bitrate_mask,
Shahar Levi6d158ff2011-09-08 13:01:33 +03004747 .channel_switch = wl12xx_op_channel_switch,
Kalle Valoc8c90872010-02-18 13:25:53 +02004748 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03004749};
4750
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004751
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004752u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004753{
4754 u8 idx;
4755
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004756 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004757
4758 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4759 wl1271_error("Illegal RX rate from HW: %d", rate);
4760 return 0;
4761 }
4762
Teemu Paasikivi6a2de932010-10-14 11:00:04 +02004763 idx = wl1271_band_rate_to_idx[band][rate];
Juuso Oikarinenf876bb92010-03-26 12:53:11 +02004764 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4765 wl1271_error("Unsupported RX rate from HW: %d", rate);
4766 return 0;
4767 }
4768
4769 return idx;
4770}
4771
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004772static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4773 struct device_attribute *attr,
4774 char *buf)
4775{
4776 struct wl1271 *wl = dev_get_drvdata(dev);
4777 ssize_t len;
4778
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004779 len = PAGE_SIZE;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004780
4781 mutex_lock(&wl->mutex);
4782 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4783 wl->sg_enabled);
4784 mutex_unlock(&wl->mutex);
4785
4786 return len;
4787
4788}
4789
4790static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4791 struct device_attribute *attr,
4792 const char *buf, size_t count)
4793{
4794 struct wl1271 *wl = dev_get_drvdata(dev);
4795 unsigned long res;
4796 int ret;
4797
Luciano Coelho6277ed62011-04-01 17:49:54 +03004798 ret = kstrtoul(buf, 10, &res);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004799 if (ret < 0) {
4800 wl1271_warning("incorrect value written to bt_coex_mode");
4801 return count;
4802 }
4803
4804 mutex_lock(&wl->mutex);
4805
4806 res = !!res;
4807
4808 if (res == wl->sg_enabled)
4809 goto out;
4810
4811 wl->sg_enabled = res;
4812
4813 if (wl->state == WL1271_STATE_OFF)
4814 goto out;
4815
Ido Yariva6208652011-03-01 15:14:41 +02004816 ret = wl1271_ps_elp_wakeup(wl);
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02004817 if (ret < 0)
4818 goto out;
4819
4820 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4821 wl1271_ps_elp_sleep(wl);
4822
4823 out:
4824 mutex_unlock(&wl->mutex);
4825 return count;
4826}
4827
4828static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4829 wl1271_sysfs_show_bt_coex_state,
4830 wl1271_sysfs_store_bt_coex_state);
4831
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004832static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4833 struct device_attribute *attr,
4834 char *buf)
4835{
4836 struct wl1271 *wl = dev_get_drvdata(dev);
4837 ssize_t len;
4838
Juuso Oikarinen2f63b012010-08-10 06:38:35 +02004839 len = PAGE_SIZE;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004840
4841 mutex_lock(&wl->mutex);
4842 if (wl->hw_pg_ver >= 0)
4843 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4844 else
4845 len = snprintf(buf, len, "n/a\n");
4846 mutex_unlock(&wl->mutex);
4847
4848 return len;
4849}
4850
Gery Kahn6f07b722011-07-18 14:21:49 +03004851static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
Juuso Oikarinend717fd62010-05-07 11:38:58 +03004852 wl1271_sysfs_show_hw_pg_ver, NULL);
4853
Ido Yariv95dac04f2011-06-06 14:57:06 +03004854static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4855 struct bin_attribute *bin_attr,
4856 char *buffer, loff_t pos, size_t count)
4857{
4858 struct device *dev = container_of(kobj, struct device, kobj);
4859 struct wl1271 *wl = dev_get_drvdata(dev);
4860 ssize_t len;
4861 int ret;
4862
4863 ret = mutex_lock_interruptible(&wl->mutex);
4864 if (ret < 0)
4865 return -ERESTARTSYS;
4866
4867 /* Let only one thread read the log at a time, blocking others */
4868 while (wl->fwlog_size == 0) {
4869 DEFINE_WAIT(wait);
4870
4871 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4872 &wait,
4873 TASK_INTERRUPTIBLE);
4874
4875 if (wl->fwlog_size != 0) {
4876 finish_wait(&wl->fwlog_waitq, &wait);
4877 break;
4878 }
4879
4880 mutex_unlock(&wl->mutex);
4881
4882 schedule();
4883 finish_wait(&wl->fwlog_waitq, &wait);
4884
4885 if (signal_pending(current))
4886 return -ERESTARTSYS;
4887
4888 ret = mutex_lock_interruptible(&wl->mutex);
4889 if (ret < 0)
4890 return -ERESTARTSYS;
4891 }
4892
4893 /* Check if the fwlog is still valid */
4894 if (wl->fwlog_size < 0) {
4895 mutex_unlock(&wl->mutex);
4896 return 0;
4897 }
4898
4899 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4900 len = min(count, (size_t)wl->fwlog_size);
4901 wl->fwlog_size -= len;
4902 memcpy(buffer, wl->fwlog, len);
4903
4904 /* Make room for new messages */
4905 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4906
4907 mutex_unlock(&wl->mutex);
4908
4909 return len;
4910}
4911
4912static struct bin_attribute fwlog_attr = {
4913 .attr = {.name = "fwlog", .mode = S_IRUSR},
4914 .read = wl1271_sysfs_read_fwlog,
4915};
4916
Luciano Coelho5e037e72011-12-23 09:32:17 +02004917static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4918{
4919 bool supported = false;
4920 u8 major, minor;
4921
4922 if (wl->chip.id == CHIP_ID_1283_PG20) {
4923 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
4924 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
4925
4926 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
4927 if (major > 2 || (major == 2 && minor >= 1))
4928 supported = true;
4929 } else {
4930 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
4931 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
4932
4933 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
4934 if (major == 3 && minor >= 1)
4935 supported = true;
4936 }
4937
4938 wl1271_debug(DEBUG_PROBE,
4939 "PG Ver major = %d minor = %d, MAC %s present",
4940 major, minor, supported ? "is" : "is not");
4941
4942 return supported;
4943}
4944
4945static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4946 u32 oui, u32 nic, int n)
4947{
4948 int i;
4949
4950 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
4951 oui, nic, n);
4952
4953 if (nic + n - 1 > 0xffffff)
4954 wl1271_warning("NIC part of the MAC address wraps around!");
4955
4956 for (i = 0; i < n; i++) {
4957 wl->addresses[i].addr[0] = (u8)(oui >> 16);
4958 wl->addresses[i].addr[1] = (u8)(oui >> 8);
4959 wl->addresses[i].addr[2] = (u8) oui;
4960 wl->addresses[i].addr[3] = (u8)(nic >> 16);
4961 wl->addresses[i].addr[4] = (u8)(nic >> 8);
4962 wl->addresses[i].addr[5] = (u8) nic;
4963 nic++;
4964 }
4965
4966 wl->hw->wiphy->n_addresses = n;
4967 wl->hw->wiphy->addresses = wl->addresses;
4968}
4969
4970static void wl12xx_get_fuse_mac(struct wl1271 *wl)
4971{
4972 u32 mac1, mac2;
4973
4974 wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
4975
4976 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
4977 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
4978
4979 /* these are the two parts of the BD_ADDR */
4980 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
4981 ((mac1 & 0xff000000) >> 24);
4982 wl->fuse_nic_addr = mac1 & 0xffffff;
4983
4984 wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
4985}
4986
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02004987static int wl12xx_get_hw_info(struct wl1271 *wl)
4988{
4989 int ret;
4990 u32 die_info;
4991
4992 ret = wl12xx_set_power_on(wl);
4993 if (ret < 0)
4994 goto out;
4995
4996 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
4997
4998 if (wl->chip.id == CHIP_ID_1283_PG20)
4999 die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
5000 else
5001 die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
5002
5003 wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
5004
Luciano Coelho5e037e72011-12-23 09:32:17 +02005005 if (!wl12xx_mac_in_fuse(wl)) {
5006 wl->fuse_oui_addr = 0;
5007 wl->fuse_nic_addr = 0;
5008 } else {
5009 wl12xx_get_fuse_mac(wl);
5010 }
5011
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005012 wl1271_power_off(wl);
5013out:
5014 return ret;
5015}
5016
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005017static int wl1271_register_hw(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005018{
5019 int ret;
Luciano Coelho5e037e72011-12-23 09:32:17 +02005020 u32 oui_addr = 0, nic_addr = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005021
5022 if (wl->mac80211_registered)
5023 return 0;
5024
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005025 ret = wl12xx_get_hw_info(wl);
5026 if (ret < 0) {
5027 wl1271_error("couldn't get hw info");
5028 goto out;
5029 }
5030
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005031 ret = wl1271_fetch_nvs(wl);
5032 if (ret == 0) {
Shahar Levibc765bf2011-03-06 16:32:10 +02005033 /* NOTE: The wl->nvs->nvs element must be first, in
5034 * order to simplify the casting, we assume it is at
5035 * the beginning of the wl->nvs structure.
5036 */
5037 u8 *nvs_ptr = (u8 *)wl->nvs;
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005038
Luciano Coelho5e037e72011-12-23 09:32:17 +02005039 oui_addr =
5040 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
5041 nic_addr =
5042 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
Arik Nemtsov31d26ec2010-10-16 21:49:52 +02005043 }
5044
Luciano Coelho5e037e72011-12-23 09:32:17 +02005045 /* if the MAC address is zeroed in the NVS derive from fuse */
5046 if (oui_addr == 0 && nic_addr == 0) {
5047 oui_addr = wl->fuse_oui_addr;
5048 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5049 nic_addr = wl->fuse_nic_addr + 1;
5050 }
5051
5052 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005053
5054 ret = ieee80211_register_hw(wl->hw);
5055 if (ret < 0) {
5056 wl1271_error("unable to register mac80211 hw: %d", ret);
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005057 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005058 }
5059
5060 wl->mac80211_registered = true;
5061
Eliad Pellerd60080a2010-11-24 12:53:16 +02005062 wl1271_debugfs_init(wl);
5063
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005064 wl1271_notice("loaded");
5065
Luciano Coelho30c5dbd2012-01-18 14:53:22 +02005066out:
5067 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005068}
5069
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005070static void wl1271_unregister_hw(struct wl1271 *wl)
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005071{
Eliad Peller3fcdab72012-02-06 12:47:54 +02005072 if (wl->plt)
Ido Yarivf3df1332012-01-11 09:42:39 +02005073 wl1271_plt_stop(wl);
Juuso Oikarinen4ae3fa82011-01-14 12:48:46 +01005074
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005075 ieee80211_unregister_hw(wl->hw);
5076 wl->mac80211_registered = false;
5077
5078}
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005079
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005080static int wl1271_init_ieee80211(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005081{
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005082 static const u32 cipher_suites[] = {
5083 WLAN_CIPHER_SUITE_WEP40,
5084 WLAN_CIPHER_SUITE_WEP104,
5085 WLAN_CIPHER_SUITE_TKIP,
5086 WLAN_CIPHER_SUITE_CCMP,
5087 WL1271_CIPHER_SUITE_GEM,
5088 };
5089
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005090 /* The tx descriptor buffer and the TKIP space. */
Eliad Peller5ec8a442012-02-02 12:22:09 +02005091 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +03005092 sizeof(struct wl1271_tx_hw_descr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005093
5094 /* unit us */
5095 /* FIXME: find a proper value */
5096 wl->hw->channel_change_time = 10000;
Juuso Oikarinen50c500a2010-04-01 11:38:22 +03005097 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005098
5099 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
Juuso Oikarinen0a343322010-02-22 08:38:41 +02005100 IEEE80211_HW_SUPPORTS_PS |
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02005101 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
Kalle Valo4695dc92010-03-18 12:26:38 +02005102 IEEE80211_HW_SUPPORTS_UAPSD |
Juuso Oikarinena9af0922010-03-26 12:53:30 +02005103 IEEE80211_HW_HAS_RATE_CONTROL |
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03005104 IEEE80211_HW_CONNECTION_MONITOR |
Luciano Coelho25eaea302011-05-02 12:37:33 +03005105 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Shahar Levifcd23b62011-05-11 12:12:56 +03005106 IEEE80211_HW_SPECTRUM_MGMT |
Arik Nemtsov93f8c8e2011-08-30 09:34:01 +03005107 IEEE80211_HW_AP_LINK_PS |
5108 IEEE80211_HW_AMPDU_AGGREGATION |
Eliad Peller79aba1b2012-02-02 13:15:35 +02005109 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
5110 IEEE80211_HW_SCAN_WHILE_IDLE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005111
Juuso Oikarinen7a557242010-09-27 12:42:07 +02005112 wl->hw->wiphy->cipher_suites = cipher_suites;
5113 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5114
Juuso Oikarinene0d8bbf2009-12-11 15:41:04 +02005115 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
Eliad Peller045c7452011-08-28 15:23:01 +03005116 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
5117 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005118 wl->hw->wiphy->max_scan_ssids = 1;
Luciano Coelho221737d2011-09-02 14:28:22 +03005119 wl->hw->wiphy->max_sched_scan_ssids = 16;
5120 wl->hw->wiphy->max_match_sets = 16;
Guy Eilamea559b42010-12-09 16:54:59 +02005121 /*
5122 * Maximum length of elements in scanning probe request templates
5123 * should be the maximum length possible for a template, without
5124 * the IEEE80211 header of the template
5125 */
Ido Reisc08e3712012-02-02 13:54:27 +02005126 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Guy Eilamea559b42010-12-09 16:54:59 +02005127 sizeof(struct ieee80211_header);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005128
Ido Reisc08e3712012-02-02 13:54:27 +02005129 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
Luciano Coelhoc9e79a42011-09-27 16:22:35 +03005130 sizeof(struct ieee80211_header);
5131
Eliad Peller1ec23f72011-08-25 14:26:54 +03005132 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5133
Luciano Coelho4a31c112011-03-21 23:16:14 +02005134 /* make sure all our channels fit in the scanned_ch bitmask */
5135 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
5136 ARRAY_SIZE(wl1271_channels_5ghz) >
5137 WL1271_MAX_CHANNELS);
Luciano Coelhoa8aaaf52011-01-11 18:25:18 +01005138 /*
5139 * We keep local copies of the band structs because we need to
5140 * modify them on a per-device basis.
5141 */
5142 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5143 sizeof(wl1271_band_2ghz));
5144 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5145 sizeof(wl1271_band_5ghz));
5146
5147 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5148 &wl->bands[IEEE80211_BAND_2GHZ];
5149 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5150 &wl->bands[IEEE80211_BAND_5GHZ];
Teemu Paasikivi1ebec3d2009-10-13 12:47:48 +03005151
Kalle Valo12bd8942010-03-18 12:26:33 +02005152 wl->hw->queues = 4;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +02005153 wl->hw->max_rates = 1;
Kalle Valo12bd8942010-03-18 12:26:33 +02005154
Juuso Oikarinenb7417d92010-11-10 11:27:19 +01005155 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5156
Arik Nemtsov9c1b1902011-11-08 18:46:55 +02005157 /* the FW answers probe-requests in AP-mode */
5158 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5159 wl->hw->wiphy->probe_resp_offload =
5160 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5161 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5162 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5163
Felipe Balbia390e852011-10-06 10:07:44 +03005164 SET_IEEE80211_DEV(wl->hw, wl->dev);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005165
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005166 wl->hw->sta_data_size = sizeof(struct wl1271_station);
Eliad Peller87fbcb02011-10-05 11:55:41 +02005167 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
Arik Nemtsovf84f7d72010-10-16 20:21:23 +02005168
Luciano Coelho4c9cfa72011-01-12 14:27:03 +01005169 wl->hw->max_rx_aggregation_subframes = 8;
5170
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005171 return 0;
5172}
5173
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005174#define WL1271_DEFAULT_CHANNEL 0
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005175
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005176static struct ieee80211_hw *wl1271_alloc_hw(void)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005177{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005178 struct ieee80211_hw *hw;
5179 struct wl1271 *wl;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005180 int i, j, ret;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005181 unsigned int order;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005182
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005183 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
Arik Nemtsovf80c2d12011-09-22 09:52:05 +03005184
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005185 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5186 if (!hw) {
5187 wl1271_error("could not alloc ieee80211_hw");
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005188 ret = -ENOMEM;
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005189 goto err_hw_alloc;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005190 }
5191
5192 wl = hw->priv;
5193 memset(wl, 0, sizeof(*wl));
5194
Eliad Peller87627212011-10-10 10:12:54 +02005195 INIT_LIST_HEAD(&wl->wlvif_list);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03005196
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005197 wl->hw = hw;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005198
Juuso Oikarinen6742f552010-12-13 09:52:37 +02005199 for (i = 0; i < NUM_TX_QUEUES; i++)
Eliad Pellerc7ffb902011-10-05 11:56:05 +02005200 for (j = 0; j < WL12XX_MAX_LINKS; j++)
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +02005201 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5202
Ido Yariva6208652011-03-01 15:14:41 +02005203 skb_queue_head_init(&wl->deferred_rx_queue);
5204 skb_queue_head_init(&wl->deferred_tx_queue);
5205
Juuso Oikarinen37b70a82009-10-08 21:56:21 +03005206 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
Ido Yariva6208652011-03-01 15:14:41 +02005207 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
Juuso Oikarinen117b38d2010-09-30 10:43:28 +02005208 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5209 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5210 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
Eliad Peller77ddaa12011-05-15 11:10:29 +03005211
Eliad Peller92ef8962011-06-07 12:50:46 +03005212 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5213 if (!wl->freezable_wq) {
5214 ret = -ENOMEM;
5215 goto err_hw;
5216 }
5217
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005218 wl->channel = WL1271_DEFAULT_CHANNEL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005219 wl->rx_counter = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005220 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +03005221 wl->band = IEEE80211_BAND_2GHZ;
Juuso Oikarinen830fb672009-12-11 15:41:06 +02005222 wl->flags = 0;
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +02005223 wl->sg_enabled = true;
Juuso Oikarinend717fd62010-05-07 11:38:58 +03005224 wl->hw_pg_ver = -1;
Arik Nemtsovb622d992011-02-23 00:22:31 +02005225 wl->ap_ps_map = 0;
5226 wl->ap_fw_ps_map = 0;
Ido Yariv606ea9f2011-03-01 15:14:39 +02005227 wl->quirks = 0;
Ido Yariv341b7cd2011-03-31 10:07:01 +02005228 wl->platform_quirks = 0;
Luciano Coelho33c2c062011-05-10 14:46:02 +03005229 wl->sched_scanning = false;
Guy Eilame9eb8cb2011-08-16 19:49:12 +03005230 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005231 wl->system_hlid = WL12XX_SYSTEM_HLID;
Arik Nemtsovda032092011-08-25 12:43:15 +03005232 wl->active_sta_count = 0;
Ido Yariv95dac04f2011-06-06 14:57:06 +03005233 wl->fwlog_size = 0;
5234 init_waitqueue_head(&wl->fwlog_waitq);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005235
Eliad Pellerf4df1bd2011-08-14 13:17:15 +03005236 /* The system link is always allocated */
5237 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5238
Ido Yariv25eeb9e2010-10-12 16:20:06 +02005239 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +03005240 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005241 wl->tx_frames[i] = NULL;
5242
5243 spin_lock_init(&wl->wl_lock);
5244
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005245 wl->state = WL1271_STATE_OFF;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005246 wl->fw_type = WL12XX_FW_TYPE_NONE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005247 mutex_init(&wl->mutex);
5248
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005249 /* Apply default driver configuration. */
5250 wl1271_conf_init(wl);
5251
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005252 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5253 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5254 if (!wl->aggr_buf) {
5255 ret = -ENOMEM;
Eliad Peller92ef8962011-06-07 12:50:46 +03005256 goto err_wq;
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005257 }
5258
Ido Yariv990f5de2011-03-31 10:06:59 +02005259 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5260 if (!wl->dummy_packet) {
5261 ret = -ENOMEM;
5262 goto err_aggr;
5263 }
5264
Ido Yariv95dac04f2011-06-06 14:57:06 +03005265 /* Allocate one page for the FW log */
5266 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5267 if (!wl->fwlog) {
5268 ret = -ENOMEM;
5269 goto err_dummy_packet;
5270 }
5271
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005272 return hw;
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005273
Ido Yariv990f5de2011-03-31 10:06:59 +02005274err_dummy_packet:
5275 dev_kfree_skb(wl->dummy_packet);
5276
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005277err_aggr:
5278 free_pages((unsigned long)wl->aggr_buf, order);
5279
Eliad Peller92ef8962011-06-07 12:50:46 +03005280err_wq:
5281 destroy_workqueue(wl->freezable_wq);
5282
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005283err_hw:
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005284 wl1271_debugfs_exit(wl);
Teemu Paasikivi3b56dd62010-03-18 12:26:46 +02005285 ieee80211_free_hw(hw);
5286
5287err_hw_alloc:
5288
Juuso Oikarinena1dd8182010-03-18 12:26:31 +02005289 return ERR_PTR(ret);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005290}
5291
Felipe Balbi4b32a2c2011-10-06 10:46:20 +03005292static int wl1271_free_hw(struct wl1271 *wl)
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005293{
Ido Yariv95dac04f2011-06-06 14:57:06 +03005294 /* Unblock any fwlog readers */
5295 mutex_lock(&wl->mutex);
5296 wl->fwlog_size = -1;
5297 wake_up_interruptible_all(&wl->fwlog_waitq);
5298 mutex_unlock(&wl->mutex);
5299
Felipe Balbif79f8902011-10-06 13:05:25 +03005300 device_remove_bin_file(wl->dev, &fwlog_attr);
Gery Kahn6f07b722011-07-18 14:21:49 +03005301
Felipe Balbif79f8902011-10-06 13:05:25 +03005302 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
Gery Kahn6f07b722011-07-18 14:21:49 +03005303
Felipe Balbif79f8902011-10-06 13:05:25 +03005304 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
Ido Yariv95dac04f2011-06-06 14:57:06 +03005305 free_page((unsigned long)wl->fwlog);
Ido Yariv990f5de2011-03-31 10:06:59 +02005306 dev_kfree_skb(wl->dummy_packet);
Ido Yariv1f37cbc2010-09-30 13:28:27 +02005307 free_pages((unsigned long)wl->aggr_buf,
5308 get_order(WL1271_AGGR_BUFFER_SIZE));
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005309
5310 wl1271_debugfs_exit(wl);
5311
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005312 vfree(wl->fw);
5313 wl->fw = NULL;
Eliad Peller3fcdab72012-02-06 12:47:54 +02005314 wl->fw_type = WL12XX_FW_TYPE_NONE;
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005315 kfree(wl->nvs);
5316 wl->nvs = NULL;
5317
5318 kfree(wl->fw_status);
5319 kfree(wl->tx_res_if);
Eliad Peller92ef8962011-06-07 12:50:46 +03005320 destroy_workqueue(wl->freezable_wq);
Teemu Paasikivic332a4b2010-02-18 13:25:57 +02005321
5322 ieee80211_free_hw(wl->hw);
5323
5324 return 0;
5325}
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005326
Felipe Balbia390e852011-10-06 10:07:44 +03005327static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5328{
5329 struct wl1271 *wl = cookie;
5330 unsigned long flags;
5331
5332 wl1271_debug(DEBUG_IRQ, "IRQ");
5333
5334 /* complete the ELP completion */
5335 spin_lock_irqsave(&wl->wl_lock, flags);
5336 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5337 if (wl->elp_compl) {
5338 complete(wl->elp_compl);
5339 wl->elp_compl = NULL;
5340 }
5341
5342 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5343 /* don't enqueue a work right now. mark it as pending */
5344 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5345 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5346 disable_irq_nosync(wl->irq);
5347 pm_wakeup_event(wl->dev, 0);
5348 spin_unlock_irqrestore(&wl->wl_lock, flags);
5349 return IRQ_HANDLED;
5350 }
5351 spin_unlock_irqrestore(&wl->wl_lock, flags);
5352
5353 return IRQ_WAKE_THREAD;
5354}
5355
Felipe Balbice2a2172011-10-05 14:12:55 +03005356static int __devinit wl12xx_probe(struct platform_device *pdev)
5357{
Felipe Balbia390e852011-10-06 10:07:44 +03005358 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5359 struct ieee80211_hw *hw;
5360 struct wl1271 *wl;
5361 unsigned long irqflags;
5362 int ret = -ENODEV;
5363
5364 hw = wl1271_alloc_hw();
5365 if (IS_ERR(hw)) {
5366 wl1271_error("can't allocate hw");
5367 ret = PTR_ERR(hw);
5368 goto out;
5369 }
5370
5371 wl = hw->priv;
5372 wl->irq = platform_get_irq(pdev, 0);
5373 wl->ref_clock = pdata->board_ref_clock;
5374 wl->tcxo_clock = pdata->board_tcxo_clock;
5375 wl->platform_quirks = pdata->platform_quirks;
5376 wl->set_power = pdata->set_power;
5377 wl->dev = &pdev->dev;
5378 wl->if_ops = pdata->ops;
5379
5380 platform_set_drvdata(pdev, wl);
5381
5382 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5383 irqflags = IRQF_TRIGGER_RISING;
5384 else
5385 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5386
5387 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5388 irqflags,
5389 pdev->name, wl);
5390 if (ret < 0) {
5391 wl1271_error("request_irq() failed: %d", ret);
5392 goto out_free_hw;
5393 }
5394
5395 ret = enable_irq_wake(wl->irq);
5396 if (!ret) {
5397 wl->irq_wake_enabled = true;
5398 device_init_wakeup(wl->dev, 1);
5399 if (pdata->pwr_in_suspend)
5400 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5401
5402 }
5403 disable_irq(wl->irq);
5404
5405 ret = wl1271_init_ieee80211(wl);
5406 if (ret)
5407 goto out_irq;
5408
5409 ret = wl1271_register_hw(wl);
5410 if (ret)
5411 goto out_irq;
5412
Felipe Balbif79f8902011-10-06 13:05:25 +03005413 /* Create sysfs file to control bt coex state */
5414 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5415 if (ret < 0) {
5416 wl1271_error("failed to create sysfs file bt_coex_state");
5417 goto out_irq;
5418 }
5419
5420 /* Create sysfs file to get HW PG version */
5421 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5422 if (ret < 0) {
5423 wl1271_error("failed to create sysfs file hw_pg_ver");
5424 goto out_bt_coex_state;
5425 }
5426
5427 /* Create sysfs file for the FW log */
5428 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5429 if (ret < 0) {
5430 wl1271_error("failed to create sysfs file fwlog");
5431 goto out_hw_pg_ver;
5432 }
5433
Felipe Balbice2a2172011-10-05 14:12:55 +03005434 return 0;
Felipe Balbia390e852011-10-06 10:07:44 +03005435
Felipe Balbif79f8902011-10-06 13:05:25 +03005436out_hw_pg_ver:
5437 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5438
5439out_bt_coex_state:
5440 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5441
Felipe Balbia390e852011-10-06 10:07:44 +03005442out_irq:
5443 free_irq(wl->irq, wl);
5444
5445out_free_hw:
5446 wl1271_free_hw(wl);
5447
5448out:
5449 return ret;
Felipe Balbice2a2172011-10-05 14:12:55 +03005450}
5451
5452static int __devexit wl12xx_remove(struct platform_device *pdev)
5453{
Felipe Balbia390e852011-10-06 10:07:44 +03005454 struct wl1271 *wl = platform_get_drvdata(pdev);
5455
5456 if (wl->irq_wake_enabled) {
5457 device_init_wakeup(wl->dev, 0);
5458 disable_irq_wake(wl->irq);
5459 }
5460 wl1271_unregister_hw(wl);
5461 free_irq(wl->irq, wl);
5462 wl1271_free_hw(wl);
5463
Felipe Balbice2a2172011-10-05 14:12:55 +03005464 return 0;
5465}
5466
5467static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005468 { "wl12xx", 0 },
Felipe Balbice2a2172011-10-05 14:12:55 +03005469 { } /* Terminating Entry */
5470};
5471MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5472
5473static struct platform_driver wl12xx_driver = {
5474 .probe = wl12xx_probe,
5475 .remove = __devexit_p(wl12xx_remove),
5476 .id_table = wl12xx_id_table,
5477 .driver = {
Luciano Coelhoccb62002011-10-07 15:54:15 +03005478 .name = "wl12xx_driver",
Felipe Balbice2a2172011-10-05 14:12:55 +03005479 .owner = THIS_MODULE,
5480 }
5481};
5482
5483static int __init wl12xx_init(void)
5484{
5485 return platform_driver_register(&wl12xx_driver);
5486}
5487module_init(wl12xx_init);
5488
5489static void __exit wl12xx_exit(void)
5490{
5491 platform_driver_unregister(&wl12xx_driver);
5492}
5493module_exit(wl12xx_exit);
5494
Guy Eilam491bbd62011-01-12 10:33:29 +01005495u32 wl12xx_debug_level = DEBUG_NONE;
Eliad Peller17c17552010-12-12 12:15:35 +02005496EXPORT_SYMBOL_GPL(wl12xx_debug_level);
Guy Eilam491bbd62011-01-12 10:33:29 +01005497module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
Eliad Peller17c17552010-12-12 12:15:35 +02005498MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5499
Ido Yariv95dac04f2011-06-06 14:57:06 +03005500module_param_named(fwlog, fwlog_param, charp, 0);
Luciano Coelho2c882fa2012-02-07 12:37:33 +02005501MODULE_PARM_DESC(fwlog,
Ido Yariv95dac04f2011-06-06 14:57:06 +03005502 "FW logger options: continuous, ondemand, dbgpins or disable");
5503
Eliad Peller2a5bff02011-08-25 18:10:59 +03005504module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5505MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5506
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005507MODULE_LICENSE("GPL");
Luciano Coelhob1a48ca2011-02-22 14:19:28 +02005508MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
Teemu Paasikivi50b3eb42010-02-22 08:38:26 +02005509MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");