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