blob: 96d26b7499523ad0793202e329b25eff58dc8504 [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 *
Johannes Berg8ca151b2013-01-24 14:25:36 +010022 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020023 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010024 *
25 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020026 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *
29 * BSD LICENSE
30 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020031 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eran Harary8d193ca2015-04-27 10:29:31 +030032 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Golan Ben-Amibdccdb82016-11-15 14:45:29 +020033 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +020034 * Copyright(c) 2018 Intel Corporation
Johannes Berg8ca151b2013-01-24 14:25:36 +010035 * All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 *
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
46 * distribution.
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *
63 *****************************************************************************/
64#include <net/mac80211.h>
Sara Sharon854d7732016-03-22 15:55:58 +020065#include <linux/netdevice.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010066
67#include "iwl-trans.h"
68#include "iwl-op-mode.h"
Johannes Bergd962f9b2017-06-01 10:22:09 +020069#include "fw/img.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include "iwl-debug.h"
71#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
72#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +020073#include "iwl-prph.h"
Luca Coelho813df5c2017-09-19 12:35:18 +030074#include "fw/acpi.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010075
76#include "mvm.h"
Johannes Berg7174beb2017-06-01 16:03:19 +020077#include "fw/dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010078#include "iwl-phy-db.h"
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +020079#include "iwl-modparams.h"
80#include "iwl-nvm-parse.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010081
82#define MVM_UCODE_ALIVE_TIMEOUT HZ
83#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
84
85#define UCODE_VALID_OK cpu_to_le32(0x1)
86
Johannes Berg8ca151b2013-01-24 14:25:36 +010087struct iwl_mvm_alive_data {
88 bool valid;
89 u32 scd_base_addr;
90};
91
Johannes Berg8ca151b2013-01-24 14:25:36 +010092static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
93{
94 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
95 .valid = cpu_to_le32(valid_tx_ant),
96 };
97
Emmanuel Grumbach33223542013-03-09 20:38:19 +020098 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +030099 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100 sizeof(tx_ant_cmd), &tx_ant_cmd);
101}
102
Sara Sharon43413a92015-12-31 11:49:18 +0200103static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
104{
105 int i;
106 struct iwl_rss_config_cmd cmd = {
107 .flags = cpu_to_le32(IWL_RSS_ENABLE),
108 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200109 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200110 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
111 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200112 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200113 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
114 };
115
Sara Sharonf43495f2016-05-04 14:22:10 +0300116 if (mvm->trans->num_rx_queues == 1)
117 return 0;
118
Sara Sharon854d7732016-03-22 15:55:58 +0200119 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
Sara Sharon43413a92015-12-31 11:49:18 +0200120 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
Sara Sharon854d7732016-03-22 15:55:58 +0200121 cmd.indirection_table[i] =
122 1 + (i % (mvm->trans->num_rx_queues - 1));
123 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200124
125 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
126}
127
Sara Sharon8edbfaa2018-02-05 12:42:44 +0200128static int iwl_configure_rxq(struct iwl_mvm *mvm)
129{
130 int i, num_queues, size;
131 struct iwl_rfh_queue_config *cmd;
132
133 /* Do not configure default queue, it is configured via context info */
134 num_queues = mvm->trans->num_rx_queues - 1;
135
136 size = sizeof(*cmd) + num_queues * sizeof(struct iwl_rfh_queue_data);
137
138 cmd = kzalloc(size, GFP_KERNEL);
139 if (!cmd)
140 return -ENOMEM;
141
142 cmd->num_queues = num_queues;
143
144 for (i = 0; i < num_queues; i++) {
145 struct iwl_trans_rxq_dma_data data;
146
147 cmd->data[i].q_num = i + 1;
148 iwl_trans_get_rxq_dma_data(mvm->trans, i + 1, &data);
149
150 cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
151 cmd->data[i].urbd_stts_wrptr =
152 cpu_to_le64(data.urbd_stts_wrptr);
153 cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
154 cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
155 }
156
157 return iwl_mvm_send_cmd_pdu(mvm,
158 WIDE_ID(DATA_PATH_GROUP,
159 RFH_QUEUE_CONFIG_CMD),
160 0, size, cmd);
161}
162
Liad Kaufman97d5be72015-08-31 14:33:23 +0300163static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
164{
165 struct iwl_dqa_enable_cmd dqa_cmd = {
166 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
167 };
168 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
169 int ret;
170
171 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
172 if (ret)
173 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
174 else
175 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
176
177 return ret;
178}
179
Golan Ben-Amibdccdb82016-11-15 14:45:29 +0200180void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
181 struct iwl_rx_cmd_buffer *rxb)
182{
183 struct iwl_rx_packet *pkt = rxb_addr(rxb);
184 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
185 __le32 *dump_data = mfu_dump_notif->data;
186 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
187 int i;
188
189 if (mfu_dump_notif->index_num == 0)
190 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
191 le32_to_cpu(mfu_dump_notif->assert_id));
192
193 for (i = 0; i < n_words; i++)
194 IWL_DEBUG_INFO(mvm,
195 "MFUART assert dump, dword %u: 0x%08x\n",
196 le16_to_cpu(mfu_dump_notif->index_num) *
197 n_words + i,
198 le32_to_cpu(dump_data[i]));
199}
200
Johannes Berg8ca151b2013-01-24 14:25:36 +0100201static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
202 struct iwl_rx_packet *pkt, void *data)
203{
204 struct iwl_mvm *mvm =
205 container_of(notif_wait, struct iwl_mvm, notif_wait);
206 struct iwl_mvm_alive_data *alive_data = data;
Sara Sharon5c228d62016-11-24 13:48:27 +0200207 struct mvm_alive_resp_v3 *palive3;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200208 struct mvm_alive_resp *palive;
Sara Sharon5c228d62016-11-24 13:48:27 +0200209 struct iwl_umac_alive *umac;
210 struct iwl_lmac_alive *lmac1;
211 struct iwl_lmac_alive *lmac2 = NULL;
212 u16 status;
Luca Coelho3485e762017-10-02 16:12:23 +0300213 u32 umac_error_event_table;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100214
Sara Sharon5c228d62016-11-24 13:48:27 +0200215 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200216 palive = (void *)pkt->data;
Sara Sharon5c228d62016-11-24 13:48:27 +0200217 umac = &palive->umac_data;
218 lmac1 = &palive->lmac_data[0];
219 lmac2 = &palive->lmac_data[1];
220 status = le16_to_cpu(palive->status);
221 } else {
222 palive3 = (void *)pkt->data;
223 umac = &palive3->umac_data;
224 lmac1 = &palive3->lmac_data;
225 status = le16_to_cpu(palive3->status);
Eran Harary01a9ca52014-02-03 09:29:57 +0200226 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100227
Sara Sharon5c228d62016-11-24 13:48:27 +0200228 mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
229 if (lmac2)
230 mvm->error_event_table[1] =
231 le32_to_cpu(lmac2->error_event_table_ptr);
232 mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
Sara Sharon5c228d62016-11-24 13:48:27 +0200233
Luca Coelho3485e762017-10-02 16:12:23 +0300234 umac_error_event_table = le32_to_cpu(umac->error_info_addr);
Sara Sharon5c228d62016-11-24 13:48:27 +0200235
Luca Coelho3485e762017-10-02 16:12:23 +0300236 if (!umac_error_event_table) {
237 mvm->support_umac_log = false;
238 } else if (umac_error_event_table >=
239 mvm->trans->cfg->min_umac_error_event_table) {
240 mvm->support_umac_log = true;
241 mvm->umac_error_event_table = umac_error_event_table;
242 } else {
Luca Coelhofb5b2842017-10-02 15:44:20 +0300243 IWL_ERR(mvm,
244 "Not valid error log pointer 0x%08X for %s uCode\n",
245 mvm->umac_error_event_table,
246 (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
247 "Init" : "RT");
Luca Coelho3485e762017-10-02 16:12:23 +0300248 mvm->support_umac_log = false;
249 }
Luca Coelhofb5b2842017-10-02 15:44:20 +0300250
Sara Sharon5c228d62016-11-24 13:48:27 +0200251 alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
252 alive_data->valid = status == IWL_ALIVE_STATUS_OK;
Sara Sharon5c228d62016-11-24 13:48:27 +0200253
254 IWL_DEBUG_FW(mvm,
255 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
256 status, lmac1->ver_type, lmac1->ver_subtype);
257
258 if (lmac2)
259 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
260
261 IWL_DEBUG_FW(mvm,
262 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
263 le32_to_cpu(umac->umac_major),
264 le32_to_cpu(umac->umac_minor));
265
Johannes Berg8ca151b2013-01-24 14:25:36 +0100266 return true;
267}
268
Sara Sharon1f370652016-08-31 18:13:57 +0300269static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
270 struct iwl_rx_packet *pkt, void *data)
271{
272 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
273
274 return true;
275}
276
Johannes Berg8ca151b2013-01-24 14:25:36 +0100277static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
278 struct iwl_rx_packet *pkt, void *data)
279{
280 struct iwl_phy_db *phy_db = data;
281
282 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
283 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
284 return true;
285 }
286
Sara Sharonce1f2772016-04-10 16:02:12 +0300287 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100288
289 return false;
290}
291
292static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
293 enum iwl_ucode_type ucode_type)
294{
295 struct iwl_notification_wait alive_wait;
296 struct iwl_mvm_alive_data alive_data;
297 const struct fw_img *fw;
298 int ret, i;
Johannes Berg702e9752017-06-02 11:56:58 +0200299 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300300 static const u16 alive_cmd[] = { MVM_ALIVE };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100301
Eran Harary61df7502014-12-01 17:40:37 +0200302 if (ucode_type == IWL_UCODE_REGULAR &&
Golan Ben-Ami3d2d4422016-02-23 10:34:48 +0200303 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
304 !(fw_has_capa(&mvm->fw->ucode_capa,
305 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
Sharon Dvir612da1e2016-08-03 10:55:45 +0300306 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
Eran Harary61df7502014-12-01 17:40:37 +0200307 else
Sharon Dvir612da1e2016-08-03 10:55:45 +0300308 fw = iwl_get_ucode_image(mvm->fw, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200309 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100310 return -EINVAL;
Johannes Berg702e9752017-06-02 11:56:58 +0200311 iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
Johannes Berg65b280f2017-03-22 22:10:36 +0100312 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313
314 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
315 alive_cmd, ARRAY_SIZE(alive_cmd),
316 iwl_alive_fn, &alive_data);
317
318 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
319 if (ret) {
Johannes Berg702e9752017-06-02 11:56:58 +0200320 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100321 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
322 return ret;
323 }
324
325 /*
326 * Some things may run in the background now, but we
327 * just wait for the ALIVE notification here.
328 */
329 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
330 MVM_UCODE_ALIVE_TIMEOUT);
331 if (ret) {
Sara Sharond6be9c12017-01-12 11:31:25 +0200332 struct iwl_trans *trans = mvm->trans;
333
Golan Ben Ami5f01df32018-02-07 20:08:56 +0200334 if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000)
Dor Shaish192de2b2015-07-15 11:41:21 +0300335 IWL_ERR(mvm,
336 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
Sara Sharond6be9c12017-01-12 11:31:25 +0200337 iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
338 iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
Sara Sharon6e584872017-03-22 14:07:50 +0200339 else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
Sara Sharond6be9c12017-01-12 11:31:25 +0200340 IWL_ERR(mvm,
341 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
342 iwl_read_prph(trans, SB_CPU_1_STATUS),
343 iwl_read_prph(trans, SB_CPU_2_STATUS));
Johannes Berg702e9752017-06-02 11:56:58 +0200344 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100345 return ret;
346 }
347
348 if (!alive_data.valid) {
349 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
Johannes Berg702e9752017-06-02 11:56:58 +0200350 iwl_fw_set_current_image(&mvm->fwrt, old_type);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100351 return -EIO;
352 }
353
354 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
355
356 /*
357 * Note: all the queues are enabled as part of the interface
358 * initialization, but in firmware restart scenarios they
359 * could be stopped, so wake them up. In firmware restart,
360 * mac80211 will have the queues stopped as well until the
361 * reconfiguration completes. During normal startup, they
362 * will be empty.
363 */
364
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300365 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
Johannes Bergc8f54702017-06-19 23:50:31 +0200366 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100367
Johannes Bergdf197c02014-08-01 18:14:45 +0200368 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
369 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100370
Johannes Berg65b280f2017-03-22 22:10:36 +0100371 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372
373 return 0;
374}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100376static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
377{
378 struct iwl_notification_wait init_wait;
379 struct iwl_nvm_access_complete_cmd nvm_complete = {};
380 struct iwl_init_extended_cfg_cmd init_cfg = {
381 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
382 };
383 static const u16 init_complete[] = {
384 INIT_COMPLETE_NOTIF,
385 };
386 int ret;
387
388 lockdep_assert_held(&mvm->mutex);
389
390 iwl_init_notification_wait(&mvm->notif_wait,
391 &init_wait,
392 init_complete,
393 ARRAY_SIZE(init_complete),
394 iwl_wait_init_complete,
395 NULL);
396
397 /* Will also start the device */
398 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
399 if (ret) {
400 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
401 goto error;
402 }
403
404 /* Send init config command to mark that we are sending NVM access
405 * commands
406 */
407 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
408 INIT_EXTENDED_CFG_CMD), 0,
409 sizeof(init_cfg), &init_cfg);
410 if (ret) {
411 IWL_ERR(mvm, "Failed to run init config command: %d\n",
412 ret);
413 goto error;
414 }
415
Sara Sharone9e1ba32017-01-08 16:46:14 +0200416 /* Load NVM to NIC if needed */
417 if (mvm->nvm_file_name) {
Shaul Triebitz9c4f7d52018-01-14 19:06:09 +0200418 iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
419 mvm->nvm_sections);
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100420 iwl_mvm_load_nvm_to_nic(mvm);
Sara Sharone9e1ba32017-01-08 16:46:14 +0200421 }
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100422
Sara Sharond4f36952017-03-06 11:13:02 +0200423 if (IWL_MVM_PARSE_NVM && read_nvm) {
Luca Coelho5bd1d2c2017-08-15 18:46:44 +0300424 ret = iwl_nvm_init(mvm);
Sara Sharond4f36952017-03-06 11:13:02 +0200425 if (ret) {
426 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
427 goto error;
428 }
429 }
430
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100431 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
432 NVM_ACCESS_COMPLETE), 0,
433 sizeof(nvm_complete), &nvm_complete);
434 if (ret) {
435 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
436 ret);
437 goto error;
438 }
439
440 /* We wait for the INIT complete notification */
Sara Sharone9e1ba32017-01-08 16:46:14 +0200441 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
442 MVM_UCODE_ALIVE_TIMEOUT);
443 if (ret)
444 return ret;
445
446 /* Read the NVM only at driver load time, no need to do this twice */
Sara Sharond4f36952017-03-06 11:13:02 +0200447 if (!IWL_MVM_PARSE_NVM && read_nvm) {
Shaul Triebitz4c625c52018-01-24 16:12:49 +0200448 mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
Shaul Triebitzc135cb52017-06-22 17:09:08 +0300449 if (IS_ERR(mvm->nvm_data)) {
450 ret = PTR_ERR(mvm->nvm_data);
451 mvm->nvm_data = NULL;
Sara Sharone9e1ba32017-01-08 16:46:14 +0200452 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
453 return ret;
454 }
455 }
456
457 return 0;
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100458
459error:
460 iwl_remove_notification(&mvm->notif_wait, &init_wait);
461 return ret;
462}
463
Johannes Berg8ca151b2013-01-24 14:25:36 +0100464static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
465{
466 struct iwl_phy_cfg_cmd phy_cfg_cmd;
Johannes Berg702e9752017-06-02 11:56:58 +0200467 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100468
469 /* Set parameters */
Moshe Harela0544272014-12-08 21:13:14 +0200470 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
Luca Coelho86a2b202018-02-21 22:18:59 +0200471
472 /* set flags extra PHY configuration flags from the device's cfg */
473 phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags);
474
Johannes Berg8ca151b2013-01-24 14:25:36 +0100475 phy_cfg_cmd.calib_control.event_trigger =
476 mvm->fw->default_calib[ucode_type].event_trigger;
477 phy_cfg_cmd.calib_control.flow_trigger =
478 mvm->fw->default_calib[ucode_type].flow_trigger;
479
480 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
481 phy_cfg_cmd.phy_cfg);
482
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300483 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100484 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
485}
486
Johannes Berg8ca151b2013-01-24 14:25:36 +0100487int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
488{
489 struct iwl_notification_wait calib_wait;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300490 static const u16 init_complete[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100491 INIT_COMPLETE_NOTIF,
492 CALIB_RES_NOTIF_PHY_DB
493 };
494 int ret;
495
Johannes Berg7d6222e22017-06-08 09:18:22 +0200496 if (iwl_mvm_has_unified_ucode(mvm))
Johannes Berg8c5f47b2017-02-20 17:47:04 +0100497 return iwl_run_unified_mvm_ucode(mvm, true);
498
Johannes Berg8ca151b2013-01-24 14:25:36 +0100499 lockdep_assert_held(&mvm->mutex);
500
Eran Harary8d193ca2015-04-27 10:29:31 +0300501 if (WARN_ON_ONCE(mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100502 return 0;
503
504 iwl_init_notification_wait(&mvm->notif_wait,
505 &calib_wait,
506 init_complete,
507 ARRAY_SIZE(init_complete),
508 iwl_wait_phy_db_entry,
509 mvm->phy_db);
510
511 /* Will also start the device */
512 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
513 if (ret) {
514 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300515 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100516 }
517
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +0300518 if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
519 ret = iwl_mvm_send_bt_init_conf(mvm);
520 if (ret)
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300521 goto remove_notif;
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +0300522 }
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200523
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200524 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100525 if (read_nvm) {
Luca Coelho5bd1d2c2017-08-15 18:46:44 +0300526 ret = iwl_nvm_init(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100527 if (ret) {
528 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300529 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100530 }
531 }
532
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200533 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300534 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200535 iwl_mvm_load_nvm_to_nic(mvm);
536
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300537 WARN_ON(iwl_nvm_check_version(mvm->nvm_data, mvm->trans));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100538
Eran Harary4f593342013-05-13 07:53:26 +0300539 /*
540 * abort after reading the nvm in case RF Kill is on, we will complete
541 * the init seq later when RF kill will switch to off
542 */
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300543 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300544 IWL_DEBUG_RF_KILL(mvm,
545 "jump over all phy activities due to RF kill\n");
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300546 goto remove_notif;
Eran Harary4f593342013-05-13 07:53:26 +0300547 }
548
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200549 mvm->calibrating = true;
550
Dor Shaishe07cbb52013-02-27 23:00:27 +0200551 /* Send TX valid antennas before triggering calibrations */
Moshe Harela0544272014-12-08 21:13:14 +0200552 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Dor Shaishe07cbb52013-02-27 23:00:27 +0200553 if (ret)
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300554 goto remove_notif;
Dor Shaishe07cbb52013-02-27 23:00:27 +0200555
Johannes Berg8ca151b2013-01-24 14:25:36 +0100556 ret = iwl_send_phy_cfg_cmd(mvm);
557 if (ret) {
558 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
559 ret);
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300560 goto remove_notif;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100561 }
562
563 /*
564 * Some things may run in the background now, but we
565 * just wait for the calibration complete notification.
566 */
567 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300568 MVM_UCODE_CALIB_TIMEOUT);
569 if (!ret)
570 goto out;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200571
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300572 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200573 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300574 ret = 0;
575 } else {
576 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
577 ret);
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200578 }
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300579
Johannes Berg8ca151b2013-01-24 14:25:36 +0100580 goto out;
581
Luca Coelho00e0c6c2017-07-24 14:47:52 +0300582remove_notif:
Johannes Berg8ca151b2013-01-24 14:25:36 +0100583 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
584out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200585 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200586 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100587 /* we want to debug INIT and we have no NVM - fake */
588 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
589 sizeof(struct ieee80211_channel) +
590 sizeof(struct ieee80211_rate),
591 GFP_KERNEL);
592 if (!mvm->nvm_data)
593 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100594 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
595 mvm->nvm_data->bands[0].n_channels = 1;
596 mvm->nvm_data->bands[0].n_bitrates = 1;
597 mvm->nvm_data->bands[0].bitrates =
598 (void *)mvm->nvm_data->channels + 1;
599 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
600 }
601
602 return ret;
603}
604
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200605static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
606{
607 struct iwl_ltr_config_cmd cmd = {
608 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
609 };
610
611 if (!mvm->trans->ltr_enabled)
612 return 0;
613
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200614 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
615 sizeof(cmd), &cmd);
616}
617
Luca Coelhoda2830a2016-05-30 13:00:44 +0300618#ifdef CONFIG_ACPI
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200619static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
620 union acpi_object *table,
621 struct iwl_mvm_sar_profile *profile,
622 bool enabled)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300623{
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200624 int i;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300625
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200626 profile->enabled = enabled;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300627
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300628 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200629 if ((table[i].type != ACPI_TYPE_INTEGER) ||
630 (table[i].integer.value > U8_MAX))
Luca Coelhoda2830a2016-05-30 13:00:44 +0300631 return -EINVAL;
632
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200633 profile->table[i] = table[i].integer.value;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300634 }
635
636 return 0;
637}
638
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200639static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
640{
Luca Coelho813df5c2017-09-19 12:35:18 +0300641 union acpi_object *wifi_pkg, *table, *data;
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200642 bool enabled;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300643 int ret;
644
Luca Coelho813df5c2017-09-19 12:35:18 +0300645 data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD);
646 if (IS_ERR(data))
647 return PTR_ERR(data);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300648
Luca Coelho2fa388c2017-09-21 14:30:53 +0300649 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
650 ACPI_WRDS_WIFI_DATA_SIZE);
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200651 if (IS_ERR(wifi_pkg)) {
652 ret = PTR_ERR(wifi_pkg);
653 goto out_free;
654 }
Luca Coelhoda2830a2016-05-30 13:00:44 +0300655
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200656 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
657 ret = -EINVAL;
658 goto out_free;
659 }
660
661 enabled = !!(wifi_pkg->package.elements[1].integer.value);
662
663 /* position of the actual table */
664 table = &wifi_pkg->package.elements[2];
665
666 /* The profile from WRDS is officially profile 1, but goes
667 * into sar_profiles[0] (because we don't have a profile 0).
668 */
669 ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
670 enabled);
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200671out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300672 kfree(data);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300673 return ret;
674}
Luca Coelhoda2830a2016-05-30 13:00:44 +0300675
Luca Coelho69964902017-01-12 12:43:12 +0200676static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
677{
Luca Coelho813df5c2017-09-19 12:35:18 +0300678 union acpi_object *wifi_pkg, *data;
Luca Coelho69964902017-01-12 12:43:12 +0200679 bool enabled;
680 int i, n_profiles, ret;
681
Luca Coelho813df5c2017-09-19 12:35:18 +0300682 data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD);
683 if (IS_ERR(data))
684 return PTR_ERR(data);
Luca Coelho69964902017-01-12 12:43:12 +0200685
Luca Coelho2fa388c2017-09-21 14:30:53 +0300686 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
687 ACPI_EWRD_WIFI_DATA_SIZE);
Luca Coelho69964902017-01-12 12:43:12 +0200688 if (IS_ERR(wifi_pkg)) {
689 ret = PTR_ERR(wifi_pkg);
690 goto out_free;
691 }
692
693 if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
694 (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
695 ret = -EINVAL;
696 goto out_free;
697 }
698
699 enabled = !!(wifi_pkg->package.elements[1].integer.value);
700 n_profiles = wifi_pkg->package.elements[2].integer.value;
701
Sharon Dvire2ef1472017-02-21 11:12:12 +0200702 /* in case of BIOS bug */
703 if (n_profiles <= 0) {
704 ret = -EINVAL;
705 goto out_free;
706 }
707
Luca Coelho69964902017-01-12 12:43:12 +0200708 for (i = 0; i < n_profiles; i++) {
709 /* the tables start at element 3 */
710 static int pos = 3;
711
712 /* The EWRD profiles officially go from 2 to 4, but we
713 * save them in sar_profiles[1-3] (because we don't
714 * have profile 0). So in the array we start from 1.
715 */
716 ret = iwl_mvm_sar_set_profile(mvm,
717 &wifi_pkg->package.elements[pos],
718 &mvm->sar_profiles[i + 1],
719 enabled);
720 if (ret < 0)
721 break;
722
723 /* go to the next table */
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300724 pos += ACPI_SAR_TABLE_SIZE;
Luca Coelho69964902017-01-12 12:43:12 +0200725 }
726
727out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300728 kfree(data);
Luca Coelho69964902017-01-12 12:43:12 +0200729 return ret;
730}
731
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300732static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200733{
Luca Coelho813df5c2017-09-19 12:35:18 +0300734 union acpi_object *wifi_pkg, *data;
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300735 int i, j, ret;
736 int idx = 1;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200737
Luca Coelho813df5c2017-09-19 12:35:18 +0300738 data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD);
739 if (IS_ERR(data))
740 return PTR_ERR(data);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200741
Luca Coelho2fa388c2017-09-21 14:30:53 +0300742 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
743 ACPI_WGDS_WIFI_DATA_SIZE);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200744 if (IS_ERR(wifi_pkg)) {
745 ret = PTR_ERR(wifi_pkg);
746 goto out_free;
747 }
748
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300749 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
750 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300751 union acpi_object *entry;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200752
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300753 entry = &wifi_pkg->package.elements[idx++];
754 if ((entry->type != ACPI_TYPE_INTEGER) ||
Christophe Jailletaae9d562017-07-14 12:06:59 +0200755 (entry->integer.value > U8_MAX)) {
756 ret = -EINVAL;
757 goto out_free;
758 }
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200759
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300760 mvm->geo_profiles[i].values[j] = entry->integer.value;
761 }
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200762 }
763 ret = 0;
764out_free:
Luca Coelho813df5c2017-09-19 12:35:18 +0300765 kfree(data);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200766 return ret;
767}
768
Luca Coelho42ce76d2017-01-11 23:36:30 +0200769int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300770{
Haim Dreyfuss0791c2f2018-03-29 14:13:54 +0300771 union {
772 struct iwl_dev_tx_power_cmd v5;
773 struct iwl_dev_tx_power_cmd_v4 v4;
774 } cmd;
Luca Coelho42ce76d2017-01-11 23:36:30 +0200775 int i, j, idx;
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300776 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
Haim Dreyfuss0791c2f2018-03-29 14:13:54 +0300777 int len;
Luca Coelhoda2830a2016-05-30 13:00:44 +0300778
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300779 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
780 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
781 ACPI_SAR_TABLE_SIZE);
Luca Coelho42ce76d2017-01-11 23:36:30 +0200782
Haim Dreyfuss0791c2f2018-03-29 14:13:54 +0300783 cmd.v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS);
784
785 if (fw_has_api(&mvm->fw->ucode_capa,
786 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
787 len = sizeof(cmd.v5);
788 else if (fw_has_capa(&mvm->fw->ucode_capa,
789 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
790 len = sizeof(cmd.v4);
791 else
792 len = sizeof(cmd.v4.v3);
Luca Coelho55bfa4b2016-06-29 00:38:40 +0300793
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300794 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
Luca Coelho42ce76d2017-01-11 23:36:30 +0200795 struct iwl_mvm_sar_profile *prof;
796
797 /* don't allow SAR to be disabled (profile 0 means disable) */
798 if (profs[i] == 0)
799 return -EPERM;
800
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300801 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
802 if (profs[i] > ACPI_SAR_PROFILE_NUM)
Luca Coelho42ce76d2017-01-11 23:36:30 +0200803 return -EINVAL;
804
805 /* profiles go from 1 to 4, so decrement to access the array */
806 prof = &mvm->sar_profiles[profs[i] - 1];
807
808 /* if the profile is disabled, do nothing */
809 if (!prof->enabled) {
810 IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
811 profs[i]);
812 /* if one of the profiles is disabled, we fail all */
813 return -ENOENT;
814 }
815
816 IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300817 for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
818 idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
Haim Dreyfuss0791c2f2018-03-29 14:13:54 +0300819 cmd.v5.v3.per_chain_restriction[i][j] =
Luca Coelho42ce76d2017-01-11 23:36:30 +0200820 cpu_to_le16(prof->table[idx]);
821 IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
822 j, prof->table[idx]);
823 }
824 }
825
826 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
827
828 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
829}
830
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300831int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
832{
833 struct iwl_geo_tx_power_profiles_resp *resp;
834 int ret;
835
836 struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
837 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
838 };
839 struct iwl_host_cmd cmd = {
840 .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
841 .len = { sizeof(geo_cmd), },
842 .flags = CMD_WANT_SKB,
843 .data = { &geo_cmd },
844 };
845
846 ret = iwl_mvm_send_cmd(mvm, &cmd);
847 if (ret) {
848 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
849 return ret;
850 }
851
852 resp = (void *)cmd.resp_pkt->data;
853 ret = le32_to_cpu(resp->profile_idx);
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300854 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300855 ret = -EIO;
856 IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
857 }
858
859 iwl_free_resp(&cmd);
860 return ret;
861}
862
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200863static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
864{
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200865 struct iwl_geo_tx_power_profiles_cmd cmd = {
866 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
867 };
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300868 int ret, i, j;
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200869 u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
870
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300871 ret = iwl_mvm_sar_get_wgds_table(mvm);
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200872 if (ret < 0) {
873 IWL_DEBUG_RADIO(mvm,
874 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
875 ret);
876 /* we don't fail if the table is not available */
877 return 0;
878 }
879
880 IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
881
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300882 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200883 ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE);
884
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300885 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
886
887 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200888 struct iwl_per_chain_offset *chain =
889 (struct iwl_per_chain_offset *)&cmd.table[i];
890
891 for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
892 u8 *value;
893
Haim Dreyfuss7fe90e02017-03-30 11:16:17 +0300894 value = &mvm->geo_profiles[i].values[j *
Luca Coelhoe7a3b8d2017-09-21 13:22:59 +0300895 ACPI_GEO_PER_CHAIN_SIZE];
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200896 chain[j].max_tx_power = cpu_to_le16(value[0]);
897 chain[j].chain_a = value[1];
898 chain[j].chain_b = value[2];
899 IWL_DEBUG_RADIO(mvm,
900 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
901 i, j, value[1], value[2], value[0]);
902 }
903 }
904 return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
905}
906
Luca Coelho69964902017-01-12 12:43:12 +0200907#else /* CONFIG_ACPI */
908static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
909{
910 return -ENOENT;
911}
912
913static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
914{
915 return -ENOENT;
916}
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +0200917
918static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
919{
920 return 0;
921}
Luca Coelho18f17552017-07-26 15:20:18 +0300922
923int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a,
924 int prof_b)
925{
926 return -ENOENT;
927}
928
929int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
930{
931 return -ENOENT;
932}
Luca Coelho69964902017-01-12 12:43:12 +0200933#endif /* CONFIG_ACPI */
934
Luca Coelho42ce76d2017-01-11 23:36:30 +0200935static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
936{
937 int ret;
938
Haim Dreyfussc386dac2016-12-28 15:58:22 +0200939 ret = iwl_mvm_sar_get_wrds_table(mvm);
Luca Coelhoda2830a2016-05-30 13:00:44 +0300940 if (ret < 0) {
941 IWL_DEBUG_RADIO(mvm,
Luca Coelho69964902017-01-12 12:43:12 +0200942 "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
Luca Coelhoda2830a2016-05-30 13:00:44 +0300943 ret);
Luca Coelho69964902017-01-12 12:43:12 +0200944 /* if not available, don't fail and don't bother with EWRD */
Luca Coelhoda2830a2016-05-30 13:00:44 +0300945 return 0;
946 }
947
Luca Coelho69964902017-01-12 12:43:12 +0200948 ret = iwl_mvm_sar_get_ewrd_table(mvm);
949 /* if EWRD is not available, we can still use WRDS, so don't fail */
950 if (ret < 0)
951 IWL_DEBUG_RADIO(mvm,
952 "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
953 ret);
954
Luca Coelho42ce76d2017-01-11 23:36:30 +0200955 /* choose profile 1 (WRDS) as default for both chains */
956 ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
957
958 /* if we don't have profile 0 from BIOS, just skip it */
959 if (ret == -ENOENT)
Luca Coelhoda2830a2016-05-30 13:00:44 +0300960 return 0;
961
Luca Coelhoda2830a2016-05-30 13:00:44 +0300962 return ret;
963}
964
Sara Sharon1f370652016-08-31 18:13:57 +0300965static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
966{
967 int ret;
968
Johannes Berg7d6222e22017-06-08 09:18:22 +0200969 if (iwl_mvm_has_unified_ucode(mvm))
Sara Sharon1f370652016-08-31 18:13:57 +0300970 return iwl_run_unified_mvm_ucode(mvm, false);
971
972 ret = iwl_run_init_mvm_ucode(mvm, false);
973
Sara Sharon1f370652016-08-31 18:13:57 +0300974 if (ret) {
975 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
Liad Kaufmanf4744252017-11-23 10:29:04 +0200976
977 if (iwlmvm_mod_params.init_dbg)
978 return 0;
Sara Sharon1f370652016-08-31 18:13:57 +0300979 return ret;
980 }
981
982 /*
983 * Stop and start the transport without entering low power
984 * mode. This will save the state of other components on the
985 * device that are triggered by the INIT firwmare (MFUART).
986 */
987 _iwl_trans_stop_device(mvm->trans, false);
988 ret = _iwl_trans_start_hw(mvm->trans, false);
989 if (ret)
990 return ret;
991
992 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
993 if (ret)
994 return ret;
995
Johannes Berg702e9752017-06-02 11:56:58 +0200996 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
Sara Sharon1f370652016-08-31 18:13:57 +0300997}
998
Johannes Berg8ca151b2013-01-24 14:25:36 +0100999int iwl_mvm_up(struct iwl_mvm *mvm)
1000{
1001 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +03001002 struct ieee80211_channel *chan;
1003 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001004
1005 lockdep_assert_held(&mvm->mutex);
1006
1007 ret = iwl_trans_start_hw(mvm->trans);
1008 if (ret)
1009 return ret;
1010
Sara Sharon1f370652016-08-31 18:13:57 +03001011 ret = iwl_mvm_load_rt_fw(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001012 if (ret) {
1013 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1014 goto error;
1015 }
1016
Johannes Bergd0b813f2017-06-01 14:44:40 +02001017 iwl_get_shared_mem_conf(&mvm->fwrt);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001018
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001019 ret = iwl_mvm_sf_update(mvm, NULL, false);
1020 if (ret)
1021 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1022
Johannes Berg7174beb2017-06-01 16:03:19 +02001023 mvm->fwrt.dump.conf = FW_DBG_INVALID;
Emmanuel Grumbach945d4202015-02-15 17:16:16 +02001024 /* if we have a destination, assume EARLY START */
1025 if (mvm->fw->dbg_dest_tlv)
Johannes Berg7174beb2017-06-01 16:03:19 +02001026 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1027 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
Liad Kaufman6a951262014-11-17 11:36:21 +02001028
Moshe Harela0544272014-12-08 21:13:14 +02001029 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001030 if (ret)
1031 goto error;
1032
Johannes Berg7d6222e22017-06-08 09:18:22 +02001033 if (!iwl_mvm_has_unified_ucode(mvm)) {
1034 /* Send phy db control command and then phy db calibration */
Sara Sharon1f370652016-08-31 18:13:57 +03001035 ret = iwl_send_phy_db_data(mvm->phy_db);
1036 if (ret)
1037 goto error;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001038
Sara Sharon1f370652016-08-31 18:13:57 +03001039 ret = iwl_send_phy_cfg_cmd(mvm);
1040 if (ret)
1041 goto error;
1042 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001043
Emmanuel Grumbachb3de3ef2017-05-29 14:01:06 +03001044 ret = iwl_mvm_send_bt_init_conf(mvm);
1045 if (ret)
1046 goto error;
1047
Sara Sharon43413a92015-12-31 11:49:18 +02001048 /* Init RSS configuration */
Sara Sharon8edbfaa2018-02-05 12:42:44 +02001049 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
1050 ret = iwl_configure_rxq(mvm);
1051 if (ret) {
1052 IWL_ERR(mvm, "Failed to configure RX queues: %d\n",
1053 ret);
1054 goto error;
1055 }
1056 }
1057
1058 if (iwl_mvm_has_new_rx_api(mvm)) {
Sara Sharon43413a92015-12-31 11:49:18 +02001059 ret = iwl_send_rss_cfg_cmd(mvm);
1060 if (ret) {
1061 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1062 ret);
1063 goto error;
1064 }
1065 }
1066
Johannes Berg8ca151b2013-01-24 14:25:36 +01001067 /* init the fw <-> mac80211 STA mapping */
Sara Sharon0ae98812017-01-04 14:53:58 +02001068 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001069 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1070
Sara Sharon0ae98812017-01-04 14:53:58 +02001071 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001072
Johannes Bergb2b78752014-09-08 16:42:54 +02001073 /* reset quota debouncing buffer - 0xff will yield invalid data */
1074 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1075
Johannes Bergc8f54702017-06-19 23:50:31 +02001076 ret = iwl_mvm_send_dqa_cmd(mvm);
1077 if (ret)
1078 goto error;
Liad Kaufman97d5be72015-08-31 14:33:23 +03001079
Johannes Berg8ca151b2013-01-24 14:25:36 +01001080 /* Add auxiliary station for scanning */
1081 ret = iwl_mvm_add_aux_sta(mvm);
1082 if (ret)
1083 goto error;
1084
Ilan Peer53a9d612013-04-28 11:55:08 +03001085 /* Add all the PHY contexts */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001086 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
Ilan Peer53a9d612013-04-28 11:55:08 +03001087 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1088 for (i = 0; i < NUM_PHY_CTX; i++) {
1089 /*
1090 * The channel used here isn't relevant as it's
1091 * going to be overwritten in the other flows.
1092 * For now use the first channel we have.
1093 */
1094 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1095 &chandef, 1, 1);
1096 if (ret)
1097 goto error;
1098 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001099
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001100#ifdef CONFIG_THERMAL
1101 if (iwl_mvm_is_tt_in_fw(mvm)) {
1102 /* in order to give the responsibility of ct-kill and
1103 * TX backoff to FW we need to send empty temperature reporting
1104 * cmd during init time
1105 */
1106 iwl_mvm_send_temp_report_ths_cmd(mvm);
1107 } else {
1108 /* Initialize tx backoffs to the minimal possible */
1109 iwl_mvm_tt_tx_backoff(mvm, 0);
1110 }
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001111
1112 /* TODO: read the budget from BIOS / Platform NVM */
Chaya Rachel Ivgi944eafc2017-07-09 16:35:14 +03001113
1114 /*
1115 * In case there is no budget from BIOS / Platform NVM the default
1116 * budget should be 2000mW (cooling state 0).
1117 */
1118 if (iwl_mvm_is_ctdp_supported(mvm)) {
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001119 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1120 mvm->cooling_dev.cur_state);
Luca Coelho75cfe332016-09-14 11:54:36 +03001121 if (ret)
1122 goto error;
1123 }
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001124#else
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001125 /* Initialize tx backoffs to the minimal possible */
1126 iwl_mvm_tt_tx_backoff(mvm, 0);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001127#endif
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001128
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +02001129 WARN_ON(iwl_mvm_config_ltr(mvm));
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +03001130
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001131 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001132 if (ret)
1133 goto error;
1134
Arik Nemtsov35af15d2015-03-04 15:08:00 +02001135 /*
1136 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1137 * anyway, so don't init MCC.
1138 */
1139 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1140 ret = iwl_mvm_init_mcc(mvm);
1141 if (ret)
1142 goto error;
1143 }
Arik Nemtsov90d4f7d2014-03-04 19:58:46 +02001144
Johannes Berg859d9142015-06-01 17:11:11 +02001145 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Emmanuel Grumbach4ca87a52016-01-03 22:23:40 +02001146 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
Sara Sharonb66b5812017-01-31 10:39:44 +02001147 mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
David Spinadeld2496222014-05-20 12:46:37 +03001148 ret = iwl_mvm_config_scan(mvm);
1149 if (ret)
1150 goto error;
1151 }
1152
Eliad Peller7498cf42014-01-16 17:10:44 +02001153 /* allow FW/transport low power modes if not during restart */
1154 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1155 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1156
Luca Coelhoda2830a2016-05-30 13:00:44 +03001157 ret = iwl_mvm_sar_init(mvm);
1158 if (ret)
1159 goto error;
1160
Haim Dreyfussa6bff3c2017-01-19 12:00:46 +02001161 ret = iwl_mvm_sar_geo_init(mvm);
1162 if (ret)
1163 goto error;
1164
Johannes Berg7089ae62017-06-28 16:19:49 +02001165 iwl_mvm_leds_sync(mvm);
1166
Ilan Peer53a9d612013-04-28 11:55:08 +03001167 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001168 return 0;
1169 error:
Liad Kaufmanf4744252017-11-23 10:29:04 +02001170 if (!iwlmvm_mod_params.init_dbg || !ret)
Liad Kaufmande8ba412017-03-16 13:00:59 +02001171 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001172 return ret;
1173}
1174
1175int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1176{
1177 int ret, i;
1178
1179 lockdep_assert_held(&mvm->mutex);
1180
1181 ret = iwl_trans_start_hw(mvm->trans);
1182 if (ret)
1183 return ret;
1184
1185 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1186 if (ret) {
1187 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1188 goto error;
1189 }
1190
Moshe Harela0544272014-12-08 21:13:14 +02001191 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001192 if (ret)
1193 goto error;
1194
1195 /* Send phy db control command and then phy db calibration*/
1196 ret = iwl_send_phy_db_data(mvm->phy_db);
1197 if (ret)
1198 goto error;
1199
1200 ret = iwl_send_phy_cfg_cmd(mvm);
1201 if (ret)
1202 goto error;
1203
1204 /* init the fw <-> mac80211 STA mapping */
Sara Sharon0ae98812017-01-04 14:53:58 +02001205 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001206 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1207
1208 /* Add auxiliary station for scanning */
1209 ret = iwl_mvm_add_aux_sta(mvm);
1210 if (ret)
1211 goto error;
1212
1213 return 0;
1214 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001215 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001216 return ret;
1217}
1218
Johannes Berg04168412015-06-23 21:22:09 +02001219void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1220 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001221{
1222 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1223 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1224 u32 flags = le32_to_cpu(card_state_notif->flags);
1225
1226 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1227 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1228 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1229 (flags & CT_KILL_CARD_DISABLED) ?
1230 "Reached" : "Not reached");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001231}
1232
Johannes Berg04168412015-06-23 21:22:09 +02001233void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1234 struct iwl_rx_cmd_buffer *rxb)
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001235{
1236 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1237 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1238
Golan Ben-Ami0c8d0a42017-01-25 15:11:30 +02001239 IWL_DEBUG_INFO(mvm,
1240 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1241 le32_to_cpu(mfuart_notif->installed_ver),
1242 le32_to_cpu(mfuart_notif->external_ver),
1243 le32_to_cpu(mfuart_notif->status),
1244 le32_to_cpu(mfuart_notif->duration));
1245
Golan Ben-Ami19f63c52016-11-07 17:40:43 +02001246 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1247 IWL_DEBUG_INFO(mvm,
Golan Ben-Ami0c8d0a42017-01-25 15:11:30 +02001248 "MFUART: image size: 0x%08x\n",
Golan Ben-Ami19f63c52016-11-07 17:40:43 +02001249 le32_to_cpu(mfuart_notif->image_size));
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001250}