iwl-agn-ucode.c 18 KB

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