blob: 626b0d184729b302351dbabd7dffe2d283c33d12 [file] [log] [blame]
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guyfb4961d2012-01-06 13:16:33 -08005 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
Wey-Yi Guy8d801082010-03-17 13:34:36 -070029#include <linux/etherdevice.h>
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/sched.h>
34
Don Fry69a679b2011-12-07 08:50:46 -080035#include "iwl-wifi.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070036#include "iwl-dev.h"
37#include "iwl-core.h"
38#include "iwl-io.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070039#include "iwl-agn-hw.h"
40#include "iwl-agn.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070041#include "iwl-trans.h"
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070042#include "iwl-shared.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070043
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070044int iwlagn_hw_valid_rtc_data_addr(u32 addr)
45{
46 return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
47 (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
48}
49
50int iwlagn_send_tx_power(struct iwl_priv *priv)
51{
Wey-Yi Guyab63c682010-09-20 09:12:31 -070052 struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070053 u8 tx_ant_cfg_cmd;
54
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -070055 if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->shrd->status),
Stanislaw Gruszka4beeba72010-10-25 10:34:50 +020056 "TX Power requested while scanning!\n"))
57 return -EAGAIN;
58
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070059 /* half dBm need to multiply */
60 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
61
62 if (priv->tx_power_lmt_in_half_dbm &&
63 priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
64 /*
65 * For the newer devices which using enhanced/extend tx power
66 * table in EEPROM, the format is in half dBm. driver need to
67 * convert to dBm format before report to mac80211.
68 * By doing so, there is a possibility of 1/2 dBm resolution
69 * lost. driver will perform "round-up" operation before
70 * reporting, but it will cause 1/2 dBm tx power over the
71 * regulatory limit. Perform the checking here, if the
72 * "tx_power_user_lmt" is higher than EEPROM value (in
73 * half-dBm format), lower the tx power based on EEPROM
74 */
75 tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
76 }
Wey-Yi Guyab63c682010-09-20 09:12:31 -070077 tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
78 tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070079
Don Fryd3596672012-02-06 15:51:15 -080080 if (IWL_UCODE_API(nic(priv)->fw.ucode_ver) == 1)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070081 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
82 else
83 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
84
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -070085 return iwl_trans_send_cmd_pdu(trans(priv), tx_ant_cfg_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070086 sizeof(tx_power_cmd), &tx_power_cmd);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070087}
88
89void iwlagn_temperature(struct iwl_priv *priv)
90{
Johannes Berg4ff70fc2012-03-05 11:24:26 -080091 lockdep_assert_held(&priv->statistics.lock);
92
Fry, Donald Hf8f79a52011-02-25 09:44:48 -080093 /* store temperature from correct statistics (in Celsius) */
Johannes Berg0da0e5b2011-04-08 08:14:56 -070094 priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070095 iwl_tt_handler(priv);
96}
97
Don Fryab36eab2011-11-30 15:37:32 -080098u16 iwl_eeprom_calib_version(struct iwl_shared *shrd)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070099{
Wey-Yi Guy7d8f2d52011-09-15 11:46:51 -0700100 struct iwl_eeprom_calib_hdr *hdr;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700101
Don Fryab36eab2011-11-30 15:37:32 -0800102 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(shrd,
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700103 EEPROM_CALIB_ALL);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700104 return hdr->version;
105
106}
107
108/*
109 * EEPROM
110 */
Don Fryab36eab2011-11-30 15:37:32 -0800111static u32 eeprom_indirect_address(const struct iwl_shared *shrd, u32 address)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700112{
113 u16 offset = 0;
114
115 if ((address & INDIRECT_ADDRESS) == 0)
116 return address;
117
118 switch (address & INDIRECT_TYPE_MSK) {
119 case INDIRECT_HOST:
Don Fryab36eab2011-11-30 15:37:32 -0800120 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_HOST);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700121 break;
122 case INDIRECT_GENERAL:
Don Fryab36eab2011-11-30 15:37:32 -0800123 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_GENERAL);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700124 break;
125 case INDIRECT_REGULATORY:
Don Fryab36eab2011-11-30 15:37:32 -0800126 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_REGULATORY);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700127 break;
Johannes Berg8d6748c2010-12-09 09:30:14 -0800128 case INDIRECT_TXP_LIMIT:
Don Fryab36eab2011-11-30 15:37:32 -0800129 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_TXP_LIMIT);
Johannes Berg8d6748c2010-12-09 09:30:14 -0800130 break;
131 case INDIRECT_TXP_LIMIT_SIZE:
Don Fryab36eab2011-11-30 15:37:32 -0800132 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_TXP_LIMIT_SIZE);
Johannes Berg8d6748c2010-12-09 09:30:14 -0800133 break;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700134 case INDIRECT_CALIBRATION:
Don Fryab36eab2011-11-30 15:37:32 -0800135 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_CALIBRATION);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700136 break;
137 case INDIRECT_PROCESS_ADJST:
Don Fryab36eab2011-11-30 15:37:32 -0800138 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_PROCESS_ADJST);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700139 break;
140 case INDIRECT_OTHERS:
Don Fryab36eab2011-11-30 15:37:32 -0800141 offset = iwl_eeprom_query16(shrd, EEPROM_LINK_OTHERS);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700142 break;
143 default:
Don Fryab36eab2011-11-30 15:37:32 -0800144 IWL_ERR(shrd->trans, "illegal indirect type: 0x%X\n",
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700145 address & INDIRECT_TYPE_MSK);
146 break;
147 }
148
149 /* translate the offset from words to byte */
150 return (address & ADDRESS_MSK) + (offset << 1);
151}
152
Don Fryab36eab2011-11-30 15:37:32 -0800153const u8 *iwl_eeprom_query_addr(const struct iwl_shared *shrd, size_t offset)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700154{
Don Fryab36eab2011-11-30 15:37:32 -0800155 u32 address = eeprom_indirect_address(shrd, offset);
Don Fry38622412011-12-16 07:07:36 -0800156 BUG_ON(address >= shrd->cfg->base_params->eeprom_size);
Don Fryab36eab2011-11-30 15:37:32 -0800157 return &shrd->eeprom[address];
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700158}
Wey-Yi Guy348ee7cd2010-03-16 12:37:27 -0700159
160struct iwl_mod_params iwlagn_mod_params = {
161 .amsdu_size_8K = 1,
162 .restart_fw = 1,
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100163 .plcp_check = true,
Wey-Yi Guyb60eec92011-06-03 13:52:38 -0700164 .bt_coex_active = true,
Wey-Yi Guy3f1e5f42011-06-03 13:52:40 -0700165 .no_sleep_autoadjust = true,
Wey-Yi Guyf7538162011-06-11 10:00:06 -0700166 .power_level = IWL_POWER_INDEX_1,
Wey-Yi Guyfee84f0d2011-08-25 23:10:57 -0700167 .bt_ch_announce = true,
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700168 .wanted_ucode_alternative = 1,
Wey-Yi Guydd5b6d02011-08-25 23:10:55 -0700169 .auto_agg = true,
Wey-Yi Guy348ee7cd2010-03-16 12:37:27 -0700170 /* the rest are 0 by default */
171};
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700172
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700173int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
174{
175 int idx = 0;
176 int band_offset = 0;
177
178 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
179 if (rate_n_flags & RATE_MCS_HT_MSK) {
180 idx = (rate_n_flags & 0xff);
181 return idx;
182 /* Legacy rate format, search for match in table */
183 } else {
184 if (band == IEEE80211_BAND_5GHZ)
185 band_offset = IWL_FIRST_OFDM_RATE;
186 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
187 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
188 return idx - band_offset;
189 }
190
191 return -1;
192}
193
Johannes Berg1fa61b22010-04-28 08:44:52 -0700194int iwlagn_manage_ibss_station(struct iwl_priv *priv,
195 struct ieee80211_vif *vif, bool add)
196{
Johannes Bergfd1af152010-04-30 11:30:43 -0700197 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
198
Johannes Berg1fa61b22010-04-28 08:44:52 -0700199 if (add)
Johannes Berga30e3112010-09-22 18:02:01 +0200200 return iwlagn_add_bssid_station(priv, vif_priv->ctx,
201 vif->bss_conf.bssid,
202 &vif_priv->ibss_bssid_sta_id);
Johannes Bergfd1af152010-04-30 11:30:43 -0700203 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
204 vif->bss_conf.bssid);
Johannes Berg1fa61b22010-04-28 08:44:52 -0700205}
Johannes Berg1ff504e2010-05-03 01:22:42 -0700206
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700207/**
208 * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
209 *
210 * pre-requirements:
211 * 1. acquire mutex before calling
212 * 2. make sure rf is on and not in exit state
213 */
214int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
215{
216 struct iwl_txfifo_flush_cmd flush_cmd;
217 struct iwl_host_cmd cmd = {
218 .id = REPLY_TXFIFO_FLUSH,
Johannes Berg3fa50732011-05-04 07:50:38 -0700219 .len = { sizeof(struct iwl_txfifo_flush_cmd), },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700220 .flags = CMD_SYNC,
Johannes Berg3fa50732011-05-04 07:50:38 -0700221 .data = { &flush_cmd, },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700222 };
223
224 might_sleep();
225
226 memset(&flush_cmd, 0, sizeof(flush_cmd));
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700227 if (flush_control & BIT(IWL_RXON_CTX_BSS))
228 flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700229 IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
230 IWL_SCD_MGMT_MSK;
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700231 if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
Emmanuel Grumbach7a10e3e42011-09-06 09:31:21 -0700232 (priv->shrd->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700233 flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
234 IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
235 IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
236 IWL_PAN_SCD_MULTICAST_MSK;
237
Johannes Berg54708d82012-03-05 11:24:31 -0800238 if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700239 flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
240
241 IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
242 flush_cmd.fifo_control);
243 flush_cmd.flush_control = cpu_to_le16(flush_control);
244
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700245 return iwl_trans_send_cmd(trans(priv), &cmd);
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700246}
Wey-Yi Guy65550632010-06-24 13:18:35 -0700247
248void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
249{
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700250 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700251 ieee80211_stop_queues(priv->hw);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -0700252 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
Wey-Yi Guy65550632010-06-24 13:18:35 -0700253 IWL_ERR(priv, "flush request fail\n");
254 goto done;
255 }
256 IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
Emmanuel Grumbach5f178cd2011-08-25 23:11:29 -0700257 iwl_trans_wait_tx_queue_empty(trans(priv));
Wey-Yi Guy65550632010-06-24 13:18:35 -0700258done:
259 ieee80211_wake_queues(priv->hw);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700260 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700261}
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700262
263/*
264 * BT coex
265 */
266/*
267 * Macros to access the lookup table.
268 *
269 * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
270* wifi_prio, wifi_txrx and wifi_sh_ant_req.
271 *
272 * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
273 *
274 * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
275 * one after another in 32-bit registers, and "registers" 0 through 7 contain
276 * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
277 *
278 * These macros encode that format.
279 */
280#define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
281 wifi_txrx, wifi_sh_ant_req) \
282 (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
283 (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
284
285#define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
286 lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
287#define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
288 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
289 (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
290 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
291 wifi_sh_ant_req))))
292#define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
293 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
294 LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
295 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
296 wifi_sh_ant_req))
297#define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
298 wifi_req, wifi_prio, wifi_txrx, \
299 wifi_sh_ant_req) \
300 LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
301 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
302 wifi_sh_ant_req))
303
304#define LUT_WLAN_KILL_OP(lut, op, val) \
305 lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
306#define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
307 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
308 (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
309 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
310#define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
311 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
312 LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
313 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
314#define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
315 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
316 LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
317 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
318
319#define LUT_ANT_SWITCH_OP(lut, op, val) \
320 lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
321#define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
322 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
323 (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
324 wifi_req, wifi_prio, wifi_txrx, \
325 wifi_sh_ant_req))))
326#define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
327 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
328 LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
329 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
330#define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
331 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
332 LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
333 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
334
335static const __le32 iwlagn_def_3w_lookup[12] = {
336 cpu_to_le32(0xaaaaaaaa),
337 cpu_to_le32(0xaaaaaaaa),
338 cpu_to_le32(0xaeaaaaaa),
339 cpu_to_le32(0xaaaaaaaa),
340 cpu_to_le32(0xcc00ff28),
341 cpu_to_le32(0x0000aaaa),
342 cpu_to_le32(0xcc00aaaa),
343 cpu_to_le32(0x0000aaaa),
344 cpu_to_le32(0xc0004000),
345 cpu_to_le32(0x00004000),
346 cpu_to_le32(0xf0005000),
Wey-Yi Guy9a67d762010-11-18 10:40:03 -0800347 cpu_to_le32(0xf0005000),
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700348};
349
350static const __le32 iwlagn_concurrent_lookup[12] = {
351 cpu_to_le32(0xaaaaaaaa),
352 cpu_to_le32(0xaaaaaaaa),
353 cpu_to_le32(0xaaaaaaaa),
354 cpu_to_le32(0xaaaaaaaa),
355 cpu_to_le32(0xaaaaaaaa),
356 cpu_to_le32(0xaaaaaaaa),
357 cpu_to_le32(0xaaaaaaaa),
358 cpu_to_le32(0xaaaaaaaa),
359 cpu_to_le32(0x00000000),
360 cpu_to_le32(0x00000000),
361 cpu_to_le32(0x00000000),
362 cpu_to_le32(0x00000000),
363};
364
365void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
366{
Wey-Yi Guy60132702011-02-18 17:23:54 -0800367 struct iwl_basic_bt_cmd basic = {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700368 .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
369 .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
370 .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
371 .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
372 };
Wey-Yi Guy60132702011-02-18 17:23:54 -0800373 struct iwl6000_bt_cmd bt_cmd_6000;
374 struct iwl2000_bt_cmd bt_cmd_2000;
375 int ret;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700376
377 BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
Wey-Yi Guy60132702011-02-18 17:23:54 -0800378 sizeof(basic.bt3_lookup_table));
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700379
Don Fry38622412011-12-16 07:07:36 -0800380 if (cfg(priv)->bt_params) {
381 if (cfg(priv)->bt_params->bt_session_2) {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800382 bt_cmd_2000.prio_boost = cpu_to_le32(
Don Fry38622412011-12-16 07:07:36 -0800383 cfg(priv)->bt_params->bt_prio_boost);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800384 bt_cmd_2000.tx_prio_boost = 0;
385 bt_cmd_2000.rx_prio_boost = 0;
386 } else {
387 bt_cmd_6000.prio_boost =
Don Fry38622412011-12-16 07:07:36 -0800388 cfg(priv)->bt_params->bt_prio_boost;
Wey-Yi Guy60132702011-02-18 17:23:54 -0800389 bt_cmd_6000.tx_prio_boost = 0;
390 bt_cmd_6000.rx_prio_boost = 0;
391 }
392 } else {
393 IWL_ERR(priv, "failed to construct BT Coex Config\n");
394 return;
395 }
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800396
Wey-Yi Guy60132702011-02-18 17:23:54 -0800397 basic.kill_ack_mask = priv->kill_ack_mask;
398 basic.kill_cts_mask = priv->kill_cts_mask;
399 basic.valid = priv->bt_valid;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700400
401 /*
402 * Configure BT coex mode to "no coexistence" when the
403 * user disabled BT coexistence, we have no interface
404 * (might be in monitor mode), or the interface is in
405 * IBSS mode (no proper uCode support for coex then).
406 */
Wey-Yi Guyb60eec92011-06-03 13:52:38 -0700407 if (!iwlagn_mod_params.bt_coex_active ||
408 priv->iw_mode == NL80211_IFTYPE_ADHOC) {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800409 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700410 } else {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800411 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700412 IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700413
414 if (!priv->bt_enable_pspoll)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800415 basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700416 else
417 basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Wey-Yi Guye3661762010-11-23 10:58:54 -0800418
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700419 if (priv->bt_ch_announce)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800420 basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700421 IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700422 }
Wey-Yi Guy60132702011-02-18 17:23:54 -0800423 priv->bt_enable_flag = basic.flags;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700424 if (priv->bt_full_concurrent)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800425 memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700426 sizeof(iwlagn_concurrent_lookup));
427 else
Wey-Yi Guy60132702011-02-18 17:23:54 -0800428 memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700429 sizeof(iwlagn_def_3w_lookup));
430
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700431 IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
Wey-Yi Guy60132702011-02-18 17:23:54 -0800432 basic.flags ? "active" : "disabled",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700433 priv->bt_full_concurrent ?
434 "full concurrency" : "3-wire");
435
Don Fry38622412011-12-16 07:07:36 -0800436 if (cfg(priv)->bt_params->bt_session_2) {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800437 memcpy(&bt_cmd_2000.basic, &basic,
438 sizeof(basic));
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700439 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700440 CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800441 } else {
442 memcpy(&bt_cmd_6000.basic, &basic,
443 sizeof(basic));
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700444 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700445 CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800446 }
447 if (ret)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700448 IWL_ERR(priv, "failed to send BT Coex Config\n");
449
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700450}
451
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700452void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
453{
454 struct iwl_rxon_context *ctx, *found_ctx = NULL;
455 bool found_ap = false;
456
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700457 lockdep_assert_held(&priv->shrd->mutex);
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700458
459 /* Check whether AP or GO mode is active. */
460 if (rssi_ena) {
461 for_each_context(priv, ctx) {
462 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
463 iwl_is_associated_ctx(ctx)) {
464 found_ap = true;
465 break;
466 }
467 }
468 }
469
470 /*
471 * If disable was received or If GO/AP mode, disable RSSI
472 * measurements.
473 */
474 if (!rssi_ena || found_ap) {
475 if (priv->cur_rssi_ctx) {
476 ctx = priv->cur_rssi_ctx;
477 ieee80211_disable_rssi_reports(ctx->vif);
478 priv->cur_rssi_ctx = NULL;
479 }
480 return;
481 }
482
483 /*
484 * If rssi measurements need to be enabled, consider all cases now.
485 * Figure out how many contexts are active.
486 */
487 for_each_context(priv, ctx) {
488 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
489 iwl_is_associated_ctx(ctx)) {
490 found_ctx = ctx;
491 break;
492 }
493 }
494
495 /*
496 * rssi monitor already enabled for the correct interface...nothing
497 * to do.
498 */
499 if (found_ctx == priv->cur_rssi_ctx)
500 return;
501
502 /*
503 * Figure out if rssi monitor is currently enabled, and needs
504 * to be changed. If rssi monitor is already enabled, disable
505 * it first else just enable rssi measurements on the
506 * interface found above.
507 */
508 if (priv->cur_rssi_ctx) {
509 ctx = priv->cur_rssi_ctx;
510 if (ctx->vif)
511 ieee80211_disable_rssi_reports(ctx->vif);
512 }
513
514 priv->cur_rssi_ctx = found_ctx;
515
516 if (!found_ctx)
517 return;
518
519 ieee80211_enable_rssi_reports(found_ctx->vif,
520 IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
521 IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
522}
523
524static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
525{
526 return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
527 BT_UART_MSG_FRAME3SCOESCO_POS;
528}
529
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700530static void iwlagn_bt_traffic_change_work(struct work_struct *work)
531{
532 struct iwl_priv *priv =
533 container_of(work, struct iwl_priv, bt_traffic_change_work);
Johannes Berg8bd413e2010-08-23 10:46:40 +0200534 struct iwl_rxon_context *ctx;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700535 int smps_request = -1;
536
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800537 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
538 /* bt coex disabled */
539 return;
540 }
541
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200542 /*
543 * Note: bt_traffic_load can be overridden by scan complete and
544 * coex profile notifications. Ignore that since only bad consequence
545 * can be not matching debug print with actual state.
546 */
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700547 IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700548 priv->bt_traffic_load);
549
550 switch (priv->bt_traffic_load) {
551 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
Wey-Yi Guyf5682c02010-10-23 09:15:44 -0700552 if (priv->bt_status)
553 smps_request = IEEE80211_SMPS_DYNAMIC;
554 else
555 smps_request = IEEE80211_SMPS_AUTOMATIC;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700556 break;
557 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
558 smps_request = IEEE80211_SMPS_DYNAMIC;
559 break;
560 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
561 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
562 smps_request = IEEE80211_SMPS_STATIC;
563 break;
564 default:
565 IWL_ERR(priv, "Invalid BT traffic load: %d\n",
566 priv->bt_traffic_load);
567 break;
568 }
569
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700570 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700571
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200572 /*
573 * We can not send command to firmware while scanning. When the scan
574 * complete we will schedule this work again. We do check with mutex
575 * locked to prevent new scan request to arrive. We do not check
576 * STATUS_SCANNING to avoid race when queue_work two times from
577 * different notifications, but quit and not perform any work at all.
578 */
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700579 if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200580 goto out;
581
Fry, Donald H6b6db912011-07-08 08:46:17 -0700582 iwl_update_chain_flags(priv);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700583
Johannes Berg8bd413e2010-08-23 10:46:40 +0200584 if (smps_request != -1) {
Wey-Yi Guy88e9ba72011-06-03 07:54:12 -0700585 priv->current_ht_config.smps = smps_request;
Johannes Berg8bd413e2010-08-23 10:46:40 +0200586 for_each_context(priv, ctx) {
587 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
588 ieee80211_request_smps(ctx->vif, smps_request);
589 }
590 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700591
592 /*
593 * Dynamic PS poll related functionality. Adjust RSSI measurements if
594 * necessary.
595 */
596 iwlagn_bt_coex_rssi_monitor(priv);
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200597out:
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700598 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700599}
600
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700601/*
602 * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
603 * correct interface or disable it if this is the last interface to be
604 * removed.
605 */
606void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
607{
608 if (priv->bt_is_sco &&
609 priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
610 iwlagn_bt_adjust_rssi_monitor(priv, true);
611 else
612 iwlagn_bt_adjust_rssi_monitor(priv, false);
613}
614
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700615static void iwlagn_print_uartmsg(struct iwl_priv *priv,
616 struct iwl_bt_uart_msg *uart_msg)
617{
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700618 IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700619 "Update Req = 0x%X",
620 (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
621 BT_UART_MSG_FRAME1MSGTYPE_POS,
622 (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
623 BT_UART_MSG_FRAME1SSN_POS,
624 (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
625 BT_UART_MSG_FRAME1UPDATEREQ_POS);
626
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700627 IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700628 "Chl_SeqN = 0x%X, In band = 0x%X",
629 (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
630 BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
631 (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
632 BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
633 (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
634 BT_UART_MSG_FRAME2CHLSEQN_POS,
635 (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
636 BT_UART_MSG_FRAME2INBAND_POS);
637
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700638 IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700639 "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
640 (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
641 BT_UART_MSG_FRAME3SCOESCO_POS,
642 (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
643 BT_UART_MSG_FRAME3SNIFF_POS,
644 (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
645 BT_UART_MSG_FRAME3A2DP_POS,
646 (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
647 BT_UART_MSG_FRAME3ACL_POS,
648 (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
649 BT_UART_MSG_FRAME3MASTER_POS,
650 (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
651 BT_UART_MSG_FRAME3OBEX_POS);
652
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700653 IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700654 (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
655 BT_UART_MSG_FRAME4IDLEDURATION_POS);
656
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700657 IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700658 "eSCO Retransmissions = 0x%X",
659 (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
660 BT_UART_MSG_FRAME5TXACTIVITY_POS,
661 (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
662 BT_UART_MSG_FRAME5RXACTIVITY_POS,
663 (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
664 BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
665
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700666 IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700667 (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
668 BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
669 (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
670 BT_UART_MSG_FRAME6DISCOVERABLE_POS);
671
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700672 IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
Wey-Yi Guy399f66f2011-02-22 08:24:22 -0800673 "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700674 (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
675 BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
Wey-Yi Guy399f66f2011-02-22 08:24:22 -0800676 (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
677 BT_UART_MSG_FRAME7PAGE_POS,
678 (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
679 BT_UART_MSG_FRAME7INQUIRY_POS,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700680 (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
681 BT_UART_MSG_FRAME7CONNECTABLE_POS);
682}
683
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800684static void iwlagn_set_kill_msk(struct iwl_priv *priv,
685 struct iwl_bt_uart_msg *uart_msg)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700686{
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800687 u8 kill_msk;
Joe Perches20407ed2010-11-20 18:38:57 -0800688 static const __le32 bt_kill_ack_msg[2] = {
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800689 IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
690 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
691 static const __le32 bt_kill_cts_msg[2] = {
692 IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
693 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700694
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800695 kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
696 ? 1 : 0;
697 if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
698 priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700699 priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800700 priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
701 priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
702 priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
703
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700704 /* schedule to send runtime bt_config */
Johannes Berg1ee158d2012-02-17 10:07:44 -0800705 queue_work(priv->workqueue, &priv->bt_runtime_config);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700706 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700707}
708
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700709int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
710 struct iwl_rx_mem_buffer *rxb,
711 struct iwl_device_cmd *cmd)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700712{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700713 struct iwl_rx_packet *pkt = rxb_addr(rxb);
714 struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700715 struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700716
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800717 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
718 /* bt coex disabled */
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700719 return 0;
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800720 }
721
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700722 IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
723 IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
724 IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
725 IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700726 coex->bt_ci_compliance);
727 iwlagn_print_uartmsg(priv, uart_msg);
728
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800729 priv->last_bt_traffic_load = priv->bt_traffic_load;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700730 priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
731
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700732 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
733 if (priv->bt_status != coex->bt_status ||
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800734 priv->last_bt_traffic_load != coex->bt_traffic_load) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700735 if (coex->bt_status) {
736 /* BT on */
737 if (!priv->bt_ch_announce)
738 priv->bt_traffic_load =
739 IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
740 else
741 priv->bt_traffic_load =
742 coex->bt_traffic_load;
743 } else {
744 /* BT off */
745 priv->bt_traffic_load =
746 IWL_BT_COEX_TRAFFIC_LOAD_NONE;
747 }
748 priv->bt_status = coex->bt_status;
Johannes Berg1ee158d2012-02-17 10:07:44 -0800749 queue_work(priv->workqueue,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700750 &priv->bt_traffic_change_work);
751 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700752 }
753
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800754 iwlagn_set_kill_msk(priv, uart_msg);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700755
756 /* FIXME: based on notification, adjust the prio_boost */
757
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700758 priv->bt_ci_compliance = coex->bt_ci_compliance;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700759 return 0;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700760}
761
762void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
763{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700764 priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
765 iwlagn_bt_coex_profile_notif;
766}
767
768void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
769{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700770 INIT_WORK(&priv->bt_traffic_change_work,
771 iwlagn_bt_traffic_change_work);
772}
773
774void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
775{
776 cancel_work_sync(&priv->bt_traffic_change_work);
777}
Johannes Berg5de33062010-09-22 18:01:58 +0200778
779static bool is_single_rx_stream(struct iwl_priv *priv)
780{
781 return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
782 priv->current_ht_config.single_chain_sufficient;
783}
784
785#define IWL_NUM_RX_CHAINS_MULTIPLE 3
786#define IWL_NUM_RX_CHAINS_SINGLE 2
787#define IWL_NUM_IDLE_CHAINS_DUAL 2
788#define IWL_NUM_IDLE_CHAINS_SINGLE 1
789
790/*
791 * Determine how many receiver/antenna chains to use.
792 *
793 * More provides better reception via diversity. Fewer saves power
794 * at the expense of throughput, but only when not in powersave to
795 * start with.
796 *
797 * MIMO (dual stream) requires at least 2, but works better with 3.
798 * This does not determine *which* chains to use, just how many.
799 */
800static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
801{
Don Fry38622412011-12-16 07:07:36 -0800802 if (cfg(priv)->bt_params &&
803 cfg(priv)->bt_params->advanced_bt_coexist &&
Johannes Berg5de33062010-09-22 18:01:58 +0200804 (priv->bt_full_concurrent ||
805 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
806 /*
807 * only use chain 'A' in bt high traffic load or
808 * full concurrency mode
809 */
810 return IWL_NUM_RX_CHAINS_SINGLE;
811 }
812 /* # of Rx chains to use when expecting MIMO. */
813 if (is_single_rx_stream(priv))
814 return IWL_NUM_RX_CHAINS_SINGLE;
815 else
816 return IWL_NUM_RX_CHAINS_MULTIPLE;
817}
818
819/*
820 * When we are in power saving mode, unless device support spatial
821 * multiplexing power save, use the active count for rx chain count.
822 */
823static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
824{
825 /* # Rx chains when idling, depending on SMPS mode */
826 switch (priv->current_ht_config.smps) {
827 case IEEE80211_SMPS_STATIC:
828 case IEEE80211_SMPS_DYNAMIC:
829 return IWL_NUM_IDLE_CHAINS_SINGLE;
Wey-Yi Guyb2ccccd2011-11-10 06:55:04 -0800830 case IEEE80211_SMPS_AUTOMATIC:
Johannes Berg5de33062010-09-22 18:01:58 +0200831 case IEEE80211_SMPS_OFF:
832 return active_cnt;
833 default:
834 WARN(1, "invalid SMPS mode %d",
835 priv->current_ht_config.smps);
836 return active_cnt;
837 }
838}
839
840/* up to 4 chains */
841static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
842{
843 u8 res;
844 res = (chain_bitmap & BIT(0)) >> 0;
845 res += (chain_bitmap & BIT(1)) >> 1;
846 res += (chain_bitmap & BIT(2)) >> 2;
847 res += (chain_bitmap & BIT(3)) >> 3;
848 return res;
849}
850
851/**
852 * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
853 *
854 * Selects how many and which Rx receivers/antennas/chains to use.
855 * This should not be used for scan command ... it puts data in wrong place.
856 */
857void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
858{
859 bool is_single = is_single_rx_stream(priv);
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700860 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
Johannes Berg5de33062010-09-22 18:01:58 +0200861 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
862 u32 active_chains;
863 u16 rx_chain;
864
865 /* Tell uCode which antennas are actually connected.
866 * Before first association, we assume all antennas are connected.
867 * Just after first association, iwl_chain_noise_calibration()
868 * checks which antennas actually *are* connected. */
869 if (priv->chain_noise_data.active_chains)
870 active_chains = priv->chain_noise_data.active_chains;
871 else
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700872 active_chains = hw_params(priv).valid_rx_ant;
Johannes Berg5de33062010-09-22 18:01:58 +0200873
Don Fry38622412011-12-16 07:07:36 -0800874 if (cfg(priv)->bt_params &&
875 cfg(priv)->bt_params->advanced_bt_coexist &&
Johannes Berg5de33062010-09-22 18:01:58 +0200876 (priv->bt_full_concurrent ||
877 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
878 /*
879 * only use chain 'A' in bt high traffic load or
880 * full concurrency mode
881 */
882 active_chains = first_antenna(active_chains);
883 }
884
885 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
886
887 /* How many receivers should we use? */
888 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
889 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
890
891
892 /* correct rx chain count according hw settings
893 * and chain noise calibration
894 */
895 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
896 if (valid_rx_cnt < active_rx_cnt)
897 active_rx_cnt = valid_rx_cnt;
898
899 if (valid_rx_cnt < idle_rx_cnt)
900 idle_rx_cnt = valid_rx_cnt;
901
902 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
903 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
904
905 ctx->staging.rx_chain = cpu_to_le16(rx_chain);
906
907 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
908 ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
909 else
910 ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
911
912 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
913 ctx->staging.rx_chain,
914 active_rx_cnt, idle_rx_cnt);
915
916 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
917 active_rx_cnt < idle_rx_cnt);
918}
Johannes Bergfacd9822010-09-22 18:02:05 +0200919
920u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
921{
922 int i;
923 u8 ind = ant;
924
925 if (priv->band == IEEE80211_BAND_2GHZ &&
926 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
927 return 0;
928
929 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
930 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
931 if (valid & BIT(ind))
932 return ind;
933 }
934 return ant;
935}
Johannes Bergfed73292010-09-22 18:02:06 +0200936
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800937#ifdef CONFIG_PM_SLEEP
938static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
939{
940 int i;
941
942 for (i = 0; i < IWLAGN_P1K_SIZE; i++)
943 out[i] = cpu_to_le16(p1k[i]);
944}
945
946struct wowlan_key_data {
947 struct iwl_rxon_context *ctx;
948 struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc;
949 struct iwlagn_wowlan_tkip_params_cmd *tkip;
950 const u8 *bssid;
951 bool error, use_rsc_tsc, use_tkip;
952};
953
954
955static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw,
956 struct ieee80211_vif *vif,
957 struct ieee80211_sta *sta,
958 struct ieee80211_key_conf *key,
959 void *_data)
960{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200961 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800962 struct wowlan_key_data *data = _data;
963 struct iwl_rxon_context *ctx = data->ctx;
964 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
965 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
966 struct iwlagn_p1k_cache *rx_p1ks;
967 u8 *rx_mic_key;
968 struct ieee80211_key_seq seq;
969 u32 cur_rx_iv32 = 0;
970 u16 p1k[IWLAGN_P1K_SIZE];
971 int ret, i;
972
973 mutex_lock(&priv->shrd->mutex);
974
975 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
976 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
977 !sta && !ctx->key_mapping_keys)
978 ret = iwl_set_default_wep_key(priv, ctx, key);
979 else
980 ret = iwl_set_dynamic_key(priv, ctx, key, sta);
981
982 if (ret) {
983 IWL_ERR(priv, "Error setting key during suspend!\n");
984 data->error = true;
985 }
986
987 switch (key->cipher) {
988 case WLAN_CIPHER_SUITE_TKIP:
989 if (sta) {
990 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
991 tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
992
993 rx_p1ks = data->tkip->rx_uni;
994
995 ieee80211_get_key_tx_seq(key, &seq);
996 tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
997 tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
998
999 ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
1000 iwlagn_convert_p1k(p1k, data->tkip->tx.p1k);
1001
1002 memcpy(data->tkip->mic_keys.tx,
1003 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
1004 IWLAGN_MIC_KEY_SIZE);
1005
1006 rx_mic_key = data->tkip->mic_keys.rx_unicast;
1007 } else {
1008 tkip_sc =
1009 data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
1010 rx_p1ks = data->tkip->rx_multi;
1011 rx_mic_key = data->tkip->mic_keys.rx_mcast;
1012 }
1013
1014 /*
1015 * For non-QoS this relies on the fact that both the uCode and
1016 * mac80211 use TID 0 (as they need to to avoid replay attacks)
1017 * for checking the IV in the frames.
1018 */
1019 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
1020 ieee80211_get_key_rx_seq(key, i, &seq);
1021 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
1022 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
1023 /* wrapping isn't allowed, AP must rekey */
1024 if (seq.tkip.iv32 > cur_rx_iv32)
1025 cur_rx_iv32 = seq.tkip.iv32;
1026 }
1027
1028 ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k);
1029 iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k);
1030 ieee80211_get_tkip_rx_p1k(key, data->bssid,
1031 cur_rx_iv32 + 1, p1k);
1032 iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k);
1033
1034 memcpy(rx_mic_key,
1035 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
1036 IWLAGN_MIC_KEY_SIZE);
1037
1038 data->use_tkip = true;
1039 data->use_rsc_tsc = true;
1040 break;
1041 case WLAN_CIPHER_SUITE_CCMP:
1042 if (sta) {
1043 u8 *pn = seq.ccmp.pn;
1044
1045 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
1046 aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
1047
1048 ieee80211_get_key_tx_seq(key, &seq);
1049 aes_tx_sc->pn = cpu_to_le64(
1050 (u64)pn[5] |
1051 ((u64)pn[4] << 8) |
1052 ((u64)pn[3] << 16) |
1053 ((u64)pn[2] << 24) |
1054 ((u64)pn[1] << 32) |
1055 ((u64)pn[0] << 40));
1056 } else
1057 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
1058
1059 /*
1060 * For non-QoS this relies on the fact that both the uCode and
1061 * mac80211 use TID 0 for checking the IV in the frames.
1062 */
1063 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
1064 u8 *pn = seq.ccmp.pn;
1065
1066 ieee80211_get_key_rx_seq(key, i, &seq);
1067 aes_sc->pn = cpu_to_le64(
1068 (u64)pn[5] |
1069 ((u64)pn[4] << 8) |
1070 ((u64)pn[3] << 16) |
1071 ((u64)pn[2] << 24) |
1072 ((u64)pn[1] << 32) |
1073 ((u64)pn[0] << 40));
1074 }
1075 data->use_rsc_tsc = true;
1076 break;
1077 }
1078
1079 mutex_unlock(&priv->shrd->mutex);
1080}
1081
1082int iwlagn_send_patterns(struct iwl_priv *priv,
1083 struct cfg80211_wowlan *wowlan)
1084{
1085 struct iwlagn_wowlan_patterns_cmd *pattern_cmd;
1086 struct iwl_host_cmd cmd = {
1087 .id = REPLY_WOWLAN_PATTERNS,
1088 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1089 .flags = CMD_SYNC,
1090 };
1091 int i, err;
1092
1093 if (!wowlan->n_patterns)
1094 return 0;
1095
1096 cmd.len[0] = sizeof(*pattern_cmd) +
1097 wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
1098
1099 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
1100 if (!pattern_cmd)
1101 return -ENOMEM;
1102
1103 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
1104
1105 for (i = 0; i < wowlan->n_patterns; i++) {
1106 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
1107
1108 memcpy(&pattern_cmd->patterns[i].mask,
1109 wowlan->patterns[i].mask, mask_len);
1110 memcpy(&pattern_cmd->patterns[i].pattern,
1111 wowlan->patterns[i].pattern,
1112 wowlan->patterns[i].pattern_len);
1113 pattern_cmd->patterns[i].mask_size = mask_len;
1114 pattern_cmd->patterns[i].pattern_size =
1115 wowlan->patterns[i].pattern_len;
1116 }
1117
1118 cmd.data[0] = pattern_cmd;
1119 err = iwl_trans_send_cmd(trans(priv), &cmd);
1120 kfree(pattern_cmd);
1121 return err;
1122}
1123
1124int iwlagn_suspend(struct iwl_priv *priv,
1125 struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1126{
1127 struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd;
1128 struct iwl_rxon_cmd rxon;
1129 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1130 struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd;
1131 struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {};
1132 struct iwlagn_d3_config_cmd d3_cfg_cmd = {};
1133 struct wowlan_key_data key_data = {
1134 .ctx = ctx,
1135 .bssid = ctx->active.bssid_addr,
1136 .use_rsc_tsc = false,
1137 .tkip = &tkip_cmd,
1138 .use_tkip = false,
1139 };
1140 int ret, i;
1141 u16 seq;
1142
1143 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
1144 if (!key_data.rsc_tsc)
1145 return -ENOMEM;
1146
1147 memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd));
1148
1149 /*
1150 * We know the last used seqno, and the uCode expects to know that
1151 * one, it will increment before TX.
1152 */
1153 seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ;
1154 wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq);
1155
1156 /*
1157 * For QoS counters, we store the one to use next, so subtract 0x10
1158 * since the uCode will add 0x10 before using the value.
1159 */
Johannes Berge0467a32011-12-02 12:24:45 -08001160 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02001161 seq = priv->tid_data[IWL_AP_ID][i].seq_number;
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001162 seq -= 0x10;
1163 wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq);
1164 }
1165
1166 if (wowlan->disconnect)
1167 wakeup_filter_cmd.enabled |=
1168 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
1169 IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE);
1170 if (wowlan->magic_pkt)
1171 wakeup_filter_cmd.enabled |=
1172 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET);
1173 if (wowlan->gtk_rekey_failure)
1174 wakeup_filter_cmd.enabled |=
1175 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
1176 if (wowlan->eap_identity_req)
1177 wakeup_filter_cmd.enabled |=
1178 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ);
1179 if (wowlan->four_way_handshake)
1180 wakeup_filter_cmd.enabled |=
1181 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
1182 if (wowlan->n_patterns)
1183 wakeup_filter_cmd.enabled |=
1184 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH);
1185
1186 if (wowlan->rfkill_release)
1187 d3_cfg_cmd.wakeup_flags |=
1188 cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL);
1189
1190 iwl_scan_cancel_timeout(priv, 200);
1191
1192 memcpy(&rxon, &ctx->active, sizeof(rxon));
1193
1194 iwl_trans_stop_device(trans(priv));
1195
Johannes Berg15b86bf2012-03-05 11:24:36 -08001196 priv->wowlan = true;
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001197
Don Fry69a679b2011-12-07 08:50:46 -08001198 ret = iwl_load_ucode_wait_alive(trans(priv), IWL_UCODE_WOWLAN);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001199 if (ret)
1200 goto out;
1201
1202 /* now configure WoWLAN ucode */
1203 ret = iwl_alive_start(priv);
1204 if (ret)
1205 goto out;
1206
1207 memcpy(&ctx->staging, &rxon, sizeof(rxon));
1208 ret = iwlagn_commit_rxon(priv, ctx);
1209 if (ret)
1210 goto out;
1211
1212 ret = iwl_power_update_mode(priv, true);
1213 if (ret)
1214 goto out;
1215
1216 if (!iwlagn_mod_params.sw_crypto) {
1217 /* mark all keys clear */
1218 priv->ucode_key_table = 0;
1219 ctx->key_mapping_keys = 0;
1220
1221 /*
1222 * This needs to be unlocked due to lock ordering
1223 * constraints. Since we're in the suspend path
1224 * that isn't really a problem though.
1225 */
1226 mutex_unlock(&priv->shrd->mutex);
1227 ieee80211_iter_keys(priv->hw, ctx->vif,
1228 iwlagn_wowlan_program_keys,
1229 &key_data);
1230 mutex_lock(&priv->shrd->mutex);
1231 if (key_data.error) {
1232 ret = -EIO;
1233 goto out;
1234 }
1235
1236 if (key_data.use_rsc_tsc) {
1237 struct iwl_host_cmd rsc_tsc_cmd = {
1238 .id = REPLY_WOWLAN_TSC_RSC_PARAMS,
1239 .flags = CMD_SYNC,
1240 .data[0] = key_data.rsc_tsc,
1241 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1242 .len[0] = sizeof(key_data.rsc_tsc),
1243 };
1244
1245 ret = iwl_trans_send_cmd(trans(priv), &rsc_tsc_cmd);
1246 if (ret)
1247 goto out;
1248 }
1249
1250 if (key_data.use_tkip) {
1251 ret = iwl_trans_send_cmd_pdu(trans(priv),
1252 REPLY_WOWLAN_TKIP_PARAMS,
1253 CMD_SYNC, sizeof(tkip_cmd),
1254 &tkip_cmd);
1255 if (ret)
1256 goto out;
1257 }
1258
1259 if (priv->have_rekey_data) {
1260 memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
1261 memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN);
1262 kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
1263 memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN);
1264 kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
1265 kek_kck_cmd.replay_ctr = priv->replay_ctr;
1266
1267 ret = iwl_trans_send_cmd_pdu(trans(priv),
1268 REPLY_WOWLAN_KEK_KCK_MATERIAL,
1269 CMD_SYNC, sizeof(kek_kck_cmd),
1270 &kek_kck_cmd);
1271 if (ret)
1272 goto out;
1273 }
1274 }
1275
1276 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_D3_CONFIG, CMD_SYNC,
1277 sizeof(d3_cfg_cmd), &d3_cfg_cmd);
1278 if (ret)
1279 goto out;
1280
1281 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_WOWLAN_WAKEUP_FILTER,
1282 CMD_SYNC, sizeof(wakeup_filter_cmd),
1283 &wakeup_filter_cmd);
1284 if (ret)
1285 goto out;
1286
1287 ret = iwlagn_send_patterns(priv, wowlan);
1288 out:
1289 kfree(key_data.rsc_tsc);
1290 return ret;
1291}
1292#endif