• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
3  *
4  * Copyright(c) 2003 - 2014, 2018 - 2022 Intel Corporation. All rights reserved.
5  * Copyright(c) 2024 Intel Corporation. All rights reserved.
6  * Copyright(c) 2015 Intel Deutschland GmbH
7  *
8  * Portions of this file are derived from the ipw3945 project, as well
9  * as portions of the ieee80211 subsystem header files.
10  *****************************************************************************/
11 
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/sched.h>
20 #include <linux/skbuff.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/if_arp.h>
24 
25 #include <net/mac80211.h>
26 
27 #include <asm/div64.h>
28 
29 #include "iwl-nvm-utils.h"
30 #include "iwl-io.h"
31 #include "iwl-trans.h"
32 #include "iwl-op-mode.h"
33 #include "iwl-drv.h"
34 #include "iwl-modparams.h"
35 #include "iwl-prph.h"
36 
37 #include "dev.h"
38 #include "calib.h"
39 #include "agn.h"
40 
41 
42 /******************************************************************************
43  *
44  * module boiler plate
45  *
46  ******************************************************************************/
47 
48 #define DRV_DESCRIPTION	"Intel(R) Wireless WiFi Link AGN driver for Linux"
49 MODULE_DESCRIPTION(DRV_DESCRIPTION);
50 MODULE_LICENSE("GPL");
51 MODULE_IMPORT_NS(IWLWIFI);
52 
53 /* Please keep this array *SORTED* by hex value.
54  * Access is done through binary search.
55  * A warning will be triggered on violation.
56  */
57 static const struct iwl_hcmd_names iwl_dvm_cmd_names[] = {
58 	HCMD_NAME(REPLY_ALIVE),
59 	HCMD_NAME(REPLY_ERROR),
60 	HCMD_NAME(REPLY_ECHO),
61 	HCMD_NAME(REPLY_RXON),
62 	HCMD_NAME(REPLY_RXON_ASSOC),
63 	HCMD_NAME(REPLY_QOS_PARAM),
64 	HCMD_NAME(REPLY_RXON_TIMING),
65 	HCMD_NAME(REPLY_ADD_STA),
66 	HCMD_NAME(REPLY_REMOVE_STA),
67 	HCMD_NAME(REPLY_REMOVE_ALL_STA),
68 	HCMD_NAME(REPLY_TX),
69 	HCMD_NAME(REPLY_TXFIFO_FLUSH),
70 	HCMD_NAME(REPLY_WEPKEY),
71 	HCMD_NAME(REPLY_LEDS_CMD),
72 	HCMD_NAME(REPLY_TX_LINK_QUALITY_CMD),
73 	HCMD_NAME(COEX_PRIORITY_TABLE_CMD),
74 	HCMD_NAME(COEX_MEDIUM_NOTIFICATION),
75 	HCMD_NAME(COEX_EVENT_CMD),
76 	HCMD_NAME(TEMPERATURE_NOTIFICATION),
77 	HCMD_NAME(CALIBRATION_CFG_CMD),
78 	HCMD_NAME(CALIBRATION_RES_NOTIFICATION),
79 	HCMD_NAME(CALIBRATION_COMPLETE_NOTIFICATION),
80 	HCMD_NAME(REPLY_QUIET_CMD),
81 	HCMD_NAME(REPLY_CHANNEL_SWITCH),
82 	HCMD_NAME(CHANNEL_SWITCH_NOTIFICATION),
83 	HCMD_NAME(REPLY_SPECTRUM_MEASUREMENT_CMD),
84 	HCMD_NAME(SPECTRUM_MEASURE_NOTIFICATION),
85 	HCMD_NAME(POWER_TABLE_CMD),
86 	HCMD_NAME(PM_SLEEP_NOTIFICATION),
87 	HCMD_NAME(PM_DEBUG_STATISTIC_NOTIFIC),
88 	HCMD_NAME(REPLY_SCAN_CMD),
89 	HCMD_NAME(REPLY_SCAN_ABORT_CMD),
90 	HCMD_NAME(SCAN_START_NOTIFICATION),
91 	HCMD_NAME(SCAN_RESULTS_NOTIFICATION),
92 	HCMD_NAME(SCAN_COMPLETE_NOTIFICATION),
93 	HCMD_NAME(BEACON_NOTIFICATION),
94 	HCMD_NAME(REPLY_TX_BEACON),
95 	HCMD_NAME(WHO_IS_AWAKE_NOTIFICATION),
96 	HCMD_NAME(REPLY_TX_POWER_DBM_CMD),
97 	HCMD_NAME(QUIET_NOTIFICATION),
98 	HCMD_NAME(REPLY_TX_PWR_TABLE_CMD),
99 	HCMD_NAME(REPLY_TX_POWER_DBM_CMD_V1),
100 	HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
101 	HCMD_NAME(MEASURE_ABORT_NOTIFICATION),
102 	HCMD_NAME(REPLY_BT_CONFIG),
103 	HCMD_NAME(REPLY_STATISTICS_CMD),
104 	HCMD_NAME(STATISTICS_NOTIFICATION),
105 	HCMD_NAME(REPLY_CARD_STATE_CMD),
106 	HCMD_NAME(CARD_STATE_NOTIFICATION),
107 	HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
108 	HCMD_NAME(REPLY_CT_KILL_CONFIG_CMD),
109 	HCMD_NAME(SENSITIVITY_CMD),
110 	HCMD_NAME(REPLY_PHY_CALIBRATION_CMD),
111 	HCMD_NAME(REPLY_WIPAN_PARAMS),
112 	HCMD_NAME(REPLY_WIPAN_RXON),
113 	HCMD_NAME(REPLY_WIPAN_RXON_TIMING),
114 	HCMD_NAME(REPLY_WIPAN_RXON_ASSOC),
115 	HCMD_NAME(REPLY_WIPAN_QOS_PARAM),
116 	HCMD_NAME(REPLY_WIPAN_WEPKEY),
117 	HCMD_NAME(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
118 	HCMD_NAME(REPLY_WIPAN_NOA_NOTIFICATION),
119 	HCMD_NAME(REPLY_WIPAN_DEACTIVATION_COMPLETE),
120 	HCMD_NAME(REPLY_RX_PHY_CMD),
121 	HCMD_NAME(REPLY_RX_MPDU_CMD),
122 	HCMD_NAME(REPLY_RX),
123 	HCMD_NAME(REPLY_COMPRESSED_BA),
124 	HCMD_NAME(REPLY_BT_COEX_PRIO_TABLE),
125 	HCMD_NAME(REPLY_BT_COEX_PROT_ENV),
126 	HCMD_NAME(REPLY_BT_COEX_PROFILE_NOTIF),
127 	HCMD_NAME(REPLY_D3_CONFIG),
128 	HCMD_NAME(REPLY_WOWLAN_PATTERNS),
129 	HCMD_NAME(REPLY_WOWLAN_WAKEUP_FILTER),
130 	HCMD_NAME(REPLY_WOWLAN_TSC_RSC_PARAMS),
131 	HCMD_NAME(REPLY_WOWLAN_TKIP_PARAMS),
132 	HCMD_NAME(REPLY_WOWLAN_KEK_KCK_MATERIAL),
133 	HCMD_NAME(REPLY_WOWLAN_GET_STATUS),
134 };
135 
136 static const struct iwl_hcmd_arr iwl_dvm_groups[] = {
137 	[0x0] = HCMD_ARR(iwl_dvm_cmd_names),
138 };
139 
140 static const struct iwl_op_mode_ops iwl_dvm_ops;
141 
iwl_update_chain_flags(struct iwl_priv * priv)142 void iwl_update_chain_flags(struct iwl_priv *priv)
143 {
144 	struct iwl_rxon_context *ctx;
145 
146 	for_each_context(priv, ctx) {
147 		iwlagn_set_rxon_chain(priv, ctx);
148 		if (ctx->active.rx_chain != ctx->staging.rx_chain)
149 			iwlagn_commit_rxon(priv, ctx);
150 	}
151 }
152 
153 /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
iwl_set_beacon_tim(struct iwl_priv * priv,struct iwl_tx_beacon_cmd * tx_beacon_cmd,u8 * beacon,u32 frame_size)154 static void iwl_set_beacon_tim(struct iwl_priv *priv,
155 			       struct iwl_tx_beacon_cmd *tx_beacon_cmd,
156 			       u8 *beacon, u32 frame_size)
157 {
158 	u16 tim_idx;
159 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
160 
161 	/*
162 	 * The index is relative to frame start but we start looking at the
163 	 * variable-length part of the beacon.
164 	 */
165 	tim_idx = mgmt->u.beacon.variable - beacon;
166 
167 	/* Parse variable-length elements of beacon to find WLAN_EID_TIM */
168 	while ((tim_idx < (frame_size - 2)) &&
169 			(beacon[tim_idx] != WLAN_EID_TIM))
170 		tim_idx += beacon[tim_idx+1] + 2;
171 
172 	/* If TIM field was found, set variables */
173 	if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
174 		tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
175 		tx_beacon_cmd->tim_size = beacon[tim_idx+1];
176 	} else
177 		IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
178 }
179 
iwlagn_send_beacon_cmd(struct iwl_priv * priv)180 int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
181 {
182 	struct iwl_tx_beacon_cmd *tx_beacon_cmd;
183 	struct iwl_host_cmd cmd = {
184 		.id = REPLY_TX_BEACON,
185 	};
186 	struct ieee80211_tx_info *info;
187 	u32 frame_size;
188 	u32 rate_flags;
189 	u32 rate;
190 
191 	/*
192 	 * We have to set up the TX command, the TX Beacon command, and the
193 	 * beacon contents.
194 	 */
195 
196 	lockdep_assert_held(&priv->mutex);
197 
198 	if (!priv->beacon_ctx) {
199 		IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
200 		return 0;
201 	}
202 
203 	if (WARN_ON(!priv->beacon_skb))
204 		return -EINVAL;
205 
206 	/* Allocate beacon command */
207 	if (!priv->beacon_cmd)
208 		priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
209 	tx_beacon_cmd = priv->beacon_cmd;
210 	if (!tx_beacon_cmd)
211 		return -ENOMEM;
212 
213 	frame_size = priv->beacon_skb->len;
214 
215 	/* Set up TX command fields */
216 	tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
217 	tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
218 	tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
219 	tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
220 		TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
221 
222 	/* Set up TX beacon command fields */
223 	iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
224 			   frame_size);
225 
226 	/* Set up packet rate and flags */
227 	info = IEEE80211_SKB_CB(priv->beacon_skb);
228 
229 	/*
230 	 * Let's set up the rate at least somewhat correctly;
231 	 * it will currently not actually be used by the uCode,
232 	 * it uses the broadcast station's rate instead.
233 	 */
234 	if (info->control.rates[0].idx < 0 ||
235 	    info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
236 		rate = 0;
237 	else
238 		rate = info->control.rates[0].idx;
239 
240 	priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
241 					      priv->nvm_data->valid_tx_ant);
242 	rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
243 
244 	/* In mac80211, rates for 5 GHz start at 0 */
245 	if (info->band == NL80211_BAND_5GHZ)
246 		rate += IWL_FIRST_OFDM_RATE;
247 	else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
248 		rate_flags |= RATE_MCS_CCK_MSK;
249 
250 	tx_beacon_cmd->tx.rate_n_flags =
251 			iwl_hw_set_rate_n_flags(rate, rate_flags);
252 
253 	/* Submit command */
254 	cmd.len[0] = sizeof(*tx_beacon_cmd);
255 	cmd.data[0] = tx_beacon_cmd;
256 	cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
257 	cmd.len[1] = frame_size;
258 	cmd.data[1] = priv->beacon_skb->data;
259 	cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
260 
261 	return iwl_dvm_send_cmd(priv, &cmd);
262 }
263 
iwl_bg_beacon_update(struct work_struct * work)264 static void iwl_bg_beacon_update(struct work_struct *work)
265 {
266 	struct iwl_priv *priv =
267 		container_of(work, struct iwl_priv, beacon_update);
268 	struct sk_buff *beacon;
269 
270 	mutex_lock(&priv->mutex);
271 	if (!priv->beacon_ctx) {
272 		IWL_ERR(priv, "updating beacon w/o beacon context!\n");
273 		goto out;
274 	}
275 
276 	if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
277 		/*
278 		 * The ucode will send beacon notifications even in
279 		 * IBSS mode, but we don't want to process them. But
280 		 * we need to defer the type check to here due to
281 		 * requiring locking around the beacon_ctx access.
282 		 */
283 		goto out;
284 	}
285 
286 	/* Pull updated AP beacon from mac80211. will fail if not in AP mode */
287 	beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif, 0);
288 	if (!beacon) {
289 		IWL_ERR(priv, "update beacon failed -- keeping old\n");
290 		goto out;
291 	}
292 
293 	/* new beacon skb is allocated every time; dispose previous.*/
294 	dev_kfree_skb(priv->beacon_skb);
295 
296 	priv->beacon_skb = beacon;
297 
298 	iwlagn_send_beacon_cmd(priv);
299  out:
300 	mutex_unlock(&priv->mutex);
301 }
302 
iwl_bg_bt_runtime_config(struct work_struct * work)303 static void iwl_bg_bt_runtime_config(struct work_struct *work)
304 {
305 	struct iwl_priv *priv =
306 		container_of(work, struct iwl_priv, bt_runtime_config);
307 
308 	mutex_lock(&priv->mutex);
309 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
310 		goto out;
311 
312 	/* dont send host command if rf-kill is on */
313 	if (!iwl_is_ready_rf(priv))
314 		goto out;
315 
316 	iwlagn_send_advance_bt_config(priv);
317 out:
318 	mutex_unlock(&priv->mutex);
319 }
320 
iwl_bg_bt_full_concurrency(struct work_struct * work)321 static void iwl_bg_bt_full_concurrency(struct work_struct *work)
322 {
323 	struct iwl_priv *priv =
324 		container_of(work, struct iwl_priv, bt_full_concurrency);
325 	struct iwl_rxon_context *ctx;
326 
327 	mutex_lock(&priv->mutex);
328 
329 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
330 		goto out;
331 
332 	/* dont send host command if rf-kill is on */
333 	if (!iwl_is_ready_rf(priv))
334 		goto out;
335 
336 	IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
337 		       priv->bt_full_concurrent ?
338 		       "full concurrency" : "3-wire");
339 
340 	/*
341 	 * LQ & RXON updated cmds must be sent before BT Config cmd
342 	 * to avoid 3-wire collisions
343 	 */
344 	for_each_context(priv, ctx) {
345 		iwlagn_set_rxon_chain(priv, ctx);
346 		iwlagn_commit_rxon(priv, ctx);
347 	}
348 
349 	iwlagn_send_advance_bt_config(priv);
350 out:
351 	mutex_unlock(&priv->mutex);
352 }
353 
iwl_send_statistics_request(struct iwl_priv * priv,u8 flags,bool clear)354 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
355 {
356 	struct iwl_statistics_cmd statistics_cmd = {
357 		.configuration_flags =
358 			clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
359 	};
360 
361 	if (flags & CMD_ASYNC)
362 		return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
363 					CMD_ASYNC,
364 					sizeof(struct iwl_statistics_cmd),
365 					&statistics_cmd);
366 	else
367 		return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 0,
368 					sizeof(struct iwl_statistics_cmd),
369 					&statistics_cmd);
370 }
371 
372 /*
373  * iwl_bg_statistics_periodic - Timer callback to queue statistics
374  *
375  * This callback is provided in order to send a statistics request.
376  *
377  * This timer function is continually reset to execute within
378  * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
379  * was received.  We need to ensure we receive the statistics in order
380  * to update the temperature used for calibrating the TXPOWER.
381  */
iwl_bg_statistics_periodic(struct timer_list * t)382 static void iwl_bg_statistics_periodic(struct timer_list *t)
383 {
384 	struct iwl_priv *priv = from_timer(priv, t, statistics_periodic);
385 
386 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
387 		return;
388 
389 	/* dont send host command if rf-kill is on */
390 	if (!iwl_is_ready_rf(priv))
391 		return;
392 
393 	iwl_send_statistics_request(priv, CMD_ASYNC, false);
394 }
395 
396 
iwl_print_cont_event_trace(struct iwl_priv * priv,u32 base,u32 start_idx,u32 num_events,u32 capacity,u32 mode)397 static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
398 					u32 start_idx, u32 num_events,
399 					u32 capacity, u32 mode)
400 {
401 	u32 i;
402 	u32 ptr;        /* SRAM byte address of log data */
403 	u32 ev, time, data; /* event log data */
404 
405 	if (mode == 0)
406 		ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
407 	else
408 		ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
409 
410 	/* Make sure device is powered up for SRAM reads */
411 	if (!iwl_trans_grab_nic_access(priv->trans))
412 		return;
413 
414 	/* Set starting address; reads will auto-increment */
415 	iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr);
416 
417 	/*
418 	 * Refuse to read more than would have fit into the log from
419 	 * the current start_idx. This used to happen due to the race
420 	 * described below, but now WARN because the code below should
421 	 * prevent it from happening here.
422 	 */
423 	if (WARN_ON(num_events > capacity - start_idx))
424 		num_events = capacity - start_idx;
425 
426 	/*
427 	 * "time" is actually "data" for mode 0 (no timestamp).
428 	 * place event id # at far right for easier visual parsing.
429 	 */
430 	for (i = 0; i < num_events; i++) {
431 		ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
432 		time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
433 		if (mode == 0) {
434 			trace_iwlwifi_dev_ucode_cont_event(
435 					priv->trans->dev, 0, time, ev);
436 		} else {
437 			data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
438 			trace_iwlwifi_dev_ucode_cont_event(
439 					priv->trans->dev, time, data, ev);
440 		}
441 	}
442 	/* Allow device to power down */
443 	iwl_trans_release_nic_access(priv->trans);
444 }
445 
iwl_continuous_event_trace(struct iwl_priv * priv)446 static void iwl_continuous_event_trace(struct iwl_priv *priv)
447 {
448 	u32 capacity;   /* event log capacity in # entries */
449 	struct {
450 		u32 capacity;
451 		u32 mode;
452 		u32 wrap_counter;
453 		u32 write_counter;
454 	} __packed read;
455 	u32 base;       /* SRAM byte address of event log header */
456 	u32 mode;       /* 0 - no timestamp, 1 - timestamp recorded */
457 	u32 num_wraps;  /* # times uCode wrapped to top of log */
458 	u32 next_entry; /* index of next entry to be written by uCode */
459 
460 	base = priv->device_pointers.log_event_table;
461 	if (iwlagn_hw_valid_rtc_data_addr(base)) {
462 		iwl_trans_read_mem_bytes(priv->trans, base,
463 					 &read, sizeof(read));
464 		capacity = read.capacity;
465 		mode = read.mode;
466 		num_wraps = read.wrap_counter;
467 		next_entry = read.write_counter;
468 	} else
469 		return;
470 
471 	/*
472 	 * Unfortunately, the uCode doesn't use temporary variables.
473 	 * Therefore, it can happen that we read next_entry == capacity,
474 	 * which really means next_entry == 0.
475 	 */
476 	if (unlikely(next_entry == capacity))
477 		next_entry = 0;
478 	/*
479 	 * Additionally, the uCode increases the write pointer before
480 	 * the wraps counter, so if the write pointer is smaller than
481 	 * the old write pointer (wrap occurred) but we read that no
482 	 * wrap occurred, we actually read between the next_entry and
483 	 * num_wraps update (this does happen in practice!!) -- take
484 	 * that into account by increasing num_wraps.
485 	 */
486 	if (unlikely(next_entry < priv->event_log.next_entry &&
487 		     num_wraps == priv->event_log.num_wraps))
488 		num_wraps++;
489 
490 	if (num_wraps == priv->event_log.num_wraps) {
491 		iwl_print_cont_event_trace(
492 			priv, base, priv->event_log.next_entry,
493 			next_entry - priv->event_log.next_entry,
494 			capacity, mode);
495 
496 		priv->event_log.non_wraps_count++;
497 	} else {
498 		if (num_wraps - priv->event_log.num_wraps > 1)
499 			priv->event_log.wraps_more_count++;
500 		else
501 			priv->event_log.wraps_once_count++;
502 
503 		trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
504 				num_wraps - priv->event_log.num_wraps,
505 				next_entry, priv->event_log.next_entry);
506 
507 		if (next_entry < priv->event_log.next_entry) {
508 			iwl_print_cont_event_trace(
509 				priv, base, priv->event_log.next_entry,
510 				capacity - priv->event_log.next_entry,
511 				capacity, mode);
512 
513 			iwl_print_cont_event_trace(
514 				priv, base, 0, next_entry, capacity, mode);
515 		} else {
516 			iwl_print_cont_event_trace(
517 				priv, base, next_entry,
518 				capacity - next_entry,
519 				capacity, mode);
520 
521 			iwl_print_cont_event_trace(
522 				priv, base, 0, next_entry, capacity, mode);
523 		}
524 	}
525 
526 	priv->event_log.num_wraps = num_wraps;
527 	priv->event_log.next_entry = next_entry;
528 }
529 
530 /*
531  * iwl_bg_ucode_trace - Timer callback to log ucode event
532  *
533  * The timer is continually set to execute every
534  * UCODE_TRACE_PERIOD milliseconds after the last timer expired
535  * this function is to perform continuous uCode event logging operation
536  * if enabled
537  */
iwl_bg_ucode_trace(struct timer_list * t)538 static void iwl_bg_ucode_trace(struct timer_list *t)
539 {
540 	struct iwl_priv *priv = from_timer(priv, t, ucode_trace);
541 
542 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
543 		return;
544 
545 	if (priv->event_log.ucode_trace) {
546 		iwl_continuous_event_trace(priv);
547 		/* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
548 		mod_timer(&priv->ucode_trace,
549 			 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
550 	}
551 }
552 
iwl_bg_tx_flush(struct work_struct * work)553 static void iwl_bg_tx_flush(struct work_struct *work)
554 {
555 	struct iwl_priv *priv =
556 		container_of(work, struct iwl_priv, tx_flush);
557 
558 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
559 		return;
560 
561 	/* do nothing if rf-kill is on */
562 	if (!iwl_is_ready_rf(priv))
563 		return;
564 
565 	IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
566 	iwlagn_dev_txfifo_flush(priv);
567 }
568 
569 /*
570  * queue/FIFO/AC mapping definitions
571  */
572 
573 static const u8 iwlagn_bss_ac_to_fifo[] = {
574 	IWL_TX_FIFO_VO,
575 	IWL_TX_FIFO_VI,
576 	IWL_TX_FIFO_BE,
577 	IWL_TX_FIFO_BK,
578 };
579 
580 static const u8 iwlagn_bss_ac_to_queue[] = {
581 	0, 1, 2, 3,
582 };
583 
584 static const u8 iwlagn_pan_ac_to_fifo[] = {
585 	IWL_TX_FIFO_VO_IPAN,
586 	IWL_TX_FIFO_VI_IPAN,
587 	IWL_TX_FIFO_BE_IPAN,
588 	IWL_TX_FIFO_BK_IPAN,
589 };
590 
591 static const u8 iwlagn_pan_ac_to_queue[] = {
592 	7, 6, 5, 4,
593 };
594 
iwl_init_context(struct iwl_priv * priv,u32 ucode_flags)595 static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
596 {
597 	int i;
598 
599 	/*
600 	 * The default context is always valid,
601 	 * the PAN context depends on uCode.
602 	 */
603 	priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
604 	if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
605 		priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
606 
607 	for (i = 0; i < NUM_IWL_RXON_CTX; i++)
608 		priv->contexts[i].ctxid = i;
609 
610 	priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
611 	priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
612 	priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
613 	priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
614 	priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
615 	priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
616 	priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
617 	priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
618 	priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
619 	priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
620 		BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
621 	priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
622 		BIT(NL80211_IFTYPE_STATION);
623 	priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
624 	priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
625 	priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
626 	priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
627 	memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
628 	       iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
629 	memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
630 	       iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
631 
632 	priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
633 	priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
634 		REPLY_WIPAN_RXON_TIMING;
635 	priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
636 		REPLY_WIPAN_RXON_ASSOC;
637 	priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
638 	priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
639 	priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
640 	priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
641 	priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
642 	priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
643 		BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
644 
645 	priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
646 	priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
647 	priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
648 	memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
649 	       iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
650 	memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
651 	       iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
652 	priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
653 
654 	BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
655 }
656 
iwl_rf_kill_ct_config(struct iwl_priv * priv)657 static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
658 {
659 	struct iwl_ct_kill_config cmd;
660 	struct iwl_ct_kill_throttling_config adv_cmd;
661 	int ret = 0;
662 
663 	iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
664 		    CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
665 
666 	priv->thermal_throttle.ct_kill_toggle = false;
667 
668 	if (priv->lib->support_ct_kill_exit) {
669 		adv_cmd.critical_temperature_enter =
670 			cpu_to_le32(priv->hw_params.ct_kill_threshold);
671 		adv_cmd.critical_temperature_exit =
672 			cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
673 
674 		ret = iwl_dvm_send_cmd_pdu(priv,
675 				       REPLY_CT_KILL_CONFIG_CMD,
676 				       0, sizeof(adv_cmd), &adv_cmd);
677 		if (ret)
678 			IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
679 		else
680 			IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
681 				"succeeded, critical temperature enter is %d,"
682 				"exit is %d\n",
683 				priv->hw_params.ct_kill_threshold,
684 				priv->hw_params.ct_kill_exit_threshold);
685 	} else {
686 		cmd.critical_temperature_R =
687 			cpu_to_le32(priv->hw_params.ct_kill_threshold);
688 
689 		ret = iwl_dvm_send_cmd_pdu(priv,
690 				       REPLY_CT_KILL_CONFIG_CMD,
691 				       0, sizeof(cmd), &cmd);
692 		if (ret)
693 			IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
694 		else
695 			IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
696 				"succeeded, "
697 				"critical temperature is %d\n",
698 				priv->hw_params.ct_kill_threshold);
699 	}
700 }
701 
iwlagn_send_calib_cfg_rt(struct iwl_priv * priv,u32 cfg)702 static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
703 {
704 	struct iwl_calib_cfg_cmd calib_cfg_cmd;
705 	struct iwl_host_cmd cmd = {
706 		.id = CALIBRATION_CFG_CMD,
707 		.len = { sizeof(struct iwl_calib_cfg_cmd), },
708 		.data = { &calib_cfg_cmd, },
709 	};
710 
711 	memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
712 	calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
713 	calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
714 
715 	return iwl_dvm_send_cmd(priv, &cmd);
716 }
717 
718 
iwlagn_send_tx_ant_config(struct iwl_priv * priv,u8 valid_tx_ant)719 static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
720 {
721 	struct iwl_tx_ant_config_cmd tx_ant_cmd = {
722 	  .valid = cpu_to_le32(valid_tx_ant),
723 	};
724 
725 	if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
726 		IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
727 		return iwl_dvm_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD, 0,
728 					sizeof(struct iwl_tx_ant_config_cmd),
729 					&tx_ant_cmd);
730 	} else {
731 		IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
732 		return -EOPNOTSUPP;
733 	}
734 }
735 
iwl_send_bt_config(struct iwl_priv * priv)736 static void iwl_send_bt_config(struct iwl_priv *priv)
737 {
738 	struct iwl_bt_cmd bt_cmd = {
739 		.lead_time = BT_LEAD_TIME_DEF,
740 		.max_kill = BT_MAX_KILL_DEF,
741 		.kill_ack_mask = 0,
742 		.kill_cts_mask = 0,
743 	};
744 
745 	if (!iwlwifi_mod_params.bt_coex_active)
746 		bt_cmd.flags = BT_COEX_DISABLE;
747 	else
748 		bt_cmd.flags = BT_COEX_ENABLE;
749 
750 	priv->bt_enable_flag = bt_cmd.flags;
751 	IWL_DEBUG_INFO(priv, "BT coex %s\n",
752 		(bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
753 
754 	if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
755 			     0, sizeof(struct iwl_bt_cmd), &bt_cmd))
756 		IWL_ERR(priv, "failed to send BT Coex Config\n");
757 }
758 
759 /*
760  * iwl_alive_start - called after REPLY_ALIVE notification received
761  *                   from protocol/runtime uCode (initialization uCode's
762  *                   Alive gets handled by iwl_init_alive_start()).
763  */
iwl_alive_start(struct iwl_priv * priv)764 int iwl_alive_start(struct iwl_priv *priv)
765 {
766 	int ret = 0;
767 	struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
768 
769 	IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
770 
771 	/* After the ALIVE response, we can send host commands to the uCode */
772 	set_bit(STATUS_ALIVE, &priv->status);
773 
774 	if (iwl_is_rfkill(priv))
775 		return -ERFKILL;
776 
777 	if (priv->event_log.ucode_trace) {
778 		/* start collecting data now */
779 		mod_timer(&priv->ucode_trace, jiffies);
780 	}
781 
782 	/* download priority table before any calibration request */
783 	if (priv->lib->bt_params &&
784 	    priv->lib->bt_params->advanced_bt_coexist) {
785 		/* Configure Bluetooth device coexistence support */
786 		if (priv->lib->bt_params->bt_sco_disable)
787 			priv->bt_enable_pspoll = false;
788 		else
789 			priv->bt_enable_pspoll = true;
790 
791 		priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
792 		priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
793 		priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
794 		iwlagn_send_advance_bt_config(priv);
795 		priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
796 		priv->cur_rssi_ctx = NULL;
797 
798 		iwl_send_prio_tbl(priv);
799 
800 		/* FIXME: w/a to force change uCode BT state machine */
801 		ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
802 					 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
803 		if (ret)
804 			return ret;
805 		ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
806 					 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
807 		if (ret)
808 			return ret;
809 	} else if (priv->lib->bt_params) {
810 		/*
811 		 * default is 2-wire BT coexexistence support
812 		 */
813 		iwl_send_bt_config(priv);
814 	}
815 
816 	/*
817 	 * Perform runtime calibrations, including DC calibration.
818 	 */
819 	iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
820 
821 	ieee80211_wake_queues(priv->hw);
822 
823 	/* Configure Tx antenna selection based on H/W config */
824 	iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant);
825 
826 	if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
827 		struct iwl_rxon_cmd *active_rxon =
828 				(struct iwl_rxon_cmd *)&ctx->active;
829 		/* apply any changes in staging */
830 		ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
831 		active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
832 	} else {
833 		struct iwl_rxon_context *tmp;
834 		/* Initialize our rx_config data */
835 		for_each_context(priv, tmp)
836 			iwl_connection_init_rx_config(priv, tmp);
837 
838 		iwlagn_set_rxon_chain(priv, ctx);
839 	}
840 
841 	if (!priv->wowlan) {
842 		/* WoWLAN ucode will not reply in the same way, skip it */
843 		iwl_reset_run_time_calib(priv);
844 	}
845 
846 	set_bit(STATUS_READY, &priv->status);
847 
848 	/* Configure the adapter for unassociated operation */
849 	ret = iwlagn_commit_rxon(priv, ctx);
850 	if (ret)
851 		return ret;
852 
853 	/* At this point, the NIC is initialized and operational */
854 	iwl_rf_kill_ct_config(priv);
855 
856 	IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
857 
858 	return iwl_power_update_mode(priv, true);
859 }
860 
861 /**
862  * iwl_clear_driver_stations - clear knowledge of all stations from driver
863  * @priv: iwl priv struct
864  *
865  * This is called during iwl_down() to make sure that in the case
866  * we're coming there from a hardware restart mac80211 will be
867  * able to reconfigure stations -- if we're getting there in the
868  * normal down flow then the stations will already be cleared.
869  */
iwl_clear_driver_stations(struct iwl_priv * priv)870 static void iwl_clear_driver_stations(struct iwl_priv *priv)
871 {
872 	struct iwl_rxon_context *ctx;
873 
874 	spin_lock_bh(&priv->sta_lock);
875 	memset(priv->stations, 0, sizeof(priv->stations));
876 	priv->num_stations = 0;
877 
878 	priv->ucode_key_table = 0;
879 
880 	for_each_context(priv, ctx) {
881 		/*
882 		 * Remove all key information that is not stored as part
883 		 * of station information since mac80211 may not have had
884 		 * a chance to remove all the keys. When device is
885 		 * reconfigured by mac80211 after an error all keys will
886 		 * be reconfigured.
887 		 */
888 		memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
889 		ctx->key_mapping_keys = 0;
890 	}
891 
892 	spin_unlock_bh(&priv->sta_lock);
893 }
894 
iwl_down(struct iwl_priv * priv)895 void iwl_down(struct iwl_priv *priv)
896 {
897 	int exit_pending;
898 
899 	IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
900 
901 	lockdep_assert_held(&priv->mutex);
902 
903 	iwl_scan_cancel_timeout(priv, 200);
904 
905 	exit_pending =
906 		test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
907 
908 	iwl_clear_ucode_stations(priv, NULL);
909 	iwl_dealloc_bcast_stations(priv);
910 	iwl_clear_driver_stations(priv);
911 
912 	/* reset BT coex data */
913 	priv->bt_status = 0;
914 	priv->cur_rssi_ctx = NULL;
915 	priv->bt_is_sco = 0;
916 	if (priv->lib->bt_params)
917 		priv->bt_traffic_load =
918 			 priv->lib->bt_params->bt_init_traffic_load;
919 	else
920 		priv->bt_traffic_load = 0;
921 	priv->bt_full_concurrent = false;
922 	priv->bt_ci_compliance = 0;
923 
924 	/* Wipe out the EXIT_PENDING status bit if we are not actually
925 	 * exiting the module */
926 	if (!exit_pending)
927 		clear_bit(STATUS_EXIT_PENDING, &priv->status);
928 
929 	if (priv->mac80211_registered)
930 		ieee80211_stop_queues(priv->hw);
931 
932 	priv->ucode_loaded = false;
933 	iwl_trans_stop_device(priv->trans);
934 
935 	/* Set num_aux_in_flight must be done after the transport is stopped */
936 	atomic_set(&priv->num_aux_in_flight, 0);
937 
938 	/* Clear out all status bits but a few that are stable across reset */
939 	priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
940 				STATUS_RF_KILL_HW |
941 			test_bit(STATUS_FW_ERROR, &priv->status) <<
942 				STATUS_FW_ERROR |
943 			test_bit(STATUS_EXIT_PENDING, &priv->status) <<
944 				STATUS_EXIT_PENDING;
945 
946 	dev_kfree_skb(priv->beacon_skb);
947 	priv->beacon_skb = NULL;
948 }
949 
950 /*****************************************************************************
951  *
952  * Workqueue callbacks
953  *
954  *****************************************************************************/
955 
iwl_bg_run_time_calib_work(struct work_struct * work)956 static void iwl_bg_run_time_calib_work(struct work_struct *work)
957 {
958 	struct iwl_priv *priv = container_of(work, struct iwl_priv,
959 			run_time_calib_work);
960 
961 	mutex_lock(&priv->mutex);
962 
963 	if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
964 	    test_bit(STATUS_SCANNING, &priv->status)) {
965 		mutex_unlock(&priv->mutex);
966 		return;
967 	}
968 
969 	if (priv->start_calib) {
970 		iwl_chain_noise_calibration(priv);
971 		iwl_sensitivity_calibration(priv);
972 	}
973 
974 	mutex_unlock(&priv->mutex);
975 }
976 
iwlagn_prepare_restart(struct iwl_priv * priv)977 void iwlagn_prepare_restart(struct iwl_priv *priv)
978 {
979 	bool bt_full_concurrent;
980 	u8 bt_ci_compliance;
981 	u8 bt_load;
982 	u8 bt_status;
983 	bool bt_is_sco;
984 	int i;
985 
986 	lockdep_assert_held(&priv->mutex);
987 
988 	priv->is_open = 0;
989 
990 	/*
991 	 * __iwl_down() will clear the BT status variables,
992 	 * which is correct, but when we restart we really
993 	 * want to keep them so restore them afterwards.
994 	 *
995 	 * The restart process will later pick them up and
996 	 * re-configure the hw when we reconfigure the BT
997 	 * command.
998 	 */
999 	bt_full_concurrent = priv->bt_full_concurrent;
1000 	bt_ci_compliance = priv->bt_ci_compliance;
1001 	bt_load = priv->bt_traffic_load;
1002 	bt_status = priv->bt_status;
1003 	bt_is_sco = priv->bt_is_sco;
1004 
1005 	iwl_down(priv);
1006 
1007 	priv->bt_full_concurrent = bt_full_concurrent;
1008 	priv->bt_ci_compliance = bt_ci_compliance;
1009 	priv->bt_traffic_load = bt_load;
1010 	priv->bt_status = bt_status;
1011 	priv->bt_is_sco = bt_is_sco;
1012 
1013 	/* reset aggregation queues */
1014 	for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
1015 		priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1016 	/* and stop counts */
1017 	for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
1018 		atomic_set(&priv->queue_stop_count[i], 0);
1019 
1020 	memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
1021 }
1022 
iwl_bg_restart(struct work_struct * data)1023 static void iwl_bg_restart(struct work_struct *data)
1024 {
1025 	struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
1026 
1027 	if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1028 		return;
1029 
1030 	if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
1031 		mutex_lock(&priv->mutex);
1032 		iwlagn_prepare_restart(priv);
1033 		mutex_unlock(&priv->mutex);
1034 		iwl_cancel_deferred_work(priv);
1035 		if (priv->mac80211_registered)
1036 			ieee80211_restart_hw(priv->hw);
1037 		else
1038 			IWL_ERR(priv,
1039 				"Cannot request restart before registering with mac80211\n");
1040 	} else {
1041 		WARN_ON(1);
1042 	}
1043 }
1044 
1045 /*****************************************************************************
1046  *
1047  * driver setup and teardown
1048  *
1049  *****************************************************************************/
1050 
iwl_setup_deferred_work(struct iwl_priv * priv)1051 static int iwl_setup_deferred_work(struct iwl_priv *priv)
1052 {
1053 	priv->workqueue = alloc_ordered_workqueue(DRV_NAME, 0);
1054 	if (!priv->workqueue)
1055 		return -ENOMEM;
1056 
1057 	INIT_WORK(&priv->restart, iwl_bg_restart);
1058 	INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
1059 	INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
1060 	INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
1061 	INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
1062 	INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
1063 
1064 	iwl_setup_scan_deferred_work(priv);
1065 
1066 	if (priv->lib->bt_params)
1067 		iwlagn_bt_setup_deferred_work(priv);
1068 
1069 	timer_setup(&priv->statistics_periodic, iwl_bg_statistics_periodic, 0);
1070 
1071 	timer_setup(&priv->ucode_trace, iwl_bg_ucode_trace, 0);
1072 
1073 	return 0;
1074 }
1075 
iwl_cancel_deferred_work(struct iwl_priv * priv)1076 void iwl_cancel_deferred_work(struct iwl_priv *priv)
1077 {
1078 	if (priv->lib->bt_params)
1079 		iwlagn_bt_cancel_deferred_work(priv);
1080 
1081 	cancel_work_sync(&priv->run_time_calib_work);
1082 	cancel_work_sync(&priv->beacon_update);
1083 
1084 	iwl_cancel_scan_deferred_work(priv);
1085 
1086 	cancel_work_sync(&priv->bt_full_concurrency);
1087 	cancel_work_sync(&priv->bt_runtime_config);
1088 
1089 	del_timer_sync(&priv->statistics_periodic);
1090 	del_timer_sync(&priv->ucode_trace);
1091 }
1092 
iwl_init_drv(struct iwl_priv * priv)1093 static int iwl_init_drv(struct iwl_priv *priv)
1094 {
1095 	spin_lock_init(&priv->sta_lock);
1096 
1097 	mutex_init(&priv->mutex);
1098 
1099 	INIT_LIST_HEAD(&priv->calib_results);
1100 
1101 	priv->band = NL80211_BAND_2GHZ;
1102 
1103 	priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold;
1104 
1105 	priv->iw_mode = NL80211_IFTYPE_STATION;
1106 	priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
1107 	priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
1108 	priv->agg_tids_count = 0;
1109 
1110 	priv->rx_statistics_jiffies = jiffies;
1111 
1112 	/* Choose which receivers/antennas to use */
1113 	iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
1114 
1115 	iwl_init_scan_params(priv);
1116 
1117 	/* init bt coex */
1118 	if (priv->lib->bt_params &&
1119 	    priv->lib->bt_params->advanced_bt_coexist) {
1120 		priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
1121 		priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
1122 		priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
1123 		priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
1124 		priv->bt_duration = BT_DURATION_LIMIT_DEF;
1125 		priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
1126 	}
1127 
1128 	return 0;
1129 }
1130 
iwl_uninit_drv(struct iwl_priv * priv)1131 static void iwl_uninit_drv(struct iwl_priv *priv)
1132 {
1133 	kfree(priv->scan_cmd);
1134 	kfree(priv->beacon_cmd);
1135 	kfree(rcu_dereference_raw(priv->noa_data));
1136 	iwl_calib_free_results(priv);
1137 #ifdef CONFIG_IWLWIFI_DEBUGFS
1138 	kfree(priv->wowlan_sram);
1139 #endif
1140 }
1141 
iwl_set_hw_params(struct iwl_priv * priv)1142 static void iwl_set_hw_params(struct iwl_priv *priv)
1143 {
1144 	if (priv->cfg->ht_params)
1145 		priv->hw_params.use_rts_for_aggregation =
1146 			priv->cfg->ht_params->use_rts_for_aggregation;
1147 
1148 	/* Device-specific setup */
1149 	priv->lib->set_hw_params(priv);
1150 }
1151 
1152 
1153 
1154 /* show what optional capabilities we have */
iwl_option_config(struct iwl_priv * priv)1155 static void iwl_option_config(struct iwl_priv *priv)
1156 {
1157 #ifdef CONFIG_IWLWIFI_DEBUG
1158 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
1159 #else
1160 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
1161 #endif
1162 
1163 #ifdef CONFIG_IWLWIFI_DEBUGFS
1164 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
1165 #else
1166 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
1167 #endif
1168 
1169 #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
1170 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
1171 #else
1172 	IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
1173 #endif
1174 }
1175 
iwl_eeprom_init_hw_params(struct iwl_priv * priv)1176 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
1177 {
1178 	struct iwl_nvm_data *data = priv->nvm_data;
1179 
1180 	if (data->sku_cap_11n_enable &&
1181 	    !priv->cfg->ht_params) {
1182 		IWL_ERR(priv, "Invalid 11n configuration\n");
1183 		return -EINVAL;
1184 	}
1185 
1186 	if (!data->sku_cap_11n_enable && !data->sku_cap_band_24ghz_enable &&
1187 	    !data->sku_cap_band_52ghz_enable) {
1188 		IWL_ERR(priv, "Invalid device sku\n");
1189 		return -EINVAL;
1190 	}
1191 
1192 	IWL_DEBUG_INFO(priv,
1193 		       "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n",
1194 		       data->sku_cap_band_24ghz_enable ? "" : "NOT", "enabled",
1195 		       data->sku_cap_band_52ghz_enable ? "" : "NOT", "enabled",
1196 		       data->sku_cap_11n_enable ? "" : "NOT", "enabled");
1197 
1198 	priv->hw_params.tx_chains_num =
1199 		num_of_ant(data->valid_tx_ant);
1200 	if (priv->cfg->rx_with_siso_diversity)
1201 		priv->hw_params.rx_chains_num = 1;
1202 	else
1203 		priv->hw_params.rx_chains_num =
1204 			num_of_ant(data->valid_rx_ant);
1205 
1206 	IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
1207 		       data->valid_tx_ant,
1208 		       data->valid_rx_ant);
1209 
1210 	return 0;
1211 }
1212 
iwl_nvm_check_version(struct iwl_nvm_data * data,struct iwl_trans * trans)1213 static int iwl_nvm_check_version(struct iwl_nvm_data *data,
1214 				 struct iwl_trans *trans)
1215 {
1216 	if (data->nvm_version >= trans->cfg->nvm_ver ||
1217 	    data->calib_version >= trans->cfg->nvm_calib_ver) {
1218 		IWL_DEBUG_INFO(trans, "device EEPROM VER=0x%x, CALIB=0x%x\n",
1219 			       data->nvm_version, data->calib_version);
1220 		return 0;
1221 	}
1222 
1223 	IWL_ERR(trans,
1224 		"Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
1225 		data->nvm_version, trans->cfg->nvm_ver,
1226 		data->calib_version,  trans->cfg->nvm_calib_ver);
1227 	return -EINVAL;
1228 }
1229 
iwl_op_mode_dvm_start(struct iwl_trans * trans,const struct iwl_cfg * cfg,const struct iwl_fw * fw,struct dentry * dbgfs_dir)1230 static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
1231 						 const struct iwl_cfg *cfg,
1232 						 const struct iwl_fw *fw,
1233 						 struct dentry *dbgfs_dir)
1234 {
1235 	struct iwl_priv *priv;
1236 	struct ieee80211_hw *hw;
1237 	struct iwl_op_mode *op_mode;
1238 	u16 num_mac;
1239 	u32 ucode_flags;
1240 	struct iwl_trans_config trans_cfg = {};
1241 	static const u8 no_reclaim_cmds[] = {
1242 		REPLY_RX_PHY_CMD,
1243 		REPLY_RX_MPDU_CMD,
1244 		REPLY_COMPRESSED_BA,
1245 		STATISTICS_NOTIFICATION,
1246 		REPLY_TX,
1247 	};
1248 	int i;
1249 
1250 	/************************
1251 	 * 1. Allocating HW data
1252 	 ************************/
1253 	hw = iwl_alloc_all();
1254 	if (!hw) {
1255 		pr_err("%s: Cannot allocate network device\n", trans->name);
1256 		goto out;
1257 	}
1258 
1259 	op_mode = hw->priv;
1260 	op_mode->ops = &iwl_dvm_ops;
1261 	priv = IWL_OP_MODE_GET_DVM(op_mode);
1262 	priv->trans = trans;
1263 	priv->dev = trans->dev;
1264 	priv->cfg = cfg;
1265 	priv->fw = fw;
1266 
1267 	switch (priv->trans->trans_cfg->device_family) {
1268 	case IWL_DEVICE_FAMILY_1000:
1269 	case IWL_DEVICE_FAMILY_100:
1270 		priv->lib = &iwl_dvm_1000_cfg;
1271 		break;
1272 	case IWL_DEVICE_FAMILY_2000:
1273 		priv->lib = &iwl_dvm_2000_cfg;
1274 		break;
1275 	case IWL_DEVICE_FAMILY_105:
1276 		priv->lib = &iwl_dvm_105_cfg;
1277 		break;
1278 	case IWL_DEVICE_FAMILY_2030:
1279 	case IWL_DEVICE_FAMILY_135:
1280 		priv->lib = &iwl_dvm_2030_cfg;
1281 		break;
1282 	case IWL_DEVICE_FAMILY_5000:
1283 		priv->lib = &iwl_dvm_5000_cfg;
1284 		break;
1285 	case IWL_DEVICE_FAMILY_5150:
1286 		priv->lib = &iwl_dvm_5150_cfg;
1287 		break;
1288 	case IWL_DEVICE_FAMILY_6000:
1289 	case IWL_DEVICE_FAMILY_6000i:
1290 		priv->lib = &iwl_dvm_6000_cfg;
1291 		break;
1292 	case IWL_DEVICE_FAMILY_6005:
1293 		priv->lib = &iwl_dvm_6005_cfg;
1294 		break;
1295 	case IWL_DEVICE_FAMILY_6050:
1296 	case IWL_DEVICE_FAMILY_6150:
1297 		priv->lib = &iwl_dvm_6050_cfg;
1298 		break;
1299 	case IWL_DEVICE_FAMILY_6030:
1300 		priv->lib = &iwl_dvm_6030_cfg;
1301 		break;
1302 	default:
1303 		break;
1304 	}
1305 
1306 	if (WARN_ON(!priv->lib))
1307 		goto out_free_hw;
1308 
1309 	/*
1310 	 * Populate the state variables that the transport layer needs
1311 	 * to know about.
1312 	 */
1313 	trans_cfg.op_mode = op_mode;
1314 	trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
1315 	trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
1316 
1317 	switch (iwlwifi_mod_params.amsdu_size) {
1318 	case IWL_AMSDU_DEF:
1319 	case IWL_AMSDU_4K:
1320 		trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1321 		break;
1322 	case IWL_AMSDU_8K:
1323 		trans_cfg.rx_buf_size = IWL_AMSDU_8K;
1324 		break;
1325 	case IWL_AMSDU_12K:
1326 	default:
1327 		trans_cfg.rx_buf_size = IWL_AMSDU_4K;
1328 		pr_err("Unsupported amsdu_size: %d\n",
1329 		       iwlwifi_mod_params.amsdu_size);
1330 	}
1331 
1332 	trans_cfg.command_groups = iwl_dvm_groups;
1333 	trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
1334 
1335 	trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
1336 	trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
1337 					  driver_data[2]);
1338 
1339 	WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
1340 		priv->trans->trans_cfg->base_params->num_of_queues);
1341 
1342 	ucode_flags = fw->ucode_capa.flags;
1343 
1344 	if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
1345 		priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
1346 		trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1347 	} else {
1348 		priv->sta_key_max_num = STA_KEY_MAX_NUM;
1349 		trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1350 	}
1351 
1352 	/* Configure transport layer */
1353 	iwl_trans_configure(priv->trans, &trans_cfg);
1354 
1355 	trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
1356 	trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
1357 	trans->command_groups = trans_cfg.command_groups;
1358 	trans->command_groups_size = trans_cfg.command_groups_size;
1359 
1360 	/* At this point both hw and priv are allocated. */
1361 
1362 	SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
1363 
1364 	iwl_option_config(priv);
1365 
1366 	IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
1367 
1368 	/* bt channel inhibition enabled*/
1369 	priv->bt_ch_announce = true;
1370 	IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
1371 		       (priv->bt_ch_announce) ? "On" : "Off");
1372 
1373 	/* these spin locks will be used in apm_ops.init and EEPROM access
1374 	 * we should init now
1375 	 */
1376 	spin_lock_init(&priv->statistics.lock);
1377 
1378 	/***********************
1379 	 * 2. Read REV register
1380 	 ***********************/
1381 	IWL_INFO(priv, "Detected %s, REV=0x%X\n",
1382 		priv->trans->name, priv->trans->hw_rev);
1383 
1384 	if (iwl_trans_start_hw(priv->trans))
1385 		goto out_free_hw;
1386 
1387 	/* Read the EEPROM */
1388 	if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
1389 			    &priv->eeprom_blob_size)) {
1390 		IWL_ERR(priv, "Unable to init EEPROM\n");
1391 		goto out_free_hw;
1392 	}
1393 
1394 	/* Reset chip to save power until we load uCode during "up". */
1395 	iwl_trans_stop_device(priv->trans);
1396 
1397 	priv->nvm_data = iwl_parse_eeprom_data(priv->trans, priv->cfg,
1398 					       priv->eeprom_blob,
1399 					       priv->eeprom_blob_size);
1400 	if (!priv->nvm_data)
1401 		goto out_free_eeprom_blob;
1402 
1403 	if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
1404 		goto out_free_eeprom;
1405 
1406 	if (iwl_eeprom_init_hw_params(priv))
1407 		goto out_free_eeprom;
1408 
1409 	/* extract MAC Address */
1410 	memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
1411 	IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
1412 	priv->hw->wiphy->addresses = priv->addresses;
1413 	priv->hw->wiphy->n_addresses = 1;
1414 	num_mac = priv->nvm_data->n_hw_addrs;
1415 	if (num_mac > 1) {
1416 		memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
1417 		       ETH_ALEN);
1418 		priv->addresses[1].addr[5]++;
1419 		priv->hw->wiphy->n_addresses++;
1420 	}
1421 
1422 	/************************
1423 	 * 4. Setup HW constants
1424 	 ************************/
1425 	iwl_set_hw_params(priv);
1426 
1427 	if (!(priv->nvm_data->sku_cap_ipan_enable)) {
1428 		IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN\n");
1429 		ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1430 		/*
1431 		 * if not PAN, then don't support P2P -- might be a uCode
1432 		 * packaging bug or due to the eeprom check above
1433 		 */
1434 		priv->sta_key_max_num = STA_KEY_MAX_NUM;
1435 		trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1436 
1437 		/* Configure transport layer again*/
1438 		iwl_trans_configure(priv->trans, &trans_cfg);
1439 	}
1440 
1441 	/*******************
1442 	 * 5. Setup priv
1443 	 *******************/
1444 	for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
1445 		priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1446 		if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
1447 		    i != IWL_DEFAULT_CMD_QUEUE_NUM &&
1448 		    i != IWL_IPAN_CMD_QUEUE_NUM)
1449 			priv->queue_to_mac80211[i] = i;
1450 		atomic_set(&priv->queue_stop_count[i], 0);
1451 	}
1452 
1453 	if (iwl_init_drv(priv))
1454 		goto out_free_eeprom;
1455 
1456 	/* At this point both hw and priv are initialized. */
1457 
1458 	/********************
1459 	 * 6. Setup services
1460 	 ********************/
1461 	if (iwl_setup_deferred_work(priv))
1462 		goto out_uninit_drv;
1463 
1464 	iwl_setup_rx_handlers(priv);
1465 
1466 	iwl_power_initialize(priv);
1467 	iwl_tt_initialize(priv);
1468 
1469 	snprintf(priv->hw->wiphy->fw_version,
1470 		 sizeof(priv->hw->wiphy->fw_version),
1471 		 "%.31s", fw->fw_version);
1472 
1473 	priv->new_scan_threshold_behaviour =
1474 		!!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1475 
1476 	priv->phy_calib_chain_noise_reset_cmd =
1477 		fw->ucode_capa.standard_phy_calibration_size;
1478 	priv->phy_calib_chain_noise_gain_cmd =
1479 		fw->ucode_capa.standard_phy_calibration_size + 1;
1480 
1481 	/* initialize all valid contexts */
1482 	iwl_init_context(priv, ucode_flags);
1483 
1484 	/**************************************************
1485 	 * This is still part of probe() in a sense...
1486 	 *
1487 	 * 7. Setup and register with mac80211 and debugfs
1488 	 **************************************************/
1489 	if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
1490 		goto out_destroy_workqueue;
1491 
1492 	iwl_dbgfs_register(priv, dbgfs_dir);
1493 
1494 	return op_mode;
1495 
1496 out_destroy_workqueue:
1497 	iwl_tt_exit(priv);
1498 	iwl_cancel_deferred_work(priv);
1499 	destroy_workqueue(priv->workqueue);
1500 	priv->workqueue = NULL;
1501 out_uninit_drv:
1502 	iwl_uninit_drv(priv);
1503 out_free_eeprom_blob:
1504 	kfree(priv->eeprom_blob);
1505 out_free_eeprom:
1506 	kfree(priv->nvm_data);
1507 out_free_hw:
1508 	ieee80211_free_hw(priv->hw);
1509 out:
1510 	op_mode = NULL;
1511 	return op_mode;
1512 }
1513 
iwl_op_mode_dvm_stop(struct iwl_op_mode * op_mode)1514 static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
1515 {
1516 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1517 
1518 	IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
1519 
1520 	iwlagn_mac_unregister(priv);
1521 
1522 	iwl_tt_exit(priv);
1523 
1524 	kfree(priv->eeprom_blob);
1525 	kfree(priv->nvm_data);
1526 
1527 	/*netif_stop_queue(dev); */
1528 
1529 	/* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
1530 	 * priv->workqueue... so we can't take down the workqueue
1531 	 * until now... */
1532 	destroy_workqueue(priv->workqueue);
1533 	priv->workqueue = NULL;
1534 
1535 	iwl_uninit_drv(priv);
1536 
1537 	dev_kfree_skb(priv->beacon_skb);
1538 
1539 	iwl_trans_op_mode_leave(priv->trans);
1540 	ieee80211_free_hw(priv->hw);
1541 }
1542 
1543 static const char * const desc_lookup_text[] = {
1544 	"OK",
1545 	"FAIL",
1546 	"BAD_PARAM",
1547 	"BAD_CHECKSUM",
1548 	"NMI_INTERRUPT_WDG",
1549 	"SYSASSERT",
1550 	"FATAL_ERROR",
1551 	"BAD_COMMAND",
1552 	"HW_ERROR_TUNE_LOCK",
1553 	"HW_ERROR_TEMPERATURE",
1554 	"ILLEGAL_CHAN_FREQ",
1555 	"VCC_NOT_STABLE",
1556 	"FH_ERROR",
1557 	"NMI_INTERRUPT_HOST",
1558 	"NMI_INTERRUPT_ACTION_PT",
1559 	"NMI_INTERRUPT_UNKNOWN",
1560 	"UCODE_VERSION_MISMATCH",
1561 	"HW_ERROR_ABS_LOCK",
1562 	"HW_ERROR_CAL_LOCK_FAIL",
1563 	"NMI_INTERRUPT_INST_ACTION_PT",
1564 	"NMI_INTERRUPT_DATA_ACTION_PT",
1565 	"NMI_TRM_HW_ER",
1566 	"NMI_INTERRUPT_TRM",
1567 	"NMI_INTERRUPT_BREAK_POINT",
1568 	"DEBUG_0",
1569 	"DEBUG_1",
1570 	"DEBUG_2",
1571 	"DEBUG_3",
1572 };
1573 
1574 static struct { char *name; u8 num; } advanced_lookup[] = {
1575 	{ "NMI_INTERRUPT_WDG", 0x34 },
1576 	{ "SYSASSERT", 0x35 },
1577 	{ "UCODE_VERSION_MISMATCH", 0x37 },
1578 	{ "BAD_COMMAND", 0x38 },
1579 	{ "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1580 	{ "FATAL_ERROR", 0x3D },
1581 	{ "NMI_TRM_HW_ERR", 0x46 },
1582 	{ "NMI_INTERRUPT_TRM", 0x4C },
1583 	{ "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1584 	{ "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1585 	{ "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1586 	{ "NMI_INTERRUPT_HOST", 0x66 },
1587 	{ "NMI_INTERRUPT_ACTION_PT", 0x7C },
1588 	{ "NMI_INTERRUPT_UNKNOWN", 0x84 },
1589 	{ "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1590 	{ "ADVANCED_SYSASSERT", 0 },
1591 };
1592 
desc_lookup(u32 num)1593 static const char *desc_lookup(u32 num)
1594 {
1595 	int i;
1596 	int max = ARRAY_SIZE(desc_lookup_text);
1597 
1598 	if (num < max)
1599 		return desc_lookup_text[num];
1600 
1601 	max = ARRAY_SIZE(advanced_lookup) - 1;
1602 	for (i = 0; i < max; i++) {
1603 		if (advanced_lookup[i].num == num)
1604 			break;
1605 	}
1606 	return advanced_lookup[i].name;
1607 }
1608 
1609 #define ERROR_START_OFFSET  (1 * sizeof(u32))
1610 #define ERROR_ELEM_SIZE     (7 * sizeof(u32))
1611 
iwl_dump_nic_error_log(struct iwl_priv * priv)1612 static void iwl_dump_nic_error_log(struct iwl_priv *priv)
1613 {
1614 	struct iwl_trans *trans = priv->trans;
1615 	u32 base;
1616 	struct iwl_error_event_table table;
1617 
1618 	base = priv->device_pointers.error_event_table;
1619 	if (priv->cur_ucode == IWL_UCODE_INIT) {
1620 		if (!base)
1621 			base = priv->fw->init_errlog_ptr;
1622 	} else {
1623 		if (!base)
1624 			base = priv->fw->inst_errlog_ptr;
1625 	}
1626 
1627 	if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1628 		IWL_ERR(priv,
1629 			"Not valid error log pointer 0x%08X for %s uCode\n",
1630 			base,
1631 			(priv->cur_ucode == IWL_UCODE_INIT)
1632 					? "Init" : "RT");
1633 		return;
1634 	}
1635 
1636 	/*TODO: Update dbgfs with ISR error stats obtained below */
1637 	iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
1638 
1639 	if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
1640 		IWL_ERR(trans, "Start IWL Error Log Dump:\n");
1641 		IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
1642 			priv->status, table.valid);
1643 	}
1644 
1645 	IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
1646 		desc_lookup(table.error_id));
1647 	IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
1648 	IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
1649 	IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
1650 	IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
1651 	IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
1652 	IWL_ERR(priv, "0x%08X | data1\n", table.data1);
1653 	IWL_ERR(priv, "0x%08X | data2\n", table.data2);
1654 	IWL_ERR(priv, "0x%08X | line\n", table.line);
1655 	IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
1656 	IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
1657 	IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
1658 	IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
1659 	IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
1660 	IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
1661 	IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
1662 	IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
1663 	IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
1664 	IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
1665 	IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
1666 	IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
1667 	IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
1668 	IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
1669 	IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
1670 	IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
1671 	IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
1672 	IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
1673 	IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
1674 	IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
1675 	IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
1676 	IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
1677 	IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
1678 	IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
1679 }
1680 
1681 #define EVENT_START_OFFSET  (4 * sizeof(u32))
1682 
1683 /*
1684  * iwl_print_event_log - Dump error event log to syslog
1685  */
iwl_print_event_log(struct iwl_priv * priv,u32 start_idx,u32 num_events,u32 mode,int pos,char ** buf,size_t bufsz)1686 static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1687 			       u32 num_events, u32 mode,
1688 			       int pos, char **buf, size_t bufsz)
1689 {
1690 	u32 i;
1691 	u32 base;       /* SRAM byte address of event log header */
1692 	u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1693 	u32 ptr;        /* SRAM byte address of log data */
1694 	u32 ev, time, data; /* event log data */
1695 
1696 	struct iwl_trans *trans = priv->trans;
1697 
1698 	if (num_events == 0)
1699 		return pos;
1700 
1701 	base = priv->device_pointers.log_event_table;
1702 	if (priv->cur_ucode == IWL_UCODE_INIT) {
1703 		if (!base)
1704 			base = priv->fw->init_evtlog_ptr;
1705 	} else {
1706 		if (!base)
1707 			base = priv->fw->inst_evtlog_ptr;
1708 	}
1709 
1710 	if (mode == 0)
1711 		event_size = 2 * sizeof(u32);
1712 	else
1713 		event_size = 3 * sizeof(u32);
1714 
1715 	ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1716 
1717 	/* Make sure device is powered up for SRAM reads */
1718 	if (!iwl_trans_grab_nic_access(trans))
1719 		return pos;
1720 
1721 	/* Set starting address; reads will auto-increment */
1722 	iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
1723 
1724 	/* "time" is actually "data" for mode 0 (no timestamp).
1725 	* place event id # at far right for easier visual parsing. */
1726 	for (i = 0; i < num_events; i++) {
1727 		ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1728 		time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1729 		if (mode == 0) {
1730 			/* data, ev */
1731 			if (bufsz) {
1732 				pos += scnprintf(*buf + pos, bufsz - pos,
1733 						"EVT_LOG:0x%08x:%04u\n",
1734 						time, ev);
1735 			} else {
1736 				trace_iwlwifi_dev_ucode_event(trans->dev, 0,
1737 					time, ev);
1738 				IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1739 					time, ev);
1740 			}
1741 		} else {
1742 			data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1743 			if (bufsz) {
1744 				pos += scnprintf(*buf + pos, bufsz - pos,
1745 						"EVT_LOGT:%010u:0x%08x:%04u\n",
1746 						 time, data, ev);
1747 			} else {
1748 				IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1749 					time, data, ev);
1750 				trace_iwlwifi_dev_ucode_event(trans->dev, time,
1751 					data, ev);
1752 			}
1753 		}
1754 	}
1755 
1756 	/* Allow device to power down */
1757 	iwl_trans_release_nic_access(trans);
1758 	return pos;
1759 }
1760 
1761 /*
1762  * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1763  */
iwl_print_last_event_logs(struct iwl_priv * priv,u32 capacity,u32 num_wraps,u32 next_entry,u32 size,u32 mode,int pos,char ** buf,size_t bufsz)1764 static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1765 				    u32 num_wraps, u32 next_entry,
1766 				    u32 size, u32 mode,
1767 				    int pos, char **buf, size_t bufsz)
1768 {
1769 	/*
1770 	 * display the newest DEFAULT_LOG_ENTRIES entries
1771 	 * i.e the entries just before the next ont that uCode would fill.
1772 	 */
1773 	if (num_wraps) {
1774 		if (next_entry < size) {
1775 			pos = iwl_print_event_log(priv,
1776 						capacity - (size - next_entry),
1777 						size - next_entry, mode,
1778 						pos, buf, bufsz);
1779 			pos = iwl_print_event_log(priv, 0,
1780 						  next_entry, mode,
1781 						  pos, buf, bufsz);
1782 		} else
1783 			pos = iwl_print_event_log(priv, next_entry - size,
1784 						  size, mode, pos, buf, bufsz);
1785 	} else {
1786 		if (next_entry < size) {
1787 			pos = iwl_print_event_log(priv, 0, next_entry,
1788 						  mode, pos, buf, bufsz);
1789 		} else {
1790 			pos = iwl_print_event_log(priv, next_entry - size,
1791 						  size, mode, pos, buf, bufsz);
1792 		}
1793 	}
1794 	return pos;
1795 }
1796 
1797 #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1798 
iwl_dump_nic_event_log(struct iwl_priv * priv,bool full_log,char ** buf)1799 int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1800 			    char **buf)
1801 {
1802 	u32 base;       /* SRAM byte address of event log header */
1803 	u32 capacity;   /* event log capacity in # entries */
1804 	u32 mode;       /* 0 - no timestamp, 1 - timestamp recorded */
1805 	u32 num_wraps;  /* # times uCode wrapped to top of log */
1806 	u32 next_entry; /* index of next entry to be written by uCode */
1807 	u32 size;       /* # entries that we'll print */
1808 	u32 logsize;
1809 	int pos = 0;
1810 	size_t bufsz = 0;
1811 	struct iwl_trans *trans = priv->trans;
1812 
1813 	base = priv->device_pointers.log_event_table;
1814 	if (priv->cur_ucode == IWL_UCODE_INIT) {
1815 		logsize = priv->fw->init_evtlog_size;
1816 		if (!base)
1817 			base = priv->fw->init_evtlog_ptr;
1818 	} else {
1819 		logsize = priv->fw->inst_evtlog_size;
1820 		if (!base)
1821 			base = priv->fw->inst_evtlog_ptr;
1822 	}
1823 
1824 	if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1825 		IWL_ERR(priv,
1826 			"Invalid event log pointer 0x%08X for %s uCode\n",
1827 			base,
1828 			(priv->cur_ucode == IWL_UCODE_INIT)
1829 					? "Init" : "RT");
1830 		return -EINVAL;
1831 	}
1832 
1833 	/* event log header */
1834 	capacity = iwl_trans_read_mem32(trans, base);
1835 	mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32)));
1836 	num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32)));
1837 	next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32)));
1838 
1839 	if (capacity > logsize) {
1840 		IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
1841 			"entries\n", capacity, logsize);
1842 		capacity = logsize;
1843 	}
1844 
1845 	if (next_entry > logsize) {
1846 		IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
1847 			next_entry, logsize);
1848 		next_entry = logsize;
1849 	}
1850 
1851 	size = num_wraps ? capacity : next_entry;
1852 
1853 	/* bail out if nothing in log */
1854 	if (size == 0) {
1855 		IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
1856 		return pos;
1857 	}
1858 
1859 	if (!(iwl_have_debug_level(IWL_DL_FW)) && !full_log)
1860 		size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1861 			? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1862 	IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1863 		size);
1864 
1865 #ifdef CONFIG_IWLWIFI_DEBUG
1866 	if (buf) {
1867 		if (full_log)
1868 			bufsz = capacity * 48;
1869 		else
1870 			bufsz = size * 48;
1871 		*buf = kmalloc(bufsz, GFP_KERNEL);
1872 		if (!*buf)
1873 			return -ENOMEM;
1874 	}
1875 	if (iwl_have_debug_level(IWL_DL_FW) || full_log) {
1876 		/*
1877 		 * if uCode has wrapped back to top of log,
1878 		 * start at the oldest entry,
1879 		 * i.e the next one that uCode would fill.
1880 		 */
1881 		if (num_wraps)
1882 			pos = iwl_print_event_log(priv, next_entry,
1883 						capacity - next_entry, mode,
1884 						pos, buf, bufsz);
1885 		/* (then/else) start at top of log */
1886 		pos = iwl_print_event_log(priv, 0,
1887 					  next_entry, mode, pos, buf, bufsz);
1888 	} else
1889 		pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1890 						next_entry, size, mode,
1891 						pos, buf, bufsz);
1892 #else
1893 	pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1894 					next_entry, size, mode,
1895 					pos, buf, bufsz);
1896 #endif
1897 	return pos;
1898 }
1899 
iwlagn_fw_error(struct iwl_priv * priv,bool ondemand)1900 static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
1901 {
1902 	unsigned int reload_msec;
1903 	unsigned long reload_jiffies;
1904 
1905 	if (iwl_have_debug_level(IWL_DL_FW))
1906 		iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
1907 
1908 	/* uCode is no longer loaded. */
1909 	priv->ucode_loaded = false;
1910 
1911 	/* Set the FW error flag -- cleared on iwl_down */
1912 	set_bit(STATUS_FW_ERROR, &priv->status);
1913 
1914 	iwl_abort_notification_waits(&priv->notif_wait);
1915 
1916 	/* Keep the restart process from trying to send host
1917 	 * commands by clearing the ready bit */
1918 	clear_bit(STATUS_READY, &priv->status);
1919 
1920 	if (!ondemand) {
1921 		/*
1922 		 * If firmware keep reloading, then it indicate something
1923 		 * serious wrong and firmware having problem to recover
1924 		 * from it. Instead of keep trying which will fill the syslog
1925 		 * and hang the system, let's just stop it
1926 		 */
1927 		reload_jiffies = jiffies;
1928 		reload_msec = jiffies_to_msecs((long) reload_jiffies -
1929 					(long) priv->reload_jiffies);
1930 		priv->reload_jiffies = reload_jiffies;
1931 		if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
1932 			priv->reload_count++;
1933 			if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
1934 				IWL_ERR(priv, "BUG_ON, Stop restarting\n");
1935 				return;
1936 			}
1937 		} else
1938 			priv->reload_count = 0;
1939 	}
1940 
1941 	if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1942 		if (iwlwifi_mod_params.fw_restart) {
1943 			IWL_DEBUG_FW(priv,
1944 				     "Restarting adapter due to uCode error.\n");
1945 			queue_work(priv->workqueue, &priv->restart);
1946 		} else
1947 			IWL_DEBUG_FW(priv,
1948 				     "Detected FW error, but not restarting\n");
1949 	}
1950 }
1951 
iwl_nic_error(struct iwl_op_mode * op_mode,bool sync)1952 static void iwl_nic_error(struct iwl_op_mode *op_mode, bool sync)
1953 {
1954 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1955 
1956 	IWL_ERR(priv, "Loaded firmware version: %s\n",
1957 		priv->fw->fw_version);
1958 
1959 	iwl_dump_nic_error_log(priv);
1960 	iwl_dump_nic_event_log(priv, false, NULL);
1961 
1962 	iwlagn_fw_error(priv, false);
1963 }
1964 
iwl_cmd_queue_full(struct iwl_op_mode * op_mode)1965 static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
1966 {
1967 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1968 
1969 	if (!iwl_check_for_ct_kill(priv)) {
1970 		IWL_ERR(priv, "Restarting adapter queue is full\n");
1971 		iwlagn_fw_error(priv, false);
1972 	}
1973 }
1974 
1975 #define EEPROM_RF_CONFIG_TYPE_MAX      0x3
1976 
iwl_nic_config(struct iwl_op_mode * op_mode)1977 static void iwl_nic_config(struct iwl_op_mode *op_mode)
1978 {
1979 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1980 
1981 	/* SKU Control */
1982 	iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
1983 				CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP_DASH,
1984 				CSR_HW_REV_STEP_DASH(priv->trans->hw_rev));
1985 
1986 	/* write radio config values to register */
1987 	if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
1988 		u32 reg_val =
1989 			priv->nvm_data->radio_cfg_type <<
1990 				CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
1991 			priv->nvm_data->radio_cfg_step <<
1992 				CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
1993 			priv->nvm_data->radio_cfg_dash <<
1994 				CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
1995 
1996 		iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
1997 					CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
1998 					CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
1999 					CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH,
2000 					reg_val);
2001 
2002 		IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
2003 			 priv->nvm_data->radio_cfg_type,
2004 			 priv->nvm_data->radio_cfg_step,
2005 			 priv->nvm_data->radio_cfg_dash);
2006 	} else {
2007 		WARN_ON(1);
2008 	}
2009 
2010 	/* set CSR_HW_CONFIG_REG for uCode use */
2011 	iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
2012 		    CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
2013 		    CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
2014 
2015 	/* W/A : NIC is stuck in a reset state after Early PCIe power off
2016 	 * (PCIe power is lost before PERST# is asserted),
2017 	 * causing ME FW to lose ownership and not being able to obtain it back.
2018 	 */
2019 	iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
2020 			       APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
2021 			       ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
2022 
2023 	if (priv->lib->nic_config)
2024 		priv->lib->nic_config(priv);
2025 }
2026 
iwl_wimax_active(struct iwl_op_mode * op_mode)2027 static void iwl_wimax_active(struct iwl_op_mode *op_mode)
2028 {
2029 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2030 
2031 	clear_bit(STATUS_READY, &priv->status);
2032 	IWL_ERR(priv, "RF is used by WiMAX\n");
2033 }
2034 
iwl_stop_sw_queue(struct iwl_op_mode * op_mode,int queue)2035 static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
2036 {
2037 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2038 	int mq = priv->queue_to_mac80211[queue];
2039 
2040 	if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
2041 		return;
2042 
2043 	if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
2044 		IWL_DEBUG_TX_QUEUES(priv,
2045 			"queue %d (mac80211 %d) already stopped\n",
2046 			queue, mq);
2047 		return;
2048 	}
2049 
2050 	set_bit(mq, &priv->transport_queue_stop);
2051 	ieee80211_stop_queue(priv->hw, mq);
2052 }
2053 
iwl_wake_sw_queue(struct iwl_op_mode * op_mode,int queue)2054 static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
2055 {
2056 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2057 	int mq = priv->queue_to_mac80211[queue];
2058 
2059 	if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
2060 		return;
2061 
2062 	if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
2063 		IWL_DEBUG_TX_QUEUES(priv,
2064 			"queue %d (mac80211 %d) already awake\n",
2065 			queue, mq);
2066 		return;
2067 	}
2068 
2069 	clear_bit(mq, &priv->transport_queue_stop);
2070 
2071 	if (!priv->passive_no_rx)
2072 		ieee80211_wake_queue(priv->hw, mq);
2073 }
2074 
iwlagn_lift_passive_no_rx(struct iwl_priv * priv)2075 void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
2076 {
2077 	int mq;
2078 
2079 	if (!priv->passive_no_rx)
2080 		return;
2081 
2082 	for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
2083 		if (!test_bit(mq, &priv->transport_queue_stop)) {
2084 			IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d\n", mq);
2085 			ieee80211_wake_queue(priv->hw, mq);
2086 		} else {
2087 			IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d\n", mq);
2088 		}
2089 	}
2090 
2091 	priv->passive_no_rx = false;
2092 }
2093 
iwl_free_skb(struct iwl_op_mode * op_mode,struct sk_buff * skb)2094 static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
2095 {
2096 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2097 	struct ieee80211_tx_info *info;
2098 
2099 	info = IEEE80211_SKB_CB(skb);
2100 	iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
2101 	ieee80211_free_txskb(priv->hw, skb);
2102 }
2103 
iwl_set_hw_rfkill_state(struct iwl_op_mode * op_mode,bool state)2104 static bool iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
2105 {
2106 	struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2107 
2108 	if (state)
2109 		set_bit(STATUS_RF_KILL_HW, &priv->status);
2110 	else
2111 		clear_bit(STATUS_RF_KILL_HW, &priv->status);
2112 
2113 	wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
2114 
2115 	return false;
2116 }
2117 
2118 static const struct iwl_op_mode_ops iwl_dvm_ops = {
2119 	.start = iwl_op_mode_dvm_start,
2120 	.stop = iwl_op_mode_dvm_stop,
2121 	.rx = iwl_rx_dispatch,
2122 	.queue_full = iwl_stop_sw_queue,
2123 	.queue_not_full = iwl_wake_sw_queue,
2124 	.hw_rf_kill = iwl_set_hw_rfkill_state,
2125 	.free_skb = iwl_free_skb,
2126 	.nic_error = iwl_nic_error,
2127 	.cmd_queue_full = iwl_cmd_queue_full,
2128 	.nic_config = iwl_nic_config,
2129 	.wimax_active = iwl_wimax_active,
2130 };
2131 
2132 /*****************************************************************************
2133  *
2134  * driver and module entry point
2135  *
2136  *****************************************************************************/
iwl_init(void)2137 static int __init iwl_init(void)
2138 {
2139 
2140 	int ret;
2141 
2142 	ret = iwlagn_rate_control_register();
2143 	if (ret) {
2144 		pr_err("Unable to register rate control algorithm: %d\n", ret);
2145 		return ret;
2146 	}
2147 
2148 	ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
2149 	if (ret) {
2150 		pr_err("Unable to register op_mode: %d\n", ret);
2151 		iwlagn_rate_control_unregister();
2152 	}
2153 
2154 	return ret;
2155 }
2156 module_init(iwl_init);
2157 
iwl_exit(void)2158 static void __exit iwl_exit(void)
2159 {
2160 	iwl_opmode_deregister("iwldvm");
2161 	iwlagn_rate_control_unregister();
2162 }
2163 module_exit(iwl_exit);
2164