blob: 2dc569bc7e8f9221a3172fe0a89ead5add6a7977 [file] [log] [blame]
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -07001/******************************************************************************
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
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
Wey-Yi Guy81b81762010-03-16 10:23:30 -070033#include <linux/sched.h>
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -070034
35#include "iwl-dev.h"
36#include "iwl-core.h"
Wey-Yi Guy81b81762010-03-16 10:23:30 -070037#include "iwl-io.h"
Wey-Yi Guy741a6262010-03-16 12:37:24 -070038#include "iwl-helpers.h"
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -070039#include "iwl-agn-hw.h"
Wey-Yi Guy741a6262010-03-16 12:37:24 -070040#include "iwl-agn.h"
41
42static const s8 iwlagn_default_queue_to_tx_fifo[] = {
43 IWL_TX_FIFO_VO,
44 IWL_TX_FIFO_VI,
45 IWL_TX_FIFO_BE,
46 IWL_TX_FIFO_BK,
47 IWLAGN_CMD_FIFO_NUM,
48 IWL_TX_FIFO_UNUSED,
49 IWL_TX_FIFO_UNUSED,
50 IWL_TX_FIFO_UNUSED,
51 IWL_TX_FIFO_UNUSED,
52 IWL_TX_FIFO_UNUSED,
53};
Wey-Yi Guy81b81762010-03-16 10:23:30 -070054
Wey-Yi Guyf4012412010-04-27 14:10:00 -070055static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
56 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
57 0, COEX_UNASSOC_IDLE_FLAGS},
58 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
59 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
60 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
61 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
62 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
63 0, COEX_CALIBRATION_FLAGS},
64 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
65 0, COEX_PERIODIC_CALIBRATION_FLAGS},
66 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
67 0, COEX_CONNECTION_ESTAB_FLAGS},
68 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
69 0, COEX_ASSOCIATED_IDLE_FLAGS},
70 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
71 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
72 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
73 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
74 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
75 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
76 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
77 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
78 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
79 0, COEX_STAND_ALONE_DEBUG_FLAGS},
80 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
81 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
82 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
83 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
84};
85
Wey-Yi Guy81b81762010-03-16 10:23:30 -070086/*
87 * ucode
88 */
89static int iwlagn_load_section(struct iwl_priv *priv, const char *name,
90 struct fw_desc *image, u32 dst_addr)
91{
92 dma_addr_t phy_addr = image->p_addr;
93 u32 byte_cnt = image->len;
94 int ret;
95
96 priv->ucode_write_complete = 0;
97
98 iwl_write_direct32(priv,
99 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
100 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
101
102 iwl_write_direct32(priv,
103 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
104
105 iwl_write_direct32(priv,
106 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
107 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
108
109 iwl_write_direct32(priv,
110 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
111 (iwl_get_dma_hi_addr(phy_addr)
112 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
113
114 iwl_write_direct32(priv,
115 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
116 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
117 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
118 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
119
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
126 IWL_DEBUG_INFO(priv, "%s uCode section being loaded...\n", name);
127 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
128 priv->ucode_write_complete, 5 * HZ);
129 if (ret == -ERESTARTSYS) {
130 IWL_ERR(priv, "Could not load the %s uCode section due "
131 "to interrupt\n", name);
132 return ret;
133 }
134 if (!ret) {
135 IWL_ERR(priv, "Could not load the %s uCode section\n",
136 name);
137 return -ETIMEDOUT;
138 }
139
140 return 0;
141}
142
143static int iwlagn_load_given_ucode(struct iwl_priv *priv,
144 struct fw_desc *inst_image,
145 struct fw_desc *data_image)
146{
147 int ret = 0;
148
149 ret = iwlagn_load_section(priv, "INST", inst_image,
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -0700150 IWLAGN_RTC_INST_LOWER_BOUND);
Wey-Yi Guy81b81762010-03-16 10:23:30 -0700151 if (ret)
152 return ret;
153
154 return iwlagn_load_section(priv, "DATA", data_image,
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -0700155 IWLAGN_RTC_DATA_LOWER_BOUND);
Wey-Yi Guy81b81762010-03-16 10:23:30 -0700156}
157
158int iwlagn_load_ucode(struct iwl_priv *priv)
159{
160 int ret = 0;
161
162 /* check whether init ucode should be loaded, or rather runtime ucode */
163 if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
164 IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
165 ret = iwlagn_load_given_ucode(priv,
166 &priv->ucode_init, &priv->ucode_init_data);
167 if (!ret) {
168 IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
169 priv->ucode_type = UCODE_INIT;
170 }
171 } else {
172 IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
173 "Loading runtime ucode...\n");
174 ret = iwlagn_load_given_ucode(priv,
175 &priv->ucode_code, &priv->ucode_data);
176 if (!ret) {
177 IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
178 priv->ucode_type = UCODE_RT;
179 }
180 }
181
182 return ret;
183}
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -0700184
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700185/*
186 * Calibration
187 */
188static int iwlagn_set_Xtal_calib(struct iwl_priv *priv)
189{
190 struct iwl_calib_xtal_freq_cmd cmd;
191 __le16 *xtal_calib =
Wey-Yi Guy7944f8e2010-04-06 21:10:33 -0700192 (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_XTAL);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700193
194 cmd.hdr.op_code = IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
195 cmd.hdr.first_group = 0;
196 cmd.hdr.groups_num = 1;
197 cmd.hdr.data_valid = 1;
198 cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
199 cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
200 return iwl_calib_set(&priv->calib_results[IWL_CALIB_XTAL],
201 (u8 *)&cmd, sizeof(cmd));
202}
203
204static int iwlagn_send_calib_cfg(struct iwl_priv *priv)
205{
206 struct iwl_calib_cfg_cmd calib_cfg_cmd;
207 struct iwl_host_cmd cmd = {
208 .id = CALIBRATION_CFG_CMD,
209 .len = sizeof(struct iwl_calib_cfg_cmd),
210 .data = &calib_cfg_cmd,
211 };
212
213 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
214 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
215 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
216 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
217 calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
218
219 return iwl_send_cmd(priv, &cmd);
220}
221
222void iwlagn_rx_calib_result(struct iwl_priv *priv,
223 struct iwl_rx_mem_buffer *rxb)
224{
225 struct iwl_rx_packet *pkt = rxb_addr(rxb);
226 struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw;
227 int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
228 int index;
229
230 /* reduce the size of the length field itself */
231 len -= 4;
232
233 /* Define the order in which the results will be sent to the runtime
234 * uCode. iwl_send_calib_results sends them in a row according to
235 * their index. We sort them here
236 */
237 switch (hdr->op_code) {
238 case IWL_PHY_CALIBRATE_DC_CMD:
239 index = IWL_CALIB_DC;
240 break;
241 case IWL_PHY_CALIBRATE_LO_CMD:
242 index = IWL_CALIB_LO;
243 break;
244 case IWL_PHY_CALIBRATE_TX_IQ_CMD:
245 index = IWL_CALIB_TX_IQ;
246 break;
247 case IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD:
248 index = IWL_CALIB_TX_IQ_PERD;
249 break;
250 case IWL_PHY_CALIBRATE_BASE_BAND_CMD:
251 index = IWL_CALIB_BASE_BAND;
252 break;
253 default:
254 IWL_ERR(priv, "Unknown calibration notification %d\n",
255 hdr->op_code);
256 return;
257 }
258 iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
259}
260
261void iwlagn_rx_calib_complete(struct iwl_priv *priv,
262 struct iwl_rx_mem_buffer *rxb)
263{
264 IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n");
265 queue_work(priv->workqueue, &priv->restart);
266}
267
268void iwlagn_init_alive_start(struct iwl_priv *priv)
269{
270 int ret = 0;
271
272 /* Check alive response for "valid" sign from uCode */
273 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
274 /* We had an error bringing up the hardware, so take it
275 * all the way back down so we can try again */
276 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
277 goto restart;
278 }
279
280 /* initialize uCode was loaded... verify inst image.
281 * This is a paranoid check, because we would not have gotten the
282 * "initialize" alive if code weren't properly loaded. */
283 if (iwl_verify_ucode(priv)) {
284 /* Runtime instruction load was bad;
285 * take it all the way back down so we can try again */
286 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
287 goto restart;
288 }
289
290 ret = priv->cfg->ops->lib->alive_notify(priv);
291 if (ret) {
292 IWL_WARN(priv,
293 "Could not complete ALIVE transition: %d\n", ret);
294 goto restart;
295 }
296
297 iwlagn_send_calib_cfg(priv);
298 return;
299
300restart:
301 /* real restart (first load init_ucode) */
302 queue_work(priv->workqueue, &priv->restart);
303}
304
Wey-Yi Guyf4012412010-04-27 14:10:00 -0700305static int iwlagn_send_wimax_coex(struct iwl_priv *priv)
306{
307 struct iwl_wimax_coex_cmd coex_cmd;
308
309 if (priv->cfg->support_wimax_coexist) {
310 /* UnMask wake up src at associated sleep */
311 coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
312
313 /* UnMask wake up src at unassociated sleep */
314 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
315 memcpy(coex_cmd.sta_prio, cu_priorities,
316 sizeof(struct iwl_wimax_coex_event_entry) *
317 COEX_NUM_OF_EVENTS);
318
319 /* enabling the coexistence feature */
320 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
321
322 /* enabling the priorities tables */
323 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
324 } else {
325 /* coexistence is disabled */
326 memset(&coex_cmd, 0, sizeof(coex_cmd));
327 }
328 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
329 sizeof(coex_cmd), &coex_cmd);
330}
331
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700332static const u8 iwlagn_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
333 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
334 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
335 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
336 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
337 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
338 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
339 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
340 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
341 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
342 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
343 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
344 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
345 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
346 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
347 ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
348 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
349 ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
350 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
351 0, 0, 0, 0, 0, 0, 0
352};
353
354static void iwlagn_send_prio_tbl(struct iwl_priv *priv)
355{
356 struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
357
358 memcpy(prio_tbl_cmd.prio_tbl, iwlagn_bt_prio_tbl,
359 sizeof(iwlagn_bt_prio_tbl));
360 if (iwl_send_cmd_pdu(priv, REPLY_BT_COEX_PRIO_TABLE,
361 sizeof(prio_tbl_cmd), &prio_tbl_cmd))
362 IWL_ERR(priv, "failed to send BT prio tbl command\n");
363}
364
365static void iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
366{
367 struct iwl_bt_coex_prot_env_cmd env_cmd;
368
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
376
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700377int iwlagn_alive_notify(struct iwl_priv *priv)
378{
379 u32 a;
380 unsigned long flags;
381 int i, chan;
382 u32 reg_val;
383
384 spin_lock_irqsave(&priv->lock, flags);
385
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700386 priv->scd_base_addr = iwl_read_prph(priv, IWLAGN_SCD_SRAM_BASE_ADDR);
387 a = priv->scd_base_addr + IWLAGN_SCD_CONTEXT_DATA_OFFSET;
388 for (; a < priv->scd_base_addr + IWLAGN_SCD_TX_STTS_BITMAP_OFFSET;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700389 a += 4)
390 iwl_write_targ_mem(priv, a, 0);
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700391 for (; a < priv->scd_base_addr + IWLAGN_SCD_TRANSLATE_TBL_OFFSET;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700392 a += 4)
393 iwl_write_targ_mem(priv, a, 0);
394 for (; a < priv->scd_base_addr +
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700395 IWLAGN_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700396 iwl_write_targ_mem(priv, a, 0);
397
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700398 iwl_write_prph(priv, IWLAGN_SCD_DRAM_BASE_ADDR,
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700399 priv->scd_bc_tbls.dma >> 10);
400
401 /* Enable DMA channel */
402 for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
403 iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
404 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
405 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
406
407 /* Update FH chicken bits */
408 reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
409 iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
410 reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
411
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700412 iwl_write_prph(priv, IWLAGN_SCD_QUEUECHAIN_SEL,
413 IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
414 iwl_write_prph(priv, IWLAGN_SCD_AGGR_SEL, 0);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700415
416 /* initiate the queues */
417 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700418 iwl_write_prph(priv, IWLAGN_SCD_QUEUE_RDPTR(i), 0);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700419 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
420 iwl_write_targ_mem(priv, priv->scd_base_addr +
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700421 IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700422 iwl_write_targ_mem(priv, priv->scd_base_addr +
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700423 IWLAGN_SCD_CONTEXT_QUEUE_OFFSET(i) +
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700424 sizeof(u32),
425 ((SCD_WIN_SIZE <<
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700426 IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
427 IWLAGN_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700428 ((SCD_FRAME_LIMIT <<
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700429 IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
430 IWLAGN_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700431 }
432
Wey-Yi Guyf4388ad2010-04-12 18:32:11 -0700433 iwl_write_prph(priv, IWLAGN_SCD_INTERRUPT_MASK,
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700434 IWL_MASK(0, priv->hw_params.max_txq_num));
435
436 /* Activate all Tx DMA/FIFO channels */
437 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
438
439 iwlagn_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
440
441 /* make sure all queue are not stopped */
442 memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
443 for (i = 0; i < 4; i++)
444 atomic_set(&priv->queue_stop_count[i], 0);
445
446 /* reset to 0 to enable all the queue first */
447 priv->txq_ctx_active_msk = 0;
448 /* map qos queues to fifos one-to-one */
449 BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) != 10);
450
451 for (i = 0; i < ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); i++) {
452 int ac = iwlagn_default_queue_to_tx_fifo[i];
453
454 iwl_txq_ctx_activate(priv, i);
455
456 if (ac == IWL_TX_FIFO_UNUSED)
457 continue;
458
459 iwlagn_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
460 }
461
462 spin_unlock_irqrestore(&priv->lock, flags);
463
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700464 if (priv->cfg->advanced_bt_coexist) {
465 /* Configure Bluetooth device coexistence support */
466 /* need to perform this before any calibration */
467 priv->cfg->ops->hcmd->send_bt_config(priv);
468 if (bt_coex_active && priv->iw_mode != NL80211_IFTYPE_ADHOC) {
469 iwlagn_send_prio_tbl(priv);
470 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
471 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
472 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
473 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
474 }
475
476 }
477
Wey-Yi Guyf4012412010-04-27 14:10:00 -0700478 iwlagn_send_wimax_coex(priv);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700479
480 iwlagn_set_Xtal_calib(priv);
481 iwl_send_calib_results(priv);
482
483 return 0;
484}
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700485
486
487/**
488 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
489 * using sample data 100 bytes apart. If these sample points are good,
490 * it's a pretty good bet that everything between them is good, too.
491 */
492static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
493{
494 u32 val;
495 int ret = 0;
496 u32 errcnt = 0;
497 u32 i;
498
499 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
500
501 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
502 /* read data comes through single port, auto-incr addr */
503 /* NOTE: Use the debugless read so we don't flood kernel log
504 * if IWL_DL_IO is set */
505 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
506 i + IWLAGN_RTC_INST_LOWER_BOUND);
507 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
508 if (val != le32_to_cpu(*image)) {
509 ret = -EIO;
510 errcnt++;
511 if (errcnt >= 3)
512 break;
513 }
514 }
515
516 return ret;
517}
518
519/**
520 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
521 * looking at all data.
522 */
523static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
524 u32 len)
525{
526 u32 val;
527 u32 save_len = len;
528 int ret = 0;
529 u32 errcnt;
530
531 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
532
533 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
534 IWLAGN_RTC_INST_LOWER_BOUND);
535
536 errcnt = 0;
537 for (; len > 0; len -= sizeof(u32), image++) {
538 /* read data comes through single port, auto-incr addr */
539 /* NOTE: Use the debugless read so we don't flood kernel log
540 * if IWL_DL_IO is set */
541 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
542 if (val != le32_to_cpu(*image)) {
543 IWL_ERR(priv, "uCode INST section is invalid at "
544 "offset 0x%x, is 0x%x, s/b 0x%x\n",
545 save_len - len, val, le32_to_cpu(*image));
546 ret = -EIO;
547 errcnt++;
548 if (errcnt >= 20)
549 break;
550 }
551 }
552
553 if (!errcnt)
554 IWL_DEBUG_INFO(priv,
555 "ucode image in INSTRUCTION memory is good\n");
556
557 return ret;
558}
559
560/**
561 * iwl_verify_ucode - determine which instruction image is in SRAM,
562 * and verify its contents
563 */
564int iwl_verify_ucode(struct iwl_priv *priv)
565{
566 __le32 *image;
567 u32 len;
568 int ret;
569
570 /* Try bootstrap */
571 image = (__le32 *)priv->ucode_boot.v_addr;
572 len = priv->ucode_boot.len;
573 ret = iwlcore_verify_inst_sparse(priv, image, len);
574 if (!ret) {
575 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
576 return 0;
577 }
578
579 /* Try initialize */
580 image = (__le32 *)priv->ucode_init.v_addr;
581 len = priv->ucode_init.len;
582 ret = iwlcore_verify_inst_sparse(priv, image, len);
583 if (!ret) {
584 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
585 return 0;
586 }
587
588 /* Try runtime/protocol */
589 image = (__le32 *)priv->ucode_code.v_addr;
590 len = priv->ucode_code.len;
591 ret = iwlcore_verify_inst_sparse(priv, image, len);
592 if (!ret) {
593 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
594 return 0;
595 }
596
597 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
598
599 /* Since nothing seems to match, show first several data entries in
600 * instruction SRAM, so maybe visual inspection will give a clue.
601 * Selection of bootstrap image (vs. other images) is arbitrary. */
602 image = (__le32 *)priv->ucode_boot.v_addr;
603 len = priv->ucode_boot.len;
604 ret = iwl_verify_inst_full(priv, image, len);
605
606 return ret;
607}