iwlwifi: fix bugs in beacon configuration
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-core.c
CommitLineData
df48c323 1/******************************************************************************
df48c323
TW
2 *
3 * GPL LICENSE SUMMARY
4 *
01f8162a 5 * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
df48c323
TW
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
759ef89f 25 * Intel Linux Wireless <ilw@linux.intel.com>
df48c323
TW
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29#include <linux/kernel.h>
30#include <linux/module.h>
8ccde88a 31#include <linux/etherdevice.h>
1d0a082d 32#include <net/mac80211.h>
df48c323 33
6bc913bd 34#include "iwl-eeprom.h"
3e0d4cb1 35#include "iwl-dev.h" /* FIXME: remove */
19335774 36#include "iwl-debug.h"
df48c323 37#include "iwl-core.h"
b661c819 38#include "iwl-io.h"
5da4b55f 39#include "iwl-power.h"
83dde8c9 40#include "iwl-sta.h"
ef850d7c 41#include "iwl-helpers.h"
df48c323 42
1d0a082d 43
df48c323
TW
44MODULE_DESCRIPTION("iwl core");
45MODULE_VERSION(IWLWIFI_VERSION);
a7b75207 46MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
712b6cf5 47MODULE_LICENSE("GPL");
df48c323 48
1933ac4d
WYG
49static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
50 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
51 0, COEX_UNASSOC_IDLE_FLAGS},
52 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
53 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
54 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
55 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
56 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
57 0, COEX_CALIBRATION_FLAGS},
58 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
59 0, COEX_PERIODIC_CALIBRATION_FLAGS},
60 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
61 0, COEX_CONNECTION_ESTAB_FLAGS},
62 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
63 0, COEX_ASSOCIATED_IDLE_FLAGS},
64 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
65 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
66 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
67 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
68 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
69 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
70 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
71 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
72 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
73 0, COEX_STAND_ALONE_DEBUG_FLAGS},
74 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
75 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
76 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
77 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
78};
79
c7de35cd
RR
80#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
81 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
82 IWL_RATE_SISO_##s##M_PLCP, \
83 IWL_RATE_MIMO2_##s##M_PLCP,\
84 IWL_RATE_MIMO3_##s##M_PLCP,\
85 IWL_RATE_##r##M_IEEE, \
86 IWL_RATE_##ip##M_INDEX, \
87 IWL_RATE_##in##M_INDEX, \
88 IWL_RATE_##rp##M_INDEX, \
89 IWL_RATE_##rn##M_INDEX, \
90 IWL_RATE_##pp##M_INDEX, \
91 IWL_RATE_##np##M_INDEX }
92
a562a9dd
RC
93u32 iwl_debug_level;
94EXPORT_SYMBOL(iwl_debug_level);
95
ef850d7c
MA
96static irqreturn_t iwl_isr(int irq, void *data);
97
c7de35cd
RR
98/*
99 * Parameter order:
100 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
101 *
102 * If there isn't a valid next or previous rate then INV is used which
103 * maps to IWL_RATE_INVALID
104 *
105 */
1826dcc0 106const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
c7de35cd
RR
107 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
108 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
109 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
110 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
111 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
112 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
113 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
114 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
115 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
116 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
117 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
118 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
119 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
120 /* FIXME:RS: ^^ should be INV (legacy) */
121};
1826dcc0 122EXPORT_SYMBOL(iwl_rates);
c7de35cd 123
e7d326ac
TW
124/**
125 * translate ucode response to mac80211 tx status control values
126 */
127void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
e6a9854b 128 struct ieee80211_tx_info *info)
e7d326ac 129{
e6a9854b 130 struct ieee80211_tx_rate *r = &info->control.rates[0];
e7d326ac 131
e6a9854b 132 info->antenna_sel_tx =
e7d326ac
TW
133 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
134 if (rate_n_flags & RATE_MCS_HT_MSK)
e6a9854b 135 r->flags |= IEEE80211_TX_RC_MCS;
e7d326ac 136 if (rate_n_flags & RATE_MCS_GF_MSK)
e6a9854b 137 r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
7aafef1c 138 if (rate_n_flags & RATE_MCS_HT40_MSK)
e6a9854b 139 r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
e7d326ac 140 if (rate_n_flags & RATE_MCS_DUP_MSK)
e6a9854b 141 r->flags |= IEEE80211_TX_RC_DUP_DATA;
e7d326ac 142 if (rate_n_flags & RATE_MCS_SGI_MSK)
e6a9854b 143 r->flags |= IEEE80211_TX_RC_SHORT_GI;
31513be8 144 r->idx = iwl_hwrate_to_mac80211_idx(rate_n_flags, info->band);
e7d326ac
TW
145}
146EXPORT_SYMBOL(iwl_hwrate_to_tx_control);
147
148int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
149{
150 int idx = 0;
151
152 /* HT rate format */
153 if (rate_n_flags & RATE_MCS_HT_MSK) {
154 idx = (rate_n_flags & 0xff);
155
60d32215
DH
156 if (idx >= IWL_RATE_MIMO3_6M_PLCP)
157 idx = idx - IWL_RATE_MIMO3_6M_PLCP;
158 else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
e7d326ac
TW
159 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
160
161 idx += IWL_FIRST_OFDM_RATE;
162 /* skip 9M not supported in ht*/
163 if (idx >= IWL_RATE_9M_INDEX)
164 idx += 1;
165 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
166 return idx;
167
168 /* legacy rate format, search for match in table */
169 } else {
170 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
171 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
172 return idx;
173 }
174
175 return -1;
176}
177EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
178
31513be8
DH
179int iwl_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
180{
181 int idx = 0;
182 int band_offset = 0;
183
184 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
185 if (rate_n_flags & RATE_MCS_HT_MSK) {
186 idx = (rate_n_flags & 0xff);
187 return idx;
188 /* Legacy rate format, search for match in table */
189 } else {
190 if (band == IEEE80211_BAND_5GHZ)
191 band_offset = IWL_FIRST_OFDM_RATE;
192 for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++)
193 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
194 return idx - band_offset;
195 }
196
197 return -1;
198}
199
76eff18b
TW
200u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant)
201{
202 int i;
203 u8 ind = ant;
204 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
205 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
206 if (priv->hw_params.valid_tx_ant & BIT(ind))
207 return ind;
208 }
209 return ant;
210}
47ff65c4 211EXPORT_SYMBOL(iwl_toggle_tx_ant);
57bd1bea
TW
212
213const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
214EXPORT_SYMBOL(iwl_bcast_addr);
215
216
1d0a082d
AK
217/* This function both allocates and initializes hw and priv. */
218struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
219 struct ieee80211_ops *hw_ops)
220{
221 struct iwl_priv *priv;
222
223 /* mac80211 allocates memory for this device instance, including
224 * space for this driver's private structure */
225 struct ieee80211_hw *hw =
226 ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
227 if (hw == NULL) {
a3139c59
SO
228 printk(KERN_ERR "%s: Can not allocate network device\n",
229 cfg->name);
1d0a082d
AK
230 goto out;
231 }
232
233 priv = hw->priv;
234 priv->hw = hw;
235
236out:
237 return hw;
238}
239EXPORT_SYMBOL(iwl_alloc_all);
240
b661c819
TW
241void iwl_hw_detect(struct iwl_priv *priv)
242{
243 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
244 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
245 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
246}
247EXPORT_SYMBOL(iwl_hw_detect);
248
1053d35f
RR
249int iwl_hw_nic_init(struct iwl_priv *priv)
250{
251 unsigned long flags;
252 struct iwl_rx_queue *rxq = &priv->rxq;
253 int ret;
254
255 /* nic_init */
1053d35f 256 spin_lock_irqsave(&priv->lock, flags);
1b73af82 257 priv->cfg->ops->lib->apm_ops.init(priv);
1053d35f
RR
258 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
259 spin_unlock_irqrestore(&priv->lock, flags);
260
261 ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
262
263 priv->cfg->ops->lib->apm_ops.config(priv);
264
265 /* Allocate the RX queue, or reset if it is already allocated */
266 if (!rxq->bd) {
267 ret = iwl_rx_queue_alloc(priv);
268 if (ret) {
15b1687c 269 IWL_ERR(priv, "Unable to initialize Rx queue\n");
1053d35f
RR
270 return -ENOMEM;
271 }
272 } else
273 iwl_rx_queue_reset(priv, rxq);
274
275 iwl_rx_replenish(priv);
276
277 iwl_rx_init(priv, rxq);
278
279 spin_lock_irqsave(&priv->lock, flags);
280
281 rxq->need_update = 1;
282 iwl_rx_queue_update_write_ptr(priv, rxq);
283
284 spin_unlock_irqrestore(&priv->lock, flags);
285
286 /* Allocate and init all Tx and Command queues */
287 ret = iwl_txq_ctx_reset(priv);
288 if (ret)
289 return ret;
290
291 set_bit(STATUS_INIT, &priv->status);
292
293 return 0;
294}
295EXPORT_SYMBOL(iwl_hw_nic_init);
296
14d2aac5
AK
297/*
298 * QoS support
299*/
300void iwl_activate_qos(struct iwl_priv *priv, u8 force)
301{
302 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
303 return;
304
305 priv->qos_data.def_qos_parm.qos_flags = 0;
306
307 if (priv->qos_data.qos_cap.q_AP.queue_request &&
308 !priv->qos_data.qos_cap.q_AP.txop_request)
309 priv->qos_data.def_qos_parm.qos_flags |=
310 QOS_PARAM_FLG_TXOP_TYPE_MSK;
311 if (priv->qos_data.qos_active)
312 priv->qos_data.def_qos_parm.qos_flags |=
313 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
314
315 if (priv->current_ht_config.is_ht)
316 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
317
318 if (force || iwl_is_associated(priv)) {
319 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
320 priv->qos_data.qos_active,
321 priv->qos_data.def_qos_parm.qos_flags);
322
323 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
324 sizeof(struct iwl_qosparam_cmd),
325 &priv->qos_data.def_qos_parm, NULL);
326 }
327}
328EXPORT_SYMBOL(iwl_activate_qos);
329
f2c95b04
WYG
330/*
331 * AC CWmin CW max AIFSN TXOP Limit TXOP Limit
332 * (802.11b) (802.11a/g)
333 * AC_BK 15 1023 7 0 0
334 * AC_BE 15 1023 3 0 0
335 * AC_VI 7 15 2 6.016ms 3.008ms
336 * AC_VO 3 7 2 3.264ms 1.504ms
337 */
c7de35cd 338void iwl_reset_qos(struct iwl_priv *priv)
bf85ea4f
AK
339{
340 u16 cw_min = 15;
341 u16 cw_max = 1023;
342 u8 aifs = 2;
30dab79e 343 bool is_legacy = false;
bf85ea4f
AK
344 unsigned long flags;
345 int i;
346
347 spin_lock_irqsave(&priv->lock, flags);
30dab79e
WT
348 /* QoS always active in AP and ADHOC mode
349 * In STA mode wait for association
350 */
351 if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
352 priv->iw_mode == NL80211_IFTYPE_AP)
353 priv->qos_data.qos_active = 1;
354 else
355 priv->qos_data.qos_active = 0;
bf85ea4f 356
30dab79e
WT
357 /* check for legacy mode */
358 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC &&
359 (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) ||
360 (priv->iw_mode == NL80211_IFTYPE_STATION &&
361 (priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) {
bf85ea4f
AK
362 cw_min = 31;
363 is_legacy = 1;
364 }
365
366 if (priv->qos_data.qos_active)
367 aifs = 3;
368
f2c95b04 369 /* AC_BE */
bf85ea4f
AK
370 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
371 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
372 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
373 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
374 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
375
376 if (priv->qos_data.qos_active) {
f2c95b04 377 /* AC_BK */
bf85ea4f
AK
378 i = 1;
379 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
380 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
381 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
382 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
383 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
384
f2c95b04 385 /* AC_VI */
bf85ea4f
AK
386 i = 2;
387 priv->qos_data.def_qos_parm.ac[i].cw_min =
388 cpu_to_le16((cw_min + 1) / 2 - 1);
389 priv->qos_data.def_qos_parm.ac[i].cw_max =
f2c95b04 390 cpu_to_le16(cw_min);
bf85ea4f
AK
391 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
392 if (is_legacy)
393 priv->qos_data.def_qos_parm.ac[i].edca_txop =
394 cpu_to_le16(6016);
395 else
396 priv->qos_data.def_qos_parm.ac[i].edca_txop =
397 cpu_to_le16(3008);
398 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
399
f2c95b04 400 /* AC_VO */
bf85ea4f
AK
401 i = 3;
402 priv->qos_data.def_qos_parm.ac[i].cw_min =
403 cpu_to_le16((cw_min + 1) / 4 - 1);
404 priv->qos_data.def_qos_parm.ac[i].cw_max =
f2c95b04 405 cpu_to_le16((cw_min + 1) / 2 - 1);
bf85ea4f
AK
406 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
407 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
408 if (is_legacy)
409 priv->qos_data.def_qos_parm.ac[i].edca_txop =
410 cpu_to_le16(3264);
411 else
412 priv->qos_data.def_qos_parm.ac[i].edca_txop =
413 cpu_to_le16(1504);
414 } else {
415 for (i = 1; i < 4; i++) {
416 priv->qos_data.def_qos_parm.ac[i].cw_min =
417 cpu_to_le16(cw_min);
418 priv->qos_data.def_qos_parm.ac[i].cw_max =
419 cpu_to_le16(cw_max);
420 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
421 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
422 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
423 }
424 }
e1623446 425 IWL_DEBUG_QOS(priv, "set QoS to default \n");
bf85ea4f
AK
426
427 spin_unlock_irqrestore(&priv->lock, flags);
428}
c7de35cd
RR
429EXPORT_SYMBOL(iwl_reset_qos);
430
d9fe60de
JB
431#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
432#define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
c7de35cd 433static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
d9fe60de 434 struct ieee80211_sta_ht_cap *ht_info,
c7de35cd
RR
435 enum ieee80211_band band)
436{
39130df3
RR
437 u16 max_bit_rate = 0;
438 u8 rx_chains_num = priv->hw_params.rx_chains_num;
439 u8 tx_chains_num = priv->hw_params.tx_chains_num;
440
c7de35cd 441 ht_info->cap = 0;
d9fe60de 442 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
c7de35cd 443
d9fe60de 444 ht_info->ht_supported = true;
c7de35cd 445
b261793d
DH
446 if (priv->cfg->ht_greenfield_support)
447 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
d9fe60de 448 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
3f3e0376
WYG
449 if (priv->cfg->support_sm_ps)
450 ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
451 (WLAN_HT_CAP_SM_PS_DYNAMIC << 2));
452 else
453 ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
454 (WLAN_HT_CAP_SM_PS_DISABLED << 2));
39130df3
RR
455
456 max_bit_rate = MAX_BIT_RATE_20_MHZ;
7aafef1c 457 if (priv->hw_params.ht40_channel & BIT(band)) {
d9fe60de
JB
458 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
459 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
460 ht_info->mcs.rx_mask[4] = 0x01;
39130df3 461 max_bit_rate = MAX_BIT_RATE_40_MHZ;
c7de35cd 462 }
c7de35cd
RR
463
464 if (priv->cfg->mod_params->amsdu_size_8K)
d9fe60de 465 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
c7de35cd
RR
466
467 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
468 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
469
d9fe60de 470 ht_info->mcs.rx_mask[0] = 0xFF;
39130df3 471 if (rx_chains_num >= 2)
d9fe60de 472 ht_info->mcs.rx_mask[1] = 0xFF;
39130df3 473 if (rx_chains_num >= 3)
d9fe60de 474 ht_info->mcs.rx_mask[2] = 0xFF;
39130df3
RR
475
476 /* Highest supported Rx data rate */
477 max_bit_rate *= rx_chains_num;
d9fe60de
JB
478 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
479 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
39130df3
RR
480
481 /* Tx MCS capabilities */
d9fe60de 482 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
39130df3 483 if (tx_chains_num != rx_chains_num) {
d9fe60de
JB
484 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
485 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
486 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
39130df3 487 }
c7de35cd 488}
c7de35cd 489
c7de35cd
RR
490/**
491 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
492 */
534166de 493int iwlcore_init_geos(struct iwl_priv *priv)
c7de35cd
RR
494{
495 struct iwl_channel_info *ch;
496 struct ieee80211_supported_band *sband;
497 struct ieee80211_channel *channels;
498 struct ieee80211_channel *geo_ch;
499 struct ieee80211_rate *rates;
500 int i = 0;
501
502 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
503 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
e1623446 504 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
c7de35cd
RR
505 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
506 return 0;
507 }
508
509 channels = kzalloc(sizeof(struct ieee80211_channel) *
510 priv->channel_count, GFP_KERNEL);
511 if (!channels)
512 return -ENOMEM;
513
5027309b 514 rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
c7de35cd
RR
515 GFP_KERNEL);
516 if (!rates) {
517 kfree(channels);
518 return -ENOMEM;
519 }
520
521 /* 5.2GHz channels start after the 2.4GHz channels */
522 sband = &priv->bands[IEEE80211_BAND_5GHZ];
523 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
524 /* just OFDM */
525 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
5027309b 526 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
c7de35cd 527
49779293 528 if (priv->cfg->sku & IWL_SKU_N)
d9fe60de 529 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
49779293 530 IEEE80211_BAND_5GHZ);
c7de35cd
RR
531
532 sband = &priv->bands[IEEE80211_BAND_2GHZ];
533 sband->channels = channels;
534 /* OFDM & CCK */
535 sband->bitrates = rates;
5027309b 536 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
c7de35cd 537
49779293 538 if (priv->cfg->sku & IWL_SKU_N)
d9fe60de 539 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
49779293 540 IEEE80211_BAND_2GHZ);
c7de35cd
RR
541
542 priv->ieee_channels = channels;
543 priv->ieee_rates = rates;
544
c7de35cd
RR
545 for (i = 0; i < priv->channel_count; i++) {
546 ch = &priv->channel_info[i];
547
548 /* FIXME: might be removed if scan is OK */
549 if (!is_channel_valid(ch))
550 continue;
551
552 if (is_channel_a_band(ch))
553 sband = &priv->bands[IEEE80211_BAND_5GHZ];
554 else
555 sband = &priv->bands[IEEE80211_BAND_2GHZ];
556
557 geo_ch = &sband->channels[sband->n_channels++];
558
559 geo_ch->center_freq =
560 ieee80211_channel_to_frequency(ch->channel);
561 geo_ch->max_power = ch->max_power_avg;
562 geo_ch->max_antenna_gain = 0xff;
563 geo_ch->hw_value = ch->channel;
564
565 if (is_channel_valid(ch)) {
566 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
567 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
568
569 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
570 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
571
572 if (ch->flags & EEPROM_CHANNEL_RADAR)
573 geo_ch->flags |= IEEE80211_CHAN_RADAR;
574
7aafef1c 575 geo_ch->flags |= ch->ht40_extension_channel;
4d38c2e8 576
dc1b0973
WYG
577 if (ch->max_power_avg > priv->tx_power_device_lmt)
578 priv->tx_power_device_lmt = ch->max_power_avg;
c7de35cd
RR
579 } else {
580 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
581 }
582
e1623446 583 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
c7de35cd
RR
584 ch->channel, geo_ch->center_freq,
585 is_channel_a_band(ch) ? "5.2" : "2.4",
586 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
587 "restricted" : "valid",
588 geo_ch->flags);
589 }
590
591 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
592 priv->cfg->sku & IWL_SKU_A) {
978785a3
TW
593 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
594 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
a3139c59
SO
595 priv->pci_dev->device,
596 priv->pci_dev->subsystem_device);
c7de35cd
RR
597 priv->cfg->sku &= ~IWL_SKU_A;
598 }
599
978785a3 600 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
a3139c59
SO
601 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
602 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
c7de35cd
RR
603
604 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
605
606 return 0;
607}
534166de 608EXPORT_SYMBOL(iwlcore_init_geos);
c7de35cd
RR
609
610/*
611 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
612 */
534166de 613void iwlcore_free_geos(struct iwl_priv *priv)
c7de35cd
RR
614{
615 kfree(priv->ieee_channels);
616 kfree(priv->ieee_rates);
617 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
618}
534166de 619EXPORT_SYMBOL(iwlcore_free_geos);
c7de35cd 620
37dc70fe
AK
621/*
622 * iwlcore_rts_tx_cmd_flag: Set rts/cts. 3945 and 4965 only share this
623 * function.
624 */
625void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
626 __le32 *tx_flags)
627{
628 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
629 *tx_flags |= TX_CMD_FLG_RTS_MSK;
630 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
631 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
632 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
633 *tx_flags |= TX_CMD_FLG_CTS_MSK;
634 }
635}
636EXPORT_SYMBOL(iwlcore_rts_tx_cmd_flag);
637
28a6b07a 638static bool is_single_rx_stream(struct iwl_priv *priv)
c7de35cd
RR
639{
640 return !priv->current_ht_config.is_ht ||
02bb1bea 641 priv->current_ht_config.single_chain_sufficient;
c7de35cd 642}
963f5517 643
47c5196e
TW
644static u8 iwl_is_channel_extension(struct iwl_priv *priv,
645 enum ieee80211_band band,
646 u16 channel, u8 extension_chan_offset)
647{
648 const struct iwl_channel_info *ch_info;
649
650 ch_info = iwl_get_channel_info(priv, band, channel);
651 if (!is_channel_valid(ch_info))
652 return 0;
653
d9fe60de 654 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
7aafef1c 655 return !(ch_info->ht40_extension_channel &
689da1b3 656 IEEE80211_CHAN_NO_HT40PLUS);
d9fe60de 657 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
7aafef1c 658 return !(ch_info->ht40_extension_channel &
689da1b3 659 IEEE80211_CHAN_NO_HT40MINUS);
47c5196e
TW
660
661 return 0;
662}
663
7aafef1c 664u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
d9fe60de 665 struct ieee80211_sta_ht_cap *sta_ht_inf)
47c5196e 666{
fad95bf5 667 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
47c5196e 668
fad95bf5 669 if (!ht_conf->is_ht || !ht_conf->is_40mhz)
47c5196e
TW
670 return 0;
671
a2b0f02e
WYG
672 /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
673 * the bit will not set if it is pure 40MHz case
674 */
47c5196e 675 if (sta_ht_inf) {
a2b0f02e 676 if (!sta_ht_inf->ht_supported)
47c5196e
TW
677 return 0;
678 }
1e4247d4
WYG
679#ifdef CONFIG_IWLWIFI_DEBUG
680 if (priv->disable_ht40)
681 return 0;
682#endif
611d3eb7
WYG
683 return iwl_is_channel_extension(priv, priv->band,
684 le16_to_cpu(priv->staging_rxon.channel),
fad95bf5 685 ht_conf->extension_chan_offset);
47c5196e 686}
7aafef1c 687EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
47c5196e 688
2c2f3b33
TW
689static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
690{
691 u16 new_val = 0;
692 u16 beacon_factor = 0;
693
694 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
695 new_val = beacon_val / beacon_factor;
696
697 if (!new_val)
698 new_val = max_beacon_val;
699
700 return new_val;
701}
702
703void iwl_setup_rxon_timing(struct iwl_priv *priv)
704{
705 u64 tsf;
706 s32 interval_tm, rem;
707 unsigned long flags;
708 struct ieee80211_conf *conf = NULL;
709 u16 beacon_int;
710
711 conf = ieee80211_get_hw_conf(priv->hw);
712
713 spin_lock_irqsave(&priv->lock, flags);
714 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
715 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
716
717 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
718 beacon_int = priv->beacon_int;
719 priv->rxon_timing.atim_window = 0;
720 } else {
721 beacon_int = priv->vif->bss_conf.beacon_int;
722
723 /* TODO: we need to get atim_window from upper stack
724 * for now we set to 0 */
725 priv->rxon_timing.atim_window = 0;
726 }
727
728 beacon_int = iwl_adjust_beacon_interval(beacon_int,
729 priv->hw_params.max_beacon_itrvl * 1024);
730 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
731
732 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
733 interval_tm = beacon_int * 1024;
734 rem = do_div(tsf, interval_tm);
735 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
736
737 spin_unlock_irqrestore(&priv->lock, flags);
738 IWL_DEBUG_ASSOC(priv,
739 "beacon interval %d beacon timer %d beacon tim %d\n",
740 le16_to_cpu(priv->rxon_timing.beacon_interval),
741 le32_to_cpu(priv->rxon_timing.beacon_init_val),
742 le16_to_cpu(priv->rxon_timing.atim_window));
743}
744EXPORT_SYMBOL(iwl_setup_rxon_timing);
745
8ccde88a
SO
746void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
747{
748 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
749
750 if (hw_decrypt)
751 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
752 else
753 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
754
755}
756EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
757
758/**
759 * iwl_check_rxon_cmd - validate RXON structure is valid
760 *
761 * NOTE: This is really only useful during development and can eventually
762 * be #ifdef'd out once the driver is stable and folks aren't actively
763 * making changes
764 */
765int iwl_check_rxon_cmd(struct iwl_priv *priv)
766{
767 int error = 0;
768 int counter = 1;
769 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
770
771 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
772 error |= le32_to_cpu(rxon->flags &
773 (RXON_FLG_TGJ_NARROW_BAND_MSK |
774 RXON_FLG_RADAR_DETECT_MSK));
775 if (error)
776 IWL_WARN(priv, "check 24G fields %d | %d\n",
777 counter++, error);
778 } else {
779 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
780 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
781 if (error)
782 IWL_WARN(priv, "check 52 fields %d | %d\n",
783 counter++, error);
784 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
785 if (error)
786 IWL_WARN(priv, "check 52 CCK %d | %d\n",
787 counter++, error);
788 }
789 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
790 if (error)
791 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
792
793 /* make sure basic rates 6Mbps and 1Mbps are supported */
794 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
795 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
796 if (error)
797 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
798
799 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
800 if (error)
801 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
802
803 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
804 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
805 if (error)
806 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
807 counter++, error);
808
809 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
810 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
811 if (error)
812 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
813 counter++, error);
814
815 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
816 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
817 if (error)
818 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
819 counter++, error);
820
821 if (error)
822 IWL_WARN(priv, "Tuning to channel %d\n",
823 le16_to_cpu(rxon->channel));
824
825 if (error) {
826 IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
827 return -1;
828 }
829 return 0;
830}
831EXPORT_SYMBOL(iwl_check_rxon_cmd);
832
833/**
834 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
835 * @priv: staging_rxon is compared to active_rxon
836 *
837 * If the RXON structure is changing enough to require a new tune,
838 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
839 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
840 */
841int iwl_full_rxon_required(struct iwl_priv *priv)
842{
843
844 /* These items are only settable from the full RXON command */
845 if (!(iwl_is_associated(priv)) ||
846 compare_ether_addr(priv->staging_rxon.bssid_addr,
847 priv->active_rxon.bssid_addr) ||
848 compare_ether_addr(priv->staging_rxon.node_addr,
849 priv->active_rxon.node_addr) ||
850 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
851 priv->active_rxon.wlap_bssid_addr) ||
852 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
853 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
854 (priv->staging_rxon.air_propagation !=
855 priv->active_rxon.air_propagation) ||
856 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
857 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
858 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
859 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
c2105fa7
DH
860 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
861 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
8ccde88a
SO
862 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
863 return 1;
864
865 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
866 * be updated with the RXON_ASSOC command -- however only some
867 * flag transitions are allowed using RXON_ASSOC */
868
869 /* Check if we are not switching bands */
870 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
871 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
872 return 1;
873
874 /* Check if we are switching association toggle */
875 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
876 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
877 return 1;
878
879 return 0;
880}
881EXPORT_SYMBOL(iwl_full_rxon_required);
882
883u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
884{
885 int i;
886 int rate_mask;
887
888 /* Set rate mask*/
889 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
890 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
891 else
892 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
893
894 /* Find lowest valid rate */
895 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
896 i = iwl_rates[i].next_ieee) {
897 if (rate_mask & (1 << i))
898 return iwl_rates[i].plcp;
899 }
900
901 /* No valid rate was found. Assign the lowest one */
902 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
903 return IWL_RATE_1M_PLCP;
904 else
905 return IWL_RATE_6M_PLCP;
906}
907EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
908
fad95bf5 909void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
47c5196e 910{
c1adf9fb 911 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
47c5196e 912
fad95bf5 913 if (!ht_conf->is_ht) {
a2b0f02e 914 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
42eb7c64 915 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
7aafef1c 916 RXON_FLG_HT40_PROT_MSK |
42eb7c64 917 RXON_FLG_HT_PROT_MSK);
47c5196e 918 return;
42eb7c64 919 }
47c5196e 920
a2b0f02e
WYG
921 /* FIXME: if the definition of ht_protection changed, the "translation"
922 * will be needed for rxon->flags
923 */
fad95bf5 924 rxon->flags |= cpu_to_le32(ht_conf->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
a2b0f02e
WYG
925
926 /* Set up channel bandwidth:
7aafef1c 927 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
a2b0f02e
WYG
928 /* clear the HT channel mode before set the mode */
929 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
930 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
7aafef1c
WYG
931 if (iwl_is_ht40_tx_allowed(priv, NULL)) {
932 /* pure ht40 */
fad95bf5 933 if (ht_conf->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
a2b0f02e 934 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
508b08e7 935 /* Note: control channel is opposite of extension channel */
fad95bf5 936 switch (ht_conf->extension_chan_offset) {
508b08e7
WYG
937 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
938 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
939 break;
940 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
941 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
942 break;
943 }
944 } else {
a2b0f02e 945 /* Note: control channel is opposite of extension channel */
fad95bf5 946 switch (ht_conf->extension_chan_offset) {
a2b0f02e
WYG
947 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
948 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
949 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
950 break;
951 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
952 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
953 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
954 break;
955 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
956 default:
957 /* channel location only valid if in Mixed mode */
958 IWL_ERR(priv, "invalid extension channel offset\n");
959 break;
960 }
961 }
962 } else {
963 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
47c5196e
TW
964 }
965
45823531
AK
966 if (priv->cfg->ops->hcmd->set_rxon_chain)
967 priv->cfg->ops->hcmd->set_rxon_chain(priv);
47c5196e 968
02bb1bea 969 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
ae5eb026 970 "extension channel offset 0x%x\n",
fad95bf5
JB
971 le32_to_cpu(rxon->flags), ht_conf->ht_protection,
972 ht_conf->extension_chan_offset);
47c5196e
TW
973 return;
974}
975EXPORT_SYMBOL(iwl_set_rxon_ht);
976
9e5e6c32
TW
977#define IWL_NUM_RX_CHAINS_MULTIPLE 3
978#define IWL_NUM_RX_CHAINS_SINGLE 2
979#define IWL_NUM_IDLE_CHAINS_DUAL 2
980#define IWL_NUM_IDLE_CHAINS_SINGLE 1
981
2b396a12
JB
982/*
983 * Determine how many receiver/antenna chains to use.
984 *
985 * More provides better reception via diversity. Fewer saves power
986 * at the expense of throughput, but only when not in powersave to
987 * start with.
988 *
c7de35cd
RR
989 * MIMO (dual stream) requires at least 2, but works better with 3.
990 * This does not determine *which* chains to use, just how many.
991 */
28a6b07a 992static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
c7de35cd 993{
c7de35cd 994 /* # of Rx chains to use when expecting MIMO. */
02bb1bea 995 if (is_single_rx_stream(priv))
9e5e6c32 996 return IWL_NUM_RX_CHAINS_SINGLE;
c7de35cd 997 else
9e5e6c32 998 return IWL_NUM_RX_CHAINS_MULTIPLE;
28a6b07a 999}
c7de35cd 1000
2b396a12 1001/*
3f3e0376
WYG
1002 * When we are in power saving mode, unless device support spatial
1003 * multiplexing power save, use the active count for rx chain count.
2b396a12 1004 */
28a6b07a
TW
1005static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
1006{
3f3e0376
WYG
1007 int idle_cnt = active_cnt;
1008 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
1009
1010 if (priv->cfg->support_sm_ps) {
1011 /* # Rx chains when idling and maybe trying to save power */
1012 switch (priv->current_ht_config.sm_ps) {
1013 case WLAN_HT_CAP_SM_PS_STATIC:
1014 case WLAN_HT_CAP_SM_PS_DYNAMIC:
1015 idle_cnt = (is_cam) ? IWL_NUM_IDLE_CHAINS_DUAL :
1016 IWL_NUM_IDLE_CHAINS_SINGLE;
1017 break;
1018 case WLAN_HT_CAP_SM_PS_DISABLED:
1019 idle_cnt = (is_cam) ? active_cnt :
1020 IWL_NUM_IDLE_CHAINS_SINGLE;
1021 break;
1022 case WLAN_HT_CAP_SM_PS_INVALID:
1023 default:
1024 IWL_ERR(priv, "invalid sm_ps mode %d\n",
1025 priv->current_ht_config.sm_ps);
1026 WARN_ON(1);
1027 break;
1028 }
1029 }
1030 return idle_cnt;
c7de35cd
RR
1031}
1032
04816448
GE
1033/* up to 4 chains */
1034static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
1035{
1036 u8 res;
1037 res = (chain_bitmap & BIT(0)) >> 0;
1038 res += (chain_bitmap & BIT(1)) >> 1;
1039 res += (chain_bitmap & BIT(2)) >> 2;
9bddbab3 1040 res += (chain_bitmap & BIT(3)) >> 3;
04816448
GE
1041 return res;
1042}
1043
4c4df78f
CR
1044/**
1045 * iwl_is_monitor_mode - Determine if interface in monitor mode
1046 *
1047 * priv->iw_mode is set in add_interface, but add_interface is
1048 * never called for monitor mode. The only way mac80211 informs us about
1049 * monitor mode is through configuring filters (call to configure_filter).
1050 */
279b05d4 1051bool iwl_is_monitor_mode(struct iwl_priv *priv)
4c4df78f
CR
1052{
1053 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
1054}
279b05d4 1055EXPORT_SYMBOL(iwl_is_monitor_mode);
4c4df78f 1056
c7de35cd
RR
1057/**
1058 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
1059 *
1060 * Selects how many and which Rx receivers/antennas/chains to use.
1061 * This should not be used for scan command ... it puts data in wrong place.
1062 */
1063void iwl_set_rxon_chain(struct iwl_priv *priv)
1064{
28a6b07a
TW
1065 bool is_single = is_single_rx_stream(priv);
1066 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
04816448
GE
1067 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
1068 u32 active_chains;
28a6b07a 1069 u16 rx_chain;
c7de35cd
RR
1070
1071 /* Tell uCode which antennas are actually connected.
1072 * Before first association, we assume all antennas are connected.
1073 * Just after first association, iwl_chain_noise_calibration()
1074 * checks which antennas actually *are* connected. */
04816448
GE
1075 if (priv->chain_noise_data.active_chains)
1076 active_chains = priv->chain_noise_data.active_chains;
1077 else
1078 active_chains = priv->hw_params.valid_rx_ant;
1079
1080 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
c7de35cd
RR
1081
1082 /* How many receivers should we use? */
28a6b07a
TW
1083 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
1084 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
1085
28a6b07a 1086
04816448
GE
1087 /* correct rx chain count according hw settings
1088 * and chain noise calibration
1089 */
1090 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
1091 if (valid_rx_cnt < active_rx_cnt)
1092 active_rx_cnt = valid_rx_cnt;
1093
1094 if (valid_rx_cnt < idle_rx_cnt)
1095 idle_rx_cnt = valid_rx_cnt;
28a6b07a
TW
1096
1097 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
1098 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
1099
7b841727
RF
1100 /* copied from 'iwl_bg_request_scan()' */
1101 /* Force use of chains B and C (0x6) for Rx for 4965
1102 * Avoid A (0x1) because of its off-channel reception on A-band.
1103 * MIMO is not used here, but value is required */
1104 if (iwl_is_monitor_mode(priv) &&
1105 !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) &&
1106 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) {
fff7a434
WYG
1107 rx_chain = ANT_ABC << RXON_RX_CHAIN_VALID_POS;
1108 rx_chain |= ANT_BC << RXON_RX_CHAIN_FORCE_SEL_POS;
1109 rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
1110 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
7b841727
RF
1111 }
1112
28a6b07a
TW
1113 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
1114
9e5e6c32 1115 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
c7de35cd
RR
1116 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
1117 else
1118 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
1119
e1623446 1120 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
28a6b07a
TW
1121 priv->staging_rxon.rx_chain,
1122 active_rx_cnt, idle_rx_cnt);
1123
1124 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
1125 active_rx_cnt < idle_rx_cnt);
c7de35cd
RR
1126}
1127EXPORT_SYMBOL(iwl_set_rxon_chain);
bf85ea4f
AK
1128
1129/**
17e72782 1130 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
bf85ea4f
AK
1131 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
1132 * @channel: Any channel valid for the requested phymode
1133
1134 * In addition to setting the staging RXON, priv->phymode is also set.
1135 *
1136 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
1137 * in the staging RXON flag structure based on the phymode
1138 */
17e72782 1139int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
bf85ea4f 1140{
17e72782
TW
1141 enum ieee80211_band band = ch->band;
1142 u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
1143
8622e705 1144 if (!iwl_get_channel_info(priv, band, channel)) {
e1623446 1145 IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
bf85ea4f
AK
1146 channel, band);
1147 return -EINVAL;
1148 }
1149
1150 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
1151 (priv->band == band))
1152 return 0;
1153
1154 priv->staging_rxon.channel = cpu_to_le16(channel);
1155 if (band == IEEE80211_BAND_5GHZ)
1156 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
1157 else
1158 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1159
1160 priv->band = band;
1161
e1623446 1162 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
bf85ea4f
AK
1163
1164 return 0;
1165}
c7de35cd 1166EXPORT_SYMBOL(iwl_set_rxon_channel);
bf85ea4f 1167
8ccde88a
SO
1168void iwl_set_flags_for_band(struct iwl_priv *priv,
1169 enum ieee80211_band band)
1170{
1171 if (band == IEEE80211_BAND_5GHZ) {
1172 priv->staging_rxon.flags &=
1173 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1174 | RXON_FLG_CCK_MSK);
1175 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1176 } else {
1177 /* Copied from iwl_post_associate() */
1178 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1179 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1180 else
1181 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1182
1183 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
1184 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1185
1186 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1187 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1188 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
1189 }
1190}
8ccde88a
SO
1191
1192/*
1193 * initialize rxon structure with default values from eeprom
1194 */
1195void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1196{
1197 const struct iwl_channel_info *ch_info;
1198
1199 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
1200
1201 switch (mode) {
1202 case NL80211_IFTYPE_AP:
1203 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
1204 break;
1205
1206 case NL80211_IFTYPE_STATION:
1207 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
1208 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1209 break;
1210
1211 case NL80211_IFTYPE_ADHOC:
1212 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1213 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1214 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1215 RXON_FILTER_ACCEPT_GRP_MSK;
1216 break;
1217
8ccde88a
SO
1218 default:
1219 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
1220 break;
1221 }
1222
1223#if 0
1224 /* TODO: Figure out when short_preamble would be set and cache from
1225 * that */
1226 if (!hw_to_local(priv->hw)->short_preamble)
1227 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1228 else
1229 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1230#endif
1231
1232 ch_info = iwl_get_channel_info(priv, priv->band,
1233 le16_to_cpu(priv->active_rxon.channel));
1234
1235 if (!ch_info)
1236 ch_info = &priv->channel_info[0];
1237
1238 /*
1239 * in some case A channels are all non IBSS
1240 * in this case force B/G channel
1241 */
1242 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
1243 !(is_channel_ibss(ch_info)))
1244 ch_info = &priv->channel_info[0];
1245
1246 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
1247 priv->band = ch_info->band;
1248
1249 iwl_set_flags_for_band(priv, priv->band);
1250
1251 priv->staging_rxon.ofdm_basic_rates =
1252 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1253 priv->staging_rxon.cck_basic_rates =
1254 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1255
a2b0f02e
WYG
1256 /* clear both MIX and PURE40 mode flag */
1257 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
1258 RXON_FLG_CHANNEL_MODE_PURE_40);
8ccde88a
SO
1259 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1260 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1261 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1262 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
11397a65 1263 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
8ccde88a
SO
1264}
1265EXPORT_SYMBOL(iwl_connection_init_rx_config);
1266
782571f4 1267static void iwl_set_rate(struct iwl_priv *priv)
8ccde88a
SO
1268{
1269 const struct ieee80211_supported_band *hw = NULL;
1270 struct ieee80211_rate *rate;
1271 int i;
1272
1273 hw = iwl_get_hw_mode(priv, priv->band);
1274 if (!hw) {
1275 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
1276 return;
1277 }
1278
1279 priv->active_rate = 0;
1280 priv->active_rate_basic = 0;
1281
1282 for (i = 0; i < hw->n_bitrates; i++) {
1283 rate = &(hw->bitrates[i]);
5027309b 1284 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
8ccde88a
SO
1285 priv->active_rate |= (1 << rate->hw_value);
1286 }
1287
e1623446 1288 IWL_DEBUG_RATE(priv, "Set active_rate = %0x, active_rate_basic = %0x\n",
8ccde88a
SO
1289 priv->active_rate, priv->active_rate_basic);
1290
1291 /*
1292 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1293 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1294 * OFDM
1295 */
1296 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
1297 priv->staging_rxon.cck_basic_rates =
1298 ((priv->active_rate_basic &
1299 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
1300 else
1301 priv->staging_rxon.cck_basic_rates =
1302 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1303
1304 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
1305 priv->staging_rxon.ofdm_basic_rates =
1306 ((priv->active_rate_basic &
1307 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
1308 IWL_FIRST_OFDM_RATE) & 0xFF;
1309 else
1310 priv->staging_rxon.ofdm_basic_rates =
1311 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1312}
8ccde88a
SO
1313
1314void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1315{
2f301227 1316 struct iwl_rx_packet *pkt = rxb_addr(rxb);
8ccde88a
SO
1317 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1318 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
4a56e965 1319
0924e519
WYG
1320 if (priv->switch_rxon.switch_in_progress) {
1321 if (!le32_to_cpu(csa->status) &&
1322 (csa->channel == priv->switch_rxon.channel)) {
1323 rxon->channel = csa->channel;
1324 priv->staging_rxon.channel = csa->channel;
1325 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
1326 le16_to_cpu(csa->channel));
1327 } else
1328 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
1329 le16_to_cpu(csa->channel));
1330
1331 priv->switch_rxon.switch_in_progress = false;
1332 }
8ccde88a
SO
1333}
1334EXPORT_SYMBOL(iwl_rx_csa);
1335
1336#ifdef CONFIG_IWLWIFI_DEBUG
a643565e 1337void iwl_print_rx_config_cmd(struct iwl_priv *priv)
8ccde88a
SO
1338{
1339 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1340
e1623446 1341 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
3d816c77 1342 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
e1623446
TW
1343 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1344 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1345 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
8ccde88a 1346 le32_to_cpu(rxon->filter_flags));
e1623446
TW
1347 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
1348 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
8ccde88a 1349 rxon->ofdm_basic_rates);
e1623446
TW
1350 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1351 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
1352 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
1353 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
8ccde88a 1354}
a643565e 1355EXPORT_SYMBOL(iwl_print_rx_config_cmd);
6686d17e 1356#endif
8ccde88a
SO
1357/**
1358 * iwl_irq_handle_error - called for HW or SW error interrupt from card
1359 */
1360void iwl_irq_handle_error(struct iwl_priv *priv)
1361{
1362 /* Set the FW error flag -- cleared on iwl_down */
1363 set_bit(STATUS_FW_ERROR, &priv->status);
1364
1365 /* Cancel currently queued command. */
1366 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1367
1368#ifdef CONFIG_IWLWIFI_DEBUG
3d816c77 1369 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) {
b7a79404
RC
1370 priv->cfg->ops->lib->dump_nic_error_log(priv);
1371 priv->cfg->ops->lib->dump_nic_event_log(priv);
8ccde88a
SO
1372 iwl_print_rx_config_cmd(priv);
1373 }
1374#endif
1375
1376 wake_up_interruptible(&priv->wait_command_queue);
1377
1378 /* Keep the restart process from trying to send host
1379 * commands by clearing the INIT status bit */
1380 clear_bit(STATUS_READY, &priv->status);
1381
1382 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
e1623446 1383 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
8ccde88a
SO
1384 "Restarting adapter due to uCode error.\n");
1385
8ccde88a
SO
1386 if (priv->cfg->mod_params->restart_fw)
1387 queue_work(priv->workqueue, &priv->restart);
1388 }
1389}
1390EXPORT_SYMBOL(iwl_irq_handle_error);
1391
d68b603c
AK
1392int iwl_apm_stop_master(struct iwl_priv *priv)
1393{
5220af0c 1394 int ret = 0;
d68b603c 1395
5220af0c 1396 /* stop device's busmaster DMA activity */
d68b603c
AK
1397 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1398
5220af0c 1399 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
d68b603c 1400 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
5220af0c
BC
1401 if (ret)
1402 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
d68b603c 1403
d68b603c
AK
1404 IWL_DEBUG_INFO(priv, "stop master\n");
1405
5220af0c 1406 return ret;
d68b603c
AK
1407}
1408EXPORT_SYMBOL(iwl_apm_stop_master);
1409
1410void iwl_apm_stop(struct iwl_priv *priv)
1411{
fadb3582
BC
1412 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1413
5220af0c 1414 /* Stop device's DMA activity */
d68b603c
AK
1415 iwl_apm_stop_master(priv);
1416
5220af0c 1417 /* Reset the entire device */
d68b603c
AK
1418 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1419
1420 udelay(10);
5220af0c
BC
1421
1422 /*
1423 * Clear "initialization complete" bit to move adapter from
1424 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1425 */
d68b603c 1426 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
d68b603c
AK
1427}
1428EXPORT_SYMBOL(iwl_apm_stop);
1429
fadb3582
BC
1430
1431/*
1432 * Start up NIC's basic functionality after it has been reset
1433 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1434 * NOTE: This does not load uCode nor start the embedded processor
1435 */
1436int iwl_apm_init(struct iwl_priv *priv)
1437{
1438 int ret = 0;
1439 u16 lctl;
1440
1441 IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
1442
1443 /*
1444 * Use "set_bit" below rather than "write", to preserve any hardware
1445 * bits already set by default after reset.
1446 */
1447
1448 /* Disable L0S exit timer (platform NMI Work/Around) */
1449 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1450 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1451
1452 /*
1453 * Disable L0s without affecting L1;
1454 * don't wait for ICH L0s (ICH bug W/A)
1455 */
1456 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1457 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1458
1459 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1460 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
1461
1462 /*
1463 * Enable HAP INTA (interrupt from management bus) to
1464 * wake device's PCI Express link L1a -> L0s
1465 * NOTE: This is no-op for 3945 (non-existant bit)
1466 */
1467 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1468 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1469
1470 /*
a6c5c731
BC
1471 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1472 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1473 * If so (likely), disable L0S, so device moves directly L0->L1;
1474 * costs negligible amount of power savings.
1475 * If not (unlikely), enable L0S, so there is at least some
1476 * power savings, even without L1.
fadb3582
BC
1477 */
1478 if (priv->cfg->set_l0s) {
1479 lctl = iwl_pcie_link_ctl(priv);
1480 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1481 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1482 /* L1-ASPM enabled; disable(!) L0S */
1483 iwl_set_bit(priv, CSR_GIO_REG,
1484 CSR_GIO_REG_VAL_L0S_ENABLED);
1485 IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
1486 } else {
1487 /* L1-ASPM disabled; enable(!) L0S */
1488 iwl_clear_bit(priv, CSR_GIO_REG,
1489 CSR_GIO_REG_VAL_L0S_ENABLED);
1490 IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
1491 }
1492 }
1493
1494 /* Configure analog phase-lock-loop before activating to D0A */
1495 if (priv->cfg->pll_cfg_val)
1496 iwl_set_bit(priv, CSR_ANA_PLL_CFG, priv->cfg->pll_cfg_val);
1497
1498 /*
1499 * Set "initialization complete" bit to move adapter from
1500 * D0U* --> D0A* (powered-up active) state.
1501 */
1502 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1503
1504 /*
1505 * Wait for clock stabilization; once stabilized, access to
1506 * device-internal resources is supported, e.g. iwl_write_prph()
1507 * and accesses to uCode SRAM.
1508 */
1509 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
1510 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1511 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1512 if (ret < 0) {
1513 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
1514 goto out;
1515 }
1516
1517 /*
1518 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1519 * BSM (Boostrap State Machine) is only in 3945 and 4965;
1520 * later devices (i.e. 5000 and later) have non-volatile SRAM,
1521 * and don't need BSM to restore data after power-saving sleep.
1522 *
1523 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1524 * do not disable clocks. This preserves any hardware bits already
1525 * set by default in "CLK_CTRL_REG" after reset.
1526 */
1527 if (priv->cfg->use_bsm)
1528 iwl_write_prph(priv, APMG_CLK_EN_REG,
1529 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1530 else
1531 iwl_write_prph(priv, APMG_CLK_EN_REG,
1532 APMG_CLK_VAL_DMA_CLK_RQT);
1533 udelay(20);
1534
1535 /* Disable L1-Active */
1536 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1537 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1538
1539out:
1540 return ret;
1541}
1542EXPORT_SYMBOL(iwl_apm_init);
1543
1544
1545
8ccde88a
SO
1546void iwl_configure_filter(struct ieee80211_hw *hw,
1547 unsigned int changed_flags,
1548 unsigned int *total_flags,
3ac64bee 1549 u64 multicast)
8ccde88a
SO
1550{
1551 struct iwl_priv *priv = hw->priv;
1552 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
1553
e1623446 1554 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
8ccde88a
SO
1555 changed_flags, *total_flags);
1556
1557 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
1558 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
1559 *filter_flags |= RXON_FILTER_PROMISC_MSK;
1560 else
1561 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
1562 }
1563 if (changed_flags & FIF_ALLMULTI) {
1564 if (*total_flags & FIF_ALLMULTI)
1565 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
1566 else
1567 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
1568 }
1569 if (changed_flags & FIF_CONTROL) {
1570 if (*total_flags & FIF_CONTROL)
1571 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
1572 else
1573 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
1574 }
1575 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
1576 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
1577 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1578 else
1579 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
1580 }
1581
1582 /* We avoid iwl_commit_rxon here to commit the new filter flags
1583 * since mac80211 will call ieee80211_hw_config immediately.
1584 * (mc_list is not supported at this time). Otherwise, we need to
1585 * queue a background iwl_commit_rxon work.
1586 */
1587
1588 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
1589 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
1590}
1591EXPORT_SYMBOL(iwl_configure_filter);
1592
da154e30
RR
1593int iwl_set_hw_params(struct iwl_priv *priv)
1594{
da154e30
RR
1595 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1596 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1597 if (priv->cfg->mod_params->amsdu_size_8K)
2f301227 1598 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
da154e30 1599 else
2f301227 1600 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
da154e30 1601
2c2f3b33
TW
1602 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
1603
49779293
RR
1604 if (priv->cfg->mod_params->disable_11n)
1605 priv->cfg->sku &= ~IWL_SKU_N;
1606
da154e30
RR
1607 /* Device-specific setup */
1608 return priv->cfg->ops->lib->set_hw_params(priv);
1609}
1610EXPORT_SYMBOL(iwl_set_hw_params);
6ba87956 1611
630fe9b6
TW
1612int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1613{
1614 int ret = 0;
5eadd94b
WYG
1615 s8 prev_tx_power = priv->tx_power_user_lmt;
1616
630fe9b6 1617 if (tx_power < IWL_TX_POWER_TARGET_POWER_MIN) {
daf518de
WF
1618 IWL_WARN(priv, "Requested user TXPOWER %d below lower limit %d.\n",
1619 tx_power,
1620 IWL_TX_POWER_TARGET_POWER_MIN);
630fe9b6
TW
1621 return -EINVAL;
1622 }
1623
dc1b0973 1624 if (tx_power > priv->tx_power_device_lmt) {
08f2d58d
WYG
1625 IWL_WARN(priv,
1626 "Requested user TXPOWER %d above upper limit %d.\n",
dc1b0973 1627 tx_power, priv->tx_power_device_lmt);
630fe9b6
TW
1628 return -EINVAL;
1629 }
1630
1631 if (priv->tx_power_user_lmt != tx_power)
1632 force = true;
1633
019fb97d 1634 /* if nic is not up don't send command */
5eadd94b
WYG
1635 if (iwl_is_ready_rf(priv)) {
1636 priv->tx_power_user_lmt = tx_power;
1637 if (force && priv->cfg->ops->lib->send_tx_power)
1638 ret = priv->cfg->ops->lib->send_tx_power(priv);
1639 else if (!priv->cfg->ops->lib->send_tx_power)
1640 ret = -EOPNOTSUPP;
1641 /*
1642 * if fail to set tx_power, restore the orig. tx power
1643 */
1644 if (ret)
1645 priv->tx_power_user_lmt = prev_tx_power;
1646 }
630fe9b6 1647
5eadd94b
WYG
1648 /*
1649 * Even this is an async host command, the command
1650 * will always report success from uCode
1651 * So once driver can placing the command into the queue
1652 * successfully, driver can use priv->tx_power_user_lmt
1653 * to reflect the current tx power
1654 */
630fe9b6
TW
1655 return ret;
1656}
1657EXPORT_SYMBOL(iwl_set_tx_power);
1658
ef850d7c
MA
1659#define ICT_COUNT (PAGE_SIZE/sizeof(u32))
1660
1661/* Free dram table */
1662void iwl_free_isr_ict(struct iwl_priv *priv)
1663{
1664 if (priv->ict_tbl_vir) {
1665 pci_free_consistent(priv->pci_dev, (sizeof(u32) * ICT_COUNT) +
1666 PAGE_SIZE, priv->ict_tbl_vir,
1667 priv->ict_tbl_dma);
1668 priv->ict_tbl_vir = NULL;
1669 }
1670}
1671EXPORT_SYMBOL(iwl_free_isr_ict);
1672
1673
1674/* allocate dram shared table it is a PAGE_SIZE aligned
1675 * also reset all data related to ICT table interrupt.
1676 */
1677int iwl_alloc_isr_ict(struct iwl_priv *priv)
1678{
1679
1680 if (priv->cfg->use_isr_legacy)
1681 return 0;
1682 /* allocate shrared data table */
1683 priv->ict_tbl_vir = pci_alloc_consistent(priv->pci_dev, (sizeof(u32) *
1684 ICT_COUNT) + PAGE_SIZE,
1685 &priv->ict_tbl_dma);
1686 if (!priv->ict_tbl_vir)
1687 return -ENOMEM;
1688
1689 /* align table to PAGE_SIZE boundry */
1690 priv->aligned_ict_tbl_dma = ALIGN(priv->ict_tbl_dma, PAGE_SIZE);
1691
1692 IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
1693 (unsigned long long)priv->ict_tbl_dma,
1694 (unsigned long long)priv->aligned_ict_tbl_dma,
1695 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1696
1697 priv->ict_tbl = priv->ict_tbl_vir +
1698 (priv->aligned_ict_tbl_dma - priv->ict_tbl_dma);
1699
1700 IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
1701 priv->ict_tbl, priv->ict_tbl_vir,
1702 (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
1703
1704 /* reset table and index to all 0 */
1705 memset(priv->ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
1706 priv->ict_index = 0;
1707
40cefda9
MA
1708 /* add periodic RX interrupt */
1709 priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
ef850d7c
MA
1710 return 0;
1711}
1712EXPORT_SYMBOL(iwl_alloc_isr_ict);
1713
1714/* Device is going up inform it about using ICT interrupt table,
1715 * also we need to tell the driver to start using ICT interrupt.
1716 */
1717int iwl_reset_ict(struct iwl_priv *priv)
1718{
1719 u32 val;
1720 unsigned long flags;
1721
1722 if (!priv->ict_tbl_vir)
1723 return 0;
1724
1725 spin_lock_irqsave(&priv->lock, flags);
1726 iwl_disable_interrupts(priv);
1727
1303dcfd 1728 memset(&priv->ict_tbl[0], 0, sizeof(u32) * ICT_COUNT);
ef850d7c
MA
1729
1730 val = priv->aligned_ict_tbl_dma >> PAGE_SHIFT;
1731
1732 val |= CSR_DRAM_INT_TBL_ENABLE;
1733 val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
1734
1735 IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
1736 "aligned dma address %Lx\n",
1737 val, (unsigned long long)priv->aligned_ict_tbl_dma);
1738
1739 iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
1740 priv->use_ict = true;
1741 priv->ict_index = 0;
40cefda9 1742 iwl_write32(priv, CSR_INT, priv->inta_mask);
ef850d7c
MA
1743 iwl_enable_interrupts(priv);
1744 spin_unlock_irqrestore(&priv->lock, flags);
1745
1746 return 0;
1747}
1748EXPORT_SYMBOL(iwl_reset_ict);
1749
1750/* Device is going down disable ict interrupt usage */
1751void iwl_disable_ict(struct iwl_priv *priv)
1752{
1753 unsigned long flags;
1754
1755 spin_lock_irqsave(&priv->lock, flags);
1756 priv->use_ict = false;
1757 spin_unlock_irqrestore(&priv->lock, flags);
1758}
1759EXPORT_SYMBOL(iwl_disable_ict);
1760
1761/* interrupt handler using ict table, with this interrupt driver will
1762 * stop using INTA register to get device's interrupt, reading this register
1763 * is expensive, device will write interrupts in ICT dram table, increment
1764 * index then will fire interrupt to driver, driver will OR all ICT table
1765 * entries from current index up to table entry with 0 value. the result is
1766 * the interrupt we need to service, driver will set the entries back to 0 and
1767 * set index.
1768 */
1769irqreturn_t iwl_isr_ict(int irq, void *data)
1770{
1771 struct iwl_priv *priv = data;
1772 u32 inta, inta_mask;
1773 u32 val = 0;
1774
1775 if (!priv)
1776 return IRQ_NONE;
1777
1778 /* dram interrupt table not set yet,
1779 * use legacy interrupt.
1780 */
1781 if (!priv->use_ict)
1782 return iwl_isr(irq, data);
1783
1784 spin_lock(&priv->lock);
1785
1786 /* Disable (but don't clear!) interrupts here to avoid
1787 * back-to-back ISRs and sporadic interrupts from our NIC.
1788 * If we have something to service, the tasklet will re-enable ints.
1789 * If we *don't* have something, we'll re-enable before leaving here.
1790 */
1791 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1792 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1793
1794
1795 /* Ignore interrupt if there's nothing in NIC to service.
1796 * This may be due to IRQ shared with another device,
1797 * or due to sporadic interrupts thrown from our NIC. */
1798 if (!priv->ict_tbl[priv->ict_index]) {
1799 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1800 goto none;
1801 }
1802
1803 /* read all entries that not 0 start with ict_index */
1804 while (priv->ict_tbl[priv->ict_index]) {
1805
1303dcfd 1806 val |= le32_to_cpu(priv->ict_tbl[priv->ict_index]);
ef850d7c 1807 IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
1303dcfd
JB
1808 priv->ict_index,
1809 le32_to_cpu(priv->ict_tbl[priv->ict_index]));
ef850d7c
MA
1810 priv->ict_tbl[priv->ict_index] = 0;
1811 priv->ict_index = iwl_queue_inc_wrap(priv->ict_index,
1303dcfd 1812 ICT_COUNT);
ef850d7c
MA
1813
1814 }
1815
1816 /* We should not get this value, just ignore it. */
1817 if (val == 0xffffffff)
1818 val = 0;
1819
1820 inta = (0xff & val) | ((0xff00 & val) << 16);
1821 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
1822 inta, inta_mask, val);
1823
40cefda9 1824 inta &= priv->inta_mask;
ef850d7c
MA
1825 priv->inta |= inta;
1826
1827 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1828 if (likely(inta))
1829 tasklet_schedule(&priv->irq_tasklet);
1830 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta) {
1831 /* Allow interrupt if was disabled by this handler and
1832 * no tasklet was schedules, We should not enable interrupt,
1833 * tasklet will enable it.
1834 */
1835 iwl_enable_interrupts(priv);
1836 }
1837
1838 spin_unlock(&priv->lock);
1839 return IRQ_HANDLED;
1840
1841 none:
1842 /* re-enable interrupts here since we don't have anything to service.
1843 * only Re-enable if disabled by irq.
1844 */
1845 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1846 iwl_enable_interrupts(priv);
1847
1848 spin_unlock(&priv->lock);
1849 return IRQ_NONE;
1850}
1851EXPORT_SYMBOL(iwl_isr_ict);
1852
1853
1854static irqreturn_t iwl_isr(int irq, void *data)
1855{
1856 struct iwl_priv *priv = data;
1857 u32 inta, inta_mask;
d651ae32 1858#ifdef CONFIG_IWLWIFI_DEBUG
ef850d7c 1859 u32 inta_fh;
d651ae32 1860#endif
ef850d7c
MA
1861 if (!priv)
1862 return IRQ_NONE;
1863
1864 spin_lock(&priv->lock);
1865
1866 /* Disable (but don't clear!) interrupts here to avoid
1867 * back-to-back ISRs and sporadic interrupts from our NIC.
1868 * If we have something to service, the tasklet will re-enable ints.
1869 * If we *don't* have something, we'll re-enable before leaving here. */
1870 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1871 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1872
1873 /* Discover which interrupts are active/pending */
1874 inta = iwl_read32(priv, CSR_INT);
1875
1876 /* Ignore interrupt if there's nothing in NIC to service.
1877 * This may be due to IRQ shared with another device,
1878 * or due to sporadic interrupts thrown from our NIC. */
1879 if (!inta) {
1880 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
1881 goto none;
1882 }
1883
1884 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1885 /* Hardware disappeared. It might have already raised
1886 * an interrupt */
1887 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1888 goto unplugged;
1889 }
1890
1891#ifdef CONFIG_IWLWIFI_DEBUG
3d816c77 1892 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
ef850d7c
MA
1893 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1894 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
1895 "fh 0x%08x\n", inta, inta_mask, inta_fh);
1896 }
1897#endif
1898
1899 priv->inta |= inta;
1900 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1901 if (likely(inta))
1902 tasklet_schedule(&priv->irq_tasklet);
1903 else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1904 iwl_enable_interrupts(priv);
1905
1906 unplugged:
1907 spin_unlock(&priv->lock);
1908 return IRQ_HANDLED;
1909
1910 none:
1911 /* re-enable interrupts here since we don't have anything to service. */
1912 /* only Re-enable if diabled by irq and no schedules tasklet. */
1913 if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
1914 iwl_enable_interrupts(priv);
1915
1916 spin_unlock(&priv->lock);
1917 return IRQ_NONE;
1918}
1919
1920irqreturn_t iwl_isr_legacy(int irq, void *data)
f17d08a6
AK
1921{
1922 struct iwl_priv *priv = data;
1923 u32 inta, inta_mask;
1924 u32 inta_fh;
1925 if (!priv)
1926 return IRQ_NONE;
1927
1928 spin_lock(&priv->lock);
1929
1930 /* Disable (but don't clear!) interrupts here to avoid
1931 * back-to-back ISRs and sporadic interrupts from our NIC.
1932 * If we have something to service, the tasklet will re-enable ints.
1933 * If we *don't* have something, we'll re-enable before leaving here. */
1934 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1935 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1936
1937 /* Discover which interrupts are active/pending */
1938 inta = iwl_read32(priv, CSR_INT);
1939 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1940
1941 /* Ignore interrupt if there's nothing in NIC to service.
1942 * This may be due to IRQ shared with another device,
1943 * or due to sporadic interrupts thrown from our NIC. */
1944 if (!inta && !inta_fh) {
1945 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
1946 goto none;
1947 }
1948
1949 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1950 /* Hardware disappeared. It might have already raised
1951 * an interrupt */
1952 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1953 goto unplugged;
1954 }
1955
1956 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1957 inta, inta_mask, inta_fh);
1958
1959 inta &= ~CSR_INT_BIT_SCD;
1960
1961 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1962 if (likely(inta || inta_fh))
1963 tasklet_schedule(&priv->irq_tasklet);
1964
1965 unplugged:
1966 spin_unlock(&priv->lock);
1967 return IRQ_HANDLED;
1968
1969 none:
1970 /* re-enable interrupts here since we don't have anything to service. */
1971 /* only Re-enable if diabled by irq */
1972 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1973 iwl_enable_interrupts(priv);
1974 spin_unlock(&priv->lock);
1975 return IRQ_NONE;
1976}
ef850d7c 1977EXPORT_SYMBOL(iwl_isr_legacy);
f17d08a6 1978
17f841cd
SO
1979int iwl_send_bt_config(struct iwl_priv *priv)
1980{
1981 struct iwl_bt_cmd bt_cmd = {
456d0f76
WYG
1982 .flags = BT_COEX_MODE_4W,
1983 .lead_time = BT_LEAD_TIME_DEF,
1984 .max_kill = BT_MAX_KILL_DEF,
17f841cd
SO
1985 .kill_ack_mask = 0,
1986 .kill_cts_mask = 0,
1987 };
1988
1989 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1990 sizeof(struct iwl_bt_cmd), &bt_cmd);
1991}
1992EXPORT_SYMBOL(iwl_send_bt_config);
1993
ef8d5529 1994int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
49ea8596 1995{
ef8d5529
WYG
1996 struct iwl_statistics_cmd statistics_cmd = {
1997 .configuration_flags =
1998 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
49ea8596 1999 };
ef8d5529
WYG
2000
2001 if (flags & CMD_ASYNC)
2002 return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
2003 sizeof(struct iwl_statistics_cmd),
2004 &statistics_cmd, NULL);
2005 else
2006 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
2007 sizeof(struct iwl_statistics_cmd),
2008 &statistics_cmd);
49ea8596
EG
2009}
2010EXPORT_SYMBOL(iwl_send_statistics_request);
7e8c519e 2011
b0692f2f
EG
2012/**
2013 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
2014 * using sample data 100 bytes apart. If these sample points are good,
2015 * it's a pretty good bet that everything between them is good, too.
2016 */
2017static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
2018{
2019 u32 val;
2020 int ret = 0;
2021 u32 errcnt = 0;
2022 u32 i;
2023
e1623446 2024 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
b0692f2f 2025
b0692f2f
EG
2026 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2027 /* read data comes through single port, auto-incr addr */
2028 /* NOTE: Use the debugless read so we don't flood kernel log
2029 * if IWL_DL_IO is set */
2030 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
250bdd21 2031 i + IWL49_RTC_INST_LOWER_BOUND);
b0692f2f
EG
2032 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2033 if (val != le32_to_cpu(*image)) {
2034 ret = -EIO;
2035 errcnt++;
2036 if (errcnt >= 3)
2037 break;
2038 }
2039 }
2040
b0692f2f
EG
2041 return ret;
2042}
2043
2044/**
2045 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
2046 * looking at all data.
2047 */
2048static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
2049 u32 len)
2050{
2051 u32 val;
2052 u32 save_len = len;
2053 int ret = 0;
2054 u32 errcnt;
2055
e1623446 2056 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
b0692f2f 2057
250bdd21
SO
2058 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2059 IWL49_RTC_INST_LOWER_BOUND);
b0692f2f
EG
2060
2061 errcnt = 0;
2062 for (; len > 0; len -= sizeof(u32), image++) {
2063 /* read data comes through single port, auto-incr addr */
2064 /* NOTE: Use the debugless read so we don't flood kernel log
2065 * if IWL_DL_IO is set */
2066 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2067 if (val != le32_to_cpu(*image)) {
15b1687c 2068 IWL_ERR(priv, "uCode INST section is invalid at "
b0692f2f
EG
2069 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2070 save_len - len, val, le32_to_cpu(*image));
2071 ret = -EIO;
2072 errcnt++;
2073 if (errcnt >= 20)
2074 break;
2075 }
2076 }
2077
b0692f2f 2078 if (!errcnt)
e1623446
TW
2079 IWL_DEBUG_INFO(priv,
2080 "ucode image in INSTRUCTION memory is good\n");
b0692f2f
EG
2081
2082 return ret;
2083}
2084
2085/**
2086 * iwl_verify_ucode - determine which instruction image is in SRAM,
2087 * and verify its contents
2088 */
2089int iwl_verify_ucode(struct iwl_priv *priv)
2090{
2091 __le32 *image;
2092 u32 len;
2093 int ret;
2094
2095 /* Try bootstrap */
2096 image = (__le32 *)priv->ucode_boot.v_addr;
2097 len = priv->ucode_boot.len;
2098 ret = iwlcore_verify_inst_sparse(priv, image, len);
2099 if (!ret) {
e1623446 2100 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
b0692f2f
EG
2101 return 0;
2102 }
2103
2104 /* Try initialize */
2105 image = (__le32 *)priv->ucode_init.v_addr;
2106 len = priv->ucode_init.len;
2107 ret = iwlcore_verify_inst_sparse(priv, image, len);
2108 if (!ret) {
e1623446 2109 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
b0692f2f
EG
2110 return 0;
2111 }
2112
2113 /* Try runtime/protocol */
2114 image = (__le32 *)priv->ucode_code.v_addr;
2115 len = priv->ucode_code.len;
2116 ret = iwlcore_verify_inst_sparse(priv, image, len);
2117 if (!ret) {
e1623446 2118 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
b0692f2f
EG
2119 return 0;
2120 }
2121
15b1687c 2122 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
b0692f2f
EG
2123
2124 /* Since nothing seems to match, show first several data entries in
2125 * instruction SRAM, so maybe visual inspection will give a clue.
2126 * Selection of bootstrap image (vs. other images) is arbitrary. */
2127 image = (__le32 *)priv->ucode_boot.v_addr;
2128 len = priv->ucode_boot.len;
2129 ret = iwl_verify_inst_full(priv, image, len);
2130
2131 return ret;
2132}
2133EXPORT_SYMBOL(iwl_verify_ucode);
2134
56e12615 2135
47f4a587
EG
2136void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2137{
2138 struct iwl_ct_kill_config cmd;
672639de 2139 struct iwl_ct_kill_throttling_config adv_cmd;
47f4a587
EG
2140 unsigned long flags;
2141 int ret = 0;
2142
2143 spin_lock_irqsave(&priv->lock, flags);
2144 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2145 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2146 spin_unlock_irqrestore(&priv->lock, flags);
3ad3b92a 2147 priv->thermal_throttle.ct_kill_toggle = false;
47f4a587 2148
480e8407 2149 if (priv->cfg->support_ct_kill_exit) {
672639de
WYG
2150 adv_cmd.critical_temperature_enter =
2151 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2152 adv_cmd.critical_temperature_exit =
2153 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2154
2155 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2156 sizeof(adv_cmd), &adv_cmd);
d91b1ba3
WYG
2157 if (ret)
2158 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2159 else
2160 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2161 "succeeded, "
2162 "critical temperature enter is %d,"
2163 "exit is %d\n",
2164 priv->hw_params.ct_kill_threshold,
2165 priv->hw_params.ct_kill_exit_threshold);
480e8407 2166 } else {
672639de
WYG
2167 cmd.critical_temperature_R =
2168 cpu_to_le32(priv->hw_params.ct_kill_threshold);
189a2b59 2169
672639de
WYG
2170 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2171 sizeof(cmd), &cmd);
d91b1ba3
WYG
2172 if (ret)
2173 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2174 else
2175 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2176 "succeeded, "
2177 "critical temperature is %d\n",
2178 priv->hw_params.ct_kill_threshold);
672639de 2179 }
47f4a587
EG
2180}
2181EXPORT_SYMBOL(iwl_rf_kill_ct_config);
14a08a7f 2182
0ad91a35 2183
14a08a7f
EG
2184/*
2185 * CARD_STATE_CMD
2186 *
2187 * Use: Sets the device's internal card state to enable, disable, or halt
2188 *
2189 * When in the 'enable' state the card operates as normal.
2190 * When in the 'disable' state, the card enters into a low power mode.
2191 * When in the 'halt' state, the card is shut down and must be fully
2192 * restarted to come back on.
2193 */
c496294e 2194int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
14a08a7f
EG
2195{
2196 struct iwl_host_cmd cmd = {
2197 .id = REPLY_CARD_STATE_CMD,
2198 .len = sizeof(u32),
2199 .data = &flags,
c2acea8e 2200 .flags = meta_flag,
14a08a7f
EG
2201 };
2202
2203 return iwl_send_cmd(priv, &cmd);
2204}
2205
030f05ed
AK
2206void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
2207 struct iwl_rx_mem_buffer *rxb)
2208{
2209#ifdef CONFIG_IWLWIFI_DEBUG
2f301227 2210 struct iwl_rx_packet *pkt = rxb_addr(rxb);
030f05ed
AK
2211 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
2212 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
2213 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2214#endif
2215}
2216EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
2217
2218void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
2219 struct iwl_rx_mem_buffer *rxb)
2220{
2f301227 2221 struct iwl_rx_packet *pkt = rxb_addr(rxb);
396887a2 2222 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
030f05ed 2223 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
396887a2
DH
2224 "notification for %s:\n", len,
2225 get_cmd_string(pkt->hdr.cmd));
2226 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
030f05ed
AK
2227}
2228EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
261b9c33
AK
2229
2230void iwl_rx_reply_error(struct iwl_priv *priv,
2231 struct iwl_rx_mem_buffer *rxb)
2232{
2f301227 2233 struct iwl_rx_packet *pkt = rxb_addr(rxb);
261b9c33
AK
2234
2235 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
2236 "seq 0x%04X ser 0x%08X\n",
2237 le32_to_cpu(pkt->u.err_resp.error_type),
2238 get_cmd_string(pkt->u.err_resp.cmd_id),
2239 pkt->u.err_resp.cmd_id,
2240 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
2241 le32_to_cpu(pkt->u.err_resp.error_info));
2242}
2243EXPORT_SYMBOL(iwl_rx_reply_error);
2244
a83b9141
WYG
2245void iwl_clear_isr_stats(struct iwl_priv *priv)
2246{
2247 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
2248}
a83b9141 2249
488829f1
AK
2250int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2251 const struct ieee80211_tx_queue_params *params)
2252{
2253 struct iwl_priv *priv = hw->priv;
2254 unsigned long flags;
2255 int q;
2256
2257 IWL_DEBUG_MAC80211(priv, "enter\n");
2258
2259 if (!iwl_is_ready_rf(priv)) {
2260 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2261 return -EIO;
2262 }
2263
2264 if (queue >= AC_NUM) {
2265 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
2266 return 0;
2267 }
2268
2269 q = AC_NUM - 1 - queue;
2270
2271 spin_lock_irqsave(&priv->lock, flags);
2272
2273 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
2274 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2275 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2276 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2277 cpu_to_le16((params->txop * 32));
2278
2279 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2280 priv->qos_data.qos_active = 1;
2281
2282 if (priv->iw_mode == NL80211_IFTYPE_AP)
2283 iwl_activate_qos(priv, 1);
2284 else if (priv->assoc_id && iwl_is_associated(priv))
2285 iwl_activate_qos(priv, 0);
2286
2287 spin_unlock_irqrestore(&priv->lock, flags);
2288
2289 IWL_DEBUG_MAC80211(priv, "leave\n");
2290 return 0;
2291}
2292EXPORT_SYMBOL(iwl_mac_conf_tx);
5bbe233b
AK
2293
2294static void iwl_ht_conf(struct iwl_priv *priv,
02bb1bea 2295 struct ieee80211_bss_conf *bss_conf)
5bbe233b 2296{
fad95bf5 2297 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
5bbe233b
AK
2298 struct ieee80211_sta *sta;
2299
2300 IWL_DEBUG_MAC80211(priv, "enter: \n");
2301
fad95bf5 2302 if (!ht_conf->is_ht)
5bbe233b
AK
2303 return;
2304
fad95bf5 2305 ht_conf->ht_protection =
9ed6bcce 2306 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
fad95bf5 2307 ht_conf->non_GF_STA_present =
9ed6bcce 2308 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
5bbe233b 2309
02bb1bea
JB
2310 ht_conf->single_chain_sufficient = false;
2311
2312 switch (priv->iw_mode) {
2313 case NL80211_IFTYPE_STATION:
2314 rcu_read_lock();
5ed176e1 2315 sta = ieee80211_find_sta(priv->vif, priv->bssid);
02bb1bea
JB
2316 if (sta) {
2317 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2318 int maxstreams;
2319
2320 maxstreams = (ht_cap->mcs.tx_params &
2321 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
2322 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
2323 maxstreams += 1;
2324
2325 if ((ht_cap->mcs.rx_mask[1] == 0) &&
2326 (ht_cap->mcs.rx_mask[2] == 0))
2327 ht_conf->single_chain_sufficient = true;
2328 if (maxstreams <= 1)
2329 ht_conf->single_chain_sufficient = true;
2330 } else {
2331 /*
2332 * If at all, this can only happen through a race
2333 * when the AP disconnects us while we're still
2334 * setting up the connection, in that case mac80211
2335 * will soon tell us about that.
2336 */
2337 ht_conf->single_chain_sufficient = true;
2338 }
2339 rcu_read_unlock();
2340 break;
2341 case NL80211_IFTYPE_ADHOC:
2342 ht_conf->single_chain_sufficient = true;
2343 break;
2344 default:
2345 break;
2346 }
5bbe233b
AK
2347
2348 IWL_DEBUG_MAC80211(priv, "leave\n");
2349}
2350
2351#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2352void iwl_bss_info_changed(struct ieee80211_hw *hw,
2d0ddec5
JB
2353 struct ieee80211_vif *vif,
2354 struct ieee80211_bss_conf *bss_conf,
2355 u32 changes)
5bbe233b
AK
2356{
2357 struct iwl_priv *priv = hw->priv;
3a650292 2358 int ret;
5bbe233b
AK
2359
2360 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2361
2d0ddec5
JB
2362 if (!iwl_is_alive(priv))
2363 return;
2364
2365 mutex_lock(&priv->mutex);
2366
2367 if (changes & BSS_CHANGED_BEACON &&
2368 priv->iw_mode == NL80211_IFTYPE_AP) {
2369 dev_kfree_skb(priv->ibss_beacon);
2370 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2371 }
2372
d7129e19
JB
2373 if (changes & BSS_CHANGED_BEACON_INT) {
2374 priv->beacon_int = bss_conf->beacon_int;
2375 /* TODO: in AP mode, do something to make this take effect */
2376 }
2377
2378 if (changes & BSS_CHANGED_BSSID) {
2379 IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
2380
2381 /*
2382 * If there is currently a HW scan going on in the
2383 * background then we need to cancel it else the RXON
2384 * below/in post_associate will fail.
2385 */
2d0ddec5 2386 if (iwl_scan_cancel_timeout(priv, 100)) {
d7129e19 2387 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
2d0ddec5
JB
2388 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2389 mutex_unlock(&priv->mutex);
2390 return;
2391 }
2d0ddec5 2392
d7129e19
JB
2393 /* mac80211 only sets assoc when in STATION mode */
2394 if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
2395 bss_conf->assoc) {
2396 memcpy(priv->staging_rxon.bssid_addr,
2397 bss_conf->bssid, ETH_ALEN);
2d0ddec5 2398
d7129e19
JB
2399 /* currently needed in a few places */
2400 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
2401 } else {
2402 priv->staging_rxon.filter_flags &=
2403 ~RXON_FILTER_ASSOC_MSK;
2d0ddec5 2404 }
d7129e19 2405
2d0ddec5
JB
2406 }
2407
d7129e19
JB
2408 /*
2409 * This needs to be after setting the BSSID in case
2410 * mac80211 decides to do both changes at once because
2411 * it will invoke post_associate.
2412 */
2d0ddec5
JB
2413 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2414 changes & BSS_CHANGED_BEACON) {
2415 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2416
2417 if (beacon)
2418 iwl_mac_beacon_update(hw, beacon);
2419 }
2420
5bbe233b
AK
2421 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2422 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2423 bss_conf->use_short_preamble);
2424 if (bss_conf->use_short_preamble)
2425 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2426 else
2427 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2428 }
2429
2430 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2431 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2432 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2433 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2434 else
2435 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2436 }
2437
d7129e19
JB
2438 if (changes & BSS_CHANGED_BASIC_RATES) {
2439 /* XXX use this information
2440 *
2441 * To do that, remove code from iwl_set_rate() and put something
2442 * like this here:
2443 *
2444 if (A-band)
2445 priv->staging_rxon.ofdm_basic_rates =
2446 bss_conf->basic_rates;
2447 else
2448 priv->staging_rxon.ofdm_basic_rates =
2449 bss_conf->basic_rates >> 4;
2450 priv->staging_rxon.cck_basic_rates =
2451 bss_conf->basic_rates & 0xF;
2452 */
2453 }
2454
5bbe233b
AK
2455 if (changes & BSS_CHANGED_HT) {
2456 iwl_ht_conf(priv, bss_conf);
45823531
AK
2457
2458 if (priv->cfg->ops->hcmd->set_rxon_chain)
2459 priv->cfg->ops->hcmd->set_rxon_chain(priv);
5bbe233b
AK
2460 }
2461
2462 if (changes & BSS_CHANGED_ASSOC) {
2463 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
5bbe233b
AK
2464 if (bss_conf->assoc) {
2465 priv->assoc_id = bss_conf->aid;
2466 priv->beacon_int = bss_conf->beacon_int;
5bbe233b
AK
2467 priv->timestamp = bss_conf->timestamp;
2468 priv->assoc_capability = bss_conf->assoc_capability;
2469
e932a609
JB
2470 iwl_led_associate(priv);
2471
d7129e19
JB
2472 /*
2473 * We have just associated, don't start scan too early
2474 * leave time for EAPOL exchange to complete.
2475 *
2476 * XXX: do this in mac80211
5bbe233b
AK
2477 */
2478 priv->next_scan_jiffies = jiffies +
2479 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
d7129e19
JB
2480 if (!iwl_is_rfkill(priv))
2481 priv->cfg->ops->lib->post_associate(priv);
e932a609 2482 } else {
5bbe233b 2483 priv->assoc_id = 0;
e932a609
JB
2484 iwl_led_disassociate(priv);
2485 }
d7129e19
JB
2486 }
2487
2488 if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2489 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
2490 changes);
2491 ret = iwl_send_rxon_assoc(priv);
2492 if (!ret) {
2493 /* Sync active_rxon with latest change. */
2494 memcpy((void *)&priv->active_rxon,
2495 &priv->staging_rxon,
2496 sizeof(struct iwl_rxon_cmd));
5bbe233b 2497 }
5bbe233b 2498 }
d7129e19
JB
2499
2500 mutex_unlock(&priv->mutex);
2501
2d0ddec5 2502 IWL_DEBUG_MAC80211(priv, "leave\n");
5bbe233b
AK
2503}
2504EXPORT_SYMBOL(iwl_bss_info_changed);
2505
9944b938
AK
2506int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2507{
2508 struct iwl_priv *priv = hw->priv;
2509 unsigned long flags;
2510 __le64 timestamp;
2511
2512 IWL_DEBUG_MAC80211(priv, "enter\n");
2513
2514 if (!iwl_is_ready_rf(priv)) {
2515 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2516 return -EIO;
2517 }
2518
2519 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2520 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2521 return -EIO;
2522 }
2523
2524 spin_lock_irqsave(&priv->lock, flags);
2525
2526 if (priv->ibss_beacon)
2527 dev_kfree_skb(priv->ibss_beacon);
2528
2529 priv->ibss_beacon = skb;
2530
2531 priv->assoc_id = 0;
2532 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2533 priv->timestamp = le64_to_cpu(timestamp);
2534
2535 IWL_DEBUG_MAC80211(priv, "leave\n");
2536 spin_unlock_irqrestore(&priv->lock, flags);
2537
2538 iwl_reset_qos(priv);
2539
2540 priv->cfg->ops->lib->post_associate(priv);
2541
2542
2543 return 0;
2544}
2545EXPORT_SYMBOL(iwl_mac_beacon_update);
2546
727882d6
AK
2547int iwl_set_mode(struct iwl_priv *priv, int mode)
2548{
2549 if (mode == NL80211_IFTYPE_ADHOC) {
2550 const struct iwl_channel_info *ch_info;
2551
2552 ch_info = iwl_get_channel_info(priv,
2553 priv->band,
2554 le16_to_cpu(priv->staging_rxon.channel));
2555
2556 if (!ch_info || !is_channel_ibss(ch_info)) {
2557 IWL_ERR(priv, "channel %d not IBSS channel\n",
2558 le16_to_cpu(priv->staging_rxon.channel));
2559 return -EINVAL;
2560 }
2561 }
2562
2563 iwl_connection_init_rx_config(priv, mode);
2564
2565 if (priv->cfg->ops->hcmd->set_rxon_chain)
2566 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2567
2568 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2569
c587de0b 2570 iwl_clear_stations_table(priv);
727882d6
AK
2571
2572 /* dont commit rxon if rf-kill is on*/
2573 if (!iwl_is_ready_rf(priv))
2574 return -EAGAIN;
2575
727882d6
AK
2576 iwlcore_commit_rxon(priv);
2577
2578 return 0;
2579}
2580EXPORT_SYMBOL(iwl_set_mode);
2581
cbb6ab94
AK
2582int iwl_mac_add_interface(struct ieee80211_hw *hw,
2583 struct ieee80211_if_init_conf *conf)
2584{
2585 struct iwl_priv *priv = hw->priv;
2586 unsigned long flags;
2587
2588 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
2589
2590 if (priv->vif) {
2591 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2592 return -EOPNOTSUPP;
2593 }
2594
2595 spin_lock_irqsave(&priv->lock, flags);
2596 priv->vif = conf->vif;
2597 priv->iw_mode = conf->type;
2598
2599 spin_unlock_irqrestore(&priv->lock, flags);
2600
2601 mutex_lock(&priv->mutex);
2602
2603 if (conf->mac_addr) {
2604 IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
2605 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2606 }
2607
2608 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2609 /* we are not ready, will run again when ready */
2610 set_bit(STATUS_MODE_PENDING, &priv->status);
2611
2612 mutex_unlock(&priv->mutex);
2613
2614 IWL_DEBUG_MAC80211(priv, "leave\n");
2615 return 0;
2616}
2617EXPORT_SYMBOL(iwl_mac_add_interface);
2618
d8052319
AK
2619void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2620 struct ieee80211_if_init_conf *conf)
2621{
2622 struct iwl_priv *priv = hw->priv;
2623
2624 IWL_DEBUG_MAC80211(priv, "enter\n");
2625
2626 mutex_lock(&priv->mutex);
2627
2628 if (iwl_is_ready_rf(priv)) {
2629 iwl_scan_cancel_timeout(priv, 100);
2630 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2631 iwlcore_commit_rxon(priv);
2632 }
2633 if (priv->vif == conf->vif) {
2634 priv->vif = NULL;
2635 memset(priv->bssid, 0, ETH_ALEN);
2636 }
2637 mutex_unlock(&priv->mutex);
2638
2639 IWL_DEBUG_MAC80211(priv, "leave\n");
2640
2641}
2642EXPORT_SYMBOL(iwl_mac_remove_interface);
2643
4808368d
AK
2644/**
2645 * iwl_mac_config - mac80211 config callback
2646 *
2647 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2648 * be set inappropriately and the driver currently sets the hardware up to
2649 * use it whenever needed.
2650 */
2651int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2652{
2653 struct iwl_priv *priv = hw->priv;
2654 const struct iwl_channel_info *ch_info;
2655 struct ieee80211_conf *conf = &hw->conf;
fad95bf5 2656 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
4808368d
AK
2657 unsigned long flags = 0;
2658 int ret = 0;
2659 u16 ch;
2660 int scan_active = 0;
2661
2662 mutex_lock(&priv->mutex);
2663
4808368d
AK
2664 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2665 conf->channel->hw_value, changed);
2666
2667 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2668 test_bit(STATUS_SCANNING, &priv->status))) {
2669 scan_active = 1;
2670 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2671 }
2672
2673
2674 /* during scanning mac80211 will delay channel setting until
2675 * scan finish with changed = 0
2676 */
2677 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2678 if (scan_active)
2679 goto set_ch_out;
2680
2681 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2682 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2683 if (!is_channel_valid(ch_info)) {
2684 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2685 ret = -EINVAL;
2686 goto set_ch_out;
2687 }
2688
2689 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2690 !is_channel_ibss(ch_info)) {
2691 IWL_ERR(priv, "channel %d in band %d not "
2692 "IBSS channel\n",
2693 conf->channel->hw_value, conf->channel->band);
2694 ret = -EINVAL;
2695 goto set_ch_out;
2696 }
2697
4808368d
AK
2698 spin_lock_irqsave(&priv->lock, flags);
2699
28bd723b
DH
2700 /* Configure HT40 channels */
2701 ht_conf->is_ht = conf_is_ht(conf);
2702 if (ht_conf->is_ht) {
2703 if (conf_is_ht40_minus(conf)) {
2704 ht_conf->extension_chan_offset =
2705 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
c812ee24 2706 ht_conf->is_40mhz = true;
28bd723b
DH
2707 } else if (conf_is_ht40_plus(conf)) {
2708 ht_conf->extension_chan_offset =
2709 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
c812ee24 2710 ht_conf->is_40mhz = true;
28bd723b
DH
2711 } else {
2712 ht_conf->extension_chan_offset =
2713 IEEE80211_HT_PARAM_CHA_SEC_NONE;
c812ee24 2714 ht_conf->is_40mhz = false;
28bd723b
DH
2715 }
2716 } else
c812ee24 2717 ht_conf->is_40mhz = false;
28bd723b
DH
2718 /* Default to no protection. Protection mode will later be set
2719 * from BSS config in iwl_ht_conf */
2720 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
4808368d
AK
2721
2722 /* if we are switching from ht to 2.4 clear flags
2723 * from any ht related info since 2.4 does not
2724 * support ht */
2725 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2726 priv->staging_rxon.flags = 0;
2727
2728 iwl_set_rxon_channel(priv, conf->channel);
2729
2730 iwl_set_flags_for_band(priv, conf->channel->band);
2731 spin_unlock_irqrestore(&priv->lock, flags);
0924e519
WYG
2732 if (iwl_is_associated(priv) &&
2733 (le16_to_cpu(priv->active_rxon.channel) != ch) &&
2734 priv->cfg->ops->lib->set_channel_switch) {
2735 iwl_set_rate(priv);
2736 /*
2737 * at this point, staging_rxon has the
2738 * configuration for channel switch
2739 */
2740 ret = priv->cfg->ops->lib->set_channel_switch(priv,
2741 ch);
2742 if (!ret) {
2743 iwl_print_rx_config_cmd(priv);
2744 goto out;
2745 }
2746 priv->switch_rxon.switch_in_progress = false;
2747 }
4808368d
AK
2748 set_ch_out:
2749 /* The list of supported rates and rate mask can be different
2750 * for each band; since the band may have changed, reset
2751 * the rate mask to what mac80211 lists */
2752 iwl_set_rate(priv);
2753 }
2754
78f5fb7f
JB
2755 if (changed & (IEEE80211_CONF_CHANGE_PS |
2756 IEEE80211_CONF_CHANGE_IDLE)) {
e312c24c 2757 ret = iwl_power_update_mode(priv, false);
4808368d 2758 if (ret)
e312c24c 2759 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
4808368d
AK
2760 }
2761
2762 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2763 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2764 priv->tx_power_user_lmt, conf->power_level);
2765
2766 iwl_set_tx_power(priv, conf->power_level, false);
2767 }
2768
2769 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2770 if (priv->cfg->ops->hcmd->set_rxon_chain)
2771 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2772
0cf4c01e
MA
2773 if (!iwl_is_ready(priv)) {
2774 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2775 goto out;
2776 }
2777
4808368d
AK
2778 if (scan_active)
2779 goto out;
2780
2781 if (memcmp(&priv->active_rxon,
2782 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2783 iwlcore_commit_rxon(priv);
2784 else
2785 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
2786
2787
2788out:
2789 IWL_DEBUG_MAC80211(priv, "leave\n");
2790 mutex_unlock(&priv->mutex);
2791 return ret;
2792}
2793EXPORT_SYMBOL(iwl_mac_config);
2794
aa89f31e
AK
2795int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2796 struct ieee80211_tx_queue_stats *stats)
2797{
2798 struct iwl_priv *priv = hw->priv;
2799 int i, avail;
2800 struct iwl_tx_queue *txq;
2801 struct iwl_queue *q;
2802 unsigned long flags;
2803
2804 IWL_DEBUG_MAC80211(priv, "enter\n");
2805
2806 if (!iwl_is_ready_rf(priv)) {
2807 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2808 return -EIO;
2809 }
2810
2811 spin_lock_irqsave(&priv->lock, flags);
2812
2813 for (i = 0; i < AC_NUM; i++) {
2814 txq = &priv->txq[i];
2815 q = &txq->q;
2816 avail = iwl_queue_space(q);
2817
2818 stats[i].len = q->n_window - avail;
2819 stats[i].limit = q->n_window - q->high_mark;
2820 stats[i].count = q->n_window;
2821
2822 }
2823 spin_unlock_irqrestore(&priv->lock, flags);
2824
2825 IWL_DEBUG_MAC80211(priv, "leave\n");
2826
2827 return 0;
2828}
2829EXPORT_SYMBOL(iwl_mac_get_tx_stats);
2830
bd564261
AK
2831void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2832{
2833 struct iwl_priv *priv = hw->priv;
2834 unsigned long flags;
2835
2836 mutex_lock(&priv->mutex);
2837 IWL_DEBUG_MAC80211(priv, "enter\n");
2838
2839 spin_lock_irqsave(&priv->lock, flags);
fad95bf5 2840 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
bd564261
AK
2841 spin_unlock_irqrestore(&priv->lock, flags);
2842
2843 iwl_reset_qos(priv);
2844
2845 spin_lock_irqsave(&priv->lock, flags);
2846 priv->assoc_id = 0;
2847 priv->assoc_capability = 0;
2848 priv->assoc_station_added = 0;
2849
2850 /* new association get rid of ibss beacon skb */
2851 if (priv->ibss_beacon)
2852 dev_kfree_skb(priv->ibss_beacon);
2853
2854 priv->ibss_beacon = NULL;
2855
57c4d7b4 2856 priv->beacon_int = priv->vif->bss_conf.beacon_int;
bd564261
AK
2857 priv->timestamp = 0;
2858 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2859 priv->beacon_int = 0;
2860
2861 spin_unlock_irqrestore(&priv->lock, flags);
2862
2863 if (!iwl_is_ready_rf(priv)) {
2864 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2865 mutex_unlock(&priv->mutex);
2866 return;
2867 }
2868
2869 /* we are restarting association process
2870 * clear RXON_FILTER_ASSOC_MSK bit
2871 */
2872 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2873 iwl_scan_cancel_timeout(priv, 100);
2874 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2875 iwlcore_commit_rxon(priv);
2876 }
2877
bd564261 2878 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
bd564261
AK
2879 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2880 mutex_unlock(&priv->mutex);
2881 return;
2882 }
2883
2884 iwl_set_rate(priv);
2885
2886 mutex_unlock(&priv->mutex);
2887
2888 IWL_DEBUG_MAC80211(priv, "leave\n");
2889}
2890EXPORT_SYMBOL(iwl_mac_reset_tsf);
2891
88804e2b
WYG
2892int iwl_alloc_txq_mem(struct iwl_priv *priv)
2893{
2894 if (!priv->txq)
2895 priv->txq = kzalloc(
2896 sizeof(struct iwl_tx_queue) * priv->cfg->num_of_queues,
2897 GFP_KERNEL);
2898 if (!priv->txq) {
2899 IWL_ERR(priv, "Not enough memory for txq \n");
2900 return -ENOMEM;
2901 }
2902 return 0;
2903}
2904EXPORT_SYMBOL(iwl_alloc_txq_mem);
2905
2906void iwl_free_txq_mem(struct iwl_priv *priv)
2907{
2908 kfree(priv->txq);
2909 priv->txq = NULL;
2910}
2911EXPORT_SYMBOL(iwl_free_txq_mem);
2912
1933ac4d
WYG
2913int iwl_send_wimax_coex(struct iwl_priv *priv)
2914{
2915 struct iwl_wimax_coex_cmd uninitialized_var(coex_cmd);
2916
2917 if (priv->cfg->support_wimax_coexist) {
2918 /* UnMask wake up src at associated sleep */
2919 coex_cmd.flags |= COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
2920
2921 /* UnMask wake up src at unassociated sleep */
2922 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
2923 memcpy(coex_cmd.sta_prio, cu_priorities,
2924 sizeof(struct iwl_wimax_coex_event_entry) *
2925 COEX_NUM_OF_EVENTS);
2926
2927 /* enabling the coexistence feature */
2928 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
2929
2930 /* enabling the priorities tables */
2931 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
2932 } else {
2933 /* coexistence is disabled */
2934 memset(&coex_cmd, 0, sizeof(coex_cmd));
2935 }
2936 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
2937 sizeof(coex_cmd), &coex_cmd);
2938}
2939EXPORT_SYMBOL(iwl_send_wimax_coex);
2940
20594eb0
WYG
2941#ifdef CONFIG_IWLWIFI_DEBUGFS
2942
2943#define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
2944
2945void iwl_reset_traffic_log(struct iwl_priv *priv)
2946{
2947 priv->tx_traffic_idx = 0;
2948 priv->rx_traffic_idx = 0;
2949 if (priv->tx_traffic)
2950 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2951 if (priv->rx_traffic)
2952 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2953}
2954
2955int iwl_alloc_traffic_mem(struct iwl_priv *priv)
2956{
2957 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
2958
2959 if (iwl_debug_level & IWL_DL_TX) {
2960 if (!priv->tx_traffic) {
2961 priv->tx_traffic =
2962 kzalloc(traffic_size, GFP_KERNEL);
2963 if (!priv->tx_traffic)
2964 return -ENOMEM;
2965 }
2966 }
2967 if (iwl_debug_level & IWL_DL_RX) {
2968 if (!priv->rx_traffic) {
2969 priv->rx_traffic =
2970 kzalloc(traffic_size, GFP_KERNEL);
2971 if (!priv->rx_traffic)
2972 return -ENOMEM;
2973 }
2974 }
2975 iwl_reset_traffic_log(priv);
2976 return 0;
2977}
2978EXPORT_SYMBOL(iwl_alloc_traffic_mem);
2979
2980void iwl_free_traffic_mem(struct iwl_priv *priv)
2981{
2982 kfree(priv->tx_traffic);
2983 priv->tx_traffic = NULL;
2984
2985 kfree(priv->rx_traffic);
2986 priv->rx_traffic = NULL;
2987}
2988EXPORT_SYMBOL(iwl_free_traffic_mem);
2989
2990void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
2991 u16 length, struct ieee80211_hdr *header)
2992{
2993 __le16 fc;
2994 u16 len;
2995
2996 if (likely(!(iwl_debug_level & IWL_DL_TX)))
2997 return;
2998
2999 if (!priv->tx_traffic)
3000 return;
3001
3002 fc = header->frame_control;
3003 if (ieee80211_is_data(fc)) {
3004 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
3005 ? IWL_TRAFFIC_ENTRY_SIZE : length;
3006 memcpy((priv->tx_traffic +
3007 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
3008 header, len);
3009 priv->tx_traffic_idx =
3010 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
3011 }
3012}
3013EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
3014
3015void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
3016 u16 length, struct ieee80211_hdr *header)
3017{
3018 __le16 fc;
3019 u16 len;
3020
3021 if (likely(!(iwl_debug_level & IWL_DL_RX)))
3022 return;
3023
3024 if (!priv->rx_traffic)
3025 return;
3026
3027 fc = header->frame_control;
3028 if (ieee80211_is_data(fc)) {
3029 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
3030 ? IWL_TRAFFIC_ENTRY_SIZE : length;
3031 memcpy((priv->rx_traffic +
3032 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
3033 header, len);
3034 priv->rx_traffic_idx =
3035 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
3036 }
3037}
3038EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
22fdf3c9
WYG
3039
3040const char *get_mgmt_string(int cmd)
3041{
3042 switch (cmd) {
3043 IWL_CMD(MANAGEMENT_ASSOC_REQ);
3044 IWL_CMD(MANAGEMENT_ASSOC_RESP);
3045 IWL_CMD(MANAGEMENT_REASSOC_REQ);
3046 IWL_CMD(MANAGEMENT_REASSOC_RESP);
3047 IWL_CMD(MANAGEMENT_PROBE_REQ);
3048 IWL_CMD(MANAGEMENT_PROBE_RESP);
3049 IWL_CMD(MANAGEMENT_BEACON);
3050 IWL_CMD(MANAGEMENT_ATIM);
3051 IWL_CMD(MANAGEMENT_DISASSOC);
3052 IWL_CMD(MANAGEMENT_AUTH);
3053 IWL_CMD(MANAGEMENT_DEAUTH);
3054 IWL_CMD(MANAGEMENT_ACTION);
3055 default:
3056 return "UNKNOWN";
3057
3058 }
3059}
3060
3061const char *get_ctrl_string(int cmd)
3062{
3063 switch (cmd) {
3064 IWL_CMD(CONTROL_BACK_REQ);
3065 IWL_CMD(CONTROL_BACK);
3066 IWL_CMD(CONTROL_PSPOLL);
3067 IWL_CMD(CONTROL_RTS);
3068 IWL_CMD(CONTROL_CTS);
3069 IWL_CMD(CONTROL_ACK);
3070 IWL_CMD(CONTROL_CFEND);
3071 IWL_CMD(CONTROL_CFENDACK);
3072 default:
3073 return "UNKNOWN";
3074
3075 }
3076}
3077
3078void iwl_clear_tx_stats(struct iwl_priv *priv)
3079{
3080 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
3081
3082}
3083
3084void iwl_clear_rx_stats(struct iwl_priv *priv)
3085{
3086 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
3087}
3088
3089/*
3090 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
3091 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
3092 * Use debugFs to display the rx/rx_statistics
3093 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
3094 * information will be recorded, but DATA pkt still will be recorded
3095 * for the reason of iwl_led.c need to control the led blinking based on
3096 * number of tx and rx data.
3097 *
3098 */
3099void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
3100{
3101 struct traffic_stats *stats;
3102
3103 if (is_tx)
3104 stats = &priv->tx_stats;
3105 else
3106 stats = &priv->rx_stats;
3107
3108 if (ieee80211_is_mgmt(fc)) {
3109 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
3110 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
3111 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
3112 break;
3113 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3114 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
3115 break;
3116 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
3117 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
3118 break;
3119 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3120 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
3121 break;
3122 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3123 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
3124 break;
3125 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3126 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
3127 break;
3128 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3129 stats->mgmt[MANAGEMENT_BEACON]++;
3130 break;
3131 case cpu_to_le16(IEEE80211_STYPE_ATIM):
3132 stats->mgmt[MANAGEMENT_ATIM]++;
3133 break;
3134 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3135 stats->mgmt[MANAGEMENT_DISASSOC]++;
3136 break;
3137 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3138 stats->mgmt[MANAGEMENT_AUTH]++;
3139 break;
3140 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3141 stats->mgmt[MANAGEMENT_DEAUTH]++;
3142 break;
3143 case cpu_to_le16(IEEE80211_STYPE_ACTION):
3144 stats->mgmt[MANAGEMENT_ACTION]++;
3145 break;
3146 }
3147 } else if (ieee80211_is_ctl(fc)) {
3148 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
3149 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
3150 stats->ctrl[CONTROL_BACK_REQ]++;
3151 break;
3152 case cpu_to_le16(IEEE80211_STYPE_BACK):
3153 stats->ctrl[CONTROL_BACK]++;
3154 break;
3155 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
3156 stats->ctrl[CONTROL_PSPOLL]++;
3157 break;
3158 case cpu_to_le16(IEEE80211_STYPE_RTS):
3159 stats->ctrl[CONTROL_RTS]++;
3160 break;
3161 case cpu_to_le16(IEEE80211_STYPE_CTS):
3162 stats->ctrl[CONTROL_CTS]++;
3163 break;
3164 case cpu_to_le16(IEEE80211_STYPE_ACK):
3165 stats->ctrl[CONTROL_ACK]++;
3166 break;
3167 case cpu_to_le16(IEEE80211_STYPE_CFEND):
3168 stats->ctrl[CONTROL_CFEND]++;
3169 break;
3170 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
3171 stats->ctrl[CONTROL_CFENDACK]++;
3172 break;
3173 }
3174 } else {
3175 /* data */
3176 stats->data_cnt++;
3177 stats->data_bytes += len;
3178 }
3179}
3180EXPORT_SYMBOL(iwl_update_stats);
20594eb0
WYG
3181#endif
3182
6da3a13e
WYG
3183#ifdef CONFIG_PM
3184
3185int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
3186{
3187 struct iwl_priv *priv = pci_get_drvdata(pdev);
3188
3189 /*
3190 * This function is called when system goes into suspend state
3191 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
3192 * first but since iwl_mac_stop() has no knowledge of who the caller is,
3193 * it will not call apm_ops.stop() to stop the DMA operation.
3194 * Calling apm_ops.stop here to make sure we stop the DMA.
3195 */
3196 priv->cfg->ops->lib->apm_ops.stop(priv);
3197
3198 pci_save_state(pdev);
3199 pci_disable_device(pdev);
3200 pci_set_power_state(pdev, PCI_D3hot);
3201
3202 return 0;
3203}
3204EXPORT_SYMBOL(iwl_pci_suspend);
3205
3206int iwl_pci_resume(struct pci_dev *pdev)
3207{
3208 struct iwl_priv *priv = pci_get_drvdata(pdev);
3209 int ret;
3210
3211 pci_set_power_state(pdev, PCI_D0);
3212 ret = pci_enable_device(pdev);
3213 if (ret)
3214 return ret;
3215 pci_restore_state(pdev);
3216 iwl_enable_interrupts(priv);
3217
3218 return 0;
3219}
3220EXPORT_SYMBOL(iwl_pci_resume);
3221
3222#endif /* CONFIG_PM */
This page took 1.544767 seconds and 5 git commands to generate.