iwl-agn-ucode.c 20 KB

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