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.
19 #include <linux/mmc/sdio_func.h>
26 unsigned int debug_mask;
27 static unsigned int testmode;
29 module_param(debug_mask, uint, 0644);
30 module_param(testmode, uint, 0644);
33 * Include definitions here that can be used to tune the WLAN module
34 * behavior. Different customers can tune the behavior as per their needs,
39 * This configuration item enable/disable keepalive support.
40 * Keepalive support: In the absence of any data traffic to AP, null
41 * frames will be sent to the AP at periodic interval, to keep the association
42 * active. This configuration item defines the periodic interval.
43 * Use value of zero to disable keepalive support
46 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
49 * This configuration item sets the value of disconnect timeout
50 * Firmware delays sending the disconnec event to the host for this
51 * timeout after is gets disconnected from the current AP.
52 * If the firmware successly roams within the disconnect timeout
53 * it sends a new connect event
55 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
57 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
59 #define ATH6KL_DATA_OFFSET 64
60 struct sk_buff *ath6kl_buf_alloc(int size)
65 /* Add chacheline space at front and back of buffer */
66 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
67 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
68 skb = dev_alloc_skb(size + reserved);
71 skb_reserve(skb, reserved - L1_CACHE_BYTES);
75 void ath6kl_init_profile_info(struct ath6kl *ar)
78 memset(ar->ssid, 0, sizeof(ar->ssid));
80 ar->dot11_auth_mode = OPEN_AUTH;
81 ar->auth_mode = NONE_AUTH;
82 ar->prwise_crypto = NONE_CRYPT;
83 ar->prwise_crypto_len = 0;
84 ar->grp_crypto = NONE_CRYPT;
85 ar->grp_crypto_len = 0;
86 memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
87 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
88 memset(ar->bssid, 0, sizeof(ar->bssid));
90 ar->nw_type = ar->next_mode = INFRA_NETWORK;
93 static u8 ath6kl_get_fw_iftype(struct ath6kl *ar)
95 switch (ar->nw_type) {
97 return HI_OPTION_FW_MODE_BSS_STA;
99 return HI_OPTION_FW_MODE_IBSS;
101 return HI_OPTION_FW_MODE_AP;
103 ath6kl_err("Unsupported interface type :%d\n", ar->nw_type);
108 static int ath6kl_set_host_app_area(struct ath6kl *ar)
111 struct host_app_area host_app_area;
113 /* Fetch the address of the host_app_area_s
114 * instance in the host interest area */
115 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
116 address = TARG_VTOP(ar->target_type, address);
118 if (ath6kl_diag_read32(ar, address, &data))
121 address = TARG_VTOP(ar->target_type, data);
122 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
123 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
124 sizeof(struct host_app_area)))
130 static inline void set_ac2_ep_map(struct ath6kl *ar,
132 enum htc_endpoint_id ep)
134 ar->ac2ep_map[ac] = ep;
135 ar->ep2ac_map[ep] = ac;
138 /* connect to a service */
139 static int ath6kl_connectservice(struct ath6kl *ar,
140 struct htc_service_connect_req *con_req,
144 struct htc_service_connect_resp response;
146 memset(&response, 0, sizeof(response));
148 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
150 ath6kl_err("failed to connect to %s service status:%d\n",
155 switch (con_req->svc_id) {
156 case WMI_CONTROL_SVC:
157 if (test_bit(WMI_ENABLED, &ar->flag))
158 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
159 ar->ctrl_ep = response.endpoint;
161 case WMI_DATA_BE_SVC:
162 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
164 case WMI_DATA_BK_SVC:
165 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
167 case WMI_DATA_VI_SVC:
168 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
170 case WMI_DATA_VO_SVC:
171 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
174 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
181 static int ath6kl_init_service_ep(struct ath6kl *ar)
183 struct htc_service_connect_req connect;
185 memset(&connect, 0, sizeof(connect));
187 /* these fields are the same for all service endpoints */
188 connect.ep_cb.rx = ath6kl_rx;
189 connect.ep_cb.rx_refill = ath6kl_rx_refill;
190 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
193 * Set the max queue depth so that our ath6kl_tx_queue_full handler
196 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
197 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
198 if (!connect.ep_cb.rx_refill_thresh)
199 connect.ep_cb.rx_refill_thresh++;
201 /* connect to control service */
202 connect.svc_id = WMI_CONTROL_SVC;
203 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
206 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
209 * Limit the HTC message size on the send path, although e can
210 * receive A-MSDU frames of 4K, we will only send ethernet-sized
211 * (802.3) frames on the send path.
213 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
216 * To reduce the amount of committed memory for larger A_MSDU
217 * frames, use the recv-alloc threshold mechanism for larger
220 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
221 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
224 * For the remaining data services set the connection flag to
225 * reduce dribbling, if configured to do so.
227 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
228 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
229 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
231 connect.svc_id = WMI_DATA_BE_SVC;
233 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
236 /* connect to back-ground map this to WMI LOW_PRI */
237 connect.svc_id = WMI_DATA_BK_SVC;
238 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
241 /* connect to Video service, map this to to HI PRI */
242 connect.svc_id = WMI_DATA_VI_SVC;
243 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
247 * Connect to VO service, this is currently not mapped to a WMI
248 * priority stream due to historical reasons. WMI originally
249 * defined 3 priorities over 3 mailboxes We can change this when
250 * WMI is reworked so that priorities are not dependent on
253 connect.svc_id = WMI_DATA_VO_SVC;
254 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
260 static void ath6kl_init_control_info(struct ath6kl *ar)
264 clear_bit(WMI_ENABLED, &ar->flag);
265 ath6kl_init_profile_info(ar);
266 ar->def_txkey_index = 0;
267 memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
269 ar->listen_intvl_t = A_DEFAULT_LISTEN_INTERVAL;
270 ar->listen_intvl_b = 0;
272 clear_bit(SKIP_SCAN, &ar->flag);
273 set_bit(WMM_ENABLED, &ar->flag);
275 memset(&ar->sc_params, 0, sizeof(ar->sc_params));
276 ar->sc_params.short_scan_ratio = WMI_SHORTSCANRATIO_DEFAULT;
277 ar->sc_params.scan_ctrl_flags = DEFAULT_SCAN_CTRL_FLAGS;
278 ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD;
280 memset((u8 *)ar->sta_list, 0,
281 AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
283 spin_lock_init(&ar->mcastpsq_lock);
285 /* Init the PS queues */
286 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
287 spin_lock_init(&ar->sta_list[ctr].psq_lock);
288 skb_queue_head_init(&ar->sta_list[ctr].psq);
291 skb_queue_head_init(&ar->mcastpsq);
293 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
297 * Set HTC/Mbox operational parameters, this can only be called when the
298 * target is in the BMI phase.
300 static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
306 blk_size = ar->mbox_info.block_size;
309 blk_size |= ((u32)htc_ctrl_buf) << 16;
311 /* set the host interest area for the block size */
312 status = ath6kl_bmi_write(ar,
313 ath6kl_get_hi_item_addr(ar,
314 HI_ITEM(hi_mbox_io_block_sz)),
318 ath6kl_err("bmi_write_memory for IO block size failed\n");
322 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
324 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
326 if (mbox_isr_yield_val) {
327 /* set the host interest area for the mbox ISR yield limit */
328 status = ath6kl_bmi_write(ar,
329 ath6kl_get_hi_item_addr(ar,
330 HI_ITEM(hi_mbox_isr_yield_limit)),
331 (u8 *)&mbox_isr_yield_val,
334 ath6kl_err("bmi_write_memory for yield limit failed\n");
343 #define REG_DUMP_COUNT_AR6003 60
344 #define REGISTER_DUMP_LEN_MAX 60
346 static void ath6kl_dump_target_assert_info(struct ath6kl *ar)
351 u32 regdump_val[REGISTER_DUMP_LEN_MAX];
354 if (ar->target_type != TARGET_TYPE_AR6003)
357 /* the reg dump pointer is copied to the host interest area */
358 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
359 address = TARG_VTOP(ar->target_type, address);
361 /* read RAM location through diagnostic window */
362 status = ath6kl_diag_read32(ar, address, ®dump_loc);
364 if (status || !regdump_loc) {
365 ath6kl_err("failed to get ptr to register dump area\n");
369 ath6kl_dbg(ATH6KL_DBG_TRC, "location of register dump data: 0x%X\n",
371 regdump_loc = TARG_VTOP(ar->target_type, regdump_loc);
373 /* fetch register dump data */
374 status = ath6kl_diag_read(ar, regdump_loc, (u8 *)®dump_val[0],
375 REG_DUMP_COUNT_AR6003 * (sizeof(u32)));
378 ath6kl_err("failed to get register dump\n");
381 ath6kl_dbg(ATH6KL_DBG_TRC, "Register Dump:\n");
383 for (i = 0; i < REG_DUMP_COUNT_AR6003; i++)
384 ath6kl_dbg(ATH6KL_DBG_TRC, " %d : 0x%8.8X\n",
389 void ath6kl_target_failure(struct ath6kl *ar)
391 ath6kl_err("target asserted\n");
393 /* try dumping target assertion information (if any) */
394 ath6kl_dump_target_assert_info(ar);
398 static int ath6kl_target_config_wlan_params(struct ath6kl *ar)
404 * Configure the device for rx dot11 header rules. "0,0" are the
405 * default values. Required if checksum offload is needed. Set
406 * RxMetaVersion to 2.
408 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
409 ar->rx_meta_ver, 0, 0)) {
410 ath6kl_err("unable to set the rx frame format\n");
414 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
415 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, 0, 1, 0, 0, 1,
416 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
417 ath6kl_err("unable to set power save fail event policy\n");
421 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
422 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, 0,
423 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
424 ath6kl_err("unable to set barker preamble policy\n");
428 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi,
429 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
430 ath6kl_err("unable to set keep alive interval\n");
434 if (ath6kl_wmi_disctimeout_cmd(ar->wmi,
435 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
436 ath6kl_err("unable to set disconnect timeout\n");
440 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
441 if (ath6kl_wmi_set_wmm_txop(ar->wmi, WMI_TXOP_DISABLED)) {
442 ath6kl_err("unable to set txop bursting\n");
447 ret = ath6kl_wmi_info_req_cmd(ar->wmi,
448 P2P_FLAG_CAPABILITIES_REQ |
449 P2P_FLAG_MACADDR_REQ |
450 P2P_FLAG_HMODEL_REQ);
452 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
453 "capabilities (%d) - assuming P2P not "
460 /* Enable Probe Request reporting for P2P */
461 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, true);
463 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
464 "Request reporting (%d)\n", ret);
471 int ath6kl_configure_target(struct ath6kl *ar)
473 u32 param, ram_reserved_size;
476 fw_iftype = ath6kl_get_fw_iftype(ar);
477 if (fw_iftype == 0xff)
480 /* Tell target which HTC version it is used*/
481 param = HTC_PROTOCOL_VERSION;
482 if (ath6kl_bmi_write(ar,
483 ath6kl_get_hi_item_addr(ar,
484 HI_ITEM(hi_app_host_interest)),
485 (u8 *)¶m, 4) != 0) {
486 ath6kl_err("bmi_write_memory for htc version failed\n");
490 /* set the firmware mode to STA/IBSS/AP */
493 if (ath6kl_bmi_read(ar,
494 ath6kl_get_hi_item_addr(ar,
495 HI_ITEM(hi_option_flag)),
496 (u8 *)¶m, 4) != 0) {
497 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
501 param |= (1 << HI_OPTION_NUM_DEV_SHIFT);
502 param |= (fw_iftype << HI_OPTION_FW_MODE_SHIFT);
503 if (ar->p2p && fw_iftype == HI_OPTION_FW_MODE_BSS_STA) {
504 param |= HI_OPTION_FW_SUBMODE_P2PDEV <<
505 HI_OPTION_FW_SUBMODE_SHIFT;
507 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
508 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
510 if (ath6kl_bmi_write(ar,
511 ath6kl_get_hi_item_addr(ar,
512 HI_ITEM(hi_option_flag)),
515 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
519 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
522 * Hardcode the address use for the extended board data
523 * Ideally this should be pre-allocate by the OS at boot time
524 * But since it is a new feature and board data is loaded
525 * at init time, we have to workaround this from host.
526 * It is difficult to patch the firmware boot code,
527 * but possible in theory.
530 param = ar->hw.board_ext_data_addr;
531 ram_reserved_size = ar->hw.reserved_ram_size;
533 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
534 HI_ITEM(hi_board_ext_data)),
535 (u8 *)¶m, 4) != 0) {
536 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
540 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
541 HI_ITEM(hi_end_ram_reserve_sz)),
542 (u8 *)&ram_reserved_size, 4) != 0) {
543 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
547 /* set the block size for the target */
548 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
549 /* use default number of control buffers */
555 struct ath6kl *ath6kl_core_alloc(struct device *sdev)
557 struct net_device *dev;
559 struct wireless_dev *wdev;
561 wdev = ath6kl_cfg80211_init(sdev);
563 ath6kl_err("ath6kl_cfg80211_init failed\n");
567 ar = wdev_priv(wdev);
570 wdev->iftype = NL80211_IFTYPE_STATION;
572 if (ath6kl_debug_init(ar)) {
573 ath6kl_err("Failed to initialize debugfs\n");
574 ath6kl_cfg80211_deinit(ar);
578 dev = alloc_netdev(0, "wlan%d", ether_setup);
580 ath6kl_err("no memory for network device instance\n");
581 ath6kl_cfg80211_deinit(ar);
585 dev->ieee80211_ptr = wdev;
586 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
588 ar->sme_state = SME_DISCONNECTED;
593 set_bit(WLAN_ENABLED, &ar->flag);
595 ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
597 spin_lock_init(&ar->lock);
599 ath6kl_init_control_info(ar);
600 init_waitqueue_head(&ar->event_wq);
601 sema_init(&ar->sem, 1);
602 clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
604 INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
606 setup_timer(&ar->disconnect_timer, disconnect_timer_handler,
607 (unsigned long) dev);
612 int ath6kl_unavail_ev(struct ath6kl *ar)
614 ath6kl_destroy(ar->net_dev, 1);
619 /* firmware upload */
620 static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
621 u8 **fw, size_t *fw_len)
623 const struct firmware *fw_entry;
626 ret = request_firmware(&fw_entry, filename, ar->dev);
630 *fw_len = fw_entry->size;
631 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
636 release_firmware(fw_entry);
642 static const char *get_target_ver_dir(const struct ath6kl *ar)
644 switch (ar->version.target_ver) {
645 case AR6003_REV1_VERSION:
646 return "ath6k/AR6003/hw1.0";
647 case AR6003_REV2_VERSION:
648 return "ath6k/AR6003/hw2.0";
649 case AR6003_REV3_VERSION:
650 return "ath6k/AR6003/hw2.1.1";
652 ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__,
653 ar->version.target_ver);
658 * Check the device tree for a board-id and use it to construct
659 * the pathname to the firmware file. Used (for now) to find a
660 * fallback to the "bdata.bin" file--typically a symlink to the
661 * appropriate board-specific file.
663 static bool check_device_tree(struct ath6kl *ar)
665 static const char *board_id_prop = "atheros,board-id";
666 struct device_node *node;
667 char board_filename[64];
668 const char *board_id;
671 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
672 board_id = of_get_property(node, board_id_prop, NULL);
673 if (board_id == NULL) {
674 ath6kl_warn("No \"%s\" property on %s node.\n",
675 board_id_prop, node->name);
678 snprintf(board_filename, sizeof(board_filename),
679 "%s/bdata.%s.bin", get_target_ver_dir(ar), board_id);
681 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
684 ath6kl_err("Failed to get DT board file %s: %d\n",
685 board_filename, ret);
693 static bool check_device_tree(struct ath6kl *ar)
697 #endif /* CONFIG_OF */
699 static int ath6kl_fetch_board_file(struct ath6kl *ar)
701 const char *filename;
704 if (ar->fw_board != NULL)
707 switch (ar->version.target_ver) {
708 case AR6003_REV2_VERSION:
709 filename = AR6003_REV2_BOARD_DATA_FILE;
711 case AR6004_REV1_VERSION:
712 filename = AR6004_REV1_BOARD_DATA_FILE;
715 filename = AR6003_REV3_BOARD_DATA_FILE;
719 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
722 /* managed to get proper board file */
726 if (check_device_tree(ar)) {
727 /* got board file from device tree */
731 /* there was no proper board file, try to use default instead */
732 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
735 switch (ar->version.target_ver) {
736 case AR6003_REV2_VERSION:
737 filename = AR6003_REV2_DEFAULT_BOARD_DATA_FILE;
739 case AR6004_REV1_VERSION:
740 filename = AR6004_REV1_DEFAULT_BOARD_DATA_FILE;
743 filename = AR6003_REV3_DEFAULT_BOARD_DATA_FILE;
747 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
750 ath6kl_err("Failed to get default board file %s: %d\n",
755 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
756 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
761 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
763 const char *filename;
766 if (ar->fw_otp != NULL)
769 switch (ar->version.target_ver) {
770 case AR6003_REV2_VERSION:
771 filename = AR6003_REV2_OTP_FILE;
773 case AR6004_REV1_VERSION:
774 ath6kl_dbg(ATH6KL_DBG_TRC, "AR6004 doesn't need OTP file\n");
778 filename = AR6003_REV3_OTP_FILE;
782 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
785 ath6kl_err("Failed to get OTP file %s: %d\n",
793 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
795 const char *filename;
802 switch (ar->version.target_ver) {
803 case AR6003_REV2_VERSION:
804 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
806 case AR6003_REV3_VERSION:
807 filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
809 case AR6004_REV1_VERSION:
810 ath6kl_warn("testmode not supported with ar6004\n");
813 ath6kl_warn("unknown target version: 0x%x\n",
814 ar->version.target_ver);
818 set_bit(TESTMODE, &ar->flag);
823 switch (ar->version.target_ver) {
824 case AR6003_REV2_VERSION:
825 filename = AR6003_REV2_FIRMWARE_FILE;
827 case AR6004_REV1_VERSION:
828 filename = AR6004_REV1_FIRMWARE_FILE;
831 filename = AR6003_REV3_FIRMWARE_FILE;
836 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
838 ath6kl_err("Failed to get firmware file %s: %d\n",
846 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
848 const char *filename;
851 switch (ar->version.target_ver) {
852 case AR6003_REV2_VERSION:
853 filename = AR6003_REV2_PATCH_FILE;
855 case AR6004_REV1_VERSION:
856 /* FIXME: implement for AR6004 */
860 filename = AR6003_REV3_PATCH_FILE;
864 if (ar->fw_patch == NULL) {
865 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
868 ath6kl_err("Failed to get patch file %s: %d\n",
877 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
881 ret = ath6kl_fetch_otp_file(ar);
885 ret = ath6kl_fetch_fw_file(ar);
889 ret = ath6kl_fetch_patch_file(ar);
896 static int ath6kl_fetch_fw_api2(struct ath6kl *ar)
898 size_t magic_len, len, ie_len;
899 const struct firmware *fw;
900 struct ath6kl_fw_ie *hdr;
901 const char *filename;
903 int ret, ie_id, i, index, bit;
906 switch (ar->version.target_ver) {
907 case AR6003_REV2_VERSION:
908 filename = AR6003_REV2_FIRMWARE_2_FILE;
910 case AR6003_REV3_VERSION:
911 filename = AR6003_REV3_FIRMWARE_2_FILE;
913 case AR6004_REV1_VERSION:
914 filename = AR6004_REV1_FIRMWARE_2_FILE;
920 ret = request_firmware(&fw, filename, ar->dev);
927 /* magic also includes the null byte, check that as well */
928 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
930 if (len < magic_len) {
935 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
944 while (len > sizeof(struct ath6kl_fw_ie)) {
945 /* hdr is unaligned! */
946 hdr = (struct ath6kl_fw_ie *) data;
948 ie_id = le32_to_cpup(&hdr->id);
949 ie_len = le32_to_cpup(&hdr->len);
952 data += sizeof(*hdr);
960 case ATH6KL_FW_IE_OTP_IMAGE:
961 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%d B)\n",
964 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
966 if (ar->fw_otp == NULL) {
971 ar->fw_otp_len = ie_len;
973 case ATH6KL_FW_IE_FW_IMAGE:
974 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%d B)\n",
977 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
979 if (ar->fw == NULL) {
986 case ATH6KL_FW_IE_PATCH_IMAGE:
987 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%d B)\n",
990 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
992 if (ar->fw_patch == NULL) {
997 ar->fw_patch_len = ie_len;
999 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
1000 val = (__le32 *) data;
1001 ar->hw.reserved_ram_size = le32_to_cpup(val);
1003 ath6kl_dbg(ATH6KL_DBG_BOOT,
1004 "found reserved ram size ie 0x%d\n",
1005 ar->hw.reserved_ram_size);
1007 case ATH6KL_FW_IE_CAPABILITIES:
1008 ath6kl_dbg(ATH6KL_DBG_BOOT,
1009 "found firmware capabilities ie (%d B)\n",
1012 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
1013 index = ALIGN(i, 8) / 8;
1016 if (data[index] & (1 << bit))
1017 __set_bit(i, ar->fw_capabilities);
1020 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
1021 ar->fw_capabilities,
1022 sizeof(ar->fw_capabilities));
1024 case ATH6KL_FW_IE_PATCH_ADDR:
1025 if (ie_len != sizeof(*val))
1028 val = (__le32 *) data;
1029 ar->hw.dataset_patch_addr = le32_to_cpup(val);
1031 ath6kl_dbg(ATH6KL_DBG_BOOT,
1032 "found patch address ie 0x%d\n",
1033 ar->hw.dataset_patch_addr);
1036 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
1037 le32_to_cpup(&hdr->id));
1047 release_firmware(fw);
1052 static int ath6kl_fetch_firmwares(struct ath6kl *ar)
1056 ret = ath6kl_fetch_board_file(ar);
1060 ret = ath6kl_fetch_fw_api2(ar);
1062 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 2\n");
1066 ret = ath6kl_fetch_fw_api1(ar);
1070 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 1\n");
1075 static int ath6kl_upload_board_file(struct ath6kl *ar)
1077 u32 board_address, board_ext_address, param;
1078 u32 board_data_size, board_ext_data_size;
1081 if (WARN_ON(ar->fw_board == NULL))
1085 * Determine where in Target RAM to write Board Data.
1086 * For AR6004, host determine Target RAM address for
1087 * writing board data.
1089 if (ar->target_type == TARGET_TYPE_AR6004) {
1090 board_address = AR6004_REV1_BOARD_DATA_ADDRESS;
1091 ath6kl_bmi_write(ar,
1092 ath6kl_get_hi_item_addr(ar,
1093 HI_ITEM(hi_board_data)),
1094 (u8 *) &board_address, 4);
1097 ath6kl_get_hi_item_addr(ar,
1098 HI_ITEM(hi_board_data)),
1099 (u8 *) &board_address, 4);
1102 /* determine where in target ram to write extended board data */
1104 ath6kl_get_hi_item_addr(ar,
1105 HI_ITEM(hi_board_ext_data)),
1106 (u8 *) &board_ext_address, 4);
1108 if (board_ext_address == 0) {
1109 ath6kl_err("Failed to get board file target address.\n");
1113 switch (ar->target_type) {
1114 case TARGET_TYPE_AR6003:
1115 board_data_size = AR6003_BOARD_DATA_SZ;
1116 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1118 case TARGET_TYPE_AR6004:
1119 board_data_size = AR6004_BOARD_DATA_SZ;
1120 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1128 if (ar->fw_board_len == (board_data_size +
1129 board_ext_data_size)) {
1131 /* write extended board data */
1132 ath6kl_dbg(ATH6KL_DBG_BOOT,
1133 "writing extended board data to 0x%x (%d B)\n",
1134 board_ext_address, board_ext_data_size);
1136 ret = ath6kl_bmi_write(ar, board_ext_address,
1137 ar->fw_board + board_data_size,
1138 board_ext_data_size);
1140 ath6kl_err("Failed to write extended board data: %d\n",
1145 /* record that extended board data is initialized */
1146 param = (board_ext_data_size << 16) | 1;
1148 ath6kl_bmi_write(ar,
1149 ath6kl_get_hi_item_addr(ar,
1150 HI_ITEM(hi_board_ext_data_config)),
1151 (unsigned char *) ¶m, 4);
1154 if (ar->fw_board_len < board_data_size) {
1155 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1160 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1161 board_address, board_data_size);
1163 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
1167 ath6kl_err("Board file bmi write failed: %d\n", ret);
1171 /* record the fact that Board Data IS initialized */
1173 ath6kl_bmi_write(ar,
1174 ath6kl_get_hi_item_addr(ar,
1175 HI_ITEM(hi_board_data_initialized)),
1181 static int ath6kl_upload_otp(struct ath6kl *ar)
1186 if (WARN_ON(ar->fw_otp == NULL))
1189 address = ar->hw.app_load_addr;
1191 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%d B)\n", address,
1194 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1197 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1201 /* read firmware start address */
1202 ret = ath6kl_bmi_read(ar,
1203 ath6kl_get_hi_item_addr(ar,
1204 HI_ITEM(hi_app_start)),
1205 (u8 *) &address, sizeof(address));
1208 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1212 ar->hw.app_start_override_addr = address;
1214 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr 0x%x\n",
1215 ar->hw.app_start_override_addr);
1217 /* execute the OTP code */
1218 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n", address);
1220 ath6kl_bmi_execute(ar, address, ¶m);
1225 static int ath6kl_upload_firmware(struct ath6kl *ar)
1230 if (WARN_ON(ar->fw == NULL))
1233 address = ar->hw.app_load_addr;
1235 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%d B)\n",
1236 address, ar->fw_len);
1238 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1241 ath6kl_err("Failed to write firmware: %d\n", ret);
1246 * Set starting address for firmware
1247 * Don't need to setup app_start override addr on AR6004
1249 if (ar->target_type != TARGET_TYPE_AR6004) {
1250 address = ar->hw.app_start_override_addr;
1251 ath6kl_bmi_set_app_start(ar, address);
1256 static int ath6kl_upload_patch(struct ath6kl *ar)
1261 if (WARN_ON(ar->fw_patch == NULL))
1264 address = ar->hw.dataset_patch_addr;
1266 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%d B)\n",
1267 address, ar->fw_patch_len);
1269 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1271 ath6kl_err("Failed to write patch file: %d\n", ret);
1276 ath6kl_bmi_write(ar,
1277 ath6kl_get_hi_item_addr(ar,
1278 HI_ITEM(hi_dset_list_head)),
1279 (unsigned char *) ¶m, 4);
1284 static int ath6kl_init_upload(struct ath6kl *ar)
1286 u32 param, options, sleep, address;
1289 if (ar->target_type != TARGET_TYPE_AR6003 &&
1290 ar->target_type != TARGET_TYPE_AR6004)
1293 /* temporarily disable system sleep */
1294 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1295 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1301 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1302 status = ath6kl_bmi_reg_write(ar, address, param);
1306 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1307 status = ath6kl_bmi_reg_read(ar, address, ¶m);
1313 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1314 status = ath6kl_bmi_reg_write(ar, address, param);
1318 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1321 /* program analog PLL register */
1322 /* no need to control 40/44MHz clock on AR6004 */
1323 if (ar->target_type != TARGET_TYPE_AR6004) {
1324 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1330 /* Run at 80/88MHz by default */
1331 param = SM(CPU_CLOCK_STANDARD, 1);
1333 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1334 status = ath6kl_bmi_reg_write(ar, address, param);
1340 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1341 param = SM(LPO_CAL_ENABLE, 1);
1342 status = ath6kl_bmi_reg_write(ar, address, param);
1346 /* WAR to avoid SDIO CRC err */
1347 if (ar->version.target_ver == AR6003_REV2_VERSION) {
1348 ath6kl_err("temporary war to avoid sdio crc error\n");
1352 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1353 status = ath6kl_bmi_reg_write(ar, address, param);
1357 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1358 status = ath6kl_bmi_reg_write(ar, address, param);
1362 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1363 status = ath6kl_bmi_reg_write(ar, address, param);
1367 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1368 status = ath6kl_bmi_reg_write(ar, address, param);
1373 /* write EEPROM data to Target RAM */
1374 status = ath6kl_upload_board_file(ar);
1378 /* transfer One time Programmable data */
1379 status = ath6kl_upload_otp(ar);
1383 /* Download Target firmware */
1384 status = ath6kl_upload_firmware(ar);
1388 status = ath6kl_upload_patch(ar);
1392 /* Restore system sleep */
1393 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1394 status = ath6kl_bmi_reg_write(ar, address, sleep);
1398 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1399 param = options | 0x20;
1400 status = ath6kl_bmi_reg_write(ar, address, param);
1404 /* Configure GPIO AR6003 UART */
1405 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1406 status = ath6kl_bmi_write(ar,
1407 ath6kl_get_hi_item_addr(ar,
1408 HI_ITEM(hi_dbg_uart_txpin)),
1414 static int ath6kl_init_hw_params(struct ath6kl *ar)
1416 switch (ar->version.target_ver) {
1417 case AR6003_REV2_VERSION:
1418 ar->hw.dataset_patch_addr = AR6003_REV2_DATASET_PATCH_ADDRESS;
1419 ar->hw.app_load_addr = AR6003_REV2_APP_LOAD_ADDRESS;
1420 ar->hw.board_ext_data_addr = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
1421 ar->hw.reserved_ram_size = AR6003_REV2_RAM_RESERVE_SIZE;
1423 case AR6003_REV3_VERSION:
1424 ar->hw.dataset_patch_addr = AR6003_REV3_DATASET_PATCH_ADDRESS;
1425 ar->hw.app_load_addr = 0x1234;
1426 ar->hw.board_ext_data_addr = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
1427 ar->hw.reserved_ram_size = AR6003_REV3_RAM_RESERVE_SIZE;
1429 case AR6004_REV1_VERSION:
1430 ar->hw.dataset_patch_addr = AR6003_REV2_DATASET_PATCH_ADDRESS;
1431 ar->hw.app_load_addr = AR6003_REV3_APP_LOAD_ADDRESS;
1432 ar->hw.board_ext_data_addr = AR6004_REV1_BOARD_EXT_DATA_ADDRESS;
1433 ar->hw.reserved_ram_size = AR6004_REV1_RAM_RESERVE_SIZE;
1436 ath6kl_err("Unsupported hardware version: 0x%x\n",
1437 ar->version.target_ver);
1441 ath6kl_dbg(ATH6KL_DBG_BOOT,
1442 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1443 ar->version.target_ver, ar->target_type,
1444 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1445 ath6kl_dbg(ATH6KL_DBG_BOOT,
1446 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1447 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1448 ar->hw.reserved_ram_size);
1453 static int ath6kl_init(struct net_device *dev)
1455 struct ath6kl *ar = ath6kl_priv(dev);
1462 /* Do we need to finish the BMI phase */
1463 if (ath6kl_bmi_done(ar)) {
1465 goto ath6kl_init_done;
1468 /* Indicate that WMI is enabled (although not ready yet) */
1469 set_bit(WMI_ENABLED, &ar->flag);
1470 ar->wmi = ath6kl_wmi_init(ar);
1472 ath6kl_err("failed to initialize wmi\n");
1474 goto ath6kl_init_done;
1477 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1480 * The reason we have to wait for the target here is that the
1481 * driver layer has to init BMI in order to set the host block
1484 if (ath6kl_htc_wait_target(ar->htc_target)) {
1486 goto err_node_cleanup;
1489 if (ath6kl_init_service_ep(ar)) {
1491 goto err_cleanup_scatter;
1494 /* setup access class priority mappings */
1495 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1496 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1497 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1498 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1500 /* give our connected endpoints some buffers */
1501 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1502 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1504 /* allocate some buffers that handle larger AMSDU frames */
1505 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1507 /* setup credit distribution */
1508 ath6k_setup_credit_dist(ar->htc_target, &ar->credit_state_info);
1510 ath6kl_cookie_init(ar);
1513 status = ath6kl_htc_start(ar->htc_target);
1516 ath6kl_cookie_cleanup(ar);
1517 goto err_rxbuf_cleanup;
1520 /* Wait for Wmi event to be ready */
1521 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1526 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1528 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1529 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1530 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1535 if (!timeleft || signal_pending(current)) {
1536 ath6kl_err("wmi is not ready or wait was interrupted\n");
1541 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1543 /* communicate the wmi protocol verision to the target */
1544 if ((ath6kl_set_host_app_area(ar)) != 0)
1545 ath6kl_err("unable to set the host app area\n");
1547 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1548 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1550 ar->wdev->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
1552 status = ath6kl_target_config_wlan_params(ar);
1554 goto ath6kl_init_done;
1557 ath6kl_htc_stop(ar->htc_target);
1559 ath6kl_htc_flush_rx_buf(ar->htc_target);
1560 ath6kl_cleanup_amsdu_rxbufs(ar);
1561 err_cleanup_scatter:
1562 ath6kl_hif_cleanup_scatter(ar);
1564 ath6kl_wmi_shutdown(ar->wmi);
1565 clear_bit(WMI_ENABLED, &ar->flag);
1572 int ath6kl_core_init(struct ath6kl *ar)
1575 struct ath6kl_bmi_target_info targ_info;
1577 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1581 ret = ath6kl_bmi_init(ar);
1585 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1587 goto err_bmi_cleanup;
1589 ar->version.target_ver = le32_to_cpu(targ_info.version);
1590 ar->target_type = le32_to_cpu(targ_info.type);
1591 ar->wdev->wiphy->hw_version = le32_to_cpu(targ_info.version);
1593 ret = ath6kl_init_hw_params(ar);
1595 goto err_bmi_cleanup;
1597 ret = ath6kl_configure_target(ar);
1599 goto err_bmi_cleanup;
1601 ar->htc_target = ath6kl_htc_create(ar);
1603 if (!ar->htc_target) {
1605 goto err_bmi_cleanup;
1608 ar->aggr_cntxt = aggr_init(ar->net_dev);
1609 if (!ar->aggr_cntxt) {
1610 ath6kl_err("failed to initialize aggr\n");
1612 goto err_htc_cleanup;
1615 ret = ath6kl_fetch_firmwares(ar);
1617 goto err_htc_cleanup;
1619 ret = ath6kl_init_upload(ar);
1621 goto err_htc_cleanup;
1623 ret = ath6kl_init(ar->net_dev);
1625 goto err_htc_cleanup;
1627 /* This runs the init function if registered */
1628 ret = register_netdev(ar->net_dev);
1630 ath6kl_err("register_netdev failed\n");
1631 ath6kl_destroy(ar->net_dev, 0);
1635 set_bit(NETDEV_REGISTERED, &ar->flag);
1637 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1638 __func__, ar->net_dev->name, ar->net_dev, ar);
1643 ath6kl_htc_cleanup(ar->htc_target);
1645 ath6kl_bmi_cleanup(ar);
1647 destroy_workqueue(ar->ath6kl_wq);
1651 void ath6kl_stop_txrx(struct ath6kl *ar)
1653 struct net_device *ndev = ar->net_dev;
1658 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1660 if (down_interruptible(&ar->sem)) {
1661 ath6kl_err("down_interruptible failed\n");
1665 if (ar->wlan_pwr_state != WLAN_POWER_STATE_CUT_PWR)
1666 ath6kl_stop_endpoint(ndev, false, true);
1668 clear_bit(WLAN_ENABLED, &ar->flag);
1672 * We need to differentiate between the surprise and planned removal of the
1673 * device because of the following consideration:
1675 * - In case of surprise removal, the hcd already frees up the pending
1676 * for the device and hence there is no need to unregister the function
1677 * driver inorder to get these requests. For planned removal, the function
1678 * driver has to explicitly unregister itself to have the hcd return all the
1679 * pending requests before the data structures for the devices are freed up.
1680 * Note that as per the current implementation, the function driver will
1681 * end up releasing all the devices since there is no API to selectively
1682 * release a particular device.
1684 * - Certain commands issued to the target can be skipped for surprise
1685 * removal since they will anyway not go through.
1687 void ath6kl_destroy(struct net_device *dev, unsigned int unregister)
1691 if (!dev || !ath6kl_priv(dev)) {
1692 ath6kl_err("failed to get device structure\n");
1696 ar = ath6kl_priv(dev);
1698 destroy_workqueue(ar->ath6kl_wq);
1701 ath6kl_htc_cleanup(ar->htc_target);
1703 aggr_module_destroy(ar->aggr_cntxt);
1705 ath6kl_cookie_cleanup(ar);
1707 ath6kl_cleanup_amsdu_rxbufs(ar);
1709 ath6kl_bmi_cleanup(ar);
1711 ath6kl_debug_cleanup(ar);
1713 if (unregister && test_bit(NETDEV_REGISTERED, &ar->flag)) {
1714 unregister_netdev(dev);
1715 clear_bit(NETDEV_REGISTERED, &ar->flag);
1720 kfree(ar->fw_board);
1723 kfree(ar->fw_patch);
1725 ath6kl_cfg80211_deinit(ar);