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> |
Toshi Kikuchi | 5aabff0 | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 20 | #include <linux/of.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 21 | |
| 22 | #include "core.h" |
| 23 | #include "mac.h" |
| 24 | #include "htc.h" |
| 25 | #include "hif.h" |
| 26 | #include "wmi.h" |
| 27 | #include "bmi.h" |
| 28 | #include "debug.h" |
| 29 | #include "htt.h" |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 30 | #include "testmode.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 31 | #include "wmi-ops.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 32 | |
| 33 | unsigned int ath10k_debug_mask; |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 34 | static unsigned int ath10k_cryptmode_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 35 | static bool uart_print; |
Rajkumar Manoharan | 8868b12 | 2014-11-17 16:44:14 +0200 | [diff] [blame] | 36 | static bool skip_otp; |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 37 | static bool rawmode; |
Rajkumar Manoharan | 8868b12 | 2014-11-17 16:44:14 +0200 | [diff] [blame] | 38 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 39 | module_param_named(debug_mask, ath10k_debug_mask, uint, 0644); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 40 | module_param_named(cryptmode, ath10k_cryptmode_param, uint, 0644); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 41 | module_param(uart_print, bool, 0644); |
Rajkumar Manoharan | 8868b12 | 2014-11-17 16:44:14 +0200 | [diff] [blame] | 42 | module_param(skip_otp, bool, 0644); |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 43 | module_param(rawmode, bool, 0644); |
Rajkumar Manoharan | 8868b12 | 2014-11-17 16:44:14 +0200 | [diff] [blame] | 44 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 45 | MODULE_PARM_DESC(debug_mask, "Debugging mask"); |
| 46 | MODULE_PARM_DESC(uart_print, "Uart target debugging"); |
Rajkumar Manoharan | 8868b12 | 2014-11-17 16:44:14 +0200 | [diff] [blame] | 47 | MODULE_PARM_DESC(skip_otp, "Skip otp failure for calibration in testmode"); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 48 | MODULE_PARM_DESC(cryptmode, "Crypto mode: 0-hardware, 1-software"); |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 49 | MODULE_PARM_DESC(rawmode, "Use raw 802.11 frame datapath"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 50 | |
| 51 | static const struct ath10k_hw_params ath10k_hw_params_list[] = { |
| 52 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 53 | .id = QCA988X_HW_2_0_VERSION, |
| 54 | .name = "qca988x hw2.0", |
| 55 | .patch_load_addr = QCA988X_HW_2_0_PATCH_LOAD_ADDR, |
Michal Kazior | 3a8200b | 2014-12-02 10:55:55 +0200 | [diff] [blame] | 56 | .uart_pin = 7, |
Michal Kazior | 587f703 | 2015-05-25 14:06:18 +0200 | [diff] [blame] | 57 | .has_shifted_cc_wraparound = true, |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 58 | .otp_exe_param = 0, |
Vasanthakumar Thiagarajan | 9c8fb54 | 2015-08-12 16:24:05 +0530 | [diff] [blame] | 59 | .channel_counters_freq_hz = 88000, |
Vivek Natarajan | 7b7da0a | 2015-08-31 16:34:55 +0530 | [diff] [blame] | 60 | .max_probe_resp_desc_thres = 0, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 61 | .fw = { |
| 62 | .dir = QCA988X_HW_2_0_FW_DIR, |
| 63 | .fw = QCA988X_HW_2_0_FW_FILE, |
| 64 | .otp = QCA988X_HW_2_0_OTP_FILE, |
| 65 | .board = QCA988X_HW_2_0_BOARD_DATA_FILE, |
Michal Kazior | 9764a2a | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 66 | .board_size = QCA988X_BOARD_DATA_SZ, |
| 67 | .board_ext_size = QCA988X_BOARD_EXT_DATA_SZ, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 68 | }, |
| 69 | }, |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 70 | { |
| 71 | .id = QCA6174_HW_2_1_VERSION, |
| 72 | .name = "qca6174 hw2.1", |
| 73 | .patch_load_addr = QCA6174_HW_2_1_PATCH_LOAD_ADDR, |
| 74 | .uart_pin = 6, |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 75 | .otp_exe_param = 0, |
Vasanthakumar Thiagarajan | 9c8fb54 | 2015-08-12 16:24:05 +0530 | [diff] [blame] | 76 | .channel_counters_freq_hz = 88000, |
Vivek Natarajan | 7b7da0a | 2015-08-31 16:34:55 +0530 | [diff] [blame] | 77 | .max_probe_resp_desc_thres = 0, |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 78 | .fw = { |
| 79 | .dir = QCA6174_HW_2_1_FW_DIR, |
| 80 | .fw = QCA6174_HW_2_1_FW_FILE, |
| 81 | .otp = QCA6174_HW_2_1_OTP_FILE, |
| 82 | .board = QCA6174_HW_2_1_BOARD_DATA_FILE, |
| 83 | .board_size = QCA6174_BOARD_DATA_SZ, |
| 84 | .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ, |
| 85 | }, |
| 86 | }, |
| 87 | { |
| 88 | .id = QCA6174_HW_3_0_VERSION, |
| 89 | .name = "qca6174 hw3.0", |
| 90 | .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR, |
| 91 | .uart_pin = 6, |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 92 | .otp_exe_param = 0, |
Vasanthakumar Thiagarajan | 9c8fb54 | 2015-08-12 16:24:05 +0530 | [diff] [blame] | 93 | .channel_counters_freq_hz = 88000, |
Vivek Natarajan | 7b7da0a | 2015-08-31 16:34:55 +0530 | [diff] [blame] | 94 | .max_probe_resp_desc_thres = 0, |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 95 | .fw = { |
| 96 | .dir = QCA6174_HW_3_0_FW_DIR, |
| 97 | .fw = QCA6174_HW_3_0_FW_FILE, |
| 98 | .otp = QCA6174_HW_3_0_OTP_FILE, |
| 99 | .board = QCA6174_HW_3_0_BOARD_DATA_FILE, |
| 100 | .board_size = QCA6174_BOARD_DATA_SZ, |
| 101 | .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ, |
| 102 | }, |
| 103 | }, |
Michal Kazior | 608b8f7 | 2015-01-29 13:24:33 +0100 | [diff] [blame] | 104 | { |
| 105 | .id = QCA6174_HW_3_2_VERSION, |
| 106 | .name = "qca6174 hw3.2", |
| 107 | .patch_load_addr = QCA6174_HW_3_0_PATCH_LOAD_ADDR, |
| 108 | .uart_pin = 6, |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 109 | .otp_exe_param = 0, |
Vasanthakumar Thiagarajan | 9c8fb54 | 2015-08-12 16:24:05 +0530 | [diff] [blame] | 110 | .channel_counters_freq_hz = 88000, |
Vivek Natarajan | 7b7da0a | 2015-08-31 16:34:55 +0530 | [diff] [blame] | 111 | .max_probe_resp_desc_thres = 0, |
Michal Kazior | 608b8f7 | 2015-01-29 13:24:33 +0100 | [diff] [blame] | 112 | .fw = { |
| 113 | /* uses same binaries as hw3.0 */ |
| 114 | .dir = QCA6174_HW_3_0_FW_DIR, |
| 115 | .fw = QCA6174_HW_3_0_FW_FILE, |
| 116 | .otp = QCA6174_HW_3_0_OTP_FILE, |
| 117 | .board = QCA6174_HW_3_0_BOARD_DATA_FILE, |
| 118 | .board_size = QCA6174_BOARD_DATA_SZ, |
| 119 | .board_ext_size = QCA6174_BOARD_EXT_DATA_SZ, |
| 120 | }, |
| 121 | }, |
Vasanthakumar Thiagarajan | 8bd4702 | 2015-06-18 12:31:03 +0530 | [diff] [blame] | 122 | { |
| 123 | .id = QCA99X0_HW_2_0_DEV_VERSION, |
| 124 | .name = "qca99x0 hw2.0", |
| 125 | .patch_load_addr = QCA99X0_HW_2_0_PATCH_LOAD_ADDR, |
| 126 | .uart_pin = 7, |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 127 | .otp_exe_param = 0x00000700, |
Raja Mani | d9156b5 | 2015-06-22 20:22:27 +0530 | [diff] [blame] | 128 | .continuous_frag_desc = true, |
Vasanthakumar Thiagarajan | 9c8fb54 | 2015-08-12 16:24:05 +0530 | [diff] [blame] | 129 | .channel_counters_freq_hz = 150000, |
Vivek Natarajan | 7b7da0a | 2015-08-31 16:34:55 +0530 | [diff] [blame] | 130 | .max_probe_resp_desc_thres = 24, |
Vasanthakumar Thiagarajan | 8bd4702 | 2015-06-18 12:31:03 +0530 | [diff] [blame] | 131 | .fw = { |
| 132 | .dir = QCA99X0_HW_2_0_FW_DIR, |
| 133 | .fw = QCA99X0_HW_2_0_FW_FILE, |
| 134 | .otp = QCA99X0_HW_2_0_OTP_FILE, |
| 135 | .board = QCA99X0_HW_2_0_BOARD_DATA_FILE, |
| 136 | .board_size = QCA99X0_BOARD_DATA_SZ, |
| 137 | .board_ext_size = QCA99X0_BOARD_EXT_DATA_SZ, |
| 138 | }, |
| 139 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 140 | }; |
| 141 | |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 142 | static const char *const ath10k_core_fw_feature_str[] = { |
| 143 | [ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX] = "wmi-mgmt-rx", |
| 144 | [ATH10K_FW_FEATURE_WMI_10X] = "wmi-10.x", |
| 145 | [ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX] = "has-wmi-mgmt-tx", |
| 146 | [ATH10K_FW_FEATURE_NO_P2P] = "no-p2p", |
| 147 | [ATH10K_FW_FEATURE_WMI_10_2] = "wmi-10.2", |
| 148 | [ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT] = "multi-vif-ps", |
| 149 | [ATH10K_FW_FEATURE_WOWLAN_SUPPORT] = "wowlan", |
| 150 | [ATH10K_FW_FEATURE_IGNORE_OTP_RESULT] = "ignore-otp", |
| 151 | [ATH10K_FW_FEATURE_NO_NWIFI_DECAP_4ADDR_PADDING] = "no-4addr-pad", |
| 152 | [ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT] = "skip-clock-init", |
Kalle Valo | 5af82fa | 2015-09-09 11:34:37 +0300 | [diff] [blame] | 153 | [ATH10K_FW_FEATURE_RAW_MODE_SUPPORT] = "raw-mode", |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | static unsigned int ath10k_core_get_fw_feature_str(char *buf, |
| 157 | size_t buf_len, |
| 158 | enum ath10k_fw_features feat) |
| 159 | { |
Kalle Valo | 5af82fa | 2015-09-09 11:34:37 +0300 | [diff] [blame] | 160 | /* make sure that ath10k_core_fw_feature_str[] gets updated */ |
| 161 | BUILD_BUG_ON(ARRAY_SIZE(ath10k_core_fw_feature_str) != |
| 162 | ATH10K_FW_FEATURE_COUNT); |
| 163 | |
Michal Kazior | b27bc5a | 2015-06-15 14:46:40 +0300 | [diff] [blame] | 164 | if (feat >= ARRAY_SIZE(ath10k_core_fw_feature_str) || |
| 165 | WARN_ON(!ath10k_core_fw_feature_str[feat])) { |
| 166 | return scnprintf(buf, buf_len, "bit%d", feat); |
| 167 | } |
| 168 | |
| 169 | return scnprintf(buf, buf_len, "%s", ath10k_core_fw_feature_str[feat]); |
| 170 | } |
| 171 | |
| 172 | void ath10k_core_get_fw_features_str(struct ath10k *ar, |
| 173 | char *buf, |
| 174 | size_t buf_len) |
| 175 | { |
| 176 | unsigned int len = 0; |
| 177 | int i; |
| 178 | |
| 179 | for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) { |
| 180 | if (test_bit(i, ar->fw_features)) { |
| 181 | if (len > 0) |
| 182 | len += scnprintf(buf + len, buf_len - len, ","); |
| 183 | |
| 184 | len += ath10k_core_get_fw_feature_str(buf + len, |
| 185 | buf_len - len, |
| 186 | i); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 191 | static void ath10k_send_suspend_complete(struct ath10k *ar) |
| 192 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 193 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot suspend complete\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 194 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 195 | complete(&ar->target_suspend); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 196 | } |
| 197 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 198 | static int ath10k_init_configure_target(struct ath10k *ar) |
| 199 | { |
| 200 | u32 param_host; |
| 201 | int ret; |
| 202 | |
| 203 | /* tell target which HTC version it is used*/ |
| 204 | ret = ath10k_bmi_write32(ar, hi_app_host_interest, |
| 205 | HTC_PROTOCOL_VERSION); |
| 206 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 207 | ath10k_err(ar, "settings HTC version failed\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | /* set the firmware mode to STA/IBSS/AP */ |
| 212 | ret = ath10k_bmi_read32(ar, hi_option_flag, ¶m_host); |
| 213 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 214 | ath10k_err(ar, "setting firmware mode (1/2) failed\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | /* TODO following parameters need to be re-visited. */ |
| 219 | /* num_device */ |
| 220 | param_host |= (1 << HI_OPTION_NUM_DEV_SHIFT); |
| 221 | /* Firmware mode */ |
| 222 | /* FIXME: Why FW_MODE_AP ??.*/ |
| 223 | param_host |= (HI_OPTION_FW_MODE_AP << HI_OPTION_FW_MODE_SHIFT); |
| 224 | /* mac_addr_method */ |
| 225 | param_host |= (1 << HI_OPTION_MAC_ADDR_METHOD_SHIFT); |
| 226 | /* firmware_bridge */ |
| 227 | param_host |= (0 << HI_OPTION_FW_BRIDGE_SHIFT); |
| 228 | /* fwsubmode */ |
| 229 | param_host |= (0 << HI_OPTION_FW_SUBMODE_SHIFT); |
| 230 | |
| 231 | ret = ath10k_bmi_write32(ar, hi_option_flag, param_host); |
| 232 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 233 | ath10k_err(ar, "setting firmware mode (2/2) failed\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | /* We do all byte-swapping on the host */ |
| 238 | ret = ath10k_bmi_write32(ar, hi_be, 0); |
| 239 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 240 | ath10k_err(ar, "setting host CPU BE mode failed\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | /* FW descriptor/Data swap flags */ |
| 245 | ret = ath10k_bmi_write32(ar, hi_fw_swap, 0); |
| 246 | |
| 247 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 248 | ath10k_err(ar, "setting FW data/desc swap flags failed\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 249 | return ret; |
| 250 | } |
| 251 | |
Michal Kazior | 36582e5 | 2015-08-13 14:32:26 +0200 | [diff] [blame] | 252 | /* Some devices have a special sanity check that verifies the PCI |
| 253 | * Device ID is written to this host interest var. It is known to be |
| 254 | * required to boot QCA6164. |
| 255 | */ |
| 256 | ret = ath10k_bmi_write32(ar, hi_hci_uart_pwr_mgmt_params_ext, |
| 257 | ar->dev_id); |
| 258 | if (ret) { |
| 259 | ath10k_err(ar, "failed to set pwr_mgmt_params: %d\n", ret); |
| 260 | return ret; |
| 261 | } |
| 262 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static const struct firmware *ath10k_fetch_fw_file(struct ath10k *ar, |
| 267 | const char *dir, |
| 268 | const char *file) |
| 269 | { |
| 270 | char filename[100]; |
| 271 | const struct firmware *fw; |
| 272 | int ret; |
| 273 | |
| 274 | if (file == NULL) |
| 275 | return ERR_PTR(-ENOENT); |
| 276 | |
| 277 | if (dir == NULL) |
| 278 | dir = "."; |
| 279 | |
| 280 | snprintf(filename, sizeof(filename), "%s/%s", dir, file); |
| 281 | ret = request_firmware(&fw, filename, ar->dev); |
| 282 | if (ret) |
| 283 | return ERR_PTR(ret); |
| 284 | |
| 285 | return fw; |
| 286 | } |
| 287 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 288 | static int ath10k_push_board_ext_data(struct ath10k *ar, const void *data, |
| 289 | size_t data_len) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 290 | { |
Michal Kazior | 9764a2a | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 291 | u32 board_data_size = ar->hw_params.fw.board_size; |
| 292 | u32 board_ext_data_size = ar->hw_params.fw.board_ext_size; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 293 | u32 board_ext_data_addr; |
| 294 | int ret; |
| 295 | |
| 296 | ret = ath10k_bmi_read32(ar, hi_board_ext_data, &board_ext_data_addr); |
| 297 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 298 | ath10k_err(ar, "could not read board ext data addr (%d)\n", |
| 299 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 300 | return ret; |
| 301 | } |
| 302 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 303 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Kalle Valo | effea96 | 2013-09-08 17:55:44 +0300 | [diff] [blame] | 304 | "boot push board extended data addr 0x%x\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 305 | board_ext_data_addr); |
| 306 | |
| 307 | if (board_ext_data_addr == 0) |
| 308 | return 0; |
| 309 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 310 | if (data_len != (board_data_size + board_ext_data_size)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 311 | ath10k_err(ar, "invalid board (ext) data sizes %zu != %d+%d\n", |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 312 | data_len, board_data_size, board_ext_data_size); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 313 | return -EINVAL; |
| 314 | } |
| 315 | |
| 316 | ret = ath10k_bmi_write_memory(ar, board_ext_data_addr, |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 317 | data + board_data_size, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 318 | board_ext_data_size); |
| 319 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 320 | ath10k_err(ar, "could not write board ext data (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | ret = ath10k_bmi_write32(ar, hi_board_ext_data_config, |
| 325 | (board_ext_data_size << 16) | 1); |
| 326 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 327 | ath10k_err(ar, "could not write board ext data bit (%d)\n", |
| 328 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 329 | return ret; |
| 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 335 | static int ath10k_download_board_data(struct ath10k *ar, const void *data, |
| 336 | size_t data_len) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 337 | { |
Michal Kazior | 9764a2a | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 338 | u32 board_data_size = ar->hw_params.fw.board_size; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 339 | u32 address; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 340 | int ret; |
| 341 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 342 | ret = ath10k_push_board_ext_data(ar, data, data_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 343 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 344 | ath10k_err(ar, "could not push board ext data (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 345 | goto exit; |
| 346 | } |
| 347 | |
| 348 | ret = ath10k_bmi_read32(ar, hi_board_data, &address); |
| 349 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 350 | ath10k_err(ar, "could not read board data addr (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 351 | goto exit; |
| 352 | } |
| 353 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 354 | ret = ath10k_bmi_write_memory(ar, address, data, |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 355 | min_t(u32, board_data_size, |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 356 | data_len)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 357 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 358 | ath10k_err(ar, "could not write board data (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 359 | goto exit; |
| 360 | } |
| 361 | |
| 362 | ret = ath10k_bmi_write32(ar, hi_board_data_initialized, 1); |
| 363 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 364 | ath10k_err(ar, "could not write board data bit (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 365 | goto exit; |
| 366 | } |
| 367 | |
| 368 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 369 | return ret; |
| 370 | } |
| 371 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 372 | static int ath10k_download_cal_file(struct ath10k *ar) |
| 373 | { |
| 374 | int ret; |
| 375 | |
| 376 | if (!ar->cal_file) |
| 377 | return -ENOENT; |
| 378 | |
| 379 | if (IS_ERR(ar->cal_file)) |
| 380 | return PTR_ERR(ar->cal_file); |
| 381 | |
| 382 | ret = ath10k_download_board_data(ar, ar->cal_file->data, |
| 383 | ar->cal_file->size); |
| 384 | if (ret) { |
| 385 | ath10k_err(ar, "failed to download cal_file data: %d\n", ret); |
| 386 | return ret; |
| 387 | } |
| 388 | |
| 389 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n"); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
Toshi Kikuchi | 5aabff0 | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 394 | static int ath10k_download_cal_dt(struct ath10k *ar) |
| 395 | { |
| 396 | struct device_node *node; |
| 397 | int data_len; |
| 398 | void *data; |
| 399 | int ret; |
| 400 | |
| 401 | node = ar->dev->of_node; |
| 402 | if (!node) |
| 403 | /* Device Tree is optional, don't print any warnings if |
| 404 | * there's no node for ath10k. |
| 405 | */ |
| 406 | return -ENOENT; |
| 407 | |
| 408 | if (!of_get_property(node, "qcom,ath10k-calibration-data", |
| 409 | &data_len)) { |
| 410 | /* The calibration data node is optional */ |
| 411 | return -ENOENT; |
| 412 | } |
| 413 | |
| 414 | if (data_len != QCA988X_CAL_DATA_LEN) { |
| 415 | ath10k_warn(ar, "invalid calibration data length in DT: %d\n", |
| 416 | data_len); |
| 417 | ret = -EMSGSIZE; |
| 418 | goto out; |
| 419 | } |
| 420 | |
| 421 | data = kmalloc(data_len, GFP_KERNEL); |
| 422 | if (!data) { |
| 423 | ret = -ENOMEM; |
| 424 | goto out; |
| 425 | } |
| 426 | |
| 427 | ret = of_property_read_u8_array(node, "qcom,ath10k-calibration-data", |
| 428 | data, data_len); |
| 429 | if (ret) { |
| 430 | ath10k_warn(ar, "failed to read calibration data from DT: %d\n", |
| 431 | ret); |
| 432 | goto out_free; |
| 433 | } |
| 434 | |
| 435 | ret = ath10k_download_board_data(ar, data, data_len); |
| 436 | if (ret) { |
| 437 | ath10k_warn(ar, "failed to download calibration data from Device Tree: %d\n", |
| 438 | ret); |
| 439 | goto out_free; |
| 440 | } |
| 441 | |
| 442 | ret = 0; |
| 443 | |
| 444 | out_free: |
| 445 | kfree(data); |
| 446 | |
| 447 | out: |
| 448 | return ret; |
| 449 | } |
| 450 | |
Manikanta Pubbisetty | db0984e | 2015-10-09 11:55:59 +0300 | [diff] [blame] | 451 | static int ath10k_core_get_board_id_from_otp(struct ath10k *ar) |
| 452 | { |
| 453 | u32 result, address; |
| 454 | u8 board_id, chip_id; |
| 455 | int ret; |
| 456 | |
| 457 | address = ar->hw_params.patch_load_addr; |
| 458 | |
| 459 | if (!ar->otp_data || !ar->otp_len) { |
| 460 | ath10k_warn(ar, |
| 461 | "failed to retrieve board id because of invalid otp\n"); |
| 462 | return -ENODATA; |
| 463 | } |
| 464 | |
| 465 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 466 | "boot upload otp to 0x%x len %zd for board id\n", |
| 467 | address, ar->otp_len); |
| 468 | |
| 469 | ret = ath10k_bmi_fast_download(ar, address, ar->otp_data, ar->otp_len); |
| 470 | if (ret) { |
| 471 | ath10k_err(ar, "could not write otp for board id check: %d\n", |
| 472 | ret); |
| 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | ret = ath10k_bmi_execute(ar, address, BMI_PARAM_GET_EEPROM_BOARD_ID, |
| 477 | &result); |
| 478 | if (ret) { |
| 479 | ath10k_err(ar, "could not execute otp for board id check: %d\n", |
| 480 | ret); |
| 481 | return ret; |
| 482 | } |
| 483 | |
| 484 | board_id = MS(result, ATH10K_BMI_BOARD_ID_FROM_OTP); |
| 485 | chip_id = MS(result, ATH10K_BMI_CHIP_ID_FROM_OTP); |
| 486 | |
| 487 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 488 | "boot get otp board id result 0x%08x board_id %d chip_id %d\n", |
| 489 | result, board_id, chip_id); |
| 490 | |
| 491 | if ((result & ATH10K_BMI_BOARD_ID_STATUS_MASK) != 0) |
| 492 | return -EOPNOTSUPP; |
| 493 | |
| 494 | ar->id.bmi_ids_valid = true; |
| 495 | ar->id.bmi_board_id = board_id; |
| 496 | ar->id.bmi_chip_id = chip_id; |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 501 | static int ath10k_download_and_run_otp(struct ath10k *ar) |
| 502 | { |
Kalle Valo | d6d4a58 | 2014-03-11 17:33:19 +0200 | [diff] [blame] | 503 | u32 result, address = ar->hw_params.patch_load_addr; |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 504 | u32 bmi_otp_exe_param = ar->hw_params.otp_exe_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 505 | int ret; |
| 506 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 507 | ret = ath10k_download_board_data(ar, ar->board_data, ar->board_len); |
Kalle Valo | 8309155 | 2014-10-13 09:40:53 +0300 | [diff] [blame] | 508 | if (ret) { |
| 509 | ath10k_err(ar, "failed to download board data: %d\n", ret); |
| 510 | return ret; |
| 511 | } |
| 512 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 513 | /* OTP is optional */ |
| 514 | |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 515 | if (!ar->otp_data || !ar->otp_len) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 516 | ath10k_warn(ar, "Not running otp, calibration will be incorrect (otp-data %p otp_len %zd)!\n", |
Ben Greear | 36a8f41 | 2014-03-24 12:20:42 -0700 | [diff] [blame] | 517 | ar->otp_data, ar->otp_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 518 | return 0; |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 521 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot upload otp to 0x%x len %zd\n", |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 522 | address, ar->otp_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 523 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 524 | 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] | 525 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 526 | ath10k_err(ar, "could not write otp (%d)\n", ret); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 527 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 528 | } |
| 529 | |
Vasanthakumar Thiagarajan | d772703 | 2015-06-18 12:31:10 +0530 | [diff] [blame] | 530 | ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 531 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 532 | ath10k_err(ar, "could not execute otp (%d)\n", ret); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 533 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 534 | } |
| 535 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 536 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot otp execute result %d\n", result); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 537 | |
Kalle Valo | d915354 | 2015-04-28 20:19:30 +0300 | [diff] [blame] | 538 | if (!(skip_otp || test_bit(ATH10K_FW_FEATURE_IGNORE_OTP_RESULT, |
Kalle Valo | be62e92 | 2015-10-05 17:56:34 +0300 | [diff] [blame] | 539 | ar->fw_features)) && |
| 540 | result != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 541 | ath10k_err(ar, "otp calibration failed: %d", result); |
Kalle Valo | 7f06ea1 | 2014-03-11 17:33:28 +0200 | [diff] [blame] | 542 | return -EINVAL; |
| 543 | } |
| 544 | |
| 545 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 546 | } |
| 547 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 548 | static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 549 | { |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 550 | u32 address, data_len; |
| 551 | const char *mode_name; |
| 552 | const void *data; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 553 | int ret; |
| 554 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 555 | address = ar->hw_params.patch_load_addr; |
| 556 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 557 | switch (mode) { |
| 558 | case ATH10K_FIRMWARE_MODE_NORMAL: |
| 559 | data = ar->firmware_data; |
| 560 | data_len = ar->firmware_len; |
| 561 | mode_name = "normal"; |
Vasanthakumar Thiagarajan | dcb02db | 2015-06-18 12:31:09 +0530 | [diff] [blame] | 562 | ret = ath10k_swap_code_seg_configure(ar, |
Kalle Valo | 617b0f4 | 2015-10-05 17:56:35 +0300 | [diff] [blame] | 563 | ATH10K_SWAP_CODE_SEG_BIN_TYPE_FW); |
Vasanthakumar Thiagarajan | dcb02db | 2015-06-18 12:31:09 +0530 | [diff] [blame] | 564 | if (ret) { |
| 565 | ath10k_err(ar, "failed to configure fw code swap: %d\n", |
| 566 | ret); |
| 567 | return ret; |
| 568 | } |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 569 | break; |
| 570 | case ATH10K_FIRMWARE_MODE_UTF: |
| 571 | data = ar->testmode.utf->data; |
| 572 | data_len = ar->testmode.utf->size; |
| 573 | mode_name = "utf"; |
| 574 | break; |
| 575 | default: |
| 576 | ath10k_err(ar, "unknown firmware mode: %d\n", mode); |
| 577 | return -EINVAL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 578 | } |
| 579 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 580 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 581 | "boot uploading firmware image %p len %d mode %s\n", |
| 582 | data, data_len, mode_name); |
| 583 | |
| 584 | ret = ath10k_bmi_fast_download(ar, address, data, data_len); |
| 585 | if (ret) { |
| 586 | ath10k_err(ar, "failed to download %s firmware: %d\n", |
| 587 | mode_name, ret); |
| 588 | return ret; |
| 589 | } |
| 590 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 591 | return ret; |
| 592 | } |
| 593 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 594 | static void ath10k_core_free_board_files(struct ath10k *ar) |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 595 | { |
Markus Elfring | db2cf86 | 2015-02-04 19:30:23 +0100 | [diff] [blame] | 596 | if (!IS_ERR(ar->board)) |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 597 | release_firmware(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 598 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 599 | ar->board = NULL; |
| 600 | ar->board_data = NULL; |
| 601 | ar->board_len = 0; |
| 602 | } |
| 603 | |
| 604 | static void ath10k_core_free_firmware_files(struct ath10k *ar) |
| 605 | { |
Markus Elfring | db2cf86 | 2015-02-04 19:30:23 +0100 | [diff] [blame] | 606 | if (!IS_ERR(ar->otp)) |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 607 | release_firmware(ar->otp); |
| 608 | |
Markus Elfring | db2cf86 | 2015-02-04 19:30:23 +0100 | [diff] [blame] | 609 | if (!IS_ERR(ar->firmware)) |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 610 | release_firmware(ar->firmware); |
| 611 | |
Markus Elfring | db2cf86 | 2015-02-04 19:30:23 +0100 | [diff] [blame] | 612 | if (!IS_ERR(ar->cal_file)) |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 613 | release_firmware(ar->cal_file); |
| 614 | |
Vasanthakumar Thiagarajan | dcb02db | 2015-06-18 12:31:09 +0530 | [diff] [blame] | 615 | ath10k_swap_code_seg_release(ar); |
| 616 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 617 | ar->otp = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 618 | ar->otp_data = NULL; |
| 619 | ar->otp_len = 0; |
| 620 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 621 | ar->firmware = NULL; |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 622 | ar->firmware_data = NULL; |
| 623 | ar->firmware_len = 0; |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 624 | |
| 625 | ar->cal_file = NULL; |
| 626 | } |
| 627 | |
| 628 | static int ath10k_fetch_cal_file(struct ath10k *ar) |
| 629 | { |
| 630 | char filename[100]; |
| 631 | |
| 632 | /* cal-<bus>-<id>.bin */ |
| 633 | scnprintf(filename, sizeof(filename), "cal-%s-%s.bin", |
| 634 | ath10k_bus_str(ar->hif.bus), dev_name(ar->dev)); |
| 635 | |
| 636 | ar->cal_file = ath10k_fetch_fw_file(ar, ATH10K_FW_DIR, filename); |
| 637 | if (IS_ERR(ar->cal_file)) |
| 638 | /* calibration file is optional, don't print any warnings */ |
| 639 | return PTR_ERR(ar->cal_file); |
| 640 | |
| 641 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "found calibration file %s/%s\n", |
| 642 | ATH10K_FW_DIR, filename); |
| 643 | |
| 644 | return 0; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 647 | static int ath10k_core_fetch_board_data_api_1(struct ath10k *ar) |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 648 | { |
Michal Kazior | d0ed74f | 2015-04-17 09:19:16 +0000 | [diff] [blame] | 649 | if (!ar->hw_params.fw.board) { |
| 650 | ath10k_err(ar, "failed to find board file fw entry\n"); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 651 | return -EINVAL; |
| 652 | } |
| 653 | |
Kalle Valo | 3652791 | 2013-09-27 19:54:55 +0300 | [diff] [blame] | 654 | ar->board = ath10k_fetch_fw_file(ar, |
| 655 | ar->hw_params.fw.dir, |
| 656 | ar->hw_params.fw.board); |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 657 | if (IS_ERR(ar->board)) |
| 658 | return PTR_ERR(ar->board); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 659 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 660 | ar->board_data = ar->board->data; |
| 661 | ar->board_len = ar->board->size; |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int ath10k_core_parse_bd_ie_board(struct ath10k *ar, |
| 667 | const void *buf, size_t buf_len, |
| 668 | const char *boardname) |
| 669 | { |
| 670 | const struct ath10k_fw_ie *hdr; |
| 671 | bool name_match_found; |
| 672 | int ret, board_ie_id; |
| 673 | size_t board_ie_len; |
| 674 | const void *board_ie_data; |
| 675 | |
| 676 | name_match_found = false; |
| 677 | |
| 678 | /* go through ATH10K_BD_IE_BOARD_ elements */ |
| 679 | while (buf_len > sizeof(struct ath10k_fw_ie)) { |
| 680 | hdr = buf; |
| 681 | board_ie_id = le32_to_cpu(hdr->id); |
| 682 | board_ie_len = le32_to_cpu(hdr->len); |
| 683 | board_ie_data = hdr->data; |
| 684 | |
| 685 | buf_len -= sizeof(*hdr); |
| 686 | buf += sizeof(*hdr); |
| 687 | |
| 688 | if (buf_len < ALIGN(board_ie_len, 4)) { |
| 689 | ath10k_err(ar, "invalid ATH10K_BD_IE_BOARD length: %zu < %zu\n", |
| 690 | buf_len, ALIGN(board_ie_len, 4)); |
| 691 | ret = -EINVAL; |
| 692 | goto out; |
| 693 | } |
| 694 | |
| 695 | switch (board_ie_id) { |
| 696 | case ATH10K_BD_IE_BOARD_NAME: |
| 697 | ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "board name", "", |
| 698 | board_ie_data, board_ie_len); |
| 699 | |
| 700 | if (board_ie_len != strlen(boardname)) |
| 701 | break; |
| 702 | |
| 703 | ret = memcmp(board_ie_data, boardname, strlen(boardname)); |
| 704 | if (ret) |
| 705 | break; |
| 706 | |
| 707 | name_match_found = true; |
| 708 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 709 | "boot found match for name '%s'", |
| 710 | boardname); |
| 711 | break; |
| 712 | case ATH10K_BD_IE_BOARD_DATA: |
| 713 | if (!name_match_found) |
| 714 | /* no match found */ |
| 715 | break; |
| 716 | |
| 717 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 718 | "boot found board data for '%s'", |
| 719 | boardname); |
| 720 | |
| 721 | ar->board_data = board_ie_data; |
| 722 | ar->board_len = board_ie_len; |
| 723 | |
| 724 | ret = 0; |
| 725 | goto out; |
| 726 | default: |
| 727 | ath10k_warn(ar, "unknown ATH10K_BD_IE_BOARD found: %d\n", |
| 728 | board_ie_id); |
| 729 | break; |
| 730 | } |
| 731 | |
| 732 | /* jump over the padding */ |
| 733 | board_ie_len = ALIGN(board_ie_len, 4); |
| 734 | |
| 735 | buf_len -= board_ie_len; |
| 736 | buf += board_ie_len; |
| 737 | } |
| 738 | |
| 739 | /* no match found */ |
| 740 | ret = -ENOENT; |
| 741 | |
| 742 | out: |
| 743 | return ret; |
| 744 | } |
| 745 | |
| 746 | static int ath10k_core_fetch_board_data_api_n(struct ath10k *ar, |
| 747 | const char *boardname, |
| 748 | const char *filename) |
| 749 | { |
| 750 | size_t len, magic_len, ie_len; |
| 751 | struct ath10k_fw_ie *hdr; |
| 752 | const u8 *data; |
| 753 | int ret, ie_id; |
| 754 | |
| 755 | ar->board = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, filename); |
| 756 | if (IS_ERR(ar->board)) |
| 757 | return PTR_ERR(ar->board); |
| 758 | |
| 759 | data = ar->board->data; |
| 760 | len = ar->board->size; |
| 761 | |
| 762 | /* magic has extra null byte padded */ |
| 763 | magic_len = strlen(ATH10K_BOARD_MAGIC) + 1; |
| 764 | if (len < magic_len) { |
| 765 | ath10k_err(ar, "failed to find magic value in %s/%s, file too short: %zu\n", |
| 766 | ar->hw_params.fw.dir, filename, len); |
| 767 | ret = -EINVAL; |
| 768 | goto err; |
| 769 | } |
| 770 | |
| 771 | if (memcmp(data, ATH10K_BOARD_MAGIC, magic_len)) { |
| 772 | ath10k_err(ar, "found invalid board magic\n"); |
| 773 | ret = -EINVAL; |
| 774 | goto err; |
| 775 | } |
| 776 | |
| 777 | /* magic is padded to 4 bytes */ |
| 778 | magic_len = ALIGN(magic_len, 4); |
| 779 | if (len < magic_len) { |
| 780 | ath10k_err(ar, "failed: %s/%s too small to contain board data, len: %zu\n", |
| 781 | ar->hw_params.fw.dir, filename, len); |
| 782 | ret = -EINVAL; |
| 783 | goto err; |
| 784 | } |
| 785 | |
| 786 | data += magic_len; |
| 787 | len -= magic_len; |
| 788 | |
| 789 | while (len > sizeof(struct ath10k_fw_ie)) { |
| 790 | hdr = (struct ath10k_fw_ie *)data; |
| 791 | ie_id = le32_to_cpu(hdr->id); |
| 792 | ie_len = le32_to_cpu(hdr->len); |
| 793 | |
| 794 | len -= sizeof(*hdr); |
| 795 | data = hdr->data; |
| 796 | |
| 797 | if (len < ALIGN(ie_len, 4)) { |
| 798 | ath10k_err(ar, "invalid length for board ie_id %d ie_len %zu len %zu\n", |
| 799 | ie_id, ie_len, len); |
| 800 | ret = -EINVAL; |
| 801 | goto err; |
| 802 | } |
| 803 | |
| 804 | switch (ie_id) { |
| 805 | case ATH10K_BD_IE_BOARD: |
| 806 | ret = ath10k_core_parse_bd_ie_board(ar, data, ie_len, |
| 807 | boardname); |
| 808 | if (ret == -ENOENT) |
| 809 | /* no match found, continue */ |
| 810 | break; |
| 811 | else if (ret) |
| 812 | /* there was an error, bail out */ |
| 813 | goto err; |
| 814 | |
| 815 | /* board data found */ |
| 816 | goto out; |
| 817 | } |
| 818 | |
| 819 | /* jump over the padding */ |
| 820 | ie_len = ALIGN(ie_len, 4); |
| 821 | |
| 822 | len -= ie_len; |
| 823 | data += ie_len; |
| 824 | } |
| 825 | |
| 826 | out: |
| 827 | if (!ar->board_data || !ar->board_len) { |
| 828 | ath10k_err(ar, |
| 829 | "failed to fetch board data for %s from %s/%s\n", |
| 830 | ar->hw_params.fw.dir, boardname, filename); |
| 831 | ret = -ENODATA; |
| 832 | goto err; |
| 833 | } |
| 834 | |
| 835 | return 0; |
| 836 | |
| 837 | err: |
| 838 | ath10k_core_free_board_files(ar); |
| 839 | return ret; |
| 840 | } |
| 841 | |
| 842 | static int ath10k_core_create_board_name(struct ath10k *ar, char *name, |
| 843 | size_t name_len) |
| 844 | { |
Manikanta Pubbisetty | db0984e | 2015-10-09 11:55:59 +0300 | [diff] [blame] | 845 | if (ar->id.bmi_ids_valid) { |
| 846 | scnprintf(name, name_len, |
| 847 | "bus=%s,bmi-chip-id=%d,bmi-board-id=%d", |
| 848 | ath10k_bus_str(ar->hif.bus), |
| 849 | ar->id.bmi_chip_id, |
| 850 | ar->id.bmi_board_id); |
| 851 | goto out; |
| 852 | } |
| 853 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 854 | scnprintf(name, name_len, |
| 855 | "bus=%s,vendor=%04x,device=%04x,subsystem-vendor=%04x,subsystem-device=%04x", |
| 856 | ath10k_bus_str(ar->hif.bus), |
| 857 | ar->id.vendor, ar->id.device, |
| 858 | ar->id.subsystem_vendor, ar->id.subsystem_device); |
| 859 | |
Manikanta Pubbisetty | db0984e | 2015-10-09 11:55:59 +0300 | [diff] [blame] | 860 | out: |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 861 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using board name '%s'\n", name); |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static int ath10k_core_fetch_board_file(struct ath10k *ar) |
| 867 | { |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 868 | char boardname[100]; |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 869 | int ret; |
| 870 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 871 | ret = ath10k_core_create_board_name(ar, boardname, sizeof(boardname)); |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 872 | if (ret) { |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 873 | ath10k_err(ar, "failed to create board name: %d", ret); |
Michal Kazior | de57e2c | 2015-04-17 09:19:17 +0000 | [diff] [blame] | 874 | return ret; |
| 875 | } |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 876 | |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 877 | ar->bd_api = 2; |
| 878 | ret = ath10k_core_fetch_board_data_api_n(ar, boardname, |
| 879 | ATH10K_BOARD_API2_FILE); |
| 880 | if (!ret) |
| 881 | goto success; |
| 882 | |
| 883 | ar->bd_api = 1; |
| 884 | ret = ath10k_core_fetch_board_data_api_1(ar); |
| 885 | if (ret) { |
| 886 | ath10k_err(ar, "failed to fetch board data\n"); |
| 887 | return ret; |
| 888 | } |
| 889 | |
| 890 | success: |
| 891 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "using board api %d\n", ar->bd_api); |
Michal Kazior | d0ed74f | 2015-04-17 09:19:16 +0000 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | static int ath10k_core_fetch_firmware_api_1(struct ath10k *ar) |
| 896 | { |
| 897 | int ret = 0; |
| 898 | |
| 899 | if (ar->hw_params.fw.fw == NULL) { |
| 900 | ath10k_err(ar, "firmware file not defined\n"); |
| 901 | return -EINVAL; |
| 902 | } |
| 903 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 904 | ar->firmware = ath10k_fetch_fw_file(ar, |
| 905 | ar->hw_params.fw.dir, |
| 906 | ar->hw_params.fw.fw); |
| 907 | if (IS_ERR(ar->firmware)) { |
| 908 | ret = PTR_ERR(ar->firmware); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 909 | ath10k_err(ar, "could not fetch firmware (%d)\n", ret); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 910 | goto err; |
| 911 | } |
| 912 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 913 | ar->firmware_data = ar->firmware->data; |
| 914 | ar->firmware_len = ar->firmware->size; |
| 915 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 916 | /* OTP may be undefined. If so, don't fetch it at all */ |
| 917 | if (ar->hw_params.fw.otp == NULL) |
| 918 | return 0; |
| 919 | |
| 920 | ar->otp = ath10k_fetch_fw_file(ar, |
| 921 | ar->hw_params.fw.dir, |
| 922 | ar->hw_params.fw.otp); |
| 923 | if (IS_ERR(ar->otp)) { |
| 924 | ret = PTR_ERR(ar->otp); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 925 | ath10k_err(ar, "could not fetch otp (%d)\n", ret); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 926 | goto err; |
| 927 | } |
| 928 | |
Kalle Valo | 958df3a | 2013-09-27 19:55:01 +0300 | [diff] [blame] | 929 | ar->otp_data = ar->otp->data; |
| 930 | ar->otp_len = ar->otp->size; |
| 931 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 932 | return 0; |
| 933 | |
| 934 | err: |
| 935 | ath10k_core_free_firmware_files(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 936 | return ret; |
| 937 | } |
| 938 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 939 | static int ath10k_core_fetch_firmware_api_n(struct ath10k *ar, const char *name) |
| 940 | { |
| 941 | size_t magic_len, len, ie_len; |
| 942 | int ie_id, i, index, bit, ret; |
| 943 | struct ath10k_fw_ie *hdr; |
| 944 | const u8 *data; |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 945 | __le32 *timestamp, *version; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 946 | |
| 947 | /* first fetch the firmware file (firmware-*.bin) */ |
| 948 | ar->firmware = ath10k_fetch_fw_file(ar, ar->hw_params.fw.dir, name); |
| 949 | if (IS_ERR(ar->firmware)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 950 | ath10k_err(ar, "could not fetch firmware file '%s/%s': %ld\n", |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 951 | ar->hw_params.fw.dir, name, PTR_ERR(ar->firmware)); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 952 | return PTR_ERR(ar->firmware); |
| 953 | } |
| 954 | |
| 955 | data = ar->firmware->data; |
| 956 | len = ar->firmware->size; |
| 957 | |
| 958 | /* magic also includes the null byte, check that as well */ |
| 959 | magic_len = strlen(ATH10K_FIRMWARE_MAGIC) + 1; |
| 960 | |
| 961 | if (len < magic_len) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 962 | ath10k_err(ar, "firmware file '%s/%s' too small to contain magic: %zu\n", |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 963 | ar->hw_params.fw.dir, name, len); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 964 | ret = -EINVAL; |
| 965 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | if (memcmp(data, ATH10K_FIRMWARE_MAGIC, magic_len) != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 969 | ath10k_err(ar, "invalid firmware magic\n"); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 970 | ret = -EINVAL; |
| 971 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /* jump over the padding */ |
| 975 | magic_len = ALIGN(magic_len, 4); |
| 976 | |
| 977 | len -= magic_len; |
| 978 | data += magic_len; |
| 979 | |
| 980 | /* loop elements */ |
| 981 | while (len > sizeof(struct ath10k_fw_ie)) { |
| 982 | hdr = (struct ath10k_fw_ie *)data; |
| 983 | |
| 984 | ie_id = le32_to_cpu(hdr->id); |
| 985 | ie_len = le32_to_cpu(hdr->len); |
| 986 | |
| 987 | len -= sizeof(*hdr); |
| 988 | data += sizeof(*hdr); |
| 989 | |
| 990 | if (len < ie_len) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 991 | ath10k_err(ar, "invalid length for FW IE %d (%zu < %zu)\n", |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 992 | ie_id, len, ie_len); |
Michal Kazior | 9bab1cc | 2013-10-04 08:13:20 +0200 | [diff] [blame] | 993 | ret = -EINVAL; |
| 994 | goto err; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | switch (ie_id) { |
| 998 | case ATH10K_FW_IE_FW_VERSION: |
| 999 | if (ie_len > sizeof(ar->hw->wiphy->fw_version) - 1) |
| 1000 | break; |
| 1001 | |
| 1002 | memcpy(ar->hw->wiphy->fw_version, data, ie_len); |
| 1003 | ar->hw->wiphy->fw_version[ie_len] = '\0'; |
| 1004 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1005 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1006 | "found fw version %s\n", |
| 1007 | ar->hw->wiphy->fw_version); |
| 1008 | break; |
| 1009 | case ATH10K_FW_IE_TIMESTAMP: |
| 1010 | if (ie_len != sizeof(u32)) |
| 1011 | break; |
| 1012 | |
| 1013 | timestamp = (__le32 *)data; |
| 1014 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1015 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw timestamp %d\n", |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1016 | le32_to_cpup(timestamp)); |
| 1017 | break; |
| 1018 | case ATH10K_FW_IE_FEATURES: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1019 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1020 | "found firmware features ie (%zd B)\n", |
| 1021 | ie_len); |
| 1022 | |
| 1023 | for (i = 0; i < ATH10K_FW_FEATURE_COUNT; i++) { |
| 1024 | index = i / 8; |
| 1025 | bit = i % 8; |
| 1026 | |
| 1027 | if (index == ie_len) |
| 1028 | break; |
| 1029 | |
Ben Greear | f591a1a | 2014-02-04 19:51:38 +0200 | [diff] [blame] | 1030 | if (data[index] & (1 << bit)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1031 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Ben Greear | f591a1a | 2014-02-04 19:51:38 +0200 | [diff] [blame] | 1032 | "Enabling feature bit: %i\n", |
| 1033 | i); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1034 | __set_bit(i, ar->fw_features); |
Ben Greear | f591a1a | 2014-02-04 19:51:38 +0200 | [diff] [blame] | 1035 | } |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1036 | } |
| 1037 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1038 | ath10k_dbg_dump(ar, ATH10K_DBG_BOOT, "features", "", |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1039 | ar->fw_features, |
| 1040 | sizeof(ar->fw_features)); |
| 1041 | break; |
| 1042 | case ATH10K_FW_IE_FW_IMAGE: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1043 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1044 | "found fw image ie (%zd B)\n", |
| 1045 | ie_len); |
| 1046 | |
| 1047 | ar->firmware_data = data; |
| 1048 | ar->firmware_len = ie_len; |
| 1049 | |
| 1050 | break; |
| 1051 | case ATH10K_FW_IE_OTP_IMAGE: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1052 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1053 | "found otp image ie (%zd B)\n", |
| 1054 | ie_len); |
| 1055 | |
| 1056 | ar->otp_data = data; |
| 1057 | ar->otp_len = ie_len; |
| 1058 | |
| 1059 | break; |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1060 | case ATH10K_FW_IE_WMI_OP_VERSION: |
| 1061 | if (ie_len != sizeof(u32)) |
| 1062 | break; |
| 1063 | |
| 1064 | version = (__le32 *)data; |
| 1065 | |
| 1066 | ar->wmi.op_version = le32_to_cpup(version); |
| 1067 | |
| 1068 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie wmi op version %d\n", |
| 1069 | ar->wmi.op_version); |
| 1070 | break; |
Rajkumar Manoharan | 8348db2 | 2015-03-25 13:12:27 +0200 | [diff] [blame] | 1071 | case ATH10K_FW_IE_HTT_OP_VERSION: |
| 1072 | if (ie_len != sizeof(u32)) |
| 1073 | break; |
| 1074 | |
| 1075 | version = (__le32 *)data; |
| 1076 | |
| 1077 | ar->htt.op_version = le32_to_cpup(version); |
| 1078 | |
| 1079 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "found fw ie htt op version %d\n", |
| 1080 | ar->htt.op_version); |
| 1081 | break; |
Vasanthakumar Thiagarajan | dcb02db | 2015-06-18 12:31:09 +0530 | [diff] [blame] | 1082 | case ATH10K_FW_IE_FW_CODE_SWAP_IMAGE: |
| 1083 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 1084 | "found fw code swap image ie (%zd B)\n", |
| 1085 | ie_len); |
| 1086 | ar->swap.firmware_codeswap_data = data; |
| 1087 | ar->swap.firmware_codeswap_len = ie_len; |
| 1088 | break; |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1089 | default: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1090 | ath10k_warn(ar, "Unknown FW IE: %u\n", |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1091 | le32_to_cpu(hdr->id)); |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | /* jump over the padding */ |
| 1096 | ie_len = ALIGN(ie_len, 4); |
| 1097 | |
| 1098 | len -= ie_len; |
| 1099 | data += ie_len; |
Fengguang Wu | e05634e | 2013-10-08 21:48:15 +0300 | [diff] [blame] | 1100 | } |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1101 | |
| 1102 | if (!ar->firmware_data || !ar->firmware_len) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1103 | ath10k_warn(ar, "No ATH10K_FW_IE_FW_IMAGE found from '%s/%s', skipping\n", |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 1104 | ar->hw_params.fw.dir, name); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1105 | ret = -ENOMEDIUM; |
| 1106 | goto err; |
| 1107 | } |
| 1108 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1109 | return 0; |
| 1110 | |
| 1111 | err: |
| 1112 | ath10k_core_free_firmware_files(ar); |
| 1113 | return ret; |
| 1114 | } |
| 1115 | |
| 1116 | static int ath10k_core_fetch_firmware_files(struct ath10k *ar) |
| 1117 | { |
| 1118 | int ret; |
| 1119 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 1120 | /* calibration file is optional, don't check for any errors */ |
| 1121 | ath10k_fetch_cal_file(ar); |
| 1122 | |
Kalle Valo | 53513c3 | 2015-03-25 13:12:42 +0200 | [diff] [blame] | 1123 | ar->fw_api = 5; |
| 1124 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
| 1125 | |
| 1126 | ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API5_FILE); |
| 1127 | if (ret == 0) |
| 1128 | goto success; |
| 1129 | |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 1130 | ar->fw_api = 4; |
| 1131 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
| 1132 | |
| 1133 | ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API4_FILE); |
| 1134 | if (ret == 0) |
| 1135 | goto success; |
| 1136 | |
Michal Kazior | 24c88f7 | 2014-07-25 13:32:17 +0200 | [diff] [blame] | 1137 | ar->fw_api = 3; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1138 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
Michal Kazior | 24c88f7 | 2014-07-25 13:32:17 +0200 | [diff] [blame] | 1139 | |
| 1140 | ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API3_FILE); |
| 1141 | if (ret == 0) |
| 1142 | goto success; |
| 1143 | |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 1144 | ar->fw_api = 2; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1145 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 1146 | |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1147 | ret = ath10k_core_fetch_firmware_api_n(ar, ATH10K_FW_API2_FILE); |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 1148 | if (ret == 0) |
| 1149 | goto success; |
| 1150 | |
| 1151 | ar->fw_api = 1; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1152 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "trying fw api %d\n", ar->fw_api); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1153 | |
| 1154 | ret = ath10k_core_fetch_firmware_api_1(ar); |
| 1155 | if (ret) |
| 1156 | return ret; |
| 1157 | |
Ben Greear | 53c0228 | 2014-03-24 12:20:41 -0700 | [diff] [blame] | 1158 | success: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1159 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "using fw api %d\n", ar->fw_api); |
Kalle Valo | 1a22243 | 2013-09-27 19:55:07 +0300 | [diff] [blame] | 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
Kalle Valo | 8309155 | 2014-10-13 09:40:53 +0300 | [diff] [blame] | 1164 | static int ath10k_download_cal_data(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1165 | { |
| 1166 | int ret; |
| 1167 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 1168 | ret = ath10k_download_cal_file(ar); |
| 1169 | if (ret == 0) { |
| 1170 | ar->cal_mode = ATH10K_CAL_MODE_FILE; |
| 1171 | goto done; |
| 1172 | } |
| 1173 | |
| 1174 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
Toshi Kikuchi | 5aabff0 | 2014-12-02 10:55:54 +0200 | [diff] [blame] | 1175 | "boot did not find a calibration file, try DT next: %d\n", |
| 1176 | ret); |
| 1177 | |
| 1178 | ret = ath10k_download_cal_dt(ar); |
| 1179 | if (ret == 0) { |
| 1180 | ar->cal_mode = ATH10K_CAL_MODE_DT; |
| 1181 | goto done; |
| 1182 | } |
| 1183 | |
| 1184 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 1185 | "boot did not find DT entry, try OTP next: %d\n", |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 1186 | ret); |
| 1187 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1188 | ret = ath10k_download_and_run_otp(ar); |
Ben Greear | 36a8f41 | 2014-03-24 12:20:42 -0700 | [diff] [blame] | 1189 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1190 | ath10k_err(ar, "failed to run otp: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1191 | return ret; |
Ben Greear | 36a8f41 | 2014-03-24 12:20:42 -0700 | [diff] [blame] | 1192 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1193 | |
Kalle Valo | a58227e | 2014-10-13 09:40:59 +0300 | [diff] [blame] | 1194 | ar->cal_mode = ATH10K_CAL_MODE_OTP; |
| 1195 | |
| 1196 | done: |
| 1197 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot using calibration mode %s\n", |
| 1198 | ath10k_cal_mode_str(ar->cal_mode)); |
| 1199 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | static int ath10k_init_uart(struct ath10k *ar) |
| 1203 | { |
| 1204 | int ret; |
| 1205 | |
| 1206 | /* |
| 1207 | * Explicitly setting UART prints to zero as target turns it on |
| 1208 | * based on scratch registers. |
| 1209 | */ |
| 1210 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 0); |
| 1211 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1212 | ath10k_warn(ar, "could not disable UART prints (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1213 | return ret; |
| 1214 | } |
| 1215 | |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 1216 | if (!uart_print) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1217 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1218 | |
Michal Kazior | 3a8200b | 2014-12-02 10:55:55 +0200 | [diff] [blame] | 1219 | ret = ath10k_bmi_write32(ar, hi_dbg_uart_txpin, ar->hw_params.uart_pin); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1220 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1221 | ath10k_warn(ar, "could not enable UART prints (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1222 | return ret; |
| 1223 | } |
| 1224 | |
| 1225 | ret = ath10k_bmi_write32(ar, hi_serial_enable, 1); |
| 1226 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1227 | ath10k_warn(ar, "could not enable UART prints (%d)\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1228 | return ret; |
| 1229 | } |
| 1230 | |
Bartosz Markowski | 03fc137 | 2013-09-03 14:24:02 +0200 | [diff] [blame] | 1231 | /* Set the UART baud rate to 19200. */ |
| 1232 | ret = ath10k_bmi_write32(ar, hi_desired_baud_rate, 19200); |
| 1233 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1234 | ath10k_warn(ar, "could not set the baud rate (%d)\n", ret); |
Bartosz Markowski | 03fc137 | 2013-09-03 14:24:02 +0200 | [diff] [blame] | 1235 | return ret; |
| 1236 | } |
| 1237 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1238 | ath10k_info(ar, "UART prints enabled\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int ath10k_init_hw_params(struct ath10k *ar) |
| 1243 | { |
| 1244 | const struct ath10k_hw_params *uninitialized_var(hw_params); |
| 1245 | int i; |
| 1246 | |
| 1247 | for (i = 0; i < ARRAY_SIZE(ath10k_hw_params_list); i++) { |
| 1248 | hw_params = &ath10k_hw_params_list[i]; |
| 1249 | |
| 1250 | if (hw_params->id == ar->target_version) |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | if (i == ARRAY_SIZE(ath10k_hw_params_list)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1255 | ath10k_err(ar, "Unsupported hardware version: 0x%x\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1256 | ar->target_version); |
| 1257 | return -EINVAL; |
| 1258 | } |
| 1259 | |
| 1260 | ar->hw_params = *hw_params; |
| 1261 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1262 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "Hardware name %s version 0x%x\n", |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 1263 | ar->hw_params.name, ar->target_version); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1264 | |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1268 | static void ath10k_core_restart(struct work_struct *work) |
| 1269 | { |
| 1270 | struct ath10k *ar = container_of(work, struct ath10k, restart_work); |
| 1271 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1272 | set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags); |
| 1273 | |
| 1274 | /* Place a barrier to make sure the compiler doesn't reorder |
| 1275 | * CRASH_FLUSH and calling other functions. |
| 1276 | */ |
| 1277 | barrier(); |
| 1278 | |
| 1279 | ieee80211_stop_queues(ar->hw); |
| 1280 | ath10k_drain_tx(ar); |
| 1281 | complete_all(&ar->scan.started); |
| 1282 | complete_all(&ar->scan.completed); |
| 1283 | complete_all(&ar->scan.on_channel); |
| 1284 | complete_all(&ar->offchan_tx_completed); |
| 1285 | complete_all(&ar->install_key_done); |
| 1286 | complete_all(&ar->vdev_setup_done); |
Rajkumar Manoharan | ac2953f | 2014-12-17 12:22:26 +0200 | [diff] [blame] | 1287 | complete_all(&ar->thermal.wmi_sync); |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1288 | wake_up(&ar->htt.empty_tx_wq); |
| 1289 | wake_up(&ar->wmi.tx_credits_wq); |
| 1290 | wake_up(&ar->peer_mapping_wq); |
| 1291 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1292 | mutex_lock(&ar->conf_mutex); |
| 1293 | |
| 1294 | switch (ar->state) { |
| 1295 | case ATH10K_STATE_ON: |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1296 | ar->state = ATH10K_STATE_RESTARTING; |
Michal Kazior | 61e9aab | 2014-08-22 14:33:18 +0200 | [diff] [blame] | 1297 | ath10k_hif_stop(ar); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 1298 | ath10k_scan_finish(ar); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1299 | ieee80211_restart_hw(ar->hw); |
| 1300 | break; |
| 1301 | case ATH10K_STATE_OFF: |
Michal Kazior | 5e90de8 | 2013-10-16 16:46:05 +0300 | [diff] [blame] | 1302 | /* this can happen if driver is being unloaded |
| 1303 | * or if the crash happens during FW probing */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1304 | ath10k_warn(ar, "cannot restart a device that hasn't been started\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1305 | break; |
| 1306 | case ATH10K_STATE_RESTARTING: |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 1307 | /* hw restart might be requested from multiple places */ |
| 1308 | break; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1309 | case ATH10K_STATE_RESTARTED: |
| 1310 | ar->state = ATH10K_STATE_WEDGED; |
| 1311 | /* fall through */ |
| 1312 | case ATH10K_STATE_WEDGED: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1313 | ath10k_warn(ar, "device is wedged, will not restart\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1314 | break; |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1315 | case ATH10K_STATE_UTF: |
| 1316 | ath10k_warn(ar, "firmware restart in UTF mode not supported\n"); |
| 1317 | break; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | mutex_unlock(&ar->conf_mutex); |
| 1321 | } |
| 1322 | |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1323 | static int ath10k_core_init_firmware_features(struct ath10k *ar) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 1324 | { |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1325 | if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, ar->fw_features) && |
| 1326 | !test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) { |
| 1327 | ath10k_err(ar, "feature bits corrupted: 10.2 feature requires 10.x feature to be set as well"); |
| 1328 | return -EINVAL; |
| 1329 | } |
| 1330 | |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1331 | if (ar->wmi.op_version >= ATH10K_FW_WMI_OP_VERSION_MAX) { |
| 1332 | ath10k_err(ar, "unsupported WMI OP version (max %d): %d\n", |
| 1333 | ATH10K_FW_WMI_OP_VERSION_MAX, ar->wmi.op_version); |
| 1334 | return -EINVAL; |
| 1335 | } |
| 1336 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1337 | ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_NATIVE_WIFI; |
| 1338 | switch (ath10k_cryptmode_param) { |
| 1339 | case ATH10K_CRYPT_MODE_HW: |
| 1340 | clear_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags); |
| 1341 | clear_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags); |
| 1342 | break; |
| 1343 | case ATH10K_CRYPT_MODE_SW: |
| 1344 | if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT, |
| 1345 | ar->fw_features)) { |
| 1346 | ath10k_err(ar, "cryptmode > 0 requires raw mode support from firmware"); |
| 1347 | return -EINVAL; |
| 1348 | } |
| 1349 | |
| 1350 | set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags); |
| 1351 | set_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags); |
| 1352 | break; |
| 1353 | default: |
| 1354 | ath10k_info(ar, "invalid cryptmode: %d\n", |
| 1355 | ath10k_cryptmode_param); |
| 1356 | return -EINVAL; |
| 1357 | } |
| 1358 | |
| 1359 | ar->htt.max_num_amsdu = ATH10K_HTT_MAX_NUM_AMSDU_DEFAULT; |
| 1360 | ar->htt.max_num_ampdu = ATH10K_HTT_MAX_NUM_AMPDU_DEFAULT; |
| 1361 | |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 1362 | if (rawmode) { |
| 1363 | if (!test_bit(ATH10K_FW_FEATURE_RAW_MODE_SUPPORT, |
| 1364 | ar->fw_features)) { |
| 1365 | ath10k_err(ar, "rawmode = 1 requires support from firmware"); |
| 1366 | return -EINVAL; |
| 1367 | } |
| 1368 | set_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags); |
| 1369 | } |
| 1370 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 1371 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
| 1372 | ar->wmi.rx_decap_mode = ATH10K_HW_TXRX_RAW; |
| 1373 | |
| 1374 | /* Workaround: |
| 1375 | * |
| 1376 | * Firmware A-MSDU aggregation breaks with RAW Tx encap mode |
| 1377 | * and causes enormous performance issues (malformed frames, |
| 1378 | * etc). |
| 1379 | * |
| 1380 | * Disabling A-MSDU makes RAW mode stable with heavy traffic |
| 1381 | * albeit a bit slower compared to regular operation. |
| 1382 | */ |
| 1383 | ar->htt.max_num_amsdu = 1; |
| 1384 | } |
| 1385 | |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1386 | /* Backwards compatibility for firmwares without |
| 1387 | * ATH10K_FW_IE_WMI_OP_VERSION. |
| 1388 | */ |
| 1389 | if (ar->wmi.op_version == ATH10K_FW_WMI_OP_VERSION_UNSET) { |
| 1390 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) { |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 1391 | if (test_bit(ATH10K_FW_FEATURE_WMI_10_2, |
| 1392 | ar->fw_features)) |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1393 | ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_2; |
| 1394 | else |
| 1395 | ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_10_1; |
| 1396 | } else { |
| 1397 | ar->wmi.op_version = ATH10K_FW_WMI_OP_VERSION_MAIN; |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | switch (ar->wmi.op_version) { |
| 1402 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 1403 | ar->max_num_peers = TARGET_NUM_PEERS; |
| 1404 | ar->max_num_stations = TARGET_NUM_STATIONS; |
Kalle Valo | 30c7816 | 2014-12-17 12:20:45 +0200 | [diff] [blame] | 1405 | ar->max_num_vdevs = TARGET_NUM_VDEVS; |
Kalle Valo | 91ad5f5 | 2014-12-03 10:10:17 +0200 | [diff] [blame] | 1406 | ar->htt.max_num_pending_tx = TARGET_NUM_MSDU_DESC; |
Yanbo Li | 6274cd4 | 2015-04-01 22:53:21 +0300 | [diff] [blame] | 1407 | ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV | |
| 1408 | WMI_STAT_PEER; |
Raja Mani | 5c8726e | 2015-06-22 20:22:26 +0530 | [diff] [blame] | 1409 | ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM; |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1410 | break; |
| 1411 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 1412 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 1413 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1414 | ar->max_num_peers = TARGET_10X_NUM_PEERS; |
| 1415 | ar->max_num_stations = TARGET_10X_NUM_STATIONS; |
Kalle Valo | 30c7816 | 2014-12-17 12:20:45 +0200 | [diff] [blame] | 1416 | ar->max_num_vdevs = TARGET_10X_NUM_VDEVS; |
Kalle Valo | 91ad5f5 | 2014-12-03 10:10:17 +0200 | [diff] [blame] | 1417 | ar->htt.max_num_pending_tx = TARGET_10X_NUM_MSDU_DESC; |
Yanbo Li | 6274cd4 | 2015-04-01 22:53:21 +0300 | [diff] [blame] | 1418 | ar->fw_stats_req_mask = WMI_STAT_PEER; |
Raja Mani | 5c8726e | 2015-06-22 20:22:26 +0530 | [diff] [blame] | 1419 | ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM; |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1420 | break; |
Michal Kazior | ca996ec | 2014-12-03 10:11:32 +0200 | [diff] [blame] | 1421 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
| 1422 | ar->max_num_peers = TARGET_TLV_NUM_PEERS; |
| 1423 | ar->max_num_stations = TARGET_TLV_NUM_STATIONS; |
Michal Kazior | 4927433 | 2015-01-08 11:36:56 +0100 | [diff] [blame] | 1424 | ar->max_num_vdevs = TARGET_TLV_NUM_VDEVS; |
Marek Puzyniak | 8cca3d6 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 1425 | ar->max_num_tdls_vdevs = TARGET_TLV_NUM_TDLS_VDEVS; |
Michal Kazior | ca996ec | 2014-12-03 10:11:32 +0200 | [diff] [blame] | 1426 | ar->htt.max_num_pending_tx = TARGET_TLV_NUM_MSDU_DESC; |
Janusz Dziedzic | 25c8661 | 2015-03-23 17:32:54 +0200 | [diff] [blame] | 1427 | ar->wow.max_num_patterns = TARGET_TLV_NUM_WOW_PATTERNS; |
Yanbo Li | 6274cd4 | 2015-04-01 22:53:21 +0300 | [diff] [blame] | 1428 | ar->fw_stats_req_mask = WMI_STAT_PDEV | WMI_STAT_VDEV | |
| 1429 | WMI_STAT_PEER; |
Raja Mani | 5c8726e | 2015-06-22 20:22:26 +0530 | [diff] [blame] | 1430 | ar->max_spatial_stream = WMI_MAX_SPATIAL_STREAM; |
Michal Kazior | ca996ec | 2014-12-03 10:11:32 +0200 | [diff] [blame] | 1431 | break; |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 1432 | case ATH10K_FW_WMI_OP_VERSION_10_4: |
Raja Mani | d1e52a8 | 2015-06-22 20:10:15 +0530 | [diff] [blame] | 1433 | ar->max_num_peers = TARGET_10_4_NUM_PEERS; |
| 1434 | ar->max_num_stations = TARGET_10_4_NUM_STATIONS; |
| 1435 | ar->num_active_peers = TARGET_10_4_ACTIVE_PEERS; |
| 1436 | ar->max_num_vdevs = TARGET_10_4_NUM_VDEVS; |
| 1437 | ar->num_tids = TARGET_10_4_TGT_NUM_TIDS; |
Raja Mani | 721ad3c | 2015-06-22 20:22:24 +0530 | [diff] [blame] | 1438 | ar->htt.max_num_pending_tx = TARGET_10_4_NUM_MSDU_DESC; |
Raja Mani | d1e52a8 | 2015-06-22 20:10:15 +0530 | [diff] [blame] | 1439 | ar->fw_stats_req_mask = WMI_STAT_PEER; |
Raja Mani | 5c8726e | 2015-06-22 20:22:26 +0530 | [diff] [blame] | 1440 | ar->max_spatial_stream = WMI_10_4_MAX_SPATIAL_STREAM; |
Raja Mani | d1e52a8 | 2015-06-22 20:10:15 +0530 | [diff] [blame] | 1441 | break; |
Kalle Valo | 202e86e | 2014-12-03 10:10:08 +0200 | [diff] [blame] | 1442 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 1443 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 1444 | WARN_ON(1); |
| 1445 | return -EINVAL; |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 1446 | } |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1447 | |
Kalle Valo | dc3632a | 2015-03-30 14:14:28 +0300 | [diff] [blame] | 1448 | /* Backwards compatibility for firmwares without |
| 1449 | * ATH10K_FW_IE_HTT_OP_VERSION. |
| 1450 | */ |
| 1451 | if (ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_UNSET) { |
| 1452 | switch (ar->wmi.op_version) { |
| 1453 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
| 1454 | ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_MAIN; |
| 1455 | break; |
| 1456 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 1457 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
| 1458 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
| 1459 | ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_10_1; |
| 1460 | break; |
| 1461 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
| 1462 | ar->htt.op_version = ATH10K_FW_HTT_OP_VERSION_TLV; |
| 1463 | break; |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 1464 | case ATH10K_FW_WMI_OP_VERSION_10_4: |
Kalle Valo | dc3632a | 2015-03-30 14:14:28 +0300 | [diff] [blame] | 1465 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 1466 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 1467 | WARN_ON(1); |
| 1468 | return -EINVAL; |
| 1469 | } |
| 1470 | } |
| 1471 | |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1472 | return 0; |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 1473 | } |
| 1474 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1475 | int ath10k_core_start(struct ath10k *ar, enum ath10k_firmware_mode mode) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1476 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1477 | int status; |
| 1478 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1479 | lockdep_assert_held(&ar->conf_mutex); |
| 1480 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1481 | clear_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags); |
| 1482 | |
Michal Kazior | 64d151d | 2013-07-16 09:38:53 +0200 | [diff] [blame] | 1483 | ath10k_bmi_start(ar); |
| 1484 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1485 | if (ath10k_init_configure_target(ar)) { |
| 1486 | status = -EINVAL; |
| 1487 | goto err; |
| 1488 | } |
| 1489 | |
Kalle Valo | 8309155 | 2014-10-13 09:40:53 +0300 | [diff] [blame] | 1490 | status = ath10k_download_cal_data(ar); |
| 1491 | if (status) |
| 1492 | goto err; |
| 1493 | |
Rajkumar Manoharan | 163f526 | 2015-05-29 17:51:53 +0300 | [diff] [blame] | 1494 | /* Some of of qca988x solutions are having global reset issue |
Kalle Valo | 617b0f4 | 2015-10-05 17:56:35 +0300 | [diff] [blame] | 1495 | * during target initialization. Bypassing PLL setting before |
| 1496 | * downloading firmware and letting the SoC run on REF_CLK is |
| 1497 | * fixing the problem. Corresponding firmware change is also needed |
| 1498 | * to set the clock source once the target is initialized. |
Rajkumar Manoharan | 163f526 | 2015-05-29 17:51:53 +0300 | [diff] [blame] | 1499 | */ |
| 1500 | if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_SKIP_CLOCK_INIT, |
| 1501 | ar->fw_features)) { |
| 1502 | status = ath10k_bmi_write32(ar, hi_skip_clock_init, 1); |
| 1503 | if (status) { |
| 1504 | ath10k_err(ar, "could not write to skip_clock_init: %d\n", |
| 1505 | status); |
| 1506 | goto err; |
| 1507 | } |
| 1508 | } |
| 1509 | |
Kalle Valo | 8309155 | 2014-10-13 09:40:53 +0300 | [diff] [blame] | 1510 | status = ath10k_download_fw(ar, mode); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1511 | if (status) |
| 1512 | goto err; |
| 1513 | |
| 1514 | status = ath10k_init_uart(ar); |
| 1515 | if (status) |
| 1516 | goto err; |
| 1517 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 1518 | ar->htc.htc_ops.target_send_suspend_complete = |
| 1519 | ath10k_send_suspend_complete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1520 | |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 1521 | status = ath10k_htc_init(ar); |
| 1522 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1523 | ath10k_err(ar, "could not init HTC (%d)\n", status); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1524 | goto err; |
| 1525 | } |
| 1526 | |
| 1527 | status = ath10k_bmi_done(ar); |
| 1528 | if (status) |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 1529 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1530 | |
| 1531 | status = ath10k_wmi_attach(ar); |
| 1532 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1533 | ath10k_err(ar, "WMI attach failed: %d\n", status); |
Michal Kazior | cd003fa | 2013-07-05 16:15:13 +0300 | [diff] [blame] | 1534 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1535 | } |
| 1536 | |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1537 | status = ath10k_htt_init(ar); |
| 1538 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1539 | ath10k_err(ar, "failed to init htt: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1540 | goto err_wmi_detach; |
| 1541 | } |
| 1542 | |
| 1543 | status = ath10k_htt_tx_alloc(&ar->htt); |
| 1544 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1545 | ath10k_err(ar, "failed to alloc htt tx: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1546 | goto err_wmi_detach; |
| 1547 | } |
| 1548 | |
| 1549 | status = ath10k_htt_rx_alloc(&ar->htt); |
| 1550 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1551 | ath10k_err(ar, "failed to alloc htt rx: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1552 | goto err_htt_tx_detach; |
| 1553 | } |
| 1554 | |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 1555 | status = ath10k_hif_start(ar); |
| 1556 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1557 | ath10k_err(ar, "could not start HIF: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1558 | goto err_htt_rx_detach; |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | status = ath10k_htc_wait_target(&ar->htc); |
| 1562 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1563 | ath10k_err(ar, "failed to connect to HTC: %d\n", status); |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 1564 | goto err_hif_stop; |
| 1565 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1566 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1567 | if (mode == ATH10K_FIRMWARE_MODE_NORMAL) { |
| 1568 | status = ath10k_htt_connect(&ar->htt); |
| 1569 | if (status) { |
| 1570 | ath10k_err(ar, "failed to connect htt (%d)\n", status); |
| 1571 | goto err_hif_stop; |
| 1572 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1573 | } |
| 1574 | |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1575 | status = ath10k_wmi_connect(ar); |
| 1576 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1577 | ath10k_err(ar, "could not connect wmi: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1578 | goto err_hif_stop; |
| 1579 | } |
| 1580 | |
| 1581 | status = ath10k_htc_start(&ar->htc); |
| 1582 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1583 | ath10k_err(ar, "failed to start htc: %d\n", status); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1584 | goto err_hif_stop; |
| 1585 | } |
| 1586 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1587 | if (mode == ATH10K_FIRMWARE_MODE_NORMAL) { |
| 1588 | status = ath10k_wmi_wait_for_service_ready(ar); |
Nicholas Mc Guire | 9eea568 | 2015-03-30 15:39:21 +0300 | [diff] [blame] | 1589 | if (status) { |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1590 | ath10k_warn(ar, "wmi service ready event not received"); |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1591 | goto err_hif_stop; |
| 1592 | } |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1593 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1594 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1595 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "firmware %s booted\n", |
Kalle Valo | c8c39af | 2013-11-20 10:00:41 +0200 | [diff] [blame] | 1596 | ar->hw->wiphy->fw_version); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1597 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1598 | status = ath10k_wmi_cmd_init(ar); |
| 1599 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1600 | ath10k_err(ar, "could not send WMI init command (%d)\n", |
| 1601 | status); |
Michal Kazior | b7967dc | 2014-08-07 11:03:31 +0200 | [diff] [blame] | 1602 | goto err_hif_stop; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | status = ath10k_wmi_wait_for_unified_ready(ar); |
Nicholas Mc Guire | 9eea568 | 2015-03-30 15:39:21 +0300 | [diff] [blame] | 1606 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1607 | ath10k_err(ar, "wmi unified ready event not received\n"); |
Michal Kazior | b7967dc | 2014-08-07 11:03:31 +0200 | [diff] [blame] | 1608 | goto err_hif_stop; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1609 | } |
| 1610 | |
Michal Kazior | c545070 | 2015-01-24 12:14:48 +0200 | [diff] [blame] | 1611 | /* If firmware indicates Full Rx Reorder support it must be used in a |
| 1612 | * slightly different manner. Let HTT code know. |
| 1613 | */ |
| 1614 | ar->htt.rx_ring.in_ord_rx = !!(test_bit(WMI_SERVICE_RX_FULL_REORDER, |
| 1615 | ar->wmi.svc_map)); |
| 1616 | |
| 1617 | status = ath10k_htt_rx_ring_refill(ar); |
| 1618 | if (status) { |
| 1619 | ath10k_err(ar, "failed to refill htt rx ring: %d\n", status); |
| 1620 | goto err_hif_stop; |
| 1621 | } |
| 1622 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1623 | /* we don't care about HTT in UTF mode */ |
| 1624 | if (mode == ATH10K_FIRMWARE_MODE_NORMAL) { |
| 1625 | status = ath10k_htt_setup(&ar->htt); |
| 1626 | if (status) { |
| 1627 | ath10k_err(ar, "failed to setup htt: %d\n", status); |
| 1628 | goto err_hif_stop; |
| 1629 | } |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1630 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1631 | |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1632 | status = ath10k_debug_start(ar); |
| 1633 | if (status) |
Michal Kazior | b7967dc | 2014-08-07 11:03:31 +0200 | [diff] [blame] | 1634 | goto err_hif_stop; |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1635 | |
Kalle Valo | 30c7816 | 2014-12-17 12:20:45 +0200 | [diff] [blame] | 1636 | ar->free_vdev_map = (1LL << ar->max_num_vdevs) - 1; |
Bartosz Markowski | dfa413d | 2014-06-02 21:19:45 +0300 | [diff] [blame] | 1637 | |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 1638 | INIT_LIST_HEAD(&ar->arvifs); |
Michal Kazior | 1a1b8a8 | 2013-07-16 09:38:55 +0200 | [diff] [blame] | 1639 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1640 | return 0; |
| 1641 | |
Michal Kazior | 67e3c63 | 2013-11-08 08:05:18 +0100 | [diff] [blame] | 1642 | err_hif_stop: |
| 1643 | ath10k_hif_stop(ar); |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1644 | err_htt_rx_detach: |
| 1645 | ath10k_htt_rx_free(&ar->htt); |
| 1646 | err_htt_tx_detach: |
| 1647 | ath10k_htt_tx_free(&ar->htt); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1648 | err_wmi_detach: |
| 1649 | ath10k_wmi_detach(ar); |
| 1650 | err: |
| 1651 | return status; |
| 1652 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1653 | EXPORT_SYMBOL(ath10k_core_start); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1654 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1655 | int ath10k_wait_for_suspend(struct ath10k *ar, u32 suspend_opt) |
| 1656 | { |
| 1657 | int ret; |
Nicholas Mc Guire | a7a4284 | 2015-03-30 15:39:21 +0300 | [diff] [blame] | 1658 | unsigned long time_left; |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1659 | |
| 1660 | reinit_completion(&ar->target_suspend); |
| 1661 | |
| 1662 | ret = ath10k_wmi_pdev_suspend_target(ar, suspend_opt); |
| 1663 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1664 | ath10k_warn(ar, "could not suspend target (%d)\n", ret); |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1665 | return ret; |
| 1666 | } |
| 1667 | |
Nicholas Mc Guire | a7a4284 | 2015-03-30 15:39:21 +0300 | [diff] [blame] | 1668 | time_left = wait_for_completion_timeout(&ar->target_suspend, 1 * HZ); |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1669 | |
Nicholas Mc Guire | a7a4284 | 2015-03-30 15:39:21 +0300 | [diff] [blame] | 1670 | if (!time_left) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1671 | ath10k_warn(ar, "suspend timed out - target pause event never came\n"); |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1672 | return -ETIMEDOUT; |
| 1673 | } |
| 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1678 | void ath10k_core_stop(struct ath10k *ar) |
| 1679 | { |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1680 | lockdep_assert_held(&ar->conf_mutex); |
Raja Mani | f1ee268 | 2015-07-09 14:19:42 +0530 | [diff] [blame] | 1681 | ath10k_debug_stop(ar); |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1682 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 1683 | /* try to suspend target */ |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1684 | if (ar->state != ATH10K_STATE_RESTARTING && |
| 1685 | ar->state != ATH10K_STATE_UTF) |
Michal Kazior | 216a183 | 2014-04-23 19:30:04 +0300 | [diff] [blame] | 1686 | ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND_AND_DISABLE_INTR); |
| 1687 | |
Michal Kazior | 95bf21f | 2014-05-16 17:15:39 +0300 | [diff] [blame] | 1688 | ath10k_hif_stop(ar); |
| 1689 | ath10k_htt_tx_free(&ar->htt); |
| 1690 | ath10k_htt_rx_free(&ar->htt); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1691 | ath10k_wmi_detach(ar); |
| 1692 | } |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1693 | EXPORT_SYMBOL(ath10k_core_stop); |
| 1694 | |
| 1695 | /* mac80211 manages fw/hw initialization through start/stop hooks. However in |
| 1696 | * order to know what hw capabilities should be advertised to mac80211 it is |
| 1697 | * necessary to load the firmware (and tear it down immediately since start |
| 1698 | * hook will try to init it again) before registering */ |
| 1699 | static int ath10k_core_probe_fw(struct ath10k *ar) |
| 1700 | { |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1701 | struct bmi_target_info target_info; |
| 1702 | int ret = 0; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1703 | |
| 1704 | ret = ath10k_hif_power_up(ar); |
| 1705 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1706 | ath10k_err(ar, "could not start pci hif (%d)\n", ret); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1707 | return ret; |
| 1708 | } |
| 1709 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1710 | memset(&target_info, 0, sizeof(target_info)); |
| 1711 | ret = ath10k_bmi_get_target_info(ar, &target_info); |
| 1712 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1713 | ath10k_err(ar, "could not get target info (%d)\n", ret); |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1714 | goto err_power_down; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | ar->target_version = target_info.version; |
| 1718 | ar->hw->wiphy->hw_version = target_info.version; |
| 1719 | |
| 1720 | ret = ath10k_init_hw_params(ar); |
| 1721 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1722 | ath10k_err(ar, "could not get hw params (%d)\n", ret); |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1723 | goto err_power_down; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | ret = ath10k_core_fetch_firmware_files(ar); |
| 1727 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1728 | ath10k_err(ar, "could not fetch firmware files (%d)\n", ret); |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1729 | goto err_power_down; |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
Manikanta Pubbisetty | db0984e | 2015-10-09 11:55:59 +0300 | [diff] [blame] | 1732 | ret = ath10k_core_get_board_id_from_otp(ar); |
| 1733 | if (ret && ret != -EOPNOTSUPP) { |
| 1734 | ath10k_err(ar, "failed to get board id from otp for qca99x0: %d\n", |
| 1735 | ret); |
| 1736 | return ret; |
| 1737 | } |
| 1738 | |
| 1739 | ret = ath10k_core_fetch_board_file(ar); |
| 1740 | if (ret) { |
| 1741 | ath10k_err(ar, "failed to fetch board file: %d\n", ret); |
| 1742 | goto err_free_firmware_files; |
| 1743 | } |
| 1744 | |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1745 | ret = ath10k_core_init_firmware_features(ar); |
| 1746 | if (ret) { |
| 1747 | ath10k_err(ar, "fatal problem with firmware features: %d\n", |
| 1748 | ret); |
| 1749 | goto err_free_firmware_files; |
| 1750 | } |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 1751 | |
Vasanthakumar Thiagarajan | dcb02db | 2015-06-18 12:31:09 +0530 | [diff] [blame] | 1752 | ret = ath10k_swap_code_seg_init(ar); |
| 1753 | if (ret) { |
| 1754 | ath10k_err(ar, "failed to initialize code swap segment: %d\n", |
| 1755 | ret); |
| 1756 | goto err_free_firmware_files; |
| 1757 | } |
| 1758 | |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1759 | mutex_lock(&ar->conf_mutex); |
| 1760 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1761 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1762 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1763 | ath10k_err(ar, "could not init core (%d)\n", ret); |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1764 | goto err_unlock; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1765 | } |
| 1766 | |
Michal Kazior | 8079de0 | 2014-08-22 14:23:29 +0200 | [diff] [blame] | 1767 | ath10k_print_driver_info(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1768 | ath10k_core_stop(ar); |
Kalle Valo | 60631c5 | 2013-10-08 21:45:25 +0300 | [diff] [blame] | 1769 | |
| 1770 | mutex_unlock(&ar->conf_mutex); |
| 1771 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1772 | ath10k_hif_power_down(ar); |
| 1773 | return 0; |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1774 | |
| 1775 | err_unlock: |
| 1776 | mutex_unlock(&ar->conf_mutex); |
| 1777 | |
Kalle Valo | 5f2144d | 2014-12-03 10:09:59 +0200 | [diff] [blame] | 1778 | err_free_firmware_files: |
Kalle Valo | c6ce492 | 2014-12-03 10:09:31 +0200 | [diff] [blame] | 1779 | ath10k_core_free_firmware_files(ar); |
| 1780 | |
| 1781 | err_power_down: |
| 1782 | ath10k_hif_power_down(ar); |
| 1783 | |
| 1784 | return ret; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1785 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1786 | |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1787 | static void ath10k_core_register_work(struct work_struct *work) |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1788 | { |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1789 | struct ath10k *ar = container_of(work, struct ath10k, register_work); |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1790 | int status; |
| 1791 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1792 | status = ath10k_core_probe_fw(ar); |
| 1793 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1794 | ath10k_err(ar, "could not probe fw (%d)\n", status); |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1795 | goto err; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1796 | } |
Michal Kazior | dd30a36 | 2013-07-16 09:38:51 +0200 | [diff] [blame] | 1797 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1798 | status = ath10k_mac_register(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1799 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1800 | ath10k_err(ar, "could not register to mac80211 (%d)\n", status); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1801 | goto err_release_fw; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 1802 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1803 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1804 | status = ath10k_debug_register(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1805 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1806 | ath10k_err(ar, "unable to initialize debugfs\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1807 | goto err_unregister_mac; |
| 1808 | } |
| 1809 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 1810 | status = ath10k_spectral_create(ar); |
| 1811 | if (status) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1812 | ath10k_err(ar, "failed to initialize spectral\n"); |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 1813 | goto err_debug_destroy; |
| 1814 | } |
| 1815 | |
Rajkumar Manoharan | fe6f36d | 2014-12-17 12:22:07 +0200 | [diff] [blame] | 1816 | status = ath10k_thermal_register(ar); |
| 1817 | if (status) { |
| 1818 | ath10k_err(ar, "could not register thermal device: %d\n", |
| 1819 | status); |
| 1820 | goto err_spectral_destroy; |
| 1821 | } |
| 1822 | |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1823 | set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags); |
| 1824 | return; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1825 | |
Rajkumar Manoharan | fe6f36d | 2014-12-17 12:22:07 +0200 | [diff] [blame] | 1826 | err_spectral_destroy: |
| 1827 | ath10k_spectral_destroy(ar); |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 1828 | err_debug_destroy: |
| 1829 | ath10k_debug_destroy(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1830 | err_unregister_mac: |
| 1831 | ath10k_mac_unregister(ar); |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1832 | err_release_fw: |
| 1833 | ath10k_core_free_firmware_files(ar); |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1834 | err: |
Michal Kazior | a491a92 | 2014-07-14 16:07:29 +0300 | [diff] [blame] | 1835 | /* TODO: It's probably a good idea to release device from the driver |
| 1836 | * but calling device_release_driver() here will cause a deadlock. |
| 1837 | */ |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | int ath10k_core_register(struct ath10k *ar, u32 chip_id) |
| 1842 | { |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1843 | ar->chip_id = chip_id; |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1844 | queue_work(ar->workqueue, &ar->register_work); |
| 1845 | |
| 1846 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1847 | } |
| 1848 | EXPORT_SYMBOL(ath10k_core_register); |
| 1849 | |
| 1850 | void ath10k_core_unregister(struct ath10k *ar) |
| 1851 | { |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1852 | cancel_work_sync(&ar->register_work); |
| 1853 | |
| 1854 | if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags)) |
| 1855 | return; |
| 1856 | |
Rajkumar Manoharan | fe6f36d | 2014-12-17 12:22:07 +0200 | [diff] [blame] | 1857 | ath10k_thermal_unregister(ar); |
Simon Wunderlich | 804eef147 | 2014-08-12 17:12:17 +0200 | [diff] [blame] | 1858 | /* Stop spectral before unregistering from mac80211 to remove the |
| 1859 | * relayfs debugfs file cleanly. Otherwise the parent debugfs tree |
| 1860 | * would be already be free'd recursively, leading to a double free. |
| 1861 | */ |
| 1862 | ath10k_spectral_destroy(ar); |
| 1863 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1864 | /* We must unregister from mac80211 before we stop HTC and HIF. |
| 1865 | * Otherwise we will fail to submit commands to FW and mac80211 will be |
| 1866 | * unhappy about callback failures. */ |
| 1867 | ath10k_mac_unregister(ar); |
Kalle Valo | db66ea0 | 2013-09-03 11:44:03 +0300 | [diff] [blame] | 1868 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 1869 | ath10k_testmode_destroy(ar); |
| 1870 | |
Michal Kazior | 2938505 | 2013-07-16 09:38:58 +0200 | [diff] [blame] | 1871 | ath10k_core_free_firmware_files(ar); |
Manikanta Pubbisetty | 0a51b34 | 2015-10-09 11:55:58 +0300 | [diff] [blame] | 1872 | ath10k_core_free_board_files(ar); |
Ben Greear | 6f1f56e | 2013-11-04 09:18:16 -0800 | [diff] [blame] | 1873 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1874 | ath10k_debug_unregister(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1875 | } |
| 1876 | EXPORT_SYMBOL(ath10k_core_unregister); |
| 1877 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 1878 | struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev, |
Kalle Valo | e07db35 | 2014-10-13 09:40:47 +0300 | [diff] [blame] | 1879 | enum ath10k_bus bus, |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1880 | enum ath10k_hw_rev hw_rev, |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1881 | const struct ath10k_hif_ops *hif_ops) |
| 1882 | { |
| 1883 | struct ath10k *ar; |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1884 | int ret; |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1885 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 1886 | ar = ath10k_mac_create(priv_size); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1887 | if (!ar) |
| 1888 | return NULL; |
| 1889 | |
| 1890 | ar->ath_common.priv = ar; |
| 1891 | ar->ath_common.hw = ar->hw; |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1892 | ar->dev = dev; |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1893 | ar->hw_rev = hw_rev; |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1894 | ar->hif.ops = hif_ops; |
Kalle Valo | e07db35 | 2014-10-13 09:40:47 +0300 | [diff] [blame] | 1895 | ar->hif.bus = bus; |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1896 | |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1897 | switch (hw_rev) { |
| 1898 | case ATH10K_HW_QCA988X: |
| 1899 | ar->regs = &qca988x_regs; |
Vasanthakumar Thiagarajan | 2f2cfc4 | 2015-06-18 12:31:01 +0530 | [diff] [blame] | 1900 | ar->hw_values = &qca988x_values; |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1901 | break; |
| 1902 | case ATH10K_HW_QCA6174: |
| 1903 | ar->regs = &qca6174_regs; |
Vasanthakumar Thiagarajan | 2f2cfc4 | 2015-06-18 12:31:01 +0530 | [diff] [blame] | 1904 | ar->hw_values = &qca6174_values; |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1905 | break; |
Vasanthakumar Thiagarajan | 8bd4702 | 2015-06-18 12:31:03 +0530 | [diff] [blame] | 1906 | case ATH10K_HW_QCA99X0: |
| 1907 | ar->regs = &qca99x0_regs; |
| 1908 | ar->hw_values = &qca99x0_values; |
| 1909 | break; |
Michal Kazior | d63955b | 2015-01-24 12:14:49 +0200 | [diff] [blame] | 1910 | default: |
| 1911 | ath10k_err(ar, "unsupported core hardware revision %d\n", |
| 1912 | hw_rev); |
| 1913 | ret = -ENOTSUPP; |
| 1914 | goto err_free_mac; |
| 1915 | } |
| 1916 | |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1917 | init_completion(&ar->scan.started); |
| 1918 | init_completion(&ar->scan.completed); |
| 1919 | init_completion(&ar->scan.on_channel); |
| 1920 | init_completion(&ar->target_suspend); |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 1921 | init_completion(&ar->wow.wakeup_completed); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1922 | |
| 1923 | init_completion(&ar->install_key_done); |
| 1924 | init_completion(&ar->vdev_setup_done); |
Rajkumar Manoharan | ac2953f | 2014-12-17 12:22:26 +0200 | [diff] [blame] | 1925 | init_completion(&ar->thermal.wmi_sync); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1926 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 1927 | INIT_DELAYED_WORK(&ar->scan.timeout, ath10k_scan_timeout_work); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1928 | |
| 1929 | ar->workqueue = create_singlethread_workqueue("ath10k_wq"); |
| 1930 | if (!ar->workqueue) |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1931 | goto err_free_mac; |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1932 | |
Raja Mani | c8ecfc1 | 2015-07-29 11:40:38 +0300 | [diff] [blame] | 1933 | ar->workqueue_aux = create_singlethread_workqueue("ath10k_aux_wq"); |
| 1934 | if (!ar->workqueue_aux) |
| 1935 | goto err_free_wq; |
| 1936 | |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1937 | mutex_init(&ar->conf_mutex); |
| 1938 | spin_lock_init(&ar->data_lock); |
| 1939 | |
| 1940 | INIT_LIST_HEAD(&ar->peers); |
| 1941 | init_waitqueue_head(&ar->peer_mapping_wq); |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1942 | init_waitqueue_head(&ar->htt.empty_tx_wq); |
| 1943 | init_waitqueue_head(&ar->wmi.tx_credits_wq); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1944 | |
| 1945 | init_completion(&ar->offchan_tx_completed); |
| 1946 | INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work); |
| 1947 | skb_queue_head_init(&ar->offchan_tx_queue); |
| 1948 | |
| 1949 | INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work); |
| 1950 | skb_queue_head_init(&ar->wmi_mgmt_tx_queue); |
| 1951 | |
Michal Kazior | 6782cb6 | 2014-05-23 12:28:47 +0200 | [diff] [blame] | 1952 | INIT_WORK(&ar->register_work, ath10k_core_register_work); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1953 | INIT_WORK(&ar->restart_work, ath10k_core_restart); |
| 1954 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1955 | ret = ath10k_debug_create(ar); |
| 1956 | if (ret) |
Raja Mani | c8ecfc1 | 2015-07-29 11:40:38 +0300 | [diff] [blame] | 1957 | goto err_free_aux_wq; |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1958 | |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1959 | return ar; |
| 1960 | |
Raja Mani | c8ecfc1 | 2015-07-29 11:40:38 +0300 | [diff] [blame] | 1961 | err_free_aux_wq: |
| 1962 | destroy_workqueue(ar->workqueue_aux); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1963 | err_free_wq: |
| 1964 | destroy_workqueue(ar->workqueue); |
| 1965 | |
| 1966 | err_free_mac: |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1967 | ath10k_mac_destroy(ar); |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1968 | |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1969 | return NULL; |
| 1970 | } |
| 1971 | EXPORT_SYMBOL(ath10k_core_create); |
| 1972 | |
| 1973 | void ath10k_core_destroy(struct ath10k *ar) |
| 1974 | { |
| 1975 | flush_workqueue(ar->workqueue); |
| 1976 | destroy_workqueue(ar->workqueue); |
| 1977 | |
Raja Mani | c8ecfc1 | 2015-07-29 11:40:38 +0300 | [diff] [blame] | 1978 | flush_workqueue(ar->workqueue_aux); |
| 1979 | destroy_workqueue(ar->workqueue_aux); |
| 1980 | |
Michal Kazior | e13cf7a | 2014-09-04 09:13:08 +0200 | [diff] [blame] | 1981 | ath10k_debug_destroy(ar); |
Vasanthakumar Thiagarajan | a925a37 | 2015-08-28 17:21:34 +0530 | [diff] [blame] | 1982 | ath10k_wmi_free_host_mem(ar); |
Michal Kazior | 0d0a693 | 2014-05-23 12:28:45 +0200 | [diff] [blame] | 1983 | ath10k_mac_destroy(ar); |
| 1984 | } |
| 1985 | EXPORT_SYMBOL(ath10k_core_destroy); |
| 1986 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1987 | MODULE_AUTHOR("Qualcomm Atheros"); |
| 1988 | MODULE_DESCRIPTION("Core module for QCA988X PCIe devices."); |
| 1989 | MODULE_LICENSE("Dual BSD/GPL"); |