3 * Copyright (c) 2011 Atheros Communications Inc.
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.
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.
18 #include <linux/moduleparam.h>
19 #include <linux/errno.h>
21 #include <linux/mmc/sdio_func.h>
28 unsigned int debug_mask;
29 static unsigned int testmode;
30 static bool suspend_cutpower;
32 module_param(debug_mask, uint, 0644);
33 module_param(testmode, uint, 0644);
34 module_param(suspend_cutpower, bool, 0444);
36 static const struct ath6kl_hw hw_list[] = {
38 .id = AR6003_HW_2_0_VERSION,
39 .name = "ar6003 hw 2.0",
40 .dataset_patch_addr = 0x57e884,
41 .app_load_addr = 0x543180,
42 .board_ext_data_addr = 0x57e500,
43 .reserved_ram_size = 6912,
45 /* hw2.0 needs override address hardcoded */
46 .app_start_override_addr = 0x944C00,
48 .fw_otp = AR6003_HW_2_0_OTP_FILE,
49 .fw = AR6003_HW_2_0_FIRMWARE_FILE,
50 .fw_tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
51 .fw_patch = AR6003_HW_2_0_PATCH_FILE,
52 .fw_api2 = AR6003_HW_2_0_FIRMWARE_2_FILE,
53 .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE,
54 .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
57 .id = AR6003_HW_2_1_1_VERSION,
58 .name = "ar6003 hw 2.1.1",
59 .dataset_patch_addr = 0x57ff74,
60 .app_load_addr = 0x1234,
61 .board_ext_data_addr = 0x542330,
62 .reserved_ram_size = 512,
64 .fw_otp = AR6003_HW_2_1_1_OTP_FILE,
65 .fw = AR6003_HW_2_1_1_FIRMWARE_FILE,
66 .fw_tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
67 .fw_patch = AR6003_HW_2_1_1_PATCH_FILE,
68 .fw_api2 = AR6003_HW_2_1_1_FIRMWARE_2_FILE,
69 .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
70 .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
73 .id = AR6004_HW_1_0_VERSION,
74 .name = "ar6004 hw 1.0",
75 .dataset_patch_addr = 0x57e884,
76 .app_load_addr = 0x1234,
77 .board_ext_data_addr = 0x437000,
78 .reserved_ram_size = 19456,
79 .board_addr = 0x433900,
81 .fw = AR6004_HW_1_0_FIRMWARE_FILE,
82 .fw_api2 = AR6004_HW_1_0_FIRMWARE_2_FILE,
83 .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
84 .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
87 .id = AR6004_HW_1_1_VERSION,
88 .name = "ar6004 hw 1.1",
89 .dataset_patch_addr = 0x57e884,
90 .app_load_addr = 0x1234,
91 .board_ext_data_addr = 0x437000,
92 .reserved_ram_size = 11264,
93 .board_addr = 0x43d400,
95 .fw = AR6004_HW_1_1_FIRMWARE_FILE,
96 .fw_api2 = AR6004_HW_1_1_FIRMWARE_2_FILE,
97 .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
98 .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
103 * Include definitions here that can be used to tune the WLAN module
104 * behavior. Different customers can tune the behavior as per their needs,
109 * This configuration item enable/disable keepalive support.
110 * Keepalive support: In the absence of any data traffic to AP, null
111 * frames will be sent to the AP at periodic interval, to keep the association
112 * active. This configuration item defines the periodic interval.
113 * Use value of zero to disable keepalive support
114 * Default: 60 seconds
116 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
119 * This configuration item sets the value of disconnect timeout
120 * Firmware delays sending the disconnec event to the host for this
121 * timeout after is gets disconnected from the current AP.
122 * If the firmware successly roams within the disconnect timeout
123 * it sends a new connect event
125 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
127 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
129 #define ATH6KL_DATA_OFFSET 64
130 struct sk_buff *ath6kl_buf_alloc(int size)
135 /* Add chacheline space at front and back of buffer */
136 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
137 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
138 skb = dev_alloc_skb(size + reserved);
141 skb_reserve(skb, reserved - L1_CACHE_BYTES);
145 void ath6kl_init_profile_info(struct ath6kl_vif *vif)
148 memset(vif->ssid, 0, sizeof(vif->ssid));
150 vif->dot11_auth_mode = OPEN_AUTH;
151 vif->auth_mode = NONE_AUTH;
152 vif->prwise_crypto = NONE_CRYPT;
153 vif->prwise_crypto_len = 0;
154 vif->grp_crypto = NONE_CRYPT;
155 vif->grp_crypto_len = 0;
156 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
157 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
158 memset(vif->bssid, 0, sizeof(vif->bssid));
162 static int ath6kl_set_host_app_area(struct ath6kl *ar)
165 struct host_app_area host_app_area;
167 /* Fetch the address of the host_app_area_s
168 * instance in the host interest area */
169 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
170 address = TARG_VTOP(ar->target_type, address);
172 if (ath6kl_diag_read32(ar, address, &data))
175 address = TARG_VTOP(ar->target_type, data);
176 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
177 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
178 sizeof(struct host_app_area)))
184 static inline void set_ac2_ep_map(struct ath6kl *ar,
186 enum htc_endpoint_id ep)
188 ar->ac2ep_map[ac] = ep;
189 ar->ep2ac_map[ep] = ac;
192 /* connect to a service */
193 static int ath6kl_connectservice(struct ath6kl *ar,
194 struct htc_service_connect_req *con_req,
198 struct htc_service_connect_resp response;
200 memset(&response, 0, sizeof(response));
202 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
204 ath6kl_err("failed to connect to %s service status:%d\n",
209 switch (con_req->svc_id) {
210 case WMI_CONTROL_SVC:
211 if (test_bit(WMI_ENABLED, &ar->flag))
212 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
213 ar->ctrl_ep = response.endpoint;
215 case WMI_DATA_BE_SVC:
216 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
218 case WMI_DATA_BK_SVC:
219 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
221 case WMI_DATA_VI_SVC:
222 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
224 case WMI_DATA_VO_SVC:
225 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
228 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
235 static int ath6kl_init_service_ep(struct ath6kl *ar)
237 struct htc_service_connect_req connect;
239 memset(&connect, 0, sizeof(connect));
241 /* these fields are the same for all service endpoints */
242 connect.ep_cb.rx = ath6kl_rx;
243 connect.ep_cb.rx_refill = ath6kl_rx_refill;
244 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
247 * Set the max queue depth so that our ath6kl_tx_queue_full handler
250 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
251 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
252 if (!connect.ep_cb.rx_refill_thresh)
253 connect.ep_cb.rx_refill_thresh++;
255 /* connect to control service */
256 connect.svc_id = WMI_CONTROL_SVC;
257 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
260 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
263 * Limit the HTC message size on the send path, although e can
264 * receive A-MSDU frames of 4K, we will only send ethernet-sized
265 * (802.3) frames on the send path.
267 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
270 * To reduce the amount of committed memory for larger A_MSDU
271 * frames, use the recv-alloc threshold mechanism for larger
274 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
275 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
278 * For the remaining data services set the connection flag to
279 * reduce dribbling, if configured to do so.
281 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
282 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
283 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
285 connect.svc_id = WMI_DATA_BE_SVC;
287 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
290 /* connect to back-ground map this to WMI LOW_PRI */
291 connect.svc_id = WMI_DATA_BK_SVC;
292 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
295 /* connect to Video service, map this to to HI PRI */
296 connect.svc_id = WMI_DATA_VI_SVC;
297 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
301 * Connect to VO service, this is currently not mapped to a WMI
302 * priority stream due to historical reasons. WMI originally
303 * defined 3 priorities over 3 mailboxes We can change this when
304 * WMI is reworked so that priorities are not dependent on
307 connect.svc_id = WMI_DATA_VO_SVC;
308 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
314 void ath6kl_init_control_info(struct ath6kl_vif *vif)
316 ath6kl_init_profile_info(vif);
317 vif->def_txkey_index = 0;
318 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
323 * Set HTC/Mbox operational parameters, this can only be called when the
324 * target is in the BMI phase.
326 static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
332 blk_size = ar->mbox_info.block_size;
335 blk_size |= ((u32)htc_ctrl_buf) << 16;
337 /* set the host interest area for the block size */
338 status = ath6kl_bmi_write(ar,
339 ath6kl_get_hi_item_addr(ar,
340 HI_ITEM(hi_mbox_io_block_sz)),
344 ath6kl_err("bmi_write_memory for IO block size failed\n");
348 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
350 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
352 if (mbox_isr_yield_val) {
353 /* set the host interest area for the mbox ISR yield limit */
354 status = ath6kl_bmi_write(ar,
355 ath6kl_get_hi_item_addr(ar,
356 HI_ITEM(hi_mbox_isr_yield_limit)),
357 (u8 *)&mbox_isr_yield_val,
360 ath6kl_err("bmi_write_memory for yield limit failed\n");
369 static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
375 * Configure the device for rx dot11 header rules. "0,0" are the
376 * default values. Required if checksum offload is needed. Set
377 * RxMetaVersion to 2.
379 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
380 ar->rx_meta_ver, 0, 0)) {
381 ath6kl_err("unable to set the rx frame format\n");
385 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
386 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
387 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
388 ath6kl_err("unable to set power save fail event policy\n");
392 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
393 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
394 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
395 ath6kl_err("unable to set barker preamble policy\n");
399 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
400 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
401 ath6kl_err("unable to set keep alive interval\n");
405 if (ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
406 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
407 ath6kl_err("unable to set disconnect timeout\n");
411 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
412 if (ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED)) {
413 ath6kl_err("unable to set txop bursting\n");
417 if (ar->p2p && (ar->vif_max == 1 || idx)) {
418 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
419 P2P_FLAG_CAPABILITIES_REQ |
420 P2P_FLAG_MACADDR_REQ |
421 P2P_FLAG_HMODEL_REQ);
423 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
424 "capabilities (%d) - assuming P2P not "
430 if (ar->p2p && (ar->vif_max == 1 || idx)) {
431 /* Enable Probe Request reporting for P2P */
432 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
434 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
435 "Request reporting (%d)\n", ret);
442 int ath6kl_configure_target(struct ath6kl *ar)
444 u32 param, ram_reserved_size;
445 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
449 * Note: Even though the firmware interface type is
450 * chosen as BSS_STA for all three interfaces, can
451 * be configured to IBSS/AP as long as the fw submode
452 * remains normal mode (0 - AP, STA and IBSS). But
453 * due to an target assert in firmware only one interface is
454 * configured for now.
456 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
458 for (i = 0; i < ar->vif_max; i++)
459 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
462 * By default, submodes :
463 * vif[0] - AP/STA/IBSS
464 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
465 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
468 for (i = 0; i < ar->max_norm_iface; i++)
469 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
470 (i * HI_OPTION_FW_SUBMODE_BITS);
472 for (i = ar->max_norm_iface; i < ar->vif_max; i++)
473 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
474 (i * HI_OPTION_FW_SUBMODE_BITS);
476 if (ar->p2p && ar->vif_max == 1)
477 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
479 param = HTC_PROTOCOL_VERSION;
480 if (ath6kl_bmi_write(ar,
481 ath6kl_get_hi_item_addr(ar,
482 HI_ITEM(hi_app_host_interest)),
483 (u8 *)¶m, 4) != 0) {
484 ath6kl_err("bmi_write_memory for htc version failed\n");
488 /* set the firmware mode to STA/IBSS/AP */
491 if (ath6kl_bmi_read(ar,
492 ath6kl_get_hi_item_addr(ar,
493 HI_ITEM(hi_option_flag)),
494 (u8 *)¶m, 4) != 0) {
495 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
499 param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
500 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
501 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
503 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
504 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
506 if (ath6kl_bmi_write(ar,
507 ath6kl_get_hi_item_addr(ar,
508 HI_ITEM(hi_option_flag)),
511 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
515 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
518 * Hardcode the address use for the extended board data
519 * Ideally this should be pre-allocate by the OS at boot time
520 * But since it is a new feature and board data is loaded
521 * at init time, we have to workaround this from host.
522 * It is difficult to patch the firmware boot code,
523 * but possible in theory.
526 param = ar->hw.board_ext_data_addr;
527 ram_reserved_size = ar->hw.reserved_ram_size;
529 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
530 HI_ITEM(hi_board_ext_data)),
531 (u8 *)¶m, 4) != 0) {
532 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
536 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
537 HI_ITEM(hi_end_ram_reserve_sz)),
538 (u8 *)&ram_reserved_size, 4) != 0) {
539 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
543 /* set the block size for the target */
544 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
545 /* use default number of control buffers */
551 void ath6kl_core_free(struct ath6kl *ar)
553 wiphy_free(ar->wiphy);
556 void ath6kl_core_cleanup(struct ath6kl *ar)
558 ath6kl_hif_power_off(ar);
560 destroy_workqueue(ar->ath6kl_wq);
563 ath6kl_htc_cleanup(ar->htc_target);
565 ath6kl_cookie_cleanup(ar);
567 ath6kl_cleanup_amsdu_rxbufs(ar);
569 ath6kl_bmi_cleanup(ar);
571 ath6kl_debug_cleanup(ar);
578 ath6kl_deinit_ieee80211_hw(ar);
581 /* firmware upload */
582 static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
583 u8 **fw, size_t *fw_len)
585 const struct firmware *fw_entry;
588 ret = request_firmware(&fw_entry, filename, ar->dev);
592 *fw_len = fw_entry->size;
593 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
598 release_firmware(fw_entry);
604 static const char *get_target_ver_dir(const struct ath6kl *ar)
606 switch (ar->version.target_ver) {
607 case AR6003_HW_1_0_VERSION:
608 return "ath6k/AR6003/hw1.0";
609 case AR6003_HW_2_0_VERSION:
610 return "ath6k/AR6003/hw2.0";
611 case AR6003_HW_2_1_1_VERSION:
612 return "ath6k/AR6003/hw2.1.1";
614 ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__,
615 ar->version.target_ver);
620 * Check the device tree for a board-id and use it to construct
621 * the pathname to the firmware file. Used (for now) to find a
622 * fallback to the "bdata.bin" file--typically a symlink to the
623 * appropriate board-specific file.
625 static bool check_device_tree(struct ath6kl *ar)
627 static const char *board_id_prop = "atheros,board-id";
628 struct device_node *node;
629 char board_filename[64];
630 const char *board_id;
633 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
634 board_id = of_get_property(node, board_id_prop, NULL);
635 if (board_id == NULL) {
636 ath6kl_warn("No \"%s\" property on %s node.\n",
637 board_id_prop, node->name);
640 snprintf(board_filename, sizeof(board_filename),
641 "%s/bdata.%s.bin", get_target_ver_dir(ar), board_id);
643 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
646 ath6kl_err("Failed to get DT board file %s: %d\n",
647 board_filename, ret);
655 static bool check_device_tree(struct ath6kl *ar)
659 #endif /* CONFIG_OF */
661 static int ath6kl_fetch_board_file(struct ath6kl *ar)
663 const char *filename;
666 if (ar->fw_board != NULL)
669 if (WARN_ON(ar->hw.fw_board == NULL))
672 filename = ar->hw.fw_board;
674 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
677 /* managed to get proper board file */
681 if (check_device_tree(ar)) {
682 /* got board file from device tree */
686 /* there was no proper board file, try to use default instead */
687 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
690 filename = ar->hw.fw_default_board;
692 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
695 ath6kl_err("Failed to get default board file %s: %d\n",
700 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
701 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
706 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
708 const char *filename;
711 if (ar->fw_otp != NULL)
714 if (ar->hw.fw_otp == NULL) {
715 ath6kl_dbg(ATH6KL_DBG_BOOT,
716 "no OTP file configured for this hw\n");
720 filename = ar->hw.fw_otp;
722 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
725 ath6kl_err("Failed to get OTP file %s: %d\n",
733 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
735 const char *filename;
742 if (ar->hw.fw_tcmd == NULL) {
743 ath6kl_warn("testmode not supported\n");
747 filename = ar->hw.fw_tcmd;
749 set_bit(TESTMODE, &ar->flag);
754 if (WARN_ON(ar->hw.fw == NULL))
757 filename = ar->hw.fw;
760 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
762 ath6kl_err("Failed to get firmware file %s: %d\n",
770 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
772 const char *filename;
775 if (ar->fw_patch != NULL)
778 if (ar->hw.fw_patch == NULL)
781 filename = ar->hw.fw_patch;
783 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
786 ath6kl_err("Failed to get patch file %s: %d\n",
794 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
798 ret = ath6kl_fetch_otp_file(ar);
802 ret = ath6kl_fetch_fw_file(ar);
806 ret = ath6kl_fetch_patch_file(ar);
813 static int ath6kl_fetch_fw_api2(struct ath6kl *ar)
815 size_t magic_len, len, ie_len;
816 const struct firmware *fw;
817 struct ath6kl_fw_ie *hdr;
818 const char *filename;
820 int ret, ie_id, i, index, bit;
823 if (ar->hw.fw_api2 == NULL)
826 filename = ar->hw.fw_api2;
828 ret = request_firmware(&fw, filename, ar->dev);
835 /* magic also includes the null byte, check that as well */
836 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
838 if (len < magic_len) {
843 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
852 while (len > sizeof(struct ath6kl_fw_ie)) {
853 /* hdr is unaligned! */
854 hdr = (struct ath6kl_fw_ie *) data;
856 ie_id = le32_to_cpup(&hdr->id);
857 ie_len = le32_to_cpup(&hdr->len);
860 data += sizeof(*hdr);
868 case ATH6KL_FW_IE_OTP_IMAGE:
869 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
872 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
874 if (ar->fw_otp == NULL) {
879 ar->fw_otp_len = ie_len;
881 case ATH6KL_FW_IE_FW_IMAGE:
882 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
885 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
887 if (ar->fw == NULL) {
894 case ATH6KL_FW_IE_PATCH_IMAGE:
895 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
898 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
900 if (ar->fw_patch == NULL) {
905 ar->fw_patch_len = ie_len;
907 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
908 val = (__le32 *) data;
909 ar->hw.reserved_ram_size = le32_to_cpup(val);
911 ath6kl_dbg(ATH6KL_DBG_BOOT,
912 "found reserved ram size ie 0x%d\n",
913 ar->hw.reserved_ram_size);
915 case ATH6KL_FW_IE_CAPABILITIES:
916 if (ie_len < DIV_ROUND_UP(ATH6KL_FW_CAPABILITY_MAX, 8))
919 ath6kl_dbg(ATH6KL_DBG_BOOT,
920 "found firmware capabilities ie (%zd B)\n",
923 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
927 if (data[index] & (1 << bit))
928 __set_bit(i, ar->fw_capabilities);
931 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
933 sizeof(ar->fw_capabilities));
935 case ATH6KL_FW_IE_PATCH_ADDR:
936 if (ie_len != sizeof(*val))
939 val = (__le32 *) data;
940 ar->hw.dataset_patch_addr = le32_to_cpup(val);
942 ath6kl_dbg(ATH6KL_DBG_BOOT,
943 "found patch address ie 0x%x\n",
944 ar->hw.dataset_patch_addr);
946 case ATH6KL_FW_IE_BOARD_ADDR:
947 if (ie_len != sizeof(*val))
950 val = (__le32 *) data;
951 ar->hw.board_addr = le32_to_cpup(val);
953 ath6kl_dbg(ATH6KL_DBG_BOOT,
954 "found board address ie 0x%x\n",
957 case ATH6KL_FW_IE_VIF_MAX:
958 if (ie_len != sizeof(*val))
961 val = (__le32 *) data;
962 ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
965 if (ar->vif_max > 1 && !ar->p2p)
966 ar->max_norm_iface = 2;
968 ath6kl_dbg(ATH6KL_DBG_BOOT,
969 "found vif max ie %d\n", ar->vif_max);
972 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
973 le32_to_cpup(&hdr->id));
983 release_firmware(fw);
988 static int ath6kl_fetch_firmwares(struct ath6kl *ar)
992 ret = ath6kl_fetch_board_file(ar);
996 ret = ath6kl_fetch_fw_api2(ar);
998 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 2\n");
1002 ret = ath6kl_fetch_fw_api1(ar);
1006 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 1\n");
1011 static int ath6kl_upload_board_file(struct ath6kl *ar)
1013 u32 board_address, board_ext_address, param;
1014 u32 board_data_size, board_ext_data_size;
1017 if (WARN_ON(ar->fw_board == NULL))
1021 * Determine where in Target RAM to write Board Data.
1022 * For AR6004, host determine Target RAM address for
1023 * writing board data.
1025 if (ar->hw.board_addr != 0) {
1026 board_address = ar->hw.board_addr;
1027 ath6kl_bmi_write(ar,
1028 ath6kl_get_hi_item_addr(ar,
1029 HI_ITEM(hi_board_data)),
1030 (u8 *) &board_address, 4);
1033 ath6kl_get_hi_item_addr(ar,
1034 HI_ITEM(hi_board_data)),
1035 (u8 *) &board_address, 4);
1038 /* determine where in target ram to write extended board data */
1040 ath6kl_get_hi_item_addr(ar,
1041 HI_ITEM(hi_board_ext_data)),
1042 (u8 *) &board_ext_address, 4);
1044 if (ar->target_type == TARGET_TYPE_AR6003 &&
1045 board_ext_address == 0) {
1046 ath6kl_err("Failed to get board file target address.\n");
1050 switch (ar->target_type) {
1051 case TARGET_TYPE_AR6003:
1052 board_data_size = AR6003_BOARD_DATA_SZ;
1053 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1055 case TARGET_TYPE_AR6004:
1056 board_data_size = AR6004_BOARD_DATA_SZ;
1057 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1065 if (board_ext_address &&
1066 ar->fw_board_len == (board_data_size + board_ext_data_size)) {
1068 /* write extended board data */
1069 ath6kl_dbg(ATH6KL_DBG_BOOT,
1070 "writing extended board data to 0x%x (%d B)\n",
1071 board_ext_address, board_ext_data_size);
1073 ret = ath6kl_bmi_write(ar, board_ext_address,
1074 ar->fw_board + board_data_size,
1075 board_ext_data_size);
1077 ath6kl_err("Failed to write extended board data: %d\n",
1082 /* record that extended board data is initialized */
1083 param = (board_ext_data_size << 16) | 1;
1085 ath6kl_bmi_write(ar,
1086 ath6kl_get_hi_item_addr(ar,
1087 HI_ITEM(hi_board_ext_data_config)),
1088 (unsigned char *) ¶m, 4);
1091 if (ar->fw_board_len < board_data_size) {
1092 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1097 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1098 board_address, board_data_size);
1100 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
1104 ath6kl_err("Board file bmi write failed: %d\n", ret);
1108 /* record the fact that Board Data IS initialized */
1110 ath6kl_bmi_write(ar,
1111 ath6kl_get_hi_item_addr(ar,
1112 HI_ITEM(hi_board_data_initialized)),
1118 static int ath6kl_upload_otp(struct ath6kl *ar)
1121 bool from_hw = false;
1124 if (ar->fw_otp == NULL)
1127 address = ar->hw.app_load_addr;
1129 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
1132 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1135 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1139 /* read firmware start address */
1140 ret = ath6kl_bmi_read(ar,
1141 ath6kl_get_hi_item_addr(ar,
1142 HI_ITEM(hi_app_start)),
1143 (u8 *) &address, sizeof(address));
1146 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1150 if (ar->hw.app_start_override_addr == 0) {
1151 ar->hw.app_start_override_addr = address;
1155 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1156 from_hw ? " (from hw)" : "",
1157 ar->hw.app_start_override_addr);
1159 /* execute the OTP code */
1160 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1161 ar->hw.app_start_override_addr);
1163 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m);
1168 static int ath6kl_upload_firmware(struct ath6kl *ar)
1173 if (WARN_ON(ar->fw == NULL))
1176 address = ar->hw.app_load_addr;
1178 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
1179 address, ar->fw_len);
1181 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1184 ath6kl_err("Failed to write firmware: %d\n", ret);
1189 * Set starting address for firmware
1190 * Don't need to setup app_start override addr on AR6004
1192 if (ar->target_type != TARGET_TYPE_AR6004) {
1193 address = ar->hw.app_start_override_addr;
1194 ath6kl_bmi_set_app_start(ar, address);
1199 static int ath6kl_upload_patch(struct ath6kl *ar)
1204 if (ar->fw_patch == NULL)
1207 address = ar->hw.dataset_patch_addr;
1209 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
1210 address, ar->fw_patch_len);
1212 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1214 ath6kl_err("Failed to write patch file: %d\n", ret);
1219 ath6kl_bmi_write(ar,
1220 ath6kl_get_hi_item_addr(ar,
1221 HI_ITEM(hi_dset_list_head)),
1222 (unsigned char *) ¶m, 4);
1227 static int ath6kl_init_upload(struct ath6kl *ar)
1229 u32 param, options, sleep, address;
1232 if (ar->target_type != TARGET_TYPE_AR6003 &&
1233 ar->target_type != TARGET_TYPE_AR6004)
1236 /* temporarily disable system sleep */
1237 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1238 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1244 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1245 status = ath6kl_bmi_reg_write(ar, address, param);
1249 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1250 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1256 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1257 status = ath6kl_bmi_reg_write(ar, address, param);
1261 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1264 /* program analog PLL register */
1265 /* no need to control 40/44MHz clock on AR6004 */
1266 if (ar->target_type != TARGET_TYPE_AR6004) {
1267 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1273 /* Run at 80/88MHz by default */
1274 param = SM(CPU_CLOCK_STANDARD, 1);
1276 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1277 status = ath6kl_bmi_reg_write(ar, address, param);
1283 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1284 param = SM(LPO_CAL_ENABLE, 1);
1285 status = ath6kl_bmi_reg_write(ar, address, param);
1289 /* WAR to avoid SDIO CRC err */
1290 if (ar->version.target_ver == AR6003_HW_2_0_VERSION) {
1291 ath6kl_err("temporary war to avoid sdio crc error\n");
1295 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1296 status = ath6kl_bmi_reg_write(ar, address, param);
1300 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1301 status = ath6kl_bmi_reg_write(ar, address, param);
1305 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1306 status = ath6kl_bmi_reg_write(ar, address, param);
1310 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1311 status = ath6kl_bmi_reg_write(ar, address, param);
1316 /* write EEPROM data to Target RAM */
1317 status = ath6kl_upload_board_file(ar);
1321 /* transfer One time Programmable data */
1322 status = ath6kl_upload_otp(ar);
1326 /* Download Target firmware */
1327 status = ath6kl_upload_firmware(ar);
1331 status = ath6kl_upload_patch(ar);
1335 /* Restore system sleep */
1336 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1337 status = ath6kl_bmi_reg_write(ar, address, sleep);
1341 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1342 param = options | 0x20;
1343 status = ath6kl_bmi_reg_write(ar, address, param);
1347 /* Configure GPIO AR6003 UART */
1348 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1349 status = ath6kl_bmi_write(ar,
1350 ath6kl_get_hi_item_addr(ar,
1351 HI_ITEM(hi_dbg_uart_txpin)),
1357 static int ath6kl_init_hw_params(struct ath6kl *ar)
1359 const struct ath6kl_hw *hw;
1362 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
1365 if (hw->id == ar->version.target_ver)
1369 if (i == ARRAY_SIZE(hw_list)) {
1370 ath6kl_err("Unsupported hardware version: 0x%x\n",
1371 ar->version.target_ver);
1377 ath6kl_dbg(ATH6KL_DBG_BOOT,
1378 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1379 ar->version.target_ver, ar->target_type,
1380 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1381 ath6kl_dbg(ATH6KL_DBG_BOOT,
1382 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1383 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1384 ar->hw.reserved_ram_size);
1389 static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
1392 case ATH6KL_HIF_TYPE_SDIO:
1394 case ATH6KL_HIF_TYPE_USB:
1401 int ath6kl_init_hw_start(struct ath6kl *ar)
1406 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
1408 ret = ath6kl_hif_power_on(ar);
1412 ret = ath6kl_configure_target(ar);
1416 ret = ath6kl_init_upload(ar);
1420 /* Do we need to finish the BMI phase */
1421 /* FIXME: return error from ath6kl_bmi_done() */
1422 if (ath6kl_bmi_done(ar)) {
1428 * The reason we have to wait for the target here is that the
1429 * driver layer has to init BMI in order to set the host block
1432 if (ath6kl_htc_wait_target(ar->htc_target)) {
1437 if (ath6kl_init_service_ep(ar)) {
1439 goto err_cleanup_scatter;
1442 /* setup credit distribution */
1443 ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
1446 ret = ath6kl_htc_start(ar->htc_target);
1448 /* FIXME: call this */
1449 ath6kl_cookie_cleanup(ar);
1450 goto err_cleanup_scatter;
1453 /* Wait for Wmi event to be ready */
1454 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1459 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1462 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
1463 ath6kl_info("%s %s fw %s%s\n",
1465 ath6kl_init_get_hif_name(ar->hif_type),
1466 ar->wiphy->fw_version,
1467 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
1470 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1471 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1472 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1477 if (!timeleft || signal_pending(current)) {
1478 ath6kl_err("wmi is not ready or wait was interrupted\n");
1483 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1485 /* communicate the wmi protocol verision to the target */
1486 /* FIXME: return error */
1487 if ((ath6kl_set_host_app_area(ar)) != 0)
1488 ath6kl_err("unable to set the host app area\n");
1490 for (i = 0; i < ar->vif_max; i++) {
1491 ret = ath6kl_target_config_wlan_params(ar, i);
1496 ar->state = ATH6KL_STATE_ON;
1501 ath6kl_htc_stop(ar->htc_target);
1502 err_cleanup_scatter:
1503 ath6kl_hif_cleanup_scatter(ar);
1505 ath6kl_hif_power_off(ar);
1510 int ath6kl_init_hw_stop(struct ath6kl *ar)
1514 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
1516 ath6kl_htc_stop(ar->htc_target);
1518 ath6kl_hif_stop(ar);
1520 ath6kl_bmi_reset(ar);
1522 ret = ath6kl_hif_power_off(ar);
1524 ath6kl_warn("failed to power off hif: %d\n", ret);
1526 ar->state = ATH6KL_STATE_OFF;
1531 int ath6kl_core_init(struct ath6kl *ar)
1533 struct ath6kl_bmi_target_info targ_info;
1534 struct net_device *ndev;
1537 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1541 ret = ath6kl_bmi_init(ar);
1546 * Turn on power to get hardware (target) version and leave power
1547 * on delibrately as we will boot the hardware anyway within few
1550 ret = ath6kl_hif_power_on(ar);
1552 goto err_bmi_cleanup;
1554 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1558 ar->version.target_ver = le32_to_cpu(targ_info.version);
1559 ar->target_type = le32_to_cpu(targ_info.type);
1560 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
1562 ret = ath6kl_init_hw_params(ar);
1566 ar->htc_target = ath6kl_htc_create(ar);
1568 if (!ar->htc_target) {
1573 ret = ath6kl_fetch_firmwares(ar);
1575 goto err_htc_cleanup;
1577 /* FIXME: we should free all firmwares in the error cases below */
1579 /* Indicate that WMI is enabled (although not ready yet) */
1580 set_bit(WMI_ENABLED, &ar->flag);
1581 ar->wmi = ath6kl_wmi_init(ar);
1583 ath6kl_err("failed to initialize wmi\n");
1585 goto err_htc_cleanup;
1588 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1590 ret = ath6kl_register_ieee80211_hw(ar);
1592 goto err_node_cleanup;
1594 ret = ath6kl_debug_init(ar);
1596 wiphy_unregister(ar->wiphy);
1597 goto err_node_cleanup;
1600 for (i = 0; i < ar->vif_max; i++)
1601 ar->avail_idx_map |= BIT(i);
1605 /* Add an initial station interface */
1606 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
1612 ath6kl_err("Failed to instantiate a network device\n");
1614 wiphy_unregister(ar->wiphy);
1615 goto err_debug_init;
1619 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1620 __func__, ndev->name, ndev, ar);
1622 /* setup access class priority mappings */
1623 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1624 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1625 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1626 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1628 /* give our connected endpoints some buffers */
1629 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1630 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1632 /* allocate some buffers that handle larger AMSDU frames */
1633 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1635 ath6kl_cookie_init(ar);
1637 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1638 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1640 if (suspend_cutpower)
1641 ar->conf_flags |= ATH6KL_CONF_SUSPEND_CUTPOWER;
1643 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
1644 WIPHY_FLAG_HAVE_AP_SME |
1645 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1647 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
1648 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
1650 ar->wiphy->probe_resp_offload =
1651 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1652 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1653 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
1654 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
1656 set_bit(FIRST_BOOT, &ar->flag);
1658 ret = ath6kl_init_hw_start(ar);
1660 ath6kl_err("Failed to start hardware: %d\n", ret);
1661 goto err_rxbuf_cleanup;
1665 * Set mac address which is received in ready event
1666 * FIXME: Move to ath6kl_interface_add()
1668 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
1673 ath6kl_htc_flush_rx_buf(ar->htc_target);
1674 ath6kl_cleanup_amsdu_rxbufs(ar);
1676 ath6kl_deinit_if_data(netdev_priv(ndev));
1678 wiphy_unregister(ar->wiphy);
1680 ath6kl_debug_cleanup(ar);
1682 ath6kl_wmi_shutdown(ar->wmi);
1683 clear_bit(WMI_ENABLED, &ar->flag);
1686 ath6kl_htc_cleanup(ar->htc_target);
1688 ath6kl_hif_power_off(ar);
1690 ath6kl_bmi_cleanup(ar);
1692 destroy_workqueue(ar->ath6kl_wq);
1697 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
1699 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1702 netif_stop_queue(vif->ndev);
1704 clear_bit(WLAN_ENABLED, &vif->flags);
1707 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1708 test_bit(CONNECT_PEND, &vif->flags);
1709 ath6kl_disconnect(vif);
1710 del_timer(&vif->disconnect_timer);
1713 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1714 (vif->nw_type & AP_NETWORK) ?
1715 bcast_mac : vif->bssid,
1719 if (vif->scan_req) {
1720 cfg80211_scan_done(vif->scan_req, true);
1721 vif->scan_req = NULL;
1725 void ath6kl_stop_txrx(struct ath6kl *ar)
1727 struct ath6kl_vif *vif, *tmp_vif;
1729 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1731 if (down_interruptible(&ar->sem)) {
1732 ath6kl_err("down_interruptible failed\n");
1736 spin_lock_bh(&ar->list_lock);
1737 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1738 list_del(&vif->list);
1739 spin_unlock_bh(&ar->list_lock);
1740 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1742 ath6kl_deinit_if_data(vif);
1744 spin_lock_bh(&ar->list_lock);
1746 spin_unlock_bh(&ar->list_lock);
1748 clear_bit(WMI_READY, &ar->flag);
1751 * After wmi_shudown all WMI events will be dropped. We
1752 * need to cleanup the buffers allocated in AP mode and
1753 * give disconnect notification to stack, which usually
1754 * happens in the disconnect_event. Simulate the disconnect
1755 * event by calling the function directly. Sometimes
1756 * disconnect_event will be received when the debug logs
1759 ath6kl_wmi_shutdown(ar->wmi);
1761 clear_bit(WMI_ENABLED, &ar->flag);
1762 if (ar->htc_target) {
1763 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1764 ath6kl_htc_stop(ar->htc_target);
1768 * Try to reset the device if we can. The driver may have been
1769 * configure NOT to reset the target during a debug session.
1771 ath6kl_dbg(ATH6KL_DBG_TRC,
1772 "attempting to reset target on instance destroy\n");
1773 ath6kl_reset_device(ar, ar->target_type, true, true);
1775 clear_bit(WLAN_ENABLED, &ar->flag);