1 /******************************************************************************
5 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
29 #include <linux/etherdevice.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/sched.h>
38 #include "iwl-agn-hw.h"
40 #include "iwl-trans.h"
41 #include "iwl-shared.h"
43 int iwlagn_hw_valid_rtc_data_addr(u32 addr
)
45 return (addr
>= IWLAGN_RTC_DATA_LOWER_BOUND
) &&
46 (addr
< IWLAGN_RTC_DATA_UPPER_BOUND
);
49 int iwlagn_send_tx_power(struct iwl_priv
*priv
)
51 struct iwlagn_tx_power_dbm_cmd tx_power_cmd
;
54 if (WARN_ONCE(test_bit(STATUS_SCAN_HW
, &priv
->status
),
55 "TX Power requested while scanning!\n"))
58 /* half dBm need to multiply */
59 tx_power_cmd
.global_lmt
= (s8
)(2 * priv
->tx_power_user_lmt
);
61 if (priv
->tx_power_lmt_in_half_dbm
&&
62 priv
->tx_power_lmt_in_half_dbm
< tx_power_cmd
.global_lmt
) {
64 * For the newer devices which using enhanced/extend tx power
65 * table in EEPROM, the format is in half dBm. driver need to
66 * convert to dBm format before report to mac80211.
67 * By doing so, there is a possibility of 1/2 dBm resolution
68 * lost. driver will perform "round-up" operation before
69 * reporting, but it will cause 1/2 dBm tx power over the
70 * regulatory limit. Perform the checking here, if the
71 * "tx_power_user_lmt" is higher than EEPROM value (in
72 * half-dBm format), lower the tx power based on EEPROM
74 tx_power_cmd
.global_lmt
= priv
->tx_power_lmt_in_half_dbm
;
76 tx_power_cmd
.flags
= IWLAGN_TX_POWER_NO_CLOSED
;
77 tx_power_cmd
.srv_chan_lmt
= IWLAGN_TX_POWER_AUTO
;
79 if (IWL_UCODE_API(priv
->fw
->ucode_ver
) == 1)
80 tx_ant_cfg_cmd
= REPLY_TX_POWER_DBM_CMD_V1
;
82 tx_ant_cfg_cmd
= REPLY_TX_POWER_DBM_CMD
;
84 return iwl_dvm_send_cmd_pdu(priv
, tx_ant_cfg_cmd
, CMD_SYNC
,
85 sizeof(tx_power_cmd
), &tx_power_cmd
);
88 void iwlagn_temperature(struct iwl_priv
*priv
)
90 lockdep_assert_held(&priv
->statistics
.lock
);
92 /* store temperature from correct statistics (in Celsius) */
93 priv
->temperature
= le32_to_cpu(priv
->statistics
.common
.temperature
);
97 struct iwl_mod_params iwlagn_mod_params
= {
101 .bt_coex_active
= true,
102 .power_level
= IWL_POWER_INDEX_1
,
103 .bt_ch_announce
= true,
104 .wanted_ucode_alternative
= 1,
106 /* the rest are 0 by default */
109 int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags
, enum ieee80211_band band
)
114 /* HT rate format: mac80211 wants an MCS number, which is just LSB */
115 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
116 idx
= (rate_n_flags
& 0xff);
118 /* Legacy rate format, search for match in table */
120 if (band
== IEEE80211_BAND_5GHZ
)
121 band_offset
= IWL_FIRST_OFDM_RATE
;
122 for (idx
= band_offset
; idx
< IWL_RATE_COUNT_LEGACY
; idx
++)
123 if (iwl_rates
[idx
].plcp
== (rate_n_flags
& 0xFF))
124 return idx
- band_offset
;
130 int iwlagn_manage_ibss_station(struct iwl_priv
*priv
,
131 struct ieee80211_vif
*vif
, bool add
)
133 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
136 return iwlagn_add_bssid_station(priv
, vif_priv
->ctx
,
138 &vif_priv
->ibss_bssid_sta_id
);
139 return iwl_remove_station(priv
, vif_priv
->ibss_bssid_sta_id
,
140 vif
->bss_conf
.bssid
);
144 * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode
147 * 1. acquire mutex before calling
148 * 2. make sure rf is on and not in exit state
150 int iwlagn_txfifo_flush(struct iwl_priv
*priv
, u16 flush_control
)
152 struct iwl_txfifo_flush_cmd flush_cmd
;
153 struct iwl_host_cmd cmd
= {
154 .id
= REPLY_TXFIFO_FLUSH
,
155 .len
= { sizeof(struct iwl_txfifo_flush_cmd
), },
157 .data
= { &flush_cmd
, },
162 memset(&flush_cmd
, 0, sizeof(flush_cmd
));
163 if (flush_control
& BIT(IWL_RXON_CTX_BSS
))
164 flush_cmd
.fifo_control
= IWL_SCD_VO_MSK
| IWL_SCD_VI_MSK
|
165 IWL_SCD_BE_MSK
| IWL_SCD_BK_MSK
|
167 if ((flush_control
& BIT(IWL_RXON_CTX_PAN
)) &&
168 (priv
->valid_contexts
!= BIT(IWL_RXON_CTX_BSS
)))
169 flush_cmd
.fifo_control
|= IWL_PAN_SCD_VO_MSK
|
170 IWL_PAN_SCD_VI_MSK
| IWL_PAN_SCD_BE_MSK
|
171 IWL_PAN_SCD_BK_MSK
| IWL_PAN_SCD_MGMT_MSK
|
172 IWL_PAN_SCD_MULTICAST_MSK
;
174 if (priv
->hw_params
.sku
& EEPROM_SKU_CAP_11N_ENABLE
)
175 flush_cmd
.fifo_control
|= IWL_AGG_TX_QUEUE_MSK
;
177 IWL_DEBUG_INFO(priv
, "fifo queue control: 0X%x\n",
178 flush_cmd
.fifo_control
);
179 flush_cmd
.flush_control
= cpu_to_le16(flush_control
);
181 return iwl_dvm_send_cmd(priv
, &cmd
);
184 void iwlagn_dev_txfifo_flush(struct iwl_priv
*priv
, u16 flush_control
)
186 mutex_lock(&priv
->mutex
);
187 ieee80211_stop_queues(priv
->hw
);
188 if (iwlagn_txfifo_flush(priv
, IWL_DROP_ALL
)) {
189 IWL_ERR(priv
, "flush request fail\n");
192 IWL_DEBUG_INFO(priv
, "wait transmit/flush all frames\n");
193 iwl_trans_wait_tx_queue_empty(trans(priv
));
195 ieee80211_wake_queues(priv
->hw
);
196 mutex_unlock(&priv
->mutex
);
203 * Macros to access the lookup table.
205 * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req,
206 * wifi_prio, wifi_txrx and wifi_sh_ant_req.
208 * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH
210 * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits
211 * one after another in 32-bit registers, and "registers" 0 through 7 contain
212 * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order).
214 * These macros encode that format.
216 #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \
217 wifi_txrx, wifi_sh_ant_req) \
218 (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \
219 (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6))
221 #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \
222 lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f)))
223 #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
224 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
225 (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \
226 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
228 #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
229 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
230 LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \
231 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
233 #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \
234 wifi_req, wifi_prio, wifi_txrx, \
236 LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \
237 bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \
240 #define LUT_WLAN_KILL_OP(lut, op, val) \
241 lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e)))
242 #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
243 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
244 (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
245 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))))
246 #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
247 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
248 LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
249 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
250 #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
251 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
252 LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
253 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
255 #define LUT_ANT_SWITCH_OP(lut, op, val) \
256 lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1)))
257 #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
258 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
259 (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
260 wifi_req, wifi_prio, wifi_txrx, \
262 #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
263 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
264 LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
265 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
266 #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \
267 wifi_prio, wifi_txrx, wifi_sh_ant_req) \
268 LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \
269 wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req))
271 static const __le32 iwlagn_def_3w_lookup
[12] = {
272 cpu_to_le32(0xaaaaaaaa),
273 cpu_to_le32(0xaaaaaaaa),
274 cpu_to_le32(0xaeaaaaaa),
275 cpu_to_le32(0xaaaaaaaa),
276 cpu_to_le32(0xcc00ff28),
277 cpu_to_le32(0x0000aaaa),
278 cpu_to_le32(0xcc00aaaa),
279 cpu_to_le32(0x0000aaaa),
280 cpu_to_le32(0xc0004000),
281 cpu_to_le32(0x00004000),
282 cpu_to_le32(0xf0005000),
283 cpu_to_le32(0xf0005000),
286 static const __le32 iwlagn_concurrent_lookup
[12] = {
287 cpu_to_le32(0xaaaaaaaa),
288 cpu_to_le32(0xaaaaaaaa),
289 cpu_to_le32(0xaaaaaaaa),
290 cpu_to_le32(0xaaaaaaaa),
291 cpu_to_le32(0xaaaaaaaa),
292 cpu_to_le32(0xaaaaaaaa),
293 cpu_to_le32(0xaaaaaaaa),
294 cpu_to_le32(0xaaaaaaaa),
295 cpu_to_le32(0x00000000),
296 cpu_to_le32(0x00000000),
297 cpu_to_le32(0x00000000),
298 cpu_to_le32(0x00000000),
301 void iwlagn_send_advance_bt_config(struct iwl_priv
*priv
)
303 struct iwl_basic_bt_cmd basic
= {
304 .max_kill
= IWLAGN_BT_MAX_KILL_DEFAULT
,
305 .bt3_timer_t7_value
= IWLAGN_BT3_T7_DEFAULT
,
306 .bt3_prio_sample_time
= IWLAGN_BT3_PRIO_SAMPLE_DEFAULT
,
307 .bt3_timer_t2_value
= IWLAGN_BT3_T2_DEFAULT
,
309 struct iwl_bt_cmd_v1 bt_cmd_v1
;
310 struct iwl_bt_cmd_v2 bt_cmd_v2
;
313 BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup
) !=
314 sizeof(basic
.bt3_lookup_table
));
316 if (cfg(priv
)->bt_params
) {
318 * newer generation of devices (2000 series and newer)
319 * use the version 2 of the bt command
320 * we need to make sure sending the host command
321 * with correct data structure to avoid uCode assert
323 if (cfg(priv
)->bt_params
->bt_session_2
) {
324 bt_cmd_v2
.prio_boost
= cpu_to_le32(
325 cfg(priv
)->bt_params
->bt_prio_boost
);
326 bt_cmd_v2
.tx_prio_boost
= 0;
327 bt_cmd_v2
.rx_prio_boost
= 0;
329 bt_cmd_v1
.prio_boost
=
330 cfg(priv
)->bt_params
->bt_prio_boost
;
331 bt_cmd_v1
.tx_prio_boost
= 0;
332 bt_cmd_v1
.rx_prio_boost
= 0;
335 IWL_ERR(priv
, "failed to construct BT Coex Config\n");
339 basic
.kill_ack_mask
= priv
->kill_ack_mask
;
340 basic
.kill_cts_mask
= priv
->kill_cts_mask
;
341 basic
.valid
= priv
->bt_valid
;
344 * Configure BT coex mode to "no coexistence" when the
345 * user disabled BT coexistence, we have no interface
346 * (might be in monitor mode), or the interface is in
347 * IBSS mode (no proper uCode support for coex then).
349 if (!iwlagn_mod_params
.bt_coex_active
||
350 priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) {
351 basic
.flags
= IWLAGN_BT_FLAG_COEX_MODE_DISABLED
;
353 basic
.flags
= IWLAGN_BT_FLAG_COEX_MODE_3W
<<
354 IWLAGN_BT_FLAG_COEX_MODE_SHIFT
;
356 if (!priv
->bt_enable_pspoll
)
357 basic
.flags
|= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE
;
359 basic
.flags
&= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE
;
361 if (priv
->bt_ch_announce
)
362 basic
.flags
|= IWLAGN_BT_FLAG_CHANNEL_INHIBITION
;
363 IWL_DEBUG_COEX(priv
, "BT coex flag: 0X%x\n", basic
.flags
);
365 priv
->bt_enable_flag
= basic
.flags
;
366 if (priv
->bt_full_concurrent
)
367 memcpy(basic
.bt3_lookup_table
, iwlagn_concurrent_lookup
,
368 sizeof(iwlagn_concurrent_lookup
));
370 memcpy(basic
.bt3_lookup_table
, iwlagn_def_3w_lookup
,
371 sizeof(iwlagn_def_3w_lookup
));
373 IWL_DEBUG_COEX(priv
, "BT coex %s in %s mode\n",
374 basic
.flags
? "active" : "disabled",
375 priv
->bt_full_concurrent
?
376 "full concurrency" : "3-wire");
378 if (cfg(priv
)->bt_params
->bt_session_2
) {
379 memcpy(&bt_cmd_v2
.basic
, &basic
,
381 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
382 CMD_SYNC
, sizeof(bt_cmd_v2
), &bt_cmd_v2
);
384 memcpy(&bt_cmd_v1
.basic
, &basic
,
386 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
387 CMD_SYNC
, sizeof(bt_cmd_v1
), &bt_cmd_v1
);
390 IWL_ERR(priv
, "failed to send BT Coex Config\n");
394 void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv
*priv
, bool rssi_ena
)
396 struct iwl_rxon_context
*ctx
, *found_ctx
= NULL
;
397 bool found_ap
= false;
399 lockdep_assert_held(&priv
->mutex
);
401 /* Check whether AP or GO mode is active. */
403 for_each_context(priv
, ctx
) {
404 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_AP
&&
405 iwl_is_associated_ctx(ctx
)) {
413 * If disable was received or If GO/AP mode, disable RSSI
416 if (!rssi_ena
|| found_ap
) {
417 if (priv
->cur_rssi_ctx
) {
418 ctx
= priv
->cur_rssi_ctx
;
419 ieee80211_disable_rssi_reports(ctx
->vif
);
420 priv
->cur_rssi_ctx
= NULL
;
426 * If rssi measurements need to be enabled, consider all cases now.
427 * Figure out how many contexts are active.
429 for_each_context(priv
, ctx
) {
430 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_STATION
&&
431 iwl_is_associated_ctx(ctx
)) {
438 * rssi monitor already enabled for the correct interface...nothing
441 if (found_ctx
== priv
->cur_rssi_ctx
)
445 * Figure out if rssi monitor is currently enabled, and needs
446 * to be changed. If rssi monitor is already enabled, disable
447 * it first else just enable rssi measurements on the
448 * interface found above.
450 if (priv
->cur_rssi_ctx
) {
451 ctx
= priv
->cur_rssi_ctx
;
453 ieee80211_disable_rssi_reports(ctx
->vif
);
456 priv
->cur_rssi_ctx
= found_ctx
;
461 ieee80211_enable_rssi_reports(found_ctx
->vif
,
462 IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD
,
463 IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD
);
466 static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg
*uart_msg
)
468 return BT_UART_MSG_FRAME3SCOESCO_MSK
& uart_msg
->frame3
>>
469 BT_UART_MSG_FRAME3SCOESCO_POS
;
472 static void iwlagn_bt_traffic_change_work(struct work_struct
*work
)
474 struct iwl_priv
*priv
=
475 container_of(work
, struct iwl_priv
, bt_traffic_change_work
);
476 struct iwl_rxon_context
*ctx
;
477 int smps_request
= -1;
479 if (priv
->bt_enable_flag
== IWLAGN_BT_FLAG_COEX_MODE_DISABLED
) {
480 /* bt coex disabled */
485 * Note: bt_traffic_load can be overridden by scan complete and
486 * coex profile notifications. Ignore that since only bad consequence
487 * can be not matching debug print with actual state.
489 IWL_DEBUG_COEX(priv
, "BT traffic load changes: %d\n",
490 priv
->bt_traffic_load
);
492 switch (priv
->bt_traffic_load
) {
493 case IWL_BT_COEX_TRAFFIC_LOAD_NONE
:
495 smps_request
= IEEE80211_SMPS_DYNAMIC
;
497 smps_request
= IEEE80211_SMPS_AUTOMATIC
;
499 case IWL_BT_COEX_TRAFFIC_LOAD_LOW
:
500 smps_request
= IEEE80211_SMPS_DYNAMIC
;
502 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH
:
503 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS
:
504 smps_request
= IEEE80211_SMPS_STATIC
;
507 IWL_ERR(priv
, "Invalid BT traffic load: %d\n",
508 priv
->bt_traffic_load
);
512 mutex_lock(&priv
->mutex
);
515 * We can not send command to firmware while scanning. When the scan
516 * complete we will schedule this work again. We do check with mutex
517 * locked to prevent new scan request to arrive. We do not check
518 * STATUS_SCANNING to avoid race when queue_work two times from
519 * different notifications, but quit and not perform any work at all.
521 if (test_bit(STATUS_SCAN_HW
, &priv
->status
))
524 iwl_update_chain_flags(priv
);
526 if (smps_request
!= -1) {
527 priv
->current_ht_config
.smps
= smps_request
;
528 for_each_context(priv
, ctx
) {
529 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_STATION
)
530 ieee80211_request_smps(ctx
->vif
, smps_request
);
535 * Dynamic PS poll related functionality. Adjust RSSI measurements if
538 iwlagn_bt_coex_rssi_monitor(priv
);
540 mutex_unlock(&priv
->mutex
);
544 * If BT sco traffic, and RSSI monitor is enabled, move measurements to the
545 * correct interface or disable it if this is the last interface to be
548 void iwlagn_bt_coex_rssi_monitor(struct iwl_priv
*priv
)
550 if (priv
->bt_is_sco
&&
551 priv
->bt_traffic_load
== IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS
)
552 iwlagn_bt_adjust_rssi_monitor(priv
, true);
554 iwlagn_bt_adjust_rssi_monitor(priv
, false);
557 static void iwlagn_print_uartmsg(struct iwl_priv
*priv
,
558 struct iwl_bt_uart_msg
*uart_msg
)
560 IWL_DEBUG_COEX(priv
, "Message Type = 0x%X, SSN = 0x%X, "
561 "Update Req = 0x%X\n",
562 (BT_UART_MSG_FRAME1MSGTYPE_MSK
& uart_msg
->frame1
) >>
563 BT_UART_MSG_FRAME1MSGTYPE_POS
,
564 (BT_UART_MSG_FRAME1SSN_MSK
& uart_msg
->frame1
) >>
565 BT_UART_MSG_FRAME1SSN_POS
,
566 (BT_UART_MSG_FRAME1UPDATEREQ_MSK
& uart_msg
->frame1
) >>
567 BT_UART_MSG_FRAME1UPDATEREQ_POS
);
569 IWL_DEBUG_COEX(priv
, "Open connections = 0x%X, Traffic load = 0x%X, "
570 "Chl_SeqN = 0x%X, In band = 0x%X\n",
571 (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK
& uart_msg
->frame2
) >>
572 BT_UART_MSG_FRAME2OPENCONNECTIONS_POS
,
573 (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK
& uart_msg
->frame2
) >>
574 BT_UART_MSG_FRAME2TRAFFICLOAD_POS
,
575 (BT_UART_MSG_FRAME2CHLSEQN_MSK
& uart_msg
->frame2
) >>
576 BT_UART_MSG_FRAME2CHLSEQN_POS
,
577 (BT_UART_MSG_FRAME2INBAND_MSK
& uart_msg
->frame2
) >>
578 BT_UART_MSG_FRAME2INBAND_POS
);
580 IWL_DEBUG_COEX(priv
, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, "
581 "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X\n",
582 (BT_UART_MSG_FRAME3SCOESCO_MSK
& uart_msg
->frame3
) >>
583 BT_UART_MSG_FRAME3SCOESCO_POS
,
584 (BT_UART_MSG_FRAME3SNIFF_MSK
& uart_msg
->frame3
) >>
585 BT_UART_MSG_FRAME3SNIFF_POS
,
586 (BT_UART_MSG_FRAME3A2DP_MSK
& uart_msg
->frame3
) >>
587 BT_UART_MSG_FRAME3A2DP_POS
,
588 (BT_UART_MSG_FRAME3ACL_MSK
& uart_msg
->frame3
) >>
589 BT_UART_MSG_FRAME3ACL_POS
,
590 (BT_UART_MSG_FRAME3MASTER_MSK
& uart_msg
->frame3
) >>
591 BT_UART_MSG_FRAME3MASTER_POS
,
592 (BT_UART_MSG_FRAME3OBEX_MSK
& uart_msg
->frame3
) >>
593 BT_UART_MSG_FRAME3OBEX_POS
);
595 IWL_DEBUG_COEX(priv
, "Idle duration = 0x%X\n",
596 (BT_UART_MSG_FRAME4IDLEDURATION_MSK
& uart_msg
->frame4
) >>
597 BT_UART_MSG_FRAME4IDLEDURATION_POS
);
599 IWL_DEBUG_COEX(priv
, "Tx Activity = 0x%X, Rx Activity = 0x%X, "
600 "eSCO Retransmissions = 0x%X\n",
601 (BT_UART_MSG_FRAME5TXACTIVITY_MSK
& uart_msg
->frame5
) >>
602 BT_UART_MSG_FRAME5TXACTIVITY_POS
,
603 (BT_UART_MSG_FRAME5RXACTIVITY_MSK
& uart_msg
->frame5
) >>
604 BT_UART_MSG_FRAME5RXACTIVITY_POS
,
605 (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK
& uart_msg
->frame5
) >>
606 BT_UART_MSG_FRAME5ESCORETRANSMIT_POS
);
608 IWL_DEBUG_COEX(priv
, "Sniff Interval = 0x%X, Discoverable = 0x%X\n",
609 (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK
& uart_msg
->frame6
) >>
610 BT_UART_MSG_FRAME6SNIFFINTERVAL_POS
,
611 (BT_UART_MSG_FRAME6DISCOVERABLE_MSK
& uart_msg
->frame6
) >>
612 BT_UART_MSG_FRAME6DISCOVERABLE_POS
);
614 IWL_DEBUG_COEX(priv
, "Sniff Activity = 0x%X, Page = "
615 "0x%X, Inquiry = 0x%X, Connectable = 0x%X\n",
616 (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK
& uart_msg
->frame7
) >>
617 BT_UART_MSG_FRAME7SNIFFACTIVITY_POS
,
618 (BT_UART_MSG_FRAME7PAGE_MSK
& uart_msg
->frame7
) >>
619 BT_UART_MSG_FRAME7PAGE_POS
,
620 (BT_UART_MSG_FRAME7INQUIRY_MSK
& uart_msg
->frame7
) >>
621 BT_UART_MSG_FRAME7INQUIRY_POS
,
622 (BT_UART_MSG_FRAME7CONNECTABLE_MSK
& uart_msg
->frame7
) >>
623 BT_UART_MSG_FRAME7CONNECTABLE_POS
);
626 static void iwlagn_set_kill_msk(struct iwl_priv
*priv
,
627 struct iwl_bt_uart_msg
*uart_msg
)
630 static const __le32 bt_kill_ack_msg
[2] = {
631 IWLAGN_BT_KILL_ACK_MASK_DEFAULT
,
632 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO
};
633 static const __le32 bt_kill_cts_msg
[2] = {
634 IWLAGN_BT_KILL_CTS_MASK_DEFAULT
,
635 IWLAGN_BT_KILL_ACK_CTS_MASK_SCO
};
637 kill_msk
= (BT_UART_MSG_FRAME3SCOESCO_MSK
& uart_msg
->frame3
)
639 if (priv
->kill_ack_mask
!= bt_kill_ack_msg
[kill_msk
] ||
640 priv
->kill_cts_mask
!= bt_kill_cts_msg
[kill_msk
]) {
641 priv
->bt_valid
|= IWLAGN_BT_VALID_KILL_ACK_MASK
;
642 priv
->kill_ack_mask
= bt_kill_ack_msg
[kill_msk
];
643 priv
->bt_valid
|= IWLAGN_BT_VALID_KILL_CTS_MASK
;
644 priv
->kill_cts_mask
= bt_kill_cts_msg
[kill_msk
];
646 /* schedule to send runtime bt_config */
647 queue_work(priv
->workqueue
, &priv
->bt_runtime_config
);
651 int iwlagn_bt_coex_profile_notif(struct iwl_priv
*priv
,
652 struct iwl_rx_cmd_buffer
*rxb
,
653 struct iwl_device_cmd
*cmd
)
655 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
656 struct iwl_bt_coex_profile_notif
*coex
= (void *)pkt
->data
;
657 struct iwl_bt_uart_msg
*uart_msg
= &coex
->last_bt_uart_msg
;
659 if (priv
->bt_enable_flag
== IWLAGN_BT_FLAG_COEX_MODE_DISABLED
) {
660 /* bt coex disabled */
664 IWL_DEBUG_COEX(priv
, "BT Coex notification:\n");
665 IWL_DEBUG_COEX(priv
, " status: %d\n", coex
->bt_status
);
666 IWL_DEBUG_COEX(priv
, " traffic load: %d\n", coex
->bt_traffic_load
);
667 IWL_DEBUG_COEX(priv
, " CI compliance: %d\n",
668 coex
->bt_ci_compliance
);
669 iwlagn_print_uartmsg(priv
, uart_msg
);
671 priv
->last_bt_traffic_load
= priv
->bt_traffic_load
;
672 priv
->bt_is_sco
= iwlagn_bt_traffic_is_sco(uart_msg
);
674 if (priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) {
675 if (priv
->bt_status
!= coex
->bt_status
||
676 priv
->last_bt_traffic_load
!= coex
->bt_traffic_load
) {
677 if (coex
->bt_status
) {
679 if (!priv
->bt_ch_announce
)
680 priv
->bt_traffic_load
=
681 IWL_BT_COEX_TRAFFIC_LOAD_HIGH
;
683 priv
->bt_traffic_load
=
684 coex
->bt_traffic_load
;
687 priv
->bt_traffic_load
=
688 IWL_BT_COEX_TRAFFIC_LOAD_NONE
;
690 priv
->bt_status
= coex
->bt_status
;
691 queue_work(priv
->workqueue
,
692 &priv
->bt_traffic_change_work
);
696 iwlagn_set_kill_msk(priv
, uart_msg
);
698 /* FIXME: based on notification, adjust the prio_boost */
700 priv
->bt_ci_compliance
= coex
->bt_ci_compliance
;
704 void iwlagn_bt_rx_handler_setup(struct iwl_priv
*priv
)
706 priv
->rx_handlers
[REPLY_BT_COEX_PROFILE_NOTIF
] =
707 iwlagn_bt_coex_profile_notif
;
710 void iwlagn_bt_setup_deferred_work(struct iwl_priv
*priv
)
712 INIT_WORK(&priv
->bt_traffic_change_work
,
713 iwlagn_bt_traffic_change_work
);
716 void iwlagn_bt_cancel_deferred_work(struct iwl_priv
*priv
)
718 cancel_work_sync(&priv
->bt_traffic_change_work
);
721 static bool is_single_rx_stream(struct iwl_priv
*priv
)
723 return priv
->current_ht_config
.smps
== IEEE80211_SMPS_STATIC
||
724 priv
->current_ht_config
.single_chain_sufficient
;
727 #define IWL_NUM_RX_CHAINS_MULTIPLE 3
728 #define IWL_NUM_RX_CHAINS_SINGLE 2
729 #define IWL_NUM_IDLE_CHAINS_DUAL 2
730 #define IWL_NUM_IDLE_CHAINS_SINGLE 1
733 * Determine how many receiver/antenna chains to use.
735 * More provides better reception via diversity. Fewer saves power
736 * at the expense of throughput, but only when not in powersave to
739 * MIMO (dual stream) requires at least 2, but works better with 3.
740 * This does not determine *which* chains to use, just how many.
742 static int iwl_get_active_rx_chain_count(struct iwl_priv
*priv
)
744 if (cfg(priv
)->bt_params
&&
745 cfg(priv
)->bt_params
->advanced_bt_coexist
&&
746 (priv
->bt_full_concurrent
||
747 priv
->bt_traffic_load
>= IWL_BT_COEX_TRAFFIC_LOAD_HIGH
)) {
749 * only use chain 'A' in bt high traffic load or
750 * full concurrency mode
752 return IWL_NUM_RX_CHAINS_SINGLE
;
754 /* # of Rx chains to use when expecting MIMO. */
755 if (is_single_rx_stream(priv
))
756 return IWL_NUM_RX_CHAINS_SINGLE
;
758 return IWL_NUM_RX_CHAINS_MULTIPLE
;
762 * When we are in power saving mode, unless device support spatial
763 * multiplexing power save, use the active count for rx chain count.
765 static int iwl_get_idle_rx_chain_count(struct iwl_priv
*priv
, int active_cnt
)
767 /* # Rx chains when idling, depending on SMPS mode */
768 switch (priv
->current_ht_config
.smps
) {
769 case IEEE80211_SMPS_STATIC
:
770 case IEEE80211_SMPS_DYNAMIC
:
771 return IWL_NUM_IDLE_CHAINS_SINGLE
;
772 case IEEE80211_SMPS_AUTOMATIC
:
773 case IEEE80211_SMPS_OFF
:
776 WARN(1, "invalid SMPS mode %d",
777 priv
->current_ht_config
.smps
);
783 static u8
iwl_count_chain_bitmap(u32 chain_bitmap
)
786 res
= (chain_bitmap
& BIT(0)) >> 0;
787 res
+= (chain_bitmap
& BIT(1)) >> 1;
788 res
+= (chain_bitmap
& BIT(2)) >> 2;
789 res
+= (chain_bitmap
& BIT(3)) >> 3;
794 * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
796 * Selects how many and which Rx receivers/antennas/chains to use.
797 * This should not be used for scan command ... it puts data in wrong place.
799 void iwlagn_set_rxon_chain(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
801 bool is_single
= is_single_rx_stream(priv
);
802 bool is_cam
= !test_bit(STATUS_POWER_PMI
, &priv
->status
);
803 u8 idle_rx_cnt
, active_rx_cnt
, valid_rx_cnt
;
807 /* Tell uCode which antennas are actually connected.
808 * Before first association, we assume all antennas are connected.
809 * Just after first association, iwl_chain_noise_calibration()
810 * checks which antennas actually *are* connected. */
811 if (priv
->chain_noise_data
.active_chains
)
812 active_chains
= priv
->chain_noise_data
.active_chains
;
814 active_chains
= priv
->hw_params
.valid_rx_ant
;
816 if (cfg(priv
)->bt_params
&&
817 cfg(priv
)->bt_params
->advanced_bt_coexist
&&
818 (priv
->bt_full_concurrent
||
819 priv
->bt_traffic_load
>= IWL_BT_COEX_TRAFFIC_LOAD_HIGH
)) {
821 * only use chain 'A' in bt high traffic load or
822 * full concurrency mode
824 active_chains
= first_antenna(active_chains
);
827 rx_chain
= active_chains
<< RXON_RX_CHAIN_VALID_POS
;
829 /* How many receivers should we use? */
830 active_rx_cnt
= iwl_get_active_rx_chain_count(priv
);
831 idle_rx_cnt
= iwl_get_idle_rx_chain_count(priv
, active_rx_cnt
);
834 /* correct rx chain count according hw settings
835 * and chain noise calibration
837 valid_rx_cnt
= iwl_count_chain_bitmap(active_chains
);
838 if (valid_rx_cnt
< active_rx_cnt
)
839 active_rx_cnt
= valid_rx_cnt
;
841 if (valid_rx_cnt
< idle_rx_cnt
)
842 idle_rx_cnt
= valid_rx_cnt
;
844 rx_chain
|= active_rx_cnt
<< RXON_RX_CHAIN_MIMO_CNT_POS
;
845 rx_chain
|= idle_rx_cnt
<< RXON_RX_CHAIN_CNT_POS
;
847 ctx
->staging
.rx_chain
= cpu_to_le16(rx_chain
);
849 if (!is_single
&& (active_rx_cnt
>= IWL_NUM_RX_CHAINS_SINGLE
) && is_cam
)
850 ctx
->staging
.rx_chain
|= RXON_RX_CHAIN_MIMO_FORCE_MSK
;
852 ctx
->staging
.rx_chain
&= ~RXON_RX_CHAIN_MIMO_FORCE_MSK
;
854 IWL_DEBUG_ASSOC(priv
, "rx_chain=0x%X active=%d idle=%d\n",
855 ctx
->staging
.rx_chain
,
856 active_rx_cnt
, idle_rx_cnt
);
858 WARN_ON(active_rx_cnt
== 0 || idle_rx_cnt
== 0 ||
859 active_rx_cnt
< idle_rx_cnt
);
862 u8
iwl_toggle_tx_ant(struct iwl_priv
*priv
, u8 ant
, u8 valid
)
867 if (priv
->band
== IEEE80211_BAND_2GHZ
&&
868 priv
->bt_traffic_load
>= IWL_BT_COEX_TRAFFIC_LOAD_HIGH
)
871 for (i
= 0; i
< RATE_ANT_NUM
- 1; i
++) {
872 ind
= (ind
+ 1) < RATE_ANT_NUM
? ind
+ 1 : 0;
873 if (valid
& BIT(ind
))
879 #ifdef CONFIG_PM_SLEEP
880 static void iwlagn_convert_p1k(u16
*p1k
, __le16
*out
)
884 for (i
= 0; i
< IWLAGN_P1K_SIZE
; i
++)
885 out
[i
] = cpu_to_le16(p1k
[i
]);
888 struct wowlan_key_data
{
889 struct iwl_rxon_context
*ctx
;
890 struct iwlagn_wowlan_rsc_tsc_params_cmd
*rsc_tsc
;
891 struct iwlagn_wowlan_tkip_params_cmd
*tkip
;
893 bool error
, use_rsc_tsc
, use_tkip
;
897 static void iwlagn_wowlan_program_keys(struct ieee80211_hw
*hw
,
898 struct ieee80211_vif
*vif
,
899 struct ieee80211_sta
*sta
,
900 struct ieee80211_key_conf
*key
,
903 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
904 struct wowlan_key_data
*data
= _data
;
905 struct iwl_rxon_context
*ctx
= data
->ctx
;
906 struct aes_sc
*aes_sc
, *aes_tx_sc
= NULL
;
907 struct tkip_sc
*tkip_sc
, *tkip_tx_sc
= NULL
;
908 struct iwlagn_p1k_cache
*rx_p1ks
;
910 struct ieee80211_key_seq seq
;
912 u16 p1k
[IWLAGN_P1K_SIZE
];
915 mutex_lock(&priv
->mutex
);
917 if ((key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
918 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
) &&
919 !sta
&& !ctx
->key_mapping_keys
)
920 ret
= iwl_set_default_wep_key(priv
, ctx
, key
);
922 ret
= iwl_set_dynamic_key(priv
, ctx
, key
, sta
);
925 IWL_ERR(priv
, "Error setting key during suspend!\n");
929 switch (key
->cipher
) {
930 case WLAN_CIPHER_SUITE_TKIP
:
932 tkip_sc
= data
->rsc_tsc
->all_tsc_rsc
.tkip
.unicast_rsc
;
933 tkip_tx_sc
= &data
->rsc_tsc
->all_tsc_rsc
.tkip
.tsc
;
935 rx_p1ks
= data
->tkip
->rx_uni
;
937 ieee80211_get_key_tx_seq(key
, &seq
);
938 tkip_tx_sc
->iv16
= cpu_to_le16(seq
.tkip
.iv16
);
939 tkip_tx_sc
->iv32
= cpu_to_le32(seq
.tkip
.iv32
);
941 ieee80211_get_tkip_p1k_iv(key
, seq
.tkip
.iv32
, p1k
);
942 iwlagn_convert_p1k(p1k
, data
->tkip
->tx
.p1k
);
944 memcpy(data
->tkip
->mic_keys
.tx
,
945 &key
->key
[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY
],
946 IWLAGN_MIC_KEY_SIZE
);
948 rx_mic_key
= data
->tkip
->mic_keys
.rx_unicast
;
951 data
->rsc_tsc
->all_tsc_rsc
.tkip
.multicast_rsc
;
952 rx_p1ks
= data
->tkip
->rx_multi
;
953 rx_mic_key
= data
->tkip
->mic_keys
.rx_mcast
;
957 * For non-QoS this relies on the fact that both the uCode and
958 * mac80211 use TID 0 (as they need to to avoid replay attacks)
959 * for checking the IV in the frames.
961 for (i
= 0; i
< IWLAGN_NUM_RSC
; i
++) {
962 ieee80211_get_key_rx_seq(key
, i
, &seq
);
963 tkip_sc
[i
].iv16
= cpu_to_le16(seq
.tkip
.iv16
);
964 tkip_sc
[i
].iv32
= cpu_to_le32(seq
.tkip
.iv32
);
965 /* wrapping isn't allowed, AP must rekey */
966 if (seq
.tkip
.iv32
> cur_rx_iv32
)
967 cur_rx_iv32
= seq
.tkip
.iv32
;
970 ieee80211_get_tkip_rx_p1k(key
, data
->bssid
, cur_rx_iv32
, p1k
);
971 iwlagn_convert_p1k(p1k
, rx_p1ks
[0].p1k
);
972 ieee80211_get_tkip_rx_p1k(key
, data
->bssid
,
973 cur_rx_iv32
+ 1, p1k
);
974 iwlagn_convert_p1k(p1k
, rx_p1ks
[1].p1k
);
977 &key
->key
[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY
],
978 IWLAGN_MIC_KEY_SIZE
);
980 data
->use_tkip
= true;
981 data
->use_rsc_tsc
= true;
983 case WLAN_CIPHER_SUITE_CCMP
:
985 u8
*pn
= seq
.ccmp
.pn
;
987 aes_sc
= data
->rsc_tsc
->all_tsc_rsc
.aes
.unicast_rsc
;
988 aes_tx_sc
= &data
->rsc_tsc
->all_tsc_rsc
.aes
.tsc
;
990 ieee80211_get_key_tx_seq(key
, &seq
);
991 aes_tx_sc
->pn
= cpu_to_le64(
999 aes_sc
= data
->rsc_tsc
->all_tsc_rsc
.aes
.multicast_rsc
;
1002 * For non-QoS this relies on the fact that both the uCode and
1003 * mac80211 use TID 0 for checking the IV in the frames.
1005 for (i
= 0; i
< IWLAGN_NUM_RSC
; i
++) {
1006 u8
*pn
= seq
.ccmp
.pn
;
1008 ieee80211_get_key_rx_seq(key
, i
, &seq
);
1009 aes_sc
->pn
= cpu_to_le64(
1012 ((u64
)pn
[3] << 16) |
1013 ((u64
)pn
[2] << 24) |
1014 ((u64
)pn
[1] << 32) |
1015 ((u64
)pn
[0] << 40));
1017 data
->use_rsc_tsc
= true;
1021 mutex_unlock(&priv
->mutex
);
1024 int iwlagn_send_patterns(struct iwl_priv
*priv
,
1025 struct cfg80211_wowlan
*wowlan
)
1027 struct iwlagn_wowlan_patterns_cmd
*pattern_cmd
;
1028 struct iwl_host_cmd cmd
= {
1029 .id
= REPLY_WOWLAN_PATTERNS
,
1030 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1035 if (!wowlan
->n_patterns
)
1038 cmd
.len
[0] = sizeof(*pattern_cmd
) +
1039 wowlan
->n_patterns
* sizeof(struct iwlagn_wowlan_pattern
);
1041 pattern_cmd
= kmalloc(cmd
.len
[0], GFP_KERNEL
);
1045 pattern_cmd
->n_patterns
= cpu_to_le32(wowlan
->n_patterns
);
1047 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
1048 int mask_len
= DIV_ROUND_UP(wowlan
->patterns
[i
].pattern_len
, 8);
1050 memcpy(&pattern_cmd
->patterns
[i
].mask
,
1051 wowlan
->patterns
[i
].mask
, mask_len
);
1052 memcpy(&pattern_cmd
->patterns
[i
].pattern
,
1053 wowlan
->patterns
[i
].pattern
,
1054 wowlan
->patterns
[i
].pattern_len
);
1055 pattern_cmd
->patterns
[i
].mask_size
= mask_len
;
1056 pattern_cmd
->patterns
[i
].pattern_size
=
1057 wowlan
->patterns
[i
].pattern_len
;
1060 cmd
.data
[0] = pattern_cmd
;
1061 err
= iwl_dvm_send_cmd(priv
, &cmd
);
1066 int iwlagn_suspend(struct iwl_priv
*priv
, struct cfg80211_wowlan
*wowlan
)
1068 struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd
;
1069 struct iwl_rxon_cmd rxon
;
1070 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1071 struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd
;
1072 struct iwlagn_wowlan_tkip_params_cmd tkip_cmd
= {};
1073 struct iwlagn_d3_config_cmd d3_cfg_cmd
= {};
1074 struct wowlan_key_data key_data
= {
1076 .bssid
= ctx
->active
.bssid_addr
,
1077 .use_rsc_tsc
= false,
1084 key_data
.rsc_tsc
= kzalloc(sizeof(*key_data
.rsc_tsc
), GFP_KERNEL
);
1085 if (!key_data
.rsc_tsc
)
1088 memset(&wakeup_filter_cmd
, 0, sizeof(wakeup_filter_cmd
));
1091 * We know the last used seqno, and the uCode expects to know that
1092 * one, it will increment before TX.
1094 seq
= le16_to_cpu(priv
->last_seq_ctl
) & IEEE80211_SCTL_SEQ
;
1095 wakeup_filter_cmd
.non_qos_seq
= cpu_to_le16(seq
);
1098 * For QoS counters, we store the one to use next, so subtract 0x10
1099 * since the uCode will add 0x10 before using the value.
1101 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
1102 seq
= priv
->tid_data
[IWL_AP_ID
][i
].seq_number
;
1104 wakeup_filter_cmd
.qos_seq
[i
] = cpu_to_le16(seq
);
1107 if (wowlan
->disconnect
)
1108 wakeup_filter_cmd
.enabled
|=
1109 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS
|
1110 IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE
);
1111 if (wowlan
->magic_pkt
)
1112 wakeup_filter_cmd
.enabled
|=
1113 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET
);
1114 if (wowlan
->gtk_rekey_failure
)
1115 wakeup_filter_cmd
.enabled
|=
1116 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL
);
1117 if (wowlan
->eap_identity_req
)
1118 wakeup_filter_cmd
.enabled
|=
1119 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ
);
1120 if (wowlan
->four_way_handshake
)
1121 wakeup_filter_cmd
.enabled
|=
1122 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE
);
1123 if (wowlan
->n_patterns
)
1124 wakeup_filter_cmd
.enabled
|=
1125 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH
);
1127 if (wowlan
->rfkill_release
)
1128 d3_cfg_cmd
.wakeup_flags
|=
1129 cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL
);
1131 iwl_scan_cancel_timeout(priv
, 200);
1133 memcpy(&rxon
, &ctx
->active
, sizeof(rxon
));
1135 priv
->ucode_loaded
= false;
1136 iwl_trans_stop_device(trans(priv
));
1138 priv
->wowlan
= true;
1140 ret
= iwl_load_ucode_wait_alive(priv
, IWL_UCODE_WOWLAN
);
1144 /* now configure WoWLAN ucode */
1145 ret
= iwl_alive_start(priv
);
1149 memcpy(&ctx
->staging
, &rxon
, sizeof(rxon
));
1150 ret
= iwlagn_commit_rxon(priv
, ctx
);
1154 ret
= iwl_power_update_mode(priv
, true);
1158 if (!iwlagn_mod_params
.sw_crypto
) {
1159 /* mark all keys clear */
1160 priv
->ucode_key_table
= 0;
1161 ctx
->key_mapping_keys
= 0;
1164 * This needs to be unlocked due to lock ordering
1165 * constraints. Since we're in the suspend path
1166 * that isn't really a problem though.
1168 mutex_unlock(&priv
->mutex
);
1169 ieee80211_iter_keys(priv
->hw
, ctx
->vif
,
1170 iwlagn_wowlan_program_keys
,
1172 mutex_lock(&priv
->mutex
);
1173 if (key_data
.error
) {
1178 if (key_data
.use_rsc_tsc
) {
1179 struct iwl_host_cmd rsc_tsc_cmd
= {
1180 .id
= REPLY_WOWLAN_TSC_RSC_PARAMS
,
1182 .data
[0] = key_data
.rsc_tsc
,
1183 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1184 .len
[0] = sizeof(*key_data
.rsc_tsc
),
1187 ret
= iwl_dvm_send_cmd(priv
, &rsc_tsc_cmd
);
1192 if (key_data
.use_tkip
) {
1193 ret
= iwl_dvm_send_cmd_pdu(priv
,
1194 REPLY_WOWLAN_TKIP_PARAMS
,
1195 CMD_SYNC
, sizeof(tkip_cmd
),
1201 if (priv
->have_rekey_data
) {
1202 memset(&kek_kck_cmd
, 0, sizeof(kek_kck_cmd
));
1203 memcpy(kek_kck_cmd
.kck
, priv
->kck
, NL80211_KCK_LEN
);
1204 kek_kck_cmd
.kck_len
= cpu_to_le16(NL80211_KCK_LEN
);
1205 memcpy(kek_kck_cmd
.kek
, priv
->kek
, NL80211_KEK_LEN
);
1206 kek_kck_cmd
.kek_len
= cpu_to_le16(NL80211_KEK_LEN
);
1207 kek_kck_cmd
.replay_ctr
= priv
->replay_ctr
;
1209 ret
= iwl_dvm_send_cmd_pdu(priv
,
1210 REPLY_WOWLAN_KEK_KCK_MATERIAL
,
1211 CMD_SYNC
, sizeof(kek_kck_cmd
),
1218 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_D3_CONFIG
, CMD_SYNC
,
1219 sizeof(d3_cfg_cmd
), &d3_cfg_cmd
);
1223 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_WOWLAN_WAKEUP_FILTER
,
1224 CMD_SYNC
, sizeof(wakeup_filter_cmd
),
1225 &wakeup_filter_cmd
);
1229 ret
= iwlagn_send_patterns(priv
, wowlan
);
1231 kfree(key_data
.rsc_tsc
);
1236 int iwl_dvm_send_cmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
1238 if (iwl_is_rfkill(priv
) || iwl_is_ctkill(priv
)) {
1239 IWL_WARN(priv
, "Not sending command - %s KILL\n",
1240 iwl_is_rfkill(priv
) ? "RF" : "CT");
1244 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
1245 IWL_ERR(priv
, "Command %s failed: FW Error\n",
1246 get_cmd_string(cmd
->id
));
1251 * Synchronous commands from this op-mode must hold
1252 * the mutex, this ensures we don't try to send two
1253 * (or more) synchronous commands at a time.
1255 if (cmd
->flags
& CMD_SYNC
)
1256 lockdep_assert_held(&priv
->mutex
);
1258 if (priv
->ucode_owner
== IWL_OWNERSHIP_TM
&&
1259 !(cmd
->flags
& CMD_ON_DEMAND
)) {
1260 IWL_DEBUG_HC(priv
, "tm own the uCode, no regular hcmd send\n");
1264 return iwl_trans_send_cmd(trans(priv
), cmd
);
1267 int iwl_dvm_send_cmd_pdu(struct iwl_priv
*priv
, u8 id
,
1268 u32 flags
, u16 len
, const void *data
)
1270 struct iwl_host_cmd cmd
= {
1277 return iwl_dvm_send_cmd(priv
, &cmd
);