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 u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
51 u8 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 struct 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 {
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 struct hci_transport_callbacks ar6kHciTransCallbacks = { NULL };
120 unsigned int processDot11Hdr = 0;
122 char ifname[IFNAMSIZ] = {0,};
124 int wlaninitmode = WLAN_INIT_MODE_DEFAULT;
125 static bool bypasswmi;
126 unsigned int debuglevel = 0;
127 int tspecCompliance = ATHEROS_COMPLIANCE;
128 unsigned int busspeedlow = 0;
129 unsigned int onebitmode = 0;
130 unsigned int skipflash = 0;
131 unsigned int wmitimeout = 2;
132 unsigned int wlanNodeCaching = 1;
133 unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT;
134 unsigned int logWmiRawMsgs = 0;
135 unsigned int enabletimerwar = 0;
136 unsigned int fwmode = 1;
137 unsigned int mbox_yield_limit = 99;
138 unsigned int enablerssicompensation = 0;
139 int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF;
140 int allow_trace_signal = 0;
141 #ifdef CONFIG_HOST_TCMD_SUPPORT
142 unsigned int testmode =0;
145 unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC;
146 unsigned int panic_on_assert = 1;
147 unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT;
149 unsigned int setuphci = SETUPHCI_DEFAULT;
150 unsigned int setuphcipal = SETUPHCIPAL_DEFAULT;
151 unsigned int loghci = 0;
152 unsigned int setupbtdev = SETUPBTDEV_DEFAULT;
153 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
154 unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT;
155 unsigned int hciuartscale = HCIUARTSCALE_DEFAULT;
156 unsigned int hciuartstep = HCIUARTSTEP_DEFAULT;
158 #ifdef CONFIG_CHECKSUM_OFFLOAD
159 unsigned int csumOffload=0;
160 unsigned int csumOffloadTest=0;
162 unsigned int eppingtest=0;
164 module_param_string(ifname, ifname, sizeof(ifname), 0644);
165 module_param(wlaninitmode, int, 0644);
166 module_param(bypasswmi, bool, 0644);
167 module_param(debuglevel, uint, 0644);
168 module_param(tspecCompliance, int, 0644);
169 module_param(onebitmode, uint, 0644);
170 module_param(busspeedlow, uint, 0644);
171 module_param(skipflash, uint, 0644);
172 module_param(wmitimeout, uint, 0644);
173 module_param(wlanNodeCaching, uint, 0644);
174 module_param(logWmiRawMsgs, uint, 0644);
175 module_param(enableuartprint, uint, 0644);
176 module_param(enabletimerwar, uint, 0644);
177 module_param(fwmode, uint, 0644);
178 module_param(mbox_yield_limit, uint, 0644);
179 module_param(reduce_credit_dribble, int, 0644);
180 module_param(allow_trace_signal, int, 0644);
181 module_param(enablerssicompensation, uint, 0644);
182 module_param(processDot11Hdr, uint, 0644);
183 #ifdef CONFIG_CHECKSUM_OFFLOAD
184 module_param(csumOffload, uint, 0644);
186 #ifdef CONFIG_HOST_TCMD_SUPPORT
187 module_param(testmode, uint, 0644);
189 module_param(irqprocmode, uint, 0644);
190 module_param(nohifscattersupport, uint, 0644);
191 module_param(panic_on_assert, uint, 0644);
192 module_param(setuphci, uint, 0644);
193 module_param(setuphcipal, uint, 0644);
194 module_param(loghci, uint, 0644);
195 module_param(setupbtdev, uint, 0644);
196 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
197 module_param(ar3khcibaud, uint, 0644);
198 module_param(hciuartscale, uint, 0644);
199 module_param(hciuartstep, uint, 0644);
201 module_param(eppingtest, uint, 0644);
203 /* in 2.6.10 and later this is now a pointer to a uint */
204 unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX;
205 #define mboxnum &_mboxnum
208 u32 g_dbg_flags = DBG_DEFAULTS;
209 unsigned int debugflags = 0;
211 unsigned int debughtc = 0;
212 unsigned int debugbmi = 0;
213 unsigned int debughif = 0;
214 unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0};
215 unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0};
216 unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0};
217 unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0};
218 module_param(debugflags, uint, 0644);
219 module_param(debugdriver, int, 0644);
220 module_param(debughtc, uint, 0644);
221 module_param(debugbmi, uint, 0644);
222 module_param(debughif, uint, 0644);
223 module_param_array(txcreditsavailable, uint, mboxnum, 0644);
224 module_param_array(txcreditsconsumed, uint, mboxnum, 0644);
225 module_param_array(txcreditintrenable, uint, mboxnum, 0644);
226 module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644);
230 unsigned int resetok = 1;
231 unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0};
232 unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0};
233 unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0};
234 unsigned int hifBusRequestNumMax = 40;
235 unsigned int war23838_disabled = 0;
236 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
237 unsigned int enableAPTCHeuristics = 1;
238 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
239 module_param_array(tx_attempt, uint, mboxnum, 0644);
240 module_param_array(tx_post, uint, mboxnum, 0644);
241 module_param_array(tx_complete, uint, mboxnum, 0644);
242 module_param(hifBusRequestNumMax, uint, 0644);
243 module_param(war23838_disabled, uint, 0644);
244 module_param(resetok, uint, 0644);
245 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
246 module_param(enableAPTCHeuristics, uint, 0644);
247 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
249 #ifdef BLOCK_TX_PATH_FLAG
251 module_param(blocktx, int, 0644);
252 #endif /* BLOCK_TX_PATH_FLAG */
254 typedef struct user_rssi_compensation_t {
266 } USER_RSSI_CPENSATION;
268 static USER_RSSI_CPENSATION rssi_compensation_param;
270 static s16 rssi_compensation_table[96];
272 int reconnect_flag = 0;
273 static ar6k_pal_config_t ar6k_pal_config_g;
275 /* Function declarations */
276 static int ar6000_init_module(void);
277 static void ar6000_cleanup_module(void);
279 int ar6000_init(struct net_device *dev);
280 static int ar6000_open(struct net_device *dev);
281 static int ar6000_close(struct net_device *dev);
282 static void ar6000_init_control_info(struct ar6_softc *ar);
283 static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev);
285 void ar6000_destroy(struct net_device *dev, unsigned int unregister);
286 static void ar6000_detect_error(unsigned long ptr);
287 static void ar6000_set_multicast_list(struct net_device *dev);
288 static struct net_device_stats *ar6000_get_stats(struct net_device *dev);
289 static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev);
291 static void disconnect_timer_handler(unsigned long ptr);
293 void read_rssi_compensation_param(struct ar6_softc *ar);
295 /* for android builds we call external APIs that handle firmware download and configuration */
297 /* !!!! Interim android support to make it easier to patch the default driver for
298 * android use. You must define an external source file ar6000_android.c that handles the following
300 extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks);
301 extern void android_module_exit(void);
304 * HTC service connection handlers
306 static int ar6000_avail_ev(void *context, void *hif_handle);
308 static int ar6000_unavail_ev(void *context, void *hif_handle);
310 int ar6000_configure_target(struct ar6_softc *ar);
312 static void ar6000_target_failure(void *Instance, int Status);
314 static void ar6000_rx(void *Context, struct htc_packet *pPacket);
316 static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint);
318 static void ar6000_tx_complete(void *Context, struct htc_packet_queue *pPackets);
320 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket);
322 #ifdef ATH_AR6K_11N_SUPPORT
323 static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num);
325 static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf);
326 //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf);
328 static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length);
330 static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count);
332 static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar);
335 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
336 struct bin_attribute *bin_attr,
337 char *buf, loff_t pos, size_t count);
340 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
341 struct bin_attribute *bin_attr,
342 char *buf, loff_t pos, size_t count);
345 ar6000_sysfs_bmi_init(struct ar6_softc *ar);
347 /* HCI PAL callback function declarations */
348 int ar6k_setup_hci_pal(struct ar6_softc *ar);
349 void ar6k_cleanup_hci_pal(struct ar6_softc *ar);
352 ar6000_sysfs_bmi_deinit(struct ar6_softc *ar);
355 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode);
361 struct net_device *ar6000_devices[MAX_AR6000];
362 static int is_netdev_registered;
363 extern struct iw_handler_def ath_iw_handler_def;
364 DECLARE_WAIT_QUEUE_HEAD(arEvent);
365 static void ar6000_cookie_init(struct ar6_softc *ar);
366 static void ar6000_cookie_cleanup(struct ar6_softc *ar);
367 static void ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie);
368 static struct ar_cookie *ar6000_alloc_cookie(struct ar6_softc *ar);
371 static int ar6000_reinstall_keys(struct ar6_softc *ar,u8 key_op_ctrl);
374 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
375 struct net_device *arApNetDev;
376 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
378 static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM];
380 #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \
381 (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \
382 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0))
385 static struct net_device_ops ar6000_netdev_ops = {
387 .ndo_open = ar6000_open,
388 .ndo_stop = ar6000_close,
389 .ndo_get_stats = ar6000_get_stats,
390 .ndo_do_ioctl = ar6000_ioctl,
391 .ndo_start_xmit = ar6000_data_tx,
392 .ndo_set_multicast_list = ar6000_set_multicast_list,
395 /* Debug log support */
398 * Flag to govern whether the debug logs should be parsed in the kernel
399 * or reported to the application.
401 #define REPORT_DEBUG_LOGS_TO_APP
404 ar6000_set_host_app_area(struct ar6_softc *ar)
407 struct host_app_area_s host_app_area;
409 /* Fetch the address of the host_app_area_s instance in the host interest area */
410 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest));
411 if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != 0) {
414 address = TARG_VTOP(ar->arTargetType, data);
415 host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION;
416 if (ar6000_WriteDataDiag(ar->arHifDevice, address,
417 (u8 *)&host_app_area,
418 sizeof(struct host_app_area_s)) != 0)
426 u32 dbglog_get_debug_hdr_ptr(struct ar6_softc *ar)
432 address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr));
433 if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address,
434 (u8 *)¶m, 4)) != 0)
443 * The dbglog module has been initialized. Its ok to access the relevant
444 * data stuctures over the diagnostic window.
447 ar6000_dbglog_init_done(struct ar6_softc *ar)
449 ar->dbglog_init_done = true;
452 u32 dbglog_get_debug_fragment(s8 *datap, u32 len, u32 limit)
461 buffer = (s32 *)datap;
462 length = (limit >> 2);
467 while (count < length) {
468 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
469 fraglen = (count << 2);
470 count += numargs + 1;
478 dbglog_parse_debug_logs(s8 *datap, u32 len)
489 buffer = (s32 *)datap;
491 while (count < length) {
492 debugid = DBGLOG_GET_DBGID(buffer[count]);
493 moduleid = DBGLOG_GET_MODULEID(buffer[count]);
494 numargs = DBGLOG_GET_NUMARGS(buffer[count]);
495 timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]);
498 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp));
502 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid,
503 timestamp, buffer[count+1]));
507 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid,
508 timestamp, buffer[count+1], buffer[count+2]));
512 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs));
514 count += numargs + 1;
519 ar6000_dbglog_get_debug_logs(struct ar6_softc *ar)
521 u32 data[8]; /* Should be able to accomodate struct dbglog_buf_s */
528 if (!ar->dbglog_init_done) return A_ERROR;
531 AR6000_SPIN_LOCK(&ar->arLock, 0);
533 if (ar->dbgLogFetchInProgress) {
534 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
538 /* block out others */
539 ar->dbgLogFetchInProgress = true;
541 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
543 debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar);
544 printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr);
546 /* Get the contents of the ring buffer */
548 address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr);
549 length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */;
550 A_MEMZERO(data, sizeof(data));
551 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)data, length);
552 address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */);
554 dropped = data[1]; /* dropped */
555 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
556 A_MEMZERO(data, sizeof(data));
557 ar6000_ReadDataDiag(ar->arHifDevice, address, (u8 *)&data, length);
560 address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/);
561 length = data[3]; /* length */
562 if ((length) && (length <= data[2] /* bufsize*/)) {
563 /* Rewind the index if it is about to overrun the buffer */
564 if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) {
567 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
568 (u8 *)&ar->log_buffer[ar->log_cnt], length))
572 ar6000_dbglog_event(ar, dropped, (s8 *)&ar->log_buffer[ar->log_cnt], length);
573 ar->log_cnt += length;
575 AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n",
579 address = TARG_VTOP(ar->arTargetType, data[0] /* next */);
580 length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */;
581 A_MEMZERO(data, sizeof(data));
582 if(0 != ar6000_ReadDataDiag(ar->arHifDevice, address,
583 (u8 *)&data, length))
588 } while (address != firstbuf);
591 ar->dbgLogFetchInProgress = false;
597 ar6000_dbglog_event(struct ar6_softc *ar, u32 dropped,
598 s8 *buffer, u32 length)
600 #ifdef REPORT_DEBUG_LOGS_TO_APP
601 #define MAX_WIRELESS_EVENT_SIZE 252
603 * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages.
604 * There seems to be a limitation on the length of message that could be
605 * transmitted to the user app via this mechanism.
610 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
611 MAX_WIRELESS_EVENT_SIZE);
613 ar6000_send_event_to_app(ar, WMIX_DBGLOG_EVENTID, (u8 *)&buffer[sent], send);
615 send = dbglog_get_debug_fragment(&buffer[sent], length - sent,
616 MAX_WIRELESS_EVENT_SIZE);
619 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n",
622 /* Interpret the debug logs */
623 dbglog_parse_debug_logs((s8 *)buffer, length);
624 #endif /* REPORT_DEBUG_LOGS_TO_APP */
629 ar6000_init_module(void)
631 static int probed = 0;
633 OSDRV_CALLBACKS osdrvCallbacks;
635 a_module_debug_support_init();
638 /* check for debug mask overrides */
640 ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc);
643 ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi);
646 ATH_DEBUG_SET_DEBUG_MASK(hif,debughif);
648 if (debugdriver != 0) {
649 ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver);
654 A_REGISTER_MODULE_DEBUG_INFO(driver);
656 A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks));
657 osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev;
658 osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev;
660 osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev;
661 osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev;
662 osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev;
668 android_module_init(&osdrvCallbacks);
672 /* Set the debug flags if specified at load time */
675 g_dbg_flags = debugflags;
684 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
685 memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD));
686 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
688 #ifdef CONFIG_HOST_GPIO_SUPPORT
690 #endif /* CONFIG_HOST_GPIO_SUPPORT */
692 status = HIFInit(&osdrvCallbacks);
700 ar6000_cleanup_module(void)
703 struct net_device *ar6000_netdev;
705 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
706 /* Delete the Adaptive Power Control timer */
707 if (timer_pending(&aptcTimer)) {
708 del_timer_sync(&aptcTimer);
710 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
712 for (i=0; i < MAX_AR6000; i++) {
713 if (ar6000_devices[i] != NULL) {
714 ar6000_netdev = ar6000_devices[i];
715 ar6000_devices[i] = NULL;
716 ar6000_destroy(ar6000_netdev, 1);
720 HIFShutDownDevice(NULL);
722 a_module_debug_support_cleanup();
727 android_module_exit();
730 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n"));
733 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
735 aptcTimerHandler(unsigned long arg)
739 struct ar6_softc *ar;
742 ar = (struct ar6_softc *)arg;
743 A_ASSERT(ar != NULL);
744 A_ASSERT(!timer_pending(&aptcTimer));
746 AR6000_SPIN_LOCK(&ar->arLock, 0);
748 /* Get the number of bytes transferred */
749 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
750 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
752 /* Calculate and decide based on throughput thresholds */
753 throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */
754 if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) {
755 /* Enable Sleep and delete the timer */
756 A_ASSERT(ar->arWmiReady == true);
757 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
758 status = wmi_powermode_cmd(ar->arWmi, REC_POWER);
759 AR6000_SPIN_LOCK(&ar->arLock, 0);
760 A_ASSERT(status == 0);
761 aptcTR.timerScheduled = false;
763 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
766 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
768 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
770 #ifdef ATH_AR6K_11N_SUPPORT
772 ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num)
777 if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) {
778 A_NETBUF_ENQUEUE(q, osbuf);
786 A_PRINTF("%s(), allocation of netbuf failed", __func__);
791 static struct bin_attribute bmi_attr = {
792 .attr = {.name = "bmi", .mode = 0600},
793 .read = ar6000_sysfs_bmi_read,
794 .write = ar6000_sysfs_bmi_write,
798 ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj,
799 struct bin_attribute *bin_attr,
800 char *buf, loff_t pos, size_t count)
803 struct ar6_softc *ar;
804 struct hif_device_os_device_info *osDevInfo;
806 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", (u32)count));
807 for (index=0; index < MAX_AR6000; index++) {
808 ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
809 osDevInfo = &ar->osDevInfo;
810 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
815 if (index == MAX_AR6000) return 0;
817 if ((BMIRawRead(ar->arHifDevice, (u8*)buf, count, true)) != 0) {
825 ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj,
826 struct bin_attribute *bin_attr,
827 char *buf, loff_t pos, size_t count)
830 struct ar6_softc *ar;
831 struct hif_device_os_device_info *osDevInfo;
833 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", (u32)count));
834 for (index=0; index < MAX_AR6000; index++) {
835 ar = (struct ar6_softc *)ar6k_priv(ar6000_devices[index]);
836 osDevInfo = &ar->osDevInfo;
837 if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) {
842 if (index == MAX_AR6000) return 0;
844 if ((BMIRawWrite(ar->arHifDevice, (u8*)buf, count)) != 0) {
852 ar6000_sysfs_bmi_init(struct ar6_softc *ar)
856 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n"));
857 A_MEMZERO(&ar->osDevInfo, sizeof(struct hif_device_os_device_info));
859 /* Get the underlying OS device */
860 status = HIFConfigureDevice(ar->arHifDevice,
861 HIF_DEVICE_GET_OS_DEVICE,
863 sizeof(struct hif_device_os_device_info));
866 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n"));
870 /* Create a bmi entry in the sysfs filesystem */
871 if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0)
873 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n"));
881 ar6000_sysfs_bmi_deinit(struct ar6_softc *ar)
883 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n"));
885 sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr);
888 #define bmifn(fn) do { \
890 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); \
895 #ifdef INIT_MODE_DRV_ENABLED
897 #ifdef SOFTMAC_FILE_USED
898 #define AR6002_MAC_ADDRESS_OFFSET 0x0A
899 #define AR6003_MAC_ADDRESS_OFFSET 0x16
901 void calculate_crc(u32 TargetType, u8 *eeprom_data)
909 if (TargetType == TARGET_TYPE_AR6001)
912 ptr_crc = (u16 *)eeprom_data;
914 else if (TargetType == TARGET_TYPE_AR6003)
917 ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
922 ptr_crc = (u16 *)((u8 *)eeprom_data + 0x04);
929 // Recalculate new CRC
931 ptr16_eeprom = (u16 *)eeprom_data;
932 for (i = 0;i < eeprom_size; i += 2)
934 checksum = checksum ^ (*ptr16_eeprom);
937 checksum = 0xFFFF ^ checksum;
942 ar6000_softmac_update(struct ar6_softc *ar, u8 *eeprom_data, size_t size)
944 const char *source = "random generated";
945 const struct firmware *softmac_entry;
947 switch (ar->arTargetType) {
948 case TARGET_TYPE_AR6002:
949 ptr_mac = (u8 *)((u8 *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET);
951 case TARGET_TYPE_AR6003:
952 ptr_mac = (u8 *)((u8 *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET);
955 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Invalid Target Type\n"));
958 printk(KERN_DEBUG "MAC from EEPROM %pM\n", ptr_mac);
960 /* create a random MAC in case we cannot read file from system */
964 ptr_mac[3] = random32() & 0xff;
965 ptr_mac[4] = random32() & 0xff;
966 ptr_mac[5] = random32() & 0xff;
967 if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0)
969 char *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1);
971 unsigned int softmac[6];
972 memcpy(macbuf, softmac_entry->data, softmac_entry->size);
973 macbuf[softmac_entry->size] = '\0';
974 if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x",
975 &softmac[0], &softmac[1], &softmac[2],
976 &softmac[3], &softmac[4], &softmac[5])==6) {
978 for (i=0; i<6; ++i) {
979 ptr_mac[i] = softmac[i] & 0xff;
981 source = "softmac file";
985 A_RELEASE_FIRMWARE(softmac_entry);
987 printk(KERN_DEBUG "MAC from %s %pM\n", source, ptr_mac);
988 calculate_crc(ar->arTargetType, eeprom_data);
990 #endif /* SOFTMAC_FILE_USED */
993 ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, bool compressed)
996 const char *filename;
997 const struct firmware *fw_entry;
1002 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1003 filename = AR6003_REV1_OTP_FILE;
1004 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1005 filename = AR6003_REV2_OTP_FILE;
1007 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1012 case AR6K_FIRMWARE_FILE:
1013 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1014 filename = AR6003_REV1_FIRMWARE_FILE;
1015 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1016 filename = AR6003_REV2_FIRMWARE_FILE;
1018 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1024 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1025 filename = AR6003_REV1_EPPING_FIRMWARE_FILE;
1026 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1027 filename = AR6003_REV2_EPPING_FIRMWARE_FILE;
1029 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n",
1030 ar->arVersion.target_ver));
1036 #ifdef CONFIG_HOST_TCMD_SUPPORT
1038 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1039 filename = AR6003_REV1_TCMD_FIRMWARE_FILE;
1040 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1041 filename = AR6003_REV2_TCMD_FIRMWARE_FILE;
1043 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1049 #ifdef HTC_RAW_INTERFACE
1050 if (!eppingtest && bypasswmi) {
1051 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1052 filename = AR6003_REV1_ART_FIRMWARE_FILE;
1053 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1054 filename = AR6003_REV2_ART_FIRMWARE_FILE;
1056 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1064 case AR6K_PATCH_FILE:
1065 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1066 filename = AR6003_REV1_PATCH_FILE;
1067 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1068 filename = AR6003_REV2_PATCH_FILE;
1070 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1075 case AR6K_BOARD_DATA_FILE:
1076 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1077 filename = AR6003_REV1_BOARD_DATA_FILE;
1078 } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1079 filename = AR6003_REV2_BOARD_DATA_FILE;
1081 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver));
1087 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file));
1090 if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1092 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename));
1096 #ifdef SOFTMAC_FILE_USED
1097 if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) {
1098 ar6000_softmac_update(ar, (u8 *)fw_entry->data, fw_entry->size);
1103 fw_entry_size = fw_entry->size;
1105 /* Load extended board data for AR6003 */
1106 if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) {
1107 u32 board_ext_address;
1108 u32 board_ext_data_size;
1109 u32 board_data_size;
1111 board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \
1112 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0));
1114 board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \
1115 (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0));
1117 /* Determine where in Target RAM to write Board Data */
1118 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (u8 *)&board_ext_address, 4));
1119 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address));
1121 /* check whether the target has allocated memory for extended board data and file contains extended board data */
1122 if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) {
1125 status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (u8 *)(fw_entry->data + board_data_size), board_ext_data_size);
1128 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1129 A_RELEASE_FIRMWARE(fw_entry);
1133 /* Record the fact that extended board Data IS initialized */
1135 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_initialized), (u8 *)¶m, 4));
1137 fw_entry_size = board_data_size;
1141 status = BMIFastDownload(ar->arHifDevice, address, (u8 *)fw_entry->data, fw_entry_size);
1143 status = BMIWriteMemory(ar->arHifDevice, address, (u8 *)fw_entry->data, fw_entry_size);
1147 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__));
1148 A_RELEASE_FIRMWARE(fw_entry);
1151 A_RELEASE_FIRMWARE(fw_entry);
1154 #endif /* INIT_MODE_DRV_ENABLED */
1157 ar6000_update_bdaddr(struct ar6_softc *ar)
1160 if (setupbtdev != 0) {
1163 if (BMIReadMemory(ar->arHifDevice,
1164 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4) != 0)
1166 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n"));
1170 if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (u8 *)ar->bdaddr, 6) != 0)
1172 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n"));
1175 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0],
1176 ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3],
1177 ar->bdaddr[4], ar->bdaddr[5]));
1184 ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode)
1186 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n"));
1188 if (mode == WLAN_INIT_MODE_UDEV) {
1190 const struct firmware *fw_entry;
1192 /* Get config using udev through a script in user space */
1193 sprintf(version, "%2.2x", ar->arVersion.target_ver);
1194 if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0)
1196 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version));
1200 A_RELEASE_FIRMWARE(fw_entry);
1201 #ifdef INIT_MODE_DRV_ENABLED
1203 /* The config is contained within the driver itself */
1205 u32 param, options, sleep, address;
1207 /* Temporarily disable system sleep */
1208 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1209 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1211 param |= AR6K_OPTION_SLEEP_DISABLE;
1212 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1214 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1215 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1217 param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1);
1218 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1219 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep));
1221 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1222 /* Program analog PLL register */
1223 bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001));
1224 /* Run at 80/88MHz by default */
1225 param = CPU_CLOCK_STANDARD_SET(1);
1227 /* Run at 40/44MHz by default */
1228 param = CPU_CLOCK_STANDARD_SET(0);
1230 address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS;
1231 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1234 if (ar->arTargetType == TARGET_TYPE_AR6002) {
1235 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1238 /* LPO_CAL.ENABLE = 1 if no external clk is detected */
1240 address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS;
1241 param = LPO_CAL_ENABLE_SET(1);
1242 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1245 /* Venus2.0: Lower SDIO pad drive strength,
1246 * temporary WAR to avoid SDIO CRC error */
1247 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1248 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n"));
1250 address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS;
1251 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1253 address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS;
1254 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1256 address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS;
1257 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1259 address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS;
1260 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1263 #ifdef FORCE_INTERNAL_CLOCK
1264 /* Ignore external clock, if any, and force use of internal clock */
1265 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1266 /* hi_ext_clk_detected = 0 */
1268 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (u8 *)¶m, 4));
1270 /* CLOCK_CONTROL &= ~LF_CLK32 */
1271 address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS;
1272 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1273 param &= (~CLOCK_CONTROL_LF_CLK32_SET(1));
1274 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1276 #endif /* FORCE_INTERNAL_CLOCK */
1278 /* Transfer Board Data from Target EEPROM to Target RAM */
1279 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1280 /* Determine where in Target RAM to write Board Data */
1281 bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (u8 *)&address, 4));
1282 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address));
1284 /* Write EEPROM data to Target RAM */
1285 if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, false)) != 0) {
1289 /* Record the fact that Board Data IS initialized */
1291 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (u8 *)¶m, 4));
1293 /* Transfer One time Programmable data */
1294 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1295 status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, true);
1297 /* Execute the OTP code */
1299 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1300 bmifn(BMIExecute(ar->arHifDevice, address, ¶m));
1301 } else if (status != A_ENOENT) {
1305 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType));
1309 /* Download Target firmware */
1310 AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1311 if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, true)) != 0) {
1315 /* Set starting address for firmware */
1316 AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver);
1317 bmifn(BMISetAppStart(ar->arHifDevice, address));
1319 /* Apply the patches */
1320 AR6K_PATCH_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver);
1321 if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, false)) != 0) {
1326 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), (u8 *)¶m, 4));
1328 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1329 if (ar->arVersion.target_ver == AR6003_REV1_VERSION) {
1330 /* Reserve 5.5K of RAM */
1332 } else { /* AR6003_REV2_VERSION */
1333 /* Reserve 6.5K of RAM */
1336 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_end_RAM_reserve_sz), (u8 *)¶m, 4));
1339 /* Restore system sleep */
1340 address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
1341 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep));
1343 address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS;
1344 param = options | 0x20;
1345 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1347 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1348 /* Configure GPIO AR6003 UART */
1349 #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN
1350 #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8
1352 param = CONFIG_AR600x_DEBUG_UART_TX_PIN;
1353 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (u8 *)¶m, 4));
1355 #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23)
1357 address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS;
1358 bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m));
1359 param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1);
1360 bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param));
1364 /* Configure GPIO for BT Reset */
1365 #ifdef ATH6KL_CONFIG_GPIO_BT_RESET
1366 #define CONFIG_AR600x_BT_RESET_PIN 0x16
1367 param = CONFIG_AR600x_BT_RESET_PIN;
1368 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (u8 *)¶m, 4));
1369 #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */
1371 /* Configure UART flow control polarity */
1372 #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY
1373 #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0
1376 #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1)
1377 if (ar->arVersion.target_ver == AR6003_REV2_VERSION) {
1378 param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2);
1379 bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (u8 *)¶m, 4));
1381 #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */
1384 #ifdef HTC_RAW_INTERFACE
1385 if (!eppingtest && bypasswmi) {
1386 /* Don't run BMIDone for ART mode and force resetok=0 */
1390 #endif /* HTC_RAW_INTERFACE */
1392 #endif /* INIT_MODE_DRV_ENABLED */
1399 ar6000_configure_target(struct ar6_softc *ar)
1402 if (enableuartprint) {
1404 if (BMIWriteMemory(ar->arHifDevice,
1405 HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable),
1409 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n"));
1412 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n"));
1415 /* Tell target which HTC version it is used*/
1416 param = HTC_PROTOCOL_VERSION;
1417 if (BMIWriteMemory(ar->arHifDevice,
1418 HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest),
1422 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n"));
1426 #ifdef CONFIG_HOST_TCMD_SUPPORT
1428 ar->arTargetMode = AR6000_TCMD_MODE;
1430 ar->arTargetMode = AR6000_WLAN_MODE;
1433 if (enabletimerwar) {
1436 if (BMIReadMemory(ar->arHifDevice,
1437 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1441 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n"));
1445 param |= HI_OPTION_TIMER_WAR;
1447 if (BMIWriteMemory(ar->arHifDevice,
1448 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1452 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n"));
1455 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n"));
1458 /* set the firmware mode to STA/IBSS/AP */
1462 if (BMIReadMemory(ar->arHifDevice,
1463 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1467 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n"));
1471 param |= (fwmode << HI_OPTION_FW_MODE_SHIFT);
1473 if (BMIWriteMemory(ar->arHifDevice,
1474 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1478 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n"));
1481 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1484 #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS
1488 if (BMIReadMemory(ar->arHifDevice,
1489 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1493 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n"));
1497 param |= HI_OPTION_DISABLE_DBGLOG;
1499 if (BMIWriteMemory(ar->arHifDevice,
1500 HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag),
1504 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n"));
1507 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n"));
1509 #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */
1512 * Hardcode the address use for the extended board data
1513 * Ideally this should be pre-allocate by the OS at boot time
1514 * But since it is a new feature and board data is loaded
1515 * at init time, we have to workaround this from host.
1516 * It is difficult to patch the firmware boot code,
1517 * but possible in theory.
1519 if (ar->arTargetType == TARGET_TYPE_AR6003) {
1520 param = AR6003_BOARD_EXT_DATA_ADDRESS;
1521 if (BMIWriteMemory(ar->arHifDevice,
1522 HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data),
1526 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n"));
1532 /* since BMIInit is called in the driver layer, we have to set the block
1533 * size here for the target */
1535 if (ar6000_set_htc_params(ar->arHifDevice, ar->arTargetType,
1536 mbox_yield_limit, 0)) {
1537 /* use default number of control buffers */
1541 if (setupbtdev != 0) {
1542 if (ar6000_set_hci_bridge_flags(ar->arHifDevice,
1552 init_netdev(struct net_device *dev, char *name)
1554 dev->netdev_ops = &ar6000_netdev_ops;
1555 dev->watchdog_timeo = AR6000_TX_TIMEOUT;
1556 dev->wireless_handlers = &ath_iw_handler_def;
1558 ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */
1561 * We need the OS to provide us with more headroom in order to
1562 * perform dix to 802.3, WMI header encap, and the HTC header
1564 if (processDot11Hdr) {
1565 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;
1567 dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) +
1568 sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR;
1573 strcpy(dev->name, name);
1576 #ifdef CONFIG_CHECKSUM_OFFLOAD
1578 dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/
1585 static int __ath6kl_init_netdev(struct net_device *dev)
1590 r = ar6000_init(dev);
1594 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n"));
1601 #ifdef HTC_RAW_INTERFACE
1602 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1604 if (!eppingtest && bypasswmi)
1607 return __ath6kl_init_netdev(dev);
1610 static int ath6kl_init_netdev_wmi(struct net_device *dev)
1612 return __ath6kl_init_netdev(dev);
1616 static int ath6kl_init_netdev(struct ar6_softc *ar)
1620 r = ar6000_sysfs_bmi_get_config(ar, wlaninitmode);
1622 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
1624 "ar6000_sysfs_bmi_get_config failed\n"));
1628 return ath6kl_init_netdev_wmi(ar->arNetDev);
1632 * HTC Event handlers
1635 ar6000_avail_ev(void *context, void *hif_handle)
1638 struct net_device *dev;
1640 struct ar6_softc *ar;
1641 int device_index = 0;
1642 struct htc_init_info htcInfo;
1643 #ifdef ATH6K_CONFIG_CFG80211
1644 struct wireless_dev *wdev;
1645 #endif /* ATH6K_CONFIG_CFG80211 */
1647 struct hif_device_os_device_info osDevInfo;
1649 memset(&osDevInfo, 0, sizeof(osDevInfo));
1650 if (HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE,
1651 &osDevInfo, sizeof(osDevInfo))) {
1652 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Failed to get OS device instance\n", __func__));
1656 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n"));
1658 for (i=0; i < MAX_AR6000; i++) {
1659 if (ar6000_devices[i] == NULL) {
1664 if (i == MAX_AR6000) {
1665 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n"));
1669 /* Save this. It gives a bit better readability especially since */
1670 /* we use another local "i" variable below. */
1673 #ifdef ATH6K_CONFIG_CFG80211
1674 wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice);
1676 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__));
1679 ar_netif = wdev_priv(wdev);
1681 dev = alloc_etherdev(sizeof(struct ar6_softc));
1683 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n"));
1687 ar_netif = ar6k_priv(dev);
1688 #endif /* ATH6K_CONFIG_CFG80211 */
1690 if (ar_netif == NULL) {
1691 AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__));
1695 A_MEMZERO(ar_netif, sizeof(struct ar6_softc));
1696 ar = (struct ar6_softc *)ar_netif;
1698 #ifdef ATH6K_CONFIG_CFG80211
1700 wdev->iftype = NL80211_IFTYPE_STATION;
1702 dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1);
1704 printk(KERN_CRIT "AR6K: no memory for network device instance\n");
1705 ar6k_cfg80211_deinit(ar);
1709 dev->ieee80211_ptr = wdev;
1710 SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy));
1712 ar->arNetworkType = INFRA_NETWORK;
1713 ar->smeState = SME_DISCONNECTED;
1714 #endif /* ATH6K_CONFIG_CFG80211 */
1716 init_netdev(dev, ifname);
1718 #ifdef SET_NETDEV_DEV
1720 SET_NETDEV_DEV(dev, osDevInfo.pOSDevice);
1725 ar->arHifDevice = hif_handle;
1726 ar->arWlanState = WLAN_ENABLED;
1727 ar->arDeviceIndex = device_index;
1729 ar->arWlanPowerState = WLAN_POWER_STATE_ON;
1730 ar->arWlanOff = false; /* We are in ON state */
1732 ar->arWowState = WLAN_WOW_STATE_NONE;
1733 ar->arBTOff = true; /* BT chip assumed to be OFF */
1734 ar->arBTSharing = WLAN_CONFIG_BT_SHARING;
1735 ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF;
1736 ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND;
1737 ar->arWow2Config = WLAN_CONFIG_PM_WOW2;
1738 #endif /* CONFIG_PM */
1740 A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev);
1741 ar->arHBChallengeResp.seqNum = 0;
1742 ar->arHBChallengeResp.outstanding = false;
1743 ar->arHBChallengeResp.missCnt = 0;
1744 ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT;
1745 ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT;
1747 ar6000_init_control_info(ar);
1748 init_waitqueue_head(&arEvent);
1749 sema_init(&ar->arSem, 1);
1750 ar->bIsDestroyProgress = false;
1752 INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue);
1754 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
1755 A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar);
1756 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
1758 A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev);
1762 ar6000_sysfs_bmi_init(ar);
1765 struct bmi_target_info targ_info;
1767 r = BMIGetTargetInfo(ar->arHifDevice, &targ_info);
1769 goto avail_ev_failed;
1771 ar->arVersion.target_ver = targ_info.target_ver;
1772 ar->arTargetType = targ_info.target_type;
1774 /* do any target-specific preparation that can be done through BMI */
1775 r = ar6000_prepare_target(ar->arHifDevice,
1776 targ_info.target_type,
1777 targ_info.target_ver);
1779 goto avail_ev_failed;
1783 r = ar6000_configure_target(ar);
1785 goto avail_ev_failed;
1787 A_MEMZERO(&htcInfo,sizeof(htcInfo));
1788 htcInfo.pContext = ar;
1789 htcInfo.TargetFailure = ar6000_target_failure;
1791 ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo);
1793 if (!ar->arHtcTarget) {
1795 goto avail_ev_failed;
1798 spin_lock_init(&ar->arLock);
1801 ar->arWapiEnable = 0;
1805 #ifdef CONFIG_CHECKSUM_OFFLOAD
1807 /*if external frame work is also needed, change and use an extended rxMetaVerion*/
1808 ar->rxMetaVersion=WMI_META_VERSION_2;
1812 #ifdef ATH_AR6K_11N_SUPPORT
1813 ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs);
1814 if (!ar->aggr_cntxt) {
1815 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__));
1817 goto avail_ev_failed;
1820 aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack);
1823 HIFClaimDevice(ar->arHifDevice, ar);
1825 /* We only register the device in the global list if we succeed. */
1826 /* If the device is in the global list, it will be destroyed */
1827 /* when the module is unloaded. */
1828 ar6000_devices[device_index] = dev;
1830 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode));
1831 if ((wlaninitmode == WLAN_INIT_MODE_UDEV) ||
1832 (wlaninitmode == WLAN_INIT_MODE_DRV)) {
1833 r = ath6kl_init_netdev(ar);
1835 goto avail_ev_failed;
1838 /* This runs the init function if registered */
1839 r = register_netdev(dev);
1841 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n"));
1842 ar6000_destroy(dev, 0);
1846 is_netdev_registered = 1;
1848 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
1850 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
1851 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n",
1852 dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index,
1853 (unsigned long)ar));
1857 ar6000_sysfs_bmi_deinit(ar);
1862 static void ar6000_target_failure(void *Instance, int Status)
1864 struct ar6_softc *ar = (struct ar6_softc *)Instance;
1865 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
1866 static bool sip = false;
1870 printk(KERN_ERR "ar6000_target_failure: target asserted \n");
1872 if (timer_pending(&ar->arHBChallengeResp.timer)) {
1873 A_UNTIMEOUT(&ar->arHBChallengeResp.timer);
1876 /* try dumping target assertion information (if any) */
1877 ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType);
1880 * Fetch the logs from the target via the diagnostic
1883 ar6000_dbglog_get_debug_logs(ar);
1885 /* Report the error only once */
1888 errEvent.errorVal = WMI_TARGET_COM_ERR |
1889 WMI_TARGET_FATAL_ERR;
1890 ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID,
1892 sizeof(WMI_TARGET_ERROR_REPORT_EVENT));
1898 ar6000_unavail_ev(void *context, void *hif_handle)
1900 struct ar6_softc *ar = (struct ar6_softc *)context;
1901 /* NULL out it's entry in the global list */
1902 ar6000_devices[ar->arDeviceIndex] = NULL;
1903 ar6000_destroy(ar->arNetDev, 1);
1909 ar6000_restart_endpoint(struct net_device *dev)
1912 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1916 if ( (status=ar6000_configure_target(ar))!= 0)
1918 if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != 0)
1920 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n"));
1924 status = (ar6000_init(dev)==0) ? 0 : A_ERROR;
1930 if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) {
1931 ar6000_connect_to_ap(ar);
1939 ar6000_devices[ar->arDeviceIndex] = NULL;
1940 ar6000_destroy(ar->arNetDev, 1);
1944 ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs)
1946 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
1948 /* Stop the transmit queues */
1949 netif_stop_queue(dev);
1951 /* Disable the target and the interrupts associated with it */
1952 if (ar->arWmiReady == true)
1956 bool disconnectIssued;
1958 disconnectIssued = (ar->arConnected) || (ar->arConnectPending);
1959 ar6000_disconnect(ar);
1961 ar6000_init_profile_info(ar);
1964 A_UNTIMEOUT(&ar->disconnect_timer);
1967 ar6000_dbglog_get_debug_logs(ar);
1970 ar->arWmiReady = false;
1971 wmi_shutdown(ar->arWmi);
1972 ar->arWmiEnabled = false;
1975 * After wmi_shudown all WMI events will be dropped.
1976 * We need to cleanup the buffers allocated in AP mode
1977 * and give disconnect notification to stack, which usually
1978 * happens in the disconnect_event.
1979 * Simulate the disconnect_event by calling the function directly.
1980 * Sometimes disconnect_event will be received when the debug logs
1983 if (disconnectIssued) {
1984 if(ar->arNetworkType & AP_NETWORK) {
1985 ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0);
1987 ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0);
1991 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
1992 ar->user_key_ctrl = 0;
1996 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__));
2000 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI not ready 0x%lx 0x%lx\n",
2001 __func__, (unsigned long) ar, (unsigned long) ar->arWmi));
2003 /* Shut down WMI if we have started it */
2004 if(ar->arWmiEnabled == true)
2006 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__));
2007 wmi_shutdown(ar->arWmi);
2008 ar->arWmiEnabled = false;
2013 if (ar->arHtcTarget != NULL) {
2014 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2015 if (NULL != ar6kHciTransCallbacks.cleanupTransport) {
2016 ar6kHciTransCallbacks.cleanupTransport(NULL);
2019 // FIXME: workaround to reset BT's UART baud rate to default
2020 if (NULL != ar->exitCallback) {
2021 struct ar3k_config_info ar3kconfig;
2024 A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig));
2025 ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig);
2026 status = ar->exitCallback(&ar3kconfig);
2028 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n"));
2033 ar6000_cleanup_hci(ar);
2035 #ifdef EXPORT_HCI_PAL_INTERFACE
2036 if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.cleanupTransport)) {
2037 ar6kHciPalCallbacks_g.cleanupTransport(ar);
2040 /* cleanup hci pal driver data structures */
2042 ar6k_cleanup_hci_pal(ar);
2044 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n"));
2046 HTCStop(ar->arHtcTarget);
2050 /* try to reset the device if we can
2051 * The driver may have been configure NOT to reset the target during
2052 * a debug session */
2053 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Attempting to reset target on instance destroy.... \n"));
2054 if (ar->arHifDevice != NULL) {
2055 bool coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? true: false;
2056 ar6000_reset_device(ar->arHifDevice, ar->arTargetType, true, coldReset);
2059 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n"));
2061 /* Done with cookies */
2062 ar6000_cookie_cleanup(ar);
2064 /* cleanup any allocated AMSDU buffers */
2065 ar6000_cleanup_amsdu_rxbufs(ar);
2068 * We need to differentiate between the surprise and planned removal of the
2069 * device because of the following consideration:
2070 * - In case of surprise removal, the hcd already frees up the pending
2071 * for the device and hence there is no need to unregister the function
2072 * driver inorder to get these requests. For planned removal, the function
2073 * driver has to explictly unregister itself to have the hcd return all the
2074 * pending requests before the data structures for the devices are freed up.
2075 * Note that as per the current implementation, the function driver will
2076 * end up releasing all the devices since there is no API to selectively
2077 * release a particular device.
2078 * - Certain commands issued to the target can be skipped for surprise
2079 * removal since they will anyway not go through.
2082 ar6000_destroy(struct net_device *dev, unsigned int unregister)
2084 struct ar6_softc *ar;
2086 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n"));
2088 if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL))
2090 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__));
2094 ar->bIsDestroyProgress = true;
2096 if (down_interruptible(&ar->arSem)) {
2097 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__));
2101 if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) {
2102 /* only stop endpoint if we are not stop it in suspend_ev */
2103 ar6000_stop_endpoint(dev, false, true);
2105 /* clear up the platform power state before rmmod */
2106 plat_setup_power(1,0);
2109 ar->arWlanState = WLAN_DISABLED;
2110 if (ar->arHtcTarget != NULL) {
2112 HTCDestroy(ar->arHtcTarget);
2114 if (ar->arHifDevice != NULL) {
2115 /*release the device so we do not get called back on remove incase we
2116 * we're explicity destroyed by module unload */
2117 HIFReleaseDevice(ar->arHifDevice);
2118 HIFShutDownDevice(ar->arHifDevice);
2120 #ifdef ATH_AR6K_11N_SUPPORT
2121 aggr_module_destroy(ar->aggr_cntxt);
2124 /* Done with cookies */
2125 ar6000_cookie_cleanup(ar);
2127 /* cleanup any allocated AMSDU buffers */
2128 ar6000_cleanup_amsdu_rxbufs(ar);
2130 ar6000_sysfs_bmi_deinit(ar);
2135 /* Clear the tx counters */
2136 memset(tx_attempt, 0, sizeof(tx_attempt));
2137 memset(tx_post, 0, sizeof(tx_post));
2138 memset(tx_complete, 0, sizeof(tx_complete));
2140 #ifdef HTC_RAW_INTERFACE
2142 kfree(ar->arRawHtc);
2143 ar->arRawHtc = NULL;
2146 /* Free up the device data structure */
2147 if (unregister && is_netdev_registered) {
2148 unregister_netdev(dev);
2149 is_netdev_registered = 0;
2153 #ifdef ATH6K_CONFIG_CFG80211
2154 ar6k_cfg80211_deinit(ar);
2155 #endif /* ATH6K_CONFIG_CFG80211 */
2157 #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT
2158 ar6000_remove_ap_interface();
2159 #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
2161 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n"));
2164 static void disconnect_timer_handler(unsigned long ptr)
2166 struct net_device *dev = (struct net_device *)ptr;
2167 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2169 A_UNTIMEOUT(&ar->disconnect_timer);
2171 ar6000_init_profile_info(ar);
2172 ar6000_disconnect(ar);
2175 static void ar6000_detect_error(unsigned long ptr)
2177 struct net_device *dev = (struct net_device *)ptr;
2178 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2179 WMI_TARGET_ERROR_REPORT_EVENT errEvent;
2181 AR6000_SPIN_LOCK(&ar->arLock, 0);
2183 if (ar->arHBChallengeResp.outstanding) {
2184 ar->arHBChallengeResp.missCnt++;
2186 ar->arHBChallengeResp.missCnt = 0;
2189 if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) {
2190 /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */
2191 ar->arHBChallengeResp.missCnt = 0;
2192 ar->arHBChallengeResp.seqNum = 0;
2193 errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR;
2194 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2195 ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID,
2197 sizeof(WMI_TARGET_ERROR_REPORT_EVENT));
2201 /* Generate the sequence number for the next challenge */
2202 ar->arHBChallengeResp.seqNum++;
2203 ar->arHBChallengeResp.outstanding = true;
2205 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
2207 /* Send the challenge on the control channel */
2208 if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != 0) {
2209 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n"));
2213 /* Reschedule the timer for the next challenge */
2214 A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0);
2217 void ar6000_init_profile_info(struct ar6_softc *ar)
2220 A_MEMZERO(ar->arSsid, sizeof(ar->arSsid));
2223 case HI_OPTION_FW_MODE_IBSS:
2224 ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK;
2226 case HI_OPTION_FW_MODE_BSS_STA:
2227 ar->arNetworkType = ar->arNextMode = INFRA_NETWORK;
2229 case HI_OPTION_FW_MODE_AP:
2230 ar->arNetworkType = ar->arNextMode = AP_NETWORK;
2234 ar->arDot11AuthMode = OPEN_AUTH;
2235 ar->arAuthMode = NONE_AUTH;
2236 ar->arPairwiseCrypto = NONE_CRYPT;
2237 ar->arPairwiseCryptoLen = 0;
2238 ar->arGroupCrypto = NONE_CRYPT;
2239 ar->arGroupCryptoLen = 0;
2240 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2241 A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid));
2242 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
2243 ar->arBssChannel = 0;
2247 ar6000_init_control_info(struct ar6_softc *ar)
2249 ar->arWmiEnabled = false;
2250 ar6000_init_profile_info(ar);
2251 ar->arDefTxKeyIndex = 0;
2252 A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList));
2253 ar->arChannelHint = 0;
2254 ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL;
2255 ar->arListenIntervalB = 0;
2256 ar->arVersion.host_ver = AR6K_SW_VERSION;
2259 ar->arTxPwrSet = false;
2261 ar->arBeaconInterval = 0;
2263 ar->arMaxRetries = 0;
2264 ar->arWmmEnabled = true;
2266 ar->scan_triggered = 0;
2267 A_MEMZERO(&ar->scParams, sizeof(ar->scParams));
2268 ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT;
2269 ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS;
2271 /* Initialize the AP mode state info */
2274 A_MEMZERO((u8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t));
2276 /* init the Mutexes */
2277 A_MUTEX_INIT(&ar->mcastpsqLock);
2279 /* Init the PS queues */
2280 for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) {
2281 A_MUTEX_INIT(&ar->sta_list[ctr].psqLock);
2282 A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq);
2285 ar->ap_profile_flag = 0;
2286 A_NETBUF_QUEUE_INIT(&ar->mcastpsq);
2288 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3);
2289 ar->ap_wmode = DEF_AP_WMODE_G;
2290 ar->ap_dtim_period = DEF_AP_DTIM;
2291 ar->ap_beacon_interval = DEF_BEACON_INTERVAL;
2296 ar6000_open(struct net_device *dev)
2298 unsigned long flags;
2299 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2301 spin_lock_irqsave(&ar->arLock, flags);
2303 #ifdef ATH6K_CONFIG_CFG80211
2304 if(ar->arWlanState == WLAN_DISABLED) {
2305 ar->arWlanState = WLAN_ENABLED;
2307 #endif /* ATH6K_CONFIG_CFG80211 */
2309 if( ar->arConnected || bypasswmi) {
2310 netif_carrier_on(dev);
2311 /* Wake up the queues */
2312 netif_wake_queue(dev);
2315 netif_carrier_off(dev);
2317 spin_unlock_irqrestore(&ar->arLock, flags);
2322 ar6000_close(struct net_device *dev)
2324 #ifdef ATH6K_CONFIG_CFG80211
2325 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2326 #endif /* ATH6K_CONFIG_CFG80211 */
2327 netif_stop_queue(dev);
2329 #ifdef ATH6K_CONFIG_CFG80211
2330 ar6000_disconnect(ar);
2332 if(ar->arWmiReady == true) {
2333 if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0,
2334 0, 0, 0, 0, 0, 0, 0, 0) != 0) {
2337 ar->arWlanState = WLAN_DISABLED;
2339 ar6k_cfg80211_scanComplete_event(ar, A_ECANCELED);
2340 #endif /* ATH6K_CONFIG_CFG80211 */
2345 /* connect to a service */
2346 static int ar6000_connectservice(struct ar6_softc *ar,
2347 struct htc_service_connect_req *pConnect,
2351 struct htc_service_connect_resp response;
2355 A_MEMZERO(&response,sizeof(response));
2357 status = HTCConnectService(ar->arHtcTarget,
2362 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n",
2366 switch (pConnect->ServiceID) {
2367 case WMI_CONTROL_SVC :
2368 if (ar->arWmiEnabled) {
2369 /* set control endpoint for WMI use */
2370 wmi_set_control_ep(ar->arWmi, response.Endpoint);
2372 /* save EP for fast lookup */
2373 ar->arControlEp = response.Endpoint;
2375 case WMI_DATA_BE_SVC :
2376 arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint);
2378 case WMI_DATA_BK_SVC :
2379 arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint);
2381 case WMI_DATA_VI_SVC :
2382 arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint);
2384 case WMI_DATA_VO_SVC :
2385 arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint);
2388 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID));
2398 void ar6000_TxDataCleanup(struct ar6_softc *ar)
2400 /* flush all the data (non-control) streams
2401 * we only flush packets that are tagged as data, we leave any control packets that
2402 * were in the TX queues alone */
2403 HTCFlushEndpoint(ar->arHtcTarget,
2404 arAc2EndpointID(ar, WMM_AC_BE),
2406 HTCFlushEndpoint(ar->arHtcTarget,
2407 arAc2EndpointID(ar, WMM_AC_BK),
2409 HTCFlushEndpoint(ar->arHtcTarget,
2410 arAc2EndpointID(ar, WMM_AC_VI),
2412 HTCFlushEndpoint(ar->arHtcTarget,
2413 arAc2EndpointID(ar, WMM_AC_VO),
2418 ar6000_ac2_endpoint_id ( void * devt, u8 ac)
2420 struct ar6_softc *ar = (struct ar6_softc *) devt;
2421 return(arAc2EndpointID(ar, ac));
2424 u8 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep )
2426 struct ar6_softc *ar = (struct ar6_softc *) devt;
2427 return(arEndpoint2Ac(ar, ep ));
2431 * This function applies WLAN specific configuration defined in wlan_config.h
2433 int ar6000_target_config_wlan_params(struct ar6_softc *ar)
2436 #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE)
2437 WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd;
2438 WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd;
2439 #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */
2441 #ifdef CONFIG_HOST_TCMD_SUPPORT
2442 if (ar->arTargetMode != AR6000_WLAN_MODE) {
2445 #endif /* CONFIG_HOST_TCMD_SUPPORT */
2448 * configure the device for rx dot11 header rules 0,0 are the default values
2449 * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required
2450 * if checksum offload is needed. Set RxMetaVersion to 2
2452 if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != 0) {
2453 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n"));
2457 #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE)
2458 /* Configure the type of BT collocated with WLAN */
2459 memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD));
2460 #ifdef CONFIG_AR600x_BT_QCOM
2461 sbcb_cmd.btcoexCoLocatedBTdev = 1;
2462 #elif defined(CONFIG_AR600x_BT_CSR)
2463 sbcb_cmd.btcoexCoLocatedBTdev = 2;
2464 #elif defined(CONFIG_AR600x_BT_AR3001)
2465 sbcb_cmd.btcoexCoLocatedBTdev = 3;
2467 #error Unsupported Bluetooth Type
2468 #endif /* Collocated Bluetooth Type */
2470 if ((wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd)) != 0) {
2471 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n"));
2475 /* Configure the type of BT collocated with WLAN */
2476 memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD));
2477 #ifdef CONFIG_AR600x_DUAL_ANTENNA
2478 sbfa_cmd.btcoexFeAntType = 2;
2479 #elif defined(CONFIG_AR600x_SINGLE_ANTENNA)
2480 sbfa_cmd.btcoexFeAntType = 1;
2482 #error Unsupported Front-End Antenna Configuration
2483 #endif /* AR600x Front-End Antenna Configuration */
2485 if ((wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd)) != 0) {
2486 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n"));
2489 #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */
2491 #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN
2492 if ((wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) {
2493 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power save fail event policy\n"));
2498 #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP
2499 if ((wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP)) != 0) {
2500 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set barker preamble policy\n"));
2505 if ((wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL)) != 0) {
2506 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set keep alive interval\n"));
2510 #if WLAN_CONFIG_DISABLE_11N
2512 WMI_SET_HT_CAP_CMD htCap;
2514 memset(&htCap, 0, sizeof(WMI_SET_HT_CAP_CMD));
2516 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2517 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2522 if ((wmi_set_ht_cap_cmd(ar->arWmi, &htCap)) != 0) {
2523 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set ht capabilities \n"));
2527 #endif /* WLAN_CONFIG_DISABLE_11N */
2529 #ifdef ATH6K_CONFIG_OTA_MODE
2530 if ((wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER)) != 0) {
2531 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set power mode \n"));
2536 if ((wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT)) != 0) {
2537 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set disconnect timeout \n"));
2541 #if WLAN_CONFIG_DISABLE_TX_BURSTING
2542 if ((wmi_set_wmm_txop(ar->arWmi, WMI_TXOP_DISABLED)) != 0) {
2543 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set txop bursting \n"));
2551 /* This function does one time initialization for the lifetime of the device */
2552 int ar6000_init(struct net_device *dev)
2554 struct ar6_softc *ar;
2560 if((ar = ar6k_priv(dev)) == NULL)
2565 if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) {
2567 ar6000_update_bdaddr(ar);
2569 if (enablerssicompensation) {
2570 ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType);
2571 read_rssi_compensation_param(ar);
2572 for (i=-95; i<=0; i++) {
2573 rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i);
2581 /* Do we need to finish the BMI phase */
2582 if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) &&
2583 (BMIDone(ar->arHifDevice) != 0))
2586 goto ar6000_init_done;
2592 if (ar->arVersion.host_ver != ar->arVersion.target_ver) {
2593 A_PRINTF("WARNING: Host version 0x%x does not match Target "
2595 ar->arVersion.host_ver, ar->arVersion.target_ver);
2599 /* Indicate that WMI is enabled (although not ready yet) */
2600 ar->arWmiEnabled = true;
2601 if ((ar->arWmi = wmi_init((void *) ar)) == NULL)
2603 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__));
2605 goto ar6000_init_done;
2608 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__,
2609 (unsigned long) ar->arWmi));
2613 struct htc_service_connect_req connect;
2615 /* the reason we have to wait for the target here is that the driver layer
2616 * has to init BMI in order to set the host block size,
2618 status = HTCWaitTarget(ar->arHtcTarget);
2624 A_MEMZERO(&connect,sizeof(connect));
2625 /* meta data is unused for now */
2626 connect.pMetaData = NULL;
2627 connect.MetaDataLength = 0;
2628 /* these fields are the same for all service endpoints */
2629 connect.EpCallbacks.pContext = ar;
2630 connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete;
2631 connect.EpCallbacks.EpRecv = ar6000_rx;
2632 connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill;
2633 connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full;
2634 /* set the max queue depth so that our ar6000_tx_queue_full handler gets called.
2635 * Linux has the peculiarity of not providing flow control between the
2636 * NIC and the network stack. There is no API to indicate that a TX packet
2637 * was sent which could provide some back pressure to the network stack.
2638 * Under linux you would have to wait till the network stack consumed all sk_buffs
2639 * before any back-flow kicked in. Which isn't very friendly.
2640 * So we have to manage this ourselves */
2641 connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH;
2642 connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */
2643 if (0 == connect.EpCallbacks.RecvRefillWaterMark) {
2644 connect.EpCallbacks.RecvRefillWaterMark++;
2646 /* connect to control service */
2647 connect.ServiceID = WMI_CONTROL_SVC;
2648 status = ar6000_connectservice(ar,
2655 connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING;
2656 /* limit the HTC message size on the send path, although we can receive A-MSDU frames of
2657 * 4K, we will only send ethernet-sized (802.3) frames on the send path. */
2658 connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH;
2660 /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold
2661 * mechanism for larger packets */
2662 connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE;
2663 connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf;
2665 /* for the remaining data services set the connection flag to reduce dribbling,
2666 * if configured to do so */
2667 if (reduce_credit_dribble) {
2668 connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE;
2669 /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value
2671 connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2672 connect.ConnectionFlags |=
2673 ((u16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK;
2675 /* connect to best-effort service */
2676 connect.ServiceID = WMI_DATA_BE_SVC;
2678 status = ar6000_connectservice(ar,
2685 /* connect to back-ground
2686 * map this to WMI LOW_PRI */
2687 connect.ServiceID = WMI_DATA_BK_SVC;
2688 status = ar6000_connectservice(ar,
2695 /* connect to Video service, map this to
2697 connect.ServiceID = WMI_DATA_VI_SVC;
2698 status = ar6000_connectservice(ar,
2705 /* connect to VO service, this is currently not
2706 * mapped to a WMI priority stream due to historical reasons.
2707 * WMI originally defined 3 priorities over 3 mailboxes
2708 * We can change this when WMI is reworked so that priorities are not
2709 * dependent on mailboxes */
2710 connect.ServiceID = WMI_DATA_VO_SVC;
2711 status = ar6000_connectservice(ar,
2718 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0);
2719 A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0);
2720 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0);
2721 A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0);
2723 /* setup access class priority mappings */
2724 ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */
2725 ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */
2726 ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */
2727 ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */
2729 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
2730 if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) {
2731 struct hci_transport_misc_handles hciHandles;
2733 hciHandles.netDevice = ar->arNetDev;
2734 hciHandles.hifDevice = ar->arHifDevice;
2735 hciHandles.htcHandle = ar->arHtcTarget;
2736 status = (int)(ar6kHciTransCallbacks.setupTransport(&hciHandles));
2741 status = ar6000_setup_hci(ar);
2744 #ifdef EXPORT_HCI_PAL_INTERFACE
2745 if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.setupTransport))
2746 status = ar6kHciPalCallbacks_g.setupTransport(ar);
2749 status = ar6k_setup_hci_pal(ar);
2756 goto ar6000_init_done;
2760 * give our connected endpoints some buffers
2763 ar6000_rx_refill(ar, ar->arControlEp);
2764 ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE));
2767 * We will post the receive buffers only for SPE or endpoint ping testing so we are
2768 * making it conditional on the 'bypasswmi' flag.
2771 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK));
2772 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI));
2773 ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO));
2776 /* allocate some buffers that handle larger AMSDU frames */
2777 ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS);
2779 /* setup credit distribution */
2780 ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo);
2782 /* Since cookies are used for HTC transports, they should be */
2783 /* initialized prior to enabling HTC. */
2784 ar6000_cookie_init(ar);
2787 status = HTCStart(ar->arHtcTarget);
2790 if (ar->arWmiEnabled == true) {
2791 wmi_shutdown(ar->arWmi);
2792 ar->arWmiEnabled = false;
2795 ar6000_cookie_cleanup(ar);
2797 goto ar6000_init_done;
2801 /* Wait for Wmi event to be ready */
2802 timeleft = wait_event_interruptible_timeout(arEvent,
2803 (ar->arWmiReady == true), wmitimeout * HZ);
2805 if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) {
2806 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver));
2807 #ifndef ATH6K_SKIP_ABI_VERSION_CHECK
2809 goto ar6000_init_done;
2810 #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */
2813 if(!timeleft || signal_pending(current))
2815 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n"));
2817 goto ar6000_init_done;
2820 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__));
2822 /* Communicate the wmi protocol verision to the target */
2823 if ((ar6000_set_host_app_area(ar)) != 0) {
2824 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n"));
2826 ar6000_target_config_wlan_params(ar);
2829 ar->arNumDataEndPts = 1;
2832 /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise
2833 * the data path through a raw socket is disabled */
2834 dev->dev_addr[0] = 0x00;
2835 dev->dev_addr[1] = 0x01;
2836 dev->dev_addr[2] = 0x02;
2837 dev->dev_addr[3] = 0xAA;
2838 dev->dev_addr[4] = 0xBB;
2839 dev->dev_addr[5] = 0xCC;
2851 ar6000_bitrate_rx(void *devt, s32 rateKbps)
2853 struct ar6_softc *ar = (struct ar6_softc *)devt;
2855 ar->arBitRate = rateKbps;
2860 ar6000_ratemask_rx(void *devt, u32 ratemask)
2862 struct ar6_softc *ar = (struct ar6_softc *)devt;
2864 ar->arRateMask = ratemask;
2869 ar6000_txPwr_rx(void *devt, u8 txPwr)
2871 struct ar6_softc *ar = (struct ar6_softc *)devt;
2873 ar->arTxPwr = txPwr;
2879 ar6000_channelList_rx(void *devt, s8 numChan, u16 *chanList)
2881 struct ar6_softc *ar = (struct ar6_softc *)devt;
2883 memcpy(ar->arChannelList, chanList, numChan * sizeof (u16));
2884 ar->arNumChannels = numChan;
2889 u8 ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, u32 *mapNo)
2891 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2893 ATH_MAC_HDR *macHdr;
2897 datap = A_NETBUF_DATA(skb);
2898 macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR));
2899 if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) {
2904 for (i = 0; i < ar->arNodeNum; i ++) {
2905 if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) {
2907 ar->arNodeMap[i].txPending ++;
2908 return ar->arNodeMap[i].epId;
2911 if ((eptMap == -1) && !ar->arNodeMap[i].txPending) {
2917 eptMap = ar->arNodeNum;
2919 A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM);
2922 memcpy(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN);
2924 for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) {
2925 if (!ar->arTxPending[i]) {
2926 ar->arNodeMap[eptMap].epId = i;
2929 // No free endpoint is available, start redistribution on the inuse endpoints.
2930 if (i == ENDPOINT_5) {
2931 ar->arNodeMap[eptMap].epId = ar->arNexEpId;
2933 if (ar->arNexEpId > ENDPOINT_5) {
2934 ar->arNexEpId = ENDPOINT_2;
2939 (*mapNo) = eptMap + 1;
2940 ar->arNodeMap[eptMap].txPending ++;
2942 return ar->arNodeMap[eptMap].epId;
2946 static void ar6000_dump_skb(struct sk_buff *skb)
2949 for (ch = A_NETBUF_DATA(skb);
2950 (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) +
2951 A_NETBUF_LEN(skb)); ch++)
2953 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch));
2955 AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n"));
2959 #ifdef HTC_TEST_SEND_PKTS
2960 static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb);
2964 ar6000_data_tx(struct sk_buff *skb, struct net_device *dev)
2966 #define AC_NOT_MAPPED 99
2967 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
2968 u8 ac = AC_NOT_MAPPED;
2969 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
2972 struct ar_cookie *cookie;
2973 bool checkAdHocPsMapping = false,bMoreData = false;
2974 HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG;
2975 u8 dot11Hdr = processDot11Hdr;
2977 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
2981 #endif /* CONFIG_PM */
2983 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n",
2984 (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb),
2985 A_NETBUF_LEN(skb)));
2987 /* If target is not associated */
2988 if( (!ar->arConnected && !bypasswmi)
2989 #ifdef CONFIG_HOST_TCMD_SUPPORT
2990 /* TCMD doesnt support any data, free the buf and return */
2991 || (ar->arTargetMode == AR6000_TCMD_MODE)
3000 if (ar->arWmiReady == false && bypasswmi == 0) {
3004 #ifdef BLOCK_TX_PATH_FLAG
3008 #endif /* BLOCK_TX_PATH_FLAG */
3010 /* AP mode Power save processing */
3011 /* If the dst STA is in sleep state, queue the pkt in its PS queue */
3013 if (ar->arNetworkType == AP_NETWORK) {
3014 ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
3017 /* If the dstMac is a Multicast address & atleast one of the
3018 * associated STA is in PS mode, then queue the pkt to the
3021 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
3026 for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) {
3027 if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) {
3033 /* If this transmit is not because of a Dtim Expiry q it */
3034 if (ar->DTIMExpired == false) {
3035 bool isMcastqEmpty = false;
3037 A_MUTEX_LOCK(&ar->mcastpsqLock);
3038 isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
3039 A_NETBUF_ENQUEUE(&ar->mcastpsq, skb);
3040 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
3042 /* If this is the first Mcast pkt getting queued
3043 * indicate to the target to set the BitmapControl LSB
3046 if (isMcastqEmpty) {
3047 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1);
3051 /* This transmit is because of Dtim expiry. Determine if
3052 * MoreData bit has to be set.
3054 A_MUTEX_LOCK(&ar->mcastpsqLock);
3055 if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
3058 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
3062 conn = ieee80211_find_conn(ar, datap->dstMac);
3064 if (STA_IS_PWR_SLEEP(conn)) {
3065 /* If this transmit is not because of a PsPoll q it*/
3066 if (!STA_IS_PS_POLLED(conn)) {
3067 bool isPsqEmpty = false;
3068 /* Queue the frames if the STA is sleeping */
3069 A_MUTEX_LOCK(&conn->psqLock);
3070 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
3071 A_NETBUF_ENQUEUE(&conn->psq, skb);
3072 A_MUTEX_UNLOCK(&conn->psqLock);
3074 /* If this is the first pkt getting queued
3075 * for this STA, update the PVB for this STA
3078 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1);
3083 /* This tx is because of a PsPoll. Determine if
3084 * MoreData bit has to be set
3086 A_MUTEX_LOCK(&conn->psqLock);
3087 if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3090 A_MUTEX_UNLOCK(&conn->psqLock);
3095 /* non existent STA. drop the frame */
3102 if (ar->arWmiEnabled) {
3103 #ifdef CONFIG_CHECKSUM_OFFLOAD
3106 u8 csum=skb->ip_summed;
3107 if(csumOffload && (csum==CHECKSUM_PARTIAL)){
3108 csumStart = (skb->head + skb->csum_start - skb_network_header(skb) +
3109 sizeof(ATH_LLC_SNAP_HDR));
3110 csumDest=skb->csum_offset+csumStart;
3113 if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) {
3114 struct sk_buff *newbuf;
3117 * We really should have gotten enough headroom but sometimes
3118 * we still get packets with not enough headroom. Copy the packet.
3120 len = A_NETBUF_LEN(skb);
3121 newbuf = A_NETBUF_ALLOC(len);
3122 if (newbuf == NULL) {
3125 A_NETBUF_PUT(newbuf, len);
3126 memcpy(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len);
3129 /* fall through and assemble header */
3133 if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != 0) {
3134 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n"));
3138 if (wmi_dix_2_dot3(ar->arWmi, skb) != 0) {
3139 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n"));
3143 #ifdef CONFIG_CHECKSUM_OFFLOAD
3144 if(csumOffload && (csum ==CHECKSUM_PARTIAL)){
3145 WMI_TX_META_V2 metaV2;
3146 metaV2.csumStart =csumStart;
3147 metaV2.csumDest = csumDest;
3148 metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/
3149 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,
3150 WMI_META_VERSION_2,&metaV2) != 0) {
3151 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3159 if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != 0) {
3160 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n"));
3166 if ((ar->arNetworkType == ADHOC_NETWORK) &&
3167 ar->arIbssPsEnable && ar->arConnected) {
3168 /* flag to check adhoc mapping once we take the lock below: */
3169 checkAdHocPsMapping = true;
3172 /* get the stream mapping */
3173 ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled);
3177 EPPING_HEADER *eppingHdr;
3179 eppingHdr = A_NETBUF_DATA(skb);
3181 if (IS_EPPING_PACKET(eppingHdr)) {
3182 /* the stream ID is mapped to an access class */
3183 ac = eppingHdr->StreamNo_h;
3184 /* some EPPING packets cannot be dropped no matter what access class it was
3185 * sent on. We can change the packet tag to guarantee it will not get dropped */
3186 if (IS_EPING_PACKET_NO_DROP(eppingHdr)) {
3187 htc_tag = AR6K_CONTROL_PKT_TAG;
3190 if (ac == HCI_TRANSPORT_STREAM_NUM) {
3191 /* pass this to HCI */
3192 #ifndef EXPORT_HCI_BRIDGE_INTERFACE
3193 if (!hci_test_send(ar,skb)) {
3197 /* set AC to discard this skb */
3200 /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition
3201 * of the HTC header will mis-align the start of the HTC frame, so we add some
3202 * padding which will be stripped off in the target */
3203 if (EPPING_ALIGNMENT_PAD > 0) {
3204 A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD);
3209 /* not a ping packet, drop it */
3216 /* did we succeed ? */
3217 if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) {
3218 /* cleanup and exit */
3220 AR6000_STAT_INC(ar, tx_dropped);
3221 AR6000_STAT_INC(ar, tx_aborted_errors);
3227 /* take the lock to protect driver data */
3228 AR6000_SPIN_LOCK(&ar->arLock, 0);
3232 if (checkAdHocPsMapping) {
3233 eid = ar6000_ibss_map_epid(skb, dev, &mapNo);
3235 eid = arAc2EndpointID (ar, ac);
3237 /* validate that the endpoint is connected */
3238 if (eid == 0 || eid == ENDPOINT_UNUSED ) {
3239 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid));
3242 /* allocate resource for this packet */
3243 cookie = ar6000_alloc_cookie(ar);
3245 if (cookie != NULL) {
3246 /* update counts while the lock is held */
3247 ar->arTxPending[eid]++;
3248 ar->arTotalTxDataPending++;
3253 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3255 if (cookie != NULL) {
3256 cookie->arc_bp[0] = (unsigned long)skb;
3257 cookie->arc_bp[1] = mapNo;
3258 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3266 if (debugdriver >= 3) {
3267 ar6000_dump_skb(skb);
3270 #ifdef HTC_TEST_SEND_PKTS
3271 DoHTCSendPktsTest(ar,mapNo,eid,skb);
3273 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3274 * the ar6000_tx_complete callback */
3275 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3277 /* no packet to send, cleanup */
3279 AR6000_STAT_INC(ar, tx_dropped);
3280 AR6000_STAT_INC(ar, tx_aborted_errors);
3287 ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev)
3289 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
3290 struct ar_cookie *cookie;
3291 HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED;
3294 AR6000_SPIN_LOCK(&ar->arLock, 0);
3296 /* For now we send ACL on BE endpoint: We can also have a dedicated EP */
3297 eid = arAc2EndpointID (ar, 0);
3298 /* allocate resource for this packet */
3299 cookie = ar6000_alloc_cookie(ar);
3301 if (cookie != NULL) {
3302 /* update counts while the lock is held */
3303 ar->arTxPending[eid]++;
3304 ar->arTotalTxDataPending++;
3308 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3310 if (cookie != NULL) {
3311 cookie->arc_bp[0] = (unsigned long)skb;
3312 cookie->arc_bp[1] = 0;
3313 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
3320 /* HTC interface is asynchronous, if this fails, cleanup will happen in
3321 * the ar6000_tx_complete callback */
3322 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
3324 /* no packet to send, cleanup */
3326 AR6000_STAT_INC(ar, tx_dropped);
3327 AR6000_STAT_INC(ar, tx_aborted_errors);
3333 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3335 tvsub(register struct timeval *out, register struct timeval *in)
3337 if((out->tv_usec -= in->tv_usec) < 0) {
3339 out->tv_usec += 1000000;
3341 out->tv_sec -= in->tv_sec;
3345 applyAPTCHeuristics(struct ar6_softc *ar)
3353 AR6000_SPIN_LOCK(&ar->arLock, 0);
3355 if ((enableAPTCHeuristics) && (!aptcTR.timerScheduled)) {
3356 do_gettimeofday(&ts);
3357 tvsub(&ts, &aptcTR.samplingTS);
3358 duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */
3359 numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived;
3361 if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) {
3362 /* Initialize the time stamp and byte count */
3363 aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0;
3364 do_gettimeofday(&aptcTR.samplingTS);
3366 /* Calculate and decide based on throughput thresholds */
3367 throughput = ((numbytes * 8) / duration);
3368 if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) {
3369 /* Disable Sleep and schedule a timer */
3370 A_ASSERT(ar->arWmiReady == true);
3371 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3372 status = wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER);
3373 AR6000_SPIN_LOCK(&ar->arLock, 0);
3374 A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0);
3375 aptcTR.timerScheduled = true;
3380 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3382 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3384 static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket)
3386 struct ar6_softc *ar = (struct ar6_softc *)Context;
3387 HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP;
3388 bool stopNet = false;
3389 HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket);
3396 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3397 /* don't drop special control packets */
3401 accessClass = arEndpoint2Ac(ar,Endpoint);
3402 /* for endpoint ping testing drop Best Effort and Background */
3403 if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) {
3404 action = HTC_SEND_FULL_DROP;
3407 /* keep but stop the netqueues */
3413 if (Endpoint == ar->arControlEp) {
3414 /* under normal WMI if this is getting full, then something is running rampant
3415 * the host should not be exhausting the WMI queue with too many commands
3416 * the only exception to this is during testing using endpointping */
3417 AR6000_SPIN_LOCK(&ar->arLock, 0);
3418 /* set flag to handle subsequent messages */
3419 ar->arWMIControlEpFull = true;
3420 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3421 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n"));
3422 /* no need to stop the network */
3427 /* if we get here, we are dealing with data endpoints getting full */
3429 if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) {
3430 /* don't drop control packets issued on ANY data endpoint */
3434 if (ar->arNetworkType == ADHOC_NETWORK) {
3435 /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to
3436 * continue, however we should stop the network */
3440 /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest
3442 if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri &&
3443 ar->arCookieCount <= MAX_HI_COOKIE_NUM) {
3444 /* this stream's priority is less than the highest active priority, we
3445 * give preference to the highest priority stream by directing
3446 * HTC to drop the packet that overflowed */
3447 action = HTC_SEND_FULL_DROP;
3448 /* since we are dropping packets, no need to stop the network */
3456 AR6000_SPIN_LOCK(&ar->arLock, 0);
3457 ar->arNetQueueStopped = true;
3458 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3459 /* one of the data endpoints queues is getting full..need to stop network stack
3460 * the queue will resume in ar6000_tx_complete() */
3461 netif_stop_queue(ar->arNetDev);
3469 ar6000_tx_complete(void *Context, struct htc_packet_queue *pPacketQueue)
3471 struct ar6_softc *ar = (struct ar6_softc *)Context;
3474 struct ar_cookie * ar_cookie;
3475 HTC_ENDPOINT_ID eid;
3476 bool wakeEvent = false;
3477 struct sk_buff_head skb_queue;
3478 struct htc_packet *pPacket;
3479 struct sk_buff *pktSkb;
3480 bool flushing = false;
3482 skb_queue_head_init(&skb_queue);
3484 /* lock the driver as we update internal state */
3485 AR6000_SPIN_LOCK(&ar->arLock, 0);
3487 /* reap completed packets */
3488 while (!HTC_QUEUE_EMPTY(pPacketQueue)) {
3490 pPacket = HTC_PACKET_DEQUEUE(pPacketQueue);
3492 ar_cookie = (struct ar_cookie *)pPacket->pPktContext;
3493 A_ASSERT(ar_cookie);
3495 status = pPacket->Status;
3496 pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0];
3497 eid = pPacket->Endpoint;
3498 mapNo = ar_cookie->arc_bp[1];
3501 A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb));
3503 /* add this to the list, use faster non-lock API */
3504 __skb_queue_tail(&skb_queue,pktSkb);
3507 A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb));
3510 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%lx data=0x%lx len=0x%x eid=%d ",
3511 (unsigned long)pktSkb, (unsigned long)pPacket->pBuffer,
3512 pPacket->ActualLength,
3515 ar->arTxPending[eid]--;
3517 if ((eid != ar->arControlEp) || bypasswmi) {
3518 ar->arTotalTxDataPending--;
3521 if (eid == ar->arControlEp)
3523 if (ar->arWMIControlEpFull) {
3524 /* since this packet completed, the WMI EP is no longer full */
3525 ar->arWMIControlEpFull = false;
3528 if (ar->arTxPending[eid] == 0) {
3534 if (status == A_ECANCELED) {
3535 /* a packet was flushed */
3538 AR6000_STAT_INC(ar, tx_errors);
3539 if (status != A_NO_RESOURCE) {
3540 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__,
3544 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n"));
3546 AR6000_STAT_INC(ar, tx_packets);
3547 ar->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb);
3548 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3549 aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb);
3550 applyAPTCHeuristics(ar);
3551 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3554 // TODO this needs to be looked at
3555 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable
3556 && (eid != ar->arControlEp) && mapNo)
3559 ar->arNodeMap[mapNo].txPending --;
3561 if (!ar->arNodeMap[mapNo].txPending && (mapNo == (ar->arNodeNum - 1))) {
3563 for (i = ar->arNodeNum; i > 0; i --) {
3564 if (!ar->arNodeMap[i - 1].txPending) {
3565 A_MEMZERO(&ar->arNodeMap[i - 1], sizeof(struct ar_node_mapping));
3574 ar6000_free_cookie(ar, ar_cookie);
3576 if (ar->arNetQueueStopped) {
3577 ar->arNetQueueStopped = false;
3581 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3583 /* lock is released, we can freely call other kernel APIs */
3585 /* free all skbs in our local list */
3586 while (!skb_queue_empty(&skb_queue)) {
3587 /* use non-lock version */
3588 pktSkb = __skb_dequeue(&skb_queue);
3589 A_NETBUF_FREE(pktSkb);
3592 if ((ar->arConnected == true) || bypasswmi) {
3594 /* don't wake the queue if we are flushing, other wise it will just
3595 * keep queueing packets, which will keep failing */
3596 netif_wake_queue(ar->arNetDev);
3607 ieee80211_find_conn(struct ar6_softc *ar, u8 *node_addr)
3612 switch(ar->arNetworkType) {
3614 max_conn = AP_MAX_NUM_STA;
3621 for (i = 0; i < max_conn; i++) {
3622 if (IEEE80211_ADDR_EQ(node_addr, ar->sta_list[i].mac)) {
3623 conn = &ar->sta_list[i];
3631 sta_t *ieee80211_find_conn_for_aid(struct ar6_softc *ar, u8 aid)
3636 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) {
3637 if (ar->sta_list[ctr].aid == aid) {
3638 conn = &ar->sta_list[ctr];
3646 * Receive event handler. This is called by HTC when a packet is received
3650 ar6000_rx(void *Context, struct htc_packet *pPacket)
3652 struct ar6_softc *ar = (struct ar6_softc *)Context;
3653 struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext;
3655 u8 containsDot11Hdr = 0;
3656 int status = pPacket->Status;
3657 HTC_ENDPOINT_ID ept = pPacket->Endpoint;
3659 A_ASSERT((status) ||
3660 (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN)));
3662 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",
3663 (unsigned long)ar, ept, (unsigned long)skb, (unsigned long)pPacket->pBuffer,
3664 pPacket->ActualLength, status));
3666 if (status != A_ECANCELED) {
3667 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status));
3671 /* take lock to protect buffer counts
3672 * and adaptive power throughput state */
3673 AR6000_SPIN_LOCK(&ar->arLock, 0);
3676 AR6000_STAT_INC(ar, rx_packets);
3677 ar->arNetStats.rx_bytes += pPacket->ActualLength;
3678 #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL
3679 aptcTR.bytesReceived += a_netbuf_to_len(skb);
3680 applyAPTCHeuristics(ar);
3681 #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */
3683 A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN);
3684 A_NETBUF_PULL(skb, HTC_HEADER_LEN);
3687 if (debugdriver >= 2) {
3688 ar6000_dump_skb(skb);
3693 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
3695 skb->dev = ar->arNetDev;
3697 AR6000_STAT_INC(ar, rx_errors);
3699 } else if (ar->arWmiEnabled == true) {
3700 if (ept == ar->arControlEp) {
3702 * this is a wmi control msg
3705 ar6000_check_wow_status(ar, skb, true);
3706 #endif /* CONFIG_PM */
3707 wmi_control_rx(ar->arWmi, skb);
3709 WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb);
3712 bool is_acl_data_frame;
3713 is_acl_data_frame = WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == WMI_DATA_HDR_DATA_TYPE_ACL;
3715 ar6000_check_wow_status(ar, NULL, false);
3716 #endif /* CONFIG_PM */
3718 * this is a wmi data packet
3722 if (processDot11Hdr) {
3723 minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR);
3725 minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) +
3726 sizeof(ATH_LLC_SNAP_HDR);
3729 /* In the case of AP mode we may receive NULL data frames
3730 * that do not have LLC hdr. They are 16 bytes in size.
3731 * Allow these frames in the AP mode.
3732 * ACL data frames don't follow ethernet frame bounds for
3735 if (ar->arNetworkType != AP_NETWORK && !is_acl_data_frame &&
3736 ((pPacket->ActualLength < minHdrLen) ||
3737 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)))
3740 * packet is too short or too long
3742 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n"));
3743 AR6000_STAT_INC(ar, rx_errors);
3744 AR6000_STAT_INC(ar, rx_length_errors);
3751 /* Access RSSI values here */
3752 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n",
3753 ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi));
3755 /* Get the Power save state of the STA */
3756 if (ar->arNetworkType == AP_NETWORK) {
3758 u8 psState=0,prevPsState;
3759 ATH_MAC_HDR *datap=NULL;
3762 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3764 psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info
3765 >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK;
3767 offset = sizeof(WMI_DATA_HDR);
3769 switch (meta_type) {
3772 case WMI_META_VERSION_1:
3773 offset += sizeof(WMI_RX_META_V1);
3775 #ifdef CONFIG_CHECKSUM_OFFLOAD
3776 case WMI_META_VERSION_2:
3777 offset += sizeof(WMI_RX_META_V2);
3784 datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset);
3785 conn = ieee80211_find_conn(ar, datap->srcMac);
3788 /* if there is a change in PS state of the STA,
3789 * take appropriate steps.
3790 * 1. If Sleep-->Awake, flush the psq for the STA
3791 * Clear the PVB for the STA.
3792 * 2. If Awake-->Sleep, Starting queueing frames
3795 prevPsState = STA_IS_PWR_SLEEP(conn);
3797 STA_SET_PWR_SLEEP(conn);
3799 STA_CLR_PWR_SLEEP(conn);
3802 if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) {
3804 if (!STA_IS_PWR_SLEEP(conn)) {
3806 A_MUTEX_LOCK(&conn->psqLock);
3807 while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) {
3808 struct sk_buff *skb=NULL;
3810 skb = A_NETBUF_DEQUEUE(&conn->psq);
3811 A_MUTEX_UNLOCK(&conn->psqLock);
3812 ar6000_data_tx(skb,ar->arNetDev);
3813 A_MUTEX_LOCK(&conn->psqLock);
3815 A_MUTEX_UNLOCK(&conn->psqLock);
3816 /* Clear the PVB for this STA */
3817 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
3821 /* This frame is from a STA that is not associated*/
3825 /* Drop NULL data frames here */
3826 if((pPacket->ActualLength < minHdrLen) ||
3827 (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) {
3833 is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr) ? true : false;
3834 tid = WMI_DATA_HDR_GET_UP(dhdr);
3835 seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr);
3836 meta_type = WMI_DATA_HDR_GET_META(dhdr);
3837 containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr);
3839 wmi_data_hdr_remove(ar->arWmi, skb);
3841 switch (meta_type) {
3842 case WMI_META_VERSION_1:
3844 WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb);
3845 A_PRINTF("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags);
3846 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1));
3849 #ifdef CONFIG_CHECKSUM_OFFLOAD
3850 case WMI_META_VERSION_2:
3852 WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb);
3853 if(pMeta->csumFlags & 0x1){
3854 skb->ip_summed=CHECKSUM_COMPLETE;
3855 skb->csum=(pMeta->csum);
3857 A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2));
3865 A_ASSERT(status == 0);
3867 /* NWF: print the 802.11 hdr bytes */
3868 if(containsDot11Hdr) {
3869 status = wmi_dot11_hdr_remove(ar->arWmi,skb);
3870 } else if(!is_amsdu && !is_acl_data_frame) {
3871 status = wmi_dot3_2_dix(skb);
3875 /* Drop frames that could not be processed (lack of memory, etc.) */
3880 if (is_acl_data_frame) {
3881 A_NETBUF_PUSH(skb, sizeof(int));
3882 *((short *)A_NETBUF_DATA(skb)) = WMI_ACL_DATA_EVENTID;
3883 /* send the data packet to PAL driver */
3884 if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) {
3885 if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, skb) == true)
3890 if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) {
3891 if (ar->arNetworkType == AP_NETWORK) {
3892 struct sk_buff *skb1 = NULL;
3895 datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb);
3896 if (IEEE80211_IS_MULTICAST(datap->dstMac)) {
3897 /* Bcast/Mcast frames should be sent to the OS
3898 * stack as well as on the air.
3900 skb1 = skb_copy(skb,GFP_ATOMIC);
3902 /* Search for a connected STA with dstMac as
3903 * the Mac address. If found send the frame to
3904 * it on the air else send the frame up the
3908 conn = ieee80211_find_conn(ar, datap->dstMac);
3910 if (conn && ar->intra_bss) {
3913 } else if(conn && !ar->intra_bss) {
3919 ar6000_data_tx(skb1, ar->arNetDev);
3923 #ifdef ATH_AR6K_11N_SUPPORT
3924 aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb);
3926 ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb);
3930 if (EPPING_ALIGNMENT_PAD > 0) {
3931 A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD);
3933 ar6000_deliver_frames_to_nw_stack((void *)ar->arNetDev, (void *)skb);
3942 ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf)
3944 struct sk_buff *skb = (struct sk_buff *)osbuf;
3948 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3950 ar6000_check_wow_status((struct ar6_softc *)ar6k_priv(dev), skb, false);
3951 #endif /* CONFIG_PM */
3952 skb->protocol = eth_type_trans(skb, skb->dev);
3954 * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ)
3955 * or tasklet use the netif_rx to deliver the packet to the stack
3956 * netif_rx will queue the packet onto the receive queue and mark
3957 * the softirq thread has a pending action to complete. Kernel will
3958 * schedule the softIrq kernel thread after processing the DSR.
3960 * If this routine is called on a process context, use netif_rx_ni
3961 * which will schedle the softIrq kernel thread after queuing the packet.
3963 if (in_interrupt()) {
3976 ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf)
3978 struct sk_buff *skb = (struct sk_buff *)osbuf;
3982 if ((skb->dev->flags & IFF_UP) == IFF_UP) {
3983 skb->protocol = htons(ETH_P_CONTROL);
3993 ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint)
3995 struct ar6_softc *ar = (struct ar6_softc *)Context;
3998 int buffersToRefill;
3999 struct htc_packet *pPacket;
4000 struct htc_packet_queue queue;
4002 buffersToRefill = (int)AR6000_MAX_RX_BUFFERS -
4003 HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint);
4005 if (buffersToRefill <= 0) {
4006 /* fast return, nothing to fill */
4010 INIT_HTC_PACKET_QUEUE(&queue);
4012 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n",
4013 buffersToRefill, Endpoint));
4015 for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) {
4016 osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE);
4017 if (NULL == osBuf) {
4020 /* the HTC packet wrapper is at the head of the reserved area
4022 pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
4023 /* set re-fill info */
4024 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint);
4026 HTC_PACKET_ENQUEUE(&queue,pPacket);
4029 if (!HTC_QUEUE_EMPTY(&queue)) {
4031 HTCAddReceivePktMultiple(ar->arHtcTarget, &queue);
4036 /* clean up our amsdu buffer list */
4037 static void ar6000_cleanup_amsdu_rxbufs(struct ar6_softc *ar)
4039 struct htc_packet *pPacket;
4042 /* empty AMSDU buffer queue and free OS bufs */
4045 AR6000_SPIN_LOCK(&ar->arLock, 0);
4046 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
4047 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4049 if (NULL == pPacket) {
4053 osBuf = pPacket->pPktContext;
4054 if (NULL == osBuf) {
4059 A_NETBUF_FREE(osBuf);
4065 /* refill the amsdu buffer list */
4066 static void ar6000_refill_amsdu_rxbufs(struct ar6_softc *ar, int Count)
4068 struct htc_packet *pPacket;
4072 osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE);
4073 if (NULL == osBuf) {
4076 /* the HTC packet wrapper is at the head of the reserved area
4078 pPacket = (struct htc_packet *)(A_NETBUF_HEAD(osBuf));
4079 /* set re-fill info */
4080 SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0);
4082 AR6000_SPIN_LOCK(&ar->arLock, 0);
4083 /* put it in the list */
4084 HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket);
4085 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4091 /* callback to allocate a large receive buffer for a pending packet. This function is called when
4092 * an HTC packet arrives whose length exceeds a threshold value
4094 * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to
4095 * keep the allocation size the same to optimize cached-slab allocations.
4098 static struct htc_packet *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length)
4100 struct htc_packet *pPacket = NULL;
4101 struct ar6_softc *ar = (struct ar6_softc *)Context;
4102 int refillCount = 0;
4104 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length));
4108 if (Length <= AR6000_BUFFER_SIZE) {
4109 /* shouldn't be getting called on normal sized packets */
4114 if (Length > AR6000_AMSDU_BUFFER_SIZE) {
4119 AR6000_SPIN_LOCK(&ar->arLock, 0);
4120 /* allocate a packet from the list */
4121 pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue);
4122 /* see if we need to refill again */
4123 refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue);
4124 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
4126 if (NULL == pPacket) {
4129 /* set actual endpoint ID */
4130 pPacket->Endpoint = Endpoint;
4134 if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) {
4135 ar6000_refill_amsdu_rxbufs(ar,refillCount);
4142 ar6000_set_multicast_list(struct net_device *dev)
4144 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: Multicast filter not supported\n"));
4147 static struct net_device_stats *
4148 ar6000_get_stats(struct net_device *dev)
4150 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
4151 return &ar->arNetStats;
4154 static struct iw_statistics *
4155 ar6000_get_iwstats(struct net_device * dev)
4157 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev);
4158 TARGET_STATS *pStats = &ar->arTargetStats;
4159 struct iw_statistics * pIwStats = &ar->arIwStats;
4162 if (ar->bIsDestroyProgress || ar->arWmiReady == false || ar->arWlanState == WLAN_DISABLED)
4164 pIwStats->status = 0;
4165 pIwStats->qual.qual = 0;
4166 pIwStats->qual.level =0;
4167 pIwStats->qual.noise = 0;
4168 pIwStats->discard.code =0;
4169 pIwStats->discard.retries=0;
4170 pIwStats->miss.beacon =0;
4175 * The in_atomic function is used to determine if the scheduling is
4176 * allowed in the current context or not. This was introduced in 2.6
4177 * From what I have read on the differences between 2.4 and 2.6, the
4178 * 2.4 kernel did not support preemption and so this check might not
4179 * be required for 2.4 kernels.
4183 wmi_get_stats_cmd(ar->arWmi);
4185 pIwStats->status = 1 ;
4186 pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161;
4187 pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */
4188 pIwStats->qual.noise = pStats->noise_floor_calibation;
4189 pIwStats->discard.code = pStats->rx_decrypt_err;
4190 pIwStats->discard.retries = pStats->tx_retry_cnt;
4191 pIwStats->miss.beacon = pStats->cs_bmiss_cnt;
4196 rtnllocked = rtnl_is_locked();
4200 pIwStats->status = 0;
4202 if (down_interruptible(&ar->arSem)) {
4208 if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) {
4212 ar->statsUpdatePending = true;
4214 if(wmi_get_stats_cmd(ar->arWmi) != 0) {
4218 wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ);
4219 if (signal_pending(current)) {
4220 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : WMI get stats timeout \n"));
4223 pIwStats->status = 1 ;
4224 pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161;
4225 pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */
4226 pIwStats->qual.noise = pStats->noise_floor_calibation;
4227 pIwStats->discard.code = pStats->rx_decrypt_err;
4228 pIwStats->discard.retries = pStats->tx_retry_cnt;
4229 pIwStats->miss.beacon = pStats->cs_bmiss_cnt;
4242 ar6000_ready_event(void *devt, u8 *datap, u8 phyCap, u32 sw_ver, u32 abi_ver)
4244 struct ar6_softc *ar = (struct ar6_softc *)devt;
4245 struct net_device *dev = ar->arNetDev;
4247 memcpy(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN);
4248 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
4249 dev->dev_addr[0], dev->dev_addr[1],
4250 dev->dev_addr[2], dev->dev_addr[3],
4251 dev->dev_addr[4], dev->dev_addr[5]));
4253 ar->arPhyCapability = phyCap;
4254 ar->arVersion.wlan_ver = sw_ver;
4255 ar->arVersion.abi_ver = abi_ver;
4257 /* Indicate to the waiting thread that the ready event was received */
4258 ar->arWmiReady = true;
4263 add_new_sta(struct ar6_softc *ar, u8 *mac, u16 aid, u8 *wpaie,
4264 u8 ielen, u8 keymgmt, u8 ucipher, u8 auth)
4268 memcpy(ar->sta_list[free_slot].mac, mac, ATH_MAC_LEN);
4269 memcpy(ar->sta_list[free_slot].wpa_ie, wpaie, ielen);
4270 ar->sta_list[free_slot].aid = aid;
4271 ar->sta_list[free_slot].keymgmt = keymgmt;
4272 ar->sta_list[free_slot].ucipher = ucipher;
4273 ar->sta_list[free_slot].auth = auth;
4274 ar->sta_list_index = ar->sta_list_index | (1 << free_slot);
4275 ar->arAPStats.sta[free_slot].aid = aid;
4279 ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid,
4280 u16 listenInterval, u16 beaconInterval,
4281 NETWORK_TYPE networkType, u8 beaconIeLen,
4282 u8 assocReqLen, u8 assocRespLen,
4285 union iwreq_data wrqu;
4286 int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos;
4287 static const char *tag1 = "ASSOCINFO(ReqIEs=";
4288 static const char *tag2 = "ASSOCRESPIE=";
4289 static const char *beaconIetag = "BEACONIE=";
4290 char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1];
4293 unsigned long flags;
4294 struct ieee80211req_key *ik;
4295 CRYPTO_TYPE keyType = NONE_CRYPT;
4297 if(ar->arNetworkType & AP_NETWORK) {
4298 struct net_device *dev = ar->arNetDev;
4299 if(memcmp(dev->dev_addr, bssid, ATH_MAC_LEN)==0) {
4300 ar->arACS = channel;
4301 ik = &ar->ap_mode_bkey;
4303 switch(ar->arAuthMode) {
4305 if(ar->arPairwiseCrypto == WEP_CRYPT) {
4306 ar6000_install_static_wep_keys(ar);
4309 else if(ar->arPairwiseCrypto == WAPI_CRYPT) {
4310 ap_set_wapi_key(ar, ik);
4316 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
4317 switch (ik->ik_type) {
4318 case IEEE80211_CIPHER_TKIP:
4319 keyType = TKIP_CRYPT;
4321 case IEEE80211_CIPHER_AES_CCM:
4322 keyType = AES_CRYPT;
4327 wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, GROUP_USAGE,
4328 ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
4329 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
4335 ar->arConnected = true;
4339 A_PRINTF("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n "
4340 " AID=%d \n", bssid[0], bssid[1], bssid[2],
4341 bssid[3], bssid[4], bssid[5], channel);
4342 switch ((listenInterval>>8)&0xFF) {
4344 A_PRINTF("AUTH: OPEN\n");
4347 A_PRINTF("AUTH: SHARED\n");
4350 A_PRINTF("AUTH: Unknown\n");
4353 switch (listenInterval&0xFF) {
4355 A_PRINTF("KeyMgmt: WPA-PSK\n");
4358 A_PRINTF("KeyMgmt: WPA2-PSK\n");
4361 A_PRINTF("KeyMgmt: NONE\n");
4364 switch (beaconInterval) {
4366 A_PRINTF("Cipher: AES\n");
4369 A_PRINTF("Cipher: TKIP\n");
4372 A_PRINTF("Cipher: WEP\n");
4376 A_PRINTF("Cipher: WAPI\n");
4380 A_PRINTF("Cipher: NONE\n");
4384 add_new_sta(ar, bssid, channel /*aid*/,
4385 assocInfo /* WPA IE */, assocRespLen /* IE len */,
4386 listenInterval&0xFF /* Keymgmt */, beaconInterval /* cipher */,
4387 (listenInterval>>8)&0xFF /* auth alg */);
4389 /* Send event to application */
4390 A_MEMZERO(&wrqu, sizeof(wrqu));
4391 memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4392 wireless_send_event(ar->arNetDev, IWEVREGISTERED, &wrqu, NULL);
4393 /* In case the queue is stopped when we switch modes, this will
4396 netif_wake_queue(ar->arNetDev);
4400 #ifdef ATH6K_CONFIG_CFG80211
4401 ar6k_cfg80211_connect_event(ar, channel, bssid,
4402 listenInterval, beaconInterval,
4403 networkType, beaconIeLen,
4404 assocReqLen, assocRespLen,
4406 #endif /* ATH6K_CONFIG_CFG80211 */
4408 memcpy(ar->arBssid, bssid, sizeof(ar->arBssid));
4409 ar->arBssChannel = channel;
4411 A_PRINTF("AR6000 connected event on freq %d ", channel);
4412 A_PRINTF("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4413 " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d"
4414 " assocRespLen =%d\n",
4415 bssid[0], bssid[1], bssid[2],
4416 bssid[3], bssid[4], bssid[5],
4417 listenInterval, beaconInterval,
4418 beaconIeLen, assocReqLen, assocRespLen);
4419 if (networkType & ADHOC_NETWORK) {
4420 if (networkType & ADHOC_CREATOR) {
4421 A_PRINTF("Network: Adhoc (Creator)\n");
4423 A_PRINTF("Network: Adhoc (Joiner)\n");
4426 A_PRINTF("Network: Infrastructure\n");
4429 if ((ar->arNetworkType == INFRA_NETWORK)) {
4430 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
4433 if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) {
4434 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= "));
4437 A_MEMZERO(buf, sizeof(buf));
4438 sprintf(buf, "%s", beaconIetag);
4440 for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) {
4441 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4442 sprintf(pos, "%2.2x", assocInfo[i]);
4445 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4447 A_MEMZERO(&wrqu, sizeof(wrqu));
4448 wrqu.data.length = strlen(buf);
4449 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4452 if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2))))
4454 assoc_resp_ie_pos = beaconIeLen + assocReqLen +
4455 sizeof(u16) + /* capinfo*/
4456 sizeof(u16) + /* status Code */
4457 sizeof(u16) ; /* associd */
4458 A_MEMZERO(buf, sizeof(buf));
4459 sprintf(buf, "%s", tag2);
4461 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= "));
4463 * The Association Response Frame w.o. the WLAN header is delivered to
4464 * the host, so skip over to the IEs
4466 for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++)
4468 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4469 sprintf(pos, "%2.2x", assocInfo[i]);
4472 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4474 A_MEMZERO(&wrqu, sizeof(wrqu));
4475 wrqu.data.length = strlen(buf);
4476 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4479 if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) {
4481 * assoc Request includes capability and listen interval. Skip these.
4483 assoc_req_ie_pos = beaconIeLen +
4484 sizeof(u16) + /* capinfo*/
4485 sizeof(u16); /* listen interval */
4487 A_MEMZERO(buf, sizeof(buf));
4488 sprintf(buf, "%s", tag1);
4490 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= "));
4491 for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) {
4492 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4493 sprintf(pos, "%2.2x", assocInfo[i]);
4496 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4498 A_MEMZERO(&wrqu, sizeof(wrqu));
4499 wrqu.data.length = strlen(buf);
4500 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4504 if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN &&
4505 ar->user_saved_keys.keyOk == true)
4507 key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC;
4509 if (ar->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) {
4510 key_op_ctrl &= ~KEY_OP_INIT_RSC;
4512 key_op_ctrl |= KEY_OP_INIT_RSC;
4514 ar6000_reinstall_keys(ar, key_op_ctrl);
4516 #endif /* USER_KEYS */
4518 netif_wake_queue(ar->arNetDev);
4520 /* For CFG80211 the key configuration and the default key comes in after connect so no point in plumbing invalid keys */
4521 #ifndef ATH6K_CONFIG_CFG80211
4522 if ((networkType & ADHOC_NETWORK) &&
4523 (OPEN_AUTH == ar->arDot11AuthMode) &&
4524 (NONE_AUTH == ar->arAuthMode) &&
4525 (WEP_CRYPT == ar->arPairwiseCrypto))
4527 if (!ar->arConnected) {
4528 wmi_addKey_cmd(ar->arWmi,
4529 ar->arDefTxKeyIndex,
4531 GROUP_USAGE | TX_USAGE,
4532 ar->arWepKeyList[ar->arDefTxKeyIndex].arKeyLen,
4534 ar->arWepKeyList[ar->arDefTxKeyIndex].arKey, KEY_OP_INIT_VAL, NULL,
4538 #endif /* ATH6K_CONFIG_CFG80211 */
4540 /* Update connect & link status atomically */
4541 spin_lock_irqsave(&ar->arLock, flags);
4542 ar->arConnected = true;
4543 ar->arConnectPending = false;
4544 netif_carrier_on(ar->arNetDev);
4545 spin_unlock_irqrestore(&ar->arLock, flags);
4546 /* reset the rx aggr state */
4547 aggr_reset_state(ar->aggr_cntxt);
4550 A_MEMZERO(&wrqu, sizeof(wrqu));
4551 memcpy(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN);
4552 wrqu.addr.sa_family = ARPHRD_ETHER;
4553 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4554 if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable) {
4555 A_MEMZERO(ar->arNodeMap, sizeof(ar->arNodeMap));
4557 ar->arNexEpId = ENDPOINT_2;
4559 if (!ar->arUserBssFilter) {
4560 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4565 void ar6000_set_numdataendpts(struct ar6_softc *ar, u32 num)
4567 A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1));
4568 ar->arNumDataEndPts = num;
4572 sta_cleanup(struct ar6_softc *ar, u8 i)
4574 struct sk_buff *skb;
4576 /* empty the queued pkts in the PS queue if any */
4577 A_MUTEX_LOCK(&ar->sta_list[i].psqLock);
4578 while (!A_NETBUF_QUEUE_EMPTY(&ar->sta_list[i].psq)) {
4579 skb = A_NETBUF_DEQUEUE(&ar->sta_list[i].psq);
4582 A_MUTEX_UNLOCK(&ar->sta_list[i].psqLock);
4584 /* Zero out the state fields */
4585 A_MEMZERO(&ar->arAPStats.sta[ar->sta_list[i].aid-1], sizeof(WMI_PER_STA_STAT));
4586 A_MEMZERO(&ar->sta_list[i].mac, ATH_MAC_LEN);
4587 A_MEMZERO(&ar->sta_list[i].wpa_ie, IEEE80211_MAX_IE);
4588 ar->sta_list[i].aid = 0;
4589 ar->sta_list[i].flags = 0;
4591 ar->sta_list_index = ar->sta_list_index & ~(1 << i);
4595 u8 remove_sta(struct ar6_softc *ar, u8 *mac, u16 reason)
4599 if(IS_MAC_NULL(mac)) {
4603 if(IS_MAC_BCAST(mac)) {
4604 A_PRINTF("DEL ALL STA\n");
4605 for(i=0; i < AP_MAX_NUM_STA; i++) {
4606 if(!IS_MAC_NULL(ar->sta_list[i].mac)) {
4612 for(i=0; i < AP_MAX_NUM_STA; i++) {
4613 if(memcmp(ar->sta_list[i].mac, mac, ATH_MAC_LEN)==0) {
4614 A_PRINTF("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
4615 " aid=%d REASON=%d\n", mac[0], mac[1], mac[2],
4616 mac[3], mac[4], mac[5], ar->sta_list[i].aid, reason);
4628 ar6000_disconnect_event(struct ar6_softc *ar, u8 reason, u8 *bssid,
4629 u8 assocRespLen, u8 *assocInfo, u16 protocolReasonStatus)
4632 unsigned long flags;
4633 union iwreq_data wrqu;
4635 if(ar->arNetworkType & AP_NETWORK) {
4636 union iwreq_data wrqu;
4637 struct sk_buff *skb;
4639 if(!remove_sta(ar, bssid, protocolReasonStatus)) {
4643 /* If there are no more associated STAs, empty the mcast PS q */
4644 if (ar->sta_list_index == 0) {
4645 A_MUTEX_LOCK(&ar->mcastpsqLock);
4646 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
4647 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
4650 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
4652 /* Clear the LSB of the BitMapCtl field of the TIM IE */
4653 if (ar->arWmiReady) {
4654 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
4658 if(!IS_MAC_BCAST(bssid)) {
4659 /* Send event to application */
4660 A_MEMZERO(&wrqu, sizeof(wrqu));
4661 memcpy(wrqu.addr.sa_data, bssid, ATH_MAC_LEN);
4662 wireless_send_event(ar->arNetDev, IWEVEXPIRED, &wrqu, NULL);
4665 ar->arConnected = false;
4669 #ifdef ATH6K_CONFIG_CFG80211
4670 ar6k_cfg80211_disconnect_event(ar, reason, bssid,
4671 assocRespLen, assocInfo,
4672 protocolReasonStatus);
4673 #endif /* ATH6K_CONFIG_CFG80211 */
4675 /* Send disconnect event to supplicant */
4676 A_MEMZERO(&wrqu, sizeof(wrqu));
4677 wrqu.addr.sa_family = ARPHRD_ETHER;
4678 wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL);
4680 /* it is necessary to clear the host-side rx aggregation state */
4681 aggr_reset_state(ar->aggr_cntxt);
4683 A_UNTIMEOUT(&ar->disconnect_timer);
4685 A_PRINTF("AR6000 disconnected");
4686 if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) {
4687 A_PRINTF(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4688 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
4691 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason));
4692 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus));
4693 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s",
4694 assocRespLen ? " " : "NULL"));
4695 for (i = 0; i < assocRespLen; i++) {
4697 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4699 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4701 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4703 * If the event is due to disconnect cmd from the host, only they the target
4704 * would stop trying to connect. Under any other condition, target would
4705 * keep trying to connect.
4708 if( reason == DISCONNECT_CMD)
4710 if ((!ar->arUserBssFilter) && (ar->arWmiReady)) {
4711 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4714 ar->arConnectPending = true;
4715 if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) ||
4716 ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) {
4717 ar->arConnected = true;
4722 if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady))
4724 bss_t *pWmiSsidnode = NULL;
4726 /* remove the current associated bssid node */
4727 wmi_free_node (ar->arWmi, bssid);
4730 * In case any other same SSID nodes are present
4731 * remove it, since those nodes also not available now
4736 * Find the nodes based on SSID and remove it
4737 * NOTE :: This case will not work out for Hidden-SSID
4739 pWmiSsidnode = wmi_find_Ssidnode (ar->arWmi, ar->arSsid, ar->arSsidLen, false, true);
4743 wmi_free_node (ar->arWmi, pWmiSsidnode->ni_macaddr);
4746 } while (pWmiSsidnode);
4749 /* Update connect & link status atomically */
4750 spin_lock_irqsave(&ar->arLock, flags);
4751 ar->arConnected = false;
4752 netif_carrier_off(ar->arNetDev);
4753 spin_unlock_irqrestore(&ar->arLock, flags);
4755 if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) {
4760 if (reason != CSERV_DISCONNECT)
4762 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
4763 ar->user_key_ctrl = 0;
4765 #endif /* USER_KEYS */
4767 netif_stop_queue(ar->arNetDev);
4768 A_MEMZERO(ar->arBssid, sizeof(ar->arBssid));
4769 ar->arBssChannel = 0;
4770 ar->arBeaconInterval = 0;
4772 ar6000_TxDataCleanup(ar);
4776 ar6000_regDomain_event(struct ar6_softc *ar, u32 regCode)
4778 A_PRINTF("AR6000 Reg Code = 0x%x\n", regCode);
4779 ar->arRegCode = regCode;
4782 #ifdef ATH_AR6K_11N_SUPPORT
4784 ar6000_aggr_rcv_addba_req_evt(struct ar6_softc *ar, WMI_ADDBA_REQ_EVENT *evt)
4786 if(evt->status == 0) {
4787 aggr_recv_addba_req_evt(ar->aggr_cntxt, evt->tid, evt->st_seq_no, evt->win_sz);
4792 ar6000_aggr_rcv_addba_resp_evt(struct ar6_softc *ar, WMI_ADDBA_RESP_EVENT *evt)
4794 A_PRINTF("ADDBA RESP. tid %d status %d, sz %d\n", evt->tid, evt->status, evt->amsdu_sz);
4795 if(evt->status == 0) {
4800 ar6000_aggr_rcv_delba_req_evt(struct ar6_softc *ar, WMI_DELBA_EVENT *evt)
4802 aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid);
4806 void register_pal_cb(ar6k_pal_config_t *palConfig_p)
4808 ar6k_pal_config_g = *palConfig_p;
4812 ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd)
4819 size = cmd->evt_buf_sz + 4;
4820 osbuf = A_NETBUF_ALLOC(size);
4821 if (osbuf == NULL) {
4823 A_PRINTF("Error in allocating netbuf \n");
4827 A_NETBUF_PUT(osbuf, size);
4828 buf = (u8 *)A_NETBUF_DATA(osbuf);
4829 /* First 2-bytes carry HCI event/ACL data type
4830 * the next 2 are free
4832 *((short *)buf) = WMI_HCI_EVENT_EVENTID;
4834 memcpy(buf, cmd->buf, cmd->evt_buf_sz);
4836 if(ar6k_pal_config_g.fpar6k_pal_recv_pkt)
4838 /* pass the cmd packet to PAL driver */
4839 if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, osbuf) == true)
4842 ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf);
4844 A_PRINTF_LOG("HCI Event From PAL <-- \n");
4845 for(i = 0; i < cmd->evt_buf_sz; i++) {
4846 A_PRINTF_LOG("0x%02x ", cmd->buf[i]);
4852 A_PRINTF_LOG("==================================\n");
4857 ar6000_neighborReport_event(struct ar6_softc *ar, int numAps, WMI_NEIGHBOR_INFO *info)
4859 #if WIRELESS_EXT >= 18
4860 struct iw_pmkid_cand *pmkcand;
4861 #else /* WIRELESS_EXT >= 18 */
4862 static const char *tag = "PRE-AUTH";
4864 #endif /* WIRELESS_EXT >= 18 */
4866 union iwreq_data wrqu;
4869 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("AR6000 Neighbor Report Event\n"));
4870 for (i=0; i < numAps; info++, i++) {
4871 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",
4872 info->bssid[0], info->bssid[1], info->bssid[2],
4873 info->bssid[3], info->bssid[4], info->bssid[5]));
4874 if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) {
4875 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("preauth-cap"));
4877 if (info->bssFlags & WMI_PMKID_VALID_BSS) {
4878 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,(" pmkid-valid\n"));
4879 continue; /* we skip bss if the pmkid is already valid */
4881 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("\n"));
4882 A_MEMZERO(&wrqu, sizeof(wrqu));
4883 #if WIRELESS_EXT >= 18
4884 pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand));
4885 A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand));
4887 pmkcand->flags = info->bssFlags;
4888 memcpy(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN);
4889 wrqu.data.length = sizeof(struct iw_pmkid_cand);
4890 wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand);
4892 #else /* WIRELESS_EXT >= 18 */
4893 snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
4895 info->bssid[0], info->bssid[1], info->bssid[2],
4896 info->bssid[3], info->bssid[4], info->bssid[5],
4898 wrqu.data.length = strlen(buf);
4899 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4900 #endif /* WIRELESS_EXT >= 18 */
4905 ar6000_tkip_micerr_event(struct ar6_softc *ar, u8 keyid, bool ismcast)
4907 static const char *tag = "MLME-MICHAELMICFAILURE.indication";
4909 union iwreq_data wrqu;
4912 * For AP case, keyid will have aid of STA which sent pkt with
4913 * MIC error. Use this aid to get MAC & send it to hostapd.
4915 if (ar->arNetworkType == AP_NETWORK) {
4916 sta_t *s = ieee80211_find_conn_for_aid(ar, (keyid >> 2));
4918 A_PRINTF("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid);
4921 A_PRINTF("AP TKIP MIC error received from aid=%d\n", keyid);
4922 snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
4923 tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]);
4926 #ifdef ATH6K_CONFIG_CFG80211
4927 ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast);
4928 #endif /* ATH6K_CONFIG_CFG80211 */
4930 A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n",
4931 keyid & 0x3, ismcast ? "multi": "uni");
4932 snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3,
4933 ismcast ? "mult" : "un");
4936 memset(&wrqu, 0, sizeof(wrqu));
4937 wrqu.data.length = strlen(buf);
4938 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
4942 ar6000_scanComplete_event(struct ar6_softc *ar, int status)
4945 #ifdef ATH6K_CONFIG_CFG80211
4946 ar6k_cfg80211_scanComplete_event(ar, status);
4947 #endif /* ATH6K_CONFIG_CFG80211 */
4949 if (!ar->arUserBssFilter) {
4950 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
4952 if (ar->scan_triggered) {
4954 union iwreq_data wrqu;
4955 A_MEMZERO(&wrqu, sizeof(wrqu));
4956 wireless_send_event(ar->arNetDev, SIOCGIWSCAN, &wrqu, NULL);
4958 ar->scan_triggered = 0;
4961 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,( "AR6000 scan complete: %d\n", status));
4965 ar6000_targetStats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
4969 if(ar->arNetworkType == AP_NETWORK) {
4970 WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr;
4971 WMI_AP_MODE_STAT *ap = &ar->arAPStats;
4973 if (len < sizeof(*p)) {
4977 for(ac=0;ac<AP_MAX_NUM_STA;ac++) {
4978 ap->sta[ac].tx_bytes += p->sta[ac].tx_bytes;
4979 ap->sta[ac].tx_pkts += p->sta[ac].tx_pkts;
4980 ap->sta[ac].tx_error += p->sta[ac].tx_error;
4981 ap->sta[ac].tx_discard += p->sta[ac].tx_discard;
4982 ap->sta[ac].rx_bytes += p->sta[ac].rx_bytes;
4983 ap->sta[ac].rx_pkts += p->sta[ac].rx_pkts;
4984 ap->sta[ac].rx_error += p->sta[ac].rx_error;
4985 ap->sta[ac].rx_discard += p->sta[ac].rx_discard;
4989 WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr;
4990 TARGET_STATS *pStats = &ar->arTargetStats;
4992 if (len < sizeof(*pTarget)) {
4996 // Update the RSSI of the connected bss.
4997 if (ar->arConnected) {
4998 bss_t *pConnBss = NULL;
5000 pConnBss = wmi_find_node(ar->arWmi,ar->arBssid);
5003 pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
5004 pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr;
5005 wmi_node_return(ar->arWmi, pConnBss);
5009 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n"));
5010 pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets;
5011 pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes;
5012 pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts;
5013 pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes;
5014 pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts;
5015 pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes;
5016 pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts;
5017 pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes;
5018 pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt;
5019 for(ac = 0; ac < WMM_NUM_AC; ac++)
5020 pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac];
5021 pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors;
5022 pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt;
5023 pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt;
5024 pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt;
5025 pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt;
5026 pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate);
5028 pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets;
5029 pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes;
5030 pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts;
5031 pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes;
5032 pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts;
5033 pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes;
5034 pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts;
5035 pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes;
5036 pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt;
5037 pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors;
5038 pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr;
5039 pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss;
5040 pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err;
5041 pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames;
5042 pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate);
5045 pStats->tkip_local_mic_failure
5046 += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure;
5047 pStats->tkip_counter_measures_invoked
5048 += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked;
5049 pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays;
5050 pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors;
5051 pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors;
5052 pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays;
5054 pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt;
5055 pStats->noise_floor_calibation = pTarget->noise_floor_calibation;
5057 pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt;
5058 pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt;
5059 pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt;
5060 pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt;
5061 pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr;
5062 pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi;
5064 if (enablerssicompensation) {
5065 pStats->cs_aveBeacon_rssi =
5066 rssi_compensation_calc(ar, pStats->cs_aveBeacon_rssi);
5068 pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec;
5069 pStats->cs_snr = pTarget->cservStats.cs_snr;
5070 pStats->cs_rssi = pTarget->cservStats.cs_rssi;
5072 pStats->lq_val = pTarget->lqVal;
5074 pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped;
5075 pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups;
5076 pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups;
5077 pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded;
5078 pStats->arp_received += pTarget->arpStats.arp_received;
5079 pStats->arp_matched += pTarget->arpStats.arp_matched;
5080 pStats->arp_replied += pTarget->arpStats.arp_replied;
5082 if (ar->statsUpdatePending) {
5083 ar->statsUpdatePending = false;
5090 ar6000_rssiThreshold_event(struct ar6_softc *ar, WMI_RSSI_THRESHOLD_VAL newThreshold, s16 rssi)
5092 USER_RSSI_THOLD userRssiThold;
5094 rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR;
5096 if (enablerssicompensation) {
5097 rssi = rssi_compensation_calc(ar, rssi);
5100 /* Send an event to the app */
5101 userRssiThold.tag = ar->rssi_map[newThreshold].tag;
5102 userRssiThold.rssi = rssi;
5103 A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold,
5104 userRssiThold.tag, userRssiThold.rssi);
5106 ar6000_send_event_to_app(ar, WMI_RSSI_THRESHOLD_EVENTID,(u8 *)&userRssiThold, sizeof(USER_RSSI_THOLD));
5111 ar6000_hbChallengeResp_event(struct ar6_softc *ar, u32 cookie, u32 source)
5113 if (source == APP_HB_CHALLENGE) {
5114 /* Report it to the app in case it wants a positive acknowledgement */
5115 ar6000_send_event_to_app(ar, WMIX_HB_CHALLENGE_RESP_EVENTID,
5116 (u8 *)&cookie, sizeof(cookie));
5118 /* This would ignore the replys that come in after their due time */
5119 if (cookie == ar->arHBChallengeResp.seqNum) {
5120 ar->arHBChallengeResp.outstanding = false;
5127 ar6000_reportError_event(struct ar6_softc *ar, WMI_TARGET_ERROR_VAL errorVal)
5129 static const char * const errString[] = {
5130 [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL",
5131 [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND",
5132 [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR",
5133 [WMI_TARGET_BMISS] "WMI_TARGET_BMISS",
5134 [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN"
5137 A_PRINTF("AR6000 Error on Target. Error = 0x%x\n", errorVal);
5139 /* One error is reported at a time, and errorval is a bitmask */
5140 if(errorVal & (errorVal - 1))
5143 A_PRINTF("AR6000 Error type = ");
5146 case WMI_TARGET_PM_ERR_FAIL:
5147 case WMI_TARGET_KEY_NOT_FOUND:
5148 case WMI_TARGET_DECRYPTION_ERR:
5149 case WMI_TARGET_BMISS:
5150 case WMI_PSDISABLE_NODE_JOIN:
5151 A_PRINTF("%s\n", errString[errorVal]);
5154 A_PRINTF("INVALID\n");
5162 ar6000_cac_event(struct ar6_softc *ar, u8 ac, u8 cacIndication,
5163 u8 statusCode, u8 *tspecSuggestion)
5165 WMM_TSPEC_IE *tspecIe;
5168 * This is the TSPEC IE suggestion from AP.
5169 * Suggestion provided by AP under some error
5170 * cases, could be helpful for the host app.
5171 * Check documentation.
5173 tspecIe = (WMM_TSPEC_IE *)tspecSuggestion;
5176 * What do we do, if we get TSPEC rejection? One thought
5177 * that comes to mind is implictly delete the pstream...
5179 A_PRINTF("AR6000 CAC notification. "
5180 "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n",
5181 ac, cacIndication, statusCode);
5185 ar6000_channel_change_event(struct ar6_softc *ar, u16 oldChannel,
5188 A_PRINTF("Channel Change notification\nOld Channel: %d, New Channel: %d\n",
5189 oldChannel, newChannel);
5192 #define AR6000_PRINT_BSSID(_pBss) do { \
5193 A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\
5194 (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\
5195 (_pBss)[4],(_pBss)[5]); \
5199 ar6000_roam_tbl_event(struct ar6_softc *ar, WMI_TARGET_ROAM_TBL *pTbl)
5203 A_PRINTF("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n",
5204 pTbl->numEntries, pTbl->roamMode);
5205 for (i= 0; i < pTbl->numEntries; i++) {
5206 A_PRINTF("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i,
5207 pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1],
5208 pTbl->bssRoamInfo[i].bssid[2],
5209 pTbl->bssRoamInfo[i].bssid[3],
5210 pTbl->bssRoamInfo[i].bssid[4],
5211 pTbl->bssRoamInfo[i].bssid[5]);
5212 A_PRINTF("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d"
5214 pTbl->bssRoamInfo[i].rssi,
5215 pTbl->bssRoamInfo[i].rssidt,
5216 pTbl->bssRoamInfo[i].last_rssi,
5217 pTbl->bssRoamInfo[i].util,
5218 pTbl->bssRoamInfo[i].roam_util,
5219 pTbl->bssRoamInfo[i].bias);
5224 ar6000_wow_list_event(struct ar6_softc *ar, u8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply)
5228 /*Each event now contains exactly one filter, see bug 26613*/
5229 A_PRINTF("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters);
5230 A_PRINTF("wow mode = %s host mode = %s\n",
5231 (wow_reply->wow_mode == 0? "disabled":"enabled"),
5232 (wow_reply->host_mode == 1 ? "awake":"asleep"));
5235 /*If there are no patterns, the reply will only contain generic
5236 WoW information. Pattern information will exist only if there are
5237 patterns present. Bug 26716*/
5239 /* If this event contains pattern information, display it*/
5240 if (wow_reply->this_filter_num) {
5242 A_PRINTF("id=%d size=%d offset=%d\n",
5243 wow_reply->wow_filters[i].wow_filter_id,
5244 wow_reply->wow_filters[i].wow_filter_size,
5245 wow_reply->wow_filters[i].wow_filter_offset);
5246 A_PRINTF("wow pattern = ");
5247 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5248 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j]);
5251 A_PRINTF("\nwow mask = ");
5252 for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) {
5253 A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j]);
5260 * Report the Roaming related data collected on the target
5263 ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p)
5265 A_PRINTF("Disconnect Data : BSSID: ");
5266 AR6000_PRINT_BSSID(p->disassoc_bssid);
5267 A_PRINTF(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n",
5268 p->disassoc_bss_rssi,p->disassoc_time,
5270 A_PRINTF("Connect Data: BSSID: ");
5271 AR6000_PRINT_BSSID(p->assoc_bssid);
5272 A_PRINTF(" RSSI %d ASSOC Time %d TXRX_TIME %d\n",
5273 p->assoc_bss_rssi,p->assoc_time,
5274 p->allow_txrx_time);
5278 ar6000_roam_data_event(struct ar6_softc *ar, WMI_TARGET_ROAM_DATA *p)
5280 switch (p->roamDataType) {
5281 case ROAM_DATA_TIME:
5282 ar6000_display_roam_time(&p->u.roamTime);
5290 ar6000_bssInfo_event_rx(struct ar6_softc *ar, u8 *datap, int len)
5292 struct sk_buff *skb;
5293 WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap;
5296 if (!ar->arMgmtFilter) {
5299 if (((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) &&
5300 (bih->frameType != BEACON_FTYPE)) ||
5301 ((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) &&
5302 (bih->frameType != PROBERESP_FTYPE)))
5307 if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) {
5309 A_NETBUF_PUT(skb, len);
5310 memcpy(A_NETBUF_DATA(skb), datap, len);
5311 skb->dev = ar->arNetDev;
5312 memcpy(skb_mac_header(skb), A_NETBUF_DATA(skb), 6);
5313 skb->ip_summed = CHECKSUM_NONE;
5314 skb->pkt_type = PACKET_OTHERHOST;
5315 skb->protocol = __constant_htons(0x0019);
5323 ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid)
5325 struct ar6_softc *ar = (struct ar6_softc *)devt;
5327 struct ar_cookie *cookie = NULL;
5330 if (ar->arWowState != WLAN_WOW_STATE_NONE) {
5331 A_NETBUF_FREE(osbuf);
5334 #endif /* CONFIG_PM */
5335 /* take lock to protect ar6000_alloc_cookie() */
5336 AR6000_SPIN_LOCK(&ar->arLock, 0);
5340 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%lx, len=0x%x eid =%d\n",
5341 (unsigned long)osbuf, A_NETBUF_LEN(osbuf), eid));
5343 if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) {
5344 /* control endpoint is full, don't allocate resources, we
5345 * are just going to drop this packet */
5347 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%lX, len:%d \n",
5348 (unsigned long)osbuf, A_NETBUF_LEN(osbuf)));
5350 cookie = ar6000_alloc_cookie(ar);
5353 if (cookie == NULL) {
5354 status = A_NO_MEMORY;
5359 A_PRINTF("WMI cmd send, msgNo %d :", wmiSendCmdNum);
5360 for(i = 0; i < a_netbuf_to_len(osbuf); i++)
5361 A_PRINTF("%x ", ((u8 *)a_netbuf_to_data(osbuf))[i]);
5369 if (cookie != NULL) {
5370 /* got a structure to send it out on */
5371 ar->arTxPending[eid]++;
5373 if (eid != ar->arControlEp) {
5374 ar->arTotalTxDataPending++;
5378 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5380 if (cookie != NULL) {
5381 cookie->arc_bp[0] = (unsigned long)osbuf;
5382 cookie->arc_bp[1] = 0;
5383 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
5385 A_NETBUF_DATA(osbuf),
5386 A_NETBUF_LEN(osbuf),
5388 AR6K_CONTROL_PKT_TAG);
5389 /* this interface is asynchronous, if there is an error, cleanup will happen in the
5390 * TX completion callback */
5391 HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt);
5396 A_NETBUF_FREE(osbuf);
5401 /* indicate tx activity or inactivity on a WMI stream */
5402 void ar6000_indicate_tx_activity(void *devt, u8 TrafficClass, bool Active)
5404 struct ar6_softc *ar = (struct ar6_softc *)devt;
5405 HTC_ENDPOINT_ID eid ;
5408 if (ar->arWmiEnabled) {
5409 eid = arAc2EndpointID(ar, TrafficClass);
5411 AR6000_SPIN_LOCK(&ar->arLock, 0);
5413 ar->arAcStreamActive[TrafficClass] = Active;
5416 /* when a stream goes active, keep track of the active stream with the highest priority */
5418 if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) {
5419 /* set the new highest active priority */
5420 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass];
5424 /* when a stream goes inactive, we may have to search for the next active stream
5425 * that is the highest priority */
5427 if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) {
5429 /* the highest priority stream just went inactive */
5431 /* reset and search for the "next" highest "active" priority stream */
5432 ar->arHiAcStreamActivePri = 0;
5433 for (i = 0; i < WMM_NUM_AC; i++) {
5434 if (ar->arAcStreamActive[i]) {
5435 if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) {
5436 /* set the new highest active priority */
5437 ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i];
5444 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
5447 /* for mbox ping testing, the traffic class is mapped directly as a stream ID,
5448 * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c
5449 * convert the stream ID to a endpoint */
5450 eid = arAc2EndpointID(ar, TrafficClass);
5453 /* notify HTC, this may cause credit distribution changes */
5455 HTCIndicateActivityChange(ar->arHtcTarget,
5462 ar6000_btcoex_config_event(struct ar6_softc *ar, u8 *ptr, u32 len)
5465 WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr;
5466 WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&ar->arBtcoexConfig;
5468 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5470 A_PRINTF("received config event\n");
5471 pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType;
5472 pArbtcoexConfig->linkId = pBtcoexConfig->linkId;
5474 switch (pBtcoexConfig->btProfileType) {
5475 case WMI_BTCOEX_BT_PROFILE_SCO:
5476 memcpy(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd,
5477 sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD));
5479 case WMI_BTCOEX_BT_PROFILE_A2DP:
5480 memcpy(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd,
5481 sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD));
5483 case WMI_BTCOEX_BT_PROFILE_ACLCOEX:
5484 memcpy(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig,
5485 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5487 case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE:
5488 memcpy(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd,
5489 sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD));
5492 if (ar->statsUpdatePending) {
5493 ar->statsUpdatePending = false;
5499 ar6000_btcoex_stats_event(struct ar6_softc *ar, u8 *ptr, u32 len)
5501 WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr;
5503 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n"));
5505 memcpy(&ar->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT));
5507 if (ar->statsUpdatePending) {
5508 ar->statsUpdatePending = false;
5513 module_init(ar6000_init_module);
5514 module_exit(ar6000_cleanup_module);
5516 /* Init cookie queue */
5518 ar6000_cookie_init(struct ar6_softc *ar)
5522 ar->arCookieList = NULL;
5523 ar->arCookieCount = 0;
5525 A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem));
5527 for (i = 0; i < MAX_COOKIE_NUM; i++) {
5528 ar6000_free_cookie(ar, &s_ar_cookie_mem[i]);
5532 /* cleanup cookie queue */
5534 ar6000_cookie_cleanup(struct ar6_softc *ar)
5536 /* It is gone .... */
5537 ar->arCookieList = NULL;
5538 ar->arCookieCount = 0;
5541 /* Init cookie queue */
5543 ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie)
5546 A_ASSERT(ar != NULL);
5547 A_ASSERT(cookie != NULL);
5549 cookie->arc_list_next = ar->arCookieList;
5550 ar->arCookieList = cookie;
5551 ar->arCookieCount++;
5554 /* cleanup cookie queue */
5555 static struct ar_cookie *
5556 ar6000_alloc_cookie(struct ar6_softc *ar)
5558 struct ar_cookie *cookie;
5560 cookie = ar->arCookieList;
5563 ar->arCookieList = cookie->arc_list_next;
5564 ar->arCookieCount--;
5570 #ifdef SEND_EVENT_TO_APP
5572 * This function is used to send event which come from taget to
5573 * the application. The buf which send to application is include
5574 * the event ID and event content.
5576 #define EVENT_ID_LEN 2
5577 void ar6000_send_event_to_app(struct ar6_softc *ar, u16 eventId,
5581 #if (WIRELESS_EXT >= 15)
5583 /* note: IWEVCUSTOM only exists in wireless extensions after version 15 */
5587 union iwreq_data wrqu;
5589 size = len + EVENT_ID_LEN;
5591 if (size > IW_CUSTOM_MAX) {
5592 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVCUSTOM (max=%d) \n",
5593 eventId, size, IW_CUSTOM_MAX));
5597 buf = A_MALLOC_NOWAIT(size);
5599 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size));
5603 A_MEMZERO(buf, size);
5604 memcpy(buf, &eventId, EVENT_ID_LEN);
5605 memcpy(buf+EVENT_ID_LEN, datap, len);
5607 //AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("event ID = %d,len = %d\n",*(u16 *)buf, size));
5608 A_MEMZERO(&wrqu, sizeof(wrqu));
5609 wrqu.data.length = size;
5610 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
5618 * This function is used to send events larger than 256 bytes
5619 * to the application. The buf which is sent to application
5620 * includes the event ID and event content.
5622 void ar6000_send_generic_event_to_app(struct ar6_softc *ar, u16 eventId,
5626 #if (WIRELESS_EXT >= 18)
5628 /* IWEVGENIE exists in wireless extensions version 18 onwards */
5632 union iwreq_data wrqu;
5634 size = len + EVENT_ID_LEN;
5636 if (size > IW_GENERIC_IE_MAX) {
5637 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVGENIE (max=%d) \n",
5638 eventId, size, IW_GENERIC_IE_MAX));
5642 buf = A_MALLOC_NOWAIT(size);
5644 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size));
5648 A_MEMZERO(buf, size);
5649 memcpy(buf, &eventId, EVENT_ID_LEN);
5650 memcpy(buf+EVENT_ID_LEN, datap, len);
5652 A_MEMZERO(&wrqu, sizeof(wrqu));
5653 wrqu.data.length = size;
5654 wireless_send_event(ar->arNetDev, IWEVGENIE, &wrqu, buf);
5658 #endif /* (WIRELESS_EXT >= 18) */
5661 #endif /* SEND_EVENT_TO_APP */
5665 ar6000_tx_retry_err_event(void *devt)
5667 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n"));
5671 ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, u8 snr)
5673 WMI_SNR_THRESHOLD_EVENT event;
5674 struct ar6_softc *ar = (struct ar6_softc *)devt;
5676 event.range = newThreshold;
5679 ar6000_send_event_to_app(ar, WMI_SNR_THRESHOLD_EVENTID, (u8 *)&event,
5680 sizeof(WMI_SNR_THRESHOLD_EVENT));
5684 ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, u8 lq)
5686 AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq));
5691 u32 a_copy_to_user(void *to, const void *from, u32 n)
5693 return(copy_to_user(to, from, n));
5696 u32 a_copy_from_user(void *to, const void *from, u32 n)
5698 return(copy_from_user(to, from, n));
5703 ar6000_get_driver_cfg(struct net_device *dev,
5712 case AR6000_DRIVER_CFG_GET_WLANNODECACHING:
5713 *((u32 *)result) = wlanNodeCaching;
5715 case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS:
5716 *((u32 *)result) = logWmiRawMsgs;
5727 ar6000_keepalive_rx(void *devt, u8 configured)
5729 struct ar6_softc *ar = (struct ar6_softc *)devt;
5731 ar->arKeepaliveConfigured = configured;
5736 ar6000_pmkid_list_event(void *devt, u8 numPMKID, WMI_PMKID *pmkidList,
5741 A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID);
5743 for (i = 0; i < numPMKID; i++) {
5744 A_PRINTF("\nBSSID %d ", i);
5745 for (j = 0; j < ATH_MAC_LEN; j++) {
5746 A_PRINTF("%2.2x", bssidList[j]);
5748 bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN);
5749 A_PRINTF("\nPMKID %d ", i);
5750 for (j = 0; j < WMI_PMKID_LEN; j++) {
5751 A_PRINTF("%2.2x", pmkidList->pmkid[j]);
5753 pmkidList = (WMI_PMKID *)((u8 *)pmkidList + ATH_MAC_LEN +
5758 void ar6000_pspoll_event(struct ar6_softc *ar,u8 aid)
5761 bool isPsqEmpty = false;
5763 conn = ieee80211_find_conn_for_aid(ar, aid);
5765 /* If the PS q for this STA is not empty, dequeue and send a pkt from
5766 * the head of the q. Also update the More data bit in the WMI_DATA_HDR
5767 * if there are more pkts for this STA in the PS q. If there are no more
5768 * pkts for this STA, update the PVB for this STA.
5770 A_MUTEX_LOCK(&conn->psqLock);
5771 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5772 A_MUTEX_UNLOCK(&conn->psqLock);
5775 /* TODO:No buffered pkts for this STA. Send out a NULL data frame */
5777 struct sk_buff *skb = NULL;
5779 A_MUTEX_LOCK(&conn->psqLock);
5780 skb = A_NETBUF_DEQUEUE(&conn->psq);
5781 A_MUTEX_UNLOCK(&conn->psqLock);
5782 /* Set the STA flag to PSPolled, so that the frame will go out */
5783 STA_SET_PS_POLLED(conn);
5784 ar6000_data_tx(skb, ar->arNetDev);
5785 STA_CLR_PS_POLLED(conn);
5787 /* Clear the PVB for this STA if the queue has become empty */
5788 A_MUTEX_LOCK(&conn->psqLock);
5789 isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq);
5790 A_MUTEX_UNLOCK(&conn->psqLock);
5793 wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0);
5798 void ar6000_dtimexpiry_event(struct ar6_softc *ar)
5800 bool isMcastQueued = false;
5801 struct sk_buff *skb = NULL;
5803 /* If there are no associated STAs, ignore the DTIM expiry event.
5804 * There can be potential race conditions where the last associated
5805 * STA may disconnect & before the host could clear the 'Indicate DTIM'
5806 * request to the firmware, the firmware would have just indicated a DTIM
5807 * expiry event. The race is between 'clear DTIM expiry cmd' going
5808 * from the host to the firmware & the DTIM expiry event happening from
5809 * the firmware to the host.
5811 if (ar->sta_list_index == 0) {
5815 A_MUTEX_LOCK(&ar->mcastpsqLock);
5816 isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq);
5817 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5819 A_ASSERT(isMcastQueued == false);
5821 /* Flush the mcast psq to the target */
5822 /* Set the STA flag to DTIMExpired, so that the frame will go out */
5823 ar->DTIMExpired = true;
5825 A_MUTEX_LOCK(&ar->mcastpsqLock);
5826 while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) {
5827 skb = A_NETBUF_DEQUEUE(&ar->mcastpsq);
5828 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5830 ar6000_data_tx(skb, ar->arNetDev);
5832 A_MUTEX_LOCK(&ar->mcastpsqLock);
5834 A_MUTEX_UNLOCK(&ar->mcastpsqLock);
5836 /* Reset the DTIMExpired flag back to 0 */
5837 ar->DTIMExpired = false;
5839 /* Clear the LSB of the BitMapCtl field of the TIM IE */
5840 wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0);
5844 read_rssi_compensation_param(struct ar6_softc *ar)
5848 //#define RSSICOMPENSATION_PRINT
5850 #ifdef RSSICOMPENSATION_PRINT
5852 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5853 for (i=0; i<16; i++) {
5854 A_PRINTF("cust_data_%d = %x \n", i, *(u8 *)cust_data_ptr);
5859 cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType);
5861 rssi_compensation_param.customerID = *(u16 *)cust_data_ptr & 0xffff;
5862 rssi_compensation_param.enable = *(u16 *)(cust_data_ptr+2) & 0xffff;
5863 rssi_compensation_param.bg_param_a = *(u16 *)(cust_data_ptr+4) & 0xffff;
5864 rssi_compensation_param.bg_param_b = *(u16 *)(cust_data_ptr+6) & 0xffff;
5865 rssi_compensation_param.a_param_a = *(u16 *)(cust_data_ptr+8) & 0xffff;
5866 rssi_compensation_param.a_param_b = *(u16 *)(cust_data_ptr+10) &0xffff;
5867 rssi_compensation_param.reserved = *(u32 *)(cust_data_ptr+12);
5869 #ifdef RSSICOMPENSATION_PRINT
5870 A_PRINTF("customerID = 0x%x \n", rssi_compensation_param.customerID);
5871 A_PRINTF("enable = 0x%x \n", rssi_compensation_param.enable);
5872 A_PRINTF("bg_param_a = 0x%x and %d \n", rssi_compensation_param.bg_param_a, rssi_compensation_param.bg_param_a);
5873 A_PRINTF("bg_param_b = 0x%x and %d \n", rssi_compensation_param.bg_param_b, rssi_compensation_param.bg_param_b);
5874 A_PRINTF("a_param_a = 0x%x and %d \n", rssi_compensation_param.a_param_a, rssi_compensation_param.a_param_a);
5875 A_PRINTF("a_param_b = 0x%x and %d \n", rssi_compensation_param.a_param_b, rssi_compensation_param.a_param_b);
5876 A_PRINTF("Last 4 bytes = 0x%x \n", rssi_compensation_param.reserved);
5879 if (rssi_compensation_param.enable != 0x1) {
5880 rssi_compensation_param.enable = 0;
5886 s32 rssi_compensation_calc_tcmd(u32 freq, s32 rssi, u32 totalPkt)
5891 if (rssi_compensation_param.enable)
5893 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5894 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5895 rssi = rssi * rssi_compensation_param.a_param_a + totalPkt * rssi_compensation_param.a_param_b;
5896 rssi = (rssi-50) /100;
5897 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5902 if (rssi_compensation_param.enable)
5904 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5905 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt));
5906 rssi = rssi * rssi_compensation_param.bg_param_a + totalPkt * rssi_compensation_param.bg_param_b;
5907 rssi = (rssi-50) /100;
5908 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5915 s16 rssi_compensation_calc(struct ar6_softc *ar, s16 rssi)
5917 if (ar->arBssChannel > 5000)
5919 if (rssi_compensation_param.enable)
5921 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5922 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5923 rssi = rssi * rssi_compensation_param.a_param_a + rssi_compensation_param.a_param_b;
5924 rssi = (rssi-50) /100;
5925 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5930 if (rssi_compensation_param.enable)
5932 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5933 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi));
5934 rssi = rssi * rssi_compensation_param.bg_param_a + rssi_compensation_param.bg_param_b;
5935 rssi = (rssi-50) /100;
5936 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi));
5943 s16 rssi_compensation_reverse_calc(struct ar6_softc *ar, s16 rssi, bool Above)
5947 if (ar->arBssChannel > 5000)
5949 if (rssi_compensation_param.enable)
5951 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n"));
5952 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5954 rssi = (rssi - rssi_compensation_param.a_param_b) / rssi_compensation_param.a_param_a;
5955 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5960 if (rssi_compensation_param.enable)
5962 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n"));
5963 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi));
5966 for (i=95; i>=0; i--) {
5967 if (rssi <= rssi_compensation_table[i]) {
5973 for (i=0; i<=95; i++) {
5974 if (rssi >= rssi_compensation_table[i]) {
5980 AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi));
5988 void ap_wapi_rekey_event(struct ar6_softc *ar, u8 type, u8 *mac)
5990 union iwreq_data wrqu;
5993 A_MEMZERO(buf, sizeof(buf));
5995 strcpy(buf, "WAPI_REKEY");
5997 memcpy(&buf[11], mac, ATH_MAC_LEN);
5999 A_MEMZERO(&wrqu, sizeof(wrqu));
6000 wrqu.data.length = 10+1+ATH_MAC_LEN;
6001 wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf);
6003 A_PRINTF("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5]);
6010 ar6000_reinstall_keys(struct ar6_softc *ar, u8 key_op_ctrl)
6013 struct ieee80211req_key *uik = &ar->user_saved_keys.ucast_ik;
6014 struct ieee80211req_key *bik = &ar->user_saved_keys.bcast_ik;
6015 CRYPTO_TYPE keyType = ar->user_saved_keys.keyType;
6017 if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) {
6018 if (NONE_CRYPT == keyType) {
6019 goto _reinstall_keys_out;
6022 if (uik->ik_keylen) {
6023 status = wmi_addKey_cmd(ar->arWmi, uik->ik_keyix,
6024 ar->user_saved_keys.keyType, PAIRWISE_USAGE,
6025 uik->ik_keylen, (u8 *)&uik->ik_keyrsc,
6026 uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG);
6030 status = wmi_add_krk_cmd(ar->arWmi, uik->ik_keydata);
6033 if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) {
6034 if (NONE_CRYPT == keyType) {
6035 goto _reinstall_keys_out;
6038 if (bik->ik_keylen) {
6039 status = wmi_addKey_cmd(ar->arWmi, bik->ik_keyix,
6040 ar->user_saved_keys.keyType, GROUP_USAGE,
6041 bik->ik_keylen, (u8 *)&bik->ik_keyrsc,
6042 bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG);
6045 status = wmi_add_krk_cmd(ar->arWmi, bik->ik_keydata);
6048 _reinstall_keys_out:
6049 ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT;
6050 ar->user_key_ctrl = 0;
6054 #endif /* USER_KEYS */
6058 ar6000_dset_open_req(
6076 ar6000_dset_data_req(
6088 ar6000_ap_mode_profile_commit(struct ar6_softc *ar)
6091 unsigned long flags;
6093 /* No change in AP's profile configuration */
6094 if(ar->ap_profile_flag==0) {
6095 A_PRINTF("COMMIT: No change in profile!!!\n");
6099 if(!ar->arSsidLen) {
6100 A_PRINTF("SSID not set!!!\n");
6104 switch(ar->arAuthMode) {
6106 if((ar->arPairwiseCrypto != NONE_CRYPT) &&
6108 (ar->arPairwiseCrypto != WAPI_CRYPT) &&
6110 (ar->arPairwiseCrypto != WEP_CRYPT)) {
6111 A_PRINTF("Cipher not supported in AP mode Open auth\n");
6117 case (WPA_PSK_AUTH|WPA2_PSK_AUTH):
6120 A_PRINTF("This key mgmt type not supported in AP mode\n");
6124 /* Update the arNetworkType */
6125 ar->arNetworkType = ar->arNextMode;
6127 A_MEMZERO(&p,sizeof(p));
6128 p.ssidLength = ar->arSsidLen;
6129 memcpy(p.ssid,ar->arSsid,p.ssidLength);
6130 p.channel = ar->arChannelHint;
6131 p.networkType = ar->arNetworkType;
6133 p.dot11AuthMode = ar->arDot11AuthMode;
6134 p.authMode = ar->arAuthMode;
6135 p.pairwiseCryptoType = ar->arPairwiseCrypto;
6136 p.pairwiseCryptoLen = ar->arPairwiseCryptoLen;
6137 p.groupCryptoType = ar->arGroupCrypto;
6138 p.groupCryptoLen = ar->arGroupCryptoLen;
6139 p.ctrl_flags = ar->arConnectCtrlFlags;
6141 wmi_ap_profile_commit(ar->arWmi, &p);
6142 spin_lock_irqsave(&ar->arLock, flags);
6143 ar->arConnected = true;
6144 netif_carrier_on(ar->arNetDev);
6145 spin_unlock_irqrestore(&ar->arLock, flags);
6146 ar->ap_profile_flag = 0;
6151 ar6000_connect_to_ap(struct ar6_softc *ar)
6153 /* The ssid length check prevents second "essid off" from the user,
6154 to be treated as a connect cmd. The second "essid off" is ignored.
6156 if((ar->arWmiReady == true) && (ar->arSsidLen > 0) && ar->arNetworkType!=AP_NETWORK)
6159 if((ADHOC_NETWORK != ar->arNetworkType) &&
6160 (NONE_AUTH==ar->arAuthMode) &&
6161 (WEP_CRYPT==ar->arPairwiseCrypto)) {
6162 ar6000_install_static_wep_keys(ar);
6165 if (!ar->arUserBssFilter) {
6166 if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != 0) {
6171 if (ar->arWapiEnable) {
6172 ar->arPairwiseCrypto = WAPI_CRYPT;
6173 ar->arPairwiseCryptoLen = 0;
6174 ar->arGroupCrypto = WAPI_CRYPT;
6175 ar->arGroupCryptoLen = 0;
6176 ar->arAuthMode = NONE_AUTH;
6177 ar->arConnectCtrlFlags |= CONNECT_IGNORE_WPAx_GROUP_CIPHER;
6180 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\
6181 " PW crypto %d PW crypto Len %d GRP crypto %d"\
6182 " GRP crypto Len %d\n",
6183 ar->arAuthMode, ar->arDot11AuthMode,
6184 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
6185 ar->arGroupCrypto, ar->arGroupCryptoLen));
6187 /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn.
6188 later set it back locally at the STA to 100/1000 TUs depending on the power mode */
6189 if ((ar->arNetworkType == INFRA_NETWORK)) {
6190 wmi_listeninterval_cmd(ar->arWmi, max(ar->arListenIntervalT, (u16)A_MAX_WOW_LISTEN_INTERVAL), 0);
6192 status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType,
6193 ar->arDot11AuthMode, ar->arAuthMode,
6194 ar->arPairwiseCrypto, ar->arPairwiseCryptoLen,
6195 ar->arGroupCrypto,ar->arGroupCryptoLen,
6196 ar->arSsidLen, ar->arSsid,
6197 ar->arReqBssid, ar->arChannelHint,
6198 ar->arConnectCtrlFlags);
6200 wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB);
6201 if (!ar->arUserBssFilter) {
6202 wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0);
6207 if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) &&
6208 ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)))
6210 A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0);
6213 ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD;
6215 ar->arConnectPending = true;
6222 ar6000_disconnect(struct ar6_softc *ar)
6224 if ((ar->arConnected == true) || (ar->arConnectPending == true)) {
6225 wmi_disconnect_cmd(ar->arWmi);
6227 * Disconnect cmd is issued, clear connectPending.
6228 * arConnected will be cleard in disconnect_event notification.
6230 ar->arConnectPending = false;
6237 ar6000_ap_mode_get_wpa_ie(struct ar6_softc *ar, struct ieee80211req_wpaie *wpaie)
6240 conn = ieee80211_find_conn(ar, wpaie->wpa_macaddr);
6242 A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE);
6243 A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE);
6246 memcpy(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE);
6253 is_iwioctl_allowed(u8 mode, u16 cmd)
6255 if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) {
6256 cmd -= SIOCSIWCOMMIT;
6257 if(sioctl_filter[cmd] == 0xFF) return 0;
6258 if(sioctl_filter[cmd] & mode) return 0;
6259 } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) {
6260 cmd -= SIOCIWFIRSTPRIV;
6261 if(pioctl_filter[cmd] == 0xFF) return 0;
6262 if(pioctl_filter[cmd] & mode) return 0;
6270 is_xioctl_allowed(u8 mode, int cmd)
6272 if(sizeof(xioctl_filter)-1 < cmd) {
6273 A_PRINTF("Filter for this cmd=%d not defined\n",cmd);
6276 if(xioctl_filter[cmd] == 0xFF) return 0;
6277 if(xioctl_filter[cmd] & mode) return 0;
6283 ap_set_wapi_key(struct ar6_softc *ar, void *ikey)
6285 struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey;
6286 KEY_USAGE keyUsage = 0;
6289 if (memcmp(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) {
6290 keyUsage = GROUP_USAGE;
6292 keyUsage = PAIRWISE_USAGE;
6294 A_PRINTF("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n",
6295 keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5],
6298 status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage,
6299 ik->ik_keylen, (u8 *)&ik->ik_keyrsc,
6300 ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr,
6310 void ar6000_peer_event(
6317 for (pos=0;pos<6;pos++)
6318 printk("%02x: ",*(macAddr+pos));
6322 #ifdef HTC_TEST_SEND_PKTS
6323 #define HTC_TEST_DUPLICATE 8
6324 static void DoHTCSendPktsTest(struct ar6_softc *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb)
6326 struct ar_cookie *cookie;
6327 struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE];
6328 struct sk_buff *new_skb;
6331 struct htc_packet_queue pktQueue;
6332 EPPING_HEADER *eppingHdr;
6334 eppingHdr = A_NETBUF_DATA(dupskb);
6336 if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) {
6337 /* skip test if this is already a tx perf test */
6341 for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) {
6342 AR6000_SPIN_LOCK(&ar->arLock, 0);
6343 cookie = ar6000_alloc_cookie(ar);
6344 if (cookie != NULL) {
6345 ar->arTxPending[eid]++;
6346 ar->arTotalTxDataPending++;
6349 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6351 if (NULL == cookie) {
6355 new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb));
6357 if (new_skb == NULL) {
6358 AR6000_SPIN_LOCK(&ar->arLock, 0);
6359 ar6000_free_cookie(ar,cookie);
6360 AR6000_SPIN_UNLOCK(&ar->arLock, 0);
6364 A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb));
6365 cookie->arc_bp[0] = (unsigned long)new_skb;
6366 cookie->arc_bp[1] = MapNo;
6367 SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt,
6369 A_NETBUF_DATA(new_skb),
6370 A_NETBUF_LEN(new_skb),
6374 cookieArray[i] = cookie;
6377 EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb);
6378 pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */
6386 INIT_HTC_PACKET_QUEUE(&pktQueue);
6388 for (i = 0; i < pkts; i++) {
6389 HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt);
6392 HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue);
6397 #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT
6399 * Add support for adding and removing a virtual adapter for soft AP.
6400 * Some OS requires different adapters names for station and soft AP mode.
6401 * To support these requirement, create and destory a netdevice instance
6402 * when the AP mode is operational. A full fledged support for virual device
6403 * is not implemented. Rather a virtual interface is created and is linked
6404 * with the existing physical device instance during the operation of the
6408 int ar6000_start_ap_interface(struct ar6_softc *ar)
6410 struct ar_virtual_interface *arApDev;
6412 /* Change net_device to point to AP instance */
6413 arApDev = (struct ar_virtual_interface *)ar->arApDev;
6414 ar->arNetDev = arApDev->arNetDev;
6419 int ar6000_stop_ap_interface(struct ar6_softc *ar)
6421 struct ar_virtual_interface *arApDev;
6423 /* Change net_device to point to sta instance */
6424 arApDev = (struct ar_virtual_interface *)ar->arApDev;
6426 ar->arNetDev = arApDev->arStaNetDev;
6433 int ar6000_create_ap_interface(struct ar6_softc *ar, char *ap_ifname)
6435 struct net_device *dev;
6436 struct ar_virtual_interface *arApDev;
6438 dev = alloc_etherdev(sizeof(struct ar_virtual_interface));
6440 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: can't alloc etherdev\n"));
6445 init_netdev(dev, ap_ifname);
6447 if (register_netdev(dev)) {
6448 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: register_netdev failed\n"));
6452 arApDev = netdev_priv(dev);
6453 arApDev->arDev = ar;
6454 arApDev->arNetDev = dev;
6455 arApDev->arStaNetDev = ar->arNetDev;
6457 ar->arApDev = arApDev;
6460 /* Copy the MAC address */
6461 memcpy(dev->dev_addr, ar->arNetDev->dev_addr, AR6000_ETH_ADDR_LEN);
6466 int ar6000_add_ap_interface(struct ar6_softc *ar, char *ap_ifname)
6468 /* Interface already added, need not proceed further */
6469 if (ar->arApDev != NULL) {
6470 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_add_ap_interface: interface already present \n"));
6474 if (ar6000_create_ap_interface(ar, ap_ifname) != 0) {
6478 A_PRINTF("Add AP interface %s \n",ap_ifname);
6480 return ar6000_start_ap_interface(ar);
6483 int ar6000_remove_ap_interface(struct ar6_softc *ar)
6486 ar6000_stop_ap_interface(ar);
6488 unregister_netdev(arApNetDev);
6489 free_netdev(apApNetDev);
6491 A_PRINTF("Remove AP interface\n");
6499 #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */
6502 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
6503 EXPORT_SYMBOL(setupbtdev);