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 | |
| 58 | ar->is_target_paused = true; |
| 59 | wake_up(&ar->event_queue); |
| 60 | } |
| 61 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 62 | static int ath10k_init_connect_htc(struct ath10k *ar) |
| 63 | { |
| 64 | int status; |
| 65 | |
| 66 | status = ath10k_wmi_connect_htc_service(ar); |
| 67 | if (status) |
| 68 | goto conn_fail; |
| 69 | |
| 70 | /* Start HTC */ |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 71 | status = ath10k_htc_start(&ar->htc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 72 | if (status) |
| 73 | goto conn_fail; |
| 74 | |
| 75 | /* Wait for WMI event to be ready */ |
| 76 | status = ath10k_wmi_wait_for_service_ready(ar); |
| 77 | if (status <= 0) { |
| 78 | ath10k_warn("wmi service ready event not received"); |
| 79 | status = -ETIMEDOUT; |
| 80 | goto timeout; |
| 81 | } |
| 82 | |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 83 | ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 84 | return 0; |
| 85 | |
| 86 | timeout: |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 87 | ath10k_htc_stop(&ar->htc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 88 | conn_fail: |
| 89 | return status; |
| 90 | } |
| 91 | |
| 92 | static int ath10k_init_configure_target(struct ath10k *ar) |
| 93 | { |
| 94 | u32 param_host; |
| 95 | int ret; |
| 96 | |
| 97 | /* tell target which HTC version it is used*/ |
| 98 | ret = ath10k_bmi_write32(ar, hi_app_host_interest, |
| 99 | HTC_PROTOCOL_VERSION); |
| 100 | if (ret) { |
| 101 | ath10k_err("settings HTC version failed\n"); |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | /* set the firmware mode to STA/IBSS/AP */ |
| 106 | ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host); |
| 107 | if (ret) { |
| 108 | ath10k_err("setting firmware mode (1/2) failed\n"); |
| 109 | return ret; |
| 110 | } |
| 111 | |
| 112 | /* TODO following parameters need to be re-visited. */ |
| 113 | /* num_device */ |
| 114 | param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT); |
| 115 | /* Firmware mode */ |
| 116 | /* FIXME: Why FW_MODE_AP ??.*/ |
| 117 | param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT); |
| 118 | /* mac_addr_method */ |
| 119 | param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT); |
| 120 | /* firmware_bridge */ |
| 121 | param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT); |
| 122 | /* fwsubmode */ |
| 123 | param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT); |
| 124 | |
| 125 | ret = ath10k_bmi_write32(ar, hi_option_flag, param_host); |
| 126 | if (ret) { |
| 127 | ath10k_err("setting firmware mode (2/2) failed\n"); |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | /* We do all byte-swapping on the host */ |
| 132 | ret = ath10k_bmi_write32(ar, hi_be, 0); |
| 133 | if (ret) { |
| 134 | ath10k_err("setting host CPU BE mode failed\n"); |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | /* FW descriptor/Data swap flags */ |
| 139 | ret = ath10k_bmi_write32(ar, hi_fw_swap, 0); |
| 140 | |
| 141 | if (ret) { |
| 142 | ath10k_err("setting FW data/desc swap flags failed\n"); |
| 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar, |
| 150 | const char *dir, |
| 151 | const char *file) |
| 152 | { |
| 153 | char filename[100]; |
| 154 | const struct firmware *fw; |
| 155 | int ret; |
| 156 | |
| 157 | if (file == NULL) |
| 158 | return ERR_PTR(-ENOENT); |
| 159 | |
| 160 | if (dir == NULL) |
| 161 | dir = "."; |
| 162 | |
| 163 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); |
| 164 | ret = request_firmware(&fw, filename, ar->dev); |
| 165 | if (ret) |
| 166 | return ERR_PTR(ret); |
| 167 | |
| 168 | return fw; |
| 169 | } |
| 170 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 171 | static int ath10k_push_board_ext_data(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 172 | { |
| 173 | u32 board_data_size = QCA988X_BOARD_DATA_SZ; |
| 174 | u32 board_ext_data_size = QCA988X_BOARD_EXT_DATA_SZ; |
| 175 | u32 board_ext_data_addr; |
| 176 | int ret; |
| 177 | |
| 178 | ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr); |
| 179 | if (ret) { |
| 180 | ath10k_err("could not read board ext data addr (%d)\n", ret); |
| 181 | return ret; |
| 182 | } |
| 183 | |
Kalle Valo | b52b768 | 2013-09-08 17:55:38 +0300 | [diff] [blame] | 184 | ath10k_dbg(ATH10K_DBG_BOOT, |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 185 | "boot push board extended data addr 0x%x\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 186 | board_ext_data_addr); |
| 187 | |
| 188 | if (board_ext_data_addr == 0) |
| 189 | return 0; |
| 190 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 191 | if (ar->board_len != (board_data_size + board_ext_data_size)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 192 | ath10k_err("invalid board (ext) data sizes %zu != %d+%d\n", |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 193 | ar->board_len, board_data_size, board_ext_data_size); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 194 | return -EINVAL; |
| 195 | } |
| 196 | |
| 197 | ret = ath10k_bmi_write_memory(ar, board_ext_data_addr, |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 198 | ar->board_data + board_data_size, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 199 | board_ext_data_size); |
| 200 | if (ret) { |
| 201 | ath10k_err("could not write board ext data (%d)\n", ret); |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | ret = ath10k_bmi_write32(ar, hi_board_ext_data_config, |
| 206 | (board_ext_data_size << 16) | 1); |
| 207 | if (ret) { |
| 208 | ath10k_err("could not write board ext data bit (%d)\n", ret); |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int ath10k_download_board_data(struct ath10k *ar) |
| 216 | { |
| 217 | u32 board_data_size = QCA988X_BOARD_DATA_SZ; |
| 218 | u32 address; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 219 | int ret; |
| 220 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 221 | ret = ath10k_push_board_ext_data(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 222 | if (ret) { |
| 223 | ath10k_err("could not push board ext data (%d)\n", ret); |
| 224 | goto exit; |
| 225 | } |
| 226 | |
| 227 | ret = ath10k_bmi_read32(ar, hi_board_data, &address); |
| 228 | if (ret) { |
| 229 | ath10k_err("could not read board data addr (%d)\n", ret); |
| 230 | goto exit; |
| 231 | } |
| 232 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 233 | ret = ath10k_bmi_write_memory(ar, address, ar->board_data, |
| 234 | min_t(u32, board_data_size, |
| 235 | ar->board_len)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 236 | if (ret) { |
| 237 | ath10k_err("could not write board data (%d)\n", ret); |
| 238 | goto exit; |
| 239 | } |
| 240 | |
| 241 | ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1); |
| 242 | if (ret) { |
| 243 | ath10k_err("could not write board data bit (%d)\n", ret); |
| 244 | goto exit; |
| 245 | } |
| 246 | |
| 247 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static int ath10k_download_and_run_otp(struct ath10k *ar) |
| 252 | { |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 253 | u32 address = ar->hw_params.patch_load_addr; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 254 | u32 exec_param; |
| 255 | int ret; |
| 256 | |
| 257 | /* OTP is optional */ |
| 258 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 259 | if (!ar->otp_data || !ar->otp_len) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 260 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 261 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 262 | 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] | 263 | if (ret) { |
| 264 | ath10k_err("could not write otp (%d)\n", ret); |
| 265 | goto exit; |
| 266 | } |
| 267 | |
| 268 | exec_param = 0; |
| 269 | ret = ath10k_bmi_execute(ar, address, &exec_param); |
| 270 | if (ret) { |
| 271 | ath10k_err("could not execute otp (%d)\n", ret); |
| 272 | goto exit; |
| 273 | } |
| 274 | |
| 275 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | static int ath10k_download_fw(struct ath10k *ar) |
| 280 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 281 | u32 address; |
| 282 | int ret; |
| 283 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 284 | address = ar->hw_params.patch_load_addr; |
| 285 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 286 | ret = ath10k_bmi_fast_download(ar, address, ar->firmware_data, |
| 287 | ar->firmware_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 288 | if (ret) { |
| 289 | ath10k_err("could not write fw (%d)\n", ret); |
| 290 | goto exit; |
| 291 | } |
| 292 | |
| 293 | exit: |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static void ath10k_core_free_firmware_files(struct ath10k *ar) |
| 298 | { |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 299 | if (ar->board && !IS_ERR(ar->board)) |
| 300 | release_firmware(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 301 | |
| 302 | if (ar->otp && !IS_ERR(ar->otp)) |
| 303 | release_firmware(ar->otp); |
| 304 | |
| 305 | if (ar->firmware && !IS_ERR(ar->firmware)) |
| 306 | release_firmware(ar->firmware); |
| 307 | |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 308 | ar->board = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 309 | ar->board_data = NULL; |
| 310 | ar->board_len = 0; |
| 311 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 312 | ar->otp = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 313 | ar->otp_data = NULL; |
| 314 | ar->otp_len = 0; |
| 315 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 316 | ar->firmware = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 317 | ar->firmware_data = NULL; |
| 318 | ar->firmware_len = 0; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static int ath10k_core_fetch_firmware_files(struct ath10k *ar) |
| 322 | { |
| 323 | int ret = 0; |
| 324 | |
| 325 | if (ar->hw_params.fw.fw == NULL) { |
| 326 | ath10k_err("firmware file not defined\n"); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
| 330 | if (ar->hw_params.fw.board == NULL) { |
| 331 | ath10k_err("board data file not defined"); |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 335 | ar->board = ath10k_fetch_fw_file(ar, |
| 336 | ar->hw_params.fw.dir, |
| 337 | ar->hw_params.fw.board); |
| 338 | if (IS_ERR(ar->board)) { |
| 339 | ret = PTR_ERR(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 340 | ath10k_err("could not fetch board data (%d)\n", ret); |
| 341 | goto err; |
| 342 | } |
| 343 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 344 | ar->board_data = ar->board->data; |
| 345 | ar->board_len = ar->board->size; |
| 346 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 347 | ar->firmware = ath10k_fetch_fw_file(ar, |
| 348 | ar->hw_params.fw.dir, |
| 349 | ar->hw_params.fw.fw); |
| 350 | if (IS_ERR(ar->firmware)) { |
| 351 | ret = PTR_ERR(ar->firmware); |
| 352 | ath10k_err("could not fetch firmware (%d)\n", ret); |
| 353 | goto err; |
| 354 | } |
| 355 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 356 | ar->firmware_data = ar->firmware->data; |
| 357 | ar->firmware_len = ar->firmware->size; |
| 358 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 359 | /* OTP may be undefined. If so, don't fetch it at all */ |
| 360 | if (ar->hw_params.fw.otp == NULL) |
| 361 | return 0; |
| 362 | |
| 363 | ar->otp = ath10k_fetch_fw_file(ar, |
| 364 | ar->hw_params.fw.dir, |
| 365 | ar->hw_params.fw.otp); |
| 366 | if (IS_ERR(ar->otp)) { |
| 367 | ret = PTR_ERR(ar->otp); |
| 368 | ath10k_err("could not fetch otp (%d)\n", ret); |
| 369 | goto err; |
| 370 | } |
| 371 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame^] | 372 | ar->otp_data = ar->otp->data; |
| 373 | ar->otp_len = ar->otp->size; |
| 374 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 375 | return 0; |
| 376 | |
| 377 | err: |
| 378 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | static int ath10k_init_download_firmware(struct ath10k *ar) |
| 383 | { |
| 384 | int ret; |
| 385 | |
| 386 | ret = ath10k_download_board_data(ar); |
| 387 | if (ret) |
| 388 | return ret; |
| 389 | |
| 390 | ret = ath10k_download_and_run_otp(ar); |
| 391 | if (ret) |
| 392 | return ret; |
| 393 | |
| 394 | ret = ath10k_download_fw(ar); |
| 395 | if (ret) |
| 396 | return ret; |
| 397 | |
| 398 | return ret; |
| 399 | } |
| 400 | |
| 401 | static int ath10k_init_uart(struct ath10k *ar) |
| 402 | { |
| 403 | int ret; |
| 404 | |
| 405 | /* |
| 406 | * Explicitly setting UART prints to zero as target turns it on |
| 407 | * based on scratch registers. |
| 408 | */ |
| 409 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 0); |
| 410 | if (ret) { |
| 411 | ath10k_warn("could not disable UART prints (%d)\n", ret); |
| 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | if (!uart_print) { |
| 416 | ath10k_info("UART prints disabled\n"); |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, 7); |
| 421 | if (ret) { |
| 422 | ath10k_warn("could not enable UART prints (%d)\n", ret); |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 1); |
| 427 | if (ret) { |
| 428 | ath10k_warn("could not enable UART prints (%d)\n", ret); |
| 429 | return ret; |
| 430 | } |
| 431 | |
Bartosz Markowski | 03fc137 | 2013-09-03 14:24:02 +0200 | [diff] [blame] | 432 | /* Set the UART baud rate to 19200. */ |
| 433 | ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200); |
| 434 | if (ret) { |
| 435 | ath10k_warn("could not set the baud rate (%d)\n", ret); |
| 436 | return ret; |
| 437 | } |
| 438 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 439 | ath10k_info("UART prints enabled\n"); |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int ath10k_init_hw_params(struct ath10k *ar) |
| 444 | { |
| 445 | const struct ath10k_hw_params *uninitialized_var(hw_params); |
| 446 | int i; |
| 447 | |
| 448 | for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) { |
| 449 | hw_params = &ath10k_hw_params_list[i]; |
| 450 | |
| 451 | if (hw_params->id == ar->target_version) |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | if (i == ARRAY_SIZE(ath10k_hw_params_list)) { |
| 456 | ath10k_err("Unsupported hardware version: 0x%x\n", |
| 457 | ar->target_version); |
| 458 | return -EINVAL; |
| 459 | } |
| 460 | |
| 461 | ar->hw_params = *hw_params; |
| 462 | |
| 463 | ath10k_info("Hardware name %s version 0x%x\n", |
| 464 | ar->hw_params.name, ar->target_version); |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 469 | static void ath10k_core_restart(struct work_struct *work) |
| 470 | { |
| 471 | struct ath10k *ar = container_of(work, struct ath10k, restart_work); |
| 472 | |
| 473 | mutex_lock(&ar->conf_mutex); |
| 474 | |
| 475 | switch (ar->state) { |
| 476 | case ATH10K_STATE_ON: |
| 477 | ath10k_halt(ar); |
| 478 | ar->state = ATH10K_STATE_RESTARTING; |
| 479 | ieee80211_restart_hw(ar->hw); |
| 480 | break; |
| 481 | case ATH10K_STATE_OFF: |
| 482 | /* this can happen if driver is being unloaded */ |
| 483 | ath10k_warn("cannot restart a device that hasn't been started\n"); |
| 484 | break; |
| 485 | case ATH10K_STATE_RESTARTING: |
| 486 | case ATH10K_STATE_RESTARTED: |
| 487 | ar->state = ATH10K_STATE_WEDGED; |
| 488 | /* fall through */ |
| 489 | case ATH10K_STATE_WEDGED: |
| 490 | ath10k_warn("device is wedged, will not restart\n"); |
| 491 | break; |
| 492 | } |
| 493 | |
| 494 | mutex_unlock(&ar->conf_mutex); |
| 495 | } |
| 496 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 497 | struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 498 | const struct ath10k_hif_ops *hif_ops) |
| 499 | { |
| 500 | struct ath10k *ar; |
| 501 | |
| 502 | ar = ath10k_mac_create(); |
| 503 | if (!ar) |
| 504 | return NULL; |
| 505 | |
| 506 | ar->ath_common.priv = ar; |
| 507 | ar->ath_common.hw = ar->hw; |
| 508 | |
| 509 | ar->p2p = !!ath10k_p2p; |
| 510 | ar->dev = dev; |
| 511 | |
| 512 | ar->hif.priv = hif_priv; |
| 513 | ar->hif.ops = hif_ops; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 514 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 515 | init_completion(&ar->scan.started); |
| 516 | init_completion(&ar->scan.completed); |
| 517 | init_completion(&ar->scan.on_channel); |
| 518 | |
| 519 | init_completion(&ar->install_key_done); |
| 520 | init_completion(&ar->vdev_setup_done); |
| 521 | |
| 522 | setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar); |
| 523 | |
| 524 | ar->workqueue = create_singlethread_workqueue("ath10k_wq"); |
| 525 | if (!ar->workqueue) |
| 526 | goto err_wq; |
| 527 | |
| 528 | mutex_init(&ar->conf_mutex); |
| 529 | spin_lock_init(&ar->data_lock); |
| 530 | |
| 531 | INIT_LIST_HEAD(&ar->peers); |
| 532 | init_waitqueue_head(&ar->peer_mapping_wq); |
| 533 | |
| 534 | init_completion(&ar->offchan_tx_completed); |
| 535 | INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work); |
| 536 | skb_queue_head_init(&ar->offchan_tx_queue); |
| 537 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 538 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work); |
| 539 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); |
| 540 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 541 | init_waitqueue_head(&ar->event_queue); |
| 542 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 543 | INIT_WORK(&ar->restart_work, ath10k_core_restart); |
| 544 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 545 | return ar; |
| 546 | |
| 547 | err_wq: |
| 548 | ath10k_mac_destroy(ar); |
| 549 | return NULL; |
| 550 | } |
| 551 | EXPORT_SYMBOL(ath10k_core_create); |
| 552 | |
| 553 | void ath10k_core_destroy(struct ath10k *ar) |
| 554 | { |
| 555 | flush_workqueue(ar->workqueue); |
| 556 | destroy_workqueue(ar->workqueue); |
| 557 | |
| 558 | ath10k_mac_destroy(ar); |
| 559 | } |
| 560 | EXPORT_SYMBOL(ath10k_core_destroy); |
| 561 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 562 | int ath10k_core_start(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 563 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 564 | int status; |
| 565 | |
Michal Kazior | 64d151d | 2013-07-16 09:38:53 +0200 | [diff] [blame] | 566 | ath10k_bmi_start(ar); |
| 567 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 568 | if (ath10k_init_configure_target(ar)) { |
| 569 | status = -EINVAL; |
| 570 | goto err; |
| 571 | } |
| 572 | |
| 573 | status = ath10k_init_download_firmware(ar); |
| 574 | if (status) |
| 575 | goto err; |
| 576 | |
| 577 | status = ath10k_init_uart(ar); |
| 578 | if (status) |
| 579 | goto err; |
| 580 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 581 | ar->htc.htc_ops.target_send_suspend_complete = |
| 582 | ath10k_send_suspend_complete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 583 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 584 | status = ath10k_htc_init(ar); |
| 585 | if (status) { |
| 586 | ath10k_err("could not init HTC (%d)\n", status); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 587 | goto err; |
| 588 | } |
| 589 | |
| 590 | status = ath10k_bmi_done(ar); |
| 591 | if (status) |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 592 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 593 | |
| 594 | status = ath10k_wmi_attach(ar); |
| 595 | if (status) { |
| 596 | ath10k_err("WMI attach failed: %d\n", status); |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 597 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 598 | } |
| 599 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 600 | status = ath10k_htc_wait_target(&ar->htc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 601 | if (status) |
| 602 | goto err_wmi_detach; |
| 603 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 604 | status = ath10k_htt_attach(ar); |
| 605 | if (status) { |
| 606 | ath10k_err("could not attach htt (%d)\n", status); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 607 | goto err_wmi_detach; |
| 608 | } |
| 609 | |
| 610 | status = ath10k_init_connect_htc(ar); |
| 611 | if (status) |
| 612 | goto err_htt_detach; |
| 613 | |
| 614 | ath10k_info("firmware %s booted\n", ar->hw->wiphy->fw_version); |
| 615 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 616 | status = ath10k_wmi_cmd_init(ar); |
| 617 | if (status) { |
| 618 | ath10k_err("could not send WMI init command (%d)\n", status); |
| 619 | goto err_disconnect_htc; |
| 620 | } |
| 621 | |
| 622 | status = ath10k_wmi_wait_for_unified_ready(ar); |
| 623 | if (status <= 0) { |
| 624 | ath10k_err("wmi unified ready event not received\n"); |
| 625 | status = -ETIMEDOUT; |
| 626 | goto err_disconnect_htc; |
| 627 | } |
| 628 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 629 | status = ath10k_htt_attach_target(&ar->htt); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 630 | if (status) |
| 631 | goto err_disconnect_htc; |
| 632 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 633 | status = ath10k_debug_start(ar); |
| 634 | if (status) |
| 635 | goto err_disconnect_htc; |
| 636 | |
Michal Kazior | 1a1b8a8 | 2013-07-16 09:38:55 +0200 | [diff] [blame] | 637 | ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1; |
| 638 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 639 | return 0; |
| 640 | |
| 641 | err_disconnect_htc: |
| 642 | ath10k_htc_stop(&ar->htc); |
| 643 | err_htt_detach: |
| 644 | ath10k_htt_detach(&ar->htt); |
| 645 | err_wmi_detach: |
| 646 | ath10k_wmi_detach(ar); |
| 647 | err: |
| 648 | return status; |
| 649 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 650 | EXPORT_SYMBOL(ath10k_core_start); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 651 | |
| 652 | void ath10k_core_stop(struct ath10k *ar) |
| 653 | { |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 654 | ath10k_debug_stop(ar); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 655 | ath10k_htc_stop(&ar->htc); |
| 656 | ath10k_htt_detach(&ar->htt); |
| 657 | ath10k_wmi_detach(ar); |
| 658 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 659 | EXPORT_SYMBOL(ath10k_core_stop); |
| 660 | |
| 661 | /* mac80211 manages fw/hw initialization through start/stop hooks. However in |
| 662 | * order to know what hw capabilities should be advertised to mac80211 it is |
| 663 | * necessary to load the firmware (and tear it down immediately since start |
| 664 | * hook will try to init it again) before registering */ |
| 665 | static int ath10k_core_probe_fw(struct ath10k *ar) |
| 666 | { |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 667 | struct bmi_target_info target_info; |
| 668 | int ret = 0; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 669 | |
| 670 | ret = ath10k_hif_power_up(ar); |
| 671 | if (ret) { |
| 672 | ath10k_err("could not start pci hif (%d)\n", ret); |
| 673 | return ret; |
| 674 | } |
| 675 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 676 | memset(&target_info, 0, sizeof(target_info)); |
| 677 | ret = ath10k_bmi_get_target_info(ar, &target_info); |
| 678 | if (ret) { |
| 679 | ath10k_err("could not get target info (%d)\n", ret); |
| 680 | ath10k_hif_power_down(ar); |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | ar->target_version = target_info.version; |
| 685 | ar->hw->wiphy->hw_version = target_info.version; |
| 686 | |
| 687 | ret = ath10k_init_hw_params(ar); |
| 688 | if (ret) { |
| 689 | ath10k_err("could not get hw params (%d)\n", ret); |
| 690 | ath10k_hif_power_down(ar); |
| 691 | return ret; |
| 692 | } |
| 693 | |
| 694 | ret = ath10k_core_fetch_firmware_files(ar); |
| 695 | if (ret) { |
| 696 | ath10k_err("could not fetch firmware files (%d)\n", ret); |
| 697 | ath10k_hif_power_down(ar); |
| 698 | return ret; |
| 699 | } |
| 700 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 701 | ret = ath10k_core_start(ar); |
| 702 | if (ret) { |
| 703 | ath10k_err("could not init core (%d)\n", ret); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 704 | ath10k_core_free_firmware_files(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 705 | ath10k_hif_power_down(ar); |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | ath10k_core_stop(ar); |
| 710 | ath10k_hif_power_down(ar); |
| 711 | return 0; |
| 712 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 713 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 714 | static int ath10k_core_check_chip_id(struct ath10k *ar) |
| 715 | { |
| 716 | u32 hw_revision = MS(ar->chip_id, SOC_CHIP_ID_REV); |
| 717 | |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 718 | ath10k_dbg(ATH10K_DBG_BOOT, "boot chip_id 0x%08x hw_revision 0x%x\n", |
| 719 | ar->chip_id, hw_revision); |
| 720 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 721 | /* Check that we are not using hw1.0 (some of them have same pci id |
| 722 | * as hw2.0) before doing anything else as ath10k crashes horribly |
| 723 | * due to missing hw1.0 workarounds. */ |
| 724 | switch (hw_revision) { |
| 725 | case QCA988X_HW_1_0_CHIP_ID_REV: |
| 726 | ath10k_err("ERROR: qca988x hw1.0 is not supported\n"); |
| 727 | return -EOPNOTSUPP; |
| 728 | |
| 729 | case QCA988X_HW_2_0_CHIP_ID_REV: |
| 730 | /* known hardware revision, continue normally */ |
| 731 | return 0; |
| 732 | |
| 733 | default: |
| 734 | ath10k_warn("Warning: hardware revision unknown (0x%x), expect problems\n", |
| 735 | ar->chip_id); |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | int ath10k_core_register(struct ath10k *ar, u32 chip_id) |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 743 | { |
| 744 | int status; |
| 745 | |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 746 | ar->chip_id = chip_id; |
| 747 | |
| 748 | status = ath10k_core_check_chip_id(ar); |
| 749 | if (status) { |
| 750 | ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id); |
| 751 | return status; |
| 752 | } |
| 753 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 754 | status = ath10k_core_probe_fw(ar); |
| 755 | if (status) { |
| 756 | ath10k_err("could not probe fw (%d)\n", status); |
| 757 | return status; |
| 758 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 759 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 760 | status = ath10k_mac_register(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 761 | if (status) { |
| 762 | ath10k_err("could not register to mac80211 (%d)\n", status); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 763 | goto err_release_fw; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 764 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 765 | |
| 766 | status = ath10k_debug_create(ar); |
| 767 | if (status) { |
| 768 | ath10k_err("unable to initialize debugfs\n"); |
| 769 | goto err_unregister_mac; |
| 770 | } |
| 771 | |
| 772 | return 0; |
| 773 | |
| 774 | err_unregister_mac: |
| 775 | ath10k_mac_unregister(ar); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 776 | err_release_fw: |
| 777 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 778 | return status; |
| 779 | } |
| 780 | EXPORT_SYMBOL(ath10k_core_register); |
| 781 | |
| 782 | void ath10k_core_unregister(struct ath10k *ar) |
| 783 | { |
| 784 | /* We must unregister from mac80211 before we stop HTC and HIF. |
| 785 | * Otherwise we will fail to submit commands to FW and mac80211 will be |
| 786 | * unhappy about callback failures. */ |
| 787 | ath10k_mac_unregister(ar); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 788 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 789 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 790 | } |
| 791 | EXPORT_SYMBOL(ath10k_core_unregister); |
| 792 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 793 | MODULE_AUTHOR("Qualcomm Atheros"); |
| 794 | MODULE_DESCRIPTION("Core module for QCA988X PCIe devices."); |
| 795 | MODULE_LICENSE("Dual BSD/GPL"); |