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