Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
Wey-Yi Guy | 4e31826 | 2011-12-27 11:21:32 -0800 | [diff] [blame] | 5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 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> |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 31 | #include <linux/init.h> |
| 32 | |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 33 | #include "iwl-io.h" |
Wey-Yi Guy | 19e6cda | 2010-03-16 17:41:23 -0700 | [diff] [blame] | 34 | #include "iwl-agn-hw.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 35 | #include "iwl-trans.h" |
Emmanuel Grumbach | dda61a4 | 2011-08-25 23:11:11 -0700 | [diff] [blame] | 36 | #include "iwl-fh.h" |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame] | 37 | #include "iwl-op-mode.h" |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 38 | |
Johannes Berg | 1023fdc | 2012-05-15 12:16:34 +0200 | [diff] [blame] | 39 | #include "dev.h" |
| 40 | #include "agn.h" |
| 41 | #include "calib.h" |
| 42 | |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 43 | /****************************************************************************** |
| 44 | * |
| 45 | * uCode download functions |
| 46 | * |
| 47 | ******************************************************************************/ |
| 48 | |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 49 | static inline const struct fw_img * |
| 50 | iwl_get_ucode_image(struct iwl_priv *priv, enum iwl_ucode_type ucode_type) |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 51 | { |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 52 | if (ucode_type >= IWL_UCODE_TYPE_MAX) |
| 53 | return NULL; |
| 54 | |
| 55 | return &priv->fw->img[ucode_type]; |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 58 | /* |
| 59 | * Calibration |
| 60 | */ |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 61 | static int iwl_set_Xtal_calib(struct iwl_priv *priv) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 62 | { |
| 63 | struct iwl_calib_xtal_freq_cmd cmd; |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame^] | 64 | __le16 *xtal_calib = priv->nvm_data->xtal_calib; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 65 | |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 66 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 67 | cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]); |
| 68 | cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]); |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 69 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 72 | static int iwl_set_temperature_offset_calib(struct iwl_priv *priv) |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 73 | { |
| 74 | struct iwl_calib_temperature_offset_cmd cmd; |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 75 | |
| 76 | memset(&cmd, 0, sizeof(cmd)); |
| 77 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame^] | 78 | cmd.radio_sensor_offset = priv->nvm_data->raw_temperature; |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 79 | if (!(cmd.radio_sensor_offset)) |
| 80 | cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET; |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 81 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 82 | IWL_DEBUG_CALIB(priv, "Radio sensor offset: %d\n", |
Wey-Yi Guy | 2e27799 | 2011-07-08 14:29:48 -0700 | [diff] [blame] | 83 | le16_to_cpu(cmd.radio_sensor_offset)); |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 84 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 87 | static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv) |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 88 | { |
| 89 | struct iwl_calib_temperature_offset_v2_cmd cmd; |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 90 | |
| 91 | memset(&cmd, 0, sizeof(cmd)); |
| 92 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame^] | 93 | cmd.radio_sensor_offset_high = priv->nvm_data->kelvin_temperature; |
| 94 | cmd.radio_sensor_offset_low = priv->nvm_data->raw_temperature; |
Johannes Berg | 26a7ca9 | 2012-05-21 11:55:54 +0200 | [diff] [blame] | 95 | if (!cmd.radio_sensor_offset_low) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 96 | IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n"); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 97 | cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET; |
| 98 | cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET; |
| 99 | } |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame^] | 100 | cmd.burntVoltageRef = priv->nvm_data->calib_voltage; |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 101 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 102 | IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 103 | le16_to_cpu(cmd.radio_sensor_offset_high)); |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 104 | IWL_DEBUG_CALIB(priv, "Radio sensor offset low: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 105 | le16_to_cpu(cmd.radio_sensor_offset_low)); |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 106 | IWL_DEBUG_CALIB(priv, "Voltage Ref: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 107 | le16_to_cpu(cmd.burntVoltageRef)); |
| 108 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 109 | return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 112 | static int iwl_send_calib_cfg(struct iwl_priv *priv) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 113 | { |
| 114 | struct iwl_calib_cfg_cmd calib_cfg_cmd; |
| 115 | struct iwl_host_cmd cmd = { |
| 116 | .id = CALIBRATION_CFG_CMD, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 117 | .len = { sizeof(struct iwl_calib_cfg_cmd), }, |
| 118 | .data = { &calib_cfg_cmd, }, |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd)); |
| 122 | calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL; |
| 123 | calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL; |
| 124 | calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL; |
Wey-Yi Guy | df2a4dc | 2011-07-08 14:29:45 -0700 | [diff] [blame] | 125 | calib_cfg_cmd.ucd_calib_cfg.flags = |
| 126 | IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 127 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 128 | return iwl_dvm_send_cmd(priv, &cmd); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 131 | int iwl_init_alive_start(struct iwl_priv *priv) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 132 | { |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 133 | int ret; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 134 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 135 | if (priv->cfg->bt_params && |
| 136 | priv->cfg->bt_params->advanced_bt_coexist) { |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 137 | /* |
| 138 | * Tell uCode we are ready to perform calibration |
| 139 | * need to perform this before any calibration |
| 140 | * no need to close the envlope since we are going |
| 141 | * to load the runtime uCode later. |
| 142 | */ |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 143 | ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 144 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 145 | if (ret) |
| 146 | return ret; |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 147 | |
| 148 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 149 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 150 | ret = iwl_send_calib_cfg(priv); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 151 | if (ret) |
| 152 | return ret; |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * temperature offset calibration is only needed for runtime ucode, |
| 156 | * so prepare the value now. |
| 157 | */ |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 158 | if (priv->cfg->need_temp_offset_calib) { |
| 159 | if (priv->cfg->temp_offset_v2) |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 160 | return iwl_set_temperature_offset_calib_v2(priv); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 161 | else |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 162 | return iwl_set_temperature_offset_calib(priv); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 163 | } |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 164 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 165 | return 0; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Johannes Berg | aca8626 | 2012-05-14 09:08:50 +0200 | [diff] [blame] | 168 | static int iwl_send_wimax_coex(struct iwl_priv *priv) |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 169 | { |
| 170 | struct iwl_wimax_coex_cmd coex_cmd; |
| 171 | |
Johannes Berg | 85560af | 2012-03-15 13:26:48 -0700 | [diff] [blame] | 172 | /* coexistence is disabled */ |
| 173 | memset(&coex_cmd, 0, sizeof(coex_cmd)); |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 174 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 175 | return iwl_dvm_send_cmd_pdu(priv, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 176 | COEX_PRIORITY_TABLE_CMD, CMD_SYNC, |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 177 | sizeof(coex_cmd), &coex_cmd); |
| 178 | } |
| 179 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 180 | static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = { |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 181 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 182 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 183 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 184 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 185 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 186 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 187 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 188 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 189 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 190 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 191 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 192 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 193 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 194 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 195 | ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 196 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 197 | ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 198 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 199 | 0, 0, 0, 0, 0, 0, 0 |
| 200 | }; |
| 201 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 202 | void iwl_send_prio_tbl(struct iwl_priv *priv) |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 203 | { |
| 204 | struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd; |
| 205 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 206 | memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl, |
| 207 | sizeof(iwl_bt_prio_tbl)); |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 208 | if (iwl_dvm_send_cmd_pdu(priv, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 209 | REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC, |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 210 | sizeof(prio_tbl_cmd), &prio_tbl_cmd)) |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 211 | IWL_ERR(priv, "failed to send BT prio tbl command\n"); |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 214 | int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type) |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 215 | { |
| 216 | struct iwl_bt_coex_prot_env_cmd env_cmd; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 217 | int ret; |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 218 | |
| 219 | env_cmd.action = action; |
| 220 | env_cmd.type = type; |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 221 | ret = iwl_dvm_send_cmd_pdu(priv, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 222 | REPLY_BT_COEX_PROT_ENV, CMD_SYNC, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 223 | sizeof(env_cmd), &env_cmd); |
| 224 | if (ret) |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 225 | IWL_ERR(priv, "failed to send BT env command\n"); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 226 | return ret; |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Emmanuel Grumbach | b04db9a | 2012-06-21 11:53:44 +0300 | [diff] [blame] | 229 | static const u8 iwlagn_default_queue_to_tx_fifo[] = { |
| 230 | IWL_TX_FIFO_VO, |
| 231 | IWL_TX_FIFO_VI, |
| 232 | IWL_TX_FIFO_BE, |
| 233 | IWL_TX_FIFO_BK, |
| 234 | }; |
| 235 | |
| 236 | static const u8 iwlagn_ipan_queue_to_tx_fifo[] = { |
| 237 | IWL_TX_FIFO_VO, |
| 238 | IWL_TX_FIFO_VI, |
| 239 | IWL_TX_FIFO_BE, |
| 240 | IWL_TX_FIFO_BK, |
| 241 | IWL_TX_FIFO_BK_IPAN, |
| 242 | IWL_TX_FIFO_BE_IPAN, |
| 243 | IWL_TX_FIFO_VI_IPAN, |
| 244 | IWL_TX_FIFO_VO_IPAN, |
| 245 | IWL_TX_FIFO_BE_IPAN, |
| 246 | IWL_TX_FIFO_UNUSED, |
| 247 | IWL_TX_FIFO_AUX, |
| 248 | }; |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 249 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 250 | static int iwl_alive_notify(struct iwl_priv *priv) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 251 | { |
Emmanuel Grumbach | b04db9a | 2012-06-21 11:53:44 +0300 | [diff] [blame] | 252 | const u8 *queue_to_txf; |
| 253 | u8 n_queues; |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 254 | int ret; |
Emmanuel Grumbach | b04db9a | 2012-06-21 11:53:44 +0300 | [diff] [blame] | 255 | int i; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 256 | |
Emmanuel Grumbach | adca123 | 2012-10-25 23:08:27 +0200 | [diff] [blame] | 257 | iwl_trans_fw_alive(priv->trans, 0); |
Johannes Berg | e755f88 | 2012-03-07 09:52:16 -0800 | [diff] [blame] | 258 | |
Emmanuel Grumbach | b04db9a | 2012-06-21 11:53:44 +0300 | [diff] [blame] | 259 | if (priv->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN && |
Eytan Lifshitz | b7998c8 | 2012-12-01 20:59:49 +0200 | [diff] [blame^] | 260 | priv->nvm_data->sku_cap_ipan_enable) { |
Emmanuel Grumbach | b04db9a | 2012-06-21 11:53:44 +0300 | [diff] [blame] | 261 | n_queues = ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo); |
| 262 | queue_to_txf = iwlagn_ipan_queue_to_tx_fifo; |
| 263 | } else { |
| 264 | n_queues = ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); |
| 265 | queue_to_txf = iwlagn_default_queue_to_tx_fifo; |
| 266 | } |
| 267 | |
| 268 | for (i = 0; i < n_queues; i++) |
| 269 | if (queue_to_txf[i] != IWL_TX_FIFO_UNUSED) |
| 270 | iwl_trans_ac_txq_enable(priv->trans, i, |
| 271 | queue_to_txf[i]); |
| 272 | |
Johannes Berg | e755f88 | 2012-03-07 09:52:16 -0800 | [diff] [blame] | 273 | priv->passive_no_rx = false; |
| 274 | priv->transport_queue_stop = 0; |
Grumbach, Emmanuel | e7cad69 | 2010-11-18 03:47:38 -0800 | [diff] [blame] | 275 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 276 | ret = iwl_send_wimax_coex(priv); |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 277 | if (ret) |
| 278 | return ret; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 279 | |
Emmanuel Grumbach | 2152268 | 2012-03-22 17:51:44 +0200 | [diff] [blame] | 280 | if (!priv->cfg->no_xtal_calib) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 281 | ret = iwl_set_Xtal_calib(priv); |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 282 | if (ret) |
| 283 | return ret; |
| 284 | } |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 285 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 286 | return iwl_send_calib_results(priv); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 287 | } |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 288 | |
| 289 | |
| 290 | /** |
| 291 | * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, |
| 292 | * using sample data 100 bytes apart. If these sample points are good, |
| 293 | * it's a pretty good bet that everything between them is good, too. |
| 294 | */ |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 295 | static int iwl_verify_sec_sparse(struct iwl_priv *priv, |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 296 | const struct fw_desc *fw_desc) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 297 | { |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 298 | __le32 *image = (__le32 *)fw_desc->data; |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 299 | u32 len = fw_desc->len; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 300 | u32 val; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 301 | u32 i; |
| 302 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 303 | IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 304 | |
| 305 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 306 | /* read data comes through single port, auto-incr addr */ |
| 307 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 308 | * if IWL_DL_IO is set */ |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 309 | iwl_write_direct32(priv->trans, HBUS_TARG_MEM_RADDR, |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 310 | i + fw_desc->offset); |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 311 | val = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 312 | if (val != le32_to_cpu(*image)) |
| 313 | return -EIO; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 316 | return 0; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 317 | } |
| 318 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 319 | static void iwl_print_mismatch_sec(struct iwl_priv *priv, |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 320 | const struct fw_desc *fw_desc) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 321 | { |
Johannes Berg | 83f84d7 | 2012-09-10 11:50:18 +0200 | [diff] [blame] | 322 | __le32 *image = (__le32 *)fw_desc->data; |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 323 | u32 len = fw_desc->len; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 324 | u32 val; |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 325 | u32 offs; |
| 326 | int errors = 0; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 327 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 328 | IWL_DEBUG_FW(priv, "ucode inst image size is %u\n", len); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 329 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 330 | iwl_write_direct32(priv->trans, HBUS_TARG_MEM_RADDR, |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 331 | fw_desc->offset); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 332 | |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 333 | for (offs = 0; |
| 334 | offs < len && errors < 20; |
| 335 | offs += sizeof(u32), image++) { |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 336 | /* read data comes through single port, auto-incr addr */ |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 337 | val = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 338 | if (val != le32_to_cpu(*image)) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 339 | IWL_ERR(priv, "uCode INST section at " |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 340 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 341 | offs, val, le32_to_cpu(*image)); |
| 342 | errors++; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /** |
| 348 | * iwl_verify_ucode - determine which instruction image is in SRAM, |
| 349 | * and verify its contents |
| 350 | */ |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 351 | static int iwl_verify_ucode(struct iwl_priv *priv, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 352 | enum iwl_ucode_type ucode_type) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 353 | { |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 354 | const struct fw_img *img = iwl_get_ucode_image(priv, ucode_type); |
Don Fry | baa0005 | 2011-11-10 06:55:09 -0800 | [diff] [blame] | 355 | |
| 356 | if (!img) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 357 | IWL_ERR(priv, "Invalid ucode requested (%d)\n", ucode_type); |
Don Fry | baa0005 | 2011-11-10 06:55:09 -0800 | [diff] [blame] | 358 | return -EINVAL; |
| 359 | } |
| 360 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 361 | if (!iwl_verify_sec_sparse(priv, &img->sec[IWL_UCODE_SECTION_INST])) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 362 | IWL_DEBUG_FW(priv, "uCode is good in inst SRAM\n"); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 363 | return 0; |
| 364 | } |
| 365 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 366 | IWL_ERR(priv, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n"); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 367 | |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 368 | iwl_print_mismatch_sec(priv, &img->sec[IWL_UCODE_SECTION_INST]); |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 369 | return -EIO; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 370 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 371 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 372 | struct iwl_alive_data { |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 373 | bool valid; |
| 374 | u8 subtype; |
| 375 | }; |
| 376 | |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 377 | static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, |
| 378 | struct iwl_rx_packet *pkt, void *data) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 379 | { |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 380 | struct iwl_priv *priv = |
| 381 | container_of(notif_wait, struct iwl_priv, notif_wait); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 382 | struct iwl_alive_data *alive_data = data; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 383 | struct iwl_alive_resp *palive; |
| 384 | |
Johannes Berg | f8d7c1a | 2012-03-06 13:31:02 -0800 | [diff] [blame] | 385 | palive = (void *)pkt->data; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 386 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 387 | IWL_DEBUG_FW(priv, "Alive ucode status 0x%08X revision " |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 388 | "0x%01X 0x%01X\n", |
| 389 | palive->is_valid, palive->ver_type, |
| 390 | palive->ver_subtype); |
| 391 | |
Meenakshi Venkataraman | 2fdfc47 | 2012-03-15 13:26:56 -0700 | [diff] [blame] | 392 | priv->device_pointers.error_event_table = |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 393 | le32_to_cpu(palive->error_event_table_ptr); |
Meenakshi Venkataraman | 2fdfc47 | 2012-03-15 13:26:56 -0700 | [diff] [blame] | 394 | priv->device_pointers.log_event_table = |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 395 | le32_to_cpu(palive->log_event_table_ptr); |
| 396 | |
| 397 | alive_data->subtype = palive->ver_subtype; |
| 398 | alive_data->valid = palive->is_valid == UCODE_VALID_OK; |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 399 | |
| 400 | return true; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | #define UCODE_ALIVE_TIMEOUT HZ |
| 404 | #define UCODE_CALIB_TIMEOUT (2*HZ) |
| 405 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 406 | int iwl_load_ucode_wait_alive(struct iwl_priv *priv, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 407 | enum iwl_ucode_type ucode_type) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 408 | { |
| 409 | struct iwl_notification_wait alive_wait; |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 410 | struct iwl_alive_data alive_data; |
Johannes Berg | 0692fe4 | 2012-03-06 13:30:37 -0800 | [diff] [blame] | 411 | const struct fw_img *fw; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 412 | int ret; |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 413 | enum iwl_ucode_type old_type; |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 414 | static const u8 alive_cmd[] = { REPLY_ALIVE }; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 415 | |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 416 | old_type = priv->cur_ucode; |
| 417 | priv->cur_ucode = ucode_type; |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 418 | fw = iwl_get_ucode_image(priv, ucode_type); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 419 | |
David Spinadel | 8f7ffbe | 2012-03-10 13:00:10 -0800 | [diff] [blame] | 420 | priv->ucode_loaded = false; |
| 421 | |
Emmanuel Grumbach | cf61429 | 2012-01-08 16:33:58 +0200 | [diff] [blame] | 422 | if (!fw) |
| 423 | return -EINVAL; |
| 424 | |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 425 | iwl_init_notification_wait(&priv->notif_wait, &alive_wait, |
| 426 | alive_cmd, ARRAY_SIZE(alive_cmd), |
| 427 | iwl_alive_fn, &alive_data); |
Johannes Berg | f472089 | 2012-03-06 13:30:57 -0800 | [diff] [blame] | 428 | |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 429 | ret = iwl_trans_start_fw(priv->trans, fw); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 430 | if (ret) { |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 431 | priv->cur_ucode = old_type; |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 432 | iwl_remove_notification(&priv->notif_wait, &alive_wait); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 433 | return ret; |
| 434 | } |
| 435 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 436 | /* |
| 437 | * Some things may run in the background now, but we |
| 438 | * just wait for the ALIVE notification here. |
| 439 | */ |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 440 | ret = iwl_wait_notification(&priv->notif_wait, &alive_wait, |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 441 | UCODE_ALIVE_TIMEOUT); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 442 | if (ret) { |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 443 | priv->cur_ucode = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 444 | return ret; |
| 445 | } |
| 446 | |
| 447 | if (!alive_data.valid) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 448 | IWL_ERR(priv, "Loaded ucode is not valid!\n"); |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 449 | priv->cur_ucode = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 450 | return -EIO; |
| 451 | } |
| 452 | |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 453 | /* |
| 454 | * This step takes a long time (60-80ms!!) and |
| 455 | * WoWLAN image should be loaded quickly, so |
| 456 | * skip it for WoWLAN. |
| 457 | */ |
| 458 | if (ucode_type != IWL_UCODE_WOWLAN) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 459 | ret = iwl_verify_ucode(priv, ucode_type); |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 460 | if (ret) { |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 461 | priv->cur_ucode = old_type; |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 462 | return ret; |
| 463 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 464 | |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 465 | /* delay a bit to give rfkill time to run */ |
| 466 | msleep(5); |
| 467 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 468 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 469 | ret = iwl_alive_notify(priv); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 470 | if (ret) { |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 471 | IWL_WARN(priv, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 472 | "Could not complete ALIVE transition: %d\n", ret); |
Meenakshi Venkataraman | a42506e | 2012-03-15 13:26:57 -0700 | [diff] [blame] | 473 | priv->cur_ucode = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 474 | return ret; |
| 475 | } |
| 476 | |
David Spinadel | 8f7ffbe | 2012-03-10 13:00:10 -0800 | [diff] [blame] | 477 | priv->ucode_loaded = true; |
| 478 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
Johannes Berg | e1f0c50 | 2012-03-15 13:26:45 -0700 | [diff] [blame] | 482 | static bool iwlagn_wait_calib(struct iwl_notif_wait_data *notif_wait, |
| 483 | struct iwl_rx_packet *pkt, void *data) |
| 484 | { |
| 485 | struct iwl_priv *priv = data; |
| 486 | struct iwl_calib_hdr *hdr; |
| 487 | int len; |
| 488 | |
| 489 | if (pkt->hdr.cmd != CALIBRATION_RES_NOTIFICATION) { |
| 490 | WARN_ON(pkt->hdr.cmd != CALIBRATION_COMPLETE_NOTIFICATION); |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | hdr = (struct iwl_calib_hdr *)pkt->data; |
| 495 | len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 496 | |
| 497 | /* reduce the size by the length field itself */ |
| 498 | len -= sizeof(__le32); |
| 499 | |
| 500 | if (iwl_calib_set(priv, hdr, len)) |
| 501 | IWL_ERR(priv, "Failed to record calibration data %d\n", |
| 502 | hdr->op_code); |
| 503 | |
| 504 | return false; |
| 505 | } |
| 506 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 507 | int iwl_run_init_ucode(struct iwl_priv *priv) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 508 | { |
| 509 | struct iwl_notification_wait calib_wait; |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 510 | static const u8 calib_complete[] = { |
Johannes Berg | e1f0c50 | 2012-03-15 13:26:45 -0700 | [diff] [blame] | 511 | CALIBRATION_RES_NOTIFICATION, |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 512 | CALIBRATION_COMPLETE_NOTIFICATION |
| 513 | }; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 514 | int ret; |
| 515 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame] | 516 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 517 | |
| 518 | /* No init ucode required? Curious, but maybe ok */ |
David Spinadel | 6dfa8d0 | 2012-03-10 13:00:14 -0800 | [diff] [blame] | 519 | if (!priv->fw->img[IWL_UCODE_INIT].sec[0].len) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 520 | return 0; |
| 521 | |
David Spinadel | b5ea162 | 2012-03-10 13:00:11 -0800 | [diff] [blame] | 522 | if (priv->init_ucode_run) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 523 | return 0; |
| 524 | |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 525 | iwl_init_notification_wait(&priv->notif_wait, &calib_wait, |
Johannes Berg | db662d4 | 2012-03-15 13:26:44 -0700 | [diff] [blame] | 526 | calib_complete, ARRAY_SIZE(calib_complete), |
Johannes Berg | e1f0c50 | 2012-03-15 13:26:45 -0700 | [diff] [blame] | 527 | iwlagn_wait_calib, priv); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 528 | |
| 529 | /* Will also start the device */ |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 530 | ret = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 531 | if (ret) |
| 532 | goto error; |
| 533 | |
Johannes Berg | e199188 | 2012-03-06 13:30:36 -0800 | [diff] [blame] | 534 | ret = iwl_init_alive_start(priv); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 535 | if (ret) |
| 536 | goto error; |
| 537 | |
| 538 | /* |
| 539 | * Some things may run in the background now, but we |
| 540 | * just wait for the calibration complete notification. |
| 541 | */ |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 542 | ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 543 | UCODE_CALIB_TIMEOUT); |
David Spinadel | b5ea162 | 2012-03-10 13:00:11 -0800 | [diff] [blame] | 544 | if (!ret) |
| 545 | priv->init_ucode_run = true; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 546 | |
| 547 | goto out; |
| 548 | |
| 549 | error: |
Johannes Berg | 4bd14dd | 2012-03-06 13:30:58 -0800 | [diff] [blame] | 550 | iwl_remove_notification(&priv->notif_wait, &calib_wait); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 551 | out: |
| 552 | /* Whatever happened, stop the device */ |
Emmanuel Grumbach | 68e8dfd | 2012-04-18 07:28:17 -0700 | [diff] [blame] | 553 | iwl_trans_stop_device(priv->trans); |
David Spinadel | 8f7ffbe | 2012-03-10 13:00:10 -0800 | [diff] [blame] | 554 | priv->ucode_loaded = false; |
| 555 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 556 | return ret; |
| 557 | } |