iwl-agn-ucode.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 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/module.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-io.h"
  36. #include "iwl-helpers.h"
  37. #include "iwl-agn-hw.h"
  38. #include "iwl-agn.h"
  39. static const s8 iwlagn_default_queue_to_tx_fifo[] = {
  40. IWL_TX_FIFO_VO,
  41. IWL_TX_FIFO_VI,
  42. IWL_TX_FIFO_BE,
  43. IWL_TX_FIFO_BK,
  44. IWLAGN_CMD_FIFO_NUM,
  45. IWL_TX_FIFO_UNUSED,
  46. IWL_TX_FIFO_UNUSED,
  47. IWL_TX_FIFO_UNUSED,
  48. IWL_TX_FIFO_UNUSED,
  49. IWL_TX_FIFO_UNUSED,
  50. };
  51. static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
  52. {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
  53. 0, COEX_UNASSOC_IDLE_FLAGS},
  54. {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
  55. 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
  56. {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
  57. 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
  58. {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
  59. 0, COEX_CALIBRATION_FLAGS},
  60. {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
  61. 0, COEX_PERIODIC_CALIBRATION_FLAGS},
  62. {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
  63. 0, COEX_CONNECTION_ESTAB_FLAGS},
  64. {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
  65. 0, COEX_ASSOCIATED_IDLE_FLAGS},
  66. {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
  67. 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
  68. {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
  69. 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
  70. {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
  71. 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
  72. {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
  73. {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
  74. {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
  75. 0, COEX_STAND_ALONE_DEBUG_FLAGS},
  76. {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
  77. 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
  78. {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
  79. {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
  80. };
  81. /*
  82. * ucode
  83. */
  84. static int iwlagn_load_section(struct iwl_priv *priv, const char *name,
  85. struct fw_desc *image, u32 dst_addr)
  86. {
  87. dma_addr_t phy_addr = image->p_addr;
  88. u32 byte_cnt = image->len;
  89. int ret;
  90. priv->ucode_write_complete = 0;
  91. iwl_write_direct32(priv,
  92. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  93. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  94. iwl_write_direct32(priv,
  95. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  96. iwl_write_direct32(priv,
  97. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  98. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  99. iwl_write_direct32(priv,
  100. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  101. (iwl_get_dma_hi_addr(phy_addr)
  102. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  103. iwl_write_direct32(priv,
  104. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  105. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  106. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  107. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  108. iwl_write_direct32(priv,
  109. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  110. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  111. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  112. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  113. IWL_DEBUG_INFO(priv, "%s uCode section being loaded...\n", name);
  114. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  115. priv->ucode_write_complete, 5 * HZ);
  116. if (ret == -ERESTARTSYS) {
  117. IWL_ERR(priv, "Could not load the %s uCode section due "
  118. "to interrupt\n", name);
  119. return ret;
  120. }
  121. if (!ret) {
  122. IWL_ERR(priv, "Could not load the %s uCode section\n",
  123. name);
  124. return -ETIMEDOUT;
  125. }
  126. return 0;
  127. }
  128. static int iwlagn_load_given_ucode(struct iwl_priv *priv,
  129. struct fw_desc *inst_image,
  130. struct fw_desc *data_image)
  131. {
  132. int ret = 0;
  133. ret = iwlagn_load_section(priv, "INST", inst_image,
  134. IWLAGN_RTC_INST_LOWER_BOUND);
  135. if (ret)
  136. return ret;
  137. return iwlagn_load_section(priv, "DATA", data_image,
  138. IWLAGN_RTC_DATA_LOWER_BOUND);
  139. }
  140. int iwlagn_load_ucode(struct iwl_priv *priv)
  141. {
  142. int ret = 0;
  143. /* check whether init ucode should be loaded, or rather runtime ucode */
  144. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  145. IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
  146. ret = iwlagn_load_given_ucode(priv,
  147. &priv->ucode_init, &priv->ucode_init_data);
  148. if (!ret) {
  149. IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
  150. priv->ucode_type = UCODE_INIT;
  151. }
  152. } else {
  153. IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
  154. "Loading runtime ucode...\n");
  155. ret = iwlagn_load_given_ucode(priv,
  156. &priv->ucode_code, &priv->ucode_data);
  157. if (!ret) {
  158. IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
  159. priv->ucode_type = UCODE_RT;
  160. }
  161. }
  162. return ret;
  163. }
  164. /*
  165. * Calibration
  166. */
  167. static int iwlagn_set_Xtal_calib(struct iwl_priv *priv)
  168. {
  169. struct iwl_calib_xtal_freq_cmd cmd;
  170. __le16 *xtal_calib =
  171. (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_XTAL);
  172. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
  173. cmd.hdr.first_group = 0;
  174. cmd.hdr.groups_num = 1;
  175. cmd.hdr.data_valid = 1;
  176. cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
  177. cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
  178. return iwl_calib_set(&priv->calib_results[IWL_CALIB_XTAL],
  179. (u8 *)&cmd, sizeof(cmd));
  180. }
  181. static int iwlagn_send_calib_cfg(struct iwl_priv *priv)
  182. {
  183. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  184. struct iwl_host_cmd cmd = {
  185. .id = CALIBRATION_CFG_CMD,
  186. .len = sizeof(struct iwl_calib_cfg_cmd),
  187. .data = &calib_cfg_cmd,
  188. };
  189. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  190. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  191. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  192. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  193. calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
  194. return iwl_send_cmd(priv, &cmd);
  195. }
  196. void iwlagn_rx_calib_result(struct iwl_priv *priv,
  197. struct iwl_rx_mem_buffer *rxb)
  198. {
  199. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  200. struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw;
  201. int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  202. int index;
  203. /* reduce the size of the length field itself */
  204. len -= 4;
  205. /* Define the order in which the results will be sent to the runtime
  206. * uCode. iwl_send_calib_results sends them in a row according to
  207. * their index. We sort them here
  208. */
  209. switch (hdr->op_code) {
  210. case IWL_PHY_CALIBRATE_DC_CMD:
  211. index = IWL_CALIB_DC;
  212. break;
  213. case IWL_PHY_CALIBRATE_LO_CMD:
  214. index = IWL_CALIB_LO;
  215. break;
  216. case IWL_PHY_CALIBRATE_TX_IQ_CMD:
  217. index = IWL_CALIB_TX_IQ;
  218. break;
  219. case IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD:
  220. index = IWL_CALIB_TX_IQ_PERD;
  221. break;
  222. case IWL_PHY_CALIBRATE_BASE_BAND_CMD:
  223. index = IWL_CALIB_BASE_BAND;
  224. break;
  225. default:
  226. IWL_ERR(priv, "Unknown calibration notification %d\n",
  227. hdr->op_code);
  228. return;
  229. }
  230. iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
  231. }
  232. void iwlagn_rx_calib_complete(struct iwl_priv *priv,
  233. struct iwl_rx_mem_buffer *rxb)
  234. {
  235. IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n");
  236. queue_work(priv->workqueue, &priv->restart);
  237. }
  238. void iwlagn_init_alive_start(struct iwl_priv *priv)
  239. {
  240. int ret = 0;
  241. /* Check alive response for "valid" sign from uCode */
  242. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  243. /* We had an error bringing up the hardware, so take it
  244. * all the way back down so we can try again */
  245. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  246. goto restart;
  247. }
  248. /* initialize uCode was loaded... verify inst image.
  249. * This is a paranoid check, because we would not have gotten the
  250. * "initialize" alive if code weren't properly loaded. */
  251. if (iwl_verify_ucode(priv)) {
  252. /* Runtime instruction load was bad;
  253. * take it all the way back down so we can try again */
  254. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  255. goto restart;
  256. }
  257. ret = priv->cfg->ops->lib->alive_notify(priv);
  258. if (ret) {
  259. IWL_WARN(priv,
  260. "Could not complete ALIVE transition: %d\n", ret);
  261. goto restart;
  262. }
  263. iwlagn_send_calib_cfg(priv);
  264. return;
  265. restart:
  266. /* real restart (first load init_ucode) */
  267. queue_work(priv->workqueue, &priv->restart);
  268. }
  269. static int iwlagn_send_wimax_coex(struct iwl_priv *priv)
  270. {
  271. struct iwl_wimax_coex_cmd coex_cmd;
  272. if (priv->cfg->support_wimax_coexist) {
  273. /* UnMask wake up src at associated sleep */
  274. coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
  275. /* UnMask wake up src at unassociated sleep */
  276. coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
  277. memcpy(coex_cmd.sta_prio, cu_priorities,
  278. sizeof(struct iwl_wimax_coex_event_entry) *
  279. COEX_NUM_OF_EVENTS);
  280. /* enabling the coexistence feature */
  281. coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
  282. /* enabling the priorities tables */
  283. coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
  284. } else {
  285. /* coexistence is disabled */
  286. memset(&coex_cmd, 0, sizeof(coex_cmd));
  287. }
  288. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  289. sizeof(coex_cmd), &coex_cmd);
  290. }
  291. int iwlagn_alive_notify(struct iwl_priv *priv)
  292. {
  293. u32 a;
  294. unsigned long flags;
  295. int i, chan;
  296. u32 reg_val;
  297. spin_lock_irqsave(&priv->lock, flags);
  298. priv->scd_base_addr = iwl_read_prph(priv, IWLAGN_SCD_SRAM_BASE_ADDR);
  299. a = priv->scd_base_addr + IWLAGN_SCD_CONTEXT_DATA_OFFSET;
  300. for (; a < priv->scd_base_addr + IWLAGN_SCD_TX_STTS_BITMAP_OFFSET;
  301. a += 4)
  302. iwl_write_targ_mem(priv, a, 0);
  303. for (; a < priv->scd_base_addr + IWLAGN_SCD_TRANSLATE_TBL_OFFSET;
  304. a += 4)
  305. iwl_write_targ_mem(priv, a, 0);
  306. for (; a < priv->scd_base_addr +
  307. IWLAGN_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
  308. iwl_write_targ_mem(priv, a, 0);
  309. iwl_write_prph(priv, IWLAGN_SCD_DRAM_BASE_ADDR,
  310. priv->scd_bc_tbls.dma >> 10);
  311. /* Enable DMA channel */
  312. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  313. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  314. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  315. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  316. /* Update FH chicken bits */
  317. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  318. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  319. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  320. iwl_write_prph(priv, IWLAGN_SCD_QUEUECHAIN_SEL,
  321. IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  322. iwl_write_prph(priv, IWLAGN_SCD_AGGR_SEL, 0);
  323. /* initiate the queues */
  324. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  325. iwl_write_prph(priv, IWLAGN_SCD_QUEUE_RDPTR(i), 0);
  326. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  327. iwl_write_targ_mem(priv, priv->scd_base_addr +
  328. IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  329. iwl_write_targ_mem(priv, priv->scd_base_addr +
  330. IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i) +
  331. sizeof(u32),
  332. ((SCD_WIN_SIZE <<
  333. IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  334. IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  335. ((SCD_FRAME_LIMIT <<
  336. IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  337. IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  338. }
  339. iwl_write_prph(priv, IWLAGN_SCD_INTERRUPT_MASK,
  340. IWL_MASK(0, priv->hw_params.max_txq_num));
  341. /* Activate all Tx DMA/FIFO channels */
  342. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  343. iwlagn_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  344. /* make sure all queue are not stopped */
  345. memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
  346. for (i = 0; i < 4; i++)
  347. atomic_set(&priv->queue_stop_count[i], 0);
  348. /* reset to 0 to enable all the queue first */
  349. priv->txq_ctx_active_msk = 0;
  350. /* map qos queues to fifos one-to-one */
  351. BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) != 10);
  352. for (i = 0; i < ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); i++) {
  353. int ac = iwlagn_default_queue_to_tx_fifo[i];
  354. iwl_txq_ctx_activate(priv, i);
  355. if (ac == IWL_TX_FIFO_UNUSED)
  356. continue;
  357. iwlagn_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  358. }
  359. spin_unlock_irqrestore(&priv->lock, flags);
  360. iwlagn_send_wimax_coex(priv);
  361. iwlagn_set_Xtal_calib(priv);
  362. iwl_send_calib_results(priv);
  363. return 0;
  364. }
  365. /**
  366. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  367. * using sample data 100 bytes apart. If these sample points are good,
  368. * it's a pretty good bet that everything between them is good, too.
  369. */
  370. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  371. {
  372. u32 val;
  373. int ret = 0;
  374. u32 errcnt = 0;
  375. u32 i;
  376. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  377. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  378. /* read data comes through single port, auto-incr addr */
  379. /* NOTE: Use the debugless read so we don't flood kernel log
  380. * if IWL_DL_IO is set */
  381. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  382. i + IWLAGN_RTC_INST_LOWER_BOUND);
  383. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  384. if (val != le32_to_cpu(*image)) {
  385. ret = -EIO;
  386. errcnt++;
  387. if (errcnt >= 3)
  388. break;
  389. }
  390. }
  391. return ret;
  392. }
  393. /**
  394. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  395. * looking at all data.
  396. */
  397. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  398. u32 len)
  399. {
  400. u32 val;
  401. u32 save_len = len;
  402. int ret = 0;
  403. u32 errcnt;
  404. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  405. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  406. IWLAGN_RTC_INST_LOWER_BOUND);
  407. errcnt = 0;
  408. for (; len > 0; len -= sizeof(u32), image++) {
  409. /* read data comes through single port, auto-incr addr */
  410. /* NOTE: Use the debugless read so we don't flood kernel log
  411. * if IWL_DL_IO is set */
  412. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  413. if (val != le32_to_cpu(*image)) {
  414. IWL_ERR(priv, "uCode INST section is invalid at "
  415. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  416. save_len - len, val, le32_to_cpu(*image));
  417. ret = -EIO;
  418. errcnt++;
  419. if (errcnt >= 20)
  420. break;
  421. }
  422. }
  423. if (!errcnt)
  424. IWL_DEBUG_INFO(priv,
  425. "ucode image in INSTRUCTION memory is good\n");
  426. return ret;
  427. }
  428. /**
  429. * iwl_verify_ucode - determine which instruction image is in SRAM,
  430. * and verify its contents
  431. */
  432. int iwl_verify_ucode(struct iwl_priv *priv)
  433. {
  434. __le32 *image;
  435. u32 len;
  436. int ret;
  437. /* Try bootstrap */
  438. image = (__le32 *)priv->ucode_boot.v_addr;
  439. len = priv->ucode_boot.len;
  440. ret = iwlcore_verify_inst_sparse(priv, image, len);
  441. if (!ret) {
  442. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  443. return 0;
  444. }
  445. /* Try initialize */
  446. image = (__le32 *)priv->ucode_init.v_addr;
  447. len = priv->ucode_init.len;
  448. ret = iwlcore_verify_inst_sparse(priv, image, len);
  449. if (!ret) {
  450. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  451. return 0;
  452. }
  453. /* Try runtime/protocol */
  454. image = (__le32 *)priv->ucode_code.v_addr;
  455. len = priv->ucode_code.len;
  456. ret = iwlcore_verify_inst_sparse(priv, image, len);
  457. if (!ret) {
  458. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  459. return 0;
  460. }
  461. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  462. /* Since nothing seems to match, show first several data entries in
  463. * instruction SRAM, so maybe visual inspection will give a clue.
  464. * Selection of bootstrap image (vs. other images) is arbitrary. */
  465. image = (__le32 *)priv->ucode_boot.v_addr;
  466. len = priv->ucode_boot.len;
  467. ret = iwl_verify_inst_full(priv, image, len);
  468. return ret;
  469. }