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