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"
30 #ifdef ATH6K_CONFIG_CFG80211
32 #endif /* ATH6K_CONFIG_CFG80211 */
34 #include "wmi_filter_linux.h"
35 #include "epping_test.h"
36 #include "wlan_config.h"
37 #include "ar3kconfig.h"
39 #include "AR6002/addrs.h"
42 /* LINUX_HACK_FUDGE_FACTOR -- this is used to provide a workaround for linux behavior. When
43 * the meta data was added to the header it was found that linux did not correctly provide
44 * enough headroom. However when more headroom was requested beyond what was truly needed
45 * Linux gave the requested headroom. Therefore to get the necessary headroom from Linux
46 * the driver requests more than is needed by the amount = LINUX_HACK_FUDGE_FACTOR */
47 #define LINUX_HACK_FUDGE_FACTOR 16
48 #define BDATA_BDADDR_OFFSET 28
50 A_UINT8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
51 A_UINT8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
55 #define ATH_DEBUG_DBG_LOG ATH_DEBUG_MAKE_MODULE_MASK(0)
56 #define ATH_DEBUG_WLAN_CONNECT ATH_DEBUG_MAKE_MODULE_MASK(1)
57 #define ATH_DEBUG_WLAN_SCAN ATH_DEBUG_MAKE_MODULE_MASK(2)
58 #define ATH_DEBUG_WLAN_TX ATH_DEBUG_MAKE_MODULE_MASK(3)
59 #define ATH_DEBUG_WLAN_RX ATH_DEBUG_MAKE_MODULE_MASK(4)
60 #define ATH_DEBUG_HTC_RAW ATH_DEBUG_MAKE_MODULE_MASK(5)
61 #define ATH_DEBUG_HCI_BRIDGE ATH_DEBUG_MAKE_MODULE_MASK(6)
63 static ATH_DEBUG_MASK_DESCRIPTION driver_debug_desc[] = {
64 { ATH_DEBUG_DBG_LOG , "Target Debug Logs"},
65 { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"},
66 { ATH_DEBUG_WLAN_SCAN , "WLAN scan"},
67 { ATH_DEBUG_WLAN_TX , "WLAN Tx"},
68 { ATH_DEBUG_WLAN_RX , "WLAN Rx"},
69 { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"},
70 { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"},
71 { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"},
72 { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"},
75 ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver,
77 "Linux Driver Interface",
78 ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN |
80 ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc),
86 #define IS_MAC_NULL(mac) (mac[0]==0 && mac[1]==0 && mac[2]==0 && mac[3]==0 && mac[4]==0 && mac[5]==0)
87 #define IS_MAC_BCAST(mac) (*mac==0xff)
89 #define DESCRIPTION "Driver to access the Atheros AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_)
91 MODULE_AUTHOR("Atheros Communications, Inc.");
92 MODULE_DESCRIPTION(DESCRIPTION);
93 MODULE_LICENSE("Dual BSD/GPL");
95 #ifndef REORG_APTC_HEURISTICS
96 #undef ADAPTIVE_POWER_THROUGHPUT_CONTROL
97 #endif /* REORG_APTC_HEURISTICS */
99 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
100 #define APTC_TRAFFIC_SAMPLING_INTERVAL 100 /* msec */
101 #define APTC_UPPER_THROUGHPUT_THRESHOLD 3000 /* Kbps */
102 #define APTC_LOWER_THROUGHPUT_THRESHOLD 2000 /* Kbps */
104 typedef struct aptc_traffic_record {
105 A_BOOL timerScheduled;
106 struct timeval samplingTS;
107 unsigned long bytesReceived;
108 unsigned long bytesTransmitted;
109 } APTC_TRAFFIC_RECORD;
112 APTC_TRAFFIC_RECORD aptcTR;
113 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
115 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
116 // callbacks registered by HCI transport driver
117 HCI_TRANSPORT_CALLBACKS ar6kHciTransCallbacks = { NULL };
120 unsigned int processDot11Hdr = 0;
121 int bmienable = BMIENABLE_DEFAULT;
123 char ifname[IFNAMSIZ] = {0,};
125 int wlaninitmode = WLAN_INIT_MODE_DEFAULT;
126 unsigned int bypasswmi = 0;
127 unsigned int debuglevel = 0;
128 int tspecCompliance = ATHEROS_COMPLIANCE;
129 unsigned int busspeedlow = 0;
130 unsigned int onebitmode = 0;
131 unsigned int skipflash = 0;
132 unsigned int wmitimeout = 2;
133 unsigned int wlanNodeCaching = 1;
134 unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT;
135 unsigned int logWmiRawMsgs = 0;
136 unsigned int enabletimerwar = 0;
137 unsigned int fwmode = 1;
138 unsigned int mbox_yield_limit = 99;
139 unsigned int enablerssicompensation = 0;
140 int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF;
141 int allow_trace_signal = 0;
142 #ifdef CONFIG_HOST_TCMD_SUPPORT
143 unsigned int testmode =0;
146 unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC;
147 unsigned int panic_on_assert = 1;
148 unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT;
150 unsigned int setuphci = SETUPHCI_DEFAULT;
151 unsigned int setuphcipal = SETUPHCIPAL_DEFAULT;
152 unsigned int loghci = 0;
153 unsigned int setupbtdev = SETUPBTDEV_DEFAULT;
154 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
155 unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT;
156 unsigned int hciuartscale = HCIUARTSCALE_DEFAULT;
157 unsigned int hciuartstep = HCIUARTSTEP_DEFAULT;
159 #ifdef CONFIG_CHECKSUM_OFFLOAD
160 unsigned int csumOffload=0;
161 unsigned int csumOffloadTest=0;
163 unsigned int eppingtest=0;
165 module_param_string(ifname, ifname, sizeof(ifname), 0644);
166 module_param(wlaninitmode, int, 0644);
167 module_param(bmienable, int, 0644);
168 module_param(bypasswmi, uint, 0644);
169 module_param(debuglevel, uint, 0644);
170 module_param(tspecCompliance, int, 0644);
171 module_param(onebitmode, uint, 0644);
172 module_param(busspeedlow, uint, 0644);
173 module_param(skipflash, uint, 0644);
174 module_param(wmitimeout, uint, 0644);
175 module_param(wlanNodeCaching, uint, 0644);
176 module_param(logWmiRawMsgs, uint, 0644);
177 module_param(enableuartprint, uint, 0644);
178 module_param(enabletimerwar, uint, 0644);
179 module_param(fwmode, uint, 0644);
180 module_param(mbox_yield_limit, uint, 0644);
181 module_param(reduce_credit_dribble, int, 0644);
182 module_param(allow_trace_signal, int, 0644);
183 module_param(enablerssicompensation, uint, 0644);
184 module_param(processDot11Hdr, uint, 0644);
185 #ifdef CONFIG_CHECKSUM_OFFLOAD
186 module_param(csumOffload, uint, 0644);
188 #ifdef CONFIG_HOST_TCMD_SUPPORT
189 module_param(testmode, uint, 0644);
191 module_param(irqprocmode, uint, 0644);
192 module_param(nohifscattersupport, uint, 0644);
193 module_param(panic_on_assert, uint, 0644);
194 module_param(setuphci, uint, 0644);
195 module_param(setuphcipal, uint, 0644);
196 module_param(loghci, uint, 0644);
197 module_param(setupbtdev, uint, 0644);
198 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
199 module_param(ar3khcibaud, uint, 0644);
200 module_param(hciuartscale, uint, 0644);
201 module_param(hciuartstep, uint, 0644);
203 module_param(eppingtest, uint, 0644);
205 /* in 2.6.10 and later this is now a pointer to a uint */
206 unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX;
207 #define mboxnum &_mboxnum
210 A_UINT32 g_dbg_flags = DBG_DEFAULTS;
211 unsigned int debugflags = 0;
213 unsigned int debughtc = 0;
214 unsigned int debugbmi = 0;
215 unsigned int debughif = 0;
216 unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0};
217 unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0};
218 unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0};
219 unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0};
220 module_param(debugflags, uint, 0644);
221 module_param(debugdriver, int, 0644);
222 module_param(debughtc, uint, 0644);
223 module_param(debugbmi, uint, 0644);
224 module_param(debughif, uint, 0644);
225 module_param_array(txcreditsavailable, uint, mboxnum, 0644);
226 module_param_array(txcreditsconsumed, uint, mboxnum, 0644);
227 module_param_array(txcreditintrenable, uint, mboxnum, 0644);
228 module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644);
232 unsigned int resetok = 1;
233 unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0};
234 unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0};
235 unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0};
236 unsigned int hifBusRequestNumMax = 40;
237 unsigned int war23838_disabled = 0;
238 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
239 unsigned int enableAPTCHeuristics = 1;
240 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
241 module_param_array(tx_attempt, uint, mboxnum, 0644);
242 module_param_array(tx_post, uint, mboxnum, 0644);
243 module_param_array(tx_complete, uint, mboxnum, 0644);
244 module_param(hifBusRequestNumMax, uint, 0644);
245 module_param(war23838_disabled, uint, 0644);
246 module_param(resetok, uint, 0644);
247 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
248 module_param(enableAPTCHeuristics, uint, 0644);
249 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
251 #ifdef BLOCK_TX_PATH_FLAG
253 module_param(blocktx, int, 0644);
254 #endif /* BLOCK_TX_PATH_FLAG */
256 typedef struct user_rssi_compensation_t {
268 } USER_RSSI_CPENSATION;
270 static USER_RSSI_CPENSATION rssi_compensation_param;
272 static A_INT16 rssi_compensation_table[96];
274 int reconnect_flag = 0;
275 static ar6k_pal_config_t ar6k_pal_config_g;
277 /* Function declarations */
278 static int ar6000_init_module(void);
279 static void ar6000_cleanup_module(void);
281 int ar6000_init(struct net_device *dev);
282 static int ar6000_open(struct net_device *dev);
283 static int ar6000_close(struct net_device *dev);
284 static void ar6000_init_control_info(AR_SOFTC_T *ar);
285 static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev);
287 void ar6000_destroy(struct net_device *dev, unsigned int unregister);
288 static void ar6000_detect_error(unsigned long ptr);
289 static void ar6000_set_multicast_list(struct net_device *dev);
290 static struct net_device_stats *ar6000_get_stats(struct net_device *dev);
291 static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev);
293 static void disconnect_timer_handler(unsigned long ptr);
295 void read_rssi_compensation_param(AR_SOFTC_T *ar);
297 /* for android builds we call external APIs that handle firmware download and configuration */
299 /* !!!! Interim android support to make it easier to patch the default driver for
300 * android use. You must define an external source file ar6000_android.c that handles the following
302 extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks);
303 extern void android_module_exit(void);
306 * HTC service connection handlers
308 static A_STATUS ar6000_avail_ev(void *context, void *hif_handle);
310 static A_STATUS ar6000_unavail_ev(void *context, void *hif_handle);
312 A_STATUS ar6000_configure_target(AR_SOFTC_T *ar);
314 static void ar6000_target_failure(void *Instance, A_STATUS Status);
316 static void ar6000_rx(void *Context, HTC_PACKET *pPacket);
318 static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint);
320 static void ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPackets);
322 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket);
324 #ifdef ATH_AR6K_11N_SUPPORT
325 static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num);
327 static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf);
328 //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf);
330 static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length);
332 static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count);
334 static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar);
337 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
338 struct bin_attribute *bin_attr,
339 char *buf, loff_t pos, size_t count);
342 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
343 struct bin_attribute *bin_attr,
344 char *buf, loff_t pos, size_t count);
347 ar6000_sysfs_bmi_init(AR_SOFTC_T *ar);
349 /* HCI PAL callback function declarations */
350 A_STATUS ar6k_setup_hci_pal(AR_SOFTC_T *ar);
351 void ar6k_cleanup_hci_pal(AR_SOFTC_T *ar);
354 ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar);
357 ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode);
363 struct net_device *ar6000_devices[MAX_AR6000];
364 static int is_netdev_registered;
365 extern struct iw_handler_def ath_iw_handler_def;
366 DECLARE_WAIT_QUEUE_HEAD(arEvent);
367 static void ar6000_cookie_init(AR_SOFTC_T *ar);
368 static void ar6000_cookie_cleanup(AR_SOFTC_T *ar);
369 static void ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie);
370 static struct ar_cookie *ar6000_alloc_cookie(AR_SOFTC_T *ar);
373 static A_STATUS ar6000_reinstall_keys(AR_SOFTC_T *ar,A_UINT8 key_op_ctrl);
376 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
377 struct net_device *arApNetDev;
378 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
380 static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
382 #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \
383 (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
384 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
387 static struct net_device_ops ar6000_netdev_ops = {
389 .ndo_open = ar6000_open,
390 .ndo_stop = ar6000_close,
391 .ndo_get_stats = ar6000_get_stats,
392 .ndo_do_ioctl = ar6000_ioctl,
393 .ndo_start_xmit = ar6000_data_tx,
394 .ndo_set_multicast_list = ar6000_set_multicast_list,
397 /* Debug log support */
400 * Flag to govern whether the debug logs should be parsed in the kernel
401 * or reported to the application.
403 #define REPORT_DEBUG_LOGS_TO_APP
406 ar6000_set_host_app_area(AR_SOFTC_T *ar)
408 A_UINT32 address, data;
409 struct host_app_area_s host_app_area;
411 /* Fetch the address of the host_app_area_s instance in the host interest area */
412 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest));
413 if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != A_OK) {
416 address = TARG_VTOP(ar->arTargetType, data);
417 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
418 if (ar6000_WriteDataDiag(ar->arHifDevice, address,
419 (A_UCHAR *)&host_app_area,
420 sizeof(struct host_app_area_s)) != A_OK)
429 dbglog_get_debug_hdr_ptr(AR_SOFTC_T *ar)
435 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr));
436 if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address,
437 (A_UCHAR *)¶m, 4)) != A_OK)
446 * The dbglog module has been initialized. Its ok to access the relevant
447 * data stuctures over the diagnostic window.
450 ar6000_dbglog_init_done(AR_SOFTC_T *ar)
452 ar->dbglog_init_done = TRUE;
456 dbglog_get_debug_fragment(A_INT8 *datap, A_UINT32 len, A_UINT32 limit)
465 buffer = (A_INT32 *)datap;
466 length = (limit >> 2);
471 while (count < length) {
472 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
473 fraglen = (count << 2);
474 count += numargs + 1;
482 dbglog_parse_debug_logs(A_INT8 *datap, A_UINT32 len)
493 buffer = (A_INT32 *)datap;
495 while (count < length) {
496 debugid = DBGLOG_GET_DBGID(buffer[count]);
497 moduleid = DBGLOG_GET_MODULEID(buffer[count]);
498 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
499 timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]);
502 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp));
506 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid,
507 timestamp, buffer[count+1]));
511 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid,
512 timestamp, buffer[count+1], buffer[count+2]));
516 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs));
518 count += numargs + 1;
523 ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar)
525 A_UINT32 data[8]; /* Should be able to accomodate struct dbglog_buf_s */
530 A_UINT32 debug_hdr_ptr;
532 if (!ar->dbglog_init_done) return A_ERROR;
535 AR6000_SPIN_LOCK(&ar->arLock, 0);
537 if (ar->dbgLogFetchInProgress) {
538 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
542 /* block out others */
543 ar->dbgLogFetchInProgress = TRUE;
545 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
547 debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar);
548 printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr);
550 /* Get the contents of the ring buffer */
552 address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr);
553 length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */;
554 A_MEMZERO(data, sizeof(data));
555 ar6000_ReadDataDiag(ar->arHifDevice, address, (A_UCHAR *)data, length);
556 address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */);
558 dropped = data[1]; /* dropped */
559 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
560 A_MEMZERO(data, sizeof(data));
561 ar6000_ReadDataDiag(ar->arHifDevice, address, (A_UCHAR *)&data, length);
564 address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/);
565 length = data[3]; /* length */
566 if ((length) && (length <= data[2] /* bufsize*/)) {
567 /* Rewind the index if it is about to overrun the buffer */
568 if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) {
571 if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address,
572 (A_UCHAR *)&ar->log_buffer[ar->log_cnt], length))
576 ar6000_dbglog_event(ar, dropped, (A_INT8*)&ar->log_buffer[ar->log_cnt], length);
577 ar->log_cnt += length;
579 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n",
583 address = TARG_VTOP(ar->arTargetType, data[0] /* next */);
584 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
585 A_MEMZERO(data, sizeof(data));
586 if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address,
587 (A_UCHAR *)&data, length))
592 } while (address != firstbuf);
595 ar->dbgLogFetchInProgress = FALSE;
601 ar6000_dbglog_event(AR_SOFTC_T *ar, A_UINT32 dropped,
602 A_INT8 *buffer, A_UINT32 length)
604 #ifdef REPORT_DEBUG_LOGS_TO_APP
605 #define MAX_WIRELESS_EVENT_SIZE 252
607 * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages.
608 * There seems to be a limitation on the length of message that could be
609 * transmitted to the user app via this mechanism.
614 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
615 MAX_WIRELESS_EVENT_SIZE);
617 ar6000_send_event_to_app(ar, WMIX_DBGLOG_EVENTID, (A_UINT8*)&buffer[sent], send);
619 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
620 MAX_WIRELESS_EVENT_SIZE);
623 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n",
626 /* Interpret the debug logs */
627 dbglog_parse_debug_logs((A_INT8*)buffer, length);
628 #endif /* REPORT_DEBUG_LOGS_TO_APP */
633 ar6000_init_module(void)
635 static int probed = 0;
637 OSDRV_CALLBACKS osdrvCallbacks;
639 a_module_debug_support_init();
642 /* check for debug mask overrides */
644 ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc);
647 ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi);
650 ATH_DEBUG_SET_DEBUG_MASK(hif,debughif);
652 if (debugdriver != 0) {
653 ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver);
658 A_REGISTER_MODULE_DEBUG_INFO(driver);
660 A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks));
661 osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev;
662 osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev;
664 osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev;
665 osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev;
666 osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev;
672 android_module_init(&osdrvCallbacks);
676 /* Set the debug flags if specified at load time */
679 g_dbg_flags = debugflags;
688 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
689 memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD));
690 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
692 #ifdef CONFIG_HOST_GPIO_SUPPORT
694 #endif /* CONFIG_HOST_GPIO_SUPPORT */
696 status = HIFInit(&osdrvCallbacks);
704 ar6000_cleanup_module(void)
707 struct net_device *ar6000_netdev;
709 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
710 /* Delete the Adaptive Power Control timer */
711 if (timer_pending(&aptcTimer)) {
712 del_timer_sync(&aptcTimer);
714 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
716 for (i=0; i < MAX_AR6000; i++) {
717 if (ar6000_devices[i] != NULL) {
718 ar6000_netdev = ar6000_devices[i];
719 ar6000_devices[i] = NULL;
720 ar6000_destroy(ar6000_netdev, 1);
724 HIFShutDownDevice(NULL);
726 a_module_debug_support_cleanup();
731 android_module_exit();
734 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n"));
737 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
739 aptcTimerHandler(unsigned long arg)
746 ar = (AR_SOFTC_T *)arg;
747 A_ASSERT(ar != NULL);
748 A_ASSERT(!timer_pending(&aptcTimer));
750 AR6000_SPIN_LOCK(&ar->arLock, 0);
752 /* Get the number of bytes transferred */
753 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
754 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
756 /* Calculate and decide based on throughput thresholds */
757 throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */
758 if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) {
759 /* Enable Sleep and delete the timer */
760 A_ASSERT(ar->arWmiReady == TRUE);
761 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
762 status = wmi_powermode_cmd(ar->arWmi, REC_POWER);
763 AR6000_SPIN_LOCK(&ar->arLock, 0);
764 A_ASSERT(status == A_OK);
765 aptcTR.timerScheduled = FALSE;
767 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
770 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
772 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
774 #ifdef ATH_AR6K_11N_SUPPORT
776 ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num)
781 if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) {
782 A_NETBUF_ENQUEUE(q, osbuf);
790 A_PRINTF("%s(), allocation of netbuf failed", __func__);
795 static struct bin_attribute bmi_attr = {
796 .attr = {.name = "bmi", .mode = 0600},
797 .read = ar6000_sysfs_bmi_read,
798 .write = ar6000_sysfs_bmi_write,
802 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
803 struct bin_attribute *bin_attr,
804 char *buf, loff_t pos, size_t count)
808 HIF_DEVICE_OS_DEVICE_INFO *osDevInfo;
810 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", (A_UINT32)count));
811 for (index=0; index < MAX_AR6000; index++) {
812 ar = (AR_SOFTC_T *)ar6k_priv(ar6000_devices[index]);
813 osDevInfo = &ar->osDevInfo;
814 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
819 if (index == MAX_AR6000) return 0;
821 if ((BMIRawRead(ar->arHifDevice, (A_UCHAR*)buf, count, TRUE)) != A_OK) {
829 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
830 struct bin_attribute *bin_attr,
831 char *buf, loff_t pos, size_t count)
835 HIF_DEVICE_OS_DEVICE_INFO *osDevInfo;
837 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", (A_UINT32)count));
838 for (index=0; index < MAX_AR6000; index++) {
839 ar = (AR_SOFTC_T *)ar6k_priv(ar6000_devices[index]);
840 osDevInfo = &ar->osDevInfo;
841 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
846 if (index == MAX_AR6000) return 0;
848 if ((BMIRawWrite(ar->arHifDevice, (A_UCHAR*)buf, count)) != A_OK) {
856 ar6000_sysfs_bmi_init(AR_SOFTC_T *ar)
860 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n"));
861 A_MEMZERO(&ar->osDevInfo, sizeof(HIF_DEVICE_OS_DEVICE_INFO));
863 /* Get the underlying OS device */
864 status = HIFConfigureDevice(ar->arHifDevice,
865 HIF_DEVICE_GET_OS_DEVICE,
867 sizeof(HIF_DEVICE_OS_DEVICE_INFO));
869 if (A_FAILED(status)) {
870 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n"));
874 /* Create a bmi entry in the sysfs filesystem */
875 if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0)
877 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n"));
885 ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar)
887 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n"));
889 sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr);
892 #define bmifn(fn) do { \
894 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); \
899 #ifdef INIT_MODE_DRV_ENABLED
901 #ifdef SOFTMAC_FILE_USED
902 #define AR6002_MAC_ADDRESS_OFFSET 0x0A
903 #define AR6003_MAC_ADDRESS_OFFSET 0x16
905 void calculate_crc(A_UINT32 TargetType, A_UCHAR *eeprom_data)
908 A_UINT16 *ptr16_eeprom;
911 A_UINT32 eeprom_size;
913 if (TargetType == TARGET_TYPE_AR6001)
916 ptr_crc = (A_UINT16 *)eeprom_data;
918 else if (TargetType == TARGET_TYPE_AR6003)
921 ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04);
926 ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04);
933 // Recalculate new CRC
935 ptr16_eeprom = (A_UINT16 *)eeprom_data;
936 for (i = 0;i < eeprom_size; i += 2)
938 checksum = checksum ^ (*ptr16_eeprom);
941 checksum = 0xFFFF ^ checksum;
946 ar6000_softmac_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t size)
948 const char *source = "random generated";
949 const struct firmware *softmac_entry;
951 switch (ar->arTargetType) {
952 case TARGET_TYPE_AR6002:
953 ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET);
955 case TARGET_TYPE_AR6003:
956 ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET);
959 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Invalid Target Type\n"));
962 printk(KERN_DEBUG "MAC from EEPROM %pM\n", ptr_mac);
964 /* create a random MAC in case we cannot read file from system */
968 ptr_mac[3] = random32() & 0xff;
969 ptr_mac[4] = random32() & 0xff;
970 ptr_mac[5] = random32() & 0xff;
971 if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0)
973 A_CHAR *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1);
975 unsigned int softmac[6];
976 memcpy(macbuf, softmac_entry->data, softmac_entry->size);
977 macbuf[softmac_entry->size] = '\0';
978 if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x",
979 &softmac[0], &softmac[1], &softmac[2],
980 &softmac[3], &softmac[4], &softmac[5])==6) {
982 for (i=0; i<6; ++i) {
983 ptr_mac[i] = softmac[i] & 0xff;
985 source = "softmac file";
989 A_RELEASE_FIRMWARE(softmac_entry);
991 printk(KERN_DEBUG "MAC from %s %pM\n", source, ptr_mac);
992 calculate_crc(ar->arTargetType, eeprom_data);
994 #endif /* SOFTMAC_FILE_USED */
997 ar6000_transfer_bin_file(AR_SOFTC_T *ar, AR6K_BIN_FILE file, A_UINT32 address, A_BOOL compressed)
1000 const char *filename;
1001 const struct firmware *fw_entry;
1002 A_UINT32 fw_entry_size;
1006 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1007 filename = AR6003_REV1_OTP_FILE;
1008 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1009 filename = AR6003_REV2_OTP_FILE;
1011 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1016 case AR6K_FIRMWARE_FILE:
1017 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1018 filename = AR6003_REV1_FIRMWARE_FILE;
1019 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1020 filename = AR6003_REV2_FIRMWARE_FILE;
1022 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1028 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1029 filename = AR6003_REV1_EPPING_FIRMWARE_FILE;
1030 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1031 filename = AR6003_REV2_EPPING_FIRMWARE_FILE;
1033 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n",
1034 ar->arVersion.target_ver));
1040 #ifdef CONFIG_HOST_TCMD_SUPPORT
1042 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1043 filename = AR6003_REV1_TCMD_FIRMWARE_FILE;
1044 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1045 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
1047 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1053 #ifdef HTC_RAW_INTERFACE
1054 if (!eppingtest && bypasswmi) {
1055 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1056 filename = AR6003_REV1_ART_FIRMWARE_FILE;
1057 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1058 filename = AR6003_REV2_ART_FIRMWARE_FILE;
1060 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1068 case AR6K_PATCH_FILE:
1069 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1070 filename = AR6003_REV1_PATCH_FILE;
1071 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1072 filename = AR6003_REV2_PATCH_FILE;
1074 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1079 case AR6K_BOARD_DATA_FILE:
1080 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1081 filename = AR6003_REV1_BOARD_DATA_FILE;
1082 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1083 filename = AR6003_REV2_BOARD_DATA_FILE;
1085 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1091 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file));
1094 if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1096 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename));
1100 #ifdef SOFTMAC_FILE_USED
1101 if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) {
1102 ar6000_softmac_update(ar, (A_UCHAR *)fw_entry->data, fw_entry->size);
1107 fw_entry_size = fw_entry->size;
1109 /* Load extended board data for AR6003 */
1110 if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) {
1111 A_UINT32 board_ext_address;
1112 A_UINT32 board_ext_data_size;
1113 A_UINT32 board_data_size;
1115 board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \
1116 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0));
1118 board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \
1119 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0));
1121 /* Determine where in Target RAM to write Board Data */
1122 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (A_UCHAR *)&board_ext_address, 4));
1123 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address));
1125 /* check whether the target has allocated memory for extended board data and file contains extended board data */
1126 if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) {
1129 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(fw_entry->data + board_data_size), board_ext_data_size);
1131 if (status != A_OK) {
1132 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1133 A_RELEASE_FIRMWARE(fw_entry);
1137 /* Record the fact that extended board Data IS initialized */
1139 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_initialized), (A_UCHAR *)¶m, 4));
1141 fw_entry_size = board_data_size;
1145 status = BMIFastDownload(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size);
1147 status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size);
1150 if (status != A_OK) {
1151 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1152 A_RELEASE_FIRMWARE(fw_entry);
1155 A_RELEASE_FIRMWARE(fw_entry);
1158 #endif /* INIT_MODE_DRV_ENABLED */
1161 ar6000_update_bdaddr(AR_SOFTC_T *ar)
1164 if (setupbtdev != 0) {
1167 if (BMIReadMemory(ar->arHifDevice,
1168 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (A_UCHAR *)&address, 4) != A_OK)
1170 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n"));
1174 if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (A_UCHAR *)ar->bdaddr, 6) != A_OK)
1176 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n"));
1179 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0],
1180 ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3],
1181 ar->bdaddr[4], ar->bdaddr[5]));
1188 ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode)
1190 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n"));
1192 if (mode == WLAN_INIT_MODE_UDEV) {
1194 const struct firmware *fw_entry;
1196 /* Get config using udev through a script in user space */
1197 sprintf(version, "%2.2x", ar->arVersion.target_ver);
1198 if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1200 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version));
1204 A_RELEASE_FIRMWARE(fw_entry);
1205 #ifdef INIT_MODE_DRV_ENABLED
1207 /* The config is contained within the driver itself */
1209 A_UINT32 param, options, sleep, address;
1211 /* Temporarily disable system sleep */
1212 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1213 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1215 param |= AR6K_OPTION_SLEEP_DISABLE;
1216 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1218 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1219 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1221 param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1);
1222 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1223 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep));
1225 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1226 /* Program analog PLL register */
1227 bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001));
1228 /* Run at 80/88MHz by default */
1229 param = CPU_CLOCK_STANDARD_SET(1);
1231 /* Run at 40/44MHz by default */
1232 param = CPU_CLOCK_STANDARD_SET(0);
1234 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1235 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1238 if (ar->arTargetType == TARGET_TYPE_AR6002) {
1239 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (A_UCHAR *)¶m, 4));
1242 /* LPO_CAL.ENABLE = 1 if no external clk is detected */
1244 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1245 param = LPO_CAL_ENABLE_SET(1);
1246 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1249 /* Venus2.0: Lower SDIO pad drive strength,
1250 * temporary WAR to avoid SDIO CRC error */
1251 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1252 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n"));
1254 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1255 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1257 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1258 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1260 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1261 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1263 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1264 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1267 #ifdef FORCE_INTERNAL_CLOCK
1268 /* Ignore external clock, if any, and force use of internal clock */
1269 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1270 /* hi_ext_clk_detected = 0 */
1272 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (A_UCHAR *)¶m, 4));
1274 /* CLOCK_CONTROL &= ~LF_CLK32 */
1275 address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS;
1276 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1277 param &= (~CLOCK_CONTROL_LF_CLK32_SET(1));
1278 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1280 #endif /* FORCE_INTERNAL_CLOCK */
1282 /* Transfer Board Data from Target EEPROM to Target RAM */
1283 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1284 /* Determine where in Target RAM to write Board Data */
1285 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (A_UCHAR *)&address, 4));
1286 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address));
1288 /* Write EEPROM data to Target RAM */
1289 if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, FALSE)) != A_OK) {
1293 /* Record the fact that Board Data IS initialized */
1295 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (A_UCHAR *)¶m, 4));
1297 /* Transfer One time Programmable data */
1298 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1299 status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, TRUE);
1300 if (status == A_OK) {
1301 /* Execute the OTP code */
1303 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1304 bmifn(BMIExecute(ar->arHifDevice, address, ¶m));
1305 } else if (status != A_ENOENT) {
1309 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType));
1313 /* Download Target firmware */
1314 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1315 if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, TRUE)) != A_OK) {
1319 /* Set starting address for firmware */
1320 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1321 bmifn(BMISetAppStart(ar->arHifDevice, address));
1323 /* Apply the patches */
1324 AR6K_PATCH_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1325 if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, FALSE)) != A_OK) {
1330 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), (A_UCHAR *)¶m, 4));
1332 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1333 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1334 /* Reserve 5.5K of RAM */
1336 } else { /* AR6003_REV2_VERSION */
1337 /* Reserve 6.5K of RAM */
1340 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_end_RAM_reserve_sz), (A_UCHAR *)¶m, 4));
1343 /* Restore system sleep */
1344 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1345 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep));
1347 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1348 param = options | 0x20;
1349 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1351 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1352 /* Configure GPIO AR6003 UART */
1353 #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN
1354 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
1356 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1357 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (A_UCHAR *)¶m, 4));
1359 #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23)
1361 address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS;
1362 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1363 param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1);
1364 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1368 /* Configure GPIO for BT Reset */
1369 #ifdef ATH6KL_CONFIG_GPIO_BT_RESET
1370 #define CONFIG_AR600x_BT_RESET_PIN 0x16
1371 param = CONFIG_AR600x_BT_RESET_PIN;
1372 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (A_UCHAR *)¶m, 4));
1373 #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */
1375 /* Configure UART flow control polarity */
1376 #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY
1377 #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0
1380 #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1)
1381 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1382 param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2);
1383 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (A_UCHAR *)¶m, 4));
1385 #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */
1388 #ifdef HTC_RAW_INTERFACE
1389 if (!eppingtest && bypasswmi) {
1390 /* Don't run BMIDone for ART mode and force resetok=0 */
1394 #endif /* HTC_RAW_INTERFACE */
1396 #endif /* INIT_MODE_DRV_ENABLED */
1403 ar6000_configure_target(AR_SOFTC_T *ar)
1406 if (enableuartprint) {
1408 if (BMIWriteMemory(ar->arHifDevice,
1409 HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable),
1413 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n"));
1416 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n"));
1419 /* Tell target which HTC version it is used*/
1420 param = HTC_PROTOCOL_VERSION;
1421 if (BMIWriteMemory(ar->arHifDevice,
1422 HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest),
1426 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n"));
1430 #ifdef CONFIG_HOST_TCMD_SUPPORT
1432 ar->arTargetMode = AR6000_TCMD_MODE;
1434 ar->arTargetMode = AR6000_WLAN_MODE;
1437 if (enabletimerwar) {
1440 if (BMIReadMemory(ar->arHifDevice,
1441 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1445 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n"));
1449 param |= HI_OPTION_TIMER_WAR;
1451 if (BMIWriteMemory(ar->arHifDevice,
1452 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1456 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n"));
1459 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n"));
1462 /* set the firmware mode to STA/IBSS/AP */
1466 if (BMIReadMemory(ar->arHifDevice,
1467 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1471 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n"));
1475 param |= (fwmode << HI_OPTION_FW_MODE_SHIFT);
1477 if (BMIWriteMemory(ar->arHifDevice,
1478 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1482 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n"));
1485 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1488 #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS
1492 if (BMIReadMemory(ar->arHifDevice,
1493 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1497 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n"));
1501 param |= HI_OPTION_DISABLE_DBGLOG;
1503 if (BMIWriteMemory(ar->arHifDevice,
1504 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1508 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n"));
1511 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1513 #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */
1516 * Hardcode the address use for the extended board data
1517 * Ideally this should be pre-allocate by the OS at boot time
1518 * But since it is a new feature and board data is loaded
1519 * at init time, we have to workaround this from host.
1520 * It is difficult to patch the firmware boot code,
1521 * but possible in theory.
1523 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1524 param = AR6003_BOARD_EXT_DATA_ADDRESS;
1525 if (BMIWriteMemory(ar->arHifDevice,
1526 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data),
1530 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n"));
1536 /* since BMIInit is called in the driver layer, we have to set the block
1537 * size here for the target */
1539 if (A_FAILED(ar6000_set_htc_params(ar->arHifDevice,
1542 0 /* use default number of control buffers */
1547 if (setupbtdev != 0) {
1548 if (A_FAILED(ar6000_set_hci_bridge_flags(ar->arHifDevice,
1558 init_netdev(struct net_device *dev, char *name)
1560 dev->netdev_ops = &ar6000_netdev_ops;
1561 dev->watchdog_timeo = AR6000_TX_TIMEOUT;
1562 dev->wireless_handlers = &ath_iw_handler_def;
1564 ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */
1567 * We need the OS to provide us with more headroom in order to
1568 * perform dix to 802.3, WMI header encap, and the HTC header
1570 if (processDot11Hdr) {
1571 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;
1573 dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) +
1574 sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
1579 strcpy(dev->name, name);
1582 #ifdef SET_MODULE_OWNER
1583 SET_MODULE_OWNER(dev);
1586 #ifdef CONFIG_CHECKSUM_OFFLOAD
1588 dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/
1596 * HTC Event handlers
1599 ar6000_avail_ev(void *context, void *hif_handle)
1602 struct net_device *dev;
1605 int device_index = 0;
1606 HTC_INIT_INFO htcInfo;
1607 #ifdef ATH6K_CONFIG_CFG80211
1608 struct wireless_dev *wdev;
1609 #endif /* ATH6K_CONFIG_CFG80211 */
1610 A_STATUS init_status = A_OK;
1612 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n"));
1614 for (i=0; i < MAX_AR6000; i++) {
1615 if (ar6000_devices[i] == NULL) {
1620 if (i == MAX_AR6000) {
1621 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n"));
1625 /* Save this. It gives a bit better readability especially since */
1626 /* we use another local "i" variable below. */
1629 #ifdef ATH6K_CONFIG_CFG80211
1630 wdev = ar6k_cfg80211_init(NULL);
1632 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__));
1635 ar_netif = wdev_priv(wdev);
1637 dev = alloc_etherdev(sizeof(AR_SOFTC_T));
1639 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n"));
1643 ar_netif = ar6k_priv(dev);
1644 #endif /* ATH6K_CONFIG_CFG80211 */
1646 if (ar_netif == NULL) {
1647 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__));
1651 A_MEMZERO(ar_netif, sizeof(AR_SOFTC_T));
1652 ar = (AR_SOFTC_T *)ar_netif;
1654 #ifdef ATH6K_CONFIG_CFG80211
1656 wdev->iftype = NL80211_IFTYPE_STATION;
1658 dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1);
1660 printk(KERN_CRIT "AR6K: no memory for network device instance\n");
1661 ar6k_cfg80211_deinit(ar);
1665 dev->ieee80211_ptr = wdev;
1666 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1668 ar->arNetworkType = INFRA_NETWORK;
1669 #endif /* ATH6K_CONFIG_CFG80211 */
1671 init_netdev(dev, ifname);
1673 #ifdef SET_NETDEV_DEV
1675 HIF_DEVICE_OS_DEVICE_INFO osDevInfo;
1676 A_MEMZERO(&osDevInfo, sizeof(osDevInfo));
1677 if ( A_SUCCESS( HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE,
1678 &osDevInfo, sizeof(osDevInfo))) ) {
1679 SET_NETDEV_DEV(dev, osDevInfo.pOSDevice);
1685 ar->arHifDevice = hif_handle;
1686 ar->arWlanState = WLAN_ENABLED;
1687 ar->arDeviceIndex = device_index;
1689 ar->arWlanPowerState = WLAN_POWER_STATE_ON;
1690 ar->arWlanOff = FALSE; /* We are in ON state */
1692 ar->arWowState = WLAN_WOW_STATE_NONE;
1693 ar->arBTOff = TRUE; /* BT chip assumed to be OFF */
1694 ar->arBTSharing = WLAN_CONFIG_BT_SHARING;
1695 ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF;
1696 ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND;
1697 ar->arWow2Config = WLAN_CONFIG_PM_WOW2;
1698 #endif /* CONFIG_PM */
1700 A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev);
1701 ar->arHBChallengeResp.seqNum = 0;
1702 ar->arHBChallengeResp.outstanding = FALSE;
1703 ar->arHBChallengeResp.missCnt = 0;
1704 ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT;
1705 ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT;
1707 ar6000_init_control_info(ar);
1708 init_waitqueue_head(&arEvent);
1709 sema_init(&ar->arSem, 1);
1710 ar->bIsDestroyProgress = FALSE;
1712 INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue);
1714 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
1715 A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar);
1716 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
1718 A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev);
1723 ar6000_sysfs_bmi_init(ar);
1727 struct bmi_target_info targ_info;
1729 if (BMIGetTargetInfo(ar->arHifDevice, &targ_info) != A_OK) {
1730 init_status = A_ERROR;
1731 goto avail_ev_failed;
1734 ar->arVersion.target_ver = targ_info.target_ver;
1735 ar->arTargetType = targ_info.target_type;
1737 /* do any target-specific preparation that can be done through BMI */
1738 if (ar6000_prepare_target(ar->arHifDevice,
1739 targ_info.target_type,
1740 targ_info.target_ver) != A_OK) {
1741 init_status = A_ERROR;
1742 goto avail_ev_failed;
1747 if (ar6000_configure_target(ar) != A_OK) {
1748 init_status = A_ERROR;
1749 goto avail_ev_failed;
1752 A_MEMZERO(&htcInfo,sizeof(htcInfo));
1753 htcInfo.pContext = ar;
1754 htcInfo.TargetFailure = ar6000_target_failure;
1756 ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo);
1758 if (ar->arHtcTarget == NULL) {
1759 init_status = A_ERROR;
1760 goto avail_ev_failed;
1763 spin_lock_init(&ar->arLock);
1766 ar->arWapiEnable = 0;
1770 #ifdef CONFIG_CHECKSUM_OFFLOAD
1772 /*if external frame work is also needed, change and use an extended rxMetaVerion*/
1773 ar->rxMetaVersion=WMI_META_VERSION_2;
1777 #ifdef ATH_AR6K_11N_SUPPORT
1778 if((ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs)) == NULL) {
1779 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__));
1780 init_status = A_ERROR;
1781 goto avail_ev_failed;
1784 aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack);
1787 HIFClaimDevice(ar->arHifDevice, ar);
1789 /* We only register the device in the global list if we succeed. */
1790 /* If the device is in the global list, it will be destroyed */
1791 /* when the module is unloaded. */
1792 ar6000_devices[device_index] = dev;
1794 /* Don't install the init function if BMI is requested */
1796 ar6000_netdev_ops.ndo_init = ar6000_init;
1798 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode));
1799 if ((wlaninitmode == WLAN_INIT_MODE_UDEV) ||
1800 (wlaninitmode == WLAN_INIT_MODE_DRV))
1802 A_STATUS status = A_OK;
1804 if ((status = ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK)
1806 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
1809 #ifdef HTC_RAW_INTERFACE
1810 break; /* Don't call ar6000_init for ART */
1813 status = (ar6000_init(dev)==0) ? A_OK : A_ERROR;
1815 if (status != A_OK) {
1816 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n"));
1820 if (status != A_OK) {
1821 init_status = status;
1822 goto avail_ev_failed;
1827 /* This runs the init function if registered */
1828 if (register_netdev(dev)) {
1829 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n"));
1830 ar6000_destroy(dev, 0);
1834 is_netdev_registered = 1;
1836 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
1838 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
1839 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n",
1840 dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index,
1841 (unsigned long)ar));
1844 if (A_FAILED(init_status)) {
1846 ar6000_sysfs_bmi_deinit(ar);
1853 static void ar6000_target_failure(void *Instance, A_STATUS Status)
1855 AR_SOFTC_T *ar = (AR_SOFTC_T *)Instance;
1856 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
1857 static A_BOOL sip = FALSE;
1859 if (Status != A_OK) {
1861 printk(KERN_ERR "ar6000_target_failure: target asserted \n");
1863 if (timer_pending(&ar->arHBChallengeResp.timer)) {
1864 A_UNTIMEOUT(&ar->arHBChallengeResp.timer);
1867 /* try dumping target assertion information (if any) */
1868 ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType);
1871 * Fetch the logs from the target via the diagnostic
1874 ar6000_dbglog_get_debug_logs(ar);
1876 /* Report the error only once */
1879 errEvent.errorVal = WMI_TARGET_COM_ERR |
1880 WMI_TARGET_FATAL_ERR;
1881 ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID,
1882 (A_UINT8 *)&errEvent,
1883 sizeof(WMI_TARGET_ERROR_REPORT_EVENT));
1889 ar6000_unavail_ev(void *context, void *hif_handle)
1891 AR_SOFTC_T *ar = (AR_SOFTC_T *)context;
1892 /* NULL out it's entry in the global list */
1893 ar6000_devices[ar->arDeviceIndex] = NULL;
1894 ar6000_destroy(ar->arNetDev, 1);
1900 ar6000_restart_endpoint(struct net_device *dev)
1902 A_STATUS status = A_OK;
1903 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
1907 if ( (status=ar6000_configure_target(ar))!=A_OK)
1909 if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK)
1911 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
1915 status = (ar6000_init(dev)==0) ? A_OK : A_ERROR;
1921 if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) {
1922 ar6000_connect_to_ap(ar);
1930 ar6000_devices[ar->arDeviceIndex] = NULL;
1931 ar6000_destroy(ar->arNetDev, 1);
1935 ar6000_stop_endpoint(struct net_device *dev, A_BOOL keepprofile, A_BOOL getdbglogs)
1937 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
1939 /* Stop the transmit queues */
1940 netif_stop_queue(dev);
1942 /* Disable the target and the interrupts associated with it */
1943 if (ar->arWmiReady == TRUE)
1947 if (ar->arConnected == TRUE || ar->arConnectPending == TRUE)
1949 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Disconnect\n", __func__));
1951 AR6000_SPIN_LOCK(&ar->arLock, 0);
1952 ar6000_init_profile_info(ar);
1953 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
1955 wmi_disconnect_cmd(ar->arWmi);
1958 A_UNTIMEOUT(&ar->disconnect_timer);
1961 ar6000_dbglog_get_debug_logs(ar);
1964 ar->arWmiReady = FALSE;
1965 wmi_shutdown(ar->arWmi);
1966 ar->arWmiEnabled = FALSE;
1969 * After wmi_shudown all WMI events will be dropped.
1970 * We need to cleanup the buffers allocated in AP mode
1971 * and give disconnect notification to stack, which usually
1972 * happens in the disconnect_event.
1973 * Simulate the disconnect_event by calling the function directly.
1974 * Sometimes disconnect_event will be received when the debug logs
1977 if (ar->arConnected == TRUE || ar->arConnectPending == TRUE) {
1978 if(ar->arNetworkType & AP_NETWORK) {
1979 ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0);
1981 ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0);
1983 ar->arConnected = FALSE;
1984 ar->arConnectPending = FALSE;
1987 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
1988 ar->user_key_ctrl = 0;
1992 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__));
1996 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n",
1997 __func__, (unsigned long) ar, (unsigned long) ar->arWmi));
1999 /* Shut down WMI if we have started it */
2000 if(ar->arWmiEnabled == TRUE)
2002 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__));
2003 wmi_shutdown(ar->arWmi);
2004 ar->arWmiEnabled = FALSE;
2009 if (ar->arHtcTarget != NULL) {
2010 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2011 if (NULL != ar6kHciTransCallbacks.cleanupTransport) {
2012 ar6kHciTransCallbacks.cleanupTransport(NULL);
2015 // FIXME: workaround to reset BT's UART baud rate to default
2016 if (NULL != ar->exitCallback) {
2017 AR3K_CONFIG_INFO ar3kconfig;
2020 A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig));
2021 ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig);
2022 status = ar->exitCallback(&ar3kconfig);
2023 if (A_OK != status) {
2024 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n"));
2029 ar6000_cleanup_hci(ar);
2031 #ifdef EXPORT_HCI_PAL_INTERFACE
2032 if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.cleanupTransport)) {
2033 ar6kHciPalCallbacks_g.cleanupTransport(ar);
2036 /* cleanup hci pal driver data structures */
2038 ar6k_cleanup_hci_pal(ar);
2040 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n"));
2042 HTCStop(ar->arHtcTarget);
2046 /* try to reset the device if we can
2047 * The driver may have been configure NOT to reset the target during
2048 * a debug session */
2049 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Attempting to reset target on instance destroy.... \n"));
2050 if (ar->arHifDevice != NULL) {
2051 A_BOOL coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? TRUE: FALSE;
2052 ar6000_reset_device(ar->arHifDevice, ar->arTargetType, TRUE, coldReset);
2055 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n"));
2057 /* Done with cookies */
2058 ar6000_cookie_cleanup(ar);
2061 * We need to differentiate between the surprise and planned removal of the
2062 * device because of the following consideration:
2063 * - In case of surprise removal, the hcd already frees up the pending
2064 * for the device and hence there is no need to unregister the function
2065 * driver inorder to get these requests. For planned removal, the function
2066 * driver has to explictly unregister itself to have the hcd return all the
2067 * pending requests before the data structures for the devices are freed up.
2068 * Note that as per the current implementation, the function driver will
2069 * end up releasing all the devices since there is no API to selectively
2070 * release a particular device.
2071 * - Certain commands issued to the target can be skipped for surprise
2072 * removal since they will anyway not go through.
2075 ar6000_destroy(struct net_device *dev, unsigned int unregister)
2079 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n"));
2081 if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL))
2083 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__));
2087 ar->bIsDestroyProgress = TRUE;
2089 if (down_interruptible(&ar->arSem)) {
2090 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__));
2094 if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) {
2095 /* only stop endpoint if we are not stop it in suspend_ev */
2096 ar6000_stop_endpoint(dev, FALSE, TRUE);
2098 /* clear up the platform power state before rmmod */
2099 plat_setup_power(1,0);
2102 ar->arWlanState = WLAN_DISABLED;
2103 if (ar->arHtcTarget != NULL) {
2105 HTCDestroy(ar->arHtcTarget);
2107 if (ar->arHifDevice != NULL) {
2108 /*release the device so we do not get called back on remove incase we
2109 * we're explicity destroyed by module unload */
2110 HIFReleaseDevice(ar->arHifDevice);
2111 HIFShutDownDevice(ar->arHifDevice);
2113 #ifdef ATH_AR6K_11N_SUPPORT
2114 aggr_module_destroy(ar->aggr_cntxt);
2117 /* Done with cookies */
2118 ar6000_cookie_cleanup(ar);
2120 /* cleanup any allocated AMSDU buffers */
2121 ar6000_cleanup_amsdu_rxbufs(ar);
2124 ar6000_sysfs_bmi_deinit(ar);
2130 /* Clear the tx counters */
2131 memset(tx_attempt, 0, sizeof(tx_attempt));
2132 memset(tx_post, 0, sizeof(tx_post));
2133 memset(tx_complete, 0, sizeof(tx_complete));
2135 #ifdef HTC_RAW_INTERFACE
2137 A_FREE(ar->arRawHtc);
2138 ar->arRawHtc = NULL;
2141 /* Free up the device data structure */
2142 if (unregister && is_netdev_registered) {
2143 unregister_netdev(dev);
2144 is_netdev_registered = 0;
2148 #ifdef ATH6K_CONFIG_CFG80211
2149 ar6k_cfg80211_deinit(ar);
2150 #endif /* ATH6K_CONFIG_CFG80211 */
2152 #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT
2153 ar6000_remove_ap_interface();
2154 #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
2156 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n"));
2159 static void disconnect_timer_handler(unsigned long ptr)
2161 struct net_device *dev = (struct net_device *)ptr;
2162 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2164 A_UNTIMEOUT(&ar->disconnect_timer);
2166 ar6000_init_profile_info(ar);
2167 wmi_disconnect_cmd(ar->arWmi);
2170 static void ar6000_detect_error(unsigned long ptr)
2172 struct net_device *dev = (struct net_device *)ptr;
2173 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2174 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
2176 AR6000_SPIN_LOCK(&ar->arLock, 0);
2178 if (ar->arHBChallengeResp.outstanding) {
2179 ar->arHBChallengeResp.missCnt++;
2181 ar->arHBChallengeResp.missCnt = 0;
2184 if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) {
2185 /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */
2186 ar->arHBChallengeResp.missCnt = 0;
2187 ar->arHBChallengeResp.seqNum = 0;
2188 errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR;
2189 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2190 ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID,
2191 (A_UINT8 *)&errEvent,
2192 sizeof(WMI_TARGET_ERROR_REPORT_EVENT));
2196 /* Generate the sequence number for the next challenge */
2197 ar->arHBChallengeResp.seqNum++;
2198 ar->arHBChallengeResp.outstanding = TRUE;
2200 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2202 /* Send the challenge on the control channel */
2203 if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != A_OK) {
2204 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n"));
2208 /* Reschedule the timer for the next challenge */
2209 A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0);
2212 void ar6000_init_profile_info(AR_SOFTC_T *ar)
2215 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
2218 case HI_OPTION_FW_MODE_IBSS:
2219 ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK;
2221 case HI_OPTION_FW_MODE_BSS_STA:
2222 ar->arNetworkType = ar->arNextMode = INFRA_NETWORK;
2224 case HI_OPTION_FW_MODE_AP:
2225 ar->arNetworkType = ar->arNextMode = AP_NETWORK;
2229 ar->arDot11AuthMode = OPEN_AUTH;
2230 ar->arAuthMode = NONE_AUTH;
2231 ar->arPairwiseCrypto = NONE_CRYPT;
2232 ar->arPairwiseCryptoLen = 0;
2233 ar->arGroupCrypto = NONE_CRYPT;
2234 ar->arGroupCryptoLen = 0;
2235 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2236 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
2237 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
2238 ar->arBssChannel = 0;
2239 ar->arConnected = FALSE;
2243 ar6000_init_control_info(AR_SOFTC_T *ar)
2245 ar->arWmiEnabled = FALSE;
2246 ar6000_init_profile_info(ar);
2247 ar->arDefTxKeyIndex = 0;
2248 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2249 ar->arChannelHint = 0;
2250 ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL;
2251 ar->arListenIntervalB = 0;
2252 ar->arVersion.host_ver = AR6K_SW_VERSION;
2255 ar->arTxPwrSet = FALSE;
2257 ar->arBeaconInterval = 0;
2259 ar->arMaxRetries = 0;
2260 ar->arWmmEnabled = TRUE;
2262 ar->scan_triggered = 0;
2263 A_MEMZERO(&ar->scParams, sizeof(ar->scParams));
2264 ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT;
2265 ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS;
2267 /* Initialize the AP mode state info */
2270 A_MEMZERO((A_UINT8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t));
2272 /* init the Mutexes */
2273 A_MUTEX_INIT(&ar->mcastpsqLock);
2275 /* Init the PS queues */
2276 for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) {
2277 A_MUTEX_INIT(&ar->sta_list[ctr].psqLock);
2278 A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq);
2281 ar->ap_profile_flag = 0;
2282 A_NETBUF_QUEUE_INIT(&ar->mcastpsq);
2284 A_MEMCPY(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
2285 ar->ap_wmode = DEF_AP_WMODE_G;
2286 ar->ap_dtim_period = DEF_AP_DTIM;
2287 ar->ap_beacon_interval = DEF_BEACON_INTERVAL;
2292 ar6000_open(struct net_device *dev)
2294 unsigned long flags;
2295 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2297 spin_lock_irqsave(&ar->arLock, flags);
2299 #ifdef ATH6K_CONFIG_CFG80211
2300 if(ar->arWlanState == WLAN_DISABLED) {
2301 ar->arWlanState = WLAN_ENABLED;
2303 #endif /* ATH6K_CONFIG_CFG80211 */
2305 if( ar->arConnected || bypasswmi) {
2306 netif_carrier_on(dev);
2307 /* Wake up the queues */
2308 netif_wake_queue(dev);
2311 netif_carrier_off(dev);
2313 spin_unlock_irqrestore(&ar->arLock, flags);
2318 ar6000_close(struct net_device *dev)
2320 #ifdef ATH6K_CONFIG_CFG80211
2321 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2322 #endif /* ATH6K_CONFIG_CFG80211 */
2323 netif_stop_queue(dev);
2325 #ifdef ATH6K_CONFIG_CFG80211
2326 AR6000_SPIN_LOCK(&ar->arLock, 0);
2327 if (ar->arConnected == TRUE || ar->arConnectPending == TRUE) {
2328 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2329 wmi_disconnect_cmd(ar->arWmi);
2331 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2334 if(ar->arWmiReady == TRUE) {
2335 if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0,
2336 0, 0, 0, 0, 0, 0, 0, 0) != A_OK) {
2339 ar->arWlanState = WLAN_DISABLED;
2341 #endif /* ATH6K_CONFIG_CFG80211 */
2346 /* connect to a service */
2347 static A_STATUS ar6000_connectservice(AR_SOFTC_T *ar,
2348 HTC_SERVICE_CONNECT_REQ *pConnect,
2352 HTC_SERVICE_CONNECT_RESP response;
2356 A_MEMZERO(&response,sizeof(response));
2358 status = HTCConnectService(ar->arHtcTarget,
2362 if (A_FAILED(status)) {
2363 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n",
2367 switch (pConnect->ServiceID) {
2368 case WMI_CONTROL_SVC :
2369 if (ar->arWmiEnabled) {
2370 /* set control endpoint for WMI use */
2371 wmi_set_control_ep(ar->arWmi, response.Endpoint);
2373 /* save EP for fast lookup */
2374 ar->arControlEp = response.Endpoint;
2376 case WMI_DATA_BE_SVC :
2377 arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint);
2379 case WMI_DATA_BK_SVC :
2380 arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint);
2382 case WMI_DATA_VI_SVC :
2383 arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint);
2385 case WMI_DATA_VO_SVC :
2386 arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint);
2389 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID));
2399 void ar6000_TxDataCleanup(AR_SOFTC_T *ar)
2401 /* flush all the data (non-control) streams
2402 * we only flush packets that are tagged as data, we leave any control packets that
2403 * were in the TX queues alone */
2404 HTCFlushEndpoint(ar->arHtcTarget,
2405 arAc2EndpointID(ar, WMM_AC_BE),
2407 HTCFlushEndpoint(ar->arHtcTarget,
2408 arAc2EndpointID(ar, WMM_AC_BK),
2410 HTCFlushEndpoint(ar->arHtcTarget,
2411 arAc2EndpointID(ar, WMM_AC_VI),
2413 HTCFlushEndpoint(ar->arHtcTarget,
2414 arAc2EndpointID(ar, WMM_AC_VO),
2419 ar6000_ac2_endpoint_id ( void * devt, A_UINT8 ac)
2421 AR_SOFTC_T *ar = (AR_SOFTC_T *) devt;
2422 return(arAc2EndpointID(ar, ac));
2426 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep )
2428 AR_SOFTC_T *ar = (AR_SOFTC_T *) devt;
2429 return(arEndpoint2Ac(ar, ep ));
2432 /* This function does one time initialization for the lifetime of the device */
2433 int ar6000_init(struct net_device *dev)
2440 #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE)
2441 WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd;
2442 WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd;
2443 #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */
2445 if((ar = ar6k_priv(dev)) == NULL)
2450 if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) {
2452 ar6000_update_bdaddr(ar);
2454 if (enablerssicompensation) {
2455 ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType);
2456 read_rssi_compensation_param(ar);
2457 for (i=-95; i<=0; i++) {
2458 rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i);
2466 /* Do we need to finish the BMI phase */
2467 if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) &&
2468 (BMIDone(ar->arHifDevice) != A_OK))
2471 goto ar6000_init_done;
2477 if (ar->arVersion.host_ver != ar->arVersion.target_ver) {
2478 A_PRINTF("WARNING: Host version 0x%x does not match Target "
2480 ar->arVersion.host_ver, ar->arVersion.target_ver);
2484 /* Indicate that WMI is enabled (although not ready yet) */
2485 ar->arWmiEnabled = TRUE;
2486 if ((ar->arWmi = wmi_init((void *) ar)) == NULL)
2488 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__));
2490 goto ar6000_init_done;
2493 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__,
2494 (unsigned long) ar->arWmi));
2498 HTC_SERVICE_CONNECT_REQ connect;
2500 /* the reason we have to wait for the target here is that the driver layer
2501 * has to init BMI in order to set the host block size,
2503 status = HTCWaitTarget(ar->arHtcTarget);
2505 if (A_FAILED(status)) {
2509 A_MEMZERO(&connect,sizeof(connect));
2510 /* meta data is unused for now */
2511 connect.pMetaData = NULL;
2512 connect.MetaDataLength = 0;
2513 /* these fields are the same for all service endpoints */
2514 connect.EpCallbacks.pContext = ar;
2515 connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete;
2516 connect.EpCallbacks.EpRecv = ar6000_rx;
2517 connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill;
2518 connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full;
2519 /* set the max queue depth so that our ar6000_tx_queue_full handler gets called.
2520 * Linux has the peculiarity of not providing flow control between the
2521 * NIC and the network stack. There is no API to indicate that a TX packet
2522 * was sent which could provide some back pressure to the network stack.
2523 * Under linux you would have to wait till the network stack consumed all sk_buffs
2524 * before any back-flow kicked in. Which isn't very friendly.
2525 * So we have to manage this ourselves */
2526 connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
2527 connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */
2528 if (0 == connect.EpCallbacks.RecvRefillWaterMark) {
2529 connect.EpCallbacks.RecvRefillWaterMark++;
2531 /* connect to control service */
2532 connect.ServiceID = WMI_CONTROL_SVC;
2533 status = ar6000_connectservice(ar,
2536 if (A_FAILED(status)) {
2540 connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING;
2541 /* limit the HTC message size on the send path, although we can receive A-MSDU frames of
2542 * 4K, we will only send ethernet-sized (802.3) frames on the send path. */
2543 connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH;
2545 /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold
2546 * mechanism for larger packets */
2547 connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE;
2548 connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf;
2550 /* for the remaining data services set the connection flag to reduce dribbling,
2551 * if configured to do so */
2552 if (reduce_credit_dribble) {
2553 connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE;
2554 /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value
2556 connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2557 connect.ConnectionFlags |=
2558 ((A_UINT16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2560 /* connect to best-effort service */
2561 connect.ServiceID = WMI_DATA_BE_SVC;
2563 status = ar6000_connectservice(ar,
2566 if (A_FAILED(status)) {
2570 /* connect to back-ground
2571 * map this to WMI LOW_PRI */
2572 connect.ServiceID = WMI_DATA_BK_SVC;
2573 status = ar6000_connectservice(ar,
2576 if (A_FAILED(status)) {
2580 /* connect to Video service, map this to
2582 connect.ServiceID = WMI_DATA_VI_SVC;
2583 status = ar6000_connectservice(ar,
2586 if (A_FAILED(status)) {
2590 /* connect to VO service, this is currently not
2591 * mapped to a WMI priority stream due to historical reasons.
2592 * WMI originally defined 3 priorities over 3 mailboxes
2593 * We can change this when WMI is reworked so that priorities are not
2594 * dependent on mailboxes */
2595 connect.ServiceID = WMI_DATA_VO_SVC;
2596 status = ar6000_connectservice(ar,
2599 if (A_FAILED(status)) {
2603 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0);
2604 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0);
2605 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0);
2606 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0);
2608 /* setup access class priority mappings */
2609 ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */
2610 ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */
2611 ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */
2612 ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */
2614 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2615 if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) {
2616 HCI_TRANSPORT_MISC_HANDLES hciHandles;
2618 hciHandles.netDevice = ar->arNetDev;
2619 hciHandles.hifDevice = ar->arHifDevice;
2620 hciHandles.htcHandle = ar->arHtcTarget;
2621 status = (A_STATUS)(ar6kHciTransCallbacks.setupTransport(&hciHandles));
2626 status = ar6000_setup_hci(ar);
2629 #ifdef EXPORT_HCI_PAL_INTERFACE
2630 if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.setupTransport))
2631 status = ar6kHciPalCallbacks_g.setupTransport(ar);
2634 status = ar6k_setup_hci_pal(ar);
2639 if (A_FAILED(status)) {
2641 goto ar6000_init_done;
2645 * give our connected endpoints some buffers
2648 ar6000_rx_refill(ar, ar->arControlEp);
2649 ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE));
2652 * We will post the receive buffers only for SPE or endpoint ping testing so we are
2653 * making it conditional on the 'bypasswmi' flag.
2656 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK));
2657 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI));
2658 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO));
2661 /* allocate some buffers that handle larger AMSDU frames */
2662 ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS);
2664 /* setup credit distribution */
2665 ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo);
2667 /* Since cookies are used for HTC transports, they should be */
2668 /* initialized prior to enabling HTC. */
2669 ar6000_cookie_init(ar);
2672 status = HTCStart(ar->arHtcTarget);
2674 if (status != A_OK) {
2675 if (ar->arWmiEnabled == TRUE) {
2676 wmi_shutdown(ar->arWmi);
2677 ar->arWmiEnabled = FALSE;
2680 ar6000_cookie_cleanup(ar);
2682 goto ar6000_init_done;
2686 /* Wait for Wmi event to be ready */
2687 timeleft = wait_event_interruptible_timeout(arEvent,
2688 (ar->arWmiReady == TRUE), wmitimeout * HZ);
2690 if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) {
2691 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver));
2692 #ifndef ATH6K_SKIP_ABI_VERSION_CHECK
2694 goto ar6000_init_done;
2695 #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */
2698 if(!timeleft || signal_pending(current))
2700 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n"));
2702 goto ar6000_init_done;
2705 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__));
2707 /* Communicate the wmi protocol verision to the target */
2708 if ((ar6000_set_host_app_area(ar)) != A_OK) {
2709 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n"));
2712 /* configure the device for rx dot11 header rules 0,0 are the default values
2713 * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required
2714 if checksum offload is needed. Set RxMetaVersion to 2*/
2715 if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != A_OK) {
2716 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n"));
2719 #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE)
2720 /* Configure the type of BT collocated with WLAN */
2721 A_MEMZERO(&sbcb_cmd, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD));
2722 #ifdef CONFIG_AR600x_BT_QCOM
2723 sbcb_cmd.btcoexCoLocatedBTdev = 1;
2724 #elif defined(CONFIG_AR600x_BT_CSR)
2725 sbcb_cmd.btcoexCoLocatedBTdev = 2;
2726 #elif defined(CONFIG_AR600x_BT_AR3001)
2727 sbcb_cmd.btcoexCoLocatedBTdev = 3;
2729 #error Unsupported Bluetooth Type
2730 #endif /* Collocated Bluetooth Type */
2732 if ((wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd)) != A_OK)
2734 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n"));
2737 /* Configure the type of BT collocated with WLAN */
2738 A_MEMZERO(&sbfa_cmd, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD));
2739 #ifdef CONFIG_AR600x_DUAL_ANTENNA
2740 sbfa_cmd.btcoexFeAntType = 2;
2741 #elif defined(CONFIG_AR600x_SINGLE_ANTENNA)
2742 sbfa_cmd.btcoexFeAntType = 1;
2744 #error Unsupported Front-End Antenna Configuration
2745 #endif /* AR600x Front-End Antenna Configuration */
2747 if ((wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd)) != A_OK) {
2748 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n"));
2750 #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */
2753 ar->arNumDataEndPts = 1;
2756 /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise
2757 * the data path through a raw socket is disabled */
2758 dev->dev_addr[0] = 0x00;
2759 dev->dev_addr[1] = 0x01;
2760 dev->dev_addr[2] = 0x02;
2761 dev->dev_addr[3] = 0xAA;
2762 dev->dev_addr[4] = 0xBB;
2763 dev->dev_addr[5] = 0xCC;
2775 ar6000_bitrate_rx(void *devt, A_INT32 rateKbps)
2777 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
2779 ar->arBitRate = rateKbps;
2784 ar6000_ratemask_rx(void *devt, A_UINT32 ratemask)
2786 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
2788 ar->arRateMask = ratemask;
2793 ar6000_txPwr_rx(void *devt, A_UINT8 txPwr)
2795 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
2797 ar->arTxPwr = txPwr;
2803 ar6000_channelList_rx(void *devt, A_INT8 numChan, A_UINT16 *chanList)
2805 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
2807 A_MEMCPY(ar->arChannelList, chanList, numChan * sizeof (A_UINT16));
2808 ar->arNumChannels = numChan;
2814 ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, A_UINT32 * mapNo)
2816 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2818 ATH_MAC_HDR *macHdr;
2822 datap = A_NETBUF_DATA(skb);
2823 macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR));
2824 if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) {
2829 for (i = 0; i < ar->arNodeNum; i ++) {
2830 if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) {
2832 ar->arNodeMap[i].txPending ++;
2833 return ar->arNodeMap[i].epId;
2836 if ((eptMap == -1) && !ar->arNodeMap[i].txPending) {
2842 eptMap = ar->arNodeNum;
2844 A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM);
2847 A_MEMCPY(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN);
2849 for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) {
2850 if (!ar->arTxPending[i]) {
2851 ar->arNodeMap[eptMap].epId = i;
2854 // No free endpoint is available, start redistribution on the inuse endpoints.
2855 if (i == ENDPOINT_5) {
2856 ar->arNodeMap[eptMap].epId = ar->arNexEpId;
2858 if (ar->arNexEpId > ENDPOINT_5) {
2859 ar->arNexEpId = ENDPOINT_2;
2864 (*mapNo) = eptMap + 1;
2865 ar->arNodeMap[eptMap].txPending ++;
2867 return ar->arNodeMap[eptMap].epId;
2871 static void ar6000_dump_skb(struct sk_buff *skb)
2874 for (ch = A_NETBUF_DATA(skb);
2875 (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) +
2876 A_NETBUF_LEN(skb)); ch++)
2878 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch));
2880 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n"));
2884 #ifdef HTC_TEST_SEND_PKTS
2885 static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb);
2889 ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
2891 #define AC_NOT_MAPPED 99
2892 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
2893 A_UINT8 ac = AC_NOT_MAPPED;
2894 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
2897 struct ar_cookie *cookie;
2898 A_BOOL checkAdHocPsMapping = FALSE,bMoreData = FALSE;
2899 HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG;
2900 A_UINT8 dot11Hdr = processDot11Hdr;
2902 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
2906 #endif /* CONFIG_PM */
2908 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n",
2909 (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb),
2910 A_NETBUF_LEN(skb)));
2912 /* If target is not associated */
2913 if( (!ar->arConnected && !bypasswmi)
2914 #ifdef CONFIG_HOST_TCMD_SUPPORT
2915 /* TCMD doesnt support any data, free the buf and return */
2916 || (ar->arTargetMode == AR6000_TCMD_MODE)
2925 if (ar->arWmiReady == FALSE && bypasswmi == 0) {
2929 #ifdef BLOCK_TX_PATH_FLAG
2933 #endif /* BLOCK_TX_PATH_FLAG */
2935 /* AP mode Power save processing */
2936 /* If the dst STA is in sleep state, queue the pkt in its PS queue */
2938 if (ar->arNetworkType == AP_NETWORK) {
2939 ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
2942 /* If the dstMac is a Multicast address & atleast one of the
2943 * associated STA is in PS mode, then queue the pkt to the
2946 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
2948 A_BOOL qMcast=FALSE;
2951 for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) {
2952 if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) {
2958 /* If this transmit is not because of a Dtim Expiry q it */
2959 if (ar->DTIMExpired == FALSE) {
2960 A_BOOL isMcastqEmpty = FALSE;
2962 A_MUTEX_LOCK(&ar->mcastpsqLock);
2963 isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
2964 A_NETBUF_ENQUEUE(&ar->mcastpsq, skb);
2965 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
2967 /* If this is the first Mcast pkt getting queued
2968 * indicate to the target to set the BitmapControl LSB
2971 if (isMcastqEmpty) {
2972 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1);
2976 /* This transmit is because of Dtim expiry. Determine if
2977 * MoreData bit has to be set.
2979 A_MUTEX_LOCK(&ar->mcastpsqLock);
2980 if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
2983 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
2987 conn = ieee80211_find_conn(ar, datap->dstMac);
2989 if (STA_IS_PWR_SLEEP(conn)) {
2990 /* If this transmit is not because of a PsPoll q it*/
2991 if (!STA_IS_PS_POLLED(conn)) {
2992 A_BOOL isPsqEmpty = FALSE;
2993 /* Queue the frames if the STA is sleeping */
2994 A_MUTEX_LOCK(&conn->psqLock);
2995 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
2996 A_NETBUF_ENQUEUE(&conn->psq, skb);
2997 A_MUTEX_UNLOCK(&conn->psqLock);
2999 /* If this is the first pkt getting queued
3000 * for this STA, update the PVB for this STA
3003 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1);
3008 /* This tx is because of a PsPoll. Determine if
3009 * MoreData bit has to be set
3011 A_MUTEX_LOCK(&conn->psqLock);
3012 if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3015 A_MUTEX_UNLOCK(&conn->psqLock);
3020 /* non existent STA. drop the frame */
3027 if (ar->arWmiEnabled) {
3028 #ifdef CONFIG_CHECKSUM_OFFLOAD
3029 A_UINT8 csumStart=0;
3031 A_UINT8 csum=skb->ip_summed;
3032 if(csumOffload && (csum==CHECKSUM_PARTIAL)){
3033 csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
3034 sizeof(ATH_LLC_SNAP_HDR));
3035 csumDest=skb->csum_offset+csumStart;
3038 if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) {
3039 struct sk_buff *newbuf;
3042 * We really should have gotten enough headroom but sometimes
3043 * we still get packets with not enough headroom. Copy the packet.
3045 len = A_NETBUF_LEN(skb);
3046 newbuf = A_NETBUF_ALLOC(len);
3047 if (newbuf == NULL) {
3050 A_NETBUF_PUT(newbuf, len);
3051 A_MEMCPY(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len);
3054 /* fall through and assemble header */
3058 if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != A_OK) {
3059 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n"));
3063 if (wmi_dix_2_dot3(ar->arWmi, skb) != A_OK) {
3064 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n"));
3068 #ifdef CONFIG_CHECKSUM_OFFLOAD
3069 if(csumOffload && (csum ==CHECKSUM_PARTIAL)){
3070 WMI_TX_META_V2 metaV2;
3071 metaV2.csumStart =csumStart;
3072 metaV2.csumDest = csumDest;
3073 metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/
3074 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,
3075 WMI_META_VERSION_2,&metaV2) != A_OK) {
3076 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3084 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != A_OK) {
3085 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3091 if ((ar->arNetworkType == ADHOC_NETWORK) &&
3092 ar->arIbssPsEnable && ar->arConnected) {
3093 /* flag to check adhoc mapping once we take the lock below: */
3094 checkAdHocPsMapping = TRUE;
3097 /* get the stream mapping */
3098 ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled);
3102 EPPING_HEADER *eppingHdr;
3104 eppingHdr = A_NETBUF_DATA(skb);
3106 if (IS_EPPING_PACKET(eppingHdr)) {
3107 /* the stream ID is mapped to an access class */
3108 ac = eppingHdr->StreamNo_h;
3109 /* some EPPING packets cannot be dropped no matter what access class it was
3110 * sent on. We can change the packet tag to guarantee it will not get dropped */
3111 if (IS_EPING_PACKET_NO_DROP(eppingHdr)) {
3112 htc_tag = AR6K_CONTROL_PKT_TAG;
3115 if (ac == HCI_TRANSPORT_STREAM_NUM) {
3116 /* pass this to HCI */
3117 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
3118 if (A_SUCCESS(hci_test_send(ar,skb))) {
3122 /* set AC to discard this skb */
3125 /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition
3126 * of the HTC header will mis-align the start of the HTC frame, so we add some
3127 * padding which will be stripped off in the target */
3128 if (EPPING_ALIGNMENT_PAD > 0) {
3129 A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD);
3134 /* not a ping packet, drop it */
3141 /* did we succeed ? */
3142 if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) {
3143 /* cleanup and exit */
3145 AR6000_STAT_INC(ar, tx_dropped);
3146 AR6000_STAT_INC(ar, tx_aborted_errors);
3152 /* take the lock to protect driver data */
3153 AR6000_SPIN_LOCK(&ar->arLock, 0);
3157 if (checkAdHocPsMapping) {
3158 eid = ar6000_ibss_map_epid(skb, dev, &mapNo);
3160 eid = arAc2EndpointID (ar, ac);
3162 /* validate that the endpoint is connected */
3163 if (eid == 0 || eid == ENDPOINT_UNUSED ) {
3164 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid));
3167 /* allocate resource for this packet */
3168 cookie = ar6000_alloc_cookie(ar);
3170 if (cookie != NULL) {
3171 /* update counts while the lock is held */
3172 ar->arTxPending[eid]++;
3173 ar->arTotalTxDataPending++;
3178 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3180 if (cookie != NULL) {
3181 cookie->arc_bp[0] = (unsigned long)skb;
3182 cookie->arc_bp[1] = mapNo;
3183 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3191 if (debugdriver >= 3) {
3192 ar6000_dump_skb(skb);
3195 #ifdef HTC_TEST_SEND_PKTS
3196 DoHTCSendPktsTest(ar,mapNo,eid,skb);
3198 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3199 * the ar6000_tx_complete callback */
3200 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3202 /* no packet to send, cleanup */
3204 AR6000_STAT_INC(ar, tx_dropped);
3205 AR6000_STAT_INC(ar, tx_aborted_errors);
3212 ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev)
3214 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
3215 struct ar_cookie *cookie;
3216 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
3219 AR6000_SPIN_LOCK(&ar->arLock, 0);
3221 /* For now we send ACL on BE endpoint: We can also have a dedicated EP */
3222 eid = arAc2EndpointID (ar, 0);
3223 /* allocate resource for this packet */
3224 cookie = ar6000_alloc_cookie(ar);
3226 if (cookie != NULL) {
3227 /* update counts while the lock is held */
3228 ar->arTxPending[eid]++;
3229 ar->arTotalTxDataPending++;
3233 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3235 if (cookie != NULL) {
3236 cookie->arc_bp[0] = (unsigned long)skb;
3237 cookie->arc_bp[1] = 0;
3238 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3245 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3246 * the ar6000_tx_complete callback */
3247 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3249 /* no packet to send, cleanup */
3251 AR6000_STAT_INC(ar, tx_dropped);
3252 AR6000_STAT_INC(ar, tx_aborted_errors);
3258 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3260 tvsub(register struct timeval *out, register struct timeval *in)
3262 if((out->tv_usec -= in->tv_usec) < 0) {
3264 out->tv_usec += 1000000;
3266 out->tv_sec -= in->tv_sec;
3270 applyAPTCHeuristics(AR_SOFTC_T *ar)
3274 A_UINT32 throughput;
3278 AR6000_SPIN_LOCK(&ar->arLock, 0);
3280 if ((enableAPTCHeuristics) && (!aptcTR.timerScheduled)) {
3281 do_gettimeofday(&ts);
3282 tvsub(&ts, &aptcTR.samplingTS);
3283 duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */
3284 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
3286 if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) {
3287 /* Initialize the time stamp and byte count */
3288 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
3289 do_gettimeofday(&aptcTR.samplingTS);
3291 /* Calculate and decide based on throughput thresholds */
3292 throughput = ((numbytes * 8) / duration);
3293 if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) {
3294 /* Disable Sleep and schedule a timer */
3295 A_ASSERT(ar->arWmiReady == TRUE);
3296 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3297 status = wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER);
3298 AR6000_SPIN_LOCK(&ar->arLock, 0);
3299 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
3300 aptcTR.timerScheduled = TRUE;
3305 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3307 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3309 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket)
3311 AR_SOFTC_T *ar = (AR_SOFTC_T *)Context;
3312 HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP;
3313 A_BOOL stopNet = FALSE;
3314 HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket);
3321 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3322 /* don't drop special control packets */
3326 accessClass = arEndpoint2Ac(ar,Endpoint);
3327 /* for endpoint ping testing drop Best Effort and Background */
3328 if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) {
3329 action = HTC_SEND_FULL_DROP;
3332 /* keep but stop the netqueues */
3338 if (Endpoint == ar->arControlEp) {
3339 /* under normal WMI if this is getting full, then something is running rampant
3340 * the host should not be exhausting the WMI queue with too many commands
3341 * the only exception to this is during testing using endpointping */
3342 AR6000_SPIN_LOCK(&ar->arLock, 0);
3343 /* set flag to handle subsequent messages */
3344 ar->arWMIControlEpFull = TRUE;
3345 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3346 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n"));
3347 /* no need to stop the network */
3352 /* if we get here, we are dealing with data endpoints getting full */
3354 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3355 /* don't drop control packets issued on ANY data endpoint */
3359 if (ar->arNetworkType == ADHOC_NETWORK) {
3360 /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to
3361 * continue, however we should stop the network */
3365 /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest
3367 if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri &&
3368 ar->arCookieCount <= MAX_HI_COOKIE_NUM) {
3369 /* this stream's priority is less than the highest active priority, we
3370 * give preference to the highest priority stream by directing
3371 * HTC to drop the packet that overflowed */
3372 action = HTC_SEND_FULL_DROP;
3373 /* since we are dropping packets, no need to stop the network */
3381 AR6000_SPIN_LOCK(&ar->arLock, 0);
3382 ar->arNetQueueStopped = TRUE;
3383 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3384 /* one of the data endpoints queues is getting full..need to stop network stack
3385 * the queue will resume in ar6000_tx_complete() */
3386 netif_stop_queue(ar->arNetDev);
3394 ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPacketQueue)
3396 AR_SOFTC_T *ar = (AR_SOFTC_T *)Context;
3399 struct ar_cookie * ar_cookie;
3400 HTC_ENDPOINT_ID eid;
3401 A_BOOL wakeEvent = FALSE;
3402 struct sk_buff_head skb_queue;
3403 HTC_PACKET *pPacket;
3404 struct sk_buff *pktSkb;
3405 A_BOOL flushing = FALSE;
3407 skb_queue_head_init(&skb_queue);
3409 /* lock the driver as we update internal state */
3410 AR6000_SPIN_LOCK(&ar->arLock, 0);
3412 /* reap completed packets */
3413 while (!HTC_QUEUE_EMPTY(pPacketQueue)) {
3415 pPacket = HTC_PACKET_DEQUEUE(pPacketQueue);
3417 ar_cookie = (struct ar_cookie *)pPacket->pPktContext;
3418 A_ASSERT(ar_cookie);
3420 status = pPacket->Status;
3421 pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0];
3422 eid = pPacket->Endpoint;
3423 mapNo = ar_cookie->arc_bp[1];
3426 A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb));
3428 /* add this to the list, use faster non-lock API */
3429 __skb_queue_tail(&skb_queue,pktSkb);
3431 if (A_SUCCESS(status)) {
3432 A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb));
3435 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%lx data=0x%lx len=0x%x eid=%d ",
3436 (unsigned long)pktSkb, (unsigned long)pPacket->pBuffer,
3437 pPacket->ActualLength,
3440 ar->arTxPending[eid]--;
3442 if ((eid != ar->arControlEp) || bypasswmi) {
3443 ar->arTotalTxDataPending--;
3446 if (eid == ar->arControlEp)
3448 if (ar->arWMIControlEpFull) {
3449 /* since this packet completed, the WMI EP is no longer full */
3450 ar->arWMIControlEpFull = FALSE;
3453 if (ar->arTxPending[eid] == 0) {
3458 if (A_FAILED(status)) {
3459 if (status == A_ECANCELED) {
3460 /* a packet was flushed */
3463 AR6000_STAT_INC(ar, tx_errors);
3464 if (status != A_NO_RESOURCE) {
3465 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__,
3469 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n"));
3471 AR6000_STAT_INC(ar, tx_packets);
3472 ar->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb);
3473 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3474 aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb);
3475 applyAPTCHeuristics(ar);
3476 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3479 // TODO this needs to be looked at
3480 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable
3481 && (eid != ar->arControlEp) && mapNo)
3484 ar->arNodeMap[mapNo].txPending --;
3486 if (!ar->arNodeMap[mapNo].txPending && (mapNo == (ar->arNodeNum - 1))) {
3488 for (i = ar->arNodeNum; i > 0; i --) {
3489 if (!ar->arNodeMap[i - 1].txPending) {
3490 A_MEMZERO(&ar->arNodeMap[i - 1], sizeof(struct ar_node_mapping));
3499 ar6000_free_cookie(ar, ar_cookie);
3501 if (ar->arNetQueueStopped) {
3502 ar->arNetQueueStopped = FALSE;
3506 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3508 /* lock is released, we can freely call other kernel APIs */
3510 /* free all skbs in our local list */
3511 while (!skb_queue_empty(&skb_queue)) {
3512 /* use non-lock version */
3513 pktSkb = __skb_dequeue(&skb_queue);
3514 A_NETBUF_FREE(pktSkb);
3517 if ((ar->arConnected == TRUE) || (bypasswmi)) {
3519 /* don't wake the queue if we are flushing, other wise it will just
3520 * keep queueing packets, which will keep failing */
3521 netif_wake_queue(ar->arNetDev);
3532 ieee80211_find_conn(AR_SOFTC_T *ar, A_UINT8 *node_addr)
3535 A_UINT8 i, max_conn;
3537 switch(ar->arNetworkType) {
3539 max_conn = AP_MAX_NUM_STA;
3546 for (i = 0; i < max_conn; i++) {
3547 if (IEEE80211_ADDR_EQ(node_addr, ar->sta_list[i].mac)) {
3548 conn = &ar->sta_list[i];
3556 sta_t *ieee80211_find_conn_for_aid(AR_SOFTC_T *ar, A_UINT8 aid)
3561 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
3562 if (ar->sta_list[ctr].aid == aid) {
3563 conn = &ar->sta_list[ctr];
3571 * Receive event handler. This is called by HTC when a packet is received
3575 ar6000_rx(void *Context, HTC_PACKET *pPacket)
3577 AR_SOFTC_T *ar = (AR_SOFTC_T *)Context;
3578 struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext;
3580 A_UINT8 containsDot11Hdr = 0;
3581 A_STATUS status = pPacket->Status;
3582 HTC_ENDPOINT_ID ept = pPacket->Endpoint;
3584 A_ASSERT((status != A_OK) ||
3585 (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN)));
3587 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",
3588 (unsigned long)ar, ept, (unsigned long)skb, (unsigned long)pPacket->pBuffer,
3589 pPacket->ActualLength, status));
3590 if (status != A_OK) {
3591 if (status != A_ECANCELED) {
3592 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status));
3596 /* take lock to protect buffer counts
3597 * and adaptive power throughput state */
3598 AR6000_SPIN_LOCK(&ar->arLock, 0);
3600 if (A_SUCCESS(status)) {
3601 AR6000_STAT_INC(ar, rx_packets);
3602 ar->arNetStats.rx_bytes += pPacket->ActualLength;
3603 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3604 aptcTR.bytesReceived += a_netbuf_to_len(skb);
3605 applyAPTCHeuristics(ar);
3606 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3608 A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN);
3609 A_NETBUF_PULL(skb, HTC_HEADER_LEN);
3612 if (debugdriver >= 2) {
3613 ar6000_dump_skb(skb);
3618 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3620 skb->dev = ar->arNetDev;
3621 if (status != A_OK) {
3622 AR6000_STAT_INC(ar, rx_errors);
3624 } else if (ar->arWmiEnabled == TRUE) {
3625 if (ept == ar->arControlEp) {
3627 * this is a wmi control msg
3630 ar6000_check_wow_status(ar, skb, TRUE);
3631 #endif /* CONFIG_PM */
3632 wmi_control_rx(ar->arWmi, skb);
3634 WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb);
3635 A_UINT8 is_amsdu, tid, is_acl_data_frame;
3636 is_acl_data_frame = WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == WMI_DATA_HDR_DATA_TYPE_ACL;
3638 ar6000_check_wow_status(ar, NULL, FALSE);
3639 #endif /* CONFIG_PM */
3641 * this is a wmi data packet
3645 if (processDot11Hdr) {
3646 minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR);
3648 minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) +
3649 sizeof(ATH_LLC_SNAP_HDR);
3652 /* In the case of AP mode we may receive NULL data frames
3653 * that do not have LLC hdr. They are 16 bytes in size.
3654 * Allow these frames in the AP mode.
3655 * ACL data frames don't follow ethernet frame bounds for
3658 if (ar->arNetworkType != AP_NETWORK && !is_acl_data_frame &&
3659 ((pPacket->ActualLength < minHdrLen) ||
3660 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)))
3663 * packet is too short or too long
3665 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n"));
3666 AR6000_STAT_INC(ar, rx_errors);
3667 AR6000_STAT_INC(ar, rx_length_errors);
3674 /* Access RSSI values here */
3675 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n",
3676 ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi));
3678 /* Get the Power save state of the STA */
3679 if (ar->arNetworkType == AP_NETWORK) {
3681 A_UINT8 psState=0,prevPsState;
3682 ATH_MAC_HDR *datap=NULL;
3685 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3687 psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info
3688 >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK;
3690 offset = sizeof(WMI_DATA_HDR);
3692 switch (meta_type) {
3695 case WMI_META_VERSION_1:
3696 offset += sizeof(WMI_RX_META_V1);
3698 #ifdef CONFIG_CHECKSUM_OFFLOAD
3699 case WMI_META_VERSION_2:
3700 offset += sizeof(WMI_RX_META_V2);
3707 datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset);
3708 conn = ieee80211_find_conn(ar, datap->srcMac);
3711 /* if there is a change in PS state of the STA,
3712 * take appropriate steps.
3713 * 1. If Sleep-->Awake, flush the psq for the STA
3714 * Clear the PVB for the STA.
3715 * 2. If Awake-->Sleep, Starting queueing frames
3718 prevPsState = STA_IS_PWR_SLEEP(conn);
3720 STA_SET_PWR_SLEEP(conn);
3722 STA_CLR_PWR_SLEEP(conn);
3725 if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) {
3727 if (!STA_IS_PWR_SLEEP(conn)) {
3729 A_MUTEX_LOCK(&conn->psqLock);
3730 while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3731 struct sk_buff *skb=NULL;
3733 skb = A_NETBUF_DEQUEUE(&conn->psq);
3734 A_MUTEX_UNLOCK(&conn->psqLock);
3735 ar6000_data_tx(skb,ar->arNetDev);
3736 A_MUTEX_LOCK(&conn->psqLock);
3738 A_MUTEX_UNLOCK(&conn->psqLock);
3739 /* Clear the PVB for this STA */
3740 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
3744 /* This frame is from a STA that is not associated*/
3748 /* Drop NULL data frames here */
3749 if((pPacket->ActualLength < minHdrLen) ||
3750 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) {
3756 is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr);
3757 tid = WMI_DATA_HDR_GET_UP(dhdr);
3758 seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr);
3759 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3760 containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr);
3762 wmi_data_hdr_remove(ar->arWmi, skb);
3764 switch (meta_type) {
3765 case WMI_META_VERSION_1:
3767 WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb);
3768 A_PRINTF("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags);
3769 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1));
3772 #ifdef CONFIG_CHECKSUM_OFFLOAD
3773 case WMI_META_VERSION_2:
3775 WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb);
3776 if(pMeta->csumFlags & 0x1){
3777 skb->ip_summed=CHECKSUM_COMPLETE;
3778 skb->csum=(pMeta->csum);
3780 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2));
3788 A_ASSERT(status == A_OK);
3790 /* NWF: print the 802.11 hdr bytes */
3791 if(containsDot11Hdr) {
3792 status = wmi_dot11_hdr_remove(ar->arWmi,skb);
3793 } else if(!is_amsdu && !is_acl_data_frame) {
3794 status = wmi_dot3_2_dix(skb);
3797 if (status != A_OK) {
3798 /* Drop frames that could not be processed (lack of memory, etc.) */
3803 if (is_acl_data_frame) {
3804 A_NETBUF_PUSH(skb, sizeof(int));
3805 *((short *)A_NETBUF_DATA(skb)) = WMI_ACL_DATA_EVENTID;
3806 /* send the data packet to PAL driver */
3807 if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) {
3808 if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, skb) == TRUE)
3813 if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) {
3814 if (ar->arNetworkType == AP_NETWORK) {
3815 struct sk_buff *skb1 = NULL;
3818 datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
3819 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
3820 /* Bcast/Mcast frames should be sent to the OS
3821 * stack as well as on the air.
3823 skb1 = skb_copy(skb,GFP_ATOMIC);
3825 /* Search for a connected STA with dstMac as
3826 * the Mac address. If found send the frame to
3827 * it on the air else send the frame up the
3831 conn = ieee80211_find_conn(ar, datap->dstMac);
3833 if (conn && ar->intra_bss) {
3836 } else if(conn && !ar->intra_bss) {
3842 ar6000_data_tx(skb1, ar->arNetDev);
3846 #ifdef ATH_AR6K_11N_SUPPORT
3847 aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb);
3849 ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb);
3853 if (EPPING_ALIGNMENT_PAD > 0) {
3854 A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD);
3856 ar6000_deliver_frames_to_nw_stack((void *)ar->arNetDev, (void *)skb);
3865 ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf)
3867 struct sk_buff *skb = (struct sk_buff *)osbuf;
3871 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3873 ar6000_check_wow_status((AR_SOFTC_T *)ar6k_priv(dev), skb, FALSE);
3874 #endif /* CONFIG_PM */
3875 skb->protocol = eth_type_trans(skb, skb->dev);
3877 * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ)
3878 * or tasklet use the netif_rx to deliver the packet to the stack
3879 * netif_rx will queue the packet onto the receive queue and mark
3880 * the softirq thread has a pending action to complete. Kernel will
3881 * schedule the softIrq kernel thread after processing the DSR.
3883 * If this routine is called on a process context, use netif_rx_ni
3884 * which will schedle the softIrq kernel thread after queuing the packet.
3886 if (in_interrupt()) {
3899 ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf)
3901 struct sk_buff *skb = (struct sk_buff *)osbuf;
3905 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3906 skb->protocol = htons(ETH_P_CONTROL);
3916 ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint)
3918 AR_SOFTC_T *ar = (AR_SOFTC_T *)Context;
3921 int buffersToRefill;
3922 HTC_PACKET *pPacket;
3923 HTC_PACKET_QUEUE queue;
3925 buffersToRefill = (int)AR6000_MAX_RX_BUFFERS -
3926 HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint);
3928 if (buffersToRefill <= 0) {
3929 /* fast return, nothing to fill */
3933 INIT_HTC_PACKET_QUEUE(&queue);
3935 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n",
3936 buffersToRefill, Endpoint));
3938 for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) {
3939 osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE);
3940 if (NULL == osBuf) {
3943 /* the HTC packet wrapper is at the head of the reserved area
3945 pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf));
3946 /* set re-fill info */
3947 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint);
3949 HTC_PACKET_ENQUEUE(&queue,pPacket);
3952 if (!HTC_QUEUE_EMPTY(&queue)) {
3954 HTCAddReceivePktMultiple(ar->arHtcTarget, &queue);
3959 /* clean up our amsdu buffer list */
3960 static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar)
3962 HTC_PACKET *pPacket;
3965 /* empty AMSDU buffer queue and free OS bufs */
3968 AR6000_SPIN_LOCK(&ar->arLock, 0);
3969 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
3970 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3972 if (NULL == pPacket) {
3976 osBuf = pPacket->pPktContext;
3977 if (NULL == osBuf) {
3982 A_NETBUF_FREE(osBuf);
3988 /* refill the amsdu buffer list */
3989 static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count)
3991 HTC_PACKET *pPacket;
3995 osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE);
3996 if (NULL == osBuf) {
3999 /* the HTC packet wrapper is at the head of the reserved area
4001 pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf));
4002 /* set re-fill info */
4003 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0);
4005 AR6000_SPIN_LOCK(&ar->arLock, 0);
4006 /* put it in the list */
4007 HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket);
4008 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4014 /* callback to allocate a large receive buffer for a pending packet. This function is called when
4015 * an HTC packet arrives whose length exceeds a threshold value
4017 * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to
4018 * keep the allocation size the same to optimize cached-slab allocations.
4021 static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length)
4023 HTC_PACKET *pPacket = NULL;
4024 AR_SOFTC_T *ar = (AR_SOFTC_T *)Context;
4025 int refillCount = 0;
4027 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length));
4031 if (Length <= AR6000_BUFFER_SIZE) {
4032 /* shouldn't be getting called on normal sized packets */
4037 if (Length > AR6000_AMSDU_BUFFER_SIZE) {
4042 AR6000_SPIN_LOCK(&ar->arLock, 0);
4043 /* allocate a packet from the list */
4044 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
4045 /* see if we need to refill again */
4046 refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue);
4047 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4049 if (NULL == pPacket) {
4052 /* set actual endpoint ID */
4053 pPacket->Endpoint = Endpoint;
4057 if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) {
4058 ar6000_refill_amsdu_rxbufs(ar,refillCount);
4065 ar6000_set_multicast_list(struct net_device *dev)
4067 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: Multicast filter not supported\n"));
4070 static struct net_device_stats *
4071 ar6000_get_stats(struct net_device *dev)
4073 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
4074 return &ar->arNetStats;
4077 static struct iw_statistics *
4078 ar6000_get_iwstats(struct net_device * dev)
4080 AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev);
4081 TARGET_STATS *pStats = &ar->arTargetStats;
4082 struct iw_statistics * pIwStats = &ar->arIwStats;
4085 if (ar->bIsDestroyProgress || ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED)
4087 pIwStats->status = 0;
4088 pIwStats->qual.qual = 0;
4089 pIwStats->qual.level =0;
4090 pIwStats->qual.noise = 0;
4091 pIwStats->discard.code =0;
4092 pIwStats->discard.retries=0;
4093 pIwStats->miss.beacon =0;
4098 * The in_atomic function is used to determine if the scheduling is
4099 * allowed in the current context or not. This was introduced in 2.6
4100 * From what I have read on the differences between 2.4 and 2.6, the
4101 * 2.4 kernel did not support preemption and so this check might not
4102 * be required for 2.4 kernels.
4106 wmi_get_stats_cmd(ar->arWmi);
4108 pIwStats->status = 1 ;
4109 pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161;
4110 pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */
4111 pIwStats->qual.noise = pStats->noise_floor_calibation;
4112 pIwStats->discard.code = pStats->rx_decrypt_err;
4113 pIwStats->discard.retries = pStats->tx_retry_cnt;
4114 pIwStats->miss.beacon = pStats->cs_bmiss_cnt;
4119 rtnllocked = rtnl_is_locked();
4123 pIwStats->status = 0;
4125 if (down_interruptible(&ar->arSem)) {
4131 if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) {
4135 ar->statsUpdatePending = TRUE;
4137 if(wmi_get_stats_cmd(ar->arWmi) != A_OK) {
4141 wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == FALSE, wmitimeout * HZ);
4142 if (signal_pending(current)) {
4143 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : WMI get stats timeout \n"));
4146 pIwStats->status = 1 ;
4147 pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161;
4148 pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */
4149 pIwStats->qual.noise = pStats->noise_floor_calibation;
4150 pIwStats->discard.code = pStats->rx_decrypt_err;
4151 pIwStats->discard.retries = pStats->tx_retry_cnt;
4152 pIwStats->miss.beacon = pStats->cs_bmiss_cnt;
4165 ar6000_ready_event(void *devt, A_UINT8 *datap, A_UINT8 phyCap, A_UINT32 sw_ver, A_UINT32 abi_ver)
4167 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
4168 struct net_device *dev = ar->arNetDev;
4170 A_MEMCPY(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN);
4171 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
4172 dev->dev_addr[0], dev->dev_addr[1],
4173 dev->dev_addr[2], dev->dev_addr[3],
4174 dev->dev_addr[4], dev->dev_addr[5]));
4176 ar->arPhyCapability = phyCap;
4177 ar->arVersion.wlan_ver = sw_ver;
4178 ar->arVersion.abi_ver = abi_ver;
4180 /* Indicate to the waiting thread that the ready event was received */
4181 ar->arWmiReady = TRUE;
4184 #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
4185 wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN);
4187 #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP
4188 wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP);
4190 wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL);
4191 #if WLAN_CONFIG_DISABLE_11N
4193 WMI_SET_HT_CAP_CMD htCap;
4195 A_MEMZERO(&htCap, sizeof(WMI_SET_HT_CAP_CMD));
4197 wmi_set_ht_cap_cmd(ar->arWmi, &htCap);
4200 wmi_set_ht_cap_cmd(ar->arWmi, &htCap);
4202 #endif /* WLAN_CONFIG_DISABLE_11N */
4204 #ifdef ATH6K_CONFIG_OTA_MODE
4205 wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER);
4207 wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT);
4211 add_new_sta(AR_SOFTC_T *ar, A_UINT8 *mac, A_UINT16 aid, A_UINT8 *wpaie,
4212 A_UINT8 ielen, A_UINT8 keymgmt, A_UINT8 ucipher, A_UINT8 auth)
4214 A_UINT8 free_slot=aid-1;
4216 A_MEMCPY(ar->sta_list[free_slot].mac, mac, ATH_MAC_LEN);
4217 A_MEMCPY(ar->sta_list[free_slot].wpa_ie, wpaie, ielen);
4218 ar->sta_list[free_slot].aid = aid;
4219 ar->sta_list[free_slot].keymgmt = keymgmt;
4220 ar->sta_list[free_slot].ucipher = ucipher;
4221 ar->sta_list[free_slot].auth = auth;
4222 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
4223 ar->arAPStats.sta[free_slot].aid = aid;
4227 ar6000_connect_event(AR_SOFTC_T *ar, A_UINT16 channel, A_UINT8 *bssid,
4228 A_UINT16 listenInterval, A_UINT16 beaconInterval,
4229 NETWORK_TYPE networkType, A_UINT8 beaconIeLen,
4230 A_UINT8 assocReqLen, A_UINT8 assocRespLen,
4233 union iwreq_data wrqu;
4234 int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos;
4235 static const char *tag1 = "ASSOCINFO(ReqIEs=";
4236 static const char *tag2 = "ASSOCRESPIE=";
4237 static const char *beaconIetag = "BEACONIE=";
4238 char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1];
4240 A_UINT8 key_op_ctrl;
4241 unsigned long flags;
4242 struct ieee80211req_key *ik;
4243 CRYPTO_TYPE keyType = NONE_CRYPT;
4245 if(ar->arNetworkType & AP_NETWORK) {
4246 struct net_device *dev = ar->arNetDev;
4247 if(A_MEMCMP(dev->dev_addr, bssid, ATH_MAC_LEN)==0) {
4248 ar->arACS = channel;
4249 ik = &ar->ap_mode_bkey;
4251 switch(ar->arAuthMode) {
4253 if(ar->arPairwiseCrypto == WEP_CRYPT) {
4254 ar6000_install_static_wep_keys(ar);
4257 else if(ar->arPairwiseCrypto == WAPI_CRYPT) {
4258 ap_set_wapi_key(ar, ik);
4264 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
4265 switch (ik->ik_type) {
4266 case IEEE80211_CIPHER_TKIP:
4267 keyType = TKIP_CRYPT;
4269 case IEEE80211_CIPHER_AES_CCM:
4270 keyType = AES_CRYPT;
4275 wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, GROUP_USAGE,
4276 ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc,
4277 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
4283 ar->arConnected = TRUE;
4287 A_PRINTF("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n "
4288 " AID=%d \n", bssid[0], bssid[1], bssid[2],
4289 bssid[3], bssid[4], bssid[5], channel);
4290 switch ((listenInterval>>8)&0xFF) {
4292 A_PRINTF("AUTH: OPEN\n");
4295 A_PRINTF("AUTH: SHARED\n");
4298 A_PRINTF("AUTH: Unknown\n");
4301 switch (listenInterval&0xFF) {
4303 A_PRINTF("KeyMgmt: WPA-PSK\n");
4306 A_PRINTF("KeyMgmt: WPA2-PSK\n");
4309 A_PRINTF("KeyMgmt: NONE\n");
4312 switch (beaconInterval) {
4314 A_PRINTF("Cipher: AES\n");
4317 A_PRINTF("Cipher: TKIP\n");
4320 A_PRINTF("Cipher: WEP\n");
4324 A_PRINTF("Cipher: WAPI\n");
4328 A_PRINTF("Cipher: NONE\n");
4332 add_new_sta(ar, bssid, channel /*aid*/,
4333 assocInfo /* WPA IE */, assocRespLen /* IE len */,
4334 listenInterval&0xFF /* Keymgmt */, beaconInterval /* cipher */,
4335 (listenInterval>>8)&0xFF /* auth alg */);
4337 /* Send event to application */
4338 A_MEMZERO(&wrqu, sizeof(wrqu));
4339 A_MEMCPY(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4340 wireless_send_event(ar->arNetDev, IWEVREGISTERED, &wrqu, NULL);
4341 /* In case the queue is stopped when we switch modes, this will
4344 netif_wake_queue(ar->arNetDev);
4348 #ifdef ATH6K_CONFIG_CFG80211
4349 ar6k_cfg80211_connect_event(ar, channel, bssid,
4350 listenInterval, beaconInterval,
4351 networkType, beaconIeLen,
4352 assocReqLen, assocRespLen,
4354 #endif /* ATH6K_CONFIG_CFG80211 */
4356 A_MEMCPY(ar->arBssid, bssid, sizeof(ar->arBssid));
4357 ar->arBssChannel = channel;
4359 A_PRINTF("AR6000 connected event on freq %d ", channel);
4360 A_PRINTF("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4361 " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d"
4362 " assocRespLen =%d\n",
4363 bssid[0], bssid[1], bssid[2],
4364 bssid[3], bssid[4], bssid[5],
4365 listenInterval, beaconInterval,
4366 beaconIeLen, assocReqLen, assocRespLen);
4367 if (networkType & ADHOC_NETWORK) {
4368 if (networkType & ADHOC_CREATOR) {
4369 A_PRINTF("Network: Adhoc (Creator)\n");
4371 A_PRINTF("Network: Adhoc (Joiner)\n");
4374 A_PRINTF("Network: Infrastructure\n");
4377 if ((ar->arNetworkType == INFRA_NETWORK)) {
4378 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
4381 if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) {
4382 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= "));
4385 A_MEMZERO(buf, sizeof(buf));
4386 sprintf(buf, "%s", beaconIetag);
4388 for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) {
4389 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4390 sprintf(pos, "%2.2x", assocInfo[i]);
4393 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4395 A_MEMZERO(&wrqu, sizeof(wrqu));
4396 wrqu.data.length = strlen(buf);
4397 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4400 if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2))))
4402 assoc_resp_ie_pos = beaconIeLen + assocReqLen +
4403 sizeof(A_UINT16) + /* capinfo*/
4404 sizeof(A_UINT16) + /* status Code */
4405 sizeof(A_UINT16) ; /* associd */
4406 A_MEMZERO(buf, sizeof(buf));
4407 sprintf(buf, "%s", tag2);
4409 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= "));
4411 * The Association Response Frame w.o. the WLAN header is delivered to
4412 * the host, so skip over to the IEs
4414 for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++)
4416 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4417 sprintf(pos, "%2.2x", assocInfo[i]);
4420 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4422 A_MEMZERO(&wrqu, sizeof(wrqu));
4423 wrqu.data.length = strlen(buf);
4424 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4427 if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) {
4429 * assoc Request includes capability and listen interval. Skip these.
4431 assoc_req_ie_pos = beaconIeLen +
4432 sizeof(A_UINT16) + /* capinfo*/
4433 sizeof(A_UINT16); /* listen interval */
4435 A_MEMZERO(buf, sizeof(buf));
4436 sprintf(buf, "%s", tag1);
4438 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= "));
4439 for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) {
4440 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4441 sprintf(pos, "%2.2x", assocInfo[i]);
4444 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4446 A_MEMZERO(&wrqu, sizeof(wrqu));
4447 wrqu.data.length = strlen(buf);
4448 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4452 if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN &&
4453 ar->user_saved_keys.keyOk == TRUE)
4455 key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC;
4457 if (ar->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) {
4458 key_op_ctrl &= ~KEY_OP_INIT_RSC;
4460 key_op_ctrl |= KEY_OP_INIT_RSC;
4462 ar6000_reinstall_keys(ar, key_op_ctrl);
4464 #endif /* USER_KEYS */
4466 netif_wake_queue(ar->arNetDev);
4468 /* For CFG80211 the key configuration and the default key comes in after connect so no point in plumbing invalid keys */
4469 #ifndef ATH6K_CONFIG_CFG80211
4470 if ((networkType & ADHOC_NETWORK) &&
4471 (OPEN_AUTH == ar->arDot11AuthMode) &&
4472 (NONE_AUTH == ar->arAuthMode) &&
4473 (WEP_CRYPT == ar->arPairwiseCrypto))
4475 if (!ar->arConnected) {
4476 wmi_addKey_cmd(ar->arWmi,
4477 ar->arDefTxKeyIndex,
4479 GROUP_USAGE | TX_USAGE,
4480 ar->arWepKeyList[ar->arDefTxKeyIndex].arKeyLen,
4482 ar->arWepKeyList[ar->arDefTxKeyIndex].arKey, KEY_OP_INIT_VAL, NULL,
4486 #endif /* ATH6K_CONFIG_CFG80211 */
4488 /* Update connect & link status atomically */
4489 spin_lock_irqsave(&ar->arLock, flags);
4490 ar->arConnected = TRUE;
4491 ar->arConnectPending = FALSE;
4492 netif_carrier_on(ar->arNetDev);
4493 spin_unlock_irqrestore(&ar->arLock, flags);
4494 /* reset the rx aggr state */
4495 aggr_reset_state(ar->aggr_cntxt);
4498 A_MEMZERO(&wrqu, sizeof(wrqu));
4499 A_MEMCPY(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN);
4500 wrqu.addr.sa_family = ARPHRD_ETHER;
4501 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4502 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable) {
4503 A_MEMZERO(ar->arNodeMap, sizeof(ar->arNodeMap));
4505 ar->arNexEpId = ENDPOINT_2;
4507 if (!ar->arUserBssFilter) {
4508 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4513 void ar6000_set_numdataendpts(AR_SOFTC_T *ar, A_UINT32 num)
4515 A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1));
4516 ar->arNumDataEndPts = num;
4520 sta_cleanup(AR_SOFTC_T *ar, A_UINT8 i)
4522 struct sk_buff *skb;
4524 /* empty the queued pkts in the PS queue if any */
4525 A_MUTEX_LOCK(&ar->sta_list[i].psqLock);
4526 while (!A_NETBUF_QUEUE_EMPTY(&ar->sta_list[i].psq)) {
4527 skb = A_NETBUF_DEQUEUE(&ar->sta_list[i].psq);
4530 A_MUTEX_UNLOCK(&ar->sta_list[i].psqLock);
4532 /* Zero out the state fields */
4533 A_MEMZERO(&ar->arAPStats.sta[ar->sta_list[i].aid-1], sizeof(WMI_PER_STA_STAT));
4534 A_MEMZERO(&ar->sta_list[i].mac, ATH_MAC_LEN);
4535 A_MEMZERO(&ar->sta_list[i].wpa_ie, IEEE80211_MAX_IE);
4536 ar->sta_list[i].aid = 0;
4537 ar->sta_list[i].flags = 0;
4539 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
4544 remove_sta(AR_SOFTC_T *ar, A_UINT8 *mac, A_UINT16 reason)
4546 A_UINT8 i, removed=0;
4548 if(IS_MAC_NULL(mac)) {
4552 if(IS_MAC_BCAST(mac)) {
4553 A_PRINTF("DEL ALL STA\n");
4554 for(i=0; i < AP_MAX_NUM_STA; i++) {
4555 if(!IS_MAC_NULL(ar->sta_list[i].mac)) {
4561 for(i=0; i < AP_MAX_NUM_STA; i++) {
4562 if(A_MEMCMP(ar->sta_list[i].mac, mac, ATH_MAC_LEN)==0) {
4563 A_PRINTF("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4564 " aid=%d REASON=%d\n", mac[0], mac[1], mac[2],
4565 mac[3], mac[4], mac[5], ar->sta_list[i].aid, reason);
4577 ar6000_disconnect_event(AR_SOFTC_T *ar, A_UINT8 reason, A_UINT8 *bssid,
4578 A_UINT8 assocRespLen, A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus)
4581 unsigned long flags;
4582 union iwreq_data wrqu;
4584 if(ar->arNetworkType & AP_NETWORK) {
4585 union iwreq_data wrqu;
4586 struct sk_buff *skb;
4588 if(!remove_sta(ar, bssid, protocolReasonStatus)) {
4592 /* If there are no more associated STAs, empty the mcast PS q */
4593 if (ar->sta_list_index == 0) {
4594 A_MUTEX_LOCK(&ar->mcastpsqLock);
4595 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
4596 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
4599 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
4601 /* Clear the LSB of the BitMapCtl field of the TIM IE */
4602 if (ar->arWmiReady) {
4603 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
4607 if(!IS_MAC_BCAST(bssid)) {
4608 /* Send event to application */
4609 A_MEMZERO(&wrqu, sizeof(wrqu));
4610 A_MEMCPY(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4611 wireless_send_event(ar->arNetDev, IWEVEXPIRED, &wrqu, NULL);
4616 #ifdef ATH6K_CONFIG_CFG80211
4617 ar6k_cfg80211_disconnect_event(ar, reason, bssid,
4618 assocRespLen, assocInfo,
4619 protocolReasonStatus);
4620 #endif /* ATH6K_CONFIG_CFG80211 */
4622 /* Send disconnect event to supplicant */
4623 A_MEMZERO(&wrqu, sizeof(wrqu));
4624 wrqu.addr.sa_family = ARPHRD_ETHER;
4625 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4627 /* it is necessary to clear the host-side rx aggregation state */
4628 aggr_reset_state(ar->aggr_cntxt);
4630 A_UNTIMEOUT(&ar->disconnect_timer);
4632 A_PRINTF("AR6000 disconnected");
4633 if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) {
4634 A_PRINTF(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4635 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
4638 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason));
4639 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus));
4640 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s",
4641 assocRespLen ? " " : "NULL"));
4642 for (i = 0; i < assocRespLen; i++) {
4644 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4646 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4648 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4650 * If the event is due to disconnect cmd from the host, only they the target
4651 * would stop trying to connect. Under any other condition, target would
4652 * keep trying to connect.
4655 if( reason == DISCONNECT_CMD)
4657 ar->arConnectPending = FALSE;
4658 if ((!ar->arUserBssFilter) && (ar->arWmiReady)) {
4659 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4662 ar->arConnectPending = TRUE;
4663 if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) ||
4664 ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) {
4665 ar->arConnected = TRUE;
4670 if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady))
4672 bss_t *pWmiSsidnode = NULL;
4674 /* remove the current associated bssid node */
4675 wmi_free_node (ar->arWmi, bssid);
4678 * In case any other same SSID nodes are present
4679 * remove it, since those nodes also not available now
4684 * Find the nodes based on SSID and remove it
4685 * NOTE :: This case will not work out for Hidden-SSID
4687 pWmiSsidnode = wmi_find_Ssidnode (ar->arWmi, ar->arSsid, ar->arSsidLen, FALSE, TRUE);
4691 wmi_free_node (ar->arWmi, pWmiSsidnode->ni_macaddr);
4694 } while (pWmiSsidnode);
4697 /* Update connect & link status atomically */
4698 spin_lock_irqsave(&ar->arLock, flags);
4699 ar->arConnected = FALSE;
4700 netif_carrier_off(ar->arNetDev);
4701 spin_unlock_irqrestore(&ar->arLock, flags);
4703 if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) {
4708 if (reason != CSERV_DISCONNECT)
4710 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
4711 ar->user_key_ctrl = 0;
4713 #endif /* USER_KEYS */
4715 netif_stop_queue(ar->arNetDev);
4716 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
4717 ar->arBssChannel = 0;
4718 ar->arBeaconInterval = 0;
4720 ar6000_TxDataCleanup(ar);
4724 ar6000_regDomain_event(AR_SOFTC_T *ar, A_UINT32 regCode)
4726 A_PRINTF("AR6000 Reg Code = 0x%x\n", regCode);
4727 ar->arRegCode = regCode;
4730 #ifdef ATH_AR6K_11N_SUPPORT
4732 ar6000_aggr_rcv_addba_req_evt(AR_SOFTC_T *ar, WMI_ADDBA_REQ_EVENT *evt)
4734 if(evt->status == 0) {
4735 aggr_recv_addba_req_evt(ar->aggr_cntxt, evt->tid, evt->st_seq_no, evt->win_sz);
4740 ar6000_aggr_rcv_addba_resp_evt(AR_SOFTC_T *ar, WMI_ADDBA_RESP_EVENT *evt)
4742 A_PRINTF("ADDBA RESP. tid %d status %d, sz %d\n", evt->tid, evt->status, evt->amsdu_sz);
4743 if(evt->status == 0) {
4748 ar6000_aggr_rcv_delba_req_evt(AR_SOFTC_T *ar, WMI_DELBA_EVENT *evt)
4750 aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid);
4754 void register_pal_cb(ar6k_pal_config_t *palConfig_p)
4756 ar6k_pal_config_g = *palConfig_p;
4760 ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd)
4765 A_STATUS ret = A_OK;
4767 size = cmd->evt_buf_sz + 4;
4768 osbuf = A_NETBUF_ALLOC(size);
4769 if (osbuf == NULL) {
4771 A_PRINTF("Error in allocating netbuf \n");
4775 A_NETBUF_PUT(osbuf, size);
4776 buf = (A_UINT8 *)A_NETBUF_DATA(osbuf);
4777 /* First 2-bytes carry HCI event/ACL data type
4778 * the next 2 are free
4780 *((short *)buf) = WMI_HCI_EVENT_EVENTID;
4782 A_MEMCPY(buf, cmd->buf, cmd->evt_buf_sz);
4784 if(ar6k_pal_config_g.fpar6k_pal_recv_pkt)
4786 /* pass the cmd packet to PAL driver */
4787 if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, osbuf) == TRUE)
4790 ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf);
4792 A_PRINTF_LOG("HCI Event From PAL <-- \n");
4793 for(i = 0; i < cmd->evt_buf_sz; i++) {
4794 A_PRINTF_LOG("0x%02x ", cmd->buf[i]);
4800 A_PRINTF_LOG("==================================\n");
4805 ar6000_neighborReport_event(AR_SOFTC_T *ar, int numAps, WMI_NEIGHBOR_INFO *info)
4807 #if WIRELESS_EXT >= 18
4808 struct iw_pmkid_cand *pmkcand;
4809 #else /* WIRELESS_EXT >= 18 */
4810 static const char *tag = "PRE-AUTH";
4812 #endif /* WIRELESS_EXT >= 18 */
4814 union iwreq_data wrqu;
4817 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("AR6000 Neighbor Report Event\n"));
4818 for (i=0; i < numAps; info++, i++) {
4819 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4820 info->bssid[0], info->bssid[1], info->bssid[2],
4821 info->bssid[3], info->bssid[4], info->bssid[5]));
4822 if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) {
4823 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("preauth-cap"));
4825 if (info->bssFlags & WMI_PMKID_VALID_BSS) {
4826 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,(" pmkid-valid\n"));
4827 continue; /* we skip bss if the pmkid is already valid */
4829 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("\n"));
4830 A_MEMZERO(&wrqu, sizeof(wrqu));
4831 #if WIRELESS_EXT >= 18
4832 pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand));
4833 A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand));
4835 pmkcand->flags = info->bssFlags;
4836 A_MEMCPY(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN);
4837 wrqu.data.length = sizeof(struct iw_pmkid_cand);
4838 wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand);
4840 #else /* WIRELESS_EXT >= 18 */
4841 snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
4843 info->bssid[0], info->bssid[1], info->bssid[2],
4844 info->bssid[3], info->bssid[4], info->bssid[5],
4846 wrqu.data.length = strlen(buf);
4847 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4848 #endif /* WIRELESS_EXT >= 18 */
4853 ar6000_tkip_micerr_event(AR_SOFTC_T *ar, A_UINT8 keyid, A_BOOL ismcast)
4855 static const char *tag = "MLME-MICHAELMICFAILURE.indication";
4857 union iwreq_data wrqu;
4860 * For AP case, keyid will have aid of STA which sent pkt with
4861 * MIC error. Use this aid to get MAC & send it to hostapd.
4863 if (ar->arNetworkType == AP_NETWORK) {
4864 sta_t *s = ieee80211_find_conn_for_aid(ar, (keyid >> 2));
4866 A_PRINTF("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid);
4869 A_PRINTF("AP TKIP MIC error received from aid=%d\n", keyid);
4870 snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
4871 tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]);
4874 #ifdef ATH6K_CONFIG_CFG80211
4875 ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast);
4876 #endif /* ATH6K_CONFIG_CFG80211 */
4878 A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n",
4879 keyid & 0x3, ismcast ? "multi": "uni");
4880 snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3,
4881 ismcast ? "mult" : "un");
4884 memset(&wrqu, 0, sizeof(wrqu));
4885 wrqu.data.length = strlen(buf);
4886 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4890 ar6000_scanComplete_event(AR_SOFTC_T *ar, A_STATUS status)
4893 #ifdef ATH6K_CONFIG_CFG80211
4894 ar6k_cfg80211_scanComplete_event(ar, status);
4895 #endif /* ATH6K_CONFIG_CFG80211 */
4897 if (!ar->arUserBssFilter) {
4898 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4900 if (ar->scan_triggered) {
4902 union iwreq_data wrqu;
4903 A_MEMZERO(&wrqu, sizeof(wrqu));
4904 wireless_send_event(ar->arNetDev, SIOCGIWSCAN, &wrqu, NULL);
4906 ar->scan_triggered = 0;
4909 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,( "AR6000 scan complete: %d\n", status));
4913 ar6000_targetStats_event(AR_SOFTC_T *ar, A_UINT8 *ptr, A_UINT32 len)
4917 if(ar->arNetworkType == AP_NETWORK) {
4918 WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr;
4919 WMI_AP_MODE_STAT *ap = &ar->arAPStats;
4921 if (len < sizeof(*p)) {
4925 for(ac=0;ac<AP_MAX_NUM_STA;ac++) {
4926 ap->sta[ac].tx_bytes += p->sta[ac].tx_bytes;
4927 ap->sta[ac].tx_pkts += p->sta[ac].tx_pkts;
4928 ap->sta[ac].tx_error += p->sta[ac].tx_error;
4929 ap->sta[ac].tx_discard += p->sta[ac].tx_discard;
4930 ap->sta[ac].rx_bytes += p->sta[ac].rx_bytes;
4931 ap->sta[ac].rx_pkts += p->sta[ac].rx_pkts;
4932 ap->sta[ac].rx_error += p->sta[ac].rx_error;
4933 ap->sta[ac].rx_discard += p->sta[ac].rx_discard;
4937 WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr;
4938 TARGET_STATS *pStats = &ar->arTargetStats;
4940 if (len < sizeof(*pTarget)) {
4944 // Update the RSSI of the connected bss.
4945 if (ar->arConnected) {
4946 bss_t *pConnBss = NULL;
4948 pConnBss = wmi_find_node(ar->arWmi,ar->arBssid);
4951 pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
4952 pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr;
4953 wmi_node_return(ar->arWmi, pConnBss);
4957 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n"));
4958 pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets;
4959 pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes;
4960 pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts;
4961 pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes;
4962 pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts;
4963 pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes;
4964 pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts;
4965 pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes;
4966 pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt;
4967 for(ac = 0; ac < WMM_NUM_AC; ac++)
4968 pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac];
4969 pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors;
4970 pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt;
4971 pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt;
4972 pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt;
4973 pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt;
4974 pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate);
4976 pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets;
4977 pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes;
4978 pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts;
4979 pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes;
4980 pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts;
4981 pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes;
4982 pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts;
4983 pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes;
4984 pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt;
4985 pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors;
4986 pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr;
4987 pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss;
4988 pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err;
4989 pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames;
4990 pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate);
4993 pStats->tkip_local_mic_failure
4994 += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure;
4995 pStats->tkip_counter_measures_invoked
4996 += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked;
4997 pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays;
4998 pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors;
4999 pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors;
5000 pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays;
5002 pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt;
5003 pStats->noise_floor_calibation = pTarget->noise_floor_calibation;
5005 pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt;
5006 pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt;
5007 pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt;
5008 pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt;
5009 pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr;
5010 pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
5012 if (enablerssicompensation) {
5013 pStats->cs_aveBeacon_rssi =
5014 rssi_compensation_calc(ar, pStats->cs_aveBeacon_rssi);
5016 pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec;
5017 pStats->cs_snr = pTarget->cservStats.cs_snr;
5018 pStats->cs_rssi = pTarget->cservStats.cs_rssi;
5020 pStats->lq_val = pTarget->lqVal;
5022 pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped;
5023 pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups;
5024 pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups;
5025 pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded;
5026 pStats->arp_received += pTarget->arpStats.arp_received;
5027 pStats->arp_matched += pTarget->arpStats.arp_matched;
5028 pStats->arp_replied += pTarget->arpStats.arp_replied;
5030 if (ar->statsUpdatePending) {
5031 ar->statsUpdatePending = FALSE;
5038 ar6000_rssiThreshold_event(AR_SOFTC_T *ar, WMI_RSSI_THRESHOLD_VAL newThreshold, A_INT16 rssi)
5040 USER_RSSI_THOLD userRssiThold;
5042 rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR;
5044 if (enablerssicompensation) {
5045 rssi = rssi_compensation_calc(ar, rssi);
5048 /* Send an event to the app */
5049 userRssiThold.tag = ar->rssi_map[newThreshold].tag;
5050 userRssiThold.rssi = rssi;
5051 A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold,
5052 userRssiThold.tag, userRssiThold.rssi);
5054 ar6000_send_event_to_app(ar, WMI_RSSI_THRESHOLD_EVENTID,(A_UINT8 *)&userRssiThold, sizeof(USER_RSSI_THOLD));
5059 ar6000_hbChallengeResp_event(AR_SOFTC_T *ar, A_UINT32 cookie, A_UINT32 source)
5061 if (source == APP_HB_CHALLENGE) {
5062 /* Report it to the app in case it wants a positive acknowledgement */
5063 ar6000_send_event_to_app(ar, WMIX_HB_CHALLENGE_RESP_EVENTID,
5064 (A_UINT8 *)&cookie, sizeof(cookie));
5066 /* This would ignore the replys that come in after their due time */
5067 if (cookie == ar->arHBChallengeResp.seqNum) {
5068 ar->arHBChallengeResp.outstanding = FALSE;
5075 ar6000_reportError_event(AR_SOFTC_T *ar, WMI_TARGET_ERROR_VAL errorVal)
5077 static const char * const errString[] = {
5078 [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL",
5079 [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND",
5080 [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR",
5081 [WMI_TARGET_BMISS] "WMI_TARGET_BMISS",
5082 [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN"
5085 A_PRINTF("AR6000 Error on Target. Error = 0x%x\n", errorVal);
5087 /* One error is reported at a time, and errorval is a bitmask */
5088 if(errorVal & (errorVal - 1))
5091 A_PRINTF("AR6000 Error type = ");
5094 case WMI_TARGET_PM_ERR_FAIL:
5095 case WMI_TARGET_KEY_NOT_FOUND:
5096 case WMI_TARGET_DECRYPTION_ERR:
5097 case WMI_TARGET_BMISS:
5098 case WMI_PSDISABLE_NODE_JOIN:
5099 A_PRINTF("%s\n", errString[errorVal]);
5102 A_PRINTF("INVALID\n");
5110 ar6000_cac_event(AR_SOFTC_T *ar, A_UINT8 ac, A_UINT8 cacIndication,
5111 A_UINT8 statusCode, A_UINT8 *tspecSuggestion)
5113 WMM_TSPEC_IE *tspecIe;
5116 * This is the TSPEC IE suggestion from AP.
5117 * Suggestion provided by AP under some error
5118 * cases, could be helpful for the host app.
5119 * Check documentation.
5121 tspecIe = (WMM_TSPEC_IE *)tspecSuggestion;
5124 * What do we do, if we get TSPEC rejection? One thought
5125 * that comes to mind is implictly delete the pstream...
5127 A_PRINTF("AR6000 CAC notification. "
5128 "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n",
5129 ac, cacIndication, statusCode);
5133 ar6000_channel_change_event(AR_SOFTC_T *ar, A_UINT16 oldChannel,
5134 A_UINT16 newChannel)
5136 A_PRINTF("Channel Change notification\nOld Channel: %d, New Channel: %d\n",
5137 oldChannel, newChannel);
5140 #define AR6000_PRINT_BSSID(_pBss) do { \
5141 A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\
5142 (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\
5143 (_pBss)[4],(_pBss)[5]); \
5147 ar6000_roam_tbl_event(AR_SOFTC_T *ar, WMI_TARGET_ROAM_TBL *pTbl)
5151 A_PRINTF("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n",
5152 pTbl->numEntries, pTbl->roamMode);
5153 for (i= 0; i < pTbl->numEntries; i++) {
5154 A_PRINTF("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i,
5155 pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1],
5156 pTbl->bssRoamInfo[i].bssid[2],
5157 pTbl->bssRoamInfo[i].bssid[3],
5158 pTbl->bssRoamInfo[i].bssid[4],
5159 pTbl->bssRoamInfo[i].bssid[5]);
5160 A_PRINTF("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d"
5162 pTbl->bssRoamInfo[i].rssi,
5163 pTbl->bssRoamInfo[i].rssidt,
5164 pTbl->bssRoamInfo[i].last_rssi,
5165 pTbl->bssRoamInfo[i].util,
5166 pTbl->bssRoamInfo[i].roam_util,
5167 pTbl->bssRoamInfo[i].bias);
5172 ar6000_wow_list_event(struct ar6_softc *ar, A_UINT8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply)
5176 /*Each event now contains exactly one filter, see bug 26613*/
5177 A_PRINTF("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters);
5178 A_PRINTF("wow mode = %s host mode = %s\n",
5179 (wow_reply->wow_mode == 0? "disabled":"enabled"),
5180 (wow_reply->host_mode == 1 ? "awake":"asleep"));
5183 /*If there are no patterns, the reply will only contain generic
5184 WoW information. Pattern information will exist only if there are
5185 patterns present. Bug 26716*/
5187 /* If this event contains pattern information, display it*/
5188 if (wow_reply->this_filter_num) {
5190 A_PRINTF("id=%d size=%d offset=%d\n",
5191 wow_reply->wow_filters[i].wow_filter_id,
5192 wow_reply->wow_filters[i].wow_filter_size,
5193 wow_reply->wow_filters[i].wow_filter_offset);
5194 A_PRINTF("wow pattern = ");
5195 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5196 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j]);
5199 A_PRINTF("\nwow mask = ");
5200 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5201 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j]);
5208 * Report the Roaming related data collected on the target
5211 ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p)
5213 A_PRINTF("Disconnect Data : BSSID: ");
5214 AR6000_PRINT_BSSID(p->disassoc_bssid);
5215 A_PRINTF(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n",
5216 p->disassoc_bss_rssi,p->disassoc_time,
5218 A_PRINTF("Connect Data: BSSID: ");
5219 AR6000_PRINT_BSSID(p->assoc_bssid);
5220 A_PRINTF(" RSSI %d ASSOC Time %d TXRX_TIME %d\n",
5221 p->assoc_bss_rssi,p->assoc_time,
5222 p->allow_txrx_time);
5226 ar6000_roam_data_event(AR_SOFTC_T *ar, WMI_TARGET_ROAM_DATA *p)
5228 switch (p->roamDataType) {
5229 case ROAM_DATA_TIME:
5230 ar6000_display_roam_time(&p->u.roamTime);
5238 ar6000_bssInfo_event_rx(AR_SOFTC_T *ar, A_UINT8 *datap, int len)
5240 struct sk_buff *skb;
5241 WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap;
5244 if (!ar->arMgmtFilter) {
5247 if (((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) &&
5248 (bih->frameType != BEACON_FTYPE)) ||
5249 ((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) &&
5250 (bih->frameType != PROBERESP_FTYPE)))
5255 if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) {
5257 A_NETBUF_PUT(skb, len);
5258 A_MEMCPY(A_NETBUF_DATA(skb), datap, len);
5259 skb->dev = ar->arNetDev;
5260 A_MEMCPY(skb_mac_header(skb), A_NETBUF_DATA(skb), 6);
5261 skb->ip_summed = CHECKSUM_NONE;
5262 skb->pkt_type = PACKET_OTHERHOST;
5263 skb->protocol = __constant_htons(0x0019);
5268 A_UINT32 wmiSendCmdNum;
5271 ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid)
5273 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
5274 A_STATUS status = A_OK;
5275 struct ar_cookie *cookie = NULL;
5278 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
5279 A_NETBUF_FREE(osbuf);
5282 #endif /* CONFIG_PM */
5283 /* take lock to protect ar6000_alloc_cookie() */
5284 AR6000_SPIN_LOCK(&ar->arLock, 0);
5288 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%lx, len=0x%x eid =%d\n",
5289 (unsigned long)osbuf, A_NETBUF_LEN(osbuf), eid));
5291 if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) {
5292 /* control endpoint is full, don't allocate resources, we
5293 * are just going to drop this packet */
5295 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%lX, len:%d \n",
5296 (unsigned long)osbuf, A_NETBUF_LEN(osbuf)));
5298 cookie = ar6000_alloc_cookie(ar);
5301 if (cookie == NULL) {
5302 status = A_NO_MEMORY;
5307 A_PRINTF("WMI cmd send, msgNo %d :", wmiSendCmdNum);
5308 for(i = 0; i < a_netbuf_to_len(osbuf); i++)
5309 A_PRINTF("%x ", ((A_UINT8 *)a_netbuf_to_data(osbuf))[i]);
5317 if (cookie != NULL) {
5318 /* got a structure to send it out on */
5319 ar->arTxPending[eid]++;
5321 if (eid != ar->arControlEp) {
5322 ar->arTotalTxDataPending++;
5326 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5328 if (cookie != NULL) {
5329 cookie->arc_bp[0] = (unsigned long)osbuf;
5330 cookie->arc_bp[1] = 0;
5331 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
5333 A_NETBUF_DATA(osbuf),
5334 A_NETBUF_LEN(osbuf),
5336 AR6K_CONTROL_PKT_TAG);
5337 /* this interface is asynchronous, if there is an error, cleanup will happen in the
5338 * TX completion callback */
5339 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
5343 if (status != A_OK) {
5344 A_NETBUF_FREE(osbuf);
5349 /* indicate tx activity or inactivity on a WMI stream */
5350 void ar6000_indicate_tx_activity(void *devt, A_UINT8 TrafficClass, A_BOOL Active)
5352 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
5353 HTC_ENDPOINT_ID eid ;
5356 if (ar->arWmiEnabled) {
5357 eid = arAc2EndpointID(ar, TrafficClass);
5359 AR6000_SPIN_LOCK(&ar->arLock, 0);
5361 ar->arAcStreamActive[TrafficClass] = Active;
5364 /* when a stream goes active, keep track of the active stream with the highest priority */
5366 if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) {
5367 /* set the new highest active priority */
5368 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass];
5372 /* when a stream goes inactive, we may have to search for the next active stream
5373 * that is the highest priority */
5375 if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) {
5377 /* the highest priority stream just went inactive */
5379 /* reset and search for the "next" highest "active" priority stream */
5380 ar->arHiAcStreamActivePri = 0;
5381 for (i = 0; i < WMM_NUM_AC; i++) {
5382 if (ar->arAcStreamActive[i]) {
5383 if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) {
5384 /* set the new highest active priority */
5385 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i];
5392 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5395 /* for mbox ping testing, the traffic class is mapped directly as a stream ID,
5396 * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c
5397 * convert the stream ID to a endpoint */
5398 eid = arAc2EndpointID(ar, TrafficClass);
5401 /* notify HTC, this may cause credit distribution changes */
5403 HTCIndicateActivityChange(ar->arHtcTarget,
5410 ar6000_btcoex_config_event(struct ar6_softc *ar, A_UINT8 *ptr, A_UINT32 len)
5413 WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr;
5414 WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&ar->arBtcoexConfig;
5416 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5418 A_PRINTF("received config event\n");
5419 pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType;
5420 pArbtcoexConfig->linkId = pBtcoexConfig->linkId;
5422 switch (pBtcoexConfig->btProfileType) {
5423 case WMI_BTCOEX_BT_PROFILE_SCO:
5424 A_MEMCPY(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd,
5425 sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD));
5427 case WMI_BTCOEX_BT_PROFILE_A2DP:
5428 A_MEMCPY(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd,
5429 sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD));
5431 case WMI_BTCOEX_BT_PROFILE_ACLCOEX:
5432 A_MEMCPY(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig,
5433 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5435 case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE:
5436 A_MEMCPY(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd,
5437 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5440 if (ar->statsUpdatePending) {
5441 ar->statsUpdatePending = FALSE;
5447 ar6000_btcoex_stats_event(struct ar6_softc *ar, A_UINT8 *ptr, A_UINT32 len)
5449 WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr;
5451 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5453 A_MEMCPY(&ar->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT));
5455 if (ar->statsUpdatePending) {
5456 ar->statsUpdatePending = FALSE;
5461 module_init(ar6000_init_module);
5462 module_exit(ar6000_cleanup_module);
5464 /* Init cookie queue */
5466 ar6000_cookie_init(AR_SOFTC_T *ar)
5470 ar->arCookieList = NULL;
5471 ar->arCookieCount = 0;
5473 A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem));
5475 for (i = 0; i < MAX_COOKIE_NUM; i++) {
5476 ar6000_free_cookie(ar, &s_ar_cookie_mem[i]);
5480 /* cleanup cookie queue */
5482 ar6000_cookie_cleanup(AR_SOFTC_T *ar)
5484 /* It is gone .... */
5485 ar->arCookieList = NULL;
5486 ar->arCookieCount = 0;
5489 /* Init cookie queue */
5491 ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie)
5494 A_ASSERT(ar != NULL);
5495 A_ASSERT(cookie != NULL);
5497 cookie->arc_list_next = ar->arCookieList;
5498 ar->arCookieList = cookie;
5499 ar->arCookieCount++;
5502 /* cleanup cookie queue */
5503 static struct ar_cookie *
5504 ar6000_alloc_cookie(AR_SOFTC_T *ar)
5506 struct ar_cookie *cookie;
5508 cookie = ar->arCookieList;
5511 ar->arCookieList = cookie->arc_list_next;
5512 ar->arCookieCount--;
5518 #ifdef SEND_EVENT_TO_APP
5520 * This function is used to send event which come from taget to
5521 * the application. The buf which send to application is include
5522 * the event ID and event content.
5524 #define EVENT_ID_LEN 2
5525 void ar6000_send_event_to_app(AR_SOFTC_T *ar, A_UINT16 eventId,
5526 A_UINT8 *datap, int len)
5529 #if (WIRELESS_EXT >= 15)
5531 /* note: IWEVCUSTOM only exists in wireless extensions after version 15 */
5535 union iwreq_data wrqu;
5537 size = len + EVENT_ID_LEN;
5539 if (size > IW_CUSTOM_MAX) {
5540 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVCUSTOM (max=%d) \n",
5541 eventId, size, IW_CUSTOM_MAX));
5545 buf = A_MALLOC_NOWAIT(size);
5547 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size));
5551 A_MEMZERO(buf, size);
5552 A_MEMCPY(buf, &eventId, EVENT_ID_LEN);
5553 A_MEMCPY(buf+EVENT_ID_LEN, datap, len);
5555 //AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("event ID = %d,len = %d\n",*(A_UINT16*)buf, size));
5556 A_MEMZERO(&wrqu, sizeof(wrqu));
5557 wrqu.data.length = size;
5558 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
5566 * This function is used to send events larger than 256 bytes
5567 * to the application. The buf which is sent to application
5568 * includes the event ID and event content.
5570 void ar6000_send_generic_event_to_app(AR_SOFTC_T *ar, A_UINT16 eventId,
5571 A_UINT8 *datap, int len)
5574 #if (WIRELESS_EXT >= 18)
5576 /* IWEVGENIE exists in wireless extensions version 18 onwards */
5580 union iwreq_data wrqu;
5582 size = len + EVENT_ID_LEN;
5584 if (size > IW_GENERIC_IE_MAX) {
5585 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVGENIE (max=%d) \n",
5586 eventId, size, IW_GENERIC_IE_MAX));
5590 buf = A_MALLOC_NOWAIT(size);
5592 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size));
5596 A_MEMZERO(buf, size);
5597 A_MEMCPY(buf, &eventId, EVENT_ID_LEN);
5598 A_MEMCPY(buf+EVENT_ID_LEN, datap, len);
5600 A_MEMZERO(&wrqu, sizeof(wrqu));
5601 wrqu.data.length = size;
5602 wireless_send_event(ar->arNetDev, IWEVGENIE, &wrqu, buf);
5606 #endif /* (WIRELESS_EXT >= 18) */
5609 #endif /* SEND_EVENT_TO_APP */
5613 ar6000_tx_retry_err_event(void *devt)
5615 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n"));
5619 ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, A_UINT8 snr)
5621 WMI_SNR_THRESHOLD_EVENT event;
5622 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
5624 event.range = newThreshold;
5627 ar6000_send_event_to_app(ar, WMI_SNR_THRESHOLD_EVENTID, (A_UINT8 *)&event,
5628 sizeof(WMI_SNR_THRESHOLD_EVENT));
5632 ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, A_UINT8 lq)
5634 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq));
5640 a_copy_to_user(void *to, const void *from, A_UINT32 n)
5642 return(copy_to_user(to, from, n));
5646 a_copy_from_user(void *to, const void *from, A_UINT32 n)
5648 return(copy_from_user(to, from, n));
5653 ar6000_get_driver_cfg(struct net_device *dev,
5662 case AR6000_DRIVER_CFG_GET_WLANNODECACHING:
5663 *((A_UINT32 *)result) = wlanNodeCaching;
5665 case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS:
5666 *((A_UINT32 *)result) = logWmiRawMsgs;
5677 ar6000_keepalive_rx(void *devt, A_UINT8 configured)
5679 AR_SOFTC_T *ar = (AR_SOFTC_T *)devt;
5681 ar->arKeepaliveConfigured = configured;
5686 ar6000_pmkid_list_event(void *devt, A_UINT8 numPMKID, WMI_PMKID *pmkidList,
5691 A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID);
5693 for (i = 0; i < numPMKID; i++) {
5694 A_PRINTF("\nBSSID %d ", i);
5695 for (j = 0; j < ATH_MAC_LEN; j++) {
5696 A_PRINTF("%2.2x", bssidList[j]);
5698 bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN);
5699 A_PRINTF("\nPMKID %d ", i);
5700 for (j = 0; j < WMI_PMKID_LEN; j++) {
5701 A_PRINTF("%2.2x", pmkidList->pmkid[j]);
5703 pmkidList = (WMI_PMKID *)((A_UINT8 *)pmkidList + ATH_MAC_LEN +
5708 void ar6000_pspoll_event(AR_SOFTC_T *ar,A_UINT8 aid)
5711 A_BOOL isPsqEmpty = FALSE;
5713 conn = ieee80211_find_conn_for_aid(ar, aid);
5715 /* If the PS q for this STA is not empty, dequeue and send a pkt from
5716 * the head of the q. Also update the More data bit in the WMI_DATA_HDR
5717 * if there are more pkts for this STA in the PS q. If there are no more
5718 * pkts for this STA, update the PVB for this STA.
5720 A_MUTEX_LOCK(&conn->psqLock);
5721 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5722 A_MUTEX_UNLOCK(&conn->psqLock);
5725 /* TODO:No buffered pkts for this STA. Send out a NULL data frame */
5727 struct sk_buff *skb = NULL;
5729 A_MUTEX_LOCK(&conn->psqLock);
5730 skb = A_NETBUF_DEQUEUE(&conn->psq);
5731 A_MUTEX_UNLOCK(&conn->psqLock);
5732 /* Set the STA flag to PSPolled, so that the frame will go out */
5733 STA_SET_PS_POLLED(conn);
5734 ar6000_data_tx(skb, ar->arNetDev);
5735 STA_CLR_PS_POLLED(conn);
5737 /* Clear the PVB for this STA if the queue has become empty */
5738 A_MUTEX_LOCK(&conn->psqLock);
5739 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5740 A_MUTEX_UNLOCK(&conn->psqLock);
5743 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
5748 void ar6000_dtimexpiry_event(AR_SOFTC_T *ar)
5750 A_BOOL isMcastQueued = FALSE;
5751 struct sk_buff *skb = NULL;
5753 /* If there are no associated STAs, ignore the DTIM expiry event.
5754 * There can be potential race conditions where the last associated
5755 * STA may disconnect & before the host could clear the 'Indicate DTIM'
5756 * request to the firmware, the firmware would have just indicated a DTIM
5757 * expiry event. The race is between 'clear DTIM expiry cmd' going
5758 * from the host to the firmware & the DTIM expiry event happening from
5759 * the firmware to the host.
5761 if (ar->sta_list_index == 0) {
5765 A_MUTEX_LOCK(&ar->mcastpsqLock);
5766 isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
5767 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5769 A_ASSERT(isMcastQueued == FALSE);
5771 /* Flush the mcast psq to the target */
5772 /* Set the STA flag to DTIMExpired, so that the frame will go out */
5773 ar->DTIMExpired = TRUE;
5775 A_MUTEX_LOCK(&ar->mcastpsqLock);
5776 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
5777 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
5778 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5780 ar6000_data_tx(skb, ar->arNetDev);
5782 A_MUTEX_LOCK(&ar->mcastpsqLock);
5784 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5786 /* Reset the DTIMExpired flag back to 0 */
5787 ar->DTIMExpired = FALSE;
5789 /* Clear the LSB of the BitMapCtl field of the TIM IE */
5790 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
5794 read_rssi_compensation_param(AR_SOFTC_T *ar)
5796 A_UINT8 *cust_data_ptr;
5798 //#define RSSICOMPENSATION_PRINT
5800 #ifdef RSSICOMPENSATION_PRINT
5802 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5803 for (i=0; i<16; i++) {
5804 A_PRINTF("cust_data_%d = %x \n", i, *(A_UINT8 *)cust_data_ptr);
5809 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5811 rssi_compensation_param.customerID = *(A_UINT16 *)cust_data_ptr & 0xffff;
5812 rssi_compensation_param.enable = *(A_UINT16 *)(cust_data_ptr+2) & 0xffff;
5813 rssi_compensation_param.bg_param_a = *(A_UINT16 *)(cust_data_ptr+4) & 0xffff;
5814 rssi_compensation_param.bg_param_b = *(A_UINT16 *)(cust_data_ptr+6) & 0xffff;
5815 rssi_compensation_param.a_param_a = *(A_UINT16 *)(cust_data_ptr+8) & 0xffff;
5816 rssi_compensation_param.a_param_b = *(A_UINT16 *)(cust_data_ptr+10) &0xffff;
5817 rssi_compensation_param.reserved = *(A_UINT32 *)(cust_data_ptr+12);
5819 #ifdef RSSICOMPENSATION_PRINT
5820 A_PRINTF("customerID = 0x%x \n", rssi_compensation_param.customerID);
5821 A_PRINTF("enable = 0x%x \n", rssi_compensation_param.enable);
5822 A_PRINTF("bg_param_a = 0x%x and %d \n", rssi_compensation_param.bg_param_a, rssi_compensation_param.bg_param_a);
5823 A_PRINTF("bg_param_b = 0x%x and %d \n", rssi_compensation_param.bg_param_b, rssi_compensation_param.bg_param_b);
5824 A_PRINTF("a_param_a = 0x%x and %d \n", rssi_compensation_param.a_param_a, rssi_compensation_param.a_param_a);
5825 A_PRINTF("a_param_b = 0x%x and %d \n", rssi_compensation_param.a_param_b, rssi_compensation_param.a_param_b);
5826 A_PRINTF("Last 4 bytes = 0x%x \n", rssi_compensation_param.reserved);
5829 if (rssi_compensation_param.enable != 0x1) {
5830 rssi_compensation_param.enable = 0;
5837 rssi_compensation_calc_tcmd(A_UINT32 freq, A_INT32 rssi, A_UINT32 totalPkt)
5842 if (rssi_compensation_param.enable)
5844 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5845 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5846 rssi = rssi * rssi_compensation_param.a_param_a + totalPkt * rssi_compensation_param.a_param_b;
5847 rssi = (rssi-50) /100;
5848 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5853 if (rssi_compensation_param.enable)
5855 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5856 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5857 rssi = rssi * rssi_compensation_param.bg_param_a + totalPkt * rssi_compensation_param.bg_param_b;
5858 rssi = (rssi-50) /100;
5859 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5867 rssi_compensation_calc(AR_SOFTC_T *ar, A_INT16 rssi)
5869 if (ar->arBssChannel > 5000)
5871 if (rssi_compensation_param.enable)
5873 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5874 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5875 rssi = rssi * rssi_compensation_param.a_param_a + rssi_compensation_param.a_param_b;
5876 rssi = (rssi-50) /100;
5877 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5882 if (rssi_compensation_param.enable)
5884 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5885 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5886 rssi = rssi * rssi_compensation_param.bg_param_a + rssi_compensation_param.bg_param_b;
5887 rssi = (rssi-50) /100;
5888 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5896 rssi_compensation_reverse_calc(AR_SOFTC_T *ar, A_INT16 rssi, A_BOOL Above)
5900 if (ar->arBssChannel > 5000)
5902 if (rssi_compensation_param.enable)
5904 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5905 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5907 rssi = (rssi - rssi_compensation_param.a_param_b) / rssi_compensation_param.a_param_a;
5908 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5913 if (rssi_compensation_param.enable)
5915 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5916 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5919 for (i=95; i>=0; i--) {
5920 if (rssi <= rssi_compensation_table[i]) {
5926 for (i=0; i<=95; i++) {
5927 if (rssi >= rssi_compensation_table[i]) {
5933 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5941 void ap_wapi_rekey_event(AR_SOFTC_T *ar, A_UINT8 type, A_UINT8 *mac)
5943 union iwreq_data wrqu;
5946 A_MEMZERO(buf, sizeof(buf));
5948 strcpy(buf, "WAPI_REKEY");
5950 A_MEMCPY(&buf[11], mac, ATH_MAC_LEN);
5952 A_MEMZERO(&wrqu, sizeof(wrqu));
5953 wrqu.data.length = 10+1+ATH_MAC_LEN;
5954 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
5956 A_PRINTF("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5]);
5963 ar6000_reinstall_keys(AR_SOFTC_T *ar, A_UINT8 key_op_ctrl)
5965 A_STATUS status = A_OK;
5966 struct ieee80211req_key *uik = &ar->user_saved_keys.ucast_ik;
5967 struct ieee80211req_key *bik = &ar->user_saved_keys.bcast_ik;
5968 CRYPTO_TYPE keyType = ar->user_saved_keys.keyType;
5970 if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) {
5971 if (NONE_CRYPT == keyType) {
5972 goto _reinstall_keys_out;
5975 if (uik->ik_keylen) {
5976 status = wmi_addKey_cmd(ar->arWmi, uik->ik_keyix,
5977 ar->user_saved_keys.keyType, PAIRWISE_USAGE,
5978 uik->ik_keylen, (A_UINT8 *)&uik->ik_keyrsc,
5979 uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG);
5983 status = wmi_add_krk_cmd(ar->arWmi, uik->ik_keydata);
5986 if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) {
5987 if (NONE_CRYPT == keyType) {
5988 goto _reinstall_keys_out;
5991 if (bik->ik_keylen) {
5992 status = wmi_addKey_cmd(ar->arWmi, bik->ik_keyix,
5993 ar->user_saved_keys.keyType, GROUP_USAGE,
5994 bik->ik_keylen, (A_UINT8 *)&bik->ik_keyrsc,
5995 bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG);
5998 status = wmi_add_krk_cmd(ar->arWmi, bik->ik_keydata);
6001 _reinstall_keys_out:
6002 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
6003 ar->user_key_ctrl = 0;
6007 #endif /* USER_KEYS */
6011 ar6000_dset_open_req(
6014 A_UINT32 targHandle,
6015 A_UINT32 targReplyFn,
6016 A_UINT32 targReplyArg)
6023 A_UINT32 access_cookie)
6029 ar6000_dset_data_req(
6031 A_UINT32 accessCookie,
6035 A_UINT32 targReplyFn,
6036 A_UINT32 targReplyArg)
6041 ar6000_ap_mode_profile_commit(struct ar6_softc *ar)
6044 unsigned long flags;
6046 /* No change in AP's profile configuration */
6047 if(ar->ap_profile_flag==0) {
6048 A_PRINTF("COMMIT: No change in profile!!!\n");
6052 if(!ar->arSsidLen) {
6053 A_PRINTF("SSID not set!!!\n");
6057 switch(ar->arAuthMode) {
6059 if((ar->arPairwiseCrypto != NONE_CRYPT) &&
6061 (ar->arPairwiseCrypto != WAPI_CRYPT) &&
6063 (ar->arPairwiseCrypto != WEP_CRYPT)) {
6064 A_PRINTF("Cipher not supported in AP mode Open auth\n");
6070 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
6073 A_PRINTF("This key mgmt type not supported in AP mode\n");
6077 /* Update the arNetworkType */
6078 ar->arNetworkType = ar->arNextMode;
6080 A_MEMZERO(&p,sizeof(p));
6081 p.ssidLength = ar->arSsidLen;
6082 A_MEMCPY(p.ssid,ar->arSsid,p.ssidLength);
6083 p.channel = ar->arChannelHint;
6084 p.networkType = ar->arNetworkType;
6086 p.dot11AuthMode = ar->arDot11AuthMode;
6087 p.authMode = ar->arAuthMode;
6088 p.pairwiseCryptoType = ar->arPairwiseCrypto;
6089 p.pairwiseCryptoLen = ar->arPairwiseCryptoLen;
6090 p.groupCryptoType = ar->arGroupCrypto;
6091 p.groupCryptoLen = ar->arGroupCryptoLen;
6092 p.ctrl_flags = ar->arConnectCtrlFlags;
6094 ar->arConnected = FALSE;
6096 wmi_ap_profile_commit(ar->arWmi, &p);
6097 spin_lock_irqsave(&ar->arLock, flags);
6098 ar->arConnected = TRUE;
6099 netif_carrier_on(ar->arNetDev);
6100 spin_unlock_irqrestore(&ar->arLock, flags);
6101 ar->ap_profile_flag = 0;
6106 ar6000_connect_to_ap(struct ar6_softc *ar)
6108 /* The ssid length check prevents second "essid off" from the user,
6109 to be treated as a connect cmd. The second "essid off" is ignored.
6111 if((ar->arWmiReady == TRUE) && (ar->arSsidLen > 0) && ar->arNetworkType!=AP_NETWORK)
6114 if((ADHOC_NETWORK != ar->arNetworkType) &&
6115 (NONE_AUTH==ar->arAuthMode) &&
6116 (WEP_CRYPT==ar->arPairwiseCrypto)) {
6117 ar6000_install_static_wep_keys(ar);
6120 if (!ar->arUserBssFilter) {
6121 if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != A_OK) {
6126 if (ar->arWapiEnable) {
6127 ar->arPairwiseCrypto = WAPI_CRYPT;
6128 ar->arPairwiseCryptoLen = 0;
6129 ar->arGroupCrypto = WAPI_CRYPT;
6130 ar->arGroupCryptoLen = 0;
6131 ar->arAuthMode = NONE_AUTH;
6132 ar->arConnectCtrlFlags |= CONNECT_IGNORE_WPAx_GROUP_CIPHER;
6135 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\
6136 " PW crypto %d PW crypto Len %d GRP crypto %d"\
6137 " GRP crypto Len %d\n",
6138 ar->arAuthMode, ar->arDot11AuthMode,
6139 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
6140 ar->arGroupCrypto, ar->arGroupCryptoLen));
6142 /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn.
6143 later set it back locally at the STA to 100/1000 TUs depending on the power mode */
6144 if ((ar->arNetworkType == INFRA_NETWORK)) {
6145 wmi_listeninterval_cmd(ar->arWmi, max(ar->arListenIntervalT, (A_UINT16)A_MAX_WOW_LISTEN_INTERVAL), 0);
6147 status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
6148 ar->arDot11AuthMode, ar->arAuthMode,
6149 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
6150 ar->arGroupCrypto,ar->arGroupCryptoLen,
6151 ar->arSsidLen, ar->arSsid,
6152 ar->arReqBssid, ar->arChannelHint,
6153 ar->arConnectCtrlFlags);
6154 if (status != A_OK) {
6155 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
6156 if (!ar->arUserBssFilter) {
6157 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
6162 if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) &&
6163 ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)))
6165 A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0);
6168 ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD;
6170 ar->arConnectPending = TRUE;
6177 ar6000_ap_mode_get_wpa_ie(struct ar6_softc *ar, struct ieee80211req_wpaie *wpaie)
6180 conn = ieee80211_find_conn(ar, wpaie->wpa_macaddr);
6182 A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE);
6183 A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE);
6186 A_MEMCPY(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE);
6193 is_iwioctl_allowed(A_UINT8 mode, A_UINT16 cmd)
6195 if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) {
6196 cmd -= SIOCSIWCOMMIT;
6197 if(sioctl_filter[cmd] == 0xFF) return A_OK;
6198 if(sioctl_filter[cmd] & mode) return A_OK;
6199 } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) {
6200 cmd -= SIOCIWFIRSTPRIV;
6201 if(pioctl_filter[cmd] == 0xFF) return A_OK;
6202 if(pioctl_filter[cmd] & mode) return A_OK;
6210 is_xioctl_allowed(A_UINT8 mode, int cmd)
6212 if(sizeof(xioctl_filter)-1 < cmd) {
6213 A_PRINTF("Filter for this cmd=%d not defined\n",cmd);
6216 if(xioctl_filter[cmd] == 0xFF) return A_OK;
6217 if(xioctl_filter[cmd] & mode) return A_OK;
6223 ap_set_wapi_key(struct ar6_softc *ar, void *ikey)
6225 struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey;
6226 KEY_USAGE keyUsage = 0;
6229 if (A_MEMCMP(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) {
6230 keyUsage = GROUP_USAGE;
6232 keyUsage = PAIRWISE_USAGE;
6234 A_PRINTF("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n",
6235 keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5],
6238 status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage,
6239 ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc,
6240 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
6243 if (A_OK != status) {
6250 void ar6000_peer_event(
6257 for (pos=0;pos<6;pos++)
6258 printk("%02x: ",*(macAddr+pos));
6262 #ifdef HTC_TEST_SEND_PKTS
6263 #define HTC_TEST_DUPLICATE 8
6264 static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb)
6266 struct ar_cookie *cookie;
6267 struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE];
6268 struct sk_buff *new_skb;
6271 HTC_PACKET_QUEUE pktQueue;
6272 EPPING_HEADER *eppingHdr;
6274 eppingHdr = A_NETBUF_DATA(dupskb);
6276 if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) {
6277 /* skip test if this is already a tx perf test */
6281 for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) {
6282 AR6000_SPIN_LOCK(&ar->arLock, 0);
6283 cookie = ar6000_alloc_cookie(ar);
6284 if (cookie != NULL) {
6285 ar->arTxPending[eid]++;
6286 ar->arTotalTxDataPending++;
6289 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6291 if (NULL == cookie) {
6295 new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb));
6297 if (new_skb == NULL) {
6298 AR6000_SPIN_LOCK(&ar->arLock, 0);
6299 ar6000_free_cookie(ar,cookie);
6300 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6304 A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb));
6305 cookie->arc_bp[0] = (unsigned long)new_skb;
6306 cookie->arc_bp[1] = MapNo;
6307 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
6309 A_NETBUF_DATA(new_skb),
6310 A_NETBUF_LEN(new_skb),
6314 cookieArray[i] = cookie;
6317 EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb);
6318 pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */
6326 INIT_HTC_PACKET_QUEUE(&pktQueue);
6328 for (i = 0; i < pkts; i++) {
6329 HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt);
6332 HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue);
6337 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
6339 * Add support for adding and removing a virtual adapter for soft AP.
6340 * Some OS requires different adapters names for station and soft AP mode.
6341 * To support these requirement, create and destory a netdevice instance
6342 * when the AP mode is operational. A full fledged support for virual device
6343 * is not implemented. Rather a virtual interface is created and is linked
6344 * with the existing physical device instance during the operation of the
6348 A_STATUS ar6000_start_ap_interface(AR_SOFTC_T *ar)
6350 AR_VIRTUAL_INTERFACE_T *arApDev;
6352 /* Change net_device to point to AP instance */
6353 arApDev = (AR_VIRTUAL_INTERFACE_T *)ar->arApDev;
6354 ar->arNetDev = arApDev->arNetDev;
6359 A_STATUS ar6000_stop_ap_interface(AR_SOFTC_T *ar)
6361 AR_VIRTUAL_INTERFACE_T *arApDev;
6363 /* Change net_device to point to sta instance */
6364 arApDev = (AR_VIRTUAL_INTERFACE_T *)ar->arApDev;
6366 ar->arNetDev = arApDev->arStaNetDev;
6373 A_STATUS ar6000_create_ap_interface(AR_SOFTC_T *ar, char *ap_ifname)
6375 struct net_device *dev;
6376 AR_VIRTUAL_INTERFACE_T *arApDev;
6378 dev = alloc_etherdev(sizeof(AR_VIRTUAL_INTERFACE_T));
6380 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: can't alloc etherdev\n"));
6385 init_netdev(dev, ap_ifname);
6387 if (register_netdev(dev)) {
6388 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: register_netdev failed\n"));
6392 arApDev = netdev_priv(dev);
6393 arApDev->arDev = ar;
6394 arApDev->arNetDev = dev;
6395 arApDev->arStaNetDev = ar->arNetDev;
6397 ar->arApDev = arApDev;
6400 /* Copy the MAC address */
6401 A_MEMCPY(dev->dev_addr, ar->arNetDev->dev_addr, AR6000_ETH_ADDR_LEN);
6406 A_STATUS ar6000_add_ap_interface(AR_SOFTC_T *ar, char *ap_ifname)
6408 /* Interface already added, need not proceed further */
6409 if (ar->arApDev != NULL) {
6410 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_add_ap_interface: interface already present \n"));
6414 if (ar6000_create_ap_interface(ar, ap_ifname) != A_OK) {
6418 A_PRINTF("Add AP interface %s \n",ap_ifname);
6420 return ar6000_start_ap_interface(ar);
6423 A_STATUS ar6000_remove_ap_interface(AR_SOFTC_T *ar)
6426 ar6000_stop_ap_interface(ar);
6428 unregister_netdev(arApNetDev);
6429 free_netdev(apApNetDev);
6431 A_PRINTF("Remove AP interface\n");
6439 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
6442 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
6443 EXPORT_SYMBOL(setupbtdev);