Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | #include <net/mac80211.h> |
| 64 | |
| 65 | #include "iwl-trans.h" |
| 66 | #include "iwl-op-mode.h" |
| 67 | #include "iwl-fw.h" |
| 68 | #include "iwl-debug.h" |
| 69 | #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */ |
| 70 | #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */ |
| 71 | #include "iwl-eeprom-parse.h" |
| 72 | |
| 73 | #include "mvm.h" |
| 74 | #include "iwl-phy-db.h" |
| 75 | |
| 76 | #define MVM_UCODE_ALIVE_TIMEOUT HZ |
| 77 | #define MVM_UCODE_CALIB_TIMEOUT (2*HZ) |
| 78 | |
| 79 | #define UCODE_VALID_OK cpu_to_le32(0x1) |
| 80 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 81 | struct iwl_mvm_alive_data { |
| 82 | bool valid; |
| 83 | u32 scd_base_addr; |
| 84 | }; |
| 85 | |
| 86 | static inline const struct fw_img * |
| 87 | iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type) |
| 88 | { |
| 89 | if (ucode_type >= IWL_UCODE_TYPE_MAX) |
| 90 | return NULL; |
| 91 | |
| 92 | return &mvm->fw->img[ucode_type]; |
| 93 | } |
| 94 | |
| 95 | static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant) |
| 96 | { |
| 97 | struct iwl_tx_ant_cfg_cmd tx_ant_cmd = { |
| 98 | .valid = cpu_to_le32(valid_tx_ant), |
| 99 | }; |
| 100 | |
Emmanuel Grumbach | 3322354 | 2013-03-09 20:38:19 +0200 | [diff] [blame] | 101 | IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 102 | return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, CMD_SYNC, |
| 103 | sizeof(tx_ant_cmd), &tx_ant_cmd); |
| 104 | } |
| 105 | |
| 106 | static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, |
| 107 | struct iwl_rx_packet *pkt, void *data) |
| 108 | { |
| 109 | struct iwl_mvm *mvm = |
| 110 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 111 | struct iwl_mvm_alive_data *alive_data = data; |
| 112 | struct mvm_alive_resp *palive; |
| 113 | |
| 114 | palive = (void *)pkt->data; |
| 115 | |
| 116 | mvm->error_event_table = le32_to_cpu(palive->error_event_table_ptr); |
| 117 | mvm->log_event_table = le32_to_cpu(palive->log_event_table_ptr); |
| 118 | alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr); |
| 119 | |
| 120 | alive_data->valid = le16_to_cpu(palive->status) == IWL_ALIVE_STATUS_OK; |
Emmanuel Grumbach | 1b53f21 | 2013-03-13 17:02:41 +0200 | [diff] [blame] | 121 | IWL_DEBUG_FW(mvm, |
| 122 | "Alive ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n", |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 123 | le16_to_cpu(palive->status), palive->ver_type, |
Emmanuel Grumbach | 1b53f21 | 2013-03-13 17:02:41 +0200 | [diff] [blame] | 124 | palive->ver_subtype, palive->flags); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 125 | |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait, |
| 130 | struct iwl_rx_packet *pkt, void *data) |
| 131 | { |
| 132 | struct iwl_phy_db *phy_db = data; |
| 133 | |
| 134 | if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) { |
| 135 | WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC)); |
| 140 | |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, |
| 145 | enum iwl_ucode_type ucode_type) |
| 146 | { |
| 147 | struct iwl_notification_wait alive_wait; |
| 148 | struct iwl_mvm_alive_data alive_data; |
| 149 | const struct fw_img *fw; |
| 150 | int ret, i; |
| 151 | enum iwl_ucode_type old_type = mvm->cur_ucode; |
| 152 | static const u8 alive_cmd[] = { MVM_ALIVE }; |
| 153 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 154 | fw = iwl_get_ucode_image(mvm, ucode_type); |
Johannes Berg | befe9b6 | 2013-10-25 12:32:51 +0200 | [diff] [blame] | 155 | if (WARN_ON(!fw)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 156 | return -EINVAL; |
Johannes Berg | befe9b6 | 2013-10-25 12:32:51 +0200 | [diff] [blame] | 157 | mvm->cur_ucode = ucode_type; |
| 158 | mvm->ucode_loaded = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | |
| 160 | iwl_init_notification_wait(&mvm->notif_wait, &alive_wait, |
| 161 | alive_cmd, ARRAY_SIZE(alive_cmd), |
| 162 | iwl_alive_fn, &alive_data); |
| 163 | |
| 164 | ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT); |
| 165 | if (ret) { |
| 166 | mvm->cur_ucode = old_type; |
| 167 | iwl_remove_notification(&mvm->notif_wait, &alive_wait); |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Some things may run in the background now, but we |
| 173 | * just wait for the ALIVE notification here. |
| 174 | */ |
| 175 | ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait, |
| 176 | MVM_UCODE_ALIVE_TIMEOUT); |
| 177 | if (ret) { |
| 178 | mvm->cur_ucode = old_type; |
| 179 | return ret; |
| 180 | } |
| 181 | |
| 182 | if (!alive_data.valid) { |
| 183 | IWL_ERR(mvm, "Loaded ucode is not valid!\n"); |
| 184 | mvm->cur_ucode = old_type; |
| 185 | return -EIO; |
| 186 | } |
| 187 | |
| 188 | iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr); |
| 189 | |
| 190 | /* |
| 191 | * Note: all the queues are enabled as part of the interface |
| 192 | * initialization, but in firmware restart scenarios they |
| 193 | * could be stopped, so wake them up. In firmware restart, |
| 194 | * mac80211 will have the queues stopped as well until the |
| 195 | * reconfiguration completes. During normal startup, they |
| 196 | * will be empty. |
| 197 | */ |
| 198 | |
| 199 | for (i = 0; i < IWL_MAX_HW_QUEUES; i++) { |
Eytan Lifshitz | 19e737c | 2013-09-09 13:30:15 +0200 | [diff] [blame] | 200 | if (i < mvm->first_agg_queue && i != IWL_MVM_CMD_QUEUE) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 201 | mvm->queue_to_mac80211[i] = i; |
| 202 | else |
| 203 | mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE; |
| 204 | atomic_set(&mvm->queue_stop_count[i], 0); |
| 205 | } |
| 206 | |
| 207 | mvm->transport_queue_stop = 0; |
| 208 | |
| 209 | mvm->ucode_loaded = true; |
| 210 | |
| 211 | return 0; |
| 212 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 213 | |
| 214 | static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm) |
| 215 | { |
| 216 | struct iwl_phy_cfg_cmd phy_cfg_cmd; |
| 217 | enum iwl_ucode_type ucode_type = mvm->cur_ucode; |
| 218 | |
| 219 | /* Set parameters */ |
Dor Shaish | 6221d47 | 2013-02-27 15:55:48 +0200 | [diff] [blame] | 220 | phy_cfg_cmd.phy_cfg = cpu_to_le32(mvm->fw->phy_config); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 221 | phy_cfg_cmd.calib_control.event_trigger = |
| 222 | mvm->fw->default_calib[ucode_type].event_trigger; |
| 223 | phy_cfg_cmd.calib_control.flow_trigger = |
| 224 | mvm->fw->default_calib[ucode_type].flow_trigger; |
| 225 | |
| 226 | IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n", |
| 227 | phy_cfg_cmd.phy_cfg); |
| 228 | |
| 229 | return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, CMD_SYNC, |
| 230 | sizeof(phy_cfg_cmd), &phy_cfg_cmd); |
| 231 | } |
| 232 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 233 | int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) |
| 234 | { |
| 235 | struct iwl_notification_wait calib_wait; |
| 236 | static const u8 init_complete[] = { |
| 237 | INIT_COMPLETE_NOTIF, |
| 238 | CALIB_RES_NOTIF_PHY_DB |
| 239 | }; |
| 240 | int ret; |
| 241 | |
| 242 | lockdep_assert_held(&mvm->mutex); |
| 243 | |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 244 | if (WARN_ON_ONCE(mvm->init_ucode_complete)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 245 | return 0; |
| 246 | |
| 247 | iwl_init_notification_wait(&mvm->notif_wait, |
| 248 | &calib_wait, |
| 249 | init_complete, |
| 250 | ARRAY_SIZE(init_complete), |
| 251 | iwl_wait_phy_db_entry, |
| 252 | mvm->phy_db); |
| 253 | |
| 254 | /* Will also start the device */ |
| 255 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT); |
| 256 | if (ret) { |
| 257 | IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret); |
| 258 | goto error; |
| 259 | } |
| 260 | |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 261 | ret = iwl_send_bt_prio_tbl(mvm); |
| 262 | if (ret) |
| 263 | goto error; |
| 264 | |
Eytan Lifshitz | 81a67e3 | 2013-09-11 12:39:18 +0200 | [diff] [blame] | 265 | /* Read the NVM only at driver load time, no need to do this twice */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 266 | if (read_nvm) { |
| 267 | /* Read nvm */ |
| 268 | ret = iwl_nvm_init(mvm); |
| 269 | if (ret) { |
| 270 | IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); |
| 271 | goto error; |
| 272 | } |
| 273 | } |
| 274 | |
Eytan Lifshitz | 81a67e3 | 2013-09-11 12:39:18 +0200 | [diff] [blame] | 275 | /* In case we read the NVM from external file, load it to the NIC */ |
| 276 | if (iwlwifi_mod_params.nvm_file) |
| 277 | iwl_mvm_load_nvm_to_nic(mvm); |
| 278 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 279 | ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans); |
| 280 | WARN_ON(ret); |
| 281 | |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 282 | /* |
| 283 | * abort after reading the nvm in case RF Kill is on, we will complete |
| 284 | * the init seq later when RF kill will switch to off |
| 285 | */ |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 286 | if (iwl_mvm_is_radio_killed(mvm)) { |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 287 | IWL_DEBUG_RF_KILL(mvm, |
| 288 | "jump over all phy activities due to RF kill\n"); |
| 289 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 290 | ret = 1; |
| 291 | goto out; |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 292 | } |
| 293 | |
Dor Shaish | e07cbb5 | 2013-02-27 23:00:27 +0200 | [diff] [blame] | 294 | /* Send TX valid antennas before triggering calibrations */ |
Emmanuel Grumbach | 3322354 | 2013-03-09 20:38:19 +0200 | [diff] [blame] | 295 | ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw)); |
Dor Shaish | e07cbb5 | 2013-02-27 23:00:27 +0200 | [diff] [blame] | 296 | if (ret) |
| 297 | goto error; |
| 298 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 299 | /* |
| 300 | * Send phy configurations command to init uCode |
| 301 | * to start the 16.0 uCode init image internal calibrations. |
| 302 | */ |
| 303 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 304 | if (ret) { |
| 305 | IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n", |
| 306 | ret); |
| 307 | goto error; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Some things may run in the background now, but we |
| 312 | * just wait for the calibration complete notification. |
| 313 | */ |
| 314 | ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait, |
| 315 | MVM_UCODE_CALIB_TIMEOUT); |
| 316 | if (!ret) |
Eytan Lifshitz | ff11637 | 2013-09-03 12:06:11 +0300 | [diff] [blame] | 317 | mvm->init_ucode_complete = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 318 | goto out; |
| 319 | |
| 320 | error: |
| 321 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); |
| 322 | out: |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 323 | if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 324 | /* we want to debug INIT and we have no NVM - fake */ |
| 325 | mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) + |
| 326 | sizeof(struct ieee80211_channel) + |
| 327 | sizeof(struct ieee80211_rate), |
| 328 | GFP_KERNEL); |
| 329 | if (!mvm->nvm_data) |
| 330 | return -ENOMEM; |
| 331 | mvm->nvm_data->valid_rx_ant = 1; |
| 332 | mvm->nvm_data->valid_tx_ant = 1; |
| 333 | mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels; |
| 334 | mvm->nvm_data->bands[0].n_channels = 1; |
| 335 | mvm->nvm_data->bands[0].n_bitrates = 1; |
| 336 | mvm->nvm_data->bands[0].bitrates = |
| 337 | (void *)mvm->nvm_data->channels + 1; |
| 338 | mvm->nvm_data->bands[0].bitrates->hw_value = 10; |
| 339 | } |
| 340 | |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | #define UCODE_CALIB_TIMEOUT (2*HZ) |
| 345 | |
| 346 | int iwl_mvm_up(struct iwl_mvm *mvm) |
| 347 | { |
| 348 | int ret, i; |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 349 | struct ieee80211_channel *chan; |
| 350 | struct cfg80211_chan_def chandef; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 351 | |
| 352 | lockdep_assert_held(&mvm->mutex); |
| 353 | |
| 354 | ret = iwl_trans_start_hw(mvm->trans); |
| 355 | if (ret) |
| 356 | return ret; |
| 357 | |
Eytan Lifshitz | ff11637 | 2013-09-03 12:06:11 +0300 | [diff] [blame] | 358 | /* |
| 359 | * If we haven't completed the run of the init ucode during |
| 360 | * module loading, load init ucode now |
| 361 | * (for example, if we were in RFKILL) |
| 362 | */ |
| 363 | if (!mvm->init_ucode_complete) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 364 | ret = iwl_run_init_mvm_ucode(mvm, false); |
| 365 | if (ret && !iwlmvm_mod_params.init_dbg) { |
| 366 | IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret); |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 367 | /* this can't happen */ |
| 368 | if (WARN_ON(ret > 0)) |
| 369 | ret = -ERFKILL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 370 | goto error; |
| 371 | } |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 372 | if (!iwlmvm_mod_params.init_dbg) { |
| 373 | /* |
| 374 | * should stop and start HW since that INIT |
| 375 | * image just loaded |
| 376 | */ |
| 377 | iwl_trans_stop_device(mvm->trans); |
| 378 | ret = iwl_trans_start_hw(mvm->trans); |
| 379 | if (ret) |
| 380 | return ret; |
| 381 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | if (iwlmvm_mod_params.init_dbg) |
| 385 | return 0; |
| 386 | |
| 387 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); |
| 388 | if (ret) { |
| 389 | IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); |
| 390 | goto error; |
| 391 | } |
| 392 | |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 393 | ret = iwl_mvm_sf_update(mvm, NULL, false); |
| 394 | if (ret) |
| 395 | IWL_ERR(mvm, "Failed to initialize Smart Fifo\n"); |
| 396 | |
Emmanuel Grumbach | 3322354 | 2013-03-09 20:38:19 +0200 | [diff] [blame] | 397 | ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 398 | if (ret) |
| 399 | goto error; |
| 400 | |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 401 | ret = iwl_send_bt_prio_tbl(mvm); |
| 402 | if (ret) |
| 403 | goto error; |
| 404 | |
| 405 | ret = iwl_send_bt_init_conf(mvm); |
| 406 | if (ret) |
| 407 | goto error; |
| 408 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 409 | /* Send phy db control command and then phy db calibration*/ |
| 410 | ret = iwl_send_phy_db_data(mvm->phy_db); |
| 411 | if (ret) |
| 412 | goto error; |
| 413 | |
| 414 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 415 | if (ret) |
| 416 | goto error; |
| 417 | |
| 418 | /* init the fw <-> mac80211 STA mapping */ |
| 419 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) |
| 420 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
| 421 | |
| 422 | /* Add auxiliary station for scanning */ |
| 423 | ret = iwl_mvm_add_aux_sta(mvm); |
| 424 | if (ret) |
| 425 | goto error; |
| 426 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 427 | /* Add all the PHY contexts */ |
| 428 | chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0]; |
| 429 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); |
| 430 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 431 | /* |
| 432 | * The channel used here isn't relevant as it's |
| 433 | * going to be overwritten in the other flows. |
| 434 | * For now use the first channel we have. |
| 435 | */ |
| 436 | ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i], |
| 437 | &chandef, 1, 1); |
| 438 | if (ret) |
| 439 | goto error; |
| 440 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 441 | |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame^] | 442 | /* Initialize tx backoffs to the minimal possible */ |
| 443 | iwl_mvm_tt_tx_backoff(mvm, 0); |
| 444 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 445 | ret = iwl_mvm_power_update_device_mode(mvm); |
| 446 | if (ret) |
| 447 | goto error; |
| 448 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 449 | IWL_DEBUG_INFO(mvm, "RT uCode started.\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 450 | return 0; |
| 451 | error: |
| 452 | iwl_trans_stop_device(mvm->trans); |
| 453 | return ret; |
| 454 | } |
| 455 | |
| 456 | int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm) |
| 457 | { |
| 458 | int ret, i; |
| 459 | |
| 460 | lockdep_assert_held(&mvm->mutex); |
| 461 | |
| 462 | ret = iwl_trans_start_hw(mvm->trans); |
| 463 | if (ret) |
| 464 | return ret; |
| 465 | |
| 466 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN); |
| 467 | if (ret) { |
| 468 | IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret); |
| 469 | goto error; |
| 470 | } |
| 471 | |
Emmanuel Grumbach | 3322354 | 2013-03-09 20:38:19 +0200 | [diff] [blame] | 472 | ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 473 | if (ret) |
| 474 | goto error; |
| 475 | |
| 476 | /* Send phy db control command and then phy db calibration*/ |
| 477 | ret = iwl_send_phy_db_data(mvm->phy_db); |
| 478 | if (ret) |
| 479 | goto error; |
| 480 | |
| 481 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 482 | if (ret) |
| 483 | goto error; |
| 484 | |
| 485 | /* init the fw <-> mac80211 STA mapping */ |
| 486 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) |
| 487 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
| 488 | |
| 489 | /* Add auxiliary station for scanning */ |
| 490 | ret = iwl_mvm_add_aux_sta(mvm); |
| 491 | if (ret) |
| 492 | goto error; |
| 493 | |
| 494 | return 0; |
| 495 | error: |
| 496 | iwl_trans_stop_device(mvm->trans); |
| 497 | return ret; |
| 498 | } |
| 499 | |
| 500 | int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm, |
| 501 | struct iwl_rx_cmd_buffer *rxb, |
| 502 | struct iwl_device_cmd *cmd) |
| 503 | { |
| 504 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 505 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; |
| 506 | u32 flags = le32_to_cpu(card_state_notif->flags); |
| 507 | |
| 508 | IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n", |
| 509 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 510 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 511 | (flags & CT_KILL_CARD_DISABLED) ? |
| 512 | "Reached" : "Not reached"); |
| 513 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 518 | struct iwl_device_cmd *cmd) |
| 519 | { |
| 520 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 521 | struct iwl_radio_version_notif *radio_version = (void *)pkt->data; |
| 522 | |
| 523 | /* TODO: what to do with that? */ |
| 524 | IWL_DEBUG_INFO(mvm, |
| 525 | "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n", |
| 526 | le32_to_cpu(radio_version->radio_flavor), |
| 527 | le32_to_cpu(radio_version->radio_step), |
| 528 | le32_to_cpu(radio_version->radio_dash)); |
| 529 | return 0; |
| 530 | } |