iwl-ucode.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include "iwl-dev.h"
  32. #include "iwl-core.h"
  33. #include "iwl-io.h"
  34. #include "iwl-agn-hw.h"
  35. #include "iwl-agn.h"
  36. #include "iwl-agn-calib.h"
  37. #include "iwl-trans.h"
  38. #include "iwl-fh.h"
  39. #include "iwl-op-mode.h"
  40. static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
  41. {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
  42. 0, COEX_UNASSOC_IDLE_FLAGS},
  43. {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
  44. 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
  45. {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
  46. 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
  47. {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
  48. 0, COEX_CALIBRATION_FLAGS},
  49. {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
  50. 0, COEX_PERIODIC_CALIBRATION_FLAGS},
  51. {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
  52. 0, COEX_CONNECTION_ESTAB_FLAGS},
  53. {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
  54. 0, COEX_ASSOCIATED_IDLE_FLAGS},
  55. {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
  56. 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
  57. {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
  58. 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
  59. {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
  60. 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
  61. {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
  62. {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
  63. {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
  64. 0, COEX_STAND_ALONE_DEBUG_FLAGS},
  65. {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
  66. 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
  67. {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
  68. {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
  69. };
  70. /******************************************************************************
  71. *
  72. * uCode download functions
  73. *
  74. ******************************************************************************/
  75. static inline const struct fw_img *
  76. iwl_get_ucode_image(struct iwl_priv *priv, enum iwl_ucode_type ucode_type)
  77. {
  78. switch (ucode_type) {
  79. case IWL_UCODE_INIT:
  80. return &priv->fw->ucode_init;
  81. case IWL_UCODE_WOWLAN:
  82. return &priv->fw->ucode_wowlan;
  83. case IWL_UCODE_REGULAR:
  84. return &priv->fw->ucode_rt;
  85. case IWL_UCODE_NONE:
  86. break;
  87. }
  88. return NULL;
  89. }
  90. /*
  91. * Calibration
  92. */
  93. static int iwl_set_Xtal_calib(struct iwl_priv *priv)
  94. {
  95. struct iwl_calib_xtal_freq_cmd cmd;
  96. __le16 *xtal_calib =
  97. (__le16 *)iwl_eeprom_query_addr(priv->shrd, EEPROM_XTAL);
  98. iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD);
  99. cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
  100. cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
  101. return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
  102. }
  103. static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
  104. {
  105. struct iwl_calib_temperature_offset_cmd cmd;
  106. __le16 *offset_calib =
  107. (__le16 *)iwl_eeprom_query_addr(priv->shrd,
  108. EEPROM_RAW_TEMPERATURE);
  109. memset(&cmd, 0, sizeof(cmd));
  110. iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
  111. memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
  112. if (!(cmd.radio_sensor_offset))
  113. cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
  114. IWL_DEBUG_CALIB(priv, "Radio sensor offset: %d\n",
  115. le16_to_cpu(cmd.radio_sensor_offset));
  116. return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
  117. }
  118. static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv)
  119. {
  120. struct iwl_calib_temperature_offset_v2_cmd cmd;
  121. __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv->shrd,
  122. EEPROM_KELVIN_TEMPERATURE);
  123. __le16 *offset_calib_low =
  124. (__le16 *)iwl_eeprom_query_addr(priv->shrd,
  125. EEPROM_RAW_TEMPERATURE);
  126. struct iwl_eeprom_calib_hdr *hdr;
  127. memset(&cmd, 0, sizeof(cmd));
  128. iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
  129. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv->shrd,
  130. EEPROM_CALIB_ALL);
  131. memcpy(&cmd.radio_sensor_offset_high, offset_calib_high,
  132. sizeof(*offset_calib_high));
  133. memcpy(&cmd.radio_sensor_offset_low, offset_calib_low,
  134. sizeof(*offset_calib_low));
  135. if (!(cmd.radio_sensor_offset_low)) {
  136. IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n");
  137. cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET;
  138. cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET;
  139. }
  140. memcpy(&cmd.burntVoltageRef, &hdr->voltage,
  141. sizeof(hdr->voltage));
  142. IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n",
  143. le16_to_cpu(cmd.radio_sensor_offset_high));
  144. IWL_DEBUG_CALIB(priv, "Radio sensor offset low: %d\n",
  145. le16_to_cpu(cmd.radio_sensor_offset_low));
  146. IWL_DEBUG_CALIB(priv, "Voltage Ref: %d\n",
  147. le16_to_cpu(cmd.burntVoltageRef));
  148. return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
  149. }
  150. static int iwl_send_calib_cfg(struct iwl_priv *priv)
  151. {
  152. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  153. struct iwl_host_cmd cmd = {
  154. .id = CALIBRATION_CFG_CMD,
  155. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  156. .data = { &calib_cfg_cmd, },
  157. };
  158. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  159. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  160. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  161. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  162. calib_cfg_cmd.ucd_calib_cfg.flags =
  163. IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK;
  164. return iwl_dvm_send_cmd(priv, &cmd);
  165. }
  166. int iwlagn_rx_calib_result(struct iwl_priv *priv,
  167. struct iwl_rx_cmd_buffer *rxb,
  168. struct iwl_device_cmd *cmd)
  169. {
  170. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  171. struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->data;
  172. int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  173. /* reduce the size of the length field itself */
  174. len -= 4;
  175. if (iwl_calib_set(priv, hdr, len))
  176. IWL_ERR(priv, "Failed to record calibration data %d\n",
  177. hdr->op_code);
  178. return 0;
  179. }
  180. int iwl_init_alive_start(struct iwl_priv *priv)
  181. {
  182. int ret;
  183. if (cfg(priv)->bt_params &&
  184. cfg(priv)->bt_params->advanced_bt_coexist) {
  185. /*
  186. * Tell uCode we are ready to perform calibration
  187. * need to perform this before any calibration
  188. * no need to close the envlope since we are going
  189. * to load the runtime uCode later.
  190. */
  191. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  192. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  193. if (ret)
  194. return ret;
  195. }
  196. ret = iwl_send_calib_cfg(priv);
  197. if (ret)
  198. return ret;
  199. /**
  200. * temperature offset calibration is only needed for runtime ucode,
  201. * so prepare the value now.
  202. */
  203. if (cfg(priv)->need_temp_offset_calib) {
  204. if (cfg(priv)->temp_offset_v2)
  205. return iwl_set_temperature_offset_calib_v2(priv);
  206. else
  207. return iwl_set_temperature_offset_calib(priv);
  208. }
  209. return 0;
  210. }
  211. static int iwl_send_wimax_coex(struct iwl_priv *priv)
  212. {
  213. struct iwl_wimax_coex_cmd coex_cmd;
  214. if (cfg(priv)->base_params->support_wimax_coexist) {
  215. /* UnMask wake up src at associated sleep */
  216. coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
  217. /* UnMask wake up src at unassociated sleep */
  218. coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
  219. memcpy(coex_cmd.sta_prio, cu_priorities,
  220. sizeof(struct iwl_wimax_coex_event_entry) *
  221. COEX_NUM_OF_EVENTS);
  222. /* enabling the coexistence feature */
  223. coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
  224. /* enabling the priorities tables */
  225. coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
  226. } else {
  227. /* coexistence is disabled */
  228. memset(&coex_cmd, 0, sizeof(coex_cmd));
  229. }
  230. return iwl_dvm_send_cmd_pdu(priv,
  231. COEX_PRIORITY_TABLE_CMD, CMD_SYNC,
  232. sizeof(coex_cmd), &coex_cmd);
  233. }
  234. static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
  235. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  236. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  237. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  238. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  239. ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  240. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  241. ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  242. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  243. ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  244. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  245. ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  246. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  247. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  248. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  249. ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  250. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  251. ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  252. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  253. 0, 0, 0, 0, 0, 0, 0
  254. };
  255. void iwl_send_prio_tbl(struct iwl_priv *priv)
  256. {
  257. struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
  258. memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl,
  259. sizeof(iwl_bt_prio_tbl));
  260. if (iwl_dvm_send_cmd_pdu(priv,
  261. REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC,
  262. sizeof(prio_tbl_cmd), &prio_tbl_cmd))
  263. IWL_ERR(priv, "failed to send BT prio tbl command\n");
  264. }
  265. int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
  266. {
  267. struct iwl_bt_coex_prot_env_cmd env_cmd;
  268. int ret;
  269. env_cmd.action = action;
  270. env_cmd.type = type;
  271. ret = iwl_dvm_send_cmd_pdu(priv,
  272. REPLY_BT_COEX_PROT_ENV, CMD_SYNC,
  273. sizeof(env_cmd), &env_cmd);
  274. if (ret)
  275. IWL_ERR(priv, "failed to send BT env command\n");
  276. return ret;
  277. }
  278. static int iwl_alive_notify(struct iwl_priv *priv)
  279. {
  280. int ret;
  281. iwl_trans_fw_alive(trans(priv));
  282. priv->passive_no_rx = false;
  283. priv->transport_queue_stop = 0;
  284. ret = iwl_send_wimax_coex(priv);
  285. if (ret)
  286. return ret;
  287. if (!cfg(priv)->no_xtal_calib) {
  288. ret = iwl_set_Xtal_calib(priv);
  289. if (ret)
  290. return ret;
  291. }
  292. return iwl_send_calib_results(priv);
  293. }
  294. /**
  295. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  296. * using sample data 100 bytes apart. If these sample points are good,
  297. * it's a pretty good bet that everything between them is good, too.
  298. */
  299. static int iwl_verify_inst_sparse(struct iwl_priv *priv,
  300. const struct fw_desc *fw_desc)
  301. {
  302. __le32 *image = (__le32 *)fw_desc->v_addr;
  303. u32 len = fw_desc->len;
  304. u32 val;
  305. u32 i;
  306. IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len);
  307. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  308. /* read data comes through single port, auto-incr addr */
  309. /* NOTE: Use the debugless read so we don't flood kernel log
  310. * if IWL_DL_IO is set */
  311. iwl_write_direct32(trans(priv), HBUS_TARG_MEM_RADDR,
  312. i + IWLAGN_RTC_INST_LOWER_BOUND);
  313. val = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  314. if (val != le32_to_cpu(*image))
  315. return -EIO;
  316. }
  317. return 0;
  318. }
  319. static void iwl_print_mismatch_inst(struct iwl_priv *priv,
  320. const struct fw_desc *fw_desc)
  321. {
  322. __le32 *image = (__le32 *)fw_desc->v_addr;
  323. u32 len = fw_desc->len;
  324. u32 val;
  325. u32 offs;
  326. int errors = 0;
  327. IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len);
  328. iwl_write_direct32(trans(priv), HBUS_TARG_MEM_RADDR,
  329. IWLAGN_RTC_INST_LOWER_BOUND);
  330. for (offs = 0;
  331. offs < len && errors < 20;
  332. offs += sizeof(u32), image++) {
  333. /* read data comes through single port, auto-incr addr */
  334. val = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  335. if (val != le32_to_cpu(*image)) {
  336. IWL_ERR(priv, "uCode INST section at "
  337. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  338. offs, val, le32_to_cpu(*image));
  339. errors++;
  340. }
  341. }
  342. }
  343. /**
  344. * iwl_verify_ucode - determine which instruction image is in SRAM,
  345. * and verify its contents
  346. */
  347. static int iwl_verify_ucode(struct iwl_priv *priv,
  348. enum iwl_ucode_type ucode_type)
  349. {
  350. const struct fw_img *img = iwl_get_ucode_image(priv, ucode_type);
  351. if (!img) {
  352. IWL_ERR(priv, "Invalid ucode requested (%d)\n", ucode_type);
  353. return -EINVAL;
  354. }
  355. if (!iwl_verify_inst_sparse(priv, &img->code)) {
  356. IWL_DEBUG_FW(priv, "uCode is good in inst SRAM\n");
  357. return 0;
  358. }
  359. IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n");
  360. iwl_print_mismatch_inst(priv, &img->code);
  361. return -EIO;
  362. }
  363. struct iwl_alive_data {
  364. bool valid;
  365. u8 subtype;
  366. };
  367. static void iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
  368. struct iwl_rx_packet *pkt,
  369. void *data)
  370. {
  371. struct iwl_priv *priv =
  372. container_of(notif_wait, struct iwl_priv, notif_wait);
  373. struct iwl_alive_data *alive_data = data;
  374. struct iwl_alive_resp *palive;
  375. palive = (void *)pkt->data;
  376. IWL_DEBUG_FW(priv, "Alive ucode status 0x%08X revision "
  377. "0x%01X 0x%01X\n",
  378. palive->is_valid, palive->ver_type,
  379. palive->ver_subtype);
  380. priv->shrd->device_pointers.error_event_table =
  381. le32_to_cpu(palive->error_event_table_ptr);
  382. priv->shrd->device_pointers.log_event_table =
  383. le32_to_cpu(palive->log_event_table_ptr);
  384. alive_data->subtype = palive->ver_subtype;
  385. alive_data->valid = palive->is_valid == UCODE_VALID_OK;
  386. }
  387. #define UCODE_ALIVE_TIMEOUT HZ
  388. #define UCODE_CALIB_TIMEOUT (2*HZ)
  389. int iwl_load_ucode_wait_alive(struct iwl_priv *priv,
  390. enum iwl_ucode_type ucode_type)
  391. {
  392. struct iwl_notification_wait alive_wait;
  393. struct iwl_alive_data alive_data;
  394. const struct fw_img *fw;
  395. int ret;
  396. enum iwl_ucode_type old_type;
  397. old_type = priv->shrd->ucode_type;
  398. priv->shrd->ucode_type = ucode_type;
  399. fw = iwl_get_ucode_image(priv, ucode_type);
  400. if (!fw)
  401. return -EINVAL;
  402. iwl_init_notification_wait(&priv->notif_wait, &alive_wait, REPLY_ALIVE,
  403. iwl_alive_fn, &alive_data);
  404. ret = iwl_trans_start_fw(trans(priv), fw);
  405. if (ret) {
  406. priv->shrd->ucode_type = old_type;
  407. iwl_remove_notification(&priv->notif_wait, &alive_wait);
  408. return ret;
  409. }
  410. /*
  411. * Some things may run in the background now, but we
  412. * just wait for the ALIVE notification here.
  413. */
  414. ret = iwl_wait_notification(&priv->notif_wait, &alive_wait,
  415. UCODE_ALIVE_TIMEOUT);
  416. if (ret) {
  417. priv->shrd->ucode_type = old_type;
  418. return ret;
  419. }
  420. if (!alive_data.valid) {
  421. IWL_ERR(priv, "Loaded ucode is not valid!\n");
  422. priv->shrd->ucode_type = old_type;
  423. return -EIO;
  424. }
  425. /*
  426. * This step takes a long time (60-80ms!!) and
  427. * WoWLAN image should be loaded quickly, so
  428. * skip it for WoWLAN.
  429. */
  430. if (ucode_type != IWL_UCODE_WOWLAN) {
  431. ret = iwl_verify_ucode(priv, ucode_type);
  432. if (ret) {
  433. priv->shrd->ucode_type = old_type;
  434. return ret;
  435. }
  436. /* delay a bit to give rfkill time to run */
  437. msleep(5);
  438. }
  439. ret = iwl_alive_notify(priv);
  440. if (ret) {
  441. IWL_WARN(priv,
  442. "Could not complete ALIVE transition: %d\n", ret);
  443. priv->shrd->ucode_type = old_type;
  444. return ret;
  445. }
  446. return 0;
  447. }
  448. int iwl_run_init_ucode(struct iwl_priv *priv)
  449. {
  450. struct iwl_notification_wait calib_wait;
  451. int ret;
  452. lockdep_assert_held(&priv->mutex);
  453. /* No init ucode required? Curious, but maybe ok */
  454. if (!priv->fw->ucode_init.code.len)
  455. return 0;
  456. if (priv->shrd->ucode_type != IWL_UCODE_NONE)
  457. return 0;
  458. iwl_init_notification_wait(&priv->notif_wait, &calib_wait,
  459. CALIBRATION_COMPLETE_NOTIFICATION,
  460. NULL, NULL);
  461. /* Will also start the device */
  462. ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT);
  463. if (ret)
  464. goto error;
  465. ret = iwl_init_alive_start(priv);
  466. if (ret)
  467. goto error;
  468. /*
  469. * Some things may run in the background now, but we
  470. * just wait for the calibration complete notification.
  471. */
  472. ret = iwl_wait_notification(&priv->notif_wait, &calib_wait,
  473. UCODE_CALIB_TIMEOUT);
  474. goto out;
  475. error:
  476. iwl_remove_notification(&priv->notif_wait, &calib_wait);
  477. out:
  478. /* Whatever happened, stop the device */
  479. iwl_trans_stop_device(trans(priv));
  480. return ret;
  481. }