fw.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *
  62. *****************************************************************************/
  63. #include <net/mac80211.h>
  64. #include "iwl-trans.h"
  65. #include "iwl-op-mode.h"
  66. #include "iwl-fw.h"
  67. #include "iwl-debug.h"
  68. #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
  69. #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
  70. #include "iwl-eeprom-parse.h"
  71. #include "mvm.h"
  72. #include "iwl-phy-db.h"
  73. #define MVM_UCODE_ALIVE_TIMEOUT HZ
  74. #define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
  75. #define UCODE_VALID_OK cpu_to_le32(0x1)
  76. /* Default calibration values for WkP - set to INIT image w/o running */
  77. static const u8 wkp_calib_values_bb_filter[] = { 0xbf, 0x00, 0x5f, 0x00, 0x2f,
  78. 0x00, 0x18, 0x00 };
  79. static const u8 wkp_calib_values_rx_dc[] = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
  80. 0x7f, 0x7f, 0x7f };
  81. static const u8 wkp_calib_values_tx_lo[] = { 0x00, 0x00, 0x00, 0x00 };
  82. static const u8 wkp_calib_values_tx_iq[] = { 0xff, 0x00, 0xff, 0x00, 0x00,
  83. 0x00 };
  84. static const u8 wkp_calib_values_rx_iq[] = { 0xff, 0x00, 0x00, 0x00 };
  85. static const u8 wkp_calib_values_rx_iq_skew[] = { 0x00, 0x00, 0x01, 0x00 };
  86. static const u8 wkp_calib_values_tx_iq_skew[] = { 0x01, 0x00, 0x00, 0x00 };
  87. static const u8 wkp_calib_values_xtal[] = { 0xd2, 0xd2 };
  88. struct iwl_calib_default_data {
  89. u16 size;
  90. void *data;
  91. };
  92. #define CALIB_SIZE_N_DATA(_buf) {.size = sizeof(_buf), .data = &_buf}
  93. static const struct iwl_calib_default_data wkp_calib_default_data[12] = {
  94. [5] = CALIB_SIZE_N_DATA(wkp_calib_values_rx_dc),
  95. [6] = CALIB_SIZE_N_DATA(wkp_calib_values_bb_filter),
  96. [7] = CALIB_SIZE_N_DATA(wkp_calib_values_tx_lo),
  97. [8] = CALIB_SIZE_N_DATA(wkp_calib_values_tx_iq),
  98. [9] = CALIB_SIZE_N_DATA(wkp_calib_values_tx_iq_skew),
  99. [10] = CALIB_SIZE_N_DATA(wkp_calib_values_rx_iq),
  100. [11] = CALIB_SIZE_N_DATA(wkp_calib_values_rx_iq_skew),
  101. };
  102. struct iwl_mvm_alive_data {
  103. bool valid;
  104. u32 scd_base_addr;
  105. };
  106. static inline const struct fw_img *
  107. iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
  108. {
  109. if (ucode_type >= IWL_UCODE_TYPE_MAX)
  110. return NULL;
  111. return &mvm->fw->img[ucode_type];
  112. }
  113. static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
  114. {
  115. struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
  116. .valid = cpu_to_le32(valid_tx_ant),
  117. };
  118. IWL_DEBUG_HC(mvm, "select valid tx ant: %u\n", valid_tx_ant);
  119. return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, CMD_SYNC,
  120. sizeof(tx_ant_cmd), &tx_ant_cmd);
  121. }
  122. static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
  123. struct iwl_rx_packet *pkt, void *data)
  124. {
  125. struct iwl_mvm *mvm =
  126. container_of(notif_wait, struct iwl_mvm, notif_wait);
  127. struct iwl_mvm_alive_data *alive_data = data;
  128. struct mvm_alive_resp *palive;
  129. palive = (void *)pkt->data;
  130. mvm->error_event_table = le32_to_cpu(palive->error_event_table_ptr);
  131. mvm->log_event_table = le32_to_cpu(palive->log_event_table_ptr);
  132. alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
  133. alive_data->valid = le16_to_cpu(palive->status) == IWL_ALIVE_STATUS_OK;
  134. IWL_DEBUG_FW(mvm, "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
  135. le16_to_cpu(palive->status), palive->ver_type,
  136. palive->ver_subtype);
  137. return true;
  138. }
  139. static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
  140. struct iwl_rx_packet *pkt, void *data)
  141. {
  142. struct iwl_phy_db *phy_db = data;
  143. if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
  144. WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
  145. return true;
  146. }
  147. WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC));
  148. return false;
  149. }
  150. static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
  151. enum iwl_ucode_type ucode_type)
  152. {
  153. struct iwl_notification_wait alive_wait;
  154. struct iwl_mvm_alive_data alive_data;
  155. const struct fw_img *fw;
  156. int ret, i;
  157. enum iwl_ucode_type old_type = mvm->cur_ucode;
  158. static const u8 alive_cmd[] = { MVM_ALIVE };
  159. mvm->cur_ucode = ucode_type;
  160. fw = iwl_get_ucode_image(mvm, ucode_type);
  161. mvm->ucode_loaded = false;
  162. if (!fw)
  163. return -EINVAL;
  164. iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
  165. alive_cmd, ARRAY_SIZE(alive_cmd),
  166. iwl_alive_fn, &alive_data);
  167. ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
  168. if (ret) {
  169. mvm->cur_ucode = old_type;
  170. iwl_remove_notification(&mvm->notif_wait, &alive_wait);
  171. return ret;
  172. }
  173. /*
  174. * Some things may run in the background now, but we
  175. * just wait for the ALIVE notification here.
  176. */
  177. ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
  178. MVM_UCODE_ALIVE_TIMEOUT);
  179. if (ret) {
  180. mvm->cur_ucode = old_type;
  181. return ret;
  182. }
  183. if (!alive_data.valid) {
  184. IWL_ERR(mvm, "Loaded ucode is not valid!\n");
  185. mvm->cur_ucode = old_type;
  186. return -EIO;
  187. }
  188. iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
  189. /*
  190. * Note: all the queues are enabled as part of the interface
  191. * initialization, but in firmware restart scenarios they
  192. * could be stopped, so wake them up. In firmware restart,
  193. * mac80211 will have the queues stopped as well until the
  194. * reconfiguration completes. During normal startup, they
  195. * will be empty.
  196. */
  197. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  198. if (i < IWL_MVM_FIRST_AGG_QUEUE && i != IWL_MVM_CMD_QUEUE)
  199. mvm->queue_to_mac80211[i] = i;
  200. else
  201. mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  202. atomic_set(&mvm->queue_stop_count[i], 0);
  203. }
  204. mvm->transport_queue_stop = 0;
  205. mvm->ucode_loaded = true;
  206. return 0;
  207. }
  208. #define IWL_HW_REV_ID_RAINBOW 0x2
  209. #define IWL_PROJ_TYPE_LHP 0x5
  210. static u32 iwl_mvm_build_phy_cfg(struct iwl_mvm *mvm)
  211. {
  212. struct iwl_nvm_data *data = mvm->nvm_data;
  213. /* Temp calls to static definitions, will be changed to CSR calls */
  214. u8 hw_rev_id = IWL_HW_REV_ID_RAINBOW;
  215. u8 project_type = IWL_PROJ_TYPE_LHP;
  216. return data->radio_cfg_dash | (data->radio_cfg_step << 2) |
  217. (hw_rev_id << 4) | ((project_type & 0x7f) << 6) |
  218. (data->valid_tx_ant << 16) | (data->valid_rx_ant << 20);
  219. }
  220. static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
  221. {
  222. struct iwl_phy_cfg_cmd phy_cfg_cmd;
  223. enum iwl_ucode_type ucode_type = mvm->cur_ucode;
  224. /* Set parameters */
  225. phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_build_phy_cfg(mvm));
  226. phy_cfg_cmd.calib_control.event_trigger =
  227. mvm->fw->default_calib[ucode_type].event_trigger;
  228. phy_cfg_cmd.calib_control.flow_trigger =
  229. mvm->fw->default_calib[ucode_type].flow_trigger;
  230. IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
  231. phy_cfg_cmd.phy_cfg);
  232. return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, CMD_SYNC,
  233. sizeof(phy_cfg_cmd), &phy_cfg_cmd);
  234. }
  235. /* Starting with the new PHY DB implementation - New calibs are enabled */
  236. /* Value - 0x405e7 */
  237. #define IWL_CALIB_DEFAULT_FLOW_INIT (IWL_CALIB_CFG_XTAL_IDX |\
  238. IWL_CALIB_CFG_TEMPERATURE_IDX |\
  239. IWL_CALIB_CFG_VOLTAGE_READ_IDX |\
  240. IWL_CALIB_CFG_DC_IDX |\
  241. IWL_CALIB_CFG_BB_FILTER_IDX |\
  242. IWL_CALIB_CFG_LO_LEAKAGE_IDX |\
  243. IWL_CALIB_CFG_TX_IQ_IDX |\
  244. IWL_CALIB_CFG_RX_IQ_IDX |\
  245. IWL_CALIB_CFG_AGC_IDX)
  246. #define IWL_CALIB_DEFAULT_EVENT_INIT 0x0
  247. /* Value 0x41567 */
  248. #define IWL_CALIB_DEFAULT_FLOW_RUN (IWL_CALIB_CFG_XTAL_IDX |\
  249. IWL_CALIB_CFG_TEMPERATURE_IDX |\
  250. IWL_CALIB_CFG_VOLTAGE_READ_IDX |\
  251. IWL_CALIB_CFG_BB_FILTER_IDX |\
  252. IWL_CALIB_CFG_DC_IDX |\
  253. IWL_CALIB_CFG_TX_IQ_IDX |\
  254. IWL_CALIB_CFG_RX_IQ_IDX |\
  255. IWL_CALIB_CFG_SENSITIVITY_IDX |\
  256. IWL_CALIB_CFG_AGC_IDX)
  257. #define IWL_CALIB_DEFAULT_EVENT_RUN (IWL_CALIB_CFG_XTAL_IDX |\
  258. IWL_CALIB_CFG_TEMPERATURE_IDX |\
  259. IWL_CALIB_CFG_VOLTAGE_READ_IDX |\
  260. IWL_CALIB_CFG_TX_PWR_IDX |\
  261. IWL_CALIB_CFG_DC_IDX |\
  262. IWL_CALIB_CFG_TX_IQ_IDX |\
  263. IWL_CALIB_CFG_SENSITIVITY_IDX)
  264. /*
  265. * Sets the calibrations trigger values that will be sent to the FW for runtime
  266. * and init calibrations.
  267. * The ones given in the FW TLV are not correct.
  268. */
  269. static void iwl_set_default_calib_trigger(struct iwl_mvm *mvm)
  270. {
  271. struct iwl_tlv_calib_ctrl default_calib;
  272. /*
  273. * WkP FW TLV calib bits are wrong, overwrite them.
  274. * This defines the dynamic calibrations which are implemented in the
  275. * uCode both for init(flow) calculation and event driven calibs.
  276. */
  277. /* Init Image */
  278. default_calib.event_trigger = cpu_to_le32(IWL_CALIB_DEFAULT_EVENT_INIT);
  279. default_calib.flow_trigger = cpu_to_le32(IWL_CALIB_DEFAULT_FLOW_INIT);
  280. if (default_calib.event_trigger !=
  281. mvm->fw->default_calib[IWL_UCODE_INIT].event_trigger)
  282. IWL_ERR(mvm,
  283. "Updating the event calib for INIT image: 0x%x -> 0x%x\n",
  284. mvm->fw->default_calib[IWL_UCODE_INIT].event_trigger,
  285. default_calib.event_trigger);
  286. if (default_calib.flow_trigger !=
  287. mvm->fw->default_calib[IWL_UCODE_INIT].flow_trigger)
  288. IWL_ERR(mvm,
  289. "Updating the flow calib for INIT image: 0x%x -> 0x%x\n",
  290. mvm->fw->default_calib[IWL_UCODE_INIT].flow_trigger,
  291. default_calib.flow_trigger);
  292. memcpy((void *)&mvm->fw->default_calib[IWL_UCODE_INIT],
  293. &default_calib, sizeof(struct iwl_tlv_calib_ctrl));
  294. IWL_ERR(mvm,
  295. "Setting uCode init calibrations event 0x%x, trigger 0x%x\n",
  296. default_calib.event_trigger,
  297. default_calib.flow_trigger);
  298. /* Run time image */
  299. default_calib.event_trigger = cpu_to_le32(IWL_CALIB_DEFAULT_EVENT_RUN);
  300. default_calib.flow_trigger = cpu_to_le32(IWL_CALIB_DEFAULT_FLOW_RUN);
  301. if (default_calib.event_trigger !=
  302. mvm->fw->default_calib[IWL_UCODE_REGULAR].event_trigger)
  303. IWL_ERR(mvm,
  304. "Updating the event calib for RT image: 0x%x -> 0x%x\n",
  305. mvm->fw->default_calib[IWL_UCODE_REGULAR].event_trigger,
  306. default_calib.event_trigger);
  307. if (default_calib.flow_trigger !=
  308. mvm->fw->default_calib[IWL_UCODE_REGULAR].flow_trigger)
  309. IWL_ERR(mvm,
  310. "Updating the flow calib for RT image: 0x%x -> 0x%x\n",
  311. mvm->fw->default_calib[IWL_UCODE_REGULAR].flow_trigger,
  312. default_calib.flow_trigger);
  313. memcpy((void *)&mvm->fw->default_calib[IWL_UCODE_REGULAR],
  314. &default_calib, sizeof(struct iwl_tlv_calib_ctrl));
  315. IWL_ERR(mvm,
  316. "Setting uCode runtime calibs event 0x%x, trigger 0x%x\n",
  317. default_calib.event_trigger,
  318. default_calib.flow_trigger);
  319. }
  320. static int iwl_set_default_calibrations(struct iwl_mvm *mvm)
  321. {
  322. u8 cmd_raw[16]; /* holds the variable size commands */
  323. struct iwl_set_calib_default_cmd *cmd =
  324. (struct iwl_set_calib_default_cmd *)cmd_raw;
  325. int ret, i;
  326. /* Setting default values for calibrations we don't run */
  327. for (i = 0; i < ARRAY_SIZE(wkp_calib_default_data); i++) {
  328. u16 cmd_len;
  329. if (wkp_calib_default_data[i].size == 0)
  330. continue;
  331. memset(cmd_raw, 0, sizeof(cmd_raw));
  332. cmd_len = wkp_calib_default_data[i].size + sizeof(cmd);
  333. cmd->calib_index = cpu_to_le16(i);
  334. cmd->length = cpu_to_le16(wkp_calib_default_data[i].size);
  335. if (WARN_ONCE(cmd_len > sizeof(cmd_raw),
  336. "Need to enlarge cmd_raw to %d\n", cmd_len))
  337. break;
  338. memcpy(cmd->data, wkp_calib_default_data[i].data,
  339. wkp_calib_default_data[i].size);
  340. ret = iwl_mvm_send_cmd_pdu(mvm, SET_CALIB_DEFAULT_CMD, 0,
  341. sizeof(*cmd) +
  342. wkp_calib_default_data[i].size,
  343. cmd);
  344. if (ret)
  345. return ret;
  346. }
  347. return 0;
  348. }
  349. int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
  350. {
  351. struct iwl_notification_wait calib_wait;
  352. static const u8 init_complete[] = {
  353. INIT_COMPLETE_NOTIF,
  354. CALIB_RES_NOTIF_PHY_DB
  355. };
  356. int ret;
  357. lockdep_assert_held(&mvm->mutex);
  358. if (mvm->init_ucode_run)
  359. return 0;
  360. iwl_init_notification_wait(&mvm->notif_wait,
  361. &calib_wait,
  362. init_complete,
  363. ARRAY_SIZE(init_complete),
  364. iwl_wait_phy_db_entry,
  365. mvm->phy_db);
  366. /* Will also start the device */
  367. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
  368. if (ret) {
  369. IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
  370. goto error;
  371. }
  372. if (read_nvm) {
  373. /* Read nvm */
  374. ret = iwl_nvm_init(mvm);
  375. if (ret) {
  376. IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
  377. goto error;
  378. }
  379. }
  380. ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
  381. WARN_ON(ret);
  382. /* Override the calibrations from TLV and the const of fw */
  383. iwl_set_default_calib_trigger(mvm);
  384. /* WkP doesn't have all calibrations, need to set default values */
  385. if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  386. ret = iwl_set_default_calibrations(mvm);
  387. if (ret)
  388. goto error;
  389. }
  390. /*
  391. * Send phy configurations command to init uCode
  392. * to start the 16.0 uCode init image internal calibrations.
  393. */
  394. ret = iwl_send_phy_cfg_cmd(mvm);
  395. if (ret) {
  396. IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
  397. ret);
  398. goto error;
  399. }
  400. /*
  401. * Some things may run in the background now, but we
  402. * just wait for the calibration complete notification.
  403. */
  404. ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
  405. MVM_UCODE_CALIB_TIMEOUT);
  406. if (!ret)
  407. mvm->init_ucode_run = true;
  408. goto out;
  409. error:
  410. iwl_remove_notification(&mvm->notif_wait, &calib_wait);
  411. out:
  412. if (!iwlmvm_mod_params.init_dbg) {
  413. iwl_trans_stop_device(mvm->trans);
  414. } else if (!mvm->nvm_data) {
  415. /* we want to debug INIT and we have no NVM - fake */
  416. mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
  417. sizeof(struct ieee80211_channel) +
  418. sizeof(struct ieee80211_rate),
  419. GFP_KERNEL);
  420. if (!mvm->nvm_data)
  421. return -ENOMEM;
  422. mvm->nvm_data->valid_rx_ant = 1;
  423. mvm->nvm_data->valid_tx_ant = 1;
  424. mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
  425. mvm->nvm_data->bands[0].n_channels = 1;
  426. mvm->nvm_data->bands[0].n_bitrates = 1;
  427. mvm->nvm_data->bands[0].bitrates =
  428. (void *)mvm->nvm_data->channels + 1;
  429. mvm->nvm_data->bands[0].bitrates->hw_value = 10;
  430. }
  431. return ret;
  432. }
  433. #define UCODE_CALIB_TIMEOUT (2*HZ)
  434. int iwl_mvm_up(struct iwl_mvm *mvm)
  435. {
  436. int ret, i;
  437. lockdep_assert_held(&mvm->mutex);
  438. ret = iwl_trans_start_hw(mvm->trans);
  439. if (ret)
  440. return ret;
  441. /* If we were in RFKILL during module loading, load init ucode now */
  442. if (!mvm->init_ucode_run) {
  443. ret = iwl_run_init_mvm_ucode(mvm, false);
  444. if (ret && !iwlmvm_mod_params.init_dbg) {
  445. IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
  446. goto error;
  447. }
  448. }
  449. if (iwlmvm_mod_params.init_dbg)
  450. return 0;
  451. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
  452. if (ret) {
  453. IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
  454. goto error;
  455. }
  456. ret = iwl_send_tx_ant_cfg(mvm, mvm->nvm_data->valid_tx_ant);
  457. if (ret)
  458. goto error;
  459. /* Send phy db control command and then phy db calibration*/
  460. ret = iwl_send_phy_db_data(mvm->phy_db);
  461. if (ret)
  462. goto error;
  463. ret = iwl_send_phy_cfg_cmd(mvm);
  464. if (ret)
  465. goto error;
  466. /* init the fw <-> mac80211 STA mapping */
  467. for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
  468. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  469. /* Add auxiliary station for scanning */
  470. ret = iwl_mvm_add_aux_sta(mvm);
  471. if (ret)
  472. goto error;
  473. IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
  474. return 0;
  475. error:
  476. iwl_trans_stop_device(mvm->trans);
  477. return ret;
  478. }
  479. int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
  480. {
  481. int ret, i;
  482. lockdep_assert_held(&mvm->mutex);
  483. ret = iwl_trans_start_hw(mvm->trans);
  484. if (ret)
  485. return ret;
  486. ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
  487. if (ret) {
  488. IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
  489. goto error;
  490. }
  491. ret = iwl_send_tx_ant_cfg(mvm, mvm->nvm_data->valid_tx_ant);
  492. if (ret)
  493. goto error;
  494. /* Send phy db control command and then phy db calibration*/
  495. ret = iwl_send_phy_db_data(mvm->phy_db);
  496. if (ret)
  497. goto error;
  498. ret = iwl_send_phy_cfg_cmd(mvm);
  499. if (ret)
  500. goto error;
  501. /* init the fw <-> mac80211 STA mapping */
  502. for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
  503. RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
  504. /* Add auxiliary station for scanning */
  505. ret = iwl_mvm_add_aux_sta(mvm);
  506. if (ret)
  507. goto error;
  508. return 0;
  509. error:
  510. iwl_trans_stop_device(mvm->trans);
  511. return ret;
  512. }
  513. int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
  514. struct iwl_rx_cmd_buffer *rxb,
  515. struct iwl_device_cmd *cmd)
  516. {
  517. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  518. struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
  519. u32 flags = le32_to_cpu(card_state_notif->flags);
  520. IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
  521. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  522. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  523. (flags & CT_KILL_CARD_DISABLED) ?
  524. "Reached" : "Not reached");
  525. return 0;
  526. }
  527. int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
  528. struct iwl_device_cmd *cmd)
  529. {
  530. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  531. struct iwl_radio_version_notif *radio_version = (void *)pkt->data;
  532. /* TODO: what to do with that? */
  533. IWL_DEBUG_INFO(mvm,
  534. "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n",
  535. le32_to_cpu(radio_version->radio_flavor),
  536. le32_to_cpu(radio_version->radio_step),
  537. le32_to_cpu(radio_version->radio_dash));
  538. return 0;
  539. }