blob: 6e6a1413ed3d39b7070996927b1a18e9290276e9 [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 Rothwellc6efe572011-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 Valo003353b2011-09-01 10:14:21 +030029static unsigned int testmode;
Kalle Valobdcd8172011-07-18 00:22:30 +030030
31module_param(debug_mask, uint, 0644);
Kalle Valo003353b2011-09-01 10:14:21 +030032module_param(testmode, uint, 0644);
Kalle Valobdcd8172011-07-18 00:22:30 +030033
34/*
35 * Include definitions here that can be used to tune the WLAN module
36 * behavior. Different customers can tune the behavior as per their needs,
37 * here.
38 */
39
40/*
41 * This configuration item enable/disable keepalive support.
42 * Keepalive support: In the absence of any data traffic to AP, null
43 * frames will be sent to the AP at periodic interval, to keep the association
44 * active. This configuration item defines the periodic interval.
45 * Use value of zero to disable keepalive support
46 * Default: 60 seconds
47 */
48#define WLAN_CONFIG_KEEP_ALIVE_INTERVAL 60
49
50/*
51 * This configuration item sets the value of disconnect timeout
52 * Firmware delays sending the disconnec event to the host for this
53 * timeout after is gets disconnected from the current AP.
54 * If the firmware successly roams within the disconnect timeout
55 * it sends a new connect event
56 */
57#define WLAN_CONFIG_DISCONNECT_TIMEOUT 10
58
59#define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
60
Kalle Valobdcd8172011-07-18 00:22:30 +030061#define ATH6KL_DATA_OFFSET 64
62struct sk_buff *ath6kl_buf_alloc(int size)
63{
64 struct sk_buff *skb;
65 u16 reserved;
66
67 /* Add chacheline space at front and back of buffer */
68 reserved = (2 * L1_CACHE_BYTES) + ATH6KL_DATA_OFFSET +
Vasanthakumar Thiagarajan1df94a82011-08-17 18:45:10 +053069 sizeof(struct htc_packet) + ATH6KL_HTC_ALIGN_BYTES;
Kalle Valobdcd8172011-07-18 00:22:30 +030070 skb = dev_alloc_skb(size + reserved);
71
72 if (skb)
73 skb_reserve(skb, reserved - L1_CACHE_BYTES);
74 return skb;
75}
76
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +053077void ath6kl_init_profile_info(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +030078{
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +053079 vif->ssid_len = 0;
80 memset(vif->ssid, 0, sizeof(vif->ssid));
81
82 vif->dot11_auth_mode = OPEN_AUTH;
83 vif->auth_mode = NONE_AUTH;
84 vif->prwise_crypto = NONE_CRYPT;
85 vif->prwise_crypto_len = 0;
86 vif->grp_crypto = NONE_CRYPT;
87 vif->grp_crypto_len = 0;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +053088 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajan8c8b65e2011-10-25 19:34:04 +053089 memset(vif->req_bssid, 0, sizeof(vif->req_bssid));
90 memset(vif->bssid, 0, sizeof(vif->bssid));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +053091 vif->bss_ch = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +030092}
93
Kalle Valobdcd8172011-07-18 00:22:30 +030094static int ath6kl_set_host_app_area(struct ath6kl *ar)
95{
96 u32 address, data;
97 struct host_app_area host_app_area;
98
99 /* Fetch the address of the host_app_area_s
100 * instance in the host interest area */
101 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_app_host_interest));
Kevin Fang31024d92011-07-11 17:14:13 +0800102 address = TARG_VTOP(ar->target_type, address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300103
Kalle Valoaddb44b2011-09-02 10:32:05 +0300104 if (ath6kl_diag_read32(ar, address, &data))
Kalle Valobdcd8172011-07-18 00:22:30 +0300105 return -EIO;
106
Kevin Fang31024d92011-07-11 17:14:13 +0800107 address = TARG_VTOP(ar->target_type, data);
Kalle Valocbf49a62011-10-05 12:23:17 +0300108 host_app_area.wmi_protocol_ver = cpu_to_le32(WMI_PROTOCOL_VERSION);
Kalle Valoaddb44b2011-09-02 10:32:05 +0300109 if (ath6kl_diag_write(ar, address, (u8 *) &host_app_area,
110 sizeof(struct host_app_area)))
Kalle Valobdcd8172011-07-18 00:22:30 +0300111 return -EIO;
112
113 return 0;
114}
115
116static inline void set_ac2_ep_map(struct ath6kl *ar,
117 u8 ac,
118 enum htc_endpoint_id ep)
119{
120 ar->ac2ep_map[ac] = ep;
121 ar->ep2ac_map[ep] = ac;
122}
123
124/* connect to a service */
125static int ath6kl_connectservice(struct ath6kl *ar,
126 struct htc_service_connect_req *con_req,
127 char *desc)
128{
129 int status;
130 struct htc_service_connect_resp response;
131
132 memset(&response, 0, sizeof(response));
133
Kalle Vaload226ec2011-08-10 09:49:12 +0300134 status = ath6kl_htc_conn_service(ar->htc_target, con_req, &response);
Kalle Valobdcd8172011-07-18 00:22:30 +0300135 if (status) {
136 ath6kl_err("failed to connect to %s service status:%d\n",
137 desc, status);
138 return status;
139 }
140
141 switch (con_req->svc_id) {
142 case WMI_CONTROL_SVC:
143 if (test_bit(WMI_ENABLED, &ar->flag))
144 ath6kl_wmi_set_control_ep(ar->wmi, response.endpoint);
145 ar->ctrl_ep = response.endpoint;
146 break;
147 case WMI_DATA_BE_SVC:
148 set_ac2_ep_map(ar, WMM_AC_BE, response.endpoint);
149 break;
150 case WMI_DATA_BK_SVC:
151 set_ac2_ep_map(ar, WMM_AC_BK, response.endpoint);
152 break;
153 case WMI_DATA_VI_SVC:
154 set_ac2_ep_map(ar, WMM_AC_VI, response.endpoint);
155 break;
156 case WMI_DATA_VO_SVC:
157 set_ac2_ep_map(ar, WMM_AC_VO, response.endpoint);
158 break;
159 default:
160 ath6kl_err("service id is not mapped %d\n", con_req->svc_id);
161 return -EINVAL;
162 }
163
164 return 0;
165}
166
167static int ath6kl_init_service_ep(struct ath6kl *ar)
168{
169 struct htc_service_connect_req connect;
170
171 memset(&connect, 0, sizeof(connect));
172
173 /* these fields are the same for all service endpoints */
174 connect.ep_cb.rx = ath6kl_rx;
175 connect.ep_cb.rx_refill = ath6kl_rx_refill;
176 connect.ep_cb.tx_full = ath6kl_tx_queue_full;
177
178 /*
179 * Set the max queue depth so that our ath6kl_tx_queue_full handler
180 * gets called.
181 */
182 connect.max_txq_depth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
183 connect.ep_cb.rx_refill_thresh = ATH6KL_MAX_RX_BUFFERS / 4;
184 if (!connect.ep_cb.rx_refill_thresh)
185 connect.ep_cb.rx_refill_thresh++;
186
187 /* connect to control service */
188 connect.svc_id = WMI_CONTROL_SVC;
189 if (ath6kl_connectservice(ar, &connect, "WMI CONTROL"))
190 return -EIO;
191
192 connect.flags |= HTC_FLGS_TX_BNDL_PAD_EN;
193
194 /*
195 * Limit the HTC message size on the send path, although e can
196 * receive A-MSDU frames of 4K, we will only send ethernet-sized
197 * (802.3) frames on the send path.
198 */
199 connect.max_rxmsg_sz = WMI_MAX_TX_DATA_FRAME_LENGTH;
200
201 /*
202 * To reduce the amount of committed memory for larger A_MSDU
203 * frames, use the recv-alloc threshold mechanism for larger
204 * packets.
205 */
206 connect.ep_cb.rx_alloc_thresh = ATH6KL_BUFFER_SIZE;
207 connect.ep_cb.rx_allocthresh = ath6kl_alloc_amsdu_rxbuf;
208
209 /*
210 * For the remaining data services set the connection flag to
211 * reduce dribbling, if configured to do so.
212 */
213 connect.conn_flags |= HTC_CONN_FLGS_REDUCE_CRED_DRIB;
214 connect.conn_flags &= ~HTC_CONN_FLGS_THRESH_MASK;
215 connect.conn_flags |= HTC_CONN_FLGS_THRESH_LVL_HALF;
216
217 connect.svc_id = WMI_DATA_BE_SVC;
218
219 if (ath6kl_connectservice(ar, &connect, "WMI DATA BE"))
220 return -EIO;
221
222 /* connect to back-ground map this to WMI LOW_PRI */
223 connect.svc_id = WMI_DATA_BK_SVC;
224 if (ath6kl_connectservice(ar, &connect, "WMI DATA BK"))
225 return -EIO;
226
227 /* connect to Video service, map this to to HI PRI */
228 connect.svc_id = WMI_DATA_VI_SVC;
229 if (ath6kl_connectservice(ar, &connect, "WMI DATA VI"))
230 return -EIO;
231
232 /*
233 * Connect to VO service, this is currently not mapped to a WMI
234 * priority stream due to historical reasons. WMI originally
235 * defined 3 priorities over 3 mailboxes We can change this when
236 * WMI is reworked so that priorities are not dependent on
237 * mailboxes.
238 */
239 connect.svc_id = WMI_DATA_VO_SVC;
240 if (ath6kl_connectservice(ar, &connect, "WMI DATA VO"))
241 return -EIO;
242
243 return 0;
244}
245
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530246void ath6kl_init_control_info(struct ath6kl_vif *vif)
Kalle Valobdcd8172011-07-18 00:22:30 +0300247{
Vasanthakumar Thiagarajane29f25f2011-10-25 19:34:15 +0530248 ath6kl_init_profile_info(vif);
Vasanthakumar Thiagarajan34503342011-10-25 19:34:02 +0530249 vif->def_txkey_index = 0;
Vasanthakumar Thiagarajan6f2a73f2011-10-25 19:34:06 +0530250 memset(vif->wep_key_list, 0, sizeof(vif->wep_key_list));
Vasanthakumar Thiagarajanf74bac52011-10-25 19:34:05 +0530251 vif->ch_hint = 0;
Kalle Valobdcd8172011-07-18 00:22:30 +0300252}
253
254/*
255 * Set HTC/Mbox operational parameters, this can only be called when the
256 * target is in the BMI phase.
257 */
258static int ath6kl_set_htc_params(struct ath6kl *ar, u32 mbox_isr_yield_val,
259 u8 htc_ctrl_buf)
260{
261 int status;
262 u32 blk_size;
263
264 blk_size = ar->mbox_info.block_size;
265
266 if (htc_ctrl_buf)
267 blk_size |= ((u32)htc_ctrl_buf) << 16;
268
269 /* set the host interest area for the block size */
270 status = ath6kl_bmi_write(ar,
271 ath6kl_get_hi_item_addr(ar,
272 HI_ITEM(hi_mbox_io_block_sz)),
273 (u8 *)&blk_size,
274 4);
275 if (status) {
276 ath6kl_err("bmi_write_memory for IO block size failed\n");
277 goto out;
278 }
279
280 ath6kl_dbg(ATH6KL_DBG_TRC, "block size set: %d (target addr:0x%X)\n",
281 blk_size,
282 ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_mbox_io_block_sz)));
283
284 if (mbox_isr_yield_val) {
285 /* set the host interest area for the mbox ISR yield limit */
286 status = ath6kl_bmi_write(ar,
287 ath6kl_get_hi_item_addr(ar,
288 HI_ITEM(hi_mbox_isr_yield_limit)),
289 (u8 *)&mbox_isr_yield_val,
290 4);
291 if (status) {
292 ath6kl_err("bmi_write_memory for yield limit failed\n");
293 goto out;
294 }
295 }
296
297out:
298 return status;
299}
300
301#define REG_DUMP_COUNT_AR6003 60
302#define REGISTER_DUMP_LEN_MAX 60
303
304static void ath6kl_dump_target_assert_info(struct ath6kl *ar)
305{
306 u32 address;
307 u32 regdump_loc = 0;
308 int status;
309 u32 regdump_val[REGISTER_DUMP_LEN_MAX];
310 u32 i;
311
312 if (ar->target_type != TARGET_TYPE_AR6003)
313 return;
314
315 /* the reg dump pointer is copied to the host interest area */
316 address = ath6kl_get_hi_item_addr(ar, HI_ITEM(hi_failure_state));
Kevin Fang31024d92011-07-11 17:14:13 +0800317 address = TARG_VTOP(ar->target_type, address);
Kalle Valobdcd8172011-07-18 00:22:30 +0300318
319 /* read RAM location through diagnostic window */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300320 status = ath6kl_diag_read32(ar, address, &regdump_loc);
Kalle Valobdcd8172011-07-18 00:22:30 +0300321
322 if (status || !regdump_loc) {
323 ath6kl_err("failed to get ptr to register dump area\n");
324 return;
325 }
326
327 ath6kl_dbg(ATH6KL_DBG_TRC, "location of register dump data: 0x%X\n",
328 regdump_loc);
Kevin Fang31024d92011-07-11 17:14:13 +0800329 regdump_loc = TARG_VTOP(ar->target_type, regdump_loc);
Kalle Valobdcd8172011-07-18 00:22:30 +0300330
331 /* fetch register dump data */
Kalle Valoaddb44b2011-09-02 10:32:05 +0300332 status = ath6kl_diag_read(ar, regdump_loc, (u8 *)&regdump_val[0],
333 REG_DUMP_COUNT_AR6003 * (sizeof(u32)));
Kalle Valobdcd8172011-07-18 00:22:30 +0300334
335 if (status) {
336 ath6kl_err("failed to get register dump\n");
337 return;
338 }
339 ath6kl_dbg(ATH6KL_DBG_TRC, "Register Dump:\n");
340
341 for (i = 0; i < REG_DUMP_COUNT_AR6003; i++)
342 ath6kl_dbg(ATH6KL_DBG_TRC, " %d : 0x%8.8X\n",
343 i, regdump_val[i]);
344
345}
346
347void ath6kl_target_failure(struct ath6kl *ar)
348{
349 ath6kl_err("target asserted\n");
350
351 /* try dumping target assertion information (if any) */
352 ath6kl_dump_target_assert_info(ar);
353
354}
355
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530356static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
Kalle Valobdcd8172011-07-18 00:22:30 +0300357{
358 int status = 0;
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300359 int ret;
Kalle Valobdcd8172011-07-18 00:22:30 +0300360
361 /*
362 * Configure the device for rx dot11 header rules. "0,0" are the
363 * default values. Required if checksum offload is needed. Set
364 * RxMetaVersion to 2.
365 */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530366 if (ath6kl_wmi_set_rx_frame_format_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300367 ar->rx_meta_ver, 0, 0)) {
368 ath6kl_err("unable to set the rx frame format\n");
369 status = -EIO;
370 }
371
372 if (ar->conf_flags & ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN)
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530373 if ((ath6kl_wmi_pmparams_cmd(ar->wmi, idx, 0, 1, 0, 0, 1,
Kalle Valobdcd8172011-07-18 00:22:30 +0300374 IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
375 ath6kl_err("unable to set power save fail event policy\n");
376 status = -EIO;
377 }
378
379 if (!(ar->conf_flags & ATH6KL_CONF_IGNORE_ERP_BARKER))
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530380 if ((ath6kl_wmi_set_lpreamble_cmd(ar->wmi, idx, 0,
Kalle Valobdcd8172011-07-18 00:22:30 +0300381 WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
382 ath6kl_err("unable to set barker preamble policy\n");
383 status = -EIO;
384 }
385
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530386 if (ath6kl_wmi_set_keepalive_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300387 WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) {
388 ath6kl_err("unable to set keep alive interval\n");
389 status = -EIO;
390 }
391
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530392 if (ath6kl_wmi_disctimeout_cmd(ar->wmi, idx,
Kalle Valobdcd8172011-07-18 00:22:30 +0300393 WLAN_CONFIG_DISCONNECT_TIMEOUT)) {
394 ath6kl_err("unable to set disconnect timeout\n");
395 status = -EIO;
396 }
397
398 if (!(ar->conf_flags & ATH6KL_CONF_ENABLE_TX_BURST))
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530399 if (ath6kl_wmi_set_wmm_txop(ar->wmi, idx, WMI_TXOP_DISABLED)) {
Kalle Valobdcd8172011-07-18 00:22:30 +0300400 ath6kl_err("unable to set txop bursting\n");
401 status = -EIO;
402 }
403
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530404 /*
405 * FIXME: Make sure p2p configurations are not applied to
406 * non-p2p capable interfaces when multivif support is enabled.
407 */
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300408 if (ar->p2p) {
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530409 ret = ath6kl_wmi_info_req_cmd(ar->wmi, idx,
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300410 P2P_FLAG_CAPABILITIES_REQ |
411 P2P_FLAG_MACADDR_REQ |
412 P2P_FLAG_HMODEL_REQ);
413 if (ret) {
414 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
415 "capabilities (%d) - assuming P2P not "
416 "supported\n", ret);
417 ar->p2p = 0;
418 }
419 }
420
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530421 /*
422 * FIXME: Make sure p2p configurations are not applied to
423 * non-p2p capable interfaces when multivif support is enabled.
424 */
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300425 if (ar->p2p) {
426 /* Enable Probe Request reporting for P2P */
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +0530427 ret = ath6kl_wmi_probe_report_req_cmd(ar->wmi, idx, true);
Jouni Malinen6bbc7c32011-09-05 17:38:47 +0300428 if (ret) {
429 ath6kl_dbg(ATH6KL_DBG_TRC, "failed to enable Probe "
430 "Request reporting (%d)\n", ret);
431 }
Jouni Malinen4dea08e2011-08-30 21:57:57 +0300432 }
433
Kalle Valobdcd8172011-07-18 00:22:30 +0300434 return status;
435}
436
437int ath6kl_configure_target(struct ath6kl *ar)
438{
439 u32 param, ram_reserved_size;
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530440 u8 fw_iftype, fw_mode = 0, fw_submode = 0;
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530441 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +0300442
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530443 /*
444 * Note: Even though the firmware interface type is
445 * chosen as BSS_STA for all three interfaces, can
446 * be configured to IBSS/AP as long as the fw submode
447 * remains normal mode (0 - AP, STA and IBSS). But
448 * due to an target assert in firmware only one interface is
449 * configured for now.
450 */
Vasanthakumar Thiagarajandd3751f2011-10-25 19:33:59 +0530451 fw_iftype = HI_OPTION_FW_MODE_BSS_STA;
Kalle Valobdcd8172011-07-18 00:22:30 +0300452
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530453 for (i = 0; i < MAX_NUM_VIF; i++)
454 fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
455
456 /*
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530457 * By default, submodes :
458 * vif[0] - AP/STA/IBSS
459 * vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
460 * vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530461 */
Vasanthakumar Thiagarajan3226f68a2011-10-25 19:34:24 +0530462
463 for (i = 0; i < ar->max_norm_iface; i++)
464 fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
465 (i * HI_OPTION_FW_SUBMODE_BITS);
466
467 for (i = ar->max_norm_iface; i < MAX_NUM_VIF; i++)
468 fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
469 (i * HI_OPTION_FW_SUBMODE_BITS);
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530470
471 /*
472 * FIXME: This needs to be removed once the multivif
473 * support is enabled.
474 */
475 if (ar->p2p)
476 fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530477
Kalle Valobdcd8172011-07-18 00:22:30 +0300478 param = HTC_PROTOCOL_VERSION;
479 if (ath6kl_bmi_write(ar,
480 ath6kl_get_hi_item_addr(ar,
481 HI_ITEM(hi_app_host_interest)),
482 (u8 *)&param, 4) != 0) {
483 ath6kl_err("bmi_write_memory for htc version failed\n");
484 return -EIO;
485 }
486
487 /* set the firmware mode to STA/IBSS/AP */
488 param = 0;
489
490 if (ath6kl_bmi_read(ar,
491 ath6kl_get_hi_item_addr(ar,
492 HI_ITEM(hi_option_flag)),
493 (u8 *)&param, 4) != 0) {
494 ath6kl_err("bmi_read_memory for setting fwmode failed\n");
495 return -EIO;
496 }
497
Vasanthakumar Thiagarajan7b858322011-10-25 19:34:22 +0530498 param |= (MAX_NUM_VIF << HI_OPTION_NUM_DEV_SHIFT);
499 param |= fw_mode << HI_OPTION_FW_MODE_SHIFT;
500 param |= fw_submode << HI_OPTION_FW_SUBMODE_SHIFT;
501
Kalle Valobdcd8172011-07-18 00:22:30 +0300502 param |= (0 << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
503 param |= (0 << HI_OPTION_FW_BRIDGE_SHIFT);
504
505 if (ath6kl_bmi_write(ar,
506 ath6kl_get_hi_item_addr(ar,
507 HI_ITEM(hi_option_flag)),
508 (u8 *)&param,
509 4) != 0) {
510 ath6kl_err("bmi_write_memory for setting fwmode failed\n");
511 return -EIO;
512 }
513
514 ath6kl_dbg(ATH6KL_DBG_TRC, "firmware mode set\n");
515
516 /*
517 * Hardcode the address use for the extended board data
518 * Ideally this should be pre-allocate by the OS at boot time
519 * But since it is a new feature and board data is loaded
520 * at init time, we have to workaround this from host.
521 * It is difficult to patch the firmware boot code,
522 * but possible in theory.
523 */
524
Kalle Valo991b27e2011-09-07 10:55:17 +0300525 param = ar->hw.board_ext_data_addr;
526 ram_reserved_size = ar->hw.reserved_ram_size;
Kalle Valobdcd8172011-07-18 00:22:30 +0300527
Kalle Valo991b27e2011-09-07 10:55:17 +0300528 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
529 HI_ITEM(hi_board_ext_data)),
530 (u8 *)&param, 4) != 0) {
531 ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
532 return -EIO;
533 }
534
535 if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
536 HI_ITEM(hi_end_ram_reserve_sz)),
537 (u8 *)&ram_reserved_size, 4) != 0) {
538 ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
539 return -EIO;
Kalle Valobdcd8172011-07-18 00:22:30 +0300540 }
541
542 /* set the block size for the target */
543 if (ath6kl_set_htc_params(ar, MBOX_YIELD_LIMIT, 0))
544 /* use default number of control buffers */
545 return -EIO;
546
547 return 0;
548}
549
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +0530550void ath6kl_core_free(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300551{
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +0530552 wiphy_free(ar->wiphy);
Kalle Valobdcd8172011-07-18 00:22:30 +0300553}
554
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530555void ath6kl_core_cleanup(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +0300556{
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530557 destroy_workqueue(ar->ath6kl_wq);
Kalle Valobdcd8172011-07-18 00:22:30 +0300558
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +0530559 if (ar->htc_target)
560 ath6kl_htc_cleanup(ar->htc_target);
561
562 ath6kl_cookie_cleanup(ar);
563
564 ath6kl_cleanup_amsdu_rxbufs(ar);
565
566 ath6kl_bmi_cleanup(ar);
567
568 ath6kl_debug_cleanup(ar);
569
570 kfree(ar->fw_board);
571 kfree(ar->fw_otp);
572 kfree(ar->fw);
573 kfree(ar->fw_patch);
574
575 ath6kl_deinit_ieee80211_hw(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +0300576}
577
578/* firmware upload */
Kalle Valobdcd8172011-07-18 00:22:30 +0300579static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
580 u8 **fw, size_t *fw_len)
581{
582 const struct firmware *fw_entry;
583 int ret;
584
585 ret = request_firmware(&fw_entry, filename, ar->dev);
586 if (ret)
587 return ret;
588
589 *fw_len = fw_entry->size;
590 *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
591
592 if (*fw == NULL)
593 ret = -ENOMEM;
594
595 release_firmware(fw_entry);
596
597 return ret;
598}
599
Sam Leffler92ecbff2011-09-07 10:55:16 +0300600#ifdef CONFIG_OF
601static const char *get_target_ver_dir(const struct ath6kl *ar)
602{
603 switch (ar->version.target_ver) {
604 case AR6003_REV1_VERSION:
605 return "ath6k/AR6003/hw1.0";
606 case AR6003_REV2_VERSION:
607 return "ath6k/AR6003/hw2.0";
608 case AR6003_REV3_VERSION:
609 return "ath6k/AR6003/hw2.1.1";
610 }
611 ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__,
612 ar->version.target_ver);
613 return NULL;
614}
615
616/*
617 * Check the device tree for a board-id and use it to construct
618 * the pathname to the firmware file. Used (for now) to find a
619 * fallback to the "bdata.bin" file--typically a symlink to the
620 * appropriate board-specific file.
621 */
622static bool check_device_tree(struct ath6kl *ar)
623{
624 static const char *board_id_prop = "atheros,board-id";
625 struct device_node *node;
626 char board_filename[64];
627 const char *board_id;
628 int ret;
629
630 for_each_compatible_node(node, NULL, "atheros,ath6kl") {
631 board_id = of_get_property(node, board_id_prop, NULL);
632 if (board_id == NULL) {
633 ath6kl_warn("No \"%s\" property on %s node.\n",
634 board_id_prop, node->name);
635 continue;
636 }
637 snprintf(board_filename, sizeof(board_filename),
638 "%s/bdata.%s.bin", get_target_ver_dir(ar), board_id);
639
640 ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
641 &ar->fw_board_len);
642 if (ret) {
643 ath6kl_err("Failed to get DT board file %s: %d\n",
644 board_filename, ret);
645 continue;
646 }
647 return true;
648 }
649 return false;
650}
651#else
652static bool check_device_tree(struct ath6kl *ar)
653{
654 return false;
655}
656#endif /* CONFIG_OF */
657
Kalle Valobdcd8172011-07-18 00:22:30 +0300658static int ath6kl_fetch_board_file(struct ath6kl *ar)
659{
660 const char *filename;
661 int ret;
662
Kalle Valo772c31e2011-09-07 10:55:16 +0300663 if (ar->fw_board != NULL)
664 return 0;
665
Kalle Valobdcd8172011-07-18 00:22:30 +0300666 switch (ar->version.target_ver) {
667 case AR6003_REV2_VERSION:
668 filename = AR6003_REV2_BOARD_DATA_FILE;
669 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800670 case AR6004_REV1_VERSION:
671 filename = AR6004_REV1_BOARD_DATA_FILE;
672 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300673 default:
674 filename = AR6003_REV3_BOARD_DATA_FILE;
675 break;
676 }
677
678 ret = ath6kl_get_fw(ar, filename, &ar->fw_board,
679 &ar->fw_board_len);
680 if (ret == 0) {
681 /* managed to get proper board file */
682 return 0;
683 }
684
Sam Leffler92ecbff2011-09-07 10:55:16 +0300685 if (check_device_tree(ar)) {
686 /* got board file from device tree */
687 return 0;
688 }
689
Kalle Valobdcd8172011-07-18 00:22:30 +0300690 /* there was no proper board file, try to use default instead */
691 ath6kl_warn("Failed to get board file %s (%d), trying to find default board file.\n",
692 filename, ret);
693
694 switch (ar->version.target_ver) {
695 case AR6003_REV2_VERSION:
696 filename = AR6003_REV2_DEFAULT_BOARD_DATA_FILE;
697 break;
Kevin Fang31024d92011-07-11 17:14:13 +0800698 case AR6004_REV1_VERSION:
699 filename = AR6004_REV1_DEFAULT_BOARD_DATA_FILE;
700 break;
Kalle Valobdcd8172011-07-18 00:22:30 +0300701 default:
702 filename = AR6003_REV3_DEFAULT_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) {
709 ath6kl_err("Failed to get default board file %s: %d\n",
710 filename, ret);
711 return ret;
712 }
713
714 ath6kl_warn("WARNING! No proper board file was not found, instead using a default board file.\n");
715 ath6kl_warn("Most likely your hardware won't work as specified. Install correct board file!\n");
716
717 return 0;
718}
719
Kalle Valo772c31e2011-09-07 10:55:16 +0300720static int ath6kl_fetch_otp_file(struct ath6kl *ar)
721{
722 const char *filename;
723 int ret;
724
725 if (ar->fw_otp != NULL)
726 return 0;
727
728 switch (ar->version.target_ver) {
729 case AR6003_REV2_VERSION:
730 filename = AR6003_REV2_OTP_FILE;
731 break;
732 case AR6004_REV1_VERSION:
733 ath6kl_dbg(ATH6KL_DBG_TRC, "AR6004 doesn't need OTP file\n");
734 return 0;
735 break;
736 default:
737 filename = AR6003_REV3_OTP_FILE;
738 break;
739 }
740
741 ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
742 &ar->fw_otp_len);
743 if (ret) {
744 ath6kl_err("Failed to get OTP file %s: %d\n",
745 filename, ret);
746 return ret;
747 }
748
749 return 0;
750}
751
752static int ath6kl_fetch_fw_file(struct ath6kl *ar)
753{
754 const char *filename;
755 int ret;
756
757 if (ar->fw != NULL)
758 return 0;
759
760 if (testmode) {
761 switch (ar->version.target_ver) {
762 case AR6003_REV2_VERSION:
763 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
764 break;
765 case AR6003_REV3_VERSION:
766 filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
767 break;
768 case AR6004_REV1_VERSION:
769 ath6kl_warn("testmode not supported with ar6004\n");
770 return -EOPNOTSUPP;
771 default:
772 ath6kl_warn("unknown target version: 0x%x\n",
773 ar->version.target_ver);
774 return -EINVAL;
775 }
776
777 set_bit(TESTMODE, &ar->flag);
778
779 goto get_fw;
780 }
781
782 switch (ar->version.target_ver) {
783 case AR6003_REV2_VERSION:
784 filename = AR6003_REV2_FIRMWARE_FILE;
785 break;
786 case AR6004_REV1_VERSION:
787 filename = AR6004_REV1_FIRMWARE_FILE;
788 break;
789 default:
790 filename = AR6003_REV3_FIRMWARE_FILE;
791 break;
792 }
793
794get_fw:
795 ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
796 if (ret) {
797 ath6kl_err("Failed to get firmware file %s: %d\n",
798 filename, ret);
799 return ret;
800 }
801
802 return 0;
803}
804
805static int ath6kl_fetch_patch_file(struct ath6kl *ar)
806{
807 const char *filename;
808 int ret;
809
810 switch (ar->version.target_ver) {
811 case AR6003_REV2_VERSION:
812 filename = AR6003_REV2_PATCH_FILE;
813 break;
814 case AR6004_REV1_VERSION:
815 /* FIXME: implement for AR6004 */
816 return 0;
817 break;
818 default:
819 filename = AR6003_REV3_PATCH_FILE;
820 break;
821 }
822
823 if (ar->fw_patch == NULL) {
824 ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
825 &ar->fw_patch_len);
826 if (ret) {
827 ath6kl_err("Failed to get patch file %s: %d\n",
828 filename, ret);
829 return ret;
830 }
831 }
832
833 return 0;
834}
835
Kalle Valo50d41232011-09-07 10:55:17 +0300836static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
Kalle Valo772c31e2011-09-07 10:55:16 +0300837{
838 int ret;
839
Kalle Valo772c31e2011-09-07 10:55:16 +0300840 ret = ath6kl_fetch_otp_file(ar);
841 if (ret)
842 return ret;
843
844 ret = ath6kl_fetch_fw_file(ar);
845 if (ret)
846 return ret;
847
848 ret = ath6kl_fetch_patch_file(ar);
849 if (ret)
850 return ret;
851
852 return 0;
853}
Kalle Valobdcd8172011-07-18 00:22:30 +0300854
Kalle Valo50d41232011-09-07 10:55:17 +0300855static int ath6kl_fetch_fw_api2(struct ath6kl *ar)
856{
857 size_t magic_len, len, ie_len;
858 const struct firmware *fw;
859 struct ath6kl_fw_ie *hdr;
860 const char *filename;
861 const u8 *data;
Kalle Valo97e04962011-09-12 13:47:34 +0300862 int ret, ie_id, i, index, bit;
Kalle Valo8a137482011-09-07 10:55:17 +0300863 __le32 *val;
Kalle Valo50d41232011-09-07 10:55:17 +0300864
865 switch (ar->version.target_ver) {
866 case AR6003_REV2_VERSION:
867 filename = AR6003_REV2_FIRMWARE_2_FILE;
868 break;
869 case AR6003_REV3_VERSION:
870 filename = AR6003_REV3_FIRMWARE_2_FILE;
871 break;
872 case AR6004_REV1_VERSION:
873 filename = AR6004_REV1_FIRMWARE_2_FILE;
874 break;
875 default:
876 return -EOPNOTSUPP;
877 }
878
879 ret = request_firmware(&fw, filename, ar->dev);
880 if (ret)
881 return ret;
882
883 data = fw->data;
884 len = fw->size;
885
886 /* magic also includes the null byte, check that as well */
887 magic_len = strlen(ATH6KL_FIRMWARE_MAGIC) + 1;
888
889 if (len < magic_len) {
890 ret = -EINVAL;
891 goto out;
892 }
893
894 if (memcmp(data, ATH6KL_FIRMWARE_MAGIC, magic_len) != 0) {
895 ret = -EINVAL;
896 goto out;
897 }
898
899 len -= magic_len;
900 data += magic_len;
901
902 /* loop elements */
903 while (len > sizeof(struct ath6kl_fw_ie)) {
904 /* hdr is unaligned! */
905 hdr = (struct ath6kl_fw_ie *) data;
906
907 ie_id = le32_to_cpup(&hdr->id);
908 ie_len = le32_to_cpup(&hdr->len);
909
910 len -= sizeof(*hdr);
911 data += sizeof(*hdr);
912
913 if (len < ie_len) {
914 ret = -EINVAL;
915 goto out;
916 }
917
918 switch (ie_id) {
919 case ATH6KL_FW_IE_OTP_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300920 ath6kl_dbg(ATH6KL_DBG_BOOT, "found otp image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300921 ie_len);
922
Kalle Valo50d41232011-09-07 10:55:17 +0300923 ar->fw_otp = kmemdup(data, ie_len, GFP_KERNEL);
924
925 if (ar->fw_otp == NULL) {
926 ret = -ENOMEM;
927 goto out;
928 }
929
930 ar->fw_otp_len = ie_len;
931 break;
932 case ATH6KL_FW_IE_FW_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300933 ath6kl_dbg(ATH6KL_DBG_BOOT, "found fw image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300934 ie_len);
935
Kalle Valo50d41232011-09-07 10:55:17 +0300936 ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
937
938 if (ar->fw == NULL) {
939 ret = -ENOMEM;
940 goto out;
941 }
942
943 ar->fw_len = ie_len;
944 break;
945 case ATH6KL_FW_IE_PATCH_IMAGE:
Kalle Valoef548622011-10-01 09:43:09 +0300946 ath6kl_dbg(ATH6KL_DBG_BOOT, "found patch image ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300947 ie_len);
948
Kalle Valo50d41232011-09-07 10:55:17 +0300949 ar->fw_patch = kmemdup(data, ie_len, GFP_KERNEL);
950
951 if (ar->fw_patch == NULL) {
952 ret = -ENOMEM;
953 goto out;
954 }
955
956 ar->fw_patch_len = ie_len;
957 break;
Kalle Valo8a137482011-09-07 10:55:17 +0300958 case ATH6KL_FW_IE_RESERVED_RAM_SIZE:
959 val = (__le32 *) data;
960 ar->hw.reserved_ram_size = le32_to_cpup(val);
Kalle Valo6bc36432011-09-27 14:31:11 +0300961
962 ath6kl_dbg(ATH6KL_DBG_BOOT,
963 "found reserved ram size ie 0x%d\n",
964 ar->hw.reserved_ram_size);
Kalle Valo8a137482011-09-07 10:55:17 +0300965 break;
Kalle Valo97e04962011-09-12 13:47:34 +0300966 case ATH6KL_FW_IE_CAPABILITIES:
Kalle Valo6bc36432011-09-27 14:31:11 +0300967 ath6kl_dbg(ATH6KL_DBG_BOOT,
Kalle Valoef548622011-10-01 09:43:09 +0300968 "found firmware capabilities ie (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +0300969 ie_len);
970
Kalle Valo97e04962011-09-12 13:47:34 +0300971 for (i = 0; i < ATH6KL_FW_CAPABILITY_MAX; i++) {
972 index = ALIGN(i, 8) / 8;
973 bit = i % 8;
974
975 if (data[index] & (1 << bit))
976 __set_bit(i, ar->fw_capabilities);
977 }
Kalle Valo6bc36432011-09-27 14:31:11 +0300978
979 ath6kl_dbg_dump(ATH6KL_DBG_BOOT, "capabilities", "",
980 ar->fw_capabilities,
981 sizeof(ar->fw_capabilities));
Kalle Valo97e04962011-09-12 13:47:34 +0300982 break;
Kalle Valo1b4304d2011-09-27 11:05:26 +0300983 case ATH6KL_FW_IE_PATCH_ADDR:
984 if (ie_len != sizeof(*val))
985 break;
986
987 val = (__le32 *) data;
988 ar->hw.dataset_patch_addr = le32_to_cpup(val);
Kalle Valo6bc36432011-09-27 14:31:11 +0300989
990 ath6kl_dbg(ATH6KL_DBG_BOOT,
991 "found patch address ie 0x%d\n",
992 ar->hw.dataset_patch_addr);
Kalle Valo1b4304d2011-09-27 11:05:26 +0300993 break;
Kalle Valo50d41232011-09-07 10:55:17 +0300994 default:
Kalle Valo6bc36432011-09-27 14:31:11 +0300995 ath6kl_dbg(ATH6KL_DBG_BOOT, "Unknown fw ie: %u\n",
Kalle Valo50d41232011-09-07 10:55:17 +0300996 le32_to_cpup(&hdr->id));
997 break;
998 }
999
1000 len -= ie_len;
1001 data += ie_len;
1002 };
1003
1004 ret = 0;
1005out:
1006 release_firmware(fw);
1007
1008 return ret;
1009}
1010
1011static int ath6kl_fetch_firmwares(struct ath6kl *ar)
1012{
1013 int ret;
1014
1015 ret = ath6kl_fetch_board_file(ar);
1016 if (ret)
1017 return ret;
1018
1019 ret = ath6kl_fetch_fw_api2(ar);
Kalle Valo6bc36432011-09-27 14:31:11 +03001020 if (ret == 0) {
1021 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 2\n");
Kalle Valo50d41232011-09-07 10:55:17 +03001022 return 0;
Kalle Valo6bc36432011-09-27 14:31:11 +03001023 }
Kalle Valo50d41232011-09-07 10:55:17 +03001024
1025 ret = ath6kl_fetch_fw_api1(ar);
1026 if (ret)
1027 return ret;
1028
Kalle Valo6bc36432011-09-27 14:31:11 +03001029 ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 1\n");
1030
Kalle Valo50d41232011-09-07 10:55:17 +03001031 return 0;
1032}
1033
Kalle Valobdcd8172011-07-18 00:22:30 +03001034static int ath6kl_upload_board_file(struct ath6kl *ar)
1035{
1036 u32 board_address, board_ext_address, param;
Kevin Fang31024d92011-07-11 17:14:13 +08001037 u32 board_data_size, board_ext_data_size;
Kalle Valobdcd8172011-07-18 00:22:30 +03001038 int ret;
1039
Kalle Valo772c31e2011-09-07 10:55:16 +03001040 if (WARN_ON(ar->fw_board == NULL))
1041 return -ENOENT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001042
Kevin Fang31024d92011-07-11 17:14:13 +08001043 /*
1044 * Determine where in Target RAM to write Board Data.
1045 * For AR6004, host determine Target RAM address for
1046 * writing board data.
1047 */
1048 if (ar->target_type == TARGET_TYPE_AR6004) {
1049 board_address = AR6004_REV1_BOARD_DATA_ADDRESS;
1050 ath6kl_bmi_write(ar,
1051 ath6kl_get_hi_item_addr(ar,
1052 HI_ITEM(hi_board_data)),
1053 (u8 *) &board_address, 4);
1054 } else {
1055 ath6kl_bmi_read(ar,
1056 ath6kl_get_hi_item_addr(ar,
1057 HI_ITEM(hi_board_data)),
1058 (u8 *) &board_address, 4);
1059 }
1060
Kalle Valobdcd8172011-07-18 00:22:30 +03001061 /* determine where in target ram to write extended board data */
1062 ath6kl_bmi_read(ar,
1063 ath6kl_get_hi_item_addr(ar,
1064 HI_ITEM(hi_board_ext_data)),
1065 (u8 *) &board_ext_address, 4);
1066
Kalle Valobdcd8172011-07-18 00:22:30 +03001067 if (board_ext_address == 0) {
1068 ath6kl_err("Failed to get board file target address.\n");
1069 return -EINVAL;
1070 }
1071
Kevin Fang31024d92011-07-11 17:14:13 +08001072 switch (ar->target_type) {
1073 case TARGET_TYPE_AR6003:
1074 board_data_size = AR6003_BOARD_DATA_SZ;
1075 board_ext_data_size = AR6003_BOARD_EXT_DATA_SZ;
1076 break;
1077 case TARGET_TYPE_AR6004:
1078 board_data_size = AR6004_BOARD_DATA_SZ;
1079 board_ext_data_size = AR6004_BOARD_EXT_DATA_SZ;
1080 break;
1081 default:
1082 WARN_ON(1);
1083 return -EINVAL;
1084 break;
1085 }
1086
1087 if (ar->fw_board_len == (board_data_size +
1088 board_ext_data_size)) {
1089
Kalle Valobdcd8172011-07-18 00:22:30 +03001090 /* write extended board data */
Kalle Valo6bc36432011-09-27 14:31:11 +03001091 ath6kl_dbg(ATH6KL_DBG_BOOT,
1092 "writing extended board data to 0x%x (%d B)\n",
1093 board_ext_address, board_ext_data_size);
1094
Kalle Valobdcd8172011-07-18 00:22:30 +03001095 ret = ath6kl_bmi_write(ar, board_ext_address,
Kevin Fang31024d92011-07-11 17:14:13 +08001096 ar->fw_board + board_data_size,
1097 board_ext_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +03001098 if (ret) {
1099 ath6kl_err("Failed to write extended board data: %d\n",
1100 ret);
1101 return ret;
1102 }
1103
1104 /* record that extended board data is initialized */
Kevin Fang31024d92011-07-11 17:14:13 +08001105 param = (board_ext_data_size << 16) | 1;
1106
Kalle Valobdcd8172011-07-18 00:22:30 +03001107 ath6kl_bmi_write(ar,
1108 ath6kl_get_hi_item_addr(ar,
1109 HI_ITEM(hi_board_ext_data_config)),
1110 (unsigned char *) &param, 4);
1111 }
1112
Kevin Fang31024d92011-07-11 17:14:13 +08001113 if (ar->fw_board_len < board_data_size) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001114 ath6kl_err("Too small board file: %zu\n", ar->fw_board_len);
1115 ret = -EINVAL;
1116 return ret;
1117 }
1118
Kalle Valo6bc36432011-09-27 14:31:11 +03001119 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
1120 board_address, board_data_size);
1121
Kalle Valobdcd8172011-07-18 00:22:30 +03001122 ret = ath6kl_bmi_write(ar, board_address, ar->fw_board,
Kevin Fang31024d92011-07-11 17:14:13 +08001123 board_data_size);
Kalle Valobdcd8172011-07-18 00:22:30 +03001124
1125 if (ret) {
1126 ath6kl_err("Board file bmi write failed: %d\n", ret);
1127 return ret;
1128 }
1129
1130 /* record the fact that Board Data IS initialized */
1131 param = 1;
1132 ath6kl_bmi_write(ar,
1133 ath6kl_get_hi_item_addr(ar,
1134 HI_ITEM(hi_board_data_initialized)),
1135 (u8 *)&param, 4);
1136
1137 return ret;
1138}
1139
1140static int ath6kl_upload_otp(struct ath6kl *ar)
1141{
Kalle Valobdcd8172011-07-18 00:22:30 +03001142 u32 address, param;
Kalle Valobef26a72011-10-12 09:58:28 +03001143 bool from_hw = false;
Kalle Valobdcd8172011-07-18 00:22:30 +03001144 int ret;
1145
Kalle Valo772c31e2011-09-07 10:55:16 +03001146 if (WARN_ON(ar->fw_otp == NULL))
1147 return -ENOENT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001148
Kalle Valoa01ac412011-09-07 10:55:17 +03001149 address = ar->hw.app_load_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001150
Kalle Valoef548622011-10-01 09:43:09 +03001151 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing otp to 0x%x (%zd B)\n", address,
Kalle Valo6bc36432011-09-27 14:31:11 +03001152 ar->fw_otp_len);
1153
Kalle Valobdcd8172011-07-18 00:22:30 +03001154 ret = ath6kl_bmi_fast_download(ar, address, ar->fw_otp,
1155 ar->fw_otp_len);
1156 if (ret) {
1157 ath6kl_err("Failed to upload OTP file: %d\n", ret);
1158 return ret;
1159 }
1160
Kalle Valo639d0b82011-09-12 12:48:09 +03001161 /* read firmware start address */
1162 ret = ath6kl_bmi_read(ar,
1163 ath6kl_get_hi_item_addr(ar,
1164 HI_ITEM(hi_app_start)),
1165 (u8 *) &address, sizeof(address));
1166
1167 if (ret) {
1168 ath6kl_err("Failed to read hi_app_start: %d\n", ret);
1169 return ret;
1170 }
1171
Kalle Valobef26a72011-10-12 09:58:28 +03001172 if (ar->hw.app_start_override_addr == 0) {
1173 ar->hw.app_start_override_addr = address;
1174 from_hw = true;
1175 }
Kalle Valo639d0b82011-09-12 12:48:09 +03001176
Kalle Valobef26a72011-10-12 09:58:28 +03001177 ath6kl_dbg(ATH6KL_DBG_BOOT, "app_start_override_addr%s 0x%x\n",
1178 from_hw ? " (from hw)" : "",
Kalle Valo6bc36432011-09-27 14:31:11 +03001179 ar->hw.app_start_override_addr);
1180
Kalle Valobdcd8172011-07-18 00:22:30 +03001181 /* execute the OTP code */
Kalle Valobef26a72011-10-12 09:58:28 +03001182 ath6kl_dbg(ATH6KL_DBG_BOOT, "executing OTP at 0x%x\n",
1183 ar->hw.app_start_override_addr);
Kalle Valobdcd8172011-07-18 00:22:30 +03001184 param = 0;
Kalle Valobef26a72011-10-12 09:58:28 +03001185 ath6kl_bmi_execute(ar, ar->hw.app_start_override_addr, &param);
Kalle Valobdcd8172011-07-18 00:22:30 +03001186
1187 return ret;
1188}
1189
1190static int ath6kl_upload_firmware(struct ath6kl *ar)
1191{
Kalle Valobdcd8172011-07-18 00:22:30 +03001192 u32 address;
1193 int ret;
1194
Kalle Valo772c31e2011-09-07 10:55:16 +03001195 if (WARN_ON(ar->fw == NULL))
1196 return -ENOENT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001197
Kalle Valoa01ac412011-09-07 10:55:17 +03001198 address = ar->hw.app_load_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001199
Kalle Valoef548622011-10-01 09:43:09 +03001200 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing firmware to 0x%x (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +03001201 address, ar->fw_len);
1202
Kalle Valobdcd8172011-07-18 00:22:30 +03001203 ret = ath6kl_bmi_fast_download(ar, address, ar->fw, ar->fw_len);
1204
1205 if (ret) {
1206 ath6kl_err("Failed to write firmware: %d\n", ret);
1207 return ret;
1208 }
1209
Kevin Fang31024d92011-07-11 17:14:13 +08001210 /*
1211 * Set starting address for firmware
1212 * Don't need to setup app_start override addr on AR6004
1213 */
1214 if (ar->target_type != TARGET_TYPE_AR6004) {
Kalle Valoa01ac412011-09-07 10:55:17 +03001215 address = ar->hw.app_start_override_addr;
Kevin Fang31024d92011-07-11 17:14:13 +08001216 ath6kl_bmi_set_app_start(ar, address);
1217 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001218 return ret;
1219}
1220
1221static int ath6kl_upload_patch(struct ath6kl *ar)
1222{
Kalle Valobdcd8172011-07-18 00:22:30 +03001223 u32 address, param;
1224 int ret;
1225
Kalle Valo772c31e2011-09-07 10:55:16 +03001226 if (WARN_ON(ar->fw_patch == NULL))
1227 return -ENOENT;
Kalle Valobdcd8172011-07-18 00:22:30 +03001228
Kalle Valoa01ac412011-09-07 10:55:17 +03001229 address = ar->hw.dataset_patch_addr;
Kalle Valobdcd8172011-07-18 00:22:30 +03001230
Kalle Valoef548622011-10-01 09:43:09 +03001231 ath6kl_dbg(ATH6KL_DBG_BOOT, "writing patch to 0x%x (%zd B)\n",
Kalle Valo6bc36432011-09-27 14:31:11 +03001232 address, ar->fw_patch_len);
1233
Kalle Valobdcd8172011-07-18 00:22:30 +03001234 ret = ath6kl_bmi_write(ar, address, ar->fw_patch, ar->fw_patch_len);
1235 if (ret) {
1236 ath6kl_err("Failed to write patch file: %d\n", ret);
1237 return ret;
1238 }
1239
1240 param = address;
1241 ath6kl_bmi_write(ar,
1242 ath6kl_get_hi_item_addr(ar,
1243 HI_ITEM(hi_dset_list_head)),
1244 (unsigned char *) &param, 4);
1245
1246 return 0;
1247}
1248
1249static int ath6kl_init_upload(struct ath6kl *ar)
1250{
1251 u32 param, options, sleep, address;
1252 int status = 0;
1253
Kevin Fang31024d92011-07-11 17:14:13 +08001254 if (ar->target_type != TARGET_TYPE_AR6003 &&
1255 ar->target_type != TARGET_TYPE_AR6004)
Kalle Valobdcd8172011-07-18 00:22:30 +03001256 return -EINVAL;
1257
1258 /* temporarily disable system sleep */
1259 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1260 status = ath6kl_bmi_reg_read(ar, address, &param);
1261 if (status)
1262 return status;
1263
1264 options = param;
1265
1266 param |= ATH6KL_OPTION_SLEEP_DISABLE;
1267 status = ath6kl_bmi_reg_write(ar, address, param);
1268 if (status)
1269 return status;
1270
1271 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1272 status = ath6kl_bmi_reg_read(ar, address, &param);
1273 if (status)
1274 return status;
1275
1276 sleep = param;
1277
1278 param |= SM(SYSTEM_SLEEP_DISABLE, 1);
1279 status = ath6kl_bmi_reg_write(ar, address, param);
1280 if (status)
1281 return status;
1282
1283 ath6kl_dbg(ATH6KL_DBG_TRC, "old options: %d, old sleep: %d\n",
1284 options, sleep);
1285
1286 /* program analog PLL register */
Kevin Fang31024d92011-07-11 17:14:13 +08001287 /* no need to control 40/44MHz clock on AR6004 */
1288 if (ar->target_type != TARGET_TYPE_AR6004) {
1289 status = ath6kl_bmi_reg_write(ar, ATH6KL_ANALOG_PLL_REGISTER,
1290 0xF9104001);
Kalle Valobdcd8172011-07-18 00:22:30 +03001291
Kevin Fang31024d92011-07-11 17:14:13 +08001292 if (status)
1293 return status;
Kalle Valobdcd8172011-07-18 00:22:30 +03001294
Kevin Fang31024d92011-07-11 17:14:13 +08001295 /* Run at 80/88MHz by default */
1296 param = SM(CPU_CLOCK_STANDARD, 1);
1297
1298 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1299 status = ath6kl_bmi_reg_write(ar, address, param);
1300 if (status)
1301 return status;
1302 }
Kalle Valobdcd8172011-07-18 00:22:30 +03001303
1304 param = 0;
1305 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1306 param = SM(LPO_CAL_ENABLE, 1);
1307 status = ath6kl_bmi_reg_write(ar, address, param);
1308 if (status)
1309 return status;
1310
1311 /* WAR to avoid SDIO CRC err */
1312 if (ar->version.target_ver == AR6003_REV2_VERSION) {
1313 ath6kl_err("temporary war to avoid sdio crc error\n");
1314
1315 param = 0x20;
1316
1317 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1318 status = ath6kl_bmi_reg_write(ar, address, param);
1319 if (status)
1320 return status;
1321
1322 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1323 status = ath6kl_bmi_reg_write(ar, address, param);
1324 if (status)
1325 return status;
1326
1327 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1328 status = ath6kl_bmi_reg_write(ar, address, param);
1329 if (status)
1330 return status;
1331
1332 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1333 status = ath6kl_bmi_reg_write(ar, address, param);
1334 if (status)
1335 return status;
1336 }
1337
1338 /* write EEPROM data to Target RAM */
1339 status = ath6kl_upload_board_file(ar);
1340 if (status)
1341 return status;
1342
1343 /* transfer One time Programmable data */
1344 status = ath6kl_upload_otp(ar);
1345 if (status)
1346 return status;
1347
1348 /* Download Target firmware */
1349 status = ath6kl_upload_firmware(ar);
1350 if (status)
1351 return status;
1352
1353 status = ath6kl_upload_patch(ar);
1354 if (status)
1355 return status;
1356
1357 /* Restore system sleep */
1358 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1359 status = ath6kl_bmi_reg_write(ar, address, sleep);
1360 if (status)
1361 return status;
1362
1363 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1364 param = options | 0x20;
1365 status = ath6kl_bmi_reg_write(ar, address, param);
1366 if (status)
1367 return status;
1368
1369 /* Configure GPIO AR6003 UART */
1370 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1371 status = ath6kl_bmi_write(ar,
1372 ath6kl_get_hi_item_addr(ar,
1373 HI_ITEM(hi_dbg_uart_txpin)),
1374 (u8 *)&param, 4);
1375
1376 return status;
1377}
1378
Kalle Valoa01ac412011-09-07 10:55:17 +03001379static int ath6kl_init_hw_params(struct ath6kl *ar)
1380{
1381 switch (ar->version.target_ver) {
1382 case AR6003_REV2_VERSION:
1383 ar->hw.dataset_patch_addr = AR6003_REV2_DATASET_PATCH_ADDRESS;
1384 ar->hw.app_load_addr = AR6003_REV2_APP_LOAD_ADDRESS;
Kalle Valo991b27e2011-09-07 10:55:17 +03001385 ar->hw.board_ext_data_addr = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
1386 ar->hw.reserved_ram_size = AR6003_REV2_RAM_RESERVE_SIZE;
Kalle Valobef26a72011-10-12 09:58:28 +03001387
1388 /* hw2.0 needs override address hardcoded */
1389 ar->hw.app_start_override_addr = 0x944C00;
1390
Kalle Valoa01ac412011-09-07 10:55:17 +03001391 break;
1392 case AR6003_REV3_VERSION:
1393 ar->hw.dataset_patch_addr = AR6003_REV3_DATASET_PATCH_ADDRESS;
1394 ar->hw.app_load_addr = 0x1234;
Kalle Valo991b27e2011-09-07 10:55:17 +03001395 ar->hw.board_ext_data_addr = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
1396 ar->hw.reserved_ram_size = AR6003_REV3_RAM_RESERVE_SIZE;
Kalle Valoa01ac412011-09-07 10:55:17 +03001397 break;
1398 case AR6004_REV1_VERSION:
1399 ar->hw.dataset_patch_addr = AR6003_REV2_DATASET_PATCH_ADDRESS;
1400 ar->hw.app_load_addr = AR6003_REV3_APP_LOAD_ADDRESS;
Kalle Valo991b27e2011-09-07 10:55:17 +03001401 ar->hw.board_ext_data_addr = AR6004_REV1_BOARD_EXT_DATA_ADDRESS;
1402 ar->hw.reserved_ram_size = AR6004_REV1_RAM_RESERVE_SIZE;
Kalle Valoa01ac412011-09-07 10:55:17 +03001403 break;
1404 default:
1405 ath6kl_err("Unsupported hardware version: 0x%x\n",
1406 ar->version.target_ver);
1407 return -EINVAL;
1408 }
1409
Kalle Valo6bc36432011-09-27 14:31:11 +03001410 ath6kl_dbg(ATH6KL_DBG_BOOT,
1411 "target_ver 0x%x target_type 0x%x dataset_patch 0x%x app_load_addr 0x%x\n",
1412 ar->version.target_ver, ar->target_type,
1413 ar->hw.dataset_patch_addr, ar->hw.app_load_addr);
1414 ath6kl_dbg(ATH6KL_DBG_BOOT,
1415 "app_start_override_addr 0x%x board_ext_data_addr 0x%x reserved_ram_size 0x%x",
1416 ar->hw.app_start_override_addr, ar->hw.board_ext_data_addr,
1417 ar->hw.reserved_ram_size);
1418
Kalle Valoa01ac412011-09-07 10:55:17 +03001419 return 0;
1420}
1421
Vasanthakumar Thiagarajan521dffc2011-10-25 19:33:56 +05301422static int ath6kl_init(struct ath6kl *ar)
Kalle Valobdcd8172011-07-18 00:22:30 +03001423{
Kalle Valobdcd8172011-07-18 00:22:30 +03001424 int status = 0;
1425 s32 timeleft;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301426 struct net_device *ndev;
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301427 int i;
Kalle Valobdcd8172011-07-18 00:22:30 +03001428
1429 if (!ar)
1430 return -EIO;
1431
1432 /* Do we need to finish the BMI phase */
1433 if (ath6kl_bmi_done(ar)) {
1434 status = -EIO;
1435 goto ath6kl_init_done;
1436 }
1437
1438 /* Indicate that WMI is enabled (although not ready yet) */
1439 set_bit(WMI_ENABLED, &ar->flag);
Vasanthakumar Thiagarajan28657852011-07-21 12:00:49 +05301440 ar->wmi = ath6kl_wmi_init(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001441 if (!ar->wmi) {
1442 ath6kl_err("failed to initialize wmi\n");
1443 status = -EIO;
1444 goto ath6kl_init_done;
1445 }
1446
1447 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: got wmi @ 0x%p.\n", __func__, ar->wmi);
1448
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301449 status = ath6kl_register_ieee80211_hw(ar);
1450 if (status)
1451 goto err_node_cleanup;
1452
1453 status = ath6kl_debug_init(ar);
1454 if (status) {
1455 wiphy_unregister(ar->wiphy);
1456 goto err_node_cleanup;
1457 }
1458
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301459 for (i = 0; i < MAX_NUM_VIF; i++)
1460 ar->avail_idx_map |= BIT(i);
1461
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301462 rtnl_lock();
1463
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301464 /* Add an initial station interface */
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301465 ndev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
1466 INFRA_NETWORK);
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301467
1468 rtnl_unlock();
1469
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301470 if (!ndev) {
1471 ath6kl_err("Failed to instantiate a network device\n");
1472 status = -ENOMEM;
1473 wiphy_unregister(ar->wiphy);
1474 goto err_debug_init;
1475 }
1476
1477
1478 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: name=%s dev=0x%p, ar=0x%p\n",
Vasanthakumar Thiagarajan28ae58d2011-10-25 19:34:14 +05301479 __func__, ndev->name, ndev, ar);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301480
Kalle Valobdcd8172011-07-18 00:22:30 +03001481 /*
1482 * The reason we have to wait for the target here is that the
1483 * driver layer has to init BMI in order to set the host block
1484 * size.
1485 */
Kalle Vaload226ec2011-08-10 09:49:12 +03001486 if (ath6kl_htc_wait_target(ar->htc_target)) {
Kalle Valobdcd8172011-07-18 00:22:30 +03001487 status = -EIO;
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301488 goto err_if_deinit;
Kalle Valobdcd8172011-07-18 00:22:30 +03001489 }
1490
1491 if (ath6kl_init_service_ep(ar)) {
1492 status = -EIO;
1493 goto err_cleanup_scatter;
1494 }
1495
1496 /* setup access class priority mappings */
1497 ar->ac_stream_pri_map[WMM_AC_BK] = 0; /* lowest */
1498 ar->ac_stream_pri_map[WMM_AC_BE] = 1;
1499 ar->ac_stream_pri_map[WMM_AC_VI] = 2;
1500 ar->ac_stream_pri_map[WMM_AC_VO] = 3; /* highest */
1501
1502 /* give our connected endpoints some buffers */
1503 ath6kl_rx_refill(ar->htc_target, ar->ctrl_ep);
1504 ath6kl_rx_refill(ar->htc_target, ar->ac2ep_map[WMM_AC_BE]);
1505
1506 /* allocate some buffers that handle larger AMSDU frames */
1507 ath6kl_refill_amsdu_rxbufs(ar, ATH6KL_MAX_AMSDU_RX_BUFFERS);
1508
1509 /* setup credit distribution */
Kalle Valocb64a612011-10-24 12:17:28 +03001510 ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
Kalle Valobdcd8172011-07-18 00:22:30 +03001511
1512 ath6kl_cookie_init(ar);
1513
1514 /* start HTC */
Kalle Vaload226ec2011-08-10 09:49:12 +03001515 status = ath6kl_htc_start(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001516
1517 if (status) {
1518 ath6kl_cookie_cleanup(ar);
1519 goto err_rxbuf_cleanup;
1520 }
1521
1522 /* Wait for Wmi event to be ready */
1523 timeleft = wait_event_interruptible_timeout(ar->event_wq,
1524 test_bit(WMI_READY,
1525 &ar->flag),
1526 WMI_TIMEOUT);
1527
Kalle Valo6bc36432011-09-27 14:31:11 +03001528 ath6kl_dbg(ATH6KL_DBG_BOOT, "firmware booted\n");
1529
Kalle Valobdcd8172011-07-18 00:22:30 +03001530 if (ar->version.abi_ver != ATH6KL_ABI_VERSION) {
1531 ath6kl_err("abi version mismatch: host(0x%x), target(0x%x)\n",
1532 ATH6KL_ABI_VERSION, ar->version.abi_ver);
1533 status = -EIO;
1534 goto err_htc_stop;
1535 }
1536
1537 if (!timeleft || signal_pending(current)) {
1538 ath6kl_err("wmi is not ready or wait was interrupted\n");
1539 status = -EIO;
1540 goto err_htc_stop;
1541 }
1542
1543 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: wmi is ready\n", __func__);
1544
1545 /* communicate the wmi protocol verision to the target */
1546 if ((ath6kl_set_host_app_area(ar)) != 0)
1547 ath6kl_err("unable to set the host app area\n");
1548
1549 ar->conf_flags = ATH6KL_CONF_IGNORE_ERP_BARKER |
1550 ATH6KL_CONF_ENABLE_11N | ATH6KL_CONF_ENABLE_TX_BURST;
1551
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301552 ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
1553 WIPHY_FLAG_HAVE_AP_SME;
Vivek Natarajan011a36e2011-09-19 13:29:16 +05301554
Vasanthakumar Thiagarajan0ce59442011-10-25 19:34:25 +05301555 for (i = 0; i < MAX_NUM_VIF; i++) {
1556 status = ath6kl_target_config_wlan_params(ar, i);
1557 if (status)
1558 goto err_htc_stop;
1559 }
Vasanthakumar Thiagarajand66ea4f2011-10-25 19:34:18 +05301560
1561 /*
1562 * Set mac address which is received in ready event
1563 * FIXME: Move to ath6kl_interface_add()
1564 */
1565 memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
1566
1567 return status;
Kalle Valobdcd8172011-07-18 00:22:30 +03001568
1569err_htc_stop:
Kalle Vaload226ec2011-08-10 09:49:12 +03001570 ath6kl_htc_stop(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001571err_rxbuf_cleanup:
Kalle Vaload226ec2011-08-10 09:49:12 +03001572 ath6kl_htc_flush_rx_buf(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001573 ath6kl_cleanup_amsdu_rxbufs(ar);
1574err_cleanup_scatter:
1575 ath6kl_hif_cleanup_scatter(ar);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301576err_if_deinit:
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301577 rtnl_lock();
Vasanthakumar Thiagarajan108438b2011-10-25 19:34:00 +05301578 ath6kl_deinit_if_data(netdev_priv(ndev));
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301579 rtnl_unlock();
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301580 wiphy_unregister(ar->wiphy);
1581err_debug_init:
1582 ath6kl_debug_cleanup(ar);
Vasanthakumar Thiagarajan852bd9d2011-07-21 14:24:54 +05301583err_node_cleanup:
Kalle Valobdcd8172011-07-18 00:22:30 +03001584 ath6kl_wmi_shutdown(ar->wmi);
1585 clear_bit(WMI_ENABLED, &ar->flag);
1586 ar->wmi = NULL;
1587
1588ath6kl_init_done:
1589 return status;
1590}
1591
1592int ath6kl_core_init(struct ath6kl *ar)
1593{
1594 int ret = 0;
1595 struct ath6kl_bmi_target_info targ_info;
1596
1597 ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
1598 if (!ar->ath6kl_wq)
1599 return -ENOMEM;
1600
1601 ret = ath6kl_bmi_init(ar);
1602 if (ret)
1603 goto err_wq;
1604
1605 ret = ath6kl_bmi_get_target_info(ar, &targ_info);
1606 if (ret)
1607 goto err_bmi_cleanup;
1608
1609 ar->version.target_ver = le32_to_cpu(targ_info.version);
1610 ar->target_type = le32_to_cpu(targ_info.type);
Vasanthakumar Thiagarajanbe98e3a2011-10-25 19:33:57 +05301611 ar->wiphy->hw_version = le32_to_cpu(targ_info.version);
Kalle Valobdcd8172011-07-18 00:22:30 +03001612
Kalle Valoa01ac412011-09-07 10:55:17 +03001613 ret = ath6kl_init_hw_params(ar);
1614 if (ret)
1615 goto err_bmi_cleanup;
1616
Kalle Valobdcd8172011-07-18 00:22:30 +03001617 ret = ath6kl_configure_target(ar);
1618 if (ret)
1619 goto err_bmi_cleanup;
1620
Kalle Vaload226ec2011-08-10 09:49:12 +03001621 ar->htc_target = ath6kl_htc_create(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001622
1623 if (!ar->htc_target) {
1624 ret = -ENOMEM;
1625 goto err_bmi_cleanup;
1626 }
1627
Kalle Valo772c31e2011-09-07 10:55:16 +03001628 ret = ath6kl_fetch_firmwares(ar);
1629 if (ret)
1630 goto err_htc_cleanup;
1631
Kalle Valobdcd8172011-07-18 00:22:30 +03001632 ret = ath6kl_init_upload(ar);
1633 if (ret)
1634 goto err_htc_cleanup;
1635
Vasanthakumar Thiagarajan521dffc2011-10-25 19:33:56 +05301636 ret = ath6kl_init(ar);
Kalle Valobdcd8172011-07-18 00:22:30 +03001637 if (ret)
1638 goto err_htc_cleanup;
1639
Kalle Valobdcd8172011-07-18 00:22:30 +03001640 return ret;
1641
1642err_htc_cleanup:
Kalle Vaload226ec2011-08-10 09:49:12 +03001643 ath6kl_htc_cleanup(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001644err_bmi_cleanup:
1645 ath6kl_bmi_cleanup(ar);
1646err_wq:
1647 destroy_workqueue(ar->ath6kl_wq);
Vasanthakumar Thiagarajan8dafb702011-10-25 19:33:58 +05301648
Kalle Valobdcd8172011-07-18 00:22:30 +03001649 return ret;
1650}
1651
Vasanthakumar Thiagarajan55055972011-10-25 19:34:23 +05301652void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301653{
1654 static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1655 bool discon_issued;
1656
1657 netif_stop_queue(vif->ndev);
1658
1659 clear_bit(WLAN_ENABLED, &vif->flags);
1660
1661 if (wmi_ready) {
1662 discon_issued = test_bit(CONNECTED, &vif->flags) ||
1663 test_bit(CONNECT_PEND, &vif->flags);
1664 ath6kl_disconnect(vif);
1665 del_timer(&vif->disconnect_timer);
1666
1667 if (discon_issued)
1668 ath6kl_disconnect_event(vif, DISCONNECT_CMD,
1669 (vif->nw_type & AP_NETWORK) ?
1670 bcast_mac : vif->bssid,
1671 0, NULL, 0);
1672 }
1673
1674 if (vif->scan_req) {
1675 cfg80211_scan_done(vif->scan_req, true);
1676 vif->scan_req = NULL;
1677 }
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301678}
1679
Kalle Valobdcd8172011-07-18 00:22:30 +03001680void ath6kl_stop_txrx(struct ath6kl *ar)
1681{
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301682 struct ath6kl_vif *vif, *tmp_vif;
Kalle Valobdcd8172011-07-18 00:22:30 +03001683
1684 set_bit(DESTROY_IN_PROGRESS, &ar->flag);
1685
1686 if (down_interruptible(&ar->sem)) {
1687 ath6kl_err("down_interruptible failed\n");
1688 return;
1689 }
1690
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301691 spin_lock(&ar->list_lock);
1692 list_for_each_entry_safe(vif, tmp_vif, &ar->vif_list, list) {
1693 list_del(&vif->list);
1694 spin_unlock(&ar->list_lock);
1695 ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
Vasanthakumar Thiagarajan27929722011-10-25 19:34:21 +05301696 rtnl_lock();
1697 ath6kl_deinit_if_data(vif);
1698 rtnl_unlock();
Vasanthakumar Thiagarajan990bd912011-10-25 19:34:20 +05301699 spin_lock(&ar->list_lock);
1700 }
1701 spin_unlock(&ar->list_lock);
Kalle Valobdcd8172011-07-18 00:22:30 +03001702
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301703 clear_bit(WMI_READY, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03001704
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301705 /*
1706 * After wmi_shudown all WMI events will be dropped. We
1707 * need to cleanup the buffers allocated in AP mode and
1708 * give disconnect notification to stack, which usually
1709 * happens in the disconnect_event. Simulate the disconnect
1710 * event by calling the function directly. Sometimes
1711 * disconnect_event will be received when the debug logs
1712 * are collected.
1713 */
1714 ath6kl_wmi_shutdown(ar->wmi);
Kalle Valobdcd8172011-07-18 00:22:30 +03001715
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301716 clear_bit(WMI_ENABLED, &ar->flag);
1717 if (ar->htc_target) {
1718 ath6kl_dbg(ATH6KL_DBG_TRC, "%s: shut down htc\n", __func__);
1719 ath6kl_htc_stop(ar->htc_target);
Kalle Valobdcd8172011-07-18 00:22:30 +03001720 }
1721
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301722 /*
1723 * Try to reset the device if we can. The driver may have been
1724 * configure NOT to reset the target during a debug session.
1725 */
1726 ath6kl_dbg(ATH6KL_DBG_TRC,
1727 "attempting to reset target on instance destroy\n");
1728 ath6kl_reset_device(ar, ar->target_type, true, true);
Kalle Valobdcd8172011-07-18 00:22:30 +03001729
Vasanthakumar Thiagarajan6db8fa52011-10-25 19:34:16 +05301730 clear_bit(WLAN_ENABLED, &ar->flag);
Kalle Valobdcd8172011-07-18 00:22:30 +03001731}