blob: 6bb1a99a197a22981f29962ab487cccb76dd0eb8 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eran Harary8d193ca2015-04-27 10:29:31 +03009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Golan Ben-Amibdccdb82016-11-15 14:45:29 +020010 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +020011 * Copyright(c) 2018 Intel Corporation
Johannes Berg8ca151b2013-01-24 14:25:36 +010012 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * USA
26 *
27 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020028 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010029 *
30 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020031 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010032 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 *
34 * BSD LICENSE
35 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020036 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eran Harary8d193ca2015-04-27 10:29:31 +030037 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Golan Ben-Amibdccdb82016-11-15 14:45:29 +020038 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +020039 * Copyright(c) 2018 Intel Corporation
Johannes Berg8ca151b2013-01-24 14:25:36 +010040 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 *
46 * * Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * * Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in
50 * the documentation and/or other materials provided with the
51 * distribution.
52 * * Neither the name Intel Corporation nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 *****************************************************************************/
69#include <net/mac80211.h>
Sara Sharon854d7732016-03-22 15:55:58 +020070#include <linux/netdevice.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010071
72#include "iwl-trans.h"
73#include "iwl-op-mode.h"
Johannes Bergd962f9b2017-06-01 10:22:09 +020074#include "fw/img.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010075#include "iwl-debug.h"
76#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
77#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +020078#include "iwl-prph.h"
Luca Coelho813df5c2017-09-19 12:35:18 +030079#include "fw/acpi.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010080
81#include "mvm.h"
Johannes Berg7174beb2017-06-01 16:03:19 +020082#include "fw/dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010083#include "iwl-phy-db.h"
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +020084#include "iwl-modparams.h"
85#include "iwl-nvm-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010086
87#define MVM_UCODE_ALIVE_TIMEOUT HZ
88#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
89
90#define UCODE_VALID_OK cpu_to_le32(0x1)
91
Johannes Berg8ca151b2013-01-24 14:25:36 +010092struct iwl_mvm_alive_data {
93 bool valid;
94 u32 scd_base_addr;
95};
96
Johannes Berg8ca151b2013-01-24 14:25:36 +010097static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
98{
99 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
100 .valid = cpu_to_le32(valid_tx_ant),
101 };
102
Emmanuel Grumbach33223542013-03-09 20:38:19 +0200103 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300104 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105 sizeof(tx_ant_cmd), &tx_ant_cmd);
106}
107
Sara Sharon43413a92015-12-31 11:49:18 +0200108static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
109{
110 int i;
111 struct iwl_rss_config_cmd cmd = {
112 .flags = cpu_to_le32(IWL_RSS_ENABLE),
113 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200114 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200115 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
116 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200117 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200118 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
119 };
120
Sara Sharonf43495f2016-05-04 14:22:10 +0300121 if (mvm->trans->num_rx_queues == 1)
122 return 0;
123
Sara Sharon854d7732016-03-22 15:55:58 +0200124 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
Sara Sharon43413a92015-12-31 11:49:18 +0200125 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
Sara Sharon854d7732016-03-22 15:55:58 +0200126 cmd.indirection_table[i] =
127 1 + (i % (mvm->trans->num_rx_queues - 1));
128 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200129
130 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
131}
132
Sara Sharon8edbfaa2018-02-05 12:42:44 +0200133static int iwl_configure_rxq(struct iwl_mvm *mvm)
134{
135 int i, num_queues, size;
136 struct iwl_rfh_queue_config *cmd;
137
138 /* Do not configure default queue, it is configured via context info */
139 num_queues = mvm->trans->num_rx_queues - 1;
140
141 size = sizeof(*cmd) + num_queues * sizeof(struct iwl_rfh_queue_data);
142
143 cmd = kzalloc(size, GFP_KERNEL);
144 if (!cmd)
145 return -ENOMEM;
146
147 cmd->num_queues = num_queues;
148
149 for (i = 0; i < num_queues; i++) {
150 struct iwl_trans_rxq_dma_data data;
151
152 cmd->data[i].q_num = i + 1;
153 iwl_trans_get_rxq_dma_data(mvm->trans, i + 1, &data);
154
155 cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
156 cmd->data[i].urbd_stts_wrptr =
157 cpu_to_le64(data.urbd_stts_wrptr);
158 cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
159 cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
160 }
161
162 return iwl_mvm_send_cmd_pdu(mvm,
163 WIDE_ID(DATA_PATH_GROUP,
164 RFH_QUEUE_CONFIG_CMD),
165 0, size, cmd);
166}
167
Liad Kaufman97d5be72015-08-31 14:33:23 +0300168static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
169{
170 struct iwl_dqa_enable_cmd dqa_cmd = {
171 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
172 };
173 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
174 int ret;
175
176 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
177 if (ret)
178 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
179 else
180 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
181
182 return ret;
183}
184
Golan Ben-Amibdccdb82016-11-15 14:45:29 +0200185void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
186 struct iwl_rx_cmd_buffer *rxb)
187{
188 struct iwl_rx_packet *pkt = rxb_addr(rxb);
189 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
190 __le32 *dump_data = mfu_dump_notif->data;
191 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
192 int i;
193
194 if (mfu_dump_notif->index_num == 0)
195 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
196 le32_to_cpu(mfu_dump_notif->assert_id));
197
198 for (i = 0; i < n_words; i++)
199 IWL_DEBUG_INFO(mvm,
200 "MFUART assert dump, dword %u: 0x%08x\n",
201 le16_to_cpu(mfu_dump_notif->index_num) *
202 n_words + i,
203 le32_to_cpu(dump_data[i]));
204}
205
Johannes Berg8ca151b2013-01-24 14:25:36 +0100206static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
207 struct iwl_rx_packet *pkt, void *data)
208{
209 struct iwl_mvm *mvm =
210 container_of(notif_wait, struct iwl_mvm, notif_wait);
211 struct iwl_mvm_alive_data *alive_data = data;
Sara Sharon5c228d62016-11-24 13:48:27 +0200212 struct mvm_alive_resp_v3 *palive3;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200213 struct mvm_alive_resp *palive;
Sara Sharon5c228d62016-11-24 13:48:27 +0200214 struct iwl_umac_alive *umac;
215 struct iwl_lmac_alive *lmac1;
216 struct iwl_lmac_alive *lmac2 = NULL;
217 u16 status;
Luca Coelho3485e762017-10-02 16:12:23 +0300218 u32 umac_error_event_table;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219
Sara Sharon5c228d62016-11-24 13:48:27 +0200220 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200221 palive = (void *)pkt->data;
Sara Sharon5c228d62016-11-24 13:48:27 +0200222 umac = &palive->umac_data;
223 lmac1 = &palive->lmac_data[0];
224 lmac2 = &palive->lmac_data[1];
225 status = le16_to_cpu(palive->status);
226 } else {
227 palive3 = (void *)pkt->data;
228 umac = &palive3->umac_data;
229 lmac1 = &palive3->lmac_data;
230 status = le16_to_cpu(palive3->status);
Eran Harary01a9ca52014-02-03 09:29:57 +0200231 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100232
Sara Sharon5c228d62016-11-24 13:48:27 +0200233 mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
234 if (lmac2)
235 mvm->error_event_table[1] =
236 le32_to_cpu(lmac2->error_event_table_ptr);
237 mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
Sara Sharon5c228d62016-11-24 13:48:27 +0200238
Luca Coelho3485e762017-10-02 16:12:23 +0300239 umac_error_event_table = le32_to_cpu(umac->error_info_addr);
Sara Sharon5c228d62016-11-24 13:48:27 +0200240
Luca Coelho3485e762017-10-02 16:12:23 +0300241 if (!umac_error_event_table) {
242 mvm->support_umac_log = false;
243 } else if (umac_error_event_table >=
244 mvm->trans->cfg->min_umac_error_event_table) {
245 mvm->support_umac_log = true;
246 mvm->umac_error_event_table = umac_error_event_table;
247 } else {
Luca Coelhofb5b2842017-10-02 15:44:20 +0300248 IWL_ERR(mvm,
249 "Not valid error log pointer 0x%08X for %s uCode\n",
250 mvm->umac_error_event_table,
251 (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
252 "Init" : "RT");
Luca Coelho3485e762017-10-02 16:12:23 +0300253 mvm->support_umac_log = false;
254 }
Luca Coelhofb5b2842017-10-02 15:44:20 +0300255
Sara Sharon5c228d62016-11-24 13:48:27 +0200256 alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
257 alive_data->valid = status == IWL_ALIVE_STATUS_OK;
Sara Sharon5c228d62016-11-24 13:48:27 +0200258
259 IWL_DEBUG_FW(mvm,
260 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
261 status, lmac1->ver_type, lmac1->ver_subtype);
262
263 if (lmac2)
264 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
265
266 IWL_DEBUG_FW(mvm,
267 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
268 le32_to_cpu(umac->umac_major),
269 le32_to_cpu(umac->umac_minor));
270
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271 return true;
272}
273
Sara Sharon1f370652016-08-31 18:13:57 +0300274static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
275 struct iwl_rx_packet *pkt, void *data)
276{
277 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
278
279 return true;
280}
281
Johannes Berg8ca151b2013-01-24 14:25:36 +0100282static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
283 struct iwl_rx_packet *pkt, void *data)
284{
285 struct iwl_phy_db *phy_db = data;
286
287 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
288 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
289 return true;
290 }
291
Sara Sharonce1f2772016-04-10 16:02:12 +0300292 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100293
294 return false;
295}
296
297static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
298 enum iwl_ucode_type ucode_type)
299{
300 struct iwl_notification_wait alive_wait;
301 struct iwl_mvm_alive_data alive_data;
302 const struct fw_img *fw;
303 int ret, i;
Johannes Berg702e9752017-06-02 11:56:58 +0200304 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300305 static const u16 alive_cmd[] = { MVM_ALIVE };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100306
Eran Harary61df7502014-12-01 17:40:37 +0200307 if (ucode_type == IWL_UCODE_REGULAR &&
Golan Ben-Ami3d2d4422016-02-23 10:34:48 +0200308 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
309 !(fw_has_capa(&mvm->fw->ucode_capa,
310 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
Sharon Dvir612da1e2016-08-03 10:55:45 +0300311 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
Eran Harary61df7502014-12-01 17:40:37 +0200312 else
Sharon Dvir612da1e2016-08-03 10:55:45 +0300313 fw = iwl_get_ucode_image(mvm->fw, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200314 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100315 return -EINVAL;
Johannes Berg702e9752017-06-02 11:56:58 +0200316 iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
Johannes Berg65b280f2017-03-22 22:10:36 +0100317 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100318
319 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
320 alive_cmd, ARRAY_SIZE(alive_cmd),
321 iwl_alive_fn, &alive_data);
322
323 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
324 if (ret) {
Johannes Berg702e9752017-06-02 11:56:58 +0200325 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100326 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
327 return ret;
328 }
329
330 /*
331 * Some things may run in the background now, but we
332 * just wait for the ALIVE notification here.
333 */
334 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
335 MVM_UCODE_ALIVE_TIMEOUT);
336 if (ret) {
Sara Sharond6be9c12017-01-12 11:31:25 +0200337 struct iwl_trans *trans = mvm->trans;
338
Golan Ben Ami5f01df32018-02-07 20:08:56 +0200339 if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000)
Dor Shaish192de2b2015-07-15 11:41:21 +0300340 IWL_ERR(mvm,
341 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
Sara Sharond6be9c12017-01-12 11:31:25 +0200342 iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
343 iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
Sara Sharon6e584872017-03-22 14:07:50 +0200344 else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
Sara Sharond6be9c12017-01-12 11:31:25 +0200345 IWL_ERR(mvm,
346 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
347 iwl_read_prph(trans, SB_CPU_1_STATUS),
348 iwl_read_prph(trans, SB_CPU_2_STATUS));
Johannes Berg702e9752017-06-02 11:56:58 +0200349 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100350 return ret;
351 }
352
353 if (!alive_data.valid) {
354 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
Johannes Berg702e9752017-06-02 11:56:58 +0200355 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100356 return -EIO;
357 }
358
359 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
360
361 /*
362 * Note: all the queues are enabled as part of the interface
363 * initialization, but in firmware restart scenarios they
364 * could be stopped, so wake them up. In firmware restart,
365 * mac80211 will have the queues stopped as well until the
366 * reconfiguration completes. During normal startup, they
367 * will be empty.
368 */
369
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300370 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
Johannes Bergc8f54702017-06-19 23:50:31 +0200371 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372
Johannes Bergdf197c02014-08-01 18:14:45 +0200373 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
374 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375
Johannes Berg65b280f2017-03-22 22:10:36 +0100376 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100377
378 return 0;
379}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100380
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100381static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
382{
383 struct iwl_notification_wait init_wait;
384 struct iwl_nvm_access_complete_cmd nvm_complete = {};
385 struct iwl_init_extended_cfg_cmd init_cfg = {
386 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
387 };
388 static const u16 init_complete[] = {
389 INIT_COMPLETE_NOTIF,
390 };
391 int ret;
392
393 lockdep_assert_held(&mvm->mutex);
394
395 iwl_init_notification_wait(&mvm->notif_wait,
396 &init_wait,
397 init_complete,
398 ARRAY_SIZE(init_complete),
399 iwl_wait_init_complete,
400 NULL);
401
402 /* Will also start the device */
403 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
404 if (ret) {
405 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
406 goto error;
407 }
408
409 /* Send init config command to mark that we are sending NVM access
410 * commands
411 */
412 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
413 INIT_EXTENDED_CFG_CMD), 0,
414 sizeof(init_cfg), &init_cfg);
415 if (ret) {
416 IWL_ERR(mvm, "Failed to run init config command: %d\n",
417 ret);
418 goto error;
419 }
420
Sara Sharone9e1ba32017-01-08 16:46:14 +0200421 /* Load NVM to NIC if needed */
422 if (mvm->nvm_file_name) {
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +0200423 iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
424 mvm->nvm_sections);
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100425 iwl_mvm_load_nvm_to_nic(mvm);
Sara Sharone9e1ba32017-01-08 16:46:14 +0200426 }
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100427
Sara Sharond4f36952017-03-06 11:13:02 +0200428 if (IWL_MVM_PARSE_NVM && read_nvm) {
Luca Coelho5bd1d2c2017-08-15 18:46:44 +0300429 ret = iwl_nvm_init(mvm);
Sara Sharond4f36952017-03-06 11:13:02 +0200430 if (ret) {
431 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
432 goto error;
433 }
434 }
435
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100436 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
437 NVM_ACCESS_COMPLETE), 0,
438 sizeof(nvm_complete), &nvm_complete);
439 if (ret) {
440 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
441 ret);
442 goto error;
443 }
444
445 /* We wait for the INIT complete notification */
Sara Sharone9e1ba32017-01-08 16:46:14 +0200446 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
447 MVM_UCODE_ALIVE_TIMEOUT);
448 if (ret)
449 return ret;
450
451 /* Read the NVM only at driver load time, no need to do this twice */
Sara Sharond4f36952017-03-06 11:13:02 +0200452 if (!IWL_MVM_PARSE_NVM && read_nvm) {
Shaul Triebitz4c625c52018-01-24 16:12:49 +0200453 mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
Shaul Triebitzc135cb52017-06-22 17:09:08 +0300454 if (IS_ERR(mvm->nvm_data)) {
455 ret = PTR_ERR(mvm->nvm_data);
456 mvm->nvm_data = NULL;
Sara Sharone9e1ba32017-01-08 16:46:14 +0200457 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
458 return ret;
459 }
460 }
461
462 return 0;
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100463
464error:
465 iwl_remove_notification(&mvm->notif_wait, &init_wait);
466 return ret;
467}
468
Johannes Berg8ca151b2013-01-24 14:25:36 +0100469static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
470{
471 struct iwl_phy_cfg_cmd phy_cfg_cmd;
Johannes Berg702e9752017-06-02 11:56:58 +0200472 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100473
474 /* Set parameters */
Moshe Harela0544272014-12-08 21:13:14 +0200475 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
Luca Coelho86a2b202018-02-21 22:18:59 +0200476
477 /* set flags extra PHY configuration flags from the device's cfg */
478 phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags);
479
Johannes Berg8ca151b2013-01-24 14:25:36 +0100480 phy_cfg_cmd.calib_control.event_trigger =
481 mvm->fw->default_calib[ucode_type].event_trigger;
482 phy_cfg_cmd.calib_control.flow_trigger =
483 mvm->fw->default_calib[ucode_type].flow_trigger;
484
485 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
486 phy_cfg_cmd.phy_cfg);
487
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300488 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100489 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
490}
491
Johannes Berg8ca151b2013-01-24 14:25:36 +0100492int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
493{
494 struct iwl_notification_wait calib_wait;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300495 static const u16 init_complete[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100496 INIT_COMPLETE_NOTIF,
497 CALIB_RES_NOTIF_PHY_DB
498 };
499 int ret;
500
Johannes Berg7d6222e22017-06-08 09:18:22 +0200501 if (iwl_mvm_has_unified_ucode(mvm))
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100502 return iwl_run_unified_mvm_ucode(mvm, true);
503
Johannes Berg8ca151b2013-01-24 14:25:36 +0100504 lockdep_assert_held(&mvm->mutex);
505
Eran Harary8d193ca2015-04-27 10:29:31 +0300506 if (WARN_ON_ONCE(mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100507 return 0;
508
509 iwl_init_notification_wait(&mvm->notif_wait,
510 &calib_wait,
511 init_complete,
512 ARRAY_SIZE(init_complete),
513 iwl_wait_phy_db_entry,
514 mvm->phy_db);
515
516 /* Will also start the device */
517 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
518 if (ret) {
519 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300520 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521 }
522
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +0300523 if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
524 ret = iwl_mvm_send_bt_init_conf(mvm);
525 if (ret)
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300526 goto remove_notif;
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +0300527 }
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200528
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200529 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100530 if (read_nvm) {
Luca Coelho5bd1d2c2017-08-15 18:46:44 +0300531 ret = iwl_nvm_init(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100532 if (ret) {
533 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300534 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100535 }
536 }
537
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200538 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300539 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200540 iwl_mvm_load_nvm_to_nic(mvm);
541
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300542 WARN_ON(iwl_nvm_check_version(mvm->nvm_data, mvm->trans));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100543
Eran Harary4f593342013-05-13 07:53:26 +0300544 /*
545 * abort after reading the nvm in case RF Kill is on, we will complete
546 * the init seq later when RF kill will switch to off
547 */
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300548 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300549 IWL_DEBUG_RF_KILL(mvm,
550 "jump over all phy activities due to RF kill\n");
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300551 goto remove_notif;
Eran Harary4f593342013-05-13 07:53:26 +0300552 }
553
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200554 mvm->calibrating = true;
555
Dor Shaishe07cbb52013-02-27 23:00:27 +0200556 /* Send TX valid antennas before triggering calibrations */
Moshe Harela0544272014-12-08 21:13:14 +0200557 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Dor Shaishe07cbb52013-02-27 23:00:27 +0200558 if (ret)
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300559 goto remove_notif;
Dor Shaishe07cbb52013-02-27 23:00:27 +0200560
Johannes Berg8ca151b2013-01-24 14:25:36 +0100561 ret = iwl_send_phy_cfg_cmd(mvm);
562 if (ret) {
563 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
564 ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300565 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100566 }
567
568 /*
569 * Some things may run in the background now, but we
570 * just wait for the calibration complete notification.
571 */
572 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300573 MVM_UCODE_CALIB_TIMEOUT);
574 if (!ret)
575 goto out;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200576
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300577 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200578 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300579 ret = 0;
580 } else {
581 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
582 ret);
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200583 }
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300584
Johannes Berg8ca151b2013-01-24 14:25:36 +0100585 goto out;
586
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300587remove_notif:
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
589out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200590 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200591 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100592 /* we want to debug INIT and we have no NVM - fake */
593 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
594 sizeof(struct ieee80211_channel) +
595 sizeof(struct ieee80211_rate),
596 GFP_KERNEL);
597 if (!mvm->nvm_data)
598 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100599 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
600 mvm->nvm_data->bands[0].n_channels = 1;
601 mvm->nvm_data->bands[0].n_bitrates = 1;
602 mvm->nvm_data->bands[0].bitrates =
603 (void *)mvm->nvm_data->channels + 1;
604 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
605 }
606
607 return ret;
608}
609
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200610static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
611{
612 struct iwl_ltr_config_cmd cmd = {
613 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
614 };
615
616 if (!mvm->trans->ltr_enabled)
617 return 0;
618
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200619 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
620 sizeof(cmd), &cmd);
621}
622
Luca Coelhoda2830a2016-05-30 13:00:44 +0300623#ifdef CONFIG_ACPI
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200624static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
625 union acpi_object *table,
626 struct iwl_mvm_sar_profile *profile,
627 bool enabled)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300628{
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200629 int i;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300630
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200631 profile->enabled = enabled;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300632
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300633 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200634 if ((table[i].type != ACPI_TYPE_INTEGER) ||
635 (table[i].integer.value > U8_MAX))
Luca Coelhoda2830a2016-05-30 13:00:44 +0300636 return -EINVAL;
637
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200638 profile->table[i] = table[i].integer.value;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300639 }
640
641 return 0;
642}
643
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200644static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
645{
Luca Coelho813df5c2017-09-19 12:35:18 +0300646 union acpi_object *wifi_pkg, *table, *data;
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200647 bool enabled;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300648 int ret;
649
Luca Coelho813df5c2017-09-19 12:35:18 +0300650 data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD);
651 if (IS_ERR(data))
652 return PTR_ERR(data);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300653
Luca Coelho2fa388c2017-09-21 14:30:53 +0300654 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
655 ACPI_WRDS_WIFI_DATA_SIZE);
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200656 if (IS_ERR(wifi_pkg)) {
657 ret = PTR_ERR(wifi_pkg);
658 goto out_free;
659 }
Luca Coelhoda2830a2016-05-30 13:00:44 +0300660
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200661 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
662 ret = -EINVAL;
663 goto out_free;
664 }
665
666 enabled = !!(wifi_pkg->package.elements[1].integer.value);
667
668 /* position of the actual table */
669 table = &wifi_pkg->package.elements[2];
670
671 /* The profile from WRDS is officially profile 1, but goes
672 * into sar_profiles[0] (because we don't have a profile 0).
673 */
674 ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
675 enabled);
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200676out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300677 kfree(data);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300678 return ret;
679}
Luca Coelhoda2830a2016-05-30 13:00:44 +0300680
Luca Coelho69964902017-01-12 12:43:12 +0200681static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
682{
Luca Coelho813df5c2017-09-19 12:35:18 +0300683 union acpi_object *wifi_pkg, *data;
Luca Coelho69964902017-01-12 12:43:12 +0200684 bool enabled;
685 int i, n_profiles, ret;
686
Luca Coelho813df5c2017-09-19 12:35:18 +0300687 data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD);
688 if (IS_ERR(data))
689 return PTR_ERR(data);
Luca Coelho69964902017-01-12 12:43:12 +0200690
Luca Coelho2fa388c2017-09-21 14:30:53 +0300691 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
692 ACPI_EWRD_WIFI_DATA_SIZE);
Luca Coelho69964902017-01-12 12:43:12 +0200693 if (IS_ERR(wifi_pkg)) {
694 ret = PTR_ERR(wifi_pkg);
695 goto out_free;
696 }
697
698 if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
699 (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
700 ret = -EINVAL;
701 goto out_free;
702 }
703
704 enabled = !!(wifi_pkg->package.elements[1].integer.value);
705 n_profiles = wifi_pkg->package.elements[2].integer.value;
706
Sharon Dvire2ef1472017-02-21 11:12:12 +0200707 /* in case of BIOS bug */
708 if (n_profiles <= 0) {
709 ret = -EINVAL;
710 goto out_free;
711 }
712
Luca Coelho69964902017-01-12 12:43:12 +0200713 for (i = 0; i < n_profiles; i++) {
714 /* the tables start at element 3 */
715 static int pos = 3;
716
717 /* The EWRD profiles officially go from 2 to 4, but we
718 * save them in sar_profiles[1-3] (because we don't
719 * have profile 0). So in the array we start from 1.
720 */
721 ret = iwl_mvm_sar_set_profile(mvm,
722 &wifi_pkg->package.elements[pos],
723 &mvm->sar_profiles[i + 1],
724 enabled);
725 if (ret < 0)
726 break;
727
728 /* go to the next table */
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300729 pos += ACPI_SAR_TABLE_SIZE;
Luca Coelho69964902017-01-12 12:43:12 +0200730 }
731
732out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300733 kfree(data);
Luca Coelho69964902017-01-12 12:43:12 +0200734 return ret;
735}
736
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300737static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200738{
Luca Coelho813df5c2017-09-19 12:35:18 +0300739 union acpi_object *wifi_pkg, *data;
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300740 int i, j, ret;
741 int idx = 1;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200742
Luca Coelho813df5c2017-09-19 12:35:18 +0300743 data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD);
744 if (IS_ERR(data))
745 return PTR_ERR(data);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200746
Luca Coelho2fa388c2017-09-21 14:30:53 +0300747 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
748 ACPI_WGDS_WIFI_DATA_SIZE);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200749 if (IS_ERR(wifi_pkg)) {
750 ret = PTR_ERR(wifi_pkg);
751 goto out_free;
752 }
753
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300754 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
755 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300756 union acpi_object *entry;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200757
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300758 entry = &wifi_pkg->package.elements[idx++];
759 if ((entry->type != ACPI_TYPE_INTEGER) ||
Christophe Jailletaae9d562017-07-14 12:06:59 +0200760 (entry->integer.value > U8_MAX)) {
761 ret = -EINVAL;
762 goto out_free;
763 }
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200764
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300765 mvm->geo_profiles[i].values[j] = entry->integer.value;
766 }
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200767 }
768 ret = 0;
769out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300770 kfree(data);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200771 return ret;
772}
773
Luca Coelho42ce76d2017-01-11 23:36:30 +0200774int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300775{
Luca Coelhoda2830a2016-05-30 13:00:44 +0300776 struct iwl_dev_tx_power_cmd cmd = {
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300777 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
Luca Coelhoda2830a2016-05-30 13:00:44 +0300778 };
Luca Coelho42ce76d2017-01-11 23:36:30 +0200779 int i, j, idx;
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300780 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
Luca Coelho55bfa4b2016-06-29 00:38:40 +0300781 int len = sizeof(cmd);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300782
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300783 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
784 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
785 ACPI_SAR_TABLE_SIZE);
Luca Coelho42ce76d2017-01-11 23:36:30 +0200786
Luca Coelho55bfa4b2016-06-29 00:38:40 +0300787 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
788 len = sizeof(cmd.v3);
789
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300790 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
Luca Coelho42ce76d2017-01-11 23:36:30 +0200791 struct iwl_mvm_sar_profile *prof;
792
793 /* don't allow SAR to be disabled (profile 0 means disable) */
794 if (profs[i] == 0)
795 return -EPERM;
796
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300797 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
798 if (profs[i] > ACPI_SAR_PROFILE_NUM)
Luca Coelho42ce76d2017-01-11 23:36:30 +0200799 return -EINVAL;
800
801 /* profiles go from 1 to 4, so decrement to access the array */
802 prof = &mvm->sar_profiles[profs[i] - 1];
803
804 /* if the profile is disabled, do nothing */
805 if (!prof->enabled) {
806 IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
807 profs[i]);
808 /* if one of the profiles is disabled, we fail all */
809 return -ENOENT;
810 }
811
812 IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300813 for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
814 idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
Luca Coelho42ce76d2017-01-11 23:36:30 +0200815 cmd.v3.per_chain_restriction[i][j] =
816 cpu_to_le16(prof->table[idx]);
817 IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
818 j, prof->table[idx]);
819 }
820 }
821
822 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
823
824 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
825}
826
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300827int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
828{
829 struct iwl_geo_tx_power_profiles_resp *resp;
830 int ret;
831
832 struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
833 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
834 };
835 struct iwl_host_cmd cmd = {
836 .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
837 .len = { sizeof(geo_cmd), },
838 .flags = CMD_WANT_SKB,
839 .data = { &geo_cmd },
840 };
841
842 ret = iwl_mvm_send_cmd(mvm, &cmd);
843 if (ret) {
844 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
845 return ret;
846 }
847
848 resp = (void *)cmd.resp_pkt->data;
849 ret = le32_to_cpu(resp->profile_idx);
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300850 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300851 ret = -EIO;
852 IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
853 }
854
855 iwl_free_resp(&cmd);
856 return ret;
857}
858
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200859static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
860{
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200861 struct iwl_geo_tx_power_profiles_cmd cmd = {
862 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
863 };
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300864 int ret, i, j;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200865 u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
866
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300867 ret = iwl_mvm_sar_get_wgds_table(mvm);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200868 if (ret < 0) {
869 IWL_DEBUG_RADIO(mvm,
870 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
871 ret);
872 /* we don't fail if the table is not available */
873 return 0;
874 }
875
876 IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
877
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300878 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200879 ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE);
880
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300881 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
882
883 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200884 struct iwl_per_chain_offset *chain =
885 (struct iwl_per_chain_offset *)&cmd.table[i];
886
887 for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
888 u8 *value;
889
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300890 value = &mvm->geo_profiles[i].values[j *
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300891 ACPI_GEO_PER_CHAIN_SIZE];
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200892 chain[j].max_tx_power = cpu_to_le16(value[0]);
893 chain[j].chain_a = value[1];
894 chain[j].chain_b = value[2];
895 IWL_DEBUG_RADIO(mvm,
896 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
897 i, j, value[1], value[2], value[0]);
898 }
899 }
900 return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
901}
902
Luca Coelho69964902017-01-12 12:43:12 +0200903#else /* CONFIG_ACPI */
904static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
905{
906 return -ENOENT;
907}
908
909static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
910{
911 return -ENOENT;
912}
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200913
914static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
915{
916 return 0;
917}
Luca Coelho18f17552017-07-26 15:20:18 +0300918
919int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a,
920 int prof_b)
921{
922 return -ENOENT;
923}
924
925int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
926{
927 return -ENOENT;
928}
Luca Coelho69964902017-01-12 12:43:12 +0200929#endif /* CONFIG_ACPI */
930
Luca Coelho42ce76d2017-01-11 23:36:30 +0200931static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
932{
933 int ret;
934
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200935 ret = iwl_mvm_sar_get_wrds_table(mvm);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300936 if (ret < 0) {
937 IWL_DEBUG_RADIO(mvm,
Luca Coelho69964902017-01-12 12:43:12 +0200938 "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
Luca Coelhoda2830a2016-05-30 13:00:44 +0300939 ret);
Luca Coelho69964902017-01-12 12:43:12 +0200940 /* if not available, don't fail and don't bother with EWRD */
Luca Coelhoda2830a2016-05-30 13:00:44 +0300941 return 0;
942 }
943
Luca Coelho69964902017-01-12 12:43:12 +0200944 ret = iwl_mvm_sar_get_ewrd_table(mvm);
945 /* if EWRD is not available, we can still use WRDS, so don't fail */
946 if (ret < 0)
947 IWL_DEBUG_RADIO(mvm,
948 "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
949 ret);
950
Luca Coelho42ce76d2017-01-11 23:36:30 +0200951 /* choose profile 1 (WRDS) as default for both chains */
952 ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
953
954 /* if we don't have profile 0 from BIOS, just skip it */
955 if (ret == -ENOENT)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300956 return 0;
957
Luca Coelhoda2830a2016-05-30 13:00:44 +0300958 return ret;
959}
960
Sara Sharon1f370652016-08-31 18:13:57 +0300961static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
962{
963 int ret;
964
Johannes Berg7d6222e22017-06-08 09:18:22 +0200965 if (iwl_mvm_has_unified_ucode(mvm))
Sara Sharon1f370652016-08-31 18:13:57 +0300966 return iwl_run_unified_mvm_ucode(mvm, false);
967
968 ret = iwl_run_init_mvm_ucode(mvm, false);
969
Sara Sharon1f370652016-08-31 18:13:57 +0300970 if (ret) {
971 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
Liad Kaufmanf4744252017-11-23 10:29:04 +0200972
973 if (iwlmvm_mod_params.init_dbg)
974 return 0;
Sara Sharon1f370652016-08-31 18:13:57 +0300975 return ret;
976 }
977
978 /*
979 * Stop and start the transport without entering low power
980 * mode. This will save the state of other components on the
981 * device that are triggered by the INIT firwmare (MFUART).
982 */
983 _iwl_trans_stop_device(mvm->trans, false);
984 ret = _iwl_trans_start_hw(mvm->trans, false);
985 if (ret)
986 return ret;
987
988 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
989 if (ret)
990 return ret;
991
Johannes Berg702e9752017-06-02 11:56:58 +0200992 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
Sara Sharon1f370652016-08-31 18:13:57 +0300993}
994
Johannes Berg8ca151b2013-01-24 14:25:36 +0100995int iwl_mvm_up(struct iwl_mvm *mvm)
996{
997 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +0300998 struct ieee80211_channel *chan;
999 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001000
1001 lockdep_assert_held(&mvm->mutex);
1002
1003 ret = iwl_trans_start_hw(mvm->trans);
1004 if (ret)
1005 return ret;
1006
Sara Sharon1f370652016-08-31 18:13:57 +03001007 ret = iwl_mvm_load_rt_fw(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001008 if (ret) {
1009 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1010 goto error;
1011 }
1012
Johannes Bergd0b813f2017-06-01 14:44:40 +02001013 iwl_get_shared_mem_conf(&mvm->fwrt);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001014
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001015 ret = iwl_mvm_sf_update(mvm, NULL, false);
1016 if (ret)
1017 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1018
Johannes Berg7174beb2017-06-01 16:03:19 +02001019 mvm->fwrt.dump.conf = FW_DBG_INVALID;
Emmanuel Grumbach945d4202015-02-15 17:16:16 +02001020 /* if we have a destination, assume EARLY START */
1021 if (mvm->fw->dbg_dest_tlv)
Johannes Berg7174beb2017-06-01 16:03:19 +02001022 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1023 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
Liad Kaufman6a951262014-11-17 11:36:21 +02001024
Moshe Harela0544272014-12-08 21:13:14 +02001025 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001026 if (ret)
1027 goto error;
1028
Johannes Berg7d6222e22017-06-08 09:18:22 +02001029 if (!iwl_mvm_has_unified_ucode(mvm)) {
1030 /* Send phy db control command and then phy db calibration */
Sara Sharon1f370652016-08-31 18:13:57 +03001031 ret = iwl_send_phy_db_data(mvm->phy_db);
1032 if (ret)
1033 goto error;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001034
Sara Sharon1f370652016-08-31 18:13:57 +03001035 ret = iwl_send_phy_cfg_cmd(mvm);
1036 if (ret)
1037 goto error;
1038 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001039
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +03001040 ret = iwl_mvm_send_bt_init_conf(mvm);
1041 if (ret)
1042 goto error;
1043
Sara Sharon43413a92015-12-31 11:49:18 +02001044 /* Init RSS configuration */
Sara Sharon8edbfaa2018-02-05 12:42:44 +02001045 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
1046 ret = iwl_configure_rxq(mvm);
1047 if (ret) {
1048 IWL_ERR(mvm, "Failed to configure RX queues: %d\n",
1049 ret);
1050 goto error;
1051 }
1052 }
1053
1054 if (iwl_mvm_has_new_rx_api(mvm)) {
Sara Sharon43413a92015-12-31 11:49:18 +02001055 ret = iwl_send_rss_cfg_cmd(mvm);
1056 if (ret) {
1057 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1058 ret);
1059 goto error;
1060 }
1061 }
1062
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063 /* init the fw <-> mac80211 STA mapping */
Sara Sharon0ae98812017-01-04 14:53:58 +02001064 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001065 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1066
Sara Sharon0ae98812017-01-04 14:53:58 +02001067 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001068
Johannes Bergb2b78752014-09-08 16:42:54 +02001069 /* reset quota debouncing buffer - 0xff will yield invalid data */
1070 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1071
Johannes Bergc8f54702017-06-19 23:50:31 +02001072 ret = iwl_mvm_send_dqa_cmd(mvm);
1073 if (ret)
1074 goto error;
Liad Kaufman97d5be72015-08-31 14:33:23 +03001075
Johannes Berg8ca151b2013-01-24 14:25:36 +01001076 /* Add auxiliary station for scanning */
1077 ret = iwl_mvm_add_aux_sta(mvm);
1078 if (ret)
1079 goto error;
1080
Ilan Peer53a9d612013-04-28 11:55:08 +03001081 /* Add all the PHY contexts */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001082 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
Ilan Peer53a9d612013-04-28 11:55:08 +03001083 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1084 for (i = 0; i < NUM_PHY_CTX; i++) {
1085 /*
1086 * The channel used here isn't relevant as it's
1087 * going to be overwritten in the other flows.
1088 * For now use the first channel we have.
1089 */
1090 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1091 &chandef, 1, 1);
1092 if (ret)
1093 goto error;
1094 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001095
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001096#ifdef CONFIG_THERMAL
1097 if (iwl_mvm_is_tt_in_fw(mvm)) {
1098 /* in order to give the responsibility of ct-kill and
1099 * TX backoff to FW we need to send empty temperature reporting
1100 * cmd during init time
1101 */
1102 iwl_mvm_send_temp_report_ths_cmd(mvm);
1103 } else {
1104 /* Initialize tx backoffs to the minimal possible */
1105 iwl_mvm_tt_tx_backoff(mvm, 0);
1106 }
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001107
1108 /* TODO: read the budget from BIOS / Platform NVM */
Chaya Rachel Ivgi944eafc2017-07-09 16:35:14 +03001109
1110 /*
1111 * In case there is no budget from BIOS / Platform NVM the default
1112 * budget should be 2000mW (cooling state 0).
1113 */
1114 if (iwl_mvm_is_ctdp_supported(mvm)) {
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001115 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1116 mvm->cooling_dev.cur_state);
Luca Coelho75cfe332016-09-14 11:54:36 +03001117 if (ret)
1118 goto error;
1119 }
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001120#else
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001121 /* Initialize tx backoffs to the minimal possible */
1122 iwl_mvm_tt_tx_backoff(mvm, 0);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001123#endif
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001124
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +02001125 WARN_ON(iwl_mvm_config_ltr(mvm));
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +03001126
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001127 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001128 if (ret)
1129 goto error;
1130
Arik Nemtsov35af15d2015-03-04 15:08:00 +02001131 /*
1132 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1133 * anyway, so don't init MCC.
1134 */
1135 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1136 ret = iwl_mvm_init_mcc(mvm);
1137 if (ret)
1138 goto error;
1139 }
Arik Nemtsov90d4f7d2014-03-04 19:58:46 +02001140
Johannes Berg859d9142015-06-01 17:11:11 +02001141 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Emmanuel Grumbach4ca87a52016-01-03 22:23:40 +02001142 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
Sara Sharonb66b5812017-01-31 10:39:44 +02001143 mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
David Spinadeld2496222014-05-20 12:46:37 +03001144 ret = iwl_mvm_config_scan(mvm);
1145 if (ret)
1146 goto error;
1147 }
1148
Eliad Peller7498cf42014-01-16 17:10:44 +02001149 /* allow FW/transport low power modes if not during restart */
1150 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1151 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1152
Luca Coelhoda2830a2016-05-30 13:00:44 +03001153 ret = iwl_mvm_sar_init(mvm);
1154 if (ret)
1155 goto error;
1156
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +02001157 ret = iwl_mvm_sar_geo_init(mvm);
1158 if (ret)
1159 goto error;
1160
Johannes Berg7089ae62017-06-28 16:19:49 +02001161 iwl_mvm_leds_sync(mvm);
1162
Ilan Peer53a9d612013-04-28 11:55:08 +03001163 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001164 return 0;
1165 error:
Liad Kaufmanf4744252017-11-23 10:29:04 +02001166 if (!iwlmvm_mod_params.init_dbg || !ret)
Liad Kaufmande8ba412017-03-16 13:00:59 +02001167 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001168 return ret;
1169}
1170
1171int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1172{
1173 int ret, i;
1174
1175 lockdep_assert_held(&mvm->mutex);
1176
1177 ret = iwl_trans_start_hw(mvm->trans);
1178 if (ret)
1179 return ret;
1180
1181 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1182 if (ret) {
1183 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1184 goto error;
1185 }
1186
Moshe Harela0544272014-12-08 21:13:14 +02001187 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001188 if (ret)
1189 goto error;
1190
1191 /* Send phy db control command and then phy db calibration*/
1192 ret = iwl_send_phy_db_data(mvm->phy_db);
1193 if (ret)
1194 goto error;
1195
1196 ret = iwl_send_phy_cfg_cmd(mvm);
1197 if (ret)
1198 goto error;
1199
1200 /* init the fw <-> mac80211 STA mapping */
Sara Sharon0ae98812017-01-04 14:53:58 +02001201 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001202 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1203
1204 /* Add auxiliary station for scanning */
1205 ret = iwl_mvm_add_aux_sta(mvm);
1206 if (ret)
1207 goto error;
1208
1209 return 0;
1210 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001211 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001212 return ret;
1213}
1214
Johannes Berg04168412015-06-23 21:22:09 +02001215void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1216 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001217{
1218 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1219 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1220 u32 flags = le32_to_cpu(card_state_notif->flags);
1221
1222 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1223 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1224 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1225 (flags & CT_KILL_CARD_DISABLED) ?
1226 "Reached" : "Not reached");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001227}
1228
Johannes Berg04168412015-06-23 21:22:09 +02001229void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1230 struct iwl_rx_cmd_buffer *rxb)
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001231{
1232 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1233 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1234
Golan Ben-Ami0c8d0a42017-01-25 15:11:30 +02001235 IWL_DEBUG_INFO(mvm,
1236 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1237 le32_to_cpu(mfuart_notif->installed_ver),
1238 le32_to_cpu(mfuart_notif->external_ver),
1239 le32_to_cpu(mfuart_notif->status),
1240 le32_to_cpu(mfuart_notif->duration));
1241
Golan Ben-Ami19f63c52016-11-07 17:40:43 +02001242 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1243 IWL_DEBUG_INFO(mvm,
Golan Ben-Ami0c8d0a42017-01-25 15:11:30 +02001244 "MFUART: image size: 0x%08x\n",
Golan Ben-Ami19f63c52016-11-07 17:40:43 +02001245 le32_to_cpu(mfuart_notif->image_size));
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001246}