blob: e8b324c84da8e4aeff107a0cad5e92179b617235 [file] [log] [blame]
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07005 * Copyright(c) 2008 - 2011 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"
36#include "iwl-core.h"
37#include "iwl-io.h"
38#include "iwl-helpers.h"
39#include "iwl-agn-hw.h"
40#include "iwl-agn.h"
Johannes Berg1fa61b22010-04-28 08:44:52 -070041#include "iwl-sta.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070042#include "iwl-trans.h"
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070043#include "iwl-shared.h"
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070044
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070045int iwlagn_hw_valid_rtc_data_addr(u32 addr)
46{
47 return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
48 (addr < IWLAGN_RTC_DATA_UPPER_BOUND);
49}
50
51int iwlagn_send_tx_power(struct iwl_priv *priv)
52{
Wey-Yi Guyab63c682010-09-20 09:12:31 -070053 struct iwlagn_tx_power_dbm_cmd tx_power_cmd;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070054 u8 tx_ant_cfg_cmd;
55
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -070056 if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->shrd->status),
Stanislaw Gruszka4beeba72010-10-25 10:34:50 +020057 "TX Power requested while scanning!\n"))
58 return -EAGAIN;
59
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070060 /* half dBm need to multiply */
61 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
62
63 if (priv->tx_power_lmt_in_half_dbm &&
64 priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
65 /*
66 * For the newer devices which using enhanced/extend tx power
67 * table in EEPROM, the format is in half dBm. driver need to
68 * convert to dBm format before report to mac80211.
69 * By doing so, there is a possibility of 1/2 dBm resolution
70 * lost. driver will perform "round-up" operation before
71 * reporting, but it will cause 1/2 dBm tx power over the
72 * regulatory limit. Perform the checking here, if the
73 * "tx_power_user_lmt" is higher than EEPROM value (in
74 * half-dBm format), lower the tx power based on EEPROM
75 */
76 tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
77 }
Wey-Yi Guyab63c682010-09-20 09:12:31 -070078 tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
79 tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070080
81 if (IWL_UCODE_API(priv->ucode_ver) == 1)
82 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
83 else
84 tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
85
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -070086 return iwl_trans_send_cmd_pdu(trans(priv), tx_ant_cfg_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -070087 sizeof(tx_power_cmd), &tx_power_cmd);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070088}
89
90void iwlagn_temperature(struct iwl_priv *priv)
91{
Fry, Donald Hf8f79a52011-02-25 09:44:48 -080092 /* store temperature from correct statistics (in Celsius) */
Johannes Berg0da0e5b2011-04-08 08:14:56 -070093 priv->temperature = le32_to_cpu(priv->statistics.common.temperature);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -070094 iwl_tt_handler(priv);
95}
96
97u16 iwlagn_eeprom_calib_version(struct iwl_priv *priv)
98{
Wey-Yi Guy7d8f2d52011-09-15 11:46:51 -070099 struct iwl_eeprom_calib_hdr *hdr;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700100
101 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700102 EEPROM_CALIB_ALL);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700103 return hdr->version;
104
105}
106
107/*
108 * EEPROM
109 */
110static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
111{
112 u16 offset = 0;
113
114 if ((address & INDIRECT_ADDRESS) == 0)
115 return address;
116
117 switch (address & INDIRECT_TYPE_MSK) {
118 case INDIRECT_HOST:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700119 offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700120 break;
121 case INDIRECT_GENERAL:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700122 offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700123 break;
124 case INDIRECT_REGULATORY:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700125 offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700126 break;
Johannes Berg8d6748c2010-12-09 09:30:14 -0800127 case INDIRECT_TXP_LIMIT:
128 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
129 break;
130 case INDIRECT_TXP_LIMIT_SIZE:
131 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
132 break;
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700133 case INDIRECT_CALIBRATION:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700134 offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700135 break;
136 case INDIRECT_PROCESS_ADJST:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700137 offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700138 break;
139 case INDIRECT_OTHERS:
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700140 offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700141 break;
142 default:
143 IWL_ERR(priv, "illegal indirect type: 0x%X\n",
144 address & INDIRECT_TYPE_MSK);
145 break;
146 }
147
148 /* translate the offset from words to byte */
149 return (address & ADDRESS_MSK) + (offset << 1);
150}
151
Fry, Donald H70e3e8a2011-07-08 08:46:19 -0700152const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700153{
154 u32 address = eeprom_indirect_address(priv, offset);
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700155 BUG_ON(address >= priv->cfg->base_params->eeprom_size);
Wey-Yi Guye04ed0a2010-03-16 17:47:58 -0700156 return &priv->eeprom[address];
157}
Wey-Yi Guy348ee7c2010-03-16 12:37:27 -0700158
159struct iwl_mod_params iwlagn_mod_params = {
160 .amsdu_size_8K = 1,
161 .restart_fw = 1,
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100162 .plcp_check = true,
Wey-Yi Guyb60eec92011-06-03 13:52:38 -0700163 .bt_coex_active = true,
Wey-Yi Guy3f1e5f42011-06-03 13:52:40 -0700164 .no_sleep_autoadjust = true,
Wey-Yi Guyf7538162011-06-11 10:00:06 -0700165 .power_level = IWL_POWER_INDEX_1,
Wey-Yi Guyfee84f02011-08-25 23:10:57 -0700166 .bt_ch_announce = true,
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700167 .wanted_ucode_alternative = 1,
Wey-Yi Guydd5b6d02011-08-25 23:10:55 -0700168 .auto_agg = true,
Wey-Yi Guy348ee7c2010-03-16 12:37:27 -0700169 /* the rest are 0 by default */
170};
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700171
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700172int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
173{
174 int idx = 0;
175 int band_offset = 0;
176
177 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
178 if (rate_n_flags & RATE_MCS_HT_MSK) {
179 idx = (rate_n_flags & 0xff);
180 return idx;
181 /* Legacy rate format, search for match in table */
182 } else {
183 if (band == IEEE80211_BAND_5GHZ)
184 band_offset = IWL_FIRST_OFDM_RATE;
185 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
186 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
187 return idx - band_offset;
188 }
189
190 return -1;
191}
192
Johannes Bergb6e4c552010-04-06 04:12:42 -0700193static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
Johannes Berg1dda6d22010-04-29 04:43:06 -0700194 struct ieee80211_vif *vif,
195 enum ieee80211_band band,
196 struct iwl_scan_channel *scan_ch)
Johannes Bergb6e4c552010-04-06 04:12:42 -0700197{
198 const struct ieee80211_supported_band *sband;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700199 u16 passive_dwell = 0;
200 u16 active_dwell = 0;
Abhijeet Kolekar14023642010-06-02 21:15:10 -0700201 int added = 0;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700202 u16 channel = 0;
203
204 sband = iwl_get_hw_mode(priv, band);
205 if (!sband) {
206 IWL_ERR(priv, "invalid band\n");
207 return added;
208 }
209
210 active_dwell = iwl_get_active_dwell_time(priv, band, 0);
Johannes Berg1dda6d22010-04-29 04:43:06 -0700211 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700212
213 if (passive_dwell <= active_dwell)
214 passive_dwell = active_dwell + 1;
215
Abhijeet Kolekar14023642010-06-02 21:15:10 -0700216 channel = iwl_get_single_channel_number(priv, band);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700217 if (channel) {
218 scan_ch->channel = cpu_to_le16(channel);
219 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
220 scan_ch->active_dwell = cpu_to_le16(active_dwell);
221 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
222 /* Set txpower levels to defaults */
223 scan_ch->dsp_atten = 110;
224 if (band == IEEE80211_BAND_5GHZ)
225 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
226 else
227 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
228 added++;
229 } else
230 IWL_ERR(priv, "no valid channel found\n");
231 return added;
232}
233
234static int iwl_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg1dda6d22010-04-29 04:43:06 -0700235 struct ieee80211_vif *vif,
Johannes Bergb6e4c552010-04-06 04:12:42 -0700236 enum ieee80211_band band,
237 u8 is_active, u8 n_probes,
238 struct iwl_scan_channel *scan_ch)
239{
240 struct ieee80211_channel *chan;
241 const struct ieee80211_supported_band *sband;
242 const struct iwl_channel_info *ch_info;
243 u16 passive_dwell = 0;
244 u16 active_dwell = 0;
245 int added, i;
246 u16 channel;
247
248 sband = iwl_get_hw_mode(priv, band);
249 if (!sband)
250 return 0;
251
252 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
Johannes Berg1dda6d22010-04-29 04:43:06 -0700253 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700254
255 if (passive_dwell <= active_dwell)
256 passive_dwell = active_dwell + 1;
257
258 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
259 chan = priv->scan_request->channels[i];
260
261 if (chan->band != band)
262 continue;
263
Shanyu Zhao81e95432010-07-28 13:40:27 -0700264 channel = chan->hw_value;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700265 scan_ch->channel = cpu_to_le16(channel);
266
267 ch_info = iwl_get_channel_info(priv, band, channel);
268 if (!is_channel_valid(ch_info)) {
269 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
270 channel);
271 continue;
272 }
273
274 if (!is_active || is_channel_passive(ch_info) ||
275 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
276 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
277 else
278 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
279
280 if (n_probes)
281 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
282
283 scan_ch->active_dwell = cpu_to_le16(active_dwell);
284 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
285
286 /* Set txpower levels to defaults */
287 scan_ch->dsp_atten = 110;
288
289 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
290 * power level:
291 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
292 */
293 if (band == IEEE80211_BAND_5GHZ)
294 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
295 else
296 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
297
298 IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n",
299 channel, le32_to_cpu(scan_ch->type),
300 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
301 "ACTIVE" : "PASSIVE",
302 (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
303 active_dwell : passive_dwell);
304
305 scan_ch++;
306 added++;
307 }
308
309 IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
310 return added;
311}
312
Johannes Berg3eecce52010-09-13 14:46:33 +0200313int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
Johannes Bergb6e4c552010-04-06 04:12:42 -0700314{
315 struct iwl_host_cmd cmd = {
316 .id = REPLY_SCAN_CMD,
Johannes Berg3fa50732011-05-04 07:50:38 -0700317 .len = { sizeof(struct iwl_scan_cmd), },
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700318 .flags = CMD_SYNC,
Johannes Bergb6e4c552010-04-06 04:12:42 -0700319 };
320 struct iwl_scan_cmd *scan;
Johannes Berga194e322010-08-27 08:53:46 -0700321 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Johannes Bergb6e4c552010-04-06 04:12:42 -0700322 u32 rate_flags = 0;
323 u16 cmd_len;
324 u16 rx_chain = 0;
325 enum ieee80211_band band;
326 u8 n_probes = 0;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700327 u8 rx_ant = hw_params(priv).valid_rx_ant;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700328 u8 rate;
329 bool is_active = false;
330 int chan_mod;
331 u8 active_chains;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700332 u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
Johannes Berg3eecce52010-09-13 14:46:33 +0200333 int ret;
334
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700335 lockdep_assert_held(&priv->shrd->mutex);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700336
Johannes Berga194e322010-08-27 08:53:46 -0700337 if (vif)
338 ctx = iwl_rxon_ctx_from_vif(vif);
339
Johannes Bergb6e4c552010-04-06 04:12:42 -0700340 if (!priv->scan_cmd) {
341 priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) +
342 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
343 if (!priv->scan_cmd) {
344 IWL_DEBUG_SCAN(priv,
345 "fail to allocate memory for scan\n");
Johannes Berg3eecce52010-09-13 14:46:33 +0200346 return -ENOMEM;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700347 }
348 }
349 scan = priv->scan_cmd;
350 memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE);
351
352 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
353 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
354
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700355 if (priv->scan_type != IWL_SCAN_ROC &&
Johannes Berg266af4c72011-03-10 20:13:26 -0800356 iwl_is_any_associated(priv)) {
Johannes Bergb6e4c552010-04-06 04:12:42 -0700357 u16 interval = 0;
358 u32 extra;
359 u32 suspend_time = 100;
360 u32 scan_suspend_time = 100;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700361
362 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Johannes Berg266af4c72011-03-10 20:13:26 -0800363 switch (priv->scan_type) {
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700364 case IWL_SCAN_ROC:
Johannes Berg266af4c72011-03-10 20:13:26 -0800365 WARN_ON(1);
366 break;
367 case IWL_SCAN_RADIO_RESET:
John W. Linvillea6e492b2010-07-22 15:24:56 -0400368 interval = 0;
Johannes Berg266af4c72011-03-10 20:13:26 -0800369 break;
370 case IWL_SCAN_NORMAL:
John W. Linvillea6e492b2010-07-22 15:24:56 -0400371 interval = vif->bss_conf.beacon_int;
Johannes Berg266af4c72011-03-10 20:13:26 -0800372 break;
373 }
Johannes Bergb6e4c552010-04-06 04:12:42 -0700374
375 scan->suspend_time = 0;
376 scan->max_out_time = cpu_to_le32(200 * 1024);
377 if (!interval)
378 interval = suspend_time;
379
380 extra = (suspend_time / interval) << 22;
381 scan_suspend_time = (extra |
382 ((suspend_time % interval) * 1024));
383 scan->suspend_time = cpu_to_le32(scan_suspend_time);
384 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
385 scan_suspend_time, interval);
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700386 } else if (priv->scan_type == IWL_SCAN_ROC) {
Johannes Berg266af4c72011-03-10 20:13:26 -0800387 scan->suspend_time = 0;
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700388 scan->max_out_time = 0;
389 scan->quiet_time = 0;
390 scan->quiet_plcp_th = 0;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700391 }
392
Johannes Berg266af4c72011-03-10 20:13:26 -0800393 switch (priv->scan_type) {
394 case IWL_SCAN_RADIO_RESET:
Johannes Bergb6e4c552010-04-06 04:12:42 -0700395 IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
Johannes Berg266af4c72011-03-10 20:13:26 -0800396 break;
397 case IWL_SCAN_NORMAL:
398 if (priv->scan_request->n_ssids) {
399 int i, p = 0;
400 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
401 for (i = 0; i < priv->scan_request->n_ssids; i++) {
402 /* always does wildcard anyway */
403 if (!priv->scan_request->ssids[i].ssid_len)
404 continue;
405 scan->direct_scan[p].id = WLAN_EID_SSID;
406 scan->direct_scan[p].len =
407 priv->scan_request->ssids[i].ssid_len;
408 memcpy(scan->direct_scan[p].ssid,
409 priv->scan_request->ssids[i].ssid,
410 priv->scan_request->ssids[i].ssid_len);
411 n_probes++;
412 p++;
413 }
414 is_active = true;
415 } else
416 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
417 break;
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700418 case IWL_SCAN_ROC:
419 IWL_DEBUG_SCAN(priv, "Start ROC scan.\n");
Johannes Berg266af4c72011-03-10 20:13:26 -0800420 break;
421 }
Johannes Bergb6e4c552010-04-06 04:12:42 -0700422
423 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Johannes Berga194e322010-08-27 08:53:46 -0700424 scan->tx_cmd.sta_id = ctx->bcast_sta_id;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700425 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
426
427 switch (priv->scan_band) {
428 case IEEE80211_BAND_2GHZ:
429 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
Johannes Berg246ed352010-08-23 10:46:32 +0200430 chan_mod = le32_to_cpu(
431 priv->contexts[IWL_RXON_CTX_BSS].active.flags &
432 RXON_FLG_CHANNEL_MODE_MSK)
Johannes Bergb6e4c552010-04-06 04:12:42 -0700433 >> RXON_FLG_CHANNEL_MODE_POS;
434 if (chan_mod == CHANNEL_MODE_PURE_40) {
435 rate = IWL_RATE_6M_PLCP;
436 } else {
437 rate = IWL_RATE_1M_PLCP;
438 rate_flags = RATE_MCS_CCK_MSK;
439 }
Johannes Bergd44ae692010-08-23 07:56:56 -0700440 /*
441 * Internal scans are passive, so we can indiscriminately set
442 * the BT ignore flag on 2.4 GHz since it applies to TX only.
443 */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700444 if (priv->cfg->bt_params &&
445 priv->cfg->bt_params->advanced_bt_coexist)
Johannes Bergd44ae692010-08-23 07:56:56 -0700446 scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700447 break;
448 case IEEE80211_BAND_5GHZ:
449 rate = IWL_RATE_6M_PLCP;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700450 break;
451 default:
Johannes Berg3eecce52010-09-13 14:46:33 +0200452 IWL_WARN(priv, "Invalid scan band\n");
453 return -EIO;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700454 }
455
Johannes Berg085fbca2010-10-04 05:47:23 -0700456 /*
457 * If active scanning is requested but a certain channel is
458 * marked passive, we can do active scanning if we detect
459 * transmissions.
460 *
461 * There is an issue with some firmware versions that triggers
462 * a sysassert on a "good CRC threshold" of zero (== disabled),
463 * on a radar channel even though this means that we should NOT
464 * send probes.
465 *
466 * The "good CRC threshold" is the number of frames that we
467 * need to receive during our dwell time on a channel before
468 * sending out probes -- setting this to a huge value will
469 * mean we never reach it, but at the same time work around
470 * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER
471 * here instead of IWL_GOOD_CRC_TH_DISABLED.
Johannes Bergd2690c02011-04-20 09:10:39 -0700472 *
473 * This was fixed in later versions along with some other
474 * scan changes, and the threshold behaves as a flag in those
475 * versions.
Johannes Berg085fbca2010-10-04 05:47:23 -0700476 */
Johannes Bergd2690c02011-04-20 09:10:39 -0700477 if (priv->new_scan_threshold_behaviour)
478 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
479 IWL_GOOD_CRC_TH_DISABLED;
480 else
481 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
482 IWL_GOOD_CRC_TH_NEVER;
Johannes Berg085fbca2010-10-04 05:47:23 -0700483
Johannes Bergb6e4c552010-04-06 04:12:42 -0700484 band = priv->scan_band;
485
Johannes Berg0e1654f2010-05-18 02:48:36 -0700486 if (priv->cfg->scan_rx_antennas[band])
487 rx_ant = priv->cfg->scan_rx_antennas[band];
Johannes Berge7cb4952010-04-13 01:04:35 -0700488
Stanislaw Gruszkacd017f22010-12-23 15:12:30 +0100489 if (band == IEEE80211_BAND_2GHZ &&
490 priv->cfg->bt_params &&
491 priv->cfg->bt_params->advanced_bt_coexist) {
492 /* transmit 2.4 GHz probes only on first antenna */
493 scan_tx_antennas = first_antenna(scan_tx_antennas);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700494 }
495
Johannes Berg0e1654f2010-05-18 02:48:36 -0700496 priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, priv->scan_tx_ant[band],
497 scan_tx_antennas);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700498 rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]);
499 scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags);
500
501 /* In power save mode use one chain, otherwise use all chains */
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700502 if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) {
Johannes Bergb6e4c552010-04-06 04:12:42 -0700503 /* rx_ant has been set to all valid chains previously */
504 active_chains = rx_ant &
505 ((u8)(priv->chain_noise_data.active_chains));
506 if (!active_chains)
507 active_chains = rx_ant;
508
509 IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n",
510 priv->chain_noise_data.active_chains);
511
512 rx_ant = first_antenna(active_chains);
513 }
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700514 if (priv->cfg->bt_params &&
515 priv->cfg->bt_params->advanced_bt_coexist &&
516 priv->bt_full_concurrent) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700517 /* operated as 1x1 in full concurrency mode */
518 rx_ant = first_antenna(rx_ant);
519 }
520
Johannes Bergb6e4c552010-04-06 04:12:42 -0700521 /* MIMO is not used here, but value is required */
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700522 rx_chain |=
523 hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700524 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
525 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
526 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
527 scan->rx_chain = cpu_to_le16(rx_chain);
Johannes Berg266af4c72011-03-10 20:13:26 -0800528 switch (priv->scan_type) {
529 case IWL_SCAN_NORMAL:
Johannes Bergb6e4c552010-04-06 04:12:42 -0700530 cmd_len = iwl_fill_probe_req(priv,
531 (struct ieee80211_mgmt *)scan->data,
Johannes Berg3a0b9aa2010-05-12 03:33:12 -0700532 vif->addr,
Johannes Bergb6e4c552010-04-06 04:12:42 -0700533 priv->scan_request->ie,
534 priv->scan_request->ie_len,
535 IWL_MAX_SCAN_SIZE - sizeof(*scan));
Johannes Berg266af4c72011-03-10 20:13:26 -0800536 break;
537 case IWL_SCAN_RADIO_RESET:
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700538 case IWL_SCAN_ROC:
Johannes Berg3a0b9aa2010-05-12 03:33:12 -0700539 /* use bcast addr, will not be transmitted but must be valid */
Johannes Bergb6e4c552010-04-06 04:12:42 -0700540 cmd_len = iwl_fill_probe_req(priv,
541 (struct ieee80211_mgmt *)scan->data,
Johannes Berg3a0b9aa2010-05-12 03:33:12 -0700542 iwl_bcast_addr, NULL, 0,
Johannes Bergb6e4c552010-04-06 04:12:42 -0700543 IWL_MAX_SCAN_SIZE - sizeof(*scan));
Johannes Berg266af4c72011-03-10 20:13:26 -0800544 break;
Johannes Berg266af4c72011-03-10 20:13:26 -0800545 default:
546 BUG();
Johannes Bergb6e4c552010-04-06 04:12:42 -0700547 }
548 scan->tx_cmd.len = cpu_to_le16(cmd_len);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700549
550 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
551 RXON_FILTER_BCON_AWARE_MSK);
552
Johannes Berg266af4c72011-03-10 20:13:26 -0800553 switch (priv->scan_type) {
554 case IWL_SCAN_RADIO_RESET:
Johannes Bergb6e4c552010-04-06 04:12:42 -0700555 scan->channel_count =
Johannes Berg1dda6d22010-04-29 04:43:06 -0700556 iwl_get_single_channel_for_scan(priv, vif, band,
Johannes Berg266af4c72011-03-10 20:13:26 -0800557 (void *)&scan->data[cmd_len]);
558 break;
559 case IWL_SCAN_NORMAL:
Johannes Bergb6e4c552010-04-06 04:12:42 -0700560 scan->channel_count =
Johannes Berg1dda6d22010-04-29 04:43:06 -0700561 iwl_get_channels_for_scan(priv, vif, band,
Johannes Bergb6e4c552010-04-06 04:12:42 -0700562 is_active, n_probes,
Johannes Berg266af4c72011-03-10 20:13:26 -0800563 (void *)&scan->data[cmd_len]);
564 break;
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700565 case IWL_SCAN_ROC: {
Johannes Berg266af4c72011-03-10 20:13:26 -0800566 struct iwl_scan_channel *scan_ch;
567
568 scan->channel_count = 1;
569
570 scan_ch = (void *)&scan->data[cmd_len];
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700571 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
Johannes Berg266af4c72011-03-10 20:13:26 -0800572 scan_ch->channel =
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700573 cpu_to_le16(priv->hw_roc_channel->hw_value);
Johannes Berg266af4c72011-03-10 20:13:26 -0800574 scan_ch->active_dwell =
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700575 scan_ch->passive_dwell =
576 cpu_to_le16(priv->hw_roc_duration);
Johannes Berg266af4c72011-03-10 20:13:26 -0800577
578 /* Set txpower levels to defaults */
579 scan_ch->dsp_atten = 110;
580
581 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
582 * power level:
583 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
584 */
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700585 if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ)
Johannes Berg266af4c72011-03-10 20:13:26 -0800586 scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
587 else
588 scan_ch->tx_gain = ((1 << 5) | (5 << 3));
589 }
590 break;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700591 }
Johannes Berg266af4c72011-03-10 20:13:26 -0800592
Johannes Bergb6e4c552010-04-06 04:12:42 -0700593 if (scan->channel_count == 0) {
594 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Johannes Berg3eecce52010-09-13 14:46:33 +0200595 return -EIO;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700596 }
597
Johannes Berg3fa50732011-05-04 07:50:38 -0700598 cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) +
Johannes Bergb6e4c552010-04-06 04:12:42 -0700599 scan->channel_count * sizeof(struct iwl_scan_channel);
Johannes Berg3fa50732011-05-04 07:50:38 -0700600 cmd.data[0] = scan;
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700601 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
Johannes Berg3fa50732011-05-04 07:50:38 -0700602 scan->len = cpu_to_le16(cmd.len[0]);
Johannes Bergb6e4c552010-04-06 04:12:42 -0700603
Johannes Berg1cf26372010-09-22 07:32:13 -0700604 /* set scan bit here for PAN params */
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700605 set_bit(STATUS_SCAN_HW, &priv->shrd->status);
Johannes Berg1cf26372010-09-22 07:32:13 -0700606
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700607 ret = iwlagn_set_pan_params(priv);
608 if (ret)
609 return ret;
Johannes Berg3eecce52010-09-13 14:46:33 +0200610
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700611 ret = iwl_trans_send_cmd(trans(priv), &cmd);
Johannes Berg3eecce52010-09-13 14:46:33 +0200612 if (ret) {
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700613 clear_bit(STATUS_SCAN_HW, &priv->shrd->status);
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700614 iwlagn_set_pan_params(priv);
Johannes Berg3eecce52010-09-13 14:46:33 +0200615 }
Johannes Berg52a02d12010-08-27 09:44:50 -0700616
Johannes Berg3eecce52010-09-13 14:46:33 +0200617 return ret;
Johannes Bergb6e4c552010-04-06 04:12:42 -0700618}
Johannes Berg1fa61b22010-04-28 08:44:52 -0700619
620int iwlagn_manage_ibss_station(struct iwl_priv *priv,
621 struct ieee80211_vif *vif, bool add)
622{
Johannes Bergfd1af152010-04-30 11:30:43 -0700623 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
624
Johannes Berg1fa61b22010-04-28 08:44:52 -0700625 if (add)
Johannes Berga30e3112010-09-22 18:02:01 +0200626 return iwlagn_add_bssid_station(priv, vif_priv->ctx,
627 vif->bss_conf.bssid,
628 &vif_priv->ibss_bssid_sta_id);
Johannes Bergfd1af152010-04-30 11:30:43 -0700629 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
630 vif->bss_conf.bssid);
Johannes Berg1fa61b22010-04-28 08:44:52 -0700631}
Johannes Berg1ff504e2010-05-03 01:22:42 -0700632
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700633/**
634 * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
635 *
636 * pre-requirements:
637 * 1. acquire mutex before calling
638 * 2. make sure rf is on and not in exit state
639 */
640int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
641{
642 struct iwl_txfifo_flush_cmd flush_cmd;
643 struct iwl_host_cmd cmd = {
644 .id = REPLY_TXFIFO_FLUSH,
Johannes Berg3fa50732011-05-04 07:50:38 -0700645 .len = { sizeof(struct iwl_txfifo_flush_cmd), },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700646 .flags = CMD_SYNC,
Johannes Berg3fa50732011-05-04 07:50:38 -0700647 .data = { &flush_cmd, },
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700648 };
649
650 might_sleep();
651
652 memset(&flush_cmd, 0, sizeof(flush_cmd));
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700653 if (flush_control & BIT(IWL_RXON_CTX_BSS))
654 flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK |
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700655 IWL_SCD_BE_MSK | IWL_SCD_BK_MSK |
656 IWL_SCD_MGMT_MSK;
Wey-Yi Guyecdbe862011-06-08 09:57:26 -0700657 if ((flush_control & BIT(IWL_RXON_CTX_PAN)) &&
Emmanuel Grumbach7a10e3e2011-09-06 09:31:21 -0700658 (priv->shrd->valid_contexts != BIT(IWL_RXON_CTX_BSS)))
Wey-Yi Guyf88e0ec2011-06-08 09:57:25 -0700659 flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK |
660 IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK |
661 IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
662 IWL_PAN_SCD_MULTICAST_MSK;
663
Wey-Yi Guy88950752011-06-06 12:05:46 -0700664 if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700665 flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
666
667 IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
668 flush_cmd.fifo_control);
669 flush_cmd.flush_control = cpu_to_le16(flush_control);
670
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700671 return iwl_trans_send_cmd(trans(priv), &cmd);
Wey-Yi Guy716c74b2010-06-24 13:22:36 -0700672}
Wey-Yi Guy65550632010-06-24 13:18:35 -0700673
674void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
675{
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700676 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700677 ieee80211_stop_queues(priv->hw);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -0700678 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
Wey-Yi Guy65550632010-06-24 13:18:35 -0700679 IWL_ERR(priv, "flush request fail\n");
680 goto done;
681 }
682 IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n");
Emmanuel Grumbach5f178cd2011-08-25 23:11:29 -0700683 iwl_trans_wait_tx_queue_empty(trans(priv));
Wey-Yi Guy65550632010-06-24 13:18:35 -0700684done:
685 ieee80211_wake_queues(priv->hw);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700686 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700687}
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700688
689/*
690 * BT coex
691 */
692/*
693 * Macros to access the lookup table.
694 *
695 * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
696* wifi_prio, wifi_txrx and wifi_sh_ant_req.
697 *
698 * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
699 *
700 * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
701 * one after another in 32-bit registers, and "registers" 0 through 7 contain
702 * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
703 *
704 * These macros encode that format.
705 */
706#define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
707 wifi_txrx, wifi_sh_ant_req) \
708 (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
709 (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
710
711#define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
712 lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
713#define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
714 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
715 (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
716 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
717 wifi_sh_ant_req))))
718#define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
719 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
720 LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
721 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
722 wifi_sh_ant_req))
723#define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
724 wifi_req, wifi_prio, wifi_txrx, \
725 wifi_sh_ant_req) \
726 LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
727 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
728 wifi_sh_ant_req))
729
730#define LUT_WLAN_KILL_OP(lut, op, val) \
731 lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
732#define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
733 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
734 (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
735 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
736#define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
737 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
738 LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
739 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
740#define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
741 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
742 LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
743 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
744
745#define LUT_ANT_SWITCH_OP(lut, op, val) \
746 lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
747#define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
748 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
749 (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
750 wifi_req, wifi_prio, wifi_txrx, \
751 wifi_sh_ant_req))))
752#define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
753 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
754 LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
755 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
756#define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
757 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
758 LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
759 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
760
761static const __le32 iwlagn_def_3w_lookup[12] = {
762 cpu_to_le32(0xaaaaaaaa),
763 cpu_to_le32(0xaaaaaaaa),
764 cpu_to_le32(0xaeaaaaaa),
765 cpu_to_le32(0xaaaaaaaa),
766 cpu_to_le32(0xcc00ff28),
767 cpu_to_le32(0x0000aaaa),
768 cpu_to_le32(0xcc00aaaa),
769 cpu_to_le32(0x0000aaaa),
770 cpu_to_le32(0xc0004000),
771 cpu_to_le32(0x00004000),
772 cpu_to_le32(0xf0005000),
Wey-Yi Guy9a67d762010-11-18 10:40:03 -0800773 cpu_to_le32(0xf0005000),
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700774};
775
776static const __le32 iwlagn_concurrent_lookup[12] = {
777 cpu_to_le32(0xaaaaaaaa),
778 cpu_to_le32(0xaaaaaaaa),
779 cpu_to_le32(0xaaaaaaaa),
780 cpu_to_le32(0xaaaaaaaa),
781 cpu_to_le32(0xaaaaaaaa),
782 cpu_to_le32(0xaaaaaaaa),
783 cpu_to_le32(0xaaaaaaaa),
784 cpu_to_le32(0xaaaaaaaa),
785 cpu_to_le32(0x00000000),
786 cpu_to_le32(0x00000000),
787 cpu_to_le32(0x00000000),
788 cpu_to_le32(0x00000000),
789};
790
791void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
792{
Wey-Yi Guy60132702011-02-18 17:23:54 -0800793 struct iwl_basic_bt_cmd basic = {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700794 .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT,
795 .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT,
796 .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
797 .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
798 };
Wey-Yi Guy60132702011-02-18 17:23:54 -0800799 struct iwl6000_bt_cmd bt_cmd_6000;
800 struct iwl2000_bt_cmd bt_cmd_2000;
801 int ret;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700802
803 BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
Wey-Yi Guy60132702011-02-18 17:23:54 -0800804 sizeof(basic.bt3_lookup_table));
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700805
Wey-Yi Guy60132702011-02-18 17:23:54 -0800806 if (priv->cfg->bt_params) {
807 if (priv->cfg->bt_params->bt_session_2) {
808 bt_cmd_2000.prio_boost = cpu_to_le32(
809 priv->cfg->bt_params->bt_prio_boost);
810 bt_cmd_2000.tx_prio_boost = 0;
811 bt_cmd_2000.rx_prio_boost = 0;
812 } else {
813 bt_cmd_6000.prio_boost =
814 priv->cfg->bt_params->bt_prio_boost;
815 bt_cmd_6000.tx_prio_boost = 0;
816 bt_cmd_6000.rx_prio_boost = 0;
817 }
818 } else {
819 IWL_ERR(priv, "failed to construct BT Coex Config\n");
820 return;
821 }
Wey-Yi Guy506aa152010-11-24 17:25:03 -0800822
Wey-Yi Guy60132702011-02-18 17:23:54 -0800823 basic.kill_ack_mask = priv->kill_ack_mask;
824 basic.kill_cts_mask = priv->kill_cts_mask;
825 basic.valid = priv->bt_valid;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700826
827 /*
828 * Configure BT coex mode to "no coexistence" when the
829 * user disabled BT coexistence, we have no interface
830 * (might be in monitor mode), or the interface is in
831 * IBSS mode (no proper uCode support for coex then).
832 */
Wey-Yi Guyb60eec92011-06-03 13:52:38 -0700833 if (!iwlagn_mod_params.bt_coex_active ||
834 priv->iw_mode == NL80211_IFTYPE_ADHOC) {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800835 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700836 } else {
Wey-Yi Guy60132702011-02-18 17:23:54 -0800837 basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W <<
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700838 IWLAGN_BT_FLAG_COEX_MODE_SHIFT;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700839
840 if (!priv->bt_enable_pspoll)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800841 basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700842 else
843 basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE;
Wey-Yi Guye3661762010-11-23 10:58:54 -0800844
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700845 if (priv->bt_ch_announce)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800846 basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION;
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700847 IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700848 }
Wey-Yi Guy60132702011-02-18 17:23:54 -0800849 priv->bt_enable_flag = basic.flags;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700850 if (priv->bt_full_concurrent)
Wey-Yi Guy60132702011-02-18 17:23:54 -0800851 memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700852 sizeof(iwlagn_concurrent_lookup));
853 else
Wey-Yi Guy60132702011-02-18 17:23:54 -0800854 memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700855 sizeof(iwlagn_def_3w_lookup));
856
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700857 IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n",
Wey-Yi Guy60132702011-02-18 17:23:54 -0800858 basic.flags ? "active" : "disabled",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700859 priv->bt_full_concurrent ?
860 "full concurrency" : "3-wire");
861
Wey-Yi Guy60132702011-02-18 17:23:54 -0800862 if (priv->cfg->bt_params->bt_session_2) {
863 memcpy(&bt_cmd_2000.basic, &basic,
864 sizeof(basic));
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700865 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700866 CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800867 } else {
868 memcpy(&bt_cmd_6000.basic, &basic,
869 sizeof(basic));
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700870 ret = iwl_trans_send_cmd_pdu(trans(priv), REPLY_BT_CONFIG,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700871 CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
Wey-Yi Guy60132702011-02-18 17:23:54 -0800872 }
873 if (ret)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700874 IWL_ERR(priv, "failed to send BT Coex Config\n");
875
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700876}
877
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700878void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena)
879{
880 struct iwl_rxon_context *ctx, *found_ctx = NULL;
881 bool found_ap = false;
882
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700883 lockdep_assert_held(&priv->shrd->mutex);
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700884
885 /* Check whether AP or GO mode is active. */
886 if (rssi_ena) {
887 for_each_context(priv, ctx) {
888 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP &&
889 iwl_is_associated_ctx(ctx)) {
890 found_ap = true;
891 break;
892 }
893 }
894 }
895
896 /*
897 * If disable was received or If GO/AP mode, disable RSSI
898 * measurements.
899 */
900 if (!rssi_ena || found_ap) {
901 if (priv->cur_rssi_ctx) {
902 ctx = priv->cur_rssi_ctx;
903 ieee80211_disable_rssi_reports(ctx->vif);
904 priv->cur_rssi_ctx = NULL;
905 }
906 return;
907 }
908
909 /*
910 * If rssi measurements need to be enabled, consider all cases now.
911 * Figure out how many contexts are active.
912 */
913 for_each_context(priv, ctx) {
914 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
915 iwl_is_associated_ctx(ctx)) {
916 found_ctx = ctx;
917 break;
918 }
919 }
920
921 /*
922 * rssi monitor already enabled for the correct interface...nothing
923 * to do.
924 */
925 if (found_ctx == priv->cur_rssi_ctx)
926 return;
927
928 /*
929 * Figure out if rssi monitor is currently enabled, and needs
930 * to be changed. If rssi monitor is already enabled, disable
931 * it first else just enable rssi measurements on the
932 * interface found above.
933 */
934 if (priv->cur_rssi_ctx) {
935 ctx = priv->cur_rssi_ctx;
936 if (ctx->vif)
937 ieee80211_disable_rssi_reports(ctx->vif);
938 }
939
940 priv->cur_rssi_ctx = found_ctx;
941
942 if (!found_ctx)
943 return;
944
945 ieee80211_enable_rssi_reports(found_ctx->vif,
946 IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD,
947 IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD);
948}
949
950static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg)
951{
952 return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >>
953 BT_UART_MSG_FRAME3SCOESCO_POS;
954}
955
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700956static void iwlagn_bt_traffic_change_work(struct work_struct *work)
957{
958 struct iwl_priv *priv =
959 container_of(work, struct iwl_priv, bt_traffic_change_work);
Johannes Berg8bd413e2010-08-23 10:46:40 +0200960 struct iwl_rxon_context *ctx;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700961 int smps_request = -1;
962
Wey-Yi Guyc4197c62011-02-06 08:56:35 -0800963 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
964 /* bt coex disabled */
965 return;
966 }
967
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200968 /*
969 * Note: bt_traffic_load can be overridden by scan complete and
970 * coex profile notifications. Ignore that since only bad consequence
971 * can be not matching debug print with actual state.
972 */
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -0700973 IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700974 priv->bt_traffic_load);
975
976 switch (priv->bt_traffic_load) {
977 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
Wey-Yi Guyf5682c02010-10-23 09:15:44 -0700978 if (priv->bt_status)
979 smps_request = IEEE80211_SMPS_DYNAMIC;
980 else
981 smps_request = IEEE80211_SMPS_AUTOMATIC;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700982 break;
983 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
984 smps_request = IEEE80211_SMPS_DYNAMIC;
985 break;
986 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
987 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
988 smps_request = IEEE80211_SMPS_STATIC;
989 break;
990 default:
991 IWL_ERR(priv, "Invalid BT traffic load: %d\n",
992 priv->bt_traffic_load);
993 break;
994 }
995
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700996 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -0700997
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +0200998 /*
999 * We can not send command to firmware while scanning. When the scan
1000 * complete we will schedule this work again. We do check with mutex
1001 * locked to prevent new scan request to arrive. We do not check
1002 * STATUS_SCANNING to avoid race when queue_work two times from
1003 * different notifications, but quit and not perform any work at all.
1004 */
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -07001005 if (test_bit(STATUS_SCAN_HW, &priv->shrd->status))
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +02001006 goto out;
1007
Fry, Donald H6b6db912011-07-08 08:46:17 -07001008 iwl_update_chain_flags(priv);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001009
Johannes Berg8bd413e2010-08-23 10:46:40 +02001010 if (smps_request != -1) {
Wey-Yi Guy88e9ba72011-06-03 07:54:12 -07001011 priv->current_ht_config.smps = smps_request;
Johannes Berg8bd413e2010-08-23 10:46:40 +02001012 for_each_context(priv, ctx) {
1013 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
1014 ieee80211_request_smps(ctx->vif, smps_request);
1015 }
1016 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001017
1018 /*
1019 * Dynamic PS poll related functionality. Adjust RSSI measurements if
1020 * necessary.
1021 */
1022 iwlagn_bt_coex_rssi_monitor(priv);
Stanislaw Gruszka5eda74a2010-10-22 17:04:28 +02001023out:
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001024 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001025}
1026
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001027/*
1028 * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
1029 * correct interface or disable it if this is the last interface to be
1030 * removed.
1031 */
1032void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv)
1033{
1034 if (priv->bt_is_sco &&
1035 priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS)
1036 iwlagn_bt_adjust_rssi_monitor(priv, true);
1037 else
1038 iwlagn_bt_adjust_rssi_monitor(priv, false);
1039}
1040
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001041static void iwlagn_print_uartmsg(struct iwl_priv *priv,
1042 struct iwl_bt_uart_msg *uart_msg)
1043{
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001044 IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001045 "Update Req = 0x%X",
1046 (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >>
1047 BT_UART_MSG_FRAME1MSGTYPE_POS,
1048 (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >>
1049 BT_UART_MSG_FRAME1SSN_POS,
1050 (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >>
1051 BT_UART_MSG_FRAME1UPDATEREQ_POS);
1052
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001053 IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001054 "Chl_SeqN = 0x%X, In band = 0x%X",
1055 (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >>
1056 BT_UART_MSG_FRAME2OPENCONNECTIONS_POS,
1057 (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >>
1058 BT_UART_MSG_FRAME2TRAFFICLOAD_POS,
1059 (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >>
1060 BT_UART_MSG_FRAME2CHLSEQN_POS,
1061 (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >>
1062 BT_UART_MSG_FRAME2INBAND_POS);
1063
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001064 IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001065 "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X",
1066 (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >>
1067 BT_UART_MSG_FRAME3SCOESCO_POS,
1068 (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >>
1069 BT_UART_MSG_FRAME3SNIFF_POS,
1070 (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >>
1071 BT_UART_MSG_FRAME3A2DP_POS,
1072 (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >>
1073 BT_UART_MSG_FRAME3ACL_POS,
1074 (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >>
1075 BT_UART_MSG_FRAME3MASTER_POS,
1076 (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >>
1077 BT_UART_MSG_FRAME3OBEX_POS);
1078
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001079 IWL_DEBUG_COEX(priv, "Idle duration = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001080 (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >>
1081 BT_UART_MSG_FRAME4IDLEDURATION_POS);
1082
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001083 IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001084 "eSCO Retransmissions = 0x%X",
1085 (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >>
1086 BT_UART_MSG_FRAME5TXACTIVITY_POS,
1087 (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >>
1088 BT_UART_MSG_FRAME5RXACTIVITY_POS,
1089 (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >>
1090 BT_UART_MSG_FRAME5ESCORETRANSMIT_POS);
1091
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001092 IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001093 (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >>
1094 BT_UART_MSG_FRAME6SNIFFINTERVAL_POS,
1095 (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >>
1096 BT_UART_MSG_FRAME6DISCOVERABLE_POS);
1097
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001098 IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = "
Wey-Yi Guy399f66f2011-02-22 08:24:22 -08001099 "0x%X, Inquiry = 0x%X, Connectable = 0x%X",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001100 (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >>
1101 BT_UART_MSG_FRAME7SNIFFACTIVITY_POS,
Wey-Yi Guy399f66f2011-02-22 08:24:22 -08001102 (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >>
1103 BT_UART_MSG_FRAME7PAGE_POS,
1104 (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >>
1105 BT_UART_MSG_FRAME7INQUIRY_POS,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001106 (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >>
1107 BT_UART_MSG_FRAME7CONNECTABLE_POS);
1108}
1109
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001110static void iwlagn_set_kill_msk(struct iwl_priv *priv,
1111 struct iwl_bt_uart_msg *uart_msg)
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001112{
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001113 u8 kill_msk;
Joe Perches20407ed2010-11-20 18:38:57 -08001114 static const __le32 bt_kill_ack_msg[2] = {
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001115 IWLAGN_BT_KILL_ACK_MASK_DEFAULT,
1116 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
1117 static const __le32 bt_kill_cts_msg[2] = {
1118 IWLAGN_BT_KILL_CTS_MASK_DEFAULT,
1119 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO };
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001120
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001121 kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3)
1122 ? 1 : 0;
1123 if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] ||
1124 priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001125 priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK;
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001126 priv->kill_ack_mask = bt_kill_ack_msg[kill_msk];
1127 priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK;
1128 priv->kill_cts_mask = bt_kill_cts_msg[kill_msk];
1129
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001130 /* schedule to send runtime bt_config */
Emmanuel Grumbach74e28e42011-08-25 23:10:41 -07001131 queue_work(priv->shrd->workqueue, &priv->bt_runtime_config);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001132 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001133}
1134
1135void iwlagn_bt_coex_profile_notif(struct iwl_priv *priv,
1136 struct iwl_rx_mem_buffer *rxb)
1137{
1138 unsigned long flags;
1139 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1140 struct iwl_bt_coex_profile_notif *coex = &pkt->u.bt_coex_profile_notif;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001141 struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg;
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001142
Wey-Yi Guyc4197c62011-02-06 08:56:35 -08001143 if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) {
1144 /* bt coex disabled */
1145 return;
1146 }
1147
Wey-Yi Guyfa7f1412011-06-06 12:49:25 -07001148 IWL_DEBUG_COEX(priv, "BT Coex notification:\n");
1149 IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status);
1150 IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load);
1151 IWL_DEBUG_COEX(priv, " CI compliance: %d\n",
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001152 coex->bt_ci_compliance);
1153 iwlagn_print_uartmsg(priv, uart_msg);
1154
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08001155 priv->last_bt_traffic_load = priv->bt_traffic_load;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001156 priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg);
1157
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001158 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
1159 if (priv->bt_status != coex->bt_status ||
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08001160 priv->last_bt_traffic_load != coex->bt_traffic_load) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001161 if (coex->bt_status) {
1162 /* BT on */
1163 if (!priv->bt_ch_announce)
1164 priv->bt_traffic_load =
1165 IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1166 else
1167 priv->bt_traffic_load =
1168 coex->bt_traffic_load;
1169 } else {
1170 /* BT off */
1171 priv->bt_traffic_load =
1172 IWL_BT_COEX_TRAFFIC_LOAD_NONE;
1173 }
1174 priv->bt_status = coex->bt_status;
Emmanuel Grumbach74e28e42011-08-25 23:10:41 -07001175 queue_work(priv->shrd->workqueue,
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001176 &priv->bt_traffic_change_work);
1177 }
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001178 }
1179
Wey-Yi Guy506aa152010-11-24 17:25:03 -08001180 iwlagn_set_kill_msk(priv, uart_msg);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001181
1182 /* FIXME: based on notification, adjust the prio_boost */
1183
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -07001184 spin_lock_irqsave(&priv->shrd->lock, flags);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001185 priv->bt_ci_compliance = coex->bt_ci_compliance;
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -07001186 spin_unlock_irqrestore(&priv->shrd->lock, flags);
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001187}
1188
1189void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv)
1190{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001191 priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] =
1192 iwlagn_bt_coex_profile_notif;
1193}
1194
1195void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv)
1196{
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001197 INIT_WORK(&priv->bt_traffic_change_work,
1198 iwlagn_bt_traffic_change_work);
1199}
1200
1201void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv)
1202{
1203 cancel_work_sync(&priv->bt_traffic_change_work);
1204}
Johannes Berg5de33062010-09-22 18:01:58 +02001205
1206static bool is_single_rx_stream(struct iwl_priv *priv)
1207{
1208 return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
1209 priv->current_ht_config.single_chain_sufficient;
1210}
1211
1212#define IWL_NUM_RX_CHAINS_MULTIPLE 3
1213#define IWL_NUM_RX_CHAINS_SINGLE 2
1214#define IWL_NUM_IDLE_CHAINS_DUAL 2
1215#define IWL_NUM_IDLE_CHAINS_SINGLE 1
1216
1217/*
1218 * Determine how many receiver/antenna chains to use.
1219 *
1220 * More provides better reception via diversity. Fewer saves power
1221 * at the expense of throughput, but only when not in powersave to
1222 * start with.
1223 *
1224 * MIMO (dual stream) requires at least 2, but works better with 3.
1225 * This does not determine *which* chains to use, just how many.
1226 */
1227static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
1228{
1229 if (priv->cfg->bt_params &&
1230 priv->cfg->bt_params->advanced_bt_coexist &&
1231 (priv->bt_full_concurrent ||
1232 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
1233 /*
1234 * only use chain 'A' in bt high traffic load or
1235 * full concurrency mode
1236 */
1237 return IWL_NUM_RX_CHAINS_SINGLE;
1238 }
1239 /* # of Rx chains to use when expecting MIMO. */
1240 if (is_single_rx_stream(priv))
1241 return IWL_NUM_RX_CHAINS_SINGLE;
1242 else
1243 return IWL_NUM_RX_CHAINS_MULTIPLE;
1244}
1245
1246/*
1247 * When we are in power saving mode, unless device support spatial
1248 * multiplexing power save, use the active count for rx chain count.
1249 */
1250static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
1251{
1252 /* # Rx chains when idling, depending on SMPS mode */
1253 switch (priv->current_ht_config.smps) {
1254 case IEEE80211_SMPS_STATIC:
1255 case IEEE80211_SMPS_DYNAMIC:
1256 return IWL_NUM_IDLE_CHAINS_SINGLE;
1257 case IEEE80211_SMPS_OFF:
1258 return active_cnt;
1259 default:
1260 WARN(1, "invalid SMPS mode %d",
1261 priv->current_ht_config.smps);
1262 return active_cnt;
1263 }
1264}
1265
1266/* up to 4 chains */
1267static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
1268{
1269 u8 res;
1270 res = (chain_bitmap & BIT(0)) >> 0;
1271 res += (chain_bitmap & BIT(1)) >> 1;
1272 res += (chain_bitmap & BIT(2)) >> 2;
1273 res += (chain_bitmap & BIT(3)) >> 3;
1274 return res;
1275}
1276
1277/**
1278 * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
1279 *
1280 * Selects how many and which Rx receivers/antennas/chains to use.
1281 * This should not be used for scan command ... it puts data in wrong place.
1282 */
1283void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1284{
1285 bool is_single = is_single_rx_stream(priv);
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -07001286 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->shrd->status);
Johannes Berg5de33062010-09-22 18:01:58 +02001287 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
1288 u32 active_chains;
1289 u16 rx_chain;
1290
1291 /* Tell uCode which antennas are actually connected.
1292 * Before first association, we assume all antennas are connected.
1293 * Just after first association, iwl_chain_noise_calibration()
1294 * checks which antennas actually *are* connected. */
1295 if (priv->chain_noise_data.active_chains)
1296 active_chains = priv->chain_noise_data.active_chains;
1297 else
Emmanuel Grumbachd6189122011-08-25 23:10:39 -07001298 active_chains = hw_params(priv).valid_rx_ant;
Johannes Berg5de33062010-09-22 18:01:58 +02001299
1300 if (priv->cfg->bt_params &&
1301 priv->cfg->bt_params->advanced_bt_coexist &&
1302 (priv->bt_full_concurrent ||
1303 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) {
1304 /*
1305 * only use chain 'A' in bt high traffic load or
1306 * full concurrency mode
1307 */
1308 active_chains = first_antenna(active_chains);
1309 }
1310
1311 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
1312
1313 /* How many receivers should we use? */
1314 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
1315 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
1316
1317
1318 /* correct rx chain count according hw settings
1319 * and chain noise calibration
1320 */
1321 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
1322 if (valid_rx_cnt < active_rx_cnt)
1323 active_rx_cnt = valid_rx_cnt;
1324
1325 if (valid_rx_cnt < idle_rx_cnt)
1326 idle_rx_cnt = valid_rx_cnt;
1327
1328 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
1329 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
1330
1331 ctx->staging.rx_chain = cpu_to_le16(rx_chain);
1332
1333 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
1334 ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
1335 else
1336 ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
1337
1338 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
1339 ctx->staging.rx_chain,
1340 active_rx_cnt, idle_rx_cnt);
1341
1342 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
1343 active_rx_cnt < idle_rx_cnt);
1344}
Johannes Bergfacd9822010-09-22 18:02:05 +02001345
1346u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
1347{
1348 int i;
1349 u8 ind = ant;
1350
1351 if (priv->band == IEEE80211_BAND_2GHZ &&
1352 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
1353 return 0;
1354
1355 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
1356 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
1357 if (valid & BIT(ind))
1358 return ind;
1359 }
1360 return ant;
1361}
Johannes Bergfed73292010-09-22 18:02:06 +02001362
Johannes Berg7194207c2011-01-04 16:22:00 -08001363/* notification wait support */
1364void iwlagn_init_notification_wait(struct iwl_priv *priv,
1365 struct iwl_notification_wait *wait_entry,
Johannes Berg09f18af2011-04-13 03:14:47 -07001366 u8 cmd,
Johannes Berg7194207c2011-01-04 16:22:00 -08001367 void (*fn)(struct iwl_priv *priv,
Johannes Berg09f18af2011-04-13 03:14:47 -07001368 struct iwl_rx_packet *pkt,
1369 void *data),
1370 void *fn_data)
Johannes Berg7194207c2011-01-04 16:22:00 -08001371{
1372 wait_entry->fn = fn;
Johannes Berg09f18af2011-04-13 03:14:47 -07001373 wait_entry->fn_data = fn_data;
Johannes Berg7194207c2011-01-04 16:22:00 -08001374 wait_entry->cmd = cmd;
1375 wait_entry->triggered = false;
Johannes Berge74fe232011-04-13 03:14:49 -07001376 wait_entry->aborted = false;
Johannes Berg7194207c2011-01-04 16:22:00 -08001377
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001378 spin_lock_bh(&priv->notif_wait_lock);
1379 list_add(&wait_entry->list, &priv->notif_waits);
1380 spin_unlock_bh(&priv->notif_wait_lock);
Johannes Berg7194207c2011-01-04 16:22:00 -08001381}
1382
Johannes Berga8674a12011-04-13 03:14:48 -07001383int iwlagn_wait_notification(struct iwl_priv *priv,
1384 struct iwl_notification_wait *wait_entry,
1385 unsigned long timeout)
Johannes Berg7194207c2011-01-04 16:22:00 -08001386{
1387 int ret;
1388
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001389 ret = wait_event_timeout(priv->notif_waitq,
Johannes Berge74fe232011-04-13 03:14:49 -07001390 wait_entry->triggered || wait_entry->aborted,
Johannes Berg7194207c2011-01-04 16:22:00 -08001391 timeout);
1392
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001393 spin_lock_bh(&priv->notif_wait_lock);
Johannes Berg7194207c2011-01-04 16:22:00 -08001394 list_del(&wait_entry->list);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001395 spin_unlock_bh(&priv->notif_wait_lock);
Johannes Berg7194207c2011-01-04 16:22:00 -08001396
Johannes Berge74fe232011-04-13 03:14:49 -07001397 if (wait_entry->aborted)
1398 return -EIO;
1399
Johannes Berga8674a12011-04-13 03:14:48 -07001400 /* return value is always >= 0 */
1401 if (ret <= 0)
1402 return -ETIMEDOUT;
1403 return 0;
Johannes Berg7194207c2011-01-04 16:22:00 -08001404}
1405
1406void iwlagn_remove_notification(struct iwl_priv *priv,
1407 struct iwl_notification_wait *wait_entry)
1408{
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001409 spin_lock_bh(&priv->notif_wait_lock);
Johannes Berg7194207c2011-01-04 16:22:00 -08001410 list_del(&wait_entry->list);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001411 spin_unlock_bh(&priv->notif_wait_lock);
Johannes Berg7194207c2011-01-04 16:22:00 -08001412}