Commit | Line | Data |
---|---|---|
8ca151b5 JB |
1 | /****************************************************************************** |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8d193ca2 | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
bdccdb85 | 10 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
8ca151b5 JB |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of version 2 of the GNU General Public License as | |
14 | * published by the Free Software Foundation. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
24 | * USA | |
25 | * | |
26 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 27 | * in the file called COPYING. |
8ca151b5 JB |
28 | * |
29 | * Contact Information: | |
cb2f8277 | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
8ca151b5 JB |
31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
32 | * | |
33 | * BSD LICENSE | |
34 | * | |
51368bf7 | 35 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8d193ca2 | 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
bdccdb85 | 37 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
8ca151b5 JB |
38 | * All rights reserved. |
39 | * | |
40 | * Redistribution and use in source and binary forms, with or without | |
41 | * modification, are permitted provided that the following conditions | |
42 | * are met: | |
43 | * | |
44 | * * Redistributions of source code must retain the above copyright | |
45 | * notice, this list of conditions and the following disclaimer. | |
46 | * * Redistributions in binary form must reproduce the above copyright | |
47 | * notice, this list of conditions and the following disclaimer in | |
48 | * the documentation and/or other materials provided with the | |
49 | * distribution. | |
50 | * * Neither the name Intel Corporation nor the names of its | |
51 | * contributors may be used to endorse or promote products derived | |
52 | * from this software without specific prior written permission. | |
53 | * | |
54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
65 | * | |
66 | *****************************************************************************/ | |
67 | #include <net/mac80211.h> | |
854d773e | 68 | #include <linux/netdevice.h> |
da2830ac | 69 | #include <linux/acpi.h> |
8ca151b5 JB |
70 | |
71 | #include "iwl-trans.h" | |
72 | #include "iwl-op-mode.h" | |
d962f9b1 | 73 | #include "fw/img.h" |
8ca151b5 JB |
74 | #include "iwl-debug.h" |
75 | #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */ | |
76 | #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */ | |
8c23f95c | 77 | #include "iwl-prph.h" |
8ca151b5 JB |
78 | #include "iwl-eeprom-parse.h" |
79 | ||
80 | #include "mvm.h" | |
2f89a5d7 | 81 | #include "fw-dbg.h" |
8ca151b5 JB |
82 | #include "iwl-phy-db.h" |
83 | ||
84 | #define MVM_UCODE_ALIVE_TIMEOUT HZ | |
85 | #define MVM_UCODE_CALIB_TIMEOUT (2*HZ) | |
86 | ||
87 | #define UCODE_VALID_OK cpu_to_le32(0x1) | |
88 | ||
8ca151b5 JB |
89 | struct iwl_mvm_alive_data { |
90 | bool valid; | |
91 | u32 scd_base_addr; | |
92 | }; | |
93 | ||
8ca151b5 JB |
94 | static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant) |
95 | { | |
96 | struct iwl_tx_ant_cfg_cmd tx_ant_cmd = { | |
97 | .valid = cpu_to_le32(valid_tx_ant), | |
98 | }; | |
99 | ||
33223542 | 100 | IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant); |
a1022927 | 101 | return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0, |
8ca151b5 JB |
102 | sizeof(tx_ant_cmd), &tx_ant_cmd); |
103 | } | |
104 | ||
43413a97 SS |
105 | static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm) |
106 | { | |
107 | int i; | |
108 | struct iwl_rss_config_cmd cmd = { | |
109 | .flags = cpu_to_le32(IWL_RSS_ENABLE), | |
110 | .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP | | |
854d773e | 111 | IWL_RSS_HASH_TYPE_IPV4_UDP | |
43413a97 SS |
112 | IWL_RSS_HASH_TYPE_IPV4_PAYLOAD | |
113 | IWL_RSS_HASH_TYPE_IPV6_TCP | | |
854d773e | 114 | IWL_RSS_HASH_TYPE_IPV6_UDP | |
43413a97 SS |
115 | IWL_RSS_HASH_TYPE_IPV6_PAYLOAD, |
116 | }; | |
117 | ||
f43495fd SS |
118 | if (mvm->trans->num_rx_queues == 1) |
119 | return 0; | |
120 | ||
854d773e | 121 | /* Do not direct RSS traffic to Q 0 which is our fallback queue */ |
43413a97 | 122 | for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++) |
854d773e SS |
123 | cmd.indirection_table[i] = |
124 | 1 + (i % (mvm->trans->num_rx_queues - 1)); | |
125 | netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key)); | |
43413a97 SS |
126 | |
127 | return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd); | |
128 | } | |
129 | ||
97d5be7e LK |
130 | static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm) |
131 | { | |
132 | struct iwl_dqa_enable_cmd dqa_cmd = { | |
133 | .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE), | |
134 | }; | |
135 | u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0); | |
136 | int ret; | |
137 | ||
138 | ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd); | |
139 | if (ret) | |
140 | IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret); | |
141 | else | |
142 | IWL_DEBUG_FW(mvm, "Working in DQA mode\n"); | |
143 | ||
144 | return ret; | |
145 | } | |
146 | ||
bdccdb85 GBA |
147 | void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm, |
148 | struct iwl_rx_cmd_buffer *rxb) | |
149 | { | |
150 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
151 | struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data; | |
152 | __le32 *dump_data = mfu_dump_notif->data; | |
153 | int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32); | |
154 | int i; | |
155 | ||
156 | if (mfu_dump_notif->index_num == 0) | |
157 | IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n", | |
158 | le32_to_cpu(mfu_dump_notif->assert_id)); | |
159 | ||
160 | for (i = 0; i < n_words; i++) | |
161 | IWL_DEBUG_INFO(mvm, | |
162 | "MFUART assert dump, dword %u: 0x%08x\n", | |
163 | le16_to_cpu(mfu_dump_notif->index_num) * | |
164 | n_words + i, | |
165 | le32_to_cpu(dump_data[i])); | |
166 | } | |
167 | ||
8ca151b5 JB |
168 | static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, |
169 | struct iwl_rx_packet *pkt, void *data) | |
170 | { | |
171 | struct iwl_mvm *mvm = | |
172 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
173 | struct iwl_mvm_alive_data *alive_data = data; | |
5c228d63 | 174 | struct mvm_alive_resp_v3 *palive3; |
7e1223b5 | 175 | struct mvm_alive_resp *palive; |
5c228d63 SS |
176 | struct iwl_umac_alive *umac; |
177 | struct iwl_lmac_alive *lmac1; | |
178 | struct iwl_lmac_alive *lmac2 = NULL; | |
179 | u16 status; | |
01a9ca51 | 180 | |
5c228d63 SS |
181 | if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) { |
182 | palive = (void *)pkt->data; | |
183 | umac = &palive->umac_data; | |
184 | lmac1 = &palive->lmac_data[0]; | |
185 | lmac2 = &palive->lmac_data[1]; | |
186 | status = le16_to_cpu(palive->status); | |
187 | } else { | |
188 | palive3 = (void *)pkt->data; | |
189 | umac = &palive3->umac_data; | |
190 | lmac1 = &palive3->lmac_data; | |
191 | status = le16_to_cpu(palive3->status); | |
192 | } | |
01a9ca51 | 193 | |
5c228d63 SS |
194 | mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr); |
195 | if (lmac2) | |
196 | mvm->error_event_table[1] = | |
197 | le32_to_cpu(lmac2->error_event_table_ptr); | |
198 | mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr); | |
199 | mvm->sf_space.addr = le32_to_cpu(lmac1->st_fwrd_addr); | |
200 | mvm->sf_space.size = le32_to_cpu(lmac1->st_fwrd_size); | |
ffa70264 | 201 | |
5c228d63 | 202 | mvm->umac_error_event_table = le32_to_cpu(umac->error_info_addr); |
01a9ca51 | 203 | |
5c228d63 SS |
204 | alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr); |
205 | alive_data->valid = status == IWL_ALIVE_STATUS_OK; | |
206 | if (mvm->umac_error_event_table) | |
207 | mvm->support_umac_log = true; | |
7e1223b5 | 208 | |
5c228d63 SS |
209 | IWL_DEBUG_FW(mvm, |
210 | "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n", | |
211 | status, lmac1->ver_type, lmac1->ver_subtype); | |
7e1223b5 | 212 | |
5c228d63 SS |
213 | if (lmac2) |
214 | IWL_DEBUG_FW(mvm, "Alive ucode CDB\n"); | |
7e1223b5 | 215 | |
5c228d63 SS |
216 | IWL_DEBUG_FW(mvm, |
217 | "UMAC version: Major - 0x%x, Minor - 0x%x\n", | |
218 | le32_to_cpu(umac->umac_major), | |
219 | le32_to_cpu(umac->umac_minor)); | |
8ca151b5 JB |
220 | |
221 | return true; | |
222 | } | |
223 | ||
1f370650 SS |
224 | static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait, |
225 | struct iwl_rx_packet *pkt, void *data) | |
226 | { | |
227 | WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); | |
228 | ||
229 | return true; | |
230 | } | |
231 | ||
8ca151b5 JB |
232 | static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait, |
233 | struct iwl_rx_packet *pkt, void *data) | |
234 | { | |
235 | struct iwl_phy_db *phy_db = data; | |
236 | ||
237 | if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) { | |
238 | WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); | |
239 | return true; | |
240 | } | |
241 | ||
ce1f2778 | 242 | WARN_ON(iwl_phy_db_set_section(phy_db, pkt)); |
8ca151b5 JB |
243 | |
244 | return false; | |
245 | } | |
246 | ||
247 | static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, | |
248 | enum iwl_ucode_type ucode_type) | |
249 | { | |
250 | struct iwl_notification_wait alive_wait; | |
251 | struct iwl_mvm_alive_data alive_data; | |
252 | const struct fw_img *fw; | |
253 | int ret, i; | |
254 | enum iwl_ucode_type old_type = mvm->cur_ucode; | |
6eb031d2 | 255 | static const u16 alive_cmd[] = { MVM_ALIVE }; |
91479b64 | 256 | struct iwl_sf_region st_fwrd_space; |
8ca151b5 | 257 | |
61df750c | 258 | if (ucode_type == IWL_UCODE_REGULAR && |
3d2d4422 GBA |
259 | iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) && |
260 | !(fw_has_capa(&mvm->fw->ucode_capa, | |
261 | IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED))) | |
612da1ef | 262 | fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER); |
61df750c | 263 | else |
612da1ef | 264 | fw = iwl_get_ucode_image(mvm->fw, ucode_type); |
befe9b6f | 265 | if (WARN_ON(!fw)) |
8ca151b5 | 266 | return -EINVAL; |
befe9b6f | 267 | mvm->cur_ucode = ucode_type; |
65b280fe | 268 | clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); |
8ca151b5 JB |
269 | |
270 | iwl_init_notification_wait(&mvm->notif_wait, &alive_wait, | |
271 | alive_cmd, ARRAY_SIZE(alive_cmd), | |
272 | iwl_alive_fn, &alive_data); | |
273 | ||
274 | ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT); | |
275 | if (ret) { | |
276 | mvm->cur_ucode = old_type; | |
277 | iwl_remove_notification(&mvm->notif_wait, &alive_wait); | |
278 | return ret; | |
279 | } | |
280 | ||
281 | /* | |
282 | * Some things may run in the background now, but we | |
283 | * just wait for the ALIVE notification here. | |
284 | */ | |
285 | ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait, | |
286 | MVM_UCODE_ALIVE_TIMEOUT); | |
287 | if (ret) { | |
d6be9c1d SS |
288 | struct iwl_trans *trans = mvm->trans; |
289 | ||
6e584873 | 290 | if (trans->cfg->device_family == IWL_DEVICE_FAMILY_A000) |
d6be9c1d SS |
291 | IWL_ERR(mvm, |
292 | "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", | |
293 | iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS), | |
294 | iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS)); | |
6e584873 | 295 | else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000) |
192de2b4 DS |
296 | IWL_ERR(mvm, |
297 | "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", | |
d6be9c1d SS |
298 | iwl_read_prph(trans, SB_CPU_1_STATUS), |
299 | iwl_read_prph(trans, SB_CPU_2_STATUS)); | |
8ca151b5 JB |
300 | mvm->cur_ucode = old_type; |
301 | return ret; | |
302 | } | |
303 | ||
304 | if (!alive_data.valid) { | |
305 | IWL_ERR(mvm, "Loaded ucode is not valid!\n"); | |
306 | mvm->cur_ucode = old_type; | |
307 | return -EIO; | |
308 | } | |
309 | ||
91479b64 EH |
310 | /* |
311 | * update the sdio allocation according to the pointer we get in the | |
312 | * alive notification. | |
313 | */ | |
314 | st_fwrd_space.addr = mvm->sf_space.addr; | |
315 | st_fwrd_space.size = mvm->sf_space.size; | |
316 | ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space); | |
82e8aea0 ES |
317 | if (ret) { |
318 | IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret); | |
319 | return ret; | |
320 | } | |
91479b64 | 321 | |
8ca151b5 JB |
322 | iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr); |
323 | ||
324 | /* | |
325 | * Note: all the queues are enabled as part of the interface | |
326 | * initialization, but in firmware restart scenarios they | |
327 | * could be stopped, so wake them up. In firmware restart, | |
328 | * mac80211 will have the queues stopped as well until the | |
329 | * reconfiguration completes. During normal startup, they | |
330 | * will be empty. | |
331 | */ | |
332 | ||
4ecafae9 | 333 | memset(&mvm->queue_info, 0, sizeof(mvm->queue_info)); |
097129c9 LK |
334 | if (iwl_mvm_is_dqa_supported(mvm)) |
335 | mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1; | |
336 | else | |
337 | mvm->queue_info[IWL_MVM_CMD_QUEUE].hw_queue_refcount = 1; | |
8ca151b5 | 338 | |
df197c00 JB |
339 | for (i = 0; i < IEEE80211_MAX_QUEUES; i++) |
340 | atomic_set(&mvm->mac80211_queue_stop_count[i], 0); | |
8ca151b5 | 341 | |
65b280fe | 342 | set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); |
8ca151b5 JB |
343 | |
344 | return 0; | |
345 | } | |
8ca151b5 | 346 | |
8c5f47b1 JB |
347 | static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) |
348 | { | |
349 | struct iwl_notification_wait init_wait; | |
350 | struct iwl_nvm_access_complete_cmd nvm_complete = {}; | |
351 | struct iwl_init_extended_cfg_cmd init_cfg = { | |
352 | .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)), | |
353 | }; | |
354 | static const u16 init_complete[] = { | |
355 | INIT_COMPLETE_NOTIF, | |
356 | }; | |
357 | int ret; | |
358 | ||
359 | lockdep_assert_held(&mvm->mutex); | |
360 | ||
361 | iwl_init_notification_wait(&mvm->notif_wait, | |
362 | &init_wait, | |
363 | init_complete, | |
364 | ARRAY_SIZE(init_complete), | |
365 | iwl_wait_init_complete, | |
366 | NULL); | |
367 | ||
368 | /* Will also start the device */ | |
369 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); | |
370 | if (ret) { | |
371 | IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); | |
372 | goto error; | |
373 | } | |
374 | ||
375 | /* Send init config command to mark that we are sending NVM access | |
376 | * commands | |
377 | */ | |
378 | ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP, | |
379 | INIT_EXTENDED_CFG_CMD), 0, | |
380 | sizeof(init_cfg), &init_cfg); | |
381 | if (ret) { | |
382 | IWL_ERR(mvm, "Failed to run init config command: %d\n", | |
383 | ret); | |
384 | goto error; | |
385 | } | |
386 | ||
e9e1ba3d SS |
387 | /* Load NVM to NIC if needed */ |
388 | if (mvm->nvm_file_name) { | |
389 | iwl_mvm_read_external_nvm(mvm); | |
8c5f47b1 | 390 | iwl_mvm_load_nvm_to_nic(mvm); |
e9e1ba3d | 391 | } |
8c5f47b1 | 392 | |
d4f3695e SS |
393 | if (IWL_MVM_PARSE_NVM && read_nvm) { |
394 | ret = iwl_nvm_init(mvm, true); | |
395 | if (ret) { | |
396 | IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); | |
397 | goto error; | |
398 | } | |
399 | } | |
400 | ||
8c5f47b1 JB |
401 | ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP, |
402 | NVM_ACCESS_COMPLETE), 0, | |
403 | sizeof(nvm_complete), &nvm_complete); | |
404 | if (ret) { | |
405 | IWL_ERR(mvm, "Failed to run complete NVM access: %d\n", | |
406 | ret); | |
407 | goto error; | |
408 | } | |
409 | ||
410 | /* We wait for the INIT complete notification */ | |
e9e1ba3d SS |
411 | ret = iwl_wait_notification(&mvm->notif_wait, &init_wait, |
412 | MVM_UCODE_ALIVE_TIMEOUT); | |
413 | if (ret) | |
414 | return ret; | |
415 | ||
416 | /* Read the NVM only at driver load time, no need to do this twice */ | |
d4f3695e | 417 | if (!IWL_MVM_PARSE_NVM && read_nvm) { |
e9e1ba3d SS |
418 | ret = iwl_mvm_nvm_get_from_fw(mvm); |
419 | if (ret) { | |
420 | IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); | |
421 | return ret; | |
422 | } | |
423 | } | |
424 | ||
425 | return 0; | |
8c5f47b1 JB |
426 | |
427 | error: | |
428 | iwl_remove_notification(&mvm->notif_wait, &init_wait); | |
429 | return ret; | |
430 | } | |
431 | ||
8ca151b5 JB |
432 | static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm) |
433 | { | |
434 | struct iwl_phy_cfg_cmd phy_cfg_cmd; | |
435 | enum iwl_ucode_type ucode_type = mvm->cur_ucode; | |
436 | ||
437 | /* Set parameters */ | |
a0544272 | 438 | phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm)); |
8ca151b5 JB |
439 | phy_cfg_cmd.calib_control.event_trigger = |
440 | mvm->fw->default_calib[ucode_type].event_trigger; | |
441 | phy_cfg_cmd.calib_control.flow_trigger = | |
442 | mvm->fw->default_calib[ucode_type].flow_trigger; | |
443 | ||
444 | IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n", | |
445 | phy_cfg_cmd.phy_cfg); | |
446 | ||
a1022927 | 447 | return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0, |
8ca151b5 JB |
448 | sizeof(phy_cfg_cmd), &phy_cfg_cmd); |
449 | } | |
450 | ||
8ca151b5 JB |
451 | int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) |
452 | { | |
453 | struct iwl_notification_wait calib_wait; | |
6eb031d2 | 454 | static const u16 init_complete[] = { |
8ca151b5 JB |
455 | INIT_COMPLETE_NOTIF, |
456 | CALIB_RES_NOTIF_PHY_DB | |
457 | }; | |
458 | int ret; | |
459 | ||
8c5f47b1 JB |
460 | if (iwl_mvm_has_new_tx_api(mvm)) |
461 | return iwl_run_unified_mvm_ucode(mvm, true); | |
462 | ||
8ca151b5 JB |
463 | lockdep_assert_held(&mvm->mutex); |
464 | ||
8d193ca2 | 465 | if (WARN_ON_ONCE(mvm->calibrating)) |
8ca151b5 JB |
466 | return 0; |
467 | ||
468 | iwl_init_notification_wait(&mvm->notif_wait, | |
469 | &calib_wait, | |
470 | init_complete, | |
471 | ARRAY_SIZE(init_complete), | |
472 | iwl_wait_phy_db_entry, | |
473 | mvm->phy_db); | |
474 | ||
475 | /* Will also start the device */ | |
476 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT); | |
477 | if (ret) { | |
478 | IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret); | |
479 | goto error; | |
480 | } | |
481 | ||
b3de3ef4 EG |
482 | if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) { |
483 | ret = iwl_mvm_send_bt_init_conf(mvm); | |
484 | if (ret) | |
485 | goto error; | |
486 | } | |
931d4160 | 487 | |
81a67e32 | 488 | /* Read the NVM only at driver load time, no need to do this twice */ |
8ca151b5 JB |
489 | if (read_nvm) { |
490 | /* Read nvm */ | |
14b485f0 | 491 | ret = iwl_nvm_init(mvm, true); |
8ca151b5 JB |
492 | if (ret) { |
493 | IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); | |
494 | goto error; | |
495 | } | |
496 | } | |
497 | ||
81a67e32 | 498 | /* In case we read the NVM from external file, load it to the NIC */ |
e02a9d60 | 499 | if (mvm->nvm_file_name) |
81a67e32 EL |
500 | iwl_mvm_load_nvm_to_nic(mvm); |
501 | ||
8ca151b5 JB |
502 | ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans); |
503 | WARN_ON(ret); | |
504 | ||
4f59334b EH |
505 | /* |
506 | * abort after reading the nvm in case RF Kill is on, we will complete | |
507 | * the init seq later when RF kill will switch to off | |
508 | */ | |
1a3fe0b2 | 509 | if (iwl_mvm_is_radio_hw_killed(mvm)) { |
4f59334b EH |
510 | IWL_DEBUG_RF_KILL(mvm, |
511 | "jump over all phy activities due to RF kill\n"); | |
512 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); | |
a4082843 AN |
513 | ret = 1; |
514 | goto out; | |
4f59334b EH |
515 | } |
516 | ||
31b8b343 EG |
517 | mvm->calibrating = true; |
518 | ||
e07cbb53 | 519 | /* Send TX valid antennas before triggering calibrations */ |
a0544272 | 520 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
e07cbb53 DS |
521 | if (ret) |
522 | goto error; | |
523 | ||
8ca151b5 JB |
524 | /* |
525 | * Send phy configurations command to init uCode | |
526 | * to start the 16.0 uCode init image internal calibrations. | |
527 | */ | |
528 | ret = iwl_send_phy_cfg_cmd(mvm); | |
529 | if (ret) { | |
530 | IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n", | |
531 | ret); | |
532 | goto error; | |
533 | } | |
534 | ||
535 | /* | |
536 | * Some things may run in the background now, but we | |
537 | * just wait for the calibration complete notification. | |
538 | */ | |
539 | ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait, | |
540 | MVM_UCODE_CALIB_TIMEOUT); | |
31b8b343 | 541 | |
1a3fe0b2 | 542 | if (ret && iwl_mvm_is_radio_hw_killed(mvm)) { |
31b8b343 EG |
543 | IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n"); |
544 | ret = 1; | |
545 | } | |
8ca151b5 JB |
546 | goto out; |
547 | ||
548 | error: | |
549 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); | |
550 | out: | |
31b8b343 | 551 | mvm->calibrating = false; |
a4082843 | 552 | if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) { |
8ca151b5 JB |
553 | /* we want to debug INIT and we have no NVM - fake */ |
554 | mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) + | |
555 | sizeof(struct ieee80211_channel) + | |
556 | sizeof(struct ieee80211_rate), | |
557 | GFP_KERNEL); | |
558 | if (!mvm->nvm_data) | |
559 | return -ENOMEM; | |
8ca151b5 JB |
560 | mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels; |
561 | mvm->nvm_data->bands[0].n_channels = 1; | |
562 | mvm->nvm_data->bands[0].n_bitrates = 1; | |
563 | mvm->nvm_data->bands[0].bitrates = | |
564 | (void *)mvm->nvm_data->channels + 1; | |
565 | mvm->nvm_data->bands[0].bitrates->hw_value = 10; | |
566 | } | |
567 | ||
568 | return ret; | |
569 | } | |
570 | ||
84bfffa9 EG |
571 | static int iwl_mvm_config_ltr(struct iwl_mvm *mvm) |
572 | { | |
573 | struct iwl_ltr_config_cmd cmd = { | |
574 | .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE), | |
575 | }; | |
576 | ||
577 | if (!mvm->trans->ltr_enabled) | |
578 | return 0; | |
579 | ||
84bfffa9 EG |
580 | return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, |
581 | sizeof(cmd), &cmd); | |
582 | } | |
583 | ||
c386dacb HD |
584 | #ifdef CONFIG_ACPI |
585 | #define ACPI_WRDS_METHOD "WRDS" | |
69964905 | 586 | #define ACPI_EWRD_METHOD "EWRD" |
a6bff3cb | 587 | #define ACPI_WGDS_METHOD "WGDS" |
69964905 | 588 | #define ACPI_WIFI_DOMAIN (0x07) |
c386dacb | 589 | #define ACPI_WRDS_WIFI_DATA_SIZE (IWL_MVM_SAR_TABLE_SIZE + 2) |
69964905 LC |
590 | #define ACPI_EWRD_WIFI_DATA_SIZE ((IWL_MVM_SAR_PROFILE_NUM - 1) * \ |
591 | IWL_MVM_SAR_TABLE_SIZE + 3) | |
a6bff3cb HD |
592 | #define ACPI_WGDS_WIFI_DATA_SIZE 18 |
593 | #define ACPI_WGDS_NUM_BANDS 2 | |
594 | #define ACPI_WGDS_TABLE_SIZE 3 | |
c386dacb HD |
595 | |
596 | static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm, | |
597 | union acpi_object *table, | |
598 | struct iwl_mvm_sar_profile *profile, | |
599 | bool enabled) | |
600 | { | |
601 | int i; | |
da2830ac | 602 | |
c386dacb | 603 | profile->enabled = enabled; |
da2830ac | 604 | |
c386dacb HD |
605 | for (i = 0; i < IWL_MVM_SAR_TABLE_SIZE; i++) { |
606 | if ((table[i].type != ACPI_TYPE_INTEGER) || | |
607 | (table[i].integer.value > U8_MAX)) | |
608 | return -EINVAL; | |
609 | ||
610 | profile->table[i] = table[i].integer.value; | |
611 | } | |
612 | ||
613 | return 0; | |
614 | } | |
615 | ||
616 | static union acpi_object *iwl_mvm_sar_find_wifi_pkg(struct iwl_mvm *mvm, | |
617 | union acpi_object *data, | |
618 | int data_size) | |
da2830ac | 619 | { |
c386dacb HD |
620 | int i; |
621 | union acpi_object *wifi_pkg; | |
da2830ac | 622 | |
c386dacb HD |
623 | /* |
624 | * We need at least two packages, one for the revision and one | |
da2830ac LC |
625 | * for the data itself. Also check that the revision is valid |
626 | * (i.e. it is an integer set to 0). | |
c386dacb HD |
627 | */ |
628 | if (data->type != ACPI_TYPE_PACKAGE || | |
629 | data->package.count < 2 || | |
630 | data->package.elements[0].type != ACPI_TYPE_INTEGER || | |
631 | data->package.elements[0].integer.value != 0) { | |
632 | IWL_DEBUG_RADIO(mvm, "Unsupported packages structure\n"); | |
633 | return ERR_PTR(-EINVAL); | |
da2830ac LC |
634 | } |
635 | ||
636 | /* loop through all the packages to find the one for WiFi */ | |
c386dacb | 637 | for (i = 1; i < data->package.count; i++) { |
da2830ac LC |
638 | union acpi_object *domain; |
639 | ||
c386dacb | 640 | wifi_pkg = &data->package.elements[i]; |
da2830ac LC |
641 | |
642 | /* Skip anything that is not a package with the right | |
643 | * amount of elements (i.e. domain_type, | |
c386dacb | 644 | * enabled/disabled plus the actual data size. |
da2830ac | 645 | */ |
c386dacb HD |
646 | if (wifi_pkg->type != ACPI_TYPE_PACKAGE || |
647 | wifi_pkg->package.count != data_size) | |
da2830ac LC |
648 | continue; |
649 | ||
c386dacb | 650 | domain = &wifi_pkg->package.elements[0]; |
da2830ac | 651 | if (domain->type == ACPI_TYPE_INTEGER && |
69964905 | 652 | domain->integer.value == ACPI_WIFI_DOMAIN) |
da2830ac LC |
653 | break; |
654 | ||
c386dacb | 655 | wifi_pkg = NULL; |
da2830ac LC |
656 | } |
657 | ||
c386dacb HD |
658 | if (!wifi_pkg) |
659 | return ERR_PTR(-ENOENT); | |
da2830ac | 660 | |
c386dacb | 661 | return wifi_pkg; |
da2830ac LC |
662 | } |
663 | ||
c386dacb | 664 | static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm) |
da2830ac | 665 | { |
c386dacb | 666 | union acpi_object *wifi_pkg, *table; |
da2830ac LC |
667 | acpi_handle root_handle; |
668 | acpi_handle handle; | |
669 | struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL}; | |
670 | acpi_status status; | |
c386dacb | 671 | bool enabled; |
da2830ac LC |
672 | int ret; |
673 | ||
674 | root_handle = ACPI_HANDLE(mvm->dev); | |
675 | if (!root_handle) { | |
676 | IWL_DEBUG_RADIO(mvm, | |
677 | "Could not retrieve root port ACPI handle\n"); | |
678 | return -ENOENT; | |
679 | } | |
680 | ||
681 | /* Get the method's handle */ | |
682 | status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD, | |
683 | &handle); | |
684 | if (ACPI_FAILURE(status)) { | |
685 | IWL_DEBUG_RADIO(mvm, "WRDS method not found\n"); | |
686 | return -ENOENT; | |
687 | } | |
688 | ||
689 | /* Call WRDS with no arguments */ | |
690 | status = acpi_evaluate_object(handle, NULL, NULL, &wrds); | |
691 | if (ACPI_FAILURE(status)) { | |
692 | IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status); | |
693 | return -ENOENT; | |
694 | } | |
695 | ||
c386dacb HD |
696 | wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, wrds.pointer, |
697 | ACPI_WRDS_WIFI_DATA_SIZE); | |
698 | if (IS_ERR(wifi_pkg)) { | |
699 | ret = PTR_ERR(wifi_pkg); | |
700 | goto out_free; | |
701 | } | |
702 | ||
703 | if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) { | |
704 | ret = -EINVAL; | |
705 | goto out_free; | |
706 | } | |
707 | ||
708 | enabled = !!(wifi_pkg->package.elements[1].integer.value); | |
da2830ac | 709 | |
c386dacb HD |
710 | /* position of the actual table */ |
711 | table = &wifi_pkg->package.elements[2]; | |
712 | ||
713 | /* The profile from WRDS is officially profile 1, but goes | |
714 | * into sar_profiles[0] (because we don't have a profile 0). | |
715 | */ | |
716 | ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0], | |
717 | enabled); | |
718 | ||
719 | out_free: | |
720 | kfree(wrds.pointer); | |
da2830ac LC |
721 | return ret; |
722 | } | |
da2830ac | 723 | |
69964905 LC |
724 | static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm) |
725 | { | |
726 | union acpi_object *wifi_pkg; | |
727 | acpi_handle root_handle; | |
728 | acpi_handle handle; | |
729 | struct acpi_buffer ewrd = {ACPI_ALLOCATE_BUFFER, NULL}; | |
730 | acpi_status status; | |
731 | bool enabled; | |
732 | int i, n_profiles, ret; | |
733 | ||
734 | root_handle = ACPI_HANDLE(mvm->dev); | |
735 | if (!root_handle) { | |
736 | IWL_DEBUG_RADIO(mvm, | |
737 | "Could not retrieve root port ACPI handle\n"); | |
738 | return -ENOENT; | |
739 | } | |
740 | ||
741 | /* Get the method's handle */ | |
742 | status = acpi_get_handle(root_handle, (acpi_string)ACPI_EWRD_METHOD, | |
743 | &handle); | |
744 | if (ACPI_FAILURE(status)) { | |
745 | IWL_DEBUG_RADIO(mvm, "EWRD method not found\n"); | |
746 | return -ENOENT; | |
747 | } | |
748 | ||
749 | /* Call EWRD with no arguments */ | |
750 | status = acpi_evaluate_object(handle, NULL, NULL, &ewrd); | |
751 | if (ACPI_FAILURE(status)) { | |
752 | IWL_DEBUG_RADIO(mvm, "EWRD invocation failed (0x%x)\n", status); | |
753 | return -ENOENT; | |
754 | } | |
755 | ||
756 | wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, ewrd.pointer, | |
757 | ACPI_EWRD_WIFI_DATA_SIZE); | |
758 | if (IS_ERR(wifi_pkg)) { | |
759 | ret = PTR_ERR(wifi_pkg); | |
760 | goto out_free; | |
761 | } | |
762 | ||
763 | if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) || | |
764 | (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) { | |
765 | ret = -EINVAL; | |
766 | goto out_free; | |
767 | } | |
768 | ||
769 | enabled = !!(wifi_pkg->package.elements[1].integer.value); | |
770 | n_profiles = wifi_pkg->package.elements[2].integer.value; | |
771 | ||
e2ef1476 SD |
772 | /* in case of BIOS bug */ |
773 | if (n_profiles <= 0) { | |
774 | ret = -EINVAL; | |
775 | goto out_free; | |
776 | } | |
777 | ||
69964905 LC |
778 | for (i = 0; i < n_profiles; i++) { |
779 | /* the tables start at element 3 */ | |
780 | static int pos = 3; | |
781 | ||
782 | /* The EWRD profiles officially go from 2 to 4, but we | |
783 | * save them in sar_profiles[1-3] (because we don't | |
784 | * have profile 0). So in the array we start from 1. | |
785 | */ | |
786 | ret = iwl_mvm_sar_set_profile(mvm, | |
787 | &wifi_pkg->package.elements[pos], | |
788 | &mvm->sar_profiles[i + 1], | |
789 | enabled); | |
790 | if (ret < 0) | |
791 | break; | |
792 | ||
793 | /* go to the next table */ | |
794 | pos += IWL_MVM_SAR_TABLE_SIZE; | |
795 | } | |
796 | ||
797 | out_free: | |
798 | kfree(ewrd.pointer); | |
799 | return ret; | |
800 | } | |
801 | ||
7fe90e0e | 802 | static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm) |
a6bff3cb HD |
803 | { |
804 | union acpi_object *wifi_pkg; | |
805 | acpi_handle root_handle; | |
806 | acpi_handle handle; | |
807 | struct acpi_buffer wgds = {ACPI_ALLOCATE_BUFFER, NULL}; | |
808 | acpi_status status; | |
7fe90e0e HD |
809 | int i, j, ret; |
810 | int idx = 1; | |
a6bff3cb HD |
811 | |
812 | root_handle = ACPI_HANDLE(mvm->dev); | |
813 | if (!root_handle) { | |
814 | IWL_DEBUG_RADIO(mvm, | |
815 | "Could not retrieve root port ACPI handle\n"); | |
816 | return -ENOENT; | |
817 | } | |
818 | ||
819 | /* Get the method's handle */ | |
820 | status = acpi_get_handle(root_handle, (acpi_string)ACPI_WGDS_METHOD, | |
821 | &handle); | |
822 | if (ACPI_FAILURE(status)) { | |
823 | IWL_DEBUG_RADIO(mvm, "WGDS method not found\n"); | |
824 | return -ENOENT; | |
825 | } | |
826 | ||
827 | /* Call WGDS with no arguments */ | |
828 | status = acpi_evaluate_object(handle, NULL, NULL, &wgds); | |
829 | if (ACPI_FAILURE(status)) { | |
830 | IWL_DEBUG_RADIO(mvm, "WGDS invocation failed (0x%x)\n", status); | |
831 | return -ENOENT; | |
832 | } | |
833 | ||
834 | wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, wgds.pointer, | |
835 | ACPI_WGDS_WIFI_DATA_SIZE); | |
836 | if (IS_ERR(wifi_pkg)) { | |
837 | ret = PTR_ERR(wifi_pkg); | |
838 | goto out_free; | |
839 | } | |
840 | ||
7fe90e0e HD |
841 | for (i = 0; i < IWL_NUM_GEO_PROFILES; i++) { |
842 | for (j = 0; j < IWL_MVM_GEO_TABLE_SIZE; j++) { | |
843 | union acpi_object *entry; | |
a6bff3cb | 844 | |
7fe90e0e HD |
845 | entry = &wifi_pkg->package.elements[idx++]; |
846 | if ((entry->type != ACPI_TYPE_INTEGER) || | |
847 | (entry->integer.value > U8_MAX)) | |
848 | return -EINVAL; | |
a6bff3cb | 849 | |
7fe90e0e HD |
850 | mvm->geo_profiles[i].values[j] = entry->integer.value; |
851 | } | |
a6bff3cb HD |
852 | } |
853 | ret = 0; | |
854 | out_free: | |
855 | kfree(wgds.pointer); | |
856 | return ret; | |
857 | } | |
858 | ||
42ce76d6 | 859 | int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b) |
da2830ac | 860 | { |
da2830ac | 861 | struct iwl_dev_tx_power_cmd cmd = { |
4b87e5af | 862 | .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS), |
da2830ac | 863 | }; |
42ce76d6 LC |
864 | int i, j, idx; |
865 | int profs[IWL_NUM_CHAIN_LIMITS] = { prof_a, prof_b }; | |
55bfa4b9 | 866 | int len = sizeof(cmd); |
da2830ac | 867 | |
42ce76d6 LC |
868 | BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS < 2); |
869 | BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS != | |
870 | IWL_MVM_SAR_TABLE_SIZE); | |
871 | ||
55bfa4b9 LC |
872 | if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) |
873 | len = sizeof(cmd.v3); | |
874 | ||
42ce76d6 LC |
875 | for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) { |
876 | struct iwl_mvm_sar_profile *prof; | |
da2830ac | 877 | |
42ce76d6 LC |
878 | /* don't allow SAR to be disabled (profile 0 means disable) */ |
879 | if (profs[i] == 0) | |
880 | return -EPERM; | |
da2830ac | 881 | |
42ce76d6 LC |
882 | /* we are off by one, so allow up to IWL_MVM_SAR_PROFILE_NUM */ |
883 | if (profs[i] > IWL_MVM_SAR_PROFILE_NUM) | |
884 | return -EINVAL; | |
da2830ac | 885 | |
42ce76d6 LC |
886 | /* profiles go from 1 to 4, so decrement to access the array */ |
887 | prof = &mvm->sar_profiles[profs[i] - 1]; | |
888 | ||
889 | /* if the profile is disabled, do nothing */ | |
890 | if (!prof->enabled) { | |
891 | IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n", | |
892 | profs[i]); | |
893 | /* if one of the profiles is disabled, we fail all */ | |
894 | return -ENOENT; | |
895 | } | |
da2830ac | 896 | |
da2830ac LC |
897 | IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i); |
898 | for (j = 0; j < IWL_NUM_SUB_BANDS; j++) { | |
899 | idx = (i * IWL_NUM_SUB_BANDS) + j; | |
55bfa4b9 | 900 | cmd.v3.per_chain_restriction[i][j] = |
42ce76d6 | 901 | cpu_to_le16(prof->table[idx]); |
da2830ac | 902 | IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n", |
42ce76d6 | 903 | j, prof->table[idx]); |
da2830ac LC |
904 | } |
905 | } | |
906 | ||
42ce76d6 LC |
907 | IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n"); |
908 | ||
909 | return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); | |
910 | } | |
911 | ||
7fe90e0e HD |
912 | int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm) |
913 | { | |
914 | struct iwl_geo_tx_power_profiles_resp *resp; | |
915 | int ret; | |
916 | ||
917 | struct iwl_geo_tx_power_profiles_cmd geo_cmd = { | |
918 | .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE), | |
919 | }; | |
920 | struct iwl_host_cmd cmd = { | |
921 | .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT), | |
922 | .len = { sizeof(geo_cmd), }, | |
923 | .flags = CMD_WANT_SKB, | |
924 | .data = { &geo_cmd }, | |
925 | }; | |
926 | ||
927 | ret = iwl_mvm_send_cmd(mvm, &cmd); | |
928 | if (ret) { | |
929 | IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret); | |
930 | return ret; | |
931 | } | |
932 | ||
933 | resp = (void *)cmd.resp_pkt->data; | |
934 | ret = le32_to_cpu(resp->profile_idx); | |
935 | if (WARN_ON(ret > IWL_NUM_GEO_PROFILES)) { | |
936 | ret = -EIO; | |
937 | IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret); | |
938 | } | |
939 | ||
940 | iwl_free_resp(&cmd); | |
941 | return ret; | |
942 | } | |
943 | ||
a6bff3cb HD |
944 | static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm) |
945 | { | |
a6bff3cb HD |
946 | struct iwl_geo_tx_power_profiles_cmd cmd = { |
947 | .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES), | |
948 | }; | |
7fe90e0e | 949 | int ret, i, j; |
a6bff3cb HD |
950 | u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT); |
951 | ||
7fe90e0e | 952 | ret = iwl_mvm_sar_get_wgds_table(mvm); |
a6bff3cb HD |
953 | if (ret < 0) { |
954 | IWL_DEBUG_RADIO(mvm, | |
955 | "Geo SAR BIOS table invalid or unavailable. (%d)\n", | |
956 | ret); | |
957 | /* we don't fail if the table is not available */ | |
958 | return 0; | |
959 | } | |
960 | ||
961 | IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n"); | |
962 | ||
963 | BUILD_BUG_ON(IWL_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS * | |
964 | ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE); | |
965 | ||
966 | for (i = 0; i < IWL_NUM_GEO_PROFILES; i++) { | |
967 | struct iwl_per_chain_offset *chain = | |
968 | (struct iwl_per_chain_offset *)&cmd.table[i]; | |
969 | ||
970 | for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) { | |
971 | u8 *value; | |
972 | ||
7fe90e0e HD |
973 | value = &mvm->geo_profiles[i].values[j * |
974 | IWL_GEO_PER_CHAIN_SIZE]; | |
a6bff3cb HD |
975 | chain[j].max_tx_power = cpu_to_le16(value[0]); |
976 | chain[j].chain_a = value[1]; | |
977 | chain[j].chain_b = value[2]; | |
978 | IWL_DEBUG_RADIO(mvm, | |
979 | "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n", | |
980 | i, j, value[1], value[2], value[0]); | |
981 | } | |
982 | } | |
983 | return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd); | |
984 | } | |
985 | ||
69964905 LC |
986 | #else /* CONFIG_ACPI */ |
987 | static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm) | |
988 | { | |
989 | return -ENOENT; | |
990 | } | |
991 | ||
992 | static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm) | |
993 | { | |
994 | return -ENOENT; | |
995 | } | |
a6bff3cb HD |
996 | |
997 | static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm) | |
998 | { | |
999 | return 0; | |
1000 | } | |
69964905 LC |
1001 | #endif /* CONFIG_ACPI */ |
1002 | ||
42ce76d6 LC |
1003 | static int iwl_mvm_sar_init(struct iwl_mvm *mvm) |
1004 | { | |
1005 | int ret; | |
1006 | ||
1007 | ret = iwl_mvm_sar_get_wrds_table(mvm); | |
1008 | if (ret < 0) { | |
1009 | IWL_DEBUG_RADIO(mvm, | |
69964905 | 1010 | "WRDS SAR BIOS table invalid or unavailable. (%d)\n", |
42ce76d6 | 1011 | ret); |
69964905 | 1012 | /* if not available, don't fail and don't bother with EWRD */ |
42ce76d6 LC |
1013 | return 0; |
1014 | } | |
1015 | ||
69964905 LC |
1016 | ret = iwl_mvm_sar_get_ewrd_table(mvm); |
1017 | /* if EWRD is not available, we can still use WRDS, so don't fail */ | |
1018 | if (ret < 0) | |
1019 | IWL_DEBUG_RADIO(mvm, | |
1020 | "EWRD SAR BIOS table invalid or unavailable. (%d)\n", | |
1021 | ret); | |
1022 | ||
42ce76d6 LC |
1023 | /* choose profile 1 (WRDS) as default for both chains */ |
1024 | ret = iwl_mvm_sar_select_profile(mvm, 1, 1); | |
1025 | ||
1026 | /* if we don't have profile 0 from BIOS, just skip it */ | |
1027 | if (ret == -ENOENT) | |
1028 | return 0; | |
da2830ac LC |
1029 | |
1030 | return ret; | |
1031 | } | |
1032 | ||
1f370650 | 1033 | static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm) |
8ca151b5 | 1034 | { |
1f370650 | 1035 | int ret; |
8ca151b5 | 1036 | |
1f370650 SS |
1037 | if (iwl_mvm_has_new_tx_api(mvm)) |
1038 | return iwl_run_unified_mvm_ucode(mvm, false); | |
8ca151b5 | 1039 | |
8d193ca2 | 1040 | ret = iwl_run_init_mvm_ucode(mvm, false); |
f2082a53 SS |
1041 | |
1042 | if (iwlmvm_mod_params.init_dbg) | |
1043 | return 0; | |
1044 | ||
1045 | if (ret) { | |
8d193ca2 EH |
1046 | IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret); |
1047 | /* this can't happen */ | |
1048 | if (WARN_ON(ret > 0)) | |
1049 | ret = -ERFKILL; | |
1f370650 | 1050 | return ret; |
8d193ca2 | 1051 | } |
8ca151b5 | 1052 | |
f2082a53 SS |
1053 | /* |
1054 | * Stop and start the transport without entering low power | |
1055 | * mode. This will save the state of other components on the | |
1056 | * device that are triggered by the INIT firwmare (MFUART). | |
1057 | */ | |
1058 | _iwl_trans_stop_device(mvm->trans, false); | |
1059 | ret = _iwl_trans_start_hw(mvm->trans, false); | |
1060 | if (ret) | |
1f370650 | 1061 | return ret; |
8ca151b5 JB |
1062 | |
1063 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); | |
1f370650 SS |
1064 | if (ret) |
1065 | return ret; | |
1066 | ||
235acb18 | 1067 | return iwl_init_paging(&mvm->fwrt, mvm->cur_ucode); |
1f370650 SS |
1068 | } |
1069 | ||
1070 | int iwl_mvm_up(struct iwl_mvm *mvm) | |
1071 | { | |
1072 | int ret, i; | |
1073 | struct ieee80211_channel *chan; | |
1074 | struct cfg80211_chan_def chandef; | |
1075 | ||
1076 | lockdep_assert_held(&mvm->mutex); | |
1077 | ||
1078 | ret = iwl_trans_start_hw(mvm->trans); | |
1079 | if (ret) | |
1080 | return ret; | |
1081 | ||
1082 | ret = iwl_mvm_load_rt_fw(mvm); | |
8ca151b5 JB |
1083 | if (ret) { |
1084 | IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); | |
1085 | goto error; | |
1086 | } | |
1087 | ||
d0b813fc | 1088 | iwl_get_shared_mem_conf(&mvm->fwrt); |
04fd2c28 | 1089 | |
1f3b0ff8 LE |
1090 | ret = iwl_mvm_sf_update(mvm, NULL, false); |
1091 | if (ret) | |
1092 | IWL_ERR(mvm, "Failed to initialize Smart Fifo\n"); | |
1093 | ||
6a951267 | 1094 | mvm->fw_dbg_conf = FW_DBG_INVALID; |
945d4202 EG |
1095 | /* if we have a destination, assume EARLY START */ |
1096 | if (mvm->fw->dbg_dest_tlv) | |
1097 | mvm->fw_dbg_conf = FW_DBG_START_FROM_ALIVE; | |
d2709ad7 | 1098 | iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_START_FROM_ALIVE); |
6a951267 | 1099 | |
a0544272 | 1100 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
8ca151b5 JB |
1101 | if (ret) |
1102 | goto error; | |
1103 | ||
1104 | /* Send phy db control command and then phy db calibration*/ | |
1f370650 SS |
1105 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
1106 | ret = iwl_send_phy_db_data(mvm->phy_db); | |
1107 | if (ret) | |
1108 | goto error; | |
8ca151b5 | 1109 | |
1f370650 SS |
1110 | ret = iwl_send_phy_cfg_cmd(mvm); |
1111 | if (ret) | |
1112 | goto error; | |
1113 | } | |
8ca151b5 | 1114 | |
b3de3ef4 EG |
1115 | ret = iwl_mvm_send_bt_init_conf(mvm); |
1116 | if (ret) | |
1117 | goto error; | |
1118 | ||
43413a97 | 1119 | /* Init RSS configuration */ |
09a2e25d SS |
1120 | /* TODO - remove a000 disablement when we have RXQ config API */ |
1121 | if (iwl_mvm_has_new_rx_api(mvm) && !iwl_mvm_has_new_tx_api(mvm)) { | |
43413a97 SS |
1122 | ret = iwl_send_rss_cfg_cmd(mvm); |
1123 | if (ret) { | |
1124 | IWL_ERR(mvm, "Failed to configure RSS queues: %d\n", | |
1125 | ret); | |
1126 | goto error; | |
1127 | } | |
1128 | } | |
1129 | ||
8ca151b5 | 1130 | /* init the fw <-> mac80211 STA mapping */ |
0ae98812 | 1131 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) |
8ca151b5 JB |
1132 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
1133 | ||
0ae98812 | 1134 | mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA; |
1d3c3f63 | 1135 | |
b2b7875b JB |
1136 | /* reset quota debouncing buffer - 0xff will yield invalid data */ |
1137 | memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd)); | |
1138 | ||
97d5be7e LK |
1139 | /* Enable DQA-mode if required */ |
1140 | if (iwl_mvm_is_dqa_supported(mvm)) { | |
1141 | ret = iwl_mvm_send_dqa_cmd(mvm); | |
1142 | if (ret) | |
1143 | goto error; | |
1144 | } else { | |
1145 | IWL_DEBUG_FW(mvm, "Working in non-DQA mode\n"); | |
1146 | } | |
1147 | ||
8ca151b5 JB |
1148 | /* Add auxiliary station for scanning */ |
1149 | ret = iwl_mvm_add_aux_sta(mvm); | |
1150 | if (ret) | |
1151 | goto error; | |
1152 | ||
53a9d61e | 1153 | /* Add all the PHY contexts */ |
57fbcce3 | 1154 | chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0]; |
53a9d61e IP |
1155 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); |
1156 | for (i = 0; i < NUM_PHY_CTX; i++) { | |
1157 | /* | |
1158 | * The channel used here isn't relevant as it's | |
1159 | * going to be overwritten in the other flows. | |
1160 | * For now use the first channel we have. | |
1161 | */ | |
1162 | ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i], | |
1163 | &chandef, 1, 1); | |
1164 | if (ret) | |
1165 | goto error; | |
1166 | } | |
8ca151b5 | 1167 | |
c221daf2 CRI |
1168 | #ifdef CONFIG_THERMAL |
1169 | if (iwl_mvm_is_tt_in_fw(mvm)) { | |
1170 | /* in order to give the responsibility of ct-kill and | |
1171 | * TX backoff to FW we need to send empty temperature reporting | |
1172 | * cmd during init time | |
1173 | */ | |
1174 | iwl_mvm_send_temp_report_ths_cmd(mvm); | |
1175 | } else { | |
1176 | /* Initialize tx backoffs to the minimal possible */ | |
1177 | iwl_mvm_tt_tx_backoff(mvm, 0); | |
1178 | } | |
5c89e7bc CRI |
1179 | |
1180 | /* TODO: read the budget from BIOS / Platform NVM */ | |
75cfe338 | 1181 | if (iwl_mvm_is_ctdp_supported(mvm) && mvm->cooling_dev.cur_state > 0) { |
5c89e7bc CRI |
1182 | ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START, |
1183 | mvm->cooling_dev.cur_state); | |
75cfe338 LC |
1184 | if (ret) |
1185 | goto error; | |
1186 | } | |
c221daf2 | 1187 | #else |
0c0e2c71 IY |
1188 | /* Initialize tx backoffs to the minimal possible */ |
1189 | iwl_mvm_tt_tx_backoff(mvm, 0); | |
c221daf2 | 1190 | #endif |
0c0e2c71 | 1191 | |
84bfffa9 | 1192 | WARN_ON(iwl_mvm_config_ltr(mvm)); |
9180ac50 | 1193 | |
c1cb92fc | 1194 | ret = iwl_mvm_power_update_device(mvm); |
64b928c4 AB |
1195 | if (ret) |
1196 | goto error; | |
1197 | ||
35af15d1 AN |
1198 | /* |
1199 | * RTNL is not taken during Ct-kill, but we don't need to scan/Tx | |
1200 | * anyway, so don't init MCC. | |
1201 | */ | |
1202 | if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) { | |
1203 | ret = iwl_mvm_init_mcc(mvm); | |
1204 | if (ret) | |
1205 | goto error; | |
1206 | } | |
90d4f7db | 1207 | |
859d914c | 1208 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
4ca87a5f | 1209 | mvm->scan_type = IWL_SCAN_TYPE_NOT_SET; |
d2496221 DS |
1210 | ret = iwl_mvm_config_scan(mvm); |
1211 | if (ret) | |
1212 | goto error; | |
1213 | } | |
1214 | ||
7498cf4c EP |
1215 | /* allow FW/transport low power modes if not during restart */ |
1216 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
1217 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); | |
1218 | ||
da2830ac LC |
1219 | ret = iwl_mvm_sar_init(mvm); |
1220 | if (ret) | |
1221 | goto error; | |
1222 | ||
a6bff3cb HD |
1223 | ret = iwl_mvm_sar_geo_init(mvm); |
1224 | if (ret) | |
1225 | goto error; | |
1226 | ||
53a9d61e | 1227 | IWL_DEBUG_INFO(mvm, "RT uCode started.\n"); |
8ca151b5 JB |
1228 | return 0; |
1229 | error: | |
de8ba41b LK |
1230 | if (!iwlmvm_mod_params.init_dbg) |
1231 | iwl_mvm_stop_device(mvm); | |
8ca151b5 JB |
1232 | return ret; |
1233 | } | |
1234 | ||
1235 | int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm) | |
1236 | { | |
1237 | int ret, i; | |
1238 | ||
1239 | lockdep_assert_held(&mvm->mutex); | |
1240 | ||
1241 | ret = iwl_trans_start_hw(mvm->trans); | |
1242 | if (ret) | |
1243 | return ret; | |
1244 | ||
1245 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN); | |
1246 | if (ret) { | |
1247 | IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret); | |
1248 | goto error; | |
1249 | } | |
1250 | ||
a0544272 | 1251 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
8ca151b5 JB |
1252 | if (ret) |
1253 | goto error; | |
1254 | ||
1255 | /* Send phy db control command and then phy db calibration*/ | |
1256 | ret = iwl_send_phy_db_data(mvm->phy_db); | |
1257 | if (ret) | |
1258 | goto error; | |
1259 | ||
1260 | ret = iwl_send_phy_cfg_cmd(mvm); | |
1261 | if (ret) | |
1262 | goto error; | |
1263 | ||
1264 | /* init the fw <-> mac80211 STA mapping */ | |
0ae98812 | 1265 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) |
8ca151b5 JB |
1266 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
1267 | ||
1268 | /* Add auxiliary station for scanning */ | |
1269 | ret = iwl_mvm_add_aux_sta(mvm); | |
1270 | if (ret) | |
1271 | goto error; | |
1272 | ||
1273 | return 0; | |
1274 | error: | |
fcb6b92a | 1275 | iwl_mvm_stop_device(mvm); |
8ca151b5 JB |
1276 | return ret; |
1277 | } | |
1278 | ||
0416841d JB |
1279 | void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm, |
1280 | struct iwl_rx_cmd_buffer *rxb) | |
8ca151b5 JB |
1281 | { |
1282 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1283 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; | |
1284 | u32 flags = le32_to_cpu(card_state_notif->flags); | |
1285 | ||
1286 | IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n", | |
1287 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | |
1288 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", | |
1289 | (flags & CT_KILL_CARD_DISABLED) ? | |
1290 | "Reached" : "Not reached"); | |
8ca151b5 JB |
1291 | } |
1292 | ||
0416841d JB |
1293 | void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm, |
1294 | struct iwl_rx_cmd_buffer *rxb) | |
30269c12 CRI |
1295 | { |
1296 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1297 | struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data; | |
1298 | ||
0c8d0a47 GBA |
1299 | IWL_DEBUG_INFO(mvm, |
1300 | "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n", | |
1301 | le32_to_cpu(mfuart_notif->installed_ver), | |
1302 | le32_to_cpu(mfuart_notif->external_ver), | |
1303 | le32_to_cpu(mfuart_notif->status), | |
1304 | le32_to_cpu(mfuart_notif->duration)); | |
1305 | ||
19f63c53 GBA |
1306 | if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif)) |
1307 | IWL_DEBUG_INFO(mvm, | |
0c8d0a47 | 1308 | "MFUART: image size: 0x%08x\n", |
19f63c53 | 1309 | le32_to_cpu(mfuart_notif->image_size)); |
30269c12 | 1310 | } |