3 * Copyright (c) 2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/moduleparam.h>
22 #include <linux/errno.h>
23 #include <linux/export.h>
25 #include <linux/mmc/sdio_func.h>
26 #include <linux/vmalloc.h>
35 static const struct ath6kl_hw hw_list[] = {
37 .id = AR6003_HW_2_0_VERSION,
38 .name = "ar6003 hw 2.0",
39 .dataset_patch_addr = 0x57e884,
40 .app_load_addr = 0x543180,
41 .board_ext_data_addr = 0x57e500,
42 .reserved_ram_size = 6912,
43 .refclk_hz = 26000000,
47 /* hw2.0 needs override address hardcoded */
48 .app_start_override_addr = 0x944C00,
51 .dir = AR6003_HW_2_0_FW_DIR,
52 .otp = AR6003_HW_2_0_OTP_FILE,
53 .fw = AR6003_HW_2_0_FIRMWARE_FILE,
54 .tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
55 .patch = AR6003_HW_2_0_PATCH_FILE,
58 .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE,
59 .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
62 .id = AR6003_HW_2_1_1_VERSION,
63 .name = "ar6003 hw 2.1.1",
64 .dataset_patch_addr = 0x57ff74,
65 .app_load_addr = 0x1234,
66 .board_ext_data_addr = 0x542330,
67 .reserved_ram_size = 512,
68 .refclk_hz = 26000000,
70 .testscript_addr = 0x57ef74,
74 .dir = AR6003_HW_2_1_1_FW_DIR,
75 .otp = AR6003_HW_2_1_1_OTP_FILE,
76 .fw = AR6003_HW_2_1_1_FIRMWARE_FILE,
77 .tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
78 .patch = AR6003_HW_2_1_1_PATCH_FILE,
79 .utf = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE,
80 .testscript = AR6003_HW_2_1_1_TESTSCRIPT_FILE,
83 .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
84 .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
87 .id = AR6004_HW_1_0_VERSION,
88 .name = "ar6004 hw 1.0",
89 .dataset_patch_addr = 0x57e884,
90 .app_load_addr = 0x1234,
91 .board_ext_data_addr = 0x437000,
92 .reserved_ram_size = 19456,
93 .board_addr = 0x433900,
94 .refclk_hz = 26000000,
96 .flags = ATH6KL_HW_64BIT_RATES |
97 ATH6KL_HW_AP_INACTIVITY_MINS,
100 .dir = AR6004_HW_1_0_FW_DIR,
101 .fw = AR6004_HW_1_0_FIRMWARE_FILE,
104 .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
105 .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
108 .id = AR6004_HW_1_1_VERSION,
109 .name = "ar6004 hw 1.1",
110 .dataset_patch_addr = 0x57e884,
111 .app_load_addr = 0x1234,
112 .board_ext_data_addr = 0x437000,
113 .reserved_ram_size = 11264,
114 .board_addr = 0x43d400,
115 .refclk_hz = 40000000,
117 .flags = ATH6KL_HW_64BIT_RATES |
118 ATH6KL_HW_AP_INACTIVITY_MINS,
120 .dir = AR6004_HW_1_1_FW_DIR,
121 .fw = AR6004_HW_1_1_FIRMWARE_FILE,
124 .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
125 .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
128 .id = AR6004_HW_1_2_VERSION,
129 .name = "ar6004 hw 1.2",
130 .dataset_patch_addr = 0x436ecc,
131 .app_load_addr = 0x1234,
132 .board_ext_data_addr = 0x437000,
133 .reserved_ram_size = 9216,
134 .board_addr = 0x435c00,
135 .refclk_hz = 40000000,
137 .flags = ATH6KL_HW_64BIT_RATES |
138 ATH6KL_HW_AP_INACTIVITY_MINS,
141 .dir = AR6004_HW_1_2_FW_DIR,
142 .fw = AR6004_HW_1_2_FIRMWARE_FILE,
144 .fw_board = AR6004_HW_1_2_BOARD_DATA_FILE,
145 .fw_default_board = AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE,
148 .id = AR6004_HW_1_3_VERSION,
149 .name = "ar6004 hw 1.3",
150 .dataset_patch_addr = 0x437860,
151 .app_load_addr = 0x1234,
152 .board_ext_data_addr = 0x437000,
153 .reserved_ram_size = 7168,
154 .board_addr = 0x436400,
155 .refclk_hz = 40000000,
157 .flags = ATH6KL_HW_64BIT_RATES |
158 ATH6KL_HW_AP_INACTIVITY_MINS,
161 .dir = AR6004_HW_1_3_FW_DIR,
162 .fw = AR6004_HW_1_3_FIRMWARE_FILE,
165 .fw_board = AR6004_HW_1_3_BOARD_DATA_FILE,
166 .fw_default_board = AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE,
171 * Include definitions here that can be used to tune the WLAN module
172 * behavior. Different customers can tune the behavior as per their needs,
177 * This configuration item enable/disable keepalive support.
178 * Keepalive support: In the absence of any data traffic to AP, null
179 * frames will be sent to the AP at periodic interval, to keep the association
180 * active. This configuration item defines the periodic interval.
181 * Use value of zero to disable keepalive support
182 * Default: 60 seconds
184 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
187 * This configuration item sets the value of disconnect timeout
188 * Firmware delays sending the disconnec event to the host for this
189 * timeout after is gets disconnected from the current AP.
190 * If the firmware successly roams within the disconnect timeout
191 * it sends a new connect event
193 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
196 #define ATH6KL_DATA_OFFSET 64
197 struct sk_buff *ath6kl_buf_alloc(int size)
202 /* Add chacheline space at front and back of buffer */
203 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
204 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
205 skb = dev_alloc_skb(size + reserved);
208 skb_reserve(skb, reserved - L1_CACHE_BYTES);
212 void ath6kl_init_profile_info(struct ath6kl_vif *vif)
215 memset(vif->ssid, 0, sizeof(vif->ssid));
217 vif->dot11_auth_mode = OPEN_AUTH;
218 vif->auth_mode = NONE_AUTH;
219 vif->prwise_crypto = NONE_CRYPT;
220 vif->prwise_crypto_len = 0;
221 vif->grp_crypto = NONE_CRYPT;
222 vif->grp_crypto_len = 0;
223 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
224 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
225 memset(vif->bssid, 0, sizeof(vif->bssid));
229 static int ath6kl_set_host_app_area(struct ath6kl *ar)
232 struct host_app_area host_app_area;
234 /* Fetch the address of the host_app_area_s
235 * instance in the host interest area */
236 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
237 address = TARG_VTOP(ar->target_type, address);
239 if (ath6kl_diag_read32(ar, address, &data))
242 address = TARG_VTOP(ar->target_type, data);
243 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
244 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
245 sizeof(struct host_app_area)))
251 static inline void set_ac2_ep_map(struct ath6kl *ar,
253 enum htc_endpoint_id ep)
255 ar->ac2ep_map[ac] = ep;
256 ar->ep2ac_map[ep] = ac;
259 /* connect to a service */
260 static int ath6kl_connectservice(struct ath6kl *ar,
261 struct htc_service_connect_req *con_req,
265 struct htc_service_connect_resp response;
267 memset(&response, 0, sizeof(response));
269 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
271 ath6kl_err("failed to connect to %s service status:%d\n",
276 switch (con_req->svc_id) {
277 case WMI_CONTROL_SVC:
278 if (test_bit(WMI_ENABLED, &ar->flag))
279 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
280 ar->ctrl_ep = response.endpoint;
282 case WMI_DATA_BE_SVC:
283 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
285 case WMI_DATA_BK_SVC:
286 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
288 case WMI_DATA_VI_SVC:
289 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
291 case WMI_DATA_VO_SVC:
292 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
295 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
302 static int ath6kl_init_service_ep(struct ath6kl *ar)
304 struct htc_service_connect_req connect;
306 memset(&connect, 0, sizeof(connect));
308 /* these fields are the same for all service endpoints */
309 connect.ep_cb.tx_comp_multi = ath6kl_tx_complete;
310 connect.ep_cb.rx = ath6kl_rx;
311 connect.ep_cb.rx_refill = ath6kl_rx_refill;
312 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
315 * Set the max queue depth so that our ath6kl_tx_queue_full handler
318 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
319 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
320 if (!connect.ep_cb.rx_refill_thresh)
321 connect.ep_cb.rx_refill_thresh++;
323 /* connect to control service */
324 connect.svc_id = WMI_CONTROL_SVC;
325 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
328 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
331 * Limit the HTC message size on the send path, although e can
332 * receive A-MSDU frames of 4K, we will only send ethernet-sized
333 * (802.3) frames on the send path.
335 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
338 * To reduce the amount of committed memory for larger A_MSDU
339 * frames, use the recv-alloc threshold mechanism for larger
342 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
343 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
346 * For the remaining data services set the connection flag to
347 * reduce dribbling, if configured to do so.
349 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
350 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
351 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
353 connect.svc_id = WMI_DATA_BE_SVC;
355 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
358 /* connect to back-ground map this to WMI LOW_PRI */
359 connect.svc_id = WMI_DATA_BK_SVC;
360 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
363 /* connect to Video service, map this to to HI PRI */
364 connect.svc_id = WMI_DATA_VI_SVC;
365 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
369 * Connect to VO service, this is currently not mapped to a WMI
370 * priority stream due to historical reasons. WMI originally
371 * defined 3 priorities over 3 mailboxes We can change this when
372 * WMI is reworked so that priorities are not dependent on
375 connect.svc_id = WMI_DATA_VO_SVC;
376 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
382 void ath6kl_init_control_info(struct ath6kl_vif *vif)
384 ath6kl_init_profile_info(vif);
385 vif->def_txkey_index = 0;
386 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
391 * Set HTC/Mbox operational parameters, this can only be called when the
392 * target is in the BMI phase.
394 static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
400 blk_size = ar->mbox_info.block_size;
403 blk_size |= ((u32)htc_ctrl_buf) << 16;
405 /* set the host interest area for the block size */
406 status = ath6kl_bmi_write_hi32(ar, hi_mbox_io_block_sz, blk_size);
408 ath6kl_err("bmi_write_memory for IO block size failed\n");
412 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
414 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
416 if (mbox_isr_yield_val) {
417 /* set the host interest area for the mbox ISR yield limit */
418 status = ath6kl_bmi_write_hi32(ar, hi_mbox_isr_yield_limit,
421 ath6kl_err("bmi_write_memory for yield limit failed\n");
430 static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
435 * Configure the device for rx dot11 header rules. "0,0" are the
436 * default values. Required if checksum offload is needed. Set
437 * RxMetaVersion to 2.
439 ret = ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
440 ar->rx_meta_ver, 0, 0);
442 ath6kl_err("unable to set the rx frame format: %d\n", ret);
446 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN) {
447 ret = ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
448 IGNORE_PS_FAIL_DURING_SCAN);
450 ath6kl_err("unable to set power save fail event policy: %d\n",
456 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER)) {
457 ret = ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
458 WMI_FOLLOW_BARKER_IN_ERP);
460 ath6kl_err("unable to set barker preamble policy: %d\n",
466 ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
467 WLAN_CONFIG_KEEP_ALIVE_INTERVAL);
469 ath6kl_err("unable to set keep alive interval: %d\n", ret);
473 ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
474 WLAN_CONFIG_DISCONNECT_TIMEOUT);
476 ath6kl_err("unable to set disconnect timeout: %d\n", ret);
480 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST)) {
481 ret = ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED);
483 ath6kl_err("unable to set txop bursting: %d\n", ret);
488 if (ar->p2p && (ar->vif_max == 1 || idx)) {
489 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
490 P2P_FLAG_CAPABILITIES_REQ |
491 P2P_FLAG_MACADDR_REQ |
492 P2P_FLAG_HMODEL_REQ);
494 ath6kl_dbg(ATH6KL_DBG_TRC,
495 "failed to request P2P capabilities (%d) - assuming P2P not supported\n",
501 if (ar->p2p && (ar->vif_max == 1 || idx)) {
502 /* Enable Probe Request reporting for P2P */
503 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
505 ath6kl_dbg(ATH6KL_DBG_TRC,
506 "failed to enable Probe Request reporting (%d)\n",
514 int ath6kl_configure_target(struct ath6kl *ar)
516 u32 param, ram_reserved_size;
517 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
520 param = !!(ar->conf_flags & ATH6KL_CONF_UART_DEBUG);
521 if (ath6kl_bmi_write_hi32(ar, hi_serial_enable, param)) {
522 ath6kl_err("bmi_write_memory for uart debug failed\n");
527 * Note: Even though the firmware interface type is
528 * chosen as BSS_STA for all three interfaces, can
529 * be configured to IBSS/AP as long as the fw submode
530 * remains normal mode (0 - AP, STA and IBSS). But
531 * due to an target assert in firmware only one interface is
532 * configured for now.
534 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
536 for (i = 0; i < ar->vif_max; i++)
537 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
540 * Submodes when fw does not support dynamic interface
542 * vif[0] - AP/STA/IBSS
543 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
544 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
545 * Otherwise, All the interface are initialized to p2p dev.
548 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
549 ar->fw_capabilities)) {
550 for (i = 0; i < ar->vif_max; i++)
551 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
552 (i * HI_OPTION_FW_SUBMODE_BITS);
554 for (i = 0; i < ar->max_norm_iface; i++)
555 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
556 (i * HI_OPTION_FW_SUBMODE_BITS);
558 for (i = ar->max_norm_iface; i < ar->vif_max; i++)
559 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
560 (i * HI_OPTION_FW_SUBMODE_BITS);
562 if (ar->p2p && ar->vif_max == 1)
563 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
566 if (ath6kl_bmi_write_hi32(ar, hi_app_host_interest,
567 HTC_PROTOCOL_VERSION) != 0) {
568 ath6kl_err("bmi_write_memory for htc version failed\n");
572 /* set the firmware mode to STA/IBSS/AP */
575 if (ath6kl_bmi_read_hi32(ar, hi_option_flag, ¶m) != 0) {
576 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
580 param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
581 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
582 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
584 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
585 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
587 if (ath6kl_bmi_write_hi32(ar, hi_option_flag, param) != 0) {
588 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
592 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
595 * Hardcode the address use for the extended board data
596 * Ideally this should be pre-allocate by the OS at boot time
597 * But since it is a new feature and board data is loaded
598 * at init time, we have to workaround this from host.
599 * It is difficult to patch the firmware boot code,
600 * but possible in theory.
603 if (ar->target_type == TARGET_TYPE_AR6003) {
604 param = ar->hw.board_ext_data_addr;
605 ram_reserved_size = ar->hw.reserved_ram_size;
607 if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) {
608 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
612 if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz,
613 ram_reserved_size) != 0) {
614 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
619 /* set the block size for the target */
620 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
621 /* use default number of control buffers */
624 /* Configure GPIO AR600x UART */
625 status = ath6kl_bmi_write_hi32(ar, hi_dbg_uart_txpin,
630 /* Configure target refclk_hz */
631 status = ath6kl_bmi_write_hi32(ar, hi_refclk_hz, ar->hw.refclk_hz);
638 /* firmware upload */
639 static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
640 u8 **fw, size_t *fw_len)
642 const struct firmware *fw_entry;
645 ret = request_firmware(&fw_entry, filename, ar->dev);
649 *fw_len = fw_entry->size;
650 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
655 release_firmware(fw_entry);
662 * Check the device tree for a board-id and use it to construct
663 * the pathname to the firmware file. Used (for now) to find a
664 * fallback to the "bdata.bin" file--typically a symlink to the
665 * appropriate board-specific file.
667 static bool check_device_tree(struct ath6kl *ar)
669 static const char *board_id_prop = "atheros,board-id";
670 struct device_node *node;
671 char board_filename[64];
672 const char *board_id;
675 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
676 board_id = of_get_property(node, board_id_prop, NULL);
677 if (board_id == NULL) {
678 ath6kl_warn("No \"%s\" property on %s node.\n",
679 board_id_prop, node->name);
682 snprintf(board_filename, sizeof(board_filename),
683 "%s/bdata.%s.bin", ar->hw.fw.dir, board_id);
685 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
688 ath6kl_err("Failed to get DT board file %s: %d\n",
689 board_filename, ret);
697 static bool check_device_tree(struct ath6kl *ar)
701 #endif /* CONFIG_OF */
703 static int ath6kl_fetch_board_file(struct ath6kl *ar)
705 const char *filename;
708 if (ar->fw_board != NULL)
711 if (WARN_ON(ar->hw.fw_board == NULL))
714 filename = ar->hw.fw_board;
716 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
719 /* managed to get proper board file */
723 if (check_device_tree(ar)) {
724 /* got board file from device tree */
728 /* there was no proper board file, try to use default instead */
729 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
732 filename = ar->hw.fw_default_board;
734 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
737 ath6kl_err("Failed to get default board file %s: %d\n",
742 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
743 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
748 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
753 if (ar->fw_otp != NULL)
756 if (ar->hw.fw.otp == NULL) {
757 ath6kl_dbg(ATH6KL_DBG_BOOT,
758 "no OTP file configured for this hw\n");
762 snprintf(filename, sizeof(filename), "%s/%s",
763 ar->hw.fw.dir, ar->hw.fw.otp);
765 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
768 ath6kl_err("Failed to get OTP file %s: %d\n",
776 static int ath6kl_fetch_testmode_file(struct ath6kl *ar)
781 if (ar->testmode == 0)
784 ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n", ar->testmode);
786 if (ar->testmode == 2) {
787 if (ar->hw.fw.utf == NULL) {
788 ath6kl_warn("testmode 2 not supported\n");
792 snprintf(filename, sizeof(filename), "%s/%s",
793 ar->hw.fw.dir, ar->hw.fw.utf);
795 if (ar->hw.fw.tcmd == NULL) {
796 ath6kl_warn("testmode 1 not supported\n");
800 snprintf(filename, sizeof(filename), "%s/%s",
801 ar->hw.fw.dir, ar->hw.fw.tcmd);
804 set_bit(TESTMODE, &ar->flag);
806 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
808 ath6kl_err("Failed to get testmode %d firmware file %s: %d\n",
809 ar->testmode, filename, ret);
816 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
824 /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
825 if (WARN_ON(ar->hw.fw.fw == NULL))
828 snprintf(filename, sizeof(filename), "%s/%s",
829 ar->hw.fw.dir, ar->hw.fw.fw);
831 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
833 ath6kl_err("Failed to get firmware file %s: %d\n",
841 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
846 if (ar->fw_patch != NULL)
849 if (ar->hw.fw.patch == NULL)
852 snprintf(filename, sizeof(filename), "%s/%s",
853 ar->hw.fw.dir, ar->hw.fw.patch);
855 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
858 ath6kl_err("Failed to get patch file %s: %d\n",
866 static int ath6kl_fetch_testscript_file(struct ath6kl *ar)
871 if (ar->testmode != 2)
874 if (ar->fw_testscript != NULL)
877 if (ar->hw.fw.testscript == NULL)
880 snprintf(filename, sizeof(filename), "%s/%s",
881 ar->hw.fw.dir, ar->hw.fw.testscript);
883 ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript,
884 &ar->fw_testscript_len);
886 ath6kl_err("Failed to get testscript file %s: %d\n",
894 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
898 ret = ath6kl_fetch_otp_file(ar);
902 ret = ath6kl_fetch_fw_file(ar);
906 ret = ath6kl_fetch_patch_file(ar);
910 ret = ath6kl_fetch_testscript_file(ar);
917 static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
919 size_t magic_len, len, ie_len;
920 const struct firmware *fw;
921 struct ath6kl_fw_ie *hdr;
924 int ret, ie_id, i, index, bit;
927 snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
929 ret = request_firmware(&fw, filename, ar->dev);
936 /* magic also includes the null byte, check that as well */
937 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
939 if (len < magic_len) {
944 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
953 while (len > sizeof(struct ath6kl_fw_ie)) {
954 /* hdr is unaligned! */
955 hdr = (struct ath6kl_fw_ie *) data;
957 ie_id = le32_to_cpup(&hdr->id);
958 ie_len = le32_to_cpup(&hdr->len);
961 data += sizeof(*hdr);
969 case ATH6KL_FW_IE_FW_VERSION:
970 strlcpy(ar->wiphy->fw_version, data,
971 sizeof(ar->wiphy->fw_version));
973 ath6kl_dbg(ATH6KL_DBG_BOOT,
974 "found fw version %s\n",
975 ar->wiphy->fw_version);
977 case ATH6KL_FW_IE_OTP_IMAGE:
978 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
981 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
983 if (ar->fw_otp == NULL) {
988 ar->fw_otp_len = ie_len;
990 case ATH6KL_FW_IE_FW_IMAGE:
991 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
994 /* in testmode we already might have a fw file */
998 ar->fw = vmalloc(ie_len);
1000 if (ar->fw == NULL) {
1005 memcpy(ar->fw, data, ie_len);
1006 ar->fw_len = ie_len;
1008 case ATH6KL_FW_IE_PATCH_IMAGE:
1009 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
1012 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
1014 if (ar->fw_patch == NULL) {
1019 ar->fw_patch_len = ie_len;
1021 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
1022 val = (__le32 *) data;
1023 ar->hw.reserved_ram_size = le32_to_cpup(val);
1025 ath6kl_dbg(ATH6KL_DBG_BOOT,
1026 "found reserved ram size ie 0x%d\n",
1027 ar->hw.reserved_ram_size);
1029 case ATH6KL_FW_IE_CAPABILITIES:
1030 ath6kl_dbg(ATH6KL_DBG_BOOT,
1031 "found firmware capabilities ie (%zd B)\n",
1034 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
1038 if (index == ie_len)
1041 if (data[index] & (1 << bit))
1042 __set_bit(i, ar->fw_capabilities);
1045 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
1046 ar->fw_capabilities,
1047 sizeof(ar->fw_capabilities));
1049 case ATH6KL_FW_IE_PATCH_ADDR:
1050 if (ie_len != sizeof(*val))
1053 val = (__le32 *) data;
1054 ar->hw.dataset_patch_addr = le32_to_cpup(val);
1056 ath6kl_dbg(ATH6KL_DBG_BOOT,
1057 "found patch address ie 0x%x\n",
1058 ar->hw.dataset_patch_addr);
1060 case ATH6KL_FW_IE_BOARD_ADDR:
1061 if (ie_len != sizeof(*val))
1064 val = (__le32 *) data;
1065 ar->hw.board_addr = le32_to_cpup(val);
1067 ath6kl_dbg(ATH6KL_DBG_BOOT,
1068 "found board address ie 0x%x\n",
1071 case ATH6KL_FW_IE_VIF_MAX:
1072 if (ie_len != sizeof(*val))
1075 val = (__le32 *) data;
1076 ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
1079 if (ar->vif_max > 1 && !ar->p2p)
1080 ar->max_norm_iface = 2;
1082 ath6kl_dbg(ATH6KL_DBG_BOOT,
1083 "found vif max ie %d\n", ar->vif_max);
1086 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
1087 le32_to_cpup(&hdr->id));
1097 release_firmware(fw);
1102 int ath6kl_init_fetch_firmwares(struct ath6kl *ar)
1106 ret = ath6kl_fetch_board_file(ar);
1110 ret = ath6kl_fetch_testmode_file(ar);
1114 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API4_FILE);
1120 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
1126 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
1132 ret = ath6kl_fetch_fw_api1(ar);
1139 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1144 static int ath6kl_upload_board_file(struct ath6kl *ar)
1146 u32 board_address, board_ext_address, param;
1147 u32 board_data_size, board_ext_data_size;
1150 if (WARN_ON(ar->fw_board == NULL))
1154 * Determine where in Target RAM to write Board Data.
1155 * For AR6004, host determine Target RAM address for
1156 * writing board data.
1158 if (ar->hw.board_addr != 0) {
1159 board_address = ar->hw.board_addr;
1160 ath6kl_bmi_write_hi32(ar, hi_board_data,
1163 ath6kl_bmi_read_hi32(ar, hi_board_data, &board_address);
1166 /* determine where in target ram to write extended board data */
1167 ath6kl_bmi_read_hi32(ar, hi_board_ext_data, &board_ext_address);
1169 if (ar->target_type == TARGET_TYPE_AR6003 &&
1170 board_ext_address == 0) {
1171 ath6kl_err("Failed to get board file target address.\n");
1175 switch (ar->target_type) {
1176 case TARGET_TYPE_AR6003:
1177 board_data_size = AR6003_BOARD_DATA_SZ;
1178 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1179 if (ar->fw_board_len > (board_data_size + board_ext_data_size))
1180 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ_V2;
1182 case TARGET_TYPE_AR6004:
1183 board_data_size = AR6004_BOARD_DATA_SZ;
1184 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1192 if (board_ext_address &&
1193 ar->fw_board_len == (board_data_size + board_ext_data_size)) {
1195 /* write extended board data */
1196 ath6kl_dbg(ATH6KL_DBG_BOOT,
1197 "writing extended board data to 0x%x (%d B)\n",
1198 board_ext_address, board_ext_data_size);
1200 ret = ath6kl_bmi_write(ar, board_ext_address,
1201 ar->fw_board + board_data_size,
1202 board_ext_data_size);
1204 ath6kl_err("Failed to write extended board data: %d\n",
1209 /* record that extended board data is initialized */
1210 param = (board_ext_data_size << 16) | 1;
1212 ath6kl_bmi_write_hi32(ar, hi_board_ext_data_config, param);
1215 if (ar->fw_board_len < board_data_size) {
1216 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1221 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1222 board_address, board_data_size);
1224 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
1228 ath6kl_err("Board file bmi write failed: %d\n", ret);
1232 /* record the fact that Board Data IS initialized */
1233 ath6kl_bmi_write_hi32(ar, hi_board_data_initialized, 1);
1238 static int ath6kl_upload_otp(struct ath6kl *ar)
1241 bool from_hw = false;
1244 if (ar->fw_otp == NULL)
1247 address = ar->hw.app_load_addr;
1249 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
1252 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1255 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1259 /* read firmware start address */
1260 ret = ath6kl_bmi_read_hi32(ar, hi_app_start, &address);
1263 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1267 if (ar->hw.app_start_override_addr == 0) {
1268 ar->hw.app_start_override_addr = address;
1272 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1273 from_hw ? " (from hw)" : "",
1274 ar->hw.app_start_override_addr);
1276 /* execute the OTP code */
1277 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1278 ar->hw.app_start_override_addr);
1280 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m);
1285 static int ath6kl_upload_firmware(struct ath6kl *ar)
1290 if (WARN_ON(ar->fw == NULL))
1293 address = ar->hw.app_load_addr;
1295 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
1296 address, ar->fw_len);
1298 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1301 ath6kl_err("Failed to write firmware: %d\n", ret);
1306 * Set starting address for firmware
1307 * Don't need to setup app_start override addr on AR6004
1309 if (ar->target_type != TARGET_TYPE_AR6004) {
1310 address = ar->hw.app_start_override_addr;
1311 ath6kl_bmi_set_app_start(ar, address);
1316 static int ath6kl_upload_patch(struct ath6kl *ar)
1321 if (ar->fw_patch == NULL)
1324 address = ar->hw.dataset_patch_addr;
1326 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
1327 address, ar->fw_patch_len);
1329 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1331 ath6kl_err("Failed to write patch file: %d\n", ret);
1335 ath6kl_bmi_write_hi32(ar, hi_dset_list_head, address);
1340 static int ath6kl_upload_testscript(struct ath6kl *ar)
1345 if (ar->testmode != 2)
1348 if (ar->fw_testscript == NULL)
1351 address = ar->hw.testscript_addr;
1353 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n",
1354 address, ar->fw_testscript_len);
1356 ret = ath6kl_bmi_write(ar, address, ar->fw_testscript,
1357 ar->fw_testscript_len);
1359 ath6kl_err("Failed to write testscript file: %d\n", ret);
1363 ath6kl_bmi_write_hi32(ar, hi_ota_testscript, address);
1364 ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz, 4096);
1365 ath6kl_bmi_write_hi32(ar, hi_test_apps_related, 1);
1370 static int ath6kl_init_upload(struct ath6kl *ar)
1372 u32 param, options, sleep, address;
1375 if (ar->target_type != TARGET_TYPE_AR6003 &&
1376 ar->target_type != TARGET_TYPE_AR6004)
1379 /* temporarily disable system sleep */
1380 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1381 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1387 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1388 status = ath6kl_bmi_reg_write(ar, address, param);
1392 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1393 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1399 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1400 status = ath6kl_bmi_reg_write(ar, address, param);
1404 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1407 /* program analog PLL register */
1408 /* no need to control 40/44MHz clock on AR6004 */
1409 if (ar->target_type != TARGET_TYPE_AR6004) {
1410 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1416 /* Run at 80/88MHz by default */
1417 param = SM(CPU_CLOCK_STANDARD, 1);
1419 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1420 status = ath6kl_bmi_reg_write(ar, address, param);
1426 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1427 param = SM(LPO_CAL_ENABLE, 1);
1428 status = ath6kl_bmi_reg_write(ar, address, param);
1432 /* WAR to avoid SDIO CRC err */
1433 if (ar->version.target_ver == AR6003_HW_2_0_VERSION ||
1434 ar->version.target_ver == AR6003_HW_2_1_1_VERSION) {
1435 ath6kl_err("temporary war to avoid sdio crc error\n");
1438 address = GPIO_BASE_ADDRESS + GPIO_PIN9_ADDRESS;
1439 status = ath6kl_bmi_reg_write(ar, address, param);
1445 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1446 status = ath6kl_bmi_reg_write(ar, address, param);
1450 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1451 status = ath6kl_bmi_reg_write(ar, address, param);
1455 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1456 status = ath6kl_bmi_reg_write(ar, address, param);
1460 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1461 status = ath6kl_bmi_reg_write(ar, address, param);
1466 /* write EEPROM data to Target RAM */
1467 status = ath6kl_upload_board_file(ar);
1471 /* transfer One time Programmable data */
1472 status = ath6kl_upload_otp(ar);
1476 /* Download Target firmware */
1477 status = ath6kl_upload_firmware(ar);
1481 status = ath6kl_upload_patch(ar);
1485 /* Download the test script */
1486 status = ath6kl_upload_testscript(ar);
1490 /* Restore system sleep */
1491 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1492 status = ath6kl_bmi_reg_write(ar, address, sleep);
1496 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1497 param = options | 0x20;
1498 status = ath6kl_bmi_reg_write(ar, address, param);
1505 int ath6kl_init_hw_params(struct ath6kl *ar)
1507 const struct ath6kl_hw *uninitialized_var(hw);
1510 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
1513 if (hw->id == ar->version.target_ver)
1517 if (i == ARRAY_SIZE(hw_list)) {
1518 ath6kl_err("Unsupported hardware version: 0x%x\n",
1519 ar->version.target_ver);
1525 ath6kl_dbg(ATH6KL_DBG_BOOT,
1526 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1527 ar->version.target_ver, ar->target_type,
1528 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1529 ath6kl_dbg(ATH6KL_DBG_BOOT,
1530 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1531 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1532 ar->hw.reserved_ram_size);
1533 ath6kl_dbg(ATH6KL_DBG_BOOT,
1534 "refclk_hz %d uarttx_pin %d",
1535 ar->hw.refclk_hz, ar->hw.uarttx_pin);
1540 static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
1543 case ATH6KL_HIF_TYPE_SDIO:
1545 case ATH6KL_HIF_TYPE_USB:
1552 static int __ath6kl_init_hw_start(struct ath6kl *ar)
1557 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
1559 ret = ath6kl_hif_power_on(ar);
1563 ret = ath6kl_configure_target(ar);
1567 ret = ath6kl_init_upload(ar);
1571 /* Do we need to finish the BMI phase */
1572 /* FIXME: return error from ath6kl_bmi_done() */
1573 if (ath6kl_bmi_done(ar)) {
1579 * The reason we have to wait for the target here is that the
1580 * driver layer has to init BMI in order to set the host block
1583 if (ath6kl_htc_wait_target(ar->htc_target)) {
1588 if (ath6kl_init_service_ep(ar)) {
1590 goto err_cleanup_scatter;
1593 /* setup credit distribution */
1594 ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info);
1597 ret = ath6kl_htc_start(ar->htc_target);
1599 /* FIXME: call this */
1600 ath6kl_cookie_cleanup(ar);
1601 goto err_cleanup_scatter;
1604 /* Wait for Wmi event to be ready */
1605 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1610 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1613 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
1614 ath6kl_info("%s %s fw %s api %d%s\n",
1616 ath6kl_init_get_hif_name(ar->hif_type),
1617 ar->wiphy->fw_version,
1619 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
1622 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1623 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1624 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1629 if (!timeleft || signal_pending(current)) {
1630 ath6kl_err("wmi is not ready or wait was interrupted\n");
1635 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1637 /* communicate the wmi protocol verision to the target */
1638 /* FIXME: return error */
1639 if ((ath6kl_set_host_app_area(ar)) != 0)
1640 ath6kl_err("unable to set the host app area\n");
1642 for (i = 0; i < ar->vif_max; i++) {
1643 ret = ath6kl_target_config_wlan_params(ar, i);
1651 ath6kl_htc_stop(ar->htc_target);
1652 err_cleanup_scatter:
1653 ath6kl_hif_cleanup_scatter(ar);
1655 ath6kl_hif_power_off(ar);
1660 int ath6kl_init_hw_start(struct ath6kl *ar)
1664 err = __ath6kl_init_hw_start(ar);
1667 ar->state = ATH6KL_STATE_ON;
1671 static int __ath6kl_init_hw_stop(struct ath6kl *ar)
1675 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
1677 ath6kl_htc_stop(ar->htc_target);
1679 ath6kl_hif_stop(ar);
1681 ath6kl_bmi_reset(ar);
1683 ret = ath6kl_hif_power_off(ar);
1685 ath6kl_warn("failed to power off hif: %d\n", ret);
1690 int ath6kl_init_hw_stop(struct ath6kl *ar)
1694 err = __ath6kl_init_hw_stop(ar);
1697 ar->state = ATH6KL_STATE_OFF;
1701 void ath6kl_init_hw_restart(struct ath6kl *ar)
1703 clear_bit(WMI_READY, &ar->flag);
1705 ath6kl_cfg80211_stop_all(ar);
1707 if (__ath6kl_init_hw_stop(ar)) {
1708 ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to stop during fw error recovery\n");
1712 if (__ath6kl_init_hw_start(ar)) {
1713 ath6kl_dbg(ATH6KL_DBG_RECOVERY, "Failed to restart during fw error recovery\n");
1718 /* FIXME: move this to cfg80211.c and rename to ath6kl_cfg80211_vif_stop() */
1719 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
1721 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1724 netif_stop_queue(vif->ndev);
1726 clear_bit(WLAN_ENABLED, &vif->flags);
1729 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1730 test_bit(CONNECT_PEND, &vif->flags);
1731 ath6kl_disconnect(vif);
1732 del_timer(&vif->disconnect_timer);
1735 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1736 (vif->nw_type & AP_NETWORK) ?
1737 bcast_mac : vif->bssid,
1741 if (vif->scan_req) {
1742 cfg80211_scan_done(vif->scan_req, true);
1743 vif->scan_req = NULL;
1746 /* need to clean up enhanced bmiss detection fw state */
1747 ath6kl_cfg80211_sta_bmiss_enhance(vif, false);
1750 void ath6kl_stop_txrx(struct ath6kl *ar)
1752 struct ath6kl_vif *vif, *tmp_vif;
1755 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1757 if (down_interruptible(&ar->sem)) {
1758 ath6kl_err("down_interruptible failed\n");
1762 for (i = 0; i < AP_MAX_NUM_STA; i++)
1763 aggr_reset_state(ar->sta_list[i].aggr_conn);
1765 spin_lock_bh(&ar->list_lock);
1766 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1767 list_del(&vif->list);
1768 spin_unlock_bh(&ar->list_lock);
1769 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1771 ath6kl_cfg80211_vif_cleanup(vif);
1773 spin_lock_bh(&ar->list_lock);
1775 spin_unlock_bh(&ar->list_lock);
1777 clear_bit(WMI_READY, &ar->flag);
1780 * After wmi_shudown all WMI events will be dropped. We
1781 * need to cleanup the buffers allocated in AP mode and
1782 * give disconnect notification to stack, which usually
1783 * happens in the disconnect_event. Simulate the disconnect
1784 * event by calling the function directly. Sometimes
1785 * disconnect_event will be received when the debug logs
1788 ath6kl_wmi_shutdown(ar->wmi);
1790 clear_bit(WMI_ENABLED, &ar->flag);
1791 if (ar->htc_target) {
1792 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1793 ath6kl_htc_stop(ar->htc_target);
1797 * Try to reset the device if we can. The driver may have been
1798 * configure NOT to reset the target during a debug session.
1800 ath6kl_dbg(ATH6KL_DBG_TRC,
1801 "attempting to reset target on instance destroy\n");
1802 ath6kl_reset_device(ar, ar->target_type, true, true);
1804 clear_bit(WLAN_ENABLED, &ar->flag);
1808 EXPORT_SYMBOL(ath6kl_stop_txrx);