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,
72 .testscript_addr = 0x57ef74,
75 .dir = AR6003_HW_2_1_1_FW_DIR,
76 .otp = AR6003_HW_2_1_1_OTP_FILE,
77 .fw = AR6003_HW_2_1_1_FIRMWARE_FILE,
78 .tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
79 .patch = AR6003_HW_2_1_1_PATCH_FILE,
80 .utf = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE,
81 .testscript = AR6003_HW_2_1_1_TESTSCRIPT_FILE,
84 .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
85 .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
88 .id = AR6004_HW_1_0_VERSION,
89 .name = "ar6004 hw 1.0",
90 .dataset_patch_addr = 0x57e884,
91 .app_load_addr = 0x1234,
92 .board_ext_data_addr = 0x437000,
93 .reserved_ram_size = 19456,
94 .board_addr = 0x433900,
95 .refclk_hz = 26000000,
99 .dir = AR6004_HW_1_0_FW_DIR,
100 .fw = AR6004_HW_1_0_FIRMWARE_FILE,
103 .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
104 .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
107 .id = AR6004_HW_1_1_VERSION,
108 .name = "ar6004 hw 1.1",
109 .dataset_patch_addr = 0x57e884,
110 .app_load_addr = 0x1234,
111 .board_ext_data_addr = 0x437000,
112 .reserved_ram_size = 11264,
113 .board_addr = 0x43d400,
114 .refclk_hz = 40000000,
118 .dir = AR6004_HW_1_1_FW_DIR,
119 .fw = AR6004_HW_1_1_FIRMWARE_FILE,
122 .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
123 .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
128 * Include definitions here that can be used to tune the WLAN module
129 * behavior. Different customers can tune the behavior as per their needs,
134 * This configuration item enable/disable keepalive support.
135 * Keepalive support: In the absence of any data traffic to AP, null
136 * frames will be sent to the AP at periodic interval, to keep the association
137 * active. This configuration item defines the periodic interval.
138 * Use value of zero to disable keepalive support
139 * Default: 60 seconds
141 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
144 * This configuration item sets the value of disconnect timeout
145 * Firmware delays sending the disconnec event to the host for this
146 * timeout after is gets disconnected from the current AP.
147 * If the firmware successly roams within the disconnect timeout
148 * it sends a new connect event
150 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
153 #define ATH6KL_DATA_OFFSET 64
154 struct sk_buff *ath6kl_buf_alloc(int size)
159 /* Add chacheline space at front and back of buffer */
160 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
161 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
162 skb = dev_alloc_skb(size + reserved);
165 skb_reserve(skb, reserved - L1_CACHE_BYTES);
169 void ath6kl_init_profile_info(struct ath6kl_vif *vif)
172 memset(vif->ssid, 0, sizeof(vif->ssid));
174 vif->dot11_auth_mode = OPEN_AUTH;
175 vif->auth_mode = NONE_AUTH;
176 vif->prwise_crypto = NONE_CRYPT;
177 vif->prwise_crypto_len = 0;
178 vif->grp_crypto = NONE_CRYPT;
179 vif->grp_crypto_len = 0;
180 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
181 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
182 memset(vif->bssid, 0, sizeof(vif->bssid));
186 static int ath6kl_set_host_app_area(struct ath6kl *ar)
189 struct host_app_area host_app_area;
191 /* Fetch the address of the host_app_area_s
192 * instance in the host interest area */
193 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
194 address = TARG_VTOP(ar->target_type, address);
196 if (ath6kl_diag_read32(ar, address, &data))
199 address = TARG_VTOP(ar->target_type, data);
200 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
201 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
202 sizeof(struct host_app_area)))
208 static inline void set_ac2_ep_map(struct ath6kl *ar,
210 enum htc_endpoint_id ep)
212 ar->ac2ep_map[ac] = ep;
213 ar->ep2ac_map[ep] = ac;
216 /* connect to a service */
217 static int ath6kl_connectservice(struct ath6kl *ar,
218 struct htc_service_connect_req *con_req,
222 struct htc_service_connect_resp response;
224 memset(&response, 0, sizeof(response));
226 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
228 ath6kl_err("failed to connect to %s service status:%d\n",
233 switch (con_req->svc_id) {
234 case WMI_CONTROL_SVC:
235 if (test_bit(WMI_ENABLED, &ar->flag))
236 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
237 ar->ctrl_ep = response.endpoint;
239 case WMI_DATA_BE_SVC:
240 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
242 case WMI_DATA_BK_SVC:
243 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
245 case WMI_DATA_VI_SVC:
246 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
248 case WMI_DATA_VO_SVC:
249 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
252 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
259 static int ath6kl_init_service_ep(struct ath6kl *ar)
261 struct htc_service_connect_req connect;
263 memset(&connect, 0, sizeof(connect));
265 /* these fields are the same for all service endpoints */
266 connect.ep_cb.rx = ath6kl_rx;
267 connect.ep_cb.rx_refill = ath6kl_rx_refill;
268 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
271 * Set the max queue depth so that our ath6kl_tx_queue_full handler
274 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
275 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
276 if (!connect.ep_cb.rx_refill_thresh)
277 connect.ep_cb.rx_refill_thresh++;
279 /* connect to control service */
280 connect.svc_id = WMI_CONTROL_SVC;
281 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
284 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
287 * Limit the HTC message size on the send path, although e can
288 * receive A-MSDU frames of 4K, we will only send ethernet-sized
289 * (802.3) frames on the send path.
291 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
294 * To reduce the amount of committed memory for larger A_MSDU
295 * frames, use the recv-alloc threshold mechanism for larger
298 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
299 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
302 * For the remaining data services set the connection flag to
303 * reduce dribbling, if configured to do so.
305 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
306 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
307 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
309 connect.svc_id = WMI_DATA_BE_SVC;
311 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
314 /* connect to back-ground map this to WMI LOW_PRI */
315 connect.svc_id = WMI_DATA_BK_SVC;
316 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
319 /* connect to Video service, map this to to HI PRI */
320 connect.svc_id = WMI_DATA_VI_SVC;
321 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
325 * Connect to VO service, this is currently not mapped to a WMI
326 * priority stream due to historical reasons. WMI originally
327 * defined 3 priorities over 3 mailboxes We can change this when
328 * WMI is reworked so that priorities are not dependent on
331 connect.svc_id = WMI_DATA_VO_SVC;
332 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
338 void ath6kl_init_control_info(struct ath6kl_vif *vif)
340 ath6kl_init_profile_info(vif);
341 vif->def_txkey_index = 0;
342 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
347 * Set HTC/Mbox operational parameters, this can only be called when the
348 * target is in the BMI phase.
350 static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
356 blk_size = ar->mbox_info.block_size;
359 blk_size |= ((u32)htc_ctrl_buf) << 16;
361 /* set the host interest area for the block size */
362 status = ath6kl_bmi_write(ar,
363 ath6kl_get_hi_item_addr(ar,
364 HI_ITEM(hi_mbox_io_block_sz)),
368 ath6kl_err("bmi_write_memory for IO block size failed\n");
372 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
374 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
376 if (mbox_isr_yield_val) {
377 /* set the host interest area for the mbox ISR yield limit */
378 status = ath6kl_bmi_write(ar,
379 ath6kl_get_hi_item_addr(ar,
380 HI_ITEM(hi_mbox_isr_yield_limit)),
381 (u8 *)&mbox_isr_yield_val,
384 ath6kl_err("bmi_write_memory for yield limit failed\n");
393 static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
399 * Configure the device for rx dot11 header rules. "0,0" are the
400 * default values. Required if checksum offload is needed. Set
401 * RxMetaVersion to 2.
403 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
404 ar->rx_meta_ver, 0, 0)) {
405 ath6kl_err("unable to set the rx frame format\n");
409 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
410 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
411 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
412 ath6kl_err("unable to set power save fail event policy\n");
416 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
417 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
418 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
419 ath6kl_err("unable to set barker preamble policy\n");
423 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
424 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
425 ath6kl_err("unable to set keep alive interval\n");
429 if (ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
430 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
431 ath6kl_err("unable to set disconnect timeout\n");
435 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
436 if (ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED)) {
437 ath6kl_err("unable to set txop bursting\n");
441 if (ar->p2p && (ar->vif_max == 1 || idx)) {
442 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
443 P2P_FLAG_CAPABILITIES_REQ |
444 P2P_FLAG_MACADDR_REQ |
445 P2P_FLAG_HMODEL_REQ);
447 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
448 "capabilities (%d) - assuming P2P not "
454 if (ar->p2p && (ar->vif_max == 1 || idx)) {
455 /* Enable Probe Request reporting for P2P */
456 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
458 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
459 "Request reporting (%d)\n", ret);
466 int ath6kl_configure_target(struct ath6kl *ar)
468 u32 param, ram_reserved_size;
469 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
472 param = !!(ar->conf_flags & ATH6KL_CONF_UART_DEBUG);
473 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
474 HI_ITEM(hi_serial_enable)), (u8 *)¶m, 4)) {
475 ath6kl_err("bmi_write_memory for uart debug failed\n");
480 * Note: Even though the firmware interface type is
481 * chosen as BSS_STA for all three interfaces, can
482 * be configured to IBSS/AP as long as the fw submode
483 * remains normal mode (0 - AP, STA and IBSS). But
484 * due to an target assert in firmware only one interface is
485 * configured for now.
487 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
489 for (i = 0; i < ar->vif_max; i++)
490 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
493 * By default, submodes :
494 * vif[0] - AP/STA/IBSS
495 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
496 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
499 for (i = 0; i < ar->max_norm_iface; i++)
500 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
501 (i * HI_OPTION_FW_SUBMODE_BITS);
503 for (i = ar->max_norm_iface; i < ar->vif_max; i++)
504 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
505 (i * HI_OPTION_FW_SUBMODE_BITS);
507 if (ar->p2p && ar->vif_max == 1)
508 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
510 param = HTC_PROTOCOL_VERSION;
511 if (ath6kl_bmi_write(ar,
512 ath6kl_get_hi_item_addr(ar,
513 HI_ITEM(hi_app_host_interest)),
514 (u8 *)¶m, 4) != 0) {
515 ath6kl_err("bmi_write_memory for htc version failed\n");
519 /* set the firmware mode to STA/IBSS/AP */
522 if (ath6kl_bmi_read(ar,
523 ath6kl_get_hi_item_addr(ar,
524 HI_ITEM(hi_option_flag)),
525 (u8 *)¶m, 4) != 0) {
526 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
530 param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
531 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
532 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
534 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
535 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
537 if (ath6kl_bmi_write(ar,
538 ath6kl_get_hi_item_addr(ar,
539 HI_ITEM(hi_option_flag)),
542 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
546 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
549 * Hardcode the address use for the extended board data
550 * Ideally this should be pre-allocate by the OS at boot time
551 * But since it is a new feature and board data is loaded
552 * at init time, we have to workaround this from host.
553 * It is difficult to patch the firmware boot code,
554 * but possible in theory.
557 param = ar->hw.board_ext_data_addr;
558 ram_reserved_size = ar->hw.reserved_ram_size;
560 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
561 HI_ITEM(hi_board_ext_data)),
562 (u8 *)¶m, 4) != 0) {
563 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
567 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
568 HI_ITEM(hi_end_ram_reserve_sz)),
569 (u8 *)&ram_reserved_size, 4) != 0) {
570 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
574 /* set the block size for the target */
575 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
576 /* use default number of control buffers */
579 /* Configure GPIO AR600x UART */
580 param = ar->hw.uarttx_pin;
581 status = ath6kl_bmi_write(ar,
582 ath6kl_get_hi_item_addr(ar,
583 HI_ITEM(hi_dbg_uart_txpin)),
588 /* Configure target refclk_hz */
589 param = ar->hw.refclk_hz;
590 status = ath6kl_bmi_write(ar,
591 ath6kl_get_hi_item_addr(ar,
592 HI_ITEM(hi_refclk_hz)),
600 void ath6kl_core_free(struct ath6kl *ar)
602 wiphy_free(ar->wiphy);
605 void ath6kl_core_cleanup(struct ath6kl *ar)
607 ath6kl_hif_power_off(ar);
609 destroy_workqueue(ar->ath6kl_wq);
612 ath6kl_htc_cleanup(ar->htc_target);
614 ath6kl_cookie_cleanup(ar);
616 ath6kl_cleanup_amsdu_rxbufs(ar);
618 ath6kl_bmi_cleanup(ar);
620 ath6kl_debug_cleanup(ar);
626 kfree(ar->fw_testscript);
628 ath6kl_cfg80211_cleanup(ar);
631 /* firmware upload */
632 static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
633 u8 **fw, size_t *fw_len)
635 const struct firmware *fw_entry;
638 ret = request_firmware(&fw_entry, filename, ar->dev);
642 *fw_len = fw_entry->size;
643 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
648 release_firmware(fw_entry);
655 * Check the device tree for a board-id and use it to construct
656 * the pathname to the firmware file. Used (for now) to find a
657 * fallback to the "bdata.bin" file--typically a symlink to the
658 * appropriate board-specific file.
660 static bool check_device_tree(struct ath6kl *ar)
662 static const char *board_id_prop = "atheros,board-id";
663 struct device_node *node;
664 char board_filename[64];
665 const char *board_id;
668 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
669 board_id = of_get_property(node, board_id_prop, NULL);
670 if (board_id == NULL) {
671 ath6kl_warn("No \"%s\" property on %s node.\n",
672 board_id_prop, node->name);
675 snprintf(board_filename, sizeof(board_filename),
676 "%s/bdata.%s.bin", ar->hw.fw.dir, board_id);
678 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
681 ath6kl_err("Failed to get DT board file %s: %d\n",
682 board_filename, ret);
690 static bool check_device_tree(struct ath6kl *ar)
694 #endif /* CONFIG_OF */
696 static int ath6kl_fetch_board_file(struct ath6kl *ar)
698 const char *filename;
701 if (ar->fw_board != NULL)
704 if (WARN_ON(ar->hw.fw_board == NULL))
707 filename = ar->hw.fw_board;
709 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
712 /* managed to get proper board file */
716 if (check_device_tree(ar)) {
717 /* got board file from device tree */
721 /* there was no proper board file, try to use default instead */
722 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
725 filename = ar->hw.fw_default_board;
727 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
730 ath6kl_err("Failed to get default board file %s: %d\n",
735 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
736 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
741 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
746 if (ar->fw_otp != NULL)
749 if (ar->hw.fw.otp == NULL) {
750 ath6kl_dbg(ATH6KL_DBG_BOOT,
751 "no OTP file configured for this hw\n");
755 snprintf(filename, sizeof(filename), "%s/%s",
756 ar->hw.fw.dir, ar->hw.fw.otp);
758 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
761 ath6kl_err("Failed to get OTP file %s: %d\n",
769 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
778 ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n",
781 if (ar->hw.fw.utf == NULL) {
782 ath6kl_warn("testmode 2 not supported\n");
786 snprintf(filename, sizeof(filename), "%s/%s",
787 ar->hw.fw.dir, ar->hw.fw.utf);
789 if (ar->hw.fw.tcmd == NULL) {
790 ath6kl_warn("testmode 1 not supported\n");
794 snprintf(filename, sizeof(filename), "%s/%s",
795 ar->hw.fw.dir, ar->hw.fw.tcmd);
797 set_bit(TESTMODE, &ar->flag);
802 /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
803 if (WARN_ON(ar->hw.fw.fw == NULL))
806 snprintf(filename, sizeof(filename), "%s/%s",
807 ar->hw.fw.dir, ar->hw.fw.fw);
810 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
812 ath6kl_err("Failed to get firmware file %s: %d\n",
820 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
825 if (ar->fw_patch != NULL)
828 if (ar->hw.fw.patch == NULL)
831 snprintf(filename, sizeof(filename), "%s/%s",
832 ar->hw.fw.dir, ar->hw.fw.patch);
834 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
837 ath6kl_err("Failed to get patch file %s: %d\n",
845 static int ath6kl_fetch_testscript_file(struct ath6kl *ar)
853 if (ar->fw_testscript != NULL)
856 if (ar->hw.fw.testscript == NULL)
859 snprintf(filename, sizeof(filename), "%s/%s",
860 ar->hw.fw.dir, ar->hw.fw.testscript);
862 ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript,
863 &ar->fw_testscript_len);
865 ath6kl_err("Failed to get testscript file %s: %d\n",
873 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
877 ret = ath6kl_fetch_otp_file(ar);
881 ret = ath6kl_fetch_fw_file(ar);
885 ret = ath6kl_fetch_patch_file(ar);
889 ret = ath6kl_fetch_testscript_file(ar);
896 static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
898 size_t magic_len, len, ie_len;
899 const struct firmware *fw;
900 struct ath6kl_fw_ie *hdr;
903 int ret, ie_id, i, index, bit;
906 snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
908 ret = request_firmware(&fw, filename, ar->dev);
915 /* magic also includes the null byte, check that as well */
916 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
918 if (len < magic_len) {
923 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
932 while (len > sizeof(struct ath6kl_fw_ie)) {
933 /* hdr is unaligned! */
934 hdr = (struct ath6kl_fw_ie *) data;
936 ie_id = le32_to_cpup(&hdr->id);
937 ie_len = le32_to_cpup(&hdr->len);
940 data += sizeof(*hdr);
948 case ATH6KL_FW_IE_OTP_IMAGE:
949 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
952 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
954 if (ar->fw_otp == NULL) {
959 ar->fw_otp_len = ie_len;
961 case ATH6KL_FW_IE_FW_IMAGE:
962 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
965 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
967 if (ar->fw == NULL) {
974 case ATH6KL_FW_IE_PATCH_IMAGE:
975 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
978 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
980 if (ar->fw_patch == NULL) {
985 ar->fw_patch_len = ie_len;
987 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
988 val = (__le32 *) data;
989 ar->hw.reserved_ram_size = le32_to_cpup(val);
991 ath6kl_dbg(ATH6KL_DBG_BOOT,
992 "found reserved ram size ie 0x%d\n",
993 ar->hw.reserved_ram_size);
995 case ATH6KL_FW_IE_CAPABILITIES:
996 if (ie_len < DIV_ROUND_UP(ATH6KL_FW_CAPABILITY_MAX, 8))
999 ath6kl_dbg(ATH6KL_DBG_BOOT,
1000 "found firmware capabilities ie (%zd B)\n",
1003 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
1007 if (data[index] & (1 << bit))
1008 __set_bit(i, ar->fw_capabilities);
1011 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
1012 ar->fw_capabilities,
1013 sizeof(ar->fw_capabilities));
1015 case ATH6KL_FW_IE_PATCH_ADDR:
1016 if (ie_len != sizeof(*val))
1019 val = (__le32 *) data;
1020 ar->hw.dataset_patch_addr = le32_to_cpup(val);
1022 ath6kl_dbg(ATH6KL_DBG_BOOT,
1023 "found patch address ie 0x%x\n",
1024 ar->hw.dataset_patch_addr);
1026 case ATH6KL_FW_IE_BOARD_ADDR:
1027 if (ie_len != sizeof(*val))
1030 val = (__le32 *) data;
1031 ar->hw.board_addr = le32_to_cpup(val);
1033 ath6kl_dbg(ATH6KL_DBG_BOOT,
1034 "found board address ie 0x%x\n",
1037 case ATH6KL_FW_IE_VIF_MAX:
1038 if (ie_len != sizeof(*val))
1041 val = (__le32 *) data;
1042 ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
1045 if (ar->vif_max > 1 && !ar->p2p)
1046 ar->max_norm_iface = 2;
1048 ath6kl_dbg(ATH6KL_DBG_BOOT,
1049 "found vif max ie %d\n", ar->vif_max);
1052 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
1053 le32_to_cpup(&hdr->id));
1063 release_firmware(fw);
1068 static int ath6kl_fetch_firmwares(struct ath6kl *ar)
1072 ret = ath6kl_fetch_board_file(ar);
1076 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
1082 ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
1088 ret = ath6kl_fetch_fw_api1(ar);
1095 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
1100 static int ath6kl_upload_board_file(struct ath6kl *ar)
1102 u32 board_address, board_ext_address, param;
1103 u32 board_data_size, board_ext_data_size;
1106 if (WARN_ON(ar->fw_board == NULL))
1110 * Determine where in Target RAM to write Board Data.
1111 * For AR6004, host determine Target RAM address for
1112 * writing board data.
1114 if (ar->hw.board_addr != 0) {
1115 board_address = ar->hw.board_addr;
1116 ath6kl_bmi_write(ar,
1117 ath6kl_get_hi_item_addr(ar,
1118 HI_ITEM(hi_board_data)),
1119 (u8 *) &board_address, 4);
1122 ath6kl_get_hi_item_addr(ar,
1123 HI_ITEM(hi_board_data)),
1124 (u8 *) &board_address, 4);
1127 /* determine where in target ram to write extended board data */
1129 ath6kl_get_hi_item_addr(ar,
1130 HI_ITEM(hi_board_ext_data)),
1131 (u8 *) &board_ext_address, 4);
1133 if (ar->target_type == TARGET_TYPE_AR6003 &&
1134 board_ext_address == 0) {
1135 ath6kl_err("Failed to get board file target address.\n");
1139 switch (ar->target_type) {
1140 case TARGET_TYPE_AR6003:
1141 board_data_size = AR6003_BOARD_DATA_SZ;
1142 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1144 case TARGET_TYPE_AR6004:
1145 board_data_size = AR6004_BOARD_DATA_SZ;
1146 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1154 if (board_ext_address &&
1155 ar->fw_board_len == (board_data_size + board_ext_data_size)) {
1157 /* write extended board data */
1158 ath6kl_dbg(ATH6KL_DBG_BOOT,
1159 "writing extended board data to 0x%x (%d B)\n",
1160 board_ext_address, board_ext_data_size);
1162 ret = ath6kl_bmi_write(ar, board_ext_address,
1163 ar->fw_board + board_data_size,
1164 board_ext_data_size);
1166 ath6kl_err("Failed to write extended board data: %d\n",
1171 /* record that extended board data is initialized */
1172 param = (board_ext_data_size << 16) | 1;
1174 ath6kl_bmi_write(ar,
1175 ath6kl_get_hi_item_addr(ar,
1176 HI_ITEM(hi_board_ext_data_config)),
1177 (unsigned char *) ¶m, 4);
1180 if (ar->fw_board_len < board_data_size) {
1181 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1186 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1187 board_address, board_data_size);
1189 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
1193 ath6kl_err("Board file bmi write failed: %d\n", ret);
1197 /* record the fact that Board Data IS initialized */
1199 ath6kl_bmi_write(ar,
1200 ath6kl_get_hi_item_addr(ar,
1201 HI_ITEM(hi_board_data_initialized)),
1207 static int ath6kl_upload_otp(struct ath6kl *ar)
1210 bool from_hw = false;
1213 if (ar->fw_otp == NULL)
1216 address = ar->hw.app_load_addr;
1218 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
1221 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1224 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1228 /* read firmware start address */
1229 ret = ath6kl_bmi_read(ar,
1230 ath6kl_get_hi_item_addr(ar,
1231 HI_ITEM(hi_app_start)),
1232 (u8 *) &address, sizeof(address));
1235 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1239 if (ar->hw.app_start_override_addr == 0) {
1240 ar->hw.app_start_override_addr = address;
1244 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1245 from_hw ? " (from hw)" : "",
1246 ar->hw.app_start_override_addr);
1248 /* execute the OTP code */
1249 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1250 ar->hw.app_start_override_addr);
1252 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, ¶m);
1257 static int ath6kl_upload_firmware(struct ath6kl *ar)
1262 if (WARN_ON(ar->fw == NULL))
1265 address = ar->hw.app_load_addr;
1267 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
1268 address, ar->fw_len);
1270 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1273 ath6kl_err("Failed to write firmware: %d\n", ret);
1278 * Set starting address for firmware
1279 * Don't need to setup app_start override addr on AR6004
1281 if (ar->target_type != TARGET_TYPE_AR6004) {
1282 address = ar->hw.app_start_override_addr;
1283 ath6kl_bmi_set_app_start(ar, address);
1288 static int ath6kl_upload_patch(struct ath6kl *ar)
1293 if (ar->fw_patch == NULL)
1296 address = ar->hw.dataset_patch_addr;
1298 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
1299 address, ar->fw_patch_len);
1301 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1303 ath6kl_err("Failed to write patch file: %d\n", ret);
1308 ath6kl_bmi_write(ar,
1309 ath6kl_get_hi_item_addr(ar,
1310 HI_ITEM(hi_dset_list_head)),
1311 (unsigned char *) ¶m, 4);
1316 static int ath6kl_upload_testscript(struct ath6kl *ar)
1324 if (ar->fw_testscript == NULL)
1327 address = ar->hw.testscript_addr;
1329 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n",
1330 address, ar->fw_testscript_len);
1332 ret = ath6kl_bmi_write(ar, address, ar->fw_testscript,
1333 ar->fw_testscript_len);
1335 ath6kl_err("Failed to write testscript file: %d\n", ret);
1340 ath6kl_bmi_write(ar,
1341 ath6kl_get_hi_item_addr(ar,
1342 HI_ITEM(hi_ota_testscript)),
1343 (unsigned char *) ¶m, 4);
1346 ath6kl_bmi_write(ar,
1347 ath6kl_get_hi_item_addr(ar,
1348 HI_ITEM(hi_end_ram_reserve_sz)),
1349 (unsigned char *) ¶m, 4);
1352 ath6kl_bmi_write(ar,
1353 ath6kl_get_hi_item_addr(ar,
1354 HI_ITEM(hi_test_apps_related)),
1355 (unsigned char *) ¶m, 4);
1360 static int ath6kl_init_upload(struct ath6kl *ar)
1362 u32 param, options, sleep, address;
1365 if (ar->target_type != TARGET_TYPE_AR6003 &&
1366 ar->target_type != TARGET_TYPE_AR6004)
1369 /* temporarily disable system sleep */
1370 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1371 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1377 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1378 status = ath6kl_bmi_reg_write(ar, address, param);
1382 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1383 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1389 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1390 status = ath6kl_bmi_reg_write(ar, address, param);
1394 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1397 /* program analog PLL register */
1398 /* no need to control 40/44MHz clock on AR6004 */
1399 if (ar->target_type != TARGET_TYPE_AR6004) {
1400 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1406 /* Run at 80/88MHz by default */
1407 param = SM(CPU_CLOCK_STANDARD, 1);
1409 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1410 status = ath6kl_bmi_reg_write(ar, address, param);
1416 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1417 param = SM(LPO_CAL_ENABLE, 1);
1418 status = ath6kl_bmi_reg_write(ar, address, param);
1422 /* WAR to avoid SDIO CRC err */
1423 if (ar->version.target_ver == AR6003_HW_2_0_VERSION) {
1424 ath6kl_err("temporary war to avoid sdio crc error\n");
1428 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1429 status = ath6kl_bmi_reg_write(ar, address, param);
1433 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1434 status = ath6kl_bmi_reg_write(ar, address, param);
1438 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1439 status = ath6kl_bmi_reg_write(ar, address, param);
1443 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1444 status = ath6kl_bmi_reg_write(ar, address, param);
1449 /* write EEPROM data to Target RAM */
1450 status = ath6kl_upload_board_file(ar);
1454 /* transfer One time Programmable data */
1455 status = ath6kl_upload_otp(ar);
1459 /* Download Target firmware */
1460 status = ath6kl_upload_firmware(ar);
1464 status = ath6kl_upload_patch(ar);
1468 /* Download the test script */
1469 status = ath6kl_upload_testscript(ar);
1473 /* Restore system sleep */
1474 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1475 status = ath6kl_bmi_reg_write(ar, address, sleep);
1479 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1480 param = options | 0x20;
1481 status = ath6kl_bmi_reg_write(ar, address, param);
1488 static int ath6kl_init_hw_params(struct ath6kl *ar)
1490 const struct ath6kl_hw *hw;
1493 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
1496 if (hw->id == ar->version.target_ver)
1500 if (i == ARRAY_SIZE(hw_list)) {
1501 ath6kl_err("Unsupported hardware version: 0x%x\n",
1502 ar->version.target_ver);
1508 ath6kl_dbg(ATH6KL_DBG_BOOT,
1509 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1510 ar->version.target_ver, ar->target_type,
1511 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1512 ath6kl_dbg(ATH6KL_DBG_BOOT,
1513 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1514 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1515 ar->hw.reserved_ram_size);
1516 ath6kl_dbg(ATH6KL_DBG_BOOT,
1517 "refclk_hz %d uarttx_pin %d",
1518 ar->hw.refclk_hz, ar->hw.uarttx_pin);
1523 static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
1526 case ATH6KL_HIF_TYPE_SDIO:
1528 case ATH6KL_HIF_TYPE_USB:
1535 int ath6kl_init_hw_start(struct ath6kl *ar)
1540 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
1542 ret = ath6kl_hif_power_on(ar);
1546 ret = ath6kl_configure_target(ar);
1550 ret = ath6kl_init_upload(ar);
1554 /* Do we need to finish the BMI phase */
1555 /* FIXME: return error from ath6kl_bmi_done() */
1556 if (ath6kl_bmi_done(ar)) {
1562 * The reason we have to wait for the target here is that the
1563 * driver layer has to init BMI in order to set the host block
1566 if (ath6kl_htc_wait_target(ar->htc_target)) {
1571 if (ath6kl_init_service_ep(ar)) {
1573 goto err_cleanup_scatter;
1576 /* setup credit distribution */
1577 ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
1580 ret = ath6kl_htc_start(ar->htc_target);
1582 /* FIXME: call this */
1583 ath6kl_cookie_cleanup(ar);
1584 goto err_cleanup_scatter;
1587 /* Wait for Wmi event to be ready */
1588 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1593 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1596 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
1597 ath6kl_info("%s %s fw %s api %d%s\n",
1599 ath6kl_init_get_hif_name(ar->hif_type),
1600 ar->wiphy->fw_version,
1602 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
1605 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1606 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1607 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1612 if (!timeleft || signal_pending(current)) {
1613 ath6kl_err("wmi is not ready or wait was interrupted\n");
1618 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1620 /* communicate the wmi protocol verision to the target */
1621 /* FIXME: return error */
1622 if ((ath6kl_set_host_app_area(ar)) != 0)
1623 ath6kl_err("unable to set the host app area\n");
1625 for (i = 0; i < ar->vif_max; i++) {
1626 ret = ath6kl_target_config_wlan_params(ar, i);
1631 ar->state = ATH6KL_STATE_ON;
1636 ath6kl_htc_stop(ar->htc_target);
1637 err_cleanup_scatter:
1638 ath6kl_hif_cleanup_scatter(ar);
1640 ath6kl_hif_power_off(ar);
1645 int ath6kl_init_hw_stop(struct ath6kl *ar)
1649 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
1651 ath6kl_htc_stop(ar->htc_target);
1653 ath6kl_hif_stop(ar);
1655 ath6kl_bmi_reset(ar);
1657 ret = ath6kl_hif_power_off(ar);
1659 ath6kl_warn("failed to power off hif: %d\n", ret);
1661 ar->state = ATH6KL_STATE_OFF;
1666 int ath6kl_core_init(struct ath6kl *ar)
1668 struct ath6kl_bmi_target_info targ_info;
1669 struct net_device *ndev;
1672 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1676 ret = ath6kl_bmi_init(ar);
1681 * Turn on power to get hardware (target) version and leave power
1682 * on delibrately as we will boot the hardware anyway within few
1685 ret = ath6kl_hif_power_on(ar);
1687 goto err_bmi_cleanup;
1689 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1693 ar->version.target_ver = le32_to_cpu(targ_info.version);
1694 ar->target_type = le32_to_cpu(targ_info.type);
1695 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
1697 ret = ath6kl_init_hw_params(ar);
1701 ar->htc_target = ath6kl_htc_create(ar);
1703 if (!ar->htc_target) {
1708 ret = ath6kl_fetch_firmwares(ar);
1710 goto err_htc_cleanup;
1712 /* FIXME: we should free all firmwares in the error cases below */
1714 /* Indicate that WMI is enabled (although not ready yet) */
1715 set_bit(WMI_ENABLED, &ar->flag);
1716 ar->wmi = ath6kl_wmi_init(ar);
1718 ath6kl_err("failed to initialize wmi\n");
1720 goto err_htc_cleanup;
1723 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1725 ret = ath6kl_cfg80211_init(ar);
1727 goto err_node_cleanup;
1729 ret = ath6kl_debug_init(ar);
1731 wiphy_unregister(ar->wiphy);
1732 goto err_node_cleanup;
1735 for (i = 0; i < ar->vif_max; i++)
1736 ar->avail_idx_map |= BIT(i);
1740 /* Add an initial station interface */
1741 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
1747 ath6kl_err("Failed to instantiate a network device\n");
1749 wiphy_unregister(ar->wiphy);
1750 goto err_debug_init;
1754 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1755 __func__, ndev->name, ndev, ar);
1757 /* setup access class priority mappings */
1758 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1759 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1760 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1761 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1763 /* give our connected endpoints some buffers */
1764 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1765 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1767 /* allocate some buffers that handle larger AMSDU frames */
1768 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1770 ath6kl_cookie_init(ar);
1772 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1773 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1775 if (suspend_cutpower)
1776 ar->conf_flags |= ATH6KL_CONF_SUSPEND_CUTPOWER;
1779 ar->conf_flags |= ATH6KL_CONF_UART_DEBUG;
1781 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
1782 WIPHY_FLAG_HAVE_AP_SME |
1783 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
1784 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1786 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
1787 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
1789 ar->wiphy->probe_resp_offload =
1790 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1791 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1792 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
1793 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
1795 set_bit(FIRST_BOOT, &ar->flag);
1797 ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
1799 ret = ath6kl_init_hw_start(ar);
1801 ath6kl_err("Failed to start hardware: %d\n", ret);
1802 goto err_rxbuf_cleanup;
1806 * Set mac address which is received in ready event
1807 * FIXME: Move to ath6kl_interface_add()
1809 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
1814 ath6kl_htc_flush_rx_buf(ar->htc_target);
1815 ath6kl_cleanup_amsdu_rxbufs(ar);
1817 ath6kl_cfg80211_vif_cleanup(netdev_priv(ndev));
1819 wiphy_unregister(ar->wiphy);
1821 ath6kl_debug_cleanup(ar);
1823 ath6kl_wmi_shutdown(ar->wmi);
1824 clear_bit(WMI_ENABLED, &ar->flag);
1827 ath6kl_htc_cleanup(ar->htc_target);
1829 ath6kl_hif_power_off(ar);
1831 ath6kl_bmi_cleanup(ar);
1833 destroy_workqueue(ar->ath6kl_wq);
1838 /* FIXME: move this to cfg80211.c and rename to ath6kl_cfg80211_vif_stop() */
1839 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
1841 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1844 netif_stop_queue(vif->ndev);
1846 clear_bit(WLAN_ENABLED, &vif->flags);
1849 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1850 test_bit(CONNECT_PEND, &vif->flags);
1851 ath6kl_disconnect(vif);
1852 del_timer(&vif->disconnect_timer);
1855 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1856 (vif->nw_type & AP_NETWORK) ?
1857 bcast_mac : vif->bssid,
1861 if (vif->scan_req) {
1862 cfg80211_scan_done(vif->scan_req, true);
1863 vif->scan_req = NULL;
1867 void ath6kl_stop_txrx(struct ath6kl *ar)
1869 struct ath6kl_vif *vif, *tmp_vif;
1871 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1873 if (down_interruptible(&ar->sem)) {
1874 ath6kl_err("down_interruptible failed\n");
1878 spin_lock_bh(&ar->list_lock);
1879 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1880 list_del(&vif->list);
1881 spin_unlock_bh(&ar->list_lock);
1882 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
1884 ath6kl_cfg80211_vif_cleanup(vif);
1886 spin_lock_bh(&ar->list_lock);
1888 spin_unlock_bh(&ar->list_lock);
1890 clear_bit(WMI_READY, &ar->flag);
1893 * After wmi_shudown all WMI events will be dropped. We
1894 * need to cleanup the buffers allocated in AP mode and
1895 * give disconnect notification to stack, which usually
1896 * happens in the disconnect_event. Simulate the disconnect
1897 * event by calling the function directly. Sometimes
1898 * disconnect_event will be received when the debug logs
1901 ath6kl_wmi_shutdown(ar->wmi);
1903 clear_bit(WMI_ENABLED, &ar->flag);
1904 if (ar->htc_target) {
1905 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1906 ath6kl_htc_stop(ar->htc_target);
1910 * Try to reset the device if we can. The driver may have been
1911 * configure NOT to reset the target during a debug session.
1913 ath6kl_dbg(ATH6KL_DBG_TRC,
1914 "attempting to reset target on instance destroy\n");
1915 ath6kl_reset_device(ar, ar->target_type, true, true);
1917 clear_bit(WLAN_ENABLED, &ar->flag);