Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (c) 2011 Atheros Communications Inc. |
Vasanthakumar Thiagarajan | 1b2df40 | 2012-02-06 20:15:53 +0530 | [diff] [blame] | 4 | * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, and/or distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Stephen Rothwell | c6efe578 | 2011-09-28 18:32:34 +1000 | [diff] [blame] | 21 | #include <linux/moduleparam.h> |
Sangwook Lee | f783020 | 2011-10-26 16:28:38 +0100 | [diff] [blame] | 22 | #include <linux/errno.h> |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 23 | #include <linux/export.h> |
Sam Leffler | 92ecbff | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 24 | #include <linux/of.h> |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 25 | #include <linux/mmc/sdio_func.h> |
Vivek Natarajan | 8437754 | 2012-03-28 19:21:25 +0530 | [diff] [blame] | 26 | #include <linux/vmalloc.h> |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 27 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 28 | #include "core.h" |
| 29 | #include "cfg80211.h" |
| 30 | #include "target.h" |
| 31 | #include "debug.h" |
| 32 | #include "hif-ops.h" |
Kalle Valo | e76ac2bf | 2012-03-25 17:15:27 +0300 | [diff] [blame] | 33 | #include "htc-ops.h" |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 34 | |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 35 | static const struct ath6kl_hw hw_list[] = { |
| 36 | { |
Kalle Valo | 0d0192ba | 2011-11-14 19:31:07 +0200 | [diff] [blame] | 37 | .id = AR6003_HW_2_0_VERSION, |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 38 | .name = "ar6003 hw 2.0", |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 39 | .dataset_patch_addr = 0x57e884, |
| 40 | .app_load_addr = 0x543180, |
| 41 | .board_ext_data_addr = 0x57e500, |
| 42 | .reserved_ram_size = 6912, |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 43 | .refclk_hz = 26000000, |
| 44 | .uarttx_pin = 8, |
Mohammed Shafi Shajakhan | a2e1be3 | 2012-09-27 18:19:53 +0530 | [diff] [blame] | 45 | .flags = ATH6KL_HW_SDIO_CRC_ERROR_WAR, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 46 | |
| 47 | /* hw2.0 needs override address hardcoded */ |
| 48 | .app_start_override_addr = 0x944C00, |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 49 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 50 | .fw = { |
| 51 | .dir = AR6003_HW_2_0_FW_DIR, |
| 52 | .otp = AR6003_HW_2_0_OTP_FILE, |
| 53 | .fw = AR6003_HW_2_0_FIRMWARE_FILE, |
| 54 | .tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE, |
| 55 | .patch = AR6003_HW_2_0_PATCH_FILE, |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 56 | }, |
| 57 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 58 | .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE, |
| 59 | .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 60 | }, |
| 61 | { |
Kalle Valo | 0d0192ba | 2011-11-14 19:31:07 +0200 | [diff] [blame] | 62 | .id = AR6003_HW_2_1_1_VERSION, |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 63 | .name = "ar6003 hw 2.1.1", |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 64 | .dataset_patch_addr = 0x57ff74, |
| 65 | .app_load_addr = 0x1234, |
| 66 | .board_ext_data_addr = 0x542330, |
| 67 | .reserved_ram_size = 512, |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 68 | .refclk_hz = 26000000, |
| 69 | .uarttx_pin = 8, |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 70 | .testscript_addr = 0x57ef74, |
Mohammed Shafi Shajakhan | a2e1be3 | 2012-09-27 18:19:53 +0530 | [diff] [blame] | 71 | .flags = ATH6KL_HW_SDIO_CRC_ERROR_WAR, |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 72 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 73 | .fw = { |
| 74 | .dir = AR6003_HW_2_1_1_FW_DIR, |
| 75 | .otp = AR6003_HW_2_1_1_OTP_FILE, |
| 76 | .fw = AR6003_HW_2_1_1_FIRMWARE_FILE, |
| 77 | .tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE, |
| 78 | .patch = AR6003_HW_2_1_1_PATCH_FILE, |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 79 | .utf = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE, |
| 80 | .testscript = AR6003_HW_2_1_1_TESTSCRIPT_FILE, |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 81 | }, |
| 82 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 83 | .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE, |
Kalle Valo | 05aab17 | 2012-03-07 20:04:00 +0200 | [diff] [blame] | 84 | .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 85 | }, |
| 86 | { |
Kalle Valo | 0d0192ba | 2011-11-14 19:31:07 +0200 | [diff] [blame] | 87 | .id = AR6004_HW_1_0_VERSION, |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 88 | .name = "ar6004 hw 1.0", |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 89 | .dataset_patch_addr = 0x57e884, |
| 90 | .app_load_addr = 0x1234, |
| 91 | .board_ext_data_addr = 0x437000, |
| 92 | .reserved_ram_size = 19456, |
Kalle Valo | 0d4d72b | 2011-11-14 19:30:39 +0200 | [diff] [blame] | 93 | .board_addr = 0x433900, |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 94 | .refclk_hz = 26000000, |
| 95 | .uarttx_pin = 11, |
Mohammed Shafi Shajakhan | 7ac25ea | 2012-09-27 18:19:51 +0530 | [diff] [blame] | 96 | .flags = ATH6KL_HW_64BIT_RATES | |
| 97 | ATH6KL_HW_AP_INACTIVITY_MINS, |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 98 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 99 | .fw = { |
| 100 | .dir = AR6004_HW_1_0_FW_DIR, |
| 101 | .fw = AR6004_HW_1_0_FIRMWARE_FILE, |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 102 | }, |
| 103 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 104 | .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE, |
| 105 | .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 106 | }, |
| 107 | { |
Kalle Valo | 0d0192ba | 2011-11-14 19:31:07 +0200 | [diff] [blame] | 108 | .id = AR6004_HW_1_1_VERSION, |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 109 | .name = "ar6004 hw 1.1", |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 110 | .dataset_patch_addr = 0x57e884, |
| 111 | .app_load_addr = 0x1234, |
| 112 | .board_ext_data_addr = 0x437000, |
| 113 | .reserved_ram_size = 11264, |
Kalle Valo | 0d4d72b | 2011-11-14 19:30:39 +0200 | [diff] [blame] | 114 | .board_addr = 0x43d400, |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 115 | .refclk_hz = 40000000, |
| 116 | .uarttx_pin = 11, |
Mohammed Shafi Shajakhan | 7ac25ea | 2012-09-27 18:19:51 +0530 | [diff] [blame] | 117 | .flags = ATH6KL_HW_64BIT_RATES | |
| 118 | ATH6KL_HW_AP_INACTIVITY_MINS, |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 119 | .fw = { |
| 120 | .dir = AR6004_HW_1_1_FW_DIR, |
| 121 | .fw = AR6004_HW_1_1_FIRMWARE_FILE, |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 122 | }, |
| 123 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 124 | .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE, |
| 125 | .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 126 | }, |
Ray Chen | 6146ca6 | 2012-04-11 10:03:13 +0800 | [diff] [blame] | 127 | { |
| 128 | .id = AR6004_HW_1_2_VERSION, |
| 129 | .name = "ar6004 hw 1.2", |
| 130 | .dataset_patch_addr = 0x436ecc, |
| 131 | .app_load_addr = 0x1234, |
| 132 | .board_ext_data_addr = 0x437000, |
| 133 | .reserved_ram_size = 9216, |
| 134 | .board_addr = 0x435c00, |
| 135 | .refclk_hz = 40000000, |
| 136 | .uarttx_pin = 11, |
Mohammed Shafi Shajakhan | 7ac25ea | 2012-09-27 18:19:51 +0530 | [diff] [blame] | 137 | .flags = ATH6KL_HW_64BIT_RATES | |
| 138 | ATH6KL_HW_AP_INACTIVITY_MINS, |
Ray Chen | 6146ca6 | 2012-04-11 10:03:13 +0800 | [diff] [blame] | 139 | |
| 140 | .fw = { |
| 141 | .dir = AR6004_HW_1_2_FW_DIR, |
| 142 | .fw = AR6004_HW_1_2_FIRMWARE_FILE, |
| 143 | }, |
| 144 | .fw_board = AR6004_HW_1_2_BOARD_DATA_FILE, |
| 145 | .fw_default_board = AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE, |
| 146 | }, |
Bala Shanmugam | bf744f1 | 2012-07-17 12:01:55 +0530 | [diff] [blame] | 147 | { |
| 148 | .id = AR6004_HW_1_3_VERSION, |
| 149 | .name = "ar6004 hw 1.3", |
| 150 | .dataset_patch_addr = 0x437860, |
| 151 | .app_load_addr = 0x1234, |
| 152 | .board_ext_data_addr = 0x437000, |
| 153 | .reserved_ram_size = 7168, |
| 154 | .board_addr = 0x436400, |
| 155 | .refclk_hz = 40000000, |
| 156 | .uarttx_pin = 11, |
Mohammed Shafi Shajakhan | 7ac25ea | 2012-09-27 18:19:51 +0530 | [diff] [blame] | 157 | .flags = ATH6KL_HW_64BIT_RATES | |
Mohammed Shafi Shajakhan | 171fe76 | 2012-09-27 18:19:52 +0530 | [diff] [blame] | 158 | ATH6KL_HW_AP_INACTIVITY_MINS | |
| 159 | ATH6KL_HW_MAP_LP_ENDPOINT, |
Bala Shanmugam | bf744f1 | 2012-07-17 12:01:55 +0530 | [diff] [blame] | 160 | |
| 161 | .fw = { |
| 162 | .dir = AR6004_HW_1_3_FW_DIR, |
| 163 | .fw = AR6004_HW_1_3_FIRMWARE_FILE, |
| 164 | }, |
| 165 | |
| 166 | .fw_board = AR6004_HW_1_3_BOARD_DATA_FILE, |
| 167 | .fw_default_board = AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE, |
| 168 | }, |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 169 | }; |
| 170 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 171 | /* |
| 172 | * Include definitions here that can be used to tune the WLAN module |
| 173 | * behavior. Different customers can tune the behavior as per their needs, |
| 174 | * here. |
| 175 | */ |
| 176 | |
| 177 | /* |
| 178 | * This configuration item enable/disable keepalive support. |
| 179 | * Keepalive support: In the absence of any data traffic to AP, null |
| 180 | * frames will be sent to the AP at periodic interval, to keep the association |
| 181 | * active. This configuration item defines the periodic interval. |
| 182 | * Use value of zero to disable keepalive support |
| 183 | * Default: 60 seconds |
| 184 | */ |
| 185 | #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60 |
| 186 | |
| 187 | /* |
| 188 | * This configuration item sets the value of disconnect timeout |
| 189 | * Firmware delays sending the disconnec event to the host for this |
| 190 | * timeout after is gets disconnected from the current AP. |
| 191 | * If the firmware successly roams within the disconnect timeout |
| 192 | * it sends a new connect event |
| 193 | */ |
| 194 | #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10 |
| 195 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 196 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 197 | #define ATH6KL_DATA_OFFSET 64 |
| 198 | struct sk_buff *ath6kl_buf_alloc(int size) |
| 199 | { |
| 200 | struct sk_buff *skb; |
| 201 | u16 reserved; |
| 202 | |
| 203 | /* Add chacheline space at front and back of buffer */ |
Myoungje Kim | 6a3e4e0 | 2013-03-10 08:16:05 +0200 | [diff] [blame] | 204 | reserved = roundup((2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET + |
| 205 | sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES, 4); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 206 | skb = dev_alloc_skb(size + reserved); |
| 207 | |
| 208 | if (skb) |
| 209 | skb_reserve(skb, reserved - L1_CACHE_BYTES); |
| 210 | return skb; |
| 211 | } |
| 212 | |
Vasanthakumar Thiagarajan | e29f25f | 2011-10-25 19:34:15 +0530 | [diff] [blame] | 213 | void ath6kl_init_profile_info(struct ath6kl_vif *vif) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 214 | { |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 215 | vif->ssid_len = 0; |
| 216 | memset(vif->ssid, 0, sizeof(vif->ssid)); |
| 217 | |
| 218 | vif->dot11_auth_mode = OPEN_AUTH; |
| 219 | vif->auth_mode = NONE_AUTH; |
| 220 | vif->prwise_crypto = NONE_CRYPT; |
| 221 | vif->prwise_crypto_len = 0; |
| 222 | vif->grp_crypto = NONE_CRYPT; |
| 223 | vif->grp_crypto_len = 0; |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 224 | memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list)); |
Vasanthakumar Thiagarajan | 8c8b65e | 2011-10-25 19:34:04 +0530 | [diff] [blame] | 225 | memset(vif->req_bssid, 0, sizeof(vif->req_bssid)); |
| 226 | memset(vif->bssid, 0, sizeof(vif->bssid)); |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 227 | vif->bss_ch = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 228 | } |
| 229 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 230 | static int ath6kl_set_host_app_area(struct ath6kl *ar) |
| 231 | { |
| 232 | u32 address, data; |
| 233 | struct host_app_area host_app_area; |
| 234 | |
| 235 | /* Fetch the address of the host_app_area_s |
| 236 | * instance in the host interest area */ |
| 237 | address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest)); |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 238 | address = TARG_VTOP(ar->target_type, address); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 239 | |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 240 | if (ath6kl_diag_read32(ar, address, &data)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 241 | return -EIO; |
| 242 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 243 | address = TARG_VTOP(ar->target_type, data); |
Kalle Valo | cbf49a6 | 2011-10-05 12:23:17 +0300 | [diff] [blame] | 244 | host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION); |
Kalle Valo | addb44b | 2011-09-02 10:32:05 +0300 | [diff] [blame] | 245 | if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area, |
| 246 | sizeof(struct host_app_area))) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 247 | return -EIO; |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static inline void set_ac2_ep_map(struct ath6kl *ar, |
| 253 | u8 ac, |
| 254 | enum htc_endpoint_id ep) |
| 255 | { |
| 256 | ar->ac2ep_map[ac] = ep; |
| 257 | ar->ep2ac_map[ep] = ac; |
| 258 | } |
| 259 | |
| 260 | /* connect to a service */ |
| 261 | static int ath6kl_connectservice(struct ath6kl *ar, |
| 262 | struct htc_service_connect_req *con_req, |
| 263 | char *desc) |
| 264 | { |
| 265 | int status; |
| 266 | struct htc_service_connect_resp response; |
| 267 | |
| 268 | memset(&response, 0, sizeof(response)); |
| 269 | |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 270 | status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 271 | if (status) { |
| 272 | ath6kl_err("failed to connect to %s service status:%d\n", |
| 273 | desc, status); |
| 274 | return status; |
| 275 | } |
| 276 | |
| 277 | switch (con_req->svc_id) { |
| 278 | case WMI_CONTROL_SVC: |
| 279 | if (test_bit(WMI_ENABLED, &ar->flag)) |
| 280 | ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint); |
| 281 | ar->ctrl_ep = response.endpoint; |
| 282 | break; |
| 283 | case WMI_DATA_BE_SVC: |
| 284 | set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint); |
| 285 | break; |
| 286 | case WMI_DATA_BK_SVC: |
| 287 | set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint); |
| 288 | break; |
| 289 | case WMI_DATA_VI_SVC: |
| 290 | set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint); |
| 291 | break; |
| 292 | case WMI_DATA_VO_SVC: |
| 293 | set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint); |
| 294 | break; |
| 295 | default: |
| 296 | ath6kl_err("service id is not mapped %d\n", con_req->svc_id); |
| 297 | return -EINVAL; |
| 298 | } |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static int ath6kl_init_service_ep(struct ath6kl *ar) |
| 304 | { |
| 305 | struct htc_service_connect_req connect; |
| 306 | |
| 307 | memset(&connect, 0, sizeof(connect)); |
| 308 | |
| 309 | /* these fields are the same for all service endpoints */ |
Kalle Valo | 900d6b3 | 2012-03-25 17:15:23 +0300 | [diff] [blame] | 310 | connect.ep_cb.tx_comp_multi = ath6kl_tx_complete; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 311 | connect.ep_cb.rx = ath6kl_rx; |
| 312 | connect.ep_cb.rx_refill = ath6kl_rx_refill; |
| 313 | connect.ep_cb.tx_full = ath6kl_tx_queue_full; |
| 314 | |
| 315 | /* |
| 316 | * Set the max queue depth so that our ath6kl_tx_queue_full handler |
| 317 | * gets called. |
| 318 | */ |
| 319 | connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH; |
| 320 | connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4; |
| 321 | if (!connect.ep_cb.rx_refill_thresh) |
| 322 | connect.ep_cb.rx_refill_thresh++; |
| 323 | |
| 324 | /* connect to control service */ |
| 325 | connect.svc_id = WMI_CONTROL_SVC; |
| 326 | if (ath6kl_connectservice(ar, &connect, "WMI CONTROL")) |
| 327 | return -EIO; |
| 328 | |
| 329 | connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN; |
| 330 | |
| 331 | /* |
| 332 | * Limit the HTC message size on the send path, although e can |
| 333 | * receive A-MSDU frames of 4K, we will only send ethernet-sized |
| 334 | * (802.3) frames on the send path. |
| 335 | */ |
| 336 | connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH; |
| 337 | |
| 338 | /* |
| 339 | * To reduce the amount of committed memory for larger A_MSDU |
| 340 | * frames, use the recv-alloc threshold mechanism for larger |
| 341 | * packets. |
| 342 | */ |
| 343 | connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE; |
| 344 | connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf; |
| 345 | |
| 346 | /* |
| 347 | * For the remaining data services set the connection flag to |
| 348 | * reduce dribbling, if configured to do so. |
| 349 | */ |
| 350 | connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB; |
| 351 | connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK; |
| 352 | connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF; |
| 353 | |
| 354 | connect.svc_id = WMI_DATA_BE_SVC; |
| 355 | |
| 356 | if (ath6kl_connectservice(ar, &connect, "WMI DATA BE")) |
| 357 | return -EIO; |
| 358 | |
| 359 | /* connect to back-ground map this to WMI LOW_PRI */ |
| 360 | connect.svc_id = WMI_DATA_BK_SVC; |
| 361 | if (ath6kl_connectservice(ar, &connect, "WMI DATA BK")) |
| 362 | return -EIO; |
| 363 | |
Mohammed Shafi Shajakhan | 171fe76 | 2012-09-27 18:19:52 +0530 | [diff] [blame] | 364 | /* connect to Video service, map this to HI PRI */ |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 365 | connect.svc_id = WMI_DATA_VI_SVC; |
| 366 | if (ath6kl_connectservice(ar, &connect, "WMI DATA VI")) |
| 367 | return -EIO; |
| 368 | |
| 369 | /* |
| 370 | * Connect to VO service, this is currently not mapped to a WMI |
| 371 | * priority stream due to historical reasons. WMI originally |
| 372 | * defined 3 priorities over 3 mailboxes We can change this when |
| 373 | * WMI is reworked so that priorities are not dependent on |
| 374 | * mailboxes. |
| 375 | */ |
| 376 | connect.svc_id = WMI_DATA_VO_SVC; |
| 377 | if (ath6kl_connectservice(ar, &connect, "WMI DATA VO")) |
| 378 | return -EIO; |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
Vasanthakumar Thiagarajan | e29f25f | 2011-10-25 19:34:15 +0530 | [diff] [blame] | 383 | void ath6kl_init_control_info(struct ath6kl_vif *vif) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 384 | { |
Vasanthakumar Thiagarajan | e29f25f | 2011-10-25 19:34:15 +0530 | [diff] [blame] | 385 | ath6kl_init_profile_info(vif); |
Vasanthakumar Thiagarajan | 3450334 | 2011-10-25 19:34:02 +0530 | [diff] [blame] | 386 | vif->def_txkey_index = 0; |
Vasanthakumar Thiagarajan | 6f2a73f | 2011-10-25 19:34:06 +0530 | [diff] [blame] | 387 | memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list)); |
Vasanthakumar Thiagarajan | f74bac5 | 2011-10-25 19:34:05 +0530 | [diff] [blame] | 388 | vif->ch_hint = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Set HTC/Mbox operational parameters, this can only be called when the |
| 393 | * target is in the BMI phase. |
| 394 | */ |
| 395 | static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val, |
| 396 | u8 htc_ctrl_buf) |
| 397 | { |
| 398 | int status; |
| 399 | u32 blk_size; |
| 400 | |
| 401 | blk_size = ar->mbox_info.block_size; |
| 402 | |
| 403 | if (htc_ctrl_buf) |
| 404 | blk_size |= ((u32)htc_ctrl_buf) << 16; |
| 405 | |
| 406 | /* set the host interest area for the block size */ |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 407 | status = ath6kl_bmi_write_hi32(ar, hi_mbox_io_block_sz, blk_size); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 408 | if (status) { |
| 409 | ath6kl_err("bmi_write_memory for IO block size failed\n"); |
| 410 | goto out; |
| 411 | } |
| 412 | |
| 413 | ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n", |
| 414 | blk_size, |
| 415 | ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz))); |
| 416 | |
| 417 | if (mbox_isr_yield_val) { |
| 418 | /* set the host interest area for the mbox ISR yield limit */ |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 419 | status = ath6kl_bmi_write_hi32(ar, hi_mbox_isr_yield_limit, |
| 420 | mbox_isr_yield_val); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 421 | if (status) { |
| 422 | ath6kl_err("bmi_write_memory for yield limit failed\n"); |
| 423 | goto out; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | out: |
| 428 | return status; |
| 429 | } |
| 430 | |
Vasanthakumar Thiagarajan | 0ce5944 | 2011-10-25 19:34:25 +0530 | [diff] [blame] | 431 | static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 432 | { |
Jouni Malinen | 4dea08e | 2011-08-30 21:57:57 +0300 | [diff] [blame] | 433 | int ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 434 | |
| 435 | /* |
| 436 | * Configure the device for rx dot11 header rules. "0,0" are the |
| 437 | * default values. Required if checksum offload is needed. Set |
| 438 | * RxMetaVersion to 2. |
| 439 | */ |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 440 | ret = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx, |
| 441 | ar->rx_meta_ver, 0, 0); |
| 442 | if (ret) { |
| 443 | ath6kl_err("unable to set the rx frame format: %d\n", ret); |
| 444 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 445 | } |
| 446 | |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 447 | if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN) { |
| 448 | ret = ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1, |
Kalle Valo | 05aab17 | 2012-03-07 20:04:00 +0200 | [diff] [blame] | 449 | IGNORE_PS_FAIL_DURING_SCAN); |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 450 | if (ret) { |
| 451 | ath6kl_err("unable to set power save fail event policy: %d\n", |
| 452 | ret); |
| 453 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 454 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 455 | } |
| 456 | |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 457 | if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER)) { |
| 458 | ret = ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0, |
Kalle Valo | 05aab17 | 2012-03-07 20:04:00 +0200 | [diff] [blame] | 459 | WMI_FOLLOW_BARKER_IN_ERP); |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 460 | if (ret) { |
| 461 | ath6kl_err("unable to set barker preamble policy: %d\n", |
| 462 | ret); |
| 463 | return ret; |
| 464 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 465 | } |
| 466 | |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 467 | ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx, |
| 468 | WLAN_CONFIG_KEEP_ALIVE_INTERVAL); |
| 469 | if (ret) { |
| 470 | ath6kl_err("unable to set keep alive interval: %d\n", ret); |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, idx, |
| 475 | WLAN_CONFIG_DISCONNECT_TIMEOUT); |
| 476 | if (ret) { |
| 477 | ath6kl_err("unable to set disconnect timeout: %d\n", ret); |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST)) { |
| 482 | ret = ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED); |
| 483 | if (ret) { |
| 484 | ath6kl_err("unable to set txop bursting: %d\n", ret); |
| 485 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 486 | } |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 487 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 488 | |
Vasanthakumar Thiagarajan | b64de35 | 2011-11-18 10:05:28 +0530 | [diff] [blame] | 489 | if (ar->p2p && (ar->vif_max == 1 || idx)) { |
Vasanthakumar Thiagarajan | 0ce5944 | 2011-10-25 19:34:25 +0530 | [diff] [blame] | 490 | ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx, |
Jouni Malinen | 6bbc7c3 | 2011-09-05 17:38:47 +0300 | [diff] [blame] | 491 | P2P_FLAG_CAPABILITIES_REQ | |
| 492 | P2P_FLAG_MACADDR_REQ | |
| 493 | P2P_FLAG_HMODEL_REQ); |
| 494 | if (ret) { |
Kalle Valo | cdeb860 | 2012-04-12 11:02:18 +0300 | [diff] [blame] | 495 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 496 | "failed to request P2P capabilities (%d) - assuming P2P not supported\n", |
| 497 | ret); |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 498 | ar->p2p = false; |
Jouni Malinen | 6bbc7c3 | 2011-09-05 17:38:47 +0300 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Vasanthakumar Thiagarajan | b64de35 | 2011-11-18 10:05:28 +0530 | [diff] [blame] | 502 | if (ar->p2p && (ar->vif_max == 1 || idx)) { |
Jouni Malinen | 6bbc7c3 | 2011-09-05 17:38:47 +0300 | [diff] [blame] | 503 | /* Enable Probe Request reporting for P2P */ |
Vasanthakumar Thiagarajan | 0ce5944 | 2011-10-25 19:34:25 +0530 | [diff] [blame] | 504 | ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true); |
Jouni Malinen | 6bbc7c3 | 2011-09-05 17:38:47 +0300 | [diff] [blame] | 505 | if (ret) { |
Kalle Valo | cdeb860 | 2012-04-12 11:02:18 +0300 | [diff] [blame] | 506 | ath6kl_dbg(ATH6KL_DBG_TRC, |
| 507 | "failed to enable Probe Request reporting (%d)\n", |
| 508 | ret); |
Jouni Malinen | 6bbc7c3 | 2011-09-05 17:38:47 +0300 | [diff] [blame] | 509 | } |
Jouni Malinen | 4dea08e | 2011-08-30 21:57:57 +0300 | [diff] [blame] | 510 | } |
| 511 | |
Kalle Valo | 1ca4d0b | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 512 | return ret; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | int ath6kl_configure_target(struct ath6kl *ar) |
| 516 | { |
| 517 | u32 param, ram_reserved_size; |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 518 | u8 fw_iftype, fw_mode = 0, fw_submode = 0; |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 519 | int i, status; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 520 | |
Kalle Valo | f29af97 | 2012-01-17 20:08:56 +0200 | [diff] [blame] | 521 | param = !!(ar->conf_flags & ATH6KL_CONF_UART_DEBUG); |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 522 | if (ath6kl_bmi_write_hi32(ar, hi_serial_enable, param)) { |
Vasanthakumar Thiagarajan | a10e2f2 | 2011-12-29 16:05:38 +0530 | [diff] [blame] | 523 | ath6kl_err("bmi_write_memory for uart debug failed\n"); |
| 524 | return -EIO; |
| 525 | } |
| 526 | |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 527 | /* |
| 528 | * Note: Even though the firmware interface type is |
| 529 | * chosen as BSS_STA for all three interfaces, can |
| 530 | * be configured to IBSS/AP as long as the fw submode |
| 531 | * remains normal mode (0 - AP, STA and IBSS). But |
| 532 | * due to an target assert in firmware only one interface is |
| 533 | * configured for now. |
| 534 | */ |
Vasanthakumar Thiagarajan | dd3751f | 2011-10-25 19:33:59 +0530 | [diff] [blame] | 535 | fw_iftype = HI_OPTION_FW_MODE_BSS_STA; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 536 | |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 537 | for (i = 0; i < ar->vif_max; i++) |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 538 | fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS); |
| 539 | |
| 540 | /* |
Vasanthakumar Thiagarajan | 1e8d13b | 2012-04-06 20:24:30 +0530 | [diff] [blame] | 541 | * Submodes when fw does not support dynamic interface |
| 542 | * switching: |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 543 | * vif[0] - AP/STA/IBSS |
| 544 | * vif[1] - "P2P dev"/"P2P GO"/"P2P Client" |
| 545 | * vif[2] - "P2P dev"/"P2P GO"/"P2P Client" |
Vasanthakumar Thiagarajan | 1e8d13b | 2012-04-06 20:24:30 +0530 | [diff] [blame] | 546 | * Otherwise, All the interface are initialized to p2p dev. |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 547 | */ |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 548 | |
Vasanthakumar Thiagarajan | 1e8d13b | 2012-04-06 20:24:30 +0530 | [diff] [blame] | 549 | if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, |
| 550 | ar->fw_capabilities)) { |
| 551 | for (i = 0; i < ar->vif_max; i++) |
| 552 | fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV << |
| 553 | (i * HI_OPTION_FW_SUBMODE_BITS); |
| 554 | } else { |
| 555 | for (i = 0; i < ar->max_norm_iface; i++) |
| 556 | fw_submode |= HI_OPTION_FW_SUBMODE_NONE << |
| 557 | (i * HI_OPTION_FW_SUBMODE_BITS); |
Vasanthakumar Thiagarajan | 3226f68a | 2011-10-25 19:34:24 +0530 | [diff] [blame] | 558 | |
Vasanthakumar Thiagarajan | 1e8d13b | 2012-04-06 20:24:30 +0530 | [diff] [blame] | 559 | for (i = ar->max_norm_iface; i < ar->vif_max; i++) |
| 560 | fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV << |
| 561 | (i * HI_OPTION_FW_SUBMODE_BITS); |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 562 | |
Vasanthakumar Thiagarajan | 1e8d13b | 2012-04-06 20:24:30 +0530 | [diff] [blame] | 563 | if (ar->p2p && ar->vif_max == 1) |
| 564 | fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV; |
| 565 | } |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 566 | |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 567 | if (ath6kl_bmi_write_hi32(ar, hi_app_host_interest, |
| 568 | HTC_PROTOCOL_VERSION) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 569 | ath6kl_err("bmi_write_memory for htc version failed\n"); |
| 570 | return -EIO; |
| 571 | } |
| 572 | |
| 573 | /* set the firmware mode to STA/IBSS/AP */ |
| 574 | param = 0; |
| 575 | |
Kalle Valo | 80fb268 | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 576 | if (ath6kl_bmi_read_hi32(ar, hi_option_flag, ¶m) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 577 | ath6kl_err("bmi_read_memory for setting fwmode failed\n"); |
| 578 | return -EIO; |
| 579 | } |
| 580 | |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 581 | param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT); |
Vasanthakumar Thiagarajan | 7b85832 | 2011-10-25 19:34:22 +0530 | [diff] [blame] | 582 | param |= fw_mode << HI_OPTION_FW_MODE_SHIFT; |
| 583 | param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT; |
| 584 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 585 | param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT); |
| 586 | param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT); |
| 587 | |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 588 | if (ath6kl_bmi_write_hi32(ar, hi_option_flag, param) != 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 589 | ath6kl_err("bmi_write_memory for setting fwmode failed\n"); |
| 590 | return -EIO; |
| 591 | } |
| 592 | |
| 593 | ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n"); |
| 594 | |
| 595 | /* |
| 596 | * Hardcode the address use for the extended board data |
| 597 | * Ideally this should be pre-allocate by the OS at boot time |
| 598 | * But since it is a new feature and board data is loaded |
| 599 | * at init time, we have to workaround this from host. |
| 600 | * It is difficult to patch the firmware boot code, |
| 601 | * but possible in theory. |
| 602 | */ |
| 603 | |
Kalle Valo | 6b42d30 | 2012-03-25 17:15:21 +0300 | [diff] [blame] | 604 | if (ar->target_type == TARGET_TYPE_AR6003) { |
| 605 | param = ar->hw.board_ext_data_addr; |
| 606 | ram_reserved_size = ar->hw.reserved_ram_size; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 607 | |
Kalle Valo | 6b42d30 | 2012-03-25 17:15:21 +0300 | [diff] [blame] | 608 | if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) { |
| 609 | ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n"); |
| 610 | return -EIO; |
| 611 | } |
Kalle Valo | 991b27e | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 612 | |
Kalle Valo | 6b42d30 | 2012-03-25 17:15:21 +0300 | [diff] [blame] | 613 | if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, |
| 614 | ram_reserved_size) != 0) { |
| 615 | ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n"); |
| 616 | return -EIO; |
| 617 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* set the block size for the target */ |
| 621 | if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0)) |
| 622 | /* use default number of control buffers */ |
| 623 | return -EIO; |
| 624 | |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 625 | /* Configure GPIO AR600x UART */ |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 626 | status = ath6kl_bmi_write_hi32(ar, hi_dbg_uart_txpin, |
| 627 | ar->hw.uarttx_pin); |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 628 | if (status) |
| 629 | return status; |
| 630 | |
| 631 | /* Configure target refclk_hz */ |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 632 | status = ath6kl_bmi_write_hi32(ar, hi_refclk_hz, ar->hw.refclk_hz); |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 633 | if (status) |
| 634 | return status; |
| 635 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 639 | /* firmware upload */ |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 640 | static int ath6kl_get_fw(struct ath6kl *ar, const char *filename, |
| 641 | u8 **fw, size_t *fw_len) |
| 642 | { |
| 643 | const struct firmware *fw_entry; |
| 644 | int ret; |
| 645 | |
| 646 | ret = request_firmware(&fw_entry, filename, ar->dev); |
| 647 | if (ret) |
| 648 | return ret; |
| 649 | |
| 650 | *fw_len = fw_entry->size; |
| 651 | *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL); |
| 652 | |
| 653 | if (*fw == NULL) |
| 654 | ret = -ENOMEM; |
| 655 | |
| 656 | release_firmware(fw_entry); |
| 657 | |
| 658 | return ret; |
| 659 | } |
| 660 | |
Sam Leffler | 92ecbff | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 661 | #ifdef CONFIG_OF |
Sam Leffler | 92ecbff | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 662 | /* |
| 663 | * Check the device tree for a board-id and use it to construct |
| 664 | * the pathname to the firmware file. Used (for now) to find a |
| 665 | * fallback to the "bdata.bin" file--typically a symlink to the |
| 666 | * appropriate board-specific file. |
| 667 | */ |
| 668 | static bool check_device_tree(struct ath6kl *ar) |
| 669 | { |
| 670 | static const char *board_id_prop = "atheros,board-id"; |
| 671 | struct device_node *node; |
| 672 | char board_filename[64]; |
| 673 | const char *board_id; |
| 674 | int ret; |
| 675 | |
| 676 | for_each_compatible_node(node, NULL, "atheros,ath6kl") { |
| 677 | board_id = of_get_property(node, board_id_prop, NULL); |
| 678 | if (board_id == NULL) { |
| 679 | ath6kl_warn("No \"%s\" property on %s node.\n", |
| 680 | board_id_prop, node->name); |
| 681 | continue; |
| 682 | } |
| 683 | snprintf(board_filename, sizeof(board_filename), |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 684 | "%s/bdata.%s.bin", ar->hw.fw.dir, board_id); |
Sam Leffler | 92ecbff | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 685 | |
| 686 | ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board, |
| 687 | &ar->fw_board_len); |
| 688 | if (ret) { |
| 689 | ath6kl_err("Failed to get DT board file %s: %d\n", |
| 690 | board_filename, ret); |
| 691 | continue; |
| 692 | } |
| 693 | return true; |
| 694 | } |
| 695 | return false; |
| 696 | } |
| 697 | #else |
| 698 | static bool check_device_tree(struct ath6kl *ar) |
| 699 | { |
| 700 | return false; |
| 701 | } |
| 702 | #endif /* CONFIG_OF */ |
| 703 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 704 | static int ath6kl_fetch_board_file(struct ath6kl *ar) |
| 705 | { |
| 706 | const char *filename; |
| 707 | int ret; |
| 708 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 709 | if (ar->fw_board != NULL) |
| 710 | return 0; |
| 711 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 712 | if (WARN_ON(ar->hw.fw_board == NULL)) |
| 713 | return -EINVAL; |
| 714 | |
| 715 | filename = ar->hw.fw_board; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 716 | |
| 717 | ret = ath6kl_get_fw(ar, filename, &ar->fw_board, |
| 718 | &ar->fw_board_len); |
| 719 | if (ret == 0) { |
| 720 | /* managed to get proper board file */ |
| 721 | return 0; |
| 722 | } |
| 723 | |
Sam Leffler | 92ecbff | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 724 | if (check_device_tree(ar)) { |
| 725 | /* got board file from device tree */ |
| 726 | return 0; |
| 727 | } |
| 728 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 729 | /* there was no proper board file, try to use default instead */ |
| 730 | ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n", |
| 731 | filename, ret); |
| 732 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 733 | filename = ar->hw.fw_default_board; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 734 | |
| 735 | ret = ath6kl_get_fw(ar, filename, &ar->fw_board, |
| 736 | &ar->fw_board_len); |
| 737 | if (ret) { |
| 738 | ath6kl_err("Failed to get default board file %s: %d\n", |
| 739 | filename, ret); |
| 740 | return ret; |
| 741 | } |
| 742 | |
| 743 | ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n"); |
| 744 | ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n"); |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 749 | static int ath6kl_fetch_otp_file(struct ath6kl *ar) |
| 750 | { |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 751 | char filename[100]; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 752 | int ret; |
| 753 | |
| 754 | if (ar->fw_otp != NULL) |
| 755 | return 0; |
| 756 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 757 | if (ar->hw.fw.otp == NULL) { |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 758 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 759 | "no OTP file configured for this hw\n"); |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 760 | return 0; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 761 | } |
| 762 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 763 | snprintf(filename, sizeof(filename), "%s/%s", |
| 764 | ar->hw.fw.dir, ar->hw.fw.otp); |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 765 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 766 | ret = ath6kl_get_fw(ar, filename, &ar->fw_otp, |
| 767 | &ar->fw_otp_len); |
| 768 | if (ret) { |
| 769 | ath6kl_err("Failed to get OTP file %s: %d\n", |
| 770 | filename, ret); |
| 771 | return ret; |
| 772 | } |
| 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
Kalle Valo | 5f1127f | 2012-01-24 13:50:16 +0200 | [diff] [blame] | 777 | static int ath6kl_fetch_testmode_file(struct ath6kl *ar) |
| 778 | { |
| 779 | char filename[100]; |
| 780 | int ret; |
| 781 | |
| 782 | if (ar->testmode == 0) |
| 783 | return 0; |
| 784 | |
| 785 | ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n", ar->testmode); |
| 786 | |
| 787 | if (ar->testmode == 2) { |
| 788 | if (ar->hw.fw.utf == NULL) { |
| 789 | ath6kl_warn("testmode 2 not supported\n"); |
| 790 | return -EOPNOTSUPP; |
| 791 | } |
| 792 | |
| 793 | snprintf(filename, sizeof(filename), "%s/%s", |
| 794 | ar->hw.fw.dir, ar->hw.fw.utf); |
| 795 | } else { |
| 796 | if (ar->hw.fw.tcmd == NULL) { |
| 797 | ath6kl_warn("testmode 1 not supported\n"); |
| 798 | return -EOPNOTSUPP; |
| 799 | } |
| 800 | |
| 801 | snprintf(filename, sizeof(filename), "%s/%s", |
| 802 | ar->hw.fw.dir, ar->hw.fw.tcmd); |
| 803 | } |
| 804 | |
| 805 | set_bit(TESTMODE, &ar->flag); |
| 806 | |
| 807 | ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len); |
| 808 | if (ret) { |
| 809 | ath6kl_err("Failed to get testmode %d firmware file %s: %d\n", |
| 810 | ar->testmode, filename, ret); |
| 811 | return ret; |
| 812 | } |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 817 | static int ath6kl_fetch_fw_file(struct ath6kl *ar) |
| 818 | { |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 819 | char filename[100]; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 820 | int ret; |
| 821 | |
| 822 | if (ar->fw != NULL) |
| 823 | return 0; |
| 824 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 825 | /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */ |
| 826 | if (WARN_ON(ar->hw.fw.fw == NULL)) |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 827 | return -EINVAL; |
| 828 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 829 | snprintf(filename, sizeof(filename), "%s/%s", |
| 830 | ar->hw.fw.dir, ar->hw.fw.fw); |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 831 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 832 | ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len); |
| 833 | if (ret) { |
| 834 | ath6kl_err("Failed to get firmware file %s: %d\n", |
| 835 | filename, ret); |
| 836 | return ret; |
| 837 | } |
| 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static int ath6kl_fetch_patch_file(struct ath6kl *ar) |
| 843 | { |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 844 | char filename[100]; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 845 | int ret; |
| 846 | |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 847 | if (ar->fw_patch != NULL) |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 848 | return 0; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 849 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 850 | if (ar->hw.fw.patch == NULL) |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 851 | return 0; |
| 852 | |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 853 | snprintf(filename, sizeof(filename), "%s/%s", |
| 854 | ar->hw.fw.dir, ar->hw.fw.patch); |
Kalle Valo | d1a9421 | 2011-11-14 19:31:23 +0200 | [diff] [blame] | 855 | |
| 856 | ret = ath6kl_get_fw(ar, filename, &ar->fw_patch, |
| 857 | &ar->fw_patch_len); |
| 858 | if (ret) { |
| 859 | ath6kl_err("Failed to get patch file %s: %d\n", |
| 860 | filename, ret); |
| 861 | return ret; |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 867 | static int ath6kl_fetch_testscript_file(struct ath6kl *ar) |
| 868 | { |
| 869 | char filename[100]; |
| 870 | int ret; |
| 871 | |
Kalle Valo | 5f1127f | 2012-01-24 13:50:16 +0200 | [diff] [blame] | 872 | if (ar->testmode != 2) |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 873 | return 0; |
| 874 | |
| 875 | if (ar->fw_testscript != NULL) |
| 876 | return 0; |
| 877 | |
| 878 | if (ar->hw.fw.testscript == NULL) |
| 879 | return 0; |
| 880 | |
| 881 | snprintf(filename, sizeof(filename), "%s/%s", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 882 | ar->hw.fw.dir, ar->hw.fw.testscript); |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 883 | |
| 884 | ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript, |
| 885 | &ar->fw_testscript_len); |
| 886 | if (ret) { |
| 887 | ath6kl_err("Failed to get testscript file %s: %d\n", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 888 | filename, ret); |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 889 | return ret; |
| 890 | } |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 895 | static int ath6kl_fetch_fw_api1(struct ath6kl *ar) |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 896 | { |
| 897 | int ret; |
| 898 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 899 | ret = ath6kl_fetch_otp_file(ar); |
| 900 | if (ret) |
| 901 | return ret; |
| 902 | |
| 903 | ret = ath6kl_fetch_fw_file(ar); |
| 904 | if (ret) |
| 905 | return ret; |
| 906 | |
| 907 | ret = ath6kl_fetch_patch_file(ar); |
| 908 | if (ret) |
| 909 | return ret; |
| 910 | |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 911 | ret = ath6kl_fetch_testscript_file(ar); |
| 912 | if (ret) |
| 913 | return ret; |
| 914 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 915 | return 0; |
| 916 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 917 | |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 918 | static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name) |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 919 | { |
| 920 | size_t magic_len, len, ie_len; |
| 921 | const struct firmware *fw; |
| 922 | struct ath6kl_fw_ie *hdr; |
Kalle Valo | c003897 | 2011-12-16 20:53:31 +0200 | [diff] [blame] | 923 | char filename[100]; |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 924 | const u8 *data; |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 925 | int ret, ie_id, i, index, bit; |
Kalle Valo | 8a13748 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 926 | __le32 *val; |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 927 | |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 928 | snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name); |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 929 | |
| 930 | ret = request_firmware(&fw, filename, ar->dev); |
| 931 | if (ret) |
| 932 | return ret; |
| 933 | |
| 934 | data = fw->data; |
| 935 | len = fw->size; |
| 936 | |
| 937 | /* magic also includes the null byte, check that as well */ |
| 938 | magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1; |
| 939 | |
| 940 | if (len < magic_len) { |
| 941 | ret = -EINVAL; |
| 942 | goto out; |
| 943 | } |
| 944 | |
| 945 | if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) { |
| 946 | ret = -EINVAL; |
| 947 | goto out; |
| 948 | } |
| 949 | |
| 950 | len -= magic_len; |
| 951 | data += magic_len; |
| 952 | |
| 953 | /* loop elements */ |
| 954 | while (len > sizeof(struct ath6kl_fw_ie)) { |
| 955 | /* hdr is unaligned! */ |
| 956 | hdr = (struct ath6kl_fw_ie *) data; |
| 957 | |
| 958 | ie_id = le32_to_cpup(&hdr->id); |
| 959 | ie_len = le32_to_cpup(&hdr->len); |
| 960 | |
| 961 | len -= sizeof(*hdr); |
| 962 | data += sizeof(*hdr); |
| 963 | |
| 964 | if (len < ie_len) { |
| 965 | ret = -EINVAL; |
| 966 | goto out; |
| 967 | } |
| 968 | |
| 969 | switch (ie_id) { |
Naveen Singh | b5b6f6a | 2012-06-07 00:44:02 -0700 | [diff] [blame] | 970 | case ATH6KL_FW_IE_FW_VERSION: |
| 971 | strlcpy(ar->wiphy->fw_version, data, |
| 972 | sizeof(ar->wiphy->fw_version)); |
| 973 | |
| 974 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 975 | "found fw version %s\n", |
| 976 | ar->wiphy->fw_version); |
| 977 | break; |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 978 | case ATH6KL_FW_IE_OTP_IMAGE: |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 979 | ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 980 | ie_len); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 981 | |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 982 | ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL); |
| 983 | |
| 984 | if (ar->fw_otp == NULL) { |
| 985 | ret = -ENOMEM; |
| 986 | goto out; |
| 987 | } |
| 988 | |
| 989 | ar->fw_otp_len = ie_len; |
| 990 | break; |
| 991 | case ATH6KL_FW_IE_FW_IMAGE: |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 992 | ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 993 | ie_len); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 994 | |
Kalle Valo | 5f1127f | 2012-01-24 13:50:16 +0200 | [diff] [blame] | 995 | /* in testmode we already might have a fw file */ |
| 996 | if (ar->fw != NULL) |
| 997 | break; |
| 998 | |
Vivek Natarajan | 8437754 | 2012-03-28 19:21:25 +0530 | [diff] [blame] | 999 | ar->fw = vmalloc(ie_len); |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1000 | |
| 1001 | if (ar->fw == NULL) { |
| 1002 | ret = -ENOMEM; |
| 1003 | goto out; |
| 1004 | } |
| 1005 | |
Vivek Natarajan | 8437754 | 2012-03-28 19:21:25 +0530 | [diff] [blame] | 1006 | memcpy(ar->fw, data, ie_len); |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1007 | ar->fw_len = ie_len; |
| 1008 | break; |
| 1009 | case ATH6KL_FW_IE_PATCH_IMAGE: |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 1010 | ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1011 | ie_len); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1012 | |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1013 | ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL); |
| 1014 | |
| 1015 | if (ar->fw_patch == NULL) { |
| 1016 | ret = -ENOMEM; |
| 1017 | goto out; |
| 1018 | } |
| 1019 | |
| 1020 | ar->fw_patch_len = ie_len; |
| 1021 | break; |
Kalle Valo | 8a13748 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1022 | case ATH6KL_FW_IE_RESERVED_RAM_SIZE: |
| 1023 | val = (__le32 *) data; |
| 1024 | ar->hw.reserved_ram_size = le32_to_cpup(val); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1025 | |
| 1026 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1027 | "found reserved ram size ie 0x%d\n", |
| 1028 | ar->hw.reserved_ram_size); |
Kalle Valo | 8a13748 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1029 | break; |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 1030 | case ATH6KL_FW_IE_CAPABILITIES: |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1031 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 1032 | "found firmware capabilities ie (%zd B)\n", |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1033 | ie_len); |
| 1034 | |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 1035 | for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) { |
Kalle Valo | 277d90f | 2011-12-13 14:51:58 +0200 | [diff] [blame] | 1036 | index = i / 8; |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 1037 | bit = i % 8; |
| 1038 | |
Thomas Pedersen | c85251f | 2012-06-11 13:36:12 -0700 | [diff] [blame] | 1039 | if (index == ie_len) |
| 1040 | break; |
| 1041 | |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 1042 | if (data[index] & (1 << bit)) |
| 1043 | __set_bit(i, ar->fw_capabilities); |
| 1044 | } |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1045 | |
| 1046 | ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "", |
| 1047 | ar->fw_capabilities, |
| 1048 | sizeof(ar->fw_capabilities)); |
Kalle Valo | 97e0496 | 2011-09-12 13:47:34 +0300 | [diff] [blame] | 1049 | break; |
Kalle Valo | 1b4304d | 2011-09-27 11:05:26 +0300 | [diff] [blame] | 1050 | case ATH6KL_FW_IE_PATCH_ADDR: |
| 1051 | if (ie_len != sizeof(*val)) |
| 1052 | break; |
| 1053 | |
| 1054 | val = (__le32 *) data; |
| 1055 | ar->hw.dataset_patch_addr = le32_to_cpup(val); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1056 | |
| 1057 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
Kalle Valo | 03ef025 | 2011-11-14 19:30:47 +0200 | [diff] [blame] | 1058 | "found patch address ie 0x%x\n", |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1059 | ar->hw.dataset_patch_addr); |
Kalle Valo | 1b4304d | 2011-09-27 11:05:26 +0300 | [diff] [blame] | 1060 | break; |
Kalle Valo | 03ef025 | 2011-11-14 19:30:47 +0200 | [diff] [blame] | 1061 | case ATH6KL_FW_IE_BOARD_ADDR: |
| 1062 | if (ie_len != sizeof(*val)) |
| 1063 | break; |
| 1064 | |
| 1065 | val = (__le32 *) data; |
| 1066 | ar->hw.board_addr = le32_to_cpup(val); |
| 1067 | |
| 1068 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1069 | "found board address ie 0x%x\n", |
| 1070 | ar->hw.board_addr); |
| 1071 | break; |
Kalle Valo | 368b1b0 | 2011-11-14 19:31:38 +0200 | [diff] [blame] | 1072 | case ATH6KL_FW_IE_VIF_MAX: |
| 1073 | if (ie_len != sizeof(*val)) |
| 1074 | break; |
| 1075 | |
| 1076 | val = (__le32 *) data; |
| 1077 | ar->vif_max = min_t(unsigned int, le32_to_cpup(val), |
| 1078 | ATH6KL_VIF_MAX); |
| 1079 | |
Vasanthakumar Thiagarajan | f143379 | 2011-11-18 10:05:27 +0530 | [diff] [blame] | 1080 | if (ar->vif_max > 1 && !ar->p2p) |
| 1081 | ar->max_norm_iface = 2; |
| 1082 | |
Kalle Valo | 368b1b0 | 2011-11-14 19:31:38 +0200 | [diff] [blame] | 1083 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1084 | "found vif max ie %d\n", ar->vif_max); |
| 1085 | break; |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1086 | default: |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1087 | ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n", |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1088 | le32_to_cpup(&hdr->id)); |
| 1089 | break; |
| 1090 | } |
| 1091 | |
| 1092 | len -= ie_len; |
| 1093 | data += ie_len; |
| 1094 | }; |
| 1095 | |
| 1096 | ret = 0; |
| 1097 | out: |
| 1098 | release_firmware(fw); |
| 1099 | |
| 1100 | return ret; |
| 1101 | } |
| 1102 | |
Kalle Valo | 45eaa78 | 2012-01-17 20:09:05 +0200 | [diff] [blame] | 1103 | int ath6kl_init_fetch_firmwares(struct ath6kl *ar) |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1104 | { |
| 1105 | int ret; |
| 1106 | |
| 1107 | ret = ath6kl_fetch_board_file(ar); |
| 1108 | if (ret) |
| 1109 | return ret; |
| 1110 | |
Kalle Valo | 5f1127f | 2012-01-24 13:50:16 +0200 | [diff] [blame] | 1111 | ret = ath6kl_fetch_testmode_file(ar); |
| 1112 | if (ret) |
| 1113 | return ret; |
| 1114 | |
Thomas Pedersen | b1f47e3 | 2012-08-15 16:51:24 -0700 | [diff] [blame] | 1115 | ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API4_FILE); |
| 1116 | if (ret == 0) { |
| 1117 | ar->fw_api = 4; |
| 1118 | goto out; |
| 1119 | } |
| 1120 | |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 1121 | ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1122 | if (ret == 0) { |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 1123 | ar->fw_api = 3; |
| 1124 | goto out; |
| 1125 | } |
| 1126 | |
| 1127 | ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE); |
| 1128 | if (ret == 0) { |
| 1129 | ar->fw_api = 2; |
| 1130 | goto out; |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1131 | } |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1132 | |
| 1133 | ret = ath6kl_fetch_fw_api1(ar); |
| 1134 | if (ret) |
| 1135 | return ret; |
| 1136 | |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 1137 | ar->fw_api = 1; |
| 1138 | |
| 1139 | out: |
| 1140 | ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1141 | |
Kalle Valo | 50d4123 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1142 | return 0; |
| 1143 | } |
| 1144 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1145 | static int ath6kl_upload_board_file(struct ath6kl *ar) |
| 1146 | { |
| 1147 | u32 board_address, board_ext_address, param; |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1148 | u32 board_data_size, board_ext_data_size; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1149 | int ret; |
| 1150 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 1151 | if (WARN_ON(ar->fw_board == NULL)) |
| 1152 | return -ENOENT; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1153 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1154 | /* |
| 1155 | * Determine where in Target RAM to write Board Data. |
| 1156 | * For AR6004, host determine Target RAM address for |
| 1157 | * writing board data. |
| 1158 | */ |
Kalle Valo | 0d4d72b | 2011-11-14 19:30:39 +0200 | [diff] [blame] | 1159 | if (ar->hw.board_addr != 0) { |
Kalle Valo | b0fc7c1 | 2012-03-12 13:22:54 +0200 | [diff] [blame] | 1160 | board_address = ar->hw.board_addr; |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1161 | ath6kl_bmi_write_hi32(ar, hi_board_data, |
Kalle Valo | b0fc7c1 | 2012-03-12 13:22:54 +0200 | [diff] [blame] | 1162 | board_address); |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1163 | } else { |
Frederic Danis | 1c3d95e | 2014-06-02 21:19:46 +0300 | [diff] [blame^] | 1164 | ret = ath6kl_bmi_read_hi32(ar, hi_board_data, &board_address); |
| 1165 | if (ret) { |
| 1166 | ath6kl_err("Failed to get board file target address.\n"); |
| 1167 | return ret; |
| 1168 | } |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1171 | /* determine where in target ram to write extended board data */ |
Frederic Danis | 1c3d95e | 2014-06-02 21:19:46 +0300 | [diff] [blame^] | 1172 | ret = ath6kl_bmi_read_hi32(ar, hi_board_ext_data, &board_ext_address); |
| 1173 | if (ret) { |
| 1174 | ath6kl_err("Failed to get extended board file target address.\n"); |
| 1175 | return ret; |
| 1176 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1177 | |
Kalle Valo | 50e2740 | 2011-11-11 12:18:06 +0200 | [diff] [blame] | 1178 | if (ar->target_type == TARGET_TYPE_AR6003 && |
| 1179 | board_ext_address == 0) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1180 | ath6kl_err("Failed to get board file target address.\n"); |
| 1181 | return -EINVAL; |
| 1182 | } |
| 1183 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1184 | switch (ar->target_type) { |
| 1185 | case TARGET_TYPE_AR6003: |
| 1186 | board_data_size = AR6003_BOARD_DATA_SZ; |
| 1187 | board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ; |
Prasanna Kumar | fb1ac2e | 2012-02-07 14:58:54 -0800 | [diff] [blame] | 1188 | if (ar->fw_board_len > (board_data_size + board_ext_data_size)) |
| 1189 | board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ_V2; |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1190 | break; |
| 1191 | case TARGET_TYPE_AR6004: |
| 1192 | board_data_size = AR6004_BOARD_DATA_SZ; |
| 1193 | board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ; |
| 1194 | break; |
| 1195 | default: |
| 1196 | WARN_ON(1); |
| 1197 | return -EINVAL; |
| 1198 | break; |
| 1199 | } |
| 1200 | |
Kalle Valo | 50e2740 | 2011-11-11 12:18:06 +0200 | [diff] [blame] | 1201 | if (board_ext_address && |
| 1202 | ar->fw_board_len == (board_data_size + board_ext_data_size)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1203 | /* write extended board data */ |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1204 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1205 | "writing extended board data to 0x%x (%d B)\n", |
| 1206 | board_ext_address, board_ext_data_size); |
| 1207 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1208 | ret = ath6kl_bmi_write(ar, board_ext_address, |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1209 | ar->fw_board + board_data_size, |
| 1210 | board_ext_data_size); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1211 | if (ret) { |
| 1212 | ath6kl_err("Failed to write extended board data: %d\n", |
| 1213 | ret); |
| 1214 | return ret; |
| 1215 | } |
| 1216 | |
| 1217 | /* record that extended board data is initialized */ |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1218 | param = (board_ext_data_size << 16) | 1; |
| 1219 | |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1220 | ath6kl_bmi_write_hi32(ar, hi_board_ext_data_config, param); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1221 | } |
| 1222 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1223 | if (ar->fw_board_len < board_data_size) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1224 | ath6kl_err("Too small board file: %zu\n", ar->fw_board_len); |
| 1225 | ret = -EINVAL; |
| 1226 | return ret; |
| 1227 | } |
| 1228 | |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1229 | ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n", |
| 1230 | board_address, board_data_size); |
| 1231 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1232 | ret = ath6kl_bmi_write(ar, board_address, ar->fw_board, |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1233 | board_data_size); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1234 | |
| 1235 | if (ret) { |
| 1236 | ath6kl_err("Board file bmi write failed: %d\n", ret); |
| 1237 | return ret; |
| 1238 | } |
| 1239 | |
| 1240 | /* record the fact that Board Data IS initialized */ |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1241 | ath6kl_bmi_write_hi32(ar, hi_board_data_initialized, 1); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1242 | |
| 1243 | return ret; |
| 1244 | } |
| 1245 | |
| 1246 | static int ath6kl_upload_otp(struct ath6kl *ar) |
| 1247 | { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1248 | u32 address, param; |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1249 | bool from_hw = false; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1250 | int ret; |
| 1251 | |
Kalle Valo | 50e2740 | 2011-11-11 12:18:06 +0200 | [diff] [blame] | 1252 | if (ar->fw_otp == NULL) |
| 1253 | return 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1254 | |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1255 | address = ar->hw.app_load_addr; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1256 | |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 1257 | ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address, |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1258 | ar->fw_otp_len); |
| 1259 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1260 | ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp, |
| 1261 | ar->fw_otp_len); |
| 1262 | if (ret) { |
| 1263 | ath6kl_err("Failed to upload OTP file: %d\n", ret); |
| 1264 | return ret; |
| 1265 | } |
| 1266 | |
Kalle Valo | 639d0b8 | 2011-09-12 12:48:09 +0300 | [diff] [blame] | 1267 | /* read firmware start address */ |
Kalle Valo | 80fb268 | 2012-03-07 20:03:59 +0200 | [diff] [blame] | 1268 | ret = ath6kl_bmi_read_hi32(ar, hi_app_start, &address); |
Kalle Valo | 639d0b8 | 2011-09-12 12:48:09 +0300 | [diff] [blame] | 1269 | |
| 1270 | if (ret) { |
| 1271 | ath6kl_err("Failed to read hi_app_start: %d\n", ret); |
| 1272 | return ret; |
| 1273 | } |
| 1274 | |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1275 | if (ar->hw.app_start_override_addr == 0) { |
| 1276 | ar->hw.app_start_override_addr = address; |
| 1277 | from_hw = true; |
| 1278 | } |
Kalle Valo | 639d0b8 | 2011-09-12 12:48:09 +0300 | [diff] [blame] | 1279 | |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1280 | ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n", |
| 1281 | from_hw ? " (from hw)" : "", |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1282 | ar->hw.app_start_override_addr); |
| 1283 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1284 | /* execute the OTP code */ |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1285 | ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n", |
| 1286 | ar->hw.app_start_override_addr); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1287 | param = 0; |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1288 | ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1289 | |
| 1290 | return ret; |
| 1291 | } |
| 1292 | |
| 1293 | static int ath6kl_upload_firmware(struct ath6kl *ar) |
| 1294 | { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1295 | u32 address; |
| 1296 | int ret; |
| 1297 | |
Kalle Valo | 772c31e | 2011-09-07 10:55:16 +0300 | [diff] [blame] | 1298 | if (WARN_ON(ar->fw == NULL)) |
Kalle Valo | 50e2740 | 2011-11-11 12:18:06 +0200 | [diff] [blame] | 1299 | return 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1300 | |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1301 | address = ar->hw.app_load_addr; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1302 | |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 1303 | ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n", |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1304 | address, ar->fw_len); |
| 1305 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1306 | ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len); |
| 1307 | |
| 1308 | if (ret) { |
| 1309 | ath6kl_err("Failed to write firmware: %d\n", ret); |
| 1310 | return ret; |
| 1311 | } |
| 1312 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1313 | /* |
| 1314 | * Set starting address for firmware |
| 1315 | * Don't need to setup app_start override addr on AR6004 |
| 1316 | */ |
| 1317 | if (ar->target_type != TARGET_TYPE_AR6004) { |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1318 | address = ar->hw.app_start_override_addr; |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1319 | ath6kl_bmi_set_app_start(ar, address); |
| 1320 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1321 | return ret; |
| 1322 | } |
| 1323 | |
| 1324 | static int ath6kl_upload_patch(struct ath6kl *ar) |
| 1325 | { |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1326 | u32 address; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1327 | int ret; |
| 1328 | |
Kalle Valo | 50e2740 | 2011-11-11 12:18:06 +0200 | [diff] [blame] | 1329 | if (ar->fw_patch == NULL) |
| 1330 | return 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1331 | |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1332 | address = ar->hw.dataset_patch_addr; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1333 | |
Kalle Valo | ef54862 | 2011-10-01 09:43:09 +0300 | [diff] [blame] | 1334 | ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n", |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1335 | address, ar->fw_patch_len); |
| 1336 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1337 | ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len); |
| 1338 | if (ret) { |
| 1339 | ath6kl_err("Failed to write patch file: %d\n", ret); |
| 1340 | return ret; |
| 1341 | } |
| 1342 | |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1343 | ath6kl_bmi_write_hi32(ar, hi_dset_list_head, address); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1344 | |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1348 | static int ath6kl_upload_testscript(struct ath6kl *ar) |
| 1349 | { |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1350 | u32 address; |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1351 | int ret; |
| 1352 | |
Kalle Valo | 5f1127f | 2012-01-24 13:50:16 +0200 | [diff] [blame] | 1353 | if (ar->testmode != 2) |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1354 | return 0; |
| 1355 | |
| 1356 | if (ar->fw_testscript == NULL) |
| 1357 | return 0; |
| 1358 | |
| 1359 | address = ar->hw.testscript_addr; |
| 1360 | |
| 1361 | ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n", |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1362 | address, ar->fw_testscript_len); |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1363 | |
| 1364 | ret = ath6kl_bmi_write(ar, address, ar->fw_testscript, |
| 1365 | ar->fw_testscript_len); |
| 1366 | if (ret) { |
| 1367 | ath6kl_err("Failed to write testscript file: %d\n", ret); |
| 1368 | return ret; |
| 1369 | } |
| 1370 | |
Kalle Valo | 24fc32b | 2012-03-07 20:03:58 +0200 | [diff] [blame] | 1371 | ath6kl_bmi_write_hi32(ar, hi_ota_testscript, address); |
| 1372 | ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 4096); |
| 1373 | ath6kl_bmi_write_hi32(ar, hi_test_apps_related, 1); |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1374 | |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1378 | static int ath6kl_init_upload(struct ath6kl *ar) |
| 1379 | { |
| 1380 | u32 param, options, sleep, address; |
| 1381 | int status = 0; |
| 1382 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1383 | if (ar->target_type != TARGET_TYPE_AR6003 && |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1384 | ar->target_type != TARGET_TYPE_AR6004) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1385 | return -EINVAL; |
| 1386 | |
| 1387 | /* temporarily disable system sleep */ |
| 1388 | address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; |
| 1389 | status = ath6kl_bmi_reg_read(ar, address, ¶m); |
| 1390 | if (status) |
| 1391 | return status; |
| 1392 | |
| 1393 | options = param; |
| 1394 | |
| 1395 | param |= ATH6KL_OPTION_SLEEP_DISABLE; |
| 1396 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1397 | if (status) |
| 1398 | return status; |
| 1399 | |
| 1400 | address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; |
| 1401 | status = ath6kl_bmi_reg_read(ar, address, ¶m); |
| 1402 | if (status) |
| 1403 | return status; |
| 1404 | |
| 1405 | sleep = param; |
| 1406 | |
| 1407 | param |= SM(SYSTEM_SLEEP_DISABLE, 1); |
| 1408 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1409 | if (status) |
| 1410 | return status; |
| 1411 | |
| 1412 | ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n", |
| 1413 | options, sleep); |
| 1414 | |
| 1415 | /* program analog PLL register */ |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1416 | /* no need to control 40/44MHz clock on AR6004 */ |
| 1417 | if (ar->target_type != TARGET_TYPE_AR6004) { |
| 1418 | status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER, |
| 1419 | 0xF9104001); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1420 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1421 | if (status) |
| 1422 | return status; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1423 | |
Kevin Fang | 31024d9 | 2011-07-11 17:14:13 +0800 | [diff] [blame] | 1424 | /* Run at 80/88MHz by default */ |
| 1425 | param = SM(CPU_CLOCK_STANDARD, 1); |
| 1426 | |
| 1427 | address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS; |
| 1428 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1429 | if (status) |
| 1430 | return status; |
| 1431 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1432 | |
| 1433 | param = 0; |
| 1434 | address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS; |
| 1435 | param = SM(LPO_CAL_ENABLE, 1); |
| 1436 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1437 | if (status) |
| 1438 | return status; |
| 1439 | |
| 1440 | /* WAR to avoid SDIO CRC err */ |
Mohammed Shafi Shajakhan | a2e1be3 | 2012-09-27 18:19:53 +0530 | [diff] [blame] | 1441 | if (ar->hw.flags & ATH6KL_HW_SDIO_CRC_ERROR_WAR) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1442 | ath6kl_err("temporary war to avoid sdio crc error\n"); |
| 1443 | |
Vasanthakumar Thiagarajan | fa338be | 2012-05-22 12:52:48 +0530 | [diff] [blame] | 1444 | param = 0x28; |
| 1445 | address = GPIO_BASE_ADDRESS + GPIO_PIN9_ADDRESS; |
| 1446 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1447 | if (status) |
| 1448 | return status; |
| 1449 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1450 | param = 0x20; |
| 1451 | |
| 1452 | address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS; |
| 1453 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1454 | if (status) |
| 1455 | return status; |
| 1456 | |
| 1457 | address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS; |
| 1458 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1459 | if (status) |
| 1460 | return status; |
| 1461 | |
| 1462 | address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS; |
| 1463 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1464 | if (status) |
| 1465 | return status; |
| 1466 | |
| 1467 | address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS; |
| 1468 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1469 | if (status) |
| 1470 | return status; |
| 1471 | } |
| 1472 | |
| 1473 | /* write EEPROM data to Target RAM */ |
| 1474 | status = ath6kl_upload_board_file(ar); |
| 1475 | if (status) |
| 1476 | return status; |
| 1477 | |
| 1478 | /* transfer One time Programmable data */ |
| 1479 | status = ath6kl_upload_otp(ar); |
| 1480 | if (status) |
| 1481 | return status; |
| 1482 | |
| 1483 | /* Download Target firmware */ |
| 1484 | status = ath6kl_upload_firmware(ar); |
| 1485 | if (status) |
| 1486 | return status; |
| 1487 | |
| 1488 | status = ath6kl_upload_patch(ar); |
| 1489 | if (status) |
| 1490 | return status; |
| 1491 | |
Alex Yang | cd23c1c | 2012-01-17 15:32:29 +0200 | [diff] [blame] | 1492 | /* Download the test script */ |
| 1493 | status = ath6kl_upload_testscript(ar); |
| 1494 | if (status) |
| 1495 | return status; |
| 1496 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1497 | /* Restore system sleep */ |
| 1498 | address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; |
| 1499 | status = ath6kl_bmi_reg_write(ar, address, sleep); |
| 1500 | if (status) |
| 1501 | return status; |
| 1502 | |
| 1503 | address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; |
| 1504 | param = options | 0x20; |
| 1505 | status = ath6kl_bmi_reg_write(ar, address, param); |
| 1506 | if (status) |
| 1507 | return status; |
| 1508 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1509 | return status; |
| 1510 | } |
| 1511 | |
Kalle Valo | 45eaa78 | 2012-01-17 20:09:05 +0200 | [diff] [blame] | 1512 | int ath6kl_init_hw_params(struct ath6kl *ar) |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1513 | { |
Kalle Valo | 1b46dc04 | 2012-01-31 21:26:22 +0200 | [diff] [blame] | 1514 | const struct ath6kl_hw *uninitialized_var(hw); |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 1515 | int i; |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1516 | |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 1517 | for (i = 0; i < ARRAY_SIZE(hw_list); i++) { |
| 1518 | hw = &hw_list[i]; |
Kalle Valo | bef26a7 | 2011-10-12 09:58:28 +0300 | [diff] [blame] | 1519 | |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 1520 | if (hw->id == ar->version.target_ver) |
| 1521 | break; |
| 1522 | } |
| 1523 | |
| 1524 | if (i == ARRAY_SIZE(hw_list)) { |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1525 | ath6kl_err("Unsupported hardware version: 0x%x\n", |
| 1526 | ar->version.target_ver); |
| 1527 | return -EINVAL; |
| 1528 | } |
| 1529 | |
Kalle Valo | 856f4b31 | 2011-11-14 19:30:29 +0200 | [diff] [blame] | 1530 | ar->hw = *hw; |
| 1531 | |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1532 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1533 | "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n", |
| 1534 | ar->version.target_ver, ar->target_type, |
| 1535 | ar->hw.dataset_patch_addr, ar->hw.app_load_addr); |
| 1536 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1537 | "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x", |
| 1538 | ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr, |
| 1539 | ar->hw.reserved_ram_size); |
Ryan Hsu | 39586bf | 2011-12-13 17:11:07 +0800 | [diff] [blame] | 1540 | ath6kl_dbg(ATH6KL_DBG_BOOT, |
| 1541 | "refclk_hz %d uarttx_pin %d", |
| 1542 | ar->hw.refclk_hz, ar->hw.uarttx_pin); |
Kalle Valo | 6bc3643 | 2011-09-27 14:31:11 +0300 | [diff] [blame] | 1543 | |
Kalle Valo | a01ac41 | 2011-09-07 10:55:17 +0300 | [diff] [blame] | 1544 | return 0; |
| 1545 | } |
| 1546 | |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 1547 | static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type) |
| 1548 | { |
| 1549 | switch (type) { |
| 1550 | case ATH6KL_HIF_TYPE_SDIO: |
| 1551 | return "sdio"; |
| 1552 | case ATH6KL_HIF_TYPE_USB: |
| 1553 | return "usb"; |
| 1554 | } |
| 1555 | |
| 1556 | return NULL; |
| 1557 | } |
| 1558 | |
Kalle Valo | e72c274 | 2013-03-06 08:56:06 +0200 | [diff] [blame] | 1559 | |
| 1560 | static const struct fw_capa_str_map { |
| 1561 | int id; |
| 1562 | const char *name; |
| 1563 | } fw_capa_map[] = { |
| 1564 | { ATH6KL_FW_CAPABILITY_HOST_P2P, "host-p2p" }, |
| 1565 | { ATH6KL_FW_CAPABILITY_SCHED_SCAN, "sched-scan" }, |
| 1566 | { ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, "sta-p2pdev-duplex" }, |
| 1567 | { ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT, "inactivity-timeout" }, |
| 1568 | { ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE, "rsn-cap-override" }, |
| 1569 | { ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER, "wow-mc-filter" }, |
| 1570 | { ATH6KL_FW_CAPABILITY_BMISS_ENHANCE, "bmiss-enhance" }, |
| 1571 | { ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST, "sscan-match-list" }, |
| 1572 | { ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD, "rssi-scan-thold" }, |
| 1573 | { ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR, "custom-mac-addr" }, |
| 1574 | { ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY, "tx-err-notify" }, |
| 1575 | { ATH6KL_FW_CAPABILITY_REGDOMAIN, "regdomain" }, |
| 1576 | { ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2, "sched-scan-v2" }, |
| 1577 | { ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL, "hb-poll" }, |
| 1578 | }; |
| 1579 | |
| 1580 | static const char *ath6kl_init_get_fw_capa_name(unsigned int id) |
| 1581 | { |
| 1582 | int i; |
| 1583 | |
| 1584 | for (i = 0; i < ARRAY_SIZE(fw_capa_map); i++) { |
| 1585 | if (fw_capa_map[i].id == id) |
| 1586 | return fw_capa_map[i].name; |
| 1587 | } |
| 1588 | |
| 1589 | return "<unknown>"; |
| 1590 | } |
| 1591 | |
| 1592 | static void ath6kl_init_get_fwcaps(struct ath6kl *ar, char *buf, size_t buf_len) |
| 1593 | { |
| 1594 | u8 *data = (u8 *) ar->fw_capabilities; |
| 1595 | size_t trunc_len, len = 0; |
| 1596 | int i, index, bit; |
| 1597 | char *trunc = "..."; |
| 1598 | |
| 1599 | for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) { |
| 1600 | index = i / 8; |
| 1601 | bit = i % 8; |
| 1602 | |
| 1603 | if (index >= sizeof(ar->fw_capabilities) * 4) |
| 1604 | break; |
| 1605 | |
| 1606 | if (buf_len - len < 4) { |
| 1607 | ath6kl_warn("firmware capability buffer too small!\n"); |
| 1608 | |
| 1609 | /* add "..." to the end of string */ |
| 1610 | trunc_len = strlen(trunc) + 1; |
| 1611 | strncpy(buf + buf_len - trunc_len, trunc, trunc_len); |
| 1612 | |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | if (data[index] & (1 << bit)) { |
| 1617 | len += scnprintf(buf + len, buf_len - len, "%s,", |
| 1618 | ath6kl_init_get_fw_capa_name(i)); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | /* overwrite the last comma */ |
| 1623 | if (len > 0) |
| 1624 | len--; |
| 1625 | |
| 1626 | buf[len] = '\0'; |
| 1627 | } |
| 1628 | |
Kalle Valo | ec1461d | 2013-03-09 12:01:35 +0200 | [diff] [blame] | 1629 | static int ath6kl_init_hw_reset(struct ath6kl *ar) |
| 1630 | { |
| 1631 | ath6kl_dbg(ATH6KL_DBG_BOOT, "cold resetting the device"); |
| 1632 | |
| 1633 | return ath6kl_diag_write32(ar, RESET_CONTROL_ADDRESS, |
| 1634 | cpu_to_le32(RESET_CONTROL_COLD_RST)); |
| 1635 | } |
| 1636 | |
Vasanthakumar Thiagarajan | ede615d | 2012-08-29 19:40:25 +0530 | [diff] [blame] | 1637 | static int __ath6kl_init_hw_start(struct ath6kl *ar) |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1638 | { |
| 1639 | long timeleft; |
| 1640 | int ret, i; |
Kalle Valo | e72c274 | 2013-03-06 08:56:06 +0200 | [diff] [blame] | 1641 | char buf[200]; |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1642 | |
Kalle Valo | 5fe4dff | 2011-10-30 21:16:15 +0200 | [diff] [blame] | 1643 | ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n"); |
| 1644 | |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1645 | ret = ath6kl_hif_power_on(ar); |
| 1646 | if (ret) |
| 1647 | return ret; |
| 1648 | |
| 1649 | ret = ath6kl_configure_target(ar); |
| 1650 | if (ret) |
| 1651 | goto err_power_off; |
| 1652 | |
| 1653 | ret = ath6kl_init_upload(ar); |
| 1654 | if (ret) |
| 1655 | goto err_power_off; |
| 1656 | |
| 1657 | /* Do we need to finish the BMI phase */ |
Mohammed Shafi Shajakhan | bf97814 | 2013-02-22 20:20:21 +0530 | [diff] [blame] | 1658 | ret = ath6kl_bmi_done(ar); |
| 1659 | if (ret) |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1660 | goto err_power_off; |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1661 | |
| 1662 | /* |
| 1663 | * The reason we have to wait for the target here is that the |
| 1664 | * driver layer has to init BMI in order to set the host block |
| 1665 | * size. |
| 1666 | */ |
Kalle Valo | 4e1609c | 2013-03-09 12:01:43 +0200 | [diff] [blame] | 1667 | ret = ath6kl_htc_wait_target(ar->htc_target); |
Kalle Valo | 44af344 | 2013-03-09 12:01:50 +0200 | [diff] [blame] | 1668 | |
| 1669 | if (ret == -ETIMEDOUT) { |
| 1670 | /* |
| 1671 | * Most likely USB target is in odd state after reboot and |
| 1672 | * needs a reset. A cold reset makes the whole device |
| 1673 | * disappear from USB bus and initialisation starts from |
| 1674 | * beginning. |
| 1675 | */ |
| 1676 | ath6kl_warn("htc wait target timed out, resetting device\n"); |
| 1677 | ath6kl_init_hw_reset(ar); |
| 1678 | goto err_power_off; |
| 1679 | } else if (ret) { |
Kalle Valo | 4e1609c | 2013-03-09 12:01:43 +0200 | [diff] [blame] | 1680 | ath6kl_err("htc wait target failed: %d\n", ret); |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1681 | goto err_power_off; |
| 1682 | } |
| 1683 | |
Kalle Valo | 4e1609c | 2013-03-09 12:01:43 +0200 | [diff] [blame] | 1684 | ret = ath6kl_init_service_ep(ar); |
| 1685 | if (ret) { |
| 1686 | ath6kl_err("Endpoint service initilisation failed: %d\n", ret); |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1687 | goto err_cleanup_scatter; |
| 1688 | } |
| 1689 | |
| 1690 | /* setup credit distribution */ |
Kalle Valo | e76ac2bf | 2012-03-25 17:15:27 +0300 | [diff] [blame] | 1691 | ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info); |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1692 | |
| 1693 | /* start HTC */ |
| 1694 | ret = ath6kl_htc_start(ar->htc_target); |
| 1695 | if (ret) { |
| 1696 | /* FIXME: call this */ |
| 1697 | ath6kl_cookie_cleanup(ar); |
| 1698 | goto err_cleanup_scatter; |
| 1699 | } |
| 1700 | |
| 1701 | /* Wait for Wmi event to be ready */ |
| 1702 | timeleft = wait_event_interruptible_timeout(ar->event_wq, |
| 1703 | test_bit(WMI_READY, |
| 1704 | &ar->flag), |
| 1705 | WMI_TIMEOUT); |
Raja Mani | ab1ef14 | 2013-03-19 09:48:35 +0530 | [diff] [blame] | 1706 | if (timeleft <= 0) { |
| 1707 | clear_bit(WMI_READY, &ar->flag); |
| 1708 | ath6kl_err("wmi is not ready or wait was interrupted: %ld\n", |
| 1709 | timeleft); |
| 1710 | ret = -EIO; |
| 1711 | goto err_htc_stop; |
| 1712 | } |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1713 | |
| 1714 | ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n"); |
| 1715 | |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 1716 | if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) { |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 1717 | ath6kl_info("%s %s fw %s api %d%s\n", |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 1718 | ar->hw.name, |
| 1719 | ath6kl_init_get_hif_name(ar->hif_type), |
| 1720 | ar->wiphy->fw_version, |
Kalle Valo | 65a8b4c | 2011-12-16 20:53:41 +0200 | [diff] [blame] | 1721 | ar->fw_api, |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 1722 | test_bit(TESTMODE, &ar->flag) ? " testmode" : ""); |
Kalle Valo | e72c274 | 2013-03-06 08:56:06 +0200 | [diff] [blame] | 1723 | ath6kl_init_get_fwcaps(ar, buf, sizeof(buf)); |
| 1724 | ath6kl_info("firmware supports: %s\n", buf); |
Kalle Valo | 293badf | 2011-11-14 19:30:54 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1727 | if (ar->version.abi_ver != ATH6KL_ABI_VERSION) { |
| 1728 | ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n", |
| 1729 | ATH6KL_ABI_VERSION, ar->version.abi_ver); |
| 1730 | ret = -EIO; |
| 1731 | goto err_htc_stop; |
| 1732 | } |
| 1733 | |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1734 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__); |
| 1735 | |
| 1736 | /* communicate the wmi protocol verision to the target */ |
| 1737 | /* FIXME: return error */ |
| 1738 | if ((ath6kl_set_host_app_area(ar)) != 0) |
| 1739 | ath6kl_err("unable to set the host app area\n"); |
| 1740 | |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 1741 | for (i = 0; i < ar->vif_max; i++) { |
Kalle Valo | 20459ee | 2011-10-27 18:48:37 +0300 | [diff] [blame] | 1742 | ret = ath6kl_target_config_wlan_params(ar, i); |
| 1743 | if (ret) |
| 1744 | goto err_htc_stop; |
| 1745 | } |
| 1746 | |
| 1747 | return 0; |
| 1748 | |
| 1749 | err_htc_stop: |
| 1750 | ath6kl_htc_stop(ar->htc_target); |
| 1751 | err_cleanup_scatter: |
| 1752 | ath6kl_hif_cleanup_scatter(ar); |
| 1753 | err_power_off: |
| 1754 | ath6kl_hif_power_off(ar); |
| 1755 | |
| 1756 | return ret; |
| 1757 | } |
| 1758 | |
Vasanthakumar Thiagarajan | ede615d | 2012-08-29 19:40:25 +0530 | [diff] [blame] | 1759 | int ath6kl_init_hw_start(struct ath6kl *ar) |
| 1760 | { |
| 1761 | int err; |
| 1762 | |
| 1763 | err = __ath6kl_init_hw_start(ar); |
| 1764 | if (err) |
| 1765 | return err; |
| 1766 | ar->state = ATH6KL_STATE_ON; |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | static int __ath6kl_init_hw_stop(struct ath6kl *ar) |
Kalle Valo | 5fe4dff | 2011-10-30 21:16:15 +0200 | [diff] [blame] | 1771 | { |
| 1772 | int ret; |
| 1773 | |
| 1774 | ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n"); |
| 1775 | |
| 1776 | ath6kl_htc_stop(ar->htc_target); |
| 1777 | |
| 1778 | ath6kl_hif_stop(ar); |
| 1779 | |
| 1780 | ath6kl_bmi_reset(ar); |
| 1781 | |
| 1782 | ret = ath6kl_hif_power_off(ar); |
| 1783 | if (ret) |
| 1784 | ath6kl_warn("failed to power off hif: %d\n", ret); |
| 1785 | |
Vasanthakumar Thiagarajan | ede615d | 2012-08-29 19:40:25 +0530 | [diff] [blame] | 1786 | return 0; |
| 1787 | } |
Kalle Valo | 76a9fbe | 2011-11-01 08:44:28 +0200 | [diff] [blame] | 1788 | |
Vasanthakumar Thiagarajan | ede615d | 2012-08-29 19:40:25 +0530 | [diff] [blame] | 1789 | int ath6kl_init_hw_stop(struct ath6kl *ar) |
| 1790 | { |
| 1791 | int err; |
| 1792 | |
| 1793 | err = __ath6kl_init_hw_stop(ar); |
| 1794 | if (err) |
| 1795 | return err; |
| 1796 | ar->state = ATH6KL_STATE_OFF; |
Kalle Valo | 5fe4dff | 2011-10-30 21:16:15 +0200 | [diff] [blame] | 1797 | return 0; |
| 1798 | } |
| 1799 | |
Vasanthakumar Thiagarajan | 84caf80 | 2012-08-29 19:40:26 +0530 | [diff] [blame] | 1800 | void ath6kl_init_hw_restart(struct ath6kl *ar) |
| 1801 | { |
Vasanthakumar Thiagarajan | 58109df | 2012-09-11 12:07:00 +0530 | [diff] [blame] | 1802 | clear_bit(WMI_READY, &ar->flag); |
| 1803 | |
Vasanthakumar Thiagarajan | 84caf80 | 2012-08-29 19:40:26 +0530 | [diff] [blame] | 1804 | ath6kl_cfg80211_stop_all(ar); |
| 1805 | |
Vasanthakumar Thiagarajan | 58109df | 2012-09-11 12:07:00 +0530 | [diff] [blame] | 1806 | if (__ath6kl_init_hw_stop(ar)) { |
| 1807 | ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to stop during fw error recovery\n"); |
Vasanthakumar Thiagarajan | 84caf80 | 2012-08-29 19:40:26 +0530 | [diff] [blame] | 1808 | return; |
Vasanthakumar Thiagarajan | 58109df | 2012-09-11 12:07:00 +0530 | [diff] [blame] | 1809 | } |
Vasanthakumar Thiagarajan | 84caf80 | 2012-08-29 19:40:26 +0530 | [diff] [blame] | 1810 | |
| 1811 | if (__ath6kl_init_hw_start(ar)) { |
| 1812 | ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to restart during fw error recovery\n"); |
| 1813 | return; |
| 1814 | } |
Vasanthakumar Thiagarajan | 84caf80 | 2012-08-29 19:40:26 +0530 | [diff] [blame] | 1815 | } |
| 1816 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1817 | void ath6kl_stop_txrx(struct ath6kl *ar) |
| 1818 | { |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1819 | struct ath6kl_vif *vif, *tmp_vif; |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1820 | int i; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1821 | |
| 1822 | set_bit(DESTROY_IN_PROGRESS, &ar->flag); |
| 1823 | |
| 1824 | if (down_interruptible(&ar->sem)) { |
| 1825 | ath6kl_err("down_interruptible failed\n"); |
| 1826 | return; |
| 1827 | } |
| 1828 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1829 | for (i = 0; i < AP_MAX_NUM_STA; i++) |
| 1830 | aggr_reset_state(ar->sta_list[i].aggr_conn); |
| 1831 | |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1832 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1833 | list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) { |
| 1834 | list_del(&vif->list); |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1835 | spin_unlock_bh(&ar->list_lock); |
Mohammed Shafi Shajakhan | 355b3a9 | 2012-11-16 18:23:36 +0530 | [diff] [blame] | 1836 | ath6kl_cfg80211_vif_stop(vif, test_bit(WMI_READY, &ar->flag)); |
Vasanthakumar Thiagarajan | 2792972 | 2011-10-25 19:34:21 +0530 | [diff] [blame] | 1837 | rtnl_lock(); |
Kalle Valo | c25889e | 2012-01-17 20:08:27 +0200 | [diff] [blame] | 1838 | ath6kl_cfg80211_vif_cleanup(vif); |
Vasanthakumar Thiagarajan | 2792972 | 2011-10-25 19:34:21 +0530 | [diff] [blame] | 1839 | rtnl_unlock(); |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1840 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 1841 | } |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 1842 | spin_unlock_bh(&ar->list_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1843 | |
Vasanthakumar Thiagarajan | 6db8fa5 | 2011-10-25 19:34:16 +0530 | [diff] [blame] | 1844 | clear_bit(WMI_READY, &ar->flag); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1845 | |
Vasanthakumar Thiagarajan | f32036e | 2013-06-20 12:47:20 +0530 | [diff] [blame] | 1846 | if (ar->fw_recovery.enable) |
| 1847 | del_timer_sync(&ar->fw_recovery.hb_timer); |
| 1848 | |
Vasanthakumar Thiagarajan | 6db8fa5 | 2011-10-25 19:34:16 +0530 | [diff] [blame] | 1849 | /* |
| 1850 | * After wmi_shudown all WMI events will be dropped. We |
| 1851 | * need to cleanup the buffers allocated in AP mode and |
| 1852 | * give disconnect notification to stack, which usually |
| 1853 | * happens in the disconnect_event. Simulate the disconnect |
| 1854 | * event by calling the function directly. Sometimes |
| 1855 | * disconnect_event will be received when the debug logs |
| 1856 | * are collected. |
| 1857 | */ |
| 1858 | ath6kl_wmi_shutdown(ar->wmi); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1859 | |
Vasanthakumar Thiagarajan | 6db8fa5 | 2011-10-25 19:34:16 +0530 | [diff] [blame] | 1860 | clear_bit(WMI_ENABLED, &ar->flag); |
| 1861 | if (ar->htc_target) { |
| 1862 | ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__); |
| 1863 | ath6kl_htc_stop(ar->htc_target); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1864 | } |
| 1865 | |
Vasanthakumar Thiagarajan | 6db8fa5 | 2011-10-25 19:34:16 +0530 | [diff] [blame] | 1866 | /* |
| 1867 | * Try to reset the device if we can. The driver may have been |
| 1868 | * configure NOT to reset the target during a debug session. |
| 1869 | */ |
Kalle Valo | ec1461d | 2013-03-09 12:01:35 +0200 | [diff] [blame] | 1870 | ath6kl_init_hw_reset(ar); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1871 | |
Vasanthakumar Thiagarajan | e8ad9a0 | 2012-02-14 20:32:59 +0530 | [diff] [blame] | 1872 | up(&ar->sem); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1873 | } |
Kalle Valo | d6a434d | 2012-01-17 20:09:36 +0200 | [diff] [blame] | 1874 | EXPORT_SYMBOL(ath6kl_stop_txrx); |