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
;
32 module_param(debug_mask
, uint
, 0644);
33 module_param(testmode
, uint
, 0644);
34 module_param(suspend_cutpower
, bool, 0444);
36 static const struct ath6kl_hw hw_list
[] = {
38 .id
= AR6003_HW_2_0_VERSION
,
39 .name
= "ar6003 hw 2.0",
40 .dataset_patch_addr
= 0x57e884,
41 .app_load_addr
= 0x543180,
42 .board_ext_data_addr
= 0x57e500,
43 .reserved_ram_size
= 6912,
44 .refclk_hz
= 26000000,
47 /* hw2.0 needs override address hardcoded */
48 .app_start_override_addr
= 0x944C00,
51 .dir
= AR6003_HW_2_0_FW_DIR
,
52 .otp
= AR6003_HW_2_0_OTP_FILE
,
53 .fw
= AR6003_HW_2_0_FIRMWARE_FILE
,
54 .tcmd
= AR6003_HW_2_0_TCMD_FIRMWARE_FILE
,
55 .patch
= AR6003_HW_2_0_PATCH_FILE
,
58 .fw_board
= AR6003_HW_2_0_BOARD_DATA_FILE
,
59 .fw_default_board
= AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE
,
62 .id
= AR6003_HW_2_1_1_VERSION
,
63 .name
= "ar6003 hw 2.1.1",
64 .dataset_patch_addr
= 0x57ff74,
65 .app_load_addr
= 0x1234,
66 .board_ext_data_addr
= 0x542330,
67 .reserved_ram_size
= 512,
68 .refclk_hz
= 26000000,
72 .dir
= AR6003_HW_2_1_1_FW_DIR
,
73 .otp
= AR6003_HW_2_1_1_OTP_FILE
,
74 .fw
= AR6003_HW_2_1_1_FIRMWARE_FILE
,
75 .tcmd
= AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE
,
76 .patch
= AR6003_HW_2_1_1_PATCH_FILE
,
79 .fw_board
= AR6003_HW_2_1_1_BOARD_DATA_FILE
,
80 .fw_default_board
= AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE
,
83 .id
= AR6004_HW_1_0_VERSION
,
84 .name
= "ar6004 hw 1.0",
85 .dataset_patch_addr
= 0x57e884,
86 .app_load_addr
= 0x1234,
87 .board_ext_data_addr
= 0x437000,
88 .reserved_ram_size
= 19456,
89 .board_addr
= 0x433900,
90 .refclk_hz
= 26000000,
94 .dir
= AR6004_HW_1_0_FW_DIR
,
95 .fw
= AR6004_HW_1_0_FIRMWARE_FILE
,
98 .fw_board
= AR6004_HW_1_0_BOARD_DATA_FILE
,
99 .fw_default_board
= AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE
,
102 .id
= AR6004_HW_1_1_VERSION
,
103 .name
= "ar6004 hw 1.1",
104 .dataset_patch_addr
= 0x57e884,
105 .app_load_addr
= 0x1234,
106 .board_ext_data_addr
= 0x437000,
107 .reserved_ram_size
= 11264,
108 .board_addr
= 0x43d400,
109 .refclk_hz
= 40000000,
113 .dir
= AR6004_HW_1_1_FW_DIR
,
114 .fw
= AR6004_HW_1_1_FIRMWARE_FILE
,
117 .fw_board
= AR6004_HW_1_1_BOARD_DATA_FILE
,
118 .fw_default_board
= AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE
,
123 * Include definitions here that can be used to tune the WLAN module
124 * behavior. Different customers can tune the behavior as per their needs,
129 * This configuration item enable/disable keepalive support.
130 * Keepalive support: In the absence of any data traffic to AP, null
131 * frames will be sent to the AP at periodic interval, to keep the association
132 * active. This configuration item defines the periodic interval.
133 * Use value of zero to disable keepalive support
134 * Default: 60 seconds
136 #define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
139 * This configuration item sets the value of disconnect timeout
140 * Firmware delays sending the disconnec event to the host for this
141 * timeout after is gets disconnected from the current AP.
142 * If the firmware successly roams within the disconnect timeout
143 * it sends a new connect event
145 #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
148 #define ATH6KL_DATA_OFFSET 64
149 struct sk_buff
*ath6kl_buf_alloc(int size
)
154 /* Add chacheline space at front and back of buffer */
155 reserved
= (2 * L1_CACHE_BYTES
) + ATH6KL_DATA_OFFSET
+
156 sizeof(struct htc_packet
) + ATH6KL_HTC_ALIGN_BYTES
;
157 skb
= dev_alloc_skb(size
+ reserved
);
160 skb_reserve(skb
, reserved
- L1_CACHE_BYTES
);
164 void ath6kl_init_profile_info(struct ath6kl_vif
*vif
)
167 memset(vif
->ssid
, 0, sizeof(vif
->ssid
));
169 vif
->dot11_auth_mode
= OPEN_AUTH
;
170 vif
->auth_mode
= NONE_AUTH
;
171 vif
->prwise_crypto
= NONE_CRYPT
;
172 vif
->prwise_crypto_len
= 0;
173 vif
->grp_crypto
= NONE_CRYPT
;
174 vif
->grp_crypto_len
= 0;
175 memset(vif
->wep_key_list
, 0, sizeof(vif
->wep_key_list
));
176 memset(vif
->req_bssid
, 0, sizeof(vif
->req_bssid
));
177 memset(vif
->bssid
, 0, sizeof(vif
->bssid
));
181 static int ath6kl_set_host_app_area(struct ath6kl
*ar
)
184 struct host_app_area host_app_area
;
186 /* Fetch the address of the host_app_area_s
187 * instance in the host interest area */
188 address
= ath6kl_get_hi_item_addr(ar
, HI_ITEM(hi_app_host_interest
));
189 address
= TARG_VTOP(ar
->target_type
, address
);
191 if (ath6kl_diag_read32(ar
, address
, &data
))
194 address
= TARG_VTOP(ar
->target_type
, data
);
195 host_app_area
.wmi_protocol_ver
= cpu_to_le32(WMI_PROTOCOL_VERSION
);
196 if (ath6kl_diag_write(ar
, address
, (u8
*) &host_app_area
,
197 sizeof(struct host_app_area
)))
203 static inline void set_ac2_ep_map(struct ath6kl
*ar
,
205 enum htc_endpoint_id ep
)
207 ar
->ac2ep_map
[ac
] = ep
;
208 ar
->ep2ac_map
[ep
] = ac
;
211 /* connect to a service */
212 static int ath6kl_connectservice(struct ath6kl
*ar
,
213 struct htc_service_connect_req
*con_req
,
217 struct htc_service_connect_resp response
;
219 memset(&response
, 0, sizeof(response
));
221 status
= ath6kl_htc_conn_service(ar
->htc_target
, con_req
, &response
);
223 ath6kl_err("failed to connect to %s service status:%d\n",
228 switch (con_req
->svc_id
) {
229 case WMI_CONTROL_SVC
:
230 if (test_bit(WMI_ENABLED
, &ar
->flag
))
231 ath6kl_wmi_set_control_ep(ar
->wmi
, response
.endpoint
);
232 ar
->ctrl_ep
= response
.endpoint
;
234 case WMI_DATA_BE_SVC
:
235 set_ac2_ep_map(ar
, WMM_AC_BE
, response
.endpoint
);
237 case WMI_DATA_BK_SVC
:
238 set_ac2_ep_map(ar
, WMM_AC_BK
, response
.endpoint
);
240 case WMI_DATA_VI_SVC
:
241 set_ac2_ep_map(ar
, WMM_AC_VI
, response
.endpoint
);
243 case WMI_DATA_VO_SVC
:
244 set_ac2_ep_map(ar
, WMM_AC_VO
, response
.endpoint
);
247 ath6kl_err("service id is not mapped %d\n", con_req
->svc_id
);
254 static int ath6kl_init_service_ep(struct ath6kl
*ar
)
256 struct htc_service_connect_req connect
;
258 memset(&connect
, 0, sizeof(connect
));
260 /* these fields are the same for all service endpoints */
261 connect
.ep_cb
.rx
= ath6kl_rx
;
262 connect
.ep_cb
.rx_refill
= ath6kl_rx_refill
;
263 connect
.ep_cb
.tx_full
= ath6kl_tx_queue_full
;
266 * Set the max queue depth so that our ath6kl_tx_queue_full handler
269 connect
.max_txq_depth
= MAX_DEFAULT_SEND_QUEUE_DEPTH
;
270 connect
.ep_cb
.rx_refill_thresh
= ATH6KL_MAX_RX_BUFFERS
/ 4;
271 if (!connect
.ep_cb
.rx_refill_thresh
)
272 connect
.ep_cb
.rx_refill_thresh
++;
274 /* connect to control service */
275 connect
.svc_id
= WMI_CONTROL_SVC
;
276 if (ath6kl_connectservice(ar
, &connect
, "WMI CONTROL"))
279 connect
.flags
|= HTC_FLGS_TX_BNDL_PAD_EN
;
282 * Limit the HTC message size on the send path, although e can
283 * receive A-MSDU frames of 4K, we will only send ethernet-sized
284 * (802.3) frames on the send path.
286 connect
.max_rxmsg_sz
= WMI_MAX_TX_DATA_FRAME_LENGTH
;
289 * To reduce the amount of committed memory for larger A_MSDU
290 * frames, use the recv-alloc threshold mechanism for larger
293 connect
.ep_cb
.rx_alloc_thresh
= ATH6KL_BUFFER_SIZE
;
294 connect
.ep_cb
.rx_allocthresh
= ath6kl_alloc_amsdu_rxbuf
;
297 * For the remaining data services set the connection flag to
298 * reduce dribbling, if configured to do so.
300 connect
.conn_flags
|= HTC_CONN_FLGS_REDUCE_CRED_DRIB
;
301 connect
.conn_flags
&= ~HTC_CONN_FLGS_THRESH_MASK
;
302 connect
.conn_flags
|= HTC_CONN_FLGS_THRESH_LVL_HALF
;
304 connect
.svc_id
= WMI_DATA_BE_SVC
;
306 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA BE"))
309 /* connect to back-ground map this to WMI LOW_PRI */
310 connect
.svc_id
= WMI_DATA_BK_SVC
;
311 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA BK"))
314 /* connect to Video service, map this to to HI PRI */
315 connect
.svc_id
= WMI_DATA_VI_SVC
;
316 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA VI"))
320 * Connect to VO service, this is currently not mapped to a WMI
321 * priority stream due to historical reasons. WMI originally
322 * defined 3 priorities over 3 mailboxes We can change this when
323 * WMI is reworked so that priorities are not dependent on
326 connect
.svc_id
= WMI_DATA_VO_SVC
;
327 if (ath6kl_connectservice(ar
, &connect
, "WMI DATA VO"))
333 void ath6kl_init_control_info(struct ath6kl_vif
*vif
)
335 ath6kl_init_profile_info(vif
);
336 vif
->def_txkey_index
= 0;
337 memset(vif
->wep_key_list
, 0, sizeof(vif
->wep_key_list
));
342 * Set HTC/Mbox operational parameters, this can only be called when the
343 * target is in the BMI phase.
345 static int ath6kl_set_htc_params(struct ath6kl
*ar
, u32 mbox_isr_yield_val
,
351 blk_size
= ar
->mbox_info
.block_size
;
354 blk_size
|= ((u32
)htc_ctrl_buf
) << 16;
356 /* set the host interest area for the block size */
357 status
= ath6kl_bmi_write(ar
,
358 ath6kl_get_hi_item_addr(ar
,
359 HI_ITEM(hi_mbox_io_block_sz
)),
363 ath6kl_err("bmi_write_memory for IO block size failed\n");
367 ath6kl_dbg(ATH6KL_DBG_TRC
, "block size set: %d (target addr:0x%X)\n",
369 ath6kl_get_hi_item_addr(ar
, HI_ITEM(hi_mbox_io_block_sz
)));
371 if (mbox_isr_yield_val
) {
372 /* set the host interest area for the mbox ISR yield limit */
373 status
= ath6kl_bmi_write(ar
,
374 ath6kl_get_hi_item_addr(ar
,
375 HI_ITEM(hi_mbox_isr_yield_limit
)),
376 (u8
*)&mbox_isr_yield_val
,
379 ath6kl_err("bmi_write_memory for yield limit failed\n");
388 static int ath6kl_target_config_wlan_params(struct ath6kl
*ar
, int idx
)
394 * Configure the device for rx dot11 header rules. "0,0" are the
395 * default values. Required if checksum offload is needed. Set
396 * RxMetaVersion to 2.
398 if (ath6kl_wmi_set_rx_frame_format_cmd(ar
->wmi
, idx
,
399 ar
->rx_meta_ver
, 0, 0)) {
400 ath6kl_err("unable to set the rx frame format\n");
404 if (ar
->conf_flags
& ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN
)
405 if ((ath6kl_wmi_pmparams_cmd(ar
->wmi
, idx
, 0, 1, 0, 0, 1,
406 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
)) != 0) {
407 ath6kl_err("unable to set power save fail event policy\n");
411 if (!(ar
->conf_flags
& ATH6KL_CONF_IGNORE_ERP_BARKER
))
412 if ((ath6kl_wmi_set_lpreamble_cmd(ar
->wmi
, idx
, 0,
413 WMI_DONOT_IGNORE_BARKER_IN_ERP
)) != 0) {
414 ath6kl_err("unable to set barker preamble policy\n");
418 if (ath6kl_wmi_set_keepalive_cmd(ar
->wmi
, idx
,
419 WLAN_CONFIG_KEEP_ALIVE_INTERVAL
)) {
420 ath6kl_err("unable to set keep alive interval\n");
424 if (ath6kl_wmi_disctimeout_cmd(ar
->wmi
, idx
,
425 WLAN_CONFIG_DISCONNECT_TIMEOUT
)) {
426 ath6kl_err("unable to set disconnect timeout\n");
430 if (!(ar
->conf_flags
& ATH6KL_CONF_ENABLE_TX_BURST
))
431 if (ath6kl_wmi_set_wmm_txop(ar
->wmi
, idx
, WMI_TXOP_DISABLED
)) {
432 ath6kl_err("unable to set txop bursting\n");
436 if (ar
->p2p
&& (ar
->vif_max
== 1 || idx
)) {
437 ret
= ath6kl_wmi_info_req_cmd(ar
->wmi
, idx
,
438 P2P_FLAG_CAPABILITIES_REQ
|
439 P2P_FLAG_MACADDR_REQ
|
440 P2P_FLAG_HMODEL_REQ
);
442 ath6kl_dbg(ATH6KL_DBG_TRC
, "failed to request P2P "
443 "capabilities (%d) - assuming P2P not "
449 if (ar
->p2p
&& (ar
->vif_max
== 1 || idx
)) {
450 /* Enable Probe Request reporting for P2P */
451 ret
= ath6kl_wmi_probe_report_req_cmd(ar
->wmi
, idx
, true);
453 ath6kl_dbg(ATH6KL_DBG_TRC
, "failed to enable Probe "
454 "Request reporting (%d)\n", ret
);
461 int ath6kl_configure_target(struct ath6kl
*ar
)
463 u32 param
, ram_reserved_size
;
464 u8 fw_iftype
, fw_mode
= 0, fw_submode
= 0;
468 * Note: Even though the firmware interface type is
469 * chosen as BSS_STA for all three interfaces, can
470 * be configured to IBSS/AP as long as the fw submode
471 * remains normal mode (0 - AP, STA and IBSS). But
472 * due to an target assert in firmware only one interface is
473 * configured for now.
475 fw_iftype
= HI_OPTION_FW_MODE_BSS_STA
;
477 for (i
= 0; i
< ar
->vif_max
; i
++)
478 fw_mode
|= fw_iftype
<< (i
* HI_OPTION_FW_MODE_BITS
);
481 * By default, submodes :
482 * vif[0] - AP/STA/IBSS
483 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
484 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
487 for (i
= 0; i
< ar
->max_norm_iface
; i
++)
488 fw_submode
|= HI_OPTION_FW_SUBMODE_NONE
<<
489 (i
* HI_OPTION_FW_SUBMODE_BITS
);
491 for (i
= ar
->max_norm_iface
; i
< ar
->vif_max
; i
++)
492 fw_submode
|= HI_OPTION_FW_SUBMODE_P2PDEV
<<
493 (i
* HI_OPTION_FW_SUBMODE_BITS
);
495 if (ar
->p2p
&& ar
->vif_max
== 1)
496 fw_submode
= HI_OPTION_FW_SUBMODE_P2PDEV
;
498 param
= HTC_PROTOCOL_VERSION
;
499 if (ath6kl_bmi_write(ar
,
500 ath6kl_get_hi_item_addr(ar
,
501 HI_ITEM(hi_app_host_interest
)),
502 (u8
*)¶m
, 4) != 0) {
503 ath6kl_err("bmi_write_memory for htc version failed\n");
507 /* set the firmware mode to STA/IBSS/AP */
510 if (ath6kl_bmi_read(ar
,
511 ath6kl_get_hi_item_addr(ar
,
512 HI_ITEM(hi_option_flag
)),
513 (u8
*)¶m
, 4) != 0) {
514 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
518 param
|= (ar
->vif_max
<< HI_OPTION_NUM_DEV_SHIFT
);
519 param
|= fw_mode
<< HI_OPTION_FW_MODE_SHIFT
;
520 param
|= fw_submode
<< HI_OPTION_FW_SUBMODE_SHIFT
;
522 param
|= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT
);
523 param
|= (0 << HI_OPTION_FW_BRIDGE_SHIFT
);
525 if (ath6kl_bmi_write(ar
,
526 ath6kl_get_hi_item_addr(ar
,
527 HI_ITEM(hi_option_flag
)),
530 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
534 ath6kl_dbg(ATH6KL_DBG_TRC
, "firmware mode set\n");
537 * Hardcode the address use for the extended board data
538 * Ideally this should be pre-allocate by the OS at boot time
539 * But since it is a new feature and board data is loaded
540 * at init time, we have to workaround this from host.
541 * It is difficult to patch the firmware boot code,
542 * but possible in theory.
545 param
= ar
->hw
.board_ext_data_addr
;
546 ram_reserved_size
= ar
->hw
.reserved_ram_size
;
548 if (ath6kl_bmi_write(ar
, ath6kl_get_hi_item_addr(ar
,
549 HI_ITEM(hi_board_ext_data
)),
550 (u8
*)¶m
, 4) != 0) {
551 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
555 if (ath6kl_bmi_write(ar
, ath6kl_get_hi_item_addr(ar
,
556 HI_ITEM(hi_end_ram_reserve_sz
)),
557 (u8
*)&ram_reserved_size
, 4) != 0) {
558 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
562 /* set the block size for the target */
563 if (ath6kl_set_htc_params(ar
, MBOX_YIELD_LIMIT
, 0))
564 /* use default number of control buffers */
567 /* Configure GPIO AR600x UART */
568 param
= ar
->hw
.uarttx_pin
;
569 status
= ath6kl_bmi_write(ar
,
570 ath6kl_get_hi_item_addr(ar
,
571 HI_ITEM(hi_dbg_uart_txpin
)),
576 /* Configure target refclk_hz */
577 param
= ar
->hw
.refclk_hz
;
578 status
= ath6kl_bmi_write(ar
,
579 ath6kl_get_hi_item_addr(ar
,
580 HI_ITEM(hi_refclk_hz
)),
588 void ath6kl_core_free(struct ath6kl
*ar
)
590 wiphy_free(ar
->wiphy
);
593 void ath6kl_core_cleanup(struct ath6kl
*ar
)
595 ath6kl_hif_power_off(ar
);
597 destroy_workqueue(ar
->ath6kl_wq
);
600 ath6kl_htc_cleanup(ar
->htc_target
);
602 ath6kl_cookie_cleanup(ar
);
604 ath6kl_cleanup_amsdu_rxbufs(ar
);
606 ath6kl_bmi_cleanup(ar
);
608 ath6kl_debug_cleanup(ar
);
615 ath6kl_deinit_ieee80211_hw(ar
);
618 /* firmware upload */
619 static int ath6kl_get_fw(struct ath6kl
*ar
, const char *filename
,
620 u8
**fw
, size_t *fw_len
)
622 const struct firmware
*fw_entry
;
625 ret
= request_firmware(&fw_entry
, filename
, ar
->dev
);
629 *fw_len
= fw_entry
->size
;
630 *fw
= kmemdup(fw_entry
->data
, fw_entry
->size
, GFP_KERNEL
);
635 release_firmware(fw_entry
);
642 * Check the device tree for a board-id and use it to construct
643 * the pathname to the firmware file. Used (for now) to find a
644 * fallback to the "bdata.bin" file--typically a symlink to the
645 * appropriate board-specific file.
647 static bool check_device_tree(struct ath6kl
*ar
)
649 static const char *board_id_prop
= "atheros,board-id";
650 struct device_node
*node
;
651 char board_filename
[64];
652 const char *board_id
;
655 for_each_compatible_node(node
, NULL
, "atheros,ath6kl") {
656 board_id
= of_get_property(node
, board_id_prop
, NULL
);
657 if (board_id
== NULL
) {
658 ath6kl_warn("No \"%s\" property on %s node.\n",
659 board_id_prop
, node
->name
);
662 snprintf(board_filename
, sizeof(board_filename
),
663 "%s/bdata.%s.bin", ar
->hw
.fw
.dir
, board_id
);
665 ret
= ath6kl_get_fw(ar
, board_filename
, &ar
->fw_board
,
668 ath6kl_err("Failed to get DT board file %s: %d\n",
669 board_filename
, ret
);
677 static bool check_device_tree(struct ath6kl
*ar
)
681 #endif /* CONFIG_OF */
683 static int ath6kl_fetch_board_file(struct ath6kl
*ar
)
685 const char *filename
;
688 if (ar
->fw_board
!= NULL
)
691 if (WARN_ON(ar
->hw
.fw_board
== NULL
))
694 filename
= ar
->hw
.fw_board
;
696 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_board
,
699 /* managed to get proper board file */
703 if (check_device_tree(ar
)) {
704 /* got board file from device tree */
708 /* there was no proper board file, try to use default instead */
709 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
712 filename
= ar
->hw
.fw_default_board
;
714 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_board
,
717 ath6kl_err("Failed to get default board file %s: %d\n",
722 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
723 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
728 static int ath6kl_fetch_otp_file(struct ath6kl
*ar
)
733 if (ar
->fw_otp
!= NULL
)
736 if (ar
->hw
.fw
.otp
== NULL
) {
737 ath6kl_dbg(ATH6KL_DBG_BOOT
,
738 "no OTP file configured for this hw\n");
742 snprintf(filename
, sizeof(filename
), "%s/%s",
743 ar
->hw
.fw
.dir
, ar
->hw
.fw
.otp
);
745 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_otp
,
748 ath6kl_err("Failed to get OTP file %s: %d\n",
756 static int ath6kl_fetch_fw_file(struct ath6kl
*ar
)
765 if (ar
->hw
.fw
.tcmd
== NULL
) {
766 ath6kl_warn("testmode not supported\n");
770 snprintf(filename
, sizeof(filename
), "%s/%s",
771 ar
->hw
.fw
.dir
, ar
->hw
.fw
.tcmd
);
773 set_bit(TESTMODE
, &ar
->flag
);
778 /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
779 if (WARN_ON(ar
->hw
.fw
.fw
== NULL
))
782 snprintf(filename
, sizeof(filename
), "%s/%s",
783 ar
->hw
.fw
.dir
, ar
->hw
.fw
.fw
);
786 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw
, &ar
->fw_len
);
788 ath6kl_err("Failed to get firmware file %s: %d\n",
796 static int ath6kl_fetch_patch_file(struct ath6kl
*ar
)
801 if (ar
->fw_patch
!= NULL
)
804 if (ar
->hw
.fw
.patch
== NULL
)
807 snprintf(filename
, sizeof(filename
), "%s/%s",
808 ar
->hw
.fw
.dir
, ar
->hw
.fw
.patch
);
810 ret
= ath6kl_get_fw(ar
, filename
, &ar
->fw_patch
,
813 ath6kl_err("Failed to get patch file %s: %d\n",
821 static int ath6kl_fetch_fw_api1(struct ath6kl
*ar
)
825 ret
= ath6kl_fetch_otp_file(ar
);
829 ret
= ath6kl_fetch_fw_file(ar
);
833 ret
= ath6kl_fetch_patch_file(ar
);
840 static int ath6kl_fetch_fw_apin(struct ath6kl
*ar
, const char *name
)
842 size_t magic_len
, len
, ie_len
;
843 const struct firmware
*fw
;
844 struct ath6kl_fw_ie
*hdr
;
847 int ret
, ie_id
, i
, index
, bit
;
850 snprintf(filename
, sizeof(filename
), "%s/%s", ar
->hw
.fw
.dir
, name
);
852 ret
= request_firmware(&fw
, filename
, ar
->dev
);
859 /* magic also includes the null byte, check that as well */
860 magic_len
= strlen(ATH6KL_FIRMWARE_MAGIC
) + 1;
862 if (len
< magic_len
) {
867 if (memcmp(data
, ATH6KL_FIRMWARE_MAGIC
, magic_len
) != 0) {
876 while (len
> sizeof(struct ath6kl_fw_ie
)) {
877 /* hdr is unaligned! */
878 hdr
= (struct ath6kl_fw_ie
*) data
;
880 ie_id
= le32_to_cpup(&hdr
->id
);
881 ie_len
= le32_to_cpup(&hdr
->len
);
884 data
+= sizeof(*hdr
);
892 case ATH6KL_FW_IE_OTP_IMAGE
:
893 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found otp image ie (%zd B)\n",
896 ar
->fw_otp
= kmemdup(data
, ie_len
, GFP_KERNEL
);
898 if (ar
->fw_otp
== NULL
) {
903 ar
->fw_otp_len
= ie_len
;
905 case ATH6KL_FW_IE_FW_IMAGE
:
906 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found fw image ie (%zd B)\n",
909 ar
->fw
= kmemdup(data
, ie_len
, GFP_KERNEL
);
911 if (ar
->fw
== NULL
) {
918 case ATH6KL_FW_IE_PATCH_IMAGE
:
919 ath6kl_dbg(ATH6KL_DBG_BOOT
, "found patch image ie (%zd B)\n",
922 ar
->fw_patch
= kmemdup(data
, ie_len
, GFP_KERNEL
);
924 if (ar
->fw_patch
== NULL
) {
929 ar
->fw_patch_len
= ie_len
;
931 case ATH6KL_FW_IE_RESERVED_RAM_SIZE
:
932 val
= (__le32
*) data
;
933 ar
->hw
.reserved_ram_size
= le32_to_cpup(val
);
935 ath6kl_dbg(ATH6KL_DBG_BOOT
,
936 "found reserved ram size ie 0x%d\n",
937 ar
->hw
.reserved_ram_size
);
939 case ATH6KL_FW_IE_CAPABILITIES
:
940 if (ie_len
< DIV_ROUND_UP(ATH6KL_FW_CAPABILITY_MAX
, 8))
943 ath6kl_dbg(ATH6KL_DBG_BOOT
,
944 "found firmware capabilities ie (%zd B)\n",
947 for (i
= 0; i
< ATH6KL_FW_CAPABILITY_MAX
; i
++) {
951 if (data
[index
] & (1 << bit
))
952 __set_bit(i
, ar
->fw_capabilities
);
955 ath6kl_dbg_dump(ATH6KL_DBG_BOOT
, "capabilities", "",
957 sizeof(ar
->fw_capabilities
));
959 case ATH6KL_FW_IE_PATCH_ADDR
:
960 if (ie_len
!= sizeof(*val
))
963 val
= (__le32
*) data
;
964 ar
->hw
.dataset_patch_addr
= le32_to_cpup(val
);
966 ath6kl_dbg(ATH6KL_DBG_BOOT
,
967 "found patch address ie 0x%x\n",
968 ar
->hw
.dataset_patch_addr
);
970 case ATH6KL_FW_IE_BOARD_ADDR
:
971 if (ie_len
!= sizeof(*val
))
974 val
= (__le32
*) data
;
975 ar
->hw
.board_addr
= le32_to_cpup(val
);
977 ath6kl_dbg(ATH6KL_DBG_BOOT
,
978 "found board address ie 0x%x\n",
981 case ATH6KL_FW_IE_VIF_MAX
:
982 if (ie_len
!= sizeof(*val
))
985 val
= (__le32
*) data
;
986 ar
->vif_max
= min_t(unsigned int, le32_to_cpup(val
),
989 if (ar
->vif_max
> 1 && !ar
->p2p
)
990 ar
->max_norm_iface
= 2;
992 ath6kl_dbg(ATH6KL_DBG_BOOT
,
993 "found vif max ie %d\n", ar
->vif_max
);
996 ath6kl_dbg(ATH6KL_DBG_BOOT
, "Unknown fw ie: %u\n",
997 le32_to_cpup(&hdr
->id
));
1007 release_firmware(fw
);
1012 static int ath6kl_fetch_firmwares(struct ath6kl
*ar
)
1016 ret
= ath6kl_fetch_board_file(ar
);
1020 ret
= ath6kl_fetch_fw_apin(ar
, ATH6KL_FW_API3_FILE
);
1026 ret
= ath6kl_fetch_fw_apin(ar
, ATH6KL_FW_API2_FILE
);
1032 ret
= ath6kl_fetch_fw_api1(ar
);
1039 ath6kl_dbg(ATH6KL_DBG_BOOT
, "using fw api %d\n", ar
->fw_api
);
1044 static int ath6kl_upload_board_file(struct ath6kl
*ar
)
1046 u32 board_address
, board_ext_address
, param
;
1047 u32 board_data_size
, board_ext_data_size
;
1050 if (WARN_ON(ar
->fw_board
== NULL
))
1054 * Determine where in Target RAM to write Board Data.
1055 * For AR6004, host determine Target RAM address for
1056 * writing board data.
1058 if (ar
->hw
.board_addr
!= 0) {
1059 board_address
= ar
->hw
.board_addr
;
1060 ath6kl_bmi_write(ar
,
1061 ath6kl_get_hi_item_addr(ar
,
1062 HI_ITEM(hi_board_data
)),
1063 (u8
*) &board_address
, 4);
1066 ath6kl_get_hi_item_addr(ar
,
1067 HI_ITEM(hi_board_data
)),
1068 (u8
*) &board_address
, 4);
1071 /* determine where in target ram to write extended board data */
1073 ath6kl_get_hi_item_addr(ar
,
1074 HI_ITEM(hi_board_ext_data
)),
1075 (u8
*) &board_ext_address
, 4);
1077 if (ar
->target_type
== TARGET_TYPE_AR6003
&&
1078 board_ext_address
== 0) {
1079 ath6kl_err("Failed to get board file target address.\n");
1083 switch (ar
->target_type
) {
1084 case TARGET_TYPE_AR6003
:
1085 board_data_size
= AR6003_BOARD_DATA_SZ
;
1086 board_ext_data_size
= AR6003_BOARD_EXT_DATA_SZ
;
1088 case TARGET_TYPE_AR6004
:
1089 board_data_size
= AR6004_BOARD_DATA_SZ
;
1090 board_ext_data_size
= AR6004_BOARD_EXT_DATA_SZ
;
1098 if (board_ext_address
&&
1099 ar
->fw_board_len
== (board_data_size
+ board_ext_data_size
)) {
1101 /* write extended board data */
1102 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1103 "writing extended board data to 0x%x (%d B)\n",
1104 board_ext_address
, board_ext_data_size
);
1106 ret
= ath6kl_bmi_write(ar
, board_ext_address
,
1107 ar
->fw_board
+ board_data_size
,
1108 board_ext_data_size
);
1110 ath6kl_err("Failed to write extended board data: %d\n",
1115 /* record that extended board data is initialized */
1116 param
= (board_ext_data_size
<< 16) | 1;
1118 ath6kl_bmi_write(ar
,
1119 ath6kl_get_hi_item_addr(ar
,
1120 HI_ITEM(hi_board_ext_data_config
)),
1121 (unsigned char *) ¶m
, 4);
1124 if (ar
->fw_board_len
< board_data_size
) {
1125 ath6kl_err("Too small board file: %zu\n", ar
->fw_board_len
);
1130 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing board file to 0x%x (%d B)\n",
1131 board_address
, board_data_size
);
1133 ret
= ath6kl_bmi_write(ar
, board_address
, ar
->fw_board
,
1137 ath6kl_err("Board file bmi write failed: %d\n", ret
);
1141 /* record the fact that Board Data IS initialized */
1143 ath6kl_bmi_write(ar
,
1144 ath6kl_get_hi_item_addr(ar
,
1145 HI_ITEM(hi_board_data_initialized
)),
1151 static int ath6kl_upload_otp(struct ath6kl
*ar
)
1154 bool from_hw
= false;
1157 if (ar
->fw_otp
== NULL
)
1160 address
= ar
->hw
.app_load_addr
;
1162 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing otp to 0x%x (%zd B)\n", address
,
1165 ret
= ath6kl_bmi_fast_download(ar
, address
, ar
->fw_otp
,
1168 ath6kl_err("Failed to upload OTP file: %d\n", ret
);
1172 /* read firmware start address */
1173 ret
= ath6kl_bmi_read(ar
,
1174 ath6kl_get_hi_item_addr(ar
,
1175 HI_ITEM(hi_app_start
)),
1176 (u8
*) &address
, sizeof(address
));
1179 ath6kl_err("Failed to read hi_app_start: %d\n", ret
);
1183 if (ar
->hw
.app_start_override_addr
== 0) {
1184 ar
->hw
.app_start_override_addr
= address
;
1188 ath6kl_dbg(ATH6KL_DBG_BOOT
, "app_start_override_addr%s 0x%x\n",
1189 from_hw
? " (from hw)" : "",
1190 ar
->hw
.app_start_override_addr
);
1192 /* execute the OTP code */
1193 ath6kl_dbg(ATH6KL_DBG_BOOT
, "executing OTP at 0x%x\n",
1194 ar
->hw
.app_start_override_addr
);
1196 ath6kl_bmi_execute(ar
, ar
->hw
.app_start_override_addr
, ¶m
);
1201 static int ath6kl_upload_firmware(struct ath6kl
*ar
)
1206 if (WARN_ON(ar
->fw
== NULL
))
1209 address
= ar
->hw
.app_load_addr
;
1211 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing firmware to 0x%x (%zd B)\n",
1212 address
, ar
->fw_len
);
1214 ret
= ath6kl_bmi_fast_download(ar
, address
, ar
->fw
, ar
->fw_len
);
1217 ath6kl_err("Failed to write firmware: %d\n", ret
);
1222 * Set starting address for firmware
1223 * Don't need to setup app_start override addr on AR6004
1225 if (ar
->target_type
!= TARGET_TYPE_AR6004
) {
1226 address
= ar
->hw
.app_start_override_addr
;
1227 ath6kl_bmi_set_app_start(ar
, address
);
1232 static int ath6kl_upload_patch(struct ath6kl
*ar
)
1237 if (ar
->fw_patch
== NULL
)
1240 address
= ar
->hw
.dataset_patch_addr
;
1242 ath6kl_dbg(ATH6KL_DBG_BOOT
, "writing patch to 0x%x (%zd B)\n",
1243 address
, ar
->fw_patch_len
);
1245 ret
= ath6kl_bmi_write(ar
, address
, ar
->fw_patch
, ar
->fw_patch_len
);
1247 ath6kl_err("Failed to write patch file: %d\n", ret
);
1252 ath6kl_bmi_write(ar
,
1253 ath6kl_get_hi_item_addr(ar
,
1254 HI_ITEM(hi_dset_list_head
)),
1255 (unsigned char *) ¶m
, 4);
1260 static int ath6kl_init_upload(struct ath6kl
*ar
)
1262 u32 param
, options
, sleep
, address
;
1265 if (ar
->target_type
!= TARGET_TYPE_AR6003
&&
1266 ar
->target_type
!= TARGET_TYPE_AR6004
)
1269 /* temporarily disable system sleep */
1270 address
= MBOX_BASE_ADDRESS
+ LOCAL_SCRATCH_ADDRESS
;
1271 status
= ath6kl_bmi_reg_read(ar
, address
, ¶m
);
1277 param
|= ATH6KL_OPTION_SLEEP_DISABLE
;
1278 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1282 address
= RTC_BASE_ADDRESS
+ SYSTEM_SLEEP_ADDRESS
;
1283 status
= ath6kl_bmi_reg_read(ar
, address
, ¶m
);
1289 param
|= SM(SYSTEM_SLEEP_DISABLE
, 1);
1290 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1294 ath6kl_dbg(ATH6KL_DBG_TRC
, "old options: %d, old sleep: %d\n",
1297 /* program analog PLL register */
1298 /* no need to control 40/44MHz clock on AR6004 */
1299 if (ar
->target_type
!= TARGET_TYPE_AR6004
) {
1300 status
= ath6kl_bmi_reg_write(ar
, ATH6KL_ANALOG_PLL_REGISTER
,
1306 /* Run at 80/88MHz by default */
1307 param
= SM(CPU_CLOCK_STANDARD
, 1);
1309 address
= RTC_BASE_ADDRESS
+ CPU_CLOCK_ADDRESS
;
1310 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1316 address
= RTC_BASE_ADDRESS
+ LPO_CAL_ADDRESS
;
1317 param
= SM(LPO_CAL_ENABLE
, 1);
1318 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1322 /* WAR to avoid SDIO CRC err */
1323 if (ar
->version
.target_ver
== AR6003_HW_2_0_VERSION
) {
1324 ath6kl_err("temporary war to avoid sdio crc error\n");
1328 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN10_ADDRESS
;
1329 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1333 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN11_ADDRESS
;
1334 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1338 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN12_ADDRESS
;
1339 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1343 address
= GPIO_BASE_ADDRESS
+ GPIO_PIN13_ADDRESS
;
1344 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1349 /* write EEPROM data to Target RAM */
1350 status
= ath6kl_upload_board_file(ar
);
1354 /* transfer One time Programmable data */
1355 status
= ath6kl_upload_otp(ar
);
1359 /* Download Target firmware */
1360 status
= ath6kl_upload_firmware(ar
);
1364 status
= ath6kl_upload_patch(ar
);
1368 /* Restore system sleep */
1369 address
= RTC_BASE_ADDRESS
+ SYSTEM_SLEEP_ADDRESS
;
1370 status
= ath6kl_bmi_reg_write(ar
, address
, sleep
);
1374 address
= MBOX_BASE_ADDRESS
+ LOCAL_SCRATCH_ADDRESS
;
1375 param
= options
| 0x20;
1376 status
= ath6kl_bmi_reg_write(ar
, address
, param
);
1383 static int ath6kl_init_hw_params(struct ath6kl
*ar
)
1385 const struct ath6kl_hw
*hw
;
1388 for (i
= 0; i
< ARRAY_SIZE(hw_list
); i
++) {
1391 if (hw
->id
== ar
->version
.target_ver
)
1395 if (i
== ARRAY_SIZE(hw_list
)) {
1396 ath6kl_err("Unsupported hardware version: 0x%x\n",
1397 ar
->version
.target_ver
);
1403 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1404 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1405 ar
->version
.target_ver
, ar
->target_type
,
1406 ar
->hw
.dataset_patch_addr
, ar
->hw
.app_load_addr
);
1407 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1408 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1409 ar
->hw
.app_start_override_addr
, ar
->hw
.board_ext_data_addr
,
1410 ar
->hw
.reserved_ram_size
);
1411 ath6kl_dbg(ATH6KL_DBG_BOOT
,
1412 "refclk_hz %d uarttx_pin %d",
1413 ar
->hw
.refclk_hz
, ar
->hw
.uarttx_pin
);
1418 static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type
)
1421 case ATH6KL_HIF_TYPE_SDIO
:
1423 case ATH6KL_HIF_TYPE_USB
:
1430 int ath6kl_init_hw_start(struct ath6kl
*ar
)
1435 ath6kl_dbg(ATH6KL_DBG_BOOT
, "hw start\n");
1437 ret
= ath6kl_hif_power_on(ar
);
1441 ret
= ath6kl_configure_target(ar
);
1445 ret
= ath6kl_init_upload(ar
);
1449 /* Do we need to finish the BMI phase */
1450 /* FIXME: return error from ath6kl_bmi_done() */
1451 if (ath6kl_bmi_done(ar
)) {
1457 * The reason we have to wait for the target here is that the
1458 * driver layer has to init BMI in order to set the host block
1461 if (ath6kl_htc_wait_target(ar
->htc_target
)) {
1466 if (ath6kl_init_service_ep(ar
)) {
1468 goto err_cleanup_scatter
;
1471 /* setup credit distribution */
1472 ath6kl_credit_setup(ar
->htc_target
, &ar
->credit_state_info
);
1475 ret
= ath6kl_htc_start(ar
->htc_target
);
1477 /* FIXME: call this */
1478 ath6kl_cookie_cleanup(ar
);
1479 goto err_cleanup_scatter
;
1482 /* Wait for Wmi event to be ready */
1483 timeleft
= wait_event_interruptible_timeout(ar
->event_wq
,
1488 ath6kl_dbg(ATH6KL_DBG_BOOT
, "firmware booted\n");
1491 if (test_and_clear_bit(FIRST_BOOT
, &ar
->flag
)) {
1492 ath6kl_info("%s %s fw %s api %d%s\n",
1494 ath6kl_init_get_hif_name(ar
->hif_type
),
1495 ar
->wiphy
->fw_version
,
1497 test_bit(TESTMODE
, &ar
->flag
) ? " testmode" : "");
1500 if (ar
->version
.abi_ver
!= ATH6KL_ABI_VERSION
) {
1501 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1502 ATH6KL_ABI_VERSION
, ar
->version
.abi_ver
);
1507 if (!timeleft
|| signal_pending(current
)) {
1508 ath6kl_err("wmi is not ready or wait was interrupted\n");
1513 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: wmi is ready\n", __func__
);
1515 /* communicate the wmi protocol verision to the target */
1516 /* FIXME: return error */
1517 if ((ath6kl_set_host_app_area(ar
)) != 0)
1518 ath6kl_err("unable to set the host app area\n");
1520 for (i
= 0; i
< ar
->vif_max
; i
++) {
1521 ret
= ath6kl_target_config_wlan_params(ar
, i
);
1526 ar
->state
= ATH6KL_STATE_ON
;
1531 ath6kl_htc_stop(ar
->htc_target
);
1532 err_cleanup_scatter
:
1533 ath6kl_hif_cleanup_scatter(ar
);
1535 ath6kl_hif_power_off(ar
);
1540 int ath6kl_init_hw_stop(struct ath6kl
*ar
)
1544 ath6kl_dbg(ATH6KL_DBG_BOOT
, "hw stop\n");
1546 ath6kl_htc_stop(ar
->htc_target
);
1548 ath6kl_hif_stop(ar
);
1550 ath6kl_bmi_reset(ar
);
1552 ret
= ath6kl_hif_power_off(ar
);
1554 ath6kl_warn("failed to power off hif: %d\n", ret
);
1556 ar
->state
= ATH6KL_STATE_OFF
;
1561 int ath6kl_core_init(struct ath6kl
*ar
)
1563 struct ath6kl_bmi_target_info targ_info
;
1564 struct net_device
*ndev
;
1567 ar
->ath6kl_wq
= create_singlethread_workqueue("ath6kl");
1571 ret
= ath6kl_bmi_init(ar
);
1576 * Turn on power to get hardware (target) version and leave power
1577 * on delibrately as we will boot the hardware anyway within few
1580 ret
= ath6kl_hif_power_on(ar
);
1582 goto err_bmi_cleanup
;
1584 ret
= ath6kl_bmi_get_target_info(ar
, &targ_info
);
1588 ar
->version
.target_ver
= le32_to_cpu(targ_info
.version
);
1589 ar
->target_type
= le32_to_cpu(targ_info
.type
);
1590 ar
->wiphy
->hw_version
= le32_to_cpu(targ_info
.version
);
1592 ret
= ath6kl_init_hw_params(ar
);
1596 ar
->htc_target
= ath6kl_htc_create(ar
);
1598 if (!ar
->htc_target
) {
1603 ret
= ath6kl_fetch_firmwares(ar
);
1605 goto err_htc_cleanup
;
1607 /* FIXME: we should free all firmwares in the error cases below */
1609 /* Indicate that WMI is enabled (although not ready yet) */
1610 set_bit(WMI_ENABLED
, &ar
->flag
);
1611 ar
->wmi
= ath6kl_wmi_init(ar
);
1613 ath6kl_err("failed to initialize wmi\n");
1615 goto err_htc_cleanup
;
1618 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: got wmi @ 0x%p.\n", __func__
, ar
->wmi
);
1620 ret
= ath6kl_register_ieee80211_hw(ar
);
1622 goto err_node_cleanup
;
1624 ret
= ath6kl_debug_init(ar
);
1626 wiphy_unregister(ar
->wiphy
);
1627 goto err_node_cleanup
;
1630 for (i
= 0; i
< ar
->vif_max
; i
++)
1631 ar
->avail_idx_map
|= BIT(i
);
1635 /* Add an initial station interface */
1636 ndev
= ath6kl_interface_add(ar
, "wlan%d", NL80211_IFTYPE_STATION
, 0,
1642 ath6kl_err("Failed to instantiate a network device\n");
1644 wiphy_unregister(ar
->wiphy
);
1645 goto err_debug_init
;
1649 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: name=%s dev=0x%p, ar=0x%p\n",
1650 __func__
, ndev
->name
, ndev
, ar
);
1652 /* setup access class priority mappings */
1653 ar
->ac_stream_pri_map
[WMM_AC_BK
] = 0; /* lowest */
1654 ar
->ac_stream_pri_map
[WMM_AC_BE
] = 1;
1655 ar
->ac_stream_pri_map
[WMM_AC_VI
] = 2;
1656 ar
->ac_stream_pri_map
[WMM_AC_VO
] = 3; /* highest */
1658 /* give our connected endpoints some buffers */
1659 ath6kl_rx_refill(ar
->htc_target
, ar
->ctrl_ep
);
1660 ath6kl_rx_refill(ar
->htc_target
, ar
->ac2ep_map
[WMM_AC_BE
]);
1662 /* allocate some buffers that handle larger AMSDU frames */
1663 ath6kl_refill_amsdu_rxbufs(ar
, ATH6KL_MAX_AMSDU_RX_BUFFERS
);
1665 ath6kl_cookie_init(ar
);
1667 ar
->conf_flags
= ATH6KL_CONF_IGNORE_ERP_BARKER
|
1668 ATH6KL_CONF_ENABLE_11N
| ATH6KL_CONF_ENABLE_TX_BURST
;
1670 if (suspend_cutpower
)
1671 ar
->conf_flags
|= ATH6KL_CONF_SUSPEND_CUTPOWER
;
1673 ar
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_FW_ROAM
|
1674 WIPHY_FLAG_HAVE_AP_SME
|
1675 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
|
1676 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
1678 if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN
, ar
->fw_capabilities
))
1679 ar
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
1681 ar
->wiphy
->probe_resp_offload
=
1682 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
1683 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
1684 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
|
1685 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
;
1687 set_bit(FIRST_BOOT
, &ar
->flag
);
1689 ndev
->hw_features
|= NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
;
1691 ret
= ath6kl_init_hw_start(ar
);
1693 ath6kl_err("Failed to start hardware: %d\n", ret
);
1694 goto err_rxbuf_cleanup
;
1698 * Set mac address which is received in ready event
1699 * FIXME: Move to ath6kl_interface_add()
1701 memcpy(ndev
->dev_addr
, ar
->mac_addr
, ETH_ALEN
);
1706 ath6kl_htc_flush_rx_buf(ar
->htc_target
);
1707 ath6kl_cleanup_amsdu_rxbufs(ar
);
1709 ath6kl_deinit_if_data(netdev_priv(ndev
));
1711 wiphy_unregister(ar
->wiphy
);
1713 ath6kl_debug_cleanup(ar
);
1715 ath6kl_wmi_shutdown(ar
->wmi
);
1716 clear_bit(WMI_ENABLED
, &ar
->flag
);
1719 ath6kl_htc_cleanup(ar
->htc_target
);
1721 ath6kl_hif_power_off(ar
);
1723 ath6kl_bmi_cleanup(ar
);
1725 destroy_workqueue(ar
->ath6kl_wq
);
1730 void ath6kl_cleanup_vif(struct ath6kl_vif
*vif
, bool wmi_ready
)
1732 static u8 bcast_mac
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1735 netif_stop_queue(vif
->ndev
);
1737 clear_bit(WLAN_ENABLED
, &vif
->flags
);
1740 discon_issued
= test_bit(CONNECTED
, &vif
->flags
) ||
1741 test_bit(CONNECT_PEND
, &vif
->flags
);
1742 ath6kl_disconnect(vif
);
1743 del_timer(&vif
->disconnect_timer
);
1746 ath6kl_disconnect_event(vif
, DISCONNECT_CMD
,
1747 (vif
->nw_type
& AP_NETWORK
) ?
1748 bcast_mac
: vif
->bssid
,
1752 if (vif
->scan_req
) {
1753 cfg80211_scan_done(vif
->scan_req
, true);
1754 vif
->scan_req
= NULL
;
1758 void ath6kl_stop_txrx(struct ath6kl
*ar
)
1760 struct ath6kl_vif
*vif
, *tmp_vif
;
1762 set_bit(DESTROY_IN_PROGRESS
, &ar
->flag
);
1764 if (down_interruptible(&ar
->sem
)) {
1765 ath6kl_err("down_interruptible failed\n");
1769 spin_lock_bh(&ar
->list_lock
);
1770 list_for_each_entry_safe(vif
, tmp_vif
, &ar
->vif_list
, list
) {
1771 list_del(&vif
->list
);
1772 spin_unlock_bh(&ar
->list_lock
);
1773 ath6kl_cleanup_vif(vif
, test_bit(WMI_READY
, &ar
->flag
));
1775 ath6kl_deinit_if_data(vif
);
1777 spin_lock_bh(&ar
->list_lock
);
1779 spin_unlock_bh(&ar
->list_lock
);
1781 clear_bit(WMI_READY
, &ar
->flag
);
1784 * After wmi_shudown all WMI events will be dropped. We
1785 * need to cleanup the buffers allocated in AP mode and
1786 * give disconnect notification to stack, which usually
1787 * happens in the disconnect_event. Simulate the disconnect
1788 * event by calling the function directly. Sometimes
1789 * disconnect_event will be received when the debug logs
1792 ath6kl_wmi_shutdown(ar
->wmi
);
1794 clear_bit(WMI_ENABLED
, &ar
->flag
);
1795 if (ar
->htc_target
) {
1796 ath6kl_dbg(ATH6KL_DBG_TRC
, "%s: shut down htc\n", __func__
);
1797 ath6kl_htc_stop(ar
->htc_target
);
1801 * Try to reset the device if we can. The driver may have been
1802 * configure NOT to reset the target during a debug session.
1804 ath6kl_dbg(ATH6KL_DBG_TRC
,
1805 "attempting to reset target on instance destroy\n");
1806 ath6kl_reset_device(ar
, ar
->target_type
, true, true);
1808 clear_bit(WLAN_ENABLED
, &ar
->flag
);