blob: f348357279a16dd7a956332e709eceb41948f196 [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
18#include <linux/mmc/sdio_func.h>
19#include "core.h"
20#include "cfg80211.h"
21#include "target.h"
22#include "debug.h"
23#include "hif-ops.h"
24
25unsigned int debug_mask;
Kalle Valo003353b0d2011-09-01 10:14:21 +030026static unsigned int testmode;
Kalle Valobdcd8172011-07-18 00:22:30 +030027
28module_param(debug_mask, uint, 0644);
Kalle Valo003353b0d2011-09-01 10:14:21 +030029module_param(testmode, uint, 0644);
Kalle Valobdcd8172011-07-18 00:22:30 +030030
31/*
32 * Include definitions here that can be used to tune the WLAN module
33 * behavior. Different customers can tune the behavior as per their needs,
34 * here.
35 */
36
37/*
38 * This configuration item enable/disable keepalive support.
39 * Keepalive support: In the absence of any data traffic to AP, null
40 * frames will be sent to the AP at periodic interval, to keep the association
41 * active. This configuration item defines the periodic interval.
42 * Use value of zero to disable keepalive support
43 * Default: 60 seconds
44 */
45#define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
46
47/*
48 * This configuration item sets the value of disconnect timeout
49 * Firmware delays sending the disconnec event to the host for this
50 * timeout after is gets disconnected from the current AP.
51 * If the firmware successly roams within the disconnect timeout
52 * it sends a new connect event
53 */
54#define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
55
56#define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
57
58enum addr_type {
59 DATASET_PATCH_ADDR,
60 APP_LOAD_ADDR,
61 APP_START_OVERRIDE_ADDR,
62};
63
64#define ATH6KL_DATA_OFFSET 64
65struct sk_buff *ath6kl_buf_alloc(int size)
66{
67 struct sk_buff *skb;
68 u16 reserved;
69
70 /* Add chacheline space at front and back of buffer */
71 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +053072 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +030073 skb = dev_alloc_skb(size + reserved);
74
75 if (skb)
76 skb_reserve(skb, reserved - L1_CACHE_BYTES);
77 return skb;
78}
79
80void ath6kl_init_profile_info(struct ath6kl *ar)
81{
82 ar->ssid_len = 0;
83 memset(ar->ssid, 0, sizeof(ar->ssid));
84
85 ar->dot11_auth_mode = OPEN_AUTH;
86 ar->auth_mode = NONE_AUTH;
87 ar->prwise_crypto = NONE_CRYPT;
88 ar->prwise_crypto_len = 0;
89 ar->grp_crypto = NONE_CRYPT;
Edward Lu38acde32011-08-30 21:58:06 +030090 ar->grp_crypto_len = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +030091 memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
92 memset(ar->req_bssid, 0, sizeof(ar->req_bssid));
93 memset(ar->bssid, 0, sizeof(ar->bssid));
94 ar->bss_ch = 0;
95 ar->nw_type = ar->next_mode = INFRA_NETWORK;
96}
97
98static u8 ath6kl_get_fw_iftype(struct ath6kl *ar)
99{
100 switch (ar->nw_type) {
101 case INFRA_NETWORK:
102 return HI_OPTION_FW_MODE_BSS_STA;
103 case ADHOC_NETWORK:
104 return HI_OPTION_FW_MODE_IBSS;
105 case AP_NETWORK:
106 return HI_OPTION_FW_MODE_AP;
107 default:
108 ath6kl_err("Unsupported interface type :%d\n", ar->nw_type);
109 return 0xff;
110 }
111}
112
113static inline u32 ath6kl_get_hi_item_addr(struct ath6kl *ar,
114 u32 item_offset)
115{
116 u32 addr = 0;
117
118 if (ar->target_type == TARGET_TYPE_AR6003)
Kevin Fang31024d92011-07-11 17:14:13 +0800119 addr = ATH6KL_AR6003_HI_START_ADDR + item_offset;
120 else if (ar->target_type == TARGET_TYPE_AR6004)
121 addr = ATH6KL_AR6004_HI_START_ADDR + item_offset;
Kalle Valobdcd8172011-07-18 00:22:30 +0300122
123 return addr;
124}
125
126static int ath6kl_set_host_app_area(struct ath6kl *ar)
127{
128 u32 address, data;
129 struct host_app_area host_app_area;
130
131 /* Fetch the address of the host_app_area_s
132 * instance in the host interest area */
133 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
Kevin Fang31024d92011-07-11 17:14:13 +0800134 address = TARG_VTOP(ar->target_type, address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300135
136 if (ath6kl_read_reg_diag(ar, &address, &data))
137 return -EIO;
138
Kevin Fang31024d92011-07-11 17:14:13 +0800139 address = TARG_VTOP(ar->target_type, data);
Kalle Valobdcd8172011-07-18 00:22:30 +0300140 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
141 if (ath6kl_access_datadiag(ar, address,
142 (u8 *)&host_app_area,
143 sizeof(struct host_app_area), false))
144 return -EIO;
145
146 return 0;
147}
148
149static inline void set_ac2_ep_map(struct ath6kl *ar,
150 u8 ac,
151 enum htc_endpoint_id ep)
152{
153 ar->ac2ep_map[ac] = ep;
154 ar->ep2ac_map[ep] = ac;
155}
156
157/* connect to a service */
158static int ath6kl_connectservice(struct ath6kl *ar,
159 struct htc_service_connect_req *con_req,
160 char *desc)
161{
162 int status;
163 struct htc_service_connect_resp response;
164
165 memset(&response, 0, sizeof(response));
166
Kalle Vaload226ec2011-08-10 09:49:12 +0300167 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
Kalle Valobdcd8172011-07-18 00:22:30 +0300168 if (status) {
169 ath6kl_err("failed to connect to %s service status:%d\n",
170 desc, status);
171 return status;
172 }
173
174 switch (con_req->svc_id) {
175 case WMI_CONTROL_SVC:
176 if (test_bit(WMI_ENABLED, &ar->flag))
177 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
178 ar->ctrl_ep = response.endpoint;
179 break;
180 case WMI_DATA_BE_SVC:
181 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
182 break;
183 case WMI_DATA_BK_SVC:
184 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
185 break;
186 case WMI_DATA_VI_SVC:
187 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
188 break;
189 case WMI_DATA_VO_SVC:
190 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
191 break;
192 default:
193 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
194 return -EINVAL;
195 }
196
197 return 0;
198}
199
200static int ath6kl_init_service_ep(struct ath6kl *ar)
201{
202 struct htc_service_connect_req connect;
203
204 memset(&connect, 0, sizeof(connect));
205
206 /* these fields are the same for all service endpoints */
207 connect.ep_cb.rx = ath6kl_rx;
208 connect.ep_cb.rx_refill = ath6kl_rx_refill;
209 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
210
211 /*
212 * Set the max queue depth so that our ath6kl_tx_queue_full handler
213 * gets called.
214 */
215 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
216 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
217 if (!connect.ep_cb.rx_refill_thresh)
218 connect.ep_cb.rx_refill_thresh++;
219
220 /* connect to control service */
221 connect.svc_id = WMI_CONTROL_SVC;
222 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
223 return -EIO;
224
225 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
226
227 /*
228 * Limit the HTC message size on the send path, although e can
229 * receive A-MSDU frames of 4K, we will only send ethernet-sized
230 * (802.3) frames on the send path.
231 */
232 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
233
234 /*
235 * To reduce the amount of committed memory for larger A_MSDU
236 * frames, use the recv-alloc threshold mechanism for larger
237 * packets.
238 */
239 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
240 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
241
242 /*
243 * For the remaining data services set the connection flag to
244 * reduce dribbling, if configured to do so.
245 */
246 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
247 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
248 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
249
250 connect.svc_id = WMI_DATA_BE_SVC;
251
252 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
253 return -EIO;
254
255 /* connect to back-ground map this to WMI LOW_PRI */
256 connect.svc_id = WMI_DATA_BK_SVC;
257 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
258 return -EIO;
259
260 /* connect to Video service, map this to to HI PRI */
261 connect.svc_id = WMI_DATA_VI_SVC;
262 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
263 return -EIO;
264
265 /*
266 * Connect to VO service, this is currently not mapped to a WMI
267 * priority stream due to historical reasons. WMI originally
268 * defined 3 priorities over 3 mailboxes We can change this when
269 * WMI is reworked so that priorities are not dependent on
270 * mailboxes.
271 */
272 connect.svc_id = WMI_DATA_VO_SVC;
273 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
274 return -EIO;
275
276 return 0;
277}
278
279static void ath6kl_init_control_info(struct ath6kl *ar)
280{
281 u8 ctr;
282
283 clear_bit(WMI_ENABLED, &ar->flag);
284 ath6kl_init_profile_info(ar);
285 ar->def_txkey_index = 0;
286 memset(ar->wep_key_list, 0, sizeof(ar->wep_key_list));
287 ar->ch_hint = 0;
288 ar->listen_intvl_t = A_DEFAULT_LISTEN_INTERVAL;
289 ar->listen_intvl_b = 0;
290 ar->tx_pwr = 0;
291 clear_bit(SKIP_SCAN, &ar->flag);
292 set_bit(WMM_ENABLED, &ar->flag);
293 ar->intra_bss = 1;
294 memset(&ar->sc_params, 0, sizeof(ar->sc_params));
295 ar->sc_params.short_scan_ratio = WMI_SHORTSCANRATIO_DEFAULT;
296 ar->sc_params.scan_ctrl_flags = DEFAULT_SCAN_CTRL_FLAGS;
297
298 memset((u8 *)ar->sta_list, 0,
299 AP_MAX_NUM_STA * sizeof(struct ath6kl_sta));
300
301 spin_lock_init(&ar->mcastpsq_lock);
302
303 /* Init the PS queues */
304 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
305 spin_lock_init(&ar->sta_list[ctr].psq_lock);
306 skb_queue_head_init(&ar->sta_list[ctr].psq);
307 }
308
309 skb_queue_head_init(&ar->mcastpsq);
310
311 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
312}
313
314/*
315 * Set HTC/Mbox operational parameters, this can only be called when the
316 * target is in the BMI phase.
317 */
318static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
319 u8 htc_ctrl_buf)
320{
321 int status;
322 u32 blk_size;
323
324 blk_size = ar->mbox_info.block_size;
325
326 if (htc_ctrl_buf)
327 blk_size |= ((u32)htc_ctrl_buf) << 16;
328
329 /* set the host interest area for the block size */
330 status = ath6kl_bmi_write(ar,
331 ath6kl_get_hi_item_addr(ar,
332 HI_ITEM(hi_mbox_io_block_sz)),
333 (u8 *)&blk_size,
334 4);
335 if (status) {
336 ath6kl_err("bmi_write_memory for IO block size failed\n");
337 goto out;
338 }
339
340 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
341 blk_size,
342 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
343
344 if (mbox_isr_yield_val) {
345 /* set the host interest area for the mbox ISR yield limit */
346 status = ath6kl_bmi_write(ar,
347 ath6kl_get_hi_item_addr(ar,
348 HI_ITEM(hi_mbox_isr_yield_limit)),
349 (u8 *)&mbox_isr_yield_val,
350 4);
351 if (status) {
352 ath6kl_err("bmi_write_memory for yield limit failed\n");
353 goto out;
354 }
355 }
356
357out:
358 return status;
359}
360
361#define REG_DUMP_COUNT_AR6003 60
362#define REGISTER_DUMP_LEN_MAX 60
363
364static void ath6kl_dump_target_assert_info(struct ath6kl *ar)
365{
366 u32 address;
367 u32 regdump_loc = 0;
368 int status;
369 u32 regdump_val[REGISTER_DUMP_LEN_MAX];
370 u32 i;
371
372 if (ar->target_type != TARGET_TYPE_AR6003)
373 return;
374
375 /* the reg dump pointer is copied to the host interest area */
376 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
Kevin Fang31024d92011-07-11 17:14:13 +0800377 address = TARG_VTOP(ar->target_type, address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300378
379 /* read RAM location through diagnostic window */
380 status = ath6kl_read_reg_diag(ar, &address, &regdump_loc);
381
382 if (status || !regdump_loc) {
383 ath6kl_err("failed to get ptr to register dump area\n");
384 return;
385 }
386
387 ath6kl_dbg(ATH6KL_DBG_TRC, "location of register dump data: 0x%X\n",
388 regdump_loc);
Kevin Fang31024d92011-07-11 17:14:13 +0800389 regdump_loc = TARG_VTOP(ar->target_type, regdump_loc);
Kalle Valobdcd8172011-07-18 00:22:30 +0300390
391 /* fetch register dump data */
392 status = ath6kl_access_datadiag(ar,
393 regdump_loc,
394 (u8 *)&regdump_val[0],
395 REG_DUMP_COUNT_AR6003 * (sizeof(u32)),
396 true);
397
398 if (status) {
399 ath6kl_err("failed to get register dump\n");
400 return;
401 }
402 ath6kl_dbg(ATH6KL_DBG_TRC, "Register Dump:\n");
403
404 for (i = 0; i < REG_DUMP_COUNT_AR6003; i++)
405 ath6kl_dbg(ATH6KL_DBG_TRC, " %d : 0x%8.8X\n",
406 i, regdump_val[i]);
407
408}
409
410void ath6kl_target_failure(struct ath6kl *ar)
411{
412 ath6kl_err("target asserted\n");
413
414 /* try dumping target assertion information (if any) */
415 ath6kl_dump_target_assert_info(ar);
416
417}
418
419static int ath6kl_target_config_wlan_params(struct ath6kl *ar)
420{
421 int status = 0;
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300422 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300423
424 /*
425 * Configure the device for rx dot11 header rules. "0,0" are the
426 * default values. Required if checksum offload is needed. Set
427 * RxMetaVersion to 2.
428 */
429 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi,
430 ar->rx_meta_ver, 0, 0)) {
431 ath6kl_err("unable to set the rx frame format\n");
432 status = -EIO;
433 }
434
435 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
436 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, 0, 1, 0, 0, 1,
437 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
438 ath6kl_err("unable to set power save fail event policy\n");
439 status = -EIO;
440 }
441
442 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
443 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, 0,
444 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
445 ath6kl_err("unable to set barker preamble policy\n");
446 status = -EIO;
447 }
448
449 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi,
450 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
451 ath6kl_err("unable to set keep alive interval\n");
452 status = -EIO;
453 }
454
455 if (ath6kl_wmi_disctimeout_cmd(ar->wmi,
456 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
457 ath6kl_err("unable to set disconnect timeout\n");
458 status = -EIO;
459 }
460
461 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
462 if (ath6kl_wmi_set_wmm_txop(ar->wmi, WMI_TXOP_DISABLED)) {
463 ath6kl_err("unable to set txop bursting\n");
464 status = -EIO;
465 }
466
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300467 ret = ath6kl_wmi_info_req_cmd(ar->wmi, P2P_FLAG_CAPABILITIES_REQ |
468 P2P_FLAG_MACADDR_REQ |
469 P2P_FLAG_HMODEL_REQ);
470 if (ret) {
471 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
472 "capabilities (%d) - assuming P2P not supported\n",
473 ret);
474 }
475
Jouni Malinenae32c302011-08-30 21:58:01 +0300476 /* Enable Probe Request reporting for P2P */
477 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, true);
478 if (ret) {
479 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe Request "
480 "reporting (%d)\n", ret);
481 }
482
Kalle Valobdcd8172011-07-18 00:22:30 +0300483 return status;
484}
485
486int ath6kl_configure_target(struct ath6kl *ar)
487{
488 u32 param, ram_reserved_size;
489 u8 fw_iftype;
490
491 fw_iftype = ath6kl_get_fw_iftype(ar);
492 if (fw_iftype == 0xff)
493 return -EINVAL;
494
495 /* Tell target which HTC version it is used*/
496 param = HTC_PROTOCOL_VERSION;
497 if (ath6kl_bmi_write(ar,
498 ath6kl_get_hi_item_addr(ar,
499 HI_ITEM(hi_app_host_interest)),
500 (u8 *)&param, 4) != 0) {
501 ath6kl_err("bmi_write_memory for htc version failed\n");
502 return -EIO;
503 }
504
505 /* set the firmware mode to STA/IBSS/AP */
506 param = 0;
507
508 if (ath6kl_bmi_read(ar,
509 ath6kl_get_hi_item_addr(ar,
510 HI_ITEM(hi_option_flag)),
511 (u8 *)&param, 4) != 0) {
512 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
513 return -EIO;
514 }
515
516 param |= (1 << HI_OPTION_NUM_DEV_SHIFT);
517 param |= (fw_iftype << HI_OPTION_FW_MODE_SHIFT);
518 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
519 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
520
521 if (ath6kl_bmi_write(ar,
522 ath6kl_get_hi_item_addr(ar,
523 HI_ITEM(hi_option_flag)),
524 (u8 *)&param,
525 4) != 0) {
526 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
527 return -EIO;
528 }
529
530 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
531
532 /*
533 * Hardcode the address use for the extended board data
534 * Ideally this should be pre-allocate by the OS at boot time
535 * But since it is a new feature and board data is loaded
536 * at init time, we have to workaround this from host.
537 * It is difficult to patch the firmware boot code,
538 * but possible in theory.
539 */
540
Kevin Fang31024d92011-07-11 17:14:13 +0800541 if (ar->target_type == TARGET_TYPE_AR6003 ||
542 ar->target_type == TARGET_TYPE_AR6004) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300543 if (ar->version.target_ver == AR6003_REV2_VERSION) {
544 param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
545 ram_reserved_size = AR6003_REV2_RAM_RESERVE_SIZE;
Kevin Fang31024d92011-07-11 17:14:13 +0800546 } else if (ar->version.target_ver == AR6004_REV1_VERSION) {
547 param = AR6004_REV1_BOARD_EXT_DATA_ADDRESS;
548 ram_reserved_size = AR6004_REV1_RAM_RESERVE_SIZE;
Kalle Valobdcd8172011-07-18 00:22:30 +0300549 } else {
550 param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
551 ram_reserved_size = AR6003_REV3_RAM_RESERVE_SIZE;
552 }
553
554 if (ath6kl_bmi_write(ar,
555 ath6kl_get_hi_item_addr(ar,
556 HI_ITEM(hi_board_ext_data)),
557 (u8 *)&param, 4) != 0) {
558 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
559 return -EIO;
560 }
561 if (ath6kl_bmi_write(ar,
562 ath6kl_get_hi_item_addr(ar,
563 HI_ITEM(hi_end_ram_reserve_sz)),
564 (u8 *)&ram_reserved_size, 4) != 0) {
565 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
566 return -EIO;
567 }
568 }
569
570 /* set the block size for the target */
571 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
572 /* use default number of control buffers */
573 return -EIO;
574
575 return 0;
576}
577
578struct ath6kl *ath6kl_core_alloc(struct device *sdev)
579{
580 struct net_device *dev;
581 struct ath6kl *ar;
582 struct wireless_dev *wdev;
583
584 wdev = ath6kl_cfg80211_init(sdev);
585 if (!wdev) {
586 ath6kl_err("ath6kl_cfg80211_init failed\n");
587 return NULL;
588 }
589
590 ar = wdev_priv(wdev);
591 ar->dev = sdev;
592 ar->wdev = wdev;
593 wdev->iftype = NL80211_IFTYPE_STATION;
594
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530595 if (ath6kl_debug_init(ar)) {
596 ath6kl_err("Failed to initialize debugfs\n");
597 ath6kl_cfg80211_deinit(ar);
598 return NULL;
599 }
600
Kalle Valobdcd8172011-07-18 00:22:30 +0300601 dev = alloc_netdev(0, "wlan%d", ether_setup);
602 if (!dev) {
603 ath6kl_err("no memory for network device instance\n");
604 ath6kl_cfg80211_deinit(ar);
605 return NULL;
606 }
607
608 dev->ieee80211_ptr = wdev;
609 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
610 wdev->netdev = dev;
611 ar->sme_state = SME_DISCONNECTED;
612 ar->auto_auth_stage = AUTH_IDLE;
613
614 init_netdev(dev);
615
616 ar->net_dev = dev;
Raja Mani575b5f32011-07-19 19:27:33 +0530617 set_bit(WLAN_ENABLED, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +0300618
619 ar->wlan_pwr_state = WLAN_POWER_STATE_ON;
620
621 spin_lock_init(&ar->lock);
622
623 ath6kl_init_control_info(ar);
624 init_waitqueue_head(&ar->event_wq);
625 sema_init(&ar->sem, 1);
626 clear_bit(DESTROY_IN_PROGRESS, &ar->flag);
627
628 INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue);
629
630 setup_timer(&ar->disconnect_timer, disconnect_timer_handler,
631 (unsigned long) dev);
632
633 return ar;
634}
635
636int ath6kl_unavail_ev(struct ath6kl *ar)
637{
638 ath6kl_destroy(ar->net_dev, 1);
639
640 return 0;
641}
642
643/* firmware upload */
644static u32 ath6kl_get_load_address(u32 target_ver, enum addr_type type)
645{
646 WARN_ON(target_ver != AR6003_REV2_VERSION &&
Kevin Fang31024d92011-07-11 17:14:13 +0800647 target_ver != AR6003_REV3_VERSION &&
648 target_ver != AR6004_REV1_VERSION);
Kalle Valobdcd8172011-07-18 00:22:30 +0300649
650 switch (type) {
651 case DATASET_PATCH_ADDR:
652 return (target_ver == AR6003_REV2_VERSION) ?
653 AR6003_REV2_DATASET_PATCH_ADDRESS :
654 AR6003_REV3_DATASET_PATCH_ADDRESS;
655 case APP_LOAD_ADDR:
656 return (target_ver == AR6003_REV2_VERSION) ?
657 AR6003_REV2_APP_LOAD_ADDRESS :
658 0x1234;
659 case APP_START_OVERRIDE_ADDR:
660 return (target_ver == AR6003_REV2_VERSION) ?
661 AR6003_REV2_APP_START_OVERRIDE :
662 AR6003_REV3_APP_START_OVERRIDE;
663 default:
664 return 0;
665 }
666}
667
668static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
669 u8 **fw, size_t *fw_len)
670{
671 const struct firmware *fw_entry;
672 int ret;
673
674 ret = request_firmware(&fw_entry, filename, ar->dev);
675 if (ret)
676 return ret;
677
678 *fw_len = fw_entry->size;
679 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
680
681 if (*fw == NULL)
682 ret = -ENOMEM;
683
684 release_firmware(fw_entry);
685
686 return ret;
687}
688
689static int ath6kl_fetch_board_file(struct ath6kl *ar)
690{
691 const char *filename;
692 int ret;
693
694 switch (ar->version.target_ver) {
695 case AR6003_REV2_VERSION:
696 filename = AR6003_REV2_BOARD_DATA_FILE;
697 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800698 case AR6004_REV1_VERSION:
699 filename = AR6004_REV1_BOARD_DATA_FILE;
700 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300701 default:
702 filename = AR6003_REV3_BOARD_DATA_FILE;
703 break;
704 }
705
706 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
707 &ar->fw_board_len);
708 if (ret == 0) {
709 /* managed to get proper board file */
710 return 0;
711 }
712
713 /* there was no proper board file, try to use default instead */
714 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
715 filename, ret);
716
717 switch (ar->version.target_ver) {
718 case AR6003_REV2_VERSION:
719 filename = AR6003_REV2_DEFAULT_BOARD_DATA_FILE;
720 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800721 case AR6004_REV1_VERSION:
722 filename = AR6004_REV1_DEFAULT_BOARD_DATA_FILE;
723 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300724 default:
725 filename = AR6003_REV3_DEFAULT_BOARD_DATA_FILE;
726 break;
727 }
728
729 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
730 &ar->fw_board_len);
731 if (ret) {
732 ath6kl_err("Failed to get default board file %s: %d\n",
733 filename, ret);
734 return ret;
735 }
736
737 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
738 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
739
740 return 0;
741}
742
743
744static int ath6kl_upload_board_file(struct ath6kl *ar)
745{
746 u32 board_address, board_ext_address, param;
Kevin Fang31024d92011-07-11 17:14:13 +0800747 u32 board_data_size, board_ext_data_size;
Kalle Valobdcd8172011-07-18 00:22:30 +0300748 int ret;
749
750 if (ar->fw_board == NULL) {
751 ret = ath6kl_fetch_board_file(ar);
752 if (ret)
753 return ret;
754 }
755
Kevin Fang31024d92011-07-11 17:14:13 +0800756 /*
757 * Determine where in Target RAM to write Board Data.
758 * For AR6004, host determine Target RAM address for
759 * writing board data.
760 */
761 if (ar->target_type == TARGET_TYPE_AR6004) {
762 board_address = AR6004_REV1_BOARD_DATA_ADDRESS;
763 ath6kl_bmi_write(ar,
764 ath6kl_get_hi_item_addr(ar,
765 HI_ITEM(hi_board_data)),
766 (u8 *) &board_address, 4);
767 } else {
768 ath6kl_bmi_read(ar,
769 ath6kl_get_hi_item_addr(ar,
770 HI_ITEM(hi_board_data)),
771 (u8 *) &board_address, 4);
772 }
773
Kalle Valobdcd8172011-07-18 00:22:30 +0300774 ath6kl_dbg(ATH6KL_DBG_TRC, "board data download addr: 0x%x\n",
775 board_address);
776
777 /* determine where in target ram to write extended board data */
778 ath6kl_bmi_read(ar,
779 ath6kl_get_hi_item_addr(ar,
780 HI_ITEM(hi_board_ext_data)),
781 (u8 *) &board_ext_address, 4);
782
783 ath6kl_dbg(ATH6KL_DBG_TRC, "board file download addr: 0x%x\n",
784 board_ext_address);
785
786 if (board_ext_address == 0) {
787 ath6kl_err("Failed to get board file target address.\n");
788 return -EINVAL;
789 }
790
Kevin Fang31024d92011-07-11 17:14:13 +0800791 switch (ar->target_type) {
792 case TARGET_TYPE_AR6003:
793 board_data_size = AR6003_BOARD_DATA_SZ;
794 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
795 break;
796 case TARGET_TYPE_AR6004:
797 board_data_size = AR6004_BOARD_DATA_SZ;
798 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
799 break;
800 default:
801 WARN_ON(1);
802 return -EINVAL;
803 break;
804 }
805
806 if (ar->fw_board_len == (board_data_size +
807 board_ext_data_size)) {
808
Kalle Valobdcd8172011-07-18 00:22:30 +0300809 /* write extended board data */
810 ret = ath6kl_bmi_write(ar, board_ext_address,
Kevin Fang31024d92011-07-11 17:14:13 +0800811 ar->fw_board + board_data_size,
812 board_ext_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +0300813 if (ret) {
814 ath6kl_err("Failed to write extended board data: %d\n",
815 ret);
816 return ret;
817 }
818
819 /* record that extended board data is initialized */
Kevin Fang31024d92011-07-11 17:14:13 +0800820 param = (board_ext_data_size << 16) | 1;
821
Kalle Valobdcd8172011-07-18 00:22:30 +0300822 ath6kl_bmi_write(ar,
823 ath6kl_get_hi_item_addr(ar,
824 HI_ITEM(hi_board_ext_data_config)),
825 (unsigned char *) &param, 4);
826 }
827
Kevin Fang31024d92011-07-11 17:14:13 +0800828 if (ar->fw_board_len < board_data_size) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300829 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
830 ret = -EINVAL;
831 return ret;
832 }
833
834 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
Kevin Fang31024d92011-07-11 17:14:13 +0800835 board_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +0300836
837 if (ret) {
838 ath6kl_err("Board file bmi write failed: %d\n", ret);
839 return ret;
840 }
841
842 /* record the fact that Board Data IS initialized */
843 param = 1;
844 ath6kl_bmi_write(ar,
845 ath6kl_get_hi_item_addr(ar,
846 HI_ITEM(hi_board_data_initialized)),
847 (u8 *)&param, 4);
848
849 return ret;
850}
851
852static int ath6kl_upload_otp(struct ath6kl *ar)
853{
854 const char *filename;
855 u32 address, param;
856 int ret;
857
858 switch (ar->version.target_ver) {
859 case AR6003_REV2_VERSION:
860 filename = AR6003_REV2_OTP_FILE;
861 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800862 case AR6004_REV1_VERSION:
863 ath6kl_dbg(ATH6KL_DBG_TRC, "AR6004 doesn't need OTP file\n");
864 return 0;
865 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300866 default:
867 filename = AR6003_REV3_OTP_FILE;
868 break;
869 }
870
871 if (ar->fw_otp == NULL) {
872 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
873 &ar->fw_otp_len);
874 if (ret) {
875 ath6kl_err("Failed to get OTP file %s: %d\n",
876 filename, ret);
877 return ret;
878 }
879 }
880
881 address = ath6kl_get_load_address(ar->version.target_ver,
882 APP_LOAD_ADDR);
883
884 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
885 ar->fw_otp_len);
886 if (ret) {
887 ath6kl_err("Failed to upload OTP file: %d\n", ret);
888 return ret;
889 }
890
891 /* execute the OTP code */
892 param = 0;
893 address = ath6kl_get_load_address(ar->version.target_ver,
894 APP_START_OVERRIDE_ADDR);
895 ath6kl_bmi_execute(ar, address, &param);
896
897 return ret;
898}
899
900static int ath6kl_upload_firmware(struct ath6kl *ar)
901{
902 const char *filename;
903 u32 address;
904 int ret;
905
Kalle Valo003353b0d2011-09-01 10:14:21 +0300906 if (testmode) {
907 switch (ar->version.target_ver) {
908 case AR6003_REV2_VERSION:
909 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
910 break;
911 case AR6003_REV3_VERSION:
912 filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
913 break;
914 case AR6004_REV1_VERSION:
915 ath6kl_warn("testmode not supported with ar6004\n");
916 return -EOPNOTSUPP;
917 default:
918 ath6kl_warn("unknown target version: 0x%x\n",
919 ar->version.target_ver);
920 return -EINVAL;
921 }
922
923 set_bit(TESTMODE, &ar->flag);
924
925 goto get_fw;
926 }
927
Kalle Valobdcd8172011-07-18 00:22:30 +0300928 switch (ar->version.target_ver) {
929 case AR6003_REV2_VERSION:
930 filename = AR6003_REV2_FIRMWARE_FILE;
931 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800932 case AR6004_REV1_VERSION:
933 filename = AR6004_REV1_FIRMWARE_FILE;
934 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300935 default:
936 filename = AR6003_REV3_FIRMWARE_FILE;
937 break;
938 }
939
Kalle Valo003353b0d2011-09-01 10:14:21 +0300940get_fw:
941
Kalle Valobdcd8172011-07-18 00:22:30 +0300942 if (ar->fw == NULL) {
943 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
944 if (ret) {
945 ath6kl_err("Failed to get firmware file %s: %d\n",
946 filename, ret);
947 return ret;
948 }
949 }
950
951 address = ath6kl_get_load_address(ar->version.target_ver,
952 APP_LOAD_ADDR);
953
954 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
955
956 if (ret) {
957 ath6kl_err("Failed to write firmware: %d\n", ret);
958 return ret;
959 }
960
Kevin Fang31024d92011-07-11 17:14:13 +0800961 /*
962 * Set starting address for firmware
963 * Don't need to setup app_start override addr on AR6004
964 */
965 if (ar->target_type != TARGET_TYPE_AR6004) {
966 address = ath6kl_get_load_address(ar->version.target_ver,
967 APP_START_OVERRIDE_ADDR);
968 ath6kl_bmi_set_app_start(ar, address);
969 }
Kalle Valobdcd8172011-07-18 00:22:30 +0300970 return ret;
971}
972
973static int ath6kl_upload_patch(struct ath6kl *ar)
974{
975 const char *filename;
976 u32 address, param;
977 int ret;
978
979 switch (ar->version.target_ver) {
980 case AR6003_REV2_VERSION:
981 filename = AR6003_REV2_PATCH_FILE;
982 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800983 case AR6004_REV1_VERSION:
984 /* FIXME: implement for AR6004 */
985 return 0;
986 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300987 default:
988 filename = AR6003_REV3_PATCH_FILE;
989 break;
990 }
991
992 if (ar->fw_patch == NULL) {
993 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
994 &ar->fw_patch_len);
995 if (ret) {
996 ath6kl_err("Failed to get patch file %s: %d\n",
997 filename, ret);
998 return ret;
999 }
1000 }
1001
1002 address = ath6kl_get_load_address(ar->version.target_ver,
1003 DATASET_PATCH_ADDR);
1004
1005 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1006 if (ret) {
1007 ath6kl_err("Failed to write patch file: %d\n", ret);
1008 return ret;
1009 }
1010
1011 param = address;
1012 ath6kl_bmi_write(ar,
1013 ath6kl_get_hi_item_addr(ar,
1014 HI_ITEM(hi_dset_list_head)),
1015 (unsigned char *) &param, 4);
1016
1017 return 0;
1018}
1019
1020static int ath6kl_init_upload(struct ath6kl *ar)
1021{
1022 u32 param, options, sleep, address;
1023 int status = 0;
1024
Kevin Fang31024d92011-07-11 17:14:13 +08001025 if (ar->target_type != TARGET_TYPE_AR6003 &&
1026 ar->target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +03001027 return -EINVAL;
1028
1029 /* temporarily disable system sleep */
1030 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1031 status = ath6kl_bmi_reg_read(ar, address, &param);
1032 if (status)
1033 return status;
1034
1035 options = param;
1036
1037 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1038 status = ath6kl_bmi_reg_write(ar, address, param);
1039 if (status)
1040 return status;
1041
1042 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1043 status = ath6kl_bmi_reg_read(ar, address, &param);
1044 if (status)
1045 return status;
1046
1047 sleep = param;
1048
1049 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1050 status = ath6kl_bmi_reg_write(ar, address, param);
1051 if (status)
1052 return status;
1053
1054 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1055 options, sleep);
1056
1057 /* program analog PLL register */
Kevin Fang31024d92011-07-11 17:14:13 +08001058 /* no need to control 40/44MHz clock on AR6004 */
1059 if (ar->target_type != TARGET_TYPE_AR6004) {
1060 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1061 0xF9104001);
Kalle Valobdcd8172011-07-18 00:22:30 +03001062
Kevin Fang31024d92011-07-11 17:14:13 +08001063 if (status)
1064 return status;
Kalle Valobdcd8172011-07-18 00:22:30 +03001065
Kevin Fang31024d92011-07-11 17:14:13 +08001066 /* Run at 80/88MHz by default */
1067 param = SM(CPU_CLOCK_STANDARD, 1);
1068
1069 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1070 status = ath6kl_bmi_reg_write(ar, address, param);
1071 if (status)
1072 return status;
1073 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001074
1075 param = 0;
1076 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1077 param = SM(LPO_CAL_ENABLE, 1);
1078 status = ath6kl_bmi_reg_write(ar, address, param);
1079 if (status)
1080 return status;
1081
1082 /* WAR to avoid SDIO CRC err */
1083 if (ar->version.target_ver == AR6003_REV2_VERSION) {
1084 ath6kl_err("temporary war to avoid sdio crc error\n");
1085
1086 param = 0x20;
1087
1088 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1089 status = ath6kl_bmi_reg_write(ar, address, param);
1090 if (status)
1091 return status;
1092
1093 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1094 status = ath6kl_bmi_reg_write(ar, address, param);
1095 if (status)
1096 return status;
1097
1098 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1099 status = ath6kl_bmi_reg_write(ar, address, param);
1100 if (status)
1101 return status;
1102
1103 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1104 status = ath6kl_bmi_reg_write(ar, address, param);
1105 if (status)
1106 return status;
1107 }
1108
1109 /* write EEPROM data to Target RAM */
1110 status = ath6kl_upload_board_file(ar);
1111 if (status)
1112 return status;
1113
1114 /* transfer One time Programmable data */
1115 status = ath6kl_upload_otp(ar);
1116 if (status)
1117 return status;
1118
1119 /* Download Target firmware */
1120 status = ath6kl_upload_firmware(ar);
1121 if (status)
1122 return status;
1123
1124 status = ath6kl_upload_patch(ar);
1125 if (status)
1126 return status;
1127
1128 /* Restore system sleep */
1129 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1130 status = ath6kl_bmi_reg_write(ar, address, sleep);
1131 if (status)
1132 return status;
1133
1134 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1135 param = options | 0x20;
1136 status = ath6kl_bmi_reg_write(ar, address, param);
1137 if (status)
1138 return status;
1139
1140 /* Configure GPIO AR6003 UART */
1141 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1142 status = ath6kl_bmi_write(ar,
1143 ath6kl_get_hi_item_addr(ar,
1144 HI_ITEM(hi_dbg_uart_txpin)),
1145 (u8 *)&param, 4);
1146
1147 return status;
1148}
1149
1150static int ath6kl_init(struct net_device *dev)
1151{
1152 struct ath6kl *ar = ath6kl_priv(dev);
1153 int status = 0;
1154 s32 timeleft;
1155
1156 if (!ar)
1157 return -EIO;
1158
1159 /* Do we need to finish the BMI phase */
1160 if (ath6kl_bmi_done(ar)) {
1161 status = -EIO;
1162 goto ath6kl_init_done;
1163 }
1164
1165 /* Indicate that WMI is enabled (although not ready yet) */
1166 set_bit(WMI_ENABLED, &ar->flag);
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05301167 ar->wmi = ath6kl_wmi_init(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001168 if (!ar->wmi) {
1169 ath6kl_err("failed to initialize wmi\n");
1170 status = -EIO;
1171 goto ath6kl_init_done;
1172 }
1173
1174 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1175
Vasanthakumar Thiagarajan852bd9d2011-07-21 14:24:54 +05301176 wlan_node_table_init(&ar->scan_table);
1177
Kalle Valobdcd8172011-07-18 00:22:30 +03001178 /*
1179 * The reason we have to wait for the target here is that the
1180 * driver layer has to init BMI in order to set the host block
1181 * size.
1182 */
Kalle Vaload226ec2011-08-10 09:49:12 +03001183 if (ath6kl_htc_wait_target(ar->htc_target)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001184 status = -EIO;
Vasanthakumar Thiagarajan852bd9d2011-07-21 14:24:54 +05301185 goto err_node_cleanup;
Kalle Valobdcd8172011-07-18 00:22:30 +03001186 }
1187
1188 if (ath6kl_init_service_ep(ar)) {
1189 status = -EIO;
1190 goto err_cleanup_scatter;
1191 }
1192
1193 /* setup access class priority mappings */
1194 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1195 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1196 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1197 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1198
1199 /* give our connected endpoints some buffers */
1200 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1201 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1202
1203 /* allocate some buffers that handle larger AMSDU frames */
1204 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1205
1206 /* setup credit distribution */
1207 ath6k_setup_credit_dist(ar->htc_target, &ar->credit_state_info);
1208
1209 ath6kl_cookie_init(ar);
1210
1211 /* start HTC */
Kalle Vaload226ec2011-08-10 09:49:12 +03001212 status = ath6kl_htc_start(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001213
1214 if (status) {
1215 ath6kl_cookie_cleanup(ar);
1216 goto err_rxbuf_cleanup;
1217 }
1218
1219 /* Wait for Wmi event to be ready */
1220 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1221 test_bit(WMI_READY,
1222 &ar->flag),
1223 WMI_TIMEOUT);
1224
1225 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1226 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1227 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1228 status = -EIO;
1229 goto err_htc_stop;
1230 }
1231
1232 if (!timeleft || signal_pending(current)) {
1233 ath6kl_err("wmi is not ready or wait was interrupted\n");
1234 status = -EIO;
1235 goto err_htc_stop;
1236 }
1237
1238 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1239
1240 /* communicate the wmi protocol verision to the target */
1241 if ((ath6kl_set_host_app_area(ar)) != 0)
1242 ath6kl_err("unable to set the host app area\n");
1243
1244 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1245 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1246
1247 status = ath6kl_target_config_wlan_params(ar);
1248 if (!status)
1249 goto ath6kl_init_done;
1250
1251err_htc_stop:
Kalle Vaload226ec2011-08-10 09:49:12 +03001252 ath6kl_htc_stop(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001253err_rxbuf_cleanup:
Kalle Vaload226ec2011-08-10 09:49:12 +03001254 ath6kl_htc_flush_rx_buf(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001255 ath6kl_cleanup_amsdu_rxbufs(ar);
1256err_cleanup_scatter:
1257 ath6kl_hif_cleanup_scatter(ar);
Vasanthakumar Thiagarajan852bd9d2011-07-21 14:24:54 +05301258err_node_cleanup:
1259 wlan_node_table_cleanup(&ar->scan_table);
Kalle Valobdcd8172011-07-18 00:22:30 +03001260 ath6kl_wmi_shutdown(ar->wmi);
1261 clear_bit(WMI_ENABLED, &ar->flag);
1262 ar->wmi = NULL;
1263
1264ath6kl_init_done:
1265 return status;
1266}
1267
1268int ath6kl_core_init(struct ath6kl *ar)
1269{
1270 int ret = 0;
1271 struct ath6kl_bmi_target_info targ_info;
1272
1273 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1274 if (!ar->ath6kl_wq)
1275 return -ENOMEM;
1276
1277 ret = ath6kl_bmi_init(ar);
1278 if (ret)
1279 goto err_wq;
1280
1281 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1282 if (ret)
1283 goto err_bmi_cleanup;
1284
1285 ar->version.target_ver = le32_to_cpu(targ_info.version);
1286 ar->target_type = le32_to_cpu(targ_info.type);
1287 ar->wdev->wiphy->hw_version = le32_to_cpu(targ_info.version);
1288
1289 ret = ath6kl_configure_target(ar);
1290 if (ret)
1291 goto err_bmi_cleanup;
1292
Kalle Vaload226ec2011-08-10 09:49:12 +03001293 ar->htc_target = ath6kl_htc_create(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001294
1295 if (!ar->htc_target) {
1296 ret = -ENOMEM;
1297 goto err_bmi_cleanup;
1298 }
1299
1300 ar->aggr_cntxt = aggr_init(ar->net_dev);
1301 if (!ar->aggr_cntxt) {
1302 ath6kl_err("failed to initialize aggr\n");
1303 ret = -ENOMEM;
1304 goto err_htc_cleanup;
1305 }
1306
1307 ret = ath6kl_init_upload(ar);
1308 if (ret)
1309 goto err_htc_cleanup;
1310
1311 ret = ath6kl_init(ar->net_dev);
1312 if (ret)
1313 goto err_htc_cleanup;
1314
1315 /* This runs the init function if registered */
1316 ret = register_netdev(ar->net_dev);
1317 if (ret) {
1318 ath6kl_err("register_netdev failed\n");
1319 ath6kl_destroy(ar->net_dev, 0);
1320 return ret;
1321 }
1322
1323 set_bit(NETDEV_REGISTERED, &ar->flag);
1324
1325 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
1326 __func__, ar->net_dev->name, ar->net_dev, ar);
1327
1328 return ret;
1329
1330err_htc_cleanup:
Kalle Vaload226ec2011-08-10 09:49:12 +03001331 ath6kl_htc_cleanup(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001332err_bmi_cleanup:
1333 ath6kl_bmi_cleanup(ar);
1334err_wq:
1335 destroy_workqueue(ar->ath6kl_wq);
1336 return ret;
1337}
1338
1339void ath6kl_stop_txrx(struct ath6kl *ar)
1340{
1341 struct net_device *ndev = ar->net_dev;
1342
1343 if (!ndev)
1344 return;
1345
1346 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1347
1348 if (down_interruptible(&ar->sem)) {
1349 ath6kl_err("down_interruptible failed\n");
1350 return;
1351 }
1352
1353 if (ar->wlan_pwr_state != WLAN_POWER_STATE_CUT_PWR)
1354 ath6kl_stop_endpoint(ndev, false, true);
1355
Raja Mani575b5f32011-07-19 19:27:33 +05301356 clear_bit(WLAN_ENABLED, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03001357}
1358
1359/*
1360 * We need to differentiate between the surprise and planned removal of the
1361 * device because of the following consideration:
1362 *
1363 * - In case of surprise removal, the hcd already frees up the pending
1364 * for the device and hence there is no need to unregister the function
1365 * driver inorder to get these requests. For planned removal, the function
1366 * driver has to explicitly unregister itself to have the hcd return all the
1367 * pending requests before the data structures for the devices are freed up.
1368 * Note that as per the current implementation, the function driver will
1369 * end up releasing all the devices since there is no API to selectively
1370 * release a particular device.
1371 *
1372 * - Certain commands issued to the target can be skipped for surprise
1373 * removal since they will anyway not go through.
1374 */
1375void ath6kl_destroy(struct net_device *dev, unsigned int unregister)
1376{
1377 struct ath6kl *ar;
1378
1379 if (!dev || !ath6kl_priv(dev)) {
1380 ath6kl_err("failed to get device structure\n");
1381 return;
1382 }
1383
1384 ar = ath6kl_priv(dev);
1385
1386 destroy_workqueue(ar->ath6kl_wq);
1387
1388 if (ar->htc_target)
Kalle Vaload226ec2011-08-10 09:49:12 +03001389 ath6kl_htc_cleanup(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001390
1391 aggr_module_destroy(ar->aggr_cntxt);
1392
1393 ath6kl_cookie_cleanup(ar);
1394
1395 ath6kl_cleanup_amsdu_rxbufs(ar);
1396
1397 ath6kl_bmi_cleanup(ar);
1398
1399 if (unregister && test_bit(NETDEV_REGISTERED, &ar->flag)) {
1400 unregister_netdev(dev);
1401 clear_bit(NETDEV_REGISTERED, &ar->flag);
1402 }
1403
1404 free_netdev(dev);
1405
Vasanthakumar Thiagarajan852bd9d2011-07-21 14:24:54 +05301406 wlan_node_table_cleanup(&ar->scan_table);
1407
Raja Mani19703572011-08-04 19:26:30 +05301408 kfree(ar->fw_board);
1409 kfree(ar->fw_otp);
1410 kfree(ar->fw);
1411 kfree(ar->fw_patch);
1412
Kalle Valobdcd8172011-07-18 00:22:30 +03001413 ath6kl_cfg80211_deinit(ar);
1414}