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