1 //------------------------------------------------------------------------------
2 // Copyright (c) 2004-2010 Atheros Communications Inc.
3 // All rights reserved.
7 // Permission to use, copy, modify, and/or distribute this software for any
8 // purpose with or without fee is hereby granted, provided that the above
9 // copyright notice and this permission notice appear in all copies.
11 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 // Author(s): ="Atheros"
22 //------------------------------------------------------------------------------
25 * This driver is a pseudo ethernet driver to access the Atheros AR6000
29 #include "ar6000_drv.h"
32 #include "wmi_filter_linux.h"
33 #include "epping_test.h"
34 #include "wlan_config.h"
35 #include "ar3kconfig.h"
37 #include "AR6002/addrs.h"
40 /* LINUX_HACK_FUDGE_FACTOR -- this is used to provide a workaround for linux behavior. When
41 * the meta data was added to the header it was found that linux did not correctly provide
42 * enough headroom. However when more headroom was requested beyond what was truly needed
43 * Linux gave the requested headroom. Therefore to get the necessary headroom from Linux
44 * the driver requests more than is needed by the amount = LINUX_HACK_FUDGE_FACTOR */
45 #define LINUX_HACK_FUDGE_FACTOR 16
46 #define BDATA_BDADDR_OFFSET 28
48 u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
49 u8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
53 #define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0)
54 #define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1)
55 #define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2)
56 #define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3)
57 #define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4)
58 #define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5)
59 #define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6)
61 static struct ath_debug_mask_description driver_debug_desc[] = {
62 { ATH_DEBUG_DBG_LOG , "Target Debug Logs"},
63 { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"},
64 { ATH_DEBUG_WLAN_SCAN , "WLAN scan"},
65 { ATH_DEBUG_WLAN_TX , "WLAN Tx"},
66 { ATH_DEBUG_WLAN_RX , "WLAN Rx"},
67 { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"},
68 { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"},
69 { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"},
70 { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"},
73 ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver,
75 "Linux Driver Interface",
76 ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN |
78 ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc),
84 #define IS_MAC_NULL(mac) (mac[0]==0 && mac[1]==0 && mac[2]==0 && mac[3]==0 && mac[4]==0 && mac[5]==0)
85 #define IS_MAC_BCAST(mac) (*mac==0xff)
87 #define DESCRIPTION "Driver to access the Atheros AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_)
89 MODULE_AUTHOR("Atheros Communications, Inc.");
90 MODULE_DESCRIPTION(DESCRIPTION);
91 MODULE_LICENSE("Dual BSD/GPL");
93 #ifndef REORG_APTC_HEURISTICS
94 #undef ADAPTIVE_POWER_THROUGHPUT_CONTROL
95 #endif /* REORG_APTC_HEURISTICS */
97 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
98 #define APTC_TRAFFIC_SAMPLING_INTERVAL 100 /* msec */
99 #define APTC_UPPER_THROUGHPUT_THRESHOLD 3000 /* Kbps */
100 #define APTC_LOWER_THROUGHPUT_THRESHOLD 2000 /* Kbps */
102 typedef struct aptc_traffic_record {
104 struct timeval samplingTS;
105 unsigned long bytesReceived;
106 unsigned long bytesTransmitted;
107 } APTC_TRAFFIC_RECORD;
110 APTC_TRAFFIC_RECORD aptcTR;
111 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
113 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
114 // callbacks registered by HCI transport driver
115 struct hci_transport_callbacks ar6kHciTransCallbacks = { NULL };
118 unsigned int processDot11Hdr = 0;
120 char ifname[IFNAMSIZ] = {0,};
122 int wlaninitmode = WLAN_INIT_MODE_DEFAULT;
123 static bool bypasswmi;
124 unsigned int debuglevel = 0;
125 int tspecCompliance = ATHEROS_COMPLIANCE;
126 unsigned int busspeedlow = 0;
127 unsigned int onebitmode = 0;
128 unsigned int skipflash = 0;
129 unsigned int wmitimeout = 2;
130 unsigned int wlanNodeCaching = 1;
131 unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT;
132 unsigned int logWmiRawMsgs = 0;
133 unsigned int enabletimerwar = 0;
134 unsigned int num_device = 1;
135 unsigned int regscanmode;
136 unsigned int fwmode = 1;
137 unsigned int mbox_yield_limit = 99;
138 unsigned int enablerssicompensation = 0;
139 int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF;
140 int allow_trace_signal = 0;
141 #ifdef CONFIG_HOST_TCMD_SUPPORT
142 unsigned int testmode =0;
145 unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC;
146 unsigned int panic_on_assert = 1;
147 unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT;
149 unsigned int setuphci = SETUPHCI_DEFAULT;
150 unsigned int loghci = 0;
151 unsigned int setupbtdev = SETUPBTDEV_DEFAULT;
152 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
153 unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT;
154 unsigned int hciuartscale = HCIUARTSCALE_DEFAULT;
155 unsigned int hciuartstep = HCIUARTSTEP_DEFAULT;
157 unsigned int csumOffload=0;
158 unsigned int csumOffloadTest=0;
159 unsigned int eppingtest=0;
160 unsigned int mac_addr_method;
161 unsigned int firmware_bridge;
163 module_param_string(ifname, ifname, sizeof(ifname), 0644);
164 module_param(wlaninitmode, int, 0644);
165 module_param(bypasswmi, bool, 0644);
166 module_param(debuglevel, uint, 0644);
167 module_param(tspecCompliance, int, 0644);
168 module_param(onebitmode, uint, 0644);
169 module_param(busspeedlow, uint, 0644);
170 module_param(skipflash, uint, 0644);
171 module_param(wmitimeout, uint, 0644);
172 module_param(wlanNodeCaching, uint, 0644);
173 module_param(logWmiRawMsgs, uint, 0644);
174 module_param(enableuartprint, uint, 0644);
175 module_param(enabletimerwar, uint, 0644);
176 module_param(fwmode, uint, 0644);
177 module_param(mbox_yield_limit, uint, 0644);
178 module_param(reduce_credit_dribble, int, 0644);
179 module_param(allow_trace_signal, int, 0644);
180 module_param(enablerssicompensation, uint, 0644);
181 module_param(processDot11Hdr, uint, 0644);
182 module_param(csumOffload, uint, 0644);
183 #ifdef CONFIG_HOST_TCMD_SUPPORT
184 module_param(testmode, uint, 0644);
186 module_param(irqprocmode, uint, 0644);
187 module_param(nohifscattersupport, uint, 0644);
188 module_param(panic_on_assert, uint, 0644);
189 module_param(setuphci, uint, 0644);
190 module_param(loghci, uint, 0644);
191 module_param(setupbtdev, uint, 0644);
192 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
193 module_param(ar3khcibaud, uint, 0644);
194 module_param(hciuartscale, uint, 0644);
195 module_param(hciuartstep, uint, 0644);
197 module_param(eppingtest, uint, 0644);
199 /* in 2.6.10 and later this is now a pointer to a uint */
200 unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX;
201 #define mboxnum &_mboxnum
204 u32 g_dbg_flags = DBG_DEFAULTS;
205 unsigned int debugflags = 0;
207 unsigned int debughtc = 0;
208 unsigned int debugbmi = 0;
209 unsigned int debughif = 0;
210 unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0};
211 unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0};
212 unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0};
213 unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0};
214 module_param(debugflags, uint, 0644);
215 module_param(debugdriver, int, 0644);
216 module_param(debughtc, uint, 0644);
217 module_param(debugbmi, uint, 0644);
218 module_param(debughif, uint, 0644);
219 module_param_array(txcreditsavailable, uint, mboxnum, 0644);
220 module_param_array(txcreditsconsumed, uint, mboxnum, 0644);
221 module_param_array(txcreditintrenable, uint, mboxnum, 0644);
222 module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644);
226 unsigned int resetok = 1;
227 unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0};
228 unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0};
229 unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0};
230 unsigned int hifBusRequestNumMax = 40;
231 unsigned int war23838_disabled = 0;
232 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
233 unsigned int enableAPTCHeuristics = 1;
234 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
235 module_param_array(tx_attempt, uint, mboxnum, 0644);
236 module_param_array(tx_post, uint, mboxnum, 0644);
237 module_param_array(tx_complete, uint, mboxnum, 0644);
238 module_param(hifBusRequestNumMax, uint, 0644);
239 module_param(war23838_disabled, uint, 0644);
240 module_param(resetok, uint, 0644);
241 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
242 module_param(enableAPTCHeuristics, uint, 0644);
243 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
245 #ifdef BLOCK_TX_PATH_FLAG
247 module_param(blocktx, int, 0644);
248 #endif /* BLOCK_TX_PATH_FLAG */
250 typedef struct user_rssi_compensation_t {
262 } USER_RSSI_CPENSATION;
264 static USER_RSSI_CPENSATION rssi_compensation_param;
266 static s16 rssi_compensation_table[96];
268 int reconnect_flag = 0;
269 static ar6k_pal_config_t ar6k_pal_config_g;
271 /* Function declarations */
272 static int ar6000_init_module(void);
273 static void ar6000_cleanup_module(void);
275 int ar6000_init(struct net_device *dev);
276 static int ar6000_open(struct net_device *dev);
277 static int ar6000_close(struct net_device *dev);
278 static void ar6000_init_control_info(struct ar6_softc *ar);
279 static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev);
281 void ar6000_destroy(struct net_device *dev, unsigned int unregister);
282 static void ar6000_detect_error(unsigned long ptr);
283 static void ar6000_set_multicast_list(struct net_device *dev);
284 static struct net_device_stats *ar6000_get_stats(struct net_device *dev);
286 static void disconnect_timer_handler(unsigned long ptr);
288 void read_rssi_compensation_param(struct ar6_softc *ar);
291 * HTC service connection handlers
293 static int ar6000_avail_ev(void *context, void *hif_handle);
295 static int ar6000_unavail_ev(void *context, void *hif_handle);
297 int ar6000_configure_target(struct ar6_softc *ar);
299 static void ar6000_target_failure(void *Instance, int Status);
301 static void ar6000_rx(void *Context, struct htc_packet *pPacket);
303 static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint);
305 static void ar6000_tx_complete(void *Context, struct htc_packet_queue *pPackets);
307 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket);
309 static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num);
310 static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf);
311 //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf);
313 static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length);
315 static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count);
317 static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar);
320 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
321 struct bin_attribute *bin_attr,
322 char *buf, loff_t pos, size_t count);
325 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
326 struct bin_attribute *bin_attr,
327 char *buf, loff_t pos, size_t count);
330 ar6000_sysfs_bmi_init(struct ar6_softc *ar);
332 void ar6k_cleanup_hci_pal(struct ar6_softc *ar);
335 ar6000_sysfs_bmi_deinit(struct ar6_softc *ar);
338 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode);
344 struct net_device *ar6000_devices[MAX_AR6000];
345 static int is_netdev_registered;
346 DECLARE_WAIT_QUEUE_HEAD(arEvent);
347 static void ar6000_cookie_init(struct ar6_softc *ar);
348 static void ar6000_cookie_cleanup(struct ar6_softc *ar);
349 static void ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie);
350 static struct ar_cookie *ar6000_alloc_cookie(struct ar6_softc *ar);
352 static int ar6000_reinstall_keys(struct ar6_softc *ar,u8 key_op_ctrl);
354 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
355 struct net_device *arApNetDev;
356 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
358 static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
360 #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \
361 (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
362 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
365 static struct net_device_ops ar6000_netdev_ops = {
367 .ndo_open = ar6000_open,
368 .ndo_stop = ar6000_close,
369 .ndo_get_stats = ar6000_get_stats,
370 .ndo_start_xmit = ar6000_data_tx,
371 .ndo_set_multicast_list = ar6000_set_multicast_list,
374 /* Debug log support */
377 * Flag to govern whether the debug logs should be parsed in the kernel
378 * or reported to the application.
380 #define REPORT_DEBUG_LOGS_TO_APP
383 ar6000_set_host_app_area(struct ar6_softc *ar)
386 struct host_app_area_s host_app_area;
388 /* Fetch the address of the host_app_area_s instance in the host interest area */
389 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest));
390 if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != 0) {
393 address = TARG_VTOP(ar->arTargetType, data);
394 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
395 if (ar6000_WriteDataDiag(ar->arHifDevice, address,
396 (u8 *)&host_app_area,
397 sizeof(struct host_app_area_s)) != 0)
405 u32 dbglog_get_debug_hdr_ptr(struct ar6_softc *ar)
411 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr));
412 if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address,
413 (u8 *)¶m, 4)) != 0)
422 * The dbglog module has been initialized. Its ok to access the relevant
423 * data stuctures over the diagnostic window.
426 ar6000_dbglog_init_done(struct ar6_softc *ar)
428 ar->dbglog_init_done = true;
431 u32 dbglog_get_debug_fragment(s8 *datap, u32 len, u32 limit)
440 buffer = (s32 *)datap;
441 length = (limit >> 2);
446 while (count < length) {
447 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
448 fraglen = (count << 2);
449 count += numargs + 1;
457 dbglog_parse_debug_logs(s8 *datap, u32 len)
468 buffer = (s32 *)datap;
470 while (count < length) {
471 debugid = DBGLOG_GET_DBGID(buffer[count]);
472 moduleid = DBGLOG_GET_MODULEID(buffer[count]);
473 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
474 timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]);
477 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp));
481 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid,
482 timestamp, buffer[count+1]));
486 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid,
487 timestamp, buffer[count+1], buffer[count+2]));
491 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs));
493 count += numargs + 1;
498 ar6000_dbglog_get_debug_logs(struct ar6_softc *ar)
500 u32 data[8]; /* Should be able to accommodate struct dbglog_buf_s */
507 if (!ar->dbglog_init_done) return A_ERROR;
510 AR6000_SPIN_LOCK(&ar->arLock, 0);
512 if (ar->dbgLogFetchInProgress) {
513 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
517 /* block out others */
518 ar->dbgLogFetchInProgress = true;
520 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
522 debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar);
523 printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr);
525 /* Get the contents of the ring buffer */
527 address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr);
528 length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */;
529 A_MEMZERO(data, sizeof(data));
530 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)data, length);
531 address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */);
533 dropped = data[1]; /* dropped */
534 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
535 A_MEMZERO(data, sizeof(data));
536 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)&data, length);
539 address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/);
540 length = data[3]; /* length */
541 if ((length) && (length <= data[2] /* bufsize*/)) {
542 /* Rewind the index if it is about to overrun the buffer */
543 if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) {
546 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
547 (u8 *)&ar->log_buffer[ar->log_cnt], length))
551 ar6000_dbglog_event(ar, dropped, (s8 *)&ar->log_buffer[ar->log_cnt], length);
552 ar->log_cnt += length;
554 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n",
558 address = TARG_VTOP(ar->arTargetType, data[0] /* next */);
559 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
560 A_MEMZERO(data, sizeof(data));
561 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
562 (u8 *)&data, length))
567 } while (address != firstbuf);
570 ar->dbgLogFetchInProgress = false;
576 ar6000_dbglog_event(struct ar6_softc *ar, u32 dropped,
577 s8 *buffer, u32 length)
579 #ifdef REPORT_DEBUG_LOGS_TO_APP
580 #define MAX_WIRELESS_EVENT_SIZE 252
582 * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages.
583 * There seems to be a limitation on the length of message that could be
584 * transmitted to the user app via this mechanism.
589 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
590 MAX_WIRELESS_EVENT_SIZE);
593 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
594 MAX_WIRELESS_EVENT_SIZE);
597 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n",
600 /* Interpret the debug logs */
601 dbglog_parse_debug_logs((s8 *)buffer, length);
602 #endif /* REPORT_DEBUG_LOGS_TO_APP */
607 ar6000_init_module(void)
609 static int probed = 0;
611 OSDRV_CALLBACKS osdrvCallbacks;
613 a_module_debug_support_init();
616 /* check for debug mask overrides */
618 ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc);
621 ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi);
624 ATH_DEBUG_SET_DEBUG_MASK(hif,debughif);
626 if (debugdriver != 0) {
627 ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver);
632 A_REGISTER_MODULE_DEBUG_INFO(driver);
634 A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks));
635 osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev;
636 osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev;
638 osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev;
639 osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev;
640 osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev;
644 /* Set the debug flags if specified at load time */
647 g_dbg_flags = debugflags;
656 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
657 memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD));
658 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
660 r = HIFInit(&osdrvCallbacks);
668 ar6000_cleanup_module(void)
671 struct net_device *ar6000_netdev;
673 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
674 /* Delete the Adaptive Power Control timer */
675 if (timer_pending(&aptcTimer)) {
676 del_timer_sync(&aptcTimer);
678 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
680 for (i=0; i < MAX_AR6000; i++) {
681 if (ar6000_devices[i] != NULL) {
682 ar6000_netdev = ar6000_devices[i];
683 ar6000_devices[i] = NULL;
684 ar6000_destroy(ar6000_netdev, 1);
688 HIFShutDownDevice(NULL);
690 a_module_debug_support_cleanup();
692 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n"));
695 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
697 aptcTimerHandler(unsigned long arg)
701 struct ar6_softc *ar;
704 ar = (struct ar6_softc *)arg;
705 A_ASSERT(ar != NULL);
706 A_ASSERT(!timer_pending(&aptcTimer));
708 AR6000_SPIN_LOCK(&ar->arLock, 0);
710 /* Get the number of bytes transferred */
711 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
712 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
714 /* Calculate and decide based on throughput thresholds */
715 throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */
716 if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) {
717 /* Enable Sleep and delete the timer */
718 A_ASSERT(ar->arWmiReady == true);
719 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
720 status = wmi_powermode_cmd(ar->arWmi, REC_POWER);
721 AR6000_SPIN_LOCK(&ar->arLock, 0);
722 A_ASSERT(status == 0);
723 aptcTR.timerScheduled = false;
725 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
728 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
730 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
733 ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num)
738 if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) {
739 A_NETBUF_ENQUEUE(q, osbuf);
747 A_PRINTF("%s(), allocation of netbuf failed", __func__);
751 static struct bin_attribute bmi_attr = {
752 .attr = {.name = "bmi", .mode = 0600},
753 .read = ar6000_sysfs_bmi_read,
754 .write = ar6000_sysfs_bmi_write,
758 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
759 struct bin_attribute *bin_attr,
760 char *buf, loff_t pos, size_t count)
763 struct ar6_softc *ar;
764 struct hif_device_os_device_info *osDevInfo;
766 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", (u32)count));
767 for (index=0; index < MAX_AR6000; index++) {
768 ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
769 osDevInfo = &ar->osDevInfo;
770 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
775 if (index == MAX_AR6000) return 0;
777 if ((BMIRawRead(ar->arHifDevice, (u8*)buf, count, true)) != 0) {
785 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
786 struct bin_attribute *bin_attr,
787 char *buf, loff_t pos, size_t count)
790 struct ar6_softc *ar;
791 struct hif_device_os_device_info *osDevInfo;
793 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", (u32)count));
794 for (index=0; index < MAX_AR6000; index++) {
795 ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
796 osDevInfo = &ar->osDevInfo;
797 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
802 if (index == MAX_AR6000) return 0;
804 if ((BMIRawWrite(ar->arHifDevice, (u8*)buf, count)) != 0) {
812 ar6000_sysfs_bmi_init(struct ar6_softc *ar)
816 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n"));
817 A_MEMZERO(&ar->osDevInfo, sizeof(struct hif_device_os_device_info));
819 /* Get the underlying OS device */
820 status = HIFConfigureDevice(ar->arHifDevice,
821 HIF_DEVICE_GET_OS_DEVICE,
823 sizeof(struct hif_device_os_device_info));
826 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n"));
830 /* Create a bmi entry in the sysfs filesystem */
831 if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0)
833 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n"));
841 ar6000_sysfs_bmi_deinit(struct ar6_softc *ar)
843 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n"));
845 sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr);
848 #define bmifn(fn) do { \
850 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); \
855 #ifdef SOFTMAC_FILE_USED
856 #define AR6002_MAC_ADDRESS_OFFSET 0x0A
857 #define AR6003_MAC_ADDRESS_OFFSET 0x16
859 void calculate_crc(u32 TargetType, u8 *eeprom_data)
867 if (TargetType == TARGET_TYPE_AR6001)
870 ptr_crc = (u16 *)eeprom_data;
872 else if (TargetType == TARGET_TYPE_AR6003)
875 ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
880 ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
887 // Recalculate new CRC
889 ptr16_eeprom = (u16 *)eeprom_data;
890 for (i = 0;i < eeprom_size; i += 2)
892 checksum = checksum ^ (*ptr16_eeprom);
895 checksum = 0xFFFF ^ checksum;
900 ar6000_softmac_update(struct ar6_softc *ar, u8 *eeprom_data, size_t size)
902 const char *source = "random generated";
903 const struct firmware *softmac_entry;
905 switch (ar->arTargetType) {
906 case TARGET_TYPE_AR6002:
907 ptr_mac = (u8 *)((u8 *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET);
909 case TARGET_TYPE_AR6003:
910 ptr_mac = (u8 *)((u8 *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET);
913 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Invalid Target Type\n"));
916 printk(KERN_DEBUG "MAC from EEPROM %pM\n", ptr_mac);
918 /* create a random MAC in case we cannot read file from system */
922 ptr_mac[3] = random32() & 0xff;
923 ptr_mac[4] = random32() & 0xff;
924 ptr_mac[5] = random32() & 0xff;
925 if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0)
927 char *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1);
929 unsigned int softmac[6];
930 memcpy(macbuf, softmac_entry->data, softmac_entry->size);
931 macbuf[softmac_entry->size] = '\0';
932 if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x",
933 &softmac[0], &softmac[1], &softmac[2],
934 &softmac[3], &softmac[4], &softmac[5])==6) {
936 for (i=0; i<6; ++i) {
937 ptr_mac[i] = softmac[i] & 0xff;
939 source = "softmac file";
943 A_RELEASE_FIRMWARE(softmac_entry);
945 printk(KERN_DEBUG "MAC from %s %pM\n", source, ptr_mac);
946 calculate_crc(ar->arTargetType, eeprom_data);
948 #endif /* SOFTMAC_FILE_USED */
951 ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, bool compressed)
954 const char *filename;
955 const struct firmware *fw_entry;
963 buf_len = &ar->fw_otp_len;
964 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
965 filename = AR6003_REV1_OTP_FILE;
966 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
967 filename = AR6003_REV2_OTP_FILE;
968 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
969 filename = AR6003_REV3_OTP_FILE;
971 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
976 case AR6K_FIRMWARE_FILE:
978 buf_len = &ar->fw_len;
979 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
980 filename = AR6003_REV1_FIRMWARE_FILE;
981 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
982 filename = AR6003_REV2_FIRMWARE_FILE;
983 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
984 filename = AR6003_REV3_FIRMWARE_FILE;
986 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
992 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
993 filename = AR6003_REV1_EPPING_FIRMWARE_FILE;
994 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
995 filename = AR6003_REV2_EPPING_FIRMWARE_FILE;
996 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
997 filename = AR6003_REV3_EPPING_FIRMWARE_FILE;
999 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n",
1000 ar->arVersion.target_ver));
1006 #ifdef CONFIG_HOST_TCMD_SUPPORT
1008 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1009 filename = AR6003_REV1_TCMD_FIRMWARE_FILE;
1010 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1011 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
1012 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
1013 filename = AR6003_REV3_TCMD_FIRMWARE_FILE;
1015 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1021 #ifdef HTC_RAW_INTERFACE
1022 if (!eppingtest && bypasswmi) {
1023 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1024 filename = AR6003_REV1_ART_FIRMWARE_FILE;
1025 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1026 filename = AR6003_REV2_ART_FIRMWARE_FILE;
1028 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1036 case AR6K_PATCH_FILE:
1037 buf = &ar->fw_patch;
1038 buf_len = &ar->fw_patch_len;
1039 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1040 filename = AR6003_REV1_PATCH_FILE;
1041 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1042 filename = AR6003_REV2_PATCH_FILE;
1043 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
1044 filename = AR6003_REV3_PATCH_FILE;
1046 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1051 case AR6K_BOARD_DATA_FILE:
1053 buf_len = &ar->fw_data_len;
1054 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1055 filename = AR6003_REV1_BOARD_DATA_FILE;
1056 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1057 filename = AR6003_REV2_BOARD_DATA_FILE;
1058 } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) {
1059 filename = AR6003_REV3_BOARD_DATA_FILE;
1061 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1067 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file));
1072 if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) {
1073 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename));
1077 *buf = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
1078 *buf_len = fw_entry->size;
1079 A_RELEASE_FIRMWARE(fw_entry);
1082 #ifdef SOFTMAC_FILE_USED
1083 if (file==AR6K_BOARD_DATA_FILE && *buf_len) {
1084 ar6000_softmac_update(ar, *buf, *buf_len);
1089 fw_entry_size = *buf_len;
1091 /* Load extended board data for AR6003 */
1092 if ((file==AR6K_BOARD_DATA_FILE) && *buf) {
1093 u32 board_ext_address;
1094 u32 board_ext_data_size;
1095 u32 board_data_size;
1097 board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \
1098 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0));
1100 board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \
1101 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0));
1103 /* Determine where in Target RAM to write Board Data */
1104 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (u8 *)&board_ext_address, 4));
1105 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address));
1107 /* check whether the target has allocated memory for extended board data and file contains extended board data */
1108 if ((board_ext_address) && (*buf_len == (board_data_size + board_ext_data_size))) {
1111 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (u8 *)(*buf + board_data_size), board_ext_data_size);
1114 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1118 /* Record the fact that extended board Data IS initialized */
1119 param = (board_ext_data_size << 16) | 1;
1120 bmifn(BMIWriteMemory(ar->arHifDevice,
1121 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_config),
1122 (unsigned char *)¶m, 4));
1124 fw_entry_size = board_data_size;
1128 status = BMIFastDownload(ar->arHifDevice, address, *buf, fw_entry_size);
1130 status = BMIWriteMemory(ar->arHifDevice, address, *buf, fw_entry_size);
1134 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1142 ar6000_update_bdaddr(struct ar6_softc *ar)
1145 if (setupbtdev != 0) {
1148 if (BMIReadMemory(ar->arHifDevice,
1149 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4) != 0)
1151 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n"));
1155 if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (u8 *)ar->bdaddr, 6) != 0)
1157 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n"));
1160 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0],
1161 ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3],
1162 ar->bdaddr[4], ar->bdaddr[5]));
1169 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode)
1171 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n"));
1173 if (mode == WLAN_INIT_MODE_UDEV) {
1175 const struct firmware *fw_entry;
1177 /* Get config using udev through a script in user space */
1178 sprintf(version, "%2.2x", ar->arVersion.target_ver);
1179 if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1181 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version));
1185 A_RELEASE_FIRMWARE(fw_entry);
1187 /* The config is contained within the driver itself */
1189 u32 param, options, sleep, address;
1191 /* Temporarily disable system sleep */
1192 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1193 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1195 param |= AR6K_OPTION_SLEEP_DISABLE;
1196 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1198 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1199 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1201 param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1);
1202 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1203 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep));
1205 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1206 /* Program analog PLL register */
1207 bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001));
1208 /* Run at 80/88MHz by default */
1209 param = CPU_CLOCK_STANDARD_SET(1);
1211 /* Run at 40/44MHz by default */
1212 param = CPU_CLOCK_STANDARD_SET(0);
1214 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1215 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1218 if (ar->arTargetType == TARGET_TYPE_AR6002) {
1219 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1222 /* LPO_CAL.ENABLE = 1 if no external clk is detected */
1224 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1225 param = LPO_CAL_ENABLE_SET(1);
1226 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1229 /* Venus2.0: Lower SDIO pad drive strength,
1230 * temporary WAR to avoid SDIO CRC error */
1231 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1232 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n"));
1234 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1235 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1237 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1238 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1240 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1241 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1243 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1244 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1247 #ifdef FORCE_INTERNAL_CLOCK
1248 /* Ignore external clock, if any, and force use of internal clock */
1249 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1250 /* hi_ext_clk_detected = 0 */
1252 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1254 /* CLOCK_CONTROL &= ~LF_CLK32 */
1255 address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS;
1256 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1257 param &= (~CLOCK_CONTROL_LF_CLK32_SET(1));
1258 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1260 #endif /* FORCE_INTERNAL_CLOCK */
1262 /* Transfer Board Data from Target EEPROM to Target RAM */
1263 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1264 /* Determine where in Target RAM to write Board Data */
1265 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4));
1266 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address));
1268 /* Write EEPROM data to Target RAM */
1269 if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, false)) != 0) {
1273 /* Record the fact that Board Data IS initialized */
1275 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (u8 *)¶m, 4));
1277 /* Transfer One time Programmable data */
1278 AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver);
1279 if (ar->arVersion.target_ver == AR6003_REV3_VERSION)
1281 status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, true);
1283 /* Execute the OTP code */
1285 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1286 bmifn(BMIExecute(ar->arHifDevice, address, ¶m));
1287 } else if (status != A_ENOENT) {
1291 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType));
1295 /* Download Target firmware */
1296 AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver);
1297 if (ar->arVersion.target_ver == AR6003_REV3_VERSION)
1299 if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, true)) != 0) {
1303 /* Set starting address for firmware */
1304 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1305 bmifn(BMISetAppStart(ar->arHifDevice, address));
1307 if(ar->arTargetType == TARGET_TYPE_AR6003) {
1308 AR6K_DATASET_PATCH_ADDRESS(address, ar->arVersion.target_ver);
1309 if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE,
1310 address, false)) != 0)
1313 bmifn(BMIWriteMemory(ar->arHifDevice,
1314 HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head),
1315 (unsigned char *)¶m, 4));
1318 /* Restore system sleep */
1319 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1320 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep));
1322 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1323 param = options | 0x20;
1324 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1326 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1327 /* Configure GPIO AR6003 UART */
1328 #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN
1329 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
1331 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1332 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (u8 *)¶m, 4));
1334 #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23)
1336 address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS;
1337 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1338 param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1);
1339 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1343 /* Configure GPIO for BT Reset */
1344 #ifdef ATH6KL_CONFIG_GPIO_BT_RESET
1345 #define CONFIG_AR600x_BT_RESET_PIN 0x16
1346 param = CONFIG_AR600x_BT_RESET_PIN;
1347 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (u8 *)¶m, 4));
1348 #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */
1350 /* Configure UART flow control polarity */
1351 #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY
1352 #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0
1355 #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1)
1356 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1357 param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2);
1358 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (u8 *)¶m, 4));
1360 #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */
1363 #ifdef HTC_RAW_INTERFACE
1364 if (!eppingtest && bypasswmi) {
1365 /* Don't run BMIDone for ART mode and force resetok=0 */
1369 #endif /* HTC_RAW_INTERFACE */
1376 ar6000_configure_target(struct ar6_softc *ar)
1379 if (enableuartprint) {
1381 if (BMIWriteMemory(ar->arHifDevice,
1382 HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable),
1386 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n"));
1389 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n"));
1392 /* Tell target which HTC version it is used*/
1393 param = HTC_PROTOCOL_VERSION;
1394 if (BMIWriteMemory(ar->arHifDevice,
1395 HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest),
1399 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n"));
1403 #ifdef CONFIG_HOST_TCMD_SUPPORT
1405 ar->arTargetMode = AR6000_TCMD_MODE;
1407 ar->arTargetMode = AR6000_WLAN_MODE;
1410 if (enabletimerwar) {
1413 if (BMIReadMemory(ar->arHifDevice,
1414 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1418 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n"));
1422 param |= HI_OPTION_TIMER_WAR;
1424 if (BMIWriteMemory(ar->arHifDevice,
1425 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1429 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n"));
1432 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n"));
1435 /* set the firmware mode to STA/IBSS/AP */
1439 if (BMIReadMemory(ar->arHifDevice,
1440 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1444 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n"));
1448 param |= (num_device << HI_OPTION_NUM_DEV_SHIFT);
1449 param |= (fwmode << HI_OPTION_FW_MODE_SHIFT);
1450 param |= (mac_addr_method << HI_OPTION_MAC_ADDR_METHOD_SHIFT);
1451 param |= (firmware_bridge << HI_OPTION_FW_BRIDGE_SHIFT);
1454 if (BMIWriteMemory(ar->arHifDevice,
1455 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1459 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n"));
1462 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1465 #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS
1469 if (BMIReadMemory(ar->arHifDevice,
1470 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1474 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n"));
1478 param |= HI_OPTION_DISABLE_DBGLOG;
1480 if (BMIWriteMemory(ar->arHifDevice,
1481 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1485 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n"));
1488 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1490 #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */
1493 * Hardcode the address use for the extended board data
1494 * Ideally this should be pre-allocate by the OS at boot time
1495 * But since it is a new feature and board data is loaded
1496 * at init time, we have to workaround this from host.
1497 * It is difficult to patch the firmware boot code,
1498 * but possible in theory.
1501 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1503 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1504 param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS;
1505 ramReservedSz = AR6003_REV2_RAM_RESERVE_SIZE;
1507 param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS;
1508 ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE;
1510 if (BMIWriteMemory(ar->arHifDevice,
1511 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data),
1512 (u8 *)¶m, 4) != 0) {
1513 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1514 ("BMIWriteMemory for "
1515 "hi_board_ext_data failed\n"));
1518 if (BMIWriteMemory(ar->arHifDevice,
1519 HOST_INTEREST_ITEM_ADDRESS(ar,
1520 hi_end_RAM_reserve_sz),
1521 (u8 *)&ramReservedSz, 4) != 0) {
1522 AR_DEBUG_PRINTF(ATH_DEBUG_ERR ,
1523 ("BMIWriteMemory for "
1524 "hi_end_RAM_reserve_sz failed\n"));
1529 /* since BMIInit is called in the driver layer, we have to set the block
1530 * size here for the target */
1532 if (ar6000_set_htc_params(ar->arHifDevice, ar->arTargetType,
1533 mbox_yield_limit, 0)) {
1534 /* use default number of control buffers */
1538 if (setupbtdev != 0) {
1539 if (ar6000_set_hci_bridge_flags(ar->arHifDevice,
1549 init_netdev(struct net_device *dev, char *name)
1551 dev->netdev_ops = &ar6000_netdev_ops;
1552 dev->watchdog_timeo = AR6000_TX_TIMEOUT;
1555 * We need the OS to provide us with more headroom in order to
1556 * perform dix to 802.3, WMI header encap, and the HTC header
1558 if (processDot11Hdr) {
1559 dev->hard_header_len = sizeof(struct ieee80211_qosframe) + sizeof(ATH_LLC_SNAP_HDR) + sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
1561 dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) +
1562 sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
1567 strcpy(dev->name, name);
1570 #ifdef CONFIG_CHECKSUM_OFFLOAD
1572 dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/
1579 static int __ath6kl_init_netdev(struct net_device *dev)
1584 r = ar6000_init(dev);
1588 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n"));
1595 #ifdef HTC_RAW_INTERFACE
1596 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1598 if (!eppingtest && bypasswmi)
1601 return __ath6kl_init_netdev(dev);
1604 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1606 return __ath6kl_init_netdev(dev);
1610 static int ath6kl_init_netdev(struct ar6_softc *ar)
1614 r = ar6000_sysfs_bmi_get_config(ar, wlaninitmode);
1616 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1618 "ar6000_sysfs_bmi_get_config failed\n"));
1622 return ath6kl_init_netdev_wmi(ar->arNetDev);
1626 * HTC Event handlers
1629 ar6000_avail_ev(void *context, void *hif_handle)
1632 struct net_device *dev;
1634 struct ar6_softc *ar;
1635 int device_index = 0;
1636 struct htc_init_info htcInfo;
1637 struct wireless_dev *wdev;
1639 struct hif_device_os_device_info osDevInfo;
1641 memset(&osDevInfo, 0, sizeof(osDevInfo));
1642 if (HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE,
1643 &osDevInfo, sizeof(osDevInfo))) {
1644 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Failed to get OS device instance\n", __func__));
1648 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n"));
1650 for (i=0; i < MAX_AR6000; i++) {
1651 if (ar6000_devices[i] == NULL) {
1656 if (i == MAX_AR6000) {
1657 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n"));
1661 /* Save this. It gives a bit better readability especially since */
1662 /* we use another local "i" variable below. */
1665 wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice);
1667 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__));
1670 ar_netif = wdev_priv(wdev);
1672 if (ar_netif == NULL) {
1673 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__));
1677 A_MEMZERO(ar_netif, sizeof(struct ar6_softc));
1678 ar = (struct ar6_softc *)ar_netif;
1681 wdev->iftype = NL80211_IFTYPE_STATION;
1683 dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1);
1685 printk(KERN_CRIT "AR6K: no memory for network device instance\n");
1686 ar6k_cfg80211_deinit(ar);
1690 dev->ieee80211_ptr = wdev;
1691 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1693 ar->arNetworkType = INFRA_NETWORK;
1694 ar->smeState = SME_DISCONNECTED;
1695 ar->arAutoAuthStage = AUTH_IDLE;
1697 init_netdev(dev, ifname);
1701 ar->arHifDevice = hif_handle;
1702 ar->arWlanState = WLAN_ENABLED;
1703 ar->arDeviceIndex = device_index;
1705 ar->arWlanPowerState = WLAN_POWER_STATE_ON;
1706 ar->arWlanOff = false; /* We are in ON state */
1708 ar->arWowState = WLAN_WOW_STATE_NONE;
1709 ar->arBTOff = true; /* BT chip assumed to be OFF */
1710 ar->arBTSharing = WLAN_CONFIG_BT_SHARING;
1711 ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF;
1712 ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND;
1713 ar->arWow2Config = WLAN_CONFIG_PM_WOW2;
1714 #endif /* CONFIG_PM */
1716 A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev);
1717 ar->arHBChallengeResp.seqNum = 0;
1718 ar->arHBChallengeResp.outstanding = false;
1719 ar->arHBChallengeResp.missCnt = 0;
1720 ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT;
1721 ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT;
1723 ar6000_init_control_info(ar);
1724 init_waitqueue_head(&arEvent);
1725 sema_init(&ar->arSem, 1);
1726 ar->bIsDestroyProgress = false;
1728 INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue);
1730 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
1731 A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar);
1732 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
1734 A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev);
1738 ar6000_sysfs_bmi_init(ar);
1741 struct bmi_target_info targ_info;
1743 r = BMIGetTargetInfo(ar->arHifDevice, &targ_info);
1745 goto avail_ev_failed;
1747 ar->arVersion.target_ver = targ_info.target_ver;
1748 ar->arTargetType = targ_info.target_type;
1749 wdev->wiphy->hw_version = targ_info.target_ver;
1752 r = ar6000_configure_target(ar);
1754 goto avail_ev_failed;
1756 A_MEMZERO(&htcInfo,sizeof(htcInfo));
1757 htcInfo.pContext = ar;
1758 htcInfo.TargetFailure = ar6000_target_failure;
1760 ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo);
1762 if (!ar->arHtcTarget) {
1764 goto avail_ev_failed;
1767 spin_lock_init(&ar->arLock);
1770 ar->arWapiEnable = 0;
1775 /*if external frame work is also needed, change and use an extended rxMetaVerion*/
1776 ar->rxMetaVersion=WMI_META_VERSION_2;
1779 ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs);
1780 if (!ar->aggr_cntxt) {
1781 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__));
1783 goto avail_ev_failed;
1786 aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack);
1788 HIFClaimDevice(ar->arHifDevice, ar);
1790 /* We only register the device in the global list if we succeed. */
1791 /* If the device is in the global list, it will be destroyed */
1792 /* when the module is unloaded. */
1793 ar6000_devices[device_index] = dev;
1795 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode));
1796 if ((wlaninitmode == WLAN_INIT_MODE_UDEV) ||
1797 (wlaninitmode == WLAN_INIT_MODE_DRV)) {
1798 r = ath6kl_init_netdev(ar);
1800 goto avail_ev_failed;
1803 /* This runs the init function if registered */
1804 r = register_netdev(dev);
1806 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n"));
1807 ar6000_destroy(dev, 0);
1811 is_netdev_registered = 1;
1813 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
1815 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
1816 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n",
1817 dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index,
1818 (unsigned long)ar));
1822 ar6000_sysfs_bmi_deinit(ar);
1827 static void ar6000_target_failure(void *Instance, int Status)
1829 struct ar6_softc *ar = (struct ar6_softc *)Instance;
1830 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
1831 static bool sip = false;
1835 printk(KERN_ERR "ar6000_target_failure: target asserted \n");
1837 if (timer_pending(&ar->arHBChallengeResp.timer)) {
1838 A_UNTIMEOUT(&ar->arHBChallengeResp.timer);
1841 /* try dumping target assertion information (if any) */
1842 ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType);
1845 * Fetch the logs from the target via the diagnostic
1848 ar6000_dbglog_get_debug_logs(ar);
1850 /* Report the error only once */
1853 errEvent.errorVal = WMI_TARGET_COM_ERR |
1854 WMI_TARGET_FATAL_ERR;
1860 ar6000_unavail_ev(void *context, void *hif_handle)
1862 struct ar6_softc *ar = (struct ar6_softc *)context;
1863 /* NULL out it's entry in the global list */
1864 ar6000_devices[ar->arDeviceIndex] = NULL;
1865 ar6000_destroy(ar->arNetDev, 1);
1871 ar6000_restart_endpoint(struct net_device *dev)
1874 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1878 if ( (status=ar6000_configure_target(ar))!= 0)
1880 if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != 0)
1882 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
1886 status = (ar6000_init(dev)==0) ? 0 : A_ERROR;
1892 if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) {
1893 ar6000_connect_to_ap(ar);
1901 ar6000_devices[ar->arDeviceIndex] = NULL;
1902 ar6000_destroy(ar->arNetDev, 1);
1906 ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs)
1908 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1910 /* Stop the transmit queues */
1911 netif_stop_queue(dev);
1913 /* Disable the target and the interrupts associated with it */
1914 if (ar->arWmiReady == true)
1918 bool disconnectIssued;
1920 disconnectIssued = (ar->arConnected) || (ar->arConnectPending);
1921 ar6000_disconnect(ar);
1923 ar6000_init_profile_info(ar);
1926 A_UNTIMEOUT(&ar->disconnect_timer);
1929 ar6000_dbglog_get_debug_logs(ar);
1932 ar->arWmiReady = false;
1933 wmi_shutdown(ar->arWmi);
1934 ar->arWmiEnabled = false;
1937 * After wmi_shudown all WMI events will be dropped.
1938 * We need to cleanup the buffers allocated in AP mode
1939 * and give disconnect notification to stack, which usually
1940 * happens in the disconnect_event.
1941 * Simulate the disconnect_event by calling the function directly.
1942 * Sometimes disconnect_event will be received when the debug logs
1945 if (disconnectIssued) {
1946 if(ar->arNetworkType & AP_NETWORK) {
1947 ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0);
1949 ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0);
1952 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
1953 ar->user_key_ctrl = 0;
1956 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__));
1960 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n",
1961 __func__, (unsigned long) ar, (unsigned long) ar->arWmi));
1963 /* Shut down WMI if we have started it */
1964 if(ar->arWmiEnabled == true)
1966 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__));
1967 wmi_shutdown(ar->arWmi);
1968 ar->arWmiEnabled = false;
1973 if (ar->arHtcTarget != NULL) {
1974 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
1975 if (NULL != ar6kHciTransCallbacks.cleanupTransport) {
1976 ar6kHciTransCallbacks.cleanupTransport(NULL);
1979 // FIXME: workaround to reset BT's UART baud rate to default
1980 if (NULL != ar->exitCallback) {
1981 struct ar3k_config_info ar3kconfig;
1984 A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig));
1985 ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig);
1986 status = ar->exitCallback(&ar3kconfig);
1988 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n"));
1993 ar6000_cleanup_hci(ar);
1995 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n"));
1997 HTCStop(ar->arHtcTarget);
2001 /* try to reset the device if we can
2002 * The driver may have been configure NOT to reset the target during
2003 * a debug session */
2004 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Attempting to reset target on instance destroy.... \n"));
2005 if (ar->arHifDevice != NULL) {
2006 bool coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? true: false;
2007 ar6000_reset_device(ar->arHifDevice, ar->arTargetType, true, coldReset);
2010 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n"));
2012 /* Done with cookies */
2013 ar6000_cookie_cleanup(ar);
2015 /* cleanup any allocated AMSDU buffers */
2016 ar6000_cleanup_amsdu_rxbufs(ar);
2019 * We need to differentiate between the surprise and planned removal of the
2020 * device because of the following consideration:
2021 * - In case of surprise removal, the hcd already frees up the pending
2022 * for the device and hence there is no need to unregister the function
2023 * driver inorder to get these requests. For planned removal, the function
2024 * driver has to explicitly unregister itself to have the hcd return all the
2025 * pending requests before the data structures for the devices are freed up.
2026 * Note that as per the current implementation, the function driver will
2027 * end up releasing all the devices since there is no API to selectively
2028 * release a particular device.
2029 * - Certain commands issued to the target can be skipped for surprise
2030 * removal since they will anyway not go through.
2033 ar6000_destroy(struct net_device *dev, unsigned int unregister)
2035 struct ar6_softc *ar;
2037 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n"));
2039 if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL))
2041 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__));
2045 ar->bIsDestroyProgress = true;
2047 if (down_interruptible(&ar->arSem)) {
2048 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__));
2052 if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) {
2053 /* only stop endpoint if we are not stop it in suspend_ev */
2054 ar6000_stop_endpoint(dev, false, true);
2057 ar->arWlanState = WLAN_DISABLED;
2058 if (ar->arHtcTarget != NULL) {
2060 HTCDestroy(ar->arHtcTarget);
2062 if (ar->arHifDevice != NULL) {
2063 /*release the device so we do not get called back on remove incase we
2064 * we're explicity destroyed by module unload */
2065 HIFReleaseDevice(ar->arHifDevice);
2066 HIFShutDownDevice(ar->arHifDevice);
2068 aggr_module_destroy(ar->aggr_cntxt);
2070 /* Done with cookies */
2071 ar6000_cookie_cleanup(ar);
2073 /* cleanup any allocated AMSDU buffers */
2074 ar6000_cleanup_amsdu_rxbufs(ar);
2076 ar6000_sysfs_bmi_deinit(ar);
2081 /* Clear the tx counters */
2082 memset(tx_attempt, 0, sizeof(tx_attempt));
2083 memset(tx_post, 0, sizeof(tx_post));
2084 memset(tx_complete, 0, sizeof(tx_complete));
2086 #ifdef HTC_RAW_INTERFACE
2088 kfree(ar->arRawHtc);
2089 ar->arRawHtc = NULL;
2092 /* Free up the device data structure */
2093 if (unregister && is_netdev_registered) {
2094 unregister_netdev(dev);
2095 is_netdev_registered = 0;
2099 ar6k_cfg80211_deinit(ar);
2101 #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT
2102 ar6000_remove_ap_interface();
2103 #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
2107 kfree(ar->fw_patch);
2110 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n"));
2113 static void disconnect_timer_handler(unsigned long ptr)
2115 struct net_device *dev = (struct net_device *)ptr;
2116 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2118 A_UNTIMEOUT(&ar->disconnect_timer);
2120 ar6000_init_profile_info(ar);
2121 ar6000_disconnect(ar);
2124 static void ar6000_detect_error(unsigned long ptr)
2126 struct net_device *dev = (struct net_device *)ptr;
2127 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2128 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
2130 AR6000_SPIN_LOCK(&ar->arLock, 0);
2132 if (ar->arHBChallengeResp.outstanding) {
2133 ar->arHBChallengeResp.missCnt++;
2135 ar->arHBChallengeResp.missCnt = 0;
2138 if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) {
2139 /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */
2140 ar->arHBChallengeResp.missCnt = 0;
2141 ar->arHBChallengeResp.seqNum = 0;
2142 errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR;
2143 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2147 /* Generate the sequence number for the next challenge */
2148 ar->arHBChallengeResp.seqNum++;
2149 ar->arHBChallengeResp.outstanding = true;
2151 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2153 /* Send the challenge on the control channel */
2154 if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != 0) {
2155 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n"));
2159 /* Reschedule the timer for the next challenge */
2160 A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0);
2163 void ar6000_init_profile_info(struct ar6_softc *ar)
2166 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
2169 case HI_OPTION_FW_MODE_IBSS:
2170 ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK;
2172 case HI_OPTION_FW_MODE_BSS_STA:
2173 ar->arNetworkType = ar->arNextMode = INFRA_NETWORK;
2175 case HI_OPTION_FW_MODE_AP:
2176 ar->arNetworkType = ar->arNextMode = AP_NETWORK;
2180 ar->arDot11AuthMode = OPEN_AUTH;
2181 ar->arAuthMode = NONE_AUTH;
2182 ar->arPairwiseCrypto = NONE_CRYPT;
2183 ar->arPairwiseCryptoLen = 0;
2184 ar->arGroupCrypto = NONE_CRYPT;
2185 ar->arGroupCryptoLen = 0;
2186 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2187 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
2188 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
2189 ar->arBssChannel = 0;
2193 ar6000_init_control_info(struct ar6_softc *ar)
2195 ar->arWmiEnabled = false;
2196 ar6000_init_profile_info(ar);
2197 ar->arDefTxKeyIndex = 0;
2198 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2199 ar->arChannelHint = 0;
2200 ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL;
2201 ar->arListenIntervalB = 0;
2202 ar->arVersion.host_ver = AR6K_SW_VERSION;
2205 ar->arTxPwrSet = false;
2207 ar->arBeaconInterval = 0;
2209 ar->arMaxRetries = 0;
2210 ar->arWmmEnabled = true;
2212 ar->scan_triggered = 0;
2213 A_MEMZERO(&ar->scParams, sizeof(ar->scParams));
2214 ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT;
2215 ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS;
2217 /* Initialize the AP mode state info */
2220 A_MEMZERO((u8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t));
2222 /* init the Mutexes */
2223 A_MUTEX_INIT(&ar->mcastpsqLock);
2225 /* Init the PS queues */
2226 for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) {
2227 A_MUTEX_INIT(&ar->sta_list[ctr].psqLock);
2228 A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq);
2231 ar->ap_profile_flag = 0;
2232 A_NETBUF_QUEUE_INIT(&ar->mcastpsq);
2234 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
2235 ar->ap_wmode = DEF_AP_WMODE_G;
2236 ar->ap_dtim_period = DEF_AP_DTIM;
2237 ar->ap_beacon_interval = DEF_BEACON_INTERVAL;
2242 ar6000_open(struct net_device *dev)
2244 unsigned long flags;
2245 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2247 spin_lock_irqsave(&ar->arLock, flags);
2249 if(ar->arWlanState == WLAN_DISABLED) {
2250 ar->arWlanState = WLAN_ENABLED;
2253 if( ar->arConnected || bypasswmi) {
2254 netif_carrier_on(dev);
2255 /* Wake up the queues */
2256 netif_wake_queue(dev);
2259 netif_carrier_off(dev);
2261 spin_unlock_irqrestore(&ar->arLock, flags);
2266 ar6000_close(struct net_device *dev)
2268 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2269 netif_stop_queue(dev);
2271 ar6000_disconnect(ar);
2273 if(ar->arWmiReady == true) {
2274 if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0,
2275 0, 0, 0, 0, 0, 0, 0, 0) != 0) {
2278 ar->arWlanState = WLAN_DISABLED;
2280 ar6k_cfg80211_scanComplete_event(ar, A_ECANCELED);
2285 /* connect to a service */
2286 static int ar6000_connectservice(struct ar6_softc *ar,
2287 struct htc_service_connect_req *pConnect,
2291 struct htc_service_connect_resp response;
2295 A_MEMZERO(&response,sizeof(response));
2297 status = HTCConnectService(ar->arHtcTarget,
2302 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n",
2306 switch (pConnect->ServiceID) {
2307 case WMI_CONTROL_SVC :
2308 if (ar->arWmiEnabled) {
2309 /* set control endpoint for WMI use */
2310 wmi_set_control_ep(ar->arWmi, response.Endpoint);
2312 /* save EP for fast lookup */
2313 ar->arControlEp = response.Endpoint;
2315 case WMI_DATA_BE_SVC :
2316 arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint);
2318 case WMI_DATA_BK_SVC :
2319 arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint);
2321 case WMI_DATA_VI_SVC :
2322 arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint);
2324 case WMI_DATA_VO_SVC :
2325 arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint);
2328 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID));
2338 void ar6000_TxDataCleanup(struct ar6_softc *ar)
2340 /* flush all the data (non-control) streams
2341 * we only flush packets that are tagged as data, we leave any control packets that
2342 * were in the TX queues alone */
2343 HTCFlushEndpoint(ar->arHtcTarget,
2344 arAc2EndpointID(ar, WMM_AC_BE),
2346 HTCFlushEndpoint(ar->arHtcTarget,
2347 arAc2EndpointID(ar, WMM_AC_BK),
2349 HTCFlushEndpoint(ar->arHtcTarget,
2350 arAc2EndpointID(ar, WMM_AC_VI),
2352 HTCFlushEndpoint(ar->arHtcTarget,
2353 arAc2EndpointID(ar, WMM_AC_VO),
2358 ar6000_ac2_endpoint_id ( void * devt, u8 ac)
2360 struct ar6_softc *ar = (struct ar6_softc *) devt;
2361 return(arAc2EndpointID(ar, ac));
2364 u8 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep )
2366 struct ar6_softc *ar = (struct ar6_softc *) devt;
2367 return(arEndpoint2Ac(ar, ep ));
2370 #if defined(CONFIG_ATH6KL_ENABLE_COEXISTENCE)
2371 static int ath6kl_config_btcoex_params(struct ar6_softc *ar)
2374 WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd;
2375 WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd;
2377 /* Configure the type of BT collocated with WLAN */
2378 memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD));
2379 sbcb_cmd.btcoexCoLocatedBTdev = ATH6KL_BT_DEV;
2381 r = wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd);
2384 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
2385 ("Unable to set collocated BT type\n"));
2389 /* Configure the type of BT collocated with WLAN */
2390 memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD));
2392 sbfa_cmd.btcoexFeAntType = ATH6KL_BT_ANTENNA;
2394 r = wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd);
2396 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
2397 ("Unable to set fornt end antenna configuration\n"));
2404 static int ath6kl_config_btcoex_params(struct ar6_softc *ar)
2408 #endif /* CONFIG_ATH6KL_ENABLE_COEXISTENCE */
2411 * This function applies WLAN specific configuration defined in wlan_config.h
2413 int ar6000_target_config_wlan_params(struct ar6_softc *ar)
2417 #ifdef CONFIG_HOST_TCMD_SUPPORT
2418 if (ar->arTargetMode != AR6000_WLAN_MODE) {
2421 #endif /* CONFIG_HOST_TCMD_SUPPORT */
2424 * configure the device for rx dot11 header rules 0,0 are the default values
2425 * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required
2426 * if checksum offload is needed. Set RxMetaVersion to 2
2428 if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != 0) {
2429 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n"));
2433 status = ath6kl_config_btcoex_params(ar);
2437 #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
2438 if ((wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
2439 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power save fail event policy\n"));
2444 #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP
2445 if ((wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
2446 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set barker preamble policy\n"));
2451 if ((wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) != 0) {
2452 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set keep alive interval\n"));
2456 #if WLAN_CONFIG_DISABLE_11N
2458 WMI_SET_HT_CAP_CMD htCap;
2460 memset(&htCap, 0, sizeof(WMI_SET_HT_CAP_CMD));
2462 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2463 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2468 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2469 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2473 #endif /* WLAN_CONFIG_DISABLE_11N */
2475 #ifdef ATH6K_CONFIG_OTA_MODE
2476 if ((wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER)) != 0) {
2477 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power mode \n"));
2482 if ((wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT)) != 0) {
2483 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set disconnect timeout \n"));
2487 #if WLAN_CONFIG_DISABLE_TX_BURSTING
2488 if ((wmi_set_wmm_txop(ar->arWmi, WMI_TXOP_DISABLED)) != 0) {
2489 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set txop bursting \n"));
2497 /* This function does one time initialization for the lifetime of the device */
2498 int ar6000_init(struct net_device *dev)
2500 struct ar6_softc *ar;
2506 if((ar = ar6k_priv(dev)) == NULL)
2511 if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) {
2513 ar6000_update_bdaddr(ar);
2515 if (enablerssicompensation) {
2516 ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType);
2517 read_rssi_compensation_param(ar);
2518 for (i=-95; i<=0; i++) {
2519 rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i);
2527 /* Do we need to finish the BMI phase */
2528 if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) &&
2529 (BMIDone(ar->arHifDevice) != 0))
2532 goto ar6000_init_done;
2538 if (ar->arVersion.host_ver != ar->arVersion.target_ver) {
2539 A_PRINTF("WARNING: Host version 0x%x does not match Target "
2541 ar->arVersion.host_ver, ar->arVersion.target_ver);
2545 /* Indicate that WMI is enabled (although not ready yet) */
2546 ar->arWmiEnabled = true;
2547 if ((ar->arWmi = wmi_init((void *) ar)) == NULL)
2549 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__));
2551 goto ar6000_init_done;
2554 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__,
2555 (unsigned long) ar->arWmi));
2559 struct htc_service_connect_req connect;
2561 /* the reason we have to wait for the target here is that the driver layer
2562 * has to init BMI in order to set the host block size,
2564 status = HTCWaitTarget(ar->arHtcTarget);
2570 A_MEMZERO(&connect,sizeof(connect));
2571 /* meta data is unused for now */
2572 connect.pMetaData = NULL;
2573 connect.MetaDataLength = 0;
2574 /* these fields are the same for all service endpoints */
2575 connect.EpCallbacks.pContext = ar;
2576 connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete;
2577 connect.EpCallbacks.EpRecv = ar6000_rx;
2578 connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill;
2579 connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full;
2580 /* set the max queue depth so that our ar6000_tx_queue_full handler gets called.
2581 * Linux has the peculiarity of not providing flow control between the
2582 * NIC and the network stack. There is no API to indicate that a TX packet
2583 * was sent which could provide some back pressure to the network stack.
2584 * Under linux you would have to wait till the network stack consumed all sk_buffs
2585 * before any back-flow kicked in. Which isn't very friendly.
2586 * So we have to manage this ourselves */
2587 connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
2588 connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */
2589 if (0 == connect.EpCallbacks.RecvRefillWaterMark) {
2590 connect.EpCallbacks.RecvRefillWaterMark++;
2592 /* connect to control service */
2593 connect.ServiceID = WMI_CONTROL_SVC;
2594 status = ar6000_connectservice(ar,
2601 connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING;
2602 /* limit the HTC message size on the send path, although we can receive A-MSDU frames of
2603 * 4K, we will only send ethernet-sized (802.3) frames on the send path. */
2604 connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH;
2606 /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold
2607 * mechanism for larger packets */
2608 connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE;
2609 connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf;
2611 /* for the remaining data services set the connection flag to reduce dribbling,
2612 * if configured to do so */
2613 if (reduce_credit_dribble) {
2614 connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE;
2615 /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value
2617 connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2618 connect.ConnectionFlags |=
2619 ((u16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2621 /* connect to best-effort service */
2622 connect.ServiceID = WMI_DATA_BE_SVC;
2624 status = ar6000_connectservice(ar,
2631 /* connect to back-ground
2632 * map this to WMI LOW_PRI */
2633 connect.ServiceID = WMI_DATA_BK_SVC;
2634 status = ar6000_connectservice(ar,
2641 /* connect to Video service, map this to
2643 connect.ServiceID = WMI_DATA_VI_SVC;
2644 status = ar6000_connectservice(ar,
2651 /* connect to VO service, this is currently not
2652 * mapped to a WMI priority stream due to historical reasons.
2653 * WMI originally defined 3 priorities over 3 mailboxes
2654 * We can change this when WMI is reworked so that priorities are not
2655 * dependent on mailboxes */
2656 connect.ServiceID = WMI_DATA_VO_SVC;
2657 status = ar6000_connectservice(ar,
2664 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0);
2665 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0);
2666 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0);
2667 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0);
2669 /* setup access class priority mappings */
2670 ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */
2671 ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */
2672 ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */
2673 ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */
2675 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2676 if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) {
2677 struct hci_transport_misc_handles hciHandles;
2679 hciHandles.netDevice = ar->arNetDev;
2680 hciHandles.hifDevice = ar->arHifDevice;
2681 hciHandles.htcHandle = ar->arHtcTarget;
2682 status = (int)(ar6kHciTransCallbacks.setupTransport(&hciHandles));
2687 status = ar6000_setup_hci(ar);
2695 goto ar6000_init_done;
2701 if (BMIReadMemory(ar->arHifDevice,
2702 HOST_INTEREST_ITEM_ADDRESS(ar,
2706 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
2707 ("BMIReadMemory forsetting "
2708 "regscanmode failed\n"));
2712 if (regscanmode == 1)
2713 param |= HI_OPTION_SKIP_REG_SCAN;
2714 else if (regscanmode == 2)
2715 param |= HI_OPTION_INIT_REG_SCAN;
2717 if (BMIWriteMemory(ar->arHifDevice,
2718 HOST_INTEREST_ITEM_ADDRESS(ar,
2722 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
2723 ("BMIWriteMemory forsetting "
2724 "regscanmode failed\n"));
2727 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Regulatory scan mode set\n"));
2731 * give our connected endpoints some buffers
2734 ar6000_rx_refill(ar, ar->arControlEp);
2735 ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE));
2738 * We will post the receive buffers only for SPE or endpoint ping testing so we are
2739 * making it conditional on the 'bypasswmi' flag.
2742 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK));
2743 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI));
2744 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO));
2747 /* allocate some buffers that handle larger AMSDU frames */
2748 ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS);
2750 /* setup credit distribution */
2751 ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo);
2753 /* Since cookies are used for HTC transports, they should be */
2754 /* initialized prior to enabling HTC. */
2755 ar6000_cookie_init(ar);
2758 status = HTCStart(ar->arHtcTarget);
2761 if (ar->arWmiEnabled == true) {
2762 wmi_shutdown(ar->arWmi);
2763 ar->arWmiEnabled = false;
2766 ar6000_cookie_cleanup(ar);
2768 goto ar6000_init_done;
2772 /* Wait for Wmi event to be ready */
2773 timeleft = wait_event_interruptible_timeout(arEvent,
2774 (ar->arWmiReady == true), wmitimeout * HZ);
2776 if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) {
2777 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver));
2778 #ifndef ATH6K_SKIP_ABI_VERSION_CHECK
2780 goto ar6000_init_done;
2781 #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */
2784 if(!timeleft || signal_pending(current))
2786 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n"));
2788 goto ar6000_init_done;
2791 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__));
2793 /* Communicate the wmi protocol verision to the target */
2794 if ((ar6000_set_host_app_area(ar)) != 0) {
2795 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n"));
2797 ar6000_target_config_wlan_params(ar);
2800 ar->arNumDataEndPts = 1;
2803 /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise
2804 * the data path through a raw socket is disabled */
2805 dev->dev_addr[0] = 0x00;
2806 dev->dev_addr[1] = 0x01;
2807 dev->dev_addr[2] = 0x02;
2808 dev->dev_addr[3] = 0xAA;
2809 dev->dev_addr[4] = 0xBB;
2810 dev->dev_addr[5] = 0xCC;
2822 ar6000_bitrate_rx(void *devt, s32 rateKbps)
2824 struct ar6_softc *ar = (struct ar6_softc *)devt;
2826 ar->arBitRate = rateKbps;
2831 ar6000_ratemask_rx(void *devt, u32 ratemask)
2833 struct ar6_softc *ar = (struct ar6_softc *)devt;
2835 ar->arRateMask = ratemask;
2840 ar6000_txPwr_rx(void *devt, u8 txPwr)
2842 struct ar6_softc *ar = (struct ar6_softc *)devt;
2844 ar->arTxPwr = txPwr;
2850 ar6000_channelList_rx(void *devt, s8 numChan, u16 *chanList)
2852 struct ar6_softc *ar = (struct ar6_softc *)devt;
2854 memcpy(ar->arChannelList, chanList, numChan * sizeof (u16));
2855 ar->arNumChannels = numChan;
2860 u8 ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, u32 *mapNo)
2862 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2864 ATH_MAC_HDR *macHdr;
2868 datap = A_NETBUF_DATA(skb);
2869 macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR));
2870 if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) {
2875 for (i = 0; i < ar->arNodeNum; i ++) {
2876 if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) {
2878 ar->arNodeMap[i].txPending ++;
2879 return ar->arNodeMap[i].epId;
2882 if ((eptMap == -1) && !ar->arNodeMap[i].txPending) {
2888 eptMap = ar->arNodeNum;
2890 A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM);
2893 memcpy(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN);
2895 for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) {
2896 if (!ar->arTxPending[i]) {
2897 ar->arNodeMap[eptMap].epId = i;
2900 // No free endpoint is available, start redistribution on the inuse endpoints.
2901 if (i == ENDPOINT_5) {
2902 ar->arNodeMap[eptMap].epId = ar->arNexEpId;
2904 if (ar->arNexEpId > ENDPOINT_5) {
2905 ar->arNexEpId = ENDPOINT_2;
2910 (*mapNo) = eptMap + 1;
2911 ar->arNodeMap[eptMap].txPending ++;
2913 return ar->arNodeMap[eptMap].epId;
2917 static void ar6000_dump_skb(struct sk_buff *skb)
2920 for (ch = A_NETBUF_DATA(skb);
2921 (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) +
2922 A_NETBUF_LEN(skb)); ch++)
2924 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch));
2926 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n"));
2930 #ifdef HTC_TEST_SEND_PKTS
2931 static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb);
2935 ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
2937 #define AC_NOT_MAPPED 99
2938 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2939 u8 ac = AC_NOT_MAPPED;
2940 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
2943 struct ar_cookie *cookie;
2944 bool checkAdHocPsMapping = false,bMoreData = false;
2945 HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG;
2946 u8 dot11Hdr = processDot11Hdr;
2948 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
2952 #endif /* CONFIG_PM */
2954 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n",
2955 (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb),
2956 A_NETBUF_LEN(skb)));
2958 /* If target is not associated */
2959 if( (!ar->arConnected && !bypasswmi)
2960 #ifdef CONFIG_HOST_TCMD_SUPPORT
2961 /* TCMD doesn't support any data, free the buf and return */
2962 || (ar->arTargetMode == AR6000_TCMD_MODE)
2971 if (ar->arWmiReady == false && bypasswmi == 0) {
2975 #ifdef BLOCK_TX_PATH_FLAG
2979 #endif /* BLOCK_TX_PATH_FLAG */
2981 /* AP mode Power save processing */
2982 /* If the dst STA is in sleep state, queue the pkt in its PS queue */
2984 if (ar->arNetworkType == AP_NETWORK) {
2985 ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
2988 /* If the dstMac is a Multicast address & atleast one of the
2989 * associated STA is in PS mode, then queue the pkt to the
2992 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
2997 for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) {
2998 if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) {
3004 /* If this transmit is not because of a Dtim Expiry q it */
3005 if (ar->DTIMExpired == false) {
3006 bool isMcastqEmpty = false;
3008 A_MUTEX_LOCK(&ar->mcastpsqLock);
3009 isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
3010 A_NETBUF_ENQUEUE(&ar->mcastpsq, skb);
3011 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
3013 /* If this is the first Mcast pkt getting queued
3014 * indicate to the target to set the BitmapControl LSB
3017 if (isMcastqEmpty) {
3018 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1);
3022 /* This transmit is because of Dtim expiry. Determine if
3023 * MoreData bit has to be set.
3025 A_MUTEX_LOCK(&ar->mcastpsqLock);
3026 if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
3029 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
3033 conn = ieee80211_find_conn(ar, datap->dstMac);
3035 if (STA_IS_PWR_SLEEP(conn)) {
3036 /* If this transmit is not because of a PsPoll q it*/
3037 if (!STA_IS_PS_POLLED(conn)) {
3038 bool isPsqEmpty = false;
3039 /* Queue the frames if the STA is sleeping */
3040 A_MUTEX_LOCK(&conn->psqLock);
3041 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
3042 A_NETBUF_ENQUEUE(&conn->psq, skb);
3043 A_MUTEX_UNLOCK(&conn->psqLock);
3045 /* If this is the first pkt getting queued
3046 * for this STA, update the PVB for this STA
3049 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1);
3054 /* This tx is because of a PsPoll. Determine if
3055 * MoreData bit has to be set
3057 A_MUTEX_LOCK(&conn->psqLock);
3058 if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3061 A_MUTEX_UNLOCK(&conn->psqLock);
3066 /* non existent STA. drop the frame */
3073 if (ar->arWmiEnabled) {
3076 u8 csum=skb->ip_summed;
3077 if(csumOffload && (csum==CHECKSUM_PARTIAL)){
3078 csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
3079 sizeof(ATH_LLC_SNAP_HDR));
3080 csumDest=skb->csum_offset+csumStart;
3082 if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) {
3083 struct sk_buff *newbuf;
3086 * We really should have gotten enough headroom but sometimes
3087 * we still get packets with not enough headroom. Copy the packet.
3089 len = A_NETBUF_LEN(skb);
3090 newbuf = A_NETBUF_ALLOC(len);
3091 if (newbuf == NULL) {
3094 A_NETBUF_PUT(newbuf, len);
3095 memcpy(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len);
3098 /* fall through and assemble header */
3102 if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != 0) {
3103 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n"));
3107 if (wmi_dix_2_dot3(ar->arWmi, skb) != 0) {
3108 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n"));
3112 if(csumOffload && (csum ==CHECKSUM_PARTIAL)){
3113 WMI_TX_META_V2 metaV2;
3114 metaV2.csumStart =csumStart;
3115 metaV2.csumDest = csumDest;
3116 metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/
3117 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,
3118 WMI_META_VERSION_2,&metaV2) != 0) {
3119 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3126 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != 0) {
3127 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3133 if ((ar->arNetworkType == ADHOC_NETWORK) &&
3134 ar->arIbssPsEnable && ar->arConnected) {
3135 /* flag to check adhoc mapping once we take the lock below: */
3136 checkAdHocPsMapping = true;
3139 /* get the stream mapping */
3140 ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled);
3144 EPPING_HEADER *eppingHdr;
3146 eppingHdr = A_NETBUF_DATA(skb);
3148 if (IS_EPPING_PACKET(eppingHdr)) {
3149 /* the stream ID is mapped to an access class */
3150 ac = eppingHdr->StreamNo_h;
3151 /* some EPPING packets cannot be dropped no matter what access class it was
3152 * sent on. We can change the packet tag to guarantee it will not get dropped */
3153 if (IS_EPING_PACKET_NO_DROP(eppingHdr)) {
3154 htc_tag = AR6K_CONTROL_PKT_TAG;
3157 if (ac == HCI_TRANSPORT_STREAM_NUM) {
3158 /* pass this to HCI */
3159 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
3160 if (!hci_test_send(ar,skb)) {
3164 /* set AC to discard this skb */
3167 /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition
3168 * of the HTC header will mis-align the start of the HTC frame, so we add some
3169 * padding which will be stripped off in the target */
3170 if (EPPING_ALIGNMENT_PAD > 0) {
3171 A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD);
3176 /* not a ping packet, drop it */
3183 /* did we succeed ? */
3184 if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) {
3185 /* cleanup and exit */
3187 AR6000_STAT_INC(ar, tx_dropped);
3188 AR6000_STAT_INC(ar, tx_aborted_errors);
3194 /* take the lock to protect driver data */
3195 AR6000_SPIN_LOCK(&ar->arLock, 0);
3199 if (checkAdHocPsMapping) {
3200 eid = ar6000_ibss_map_epid(skb, dev, &mapNo);
3202 eid = arAc2EndpointID (ar, ac);
3204 /* validate that the endpoint is connected */
3205 if (eid == 0 || eid == ENDPOINT_UNUSED ) {
3206 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid));
3209 /* allocate resource for this packet */
3210 cookie = ar6000_alloc_cookie(ar);
3212 if (cookie != NULL) {
3213 /* update counts while the lock is held */
3214 ar->arTxPending[eid]++;
3215 ar->arTotalTxDataPending++;
3220 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3222 if (cookie != NULL) {
3223 cookie->arc_bp[0] = (unsigned long)skb;
3224 cookie->arc_bp[1] = mapNo;
3225 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3233 if (debugdriver >= 3) {
3234 ar6000_dump_skb(skb);
3237 #ifdef HTC_TEST_SEND_PKTS
3238 DoHTCSendPktsTest(ar,mapNo,eid,skb);
3240 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3241 * the ar6000_tx_complete callback */
3242 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3244 /* no packet to send, cleanup */
3246 AR6000_STAT_INC(ar, tx_dropped);
3247 AR6000_STAT_INC(ar, tx_aborted_errors);
3254 ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev)
3256 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
3257 struct ar_cookie *cookie;
3258 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;