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 fwmode = 1;
135 unsigned int mbox_yield_limit = 99;
136 unsigned int enablerssicompensation = 0;
137 int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF;
138 int allow_trace_signal = 0;
139 #ifdef CONFIG_HOST_TCMD_SUPPORT
140 unsigned int testmode =0;
143 unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC;
144 unsigned int panic_on_assert = 1;
145 unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT;
147 unsigned int setuphci = SETUPHCI_DEFAULT;
148 unsigned int loghci = 0;
149 unsigned int setupbtdev = SETUPBTDEV_DEFAULT;
150 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
151 unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT;
152 unsigned int hciuartscale = HCIUARTSCALE_DEFAULT;
153 unsigned int hciuartstep = HCIUARTSTEP_DEFAULT;
155 unsigned int csumOffload=0;
156 unsigned int csumOffloadTest=0;
157 unsigned int eppingtest=0;
159 module_param_string(ifname, ifname, sizeof(ifname), 0644);
160 module_param(wlaninitmode, int, 0644);
161 module_param(bypasswmi, bool, 0644);
162 module_param(debuglevel, uint, 0644);
163 module_param(tspecCompliance, int, 0644);
164 module_param(onebitmode, uint, 0644);
165 module_param(busspeedlow, uint, 0644);
166 module_param(skipflash, uint, 0644);
167 module_param(wmitimeout, uint, 0644);
168 module_param(wlanNodeCaching, uint, 0644);
169 module_param(logWmiRawMsgs, uint, 0644);
170 module_param(enableuartprint, uint, 0644);
171 module_param(enabletimerwar, uint, 0644);
172 module_param(fwmode, uint, 0644);
173 module_param(mbox_yield_limit, uint, 0644);
174 module_param(reduce_credit_dribble, int, 0644);
175 module_param(allow_trace_signal, int, 0644);
176 module_param(enablerssicompensation, uint, 0644);
177 module_param(processDot11Hdr, uint, 0644);
178 module_param(csumOffload, uint, 0644);
179 #ifdef CONFIG_HOST_TCMD_SUPPORT
180 module_param(testmode, uint, 0644);
182 module_param(irqprocmode, uint, 0644);
183 module_param(nohifscattersupport, uint, 0644);
184 module_param(panic_on_assert, uint, 0644);
185 module_param(setuphci, uint, 0644);
186 module_param(loghci, uint, 0644);
187 module_param(setupbtdev, uint, 0644);
188 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
189 module_param(ar3khcibaud, uint, 0644);
190 module_param(hciuartscale, uint, 0644);
191 module_param(hciuartstep, uint, 0644);
193 module_param(eppingtest, uint, 0644);
195 /* in 2.6.10 and later this is now a pointer to a uint */
196 unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX;
197 #define mboxnum &_mboxnum
200 u32 g_dbg_flags = DBG_DEFAULTS;
201 unsigned int debugflags = 0;
203 unsigned int debughtc = 0;
204 unsigned int debugbmi = 0;
205 unsigned int debughif = 0;
206 unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0};
207 unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0};
208 unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0};
209 unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0};
210 module_param(debugflags, uint, 0644);
211 module_param(debugdriver, int, 0644);
212 module_param(debughtc, uint, 0644);
213 module_param(debugbmi, uint, 0644);
214 module_param(debughif, uint, 0644);
215 module_param_array(txcreditsavailable, uint, mboxnum, 0644);
216 module_param_array(txcreditsconsumed, uint, mboxnum, 0644);
217 module_param_array(txcreditintrenable, uint, mboxnum, 0644);
218 module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644);
222 unsigned int resetok = 1;
223 unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0};
224 unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0};
225 unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0};
226 unsigned int hifBusRequestNumMax = 40;
227 unsigned int war23838_disabled = 0;
228 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
229 unsigned int enableAPTCHeuristics = 1;
230 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
231 module_param_array(tx_attempt, uint, mboxnum, 0644);
232 module_param_array(tx_post, uint, mboxnum, 0644);
233 module_param_array(tx_complete, uint, mboxnum, 0644);
234 module_param(hifBusRequestNumMax, uint, 0644);
235 module_param(war23838_disabled, uint, 0644);
236 module_param(resetok, uint, 0644);
237 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
238 module_param(enableAPTCHeuristics, uint, 0644);
239 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
241 #ifdef BLOCK_TX_PATH_FLAG
243 module_param(blocktx, int, 0644);
244 #endif /* BLOCK_TX_PATH_FLAG */
246 typedef struct user_rssi_compensation_t {
258 } USER_RSSI_CPENSATION;
260 static USER_RSSI_CPENSATION rssi_compensation_param;
262 static s16 rssi_compensation_table[96];
264 int reconnect_flag = 0;
265 static ar6k_pal_config_t ar6k_pal_config_g;
267 /* Function declarations */
268 static int ar6000_init_module(void);
269 static void ar6000_cleanup_module(void);
271 int ar6000_init(struct net_device *dev);
272 static int ar6000_open(struct net_device *dev);
273 static int ar6000_close(struct net_device *dev);
274 static void ar6000_init_control_info(struct ar6_softc *ar);
275 static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev);
277 void ar6000_destroy(struct net_device *dev, unsigned int unregister);
278 static void ar6000_detect_error(unsigned long ptr);
279 static void ar6000_set_multicast_list(struct net_device *dev);
280 static struct net_device_stats *ar6000_get_stats(struct net_device *dev);
282 static void disconnect_timer_handler(unsigned long ptr);
284 void read_rssi_compensation_param(struct ar6_softc *ar);
287 * HTC service connection handlers
289 static int ar6000_avail_ev(void *context, void *hif_handle);
291 static int ar6000_unavail_ev(void *context, void *hif_handle);
293 int ar6000_configure_target(struct ar6_softc *ar);
295 static void ar6000_target_failure(void *Instance, int Status);
297 static void ar6000_rx(void *Context, struct htc_packet *pPacket);
299 static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint);
301 static void ar6000_tx_complete(void *Context, struct htc_packet_queue *pPackets);
303 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket);
305 static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num);
306 static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf);
307 //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf);
309 static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length);
311 static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count);
313 static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar);
316 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
317 struct bin_attribute *bin_attr,
318 char *buf, loff_t pos, size_t count);
321 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
322 struct bin_attribute *bin_attr,
323 char *buf, loff_t pos, size_t count);
326 ar6000_sysfs_bmi_init(struct ar6_softc *ar);
328 void ar6k_cleanup_hci_pal(struct ar6_softc *ar);
331 ar6000_sysfs_bmi_deinit(struct ar6_softc *ar);
334 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode);
340 struct net_device *ar6000_devices[MAX_AR6000];
341 static int is_netdev_registered;
342 DECLARE_WAIT_QUEUE_HEAD(arEvent);
343 static void ar6000_cookie_init(struct ar6_softc *ar);
344 static void ar6000_cookie_cleanup(struct ar6_softc *ar);
345 static void ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie);
346 static struct ar_cookie *ar6000_alloc_cookie(struct ar6_softc *ar);
348 static int ar6000_reinstall_keys(struct ar6_softc *ar,u8 key_op_ctrl);
350 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
351 struct net_device *arApNetDev;
352 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
354 static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
356 #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \
357 (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
358 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
361 static struct net_device_ops ar6000_netdev_ops = {
363 .ndo_open = ar6000_open,
364 .ndo_stop = ar6000_close,
365 .ndo_get_stats = ar6000_get_stats,
366 .ndo_start_xmit = ar6000_data_tx,
367 .ndo_set_multicast_list = ar6000_set_multicast_list,
370 /* Debug log support */
373 * Flag to govern whether the debug logs should be parsed in the kernel
374 * or reported to the application.
376 #define REPORT_DEBUG_LOGS_TO_APP
379 ar6000_set_host_app_area(struct ar6_softc *ar)
382 struct host_app_area_s host_app_area;
384 /* Fetch the address of the host_app_area_s instance in the host interest area */
385 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest));
386 if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != 0) {
389 address = TARG_VTOP(ar->arTargetType, data);
390 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
391 if (ar6000_WriteDataDiag(ar->arHifDevice, address,
392 (u8 *)&host_app_area,
393 sizeof(struct host_app_area_s)) != 0)
401 u32 dbglog_get_debug_hdr_ptr(struct ar6_softc *ar)
407 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr));
408 if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address,
409 (u8 *)¶m, 4)) != 0)
418 * The dbglog module has been initialized. Its ok to access the relevant
419 * data stuctures over the diagnostic window.
422 ar6000_dbglog_init_done(struct ar6_softc *ar)
424 ar->dbglog_init_done = true;
427 u32 dbglog_get_debug_fragment(s8 *datap, u32 len, u32 limit)
436 buffer = (s32 *)datap;
437 length = (limit >> 2);
442 while (count < length) {
443 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
444 fraglen = (count << 2);
445 count += numargs + 1;
453 dbglog_parse_debug_logs(s8 *datap, u32 len)
464 buffer = (s32 *)datap;
466 while (count < length) {
467 debugid = DBGLOG_GET_DBGID(buffer[count]);
468 moduleid = DBGLOG_GET_MODULEID(buffer[count]);
469 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
470 timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]);
473 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp));
477 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid,
478 timestamp, buffer[count+1]));
482 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid,
483 timestamp, buffer[count+1], buffer[count+2]));
487 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs));
489 count += numargs + 1;
494 ar6000_dbglog_get_debug_logs(struct ar6_softc *ar)
496 u32 data[8]; /* Should be able to accomodate struct dbglog_buf_s */
503 if (!ar->dbglog_init_done) return A_ERROR;
506 AR6000_SPIN_LOCK(&ar->arLock, 0);
508 if (ar->dbgLogFetchInProgress) {
509 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
513 /* block out others */
514 ar->dbgLogFetchInProgress = true;
516 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
518 debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar);
519 printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr);
521 /* Get the contents of the ring buffer */
523 address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr);
524 length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */;
525 A_MEMZERO(data, sizeof(data));
526 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)data, length);
527 address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */);
529 dropped = data[1]; /* dropped */
530 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
531 A_MEMZERO(data, sizeof(data));
532 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)&data, length);
535 address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/);
536 length = data[3]; /* length */
537 if ((length) && (length <= data[2] /* bufsize*/)) {
538 /* Rewind the index if it is about to overrun the buffer */
539 if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) {
542 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
543 (u8 *)&ar->log_buffer[ar->log_cnt], length))
547 ar6000_dbglog_event(ar, dropped, (s8 *)&ar->log_buffer[ar->log_cnt], length);
548 ar->log_cnt += length;
550 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n",
554 address = TARG_VTOP(ar->arTargetType, data[0] /* next */);
555 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
556 A_MEMZERO(data, sizeof(data));
557 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
558 (u8 *)&data, length))
563 } while (address != firstbuf);
566 ar->dbgLogFetchInProgress = false;
572 ar6000_dbglog_event(struct ar6_softc *ar, u32 dropped,
573 s8 *buffer, u32 length)
575 #ifdef REPORT_DEBUG_LOGS_TO_APP
576 #define MAX_WIRELESS_EVENT_SIZE 252
578 * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages.
579 * There seems to be a limitation on the length of message that could be
580 * transmitted to the user app via this mechanism.
585 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
586 MAX_WIRELESS_EVENT_SIZE);
589 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
590 MAX_WIRELESS_EVENT_SIZE);
593 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n",
596 /* Interpret the debug logs */
597 dbglog_parse_debug_logs((s8 *)buffer, length);
598 #endif /* REPORT_DEBUG_LOGS_TO_APP */
603 ar6000_init_module(void)
605 static int probed = 0;
607 OSDRV_CALLBACKS osdrvCallbacks;
609 a_module_debug_support_init();
612 /* check for debug mask overrides */
614 ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc);
617 ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi);
620 ATH_DEBUG_SET_DEBUG_MASK(hif,debughif);
622 if (debugdriver != 0) {
623 ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver);
628 A_REGISTER_MODULE_DEBUG_INFO(driver);
630 A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks));
631 osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev;
632 osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev;
634 osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev;
635 osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev;
636 osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev;
642 /* Set the debug flags if specified at load time */
645 g_dbg_flags = debugflags;
654 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
655 memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD));
656 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
658 status = HIFInit(&osdrvCallbacks);
666 ar6000_cleanup_module(void)
669 struct net_device *ar6000_netdev;
671 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
672 /* Delete the Adaptive Power Control timer */
673 if (timer_pending(&aptcTimer)) {
674 del_timer_sync(&aptcTimer);
676 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
678 for (i=0; i < MAX_AR6000; i++) {
679 if (ar6000_devices[i] != NULL) {
680 ar6000_netdev = ar6000_devices[i];
681 ar6000_devices[i] = NULL;
682 ar6000_destroy(ar6000_netdev, 1);
686 HIFShutDownDevice(NULL);
688 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;
960 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
961 filename = AR6003_REV1_OTP_FILE;
962 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
963 filename = AR6003_REV2_OTP_FILE;
965 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
970 case AR6K_FIRMWARE_FILE:
971 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
972 filename = AR6003_REV1_FIRMWARE_FILE;
973 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
974 filename = AR6003_REV2_FIRMWARE_FILE;
976 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
982 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
983 filename = AR6003_REV1_EPPING_FIRMWARE_FILE;
984 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
985 filename = AR6003_REV2_EPPING_FIRMWARE_FILE;
987 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n",
988 ar->arVersion.target_ver));
994 #ifdef CONFIG_HOST_TCMD_SUPPORT
996 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
997 filename = AR6003_REV1_TCMD_FIRMWARE_FILE;
998 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
999 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
1001 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1007 #ifdef HTC_RAW_INTERFACE
1008 if (!eppingtest && bypasswmi) {
1009 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1010 filename = AR6003_REV1_ART_FIRMWARE_FILE;
1011 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1012 filename = AR6003_REV2_ART_FIRMWARE_FILE;
1014 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1022 case AR6K_PATCH_FILE:
1023 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1024 filename = AR6003_REV1_PATCH_FILE;
1025 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1026 filename = AR6003_REV2_PATCH_FILE;
1028 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1033 case AR6K_BOARD_DATA_FILE:
1034 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1035 filename = AR6003_REV1_BOARD_DATA_FILE;
1036 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1037 filename = AR6003_REV2_BOARD_DATA_FILE;
1039 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1045 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file));
1048 if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1050 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename));
1054 #ifdef SOFTMAC_FILE_USED
1055 if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) {
1056 ar6000_softmac_update(ar, (u8 *)fw_entry->data, fw_entry->size);
1061 fw_entry_size = fw_entry->size;
1063 /* Load extended board data for AR6003 */
1064 if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) {
1065 u32 board_ext_address;
1066 u32 board_ext_data_size;
1067 u32 board_data_size;
1069 board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \
1070 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0));
1072 board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \
1073 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0));
1075 /* Determine where in Target RAM to write Board Data */
1076 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (u8 *)&board_ext_address, 4));
1077 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address));
1079 /* check whether the target has allocated memory for extended board data and file contains extended board data */
1080 if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) {
1083 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (u8 *)(fw_entry->data + board_data_size), board_ext_data_size);
1086 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1087 A_RELEASE_FIRMWARE(fw_entry);
1091 /* Record the fact that extended board Data IS initialized */
1093 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_initialized), (u8 *)¶m, 4));
1095 fw_entry_size = board_data_size;
1099 status = BMIFastDownload(ar->arHifDevice, address, (u8 *)fw_entry->data, fw_entry_size);
1101 status = BMIWriteMemory(ar->arHifDevice, address, (u8 *)fw_entry->data, fw_entry_size);
1105 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1106 A_RELEASE_FIRMWARE(fw_entry);
1109 A_RELEASE_FIRMWARE(fw_entry);
1114 ar6000_update_bdaddr(struct ar6_softc *ar)
1117 if (setupbtdev != 0) {
1120 if (BMIReadMemory(ar->arHifDevice,
1121 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4) != 0)
1123 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n"));
1127 if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (u8 *)ar->bdaddr, 6) != 0)
1129 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n"));
1132 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0],
1133 ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3],
1134 ar->bdaddr[4], ar->bdaddr[5]));
1141 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode)
1143 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n"));
1145 if (mode == WLAN_INIT_MODE_UDEV) {
1147 const struct firmware *fw_entry;
1149 /* Get config using udev through a script in user space */
1150 sprintf(version, "%2.2x", ar->arVersion.target_ver);
1151 if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1153 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version));
1157 A_RELEASE_FIRMWARE(fw_entry);
1159 /* The config is contained within the driver itself */
1161 u32 param, options, sleep, address;
1163 /* Temporarily disable system sleep */
1164 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1165 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1167 param |= AR6K_OPTION_SLEEP_DISABLE;
1168 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1170 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1171 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1173 param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1);
1174 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1175 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep));
1177 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1178 /* Program analog PLL register */
1179 bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001));
1180 /* Run at 80/88MHz by default */
1181 param = CPU_CLOCK_STANDARD_SET(1);
1183 /* Run at 40/44MHz by default */
1184 param = CPU_CLOCK_STANDARD_SET(0);
1186 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1187 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1190 if (ar->arTargetType == TARGET_TYPE_AR6002) {
1191 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1194 /* LPO_CAL.ENABLE = 1 if no external clk is detected */
1196 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1197 param = LPO_CAL_ENABLE_SET(1);
1198 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1201 /* Venus2.0: Lower SDIO pad drive strength,
1202 * temporary WAR to avoid SDIO CRC error */
1203 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1204 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n"));
1206 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1207 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1209 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1210 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1212 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1213 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1215 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1216 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1219 #ifdef FORCE_INTERNAL_CLOCK
1220 /* Ignore external clock, if any, and force use of internal clock */
1221 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1222 /* hi_ext_clk_detected = 0 */
1224 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1226 /* CLOCK_CONTROL &= ~LF_CLK32 */
1227 address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS;
1228 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1229 param &= (~CLOCK_CONTROL_LF_CLK32_SET(1));
1230 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1232 #endif /* FORCE_INTERNAL_CLOCK */
1234 /* Transfer Board Data from Target EEPROM to Target RAM */
1235 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1236 /* Determine where in Target RAM to write Board Data */
1237 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4));
1238 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address));
1240 /* Write EEPROM data to Target RAM */
1241 if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, false)) != 0) {
1245 /* Record the fact that Board Data IS initialized */
1247 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (u8 *)¶m, 4));
1249 /* Transfer One time Programmable data */
1250 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1251 status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, true);
1253 /* Execute the OTP code */
1255 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1256 bmifn(BMIExecute(ar->arHifDevice, address, ¶m));
1257 } else if (status != A_ENOENT) {
1261 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType));
1265 /* Download Target firmware */
1266 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1267 if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, true)) != 0) {
1271 /* Set starting address for firmware */
1272 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1273 bmifn(BMISetAppStart(ar->arHifDevice, address));
1275 /* Apply the patches */
1276 AR6K_PATCH_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1277 if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, false)) != 0) {
1282 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), (u8 *)¶m, 4));
1284 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1285 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1286 /* Reserve 5.5K of RAM */
1288 } else { /* AR6003_REV2_VERSION */
1289 /* Reserve 6.5K of RAM */
1292 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_end_RAM_reserve_sz), (u8 *)¶m, 4));
1295 /* Restore system sleep */
1296 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1297 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep));
1299 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1300 param = options | 0x20;
1301 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1303 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1304 /* Configure GPIO AR6003 UART */
1305 #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN
1306 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
1308 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1309 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (u8 *)¶m, 4));
1311 #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23)
1313 address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS;
1314 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1315 param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1);
1316 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1320 /* Configure GPIO for BT Reset */
1321 #ifdef ATH6KL_CONFIG_GPIO_BT_RESET
1322 #define CONFIG_AR600x_BT_RESET_PIN 0x16
1323 param = CONFIG_AR600x_BT_RESET_PIN;
1324 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (u8 *)¶m, 4));
1325 #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */
1327 /* Configure UART flow control polarity */
1328 #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY
1329 #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0
1332 #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1)
1333 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1334 param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2);
1335 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (u8 *)¶m, 4));
1337 #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */
1340 #ifdef HTC_RAW_INTERFACE
1341 if (!eppingtest && bypasswmi) {
1342 /* Don't run BMIDone for ART mode and force resetok=0 */
1346 #endif /* HTC_RAW_INTERFACE */
1353 ar6000_configure_target(struct ar6_softc *ar)
1356 if (enableuartprint) {
1358 if (BMIWriteMemory(ar->arHifDevice,
1359 HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable),
1363 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n"));
1366 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n"));
1369 /* Tell target which HTC version it is used*/
1370 param = HTC_PROTOCOL_VERSION;
1371 if (BMIWriteMemory(ar->arHifDevice,
1372 HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest),
1376 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n"));
1380 #ifdef CONFIG_HOST_TCMD_SUPPORT
1382 ar->arTargetMode = AR6000_TCMD_MODE;
1384 ar->arTargetMode = AR6000_WLAN_MODE;
1387 if (enabletimerwar) {
1390 if (BMIReadMemory(ar->arHifDevice,
1391 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1395 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n"));
1399 param |= HI_OPTION_TIMER_WAR;
1401 if (BMIWriteMemory(ar->arHifDevice,
1402 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1406 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n"));
1409 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n"));
1412 /* set the firmware mode to STA/IBSS/AP */
1416 if (BMIReadMemory(ar->arHifDevice,
1417 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1421 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n"));
1425 param |= (fwmode << HI_OPTION_FW_MODE_SHIFT);
1427 if (BMIWriteMemory(ar->arHifDevice,
1428 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1432 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n"));
1435 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1438 #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS
1442 if (BMIReadMemory(ar->arHifDevice,
1443 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1447 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n"));
1451 param |= HI_OPTION_DISABLE_DBGLOG;
1453 if (BMIWriteMemory(ar->arHifDevice,
1454 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1458 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n"));
1461 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1463 #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */
1466 * Hardcode the address use for the extended board data
1467 * Ideally this should be pre-allocate by the OS at boot time
1468 * But since it is a new feature and board data is loaded
1469 * at init time, we have to workaround this from host.
1470 * It is difficult to patch the firmware boot code,
1471 * but possible in theory.
1473 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1474 param = AR6003_BOARD_EXT_DATA_ADDRESS;
1475 if (BMIWriteMemory(ar->arHifDevice,
1476 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data),
1480 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n"));
1486 /* since BMIInit is called in the driver layer, we have to set the block
1487 * size here for the target */
1489 if (ar6000_set_htc_params(ar->arHifDevice, ar->arTargetType,
1490 mbox_yield_limit, 0)) {
1491 /* use default number of control buffers */
1495 if (setupbtdev != 0) {
1496 if (ar6000_set_hci_bridge_flags(ar->arHifDevice,
1506 init_netdev(struct net_device *dev, char *name)
1508 dev->netdev_ops = &ar6000_netdev_ops;
1509 dev->watchdog_timeo = AR6000_TX_TIMEOUT;
1512 * We need the OS to provide us with more headroom in order to
1513 * perform dix to 802.3, WMI header encap, and the HTC header
1515 if (processDot11Hdr) {
1516 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;
1518 dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) +
1519 sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
1524 strcpy(dev->name, name);
1527 #ifdef CONFIG_CHECKSUM_OFFLOAD
1529 dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/
1536 static int __ath6kl_init_netdev(struct net_device *dev)
1541 r = ar6000_init(dev);
1545 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n"));
1552 #ifdef HTC_RAW_INTERFACE
1553 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1555 if (!eppingtest && bypasswmi)
1558 return __ath6kl_init_netdev(dev);
1561 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1563 return __ath6kl_init_netdev(dev);
1567 static int ath6kl_init_netdev(struct ar6_softc *ar)
1571 r = ar6000_sysfs_bmi_get_config(ar, wlaninitmode);
1573 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1575 "ar6000_sysfs_bmi_get_config failed\n"));
1579 return ath6kl_init_netdev_wmi(ar->arNetDev);
1583 * HTC Event handlers
1586 ar6000_avail_ev(void *context, void *hif_handle)
1589 struct net_device *dev;
1591 struct ar6_softc *ar;
1592 int device_index = 0;
1593 struct htc_init_info htcInfo;
1594 struct wireless_dev *wdev;
1596 struct hif_device_os_device_info osDevInfo;
1598 memset(&osDevInfo, 0, sizeof(osDevInfo));
1599 if (HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE,
1600 &osDevInfo, sizeof(osDevInfo))) {
1601 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Failed to get OS device instance\n", __func__));
1605 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n"));
1607 for (i=0; i < MAX_AR6000; i++) {
1608 if (ar6000_devices[i] == NULL) {
1613 if (i == MAX_AR6000) {
1614 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n"));
1618 /* Save this. It gives a bit better readability especially since */
1619 /* we use another local "i" variable below. */
1622 wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice);
1624 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__));
1627 ar_netif = wdev_priv(wdev);
1629 if (ar_netif == NULL) {
1630 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__));
1634 A_MEMZERO(ar_netif, sizeof(struct ar6_softc));
1635 ar = (struct ar6_softc *)ar_netif;
1638 wdev->iftype = NL80211_IFTYPE_STATION;
1640 dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1);
1642 printk(KERN_CRIT "AR6K: no memory for network device instance\n");
1643 ar6k_cfg80211_deinit(ar);
1647 dev->ieee80211_ptr = wdev;
1648 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1650 ar->arNetworkType = INFRA_NETWORK;
1651 ar->smeState = SME_DISCONNECTED;
1653 init_netdev(dev, ifname);
1657 ar->arHifDevice = hif_handle;
1658 ar->arWlanState = WLAN_ENABLED;
1659 ar->arDeviceIndex = device_index;
1661 ar->arWlanPowerState = WLAN_POWER_STATE_ON;
1662 ar->arWlanOff = false; /* We are in ON state */
1664 ar->arWowState = WLAN_WOW_STATE_NONE;
1665 ar->arBTOff = true; /* BT chip assumed to be OFF */
1666 ar->arBTSharing = WLAN_CONFIG_BT_SHARING;
1667 ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF;
1668 ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND;
1669 ar->arWow2Config = WLAN_CONFIG_PM_WOW2;
1670 #endif /* CONFIG_PM */
1672 A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev);
1673 ar->arHBChallengeResp.seqNum = 0;
1674 ar->arHBChallengeResp.outstanding = false;
1675 ar->arHBChallengeResp.missCnt = 0;
1676 ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT;
1677 ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT;
1679 ar6000_init_control_info(ar);
1680 init_waitqueue_head(&arEvent);
1681 sema_init(&ar->arSem, 1);
1682 ar->bIsDestroyProgress = false;
1684 INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue);
1686 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
1687 A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar);
1688 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
1690 A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev);
1694 ar6000_sysfs_bmi_init(ar);
1697 struct bmi_target_info targ_info;
1699 r = BMIGetTargetInfo(ar->arHifDevice, &targ_info);
1701 goto avail_ev_failed;
1703 ar->arVersion.target_ver = targ_info.target_ver;
1704 ar->arTargetType = targ_info.target_type;
1706 /* do any target-specific preparation that can be done through BMI */
1707 r = ar6000_prepare_target(ar->arHifDevice,
1708 targ_info.target_type,
1709 targ_info.target_ver);
1711 goto avail_ev_failed;
1715 r = ar6000_configure_target(ar);
1717 goto avail_ev_failed;
1719 A_MEMZERO(&htcInfo,sizeof(htcInfo));
1720 htcInfo.pContext = ar;
1721 htcInfo.TargetFailure = ar6000_target_failure;
1723 ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo);
1725 if (!ar->arHtcTarget) {
1727 goto avail_ev_failed;
1730 spin_lock_init(&ar->arLock);
1733 ar->arWapiEnable = 0;
1738 /*if external frame work is also needed, change and use an extended rxMetaVerion*/
1739 ar->rxMetaVersion=WMI_META_VERSION_2;
1742 ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs);
1743 if (!ar->aggr_cntxt) {
1744 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__));
1746 goto avail_ev_failed;
1749 aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack);
1751 HIFClaimDevice(ar->arHifDevice, ar);
1753 /* We only register the device in the global list if we succeed. */
1754 /* If the device is in the global list, it will be destroyed */
1755 /* when the module is unloaded. */
1756 ar6000_devices[device_index] = dev;
1758 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode));
1759 if ((wlaninitmode == WLAN_INIT_MODE_UDEV) ||
1760 (wlaninitmode == WLAN_INIT_MODE_DRV)) {
1761 r = ath6kl_init_netdev(ar);
1763 goto avail_ev_failed;
1766 /* This runs the init function if registered */
1767 r = register_netdev(dev);
1769 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n"));
1770 ar6000_destroy(dev, 0);
1774 is_netdev_registered = 1;
1776 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
1778 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
1779 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n",
1780 dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index,
1781 (unsigned long)ar));
1785 ar6000_sysfs_bmi_deinit(ar);
1790 static void ar6000_target_failure(void *Instance, int Status)
1792 struct ar6_softc *ar = (struct ar6_softc *)Instance;
1793 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
1794 static bool sip = false;
1798 printk(KERN_ERR "ar6000_target_failure: target asserted \n");
1800 if (timer_pending(&ar->arHBChallengeResp.timer)) {
1801 A_UNTIMEOUT(&ar->arHBChallengeResp.timer);
1804 /* try dumping target assertion information (if any) */
1805 ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType);
1808 * Fetch the logs from the target via the diagnostic
1811 ar6000_dbglog_get_debug_logs(ar);
1813 /* Report the error only once */
1816 errEvent.errorVal = WMI_TARGET_COM_ERR |
1817 WMI_TARGET_FATAL_ERR;
1823 ar6000_unavail_ev(void *context, void *hif_handle)
1825 struct ar6_softc *ar = (struct ar6_softc *)context;
1826 /* NULL out it's entry in the global list */
1827 ar6000_devices[ar->arDeviceIndex] = NULL;
1828 ar6000_destroy(ar->arNetDev, 1);
1834 ar6000_restart_endpoint(struct net_device *dev)
1837 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1841 if ( (status=ar6000_configure_target(ar))!= 0)
1843 if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != 0)
1845 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
1849 status = (ar6000_init(dev)==0) ? 0 : A_ERROR;
1855 if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) {
1856 ar6000_connect_to_ap(ar);
1864 ar6000_devices[ar->arDeviceIndex] = NULL;
1865 ar6000_destroy(ar->arNetDev, 1);
1869 ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs)
1871 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1873 /* Stop the transmit queues */
1874 netif_stop_queue(dev);
1876 /* Disable the target and the interrupts associated with it */
1877 if (ar->arWmiReady == true)
1881 bool disconnectIssued;
1883 disconnectIssued = (ar->arConnected) || (ar->arConnectPending);
1884 ar6000_disconnect(ar);
1886 ar6000_init_profile_info(ar);
1889 A_UNTIMEOUT(&ar->disconnect_timer);
1892 ar6000_dbglog_get_debug_logs(ar);
1895 ar->arWmiReady = false;
1896 wmi_shutdown(ar->arWmi);
1897 ar->arWmiEnabled = false;
1900 * After wmi_shudown all WMI events will be dropped.
1901 * We need to cleanup the buffers allocated in AP mode
1902 * and give disconnect notification to stack, which usually
1903 * happens in the disconnect_event.
1904 * Simulate the disconnect_event by calling the function directly.
1905 * Sometimes disconnect_event will be received when the debug logs
1908 if (disconnectIssued) {
1909 if(ar->arNetworkType & AP_NETWORK) {
1910 ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0);
1912 ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0);
1915 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
1916 ar->user_key_ctrl = 0;
1919 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__));
1923 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n",
1924 __func__, (unsigned long) ar, (unsigned long) ar->arWmi));
1926 /* Shut down WMI if we have started it */
1927 if(ar->arWmiEnabled == true)
1929 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__));
1930 wmi_shutdown(ar->arWmi);
1931 ar->arWmiEnabled = false;
1936 if (ar->arHtcTarget != NULL) {
1937 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
1938 if (NULL != ar6kHciTransCallbacks.cleanupTransport) {
1939 ar6kHciTransCallbacks.cleanupTransport(NULL);
1942 // FIXME: workaround to reset BT's UART baud rate to default
1943 if (NULL != ar->exitCallback) {
1944 struct ar3k_config_info ar3kconfig;
1947 A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig));
1948 ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig);
1949 status = ar->exitCallback(&ar3kconfig);
1951 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n"));
1956 ar6000_cleanup_hci(ar);
1958 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n"));
1960 HTCStop(ar->arHtcTarget);
1964 /* try to reset the device if we can
1965 * The driver may have been configure NOT to reset the target during
1966 * a debug session */
1967 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Attempting to reset target on instance destroy.... \n"));
1968 if (ar->arHifDevice != NULL) {
1969 bool coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? true: false;
1970 ar6000_reset_device(ar->arHifDevice, ar->arTargetType, true, coldReset);
1973 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n"));
1975 /* Done with cookies */
1976 ar6000_cookie_cleanup(ar);
1978 /* cleanup any allocated AMSDU buffers */
1979 ar6000_cleanup_amsdu_rxbufs(ar);
1982 * We need to differentiate between the surprise and planned removal of the
1983 * device because of the following consideration:
1984 * - In case of surprise removal, the hcd already frees up the pending
1985 * for the device and hence there is no need to unregister the function
1986 * driver inorder to get these requests. For planned removal, the function
1987 * driver has to explictly unregister itself to have the hcd return all the
1988 * pending requests before the data structures for the devices are freed up.
1989 * Note that as per the current implementation, the function driver will
1990 * end up releasing all the devices since there is no API to selectively
1991 * release a particular device.
1992 * - Certain commands issued to the target can be skipped for surprise
1993 * removal since they will anyway not go through.
1996 ar6000_destroy(struct net_device *dev, unsigned int unregister)
1998 struct ar6_softc *ar;
2000 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n"));
2002 if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL))
2004 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__));
2008 ar->bIsDestroyProgress = true;
2010 if (down_interruptible(&ar->arSem)) {
2011 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__));
2015 if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) {
2016 /* only stop endpoint if we are not stop it in suspend_ev */
2017 ar6000_stop_endpoint(dev, false, true);
2019 /* clear up the platform power state before rmmod */
2020 plat_setup_power(1,0);
2023 ar->arWlanState = WLAN_DISABLED;
2024 if (ar->arHtcTarget != NULL) {
2026 HTCDestroy(ar->arHtcTarget);
2028 if (ar->arHifDevice != NULL) {
2029 /*release the device so we do not get called back on remove incase we
2030 * we're explicity destroyed by module unload */
2031 HIFReleaseDevice(ar->arHifDevice);
2032 HIFShutDownDevice(ar->arHifDevice);
2034 aggr_module_destroy(ar->aggr_cntxt);
2036 /* Done with cookies */
2037 ar6000_cookie_cleanup(ar);
2039 /* cleanup any allocated AMSDU buffers */
2040 ar6000_cleanup_amsdu_rxbufs(ar);
2042 ar6000_sysfs_bmi_deinit(ar);
2047 /* Clear the tx counters */
2048 memset(tx_attempt, 0, sizeof(tx_attempt));
2049 memset(tx_post, 0, sizeof(tx_post));
2050 memset(tx_complete, 0, sizeof(tx_complete));
2052 #ifdef HTC_RAW_INTERFACE
2054 kfree(ar->arRawHtc);
2055 ar->arRawHtc = NULL;
2058 /* Free up the device data structure */
2059 if (unregister && is_netdev_registered) {
2060 unregister_netdev(dev);
2061 is_netdev_registered = 0;
2065 ar6k_cfg80211_deinit(ar);
2067 #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT
2068 ar6000_remove_ap_interface();
2069 #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
2071 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n"));
2074 static void disconnect_timer_handler(unsigned long ptr)
2076 struct net_device *dev = (struct net_device *)ptr;
2077 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2079 A_UNTIMEOUT(&ar->disconnect_timer);
2081 ar6000_init_profile_info(ar);
2082 ar6000_disconnect(ar);
2085 static void ar6000_detect_error(unsigned long ptr)
2087 struct net_device *dev = (struct net_device *)ptr;
2088 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2089 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
2091 AR6000_SPIN_LOCK(&ar->arLock, 0);
2093 if (ar->arHBChallengeResp.outstanding) {
2094 ar->arHBChallengeResp.missCnt++;
2096 ar->arHBChallengeResp.missCnt = 0;
2099 if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) {
2100 /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */
2101 ar->arHBChallengeResp.missCnt = 0;
2102 ar->arHBChallengeResp.seqNum = 0;
2103 errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR;
2104 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2108 /* Generate the sequence number for the next challenge */
2109 ar->arHBChallengeResp.seqNum++;
2110 ar->arHBChallengeResp.outstanding = true;
2112 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2114 /* Send the challenge on the control channel */
2115 if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != 0) {
2116 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n"));
2120 /* Reschedule the timer for the next challenge */
2121 A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0);
2124 void ar6000_init_profile_info(struct ar6_softc *ar)
2127 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
2130 case HI_OPTION_FW_MODE_IBSS:
2131 ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK;
2133 case HI_OPTION_FW_MODE_BSS_STA:
2134 ar->arNetworkType = ar->arNextMode = INFRA_NETWORK;
2136 case HI_OPTION_FW_MODE_AP:
2137 ar->arNetworkType = ar->arNextMode = AP_NETWORK;
2141 ar->arDot11AuthMode = OPEN_AUTH;
2142 ar->arAuthMode = NONE_AUTH;
2143 ar->arPairwiseCrypto = NONE_CRYPT;
2144 ar->arPairwiseCryptoLen = 0;
2145 ar->arGroupCrypto = NONE_CRYPT;
2146 ar->arGroupCryptoLen = 0;
2147 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2148 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
2149 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
2150 ar->arBssChannel = 0;
2154 ar6000_init_control_info(struct ar6_softc *ar)
2156 ar->arWmiEnabled = false;
2157 ar6000_init_profile_info(ar);
2158 ar->arDefTxKeyIndex = 0;
2159 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2160 ar->arChannelHint = 0;
2161 ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL;
2162 ar->arListenIntervalB = 0;
2163 ar->arVersion.host_ver = AR6K_SW_VERSION;
2166 ar->arTxPwrSet = false;
2168 ar->arBeaconInterval = 0;
2170 ar->arMaxRetries = 0;
2171 ar->arWmmEnabled = true;
2173 ar->scan_triggered = 0;
2174 A_MEMZERO(&ar->scParams, sizeof(ar->scParams));
2175 ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT;
2176 ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS;
2178 /* Initialize the AP mode state info */
2181 A_MEMZERO((u8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t));
2183 /* init the Mutexes */
2184 A_MUTEX_INIT(&ar->mcastpsqLock);
2186 /* Init the PS queues */
2187 for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) {
2188 A_MUTEX_INIT(&ar->sta_list[ctr].psqLock);
2189 A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq);
2192 ar->ap_profile_flag = 0;
2193 A_NETBUF_QUEUE_INIT(&ar->mcastpsq);
2195 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
2196 ar->ap_wmode = DEF_AP_WMODE_G;
2197 ar->ap_dtim_period = DEF_AP_DTIM;
2198 ar->ap_beacon_interval = DEF_BEACON_INTERVAL;
2203 ar6000_open(struct net_device *dev)
2205 unsigned long flags;
2206 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2208 spin_lock_irqsave(&ar->arLock, flags);
2210 if(ar->arWlanState == WLAN_DISABLED) {
2211 ar->arWlanState = WLAN_ENABLED;
2214 if( ar->arConnected || bypasswmi) {
2215 netif_carrier_on(dev);
2216 /* Wake up the queues */
2217 netif_wake_queue(dev);
2220 netif_carrier_off(dev);
2222 spin_unlock_irqrestore(&ar->arLock, flags);
2227 ar6000_close(struct net_device *dev)
2229 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2230 netif_stop_queue(dev);
2232 ar6000_disconnect(ar);
2234 if(ar->arWmiReady == true) {
2235 if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0,
2236 0, 0, 0, 0, 0, 0, 0, 0) != 0) {
2239 ar->arWlanState = WLAN_DISABLED;
2241 ar6k_cfg80211_scanComplete_event(ar, A_ECANCELED);
2246 /* connect to a service */
2247 static int ar6000_connectservice(struct ar6_softc *ar,
2248 struct htc_service_connect_req *pConnect,
2252 struct htc_service_connect_resp response;
2256 A_MEMZERO(&response,sizeof(response));
2258 status = HTCConnectService(ar->arHtcTarget,
2263 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n",
2267 switch (pConnect->ServiceID) {
2268 case WMI_CONTROL_SVC :
2269 if (ar->arWmiEnabled) {
2270 /* set control endpoint for WMI use */
2271 wmi_set_control_ep(ar->arWmi, response.Endpoint);
2273 /* save EP for fast lookup */
2274 ar->arControlEp = response.Endpoint;
2276 case WMI_DATA_BE_SVC :
2277 arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint);
2279 case WMI_DATA_BK_SVC :
2280 arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint);
2282 case WMI_DATA_VI_SVC :
2283 arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint);
2285 case WMI_DATA_VO_SVC :
2286 arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint);
2289 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID));
2299 void ar6000_TxDataCleanup(struct ar6_softc *ar)
2301 /* flush all the data (non-control) streams
2302 * we only flush packets that are tagged as data, we leave any control packets that
2303 * were in the TX queues alone */
2304 HTCFlushEndpoint(ar->arHtcTarget,
2305 arAc2EndpointID(ar, WMM_AC_BE),
2307 HTCFlushEndpoint(ar->arHtcTarget,
2308 arAc2EndpointID(ar, WMM_AC_BK),
2310 HTCFlushEndpoint(ar->arHtcTarget,
2311 arAc2EndpointID(ar, WMM_AC_VI),
2313 HTCFlushEndpoint(ar->arHtcTarget,
2314 arAc2EndpointID(ar, WMM_AC_VO),
2319 ar6000_ac2_endpoint_id ( void * devt, u8 ac)
2321 struct ar6_softc *ar = (struct ar6_softc *) devt;
2322 return(arAc2EndpointID(ar, ac));
2325 u8 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep )
2327 struct ar6_softc *ar = (struct ar6_softc *) devt;
2328 return(arEndpoint2Ac(ar, ep ));
2332 * This function applies WLAN specific configuration defined in wlan_config.h
2334 int ar6000_target_config_wlan_params(struct ar6_softc *ar)
2337 #if defined(ENABLE_COEXISTENCE)
2338 WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd;
2339 WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd;
2340 #endif /* ENABLE_COEXISTENCE */
2342 #ifdef CONFIG_HOST_TCMD_SUPPORT
2343 if (ar->arTargetMode != AR6000_WLAN_MODE) {
2346 #endif /* CONFIG_HOST_TCMD_SUPPORT */
2349 * configure the device for rx dot11 header rules 0,0 are the default values
2350 * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required
2351 * if checksum offload is needed. Set RxMetaVersion to 2
2353 if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != 0) {
2354 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n"));
2358 #if defined(ENABLE_COEXISTENCE)
2359 /* Configure the type of BT collocated with WLAN */
2360 memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD));
2361 #ifdef CONFIG_AR600x_BT_QCOM
2362 sbcb_cmd.btcoexCoLocatedBTdev = 1;
2363 #elif defined(CONFIG_AR600x_BT_CSR)
2364 sbcb_cmd.btcoexCoLocatedBTdev = 2;
2365 #elif defined(CONFIG_AR600x_BT_AR3001)
2366 sbcb_cmd.btcoexCoLocatedBTdev = 3;
2368 #error Unsupported Bluetooth Type
2369 #endif /* Collocated Bluetooth Type */
2371 if ((wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd)) != 0) {
2372 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n"));
2376 /* Configure the type of BT collocated with WLAN */
2377 memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD));
2378 #ifdef CONFIG_AR600x_DUAL_ANTENNA
2379 sbfa_cmd.btcoexFeAntType = 2;
2380 #elif defined(CONFIG_AR600x_SINGLE_ANTENNA)
2381 sbfa_cmd.btcoexFeAntType = 1;
2383 #error Unsupported Front-End Antenna Configuration
2384 #endif /* AR600x Front-End Antenna Configuration */
2386 if ((wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd)) != 0) {
2387 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n"));
2390 #endif /* ENABLE_COEXISTENCE */
2392 #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
2393 if ((wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
2394 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power save fail event policy\n"));
2399 #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP
2400 if ((wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
2401 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set barker preamble policy\n"));
2406 if ((wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) != 0) {
2407 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set keep alive interval\n"));
2411 #if WLAN_CONFIG_DISABLE_11N
2413 WMI_SET_HT_CAP_CMD htCap;
2415 memset(&htCap, 0, sizeof(WMI_SET_HT_CAP_CMD));
2417 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2418 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2423 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2424 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2428 #endif /* WLAN_CONFIG_DISABLE_11N */
2430 #ifdef ATH6K_CONFIG_OTA_MODE
2431 if ((wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER)) != 0) {
2432 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power mode \n"));
2437 if ((wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT)) != 0) {
2438 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set disconnect timeout \n"));
2442 #if WLAN_CONFIG_DISABLE_TX_BURSTING
2443 if ((wmi_set_wmm_txop(ar->arWmi, WMI_TXOP_DISABLED)) != 0) {
2444 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set txop bursting \n"));
2452 /* This function does one time initialization for the lifetime of the device */
2453 int ar6000_init(struct net_device *dev)
2455 struct ar6_softc *ar;
2461 if((ar = ar6k_priv(dev)) == NULL)
2466 if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) {
2468 ar6000_update_bdaddr(ar);
2470 if (enablerssicompensation) {
2471 ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType);
2472 read_rssi_compensation_param(ar);
2473 for (i=-95; i<=0; i++) {
2474 rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i);
2482 /* Do we need to finish the BMI phase */
2483 if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) &&
2484 (BMIDone(ar->arHifDevice) != 0))
2487 goto ar6000_init_done;
2493 if (ar->arVersion.host_ver != ar->arVersion.target_ver) {
2494 A_PRINTF("WARNING: Host version 0x%x does not match Target "
2496 ar->arVersion.host_ver, ar->arVersion.target_ver);
2500 /* Indicate that WMI is enabled (although not ready yet) */
2501 ar->arWmiEnabled = true;
2502 if ((ar->arWmi = wmi_init((void *) ar)) == NULL)
2504 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__));
2506 goto ar6000_init_done;
2509 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__,
2510 (unsigned long) ar->arWmi));
2514 struct htc_service_connect_req connect;
2516 /* the reason we have to wait for the target here is that the driver layer
2517 * has to init BMI in order to set the host block size,
2519 status = HTCWaitTarget(ar->arHtcTarget);
2525 A_MEMZERO(&connect,sizeof(connect));
2526 /* meta data is unused for now */
2527 connect.pMetaData = NULL;
2528 connect.MetaDataLength = 0;
2529 /* these fields are the same for all service endpoints */
2530 connect.EpCallbacks.pContext = ar;
2531 connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete;
2532 connect.EpCallbacks.EpRecv = ar6000_rx;
2533 connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill;
2534 connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full;
2535 /* set the max queue depth so that our ar6000_tx_queue_full handler gets called.
2536 * Linux has the peculiarity of not providing flow control between the
2537 * NIC and the network stack. There is no API to indicate that a TX packet
2538 * was sent which could provide some back pressure to the network stack.
2539 * Under linux you would have to wait till the network stack consumed all sk_buffs
2540 * before any back-flow kicked in. Which isn't very friendly.
2541 * So we have to manage this ourselves */
2542 connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
2543 connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */
2544 if (0 == connect.EpCallbacks.RecvRefillWaterMark) {
2545 connect.EpCallbacks.RecvRefillWaterMark++;
2547 /* connect to control service */
2548 connect.ServiceID = WMI_CONTROL_SVC;
2549 status = ar6000_connectservice(ar,
2556 connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING;
2557 /* limit the HTC message size on the send path, although we can receive A-MSDU frames of
2558 * 4K, we will only send ethernet-sized (802.3) frames on the send path. */
2559 connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH;
2561 /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold
2562 * mechanism for larger packets */
2563 connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE;
2564 connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf;
2566 /* for the remaining data services set the connection flag to reduce dribbling,
2567 * if configured to do so */
2568 if (reduce_credit_dribble) {
2569 connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE;
2570 /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value
2572 connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2573 connect.ConnectionFlags |=
2574 ((u16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2576 /* connect to best-effort service */
2577 connect.ServiceID = WMI_DATA_BE_SVC;
2579 status = ar6000_connectservice(ar,
2586 /* connect to back-ground
2587 * map this to WMI LOW_PRI */
2588 connect.ServiceID = WMI_DATA_BK_SVC;
2589 status = ar6000_connectservice(ar,
2596 /* connect to Video service, map this to
2598 connect.ServiceID = WMI_DATA_VI_SVC;
2599 status = ar6000_connectservice(ar,
2606 /* connect to VO service, this is currently not
2607 * mapped to a WMI priority stream due to historical reasons.
2608 * WMI originally defined 3 priorities over 3 mailboxes
2609 * We can change this when WMI is reworked so that priorities are not
2610 * dependent on mailboxes */
2611 connect.ServiceID = WMI_DATA_VO_SVC;
2612 status = ar6000_connectservice(ar,
2619 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0);
2620 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0);
2621 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0);
2622 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0);
2624 /* setup access class priority mappings */
2625 ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */
2626 ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */
2627 ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */
2628 ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */
2630 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2631 if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) {
2632 struct hci_transport_misc_handles hciHandles;
2634 hciHandles.netDevice = ar->arNetDev;
2635 hciHandles.hifDevice = ar->arHifDevice;
2636 hciHandles.htcHandle = ar->arHtcTarget;
2637 status = (int)(ar6kHciTransCallbacks.setupTransport(&hciHandles));
2642 status = ar6000_setup_hci(ar);
2650 goto ar6000_init_done;
2654 * give our connected endpoints some buffers
2657 ar6000_rx_refill(ar, ar->arControlEp);
2658 ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE));
2661 * We will post the receive buffers only for SPE or endpoint ping testing so we are
2662 * making it conditional on the 'bypasswmi' flag.
2665 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK));
2666 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI));
2667 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO));
2670 /* allocate some buffers that handle larger AMSDU frames */
2671 ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS);
2673 /* setup credit distribution */
2674 ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo);
2676 /* Since cookies are used for HTC transports, they should be */
2677 /* initialized prior to enabling HTC. */
2678 ar6000_cookie_init(ar);
2681 status = HTCStart(ar->arHtcTarget);
2684 if (ar->arWmiEnabled == true) {
2685 wmi_shutdown(ar->arWmi);
2686 ar->arWmiEnabled = false;
2689 ar6000_cookie_cleanup(ar);
2691 goto ar6000_init_done;
2695 /* Wait for Wmi event to be ready */
2696 timeleft = wait_event_interruptible_timeout(arEvent,
2697 (ar->arWmiReady == true), wmitimeout * HZ);
2699 if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) {
2700 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver));
2701 #ifndef ATH6K_SKIP_ABI_VERSION_CHECK
2703 goto ar6000_init_done;
2704 #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */
2707 if(!timeleft || signal_pending(current))
2709 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n"));
2711 goto ar6000_init_done;
2714 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__));
2716 /* Communicate the wmi protocol verision to the target */
2717 if ((ar6000_set_host_app_area(ar)) != 0) {
2718 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n"));
2720 ar6000_target_config_wlan_params(ar);
2723 ar->arNumDataEndPts = 1;
2726 /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise
2727 * the data path through a raw socket is disabled */
2728 dev->dev_addr[0] = 0x00;
2729 dev->dev_addr[1] = 0x01;
2730 dev->dev_addr[2] = 0x02;
2731 dev->dev_addr[3] = 0xAA;
2732 dev->dev_addr[4] = 0xBB;
2733 dev->dev_addr[5] = 0xCC;
2745 ar6000_bitrate_rx(void *devt, s32 rateKbps)
2747 struct ar6_softc *ar = (struct ar6_softc *)devt;
2749 ar->arBitRate = rateKbps;
2754 ar6000_ratemask_rx(void *devt, u32 ratemask)
2756 struct ar6_softc *ar = (struct ar6_softc *)devt;
2758 ar->arRateMask = ratemask;
2763 ar6000_txPwr_rx(void *devt, u8 txPwr)
2765 struct ar6_softc *ar = (struct ar6_softc *)devt;
2767 ar->arTxPwr = txPwr;
2773 ar6000_channelList_rx(void *devt, s8 numChan, u16 *chanList)
2775 struct ar6_softc *ar = (struct ar6_softc *)devt;
2777 memcpy(ar->arChannelList, chanList, numChan * sizeof (u16));
2778 ar->arNumChannels = numChan;
2783 u8 ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, u32 *mapNo)
2785 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2787 ATH_MAC_HDR *macHdr;
2791 datap = A_NETBUF_DATA(skb);
2792 macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR));
2793 if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) {
2798 for (i = 0; i < ar->arNodeNum; i ++) {
2799 if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) {
2801 ar->arNodeMap[i].txPending ++;
2802 return ar->arNodeMap[i].epId;
2805 if ((eptMap == -1) && !ar->arNodeMap[i].txPending) {
2811 eptMap = ar->arNodeNum;
2813 A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM);
2816 memcpy(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN);
2818 for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) {
2819 if (!ar->arTxPending[i]) {
2820 ar->arNodeMap[eptMap].epId = i;
2823 // No free endpoint is available, start redistribution on the inuse endpoints.
2824 if (i == ENDPOINT_5) {
2825 ar->arNodeMap[eptMap].epId = ar->arNexEpId;
2827 if (ar->arNexEpId > ENDPOINT_5) {
2828 ar->arNexEpId = ENDPOINT_2;
2833 (*mapNo) = eptMap + 1;
2834 ar->arNodeMap[eptMap].txPending ++;
2836 return ar->arNodeMap[eptMap].epId;
2840 static void ar6000_dump_skb(struct sk_buff *skb)
2843 for (ch = A_NETBUF_DATA(skb);
2844 (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) +
2845 A_NETBUF_LEN(skb)); ch++)
2847 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch));
2849 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n"));
2853 #ifdef HTC_TEST_SEND_PKTS
2854 static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb);
2858 ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
2860 #define AC_NOT_MAPPED 99
2861 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2862 u8 ac = AC_NOT_MAPPED;
2863 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
2866 struct ar_cookie *cookie;
2867 bool checkAdHocPsMapping = false,bMoreData = false;
2868 HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG;
2869 u8 dot11Hdr = processDot11Hdr;
2871 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
2875 #endif /* CONFIG_PM */
2877 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n",
2878 (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb),
2879 A_NETBUF_LEN(skb)));
2881 /* If target is not associated */
2882 if( (!ar->arConnected && !bypasswmi)
2883 #ifdef CONFIG_HOST_TCMD_SUPPORT
2884 /* TCMD doesnt support any data, free the buf and return */
2885 || (ar->arTargetMode == AR6000_TCMD_MODE)
2894 if (ar->arWmiReady == false && bypasswmi == 0) {
2898 #ifdef BLOCK_TX_PATH_FLAG
2902 #endif /* BLOCK_TX_PATH_FLAG */
2904 /* AP mode Power save processing */
2905 /* If the dst STA is in sleep state, queue the pkt in its PS queue */
2907 if (ar->arNetworkType == AP_NETWORK) {
2908 ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
2911 /* If the dstMac is a Multicast address & atleast one of the
2912 * associated STA is in PS mode, then queue the pkt to the
2915 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
2920 for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) {
2921 if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) {
2927 /* If this transmit is not because of a Dtim Expiry q it */
2928 if (ar->DTIMExpired == false) {
2929 bool isMcastqEmpty = false;
2931 A_MUTEX_LOCK(&ar->mcastpsqLock);
2932 isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
2933 A_NETBUF_ENQUEUE(&ar->mcastpsq, skb);
2934 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
2936 /* If this is the first Mcast pkt getting queued
2937 * indicate to the target to set the BitmapControl LSB
2940 if (isMcastqEmpty) {
2941 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1);
2945 /* This transmit is because of Dtim expiry. Determine if
2946 * MoreData bit has to be set.
2948 A_MUTEX_LOCK(&ar->mcastpsqLock);
2949 if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
2952 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
2956 conn = ieee80211_find_conn(ar, datap->dstMac);
2958 if (STA_IS_PWR_SLEEP(conn)) {
2959 /* If this transmit is not because of a PsPoll q it*/
2960 if (!STA_IS_PS_POLLED(conn)) {
2961 bool isPsqEmpty = false;
2962 /* Queue the frames if the STA is sleeping */
2963 A_MUTEX_LOCK(&conn->psqLock);
2964 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
2965 A_NETBUF_ENQUEUE(&conn->psq, skb);
2966 A_MUTEX_UNLOCK(&conn->psqLock);
2968 /* If this is the first pkt getting queued
2969 * for this STA, update the PVB for this STA
2972 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1);
2977 /* This tx is because of a PsPoll. Determine if
2978 * MoreData bit has to be set
2980 A_MUTEX_LOCK(&conn->psqLock);
2981 if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
2984 A_MUTEX_UNLOCK(&conn->psqLock);
2989 /* non existent STA. drop the frame */
2996 if (ar->arWmiEnabled) {
2999 u8 csum=skb->ip_summed;
3000 if(csumOffload && (csum==CHECKSUM_PARTIAL)){
3001 csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
3002 sizeof(ATH_LLC_SNAP_HDR));
3003 csumDest=skb->csum_offset+csumStart;
3005 if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) {
3006 struct sk_buff *newbuf;
3009 * We really should have gotten enough headroom but sometimes
3010 * we still get packets with not enough headroom. Copy the packet.
3012 len = A_NETBUF_LEN(skb);
3013 newbuf = A_NETBUF_ALLOC(len);
3014 if (newbuf == NULL) {
3017 A_NETBUF_PUT(newbuf, len);
3018 memcpy(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len);
3021 /* fall through and assemble header */
3025 if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != 0) {
3026 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n"));
3030 if (wmi_dix_2_dot3(ar->arWmi, skb) != 0) {
3031 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n"));
3035 if(csumOffload && (csum ==CHECKSUM_PARTIAL)){
3036 WMI_TX_META_V2 metaV2;
3037 metaV2.csumStart =csumStart;
3038 metaV2.csumDest = csumDest;
3039 metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/
3040 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,
3041 WMI_META_VERSION_2,&metaV2) != 0) {
3042 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3049 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != 0) {
3050 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3056 if ((ar->arNetworkType == ADHOC_NETWORK) &&
3057 ar->arIbssPsEnable && ar->arConnected) {
3058 /* flag to check adhoc mapping once we take the lock below: */
3059 checkAdHocPsMapping = true;
3062 /* get the stream mapping */
3063 ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled);
3067 EPPING_HEADER *eppingHdr;
3069 eppingHdr = A_NETBUF_DATA(skb);
3071 if (IS_EPPING_PACKET(eppingHdr)) {
3072 /* the stream ID is mapped to an access class */
3073 ac = eppingHdr->StreamNo_h;
3074 /* some EPPING packets cannot be dropped no matter what access class it was
3075 * sent on. We can change the packet tag to guarantee it will not get dropped */
3076 if (IS_EPING_PACKET_NO_DROP(eppingHdr)) {
3077 htc_tag = AR6K_CONTROL_PKT_TAG;
3080 if (ac == HCI_TRANSPORT_STREAM_NUM) {
3081 /* pass this to HCI */
3082 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
3083 if (!hci_test_send(ar,skb)) {
3087 /* set AC to discard this skb */
3090 /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition
3091 * of the HTC header will mis-align the start of the HTC frame, so we add some
3092 * padding which will be stripped off in the target */
3093 if (EPPING_ALIGNMENT_PAD > 0) {
3094 A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD);
3099 /* not a ping packet, drop it */
3106 /* did we succeed ? */
3107 if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) {
3108 /* cleanup and exit */
3110 AR6000_STAT_INC(ar, tx_dropped);
3111 AR6000_STAT_INC(ar, tx_aborted_errors);
3117 /* take the lock to protect driver data */
3118 AR6000_SPIN_LOCK(&ar->arLock, 0);
3122 if (checkAdHocPsMapping) {
3123 eid = ar6000_ibss_map_epid(skb, dev, &mapNo);
3125 eid = arAc2EndpointID (ar, ac);
3127 /* validate that the endpoint is connected */
3128 if (eid == 0 || eid == ENDPOINT_UNUSED ) {
3129 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid));
3132 /* allocate resource for this packet */
3133 cookie = ar6000_alloc_cookie(ar);
3135 if (cookie != NULL) {
3136 /* update counts while the lock is held */
3137 ar->arTxPending[eid]++;
3138 ar->arTotalTxDataPending++;
3143 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3145 if (cookie != NULL) {
3146 cookie->arc_bp[0] = (unsigned long)skb;
3147 cookie->arc_bp[1] = mapNo;
3148 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3156 if (debugdriver >= 3) {
3157 ar6000_dump_skb(skb);
3160 #ifdef HTC_TEST_SEND_PKTS
3161 DoHTCSendPktsTest(ar,mapNo,eid,skb);
3163 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3164 * the ar6000_tx_complete callback */
3165 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3167 /* no packet to send, cleanup */
3169 AR6000_STAT_INC(ar, tx_dropped);
3170 AR6000_STAT_INC(ar, tx_aborted_errors);
3177 ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev)
3179 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
3180 struct ar_cookie *cookie;
3181 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
3184 AR6000_SPIN_LOCK(&ar->arLock, 0);
3186 /* For now we send ACL on BE endpoint: We can also have a dedicated EP */
3187 eid = arAc2EndpointID (ar, 0);
3188 /* allocate resource for this packet */
3189 cookie = ar6000_alloc_cookie(ar);
3191 if (cookie != NULL) {
3192 /* update counts while the lock is held */
3193 ar->arTxPending[eid]++;
3194 ar->arTotalTxDataPending++;
3198 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3200 if (cookie != NULL) {
3201 cookie->arc_bp[0] = (unsigned long)skb;
3202 cookie->arc_bp[1] = 0;
3203 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3210 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3211 * the ar6000_tx_complete callback */
3212 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3214 /* no packet to send, cleanup */
3216 AR6000_STAT_INC(ar, tx_dropped);
3217 AR6000_STAT_INC(ar, tx_aborted_errors);
3223 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3225 tvsub(register struct timeval *out, register struct timeval *in)
3227 if((out->tv_usec -= in->tv_usec) < 0) {
3229 out->tv_usec += 1000000;
3231 out->tv_sec -= in->tv_sec;
3235 applyAPTCHeuristics(struct ar6_softc *ar)
3243 AR6000_SPIN_LOCK(&ar->arLock, 0);
3245 if ((enableAPTCHeuristics) && (!aptcTR.timerScheduled)) {
3246 do_gettimeofday(&ts);
3247 tvsub(&ts, &aptcTR.samplingTS);
3248 duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */
3249 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
3251 if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) {
3252 /* Initialize the time stamp and byte count */
3253 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
3254 do_gettimeofday(&aptcTR.samplingTS);
3256 /* Calculate and decide based on throughput thresholds */
3257 throughput = ((numbytes * 8) / duration);
3258 if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) {
3259 /* Disable Sleep and schedule a timer */
3260 A_ASSERT(ar->arWmiReady == true);
3261 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3262 status = wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER);
3263 AR6000_SPIN_LOCK(&ar->arLock, 0);
3264 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
3265 aptcTR.timerScheduled = true;
3270 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3272 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3274 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket)
3276 struct ar6_softc *ar = (struct ar6_softc *)Context;
3277 HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP;
3278 bool stopNet = false;
3279 HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket);
3286 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3287 /* don't drop special control packets */
3291 accessClass = arEndpoint2Ac(ar,Endpoint);
3292 /* for endpoint ping testing drop Best Effort and Background */
3293 if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) {
3294 action = HTC_SEND_FULL_DROP;
3297 /* keep but stop the netqueues */
3303 if (Endpoint == ar->arControlEp) {
3304 /* under normal WMI if this is getting full, then something is running rampant
3305 * the host should not be exhausting the WMI queue with too many commands
3306 * the only exception to this is during testing using endpointping */
3307 AR6000_SPIN_LOCK(&ar->arLock, 0);
3308 /* set flag to handle subsequent messages */
3309 ar->arWMIControlEpFull = true;
3310 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3311 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n"));
3312 /* no need to stop the network */
3317 /* if we get here, we are dealing with data endpoints getting full */
3319 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3320 /* don't drop control packets issued on ANY data endpoint */
3324 if (ar->arNetworkType == ADHOC_NETWORK) {
3325 /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to
3326 * continue, however we should stop the network */
3330 /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest
3332 if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri &&
3333 ar->arCookieCount <= MAX_HI_COOKIE_NUM) {
3334 /* this stream's priority is less than the highest active priority, we
3335 * give preference to the highest priority stream by directing
3336 * HTC to drop the packet that overflowed */
3337 action = HTC_SEND_FULL_DROP;
3338 /* since we are dropping packets, no need to stop the network */
3346 AR6000_SPIN_LOCK(&ar->arLock, 0);
3347 ar->arNetQueueStopped = true;
3348 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3349 /* one of the data endpoints queues is getting full..need to stop network stack
3350 * the queue will resume in ar6000_tx_complete() */
3351 netif_stop_queue(ar->arNetDev);
3359 ar6000_tx_complete(void *Context, struct htc_packet_queue *pPacketQueue)
3361 struct ar6_softc *ar = (struct ar6_softc *)Context;
3364 struct ar_cookie * ar_cookie;
3365 HTC_ENDPOINT_ID eid;
3366 bool wakeEvent = false;
3367 struct sk_buff_head skb_queue;
3368 struct htc_packet *pPacket;
3369 struct sk_buff *pktSkb;
3370 bool flushing = false;
3372 skb_queue_head_init(&skb_queue);
3374 /* lock the driver as we update internal state */
3375 AR6000_SPIN_LOCK(&ar->arLock, 0);
3377 /* reap completed packets */
3378 while (!HTC_QUEUE_EMPTY(pPacketQueue)) {
3380 pPacket = HTC_PACKET_DEQUEUE(pPacketQueue);
3382 ar_cookie = (struct ar_cookie *)pPacket->pPktContext;
3383 A_ASSERT(ar_cookie);
3385 status = pPacket->Status;
3386 pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0];
3387 eid = pPacket->Endpoint;
3388 mapNo = ar_cookie->arc_bp[1];
3391 A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb));
3393 /* add this to the list, use faster non-lock API */
3394 __skb_queue_tail(&skb_queue,pktSkb);
3397 A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb));
3400 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%lx data=0x%lx len=0x%x eid=%d ",
3401 (unsigned long)pktSkb, (unsigned long)pPacket->pBuffer,
3402 pPacket->ActualLength,
3405 ar->arTxPending[eid]--;
3407 if ((eid != ar->arControlEp) || bypasswmi) {
3408 ar->arTotalTxDataPending--;
3411 if (eid == ar->arControlEp)
3413 if (ar->arWMIControlEpFull) {
3414 /* since this packet completed, the WMI EP is no longer full */
3415 ar->arWMIControlEpFull = false;
3418 if (ar->arTxPending[eid] == 0) {
3424 if (status == A_ECANCELED) {
3425 /* a packet was flushed */
3428 AR6000_STAT_INC(ar, tx_errors);
3429 if (status != A_NO_RESOURCE) {
3430 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__,
3434 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n"));
3436 AR6000_STAT_INC(ar, tx_packets);
3437 ar->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb);
3438 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3439 aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb);
3440 applyAPTCHeuristics(ar);
3441 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3444 // TODO this needs to be looked at
3445 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable
3446 && (eid != ar->arControlEp) && mapNo)
3449 ar->arNodeMap[mapNo].txPending --;
3451 if (!ar->arNodeMap[mapNo].txPending && (mapNo == (ar->arNodeNum - 1))) {
3453 for (i = ar->arNodeNum; i > 0; i --) {
3454 if (!ar->arNodeMap[i - 1].txPending) {
3455 A_MEMZERO(&ar->arNodeMap[i - 1], sizeof(struct ar_node_mapping));
3464 ar6000_free_cookie(ar, ar_cookie);
3466 if (ar->arNetQueueStopped) {
3467 ar->arNetQueueStopped = false;
3471 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3473 /* lock is released, we can freely call other kernel APIs */
3475 /* free all skbs in our local list */
3476 while (!skb_queue_empty(&skb_queue)) {
3477 /* use non-lock version */
3478 pktSkb = __skb_dequeue(&skb_queue);
3479 A_NETBUF_FREE(pktSkb);
3482 if ((ar->arConnected == true) || bypasswmi) {
3484 /* don't wake the queue if we are flushing, other wise it will just
3485 * keep queueing packets, which will keep failing */
3486 netif_wake_queue(ar->arNetDev);
3497 ieee80211_find_conn(struct ar6_softc *ar, u8 *node_addr)
3502 switch(ar->arNetworkType) {
3504 max_conn = AP_MAX_NUM_STA;
3511 for (i = 0; i < max_conn; i++) {
3512 if (IEEE80211_ADDR_EQ(node_addr, ar->sta_list[i].mac)) {
3513 conn = &ar->sta_list[i];
3521 sta_t *ieee80211_find_conn_for_aid(struct ar6_softc *ar, u8 aid)
3526 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
3527 if (ar->sta_list[ctr].aid == aid) {
3528 conn = &ar->sta_list[ctr];
3536 * Receive event handler. This is called by HTC when a packet is received
3540 ar6000_rx(void *Context, struct htc_packet *pPacket)
3542 struct ar6_softc *ar = (struct ar6_softc *)Context;
3543 struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext;
3545 u8 containsDot11Hdr = 0;
3546 int status = pPacket->Status;
3547 HTC_ENDPOINT_ID ept = pPacket->Endpoint;
3549 A_ASSERT((status) ||
3550 (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN)));
3552 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx ar=0x%lx eid=%d, skb=0x%lx, data=0x%lx, len=0x%x status:%d",
3553 (unsigned long)ar, ept, (unsigned long)skb, (unsigned long)pPacket->pBuffer,
3554 pPacket->ActualLength, status));
3556 if (status != A_ECANCELED) {
3557 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status));
3561 /* take lock to protect buffer counts
3562 * and adaptive power throughput state */
3563 AR6000_SPIN_LOCK(&ar->arLock, 0);
3566 AR6000_STAT_INC(ar, rx_packets);
3567 ar->arNetStats.rx_bytes += pPacket->ActualLength;
3568 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3569 aptcTR.bytesReceived += a_netbuf_to_len(skb);
3570 applyAPTCHeuristics(ar);
3571 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3573 A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN);
3574 A_NETBUF_PULL(skb, HTC_HEADER_LEN);
3577 if (debugdriver >= 2) {
3578 ar6000_dump_skb(skb);
3583 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3585 skb->dev = ar->arNetDev;
3587 AR6000_STAT_INC(ar, rx_errors);
3589 } else if (ar->arWmiEnabled == true) {
3590 if (ept == ar->arControlEp) {
3592 * this is a wmi control msg
3595 ar6000_check_wow_status(ar, skb, true);
3596 #endif /* CONFIG_PM */
3597 wmi_control_rx(ar->arWmi, skb);
3599 WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb);
3604 * This check can be removed if after a while we do not
3605 * see the warning. For now we leave it to ensure
3606 * we drop these frames accordingly in case the
3607 * target generates them for some reason. These
3608 * were used for an internal PAL but that's not
3609 * used or supported anymore. These frames should
3610 * not come up from the target.
3612 if (WARN_ON(WMI_DATA_HDR_GET_DATA_TYPE(dhdr) ==
3613 WMI_DATA_HDR_DATA_TYPE_ACL)) {
3614 AR6000_STAT_INC(ar, rx_errors);
3620 ar6000_check_wow_status(ar, NULL, false);
3621 #endif /* CONFIG_PM */
3623 * this is a wmi data packet
3627 if (processDot11Hdr) {
3628 minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR);
3630 minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) +
3631 sizeof(ATH_LLC_SNAP_HDR);
3634 /* In the case of AP mode we may receive NULL data frames
3635 * that do not have LLC hdr. They are 16 bytes in size.
3636 * Allow these frames in the AP mode.
3637 * ACL data frames don't follow ethernet frame bounds for
3640 if (ar->arNetworkType != AP_NETWORK &&
3641 ((pPacket->ActualLength < minHdrLen) ||
3642 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)))
3645 * packet is too short or too long
3647 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n"));
3648 AR6000_STAT_INC(ar, rx_errors);
3649 AR6000_STAT_INC(ar, rx_length_errors);
3656 /* Access RSSI values here */
3657 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n",
3658 ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi));
3660 /* Get the Power save state of the STA */
3661 if (ar->arNetworkType == AP_NETWORK) {
3663 u8 psState=0,prevPsState;
3664 ATH_MAC_HDR *datap=NULL;
3667 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3669 psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info
3670 >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK;
3672 offset = sizeof(WMI_DATA_HDR);
3674 switch (meta_type) {
3677 case WMI_META_VERSION_1:
3678 offset += sizeof(WMI_RX_META_V1);
3680 case WMI_META_VERSION_2:
3681 offset += sizeof(WMI_RX_META_V2);
3687 datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset);
3688 conn = ieee80211_find_conn(ar, datap->srcMac);
3691 /* if there is a change in PS state of the STA,
3692 * take appropriate steps.
3693 * 1. If Sleep-->Awake, flush the psq for the STA
3694 * Clear the PVB for the STA.
3695 * 2. If Awake-->Sleep, Starting queueing frames
3698 prevPsState = STA_IS_PWR_SLEEP(conn);
3700 STA_SET_PWR_SLEEP(conn);
3702 STA_CLR_PWR_SLEEP(conn);
3705 if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) {
3707 if (!STA_IS_PWR_SLEEP(conn)) {
3709 A_MUTEX_LOCK(&conn->psqLock);
3710 while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3711 struct sk_buff *skb=NULL;
3713 skb = A_NETBUF_DEQUEUE(&conn->psq);
3714 A_MUTEX_UNLOCK(&conn->psqLock);
3715 ar6000_data_tx(skb,ar->arNetDev);
3716 A_MUTEX_LOCK(&conn->psqLock);
3718 A_MUTEX_UNLOCK(&conn->psqLock);
3719 /* Clear the PVB for this STA */
3720 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
3724 /* This frame is from a STA that is not associated*/
3728 /* Drop NULL data frames here */
3729 if((pPacket->ActualLength < minHdrLen) ||
3730 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) {
3736 is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr) ? true : false;
3737 tid = WMI_DATA_HDR_GET_UP(dhdr);
3738 seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr);
3739 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3740 containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr);
3742 wmi_data_hdr_remove(ar->arWmi, skb);
3744 switch (meta_type) {
3745 case WMI_META_VERSION_1:
3747 WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb);
3748 A_PRINTF("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags);
3749 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1));
3752 case WMI_META_VERSION_2:
3754 WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb);
3755 if(pMeta->csumFlags & 0x1){
3756 skb->ip_summed=CHECKSUM_COMPLETE;
3757 skb->csum=(pMeta->csum);
3759 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2));
3766 A_ASSERT(status == 0);
3768 /* NWF: print the 802.11 hdr bytes */
3769 if(containsDot11Hdr) {
3770 status = wmi_dot11_hdr_remove(ar->arWmi,skb);
3771 } else if(!is_amsdu) {
3772 status = wmi_dot3_2_dix(skb);
3776 /* Drop frames that could not be processed (lack of memory, etc.) */
3781 if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) {
3782 if (ar->arNetworkType == AP_NETWORK) {
3783 struct sk_buff *skb1 = NULL;
3786 datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
3787 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
3788 /* Bcast/Mcast frames should be sent to the OS
3789 * stack as well as on the air.
3791 skb1 = skb_copy(skb,GFP_ATOMIC);
3793 /* Search for a connected STA with dstMac as
3794 * the Mac address. If found send the frame to
3795 * it on the air else send the frame up the
3799 conn = ieee80211_find_conn(ar, datap->dstMac);
3801 if (conn && ar->intra_bss) {
3804 } else if(conn && !ar->intra_bss) {
3810 ar6000_data_tx(skb1, ar->arNetDev);
3814 aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb);
3815 ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb);
3819 if (EPPING_ALIGNMENT_PAD > 0) {
3820 A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD);
3822 ar6000_deliver_frames_to_nw_stack((void *)ar->arNetDev, (void *)skb);
3831 ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf)
3833 struct sk_buff *skb = (struct sk_buff *)osbuf;
3837 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3839 ar6000_check_wow_status((struct ar6_softc *)ar6k_priv(dev), skb, false);
3840 #endif /* CONFIG_PM */
3841 skb->protocol = eth_type_trans(skb, skb->dev);
3843 * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ)
3844 * or tasklet use the netif_rx to deliver the packet to the stack
3845 * netif_rx will queue the packet onto the receive queue and mark
3846 * the softirq thread has a pending action to complete. Kernel will
3847 * schedule the softIrq kernel thread after processing the DSR.
3849 * If this routine is called on a process context, use netif_rx_ni
3850 * which will schedle the softIrq kernel thread after queuing the packet.
3852 if (in_interrupt()) {
3865 ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf)
3867 struct sk_buff *skb = (struct sk_buff *)osbuf;
3871 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3872 skb->protocol = htons(ETH_P_CONTROL);
3882 ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint)
3884 struct ar6_softc *ar = (struct ar6_softc *)Context;
3887 int buffersToRefill;
3888 struct htc_packet *pPacket;
3889 struct htc_packet_queue queue;
3891 buffersToRefill = (int)AR6000_MAX_RX_BUFFERS -
3892 HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint);
3894 if (buffersToRefill <= 0) {
3895 /* fast return, nothing to fill */
3899 INIT_HTC_PACKET_QUEUE(&queue);
3901 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n",
3902 buffersToRefill, Endpoint));
3904 for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) {
3905 osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE);
3906 if (NULL == osBuf) {
3909 /* the HTC packet wrapper is at the head of the reserved area
3911 pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
3912 /* set re-fill info */
3913 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint);
3915 HTC_PACKET_ENQUEUE(&queue,pPacket);
3918 if (!HTC_QUEUE_EMPTY(&queue)) {
3920 HTCAddReceivePktMultiple(ar->arHtcTarget, &queue);
3925 /* clean up our amsdu buffer list */
3926 static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar)
3928 struct htc_packet *pPacket;
3931 /* empty AMSDU buffer queue and free OS bufs */
3934 AR6000_SPIN_LOCK(&ar->arLock, 0);
3935 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
3936 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3938 if (NULL == pPacket) {
3942 osBuf = pPacket->pPktContext;
3943 if (NULL == osBuf) {
3948 A_NETBUF_FREE(osBuf);
3954 /* refill the amsdu buffer list */
3955 static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count)
3957 struct htc_packet *pPacket;
3961 osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE);
3962 if (NULL == osBuf) {
3965 /* the HTC packet wrapper is at the head of the reserved area
3967 pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
3968 /* set re-fill info */
3969 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0);
3971 AR6000_SPIN_LOCK(&ar->arLock, 0);
3972 /* put it in the list */
3973 HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket);
3974 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3980 /* callback to allocate a large receive buffer for a pending packet. This function is called when
3981 * an HTC packet arrives whose length exceeds a threshold value
3983 * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to
3984 * keep the allocation size the same to optimize cached-slab allocations.
3987 static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length)
3989 struct htc_packet *pPacket = NULL;
3990 struct ar6_softc *ar = (struct ar6_softc *)Context;
3991 int refillCount = 0;
3993 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length));
3997 if (Length <= AR6000_BUFFER_SIZE) {
3998 /* shouldn't be getting called on normal sized packets */
4003 if (Length > AR6000_AMSDU_BUFFER_SIZE) {
4008 AR6000_SPIN_LOCK(&ar->arLock, 0);
4009 /* allocate a packet from the list */
4010 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
4011 /* see if we need to refill again */
4012 refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue);
4013 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4015 if (NULL == pPacket) {
4018 /* set actual endpoint ID */
4019 pPacket->Endpoint = Endpoint;
4023 if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) {
4024 ar6000_refill_amsdu_rxbufs(ar,refillCount);
4031 ar6000_set_multicast_list(struct net_device *dev)
4033 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: Multicast filter not supported\n"));
4036 static struct net_device_stats *
4037 ar6000_get_stats(struct net_device *dev)
4039 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
4040 return &ar->arNetStats;
4044 ar6000_ready_event(void *devt, u8 *datap, u8 phyCap, u32 sw_ver, u32 abi_ver)
4046 struct ar6_softc *ar = (struct ar6_softc *)devt;
4047 struct net_device *dev = ar->arNetDev;
4049 memcpy(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN);
4050 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
4051 dev->dev_addr[0], dev->dev_addr[1],
4052 dev->dev_addr[2], dev->dev_addr[3],
4053 dev->dev_addr[4], dev->dev_addr[5]));
4055 ar->arPhyCapability = phyCap;
4056 ar->arVersion.wlan_ver = sw_ver;
4057 ar->arVersion.abi_ver = abi_ver;
4059 /* Indicate to the waiting thread that the ready event was received */
4060 ar->arWmiReady = true;
4064 void ar6000_install_static_wep_keys(struct ar6_softc *ar)
4069 for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) {
4070 if (ar->arWepKeyList[index].arKeyLen) {
4071 keyUsage = GROUP_USAGE;
4072 if (index == ar->arDefTxKeyIndex) {
4073 keyUsage |= TX_USAGE;
4075 wmi_addKey_cmd(ar->arWmi,
4079 ar->arWepKeyList[index].arKeyLen,
4081 ar->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL,
4088 add_new_sta(struct ar6_softc *ar, u8 *mac, u16 aid, u8 *wpaie,
4089 u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
4093 memcpy(ar->sta_list[free_slot].mac, mac, ATH_MAC_LEN);
4094 memcpy(ar->sta_list[free_slot].wpa_ie, wpaie, ielen);
4095 ar->sta_list[free_slot].aid = aid;
4096 ar->sta_list[free_slot].keymgmt = keymgmt;
4097 ar->sta_list[free_slot].ucipher = ucipher;
4098 ar->sta_list[free_slot].auth = auth;
4099 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
4100 ar->arAPStats.sta[free_slot].aid = aid;
4104 ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid,
4105 u16 listenInterval, u16 beaconInterval,
4106 NETWORK_TYPE networkType, u8 beaconIeLen,
4107 u8 assocReqLen, u8 assocRespLen,
4110 union iwreq_data wrqu;
4111 int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos;
4112 static const char *tag1 = "ASSOCINFO(ReqIEs=";
4113 static const char *tag2 = "ASSOCRESPIE=";
4114 static const char *beaconIetag = "BEACONIE=";
4115 char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1];
4118 unsigned long flags;
4119 struct ieee80211req_key *ik;
4120 CRYPTO_TYPE keyType = NONE_CRYPT;
4122 if(ar->arNetworkType & AP_NETWORK) {
4123 struct net_device *dev = ar->arNetDev;
4124 if(memcmp(dev->dev_addr, bssid, ATH_MAC_LEN)==0) {
4125 ar->arACS = channel;
4126 ik = &ar->ap_mode_bkey;
4128 switch(ar->arAuthMode) {
4130 if(ar->arPairwiseCrypto == WEP_CRYPT) {
4131 ar6000_install_static_wep_keys(ar);
4134 else if(ar->arPairwiseCrypto == WAPI_CRYPT) {
4135 ap_set_wapi_key(ar, ik);
4141 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
4142 switch (ik->ik_type) {
4143 case IEEE80211_CIPHER_TKIP:
4144 keyType = TKIP_CRYPT;
4146 case IEEE80211_CIPHER_AES_CCM:
4147 keyType = AES_CRYPT;
4152 wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, GROUP_USAGE,
4153 ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
4154 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
4160 ar->arConnected = true;
4164 A_PRINTF("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n "
4165 " AID=%d \n", bssid[0], bssid[1], bssid[2],
4166 bssid[3], bssid[4], bssid[5], channel);
4167 switch ((listenInterval>>8)&0xFF) {
4169 A_PRINTF("AUTH: OPEN\n");
4172 A_PRINTF("AUTH: SHARED\n");
4175 A_PRINTF("AUTH: Unknown\n");
4178 switch (listenInterval&0xFF) {
4180 A_PRINTF("KeyMgmt: WPA-PSK\n");
4183 A_PRINTF("KeyMgmt: WPA2-PSK\n");
4186 A_PRINTF("KeyMgmt: NONE\n");
4189 switch (beaconInterval) {
4191 A_PRINTF("Cipher: AES\n");
4194 A_PRINTF("Cipher: TKIP\n");
4197 A_PRINTF("Cipher: WEP\n");
4201 A_PRINTF("Cipher: WAPI\n");
4205 A_PRINTF("Cipher: NONE\n");
4209 add_new_sta(ar, bssid, channel /*aid*/,
4210 assocInfo /* WPA IE */, assocRespLen /* IE len */,
4211 listenInterval&0xFF /* Keymgmt */, beaconInterval /* cipher */,
4212 (listenInterval>>8)&0xFF /* auth alg */);
4214 /* Send event to application */
4215 A_MEMZERO(&wrqu, sizeof(wrqu));
4216 memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4217 wireless_send_event(ar->arNetDev, IWEVREGISTERED, &wrqu, NULL);
4218 /* In case the queue is stopped when we switch modes, this will
4221 netif_wake_queue(ar->arNetDev);
4225 ar6k_cfg80211_connect_event(ar, channel, bssid,
4226 listenInterval, beaconInterval,
4227 networkType, beaconIeLen,
4228 assocReqLen, assocRespLen,
4231 memcpy(ar->arBssid, bssid, sizeof(ar->arBssid));
4232 ar->arBssChannel = channel;
4234 A_PRINTF("AR6000 connected event on freq %d ", channel);
4235 A_PRINTF("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4236 " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d"
4237 " assocRespLen =%d\n",
4238 bssid[0], bssid[1], bssid[2],
4239 bssid[3], bssid[4], bssid[5],
4240 listenInterval, beaconInterval,
4241 beaconIeLen, assocReqLen, assocRespLen);
4242 if (networkType & ADHOC_NETWORK) {
4243 if (networkType & ADHOC_CREATOR) {
4244 A_PRINTF("Network: Adhoc (Creator)\n");
4246 A_PRINTF("Network: Adhoc (Joiner)\n");
4249 A_PRINTF("Network: Infrastructure\n");
4252 if ((ar->arNetworkType == INFRA_NETWORK)) {
4253 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
4256 if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) {
4257 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= "));
4260 A_MEMZERO(buf, sizeof(buf));
4261 sprintf(buf, "%s", beaconIetag);
4263 for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) {
4264 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4265 sprintf(pos, "%2.2x", assocInfo[i]);
4268 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4270 A_MEMZERO(&wrqu, sizeof(wrqu));
4271 wrqu.data.length = strlen(buf);
4272 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4275 if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2))))
4277 assoc_resp_ie_pos = beaconIeLen + assocReqLen +
4278 sizeof(u16) + /* capinfo*/
4279 sizeof(u16) + /* status Code */
4280 sizeof(u16) ; /* associd */
4281 A_MEMZERO(buf, sizeof(buf));
4282 sprintf(buf, "%s", tag2);
4284 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= "));
4286 * The Association Response Frame w.o. the WLAN header is delivered to
4287 * the host, so skip over to the IEs
4289 for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++)
4291 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4292 sprintf(pos, "%2.2x", assocInfo[i]);
4295 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4297 A_MEMZERO(&wrqu, sizeof(wrqu));
4298 wrqu.data.length = strlen(buf);
4299 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4302 if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) {
4304 * assoc Request includes capability and listen interval. Skip these.
4306 assoc_req_ie_pos = beaconIeLen +
4307 sizeof(u16) + /* capinfo*/
4308 sizeof(u16); /* listen interval */
4310 A_MEMZERO(buf, sizeof(buf));
4311 sprintf(buf, "%s", tag1);
4313 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= "));
4314 for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) {
4315 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4316 sprintf(pos, "%2.2x", assocInfo[i]);
4319 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4321 A_MEMZERO(&wrqu, sizeof(wrqu));
4322 wrqu.data.length = strlen(buf);
4323 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4326 if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN &&
4327 ar->user_saved_keys.keyOk == true)
4329 key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC;
4331 if (ar->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) {
4332 key_op_ctrl &= ~KEY_OP_INIT_RSC;
4334 key_op_ctrl |= KEY_OP_INIT_RSC;
4336 ar6000_reinstall_keys(ar, key_op_ctrl);
4339 netif_wake_queue(ar->arNetDev);
4341 /* Update connect & link status atomically */
4342 spin_lock_irqsave(&ar->arLock, flags);
4343 ar->arConnected = true;
4344 ar->arConnectPending = false;
4345 netif_carrier_on(ar->arNetDev);
4346 spin_unlock_irqrestore(&ar->arLock, flags);
4347 /* reset the rx aggr state */
4348 aggr_reset_state(ar->aggr_cntxt);
4351 A_MEMZERO(&wrqu, sizeof(wrqu));
4352 memcpy(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN);
4353 wrqu.addr.sa_family = ARPHRD_ETHER;
4354 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4355 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable) {
4356 A_MEMZERO(ar->arNodeMap, sizeof(ar->arNodeMap));
4358 ar->arNexEpId = ENDPOINT_2;
4360 if (!ar->arUserBssFilter) {
4361 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4366 void ar6000_set_numdataendpts(struct ar6_softc *ar, u32 num)
4368 A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1));
4369 ar->arNumDataEndPts = num;
4373 sta_cleanup(struct ar6_softc *ar, u8 i)
4375 struct sk_buff *skb;
4377 /* empty the queued pkts in the PS queue if any */
4378 A_MUTEX_LOCK(&ar->sta_list[i].psqLock);
4379 while (!A_NETBUF_QUEUE_EMPTY(&ar->sta_list[i].psq)) {
4380 skb = A_NETBUF_DEQUEUE(&ar->sta_list[i].psq);
4383 A_MUTEX_UNLOCK(&ar->sta_list[i].psqLock);
4385 /* Zero out the state fields */
4386 A_MEMZERO(&ar->arAPStats.sta[ar->sta_list[i].aid-1], sizeof(WMI_PER_STA_STAT));
4387 A_MEMZERO(&ar->sta_list[i].mac, ATH_MAC_LEN);
4388 A_MEMZERO(&ar->sta_list[i].wpa_ie, IEEE80211_MAX_IE);
4389 ar->sta_list[i].aid = 0;
4390 ar->sta_list[i].flags = 0;
4392 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
4396 u8 remove_sta(struct ar6_softc *ar, u8 *mac, u16 reason)
4400 if(IS_MAC_NULL(mac)) {
4404 if(IS_MAC_BCAST(mac)) {
4405 A_PRINTF("DEL ALL STA\n");
4406 for(i=0; i < AP_MAX_NUM_STA; i++) {
4407 if(!IS_MAC_NULL(ar->sta_list[i].mac)) {
4413 for(i=0; i < AP_MAX_NUM_STA; i++) {
4414 if(memcmp(ar->sta_list[i].mac, mac, ATH_MAC_LEN)==0) {
4415 A_PRINTF("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4416 " aid=%d REASON=%d\n", mac[0], mac[1], mac[2],
4417 mac[3], mac[4], mac[5], ar->sta_list[i].aid, reason);
4429 ar6000_disconnect_event(struct ar6_softc *ar, u8 reason, u8 *bssid,
4430 u8 assocRespLen, u8 *assocInfo, u16 protocolReasonStatus)
4433 unsigned long flags;
4434 union iwreq_data wrqu;
4436 if(ar->arNetworkType & AP_NETWORK) {
4437 union iwreq_data wrqu;
4438 struct sk_buff *skb;
4440 if(!remove_sta(ar, bssid, protocolReasonStatus)) {
4444 /* If there are no more associated STAs, empty the mcast PS q */
4445 if (ar->sta_list_index == 0) {
4446 A_MUTEX_LOCK(&ar->mcastpsqLock);
4447 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
4448 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
4451 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
4453 /* Clear the LSB of the BitMapCtl field of the TIM IE */
4454 if (ar->arWmiReady) {
4455 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
4459 if(!IS_MAC_BCAST(bssid)) {
4460 /* Send event to application */
4461 A_MEMZERO(&wrqu, sizeof(wrqu));
4462 memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4463 wireless_send_event(ar->arNetDev, IWEVEXPIRED, &wrqu, NULL);
4466 ar->arConnected = false;
4470 ar6k_cfg80211_disconnect_event(ar, reason, bssid,
4471 assocRespLen, assocInfo,
4472 protocolReasonStatus);
4474 /* Send disconnect event to supplicant */
4475 A_MEMZERO(&wrqu, sizeof(wrqu));
4476 wrqu.addr.sa_family = ARPHRD_ETHER;
4477 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4479 /* it is necessary to clear the host-side rx aggregation state */
4480 aggr_reset_state(ar->aggr_cntxt);
4482 A_UNTIMEOUT(&ar->disconnect_timer);
4484 A_PRINTF("AR6000 disconnected");
4485 if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) {
4486 A_PRINTF(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4487 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
4490 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason));
4491 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus));
4492 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s",
4493 assocRespLen ? " " : "NULL"));
4494 for (i = 0; i < assocRespLen; i++) {
4496 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4498 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4500 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4502 * If the event is due to disconnect cmd from the host, only they the target
4503 * would stop trying to connect. Under any other condition, target would
4504 * keep trying to connect.
4507 if( reason == DISCONNECT_CMD)
4509 if ((!ar->arUserBssFilter) && (ar->arWmiReady)) {
4510 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4513 ar->arConnectPending = true;
4514 if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) ||
4515 ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) {
4516 ar->arConnected = true;
4521 if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady))
4523 bss_t *pWmiSsidnode = NULL;
4525 /* remove the current associated bssid node */
4526 wmi_free_node (ar->arWmi, bssid);
4529 * In case any other same SSID nodes are present
4530 * remove it, since those nodes also not available now
4535 * Find the nodes based on SSID and remove it
4536 * NOTE :: This case will not work out for Hidden-SSID
4538 pWmiSsidnode = wmi_find_Ssidnode (ar->arWmi, ar->arSsid, ar->arSsidLen, false, true);
4542 wmi_free_node (ar->arWmi, pWmiSsidnode->ni_macaddr);
4545 } while (pWmiSsidnode);
4548 /* Update connect & link status atomically */
4549 spin_lock_irqsave(&ar->arLock, flags);
4550 ar->arConnected = false;
4551 netif_carrier_off(ar->arNetDev);
4552 spin_unlock_irqrestore(&ar->arLock, flags);
4554 if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) {
4558 if (reason != CSERV_DISCONNECT)
4560 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
4561 ar->user_key_ctrl = 0;
4564 netif_stop_queue(ar->arNetDev);
4565 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
4566 ar->arBssChannel = 0;
4567 ar->arBeaconInterval = 0;
4569 ar6000_TxDataCleanup(ar);
4573 ar6000_regDomain_event(struct ar6_softc *ar, u32 regCode)
4575 A_PRINTF("AR6000 Reg Code = 0x%x\n", regCode);
4576 ar->arRegCode = regCode;
4580 ar6000_aggr_rcv_addba_req_evt(struct ar6_softc *ar, WMI_ADDBA_REQ_EVENT *evt)
4582 if(evt->status == 0) {
4583 aggr_recv_addba_req_evt(ar->aggr_cntxt, evt->tid, evt->st_seq_no, evt->win_sz);
4588 ar6000_aggr_rcv_addba_resp_evt(struct ar6_softc *ar, WMI_ADDBA_RESP_EVENT *evt)
4590 A_PRINTF("ADDBA RESP. tid %d status %d, sz %d\n", evt->tid, evt->status, evt->amsdu_sz);
4591 if(evt->status == 0) {
4596 ar6000_aggr_rcv_delba_req_evt(struct ar6_softc *ar, WMI_DELBA_EVENT *evt)
4598 aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid);
4601 void register_pal_cb(ar6k_pal_config_t *palConfig_p)
4603 ar6k_pal_config_g = *palConfig_p;
4607 ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd)
4614 size = cmd->evt_buf_sz + 4;
4615 osbuf = A_NETBUF_ALLOC(size);
4616 if (osbuf == NULL) {
4618 A_PRINTF("Error in allocating netbuf \n");
4622 A_NETBUF_PUT(osbuf, size);
4623 buf = (u8 *)A_NETBUF_DATA(osbuf);
4624 /* First 2-bytes carry HCI event/ACL data type
4625 * the next 2 are free
4627 *((short *)buf) = WMI_HCI_EVENT_EVENTID;
4629 memcpy(buf, cmd->buf, cmd->evt_buf_sz);
4631 ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf);
4633 A_PRINTF_LOG("HCI Event From PAL <-- \n");
4634 for(i = 0; i < cmd->evt_buf_sz; i++) {
4635 A_PRINTF_LOG("0x%02x ", cmd->buf[i]);
4641 A_PRINTF_LOG("==================================\n");
4646 ar6000_neighborReport_event(struct ar6_softc *ar, int numAps, WMI_NEIGHBOR_INFO *info)
4648 #if WIRELESS_EXT >= 18
4649 struct iw_pmkid_cand *pmkcand;
4650 #else /* WIRELESS_EXT >= 18 */
4651 static const char *tag = "PRE-AUTH";
4653 #endif /* WIRELESS_EXT >= 18 */
4655 union iwreq_data wrqu;
4658 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("AR6000 Neighbor Report Event\n"));
4659 for (i=0; i < numAps; info++, i++) {
4660 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4661 info->bssid[0], info->bssid[1], info->bssid[2],
4662 info->bssid[3], info->bssid[4], info->bssid[5]));
4663 if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) {
4664 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("preauth-cap"));
4666 if (info->bssFlags & WMI_PMKID_VALID_BSS) {
4667 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,(" pmkid-valid\n"));
4668 continue; /* we skip bss if the pmkid is already valid */
4670 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("\n"));
4671 A_MEMZERO(&wrqu, sizeof(wrqu));
4672 #if WIRELESS_EXT >= 18
4673 pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand));
4674 A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand));
4676 pmkcand->flags = info->bssFlags;
4677 memcpy(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN);
4678 wrqu.data.length = sizeof(struct iw_pmkid_cand);
4679 wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand);
4681 #else /* WIRELESS_EXT >= 18 */
4682 snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
4684 info->bssid[0], info->bssid[1], info->bssid[2],
4685 info->bssid[3], info->bssid[4], info->bssid[5],
4687 wrqu.data.length = strlen(buf);
4688 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4689 #endif /* WIRELESS_EXT >= 18 */
4694 ar6000_tkip_micerr_event(struct ar6_softc *ar, u8 keyid, bool ismcast)
4696 static const char *tag = "MLME-MICHAELMICFAILURE.indication";
4698 union iwreq_data wrqu;
4701 * For AP case, keyid will have aid of STA which sent pkt with
4702 * MIC error. Use this aid to get MAC & send it to hostapd.
4704 if (ar->arNetworkType == AP_NETWORK) {
4705 sta_t *s = ieee80211_find_conn_for_aid(ar, (keyid >> 2));
4707 A_PRINTF("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid);
4710 A_PRINTF("AP TKIP MIC error received from aid=%d\n", keyid);
4711 snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
4712 tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]);
4715 ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast);
4717 A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n",
4718 keyid & 0x3, ismcast ? "multi": "uni");
4719 snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3,
4720 ismcast ? "mult" : "un");
4723 memset(&wrqu, 0, sizeof(wrqu));
4724 wrqu.data.length = strlen(buf);
4725 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4729 ar6000_scanComplete_event(struct ar6_softc *ar, int status)
4732 ar6k_cfg80211_scanComplete_event(ar, status);
4734 if (!ar->arUserBssFilter) {
4735 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4737 if (ar->scan_triggered) {
4739 union iwreq_data wrqu;
4740 A_MEMZERO(&wrqu, sizeof(wrqu));
4741 wireless_send_event(ar->arNetDev, SIOCGIWSCAN, &wrqu, NULL);
4743 ar->scan_triggered = 0;
4746 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,( "AR6000 scan complete: %d\n", status));
4750 ar6000_targetStats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
4754 if(ar->arNetworkType == AP_NETWORK) {
4755 WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr;
4756 WMI_AP_MODE_STAT *ap = &ar->arAPStats;
4758 if (len < sizeof(*p)) {
4762 for(ac=0;ac<AP_MAX_NUM_STA;ac++) {
4763 ap->sta[ac].tx_bytes += p->sta[ac].tx_bytes;
4764 ap->sta[ac].tx_pkts += p->sta[ac].tx_pkts;
4765 ap->sta[ac].tx_error += p->sta[ac].tx_error;
4766 ap->sta[ac].tx_discard += p->sta[ac].tx_discard;
4767 ap->sta[ac].rx_bytes += p->sta[ac].rx_bytes;
4768 ap->sta[ac].rx_pkts += p->sta[ac].rx_pkts;
4769 ap->sta[ac].rx_error += p->sta[ac].rx_error;
4770 ap->sta[ac].rx_discard += p->sta[ac].rx_discard;
4774 WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr;
4775 TARGET_STATS *pStats = &ar->arTargetStats;
4777 if (len < sizeof(*pTarget)) {
4781 // Update the RSSI of the connected bss.
4782 if (ar->arConnected) {
4783 bss_t *pConnBss = NULL;
4785 pConnBss = wmi_find_node(ar->arWmi,ar->arBssid);
4788 pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
4789 pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr;
4790 wmi_node_return(ar->arWmi, pConnBss);
4794 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n"));
4795 pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets;
4796 pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes;
4797 pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts;
4798 pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes;
4799 pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts;
4800 pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes;
4801 pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts;
4802 pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes;
4803 pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt;
4804 for(ac = 0; ac < WMM_NUM_AC; ac++)
4805 pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac];
4806 pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors;
4807 pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt;
4808 pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt;
4809 pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt;
4810 pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt;
4811 pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate);
4813 pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets;
4814 pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes;
4815 pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts;
4816 pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes;
4817 pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts;
4818 pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes;
4819 pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts;
4820 pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes;
4821 pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt;
4822 pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors;
4823 pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr;
4824 pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss;
4825 pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err;
4826 pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames;
4827 pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate);
4830 pStats->tkip_local_mic_failure
4831 += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure;
4832 pStats->tkip_counter_measures_invoked
4833 += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked;
4834 pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays;
4835 pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors;
4836 pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors;
4837 pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays;
4839 pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt;
4840 pStats->noise_floor_calibation = pTarget->noise_floor_calibation;
4842 pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt;
4843 pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt;
4844 pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt;
4845 pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt;
4846 pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr;
4847 pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
4849 if (enablerssicompensation) {
4850 pStats->cs_aveBeacon_rssi =
4851 rssi_compensation_calc(ar, pStats->cs_aveBeacon_rssi);
4853 pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec;
4854 pStats->cs_snr = pTarget->cservStats.cs_snr;
4855 pStats->cs_rssi = pTarget->cservStats.cs_rssi;
4857 pStats->lq_val = pTarget->lqVal;
4859 pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped;
4860 pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups;
4861 pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups;
4862 pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded;
4863 pStats->arp_received += pTarget->arpStats.arp_received;
4864 pStats->arp_matched += pTarget->arpStats.arp_matched;
4865 pStats->arp_replied += pTarget->arpStats.arp_replied;
4867 if (ar->statsUpdatePending) {
4868 ar->statsUpdatePending = false;
4875 ar6000_rssiThreshold_event(struct ar6_softc *ar, WMI_RSSI_THRESHOLD_VAL newThreshold, s16 rssi)
4877 USER_RSSI_THOLD userRssiThold;
4879 rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR;
4881 if (enablerssicompensation) {
4882 rssi = rssi_compensation_calc(ar, rssi);
4885 /* Send an event to the app */
4886 userRssiThold.tag = ar->rssi_map[newThreshold].tag;
4887 userRssiThold.rssi = rssi;
4888 A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold,
4889 userRssiThold.tag, userRssiThold.rssi);
4894 ar6000_hbChallengeResp_event(struct ar6_softc *ar, u32 cookie, u32 source)
4896 if (source != APP_HB_CHALLENGE) {
4897 /* This would ignore the replys that come in after their due time */
4898 if (cookie == ar->arHBChallengeResp.seqNum) {
4899 ar->arHBChallengeResp.outstanding = false;
4906 ar6000_reportError_event(struct ar6_softc *ar, WMI_TARGET_ERROR_VAL errorVal)
4908 static const char * const errString[] = {
4909 [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL",
4910 [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND",
4911 [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR",
4912 [WMI_TARGET_BMISS] "WMI_TARGET_BMISS",
4913 [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN"
4916 A_PRINTF("AR6000 Error on Target. Error = 0x%x\n", errorVal);
4918 /* One error is reported at a time, and errorval is a bitmask */
4919 if(errorVal & (errorVal - 1))
4922 A_PRINTF("AR6000 Error type = ");
4925 case WMI_TARGET_PM_ERR_FAIL:
4926 case WMI_TARGET_KEY_NOT_FOUND:
4927 case WMI_TARGET_DECRYPTION_ERR:
4928 case WMI_TARGET_BMISS:
4929 case WMI_PSDISABLE_NODE_JOIN:
4930 A_PRINTF("%s\n", errString[errorVal]);
4933 A_PRINTF("INVALID\n");
4941 ar6000_cac_event(struct ar6_softc *ar, u8 ac, u8 cacIndication,
4942 u8 statusCode, u8 *tspecSuggestion)
4944 WMM_TSPEC_IE *tspecIe;
4947 * This is the TSPEC IE suggestion from AP.
4948 * Suggestion provided by AP under some error
4949 * cases, could be helpful for the host app.
4950 * Check documentation.
4952 tspecIe = (WMM_TSPEC_IE *)tspecSuggestion;
4955 * What do we do, if we get TSPEC rejection? One thought
4956 * that comes to mind is implictly delete the pstream...
4958 A_PRINTF("AR6000 CAC notification. "
4959 "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n",
4960 ac, cacIndication, statusCode);
4964 ar6000_channel_change_event(struct ar6_softc *ar, u16 oldChannel,
4967 A_PRINTF("Channel Change notification\nOld Channel: %d, New Channel: %d\n",
4968 oldChannel, newChannel);
4971 #define AR6000_PRINT_BSSID(_pBss) do { \
4972 A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\
4973 (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\
4974 (_pBss)[4],(_pBss)[5]); \
4978 ar6000_roam_tbl_event(struct ar6_softc *ar, WMI_TARGET_ROAM_TBL *pTbl)
4982 A_PRINTF("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n",
4983 pTbl->numEntries, pTbl->roamMode);
4984 for (i= 0; i < pTbl->numEntries; i++) {
4985 A_PRINTF("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i,
4986 pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1],
4987 pTbl->bssRoamInfo[i].bssid[2],
4988 pTbl->bssRoamInfo[i].bssid[3],
4989 pTbl->bssRoamInfo[i].bssid[4],
4990 pTbl->bssRoamInfo[i].bssid[5]);
4991 A_PRINTF("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d"
4993 pTbl->bssRoamInfo[i].rssi,
4994 pTbl->bssRoamInfo[i].rssidt,
4995 pTbl->bssRoamInfo[i].last_rssi,
4996 pTbl->bssRoamInfo[i].util,
4997 pTbl->bssRoamInfo[i].roam_util,
4998 pTbl->bssRoamInfo[i].bias);
5003 ar6000_wow_list_event(struct ar6_softc *ar, u8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply)
5007 /*Each event now contains exactly one filter, see bug 26613*/
5008 A_PRINTF("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters);
5009 A_PRINTF("wow mode = %s host mode = %s\n",
5010 (wow_reply->wow_mode == 0? "disabled":"enabled"),
5011 (wow_reply->host_mode == 1 ? "awake":"asleep"));
5014 /*If there are no patterns, the reply will only contain generic
5015 WoW information. Pattern information will exist only if there are
5016 patterns present. Bug 26716*/
5018 /* If this event contains pattern information, display it*/
5019 if (wow_reply->this_filter_num) {
5021 A_PRINTF("id=%d size=%d offset=%d\n",
5022 wow_reply->wow_filters[i].wow_filter_id,
5023 wow_reply->wow_filters[i].wow_filter_size,
5024 wow_reply->wow_filters[i].wow_filter_offset);
5025 A_PRINTF("wow pattern = ");
5026 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5027 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j]);
5030 A_PRINTF("\nwow mask = ");
5031 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5032 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j]);
5039 * Report the Roaming related data collected on the target
5042 ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p)
5044 A_PRINTF("Disconnect Data : BSSID: ");
5045 AR6000_PRINT_BSSID(p->disassoc_bssid);
5046 A_PRINTF(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n",
5047 p->disassoc_bss_rssi,p->disassoc_time,
5049 A_PRINTF("Connect Data: BSSID: ");
5050 AR6000_PRINT_BSSID(p->assoc_bssid);
5051 A_PRINTF(" RSSI %d ASSOC Time %d TXRX_TIME %d\n",
5052 p->assoc_bss_rssi,p->assoc_time,
5053 p->allow_txrx_time);
5057 ar6000_roam_data_event(struct ar6_softc *ar, WMI_TARGET_ROAM_DATA *p)
5059 switch (p->roamDataType) {
5060 case ROAM_DATA_TIME:
5061 ar6000_display_roam_time(&p->u.roamTime);
5069 ar6000_bssInfo_event_rx(struct ar6_softc *ar, u8 *datap, int len)
5071 struct sk_buff *skb;
5072 WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap;
5075 if (!ar->arMgmtFilter) {
5078 if (((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) &&
5079 (bih->frameType != BEACON_FTYPE)) ||
5080 ((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) &&
5081 (bih->frameType != PROBERESP_FTYPE)))
5086 if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) {
5088 A_NETBUF_PUT(skb, len);
5089 memcpy(A_NETBUF_DATA(skb), datap, len);
5090 skb->dev = ar->arNetDev;
5091 memcpy(skb_mac_header(skb), A_NETBUF_DATA(skb), 6);
5092 skb->ip_summed = CHECKSUM_NONE;
5093 skb->pkt_type = PACKET_OTHERHOST;
5094 skb->protocol = __constant_htons(0x0019);
5102 ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid)
5104 struct ar6_softc *ar = (struct ar6_softc *)devt;
5106 struct ar_cookie *cookie = NULL;
5109 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
5110 A_NETBUF_FREE(osbuf);
5113 #endif /* CONFIG_PM */
5114 /* take lock to protect ar6000_alloc_cookie() */
5115 AR6000_SPIN_LOCK(&ar->arLock, 0);
5119 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%lx, len=0x%x eid =%d\n",
5120 (unsigned long)osbuf, A_NETBUF_LEN(osbuf), eid));
5122 if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) {
5123 /* control endpoint is full, don't allocate resources, we
5124 * are just going to drop this packet */
5126 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%lX, len:%d \n",
5127 (unsigned long)osbuf, A_NETBUF_LEN(osbuf)));
5129 cookie = ar6000_alloc_cookie(ar);
5132 if (cookie == NULL) {
5133 status = A_NO_MEMORY;
5138 A_PRINTF("WMI cmd send, msgNo %d :", wmiSendCmdNum);
5139 for(i = 0; i < a_netbuf_to_len(osbuf); i++)
5140 A_PRINTF("%x ", ((u8 *)a_netbuf_to_data(osbuf))[i]);
5148 if (cookie != NULL) {
5149 /* got a structure to send it out on */
5150 ar->arTxPending[eid]++;
5152 if (eid != ar->arControlEp) {
5153 ar->arTotalTxDataPending++;
5157 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5159 if (cookie != NULL) {
5160 cookie->arc_bp[0] = (unsigned long)osbuf;
5161 cookie->arc_bp[1] = 0;
5162 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
5164 A_NETBUF_DATA(osbuf),
5165 A_NETBUF_LEN(osbuf),
5167 AR6K_CONTROL_PKT_TAG);
5168 /* this interface is asynchronous, if there is an error, cleanup will happen in the
5169 * TX completion callback */
5170 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
5175 A_NETBUF_FREE(osbuf);
5180 /* indicate tx activity or inactivity on a WMI stream */
5181 void ar6000_indicate_tx_activity(void *devt, u8 TrafficClass, bool Active)
5183 struct ar6_softc *ar = (struct ar6_softc *)devt;
5184 HTC_ENDPOINT_ID eid ;
5187 if (ar->arWmiEnabled) {
5188 eid = arAc2EndpointID(ar, TrafficClass);
5190 AR6000_SPIN_LOCK(&ar->arLock, 0);
5192 ar->arAcStreamActive[TrafficClass] = Active;
5195 /* when a stream goes active, keep track of the active stream with the highest priority */
5197 if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) {
5198 /* set the new highest active priority */
5199 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass];
5203 /* when a stream goes inactive, we may have to search for the next active stream
5204 * that is the highest priority */
5206 if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) {
5208 /* the highest priority stream just went inactive */
5210 /* reset and search for the "next" highest "active" priority stream */
5211 ar->arHiAcStreamActivePri = 0;
5212 for (i = 0; i < WMM_NUM_AC; i++) {
5213 if (ar->arAcStreamActive[i]) {
5214 if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) {
5215 /* set the new highest active priority */
5216 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i];
5223 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5226 /* for mbox ping testing, the traffic class is mapped directly as a stream ID,
5227 * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c
5228 * convert the stream ID to a endpoint */
5229 eid = arAc2EndpointID(ar, TrafficClass);
5232 /* notify HTC, this may cause credit distribution changes */
5234 HTCIndicateActivityChange(ar->arHtcTarget,
5241 ar6000_btcoex_config_event(struct ar6_softc *ar, u8 *ptr, u32 len)
5244 WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr;
5245 WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&ar->arBtcoexConfig;
5247 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5249 A_PRINTF("received config event\n");
5250 pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType;
5251 pArbtcoexConfig->linkId = pBtcoexConfig->linkId;
5253 switch (pBtcoexConfig->btProfileType) {
5254 case WMI_BTCOEX_BT_PROFILE_SCO:
5255 memcpy(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd,
5256 sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD));
5258 case WMI_BTCOEX_BT_PROFILE_A2DP:
5259 memcpy(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd,
5260 sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD));
5262 case WMI_BTCOEX_BT_PROFILE_ACLCOEX:
5263 memcpy(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig,
5264 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5266 case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE:
5267 memcpy(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd,
5268 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5271 if (ar->statsUpdatePending) {
5272 ar->statsUpdatePending = false;
5278 ar6000_btcoex_stats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
5280 WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr;
5282 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5284 memcpy(&ar->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT));
5286 if (ar->statsUpdatePending) {
5287 ar->statsUpdatePending = false;
5292 module_init(ar6000_init_module);
5293 module_exit(ar6000_cleanup_module);
5295 /* Init cookie queue */
5297 ar6000_cookie_init(struct ar6_softc *ar)
5301 ar->arCookieList = NULL;
5302 ar->arCookieCount = 0;
5304 A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem));
5306 for (i = 0; i < MAX_COOKIE_NUM; i++) {
5307 ar6000_free_cookie(ar, &s_ar_cookie_mem[i]);
5311 /* cleanup cookie queue */
5313 ar6000_cookie_cleanup(struct ar6_softc *ar)
5315 /* It is gone .... */
5316 ar->arCookieList = NULL;
5317 ar->arCookieCount = 0;
5320 /* Init cookie queue */
5322 ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie)
5325 A_ASSERT(ar != NULL);
5326 A_ASSERT(cookie != NULL);
5328 cookie->arc_list_next = ar->arCookieList;
5329 ar->arCookieList = cookie;
5330 ar->arCookieCount++;
5333 /* cleanup cookie queue */
5334 static struct ar_cookie *
5335 ar6000_alloc_cookie(struct ar6_softc *ar)
5337 struct ar_cookie *cookie;
5339 cookie = ar->arCookieList;
5342 ar->arCookieList = cookie->arc_list_next;
5343 ar->arCookieCount--;
5350 ar6000_tx_retry_err_event(void *devt)
5352 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n"));
5356 ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, u8 snr)
5358 WMI_SNR_THRESHOLD_EVENT event;
5360 event.range = newThreshold;
5365 ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, u8 lq)
5367 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq));
5372 u32 a_copy_to_user(void *to, const void *from, u32 n)
5374 return(copy_to_user(to, from, n));
5377 u32 a_copy_from_user(void *to, const void *from, u32 n)
5379 return(copy_from_user(to, from, n));
5384 ar6000_get_driver_cfg(struct net_device *dev,
5393 case AR6000_DRIVER_CFG_GET_WLANNODECACHING:
5394 *((u32 *)result) = wlanNodeCaching;
5396 case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS:
5397 *((u32 *)result) = logWmiRawMsgs;
5408 ar6000_keepalive_rx(void *devt, u8 configured)
5410 struct ar6_softc *ar = (struct ar6_softc *)devt;
5412 ar->arKeepaliveConfigured = configured;
5417 ar6000_pmkid_list_event(void *devt, u8 numPMKID, WMI_PMKID *pmkidList,
5422 A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID);
5424 for (i = 0; i < numPMKID; i++) {
5425 A_PRINTF("\nBSSID %d ", i);
5426 for (j = 0; j < ATH_MAC_LEN; j++) {
5427 A_PRINTF("%2.2x", bssidList[j]);
5429 bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN);
5430 A_PRINTF("\nPMKID %d ", i);
5431 for (j = 0; j < WMI_PMKID_LEN; j++) {
5432 A_PRINTF("%2.2x", pmkidList->pmkid[j]);
5434 pmkidList = (WMI_PMKID *)((u8 *)pmkidList + ATH_MAC_LEN +
5439 void ar6000_pspoll_event(struct ar6_softc *ar,u8 aid)
5442 bool isPsqEmpty = false;
5444 conn = ieee80211_find_conn_for_aid(ar, aid);
5446 /* If the PS q for this STA is not empty, dequeue and send a pkt from
5447 * the head of the q. Also update the More data bit in the WMI_DATA_HDR
5448 * if there are more pkts for this STA in the PS q. If there are no more
5449 * pkts for this STA, update the PVB for this STA.
5451 A_MUTEX_LOCK(&conn->psqLock);
5452 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5453 A_MUTEX_UNLOCK(&conn->psqLock);
5456 /* TODO:No buffered pkts for this STA. Send out a NULL data frame */
5458 struct sk_buff *skb = NULL;
5460 A_MUTEX_LOCK(&conn->psqLock);
5461 skb = A_NETBUF_DEQUEUE(&conn->psq);
5462 A_MUTEX_UNLOCK(&conn->psqLock);
5463 /* Set the STA flag to PSPolled, so that the frame will go out */
5464 STA_SET_PS_POLLED(conn);
5465 ar6000_data_tx(skb, ar->arNetDev);
5466 STA_CLR_PS_POLLED(conn);
5468 /* Clear the PVB for this STA if the queue has become empty */
5469 A_MUTEX_LOCK(&conn->psqLock);
5470 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5471 A_MUTEX_UNLOCK(&conn->psqLock);
5474 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
5479 void ar6000_dtimexpiry_event(struct ar6_softc *ar)
5481 bool isMcastQueued = false;
5482 struct sk_buff *skb = NULL;
5484 /* If there are no associated STAs, ignore the DTIM expiry event.
5485 * There can be potential race conditions where the last associated
5486 * STA may disconnect & before the host could clear the 'Indicate DTIM'
5487 * request to the firmware, the firmware would have just indicated a DTIM
5488 * expiry event. The race is between 'clear DTIM expiry cmd' going
5489 * from the host to the firmware & the DTIM expiry event happening from
5490 * the firmware to the host.
5492 if (ar->sta_list_index == 0) {
5496 A_MUTEX_LOCK(&ar->mcastpsqLock);
5497 isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
5498 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5500 A_ASSERT(isMcastQueued == false);
5502 /* Flush the mcast psq to the target */
5503 /* Set the STA flag to DTIMExpired, so that the frame will go out */
5504 ar->DTIMExpired = true;
5506 A_MUTEX_LOCK(&ar->mcastpsqLock);
5507 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
5508 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
5509 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5511 ar6000_data_tx(skb, ar->arNetDev);
5513 A_MUTEX_LOCK(&ar->mcastpsqLock);
5515 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5517 /* Reset the DTIMExpired flag back to 0 */
5518 ar->DTIMExpired = false;
5520 /* Clear the LSB of the BitMapCtl field of the TIM IE */
5521 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
5525 read_rssi_compensation_param(struct ar6_softc *ar)
5529 //#define RSSICOMPENSATION_PRINT
5531 #ifdef RSSICOMPENSATION_PRINT
5533 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5534 for (i=0; i<16; i++) {
5535 A_PRINTF("cust_data_%d = %x \n", i, *(u8 *)cust_data_ptr);
5540 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5542 rssi_compensation_param.customerID = *(u16 *)cust_data_ptr & 0xffff;
5543 rssi_compensation_param.enable = *(u16 *)(cust_data_ptr+2) & 0xffff;
5544 rssi_compensation_param.bg_param_a = *(u16 *)(cust_data_ptr+4) & 0xffff;
5545 rssi_compensation_param.bg_param_b = *(u16 *)(cust_data_ptr+6) & 0xffff;
5546 rssi_compensation_param.a_param_a = *(u16 *)(cust_data_ptr+8) & 0xffff;
5547 rssi_compensation_param.a_param_b = *(u16 *)(cust_data_ptr+10) &0xffff;
5548 rssi_compensation_param.reserved = *(u32 *)(cust_data_ptr+12);
5550 #ifdef RSSICOMPENSATION_PRINT
5551 A_PRINTF("customerID = 0x%x \n", rssi_compensation_param.customerID);
5552 A_PRINTF("enable = 0x%x \n", rssi_compensation_param.enable);
5553 A_PRINTF("bg_param_a = 0x%x and %d \n", rssi_compensation_param.bg_param_a, rssi_compensation_param.bg_param_a);
5554 A_PRINTF("bg_param_b = 0x%x and %d \n", rssi_compensation_param.bg_param_b, rssi_compensation_param.bg_param_b);
5555 A_PRINTF("a_param_a = 0x%x and %d \n", rssi_compensation_param.a_param_a, rssi_compensation_param.a_param_a);
5556 A_PRINTF("a_param_b = 0x%x and %d \n", rssi_compensation_param.a_param_b, rssi_compensation_param.a_param_b);
5557 A_PRINTF("Last 4 bytes = 0x%x \n", rssi_compensation_param.reserved);
5560 if (rssi_compensation_param.enable != 0x1) {
5561 rssi_compensation_param.enable = 0;
5567 s32 rssi_compensation_calc_tcmd(u32 freq, s32 rssi, u32 totalPkt)
5572 if (rssi_compensation_param.enable)
5574 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5575 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5576 rssi = rssi * rssi_compensation_param.a_param_a + totalPkt * rssi_compensation_param.a_param_b;
5577 rssi = (rssi-50) /100;
5578 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5583 if (rssi_compensation_param.enable)
5585 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5586 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5587 rssi = rssi * rssi_compensation_param.bg_param_a + totalPkt * rssi_compensation_param.bg_param_b;
5588 rssi = (rssi-50) /100;
5589 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5596 s16 rssi_compensation_calc(struct ar6_softc *ar, s16 rssi)
5598 if (ar->arBssChannel > 5000)
5600 if (rssi_compensation_param.enable)
5602 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5603 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5604 rssi = rssi * rssi_compensation_param.a_param_a + rssi_compensation_param.a_param_b;
5605 rssi = (rssi-50) /100;
5606 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5611 if (rssi_compensation_param.enable)
5613 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5614 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5615 rssi = rssi * rssi_compensation_param.bg_param_a + rssi_compensation_param.bg_param_b;
5616 rssi = (rssi-50) /100;
5617 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5624 s16 rssi_compensation_reverse_calc(struct ar6_softc *ar, s16 rssi, bool Above)
5628 if (ar->arBssChannel > 5000)
5630 if (rssi_compensation_param.enable)
5632 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5633 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5635 rssi = (rssi - rssi_compensation_param.a_param_b) / rssi_compensation_param.a_param_a;
5636 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5641 if (rssi_compensation_param.enable)
5643 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5644 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5647 for (i=95; i>=0; i--) {
5648 if (rssi <= rssi_compensation_table[i]) {
5654 for (i=0; i<=95; i++) {
5655 if (rssi >= rssi_compensation_table[i]) {
5661 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5669 void ap_wapi_rekey_event(struct ar6_softc *ar, u8 type, u8 *mac)
5671 union iwreq_data wrqu;
5674 A_MEMZERO(buf, sizeof(buf));
5676 strcpy(buf, "WAPI_REKEY");
5678 memcpy(&buf[11], mac, ATH_MAC_LEN);
5680 A_MEMZERO(&wrqu, sizeof(wrqu));
5681 wrqu.data.length = 10+1+ATH_MAC_LEN;
5682 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
5684 A_PRINTF("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5]);
5689 ar6000_reinstall_keys(struct ar6_softc *ar, u8 key_op_ctrl)
5692 struct ieee80211req_key *uik = &ar->user_saved_keys.ucast_ik;
5693 struct ieee80211req_key *bik = &ar->user_saved_keys.bcast_ik;
5694 CRYPTO_TYPE keyType = ar->user_saved_keys.keyType;
5696 if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) {
5697 if (NONE_CRYPT == keyType) {
5698 goto _reinstall_keys_out;
5701 if (uik->ik_keylen) {
5702 status = wmi_addKey_cmd(ar->arWmi, uik->ik_keyix,
5703 ar->user_saved_keys.keyType, PAIRWISE_USAGE,
5704 uik->ik_keylen, (u8 *)&uik->ik_keyrsc,
5705 uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG);
5709 status = wmi_add_krk_cmd(ar->arWmi, uik->ik_keydata);
5712 if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) {
5713 if (NONE_CRYPT == keyType) {
5714 goto _reinstall_keys_out;
5717 if (bik->ik_keylen) {
5718 status = wmi_addKey_cmd(ar->arWmi, bik->ik_keyix,
5719 ar->user_saved_keys.keyType, GROUP_USAGE,
5720 bik->ik_keylen, (u8 *)&bik->ik_keyrsc,
5721 bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG);
5724 status = wmi_add_krk_cmd(ar->arWmi, bik->ik_keydata);
5727 _reinstall_keys_out:
5728 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
5729 ar->user_key_ctrl = 0;
5736 ar6000_dset_open_req(
5754 ar6000_dset_data_req(
5766 ar6000_ap_mode_profile_commit(struct ar6_softc *ar)
5769 unsigned long flags;
5771 /* No change in AP's profile configuration */
5772 if(ar->ap_profile_flag==0) {
5773 A_PRINTF("COMMIT: No change in profile!!!\n");
5777 if(!ar->arSsidLen) {
5778 A_PRINTF("SSID not set!!!\n");
5782 switch(ar->arAuthMode) {
5784 if((ar->arPairwiseCrypto != NONE_CRYPT) &&
5786 (ar->arPairwiseCrypto != WAPI_CRYPT) &&
5788 (ar->arPairwiseCrypto != WEP_CRYPT)) {
5789 A_PRINTF("Cipher not supported in AP mode Open auth\n");
5795 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
5798 A_PRINTF("This key mgmt type not supported in AP mode\n");
5802 /* Update the arNetworkType */
5803 ar->arNetworkType = ar->arNextMode;
5805 A_MEMZERO(&p,sizeof(p));
5806 p.ssidLength = ar->arSsidLen;
5807 memcpy(p.ssid,ar->arSsid,p.ssidLength);
5808 p.channel = ar->arChannelHint;
5809 p.networkType = ar->arNetworkType;
5811 p.dot11AuthMode = ar->arDot11AuthMode;
5812 p.authMode = ar->arAuthMode;
5813 p.pairwiseCryptoType = ar->arPairwiseCrypto;
5814 p.pairwiseCryptoLen = ar->arPairwiseCryptoLen;
5815 p.groupCryptoType = ar->arGroupCrypto;
5816 p.groupCryptoLen = ar->arGroupCryptoLen;
5817 p.ctrl_flags = ar->arConnectCtrlFlags;
5819 wmi_ap_profile_commit(ar->arWmi, &p);
5820 spin_lock_irqsave(&ar->arLock, flags);
5821 ar->arConnected = true;
5822 netif_carrier_on(ar->arNetDev);
5823 spin_unlock_irqrestore(&ar->arLock, flags);
5824 ar->ap_profile_flag = 0;
5829 ar6000_connect_to_ap(struct ar6_softc *ar)
5831 /* The ssid length check prevents second "essid off" from the user,
5832 to be treated as a connect cmd. The second "essid off" is ignored.
5834 if((ar->arWmiReady == true) && (ar->arSsidLen > 0) && ar->arNetworkType!=AP_NETWORK)
5837 if((ADHOC_NETWORK != ar->arNetworkType) &&
5838 (NONE_AUTH==ar->arAuthMode) &&
5839 (WEP_CRYPT==ar->arPairwiseCrypto)) {
5840 ar6000_install_static_wep_keys(ar);
5843 if (!ar->arUserBssFilter) {
5844 if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != 0) {
5849 if (ar->arWapiEnable) {
5850 ar->arPairwiseCrypto = WAPI_CRYPT;
5851 ar->arPairwiseCryptoLen = 0;
5852 ar->arGroupCrypto = WAPI_CRYPT;
5853 ar->arGroupCryptoLen = 0;
5854 ar->arAuthMode = NONE_AUTH;
5855 ar->arConnectCtrlFlags |= CONNECT_IGNORE_WPAx_GROUP_CIPHER;
5858 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\
5859 " PW crypto %d PW crypto Len %d GRP crypto %d"\
5860 " GRP crypto Len %d\n",
5861 ar->arAuthMode, ar->arDot11AuthMode,
5862 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
5863 ar->arGroupCrypto, ar->arGroupCryptoLen));
5865 /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn.
5866 later set it back locally at the STA to 100/1000 TUs depending on the power mode */
5867 if ((ar->arNetworkType == INFRA_NETWORK)) {
5868 wmi_listeninterval_cmd(ar->arWmi, max(ar->arListenIntervalT, (u16)A_MAX_WOW_LISTEN_INTERVAL), 0);
5870 status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
5871 ar->arDot11AuthMode, ar->arAuthMode,
5872 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
5873 ar->arGroupCrypto,ar->arGroupCryptoLen,
5874 ar->arSsidLen, ar->arSsid,
5875 ar->arReqBssid, ar->arChannelHint,
5876 ar->arConnectCtrlFlags);
5878 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
5879 if (!ar->arUserBssFilter) {
5880 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
5885 if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) &&
5886 ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)))
5888 A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0);
5891 ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD;
5893 ar->arConnectPending = true;
5900 ar6000_disconnect(struct ar6_softc *ar)
5902 if ((ar->arConnected == true) || (ar->arConnectPending == true)) {
5903 wmi_disconnect_cmd(ar->arWmi);
5905 * Disconnect cmd is issued, clear connectPending.
5906 * arConnected will be cleard in disconnect_event notification.
5908 ar->arConnectPending = false;
5915 ar6000_ap_mode_get_wpa_ie(struct ar6_softc *ar, struct ieee80211req_wpaie *wpaie)
5918 conn = ieee80211_find_conn(ar, wpaie->wpa_macaddr);
5920 A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE);
5921 A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE);
5924 memcpy(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE);
5931 is_iwioctl_allowed(u8 mode, u16 cmd)
5933 if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) {
5934 cmd -= SIOCSIWCOMMIT;
5935 if(sioctl_filter[cmd] == 0xFF) return 0;
5936 if(sioctl_filter[cmd] & mode) return 0;
5937 } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) {
5938 cmd -= SIOCIWFIRSTPRIV;
5939 if(pioctl_filter[cmd] == 0xFF) return 0;
5940 if(pioctl_filter[cmd] & mode) return 0;
5948 is_xioctl_allowed(u8 mode, int cmd)
5950 if(sizeof(xioctl_filter)-1 < cmd) {
5951 A_PRINTF("Filter for this cmd=%d not defined\n",cmd);
5954 if(xioctl_filter[cmd] == 0xFF) return 0;
5955 if(xioctl_filter[cmd] & mode) return 0;
5961 ap_set_wapi_key(struct ar6_softc *ar, void *ikey)
5963 struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey;
5964 KEY_USAGE keyUsage = 0;
5967 if (memcmp(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) {
5968 keyUsage = GROUP_USAGE;
5970 keyUsage = PAIRWISE_USAGE;
5972 A_PRINTF("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n",
5973 keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5],
5976 status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage,
5977 ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
5978 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
5988 void ar6000_peer_event(
5995 for (pos=0;pos<6;pos++)
5996 printk("%02x: ",*(macAddr+pos));
6000 #ifdef HTC_TEST_SEND_PKTS
6001 #define HTC_TEST_DUPLICATE 8
6002 static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb)
6004 struct ar_cookie *cookie;
6005 struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE];
6006 struct sk_buff *new_skb;
6009 struct htc_packet_queue pktQueue;
6010 EPPING_HEADER *eppingHdr;
6012 eppingHdr = A_NETBUF_DATA(dupskb);
6014 if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) {
6015 /* skip test if this is already a tx perf test */
6019 for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) {
6020 AR6000_SPIN_LOCK(&ar->arLock, 0);
6021 cookie = ar6000_alloc_cookie(ar);
6022 if (cookie != NULL) {
6023 ar->arTxPending[eid]++;
6024 ar->arTotalTxDataPending++;
6027 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6029 if (NULL == cookie) {
6033 new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb));
6035 if (new_skb == NULL) {
6036 AR6000_SPIN_LOCK(&ar->arLock, 0);
6037 ar6000_free_cookie(ar,cookie);
6038 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6042 A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb));
6043 cookie->arc_bp[0] = (unsigned long)new_skb;
6044 cookie->arc_bp[1] = MapNo;
6045 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
6047 A_NETBUF_DATA(new_skb),
6048 A_NETBUF_LEN(new_skb),
6052 cookieArray[i] = cookie;
6055 EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb);
6056 pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */
6064 INIT_HTC_PACKET_QUEUE(&pktQueue);
6066 for (i = 0; i < pkts; i++) {
6067 HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt);
6070 HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue);
6075 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
6077 * Add support for adding and removing a virtual adapter for soft AP.
6078 * Some OS requires different adapters names for station and soft AP mode.
6079 * To support these requirement, create and destory a netdevice instance
6080 * when the AP mode is operational. A full fledged support for virual device
6081 * is not implemented. Rather a virtual interface is created and is linked
6082 * with the existing physical device instance during the operation of the
6086 int ar6000_start_ap_interface(struct ar6_softc *ar)
6088 struct ar_virtual_interface *arApDev;
6090 /* Change net_device to point to AP instance */
6091 arApDev = (struct ar_virtual_interface *)ar->arApDev;
6092 ar->arNetDev = arApDev->arNetDev;
6097 int ar6000_stop_ap_interface(struct ar6_softc *ar)
6099 struct ar_virtual_interface *arApDev;
6101 /* Change net_device to point to sta instance */
6102 arApDev = (struct ar_virtual_interface *)ar->arApDev;
6104 ar->arNetDev = arApDev->arStaNetDev;
6111 int ar6000_create_ap_interface(struct ar6_softc *ar, char *ap_ifname)
6113 struct net_device *dev;
6114 struct ar_virtual_interface *arApDev;
6116 dev = alloc_etherdev(sizeof(struct ar_virtual_interface));
6118 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: can't alloc etherdev\n"));
6123 init_netdev(dev, ap_ifname);
6125 if (register_netdev(dev)) {
6126 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: register_netdev failed\n"));
6130 arApDev = netdev_priv(dev);
6131 arApDev->arDev = ar;
6132 arApDev->arNetDev = dev;
6133 arApDev->arStaNetDev = ar->arNetDev;
6135 ar->arApDev = arApDev;
6138 /* Copy the MAC address */
6139 memcpy(dev->dev_addr, ar->arNetDev->dev_addr, AR6000_ETH_ADDR_LEN);
6144 int ar6000_add_ap_interface(struct ar6_softc *ar, char *ap_ifname)
6146 /* Interface already added, need not proceed further */
6147 if (ar->arApDev != NULL) {
6148 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_add_ap_interface: interface already present \n"));
6152 if (ar6000_create_ap_interface(ar, ap_ifname) != 0) {
6156 A_PRINTF("Add AP interface %s \n",ap_ifname);
6158 return ar6000_start_ap_interface(ar);
6161 int ar6000_remove_ap_interface(struct ar6_softc *ar)
6164 ar6000_stop_ap_interface(ar);
6166 unregister_netdev(arApNetDev);
6167 free_netdev(apApNetDev);
6169 A_PRINTF("Remove AP interface\n");
6177 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
6180 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
6181 EXPORT_SYMBOL(setupbtdev);