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;
31 static unsigned int uart_debug;
33 module_param(debug_mask, uint, 0644);
34 module_param(testmode, uint, 0644);
35 module_param(suspend_cutpower, bool, 0444);
36 module_param(uart_debug, uint, 0644);
38 static const struct ath6kl_hw hw_list[] = {
40 .id = AR6003_HW_2_0_VERSION,
41 .name = "ar6003 hw 2.0",
42 .dataset_patch_addr = 0x57e884,
43 .app_load_addr = 0x543180,
44 .board_ext_data_addr = 0x57e500,
45 .reserved_ram_size = 6912,
46 .refclk_hz = 26000000,
49 /* hw2.0 needs override address hardcoded */
50 .app_start_override_addr = 0x944C00,
53 .dir = AR6003_HW_2_0_FW_DIR,
54 .otp = AR6003_HW_2_0_OTP_FILE,
55 .fw = AR6003_HW_2_0_FIRMWARE_FILE,
56 .tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
57 .patch = AR6003_HW_2_0_PATCH_FILE,
60 .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE,
61 .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
64 .id = AR6003_HW_2_1_1_VERSION,
65 .name = "ar6003 hw 2.1.1",
66 .dataset_patch_addr = 0x57ff74,
67 .app_load_addr = 0x1234,
68 .board_ext_data_addr = 0x542330,
69 .reserved_ram_size = 512,
70 .refclk_hz = 26000000,
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,
81 .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
82 .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
85 .id = AR6004_HW_1_0_VERSION,
86 .name = "ar6004 hw 1.0",
87 .dataset_patch_addr = 0x57e884,
88 .app_load_addr = 0x1234,
89 .board_ext_data_addr = 0x437000,
90 .reserved_ram_size = 19456,
91 .board_addr = 0x433900,
92 .refclk_hz = 26000000,
96 .dir = AR6004_HW_1_0_FW_DIR,
97 .fw = AR6004_HW_1_0_FIRMWARE_FILE,
100 .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
101 .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
104 .id = AR6004_HW_1_1_VERSION,
105 .name = "ar6004 hw 1.1",
106 .dataset_patch_addr = 0x57e884,
107 .app_load_addr = 0x1234,
108 .board_ext_data_addr = 0x437000,
109 .reserved_ram_size = 11264,
110 .board_addr = 0x43d400,
111 .refclk_hz = 40000000,
115 .dir = AR6004_HW_1_1_FW_DIR,
116 .fw = AR6004_HW_1_1_FIRMWARE_FILE,
119 .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
120 .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
125 * Include definitions here that can be used to tune the WLAN module
126 * behavior. Different customers can tune the behavior as per their needs,
131 * This configuration item enable/disable keepalive support.
132 * Keepalive support: In the absence of any data traffic to AP, null
133 * frames will be sent to the AP at periodic interval, to keep the association
134 * active. This configuration item defines the periodic interval.
135 * Use value of zero to disable keepalive support
136 * Default: 60 seconds
138 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
141 * This configuration item sets the value of disconnect timeout
142 * Firmware delays sending the disconnec event to the host for this
143 * timeout after is gets disconnected from the current AP.
144 * If the firmware successly roams within the disconnect timeout
145 * it sends a new connect event
147 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
150 #define ATH6KL_DATA_OFFSET 64
151 struct sk_buff *ath6kl_buf_alloc(int size)
156 /* Add chacheline space at front and back of buffer */
157 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
158 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
159 skb = dev_alloc_skb(size + reserved);
162 skb_reserve(skb, reserved - L1_CACHE_BYTES);
166 void ath6kl_init_profile_info(struct ath6kl_vif *vif)
169 memset(vif->ssid, 0, sizeof(vif->ssid));
171 vif->dot11_auth_mode = OPEN_AUTH;
172 vif->auth_mode = NONE_AUTH;
173 vif->prwise_crypto = NONE_CRYPT;
174 vif->prwise_crypto_len = 0;
175 vif->grp_crypto = NONE_CRYPT;
176 vif->grp_crypto_len = 0;
177 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
178 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
179 memset(vif->bssid, 0, sizeof(vif->bssid));
183 static int ath6kl_set_host_app_area(struct ath6kl *ar)
186 struct host_app_area host_app_area;
188 /* Fetch the address of the host_app_area_s
189 * instance in the host interest area */
190 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
191 address = TARG_VTOP(ar->target_type, address);
193 if (ath6kl_diag_read32(ar, address, &data))
196 address = TARG_VTOP(ar->target_type, data);
197 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
198 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
199 sizeof(struct host_app_area)))
205 static inline void set_ac2_ep_map(struct ath6kl *ar,
207 enum htc_endpoint_id ep)
209 ar->ac2ep_map[ac] = ep;
210 ar->ep2ac_map[ep] = ac;
213 /* connect to a service */
214 static int ath6kl_connectservice(struct ath6kl *ar,
215 struct htc_service_connect_req *con_req,
219 struct htc_service_connect_resp response;
221 memset(&response, 0, sizeof(response));
223 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
225 ath6kl_err("failed to connect to %s service status:%d\n",
230 switch (con_req->svc_id) {
231 case WMI_CONTROL_SVC:
232 if (test_bit(WMI_ENABLED, &ar->flag))
233 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
234 ar->ctrl_ep = response.endpoint;
236 case WMI_DATA_BE_SVC:
237 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
239 case WMI_DATA_BK_SVC:
240 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
242 case WMI_DATA_VI_SVC:
243 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
245 case WMI_DATA_VO_SVC:
246 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
249 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
256 static int ath6kl_init_service_ep(struct ath6kl *ar)
258 struct htc_service_connect_req connect;
260 memset(&connect, 0, sizeof(connect));
262 /* these fields are the same for all service endpoints */
263 connect.ep_cb.rx = ath6kl_rx;
264 connect.ep_cb.rx_refill = ath6kl_rx_refill;
265 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
268 * Set the max queue depth so that our ath6kl_tx_queue_full handler
271 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
272 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
273 if (!connect.ep_cb.rx_refill_thresh)
274 connect.ep_cb.rx_refill_thresh++;
276 /* connect to control service */
277 connect.svc_id = WMI_CONTROL_SVC;
278 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
281 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
284 * Limit the HTC message size on the send path, although e can
285 * receive A-MSDU frames of 4K, we will only send ethernet-sized
286 * (802.3) frames on the send path.
288 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
291 * To reduce the amount of committed memory for larger A_MSDU
292 * frames, use the recv-alloc threshold mechanism for larger
295 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
296 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
299 * For the remaining data services set the connection flag to
300 * reduce dribbling, if configured to do so.
302 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
303 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
304 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
306 connect.svc_id = WMI_DATA_BE_SVC;
308 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
311 /* connect to back-ground map this to WMI LOW_PRI */
312 connect.svc_id = WMI_DATA_BK_SVC;
313 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
316 /* connect to Video service, map this to to HI PRI */
317 connect.svc_id = WMI_DATA_VI_SVC;
318 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
322 * Connect to VO service, this is currently not mapped to a WMI
323 * priority stream due to historical reasons. WMI originally
324 * defined 3 priorities over 3 mailboxes We can change this when
325 * WMI is reworked so that priorities are not dependent on
328 connect.svc_id = WMI_DATA_VO_SVC;
329 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
335 void ath6kl_init_control_info(struct ath6kl_vif *vif)
337 ath6kl_init_profile_info(vif);
338 vif->def_txkey_index = 0;
339 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
344 * Set HTC/Mbox operational parameters, this can only be called when the
345 * target is in the BMI phase.
347 static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
353 blk_size = ar->mbox_info.block_size;
356 blk_size |= ((u32)htc_ctrl_buf) << 16;
358 /* set the host interest area for the block size */
359 status = ath6kl_bmi_write(ar,
360 ath6kl_get_hi_item_addr(ar,
361 HI_ITEM(hi_mbox_io_block_sz)),
365 ath6kl_err("bmi_write_memory for IO block size failed\n");
369 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
371 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
373 if (mbox_isr_yield_val) {
374 /* set the host interest area for the mbox ISR yield limit */
375 status = ath6kl_bmi_write(ar,
376 ath6kl_get_hi_item_addr(ar,
377 HI_ITEM(hi_mbox_isr_yield_limit)),
378 (u8 *)&mbox_isr_yield_val,
381 ath6kl_err("bmi_write_memory for yield limit failed\n");
390 static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
396 * Configure the device for rx dot11 header rules. "0,0" are the
397 * default values. Required if checksum offload is needed. Set
398 * RxMetaVersion to 2.
400 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
401 ar->rx_meta_ver, 0, 0)) {
402 ath6kl_err("unable to set the rx frame format\n");
406 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
407 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
408 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
409 ath6kl_err("unable to set power save fail event policy\n");
413 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
414 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
415 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
416 ath6kl_err("unable to set barker preamble policy\n");
420 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
421 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
422 ath6kl_err("unable to set keep alive interval\n");
426 if (ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
427 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
428 ath6kl_err("unable to set disconnect timeout\n");
432 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
433 if (ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED)) {
434 ath6kl_err("unable to set txop bursting\n");
438 if (ar->p2p && (ar->vif_max == 1 || idx)) {
439 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
440 P2P_FLAG_CAPABILITIES_REQ |
441 P2P_FLAG_MACADDR_REQ |
442 P2P_FLAG_HMODEL_REQ);
444 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
445 "capabilities (%d) - assuming P2P not "
451 if (ar->p2p && (ar->vif_max == 1 || idx)) {
452 /* Enable Probe Request reporting for P2P */
453 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
455 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
456 "Request reporting (%d)\n", ret);
463 int ath6kl_configure_target(struct ath6kl *ar)
465 u32 param, ram_reserved_size;
466 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
470 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
471 HI_ITEM(hi_serial_enable)), (u8 *)¶m, 4)) {
472 ath6kl_err("bmi_write_memory for uart debug failed\n");
477 * Note: Even though the firmware interface type is
478 * chosen as BSS_STA for all three interfaces, can
479 * be configured to IBSS/AP as long as the fw submode
480 * remains normal mode (0 - AP, STA and IBSS). But
481 * due to an target assert in firmware only one interface is
482 * configured for now.
484 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
486 for (i = 0; i < ar->vif_max; i++)
487 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
490 * By default, submodes :
491 * vif[0] - AP/STA/IBSS
492 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
493 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
496 for (i = 0; i < ar->max_norm_iface; i++)
497 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
498 (i * HI_OPTION_FW_SUBMODE_BITS);
500 for (i = ar->max_norm_iface; i < ar->vif_max; i++)
501 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
502 (i * HI_OPTION_FW_SUBMODE_BITS);
504 if (ar->p2p && ar->vif_max == 1)
505 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
507 param = HTC_PROTOCOL_VERSION;
508 if (ath6kl_bmi_write(ar,
509 ath6kl_get_hi_item_addr(ar,
510 HI_ITEM(hi_app_host_interest)),
511 (u8 *)¶m, 4) != 0) {
512 ath6kl_err("bmi_write_memory for htc version failed\n");
516 /* set the firmware mode to STA/IBSS/AP */
519 if (ath6kl_bmi_read(ar,
520 ath6kl_get_hi_item_addr(ar,
521 HI_ITEM(hi_option_flag)),
522 (u8 *)¶m, 4) != 0) {
523 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
527 param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
528 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
529 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
531 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
532 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
534 if (ath6kl_bmi_write(ar,
535 ath6kl_get_hi_item_addr(ar,
536 HI_ITEM(hi_option_flag)),
539 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
543 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
546 * Hardcode the address use for the extended board data
547 * Ideally this should be pre-allocate by the OS at boot time
548 * But since it is a new feature and board data is loaded
549 * at init time, we have to workaround this from host.
550 * It is difficult to patch the firmware boot code,
551 * but possible in theory.
554 param = ar->hw.board_ext_data_addr;
555 ram_reserved_size = ar->hw.reserved_ram_size;
557 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
558 HI_ITEM(hi_board_ext_data)),
559 (u8 *)¶m, 4) != 0) {
560 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
564 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
565 HI_ITEM(hi_end_ram_reserve_sz)),
566 (u8 *)&ram_reserved_size, 4) != 0) {
567 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
571 /* set the block size for the target */
572 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
573 /* use default number of control buffers */
576 /* Configure GPIO AR600x UART */
577 param = ar->hw.uarttx_pin;
578 status = ath6kl_bmi_write(ar,
579 ath6kl_get_hi_item_addr(ar,
580 HI_ITEM(hi_dbg_uart_txpin)),
585 /* Configure target refclk_hz */
586 param = ar->hw.refclk_hz;
587 status = ath6kl_bmi_write(ar,
588 ath6kl_get_hi_item_addr(ar,
589 HI_ITEM(hi_refclk_hz)),
597 void ath6kl_core_free(struct ath6kl *ar)
599 wiphy_free(ar->wiphy);
602 void ath6kl_core_cleanup(struct ath6kl *ar)
604 ath6kl_hif_power_off(ar);
606 destroy_workqueue(ar->ath6kl_wq);
609 ath6kl_htc_cleanup(ar->htc_target);
611 ath6kl_cookie_cleanup(ar);
613 ath6kl_cleanup_amsdu_rxbufs(ar);
615 ath6kl_bmi_cleanup(ar);
617 ath6kl_debug_cleanup(ar);
624 ath6kl_deinit_ieee80211_hw(ar);
627 /* firmware upload */
628 static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
629 u8 **fw, size_t *fw_len)
631 const struct firmware *fw_entry;
634 ret = request_firmware(&fw_entry, filename, ar->dev);
638 *fw_len = fw_entry->size;
639 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
644 release_firmware(fw_entry);
651 * Check the device tree for a board-id and use it to construct
652 * the pathname to the firmware file. Used (for now) to find a
653 * fallback to the "bdata.bin" file--typically a symlink to the
654 * appropriate board-specific file.
656 static bool check_device_tree(struct ath6kl *ar)
658 static const char *board_id_prop = "atheros,board-id";
659 struct device_node *node;
660 char board_filename[64];
661 const char *board_id;
664 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
665 board_id = of_get_property(node, board_id_prop, NULL);
666 if (board_id == NULL) {
667 ath6kl_warn("No \"%s\" property on %s node.\n",
668 board_id_prop, node->name);
671 snprintf(board_filename, sizeof(board_filename),
672 "%s/bdata.%s.bin", ar->hw.fw.dir, board_id);
674 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
677 ath6kl_err("Failed to get DT board file %s: %d\n",
678 board_filename, ret);
686 static bool check_device_tree(struct ath6kl *ar)
690 #endif /* CONFIG_OF */
692 static int ath6kl_fetch_board_file(struct ath6kl *ar)
694 const char *filename;
697 if (ar->fw_board != NULL)
700 if (WARN_ON(ar->hw.fw_board == NULL))
703 filename = ar->hw.fw_board;
705 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
708 /* managed to get proper board file */
712 if (check_device_tree(ar)) {
713 /* got board file from device tree */
717 /* there was no proper board file, try to use default instead */
718 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
721 filename = ar->hw.fw_default_board;
723 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
726 ath6kl_err("Failed to get default board file %s: %d\n",
731 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
732 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
737 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
742 if (ar->fw_otp != NULL)
745 if (ar->hw.fw.otp == NULL) {
746 ath6kl_dbg(ATH6KL_DBG_BOOT,
747 "no OTP file configured for this hw\n");
751 snprintf(filename, sizeof(filename), "%s/%s",
752 ar->hw.fw.dir, ar->hw.fw.otp);
754 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
757 ath6kl_err("Failed to get OTP file %s: %d\n",
765 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
774 if (ar->hw.fw.tcmd == NULL) {
775 ath6kl_warn("testmode not supported\n");
779 snprintf(filename, sizeof(filename), "%s/%s",
780 ar->hw.fw.dir, ar->hw.fw.tcmd);
782 set_bit(TESTMODE, &ar->flag);
787 /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
788 if (WARN_ON(ar->hw.fw.fw == NULL))
791 snprintf(filename, sizeof(filename), "%s/%s",
792 ar->hw.fw.dir, ar->hw.fw.fw);
795 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
797 ath6kl_err("Failed to get firmware file %s: %d\n",
805 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
810 if (ar->fw_patch != NULL)
813 if (ar->hw.fw.patch == NULL)
816 snprintf(filename, sizeof(filename), "%s/%s",
817 ar->hw.fw.dir, ar->hw.fw.patch);
819 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
822 ath6kl_err("Failed to get patch file %s: %d\n",
830 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
834 ret = ath6kl_fetch_otp_file(ar);
838 ret = ath6kl_fetch_fw_file(ar);
842 ret = ath6kl_fetch_patch_file(ar);
849 static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
851 size_t magic_len, len, ie_len;
852 const struct firmware *fw;
853 struct ath6kl_fw_ie *hdr;
856 int ret, ie_id, i, index, bit;
859 snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
861 ret = request_firmware(&fw, filename, ar->dev);
868 /* magic also includes the null byte, check that as well */
869 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
871 if (len < magic_len) {
876 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
885 while (len > sizeof(struct ath6kl_fw_ie)) {
886 /* hdr is unaligned! */
887 hdr = (struct ath6kl_fw_ie *) data;
889 ie_id = le32_to_cpup(&hdr->id);
890 ie_len = le32_to_cpup(&hdr->len);
893 data += sizeof(*hdr);
901 case ATH6KL_FW_IE_OTP_IMAGE:
902 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
905 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
907 if (ar->fw_otp == NULL) {
912 ar->fw_otp_len = ie_len;
914 case ATH6KL_FW_IE_FW_IMAGE:
915 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
918 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
920 if (ar->fw == NULL) {
927 case ATH6KL_FW_IE_PATCH_IMAGE:
928 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
931 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
933 if (ar->fw_patch == NULL) {
938 ar->fw_patch_len = ie_len;
940 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
941 val = (__le32 *) data;
942 ar->hw.reserved_ram_size = le32_to_cpup(val);
944 ath6kl_dbg(ATH6KL_DBG_BOOT,
945 "found reserved ram size ie 0x%d\n",
946 ar->hw.reserved_ram_size);
948 case ATH6KL_FW_IE_CAPABILITIES:
949 if (ie_len < DIV_ROUND_UP(ATH6KL_FW_CAPABILITY_MAX, 8))
952 ath6kl_dbg(ATH6KL_DBG_BOOT,
953 "found firmware capabilities ie (%zd B)\n",
956 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
960 if (data[index] & (1 << bit))
961 __set_bit(i, ar->fw_capabilities);
964 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
966 sizeof(ar->fw_capabilities));
968 case ATH6KL_FW_IE_PATCH_ADDR:
969 if (ie_len != sizeof(*val))
972 val = (__le32 *) data;
973 ar->hw.dataset_patch_addr = le32_to_cpup(val);
975 ath6kl_dbg(ATH6KL_DBG_BOOT,
976 "found patch address ie 0x%x\n",
977 ar->hw.dataset_patch_addr);
979 case ATH6KL_FW_IE_BOARD_ADDR:
980 if (ie_len != sizeof(*val))
983 val = (__le32 *) data;
984 ar->hw.board_addr = le32_to_cpup(val);
986 ath6kl_dbg(ATH6KL_DBG_BOOT,
987 "found board address ie 0x%x\n",
990 case ATH6KL_FW_IE_VIF_MAX:
991 if (ie_len != sizeof(*val))
994 val = (__le32 *) data;
995 ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
998 if (ar->vif_max > 1 && !ar->p2p)
999 ar->max_norm_iface = 2;
1001 ath6kl_dbg(ATH6KL_DBG_BOOT,
1002 "found vif max ie %d\n", ar->vif_max);
1005 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
1006 le32_to_cpup(&hdr->id));
1016 release_firmware(fw);
1021 static int ath6kl_fetch_firmwares(struct ath6kl *ar)
1025 ret = ath6kl_fetch_board_file(ar);
1029 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
1035 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
1041 ret = ath6kl_fetch_fw_api1(ar);
1048 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1053 static int ath6kl_upload_board_file(struct ath6kl *ar)
1055 u32 board_address, board_ext_address, param;
1056 u32 board_data_size, board_ext_data_size;
1059 if (WARN_ON(ar->fw_board == NULL))
1063 * Determine where in Target RAM to write Board Data.
1064 * For AR6004, host determine Target RAM address for
1065 * writing board data.
1067 if (ar->hw.board_addr != 0) {
1068 board_address = ar->hw.board_addr;
1069 ath6kl_bmi_write(ar,
1070 ath6kl_get_hi_item_addr(ar,
1071 HI_ITEM(hi_board_data)),
1072 (u8 *) &board_address, 4);
1075 ath6kl_get_hi_item_addr(ar,
1076 HI_ITEM(hi_board_data)),
1077 (u8 *) &board_address, 4);
1080 /* determine where in target ram to write extended board data */
1082 ath6kl_get_hi_item_addr(ar,
1083 HI_ITEM(hi_board_ext_data)),
1084 (u8 *) &board_ext_address, 4);
1086 if (ar->target_type == TARGET_TYPE_AR6003 &&
1087 board_ext_address == 0) {
1088 ath6kl_err("Failed to get board file target address.\n");
1092 switch (ar->target_type) {
1093 case TARGET_TYPE_AR6003:
1094 board_data_size = AR6003_BOARD_DATA_SZ;
1095 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1097 case TARGET_TYPE_AR6004:
1098 board_data_size = AR6004_BOARD_DATA_SZ;
1099 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1107 if (board_ext_address &&
1108 ar->fw_board_len == (board_data_size + board_ext_data_size)) {
1110 /* write extended board data */
1111 ath6kl_dbg(ATH6KL_DBG_BOOT,
1112 "writing extended board data to 0x%x (%d B)\n",
1113 board_ext_address, board_ext_data_size);
1115 ret = ath6kl_bmi_write(ar, board_ext_address,
1116 ar->fw_board + board_data_size,
1117 board_ext_data_size);
1119 ath6kl_err("Failed to write extended board data: %d\n",
1124 /* record that extended board data is initialized */
1125 param = (board_ext_data_size << 16) | 1;
1127 ath6kl_bmi_write(ar,
1128 ath6kl_get_hi_item_addr(ar,
1129 HI_ITEM(hi_board_ext_data_config)),
1130 (unsigned char *) ¶m, 4);
1133 if (ar->fw_board_len < board_data_size) {
1134 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1139 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1140 board_address, board_data_size);
1142 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
1146 ath6kl_err("Board file bmi write failed: %d\n", ret);
1150 /* record the fact that Board Data IS initialized */
1152 ath6kl_bmi_write(ar,
1153 ath6kl_get_hi_item_addr(ar,
1154 HI_ITEM(hi_board_data_initialized)),
1160 static int ath6kl_upload_otp(struct ath6kl *ar)
1163 bool from_hw = false;
1166 if (ar->fw_otp == NULL)
1169 address = ar->hw.app_load_addr;
1171 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
1174 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1177 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1181 /* read firmware start address */
1182 ret = ath6kl_bmi_read(ar,
1183 ath6kl_get_hi_item_addr(ar,
1184 HI_ITEM(hi_app_start)),
1185 (u8 *) &address, sizeof(address));
1188 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1192 if (ar->hw.app_start_override_addr == 0) {
1193 ar->hw.app_start_override_addr = address;
1197 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1198 from_hw ? " (from hw)" : "",
1199 ar->hw.app_start_override_addr);
1201 /* execute the OTP code */
1202 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1203 ar->hw.app_start_override_addr);
1205 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m);
1210 static int ath6kl_upload_firmware(struct ath6kl *ar)
1215 if (WARN_ON(ar->fw == NULL))
1218 address = ar->hw.app_load_addr;
1220 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
1221 address, ar->fw_len);
1223 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1226 ath6kl_err("Failed to write firmware: %d\n", ret);
1231 * Set starting address for firmware
1232 * Don't need to setup app_start override addr on AR6004
1234 if (ar->target_type != TARGET_TYPE_AR6004) {
1235 address = ar->hw.app_start_override_addr;
1236 ath6kl_bmi_set_app_start(ar, address);
1241 static int ath6kl_upload_patch(struct ath6kl *ar)
1246 if (ar->fw_patch == NULL)
1249 address = ar->hw.dataset_patch_addr;
1251 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
1252 address, ar->fw_patch_len);
1254 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1256 ath6kl_err("Failed to write patch file: %d\n", ret);
1261 ath6kl_bmi_write(ar,
1262 ath6kl_get_hi_item_addr(ar,
1263 HI_ITEM(hi_dset_list_head)),
1264 (unsigned char *) ¶m, 4);
1269 static int ath6kl_init_upload(struct ath6kl *ar)
1271 u32 param, options, sleep, address;
1274 if (ar->target_type != TARGET_TYPE_AR6003 &&
1275 ar->target_type != TARGET_TYPE_AR6004)
1278 /* temporarily disable system sleep */
1279 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1280 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1286 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1287 status = ath6kl_bmi_reg_write(ar, address, param);
1291 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1292 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1298 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1299 status = ath6kl_bmi_reg_write(ar, address, param);
1303 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1306 /* program analog PLL register */
1307 /* no need to control 40/44MHz clock on AR6004 */
1308 if (ar->target_type != TARGET_TYPE_AR6004) {
1309 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1315 /* Run at 80/88MHz by default */
1316 param = SM(CPU_CLOCK_STANDARD, 1);
1318 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1319 status = ath6kl_bmi_reg_write(ar, address, param);
1325 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1326 param = SM(LPO_CAL_ENABLE, 1);
1327 status = ath6kl_bmi_reg_write(ar, address, param);
1331 /* WAR to avoid SDIO CRC err */
1332 if (ar->version.target_ver == AR6003_HW_2_0_VERSION) {
1333 ath6kl_err("temporary war to avoid sdio crc error\n");
1337 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1338 status = ath6kl_bmi_reg_write(ar, address, param);
1342 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1343 status = ath6kl_bmi_reg_write(ar, address, param);
1347 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1348 status = ath6kl_bmi_reg_write(ar, address, param);
1352 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1353 status = ath6kl_bmi_reg_write(ar, address, param);
1358 /* write EEPROM data to Target RAM */
1359 status = ath6kl_upload_board_file(ar);
1363 /* transfer One time Programmable data */
1364 status = ath6kl_upload_otp(ar);
1368 /* Download Target firmware */
1369 status = ath6kl_upload_firmware(ar);
1373 status = ath6kl_upload_patch(ar);
1377 /* Restore system sleep */
1378 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1379 status = ath6kl_bmi_reg_write(ar, address, sleep);
1383 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1384 param = options | 0x20;
1385 status = ath6kl_bmi_reg_write(ar, address, param);
1392 static int ath6kl_init_hw_params(struct ath6kl *ar)
1394 const struct ath6kl_hw *hw;
1397 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
1400 if (hw->id == ar->version.target_ver)
1404 if (i == ARRAY_SIZE(hw_list)) {
1405 ath6kl_err("Unsupported hardware version: 0x%x\n",
1406 ar->version.target_ver);
1412 ath6kl_dbg(ATH6KL_DBG_BOOT,
1413 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1414 ar->version.target_ver, ar->target_type,
1415 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1416 ath6kl_dbg(ATH6KL_DBG_BOOT,
1417 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1418 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1419 ar->hw.reserved_ram_size);
1420 ath6kl_dbg(ATH6KL_DBG_BOOT,
1421 "refclk_hz %d uarttx_pin %d",
1422 ar->hw.refclk_hz, ar->hw.uarttx_pin);
1427 static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
1430 case ATH6KL_HIF_TYPE_SDIO:
1432 case ATH6KL_HIF_TYPE_USB:
1439 int ath6kl_init_hw_start(struct ath6kl *ar)
1444 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
1446 ret = ath6kl_hif_power_on(ar);
1450 ret = ath6kl_configure_target(ar);
1454 ret = ath6kl_init_upload(ar);
1458 /* Do we need to finish the BMI phase */
1459 /* FIXME: return error from ath6kl_bmi_done() */
1460 if (ath6kl_bmi_done(ar)) {
1466 * The reason we have to wait for the target here is that the
1467 * driver layer has to init BMI in order to set the host block
1470 if (ath6kl_htc_wait_target(ar->htc_target)) {
1475 if (ath6kl_init_service_ep(ar)) {
1477 goto err_cleanup_scatter;
1480 /* setup credit distribution */
1481 ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
1484 ret = ath6kl_htc_start(ar->htc_target);
1486 /* FIXME: call this */
1487 ath6kl_cookie_cleanup(ar);
1488 goto err_cleanup_scatter;
1491 /* Wait for Wmi event to be ready */
1492 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1497 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1500 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
1501 ath6kl_info("%s %s fw %s api %d%s\n",
1503 ath6kl_init_get_hif_name(ar->hif_type),
1504 ar->wiphy->fw_version,
1506 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
1509 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1510 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1511 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1516 if (!timeleft || signal_pending(current)) {
1517 ath6kl_err("wmi is not ready or wait was interrupted\n");
1522 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1524 /* communicate the wmi protocol verision to the target */
1525 /* FIXME: return error */
1526 if ((ath6kl_set_host_app_area(ar)) != 0)
1527 ath6kl_err("unable to set the host app area\n");
1529 for (i = 0; i < ar->vif_max; i++) {
1530 ret = ath6kl_target_config_wlan_params(ar, i);
1535 ar->state = ATH6KL_STATE_ON;
1540 ath6kl_htc_stop(ar->htc_target);
1541 err_cleanup_scatter:
1542 ath6kl_hif_cleanup_scatter(ar);
1544 ath6kl_hif_power_off(ar);
1549 int ath6kl_init_hw_stop(struct ath6kl *ar)
1553 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
1555 ath6kl_htc_stop(ar->htc_target);
1557 ath6kl_hif_stop(ar);
1559 ath6kl_bmi_reset(ar);
1561 ret = ath6kl_hif_power_off(ar);
1563 ath6kl_warn("failed to power off hif: %d\n", ret);
1565 ar->state = ATH6KL_STATE_OFF;
1570 int ath6kl_core_init(struct ath6kl *ar)
1572 struct ath6kl_bmi_target_info targ_info;
1573 struct net_device *ndev;
1576 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1580 ret = ath6kl_bmi_init(ar);
1585 * Turn on power to get hardware (target) version and leave power
1586 * on delibrately as we will boot the hardware anyway within few
1589 ret = ath6kl_hif_power_on(ar);
1591 goto err_bmi_cleanup;
1593 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1597 ar->version.target_ver = le32_to_cpu(targ_info.version);
1598 ar->target_type = le32_to_cpu(targ_info.type);
1599 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
1601 ret = ath6kl_init_hw_params(ar);
1605 ar->htc_target = ath6kl_htc_create(ar);
1607 if (!ar->htc_target) {
1612 ret = ath6kl_fetch_firmwares(ar);
1614 goto err_htc_cleanup;
1616 /* FIXME: we should free all firmwares in the error cases below */
1618 /* Indicate that WMI is enabled (although not ready yet) */
1619 set_bit(WMI_ENABLED, &ar->flag);
1620 ar->wmi = ath6kl_wmi_init(ar);
1622 ath6kl_err("failed to initialize wmi\n");
1624 goto err_htc_cleanup;
1627 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1629 ret = ath6kl_register_ieee80211_hw(ar);
1631 goto err_node_cleanup;
1633 ret = ath6kl_debug_init(ar);
1635 wiphy_unregister(ar->wiphy);
1636 goto err_node_cleanup;
1639 for (i = 0; i < ar->vif_max; i++)
1640 ar->avail_idx_map |= BIT(i);
1644 /* Add an initial station interface */
1645 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
1651 ath6kl_err("Failed to instantiate a network device\n");
1653 wiphy_unregister(ar->wiphy);
1654 goto err_debug_init;
1658 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1659 __func__, ndev->name, ndev, ar);
1661 /* setup access class priority mappings */
1662 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1663 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1664 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1665 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1667 /* give our connected endpoints some buffers */
1668 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1669 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1671 /* allocate some buffers that handle larger AMSDU frames */
1672 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1674 ath6kl_cookie_init(ar);
1676 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1677 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1679 if (suspend_cutpower)
1680 ar->conf_flags |= ATH6KL_CONF_SUSPEND_CUTPOWER;
1682 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
1683 WIPHY_FLAG_HAVE_AP_SME |
1684 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
1685 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1687 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
1688 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
1690 ar->wiphy->probe_resp_offload =
1691 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1692 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1693 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
1694 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
1696 set_bit(FIRST_BOOT, &ar->flag);
1698 ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1700 ret = ath6kl_init_hw_start(ar);
1702 ath6kl_err("Failed to start hardware: %d\n", ret);
1703 goto err_rxbuf_cleanup;
1707 * Set mac address which is received in ready event
1708 * FIXME: Move to ath6kl_interface_add()
1710 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
1715 ath6kl_htc_flush_rx_buf(ar->htc_target);
1716 ath6kl_cleanup_amsdu_rxbufs(ar);
1718 ath6kl_deinit_if_data(netdev_priv(ndev));
1720 wiphy_unregister(ar->wiphy);
1722 ath6kl_debug_cleanup(ar);
1724 ath6kl_wmi_shutdown(ar->wmi);
1725 clear_bit(WMI_ENABLED, &ar->flag);
1728 ath6kl_htc_cleanup(ar->htc_target);
1730 ath6kl_hif_power_off(ar);
1732 ath6kl_bmi_cleanup(ar);
1734 destroy_workqueue(ar->ath6kl_wq);
1739 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
1741 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1744 netif_stop_queue(vif->ndev);
1746 clear_bit(WLAN_ENABLED, &vif->flags);
1749 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1750 test_bit(CONNECT_PEND, &vif->flags);
1751 ath6kl_disconnect(vif);
1752 del_timer(&vif->disconnect_timer);
1755 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1756 (vif->nw_type & AP_NETWORK) ?
1757 bcast_mac : vif->bssid,
1761 if (vif->scan_req) {
1762 cfg80211_scan_done(vif->scan_req, true);
1763 vif->scan_req = NULL;
1767 void ath6kl_stop_txrx(struct ath6kl *ar)
1769 struct ath6kl_vif *vif, *tmp_vif;
1771 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1773 if (down_interruptible(&ar->sem)) {
1774 ath6kl_err("down_interruptible failed\n");
1778 spin_lock_bh(&ar->list_lock);
1779 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1780 list_del(&vif->list);
1781 spin_unlock_bh(&ar->list_lock);
1782 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1784 ath6kl_deinit_if_data(vif);
1786 spin_lock_bh(&ar->list_lock);
1788 spin_unlock_bh(&ar->list_lock);
1790 clear_bit(WMI_READY, &ar->flag);
1793 * After wmi_shudown all WMI events will be dropped. We
1794 * need to cleanup the buffers allocated in AP mode and
1795 * give disconnect notification to stack, which usually
1796 * happens in the disconnect_event. Simulate the disconnect
1797 * event by calling the function directly. Sometimes
1798 * disconnect_event will be received when the debug logs
1801 ath6kl_wmi_shutdown(ar->wmi);
1803 clear_bit(WMI_ENABLED, &ar->flag);
1804 if (ar->htc_target) {
1805 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1806 ath6kl_htc_stop(ar->htc_target);
1810 * Try to reset the device if we can. The driver may have been
1811 * configure NOT to reset the target during a debug session.
1813 ath6kl_dbg(ATH6KL_DBG_TRC,
1814 "attempting to reset target on instance destroy\n");
1815 ath6kl_reset_device(ar, ar->target_type, true, true);
1817 clear_bit(WLAN_ENABLED, &ar->flag);