iwl-agn-ucode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. static const u8 iwlagn_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
  292. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  293. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  294. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  295. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  296. ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  297. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  298. ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  299. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  300. ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  301. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  302. ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  303. (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  304. ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  305. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  306. ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  307. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  308. ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
  309. (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
  310. 0, 0, 0, 0, 0, 0, 0
  311. };
  312. static void iwlagn_send_prio_tbl(struct iwl_priv *priv)
  313. {
  314. struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
  315. memcpy(prio_tbl_cmd.prio_tbl, iwlagn_bt_prio_tbl,
  316. sizeof(iwlagn_bt_prio_tbl));
  317. if (iwl_send_cmd_pdu(priv, REPLY_BT_COEX_PRIO_TABLE,
  318. sizeof(prio_tbl_cmd), &prio_tbl_cmd))
  319. IWL_ERR(priv, "failed to send BT prio tbl command\n");
  320. }
  321. static void iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
  322. {
  323. struct iwl_bt_coex_prot_env_cmd env_cmd;
  324. env_cmd.action = action;
  325. env_cmd.type = type;
  326. if (iwl_send_cmd_pdu(priv, REPLY_BT_COEX_PROT_ENV,
  327. sizeof(env_cmd), &env_cmd))
  328. IWL_ERR(priv, "failed to send BT env command\n");
  329. }
  330. int iwlagn_alive_notify(struct iwl_priv *priv)
  331. {
  332. u32 a;
  333. unsigned long flags;
  334. int i, chan;
  335. u32 reg_val;
  336. spin_lock_irqsave(&priv->lock, flags);
  337. priv->scd_base_addr = iwl_read_prph(priv, IWLAGN_SCD_SRAM_BASE_ADDR);
  338. a = priv->scd_base_addr + IWLAGN_SCD_CONTEXT_DATA_OFFSET;
  339. for (; a < priv->scd_base_addr + IWLAGN_SCD_TX_STTS_BITMAP_OFFSET;
  340. a += 4)
  341. iwl_write_targ_mem(priv, a, 0);
  342. for (; a < priv->scd_base_addr + IWLAGN_SCD_TRANSLATE_TBL_OFFSET;
  343. a += 4)
  344. iwl_write_targ_mem(priv, a, 0);
  345. for (; a < priv->scd_base_addr +
  346. IWLAGN_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
  347. iwl_write_targ_mem(priv, a, 0);
  348. iwl_write_prph(priv, IWLAGN_SCD_DRAM_BASE_ADDR,
  349. priv->scd_bc_tbls.dma >> 10);
  350. /* Enable DMA channel */
  351. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  352. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  353. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  354. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  355. /* Update FH chicken bits */
  356. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  357. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  358. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  359. iwl_write_prph(priv, IWLAGN_SCD_QUEUECHAIN_SEL,
  360. IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  361. iwl_write_prph(priv, IWLAGN_SCD_AGGR_SEL, 0);
  362. /* initiate the queues */
  363. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  364. iwl_write_prph(priv, IWLAGN_SCD_QUEUE_RDPTR(i), 0);
  365. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  366. iwl_write_targ_mem(priv, priv->scd_base_addr +
  367. IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  368. iwl_write_targ_mem(priv, priv->scd_base_addr +
  369. IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i) +
  370. sizeof(u32),
  371. ((SCD_WIN_SIZE <<
  372. IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  373. IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  374. ((SCD_FRAME_LIMIT <<
  375. IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  376. IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  377. }
  378. iwl_write_prph(priv, IWLAGN_SCD_INTERRUPT_MASK,
  379. IWL_MASK(0, priv->hw_params.max_txq_num));
  380. /* Activate all Tx DMA/FIFO channels */
  381. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  382. iwlagn_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  383. /* make sure all queue are not stopped */
  384. memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
  385. for (i = 0; i < 4; i++)
  386. atomic_set(&priv->queue_stop_count[i], 0);
  387. /* reset to 0 to enable all the queue first */
  388. priv->txq_ctx_active_msk = 0;
  389. /* map qos queues to fifos one-to-one */
  390. BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) != 10);
  391. for (i = 0; i < ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); i++) {
  392. int ac = iwlagn_default_queue_to_tx_fifo[i];
  393. iwl_txq_ctx_activate(priv, i);
  394. if (ac == IWL_TX_FIFO_UNUSED)
  395. continue;
  396. iwlagn_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  397. }
  398. spin_unlock_irqrestore(&priv->lock, flags);
  399. if (priv->cfg->advanced_bt_coexist) {
  400. /* Configure Bluetooth device coexistence support */
  401. /* need to perform this before any calibration */
  402. priv->bt_valid = IWL6000G2B_BT_ALL_VALID_MSK;
  403. priv->kill_ack_mask = IWL6000G2B_BT_KILL_ACK_MASK_DEFAULT;
  404. priv->kill_cts_mask = IWL6000G2B_BT_KILL_CTS_MASK_DEFAULT;
  405. priv->cfg->ops->hcmd->send_bt_config(priv);
  406. priv->bt_valid = IWL6000G2B_BT_VALID_ENABLE_FLAGS;
  407. if (bt_coex_active && priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  408. iwlagn_send_prio_tbl(priv);
  409. iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  410. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  411. iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  412. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  413. }
  414. }
  415. iwlagn_send_wimax_coex(priv);
  416. iwlagn_set_Xtal_calib(priv);
  417. iwl_send_calib_results(priv);
  418. return 0;
  419. }
  420. /**
  421. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  422. * using sample data 100 bytes apart. If these sample points are good,
  423. * it's a pretty good bet that everything between them is good, too.
  424. */
  425. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  426. {
  427. u32 val;
  428. int ret = 0;
  429. u32 errcnt = 0;
  430. u32 i;
  431. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  432. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  433. /* read data comes through single port, auto-incr addr */
  434. /* NOTE: Use the debugless read so we don't flood kernel log
  435. * if IWL_DL_IO is set */
  436. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  437. i + IWLAGN_RTC_INST_LOWER_BOUND);
  438. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  439. if (val != le32_to_cpu(*image)) {
  440. ret = -EIO;
  441. errcnt++;
  442. if (errcnt >= 3)
  443. break;
  444. }
  445. }
  446. return ret;
  447. }
  448. /**
  449. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  450. * looking at all data.
  451. */
  452. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  453. u32 len)
  454. {
  455. u32 val;
  456. u32 save_len = len;
  457. int ret = 0;
  458. u32 errcnt;
  459. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  460. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  461. IWLAGN_RTC_INST_LOWER_BOUND);
  462. errcnt = 0;
  463. for (; len > 0; len -= sizeof(u32), image++) {
  464. /* read data comes through single port, auto-incr addr */
  465. /* NOTE: Use the debugless read so we don't flood kernel log
  466. * if IWL_DL_IO is set */
  467. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  468. if (val != le32_to_cpu(*image)) {
  469. IWL_ERR(priv, "uCode INST section is invalid at "
  470. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  471. save_len - len, val, le32_to_cpu(*image));
  472. ret = -EIO;
  473. errcnt++;
  474. if (errcnt >= 20)
  475. break;
  476. }
  477. }
  478. if (!errcnt)
  479. IWL_DEBUG_INFO(priv,
  480. "ucode image in INSTRUCTION memory is good\n");
  481. return ret;
  482. }
  483. /**
  484. * iwl_verify_ucode - determine which instruction image is in SRAM,
  485. * and verify its contents
  486. */
  487. int iwl_verify_ucode(struct iwl_priv *priv)
  488. {
  489. __le32 *image;
  490. u32 len;
  491. int ret;
  492. /* Try bootstrap */
  493. image = (__le32 *)priv->ucode_boot.v_addr;
  494. len = priv->ucode_boot.len;
  495. ret = iwlcore_verify_inst_sparse(priv, image, len);
  496. if (!ret) {
  497. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  498. return 0;
  499. }
  500. /* Try initialize */
  501. image = (__le32 *)priv->ucode_init.v_addr;
  502. len = priv->ucode_init.len;
  503. ret = iwlcore_verify_inst_sparse(priv, image, len);
  504. if (!ret) {
  505. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  506. return 0;
  507. }
  508. /* Try runtime/protocol */
  509. image = (__le32 *)priv->ucode_code.v_addr;
  510. len = priv->ucode_code.len;
  511. ret = iwlcore_verify_inst_sparse(priv, image, len);
  512. if (!ret) {
  513. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  514. return 0;
  515. }
  516. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  517. /* Since nothing seems to match, show first several data entries in
  518. * instruction SRAM, so maybe visual inspection will give a clue.
  519. * Selection of bootstrap image (vs. other images) is arbitrary. */
  520. image = (__le32 *)priv->ucode_boot.v_addr;
  521. len = priv->ucode_boot.len;
  522. ret = iwl_verify_inst_full(priv, image, len);
  523. return ret;
  524. }