blob: 075f16a80f05bf8bbc2de7fa6844e9c0a5c01ce8 [file] [log] [blame]
Kalle Valobdcd8172011-07-18 00:22:30 +03001
2/*
3 * Copyright (c) 2011 Atheros Communications Inc.
4 *
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.
8 *
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.
16 */
17
Stephen Rothwellc6efe5782011-09-28 18:32:34 +100018#include <linux/moduleparam.h>
Sangwook Leef7830202011-10-26 16:28:38 +010019#include <linux/errno.h>
Sam Leffler92ecbff2011-09-07 10:55:16 +030020#include <linux/of.h>
Kalle Valobdcd8172011-07-18 00:22:30 +030021#include <linux/mmc/sdio_func.h>
22#include "core.h"
23#include "cfg80211.h"
24#include "target.h"
25#include "debug.h"
26#include "hif-ops.h"
27
28unsigned int debug_mask;
Kalle Valo003353b0d2011-09-01 10:14:21 +030029static unsigned int testmode;
Kalle Valo8277de12011-11-03 12:18:31 +020030static bool suspend_cutpower;
Kalle Valobdcd8172011-07-18 00:22:30 +030031
32module_param(debug_mask, uint, 0644);
Kalle Valo003353b0d2011-09-01 10:14:21 +030033module_param(testmode, uint, 0644);
Kalle Valo8277de12011-11-03 12:18:31 +020034module_param(suspend_cutpower, bool, 0444);
Kalle Valobdcd8172011-07-18 00:22:30 +030035
Kalle Valo856f4b312011-11-14 19:30:29 +020036static const struct ath6kl_hw hw_list[] = {
37 {
Kalle Valo0d0192ba2011-11-14 19:31:07 +020038 .id = AR6003_HW_2_0_VERSION,
Kalle Valo293badf2011-11-14 19:30:54 +020039 .name = "ar6003 hw 2.0",
Kalle Valo856f4b312011-11-14 19:30:29 +020040 .dataset_patch_addr = 0x57e884,
41 .app_load_addr = 0x543180,
42 .board_ext_data_addr = 0x57e500,
43 .reserved_ram_size = 6912,
44
45 /* hw2.0 needs override address hardcoded */
46 .app_start_override_addr = 0x944C00,
Kalle Valod1a94212011-11-14 19:31:23 +020047
48 .fw_otp = AR6003_HW_2_0_OTP_FILE,
49 .fw = AR6003_HW_2_0_FIRMWARE_FILE,
50 .fw_tcmd = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
51 .fw_patch = AR6003_HW_2_0_PATCH_FILE,
52 .fw_api2 = AR6003_HW_2_0_FIRMWARE_2_FILE,
53 .fw_board = AR6003_HW_2_0_BOARD_DATA_FILE,
54 .fw_default_board = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
Kalle Valo856f4b312011-11-14 19:30:29 +020055 },
56 {
Kalle Valo0d0192ba2011-11-14 19:31:07 +020057 .id = AR6003_HW_2_1_1_VERSION,
Kalle Valo293badf2011-11-14 19:30:54 +020058 .name = "ar6003 hw 2.1.1",
Kalle Valo856f4b312011-11-14 19:30:29 +020059 .dataset_patch_addr = 0x57ff74,
60 .app_load_addr = 0x1234,
61 .board_ext_data_addr = 0x542330,
62 .reserved_ram_size = 512,
Kalle Valod1a94212011-11-14 19:31:23 +020063
64 .fw_otp = AR6003_HW_2_1_1_OTP_FILE,
65 .fw = AR6003_HW_2_1_1_FIRMWARE_FILE,
66 .fw_tcmd = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
67 .fw_patch = AR6003_HW_2_1_1_PATCH_FILE,
68 .fw_api2 = AR6003_HW_2_1_1_FIRMWARE_2_FILE,
69 .fw_board = AR6003_HW_2_1_1_BOARD_DATA_FILE,
70 .fw_default_board = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
Kalle Valo856f4b312011-11-14 19:30:29 +020071 },
72 {
Kalle Valo0d0192ba2011-11-14 19:31:07 +020073 .id = AR6004_HW_1_0_VERSION,
Kalle Valo293badf2011-11-14 19:30:54 +020074 .name = "ar6004 hw 1.0",
Kalle Valo856f4b312011-11-14 19:30:29 +020075 .dataset_patch_addr = 0x57e884,
76 .app_load_addr = 0x1234,
77 .board_ext_data_addr = 0x437000,
78 .reserved_ram_size = 19456,
Kalle Valo0d4d72b2011-11-14 19:30:39 +020079 .board_addr = 0x433900,
Kalle Valod1a94212011-11-14 19:31:23 +020080
81 .fw = AR6004_HW_1_0_FIRMWARE_FILE,
82 .fw_api2 = AR6004_HW_1_0_FIRMWARE_2_FILE,
83 .fw_board = AR6004_HW_1_0_BOARD_DATA_FILE,
84 .fw_default_board = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
Kalle Valo856f4b312011-11-14 19:30:29 +020085 },
86 {
Kalle Valo0d0192ba2011-11-14 19:31:07 +020087 .id = AR6004_HW_1_1_VERSION,
Kalle Valo293badf2011-11-14 19:30:54 +020088 .name = "ar6004 hw 1.1",
Kalle Valo856f4b312011-11-14 19:30:29 +020089 .dataset_patch_addr = 0x57e884,
90 .app_load_addr = 0x1234,
91 .board_ext_data_addr = 0x437000,
92 .reserved_ram_size = 11264,
Kalle Valo0d4d72b2011-11-14 19:30:39 +020093 .board_addr = 0x43d400,
Kalle Valod1a94212011-11-14 19:31:23 +020094
95 .fw = AR6004_HW_1_1_FIRMWARE_FILE,
96 .fw_api2 = AR6004_HW_1_1_FIRMWARE_2_FILE,
97 .fw_board = AR6004_HW_1_1_BOARD_DATA_FILE,
98 .fw_default_board = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
Kalle Valo856f4b312011-11-14 19:30:29 +020099 },
100};
101
Kalle Valobdcd8172011-07-18 00:22:30 +0300102/*
103 * Include definitions here that can be used to tune the WLAN module
104 * behavior. Different customers can tune the behavior as per their needs,
105 * here.
106 */
107
108/*
109 * This configuration item enable/disable keepalive support.
110 * Keepalive support: In the absence of any data traffic to AP, null
111 * frames will be sent to the AP at periodic interval, to keep the association
112 * active. This configuration item defines the periodic interval.
113 * Use value of zero to disable keepalive support
114 * Default: 60 seconds
115 */
116#define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
117
118/*
119 * This configuration item sets the value of disconnect timeout
120 * Firmware delays sending the disconnec event to the host for this
121 * timeout after is gets disconnected from the current AP.
122 * If the firmware successly roams within the disconnect timeout
123 * it sends a new connect event
124 */
125#define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
126
127#define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
128
Kalle Valobdcd8172011-07-18 00:22:30 +0300129#define ATH6KL_DATA_OFFSET 64
130struct sk_buff *ath6kl_buf_alloc(int size)
131{
132 struct sk_buff *skb;
133 u16 reserved;
134
135 /* Add chacheline space at front and back of buffer */
136 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +0530137 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +0300138 skb = dev_alloc_skb(size + reserved);
139
140 if (skb)
141 skb_reserve(skb, reserved - L1_CACHE_BYTES);
142 return skb;
143}
144
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530145void ath6kl_init_profile_info(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300146{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530147 vif->ssid_len = 0;
148 memset(vif->ssid, 0, sizeof(vif->ssid));
149
150 vif->dot11_auth_mode = OPEN_AUTH;
151 vif->auth_mode = NONE_AUTH;
152 vif->prwise_crypto = NONE_CRYPT;
153 vif->prwise_crypto_len = 0;
154 vif->grp_crypto = NONE_CRYPT;
155 vif->grp_crypto_len = 0;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530156 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +0530157 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
158 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530159 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300160}
161
Kalle Valobdcd8172011-07-18 00:22:30 +0300162static int ath6kl_set_host_app_area(struct ath6kl *ar)
163{
164 u32 address, data;
165 struct host_app_area host_app_area;
166
167 /* Fetch the address of the host_app_area_s
168 * instance in the host interest area */
169 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
Kevin Fang31024d92011-07-11 17:14:13 +0800170 address = TARG_VTOP(ar->target_type, address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300171
Kalle Valoaddb44b2011-09-02 10:32:05 +0300172 if (ath6kl_diag_read32(ar, address, &data))
Kalle Valobdcd8172011-07-18 00:22:30 +0300173 return -EIO;
174
Kevin Fang31024d92011-07-11 17:14:13 +0800175 address = TARG_VTOP(ar->target_type, data);
Kalle Valocbf49a62011-10-05 12:23:17 +0300176 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
Kalle Valoaddb44b2011-09-02 10:32:05 +0300177 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
178 sizeof(struct host_app_area)))
Kalle Valobdcd8172011-07-18 00:22:30 +0300179 return -EIO;
180
181 return 0;
182}
183
184static inline void set_ac2_ep_map(struct ath6kl *ar,
185 u8 ac,
186 enum htc_endpoint_id ep)
187{
188 ar->ac2ep_map[ac] = ep;
189 ar->ep2ac_map[ep] = ac;
190}
191
192/* connect to a service */
193static int ath6kl_connectservice(struct ath6kl *ar,
194 struct htc_service_connect_req *con_req,
195 char *desc)
196{
197 int status;
198 struct htc_service_connect_resp response;
199
200 memset(&response, 0, sizeof(response));
201
Kalle Vaload226ec2011-08-10 09:49:12 +0300202 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
Kalle Valobdcd8172011-07-18 00:22:30 +0300203 if (status) {
204 ath6kl_err("failed to connect to %s service status:%d\n",
205 desc, status);
206 return status;
207 }
208
209 switch (con_req->svc_id) {
210 case WMI_CONTROL_SVC:
211 if (test_bit(WMI_ENABLED, &ar->flag))
212 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
213 ar->ctrl_ep = response.endpoint;
214 break;
215 case WMI_DATA_BE_SVC:
216 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
217 break;
218 case WMI_DATA_BK_SVC:
219 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
220 break;
221 case WMI_DATA_VI_SVC:
222 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
223 break;
224 case WMI_DATA_VO_SVC:
225 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
226 break;
227 default:
228 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
229 return -EINVAL;
230 }
231
232 return 0;
233}
234
235static int ath6kl_init_service_ep(struct ath6kl *ar)
236{
237 struct htc_service_connect_req connect;
238
239 memset(&connect, 0, sizeof(connect));
240
241 /* these fields are the same for all service endpoints */
242 connect.ep_cb.rx = ath6kl_rx;
243 connect.ep_cb.rx_refill = ath6kl_rx_refill;
244 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
245
246 /*
247 * Set the max queue depth so that our ath6kl_tx_queue_full handler
248 * gets called.
249 */
250 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
251 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
252 if (!connect.ep_cb.rx_refill_thresh)
253 connect.ep_cb.rx_refill_thresh++;
254
255 /* connect to control service */
256 connect.svc_id = WMI_CONTROL_SVC;
257 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
258 return -EIO;
259
260 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
261
262 /*
263 * Limit the HTC message size on the send path, although e can
264 * receive A-MSDU frames of 4K, we will only send ethernet-sized
265 * (802.3) frames on the send path.
266 */
267 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
268
269 /*
270 * To reduce the amount of committed memory for larger A_MSDU
271 * frames, use the recv-alloc threshold mechanism for larger
272 * packets.
273 */
274 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
275 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
276
277 /*
278 * For the remaining data services set the connection flag to
279 * reduce dribbling, if configured to do so.
280 */
281 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
282 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
283 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
284
285 connect.svc_id = WMI_DATA_BE_SVC;
286
287 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
288 return -EIO;
289
290 /* connect to back-ground map this to WMI LOW_PRI */
291 connect.svc_id = WMI_DATA_BK_SVC;
292 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
293 return -EIO;
294
295 /* connect to Video service, map this to to HI PRI */
296 connect.svc_id = WMI_DATA_VI_SVC;
297 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
298 return -EIO;
299
300 /*
301 * Connect to VO service, this is currently not mapped to a WMI
302 * priority stream due to historical reasons. WMI originally
303 * defined 3 priorities over 3 mailboxes We can change this when
304 * WMI is reworked so that priorities are not dependent on
305 * mailboxes.
306 */
307 connect.svc_id = WMI_DATA_VO_SVC;
308 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
309 return -EIO;
310
311 return 0;
312}
313
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530314void ath6kl_init_control_info(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300315{
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530316 ath6kl_init_profile_info(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530317 vif->def_txkey_index = 0;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530318 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530319 vif->ch_hint = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300320}
321
322/*
323 * Set HTC/Mbox operational parameters, this can only be called when the
324 * target is in the BMI phase.
325 */
326static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
327 u8 htc_ctrl_buf)
328{
329 int status;
330 u32 blk_size;
331
332 blk_size = ar->mbox_info.block_size;
333
334 if (htc_ctrl_buf)
335 blk_size |= ((u32)htc_ctrl_buf) << 16;
336
337 /* set the host interest area for the block size */
338 status = ath6kl_bmi_write(ar,
339 ath6kl_get_hi_item_addr(ar,
340 HI_ITEM(hi_mbox_io_block_sz)),
341 (u8 *)&blk_size,
342 4);
343 if (status) {
344 ath6kl_err("bmi_write_memory for IO block size failed\n");
345 goto out;
346 }
347
348 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
349 blk_size,
350 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
351
352 if (mbox_isr_yield_val) {
353 /* set the host interest area for the mbox ISR yield limit */
354 status = ath6kl_bmi_write(ar,
355 ath6kl_get_hi_item_addr(ar,
356 HI_ITEM(hi_mbox_isr_yield_limit)),
357 (u8 *)&mbox_isr_yield_val,
358 4);
359 if (status) {
360 ath6kl_err("bmi_write_memory for yield limit failed\n");
361 goto out;
362 }
363 }
364
365out:
366 return status;
367}
368
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530369static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
Kalle Valobdcd8172011-07-18 00:22:30 +0300370{
371 int status = 0;
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300372 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300373
374 /*
375 * Configure the device for rx dot11 header rules. "0,0" are the
376 * default values. Required if checksum offload is needed. Set
377 * RxMetaVersion to 2.
378 */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530379 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300380 ar->rx_meta_ver, 0, 0)) {
381 ath6kl_err("unable to set the rx frame format\n");
382 status = -EIO;
383 }
384
385 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530386 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
Kalle Valobdcd8172011-07-18 00:22:30 +0300387 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
388 ath6kl_err("unable to set power save fail event policy\n");
389 status = -EIO;
390 }
391
392 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530393 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
Kalle Valobdcd8172011-07-18 00:22:30 +0300394 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
395 ath6kl_err("unable to set barker preamble policy\n");
396 status = -EIO;
397 }
398
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530399 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300400 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
401 ath6kl_err("unable to set keep alive interval\n");
402 status = -EIO;
403 }
404
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530405 if (ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300406 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
407 ath6kl_err("unable to set disconnect timeout\n");
408 status = -EIO;
409 }
410
411 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530412 if (ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300413 ath6kl_err("unable to set txop bursting\n");
414 status = -EIO;
415 }
416
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530417 /*
418 * FIXME: Make sure p2p configurations are not applied to
419 * non-p2p capable interfaces when multivif support is enabled.
420 */
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300421 if (ar->p2p) {
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530422 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300423 P2P_FLAG_CAPABILITIES_REQ |
424 P2P_FLAG_MACADDR_REQ |
425 P2P_FLAG_HMODEL_REQ);
426 if (ret) {
427 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
428 "capabilities (%d) - assuming P2P not "
429 "supported\n", ret);
430 ar->p2p = 0;
431 }
432 }
433
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530434 /*
435 * FIXME: Make sure p2p configurations are not applied to
436 * non-p2p capable interfaces when multivif support is enabled.
437 */
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300438 if (ar->p2p) {
439 /* Enable Probe Request reporting for P2P */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530440 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300441 if (ret) {
442 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
443 "Request reporting (%d)\n", ret);
444 }
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300445 }
446
Kalle Valobdcd8172011-07-18 00:22:30 +0300447 return status;
448}
449
450int ath6kl_configure_target(struct ath6kl *ar)
451{
452 u32 param, ram_reserved_size;
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530453 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530454 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300455
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530456 /*
457 * Note: Even though the firmware interface type is
458 * chosen as BSS_STA for all three interfaces, can
459 * be configured to IBSS/AP as long as the fw submode
460 * remains normal mode (0 - AP, STA and IBSS). But
461 * due to an target assert in firmware only one interface is
462 * configured for now.
463 */
Vasanthakumar Thiagarajandd3751f2011-10-25 19:33:59 +0530464 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
Kalle Valobdcd8172011-07-18 00:22:30 +0300465
Kalle Valo71f96ee2011-11-14 19:31:30 +0200466 for (i = 0; i < ar->vif_max; i++)
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530467 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
468
469 /*
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530470 * By default, submodes :
471 * vif[0] - AP/STA/IBSS
472 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
473 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530474 */
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530475
476 for (i = 0; i < ar->max_norm_iface; i++)
477 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
478 (i * HI_OPTION_FW_SUBMODE_BITS);
479
Kalle Valo71f96ee2011-11-14 19:31:30 +0200480 for (i = ar->max_norm_iface; i < ar->vif_max; i++)
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530481 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
482 (i * HI_OPTION_FW_SUBMODE_BITS);
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530483
484 /*
485 * FIXME: This needs to be removed once the multivif
486 * support is enabled.
487 */
488 if (ar->p2p)
489 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530490
Kalle Valobdcd8172011-07-18 00:22:30 +0300491 param = HTC_PROTOCOL_VERSION;
492 if (ath6kl_bmi_write(ar,
493 ath6kl_get_hi_item_addr(ar,
494 HI_ITEM(hi_app_host_interest)),
495 (u8 *)&param, 4) != 0) {
496 ath6kl_err("bmi_write_memory for htc version failed\n");
497 return -EIO;
498 }
499
500 /* set the firmware mode to STA/IBSS/AP */
501 param = 0;
502
503 if (ath6kl_bmi_read(ar,
504 ath6kl_get_hi_item_addr(ar,
505 HI_ITEM(hi_option_flag)),
506 (u8 *)&param, 4) != 0) {
507 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
508 return -EIO;
509 }
510
Kalle Valo71f96ee2011-11-14 19:31:30 +0200511 param |= (ar->vif_max << HI_OPTION_NUM_DEV_SHIFT);
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530512 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
513 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
514
Kalle Valobdcd8172011-07-18 00:22:30 +0300515 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
516 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
517
518 if (ath6kl_bmi_write(ar,
519 ath6kl_get_hi_item_addr(ar,
520 HI_ITEM(hi_option_flag)),
521 (u8 *)&param,
522 4) != 0) {
523 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
524 return -EIO;
525 }
526
527 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
528
529 /*
530 * Hardcode the address use for the extended board data
531 * Ideally this should be pre-allocate by the OS at boot time
532 * But since it is a new feature and board data is loaded
533 * at init time, we have to workaround this from host.
534 * It is difficult to patch the firmware boot code,
535 * but possible in theory.
536 */
537
Kalle Valo991b27e2011-09-07 10:55:17 +0300538 param = ar->hw.board_ext_data_addr;
539 ram_reserved_size = ar->hw.reserved_ram_size;
Kalle Valobdcd8172011-07-18 00:22:30 +0300540
Kalle Valo991b27e2011-09-07 10:55:17 +0300541 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
542 HI_ITEM(hi_board_ext_data)),
543 (u8 *)&param, 4) != 0) {
544 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
545 return -EIO;
546 }
547
548 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
549 HI_ITEM(hi_end_ram_reserve_sz)),
550 (u8 *)&ram_reserved_size, 4) != 0) {
551 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
552 return -EIO;
Kalle Valobdcd8172011-07-18 00:22:30 +0300553 }
554
555 /* set the block size for the target */
556 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
557 /* use default number of control buffers */
558 return -EIO;
559
560 return 0;
561}
562
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +0530563void ath6kl_core_free(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300564{
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +0530565 wiphy_free(ar->wiphy);
Kalle Valobdcd8172011-07-18 00:22:30 +0300566}
567
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530568void ath6kl_core_cleanup(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300569{
Kalle Valob2e75692011-10-27 18:48:14 +0300570 ath6kl_hif_power_off(ar);
571
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530572 destroy_workqueue(ar->ath6kl_wq);
Kalle Valobdcd8172011-07-18 00:22:30 +0300573
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530574 if (ar->htc_target)
575 ath6kl_htc_cleanup(ar->htc_target);
576
577 ath6kl_cookie_cleanup(ar);
578
579 ath6kl_cleanup_amsdu_rxbufs(ar);
580
581 ath6kl_bmi_cleanup(ar);
582
583 ath6kl_debug_cleanup(ar);
584
585 kfree(ar->fw_board);
586 kfree(ar->fw_otp);
587 kfree(ar->fw);
588 kfree(ar->fw_patch);
589
590 ath6kl_deinit_ieee80211_hw(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300591}
592
593/* firmware upload */
Kalle Valobdcd8172011-07-18 00:22:30 +0300594static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
595 u8 **fw, size_t *fw_len)
596{
597 const struct firmware *fw_entry;
598 int ret;
599
600 ret = request_firmware(&fw_entry, filename, ar->dev);
601 if (ret)
602 return ret;
603
604 *fw_len = fw_entry->size;
605 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
606
607 if (*fw == NULL)
608 ret = -ENOMEM;
609
610 release_firmware(fw_entry);
611
612 return ret;
613}
614
Sam Leffler92ecbff2011-09-07 10:55:16 +0300615#ifdef CONFIG_OF
616static const char *get_target_ver_dir(const struct ath6kl *ar)
617{
618 switch (ar->version.target_ver) {
Kalle Valo0d0192ba2011-11-14 19:31:07 +0200619 case AR6003_HW_1_0_VERSION:
Sam Leffler92ecbff2011-09-07 10:55:16 +0300620 return "ath6k/AR6003/hw1.0";
Kalle Valo0d0192ba2011-11-14 19:31:07 +0200621 case AR6003_HW_2_0_VERSION:
Sam Leffler92ecbff2011-09-07 10:55:16 +0300622 return "ath6k/AR6003/hw2.0";
Kalle Valo0d0192ba2011-11-14 19:31:07 +0200623 case AR6003_HW_2_1_1_VERSION:
Sam Leffler92ecbff2011-09-07 10:55:16 +0300624 return "ath6k/AR6003/hw2.1.1";
625 }
626 ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__,
627 ar->version.target_ver);
628 return NULL;
629}
630
631/*
632 * Check the device tree for a board-id and use it to construct
633 * the pathname to the firmware file. Used (for now) to find a
634 * fallback to the "bdata.bin" file--typically a symlink to the
635 * appropriate board-specific file.
636 */
637static bool check_device_tree(struct ath6kl *ar)
638{
639 static const char *board_id_prop = "atheros,board-id";
640 struct device_node *node;
641 char board_filename[64];
642 const char *board_id;
643 int ret;
644
645 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
646 board_id = of_get_property(node, board_id_prop, NULL);
647 if (board_id == NULL) {
648 ath6kl_warn("No \"%s\" property on %s node.\n",
649 board_id_prop, node->name);
650 continue;
651 }
652 snprintf(board_filename, sizeof(board_filename),
653 "%s/bdata.%s.bin", get_target_ver_dir(ar), board_id);
654
655 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
656 &ar->fw_board_len);
657 if (ret) {
658 ath6kl_err("Failed to get DT board file %s: %d\n",
659 board_filename, ret);
660 continue;
661 }
662 return true;
663 }
664 return false;
665}
666#else
667static bool check_device_tree(struct ath6kl *ar)
668{
669 return false;
670}
671#endif /* CONFIG_OF */
672
Kalle Valobdcd8172011-07-18 00:22:30 +0300673static int ath6kl_fetch_board_file(struct ath6kl *ar)
674{
675 const char *filename;
676 int ret;
677
Kalle Valo772c31e2011-09-07 10:55:16 +0300678 if (ar->fw_board != NULL)
679 return 0;
680
Kalle Valod1a94212011-11-14 19:31:23 +0200681 if (WARN_ON(ar->hw.fw_board == NULL))
682 return -EINVAL;
683
684 filename = ar->hw.fw_board;
Kalle Valobdcd8172011-07-18 00:22:30 +0300685
686 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
687 &ar->fw_board_len);
688 if (ret == 0) {
689 /* managed to get proper board file */
690 return 0;
691 }
692
Sam Leffler92ecbff2011-09-07 10:55:16 +0300693 if (check_device_tree(ar)) {
694 /* got board file from device tree */
695 return 0;
696 }
697
Kalle Valobdcd8172011-07-18 00:22:30 +0300698 /* there was no proper board file, try to use default instead */
699 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
700 filename, ret);
701
Kalle Valod1a94212011-11-14 19:31:23 +0200702 filename = ar->hw.fw_default_board;
Kalle Valobdcd8172011-07-18 00:22:30 +0300703
704 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
705 &ar->fw_board_len);
706 if (ret) {
707 ath6kl_err("Failed to get default board file %s: %d\n",
708 filename, ret);
709 return ret;
710 }
711
712 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
713 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
714
715 return 0;
716}
717
Kalle Valo772c31e2011-09-07 10:55:16 +0300718static int ath6kl_fetch_otp_file(struct ath6kl *ar)
719{
720 const char *filename;
721 int ret;
722
723 if (ar->fw_otp != NULL)
724 return 0;
725
Kalle Valod1a94212011-11-14 19:31:23 +0200726 if (ar->hw.fw_otp == NULL) {
727 ath6kl_dbg(ATH6KL_DBG_BOOT,
728 "no OTP file configured for this hw\n");
Kalle Valo772c31e2011-09-07 10:55:16 +0300729 return 0;
Kalle Valo772c31e2011-09-07 10:55:16 +0300730 }
731
Kalle Valod1a94212011-11-14 19:31:23 +0200732 filename = ar->hw.fw_otp;
733
Kalle Valo772c31e2011-09-07 10:55:16 +0300734 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
735 &ar->fw_otp_len);
736 if (ret) {
737 ath6kl_err("Failed to get OTP file %s: %d\n",
738 filename, ret);
739 return ret;
740 }
741
742 return 0;
743}
744
745static int ath6kl_fetch_fw_file(struct ath6kl *ar)
746{
747 const char *filename;
748 int ret;
749
750 if (ar->fw != NULL)
751 return 0;
752
753 if (testmode) {
Kalle Valod1a94212011-11-14 19:31:23 +0200754 if (ar->hw.fw_tcmd == NULL) {
755 ath6kl_warn("testmode not supported\n");
Kalle Valo772c31e2011-09-07 10:55:16 +0300756 return -EOPNOTSUPP;
Kalle Valo772c31e2011-09-07 10:55:16 +0300757 }
758
Kalle Valod1a94212011-11-14 19:31:23 +0200759 filename = ar->hw.fw_tcmd;
760
Kalle Valo772c31e2011-09-07 10:55:16 +0300761 set_bit(TESTMODE, &ar->flag);
762
763 goto get_fw;
764 }
765
Kalle Valod1a94212011-11-14 19:31:23 +0200766 if (WARN_ON(ar->hw.fw == NULL))
767 return -EINVAL;
768
769 filename = ar->hw.fw;
Kalle Valo772c31e2011-09-07 10:55:16 +0300770
771get_fw:
772 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
773 if (ret) {
774 ath6kl_err("Failed to get firmware file %s: %d\n",
775 filename, ret);
776 return ret;
777 }
778
779 return 0;
780}
781
782static int ath6kl_fetch_patch_file(struct ath6kl *ar)
783{
784 const char *filename;
785 int ret;
786
Kalle Valod1a94212011-11-14 19:31:23 +0200787 if (ar->fw_patch != NULL)
Kalle Valo772c31e2011-09-07 10:55:16 +0300788 return 0;
Kalle Valo772c31e2011-09-07 10:55:16 +0300789
Kalle Valod1a94212011-11-14 19:31:23 +0200790 if (ar->hw.fw_patch == NULL)
791 return 0;
792
793 filename = ar->hw.fw_patch;
794
795 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
796 &ar->fw_patch_len);
797 if (ret) {
798 ath6kl_err("Failed to get patch file %s: %d\n",
799 filename, ret);
800 return ret;
Kalle Valo772c31e2011-09-07 10:55:16 +0300801 }
802
803 return 0;
804}
805
Kalle Valo50d41232011-09-07 10:55:17 +0300806static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
Kalle Valo772c31e2011-09-07 10:55:16 +0300807{
808 int ret;
809
Kalle Valo772c31e2011-09-07 10:55:16 +0300810 ret = ath6kl_fetch_otp_file(ar);
811 if (ret)
812 return ret;
813
814 ret = ath6kl_fetch_fw_file(ar);
815 if (ret)
816 return ret;
817
818 ret = ath6kl_fetch_patch_file(ar);
819 if (ret)
820 return ret;
821
822 return 0;
823}
Kalle Valobdcd8172011-07-18 00:22:30 +0300824
Kalle Valo50d41232011-09-07 10:55:17 +0300825static int ath6kl_fetch_fw_api2(struct ath6kl *ar)
826{
827 size_t magic_len, len, ie_len;
828 const struct firmware *fw;
829 struct ath6kl_fw_ie *hdr;
830 const char *filename;
831 const u8 *data;
Kalle Valo97e04962011-09-12 13:47:34 +0300832 int ret, ie_id, i, index, bit;
Kalle Valo8a137482011-09-07 10:55:17 +0300833 __le32 *val;
Kalle Valo50d41232011-09-07 10:55:17 +0300834
Kalle Valod1a94212011-11-14 19:31:23 +0200835 if (ar->hw.fw_api2 == NULL)
Kalle Valo50d41232011-09-07 10:55:17 +0300836 return -EOPNOTSUPP;
Kalle Valod1a94212011-11-14 19:31:23 +0200837
838 filename = ar->hw.fw_api2;
Kalle Valo50d41232011-09-07 10:55:17 +0300839
840 ret = request_firmware(&fw, filename, ar->dev);
841 if (ret)
842 return ret;
843
844 data = fw->data;
845 len = fw->size;
846
847 /* magic also includes the null byte, check that as well */
848 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
849
850 if (len < magic_len) {
851 ret = -EINVAL;
852 goto out;
853 }
854
855 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
856 ret = -EINVAL;
857 goto out;
858 }
859
860 len -= magic_len;
861 data += magic_len;
862
863 /* loop elements */
864 while (len > sizeof(struct ath6kl_fw_ie)) {
865 /* hdr is unaligned! */
866 hdr = (struct ath6kl_fw_ie *) data;
867
868 ie_id = le32_to_cpup(&hdr->id);
869 ie_len = le32_to_cpup(&hdr->len);
870
871 len -= sizeof(*hdr);
872 data += sizeof(*hdr);
873
874 if (len < ie_len) {
875 ret = -EINVAL;
876 goto out;
877 }
878
879 switch (ie_id) {
880 case ATH6KL_FW_IE_OTP_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300881 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300882 ie_len);
883
Kalle Valo50d41232011-09-07 10:55:17 +0300884 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
885
886 if (ar->fw_otp == NULL) {
887 ret = -ENOMEM;
888 goto out;
889 }
890
891 ar->fw_otp_len = ie_len;
892 break;
893 case ATH6KL_FW_IE_FW_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300894 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300895 ie_len);
896
Kalle Valo50d41232011-09-07 10:55:17 +0300897 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
898
899 if (ar->fw == NULL) {
900 ret = -ENOMEM;
901 goto out;
902 }
903
904 ar->fw_len = ie_len;
905 break;
906 case ATH6KL_FW_IE_PATCH_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300907 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300908 ie_len);
909
Kalle Valo50d41232011-09-07 10:55:17 +0300910 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
911
912 if (ar->fw_patch == NULL) {
913 ret = -ENOMEM;
914 goto out;
915 }
916
917 ar->fw_patch_len = ie_len;
918 break;
Kalle Valo8a137482011-09-07 10:55:17 +0300919 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
920 val = (__le32 *) data;
921 ar->hw.reserved_ram_size = le32_to_cpup(val);
Kalle Valo6bc36432011-09-27 14:31:11 +0300922
923 ath6kl_dbg(ATH6KL_DBG_BOOT,
924 "found reserved ram size ie 0x%d\n",
925 ar->hw.reserved_ram_size);
Kalle Valo8a137482011-09-07 10:55:17 +0300926 break;
Kalle Valo97e04962011-09-12 13:47:34 +0300927 case ATH6KL_FW_IE_CAPABILITIES:
Kalle Valo6bc36432011-09-27 14:31:11 +0300928 ath6kl_dbg(ATH6KL_DBG_BOOT,
Kalle Valoef548622011-10-01 09:43:09 +0300929 "found firmware capabilities ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300930 ie_len);
931
Kalle Valo97e04962011-09-12 13:47:34 +0300932 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
933 index = ALIGN(i, 8) / 8;
934 bit = i % 8;
935
936 if (data[index] & (1 << bit))
937 __set_bit(i, ar->fw_capabilities);
938 }
Kalle Valo6bc36432011-09-27 14:31:11 +0300939
940 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
941 ar->fw_capabilities,
942 sizeof(ar->fw_capabilities));
Kalle Valo97e04962011-09-12 13:47:34 +0300943 break;
Kalle Valo1b4304d2011-09-27 11:05:26 +0300944 case ATH6KL_FW_IE_PATCH_ADDR:
945 if (ie_len != sizeof(*val))
946 break;
947
948 val = (__le32 *) data;
949 ar->hw.dataset_patch_addr = le32_to_cpup(val);
Kalle Valo6bc36432011-09-27 14:31:11 +0300950
951 ath6kl_dbg(ATH6KL_DBG_BOOT,
Kalle Valo03ef0252011-11-14 19:30:47 +0200952 "found patch address ie 0x%x\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300953 ar->hw.dataset_patch_addr);
Kalle Valo1b4304d2011-09-27 11:05:26 +0300954 break;
Kalle Valo03ef0252011-11-14 19:30:47 +0200955 case ATH6KL_FW_IE_BOARD_ADDR:
956 if (ie_len != sizeof(*val))
957 break;
958
959 val = (__le32 *) data;
960 ar->hw.board_addr = le32_to_cpup(val);
961
962 ath6kl_dbg(ATH6KL_DBG_BOOT,
963 "found board address ie 0x%x\n",
964 ar->hw.board_addr);
965 break;
Kalle Valo368b1b02011-11-14 19:31:38 +0200966 case ATH6KL_FW_IE_VIF_MAX:
967 if (ie_len != sizeof(*val))
968 break;
969
970 val = (__le32 *) data;
971 ar->vif_max = min_t(unsigned int, le32_to_cpup(val),
972 ATH6KL_VIF_MAX);
973
Vasanthakumar Thiagarajanf1433792011-11-18 10:05:27 +0530974 if (ar->vif_max > 1 && !ar->p2p)
975 ar->max_norm_iface = 2;
976
Kalle Valo368b1b02011-11-14 19:31:38 +0200977 ath6kl_dbg(ATH6KL_DBG_BOOT,
978 "found vif max ie %d\n", ar->vif_max);
979 break;
Kalle Valo50d41232011-09-07 10:55:17 +0300980 default:
Kalle Valo6bc36432011-09-27 14:31:11 +0300981 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
Kalle Valo50d41232011-09-07 10:55:17 +0300982 le32_to_cpup(&hdr->id));
983 break;
984 }
985
986 len -= ie_len;
987 data += ie_len;
988 };
989
990 ret = 0;
991out:
992 release_firmware(fw);
993
994 return ret;
995}
996
997static int ath6kl_fetch_firmwares(struct ath6kl *ar)
998{
999 int ret;
1000
1001 ret = ath6kl_fetch_board_file(ar);
1002 if (ret)
1003 return ret;
1004
1005 ret = ath6kl_fetch_fw_api2(ar);
Kalle Valo6bc36432011-09-27 14:31:11 +03001006 if (ret == 0) {
1007 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 2\n");
Kalle Valo50d41232011-09-07 10:55:17 +03001008 return 0;
Kalle Valo6bc36432011-09-27 14:31:11 +03001009 }
Kalle Valo50d41232011-09-07 10:55:17 +03001010
1011 ret = ath6kl_fetch_fw_api1(ar);
1012 if (ret)
1013 return ret;
1014
Kalle Valo6bc36432011-09-27 14:31:11 +03001015 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 1\n");
1016
Kalle Valo50d41232011-09-07 10:55:17 +03001017 return 0;
1018}
1019
Kalle Valobdcd8172011-07-18 00:22:30 +03001020static int ath6kl_upload_board_file(struct ath6kl *ar)
1021{
1022 u32 board_address, board_ext_address, param;
Kevin Fang31024d92011-07-11 17:14:13 +08001023 u32 board_data_size, board_ext_data_size;
Kalle Valobdcd8172011-07-18 00:22:30 +03001024 int ret;
1025
Kalle Valo772c31e2011-09-07 10:55:16 +03001026 if (WARN_ON(ar->fw_board == NULL))
1027 return -ENOENT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001028
Kevin Fang31024d92011-07-11 17:14:13 +08001029 /*
1030 * Determine where in Target RAM to write Board Data.
1031 * For AR6004, host determine Target RAM address for
1032 * writing board data.
1033 */
Kalle Valo0d4d72b2011-11-14 19:30:39 +02001034 if (ar->hw.board_addr != 0) {
1035 board_address = ar->hw.board_addr;
Kevin Fang31024d92011-07-11 17:14:13 +08001036 ath6kl_bmi_write(ar,
1037 ath6kl_get_hi_item_addr(ar,
1038 HI_ITEM(hi_board_data)),
1039 (u8 *) &board_address, 4);
1040 } else {
1041 ath6kl_bmi_read(ar,
1042 ath6kl_get_hi_item_addr(ar,
1043 HI_ITEM(hi_board_data)),
1044 (u8 *) &board_address, 4);
1045 }
1046
Kalle Valobdcd8172011-07-18 00:22:30 +03001047 /* determine where in target ram to write extended board data */
1048 ath6kl_bmi_read(ar,
1049 ath6kl_get_hi_item_addr(ar,
1050 HI_ITEM(hi_board_ext_data)),
1051 (u8 *) &board_ext_address, 4);
1052
Kalle Valo50e27402011-11-11 12:18:06 +02001053 if (ar->target_type == TARGET_TYPE_AR6003 &&
1054 board_ext_address == 0) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001055 ath6kl_err("Failed to get board file target address.\n");
1056 return -EINVAL;
1057 }
1058
Kevin Fang31024d92011-07-11 17:14:13 +08001059 switch (ar->target_type) {
1060 case TARGET_TYPE_AR6003:
1061 board_data_size = AR6003_BOARD_DATA_SZ;
1062 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1063 break;
1064 case TARGET_TYPE_AR6004:
1065 board_data_size = AR6004_BOARD_DATA_SZ;
1066 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1067 break;
1068 default:
1069 WARN_ON(1);
1070 return -EINVAL;
1071 break;
1072 }
1073
Kalle Valo50e27402011-11-11 12:18:06 +02001074 if (board_ext_address &&
1075 ar->fw_board_len == (board_data_size + board_ext_data_size)) {
Kevin Fang31024d92011-07-11 17:14:13 +08001076
Kalle Valobdcd8172011-07-18 00:22:30 +03001077 /* write extended board data */
Kalle Valo6bc36432011-09-27 14:31:11 +03001078 ath6kl_dbg(ATH6KL_DBG_BOOT,
1079 "writing extended board data to 0x%x (%d B)\n",
1080 board_ext_address, board_ext_data_size);
1081
Kalle Valobdcd8172011-07-18 00:22:30 +03001082 ret = ath6kl_bmi_write(ar, board_ext_address,
Kevin Fang31024d92011-07-11 17:14:13 +08001083 ar->fw_board + board_data_size,
1084 board_ext_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +03001085 if (ret) {
1086 ath6kl_err("Failed to write extended board data: %d\n",
1087 ret);
1088 return ret;
1089 }
1090
1091 /* record that extended board data is initialized */
Kevin Fang31024d92011-07-11 17:14:13 +08001092 param = (board_ext_data_size << 16) | 1;
1093
Kalle Valobdcd8172011-07-18 00:22:30 +03001094 ath6kl_bmi_write(ar,
1095 ath6kl_get_hi_item_addr(ar,
1096 HI_ITEM(hi_board_ext_data_config)),
1097 (unsigned char *) &param, 4);
1098 }
1099
Kevin Fang31024d92011-07-11 17:14:13 +08001100 if (ar->fw_board_len < board_data_size) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001101 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1102 ret = -EINVAL;
1103 return ret;
1104 }
1105
Kalle Valo6bc36432011-09-27 14:31:11 +03001106 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1107 board_address, board_data_size);
1108
Kalle Valobdcd8172011-07-18 00:22:30 +03001109 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
Kevin Fang31024d92011-07-11 17:14:13 +08001110 board_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +03001111
1112 if (ret) {
1113 ath6kl_err("Board file bmi write failed: %d\n", ret);
1114 return ret;
1115 }
1116
1117 /* record the fact that Board Data IS initialized */
1118 param = 1;
1119 ath6kl_bmi_write(ar,
1120 ath6kl_get_hi_item_addr(ar,
1121 HI_ITEM(hi_board_data_initialized)),
1122 (u8 *)&param, 4);
1123
1124 return ret;
1125}
1126
1127static int ath6kl_upload_otp(struct ath6kl *ar)
1128{
Kalle Valobdcd8172011-07-18 00:22:30 +03001129 u32 address, param;
Kalle Valobef26a72011-10-12 09:58:28 +03001130 bool from_hw = false;
Kalle Valobdcd8172011-07-18 00:22:30 +03001131 int ret;
1132
Kalle Valo50e27402011-11-11 12:18:06 +02001133 if (ar->fw_otp == NULL)
1134 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001135
Kalle Valoa01ac412011-09-07 10:55:17 +03001136 address = ar->hw.app_load_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001137
Kalle Valoef548622011-10-01 09:43:09 +03001138 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
Kalle Valo6bc36432011-09-27 14:31:11 +03001139 ar->fw_otp_len);
1140
Kalle Valobdcd8172011-07-18 00:22:30 +03001141 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1142 ar->fw_otp_len);
1143 if (ret) {
1144 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1145 return ret;
1146 }
1147
Kalle Valo639d0b82011-09-12 12:48:09 +03001148 /* read firmware start address */
1149 ret = ath6kl_bmi_read(ar,
1150 ath6kl_get_hi_item_addr(ar,
1151 HI_ITEM(hi_app_start)),
1152 (u8 *) &address, sizeof(address));
1153
1154 if (ret) {
1155 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1156 return ret;
1157 }
1158
Kalle Valobef26a72011-10-12 09:58:28 +03001159 if (ar->hw.app_start_override_addr == 0) {
1160 ar->hw.app_start_override_addr = address;
1161 from_hw = true;
1162 }
Kalle Valo639d0b82011-09-12 12:48:09 +03001163
Kalle Valobef26a72011-10-12 09:58:28 +03001164 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1165 from_hw ? " (from hw)" : "",
Kalle Valo6bc36432011-09-27 14:31:11 +03001166 ar->hw.app_start_override_addr);
1167
Kalle Valobdcd8172011-07-18 00:22:30 +03001168 /* execute the OTP code */
Kalle Valobef26a72011-10-12 09:58:28 +03001169 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1170 ar->hw.app_start_override_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001171 param = 0;
Kalle Valobef26a72011-10-12 09:58:28 +03001172 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, &param);
Kalle Valobdcd8172011-07-18 00:22:30 +03001173
1174 return ret;
1175}
1176
1177static int ath6kl_upload_firmware(struct ath6kl *ar)
1178{
Kalle Valobdcd8172011-07-18 00:22:30 +03001179 u32 address;
1180 int ret;
1181
Kalle Valo772c31e2011-09-07 10:55:16 +03001182 if (WARN_ON(ar->fw == NULL))
Kalle Valo50e27402011-11-11 12:18:06 +02001183 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001184
Kalle Valoa01ac412011-09-07 10:55:17 +03001185 address = ar->hw.app_load_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001186
Kalle Valoef548622011-10-01 09:43:09 +03001187 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +03001188 address, ar->fw_len);
1189
Kalle Valobdcd8172011-07-18 00:22:30 +03001190 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1191
1192 if (ret) {
1193 ath6kl_err("Failed to write firmware: %d\n", ret);
1194 return ret;
1195 }
1196
Kevin Fang31024d92011-07-11 17:14:13 +08001197 /*
1198 * Set starting address for firmware
1199 * Don't need to setup app_start override addr on AR6004
1200 */
1201 if (ar->target_type != TARGET_TYPE_AR6004) {
Kalle Valoa01ac412011-09-07 10:55:17 +03001202 address = ar->hw.app_start_override_addr;
Kevin Fang31024d92011-07-11 17:14:13 +08001203 ath6kl_bmi_set_app_start(ar, address);
1204 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001205 return ret;
1206}
1207
1208static int ath6kl_upload_patch(struct ath6kl *ar)
1209{
Kalle Valobdcd8172011-07-18 00:22:30 +03001210 u32 address, param;
1211 int ret;
1212
Kalle Valo50e27402011-11-11 12:18:06 +02001213 if (ar->fw_patch == NULL)
1214 return 0;
Kalle Valobdcd8172011-07-18 00:22:30 +03001215
Kalle Valoa01ac412011-09-07 10:55:17 +03001216 address = ar->hw.dataset_patch_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001217
Kalle Valoef548622011-10-01 09:43:09 +03001218 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +03001219 address, ar->fw_patch_len);
1220
Kalle Valobdcd8172011-07-18 00:22:30 +03001221 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1222 if (ret) {
1223 ath6kl_err("Failed to write patch file: %d\n", ret);
1224 return ret;
1225 }
1226
1227 param = address;
1228 ath6kl_bmi_write(ar,
1229 ath6kl_get_hi_item_addr(ar,
1230 HI_ITEM(hi_dset_list_head)),
1231 (unsigned char *) &param, 4);
1232
1233 return 0;
1234}
1235
1236static int ath6kl_init_upload(struct ath6kl *ar)
1237{
1238 u32 param, options, sleep, address;
1239 int status = 0;
1240
Kevin Fang31024d92011-07-11 17:14:13 +08001241 if (ar->target_type != TARGET_TYPE_AR6003 &&
1242 ar->target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +03001243 return -EINVAL;
1244
1245 /* temporarily disable system sleep */
1246 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1247 status = ath6kl_bmi_reg_read(ar, address, &param);
1248 if (status)
1249 return status;
1250
1251 options = param;
1252
1253 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1254 status = ath6kl_bmi_reg_write(ar, address, param);
1255 if (status)
1256 return status;
1257
1258 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1259 status = ath6kl_bmi_reg_read(ar, address, &param);
1260 if (status)
1261 return status;
1262
1263 sleep = param;
1264
1265 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1266 status = ath6kl_bmi_reg_write(ar, address, param);
1267 if (status)
1268 return status;
1269
1270 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1271 options, sleep);
1272
1273 /* program analog PLL register */
Kevin Fang31024d92011-07-11 17:14:13 +08001274 /* no need to control 40/44MHz clock on AR6004 */
1275 if (ar->target_type != TARGET_TYPE_AR6004) {
1276 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1277 0xF9104001);
Kalle Valobdcd8172011-07-18 00:22:30 +03001278
Kevin Fang31024d92011-07-11 17:14:13 +08001279 if (status)
1280 return status;
Kalle Valobdcd8172011-07-18 00:22:30 +03001281
Kevin Fang31024d92011-07-11 17:14:13 +08001282 /* Run at 80/88MHz by default */
1283 param = SM(CPU_CLOCK_STANDARD, 1);
1284
1285 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1286 status = ath6kl_bmi_reg_write(ar, address, param);
1287 if (status)
1288 return status;
1289 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001290
1291 param = 0;
1292 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1293 param = SM(LPO_CAL_ENABLE, 1);
1294 status = ath6kl_bmi_reg_write(ar, address, param);
1295 if (status)
1296 return status;
1297
1298 /* WAR to avoid SDIO CRC err */
Kalle Valo0d0192ba2011-11-14 19:31:07 +02001299 if (ar->version.target_ver == AR6003_HW_2_0_VERSION) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001300 ath6kl_err("temporary war to avoid sdio crc error\n");
1301
1302 param = 0x20;
1303
1304 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1305 status = ath6kl_bmi_reg_write(ar, address, param);
1306 if (status)
1307 return status;
1308
1309 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1310 status = ath6kl_bmi_reg_write(ar, address, param);
1311 if (status)
1312 return status;
1313
1314 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1315 status = ath6kl_bmi_reg_write(ar, address, param);
1316 if (status)
1317 return status;
1318
1319 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1320 status = ath6kl_bmi_reg_write(ar, address, param);
1321 if (status)
1322 return status;
1323 }
1324
1325 /* write EEPROM data to Target RAM */
1326 status = ath6kl_upload_board_file(ar);
1327 if (status)
1328 return status;
1329
1330 /* transfer One time Programmable data */
1331 status = ath6kl_upload_otp(ar);
1332 if (status)
1333 return status;
1334
1335 /* Download Target firmware */
1336 status = ath6kl_upload_firmware(ar);
1337 if (status)
1338 return status;
1339
1340 status = ath6kl_upload_patch(ar);
1341 if (status)
1342 return status;
1343
1344 /* Restore system sleep */
1345 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1346 status = ath6kl_bmi_reg_write(ar, address, sleep);
1347 if (status)
1348 return status;
1349
1350 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1351 param = options | 0x20;
1352 status = ath6kl_bmi_reg_write(ar, address, param);
1353 if (status)
1354 return status;
1355
1356 /* Configure GPIO AR6003 UART */
1357 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1358 status = ath6kl_bmi_write(ar,
1359 ath6kl_get_hi_item_addr(ar,
1360 HI_ITEM(hi_dbg_uart_txpin)),
1361 (u8 *)&param, 4);
1362
1363 return status;
1364}
1365
Kalle Valoa01ac412011-09-07 10:55:17 +03001366static int ath6kl_init_hw_params(struct ath6kl *ar)
1367{
Kalle Valo856f4b312011-11-14 19:30:29 +02001368 const struct ath6kl_hw *hw;
1369 int i;
Kalle Valobef26a72011-10-12 09:58:28 +03001370
Kalle Valo856f4b312011-11-14 19:30:29 +02001371 for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
1372 hw = &hw_list[i];
Kalle Valobef26a72011-10-12 09:58:28 +03001373
Kalle Valo856f4b312011-11-14 19:30:29 +02001374 if (hw->id == ar->version.target_ver)
1375 break;
1376 }
1377
1378 if (i == ARRAY_SIZE(hw_list)) {
Kalle Valoa01ac412011-09-07 10:55:17 +03001379 ath6kl_err("Unsupported hardware version: 0x%x\n",
1380 ar->version.target_ver);
1381 return -EINVAL;
1382 }
1383
Kalle Valo856f4b312011-11-14 19:30:29 +02001384 ar->hw = *hw;
1385
Kalle Valo6bc36432011-09-27 14:31:11 +03001386 ath6kl_dbg(ATH6KL_DBG_BOOT,
1387 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1388 ar->version.target_ver, ar->target_type,
1389 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1390 ath6kl_dbg(ATH6KL_DBG_BOOT,
1391 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1392 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1393 ar->hw.reserved_ram_size);
1394
Kalle Valoa01ac412011-09-07 10:55:17 +03001395 return 0;
1396}
1397
Kalle Valo293badf2011-11-14 19:30:54 +02001398static const char *ath6kl_init_get_hif_name(enum ath6kl_hif_type type)
1399{
1400 switch (type) {
1401 case ATH6KL_HIF_TYPE_SDIO:
1402 return "sdio";
1403 case ATH6KL_HIF_TYPE_USB:
1404 return "usb";
1405 }
1406
1407 return NULL;
1408}
1409
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001410int ath6kl_init_hw_start(struct ath6kl *ar)
Kalle Valo20459ee2011-10-27 18:48:37 +03001411{
1412 long timeleft;
1413 int ret, i;
1414
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001415 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
1416
Kalle Valo20459ee2011-10-27 18:48:37 +03001417 ret = ath6kl_hif_power_on(ar);
1418 if (ret)
1419 return ret;
1420
1421 ret = ath6kl_configure_target(ar);
1422 if (ret)
1423 goto err_power_off;
1424
1425 ret = ath6kl_init_upload(ar);
1426 if (ret)
1427 goto err_power_off;
1428
1429 /* Do we need to finish the BMI phase */
1430 /* FIXME: return error from ath6kl_bmi_done() */
1431 if (ath6kl_bmi_done(ar)) {
1432 ret = -EIO;
1433 goto err_power_off;
1434 }
1435
1436 /*
1437 * The reason we have to wait for the target here is that the
1438 * driver layer has to init BMI in order to set the host block
1439 * size.
1440 */
1441 if (ath6kl_htc_wait_target(ar->htc_target)) {
1442 ret = -EIO;
1443 goto err_power_off;
1444 }
1445
1446 if (ath6kl_init_service_ep(ar)) {
1447 ret = -EIO;
1448 goto err_cleanup_scatter;
1449 }
1450
1451 /* setup credit distribution */
1452 ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
1453
1454 /* start HTC */
1455 ret = ath6kl_htc_start(ar->htc_target);
1456 if (ret) {
1457 /* FIXME: call this */
1458 ath6kl_cookie_cleanup(ar);
1459 goto err_cleanup_scatter;
1460 }
1461
1462 /* Wait for Wmi event to be ready */
1463 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1464 test_bit(WMI_READY,
1465 &ar->flag),
1466 WMI_TIMEOUT);
1467
1468 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1469
Kalle Valo293badf2011-11-14 19:30:54 +02001470
1471 if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
1472 ath6kl_info("%s %s fw %s%s\n",
1473 ar->hw.name,
1474 ath6kl_init_get_hif_name(ar->hif_type),
1475 ar->wiphy->fw_version,
1476 test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
1477 }
1478
Kalle Valo20459ee2011-10-27 18:48:37 +03001479 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1480 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1481 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1482 ret = -EIO;
1483 goto err_htc_stop;
1484 }
1485
1486 if (!timeleft || signal_pending(current)) {
1487 ath6kl_err("wmi is not ready or wait was interrupted\n");
1488 ret = -EIO;
1489 goto err_htc_stop;
1490 }
1491
1492 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1493
1494 /* communicate the wmi protocol verision to the target */
1495 /* FIXME: return error */
1496 if ((ath6kl_set_host_app_area(ar)) != 0)
1497 ath6kl_err("unable to set the host app area\n");
1498
Kalle Valo71f96ee2011-11-14 19:31:30 +02001499 for (i = 0; i < ar->vif_max; i++) {
Kalle Valo20459ee2011-10-27 18:48:37 +03001500 ret = ath6kl_target_config_wlan_params(ar, i);
1501 if (ret)
1502 goto err_htc_stop;
1503 }
1504
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001505 ar->state = ATH6KL_STATE_ON;
1506
Kalle Valo20459ee2011-10-27 18:48:37 +03001507 return 0;
1508
1509err_htc_stop:
1510 ath6kl_htc_stop(ar->htc_target);
1511err_cleanup_scatter:
1512 ath6kl_hif_cleanup_scatter(ar);
1513err_power_off:
1514 ath6kl_hif_power_off(ar);
1515
1516 return ret;
1517}
1518
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001519int ath6kl_init_hw_stop(struct ath6kl *ar)
1520{
1521 int ret;
1522
1523 ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
1524
1525 ath6kl_htc_stop(ar->htc_target);
1526
1527 ath6kl_hif_stop(ar);
1528
1529 ath6kl_bmi_reset(ar);
1530
1531 ret = ath6kl_hif_power_off(ar);
1532 if (ret)
1533 ath6kl_warn("failed to power off hif: %d\n", ret);
1534
Kalle Valo76a9fbe2011-11-01 08:44:28 +02001535 ar->state = ATH6KL_STATE_OFF;
1536
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001537 return 0;
1538}
1539
Kalle Valobdcd8172011-07-18 00:22:30 +03001540int ath6kl_core_init(struct ath6kl *ar)
1541{
Kalle Valobdcd8172011-07-18 00:22:30 +03001542 struct ath6kl_bmi_target_info targ_info;
Kalle Valo61448a92011-10-27 18:48:29 +03001543 struct net_device *ndev;
Kalle Valo20459ee2011-10-27 18:48:37 +03001544 int ret = 0, i;
Kalle Valobdcd8172011-07-18 00:22:30 +03001545
1546 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1547 if (!ar->ath6kl_wq)
1548 return -ENOMEM;
1549
1550 ret = ath6kl_bmi_init(ar);
1551 if (ret)
1552 goto err_wq;
1553
Kalle Valo20459ee2011-10-27 18:48:37 +03001554 /*
1555 * Turn on power to get hardware (target) version and leave power
1556 * on delibrately as we will boot the hardware anyway within few
1557 * seconds.
1558 */
Kalle Valob2e75692011-10-27 18:48:14 +03001559 ret = ath6kl_hif_power_on(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001560 if (ret)
1561 goto err_bmi_cleanup;
1562
Kalle Valob2e75692011-10-27 18:48:14 +03001563 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1564 if (ret)
1565 goto err_power_off;
1566
Kalle Valobdcd8172011-07-18 00:22:30 +03001567 ar->version.target_ver = le32_to_cpu(targ_info.version);
1568 ar->target_type = le32_to_cpu(targ_info.type);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301569 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
Kalle Valobdcd8172011-07-18 00:22:30 +03001570
Kalle Valoa01ac412011-09-07 10:55:17 +03001571 ret = ath6kl_init_hw_params(ar);
1572 if (ret)
Kalle Valob2e75692011-10-27 18:48:14 +03001573 goto err_power_off;
Kalle Valoa01ac412011-09-07 10:55:17 +03001574
Kalle Vaload226ec2011-08-10 09:49:12 +03001575 ar->htc_target = ath6kl_htc_create(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001576
1577 if (!ar->htc_target) {
1578 ret = -ENOMEM;
Kalle Valob2e75692011-10-27 18:48:14 +03001579 goto err_power_off;
Kalle Valobdcd8172011-07-18 00:22:30 +03001580 }
1581
Kalle Valo772c31e2011-09-07 10:55:16 +03001582 ret = ath6kl_fetch_firmwares(ar);
1583 if (ret)
1584 goto err_htc_cleanup;
1585
Kalle Valo61448a92011-10-27 18:48:29 +03001586 /* FIXME: we should free all firmwares in the error cases below */
1587
Kalle Valo61448a92011-10-27 18:48:29 +03001588 /* Indicate that WMI is enabled (although not ready yet) */
1589 set_bit(WMI_ENABLED, &ar->flag);
1590 ar->wmi = ath6kl_wmi_init(ar);
1591 if (!ar->wmi) {
1592 ath6kl_err("failed to initialize wmi\n");
1593 ret = -EIO;
1594 goto err_htc_cleanup;
1595 }
1596
1597 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1598
1599 ret = ath6kl_register_ieee80211_hw(ar);
1600 if (ret)
1601 goto err_node_cleanup;
1602
1603 ret = ath6kl_debug_init(ar);
1604 if (ret) {
1605 wiphy_unregister(ar->wiphy);
1606 goto err_node_cleanup;
1607 }
1608
Kalle Valo71f96ee2011-11-14 19:31:30 +02001609 for (i = 0; i < ar->vif_max; i++)
Kalle Valo61448a92011-10-27 18:48:29 +03001610 ar->avail_idx_map |= BIT(i);
1611
1612 rtnl_lock();
1613
1614 /* Add an initial station interface */
1615 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
1616 INFRA_NETWORK);
1617
1618 rtnl_unlock();
1619
1620 if (!ndev) {
1621 ath6kl_err("Failed to instantiate a network device\n");
1622 ret = -ENOMEM;
1623 wiphy_unregister(ar->wiphy);
1624 goto err_debug_init;
1625 }
1626
1627
1628 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1629 __func__, ndev->name, ndev, ar);
1630
Kalle Valo61448a92011-10-27 18:48:29 +03001631 /* setup access class priority mappings */
1632 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1633 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1634 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1635 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1636
1637 /* give our connected endpoints some buffers */
1638 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1639 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1640
1641 /* allocate some buffers that handle larger AMSDU frames */
1642 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1643
Kalle Valo61448a92011-10-27 18:48:29 +03001644 ath6kl_cookie_init(ar);
1645
Kalle Valo61448a92011-10-27 18:48:29 +03001646 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1647 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1648
Kalle Valo8277de12011-11-03 12:18:31 +02001649 if (suspend_cutpower)
1650 ar->conf_flags |= ATH6KL_CONF_SUSPEND_CUTPOWER;
1651
Kalle Valo61448a92011-10-27 18:48:29 +03001652 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
Arik Nemtsovfb943332011-11-08 19:14:08 +02001653 WIPHY_FLAG_HAVE_AP_SME |
1654 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1655
1656 ar->wiphy->probe_resp_offload =
1657 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
1658 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
1659 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P |
1660 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U;
Kalle Valo61448a92011-10-27 18:48:29 +03001661
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001662 set_bit(FIRST_BOOT, &ar->flag);
1663
1664 ret = ath6kl_init_hw_start(ar);
Kalle Valo20459ee2011-10-27 18:48:37 +03001665 if (ret) {
Kalle Valo5fe4dff2011-10-30 21:16:15 +02001666 ath6kl_err("Failed to start hardware: %d\n", ret);
Kalle Valo20459ee2011-10-27 18:48:37 +03001667 goto err_rxbuf_cleanup;
Kalle Valo61448a92011-10-27 18:48:29 +03001668 }
1669
1670 /*
1671 * Set mac address which is received in ready event
1672 * FIXME: Move to ath6kl_interface_add()
1673 */
1674 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
Kalle Valobdcd8172011-07-18 00:22:30 +03001675
Kalle Valobdcd8172011-07-18 00:22:30 +03001676 return ret;
1677
Kalle Valo61448a92011-10-27 18:48:29 +03001678err_rxbuf_cleanup:
1679 ath6kl_htc_flush_rx_buf(ar->htc_target);
1680 ath6kl_cleanup_amsdu_rxbufs(ar);
Kalle Valo61448a92011-10-27 18:48:29 +03001681 rtnl_lock();
1682 ath6kl_deinit_if_data(netdev_priv(ndev));
1683 rtnl_unlock();
1684 wiphy_unregister(ar->wiphy);
1685err_debug_init:
1686 ath6kl_debug_cleanup(ar);
1687err_node_cleanup:
1688 ath6kl_wmi_shutdown(ar->wmi);
1689 clear_bit(WMI_ENABLED, &ar->flag);
1690 ar->wmi = NULL;
Kalle Valobdcd8172011-07-18 00:22:30 +03001691err_htc_cleanup:
Kalle Vaload226ec2011-08-10 09:49:12 +03001692 ath6kl_htc_cleanup(ar->htc_target);
Kalle Valob2e75692011-10-27 18:48:14 +03001693err_power_off:
1694 ath6kl_hif_power_off(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001695err_bmi_cleanup:
1696 ath6kl_bmi_cleanup(ar);
1697err_wq:
1698 destroy_workqueue(ar->ath6kl_wq);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301699
Kalle Valobdcd8172011-07-18 00:22:30 +03001700 return ret;
1701}
1702
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301703void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301704{
1705 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1706 bool discon_issued;
1707
1708 netif_stop_queue(vif->ndev);
1709
1710 clear_bit(WLAN_ENABLED, &vif->flags);
1711
1712 if (wmi_ready) {
1713 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1714 test_bit(CONNECT_PEND, &vif->flags);
1715 ath6kl_disconnect(vif);
1716 del_timer(&vif->disconnect_timer);
1717
1718 if (discon_issued)
1719 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1720 (vif->nw_type & AP_NETWORK) ?
1721 bcast_mac : vif->bssid,
1722 0, NULL, 0);
1723 }
1724
1725 if (vif->scan_req) {
1726 cfg80211_scan_done(vif->scan_req, true);
1727 vif->scan_req = NULL;
1728 }
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301729}
1730
Kalle Valobdcd8172011-07-18 00:22:30 +03001731void ath6kl_stop_txrx(struct ath6kl *ar)
1732{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301733 struct ath6kl_vif *vif, *tmp_vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001734
1735 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1736
1737 if (down_interruptible(&ar->sem)) {
1738 ath6kl_err("down_interruptible failed\n");
1739 return;
1740 }
1741
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301742 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301743 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1744 list_del(&vif->list);
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301745 spin_unlock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301746 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301747 rtnl_lock();
1748 ath6kl_deinit_if_data(vif);
1749 rtnl_unlock();
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301750 spin_lock_bh(&ar->list_lock);
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301751 }
Vasanthakumar Thiagarajan11f6e402011-11-01 16:38:50 +05301752 spin_unlock_bh(&ar->list_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001753
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301754 clear_bit(WMI_READY, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03001755
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301756 /*
1757 * After wmi_shudown all WMI events will be dropped. We
1758 * need to cleanup the buffers allocated in AP mode and
1759 * give disconnect notification to stack, which usually
1760 * happens in the disconnect_event. Simulate the disconnect
1761 * event by calling the function directly. Sometimes
1762 * disconnect_event will be received when the debug logs
1763 * are collected.
1764 */
1765 ath6kl_wmi_shutdown(ar->wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001766
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301767 clear_bit(WMI_ENABLED, &ar->flag);
1768 if (ar->htc_target) {
1769 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1770 ath6kl_htc_stop(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001771 }
1772
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301773 /*
1774 * Try to reset the device if we can. The driver may have been
1775 * configure NOT to reset the target during a debug session.
1776 */
1777 ath6kl_dbg(ATH6KL_DBG_TRC,
1778 "attempting to reset target on instance destroy\n");
1779 ath6kl_reset_device(ar, ar->target_type, true, true);
Kalle Valobdcd8172011-07-18 00:22:30 +03001780
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301781 clear_bit(WLAN_ENABLED, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03001782}