Commit | Line | Data |
---|---|---|
e04ed0a5 WYG |
1 | /****************************************************************************** |
2 | * | |
3 | * GPL LICENSE SUMMARY | |
4 | * | |
fb4961db | 5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
e04ed0a5 WYG |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of version 2 of the GNU General Public License as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
19 | * USA | |
20 | * | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * Contact Information: | |
25 | * Intel Linux Wireless <ilw@linux.intel.com> | |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
27 | * | |
28 | *****************************************************************************/ | |
8d801080 | 29 | #include <linux/etherdevice.h> |
e04ed0a5 WYG |
30 | #include <linux/kernel.h> |
31 | #include <linux/module.h> | |
32 | #include <linux/init.h> | |
33 | #include <linux/sched.h> | |
34 | ||
35 | #include "iwl-dev.h" | |
36 | #include "iwl-core.h" | |
37 | #include "iwl-io.h" | |
e04ed0a5 WYG |
38 | #include "iwl-agn-hw.h" |
39 | #include "iwl-agn.h" | |
bdfbf092 | 40 | #include "iwl-trans.h" |
48f20d35 | 41 | #include "iwl-shared.h" |
e04ed0a5 | 42 | |
e04ed0a5 WYG |
43 | int iwlagn_hw_valid_rtc_data_addr(u32 addr) |
44 | { | |
45 | return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) && | |
46 | (addr < IWLAGN_RTC_DATA_UPPER_BOUND); | |
47 | } | |
48 | ||
49 | int iwlagn_send_tx_power(struct iwl_priv *priv) | |
50 | { | |
ab63c68a | 51 | struct iwlagn_tx_power_dbm_cmd tx_power_cmd; |
e04ed0a5 WYG |
52 | u8 tx_ant_cfg_cmd; |
53 | ||
83626404 | 54 | if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &priv->status), |
4beeba7d SG |
55 | "TX Power requested while scanning!\n")) |
56 | return -EAGAIN; | |
57 | ||
e04ed0a5 WYG |
58 | /* half dBm need to multiply */ |
59 | tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt); | |
60 | ||
61 | if (priv->tx_power_lmt_in_half_dbm && | |
62 | priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) { | |
63 | /* | |
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 | |
73 | */ | |
74 | tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm; | |
75 | } | |
ab63c68a WYG |
76 | tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED; |
77 | tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO; | |
e04ed0a5 | 78 | |
0692fe41 | 79 | if (IWL_UCODE_API(priv->fw->ucode_ver) == 1) |
e04ed0a5 WYG |
80 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1; |
81 | else | |
82 | tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD; | |
83 | ||
e10a0533 | 84 | return iwl_dvm_send_cmd_pdu(priv, tx_ant_cfg_cmd, CMD_SYNC, |
e419d62d | 85 | sizeof(tx_power_cmd), &tx_power_cmd); |
e04ed0a5 WYG |
86 | } |
87 | ||
88 | void iwlagn_temperature(struct iwl_priv *priv) | |
89 | { | |
4ff70fcd JB |
90 | lockdep_assert_held(&priv->statistics.lock); |
91 | ||
f8f79a5d | 92 | /* store temperature from correct statistics (in Celsius) */ |
0da0e5bf | 93 | priv->temperature = le32_to_cpu(priv->statistics.common.temperature); |
e04ed0a5 WYG |
94 | iwl_tt_handler(priv); |
95 | } | |
96 | ||
348ee7cd WYG |
97 | struct iwl_mod_params iwlagn_mod_params = { |
98 | .amsdu_size_8K = 1, | |
99 | .restart_fw = 1, | |
b7977ffa | 100 | .plcp_check = true, |
b60eec9b | 101 | .bt_coex_active = true, |
f7538168 | 102 | .power_level = IWL_POWER_INDEX_1, |
fee84f0d | 103 | .bt_ch_announce = true, |
dd5b6d0a | 104 | .auto_agg = true, |
348ee7cd WYG |
105 | /* the rest are 0 by default */ |
106 | }; | |
74bcdb33 | 107 | |
8d801080 WYG |
108 | int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band) |
109 | { | |
110 | int idx = 0; | |
111 | int band_offset = 0; | |
112 | ||
113 | /* HT rate format: mac80211 wants an MCS number, which is just LSB */ | |
114 | if (rate_n_flags & RATE_MCS_HT_MSK) { | |
115 | idx = (rate_n_flags & 0xff); | |
116 | return idx; | |
117 | /* Legacy rate format, search for match in table */ | |
118 | } else { | |
119 | if (band == IEEE80211_BAND_5GHZ) | |
120 | band_offset = IWL_FIRST_OFDM_RATE; | |
121 | for (idx = band_offset; idx < IWL_RATE_COUNT_LEGACY; idx++) | |
122 | if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF)) | |
123 | return idx - band_offset; | |
124 | } | |
125 | ||
126 | return -1; | |
127 | } | |
128 | ||
1fa61b2e JB |
129 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, |
130 | struct ieee80211_vif *vif, bool add) | |
131 | { | |
fd1af15d JB |
132 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
133 | ||
1fa61b2e | 134 | if (add) |
a30e3112 JB |
135 | return iwlagn_add_bssid_station(priv, vif_priv->ctx, |
136 | vif->bss_conf.bssid, | |
137 | &vif_priv->ibss_bssid_sta_id); | |
fd1af15d JB |
138 | return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id, |
139 | vif->bss_conf.bssid); | |
1fa61b2e | 140 | } |
1ff504e0 | 141 | |
716c74b0 WYG |
142 | /** |
143 | * iwlagn_txfifo_flush: send REPLY_TXFIFO_FLUSH command to uCode | |
144 | * | |
145 | * pre-requirements: | |
146 | * 1. acquire mutex before calling | |
147 | * 2. make sure rf is on and not in exit state | |
148 | */ | |
149 | int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control) | |
150 | { | |
151 | struct iwl_txfifo_flush_cmd flush_cmd; | |
152 | struct iwl_host_cmd cmd = { | |
153 | .id = REPLY_TXFIFO_FLUSH, | |
3fa50738 | 154 | .len = { sizeof(struct iwl_txfifo_flush_cmd), }, |
716c74b0 | 155 | .flags = CMD_SYNC, |
3fa50738 | 156 | .data = { &flush_cmd, }, |
716c74b0 WYG |
157 | }; |
158 | ||
159 | might_sleep(); | |
160 | ||
161 | memset(&flush_cmd, 0, sizeof(flush_cmd)); | |
ecdbe86e WYG |
162 | if (flush_control & BIT(IWL_RXON_CTX_BSS)) |
163 | flush_cmd.fifo_control = IWL_SCD_VO_MSK | IWL_SCD_VI_MSK | | |
f88e0ecc WYG |
164 | IWL_SCD_BE_MSK | IWL_SCD_BK_MSK | |
165 | IWL_SCD_MGMT_MSK; | |
ecdbe86e | 166 | if ((flush_control & BIT(IWL_RXON_CTX_PAN)) && |
a18f61bc | 167 | (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))) |
f88e0ecc WYG |
168 | flush_cmd.fifo_control |= IWL_PAN_SCD_VO_MSK | |
169 | IWL_PAN_SCD_VI_MSK | IWL_PAN_SCD_BE_MSK | | |
170 | IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK | | |
171 | IWL_PAN_SCD_MULTICAST_MSK; | |
172 | ||
9e295116 | 173 | if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE) |
716c74b0 WYG |
174 | flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK; |
175 | ||
176 | IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n", | |
177 | flush_cmd.fifo_control); | |
178 | flush_cmd.flush_control = cpu_to_le16(flush_control); | |
179 | ||
e10a0533 | 180 | return iwl_dvm_send_cmd(priv, &cmd); |
716c74b0 | 181 | } |
65550636 WYG |
182 | |
183 | void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control) | |
184 | { | |
b1eea297 | 185 | mutex_lock(&priv->mutex); |
65550636 | 186 | ieee80211_stop_queues(priv->hw); |
c68744fb | 187 | if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) { |
65550636 WYG |
188 | IWL_ERR(priv, "flush request fail\n"); |
189 | goto done; | |
190 | } | |
191 | IWL_DEBUG_INFO(priv, "wait transmit/flush all frames\n"); | |
5f178cd2 | 192 | iwl_trans_wait_tx_queue_empty(trans(priv)); |
65550636 WYG |
193 | done: |
194 | ieee80211_wake_queues(priv->hw); | |
b1eea297 | 195 | mutex_unlock(&priv->mutex); |
65550636 | 196 | } |
b6e116e8 WYG |
197 | |
198 | /* | |
199 | * BT coex | |
200 | */ | |
201 | /* | |
202 | * Macros to access the lookup table. | |
203 | * | |
204 | * The lookup table has 7 inputs: bt3_prio, bt3_txrx, bt_rf_act, wifi_req, | |
205 | * wifi_prio, wifi_txrx and wifi_sh_ant_req. | |
206 | * | |
207 | * It has three outputs: WLAN_ACTIVE, WLAN_KILL and ANT_SWITCH | |
208 | * | |
209 | * The format is that "registers" 8 through 11 contain the WLAN_ACTIVE bits | |
210 | * one after another in 32-bit registers, and "registers" 0 through 7 contain | |
211 | * the WLAN_KILL and ANT_SWITCH bits interleaved (in that order). | |
212 | * | |
213 | * These macros encode that format. | |
214 | */ | |
215 | #define LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, wifi_req, wifi_prio, \ | |
216 | wifi_txrx, wifi_sh_ant_req) \ | |
217 | (bt3_prio | (bt3_txrx << 1) | (bt_rf_act << 2) | (wifi_req << 3) | \ | |
218 | (wifi_prio << 4) | (wifi_txrx << 5) | (wifi_sh_ant_req << 6)) | |
219 | ||
220 | #define LUT_PTA_WLAN_ACTIVE_OP(lut, op, val) \ | |
221 | lut[8 + ((val) >> 5)] op (cpu_to_le32(BIT((val) & 0x1f))) | |
222 | #define LUT_TEST_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
223 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
224 | (!!(LUT_PTA_WLAN_ACTIVE_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, \ | |
225 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ | |
226 | wifi_sh_ant_req)))) | |
227 | #define LUT_SET_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
228 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
229 | LUT_PTA_WLAN_ACTIVE_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, \ | |
230 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ | |
231 | wifi_sh_ant_req)) | |
232 | #define LUT_CLEAR_PTA_WLAN_ACTIVE(lut, bt3_prio, bt3_txrx, bt_rf_act, \ | |
233 | wifi_req, wifi_prio, wifi_txrx, \ | |
234 | wifi_sh_ant_req) \ | |
235 | LUT_PTA_WLAN_ACTIVE_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, \ | |
236 | bt_rf_act, wifi_req, wifi_prio, wifi_txrx, \ | |
237 | wifi_sh_ant_req)) | |
238 | ||
239 | #define LUT_WLAN_KILL_OP(lut, op, val) \ | |
240 | lut[(val) >> 4] op (cpu_to_le32(BIT(((val) << 1) & 0x1e))) | |
241 | #define LUT_TEST_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
242 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
243 | (!!(LUT_WLAN_KILL_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
244 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)))) | |
245 | #define LUT_SET_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
246 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
247 | LUT_WLAN_KILL_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
248 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) | |
249 | #define LUT_CLEAR_WLAN_KILL(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
250 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
251 | LUT_WLAN_KILL_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
252 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) | |
253 | ||
254 | #define LUT_ANT_SWITCH_OP(lut, op, val) \ | |
255 | lut[(val) >> 4] op (cpu_to_le32(BIT((((val) << 1) & 0x1e) + 1))) | |
256 | #define LUT_TEST_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
257 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
258 | (!!(LUT_ANT_SWITCH_OP(lut, &, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
259 | wifi_req, wifi_prio, wifi_txrx, \ | |
260 | wifi_sh_ant_req)))) | |
261 | #define LUT_SET_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
262 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
263 | LUT_ANT_SWITCH_OP(lut, |=, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
264 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) | |
265 | #define LUT_CLEAR_ANT_SWITCH(lut, bt3_prio, bt3_txrx, bt_rf_act, wifi_req, \ | |
266 | wifi_prio, wifi_txrx, wifi_sh_ant_req) \ | |
267 | LUT_ANT_SWITCH_OP(lut, &= ~, LUT_VALUE(bt3_prio, bt3_txrx, bt_rf_act, \ | |
268 | wifi_req, wifi_prio, wifi_txrx, wifi_sh_ant_req)) | |
269 | ||
270 | static const __le32 iwlagn_def_3w_lookup[12] = { | |
271 | cpu_to_le32(0xaaaaaaaa), | |
272 | cpu_to_le32(0xaaaaaaaa), | |
273 | cpu_to_le32(0xaeaaaaaa), | |
274 | cpu_to_le32(0xaaaaaaaa), | |
275 | cpu_to_le32(0xcc00ff28), | |
276 | cpu_to_le32(0x0000aaaa), | |
277 | cpu_to_le32(0xcc00aaaa), | |
278 | cpu_to_le32(0x0000aaaa), | |
279 | cpu_to_le32(0xc0004000), | |
280 | cpu_to_le32(0x00004000), | |
281 | cpu_to_le32(0xf0005000), | |
9a67d761 | 282 | cpu_to_le32(0xf0005000), |
b6e116e8 WYG |
283 | }; |
284 | ||
285 | static const __le32 iwlagn_concurrent_lookup[12] = { | |
286 | cpu_to_le32(0xaaaaaaaa), | |
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(0x00000000), | |
295 | cpu_to_le32(0x00000000), | |
296 | cpu_to_le32(0x00000000), | |
297 | cpu_to_le32(0x00000000), | |
298 | }; | |
299 | ||
300 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv) | |
301 | { | |
6013270a | 302 | struct iwl_basic_bt_cmd basic = { |
b6e116e8 WYG |
303 | .max_kill = IWLAGN_BT_MAX_KILL_DEFAULT, |
304 | .bt3_timer_t7_value = IWLAGN_BT3_T7_DEFAULT, | |
305 | .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT, | |
306 | .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT, | |
307 | }; | |
8347deb3 WYG |
308 | struct iwl_bt_cmd_v1 bt_cmd_v1; |
309 | struct iwl_bt_cmd_v2 bt_cmd_v2; | |
6013270a | 310 | int ret; |
b6e116e8 WYG |
311 | |
312 | BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) != | |
6013270a WYG |
313 | sizeof(basic.bt3_lookup_table)); |
314 | ||
38622419 | 315 | if (cfg(priv)->bt_params) { |
8347deb3 WYG |
316 | /* |
317 | * newer generation of devices (2000 series and newer) | |
318 | * use the version 2 of the bt command | |
319 | * we need to make sure sending the host command | |
320 | * with correct data structure to avoid uCode assert | |
321 | */ | |
38622419 | 322 | if (cfg(priv)->bt_params->bt_session_2) { |
8347deb3 | 323 | bt_cmd_v2.prio_boost = cpu_to_le32( |
38622419 | 324 | cfg(priv)->bt_params->bt_prio_boost); |
8347deb3 WYG |
325 | bt_cmd_v2.tx_prio_boost = 0; |
326 | bt_cmd_v2.rx_prio_boost = 0; | |
6013270a | 327 | } else { |
8347deb3 | 328 | bt_cmd_v1.prio_boost = |
38622419 | 329 | cfg(priv)->bt_params->bt_prio_boost; |
8347deb3 WYG |
330 | bt_cmd_v1.tx_prio_boost = 0; |
331 | bt_cmd_v1.rx_prio_boost = 0; | |
6013270a WYG |
332 | } |
333 | } else { | |
334 | IWL_ERR(priv, "failed to construct BT Coex Config\n"); | |
335 | return; | |
336 | } | |
506aa156 | 337 | |
6013270a WYG |
338 | basic.kill_ack_mask = priv->kill_ack_mask; |
339 | basic.kill_cts_mask = priv->kill_cts_mask; | |
340 | basic.valid = priv->bt_valid; | |
b6e116e8 WYG |
341 | |
342 | /* | |
343 | * Configure BT coex mode to "no coexistence" when the | |
344 | * user disabled BT coexistence, we have no interface | |
345 | * (might be in monitor mode), or the interface is in | |
346 | * IBSS mode (no proper uCode support for coex then). | |
347 | */ | |
b60eec9b WYG |
348 | if (!iwlagn_mod_params.bt_coex_active || |
349 | priv->iw_mode == NL80211_IFTYPE_ADHOC) { | |
6013270a | 350 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_DISABLED; |
b6e116e8 | 351 | } else { |
6013270a | 352 | basic.flags = IWLAGN_BT_FLAG_COEX_MODE_3W << |
b6e116e8 | 353 | IWLAGN_BT_FLAG_COEX_MODE_SHIFT; |
207ecc5e MV |
354 | |
355 | if (!priv->bt_enable_pspoll) | |
6013270a | 356 | basic.flags |= IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; |
207ecc5e MV |
357 | else |
358 | basic.flags &= ~IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE; | |
e366176e | 359 | |
b6e116e8 | 360 | if (priv->bt_ch_announce) |
6013270a | 361 | basic.flags |= IWLAGN_BT_FLAG_CHANNEL_INHIBITION; |
fa7f1413 | 362 | IWL_DEBUG_COEX(priv, "BT coex flag: 0X%x\n", basic.flags); |
b6e116e8 | 363 | } |
6013270a | 364 | priv->bt_enable_flag = basic.flags; |
b6e116e8 | 365 | if (priv->bt_full_concurrent) |
6013270a | 366 | memcpy(basic.bt3_lookup_table, iwlagn_concurrent_lookup, |
b6e116e8 WYG |
367 | sizeof(iwlagn_concurrent_lookup)); |
368 | else | |
6013270a | 369 | memcpy(basic.bt3_lookup_table, iwlagn_def_3w_lookup, |
b6e116e8 WYG |
370 | sizeof(iwlagn_def_3w_lookup)); |
371 | ||
fa7f1413 | 372 | IWL_DEBUG_COEX(priv, "BT coex %s in %s mode\n", |
6013270a | 373 | basic.flags ? "active" : "disabled", |
b6e116e8 WYG |
374 | priv->bt_full_concurrent ? |
375 | "full concurrency" : "3-wire"); | |
376 | ||
38622419 | 377 | if (cfg(priv)->bt_params->bt_session_2) { |
8347deb3 | 378 | memcpy(&bt_cmd_v2.basic, &basic, |
6013270a | 379 | sizeof(basic)); |
e10a0533 | 380 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
8347deb3 | 381 | CMD_SYNC, sizeof(bt_cmd_v2), &bt_cmd_v2); |
6013270a | 382 | } else { |
8347deb3 | 383 | memcpy(&bt_cmd_v1.basic, &basic, |
6013270a | 384 | sizeof(basic)); |
e10a0533 | 385 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
8347deb3 | 386 | CMD_SYNC, sizeof(bt_cmd_v1), &bt_cmd_v1); |
6013270a WYG |
387 | } |
388 | if (ret) | |
b6e116e8 WYG |
389 | IWL_ERR(priv, "failed to send BT Coex Config\n"); |
390 | ||
b6e116e8 WYG |
391 | } |
392 | ||
207ecc5e MV |
393 | void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena) |
394 | { | |
395 | struct iwl_rxon_context *ctx, *found_ctx = NULL; | |
396 | bool found_ap = false; | |
397 | ||
b1eea297 | 398 | lockdep_assert_held(&priv->mutex); |
207ecc5e MV |
399 | |
400 | /* Check whether AP or GO mode is active. */ | |
401 | if (rssi_ena) { | |
402 | for_each_context(priv, ctx) { | |
403 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_AP && | |
404 | iwl_is_associated_ctx(ctx)) { | |
405 | found_ap = true; | |
406 | break; | |
407 | } | |
408 | } | |
409 | } | |
410 | ||
411 | /* | |
412 | * If disable was received or If GO/AP mode, disable RSSI | |
413 | * measurements. | |
414 | */ | |
415 | if (!rssi_ena || found_ap) { | |
416 | if (priv->cur_rssi_ctx) { | |
417 | ctx = priv->cur_rssi_ctx; | |
418 | ieee80211_disable_rssi_reports(ctx->vif); | |
419 | priv->cur_rssi_ctx = NULL; | |
420 | } | |
421 | return; | |
422 | } | |
423 | ||
424 | /* | |
425 | * If rssi measurements need to be enabled, consider all cases now. | |
426 | * Figure out how many contexts are active. | |
427 | */ | |
428 | for_each_context(priv, ctx) { | |
429 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && | |
430 | iwl_is_associated_ctx(ctx)) { | |
431 | found_ctx = ctx; | |
432 | break; | |
433 | } | |
434 | } | |
435 | ||
436 | /* | |
437 | * rssi monitor already enabled for the correct interface...nothing | |
438 | * to do. | |
439 | */ | |
440 | if (found_ctx == priv->cur_rssi_ctx) | |
441 | return; | |
442 | ||
443 | /* | |
444 | * Figure out if rssi monitor is currently enabled, and needs | |
445 | * to be changed. If rssi monitor is already enabled, disable | |
446 | * it first else just enable rssi measurements on the | |
447 | * interface found above. | |
448 | */ | |
449 | if (priv->cur_rssi_ctx) { | |
450 | ctx = priv->cur_rssi_ctx; | |
451 | if (ctx->vif) | |
452 | ieee80211_disable_rssi_reports(ctx->vif); | |
453 | } | |
454 | ||
455 | priv->cur_rssi_ctx = found_ctx; | |
456 | ||
457 | if (!found_ctx) | |
458 | return; | |
459 | ||
460 | ieee80211_enable_rssi_reports(found_ctx->vif, | |
461 | IWLAGN_BT_PSP_MIN_RSSI_THRESHOLD, | |
462 | IWLAGN_BT_PSP_MAX_RSSI_THRESHOLD); | |
463 | } | |
464 | ||
465 | static bool iwlagn_bt_traffic_is_sco(struct iwl_bt_uart_msg *uart_msg) | |
466 | { | |
467 | return BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3 >> | |
468 | BT_UART_MSG_FRAME3SCOESCO_POS; | |
469 | } | |
470 | ||
b6e116e8 WYG |
471 | static void iwlagn_bt_traffic_change_work(struct work_struct *work) |
472 | { | |
473 | struct iwl_priv *priv = | |
474 | container_of(work, struct iwl_priv, bt_traffic_change_work); | |
8bd413e6 | 475 | struct iwl_rxon_context *ctx; |
b6e116e8 WYG |
476 | int smps_request = -1; |
477 | ||
c4197c62 WYG |
478 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { |
479 | /* bt coex disabled */ | |
480 | return; | |
481 | } | |
482 | ||
5eda74a4 SG |
483 | /* |
484 | * Note: bt_traffic_load can be overridden by scan complete and | |
485 | * coex profile notifications. Ignore that since only bad consequence | |
486 | * can be not matching debug print with actual state. | |
487 | */ | |
fa7f1413 | 488 | IWL_DEBUG_COEX(priv, "BT traffic load changes: %d\n", |
b6e116e8 WYG |
489 | priv->bt_traffic_load); |
490 | ||
491 | switch (priv->bt_traffic_load) { | |
492 | case IWL_BT_COEX_TRAFFIC_LOAD_NONE: | |
f5682c01 WYG |
493 | if (priv->bt_status) |
494 | smps_request = IEEE80211_SMPS_DYNAMIC; | |
495 | else | |
496 | smps_request = IEEE80211_SMPS_AUTOMATIC; | |
b6e116e8 WYG |
497 | break; |
498 | case IWL_BT_COEX_TRAFFIC_LOAD_LOW: | |
499 | smps_request = IEEE80211_SMPS_DYNAMIC; | |
500 | break; | |
501 | case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: | |
502 | case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: | |
503 | smps_request = IEEE80211_SMPS_STATIC; | |
504 | break; | |
505 | default: | |
506 | IWL_ERR(priv, "Invalid BT traffic load: %d\n", | |
507 | priv->bt_traffic_load); | |
508 | break; | |
509 | } | |
510 | ||
b1eea297 | 511 | mutex_lock(&priv->mutex); |
b6e116e8 | 512 | |
5eda74a4 SG |
513 | /* |
514 | * We can not send command to firmware while scanning. When the scan | |
515 | * complete we will schedule this work again. We do check with mutex | |
516 | * locked to prevent new scan request to arrive. We do not check | |
517 | * STATUS_SCANNING to avoid race when queue_work two times from | |
518 | * different notifications, but quit and not perform any work at all. | |
519 | */ | |
83626404 | 520 | if (test_bit(STATUS_SCAN_HW, &priv->status)) |
5eda74a4 SG |
521 | goto out; |
522 | ||
6b6db91c | 523 | iwl_update_chain_flags(priv); |
b6e116e8 | 524 | |
8bd413e6 | 525 | if (smps_request != -1) { |
88e9ba76 | 526 | priv->current_ht_config.smps = smps_request; |
8bd413e6 JB |
527 | for_each_context(priv, ctx) { |
528 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION) | |
529 | ieee80211_request_smps(ctx->vif, smps_request); | |
530 | } | |
531 | } | |
207ecc5e MV |
532 | |
533 | /* | |
534 | * Dynamic PS poll related functionality. Adjust RSSI measurements if | |
535 | * necessary. | |
536 | */ | |
537 | iwlagn_bt_coex_rssi_monitor(priv); | |
5eda74a4 | 538 | out: |
b1eea297 | 539 | mutex_unlock(&priv->mutex); |
b6e116e8 WYG |
540 | } |
541 | ||
207ecc5e MV |
542 | /* |
543 | * If BT sco traffic, and RSSI monitor is enabled, move measurements to the | |
544 | * correct interface or disable it if this is the last interface to be | |
545 | * removed. | |
546 | */ | |
547 | void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv) | |
548 | { | |
549 | if (priv->bt_is_sco && | |
550 | priv->bt_traffic_load == IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS) | |
551 | iwlagn_bt_adjust_rssi_monitor(priv, true); | |
552 | else | |
553 | iwlagn_bt_adjust_rssi_monitor(priv, false); | |
554 | } | |
555 | ||
b6e116e8 WYG |
556 | static void iwlagn_print_uartmsg(struct iwl_priv *priv, |
557 | struct iwl_bt_uart_msg *uart_msg) | |
558 | { | |
fa7f1413 | 559 | IWL_DEBUG_COEX(priv, "Message Type = 0x%X, SSN = 0x%X, " |
0ca24daf | 560 | "Update Req = 0x%X\n", |
b6e116e8 WYG |
561 | (BT_UART_MSG_FRAME1MSGTYPE_MSK & uart_msg->frame1) >> |
562 | BT_UART_MSG_FRAME1MSGTYPE_POS, | |
563 | (BT_UART_MSG_FRAME1SSN_MSK & uart_msg->frame1) >> | |
564 | BT_UART_MSG_FRAME1SSN_POS, | |
565 | (BT_UART_MSG_FRAME1UPDATEREQ_MSK & uart_msg->frame1) >> | |
566 | BT_UART_MSG_FRAME1UPDATEREQ_POS); | |
567 | ||
fa7f1413 | 568 | IWL_DEBUG_COEX(priv, "Open connections = 0x%X, Traffic load = 0x%X, " |
0ca24daf | 569 | "Chl_SeqN = 0x%X, In band = 0x%X\n", |
b6e116e8 WYG |
570 | (BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK & uart_msg->frame2) >> |
571 | BT_UART_MSG_FRAME2OPENCONNECTIONS_POS, | |
572 | (BT_UART_MSG_FRAME2TRAFFICLOAD_MSK & uart_msg->frame2) >> | |
573 | BT_UART_MSG_FRAME2TRAFFICLOAD_POS, | |
574 | (BT_UART_MSG_FRAME2CHLSEQN_MSK & uart_msg->frame2) >> | |
575 | BT_UART_MSG_FRAME2CHLSEQN_POS, | |
576 | (BT_UART_MSG_FRAME2INBAND_MSK & uart_msg->frame2) >> | |
577 | BT_UART_MSG_FRAME2INBAND_POS); | |
578 | ||
fa7f1413 | 579 | IWL_DEBUG_COEX(priv, "SCO/eSCO = 0x%X, Sniff = 0x%X, A2DP = 0x%X, " |
0ca24daf | 580 | "ACL = 0x%X, Master = 0x%X, OBEX = 0x%X\n", |
b6e116e8 WYG |
581 | (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) >> |
582 | BT_UART_MSG_FRAME3SCOESCO_POS, | |
583 | (BT_UART_MSG_FRAME3SNIFF_MSK & uart_msg->frame3) >> | |
584 | BT_UART_MSG_FRAME3SNIFF_POS, | |
585 | (BT_UART_MSG_FRAME3A2DP_MSK & uart_msg->frame3) >> | |
586 | BT_UART_MSG_FRAME3A2DP_POS, | |
587 | (BT_UART_MSG_FRAME3ACL_MSK & uart_msg->frame3) >> | |
588 | BT_UART_MSG_FRAME3ACL_POS, | |
589 | (BT_UART_MSG_FRAME3MASTER_MSK & uart_msg->frame3) >> | |
590 | BT_UART_MSG_FRAME3MASTER_POS, | |
591 | (BT_UART_MSG_FRAME3OBEX_MSK & uart_msg->frame3) >> | |
592 | BT_UART_MSG_FRAME3OBEX_POS); | |
593 | ||
0ca24daf | 594 | IWL_DEBUG_COEX(priv, "Idle duration = 0x%X\n", |
b6e116e8 WYG |
595 | (BT_UART_MSG_FRAME4IDLEDURATION_MSK & uart_msg->frame4) >> |
596 | BT_UART_MSG_FRAME4IDLEDURATION_POS); | |
597 | ||
fa7f1413 | 598 | IWL_DEBUG_COEX(priv, "Tx Activity = 0x%X, Rx Activity = 0x%X, " |
0ca24daf | 599 | "eSCO Retransmissions = 0x%X\n", |
b6e116e8 WYG |
600 | (BT_UART_MSG_FRAME5TXACTIVITY_MSK & uart_msg->frame5) >> |
601 | BT_UART_MSG_FRAME5TXACTIVITY_POS, | |
602 | (BT_UART_MSG_FRAME5RXACTIVITY_MSK & uart_msg->frame5) >> | |
603 | BT_UART_MSG_FRAME5RXACTIVITY_POS, | |
604 | (BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK & uart_msg->frame5) >> | |
605 | BT_UART_MSG_FRAME5ESCORETRANSMIT_POS); | |
606 | ||
0ca24daf | 607 | IWL_DEBUG_COEX(priv, "Sniff Interval = 0x%X, Discoverable = 0x%X\n", |
b6e116e8 WYG |
608 | (BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK & uart_msg->frame6) >> |
609 | BT_UART_MSG_FRAME6SNIFFINTERVAL_POS, | |
610 | (BT_UART_MSG_FRAME6DISCOVERABLE_MSK & uart_msg->frame6) >> | |
611 | BT_UART_MSG_FRAME6DISCOVERABLE_POS); | |
612 | ||
fa7f1413 | 613 | IWL_DEBUG_COEX(priv, "Sniff Activity = 0x%X, Page = " |
0ca24daf | 614 | "0x%X, Inquiry = 0x%X, Connectable = 0x%X\n", |
b6e116e8 WYG |
615 | (BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK & uart_msg->frame7) >> |
616 | BT_UART_MSG_FRAME7SNIFFACTIVITY_POS, | |
399f66fd WYG |
617 | (BT_UART_MSG_FRAME7PAGE_MSK & uart_msg->frame7) >> |
618 | BT_UART_MSG_FRAME7PAGE_POS, | |
619 | (BT_UART_MSG_FRAME7INQUIRY_MSK & uart_msg->frame7) >> | |
620 | BT_UART_MSG_FRAME7INQUIRY_POS, | |
b6e116e8 WYG |
621 | (BT_UART_MSG_FRAME7CONNECTABLE_MSK & uart_msg->frame7) >> |
622 | BT_UART_MSG_FRAME7CONNECTABLE_POS); | |
623 | } | |
624 | ||
506aa156 WYG |
625 | static void iwlagn_set_kill_msk(struct iwl_priv *priv, |
626 | struct iwl_bt_uart_msg *uart_msg) | |
b6e116e8 | 627 | { |
506aa156 | 628 | u8 kill_msk; |
20407ed8 | 629 | static const __le32 bt_kill_ack_msg[2] = { |
506aa156 WYG |
630 | IWLAGN_BT_KILL_ACK_MASK_DEFAULT, |
631 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO }; | |
632 | static const __le32 bt_kill_cts_msg[2] = { | |
633 | IWLAGN_BT_KILL_CTS_MASK_DEFAULT, | |
634 | IWLAGN_BT_KILL_ACK_CTS_MASK_SCO }; | |
635 | ||
636 | kill_msk = (BT_UART_MSG_FRAME3SCOESCO_MSK & uart_msg->frame3) | |
637 | ? 1 : 0; | |
638 | if (priv->kill_ack_mask != bt_kill_ack_msg[kill_msk] || | |
639 | priv->kill_cts_mask != bt_kill_cts_msg[kill_msk]) { | |
b6e116e8 | 640 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_ACK_MASK; |
506aa156 WYG |
641 | priv->kill_ack_mask = bt_kill_ack_msg[kill_msk]; |
642 | priv->bt_valid |= IWLAGN_BT_VALID_KILL_CTS_MASK; | |
643 | priv->kill_cts_mask = bt_kill_cts_msg[kill_msk]; | |
644 | ||
b6e116e8 | 645 | /* schedule to send runtime bt_config */ |
1ee158d8 | 646 | queue_work(priv->workqueue, &priv->bt_runtime_config); |
b6e116e8 | 647 | } |
b6e116e8 WYG |
648 | } |
649 | ||
247c61d6 | 650 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, |
48a2d66f | 651 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 652 | struct iwl_device_cmd *cmd) |
b6e116e8 | 653 | { |
b6e116e8 | 654 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
f8d7c1a1 | 655 | struct iwl_bt_coex_profile_notif *coex = (void *)pkt->data; |
b6e116e8 | 656 | struct iwl_bt_uart_msg *uart_msg = &coex->last_bt_uart_msg; |
b6e116e8 | 657 | |
c4197c62 WYG |
658 | if (priv->bt_enable_flag == IWLAGN_BT_FLAG_COEX_MODE_DISABLED) { |
659 | /* bt coex disabled */ | |
247c61d6 | 660 | return 0; |
c4197c62 WYG |
661 | } |
662 | ||
fa7f1413 WYG |
663 | IWL_DEBUG_COEX(priv, "BT Coex notification:\n"); |
664 | IWL_DEBUG_COEX(priv, " status: %d\n", coex->bt_status); | |
665 | IWL_DEBUG_COEX(priv, " traffic load: %d\n", coex->bt_traffic_load); | |
666 | IWL_DEBUG_COEX(priv, " CI compliance: %d\n", | |
b6e116e8 WYG |
667 | coex->bt_ci_compliance); |
668 | iwlagn_print_uartmsg(priv, uart_msg); | |
669 | ||
66e863a5 | 670 | priv->last_bt_traffic_load = priv->bt_traffic_load; |
207ecc5e MV |
671 | priv->bt_is_sco = iwlagn_bt_traffic_is_sco(uart_msg); |
672 | ||
b6e116e8 WYG |
673 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
674 | if (priv->bt_status != coex->bt_status || | |
66e863a5 | 675 | priv->last_bt_traffic_load != coex->bt_traffic_load) { |
b6e116e8 WYG |
676 | if (coex->bt_status) { |
677 | /* BT on */ | |
678 | if (!priv->bt_ch_announce) | |
679 | priv->bt_traffic_load = | |
680 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | |
681 | else | |
682 | priv->bt_traffic_load = | |
683 | coex->bt_traffic_load; | |
684 | } else { | |
685 | /* BT off */ | |
686 | priv->bt_traffic_load = | |
687 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; | |
688 | } | |
689 | priv->bt_status = coex->bt_status; | |
1ee158d8 | 690 | queue_work(priv->workqueue, |
b6e116e8 WYG |
691 | &priv->bt_traffic_change_work); |
692 | } | |
b6e116e8 WYG |
693 | } |
694 | ||
506aa156 | 695 | iwlagn_set_kill_msk(priv, uart_msg); |
b6e116e8 WYG |
696 | |
697 | /* FIXME: based on notification, adjust the prio_boost */ | |
698 | ||
b6e116e8 | 699 | priv->bt_ci_compliance = coex->bt_ci_compliance; |
247c61d6 | 700 | return 0; |
b6e116e8 WYG |
701 | } |
702 | ||
703 | void iwlagn_bt_rx_handler_setup(struct iwl_priv *priv) | |
704 | { | |
b6e116e8 WYG |
705 | priv->rx_handlers[REPLY_BT_COEX_PROFILE_NOTIF] = |
706 | iwlagn_bt_coex_profile_notif; | |
707 | } | |
708 | ||
709 | void iwlagn_bt_setup_deferred_work(struct iwl_priv *priv) | |
710 | { | |
b6e116e8 WYG |
711 | INIT_WORK(&priv->bt_traffic_change_work, |
712 | iwlagn_bt_traffic_change_work); | |
713 | } | |
714 | ||
715 | void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv) | |
716 | { | |
717 | cancel_work_sync(&priv->bt_traffic_change_work); | |
718 | } | |
5de33068 JB |
719 | |
720 | static bool is_single_rx_stream(struct iwl_priv *priv) | |
721 | { | |
722 | return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC || | |
723 | priv->current_ht_config.single_chain_sufficient; | |
724 | } | |
725 | ||
726 | #define IWL_NUM_RX_CHAINS_MULTIPLE 3 | |
727 | #define IWL_NUM_RX_CHAINS_SINGLE 2 | |
728 | #define IWL_NUM_IDLE_CHAINS_DUAL 2 | |
729 | #define IWL_NUM_IDLE_CHAINS_SINGLE 1 | |
730 | ||
731 | /* | |
732 | * Determine how many receiver/antenna chains to use. | |
733 | * | |
734 | * More provides better reception via diversity. Fewer saves power | |
735 | * at the expense of throughput, but only when not in powersave to | |
736 | * start with. | |
737 | * | |
738 | * MIMO (dual stream) requires at least 2, but works better with 3. | |
739 | * This does not determine *which* chains to use, just how many. | |
740 | */ | |
741 | static int iwl_get_active_rx_chain_count(struct iwl_priv *priv) | |
742 | { | |
38622419 DF |
743 | if (cfg(priv)->bt_params && |
744 | cfg(priv)->bt_params->advanced_bt_coexist && | |
5de33068 JB |
745 | (priv->bt_full_concurrent || |
746 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { | |
747 | /* | |
748 | * only use chain 'A' in bt high traffic load or | |
749 | * full concurrency mode | |
750 | */ | |
751 | return IWL_NUM_RX_CHAINS_SINGLE; | |
752 | } | |
753 | /* # of Rx chains to use when expecting MIMO. */ | |
754 | if (is_single_rx_stream(priv)) | |
755 | return IWL_NUM_RX_CHAINS_SINGLE; | |
756 | else | |
757 | return IWL_NUM_RX_CHAINS_MULTIPLE; | |
758 | } | |
759 | ||
760 | /* | |
761 | * When we are in power saving mode, unless device support spatial | |
762 | * multiplexing power save, use the active count for rx chain count. | |
763 | */ | |
764 | static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt) | |
765 | { | |
766 | /* # Rx chains when idling, depending on SMPS mode */ | |
767 | switch (priv->current_ht_config.smps) { | |
768 | case IEEE80211_SMPS_STATIC: | |
769 | case IEEE80211_SMPS_DYNAMIC: | |
770 | return IWL_NUM_IDLE_CHAINS_SINGLE; | |
b2ccccdc | 771 | case IEEE80211_SMPS_AUTOMATIC: |
5de33068 JB |
772 | case IEEE80211_SMPS_OFF: |
773 | return active_cnt; | |
774 | default: | |
775 | WARN(1, "invalid SMPS mode %d", | |
776 | priv->current_ht_config.smps); | |
777 | return active_cnt; | |
778 | } | |
779 | } | |
780 | ||
781 | /* up to 4 chains */ | |
782 | static u8 iwl_count_chain_bitmap(u32 chain_bitmap) | |
783 | { | |
784 | u8 res; | |
785 | res = (chain_bitmap & BIT(0)) >> 0; | |
786 | res += (chain_bitmap & BIT(1)) >> 1; | |
787 | res += (chain_bitmap & BIT(2)) >> 2; | |
788 | res += (chain_bitmap & BIT(3)) >> 3; | |
789 | return res; | |
790 | } | |
791 | ||
792 | /** | |
793 | * iwlagn_set_rxon_chain - Set up Rx chain usage in "staging" RXON image | |
794 | * | |
795 | * Selects how many and which Rx receivers/antennas/chains to use. | |
796 | * This should not be used for scan command ... it puts data in wrong place. | |
797 | */ | |
798 | void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | |
799 | { | |
800 | bool is_single = is_single_rx_stream(priv); | |
47107e84 | 801 | bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status); |
5de33068 JB |
802 | u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt; |
803 | u32 active_chains; | |
804 | u16 rx_chain; | |
805 | ||
806 | /* Tell uCode which antennas are actually connected. | |
807 | * Before first association, we assume all antennas are connected. | |
808 | * Just after first association, iwl_chain_noise_calibration() | |
809 | * checks which antennas actually *are* connected. */ | |
810 | if (priv->chain_noise_data.active_chains) | |
811 | active_chains = priv->chain_noise_data.active_chains; | |
812 | else | |
9e295116 | 813 | active_chains = priv->hw_params.valid_rx_ant; |
5de33068 | 814 | |
38622419 DF |
815 | if (cfg(priv)->bt_params && |
816 | cfg(priv)->bt_params->advanced_bt_coexist && | |
5de33068 JB |
817 | (priv->bt_full_concurrent || |
818 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)) { | |
819 | /* | |
820 | * only use chain 'A' in bt high traffic load or | |
821 | * full concurrency mode | |
822 | */ | |
823 | active_chains = first_antenna(active_chains); | |
824 | } | |
825 | ||
826 | rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS; | |
827 | ||
828 | /* How many receivers should we use? */ | |
829 | active_rx_cnt = iwl_get_active_rx_chain_count(priv); | |
830 | idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt); | |
831 | ||
832 | ||
833 | /* correct rx chain count according hw settings | |
834 | * and chain noise calibration | |
835 | */ | |
836 | valid_rx_cnt = iwl_count_chain_bitmap(active_chains); | |
837 | if (valid_rx_cnt < active_rx_cnt) | |
838 | active_rx_cnt = valid_rx_cnt; | |
839 | ||
840 | if (valid_rx_cnt < idle_rx_cnt) | |
841 | idle_rx_cnt = valid_rx_cnt; | |
842 | ||
843 | rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; | |
844 | rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; | |
845 | ||
846 | ctx->staging.rx_chain = cpu_to_le16(rx_chain); | |
847 | ||
848 | if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam) | |
849 | ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; | |
850 | else | |
851 | ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; | |
852 | ||
853 | IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n", | |
854 | ctx->staging.rx_chain, | |
855 | active_rx_cnt, idle_rx_cnt); | |
856 | ||
857 | WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || | |
858 | active_rx_cnt < idle_rx_cnt); | |
859 | } | |
facd982e JB |
860 | |
861 | u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid) | |
862 | { | |
863 | int i; | |
864 | u8 ind = ant; | |
865 | ||
866 | if (priv->band == IEEE80211_BAND_2GHZ && | |
867 | priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH) | |
868 | return 0; | |
869 | ||
870 | for (i = 0; i < RATE_ANT_NUM - 1; i++) { | |
871 | ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0; | |
872 | if (valid & BIT(ind)) | |
873 | return ind; | |
874 | } | |
875 | return ant; | |
876 | } | |
fed73292 | 877 | |
023ca58f WYG |
878 | #ifdef CONFIG_PM_SLEEP |
879 | static void iwlagn_convert_p1k(u16 *p1k, __le16 *out) | |
880 | { | |
881 | int i; | |
882 | ||
883 | for (i = 0; i < IWLAGN_P1K_SIZE; i++) | |
884 | out[i] = cpu_to_le16(p1k[i]); | |
885 | } | |
886 | ||
887 | struct wowlan_key_data { | |
888 | struct iwl_rxon_context *ctx; | |
889 | struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc; | |
890 | struct iwlagn_wowlan_tkip_params_cmd *tkip; | |
891 | const u8 *bssid; | |
892 | bool error, use_rsc_tsc, use_tkip; | |
893 | }; | |
894 | ||
895 | ||
896 | static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw, | |
897 | struct ieee80211_vif *vif, | |
898 | struct ieee80211_sta *sta, | |
899 | struct ieee80211_key_conf *key, | |
900 | void *_data) | |
901 | { | |
d0f76d68 | 902 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
023ca58f WYG |
903 | struct wowlan_key_data *data = _data; |
904 | struct iwl_rxon_context *ctx = data->ctx; | |
905 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; | |
906 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; | |
907 | struct iwlagn_p1k_cache *rx_p1ks; | |
908 | u8 *rx_mic_key; | |
909 | struct ieee80211_key_seq seq; | |
910 | u32 cur_rx_iv32 = 0; | |
911 | u16 p1k[IWLAGN_P1K_SIZE]; | |
912 | int ret, i; | |
913 | ||
b1eea297 | 914 | mutex_lock(&priv->mutex); |
023ca58f WYG |
915 | |
916 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
917 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && | |
918 | !sta && !ctx->key_mapping_keys) | |
919 | ret = iwl_set_default_wep_key(priv, ctx, key); | |
920 | else | |
921 | ret = iwl_set_dynamic_key(priv, ctx, key, sta); | |
922 | ||
923 | if (ret) { | |
924 | IWL_ERR(priv, "Error setting key during suspend!\n"); | |
925 | data->error = true; | |
926 | } | |
927 | ||
928 | switch (key->cipher) { | |
929 | case WLAN_CIPHER_SUITE_TKIP: | |
930 | if (sta) { | |
931 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; | |
932 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; | |
933 | ||
934 | rx_p1ks = data->tkip->rx_uni; | |
935 | ||
936 | ieee80211_get_key_tx_seq(key, &seq); | |
937 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); | |
938 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); | |
939 | ||
940 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); | |
941 | iwlagn_convert_p1k(p1k, data->tkip->tx.p1k); | |
942 | ||
943 | memcpy(data->tkip->mic_keys.tx, | |
944 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], | |
945 | IWLAGN_MIC_KEY_SIZE); | |
946 | ||
947 | rx_mic_key = data->tkip->mic_keys.rx_unicast; | |
948 | } else { | |
949 | tkip_sc = | |
950 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; | |
951 | rx_p1ks = data->tkip->rx_multi; | |
952 | rx_mic_key = data->tkip->mic_keys.rx_mcast; | |
953 | } | |
954 | ||
955 | /* | |
956 | * For non-QoS this relies on the fact that both the uCode and | |
957 | * mac80211 use TID 0 (as they need to to avoid replay attacks) | |
958 | * for checking the IV in the frames. | |
959 | */ | |
960 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { | |
961 | ieee80211_get_key_rx_seq(key, i, &seq); | |
962 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); | |
963 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); | |
964 | /* wrapping isn't allowed, AP must rekey */ | |
965 | if (seq.tkip.iv32 > cur_rx_iv32) | |
966 | cur_rx_iv32 = seq.tkip.iv32; | |
967 | } | |
968 | ||
969 | ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k); | |
970 | iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k); | |
971 | ieee80211_get_tkip_rx_p1k(key, data->bssid, | |
972 | cur_rx_iv32 + 1, p1k); | |
973 | iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k); | |
974 | ||
975 | memcpy(rx_mic_key, | |
976 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], | |
977 | IWLAGN_MIC_KEY_SIZE); | |
978 | ||
979 | data->use_tkip = true; | |
980 | data->use_rsc_tsc = true; | |
981 | break; | |
982 | case WLAN_CIPHER_SUITE_CCMP: | |
983 | if (sta) { | |
984 | u8 *pn = seq.ccmp.pn; | |
985 | ||
986 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; | |
987 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; | |
988 | ||
989 | ieee80211_get_key_tx_seq(key, &seq); | |
990 | aes_tx_sc->pn = cpu_to_le64( | |
991 | (u64)pn[5] | | |
992 | ((u64)pn[4] << 8) | | |
993 | ((u64)pn[3] << 16) | | |
994 | ((u64)pn[2] << 24) | | |
995 | ((u64)pn[1] << 32) | | |
996 | ((u64)pn[0] << 40)); | |
997 | } else | |
998 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; | |
999 | ||
1000 | /* | |
1001 | * For non-QoS this relies on the fact that both the uCode and | |
1002 | * mac80211 use TID 0 for checking the IV in the frames. | |
1003 | */ | |
1004 | for (i = 0; i < IWLAGN_NUM_RSC; i++) { | |
1005 | u8 *pn = seq.ccmp.pn; | |
1006 | ||
1007 | ieee80211_get_key_rx_seq(key, i, &seq); | |
1008 | aes_sc->pn = cpu_to_le64( | |
1009 | (u64)pn[5] | | |
1010 | ((u64)pn[4] << 8) | | |
1011 | ((u64)pn[3] << 16) | | |
1012 | ((u64)pn[2] << 24) | | |
1013 | ((u64)pn[1] << 32) | | |
1014 | ((u64)pn[0] << 40)); | |
1015 | } | |
1016 | data->use_rsc_tsc = true; | |
1017 | break; | |
1018 | } | |
1019 | ||
b1eea297 | 1020 | mutex_unlock(&priv->mutex); |
023ca58f WYG |
1021 | } |
1022 | ||
1023 | int iwlagn_send_patterns(struct iwl_priv *priv, | |
1024 | struct cfg80211_wowlan *wowlan) | |
1025 | { | |
1026 | struct iwlagn_wowlan_patterns_cmd *pattern_cmd; | |
1027 | struct iwl_host_cmd cmd = { | |
1028 | .id = REPLY_WOWLAN_PATTERNS, | |
1029 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
1030 | .flags = CMD_SYNC, | |
1031 | }; | |
1032 | int i, err; | |
1033 | ||
1034 | if (!wowlan->n_patterns) | |
1035 | return 0; | |
1036 | ||
1037 | cmd.len[0] = sizeof(*pattern_cmd) + | |
1038 | wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern); | |
1039 | ||
1040 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); | |
1041 | if (!pattern_cmd) | |
1042 | return -ENOMEM; | |
1043 | ||
1044 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); | |
1045 | ||
1046 | for (i = 0; i < wowlan->n_patterns; i++) { | |
1047 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); | |
1048 | ||
1049 | memcpy(&pattern_cmd->patterns[i].mask, | |
1050 | wowlan->patterns[i].mask, mask_len); | |
1051 | memcpy(&pattern_cmd->patterns[i].pattern, | |
1052 | wowlan->patterns[i].pattern, | |
1053 | wowlan->patterns[i].pattern_len); | |
1054 | pattern_cmd->patterns[i].mask_size = mask_len; | |
1055 | pattern_cmd->patterns[i].pattern_size = | |
1056 | wowlan->patterns[i].pattern_len; | |
1057 | } | |
1058 | ||
1059 | cmd.data[0] = pattern_cmd; | |
e10a0533 | 1060 | err = iwl_dvm_send_cmd(priv, &cmd); |
023ca58f WYG |
1061 | kfree(pattern_cmd); |
1062 | return err; | |
1063 | } | |
1064 | ||
ea886a60 | 1065 | int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan) |
023ca58f WYG |
1066 | { |
1067 | struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd; | |
1068 | struct iwl_rxon_cmd rxon; | |
1069 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
1070 | struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd; | |
1071 | struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {}; | |
1072 | struct iwlagn_d3_config_cmd d3_cfg_cmd = {}; | |
1073 | struct wowlan_key_data key_data = { | |
1074 | .ctx = ctx, | |
1075 | .bssid = ctx->active.bssid_addr, | |
1076 | .use_rsc_tsc = false, | |
1077 | .tkip = &tkip_cmd, | |
1078 | .use_tkip = false, | |
1079 | }; | |
1080 | int ret, i; | |
1081 | u16 seq; | |
1082 | ||
1083 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); | |
1084 | if (!key_data.rsc_tsc) | |
1085 | return -ENOMEM; | |
1086 | ||
1087 | memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd)); | |
1088 | ||
1089 | /* | |
1090 | * We know the last used seqno, and the uCode expects to know that | |
1091 | * one, it will increment before TX. | |
1092 | */ | |
1093 | seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ; | |
1094 | wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq); | |
1095 | ||
1096 | /* | |
1097 | * For QoS counters, we store the one to use next, so subtract 0x10 | |
1098 | * since the uCode will add 0x10 before using the value. | |
1099 | */ | |
e0467a30 | 1100 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
04cf6824 | 1101 | seq = priv->tid_data[IWL_AP_ID][i].seq_number; |
023ca58f WYG |
1102 | seq -= 0x10; |
1103 | wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq); | |
1104 | } | |
1105 | ||
1106 | if (wowlan->disconnect) | |
1107 | wakeup_filter_cmd.enabled |= | |
1108 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS | | |
1109 | IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE); | |
1110 | if (wowlan->magic_pkt) | |
1111 | wakeup_filter_cmd.enabled |= | |
1112 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET); | |
1113 | if (wowlan->gtk_rekey_failure) | |
1114 | wakeup_filter_cmd.enabled |= | |
1115 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL); | |
1116 | if (wowlan->eap_identity_req) | |
1117 | wakeup_filter_cmd.enabled |= | |
1118 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ); | |
1119 | if (wowlan->four_way_handshake) | |
1120 | wakeup_filter_cmd.enabled |= | |
1121 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE); | |
1122 | if (wowlan->n_patterns) | |
1123 | wakeup_filter_cmd.enabled |= | |
1124 | cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH); | |
1125 | ||
1126 | if (wowlan->rfkill_release) | |
1127 | d3_cfg_cmd.wakeup_flags |= | |
1128 | cpu_to_le32(IWLAGN_D3_WAKEUP_RFKILL); | |
1129 | ||
1130 | iwl_scan_cancel_timeout(priv, 200); | |
1131 | ||
1132 | memcpy(&rxon, &ctx->active, sizeof(rxon)); | |
1133 | ||
8f7ffbe2 | 1134 | priv->ucode_loaded = false; |
023ca58f WYG |
1135 | iwl_trans_stop_device(trans(priv)); |
1136 | ||
15b86bff | 1137 | priv->wowlan = true; |
023ca58f | 1138 | |
e1991885 | 1139 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN); |
023ca58f WYG |
1140 | if (ret) |
1141 | goto out; | |
1142 | ||
1143 | /* now configure WoWLAN ucode */ | |
1144 | ret = iwl_alive_start(priv); | |
1145 | if (ret) | |
1146 | goto out; | |
1147 | ||
1148 | memcpy(&ctx->staging, &rxon, sizeof(rxon)); | |
1149 | ret = iwlagn_commit_rxon(priv, ctx); | |
1150 | if (ret) | |
1151 | goto out; | |
1152 | ||
1153 | ret = iwl_power_update_mode(priv, true); | |
1154 | if (ret) | |
1155 | goto out; | |
1156 | ||
1157 | if (!iwlagn_mod_params.sw_crypto) { | |
1158 | /* mark all keys clear */ | |
1159 | priv->ucode_key_table = 0; | |
1160 | ctx->key_mapping_keys = 0; | |
1161 | ||
1162 | /* | |
1163 | * This needs to be unlocked due to lock ordering | |
1164 | * constraints. Since we're in the suspend path | |
1165 | * that isn't really a problem though. | |
1166 | */ | |
b1eea297 | 1167 | mutex_unlock(&priv->mutex); |
023ca58f WYG |
1168 | ieee80211_iter_keys(priv->hw, ctx->vif, |
1169 | iwlagn_wowlan_program_keys, | |
1170 | &key_data); | |
b1eea297 | 1171 | mutex_lock(&priv->mutex); |
023ca58f WYG |
1172 | if (key_data.error) { |
1173 | ret = -EIO; | |
1174 | goto out; | |
1175 | } | |
1176 | ||
1177 | if (key_data.use_rsc_tsc) { | |
1178 | struct iwl_host_cmd rsc_tsc_cmd = { | |
1179 | .id = REPLY_WOWLAN_TSC_RSC_PARAMS, | |
1180 | .flags = CMD_SYNC, | |
1181 | .data[0] = key_data.rsc_tsc, | |
1182 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
182ada1c | 1183 | .len[0] = sizeof(*key_data.rsc_tsc), |
023ca58f WYG |
1184 | }; |
1185 | ||
e10a0533 | 1186 | ret = iwl_dvm_send_cmd(priv, &rsc_tsc_cmd); |
023ca58f WYG |
1187 | if (ret) |
1188 | goto out; | |
1189 | } | |
1190 | ||
1191 | if (key_data.use_tkip) { | |
e10a0533 | 1192 | ret = iwl_dvm_send_cmd_pdu(priv, |
023ca58f WYG |
1193 | REPLY_WOWLAN_TKIP_PARAMS, |
1194 | CMD_SYNC, sizeof(tkip_cmd), | |
1195 | &tkip_cmd); | |
1196 | if (ret) | |
1197 | goto out; | |
1198 | } | |
1199 | ||
1200 | if (priv->have_rekey_data) { | |
1201 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); | |
1202 | memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN); | |
1203 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); | |
1204 | memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN); | |
1205 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); | |
1206 | kek_kck_cmd.replay_ctr = priv->replay_ctr; | |
1207 | ||
e10a0533 | 1208 | ret = iwl_dvm_send_cmd_pdu(priv, |
023ca58f WYG |
1209 | REPLY_WOWLAN_KEK_KCK_MATERIAL, |
1210 | CMD_SYNC, sizeof(kek_kck_cmd), | |
1211 | &kek_kck_cmd); | |
1212 | if (ret) | |
1213 | goto out; | |
1214 | } | |
1215 | } | |
1216 | ||
e10a0533 | 1217 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_D3_CONFIG, CMD_SYNC, |
023ca58f WYG |
1218 | sizeof(d3_cfg_cmd), &d3_cfg_cmd); |
1219 | if (ret) | |
1220 | goto out; | |
1221 | ||
e10a0533 | 1222 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WOWLAN_WAKEUP_FILTER, |
023ca58f WYG |
1223 | CMD_SYNC, sizeof(wakeup_filter_cmd), |
1224 | &wakeup_filter_cmd); | |
1225 | if (ret) | |
1226 | goto out; | |
1227 | ||
1228 | ret = iwlagn_send_patterns(priv, wowlan); | |
1229 | out: | |
1230 | kfree(key_data.rsc_tsc); | |
1231 | return ret; | |
1232 | } | |
1233 | #endif | |
e10a0533 JB |
1234 | |
1235 | int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) | |
1236 | { | |
83626404 | 1237 | if (iwl_is_rfkill(priv) || iwl_is_ctkill(priv)) { |
721c32f7 | 1238 | IWL_WARN(priv, "Not sending command - %s KILL\n", |
83626404 | 1239 | iwl_is_rfkill(priv) ? "RF" : "CT"); |
721c32f7 JB |
1240 | return -EIO; |
1241 | } | |
1242 | ||
17acd0b6 DF |
1243 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
1244 | IWL_ERR(priv, "Command %s failed: FW Error\n", | |
1245 | get_cmd_string(cmd->id)); | |
1246 | return -EIO; | |
1247 | } | |
1248 | ||
2cc39c94 JB |
1249 | /* |
1250 | * Synchronous commands from this op-mode must hold | |
1251 | * the mutex, this ensures we don't try to send two | |
1252 | * (or more) synchronous commands at a time. | |
1253 | */ | |
1254 | if (cmd->flags & CMD_SYNC) | |
b1eea297 | 1255 | lockdep_assert_held(&priv->mutex); |
2cc39c94 | 1256 | |
947a9407 JB |
1257 | if (priv->ucode_owner == IWL_OWNERSHIP_TM && |
1258 | !(cmd->flags & CMD_ON_DEMAND)) { | |
1259 | IWL_DEBUG_HC(priv, "tm own the uCode, no regular hcmd send\n"); | |
1260 | return -EIO; | |
1261 | } | |
1262 | ||
e10a0533 JB |
1263 | return iwl_trans_send_cmd(trans(priv), cmd); |
1264 | } | |
1265 | ||
1266 | int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id, | |
1267 | u32 flags, u16 len, const void *data) | |
1268 | { | |
1269 | struct iwl_host_cmd cmd = { | |
1270 | .id = id, | |
1271 | .len = { len, }, | |
1272 | .data = { data, }, | |
1273 | .flags = flags, | |
1274 | }; | |
1275 | ||
1276 | return iwl_dvm_send_cmd(priv, &cmd); | |
1277 | } |