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