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