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
;
31 module_param(debug_mask
, uint
, 0644);
32 module_param(testmode
, uint
, 0644);
35 * Include definitions here that can be used to tune the WLAN module
36 * behavior. Different customers can tune the behavior as per their needs,
41 * This configuration item enable/disable keepalive support.
42 * Keepalive support: In the absence of any data traffic to AP, null
43 * frames will be sent to the AP at periodic interval, to keep the association
44 * active. This configuration item defines the periodic interval.
45 * Use value of zero to disable keepalive support
48 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
51 * This configuration item sets the value of disconnect timeout
52 * Firmware delays sending the disconnec event to the host for this
53 * timeout after is gets disconnected from the current AP.
54 * If the firmware successly roams within the disconnect timeout
55 * it sends a new connect event
57 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
59 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
61 #define ATH6KL_DATA_OFFSET 64
62 struct sk_buff
*ath6kl_buf_alloc(int size
)
67 /* Add chacheline space at front and back of buffer */
68 reserved
= (2 * L1_CACHE_BYTES
) + ATH6KL_DATA_OFFSET
+
69 sizeof(struct htc_packet
) + ATH6KL_HTC_ALIGN_BYTES
;
70 skb
= dev_alloc_skb(size
+ reserved
);
73 skb_reserve(skb
, reserved
- L1_CACHE_BYTES
);
77 void ath6kl_init_profile_info(struct ath6kl_vif
*vif
)
80 memset(vif
->ssid
, 0, sizeof(vif
->ssid
));
82 vif
->dot11_auth_mode
= OPEN_AUTH
;
83 vif
->auth_mode
= NONE_AUTH
;
84 vif
->prwise_crypto
= NONE_CRYPT
;
85 vif
->prwise_crypto_len
= 0;
86 vif
->grp_crypto
= NONE_CRYPT
;
87 vif
->grp_crypto_len
= 0;
88 memset(vif
->wep_key_list
, 0, sizeof(vif
->wep_key_list
));
89 memset(vif
->req_bssid
, 0, sizeof(vif
->req_bssid
));
90 memset(vif
->bssid
, 0, sizeof(vif
->bssid
));
94 static int ath6kl_set_host_app_area(struct ath6kl
*ar
)
97 struct host_app_area host_app_area
;
99 /* Fetch the address of the host_app_area_s
100 * instance in the host interest area */
101 address
= ath6kl_get_hi_item_addr(ar
, HI_ITEM(hi_app_host_interest
));
102 address
= TARG_VTOP(ar
->target_type
, address
);
104 if (ath6kl_diag_read32(ar
, address
, &data
))
107 address
= TARG_VTOP(ar
->target_type
, data
);
108 host_app_area
.wmi_protocol_ver
= cpu_to_le32(WMI_PROTOCOL_VERSION
);
109 if (ath6kl_diag_write(ar
, address
, (u8
*) &host_app_area
,
110 sizeof(struct host_app_area
)))
116 static inline void set_ac2_ep_map(struct ath6kl
*ar
,
118 enum htc_endpoint_id ep
)
120 ar
->ac2ep_map
[ac
] = ep
;
121 ar
->ep2ac_map
[ep
] = ac
;
124 /* connect to a service */
125 static int ath6kl_connectservice(struct ath6kl
*ar
,
126 struct htc_service_connect_req
*con_req
,
130 struct htc_service_connect_resp response
;
132 memset(&response
, 0, sizeof(response
));
134 status
= ath6kl_htc_conn_service(ar
->htc_target
, con_req
, &response
);
136 ath6kl_err("failed to connect to %s service status:%d\n",
141 switch (con_req
->svc_id
) {
142 case WMI_CONTROL_SVC
:
143 if (test_bit(WMI_ENABLED
, &ar
->flag
))
144 ath6kl_wmi_set_control_ep(ar
->wmi
, response
.endpoint
);
145 ar
->ctrl_ep
= response
.endpoint
;
147 case WMI_DATA_BE_SVC
:
148 set_ac2_ep_map(ar
, WMM_AC_BE
, response
.endpoint
);
150 case WMI_DATA_BK_SVC
:
151 set_ac2_ep_map(ar
, WMM_AC_BK
, response
.endpoint
);
153 case WMI_DATA_VI_SVC
:
154 set_ac2_ep_map(ar
, WMM_AC_VI
, response
.endpoint
);
156 case WMI_DATA_VO_SVC
:
157 set_ac2_ep_map(ar
, WMM_AC_VO
, response
.endpoint
);
160 ath6kl_err("service id is not mapped %d\n", con_req
->svc_id
);
167 static int ath6kl_init_service_ep(struct ath6kl
*ar
)
169 struct htc_service_connect_req connect
;
171 memset(&connect
, 0, sizeof(connect
));
173 /* these fields are the same for all service endpoints */
174 connect
.ep_cb
.rx
= ath6kl_rx
;
175 connect
.ep_cb
.rx_refill
= ath6kl_rx_refill
;
176 connect
.ep_cb
.tx_full
= ath6kl_tx_queue_full
;
179 * Set the max queue depth so that our ath6kl_tx_queue_full handler
182 connect
.max_txq_depth
= MAX_DEFAULT_SEND_QUEUE_DEPTH
;
183 connect
.ep_cb
.rx_refill_thresh
= ATH6KL_MAX_RX_BUFFERS
/ 4;
184 if (!connect
.ep_cb
.rx_refill_thresh
)
185 connect
.ep_cb
.rx_refill_thresh
++;
187 /* connect to control service */
188 connect
.svc_id
= WMI_CONTROL_SVC
;
189 if (ath6kl_connectservice(ar
, &connect
, "WMI CONTROL"))
192 connect
.flags
|= HTC_FLGS_TX_BNDL_PAD_EN
;
195 * Limit the HTC message size on the send path, although e can
196 * receive A-MSDU frames of 4K, we will only send ethernet-sized
197 * (802.3) frames on the send path.
199 connect
.max_rxmsg_sz
= WMI_MAX_TX_DATA_FRAME_LENGTH
;
202 * To reduce the amount of committed memory for larger A_MSDU
203 * frames, use the recv-alloc threshold mechanism for larger
206 connect
.ep_cb
.rx_alloc_thresh
= ATH6KL_BUFFER_SIZE
;
207 connect
.ep_cb
.rx_allocthresh
= ath6kl_alloc_amsdu_rxbuf
;
210 * For the remaining data services set the connection flag to
211 * reduce dribbling, if configured to do so.
213 connect
.conn_flags
|= HTC_CONN_FLGS_REDUCE_CRED_DRIB
;
214 connect
.conn_flags
&= ~HTC_CONN_FLGS_THRESH_MASK
;
215 connect
.conn_flags
|= HTC_CONN_FLGS_THRESH_LVL_HALF
;
217 connect
.svc_id
= WMI_DATA_BE_SVC
;
219 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA BE"))
222 /* connect to back-ground map this to WMI LOW_PRI */
223 connect
.svc_id
= WMI_DATA_BK_SVC
;
224 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA BK"))
227 /* connect to Video service, map this to to HI PRI */
228 connect
.svc_id
= WMI_DATA_VI_SVC
;
229 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA VI"))
233 * Connect to VO service, this is currently not mapped to a WMI
234 * priority stream due to historical reasons. WMI originally
235 * defined 3 priorities over 3 mailboxes We can change this when
236 * WMI is reworked so that priorities are not dependent on
239 connect
.svc_id
= WMI_DATA_VO_SVC
;
240 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA VO"))
246 void ath6kl_init_control_info(struct ath6kl_vif
*vif
)
248 ath6kl_init_profile_info(vif
);
249 vif
->def_txkey_index
= 0;
250 memset(vif
->wep_key_list
, 0, sizeof(vif
->wep_key_list
));
255 * Set HTC/Mbox operational parameters, this can only be called when the
256 * target is in the BMI phase.
258 static int ath6kl_set_htc_params(struct ath6kl
*ar
, u32 mbox_isr_yield_val
,
264 blk_size
= ar
->mbox_info
.block_size
;
267 blk_size
|= ((u32
)htc_ctrl_buf
) << 16;
269 /* set the host interest area for the block size */
270 status
= ath6kl_bmi_write(ar
,
271 ath6kl_get_hi_item_addr(ar
,
272 HI_ITEM(hi_mbox_io_block_sz
)),
276 ath6kl_err("bmi_write_memory for IO block size failed\n");
280 ath6kl_dbg(ATH6KL_DBG_TRC
, "block size set: %d (target addr:0x%X)\n",
282 ath6kl_get_hi_item_addr(ar
, HI_ITEM(hi_mbox_io_block_sz
)));
284 if (mbox_isr_yield_val
) {
285 /* set the host interest area for the mbox ISR yield limit */
286 status
= ath6kl_bmi_write(ar
,
287 ath6kl_get_hi_item_addr(ar
,
288 HI_ITEM(hi_mbox_isr_yield_limit
)),
289 (u8
*)&mbox_isr_yield_val
,
292 ath6kl_err("bmi_write_memory for yield limit failed\n");
301 static int ath6kl_target_config_wlan_params(struct ath6kl
*ar
, int idx
)
307 * Configure the device for rx dot11 header rules. "0,0" are the
308 * default values. Required if checksum offload is needed. Set
309 * RxMetaVersion to 2.
311 if (ath6kl_wmi_set_rx_frame_format_cmd(ar
->wmi
, idx
,
312 ar
->rx_meta_ver
, 0, 0)) {
313 ath6kl_err("unable to set the rx frame format\n");
317 if (ar
->conf_flags
& ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN
)
318 if ((ath6kl_wmi_pmparams_cmd(ar
->wmi
, idx
, 0, 1, 0, 0, 1,
319 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
)) != 0) {
320 ath6kl_err("unable to set power save fail event policy\n");
324 if (!(ar
->conf_flags
& ATH6KL_CONF_IGNORE_ERP_BARKER
))
325 if ((ath6kl_wmi_set_lpreamble_cmd(ar
->wmi
, idx
, 0,
326 WMI_DONOT_IGNORE_BARKER_IN_ERP
)) != 0) {
327 ath6kl_err("unable to set barker preamble policy\n");
331 if (ath6kl_wmi_set_keepalive_cmd(ar
->wmi
, idx
,
332 WLAN_CONFIG_KEEP_ALIVE_INTERVAL
)) {
333 ath6kl_err("unable to set keep alive interval\n");
337 if (ath6kl_wmi_disctimeout_cmd(ar
->wmi
, idx
,
338 WLAN_CONFIG_DISCONNECT_TIMEOUT
)) {
339 ath6kl_err("unable to set disconnect timeout\n");
343 if (!(ar
->conf_flags
& ATH6KL_CONF_ENABLE_TX_BURST
))
344 if (ath6kl_wmi_set_wmm_txop(ar
->wmi
, idx
, WMI_TXOP_DISABLED
)) {
345 ath6kl_err("unable to set txop bursting\n");
350 * FIXME: Make sure p2p configurations are not applied to
351 * non-p2p capable interfaces when multivif support is enabled.
354 ret
= ath6kl_wmi_info_req_cmd(ar
->wmi
, idx
,
355 P2P_FLAG_CAPABILITIES_REQ
|
356 P2P_FLAG_MACADDR_REQ
|
357 P2P_FLAG_HMODEL_REQ
);
359 ath6kl_dbg(ATH6KL_DBG_TRC
, "failed to request P2P "
360 "capabilities (%d) - assuming P2P not "
367 * FIXME: Make sure p2p configurations are not applied to
368 * non-p2p capable interfaces when multivif support is enabled.
371 /* Enable Probe Request reporting for P2P */
372 ret
= ath6kl_wmi_probe_report_req_cmd(ar
->wmi
, idx
, true);
374 ath6kl_dbg(ATH6KL_DBG_TRC
, "failed to enable Probe "
375 "Request reporting (%d)\n", ret
);
382 int ath6kl_configure_target(struct ath6kl
*ar
)
384 u32 param
, ram_reserved_size
;
385 u8 fw_iftype
, fw_mode
= 0, fw_submode
= 0;
389 * Note: Even though the firmware interface type is
390 * chosen as BSS_STA for all three interfaces, can
391 * be configured to IBSS/AP as long as the fw submode
392 * remains normal mode (0 - AP, STA and IBSS). But
393 * due to an target assert in firmware only one interface is
394 * configured for now.
396 fw_iftype
= HI_OPTION_FW_MODE_BSS_STA
;
398 for (i
= 0; i
< MAX_NUM_VIF
; i
++)
399 fw_mode
|= fw_iftype
<< (i
* HI_OPTION_FW_MODE_BITS
);
402 * By default, submodes :
403 * vif[0] - AP/STA/IBSS
404 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
405 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
408 for (i
= 0; i
< ar
->max_norm_iface
; i
++)
409 fw_submode
|= HI_OPTION_FW_SUBMODE_NONE
<<
410 (i
* HI_OPTION_FW_SUBMODE_BITS
);
412 for (i
= ar
->max_norm_iface
; i
< MAX_NUM_VIF
; i
++)
413 fw_submode
|= HI_OPTION_FW_SUBMODE_P2PDEV
<<
414 (i
* HI_OPTION_FW_SUBMODE_BITS
);
417 * FIXME: This needs to be removed once the multivif
418 * support is enabled.
421 fw_submode
= HI_OPTION_FW_SUBMODE_P2PDEV
;
423 param
= HTC_PROTOCOL_VERSION
;
424 if (ath6kl_bmi_write(ar
,
425 ath6kl_get_hi_item_addr(ar
,
426 HI_ITEM(hi_app_host_interest
)),
427 (u8
*)¶m
, 4) != 0) {
428 ath6kl_err("bmi_write_memory for htc version failed\n");
432 /* set the firmware mode to STA/IBSS/AP */
435 if (ath6kl_bmi_read(ar
,
436 ath6kl_get_hi_item_addr(ar
,
437 HI_ITEM(hi_option_flag
)),
438 (u8
*)¶m
, 4) != 0) {
439 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
443 param
|= (MAX_NUM_VIF
<< HI_OPTION_NUM_DEV_SHIFT
);
444 param
|= fw_mode
<< HI_OPTION_FW_MODE_SHIFT
;
445 param
|= fw_submode
<< HI_OPTION_FW_SUBMODE_SHIFT
;
447 param
|= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
448 param
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
450 if (ath6kl_bmi_write(ar
,
451 ath6kl_get_hi_item_addr(ar
,
452 HI_ITEM(hi_option_flag
)),
455 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
459 ath6kl_dbg(ATH6KL_DBG_TRC
, "firmware mode set\n");
462 * Hardcode the address use for the extended board data
463 * Ideally this should be pre-allocate by the OS at boot time
464 * But since it is a new feature and board data is loaded
465 * at init time, we have to workaround this from host.
466 * It is difficult to patch the firmware boot code,
467 * but possible in theory.
470 param
= ar
->hw
.board_ext_data_addr
;
471 ram_reserved_size
= ar
->hw
.reserved_ram_size
;
473 if (ath6kl_bmi_write(ar
, ath6kl_get_hi_item_addr(ar
,
474 HI_ITEM(hi_board_ext_data
)),
475 (u8
*)¶m
, 4) != 0) {
476 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
480 if (ath6kl_bmi_write(ar
, ath6kl_get_hi_item_addr(ar
,
481 HI_ITEM(hi_end_ram_reserve_sz
)),
482 (u8
*)&ram_reserved_size
, 4) != 0) {
483 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
487 /* set the block size for the target */
488 if (ath6kl_set_htc_params(ar
, MBOX_YIELD_LIMIT
, 0))
489 /* use default number of control buffers */
495 void ath6kl_core_free(struct ath6kl
*ar
)
497 wiphy_free(ar
->wiphy
);
500 void ath6kl_core_cleanup(struct ath6kl
*ar
)
502 ath6kl_hif_power_off(ar
);
504 destroy_workqueue(ar
->ath6kl_wq
);
507 ath6kl_htc_cleanup(ar
->htc_target
);
509 ath6kl_cookie_cleanup(ar
);
511 ath6kl_cleanup_amsdu_rxbufs(ar
);
513 ath6kl_bmi_cleanup(ar
);
515 ath6kl_debug_cleanup(ar
);
522 ath6kl_deinit_ieee80211_hw(ar
);
525 /* firmware upload */
526 static int ath6kl_get_fw(struct ath6kl
*ar
, const char *filename
,
527 u8
**fw
, size_t *fw_len
)
529 const struct firmware
*fw_entry
;
532 ret
= request_firmware(&fw_entry
, filename
, ar
->dev
);
536 *fw_len
= fw_entry
->size
;
537 *fw
= kmemdup(fw_entry
->data
, fw_entry
->size
, GFP_KERNEL
);
542 release_firmware(fw_entry
);
548 static const char *get_target_ver_dir(const struct ath6kl
*ar
)
550 switch (ar
->version
.target_ver
) {
551 case AR6003_REV1_VERSION
:
552 return "ath6k/AR6003/hw1.0";
553 case AR6003_REV2_VERSION
:
554 return "ath6k/AR6003/hw2.0";
555 case AR6003_REV3_VERSION
:
556 return "ath6k/AR6003/hw2.1.1";
558 ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__
,
559 ar
->version
.target_ver
);
564 * Check the device tree for a board-id and use it to construct
565 * the pathname to the firmware file. Used (for now) to find a
566 * fallback to the "bdata.bin" file--typically a symlink to the
567 * appropriate board-specific file.
569 static bool check_device_tree(struct ath6kl
*ar
)
571 static const char *board_id_prop
= "atheros,board-id";
572 struct device_node
*node
;
573 char board_filename
[64];
574 const char *board_id
;
577 for_each_compatible_node(node
, NULL
, "atheros,ath6kl") {
578 board_id
= of_get_property(node
, board_id_prop
, NULL
);
579 if (board_id
== NULL
) {
580 ath6kl_warn("No \"%s\" property on %s node.\n",
581 board_id_prop
, node
->name
);
584 snprintf(board_filename
, sizeof(board_filename
),
585 "%s/bdata.%s.bin", get_target_ver_dir(ar
), board_id
);
587 ret
= ath6kl_get_fw(ar
, board_filename
, &ar
->fw_board
,
590 ath6kl_err("Failed to get DT board file %s: %d\n",
591 board_filename
, ret
);
599 static bool check_device_tree(struct ath6kl
*ar
)
603 #endif /* CONFIG_OF */
605 static int ath6kl_fetch_board_file(struct ath6kl
*ar
)
607 const char *filename
;
610 if (ar
->fw_board
!= NULL
)
613 switch (ar
->version
.target_ver
) {
614 case AR6003_REV2_VERSION
:
615 filename
= AR6003_REV2_BOARD_DATA_FILE
;
617 case AR6004_REV1_VERSION
:
618 filename
= AR6004_REV1_BOARD_DATA_FILE
;
621 filename
= AR6003_REV3_BOARD_DATA_FILE
;
625 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_board
,
628 /* managed to get proper board file */
632 if (check_device_tree(ar
)) {
633 /* got board file from device tree */
637 /* there was no proper board file, try to use default instead */
638 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
641 switch (ar
->version
.target_ver
) {
642 case AR6003_REV2_VERSION
:
643 filename
= AR6003_REV2_DEFAULT_BOARD_DATA_FILE
;
645 case AR6004_REV1_VERSION
:
646 filename
= AR6004_REV1_DEFAULT_BOARD_DATA_FILE
;
649 filename
= AR6003_REV3_DEFAULT_BOARD_DATA_FILE
;
653 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_board
,
656 ath6kl_err("Failed to get default board file %s: %d\n",
661 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
662 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
667 static int ath6kl_fetch_otp_file(struct ath6kl
*ar
)
669 const char *filename
;
672 if (ar
->fw_otp
!= NULL
)
675 switch (ar
->version
.target_ver
) {
676 case AR6003_REV2_VERSION
:
677 filename
= AR6003_REV2_OTP_FILE
;
679 case AR6004_REV1_VERSION
:
680 ath6kl_dbg(ATH6KL_DBG_TRC
, "AR6004 doesn't need OTP file\n");
684 filename
= AR6003_REV3_OTP_FILE
;
688 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_otp
,
691 ath6kl_err("Failed to get OTP file %s: %d\n",
699 static int ath6kl_fetch_fw_file(struct ath6kl
*ar
)
701 const char *filename
;
708 switch (ar
->version
.target_ver
) {
709 case AR6003_REV2_VERSION
:
710 filename
= AR6003_REV2_TCMD_FIRMWARE_FILE
;
712 case AR6003_REV3_VERSION
:
713 filename
= AR6003_REV3_TCMD_FIRMWARE_FILE
;
715 case AR6004_REV1_VERSION
:
716 ath6kl_warn("testmode not supported with ar6004\n");
719 ath6kl_warn("unknown target version: 0x%x\n",
720 ar
->version
.target_ver
);
724 set_bit(TESTMODE
, &ar
->flag
);
729 switch (ar
->version
.target_ver
) {
730 case AR6003_REV2_VERSION
:
731 filename
= AR6003_REV2_FIRMWARE_FILE
;
733 case AR6004_REV1_VERSION
:
734 filename
= AR6004_REV1_FIRMWARE_FILE
;
737 filename
= AR6003_REV3_FIRMWARE_FILE
;
742 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw
, &ar
->fw_len
);
744 ath6kl_err("Failed to get firmware file %s: %d\n",
752 static int ath6kl_fetch_patch_file(struct ath6kl
*ar
)
754 const char *filename
;
757 switch (ar
->version
.target_ver
) {
758 case AR6003_REV2_VERSION
:
759 filename
= AR6003_REV2_PATCH_FILE
;
761 case AR6004_REV1_VERSION
:
762 /* FIXME: implement for AR6004 */
766 filename
= AR6003_REV3_PATCH_FILE
;
770 if (ar
->fw_patch
== NULL
) {
771 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_patch
,
774 ath6kl_err("Failed to get patch file %s: %d\n",
783 static int ath6kl_fetch_fw_api1(struct ath6kl
*ar
)
787 ret
= ath6kl_fetch_otp_file(ar
);
791 ret
= ath6kl_fetch_fw_file(ar
);
795 ret
= ath6kl_fetch_patch_file(ar
);
802 static int ath6kl_fetch_fw_api2(struct ath6kl
*ar
)
804 size_t magic_len
, len
, ie_len
;
805 const struct firmware
*fw
;
806 struct ath6kl_fw_ie
*hdr
;
807 const char *filename
;
809 int ret
, ie_id
, i
, index
, bit
;
812 switch (ar
->version
.target_ver
) {
813 case AR6003_REV2_VERSION
:
814 filename
= AR6003_REV2_FIRMWARE_2_FILE
;
816 case AR6003_REV3_VERSION
:
817 filename
= AR6003_REV3_FIRMWARE_2_FILE
;
819 case AR6004_REV1_VERSION
:
820 filename
= AR6004_REV1_FIRMWARE_2_FILE
;
826 ret
= request_firmware(&fw
, filename
, ar
->dev
);
833 /* magic also includes the null byte, check that as well */
834 magic_len
= strlen(ATH6KL_FIRMWARE_MAGIC
) + 1;
836 if (len
< magic_len
) {
841 if (memcmp(data
, ATH6KL_FIRMWARE_MAGIC
, magic_len
) != 0) {
850 while (len
> sizeof(struct ath6kl_fw_ie
)) {
851 /* hdr is unaligned! */
852 hdr
= (struct ath6kl_fw_ie
*) data
;
854 ie_id
= le32_to_cpup(&hdr
->id
);
855 ie_len
= le32_to_cpup(&hdr
->len
);
858 data
+= sizeof(*hdr
);
866 case ATH6KL_FW_IE_OTP_IMAGE
:
867 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found otp image ie (%zd B)\n",
870 ar
->fw_otp
= kmemdup(data
, ie_len
, GFP_KERNEL
);
872 if (ar
->fw_otp
== NULL
) {
877 ar
->fw_otp_len
= ie_len
;
879 case ATH6KL_FW_IE_FW_IMAGE
:
880 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found fw image ie (%zd B)\n",
883 ar
->fw
= kmemdup(data
, ie_len
, GFP_KERNEL
);
885 if (ar
->fw
== NULL
) {
892 case ATH6KL_FW_IE_PATCH_IMAGE
:
893 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found patch image ie (%zd B)\n",
896 ar
->fw_patch
= kmemdup(data
, ie_len
, GFP_KERNEL
);
898 if (ar
->fw_patch
== NULL
) {
903 ar
->fw_patch_len
= ie_len
;
905 case ATH6KL_FW_IE_RESERVED_RAM_SIZE
:
906 val
= (__le32
*) data
;
907 ar
->hw
.reserved_ram_size
= le32_to_cpup(val
);
909 ath6kl_dbg(ATH6KL_DBG_BOOT
,
910 "found reserved ram size ie 0x%d\n",
911 ar
->hw
.reserved_ram_size
);
913 case ATH6KL_FW_IE_CAPABILITIES
:
914 ath6kl_dbg(ATH6KL_DBG_BOOT
,
915 "found firmware capabilities ie (%zd B)\n",
918 for (i
= 0; i
< ATH6KL_FW_CAPABILITY_MAX
; i
++) {
919 index
= ALIGN(i
, 8) / 8;
922 if (data
[index
] & (1 << bit
))
923 __set_bit(i
, ar
->fw_capabilities
);
926 ath6kl_dbg_dump(ATH6KL_DBG_BOOT
, "capabilities", "",
928 sizeof(ar
->fw_capabilities
));
930 case ATH6KL_FW_IE_PATCH_ADDR
:
931 if (ie_len
!= sizeof(*val
))
934 val
= (__le32
*) data
;
935 ar
->hw
.dataset_patch_addr
= le32_to_cpup(val
);
937 ath6kl_dbg(ATH6KL_DBG_BOOT
,
938 "found patch address ie 0x%d\n",
939 ar
->hw
.dataset_patch_addr
);
942 ath6kl_dbg(ATH6KL_DBG_BOOT
, "Unknown fw ie: %u\n",
943 le32_to_cpup(&hdr
->id
));
953 release_firmware(fw
);
958 static int ath6kl_fetch_firmwares(struct ath6kl
*ar
)
962 ret
= ath6kl_fetch_board_file(ar
);
966 ret
= ath6kl_fetch_fw_api2(ar
);
968 ath6kl_dbg(ATH6KL_DBG_BOOT
, "using fw api 2\n");
972 ret
= ath6kl_fetch_fw_api1(ar
);
976 ath6kl_dbg(ATH6KL_DBG_BOOT
, "using fw api 1\n");
981 static int ath6kl_upload_board_file(struct ath6kl
*ar
)
983 u32 board_address
, board_ext_address
, param
;
984 u32 board_data_size
, board_ext_data_size
;
987 if (WARN_ON(ar
->fw_board
== NULL
))
991 * Determine where in Target RAM to write Board Data.
992 * For AR6004, host determine Target RAM address for
993 * writing board data.
995 if (ar
->target_type
== TARGET_TYPE_AR6004
) {
996 board_address
= AR6004_REV1_BOARD_DATA_ADDRESS
;
998 ath6kl_get_hi_item_addr(ar
,
999 HI_ITEM(hi_board_data
)),
1000 (u8
*) &board_address
, 4);
1003 ath6kl_get_hi_item_addr(ar
,
1004 HI_ITEM(hi_board_data
)),
1005 (u8
*) &board_address
, 4);
1008 /* determine where in target ram to write extended board data */
1010 ath6kl_get_hi_item_addr(ar
,
1011 HI_ITEM(hi_board_ext_data
)),
1012 (u8
*) &board_ext_address
, 4);
1014 if (board_ext_address
== 0) {
1015 ath6kl_err("Failed to get board file target address.\n");
1019 switch (ar
->target_type
) {
1020 case TARGET_TYPE_AR6003
:
1021 board_data_size
= AR6003_BOARD_DATA_SZ
;
1022 board_ext_data_size
= AR6003_BOARD_EXT_DATA_SZ
;
1024 case TARGET_TYPE_AR6004
:
1025 board_data_size
= AR6004_BOARD_DATA_SZ
;
1026 board_ext_data_size
= AR6004_BOARD_EXT_DATA_SZ
;
1034 if (ar
->fw_board_len
== (board_data_size
+
1035 board_ext_data_size
)) {
1037 /* write extended board data */
1038 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1039 "writing extended board data to 0x%x (%d B)\n",
1040 board_ext_address
, board_ext_data_size
);
1042 ret
= ath6kl_bmi_write(ar
, board_ext_address
,
1043 ar
->fw_board
+ board_data_size
,
1044 board_ext_data_size
);
1046 ath6kl_err("Failed to write extended board data: %d\n",
1051 /* record that extended board data is initialized */
1052 param
= (board_ext_data_size
<< 16) | 1;
1054 ath6kl_bmi_write(ar
,
1055 ath6kl_get_hi_item_addr(ar
,
1056 HI_ITEM(hi_board_ext_data_config
)),
1057 (unsigned char *) ¶m
, 4);
1060 if (ar
->fw_board_len
< board_data_size
) {
1061 ath6kl_err("Too small board file: %zu\n", ar
->fw_board_len
);
1066 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing board file to 0x%x (%d B)\n",
1067 board_address
, board_data_size
);
1069 ret
= ath6kl_bmi_write(ar
, board_address
, ar
->fw_board
,
1073 ath6kl_err("Board file bmi write failed: %d\n", ret
);
1077 /* record the fact that Board Data IS initialized */
1079 ath6kl_bmi_write(ar
,
1080 ath6kl_get_hi_item_addr(ar
,
1081 HI_ITEM(hi_board_data_initialized
)),
1087 static int ath6kl_upload_otp(struct ath6kl
*ar
)
1090 bool from_hw
= false;
1093 if (WARN_ON(ar
->fw_otp
== NULL
))
1096 address
= ar
->hw
.app_load_addr
;
1098 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing otp to 0x%x (%zd B)\n", address
,
1101 ret
= ath6kl_bmi_fast_download(ar
, address
, ar
->fw_otp
,
1104 ath6kl_err("Failed to upload OTP file: %d\n", ret
);
1108 /* read firmware start address */
1109 ret
= ath6kl_bmi_read(ar
,
1110 ath6kl_get_hi_item_addr(ar
,
1111 HI_ITEM(hi_app_start
)),
1112 (u8
*) &address
, sizeof(address
));
1115 ath6kl_err("Failed to read hi_app_start: %d\n", ret
);
1119 if (ar
->hw
.app_start_override_addr
== 0) {
1120 ar
->hw
.app_start_override_addr
= address
;
1124 ath6kl_dbg(ATH6KL_DBG_BOOT
, "app_start_override_addr%s 0x%x\n",
1125 from_hw
? " (from hw)" : "",
1126 ar
->hw
.app_start_override_addr
);
1128 /* execute the OTP code */
1129 ath6kl_dbg(ATH6KL_DBG_BOOT
, "executing OTP at 0x%x\n",
1130 ar
->hw
.app_start_override_addr
);
1132 ath6kl_bmi_execute(ar
, ar
->hw
.app_start_override_addr
, ¶m
);
1137 static int ath6kl_upload_firmware(struct ath6kl
*ar
)
1142 if (WARN_ON(ar
->fw
== NULL
))
1145 address
= ar
->hw
.app_load_addr
;
1147 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing firmware to 0x%x (%zd B)\n",
1148 address
, ar
->fw_len
);
1150 ret
= ath6kl_bmi_fast_download(ar
, address
, ar
->fw
, ar
->fw_len
);
1153 ath6kl_err("Failed to write firmware: %d\n", ret
);
1158 * Set starting address for firmware
1159 * Don't need to setup app_start override addr on AR6004
1161 if (ar
->target_type
!= TARGET_TYPE_AR6004
) {
1162 address
= ar
->hw
.app_start_override_addr
;
1163 ath6kl_bmi_set_app_start(ar
, address
);
1168 static int ath6kl_upload_patch(struct ath6kl
*ar
)
1173 if (WARN_ON(ar
->fw_patch
== NULL
))
1176 address
= ar
->hw
.dataset_patch_addr
;
1178 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing patch to 0x%x (%zd B)\n",
1179 address
, ar
->fw_patch_len
);
1181 ret
= ath6kl_bmi_write(ar
, address
, ar
->fw_patch
, ar
->fw_patch_len
);
1183 ath6kl_err("Failed to write patch file: %d\n", ret
);
1188 ath6kl_bmi_write(ar
,
1189 ath6kl_get_hi_item_addr(ar
,
1190 HI_ITEM(hi_dset_list_head
)),
1191 (unsigned char *) ¶m
, 4);
1196 static int ath6kl_init_upload(struct ath6kl
*ar
)
1198 u32 param
, options
, sleep
, address
;
1201 if (ar
->target_type
!= TARGET_TYPE_AR6003
&&
1202 ar
->target_type
!= TARGET_TYPE_AR6004
)
1205 /* temporarily disable system sleep */
1206 address
= MBOX_BASE_ADDRESS
+ LOCAL_SCRATCH_ADDRESS
;
1207 status
= ath6kl_bmi_reg_read(ar
, address
, ¶m
);
1213 param
|= ATH6KL_OPTION_SLEEP_DISABLE
;
1214 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1218 address
= RTC_BASE_ADDRESS
+ SYSTEM_SLEEP_ADDRESS
;
1219 status
= ath6kl_bmi_reg_read(ar
, address
, ¶m
);
1225 param
|= SM(SYSTEM_SLEEP_DISABLE
, 1);
1226 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1230 ath6kl_dbg(ATH6KL_DBG_TRC
, "old options: %d, old sleep: %d\n",
1233 /* program analog PLL register */
1234 /* no need to control 40/44MHz clock on AR6004 */
1235 if (ar
->target_type
!= TARGET_TYPE_AR6004
) {
1236 status
= ath6kl_bmi_reg_write(ar
, ATH6KL_ANALOG_PLL_REGISTER
,
1242 /* Run at 80/88MHz by default */
1243 param
= SM(CPU_CLOCK_STANDARD
, 1);
1245 address
= RTC_BASE_ADDRESS
+ CPU_CLOCK_ADDRESS
;
1246 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1252 address
= RTC_BASE_ADDRESS
+ LPO_CAL_ADDRESS
;
1253 param
= SM(LPO_CAL_ENABLE
, 1);
1254 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1258 /* WAR to avoid SDIO CRC err */
1259 if (ar
->version
.target_ver
== AR6003_REV2_VERSION
) {
1260 ath6kl_err("temporary war to avoid sdio crc error\n");
1264 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN10_ADDRESS
;
1265 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1269 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN11_ADDRESS
;
1270 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1274 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN12_ADDRESS
;
1275 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1279 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN13_ADDRESS
;
1280 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1285 /* write EEPROM data to Target RAM */
1286 status
= ath6kl_upload_board_file(ar
);
1290 /* transfer One time Programmable data */
1291 status
= ath6kl_upload_otp(ar
);
1295 /* Download Target firmware */
1296 status
= ath6kl_upload_firmware(ar
);
1300 status
= ath6kl_upload_patch(ar
);
1304 /* Restore system sleep */
1305 address
= RTC_BASE_ADDRESS
+ SYSTEM_SLEEP_ADDRESS
;
1306 status
= ath6kl_bmi_reg_write(ar
, address
, sleep
);
1310 address
= MBOX_BASE_ADDRESS
+ LOCAL_SCRATCH_ADDRESS
;
1311 param
= options
| 0x20;
1312 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1316 /* Configure GPIO AR6003 UART */
1317 param
= CONFIG_AR600x_DEBUG_UART_TX_PIN
;
1318 status
= ath6kl_bmi_write(ar
,
1319 ath6kl_get_hi_item_addr(ar
,
1320 HI_ITEM(hi_dbg_uart_txpin
)),
1326 static int ath6kl_init_hw_params(struct ath6kl
*ar
)
1328 switch (ar
->version
.target_ver
) {
1329 case AR6003_REV2_VERSION
:
1330 ar
->hw
.dataset_patch_addr
= AR6003_REV2_DATASET_PATCH_ADDRESS
;
1331 ar
->hw
.app_load_addr
= AR6003_REV2_APP_LOAD_ADDRESS
;
1332 ar
->hw
.board_ext_data_addr
= AR6003_REV2_BOARD_EXT_DATA_ADDRESS
;
1333 ar
->hw
.reserved_ram_size
= AR6003_REV2_RAM_RESERVE_SIZE
;
1335 /* hw2.0 needs override address hardcoded */
1336 ar
->hw
.app_start_override_addr
= 0x944C00;
1339 case AR6003_REV3_VERSION
:
1340 ar
->hw
.dataset_patch_addr
= AR6003_REV3_DATASET_PATCH_ADDRESS
;
1341 ar
->hw
.app_load_addr
= 0x1234;
1342 ar
->hw
.board_ext_data_addr
= AR6003_REV3_BOARD_EXT_DATA_ADDRESS
;
1343 ar
->hw
.reserved_ram_size
= AR6003_REV3_RAM_RESERVE_SIZE
;
1345 case AR6004_REV1_VERSION
:
1346 ar
->hw
.dataset_patch_addr
= AR6003_REV2_DATASET_PATCH_ADDRESS
;
1347 ar
->hw
.app_load_addr
= AR6003_REV3_APP_LOAD_ADDRESS
;
1348 ar
->hw
.board_ext_data_addr
= AR6004_REV1_BOARD_EXT_DATA_ADDRESS
;
1349 ar
->hw
.reserved_ram_size
= AR6004_REV1_RAM_RESERVE_SIZE
;
1352 ath6kl_err("Unsupported hardware version: 0x%x\n",
1353 ar
->version
.target_ver
);
1357 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1358 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1359 ar
->version
.target_ver
, ar
->target_type
,
1360 ar
->hw
.dataset_patch_addr
, ar
->hw
.app_load_addr
);
1361 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1362 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1363 ar
->hw
.app_start_override_addr
, ar
->hw
.board_ext_data_addr
,
1364 ar
->hw
.reserved_ram_size
);
1369 int ath6kl_init_hw_start(struct ath6kl
*ar
)
1374 ath6kl_dbg(ATH6KL_DBG_BOOT
, "hw start\n");
1376 ret
= ath6kl_hif_power_on(ar
);
1380 ret
= ath6kl_configure_target(ar
);
1384 ret
= ath6kl_init_upload(ar
);
1388 /* Do we need to finish the BMI phase */
1389 /* FIXME: return error from ath6kl_bmi_done() */
1390 if (ath6kl_bmi_done(ar
)) {
1396 * The reason we have to wait for the target here is that the
1397 * driver layer has to init BMI in order to set the host block
1400 if (ath6kl_htc_wait_target(ar
->htc_target
)) {
1405 if (ath6kl_init_service_ep(ar
)) {
1407 goto err_cleanup_scatter
;
1410 /* setup credit distribution */
1411 ath6kl_credit_setup(ar
->htc_target
, &ar
->credit_state_info
);
1414 ret
= ath6kl_htc_start(ar
->htc_target
);
1416 /* FIXME: call this */
1417 ath6kl_cookie_cleanup(ar
);
1418 goto err_cleanup_scatter
;
1421 /* Wait for Wmi event to be ready */
1422 timeleft
= wait_event_interruptible_timeout(ar
->event_wq
,
1427 ath6kl_dbg(ATH6KL_DBG_BOOT
, "firmware booted\n");
1429 if (ar
->version
.abi_ver
!= ATH6KL_ABI_VERSION
) {
1430 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1431 ATH6KL_ABI_VERSION
, ar
->version
.abi_ver
);
1436 if (!timeleft
|| signal_pending(current
)) {
1437 ath6kl_err("wmi is not ready or wait was interrupted\n");
1442 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: wmi is ready\n", __func__
);
1444 /* communicate the wmi protocol verision to the target */
1445 /* FIXME: return error */
1446 if ((ath6kl_set_host_app_area(ar
)) != 0)
1447 ath6kl_err("unable to set the host app area\n");
1449 for (i
= 0; i
< MAX_NUM_VIF
; i
++) {
1450 ret
= ath6kl_target_config_wlan_params(ar
, i
);
1455 ar
->state
= ATH6KL_STATE_ON
;
1460 ath6kl_htc_stop(ar
->htc_target
);
1461 err_cleanup_scatter
:
1462 ath6kl_hif_cleanup_scatter(ar
);
1464 ath6kl_hif_power_off(ar
);
1469 int ath6kl_init_hw_stop(struct ath6kl
*ar
)
1473 ath6kl_dbg(ATH6KL_DBG_BOOT
, "hw stop\n");
1475 ath6kl_htc_stop(ar
->htc_target
);
1477 ath6kl_hif_stop(ar
);
1479 ath6kl_bmi_reset(ar
);
1481 ret
= ath6kl_hif_power_off(ar
);
1483 ath6kl_warn("failed to power off hif: %d\n", ret
);
1485 ar
->state
= ATH6KL_STATE_OFF
;
1490 int ath6kl_core_init(struct ath6kl
*ar
)
1492 struct ath6kl_bmi_target_info targ_info
;
1493 struct net_device
*ndev
;
1496 ar
->ath6kl_wq
= create_singlethread_workqueue("ath6kl");
1500 ret
= ath6kl_bmi_init(ar
);
1505 * Turn on power to get hardware (target) version and leave power
1506 * on delibrately as we will boot the hardware anyway within few
1509 ret
= ath6kl_hif_power_on(ar
);
1511 goto err_bmi_cleanup
;
1513 ret
= ath6kl_bmi_get_target_info(ar
, &targ_info
);
1517 ar
->version
.target_ver
= le32_to_cpu(targ_info
.version
);
1518 ar
->target_type
= le32_to_cpu(targ_info
.type
);
1519 ar
->wiphy
->hw_version
= le32_to_cpu(targ_info
.version
);
1521 ret
= ath6kl_init_hw_params(ar
);
1525 ar
->htc_target
= ath6kl_htc_create(ar
);
1527 if (!ar
->htc_target
) {
1532 ret
= ath6kl_fetch_firmwares(ar
);
1534 goto err_htc_cleanup
;
1536 /* FIXME: we should free all firmwares in the error cases below */
1538 /* Indicate that WMI is enabled (although not ready yet) */
1539 set_bit(WMI_ENABLED
, &ar
->flag
);
1540 ar
->wmi
= ath6kl_wmi_init(ar
);
1542 ath6kl_err("failed to initialize wmi\n");
1544 goto err_htc_cleanup
;
1547 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: got wmi @ 0x%p.\n", __func__
, ar
->wmi
);
1549 ret
= ath6kl_register_ieee80211_hw(ar
);
1551 goto err_node_cleanup
;
1553 ret
= ath6kl_debug_init(ar
);
1555 wiphy_unregister(ar
->wiphy
);
1556 goto err_node_cleanup
;
1559 for (i
= 0; i
< MAX_NUM_VIF
; i
++)
1560 ar
->avail_idx_map
|= BIT(i
);
1564 /* Add an initial station interface */
1565 ndev
= ath6kl_interface_add(ar
, "wlan%d", NL80211_IFTYPE_STATION
, 0,
1571 ath6kl_err("Failed to instantiate a network device\n");
1573 wiphy_unregister(ar
->wiphy
);
1574 goto err_debug_init
;
1578 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: name=%s dev=0x%p, ar=0x%p\n",
1579 __func__
, ndev
->name
, ndev
, ar
);
1581 /* setup access class priority mappings */
1582 ar
->ac_stream_pri_map
[WMM_AC_BK
] = 0; /* lowest */
1583 ar
->ac_stream_pri_map
[WMM_AC_BE
] = 1;
1584 ar
->ac_stream_pri_map
[WMM_AC_VI
] = 2;
1585 ar
->ac_stream_pri_map
[WMM_AC_VO
] = 3; /* highest */
1587 /* give our connected endpoints some buffers */
1588 ath6kl_rx_refill(ar
->htc_target
, ar
->ctrl_ep
);
1589 ath6kl_rx_refill(ar
->htc_target
, ar
->ac2ep_map
[WMM_AC_BE
]);
1591 /* allocate some buffers that handle larger AMSDU frames */
1592 ath6kl_refill_amsdu_rxbufs(ar
, ATH6KL_MAX_AMSDU_RX_BUFFERS
);
1594 ath6kl_cookie_init(ar
);
1596 ar
->conf_flags
= ATH6KL_CONF_IGNORE_ERP_BARKER
|
1597 ATH6KL_CONF_ENABLE_11N
| ATH6KL_CONF_ENABLE_TX_BURST
;
1599 ar
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_FW_ROAM
|
1600 WIPHY_FLAG_HAVE_AP_SME
;
1602 set_bit(FIRST_BOOT
, &ar
->flag
);
1604 ret
= ath6kl_init_hw_start(ar
);
1606 ath6kl_err("Failed to start hardware: %d\n", ret
);
1607 goto err_rxbuf_cleanup
;
1611 * Set mac address which is received in ready event
1612 * FIXME: Move to ath6kl_interface_add()
1614 memcpy(ndev
->dev_addr
, ar
->mac_addr
, ETH_ALEN
);
1616 ret
= ath6kl_init_hw_stop(ar
);
1618 ath6kl_err("Failed to stop hardware: %d\n", ret
);
1619 goto err_htc_cleanup
;
1625 ath6kl_htc_flush_rx_buf(ar
->htc_target
);
1626 ath6kl_cleanup_amsdu_rxbufs(ar
);
1628 ath6kl_deinit_if_data(netdev_priv(ndev
));
1630 wiphy_unregister(ar
->wiphy
);
1632 ath6kl_debug_cleanup(ar
);
1634 ath6kl_wmi_shutdown(ar
->wmi
);
1635 clear_bit(WMI_ENABLED
, &ar
->flag
);
1638 ath6kl_htc_cleanup(ar
->htc_target
);
1640 ath6kl_hif_power_off(ar
);
1642 ath6kl_bmi_cleanup(ar
);
1644 destroy_workqueue(ar
->ath6kl_wq
);
1649 void ath6kl_cleanup_vif(struct ath6kl_vif
*vif
, bool wmi_ready
)
1651 static u8 bcast_mac
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1654 netif_stop_queue(vif
->ndev
);
1656 clear_bit(WLAN_ENABLED
, &vif
->flags
);
1659 discon_issued
= test_bit(CONNECTED
, &vif
->flags
) ||
1660 test_bit(CONNECT_PEND
, &vif
->flags
);
1661 ath6kl_disconnect(vif
);
1662 del_timer(&vif
->disconnect_timer
);
1665 ath6kl_disconnect_event(vif
, DISCONNECT_CMD
,
1666 (vif
->nw_type
& AP_NETWORK
) ?
1667 bcast_mac
: vif
->bssid
,
1671 if (vif
->scan_req
) {
1672 cfg80211_scan_done(vif
->scan_req
, true);
1673 vif
->scan_req
= NULL
;
1677 void ath6kl_stop_txrx(struct ath6kl
*ar
)
1679 struct ath6kl_vif
*vif
, *tmp_vif
;
1681 set_bit(DESTROY_IN_PROGRESS
, &ar
->flag
);
1683 if (down_interruptible(&ar
->sem
)) {
1684 ath6kl_err("down_interruptible failed\n");
1688 spin_lock_bh(&ar
->list_lock
);
1689 list_for_each_entry_safe(vif
, tmp_vif
, &ar
->vif_list
, list
) {
1690 list_del(&vif
->list
);
1691 spin_unlock_bh(&ar
->list_lock
);
1692 ath6kl_cleanup_vif(vif
, test_bit(WMI_READY
, &ar
->flag
));
1694 ath6kl_deinit_if_data(vif
);
1696 spin_lock_bh(&ar
->list_lock
);
1698 spin_unlock_bh(&ar
->list_lock
);
1700 clear_bit(WMI_READY
, &ar
->flag
);
1703 * After wmi_shudown all WMI events will be dropped. We
1704 * need to cleanup the buffers allocated in AP mode and
1705 * give disconnect notification to stack, which usually
1706 * happens in the disconnect_event. Simulate the disconnect
1707 * event by calling the function directly. Sometimes
1708 * disconnect_event will be received when the debug logs
1711 ath6kl_wmi_shutdown(ar
->wmi
);
1713 clear_bit(WMI_ENABLED
, &ar
->flag
);
1714 if (ar
->htc_target
) {
1715 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: shut down htc\n", __func__
);
1716 ath6kl_htc_stop(ar
->htc_target
);
1720 * Try to reset the device if we can. The driver may have been
1721 * configure NOT to reset the target during a debug session.
1723 ath6kl_dbg(ATH6KL_DBG_TRC
,
1724 "attempting to reset target on instance destroy\n");
1725 ath6kl_reset_device(ar
, ar
->target_type
, true, true);
1727 clear_bit(WLAN_ENABLED
, &ar
->flag
);