blob: e1c2bb802050777c34cd870e0d0e7e4349cacf13 [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
35#include "iwl-dev.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070036#include "iwl-io.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070037#include "iwl-agn-hw.h"
38#include "iwl-agn.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070039#include "iwl-trans.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070040#include "iwl-modparams.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070041
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070042int iwlagn_hw_valid_rtc_data_addr(u32 addr)
43{
44 return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
45 (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
46}
47
48int iwlagn_send_tx_power(struct iwl_priv *priv)
49{
Wey-Yi Guyab63c682010-09-20 09:12:31 -070050 struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070051 u8 tx_ant_cfg_cmd;
52
Don Fry83626402012-03-07 09:52:37 -080053 if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->status),
Stanislaw Gruszka4beeba72010-10-25 10:34:50 +020054 "TX Power requested while scanning!\n"))
55 return -EAGAIN;
56
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070057 /* half dBm need to multiply */
58 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
59
60 if (priv->tx_power_lmt_in_half_dbm &&
61 priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
62 /*
63 * For the newer devices which using enhanced/extend tx power
64 * table in EEPROM, the format is in half dBm. driver need to
65 * convert to dBm format before report to mac80211.
66 * By doing so, there is a possibility of 1/2 dBm resolution
67 * lost. driver will perform "round-up" operation before
68 * reporting, but it will cause 1/2 dBm tx power over the
69 * regulatory limit. Perform the checking here, if the
70 * "tx_power_user_lmt" is higher than EEPROM value (in
71 * half-dBm format), lower the tx power based on EEPROM
72 */
73 tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
74 }
Wey-Yi Guyab63c682010-09-20 09:12:31 -070075 tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
76 tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070077
Johannes Berg0692fe42012-03-06 13:30:37 -080078 if (IWL_UCODE_API(priv->fw->ucode_ver) == 1)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070079 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
80 else
81 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
82
Johannes Berge10a0532012-03-06 13:30:39 -080083 return iwl_dvm_send_cmd_pdu(priv, tx_ant_cfg_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070084 sizeof(tx_power_cmd), &tx_power_cmd);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070085}
86
87void iwlagn_temperature(struct iwl_priv *priv)
88{
Johannes Berg4ff70fc2012-03-05 11:24:26 -080089 lockdep_assert_held(&priv->statistics.lock);
90
Fry, Donald Hf8f79a52011-02-25 09:44:48 -080091 /* store temperature from correct statistics (in Celsius) */
Johannes Berg0da0e5b2011-04-08 08:14:56 -070092 priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070093 iwl_tt_handler(priv);
94}
95
Wey-Yi Guy8d801082010-03-17 13:34:36 -070096int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
97{
98 int idx = 0;
99 int band_offset = 0;
100
101 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
102 if (rate_n_flags & RATE_MCS_HT_MSK) {
103 idx = (rate_n_flags & 0xff);
104 return idx;
105 /* Legacy rate format, search for match in table */
106 } else {
107 if (band == IEEE80211_BAND_5GHZ)
108 band_offset = IWL_FIRST_OFDM_RATE;
109 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
110 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
111 return idx - band_offset;
112 }
113
114 return -1;
115}
116
Johannes Berg1fa61b22010-04-28 08:44:52 -0700117int iwlagn_manage_ibss_station(struct iwl_priv *priv,
118 struct ieee80211_vif *vif, bool add)
119{
Johannes Bergfd1af152010-04-30 11:30:43 -0700120 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
121
Johannes Berg1fa61b22010-04-28 08:44:52 -0700122 if (add)
Johannes Berga30e3112010-09-22 18:02:01 +0200123 return iwlagn_add_bssid_station(priv, vif_priv->ctx,
124 vif->bss_conf.bssid,
125 &vif_priv->ibss_bssid_sta_id);
Johannes Bergfd1af152010-04-30 11:30:43 -0700126 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
127 vif->bss_conf.bssid);
Johannes Berg1fa61b22010-04-28 08:44:52 -0700128}
Johannes Berg1ff504e2010-05-03 01:22:42 -0700129
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700130/**
131 * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
132 *
133 * pre-requirements:
134 * 1. acquire mutex before calling
135 * 2. make sure rf is on and not in exit state
136 */
137int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
138{
139 struct iwl_txfifo_flush_cmd flush_cmd;
140 struct iwl_host_cmd cmd = {
141 .id = REPLY_TXFIFO_FLUSH,
Johannes Berg3fa50732011-05-04 07:50:38 -0700142 .len = { sizeof(struct iwl_txfifo_flush_cmd), },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700143 .flags = CMD_SYNC,
Johannes Berg3fa50732011-05-04 07:50:38 -0700144 .data = { &flush_cmd, },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700145 };
146
147 might_sleep();
148
149 memset(&flush_cmd, 0, sizeof(flush_cmd));
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700150 if (flush_control & BIT(IWL_RXON_CTX_BSS))
151 flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700152 IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
153 IWL_SCD_MGMT_MSK;
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700154 if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
Johannes Berga18f61b2012-03-15 13:26:53 -0700155 (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700156 flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
157 IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
158 IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
159 IWL_PAN_SCD_MULTICAST_MSK;
160
Johannes Berg9e295112012-04-09 17:46:55 -0700161 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700162 flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
163
164 IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
165 flush_cmd.fifo_control);
166 flush_cmd.flush_control = cpu_to_le16(flush_control);
167
Johannes Berge10a0532012-03-06 13:30:39 -0800168 return iwl_dvm_send_cmd(priv, &cmd);
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700169}
Wey-Yi Guy65550632010-06-24 13:18:35 -0700170
171void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
172{
Johannes Bergb1eea292012-03-06 13:30:42 -0800173 mutex_lock(&priv->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700174 ieee80211_stop_queues(priv->hw);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -0700175 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
Wey-Yi Guy65550632010-06-24 13:18:35 -0700176 IWL_ERR(priv, "flush request fail\n");
177 goto done;
178 }
179 IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700180 iwl_trans_wait_tx_queue_empty(priv->trans);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700181done:
182 ieee80211_wake_queues(priv->hw);
Johannes Bergb1eea292012-03-06 13:30:42 -0800183 mutex_unlock(&priv->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700184}
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700185
186/*
187 * BT coex
188 */
189/*
190 * Macros to access the lookup table.
191 *
192 * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
193* wifi_prio, wifi_txrx and wifi_sh_ant_req.
194 *
195 * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
196 *
197 * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
198 * one after another in 32-bit registers, and "registers" 0 through 7 contain
199 * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
200 *
201 * These macros encode that format.
202 */
203#define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
204 wifi_txrx, wifi_sh_ant_req) \
205 (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
206 (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
207
208#define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
209 lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
210#define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
211 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
212 (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
213 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
214 wifi_sh_ant_req))))
215#define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
216 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
217 LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
218 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
219 wifi_sh_ant_req))
220#define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
221 wifi_req, wifi_prio, wifi_txrx, \
222 wifi_sh_ant_req) \
223 LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
224 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
225 wifi_sh_ant_req))
226
227#define LUT_WLAN_KILL_OP(lut, op, val) \
228 lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
229#define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
230 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
231 (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
232 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
233#define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
234 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
235 LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
236 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
237#define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
238 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
239 LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
240 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
241
242#define LUT_ANT_SWITCH_OP(lut, op, val) \
243 lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
244#define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
245 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
246 (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
247 wifi_req, wifi_prio, wifi_txrx, \
248 wifi_sh_ant_req))))
249#define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
250 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
251 LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
252 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
253#define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
254 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
255 LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
256 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
257
258static const __le32 iwlagn_def_3w_lookup[12] = {
259 cpu_to_le32(0xaaaaaaaa),
260 cpu_to_le32(0xaaaaaaaa),
261 cpu_to_le32(0xaeaaaaaa),
262 cpu_to_le32(0xaaaaaaaa),
263 cpu_to_le32(0xcc00ff28),
264 cpu_to_le32(0x0000aaaa),
265 cpu_to_le32(0xcc00aaaa),
266 cpu_to_le32(0x0000aaaa),
267 cpu_to_le32(0xc0004000),
268 cpu_to_le32(0x00004000),
269 cpu_to_le32(0xf0005000),
Wey-Yi Guy9a67d762010-11-18 10:40:03 -0800270 cpu_to_le32(0xf0005000),
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700271};
272
273static const __le32 iwlagn_concurrent_lookup[12] = {
274 cpu_to_le32(0xaaaaaaaa),
275 cpu_to_le32(0xaaaaaaaa),
276 cpu_to_le32(0xaaaaaaaa),
277 cpu_to_le32(0xaaaaaaaa),
278 cpu_to_le32(0xaaaaaaaa),
279 cpu_to_le32(0xaaaaaaaa),
280 cpu_to_le32(0xaaaaaaaa),
281 cpu_to_le32(0xaaaaaaaa),
282 cpu_to_le32(0x00000000),
283 cpu_to_le32(0x00000000),
284 cpu_to_le32(0x00000000),
285 cpu_to_le32(0x00000000),
286};
287
288void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
289{
Wey-Yi Guy60132702011-02-18 17:23:54 -0800290 struct iwl_basic_bt_cmd basic = {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700291 .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
292 .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
293 .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
294 .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
295 };
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800296 struct iwl_bt_cmd_v1 bt_cmd_v1;
297 struct iwl_bt_cmd_v2 bt_cmd_v2;
Wey-Yi Guy60132702011-02-18 17:23:54 -0800298 int ret;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700299
300 BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
Wey-Yi Guy60132702011-02-18 17:23:54 -0800301 sizeof(basic.bt3_lookup_table));
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700302
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200303 if (priv->cfg->bt_params) {
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800304 /*
305 * newer generation of devices (2000 series and newer)
306 * use the version 2 of the bt command
307 * we need to make sure sending the host command
308 * with correct data structure to avoid uCode assert
309 */
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200310 if (priv->cfg->bt_params->bt_session_2) {
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800311 bt_cmd_v2.prio_boost = cpu_to_le32(
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200312 priv->cfg->bt_params->bt_prio_boost);
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800313 bt_cmd_v2.tx_prio_boost = 0;
314 bt_cmd_v2.rx_prio_boost = 0;
Wey-Yi Guy60132702011-02-18 17:23:54 -0800315 } else {
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800316 bt_cmd_v1.prio_boost =
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200317 priv->cfg->bt_params->bt_prio_boost;
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800318 bt_cmd_v1.tx_prio_boost = 0;
319 bt_cmd_v1.rx_prio_boost = 0;
Wey-Yi Guy60132702011-02-18 17:23:54 -0800320 }
321 } else {
322 IWL_ERR(priv, "failed to construct BT Coex Config\n");
323 return;
324 }
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800325
Wey-Yi Guy60132702011-02-18 17:23:54 -0800326 basic.kill_ack_mask = priv->kill_ack_mask;
327 basic.kill_cts_mask = priv->kill_cts_mask;
328 basic.valid = priv->bt_valid;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700329
330 /*
331 * Configure BT coex mode to "no coexistence" when the
332 * user disabled BT coexistence, we have no interface
333 * (might be in monitor mode), or the interface is in
334 * IBSS mode (no proper uCode support for coex then).
335 */
Johannes Berg65de7e82012-04-17 07:36:30 -0700336 if (!iwlwifi_mod_params.bt_coex_active ||
Wey-Yi Guyb60eec92011-06-03 13:52:38 -0700337 priv->iw_mode == NL80211_IFTYPE_ADHOC) {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800338 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700339 } else {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800340 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700341 IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700342
343 if (!priv->bt_enable_pspoll)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800344 basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700345 else
346 basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Wey-Yi Guye3661762010-11-23 10:58:54 -0800347
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700348 if (priv->bt_ch_announce)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800349 basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700350 IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700351 }
Wey-Yi Guy60132702011-02-18 17:23:54 -0800352 priv->bt_enable_flag = basic.flags;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700353 if (priv->bt_full_concurrent)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800354 memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700355 sizeof(iwlagn_concurrent_lookup));
356 else
Wey-Yi Guy60132702011-02-18 17:23:54 -0800357 memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700358 sizeof(iwlagn_def_3w_lookup));
359
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700360 IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
Wey-Yi Guy60132702011-02-18 17:23:54 -0800361 basic.flags ? "active" : "disabled",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700362 priv->bt_full_concurrent ?
363 "full concurrency" : "3-wire");
364
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200365 if (priv->cfg->bt_params->bt_session_2) {
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800366 memcpy(&bt_cmd_v2.basic, &basic,
Wey-Yi Guy60132702011-02-18 17:23:54 -0800367 sizeof(basic));
Johannes Berge10a0532012-03-06 13:30:39 -0800368 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800369 CMD_SYNC, sizeof(bt_cmd_v2), &bt_cmd_v2);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800370 } else {
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800371 memcpy(&bt_cmd_v1.basic, &basic,
Wey-Yi Guy60132702011-02-18 17:23:54 -0800372 sizeof(basic));
Johannes Berge10a0532012-03-06 13:30:39 -0800373 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Wey-Yi Guy8347deb2012-03-09 07:15:04 -0800374 CMD_SYNC, sizeof(bt_cmd_v1), &bt_cmd_v1);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800375 }
376 if (ret)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700377 IWL_ERR(priv, "failed to send BT Coex Config\n");
378
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700379}
380
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700381void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
382{
383 struct iwl_rxon_context *ctx, *found_ctx = NULL;
384 bool found_ap = false;
385
Johannes Bergb1eea292012-03-06 13:30:42 -0800386 lockdep_assert_held(&priv->mutex);
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700387
388 /* Check whether AP or GO mode is active. */
389 if (rssi_ena) {
390 for_each_context(priv, ctx) {
391 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
392 iwl_is_associated_ctx(ctx)) {
393 found_ap = true;
394 break;
395 }
396 }
397 }
398
399 /*
400 * If disable was received or If GO/AP mode, disable RSSI
401 * measurements.
402 */
403 if (!rssi_ena || found_ap) {
404 if (priv->cur_rssi_ctx) {
405 ctx = priv->cur_rssi_ctx;
406 ieee80211_disable_rssi_reports(ctx->vif);
407 priv->cur_rssi_ctx = NULL;
408 }
409 return;
410 }
411
412 /*
413 * If rssi measurements need to be enabled, consider all cases now.
414 * Figure out how many contexts are active.
415 */
416 for_each_context(priv, ctx) {
417 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
418 iwl_is_associated_ctx(ctx)) {
419 found_ctx = ctx;
420 break;
421 }
422 }
423
424 /*
425 * rssi monitor already enabled for the correct interface...nothing
426 * to do.
427 */
428 if (found_ctx == priv->cur_rssi_ctx)
429 return;
430
431 /*
432 * Figure out if rssi monitor is currently enabled, and needs
433 * to be changed. If rssi monitor is already enabled, disable
434 * it first else just enable rssi measurements on the
435 * interface found above.
436 */
437 if (priv->cur_rssi_ctx) {
438 ctx = priv->cur_rssi_ctx;
439 if (ctx->vif)
440 ieee80211_disable_rssi_reports(ctx->vif);
441 }
442
443 priv->cur_rssi_ctx = found_ctx;
444
445 if (!found_ctx)
446 return;
447
448 ieee80211_enable_rssi_reports(found_ctx->vif,
449 IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
450 IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
451}
452
453static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
454{
455 return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
456 BT_UART_MSG_FRAME3SCOESCO_POS;
457}
458
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700459static void iwlagn_bt_traffic_change_work(struct work_struct *work)
460{
461 struct iwl_priv *priv =
462 container_of(work, struct iwl_priv, bt_traffic_change_work);
Johannes Berg8bd413e2010-08-23 10:46:40 +0200463 struct iwl_rxon_context *ctx;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700464 int smps_request = -1;
465
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800466 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
467 /* bt coex disabled */
468 return;
469 }
470
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200471 /*
472 * Note: bt_traffic_load can be overridden by scan complete and
473 * coex profile notifications. Ignore that since only bad consequence
474 * can be not matching debug print with actual state.
475 */
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700476 IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700477 priv->bt_traffic_load);
478
479 switch (priv->bt_traffic_load) {
480 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
Wey-Yi Guyf5682c02010-10-23 09:15:44 -0700481 if (priv->bt_status)
482 smps_request = IEEE80211_SMPS_DYNAMIC;
483 else
484 smps_request = IEEE80211_SMPS_AUTOMATIC;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700485 break;
486 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
487 smps_request = IEEE80211_SMPS_DYNAMIC;
488 break;
489 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
490 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
491 smps_request = IEEE80211_SMPS_STATIC;
492 break;
493 default:
494 IWL_ERR(priv, "Invalid BT traffic load: %d\n",
495 priv->bt_traffic_load);
496 break;
497 }
498
Johannes Bergb1eea292012-03-06 13:30:42 -0800499 mutex_lock(&priv->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700500
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200501 /*
502 * We can not send command to firmware while scanning. When the scan
503 * complete we will schedule this work again. We do check with mutex
504 * locked to prevent new scan request to arrive. We do not check
505 * STATUS_SCANNING to avoid race when queue_work two times from
506 * different notifications, but quit and not perform any work at all.
507 */
Don Fry83626402012-03-07 09:52:37 -0800508 if (test_bit(STATUS_SCAN_HW, &priv->status))
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200509 goto out;
510
Fry, Donald H6b6db912011-07-08 08:46:17 -0700511 iwl_update_chain_flags(priv);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700512
Johannes Berg8bd413e2010-08-23 10:46:40 +0200513 if (smps_request != -1) {
Wey-Yi Guy88e9ba72011-06-03 07:54:12 -0700514 priv->current_ht_config.smps = smps_request;
Johannes Berg8bd413e2010-08-23 10:46:40 +0200515 for_each_context(priv, ctx) {
516 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
517 ieee80211_request_smps(ctx->vif, smps_request);
518 }
519 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700520
521 /*
522 * Dynamic PS poll related functionality. Adjust RSSI measurements if
523 * necessary.
524 */
525 iwlagn_bt_coex_rssi_monitor(priv);
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200526out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800527 mutex_unlock(&priv->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700528}
529
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700530/*
531 * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
532 * correct interface or disable it if this is the last interface to be
533 * removed.
534 */
535void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
536{
537 if (priv->bt_is_sco &&
538 priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
539 iwlagn_bt_adjust_rssi_monitor(priv, true);
540 else
541 iwlagn_bt_adjust_rssi_monitor(priv, false);
542}
543
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700544static void iwlagn_print_uartmsg(struct iwl_priv *priv,
545 struct iwl_bt_uart_msg *uart_msg)
546{
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700547 IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
Johannes Berg0ca24da2012-03-15 13:26:46 -0700548 "Update Req = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700549 (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
550 BT_UART_MSG_FRAME1MSGTYPE_POS,
551 (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
552 BT_UART_MSG_FRAME1SSN_POS,
553 (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
554 BT_UART_MSG_FRAME1UPDATEREQ_POS);
555
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700556 IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
Johannes Berg0ca24da2012-03-15 13:26:46 -0700557 "Chl_SeqN = 0x%X, In band = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700558 (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
559 BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
560 (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
561 BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
562 (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
563 BT_UART_MSG_FRAME2CHLSEQN_POS,
564 (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
565 BT_UART_MSG_FRAME2INBAND_POS);
566
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700567 IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
Johannes Berg0ca24da2012-03-15 13:26:46 -0700568 "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700569 (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
570 BT_UART_MSG_FRAME3SCOESCO_POS,
571 (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
572 BT_UART_MSG_FRAME3SNIFF_POS,
573 (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
574 BT_UART_MSG_FRAME3A2DP_POS,
575 (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
576 BT_UART_MSG_FRAME3ACL_POS,
577 (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
578 BT_UART_MSG_FRAME3MASTER_POS,
579 (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
580 BT_UART_MSG_FRAME3OBEX_POS);
581
Johannes Berg0ca24da2012-03-15 13:26:46 -0700582 IWL_DEBUG_COEX(priv, "Idle duration = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700583 (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
584 BT_UART_MSG_FRAME4IDLEDURATION_POS);
585
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700586 IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
Johannes Berg0ca24da2012-03-15 13:26:46 -0700587 "eSCO Retransmissions = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700588 (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
589 BT_UART_MSG_FRAME5TXACTIVITY_POS,
590 (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
591 BT_UART_MSG_FRAME5RXACTIVITY_POS,
592 (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
593 BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
594
Johannes Berg0ca24da2012-03-15 13:26:46 -0700595 IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700596 (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
597 BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
598 (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
599 BT_UART_MSG_FRAME6DISCOVERABLE_POS);
600
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700601 IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
Johannes Berg0ca24da2012-03-15 13:26:46 -0700602 "0x%X, Inquiry = 0x%X, Connectable = 0x%X\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700603 (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
604 BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
Wey-Yi Guy399f66f2011-02-22 08:24:22 -0800605 (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
606 BT_UART_MSG_FRAME7PAGE_POS,
607 (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
608 BT_UART_MSG_FRAME7INQUIRY_POS,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700609 (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
610 BT_UART_MSG_FRAME7CONNECTABLE_POS);
611}
612
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800613static void iwlagn_set_kill_msk(struct iwl_priv *priv,
614 struct iwl_bt_uart_msg *uart_msg)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700615{
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800616 u8 kill_msk;
Joe Perches20407ed2010-11-20 18:38:57 -0800617 static const __le32 bt_kill_ack_msg[2] = {
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800618 IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
619 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
620 static const __le32 bt_kill_cts_msg[2] = {
621 IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
622 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700623
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800624 kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
625 ? 1 : 0;
626 if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
627 priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700628 priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800629 priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
630 priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
631 priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
632
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700633 /* schedule to send runtime bt_config */
Johannes Berg1ee158d2012-02-17 10:07:44 -0800634 queue_work(priv->workqueue, &priv->bt_runtime_config);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700635 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700636}
637
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700638int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800639 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700640 struct iwl_device_cmd *cmd)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700641{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700642 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800643 struct iwl_bt_coex_profile_notif *coex = (void *)pkt->data;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700644 struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700645
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800646 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
647 /* bt coex disabled */
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700648 return 0;
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800649 }
650
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700651 IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
652 IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
653 IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
654 IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700655 coex->bt_ci_compliance);
656 iwlagn_print_uartmsg(priv, uart_msg);
657
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800658 priv->last_bt_traffic_load = priv->bt_traffic_load;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700659 priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
660
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700661 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
662 if (priv->bt_status != coex->bt_status ||
Wey-Yi Guy66e863a52010-11-08 14:54:37 -0800663 priv->last_bt_traffic_load != coex->bt_traffic_load) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700664 if (coex->bt_status) {
665 /* BT on */
666 if (!priv->bt_ch_announce)
667 priv->bt_traffic_load =
668 IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
669 else
670 priv->bt_traffic_load =
671 coex->bt_traffic_load;
672 } else {
673 /* BT off */
674 priv->bt_traffic_load =
675 IWL_BT_COEX_TRAFFIC_LOAD_NONE;
676 }
677 priv->bt_status = coex->bt_status;
Johannes Berg1ee158d2012-02-17 10:07:44 -0800678 queue_work(priv->workqueue,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700679 &priv->bt_traffic_change_work);
680 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700681 }
682
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800683 iwlagn_set_kill_msk(priv, uart_msg);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700684
685 /* FIXME: based on notification, adjust the prio_boost */
686
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700687 priv->bt_ci_compliance = coex->bt_ci_compliance;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700688 return 0;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700689}
690
691void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
692{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700693 priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
694 iwlagn_bt_coex_profile_notif;
695}
696
697void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
698{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700699 INIT_WORK(&priv->bt_traffic_change_work,
700 iwlagn_bt_traffic_change_work);
701}
702
703void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
704{
705 cancel_work_sync(&priv->bt_traffic_change_work);
706}
Johannes Berg5de33062010-09-22 18:01:58 +0200707
708static bool is_single_rx_stream(struct iwl_priv *priv)
709{
710 return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
711 priv->current_ht_config.single_chain_sufficient;
712}
713
714#define IWL_NUM_RX_CHAINS_MULTIPLE 3
715#define IWL_NUM_RX_CHAINS_SINGLE 2
716#define IWL_NUM_IDLE_CHAINS_DUAL 2
717#define IWL_NUM_IDLE_CHAINS_SINGLE 1
718
719/*
720 * Determine how many receiver/antenna chains to use.
721 *
722 * More provides better reception via diversity. Fewer saves power
723 * at the expense of throughput, but only when not in powersave to
724 * start with.
725 *
726 * MIMO (dual stream) requires at least 2, but works better with 3.
727 * This does not determine *which* chains to use, just how many.
728 */
729static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
730{
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200731 if (priv->cfg->bt_params &&
732 priv->cfg->bt_params->advanced_bt_coexist &&
Johannes Berg5de33062010-09-22 18:01:58 +0200733 (priv->bt_full_concurrent ||
734 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
735 /*
736 * only use chain 'A' in bt high traffic load or
737 * full concurrency mode
738 */
739 return IWL_NUM_RX_CHAINS_SINGLE;
740 }
741 /* # of Rx chains to use when expecting MIMO. */
742 if (is_single_rx_stream(priv))
743 return IWL_NUM_RX_CHAINS_SINGLE;
744 else
745 return IWL_NUM_RX_CHAINS_MULTIPLE;
746}
747
748/*
749 * When we are in power saving mode, unless device support spatial
750 * multiplexing power save, use the active count for rx chain count.
751 */
752static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
753{
754 /* # Rx chains when idling, depending on SMPS mode */
755 switch (priv->current_ht_config.smps) {
756 case IEEE80211_SMPS_STATIC:
757 case IEEE80211_SMPS_DYNAMIC:
758 return IWL_NUM_IDLE_CHAINS_SINGLE;
Wey-Yi Guyb2ccccd2011-11-10 06:55:04 -0800759 case IEEE80211_SMPS_AUTOMATIC:
Johannes Berg5de33062010-09-22 18:01:58 +0200760 case IEEE80211_SMPS_OFF:
761 return active_cnt;
762 default:
763 WARN(1, "invalid SMPS mode %d",
764 priv->current_ht_config.smps);
765 return active_cnt;
766 }
767}
768
769/* up to 4 chains */
770static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
771{
772 u8 res;
773 res = (chain_bitmap & BIT(0)) >> 0;
774 res += (chain_bitmap & BIT(1)) >> 1;
775 res += (chain_bitmap & BIT(2)) >> 2;
776 res += (chain_bitmap & BIT(3)) >> 3;
777 return res;
778}
779
780/**
781 * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
782 *
783 * Selects how many and which Rx receivers/antennas/chains to use.
784 * This should not be used for scan command ... it puts data in wrong place.
785 */
786void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
787{
788 bool is_single = is_single_rx_stream(priv);
Don Fry47107e82012-03-15 13:27:06 -0700789 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
Johannes Berg5de33062010-09-22 18:01:58 +0200790 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
791 u32 active_chains;
792 u16 rx_chain;
793
794 /* Tell uCode which antennas are actually connected.
795 * Before first association, we assume all antennas are connected.
796 * Just after first association, iwl_chain_noise_calibration()
797 * checks which antennas actually *are* connected. */
798 if (priv->chain_noise_data.active_chains)
799 active_chains = priv->chain_noise_data.active_chains;
800 else
Johannes Berg9e295112012-04-09 17:46:55 -0700801 active_chains = priv->hw_params.valid_rx_ant;
Johannes Berg5de33062010-09-22 18:01:58 +0200802
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200803 if (priv->cfg->bt_params &&
804 priv->cfg->bt_params->advanced_bt_coexist &&
Johannes Berg5de33062010-09-22 18:01:58 +0200805 (priv->bt_full_concurrent ||
806 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
807 /*
808 * only use chain 'A' in bt high traffic load or
809 * full concurrency mode
810 */
811 active_chains = first_antenna(active_chains);
812 }
813
814 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
815
816 /* How many receivers should we use? */
817 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
818 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
819
820
821 /* correct rx chain count according hw settings
822 * and chain noise calibration
823 */
824 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
825 if (valid_rx_cnt < active_rx_cnt)
826 active_rx_cnt = valid_rx_cnt;
827
828 if (valid_rx_cnt < idle_rx_cnt)
829 idle_rx_cnt = valid_rx_cnt;
830
831 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
832 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
833
834 ctx->staging.rx_chain = cpu_to_le16(rx_chain);
835
836 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
837 ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
838 else
839 ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
840
841 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
842 ctx->staging.rx_chain,
843 active_rx_cnt, idle_rx_cnt);
844
845 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
846 active_rx_cnt < idle_rx_cnt);
847}
Johannes Bergfacd9822010-09-22 18:02:05 +0200848
849u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
850{
851 int i;
852 u8 ind = ant;
853
854 if (priv->band == IEEE80211_BAND_2GHZ &&
855 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
856 return 0;
857
858 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
859 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
860 if (valid & BIT(ind))
861 return ind;
862 }
863 return ant;
864}
Johannes Bergfed73292010-09-22 18:02:06 +0200865
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800866#ifdef CONFIG_PM_SLEEP
867static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
868{
869 int i;
870
871 for (i = 0; i < IWLAGN_P1K_SIZE; i++)
872 out[i] = cpu_to_le16(p1k[i]);
873}
874
875struct wowlan_key_data {
876 struct iwl_rxon_context *ctx;
877 struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc;
878 struct iwlagn_wowlan_tkip_params_cmd *tkip;
879 const u8 *bssid;
880 bool error, use_rsc_tsc, use_tkip;
881};
882
883
884static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw,
885 struct ieee80211_vif *vif,
886 struct ieee80211_sta *sta,
887 struct ieee80211_key_conf *key,
888 void *_data)
889{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +0200890 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800891 struct wowlan_key_data *data = _data;
892 struct iwl_rxon_context *ctx = data->ctx;
893 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
894 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
895 struct iwlagn_p1k_cache *rx_p1ks;
896 u8 *rx_mic_key;
897 struct ieee80211_key_seq seq;
898 u32 cur_rx_iv32 = 0;
899 u16 p1k[IWLAGN_P1K_SIZE];
900 int ret, i;
901
Johannes Bergb1eea292012-03-06 13:30:42 -0800902 mutex_lock(&priv->mutex);
Wey-Yi Guy023ca582011-11-10 06:55:17 -0800903
904 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
905 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
906 !sta && !ctx->key_mapping_keys)
907 ret = iwl_set_default_wep_key(priv, ctx, key);
908 else
909 ret = iwl_set_dynamic_key(priv, ctx, key, sta);
910
911 if (ret) {
912 IWL_ERR(priv, "Error setting key during suspend!\n");
913 data->error = true;
914 }
915
916 switch (key->cipher) {
917 case WLAN_CIPHER_SUITE_TKIP:
918 if (sta) {
919 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
920 tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
921
922 rx_p1ks = data->tkip->rx_uni;
923
924 ieee80211_get_key_tx_seq(key, &seq);
925 tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
926 tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
927
928 ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
929 iwlagn_convert_p1k(p1k, data->tkip->tx.p1k);
930
931 memcpy(data->tkip->mic_keys.tx,
932 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
933 IWLAGN_MIC_KEY_SIZE);
934
935 rx_mic_key = data->tkip->mic_keys.rx_unicast;
936 } else {
937 tkip_sc =
938 data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
939 rx_p1ks = data->tkip->rx_multi;
940 rx_mic_key = data->tkip->mic_keys.rx_mcast;
941 }
942
943 /*
944 * For non-QoS this relies on the fact that both the uCode and
945 * mac80211 use TID 0 (as they need to to avoid replay attacks)
946 * for checking the IV in the frames.
947 */
948 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
949 ieee80211_get_key_rx_seq(key, i, &seq);
950 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
951 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
952 /* wrapping isn't allowed, AP must rekey */
953 if (seq.tkip.iv32 > cur_rx_iv32)
954 cur_rx_iv32 = seq.tkip.iv32;
955 }
956
957 ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k);
958 iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k);
959 ieee80211_get_tkip_rx_p1k(key, data->bssid,
960 cur_rx_iv32 + 1, p1k);
961 iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k);
962
963 memcpy(rx_mic_key,
964 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
965 IWLAGN_MIC_KEY_SIZE);
966
967 data->use_tkip = true;
968 data->use_rsc_tsc = true;
969 break;
970 case WLAN_CIPHER_SUITE_CCMP:
971 if (sta) {
972 u8 *pn = seq.ccmp.pn;
973
974 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
975 aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
976
977 ieee80211_get_key_tx_seq(key, &seq);
978 aes_tx_sc->pn = cpu_to_le64(
979 (u64)pn[5] |
980 ((u64)pn[4] << 8) |
981 ((u64)pn[3] << 16) |
982 ((u64)pn[2] << 24) |
983 ((u64)pn[1] << 32) |
984 ((u64)pn[0] << 40));
985 } else
986 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
987
988 /*
989 * For non-QoS this relies on the fact that both the uCode and
990 * mac80211 use TID 0 for checking the IV in the frames.
991 */
992 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
993 u8 *pn = seq.ccmp.pn;
994
995 ieee80211_get_key_rx_seq(key, i, &seq);
996 aes_sc->pn = cpu_to_le64(
997 (u64)pn[5] |
998 ((u64)pn[4] << 8) |
999 ((u64)pn[3] << 16) |
1000 ((u64)pn[2] << 24) |
1001 ((u64)pn[1] << 32) |
1002 ((u64)pn[0] << 40));
1003 }
1004 data->use_rsc_tsc = true;
1005 break;
1006 }
1007
Johannes Bergb1eea292012-03-06 13:30:42 -08001008 mutex_unlock(&priv->mutex);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001009}
1010
1011int iwlagn_send_patterns(struct iwl_priv *priv,
1012 struct cfg80211_wowlan *wowlan)
1013{
1014 struct iwlagn_wowlan_patterns_cmd *pattern_cmd;
1015 struct iwl_host_cmd cmd = {
1016 .id = REPLY_WOWLAN_PATTERNS,
1017 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1018 .flags = CMD_SYNC,
1019 };
1020 int i, err;
1021
1022 if (!wowlan->n_patterns)
1023 return 0;
1024
1025 cmd.len[0] = sizeof(*pattern_cmd) +
1026 wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
1027
1028 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
1029 if (!pattern_cmd)
1030 return -ENOMEM;
1031
1032 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
1033
1034 for (i = 0; i < wowlan->n_patterns; i++) {
1035 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
1036
1037 memcpy(&pattern_cmd->patterns[i].mask,
1038 wowlan->patterns[i].mask, mask_len);
1039 memcpy(&pattern_cmd->patterns[i].pattern,
1040 wowlan->patterns[i].pattern,
1041 wowlan->patterns[i].pattern_len);
1042 pattern_cmd->patterns[i].mask_size = mask_len;
1043 pattern_cmd->patterns[i].pattern_size =
1044 wowlan->patterns[i].pattern_len;
1045 }
1046
1047 cmd.data[0] = pattern_cmd;
Johannes Berge10a0532012-03-06 13:30:39 -08001048 err = iwl_dvm_send_cmd(priv, &cmd);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001049 kfree(pattern_cmd);
1050 return err;
1051}
1052
Johannes Bergea886a62012-03-07 09:52:15 -08001053int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan)
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001054{
1055 struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd;
1056 struct iwl_rxon_cmd rxon;
1057 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1058 struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd;
1059 struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {};
1060 struct iwlagn_d3_config_cmd d3_cfg_cmd = {};
1061 struct wowlan_key_data key_data = {
1062 .ctx = ctx,
1063 .bssid = ctx->active.bssid_addr,
1064 .use_rsc_tsc = false,
1065 .tkip = &tkip_cmd,
1066 .use_tkip = false,
1067 };
1068 int ret, i;
1069 u16 seq;
1070
1071 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
1072 if (!key_data.rsc_tsc)
1073 return -ENOMEM;
1074
1075 memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd));
1076
1077 /*
1078 * We know the last used seqno, and the uCode expects to know that
1079 * one, it will increment before TX.
1080 */
1081 seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ;
1082 wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq);
1083
1084 /*
1085 * For QoS counters, we store the one to use next, so subtract 0x10
1086 * since the uCode will add 0x10 before using the value.
1087 */
Johannes Berge0467a32011-12-02 12:24:45 -08001088 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +02001089 seq = priv->tid_data[IWL_AP_ID][i].seq_number;
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001090 seq -= 0x10;
1091 wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq);
1092 }
1093
1094 if (wowlan->disconnect)
1095 wakeup_filter_cmd.enabled |=
1096 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
1097 IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE);
1098 if (wowlan->magic_pkt)
1099 wakeup_filter_cmd.enabled |=
1100 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET);
1101 if (wowlan->gtk_rekey_failure)
1102 wakeup_filter_cmd.enabled |=
1103 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
1104 if (wowlan->eap_identity_req)
1105 wakeup_filter_cmd.enabled |=
1106 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ);
1107 if (wowlan->four_way_handshake)
1108 wakeup_filter_cmd.enabled |=
1109 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
1110 if (wowlan->n_patterns)
1111 wakeup_filter_cmd.enabled |=
1112 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH);
1113
1114 if (wowlan->rfkill_release)
1115 d3_cfg_cmd.wakeup_flags |=
1116 cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL);
1117
1118 iwl_scan_cancel_timeout(priv, 200);
1119
1120 memcpy(&rxon, &ctx->active, sizeof(rxon));
1121
David Spinadel8f7ffbe2012-03-10 13:00:10 -08001122 priv->ucode_loaded = false;
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001123 iwl_trans_stop_device(priv->trans);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001124
Johannes Berg15b86bf2012-03-05 11:24:36 -08001125 priv->wowlan = true;
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001126
Johannes Berge1991882012-03-06 13:30:36 -08001127 ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001128 if (ret)
1129 goto out;
1130
1131 /* now configure WoWLAN ucode */
1132 ret = iwl_alive_start(priv);
1133 if (ret)
1134 goto out;
1135
1136 memcpy(&ctx->staging, &rxon, sizeof(rxon));
1137 ret = iwlagn_commit_rxon(priv, ctx);
1138 if (ret)
1139 goto out;
1140
1141 ret = iwl_power_update_mode(priv, true);
1142 if (ret)
1143 goto out;
1144
Johannes Berg65de7e82012-04-17 07:36:30 -07001145 if (!iwlwifi_mod_params.sw_crypto) {
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001146 /* mark all keys clear */
1147 priv->ucode_key_table = 0;
1148 ctx->key_mapping_keys = 0;
1149
1150 /*
1151 * This needs to be unlocked due to lock ordering
1152 * constraints. Since we're in the suspend path
1153 * that isn't really a problem though.
1154 */
Johannes Bergb1eea292012-03-06 13:30:42 -08001155 mutex_unlock(&priv->mutex);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001156 ieee80211_iter_keys(priv->hw, ctx->vif,
1157 iwlagn_wowlan_program_keys,
1158 &key_data);
Johannes Bergb1eea292012-03-06 13:30:42 -08001159 mutex_lock(&priv->mutex);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001160 if (key_data.error) {
1161 ret = -EIO;
1162 goto out;
1163 }
1164
1165 if (key_data.use_rsc_tsc) {
1166 struct iwl_host_cmd rsc_tsc_cmd = {
1167 .id = REPLY_WOWLAN_TSC_RSC_PARAMS,
1168 .flags = CMD_SYNC,
1169 .data[0] = key_data.rsc_tsc,
1170 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
Johannes Berg182ada12012-03-04 08:31:35 -08001171 .len[0] = sizeof(*key_data.rsc_tsc),
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001172 };
1173
Johannes Berge10a0532012-03-06 13:30:39 -08001174 ret = iwl_dvm_send_cmd(priv, &rsc_tsc_cmd);
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001175 if (ret)
1176 goto out;
1177 }
1178
1179 if (key_data.use_tkip) {
Johannes Berge10a0532012-03-06 13:30:39 -08001180 ret = iwl_dvm_send_cmd_pdu(priv,
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001181 REPLY_WOWLAN_TKIP_PARAMS,
1182 CMD_SYNC, sizeof(tkip_cmd),
1183 &tkip_cmd);
1184 if (ret)
1185 goto out;
1186 }
1187
1188 if (priv->have_rekey_data) {
1189 memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
1190 memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN);
1191 kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
1192 memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN);
1193 kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
1194 kek_kck_cmd.replay_ctr = priv->replay_ctr;
1195
Johannes Berge10a0532012-03-06 13:30:39 -08001196 ret = iwl_dvm_send_cmd_pdu(priv,
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001197 REPLY_WOWLAN_KEK_KCK_MATERIAL,
1198 CMD_SYNC, sizeof(kek_kck_cmd),
1199 &kek_kck_cmd);
1200 if (ret)
1201 goto out;
1202 }
1203 }
1204
Johannes Berge10a0532012-03-06 13:30:39 -08001205 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_D3_CONFIG, CMD_SYNC,
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001206 sizeof(d3_cfg_cmd), &d3_cfg_cmd);
1207 if (ret)
1208 goto out;
1209
Johannes Berge10a0532012-03-06 13:30:39 -08001210 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WOWLAN_WAKEUP_FILTER,
Wey-Yi Guy023ca582011-11-10 06:55:17 -08001211 CMD_SYNC, sizeof(wakeup_filter_cmd),
1212 &wakeup_filter_cmd);
1213 if (ret)
1214 goto out;
1215
1216 ret = iwlagn_send_patterns(priv, wowlan);
1217 out:
1218 kfree(key_data.rsc_tsc);
1219 return ret;
1220}
1221#endif
Johannes Berge10a0532012-03-06 13:30:39 -08001222
1223int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
1224{
Don Fry83626402012-03-07 09:52:37 -08001225 if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) {
Johannes Berg721c32f2012-03-06 13:30:40 -08001226 IWL_WARN(priv, "Not sending command - %s KILL\n",
Don Fry83626402012-03-07 09:52:37 -08001227 iwl_is_rfkill(priv) ? "RF" : "CT");
Johannes Berg721c32f2012-03-06 13:30:40 -08001228 return -EIO;
1229 }
1230
Don Fry17acd0b2012-03-15 13:27:05 -07001231 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
1232 IWL_ERR(priv, "Command %s failed: FW Error\n",
Johannes Bergd9fb6462012-03-26 08:23:39 -07001233 iwl_dvm_get_cmd_string(cmd->id));
Don Fry17acd0b2012-03-15 13:27:05 -07001234 return -EIO;
1235 }
1236
Johannes Berg2cc39c92012-03-06 13:30:41 -08001237 /*
1238 * Synchronous commands from this op-mode must hold
1239 * the mutex, this ensures we don't try to send two
1240 * (or more) synchronous commands at a time.
1241 */
1242 if (cmd->flags & CMD_SYNC)
Johannes Bergb1eea292012-03-06 13:30:42 -08001243 lockdep_assert_held(&priv->mutex);
Johannes Berg2cc39c92012-03-06 13:30:41 -08001244
Johannes Berg947a9402012-03-06 13:30:59 -08001245 if (priv->ucode_owner == IWL_OWNERSHIP_TM &&
1246 !(cmd->flags & CMD_ON_DEMAND)) {
1247 IWL_DEBUG_HC(priv, "tm own the uCode, no regular hcmd send\n");
1248 return -EIO;
1249 }
1250
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001251 return iwl_trans_send_cmd(priv->trans, cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001252}
1253
1254int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id,
1255 u32 flags, u16 len, const void *data)
1256{
1257 struct iwl_host_cmd cmd = {
1258 .id = id,
1259 .len = { len, },
1260 .data = { data, },
1261 .flags = flags,
1262 };
1263
1264 return iwl_dvm_send_cmd(priv, &cmd);
1265}