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> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/init.h> |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 33 | #include <linux/sched.h> |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 34 | #include <linux/dma-mapping.h> |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 35 | #include <linux/firmware.h> |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 36 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 37 | #include "iwl-ucode.h" |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 38 | #include "iwl-wifi.h" |
Wey-Yi Guy | 792bc3c | 2010-03-16 10:23:29 -0700 | [diff] [blame] | 39 | #include "iwl-dev.h" |
| 40 | #include "iwl-core.h" |
Wey-Yi Guy | 81b8176 | 2010-03-16 10:23:30 -0700 | [diff] [blame] | 41 | #include "iwl-io.h" |
Wey-Yi Guy | 19e6cda | 2010-03-16 17:41:23 -0700 | [diff] [blame] | 42 | #include "iwl-agn-hw.h" |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 43 | #include "iwl-agn.h" |
Johannes Berg | 0de7673 | 2010-09-22 18:02:11 +0200 | [diff] [blame] | 44 | #include "iwl-agn-calib.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 45 | #include "iwl-trans.h" |
Emmanuel Grumbach | dda61a4 | 2011-08-25 23:11:11 -0700 | [diff] [blame] | 46 | #include "iwl-fh.h" |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame^] | 47 | #include "iwl-op-mode.h" |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 48 | |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 49 | static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = { |
| 50 | {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP, |
| 51 | 0, COEX_UNASSOC_IDLE_FLAGS}, |
| 52 | {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP, |
| 53 | 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS}, |
| 54 | {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP, |
| 55 | 0, COEX_UNASSOC_AUTO_SCAN_FLAGS}, |
| 56 | {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP, |
| 57 | 0, COEX_CALIBRATION_FLAGS}, |
| 58 | {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP, |
| 59 | 0, COEX_PERIODIC_CALIBRATION_FLAGS}, |
| 60 | {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP, |
| 61 | 0, COEX_CONNECTION_ESTAB_FLAGS}, |
| 62 | {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP, |
| 63 | 0, COEX_ASSOCIATED_IDLE_FLAGS}, |
| 64 | {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP, |
| 65 | 0, COEX_ASSOC_MANUAL_SCAN_FLAGS}, |
| 66 | {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP, |
| 67 | 0, COEX_ASSOC_AUTO_SCAN_FLAGS}, |
| 68 | {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP, |
| 69 | 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS}, |
| 70 | {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS}, |
| 71 | {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS}, |
| 72 | {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP, |
| 73 | 0, COEX_STAND_ALONE_DEBUG_FLAGS}, |
| 74 | {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP, |
| 75 | 0, COEX_IPAN_ASSOC_LEVEL_FLAGS}, |
| 76 | {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS}, |
| 77 | {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS} |
| 78 | }; |
| 79 | |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 80 | /****************************************************************************** |
| 81 | * |
| 82 | * uCode download functions |
| 83 | * |
| 84 | ******************************************************************************/ |
| 85 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 86 | static void iwl_free_fw_desc(struct iwl_nic *nic, struct fw_desc *desc) |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 87 | { |
| 88 | if (desc->v_addr) |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 89 | dma_free_coherent(trans(nic)->dev, desc->len, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 90 | desc->v_addr, desc->p_addr); |
| 91 | desc->v_addr = NULL; |
| 92 | desc->len = 0; |
| 93 | } |
| 94 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 95 | static void iwl_free_fw_img(struct iwl_nic *nic, struct fw_img *img) |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 96 | { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 97 | iwl_free_fw_desc(nic, &img->code); |
| 98 | iwl_free_fw_desc(nic, &img->data); |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 101 | void iwl_dealloc_ucode(struct iwl_nic *nic) |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 102 | { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 103 | iwl_free_fw_img(nic, &nic->fw.ucode_rt); |
| 104 | iwl_free_fw_img(nic, &nic->fw.ucode_init); |
| 105 | iwl_free_fw_img(nic, &nic->fw.ucode_wowlan); |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 108 | static int iwl_alloc_fw_desc(struct iwl_nic *nic, struct fw_desc *desc, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 109 | const void *data, size_t len) |
| 110 | { |
| 111 | if (!len) { |
| 112 | desc->v_addr = NULL; |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 116 | desc->v_addr = dma_alloc_coherent(trans(nic)->dev, len, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 117 | &desc->p_addr, GFP_KERNEL); |
| 118 | if (!desc->v_addr) |
| 119 | return -ENOMEM; |
| 120 | |
| 121 | desc->len = len; |
| 122 | memcpy(desc->v_addr, data, len); |
| 123 | return 0; |
| 124 | } |
| 125 | |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 126 | 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] | 127 | enum iwl_ucode_type ucode_type) |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 128 | { |
| 129 | switch (ucode_type) { |
| 130 | case IWL_UCODE_INIT: |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 131 | return &nic->fw.ucode_init; |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 132 | case IWL_UCODE_WOWLAN: |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 133 | return &nic->fw.ucode_wowlan; |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 134 | case IWL_UCODE_REGULAR: |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 135 | return &nic->fw.ucode_rt; |
Don Fry | 8929c24 | 2011-11-10 06:55:08 -0800 | [diff] [blame] | 136 | case IWL_UCODE_NONE: |
| 137 | break; |
| 138 | } |
| 139 | return NULL; |
| 140 | } |
| 141 | |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 142 | /* |
| 143 | * Calibration |
| 144 | */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 145 | static int iwl_set_Xtal_calib(struct iwl_trans *trans) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 146 | { |
| 147 | struct iwl_calib_xtal_freq_cmd cmd; |
| 148 | __le16 *xtal_calib = |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 149 | (__le16 *)iwl_eeprom_query_addr(trans->shrd, EEPROM_XTAL); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 150 | |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 151 | 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] | 152 | cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]); |
| 153 | cmd.cap_pin2 = le16_to_cpu(xtal_calib[1]); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 154 | return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd)); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 157 | static int iwl_set_temperature_offset_calib(struct iwl_trans *trans) |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 158 | { |
| 159 | struct iwl_calib_temperature_offset_cmd cmd; |
| 160 | __le16 *offset_calib = |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 161 | (__le16 *)iwl_eeprom_query_addr(trans->shrd, |
Don Fry | ab36eab | 2011-11-30 15:37:32 -0800 | [diff] [blame] | 162 | EEPROM_RAW_TEMPERATURE); |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 163 | |
| 164 | memset(&cmd, 0, sizeof(cmd)); |
| 165 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); |
Johannes Berg | 456fc37 | 2011-09-12 21:08:25 +0200 | [diff] [blame] | 166 | memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib)); |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 167 | if (!(cmd.radio_sensor_offset)) |
| 168 | cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET; |
Wey-Yi Guy | 1f8bf03 | 2011-06-06 14:26:43 -0700 | [diff] [blame] | 169 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 170 | IWL_DEBUG_CALIB(trans, "Radio sensor offset: %d\n", |
Wey-Yi Guy | 2e27799 | 2011-07-08 14:29:48 -0700 | [diff] [blame] | 171 | le16_to_cpu(cmd.radio_sensor_offset)); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 172 | return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd)); |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 175 | 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] | 176 | { |
| 177 | struct iwl_calib_temperature_offset_v2_cmd cmd; |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 178 | __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(trans->shrd, |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 179 | EEPROM_KELVIN_TEMPERATURE); |
| 180 | __le16 *offset_calib_low = |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 181 | (__le16 *)iwl_eeprom_query_addr(trans->shrd, |
Don Fry | ab36eab | 2011-11-30 15:37:32 -0800 | [diff] [blame] | 182 | EEPROM_RAW_TEMPERATURE); |
Wey-Yi Guy | 7d8f2d5 | 2011-09-15 11:46:51 -0700 | [diff] [blame] | 183 | struct iwl_eeprom_calib_hdr *hdr; |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 184 | |
| 185 | memset(&cmd, 0, sizeof(cmd)); |
| 186 | iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 187 | 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] | 188 | EEPROM_CALIB_ALL); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 189 | memcpy(&cmd.radio_sensor_offset_high, offset_calib_high, |
Wey-Yi Guy | 0008500 | 2011-09-15 11:46:53 -0700 | [diff] [blame] | 190 | sizeof(*offset_calib_high)); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 191 | memcpy(&cmd.radio_sensor_offset_low, offset_calib_low, |
Wey-Yi Guy | 0008500 | 2011-09-15 11:46:53 -0700 | [diff] [blame] | 192 | sizeof(*offset_calib_low)); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 193 | if (!(cmd.radio_sensor_offset_low)) { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 194 | IWL_DEBUG_CALIB(trans, "no info in EEPROM, use default\n"); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 195 | cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET; |
| 196 | cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET; |
| 197 | } |
Wey-Yi Guy | 7d8f2d5 | 2011-09-15 11:46:51 -0700 | [diff] [blame] | 198 | memcpy(&cmd.burntVoltageRef, &hdr->voltage, |
| 199 | sizeof(hdr->voltage)); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 200 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 201 | IWL_DEBUG_CALIB(trans, "Radio sensor offset high: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 202 | le16_to_cpu(cmd.radio_sensor_offset_high)); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 203 | IWL_DEBUG_CALIB(trans, "Radio sensor offset low: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 204 | le16_to_cpu(cmd.radio_sensor_offset_low)); |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 205 | IWL_DEBUG_CALIB(trans, "Voltage Ref: %d\n", |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 206 | le16_to_cpu(cmd.burntVoltageRef)); |
| 207 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 208 | return iwl_calib_set(trans, (void *)&cmd, sizeof(cmd)); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 211 | static int iwl_send_calib_cfg(struct iwl_trans *trans) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 212 | { |
| 213 | struct iwl_calib_cfg_cmd calib_cfg_cmd; |
| 214 | struct iwl_host_cmd cmd = { |
| 215 | .id = CALIBRATION_CFG_CMD, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 216 | .len = { sizeof(struct iwl_calib_cfg_cmd), }, |
| 217 | .data = { &calib_cfg_cmd, }, |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd)); |
| 221 | calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL; |
| 222 | calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL; |
| 223 | calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL; |
Wey-Yi Guy | df2a4dc | 2011-07-08 14:29:45 -0700 | [diff] [blame] | 224 | calib_cfg_cmd.ucd_calib_cfg.flags = |
| 225 | IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 226 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 227 | return iwl_trans_send_cmd(trans, &cmd); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 230 | int iwlagn_rx_calib_result(struct iwl_priv *priv, |
| 231 | struct iwl_rx_mem_buffer *rxb, |
| 232 | struct iwl_device_cmd *cmd) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 233 | { |
| 234 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 235 | struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw; |
| 236 | int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 237 | |
| 238 | /* reduce the size of the length field itself */ |
| 239 | len -= 4; |
| 240 | |
Don Fry | 45c30db | 2011-11-30 16:58:39 -0800 | [diff] [blame] | 241 | if (iwl_calib_set(trans(priv), hdr, len)) |
Johannes Berg | f02c2fd | 2011-11-17 08:51:57 -0800 | [diff] [blame] | 242 | IWL_ERR(priv, "Failed to record calibration data %d\n", |
| 243 | hdr->op_code); |
| 244 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 245 | return 0; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 248 | int iwl_init_alive_start(struct iwl_trans *trans) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 249 | { |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 250 | int ret; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 251 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 252 | if (cfg(trans)->bt_params && |
| 253 | cfg(trans)->bt_params->advanced_bt_coexist) { |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 254 | /* |
| 255 | * Tell uCode we are ready to perform calibration |
| 256 | * need to perform this before any calibration |
| 257 | * no need to close the envlope since we are going |
| 258 | * to load the runtime uCode later. |
| 259 | */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 260 | ret = iwl_send_bt_env(trans, IWL_BT_COEX_ENV_OPEN, |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 261 | BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 262 | if (ret) |
| 263 | return ret; |
Wey-Yi Guy | f7322f8 | 2010-08-23 15:24:49 -0700 | [diff] [blame] | 264 | |
| 265 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 266 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 267 | ret = iwl_send_calib_cfg(trans); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 268 | if (ret) |
| 269 | return ret; |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * temperature offset calibration is only needed for runtime ucode, |
| 273 | * so prepare the value now. |
| 274 | */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 275 | if (cfg(trans)->need_temp_offset_calib) { |
| 276 | if (cfg(trans)->temp_offset_v2) |
| 277 | return iwl_set_temperature_offset_calib_v2(trans); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 278 | else |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 279 | return iwl_set_temperature_offset_calib(trans); |
Wey-Yi Guy | c6f3034 | 2011-09-15 11:46:50 -0700 | [diff] [blame] | 280 | } |
Shanyu Zhao | bf53f93 | 2010-09-21 16:54:01 -0700 | [diff] [blame] | 281 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 282 | return 0; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 285 | static int iwl_send_wimax_coex(struct iwl_trans *trans) |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 286 | { |
| 287 | struct iwl_wimax_coex_cmd coex_cmd; |
| 288 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 289 | if (cfg(trans)->base_params->support_wimax_coexist) { |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 290 | /* UnMask wake up src at associated sleep */ |
| 291 | coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK; |
| 292 | |
| 293 | /* UnMask wake up src at unassociated sleep */ |
| 294 | coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK; |
| 295 | memcpy(coex_cmd.sta_prio, cu_priorities, |
| 296 | sizeof(struct iwl_wimax_coex_event_entry) * |
| 297 | COEX_NUM_OF_EVENTS); |
| 298 | |
| 299 | /* enabling the coexistence feature */ |
| 300 | coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK; |
| 301 | |
| 302 | /* enabling the priorities tables */ |
| 303 | coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK; |
| 304 | } else { |
| 305 | /* coexistence is disabled */ |
| 306 | memset(&coex_cmd, 0, sizeof(coex_cmd)); |
| 307 | } |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 308 | return iwl_trans_send_cmd_pdu(trans, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 309 | COEX_PRIORITY_TABLE_CMD, CMD_SYNC, |
Wey-Yi Guy | f401241 | 2010-04-27 14:10:00 -0700 | [diff] [blame] | 310 | sizeof(coex_cmd), &coex_cmd); |
| 311 | } |
| 312 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 313 | 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] | 314 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 315 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 316 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 317 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 318 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 319 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 320 | ((BT_COEX_PRIO_TBL_PRIO_LOW << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 321 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 322 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 323 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 324 | ((BT_COEX_PRIO_TBL_PRIO_HIGH << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 325 | (1 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 326 | ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 327 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 328 | ((BT_COEX_PRIO_TBL_PRIO_COEX_OFF << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 329 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 330 | ((BT_COEX_PRIO_TBL_PRIO_COEX_ON << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | |
| 331 | (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), |
| 332 | 0, 0, 0, 0, 0, 0, 0 |
| 333 | }; |
| 334 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 335 | void iwl_send_prio_tbl(struct iwl_trans *trans) |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 336 | { |
| 337 | struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd; |
| 338 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 339 | memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl, |
| 340 | sizeof(iwl_bt_prio_tbl)); |
| 341 | if (iwl_trans_send_cmd_pdu(trans, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 342 | REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC, |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 343 | sizeof(prio_tbl_cmd), &prio_tbl_cmd)) |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 344 | IWL_ERR(trans, "failed to send BT prio tbl command\n"); |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 347 | 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] | 348 | { |
| 349 | struct iwl_bt_coex_prot_env_cmd env_cmd; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 350 | int ret; |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 351 | |
| 352 | env_cmd.action = action; |
| 353 | env_cmd.type = type; |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 354 | ret = iwl_trans_send_cmd_pdu(trans, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 355 | REPLY_BT_COEX_PROT_ENV, CMD_SYNC, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 356 | sizeof(env_cmd), &env_cmd); |
| 357 | if (ret) |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 358 | IWL_ERR(trans, "failed to send BT env command\n"); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 359 | return ret; |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 363 | static int iwl_alive_notify(struct iwl_trans *trans) |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 364 | { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 365 | struct iwl_priv *priv = priv(trans); |
Emmanuel Grumbach | 7a10e3e4 | 2011-09-06 09:31:21 -0700 | [diff] [blame] | 366 | struct iwl_rxon_context *ctx; |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 367 | int ret; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 368 | |
Emmanuel Grumbach | dfa2bdb | 2011-08-25 23:11:23 -0700 | [diff] [blame] | 369 | if (!priv->tx_cmd_pool) |
| 370 | priv->tx_cmd_pool = |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 371 | kmem_cache_create("iwl_dev_cmd", |
Emmanuel Grumbach | dfa2bdb | 2011-08-25 23:11:23 -0700 | [diff] [blame] | 372 | sizeof(struct iwl_device_cmd), |
| 373 | sizeof(void *), 0, NULL); |
| 374 | |
| 375 | if (!priv->tx_cmd_pool) |
| 376 | return -ENOMEM; |
| 377 | |
Emmanuel Grumbach | ed6a380 | 2012-01-02 16:10:08 +0200 | [diff] [blame] | 378 | iwl_trans_fw_alive(trans); |
Emmanuel Grumbach | 7a10e3e4 | 2011-09-06 09:31:21 -0700 | [diff] [blame] | 379 | for_each_context(priv, ctx) |
| 380 | ctx->last_tx_rejected = false; |
Grumbach, Emmanuel | e7cad69 | 2010-11-18 03:47:38 -0800 | [diff] [blame] | 381 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 382 | ret = iwl_send_wimax_coex(trans); |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 383 | if (ret) |
| 384 | return ret; |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 385 | |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 386 | if (!cfg(priv)->no_xtal_calib) { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 387 | ret = iwl_set_Xtal_calib(trans); |
Johannes Berg | 93b6410 | 2011-11-17 08:51:53 -0800 | [diff] [blame] | 388 | if (ret) |
| 389 | return ret; |
| 390 | } |
Wey-Yi Guy | 7415952 | 2011-04-05 09:42:01 -0700 | [diff] [blame] | 391 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 392 | return iwl_send_calib_results(trans); |
Wey-Yi Guy | 741a626 | 2010-03-16 12:37:24 -0700 | [diff] [blame] | 393 | } |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 394 | |
| 395 | |
| 396 | /** |
| 397 | * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, |
| 398 | * using sample data 100 bytes apart. If these sample points are good, |
| 399 | * it's a pretty good bet that everything between them is good, too. |
| 400 | */ |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 401 | static int iwl_verify_inst_sparse(struct iwl_nic *nic, |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 402 | struct fw_desc *fw_desc) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 403 | { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 404 | struct iwl_trans *trans = trans(nic); |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 405 | __le32 *image = (__le32 *)fw_desc->v_addr; |
| 406 | u32 len = fw_desc->len; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 407 | u32 val; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 408 | u32 i; |
| 409 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 410 | IWL_DEBUG_FW(nic, "ucode inst image size is %u\n", len); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 411 | |
| 412 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 413 | /* read data comes through single port, auto-incr addr */ |
| 414 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 415 | * if IWL_DL_IO is set */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 416 | iwl_write_direct32(trans, HBUS_TARG_MEM_RADDR, |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 417 | i + IWLAGN_RTC_INST_LOWER_BOUND); |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 418 | val = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 419 | if (val != le32_to_cpu(*image)) |
| 420 | return -EIO; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 423 | return 0; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 426 | static void iwl_print_mismatch_inst(struct iwl_nic *nic, |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 427 | struct fw_desc *fw_desc) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 428 | { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 429 | struct iwl_trans *trans = trans(nic); |
Johannes Berg | 35b1d92 | 2011-04-05 09:41:56 -0700 | [diff] [blame] | 430 | __le32 *image = (__le32 *)fw_desc->v_addr; |
| 431 | u32 len = fw_desc->len; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 432 | u32 val; |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 433 | u32 offs; |
| 434 | int errors = 0; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 435 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 436 | IWL_DEBUG_FW(nic, "ucode inst image size is %u\n", len); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 437 | |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 438 | iwl_write_direct32(trans, HBUS_TARG_MEM_RADDR, |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 439 | IWLAGN_RTC_INST_LOWER_BOUND); |
| 440 | |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 441 | for (offs = 0; |
| 442 | offs < len && errors < 20; |
| 443 | offs += sizeof(u32), image++) { |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 444 | /* read data comes through single port, auto-incr addr */ |
Emmanuel Grumbach | 1042db2 | 2012-01-03 16:56:15 +0200 | [diff] [blame] | 445 | val = iwl_read32(trans, HBUS_TARG_MEM_RDAT); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 446 | if (val != le32_to_cpu(*image)) { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 447 | IWL_ERR(nic, "uCode INST section at " |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 448 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 449 | offs, val, le32_to_cpu(*image)); |
| 450 | errors++; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
| 456 | * iwl_verify_ucode - determine which instruction image is in SRAM, |
| 457 | * and verify its contents |
| 458 | */ |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 459 | static int iwl_verify_ucode(struct iwl_nic *nic, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 460 | enum iwl_ucode_type ucode_type) |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 461 | { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 462 | struct fw_img *img = iwl_get_ucode_image(nic, ucode_type); |
Don Fry | baa0005 | 2011-11-10 06:55:09 -0800 | [diff] [blame] | 463 | |
| 464 | if (!img) { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 465 | IWL_ERR(nic, "Invalid ucode requested (%d)\n", ucode_type); |
Don Fry | baa0005 | 2011-11-10 06:55:09 -0800 | [diff] [blame] | 466 | return -EINVAL; |
| 467 | } |
| 468 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 469 | if (!iwl_verify_inst_sparse(nic, &img->code)) { |
| 470 | IWL_DEBUG_FW(nic, "uCode is good in inst SRAM\n"); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 474 | IWL_ERR(nic, "UCODE IMAGE IN INSTRUCTION SRAM NOT VALID!!\n"); |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 475 | |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 476 | iwl_print_mismatch_inst(nic, &img->code); |
Johannes Berg | fb66216 | 2011-04-05 09:41:55 -0700 | [diff] [blame] | 477 | return -EIO; |
Wey-Yi Guy | db41dd27 | 2010-05-10 14:15:25 -0700 | [diff] [blame] | 478 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 479 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 480 | struct iwl_alive_data { |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 481 | bool valid; |
| 482 | u8 subtype; |
| 483 | }; |
| 484 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 485 | static void iwl_alive_fn(struct iwl_trans *trans, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 486 | struct iwl_rx_packet *pkt, |
| 487 | void *data) |
| 488 | { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 489 | struct iwl_alive_data *alive_data = data; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 490 | struct iwl_alive_resp *palive; |
| 491 | |
| 492 | palive = &pkt->u.alive_frame; |
| 493 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 494 | IWL_DEBUG_FW(trans, "Alive ucode status 0x%08X revision " |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 495 | "0x%01X 0x%01X\n", |
| 496 | palive->is_valid, palive->ver_type, |
| 497 | palive->ver_subtype); |
| 498 | |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 499 | trans->shrd->device_pointers.error_event_table = |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 500 | le32_to_cpu(palive->error_event_table_ptr); |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 501 | trans->shrd->device_pointers.log_event_table = |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 502 | le32_to_cpu(palive->log_event_table_ptr); |
| 503 | |
| 504 | alive_data->subtype = palive->ver_subtype; |
| 505 | alive_data->valid = palive->is_valid == UCODE_VALID_OK; |
| 506 | } |
| 507 | |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 508 | /* notification wait support */ |
| 509 | void iwl_init_notification_wait(struct iwl_shared *shrd, |
| 510 | struct iwl_notification_wait *wait_entry, |
| 511 | u8 cmd, |
Don Fry | ae6130f | 2011-11-30 16:12:59 -0800 | [diff] [blame] | 512 | void (*fn)(struct iwl_trans *trans, |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 513 | struct iwl_rx_packet *pkt, |
| 514 | void *data), |
| 515 | void *fn_data) |
| 516 | { |
| 517 | wait_entry->fn = fn; |
| 518 | wait_entry->fn_data = fn_data; |
| 519 | wait_entry->cmd = cmd; |
| 520 | wait_entry->triggered = false; |
| 521 | wait_entry->aborted = false; |
| 522 | |
| 523 | spin_lock_bh(&shrd->notif_wait_lock); |
| 524 | list_add(&wait_entry->list, &shrd->notif_waits); |
| 525 | spin_unlock_bh(&shrd->notif_wait_lock); |
| 526 | } |
| 527 | |
| 528 | int iwl_wait_notification(struct iwl_shared *shrd, |
| 529 | struct iwl_notification_wait *wait_entry, |
| 530 | unsigned long timeout) |
| 531 | { |
| 532 | int ret; |
| 533 | |
| 534 | ret = wait_event_timeout(shrd->notif_waitq, |
| 535 | wait_entry->triggered || wait_entry->aborted, |
| 536 | timeout); |
| 537 | |
| 538 | spin_lock_bh(&shrd->notif_wait_lock); |
| 539 | list_del(&wait_entry->list); |
| 540 | spin_unlock_bh(&shrd->notif_wait_lock); |
| 541 | |
| 542 | if (wait_entry->aborted) |
| 543 | return -EIO; |
| 544 | |
| 545 | /* return value is always >= 0 */ |
| 546 | if (ret <= 0) |
| 547 | return -ETIMEDOUT; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | void iwl_remove_notification(struct iwl_shared *shrd, |
| 552 | struct iwl_notification_wait *wait_entry) |
| 553 | { |
| 554 | spin_lock_bh(&shrd->notif_wait_lock); |
| 555 | list_del(&wait_entry->list); |
| 556 | spin_unlock_bh(&shrd->notif_wait_lock); |
| 557 | } |
| 558 | |
| 559 | void iwl_abort_notification_waits(struct iwl_shared *shrd) |
| 560 | { |
| 561 | unsigned long flags; |
| 562 | struct iwl_notification_wait *wait_entry; |
| 563 | |
| 564 | spin_lock_irqsave(&shrd->notif_wait_lock, flags); |
| 565 | list_for_each_entry(wait_entry, &shrd->notif_waits, list) |
| 566 | wait_entry->aborted = true; |
| 567 | spin_unlock_irqrestore(&shrd->notif_wait_lock, flags); |
| 568 | |
| 569 | wake_up_all(&shrd->notif_waitq); |
| 570 | } |
| 571 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 572 | #define UCODE_ALIVE_TIMEOUT HZ |
| 573 | #define UCODE_CALIB_TIMEOUT (2*HZ) |
| 574 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 575 | int iwl_load_ucode_wait_alive(struct iwl_trans *trans, |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 576 | enum iwl_ucode_type ucode_type) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 577 | { |
| 578 | struct iwl_notification_wait alive_wait; |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 579 | struct iwl_alive_data alive_data; |
Emmanuel Grumbach | cf61429 | 2012-01-08 16:33:58 +0200 | [diff] [blame] | 580 | struct fw_img *fw; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 581 | int ret; |
Don Fry | de7f5f9 | 2011-11-10 06:55:10 -0800 | [diff] [blame] | 582 | enum iwl_ucode_type old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 583 | |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 584 | iwl_init_notification_wait(trans->shrd, &alive_wait, REPLY_ALIVE, |
Don Fry | 66128b1 | 2011-11-28 14:35:14 -0800 | [diff] [blame] | 585 | iwl_alive_fn, &alive_data); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 586 | |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 587 | old_type = trans->shrd->ucode_type; |
| 588 | trans->shrd->ucode_type = ucode_type; |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 589 | fw = iwl_get_ucode_image(nic(trans), ucode_type); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 590 | |
Emmanuel Grumbach | cf61429 | 2012-01-08 16:33:58 +0200 | [diff] [blame] | 591 | if (!fw) |
| 592 | return -EINVAL; |
| 593 | |
| 594 | ret = iwl_trans_start_fw(trans, fw); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 595 | if (ret) { |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 596 | trans->shrd->ucode_type = old_type; |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 597 | iwl_remove_notification(trans->shrd, &alive_wait); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 598 | return ret; |
| 599 | } |
| 600 | |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 601 | /* |
| 602 | * Some things may run in the background now, but we |
| 603 | * just wait for the ALIVE notification here. |
| 604 | */ |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 605 | ret = iwl_wait_notification(trans->shrd, &alive_wait, |
| 606 | UCODE_ALIVE_TIMEOUT); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 607 | if (ret) { |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 608 | trans->shrd->ucode_type = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 609 | return ret; |
| 610 | } |
| 611 | |
| 612 | if (!alive_data.valid) { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 613 | IWL_ERR(trans, "Loaded ucode is not valid!\n"); |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 614 | trans->shrd->ucode_type = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 615 | return -EIO; |
| 616 | } |
| 617 | |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 618 | /* |
| 619 | * This step takes a long time (60-80ms!!) and |
| 620 | * WoWLAN image should be loaded quickly, so |
| 621 | * skip it for WoWLAN. |
| 622 | */ |
| 623 | if (ucode_type != IWL_UCODE_WOWLAN) { |
Don Fry | 655ccce | 2012-02-06 16:37:46 -0800 | [diff] [blame] | 624 | ret = iwl_verify_ucode(nic(trans), ucode_type); |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 625 | if (ret) { |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 626 | trans->shrd->ucode_type = old_type; |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 627 | return ret; |
| 628 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 629 | |
Johannes Berg | c8ac61c | 2011-07-15 13:23:45 -0700 | [diff] [blame] | 630 | /* delay a bit to give rfkill time to run */ |
| 631 | msleep(5); |
| 632 | } |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 633 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 634 | ret = iwl_alive_notify(trans); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 635 | if (ret) { |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 636 | IWL_WARN(trans, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 637 | "Could not complete ALIVE transition: %d\n", ret); |
Don Fry | 3d6acef | 2011-11-28 17:05:01 -0800 | [diff] [blame] | 638 | trans->shrd->ucode_type = old_type; |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 645 | int iwl_run_init_ucode(struct iwl_trans *trans) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 646 | { |
| 647 | struct iwl_notification_wait calib_wait; |
| 648 | int ret; |
| 649 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 650 | lockdep_assert_held(&trans->shrd->mutex); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 651 | |
| 652 | /* No init ucode required? Curious, but maybe ok */ |
Don Fry | 6516174 | 2012-02-07 15:00:12 -0800 | [diff] [blame] | 653 | if (!nic(trans)->fw.ucode_init.code.len) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 654 | return 0; |
| 655 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 656 | if (trans->shrd->ucode_type != IWL_UCODE_NONE) |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 657 | return 0; |
| 658 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 659 | iwl_init_notification_wait(trans->shrd, &calib_wait, |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 660 | CALIBRATION_COMPLETE_NOTIFICATION, |
| 661 | NULL, NULL); |
| 662 | |
| 663 | /* Will also start the device */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 664 | ret = iwl_load_ucode_wait_alive(trans, IWL_UCODE_INIT); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 665 | if (ret) |
| 666 | goto error; |
| 667 | |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 668 | ret = iwl_init_alive_start(trans); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 669 | if (ret) |
| 670 | goto error; |
| 671 | |
| 672 | /* |
| 673 | * Some things may run in the background now, but we |
| 674 | * just wait for the calibration complete notification. |
| 675 | */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 676 | ret = iwl_wait_notification(trans->shrd, &calib_wait, |
Don Fry | dd5fe10 | 2011-11-28 16:13:19 -0800 | [diff] [blame] | 677 | UCODE_CALIB_TIMEOUT); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 678 | |
| 679 | goto out; |
| 680 | |
| 681 | error: |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 682 | iwl_remove_notification(trans->shrd, &calib_wait); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 683 | out: |
| 684 | /* Whatever happened, stop the device */ |
Don Fry | 69a679b | 2011-12-07 08:50:46 -0800 | [diff] [blame] | 685 | iwl_trans_stop_device(trans); |
Johannes Berg | ca7966c | 2011-04-22 10:15:23 -0700 | [diff] [blame] | 686 | return ret; |
| 687 | } |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 688 | |
| 689 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context); |
| 690 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 691 | #define UCODE_EXPERIMENTAL_TAG "exp" |
| 692 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 693 | int __must_check iwl_request_firmware(struct iwl_nic *nic, bool first) |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 694 | { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 695 | struct iwl_cfg *cfg = cfg(nic); |
| 696 | const char *name_pre = cfg->fw_name_pre; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 697 | char tag[8]; |
| 698 | |
| 699 | if (first) { |
| 700 | #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 701 | nic->fw_index = UCODE_EXPERIMENTAL_INDEX; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 702 | strcpy(tag, UCODE_EXPERIMENTAL_TAG); |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 703 | } else if (nic->fw_index == UCODE_EXPERIMENTAL_INDEX) { |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 704 | #endif |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 705 | nic->fw_index = cfg->ucode_api_max; |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 706 | sprintf(tag, "%d", nic->fw_index); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 707 | } else { |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 708 | nic->fw_index--; |
| 709 | sprintf(tag, "%d", nic->fw_index); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 712 | if (nic->fw_index < cfg->ucode_api_min) { |
| 713 | IWL_ERR(nic, "no suitable firmware found!\n"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 714 | return -ENOENT; |
| 715 | } |
| 716 | |
Don Fry | 737805f | 2012-02-06 15:57:40 -0800 | [diff] [blame] | 717 | sprintf(nic->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 718 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 719 | IWL_DEBUG_INFO(nic, "attempting to load firmware %s'%s'\n", |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 720 | (nic->fw_index == UCODE_EXPERIMENTAL_INDEX) |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 721 | ? "EXPERIMENTAL " : "", |
Don Fry | 737805f | 2012-02-06 15:57:40 -0800 | [diff] [blame] | 722 | nic->firmware_name); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 723 | |
Don Fry | 737805f | 2012-02-06 15:57:40 -0800 | [diff] [blame] | 724 | return request_firmware_nowait(THIS_MODULE, 1, nic->firmware_name, |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 725 | trans(nic)->dev, |
| 726 | GFP_KERNEL, nic, iwl_ucode_callback); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | struct iwlagn_firmware_pieces { |
| 730 | const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data; |
| 731 | size_t inst_size, data_size, init_size, init_data_size, |
| 732 | wowlan_inst_size, wowlan_data_size; |
| 733 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 734 | u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; |
| 735 | u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; |
| 736 | }; |
| 737 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 738 | static int iwl_parse_v1_v2_firmware(struct iwl_nic *nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 739 | const struct firmware *ucode_raw, |
| 740 | struct iwlagn_firmware_pieces *pieces) |
| 741 | { |
| 742 | struct iwl_ucode_header *ucode = (void *)ucode_raw->data; |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 743 | u32 api_ver, hdr_size, build; |
| 744 | char buildstr[25]; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 745 | const u8 *src; |
| 746 | |
Don Fry | d359667 | 2012-02-06 15:51:15 -0800 | [diff] [blame] | 747 | nic->fw.ucode_ver = le32_to_cpu(ucode->ver); |
| 748 | api_ver = IWL_UCODE_API(nic->fw.ucode_ver); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 749 | |
| 750 | switch (api_ver) { |
| 751 | default: |
| 752 | hdr_size = 28; |
| 753 | if (ucode_raw->size < hdr_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 754 | IWL_ERR(nic, "File size too small!\n"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 755 | return -EINVAL; |
| 756 | } |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 757 | build = le32_to_cpu(ucode->u.v2.build); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 758 | pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size); |
| 759 | pieces->data_size = le32_to_cpu(ucode->u.v2.data_size); |
| 760 | pieces->init_size = le32_to_cpu(ucode->u.v2.init_size); |
| 761 | pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size); |
| 762 | src = ucode->u.v2.data; |
| 763 | break; |
| 764 | case 0: |
| 765 | case 1: |
| 766 | case 2: |
| 767 | hdr_size = 24; |
| 768 | if (ucode_raw->size < hdr_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 769 | IWL_ERR(nic, "File size too small!\n"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 770 | return -EINVAL; |
| 771 | } |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 772 | build = 0; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 773 | pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size); |
| 774 | pieces->data_size = le32_to_cpu(ucode->u.v1.data_size); |
| 775 | pieces->init_size = le32_to_cpu(ucode->u.v1.init_size); |
| 776 | pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size); |
| 777 | src = ucode->u.v1.data; |
| 778 | break; |
| 779 | } |
| 780 | |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 781 | if (build) |
| 782 | sprintf(buildstr, " build %u%s", build, |
| 783 | (nic->fw_index == UCODE_EXPERIMENTAL_INDEX) |
| 784 | ? " (EXP)" : ""); |
| 785 | else |
| 786 | buildstr[0] = '\0'; |
| 787 | |
| 788 | snprintf(nic->fw.fw_version, |
| 789 | sizeof(nic->fw.fw_version), |
| 790 | "%u.%u.%u.%u%s", |
| 791 | IWL_UCODE_MAJOR(nic->fw.ucode_ver), |
| 792 | IWL_UCODE_MINOR(nic->fw.ucode_ver), |
| 793 | IWL_UCODE_API(nic->fw.ucode_ver), |
| 794 | IWL_UCODE_SERIAL(nic->fw.ucode_ver), |
| 795 | buildstr); |
| 796 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 797 | /* Verify size of file vs. image size info in file's header */ |
| 798 | if (ucode_raw->size != hdr_size + pieces->inst_size + |
| 799 | pieces->data_size + pieces->init_size + |
| 800 | pieces->init_data_size) { |
| 801 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 802 | IWL_ERR(nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 803 | "uCode file size %d does not match expected size\n", |
| 804 | (int)ucode_raw->size); |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | pieces->inst = src; |
| 809 | src += pieces->inst_size; |
| 810 | pieces->data = src; |
| 811 | src += pieces->data_size; |
| 812 | pieces->init = src; |
| 813 | src += pieces->init_size; |
| 814 | pieces->init_data = src; |
| 815 | src += pieces->init_data_size; |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 820 | static int iwl_parse_tlv_firmware(struct iwl_nic *nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 821 | const struct firmware *ucode_raw, |
| 822 | struct iwlagn_firmware_pieces *pieces, |
Don Fry | 4a98677 | 2012-02-06 17:06:07 -0800 | [diff] [blame] | 823 | struct iwl_ucode_capabilities *capa) |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 824 | { |
| 825 | struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data; |
| 826 | struct iwl_ucode_tlv *tlv; |
| 827 | size_t len = ucode_raw->size; |
| 828 | const u8 *data; |
| 829 | int wanted_alternative = iwlagn_mod_params.wanted_ucode_alternative; |
| 830 | int tmp; |
| 831 | u64 alternatives; |
| 832 | u32 tlv_len; |
| 833 | enum iwl_ucode_tlv_type tlv_type; |
| 834 | const u8 *tlv_data; |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 835 | char buildstr[25]; |
| 836 | u32 build; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 837 | |
| 838 | if (len < sizeof(*ucode)) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 839 | IWL_ERR(nic, "uCode has invalid length: %zd\n", len); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 840 | return -EINVAL; |
| 841 | } |
| 842 | |
| 843 | if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 844 | IWL_ERR(nic, "invalid uCode magic: 0X%x\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 845 | le32_to_cpu(ucode->magic)); |
| 846 | return -EINVAL; |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | * Check which alternatives are present, and "downgrade" |
| 851 | * when the chosen alternative is not present, warning |
| 852 | * the user when that happens. Some files may not have |
| 853 | * any alternatives, so don't warn in that case. |
| 854 | */ |
| 855 | alternatives = le64_to_cpu(ucode->alternatives); |
| 856 | tmp = wanted_alternative; |
| 857 | if (wanted_alternative > 63) |
| 858 | wanted_alternative = 63; |
| 859 | while (wanted_alternative && !(alternatives & BIT(wanted_alternative))) |
| 860 | wanted_alternative--; |
| 861 | if (wanted_alternative && wanted_alternative != tmp) |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 862 | IWL_WARN(nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 863 | "uCode alternative %d not available, choosing %d\n", |
| 864 | tmp, wanted_alternative); |
| 865 | |
Don Fry | d359667 | 2012-02-06 15:51:15 -0800 | [diff] [blame] | 866 | nic->fw.ucode_ver = le32_to_cpu(ucode->ver); |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 867 | build = le32_to_cpu(ucode->build); |
| 868 | |
| 869 | if (build) |
| 870 | sprintf(buildstr, " build %u%s", build, |
| 871 | (nic->fw_index == UCODE_EXPERIMENTAL_INDEX) |
| 872 | ? " (EXP)" : ""); |
| 873 | else |
| 874 | buildstr[0] = '\0'; |
| 875 | |
| 876 | snprintf(nic->fw.fw_version, |
| 877 | sizeof(nic->fw.fw_version), |
| 878 | "%u.%u.%u.%u%s", |
| 879 | IWL_UCODE_MAJOR(nic->fw.ucode_ver), |
| 880 | IWL_UCODE_MINOR(nic->fw.ucode_ver), |
| 881 | IWL_UCODE_API(nic->fw.ucode_ver), |
| 882 | IWL_UCODE_SERIAL(nic->fw.ucode_ver), |
| 883 | buildstr); |
| 884 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 885 | data = ucode->data; |
| 886 | |
| 887 | len -= sizeof(*ucode); |
| 888 | |
| 889 | while (len >= sizeof(*tlv)) { |
| 890 | u16 tlv_alt; |
| 891 | |
| 892 | len -= sizeof(*tlv); |
| 893 | tlv = (void *)data; |
| 894 | |
| 895 | tlv_len = le32_to_cpu(tlv->length); |
| 896 | tlv_type = le16_to_cpu(tlv->type); |
| 897 | tlv_alt = le16_to_cpu(tlv->alternative); |
| 898 | tlv_data = tlv->data; |
| 899 | |
| 900 | if (len < tlv_len) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 901 | IWL_ERR(nic, "invalid TLV len: %zd/%u\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 902 | len, tlv_len); |
| 903 | return -EINVAL; |
| 904 | } |
| 905 | len -= ALIGN(tlv_len, 4); |
| 906 | data += sizeof(*tlv) + ALIGN(tlv_len, 4); |
| 907 | |
| 908 | /* |
| 909 | * Alternative 0 is always valid. |
| 910 | * |
| 911 | * Skip alternative TLVs that are not selected. |
| 912 | */ |
| 913 | if (tlv_alt != 0 && tlv_alt != wanted_alternative) |
| 914 | continue; |
| 915 | |
| 916 | switch (tlv_type) { |
| 917 | case IWL_UCODE_TLV_INST: |
| 918 | pieces->inst = tlv_data; |
| 919 | pieces->inst_size = tlv_len; |
| 920 | break; |
| 921 | case IWL_UCODE_TLV_DATA: |
| 922 | pieces->data = tlv_data; |
| 923 | pieces->data_size = tlv_len; |
| 924 | break; |
| 925 | case IWL_UCODE_TLV_INIT: |
| 926 | pieces->init = tlv_data; |
| 927 | pieces->init_size = tlv_len; |
| 928 | break; |
| 929 | case IWL_UCODE_TLV_INIT_DATA: |
| 930 | pieces->init_data = tlv_data; |
| 931 | pieces->init_data_size = tlv_len; |
| 932 | break; |
| 933 | case IWL_UCODE_TLV_BOOT: |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 934 | IWL_ERR(nic, "Found unexpected BOOT ucode\n"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 935 | break; |
| 936 | case IWL_UCODE_TLV_PROBE_MAX_LEN: |
| 937 | if (tlv_len != sizeof(u32)) |
| 938 | goto invalid_tlv_len; |
| 939 | capa->max_probe_length = |
| 940 | le32_to_cpup((__le32 *)tlv_data); |
| 941 | break; |
| 942 | case IWL_UCODE_TLV_PAN: |
| 943 | if (tlv_len) |
| 944 | goto invalid_tlv_len; |
| 945 | capa->flags |= IWL_UCODE_TLV_FLAGS_PAN; |
| 946 | break; |
| 947 | case IWL_UCODE_TLV_FLAGS: |
| 948 | /* must be at least one u32 */ |
| 949 | if (tlv_len < sizeof(u32)) |
| 950 | goto invalid_tlv_len; |
| 951 | /* and a proper number of u32s */ |
| 952 | if (tlv_len % sizeof(u32)) |
| 953 | goto invalid_tlv_len; |
| 954 | /* |
| 955 | * This driver only reads the first u32 as |
| 956 | * right now no more features are defined, |
| 957 | * if that changes then either the driver |
| 958 | * will not work with the new firmware, or |
| 959 | * it'll not take advantage of new features. |
| 960 | */ |
| 961 | capa->flags = le32_to_cpup((__le32 *)tlv_data); |
| 962 | break; |
| 963 | case IWL_UCODE_TLV_INIT_EVTLOG_PTR: |
| 964 | if (tlv_len != sizeof(u32)) |
| 965 | goto invalid_tlv_len; |
| 966 | pieces->init_evtlog_ptr = |
| 967 | le32_to_cpup((__le32 *)tlv_data); |
| 968 | break; |
| 969 | case IWL_UCODE_TLV_INIT_EVTLOG_SIZE: |
| 970 | if (tlv_len != sizeof(u32)) |
| 971 | goto invalid_tlv_len; |
| 972 | pieces->init_evtlog_size = |
| 973 | le32_to_cpup((__le32 *)tlv_data); |
| 974 | break; |
| 975 | case IWL_UCODE_TLV_INIT_ERRLOG_PTR: |
| 976 | if (tlv_len != sizeof(u32)) |
| 977 | goto invalid_tlv_len; |
| 978 | pieces->init_errlog_ptr = |
| 979 | le32_to_cpup((__le32 *)tlv_data); |
| 980 | break; |
| 981 | case IWL_UCODE_TLV_RUNT_EVTLOG_PTR: |
| 982 | if (tlv_len != sizeof(u32)) |
| 983 | goto invalid_tlv_len; |
| 984 | pieces->inst_evtlog_ptr = |
| 985 | le32_to_cpup((__le32 *)tlv_data); |
| 986 | break; |
| 987 | case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE: |
| 988 | if (tlv_len != sizeof(u32)) |
| 989 | goto invalid_tlv_len; |
| 990 | pieces->inst_evtlog_size = |
| 991 | le32_to_cpup((__le32 *)tlv_data); |
| 992 | break; |
| 993 | case IWL_UCODE_TLV_RUNT_ERRLOG_PTR: |
| 994 | if (tlv_len != sizeof(u32)) |
| 995 | goto invalid_tlv_len; |
| 996 | pieces->inst_errlog_ptr = |
| 997 | le32_to_cpup((__le32 *)tlv_data); |
| 998 | break; |
| 999 | case IWL_UCODE_TLV_ENHANCE_SENS_TBL: |
| 1000 | if (tlv_len) |
| 1001 | goto invalid_tlv_len; |
Emmanuel Grumbach | 637d7925 | 2012-02-07 10:55:46 +0200 | [diff] [blame] | 1002 | nic->fw.enhance_sensitivity_table = true; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1003 | break; |
| 1004 | case IWL_UCODE_TLV_WOWLAN_INST: |
| 1005 | pieces->wowlan_inst = tlv_data; |
| 1006 | pieces->wowlan_inst_size = tlv_len; |
| 1007 | break; |
| 1008 | case IWL_UCODE_TLV_WOWLAN_DATA: |
| 1009 | pieces->wowlan_data = tlv_data; |
| 1010 | pieces->wowlan_data_size = tlv_len; |
| 1011 | break; |
| 1012 | case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE: |
| 1013 | if (tlv_len != sizeof(u32)) |
| 1014 | goto invalid_tlv_len; |
| 1015 | capa->standard_phy_calibration_size = |
| 1016 | le32_to_cpup((__le32 *)tlv_data); |
| 1017 | break; |
| 1018 | default: |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1019 | IWL_DEBUG_INFO(nic, "unknown TLV: %d\n", tlv_type); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1020 | break; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | if (len) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1025 | IWL_ERR(nic, "invalid TLV after parsing: %zd\n", len); |
| 1026 | iwl_print_hex_dump(nic, IWL_DL_FW, (u8 *)data, len); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1027 | return -EINVAL; |
| 1028 | } |
| 1029 | |
| 1030 | return 0; |
| 1031 | |
| 1032 | invalid_tlv_len: |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1033 | IWL_ERR(nic, "TLV %d has invalid size: %u\n", tlv_type, tlv_len); |
| 1034 | iwl_print_hex_dump(nic, IWL_DL_FW, tlv_data, tlv_len); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1035 | |
| 1036 | return -EINVAL; |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * iwl_ucode_callback - callback when firmware was loaded |
| 1041 | * |
| 1042 | * If loaded successfully, copies the firmware into buffers |
| 1043 | * for the card to fetch (via DMA). |
| 1044 | */ |
| 1045 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) |
| 1046 | { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1047 | struct iwl_nic *nic = context; |
| 1048 | struct iwl_cfg *cfg = cfg(nic); |
Don Fry | 4a98677 | 2012-02-06 17:06:07 -0800 | [diff] [blame] | 1049 | struct iwl_fw *fw = &nic->fw; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1050 | struct iwl_ucode_header *ucode; |
| 1051 | int err; |
| 1052 | struct iwlagn_firmware_pieces pieces; |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1053 | const unsigned int api_max = cfg->ucode_api_max; |
| 1054 | unsigned int api_ok = cfg->ucode_api_ok; |
| 1055 | const unsigned int api_min = cfg->ucode_api_min; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1056 | u32 api_ver; |
Don Fry | 4a98677 | 2012-02-06 17:06:07 -0800 | [diff] [blame] | 1057 | |
| 1058 | fw->ucode_capa.max_probe_length = 200; |
| 1059 | fw->ucode_capa.standard_phy_calibration_size = |
| 1060 | IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1061 | |
| 1062 | if (!api_ok) |
| 1063 | api_ok = api_max; |
| 1064 | |
| 1065 | memset(&pieces, 0, sizeof(pieces)); |
| 1066 | |
| 1067 | if (!ucode_raw) { |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 1068 | if (nic->fw_index <= api_ok) |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1069 | IWL_ERR(nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1070 | "request for firmware file '%s' failed.\n", |
Don Fry | 737805f | 2012-02-06 15:57:40 -0800 | [diff] [blame] | 1071 | nic->firmware_name); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1072 | goto try_again; |
| 1073 | } |
| 1074 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1075 | IWL_DEBUG_INFO(nic, "Loaded firmware file '%s' (%zd bytes).\n", |
Don Fry | 737805f | 2012-02-06 15:57:40 -0800 | [diff] [blame] | 1076 | nic->firmware_name, ucode_raw->size); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1077 | |
| 1078 | /* Make sure that we got at least the API version number */ |
| 1079 | if (ucode_raw->size < 4) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1080 | IWL_ERR(nic, "File size way too small!\n"); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1081 | goto try_again; |
| 1082 | } |
| 1083 | |
| 1084 | /* Data from ucode file: header followed by uCode images */ |
| 1085 | ucode = (struct iwl_ucode_header *)ucode_raw->data; |
| 1086 | |
| 1087 | if (ucode->ver) |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1088 | err = iwl_parse_v1_v2_firmware(nic, ucode_raw, &pieces); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1089 | else |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1090 | err = iwl_parse_tlv_firmware(nic, ucode_raw, &pieces, |
Don Fry | 4a98677 | 2012-02-06 17:06:07 -0800 | [diff] [blame] | 1091 | &fw->ucode_capa); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1092 | |
| 1093 | if (err) |
| 1094 | goto try_again; |
| 1095 | |
Don Fry | d359667 | 2012-02-06 15:51:15 -0800 | [diff] [blame] | 1096 | api_ver = IWL_UCODE_API(nic->fw.ucode_ver); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1097 | |
| 1098 | /* |
| 1099 | * api_ver should match the api version forming part of the |
| 1100 | * firmware filename ... but we don't check for that and only rely |
| 1101 | * on the API version read from firmware header from here on forward |
| 1102 | */ |
| 1103 | /* no api version check required for experimental uCode */ |
Don Fry | f6fd51d | 2012-02-06 15:54:31 -0800 | [diff] [blame] | 1104 | if (nic->fw_index != UCODE_EXPERIMENTAL_INDEX) { |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1105 | if (api_ver < api_min || api_ver > api_max) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1106 | IWL_ERR(nic, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1107 | "Driver unable to support your firmware API. " |
| 1108 | "Driver supports v%u, firmware is v%u.\n", |
| 1109 | api_max, api_ver); |
| 1110 | goto try_again; |
| 1111 | } |
| 1112 | |
| 1113 | if (api_ver < api_ok) { |
| 1114 | if (api_ok != api_max) |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1115 | IWL_ERR(nic, "Firmware has old API version, " |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1116 | "expected v%u through v%u, got v%u.\n", |
| 1117 | api_ok, api_max, api_ver); |
| 1118 | else |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1119 | IWL_ERR(nic, "Firmware has old API version, " |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1120 | "expected v%u, got v%u.\n", |
| 1121 | api_max, api_ver); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1122 | IWL_ERR(nic, "New firmware can be obtained from " |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1123 | "http://www.intellinuxwireless.org/.\n"); |
| 1124 | } |
| 1125 | } |
| 1126 | |
Emmanuel Grumbach | e9daccd | 2012-02-09 08:42:43 +0200 | [diff] [blame] | 1127 | IWL_INFO(nic, "loaded firmware version %s", nic->fw.fw_version); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1128 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1129 | /* |
| 1130 | * For any of the failures below (before allocating pci memory) |
| 1131 | * we will try to load a version with a smaller API -- maybe the |
| 1132 | * user just got a corrupted version of the latest API. |
| 1133 | */ |
| 1134 | |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1135 | IWL_DEBUG_INFO(nic, "f/w package hdr ucode version raw = 0x%x\n", |
Don Fry | d359667 | 2012-02-06 15:51:15 -0800 | [diff] [blame] | 1136 | nic->fw.ucode_ver); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1137 | IWL_DEBUG_INFO(nic, "f/w package hdr runtime inst size = %Zd\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1138 | pieces.inst_size); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1139 | IWL_DEBUG_INFO(nic, "f/w package hdr runtime data size = %Zd\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1140 | pieces.data_size); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1141 | IWL_DEBUG_INFO(nic, "f/w package hdr init inst size = %Zd\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1142 | pieces.init_size); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1143 | IWL_DEBUG_INFO(nic, "f/w package hdr init data size = %Zd\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1144 | pieces.init_data_size); |
| 1145 | |
| 1146 | /* Verify that uCode images will fit in card's SRAM */ |
Emmanuel Grumbach | dae66d0 | 2012-02-07 12:56:26 +0200 | [diff] [blame] | 1147 | if (pieces.inst_size > cfg->max_inst_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1148 | IWL_ERR(nic, "uCode instr len %Zd too large to fit in\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1149 | pieces.inst_size); |
| 1150 | goto try_again; |
| 1151 | } |
| 1152 | |
Emmanuel Grumbach | dae66d0 | 2012-02-07 12:56:26 +0200 | [diff] [blame] | 1153 | if (pieces.data_size > cfg->max_data_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1154 | IWL_ERR(nic, "uCode data len %Zd too large to fit in\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1155 | pieces.data_size); |
| 1156 | goto try_again; |
| 1157 | } |
| 1158 | |
Emmanuel Grumbach | dae66d0 | 2012-02-07 12:56:26 +0200 | [diff] [blame] | 1159 | if (pieces.init_size > cfg->max_inst_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1160 | IWL_ERR(nic, "uCode init instr len %Zd too large to fit in\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1161 | pieces.init_size); |
| 1162 | goto try_again; |
| 1163 | } |
| 1164 | |
Emmanuel Grumbach | dae66d0 | 2012-02-07 12:56:26 +0200 | [diff] [blame] | 1165 | if (pieces.init_data_size > cfg->max_data_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1166 | IWL_ERR(nic, "uCode init data len %Zd too large to fit in\n", |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1167 | pieces.init_data_size); |
| 1168 | goto try_again; |
| 1169 | } |
| 1170 | |
| 1171 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 1172 | |
| 1173 | /* Runtime instructions and 2 copies of data: |
| 1174 | * 1) unmodified from disk |
| 1175 | * 2) backup cache for save/restore during power-downs */ |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1176 | if (iwl_alloc_fw_desc(nic, &nic->fw.ucode_rt.code, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1177 | pieces.inst, pieces.inst_size)) |
| 1178 | goto err_pci_alloc; |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1179 | if (iwl_alloc_fw_desc(nic, &nic->fw.ucode_rt.data, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1180 | pieces.data, pieces.data_size)) |
| 1181 | goto err_pci_alloc; |
| 1182 | |
| 1183 | /* Initialization instructions and data */ |
| 1184 | if (pieces.init_size && pieces.init_data_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1185 | if (iwl_alloc_fw_desc(nic, |
| 1186 | &nic->fw.ucode_init.code, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1187 | pieces.init, pieces.init_size)) |
| 1188 | goto err_pci_alloc; |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1189 | if (iwl_alloc_fw_desc(nic, |
| 1190 | &nic->fw.ucode_init.data, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1191 | pieces.init_data, pieces.init_data_size)) |
| 1192 | goto err_pci_alloc; |
| 1193 | } |
| 1194 | |
| 1195 | /* WoWLAN instructions and data */ |
| 1196 | if (pieces.wowlan_inst_size && pieces.wowlan_data_size) { |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1197 | if (iwl_alloc_fw_desc(nic, |
| 1198 | &nic->fw.ucode_wowlan.code, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1199 | pieces.wowlan_inst, |
| 1200 | pieces.wowlan_inst_size)) |
| 1201 | goto err_pci_alloc; |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1202 | if (iwl_alloc_fw_desc(nic, |
| 1203 | &nic->fw.ucode_wowlan.data, |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1204 | pieces.wowlan_data, |
| 1205 | pieces.wowlan_data_size)) |
| 1206 | goto err_pci_alloc; |
| 1207 | } |
| 1208 | |
| 1209 | /* Now that we can no longer fail, copy information */ |
| 1210 | |
| 1211 | /* |
| 1212 | * The (size - 16) / 12 formula is based on the information recorded |
| 1213 | * for each event, which is of mode 1 (including timestamp) for all |
| 1214 | * new microcodes that include this information. |
| 1215 | */ |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1216 | nic->init_evtlog_ptr = pieces.init_evtlog_ptr; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1217 | if (pieces.init_evtlog_size) |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1218 | nic->init_evtlog_size = (pieces.init_evtlog_size - 16)/12; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1219 | else |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1220 | nic->init_evtlog_size = |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1221 | cfg->base_params->max_event_log_size; |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1222 | nic->init_errlog_ptr = pieces.init_errlog_ptr; |
| 1223 | nic->inst_evtlog_ptr = pieces.inst_evtlog_ptr; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1224 | if (pieces.inst_evtlog_size) |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1225 | nic->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1226 | else |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1227 | nic->inst_evtlog_size = |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1228 | cfg->base_params->max_event_log_size; |
Don Fry | 8655112 | 2012-02-07 14:03:55 -0800 | [diff] [blame] | 1229 | nic->inst_errlog_ptr = pieces.inst_errlog_ptr; |
Johannes Berg | a78be21 | 2012-02-21 18:31:06 +0200 | [diff] [blame] | 1230 | |
Emmanuel Grumbach | e211b24 | 2012-02-07 10:35:18 +0200 | [diff] [blame] | 1231 | /* |
| 1232 | * figure out the offset of chain noise reset and gain commands |
| 1233 | * base on the size of standard phy calibration commands table size |
| 1234 | */ |
| 1235 | if (fw->ucode_capa.standard_phy_calibration_size > |
| 1236 | IWL_MAX_PHY_CALIBRATE_TBL_SIZE) |
| 1237 | fw->ucode_capa.standard_phy_calibration_size = |
| 1238 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1239 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1240 | /* We have our copies now, allow OS release its copies */ |
| 1241 | release_firmware(ucode_raw); |
Don Fry | 96502ce | 2012-02-06 16:00:14 -0800 | [diff] [blame] | 1242 | complete(&nic->request_firmware_complete); |
Emmanuel Grumbach | e211b24 | 2012-02-07 10:35:18 +0200 | [diff] [blame] | 1243 | |
Emmanuel Grumbach | d0f76d6 | 2012-02-09 16:08:15 +0200 | [diff] [blame^] | 1244 | nic->op_mode = iwl_dvm_ops.start(nic->shrd->trans); |
| 1245 | |
| 1246 | if (!nic->op_mode) |
Emmanuel Grumbach | e211b24 | 2012-02-07 10:35:18 +0200 | [diff] [blame] | 1247 | goto out_unbind; |
| 1248 | |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1249 | return; |
| 1250 | |
| 1251 | try_again: |
| 1252 | /* try next, if any */ |
Emmanuel Grumbach | e211b24 | 2012-02-07 10:35:18 +0200 | [diff] [blame] | 1253 | release_firmware(ucode_raw); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1254 | if (iwl_request_firmware(nic, false)) |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1255 | goto out_unbind; |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1256 | return; |
| 1257 | |
| 1258 | err_pci_alloc: |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1259 | IWL_ERR(nic, "failed to allocate pci memory\n"); |
| 1260 | iwl_dealloc_ucode(nic); |
Emmanuel Grumbach | e211b24 | 2012-02-07 10:35:18 +0200 | [diff] [blame] | 1261 | release_firmware(ucode_raw); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1262 | out_unbind: |
Don Fry | 96502ce | 2012-02-06 16:00:14 -0800 | [diff] [blame] | 1263 | complete(&nic->request_firmware_complete); |
Don Fry | 06e03f8 | 2012-02-07 14:21:32 -0800 | [diff] [blame] | 1264 | device_release_driver(trans(nic)->dev); |
Don Fry | edf3833 | 2012-01-25 16:18:52 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |