Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
| 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/firmware.h> |
| 20 | |
| 21 | #include "core.h" |
| 22 | #include "mac.h" |
| 23 | #include "htc.h" |
| 24 | #include "hif.h" |
| 25 | #include "wmi.h" |
| 26 | #include "bmi.h" |
| 27 | #include "debug.h" |
| 28 | #include "htt.h" |
| 29 | |
| 30 | unsigned int ath10k_debug_mask; |
| 31 | static bool uart_print; |
| 32 | static unsigned int ath10k_p2p; |
| 33 | module_param_named(debug_mask, ath10k_debug_mask, uint, 0644); |
| 34 | module_param(uart_print, bool, 0644); |
| 35 | module_param_named(p2p, ath10k_p2p, uint, 0644); |
| 36 | MODULE_PARM_DESC(debug_mask, "Debugging mask"); |
| 37 | MODULE_PARM_DESC(uart_print, "Uart target debugging"); |
| 38 | MODULE_PARM_DESC(p2p, "Enable ath10k P2P support"); |
| 39 | |
| 40 | static const struct ath10k_hw_params ath10k_hw_params_list[] = { |
| 41 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 42 | .id = QCA988X_HW_2_0_VERSION, |
| 43 | .name = "qca988x hw2.0", |
| 44 | .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR, |
| 45 | .fw = { |
| 46 | .dir = QCA988X_HW_2_0_FW_DIR, |
| 47 | .fw = QCA988X_HW_2_0_FW_FILE, |
| 48 | .otp = QCA988X_HW_2_0_OTP_FILE, |
| 49 | .board = QCA988X_HW_2_0_BOARD_DATA_FILE, |
| 50 | }, |
| 51 | }, |
| 52 | }; |
| 53 | |
| 54 | static void ath10k_send_suspend_complete(struct ath10k *ar) |
| 55 | { |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 56 | ath10k_dbg(ATH10K_DBG_BOOT, "boot suspend complete\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 57 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 58 | complete(&ar->target_suspend); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 59 | } |
| 60 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 61 | static int ath10k_init_connect_htc(struct ath10k *ar) |
| 62 | { |
| 63 | int status; |
| 64 | |
| 65 | status = ath10k_wmi_connect_htc_service(ar); |
| 66 | if (status) |
| 67 | goto conn_fail; |
| 68 | |
| 69 | /* Start HTC */ |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 70 | status = ath10k_htc_start(&ar->htc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 71 | if (status) |
| 72 | goto conn_fail; |
| 73 | |
| 74 | /* Wait for WMI event to be ready */ |
| 75 | status = ath10k_wmi_wait_for_service_ready(ar); |
| 76 | if (status <= 0) { |
| 77 | ath10k_warn("wmi service ready event not received"); |
| 78 | status = -ETIMEDOUT; |
| 79 | goto timeout; |
| 80 | } |
| 81 | |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 82 | ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 83 | return 0; |
| 84 | |
| 85 | timeout: |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 86 | ath10k_htc_stop(&ar->htc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 87 | conn_fail: |
| 88 | return status; |
| 89 | } |
| 90 | |
| 91 | static int ath10k_init_configure_target(struct ath10k *ar) |
| 92 | { |
| 93 | u32 param_host; |
| 94 | int ret; |
| 95 | |
| 96 | /* tell target which HTC version it is used*/ |
| 97 | ret = ath10k_bmi_write32(ar, hi_app_host_interest, |
| 98 | HTC_PROTOCOL_VERSION); |
| 99 | if (ret) { |
| 100 | ath10k_err("settings HTC version failed\n"); |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | /* set the firmware mode to STA/IBSS/AP */ |
| 105 | ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host); |
| 106 | if (ret) { |
| 107 | ath10k_err("setting firmware mode (1/2) failed\n"); |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | /* TODO following parameters need to be re-visited. */ |
| 112 | /* num_device */ |
| 113 | param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT); |
| 114 | /* Firmware mode */ |
| 115 | /* FIXME: Why FW_MODE_AP ??.*/ |
| 116 | param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT); |
| 117 | /* mac_addr_method */ |
| 118 | param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT); |
| 119 | /* firmware_bridge */ |
| 120 | param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT); |
| 121 | /* fwsubmode */ |
| 122 | param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT); |
| 123 | |
| 124 | ret = ath10k_bmi_write32(ar, hi_option_flag, param_host); |
| 125 | if (ret) { |
| 126 | ath10k_err("setting firmware mode (2/2) failed\n"); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /* We do all byte-swapping on the host */ |
| 131 | ret = ath10k_bmi_write32(ar, hi_be, 0); |
| 132 | if (ret) { |
| 133 | ath10k_err("setting host CPU BE mode failed\n"); |
| 134 | return ret; |
| 135 | } |
| 136 | |
| 137 | /* FW descriptor/Data swap flags */ |
| 138 | ret = ath10k_bmi_write32(ar, hi_fw_swap, 0); |
| 139 | |
| 140 | if (ret) { |
| 141 | ath10k_err("setting FW data/desc swap flags failed\n"); |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar, |
| 149 | const char *dir, |
| 150 | const char *file) |
| 151 | { |
| 152 | char filename[100]; |
| 153 | const struct firmware *fw; |
| 154 | int ret; |
| 155 | |
| 156 | if (file == NULL) |
| 157 | return ERR_PTR(-ENOENT); |
| 158 | |
| 159 | if (dir == NULL) |
| 160 | dir = "."; |
| 161 | |
| 162 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); |
| 163 | ret = request_firmware(&fw, filename, ar->dev); |
| 164 | if (ret) |
| 165 | return ERR_PTR(ret); |
| 166 | |
| 167 | return fw; |
| 168 | } |
| 169 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 170 | static int ath10k_push_board_ext_data(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 171 | { |
| 172 | u32 board_data_size = QCA988X_BOARD_DATA_SZ; |
| 173 | u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ; |
| 174 | u32 board_ext_data_addr; |
| 175 | int ret; |
| 176 | |
| 177 | ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr); |
| 178 | if (ret) { |
| 179 | ath10k_err("could not read board ext data addr (%d)\n", ret); |
| 180 | return ret; |
| 181 | } |
| 182 | |
Kalle Valo | b52b768 | 2013-09-08 17:55:38 +0300 | [diff] [blame] | 183 | ath10k_dbg(ATH10K_DBG_BOOT, |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 184 | "boot push board extended data addr 0x%x\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 185 | board_ext_data_addr); |
| 186 | |
| 187 | if (board_ext_data_addr == 0) |
| 188 | return 0; |
| 189 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 190 | if (ar->board_len != (board_data_size + board_ext_data_size)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 191 | ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n", |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 192 | ar->board_len, board_data_size, board_ext_data_size); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 193 | return -EINVAL; |
| 194 | } |
| 195 | |
| 196 | ret = ath10k_bmi_write_memory(ar, board_ext_data_addr, |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 197 | ar->board_data + board_data_size, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 198 | board_ext_data_size); |
| 199 | if (ret) { |
| 200 | ath10k_err("could not write board ext data (%d)\n", ret); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | ret = ath10k_bmi_write32(ar, hi_board_ext_data_config, |
| 205 | (board_ext_data_size << 16) | 1); |
| 206 | if (ret) { |
| 207 | ath10k_err("could not write board ext data bit (%d)\n", ret); |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static int ath10k_download_board_data(struct ath10k *ar) |
| 215 | { |
| 216 | u32 board_data_size = QCA988X_BOARD_DATA_SZ; |
| 217 | u32 address; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 218 | int ret; |
| 219 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 220 | ret = ath10k_push_board_ext_data(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 221 | if (ret) { |
| 222 | ath10k_err("could not push board ext data (%d)\n", ret); |
| 223 | goto exit; |
| 224 | } |
| 225 | |
| 226 | ret = ath10k_bmi_read32(ar, hi_board_data, &address); |
| 227 | if (ret) { |
| 228 | ath10k_err("could not read board data addr (%d)\n", ret); |
| 229 | goto exit; |
| 230 | } |
| 231 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 232 | ret = ath10k_bmi_write_memory(ar, address, ar->board_data, |
| 233 | min_t(u32, board_data_size, |
| 234 | ar->board_len)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 235 | if (ret) { |
| 236 | ath10k_err("could not write board data (%d)\n", ret); |
| 237 | goto exit; |
| 238 | } |
| 239 | |
| 240 | ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1); |
| 241 | if (ret) { |
| 242 | ath10k_err("could not write board data bit (%d)\n", ret); |
| 243 | goto exit; |
| 244 | } |
| 245 | |
| 246 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static int ath10k_download_and_run_otp(struct ath10k *ar) |
| 251 | { |
Kalle Valo | d6d4a58 | 2014-03-11 17:33:19 +0200 | [diff] [blame] | 252 | u32 result, address = ar->hw_params.patch_load_addr; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 253 | int ret; |
| 254 | |
| 255 | /* OTP is optional */ |
| 256 | |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 257 | if (!ar->otp_data || !ar->otp_len) { |
| 258 | ath10k_warn("Not running otp, calibration will be incorrect!\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 259 | return 0; |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | ath10k_dbg(ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n", |
| 263 | address, ar->otp_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 264 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 265 | ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 266 | if (ret) { |
| 267 | ath10k_err("could not write otp (%d)\n", ret); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 268 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 269 | } |
| 270 | |
Kalle Valo | d6d4a58 | 2014-03-11 17:33:19 +0200 | [diff] [blame] | 271 | ret = ath10k_bmi_execute(ar, address, 0, &result); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 272 | if (ret) { |
| 273 | ath10k_err("could not execute otp (%d)\n", ret); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 274 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 275 | } |
| 276 | |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 277 | ath10k_dbg(ATH10K_DBG_BOOT, "boot otp execute result %d\n", result); |
| 278 | |
| 279 | if (result != 0) { |
| 280 | ath10k_err("otp calibration failed: %d", result); |
| 281 | return -EINVAL; |
| 282 | } |
| 283 | |
| 284 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static int ath10k_download_fw(struct ath10k *ar) |
| 288 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 289 | u32 address; |
| 290 | int ret; |
| 291 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 292 | address = ar->hw_params.patch_load_addr; |
| 293 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 294 | ret = ath10k_bmi_fast_download(ar, address, ar->firmware_data, |
| 295 | ar->firmware_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 296 | if (ret) { |
| 297 | ath10k_err("could not write fw (%d)\n", ret); |
| 298 | goto exit; |
| 299 | } |
| 300 | |
| 301 | exit: |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 302 | return ret; |
| 303 | } |
| 304 | |
| 305 | static void ath10k_core_free_firmware_files(struct ath10k *ar) |
| 306 | { |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 307 | if (ar->board && !IS_ERR(ar->board)) |
| 308 | release_firmware(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 309 | |
| 310 | if (ar->otp && !IS_ERR(ar->otp)) |
| 311 | release_firmware(ar->otp); |
| 312 | |
| 313 | if (ar->firmware && !IS_ERR(ar->firmware)) |
| 314 | release_firmware(ar->firmware); |
| 315 | |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 316 | ar->board = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 317 | ar->board_data = NULL; |
| 318 | ar->board_len = 0; |
| 319 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 320 | ar->otp = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 321 | ar->otp_data = NULL; |
| 322 | ar->otp_len = 0; |
| 323 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 324 | ar->firmware = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 325 | ar->firmware_data = NULL; |
| 326 | ar->firmware_len = 0; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 329 | static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar) |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 330 | { |
| 331 | int ret = 0; |
| 332 | |
| 333 | if (ar->hw_params.fw.fw == NULL) { |
| 334 | ath10k_err("firmware file not defined\n"); |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | |
| 338 | if (ar->hw_params.fw.board == NULL) { |
| 339 | ath10k_err("board data file not defined"); |
| 340 | return -EINVAL; |
| 341 | } |
| 342 | |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 343 | ar->board = ath10k_fetch_fw_file(ar, |
| 344 | ar->hw_params.fw.dir, |
| 345 | ar->hw_params.fw.board); |
| 346 | if (IS_ERR(ar->board)) { |
| 347 | ret = PTR_ERR(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 348 | ath10k_err("could not fetch board data (%d)\n", ret); |
| 349 | goto err; |
| 350 | } |
| 351 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 352 | ar->board_data = ar->board->data; |
| 353 | ar->board_len = ar->board->size; |
| 354 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 355 | ar->firmware = ath10k_fetch_fw_file(ar, |
| 356 | ar->hw_params.fw.dir, |
| 357 | ar->hw_params.fw.fw); |
| 358 | if (IS_ERR(ar->firmware)) { |
| 359 | ret = PTR_ERR(ar->firmware); |
| 360 | ath10k_err("could not fetch firmware (%d)\n", ret); |
| 361 | goto err; |
| 362 | } |
| 363 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 364 | ar->firmware_data = ar->firmware->data; |
| 365 | ar->firmware_len = ar->firmware->size; |
| 366 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 367 | /* OTP may be undefined. If so, don't fetch it at all */ |
| 368 | if (ar->hw_params.fw.otp == NULL) |
| 369 | return 0; |
| 370 | |
| 371 | ar->otp = ath10k_fetch_fw_file(ar, |
| 372 | ar->hw_params.fw.dir, |
| 373 | ar->hw_params.fw.otp); |
| 374 | if (IS_ERR(ar->otp)) { |
| 375 | ret = PTR_ERR(ar->otp); |
| 376 | ath10k_err("could not fetch otp (%d)\n", ret); |
| 377 | goto err; |
| 378 | } |
| 379 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 380 | ar->otp_data = ar->otp->data; |
| 381 | ar->otp_len = ar->otp->size; |
| 382 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 383 | return 0; |
| 384 | |
| 385 | err: |
| 386 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 387 | return ret; |
| 388 | } |
| 389 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 390 | static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name) |
| 391 | { |
| 392 | size_t magic_len, len, ie_len; |
| 393 | int ie_id, i, index, bit, ret; |
| 394 | struct ath10k_fw_ie *hdr; |
| 395 | const u8 *data; |
| 396 | __le32 *timestamp; |
| 397 | |
| 398 | /* first fetch the firmware file (firmware-*.bin) */ |
| 399 | ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name); |
| 400 | if (IS_ERR(ar->firmware)) { |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 401 | ath10k_err("could not fetch firmware file '%s/%s': %ld\n", |
| 402 | ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware)); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 403 | return PTR_ERR(ar->firmware); |
| 404 | } |
| 405 | |
| 406 | data = ar->firmware->data; |
| 407 | len = ar->firmware->size; |
| 408 | |
| 409 | /* magic also includes the null byte, check that as well */ |
| 410 | magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1; |
| 411 | |
| 412 | if (len < magic_len) { |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 413 | ath10k_err("firmware file '%s/%s' too small to contain magic: %zu\n", |
| 414 | ar->hw_params.fw.dir, name, len); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 415 | ret = -EINVAL; |
| 416 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) { |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 420 | ath10k_err("invalid firmware magic\n"); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 421 | ret = -EINVAL; |
| 422 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /* jump over the padding */ |
| 426 | magic_len = ALIGN(magic_len, 4); |
| 427 | |
| 428 | len -= magic_len; |
| 429 | data += magic_len; |
| 430 | |
| 431 | /* loop elements */ |
| 432 | while (len > sizeof(struct ath10k_fw_ie)) { |
| 433 | hdr = (struct ath10k_fw_ie *)data; |
| 434 | |
| 435 | ie_id = le32_to_cpu(hdr->id); |
| 436 | ie_len = le32_to_cpu(hdr->len); |
| 437 | |
| 438 | len -= sizeof(*hdr); |
| 439 | data += sizeof(*hdr); |
| 440 | |
| 441 | if (len < ie_len) { |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 442 | ath10k_err("invalid length for FW IE %d (%zu < %zu)\n", |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 443 | ie_id, len, ie_len); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 444 | ret = -EINVAL; |
| 445 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | switch (ie_id) { |
| 449 | case ATH10K_FW_IE_FW_VERSION: |
| 450 | if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1) |
| 451 | break; |
| 452 | |
| 453 | memcpy(ar->hw->wiphy->fw_version, data, ie_len); |
| 454 | ar->hw->wiphy->fw_version[ie_len] = '\0'; |
| 455 | |
| 456 | ath10k_dbg(ATH10K_DBG_BOOT, |
| 457 | "found fw version %s\n", |
| 458 | ar->hw->wiphy->fw_version); |
| 459 | break; |
| 460 | case ATH10K_FW_IE_TIMESTAMP: |
| 461 | if (ie_len != sizeof(u32)) |
| 462 | break; |
| 463 | |
| 464 | timestamp = (__le32 *)data; |
| 465 | |
| 466 | ath10k_dbg(ATH10K_DBG_BOOT, "found fw timestamp %d\n", |
| 467 | le32_to_cpup(timestamp)); |
| 468 | break; |
| 469 | case ATH10K_FW_IE_FEATURES: |
| 470 | ath10k_dbg(ATH10K_DBG_BOOT, |
| 471 | "found firmware features ie (%zd B)\n", |
| 472 | ie_len); |
| 473 | |
| 474 | for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) { |
| 475 | index = i / 8; |
| 476 | bit = i % 8; |
| 477 | |
| 478 | if (index == ie_len) |
| 479 | break; |
| 480 | |
Ben Greear | f591a1a | 2014-02-04 19:51:38 +0200 | [diff] [blame] | 481 | if (data[index] & (1 << bit)) { |
| 482 | ath10k_dbg(ATH10K_DBG_BOOT, |
| 483 | "Enabling feature bit: %i\n", |
| 484 | i); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 485 | __set_bit(i, ar->fw_features); |
Ben Greear | f591a1a | 2014-02-04 19:51:38 +0200 | [diff] [blame] | 486 | } |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | ath10k_dbg_dump(ATH10K_DBG_BOOT, "features", "", |
| 490 | ar->fw_features, |
| 491 | sizeof(ar->fw_features)); |
| 492 | break; |
| 493 | case ATH10K_FW_IE_FW_IMAGE: |
| 494 | ath10k_dbg(ATH10K_DBG_BOOT, |
| 495 | "found fw image ie (%zd B)\n", |
| 496 | ie_len); |
| 497 | |
| 498 | ar->firmware_data = data; |
| 499 | ar->firmware_len = ie_len; |
| 500 | |
| 501 | break; |
| 502 | case ATH10K_FW_IE_OTP_IMAGE: |
| 503 | ath10k_dbg(ATH10K_DBG_BOOT, |
| 504 | "found otp image ie (%zd B)\n", |
| 505 | ie_len); |
| 506 | |
| 507 | ar->otp_data = data; |
| 508 | ar->otp_len = ie_len; |
| 509 | |
| 510 | break; |
| 511 | default: |
| 512 | ath10k_warn("Unknown FW IE: %u\n", |
| 513 | le32_to_cpu(hdr->id)); |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | /* jump over the padding */ |
| 518 | ie_len = ALIGN(ie_len, 4); |
| 519 | |
| 520 | len -= ie_len; |
| 521 | data += ie_len; |
Fengguang Wu | e05634e | 2013-10-08 21:48:15 +0300 | [diff] [blame] | 522 | } |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 523 | |
| 524 | if (!ar->firmware_data || !ar->firmware_len) { |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 525 | ath10k_warn("No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n", |
| 526 | ar->hw_params.fw.dir, name); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 527 | ret = -ENOMEDIUM; |
| 528 | goto err; |
| 529 | } |
| 530 | |
| 531 | /* now fetch the board file */ |
| 532 | if (ar->hw_params.fw.board == NULL) { |
| 533 | ath10k_err("board data file not defined"); |
| 534 | ret = -EINVAL; |
| 535 | goto err; |
| 536 | } |
| 537 | |
| 538 | ar->board = ath10k_fetch_fw_file(ar, |
| 539 | ar->hw_params.fw.dir, |
| 540 | ar->hw_params.fw.board); |
| 541 | if (IS_ERR(ar->board)) { |
| 542 | ret = PTR_ERR(ar->board); |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 543 | ath10k_err("could not fetch board data '%s/%s' (%d)\n", |
| 544 | ar->hw_params.fw.dir, ar->hw_params.fw.board, |
| 545 | ret); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 546 | goto err; |
| 547 | } |
| 548 | |
| 549 | ar->board_data = ar->board->data; |
| 550 | ar->board_len = ar->board->size; |
| 551 | |
| 552 | return 0; |
| 553 | |
| 554 | err: |
| 555 | ath10k_core_free_firmware_files(ar); |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | static int ath10k_core_fetch_firmware_files(struct ath10k *ar) |
| 560 | { |
| 561 | int ret; |
| 562 | |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 563 | ar->fw_api = 2; |
| 564 | ath10k_dbg(ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
| 565 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 566 | ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE); |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 567 | if (ret == 0) |
| 568 | goto success; |
| 569 | |
| 570 | ar->fw_api = 1; |
| 571 | ath10k_dbg(ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 572 | |
| 573 | ret = ath10k_core_fetch_firmware_api_1(ar); |
| 574 | if (ret) |
| 575 | return ret; |
| 576 | |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame^] | 577 | success: |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 578 | ath10k_dbg(ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api); |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 583 | static int ath10k_init_download_firmware(struct ath10k *ar) |
| 584 | { |
| 585 | int ret; |
| 586 | |
| 587 | ret = ath10k_download_board_data(ar); |
| 588 | if (ret) |
| 589 | return ret; |
| 590 | |
| 591 | ret = ath10k_download_and_run_otp(ar); |
| 592 | if (ret) |
| 593 | return ret; |
| 594 | |
| 595 | ret = ath10k_download_fw(ar); |
| 596 | if (ret) |
| 597 | return ret; |
| 598 | |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | static int ath10k_init_uart(struct ath10k *ar) |
| 603 | { |
| 604 | int ret; |
| 605 | |
| 606 | /* |
| 607 | * Explicitly setting UART prints to zero as target turns it on |
| 608 | * based on scratch registers. |
| 609 | */ |
| 610 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 0); |
| 611 | if (ret) { |
| 612 | ath10k_warn("could not disable UART prints (%d)\n", ret); |
| 613 | return ret; |
| 614 | } |
| 615 | |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 616 | if (!uart_print) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 617 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 618 | |
| 619 | ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7); |
| 620 | if (ret) { |
| 621 | ath10k_warn("could not enable UART prints (%d)\n", ret); |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 1); |
| 626 | if (ret) { |
| 627 | ath10k_warn("could not enable UART prints (%d)\n", ret); |
| 628 | return ret; |
| 629 | } |
| 630 | |
Bartosz Markowski | 03fc137 | 2013-09-03 14:24:02 +0200 | [diff] [blame] | 631 | /* Set the UART baud rate to 19200. */ |
| 632 | ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200); |
| 633 | if (ret) { |
| 634 | ath10k_warn("could not set the baud rate (%d)\n", ret); |
| 635 | return ret; |
| 636 | } |
| 637 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 638 | ath10k_info("UART prints enabled\n"); |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int ath10k_init_hw_params(struct ath10k *ar) |
| 643 | { |
| 644 | const struct ath10k_hw_params *uninitialized_var(hw_params); |
| 645 | int i; |
| 646 | |
| 647 | for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) { |
| 648 | hw_params = &ath10k_hw_params_list[i]; |
| 649 | |
| 650 | if (hw_params->id == ar->target_version) |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | if (i == ARRAY_SIZE(ath10k_hw_params_list)) { |
| 655 | ath10k_err("Unsupported hardware version: 0x%x\n", |
| 656 | ar->target_version); |
| 657 | return -EINVAL; |
| 658 | } |
| 659 | |
| 660 | ar->hw_params = *hw_params; |
| 661 | |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 662 | ath10k_dbg(ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n", |
| 663 | ar->hw_params.name, ar->target_version); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 668 | static void ath10k_core_restart(struct work_struct *work) |
| 669 | { |
| 670 | struct ath10k *ar = container_of(work, struct ath10k, restart_work); |
| 671 | |
| 672 | mutex_lock(&ar->conf_mutex); |
| 673 | |
| 674 | switch (ar->state) { |
| 675 | case ATH10K_STATE_ON: |
| 676 | ath10k_halt(ar); |
| 677 | ar->state = ATH10K_STATE_RESTARTING; |
| 678 | ieee80211_restart_hw(ar->hw); |
| 679 | break; |
| 680 | case ATH10K_STATE_OFF: |
Michal Kazior | 5e90de8 | 2013-10-16 16:46:05 +0300 | [diff] [blame] | 681 | /* this can happen if driver is being unloaded |
| 682 | * or if the crash happens during FW probing */ |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 683 | ath10k_warn("cannot restart a device that hasn't been started\n"); |
| 684 | break; |
| 685 | case ATH10K_STATE_RESTARTING: |
| 686 | case ATH10K_STATE_RESTARTED: |
| 687 | ar->state = ATH10K_STATE_WEDGED; |
| 688 | /* fall through */ |
| 689 | case ATH10K_STATE_WEDGED: |
| 690 | ath10k_warn("device is wedged, will not restart\n"); |
| 691 | break; |
| 692 | } |
| 693 | |
| 694 | mutex_unlock(&ar->conf_mutex); |
| 695 | } |
| 696 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 697 | struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 698 | const struct ath10k_hif_ops *hif_ops) |
| 699 | { |
| 700 | struct ath10k *ar; |
| 701 | |
| 702 | ar = ath10k_mac_create(); |
| 703 | if (!ar) |
| 704 | return NULL; |
| 705 | |
| 706 | ar->ath_common.priv = ar; |
| 707 | ar->ath_common.hw = ar->hw; |
| 708 | |
| 709 | ar->p2p = !!ath10k_p2p; |
| 710 | ar->dev = dev; |
| 711 | |
| 712 | ar->hif.priv = hif_priv; |
| 713 | ar->hif.ops = hif_ops; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 714 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 715 | init_completion(&ar->scan.started); |
| 716 | init_completion(&ar->scan.completed); |
| 717 | init_completion(&ar->scan.on_channel); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 718 | init_completion(&ar->target_suspend); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 719 | |
| 720 | init_completion(&ar->install_key_done); |
| 721 | init_completion(&ar->vdev_setup_done); |
| 722 | |
| 723 | setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar); |
| 724 | |
| 725 | ar->workqueue = create_singlethread_workqueue("ath10k_wq"); |
| 726 | if (!ar->workqueue) |
| 727 | goto err_wq; |
| 728 | |
| 729 | mutex_init(&ar->conf_mutex); |
| 730 | spin_lock_init(&ar->data_lock); |
| 731 | |
| 732 | INIT_LIST_HEAD(&ar->peers); |
| 733 | init_waitqueue_head(&ar->peer_mapping_wq); |
| 734 | |
| 735 | init_completion(&ar->offchan_tx_completed); |
| 736 | INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work); |
| 737 | skb_queue_head_init(&ar->offchan_tx_queue); |
| 738 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 739 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work); |
| 740 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); |
| 741 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 742 | INIT_WORK(&ar->restart_work, ath10k_core_restart); |
| 743 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 744 | return ar; |
| 745 | |
| 746 | err_wq: |
| 747 | ath10k_mac_destroy(ar); |
| 748 | return NULL; |
| 749 | } |
| 750 | EXPORT_SYMBOL(ath10k_core_create); |
| 751 | |
| 752 | void ath10k_core_destroy(struct ath10k *ar) |
| 753 | { |
| 754 | flush_workqueue(ar->workqueue); |
| 755 | destroy_workqueue(ar->workqueue); |
| 756 | |
| 757 | ath10k_mac_destroy(ar); |
| 758 | } |
| 759 | EXPORT_SYMBOL(ath10k_core_destroy); |
| 760 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 761 | int ath10k_core_start(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 762 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 763 | int status; |
| 764 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 765 | lockdep_assert_held(&ar->conf_mutex); |
| 766 | |
Michal Kazior | 64d151d | 2013-07-16 09:38:53 +0200 | [diff] [blame] | 767 | ath10k_bmi_start(ar); |
| 768 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 769 | if (ath10k_init_configure_target(ar)) { |
| 770 | status = -EINVAL; |
| 771 | goto err; |
| 772 | } |
| 773 | |
| 774 | status = ath10k_init_download_firmware(ar); |
| 775 | if (status) |
| 776 | goto err; |
| 777 | |
| 778 | status = ath10k_init_uart(ar); |
| 779 | if (status) |
| 780 | goto err; |
| 781 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 782 | ar->htc.htc_ops.target_send_suspend_complete = |
| 783 | ath10k_send_suspend_complete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 784 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 785 | status = ath10k_htc_init(ar); |
| 786 | if (status) { |
| 787 | ath10k_err("could not init HTC (%d)\n", status); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 788 | goto err; |
| 789 | } |
| 790 | |
| 791 | status = ath10k_bmi_done(ar); |
| 792 | if (status) |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 793 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 794 | |
| 795 | status = ath10k_wmi_attach(ar); |
| 796 | if (status) { |
| 797 | ath10k_err("WMI attach failed: %d\n", status); |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 798 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 799 | } |
| 800 | |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 801 | status = ath10k_hif_start(ar); |
| 802 | if (status) { |
| 803 | ath10k_err("could not start HIF: %d\n", status); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 804 | goto err_wmi_detach; |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | status = ath10k_htc_wait_target(&ar->htc); |
| 808 | if (status) { |
| 809 | ath10k_err("failed to connect to HTC: %d\n", status); |
| 810 | goto err_hif_stop; |
| 811 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 812 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 813 | status = ath10k_htt_attach(ar); |
| 814 | if (status) { |
| 815 | ath10k_err("could not attach htt (%d)\n", status); |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 816 | goto err_hif_stop; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | status = ath10k_init_connect_htc(ar); |
| 820 | if (status) |
| 821 | goto err_htt_detach; |
| 822 | |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 823 | ath10k_dbg(ATH10K_DBG_BOOT, "firmware %s booted\n", |
| 824 | ar->hw->wiphy->fw_version); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 825 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 826 | status = ath10k_wmi_cmd_init(ar); |
| 827 | if (status) { |
| 828 | ath10k_err("could not send WMI init command (%d)\n", status); |
| 829 | goto err_disconnect_htc; |
| 830 | } |
| 831 | |
| 832 | status = ath10k_wmi_wait_for_unified_ready(ar); |
| 833 | if (status <= 0) { |
| 834 | ath10k_err("wmi unified ready event not received\n"); |
| 835 | status = -ETIMEDOUT; |
| 836 | goto err_disconnect_htc; |
| 837 | } |
| 838 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 839 | status = ath10k_htt_attach_target(&ar->htt); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 840 | if (status) |
| 841 | goto err_disconnect_htc; |
| 842 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 843 | status = ath10k_debug_start(ar); |
| 844 | if (status) |
| 845 | goto err_disconnect_htc; |
| 846 | |
Michal Kazior | 1a1b8a8 | 2013-07-16 09:38:55 +0200 | [diff] [blame] | 847 | ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 848 | INIT_LIST_HEAD(&ar->arvifs); |
Michal Kazior | 1a1b8a8 | 2013-07-16 09:38:55 +0200 | [diff] [blame] | 849 | |
Kalle Valo | 650b91f | 2013-11-20 10:00:49 +0200 | [diff] [blame] | 850 | if (!test_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags)) |
| 851 | ath10k_info("%s (0x%x) fw %s api %d htt %d.%d\n", |
| 852 | ar->hw_params.name, ar->target_version, |
| 853 | ar->hw->wiphy->fw_version, ar->fw_api, |
| 854 | ar->htt.target_version_major, |
| 855 | ar->htt.target_version_minor); |
| 856 | |
| 857 | __set_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags); |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 858 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 859 | return 0; |
| 860 | |
| 861 | err_disconnect_htc: |
| 862 | ath10k_htc_stop(&ar->htc); |
| 863 | err_htt_detach: |
| 864 | ath10k_htt_detach(&ar->htt); |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 865 | err_hif_stop: |
| 866 | ath10k_hif_stop(ar); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 867 | err_wmi_detach: |
| 868 | ath10k_wmi_detach(ar); |
| 869 | err: |
| 870 | return status; |
| 871 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 872 | EXPORT_SYMBOL(ath10k_core_start); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 873 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 874 | int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt) |
| 875 | { |
| 876 | int ret; |
| 877 | |
| 878 | reinit_completion(&ar->target_suspend); |
| 879 | |
| 880 | ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt); |
| 881 | if (ret) { |
| 882 | ath10k_warn("could not suspend target (%d)\n", ret); |
| 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | ret = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ); |
| 887 | |
| 888 | if (ret == 0) { |
| 889 | ath10k_warn("suspend timed out - target pause event never came\n"); |
| 890 | return -ETIMEDOUT; |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 896 | void ath10k_core_stop(struct ath10k *ar) |
| 897 | { |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 898 | lockdep_assert_held(&ar->conf_mutex); |
| 899 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 900 | /* try to suspend target */ |
| 901 | ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 902 | ath10k_debug_stop(ar); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 903 | ath10k_htc_stop(&ar->htc); |
| 904 | ath10k_htt_detach(&ar->htt); |
| 905 | ath10k_wmi_detach(ar); |
| 906 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 907 | EXPORT_SYMBOL(ath10k_core_stop); |
| 908 | |
| 909 | /* mac80211 manages fw/hw initialization through start/stop hooks. However in |
| 910 | * order to know what hw capabilities should be advertised to mac80211 it is |
| 911 | * necessary to load the firmware (and tear it down immediately since start |
| 912 | * hook will try to init it again) before registering */ |
| 913 | static int ath10k_core_probe_fw(struct ath10k *ar) |
| 914 | { |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 915 | struct bmi_target_info target_info; |
| 916 | int ret = 0; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 917 | |
| 918 | ret = ath10k_hif_power_up(ar); |
| 919 | if (ret) { |
| 920 | ath10k_err("could not start pci hif (%d)\n", ret); |
| 921 | return ret; |
| 922 | } |
| 923 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 924 | memset(&target_info, 0, sizeof(target_info)); |
| 925 | ret = ath10k_bmi_get_target_info(ar, &target_info); |
| 926 | if (ret) { |
| 927 | ath10k_err("could not get target info (%d)\n", ret); |
| 928 | ath10k_hif_power_down(ar); |
| 929 | return ret; |
| 930 | } |
| 931 | |
| 932 | ar->target_version = target_info.version; |
| 933 | ar->hw->wiphy->hw_version = target_info.version; |
| 934 | |
| 935 | ret = ath10k_init_hw_params(ar); |
| 936 | if (ret) { |
| 937 | ath10k_err("could not get hw params (%d)\n", ret); |
| 938 | ath10k_hif_power_down(ar); |
| 939 | return ret; |
| 940 | } |
| 941 | |
| 942 | ret = ath10k_core_fetch_firmware_files(ar); |
| 943 | if (ret) { |
| 944 | ath10k_err("could not fetch firmware files (%d)\n", ret); |
| 945 | ath10k_hif_power_down(ar); |
| 946 | return ret; |
| 947 | } |
| 948 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 949 | mutex_lock(&ar->conf_mutex); |
| 950 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 951 | ret = ath10k_core_start(ar); |
| 952 | if (ret) { |
| 953 | ath10k_err("could not init core (%d)\n", ret); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 954 | ath10k_core_free_firmware_files(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 955 | ath10k_hif_power_down(ar); |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 956 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 957 | return ret; |
| 958 | } |
| 959 | |
| 960 | ath10k_core_stop(ar); |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 961 | |
| 962 | mutex_unlock(&ar->conf_mutex); |
| 963 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 964 | ath10k_hif_power_down(ar); |
| 965 | return 0; |
| 966 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 967 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 968 | static int ath10k_core_check_chip_id(struct ath10k *ar) |
| 969 | { |
| 970 | u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV); |
| 971 | |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 972 | ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n", |
| 973 | ar->chip_id, hw_revision); |
| 974 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 975 | /* Check that we are not using hw1.0 (some of them have same pci id |
| 976 | * as hw2.0) before doing anything else as ath10k crashes horribly |
| 977 | * due to missing hw1.0 workarounds. */ |
| 978 | switch (hw_revision) { |
| 979 | case QCA988X_HW_1_0_CHIP_ID_REV: |
| 980 | ath10k_err("ERROR: qca988x hw1.0 is not supported\n"); |
| 981 | return -EOPNOTSUPP; |
| 982 | |
| 983 | case QCA988X_HW_2_0_CHIP_ID_REV: |
| 984 | /* known hardware revision, continue normally */ |
| 985 | return 0; |
| 986 | |
| 987 | default: |
| 988 | ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n", |
| 989 | ar->chip_id); |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | return 0; |
| 994 | } |
| 995 | |
| 996 | int ath10k_core_register(struct ath10k *ar, u32 chip_id) |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 997 | { |
| 998 | int status; |
| 999 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 1000 | ar->chip_id = chip_id; |
| 1001 | |
| 1002 | status = ath10k_core_check_chip_id(ar); |
| 1003 | if (status) { |
| 1004 | ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id); |
| 1005 | return status; |
| 1006 | } |
| 1007 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1008 | status = ath10k_core_probe_fw(ar); |
| 1009 | if (status) { |
| 1010 | ath10k_err("could not probe fw (%d)\n", status); |
| 1011 | return status; |
| 1012 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1013 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1014 | status = ath10k_mac_register(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1015 | if (status) { |
| 1016 | ath10k_err("could not register to mac80211 (%d)\n", status); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1017 | goto err_release_fw; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1018 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1019 | |
| 1020 | status = ath10k_debug_create(ar); |
| 1021 | if (status) { |
| 1022 | ath10k_err("unable to initialize debugfs\n"); |
| 1023 | goto err_unregister_mac; |
| 1024 | } |
| 1025 | |
| 1026 | return 0; |
| 1027 | |
| 1028 | err_unregister_mac: |
| 1029 | ath10k_mac_unregister(ar); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1030 | err_release_fw: |
| 1031 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1032 | return status; |
| 1033 | } |
| 1034 | EXPORT_SYMBOL(ath10k_core_register); |
| 1035 | |
| 1036 | void ath10k_core_unregister(struct ath10k *ar) |
| 1037 | { |
| 1038 | /* We must unregister from mac80211 before we stop HTC and HIF. |
| 1039 | * Otherwise we will fail to submit commands to FW and mac80211 will be |
| 1040 | * unhappy about callback failures. */ |
| 1041 | ath10k_mac_unregister(ar); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1042 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1043 | ath10k_core_free_firmware_files(ar); |
Ben Greear | 6f1f56e | 2013-11-04 09:18:16 -0800 | [diff] [blame] | 1044 | |
| 1045 | ath10k_debug_destroy(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1046 | } |
| 1047 | EXPORT_SYMBOL(ath10k_core_unregister); |
| 1048 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1049 | MODULE_AUTHOR("Qualcomm Atheros"); |
| 1050 | MODULE_DESCRIPTION("Core module for QCA988X PCIe devices."); |
| 1051 | MODULE_LICENSE("Dual BSD/GPL"); |