1bdcd8170SKalle Valo 2bdcd8170SKalle Valo /* 3bdcd8170SKalle Valo * Copyright (c) 2011 Atheros Communications Inc. 41b2df407SVasanthakumar Thiagarajan * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. 5bdcd8170SKalle Valo * 6bdcd8170SKalle Valo * Permission to use, copy, modify, and/or distribute this software for any 7bdcd8170SKalle Valo * purpose with or without fee is hereby granted, provided that the above 8bdcd8170SKalle Valo * copyright notice and this permission notice appear in all copies. 9bdcd8170SKalle Valo * 10bdcd8170SKalle Valo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11bdcd8170SKalle Valo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12bdcd8170SKalle Valo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13bdcd8170SKalle Valo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14bdcd8170SKalle Valo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15bdcd8170SKalle Valo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16bdcd8170SKalle Valo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17bdcd8170SKalle Valo */ 18bdcd8170SKalle Valo 19516304b0SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20516304b0SJoe Perches 21c6efe578SStephen Rothwell #include <linux/moduleparam.h> 22f7830202SSangwook Lee #include <linux/errno.h> 23d6a434d6SKalle Valo #include <linux/export.h> 2492ecbff4SSam Leffler #include <linux/of.h> 25bdcd8170SKalle Valo #include <linux/mmc/sdio_func.h> 268437754cSVivek Natarajan #include <linux/vmalloc.h> 27d6a434d6SKalle Valo 28bdcd8170SKalle Valo #include "core.h" 29bdcd8170SKalle Valo #include "cfg80211.h" 30bdcd8170SKalle Valo #include "target.h" 31bdcd8170SKalle Valo #include "debug.h" 32bdcd8170SKalle Valo #include "hif-ops.h" 33e76ac2bfSKalle Valo #include "htc-ops.h" 34bdcd8170SKalle Valo 35856f4b31SKalle Valo static const struct ath6kl_hw hw_list[] = { 36856f4b31SKalle Valo { 370d0192baSKalle Valo .id = AR6003_HW_2_0_VERSION, 38293badf4SKalle Valo .name = "ar6003 hw 2.0", 39856f4b31SKalle Valo .dataset_patch_addr = 0x57e884, 40856f4b31SKalle Valo .app_load_addr = 0x543180, 41856f4b31SKalle Valo .board_ext_data_addr = 0x57e500, 42856f4b31SKalle Valo .reserved_ram_size = 6912, 4339586bf2SRyan Hsu .refclk_hz = 26000000, 4439586bf2SRyan Hsu .uarttx_pin = 8, 45a2e1be33SMohammed Shafi Shajakhan .flags = ATH6KL_HW_SDIO_CRC_ERROR_WAR, 46856f4b31SKalle Valo 47856f4b31SKalle Valo /* hw2.0 needs override address hardcoded */ 48856f4b31SKalle Valo .app_start_override_addr = 0x944C00, 49d1a9421dSKalle Valo 50c0038972SKalle Valo .fw = { 51c0038972SKalle Valo .dir = AR6003_HW_2_0_FW_DIR, 52c0038972SKalle Valo .otp = AR6003_HW_2_0_OTP_FILE, 53d1a9421dSKalle Valo .fw = AR6003_HW_2_0_FIRMWARE_FILE, 54c0038972SKalle Valo .tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE, 55c0038972SKalle Valo .patch = AR6003_HW_2_0_PATCH_FILE, 56c0038972SKalle Valo }, 57c0038972SKalle Valo 58d1a9421dSKalle Valo .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE, 59d1a9421dSKalle Valo .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE, 60856f4b31SKalle Valo }, 61856f4b31SKalle Valo { 620d0192baSKalle Valo .id = AR6003_HW_2_1_1_VERSION, 63293badf4SKalle Valo .name = "ar6003 hw 2.1.1", 64856f4b31SKalle Valo .dataset_patch_addr = 0x57ff74, 65856f4b31SKalle Valo .app_load_addr = 0x1234, 66856f4b31SKalle Valo .board_ext_data_addr = 0x542330, 67856f4b31SKalle Valo .reserved_ram_size = 512, 6839586bf2SRyan Hsu .refclk_hz = 26000000, 6939586bf2SRyan Hsu .uarttx_pin = 8, 70cd23c1c9SAlex Yang .testscript_addr = 0x57ef74, 71a2e1be33SMohammed Shafi Shajakhan .flags = ATH6KL_HW_SDIO_CRC_ERROR_WAR, 72d1a9421dSKalle Valo 73c0038972SKalle Valo .fw = { 74c0038972SKalle Valo .dir = AR6003_HW_2_1_1_FW_DIR, 75c0038972SKalle Valo .otp = AR6003_HW_2_1_1_OTP_FILE, 76d1a9421dSKalle Valo .fw = AR6003_HW_2_1_1_FIRMWARE_FILE, 77c0038972SKalle Valo .tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE, 78c0038972SKalle Valo .patch = AR6003_HW_2_1_1_PATCH_FILE, 79cd23c1c9SAlex Yang .utf = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE, 80cd23c1c9SAlex Yang .testscript = AR6003_HW_2_1_1_TESTSCRIPT_FILE, 81c0038972SKalle Valo }, 82c0038972SKalle Valo 83d1a9421dSKalle Valo .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE, 84d1a9421dSKalle Valo .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE, 85856f4b31SKalle Valo }, 86856f4b31SKalle Valo { 870d0192baSKalle Valo .id = AR6004_HW_1_0_VERSION, 88293badf4SKalle Valo .name = "ar6004 hw 1.0", 89856f4b31SKalle Valo .dataset_patch_addr = 0x57e884, 90856f4b31SKalle Valo .app_load_addr = 0x1234, 91856f4b31SKalle Valo .board_ext_data_addr = 0x437000, 92856f4b31SKalle Valo .reserved_ram_size = 19456, 930d4d72bfSKalle Valo .board_addr = 0x433900, 9439586bf2SRyan Hsu .refclk_hz = 26000000, 9539586bf2SRyan Hsu .uarttx_pin = 11, 967ac25eacSMohammed Shafi Shajakhan .flags = ATH6KL_HW_64BIT_RATES | 977ac25eacSMohammed Shafi Shajakhan ATH6KL_HW_AP_INACTIVITY_MINS, 98d1a9421dSKalle Valo 99c0038972SKalle Valo .fw = { 100c0038972SKalle Valo .dir = AR6004_HW_1_0_FW_DIR, 101d1a9421dSKalle Valo .fw = AR6004_HW_1_0_FIRMWARE_FILE, 102c0038972SKalle Valo }, 103c0038972SKalle Valo 104d1a9421dSKalle Valo .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE, 105d1a9421dSKalle Valo .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE, 106856f4b31SKalle Valo }, 107856f4b31SKalle Valo { 1080d0192baSKalle Valo .id = AR6004_HW_1_1_VERSION, 109293badf4SKalle Valo .name = "ar6004 hw 1.1", 110856f4b31SKalle Valo .dataset_patch_addr = 0x57e884, 111856f4b31SKalle Valo .app_load_addr = 0x1234, 112856f4b31SKalle Valo .board_ext_data_addr = 0x437000, 113856f4b31SKalle Valo .reserved_ram_size = 11264, 1140d4d72bfSKalle Valo .board_addr = 0x43d400, 11539586bf2SRyan Hsu .refclk_hz = 40000000, 11639586bf2SRyan Hsu .uarttx_pin = 11, 1177ac25eacSMohammed Shafi Shajakhan .flags = ATH6KL_HW_64BIT_RATES | 1187ac25eacSMohammed Shafi Shajakhan ATH6KL_HW_AP_INACTIVITY_MINS, 119c0038972SKalle Valo .fw = { 120c0038972SKalle Valo .dir = AR6004_HW_1_1_FW_DIR, 121d1a9421dSKalle Valo .fw = AR6004_HW_1_1_FIRMWARE_FILE, 122c0038972SKalle Valo }, 123c0038972SKalle Valo 124d1a9421dSKalle Valo .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE, 125d1a9421dSKalle Valo .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE, 126856f4b31SKalle Valo }, 1276146ca69SRay Chen { 1286146ca69SRay Chen .id = AR6004_HW_1_2_VERSION, 1296146ca69SRay Chen .name = "ar6004 hw 1.2", 1306146ca69SRay Chen .dataset_patch_addr = 0x436ecc, 1316146ca69SRay Chen .app_load_addr = 0x1234, 1326146ca69SRay Chen .board_ext_data_addr = 0x437000, 1336146ca69SRay Chen .reserved_ram_size = 9216, 1346146ca69SRay Chen .board_addr = 0x435c00, 1356146ca69SRay Chen .refclk_hz = 40000000, 1366146ca69SRay Chen .uarttx_pin = 11, 1377ac25eacSMohammed Shafi Shajakhan .flags = ATH6KL_HW_64BIT_RATES | 1387ac25eacSMohammed Shafi Shajakhan ATH6KL_HW_AP_INACTIVITY_MINS, 1396146ca69SRay Chen 1406146ca69SRay Chen .fw = { 1416146ca69SRay Chen .dir = AR6004_HW_1_2_FW_DIR, 1426146ca69SRay Chen .fw = AR6004_HW_1_2_FIRMWARE_FILE, 1436146ca69SRay Chen }, 1446146ca69SRay Chen .fw_board = AR6004_HW_1_2_BOARD_DATA_FILE, 1456146ca69SRay Chen .fw_default_board = AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE, 1466146ca69SRay Chen }, 147bf744f11SBala Shanmugam { 148bf744f11SBala Shanmugam .id = AR6004_HW_1_3_VERSION, 149bf744f11SBala Shanmugam .name = "ar6004 hw 1.3", 150bf744f11SBala Shanmugam .dataset_patch_addr = 0x437860, 151bf744f11SBala Shanmugam .app_load_addr = 0x1234, 152bf744f11SBala Shanmugam .board_ext_data_addr = 0x437000, 153bf744f11SBala Shanmugam .reserved_ram_size = 7168, 154bf744f11SBala Shanmugam .board_addr = 0x436400, 155bf744f11SBala Shanmugam .refclk_hz = 40000000, 156bf744f11SBala Shanmugam .uarttx_pin = 11, 1577ac25eacSMohammed Shafi Shajakhan .flags = ATH6KL_HW_64BIT_RATES | 158171fe768SMohammed Shafi Shajakhan ATH6KL_HW_AP_INACTIVITY_MINS | 159171fe768SMohammed Shafi Shajakhan ATH6KL_HW_MAP_LP_ENDPOINT, 160bf744f11SBala Shanmugam 161bf744f11SBala Shanmugam .fw = { 162bf744f11SBala Shanmugam .dir = AR6004_HW_1_3_FW_DIR, 163bf744f11SBala Shanmugam .fw = AR6004_HW_1_3_FIRMWARE_FILE, 164bf744f11SBala Shanmugam }, 165bf744f11SBala Shanmugam 166bf744f11SBala Shanmugam .fw_board = AR6004_HW_1_3_BOARD_DATA_FILE, 167bf744f11SBala Shanmugam .fw_default_board = AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE, 168bf744f11SBala Shanmugam }, 169856f4b31SKalle Valo }; 170856f4b31SKalle Valo 171bdcd8170SKalle Valo /* 172bdcd8170SKalle Valo * Include definitions here that can be used to tune the WLAN module 173bdcd8170SKalle Valo * behavior. Different customers can tune the behavior as per their needs, 174bdcd8170SKalle Valo * here. 175bdcd8170SKalle Valo */ 176bdcd8170SKalle Valo 177bdcd8170SKalle Valo /* 178bdcd8170SKalle Valo * This configuration item enable/disable keepalive support. 179bdcd8170SKalle Valo * Keepalive support: In the absence of any data traffic to AP, null 180bdcd8170SKalle Valo * frames will be sent to the AP at periodic interval, to keep the association 181bdcd8170SKalle Valo * active. This configuration item defines the periodic interval. 182bdcd8170SKalle Valo * Use value of zero to disable keepalive support 183bdcd8170SKalle Valo * Default: 60 seconds 184bdcd8170SKalle Valo */ 185bdcd8170SKalle Valo #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60 186bdcd8170SKalle Valo 187bdcd8170SKalle Valo /* 188bdcd8170SKalle Valo * This configuration item sets the value of disconnect timeout 189bdcd8170SKalle Valo * Firmware delays sending the disconnec event to the host for this 190bdcd8170SKalle Valo * timeout after is gets disconnected from the current AP. 191bdcd8170SKalle Valo * If the firmware successly roams within the disconnect timeout 192bdcd8170SKalle Valo * it sends a new connect event 193bdcd8170SKalle Valo */ 194bdcd8170SKalle Valo #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10 195bdcd8170SKalle Valo 196bdcd8170SKalle Valo 197bdcd8170SKalle Valo #define ATH6KL_DATA_OFFSET 64 198bdcd8170SKalle Valo struct sk_buff *ath6kl_buf_alloc(int size) 199bdcd8170SKalle Valo { 200bdcd8170SKalle Valo struct sk_buff *skb; 201bdcd8170SKalle Valo u16 reserved; 202bdcd8170SKalle Valo 203bdcd8170SKalle Valo /* Add chacheline space at front and back of buffer */ 204bdcd8170SKalle Valo reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET + 2051df94a85SVasanthakumar Thiagarajan sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES; 206bdcd8170SKalle Valo skb = dev_alloc_skb(size + reserved); 207bdcd8170SKalle Valo 208bdcd8170SKalle Valo if (skb) 209bdcd8170SKalle Valo skb_reserve(skb, reserved - L1_CACHE_BYTES); 210bdcd8170SKalle Valo return skb; 211bdcd8170SKalle Valo } 212bdcd8170SKalle Valo 213e29f25f5SVasanthakumar Thiagarajan void ath6kl_init_profile_info(struct ath6kl_vif *vif) 214bdcd8170SKalle Valo { 2153450334fSVasanthakumar Thiagarajan vif->ssid_len = 0; 2163450334fSVasanthakumar Thiagarajan memset(vif->ssid, 0, sizeof(vif->ssid)); 2173450334fSVasanthakumar Thiagarajan 2183450334fSVasanthakumar Thiagarajan vif->dot11_auth_mode = OPEN_AUTH; 2193450334fSVasanthakumar Thiagarajan vif->auth_mode = NONE_AUTH; 2203450334fSVasanthakumar Thiagarajan vif->prwise_crypto = NONE_CRYPT; 2213450334fSVasanthakumar Thiagarajan vif->prwise_crypto_len = 0; 2223450334fSVasanthakumar Thiagarajan vif->grp_crypto = NONE_CRYPT; 2233450334fSVasanthakumar Thiagarajan vif->grp_crypto_len = 0; 2246f2a73f9SVasanthakumar Thiagarajan memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list)); 2258c8b65e3SVasanthakumar Thiagarajan memset(vif->req_bssid, 0, sizeof(vif->req_bssid)); 2268c8b65e3SVasanthakumar Thiagarajan memset(vif->bssid, 0, sizeof(vif->bssid)); 227f74bac54SVasanthakumar Thiagarajan vif->bss_ch = 0; 228bdcd8170SKalle Valo } 229bdcd8170SKalle Valo 230bdcd8170SKalle Valo static int ath6kl_set_host_app_area(struct ath6kl *ar) 231bdcd8170SKalle Valo { 232bdcd8170SKalle Valo u32 address, data; 233bdcd8170SKalle Valo struct host_app_area host_app_area; 234bdcd8170SKalle Valo 235bdcd8170SKalle Valo /* Fetch the address of the host_app_area_s 236bdcd8170SKalle Valo * instance in the host interest area */ 237bdcd8170SKalle Valo address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest)); 23831024d99SKevin Fang address = TARG_VTOP(ar->target_type, address); 239bdcd8170SKalle Valo 240addb44beSKalle Valo if (ath6kl_diag_read32(ar, address, &data)) 241bdcd8170SKalle Valo return -EIO; 242bdcd8170SKalle Valo 24331024d99SKevin Fang address = TARG_VTOP(ar->target_type, data); 244cbf49a6fSKalle Valo host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION); 245addb44beSKalle Valo if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area, 246addb44beSKalle Valo sizeof(struct host_app_area))) 247bdcd8170SKalle Valo return -EIO; 248bdcd8170SKalle Valo 249bdcd8170SKalle Valo return 0; 250bdcd8170SKalle Valo } 251bdcd8170SKalle Valo 252bdcd8170SKalle Valo static inline void set_ac2_ep_map(struct ath6kl *ar, 253bdcd8170SKalle Valo u8 ac, 254bdcd8170SKalle Valo enum htc_endpoint_id ep) 255bdcd8170SKalle Valo { 256bdcd8170SKalle Valo ar->ac2ep_map[ac] = ep; 257bdcd8170SKalle Valo ar->ep2ac_map[ep] = ac; 258bdcd8170SKalle Valo } 259bdcd8170SKalle Valo 260bdcd8170SKalle Valo /* connect to a service */ 261bdcd8170SKalle Valo static int ath6kl_connectservice(struct ath6kl *ar, 262bdcd8170SKalle Valo struct htc_service_connect_req *con_req, 263bdcd8170SKalle Valo char *desc) 264bdcd8170SKalle Valo { 265bdcd8170SKalle Valo int status; 266bdcd8170SKalle Valo struct htc_service_connect_resp response; 267bdcd8170SKalle Valo 268bdcd8170SKalle Valo memset(&response, 0, sizeof(response)); 269bdcd8170SKalle Valo 270ad226ec2SKalle Valo status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response); 271bdcd8170SKalle Valo if (status) { 272bdcd8170SKalle Valo ath6kl_err("failed to connect to %s service status:%d\n", 273bdcd8170SKalle Valo desc, status); 274bdcd8170SKalle Valo return status; 275bdcd8170SKalle Valo } 276bdcd8170SKalle Valo 277bdcd8170SKalle Valo switch (con_req->svc_id) { 278bdcd8170SKalle Valo case WMI_CONTROL_SVC: 279bdcd8170SKalle Valo if (test_bit(WMI_ENABLED, &ar->flag)) 280bdcd8170SKalle Valo ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint); 281bdcd8170SKalle Valo ar->ctrl_ep = response.endpoint; 282bdcd8170SKalle Valo break; 283bdcd8170SKalle Valo case WMI_DATA_BE_SVC: 284bdcd8170SKalle Valo set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint); 285bdcd8170SKalle Valo break; 286bdcd8170SKalle Valo case WMI_DATA_BK_SVC: 287bdcd8170SKalle Valo set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint); 288bdcd8170SKalle Valo break; 289bdcd8170SKalle Valo case WMI_DATA_VI_SVC: 290bdcd8170SKalle Valo set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint); 291bdcd8170SKalle Valo break; 292bdcd8170SKalle Valo case WMI_DATA_VO_SVC: 293bdcd8170SKalle Valo set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint); 294bdcd8170SKalle Valo break; 295bdcd8170SKalle Valo default: 296bdcd8170SKalle Valo ath6kl_err("service id is not mapped %d\n", con_req->svc_id); 297bdcd8170SKalle Valo return -EINVAL; 298bdcd8170SKalle Valo } 299bdcd8170SKalle Valo 300bdcd8170SKalle Valo return 0; 301bdcd8170SKalle Valo } 302bdcd8170SKalle Valo 303bdcd8170SKalle Valo static int ath6kl_init_service_ep(struct ath6kl *ar) 304bdcd8170SKalle Valo { 305bdcd8170SKalle Valo struct htc_service_connect_req connect; 306bdcd8170SKalle Valo 307bdcd8170SKalle Valo memset(&connect, 0, sizeof(connect)); 308bdcd8170SKalle Valo 309bdcd8170SKalle Valo /* these fields are the same for all service endpoints */ 310900d6b3fSKalle Valo connect.ep_cb.tx_comp_multi = ath6kl_tx_complete; 311bdcd8170SKalle Valo connect.ep_cb.rx = ath6kl_rx; 312bdcd8170SKalle Valo connect.ep_cb.rx_refill = ath6kl_rx_refill; 313bdcd8170SKalle Valo connect.ep_cb.tx_full = ath6kl_tx_queue_full; 314bdcd8170SKalle Valo 315bdcd8170SKalle Valo /* 316bdcd8170SKalle Valo * Set the max queue depth so that our ath6kl_tx_queue_full handler 317bdcd8170SKalle Valo * gets called. 318bdcd8170SKalle Valo */ 319bdcd8170SKalle Valo connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH; 320bdcd8170SKalle Valo connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4; 321bdcd8170SKalle Valo if (!connect.ep_cb.rx_refill_thresh) 322bdcd8170SKalle Valo connect.ep_cb.rx_refill_thresh++; 323bdcd8170SKalle Valo 324bdcd8170SKalle Valo /* connect to control service */ 325bdcd8170SKalle Valo connect.svc_id = WMI_CONTROL_SVC; 326bdcd8170SKalle Valo if (ath6kl_connectservice(ar, &connect, "WMI CONTROL")) 327bdcd8170SKalle Valo return -EIO; 328bdcd8170SKalle Valo 329bdcd8170SKalle Valo connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN; 330bdcd8170SKalle Valo 331bdcd8170SKalle Valo /* 332bdcd8170SKalle Valo * Limit the HTC message size on the send path, although e can 333bdcd8170SKalle Valo * receive A-MSDU frames of 4K, we will only send ethernet-sized 334bdcd8170SKalle Valo * (802.3) frames on the send path. 335bdcd8170SKalle Valo */ 336bdcd8170SKalle Valo connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH; 337bdcd8170SKalle Valo 338bdcd8170SKalle Valo /* 339bdcd8170SKalle Valo * To reduce the amount of committed memory for larger A_MSDU 340bdcd8170SKalle Valo * frames, use the recv-alloc threshold mechanism for larger 341bdcd8170SKalle Valo * packets. 342bdcd8170SKalle Valo */ 343bdcd8170SKalle Valo connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE; 344bdcd8170SKalle Valo connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf; 345bdcd8170SKalle Valo 346bdcd8170SKalle Valo /* 347bdcd8170SKalle Valo * For the remaining data services set the connection flag to 348bdcd8170SKalle Valo * reduce dribbling, if configured to do so. 349bdcd8170SKalle Valo */ 350bdcd8170SKalle Valo connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB; 351bdcd8170SKalle Valo connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK; 352bdcd8170SKalle Valo connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF; 353bdcd8170SKalle Valo 354bdcd8170SKalle Valo connect.svc_id = WMI_DATA_BE_SVC; 355bdcd8170SKalle Valo 356bdcd8170SKalle Valo if (ath6kl_connectservice(ar, &connect, "WMI DATA BE")) 357bdcd8170SKalle Valo return -EIO; 358bdcd8170SKalle Valo 359bdcd8170SKalle Valo /* connect to back-ground map this to WMI LOW_PRI */ 360bdcd8170SKalle Valo connect.svc_id = WMI_DATA_BK_SVC; 361bdcd8170SKalle Valo if (ath6kl_connectservice(ar, &connect, "WMI DATA BK")) 362bdcd8170SKalle Valo return -EIO; 363bdcd8170SKalle Valo 364171fe768SMohammed Shafi Shajakhan /* connect to Video service, map this to HI PRI */ 365bdcd8170SKalle Valo connect.svc_id = WMI_DATA_VI_SVC; 366bdcd8170SKalle Valo if (ath6kl_connectservice(ar, &connect, "WMI DATA VI")) 367bdcd8170SKalle Valo return -EIO; 368bdcd8170SKalle Valo 369bdcd8170SKalle Valo /* 370bdcd8170SKalle Valo * Connect to VO service, this is currently not mapped to a WMI 371bdcd8170SKalle Valo * priority stream due to historical reasons. WMI originally 372bdcd8170SKalle Valo * defined 3 priorities over 3 mailboxes We can change this when 373bdcd8170SKalle Valo * WMI is reworked so that priorities are not dependent on 374bdcd8170SKalle Valo * mailboxes. 375bdcd8170SKalle Valo */ 376bdcd8170SKalle Valo connect.svc_id = WMI_DATA_VO_SVC; 377bdcd8170SKalle Valo if (ath6kl_connectservice(ar, &connect, "WMI DATA VO")) 378bdcd8170SKalle Valo return -EIO; 379bdcd8170SKalle Valo 380bdcd8170SKalle Valo return 0; 381bdcd8170SKalle Valo } 382bdcd8170SKalle Valo 383e29f25f5SVasanthakumar Thiagarajan void ath6kl_init_control_info(struct ath6kl_vif *vif) 384bdcd8170SKalle Valo { 385e29f25f5SVasanthakumar Thiagarajan ath6kl_init_profile_info(vif); 3863450334fSVasanthakumar Thiagarajan vif->def_txkey_index = 0; 3876f2a73f9SVasanthakumar Thiagarajan memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list)); 388f74bac54SVasanthakumar Thiagarajan vif->ch_hint = 0; 389bdcd8170SKalle Valo } 390bdcd8170SKalle Valo 391bdcd8170SKalle Valo /* 392bdcd8170SKalle Valo * Set HTC/Mbox operational parameters, this can only be called when the 393bdcd8170SKalle Valo * target is in the BMI phase. 394bdcd8170SKalle Valo */ 395bdcd8170SKalle Valo static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val, 396bdcd8170SKalle Valo u8 htc_ctrl_buf) 397bdcd8170SKalle Valo { 398bdcd8170SKalle Valo int status; 399bdcd8170SKalle Valo u32 blk_size; 400bdcd8170SKalle Valo 401bdcd8170SKalle Valo blk_size = ar->mbox_info.block_size; 402bdcd8170SKalle Valo 403bdcd8170SKalle Valo if (htc_ctrl_buf) 404bdcd8170SKalle Valo blk_size |= ((u32)htc_ctrl_buf) << 16; 405bdcd8170SKalle Valo 406bdcd8170SKalle Valo /* set the host interest area for the block size */ 40724fc32b3SKalle Valo status = ath6kl_bmi_write_hi32(ar, hi_mbox_io_block_sz, blk_size); 408bdcd8170SKalle Valo if (status) { 409bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for IO block size failed\n"); 410bdcd8170SKalle Valo goto out; 411bdcd8170SKalle Valo } 412bdcd8170SKalle Valo 413bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n", 414bdcd8170SKalle Valo blk_size, 415bdcd8170SKalle Valo ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz))); 416bdcd8170SKalle Valo 417bdcd8170SKalle Valo if (mbox_isr_yield_val) { 418bdcd8170SKalle Valo /* set the host interest area for the mbox ISR yield limit */ 41924fc32b3SKalle Valo status = ath6kl_bmi_write_hi32(ar, hi_mbox_isr_yield_limit, 42024fc32b3SKalle Valo mbox_isr_yield_val); 421bdcd8170SKalle Valo if (status) { 422bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for yield limit failed\n"); 423bdcd8170SKalle Valo goto out; 424bdcd8170SKalle Valo } 425bdcd8170SKalle Valo } 426bdcd8170SKalle Valo 427bdcd8170SKalle Valo out: 428bdcd8170SKalle Valo return status; 429bdcd8170SKalle Valo } 430bdcd8170SKalle Valo 4310ce59445SVasanthakumar Thiagarajan static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx) 432bdcd8170SKalle Valo { 4334dea08e0SJouni Malinen int ret; 434bdcd8170SKalle Valo 435bdcd8170SKalle Valo /* 436bdcd8170SKalle Valo * Configure the device for rx dot11 header rules. "0,0" are the 437bdcd8170SKalle Valo * default values. Required if checksum offload is needed. Set 438bdcd8170SKalle Valo * RxMetaVersion to 2. 439bdcd8170SKalle Valo */ 4401ca4d0b6SKalle Valo ret = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx, 4411ca4d0b6SKalle Valo ar->rx_meta_ver, 0, 0); 4421ca4d0b6SKalle Valo if (ret) { 4431ca4d0b6SKalle Valo ath6kl_err("unable to set the rx frame format: %d\n", ret); 4441ca4d0b6SKalle Valo return ret; 445bdcd8170SKalle Valo } 446bdcd8170SKalle Valo 4471ca4d0b6SKalle Valo if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN) { 4481ca4d0b6SKalle Valo ret = ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1, 44905aab177SKalle Valo IGNORE_PS_FAIL_DURING_SCAN); 4501ca4d0b6SKalle Valo if (ret) { 4511ca4d0b6SKalle Valo ath6kl_err("unable to set power save fail event policy: %d\n", 4521ca4d0b6SKalle Valo ret); 4531ca4d0b6SKalle Valo return ret; 4541ca4d0b6SKalle Valo } 455bdcd8170SKalle Valo } 456bdcd8170SKalle Valo 4571ca4d0b6SKalle Valo if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER)) { 4581ca4d0b6SKalle Valo ret = ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0, 45905aab177SKalle Valo WMI_FOLLOW_BARKER_IN_ERP); 4601ca4d0b6SKalle Valo if (ret) { 4611ca4d0b6SKalle Valo ath6kl_err("unable to set barker preamble policy: %d\n", 4621ca4d0b6SKalle Valo ret); 4631ca4d0b6SKalle Valo return ret; 4641ca4d0b6SKalle Valo } 465bdcd8170SKalle Valo } 466bdcd8170SKalle Valo 4671ca4d0b6SKalle Valo ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx, 4681ca4d0b6SKalle Valo WLAN_CONFIG_KEEP_ALIVE_INTERVAL); 4691ca4d0b6SKalle Valo if (ret) { 4701ca4d0b6SKalle Valo ath6kl_err("unable to set keep alive interval: %d\n", ret); 4711ca4d0b6SKalle Valo return ret; 472bdcd8170SKalle Valo } 473bdcd8170SKalle Valo 4741ca4d0b6SKalle Valo ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, idx, 4751ca4d0b6SKalle Valo WLAN_CONFIG_DISCONNECT_TIMEOUT); 4761ca4d0b6SKalle Valo if (ret) { 4771ca4d0b6SKalle Valo ath6kl_err("unable to set disconnect timeout: %d\n", ret); 4781ca4d0b6SKalle Valo return ret; 479bdcd8170SKalle Valo } 480bdcd8170SKalle Valo 4811ca4d0b6SKalle Valo if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST)) { 4821ca4d0b6SKalle Valo ret = ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED); 4831ca4d0b6SKalle Valo if (ret) { 4841ca4d0b6SKalle Valo ath6kl_err("unable to set txop bursting: %d\n", ret); 4851ca4d0b6SKalle Valo return ret; 4861ca4d0b6SKalle Valo } 487bdcd8170SKalle Valo } 488bdcd8170SKalle Valo 489b64de356SVasanthakumar Thiagarajan if (ar->p2p && (ar->vif_max == 1 || idx)) { 4900ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx, 4916bbc7c35SJouni Malinen P2P_FLAG_CAPABILITIES_REQ | 4924dea08e0SJouni Malinen P2P_FLAG_MACADDR_REQ | 4934dea08e0SJouni Malinen P2P_FLAG_HMODEL_REQ); 4944dea08e0SJouni Malinen if (ret) { 495cdeb8602SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, 496cdeb8602SKalle Valo "failed to request P2P capabilities (%d) - assuming P2P not supported\n", 497cdeb8602SKalle Valo ret); 4983db1cd5cSRusty Russell ar->p2p = false; 4996bbc7c35SJouni Malinen } 5006bbc7c35SJouni Malinen } 5016bbc7c35SJouni Malinen 502b64de356SVasanthakumar Thiagarajan if (ar->p2p && (ar->vif_max == 1 || idx)) { 5036bbc7c35SJouni Malinen /* Enable Probe Request reporting for P2P */ 5040ce59445SVasanthakumar Thiagarajan ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true); 5056bbc7c35SJouni Malinen if (ret) { 506cdeb8602SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, 507cdeb8602SKalle Valo "failed to enable Probe Request reporting (%d)\n", 508cdeb8602SKalle Valo ret); 5096bbc7c35SJouni Malinen } 5104dea08e0SJouni Malinen } 5114dea08e0SJouni Malinen 5121ca4d0b6SKalle Valo return ret; 513bdcd8170SKalle Valo } 514bdcd8170SKalle Valo 515bdcd8170SKalle Valo int ath6kl_configure_target(struct ath6kl *ar) 516bdcd8170SKalle Valo { 517bdcd8170SKalle Valo u32 param, ram_reserved_size; 5183226f68aSVasanthakumar Thiagarajan u8 fw_iftype, fw_mode = 0, fw_submode = 0; 51939586bf2SRyan Hsu int i, status; 520bdcd8170SKalle Valo 521f29af978SKalle Valo param = !!(ar->conf_flags & ATH6KL_CONF_UART_DEBUG); 52224fc32b3SKalle Valo if (ath6kl_bmi_write_hi32(ar, hi_serial_enable, param)) { 523a10e2f2fSVasanthakumar Thiagarajan ath6kl_err("bmi_write_memory for uart debug failed\n"); 524a10e2f2fSVasanthakumar Thiagarajan return -EIO; 525a10e2f2fSVasanthakumar Thiagarajan } 526a10e2f2fSVasanthakumar Thiagarajan 5277b85832dSVasanthakumar Thiagarajan /* 5287b85832dSVasanthakumar Thiagarajan * Note: Even though the firmware interface type is 5297b85832dSVasanthakumar Thiagarajan * chosen as BSS_STA for all three interfaces, can 5307b85832dSVasanthakumar Thiagarajan * be configured to IBSS/AP as long as the fw submode 5317b85832dSVasanthakumar Thiagarajan * remains normal mode (0 - AP, STA and IBSS). But 5327b85832dSVasanthakumar Thiagarajan * due to an target assert in firmware only one interface is 5337b85832dSVasanthakumar Thiagarajan * configured for now. 5347b85832dSVasanthakumar Thiagarajan */ 535dd3751f7SVasanthakumar Thiagarajan fw_iftype = HI_OPTION_FW_MODE_BSS_STA; 536bdcd8170SKalle Valo 53771f96ee6SKalle Valo for (i = 0; i < ar->vif_max; i++) 5387b85832dSVasanthakumar Thiagarajan fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS); 5397b85832dSVasanthakumar Thiagarajan 5407b85832dSVasanthakumar Thiagarajan /* 5411e8d13b0SVasanthakumar Thiagarajan * Submodes when fw does not support dynamic interface 5421e8d13b0SVasanthakumar Thiagarajan * switching: 5433226f68aSVasanthakumar Thiagarajan * vif[0] - AP/STA/IBSS 5447b85832dSVasanthakumar Thiagarajan * vif[1] - "P2P dev"/"P2P GO"/"P2P Client" 5457b85832dSVasanthakumar Thiagarajan * vif[2] - "P2P dev"/"P2P GO"/"P2P Client" 5461e8d13b0SVasanthakumar Thiagarajan * Otherwise, All the interface are initialized to p2p dev. 5477b85832dSVasanthakumar Thiagarajan */ 5483226f68aSVasanthakumar Thiagarajan 5491e8d13b0SVasanthakumar Thiagarajan if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, 5501e8d13b0SVasanthakumar Thiagarajan ar->fw_capabilities)) { 5511e8d13b0SVasanthakumar Thiagarajan for (i = 0; i < ar->vif_max; i++) 5521e8d13b0SVasanthakumar Thiagarajan fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV << 5531e8d13b0SVasanthakumar Thiagarajan (i * HI_OPTION_FW_SUBMODE_BITS); 5541e8d13b0SVasanthakumar Thiagarajan } else { 5553226f68aSVasanthakumar Thiagarajan for (i = 0; i < ar->max_norm_iface; i++) 5563226f68aSVasanthakumar Thiagarajan fw_submode |= HI_OPTION_FW_SUBMODE_NONE << 5573226f68aSVasanthakumar Thiagarajan (i * HI_OPTION_FW_SUBMODE_BITS); 5583226f68aSVasanthakumar Thiagarajan 55971f96ee6SKalle Valo for (i = ar->max_norm_iface; i < ar->vif_max; i++) 5603226f68aSVasanthakumar Thiagarajan fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV << 5613226f68aSVasanthakumar Thiagarajan (i * HI_OPTION_FW_SUBMODE_BITS); 5627b85832dSVasanthakumar Thiagarajan 563b64de356SVasanthakumar Thiagarajan if (ar->p2p && ar->vif_max == 1) 5647b85832dSVasanthakumar Thiagarajan fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV; 5651e8d13b0SVasanthakumar Thiagarajan } 5667b85832dSVasanthakumar Thiagarajan 56724fc32b3SKalle Valo if (ath6kl_bmi_write_hi32(ar, hi_app_host_interest, 56824fc32b3SKalle Valo HTC_PROTOCOL_VERSION) != 0) { 569bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for htc version failed\n"); 570bdcd8170SKalle Valo return -EIO; 571bdcd8170SKalle Valo } 572bdcd8170SKalle Valo 573bdcd8170SKalle Valo /* set the firmware mode to STA/IBSS/AP */ 574bdcd8170SKalle Valo param = 0; 575bdcd8170SKalle Valo 57680fb2686SKalle Valo if (ath6kl_bmi_read_hi32(ar, hi_option_flag, ¶m) != 0) { 577bdcd8170SKalle Valo ath6kl_err("bmi_read_memory for setting fwmode failed\n"); 578bdcd8170SKalle Valo return -EIO; 579bdcd8170SKalle Valo } 580bdcd8170SKalle Valo 58171f96ee6SKalle Valo param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT); 5827b85832dSVasanthakumar Thiagarajan param |= fw_mode << HI_OPTION_FW_MODE_SHIFT; 5837b85832dSVasanthakumar Thiagarajan param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT; 5847b85832dSVasanthakumar Thiagarajan 585bdcd8170SKalle Valo param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT); 586bdcd8170SKalle Valo param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT); 587bdcd8170SKalle Valo 58824fc32b3SKalle Valo if (ath6kl_bmi_write_hi32(ar, hi_option_flag, param) != 0) { 589bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for setting fwmode failed\n"); 590bdcd8170SKalle Valo return -EIO; 591bdcd8170SKalle Valo } 592bdcd8170SKalle Valo 593bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n"); 594bdcd8170SKalle Valo 595bdcd8170SKalle Valo /* 596bdcd8170SKalle Valo * Hardcode the address use for the extended board data 597bdcd8170SKalle Valo * Ideally this should be pre-allocate by the OS at boot time 598bdcd8170SKalle Valo * But since it is a new feature and board data is loaded 599bdcd8170SKalle Valo * at init time, we have to workaround this from host. 600bdcd8170SKalle Valo * It is difficult to patch the firmware boot code, 601bdcd8170SKalle Valo * but possible in theory. 602bdcd8170SKalle Valo */ 603bdcd8170SKalle Valo 6046b42d308SKalle Valo if (ar->target_type == TARGET_TYPE_AR6003) { 605991b27eaSKalle Valo param = ar->hw.board_ext_data_addr; 606991b27eaSKalle Valo ram_reserved_size = ar->hw.reserved_ram_size; 607bdcd8170SKalle Valo 60824fc32b3SKalle Valo if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) { 609bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n"); 610bdcd8170SKalle Valo return -EIO; 611bdcd8170SKalle Valo } 612991b27eaSKalle Valo 61324fc32b3SKalle Valo if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 61424fc32b3SKalle Valo ram_reserved_size) != 0) { 615bdcd8170SKalle Valo ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n"); 616bdcd8170SKalle Valo return -EIO; 617bdcd8170SKalle Valo } 6186b42d308SKalle Valo } 619bdcd8170SKalle Valo 620bdcd8170SKalle Valo /* set the block size for the target */ 621bdcd8170SKalle Valo if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0)) 622bdcd8170SKalle Valo /* use default number of control buffers */ 623bdcd8170SKalle Valo return -EIO; 624bdcd8170SKalle Valo 62539586bf2SRyan Hsu /* Configure GPIO AR600x UART */ 62624fc32b3SKalle Valo status = ath6kl_bmi_write_hi32(ar, hi_dbg_uart_txpin, 62724fc32b3SKalle Valo ar->hw.uarttx_pin); 62839586bf2SRyan Hsu if (status) 62939586bf2SRyan Hsu return status; 63039586bf2SRyan Hsu 63139586bf2SRyan Hsu /* Configure target refclk_hz */ 63224fc32b3SKalle Valo status = ath6kl_bmi_write_hi32(ar, hi_refclk_hz, ar->hw.refclk_hz); 63339586bf2SRyan Hsu if (status) 63439586bf2SRyan Hsu return status; 63539586bf2SRyan Hsu 636bdcd8170SKalle Valo return 0; 637bdcd8170SKalle Valo } 638bdcd8170SKalle Valo 639bdcd8170SKalle Valo /* firmware upload */ 640bdcd8170SKalle Valo static int ath6kl_get_fw(struct ath6kl *ar, const char *filename, 641bdcd8170SKalle Valo u8 **fw, size_t *fw_len) 642bdcd8170SKalle Valo { 643bdcd8170SKalle Valo const struct firmware *fw_entry; 644bdcd8170SKalle Valo int ret; 645bdcd8170SKalle Valo 646bdcd8170SKalle Valo ret = request_firmware(&fw_entry, filename, ar->dev); 647bdcd8170SKalle Valo if (ret) 648bdcd8170SKalle Valo return ret; 649bdcd8170SKalle Valo 650bdcd8170SKalle Valo *fw_len = fw_entry->size; 651bdcd8170SKalle Valo *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL); 652bdcd8170SKalle Valo 653bdcd8170SKalle Valo if (*fw == NULL) 654bdcd8170SKalle Valo ret = -ENOMEM; 655bdcd8170SKalle Valo 656bdcd8170SKalle Valo release_firmware(fw_entry); 657bdcd8170SKalle Valo 658bdcd8170SKalle Valo return ret; 659bdcd8170SKalle Valo } 660bdcd8170SKalle Valo 66192ecbff4SSam Leffler #ifdef CONFIG_OF 66292ecbff4SSam Leffler /* 66392ecbff4SSam Leffler * Check the device tree for a board-id and use it to construct 66492ecbff4SSam Leffler * the pathname to the firmware file. Used (for now) to find a 66592ecbff4SSam Leffler * fallback to the "bdata.bin" file--typically a symlink to the 66692ecbff4SSam Leffler * appropriate board-specific file. 66792ecbff4SSam Leffler */ 66892ecbff4SSam Leffler static bool check_device_tree(struct ath6kl *ar) 66992ecbff4SSam Leffler { 67092ecbff4SSam Leffler static const char *board_id_prop = "atheros,board-id"; 67192ecbff4SSam Leffler struct device_node *node; 67292ecbff4SSam Leffler char board_filename[64]; 67392ecbff4SSam Leffler const char *board_id; 67492ecbff4SSam Leffler int ret; 67592ecbff4SSam Leffler 67692ecbff4SSam Leffler for_each_compatible_node(node, NULL, "atheros,ath6kl") { 67792ecbff4SSam Leffler board_id = of_get_property(node, board_id_prop, NULL); 67892ecbff4SSam Leffler if (board_id == NULL) { 67992ecbff4SSam Leffler ath6kl_warn("No \"%s\" property on %s node.\n", 68092ecbff4SSam Leffler board_id_prop, node->name); 68192ecbff4SSam Leffler continue; 68292ecbff4SSam Leffler } 68392ecbff4SSam Leffler snprintf(board_filename, sizeof(board_filename), 684c0038972SKalle Valo "%s/bdata.%s.bin", ar->hw.fw.dir, board_id); 68592ecbff4SSam Leffler 68692ecbff4SSam Leffler ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board, 68792ecbff4SSam Leffler &ar->fw_board_len); 68892ecbff4SSam Leffler if (ret) { 68992ecbff4SSam Leffler ath6kl_err("Failed to get DT board file %s: %d\n", 69092ecbff4SSam Leffler board_filename, ret); 69192ecbff4SSam Leffler continue; 69292ecbff4SSam Leffler } 69392ecbff4SSam Leffler return true; 69492ecbff4SSam Leffler } 69592ecbff4SSam Leffler return false; 69692ecbff4SSam Leffler } 69792ecbff4SSam Leffler #else 69892ecbff4SSam Leffler static bool check_device_tree(struct ath6kl *ar) 69992ecbff4SSam Leffler { 70092ecbff4SSam Leffler return false; 70192ecbff4SSam Leffler } 70292ecbff4SSam Leffler #endif /* CONFIG_OF */ 70392ecbff4SSam Leffler 704bdcd8170SKalle Valo static int ath6kl_fetch_board_file(struct ath6kl *ar) 705bdcd8170SKalle Valo { 706bdcd8170SKalle Valo const char *filename; 707bdcd8170SKalle Valo int ret; 708bdcd8170SKalle Valo 709772c31eeSKalle Valo if (ar->fw_board != NULL) 710772c31eeSKalle Valo return 0; 711772c31eeSKalle Valo 712d1a9421dSKalle Valo if (WARN_ON(ar->hw.fw_board == NULL)) 713d1a9421dSKalle Valo return -EINVAL; 714d1a9421dSKalle Valo 715d1a9421dSKalle Valo filename = ar->hw.fw_board; 716bdcd8170SKalle Valo 717bdcd8170SKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw_board, 718bdcd8170SKalle Valo &ar->fw_board_len); 719bdcd8170SKalle Valo if (ret == 0) { 720bdcd8170SKalle Valo /* managed to get proper board file */ 721bdcd8170SKalle Valo return 0; 722bdcd8170SKalle Valo } 723bdcd8170SKalle Valo 72492ecbff4SSam Leffler if (check_device_tree(ar)) { 72592ecbff4SSam Leffler /* got board file from device tree */ 72692ecbff4SSam Leffler return 0; 72792ecbff4SSam Leffler } 72892ecbff4SSam Leffler 729bdcd8170SKalle Valo /* there was no proper board file, try to use default instead */ 730bdcd8170SKalle Valo ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n", 731bdcd8170SKalle Valo filename, ret); 732bdcd8170SKalle Valo 733d1a9421dSKalle Valo filename = ar->hw.fw_default_board; 734bdcd8170SKalle Valo 735bdcd8170SKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw_board, 736bdcd8170SKalle Valo &ar->fw_board_len); 737bdcd8170SKalle Valo if (ret) { 738bdcd8170SKalle Valo ath6kl_err("Failed to get default board file %s: %d\n", 739bdcd8170SKalle Valo filename, ret); 740bdcd8170SKalle Valo return ret; 741bdcd8170SKalle Valo } 742bdcd8170SKalle Valo 743bdcd8170SKalle Valo ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n"); 744bdcd8170SKalle Valo ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n"); 745bdcd8170SKalle Valo 746bdcd8170SKalle Valo return 0; 747bdcd8170SKalle Valo } 748bdcd8170SKalle Valo 749772c31eeSKalle Valo static int ath6kl_fetch_otp_file(struct ath6kl *ar) 750772c31eeSKalle Valo { 751c0038972SKalle Valo char filename[100]; 752772c31eeSKalle Valo int ret; 753772c31eeSKalle Valo 754772c31eeSKalle Valo if (ar->fw_otp != NULL) 755772c31eeSKalle Valo return 0; 756772c31eeSKalle Valo 757c0038972SKalle Valo if (ar->hw.fw.otp == NULL) { 758d1a9421dSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 759d1a9421dSKalle Valo "no OTP file configured for this hw\n"); 760772c31eeSKalle Valo return 0; 761772c31eeSKalle Valo } 762772c31eeSKalle Valo 763c0038972SKalle Valo snprintf(filename, sizeof(filename), "%s/%s", 764c0038972SKalle Valo ar->hw.fw.dir, ar->hw.fw.otp); 765d1a9421dSKalle Valo 766772c31eeSKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw_otp, 767772c31eeSKalle Valo &ar->fw_otp_len); 768772c31eeSKalle Valo if (ret) { 769772c31eeSKalle Valo ath6kl_err("Failed to get OTP file %s: %d\n", 770772c31eeSKalle Valo filename, ret); 771772c31eeSKalle Valo return ret; 772772c31eeSKalle Valo } 773772c31eeSKalle Valo 774772c31eeSKalle Valo return 0; 775772c31eeSKalle Valo } 776772c31eeSKalle Valo 7775f1127ffSKalle Valo static int ath6kl_fetch_testmode_file(struct ath6kl *ar) 778772c31eeSKalle Valo { 779c0038972SKalle Valo char filename[100]; 780772c31eeSKalle Valo int ret; 781772c31eeSKalle Valo 7825f1127ffSKalle Valo if (ar->testmode == 0) 783772c31eeSKalle Valo return 0; 784772c31eeSKalle Valo 7855f1127ffSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n", ar->testmode); 7865f1127ffSKalle Valo 7875f1127ffSKalle Valo if (ar->testmode == 2) { 788cd23c1c9SAlex Yang if (ar->hw.fw.utf == NULL) { 789cd23c1c9SAlex Yang ath6kl_warn("testmode 2 not supported\n"); 790cd23c1c9SAlex Yang return -EOPNOTSUPP; 791cd23c1c9SAlex Yang } 792cd23c1c9SAlex Yang 793cd23c1c9SAlex Yang snprintf(filename, sizeof(filename), "%s/%s", 794cd23c1c9SAlex Yang ar->hw.fw.dir, ar->hw.fw.utf); 795cd23c1c9SAlex Yang } else { 796c0038972SKalle Valo if (ar->hw.fw.tcmd == NULL) { 797cd23c1c9SAlex Yang ath6kl_warn("testmode 1 not supported\n"); 798772c31eeSKalle Valo return -EOPNOTSUPP; 799772c31eeSKalle Valo } 800772c31eeSKalle Valo 801c0038972SKalle Valo snprintf(filename, sizeof(filename), "%s/%s", 802c0038972SKalle Valo ar->hw.fw.dir, ar->hw.fw.tcmd); 803cd23c1c9SAlex Yang } 8045f1127ffSKalle Valo 805772c31eeSKalle Valo set_bit(TESTMODE, &ar->flag); 806772c31eeSKalle Valo 8075f1127ffSKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len); 8085f1127ffSKalle Valo if (ret) { 8095f1127ffSKalle Valo ath6kl_err("Failed to get testmode %d firmware file %s: %d\n", 8105f1127ffSKalle Valo ar->testmode, filename, ret); 8115f1127ffSKalle Valo return ret; 812772c31eeSKalle Valo } 813772c31eeSKalle Valo 8145f1127ffSKalle Valo return 0; 8155f1127ffSKalle Valo } 8165f1127ffSKalle Valo 8175f1127ffSKalle Valo static int ath6kl_fetch_fw_file(struct ath6kl *ar) 8185f1127ffSKalle Valo { 8195f1127ffSKalle Valo char filename[100]; 8205f1127ffSKalle Valo int ret; 8215f1127ffSKalle Valo 8225f1127ffSKalle Valo if (ar->fw != NULL) 8235f1127ffSKalle Valo return 0; 8245f1127ffSKalle Valo 825c0038972SKalle Valo /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */ 826c0038972SKalle Valo if (WARN_ON(ar->hw.fw.fw == NULL)) 827d1a9421dSKalle Valo return -EINVAL; 828d1a9421dSKalle Valo 829c0038972SKalle Valo snprintf(filename, sizeof(filename), "%s/%s", 830c0038972SKalle Valo ar->hw.fw.dir, ar->hw.fw.fw); 831772c31eeSKalle Valo 832772c31eeSKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len); 833772c31eeSKalle Valo if (ret) { 834772c31eeSKalle Valo ath6kl_err("Failed to get firmware file %s: %d\n", 835772c31eeSKalle Valo filename, ret); 836772c31eeSKalle Valo return ret; 837772c31eeSKalle Valo } 838772c31eeSKalle Valo 839772c31eeSKalle Valo return 0; 840772c31eeSKalle Valo } 841772c31eeSKalle Valo 842772c31eeSKalle Valo static int ath6kl_fetch_patch_file(struct ath6kl *ar) 843772c31eeSKalle Valo { 844c0038972SKalle Valo char filename[100]; 845772c31eeSKalle Valo int ret; 846772c31eeSKalle Valo 847d1a9421dSKalle Valo if (ar->fw_patch != NULL) 848772c31eeSKalle Valo return 0; 849772c31eeSKalle Valo 850c0038972SKalle Valo if (ar->hw.fw.patch == NULL) 851d1a9421dSKalle Valo return 0; 852d1a9421dSKalle Valo 853c0038972SKalle Valo snprintf(filename, sizeof(filename), "%s/%s", 854c0038972SKalle Valo ar->hw.fw.dir, ar->hw.fw.patch); 855d1a9421dSKalle Valo 856772c31eeSKalle Valo ret = ath6kl_get_fw(ar, filename, &ar->fw_patch, 857772c31eeSKalle Valo &ar->fw_patch_len); 858772c31eeSKalle Valo if (ret) { 859772c31eeSKalle Valo ath6kl_err("Failed to get patch file %s: %d\n", 860772c31eeSKalle Valo filename, ret); 861772c31eeSKalle Valo return ret; 862772c31eeSKalle Valo } 863772c31eeSKalle Valo 864772c31eeSKalle Valo return 0; 865772c31eeSKalle Valo } 866772c31eeSKalle Valo 867cd23c1c9SAlex Yang static int ath6kl_fetch_testscript_file(struct ath6kl *ar) 868cd23c1c9SAlex Yang { 869cd23c1c9SAlex Yang char filename[100]; 870cd23c1c9SAlex Yang int ret; 871cd23c1c9SAlex Yang 8725f1127ffSKalle Valo if (ar->testmode != 2) 873cd23c1c9SAlex Yang return 0; 874cd23c1c9SAlex Yang 875cd23c1c9SAlex Yang if (ar->fw_testscript != NULL) 876cd23c1c9SAlex Yang return 0; 877cd23c1c9SAlex Yang 878cd23c1c9SAlex Yang if (ar->hw.fw.testscript == NULL) 879cd23c1c9SAlex Yang return 0; 880cd23c1c9SAlex Yang 881cd23c1c9SAlex Yang snprintf(filename, sizeof(filename), "%s/%s", 882cd23c1c9SAlex Yang ar->hw.fw.dir, ar->hw.fw.testscript); 883cd23c1c9SAlex Yang 884cd23c1c9SAlex Yang ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript, 885cd23c1c9SAlex Yang &ar->fw_testscript_len); 886cd23c1c9SAlex Yang if (ret) { 887cd23c1c9SAlex Yang ath6kl_err("Failed to get testscript file %s: %d\n", 888cd23c1c9SAlex Yang filename, ret); 889cd23c1c9SAlex Yang return ret; 890cd23c1c9SAlex Yang } 891cd23c1c9SAlex Yang 892cd23c1c9SAlex Yang return 0; 893cd23c1c9SAlex Yang } 894cd23c1c9SAlex Yang 89550d41234SKalle Valo static int ath6kl_fetch_fw_api1(struct ath6kl *ar) 896772c31eeSKalle Valo { 897772c31eeSKalle Valo int ret; 898772c31eeSKalle Valo 899772c31eeSKalle Valo ret = ath6kl_fetch_otp_file(ar); 900772c31eeSKalle Valo if (ret) 901772c31eeSKalle Valo return ret; 902772c31eeSKalle Valo 903772c31eeSKalle Valo ret = ath6kl_fetch_fw_file(ar); 904772c31eeSKalle Valo if (ret) 905772c31eeSKalle Valo return ret; 906772c31eeSKalle Valo 907772c31eeSKalle Valo ret = ath6kl_fetch_patch_file(ar); 908772c31eeSKalle Valo if (ret) 909772c31eeSKalle Valo return ret; 910772c31eeSKalle Valo 911cd23c1c9SAlex Yang ret = ath6kl_fetch_testscript_file(ar); 912cd23c1c9SAlex Yang if (ret) 913cd23c1c9SAlex Yang return ret; 914cd23c1c9SAlex Yang 915772c31eeSKalle Valo return 0; 916772c31eeSKalle Valo } 917bdcd8170SKalle Valo 91865a8b4ccSKalle Valo static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name) 91950d41234SKalle Valo { 92050d41234SKalle Valo size_t magic_len, len, ie_len; 92150d41234SKalle Valo const struct firmware *fw; 92250d41234SKalle Valo struct ath6kl_fw_ie *hdr; 923c0038972SKalle Valo char filename[100]; 92450d41234SKalle Valo const u8 *data; 92597e0496dSKalle Valo int ret, ie_id, i, index, bit; 9268a137480SKalle Valo __le32 *val; 92750d41234SKalle Valo 92865a8b4ccSKalle Valo snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name); 92950d41234SKalle Valo 93050d41234SKalle Valo ret = request_firmware(&fw, filename, ar->dev); 93150d41234SKalle Valo if (ret) 93250d41234SKalle Valo return ret; 93350d41234SKalle Valo 93450d41234SKalle Valo data = fw->data; 93550d41234SKalle Valo len = fw->size; 93650d41234SKalle Valo 93750d41234SKalle Valo /* magic also includes the null byte, check that as well */ 93850d41234SKalle Valo magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1; 93950d41234SKalle Valo 94050d41234SKalle Valo if (len < magic_len) { 94150d41234SKalle Valo ret = -EINVAL; 94250d41234SKalle Valo goto out; 94350d41234SKalle Valo } 94450d41234SKalle Valo 94550d41234SKalle Valo if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) { 94650d41234SKalle Valo ret = -EINVAL; 94750d41234SKalle Valo goto out; 94850d41234SKalle Valo } 94950d41234SKalle Valo 95050d41234SKalle Valo len -= magic_len; 95150d41234SKalle Valo data += magic_len; 95250d41234SKalle Valo 95350d41234SKalle Valo /* loop elements */ 95450d41234SKalle Valo while (len > sizeof(struct ath6kl_fw_ie)) { 95550d41234SKalle Valo /* hdr is unaligned! */ 95650d41234SKalle Valo hdr = (struct ath6kl_fw_ie *) data; 95750d41234SKalle Valo 95850d41234SKalle Valo ie_id = le32_to_cpup(&hdr->id); 95950d41234SKalle Valo ie_len = le32_to_cpup(&hdr->len); 96050d41234SKalle Valo 96150d41234SKalle Valo len -= sizeof(*hdr); 96250d41234SKalle Valo data += sizeof(*hdr); 96350d41234SKalle Valo 96450d41234SKalle Valo if (len < ie_len) { 96550d41234SKalle Valo ret = -EINVAL; 96650d41234SKalle Valo goto out; 96750d41234SKalle Valo } 96850d41234SKalle Valo 96950d41234SKalle Valo switch (ie_id) { 970b5b6f6a9SNaveen Singh case ATH6KL_FW_IE_FW_VERSION: 971b5b6f6a9SNaveen Singh strlcpy(ar->wiphy->fw_version, data, 972b5b6f6a9SNaveen Singh sizeof(ar->wiphy->fw_version)); 973b5b6f6a9SNaveen Singh 974b5b6f6a9SNaveen Singh ath6kl_dbg(ATH6KL_DBG_BOOT, 975b5b6f6a9SNaveen Singh "found fw version %s\n", 976b5b6f6a9SNaveen Singh ar->wiphy->fw_version); 977b5b6f6a9SNaveen Singh break; 97850d41234SKalle Valo case ATH6KL_FW_IE_OTP_IMAGE: 979ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n", 9806bc36431SKalle Valo ie_len); 9816bc36431SKalle Valo 98250d41234SKalle Valo ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL); 98350d41234SKalle Valo 98450d41234SKalle Valo if (ar->fw_otp == NULL) { 98550d41234SKalle Valo ret = -ENOMEM; 98650d41234SKalle Valo goto out; 98750d41234SKalle Valo } 98850d41234SKalle Valo 98950d41234SKalle Valo ar->fw_otp_len = ie_len; 99050d41234SKalle Valo break; 99150d41234SKalle Valo case ATH6KL_FW_IE_FW_IMAGE: 992ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n", 9936bc36431SKalle Valo ie_len); 9946bc36431SKalle Valo 9955f1127ffSKalle Valo /* in testmode we already might have a fw file */ 9965f1127ffSKalle Valo if (ar->fw != NULL) 9975f1127ffSKalle Valo break; 9985f1127ffSKalle Valo 9998437754cSVivek Natarajan ar->fw = vmalloc(ie_len); 100050d41234SKalle Valo 100150d41234SKalle Valo if (ar->fw == NULL) { 100250d41234SKalle Valo ret = -ENOMEM; 100350d41234SKalle Valo goto out; 100450d41234SKalle Valo } 100550d41234SKalle Valo 10068437754cSVivek Natarajan memcpy(ar->fw, data, ie_len); 100750d41234SKalle Valo ar->fw_len = ie_len; 100850d41234SKalle Valo break; 100950d41234SKalle Valo case ATH6KL_FW_IE_PATCH_IMAGE: 1010ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n", 10116bc36431SKalle Valo ie_len); 10126bc36431SKalle Valo 101350d41234SKalle Valo ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL); 101450d41234SKalle Valo 101550d41234SKalle Valo if (ar->fw_patch == NULL) { 101650d41234SKalle Valo ret = -ENOMEM; 101750d41234SKalle Valo goto out; 101850d41234SKalle Valo } 101950d41234SKalle Valo 102050d41234SKalle Valo ar->fw_patch_len = ie_len; 102150d41234SKalle Valo break; 10228a137480SKalle Valo case ATH6KL_FW_IE_RESERVED_RAM_SIZE: 10238a137480SKalle Valo val = (__le32 *) data; 10248a137480SKalle Valo ar->hw.reserved_ram_size = le32_to_cpup(val); 10256bc36431SKalle Valo 10266bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 10276bc36431SKalle Valo "found reserved ram size ie 0x%d\n", 10286bc36431SKalle Valo ar->hw.reserved_ram_size); 10298a137480SKalle Valo break; 103097e0496dSKalle Valo case ATH6KL_FW_IE_CAPABILITIES: 10316bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 1032ef548626SKalle Valo "found firmware capabilities ie (%zd B)\n", 10336bc36431SKalle Valo ie_len); 10346bc36431SKalle Valo 103597e0496dSKalle Valo for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) { 1036277d90f4SKalle Valo index = i / 8; 103797e0496dSKalle Valo bit = i % 8; 103897e0496dSKalle Valo 1039c85251f8SThomas Pedersen if (index == ie_len) 1040c85251f8SThomas Pedersen break; 1041c85251f8SThomas Pedersen 104297e0496dSKalle Valo if (data[index] & (1 << bit)) 104397e0496dSKalle Valo __set_bit(i, ar->fw_capabilities); 104497e0496dSKalle Valo } 10456bc36431SKalle Valo 10466bc36431SKalle Valo ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "", 10476bc36431SKalle Valo ar->fw_capabilities, 10486bc36431SKalle Valo sizeof(ar->fw_capabilities)); 104997e0496dSKalle Valo break; 10501b4304daSKalle Valo case ATH6KL_FW_IE_PATCH_ADDR: 10511b4304daSKalle Valo if (ie_len != sizeof(*val)) 10521b4304daSKalle Valo break; 10531b4304daSKalle Valo 10541b4304daSKalle Valo val = (__le32 *) data; 10551b4304daSKalle Valo ar->hw.dataset_patch_addr = le32_to_cpup(val); 10566bc36431SKalle Valo 10576bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 105803ef0250SKalle Valo "found patch address ie 0x%x\n", 10596bc36431SKalle Valo ar->hw.dataset_patch_addr); 10601b4304daSKalle Valo break; 106103ef0250SKalle Valo case ATH6KL_FW_IE_BOARD_ADDR: 106203ef0250SKalle Valo if (ie_len != sizeof(*val)) 106303ef0250SKalle Valo break; 106403ef0250SKalle Valo 106503ef0250SKalle Valo val = (__le32 *) data; 106603ef0250SKalle Valo ar->hw.board_addr = le32_to_cpup(val); 106703ef0250SKalle Valo 106803ef0250SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 106903ef0250SKalle Valo "found board address ie 0x%x\n", 107003ef0250SKalle Valo ar->hw.board_addr); 107103ef0250SKalle Valo break; 1072368b1b0fSKalle Valo case ATH6KL_FW_IE_VIF_MAX: 1073368b1b0fSKalle Valo if (ie_len != sizeof(*val)) 1074368b1b0fSKalle Valo break; 1075368b1b0fSKalle Valo 1076368b1b0fSKalle Valo val = (__le32 *) data; 1077368b1b0fSKalle Valo ar->vif_max = min_t(unsigned int, le32_to_cpup(val), 1078368b1b0fSKalle Valo ATH6KL_VIF_MAX); 1079368b1b0fSKalle Valo 1080f143379dSVasanthakumar Thiagarajan if (ar->vif_max > 1 && !ar->p2p) 1081f143379dSVasanthakumar Thiagarajan ar->max_norm_iface = 2; 1082f143379dSVasanthakumar Thiagarajan 1083368b1b0fSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 1084368b1b0fSKalle Valo "found vif max ie %d\n", ar->vif_max); 1085368b1b0fSKalle Valo break; 108650d41234SKalle Valo default: 10876bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n", 108850d41234SKalle Valo le32_to_cpup(&hdr->id)); 108950d41234SKalle Valo break; 109050d41234SKalle Valo } 109150d41234SKalle Valo 109250d41234SKalle Valo len -= ie_len; 109350d41234SKalle Valo data += ie_len; 109450d41234SKalle Valo }; 109550d41234SKalle Valo 109650d41234SKalle Valo ret = 0; 109750d41234SKalle Valo out: 109850d41234SKalle Valo release_firmware(fw); 109950d41234SKalle Valo 110050d41234SKalle Valo return ret; 110150d41234SKalle Valo } 110250d41234SKalle Valo 110345eaa78fSKalle Valo int ath6kl_init_fetch_firmwares(struct ath6kl *ar) 110450d41234SKalle Valo { 110550d41234SKalle Valo int ret; 110650d41234SKalle Valo 110750d41234SKalle Valo ret = ath6kl_fetch_board_file(ar); 110850d41234SKalle Valo if (ret) 110950d41234SKalle Valo return ret; 111050d41234SKalle Valo 11115f1127ffSKalle Valo ret = ath6kl_fetch_testmode_file(ar); 11125f1127ffSKalle Valo if (ret) 11135f1127ffSKalle Valo return ret; 11145f1127ffSKalle Valo 1115b1f47e3aSThomas Pedersen ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API4_FILE); 1116b1f47e3aSThomas Pedersen if (ret == 0) { 1117b1f47e3aSThomas Pedersen ar->fw_api = 4; 1118b1f47e3aSThomas Pedersen goto out; 1119b1f47e3aSThomas Pedersen } 1120b1f47e3aSThomas Pedersen 112165a8b4ccSKalle Valo ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE); 11226bc36431SKalle Valo if (ret == 0) { 112365a8b4ccSKalle Valo ar->fw_api = 3; 112465a8b4ccSKalle Valo goto out; 112565a8b4ccSKalle Valo } 112665a8b4ccSKalle Valo 112765a8b4ccSKalle Valo ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE); 112865a8b4ccSKalle Valo if (ret == 0) { 112965a8b4ccSKalle Valo ar->fw_api = 2; 113065a8b4ccSKalle Valo goto out; 11316bc36431SKalle Valo } 113250d41234SKalle Valo 113350d41234SKalle Valo ret = ath6kl_fetch_fw_api1(ar); 113450d41234SKalle Valo if (ret) 113550d41234SKalle Valo return ret; 113650d41234SKalle Valo 113765a8b4ccSKalle Valo ar->fw_api = 1; 113865a8b4ccSKalle Valo 113965a8b4ccSKalle Valo out: 114065a8b4ccSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api); 11416bc36431SKalle Valo 114250d41234SKalle Valo return 0; 114350d41234SKalle Valo } 114450d41234SKalle Valo 1145bdcd8170SKalle Valo static int ath6kl_upload_board_file(struct ath6kl *ar) 1146bdcd8170SKalle Valo { 1147bdcd8170SKalle Valo u32 board_address, board_ext_address, param; 114831024d99SKevin Fang u32 board_data_size, board_ext_data_size; 1149bdcd8170SKalle Valo int ret; 1150bdcd8170SKalle Valo 1151772c31eeSKalle Valo if (WARN_ON(ar->fw_board == NULL)) 1152772c31eeSKalle Valo return -ENOENT; 1153bdcd8170SKalle Valo 115431024d99SKevin Fang /* 115531024d99SKevin Fang * Determine where in Target RAM to write Board Data. 115631024d99SKevin Fang * For AR6004, host determine Target RAM address for 115731024d99SKevin Fang * writing board data. 115831024d99SKevin Fang */ 11590d4d72bfSKalle Valo if (ar->hw.board_addr != 0) { 1160b0fc7c1aSKalle Valo board_address = ar->hw.board_addr; 116124fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_board_data, 1162b0fc7c1aSKalle Valo board_address); 116331024d99SKevin Fang } else { 116480fb2686SKalle Valo ath6kl_bmi_read_hi32(ar, hi_board_data, &board_address); 116531024d99SKevin Fang } 116631024d99SKevin Fang 1167bdcd8170SKalle Valo /* determine where in target ram to write extended board data */ 116880fb2686SKalle Valo ath6kl_bmi_read_hi32(ar, hi_board_ext_data, &board_ext_address); 1169bdcd8170SKalle Valo 117050e2740bSKalle Valo if (ar->target_type == TARGET_TYPE_AR6003 && 117150e2740bSKalle Valo board_ext_address == 0) { 1172bdcd8170SKalle Valo ath6kl_err("Failed to get board file target address.\n"); 1173bdcd8170SKalle Valo return -EINVAL; 1174bdcd8170SKalle Valo } 1175bdcd8170SKalle Valo 117631024d99SKevin Fang switch (ar->target_type) { 117731024d99SKevin Fang case TARGET_TYPE_AR6003: 117831024d99SKevin Fang board_data_size = AR6003_BOARD_DATA_SZ; 117931024d99SKevin Fang board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ; 1180fb1ac2efSPrasanna Kumar if (ar->fw_board_len > (board_data_size + board_ext_data_size)) 1181fb1ac2efSPrasanna Kumar board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ_V2; 118231024d99SKevin Fang break; 118331024d99SKevin Fang case TARGET_TYPE_AR6004: 118431024d99SKevin Fang board_data_size = AR6004_BOARD_DATA_SZ; 118531024d99SKevin Fang board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ; 118631024d99SKevin Fang break; 118731024d99SKevin Fang default: 118831024d99SKevin Fang WARN_ON(1); 118931024d99SKevin Fang return -EINVAL; 119031024d99SKevin Fang break; 119131024d99SKevin Fang } 119231024d99SKevin Fang 119350e2740bSKalle Valo if (board_ext_address && 119450e2740bSKalle Valo ar->fw_board_len == (board_data_size + board_ext_data_size)) { 119531024d99SKevin Fang 1196bdcd8170SKalle Valo /* write extended board data */ 11976bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 11986bc36431SKalle Valo "writing extended board data to 0x%x (%d B)\n", 11996bc36431SKalle Valo board_ext_address, board_ext_data_size); 12006bc36431SKalle Valo 1201bdcd8170SKalle Valo ret = ath6kl_bmi_write(ar, board_ext_address, 120231024d99SKevin Fang ar->fw_board + board_data_size, 120331024d99SKevin Fang board_ext_data_size); 1204bdcd8170SKalle Valo if (ret) { 1205bdcd8170SKalle Valo ath6kl_err("Failed to write extended board data: %d\n", 1206bdcd8170SKalle Valo ret); 1207bdcd8170SKalle Valo return ret; 1208bdcd8170SKalle Valo } 1209bdcd8170SKalle Valo 1210bdcd8170SKalle Valo /* record that extended board data is initialized */ 121131024d99SKevin Fang param = (board_ext_data_size << 16) | 1; 121231024d99SKevin Fang 121324fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_board_ext_data_config, param); 1214bdcd8170SKalle Valo } 1215bdcd8170SKalle Valo 121631024d99SKevin Fang if (ar->fw_board_len < board_data_size) { 1217bdcd8170SKalle Valo ath6kl_err("Too small board file: %zu\n", ar->fw_board_len); 1218bdcd8170SKalle Valo ret = -EINVAL; 1219bdcd8170SKalle Valo return ret; 1220bdcd8170SKalle Valo } 1221bdcd8170SKalle Valo 12226bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n", 12236bc36431SKalle Valo board_address, board_data_size); 12246bc36431SKalle Valo 1225bdcd8170SKalle Valo ret = ath6kl_bmi_write(ar, board_address, ar->fw_board, 122631024d99SKevin Fang board_data_size); 1227bdcd8170SKalle Valo 1228bdcd8170SKalle Valo if (ret) { 1229bdcd8170SKalle Valo ath6kl_err("Board file bmi write failed: %d\n", ret); 1230bdcd8170SKalle Valo return ret; 1231bdcd8170SKalle Valo } 1232bdcd8170SKalle Valo 1233bdcd8170SKalle Valo /* record the fact that Board Data IS initialized */ 123424fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_board_data_initialized, 1); 1235bdcd8170SKalle Valo 1236bdcd8170SKalle Valo return ret; 1237bdcd8170SKalle Valo } 1238bdcd8170SKalle Valo 1239bdcd8170SKalle Valo static int ath6kl_upload_otp(struct ath6kl *ar) 1240bdcd8170SKalle Valo { 1241bdcd8170SKalle Valo u32 address, param; 1242bef26a7fSKalle Valo bool from_hw = false; 1243bdcd8170SKalle Valo int ret; 1244bdcd8170SKalle Valo 124550e2740bSKalle Valo if (ar->fw_otp == NULL) 124650e2740bSKalle Valo return 0; 1247bdcd8170SKalle Valo 1248a01ac414SKalle Valo address = ar->hw.app_load_addr; 1249bdcd8170SKalle Valo 1250ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address, 12516bc36431SKalle Valo ar->fw_otp_len); 12526bc36431SKalle Valo 1253bdcd8170SKalle Valo ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp, 1254bdcd8170SKalle Valo ar->fw_otp_len); 1255bdcd8170SKalle Valo if (ret) { 1256bdcd8170SKalle Valo ath6kl_err("Failed to upload OTP file: %d\n", ret); 1257bdcd8170SKalle Valo return ret; 1258bdcd8170SKalle Valo } 1259bdcd8170SKalle Valo 1260639d0b89SKalle Valo /* read firmware start address */ 126180fb2686SKalle Valo ret = ath6kl_bmi_read_hi32(ar, hi_app_start, &address); 1262639d0b89SKalle Valo 1263639d0b89SKalle Valo if (ret) { 1264639d0b89SKalle Valo ath6kl_err("Failed to read hi_app_start: %d\n", ret); 1265639d0b89SKalle Valo return ret; 1266639d0b89SKalle Valo } 1267639d0b89SKalle Valo 1268bef26a7fSKalle Valo if (ar->hw.app_start_override_addr == 0) { 1269639d0b89SKalle Valo ar->hw.app_start_override_addr = address; 1270bef26a7fSKalle Valo from_hw = true; 1271bef26a7fSKalle Valo } 1272639d0b89SKalle Valo 1273bef26a7fSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n", 1274bef26a7fSKalle Valo from_hw ? " (from hw)" : "", 12756bc36431SKalle Valo ar->hw.app_start_override_addr); 12766bc36431SKalle Valo 1277bdcd8170SKalle Valo /* execute the OTP code */ 1278bef26a7fSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n", 1279bef26a7fSKalle Valo ar->hw.app_start_override_addr); 1280bdcd8170SKalle Valo param = 0; 1281bef26a7fSKalle Valo ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m); 1282bdcd8170SKalle Valo 1283bdcd8170SKalle Valo return ret; 1284bdcd8170SKalle Valo } 1285bdcd8170SKalle Valo 1286bdcd8170SKalle Valo static int ath6kl_upload_firmware(struct ath6kl *ar) 1287bdcd8170SKalle Valo { 1288bdcd8170SKalle Valo u32 address; 1289bdcd8170SKalle Valo int ret; 1290bdcd8170SKalle Valo 1291772c31eeSKalle Valo if (WARN_ON(ar->fw == NULL)) 129250e2740bSKalle Valo return 0; 1293bdcd8170SKalle Valo 1294a01ac414SKalle Valo address = ar->hw.app_load_addr; 1295bdcd8170SKalle Valo 1296ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n", 12976bc36431SKalle Valo address, ar->fw_len); 12986bc36431SKalle Valo 1299bdcd8170SKalle Valo ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len); 1300bdcd8170SKalle Valo 1301bdcd8170SKalle Valo if (ret) { 1302bdcd8170SKalle Valo ath6kl_err("Failed to write firmware: %d\n", ret); 1303bdcd8170SKalle Valo return ret; 1304bdcd8170SKalle Valo } 1305bdcd8170SKalle Valo 130631024d99SKevin Fang /* 130731024d99SKevin Fang * Set starting address for firmware 130831024d99SKevin Fang * Don't need to setup app_start override addr on AR6004 130931024d99SKevin Fang */ 131031024d99SKevin Fang if (ar->target_type != TARGET_TYPE_AR6004) { 1311a01ac414SKalle Valo address = ar->hw.app_start_override_addr; 1312bdcd8170SKalle Valo ath6kl_bmi_set_app_start(ar, address); 131331024d99SKevin Fang } 1314bdcd8170SKalle Valo return ret; 1315bdcd8170SKalle Valo } 1316bdcd8170SKalle Valo 1317bdcd8170SKalle Valo static int ath6kl_upload_patch(struct ath6kl *ar) 1318bdcd8170SKalle Valo { 131924fc32b3SKalle Valo u32 address; 1320bdcd8170SKalle Valo int ret; 1321bdcd8170SKalle Valo 132250e2740bSKalle Valo if (ar->fw_patch == NULL) 132350e2740bSKalle Valo return 0; 1324bdcd8170SKalle Valo 1325a01ac414SKalle Valo address = ar->hw.dataset_patch_addr; 1326bdcd8170SKalle Valo 1327ef548626SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n", 13286bc36431SKalle Valo address, ar->fw_patch_len); 13296bc36431SKalle Valo 1330bdcd8170SKalle Valo ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len); 1331bdcd8170SKalle Valo if (ret) { 1332bdcd8170SKalle Valo ath6kl_err("Failed to write patch file: %d\n", ret); 1333bdcd8170SKalle Valo return ret; 1334bdcd8170SKalle Valo } 1335bdcd8170SKalle Valo 133624fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_dset_list_head, address); 1337bdcd8170SKalle Valo 1338bdcd8170SKalle Valo return 0; 1339bdcd8170SKalle Valo } 1340bdcd8170SKalle Valo 1341cd23c1c9SAlex Yang static int ath6kl_upload_testscript(struct ath6kl *ar) 1342cd23c1c9SAlex Yang { 134324fc32b3SKalle Valo u32 address; 1344cd23c1c9SAlex Yang int ret; 1345cd23c1c9SAlex Yang 13465f1127ffSKalle Valo if (ar->testmode != 2) 1347cd23c1c9SAlex Yang return 0; 1348cd23c1c9SAlex Yang 1349cd23c1c9SAlex Yang if (ar->fw_testscript == NULL) 1350cd23c1c9SAlex Yang return 0; 1351cd23c1c9SAlex Yang 1352cd23c1c9SAlex Yang address = ar->hw.testscript_addr; 1353cd23c1c9SAlex Yang 1354cd23c1c9SAlex Yang ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n", 1355cd23c1c9SAlex Yang address, ar->fw_testscript_len); 1356cd23c1c9SAlex Yang 1357cd23c1c9SAlex Yang ret = ath6kl_bmi_write(ar, address, ar->fw_testscript, 1358cd23c1c9SAlex Yang ar->fw_testscript_len); 1359cd23c1c9SAlex Yang if (ret) { 1360cd23c1c9SAlex Yang ath6kl_err("Failed to write testscript file: %d\n", ret); 1361cd23c1c9SAlex Yang return ret; 1362cd23c1c9SAlex Yang } 1363cd23c1c9SAlex Yang 136424fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_ota_testscript, address); 136524fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 4096); 136624fc32b3SKalle Valo ath6kl_bmi_write_hi32(ar, hi_test_apps_related, 1); 1367cd23c1c9SAlex Yang 1368cd23c1c9SAlex Yang return 0; 1369cd23c1c9SAlex Yang } 1370cd23c1c9SAlex Yang 1371bdcd8170SKalle Valo static int ath6kl_init_upload(struct ath6kl *ar) 1372bdcd8170SKalle Valo { 1373bdcd8170SKalle Valo u32 param, options, sleep, address; 1374bdcd8170SKalle Valo int status = 0; 1375bdcd8170SKalle Valo 137631024d99SKevin Fang if (ar->target_type != TARGET_TYPE_AR6003 && 137731024d99SKevin Fang ar->target_type != TARGET_TYPE_AR6004) 1378bdcd8170SKalle Valo return -EINVAL; 1379bdcd8170SKalle Valo 1380bdcd8170SKalle Valo /* temporarily disable system sleep */ 1381bdcd8170SKalle Valo address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; 1382bdcd8170SKalle Valo status = ath6kl_bmi_reg_read(ar, address, ¶m); 1383bdcd8170SKalle Valo if (status) 1384bdcd8170SKalle Valo return status; 1385bdcd8170SKalle Valo 1386bdcd8170SKalle Valo options = param; 1387bdcd8170SKalle Valo 1388bdcd8170SKalle Valo param |= ATH6KL_OPTION_SLEEP_DISABLE; 1389bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1390bdcd8170SKalle Valo if (status) 1391bdcd8170SKalle Valo return status; 1392bdcd8170SKalle Valo 1393bdcd8170SKalle Valo address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; 1394bdcd8170SKalle Valo status = ath6kl_bmi_reg_read(ar, address, ¶m); 1395bdcd8170SKalle Valo if (status) 1396bdcd8170SKalle Valo return status; 1397bdcd8170SKalle Valo 1398bdcd8170SKalle Valo sleep = param; 1399bdcd8170SKalle Valo 1400bdcd8170SKalle Valo param |= SM(SYSTEM_SLEEP_DISABLE, 1); 1401bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1402bdcd8170SKalle Valo if (status) 1403bdcd8170SKalle Valo return status; 1404bdcd8170SKalle Valo 1405bdcd8170SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n", 1406bdcd8170SKalle Valo options, sleep); 1407bdcd8170SKalle Valo 1408bdcd8170SKalle Valo /* program analog PLL register */ 140931024d99SKevin Fang /* no need to control 40/44MHz clock on AR6004 */ 141031024d99SKevin Fang if (ar->target_type != TARGET_TYPE_AR6004) { 1411bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER, 1412bdcd8170SKalle Valo 0xF9104001); 141331024d99SKevin Fang 1414bdcd8170SKalle Valo if (status) 1415bdcd8170SKalle Valo return status; 1416bdcd8170SKalle Valo 1417bdcd8170SKalle Valo /* Run at 80/88MHz by default */ 1418bdcd8170SKalle Valo param = SM(CPU_CLOCK_STANDARD, 1); 1419bdcd8170SKalle Valo 1420bdcd8170SKalle Valo address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS; 1421bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1422bdcd8170SKalle Valo if (status) 1423bdcd8170SKalle Valo return status; 142431024d99SKevin Fang } 1425bdcd8170SKalle Valo 1426bdcd8170SKalle Valo param = 0; 1427bdcd8170SKalle Valo address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS; 1428bdcd8170SKalle Valo param = SM(LPO_CAL_ENABLE, 1); 1429bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1430bdcd8170SKalle Valo if (status) 1431bdcd8170SKalle Valo return status; 1432bdcd8170SKalle Valo 1433bdcd8170SKalle Valo /* WAR to avoid SDIO CRC err */ 1434a2e1be33SMohammed Shafi Shajakhan if (ar->hw.flags & ATH6KL_HW_SDIO_CRC_ERROR_WAR) { 1435bdcd8170SKalle Valo ath6kl_err("temporary war to avoid sdio crc error\n"); 1436bdcd8170SKalle Valo 1437fa338be0SVasanthakumar Thiagarajan param = 0x28; 1438fa338be0SVasanthakumar Thiagarajan address = GPIO_BASE_ADDRESS + GPIO_PIN9_ADDRESS; 1439fa338be0SVasanthakumar Thiagarajan status = ath6kl_bmi_reg_write(ar, address, param); 1440fa338be0SVasanthakumar Thiagarajan if (status) 1441fa338be0SVasanthakumar Thiagarajan return status; 1442fa338be0SVasanthakumar Thiagarajan 1443bdcd8170SKalle Valo param = 0x20; 1444bdcd8170SKalle Valo 1445bdcd8170SKalle Valo address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS; 1446bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1447bdcd8170SKalle Valo if (status) 1448bdcd8170SKalle Valo return status; 1449bdcd8170SKalle Valo 1450bdcd8170SKalle Valo address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS; 1451bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1452bdcd8170SKalle Valo if (status) 1453bdcd8170SKalle Valo return status; 1454bdcd8170SKalle Valo 1455bdcd8170SKalle Valo address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS; 1456bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1457bdcd8170SKalle Valo if (status) 1458bdcd8170SKalle Valo return status; 1459bdcd8170SKalle Valo 1460bdcd8170SKalle Valo address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS; 1461bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1462bdcd8170SKalle Valo if (status) 1463bdcd8170SKalle Valo return status; 1464bdcd8170SKalle Valo } 1465bdcd8170SKalle Valo 1466bdcd8170SKalle Valo /* write EEPROM data to Target RAM */ 1467bdcd8170SKalle Valo status = ath6kl_upload_board_file(ar); 1468bdcd8170SKalle Valo if (status) 1469bdcd8170SKalle Valo return status; 1470bdcd8170SKalle Valo 1471bdcd8170SKalle Valo /* transfer One time Programmable data */ 1472bdcd8170SKalle Valo status = ath6kl_upload_otp(ar); 1473bdcd8170SKalle Valo if (status) 1474bdcd8170SKalle Valo return status; 1475bdcd8170SKalle Valo 1476bdcd8170SKalle Valo /* Download Target firmware */ 1477bdcd8170SKalle Valo status = ath6kl_upload_firmware(ar); 1478bdcd8170SKalle Valo if (status) 1479bdcd8170SKalle Valo return status; 1480bdcd8170SKalle Valo 1481bdcd8170SKalle Valo status = ath6kl_upload_patch(ar); 1482bdcd8170SKalle Valo if (status) 1483bdcd8170SKalle Valo return status; 1484bdcd8170SKalle Valo 1485cd23c1c9SAlex Yang /* Download the test script */ 1486cd23c1c9SAlex Yang status = ath6kl_upload_testscript(ar); 1487cd23c1c9SAlex Yang if (status) 1488cd23c1c9SAlex Yang return status; 1489cd23c1c9SAlex Yang 1490bdcd8170SKalle Valo /* Restore system sleep */ 1491bdcd8170SKalle Valo address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; 1492bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, sleep); 1493bdcd8170SKalle Valo if (status) 1494bdcd8170SKalle Valo return status; 1495bdcd8170SKalle Valo 1496bdcd8170SKalle Valo address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; 1497bdcd8170SKalle Valo param = options | 0x20; 1498bdcd8170SKalle Valo status = ath6kl_bmi_reg_write(ar, address, param); 1499bdcd8170SKalle Valo if (status) 1500bdcd8170SKalle Valo return status; 1501bdcd8170SKalle Valo 1502bdcd8170SKalle Valo return status; 1503bdcd8170SKalle Valo } 1504bdcd8170SKalle Valo 150545eaa78fSKalle Valo int ath6kl_init_hw_params(struct ath6kl *ar) 1506a01ac414SKalle Valo { 15071b46dc04SKalle Valo const struct ath6kl_hw *uninitialized_var(hw); 1508856f4b31SKalle Valo int i; 1509bef26a7fSKalle Valo 1510856f4b31SKalle Valo for (i = 0; i < ARRAY_SIZE(hw_list); i++) { 1511856f4b31SKalle Valo hw = &hw_list[i]; 1512bef26a7fSKalle Valo 1513856f4b31SKalle Valo if (hw->id == ar->version.target_ver) 1514a01ac414SKalle Valo break; 1515856f4b31SKalle Valo } 1516856f4b31SKalle Valo 1517856f4b31SKalle Valo if (i == ARRAY_SIZE(hw_list)) { 1518a01ac414SKalle Valo ath6kl_err("Unsupported hardware version: 0x%x\n", 1519a01ac414SKalle Valo ar->version.target_ver); 1520a01ac414SKalle Valo return -EINVAL; 1521a01ac414SKalle Valo } 1522a01ac414SKalle Valo 1523856f4b31SKalle Valo ar->hw = *hw; 1524856f4b31SKalle Valo 15256bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 15266bc36431SKalle Valo "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n", 15276bc36431SKalle Valo ar->version.target_ver, ar->target_type, 15286bc36431SKalle Valo ar->hw.dataset_patch_addr, ar->hw.app_load_addr); 15296bc36431SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, 15306bc36431SKalle Valo "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x", 15316bc36431SKalle Valo ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr, 15326bc36431SKalle Valo ar->hw.reserved_ram_size); 153339586bf2SRyan Hsu ath6kl_dbg(ATH6KL_DBG_BOOT, 153439586bf2SRyan Hsu "refclk_hz %d uarttx_pin %d", 153539586bf2SRyan Hsu ar->hw.refclk_hz, ar->hw.uarttx_pin); 15366bc36431SKalle Valo 1537a01ac414SKalle Valo return 0; 1538a01ac414SKalle Valo } 1539a01ac414SKalle Valo 1540293badf4SKalle Valo static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type) 1541293badf4SKalle Valo { 1542293badf4SKalle Valo switch (type) { 1543293badf4SKalle Valo case ATH6KL_HIF_TYPE_SDIO: 1544293badf4SKalle Valo return "sdio"; 1545293badf4SKalle Valo case ATH6KL_HIF_TYPE_USB: 1546293badf4SKalle Valo return "usb"; 1547293badf4SKalle Valo } 1548293badf4SKalle Valo 1549293badf4SKalle Valo return NULL; 1550293badf4SKalle Valo } 1551293badf4SKalle Valo 1552e72c2746SKalle Valo 1553e72c2746SKalle Valo static const struct fw_capa_str_map { 1554e72c2746SKalle Valo int id; 1555e72c2746SKalle Valo const char *name; 1556e72c2746SKalle Valo } fw_capa_map[] = { 1557e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_HOST_P2P, "host-p2p" }, 1558e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_SCHED_SCAN, "sched-scan" }, 1559e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, "sta-p2pdev-duplex" }, 1560e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT, "inactivity-timeout" }, 1561e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE, "rsn-cap-override" }, 1562e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER, "wow-mc-filter" }, 1563e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_BMISS_ENHANCE, "bmiss-enhance" }, 1564e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST, "sscan-match-list" }, 1565e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD, "rssi-scan-thold" }, 1566e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR, "custom-mac-addr" }, 1567e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY, "tx-err-notify" }, 1568e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_REGDOMAIN, "regdomain" }, 1569e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2, "sched-scan-v2" }, 1570e72c2746SKalle Valo { ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL, "hb-poll" }, 1571e72c2746SKalle Valo }; 1572e72c2746SKalle Valo 1573e72c2746SKalle Valo static const char *ath6kl_init_get_fw_capa_name(unsigned int id) 1574e72c2746SKalle Valo { 1575e72c2746SKalle Valo int i; 1576e72c2746SKalle Valo 1577e72c2746SKalle Valo for (i = 0; i < ARRAY_SIZE(fw_capa_map); i++) { 1578e72c2746SKalle Valo if (fw_capa_map[i].id == id) 1579e72c2746SKalle Valo return fw_capa_map[i].name; 1580e72c2746SKalle Valo } 1581e72c2746SKalle Valo 1582e72c2746SKalle Valo return "<unknown>"; 1583e72c2746SKalle Valo } 1584e72c2746SKalle Valo 1585e72c2746SKalle Valo static void ath6kl_init_get_fwcaps(struct ath6kl *ar, char *buf, size_t buf_len) 1586e72c2746SKalle Valo { 1587e72c2746SKalle Valo u8 *data = (u8 *) ar->fw_capabilities; 1588e72c2746SKalle Valo size_t trunc_len, len = 0; 1589e72c2746SKalle Valo int i, index, bit; 1590e72c2746SKalle Valo char *trunc = "..."; 1591e72c2746SKalle Valo 1592e72c2746SKalle Valo for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) { 1593e72c2746SKalle Valo index = i / 8; 1594e72c2746SKalle Valo bit = i % 8; 1595e72c2746SKalle Valo 1596e72c2746SKalle Valo if (index >= sizeof(ar->fw_capabilities) * 4) 1597e72c2746SKalle Valo break; 1598e72c2746SKalle Valo 1599e72c2746SKalle Valo if (buf_len - len < 4) { 1600e72c2746SKalle Valo ath6kl_warn("firmware capability buffer too small!\n"); 1601e72c2746SKalle Valo 1602e72c2746SKalle Valo /* add "..." to the end of string */ 1603e72c2746SKalle Valo trunc_len = strlen(trunc) + 1; 1604e72c2746SKalle Valo strncpy(buf + buf_len - trunc_len, trunc, trunc_len); 1605e72c2746SKalle Valo 1606e72c2746SKalle Valo return; 1607e72c2746SKalle Valo } 1608e72c2746SKalle Valo 1609e72c2746SKalle Valo if (data[index] & (1 << bit)) { 1610e72c2746SKalle Valo len += scnprintf(buf + len, buf_len - len, "%s,", 1611e72c2746SKalle Valo ath6kl_init_get_fw_capa_name(i)); 1612e72c2746SKalle Valo } 1613e72c2746SKalle Valo } 1614e72c2746SKalle Valo 1615e72c2746SKalle Valo /* overwrite the last comma */ 1616e72c2746SKalle Valo if (len > 0) 1617e72c2746SKalle Valo len--; 1618e72c2746SKalle Valo 1619e72c2746SKalle Valo buf[len] = '\0'; 1620e72c2746SKalle Valo } 1621e72c2746SKalle Valo 1622ec1461dcSKalle Valo static int ath6kl_init_hw_reset(struct ath6kl *ar) 1623ec1461dcSKalle Valo { 1624ec1461dcSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "cold resetting the device"); 1625ec1461dcSKalle Valo 1626ec1461dcSKalle Valo return ath6kl_diag_write32(ar, RESET_CONTROL_ADDRESS, 1627ec1461dcSKalle Valo cpu_to_le32(RESET_CONTROL_COLD_RST)); 1628ec1461dcSKalle Valo } 1629ec1461dcSKalle Valo 1630ede615d2SVasanthakumar Thiagarajan static int __ath6kl_init_hw_start(struct ath6kl *ar) 163120459ee2SKalle Valo { 163220459ee2SKalle Valo long timeleft; 163320459ee2SKalle Valo int ret, i; 1634e72c2746SKalle Valo char buf[200]; 163520459ee2SKalle Valo 16365fe4dffbSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n"); 16375fe4dffbSKalle Valo 163820459ee2SKalle Valo ret = ath6kl_hif_power_on(ar); 163920459ee2SKalle Valo if (ret) 164020459ee2SKalle Valo return ret; 164120459ee2SKalle Valo 164220459ee2SKalle Valo ret = ath6kl_configure_target(ar); 164320459ee2SKalle Valo if (ret) 164420459ee2SKalle Valo goto err_power_off; 164520459ee2SKalle Valo 164620459ee2SKalle Valo ret = ath6kl_init_upload(ar); 164720459ee2SKalle Valo if (ret) 164820459ee2SKalle Valo goto err_power_off; 164920459ee2SKalle Valo 165020459ee2SKalle Valo /* Do we need to finish the BMI phase */ 1651bf978145SMohammed Shafi Shajakhan ret = ath6kl_bmi_done(ar); 1652bf978145SMohammed Shafi Shajakhan if (ret) 165320459ee2SKalle Valo goto err_power_off; 165420459ee2SKalle Valo 165520459ee2SKalle Valo /* 165620459ee2SKalle Valo * The reason we have to wait for the target here is that the 165720459ee2SKalle Valo * driver layer has to init BMI in order to set the host block 165820459ee2SKalle Valo * size. 165920459ee2SKalle Valo */ 1660*4e1609c9SKalle Valo ret = ath6kl_htc_wait_target(ar->htc_target); 1661*4e1609c9SKalle Valo if (ret) { 1662*4e1609c9SKalle Valo ath6kl_err("htc wait target failed: %d\n", ret); 166320459ee2SKalle Valo goto err_power_off; 166420459ee2SKalle Valo } 166520459ee2SKalle Valo 1666*4e1609c9SKalle Valo ret = ath6kl_init_service_ep(ar); 1667*4e1609c9SKalle Valo if (ret) { 1668*4e1609c9SKalle Valo ath6kl_err("Endpoint service initilisation failed: %d\n", ret); 166920459ee2SKalle Valo goto err_cleanup_scatter; 167020459ee2SKalle Valo } 167120459ee2SKalle Valo 167220459ee2SKalle Valo /* setup credit distribution */ 1673e76ac2bfSKalle Valo ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info); 167420459ee2SKalle Valo 167520459ee2SKalle Valo /* start HTC */ 167620459ee2SKalle Valo ret = ath6kl_htc_start(ar->htc_target); 167720459ee2SKalle Valo if (ret) { 167820459ee2SKalle Valo /* FIXME: call this */ 167920459ee2SKalle Valo ath6kl_cookie_cleanup(ar); 168020459ee2SKalle Valo goto err_cleanup_scatter; 168120459ee2SKalle Valo } 168220459ee2SKalle Valo 168320459ee2SKalle Valo /* Wait for Wmi event to be ready */ 168420459ee2SKalle Valo timeleft = wait_event_interruptible_timeout(ar->event_wq, 168520459ee2SKalle Valo test_bit(WMI_READY, 168620459ee2SKalle Valo &ar->flag), 168720459ee2SKalle Valo WMI_TIMEOUT); 168820459ee2SKalle Valo 168920459ee2SKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n"); 169020459ee2SKalle Valo 1691293badf4SKalle Valo 1692293badf4SKalle Valo if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) { 169365a8b4ccSKalle Valo ath6kl_info("%s %s fw %s api %d%s\n", 1694293badf4SKalle Valo ar->hw.name, 1695293badf4SKalle Valo ath6kl_init_get_hif_name(ar->hif_type), 1696293badf4SKalle Valo ar->wiphy->fw_version, 169765a8b4ccSKalle Valo ar->fw_api, 1698293badf4SKalle Valo test_bit(TESTMODE, &ar->flag) ? " testmode" : ""); 1699e72c2746SKalle Valo ath6kl_init_get_fwcaps(ar, buf, sizeof(buf)); 1700e72c2746SKalle Valo ath6kl_info("firmware supports: %s\n", buf); 1701293badf4SKalle Valo } 1702293badf4SKalle Valo 170320459ee2SKalle Valo if (ar->version.abi_ver != ATH6KL_ABI_VERSION) { 170420459ee2SKalle Valo ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n", 170520459ee2SKalle Valo ATH6KL_ABI_VERSION, ar->version.abi_ver); 170620459ee2SKalle Valo ret = -EIO; 170720459ee2SKalle Valo goto err_htc_stop; 170820459ee2SKalle Valo } 170920459ee2SKalle Valo 171020459ee2SKalle Valo if (!timeleft || signal_pending(current)) { 171120459ee2SKalle Valo ath6kl_err("wmi is not ready or wait was interrupted\n"); 171220459ee2SKalle Valo ret = -EIO; 171320459ee2SKalle Valo goto err_htc_stop; 171420459ee2SKalle Valo } 171520459ee2SKalle Valo 171620459ee2SKalle Valo ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__); 171720459ee2SKalle Valo 171820459ee2SKalle Valo /* communicate the wmi protocol verision to the target */ 171920459ee2SKalle Valo /* FIXME: return error */ 172020459ee2SKalle Valo if ((ath6kl_set_host_app_area(ar)) != 0) 172120459ee2SKalle Valo ath6kl_err("unable to set the host app area\n"); 172220459ee2SKalle Valo 172371f96ee6SKalle Valo for (i = 0; i < ar->vif_max; i++) { 172420459ee2SKalle Valo ret = ath6kl_target_config_wlan_params(ar, i); 172520459ee2SKalle Valo if (ret) 172620459ee2SKalle Valo goto err_htc_stop; 172720459ee2SKalle Valo } 172820459ee2SKalle Valo 172920459ee2SKalle Valo return 0; 173020459ee2SKalle Valo 173120459ee2SKalle Valo err_htc_stop: 173220459ee2SKalle Valo ath6kl_htc_stop(ar->htc_target); 173320459ee2SKalle Valo err_cleanup_scatter: 173420459ee2SKalle Valo ath6kl_hif_cleanup_scatter(ar); 173520459ee2SKalle Valo err_power_off: 173620459ee2SKalle Valo ath6kl_hif_power_off(ar); 173720459ee2SKalle Valo 173820459ee2SKalle Valo return ret; 173920459ee2SKalle Valo } 174020459ee2SKalle Valo 1741ede615d2SVasanthakumar Thiagarajan int ath6kl_init_hw_start(struct ath6kl *ar) 1742ede615d2SVasanthakumar Thiagarajan { 1743ede615d2SVasanthakumar Thiagarajan int err; 1744ede615d2SVasanthakumar Thiagarajan 1745ede615d2SVasanthakumar Thiagarajan err = __ath6kl_init_hw_start(ar); 1746ede615d2SVasanthakumar Thiagarajan if (err) 1747ede615d2SVasanthakumar Thiagarajan return err; 1748ede615d2SVasanthakumar Thiagarajan ar->state = ATH6KL_STATE_ON; 1749ede615d2SVasanthakumar Thiagarajan return 0; 1750ede615d2SVasanthakumar Thiagarajan } 1751ede615d2SVasanthakumar Thiagarajan 1752ede615d2SVasanthakumar Thiagarajan static int __ath6kl_init_hw_stop(struct ath6kl *ar) 17535fe4dffbSKalle Valo { 17545fe4dffbSKalle Valo int ret; 17555fe4dffbSKalle Valo 17565fe4dffbSKalle Valo ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n"); 17575fe4dffbSKalle Valo 17585fe4dffbSKalle Valo ath6kl_htc_stop(ar->htc_target); 17595fe4dffbSKalle Valo 17605fe4dffbSKalle Valo ath6kl_hif_stop(ar); 17615fe4dffbSKalle Valo 17625fe4dffbSKalle Valo ath6kl_bmi_reset(ar); 17635fe4dffbSKalle Valo 17645fe4dffbSKalle Valo ret = ath6kl_hif_power_off(ar); 17655fe4dffbSKalle Valo if (ret) 17665fe4dffbSKalle Valo ath6kl_warn("failed to power off hif: %d\n", ret); 17675fe4dffbSKalle Valo 1768ede615d2SVasanthakumar Thiagarajan return 0; 1769ede615d2SVasanthakumar Thiagarajan } 177076a9fbe2SKalle Valo 1771ede615d2SVasanthakumar Thiagarajan int ath6kl_init_hw_stop(struct ath6kl *ar) 1772ede615d2SVasanthakumar Thiagarajan { 1773ede615d2SVasanthakumar Thiagarajan int err; 1774ede615d2SVasanthakumar Thiagarajan 1775ede615d2SVasanthakumar Thiagarajan err = __ath6kl_init_hw_stop(ar); 1776ede615d2SVasanthakumar Thiagarajan if (err) 1777ede615d2SVasanthakumar Thiagarajan return err; 1778ede615d2SVasanthakumar Thiagarajan ar->state = ATH6KL_STATE_OFF; 17795fe4dffbSKalle Valo return 0; 17805fe4dffbSKalle Valo } 17815fe4dffbSKalle Valo 178284caf800SVasanthakumar Thiagarajan void ath6kl_init_hw_restart(struct ath6kl *ar) 178384caf800SVasanthakumar Thiagarajan { 178458109df6SVasanthakumar Thiagarajan clear_bit(WMI_READY, &ar->flag); 178558109df6SVasanthakumar Thiagarajan 178684caf800SVasanthakumar Thiagarajan ath6kl_cfg80211_stop_all(ar); 178784caf800SVasanthakumar Thiagarajan 178858109df6SVasanthakumar Thiagarajan if (__ath6kl_init_hw_stop(ar)) { 178958109df6SVasanthakumar Thiagarajan ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to stop during fw error recovery\n"); 179084caf800SVasanthakumar Thiagarajan return; 179158109df6SVasanthakumar Thiagarajan } 179284caf800SVasanthakumar Thiagarajan 179384caf800SVasanthakumar Thiagarajan if (__ath6kl_init_hw_start(ar)) { 179484caf800SVasanthakumar Thiagarajan ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to restart during fw error recovery\n"); 179584caf800SVasanthakumar Thiagarajan return; 179684caf800SVasanthakumar Thiagarajan } 179784caf800SVasanthakumar Thiagarajan } 179884caf800SVasanthakumar Thiagarajan 1799bdcd8170SKalle Valo void ath6kl_stop_txrx(struct ath6kl *ar) 1800bdcd8170SKalle Valo { 1801990bd915SVasanthakumar Thiagarajan struct ath6kl_vif *vif, *tmp_vif; 18021d2a4456SVasanthakumar Thiagarajan int i; 1803bdcd8170SKalle Valo 1804bdcd8170SKalle Valo set_bit(DESTROY_IN_PROGRESS, &ar->flag); 1805bdcd8170SKalle Valo 1806bdcd8170SKalle Valo if (down_interruptible(&ar->sem)) { 1807bdcd8170SKalle Valo ath6kl_err("down_interruptible failed\n"); 1808bdcd8170SKalle Valo return; 1809bdcd8170SKalle Valo } 1810bdcd8170SKalle Valo 18111d2a4456SVasanthakumar Thiagarajan for (i = 0; i < AP_MAX_NUM_STA; i++) 18121d2a4456SVasanthakumar Thiagarajan aggr_reset_state(ar->sta_list[i].aggr_conn); 18131d2a4456SVasanthakumar Thiagarajan 181411f6e40dSVasanthakumar Thiagarajan spin_lock_bh(&ar->list_lock); 1815990bd915SVasanthakumar Thiagarajan list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) { 1816990bd915SVasanthakumar Thiagarajan list_del(&vif->list); 181711f6e40dSVasanthakumar Thiagarajan spin_unlock_bh(&ar->list_lock); 1818355b3a98SMohammed Shafi Shajakhan ath6kl_cfg80211_vif_stop(vif, test_bit(WMI_READY, &ar->flag)); 181927929723SVasanthakumar Thiagarajan rtnl_lock(); 1820c25889e8SKalle Valo ath6kl_cfg80211_vif_cleanup(vif); 182127929723SVasanthakumar Thiagarajan rtnl_unlock(); 182211f6e40dSVasanthakumar Thiagarajan spin_lock_bh(&ar->list_lock); 1823990bd915SVasanthakumar Thiagarajan } 182411f6e40dSVasanthakumar Thiagarajan spin_unlock_bh(&ar->list_lock); 1825bdcd8170SKalle Valo 18266db8fa53SVasanthakumar Thiagarajan clear_bit(WMI_READY, &ar->flag); 18276db8fa53SVasanthakumar Thiagarajan 18286db8fa53SVasanthakumar Thiagarajan /* 18296db8fa53SVasanthakumar Thiagarajan * After wmi_shudown all WMI events will be dropped. We 18306db8fa53SVasanthakumar Thiagarajan * need to cleanup the buffers allocated in AP mode and 18316db8fa53SVasanthakumar Thiagarajan * give disconnect notification to stack, which usually 18326db8fa53SVasanthakumar Thiagarajan * happens in the disconnect_event. Simulate the disconnect 18336db8fa53SVasanthakumar Thiagarajan * event by calling the function directly. Sometimes 18346db8fa53SVasanthakumar Thiagarajan * disconnect_event will be received when the debug logs 18356db8fa53SVasanthakumar Thiagarajan * are collected. 18366db8fa53SVasanthakumar Thiagarajan */ 18376db8fa53SVasanthakumar Thiagarajan ath6kl_wmi_shutdown(ar->wmi); 18386db8fa53SVasanthakumar Thiagarajan 18396db8fa53SVasanthakumar Thiagarajan clear_bit(WMI_ENABLED, &ar->flag); 18406db8fa53SVasanthakumar Thiagarajan if (ar->htc_target) { 18416db8fa53SVasanthakumar Thiagarajan ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__); 18426db8fa53SVasanthakumar Thiagarajan ath6kl_htc_stop(ar->htc_target); 1843bdcd8170SKalle Valo } 1844bdcd8170SKalle Valo 1845bdcd8170SKalle Valo /* 18466db8fa53SVasanthakumar Thiagarajan * Try to reset the device if we can. The driver may have been 18476db8fa53SVasanthakumar Thiagarajan * configure NOT to reset the target during a debug session. 1848bdcd8170SKalle Valo */ 1849ec1461dcSKalle Valo ath6kl_init_hw_reset(ar); 1850bdcd8170SKalle Valo 1851e8ad9a06SVasanthakumar Thiagarajan up(&ar->sem); 1852bdcd8170SKalle Valo } 1853d6a434d6SKalle Valo EXPORT_SYMBOL(ath6kl_stop_txrx); 1854