iwlwifi: fix locking in iwl_mac_add_interface
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / iwlwifi / iwl-core.c
blob02bf17ecaf54c15a17d34746bf07a1a43cec4ac4
1 /******************************************************************************
3 * GPL LICENSE SUMMARY
5 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
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.
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.
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
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
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 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/etherdevice.h>
32 #include <linux/sched.h>
33 #include <net/mac80211.h>
35 #include "iwl-eeprom.h"
36 #include "iwl-dev.h" /* FIXME: remove */
37 #include "iwl-debug.h"
38 #include "iwl-core.h"
39 #include "iwl-io.h"
40 #include "iwl-power.h"
41 #include "iwl-sta.h"
42 #include "iwl-helpers.h"
45 MODULE_DESCRIPTION("iwl core");
46 MODULE_VERSION(IWLWIFI_VERSION);
47 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
48 MODULE_LICENSE("GPL");
51 * set bt_coex_active to true, uCode will do kill/defer
52 * every time the priority line is asserted (BT is sending signals on the
53 * priority line in the PCIx).
54 * set bt_coex_active to false, uCode will ignore the BT activity and
55 * perform the normal operation
57 * User might experience transmit issue on some platform due to WiFi/BT
58 * co-exist problem. The possible behaviors are:
59 * Able to scan and finding all the available AP
60 * Not able to associate with any AP
61 * On those platforms, WiFi communication can be restored by set
62 * "bt_coex_active" module parameter to "false"
64 * default: bt_coex_active = true (BT_COEX_ENABLE)
66 static bool bt_coex_active = true;
67 module_param(bt_coex_active, bool, S_IRUGO);
68 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist\n");
70 static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
71 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
72 0, COEX_UNASSOC_IDLE_FLAGS},
73 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
74 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
75 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
76 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
77 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
78 0, COEX_CALIBRATION_FLAGS},
79 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
80 0, COEX_PERIODIC_CALIBRATION_FLAGS},
81 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
82 0, COEX_CONNECTION_ESTAB_FLAGS},
83 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
84 0, COEX_ASSOCIATED_IDLE_FLAGS},
85 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
86 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
87 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
88 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
89 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
90 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
91 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
92 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
93 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
94 0, COEX_STAND_ALONE_DEBUG_FLAGS},
95 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
96 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
97 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
98 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
101 #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
102 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
103 IWL_RATE_SISO_##s##M_PLCP, \
104 IWL_RATE_MIMO2_##s##M_PLCP,\
105 IWL_RATE_MIMO3_##s##M_PLCP,\
106 IWL_RATE_##r##M_IEEE, \
107 IWL_RATE_##ip##M_INDEX, \
108 IWL_RATE_##in##M_INDEX, \
109 IWL_RATE_##rp##M_INDEX, \
110 IWL_RATE_##rn##M_INDEX, \
111 IWL_RATE_##pp##M_INDEX, \
112 IWL_RATE_##np##M_INDEX }
114 u32 iwl_debug_level;
115 EXPORT_SYMBOL(iwl_debug_level);
117 static irqreturn_t iwl_isr(int irq, void *data);
120 * Parameter order:
121 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
123 * If there isn't a valid next or previous rate then INV is used which
124 * maps to IWL_RATE_INVALID
127 const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
128 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
129 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
130 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
131 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
132 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
133 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
134 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
135 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
136 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
137 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
138 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
139 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
140 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
141 /* FIXME:RS: ^^ should be INV (legacy) */
143 EXPORT_SYMBOL(iwl_rates);
146 * translate ucode response to mac80211 tx status control values
148 void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
149 struct ieee80211_tx_info *info)
151 struct ieee80211_tx_rate *r = &info->control.rates[0];
153 info->antenna_sel_tx =
154 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
155 if (rate_n_flags & RATE_MCS_HT_MSK)
156 r->flags |= IEEE80211_TX_RC_MCS;
157 if (rate_n_flags & RATE_MCS_GF_MSK)
158 r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
159 if (rate_n_flags & RATE_MCS_HT40_MSK)
160 r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
161 if (rate_n_flags & RATE_MCS_DUP_MSK)
162 r->flags |= IEEE80211_TX_RC_DUP_DATA;
163 if (rate_n_flags & RATE_MCS_SGI_MSK)
164 r->flags |= IEEE80211_TX_RC_SHORT_GI;
165 r->idx = iwl_hwrate_to_mac80211_idx(rate_n_flags, info->band);
167 EXPORT_SYMBOL(iwl_hwrate_to_tx_control);
169 int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
171 int idx = 0;
173 /* HT rate format */
174 if (rate_n_flags & RATE_MCS_HT_MSK) {
175 idx = (rate_n_flags & 0xff);
177 if (idx >= IWL_RATE_MIMO3_6M_PLCP)
178 idx = idx - IWL_RATE_MIMO3_6M_PLCP;
179 else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
180 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
182 idx += IWL_FIRST_OFDM_RATE;
183 /* skip 9M not supported in ht*/
184 if (idx >= IWL_RATE_9M_INDEX)
185 idx += 1;
186 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
187 return idx;
189 /* legacy rate format, search for match in table */
190 } else {
191 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
192 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
193 return idx;
196 return -1;
198 EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
200 int iwl_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
202 int idx = 0;
203 int band_offset = 0;
205 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
206 if (rate_n_flags & RATE_MCS_HT_MSK) {
207 idx = (rate_n_flags & 0xff);
208 return idx;
209 /* Legacy rate format, search for match in table */
210 } else {
211 if (band == IEEE80211_BAND_5GHZ)
212 band_offset = IWL_FIRST_OFDM_RATE;
213 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
214 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
215 return idx - band_offset;
218 return -1;
221 u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant)
223 int i;
224 u8 ind = ant;
225 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
226 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
227 if (priv->hw_params.valid_tx_ant & BIT(ind))
228 return ind;
230 return ant;
232 EXPORT_SYMBOL(iwl_toggle_tx_ant);
234 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
235 EXPORT_SYMBOL(iwl_bcast_addr);
238 /* This function both allocates and initializes hw and priv. */
239 struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
240 struct ieee80211_ops *hw_ops)
242 struct iwl_priv *priv;
244 /* mac80211 allocates memory for this device instance, including
245 * space for this driver's private structure */
246 struct ieee80211_hw *hw =
247 ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
248 if (hw == NULL) {
249 printk(KERN_ERR "%s: Can not allocate network device\n",
250 cfg->name);
251 goto out;
254 priv = hw->priv;
255 priv->hw = hw;
257 out:
258 return hw;
260 EXPORT_SYMBOL(iwl_alloc_all);
262 void iwl_hw_detect(struct iwl_priv *priv)
264 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
265 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
266 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
268 EXPORT_SYMBOL(iwl_hw_detect);
270 int iwl_hw_nic_init(struct iwl_priv *priv)
272 unsigned long flags;
273 struct iwl_rx_queue *rxq = &priv->rxq;
274 int ret;
276 /* nic_init */
277 spin_lock_irqsave(&priv->lock, flags);
278 priv->cfg->ops->lib->apm_ops.init(priv);
280 /* Set interrupt coalescing calibration timer to default (512 usecs) */
281 iwl_write8(priv, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
283 spin_unlock_irqrestore(&priv->lock, flags);
285 ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
287 priv->cfg->ops->lib->apm_ops.config(priv);
289 /* Allocate the RX queue, or reset if it is already allocated */
290 if (!rxq->bd) {
291 ret = iwl_rx_queue_alloc(priv);
292 if (ret) {
293 IWL_ERR(priv, "Unable to initialize Rx queue\n");
294 return -ENOMEM;
296 } else
297 iwl_rx_queue_reset(priv, rxq);
299 iwl_rx_replenish(priv);
301 iwl_rx_init(priv, rxq);
303 spin_lock_irqsave(&priv->lock, flags);
305 rxq->need_update = 1;
306 iwl_rx_queue_update_write_ptr(priv, rxq);
308 spin_unlock_irqrestore(&priv->lock, flags);
310 /* Allocate and init all Tx and Command queues */
311 ret = iwl_txq_ctx_reset(priv);
312 if (ret)
313 return ret;
315 set_bit(STATUS_INIT, &priv->status);
317 return 0;
319 EXPORT_SYMBOL(iwl_hw_nic_init);
322 * QoS support
324 void iwl_activate_qos(struct iwl_priv *priv, u8 force)
326 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
327 return;
329 priv->qos_data.def_qos_parm.qos_flags = 0;
331 if (priv->qos_data.qos_cap.q_AP.queue_request &&
332 !priv->qos_data.qos_cap.q_AP.txop_request)
333 priv->qos_data.def_qos_parm.qos_flags |=
334 QOS_PARAM_FLG_TXOP_TYPE_MSK;
335 if (priv->qos_data.qos_active)
336 priv->qos_data.def_qos_parm.qos_flags |=
337 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
339 if (priv->current_ht_config.is_ht)
340 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
342 if (force || iwl_is_associated(priv)) {
343 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
344 priv->qos_data.qos_active,
345 priv->qos_data.def_qos_parm.qos_flags);
347 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
348 sizeof(struct iwl_qosparam_cmd),
349 &priv->qos_data.def_qos_parm, NULL);
352 EXPORT_SYMBOL(iwl_activate_qos);
355 * AC CWmin CW max AIFSN TXOP Limit TXOP Limit
356 * (802.11b) (802.11a/g)
357 * AC_BK 15 1023 7 0 0
358 * AC_BE 15 1023 3 0 0
359 * AC_VI 7 15 2 6.016ms 3.008ms
360 * AC_VO 3 7 2 3.264ms 1.504ms
362 void iwl_reset_qos(struct iwl_priv *priv)
364 u16 cw_min = 15;
365 u16 cw_max = 1023;
366 u8 aifs = 2;
367 bool is_legacy = false;
368 unsigned long flags;
369 int i;
371 spin_lock_irqsave(&priv->lock, flags);
372 /* QoS always active in AP and ADHOC mode
373 * In STA mode wait for association
375 if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
376 priv->iw_mode == NL80211_IFTYPE_AP)
377 priv->qos_data.qos_active = 1;
378 else
379 priv->qos_data.qos_active = 0;
381 /* check for legacy mode */
382 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC &&
383 (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) ||
384 (priv->iw_mode == NL80211_IFTYPE_STATION &&
385 (priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) {
386 cw_min = 31;
387 is_legacy = 1;
390 if (priv->qos_data.qos_active)
391 aifs = 3;
393 /* AC_BE */
394 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
395 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
396 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
397 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
398 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
400 if (priv->qos_data.qos_active) {
401 /* AC_BK */
402 i = 1;
403 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
404 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
405 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
406 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
407 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
409 /* AC_VI */
410 i = 2;
411 priv->qos_data.def_qos_parm.ac[i].cw_min =
412 cpu_to_le16((cw_min + 1) / 2 - 1);
413 priv->qos_data.def_qos_parm.ac[i].cw_max =
414 cpu_to_le16(cw_min);
415 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
416 if (is_legacy)
417 priv->qos_data.def_qos_parm.ac[i].edca_txop =
418 cpu_to_le16(6016);
419 else
420 priv->qos_data.def_qos_parm.ac[i].edca_txop =
421 cpu_to_le16(3008);
422 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
424 /* AC_VO */
425 i = 3;
426 priv->qos_data.def_qos_parm.ac[i].cw_min =
427 cpu_to_le16((cw_min + 1) / 4 - 1);
428 priv->qos_data.def_qos_parm.ac[i].cw_max =
429 cpu_to_le16((cw_min + 1) / 2 - 1);
430 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
431 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
432 if (is_legacy)
433 priv->qos_data.def_qos_parm.ac[i].edca_txop =
434 cpu_to_le16(3264);
435 else
436 priv->qos_data.def_qos_parm.ac[i].edca_txop =
437 cpu_to_le16(1504);
438 } else {
439 for (i = 1; i < 4; i++) {
440 priv->qos_data.def_qos_parm.ac[i].cw_min =
441 cpu_to_le16(cw_min);
442 priv->qos_data.def_qos_parm.ac[i].cw_max =
443 cpu_to_le16(cw_max);
444 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
445 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
446 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
449 IWL_DEBUG_QOS(priv, "set QoS to default \n");
451 spin_unlock_irqrestore(&priv->lock, flags);
453 EXPORT_SYMBOL(iwl_reset_qos);
455 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
456 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
457 static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
458 struct ieee80211_sta_ht_cap *ht_info,
459 enum ieee80211_band band)
461 u16 max_bit_rate = 0;
462 u8 rx_chains_num = priv->hw_params.rx_chains_num;
463 u8 tx_chains_num = priv->hw_params.tx_chains_num;
465 ht_info->cap = 0;
466 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
468 ht_info->ht_supported = true;
470 if (priv->cfg->ht_greenfield_support)
471 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
472 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
473 max_bit_rate = MAX_BIT_RATE_20_MHZ;
474 if (priv->hw_params.ht40_channel & BIT(band)) {
475 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
476 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
477 ht_info->mcs.rx_mask[4] = 0x01;
478 max_bit_rate = MAX_BIT_RATE_40_MHZ;
481 if (priv->cfg->mod_params->amsdu_size_8K)
482 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
484 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
485 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
487 ht_info->mcs.rx_mask[0] = 0xFF;
488 if (rx_chains_num >= 2)
489 ht_info->mcs.rx_mask[1] = 0xFF;
490 if (rx_chains_num >= 3)
491 ht_info->mcs.rx_mask[2] = 0xFF;
493 /* Highest supported Rx data rate */
494 max_bit_rate *= rx_chains_num;
495 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
496 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
498 /* Tx MCS capabilities */
499 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
500 if (tx_chains_num != rx_chains_num) {
501 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
502 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
503 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
508 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
510 int iwlcore_init_geos(struct iwl_priv *priv)
512 struct iwl_channel_info *ch;
513 struct ieee80211_supported_band *sband;
514 struct ieee80211_channel *channels;
515 struct ieee80211_channel *geo_ch;
516 struct ieee80211_rate *rates;
517 int i = 0;
519 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
520 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
521 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
522 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
523 return 0;
526 channels = kzalloc(sizeof(struct ieee80211_channel) *
527 priv->channel_count, GFP_KERNEL);
528 if (!channels)
529 return -ENOMEM;
531 rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
532 GFP_KERNEL);
533 if (!rates) {
534 kfree(channels);
535 return -ENOMEM;
538 /* 5.2GHz channels start after the 2.4GHz channels */
539 sband = &priv->bands[IEEE80211_BAND_5GHZ];
540 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
541 /* just OFDM */
542 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
543 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
545 if (priv->cfg->sku & IWL_SKU_N)
546 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
547 IEEE80211_BAND_5GHZ);
549 sband = &priv->bands[IEEE80211_BAND_2GHZ];
550 sband->channels = channels;
551 /* OFDM & CCK */
552 sband->bitrates = rates;
553 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
555 if (priv->cfg->sku & IWL_SKU_N)
556 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
557 IEEE80211_BAND_2GHZ);
559 priv->ieee_channels = channels;
560 priv->ieee_rates = rates;
562 for (i = 0; i < priv->channel_count; i++) {
563 ch = &priv->channel_info[i];
565 /* FIXME: might be removed if scan is OK */
566 if (!is_channel_valid(ch))
567 continue;
569 if (is_channel_a_band(ch))
570 sband = &priv->bands[IEEE80211_BAND_5GHZ];
571 else
572 sband = &priv->bands[IEEE80211_BAND_2GHZ];
574 geo_ch = &sband->channels[sband->n_channels++];
576 geo_ch->center_freq =
577 ieee80211_channel_to_frequency(ch->channel);
578 geo_ch->max_power = ch->max_power_avg;
579 geo_ch->max_antenna_gain = 0xff;
580 geo_ch->hw_value = ch->channel;
582 if (is_channel_valid(ch)) {
583 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
584 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
586 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
587 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
589 if (ch->flags & EEPROM_CHANNEL_RADAR)
590 geo_ch->flags |= IEEE80211_CHAN_RADAR;
592 geo_ch->flags |= ch->ht40_extension_channel;
594 if (ch->max_power_avg > priv->tx_power_device_lmt)
595 priv->tx_power_device_lmt = ch->max_power_avg;
596 } else {
597 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
600 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
601 ch->channel, geo_ch->center_freq,
602 is_channel_a_band(ch) ? "5.2" : "2.4",
603 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
604 "restricted" : "valid",
605 geo_ch->flags);
608 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
609 priv->cfg->sku & IWL_SKU_A) {
610 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
611 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
612 priv->pci_dev->device,
613 priv->pci_dev->subsystem_device);
614 priv->cfg->sku &= ~IWL_SKU_A;
617 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
618 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
619 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
621 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
623 return 0;
625 EXPORT_SYMBOL(iwlcore_init_geos);
628 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
630 void iwlcore_free_geos(struct iwl_priv *priv)
632 kfree(priv->ieee_channels);
633 kfree(priv->ieee_rates);
634 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
636 EXPORT_SYMBOL(iwlcore_free_geos);
639 * iwlcore_rts_tx_cmd_flag: Set rts/cts. 3945 and 4965 only share this
640 * function.
642 void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
643 __le32 *tx_flags)
645 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
646 *tx_flags |= TX_CMD_FLG_RTS_MSK;
647 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
648 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
649 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
650 *tx_flags |= TX_CMD_FLG_CTS_MSK;
653 EXPORT_SYMBOL(iwlcore_rts_tx_cmd_flag);
655 static bool is_single_rx_stream(struct iwl_priv *priv)
657 return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
658 priv->current_ht_config.single_chain_sufficient;
661 static u8 iwl_is_channel_extension(struct iwl_priv *priv,
662 enum ieee80211_band band,
663 u16 channel, u8 extension_chan_offset)
665 const struct iwl_channel_info *ch_info;
667 ch_info = iwl_get_channel_info(priv, band, channel);
668 if (!is_channel_valid(ch_info))
669 return 0;
671 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
672 return !(ch_info->ht40_extension_channel &
673 IEEE80211_CHAN_NO_HT40PLUS);
674 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
675 return !(ch_info->ht40_extension_channel &
676 IEEE80211_CHAN_NO_HT40MINUS);
678 return 0;
681 u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
682 struct ieee80211_sta_ht_cap *sta_ht_inf)
684 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
686 if (!ht_conf->is_ht || !ht_conf->is_40mhz)
687 return 0;
689 /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
690 * the bit will not set if it is pure 40MHz case
692 if (sta_ht_inf) {
693 if (!sta_ht_inf->ht_supported)
694 return 0;
696 #ifdef CONFIG_IWLWIFI_DEBUG
697 if (priv->disable_ht40)
698 return 0;
699 #endif
700 return iwl_is_channel_extension(priv, priv->band,
701 le16_to_cpu(priv->staging_rxon.channel),
702 ht_conf->extension_chan_offset);
704 EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
706 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
708 u16 new_val = 0;
709 u16 beacon_factor = 0;
711 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
712 new_val = beacon_val / beacon_factor;
714 if (!new_val)
715 new_val = max_beacon_val;
717 return new_val;
720 void iwl_setup_rxon_timing(struct iwl_priv *priv)
722 u64 tsf;
723 s32 interval_tm, rem;
724 unsigned long flags;
725 struct ieee80211_conf *conf = NULL;
726 u16 beacon_int;
728 conf = ieee80211_get_hw_conf(priv->hw);
730 spin_lock_irqsave(&priv->lock, flags);
731 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
732 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
734 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
735 beacon_int = priv->beacon_int;
736 priv->rxon_timing.atim_window = 0;
737 } else {
738 beacon_int = priv->vif->bss_conf.beacon_int;
740 /* TODO: we need to get atim_window from upper stack
741 * for now we set to 0 */
742 priv->rxon_timing.atim_window = 0;
745 beacon_int = iwl_adjust_beacon_interval(beacon_int,
746 priv->hw_params.max_beacon_itrvl * 1024);
747 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
749 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
750 interval_tm = beacon_int * 1024;
751 rem = do_div(tsf, interval_tm);
752 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
754 spin_unlock_irqrestore(&priv->lock, flags);
755 IWL_DEBUG_ASSOC(priv,
756 "beacon interval %d beacon timer %d beacon tim %d\n",
757 le16_to_cpu(priv->rxon_timing.beacon_interval),
758 le32_to_cpu(priv->rxon_timing.beacon_init_val),
759 le16_to_cpu(priv->rxon_timing.atim_window));
761 EXPORT_SYMBOL(iwl_setup_rxon_timing);
763 void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
765 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
767 if (hw_decrypt)
768 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
769 else
770 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
773 EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
776 * iwl_check_rxon_cmd - validate RXON structure is valid
778 * NOTE: This is really only useful during development and can eventually
779 * be #ifdef'd out once the driver is stable and folks aren't actively
780 * making changes
782 int iwl_check_rxon_cmd(struct iwl_priv *priv)
784 int error = 0;
785 int counter = 1;
786 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
788 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
789 error |= le32_to_cpu(rxon->flags &
790 (RXON_FLG_TGJ_NARROW_BAND_MSK |
791 RXON_FLG_RADAR_DETECT_MSK));
792 if (error)
793 IWL_WARN(priv, "check 24G fields %d | %d\n",
794 counter++, error);
795 } else {
796 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
797 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
798 if (error)
799 IWL_WARN(priv, "check 52 fields %d | %d\n",
800 counter++, error);
801 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
802 if (error)
803 IWL_WARN(priv, "check 52 CCK %d | %d\n",
804 counter++, error);
806 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
807 if (error)
808 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
810 /* make sure basic rates 6Mbps and 1Mbps are supported */
811 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
812 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
813 if (error)
814 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
816 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
817 if (error)
818 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
820 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
821 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
822 if (error)
823 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
824 counter++, error);
826 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
827 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
828 if (error)
829 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
830 counter++, error);
832 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
833 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
834 if (error)
835 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
836 counter++, error);
838 if (error)
839 IWL_WARN(priv, "Tuning to channel %d\n",
840 le16_to_cpu(rxon->channel));
842 if (error) {
843 IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
844 return -1;
846 return 0;
848 EXPORT_SYMBOL(iwl_check_rxon_cmd);
851 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
852 * @priv: staging_rxon is compared to active_rxon
854 * If the RXON structure is changing enough to require a new tune,
855 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
856 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
858 int iwl_full_rxon_required(struct iwl_priv *priv)
861 /* These items are only settable from the full RXON command */
862 if (!(iwl_is_associated(priv)) ||
863 compare_ether_addr(priv->staging_rxon.bssid_addr,
864 priv->active_rxon.bssid_addr) ||
865 compare_ether_addr(priv->staging_rxon.node_addr,
866 priv->active_rxon.node_addr) ||
867 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
868 priv->active_rxon.wlap_bssid_addr) ||
869 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
870 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
871 (priv->staging_rxon.air_propagation !=
872 priv->active_rxon.air_propagation) ||
873 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
874 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
875 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
876 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
877 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
878 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
879 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
880 return 1;
882 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
883 * be updated with the RXON_ASSOC command -- however only some
884 * flag transitions are allowed using RXON_ASSOC */
886 /* Check if we are not switching bands */
887 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
888 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
889 return 1;
891 /* Check if we are switching association toggle */
892 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
893 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
894 return 1;
896 return 0;
898 EXPORT_SYMBOL(iwl_full_rxon_required);
900 u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
902 int i;
903 int rate_mask;
905 /* Set rate mask*/
906 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
907 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
908 else
909 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
911 /* Find lowest valid rate */
912 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
913 i = iwl_rates[i].next_ieee) {
914 if (rate_mask & (1 << i))
915 return iwl_rates[i].plcp;
918 /* No valid rate was found. Assign the lowest one */
919 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
920 return IWL_RATE_1M_PLCP;
921 else
922 return IWL_RATE_6M_PLCP;
924 EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
926 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
928 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
930 if (!ht_conf->is_ht) {
931 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
932 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
933 RXON_FLG_HT40_PROT_MSK |
934 RXON_FLG_HT_PROT_MSK);
935 return;
938 /* FIXME: if the definition of ht_protection changed, the "translation"
939 * will be needed for rxon->flags
941 rxon->flags |= cpu_to_le32(ht_conf->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
943 /* Set up channel bandwidth:
944 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
945 /* clear the HT channel mode before set the mode */
946 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
947 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
948 if (iwl_is_ht40_tx_allowed(priv, NULL)) {
949 /* pure ht40 */
950 if (ht_conf->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
951 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
952 /* Note: control channel is opposite of extension channel */
953 switch (ht_conf->extension_chan_offset) {
954 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
955 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
956 break;
957 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
958 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
959 break;
961 } else {
962 /* Note: control channel is opposite of extension channel */
963 switch (ht_conf->extension_chan_offset) {
964 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
965 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
966 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
967 break;
968 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
969 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
970 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
971 break;
972 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
973 default:
974 /* channel location only valid if in Mixed mode */
975 IWL_ERR(priv, "invalid extension channel offset\n");
976 break;
979 } else {
980 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
983 if (priv->cfg->ops->hcmd->set_rxon_chain)
984 priv->cfg->ops->hcmd->set_rxon_chain(priv);
986 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
987 "extension channel offset 0x%x\n",
988 le32_to_cpu(rxon->flags), ht_conf->ht_protection,
989 ht_conf->extension_chan_offset);
990 return;
992 EXPORT_SYMBOL(iwl_set_rxon_ht);
994 #define IWL_NUM_RX_CHAINS_MULTIPLE 3
995 #define IWL_NUM_RX_CHAINS_SINGLE 2
996 #define IWL_NUM_IDLE_CHAINS_DUAL 2
997 #define IWL_NUM_IDLE_CHAINS_SINGLE 1
1000 * Determine how many receiver/antenna chains to use.
1002 * More provides better reception via diversity. Fewer saves power
1003 * at the expense of throughput, but only when not in powersave to
1004 * start with.
1006 * MIMO (dual stream) requires at least 2, but works better with 3.
1007 * This does not determine *which* chains to use, just how many.
1009 static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
1011 /* # of Rx chains to use when expecting MIMO. */
1012 if (is_single_rx_stream(priv))
1013 return IWL_NUM_RX_CHAINS_SINGLE;
1014 else
1015 return IWL_NUM_RX_CHAINS_MULTIPLE;
1019 * When we are in power saving mode, unless device support spatial
1020 * multiplexing power save, use the active count for rx chain count.
1022 static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
1024 /* # Rx chains when idling, depending on SMPS mode */
1025 switch (priv->current_ht_config.smps) {
1026 case IEEE80211_SMPS_STATIC:
1027 case IEEE80211_SMPS_DYNAMIC:
1028 return IWL_NUM_IDLE_CHAINS_SINGLE;
1029 case IEEE80211_SMPS_OFF:
1030 return active_cnt;
1031 default:
1032 WARN(1, "invalid SMPS mode %d",
1033 priv->current_ht_config.smps);
1034 return active_cnt;
1038 /* up to 4 chains */
1039 static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
1041 u8 res;
1042 res = (chain_bitmap & BIT(0)) >> 0;
1043 res += (chain_bitmap & BIT(1)) >> 1;
1044 res += (chain_bitmap & BIT(2)) >> 2;
1045 res += (chain_bitmap & BIT(3)) >> 3;
1046 return res;
1050 * iwl_is_monitor_mode - Determine if interface in monitor mode
1052 * priv->iw_mode is set in add_interface, but add_interface is
1053 * never called for monitor mode. The only way mac80211 informs us about
1054 * monitor mode is through configuring filters (call to configure_filter).
1056 bool iwl_is_monitor_mode(struct iwl_priv *priv)
1058 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
1060 EXPORT_SYMBOL(iwl_is_monitor_mode);
1063 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
1065 * Selects how many and which Rx receivers/antennas/chains to use.
1066 * This should not be used for scan command ... it puts data in wrong place.
1068 void iwl_set_rxon_chain(struct iwl_priv *priv)
1070 bool is_single = is_single_rx_stream(priv);
1071 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
1072 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
1073 u32 active_chains;
1074 u16 rx_chain;
1076 /* Tell uCode which antennas are actually connected.
1077 * Before first association, we assume all antennas are connected.
1078 * Just after first association, iwl_chain_noise_calibration()
1079 * checks which antennas actually *are* connected. */
1080 if (priv->chain_noise_data.active_chains)
1081 active_chains = priv->chain_noise_data.active_chains;
1082 else
1083 active_chains = priv->hw_params.valid_rx_ant;
1085 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
1087 /* How many receivers should we use? */
1088 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
1089 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
1092 /* correct rx chain count according hw settings
1093 * and chain noise calibration
1095 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
1096 if (valid_rx_cnt < active_rx_cnt)
1097 active_rx_cnt = valid_rx_cnt;
1099 if (valid_rx_cnt < idle_rx_cnt)
1100 idle_rx_cnt = valid_rx_cnt;
1102 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
1103 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
1105 /* copied from 'iwl_bg_request_scan()' */
1106 /* Force use of chains B and C (0x6) for Rx for 4965
1107 * Avoid A (0x1) because of its off-channel reception on A-band.
1108 * MIMO is not used here, but value is required */
1109 if (iwl_is_monitor_mode(priv) &&
1110 !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) &&
1111 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) {
1112 rx_chain = ANT_ABC << RXON_RX_CHAIN_VALID_POS;
1113 rx_chain |= ANT_BC << RXON_RX_CHAIN_FORCE_SEL_POS;
1114 rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
1115 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
1118 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
1120 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
1121 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
1122 else
1123 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
1125 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
1126 priv->staging_rxon.rx_chain,
1127 active_rx_cnt, idle_rx_cnt);
1129 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
1130 active_rx_cnt < idle_rx_cnt);
1132 EXPORT_SYMBOL(iwl_set_rxon_chain);
1135 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
1136 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
1137 * @channel: Any channel valid for the requested phymode
1139 * In addition to setting the staging RXON, priv->phymode is also set.
1141 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
1142 * in the staging RXON flag structure based on the phymode
1144 int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
1146 enum ieee80211_band band = ch->band;
1147 u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
1149 if (!iwl_get_channel_info(priv, band, channel)) {
1150 IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
1151 channel, band);
1152 return -EINVAL;
1155 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
1156 (priv->band == band))
1157 return 0;
1159 priv->staging_rxon.channel = cpu_to_le16(channel);
1160 if (band == IEEE80211_BAND_5GHZ)
1161 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
1162 else
1163 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1165 priv->band = band;
1167 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
1169 return 0;
1171 EXPORT_SYMBOL(iwl_set_rxon_channel);
1173 void iwl_set_flags_for_band(struct iwl_priv *priv,
1174 enum ieee80211_band band)
1176 if (band == IEEE80211_BAND_5GHZ) {
1177 priv->staging_rxon.flags &=
1178 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1179 | RXON_FLG_CCK_MSK);
1180 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1181 } else {
1182 /* Copied from iwl_post_associate() */
1183 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1184 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1185 else
1186 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1188 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
1189 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1191 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1192 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1193 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
1198 * initialize rxon structure with default values from eeprom
1200 void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1202 const struct iwl_channel_info *ch_info;
1204 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
1206 switch (mode) {
1207 case NL80211_IFTYPE_AP:
1208 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
1209 break;
1211 case NL80211_IFTYPE_STATION:
1212 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
1213 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1214 break;
1216 case NL80211_IFTYPE_ADHOC:
1217 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1218 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1219 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1220 RXON_FILTER_ACCEPT_GRP_MSK;
1221 break;
1223 default:
1224 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
1225 break;
1228 #if 0
1229 /* TODO: Figure out when short_preamble would be set and cache from
1230 * that */
1231 if (!hw_to_local(priv->hw)->short_preamble)
1232 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1233 else
1234 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1235 #endif
1237 ch_info = iwl_get_channel_info(priv, priv->band,
1238 le16_to_cpu(priv->active_rxon.channel));
1240 if (!ch_info)
1241 ch_info = &priv->channel_info[0];
1244 * in some case A channels are all non IBSS
1245 * in this case force B/G channel
1247 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
1248 !(is_channel_ibss(ch_info)))
1249 ch_info = &priv->channel_info[0];
1251 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
1252 priv->band = ch_info->band;
1254 iwl_set_flags_for_band(priv, priv->band);
1256 priv->staging_rxon.ofdm_basic_rates =
1257 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1258 priv->staging_rxon.cck_basic_rates =
1259 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1261 /* clear both MIX and PURE40 mode flag */
1262 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
1263 RXON_FLG_CHANNEL_MODE_PURE_40);
1264 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1265 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1266 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1267 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1268 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
1270 EXPORT_SYMBOL(iwl_connection_init_rx_config);
1272 static void iwl_set_rate(struct iwl_priv *priv)
1274 const struct ieee80211_supported_band *hw = NULL;
1275 struct ieee80211_rate *rate;
1276 int i;
1278 hw = iwl_get_hw_mode(priv, priv->band);
1279 if (!hw) {
1280 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
1281 return;
1284 priv->active_rate = 0;
1285 priv->active_rate_basic = 0;
1287 for (i = 0; i < hw->n_bitrates; i++) {
1288 rate = &(hw->bitrates[i]);
1289 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
1290 priv->active_rate |= (1 << rate->hw_value);
1293 IWL_DEBUG_RATE(priv, "Set active_rate = %0x, active_rate_basic = %0x\n",
1294 priv->active_rate, priv->active_rate_basic);
1297 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1298 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1299 * OFDM
1301 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
1302 priv->staging_rxon.cck_basic_rates =
1303 ((priv->active_rate_basic &
1304 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
1305 else
1306 priv->staging_rxon.cck_basic_rates =
1307 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1309 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
1310 priv->staging_rxon.ofdm_basic_rates =
1311 ((priv->active_rate_basic &
1312 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
1313 IWL_FIRST_OFDM_RATE) & 0xFF;
1314 else
1315 priv->staging_rxon.ofdm_basic_rates =
1316 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1319 void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1321 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1322 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1323 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
1325 if (priv->switch_rxon.switch_in_progress) {
1326 if (!le32_to_cpu(csa->status) &&
1327 (csa->channel == priv->switch_rxon.channel)) {
1328 rxon->channel = csa->channel;
1329 priv->staging_rxon.channel = csa->channel;
1330 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
1331 le16_to_cpu(csa->channel));
1332 } else
1333 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
1334 le16_to_cpu(csa->channel));
1336 priv->switch_rxon.switch_in_progress = false;
1339 EXPORT_SYMBOL(iwl_rx_csa);
1341 #ifdef CONFIG_IWLWIFI_DEBUG
1342 void iwl_print_rx_config_cmd(struct iwl_priv *priv)
1344 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1346 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
1347 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
1348 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1349 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1350 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
1351 le32_to_cpu(rxon->filter_flags));
1352 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
1353 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
1354 rxon->ofdm_basic_rates);
1355 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1356 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
1357 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
1358 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1360 EXPORT_SYMBOL(iwl_print_rx_config_cmd);
1361 #endif
1363 * iwl_irq_handle_error - called for HW or SW error interrupt from card
1365 void iwl_irq_handle_error(struct iwl_priv *priv)
1367 /* Set the FW error flag -- cleared on iwl_down */
1368 set_bit(STATUS_FW_ERROR, &priv->status);
1370 /* Cancel currently queued command. */
1371 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1373 priv->cfg->ops->lib->dump_nic_error_log(priv);
1374 if (priv->cfg->ops->lib->dump_csr)
1375 priv->cfg->ops->lib->dump_csr(priv);
1376 if (priv->cfg->ops->lib->dump_fh)
1377 priv->cfg->ops->lib->dump_fh(priv, NULL, false);
1378 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
1379 #ifdef CONFIG_IWLWIFI_DEBUG
1380 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
1381 iwl_print_rx_config_cmd(priv);
1382 #endif
1384 wake_up_interruptible(&priv->wait_command_queue);
1386 /* Keep the restart process from trying to send host
1387 * commands by clearing the INIT status bit */
1388 clear_bit(STATUS_READY, &priv->status);
1390 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1391 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
1392 "Restarting adapter due to uCode error.\n");
1394 if (priv->cfg->mod_params->restart_fw)
1395 queue_work(priv->workqueue, &priv->restart);
1398 EXPORT_SYMBOL(iwl_irq_handle_error);
1400 int iwl_apm_stop_master(struct iwl_priv *priv)
1402 int ret = 0;
1404 /* stop device's busmaster DMA activity */
1405 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1407 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
1408 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
1409 if (ret)
1410 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
1412 IWL_DEBUG_INFO(priv, "stop master\n");
1414 return ret;
1416 EXPORT_SYMBOL(iwl_apm_stop_master);
1418 void iwl_apm_stop(struct iwl_priv *priv)
1420 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1422 /* Stop device's DMA activity */
1423 iwl_apm_stop_master(priv);
1425 /* Reset the entire device */
1426 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1428 udelay(10);
1431 * Clear "initialization complete" bit to move adapter from
1432 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1434 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1436 EXPORT_SYMBOL(iwl_apm_stop);
1440 * Start up NIC's basic functionality after it has been reset
1441 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1442 * NOTE: This does not load uCode nor start the embedded processor
1444 int iwl_apm_init(struct iwl_priv *priv)
1446 int ret = 0;
1447 u16 lctl;
1449 IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
1452 * Use "set_bit" below rather than "write", to preserve any hardware
1453 * bits already set by default after reset.
1456 /* Disable L0S exit timer (platform NMI Work/Around) */
1457 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1458 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1461 * Disable L0s without affecting L1;
1462 * don't wait for ICH L0s (ICH bug W/A)
1464 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1465 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1467 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1468 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
1471 * Enable HAP INTA (interrupt from management bus) to
1472 * wake device's PCI Express link L1a -> L0s
1473 * NOTE: This is no-op for 3945 (non-existant bit)
1475 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1476 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1479 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1480 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1481 * If so (likely), disable L0S, so device moves directly L0->L1;
1482 * costs negligible amount of power savings.
1483 * If not (unlikely), enable L0S, so there is at least some
1484 * power savings, even without L1.
1486 if (priv->cfg->set_l0s) {
1487 lctl = iwl_pcie_link_ctl(priv);
1488 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1489 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1490 /* L1-ASPM enabled; disable(!) L0S */
1491 iwl_set_bit(priv, CSR_GIO_REG,
1492 CSR_GIO_REG_VAL_L0S_ENABLED);
1493 IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
1494 } else {
1495 /* L1-ASPM disabled; enable(!) L0S */
1496 iwl_clear_bit(priv, CSR_GIO_REG,
1497 CSR_GIO_REG_VAL_L0S_ENABLED);
1498 IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
1502 /* Configure analog phase-lock-loop before activating to D0A */
1503 if (priv->cfg->pll_cfg_val)
1504 iwl_set_bit(priv, CSR_ANA_PLL_CFG, priv->cfg->pll_cfg_val);
1507 * Set "initialization complete" bit to move adapter from
1508 * D0U* --> D0A* (powered-up active) state.
1510 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1513 * Wait for clock stabilization; once stabilized, access to
1514 * device-internal resources is supported, e.g. iwl_write_prph()
1515 * and accesses to uCode SRAM.
1517 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
1518 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1519 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1520 if (ret < 0) {
1521 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
1522 goto out;
1526 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1527 * BSM (Boostrap State Machine) is only in 3945 and 4965;
1528 * later devices (i.e. 5000 and later) have non-volatile SRAM,
1529 * and don't need BSM to restore data after power-saving sleep.
1531 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1532 * do not disable clocks. This preserves any hardware bits already
1533 * set by default in "CLK_CTRL_REG" after reset.
1535 if (priv->cfg->use_bsm)
1536 iwl_write_prph(priv, APMG_CLK_EN_REG,
1537 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1538 else
1539 iwl_write_prph(priv, APMG_CLK_EN_REG,
1540 APMG_CLK_VAL_DMA_CLK_RQT);
1541 udelay(20);
1543 /* Disable L1-Active */
1544 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1545 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1547 out:
1548 return ret;
1550 EXPORT_SYMBOL(iwl_apm_init);
1554 void iwl_configure_filter(struct ieee80211_hw *hw,
1555 unsigned int changed_flags,
1556 unsigned int *total_flags,
1557 u64 multicast)
1559 struct iwl_priv *priv = hw->priv;
1560 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
1562 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
1563 changed_flags, *total_flags);
1565 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
1566 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
1567 *filter_flags |= RXON_FILTER_PROMISC_MSK;
1568 else
1569 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
1571 if (changed_flags & FIF_ALLMULTI) {
1572 if (*total_flags & FIF_ALLMULTI)
1573 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
1574 else
1575 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
1577 if (changed_flags & FIF_CONTROL) {
1578 if (*total_flags & FIF_CONTROL)
1579 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
1580 else
1581 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
1583 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
1584 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
1585 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1586 else
1587 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
1590 /* We avoid iwl_commit_rxon here to commit the new filter flags
1591 * since mac80211 will call ieee80211_hw_config immediately.
1592 * (mc_list is not supported at this time). Otherwise, we need to
1593 * queue a background iwl_commit_rxon work.
1596 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
1597 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
1599 EXPORT_SYMBOL(iwl_configure_filter);
1601 int iwl_set_hw_params(struct iwl_priv *priv)
1603 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1604 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1605 if (priv->cfg->mod_params->amsdu_size_8K)
1606 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
1607 else
1608 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
1610 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
1612 if (priv->cfg->mod_params->disable_11n)
1613 priv->cfg->sku &= ~IWL_SKU_N;
1615 /* Device-specific setup */
1616 return priv->cfg->ops->lib->set_hw_params(priv);
1618 EXPORT_SYMBOL(iwl_set_hw_params);
1620 int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1622 int ret = 0;
1623 s8 prev_tx_power = priv->tx_power_user_lmt;
1625 if (tx_power < IWL_TX_POWER_TARGET_POWER_MIN) {
1626 IWL_WARN(priv, "Requested user TXPOWER %d below lower limit %d.\n",
1627 tx_power,
1628 IWL_TX_POWER_TARGET_POWER_MIN);
1629 return -EINVAL;
1632 if (tx_power > priv->tx_power_device_lmt) {
1633 IWL_WARN(priv,
1634 "Requested user TXPOWER %d above upper limit %d.\n",
1635 tx_power, priv->tx_power_device_lmt);
1636 return -EINVAL;
1639 if (priv->tx_power_user_lmt != tx_power)
1640 force = true;
1642 /* if nic is not up don't send command */
1643 if (iwl_is_ready_rf(priv)) {
1644 priv->tx_power_user_lmt = tx_power;
1645 if (force && priv->cfg->ops->lib->send_tx_power)
1646 ret = priv->cfg->ops->lib->send_tx_power(priv);
1647 else if (!priv->cfg->ops->lib->send_tx_power)
1648 ret = -EOPNOTSUPP;
1650 * if fail to set tx_power, restore the orig. tx power
1652 if (ret)
1653 priv->tx_power_user_lmt = prev_tx_power;
1657 * Even this is an async host command, the command
1658 * will always report success from uCode
1659 * So once driver can placing the command into the queue
1660 * successfully, driver can use priv->tx_power_user_lmt
1661 * to reflect the current tx power
1663 return ret;
1665 EXPORT_SYMBOL(iwl_set_tx_power);
1667 #define ICT_COUNT (PAGE_SIZE/sizeof(u32))
1669 /* Free dram table */
1670 void iwl_free_isr_ict(struct iwl_priv *priv)
1672 if (priv->ict_tbl_vir) {
1673 pci_free_consistent(priv->pci_dev, (sizeof(u32) * ICT_COUNT) +
1674 PAGE_SIZE, priv->ict_tbl_vir,
1675 priv->ict_tbl_dma);
1676 priv->ict_tbl_vir = NULL;
1679 EXPORT_SYMBOL(iwl_free_isr_ict);
1682 /* allocate dram shared table it is a PAGE_SIZE aligned
1683 * also reset all data related to ICT table interrupt.
1685 int iwl_alloc_isr_ict(struct iwl_priv *priv)
1688 if (priv->cfg->use_isr_legacy)
1689 return 0;
1690 /* allocate shrared data table */
1691 priv->ict_tbl_vir = pci_alloc_consistent(priv->pci_dev, (sizeof(u32) *
1692 ICT_COUNT) + PAGE_SIZE,
1693 &priv->ict_tbl_dma);
1694 if (!priv->ict_tbl_vir)
1695 return -ENOMEM;
1697 /* align table to PAGE_SIZE boundry */
1698 priv->aligned_ict_tbl_dma = ALIGN(priv->ict_tbl_dma, PAGE_SIZE);
1700 IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
1701 (unsigned long long)priv->ict_tbl_dma,
1702 (unsigned long long)priv->aligned_ict_tbl_dma,
1703 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1705 priv->ict_tbl = priv->ict_tbl_vir +
1706 (priv->aligned_ict_tbl_dma - priv->ict_tbl_dma);
1708 IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
1709 priv->ict_tbl, priv->ict_tbl_vir,
1710 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1712 /* reset table and index to all 0 */
1713 memset(priv->ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
1714 priv->ict_index = 0;
1716 /* add periodic RX interrupt */
1717 priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
1718 return 0;
1720 EXPORT_SYMBOL(iwl_alloc_isr_ict);
1722 /* Device is going up inform it about using ICT interrupt table,
1723 * also we need to tell the driver to start using ICT interrupt.
1725 int iwl_reset_ict(struct iwl_priv *priv)
1727 u32 val;
1728 unsigned long flags;
1730 if (!priv->ict_tbl_vir)
1731 return 0;
1733 spin_lock_irqsave(&priv->lock, flags);
1734 iwl_disable_interrupts(priv);
1736 memset(&priv->ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
1738 val = priv->aligned_ict_tbl_dma >> PAGE_SHIFT;
1740 val |= CSR_DRAM_INT_TBL_ENABLE;
1741 val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
1743 IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
1744 "aligned dma address %Lx\n",
1745 val, (unsigned long long)priv->aligned_ict_tbl_dma);
1747 iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
1748 priv->use_ict = true;
1749 priv->ict_index = 0;
1750 iwl_write32(priv, CSR_INT, priv->inta_mask);
1751 iwl_enable_interrupts(priv);
1752 spin_unlock_irqrestore(&priv->lock, flags);
1754 return 0;
1756 EXPORT_SYMBOL(iwl_reset_ict);
1758 /* Device is going down disable ict interrupt usage */
1759 void iwl_disable_ict(struct iwl_priv *priv)
1761 unsigned long flags;
1763 spin_lock_irqsave(&priv->lock, flags);
1764 priv->use_ict = false;
1765 spin_unlock_irqrestore(&priv->lock, flags);
1767 EXPORT_SYMBOL(iwl_disable_ict);
1769 /* interrupt handler using ict table, with this interrupt driver will
1770 * stop using INTA register to get device's interrupt, reading this register
1771 * is expensive, device will write interrupts in ICT dram table, increment
1772 * index then will fire interrupt to driver, driver will OR all ICT table
1773 * entries from current index up to table entry with 0 value. the result is
1774 * the interrupt we need to service, driver will set the entries back to 0 and
1775 * set index.
1777 irqreturn_t iwl_isr_ict(int irq, void *data)
1779 struct iwl_priv *priv = data;
1780 u32 inta, inta_mask;
1781 u32 val = 0;
1783 if (!priv)
1784 return IRQ_NONE;
1786 /* dram interrupt table not set yet,
1787 * use legacy interrupt.
1789 if (!priv->use_ict)
1790 return iwl_isr(irq, data);
1792 spin_lock(&priv->lock);
1794 /* Disable (but don't clear!) interrupts here to avoid
1795 * back-to-back ISRs and sporadic interrupts from our NIC.
1796 * If we have something to service, the tasklet will re-enable ints.
1797 * If we *don't* have something, we'll re-enable before leaving here.
1799 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1800 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1803 /* Ignore interrupt if there's nothing in NIC to service.
1804 * This may be due to IRQ shared with another device,
1805 * or due to sporadic interrupts thrown from our NIC. */
1806 if (!priv->ict_tbl[priv->ict_index]) {
1807 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1808 goto none;
1811 /* read all entries that not 0 start with ict_index */
1812 while (priv->ict_tbl[priv->ict_index]) {
1814 val |= le32_to_cpu(priv->ict_tbl[priv->ict_index]);
1815 IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
1816 priv->ict_index,
1817 le32_to_cpu(priv->ict_tbl[priv->ict_index]));
1818 priv->ict_tbl[priv->ict_index] = 0;
1819 priv->ict_index = iwl_queue_inc_wrap(priv->ict_index,
1820 ICT_COUNT);
1824 /* We should not get this value, just ignore it. */
1825 if (val == 0xffffffff)
1826 val = 0;
1829 * this is a w/a for a h/w bug. the h/w bug may cause the Rx bit
1830 * (bit 15 before shifting it to 31) to clear when using interrupt
1831 * coalescing. fortunately, bits 18 and 19 stay set when this happens
1832 * so we use them to decide on the real state of the Rx bit.
1833 * In order words, bit 15 is set if bit 18 or bit 19 are set.
1835 if (val & 0xC0000)
1836 val |= 0x8000;
1838 inta = (0xff & val) | ((0xff00 & val) << 16);
1839 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
1840 inta, inta_mask, val);
1842 inta &= priv->inta_mask;
1843 priv->inta |= inta;
1845 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1846 if (likely(inta))
1847 tasklet_schedule(&priv->irq_tasklet);
1848 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta) {
1849 /* Allow interrupt if was disabled by this handler and
1850 * no tasklet was schedules, We should not enable interrupt,
1851 * tasklet will enable it.
1853 iwl_enable_interrupts(priv);
1856 spin_unlock(&priv->lock);
1857 return IRQ_HANDLED;
1859 none:
1860 /* re-enable interrupts here since we don't have anything to service.
1861 * only Re-enable if disabled by irq.
1863 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1864 iwl_enable_interrupts(priv);
1866 spin_unlock(&priv->lock);
1867 return IRQ_NONE;
1869 EXPORT_SYMBOL(iwl_isr_ict);
1872 static irqreturn_t iwl_isr(int irq, void *data)
1874 struct iwl_priv *priv = data;
1875 u32 inta, inta_mask;
1876 #ifdef CONFIG_IWLWIFI_DEBUG
1877 u32 inta_fh;
1878 #endif
1879 if (!priv)
1880 return IRQ_NONE;
1882 spin_lock(&priv->lock);
1884 /* Disable (but don't clear!) interrupts here to avoid
1885 * back-to-back ISRs and sporadic interrupts from our NIC.
1886 * If we have something to service, the tasklet will re-enable ints.
1887 * If we *don't* have something, we'll re-enable before leaving here. */
1888 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1889 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1891 /* Discover which interrupts are active/pending */
1892 inta = iwl_read32(priv, CSR_INT);
1894 /* Ignore interrupt if there's nothing in NIC to service.
1895 * This may be due to IRQ shared with another device,
1896 * or due to sporadic interrupts thrown from our NIC. */
1897 if (!inta) {
1898 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1899 goto none;
1902 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1903 /* Hardware disappeared. It might have already raised
1904 * an interrupt */
1905 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1906 goto unplugged;
1909 #ifdef CONFIG_IWLWIFI_DEBUG
1910 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
1911 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1912 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
1913 "fh 0x%08x\n", inta, inta_mask, inta_fh);
1915 #endif
1917 priv->inta |= inta;
1918 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1919 if (likely(inta))
1920 tasklet_schedule(&priv->irq_tasklet);
1921 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1922 iwl_enable_interrupts(priv);
1924 unplugged:
1925 spin_unlock(&priv->lock);
1926 return IRQ_HANDLED;
1928 none:
1929 /* re-enable interrupts here since we don't have anything to service. */
1930 /* only Re-enable if diabled by irq and no schedules tasklet. */
1931 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1932 iwl_enable_interrupts(priv);
1934 spin_unlock(&priv->lock);
1935 return IRQ_NONE;
1938 irqreturn_t iwl_isr_legacy(int irq, void *data)
1940 struct iwl_priv *priv = data;
1941 u32 inta, inta_mask;
1942 u32 inta_fh;
1943 if (!priv)
1944 return IRQ_NONE;
1946 spin_lock(&priv->lock);
1948 /* Disable (but don't clear!) interrupts here to avoid
1949 * back-to-back ISRs and sporadic interrupts from our NIC.
1950 * If we have something to service, the tasklet will re-enable ints.
1951 * If we *don't* have something, we'll re-enable before leaving here. */
1952 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1953 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1955 /* Discover which interrupts are active/pending */
1956 inta = iwl_read32(priv, CSR_INT);
1957 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1959 /* Ignore interrupt if there's nothing in NIC to service.
1960 * This may be due to IRQ shared with another device,
1961 * or due to sporadic interrupts thrown from our NIC. */
1962 if (!inta && !inta_fh) {
1963 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
1964 goto none;
1967 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1968 /* Hardware disappeared. It might have already raised
1969 * an interrupt */
1970 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1971 goto unplugged;
1974 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1975 inta, inta_mask, inta_fh);
1977 inta &= ~CSR_INT_BIT_SCD;
1979 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1980 if (likely(inta || inta_fh))
1981 tasklet_schedule(&priv->irq_tasklet);
1983 unplugged:
1984 spin_unlock(&priv->lock);
1985 return IRQ_HANDLED;
1987 none:
1988 /* re-enable interrupts here since we don't have anything to service. */
1989 /* only Re-enable if diabled by irq */
1990 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1991 iwl_enable_interrupts(priv);
1992 spin_unlock(&priv->lock);
1993 return IRQ_NONE;
1995 EXPORT_SYMBOL(iwl_isr_legacy);
1997 int iwl_send_bt_config(struct iwl_priv *priv)
1999 struct iwl_bt_cmd bt_cmd = {
2000 .lead_time = BT_LEAD_TIME_DEF,
2001 .max_kill = BT_MAX_KILL_DEF,
2002 .kill_ack_mask = 0,
2003 .kill_cts_mask = 0,
2006 if (!bt_coex_active)
2007 bt_cmd.flags = BT_COEX_DISABLE;
2008 else
2009 bt_cmd.flags = BT_COEX_ENABLE;
2011 IWL_DEBUG_INFO(priv, "BT coex %s\n",
2012 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
2014 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
2015 sizeof(struct iwl_bt_cmd), &bt_cmd);
2017 EXPORT_SYMBOL(iwl_send_bt_config);
2019 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
2021 struct iwl_statistics_cmd statistics_cmd = {
2022 .configuration_flags =
2023 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
2026 if (flags & CMD_ASYNC)
2027 return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
2028 sizeof(struct iwl_statistics_cmd),
2029 &statistics_cmd, NULL);
2030 else
2031 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
2032 sizeof(struct iwl_statistics_cmd),
2033 &statistics_cmd);
2035 EXPORT_SYMBOL(iwl_send_statistics_request);
2038 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
2039 * using sample data 100 bytes apart. If these sample points are good,
2040 * it's a pretty good bet that everything between them is good, too.
2042 static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
2044 u32 val;
2045 int ret = 0;
2046 u32 errcnt = 0;
2047 u32 i;
2049 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2051 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2052 /* read data comes through single port, auto-incr addr */
2053 /* NOTE: Use the debugless read so we don't flood kernel log
2054 * if IWL_DL_IO is set */
2055 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2056 i + IWL49_RTC_INST_LOWER_BOUND);
2057 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2058 if (val != le32_to_cpu(*image)) {
2059 ret = -EIO;
2060 errcnt++;
2061 if (errcnt >= 3)
2062 break;
2066 return ret;
2070 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
2071 * looking at all data.
2073 static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
2074 u32 len)
2076 u32 val;
2077 u32 save_len = len;
2078 int ret = 0;
2079 u32 errcnt;
2081 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2083 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2084 IWL49_RTC_INST_LOWER_BOUND);
2086 errcnt = 0;
2087 for (; len > 0; len -= sizeof(u32), image++) {
2088 /* read data comes through single port, auto-incr addr */
2089 /* NOTE: Use the debugless read so we don't flood kernel log
2090 * if IWL_DL_IO is set */
2091 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2092 if (val != le32_to_cpu(*image)) {
2093 IWL_ERR(priv, "uCode INST section is invalid at "
2094 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2095 save_len - len, val, le32_to_cpu(*image));
2096 ret = -EIO;
2097 errcnt++;
2098 if (errcnt >= 20)
2099 break;
2103 if (!errcnt)
2104 IWL_DEBUG_INFO(priv,
2105 "ucode image in INSTRUCTION memory is good\n");
2107 return ret;
2111 * iwl_verify_ucode - determine which instruction image is in SRAM,
2112 * and verify its contents
2114 int iwl_verify_ucode(struct iwl_priv *priv)
2116 __le32 *image;
2117 u32 len;
2118 int ret;
2120 /* Try bootstrap */
2121 image = (__le32 *)priv->ucode_boot.v_addr;
2122 len = priv->ucode_boot.len;
2123 ret = iwlcore_verify_inst_sparse(priv, image, len);
2124 if (!ret) {
2125 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
2126 return 0;
2129 /* Try initialize */
2130 image = (__le32 *)priv->ucode_init.v_addr;
2131 len = priv->ucode_init.len;
2132 ret = iwlcore_verify_inst_sparse(priv, image, len);
2133 if (!ret) {
2134 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
2135 return 0;
2138 /* Try runtime/protocol */
2139 image = (__le32 *)priv->ucode_code.v_addr;
2140 len = priv->ucode_code.len;
2141 ret = iwlcore_verify_inst_sparse(priv, image, len);
2142 if (!ret) {
2143 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
2144 return 0;
2147 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
2149 /* Since nothing seems to match, show first several data entries in
2150 * instruction SRAM, so maybe visual inspection will give a clue.
2151 * Selection of bootstrap image (vs. other images) is arbitrary. */
2152 image = (__le32 *)priv->ucode_boot.v_addr;
2153 len = priv->ucode_boot.len;
2154 ret = iwl_verify_inst_full(priv, image, len);
2156 return ret;
2158 EXPORT_SYMBOL(iwl_verify_ucode);
2161 void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2163 struct iwl_ct_kill_config cmd;
2164 struct iwl_ct_kill_throttling_config adv_cmd;
2165 unsigned long flags;
2166 int ret = 0;
2168 spin_lock_irqsave(&priv->lock, flags);
2169 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2170 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2171 spin_unlock_irqrestore(&priv->lock, flags);
2172 priv->thermal_throttle.ct_kill_toggle = false;
2174 if (priv->cfg->support_ct_kill_exit) {
2175 adv_cmd.critical_temperature_enter =
2176 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2177 adv_cmd.critical_temperature_exit =
2178 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2180 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2181 sizeof(adv_cmd), &adv_cmd);
2182 if (ret)
2183 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2184 else
2185 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2186 "succeeded, "
2187 "critical temperature enter is %d,"
2188 "exit is %d\n",
2189 priv->hw_params.ct_kill_threshold,
2190 priv->hw_params.ct_kill_exit_threshold);
2191 } else {
2192 cmd.critical_temperature_R =
2193 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2195 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2196 sizeof(cmd), &cmd);
2197 if (ret)
2198 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2199 else
2200 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2201 "succeeded, "
2202 "critical temperature is %d\n",
2203 priv->hw_params.ct_kill_threshold);
2206 EXPORT_SYMBOL(iwl_rf_kill_ct_config);
2210 * CARD_STATE_CMD
2212 * Use: Sets the device's internal card state to enable, disable, or halt
2214 * When in the 'enable' state the card operates as normal.
2215 * When in the 'disable' state, the card enters into a low power mode.
2216 * When in the 'halt' state, the card is shut down and must be fully
2217 * restarted to come back on.
2219 int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
2221 struct iwl_host_cmd cmd = {
2222 .id = REPLY_CARD_STATE_CMD,
2223 .len = sizeof(u32),
2224 .data = &flags,
2225 .flags = meta_flag,
2228 return iwl_send_cmd(priv, &cmd);
2231 void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
2232 struct iwl_rx_mem_buffer *rxb)
2234 #ifdef CONFIG_IWLWIFI_DEBUG
2235 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2236 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
2237 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
2238 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2239 #endif
2241 EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
2243 void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
2244 struct iwl_rx_mem_buffer *rxb)
2246 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2247 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
2248 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
2249 "notification for %s:\n", len,
2250 get_cmd_string(pkt->hdr.cmd));
2251 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
2253 EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
2255 void iwl_rx_reply_error(struct iwl_priv *priv,
2256 struct iwl_rx_mem_buffer *rxb)
2258 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2260 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
2261 "seq 0x%04X ser 0x%08X\n",
2262 le32_to_cpu(pkt->u.err_resp.error_type),
2263 get_cmd_string(pkt->u.err_resp.cmd_id),
2264 pkt->u.err_resp.cmd_id,
2265 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
2266 le32_to_cpu(pkt->u.err_resp.error_info));
2268 EXPORT_SYMBOL(iwl_rx_reply_error);
2270 void iwl_clear_isr_stats(struct iwl_priv *priv)
2272 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
2275 int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2276 const struct ieee80211_tx_queue_params *params)
2278 struct iwl_priv *priv = hw->priv;
2279 unsigned long flags;
2280 int q;
2282 IWL_DEBUG_MAC80211(priv, "enter\n");
2284 if (!iwl_is_ready_rf(priv)) {
2285 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2286 return -EIO;
2289 if (queue >= AC_NUM) {
2290 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
2291 return 0;
2294 q = AC_NUM - 1 - queue;
2296 spin_lock_irqsave(&priv->lock, flags);
2298 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
2299 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2300 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2301 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2302 cpu_to_le16((params->txop * 32));
2304 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2305 priv->qos_data.qos_active = 1;
2307 if (priv->iw_mode == NL80211_IFTYPE_AP)
2308 iwl_activate_qos(priv, 1);
2309 else if (priv->assoc_id && iwl_is_associated(priv))
2310 iwl_activate_qos(priv, 0);
2312 spin_unlock_irqrestore(&priv->lock, flags);
2314 IWL_DEBUG_MAC80211(priv, "leave\n");
2315 return 0;
2317 EXPORT_SYMBOL(iwl_mac_conf_tx);
2319 static void iwl_ht_conf(struct iwl_priv *priv,
2320 struct ieee80211_bss_conf *bss_conf)
2322 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
2323 struct ieee80211_sta *sta;
2325 IWL_DEBUG_MAC80211(priv, "enter: \n");
2327 if (!ht_conf->is_ht)
2328 return;
2330 ht_conf->ht_protection =
2331 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
2332 ht_conf->non_GF_STA_present =
2333 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
2335 ht_conf->single_chain_sufficient = false;
2337 switch (priv->iw_mode) {
2338 case NL80211_IFTYPE_STATION:
2339 rcu_read_lock();
2340 sta = ieee80211_find_sta(priv->vif, priv->bssid);
2341 if (sta) {
2342 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2343 int maxstreams;
2345 maxstreams = (ht_cap->mcs.tx_params &
2346 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
2347 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2348 maxstreams += 1;
2350 if ((ht_cap->mcs.rx_mask[1] == 0) &&
2351 (ht_cap->mcs.rx_mask[2] == 0))
2352 ht_conf->single_chain_sufficient = true;
2353 if (maxstreams <= 1)
2354 ht_conf->single_chain_sufficient = true;
2355 } else {
2357 * If at all, this can only happen through a race
2358 * when the AP disconnects us while we're still
2359 * setting up the connection, in that case mac80211
2360 * will soon tell us about that.
2362 ht_conf->single_chain_sufficient = true;
2364 rcu_read_unlock();
2365 break;
2366 case NL80211_IFTYPE_ADHOC:
2367 ht_conf->single_chain_sufficient = true;
2368 break;
2369 default:
2370 break;
2373 IWL_DEBUG_MAC80211(priv, "leave\n");
2376 static inline void iwl_set_no_assoc(struct iwl_priv *priv)
2378 priv->assoc_id = 0;
2379 iwl_led_disassociate(priv);
2381 * inform the ucode that there is no longer an
2382 * association and that no more packets should be
2383 * sent
2385 priv->staging_rxon.filter_flags &=
2386 ~RXON_FILTER_ASSOC_MSK;
2387 priv->staging_rxon.assoc_id = 0;
2388 iwlcore_commit_rxon(priv);
2391 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2392 void iwl_bss_info_changed(struct ieee80211_hw *hw,
2393 struct ieee80211_vif *vif,
2394 struct ieee80211_bss_conf *bss_conf,
2395 u32 changes)
2397 struct iwl_priv *priv = hw->priv;
2398 int ret;
2400 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2402 if (!iwl_is_alive(priv))
2403 return;
2405 mutex_lock(&priv->mutex);
2407 if (changes & BSS_CHANGED_BEACON &&
2408 priv->iw_mode == NL80211_IFTYPE_AP) {
2409 dev_kfree_skb(priv->ibss_beacon);
2410 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2413 if (changes & BSS_CHANGED_BEACON_INT) {
2414 priv->beacon_int = bss_conf->beacon_int;
2415 /* TODO: in AP mode, do something to make this take effect */
2418 if (changes & BSS_CHANGED_BSSID) {
2419 IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
2422 * If there is currently a HW scan going on in the
2423 * background then we need to cancel it else the RXON
2424 * below/in post_associate will fail.
2426 if (iwl_scan_cancel_timeout(priv, 100)) {
2427 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
2428 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2429 mutex_unlock(&priv->mutex);
2430 return;
2433 /* mac80211 only sets assoc when in STATION mode */
2434 if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
2435 bss_conf->assoc) {
2436 memcpy(priv->staging_rxon.bssid_addr,
2437 bss_conf->bssid, ETH_ALEN);
2439 /* currently needed in a few places */
2440 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
2441 } else {
2442 priv->staging_rxon.filter_flags &=
2443 ~RXON_FILTER_ASSOC_MSK;
2449 * This needs to be after setting the BSSID in case
2450 * mac80211 decides to do both changes at once because
2451 * it will invoke post_associate.
2453 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2454 changes & BSS_CHANGED_BEACON) {
2455 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2457 if (beacon)
2458 iwl_mac_beacon_update(hw, beacon);
2461 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2462 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2463 bss_conf->use_short_preamble);
2464 if (bss_conf->use_short_preamble)
2465 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2466 else
2467 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2470 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2471 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2472 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2473 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2474 else
2475 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2478 if (changes & BSS_CHANGED_BASIC_RATES) {
2479 /* XXX use this information
2481 * To do that, remove code from iwl_set_rate() and put something
2482 * like this here:
2484 if (A-band)
2485 priv->staging_rxon.ofdm_basic_rates =
2486 bss_conf->basic_rates;
2487 else
2488 priv->staging_rxon.ofdm_basic_rates =
2489 bss_conf->basic_rates >> 4;
2490 priv->staging_rxon.cck_basic_rates =
2491 bss_conf->basic_rates & 0xF;
2495 if (changes & BSS_CHANGED_HT) {
2496 iwl_ht_conf(priv, bss_conf);
2498 if (priv->cfg->ops->hcmd->set_rxon_chain)
2499 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2502 if (changes & BSS_CHANGED_ASSOC) {
2503 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
2504 if (bss_conf->assoc) {
2505 priv->assoc_id = bss_conf->aid;
2506 priv->beacon_int = bss_conf->beacon_int;
2507 priv->timestamp = bss_conf->timestamp;
2508 priv->assoc_capability = bss_conf->assoc_capability;
2510 iwl_led_associate(priv);
2513 * We have just associated, don't start scan too early
2514 * leave time for EAPOL exchange to complete.
2516 * XXX: do this in mac80211
2518 priv->next_scan_jiffies = jiffies +
2519 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
2520 if (!iwl_is_rfkill(priv))
2521 priv->cfg->ops->lib->post_associate(priv);
2522 } else
2523 iwl_set_no_assoc(priv);
2526 if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2527 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
2528 changes);
2529 ret = iwl_send_rxon_assoc(priv);
2530 if (!ret) {
2531 /* Sync active_rxon with latest change. */
2532 memcpy((void *)&priv->active_rxon,
2533 &priv->staging_rxon,
2534 sizeof(struct iwl_rxon_cmd));
2538 if (changes & BSS_CHANGED_BEACON_ENABLED) {
2539 if (vif->bss_conf.enable_beacon) {
2540 memcpy(priv->staging_rxon.bssid_addr,
2541 bss_conf->bssid, ETH_ALEN);
2542 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
2543 iwlcore_config_ap(priv);
2544 } else
2545 iwl_set_no_assoc(priv);
2548 mutex_unlock(&priv->mutex);
2550 IWL_DEBUG_MAC80211(priv, "leave\n");
2552 EXPORT_SYMBOL(iwl_bss_info_changed);
2554 int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2556 struct iwl_priv *priv = hw->priv;
2557 unsigned long flags;
2558 __le64 timestamp;
2560 IWL_DEBUG_MAC80211(priv, "enter\n");
2562 if (!iwl_is_ready_rf(priv)) {
2563 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2564 return -EIO;
2567 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2568 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2569 return -EIO;
2572 spin_lock_irqsave(&priv->lock, flags);
2574 if (priv->ibss_beacon)
2575 dev_kfree_skb(priv->ibss_beacon);
2577 priv->ibss_beacon = skb;
2579 priv->assoc_id = 0;
2580 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2581 priv->timestamp = le64_to_cpu(timestamp);
2583 IWL_DEBUG_MAC80211(priv, "leave\n");
2584 spin_unlock_irqrestore(&priv->lock, flags);
2586 iwl_reset_qos(priv);
2588 priv->cfg->ops->lib->post_associate(priv);
2591 return 0;
2593 EXPORT_SYMBOL(iwl_mac_beacon_update);
2595 int iwl_set_mode(struct iwl_priv *priv, int mode)
2597 if (mode == NL80211_IFTYPE_ADHOC) {
2598 const struct iwl_channel_info *ch_info;
2600 ch_info = iwl_get_channel_info(priv,
2601 priv->band,
2602 le16_to_cpu(priv->staging_rxon.channel));
2604 if (!ch_info || !is_channel_ibss(ch_info)) {
2605 IWL_ERR(priv, "channel %d not IBSS channel\n",
2606 le16_to_cpu(priv->staging_rxon.channel));
2607 return -EINVAL;
2611 iwl_connection_init_rx_config(priv, mode);
2613 if (priv->cfg->ops->hcmd->set_rxon_chain)
2614 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2616 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2618 iwl_clear_stations_table(priv);
2620 /* dont commit rxon if rf-kill is on*/
2621 if (!iwl_is_ready_rf(priv))
2622 return -EAGAIN;
2624 iwlcore_commit_rxon(priv);
2626 return 0;
2628 EXPORT_SYMBOL(iwl_set_mode);
2630 int iwl_mac_add_interface(struct ieee80211_hw *hw,
2631 struct ieee80211_vif *vif)
2633 struct iwl_priv *priv = hw->priv;
2634 int err = 0;
2636 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", vif->type);
2638 mutex_lock(&priv->mutex);
2640 if (priv->vif) {
2641 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2642 err = -EOPNOTSUPP;
2643 goto out;
2646 priv->vif = vif;
2647 priv->iw_mode = vif->type;
2649 if (vif->addr) {
2650 IWL_DEBUG_MAC80211(priv, "Set %pM\n", vif->addr);
2651 memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
2654 if (iwl_set_mode(priv, vif->type) == -EAGAIN)
2655 /* we are not ready, will run again when ready */
2656 set_bit(STATUS_MODE_PENDING, &priv->status);
2658 out:
2659 mutex_unlock(&priv->mutex);
2661 IWL_DEBUG_MAC80211(priv, "leave\n");
2662 return err;
2664 EXPORT_SYMBOL(iwl_mac_add_interface);
2666 void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2667 struct ieee80211_vif *vif)
2669 struct iwl_priv *priv = hw->priv;
2671 IWL_DEBUG_MAC80211(priv, "enter\n");
2673 mutex_lock(&priv->mutex);
2675 if (iwl_is_ready_rf(priv)) {
2676 iwl_scan_cancel_timeout(priv, 100);
2677 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2678 iwlcore_commit_rxon(priv);
2680 if (priv->vif == vif) {
2681 priv->vif = NULL;
2682 memset(priv->bssid, 0, ETH_ALEN);
2684 mutex_unlock(&priv->mutex);
2686 IWL_DEBUG_MAC80211(priv, "leave\n");
2689 EXPORT_SYMBOL(iwl_mac_remove_interface);
2692 * iwl_mac_config - mac80211 config callback
2694 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2695 * be set inappropriately and the driver currently sets the hardware up to
2696 * use it whenever needed.
2698 int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2700 struct iwl_priv *priv = hw->priv;
2701 const struct iwl_channel_info *ch_info;
2702 struct ieee80211_conf *conf = &hw->conf;
2703 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
2704 unsigned long flags = 0;
2705 int ret = 0;
2706 u16 ch;
2707 int scan_active = 0;
2709 mutex_lock(&priv->mutex);
2711 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2712 conf->channel->hw_value, changed);
2714 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2715 test_bit(STATUS_SCANNING, &priv->status))) {
2716 scan_active = 1;
2717 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2720 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
2721 IEEE80211_CONF_CHANGE_CHANNEL)) {
2722 /* mac80211 uses static for non-HT which is what we want */
2723 priv->current_ht_config.smps = conf->smps_mode;
2726 * Recalculate chain counts.
2728 * If monitor mode is enabled then mac80211 will
2729 * set up the SM PS mode to OFF if an HT channel is
2730 * configured.
2732 if (priv->cfg->ops->hcmd->set_rxon_chain)
2733 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2736 /* during scanning mac80211 will delay channel setting until
2737 * scan finish with changed = 0
2739 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2740 if (scan_active)
2741 goto set_ch_out;
2743 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2744 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2745 if (!is_channel_valid(ch_info)) {
2746 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2747 ret = -EINVAL;
2748 goto set_ch_out;
2751 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2752 !is_channel_ibss(ch_info)) {
2753 IWL_ERR(priv, "channel %d in band %d not "
2754 "IBSS channel\n",
2755 conf->channel->hw_value, conf->channel->band);
2756 ret = -EINVAL;
2757 goto set_ch_out;
2760 spin_lock_irqsave(&priv->lock, flags);
2762 /* Configure HT40 channels */
2763 ht_conf->is_ht = conf_is_ht(conf);
2764 if (ht_conf->is_ht) {
2765 if (conf_is_ht40_minus(conf)) {
2766 ht_conf->extension_chan_offset =
2767 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2768 ht_conf->is_40mhz = true;
2769 } else if (conf_is_ht40_plus(conf)) {
2770 ht_conf->extension_chan_offset =
2771 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2772 ht_conf->is_40mhz = true;
2773 } else {
2774 ht_conf->extension_chan_offset =
2775 IEEE80211_HT_PARAM_CHA_SEC_NONE;
2776 ht_conf->is_40mhz = false;
2778 } else
2779 ht_conf->is_40mhz = false;
2780 /* Default to no protection. Protection mode will later be set
2781 * from BSS config in iwl_ht_conf */
2782 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2784 /* if we are switching from ht to 2.4 clear flags
2785 * from any ht related info since 2.4 does not
2786 * support ht */
2787 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2788 priv->staging_rxon.flags = 0;
2790 iwl_set_rxon_channel(priv, conf->channel);
2792 iwl_set_flags_for_band(priv, conf->channel->band);
2793 spin_unlock_irqrestore(&priv->lock, flags);
2794 if (iwl_is_associated(priv) &&
2795 (le16_to_cpu(priv->active_rxon.channel) != ch) &&
2796 priv->cfg->ops->lib->set_channel_switch) {
2797 iwl_set_rate(priv);
2799 * at this point, staging_rxon has the
2800 * configuration for channel switch
2802 ret = priv->cfg->ops->lib->set_channel_switch(priv,
2803 ch);
2804 if (!ret) {
2805 iwl_print_rx_config_cmd(priv);
2806 goto out;
2808 priv->switch_rxon.switch_in_progress = false;
2810 set_ch_out:
2811 /* The list of supported rates and rate mask can be different
2812 * for each band; since the band may have changed, reset
2813 * the rate mask to what mac80211 lists */
2814 iwl_set_rate(priv);
2817 if (changed & (IEEE80211_CONF_CHANGE_PS |
2818 IEEE80211_CONF_CHANGE_IDLE)) {
2819 ret = iwl_power_update_mode(priv, false);
2820 if (ret)
2821 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
2824 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2825 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2826 priv->tx_power_user_lmt, conf->power_level);
2828 iwl_set_tx_power(priv, conf->power_level, false);
2831 if (!iwl_is_ready(priv)) {
2832 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2833 goto out;
2836 if (scan_active)
2837 goto out;
2839 if (memcmp(&priv->active_rxon,
2840 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2841 iwlcore_commit_rxon(priv);
2842 else
2843 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
2846 out:
2847 IWL_DEBUG_MAC80211(priv, "leave\n");
2848 mutex_unlock(&priv->mutex);
2849 return ret;
2851 EXPORT_SYMBOL(iwl_mac_config);
2853 int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2854 struct ieee80211_tx_queue_stats *stats)
2856 struct iwl_priv *priv = hw->priv;
2857 int i, avail;
2858 struct iwl_tx_queue *txq;
2859 struct iwl_queue *q;
2860 unsigned long flags;
2862 IWL_DEBUG_MAC80211(priv, "enter\n");
2864 if (!iwl_is_ready_rf(priv)) {
2865 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2866 return -EIO;
2869 spin_lock_irqsave(&priv->lock, flags);
2871 for (i = 0; i < AC_NUM; i++) {
2872 txq = &priv->txq[i];
2873 q = &txq->q;
2874 avail = iwl_queue_space(q);
2876 stats[i].len = q->n_window - avail;
2877 stats[i].limit = q->n_window - q->high_mark;
2878 stats[i].count = q->n_window;
2881 spin_unlock_irqrestore(&priv->lock, flags);
2883 IWL_DEBUG_MAC80211(priv, "leave\n");
2885 return 0;
2887 EXPORT_SYMBOL(iwl_mac_get_tx_stats);
2889 void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2891 struct iwl_priv *priv = hw->priv;
2892 unsigned long flags;
2894 mutex_lock(&priv->mutex);
2895 IWL_DEBUG_MAC80211(priv, "enter\n");
2897 spin_lock_irqsave(&priv->lock, flags);
2898 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
2899 spin_unlock_irqrestore(&priv->lock, flags);
2901 iwl_reset_qos(priv);
2903 spin_lock_irqsave(&priv->lock, flags);
2904 priv->assoc_id = 0;
2905 priv->assoc_capability = 0;
2906 priv->assoc_station_added = 0;
2908 /* new association get rid of ibss beacon skb */
2909 if (priv->ibss_beacon)
2910 dev_kfree_skb(priv->ibss_beacon);
2912 priv->ibss_beacon = NULL;
2914 priv->beacon_int = priv->vif->bss_conf.beacon_int;
2915 priv->timestamp = 0;
2916 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2917 priv->beacon_int = 0;
2919 spin_unlock_irqrestore(&priv->lock, flags);
2921 if (!iwl_is_ready_rf(priv)) {
2922 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2923 mutex_unlock(&priv->mutex);
2924 return;
2927 /* we are restarting association process
2928 * clear RXON_FILTER_ASSOC_MSK bit
2930 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2931 iwl_scan_cancel_timeout(priv, 100);
2932 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2933 iwlcore_commit_rxon(priv);
2936 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2937 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2938 mutex_unlock(&priv->mutex);
2939 return;
2942 iwl_set_rate(priv);
2944 mutex_unlock(&priv->mutex);
2946 IWL_DEBUG_MAC80211(priv, "leave\n");
2948 EXPORT_SYMBOL(iwl_mac_reset_tsf);
2950 int iwl_alloc_txq_mem(struct iwl_priv *priv)
2952 if (!priv->txq)
2953 priv->txq = kzalloc(
2954 sizeof(struct iwl_tx_queue) * priv->cfg->num_of_queues,
2955 GFP_KERNEL);
2956 if (!priv->txq) {
2957 IWL_ERR(priv, "Not enough memory for txq \n");
2958 return -ENOMEM;
2960 return 0;
2962 EXPORT_SYMBOL(iwl_alloc_txq_mem);
2964 void iwl_free_txq_mem(struct iwl_priv *priv)
2966 kfree(priv->txq);
2967 priv->txq = NULL;
2969 EXPORT_SYMBOL(iwl_free_txq_mem);
2971 int iwl_send_wimax_coex(struct iwl_priv *priv)
2973 struct iwl_wimax_coex_cmd uninitialized_var(coex_cmd);
2975 if (priv->cfg->support_wimax_coexist) {
2976 /* UnMask wake up src at associated sleep */
2977 coex_cmd.flags |= COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
2979 /* UnMask wake up src at unassociated sleep */
2980 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
2981 memcpy(coex_cmd.sta_prio, cu_priorities,
2982 sizeof(struct iwl_wimax_coex_event_entry) *
2983 COEX_NUM_OF_EVENTS);
2985 /* enabling the coexistence feature */
2986 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
2988 /* enabling the priorities tables */
2989 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
2990 } else {
2991 /* coexistence is disabled */
2992 memset(&coex_cmd, 0, sizeof(coex_cmd));
2994 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
2995 sizeof(coex_cmd), &coex_cmd);
2997 EXPORT_SYMBOL(iwl_send_wimax_coex);
2999 #ifdef CONFIG_IWLWIFI_DEBUGFS
3001 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
3003 void iwl_reset_traffic_log(struct iwl_priv *priv)
3005 priv->tx_traffic_idx = 0;
3006 priv->rx_traffic_idx = 0;
3007 if (priv->tx_traffic)
3008 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
3009 if (priv->rx_traffic)
3010 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
3013 int iwl_alloc_traffic_mem(struct iwl_priv *priv)
3015 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
3017 if (iwl_debug_level & IWL_DL_TX) {
3018 if (!priv->tx_traffic) {
3019 priv->tx_traffic =
3020 kzalloc(traffic_size, GFP_KERNEL);
3021 if (!priv->tx_traffic)
3022 return -ENOMEM;
3025 if (iwl_debug_level & IWL_DL_RX) {
3026 if (!priv->rx_traffic) {
3027 priv->rx_traffic =
3028 kzalloc(traffic_size, GFP_KERNEL);
3029 if (!priv->rx_traffic)
3030 return -ENOMEM;
3033 iwl_reset_traffic_log(priv);
3034 return 0;
3036 EXPORT_SYMBOL(iwl_alloc_traffic_mem);
3038 void iwl_free_traffic_mem(struct iwl_priv *priv)
3040 kfree(priv->tx_traffic);
3041 priv->tx_traffic = NULL;
3043 kfree(priv->rx_traffic);
3044 priv->rx_traffic = NULL;
3046 EXPORT_SYMBOL(iwl_free_traffic_mem);
3048 void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
3049 u16 length, struct ieee80211_hdr *header)
3051 __le16 fc;
3052 u16 len;
3054 if (likely(!(iwl_debug_level & IWL_DL_TX)))
3055 return;
3057 if (!priv->tx_traffic)
3058 return;
3060 fc = header->frame_control;
3061 if (ieee80211_is_data(fc)) {
3062 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
3063 ? IWL_TRAFFIC_ENTRY_SIZE : length;
3064 memcpy((priv->tx_traffic +
3065 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
3066 header, len);
3067 priv->tx_traffic_idx =
3068 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
3071 EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
3073 void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
3074 u16 length, struct ieee80211_hdr *header)
3076 __le16 fc;
3077 u16 len;
3079 if (likely(!(iwl_debug_level & IWL_DL_RX)))
3080 return;
3082 if (!priv->rx_traffic)
3083 return;
3085 fc = header->frame_control;
3086 if (ieee80211_is_data(fc)) {
3087 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
3088 ? IWL_TRAFFIC_ENTRY_SIZE : length;
3089 memcpy((priv->rx_traffic +
3090 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
3091 header, len);
3092 priv->rx_traffic_idx =
3093 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
3096 EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
3098 const char *get_mgmt_string(int cmd)
3100 switch (cmd) {
3101 IWL_CMD(MANAGEMENT_ASSOC_REQ);
3102 IWL_CMD(MANAGEMENT_ASSOC_RESP);
3103 IWL_CMD(MANAGEMENT_REASSOC_REQ);
3104 IWL_CMD(MANAGEMENT_REASSOC_RESP);
3105 IWL_CMD(MANAGEMENT_PROBE_REQ);
3106 IWL_CMD(MANAGEMENT_PROBE_RESP);
3107 IWL_CMD(MANAGEMENT_BEACON);
3108 IWL_CMD(MANAGEMENT_ATIM);
3109 IWL_CMD(MANAGEMENT_DISASSOC);
3110 IWL_CMD(MANAGEMENT_AUTH);
3111 IWL_CMD(MANAGEMENT_DEAUTH);
3112 IWL_CMD(MANAGEMENT_ACTION);
3113 default:
3114 return "UNKNOWN";
3119 const char *get_ctrl_string(int cmd)
3121 switch (cmd) {
3122 IWL_CMD(CONTROL_BACK_REQ);
3123 IWL_CMD(CONTROL_BACK);
3124 IWL_CMD(CONTROL_PSPOLL);
3125 IWL_CMD(CONTROL_RTS);
3126 IWL_CMD(CONTROL_CTS);
3127 IWL_CMD(CONTROL_ACK);
3128 IWL_CMD(CONTROL_CFEND);
3129 IWL_CMD(CONTROL_CFENDACK);
3130 default:
3131 return "UNKNOWN";
3136 void iwl_clear_traffic_stats(struct iwl_priv *priv)
3138 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
3139 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
3140 priv->led_tpt = 0;
3144 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
3145 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
3146 * Use debugFs to display the rx/rx_statistics
3147 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
3148 * information will be recorded, but DATA pkt still will be recorded
3149 * for the reason of iwl_led.c need to control the led blinking based on
3150 * number of tx and rx data.
3153 void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
3155 struct traffic_stats *stats;
3157 if (is_tx)
3158 stats = &priv->tx_stats;
3159 else
3160 stats = &priv->rx_stats;
3162 if (ieee80211_is_mgmt(fc)) {
3163 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
3164 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
3165 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
3166 break;
3167 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3168 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
3169 break;
3170 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
3171 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
3172 break;
3173 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3174 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
3175 break;
3176 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3177 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
3178 break;
3179 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3180 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
3181 break;
3182 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3183 stats->mgmt[MANAGEMENT_BEACON]++;
3184 break;
3185 case cpu_to_le16(IEEE80211_STYPE_ATIM):
3186 stats->mgmt[MANAGEMENT_ATIM]++;
3187 break;
3188 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3189 stats->mgmt[MANAGEMENT_DISASSOC]++;
3190 break;
3191 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3192 stats->mgmt[MANAGEMENT_AUTH]++;
3193 break;
3194 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3195 stats->mgmt[MANAGEMENT_DEAUTH]++;
3196 break;
3197 case cpu_to_le16(IEEE80211_STYPE_ACTION):
3198 stats->mgmt[MANAGEMENT_ACTION]++;
3199 break;
3201 } else if (ieee80211_is_ctl(fc)) {
3202 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
3203 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
3204 stats->ctrl[CONTROL_BACK_REQ]++;
3205 break;
3206 case cpu_to_le16(IEEE80211_STYPE_BACK):
3207 stats->ctrl[CONTROL_BACK]++;
3208 break;
3209 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
3210 stats->ctrl[CONTROL_PSPOLL]++;
3211 break;
3212 case cpu_to_le16(IEEE80211_STYPE_RTS):
3213 stats->ctrl[CONTROL_RTS]++;
3214 break;
3215 case cpu_to_le16(IEEE80211_STYPE_CTS):
3216 stats->ctrl[CONTROL_CTS]++;
3217 break;
3218 case cpu_to_le16(IEEE80211_STYPE_ACK):
3219 stats->ctrl[CONTROL_ACK]++;
3220 break;
3221 case cpu_to_le16(IEEE80211_STYPE_CFEND):
3222 stats->ctrl[CONTROL_CFEND]++;
3223 break;
3224 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
3225 stats->ctrl[CONTROL_CFENDACK]++;
3226 break;
3228 } else {
3229 /* data */
3230 stats->data_cnt++;
3231 stats->data_bytes += len;
3233 iwl_leds_background(priv);
3235 EXPORT_SYMBOL(iwl_update_stats);
3236 #endif
3238 const static char *get_csr_string(int cmd)
3240 switch (cmd) {
3241 IWL_CMD(CSR_HW_IF_CONFIG_REG);
3242 IWL_CMD(CSR_INT_COALESCING);
3243 IWL_CMD(CSR_INT);
3244 IWL_CMD(CSR_INT_MASK);
3245 IWL_CMD(CSR_FH_INT_STATUS);
3246 IWL_CMD(CSR_GPIO_IN);
3247 IWL_CMD(CSR_RESET);
3248 IWL_CMD(CSR_GP_CNTRL);
3249 IWL_CMD(CSR_HW_REV);
3250 IWL_CMD(CSR_EEPROM_REG);
3251 IWL_CMD(CSR_EEPROM_GP);
3252 IWL_CMD(CSR_OTP_GP_REG);
3253 IWL_CMD(CSR_GIO_REG);
3254 IWL_CMD(CSR_GP_UCODE_REG);
3255 IWL_CMD(CSR_GP_DRIVER_REG);
3256 IWL_CMD(CSR_UCODE_DRV_GP1);
3257 IWL_CMD(CSR_UCODE_DRV_GP2);
3258 IWL_CMD(CSR_LED_REG);
3259 IWL_CMD(CSR_DRAM_INT_TBL_REG);
3260 IWL_CMD(CSR_GIO_CHICKEN_BITS);
3261 IWL_CMD(CSR_ANA_PLL_CFG);
3262 IWL_CMD(CSR_HW_REV_WA_REG);
3263 IWL_CMD(CSR_DBG_HPET_MEM_REG);
3264 default:
3265 return "UNKNOWN";
3270 void iwl_dump_csr(struct iwl_priv *priv)
3272 int i;
3273 u32 csr_tbl[] = {
3274 CSR_HW_IF_CONFIG_REG,
3275 CSR_INT_COALESCING,
3276 CSR_INT,
3277 CSR_INT_MASK,
3278 CSR_FH_INT_STATUS,
3279 CSR_GPIO_IN,
3280 CSR_RESET,
3281 CSR_GP_CNTRL,
3282 CSR_HW_REV,
3283 CSR_EEPROM_REG,
3284 CSR_EEPROM_GP,
3285 CSR_OTP_GP_REG,
3286 CSR_GIO_REG,
3287 CSR_GP_UCODE_REG,
3288 CSR_GP_DRIVER_REG,
3289 CSR_UCODE_DRV_GP1,
3290 CSR_UCODE_DRV_GP2,
3291 CSR_LED_REG,
3292 CSR_DRAM_INT_TBL_REG,
3293 CSR_GIO_CHICKEN_BITS,
3294 CSR_ANA_PLL_CFG,
3295 CSR_HW_REV_WA_REG,
3296 CSR_DBG_HPET_MEM_REG
3298 IWL_ERR(priv, "CSR values:\n");
3299 IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
3300 "CSR_INT_PERIODIC_REG)\n");
3301 for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
3302 IWL_ERR(priv, " %25s: 0X%08x\n",
3303 get_csr_string(csr_tbl[i]),
3304 iwl_read32(priv, csr_tbl[i]));
3307 EXPORT_SYMBOL(iwl_dump_csr);
3309 const static char *get_fh_string(int cmd)
3311 switch (cmd) {
3312 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
3313 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
3314 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
3315 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
3316 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
3317 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
3318 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
3319 IWL_CMD(FH_TSSR_TX_STATUS_REG);
3320 IWL_CMD(FH_TSSR_TX_ERROR_REG);
3321 default:
3322 return "UNKNOWN";
3327 int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
3329 int i;
3330 #ifdef CONFIG_IWLWIFI_DEBUG
3331 int pos = 0;
3332 size_t bufsz = 0;
3333 #endif
3334 u32 fh_tbl[] = {
3335 FH_RSCSR_CHNL0_STTS_WPTR_REG,
3336 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
3337 FH_RSCSR_CHNL0_WPTR,
3338 FH_MEM_RCSR_CHNL0_CONFIG_REG,
3339 FH_MEM_RSSR_SHARED_CTRL_REG,
3340 FH_MEM_RSSR_RX_STATUS_REG,
3341 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
3342 FH_TSSR_TX_STATUS_REG,
3343 FH_TSSR_TX_ERROR_REG
3345 #ifdef CONFIG_IWLWIFI_DEBUG
3346 if (display) {
3347 bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
3348 *buf = kmalloc(bufsz, GFP_KERNEL);
3349 if (!*buf)
3350 return -ENOMEM;
3351 pos += scnprintf(*buf + pos, bufsz - pos,
3352 "FH register values:\n");
3353 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
3354 pos += scnprintf(*buf + pos, bufsz - pos,
3355 " %34s: 0X%08x\n",
3356 get_fh_string(fh_tbl[i]),
3357 iwl_read_direct32(priv, fh_tbl[i]));
3359 return pos;
3361 #endif
3362 IWL_ERR(priv, "FH register values:\n");
3363 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
3364 IWL_ERR(priv, " %34s: 0X%08x\n",
3365 get_fh_string(fh_tbl[i]),
3366 iwl_read_direct32(priv, fh_tbl[i]));
3368 return 0;
3370 EXPORT_SYMBOL(iwl_dump_fh);
3372 void iwl_force_rf_reset(struct iwl_priv *priv)
3374 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3375 return;
3377 if (!iwl_is_associated(priv)) {
3378 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
3379 return;
3382 * There is no easy and better way to force reset the radio,
3383 * the only known method is switching channel which will force to
3384 * reset and tune the radio.
3385 * Use internal short scan (single channel) operation to should
3386 * achieve this objective.
3387 * Driver should reset the radio when number of consecutive missed
3388 * beacon, or any other uCode error condition detected.
3390 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
3391 iwl_internal_short_hw_scan(priv);
3392 return;
3394 EXPORT_SYMBOL(iwl_force_rf_reset);
3396 #ifdef CONFIG_PM
3398 int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
3400 struct iwl_priv *priv = pci_get_drvdata(pdev);
3403 * This function is called when system goes into suspend state
3404 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
3405 * first but since iwl_mac_stop() has no knowledge of who the caller is,
3406 * it will not call apm_ops.stop() to stop the DMA operation.
3407 * Calling apm_ops.stop here to make sure we stop the DMA.
3409 priv->cfg->ops->lib->apm_ops.stop(priv);
3411 pci_save_state(pdev);
3412 pci_disable_device(pdev);
3413 pci_set_power_state(pdev, PCI_D3hot);
3415 return 0;
3417 EXPORT_SYMBOL(iwl_pci_suspend);
3419 int iwl_pci_resume(struct pci_dev *pdev)
3421 struct iwl_priv *priv = pci_get_drvdata(pdev);
3422 int ret;
3424 pci_set_power_state(pdev, PCI_D0);
3425 ret = pci_enable_device(pdev);
3426 if (ret)
3427 return ret;
3428 pci_restore_state(pdev);
3429 iwl_enable_interrupts(priv);
3431 return 0;
3433 EXPORT_SYMBOL(iwl_pci_resume);
3435 #endif /* CONFIG_PM */