iwl-agn-ucode.c 20 KB

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