blob: b4984868358769dbfcdb8280e3c361374f206141 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02003 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
Sharon Dvir39bdb172015-10-15 18:18:09 +03004 * Copyright(c) 2015 Intel Deutschland GmbH
Zhu Yib481de92007-09-25 17:54:57 -07005 *
6 * Portions of this file are derived from the ipw3945 project, as well
7 * as portions of the ieee80211 subsystem header files.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 *
22 * The full GNU General Public License is included in this distribution in the
23 * file called LICENSE.
24 *
25 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020026 * Intel Linux Wireless <linuxwifi@intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070027 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *
29 *****************************************************************************/
Joe Perches69b87972012-03-26 08:27:40 -070030
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
Zhu Yib481de92007-09-25 17:54:57 -070033#include <linux/kernel.h>
34#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070035#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070037#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040038#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070039#include <linux/skbuff.h>
40#include <linux/netdevice.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Johannes Berg26a7ca92012-05-21 11:55:54 +020048#include "iwl-eeprom-read.h"
49#include "iwl-eeprom-parse.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070050#include "iwl-io.h"
Emmanuel Grumbachc85eb612011-06-14 10:13:24 +030051#include "iwl-trans.h"
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +020052#include "iwl-op-mode.h"
Johannes Berg82575102012-04-03 16:44:37 -070053#include "iwl-drv.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070054#include "iwl-modparams.h"
Emmanuel Grumbachdada03c2012-06-17 15:42:37 +030055#include "iwl-prph.h"
Christoph Hellwig416e1432007-10-25 17:15:49 +080056
Johannes Berg1023fdc2012-05-15 12:16:34 +020057#include "dev.h"
58#include "calib.h"
59#include "agn.h"
60
Emmanuel Grumbachdada03c2012-06-17 15:42:37 +030061
Zhu Yib481de92007-09-25 17:54:57 -070062/******************************************************************************
63 *
64 * module boiler plate
65 *
66 ******************************************************************************/
67
Tomas Winklerd783b062008-07-18 13:53:02 +080068#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070069MODULE_DESCRIPTION(DRV_DESCRIPTION);
Tomas Winklera7b75202008-12-11 10:33:41 -080070MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070071MODULE_LICENSE("GPL");
72
Sharon Dvir39bdb172015-10-15 18:18:09 +030073/* Please keep this array *SORTED* by hex value.
74 * Access is done through binary search.
75 * A warning will be triggered on violation.
76 */
77static const struct iwl_hcmd_names iwl_dvm_cmd_names[] = {
78 HCMD_NAME(REPLY_ALIVE),
79 HCMD_NAME(REPLY_ERROR),
80 HCMD_NAME(REPLY_ECHO),
81 HCMD_NAME(REPLY_RXON),
82 HCMD_NAME(REPLY_RXON_ASSOC),
83 HCMD_NAME(REPLY_QOS_PARAM),
84 HCMD_NAME(REPLY_RXON_TIMING),
85 HCMD_NAME(REPLY_ADD_STA),
86 HCMD_NAME(REPLY_REMOVE_STA),
87 HCMD_NAME(REPLY_REMOVE_ALL_STA),
88 HCMD_NAME(REPLY_TX),
89 HCMD_NAME(REPLY_TXFIFO_FLUSH),
90 HCMD_NAME(REPLY_WEPKEY),
91 HCMD_NAME(REPLY_LEDS_CMD),
92 HCMD_NAME(REPLY_TX_LINK_QUALITY_CMD),
93 HCMD_NAME(COEX_PRIORITY_TABLE_CMD),
94 HCMD_NAME(COEX_MEDIUM_NOTIFICATION),
95 HCMD_NAME(COEX_EVENT_CMD),
96 HCMD_NAME(TEMPERATURE_NOTIFICATION),
97 HCMD_NAME(CALIBRATION_CFG_CMD),
98 HCMD_NAME(CALIBRATION_RES_NOTIFICATION),
99 HCMD_NAME(CALIBRATION_COMPLETE_NOTIFICATION),
100 HCMD_NAME(REPLY_QUIET_CMD),
101 HCMD_NAME(REPLY_CHANNEL_SWITCH),
102 HCMD_NAME(CHANNEL_SWITCH_NOTIFICATION),
103 HCMD_NAME(REPLY_SPECTRUM_MEASUREMENT_CMD),
104 HCMD_NAME(SPECTRUM_MEASURE_NOTIFICATION),
105 HCMD_NAME(POWER_TABLE_CMD),
106 HCMD_NAME(PM_SLEEP_NOTIFICATION),
107 HCMD_NAME(PM_DEBUG_STATISTIC_NOTIFIC),
108 HCMD_NAME(REPLY_SCAN_CMD),
109 HCMD_NAME(REPLY_SCAN_ABORT_CMD),
110 HCMD_NAME(SCAN_START_NOTIFICATION),
111 HCMD_NAME(SCAN_RESULTS_NOTIFICATION),
112 HCMD_NAME(SCAN_COMPLETE_NOTIFICATION),
113 HCMD_NAME(BEACON_NOTIFICATION),
114 HCMD_NAME(REPLY_TX_BEACON),
115 HCMD_NAME(WHO_IS_AWAKE_NOTIFICATION),
116 HCMD_NAME(REPLY_TX_POWER_DBM_CMD),
117 HCMD_NAME(QUIET_NOTIFICATION),
118 HCMD_NAME(REPLY_TX_PWR_TABLE_CMD),
119 HCMD_NAME(REPLY_TX_POWER_DBM_CMD_V1),
120 HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
121 HCMD_NAME(MEASURE_ABORT_NOTIFICATION),
122 HCMD_NAME(REPLY_BT_CONFIG),
123 HCMD_NAME(REPLY_STATISTICS_CMD),
124 HCMD_NAME(STATISTICS_NOTIFICATION),
125 HCMD_NAME(REPLY_CARD_STATE_CMD),
126 HCMD_NAME(CARD_STATE_NOTIFICATION),
127 HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
128 HCMD_NAME(REPLY_CT_KILL_CONFIG_CMD),
129 HCMD_NAME(SENSITIVITY_CMD),
130 HCMD_NAME(REPLY_PHY_CALIBRATION_CMD),
131 HCMD_NAME(REPLY_WIPAN_PARAMS),
132 HCMD_NAME(REPLY_WIPAN_RXON),
133 HCMD_NAME(REPLY_WIPAN_RXON_TIMING),
134 HCMD_NAME(REPLY_WIPAN_RXON_ASSOC),
135 HCMD_NAME(REPLY_WIPAN_QOS_PARAM),
136 HCMD_NAME(REPLY_WIPAN_WEPKEY),
137 HCMD_NAME(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
138 HCMD_NAME(REPLY_WIPAN_NOA_NOTIFICATION),
139 HCMD_NAME(REPLY_WIPAN_DEACTIVATION_COMPLETE),
140 HCMD_NAME(REPLY_RX_PHY_CMD),
141 HCMD_NAME(REPLY_RX_MPDU_CMD),
142 HCMD_NAME(REPLY_RX),
143 HCMD_NAME(REPLY_COMPRESSED_BA),
144 HCMD_NAME(REPLY_BT_COEX_PRIO_TABLE),
145 HCMD_NAME(REPLY_BT_COEX_PROT_ENV),
146 HCMD_NAME(REPLY_BT_COEX_PROFILE_NOTIF),
147 HCMD_NAME(REPLY_D3_CONFIG),
148 HCMD_NAME(REPLY_WOWLAN_PATTERNS),
149 HCMD_NAME(REPLY_WOWLAN_WAKEUP_FILTER),
150 HCMD_NAME(REPLY_WOWLAN_TSC_RSC_PARAMS),
151 HCMD_NAME(REPLY_WOWLAN_TKIP_PARAMS),
152 HCMD_NAME(REPLY_WOWLAN_KEK_KCK_MATERIAL),
153 HCMD_NAME(REPLY_WOWLAN_GET_STATUS),
154};
155
156static const struct iwl_hcmd_arr iwl_dvm_groups[] = {
157 [0x0] = HCMD_ARR(iwl_dvm_cmd_names),
158};
159
Johannes Bergb1abeda2012-05-31 13:54:56 +0200160static const struct iwl_op_mode_ops iwl_dvm_ops;
161
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700162void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700163{
Johannes Berg246ed352010-08-23 10:46:32 +0200164 struct iwl_rxon_context *ctx;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700165
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700166 for_each_context(priv, ctx) {
167 iwlagn_set_rxon_chain(priv, ctx);
168 if (ctx->active.rx_chain != ctx->staging.rx_chain)
169 iwlagn_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +0200170 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700171}
172
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800173/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
174static void iwl_set_beacon_tim(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -0700175 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
176 u8 *beacon, u32 frame_size)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800177{
178 u16 tim_idx;
179 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
180
181 /*
182 * The index is relative to frame start but we start looking at the
183 * variable-length part of the beacon.
184 */
185 tim_idx = mgmt->u.beacon.variable - beacon;
186
187 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
188 while ((tim_idx < (frame_size - 2)) &&
189 (beacon[tim_idx] != WLAN_EID_TIM))
190 tim_idx += beacon[tim_idx+1] + 2;
191
192 /* If TIM field was found, set variables */
193 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
194 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
195 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
196 } else
197 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
198}
199
Johannes Berg8a98d492011-04-29 09:48:14 -0700200int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800201{
202 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700203 struct iwl_host_cmd cmd = {
204 .id = REPLY_TX_BEACON,
Johannes Berg8a98d492011-04-29 09:48:14 -0700205 };
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700206 struct ieee80211_tx_info *info;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800207 u32 frame_size;
208 u32 rate_flags;
209 u32 rate;
Johannes Berg8a98d492011-04-29 09:48:14 -0700210
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800211 /*
212 * We have to set up the TX command, the TX Beacon command, and the
213 * beacon contents.
214 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800215
Johannes Bergb1eea292012-03-06 13:30:42 -0800216 lockdep_assert_held(&priv->mutex);
Johannes Berg76d04812010-08-23 10:46:47 +0200217
218 if (!priv->beacon_ctx) {
219 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
Julia Lawall950094c2010-09-05 21:00:26 +0200220 return 0;
Johannes Berg76d04812010-08-23 10:46:47 +0200221 }
222
Johannes Berg8a98d492011-04-29 09:48:14 -0700223 if (WARN_ON(!priv->beacon_skb))
224 return -EINVAL;
225
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700226 /* Allocate beacon command */
227 if (!priv->beacon_cmd)
228 priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
229 tx_beacon_cmd = priv->beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700230 if (!tx_beacon_cmd)
231 return -ENOMEM;
232
233 frame_size = priv->beacon_skb->len;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800234
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800235 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800236 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Johannes Berg76d04812010-08-23 10:46:47 +0200237 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800238 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800239 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800240 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
241
242 /* Set up TX beacon command fields */
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700243 iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
Johannes Berg77834542010-10-04 05:50:36 -0700244 frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800245
246 /* Set up packet rate and flags */
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700247 info = IEEE80211_SKB_CB(priv->beacon_skb);
248
249 /*
250 * Let's set up the rate at least somewhat correctly;
251 * it will currently not actually be used by the uCode,
252 * it uses the broadcast station's rate instead.
253 */
254 if (info->control.rates[0].idx < 0 ||
255 info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
256 rate = 0;
257 else
258 rate = info->control.rates[0].idx;
259
Johannes Berg0e1654f2010-05-18 02:48:36 -0700260 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200261 priv->nvm_data->valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800262 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700263
264 /* In mac80211, rates for 5 GHz start at 0 */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200265 if (info->band == NL80211_BAND_5GHZ)
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700266 rate += IWL_FIRST_OFDM_RATE;
267 else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800268 rate_flags |= RATE_MCS_CCK_MSK;
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700269
270 tx_beacon_cmd->tx.rate_n_flags =
271 iwl_hw_set_rate_n_flags(rate, rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800272
Johannes Berg8a98d492011-04-29 09:48:14 -0700273 /* Submit command */
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700274 cmd.len[0] = sizeof(*tx_beacon_cmd);
Johannes Berg3fa50732011-05-04 07:50:38 -0700275 cmd.data[0] = tx_beacon_cmd;
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700276 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
277 cmd.len[1] = frame_size;
278 cmd.data[1] = priv->beacon_skb->data;
279 cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
Johannes Berg2295c662010-10-23 09:15:41 -0700280
Johannes Berge10a0532012-03-06 13:30:39 -0800281 return iwl_dvm_send_cmd(priv, &cmd);
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800282}
283
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700284static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700285{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700286 struct iwl_priv *priv =
287 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700288 struct sk_buff *beacon;
289
Johannes Bergb1eea292012-03-06 13:30:42 -0800290 mutex_lock(&priv->mutex);
Johannes Berg76d04812010-08-23 10:46:47 +0200291 if (!priv->beacon_ctx) {
292 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
293 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700294 }
295
Johannes Berg60744f62010-08-23 10:46:50 +0200296 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
297 /*
298 * The ucode will send beacon notifications even in
299 * IBSS mode, but we don't want to process them. But
300 * we need to defer the type check to here due to
301 * requiring locking around the beacon_ctx access.
302 */
303 goto out;
304 }
305
Johannes Berg76d04812010-08-23 10:46:47 +0200306 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
307 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
308 if (!beacon) {
Johannes Berg77834542010-10-04 05:50:36 -0700309 IWL_ERR(priv, "update beacon failed -- keeping old\n");
Johannes Berg76d04812010-08-23 10:46:47 +0200310 goto out;
311 }
312
Zhu Yib481de92007-09-25 17:54:57 -0700313 /* new beacon skb is allocated every time; dispose previous.*/
Johannes Berg77834542010-10-04 05:50:36 -0700314 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700315
Johannes Berg12e934d2010-10-04 05:50:06 -0700316 priv->beacon_skb = beacon;
Zhu Yib481de92007-09-25 17:54:57 -0700317
Johannes Berg2295c662010-10-23 09:15:41 -0700318 iwlagn_send_beacon_cmd(priv);
Johannes Berg76d04812010-08-23 10:46:47 +0200319 out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800320 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -0700321}
322
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700323static void iwl_bg_bt_runtime_config(struct work_struct *work)
324{
325 struct iwl_priv *priv =
326 container_of(work, struct iwl_priv, bt_runtime_config);
327
Emmanuel Grumbach82e5a642014-03-10 15:22:03 +0200328 mutex_lock(&priv->mutex);
Don Fry83626402012-03-07 09:52:37 -0800329 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Emmanuel Grumbach82e5a642014-03-10 15:22:03 +0200330 goto out;
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700331
332 /* dont send host command if rf-kill is on */
Don Fry83626402012-03-07 09:52:37 -0800333 if (!iwl_is_ready_rf(priv))
Emmanuel Grumbach82e5a642014-03-10 15:22:03 +0200334 goto out;
335
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700336 iwlagn_send_advance_bt_config(priv);
Emmanuel Grumbach82e5a642014-03-10 15:22:03 +0200337out:
338 mutex_unlock(&priv->mutex);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700339}
340
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700341static void iwl_bg_bt_full_concurrency(struct work_struct *work)
342{
343 struct iwl_priv *priv =
344 container_of(work, struct iwl_priv, bt_full_concurrency);
Johannes Berg246ed352010-08-23 10:46:32 +0200345 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700346
Johannes Bergb1eea292012-03-06 13:30:42 -0800347 mutex_lock(&priv->mutex);
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200348
Don Fry83626402012-03-07 09:52:37 -0800349 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200350 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700351
352 /* dont send host command if rf-kill is on */
Don Fry83626402012-03-07 09:52:37 -0800353 if (!iwl_is_ready_rf(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200354 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700355
356 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
357 priv->bt_full_concurrent ?
358 "full concurrency" : "3-wire");
359
360 /*
361 * LQ & RXON updated cmds must be sent before BT Config cmd
362 * to avoid 3-wire collisions
363 */
Johannes Berg246ed352010-08-23 10:46:32 +0200364 for_each_context(priv, ctx) {
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700365 iwlagn_set_rxon_chain(priv, ctx);
Wey-Yi Guy805a3b82011-06-03 07:54:16 -0700366 iwlagn_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +0200367 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700368
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700369 iwlagn_send_advance_bt_config(priv);
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200370out:
Johannes Bergb1eea292012-03-06 13:30:42 -0800371 mutex_unlock(&priv->mutex);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700372}
373
Meenakshi Venkataraman15911292012-03-14 15:49:37 -0700374int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
375{
376 struct iwl_statistics_cmd statistics_cmd = {
377 .configuration_flags =
378 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
379 };
380
381 if (flags & CMD_ASYNC)
382 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
383 CMD_ASYNC,
384 sizeof(struct iwl_statistics_cmd),
385 &statistics_cmd);
386 else
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300387 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 0,
Meenakshi Venkataraman15911292012-03-14 15:49:37 -0700388 sizeof(struct iwl_statistics_cmd),
389 &statistics_cmd);
390}
391
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800392/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700393 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800394 *
395 * This callback is provided in order to send a statistics request.
396 *
397 * This timer function is continually reset to execute within
398 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
399 * was received. We need to ensure we receive the statistics in order
400 * to update the temperature used for calibrating the TXPOWER.
401 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700402static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800403{
404 struct iwl_priv *priv = (struct iwl_priv *)data;
405
Don Fry83626402012-03-07 09:52:37 -0800406 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800407 return;
408
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700409 /* dont send host command if rf-kill is on */
Don Fry83626402012-03-07 09:52:37 -0800410 if (!iwl_is_ready_rf(priv))
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700411 return;
412
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800413 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800414}
415
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800416
417static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
418 u32 start_idx, u32 num_events,
Johannes Berg98d4bf02012-01-13 11:56:11 +0100419 u32 capacity, u32 mode)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800420{
421 u32 i;
422 u32 ptr; /* SRAM byte address of log data */
423 u32 ev, time, data; /* event log data */
424 unsigned long reg_flags;
425
426 if (mode == 0)
427 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
428 else
429 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
430
431 /* Make sure device is powered up for SRAM reads */
Emmanuel Grumbach23ba9342015-12-17 11:55:13 +0200432 if (!iwl_trans_grab_nic_access(priv->trans, &reg_flags))
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800433 return;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800434
435 /* Set starting address; reads will auto-increment */
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700436 iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800437
438 /*
Johannes Berg98d4bf02012-01-13 11:56:11 +0100439 * Refuse to read more than would have fit into the log from
440 * the current start_idx. This used to happen due to the race
441 * described below, but now WARN because the code below should
442 * prevent it from happening here.
443 */
444 if (WARN_ON(num_events > capacity - start_idx))
445 num_events = capacity - start_idx;
446
447 /*
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800448 * "time" is actually "data" for mode 0 (no timestamp).
449 * place event id # at far right for easier visual parsing.
450 */
451 for (i = 0; i < num_events; i++) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700452 ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
453 time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800454 if (mode == 0) {
Johannes Berg6c1011e2012-03-06 13:30:48 -0800455 trace_iwlwifi_dev_ucode_cont_event(
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700456 priv->trans->dev, 0, time, ev);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800457 } else {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700458 data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
Johannes Berg6c1011e2012-03-06 13:30:48 -0800459 trace_iwlwifi_dev_ucode_cont_event(
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700460 priv->trans->dev, time, data, ev);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800461 }
462 }
463 /* Allow device to power down */
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200464 iwl_trans_release_nic_access(priv->trans, &reg_flags);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800465}
466
Johannes Berg875295f2010-01-22 14:22:55 -0800467static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800468{
469 u32 capacity; /* event log capacity in # entries */
Johannes Berg98d4bf02012-01-13 11:56:11 +0100470 struct {
471 u32 capacity;
472 u32 mode;
473 u32 wrap_counter;
474 u32 write_counter;
475 } __packed read;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800476 u32 base; /* SRAM byte address of event log header */
477 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
478 u32 num_wraps; /* # times uCode wrapped to top of log */
479 u32 next_entry; /* index of next entry to be written by uCode */
480
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -0700481 base = priv->device_pointers.log_event_table;
Fry, Donald H4caab322011-07-07 15:24:07 -0700482 if (iwlagn_hw_valid_rtc_data_addr(base)) {
Emmanuel Grumbach4fd442d2012-12-24 14:27:11 +0200483 iwl_trans_read_mem_bytes(priv->trans, base,
484 &read, sizeof(read));
Johannes Berg98d4bf02012-01-13 11:56:11 +0100485 capacity = read.capacity;
486 mode = read.mode;
487 num_wraps = read.wrap_counter;
488 next_entry = read.write_counter;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800489 } else
490 return;
491
Johannes Berg98d4bf02012-01-13 11:56:11 +0100492 /*
493 * Unfortunately, the uCode doesn't use temporary variables.
494 * Therefore, it can happen that we read next_entry == capacity,
495 * which really means next_entry == 0.
496 */
497 if (unlikely(next_entry == capacity))
498 next_entry = 0;
499 /*
500 * Additionally, the uCode increases the write pointer before
501 * the wraps counter, so if the write pointer is smaller than
502 * the old write pointer (wrap occurred) but we read that no
503 * wrap occurred, we actually read between the next_entry and
504 * num_wraps update (this does happen in practice!!) -- take
505 * that into account by increasing num_wraps.
506 */
507 if (unlikely(next_entry < priv->event_log.next_entry &&
508 num_wraps == priv->event_log.num_wraps))
509 num_wraps++;
510
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800511 if (num_wraps == priv->event_log.num_wraps) {
Johannes Berg98d4bf02012-01-13 11:56:11 +0100512 iwl_print_cont_event_trace(
513 priv, base, priv->event_log.next_entry,
514 next_entry - priv->event_log.next_entry,
515 capacity, mode);
516
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800517 priv->event_log.non_wraps_count++;
518 } else {
Johannes Berg98d4bf02012-01-13 11:56:11 +0100519 if (num_wraps - priv->event_log.num_wraps > 1)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800520 priv->event_log.wraps_more_count++;
521 else
522 priv->event_log.wraps_once_count++;
Johannes Berg98d4bf02012-01-13 11:56:11 +0100523
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700524 trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800525 num_wraps - priv->event_log.num_wraps,
526 next_entry, priv->event_log.next_entry);
Johannes Berg98d4bf02012-01-13 11:56:11 +0100527
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800528 if (next_entry < priv->event_log.next_entry) {
Johannes Berg98d4bf02012-01-13 11:56:11 +0100529 iwl_print_cont_event_trace(
530 priv, base, priv->event_log.next_entry,
531 capacity - priv->event_log.next_entry,
532 capacity, mode);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800533
Johannes Berg98d4bf02012-01-13 11:56:11 +0100534 iwl_print_cont_event_trace(
535 priv, base, 0, next_entry, capacity, mode);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800536 } else {
Johannes Berg98d4bf02012-01-13 11:56:11 +0100537 iwl_print_cont_event_trace(
538 priv, base, next_entry,
539 capacity - next_entry,
540 capacity, mode);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800541
Johannes Berg98d4bf02012-01-13 11:56:11 +0100542 iwl_print_cont_event_trace(
543 priv, base, 0, next_entry, capacity, mode);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800544 }
545 }
Johannes Berg98d4bf02012-01-13 11:56:11 +0100546
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800547 priv->event_log.num_wraps = num_wraps;
548 priv->event_log.next_entry = next_entry;
549}
550
551/**
552 * iwl_bg_ucode_trace - Timer callback to log ucode event
553 *
554 * The timer is continually set to execute every
555 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
556 * this function is to perform continuous uCode event logging operation
557 * if enabled
558 */
559static void iwl_bg_ucode_trace(unsigned long data)
560{
561 struct iwl_priv *priv = (struct iwl_priv *)data;
562
Don Fry83626402012-03-07 09:52:37 -0800563 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800564 return;
565
566 if (priv->event_log.ucode_trace) {
567 iwl_continuous_event_trace(priv);
568 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
569 mod_timer(&priv->ucode_trace,
570 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
571 }
572}
573
Wey-Yi Guy65550632010-06-24 13:18:35 -0700574static void iwl_bg_tx_flush(struct work_struct *work)
575{
576 struct iwl_priv *priv =
577 container_of(work, struct iwl_priv, tx_flush);
578
Don Fry83626402012-03-07 09:52:37 -0800579 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Wey-Yi Guy65550632010-06-24 13:18:35 -0700580 return;
581
582 /* do nothing if rf-kill is on */
Don Fry83626402012-03-07 09:52:37 -0800583 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy65550632010-06-24 13:18:35 -0700584 return;
585
Wey-Yi Guyc68744f2011-06-18 08:03:18 -0700586 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
Johannes Berga4dece92012-10-31 22:21:28 +0100587 iwlagn_dev_txfifo_flush(priv);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700588}
589
Johannes Berg9eae88f2012-03-15 13:26:52 -0700590/*
591 * queue/FIFO/AC mapping definitions
592 */
593
Johannes Berg9eae88f2012-03-15 13:26:52 -0700594static const u8 iwlagn_bss_ac_to_fifo[] = {
595 IWL_TX_FIFO_VO,
596 IWL_TX_FIFO_VI,
597 IWL_TX_FIFO_BE,
598 IWL_TX_FIFO_BK,
599};
600
601static const u8 iwlagn_bss_ac_to_queue[] = {
602 0, 1, 2, 3,
603};
604
605static const u8 iwlagn_pan_ac_to_fifo[] = {
606 IWL_TX_FIFO_VO_IPAN,
607 IWL_TX_FIFO_VI_IPAN,
608 IWL_TX_FIFO_BE_IPAN,
609 IWL_TX_FIFO_BK_IPAN,
610};
611
612static const u8 iwlagn_pan_ac_to_queue[] = {
613 7, 6, 5, 4,
614};
615
Johannes Bergaca86262012-05-14 09:08:50 +0200616static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700617{
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700618 int i;
619
620 /*
621 * The default context is always valid,
622 * the PAN context depends on uCode.
623 */
Johannes Berga18f61b2012-03-15 13:26:53 -0700624 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700625 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
Johannes Berga18f61b2012-03-15 13:26:53 -0700626 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700627
628 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
629 priv->contexts[i].ctxid = i;
630
631 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
632 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
633 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
634 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
635 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
636 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
637 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
638 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
Don Fry87272af2012-01-25 15:26:34 -0800639 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700640 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
Johannes Berg57897722012-05-11 10:53:18 +0200641 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700642 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
643 BIT(NL80211_IFTYPE_STATION);
644 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
645 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
646 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
647 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
Johannes Berg9eae88f2012-03-15 13:26:52 -0700648 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
649 iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
650 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
651 iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700652
653 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
654 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
655 REPLY_WIPAN_RXON_TIMING;
656 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
657 REPLY_WIPAN_RXON_ASSOC;
658 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
659 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
660 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
661 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
662 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700663 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
664 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700665
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700666 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
667 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
668 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
Johannes Berg9eae88f2012-03-15 13:26:52 -0700669 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
670 iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
671 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
672 iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
673 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
Johannes Berg4d2a5d02011-07-23 10:24:46 -0700674
675 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
676}
677
Johannes Bergaca86262012-05-14 09:08:50 +0200678static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700679{
680 struct iwl_ct_kill_config cmd;
681 struct iwl_ct_kill_throttling_config adv_cmd;
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700682 int ret = 0;
683
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700684 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700685 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Johannes Berg08ae86a2012-03-05 11:24:27 -0800686
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700687 priv->thermal_throttle.ct_kill_toggle = false;
688
Johannes Berg0d8877a2013-05-17 10:36:29 +0200689 if (priv->lib->support_ct_kill_exit) {
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700690 adv_cmd.critical_temperature_enter =
Johannes Berg9e295112012-04-09 17:46:55 -0700691 cpu_to_le32(priv->hw_params.ct_kill_threshold);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700692 adv_cmd.critical_temperature_exit =
Johannes Berg9e295112012-04-09 17:46:55 -0700693 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700694
Johannes Berge10a0532012-03-06 13:30:39 -0800695 ret = iwl_dvm_send_cmd_pdu(priv,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700696 REPLY_CT_KILL_CONFIG_CMD,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300697 0, sizeof(adv_cmd), &adv_cmd);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700698 if (ret)
699 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
700 else
701 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700702 "succeeded, critical temperature enter is %d,"
703 "exit is %d\n",
Johannes Berg9e295112012-04-09 17:46:55 -0700704 priv->hw_params.ct_kill_threshold,
705 priv->hw_params.ct_kill_exit_threshold);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700706 } else {
707 cmd.critical_temperature_R =
Johannes Berg9e295112012-04-09 17:46:55 -0700708 cpu_to_le32(priv->hw_params.ct_kill_threshold);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700709
Johannes Berge10a0532012-03-06 13:30:39 -0800710 ret = iwl_dvm_send_cmd_pdu(priv,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700711 REPLY_CT_KILL_CONFIG_CMD,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300712 0, sizeof(cmd), &cmd);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700713 if (ret)
714 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
715 else
716 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700717 "succeeded, "
718 "critical temperature is %d\n",
Johannes Berg9e295112012-04-09 17:46:55 -0700719 priv->hw_params.ct_kill_threshold);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -0700720 }
721}
722
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -0700723static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
724{
725 struct iwl_calib_cfg_cmd calib_cfg_cmd;
726 struct iwl_host_cmd cmd = {
727 .id = CALIBRATION_CFG_CMD,
Johannes Berg3fa50732011-05-04 07:50:38 -0700728 .len = { sizeof(struct iwl_calib_cfg_cmd), },
729 .data = { &calib_cfg_cmd, },
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -0700730 };
731
732 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
Wey-Yi Guyaf4dc882011-10-04 07:10:19 -0700733 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700734 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -0700735
Johannes Berge10a0532012-03-06 13:30:39 -0800736 return iwl_dvm_send_cmd(priv, &cmd);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -0700737}
738
739
Wey-Yi Guye505c432011-07-07 08:27:41 -0700740static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
741{
742 struct iwl_tx_ant_config_cmd tx_ant_cmd = {
743 .valid = cpu_to_le32(valid_tx_ant),
744 };
745
Johannes Berg0692fe42012-03-06 13:30:37 -0800746 if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700747 IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300748 return iwl_dvm_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD, 0,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700749 sizeof(struct iwl_tx_ant_config_cmd),
750 &tx_ant_cmd);
751 } else {
752 IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
753 return -EOPNOTSUPP;
754 }
755}
756
Johannes Bergaca86262012-05-14 09:08:50 +0200757static void iwl_send_bt_config(struct iwl_priv *priv)
Meenakshi Venkataramane4c52ab2012-03-13 18:23:51 -0700758{
759 struct iwl_bt_cmd bt_cmd = {
760 .lead_time = BT_LEAD_TIME_DEF,
761 .max_kill = BT_MAX_KILL_DEF,
762 .kill_ack_mask = 0,
763 .kill_cts_mask = 0,
764 };
765
Johannes Berg65de7e82012-04-17 07:36:30 -0700766 if (!iwlwifi_mod_params.bt_coex_active)
Meenakshi Venkataramane4c52ab2012-03-13 18:23:51 -0700767 bt_cmd.flags = BT_COEX_DISABLE;
768 else
769 bt_cmd.flags = BT_COEX_ENABLE;
770
771 priv->bt_enable_flag = bt_cmd.flags;
772 IWL_DEBUG_INFO(priv, "BT coex %s\n",
773 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
774
775 if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300776 0, sizeof(struct iwl_bt_cmd), &bt_cmd))
Meenakshi Venkataramane4c52ab2012-03-13 18:23:51 -0700777 IWL_ERR(priv, "failed to send BT Coex Config\n");
778}
779
Zhu Yib481de92007-09-25 17:54:57 -0700780/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +0800781 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -0700782 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +0800783 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -0700784 */
Cindy H. Kao4613e722011-05-06 10:40:15 -0700785int iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700786{
Tomas Winkler57aab752008-04-14 21:16:03 -0700787 int ret = 0;
Johannes Berg246ed352010-08-23 10:46:32 +0200788 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -0700789
Tomas Winklere1623442009-01-27 14:27:56 -0800790 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700791
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700792 /* After the ALIVE response, we can send host commands to the uCode */
Don Fry83626402012-03-07 09:52:37 -0800793 set_bit(STATUS_ALIVE, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -0700794
Don Fry83626402012-03-07 09:52:37 -0800795 if (iwl_is_rfkill(priv))
Johannes Bergca7966c2011-04-22 10:15:23 -0700796 return -ERFKILL;
Zhu Yib481de92007-09-25 17:54:57 -0700797
Johannes Berg98d4bf02012-01-13 11:56:11 +0100798 if (priv->event_log.ucode_trace) {
799 /* start collecting data now */
800 mod_timer(&priv->ucode_trace, jiffies);
801 }
802
Wey-Yi Guybc795df2010-10-11 14:24:05 -0700803 /* download priority table before any calibration request */
Johannes Berg0d8877a2013-05-17 10:36:29 +0200804 if (priv->lib->bt_params &&
805 priv->lib->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700806 /* Configure Bluetooth device coexistence support */
Johannes Berg0d8877a2013-05-17 10:36:29 +0200807 if (priv->lib->bt_params->bt_sco_disable)
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700808 priv->bt_enable_pspoll = false;
809 else
810 priv->bt_enable_pspoll = true;
811
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700812 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
813 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
814 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700815 iwlagn_send_advance_bt_config(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700816 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700817 priv->cur_rssi_ctx = NULL;
818
Johannes Berge1991882012-03-06 13:30:36 -0800819 iwl_send_prio_tbl(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700820
821 /* FIXME: w/a to force change uCode BT state machine */
Johannes Berge1991882012-03-06 13:30:36 -0800822 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
Johannes Bergca7966c2011-04-22 10:15:23 -0700823 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
824 if (ret)
825 return ret;
Johannes Berge1991882012-03-06 13:30:36 -0800826 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
Johannes Bergca7966c2011-04-22 10:15:23 -0700827 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
828 if (ret)
829 return ret;
Johannes Berg707aee42013-05-03 18:58:16 +0200830 } else if (priv->lib->bt_params) {
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700831 /*
832 * default is 2-wire BT coexexistence support
833 */
834 iwl_send_bt_config(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700835 }
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700836
Venkataraman, Meenakshi885765f2011-12-14 16:54:21 -0800837 /*
838 * Perform runtime calibrations, including DC calibration.
839 */
840 iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
Wey-Yi Guybc795df2010-10-11 14:24:05 -0700841
Johannes Berg36d68252008-05-15 12:55:26 +0200842 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -0700843
Wey-Yi Guy2f748de2009-09-17 10:43:51 -0700844 /* Configure Tx antenna selection based on H/W config */
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200845 iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant);
Wey-Yi Guy2f748de2009-09-17 10:43:51 -0700846
Johannes Berg15b86bf2012-03-05 11:24:36 -0800847 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800848 struct iwl_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +0200849 (struct iwl_rxon_cmd *)&ctx->active;
Mohamed Abbas019fb972009-03-17 21:59:18 -0700850 /* apply any changes in staging */
Johannes Berg246ed352010-08-23 10:46:32 +0200851 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700852 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
853 } else {
Johannes Bergd0fe4782010-08-23 10:46:58 +0200854 struct iwl_rxon_context *tmp;
Zhu Yib481de92007-09-25 17:54:57 -0700855 /* Initialize our rx_config data */
Johannes Bergd0fe4782010-08-23 10:46:58 +0200856 for_each_context(priv, tmp)
857 iwl_connection_init_rx_config(priv, tmp);
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700858
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700859 iwlagn_set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -0700860 }
861
Johannes Berg15b86bf2012-03-05 11:24:36 -0800862 if (!priv->wowlan) {
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700863 /* WoWLAN ucode will not reply in the same way, skip it */
864 iwl_reset_run_time_calib(priv);
865 }
Tomas Winkler4a4a9e82008-05-29 16:34:54 +0800866
Don Fry83626402012-03-07 09:52:37 -0800867 set_bit(STATUS_READY, &priv->status);
Wey-Yi Guy9e2e7422010-11-12 13:52:37 -0800868
Zhu Yib481de92007-09-25 17:54:57 -0700869 /* Configure the adapter for unassociated operation */
Wey-Yi Guy805a3b82011-06-03 07:54:16 -0700870 ret = iwlagn_commit_rxon(priv, ctx);
Johannes Bergca7966c2011-04-22 10:15:23 -0700871 if (ret)
872 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700873
874 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +0800875 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -0800876
Tomas Winklere1623442009-01-27 14:27:56 -0800877 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700878
Johannes Bergca7966c2011-04-22 10:15:23 -0700879 return iwl_power_update_mode(priv, true);
Zhu Yib481de92007-09-25 17:54:57 -0700880}
881
Johannes Bergd3163832012-03-05 11:24:19 -0800882/**
883 * iwl_clear_driver_stations - clear knowledge of all stations from driver
884 * @priv: iwl priv struct
885 *
886 * This is called during iwl_down() to make sure that in the case
887 * we're coming there from a hardware restart mac80211 will be
888 * able to reconfigure stations -- if we're getting there in the
889 * normal down flow then the stations will already be cleared.
890 */
891static void iwl_clear_driver_stations(struct iwl_priv *priv)
892{
Johannes Bergd3163832012-03-05 11:24:19 -0800893 struct iwl_rxon_context *ctx;
894
Johannes Bergfa23cb02012-03-05 11:24:25 -0800895 spin_lock_bh(&priv->sta_lock);
Johannes Bergd3163832012-03-05 11:24:19 -0800896 memset(priv->stations, 0, sizeof(priv->stations));
897 priv->num_stations = 0;
898
899 priv->ucode_key_table = 0;
900
901 for_each_context(priv, ctx) {
902 /*
903 * Remove all key information that is not stored as part
904 * of station information since mac80211 may not have had
905 * a chance to remove all the keys. When device is
906 * reconfigured by mac80211 after an error all keys will
907 * be reconfigured.
908 */
909 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
910 ctx->key_mapping_keys = 0;
911 }
912
Johannes Bergfa23cb02012-03-05 11:24:25 -0800913 spin_unlock_bh(&priv->sta_lock);
Johannes Bergd3163832012-03-05 11:24:19 -0800914}
915
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800916void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700917{
Dan Carpenter22dd2fd2011-03-15 10:03:24 +0300918 int exit_pending;
Zhu Yib481de92007-09-25 17:54:57 -0700919
Tomas Winklere1623442009-01-27 14:27:56 -0800920 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -0700921
Johannes Bergb1eea292012-03-06 13:30:42 -0800922 lockdep_assert_held(&priv->mutex);
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -0800923
Stanislaw Gruszkad745d472010-09-13 14:46:35 +0200924 iwl_scan_cancel_timeout(priv, 200);
925
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700926 exit_pending =
Don Fry83626402012-03-07 09:52:37 -0800927 test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -0700928
Johannes Bergdcef7322010-08-27 08:55:52 -0700929 iwl_clear_ucode_stations(priv, NULL);
Johannes Berga194e322010-08-27 08:53:46 -0700930 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -0700931 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700932
Johannes Berga1174132010-08-23 07:56:59 -0700933 /* reset BT coex data */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -0700934 priv->bt_status = 0;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -0700935 priv->cur_rssi_ctx = NULL;
936 priv->bt_is_sco = 0;
Johannes Berg0d8877a2013-05-17 10:36:29 +0200937 if (priv->lib->bt_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700938 priv->bt_traffic_load =
Johannes Berg0d8877a2013-05-17 10:36:29 +0200939 priv->lib->bt_params->bt_init_traffic_load;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700940 else
941 priv->bt_traffic_load = 0;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700942 priv->bt_full_concurrent = false;
943 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -0700944
Zhu Yib481de92007-09-25 17:54:57 -0700945 /* Wipe out the EXIT_PENDING status bit if we are not actually
946 * exiting the module */
947 if (!exit_pending)
Don Fry83626402012-03-07 09:52:37 -0800948 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -0700949
Emmanuel Grumbach859cfb02011-09-15 11:46:31 -0700950 if (priv->mac80211_registered)
Zhu Yib481de92007-09-25 17:54:57 -0700951 ieee80211_stop_queues(priv->hw);
952
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800953 priv->ucode_loaded = false;
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700954 iwl_trans_stop_device(priv->trans);
Emmanuel Grumbach909e9b22011-09-15 11:46:30 -0700955
Ilan Peer622a9262012-05-09 16:11:55 +0300956 /* Set num_aux_in_flight must be done after the transport is stopped */
957 atomic_set(&priv->num_aux_in_flight, 0);
958
Johannes Berg1a10f432011-04-13 03:14:44 -0700959 /* Clear out all status bits but a few that are stable across reset */
Don Fry1353a7b2012-03-07 09:52:43 -0800960 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
Zhu Yib481de92007-09-25 17:54:57 -0700961 STATUS_RF_KILL_HW |
Don Fry17acd0b2012-03-15 13:27:05 -0700962 test_bit(STATUS_FW_ERROR, &priv->status) <<
963 STATUS_FW_ERROR |
Don Fry83626402012-03-07 09:52:37 -0800964 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +0800965 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -0700966
Johannes Berg77834542010-10-04 05:50:36 -0700967 dev_kfree_skb(priv->beacon_skb);
Johannes Berg12e934d2010-10-04 05:50:06 -0700968 priv->beacon_skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700969}
970
Zhu Yib481de92007-09-25 17:54:57 -0700971/*****************************************************************************
972 *
973 * Workqueue callbacks
974 *
975 *****************************************************************************/
976
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +0800977static void iwl_bg_run_time_calib_work(struct work_struct *work)
978{
979 struct iwl_priv *priv = container_of(work, struct iwl_priv,
980 run_time_calib_work);
981
Johannes Bergb1eea292012-03-06 13:30:42 -0800982 mutex_lock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +0800983
Don Fry83626402012-03-07 09:52:37 -0800984 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
985 test_bit(STATUS_SCANNING, &priv->status)) {
Johannes Bergb1eea292012-03-06 13:30:42 -0800986 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +0800987 return;
988 }
989
990 if (priv->start_calib) {
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700991 iwl_chain_noise_calibration(priv);
992 iwl_sensitivity_calibration(priv);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +0800993 }
994
Johannes Bergb1eea292012-03-06 13:30:42 -0800995 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +0800996}
997
Wey-Yi Guy73356132011-11-10 06:55:11 -0800998void iwlagn_prepare_restart(struct iwl_priv *priv)
Johannes Berge43e85c2011-04-19 07:45:16 -0700999{
Johannes Berge43e85c2011-04-19 07:45:16 -07001000 bool bt_full_concurrent;
1001 u8 bt_ci_compliance;
1002 u8 bt_load;
1003 u8 bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001004 bool bt_is_sco;
Johannes Berg9eae88f2012-03-15 13:26:52 -07001005 int i;
Johannes Berge43e85c2011-04-19 07:45:16 -07001006
Johannes Bergb1eea292012-03-06 13:30:42 -08001007 lockdep_assert_held(&priv->mutex);
Johannes Berge43e85c2011-04-19 07:45:16 -07001008
Johannes Berge43e85c2011-04-19 07:45:16 -07001009 priv->is_open = 0;
1010
1011 /*
1012 * __iwl_down() will clear the BT status variables,
1013 * which is correct, but when we restart we really
1014 * want to keep them so restore them afterwards.
1015 *
1016 * The restart process will later pick them up and
1017 * re-configure the hw when we reconfigure the BT
1018 * command.
1019 */
1020 bt_full_concurrent = priv->bt_full_concurrent;
1021 bt_ci_compliance = priv->bt_ci_compliance;
1022 bt_load = priv->bt_traffic_load;
1023 bt_status = priv->bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001024 bt_is_sco = priv->bt_is_sco;
Johannes Berge43e85c2011-04-19 07:45:16 -07001025
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -08001026 iwl_down(priv);
Johannes Berge43e85c2011-04-19 07:45:16 -07001027
1028 priv->bt_full_concurrent = bt_full_concurrent;
1029 priv->bt_ci_compliance = bt_ci_compliance;
1030 priv->bt_traffic_load = bt_load;
1031 priv->bt_status = bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001032 priv->bt_is_sco = bt_is_sco;
Johannes Berg9eae88f2012-03-15 13:26:52 -07001033
Johannes Berg14791772012-04-17 07:39:03 -07001034 /* reset aggregation queues */
Johannes Berg9eae88f2012-03-15 13:26:52 -07001035 for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
Johannes Berg14791772012-04-17 07:39:03 -07001036 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1037 /* and stop counts */
1038 for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
1039 atomic_set(&priv->queue_stop_count[i], 0);
Johannes Berg9eae88f2012-03-15 13:26:52 -07001040
1041 memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
Johannes Berge43e85c2011-04-19 07:45:16 -07001042}
1043
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001044static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001045{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001046 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07001047
Don Fry83626402012-03-07 09:52:37 -08001048 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07001049 return;
1050
Don Fry17acd0b2012-03-15 13:27:05 -07001051 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
Johannes Bergb1eea292012-03-06 13:30:42 -08001052 mutex_lock(&priv->mutex);
Johannes Berge43e85c2011-04-19 07:45:16 -07001053 iwlagn_prepare_restart(priv);
Johannes Bergb1eea292012-03-06 13:30:42 -08001054 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07001055 iwl_cancel_deferred_work(priv);
Amit Beka40503f72012-08-06 17:01:05 +03001056 if (priv->mac80211_registered)
1057 ieee80211_restart_hw(priv->hw);
1058 else
1059 IWL_ERR(priv,
Johannes Berg3c6acb62014-05-07 11:47:53 +02001060 "Cannot request restart before registrating with mac80211\n");
Johannes Berg19cc1082009-05-08 13:44:36 -07001061 } else {
Johannes Bergca7966c2011-04-22 10:15:23 -07001062 WARN_ON(1);
Johannes Berg19cc1082009-05-08 13:44:36 -07001063 }
Zhu Yib481de92007-09-25 17:54:57 -07001064}
1065
Zhu Yib481de92007-09-25 17:54:57 -07001066/*****************************************************************************
1067 *
Zhu Yib481de92007-09-25 17:54:57 -07001068 * driver setup and teardown
1069 *
1070 *****************************************************************************/
1071
Johannes Bergaca86262012-05-14 09:08:50 +02001072static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001073{
Eva Rachel Retuyab429a772016-03-19 05:15:47 +00001074 priv->workqueue = alloc_ordered_workqueue(DRV_NAME, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001075
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001076 INIT_WORK(&priv->restart, iwl_bg_restart);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001077 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001078 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07001079 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001080 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07001081 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001082
Tomas Winkler2a421b92008-06-12 09:47:10 +08001083 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001084
Johannes Berg0d8877a2013-05-17 10:36:29 +02001085 if (priv->lib->bt_params)
Johannes Berg562f08e2012-03-07 09:52:18 -08001086 iwlagn_bt_setup_deferred_work(priv);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001087
Julia Lawallbd9c5042014-12-26 15:35:44 +01001088 setup_timer(&priv->statistics_periodic, iwl_bg_statistics_periodic,
1089 (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07001090
Julia Lawallbd9c5042014-12-26 15:35:44 +01001091 setup_timer(&priv->ucode_trace, iwl_bg_ucode_trace,
1092 (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07001093}
1094
Emmanuel Grumbach78e5a462012-02-17 10:34:53 -08001095void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001096{
Johannes Berg0d8877a2013-05-17 10:36:29 +02001097 if (priv->lib->bt_params)
Johannes Berg562f08e2012-03-07 09:52:18 -08001098 iwlagn_bt_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001099
Wey-Yi Guy815e6292010-06-03 10:14:01 -07001100 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07001101 cancel_work_sync(&priv->beacon_update);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02001102
1103 iwl_cancel_scan_deferred_work(priv);
1104
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001105 cancel_work_sync(&priv->bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07001106 cancel_work_sync(&priv->bt_runtime_config);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02001107
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001108 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001109 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07001110}
1111
Johannes Bergaca86262012-05-14 09:08:50 +02001112static int iwl_init_drv(struct iwl_priv *priv)
Reinette Chatre89f186a2009-10-30 14:36:11 -07001113{
Johannes Bergfa23cb02012-03-05 11:24:25 -08001114 spin_lock_init(&priv->sta_lock);
Reinette Chatre89f186a2009-10-30 14:36:11 -07001115
Johannes Bergb1eea292012-03-06 13:30:42 -08001116 mutex_init(&priv->mutex);
Reinette Chatre89f186a2009-10-30 14:36:11 -07001117
Johannes Berge1991882012-03-06 13:30:36 -08001118 INIT_LIST_HEAD(&priv->calib_results);
Johannes Berg80e83da2011-11-25 11:11:44 -08001119
Johannes Berg57fbcce2016-04-12 15:56:15 +02001120 priv->band = NL80211_BAND_2GHZ;
Reinette Chatre89f186a2009-10-30 14:36:11 -07001121
Johannes Berg0d8877a2013-05-17 10:36:29 +02001122 priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold;
Johannes Bergab5c0f12012-03-06 13:30:53 -08001123
Reinette Chatre89f186a2009-10-30 14:36:11 -07001124 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08001125 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001126 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001127 priv->agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07001128
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +01001129 priv->rx_statistics_jiffies = jiffies;
1130
Reinette Chatre89f186a2009-10-30 14:36:11 -07001131 /* Choose which receivers/antennas to use */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001132 iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
Reinette Chatre89f186a2009-10-30 14:36:11 -07001133
1134 iwl_init_scan_params(priv);
1135
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07001136 /* init bt coex */
Johannes Berg0d8877a2013-05-17 10:36:29 +02001137 if (priv->lib->bt_params &&
1138 priv->lib->bt_params->advanced_bt_coexist) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07001139 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
1140 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
1141 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07001142 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
1143 priv->bt_duration = BT_DURATION_LIMIT_DEF;
1144 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07001145 }
1146
Reinette Chatre89f186a2009-10-30 14:36:11 -07001147 return 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07001148}
1149
Johannes Bergaca86262012-05-14 09:08:50 +02001150static void iwl_uninit_drv(struct iwl_priv *priv)
Reinette Chatre89f186a2009-10-30 14:36:11 -07001151{
Johannes Berg811ecc92010-04-06 04:12:41 -07001152 kfree(priv->scan_cmd);
Johannes Berg4ce7cc22011-05-13 11:57:40 -07001153 kfree(priv->beacon_cmd);
Johannes Berg79d3eef2011-11-10 06:55:01 -08001154 kfree(rcu_dereference_raw(priv->noa_data));
Johannes Berge1991882012-03-06 13:30:36 -08001155 iwl_calib_free_results(priv);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001156#ifdef CONFIG_IWLWIFI_DEBUGFS
1157 kfree(priv->wowlan_sram);
1158#endif
Reinette Chatre89f186a2009-10-30 14:36:11 -07001159}
1160
Johannes Bergaca86262012-05-14 09:08:50 +02001161static void iwl_set_hw_params(struct iwl_priv *priv)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07001162{
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001163 if (priv->cfg->ht_params)
Johannes Berg9e295112012-04-09 17:46:55 -07001164 priv->hw_params.use_rts_for_aggregation =
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001165 priv->cfg->ht_params->use_rts_for_aggregation;
Johannes Bergb9ad70d2012-03-06 13:30:55 -08001166
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07001167 /* Device-specific setup */
Johannes Berge9676692012-04-10 14:10:28 -07001168 priv->lib->set_hw_params(priv);
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07001169}
1170
Wey-Yi Guy119ea182011-04-18 09:34:06 -07001171
Wey-Yi Guy119ea182011-04-18 09:34:06 -07001172
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001173/* show what optional capabilities we have */
Johannes Bergaca86262012-05-14 09:08:50 +02001174static void iwl_option_config(struct iwl_priv *priv)
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001175{
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001176#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001177 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001178#else
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001179 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001180#endif
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001181
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001182#ifdef CONFIG_IWLWIFI_DEBUGFS
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001183 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001184#else
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001185 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001186#endif
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001187
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001188#ifdef CONFIG_IWLWIFI_DEVICE_TRACING
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001189 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001190#else
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001191 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001192#endif
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001193}
1194
Johannes Berg26a7ca92012-05-21 11:55:54 +02001195static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
1196{
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001197 struct iwl_nvm_data *data = priv->nvm_data;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001198
1199 if (data->sku_cap_11n_enable &&
Johannes Berg26a7ca92012-05-21 11:55:54 +02001200 !priv->cfg->ht_params) {
1201 IWL_ERR(priv, "Invalid 11n configuration\n");
1202 return -EINVAL;
1203 }
1204
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001205 if (!data->sku_cap_11n_enable && !data->sku_cap_band_24GHz_enable &&
1206 !data->sku_cap_band_52GHz_enable) {
Johannes Berg26a7ca92012-05-21 11:55:54 +02001207 IWL_ERR(priv, "Invalid device sku\n");
1208 return -EINVAL;
1209 }
1210
Johannes Berg3c6acb62014-05-07 11:47:53 +02001211 IWL_DEBUG_INFO(priv,
1212 "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001213 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
1214 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
1215 data->sku_cap_11n_enable ? "" : "NOT", "enabled");
Johannes Berg26a7ca92012-05-21 11:55:54 +02001216
Johannes Berg26a7ca92012-05-21 11:55:54 +02001217 priv->hw_params.tx_chains_num =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001218 num_of_ant(data->valid_tx_ant);
Johannes Berg26a7ca92012-05-21 11:55:54 +02001219 if (priv->cfg->rx_with_siso_diversity)
1220 priv->hw_params.rx_chains_num = 1;
1221 else
1222 priv->hw_params.rx_chains_num =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001223 num_of_ant(data->valid_rx_ant);
Johannes Berg26a7ca92012-05-21 11:55:54 +02001224
Johannes Berg468b4bf2012-11-05 19:48:33 +01001225 IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001226 data->valid_tx_ant,
1227 data->valid_rx_ant);
Johannes Berg26a7ca92012-05-21 11:55:54 +02001228
1229 return 0;
1230}
1231
Johannes Berg0692fe42012-03-06 13:30:37 -08001232static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001233 const struct iwl_cfg *cfg,
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001234 const struct iwl_fw *fw,
1235 struct dentry *dbgfs_dir)
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001236{
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001237 struct iwl_priv *priv;
1238 struct ieee80211_hw *hw;
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001239 struct iwl_op_mode *op_mode;
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03001240 u16 num_mac;
Johannes Berga78be212012-02-21 18:31:06 +02001241 u32 ucode_flags;
Emmanuel Grumbache7332692012-11-05 12:52:57 +02001242 struct iwl_trans_config trans_cfg = {};
Johannes Bergd663ee72012-03-10 13:00:07 -08001243 static const u8 no_reclaim_cmds[] = {
1244 REPLY_RX_PHY_CMD,
Johannes Bergd663ee72012-03-10 13:00:07 -08001245 REPLY_RX_MPDU_CMD,
1246 REPLY_COMPRESSED_BA,
1247 STATISTICS_NOTIFICATION,
1248 REPLY_TX,
1249 };
Johannes Berg9eae88f2012-03-15 13:26:52 -07001250 int i;
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001251
1252 /************************
1253 * 1. Allocating HW data
1254 ************************/
Don Fryfa06ec72011-10-14 12:54:46 -07001255 hw = iwl_alloc_all();
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001256 if (!hw) {
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001257 pr_err("%s: Cannot allocate network device\n", cfg->name);
Emmanuel Grumbach807caf22011-06-09 02:55:55 -07001258 goto out;
1259 }
1260
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001261 op_mode = hw->priv;
1262 op_mode->ops = &iwl_dvm_ops;
1263 priv = IWL_OP_MODE_GET_DVM(op_mode);
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001264 priv->trans = trans;
Emmanuel Grumbach4b9844f2012-03-22 23:59:52 +02001265 priv->dev = trans->dev;
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001266 priv->cfg = cfg;
Johannes Berg0692fe42012-03-06 13:30:37 -08001267 priv->fw = fw;
Emmanuel Grumbacha48709c2011-05-31 08:22:30 +03001268
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001269 switch (priv->cfg->device_family) {
Johannes Berge9676692012-04-10 14:10:28 -07001270 case IWL_DEVICE_FAMILY_1000:
1271 case IWL_DEVICE_FAMILY_100:
Johannes Bergee4d5472013-05-17 09:58:27 +02001272 priv->lib = &iwl_dvm_1000_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001273 break;
1274 case IWL_DEVICE_FAMILY_2000:
Johannes Bergee4d5472013-05-17 09:58:27 +02001275 priv->lib = &iwl_dvm_2000_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001276 break;
Johannes Berg0d8877a2013-05-17 10:36:29 +02001277 case IWL_DEVICE_FAMILY_105:
1278 priv->lib = &iwl_dvm_105_cfg;
1279 break;
Johannes Berge9676692012-04-10 14:10:28 -07001280 case IWL_DEVICE_FAMILY_2030:
1281 case IWL_DEVICE_FAMILY_135:
Johannes Bergee4d5472013-05-17 09:58:27 +02001282 priv->lib = &iwl_dvm_2030_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001283 break;
1284 case IWL_DEVICE_FAMILY_5000:
Johannes Bergee4d5472013-05-17 09:58:27 +02001285 priv->lib = &iwl_dvm_5000_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001286 break;
1287 case IWL_DEVICE_FAMILY_5150:
Johannes Bergee4d5472013-05-17 09:58:27 +02001288 priv->lib = &iwl_dvm_5150_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001289 break;
1290 case IWL_DEVICE_FAMILY_6000:
Johannes Berge9676692012-04-10 14:10:28 -07001291 case IWL_DEVICE_FAMILY_6000i:
Johannes Berg0d8877a2013-05-17 10:36:29 +02001292 priv->lib = &iwl_dvm_6000_cfg;
1293 break;
1294 case IWL_DEVICE_FAMILY_6005:
1295 priv->lib = &iwl_dvm_6005_cfg;
1296 break;
Johannes Berge9676692012-04-10 14:10:28 -07001297 case IWL_DEVICE_FAMILY_6050:
1298 case IWL_DEVICE_FAMILY_6150:
Johannes Berg0d8877a2013-05-17 10:36:29 +02001299 priv->lib = &iwl_dvm_6050_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001300 break;
1301 case IWL_DEVICE_FAMILY_6030:
Johannes Bergee4d5472013-05-17 09:58:27 +02001302 priv->lib = &iwl_dvm_6030_cfg;
Johannes Berge9676692012-04-10 14:10:28 -07001303 break;
1304 default:
1305 break;
1306 }
1307
1308 if (WARN_ON(!priv->lib))
Johannes Berg063c5162012-04-03 16:35:41 -07001309 goto out_free_hw;
Johannes Berge9676692012-04-10 14:10:28 -07001310
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001311 /*
1312 * Populate the state variables that the transport layer needs
1313 * to know about.
1314 */
1315 trans_cfg.op_mode = op_mode;
Johannes Bergd663ee72012-03-10 13:00:07 -08001316 trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
1317 trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
Emmanuel Grumbach6c4fbcb2015-11-10 11:57:41 +02001318
1319 switch (iwlwifi_mod_params.amsdu_size) {
Emmanuel Grumbach4bdd4df2016-04-07 16:44:42 +03001320 case IWL_AMSDU_DEF:
Emmanuel Grumbach6c4fbcb2015-11-10 11:57:41 +02001321 case IWL_AMSDU_4K:
1322 trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1323 break;
1324 case IWL_AMSDU_8K:
1325 trans_cfg.rx_buf_size = IWL_AMSDU_8K;
1326 break;
1327 case IWL_AMSDU_12K:
1328 default:
1329 trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1330 pr_err("Unsupported amsdu_size: %d\n",
1331 iwlwifi_mod_params.amsdu_size);
1332 }
1333
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +02001334 trans_cfg.cmd_q_wdg_timeout = IWL_WATCHDOG_DISABLED;
1335
Sharon Dvir39bdb172015-10-15 18:18:09 +03001336 trans_cfg.command_groups = iwl_dvm_groups;
1337 trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
1338
Emmanuel Grumbachb04db9a2012-06-21 11:53:44 +03001339 trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
Johannes Berg21cb3222016-06-21 13:11:48 +02001340 trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
1341 driver_data[2]);
Meenakshi Venkataraman9bdfbfa2012-03-07 09:52:36 -08001342
Emmanuel Grumbach303e56f2012-06-13 19:37:06 +03001343 WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
1344 priv->cfg->base_params->num_of_queues);
1345
Meenakshi Venkataraman9bdfbfa2012-03-07 09:52:36 -08001346 ucode_flags = fw->ucode_capa.flags;
1347
Meenakshi Venkataramanc6f600f2012-03-08 11:29:12 -08001348 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
1349 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
1350 trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1351 } else {
1352 priv->sta_key_max_num = STA_KEY_MAX_NUM;
1353 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1354 }
1355
Meenakshi Venkataraman92d743a2012-03-07 09:52:35 -08001356 /* Configure transport layer */
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001357 iwl_trans_configure(priv->trans, &trans_cfg);
Emmanuel Grumbached277c92012-02-09 16:08:15 +02001358
Johannes Bergf042c2e2012-09-05 22:34:44 +02001359 trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
1360 trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
Sharon Dvir39bdb172015-10-15 18:18:09 +03001361 trans->command_groups = trans_cfg.command_groups;
1362 trans->command_groups_size = trans_cfg.command_groups_size;
Johannes Bergf042c2e2012-09-05 22:34:44 +02001363
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001364 /* At this point both hw and priv are allocated. */
Johannes Berg8f2d3d22010-08-23 10:46:37 +02001365
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001366 SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
Zhu Yib481de92007-09-25 17:54:57 -07001367
Wey-Yi Guy07d3c152012-04-27 16:18:47 -07001368 iwl_option_config(priv);
Wey-Yi Guyebfa8672011-11-25 11:11:47 -08001369
Tomas Winklere1623442009-01-27 14:27:56 -08001370 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07001371
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001372 /* is antenna coupling more than 35dB ? */
1373 priv->bt_ant_couple_ok =
Johannes Berg65de7e82012-04-17 07:36:30 -07001374 (iwlwifi_mod_params.ant_coupling >
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -07001375 IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
1376 true : false;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001377
Emmanuel Grumbachbc53cd42013-06-18 06:29:56 +03001378 /* bt channel inhibition enabled*/
1379 priv->bt_ch_announce = true;
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08001380 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
1381 (priv->bt_ch_announce) ? "On" : "Off");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07001382
Reinette Chatre731a29b2009-12-14 14:12:11 -08001383 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001384 * we should init now
1385 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001386 spin_lock_init(&priv->statistics.lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08001387
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03001388 /***********************
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001389 * 2. Read REV register
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03001390 ***********************/
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08001391 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001392 priv->cfg->name, priv->trans->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07001393
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001394 if (iwl_trans_start_hw(priv->trans))
Johannes Berg063c5162012-04-03 16:35:41 -07001395 goto out_free_hw;
Emmanuel Grumbach1e89cbac2011-07-20 17:51:22 -07001396
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001397 /* Read the EEPROM */
Johannes Berg26a7ca92012-05-21 11:55:54 +02001398 if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
1399 &priv->eeprom_blob_size)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001400 IWL_ERR(priv, "Unable to init EEPROM\n");
Johannes Berg063c5162012-04-03 16:35:41 -07001401 goto out_free_hw;
Assaf Krauss316c30d2008-03-14 10:38:46 -07001402 }
Johannes Berg26a7ca92012-05-21 11:55:54 +02001403
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001404 /* Reset chip to save power until we load uCode during "up". */
Arik Nemtsova4082842013-11-24 19:10:46 +02001405 iwl_trans_stop_device(priv->trans);
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001406
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001407 priv->nvm_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
Johannes Berg26a7ca92012-05-21 11:55:54 +02001408 priv->eeprom_blob,
1409 priv->eeprom_blob_size);
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001410 if (!priv->nvm_data)
Johannes Berg26a7ca92012-05-21 11:55:54 +02001411 goto out_free_eeprom_blob;
1412
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001413 if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
Reinette Chatrec8f16132009-02-27 16:21:22 -08001414 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07001415
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001416 if (iwl_eeprom_init_hw_params(priv))
Wey-Yi Guy21a5b3c2010-11-10 13:32:59 -08001417 goto out_free_eeprom;
1418
Ron Rindjunsky02883012008-05-15 13:53:53 +08001419 /* extract MAC Address */
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001420 memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07001421 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
1422 priv->hw->wiphy->addresses = priv->addresses;
1423 priv->hw->wiphy->n_addresses = 1;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001424 num_mac = priv->nvm_data->n_hw_addrs;
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07001425 if (num_mac > 1) {
1426 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
1427 ETH_ALEN);
1428 priv->addresses[1].addr[5]++;
1429 priv->hw->wiphy->n_addresses++;
1430 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07001431
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001432 /************************
1433 * 4. Setup HW constants
1434 ************************/
1435 iwl_set_hw_params(priv);
1436
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001437 if (!(priv->nvm_data->sku_cap_ipan_enable)) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02001438 IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN\n");
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001439 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1440 /*
1441 * if not PAN, then don't support P2P -- might be a uCode
1442 * packaging bug or due to the eeprom check above
1443 */
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001444 priv->sta_key_max_num = STA_KEY_MAX_NUM;
1445 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1446
1447 /* Configure transport layer again*/
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001448 iwl_trans_configure(priv->trans, &trans_cfg);
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001449 }
1450
Assaf Krauss316c30d2008-03-14 10:38:46 -07001451 /*******************
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001452 * 5. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07001453 *******************/
Johannes Berg9eae88f2012-03-15 13:26:52 -07001454 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
Johannes Berg14791772012-04-17 07:39:03 -07001455 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1456 if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
1457 i != IWL_DEFAULT_CMD_QUEUE_NUM &&
1458 i != IWL_IPAN_CMD_QUEUE_NUM)
1459 priv->queue_to_mac80211[i] = i;
1460 atomic_set(&priv->queue_stop_count[i], 0);
Johannes Berg9eae88f2012-03-15 13:26:52 -07001461 }
1462
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001463 if (iwl_init_drv(priv))
Ron Rindjunsky399f4902008-04-23 17:14:56 -07001464 goto out_free_eeprom;
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001465
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001466 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07001467
Assaf Krauss316c30d2008-03-14 10:38:46 -07001468 /********************
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001469 * 6. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07001470 ********************/
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001471 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001472 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07001473
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08001474 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07001475 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08001476
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001477 snprintf(priv->hw->wiphy->fw_version,
1478 sizeof(priv->hw->wiphy->fw_version),
1479 "%s", fw->fw_version);
Johannes Berg562db532010-04-29 07:41:53 -07001480
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001481 priv->new_scan_threshold_behaviour =
Johannes Berga78be212012-02-21 18:31:06 +02001482 !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001483
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001484 priv->phy_calib_chain_noise_reset_cmd =
1485 fw->ucode_capa.standard_phy_calibration_size;
1486 priv->phy_calib_chain_noise_gain_cmd =
1487 fw->ucode_capa.standard_phy_calibration_size + 1;
1488
1489 /* initialize all valid contexts */
Johannes Berga78be212012-02-21 18:31:06 +02001490 iwl_init_context(priv, ucode_flags);
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001491
1492 /**************************************************
1493 * This is still part of probe() in a sense...
1494 *
Emmanuel Grumbach3dc420b2012-03-07 09:52:41 -08001495 * 7. Setup and register with mac80211 and debugfs
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001496 **************************************************/
Wey-Yi Guy88f10a12012-03-15 13:26:42 -07001497 if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001498 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08001499
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001500 if (iwl_dbgfs_register(priv, dbgfs_dir))
1501 goto out_mac80211_unregister;
Emmanuel Grumbache211b242012-02-07 10:35:18 +02001502
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001503 return op_mode;
Zhu Yib481de92007-09-25 17:54:57 -07001504
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07001505out_mac80211_unregister:
1506 iwlagn_mac_unregister(priv);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03001507out_destroy_workqueue:
Meenakshi Venkataraman273a5762012-07-17 13:05:03 -07001508 iwl_tt_exit(priv);
Meenakshi Venkataraman273a5762012-07-17 13:05:03 -07001509 iwl_cancel_deferred_work(priv);
Johannes Berg1ee158d2012-02-17 10:07:44 -08001510 destroy_workqueue(priv->workqueue);
1511 priv->workqueue = NULL;
Tomas Winkler6ba87952008-05-15 13:54:17 +08001512 iwl_uninit_drv(priv);
Johannes Berg26a7ca92012-05-21 11:55:54 +02001513out_free_eeprom_blob:
1514 kfree(priv->eeprom_blob);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03001515out_free_eeprom:
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001516 iwl_free_nvm_data(priv->nvm_data);
Johannes Berg063c5162012-04-03 16:35:41 -07001517out_free_hw:
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07001518 ieee80211_free_hw(priv->hw);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03001519out:
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001520 op_mode = NULL;
1521 return op_mode;
Zhu Yib481de92007-09-25 17:54:57 -07001522}
1523
Johannes Bergaca86262012-05-14 09:08:50 +02001524static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
Zhu Yib481de92007-09-25 17:54:57 -07001525{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001526 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1527
Tomas Winklere1623442009-01-27 14:27:56 -08001528 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07001529
Don Fry09af1402011-12-09 10:07:38 -08001530 iwlagn_mac_unregister(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07001531
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07001532 iwl_tt_exit(priv);
1533
Johannes Berg26a7ca92012-05-21 11:55:54 +02001534 kfree(priv->eeprom_blob);
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001535 iwl_free_nvm_data(priv->nvm_data);
Zhu Yib481de92007-09-25 17:54:57 -07001536
Mohamed Abbas948c1712007-10-25 17:15:45 +08001537 /*netif_stop_queue(dev); */
Johannes Berg1ee158d2012-02-17 10:07:44 -08001538 flush_workqueue(priv->workqueue);
Mohamed Abbas948c1712007-10-25 17:15:45 +08001539
Wey-Yi Guyade4c642011-10-10 07:27:11 -07001540 /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
Johannes Berg1ee158d2012-02-17 10:07:44 -08001541 * priv->workqueue... so we can't take down the workqueue
Zhu Yib481de92007-09-25 17:54:57 -07001542 * until now... */
Johannes Berg1ee158d2012-02-17 10:07:44 -08001543 destroy_workqueue(priv->workqueue);
1544 priv->workqueue = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001545
Tomas Winkler6ba87952008-05-15 13:54:17 +08001546 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001547
Johannes Berg77834542010-10-04 05:50:36 -07001548 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -07001549
Arik Nemtsova4082842013-11-24 19:10:46 +02001550 iwl_trans_op_mode_leave(priv->trans);
Zhu Yib481de92007-09-25 17:54:57 -07001551 ieee80211_free_hw(priv->hw);
1552}
1553
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001554static const char * const desc_lookup_text[] = {
1555 "OK",
1556 "FAIL",
1557 "BAD_PARAM",
1558 "BAD_CHECKSUM",
1559 "NMI_INTERRUPT_WDG",
1560 "SYSASSERT",
1561 "FATAL_ERROR",
1562 "BAD_COMMAND",
1563 "HW_ERROR_TUNE_LOCK",
1564 "HW_ERROR_TEMPERATURE",
1565 "ILLEGAL_CHAN_FREQ",
1566 "VCC_NOT_STABLE",
1567 "FH_ERROR",
1568 "NMI_INTERRUPT_HOST",
1569 "NMI_INTERRUPT_ACTION_PT",
1570 "NMI_INTERRUPT_UNKNOWN",
1571 "UCODE_VERSION_MISMATCH",
1572 "HW_ERROR_ABS_LOCK",
1573 "HW_ERROR_CAL_LOCK_FAIL",
1574 "NMI_INTERRUPT_INST_ACTION_PT",
1575 "NMI_INTERRUPT_DATA_ACTION_PT",
1576 "NMI_TRM_HW_ER",
1577 "NMI_INTERRUPT_TRM",
1578 "NMI_INTERRUPT_BREAK_POINT",
1579 "DEBUG_0",
1580 "DEBUG_1",
1581 "DEBUG_2",
1582 "DEBUG_3",
1583};
1584
1585static struct { char *name; u8 num; } advanced_lookup[] = {
1586 { "NMI_INTERRUPT_WDG", 0x34 },
1587 { "SYSASSERT", 0x35 },
1588 { "UCODE_VERSION_MISMATCH", 0x37 },
1589 { "BAD_COMMAND", 0x38 },
1590 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1591 { "FATAL_ERROR", 0x3D },
1592 { "NMI_TRM_HW_ERR", 0x46 },
1593 { "NMI_INTERRUPT_TRM", 0x4C },
1594 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1595 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1596 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1597 { "NMI_INTERRUPT_HOST", 0x66 },
1598 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1599 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1600 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1601 { "ADVANCED_SYSASSERT", 0 },
1602};
1603
1604static const char *desc_lookup(u32 num)
1605{
1606 int i;
1607 int max = ARRAY_SIZE(desc_lookup_text);
1608
1609 if (num < max)
1610 return desc_lookup_text[num];
1611
1612 max = ARRAY_SIZE(advanced_lookup) - 1;
1613 for (i = 0; i < max; i++) {
1614 if (advanced_lookup[i].num == num)
1615 break;
1616 }
1617 return advanced_lookup[i].name;
1618}
1619
1620#define ERROR_START_OFFSET (1 * sizeof(u32))
1621#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1622
1623static void iwl_dump_nic_error_log(struct iwl_priv *priv)
1624{
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001625 struct iwl_trans *trans = priv->trans;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001626 u32 base;
1627 struct iwl_error_event_table table;
1628
1629 base = priv->device_pointers.error_event_table;
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -07001630 if (priv->cur_ucode == IWL_UCODE_INIT) {
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001631 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001632 base = priv->fw->init_errlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001633 } else {
1634 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001635 base = priv->fw->inst_errlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001636 }
1637
1638 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1639 IWL_ERR(priv,
1640 "Not valid error log pointer 0x%08X for %s uCode\n",
1641 base,
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -07001642 (priv->cur_ucode == IWL_UCODE_INIT)
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001643 ? "Init" : "RT");
1644 return;
1645 }
1646
1647 /*TODO: Update dbgfs with ISR error stats obtained below */
Emmanuel Grumbach4fd442d2012-12-24 14:27:11 +02001648 iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001649
1650 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
1651 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
1652 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
Don Fry74fda972012-03-20 16:36:54 -07001653 priv->status, table.valid);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001654 }
1655
1656 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
1657 table.data1, table.data2, table.line,
Emmanuel Grumbach7d3ca7f2016-03-07 10:16:38 +02001658 table.blink2, table.ilink1, table.ilink2,
1659 table.bcon_time, table.gp1, table.gp2,
1660 table.gp3, table.ucode_ver, table.hw_ver,
1661 0, table.brd_ver);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001662 IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
1663 desc_lookup(table.error_id));
1664 IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
1665 IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
1666 IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
1667 IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
1668 IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
1669 IWL_ERR(priv, "0x%08X | data1\n", table.data1);
1670 IWL_ERR(priv, "0x%08X | data2\n", table.data2);
1671 IWL_ERR(priv, "0x%08X | line\n", table.line);
1672 IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
1673 IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
1674 IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
1675 IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
1676 IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
1677 IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
1678 IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
1679 IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
1680 IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
1681 IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
1682 IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
1683 IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
1684 IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
1685 IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
1686 IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
1687 IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
1688 IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
1689 IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
1690 IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
1691 IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
1692 IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
1693 IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
1694 IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
1695 IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
1696}
1697
1698#define EVENT_START_OFFSET (4 * sizeof(u32))
1699
1700/**
1701 * iwl_print_event_log - Dump error event log to syslog
1702 *
1703 */
1704static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1705 u32 num_events, u32 mode,
1706 int pos, char **buf, size_t bufsz)
1707{
1708 u32 i;
1709 u32 base; /* SRAM byte address of event log header */
1710 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1711 u32 ptr; /* SRAM byte address of log data */
1712 u32 ev, time, data; /* event log data */
1713 unsigned long reg_flags;
1714
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001715 struct iwl_trans *trans = priv->trans;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001716
1717 if (num_events == 0)
1718 return pos;
1719
1720 base = priv->device_pointers.log_event_table;
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -07001721 if (priv->cur_ucode == IWL_UCODE_INIT) {
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001722 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001723 base = priv->fw->init_evtlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001724 } else {
1725 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001726 base = priv->fw->inst_evtlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001727 }
1728
1729 if (mode == 0)
1730 event_size = 2 * sizeof(u32);
1731 else
1732 event_size = 3 * sizeof(u32);
1733
1734 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1735
1736 /* Make sure device is powered up for SRAM reads */
Emmanuel Grumbach23ba9342015-12-17 11:55:13 +02001737 if (!iwl_trans_grab_nic_access(trans, &reg_flags))
Lilach Edelsteine56b04e2013-01-16 11:34:49 +02001738 return pos;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001739
1740 /* Set starting address; reads will auto-increment */
1741 iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
1742
1743 /* "time" is actually "data" for mode 0 (no timestamp).
1744 * place event id # at far right for easier visual parsing. */
1745 for (i = 0; i < num_events; i++) {
1746 ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1747 time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1748 if (mode == 0) {
1749 /* data, ev */
1750 if (bufsz) {
1751 pos += scnprintf(*buf + pos, bufsz - pos,
1752 "EVT_LOG:0x%08x:%04u\n",
1753 time, ev);
1754 } else {
1755 trace_iwlwifi_dev_ucode_event(trans->dev, 0,
1756 time, ev);
1757 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1758 time, ev);
1759 }
1760 } else {
1761 data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1762 if (bufsz) {
1763 pos += scnprintf(*buf + pos, bufsz - pos,
1764 "EVT_LOGT:%010u:0x%08x:%04u\n",
1765 time, data, ev);
1766 } else {
1767 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1768 time, data, ev);
1769 trace_iwlwifi_dev_ucode_event(trans->dev, time,
1770 data, ev);
1771 }
1772 }
1773 }
1774
1775 /* Allow device to power down */
Lilach Edelsteine56b04e2013-01-16 11:34:49 +02001776 iwl_trans_release_nic_access(trans, &reg_flags);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001777 return pos;
1778}
1779
1780/**
1781 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1782 */
1783static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1784 u32 num_wraps, u32 next_entry,
1785 u32 size, u32 mode,
1786 int pos, char **buf, size_t bufsz)
1787{
1788 /*
1789 * display the newest DEFAULT_LOG_ENTRIES entries
1790 * i.e the entries just before the next ont that uCode would fill.
1791 */
1792 if (num_wraps) {
1793 if (next_entry < size) {
1794 pos = iwl_print_event_log(priv,
1795 capacity - (size - next_entry),
1796 size - next_entry, mode,
1797 pos, buf, bufsz);
1798 pos = iwl_print_event_log(priv, 0,
1799 next_entry, mode,
1800 pos, buf, bufsz);
1801 } else
1802 pos = iwl_print_event_log(priv, next_entry - size,
1803 size, mode, pos, buf, bufsz);
1804 } else {
1805 if (next_entry < size) {
1806 pos = iwl_print_event_log(priv, 0, next_entry,
1807 mode, pos, buf, bufsz);
1808 } else {
1809 pos = iwl_print_event_log(priv, next_entry - size,
1810 size, mode, pos, buf, bufsz);
1811 }
1812 }
1813 return pos;
1814}
1815
1816#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1817
1818int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
Stanislaw Gruszkaa6db0062013-04-16 15:40:54 +02001819 char **buf)
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001820{
1821 u32 base; /* SRAM byte address of event log header */
1822 u32 capacity; /* event log capacity in # entries */
1823 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1824 u32 num_wraps; /* # times uCode wrapped to top of log */
1825 u32 next_entry; /* index of next entry to be written by uCode */
1826 u32 size; /* # entries that we'll print */
1827 u32 logsize;
1828 int pos = 0;
1829 size_t bufsz = 0;
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001830 struct iwl_trans *trans = priv->trans;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001831
1832 base = priv->device_pointers.log_event_table;
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -07001833 if (priv->cur_ucode == IWL_UCODE_INIT) {
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001834 logsize = priv->fw->init_evtlog_size;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001835 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001836 base = priv->fw->init_evtlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001837 } else {
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001838 logsize = priv->fw->inst_evtlog_size;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001839 if (!base)
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001840 base = priv->fw->inst_evtlog_ptr;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001841 }
1842
1843 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1844 IWL_ERR(priv,
1845 "Invalid event log pointer 0x%08X for %s uCode\n",
1846 base,
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -07001847 (priv->cur_ucode == IWL_UCODE_INIT)
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001848 ? "Init" : "RT");
1849 return -EINVAL;
1850 }
1851
1852 /* event log header */
Emmanuel Grumbach4fd442d2012-12-24 14:27:11 +02001853 capacity = iwl_trans_read_mem32(trans, base);
1854 mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32)));
1855 num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32)));
1856 next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32)));
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001857
1858 if (capacity > logsize) {
1859 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
1860 "entries\n", capacity, logsize);
1861 capacity = logsize;
1862 }
1863
1864 if (next_entry > logsize) {
1865 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
1866 next_entry, logsize);
1867 next_entry = logsize;
1868 }
1869
1870 size = num_wraps ? capacity : next_entry;
1871
1872 /* bail out if nothing in log */
1873 if (size == 0) {
1874 IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
1875 return pos;
1876 }
1877
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001878 if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
1879 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1880 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001881 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1882 size);
1883
1884#ifdef CONFIG_IWLWIFI_DEBUG
Stanislaw Gruszkaa6db0062013-04-16 15:40:54 +02001885 if (buf) {
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001886 if (full_log)
1887 bufsz = capacity * 48;
1888 else
1889 bufsz = size * 48;
1890 *buf = kmalloc(bufsz, GFP_KERNEL);
1891 if (!*buf)
1892 return -ENOMEM;
1893 }
1894 if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
1895 /*
1896 * if uCode has wrapped back to top of log,
1897 * start at the oldest entry,
1898 * i.e the next one that uCode would fill.
1899 */
1900 if (num_wraps)
1901 pos = iwl_print_event_log(priv, next_entry,
1902 capacity - next_entry, mode,
1903 pos, buf, bufsz);
1904 /* (then/else) start at top of log */
1905 pos = iwl_print_event_log(priv, 0,
1906 next_entry, mode, pos, buf, bufsz);
1907 } else
1908 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1909 next_entry, size, mode,
1910 pos, buf, bufsz);
1911#else
1912 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1913 next_entry, size, mode,
1914 pos, buf, bufsz);
1915#endif
1916 return pos;
1917}
1918
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001919static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
1920{
1921 unsigned int reload_msec;
1922 unsigned long reload_jiffies;
1923
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001924 if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
1925 iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001926
1927 /* uCode is no longer loaded. */
1928 priv->ucode_loaded = false;
1929
1930 /* Set the FW error flag -- cleared on iwl_down */
1931 set_bit(STATUS_FW_ERROR, &priv->status);
1932
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001933 iwl_abort_notification_waits(&priv->notif_wait);
1934
1935 /* Keep the restart process from trying to send host
1936 * commands by clearing the ready bit */
1937 clear_bit(STATUS_READY, &priv->status);
1938
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001939 if (!ondemand) {
1940 /*
1941 * If firmware keep reloading, then it indicate something
1942 * serious wrong and firmware having problem to recover
1943 * from it. Instead of keep trying which will fill the syslog
1944 * and hang the system, let's just stop it
1945 */
1946 reload_jiffies = jiffies;
1947 reload_msec = jiffies_to_msecs((long) reload_jiffies -
1948 (long) priv->reload_jiffies);
1949 priv->reload_jiffies = reload_jiffies;
1950 if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
1951 priv->reload_count++;
1952 if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
1953 IWL_ERR(priv, "BUG_ON, Stop restarting\n");
1954 return;
1955 }
1956 } else
1957 priv->reload_count = 0;
1958 }
1959
1960 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Johannes Berg65de7e82012-04-17 07:36:30 -07001961 if (iwlwifi_mod_params.restart_fw) {
Meenakshi Venkataraman193219c2012-03-13 18:00:15 -07001962 IWL_DEBUG_FW_ERRORS(priv,
1963 "Restarting adapter due to uCode error.\n");
1964 queue_work(priv->workqueue, &priv->restart);
1965 } else
1966 IWL_DEBUG_FW_ERRORS(priv,
1967 "Detected FW error, but not restarting\n");
1968 }
1969}
1970
Johannes Bergaca86262012-05-14 09:08:50 +02001971static void iwl_nic_error(struct iwl_op_mode *op_mode)
Meenakshi Venkataraman19469f42012-03-15 13:26:55 -07001972{
1973 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1974
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001975 IWL_ERR(priv, "Loaded firmware version: %s\n",
Meenakshi Venkataramane3ec26d2012-03-15 13:27:04 -07001976 priv->fw->fw_version);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001977
1978 iwl_dump_nic_error_log(priv);
Stanislaw Gruszkaa6db0062013-04-16 15:40:54 +02001979 iwl_dump_nic_event_log(priv, false, NULL);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07001980
Meenakshi Venkataraman19469f42012-03-15 13:26:55 -07001981 iwlagn_fw_error(priv, false);
1982}
1983
Johannes Bergaca86262012-05-14 09:08:50 +02001984static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
Johannes Berg0e781842012-03-06 13:30:49 -08001985{
1986 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1987
1988 if (!iwl_check_for_ct_kill(priv)) {
1989 IWL_ERR(priv, "Restarting adapter queue is full\n");
Meenakshi Venkataramanb7e21bf2012-03-15 13:26:54 -07001990 iwlagn_fw_error(priv, false);
Johannes Berg0e781842012-03-06 13:30:49 -08001991 }
1992}
1993
Johannes Berg1280d422012-05-30 12:36:23 +02001994#define EEPROM_RF_CONFIG_TYPE_MAX 0x3
1995
Johannes Bergaca86262012-05-14 09:08:50 +02001996static void iwl_nic_config(struct iwl_op_mode *op_mode)
Johannes Bergecdb9752012-03-06 13:31:03 -08001997{
1998 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1999
Emmanuel Grumbach08838cd2012-05-29 17:48:08 +03002000 /* SKU Control */
Lilach Edelsteine139dc42013-01-13 13:31:10 +02002001 iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
2002 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
2003 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
2004 (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
2005 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
2006 (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
2007 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
Emmanuel Grumbach08838cd2012-05-29 17:48:08 +03002008
Johannes Berg1280d422012-05-30 12:36:23 +02002009 /* write radio config values to register */
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002010 if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
Johannes Berg1280d422012-05-30 12:36:23 +02002011 u32 reg_val =
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002012 priv->nvm_data->radio_cfg_type <<
Johannes Berg1280d422012-05-30 12:36:23 +02002013 CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002014 priv->nvm_data->radio_cfg_step <<
Johannes Berg1280d422012-05-30 12:36:23 +02002015 CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002016 priv->nvm_data->radio_cfg_dash <<
Johannes Berg1280d422012-05-30 12:36:23 +02002017 CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
2018
Lilach Edelsteine139dc42013-01-13 13:31:10 +02002019 iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
2020 CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
2021 CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
2022 CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH,
2023 reg_val);
Johannes Berg1280d422012-05-30 12:36:23 +02002024
2025 IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02002026 priv->nvm_data->radio_cfg_type,
2027 priv->nvm_data->radio_cfg_step,
2028 priv->nvm_data->radio_cfg_dash);
Johannes Berg1280d422012-05-30 12:36:23 +02002029 } else {
2030 WARN_ON(1);
2031 }
2032
2033 /* set CSR_HW_CONFIG_REG for uCode use */
2034 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
2035 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
2036 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
2037
Emmanuel Grumbachdada03c2012-06-17 15:42:37 +03002038 /* W/A : NIC is stuck in a reset state after Early PCIe power off
2039 * (PCIe power is lost before PERST# is asserted),
2040 * causing ME FW to lose ownership and not being able to obtain it back.
2041 */
2042 iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
2043 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
2044 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
2045
2046 if (priv->lib->nic_config)
2047 priv->lib->nic_config(priv);
Johannes Bergecdb9752012-03-06 13:31:03 -08002048}
2049
Don Fry8a8bbdb2012-03-20 10:33:34 -07002050static void iwl_wimax_active(struct iwl_op_mode *op_mode)
2051{
2052 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2053
2054 clear_bit(STATUS_READY, &priv->status);
2055 IWL_ERR(priv, "RF is used by WiMAX\n");
2056}
2057
Johannes Bergaca86262012-05-14 09:08:50 +02002058static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
Johannes Berge755f882012-03-07 09:52:16 -08002059{
2060 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berg14791772012-04-17 07:39:03 -07002061 int mq = priv->queue_to_mac80211[queue];
Johannes Berg9eae88f2012-03-15 13:26:52 -07002062
Johannes Berg14791772012-04-17 07:39:03 -07002063 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
Johannes Berg9eae88f2012-03-15 13:26:52 -07002064 return;
2065
Johannes Berg14791772012-04-17 07:39:03 -07002066 if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
Johannes Berg9eae88f2012-03-15 13:26:52 -07002067 IWL_DEBUG_TX_QUEUES(priv,
Johannes Berg14791772012-04-17 07:39:03 -07002068 "queue %d (mac80211 %d) already stopped\n",
2069 queue, mq);
Johannes Berg9eae88f2012-03-15 13:26:52 -07002070 return;
2071 }
Johannes Berge755f882012-03-07 09:52:16 -08002072
Johannes Berg14791772012-04-17 07:39:03 -07002073 set_bit(mq, &priv->transport_queue_stop);
2074 ieee80211_stop_queue(priv->hw, mq);
Johannes Berge755f882012-03-07 09:52:16 -08002075}
2076
Johannes Bergaca86262012-05-14 09:08:50 +02002077static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
Johannes Berge755f882012-03-07 09:52:16 -08002078{
2079 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Johannes Berg14791772012-04-17 07:39:03 -07002080 int mq = priv->queue_to_mac80211[queue];
Johannes Berg9eae88f2012-03-15 13:26:52 -07002081
Johannes Berg14791772012-04-17 07:39:03 -07002082 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
Johannes Berg9eae88f2012-03-15 13:26:52 -07002083 return;
2084
Johannes Berg14791772012-04-17 07:39:03 -07002085 if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
Johannes Berg9eae88f2012-03-15 13:26:52 -07002086 IWL_DEBUG_TX_QUEUES(priv,
Johannes Berg14791772012-04-17 07:39:03 -07002087 "queue %d (mac80211 %d) already awake\n",
2088 queue, mq);
Johannes Berg9eae88f2012-03-15 13:26:52 -07002089 return;
2090 }
Johannes Berge755f882012-03-07 09:52:16 -08002091
Johannes Berg14791772012-04-17 07:39:03 -07002092 clear_bit(mq, &priv->transport_queue_stop);
Johannes Berge755f882012-03-07 09:52:16 -08002093
2094 if (!priv->passive_no_rx)
Johannes Berg14791772012-04-17 07:39:03 -07002095 ieee80211_wake_queue(priv->hw, mq);
Johannes Berge755f882012-03-07 09:52:16 -08002096}
2097
2098void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
2099{
Johannes Berg14791772012-04-17 07:39:03 -07002100 int mq;
Johannes Berge755f882012-03-07 09:52:16 -08002101
2102 if (!priv->passive_no_rx)
2103 return;
2104
Johannes Berg14791772012-04-17 07:39:03 -07002105 for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
2106 if (!test_bit(mq, &priv->transport_queue_stop)) {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002107 IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d\n", mq);
Johannes Berg14791772012-04-17 07:39:03 -07002108 ieee80211_wake_queue(priv->hw, mq);
Emmanuel Grumbach32517152012-03-07 09:52:34 -08002109 } else {
Johannes Berg3c6acb62014-05-07 11:47:53 +02002110 IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d\n", mq);
Emmanuel Grumbach32517152012-03-07 09:52:34 -08002111 }
Johannes Berge755f882012-03-07 09:52:16 -08002112 }
2113
2114 priv->passive_no_rx = false;
2115}
2116
Johannes Bergaca86262012-05-14 09:08:50 +02002117static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
Meenakshi Venkataramanae625db2012-03-13 15:24:44 -07002118{
Emmanuel Grumbach59c647b2012-05-24 19:24:34 +03002119 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Meenakshi Venkataramanae625db2012-03-13 15:24:44 -07002120 struct ieee80211_tx_info *info;
2121
2122 info = IEEE80211_SKB_CB(skb);
Emmanuel Grumbach59c647b2012-05-24 19:24:34 +03002123 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
Johannes Berg31df3bb2012-10-31 22:07:39 +01002124 ieee80211_free_txskb(priv->hw, skb);
Meenakshi Venkataramanae625db2012-03-13 15:24:44 -07002125}
2126
Johannes Berg14cfca72014-02-25 20:50:53 +01002127static bool iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
Meenakshi Venkataramana297d952012-03-13 15:33:18 -07002128{
2129 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2130
2131 if (state)
2132 set_bit(STATUS_RF_KILL_HW, &priv->status);
2133 else
2134 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2135
2136 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
Johannes Berg14cfca72014-02-25 20:50:53 +01002137
2138 return false;
Meenakshi Venkataramana297d952012-03-13 15:33:18 -07002139}
2140
Johannes Bergb1abeda2012-05-31 13:54:56 +02002141static const struct iwl_op_mode_ops iwl_dvm_ops = {
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002142 .start = iwl_op_mode_dvm_start,
2143 .stop = iwl_op_mode_dvm_stop,
Emmanuel Grumbachdb70f292012-02-09 16:08:15 +02002144 .rx = iwl_rx_dispatch,
Emmanuel Grumbach02e38352012-02-09 16:08:15 +02002145 .queue_full = iwl_stop_sw_queue,
2146 .queue_not_full = iwl_wake_sw_queue,
Emmanuel Grumbach7120d982012-02-09 16:08:15 +02002147 .hw_rf_kill = iwl_set_hw_rfkill_state,
Emmanuel Grumbached277c92012-02-09 16:08:15 +02002148 .free_skb = iwl_free_skb,
Emmanuel Grumbachbcb93212012-02-09 16:08:15 +02002149 .nic_error = iwl_nic_error,
Johannes Berg0e781842012-03-06 13:30:49 -08002150 .cmd_queue_full = iwl_cmd_queue_full,
Johannes Bergecdb9752012-03-06 13:31:03 -08002151 .nic_config = iwl_nic_config,
Don Fry8a8bbdb2012-03-20 10:33:34 -07002152 .wimax_active = iwl_wimax_active,
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02002153};
Zhu Yib481de92007-09-25 17:54:57 -07002154
2155/*****************************************************************************
2156 *
2157 * driver and module entry point
2158 *
2159 *****************************************************************************/
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002160static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07002161{
2162
2163 int ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07002164
Tomas Winklere227cea2008-07-18 13:53:05 +08002165 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07002166 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07002167 pr_err("Unable to register rate control algorithm: %d\n", ret);
Emmanuel Grumbach59c647b2012-05-24 19:24:34 +03002168 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07002169 }
2170
Don Frycc5f7e32012-05-16 22:54:27 +02002171 ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
2172 if (ret) {
2173 pr_err("Unable to register op_mode: %d\n", ret);
Emmanuel Grumbach59c647b2012-05-24 19:24:34 +03002174 iwlagn_rate_control_unregister();
Don Frycc5f7e32012-05-16 22:54:27 +02002175 }
Reinette Chatre897e1cf2008-03-28 16:21:09 -07002176
Reinette Chatre897e1cf2008-03-28 16:21:09 -07002177 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002178}
Don Frycc5f7e32012-05-16 22:54:27 +02002179module_init(iwl_init);
Zhu Yib481de92007-09-25 17:54:57 -07002180
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002181static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07002182{
Don Frycc5f7e32012-05-16 22:54:27 +02002183 iwl_opmode_deregister("iwldvm");
Tomas Winklere227cea2008-07-18 13:53:05 +08002184 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07002185}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002186module_exit(iwl_exit);