blob: 36039eb54dd4d2787a72ef3824c03d728f2669ed [file] [log] [blame]
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08005 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -07006 *
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>
Don Fryde7f5f92011-11-10 06:55:10 -080034#include <linux/dma-mapping.h>
Don Fryedf38332012-01-25 16:18:52 -080035#include <linux/firmware.h>
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -070036
Don Fryedf38332012-01-25 16:18:52 -080037#include "iwl-ucode.h"
Don Fry69a679b2011-12-07 08:50:46 -080038#include "iwl-wifi.h"
Wey-Yi Guy792bc3c2010-03-16 10:23:29 -070039#include "iwl-dev.h"
40#include "iwl-core.h"
Wey-Yi Guy81b81762010-03-16 10:23:30 -070041#include "iwl-io.h"
Wey-Yi Guy19e6cda2010-03-16 17:41:23 -070042#include "iwl-agn-hw.h"
Wey-Yi Guy741a6262010-03-16 12:37:24 -070043#include "iwl-agn.h"
Johannes Berg0de76732010-09-22 18:02:11 +020044#include "iwl-agn-calib.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070045#include "iwl-trans.h"
Emmanuel Grumbachdda61a42011-08-25 23:11:11 -070046#include "iwl-fh.h"
Wey-Yi Guy741a6262010-03-16 12:37:24 -070047
Wey-Yi Guyf4012412010-04-27 14:10:00 -070048static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
49 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
50 0, COEX_UNASSOC_IDLE_FLAGS},
51 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
52 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
53 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
54 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
55 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
56 0, COEX_CALIBRATION_FLAGS},
57 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
58 0, COEX_PERIODIC_CALIBRATION_FLAGS},
59 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
60 0, COEX_CONNECTION_ESTAB_FLAGS},
61 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
62 0, COEX_ASSOCIATED_IDLE_FLAGS},
63 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
64 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
65 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
66 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
67 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
68 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
69 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
70 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
71 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
72 0, COEX_STAND_ALONE_DEBUG_FLAGS},
73 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
74 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
75 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
76 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
77};
78
Don Fryde7f5f92011-11-10 06:55:10 -080079/******************************************************************************
80 *
81 * uCode download functions
82 *
83 ******************************************************************************/
84
Emmanuel Grumbach8467ab42012-01-03 16:28:12 +020085static void iwl_free_fw_desc(struct iwl_trans *trans, struct fw_desc *desc)
Don Fryde7f5f92011-11-10 06:55:10 -080086{
87 if (desc->v_addr)
Emmanuel Grumbach8467ab42012-01-03 16:28:12 +020088 dma_free_coherent(trans->dev, desc->len,
Don Fryde7f5f92011-11-10 06:55:10 -080089 desc->v_addr, desc->p_addr);
90 desc->v_addr = NULL;
91 desc->len = 0;
92}
93
Emmanuel Grumbach8467ab42012-01-03 16:28:12 +020094static void iwl_free_fw_img(struct iwl_trans *trans, struct fw_img *img)
Don Fryde7f5f92011-11-10 06:55:10 -080095{
Emmanuel Grumbach8467ab42012-01-03 16:28:12 +020096 iwl_free_fw_desc(trans, &img->code);
97 iwl_free_fw_desc(trans, &img->data);
Don Fryde7f5f92011-11-10 06:55:10 -080098}
99
100void iwl_dealloc_ucode(struct iwl_trans *trans)
101{
Don Fry65161742012-02-07 15:00:12 -0800102 struct iwl_nic *nic = nic(trans);
103 iwl_free_fw_img(trans, &nic->fw.ucode_rt);
104 iwl_free_fw_img(trans, &nic->fw.ucode_init);
105 iwl_free_fw_img(trans, &nic->fw.ucode_wowlan);
Don Fryde7f5f92011-11-10 06:55:10 -0800106}
107
Don Fryedf38332012-01-25 16:18:52 -0800108static int iwl_alloc_fw_desc(struct iwl_trans *trans, struct fw_desc *desc,
Don Fryde7f5f92011-11-10 06:55:10 -0800109 const void *data, size_t len)
110{
111 if (!len) {
112 desc->v_addr = NULL;
113 return -EINVAL;
114 }
115
Emmanuel Grumbach8467ab42012-01-03 16:28:12 +0200116 desc->v_addr = dma_alloc_coherent(trans->dev, len,
Don Fryde7f5f92011-11-10 06:55:10 -0800117 &desc->p_addr, GFP_KERNEL);
118 if (!desc->v_addr)
119 return -ENOMEM;
120
121 desc->len = len;
122 memcpy(desc->v_addr, data, len);
123 return 0;
124}
125
Don Fry65161742012-02-07 15:00:12 -0800126static inline struct fw_img *iwl_get_ucode_image(struct iwl_nic *nic,
Don Fryde7f5f92011-11-10 06:55:10 -0800127 enum iwl_ucode_type ucode_type)
Don Fry8929c242011-11-10 06:55:08 -0800128{
129 switch (ucode_type) {
130 case IWL_UCODE_INIT:
Don Fry65161742012-02-07 15:00:12 -0800131 return &nic->fw.ucode_init;
Don Fry8929c242011-11-10 06:55:08 -0800132 case IWL_UCODE_WOWLAN:
Don Fry65161742012-02-07 15:00:12 -0800133 return &nic->fw.ucode_wowlan;
Don Fry8929c242011-11-10 06:55:08 -0800134 case IWL_UCODE_REGULAR:
Don Fry65161742012-02-07 15:00:12 -0800135 return &nic->fw.ucode_rt;
Don Fry8929c242011-11-10 06:55:08 -0800136 case IWL_UCODE_NONE:
137 break;
138 }
139 return NULL;
140}
141
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700142/*
143 * Calibration
144 */
Don Fry69a679b2011-12-07 08:50:46 -0800145static int iwl_set_Xtal_calib(struct iwl_trans *trans)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700146{
147 struct iwl_calib_xtal_freq_cmd cmd;
148 __le16 *xtal_calib =
Don Fry69a679b2011-12-07 08:50:46 -0800149 (__le16 *)iwl_eeprom_query_addr(trans->shrd, EEPROM_XTAL);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700150
Wey-Yi Guy1f8bf032011-06-06 14:26:43 -0700151 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700152 cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
153 cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]);
Don Fry69a679b2011-12-07 08:50:46 -0800154 return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd));
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700155}
156
Don Fry69a679b2011-12-07 08:50:46 -0800157static int iwl_set_temperature_offset_calib(struct iwl_trans *trans)
Shanyu Zhaobf53f932010-09-21 16:54:01 -0700158{
159 struct iwl_calib_temperature_offset_cmd cmd;
160 __le16 *offset_calib =
Don Fry69a679b2011-12-07 08:50:46 -0800161 (__le16 *)iwl_eeprom_query_addr(trans->shrd,
Don Fryab36eab2011-11-30 15:37:32 -0800162 EEPROM_RAW_TEMPERATURE);
Wey-Yi Guy1f8bf032011-06-06 14:26:43 -0700163
164 memset(&cmd, 0, sizeof(cmd));
165 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
Johannes Berg456fc372011-09-12 21:08:25 +0200166 memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib));
Shanyu Zhaobf53f932010-09-21 16:54:01 -0700167 if (!(cmd.radio_sensor_offset))
168 cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
Wey-Yi Guy1f8bf032011-06-06 14:26:43 -0700169
Don Fry69a679b2011-12-07 08:50:46 -0800170 IWL_DEBUG_CALIB(trans, "Radio sensor offset: %d\n",
Wey-Yi Guy2e277992011-07-08 14:29:48 -0700171 le16_to_cpu(cmd.radio_sensor_offset));
Don Fry69a679b2011-12-07 08:50:46 -0800172 return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd));
Shanyu Zhaobf53f932010-09-21 16:54:01 -0700173}
174
Don Fry69a679b2011-12-07 08:50:46 -0800175static int iwl_set_temperature_offset_calib_v2(struct iwl_trans *trans)
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700176{
177 struct iwl_calib_temperature_offset_v2_cmd cmd;
Don Fry69a679b2011-12-07 08:50:46 -0800178 __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(trans->shrd,
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700179 EEPROM_KELVIN_TEMPERATURE);
180 __le16 *offset_calib_low =
Don Fry69a679b2011-12-07 08:50:46 -0800181 (__le16 *)iwl_eeprom_query_addr(trans->shrd,
Don Fryab36eab2011-11-30 15:37:32 -0800182 EEPROM_RAW_TEMPERATURE);
Wey-Yi Guy7d8f2d52011-09-15 11:46:51 -0700183 struct iwl_eeprom_calib_hdr *hdr;
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700184
185 memset(&cmd, 0, sizeof(cmd));
186 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
Don Fry69a679b2011-12-07 08:50:46 -0800187 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(trans->shrd,
Wey-Yi Guy7d8f2d52011-09-15 11:46:51 -0700188 EEPROM_CALIB_ALL);
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700189 memcpy(&cmd.radio_sensor_offset_high, offset_calib_high,
Wey-Yi Guy00085002011-09-15 11:46:53 -0700190 sizeof(*offset_calib_high));
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700191 memcpy(&cmd.radio_sensor_offset_low, offset_calib_low,
Wey-Yi Guy00085002011-09-15 11:46:53 -0700192 sizeof(*offset_calib_low));
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700193 if (!(cmd.radio_sensor_offset_low)) {
Don Fry69a679b2011-12-07 08:50:46 -0800194 IWL_DEBUG_CALIB(trans, "no info in EEPROM, use default\n");
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700195 cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET;
196 cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET;
197 }
Wey-Yi Guy7d8f2d52011-09-15 11:46:51 -0700198 memcpy(&cmd.burntVoltageRef, &hdr->voltage,
199 sizeof(hdr->voltage));
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700200
Don Fry69a679b2011-12-07 08:50:46 -0800201 IWL_DEBUG_CALIB(trans, "Radio sensor offset high: %d\n",
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700202 le16_to_cpu(cmd.radio_sensor_offset_high));
Don Fry69a679b2011-12-07 08:50:46 -0800203 IWL_DEBUG_CALIB(trans, "Radio sensor offset low: %d\n",
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700204 le16_to_cpu(cmd.radio_sensor_offset_low));
Don Fry69a679b2011-12-07 08:50:46 -0800205 IWL_DEBUG_CALIB(trans, "Voltage Ref: %d\n",
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700206 le16_to_cpu(cmd.burntVoltageRef));
207
Don Fry69a679b2011-12-07 08:50:46 -0800208 return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd));
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700209}
210
Don Fry66128b12011-11-28 14:35:14 -0800211static int iwl_send_calib_cfg(struct iwl_trans *trans)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700212{
213 struct iwl_calib_cfg_cmd calib_cfg_cmd;
214 struct iwl_host_cmd cmd = {
215 .id = CALIBRATION_CFG_CMD,
Johannes Berg3fa50732011-05-04 07:50:38 -0700216 .len = { sizeof(struct iwl_calib_cfg_cmd), },
217 .data = { &calib_cfg_cmd, },
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700218 };
219
220 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
221 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
222 calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
223 calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
Wey-Yi Guydf2a4dc2011-07-08 14:29:45 -0700224 calib_cfg_cmd.ucd_calib_cfg.flags =
225 IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700226
Don Fry66128b12011-11-28 14:35:14 -0800227 return iwl_trans_send_cmd(trans, &cmd);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700228}
229
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700230int iwlagn_rx_calib_result(struct iwl_priv *priv,
231 struct iwl_rx_mem_buffer *rxb,
232 struct iwl_device_cmd *cmd)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700233{
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;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700237
238 /* reduce the size of the length field itself */
239 len -= 4;
240
Don Fry45c30db2011-11-30 16:58:39 -0800241 if (iwl_calib_set(trans(priv), hdr, len))
Johannes Bergf02c2fd2011-11-17 08:51:57 -0800242 IWL_ERR(priv, "Failed to record calibration data %d\n",
243 hdr->op_code);
244
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700245 return 0;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700246}
247
Don Fry69a679b2011-12-07 08:50:46 -0800248int iwl_init_alive_start(struct iwl_trans *trans)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700249{
Johannes Bergca7966c2011-04-22 10:15:23 -0700250 int ret;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700251
Don Fry69a679b2011-12-07 08:50:46 -0800252 if (cfg(trans)->bt_params &&
253 cfg(trans)->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700254 /*
255 * Tell uCode we are ready to perform calibration
256 * need to perform this before any calibration
257 * no need to close the envlope since we are going
258 * to load the runtime uCode later.
259 */
Don Fry69a679b2011-12-07 08:50:46 -0800260 ret = iwl_send_bt_env(trans, IWL_BT_COEX_ENV_OPEN,
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700261 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
Johannes Bergca7966c2011-04-22 10:15:23 -0700262 if (ret)
263 return ret;
Wey-Yi Guyf7322f82010-08-23 15:24:49 -0700264
265 }
Johannes Bergca7966c2011-04-22 10:15:23 -0700266
Don Fry69a679b2011-12-07 08:50:46 -0800267 ret = iwl_send_calib_cfg(trans);
Johannes Bergca7966c2011-04-22 10:15:23 -0700268 if (ret)
269 return ret;
Shanyu Zhaobf53f932010-09-21 16:54:01 -0700270
271 /**
272 * temperature offset calibration is only needed for runtime ucode,
273 * so prepare the value now.
274 */
Don Fry69a679b2011-12-07 08:50:46 -0800275 if (cfg(trans)->need_temp_offset_calib) {
276 if (cfg(trans)->temp_offset_v2)
277 return iwl_set_temperature_offset_calib_v2(trans);
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700278 else
Don Fry69a679b2011-12-07 08:50:46 -0800279 return iwl_set_temperature_offset_calib(trans);
Wey-Yi Guyc6f30342011-09-15 11:46:50 -0700280 }
Shanyu Zhaobf53f932010-09-21 16:54:01 -0700281
Johannes Bergca7966c2011-04-22 10:15:23 -0700282 return 0;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700283}
284
Don Fry69a679b2011-12-07 08:50:46 -0800285static int iwl_send_wimax_coex(struct iwl_trans *trans)
Wey-Yi Guyf4012412010-04-27 14:10:00 -0700286{
287 struct iwl_wimax_coex_cmd coex_cmd;
288
Don Fry69a679b2011-12-07 08:50:46 -0800289 if (cfg(trans)->base_params->support_wimax_coexist) {
Wey-Yi Guyf4012412010-04-27 14:10:00 -0700290 /* UnMask wake up src at associated sleep */
291 coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
292
293 /* UnMask wake up src at unassociated sleep */
294 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
295 memcpy(coex_cmd.sta_prio, cu_priorities,
296 sizeof(struct iwl_wimax_coex_event_entry) *
297 COEX_NUM_OF_EVENTS);
298
299 /* enabling the coexistence feature */
300 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
301
302 /* enabling the priorities tables */
303 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
304 } else {
305 /* coexistence is disabled */
306 memset(&coex_cmd, 0, sizeof(coex_cmd));
307 }
Don Fry69a679b2011-12-07 08:50:46 -0800308 return iwl_trans_send_cmd_pdu(trans,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700309 COEX_PRIORITY_TABLE_CMD, CMD_SYNC,
Wey-Yi Guyf4012412010-04-27 14:10:00 -0700310 sizeof(coex_cmd), &coex_cmd);
311}
312
Don Fry66128b12011-11-28 14:35:14 -0800313static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700314 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
315 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
316 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
317 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
318 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
319 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
320 ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
321 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
322 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
323 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
324 ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
325 (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
326 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
327 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
328 ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
329 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
330 ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
331 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
332 0, 0, 0, 0, 0, 0, 0
333};
334
Don Fry66128b12011-11-28 14:35:14 -0800335void iwl_send_prio_tbl(struct iwl_trans *trans)
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700336{
337 struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
338
Don Fry66128b12011-11-28 14:35:14 -0800339 memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl,
340 sizeof(iwl_bt_prio_tbl));
341 if (iwl_trans_send_cmd_pdu(trans,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700342 REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC,
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700343 sizeof(prio_tbl_cmd), &prio_tbl_cmd))
Don Fry66128b12011-11-28 14:35:14 -0800344 IWL_ERR(trans, "failed to send BT prio tbl command\n");
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700345}
346
Don Fry66128b12011-11-28 14:35:14 -0800347int iwl_send_bt_env(struct iwl_trans *trans, u8 action, u8 type)
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700348{
349 struct iwl_bt_coex_prot_env_cmd env_cmd;
Johannes Bergca7966c2011-04-22 10:15:23 -0700350 int ret;
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700351
352 env_cmd.action = action;
353 env_cmd.type = type;
Don Fry66128b12011-11-28 14:35:14 -0800354 ret = iwl_trans_send_cmd_pdu(trans,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700355 REPLY_BT_COEX_PROT_ENV, CMD_SYNC,
Johannes Bergca7966c2011-04-22 10:15:23 -0700356 sizeof(env_cmd), &env_cmd);
357 if (ret)
Don Fry66128b12011-11-28 14:35:14 -0800358 IWL_ERR(trans, "failed to send BT env command\n");
Johannes Bergca7966c2011-04-22 10:15:23 -0700359 return ret;
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -0700360}
361
362
Don Fry69a679b2011-12-07 08:50:46 -0800363static int iwl_alive_notify(struct iwl_trans *trans)
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700364{
Don Fry69a679b2011-12-07 08:50:46 -0800365 struct iwl_priv *priv = priv(trans);
Emmanuel Grumbach7a10e3e42011-09-06 09:31:21 -0700366 struct iwl_rxon_context *ctx;
Wey-Yi Guy74159522011-04-05 09:42:01 -0700367 int ret;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700368
Emmanuel Grumbachdfa2bdb2011-08-25 23:11:23 -0700369 if (!priv->tx_cmd_pool)
370 priv->tx_cmd_pool =
Don Fry66128b12011-11-28 14:35:14 -0800371 kmem_cache_create("iwl_dev_cmd",
Emmanuel Grumbachdfa2bdb2011-08-25 23:11:23 -0700372 sizeof(struct iwl_device_cmd),
373 sizeof(void *), 0, NULL);
374
375 if (!priv->tx_cmd_pool)
376 return -ENOMEM;
377
Emmanuel Grumbached6a3802012-01-02 16:10:08 +0200378 iwl_trans_fw_alive(trans);
Emmanuel Grumbach7a10e3e42011-09-06 09:31:21 -0700379 for_each_context(priv, ctx)
380 ctx->last_tx_rejected = false;
Grumbach, Emmanuele7cad692010-11-18 03:47:38 -0800381
Don Fry69a679b2011-12-07 08:50:46 -0800382 ret = iwl_send_wimax_coex(trans);
Wey-Yi Guy74159522011-04-05 09:42:01 -0700383 if (ret)
384 return ret;
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700385
Don Fry38622412011-12-16 07:07:36 -0800386 if (!cfg(priv)->no_xtal_calib) {
Don Fry69a679b2011-12-07 08:50:46 -0800387 ret = iwl_set_Xtal_calib(trans);
Johannes Berg93b64102011-11-17 08:51:53 -0800388 if (ret)
389 return ret;
390 }
Wey-Yi Guy74159522011-04-05 09:42:01 -0700391
Don Fry69a679b2011-12-07 08:50:46 -0800392 return iwl_send_calib_results(trans);
Wey-Yi Guy741a6262010-03-16 12:37:24 -0700393}
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700394
395
396/**
397 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
398 * using sample data 100 bytes apart. If these sample points are good,
399 * it's a pretty good bet that everything between them is good, too.
400 */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200401static int iwl_verify_inst_sparse(struct iwl_trans *trans,
Johannes Berg35b1d922011-04-05 09:41:56 -0700402 struct fw_desc *fw_desc)
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700403{
Johannes Berg35b1d922011-04-05 09:41:56 -0700404 __le32 *image = (__le32 *)fw_desc->v_addr;
405 u32 len = fw_desc->len;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700406 u32 val;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700407 u32 i;
408
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200409 IWL_DEBUG_FW(trans, "ucode inst image size is %u\n", len);
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700410
411 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
412 /* read data comes through single port, auto-incr addr */
413 /* NOTE: Use the debugless read so we don't flood kernel log
414 * if IWL_DL_IO is set */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200415 iwl_write_direct32(trans, HBUS_TARG_MEM_RADDR,
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700416 i + IWLAGN_RTC_INST_LOWER_BOUND);
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200417 val = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
Johannes Bergfb662162011-04-05 09:41:55 -0700418 if (val != le32_to_cpu(*image))
419 return -EIO;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700420 }
421
Johannes Bergfb662162011-04-05 09:41:55 -0700422 return 0;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700423}
424
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200425static void iwl_print_mismatch_inst(struct iwl_trans *trans,
Johannes Berg35b1d922011-04-05 09:41:56 -0700426 struct fw_desc *fw_desc)
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700427{
Johannes Berg35b1d922011-04-05 09:41:56 -0700428 __le32 *image = (__le32 *)fw_desc->v_addr;
429 u32 len = fw_desc->len;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700430 u32 val;
Johannes Bergfb662162011-04-05 09:41:55 -0700431 u32 offs;
432 int errors = 0;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700433
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200434 IWL_DEBUG_FW(trans, "ucode inst image size is %u\n", len);
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700435
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200436 iwl_write_direct32(trans, HBUS_TARG_MEM_RADDR,
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700437 IWLAGN_RTC_INST_LOWER_BOUND);
438
Johannes Bergfb662162011-04-05 09:41:55 -0700439 for (offs = 0;
440 offs < len && errors < 20;
441 offs += sizeof(u32), image++) {
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700442 /* read data comes through single port, auto-incr addr */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200443 val = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700444 if (val != le32_to_cpu(*image)) {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200445 IWL_ERR(trans, "uCode INST section at "
Johannes Bergfb662162011-04-05 09:41:55 -0700446 "offset 0x%x, is 0x%x, s/b 0x%x\n",
447 offs, val, le32_to_cpu(*image));
448 errors++;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700449 }
450 }
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700451}
452
453/**
454 * iwl_verify_ucode - determine which instruction image is in SRAM,
455 * and verify its contents
456 */
Don Fryde7f5f92011-11-10 06:55:10 -0800457static int iwl_verify_ucode(struct iwl_trans *trans,
458 enum iwl_ucode_type ucode_type)
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700459{
Don Fry65161742012-02-07 15:00:12 -0800460 struct fw_img *img = iwl_get_ucode_image(nic(trans), ucode_type);
Don Frybaa00052011-11-10 06:55:09 -0800461
462 if (!img) {
Don Fryde7f5f92011-11-10 06:55:10 -0800463 IWL_ERR(trans, "Invalid ucode requested (%d)\n", ucode_type);
Don Frybaa00052011-11-10 06:55:09 -0800464 return -EINVAL;
465 }
466
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200467 if (!iwl_verify_inst_sparse(trans, &img->code)) {
Don Fryde7f5f92011-11-10 06:55:10 -0800468 IWL_DEBUG_FW(trans, "uCode is good in inst SRAM\n");
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700469 return 0;
470 }
471
Don Fryde7f5f92011-11-10 06:55:10 -0800472 IWL_ERR(trans, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n");
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700473
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200474 iwl_print_mismatch_inst(trans, &img->code);
Johannes Bergfb662162011-04-05 09:41:55 -0700475 return -EIO;
Wey-Yi Guydb41dd272010-05-10 14:15:25 -0700476}
Johannes Bergca7966c2011-04-22 10:15:23 -0700477
Don Fry69a679b2011-12-07 08:50:46 -0800478struct iwl_alive_data {
Johannes Bergca7966c2011-04-22 10:15:23 -0700479 bool valid;
480 u8 subtype;
481};
482
Don Fryae6130f2011-11-30 16:12:59 -0800483static void iwl_alive_fn(struct iwl_trans *trans,
Johannes Bergca7966c2011-04-22 10:15:23 -0700484 struct iwl_rx_packet *pkt,
485 void *data)
486{
Don Fry69a679b2011-12-07 08:50:46 -0800487 struct iwl_alive_data *alive_data = data;
Johannes Bergca7966c2011-04-22 10:15:23 -0700488 struct iwl_alive_resp *palive;
489
490 palive = &pkt->u.alive_frame;
491
Don Fryae6130f2011-11-30 16:12:59 -0800492 IWL_DEBUG_FW(trans, "Alive ucode status 0x%08X revision "
Johannes Bergca7966c2011-04-22 10:15:23 -0700493 "0x%01X 0x%01X\n",
494 palive->is_valid, palive->ver_type,
495 palive->ver_subtype);
496
Don Fryae6130f2011-11-30 16:12:59 -0800497 trans->shrd->device_pointers.error_event_table =
Johannes Bergca7966c2011-04-22 10:15:23 -0700498 le32_to_cpu(palive->error_event_table_ptr);
Don Fryae6130f2011-11-30 16:12:59 -0800499 trans->shrd->device_pointers.log_event_table =
Johannes Bergca7966c2011-04-22 10:15:23 -0700500 le32_to_cpu(palive->log_event_table_ptr);
501
502 alive_data->subtype = palive->ver_subtype;
503 alive_data->valid = palive->is_valid == UCODE_VALID_OK;
504}
505
Don Frydd5fe102011-11-28 16:13:19 -0800506/* notification wait support */
507void iwl_init_notification_wait(struct iwl_shared *shrd,
508 struct iwl_notification_wait *wait_entry,
509 u8 cmd,
Don Fryae6130f2011-11-30 16:12:59 -0800510 void (*fn)(struct iwl_trans *trans,
Don Frydd5fe102011-11-28 16:13:19 -0800511 struct iwl_rx_packet *pkt,
512 void *data),
513 void *fn_data)
514{
515 wait_entry->fn = fn;
516 wait_entry->fn_data = fn_data;
517 wait_entry->cmd = cmd;
518 wait_entry->triggered = false;
519 wait_entry->aborted = false;
520
521 spin_lock_bh(&shrd->notif_wait_lock);
522 list_add(&wait_entry->list, &shrd->notif_waits);
523 spin_unlock_bh(&shrd->notif_wait_lock);
524}
525
526int iwl_wait_notification(struct iwl_shared *shrd,
527 struct iwl_notification_wait *wait_entry,
528 unsigned long timeout)
529{
530 int ret;
531
532 ret = wait_event_timeout(shrd->notif_waitq,
533 wait_entry->triggered || wait_entry->aborted,
534 timeout);
535
536 spin_lock_bh(&shrd->notif_wait_lock);
537 list_del(&wait_entry->list);
538 spin_unlock_bh(&shrd->notif_wait_lock);
539
540 if (wait_entry->aborted)
541 return -EIO;
542
543 /* return value is always >= 0 */
544 if (ret <= 0)
545 return -ETIMEDOUT;
546 return 0;
547}
548
549void iwl_remove_notification(struct iwl_shared *shrd,
550 struct iwl_notification_wait *wait_entry)
551{
552 spin_lock_bh(&shrd->notif_wait_lock);
553 list_del(&wait_entry->list);
554 spin_unlock_bh(&shrd->notif_wait_lock);
555}
556
557void iwl_abort_notification_waits(struct iwl_shared *shrd)
558{
559 unsigned long flags;
560 struct iwl_notification_wait *wait_entry;
561
562 spin_lock_irqsave(&shrd->notif_wait_lock, flags);
563 list_for_each_entry(wait_entry, &shrd->notif_waits, list)
564 wait_entry->aborted = true;
565 spin_unlock_irqrestore(&shrd->notif_wait_lock, flags);
566
567 wake_up_all(&shrd->notif_waitq);
568}
569
Johannes Bergca7966c2011-04-22 10:15:23 -0700570#define UCODE_ALIVE_TIMEOUT HZ
571#define UCODE_CALIB_TIMEOUT (2*HZ)
572
Don Fry69a679b2011-12-07 08:50:46 -0800573int iwl_load_ucode_wait_alive(struct iwl_trans *trans,
Don Fryde7f5f92011-11-10 06:55:10 -0800574 enum iwl_ucode_type ucode_type)
Johannes Bergca7966c2011-04-22 10:15:23 -0700575{
576 struct iwl_notification_wait alive_wait;
Don Fry69a679b2011-12-07 08:50:46 -0800577 struct iwl_alive_data alive_data;
Emmanuel Grumbachcf614292012-01-08 16:33:58 +0200578 struct fw_img *fw;
Johannes Bergca7966c2011-04-22 10:15:23 -0700579 int ret;
Don Fryde7f5f92011-11-10 06:55:10 -0800580 enum iwl_ucode_type old_type;
Johannes Bergca7966c2011-04-22 10:15:23 -0700581
Don Frydd5fe102011-11-28 16:13:19 -0800582 iwl_init_notification_wait(trans->shrd, &alive_wait, REPLY_ALIVE,
Don Fry66128b12011-11-28 14:35:14 -0800583 iwl_alive_fn, &alive_data);
Johannes Bergca7966c2011-04-22 10:15:23 -0700584
Don Fry3d6acef2011-11-28 17:05:01 -0800585 old_type = trans->shrd->ucode_type;
586 trans->shrd->ucode_type = ucode_type;
Don Fry65161742012-02-07 15:00:12 -0800587 fw = iwl_get_ucode_image(nic(trans), ucode_type);
Johannes Bergca7966c2011-04-22 10:15:23 -0700588
Emmanuel Grumbachcf614292012-01-08 16:33:58 +0200589 if (!fw)
590 return -EINVAL;
591
592 ret = iwl_trans_start_fw(trans, fw);
Johannes Bergca7966c2011-04-22 10:15:23 -0700593 if (ret) {
Don Fry3d6acef2011-11-28 17:05:01 -0800594 trans->shrd->ucode_type = old_type;
Don Frydd5fe102011-11-28 16:13:19 -0800595 iwl_remove_notification(trans->shrd, &alive_wait);
Johannes Bergca7966c2011-04-22 10:15:23 -0700596 return ret;
597 }
598
Johannes Bergca7966c2011-04-22 10:15:23 -0700599 /*
600 * Some things may run in the background now, but we
601 * just wait for the ALIVE notification here.
602 */
Don Frydd5fe102011-11-28 16:13:19 -0800603 ret = iwl_wait_notification(trans->shrd, &alive_wait,
604 UCODE_ALIVE_TIMEOUT);
Johannes Bergca7966c2011-04-22 10:15:23 -0700605 if (ret) {
Don Fry3d6acef2011-11-28 17:05:01 -0800606 trans->shrd->ucode_type = old_type;
Johannes Bergca7966c2011-04-22 10:15:23 -0700607 return ret;
608 }
609
610 if (!alive_data.valid) {
Don Fry69a679b2011-12-07 08:50:46 -0800611 IWL_ERR(trans, "Loaded ucode is not valid!\n");
Don Fry3d6acef2011-11-28 17:05:01 -0800612 trans->shrd->ucode_type = old_type;
Johannes Bergca7966c2011-04-22 10:15:23 -0700613 return -EIO;
614 }
615
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700616 /*
617 * This step takes a long time (60-80ms!!) and
618 * WoWLAN image should be loaded quickly, so
619 * skip it for WoWLAN.
620 */
621 if (ucode_type != IWL_UCODE_WOWLAN) {
Don Fry3d6acef2011-11-28 17:05:01 -0800622 ret = iwl_verify_ucode(trans, ucode_type);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700623 if (ret) {
Don Fry3d6acef2011-11-28 17:05:01 -0800624 trans->shrd->ucode_type = old_type;
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700625 return ret;
626 }
Johannes Bergca7966c2011-04-22 10:15:23 -0700627
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700628 /* delay a bit to give rfkill time to run */
629 msleep(5);
630 }
Johannes Bergca7966c2011-04-22 10:15:23 -0700631
Don Fry69a679b2011-12-07 08:50:46 -0800632 ret = iwl_alive_notify(trans);
Johannes Bergca7966c2011-04-22 10:15:23 -0700633 if (ret) {
Don Fry69a679b2011-12-07 08:50:46 -0800634 IWL_WARN(trans,
Johannes Bergca7966c2011-04-22 10:15:23 -0700635 "Could not complete ALIVE transition: %d\n", ret);
Don Fry3d6acef2011-11-28 17:05:01 -0800636 trans->shrd->ucode_type = old_type;
Johannes Bergca7966c2011-04-22 10:15:23 -0700637 return ret;
638 }
639
640 return 0;
641}
642
Don Fry69a679b2011-12-07 08:50:46 -0800643int iwl_run_init_ucode(struct iwl_trans *trans)
Johannes Bergca7966c2011-04-22 10:15:23 -0700644{
645 struct iwl_notification_wait calib_wait;
646 int ret;
647
Don Fry69a679b2011-12-07 08:50:46 -0800648 lockdep_assert_held(&trans->shrd->mutex);
Johannes Bergca7966c2011-04-22 10:15:23 -0700649
650 /* No init ucode required? Curious, but maybe ok */
Don Fry65161742012-02-07 15:00:12 -0800651 if (!nic(trans)->fw.ucode_init.code.len)
Johannes Bergca7966c2011-04-22 10:15:23 -0700652 return 0;
653
Don Fry69a679b2011-12-07 08:50:46 -0800654 if (trans->shrd->ucode_type != IWL_UCODE_NONE)
Johannes Bergca7966c2011-04-22 10:15:23 -0700655 return 0;
656
Don Fry69a679b2011-12-07 08:50:46 -0800657 iwl_init_notification_wait(trans->shrd, &calib_wait,
Johannes Bergca7966c2011-04-22 10:15:23 -0700658 CALIBRATION_COMPLETE_NOTIFICATION,
659 NULL, NULL);
660
661 /* Will also start the device */
Don Fry69a679b2011-12-07 08:50:46 -0800662 ret = iwl_load_ucode_wait_alive(trans, IWL_UCODE_INIT);
Johannes Bergca7966c2011-04-22 10:15:23 -0700663 if (ret)
664 goto error;
665
Don Fry69a679b2011-12-07 08:50:46 -0800666 ret = iwl_init_alive_start(trans);
Johannes Bergca7966c2011-04-22 10:15:23 -0700667 if (ret)
668 goto error;
669
670 /*
671 * Some things may run in the background now, but we
672 * just wait for the calibration complete notification.
673 */
Don Fry69a679b2011-12-07 08:50:46 -0800674 ret = iwl_wait_notification(trans->shrd, &calib_wait,
Don Frydd5fe102011-11-28 16:13:19 -0800675 UCODE_CALIB_TIMEOUT);
Johannes Bergca7966c2011-04-22 10:15:23 -0700676
677 goto out;
678
679 error:
Don Fry69a679b2011-12-07 08:50:46 -0800680 iwl_remove_notification(trans->shrd, &calib_wait);
Johannes Bergca7966c2011-04-22 10:15:23 -0700681 out:
682 /* Whatever happened, stop the device */
Don Fry69a679b2011-12-07 08:50:46 -0800683 iwl_trans_stop_device(trans);
Johannes Bergca7966c2011-04-22 10:15:23 -0700684 return ret;
685}
Don Fryedf38332012-01-25 16:18:52 -0800686
687static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
688
689#define UCODE_EXPERIMENTAL_INDEX 100
690#define UCODE_EXPERIMENTAL_TAG "exp"
691
692int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
693{
Don Fryf6fd51d2012-02-06 15:54:31 -0800694 struct iwl_nic *nic = nic(priv);
Don Fryedf38332012-01-25 16:18:52 -0800695 const char *name_pre = cfg(priv)->fw_name_pre;
696 char tag[8];
697
698 if (first) {
699#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
Don Fryf6fd51d2012-02-06 15:54:31 -0800700 nic->fw_index = UCODE_EXPERIMENTAL_INDEX;
Don Fryedf38332012-01-25 16:18:52 -0800701 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
Don Fryf6fd51d2012-02-06 15:54:31 -0800702 } else if (nic->fw_index == UCODE_EXPERIMENTAL_INDEX) {
Don Fryedf38332012-01-25 16:18:52 -0800703#endif
Don Fryf6fd51d2012-02-06 15:54:31 -0800704 nic->fw_index = cfg(priv)->ucode_api_max;
705 sprintf(tag, "%d", nic->fw_index);
Don Fryedf38332012-01-25 16:18:52 -0800706 } else {
Don Fryf6fd51d2012-02-06 15:54:31 -0800707 nic->fw_index--;
708 sprintf(tag, "%d", nic->fw_index);
Don Fryedf38332012-01-25 16:18:52 -0800709 }
710
Don Fryf6fd51d2012-02-06 15:54:31 -0800711 if (nic->fw_index < cfg(priv)->ucode_api_min) {
Don Fryedf38332012-01-25 16:18:52 -0800712 IWL_ERR(priv, "no suitable firmware found!\n");
713 return -ENOENT;
714 }
715
Don Fry737805f2012-02-06 15:57:40 -0800716 sprintf(nic->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Don Fryedf38332012-01-25 16:18:52 -0800717
718 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
Don Fryf6fd51d2012-02-06 15:54:31 -0800719 (nic->fw_index == UCODE_EXPERIMENTAL_INDEX)
Don Fryedf38332012-01-25 16:18:52 -0800720 ? "EXPERIMENTAL " : "",
Don Fry737805f2012-02-06 15:57:40 -0800721 nic->firmware_name);
Don Fryedf38332012-01-25 16:18:52 -0800722
Don Fry737805f2012-02-06 15:57:40 -0800723 return request_firmware_nowait(THIS_MODULE, 1, nic->firmware_name,
Don Fryedf38332012-01-25 16:18:52 -0800724 trans(priv)->dev,
725 GFP_KERNEL, priv, iwl_ucode_callback);
726}
727
728struct iwlagn_firmware_pieces {
729 const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data;
730 size_t inst_size, data_size, init_size, init_data_size,
731 wowlan_inst_size, wowlan_data_size;
732
733 u32 build;
734
735 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
736 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
737};
738
739static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
740 const struct firmware *ucode_raw,
741 struct iwlagn_firmware_pieces *pieces)
742{
Don Fryd3596672012-02-06 15:51:15 -0800743 struct iwl_nic *nic = nic(priv);
Don Fryedf38332012-01-25 16:18:52 -0800744 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
745 u32 api_ver, hdr_size;
746 const u8 *src;
747
Don Fryd3596672012-02-06 15:51:15 -0800748 nic->fw.ucode_ver = le32_to_cpu(ucode->ver);
749 api_ver = IWL_UCODE_API(nic->fw.ucode_ver);
Don Fryedf38332012-01-25 16:18:52 -0800750
751 switch (api_ver) {
752 default:
753 hdr_size = 28;
754 if (ucode_raw->size < hdr_size) {
755 IWL_ERR(priv, "File size too small!\n");
756 return -EINVAL;
757 }
758 pieces->build = le32_to_cpu(ucode->u.v2.build);
759 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
760 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
761 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
762 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
763 src = ucode->u.v2.data;
764 break;
765 case 0:
766 case 1:
767 case 2:
768 hdr_size = 24;
769 if (ucode_raw->size < hdr_size) {
770 IWL_ERR(priv, "File size too small!\n");
771 return -EINVAL;
772 }
773 pieces->build = 0;
774 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
775 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
776 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
777 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
778 src = ucode->u.v1.data;
779 break;
780 }
781
782 /* Verify size of file vs. image size info in file's header */
783 if (ucode_raw->size != hdr_size + pieces->inst_size +
784 pieces->data_size + pieces->init_size +
785 pieces->init_data_size) {
786
787 IWL_ERR(priv,
788 "uCode file size %d does not match expected size\n",
789 (int)ucode_raw->size);
790 return -EINVAL;
791 }
792
793 pieces->inst = src;
794 src += pieces->inst_size;
795 pieces->data = src;
796 src += pieces->data_size;
797 pieces->init = src;
798 src += pieces->init_size;
799 pieces->init_data = src;
800 src += pieces->init_data_size;
801
802 return 0;
803}
804
805static int iwlagn_load_firmware(struct iwl_priv *priv,
806 const struct firmware *ucode_raw,
807 struct iwlagn_firmware_pieces *pieces,
808 struct iwlagn_ucode_capabilities *capa)
809{
Don Fryd3596672012-02-06 15:51:15 -0800810 struct iwl_nic *nic = nic(priv);
Don Fryedf38332012-01-25 16:18:52 -0800811 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
812 struct iwl_ucode_tlv *tlv;
813 size_t len = ucode_raw->size;
814 const u8 *data;
815 int wanted_alternative = iwlagn_mod_params.wanted_ucode_alternative;
816 int tmp;
817 u64 alternatives;
818 u32 tlv_len;
819 enum iwl_ucode_tlv_type tlv_type;
820 const u8 *tlv_data;
821
822 if (len < sizeof(*ucode)) {
823 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
824 return -EINVAL;
825 }
826
827 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
828 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
829 le32_to_cpu(ucode->magic));
830 return -EINVAL;
831 }
832
833 /*
834 * Check which alternatives are present, and "downgrade"
835 * when the chosen alternative is not present, warning
836 * the user when that happens. Some files may not have
837 * any alternatives, so don't warn in that case.
838 */
839 alternatives = le64_to_cpu(ucode->alternatives);
840 tmp = wanted_alternative;
841 if (wanted_alternative > 63)
842 wanted_alternative = 63;
843 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
844 wanted_alternative--;
845 if (wanted_alternative && wanted_alternative != tmp)
846 IWL_WARN(priv,
847 "uCode alternative %d not available, choosing %d\n",
848 tmp, wanted_alternative);
849
Don Fryd3596672012-02-06 15:51:15 -0800850 nic->fw.ucode_ver = le32_to_cpu(ucode->ver);
Don Fryedf38332012-01-25 16:18:52 -0800851 pieces->build = le32_to_cpu(ucode->build);
852 data = ucode->data;
853
854 len -= sizeof(*ucode);
855
856 while (len >= sizeof(*tlv)) {
857 u16 tlv_alt;
858
859 len -= sizeof(*tlv);
860 tlv = (void *)data;
861
862 tlv_len = le32_to_cpu(tlv->length);
863 tlv_type = le16_to_cpu(tlv->type);
864 tlv_alt = le16_to_cpu(tlv->alternative);
865 tlv_data = tlv->data;
866
867 if (len < tlv_len) {
868 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
869 len, tlv_len);
870 return -EINVAL;
871 }
872 len -= ALIGN(tlv_len, 4);
873 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
874
875 /*
876 * Alternative 0 is always valid.
877 *
878 * Skip alternative TLVs that are not selected.
879 */
880 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
881 continue;
882
883 switch (tlv_type) {
884 case IWL_UCODE_TLV_INST:
885 pieces->inst = tlv_data;
886 pieces->inst_size = tlv_len;
887 break;
888 case IWL_UCODE_TLV_DATA:
889 pieces->data = tlv_data;
890 pieces->data_size = tlv_len;
891 break;
892 case IWL_UCODE_TLV_INIT:
893 pieces->init = tlv_data;
894 pieces->init_size = tlv_len;
895 break;
896 case IWL_UCODE_TLV_INIT_DATA:
897 pieces->init_data = tlv_data;
898 pieces->init_data_size = tlv_len;
899 break;
900 case IWL_UCODE_TLV_BOOT:
901 IWL_ERR(priv, "Found unexpected BOOT ucode\n");
902 break;
903 case IWL_UCODE_TLV_PROBE_MAX_LEN:
904 if (tlv_len != sizeof(u32))
905 goto invalid_tlv_len;
906 capa->max_probe_length =
907 le32_to_cpup((__le32 *)tlv_data);
908 break;
909 case IWL_UCODE_TLV_PAN:
910 if (tlv_len)
911 goto invalid_tlv_len;
912 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
913 break;
914 case IWL_UCODE_TLV_FLAGS:
915 /* must be at least one u32 */
916 if (tlv_len < sizeof(u32))
917 goto invalid_tlv_len;
918 /* and a proper number of u32s */
919 if (tlv_len % sizeof(u32))
920 goto invalid_tlv_len;
921 /*
922 * This driver only reads the first u32 as
923 * right now no more features are defined,
924 * if that changes then either the driver
925 * will not work with the new firmware, or
926 * it'll not take advantage of new features.
927 */
928 capa->flags = le32_to_cpup((__le32 *)tlv_data);
929 break;
930 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
931 if (tlv_len != sizeof(u32))
932 goto invalid_tlv_len;
933 pieces->init_evtlog_ptr =
934 le32_to_cpup((__le32 *)tlv_data);
935 break;
936 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
937 if (tlv_len != sizeof(u32))
938 goto invalid_tlv_len;
939 pieces->init_evtlog_size =
940 le32_to_cpup((__le32 *)tlv_data);
941 break;
942 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
943 if (tlv_len != sizeof(u32))
944 goto invalid_tlv_len;
945 pieces->init_errlog_ptr =
946 le32_to_cpup((__le32 *)tlv_data);
947 break;
948 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
949 if (tlv_len != sizeof(u32))
950 goto invalid_tlv_len;
951 pieces->inst_evtlog_ptr =
952 le32_to_cpup((__le32 *)tlv_data);
953 break;
954 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
955 if (tlv_len != sizeof(u32))
956 goto invalid_tlv_len;
957 pieces->inst_evtlog_size =
958 le32_to_cpup((__le32 *)tlv_data);
959 break;
960 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
961 if (tlv_len != sizeof(u32))
962 goto invalid_tlv_len;
963 pieces->inst_errlog_ptr =
964 le32_to_cpup((__le32 *)tlv_data);
965 break;
966 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
967 if (tlv_len)
968 goto invalid_tlv_len;
969 priv->enhance_sensitivity_table = true;
970 break;
971 case IWL_UCODE_TLV_WOWLAN_INST:
972 pieces->wowlan_inst = tlv_data;
973 pieces->wowlan_inst_size = tlv_len;
974 break;
975 case IWL_UCODE_TLV_WOWLAN_DATA:
976 pieces->wowlan_data = tlv_data;
977 pieces->wowlan_data_size = tlv_len;
978 break;
979 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
980 if (tlv_len != sizeof(u32))
981 goto invalid_tlv_len;
982 capa->standard_phy_calibration_size =
983 le32_to_cpup((__le32 *)tlv_data);
984 break;
985 default:
986 IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
987 break;
988 }
989 }
990
991 if (len) {
992 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
993 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
994 return -EINVAL;
995 }
996
997 return 0;
998
999 invalid_tlv_len:
1000 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1001 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
1002
1003 return -EINVAL;
1004}
1005
1006/**
1007 * iwl_ucode_callback - callback when firmware was loaded
1008 *
1009 * If loaded successfully, copies the firmware into buffers
1010 * for the card to fetch (via DMA).
1011 */
1012static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
1013{
1014 struct iwl_priv *priv = context;
Don Fryd3596672012-02-06 15:51:15 -08001015 struct iwl_nic *nic = nic(priv);
Don Fryedf38332012-01-25 16:18:52 -08001016 struct iwl_ucode_header *ucode;
1017 int err;
1018 struct iwlagn_firmware_pieces pieces;
1019 const unsigned int api_max = cfg(priv)->ucode_api_max;
1020 unsigned int api_ok = cfg(priv)->ucode_api_ok;
1021 const unsigned int api_min = cfg(priv)->ucode_api_min;
1022 u32 api_ver;
1023 char buildstr[25];
1024 u32 build;
1025 struct iwlagn_ucode_capabilities ucode_capa = {
1026 .max_probe_length = 200,
1027 .standard_phy_calibration_size =
1028 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
1029 };
1030
1031 if (!api_ok)
1032 api_ok = api_max;
1033
1034 memset(&pieces, 0, sizeof(pieces));
1035
1036 if (!ucode_raw) {
Don Fryf6fd51d2012-02-06 15:54:31 -08001037 if (nic->fw_index <= api_ok)
Don Fryedf38332012-01-25 16:18:52 -08001038 IWL_ERR(priv,
1039 "request for firmware file '%s' failed.\n",
Don Fry737805f2012-02-06 15:57:40 -08001040 nic->firmware_name);
Don Fryedf38332012-01-25 16:18:52 -08001041 goto try_again;
1042 }
1043
1044 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
Don Fry737805f2012-02-06 15:57:40 -08001045 nic->firmware_name, ucode_raw->size);
Don Fryedf38332012-01-25 16:18:52 -08001046
1047 /* Make sure that we got at least the API version number */
1048 if (ucode_raw->size < 4) {
1049 IWL_ERR(priv, "File size way too small!\n");
1050 goto try_again;
1051 }
1052
1053 /* Data from ucode file: header followed by uCode images */
1054 ucode = (struct iwl_ucode_header *)ucode_raw->data;
1055
1056 if (ucode->ver)
1057 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
1058 else
1059 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
1060 &ucode_capa);
1061
1062 if (err)
1063 goto try_again;
1064
Don Fryd3596672012-02-06 15:51:15 -08001065 api_ver = IWL_UCODE_API(nic->fw.ucode_ver);
Don Fryedf38332012-01-25 16:18:52 -08001066 build = pieces.build;
1067
1068 /*
1069 * api_ver should match the api version forming part of the
1070 * firmware filename ... but we don't check for that and only rely
1071 * on the API version read from firmware header from here on forward
1072 */
1073 /* no api version check required for experimental uCode */
Don Fryf6fd51d2012-02-06 15:54:31 -08001074 if (nic->fw_index != UCODE_EXPERIMENTAL_INDEX) {
Don Fryedf38332012-01-25 16:18:52 -08001075 if (api_ver < api_min || api_ver > api_max) {
1076 IWL_ERR(priv,
1077 "Driver unable to support your firmware API. "
1078 "Driver supports v%u, firmware is v%u.\n",
1079 api_max, api_ver);
1080 goto try_again;
1081 }
1082
1083 if (api_ver < api_ok) {
1084 if (api_ok != api_max)
1085 IWL_ERR(priv, "Firmware has old API version, "
1086 "expected v%u through v%u, got v%u.\n",
1087 api_ok, api_max, api_ver);
1088 else
1089 IWL_ERR(priv, "Firmware has old API version, "
1090 "expected v%u, got v%u.\n",
1091 api_max, api_ver);
1092 IWL_ERR(priv, "New firmware can be obtained from "
1093 "http://www.intellinuxwireless.org/.\n");
1094 }
1095 }
1096
1097 if (build)
1098 sprintf(buildstr, " build %u%s", build,
Don Fryf6fd51d2012-02-06 15:54:31 -08001099 (nic->fw_index == UCODE_EXPERIMENTAL_INDEX)
Don Fryedf38332012-01-25 16:18:52 -08001100 ? " (EXP)" : "");
1101 else
1102 buildstr[0] = '\0';
1103
1104 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Don Fryd3596672012-02-06 15:51:15 -08001105 IWL_UCODE_MAJOR(nic->fw.ucode_ver),
1106 IWL_UCODE_MINOR(nic->fw.ucode_ver),
1107 IWL_UCODE_API(nic->fw.ucode_ver),
1108 IWL_UCODE_SERIAL(nic->fw.ucode_ver),
Don Fryedf38332012-01-25 16:18:52 -08001109 buildstr);
1110
1111 snprintf(priv->hw->wiphy->fw_version,
1112 sizeof(priv->hw->wiphy->fw_version),
1113 "%u.%u.%u.%u%s",
Don Fryd3596672012-02-06 15:51:15 -08001114 IWL_UCODE_MAJOR(nic->fw.ucode_ver),
1115 IWL_UCODE_MINOR(nic->fw.ucode_ver),
1116 IWL_UCODE_API(nic->fw.ucode_ver),
1117 IWL_UCODE_SERIAL(nic->fw.ucode_ver),
Don Fryedf38332012-01-25 16:18:52 -08001118 buildstr);
1119
1120 /*
1121 * For any of the failures below (before allocating pci memory)
1122 * we will try to load a version with a smaller API -- maybe the
1123 * user just got a corrupted version of the latest API.
1124 */
1125
1126 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Don Fryd3596672012-02-06 15:51:15 -08001127 nic->fw.ucode_ver);
Don Fryedf38332012-01-25 16:18:52 -08001128 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
1129 pieces.inst_size);
1130 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
1131 pieces.data_size);
1132 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
1133 pieces.init_size);
1134 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
1135 pieces.init_data_size);
1136
1137 /* Verify that uCode images will fit in card's SRAM */
1138 if (pieces.inst_size > hw_params(priv).max_inst_size) {
1139 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
1140 pieces.inst_size);
1141 goto try_again;
1142 }
1143
1144 if (pieces.data_size > hw_params(priv).max_data_size) {
1145 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
1146 pieces.data_size);
1147 goto try_again;
1148 }
1149
1150 if (pieces.init_size > hw_params(priv).max_inst_size) {
1151 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
1152 pieces.init_size);
1153 goto try_again;
1154 }
1155
1156 if (pieces.init_data_size > hw_params(priv).max_data_size) {
1157 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
1158 pieces.init_data_size);
1159 goto try_again;
1160 }
1161
1162 /* Allocate ucode buffers for card's bus-master loading ... */
1163
1164 /* Runtime instructions and 2 copies of data:
1165 * 1) unmodified from disk
1166 * 2) backup cache for save/restore during power-downs */
Don Fry65161742012-02-07 15:00:12 -08001167 if (iwl_alloc_fw_desc(trans(priv), &nic(priv)->fw.ucode_rt.code,
Don Fryedf38332012-01-25 16:18:52 -08001168 pieces.inst, pieces.inst_size))
1169 goto err_pci_alloc;
Don Fry65161742012-02-07 15:00:12 -08001170 if (iwl_alloc_fw_desc(trans(priv), &nic(priv)->fw.ucode_rt.data,
Don Fryedf38332012-01-25 16:18:52 -08001171 pieces.data, pieces.data_size))
1172 goto err_pci_alloc;
1173
1174 /* Initialization instructions and data */
1175 if (pieces.init_size && pieces.init_data_size) {
1176 if (iwl_alloc_fw_desc(trans(priv),
Don Fry65161742012-02-07 15:00:12 -08001177 &nic(priv)->fw.ucode_init.code,
Don Fryedf38332012-01-25 16:18:52 -08001178 pieces.init, pieces.init_size))
1179 goto err_pci_alloc;
1180 if (iwl_alloc_fw_desc(trans(priv),
Don Fry65161742012-02-07 15:00:12 -08001181 &nic(priv)->fw.ucode_init.data,
Don Fryedf38332012-01-25 16:18:52 -08001182 pieces.init_data, pieces.init_data_size))
1183 goto err_pci_alloc;
1184 }
1185
1186 /* WoWLAN instructions and data */
1187 if (pieces.wowlan_inst_size && pieces.wowlan_data_size) {
1188 if (iwl_alloc_fw_desc(trans(priv),
Don Fry65161742012-02-07 15:00:12 -08001189 &nic(priv)->fw.ucode_wowlan.code,
Don Fryedf38332012-01-25 16:18:52 -08001190 pieces.wowlan_inst,
1191 pieces.wowlan_inst_size))
1192 goto err_pci_alloc;
1193 if (iwl_alloc_fw_desc(trans(priv),
Don Fry65161742012-02-07 15:00:12 -08001194 &nic(priv)->fw.ucode_wowlan.data,
Don Fryedf38332012-01-25 16:18:52 -08001195 pieces.wowlan_data,
1196 pieces.wowlan_data_size))
1197 goto err_pci_alloc;
1198 }
1199
1200 /* Now that we can no longer fail, copy information */
1201
1202 /*
1203 * The (size - 16) / 12 formula is based on the information recorded
1204 * for each event, which is of mode 1 (including timestamp) for all
1205 * new microcodes that include this information.
1206 */
1207 priv->init_evtlog_ptr = pieces.init_evtlog_ptr;
1208 if (pieces.init_evtlog_size)
1209 priv->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
1210 else
1211 priv->init_evtlog_size =
1212 cfg(priv)->base_params->max_event_log_size;
1213 priv->init_errlog_ptr = pieces.init_errlog_ptr;
1214 priv->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
1215 if (pieces.inst_evtlog_size)
1216 priv->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
1217 else
1218 priv->inst_evtlog_size =
1219 cfg(priv)->base_params->max_event_log_size;
1220 priv->inst_errlog_ptr = pieces.inst_errlog_ptr;
1221#ifndef CONFIG_IWLWIFI_P2P
1222 ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1223#endif
1224
1225 priv->new_scan_threshold_behaviour =
1226 !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1227
1228 if (!(cfg(priv)->sku & EEPROM_SKU_CAP_IPAN_ENABLE))
1229 ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1230
1231 /*
1232 * if not PAN, then don't support P2P -- might be a uCode
1233 * packaging bug or due to the eeprom check above
1234 */
1235 if (!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN))
1236 ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
1237
1238 if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
1239 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
1240 priv->shrd->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1241 } else {
1242 priv->sta_key_max_num = STA_KEY_MAX_NUM;
1243 priv->shrd->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1244 }
1245 /*
1246 * figure out the offset of chain noise reset and gain commands
1247 * base on the size of standard phy calibration commands table size
1248 */
1249 if (ucode_capa.standard_phy_calibration_size >
1250 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1251 ucode_capa.standard_phy_calibration_size =
1252 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1253
1254 priv->phy_calib_chain_noise_reset_cmd =
1255 ucode_capa.standard_phy_calibration_size;
1256 priv->phy_calib_chain_noise_gain_cmd =
1257 ucode_capa.standard_phy_calibration_size + 1;
1258
1259 /* initialize all valid contexts */
1260 iwl_init_context(priv, ucode_capa.flags);
1261
1262 /**************************************************
1263 * This is still part of probe() in a sense...
1264 *
1265 * 9. Setup and register with mac80211 and debugfs
1266 **************************************************/
1267 err = iwlagn_mac_setup_register(priv, &ucode_capa);
1268 if (err)
1269 goto out_unbind;
1270
1271 err = iwl_dbgfs_register(priv, DRV_NAME);
1272 if (err)
1273 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
1274
1275 /* We have our copies now, allow OS release its copies */
1276 release_firmware(ucode_raw);
Don Fry96502ce2012-02-06 16:00:14 -08001277 complete(&nic->request_firmware_complete);
Don Fryedf38332012-01-25 16:18:52 -08001278 return;
1279
1280 try_again:
1281 /* try next, if any */
1282 if (iwl_request_firmware(priv, false))
1283 goto out_unbind;
1284 release_firmware(ucode_raw);
1285 return;
1286
1287 err_pci_alloc:
1288 IWL_ERR(priv, "failed to allocate pci memory\n");
1289 iwl_dealloc_ucode(trans(priv));
1290 out_unbind:
Don Fry96502ce2012-02-06 16:00:14 -08001291 complete(&nic->request_firmware_complete);
Don Fryedf38332012-01-25 16:18:52 -08001292 device_release_driver(trans(priv)->dev);
1293 release_firmware(ucode_raw);
1294}
1295