]>
Commit | Line | Data |
---|---|---|
30295c89 VM |
1 | //------------------------------------------------------------------------------ |
2 | // Copyright (c) 2004-2010 Atheros Communications Inc. | |
3 | // All rights reserved. | |
4 | // | |
5 | // | |
6 | // | |
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. | |
10 | // | |
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. | |
18 | // | |
19 | // | |
20 | // | |
21 | // Author(s): ="Atheros" | |
22 | //------------------------------------------------------------------------------ | |
23 | ||
24 | /* | |
25 | * This driver is a pseudo ethernet driver to access the Atheros AR6000 | |
26 | * WLAN Device | |
27 | */ | |
28 | ||
29 | #include "ar6000_drv.h" | |
30 | #ifdef ATH6K_CONFIG_CFG80211 | |
31 | #include "cfg80211.h" | |
32 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
33 | #include "htc.h" | |
34 | #include "wmi_filter_linux.h" | |
35 | #include "epping_test.h" | |
36 | #include "wlan_config.h" | |
37 | #include "ar3kconfig.h" | |
38 | #include "ar6k_pal.h" | |
39 | #include "AR6002/addrs.h" | |
40 | ||
41 | ||
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 | |
49 | ||
50 | A_UINT8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | |
51 | A_UINT8 null_mac[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; | |
52 | ||
53 | #ifdef DEBUG | |
54 | ||
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) | |
62 | ||
63 | static ATH_DEBUG_MASK_DESCRIPTION driver_debug_desc[] = { | |
64 | { ATH_DEBUG_DBG_LOG , "Target Debug Logs"}, | |
65 | { ATH_DEBUG_WLAN_CONNECT , "WLAN connect"}, | |
66 | { ATH_DEBUG_WLAN_SCAN , "WLAN scan"}, | |
67 | { ATH_DEBUG_WLAN_TX , "WLAN Tx"}, | |
68 | { ATH_DEBUG_WLAN_RX , "WLAN Rx"}, | |
69 | { ATH_DEBUG_HTC_RAW , "HTC Raw IF tracing"}, | |
70 | { ATH_DEBUG_HCI_BRIDGE , "HCI Bridge Setup"}, | |
71 | { ATH_DEBUG_HCI_RECV , "HCI Recv tracing"}, | |
72 | { ATH_DEBUG_HCI_DUMP , "HCI Packet dumps"}, | |
73 | }; | |
74 | ||
75 | ATH_DEBUG_INSTANTIATE_MODULE_VAR(driver, | |
76 | "driver", | |
77 | "Linux Driver Interface", | |
78 | ATH_DEBUG_MASK_DEFAULTS | ATH_DEBUG_WLAN_SCAN | | |
79 | ATH_DEBUG_HCI_BRIDGE, | |
80 | ATH_DEBUG_DESCRIPTION_COUNT(driver_debug_desc), | |
81 | driver_debug_desc); | |
82 | ||
83 | #endif | |
84 | ||
85 | ||
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) | |
88 | ||
89 | #define DESCRIPTION "Driver to access the Atheros AR600x Device, version " __stringify(__VER_MAJOR_) "." __stringify(__VER_MINOR_) "." __stringify(__VER_PATCH_) "." __stringify(__BUILD_NUMBER_) | |
90 | ||
91 | MODULE_AUTHOR("Atheros Communications, Inc."); | |
92 | MODULE_DESCRIPTION(DESCRIPTION); | |
93 | MODULE_LICENSE("Dual BSD/GPL"); | |
94 | ||
95 | #ifndef REORG_APTC_HEURISTICS | |
96 | #undef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
97 | #endif /* REORG_APTC_HEURISTICS */ | |
98 | ||
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 */ | |
103 | ||
104 | typedef struct aptc_traffic_record { | |
105 | A_BOOL timerScheduled; | |
106 | struct timeval samplingTS; | |
107 | unsigned long bytesReceived; | |
108 | unsigned long bytesTransmitted; | |
109 | } APTC_TRAFFIC_RECORD; | |
110 | ||
111 | A_TIMER aptcTimer; | |
112 | APTC_TRAFFIC_RECORD aptcTR; | |
113 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
114 | ||
115 | #ifdef EXPORT_HCI_BRIDGE_INTERFACE | |
116 | // callbacks registered by HCI transport driver | |
117 | HCI_TRANSPORT_CALLBACKS ar6kHciTransCallbacks = { NULL }; | |
118 | #endif | |
119 | ||
120 | unsigned int processDot11Hdr = 0; | |
121 | int bmienable = BMIENABLE_DEFAULT; | |
122 | ||
123 | char ifname[IFNAMSIZ] = {0,}; | |
124 | ||
125 | int wlaninitmode = WLAN_INIT_MODE_DEFAULT; | |
126 | unsigned int bypasswmi = 0; | |
127 | unsigned int debuglevel = 0; | |
128 | int tspecCompliance = ATHEROS_COMPLIANCE; | |
129 | unsigned int busspeedlow = 0; | |
130 | unsigned int onebitmode = 0; | |
131 | unsigned int skipflash = 0; | |
132 | unsigned int wmitimeout = 2; | |
133 | unsigned int wlanNodeCaching = 1; | |
134 | unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT; | |
135 | unsigned int logWmiRawMsgs = 0; | |
136 | unsigned int enabletimerwar = 0; | |
137 | unsigned int fwmode = 1; | |
138 | unsigned int mbox_yield_limit = 99; | |
139 | unsigned int enablerssicompensation = 0; | |
140 | int reduce_credit_dribble = 1 + HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_ONE_HALF; | |
141 | int allow_trace_signal = 0; | |
142 | #ifdef CONFIG_HOST_TCMD_SUPPORT | |
143 | unsigned int testmode =0; | |
144 | #endif | |
145 | ||
146 | unsigned int irqprocmode = HIF_DEVICE_IRQ_SYNC_ONLY;//HIF_DEVICE_IRQ_ASYNC_SYNC; | |
147 | unsigned int panic_on_assert = 1; | |
148 | unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT; | |
149 | ||
150 | unsigned int setuphci = SETUPHCI_DEFAULT; | |
151 | unsigned int setuphcipal = SETUPHCIPAL_DEFAULT; | |
152 | unsigned int loghci = 0; | |
153 | unsigned int setupbtdev = SETUPBTDEV_DEFAULT; | |
154 | #ifndef EXPORT_HCI_BRIDGE_INTERFACE | |
155 | unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT; | |
156 | unsigned int hciuartscale = HCIUARTSCALE_DEFAULT; | |
157 | unsigned int hciuartstep = HCIUARTSTEP_DEFAULT; | |
158 | #endif | |
159 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
160 | unsigned int csumOffload=0; | |
161 | unsigned int csumOffloadTest=0; | |
162 | #endif | |
163 | unsigned int eppingtest=0; | |
164 | ||
165 | module_param_string(ifname, ifname, sizeof(ifname), 0644); | |
166 | module_param(wlaninitmode, int, 0644); | |
167 | module_param(bmienable, int, 0644); | |
168 | module_param(bypasswmi, uint, 0644); | |
169 | module_param(debuglevel, uint, 0644); | |
170 | module_param(tspecCompliance, int, 0644); | |
171 | module_param(onebitmode, uint, 0644); | |
172 | module_param(busspeedlow, uint, 0644); | |
173 | module_param(skipflash, uint, 0644); | |
174 | module_param(wmitimeout, uint, 0644); | |
175 | module_param(wlanNodeCaching, uint, 0644); | |
176 | module_param(logWmiRawMsgs, uint, 0644); | |
177 | module_param(enableuartprint, uint, 0644); | |
178 | module_param(enabletimerwar, uint, 0644); | |
179 | module_param(fwmode, uint, 0644); | |
180 | module_param(mbox_yield_limit, uint, 0644); | |
181 | module_param(reduce_credit_dribble, int, 0644); | |
182 | module_param(allow_trace_signal, int, 0644); | |
183 | module_param(enablerssicompensation, uint, 0644); | |
184 | module_param(processDot11Hdr, uint, 0644); | |
185 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
186 | module_param(csumOffload, uint, 0644); | |
187 | #endif | |
188 | #ifdef CONFIG_HOST_TCMD_SUPPORT | |
189 | module_param(testmode, uint, 0644); | |
190 | #endif | |
191 | module_param(irqprocmode, uint, 0644); | |
192 | module_param(nohifscattersupport, uint, 0644); | |
193 | module_param(panic_on_assert, uint, 0644); | |
194 | module_param(setuphci, uint, 0644); | |
195 | module_param(setuphcipal, uint, 0644); | |
196 | module_param(loghci, uint, 0644); | |
197 | module_param(setupbtdev, uint, 0644); | |
198 | #ifndef EXPORT_HCI_BRIDGE_INTERFACE | |
199 | module_param(ar3khcibaud, uint, 0644); | |
200 | module_param(hciuartscale, uint, 0644); | |
201 | module_param(hciuartstep, uint, 0644); | |
202 | #endif | |
203 | module_param(eppingtest, uint, 0644); | |
204 | ||
205 | /* in 2.6.10 and later this is now a pointer to a uint */ | |
206 | unsigned int _mboxnum = HTC_MAILBOX_NUM_MAX; | |
207 | #define mboxnum &_mboxnum | |
208 | ||
209 | #ifdef DEBUG | |
210 | A_UINT32 g_dbg_flags = DBG_DEFAULTS; | |
211 | unsigned int debugflags = 0; | |
212 | int debugdriver = 0; | |
213 | unsigned int debughtc = 0; | |
214 | unsigned int debugbmi = 0; | |
215 | unsigned int debughif = 0; | |
216 | unsigned int txcreditsavailable[HTC_MAILBOX_NUM_MAX] = {0}; | |
217 | unsigned int txcreditsconsumed[HTC_MAILBOX_NUM_MAX] = {0}; | |
218 | unsigned int txcreditintrenable[HTC_MAILBOX_NUM_MAX] = {0}; | |
219 | unsigned int txcreditintrenableaggregate[HTC_MAILBOX_NUM_MAX] = {0}; | |
220 | module_param(debugflags, uint, 0644); | |
221 | module_param(debugdriver, int, 0644); | |
222 | module_param(debughtc, uint, 0644); | |
223 | module_param(debugbmi, uint, 0644); | |
224 | module_param(debughif, uint, 0644); | |
225 | module_param_array(txcreditsavailable, uint, mboxnum, 0644); | |
226 | module_param_array(txcreditsconsumed, uint, mboxnum, 0644); | |
227 | module_param_array(txcreditintrenable, uint, mboxnum, 0644); | |
228 | module_param_array(txcreditintrenableaggregate, uint, mboxnum, 0644); | |
229 | ||
230 | #endif /* DEBUG */ | |
231 | ||
232 | unsigned int resetok = 1; | |
233 | unsigned int tx_attempt[HTC_MAILBOX_NUM_MAX] = {0}; | |
234 | unsigned int tx_post[HTC_MAILBOX_NUM_MAX] = {0}; | |
235 | unsigned int tx_complete[HTC_MAILBOX_NUM_MAX] = {0}; | |
236 | unsigned int hifBusRequestNumMax = 40; | |
237 | unsigned int war23838_disabled = 0; | |
238 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
239 | unsigned int enableAPTCHeuristics = 1; | |
240 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
241 | module_param_array(tx_attempt, uint, mboxnum, 0644); | |
242 | module_param_array(tx_post, uint, mboxnum, 0644); | |
243 | module_param_array(tx_complete, uint, mboxnum, 0644); | |
244 | module_param(hifBusRequestNumMax, uint, 0644); | |
245 | module_param(war23838_disabled, uint, 0644); | |
246 | module_param(resetok, uint, 0644); | |
247 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
248 | module_param(enableAPTCHeuristics, uint, 0644); | |
249 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
250 | ||
251 | #ifdef BLOCK_TX_PATH_FLAG | |
252 | int blocktx = 0; | |
253 | module_param(blocktx, int, 0644); | |
254 | #endif /* BLOCK_TX_PATH_FLAG */ | |
255 | ||
256 | typedef struct user_rssi_compensation_t { | |
257 | A_UINT16 customerID; | |
258 | union { | |
259 | A_UINT16 a_enable; | |
260 | A_UINT16 bg_enable; | |
261 | A_UINT16 enable; | |
262 | }; | |
263 | A_INT16 bg_param_a; | |
264 | A_INT16 bg_param_b; | |
265 | A_INT16 a_param_a; | |
266 | A_INT16 a_param_b; | |
267 | A_UINT32 reserved; | |
268 | } USER_RSSI_CPENSATION; | |
269 | ||
270 | static USER_RSSI_CPENSATION rssi_compensation_param; | |
271 | ||
272 | static A_INT16 rssi_compensation_table[96]; | |
273 | ||
274 | int reconnect_flag = 0; | |
275 | static ar6k_pal_config_t ar6k_pal_config_g; | |
276 | ||
277 | /* Function declarations */ | |
278 | static int ar6000_init_module(void); | |
279 | static void ar6000_cleanup_module(void); | |
280 | ||
281 | int ar6000_init(struct net_device *dev); | |
282 | static int ar6000_open(struct net_device *dev); | |
283 | static int ar6000_close(struct net_device *dev); | |
284 | static void ar6000_init_control_info(AR_SOFTC_T *ar); | |
285 | static int ar6000_data_tx(struct sk_buff *skb, struct net_device *dev); | |
286 | ||
287 | void ar6000_destroy(struct net_device *dev, unsigned int unregister); | |
288 | static void ar6000_detect_error(unsigned long ptr); | |
289 | static void ar6000_set_multicast_list(struct net_device *dev); | |
290 | static struct net_device_stats *ar6000_get_stats(struct net_device *dev); | |
291 | static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev); | |
292 | ||
293 | static void disconnect_timer_handler(unsigned long ptr); | |
294 | ||
295 | void read_rssi_compensation_param(AR_SOFTC_T *ar); | |
296 | ||
297 | /* for android builds we call external APIs that handle firmware download and configuration */ | |
298 | #ifdef ANDROID_ENV | |
299 | /* !!!! Interim android support to make it easier to patch the default driver for | |
300 | * android use. You must define an external source file ar6000_android.c that handles the following | |
301 | * APIs */ | |
302 | extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks); | |
303 | extern void android_module_exit(void); | |
304 | #endif | |
305 | /* | |
306 | * HTC service connection handlers | |
307 | */ | |
308 | static A_STATUS ar6000_avail_ev(void *context, void *hif_handle); | |
309 | ||
310 | static A_STATUS ar6000_unavail_ev(void *context, void *hif_handle); | |
311 | ||
312 | A_STATUS ar6000_configure_target(AR_SOFTC_T *ar); | |
313 | ||
314 | static void ar6000_target_failure(void *Instance, A_STATUS Status); | |
315 | ||
316 | static void ar6000_rx(void *Context, HTC_PACKET *pPacket); | |
317 | ||
318 | static void ar6000_rx_refill(void *Context,HTC_ENDPOINT_ID Endpoint); | |
319 | ||
320 | static void ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPackets); | |
321 | ||
322 | static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket); | |
323 | ||
324 | #ifdef ATH_AR6K_11N_SUPPORT | |
325 | static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num); | |
326 | #endif | |
327 | static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf); | |
328 | //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf); | |
329 | ||
330 | static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length); | |
331 | ||
332 | static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count); | |
333 | ||
334 | static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar); | |
335 | ||
336 | static ssize_t | |
337 | ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, | |
338 | struct bin_attribute *bin_attr, | |
339 | char *buf, loff_t pos, size_t count); | |
340 | ||
341 | static ssize_t | |
342 | ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, | |
343 | struct bin_attribute *bin_attr, | |
344 | char *buf, loff_t pos, size_t count); | |
345 | ||
346 | static A_STATUS | |
347 | ar6000_sysfs_bmi_init(AR_SOFTC_T *ar); | |
348 | ||
349 | /* HCI PAL callback function declarations */ | |
350 | A_STATUS ar6k_setup_hci_pal(AR_SOFTC_T *ar); | |
351 | void ar6k_cleanup_hci_pal(AR_SOFTC_T *ar); | |
352 | ||
353 | static void | |
354 | ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar); | |
355 | ||
356 | A_STATUS | |
357 | ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode); | |
358 | ||
359 | /* | |
360 | * Static variables | |
361 | */ | |
362 | ||
363 | struct net_device *ar6000_devices[MAX_AR6000]; | |
364 | static int is_netdev_registered; | |
365 | extern struct iw_handler_def ath_iw_handler_def; | |
366 | DECLARE_WAIT_QUEUE_HEAD(arEvent); | |
367 | static void ar6000_cookie_init(AR_SOFTC_T *ar); | |
368 | static void ar6000_cookie_cleanup(AR_SOFTC_T *ar); | |
369 | static void ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie); | |
370 | static struct ar_cookie *ar6000_alloc_cookie(AR_SOFTC_T *ar); | |
371 | ||
372 | #ifdef USER_KEYS | |
373 | static A_STATUS ar6000_reinstall_keys(AR_SOFTC_T *ar,A_UINT8 key_op_ctrl); | |
374 | #endif | |
375 | ||
376 | #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT | |
377 | struct net_device *arApNetDev; | |
378 | #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ | |
379 | ||
380 | static struct ar_cookie s_ar_cookie_mem[MAX_COOKIE_NUM]; | |
381 | ||
382 | #define HOST_INTEREST_ITEM_ADDRESS(ar, item) \ | |
383 | (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_HOST_INTEREST_ITEM_ADDRESS(item) : \ | |
384 | (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_HOST_INTEREST_ITEM_ADDRESS(item) : 0)) | |
385 | ||
386 | ||
387 | static struct net_device_ops ar6000_netdev_ops = { | |
388 | .ndo_init = NULL, | |
389 | .ndo_open = ar6000_open, | |
390 | .ndo_stop = ar6000_close, | |
391 | .ndo_get_stats = ar6000_get_stats, | |
392 | .ndo_do_ioctl = ar6000_ioctl, | |
393 | .ndo_start_xmit = ar6000_data_tx, | |
394 | .ndo_set_multicast_list = ar6000_set_multicast_list, | |
395 | }; | |
396 | ||
397 | /* Debug log support */ | |
398 | ||
399 | /* | |
400 | * Flag to govern whether the debug logs should be parsed in the kernel | |
401 | * or reported to the application. | |
402 | */ | |
403 | #define REPORT_DEBUG_LOGS_TO_APP | |
404 | ||
405 | A_STATUS | |
406 | ar6000_set_host_app_area(AR_SOFTC_T *ar) | |
407 | { | |
408 | A_UINT32 address, data; | |
409 | struct host_app_area_s host_app_area; | |
410 | ||
411 | /* Fetch the address of the host_app_area_s instance in the host interest area */ | |
412 | address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest)); | |
413 | if (ar6000_ReadRegDiag(ar->arHifDevice, &address, &data) != A_OK) { | |
414 | return A_ERROR; | |
415 | } | |
416 | address = TARG_VTOP(ar->arTargetType, data); | |
417 | host_app_area.wmi_protocol_ver = WMI_PROTOCOL_VERSION; | |
418 | if (ar6000_WriteDataDiag(ar->arHifDevice, address, | |
419 | (A_UCHAR *)&host_app_area, | |
420 | sizeof(struct host_app_area_s)) != A_OK) | |
421 | { | |
422 | return A_ERROR; | |
423 | } | |
424 | ||
425 | return A_OK; | |
426 | } | |
427 | ||
428 | A_UINT32 | |
429 | dbglog_get_debug_hdr_ptr(AR_SOFTC_T *ar) | |
430 | { | |
431 | A_UINT32 param; | |
432 | A_UINT32 address; | |
433 | A_STATUS status; | |
434 | ||
435 | address = TARG_VTOP(ar->arTargetType, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbglog_hdr)); | |
436 | if ((status = ar6000_ReadDataDiag(ar->arHifDevice, address, | |
437 | (A_UCHAR *)¶m, 4)) != A_OK) | |
438 | { | |
439 | param = 0; | |
440 | } | |
441 | ||
442 | return param; | |
443 | } | |
444 | ||
445 | /* | |
446 | * The dbglog module has been initialized. Its ok to access the relevant | |
447 | * data stuctures over the diagnostic window. | |
448 | */ | |
449 | void | |
450 | ar6000_dbglog_init_done(AR_SOFTC_T *ar) | |
451 | { | |
452 | ar->dbglog_init_done = TRUE; | |
453 | } | |
454 | ||
455 | A_UINT32 | |
456 | dbglog_get_debug_fragment(A_INT8 *datap, A_UINT32 len, A_UINT32 limit) | |
457 | { | |
458 | A_INT32 *buffer; | |
459 | A_UINT32 count; | |
460 | A_UINT32 numargs; | |
461 | A_UINT32 length; | |
462 | A_UINT32 fraglen; | |
463 | ||
464 | count = fraglen = 0; | |
465 | buffer = (A_INT32 *)datap; | |
466 | length = (limit >> 2); | |
467 | ||
468 | if (len <= limit) { | |
469 | fraglen = len; | |
470 | } else { | |
471 | while (count < length) { | |
472 | numargs = DBGLOG_GET_NUMARGS(buffer[count]); | |
473 | fraglen = (count << 2); | |
474 | count += numargs + 1; | |
475 | } | |
476 | } | |
477 | ||
478 | return fraglen; | |
479 | } | |
480 | ||
481 | void | |
482 | dbglog_parse_debug_logs(A_INT8 *datap, A_UINT32 len) | |
483 | { | |
484 | A_INT32 *buffer; | |
485 | A_UINT32 count; | |
486 | A_UINT32 timestamp; | |
487 | A_UINT32 debugid; | |
488 | A_UINT32 moduleid; | |
489 | A_UINT32 numargs; | |
490 | A_UINT32 length; | |
491 | ||
492 | count = 0; | |
493 | buffer = (A_INT32 *)datap; | |
494 | length = (len >> 2); | |
495 | while (count < length) { | |
496 | debugid = DBGLOG_GET_DBGID(buffer[count]); | |
497 | moduleid = DBGLOG_GET_MODULEID(buffer[count]); | |
498 | numargs = DBGLOG_GET_NUMARGS(buffer[count]); | |
499 | timestamp = DBGLOG_GET_TIMESTAMP(buffer[count]); | |
500 | switch (numargs) { | |
501 | case 0: | |
502 | AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d)\n", moduleid, debugid, timestamp)); | |
503 | break; | |
504 | ||
505 | case 1: | |
506 | AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x\n", moduleid, debugid, | |
507 | timestamp, buffer[count+1])); | |
508 | break; | |
509 | ||
510 | case 2: | |
511 | AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("%d %d (%d): 0x%x, 0x%x\n", moduleid, debugid, | |
512 | timestamp, buffer[count+1], buffer[count+2])); | |
513 | break; | |
514 | ||
515 | default: | |
516 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid args: %d\n", numargs)); | |
517 | } | |
518 | count += numargs + 1; | |
519 | } | |
520 | } | |
521 | ||
522 | int | |
523 | ar6000_dbglog_get_debug_logs(AR_SOFTC_T *ar) | |
524 | { | |
525 | A_UINT32 data[8]; /* Should be able to accomodate struct dbglog_buf_s */ | |
526 | A_UINT32 address; | |
527 | A_UINT32 length; | |
528 | A_UINT32 dropped; | |
529 | A_UINT32 firstbuf; | |
530 | A_UINT32 debug_hdr_ptr; | |
531 | ||
532 | if (!ar->dbglog_init_done) return A_ERROR; | |
533 | ||
534 | ||
535 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
536 | ||
537 | if (ar->dbgLogFetchInProgress) { | |
538 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
539 | return A_EBUSY; | |
540 | } | |
541 | ||
542 | /* block out others */ | |
543 | ar->dbgLogFetchInProgress = TRUE; | |
544 | ||
545 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
546 | ||
547 | debug_hdr_ptr = dbglog_get_debug_hdr_ptr(ar); | |
548 | printk("debug_hdr_ptr: 0x%x\n", debug_hdr_ptr); | |
549 | ||
550 | /* Get the contents of the ring buffer */ | |
551 | if (debug_hdr_ptr) { | |
552 | address = TARG_VTOP(ar->arTargetType, debug_hdr_ptr); | |
553 | length = 4 /* sizeof(dbuf) */ + 4 /* sizeof(dropped) */; | |
554 | A_MEMZERO(data, sizeof(data)); | |
555 | ar6000_ReadDataDiag(ar->arHifDevice, address, (A_UCHAR *)data, length); | |
556 | address = TARG_VTOP(ar->arTargetType, data[0] /* dbuf */); | |
557 | firstbuf = address; | |
558 | dropped = data[1]; /* dropped */ | |
559 | length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */; | |
560 | A_MEMZERO(data, sizeof(data)); | |
561 | ar6000_ReadDataDiag(ar->arHifDevice, address, (A_UCHAR *)&data, length); | |
562 | ||
563 | do { | |
564 | address = TARG_VTOP(ar->arTargetType, data[1] /* buffer*/); | |
565 | length = data[3]; /* length */ | |
566 | if ((length) && (length <= data[2] /* bufsize*/)) { | |
567 | /* Rewind the index if it is about to overrun the buffer */ | |
568 | if (ar->log_cnt > (DBGLOG_HOST_LOG_BUFFER_SIZE - length)) { | |
569 | ar->log_cnt = 0; | |
570 | } | |
571 | if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, | |
572 | (A_UCHAR *)&ar->log_buffer[ar->log_cnt], length)) | |
573 | { | |
574 | break; | |
575 | } | |
576 | ar6000_dbglog_event(ar, dropped, (A_INT8*)&ar->log_buffer[ar->log_cnt], length); | |
577 | ar->log_cnt += length; | |
578 | } else { | |
579 | AR_DEBUG_PRINTF(ATH_DEBUG_DBG_LOG,("Length: %d (Total size: %d)\n", | |
580 | data[3], data[2])); | |
581 | } | |
582 | ||
583 | address = TARG_VTOP(ar->arTargetType, data[0] /* next */); | |
584 | length = 4 /* sizeof(next) */ + 4 /* sizeof(buffer) */ + 4 /* sizeof(bufsize) */ + 4 /* sizeof(length) */ + 4 /* sizeof(count) */ + 4 /* sizeof(free) */; | |
585 | A_MEMZERO(data, sizeof(data)); | |
586 | if(A_OK != ar6000_ReadDataDiag(ar->arHifDevice, address, | |
587 | (A_UCHAR *)&data, length)) | |
588 | { | |
589 | break; | |
590 | } | |
591 | ||
592 | } while (address != firstbuf); | |
593 | } | |
594 | ||
595 | ar->dbgLogFetchInProgress = FALSE; | |
596 | ||
597 | return A_OK; | |
598 | } | |
599 | ||
600 | void | |
601 | ar6000_dbglog_event(AR_SOFTC_T *ar, A_UINT32 dropped, | |
602 | A_INT8 *buffer, A_UINT32 length) | |
603 | { | |
604 | #ifdef REPORT_DEBUG_LOGS_TO_APP | |
605 | #define MAX_WIRELESS_EVENT_SIZE 252 | |
606 | /* | |
607 | * Break it up into chunks of MAX_WIRELESS_EVENT_SIZE bytes of messages. | |
608 | * There seems to be a limitation on the length of message that could be | |
609 | * transmitted to the user app via this mechanism. | |
610 | */ | |
611 | A_UINT32 send, sent; | |
612 | ||
613 | sent = 0; | |
614 | send = dbglog_get_debug_fragment(&buffer[sent], length - sent, | |
615 | MAX_WIRELESS_EVENT_SIZE); | |
616 | while (send) { | |
617 | ar6000_send_event_to_app(ar, WMIX_DBGLOG_EVENTID, (A_UINT8*)&buffer[sent], send); | |
618 | sent += send; | |
619 | send = dbglog_get_debug_fragment(&buffer[sent], length - sent, | |
620 | MAX_WIRELESS_EVENT_SIZE); | |
621 | } | |
622 | #else | |
623 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Dropped logs: 0x%x\nDebug info length: %d\n", | |
624 | dropped, length)); | |
625 | ||
626 | /* Interpret the debug logs */ | |
627 | dbglog_parse_debug_logs((A_INT8*)buffer, length); | |
628 | #endif /* REPORT_DEBUG_LOGS_TO_APP */ | |
629 | } | |
630 | ||
631 | ||
632 | static int __init | |
633 | ar6000_init_module(void) | |
634 | { | |
635 | static int probed = 0; | |
636 | A_STATUS status; | |
637 | OSDRV_CALLBACKS osdrvCallbacks; | |
638 | ||
639 | a_module_debug_support_init(); | |
640 | ||
641 | #ifdef DEBUG | |
642 | /* check for debug mask overrides */ | |
643 | if (debughtc != 0) { | |
644 | ATH_DEBUG_SET_DEBUG_MASK(htc,debughtc); | |
645 | } | |
646 | if (debugbmi != 0) { | |
647 | ATH_DEBUG_SET_DEBUG_MASK(bmi,debugbmi); | |
648 | } | |
649 | if (debughif != 0) { | |
650 | ATH_DEBUG_SET_DEBUG_MASK(hif,debughif); | |
651 | } | |
652 | if (debugdriver != 0) { | |
653 | ATH_DEBUG_SET_DEBUG_MASK(driver,debugdriver); | |
654 | } | |
655 | ||
656 | #endif | |
657 | ||
658 | A_REGISTER_MODULE_DEBUG_INFO(driver); | |
659 | ||
660 | A_MEMZERO(&osdrvCallbacks,sizeof(osdrvCallbacks)); | |
661 | osdrvCallbacks.deviceInsertedHandler = ar6000_avail_ev; | |
662 | osdrvCallbacks.deviceRemovedHandler = ar6000_unavail_ev; | |
663 | #ifdef CONFIG_PM | |
664 | osdrvCallbacks.deviceSuspendHandler = ar6000_suspend_ev; | |
665 | osdrvCallbacks.deviceResumeHandler = ar6000_resume_ev; | |
666 | osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev; | |
667 | #endif | |
668 | ||
669 | ar6000_pm_init(); | |
670 | ||
671 | #ifdef ANDROID_ENV | |
672 | android_module_init(&osdrvCallbacks); | |
673 | #endif | |
674 | ||
675 | #ifdef DEBUG | |
676 | /* Set the debug flags if specified at load time */ | |
677 | if(debugflags != 0) | |
678 | { | |
679 | g_dbg_flags = debugflags; | |
680 | } | |
681 | #endif | |
682 | ||
683 | if (probed) { | |
684 | return -ENODEV; | |
685 | } | |
686 | probed++; | |
687 | ||
688 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
689 | memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD)); | |
690 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
691 | ||
692 | #ifdef CONFIG_HOST_GPIO_SUPPORT | |
693 | ar6000_gpio_init(); | |
694 | #endif /* CONFIG_HOST_GPIO_SUPPORT */ | |
695 | ||
696 | status = HIFInit(&osdrvCallbacks); | |
697 | if(status != A_OK) | |
698 | return -ENODEV; | |
699 | ||
700 | return 0; | |
701 | } | |
702 | ||
703 | static void __exit | |
704 | ar6000_cleanup_module(void) | |
705 | { | |
706 | int i = 0; | |
707 | struct net_device *ar6000_netdev; | |
708 | ||
709 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
710 | /* Delete the Adaptive Power Control timer */ | |
711 | if (timer_pending(&aptcTimer)) { | |
712 | del_timer_sync(&aptcTimer); | |
713 | } | |
714 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
715 | ||
716 | for (i=0; i < MAX_AR6000; i++) { | |
717 | if (ar6000_devices[i] != NULL) { | |
718 | ar6000_netdev = ar6000_devices[i]; | |
719 | ar6000_devices[i] = NULL; | |
720 | ar6000_destroy(ar6000_netdev, 1); | |
721 | } | |
722 | } | |
723 | ||
724 | HIFShutDownDevice(NULL); | |
725 | ||
726 | a_module_debug_support_cleanup(); | |
727 | ||
728 | ar6000_pm_exit(); | |
729 | ||
730 | #ifdef ANDROID_ENV | |
731 | android_module_exit(); | |
732 | #endif | |
733 | ||
734 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n")); | |
735 | } | |
736 | ||
737 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
738 | void | |
739 | aptcTimerHandler(unsigned long arg) | |
740 | { | |
741 | A_UINT32 numbytes; | |
742 | A_UINT32 throughput; | |
743 | AR_SOFTC_T *ar; | |
744 | A_STATUS status; | |
745 | ||
746 | ar = (AR_SOFTC_T *)arg; | |
747 | A_ASSERT(ar != NULL); | |
748 | A_ASSERT(!timer_pending(&aptcTimer)); | |
749 | ||
750 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
751 | ||
752 | /* Get the number of bytes transferred */ | |
753 | numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived; | |
754 | aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0; | |
755 | ||
756 | /* Calculate and decide based on throughput thresholds */ | |
757 | throughput = ((numbytes * 8)/APTC_TRAFFIC_SAMPLING_INTERVAL); /* Kbps */ | |
758 | if (throughput < APTC_LOWER_THROUGHPUT_THRESHOLD) { | |
759 | /* Enable Sleep and delete the timer */ | |
760 | A_ASSERT(ar->arWmiReady == TRUE); | |
761 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
762 | status = wmi_powermode_cmd(ar->arWmi, REC_POWER); | |
763 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
764 | A_ASSERT(status == A_OK); | |
765 | aptcTR.timerScheduled = FALSE; | |
766 | } else { | |
767 | A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0); | |
768 | } | |
769 | ||
770 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
771 | } | |
772 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
773 | ||
774 | #ifdef ATH_AR6K_11N_SUPPORT | |
775 | static void | |
776 | ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, A_UINT16 num) | |
777 | { | |
778 | void * osbuf; | |
779 | ||
780 | while(num) { | |
781 | if((osbuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE))) { | |
782 | A_NETBUF_ENQUEUE(q, osbuf); | |
783 | } else { | |
784 | break; | |
785 | } | |
786 | num--; | |
787 | } | |
788 | ||
789 | if(num) { | |
790 | A_PRINTF("%s(), allocation of netbuf failed", __func__); | |
791 | } | |
792 | } | |
793 | #endif | |
794 | ||
795 | static struct bin_attribute bmi_attr = { | |
796 | .attr = {.name = "bmi", .mode = 0600}, | |
797 | .read = ar6000_sysfs_bmi_read, | |
798 | .write = ar6000_sysfs_bmi_write, | |
799 | }; | |
800 | ||
801 | static ssize_t | |
802 | ar6000_sysfs_bmi_read(struct file *fp, struct kobject *kobj, | |
803 | struct bin_attribute *bin_attr, | |
804 | char *buf, loff_t pos, size_t count) | |
805 | { | |
806 | int index; | |
807 | AR_SOFTC_T *ar; | |
808 | HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; | |
809 | ||
810 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Read %d bytes\n", (A_UINT32)count)); | |
811 | for (index=0; index < MAX_AR6000; index++) { | |
812 | ar = (AR_SOFTC_T *)ar6k_priv(ar6000_devices[index]); | |
813 | osDevInfo = &ar->osDevInfo; | |
814 | if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { | |
815 | break; | |
816 | } | |
817 | } | |
818 | ||
819 | if (index == MAX_AR6000) return 0; | |
820 | ||
821 | if ((BMIRawRead(ar->arHifDevice, (A_UCHAR*)buf, count, TRUE)) != A_OK) { | |
822 | return 0; | |
823 | } | |
824 | ||
825 | return count; | |
826 | } | |
827 | ||
828 | static ssize_t | |
829 | ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, | |
830 | struct bin_attribute *bin_attr, | |
831 | char *buf, loff_t pos, size_t count) | |
832 | { | |
833 | int index; | |
834 | AR_SOFTC_T *ar; | |
835 | HIF_DEVICE_OS_DEVICE_INFO *osDevInfo; | |
836 | ||
837 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Write %d bytes\n", (A_UINT32)count)); | |
838 | for (index=0; index < MAX_AR6000; index++) { | |
839 | ar = (AR_SOFTC_T *)ar6k_priv(ar6000_devices[index]); | |
840 | osDevInfo = &ar->osDevInfo; | |
841 | if (kobj == (&(((struct device *)osDevInfo->pOSDevice)->kobj))) { | |
842 | break; | |
843 | } | |
844 | } | |
845 | ||
846 | if (index == MAX_AR6000) return 0; | |
847 | ||
848 | if ((BMIRawWrite(ar->arHifDevice, (A_UCHAR*)buf, count)) != A_OK) { | |
849 | return 0; | |
850 | } | |
851 | ||
852 | return count; | |
853 | } | |
854 | ||
855 | static A_STATUS | |
856 | ar6000_sysfs_bmi_init(AR_SOFTC_T *ar) | |
857 | { | |
858 | A_STATUS status; | |
859 | ||
860 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Creating sysfs entry\n")); | |
861 | A_MEMZERO(&ar->osDevInfo, sizeof(HIF_DEVICE_OS_DEVICE_INFO)); | |
862 | ||
863 | /* Get the underlying OS device */ | |
864 | status = HIFConfigureDevice(ar->arHifDevice, | |
865 | HIF_DEVICE_GET_OS_DEVICE, | |
866 | &ar->osDevInfo, | |
867 | sizeof(HIF_DEVICE_OS_DEVICE_INFO)); | |
868 | ||
869 | if (A_FAILED(status)) { | |
870 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failed to get OS device info from HIF\n")); | |
871 | return A_ERROR; | |
872 | } | |
873 | ||
874 | /* Create a bmi entry in the sysfs filesystem */ | |
875 | if ((sysfs_create_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr)) < 0) | |
876 | { | |
877 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMI: Failed to create entry for bmi in sysfs filesystem\n")); | |
878 | return A_ERROR; | |
879 | } | |
880 | ||
881 | return A_OK; | |
882 | } | |
883 | ||
884 | static void | |
885 | ar6000_sysfs_bmi_deinit(AR_SOFTC_T *ar) | |
886 | { | |
887 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Deleting sysfs entry\n")); | |
888 | ||
889 | sysfs_remove_bin_file(&(((struct device *)ar->osDevInfo.pOSDevice)->kobj), &bmi_attr); | |
890 | } | |
891 | ||
892 | #define bmifn(fn) do { \ | |
893 | if ((fn) < A_OK) { \ | |
894 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); \ | |
895 | return A_ERROR; \ | |
896 | } \ | |
897 | } while(0) | |
898 | ||
899 | #ifdef INIT_MODE_DRV_ENABLED | |
900 | ||
901 | #ifdef SOFTMAC_FILE_USED | |
902 | #define AR6002_MAC_ADDRESS_OFFSET 0x0A | |
903 | #define AR6003_MAC_ADDRESS_OFFSET 0x16 | |
904 | static | |
905 | void calculate_crc(A_UINT32 TargetType, A_UCHAR *eeprom_data) | |
906 | { | |
907 | A_UINT16 *ptr_crc; | |
908 | A_UINT16 *ptr16_eeprom; | |
909 | A_UINT16 checksum; | |
910 | A_UINT32 i; | |
911 | A_UINT32 eeprom_size; | |
912 | ||
913 | if (TargetType == TARGET_TYPE_AR6001) | |
914 | { | |
915 | eeprom_size = 512; | |
916 | ptr_crc = (A_UINT16 *)eeprom_data; | |
917 | } | |
918 | else if (TargetType == TARGET_TYPE_AR6003) | |
919 | { | |
920 | eeprom_size = 1024; | |
921 | ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); | |
922 | } | |
923 | else | |
924 | { | |
925 | eeprom_size = 768; | |
926 | ptr_crc = (A_UINT16 *)((A_UCHAR *)eeprom_data + 0x04); | |
927 | } | |
928 | ||
929 | ||
930 | // Clear the crc | |
931 | *ptr_crc = 0; | |
932 | ||
933 | // Recalculate new CRC | |
934 | checksum = 0; | |
935 | ptr16_eeprom = (A_UINT16 *)eeprom_data; | |
936 | for (i = 0;i < eeprom_size; i += 2) | |
937 | { | |
938 | checksum = checksum ^ (*ptr16_eeprom); | |
939 | ptr16_eeprom++; | |
940 | } | |
941 | checksum = 0xFFFF ^ checksum; | |
942 | *ptr_crc = checksum; | |
943 | } | |
944 | ||
945 | static void | |
946 | ar6000_softmac_update(AR_SOFTC_T *ar, A_UCHAR *eeprom_data, size_t size) | |
947 | { | |
948 | const char *source = "random generated"; | |
949 | const struct firmware *softmac_entry; | |
950 | A_UCHAR *ptr_mac; | |
951 | switch (ar->arTargetType) { | |
952 | case TARGET_TYPE_AR6002: | |
953 | ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6002_MAC_ADDRESS_OFFSET); | |
954 | break; | |
955 | case TARGET_TYPE_AR6003: | |
956 | ptr_mac = (A_UINT8 *)((A_UCHAR *)eeprom_data + AR6003_MAC_ADDRESS_OFFSET); | |
957 | break; | |
958 | default: | |
959 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Invalid Target Type \n")); | |
960 | return; | |
961 | } | |
962 | printk("MAC from EEPROM %02X:%02X:%02X:%02X:%02X:%02X\n", | |
963 | ptr_mac[0], ptr_mac[1], ptr_mac[2], | |
964 | ptr_mac[3], ptr_mac[4], ptr_mac[5]); | |
965 | ||
966 | /* create a random MAC in case we cannot read file from system */ | |
967 | ptr_mac[0] = 0; | |
968 | ptr_mac[1] = 0x03; | |
969 | ptr_mac[2] = 0x7F; | |
970 | ptr_mac[3] = random32() & 0xff; | |
971 | ptr_mac[4] = random32() & 0xff; | |
972 | ptr_mac[5] = random32() & 0xff; | |
973 | if ((A_REQUEST_FIRMWARE(&softmac_entry, "softmac", ((struct device *)ar->osDevInfo.pOSDevice))) == 0) | |
974 | { | |
975 | A_CHAR *macbuf = A_MALLOC_NOWAIT(softmac_entry->size+1); | |
976 | if (macbuf) { | |
977 | unsigned int softmac[6]; | |
978 | memcpy(macbuf, softmac_entry->data, softmac_entry->size); | |
979 | macbuf[softmac_entry->size] = '\0'; | |
980 | if (sscanf(macbuf, "%02x:%02x:%02x:%02x:%02x:%02x", | |
981 | &softmac[0], &softmac[1], &softmac[2], | |
982 | &softmac[3], &softmac[4], &softmac[5])==6) { | |
983 | int i; | |
984 | for (i=0; i<6; ++i) { | |
985 | ptr_mac[i] = softmac[i] & 0xff; | |
986 | } | |
987 | source = "softmac file"; | |
988 | } | |
989 | A_FREE(macbuf); | |
990 | } | |
991 | A_RELEASE_FIRMWARE(softmac_entry); | |
992 | } | |
993 | printk("MAC from %s %02X:%02X:%02X:%02X:%02X:%02X\n", source, | |
994 | ptr_mac[0], ptr_mac[1], ptr_mac[2], | |
995 | ptr_mac[3], ptr_mac[4], ptr_mac[5]); | |
996 | calculate_crc(ar->arTargetType, eeprom_data); | |
997 | } | |
998 | #endif /* SOFTMAC_FILE_USED */ | |
999 | ||
1000 | static A_STATUS | |
1001 | ar6000_transfer_bin_file(AR_SOFTC_T *ar, AR6K_BIN_FILE file, A_UINT32 address, A_BOOL compressed) | |
1002 | { | |
1003 | A_STATUS status; | |
1004 | const char *filename; | |
1005 | const struct firmware *fw_entry; | |
1006 | A_UINT32 fw_entry_size; | |
1007 | ||
1008 | switch (file) { | |
1009 | case AR6K_OTP_FILE: | |
1010 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1011 | filename = AR6003_REV1_OTP_FILE; | |
1012 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1013 | filename = AR6003_REV2_OTP_FILE; | |
1014 | } else { | |
1015 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1016 | return A_ERROR; | |
1017 | } | |
1018 | break; | |
1019 | ||
1020 | case AR6K_FIRMWARE_FILE: | |
1021 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1022 | filename = AR6003_REV1_FIRMWARE_FILE; | |
1023 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1024 | filename = AR6003_REV2_FIRMWARE_FILE; | |
1025 | } else { | |
1026 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1027 | return A_ERROR; | |
1028 | } | |
1029 | ||
1030 | if (eppingtest) { | |
1031 | bypasswmi = TRUE; | |
1032 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1033 | filename = AR6003_REV1_EPPING_FIRMWARE_FILE; | |
1034 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1035 | filename = AR6003_REV2_EPPING_FIRMWARE_FILE; | |
1036 | } else { | |
1037 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n", | |
1038 | ar->arVersion.target_ver)); | |
1039 | return A_ERROR; | |
1040 | } | |
1041 | compressed = 0; | |
1042 | } | |
1043 | ||
1044 | #ifdef CONFIG_HOST_TCMD_SUPPORT | |
1045 | if(testmode) { | |
1046 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1047 | filename = AR6003_REV1_TCMD_FIRMWARE_FILE; | |
1048 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1049 | filename = AR6003_REV2_TCMD_FIRMWARE_FILE; | |
1050 | } else { | |
1051 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1052 | return A_ERROR; | |
1053 | } | |
1054 | compressed = 0; | |
1055 | } | |
1056 | #endif | |
1057 | #ifdef HTC_RAW_INTERFACE | |
1058 | if (!eppingtest && bypasswmi) { | |
1059 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1060 | filename = AR6003_REV1_ART_FIRMWARE_FILE; | |
1061 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1062 | filename = AR6003_REV2_ART_FIRMWARE_FILE; | |
1063 | } else { | |
1064 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1065 | return A_ERROR; | |
1066 | } | |
1067 | compressed = 0; | |
1068 | } | |
1069 | #endif | |
1070 | break; | |
1071 | ||
1072 | case AR6K_PATCH_FILE: | |
1073 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1074 | filename = AR6003_REV1_PATCH_FILE; | |
1075 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1076 | filename = AR6003_REV2_PATCH_FILE; | |
1077 | } else { | |
1078 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1079 | return A_ERROR; | |
1080 | } | |
1081 | break; | |
1082 | ||
1083 | case AR6K_BOARD_DATA_FILE: | |
1084 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1085 | filename = AR6003_REV1_BOARD_DATA_FILE; | |
1086 | } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1087 | filename = AR6003_REV2_BOARD_DATA_FILE; | |
1088 | } else { | |
1089 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); | |
1090 | return A_ERROR; | |
1091 | } | |
1092 | break; | |
1093 | ||
1094 | default: | |
1095 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown file type: %d\n", file)); | |
1096 | return A_ERROR; | |
1097 | } | |
1098 | if ((A_REQUEST_FIRMWARE(&fw_entry, filename, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) | |
1099 | { | |
1100 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Failed to get %s\n", filename)); | |
1101 | return A_ENOENT; | |
1102 | } | |
1103 | ||
1104 | #ifdef SOFTMAC_FILE_USED | |
1105 | if (file==AR6K_BOARD_DATA_FILE && fw_entry->data) { | |
1106 | ar6000_softmac_update(ar, (A_UCHAR *)fw_entry->data, fw_entry->size); | |
1107 | } | |
1108 | #endif | |
1109 | ||
1110 | ||
1111 | fw_entry_size = fw_entry->size; | |
1112 | ||
1113 | /* Load extended board data for AR6003 */ | |
1114 | if ((file==AR6K_BOARD_DATA_FILE) && (fw_entry->data)) { | |
1115 | A_UINT32 board_ext_address; | |
1116 | A_UINT32 board_ext_data_size; | |
1117 | A_UINT32 board_data_size; | |
1118 | ||
1119 | board_ext_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_EXT_DATA_SZ : \ | |
1120 | (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_EXT_DATA_SZ : 0)); | |
1121 | ||
1122 | board_data_size = (((ar)->arTargetType == TARGET_TYPE_AR6002) ? AR6002_BOARD_DATA_SZ : \ | |
1123 | (((ar)->arTargetType == TARGET_TYPE_AR6003) ? AR6003_BOARD_DATA_SZ : 0)); | |
1124 | ||
1125 | /* Determine where in Target RAM to write Board Data */ | |
1126 | bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), (A_UCHAR *)&board_ext_address, 4)); | |
1127 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board extended Data download address: 0x%x\n", board_ext_address)); | |
1128 | ||
1129 | /* check whether the target has allocated memory for extended board data and file contains extended board data */ | |
1130 | if ((board_ext_address) && (fw_entry->size == (board_data_size + board_ext_data_size))) { | |
1131 | A_UINT32 param; | |
1132 | ||
1133 | status = BMIWriteMemory(ar->arHifDevice, board_ext_address, (A_UCHAR *)(((A_UINT32)fw_entry->data) + board_data_size), board_ext_data_size); | |
1134 | ||
1135 | if (status != A_OK) { | |
1136 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); | |
1137 | A_RELEASE_FIRMWARE(fw_entry); | |
1138 | return A_ERROR; | |
1139 | } | |
1140 | ||
1141 | /* Record the fact that extended board Data IS initialized */ | |
1142 | param = 1; | |
1143 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_initialized), (A_UCHAR *)¶m, 4)); | |
1144 | } | |
1145 | fw_entry_size = board_data_size; | |
1146 | } | |
1147 | ||
1148 | if (compressed) { | |
1149 | status = BMIFastDownload(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); | |
1150 | } else { | |
1151 | status = BMIWriteMemory(ar->arHifDevice, address, (A_UCHAR *)fw_entry->data, fw_entry_size); | |
1152 | } | |
1153 | ||
1154 | if (status != A_OK) { | |
1155 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI operation failed: %d\n", __LINE__)); | |
1156 | A_RELEASE_FIRMWARE(fw_entry); | |
1157 | return A_ERROR; | |
1158 | } | |
1159 | A_RELEASE_FIRMWARE(fw_entry); | |
1160 | return A_OK; | |
1161 | } | |
1162 | #endif /* INIT_MODE_DRV_ENABLED */ | |
1163 | ||
1164 | A_STATUS | |
1165 | ar6000_update_bdaddr(AR_SOFTC_T *ar) | |
1166 | { | |
1167 | ||
1168 | if (setupbtdev != 0) { | |
1169 | A_UINT32 address; | |
1170 | ||
1171 | if (BMIReadMemory(ar->arHifDevice, | |
1172 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (A_UCHAR *)&address, 4) != A_OK) | |
1173 | { | |
1174 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for hi_board_data failed\n")); | |
1175 | return A_ERROR; | |
1176 | } | |
1177 | ||
1178 | if (BMIReadMemory(ar->arHifDevice, address + BDATA_BDADDR_OFFSET, (A_UCHAR *)ar->bdaddr, 6) != A_OK) | |
1179 | { | |
1180 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for BD address failed\n")); | |
1181 | return A_ERROR; | |
1182 | } | |
1183 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BDADDR 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x\n", ar->bdaddr[0], | |
1184 | ar->bdaddr[1], ar->bdaddr[2], ar->bdaddr[3], | |
1185 | ar->bdaddr[4], ar->bdaddr[5])); | |
1186 | } | |
1187 | ||
1188 | return A_OK; | |
1189 | } | |
1190 | ||
1191 | A_STATUS | |
1192 | ar6000_sysfs_bmi_get_config(AR_SOFTC_T *ar, A_UINT32 mode) | |
1193 | { | |
1194 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("BMI: Requesting device specific configuration\n")); | |
1195 | ||
1196 | if (mode == WLAN_INIT_MODE_UDEV) { | |
1197 | A_CHAR version[16]; | |
1198 | const struct firmware *fw_entry; | |
1199 | ||
1200 | /* Get config using udev through a script in user space */ | |
1201 | sprintf(version, "%2.2x", ar->arVersion.target_ver); | |
1202 | if ((A_REQUEST_FIRMWARE(&fw_entry, version, ((struct device *)ar->osDevInfo.pOSDevice))) != 0) | |
1203 | { | |
1204 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("BMI: Failure to get configuration for target version: %s\n", version)); | |
1205 | return A_ERROR; | |
1206 | } | |
1207 | ||
1208 | A_RELEASE_FIRMWARE(fw_entry); | |
1209 | #ifdef INIT_MODE_DRV_ENABLED | |
1210 | } else { | |
1211 | /* The config is contained within the driver itself */ | |
1212 | A_STATUS status; | |
1213 | A_UINT32 param, options, sleep, address; | |
1214 | ||
1215 | /* Temporarily disable system sleep */ | |
1216 | address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; | |
1217 | bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); | |
1218 | options = param; | |
1219 | param |= AR6K_OPTION_SLEEP_DISABLE; | |
1220 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1221 | ||
1222 | address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; | |
1223 | bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); | |
1224 | sleep = param; | |
1225 | param |= WLAN_SYSTEM_SLEEP_DISABLE_SET(1); | |
1226 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1227 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("old options: %d, old sleep: %d\n", options, sleep)); | |
1228 | ||
1229 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1230 | /* Program analog PLL register */ | |
1231 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, ANALOG_INTF_BASE_ADDRESS + 0x284, 0xF9104001)); | |
1232 | /* Run at 80/88MHz by default */ | |
1233 | param = CPU_CLOCK_STANDARD_SET(1); | |
1234 | } else { | |
1235 | /* Run at 40/44MHz by default */ | |
1236 | param = CPU_CLOCK_STANDARD_SET(0); | |
1237 | } | |
1238 | address = RTC_BASE_ADDRESS + CPU_CLOCK_ADDRESS; | |
1239 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1240 | ||
1241 | param = 0; | |
1242 | if (ar->arTargetType == TARGET_TYPE_AR6002) { | |
1243 | bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (A_UCHAR *)¶m, 4)); | |
1244 | } | |
1245 | ||
1246 | /* LPO_CAL.ENABLE = 1 if no external clk is detected */ | |
1247 | if (param != 1) { | |
1248 | address = RTC_BASE_ADDRESS + LPO_CAL_ADDRESS; | |
1249 | param = LPO_CAL_ENABLE_SET(1); | |
1250 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1251 | } | |
1252 | ||
1253 | /* Venus2.0: Lower SDIO pad drive strength, | |
1254 | * temporary WAR to avoid SDIO CRC error */ | |
1255 | if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1256 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6K: Temporary WAR to avoid SDIO CRC error\n")); | |
1257 | param = 0x20; | |
1258 | address = GPIO_BASE_ADDRESS + GPIO_PIN10_ADDRESS; | |
1259 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1260 | ||
1261 | address = GPIO_BASE_ADDRESS + GPIO_PIN11_ADDRESS; | |
1262 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1263 | ||
1264 | address = GPIO_BASE_ADDRESS + GPIO_PIN12_ADDRESS; | |
1265 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1266 | ||
1267 | address = GPIO_BASE_ADDRESS + GPIO_PIN13_ADDRESS; | |
1268 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1269 | } | |
1270 | ||
1271 | #ifdef FORCE_INTERNAL_CLOCK | |
1272 | /* Ignore external clock, if any, and force use of internal clock */ | |
1273 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1274 | /* hi_ext_clk_detected = 0 */ | |
1275 | param = 0; | |
1276 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_ext_clk_detected), (A_UCHAR *)¶m, 4)); | |
1277 | ||
1278 | /* CLOCK_CONTROL &= ~LF_CLK32 */ | |
1279 | address = RTC_BASE_ADDRESS + CLOCK_CONTROL_ADDRESS; | |
1280 | bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); | |
1281 | param &= (~CLOCK_CONTROL_LF_CLK32_SET(1)); | |
1282 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1283 | } | |
1284 | #endif /* FORCE_INTERNAL_CLOCK */ | |
1285 | ||
1286 | /* Transfer Board Data from Target EEPROM to Target RAM */ | |
1287 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1288 | /* Determine where in Target RAM to write Board Data */ | |
1289 | bmifn(BMIReadMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data), (A_UCHAR *)&address, 4)); | |
1290 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Board Data download address: 0x%x\n", address)); | |
1291 | ||
1292 | /* Write EEPROM data to Target RAM */ | |
1293 | if ((ar6000_transfer_bin_file(ar, AR6K_BOARD_DATA_FILE, address, FALSE)) != A_OK) { | |
1294 | return A_ERROR; | |
1295 | } | |
1296 | ||
1297 | /* Record the fact that Board Data IS initialized */ | |
1298 | param = 1; | |
1299 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (A_UCHAR *)¶m, 4)); | |
1300 | ||
1301 | /* Transfer One time Programmable data */ | |
1302 | AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); | |
1303 | status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, TRUE); | |
1304 | if (status == A_OK) { | |
1305 | /* Execute the OTP code */ | |
1306 | param = 0; | |
1307 | AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); | |
1308 | bmifn(BMIExecute(ar->arHifDevice, address, ¶m)); | |
1309 | } else if (status != A_ENOENT) { | |
1310 | return A_ERROR; | |
1311 | } | |
1312 | } else { | |
1313 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Programming of board data for chip %d not supported\n", ar->arTargetType)); | |
1314 | return A_ERROR; | |
1315 | } | |
1316 | ||
1317 | /* Download Target firmware */ | |
1318 | AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); | |
1319 | if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, TRUE)) != A_OK) { | |
1320 | return A_ERROR; | |
1321 | } | |
1322 | ||
1323 | /* Set starting address for firmware */ | |
1324 | AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); | |
1325 | bmifn(BMISetAppStart(ar->arHifDevice, address)); | |
1326 | ||
1327 | /* Apply the patches */ | |
1328 | AR6K_PATCH_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); | |
1329 | if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, FALSE)) != A_OK) { | |
1330 | return A_ERROR; | |
1331 | } | |
1332 | ||
1333 | param = address; | |
1334 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), (A_UCHAR *)¶m, 4)); | |
1335 | ||
1336 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1337 | if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { | |
1338 | /* Reserve 5.5K of RAM */ | |
1339 | param = 5632; | |
1340 | } else { /* AR6003_REV2_VERSION */ | |
1341 | /* Reserve 6.5K of RAM */ | |
1342 | param = 6656; | |
1343 | } | |
1344 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_end_RAM_reserve_sz), (A_UCHAR *)¶m, 4)); | |
1345 | } | |
1346 | ||
1347 | /* Restore system sleep */ | |
1348 | address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; | |
1349 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, sleep)); | |
1350 | ||
1351 | address = MBOX_BASE_ADDRESS + LOCAL_SCRATCH_ADDRESS; | |
1352 | param = options | 0x20; | |
1353 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1354 | ||
1355 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1356 | /* Configure GPIO AR6003 UART */ | |
1357 | #ifndef CONFIG_AR600x_DEBUG_UART_TX_PIN | |
1358 | #define CONFIG_AR600x_DEBUG_UART_TX_PIN 8 | |
1359 | #endif | |
1360 | param = CONFIG_AR600x_DEBUG_UART_TX_PIN; | |
1361 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dbg_uart_txpin), (A_UCHAR *)¶m, 4)); | |
1362 | ||
1363 | #if (CONFIG_AR600x_DEBUG_UART_TX_PIN == 23) | |
1364 | { | |
1365 | address = GPIO_BASE_ADDRESS + CLOCK_GPIO_ADDRESS; | |
1366 | bmifn(BMIReadSOCRegister(ar->arHifDevice, address, ¶m)); | |
1367 | param |= CLOCK_GPIO_BT_CLK_OUT_EN_SET(1); | |
1368 | bmifn(BMIWriteSOCRegister(ar->arHifDevice, address, param)); | |
1369 | } | |
1370 | #endif | |
1371 | ||
1372 | /* Configure GPIO for BT Reset */ | |
1373 | #ifdef ATH6KL_CONFIG_GPIO_BT_RESET | |
1374 | #define CONFIG_AR600x_BT_RESET_PIN 0x16 | |
1375 | param = CONFIG_AR600x_BT_RESET_PIN; | |
1376 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_support_pins), (A_UCHAR *)¶m, 4)); | |
1377 | #endif /* ATH6KL_CONFIG_GPIO_BT_RESET */ | |
1378 | ||
1379 | /* Configure UART flow control polarity */ | |
1380 | #ifndef CONFIG_ATH6KL_BT_UART_FC_POLARITY | |
1381 | #define CONFIG_ATH6KL_BT_UART_FC_POLARITY 0 | |
1382 | #endif | |
1383 | ||
1384 | #if (CONFIG_ATH6KL_BT_UART_FC_POLARITY == 1) | |
1385 | if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { | |
1386 | param = ((CONFIG_ATH6KL_BT_UART_FC_POLARITY << 1) & 0x2); | |
1387 | bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_hci_uart_pwr_mgmt_params), (A_UCHAR *)¶m, 4)); | |
1388 | } | |
1389 | #endif /* CONFIG_ATH6KL_BT_UART_FC_POLARITY */ | |
1390 | } | |
1391 | ||
1392 | #ifdef HTC_RAW_INTERFACE | |
1393 | if (!eppingtest && bypasswmi) { | |
1394 | /* Don't run BMIDone for ART mode and force resetok=0 */ | |
1395 | resetok = 0; | |
1396 | msleep(1000); | |
1397 | } | |
1398 | #endif /* HTC_RAW_INTERFACE */ | |
1399 | ||
1400 | #endif /* INIT_MODE_DRV_ENABLED */ | |
1401 | } | |
1402 | ||
1403 | return A_OK; | |
1404 | } | |
1405 | ||
1406 | A_STATUS | |
1407 | ar6000_configure_target(AR_SOFTC_T *ar) | |
1408 | { | |
1409 | A_UINT32 param; | |
1410 | if (enableuartprint) { | |
1411 | param = 1; | |
1412 | if (BMIWriteMemory(ar->arHifDevice, | |
1413 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_serial_enable), | |
1414 | (A_UCHAR *)¶m, | |
1415 | 4)!= A_OK) | |
1416 | { | |
1417 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enableuartprint failed \n")); | |
1418 | return A_ERROR; | |
1419 | } | |
1420 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Serial console prints enabled\n")); | |
1421 | } | |
1422 | ||
1423 | /* Tell target which HTC version it is used*/ | |
1424 | param = HTC_PROTOCOL_VERSION; | |
1425 | if (BMIWriteMemory(ar->arHifDevice, | |
1426 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_app_host_interest), | |
1427 | (A_UCHAR *)¶m, | |
1428 | 4)!= A_OK) | |
1429 | { | |
1430 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for htc version failed \n")); | |
1431 | return A_ERROR; | |
1432 | } | |
1433 | ||
1434 | #ifdef CONFIG_HOST_TCMD_SUPPORT | |
1435 | if(testmode) { | |
1436 | ar->arTargetMode = AR6000_TCMD_MODE; | |
1437 | }else { | |
1438 | ar->arTargetMode = AR6000_WLAN_MODE; | |
1439 | } | |
1440 | #endif | |
1441 | if (enabletimerwar) { | |
1442 | A_UINT32 param; | |
1443 | ||
1444 | if (BMIReadMemory(ar->arHifDevice, | |
1445 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1446 | (A_UCHAR *)¶m, | |
1447 | 4)!= A_OK) | |
1448 | { | |
1449 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for enabletimerwar failed \n")); | |
1450 | return A_ERROR; | |
1451 | } | |
1452 | ||
1453 | param |= HI_OPTION_TIMER_WAR; | |
1454 | ||
1455 | if (BMIWriteMemory(ar->arHifDevice, | |
1456 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1457 | (A_UCHAR *)¶m, | |
1458 | 4) != A_OK) | |
1459 | { | |
1460 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for enabletimerwar failed \n")); | |
1461 | return A_ERROR; | |
1462 | } | |
1463 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Timer WAR enabled\n")); | |
1464 | } | |
1465 | ||
1466 | /* set the firmware mode to STA/IBSS/AP */ | |
1467 | { | |
1468 | A_UINT32 param; | |
1469 | ||
1470 | if (BMIReadMemory(ar->arHifDevice, | |
1471 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1472 | (A_UCHAR *)¶m, | |
1473 | 4)!= A_OK) | |
1474 | { | |
1475 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for setting fwmode failed \n")); | |
1476 | return A_ERROR; | |
1477 | } | |
1478 | ||
1479 | param |= (fwmode << HI_OPTION_FW_MODE_SHIFT); | |
1480 | ||
1481 | if (BMIWriteMemory(ar->arHifDevice, | |
1482 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1483 | (A_UCHAR *)¶m, | |
1484 | 4) != A_OK) | |
1485 | { | |
1486 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for setting fwmode failed \n")); | |
1487 | return A_ERROR; | |
1488 | } | |
1489 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); | |
1490 | } | |
1491 | ||
1492 | #ifdef ATH6KL_DISABLE_TARGET_DBGLOGS | |
1493 | { | |
1494 | A_UINT32 param; | |
1495 | ||
1496 | if (BMIReadMemory(ar->arHifDevice, | |
1497 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1498 | (A_UCHAR *)¶m, | |
1499 | 4)!= A_OK) | |
1500 | { | |
1501 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIReadMemory for disabling debug logs failed\n")); | |
1502 | return A_ERROR; | |
1503 | } | |
1504 | ||
1505 | param |= HI_OPTION_DISABLE_DBGLOG; | |
1506 | ||
1507 | if (BMIWriteMemory(ar->arHifDevice, | |
1508 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), | |
1509 | (A_UCHAR *)¶m, | |
1510 | 4) != A_OK) | |
1511 | { | |
1512 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for HI_OPTION_DISABLE_DBGLOG\n")); | |
1513 | return A_ERROR; | |
1514 | } | |
1515 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Firmware mode set\n")); | |
1516 | } | |
1517 | #endif /* ATH6KL_DISABLE_TARGET_DBGLOGS */ | |
1518 | ||
1519 | /* | |
1520 | * Hardcode the address use for the extended board data | |
1521 | * Ideally this should be pre-allocate by the OS at boot time | |
1522 | * But since it is a new feature and board data is loaded | |
1523 | * at init time, we have to workaround this from host. | |
1524 | * It is difficult to patch the firmware boot code, | |
1525 | * but possible in theory. | |
1526 | */ | |
1527 | if (ar->arTargetType == TARGET_TYPE_AR6003) { | |
1528 | param = AR6003_BOARD_EXT_DATA_ADDRESS; | |
1529 | if (BMIWriteMemory(ar->arHifDevice, | |
1530 | HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), | |
1531 | (A_UCHAR *)¶m, | |
1532 | 4) != A_OK) | |
1533 | { | |
1534 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n")); | |
1535 | return A_ERROR; | |
1536 | } | |
1537 | } | |
1538 | ||
1539 | ||
1540 | /* since BMIInit is called in the driver layer, we have to set the block | |
1541 | * size here for the target */ | |
1542 | ||
1543 | if (A_FAILED(ar6000_set_htc_params(ar->arHifDevice, | |
1544 | ar->arTargetType, | |
1545 | mbox_yield_limit, | |
1546 | 0 /* use default number of control buffers */ | |
1547 | ))) { | |
1548 | return A_ERROR; | |
1549 | } | |
1550 | ||
1551 | if (setupbtdev != 0) { | |
1552 | if (A_FAILED(ar6000_set_hci_bridge_flags(ar->arHifDevice, | |
1553 | ar->arTargetType, | |
1554 | setupbtdev))) { | |
1555 | return A_ERROR; | |
1556 | } | |
1557 | } | |
1558 | return A_OK; | |
1559 | } | |
1560 | ||
1561 | static void | |
1562 | init_netdev(struct net_device *dev, char *name) | |
1563 | { | |
1564 | dev->netdev_ops = &ar6000_netdev_ops; | |
1565 | dev->watchdog_timeo = AR6000_TX_TIMEOUT; | |
1566 | dev->wireless_handlers = &ath_iw_handler_def; | |
1567 | ||
1568 | ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ | |
1569 | ||
1570 | /* | |
1571 | * We need the OS to provide us with more headroom in order to | |
1572 | * perform dix to 802.3, WMI header encap, and the HTC header | |
1573 | */ | |
1574 | if (processDot11Hdr) { | |
1575 | 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; | |
1576 | } else { | |
1577 | dev->hard_header_len = ETH_HLEN + sizeof(ATH_LLC_SNAP_HDR) + | |
1578 | sizeof(WMI_DATA_HDR) + HTC_HEADER_LEN + WMI_MAX_TX_META_SZ + LINUX_HACK_FUDGE_FACTOR; | |
1579 | } | |
1580 | ||
1581 | if (name[0]) | |
1582 | { | |
1583 | strcpy(dev->name, name); | |
1584 | } | |
1585 | ||
1586 | #ifdef SET_MODULE_OWNER | |
1587 | SET_MODULE_OWNER(dev); | |
1588 | #endif | |
1589 | ||
1590 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
1591 | if(csumOffload){ | |
1592 | dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/ | |
1593 | } | |
1594 | #endif | |
1595 | ||
1596 | return; | |
1597 | } | |
1598 | ||
1599 | /* | |
1600 | * HTC Event handlers | |
1601 | */ | |
1602 | static A_STATUS | |
1603 | ar6000_avail_ev(void *context, void *hif_handle) | |
1604 | { | |
1605 | int i; | |
1606 | struct net_device *dev; | |
1607 | void *ar_netif; | |
1608 | AR_SOFTC_T *ar; | |
1609 | int device_index = 0; | |
1610 | HTC_INIT_INFO htcInfo; | |
1611 | #ifdef ATH6K_CONFIG_CFG80211 | |
1612 | struct wireless_dev *wdev; | |
1613 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
1614 | A_STATUS init_status = A_OK; | |
1615 | ||
1616 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_available\n")); | |
1617 | ||
1618 | for (i=0; i < MAX_AR6000; i++) { | |
1619 | if (ar6000_devices[i] == NULL) { | |
1620 | break; | |
1621 | } | |
1622 | } | |
1623 | ||
1624 | if (i == MAX_AR6000) { | |
1625 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: max devices reached\n")); | |
1626 | return A_ERROR; | |
1627 | } | |
1628 | ||
1629 | /* Save this. It gives a bit better readability especially since */ | |
1630 | /* we use another local "i" variable below. */ | |
1631 | device_index = i; | |
1632 | ||
1633 | #ifdef ATH6K_CONFIG_CFG80211 | |
1634 | wdev = ar6k_cfg80211_init(NULL); | |
1635 | if (IS_ERR(wdev)) { | |
1636 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__)); | |
1637 | return A_ERROR; | |
1638 | } | |
1639 | ar_netif = wdev_priv(wdev); | |
1640 | #else | |
1641 | dev = alloc_etherdev(sizeof(AR_SOFTC_T)); | |
1642 | if (dev == NULL) { | |
1643 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n")); | |
1644 | return A_ERROR; | |
1645 | } | |
1646 | ether_setup(dev); | |
1647 | ar_netif = ar6k_priv(dev); | |
1648 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
1649 | ||
1650 | if (ar_netif == NULL) { | |
1651 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__)); | |
1652 | return A_ERROR; | |
1653 | } | |
1654 | ||
1655 | A_MEMZERO(ar_netif, sizeof(AR_SOFTC_T)); | |
1656 | ar = (AR_SOFTC_T *)ar_netif; | |
1657 | ||
1658 | #ifdef ATH6K_CONFIG_CFG80211 | |
1659 | ar->wdev = wdev; | |
1660 | wdev->iftype = NL80211_IFTYPE_STATION; | |
1661 | ||
1662 | dev = alloc_netdev_mq(0, "wlan%d", ether_setup, 1); | |
1663 | if (!dev) { | |
1664 | printk(KERN_CRIT "AR6K: no memory for network device instance\n"); | |
1665 | ar6k_cfg80211_deinit(ar); | |
1666 | return A_ERROR; | |
1667 | } | |
1668 | ||
1669 | dev->ieee80211_ptr = wdev; | |
1670 | SET_NETDEV_DEV(dev, wiphy_dev(wdev->wiphy)); | |
1671 | wdev->netdev = dev; | |
1672 | ar->arNetworkType = INFRA_NETWORK; | |
1673 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
1674 | ||
1675 | init_netdev(dev, ifname); | |
1676 | ||
1677 | #ifdef SET_NETDEV_DEV | |
1678 | if (ar_netif) { | |
1679 | HIF_DEVICE_OS_DEVICE_INFO osDevInfo; | |
1680 | A_MEMZERO(&osDevInfo, sizeof(osDevInfo)); | |
1681 | if ( A_SUCCESS( HIFConfigureDevice(hif_handle, HIF_DEVICE_GET_OS_DEVICE, | |
1682 | &osDevInfo, sizeof(osDevInfo))) ) { | |
1683 | SET_NETDEV_DEV(dev, osDevInfo.pOSDevice); | |
1684 | } | |
1685 | } | |
1686 | #endif | |
1687 | ||
1688 | ar->arNetDev = dev; | |
1689 | ar->arHifDevice = hif_handle; | |
1690 | ar->arWlanState = WLAN_ENABLED; | |
1691 | ar->arDeviceIndex = device_index; | |
1692 | ||
1693 | ar->arWlanPowerState = WLAN_POWER_STATE_ON; | |
1694 | ar->arWlanOff = FALSE; /* We are in ON state */ | |
1695 | #ifdef CONFIG_PM | |
1696 | ar->arWowState = WLAN_WOW_STATE_NONE; | |
1697 | ar->arBTOff = TRUE; /* BT chip assumed to be OFF */ | |
1698 | ar->arBTSharing = WLAN_CONFIG_BT_SHARING; | |
1699 | ar->arWlanOffConfig = WLAN_CONFIG_WLAN_OFF; | |
1700 | ar->arSuspendConfig = WLAN_CONFIG_PM_SUSPEND; | |
1701 | ar->arWow2Config = WLAN_CONFIG_PM_WOW2; | |
1702 | #endif /* CONFIG_PM */ | |
1703 | ||
1704 | A_INIT_TIMER(&ar->arHBChallengeResp.timer, ar6000_detect_error, dev); | |
1705 | ar->arHBChallengeResp.seqNum = 0; | |
1706 | ar->arHBChallengeResp.outstanding = FALSE; | |
1707 | ar->arHBChallengeResp.missCnt = 0; | |
1708 | ar->arHBChallengeResp.frequency = AR6000_HB_CHALLENGE_RESP_FREQ_DEFAULT; | |
1709 | ar->arHBChallengeResp.missThres = AR6000_HB_CHALLENGE_RESP_MISS_THRES_DEFAULT; | |
1710 | ||
1711 | ar6000_init_control_info(ar); | |
1712 | init_waitqueue_head(&arEvent); | |
1713 | sema_init(&ar->arSem, 1); | |
1714 | ar->bIsDestroyProgress = FALSE; | |
1715 | ||
1716 | INIT_HTC_PACKET_QUEUE(&ar->amsdu_rx_buffer_queue); | |
1717 | ||
1718 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
1719 | A_INIT_TIMER(&aptcTimer, aptcTimerHandler, ar); | |
1720 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
1721 | ||
1722 | A_INIT_TIMER(&ar->disconnect_timer, disconnect_timer_handler, dev); | |
1723 | ||
1724 | BMIInit(); | |
1725 | ||
1726 | if (bmienable) { | |
1727 | ar6000_sysfs_bmi_init(ar); | |
1728 | } | |
1729 | ||
1730 | { | |
1731 | struct bmi_target_info targ_info; | |
1732 | ||
1733 | if (BMIGetTargetInfo(ar->arHifDevice, &targ_info) != A_OK) { | |
1734 | init_status = A_ERROR; | |
1735 | goto avail_ev_failed; | |
1736 | } | |
1737 | ||
1738 | ar->arVersion.target_ver = targ_info.target_ver; | |
1739 | ar->arTargetType = targ_info.target_type; | |
1740 | ||
1741 | /* do any target-specific preparation that can be done through BMI */ | |
1742 | if (ar6000_prepare_target(ar->arHifDevice, | |
1743 | targ_info.target_type, | |
1744 | targ_info.target_ver) != A_OK) { | |
1745 | init_status = A_ERROR; | |
1746 | goto avail_ev_failed; | |
1747 | } | |
1748 | ||
1749 | } | |
1750 | ||
1751 | if (ar6000_configure_target(ar) != A_OK) { | |
1752 | init_status = A_ERROR; | |
1753 | goto avail_ev_failed; | |
1754 | } | |
1755 | ||
1756 | A_MEMZERO(&htcInfo,sizeof(htcInfo)); | |
1757 | htcInfo.pContext = ar; | |
1758 | htcInfo.TargetFailure = ar6000_target_failure; | |
1759 | ||
1760 | ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo); | |
1761 | ||
1762 | if (ar->arHtcTarget == NULL) { | |
1763 | init_status = A_ERROR; | |
1764 | goto avail_ev_failed; | |
1765 | } | |
1766 | ||
1767 | spin_lock_init(&ar->arLock); | |
1768 | ||
1769 | #ifdef WAPI_ENABLE | |
1770 | ar->arWapiEnable = 0; | |
1771 | #endif | |
1772 | ||
1773 | ||
1774 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
1775 | if(csumOffload){ | |
1776 | /*if external frame work is also needed, change and use an extended rxMetaVerion*/ | |
1777 | ar->rxMetaVersion=WMI_META_VERSION_2; | |
1778 | } | |
1779 | #endif | |
1780 | ||
1781 | #ifdef ATH_AR6K_11N_SUPPORT | |
1782 | if((ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs)) == NULL) { | |
1783 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__)); | |
1784 | init_status = A_ERROR; | |
1785 | goto avail_ev_failed; | |
1786 | } | |
1787 | ||
1788 | aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack); | |
1789 | #endif | |
1790 | ||
1791 | HIFClaimDevice(ar->arHifDevice, ar); | |
1792 | ||
1793 | /* We only register the device in the global list if we succeed. */ | |
1794 | /* If the device is in the global list, it will be destroyed */ | |
1795 | /* when the module is unloaded. */ | |
1796 | ar6000_devices[device_index] = dev; | |
1797 | ||
1798 | /* Don't install the init function if BMI is requested */ | |
1799 | if (!bmienable) { | |
1800 | ar6000_netdev_ops.ndo_init = ar6000_init; | |
1801 | } else { | |
1802 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); | |
1803 | if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || | |
1804 | (wlaninitmode == WLAN_INIT_MODE_DRV)) | |
1805 | { | |
1806 | A_STATUS status = A_OK; | |
1807 | do { | |
1808 | if ((status = ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK) | |
1809 | { | |
1810 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); | |
1811 | break; | |
1812 | } | |
1813 | #ifdef HTC_RAW_INTERFACE | |
1814 | break; /* Don't call ar6000_init for ART */ | |
1815 | #endif | |
1816 | rtnl_lock(); | |
1817 | status = (ar6000_init(dev)==0) ? A_OK : A_ERROR; | |
1818 | rtnl_unlock(); | |
1819 | if (status != A_OK) { | |
1820 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n")); | |
1821 | } | |
1822 | } while (FALSE); | |
1823 | ||
1824 | if (status != A_OK) { | |
1825 | init_status = status; | |
1826 | goto avail_ev_failed; | |
1827 | } | |
1828 | } | |
1829 | } | |
1830 | ||
1831 | /* This runs the init function if registered */ | |
1832 | if (register_netdev(dev)) { | |
1833 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n")); | |
1834 | ar6000_destroy(dev, 0); | |
1835 | return A_ERROR; | |
1836 | } | |
1837 | ||
1838 | is_netdev_registered = 1; | |
1839 | ||
1840 | #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT | |
1841 | arApNetDev = NULL; | |
1842 | #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ | |
1843 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_avail: name=%s hifdevice=0x%lx, dev=0x%lx (%d), ar=0x%lx\n", | |
1844 | dev->name, (unsigned long)ar->arHifDevice, (unsigned long)dev, device_index, | |
1845 | (unsigned long)ar)); | |
1846 | ||
1847 | avail_ev_failed : | |
1848 | if (A_FAILED(init_status)) { | |
1849 | if (bmienable) { | |
1850 | ar6000_sysfs_bmi_deinit(ar); | |
1851 | } | |
1852 | } | |
1853 | ||
1854 | return init_status; | |
1855 | } | |
1856 | ||
1857 | static void ar6000_target_failure(void *Instance, A_STATUS Status) | |
1858 | { | |
1859 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Instance; | |
1860 | WMI_TARGET_ERROR_REPORT_EVENT errEvent; | |
1861 | static A_BOOL sip = FALSE; | |
1862 | ||
1863 | if (Status != A_OK) { | |
1864 | ||
1865 | printk(KERN_ERR "ar6000_target_failure: target asserted \n"); | |
1866 | ||
1867 | if (timer_pending(&ar->arHBChallengeResp.timer)) { | |
1868 | A_UNTIMEOUT(&ar->arHBChallengeResp.timer); | |
1869 | } | |
1870 | ||
1871 | /* try dumping target assertion information (if any) */ | |
1872 | ar6000_dump_target_assert_info(ar->arHifDevice,ar->arTargetType); | |
1873 | ||
1874 | /* | |
1875 | * Fetch the logs from the target via the diagnostic | |
1876 | * window. | |
1877 | */ | |
1878 | ar6000_dbglog_get_debug_logs(ar); | |
1879 | ||
1880 | /* Report the error only once */ | |
1881 | if (!sip) { | |
1882 | sip = TRUE; | |
1883 | errEvent.errorVal = WMI_TARGET_COM_ERR | | |
1884 | WMI_TARGET_FATAL_ERR; | |
1885 | ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID, | |
1886 | (A_UINT8 *)&errEvent, | |
1887 | sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); | |
1888 | } | |
1889 | } | |
1890 | } | |
1891 | ||
1892 | static A_STATUS | |
1893 | ar6000_unavail_ev(void *context, void *hif_handle) | |
1894 | { | |
1895 | AR_SOFTC_T *ar = (AR_SOFTC_T *)context; | |
1896 | /* NULL out it's entry in the global list */ | |
1897 | ar6000_devices[ar->arDeviceIndex] = NULL; | |
1898 | ar6000_destroy(ar->arNetDev, 1); | |
1899 | ||
1900 | return A_OK; | |
1901 | } | |
1902 | ||
1903 | void | |
1904 | ar6000_restart_endpoint(struct net_device *dev) | |
1905 | { | |
1906 | A_STATUS status = A_OK; | |
1907 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
1908 | ||
1909 | BMIInit(); | |
1910 | do { | |
1911 | if ( (status=ar6000_configure_target(ar))!=A_OK) | |
1912 | break; | |
1913 | if ( (status=ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != A_OK) | |
1914 | { | |
1915 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); | |
1916 | break; | |
1917 | } | |
1918 | rtnl_lock(); | |
1919 | status = (ar6000_init(dev)==0) ? A_OK : A_ERROR; | |
1920 | rtnl_unlock(); | |
1921 | ||
1922 | if (status!=A_OK) { | |
1923 | break; | |
1924 | } | |
1925 | if (ar->arSsidLen && ar->arWlanState == WLAN_ENABLED) { | |
1926 | ar6000_connect_to_ap(ar); | |
1927 | } | |
1928 | } while (0); | |
1929 | ||
1930 | if (status==A_OK) { | |
1931 | return; | |
1932 | } | |
1933 | ||
1934 | ar6000_devices[ar->arDeviceIndex] = NULL; | |
1935 | ar6000_destroy(ar->arNetDev, 1); | |
1936 | } | |
1937 | ||
1938 | void | |
1939 | ar6000_stop_endpoint(struct net_device *dev, A_BOOL keepprofile, A_BOOL getdbglogs) | |
1940 | { | |
1941 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
1942 | ||
1943 | /* Stop the transmit queues */ | |
1944 | netif_stop_queue(dev); | |
1945 | ||
1946 | /* Disable the target and the interrupts associated with it */ | |
1947 | if (ar->arWmiReady == TRUE) | |
1948 | { | |
1949 | if (!bypasswmi) | |
1950 | { | |
1951 | if (ar->arConnected == TRUE || ar->arConnectPending == TRUE) | |
1952 | { | |
1953 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Disconnect\n", __func__)); | |
1954 | if (!keepprofile) { | |
1955 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
1956 | ar6000_init_profile_info(ar); | |
1957 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
1958 | } | |
1959 | wmi_disconnect_cmd(ar->arWmi); | |
1960 | } | |
1961 | ||
1962 | A_UNTIMEOUT(&ar->disconnect_timer); | |
1963 | ||
1964 | if (getdbglogs) { | |
1965 | ar6000_dbglog_get_debug_logs(ar); | |
1966 | } | |
1967 | ||
1968 | ar->arWmiReady = FALSE; | |
1969 | wmi_shutdown(ar->arWmi); | |
1970 | ar->arWmiEnabled = FALSE; | |
1971 | ar->arWmi = NULL; | |
1972 | /* | |
1973 | * After wmi_shudown all WMI events will be dropped. | |
1974 | * We need to cleanup the buffers allocated in AP mode | |
1975 | * and give disconnect notification to stack, which usually | |
1976 | * happens in the disconnect_event. | |
1977 | * Simulate the disconnect_event by calling the function directly. | |
1978 | * Sometimes disconnect_event will be received when the debug logs | |
1979 | * are collected. | |
1980 | */ | |
1981 | if (ar->arConnected == TRUE || ar->arConnectPending == TRUE) { | |
1982 | if(ar->arNetworkType & AP_NETWORK) { | |
1983 | ar6000_disconnect_event(ar, DISCONNECT_CMD, bcast_mac, 0, NULL, 0); | |
1984 | } else { | |
1985 | ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0); | |
1986 | } | |
1987 | ar->arConnected = FALSE; | |
1988 | ar->arConnectPending = FALSE; | |
1989 | } | |
1990 | #ifdef USER_KEYS | |
1991 | ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; | |
1992 | ar->user_key_ctrl = 0; | |
1993 | #endif | |
1994 | } | |
1995 | ||
1996 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__)); | |
1997 | } | |
1998 | else | |
1999 | { | |
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)); | |
2002 | ||
2003 | /* Shut down WMI if we have started it */ | |
2004 | if(ar->arWmiEnabled == TRUE) | |
2005 | { | |
2006 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): Shut down WMI\n", __func__)); | |
2007 | wmi_shutdown(ar->arWmi); | |
2008 | ar->arWmiEnabled = FALSE; | |
2009 | ar->arWmi = NULL; | |
2010 | } | |
2011 | } | |
2012 | ||
2013 | if (ar->arHtcTarget != NULL) { | |
2014 | #ifdef EXPORT_HCI_BRIDGE_INTERFACE | |
2015 | if (NULL != ar6kHciTransCallbacks.cleanupTransport) { | |
2016 | ar6kHciTransCallbacks.cleanupTransport(NULL); | |
2017 | } | |
2018 | #else | |
2019 | // FIXME: workaround to reset BT's UART baud rate to default | |
2020 | if (NULL != ar->exitCallback) { | |
2021 | AR3K_CONFIG_INFO ar3kconfig; | |
2022 | A_STATUS status; | |
2023 | ||
2024 | A_MEMZERO(&ar3kconfig,sizeof(ar3kconfig)); | |
2025 | ar6000_set_default_ar3kconfig(ar, (void *)&ar3kconfig); | |
2026 | status = ar->exitCallback(&ar3kconfig); | |
2027 | if (A_OK != status) { | |
2028 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Failed to reset AR3K baud rate! \n")); | |
2029 | } | |
2030 | } | |
2031 | // END workaround | |
2032 | if (setuphci) | |
2033 | ar6000_cleanup_hci(ar); | |
2034 | #endif | |
2035 | #ifdef EXPORT_HCI_PAL_INTERFACE | |
2036 | if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.cleanupTransport)) { | |
2037 | ar6kHciPalCallbacks_g.cleanupTransport(ar); | |
2038 | } | |
2039 | #else | |
2040 | /* cleanup hci pal driver data structures */ | |
2041 | if(setuphcipal) | |
2042 | ar6k_cleanup_hci_pal(ar); | |
2043 | #endif | |
2044 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n")); | |
2045 | /* stop HTC */ | |
2046 | HTCStop(ar->arHtcTarget); | |
2047 | } | |
2048 | ||
2049 | if (resetok) { | |
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 | A_BOOL coldReset = (ar->arTargetType == TARGET_TYPE_AR6003) ? TRUE: FALSE; | |
2056 | ar6000_reset_device(ar->arHifDevice, ar->arTargetType, TRUE, coldReset); | |
2057 | } | |
2058 | } else { | |
2059 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Host does not want target reset. \n")); | |
2060 | } | |
2061 | /* Done with cookies */ | |
2062 | ar6000_cookie_cleanup(ar); | |
2063 | } | |
2064 | /* | |
2065 | * We need to differentiate between the surprise and planned removal of the | |
2066 | * device because of the following consideration: | |
2067 | * - In case of surprise removal, the hcd already frees up the pending | |
2068 | * for the device and hence there is no need to unregister the function | |
2069 | * driver inorder to get these requests. For planned removal, the function | |
2070 | * driver has to explictly unregister itself to have the hcd return all the | |
2071 | * pending requests before the data structures for the devices are freed up. | |
2072 | * Note that as per the current implementation, the function driver will | |
2073 | * end up releasing all the devices since there is no API to selectively | |
2074 | * release a particular device. | |
2075 | * - Certain commands issued to the target can be skipped for surprise | |
2076 | * removal since they will anyway not go through. | |
2077 | */ | |
2078 | void | |
2079 | ar6000_destroy(struct net_device *dev, unsigned int unregister) | |
2080 | { | |
2081 | AR_SOFTC_T *ar; | |
2082 | ||
2083 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("+ar6000_destroy \n")); | |
2084 | ||
2085 | if((dev == NULL) || ((ar = ar6k_priv(dev)) == NULL)) | |
2086 | { | |
2087 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): Failed to get device structure.\n", __func__)); | |
2088 | return; | |
2089 | } | |
2090 | ||
2091 | ar->bIsDestroyProgress = TRUE; | |
2092 | ||
2093 | if (down_interruptible(&ar->arSem)) { | |
2094 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s(): down_interruptible failed \n", __func__)); | |
2095 | return; | |
2096 | } | |
2097 | ||
2098 | if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) { | |
2099 | /* only stop endpoint if we are not stop it in suspend_ev */ | |
2100 | ar6000_stop_endpoint(dev, FALSE, TRUE); | |
2101 | } else { | |
2102 | /* clear up the platform power state before rmmod */ | |
2103 | plat_setup_power(1,0); | |
2104 | } | |
2105 | ||
2106 | ar->arWlanState = WLAN_DISABLED; | |
2107 | if (ar->arHtcTarget != NULL) { | |
2108 | /* destroy HTC */ | |
2109 | HTCDestroy(ar->arHtcTarget); | |
2110 | } | |
2111 | if (ar->arHifDevice != NULL) { | |
2112 | /*release the device so we do not get called back on remove incase we | |
2113 | * we're explicity destroyed by module unload */ | |
2114 | HIFReleaseDevice(ar->arHifDevice); | |
2115 | HIFShutDownDevice(ar->arHifDevice); | |
2116 | } | |
2117 | #ifdef ATH_AR6K_11N_SUPPORT | |
2118 | aggr_module_destroy(ar->aggr_cntxt); | |
2119 | #endif | |
2120 | ||
2121 | /* Done with cookies */ | |
2122 | ar6000_cookie_cleanup(ar); | |
2123 | ||
2124 | /* cleanup any allocated AMSDU buffers */ | |
2125 | ar6000_cleanup_amsdu_rxbufs(ar); | |
2126 | ||
2127 | if (bmienable) { | |
2128 | ar6000_sysfs_bmi_deinit(ar); | |
2129 | } | |
2130 | ||
2131 | /* Cleanup BMI */ | |
2132 | BMICleanup(); | |
2133 | ||
2134 | /* Clear the tx counters */ | |
2135 | memset(tx_attempt, 0, sizeof(tx_attempt)); | |
2136 | memset(tx_post, 0, sizeof(tx_post)); | |
2137 | memset(tx_complete, 0, sizeof(tx_complete)); | |
2138 | ||
2139 | #ifdef HTC_RAW_INTERFACE | |
2140 | if (ar->arRawHtc) { | |
2141 | A_FREE(ar->arRawHtc); | |
2142 | ar->arRawHtc = NULL; | |
2143 | } | |
2144 | #endif | |
2145 | /* Free up the device data structure */ | |
2146 | if (unregister && is_netdev_registered) { | |
2147 | unregister_netdev(dev); | |
2148 | is_netdev_registered = 0; | |
2149 | } | |
2150 | #ifndef free_netdev | |
2151 | kfree(dev); | |
2152 | #else | |
2153 | free_netdev(dev); | |
2154 | #endif | |
2155 | ||
2156 | #ifdef ATH6K_CONFIG_CFG80211 | |
2157 | ar6k_cfg80211_deinit(ar); | |
2158 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
2159 | ||
2160 | #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT | |
2161 | ar6000_remove_ap_interface(); | |
2162 | #endif /*CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ | |
2163 | ||
2164 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("-ar6000_destroy \n")); | |
2165 | } | |
2166 | ||
2167 | static void disconnect_timer_handler(unsigned long ptr) | |
2168 | { | |
2169 | struct net_device *dev = (struct net_device *)ptr; | |
2170 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2171 | ||
2172 | A_UNTIMEOUT(&ar->disconnect_timer); | |
2173 | ||
2174 | ar6000_init_profile_info(ar); | |
2175 | wmi_disconnect_cmd(ar->arWmi); | |
2176 | } | |
2177 | ||
2178 | static void ar6000_detect_error(unsigned long ptr) | |
2179 | { | |
2180 | struct net_device *dev = (struct net_device *)ptr; | |
2181 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2182 | WMI_TARGET_ERROR_REPORT_EVENT errEvent; | |
2183 | ||
2184 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
2185 | ||
2186 | if (ar->arHBChallengeResp.outstanding) { | |
2187 | ar->arHBChallengeResp.missCnt++; | |
2188 | } else { | |
2189 | ar->arHBChallengeResp.missCnt = 0; | |
2190 | } | |
2191 | ||
2192 | if (ar->arHBChallengeResp.missCnt > ar->arHBChallengeResp.missThres) { | |
2193 | /* Send Error Detect event to the application layer and do not reschedule the error detection module timer */ | |
2194 | ar->arHBChallengeResp.missCnt = 0; | |
2195 | ar->arHBChallengeResp.seqNum = 0; | |
2196 | errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR; | |
2197 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
2198 | ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID, | |
2199 | (A_UINT8 *)&errEvent, | |
2200 | sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); | |
2201 | return; | |
2202 | } | |
2203 | ||
2204 | /* Generate the sequence number for the next challenge */ | |
2205 | ar->arHBChallengeResp.seqNum++; | |
2206 | ar->arHBChallengeResp.outstanding = TRUE; | |
2207 | ||
2208 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
2209 | ||
2210 | /* Send the challenge on the control channel */ | |
2211 | if (wmi_get_challenge_resp_cmd(ar->arWmi, ar->arHBChallengeResp.seqNum, DRV_HB_CHALLENGE) != A_OK) { | |
2212 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to send heart beat challenge\n")); | |
2213 | } | |
2214 | ||
2215 | ||
2216 | /* Reschedule the timer for the next challenge */ | |
2217 | A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0); | |
2218 | } | |
2219 | ||
2220 | void ar6000_init_profile_info(AR_SOFTC_T *ar) | |
2221 | { | |
2222 | ar->arSsidLen = 0; | |
2223 | A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); | |
2224 | ||
2225 | switch(fwmode) { | |
2226 | case HI_OPTION_FW_MODE_IBSS: | |
2227 | ar->arNetworkType = ar->arNextMode = ADHOC_NETWORK; | |
2228 | break; | |
2229 | case HI_OPTION_FW_MODE_BSS_STA: | |
2230 | ar->arNetworkType = ar->arNextMode = INFRA_NETWORK; | |
2231 | break; | |
2232 | case HI_OPTION_FW_MODE_AP: | |
2233 | ar->arNetworkType = ar->arNextMode = AP_NETWORK; | |
2234 | break; | |
2235 | } | |
2236 | ||
2237 | ar->arDot11AuthMode = OPEN_AUTH; | |
2238 | ar->arAuthMode = NONE_AUTH; | |
2239 | ar->arPairwiseCrypto = NONE_CRYPT; | |
2240 | ar->arPairwiseCryptoLen = 0; | |
2241 | ar->arGroupCrypto = NONE_CRYPT; | |
2242 | ar->arGroupCryptoLen = 0; | |
2243 | A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList)); | |
2244 | A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid)); | |
2245 | A_MEMZERO(ar->arBssid, sizeof(ar->arBssid)); | |
2246 | ar->arBssChannel = 0; | |
2247 | ar->arConnected = FALSE; | |
2248 | } | |
2249 | ||
2250 | static void | |
2251 | ar6000_init_control_info(AR_SOFTC_T *ar) | |
2252 | { | |
2253 | ar->arWmiEnabled = FALSE; | |
2254 | ar6000_init_profile_info(ar); | |
2255 | ar->arDefTxKeyIndex = 0; | |
2256 | A_MEMZERO(ar->arWepKeyList, sizeof(ar->arWepKeyList)); | |
2257 | ar->arChannelHint = 0; | |
2258 | ar->arListenIntervalT = A_DEFAULT_LISTEN_INTERVAL; | |
2259 | ar->arListenIntervalB = 0; | |
2260 | ar->arVersion.host_ver = AR6K_SW_VERSION; | |
2261 | ar->arRssi = 0; | |
2262 | ar->arTxPwr = 0; | |
2263 | ar->arTxPwrSet = FALSE; | |
2264 | ar->arSkipScan = 0; | |
2265 | ar->arBeaconInterval = 0; | |
2266 | ar->arBitRate = 0; | |
2267 | ar->arMaxRetries = 0; | |
2268 | ar->arWmmEnabled = TRUE; | |
2269 | ar->intra_bss = 1; | |
2270 | ar->scan_triggered = 0; | |
2271 | A_MEMZERO(&ar->scParams, sizeof(ar->scParams)); | |
2272 | ar->scParams.shortScanRatio = WMI_SHORTSCANRATIO_DEFAULT; | |
2273 | ar->scParams.scanCtrlFlags = DEFAULT_SCAN_CTRL_FLAGS; | |
2274 | ||
2275 | /* Initialize the AP mode state info */ | |
2276 | { | |
2277 | A_UINT8 ctr; | |
2278 | A_MEMZERO((A_UINT8 *)ar->sta_list, AP_MAX_NUM_STA * sizeof(sta_t)); | |
2279 | ||
2280 | /* init the Mutexes */ | |
2281 | A_MUTEX_INIT(&ar->mcastpsqLock); | |
2282 | ||
2283 | /* Init the PS queues */ | |
2284 | for (ctr=0; ctr < AP_MAX_NUM_STA ; ctr++) { | |
2285 | A_MUTEX_INIT(&ar->sta_list[ctr].psqLock); | |
2286 | A_NETBUF_QUEUE_INIT(&ar->sta_list[ctr].psq); | |
2287 | } | |
2288 | ||
2289 | ar->ap_profile_flag = 0; | |
2290 | A_NETBUF_QUEUE_INIT(&ar->mcastpsq); | |
2291 | ||
2292 | A_MEMCPY(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3); | |
2293 | ar->ap_wmode = DEF_AP_WMODE_G; | |
2294 | ar->ap_dtim_period = DEF_AP_DTIM; | |
2295 | ar->ap_beacon_interval = DEF_BEACON_INTERVAL; | |
2296 | } | |
2297 | } | |
2298 | ||
2299 | static int | |
2300 | ar6000_open(struct net_device *dev) | |
2301 | { | |
2302 | unsigned long flags; | |
2303 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2304 | ||
2305 | spin_lock_irqsave(&ar->arLock, flags); | |
2306 | ||
2307 | #ifdef ATH6K_CONFIG_CFG80211 | |
2308 | if(ar->arWlanState == WLAN_DISABLED) { | |
2309 | ar->arWlanState = WLAN_ENABLED; | |
2310 | } | |
2311 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
2312 | ||
2313 | if( ar->arConnected || bypasswmi) { | |
2314 | netif_carrier_on(dev); | |
2315 | /* Wake up the queues */ | |
2316 | netif_wake_queue(dev); | |
2317 | } | |
2318 | else | |
2319 | netif_carrier_off(dev); | |
2320 | ||
2321 | spin_unlock_irqrestore(&ar->arLock, flags); | |
2322 | return 0; | |
2323 | } | |
2324 | ||
2325 | static int | |
2326 | ar6000_close(struct net_device *dev) | |
2327 | { | |
2328 | #ifdef ATH6K_CONFIG_CFG80211 | |
2329 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2330 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
2331 | netif_stop_queue(dev); | |
2332 | ||
2333 | #ifdef ATH6K_CONFIG_CFG80211 | |
2334 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
2335 | if (ar->arConnected == TRUE || ar->arConnectPending == TRUE) { | |
2336 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
2337 | wmi_disconnect_cmd(ar->arWmi); | |
2338 | } else { | |
2339 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
2340 | } | |
2341 | ||
2342 | if(ar->arWmiReady == TRUE) { | |
2343 | if (wmi_scanparams_cmd(ar->arWmi, 0xFFFF, 0, | |
2344 | 0, 0, 0, 0, 0, 0, 0, 0) != A_OK) { | |
2345 | return -EIO; | |
2346 | } | |
2347 | ar->arWlanState = WLAN_DISABLED; | |
2348 | } | |
2349 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
2350 | ||
2351 | return 0; | |
2352 | } | |
2353 | ||
2354 | /* connect to a service */ | |
2355 | static A_STATUS ar6000_connectservice(AR_SOFTC_T *ar, | |
2356 | HTC_SERVICE_CONNECT_REQ *pConnect, | |
2357 | char *pDesc) | |
2358 | { | |
2359 | A_STATUS status; | |
2360 | HTC_SERVICE_CONNECT_RESP response; | |
2361 | ||
2362 | do { | |
2363 | ||
2364 | A_MEMZERO(&response,sizeof(response)); | |
2365 | ||
2366 | status = HTCConnectService(ar->arHtcTarget, | |
2367 | pConnect, | |
2368 | &response); | |
2369 | ||
2370 | if (A_FAILED(status)) { | |
2371 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" Failed to connect to %s service status:%d \n", | |
2372 | pDesc, status)); | |
2373 | break; | |
2374 | } | |
2375 | switch (pConnect->ServiceID) { | |
2376 | case WMI_CONTROL_SVC : | |
2377 | if (ar->arWmiEnabled) { | |
2378 | /* set control endpoint for WMI use */ | |
2379 | wmi_set_control_ep(ar->arWmi, response.Endpoint); | |
2380 | } | |
2381 | /* save EP for fast lookup */ | |
2382 | ar->arControlEp = response.Endpoint; | |
2383 | break; | |
2384 | case WMI_DATA_BE_SVC : | |
2385 | arSetAc2EndpointIDMap(ar, WMM_AC_BE, response.Endpoint); | |
2386 | break; | |
2387 | case WMI_DATA_BK_SVC : | |
2388 | arSetAc2EndpointIDMap(ar, WMM_AC_BK, response.Endpoint); | |
2389 | break; | |
2390 | case WMI_DATA_VI_SVC : | |
2391 | arSetAc2EndpointIDMap(ar, WMM_AC_VI, response.Endpoint); | |
2392 | break; | |
2393 | case WMI_DATA_VO_SVC : | |
2394 | arSetAc2EndpointIDMap(ar, WMM_AC_VO, response.Endpoint); | |
2395 | break; | |
2396 | default: | |
2397 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ServiceID not mapped %d\n", pConnect->ServiceID)); | |
2398 | status = A_EINVAL; | |
2399 | break; | |
2400 | } | |
2401 | ||
2402 | } while (FALSE); | |
2403 | ||
2404 | return status; | |
2405 | } | |
2406 | ||
2407 | void ar6000_TxDataCleanup(AR_SOFTC_T *ar) | |
2408 | { | |
2409 | /* flush all the data (non-control) streams | |
2410 | * we only flush packets that are tagged as data, we leave any control packets that | |
2411 | * were in the TX queues alone */ | |
2412 | HTCFlushEndpoint(ar->arHtcTarget, | |
2413 | arAc2EndpointID(ar, WMM_AC_BE), | |
2414 | AR6K_DATA_PKT_TAG); | |
2415 | HTCFlushEndpoint(ar->arHtcTarget, | |
2416 | arAc2EndpointID(ar, WMM_AC_BK), | |
2417 | AR6K_DATA_PKT_TAG); | |
2418 | HTCFlushEndpoint(ar->arHtcTarget, | |
2419 | arAc2EndpointID(ar, WMM_AC_VI), | |
2420 | AR6K_DATA_PKT_TAG); | |
2421 | HTCFlushEndpoint(ar->arHtcTarget, | |
2422 | arAc2EndpointID(ar, WMM_AC_VO), | |
2423 | AR6K_DATA_PKT_TAG); | |
2424 | } | |
2425 | ||
2426 | HTC_ENDPOINT_ID | |
2427 | ar6000_ac2_endpoint_id ( void * devt, A_UINT8 ac) | |
2428 | { | |
2429 | AR_SOFTC_T *ar = (AR_SOFTC_T *) devt; | |
2430 | return(arAc2EndpointID(ar, ac)); | |
2431 | } | |
2432 | ||
2433 | A_UINT8 | |
2434 | ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep ) | |
2435 | { | |
2436 | AR_SOFTC_T *ar = (AR_SOFTC_T *) devt; | |
2437 | return(arEndpoint2Ac(ar, ep )); | |
2438 | } | |
2439 | ||
2440 | /* This function does one time initialization for the lifetime of the device */ | |
2441 | int ar6000_init(struct net_device *dev) | |
2442 | { | |
2443 | AR_SOFTC_T *ar; | |
2444 | A_STATUS status; | |
2445 | A_INT32 timeleft; | |
2446 | A_INT16 i; | |
2447 | int ret = 0; | |
2448 | #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) | |
2449 | WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd; | |
2450 | WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd; | |
2451 | #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ | |
2452 | ||
2453 | if((ar = ar6k_priv(dev)) == NULL) | |
2454 | { | |
2455 | return -EIO; | |
2456 | } | |
2457 | ||
2458 | if (wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) { | |
2459 | ||
2460 | ar6000_update_bdaddr(ar); | |
2461 | ||
2462 | if (enablerssicompensation) { | |
2463 | ar6000_copy_cust_data_from_target(ar->arHifDevice, ar->arTargetType); | |
2464 | read_rssi_compensation_param(ar); | |
2465 | for (i=-95; i<=0; i++) { | |
2466 | rssi_compensation_table[0-i] = rssi_compensation_calc(ar,i); | |
2467 | } | |
2468 | } | |
2469 | } | |
2470 | ||
2471 | dev_hold(dev); | |
2472 | rtnl_unlock(); | |
2473 | ||
2474 | /* Do we need to finish the BMI phase */ | |
2475 | if ((wlaninitmode == WLAN_INIT_MODE_USR || wlaninitmode == WLAN_INIT_MODE_DRV) && | |
2476 | (BMIDone(ar->arHifDevice) != A_OK)) | |
2477 | { | |
2478 | ret = -EIO; | |
2479 | goto ar6000_init_done; | |
2480 | } | |
2481 | ||
2482 | if (!bypasswmi) | |
2483 | { | |
2484 | #if 0 /* TBDXXX */ | |
2485 | if (ar->arVersion.host_ver != ar->arVersion.target_ver) { | |
2486 | A_PRINTF("WARNING: Host version 0x%x does not match Target " | |
2487 | " version 0x%x!\n", | |
2488 | ar->arVersion.host_ver, ar->arVersion.target_ver); | |
2489 | } | |
2490 | #endif | |
2491 | ||
2492 | /* Indicate that WMI is enabled (although not ready yet) */ | |
2493 | ar->arWmiEnabled = TRUE; | |
2494 | if ((ar->arWmi = wmi_init((void *) ar)) == NULL) | |
2495 | { | |
2496 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize WMI.\n", __func__)); | |
2497 | ret = -EIO; | |
2498 | goto ar6000_init_done; | |
2499 | } | |
2500 | ||
2501 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Got WMI @ 0x%lx.\n", __func__, | |
2502 | (unsigned long) ar->arWmi)); | |
2503 | } | |
2504 | ||
2505 | do { | |
2506 | HTC_SERVICE_CONNECT_REQ connect; | |
2507 | ||
2508 | /* the reason we have to wait for the target here is that the driver layer | |
2509 | * has to init BMI in order to set the host block size, | |
2510 | */ | |
2511 | status = HTCWaitTarget(ar->arHtcTarget); | |
2512 | ||
2513 | if (A_FAILED(status)) { | |
2514 | break; | |
2515 | } | |
2516 | ||
2517 | A_MEMZERO(&connect,sizeof(connect)); | |
2518 | /* meta data is unused for now */ | |
2519 | connect.pMetaData = NULL; | |
2520 | connect.MetaDataLength = 0; | |
2521 | /* these fields are the same for all service endpoints */ | |
2522 | connect.EpCallbacks.pContext = ar; | |
2523 | connect.EpCallbacks.EpTxCompleteMultiple = ar6000_tx_complete; | |
2524 | connect.EpCallbacks.EpRecv = ar6000_rx; | |
2525 | connect.EpCallbacks.EpRecvRefill = ar6000_rx_refill; | |
2526 | connect.EpCallbacks.EpSendFull = ar6000_tx_queue_full; | |
2527 | /* set the max queue depth so that our ar6000_tx_queue_full handler gets called. | |
2528 | * Linux has the peculiarity of not providing flow control between the | |
2529 | * NIC and the network stack. There is no API to indicate that a TX packet | |
2530 | * was sent which could provide some back pressure to the network stack. | |
2531 | * Under linux you would have to wait till the network stack consumed all sk_buffs | |
2532 | * before any back-flow kicked in. Which isn't very friendly. | |
2533 | * So we have to manage this ourselves */ | |
2534 | connect.MaxSendQueueDepth = MAX_DEFAULT_SEND_QUEUE_DEPTH; | |
2535 | connect.EpCallbacks.RecvRefillWaterMark = AR6000_MAX_RX_BUFFERS / 4; /* set to 25 % */ | |
2536 | if (0 == connect.EpCallbacks.RecvRefillWaterMark) { | |
2537 | connect.EpCallbacks.RecvRefillWaterMark++; | |
2538 | } | |
2539 | /* connect to control service */ | |
2540 | connect.ServiceID = WMI_CONTROL_SVC; | |
2541 | status = ar6000_connectservice(ar, | |
2542 | &connect, | |
2543 | "WMI CONTROL"); | |
2544 | if (A_FAILED(status)) { | |
2545 | break; | |
2546 | } | |
2547 | ||
2548 | connect.LocalConnectionFlags |= HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING; | |
2549 | /* limit the HTC message size on the send path, although we can receive A-MSDU frames of | |
2550 | * 4K, we will only send ethernet-sized (802.3) frames on the send path. */ | |
2551 | connect.MaxSendMsgSize = WMI_MAX_TX_DATA_FRAME_LENGTH; | |
2552 | ||
2553 | /* to reduce the amount of committed memory for larger A_MSDU frames, use the recv-alloc threshold | |
2554 | * mechanism for larger packets */ | |
2555 | connect.EpCallbacks.RecvAllocThreshold = AR6000_BUFFER_SIZE; | |
2556 | connect.EpCallbacks.EpRecvAllocThresh = ar6000_alloc_amsdu_rxbuf; | |
2557 | ||
2558 | /* for the remaining data services set the connection flag to reduce dribbling, | |
2559 | * if configured to do so */ | |
2560 | if (reduce_credit_dribble) { | |
2561 | connect.ConnectionFlags |= HTC_CONNECT_FLAGS_REDUCE_CREDIT_DRIBBLE; | |
2562 | /* the credit dribble trigger threshold is (reduce_credit_dribble - 1) for a value | |
2563 | * of 0-3 */ | |
2564 | connect.ConnectionFlags &= ~HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK; | |
2565 | connect.ConnectionFlags |= | |
2566 | ((A_UINT16)reduce_credit_dribble - 1) & HTC_CONNECT_FLAGS_THRESHOLD_LEVEL_MASK; | |
2567 | } | |
2568 | /* connect to best-effort service */ | |
2569 | connect.ServiceID = WMI_DATA_BE_SVC; | |
2570 | ||
2571 | status = ar6000_connectservice(ar, | |
2572 | &connect, | |
2573 | "WMI DATA BE"); | |
2574 | if (A_FAILED(status)) { | |
2575 | break; | |
2576 | } | |
2577 | ||
2578 | /* connect to back-ground | |
2579 | * map this to WMI LOW_PRI */ | |
2580 | connect.ServiceID = WMI_DATA_BK_SVC; | |
2581 | status = ar6000_connectservice(ar, | |
2582 | &connect, | |
2583 | "WMI DATA BK"); | |
2584 | if (A_FAILED(status)) { | |
2585 | break; | |
2586 | } | |
2587 | ||
2588 | /* connect to Video service, map this to | |
2589 | * to HI PRI */ | |
2590 | connect.ServiceID = WMI_DATA_VI_SVC; | |
2591 | status = ar6000_connectservice(ar, | |
2592 | &connect, | |
2593 | "WMI DATA VI"); | |
2594 | if (A_FAILED(status)) { | |
2595 | break; | |
2596 | } | |
2597 | ||
2598 | /* connect to VO service, this is currently not | |
2599 | * mapped to a WMI priority stream due to historical reasons. | |
2600 | * WMI originally defined 3 priorities over 3 mailboxes | |
2601 | * We can change this when WMI is reworked so that priorities are not | |
2602 | * dependent on mailboxes */ | |
2603 | connect.ServiceID = WMI_DATA_VO_SVC; | |
2604 | status = ar6000_connectservice(ar, | |
2605 | &connect, | |
2606 | "WMI DATA VO"); | |
2607 | if (A_FAILED(status)) { | |
2608 | break; | |
2609 | } | |
2610 | ||
2611 | A_ASSERT(arAc2EndpointID(ar,WMM_AC_BE) != 0); | |
2612 | A_ASSERT(arAc2EndpointID(ar,WMM_AC_BK) != 0); | |
2613 | A_ASSERT(arAc2EndpointID(ar,WMM_AC_VI) != 0); | |
2614 | A_ASSERT(arAc2EndpointID(ar,WMM_AC_VO) != 0); | |
2615 | ||
2616 | /* setup access class priority mappings */ | |
2617 | ar->arAcStreamPriMap[WMM_AC_BK] = 0; /* lowest */ | |
2618 | ar->arAcStreamPriMap[WMM_AC_BE] = 1; /* */ | |
2619 | ar->arAcStreamPriMap[WMM_AC_VI] = 2; /* */ | |
2620 | ar->arAcStreamPriMap[WMM_AC_VO] = 3; /* highest */ | |
2621 | ||
2622 | #ifdef EXPORT_HCI_BRIDGE_INTERFACE | |
2623 | if (setuphci && (NULL != ar6kHciTransCallbacks.setupTransport)) { | |
2624 | HCI_TRANSPORT_MISC_HANDLES hciHandles; | |
2625 | ||
2626 | hciHandles.netDevice = ar->arNetDev; | |
2627 | hciHandles.hifDevice = ar->arHifDevice; | |
2628 | hciHandles.htcHandle = ar->arHtcTarget; | |
2629 | status = (A_STATUS)(ar6kHciTransCallbacks.setupTransport(&hciHandles)); | |
2630 | } | |
2631 | #else | |
2632 | if (setuphci) { | |
2633 | /* setup HCI */ | |
2634 | status = ar6000_setup_hci(ar); | |
2635 | } | |
2636 | #endif | |
2637 | #ifdef EXPORT_HCI_PAL_INTERFACE | |
2638 | if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.setupTransport)) | |
2639 | status = ar6kHciPalCallbacks_g.setupTransport(ar); | |
2640 | #else | |
2641 | if(setuphcipal) | |
2642 | status = ar6k_setup_hci_pal(ar); | |
2643 | #endif | |
2644 | ||
2645 | } while (FALSE); | |
2646 | ||
2647 | if (A_FAILED(status)) { | |
2648 | ret = -EIO; | |
2649 | goto ar6000_init_done; | |
2650 | } | |
2651 | ||
2652 | /* | |
2653 | * give our connected endpoints some buffers | |
2654 | */ | |
2655 | ||
2656 | ar6000_rx_refill(ar, ar->arControlEp); | |
2657 | ar6000_rx_refill(ar, arAc2EndpointID(ar,WMM_AC_BE)); | |
2658 | ||
2659 | /* | |
2660 | * We will post the receive buffers only for SPE or endpoint ping testing so we are | |
2661 | * making it conditional on the 'bypasswmi' flag. | |
2662 | */ | |
2663 | if (bypasswmi) { | |
2664 | ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_BK)); | |
2665 | ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VI)); | |
2666 | ar6000_rx_refill(ar,arAc2EndpointID(ar,WMM_AC_VO)); | |
2667 | } | |
2668 | ||
2669 | /* allocate some buffers that handle larger AMSDU frames */ | |
2670 | ar6000_refill_amsdu_rxbufs(ar,AR6000_MAX_AMSDU_RX_BUFFERS); | |
2671 | ||
2672 | /* setup credit distribution */ | |
2673 | ar6000_setup_credit_dist(ar->arHtcTarget, &ar->arCreditStateInfo); | |
2674 | ||
2675 | /* Since cookies are used for HTC transports, they should be */ | |
2676 | /* initialized prior to enabling HTC. */ | |
2677 | ar6000_cookie_init(ar); | |
2678 | ||
2679 | /* start HTC */ | |
2680 | status = HTCStart(ar->arHtcTarget); | |
2681 | ||
2682 | if (status != A_OK) { | |
2683 | if (ar->arWmiEnabled == TRUE) { | |
2684 | wmi_shutdown(ar->arWmi); | |
2685 | ar->arWmiEnabled = FALSE; | |
2686 | ar->arWmi = NULL; | |
2687 | } | |
2688 | ar6000_cookie_cleanup(ar); | |
2689 | ret = -EIO; | |
2690 | goto ar6000_init_done; | |
2691 | } | |
2692 | ||
2693 | if (!bypasswmi) { | |
2694 | /* Wait for Wmi event to be ready */ | |
2695 | timeleft = wait_event_interruptible_timeout(arEvent, | |
2696 | (ar->arWmiReady == TRUE), wmitimeout * HZ); | |
2697 | ||
2698 | if (ar->arVersion.abi_ver != AR6K_ABI_VERSION) { | |
2699 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ABI Version mismatch: Host(0x%x), Target(0x%x)\n", AR6K_ABI_VERSION, ar->arVersion.abi_ver)); | |
2700 | #ifndef ATH6K_SKIP_ABI_VERSION_CHECK | |
2701 | ret = -EIO; | |
2702 | goto ar6000_init_done; | |
2703 | #endif /* ATH6K_SKIP_ABI_VERSION_CHECK */ | |
2704 | } | |
2705 | ||
2706 | if(!timeleft || signal_pending(current)) | |
2707 | { | |
2708 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI is not ready or wait was interrupted\n")); | |
2709 | ret = -EIO; | |
2710 | goto ar6000_init_done; | |
2711 | } | |
2712 | ||
2713 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() WMI is ready\n", __func__)); | |
2714 | ||
2715 | /* Communicate the wmi protocol verision to the target */ | |
2716 | if ((ar6000_set_host_app_area(ar)) != A_OK) { | |
2717 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the host app area\n")); | |
2718 | } | |
2719 | ||
2720 | /* configure the device for rx dot11 header rules 0,0 are the default values | |
2721 | * therefore this command can be skipped if the inputs are 0,FALSE,FALSE.Required | |
2722 | if checksum offload is needed. Set RxMetaVersion to 2*/ | |
2723 | if ((wmi_set_rx_frame_format_cmd(ar->arWmi,ar->rxMetaVersion, processDot11Hdr, processDot11Hdr)) != A_OK) { | |
2724 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set the rx frame format.\n")); | |
2725 | } | |
2726 | ||
2727 | #if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) | |
2728 | /* Configure the type of BT collocated with WLAN */ | |
2729 | A_MEMZERO(&sbcb_cmd, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)); | |
2730 | #ifdef CONFIG_AR600x_BT_QCOM | |
2731 | sbcb_cmd.btcoexCoLocatedBTdev = 1; | |
2732 | #elif defined(CONFIG_AR600x_BT_CSR) | |
2733 | sbcb_cmd.btcoexCoLocatedBTdev = 2; | |
2734 | #elif defined(CONFIG_AR600x_BT_AR3001) | |
2735 | sbcb_cmd.btcoexCoLocatedBTdev = 3; | |
2736 | #else | |
2737 | #error Unsupported Bluetooth Type | |
2738 | #endif /* Collocated Bluetooth Type */ | |
2739 | ||
2740 | if ((wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd)) != A_OK) | |
2741 | { | |
2742 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n")); | |
2743 | } | |
2744 | ||
2745 | /* Configure the type of BT collocated with WLAN */ | |
2746 | A_MEMZERO(&sbfa_cmd, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)); | |
2747 | #ifdef CONFIG_AR600x_DUAL_ANTENNA | |
2748 | sbfa_cmd.btcoexFeAntType = 2; | |
2749 | #elif defined(CONFIG_AR600x_SINGLE_ANTENNA) | |
2750 | sbfa_cmd.btcoexFeAntType = 1; | |
2751 | #else | |
2752 | #error Unsupported Front-End Antenna Configuration | |
2753 | #endif /* AR600x Front-End Antenna Configuration */ | |
2754 | ||
2755 | if ((wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd)) != A_OK) { | |
2756 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n")); | |
2757 | } | |
2758 | #endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ | |
2759 | } | |
2760 | ||
2761 | ar->arNumDataEndPts = 1; | |
2762 | ||
2763 | if (bypasswmi) { | |
2764 | /* for tests like endpoint ping, the MAC address needs to be non-zero otherwise | |
2765 | * the data path through a raw socket is disabled */ | |
2766 | dev->dev_addr[0] = 0x00; | |
2767 | dev->dev_addr[1] = 0x01; | |
2768 | dev->dev_addr[2] = 0x02; | |
2769 | dev->dev_addr[3] = 0xAA; | |
2770 | dev->dev_addr[4] = 0xBB; | |
2771 | dev->dev_addr[5] = 0xCC; | |
2772 | } | |
2773 | ||
2774 | ar6000_init_done: | |
2775 | rtnl_lock(); | |
2776 | dev_put(dev); | |
2777 | ||
2778 | return ret; | |
2779 | } | |
2780 | ||
2781 | ||
2782 | void | |
2783 | ar6000_bitrate_rx(void *devt, A_INT32 rateKbps) | |
2784 | { | |
2785 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
2786 | ||
2787 | ar->arBitRate = rateKbps; | |
2788 | wake_up(&arEvent); | |
2789 | } | |
2790 | ||
2791 | void | |
2792 | ar6000_ratemask_rx(void *devt, A_UINT32 ratemask) | |
2793 | { | |
2794 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
2795 | ||
2796 | ar->arRateMask = ratemask; | |
2797 | wake_up(&arEvent); | |
2798 | } | |
2799 | ||
2800 | void | |
2801 | ar6000_txPwr_rx(void *devt, A_UINT8 txPwr) | |
2802 | { | |
2803 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
2804 | ||
2805 | ar->arTxPwr = txPwr; | |
2806 | wake_up(&arEvent); | |
2807 | } | |
2808 | ||
2809 | ||
2810 | void | |
2811 | ar6000_channelList_rx(void *devt, A_INT8 numChan, A_UINT16 *chanList) | |
2812 | { | |
2813 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
2814 | ||
2815 | A_MEMCPY(ar->arChannelList, chanList, numChan * sizeof (A_UINT16)); | |
2816 | ar->arNumChannels = numChan; | |
2817 | ||
2818 | wake_up(&arEvent); | |
2819 | } | |
2820 | ||
2821 | A_UINT8 | |
2822 | ar6000_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, A_UINT32 * mapNo) | |
2823 | { | |
2824 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2825 | A_UINT8 *datap; | |
2826 | ATH_MAC_HDR *macHdr; | |
2827 | A_UINT32 i, eptMap; | |
2828 | ||
2829 | (*mapNo) = 0; | |
2830 | datap = A_NETBUF_DATA(skb); | |
2831 | macHdr = (ATH_MAC_HDR *)(datap + sizeof(WMI_DATA_HDR)); | |
2832 | if (IEEE80211_IS_MULTICAST(macHdr->dstMac)) { | |
2833 | return ENDPOINT_2; | |
2834 | } | |
2835 | ||
2836 | eptMap = -1; | |
2837 | for (i = 0; i < ar->arNodeNum; i ++) { | |
2838 | if (IEEE80211_ADDR_EQ(macHdr->dstMac, ar->arNodeMap[i].macAddress)) { | |
2839 | (*mapNo) = i + 1; | |
2840 | ar->arNodeMap[i].txPending ++; | |
2841 | return ar->arNodeMap[i].epId; | |
2842 | } | |
2843 | ||
2844 | if ((eptMap == -1) && !ar->arNodeMap[i].txPending) { | |
2845 | eptMap = i; | |
2846 | } | |
2847 | } | |
2848 | ||
2849 | if (eptMap == -1) { | |
2850 | eptMap = ar->arNodeNum; | |
2851 | ar->arNodeNum ++; | |
2852 | A_ASSERT(ar->arNodeNum <= MAX_NODE_NUM); | |
2853 | } | |
2854 | ||
2855 | A_MEMCPY(ar->arNodeMap[eptMap].macAddress, macHdr->dstMac, IEEE80211_ADDR_LEN); | |
2856 | ||
2857 | for (i = ENDPOINT_2; i <= ENDPOINT_5; i ++) { | |
2858 | if (!ar->arTxPending[i]) { | |
2859 | ar->arNodeMap[eptMap].epId = i; | |
2860 | break; | |
2861 | } | |
2862 | // No free endpoint is available, start redistribution on the inuse endpoints. | |
2863 | if (i == ENDPOINT_5) { | |
2864 | ar->arNodeMap[eptMap].epId = ar->arNexEpId; | |
2865 | ar->arNexEpId ++; | |
2866 | if (ar->arNexEpId > ENDPOINT_5) { | |
2867 | ar->arNexEpId = ENDPOINT_2; | |
2868 | } | |
2869 | } | |
2870 | } | |
2871 | ||
2872 | (*mapNo) = eptMap + 1; | |
2873 | ar->arNodeMap[eptMap].txPending ++; | |
2874 | ||
2875 | return ar->arNodeMap[eptMap].epId; | |
2876 | } | |
2877 | ||
2878 | #ifdef DEBUG | |
2879 | static void ar6000_dump_skb(struct sk_buff *skb) | |
2880 | { | |
2881 | u_char *ch; | |
2882 | for (ch = A_NETBUF_DATA(skb); | |
2883 | (unsigned long)ch < ((unsigned long)A_NETBUF_DATA(skb) + | |
2884 | A_NETBUF_LEN(skb)); ch++) | |
2885 | { | |
2886 | AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("%2.2x ", *ch)); | |
2887 | } | |
2888 | AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("\n")); | |
2889 | } | |
2890 | #endif | |
2891 | ||
2892 | #ifdef HTC_TEST_SEND_PKTS | |
2893 | static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *skb); | |
2894 | #endif | |
2895 | ||
2896 | static int | |
2897 | ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) | |
2898 | { | |
2899 | #define AC_NOT_MAPPED 99 | |
2900 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
2901 | A_UINT8 ac = AC_NOT_MAPPED; | |
2902 | HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED; | |
2903 | A_UINT32 mapNo = 0; | |
2904 | int len; | |
2905 | struct ar_cookie *cookie; | |
2906 | A_BOOL checkAdHocPsMapping = FALSE,bMoreData = FALSE; | |
2907 | HTC_TX_TAG htc_tag = AR6K_DATA_PKT_TAG; | |
2908 | A_UINT8 dot11Hdr = processDot11Hdr; | |
2909 | #ifdef CONFIG_PM | |
2910 | if (ar->arWowState != WLAN_WOW_STATE_NONE) { | |
2911 | A_NETBUF_FREE(skb); | |
2912 | return 0; | |
2913 | } | |
2914 | #endif /* CONFIG_PM */ | |
2915 | ||
2916 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_data_tx start - skb=0x%lx, data=0x%lx, len=0x%x\n", | |
2917 | (unsigned long)skb, (unsigned long)A_NETBUF_DATA(skb), | |
2918 | A_NETBUF_LEN(skb))); | |
2919 | ||
2920 | /* If target is not associated */ | |
2921 | if( (!ar->arConnected && !bypasswmi) | |
2922 | #ifdef CONFIG_HOST_TCMD_SUPPORT | |
2923 | /* TCMD doesnt support any data, free the buf and return */ | |
2924 | || (ar->arTargetMode == AR6000_TCMD_MODE) | |
2925 | #endif | |
2926 | ) { | |
2927 | A_NETBUF_FREE(skb); | |
2928 | return 0; | |
2929 | } | |
2930 | ||
2931 | do { | |
2932 | ||
2933 | if (ar->arWmiReady == FALSE && bypasswmi == 0) { | |
2934 | break; | |
2935 | } | |
2936 | ||
2937 | #ifdef BLOCK_TX_PATH_FLAG | |
2938 | if (blocktx) { | |
2939 | break; | |
2940 | } | |
2941 | #endif /* BLOCK_TX_PATH_FLAG */ | |
2942 | ||
2943 | /* AP mode Power save processing */ | |
2944 | /* If the dst STA is in sleep state, queue the pkt in its PS queue */ | |
2945 | ||
2946 | if (ar->arNetworkType == AP_NETWORK) { | |
2947 | ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); | |
2948 | sta_t *conn = NULL; | |
2949 | ||
2950 | /* If the dstMac is a Multicast address & atleast one of the | |
2951 | * associated STA is in PS mode, then queue the pkt to the | |
2952 | * mcastq | |
2953 | */ | |
2954 | if (IEEE80211_IS_MULTICAST(datap->dstMac)) { | |
2955 | A_UINT8 ctr=0; | |
2956 | A_BOOL qMcast=FALSE; | |
2957 | ||
2958 | ||
2959 | for (ctr=0; ctr<AP_MAX_NUM_STA; ctr++) { | |
2960 | if (STA_IS_PWR_SLEEP((&ar->sta_list[ctr]))) { | |
2961 | qMcast = TRUE; | |
2962 | } | |
2963 | } | |
2964 | if(qMcast) { | |
2965 | ||
2966 | /* If this transmit is not because of a Dtim Expiry q it */ | |
2967 | if (ar->DTIMExpired == FALSE) { | |
2968 | A_BOOL isMcastqEmpty = FALSE; | |
2969 | ||
2970 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
2971 | isMcastqEmpty = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq); | |
2972 | A_NETBUF_ENQUEUE(&ar->mcastpsq, skb); | |
2973 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
2974 | ||
2975 | /* If this is the first Mcast pkt getting queued | |
2976 | * indicate to the target to set the BitmapControl LSB | |
2977 | * of the TIM IE. | |
2978 | */ | |
2979 | if (isMcastqEmpty) { | |
2980 | wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 1); | |
2981 | } | |
2982 | return 0; | |
2983 | } else { | |
2984 | /* This transmit is because of Dtim expiry. Determine if | |
2985 | * MoreData bit has to be set. | |
2986 | */ | |
2987 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
2988 | if(!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) { | |
2989 | bMoreData = TRUE; | |
2990 | } | |
2991 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
2992 | } | |
2993 | } | |
2994 | } else { | |
2995 | conn = ieee80211_find_conn(ar, datap->dstMac); | |
2996 | if (conn) { | |
2997 | if (STA_IS_PWR_SLEEP(conn)) { | |
2998 | /* If this transmit is not because of a PsPoll q it*/ | |
2999 | if (!STA_IS_PS_POLLED(conn)) { | |
3000 | A_BOOL isPsqEmpty = FALSE; | |
3001 | /* Queue the frames if the STA is sleeping */ | |
3002 | A_MUTEX_LOCK(&conn->psqLock); | |
3003 | isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); | |
3004 | A_NETBUF_ENQUEUE(&conn->psq, skb); | |
3005 | A_MUTEX_UNLOCK(&conn->psqLock); | |
3006 | ||
3007 | /* If this is the first pkt getting queued | |
3008 | * for this STA, update the PVB for this STA | |
3009 | */ | |
3010 | if (isPsqEmpty) { | |
3011 | wmi_set_pvb_cmd(ar->arWmi, conn->aid, 1); | |
3012 | } | |
3013 | ||
3014 | return 0; | |
3015 | } else { | |
3016 | /* This tx is because of a PsPoll. Determine if | |
3017 | * MoreData bit has to be set | |
3018 | */ | |
3019 | A_MUTEX_LOCK(&conn->psqLock); | |
3020 | if (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) { | |
3021 | bMoreData = TRUE; | |
3022 | } | |
3023 | A_MUTEX_UNLOCK(&conn->psqLock); | |
3024 | } | |
3025 | } | |
3026 | } else { | |
3027 | ||
3028 | /* non existent STA. drop the frame */ | |
3029 | A_NETBUF_FREE(skb); | |
3030 | return 0; | |
3031 | } | |
3032 | } | |
3033 | } | |
3034 | ||
3035 | if (ar->arWmiEnabled) { | |
3036 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
3037 | A_UINT8 csumStart=0; | |
3038 | A_UINT8 csumDest=0; | |
3039 | A_UINT8 csum=skb->ip_summed; | |
3040 | if(csumOffload && (csum==CHECKSUM_PARTIAL)){ | |
3041 | csumStart=skb->csum_start-(skb->network_header-skb->head)+sizeof(ATH_LLC_SNAP_HDR); | |
3042 | csumDest=skb->csum_offset+csumStart; | |
3043 | } | |
3044 | #endif | |
3045 | if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) { | |
3046 | struct sk_buff *newbuf; | |
3047 | ||
3048 | /* | |
3049 | * We really should have gotten enough headroom but sometimes | |
3050 | * we still get packets with not enough headroom. Copy the packet. | |
3051 | */ | |
3052 | len = A_NETBUF_LEN(skb); | |
3053 | newbuf = A_NETBUF_ALLOC(len); | |
3054 | if (newbuf == NULL) { | |
3055 | break; | |
3056 | } | |
3057 | A_NETBUF_PUT(newbuf, len); | |
3058 | A_MEMCPY(A_NETBUF_DATA(newbuf), A_NETBUF_DATA(skb), len); | |
3059 | A_NETBUF_FREE(skb); | |
3060 | skb = newbuf; | |
3061 | /* fall through and assemble header */ | |
3062 | } | |
3063 | ||
3064 | if (dot11Hdr) { | |
3065 | if (wmi_dot11_hdr_add(ar->arWmi,skb,ar->arNetworkType) != A_OK) { | |
3066 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx-wmi_dot11_hdr_add failed\n")); | |
3067 | break; | |
3068 | } | |
3069 | } else { | |
3070 | if (wmi_dix_2_dot3(ar->arWmi, skb) != A_OK) { | |
3071 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_dix_2_dot3 failed\n")); | |
3072 | break; | |
3073 | } | |
3074 | } | |
3075 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
3076 | if(csumOffload && (csum ==CHECKSUM_PARTIAL)){ | |
3077 | WMI_TX_META_V2 metaV2; | |
3078 | metaV2.csumStart =csumStart; | |
3079 | metaV2.csumDest = csumDest; | |
3080 | metaV2.csumFlags = 0x1;/*instruct target to calculate checksum*/ | |
3081 | if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr, | |
3082 | WMI_META_VERSION_2,&metaV2) != A_OK) { | |
3083 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n")); | |
3084 | break; | |
3085 | } | |
3086 | ||
3087 | } | |
3088 | else | |
3089 | #endif | |
3090 | { | |
3091 | if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != A_OK) { | |
3092 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n")); | |
3093 | break; | |
3094 | } | |
3095 | } | |
3096 | ||
3097 | ||
3098 | if ((ar->arNetworkType == ADHOC_NETWORK) && | |
3099 | ar->arIbssPsEnable && ar->arConnected) { | |
3100 | /* flag to check adhoc mapping once we take the lock below: */ | |
3101 | checkAdHocPsMapping = TRUE; | |
3102 | ||
3103 | } else { | |
3104 | /* get the stream mapping */ | |
3105 | ac = wmi_implicit_create_pstream(ar->arWmi, skb, 0, ar->arWmmEnabled); | |
3106 | } | |
3107 | ||
3108 | } else { | |
3109 | EPPING_HEADER *eppingHdr; | |
3110 | ||
3111 | eppingHdr = A_NETBUF_DATA(skb); | |
3112 | ||
3113 | if (IS_EPPING_PACKET(eppingHdr)) { | |
3114 | /* the stream ID is mapped to an access class */ | |
3115 | ac = eppingHdr->StreamNo_h; | |
3116 | /* some EPPING packets cannot be dropped no matter what access class it was | |
3117 | * sent on. We can change the packet tag to guarantee it will not get dropped */ | |
3118 | if (IS_EPING_PACKET_NO_DROP(eppingHdr)) { | |
3119 | htc_tag = AR6K_CONTROL_PKT_TAG; | |
3120 | } | |
3121 | ||
3122 | if (ac == HCI_TRANSPORT_STREAM_NUM) { | |
3123 | /* pass this to HCI */ | |
3124 | #ifndef EXPORT_HCI_BRIDGE_INTERFACE | |
3125 | if (A_SUCCESS(hci_test_send(ar,skb))) { | |
3126 | return 0; | |
3127 | } | |
3128 | #endif | |
3129 | /* set AC to discard this skb */ | |
3130 | ac = AC_NOT_MAPPED; | |
3131 | } else { | |
3132 | /* a quirk of linux, the payload of the frame is 32-bit aligned and thus the addition | |
3133 | * of the HTC header will mis-align the start of the HTC frame, so we add some | |
3134 | * padding which will be stripped off in the target */ | |
3135 | if (EPPING_ALIGNMENT_PAD > 0) { | |
3136 | A_NETBUF_PUSH(skb, EPPING_ALIGNMENT_PAD); | |
3137 | } | |
3138 | } | |
3139 | ||
3140 | } else { | |
3141 | /* not a ping packet, drop it */ | |
3142 | ac = AC_NOT_MAPPED; | |
3143 | } | |
3144 | } | |
3145 | ||
3146 | } while (FALSE); | |
3147 | ||
3148 | /* did we succeed ? */ | |
3149 | if ((ac == AC_NOT_MAPPED) && !checkAdHocPsMapping) { | |
3150 | /* cleanup and exit */ | |
3151 | A_NETBUF_FREE(skb); | |
3152 | AR6000_STAT_INC(ar, tx_dropped); | |
3153 | AR6000_STAT_INC(ar, tx_aborted_errors); | |
3154 | return 0; | |
3155 | } | |
3156 | ||
3157 | cookie = NULL; | |
3158 | ||
3159 | /* take the lock to protect driver data */ | |
3160 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3161 | ||
3162 | do { | |
3163 | ||
3164 | if (checkAdHocPsMapping) { | |
3165 | eid = ar6000_ibss_map_epid(skb, dev, &mapNo); | |
3166 | }else { | |
3167 | eid = arAc2EndpointID (ar, ac); | |
3168 | } | |
3169 | /* validate that the endpoint is connected */ | |
3170 | if (eid == 0 || eid == ENDPOINT_UNUSED ) { | |
3171 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" eid %d is NOT mapped!\n", eid)); | |
3172 | break; | |
3173 | } | |
3174 | /* allocate resource for this packet */ | |
3175 | cookie = ar6000_alloc_cookie(ar); | |
3176 | ||
3177 | if (cookie != NULL) { | |
3178 | /* update counts while the lock is held */ | |
3179 | ar->arTxPending[eid]++; | |
3180 | ar->arTotalTxDataPending++; | |
3181 | } | |
3182 | ||
3183 | } while (FALSE); | |
3184 | ||
3185 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3186 | ||
3187 | if (cookie != NULL) { | |
3188 | cookie->arc_bp[0] = (unsigned long)skb; | |
3189 | cookie->arc_bp[1] = mapNo; | |
3190 | SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, | |
3191 | cookie, | |
3192 | A_NETBUF_DATA(skb), | |
3193 | A_NETBUF_LEN(skb), | |
3194 | eid, | |
3195 | htc_tag); | |
3196 | ||
3197 | #ifdef DEBUG | |
3198 | if (debugdriver >= 3) { | |
3199 | ar6000_dump_skb(skb); | |
3200 | } | |
3201 | #endif | |
3202 | #ifdef HTC_TEST_SEND_PKTS | |
3203 | DoHTCSendPktsTest(ar,mapNo,eid,skb); | |
3204 | #endif | |
3205 | /* HTC interface is asynchronous, if this fails, cleanup will happen in | |
3206 | * the ar6000_tx_complete callback */ | |
3207 | HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); | |
3208 | } else { | |
3209 | /* no packet to send, cleanup */ | |
3210 | A_NETBUF_FREE(skb); | |
3211 | AR6000_STAT_INC(ar, tx_dropped); | |
3212 | AR6000_STAT_INC(ar, tx_aborted_errors); | |
3213 | } | |
3214 | ||
3215 | return 0; | |
3216 | } | |
3217 | ||
3218 | int | |
3219 | ar6000_acl_data_tx(struct sk_buff *skb, struct net_device *dev) | |
3220 | { | |
3221 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
3222 | struct ar_cookie *cookie; | |
3223 | HTC_ENDPOINT_ID eid = ENDPOINT_UNUSED; | |
3224 | ||
3225 | cookie = NULL; | |
3226 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3227 | ||
3228 | /* For now we send ACL on BE endpoint: We can also have a dedicated EP */ | |
3229 | eid = arAc2EndpointID (ar, 0); | |
3230 | /* allocate resource for this packet */ | |
3231 | cookie = ar6000_alloc_cookie(ar); | |
3232 | ||
3233 | if (cookie != NULL) { | |
3234 | /* update counts while the lock is held */ | |
3235 | ar->arTxPending[eid]++; | |
3236 | ar->arTotalTxDataPending++; | |
3237 | } | |
3238 | ||
3239 | ||
3240 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3241 | ||
3242 | if (cookie != NULL) { | |
3243 | cookie->arc_bp[0] = (unsigned long)skb; | |
3244 | cookie->arc_bp[1] = 0; | |
3245 | SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, | |
3246 | cookie, | |
3247 | A_NETBUF_DATA(skb), | |
3248 | A_NETBUF_LEN(skb), | |
3249 | eid, | |
3250 | AR6K_DATA_PKT_TAG); | |
3251 | ||
3252 | /* HTC interface is asynchronous, if this fails, cleanup will happen in | |
3253 | * the ar6000_tx_complete callback */ | |
3254 | HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); | |
3255 | } else { | |
3256 | /* no packet to send, cleanup */ | |
3257 | A_NETBUF_FREE(skb); | |
3258 | AR6000_STAT_INC(ar, tx_dropped); | |
3259 | AR6000_STAT_INC(ar, tx_aborted_errors); | |
3260 | } | |
3261 | return 0; | |
3262 | } | |
3263 | ||
3264 | ||
3265 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
3266 | static void | |
3267 | tvsub(register struct timeval *out, register struct timeval *in) | |
3268 | { | |
3269 | if((out->tv_usec -= in->tv_usec) < 0) { | |
3270 | out->tv_sec--; | |
3271 | out->tv_usec += 1000000; | |
3272 | } | |
3273 | out->tv_sec -= in->tv_sec; | |
3274 | } | |
3275 | ||
3276 | void | |
3277 | applyAPTCHeuristics(AR_SOFTC_T *ar) | |
3278 | { | |
3279 | A_UINT32 duration; | |
3280 | A_UINT32 numbytes; | |
3281 | A_UINT32 throughput; | |
3282 | struct timeval ts; | |
3283 | A_STATUS status; | |
3284 | ||
3285 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3286 | ||
3287 | if ((enableAPTCHeuristics) && (!aptcTR.timerScheduled)) { | |
3288 | do_gettimeofday(&ts); | |
3289 | tvsub(&ts, &aptcTR.samplingTS); | |
3290 | duration = ts.tv_sec * 1000 + ts.tv_usec / 1000; /* ms */ | |
3291 | numbytes = aptcTR.bytesTransmitted + aptcTR.bytesReceived; | |
3292 | ||
3293 | if (duration > APTC_TRAFFIC_SAMPLING_INTERVAL) { | |
3294 | /* Initialize the time stamp and byte count */ | |
3295 | aptcTR.bytesTransmitted = aptcTR.bytesReceived = 0; | |
3296 | do_gettimeofday(&aptcTR.samplingTS); | |
3297 | ||
3298 | /* Calculate and decide based on throughput thresholds */ | |
3299 | throughput = ((numbytes * 8) / duration); | |
3300 | if (throughput > APTC_UPPER_THROUGHPUT_THRESHOLD) { | |
3301 | /* Disable Sleep and schedule a timer */ | |
3302 | A_ASSERT(ar->arWmiReady == TRUE); | |
3303 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3304 | status = wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER); | |
3305 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3306 | A_TIMEOUT_MS(&aptcTimer, APTC_TRAFFIC_SAMPLING_INTERVAL, 0); | |
3307 | aptcTR.timerScheduled = TRUE; | |
3308 | } | |
3309 | } | |
3310 | } | |
3311 | ||
3312 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3313 | } | |
3314 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
3315 | ||
3316 | static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, HTC_PACKET *pPacket) | |
3317 | { | |
3318 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; | |
3319 | HTC_SEND_FULL_ACTION action = HTC_SEND_FULL_KEEP; | |
3320 | A_BOOL stopNet = FALSE; | |
3321 | HTC_ENDPOINT_ID Endpoint = HTC_GET_ENDPOINT_FROM_PKT(pPacket); | |
3322 | ||
3323 | do { | |
3324 | ||
3325 | if (bypasswmi) { | |
3326 | int accessClass; | |
3327 | ||
3328 | if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) { | |
3329 | /* don't drop special control packets */ | |
3330 | break; | |
3331 | } | |
3332 | ||
3333 | accessClass = arEndpoint2Ac(ar,Endpoint); | |
3334 | /* for endpoint ping testing drop Best Effort and Background */ | |
3335 | if ((accessClass == WMM_AC_BE) || (accessClass == WMM_AC_BK)) { | |
3336 | action = HTC_SEND_FULL_DROP; | |
3337 | stopNet = FALSE; | |
3338 | } else { | |
3339 | /* keep but stop the netqueues */ | |
3340 | stopNet = TRUE; | |
3341 | } | |
3342 | break; | |
3343 | } | |
3344 | ||
3345 | if (Endpoint == ar->arControlEp) { | |
3346 | /* under normal WMI if this is getting full, then something is running rampant | |
3347 | * the host should not be exhausting the WMI queue with too many commands | |
3348 | * the only exception to this is during testing using endpointping */ | |
3349 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3350 | /* set flag to handle subsequent messages */ | |
3351 | ar->arWMIControlEpFull = TRUE; | |
3352 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3353 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI Control Endpoint is FULL!!! \n")); | |
3354 | /* no need to stop the network */ | |
3355 | stopNet = FALSE; | |
3356 | break; | |
3357 | } | |
3358 | ||
3359 | /* if we get here, we are dealing with data endpoints getting full */ | |
3360 | ||
3361 | if (HTC_GET_TAG_FROM_PKT(pPacket) == AR6K_CONTROL_PKT_TAG) { | |
3362 | /* don't drop control packets issued on ANY data endpoint */ | |
3363 | break; | |
3364 | } | |
3365 | ||
3366 | if (ar->arNetworkType == ADHOC_NETWORK) { | |
3367 | /* in adhoc mode, we cannot differentiate traffic priorities so there is no need to | |
3368 | * continue, however we should stop the network */ | |
3369 | stopNet = TRUE; | |
3370 | break; | |
3371 | } | |
3372 | /* the last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for the highest | |
3373 | * active stream */ | |
3374 | if (ar->arAcStreamPriMap[arEndpoint2Ac(ar,Endpoint)] < ar->arHiAcStreamActivePri && | |
3375 | ar->arCookieCount <= MAX_HI_COOKIE_NUM) { | |
3376 | /* this stream's priority is less than the highest active priority, we | |
3377 | * give preference to the highest priority stream by directing | |
3378 | * HTC to drop the packet that overflowed */ | |
3379 | action = HTC_SEND_FULL_DROP; | |
3380 | /* since we are dropping packets, no need to stop the network */ | |
3381 | stopNet = FALSE; | |
3382 | break; | |
3383 | } | |
3384 | ||
3385 | } while (FALSE); | |
3386 | ||
3387 | if (stopNet) { | |
3388 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3389 | ar->arNetQueueStopped = TRUE; | |
3390 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3391 | /* one of the data endpoints queues is getting full..need to stop network stack | |
3392 | * the queue will resume in ar6000_tx_complete() */ | |
3393 | netif_stop_queue(ar->arNetDev); | |
3394 | } | |
3395 | ||
3396 | return action; | |
3397 | } | |
3398 | ||
3399 | ||
3400 | static void | |
3401 | ar6000_tx_complete(void *Context, HTC_PACKET_QUEUE *pPacketQueue) | |
3402 | { | |
3403 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; | |
3404 | A_UINT32 mapNo = 0; | |
3405 | A_STATUS status; | |
3406 | struct ar_cookie * ar_cookie; | |
3407 | HTC_ENDPOINT_ID eid; | |
3408 | A_BOOL wakeEvent = FALSE; | |
3409 | struct sk_buff_head skb_queue; | |
3410 | HTC_PACKET *pPacket; | |
3411 | struct sk_buff *pktSkb; | |
3412 | A_BOOL flushing = FALSE; | |
3413 | ||
3414 | skb_queue_head_init(&skb_queue); | |
3415 | ||
3416 | /* lock the driver as we update internal state */ | |
3417 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3418 | ||
3419 | /* reap completed packets */ | |
3420 | while (!HTC_QUEUE_EMPTY(pPacketQueue)) { | |
3421 | ||
3422 | pPacket = HTC_PACKET_DEQUEUE(pPacketQueue); | |
3423 | ||
3424 | ar_cookie = (struct ar_cookie *)pPacket->pPktContext; | |
3425 | A_ASSERT(ar_cookie); | |
3426 | ||
3427 | status = pPacket->Status; | |
3428 | pktSkb = (struct sk_buff *)ar_cookie->arc_bp[0]; | |
3429 | eid = pPacket->Endpoint; | |
3430 | mapNo = ar_cookie->arc_bp[1]; | |
3431 | ||
3432 | A_ASSERT(pktSkb); | |
3433 | A_ASSERT(pPacket->pBuffer == A_NETBUF_DATA(pktSkb)); | |
3434 | ||
3435 | /* add this to the list, use faster non-lock API */ | |
3436 | __skb_queue_tail(&skb_queue,pktSkb); | |
3437 | ||
3438 | if (A_SUCCESS(status)) { | |
3439 | A_ASSERT(pPacket->ActualLength == A_NETBUF_LEN(pktSkb)); | |
3440 | } | |
3441 | ||
3442 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar6000_tx_complete skb=0x%lx data=0x%lx len=0x%x eid=%d ", | |
3443 | (unsigned long)pktSkb, (unsigned long)pPacket->pBuffer, | |
3444 | pPacket->ActualLength, | |
3445 | eid)); | |
3446 | ||
3447 | ar->arTxPending[eid]--; | |
3448 | ||
3449 | if ((eid != ar->arControlEp) || bypasswmi) { | |
3450 | ar->arTotalTxDataPending--; | |
3451 | } | |
3452 | ||
3453 | if (eid == ar->arControlEp) | |
3454 | { | |
3455 | if (ar->arWMIControlEpFull) { | |
3456 | /* since this packet completed, the WMI EP is no longer full */ | |
3457 | ar->arWMIControlEpFull = FALSE; | |
3458 | } | |
3459 | ||
3460 | if (ar->arTxPending[eid] == 0) { | |
3461 | wakeEvent = TRUE; | |
3462 | } | |
3463 | } | |
3464 | ||
3465 | if (A_FAILED(status)) { | |
3466 | if (status == A_ECANCELED) { | |
3467 | /* a packet was flushed */ | |
3468 | flushing = TRUE; | |
3469 | } | |
3470 | AR6000_STAT_INC(ar, tx_errors); | |
3471 | if (status != A_NO_RESOURCE) { | |
3472 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() -TX ERROR, status: 0x%x\n", __func__, | |
3473 | status)); | |
3474 | } | |
3475 | } else { | |
3476 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("OK\n")); | |
3477 | flushing = FALSE; | |
3478 | AR6000_STAT_INC(ar, tx_packets); | |
3479 | ar->arNetStats.tx_bytes += A_NETBUF_LEN(pktSkb); | |
3480 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
3481 | aptcTR.bytesTransmitted += a_netbuf_to_len(pktSkb); | |
3482 | applyAPTCHeuristics(ar); | |
3483 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
3484 | } | |
3485 | ||
3486 | // TODO this needs to be looked at | |
3487 | if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable | |
3488 | && (eid != ar->arControlEp) && mapNo) | |
3489 | { | |
3490 | mapNo --; | |
3491 | ar->arNodeMap[mapNo].txPending --; | |
3492 | ||
3493 | if (!ar->arNodeMap[mapNo].txPending && (mapNo == (ar->arNodeNum - 1))) { | |
3494 | A_UINT32 i; | |
3495 | for (i = ar->arNodeNum; i > 0; i --) { | |
3496 | if (!ar->arNodeMap[i - 1].txPending) { | |
3497 | A_MEMZERO(&ar->arNodeMap[i - 1], sizeof(struct ar_node_mapping)); | |
3498 | ar->arNodeNum --; | |
3499 | } else { | |
3500 | break; | |
3501 | } | |
3502 | } | |
3503 | } | |
3504 | } | |
3505 | ||
3506 | ar6000_free_cookie(ar, ar_cookie); | |
3507 | ||
3508 | if (ar->arNetQueueStopped) { | |
3509 | ar->arNetQueueStopped = FALSE; | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3514 | ||
3515 | /* lock is released, we can freely call other kernel APIs */ | |
3516 | ||
3517 | /* free all skbs in our local list */ | |
3518 | while (!skb_queue_empty(&skb_queue)) { | |
3519 | /* use non-lock version */ | |
3520 | pktSkb = __skb_dequeue(&skb_queue); | |
3521 | A_NETBUF_FREE(pktSkb); | |
3522 | } | |
3523 | ||
3524 | if ((ar->arConnected == TRUE) || (bypasswmi)) { | |
3525 | if (!flushing) { | |
3526 | /* don't wake the queue if we are flushing, other wise it will just | |
3527 | * keep queueing packets, which will keep failing */ | |
3528 | netif_wake_queue(ar->arNetDev); | |
3529 | } | |
3530 | } | |
3531 | ||
3532 | if (wakeEvent) { | |
3533 | wake_up(&arEvent); | |
3534 | } | |
3535 | ||
3536 | } | |
3537 | ||
3538 | sta_t * | |
3539 | ieee80211_find_conn(AR_SOFTC_T *ar, A_UINT8 *node_addr) | |
3540 | { | |
3541 | sta_t *conn = NULL; | |
3542 | A_UINT8 i, max_conn; | |
3543 | ||
3544 | switch(ar->arNetworkType) { | |
3545 | case AP_NETWORK: | |
3546 | max_conn = AP_MAX_NUM_STA; | |
3547 | break; | |
3548 | default: | |
3549 | max_conn=0; | |
3550 | break; | |
3551 | } | |
3552 | ||
3553 | for (i = 0; i < max_conn; i++) { | |
3554 | if (IEEE80211_ADDR_EQ(node_addr, ar->sta_list[i].mac)) { | |
3555 | conn = &ar->sta_list[i]; | |
3556 | break; | |
3557 | } | |
3558 | } | |
3559 | ||
3560 | return conn; | |
3561 | } | |
3562 | ||
3563 | sta_t *ieee80211_find_conn_for_aid(AR_SOFTC_T *ar, A_UINT8 aid) | |
3564 | { | |
3565 | sta_t *conn = NULL; | |
3566 | A_UINT8 ctr; | |
3567 | ||
3568 | for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { | |
3569 | if (ar->sta_list[ctr].aid == aid) { | |
3570 | conn = &ar->sta_list[ctr]; | |
3571 | break; | |
3572 | } | |
3573 | } | |
3574 | return conn; | |
3575 | } | |
3576 | ||
3577 | /* | |
3578 | * Receive event handler. This is called by HTC when a packet is received | |
3579 | */ | |
3580 | int pktcount; | |
3581 | static void | |
3582 | ar6000_rx(void *Context, HTC_PACKET *pPacket) | |
3583 | { | |
3584 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; | |
3585 | struct sk_buff *skb = (struct sk_buff *)pPacket->pPktContext; | |
3586 | int minHdrLen; | |
3587 | A_UINT8 containsDot11Hdr = 0; | |
3588 | A_STATUS status = pPacket->Status; | |
3589 | HTC_ENDPOINT_ID ept = pPacket->Endpoint; | |
3590 | ||
3591 | A_ASSERT((status != A_OK) || | |
3592 | (pPacket->pBuffer == (A_NETBUF_DATA(skb) + HTC_HEADER_LEN))); | |
3593 | ||
3594 | 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", | |
3595 | (unsigned long)ar, ept, (unsigned long)skb, (unsigned long)pPacket->pBuffer, | |
3596 | pPacket->ActualLength, status)); | |
3597 | if (status != A_OK) { | |
3598 | if (status != A_ECANCELED) { | |
3599 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("RX ERR (%d) \n",status)); | |
3600 | } | |
3601 | } | |
3602 | ||
3603 | /* take lock to protect buffer counts | |
3604 | * and adaptive power throughput state */ | |
3605 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3606 | ||
3607 | if (A_SUCCESS(status)) { | |
3608 | AR6000_STAT_INC(ar, rx_packets); | |
3609 | ar->arNetStats.rx_bytes += pPacket->ActualLength; | |
3610 | #ifdef ADAPTIVE_POWER_THROUGHPUT_CONTROL | |
3611 | aptcTR.bytesReceived += a_netbuf_to_len(skb); | |
3612 | applyAPTCHeuristics(ar); | |
3613 | #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ | |
3614 | ||
3615 | A_NETBUF_PUT(skb, pPacket->ActualLength + HTC_HEADER_LEN); | |
3616 | A_NETBUF_PULL(skb, HTC_HEADER_LEN); | |
3617 | ||
3618 | #ifdef DEBUG | |
3619 | if (debugdriver >= 2) { | |
3620 | ar6000_dump_skb(skb); | |
3621 | } | |
3622 | #endif /* DEBUG */ | |
3623 | } | |
3624 | ||
3625 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3626 | ||
3627 | skb->dev = ar->arNetDev; | |
3628 | if (status != A_OK) { | |
3629 | AR6000_STAT_INC(ar, rx_errors); | |
3630 | A_NETBUF_FREE(skb); | |
3631 | } else if (ar->arWmiEnabled == TRUE) { | |
3632 | if (ept == ar->arControlEp) { | |
3633 | /* | |
3634 | * this is a wmi control msg | |
3635 | */ | |
3636 | #ifdef CONFIG_PM | |
3637 | ar6000_check_wow_status(ar, skb, TRUE); | |
3638 | #endif /* CONFIG_PM */ | |
3639 | wmi_control_rx(ar->arWmi, skb); | |
3640 | } else { | |
3641 | WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb); | |
3642 | A_UINT8 is_amsdu, tid, is_acl_data_frame; | |
3643 | is_acl_data_frame = WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == WMI_DATA_HDR_DATA_TYPE_ACL; | |
3644 | #ifdef CONFIG_PM | |
3645 | ar6000_check_wow_status(ar, NULL, FALSE); | |
3646 | #endif /* CONFIG_PM */ | |
3647 | /* | |
3648 | * this is a wmi data packet | |
3649 | */ | |
3650 | // NWF | |
3651 | ||
3652 | if (processDot11Hdr) { | |
3653 | minHdrLen = sizeof(WMI_DATA_HDR) + sizeof(struct ieee80211_frame) + sizeof(ATH_LLC_SNAP_HDR); | |
3654 | } else { | |
3655 | minHdrLen = sizeof (WMI_DATA_HDR) + sizeof(ATH_MAC_HDR) + | |
3656 | sizeof(ATH_LLC_SNAP_HDR); | |
3657 | } | |
3658 | ||
3659 | /* In the case of AP mode we may receive NULL data frames | |
3660 | * that do not have LLC hdr. They are 16 bytes in size. | |
3661 | * Allow these frames in the AP mode. | |
3662 | * ACL data frames don't follow ethernet frame bounds for | |
3663 | * min length | |
3664 | */ | |
3665 | if (ar->arNetworkType != AP_NETWORK && !is_acl_data_frame && | |
3666 | ((pPacket->ActualLength < minHdrLen) || | |
3667 | (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE))) | |
3668 | { | |
3669 | /* | |
3670 | * packet is too short or too long | |
3671 | */ | |
3672 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("TOO SHORT or TOO LONG\n")); | |
3673 | AR6000_STAT_INC(ar, rx_errors); | |
3674 | AR6000_STAT_INC(ar, rx_length_errors); | |
3675 | A_NETBUF_FREE(skb); | |
3676 | } else { | |
3677 | A_UINT16 seq_no; | |
3678 | A_UINT8 meta_type; | |
3679 | ||
3680 | #if 0 | |
3681 | /* Access RSSI values here */ | |
3682 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("RSSI %d\n", | |
3683 | ((WMI_DATA_HDR *) A_NETBUF_DATA(skb))->rssi)); | |
3684 | #endif | |
3685 | /* Get the Power save state of the STA */ | |
3686 | if (ar->arNetworkType == AP_NETWORK) { | |
3687 | sta_t *conn = NULL; | |
3688 | A_UINT8 psState=0,prevPsState; | |
3689 | ATH_MAC_HDR *datap=NULL; | |
3690 | A_UINT16 offset; | |
3691 | ||
3692 | meta_type = WMI_DATA_HDR_GET_META(dhdr); | |
3693 | ||
3694 | psState = (((WMI_DATA_HDR *)A_NETBUF_DATA(skb))->info | |
3695 | >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK; | |
3696 | ||
3697 | offset = sizeof(WMI_DATA_HDR); | |
3698 | ||
3699 | switch (meta_type) { | |
3700 | case 0: | |
3701 | break; | |
3702 | case WMI_META_VERSION_1: | |
3703 | offset += sizeof(WMI_RX_META_V1); | |
3704 | break; | |
3705 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
3706 | case WMI_META_VERSION_2: | |
3707 | offset += sizeof(WMI_RX_META_V2); | |
3708 | break; | |
3709 | #endif | |
3710 | default: | |
3711 | break; | |
3712 | } | |
3713 | ||
3714 | datap = (ATH_MAC_HDR *)(A_NETBUF_DATA(skb)+offset); | |
3715 | conn = ieee80211_find_conn(ar, datap->srcMac); | |
3716 | ||
3717 | if (conn) { | |
3718 | /* if there is a change in PS state of the STA, | |
3719 | * take appropriate steps. | |
3720 | * 1. If Sleep-->Awake, flush the psq for the STA | |
3721 | * Clear the PVB for the STA. | |
3722 | * 2. If Awake-->Sleep, Starting queueing frames | |
3723 | * the STA. | |
3724 | */ | |
3725 | prevPsState = STA_IS_PWR_SLEEP(conn); | |
3726 | if (psState) { | |
3727 | STA_SET_PWR_SLEEP(conn); | |
3728 | } else { | |
3729 | STA_CLR_PWR_SLEEP(conn); | |
3730 | } | |
3731 | ||
3732 | if (prevPsState ^ STA_IS_PWR_SLEEP(conn)) { | |
3733 | ||
3734 | if (!STA_IS_PWR_SLEEP(conn)) { | |
3735 | ||
3736 | A_MUTEX_LOCK(&conn->psqLock); | |
3737 | while (!A_NETBUF_QUEUE_EMPTY(&conn->psq)) { | |
3738 | struct sk_buff *skb=NULL; | |
3739 | ||
3740 | skb = A_NETBUF_DEQUEUE(&conn->psq); | |
3741 | A_MUTEX_UNLOCK(&conn->psqLock); | |
3742 | ar6000_data_tx(skb,ar->arNetDev); | |
3743 | A_MUTEX_LOCK(&conn->psqLock); | |
3744 | } | |
3745 | A_MUTEX_UNLOCK(&conn->psqLock); | |
3746 | /* Clear the PVB for this STA */ | |
3747 | wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0); | |
3748 | } | |
3749 | } | |
3750 | } else { | |
3751 | /* This frame is from a STA that is not associated*/ | |
3752 | A_ASSERT(FALSE); | |
3753 | } | |
3754 | ||
3755 | /* Drop NULL data frames here */ | |
3756 | if((pPacket->ActualLength < minHdrLen) || | |
3757 | (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE)) { | |
3758 | A_NETBUF_FREE(skb); | |
3759 | goto rx_done; | |
3760 | } | |
3761 | } | |
3762 | ||
3763 | is_amsdu = WMI_DATA_HDR_IS_AMSDU(dhdr); | |
3764 | tid = WMI_DATA_HDR_GET_UP(dhdr); | |
3765 | seq_no = WMI_DATA_HDR_GET_SEQNO(dhdr); | |
3766 | meta_type = WMI_DATA_HDR_GET_META(dhdr); | |
3767 | containsDot11Hdr = WMI_DATA_HDR_GET_DOT11(dhdr); | |
3768 | ||
3769 | wmi_data_hdr_remove(ar->arWmi, skb); | |
3770 | ||
3771 | switch (meta_type) { | |
3772 | case WMI_META_VERSION_1: | |
3773 | { | |
3774 | WMI_RX_META_V1 *pMeta = (WMI_RX_META_V1 *)A_NETBUF_DATA(skb); | |
3775 | A_PRINTF("META %d %d %d %d %x\n", pMeta->status, pMeta->rix, pMeta->rssi, pMeta->channel, pMeta->flags); | |
3776 | A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1)); | |
3777 | break; | |
3778 | } | |
3779 | #ifdef CONFIG_CHECKSUM_OFFLOAD | |
3780 | case WMI_META_VERSION_2: | |
3781 | { | |
3782 | WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb); | |
3783 | if(pMeta->csumFlags & 0x1){ | |
3784 | skb->ip_summed=CHECKSUM_COMPLETE; | |
3785 | skb->csum=(pMeta->csum); | |
3786 | } | |
3787 | A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2)); | |
3788 | break; | |
3789 | } | |
3790 | #endif | |
3791 | default: | |
3792 | break; | |
3793 | } | |
3794 | ||
3795 | A_ASSERT(status == A_OK); | |
3796 | ||
3797 | /* NWF: print the 802.11 hdr bytes */ | |
3798 | if(containsDot11Hdr) { | |
3799 | status = wmi_dot11_hdr_remove(ar->arWmi,skb); | |
3800 | } else if(!is_amsdu && !is_acl_data_frame) { | |
3801 | status = wmi_dot3_2_dix(skb); | |
3802 | } | |
3803 | ||
3804 | if (status != A_OK) { | |
3805 | /* Drop frames that could not be processed (lack of memory, etc.) */ | |
3806 | A_NETBUF_FREE(skb); | |
3807 | goto rx_done; | |
3808 | } | |
3809 | ||
3810 | if (is_acl_data_frame) { | |
3811 | A_NETBUF_PUSH(skb, sizeof(int)); | |
3812 | *((short *)A_NETBUF_DATA(skb)) = WMI_ACL_DATA_EVENTID; | |
3813 | /* send the data packet to PAL driver */ | |
3814 | if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) { | |
3815 | if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, skb) == TRUE) | |
3816 | goto rx_done; | |
3817 | } | |
3818 | } | |
3819 | ||
3820 | if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) { | |
3821 | if (ar->arNetworkType == AP_NETWORK) { | |
3822 | struct sk_buff *skb1 = NULL; | |
3823 | ATH_MAC_HDR *datap; | |
3824 | ||
3825 | datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); | |
3826 | if (IEEE80211_IS_MULTICAST(datap->dstMac)) { | |
3827 | /* Bcast/Mcast frames should be sent to the OS | |
3828 | * stack as well as on the air. | |
3829 | */ | |
3830 | skb1 = skb_copy(skb,GFP_ATOMIC); | |
3831 | } else { | |
3832 | /* Search for a connected STA with dstMac as | |
3833 | * the Mac address. If found send the frame to | |
3834 | * it on the air else send the frame up the | |
3835 | * stack | |
3836 | */ | |
3837 | sta_t *conn = NULL; | |
3838 | conn = ieee80211_find_conn(ar, datap->dstMac); | |
3839 | ||
3840 | if (conn && ar->intra_bss) { | |
3841 | skb1 = skb; | |
3842 | skb = NULL; | |
3843 | } else if(conn && !ar->intra_bss) { | |
3844 | A_NETBUF_FREE(skb); | |
3845 | skb = NULL; | |
3846 | } | |
3847 | } | |
3848 | if (skb1) { | |
3849 | ar6000_data_tx(skb1, ar->arNetDev); | |
3850 | } | |
3851 | } | |
3852 | } | |
3853 | #ifdef ATH_AR6K_11N_SUPPORT | |
3854 | aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb); | |
3855 | #endif | |
3856 | ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb); | |
3857 | } | |
3858 | } | |
3859 | } else { | |
3860 | if (EPPING_ALIGNMENT_PAD > 0) { | |
3861 | A_NETBUF_PULL(skb, EPPING_ALIGNMENT_PAD); | |
3862 | } | |
3863 | ar6000_deliver_frames_to_nw_stack((void *)ar->arNetDev, (void *)skb); | |
3864 | } | |
3865 | ||
3866 | rx_done: | |
3867 | ||
3868 | return; | |
3869 | } | |
3870 | ||
3871 | static void | |
3872 | ar6000_deliver_frames_to_nw_stack(void *dev, void *osbuf) | |
3873 | { | |
3874 | struct sk_buff *skb = (struct sk_buff *)osbuf; | |
3875 | ||
3876 | if(skb) { | |
3877 | skb->dev = dev; | |
3878 | if ((skb->dev->flags & IFF_UP) == IFF_UP) { | |
3879 | #ifdef CONFIG_PM | |
3880 | ar6000_check_wow_status((AR_SOFTC_T *)ar6k_priv(dev), skb, FALSE); | |
3881 | #endif /* CONFIG_PM */ | |
3882 | skb->protocol = eth_type_trans(skb, skb->dev); | |
3883 | /* | |
3884 | * If this routine is called on a ISR (Hard IRQ) or DSR (Soft IRQ) | |
3885 | * or tasklet use the netif_rx to deliver the packet to the stack | |
3886 | * netif_rx will queue the packet onto the receive queue and mark | |
3887 | * the softirq thread has a pending action to complete. Kernel will | |
3888 | * schedule the softIrq kernel thread after processing the DSR. | |
3889 | * | |
3890 | * If this routine is called on a process context, use netif_rx_ni | |
3891 | * which will schedle the softIrq kernel thread after queuing the packet. | |
3892 | */ | |
3893 | if (in_interrupt()) { | |
3894 | netif_rx(skb); | |
3895 | } else { | |
3896 | netif_rx_ni(skb); | |
3897 | } | |
3898 | } else { | |
3899 | A_NETBUF_FREE(skb); | |
3900 | } | |
3901 | } | |
3902 | } | |
3903 | ||
3904 | #if 0 | |
3905 | static void | |
3906 | ar6000_deliver_frames_to_bt_stack(void *dev, void *osbuf) | |
3907 | { | |
3908 | struct sk_buff *skb = (struct sk_buff *)osbuf; | |
3909 | ||
3910 | if(skb) { | |
3911 | skb->dev = dev; | |
3912 | if ((skb->dev->flags & IFF_UP) == IFF_UP) { | |
3913 | skb->protocol = htons(ETH_P_CONTROL); | |
3914 | netif_rx(skb); | |
3915 | } else { | |
3916 | A_NETBUF_FREE(skb); | |
3917 | } | |
3918 | } | |
3919 | } | |
3920 | #endif | |
3921 | ||
3922 | static void | |
3923 | ar6000_rx_refill(void *Context, HTC_ENDPOINT_ID Endpoint) | |
3924 | { | |
3925 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; | |
3926 | void *osBuf; | |
3927 | int RxBuffers; | |
3928 | int buffersToRefill; | |
3929 | HTC_PACKET *pPacket; | |
3930 | HTC_PACKET_QUEUE queue; | |
3931 | ||
3932 | buffersToRefill = (int)AR6000_MAX_RX_BUFFERS - | |
3933 | HTCGetNumRecvBuffers(ar->arHtcTarget, Endpoint); | |
3934 | ||
3935 | if (buffersToRefill <= 0) { | |
3936 | /* fast return, nothing to fill */ | |
3937 | return; | |
3938 | } | |
3939 | ||
3940 | INIT_HTC_PACKET_QUEUE(&queue); | |
3941 | ||
3942 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_rx_refill: providing htc with %d buffers at eid=%d\n", | |
3943 | buffersToRefill, Endpoint)); | |
3944 | ||
3945 | for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) { | |
3946 | osBuf = A_NETBUF_ALLOC(AR6000_BUFFER_SIZE); | |
3947 | if (NULL == osBuf) { | |
3948 | break; | |
3949 | } | |
3950 | /* the HTC packet wrapper is at the head of the reserved area | |
3951 | * in the skb */ | |
3952 | pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf)); | |
3953 | /* set re-fill info */ | |
3954 | SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_BUFFER_SIZE,Endpoint); | |
3955 | /* add to queue */ | |
3956 | HTC_PACKET_ENQUEUE(&queue,pPacket); | |
3957 | } | |
3958 | ||
3959 | if (!HTC_QUEUE_EMPTY(&queue)) { | |
3960 | /* add packets */ | |
3961 | HTCAddReceivePktMultiple(ar->arHtcTarget, &queue); | |
3962 | } | |
3963 | ||
3964 | } | |
3965 | ||
3966 | /* clean up our amsdu buffer list */ | |
3967 | static void ar6000_cleanup_amsdu_rxbufs(AR_SOFTC_T *ar) | |
3968 | { | |
3969 | HTC_PACKET *pPacket; | |
3970 | void *osBuf; | |
3971 | ||
3972 | /* empty AMSDU buffer queue and free OS bufs */ | |
3973 | while (TRUE) { | |
3974 | ||
3975 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
3976 | pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue); | |
3977 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
3978 | ||
3979 | if (NULL == pPacket) { | |
3980 | break; | |
3981 | } | |
3982 | ||
3983 | osBuf = pPacket->pPktContext; | |
3984 | if (NULL == osBuf) { | |
3985 | A_ASSERT(FALSE); | |
3986 | break; | |
3987 | } | |
3988 | ||
3989 | A_NETBUF_FREE(osBuf); | |
3990 | } | |
3991 | ||
3992 | } | |
3993 | ||
3994 | ||
3995 | /* refill the amsdu buffer list */ | |
3996 | static void ar6000_refill_amsdu_rxbufs(AR_SOFTC_T *ar, int Count) | |
3997 | { | |
3998 | HTC_PACKET *pPacket; | |
3999 | void *osBuf; | |
4000 | ||
4001 | while (Count > 0) { | |
4002 | osBuf = A_NETBUF_ALLOC(AR6000_AMSDU_BUFFER_SIZE); | |
4003 | if (NULL == osBuf) { | |
4004 | break; | |
4005 | } | |
4006 | /* the HTC packet wrapper is at the head of the reserved area | |
4007 | * in the skb */ | |
4008 | pPacket = (HTC_PACKET *)(A_NETBUF_HEAD(osBuf)); | |
4009 | /* set re-fill info */ | |
4010 | SET_HTC_PACKET_INFO_RX_REFILL(pPacket,osBuf,A_NETBUF_DATA(osBuf),AR6000_AMSDU_BUFFER_SIZE,0); | |
4011 | ||
4012 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
4013 | /* put it in the list */ | |
4014 | HTC_PACKET_ENQUEUE(&ar->amsdu_rx_buffer_queue,pPacket); | |
4015 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
4016 | Count--; | |
4017 | } | |
4018 | ||
4019 | } | |
4020 | ||
4021 | /* callback to allocate a large receive buffer for a pending packet. This function is called when | |
4022 | * an HTC packet arrives whose length exceeds a threshold value | |
4023 | * | |
4024 | * We use a pre-allocated list of buffers of maximum AMSDU size (4K). Under linux it is more optimal to | |
4025 | * keep the allocation size the same to optimize cached-slab allocations. | |
4026 | * | |
4027 | * */ | |
4028 | static HTC_PACKET *ar6000_alloc_amsdu_rxbuf(void *Context, HTC_ENDPOINT_ID Endpoint, int Length) | |
4029 | { | |
4030 | HTC_PACKET *pPacket = NULL; | |
4031 | AR_SOFTC_T *ar = (AR_SOFTC_T *)Context; | |
4032 | int refillCount = 0; | |
4033 | ||
4034 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_RX,("ar6000_alloc_amsdu_rxbuf: eid=%d, Length:%d\n",Endpoint,Length)); | |
4035 | ||
4036 | do { | |
4037 | ||
4038 | if (Length <= AR6000_BUFFER_SIZE) { | |
4039 | /* shouldn't be getting called on normal sized packets */ | |
4040 | A_ASSERT(FALSE); | |
4041 | break; | |
4042 | } | |
4043 | ||
4044 | if (Length > AR6000_AMSDU_BUFFER_SIZE) { | |
4045 | A_ASSERT(FALSE); | |
4046 | break; | |
4047 | } | |
4048 | ||
4049 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
4050 | /* allocate a packet from the list */ | |
4051 | pPacket = HTC_PACKET_DEQUEUE(&ar->amsdu_rx_buffer_queue); | |
4052 | /* see if we need to refill again */ | |
4053 | refillCount = AR6000_MAX_AMSDU_RX_BUFFERS - HTC_PACKET_QUEUE_DEPTH(&ar->amsdu_rx_buffer_queue); | |
4054 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
4055 | ||
4056 | if (NULL == pPacket) { | |
4057 | break; | |
4058 | } | |
4059 | /* set actual endpoint ID */ | |
4060 | pPacket->Endpoint = Endpoint; | |
4061 | ||
4062 | } while (FALSE); | |
4063 | ||
4064 | if (refillCount >= AR6000_AMSDU_REFILL_THRESHOLD) { | |
4065 | ar6000_refill_amsdu_rxbufs(ar,refillCount); | |
4066 | } | |
4067 | ||
4068 | return pPacket; | |
4069 | } | |
4070 | ||
4071 | static void | |
4072 | ar6000_set_multicast_list(struct net_device *dev) | |
4073 | { | |
4074 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: Multicast filter not supported\n")); | |
4075 | } | |
4076 | ||
4077 | static struct net_device_stats * | |
4078 | ar6000_get_stats(struct net_device *dev) | |
4079 | { | |
4080 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
4081 | return &ar->arNetStats; | |
4082 | } | |
4083 | ||
4084 | static struct iw_statistics * | |
4085 | ar6000_get_iwstats(struct net_device * dev) | |
4086 | { | |
4087 | AR_SOFTC_T *ar = (AR_SOFTC_T *)ar6k_priv(dev); | |
4088 | TARGET_STATS *pStats = &ar->arTargetStats; | |
4089 | struct iw_statistics * pIwStats = &ar->arIwStats; | |
4090 | int rtnllocked; | |
4091 | ||
4092 | if (ar->bIsDestroyProgress || ar->arWmiReady == FALSE || ar->arWlanState == WLAN_DISABLED) | |
4093 | { | |
4094 | pIwStats->status = 0; | |
4095 | pIwStats->qual.qual = 0; | |
4096 | pIwStats->qual.level =0; | |
4097 | pIwStats->qual.noise = 0; | |
4098 | pIwStats->discard.code =0; | |
4099 | pIwStats->discard.retries=0; | |
4100 | pIwStats->miss.beacon =0; | |
4101 | return pIwStats; | |
4102 | } | |
4103 | ||
4104 | /* | |
4105 | * The in_atomic function is used to determine if the scheduling is | |
4106 | * allowed in the current context or not. This was introduced in 2.6 | |
4107 | * From what I have read on the differences between 2.4 and 2.6, the | |
4108 | * 2.4 kernel did not support preemption and so this check might not | |
4109 | * be required for 2.4 kernels. | |
4110 | */ | |
4111 | if (in_atomic()) | |
4112 | { | |
4113 | wmi_get_stats_cmd(ar->arWmi); | |
4114 | ||
4115 | pIwStats->status = 1 ; | |
4116 | pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; | |
4117 | pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ | |
4118 | pIwStats->qual.noise = pStats->noise_floor_calibation; | |
4119 | pIwStats->discard.code = pStats->rx_decrypt_err; | |
4120 | pIwStats->discard.retries = pStats->tx_retry_cnt; | |
4121 | pIwStats->miss.beacon = pStats->cs_bmiss_cnt; | |
4122 | return pIwStats; | |
4123 | } | |
4124 | ||
4125 | dev_hold(dev); | |
4126 | rtnllocked = rtnl_is_locked(); | |
4127 | if (rtnllocked) { | |
4128 | rtnl_unlock(); | |
4129 | } | |
4130 | pIwStats->status = 0; | |
4131 | ||
4132 | if (down_interruptible(&ar->arSem)) { | |
4133 | goto err_exit; | |
4134 | } | |
4135 | ||
4136 | do { | |
4137 | ||
4138 | if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { | |
4139 | break; | |
4140 | } | |
4141 | ||
4142 | ar->statsUpdatePending = TRUE; | |
4143 | ||
4144 | if(wmi_get_stats_cmd(ar->arWmi) != A_OK) { | |
4145 | break; | |
4146 | } | |
4147 | ||
4148 | wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == FALSE, wmitimeout * HZ); | |
4149 | if (signal_pending(current)) { | |
4150 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : WMI get stats timeout \n")); | |
4151 | break; | |
4152 | } | |
4153 | pIwStats->status = 1 ; | |
4154 | pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; | |
4155 | pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ | |
4156 | pIwStats->qual.noise = pStats->noise_floor_calibation; | |
4157 | pIwStats->discard.code = pStats->rx_decrypt_err; | |
4158 | pIwStats->discard.retries = pStats->tx_retry_cnt; | |
4159 | pIwStats->miss.beacon = pStats->cs_bmiss_cnt; | |
4160 | } while (0); | |
4161 | up(&ar->arSem); | |
4162 | ||
4163 | err_exit: | |
4164 | if (rtnllocked) { | |
4165 | rtnl_lock(); | |
4166 | } | |
4167 | dev_put(dev); | |
4168 | return pIwStats; | |
4169 | } | |
4170 | ||
4171 | void | |
4172 | ar6000_ready_event(void *devt, A_UINT8 *datap, A_UINT8 phyCap, A_UINT32 sw_ver, A_UINT32 abi_ver) | |
4173 | { | |
4174 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
4175 | struct net_device *dev = ar->arNetDev; | |
4176 | ||
4177 | ar->arWmiReady = TRUE; | |
4178 | wake_up(&arEvent); | |
4179 | A_MEMCPY(dev->dev_addr, datap, AR6000_ETH_ADDR_LEN); | |
4180 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("mac address = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", | |
4181 | dev->dev_addr[0], dev->dev_addr[1], | |
4182 | dev->dev_addr[2], dev->dev_addr[3], | |
4183 | dev->dev_addr[4], dev->dev_addr[5])); | |
4184 | ||
4185 | ar->arPhyCapability = phyCap; | |
4186 | ar->arVersion.wlan_ver = sw_ver; | |
4187 | ar->arVersion.abi_ver = abi_ver; | |
4188 | ||
4189 | #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN | |
4190 | wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN); | |
4191 | #endif | |
4192 | #if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP | |
4193 | wmi_set_lpreamble_cmd(ar->arWmi, 0, WMI_DONOT_IGNORE_BARKER_IN_ERP); | |
4194 | #endif | |
4195 | wmi_set_keepalive_cmd(ar->arWmi, WLAN_CONFIG_KEEP_ALIVE_INTERVAL); | |
4196 | #if WLAN_CONFIG_DISABLE_11N | |
4197 | { | |
4198 | WMI_SET_HT_CAP_CMD htCap; | |
4199 | ||
4200 | A_MEMZERO(&htCap, sizeof(WMI_SET_HT_CAP_CMD)); | |
4201 | htCap.band = 0; | |
4202 | wmi_set_ht_cap_cmd(ar->arWmi, &htCap); | |
4203 | ||
4204 | htCap.band = 1; | |
4205 | wmi_set_ht_cap_cmd(ar->arWmi, &htCap); | |
4206 | } | |
4207 | #endif /* WLAN_CONFIG_DISABLE_11N */ | |
4208 | ||
4209 | #ifdef ATH6K_CONFIG_OTA_MODE | |
4210 | wmi_powermode_cmd(ar->arWmi, MAX_PERF_POWER); | |
4211 | #endif | |
4212 | wmi_disctimeout_cmd(ar->arWmi, WLAN_CONFIG_DISCONNECT_TIMEOUT); | |
4213 | } | |
4214 | ||
4215 | void | |
4216 | add_new_sta(AR_SOFTC_T *ar, A_UINT8 *mac, A_UINT16 aid, A_UINT8 *wpaie, | |
4217 | A_UINT8 ielen, A_UINT8 keymgmt, A_UINT8 ucipher, A_UINT8 auth) | |
4218 | { | |
4219 | A_UINT8 free_slot=aid-1; | |
4220 | ||
4221 | A_MEMCPY(ar->sta_list[free_slot].mac, mac, ATH_MAC_LEN); | |
4222 | A_MEMCPY(ar->sta_list[free_slot].wpa_ie, wpaie, ielen); | |
4223 | ar->sta_list[free_slot].aid = aid; | |
4224 | ar->sta_list[free_slot].keymgmt = keymgmt; | |
4225 | ar->sta_list[free_slot].ucipher = ucipher; | |
4226 | ar->sta_list[free_slot].auth = auth; | |
4227 | ar->sta_list_index = ar->sta_list_index | (1 << free_slot); | |
4228 | ar->arAPStats.sta[free_slot].aid = aid; | |
4229 | } | |
4230 | ||
4231 | void | |
4232 | ar6000_connect_event(AR_SOFTC_T *ar, A_UINT16 channel, A_UINT8 *bssid, | |
4233 | A_UINT16 listenInterval, A_UINT16 beaconInterval, | |
4234 | NETWORK_TYPE networkType, A_UINT8 beaconIeLen, | |
4235 | A_UINT8 assocReqLen, A_UINT8 assocRespLen, | |
4236 | A_UINT8 *assocInfo) | |
4237 | { | |
4238 | union iwreq_data wrqu; | |
4239 | int i, beacon_ie_pos, assoc_resp_ie_pos, assoc_req_ie_pos; | |
4240 | static const char *tag1 = "ASSOCINFO(ReqIEs="; | |
4241 | static const char *tag2 = "ASSOCRESPIE="; | |
4242 | static const char *beaconIetag = "BEACONIE="; | |
4243 | char buf[WMI_CONTROL_MSG_MAX_LEN * 2 + strlen(tag1) + 1]; | |
4244 | char *pos; | |
4245 | A_UINT8 key_op_ctrl; | |
4246 | unsigned long flags; | |
4247 | struct ieee80211req_key *ik; | |
4248 | CRYPTO_TYPE keyType = NONE_CRYPT; | |
4249 | ||
4250 | if(ar->arNetworkType & AP_NETWORK) { | |
4251 | struct net_device *dev = ar->arNetDev; | |
4252 | if(A_MEMCMP(dev->dev_addr, bssid, ATH_MAC_LEN)==0) { | |
4253 | ar->arACS = channel; | |
4254 | ik = &ar->ap_mode_bkey; | |
4255 | ||
4256 | switch(ar->arAuthMode) { | |
4257 | case NONE_AUTH: | |
4258 | if(ar->arPairwiseCrypto == WEP_CRYPT) { | |
4259 | ar6000_install_static_wep_keys(ar); | |
4260 | } | |
4261 | #ifdef WAPI_ENABLE | |
4262 | else if(ar->arPairwiseCrypto == WAPI_CRYPT) { | |
4263 | ap_set_wapi_key(ar, ik); | |
4264 | } | |
4265 | #endif | |
4266 | break; | |
4267 | case WPA_PSK_AUTH: | |
4268 | case WPA2_PSK_AUTH: | |
4269 | case (WPA_PSK_AUTH|WPA2_PSK_AUTH): | |
4270 | switch (ik->ik_type) { | |
4271 | case IEEE80211_CIPHER_TKIP: | |
4272 | keyType = TKIP_CRYPT; | |
4273 | break; | |
4274 | case IEEE80211_CIPHER_AES_CCM: | |
4275 | keyType = AES_CRYPT; | |
4276 | break; | |
4277 | default: | |
4278 | goto skip_key; | |
4279 | } | |
4280 | wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, GROUP_USAGE, | |
4281 | ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc, | |
4282 | ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, | |
4283 | SYNC_BOTH_WMIFLAG); | |
4284 | ||
4285 | break; | |
4286 | } | |
4287 | skip_key: | |
4288 | ar->arConnected = TRUE; | |
4289 | return; | |
4290 | } | |
4291 | ||
4292 | A_PRINTF("NEW STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x \n " | |
4293 | " AID=%d \n", bssid[0], bssid[1], bssid[2], | |
4294 | bssid[3], bssid[4], bssid[5], channel); | |
4295 | switch ((listenInterval>>8)&0xFF) { | |
4296 | case OPEN_AUTH: | |
4297 | A_PRINTF("AUTH: OPEN\n"); | |
4298 | break; | |
4299 | case SHARED_AUTH: | |
4300 | A_PRINTF("AUTH: SHARED\n"); | |
4301 | break; | |
4302 | default: | |
4303 | A_PRINTF("AUTH: Unknown\n"); | |
4304 | break; | |
4305 | }; | |
4306 | switch (listenInterval&0xFF) { | |
4307 | case WPA_PSK_AUTH: | |
4308 | A_PRINTF("KeyMgmt: WPA-PSK\n"); | |
4309 | break; | |
4310 | case WPA2_PSK_AUTH: | |
4311 | A_PRINTF("KeyMgmt: WPA2-PSK\n"); | |
4312 | break; | |
4313 | default: | |
4314 | A_PRINTF("KeyMgmt: NONE\n"); | |
4315 | break; | |
4316 | }; | |
4317 | switch (beaconInterval) { | |
4318 | case AES_CRYPT: | |
4319 | A_PRINTF("Cipher: AES\n"); | |
4320 | break; | |
4321 | case TKIP_CRYPT: | |
4322 | A_PRINTF("Cipher: TKIP\n"); | |
4323 | break; | |
4324 | case WEP_CRYPT: | |
4325 | A_PRINTF("Cipher: WEP\n"); | |
4326 | break; | |
4327 | #ifdef WAPI_ENABLE | |
4328 | case WAPI_CRYPT: | |
4329 | A_PRINTF("Cipher: WAPI\n"); | |
4330 | break; | |
4331 | #endif | |
4332 | default: | |
4333 | A_PRINTF("Cipher: NONE\n"); | |
4334 | break; | |
4335 | }; | |
4336 | ||
4337 | add_new_sta(ar, bssid, channel /*aid*/, | |
4338 | assocInfo /* WPA IE */, assocRespLen /* IE len */, | |
4339 | listenInterval&0xFF /* Keymgmt */, beaconInterval /* cipher */, | |
4340 | (listenInterval>>8)&0xFF /* auth alg */); | |
4341 | ||
4342 | /* Send event to application */ | |
4343 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4344 | A_MEMCPY(wrqu.addr.sa_data, bssid, ATH_MAC_LEN); | |
4345 | wireless_send_event(ar->arNetDev, IWEVREGISTERED, &wrqu, NULL); | |
4346 | /* In case the queue is stopped when we switch modes, this will | |
4347 | * wake it up | |
4348 | */ | |
4349 | netif_wake_queue(ar->arNetDev); | |
4350 | return; | |
4351 | } | |
4352 | ||
4353 | #ifdef ATH6K_CONFIG_CFG80211 | |
4354 | ar6k_cfg80211_connect_event(ar, channel, bssid, | |
4355 | listenInterval, beaconInterval, | |
4356 | networkType, beaconIeLen, | |
4357 | assocReqLen, assocRespLen, | |
4358 | assocInfo); | |
4359 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
4360 | ||
4361 | A_MEMCPY(ar->arBssid, bssid, sizeof(ar->arBssid)); | |
4362 | ar->arBssChannel = channel; | |
4363 | ||
4364 | A_PRINTF("AR6000 connected event on freq %d ", channel); | |
4365 | A_PRINTF("with bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " | |
4366 | " listenInterval=%d, beaconInterval = %d, beaconIeLen = %d assocReqLen=%d" | |
4367 | " assocRespLen =%d\n", | |
4368 | bssid[0], bssid[1], bssid[2], | |
4369 | bssid[3], bssid[4], bssid[5], | |
4370 | listenInterval, beaconInterval, | |
4371 | beaconIeLen, assocReqLen, assocRespLen); | |
4372 | if (networkType & ADHOC_NETWORK) { | |
4373 | if (networkType & ADHOC_CREATOR) { | |
4374 | A_PRINTF("Network: Adhoc (Creator)\n"); | |
4375 | } else { | |
4376 | A_PRINTF("Network: Adhoc (Joiner)\n"); | |
4377 | } | |
4378 | } else { | |
4379 | A_PRINTF("Network: Infrastructure\n"); | |
4380 | } | |
4381 | ||
4382 | if ((ar->arNetworkType == INFRA_NETWORK)) { | |
4383 | wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB); | |
4384 | } | |
4385 | ||
4386 | if (beaconIeLen && (sizeof(buf) > (9 + beaconIeLen * 2))) { | |
4387 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nBeaconIEs= ")); | |
4388 | ||
4389 | beacon_ie_pos = 0; | |
4390 | A_MEMZERO(buf, sizeof(buf)); | |
4391 | sprintf(buf, "%s", beaconIetag); | |
4392 | pos = buf + 9; | |
4393 | for (i = beacon_ie_pos; i < beacon_ie_pos + beaconIeLen; i++) { | |
4394 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); | |
4395 | sprintf(pos, "%2.2x", assocInfo[i]); | |
4396 | pos += 2; | |
4397 | } | |
4398 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); | |
4399 | ||
4400 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4401 | wrqu.data.length = strlen(buf); | |
4402 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
4403 | } | |
4404 | ||
4405 | if (assocRespLen && (sizeof(buf) > (12 + (assocRespLen * 2)))) | |
4406 | { | |
4407 | assoc_resp_ie_pos = beaconIeLen + assocReqLen + | |
4408 | sizeof(A_UINT16) + /* capinfo*/ | |
4409 | sizeof(A_UINT16) + /* status Code */ | |
4410 | sizeof(A_UINT16) ; /* associd */ | |
4411 | A_MEMZERO(buf, sizeof(buf)); | |
4412 | sprintf(buf, "%s", tag2); | |
4413 | pos = buf + 12; | |
4414 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocRespIEs= ")); | |
4415 | /* | |
4416 | * The Association Response Frame w.o. the WLAN header is delivered to | |
4417 | * the host, so skip over to the IEs | |
4418 | */ | |
4419 | for (i = assoc_resp_ie_pos; i < assoc_resp_ie_pos + assocRespLen - 6; i++) | |
4420 | { | |
4421 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); | |
4422 | sprintf(pos, "%2.2x", assocInfo[i]); | |
4423 | pos += 2; | |
4424 | } | |
4425 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); | |
4426 | ||
4427 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4428 | wrqu.data.length = strlen(buf); | |
4429 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
4430 | } | |
4431 | ||
4432 | if (assocReqLen && (sizeof(buf) > (17 + (assocReqLen * 2)))) { | |
4433 | /* | |
4434 | * assoc Request includes capability and listen interval. Skip these. | |
4435 | */ | |
4436 | assoc_req_ie_pos = beaconIeLen + | |
4437 | sizeof(A_UINT16) + /* capinfo*/ | |
4438 | sizeof(A_UINT16); /* listen interval */ | |
4439 | ||
4440 | A_MEMZERO(buf, sizeof(buf)); | |
4441 | sprintf(buf, "%s", tag1); | |
4442 | pos = buf + 17; | |
4443 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AssocReqIEs= ")); | |
4444 | for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) { | |
4445 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); | |
4446 | sprintf(pos, "%2.2x", assocInfo[i]); | |
4447 | pos += 2;; | |
4448 | } | |
4449 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); | |
4450 | ||
4451 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4452 | wrqu.data.length = strlen(buf); | |
4453 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
4454 | } | |
4455 | ||
4456 | #ifdef USER_KEYS | |
4457 | if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN && | |
4458 | ar->user_saved_keys.keyOk == TRUE) | |
4459 | { | |
4460 | key_op_ctrl = KEY_OP_VALID_MASK & ~KEY_OP_INIT_TSC; | |
4461 | ||
4462 | if (ar->user_key_ctrl & AR6000_USER_SETKEYS_RSC_UNCHANGED) { | |
4463 | key_op_ctrl &= ~KEY_OP_INIT_RSC; | |
4464 | } else { | |
4465 | key_op_ctrl |= KEY_OP_INIT_RSC; | |
4466 | } | |
4467 | ar6000_reinstall_keys(ar, key_op_ctrl); | |
4468 | } | |
4469 | #endif /* USER_KEYS */ | |
4470 | ||
4471 | netif_wake_queue(ar->arNetDev); | |
4472 | ||
4473 | /* For CFG80211 the key configuration and the default key comes in after connect so no point in plumbing invalid keys */ | |
4474 | #ifndef ATH6K_CONFIG_CFG80211 | |
4475 | if ((networkType & ADHOC_NETWORK) && | |
4476 | (OPEN_AUTH == ar->arDot11AuthMode) && | |
4477 | (NONE_AUTH == ar->arAuthMode) && | |
4478 | (WEP_CRYPT == ar->arPairwiseCrypto)) | |
4479 | { | |
4480 | if (!ar->arConnected) { | |
4481 | wmi_addKey_cmd(ar->arWmi, | |
4482 | ar->arDefTxKeyIndex, | |
4483 | WEP_CRYPT, | |
4484 | GROUP_USAGE | TX_USAGE, | |
4485 | ar->arWepKeyList[ar->arDefTxKeyIndex].arKeyLen, | |
4486 | NULL, | |
4487 | ar->arWepKeyList[ar->arDefTxKeyIndex].arKey, KEY_OP_INIT_VAL, NULL, | |
4488 | NO_SYNC_WMIFLAG); | |
4489 | } | |
4490 | } | |
4491 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
4492 | ||
4493 | /* Update connect & link status atomically */ | |
4494 | spin_lock_irqsave(&ar->arLock, flags); | |
4495 | ar->arConnected = TRUE; | |
4496 | ar->arConnectPending = FALSE; | |
4497 | netif_carrier_on(ar->arNetDev); | |
4498 | spin_unlock_irqrestore(&ar->arLock, flags); | |
4499 | /* reset the rx aggr state */ | |
4500 | aggr_reset_state(ar->aggr_cntxt); | |
4501 | reconnect_flag = 0; | |
4502 | ||
4503 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4504 | A_MEMCPY(wrqu.addr.sa_data, bssid, IEEE80211_ADDR_LEN); | |
4505 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
4506 | wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL); | |
4507 | if ((ar->arNetworkType == ADHOC_NETWORK) && ar->arIbssPsEnable) { | |
4508 | A_MEMZERO(ar->arNodeMap, sizeof(ar->arNodeMap)); | |
4509 | ar->arNodeNum = 0; | |
4510 | ar->arNexEpId = ENDPOINT_2; | |
4511 | } | |
4512 | if (!ar->arUserBssFilter) { | |
4513 | wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0); | |
4514 | } | |
4515 | ||
4516 | } | |
4517 | ||
4518 | void ar6000_set_numdataendpts(AR_SOFTC_T *ar, A_UINT32 num) | |
4519 | { | |
4520 | A_ASSERT(num <= (HTC_MAILBOX_NUM_MAX - 1)); | |
4521 | ar->arNumDataEndPts = num; | |
4522 | } | |
4523 | ||
4524 | void | |
4525 | sta_cleanup(AR_SOFTC_T *ar, A_UINT8 i) | |
4526 | { | |
4527 | struct sk_buff *skb; | |
4528 | ||
4529 | /* empty the queued pkts in the PS queue if any */ | |
4530 | A_MUTEX_LOCK(&ar->sta_list[i].psqLock); | |
4531 | while (!A_NETBUF_QUEUE_EMPTY(&ar->sta_list[i].psq)) { | |
4532 | skb = A_NETBUF_DEQUEUE(&ar->sta_list[i].psq); | |
4533 | A_NETBUF_FREE(skb); | |
4534 | } | |
4535 | A_MUTEX_UNLOCK(&ar->sta_list[i].psqLock); | |
4536 | ||
4537 | /* Zero out the state fields */ | |
4538 | A_MEMZERO(&ar->arAPStats.sta[ar->sta_list[i].aid-1], sizeof(WMI_PER_STA_STAT)); | |
4539 | A_MEMZERO(&ar->sta_list[i].mac, ATH_MAC_LEN); | |
4540 | A_MEMZERO(&ar->sta_list[i].wpa_ie, IEEE80211_MAX_IE); | |
4541 | ar->sta_list[i].aid = 0; | |
4542 | ar->sta_list[i].flags = 0; | |
4543 | ||
4544 | ar->sta_list_index = ar->sta_list_index & ~(1 << i); | |
4545 | ||
4546 | } | |
4547 | ||
4548 | A_UINT8 | |
4549 | remove_sta(AR_SOFTC_T *ar, A_UINT8 *mac, A_UINT16 reason) | |
4550 | { | |
4551 | A_UINT8 i, removed=0; | |
4552 | ||
4553 | if(IS_MAC_NULL(mac)) { | |
4554 | return removed; | |
4555 | } | |
4556 | ||
4557 | if(IS_MAC_BCAST(mac)) { | |
4558 | A_PRINTF("DEL ALL STA\n"); | |
4559 | for(i=0; i < AP_MAX_NUM_STA; i++) { | |
4560 | if(!IS_MAC_NULL(ar->sta_list[i].mac)) { | |
4561 | sta_cleanup(ar, i); | |
4562 | removed = 1; | |
4563 | } | |
4564 | } | |
4565 | } else { | |
4566 | for(i=0; i < AP_MAX_NUM_STA; i++) { | |
4567 | if(A_MEMCMP(ar->sta_list[i].mac, mac, ATH_MAC_LEN)==0) { | |
4568 | A_PRINTF("DEL STA %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x " | |
4569 | " aid=%d REASON=%d\n", mac[0], mac[1], mac[2], | |
4570 | mac[3], mac[4], mac[5], ar->sta_list[i].aid, reason); | |
4571 | ||
4572 | sta_cleanup(ar, i); | |
4573 | removed = 1; | |
4574 | break; | |
4575 | } | |
4576 | } | |
4577 | } | |
4578 | return removed; | |
4579 | } | |
4580 | ||
4581 | void | |
4582 | ar6000_disconnect_event(AR_SOFTC_T *ar, A_UINT8 reason, A_UINT8 *bssid, | |
4583 | A_UINT8 assocRespLen, A_UINT8 *assocInfo, A_UINT16 protocolReasonStatus) | |
4584 | { | |
4585 | A_UINT8 i; | |
4586 | unsigned long flags; | |
4587 | union iwreq_data wrqu; | |
4588 | ||
4589 | if(ar->arNetworkType & AP_NETWORK) { | |
4590 | union iwreq_data wrqu; | |
4591 | struct sk_buff *skb; | |
4592 | ||
4593 | if(!remove_sta(ar, bssid, protocolReasonStatus)) { | |
4594 | return; | |
4595 | } | |
4596 | ||
4597 | /* If there are no more associated STAs, empty the mcast PS q */ | |
4598 | if (ar->sta_list_index == 0) { | |
4599 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
4600 | while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) { | |
4601 | skb = A_NETBUF_DEQUEUE(&ar->mcastpsq); | |
4602 | A_NETBUF_FREE(skb); | |
4603 | } | |
4604 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
4605 | ||
4606 | /* Clear the LSB of the BitMapCtl field of the TIM IE */ | |
4607 | if (ar->arWmiReady) { | |
4608 | wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0); | |
4609 | } | |
4610 | } | |
4611 | ||
4612 | if(!IS_MAC_BCAST(bssid)) { | |
4613 | /* Send event to application */ | |
4614 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4615 | A_MEMCPY(wrqu.addr.sa_data, bssid, ATH_MAC_LEN); | |
4616 | wireless_send_event(ar->arNetDev, IWEVEXPIRED, &wrqu, NULL); | |
4617 | } | |
4618 | return; | |
4619 | } | |
4620 | ||
4621 | #ifdef ATH6K_CONFIG_CFG80211 | |
4622 | ar6k_cfg80211_disconnect_event(ar, reason, bssid, | |
4623 | assocRespLen, assocInfo, | |
4624 | protocolReasonStatus); | |
4625 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
4626 | ||
4627 | /* Send disconnect event to supplicant */ | |
4628 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4629 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
4630 | wireless_send_event(ar->arNetDev, SIOCGIWAP, &wrqu, NULL); | |
4631 | ||
4632 | /* it is necessary to clear the host-side rx aggregation state */ | |
4633 | aggr_reset_state(ar->aggr_cntxt); | |
4634 | ||
4635 | A_UNTIMEOUT(&ar->disconnect_timer); | |
4636 | ||
4637 | A_PRINTF("AR6000 disconnected"); | |
4638 | if (bssid[0] || bssid[1] || bssid[2] || bssid[3] || bssid[4] || bssid[5]) { | |
4639 | A_PRINTF(" from %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", | |
4640 | bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); | |
4641 | } | |
4642 | ||
4643 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nDisconnect Reason is %d", reason)); | |
4644 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nProtocol Reason/Status Code is %d", protocolReasonStatus)); | |
4645 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\nAssocResp Frame = %s", | |
4646 | assocRespLen ? " " : "NULL")); | |
4647 | for (i = 0; i < assocRespLen; i++) { | |
4648 | if (!(i % 0x10)) { | |
4649 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); | |
4650 | } | |
4651 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); | |
4652 | } | |
4653 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); | |
4654 | /* | |
4655 | * If the event is due to disconnect cmd from the host, only they the target | |
4656 | * would stop trying to connect. Under any other condition, target would | |
4657 | * keep trying to connect. | |
4658 | * | |
4659 | */ | |
4660 | if( reason == DISCONNECT_CMD) | |
4661 | { | |
4662 | ar->arConnectPending = FALSE; | |
4663 | if ((!ar->arUserBssFilter) && (ar->arWmiReady)) { | |
4664 | wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0); | |
4665 | } | |
4666 | } else { | |
4667 | ar->arConnectPending = TRUE; | |
4668 | if (((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x11)) || | |
4669 | ((reason == ASSOC_FAILED) && (protocolReasonStatus == 0x0) && (reconnect_flag == 1))) { | |
4670 | ar->arConnected = TRUE; | |
4671 | return; | |
4672 | } | |
4673 | } | |
4674 | ||
4675 | if ((reason == NO_NETWORK_AVAIL) && (ar->arWmiReady)) | |
4676 | { | |
4677 | bss_t *pWmiSsidnode = NULL; | |
4678 | ||
4679 | /* remove the current associated bssid node */ | |
4680 | wmi_free_node (ar->arWmi, bssid); | |
4681 | ||
4682 | /* | |
4683 | * In case any other same SSID nodes are present | |
4684 | * remove it, since those nodes also not available now | |
4685 | */ | |
4686 | do | |
4687 | { | |
4688 | /* | |
4689 | * Find the nodes based on SSID and remove it | |
4690 | * NOTE :: This case will not work out for Hidden-SSID | |
4691 | */ | |
4692 | pWmiSsidnode = wmi_find_Ssidnode (ar->arWmi, ar->arSsid, ar->arSsidLen, FALSE, TRUE); | |
4693 | ||
4694 | if (pWmiSsidnode) | |
4695 | { | |
4696 | wmi_free_node (ar->arWmi, pWmiSsidnode->ni_macaddr); | |
4697 | } | |
4698 | ||
4699 | } while (pWmiSsidnode); | |
4700 | } | |
4701 | ||
4702 | /* Update connect & link status atomically */ | |
4703 | spin_lock_irqsave(&ar->arLock, flags); | |
4704 | ar->arConnected = FALSE; | |
4705 | netif_carrier_off(ar->arNetDev); | |
4706 | spin_unlock_irqrestore(&ar->arLock, flags); | |
4707 | ||
4708 | if( (reason != CSERV_DISCONNECT) || (reconnect_flag != 1) ) { | |
4709 | reconnect_flag = 0; | |
4710 | } | |
4711 | ||
4712 | #ifdef USER_KEYS | |
4713 | if (reason != CSERV_DISCONNECT) | |
4714 | { | |
4715 | ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; | |
4716 | ar->user_key_ctrl = 0; | |
4717 | } | |
4718 | #endif /* USER_KEYS */ | |
4719 | ||
4720 | netif_stop_queue(ar->arNetDev); | |
4721 | A_MEMZERO(ar->arBssid, sizeof(ar->arBssid)); | |
4722 | ar->arBssChannel = 0; | |
4723 | ar->arBeaconInterval = 0; | |
4724 | ||
4725 | ar6000_TxDataCleanup(ar); | |
4726 | } | |
4727 | ||
4728 | void | |
4729 | ar6000_regDomain_event(AR_SOFTC_T *ar, A_UINT32 regCode) | |
4730 | { | |
4731 | A_PRINTF("AR6000 Reg Code = 0x%x\n", regCode); | |
4732 | ar->arRegCode = regCode; | |
4733 | } | |
4734 | ||
4735 | #ifdef ATH_AR6K_11N_SUPPORT | |
4736 | void | |
4737 | ar6000_aggr_rcv_addba_req_evt(AR_SOFTC_T *ar, WMI_ADDBA_REQ_EVENT *evt) | |
4738 | { | |
4739 | if(evt->status == 0) { | |
4740 | aggr_recv_addba_req_evt(ar->aggr_cntxt, evt->tid, evt->st_seq_no, evt->win_sz); | |
4741 | } | |
4742 | } | |
4743 | ||
4744 | void | |
4745 | ar6000_aggr_rcv_addba_resp_evt(AR_SOFTC_T *ar, WMI_ADDBA_RESP_EVENT *evt) | |
4746 | { | |
4747 | A_PRINTF("ADDBA RESP. tid %d status %d, sz %d\n", evt->tid, evt->status, evt->amsdu_sz); | |
4748 | if(evt->status == 0) { | |
4749 | } | |
4750 | } | |
4751 | ||
4752 | void | |
4753 | ar6000_aggr_rcv_delba_req_evt(AR_SOFTC_T *ar, WMI_DELBA_EVENT *evt) | |
4754 | { | |
4755 | aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid); | |
4756 | } | |
4757 | #endif | |
4758 | ||
4759 | void register_pal_cb(ar6k_pal_config_t *palConfig_p) | |
4760 | { | |
4761 | ar6k_pal_config_g = *palConfig_p; | |
4762 | } | |
4763 | ||
4764 | void | |
4765 | ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd) | |
4766 | { | |
4767 | void *osbuf = NULL; | |
4768 | A_INT8 i; | |
4769 | A_UINT8 size, *buf; | |
4770 | A_STATUS ret = A_OK; | |
4771 | ||
4772 | size = cmd->evt_buf_sz + 4; | |
4773 | osbuf = A_NETBUF_ALLOC(size); | |
4774 | if (osbuf == NULL) { | |
4775 | ret = A_NO_MEMORY; | |
4776 | A_PRINTF("Error in allocating netbuf \n"); | |
4777 | return; | |
4778 | } | |
4779 | ||
4780 | A_NETBUF_PUT(osbuf, size); | |
4781 | buf = (A_UINT8 *)A_NETBUF_DATA(osbuf); | |
4782 | /* First 2-bytes carry HCI event/ACL data type | |
4783 | * the next 2 are free | |
4784 | */ | |
4785 | *((short *)buf) = WMI_HCI_EVENT_EVENTID; | |
4786 | buf += sizeof(int); | |
4787 | A_MEMCPY(buf, cmd->buf, cmd->evt_buf_sz); | |
4788 | ||
4789 | if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) | |
4790 | { | |
4791 | /* pass the cmd packet to PAL driver */ | |
4792 | if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, osbuf) == TRUE) | |
4793 | return; | |
4794 | } | |
4795 | ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf); | |
4796 | if(loghci) { | |
4797 | A_PRINTF_LOG("HCI Event From PAL <-- \n"); | |
4798 | for(i = 0; i < cmd->evt_buf_sz; i++) { | |
4799 | A_PRINTF_LOG("0x%02x ", cmd->buf[i]); | |
4800 | if((i % 10) == 0) { | |
4801 | A_PRINTF_LOG("\n"); | |
4802 | } | |
4803 | } | |
4804 | A_PRINTF_LOG("\n"); | |
4805 | A_PRINTF_LOG("==================================\n"); | |
4806 | } | |
4807 | } | |
4808 | ||
4809 | void | |
4810 | ar6000_neighborReport_event(AR_SOFTC_T *ar, int numAps, WMI_NEIGHBOR_INFO *info) | |
4811 | { | |
4812 | #if WIRELESS_EXT >= 18 | |
4813 | struct iw_pmkid_cand *pmkcand; | |
4814 | #else /* WIRELESS_EXT >= 18 */ | |
4815 | static const char *tag = "PRE-AUTH"; | |
4816 | char buf[128]; | |
4817 | #endif /* WIRELESS_EXT >= 18 */ | |
4818 | ||
4819 | union iwreq_data wrqu; | |
4820 | int i; | |
4821 | ||
4822 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("AR6000 Neighbor Report Event\n")); | |
4823 | for (i=0; i < numAps; info++, i++) { | |
4824 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", | |
4825 | info->bssid[0], info->bssid[1], info->bssid[2], | |
4826 | info->bssid[3], info->bssid[4], info->bssid[5])); | |
4827 | if (info->bssFlags & WMI_PREAUTH_CAPABLE_BSS) { | |
4828 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("preauth-cap")); | |
4829 | } | |
4830 | if (info->bssFlags & WMI_PMKID_VALID_BSS) { | |
4831 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,(" pmkid-valid\n")); | |
4832 | continue; /* we skip bss if the pmkid is already valid */ | |
4833 | } | |
4834 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("\n")); | |
4835 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4836 | #if WIRELESS_EXT >= 18 | |
4837 | pmkcand = A_MALLOC_NOWAIT(sizeof(struct iw_pmkid_cand)); | |
4838 | A_MEMZERO(pmkcand, sizeof(struct iw_pmkid_cand)); | |
4839 | pmkcand->index = i; | |
4840 | pmkcand->flags = info->bssFlags; | |
4841 | A_MEMCPY(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN); | |
4842 | wrqu.data.length = sizeof(struct iw_pmkid_cand); | |
4843 | wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand); | |
4844 | A_FREE(pmkcand); | |
4845 | #else /* WIRELESS_EXT >= 18 */ | |
4846 | snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", | |
4847 | tag, | |
4848 | info->bssid[0], info->bssid[1], info->bssid[2], | |
4849 | info->bssid[3], info->bssid[4], info->bssid[5], | |
4850 | i, info->bssFlags); | |
4851 | wrqu.data.length = strlen(buf); | |
4852 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
4853 | #endif /* WIRELESS_EXT >= 18 */ | |
4854 | } | |
4855 | } | |
4856 | ||
4857 | void | |
4858 | ar6000_tkip_micerr_event(AR_SOFTC_T *ar, A_UINT8 keyid, A_BOOL ismcast) | |
4859 | { | |
4860 | static const char *tag = "MLME-MICHAELMICFAILURE.indication"; | |
4861 | char buf[128]; | |
4862 | union iwreq_data wrqu; | |
4863 | ||
4864 | /* | |
4865 | * For AP case, keyid will have aid of STA which sent pkt with | |
4866 | * MIC error. Use this aid to get MAC & send it to hostapd. | |
4867 | */ | |
4868 | if (ar->arNetworkType == AP_NETWORK) { | |
4869 | sta_t *s = ieee80211_find_conn_for_aid(ar, (keyid >> 2)); | |
4870 | if(!s){ | |
4871 | A_PRINTF("AP TKIP MIC error received from Invalid aid / STA not found =%d\n", keyid); | |
4872 | return; | |
4873 | } | |
4874 | A_PRINTF("AP TKIP MIC error received from aid=%d\n", keyid); | |
4875 | snprintf(buf,sizeof(buf), "%s addr=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", | |
4876 | tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]); | |
4877 | } else { | |
4878 | ||
4879 | #ifdef ATH6K_CONFIG_CFG80211 | |
4880 | ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast); | |
4881 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
4882 | ||
4883 | A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n", | |
4884 | keyid & 0x3, ismcast ? "multi": "uni"); | |
4885 | snprintf(buf, sizeof(buf), "%s(keyid=%d %sicast)", tag, keyid & 0x3, | |
4886 | ismcast ? "mult" : "un"); | |
4887 | } | |
4888 | ||
4889 | memset(&wrqu, 0, sizeof(wrqu)); | |
4890 | wrqu.data.length = strlen(buf); | |
4891 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
4892 | } | |
4893 | ||
4894 | void | |
4895 | ar6000_scanComplete_event(AR_SOFTC_T *ar, A_STATUS status) | |
4896 | { | |
4897 | ||
4898 | #ifdef ATH6K_CONFIG_CFG80211 | |
4899 | ar6k_cfg80211_scanComplete_event(ar, status); | |
4900 | #endif /* ATH6K_CONFIG_CFG80211 */ | |
4901 | ||
4902 | if (!ar->arUserBssFilter) { | |
4903 | wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0); | |
4904 | } | |
4905 | if (ar->scan_triggered) { | |
4906 | if (status==A_OK) { | |
4907 | union iwreq_data wrqu; | |
4908 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
4909 | wireless_send_event(ar->arNetDev, SIOCGIWSCAN, &wrqu, NULL); | |
4910 | } | |
4911 | ar->scan_triggered = 0; | |
4912 | } | |
4913 | ||
4914 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,( "AR6000 scan complete: %d\n", status)); | |
4915 | } | |
4916 | ||
4917 | void | |
4918 | ar6000_targetStats_event(AR_SOFTC_T *ar, A_UINT8 *ptr, A_UINT32 len) | |
4919 | { | |
4920 | A_UINT8 ac; | |
4921 | ||
4922 | if(ar->arNetworkType == AP_NETWORK) { | |
4923 | WMI_AP_MODE_STAT *p = (WMI_AP_MODE_STAT *)ptr; | |
4924 | WMI_AP_MODE_STAT *ap = &ar->arAPStats; | |
4925 | ||
4926 | if (len < sizeof(*p)) { | |
4927 | return; | |
4928 | } | |
4929 | ||
4930 | for(ac=0;ac<AP_MAX_NUM_STA;ac++) { | |
4931 | ap->sta[ac].tx_bytes += p->sta[ac].tx_bytes; | |
4932 | ap->sta[ac].tx_pkts += p->sta[ac].tx_pkts; | |
4933 | ap->sta[ac].tx_error += p->sta[ac].tx_error; | |
4934 | ap->sta[ac].tx_discard += p->sta[ac].tx_discard; | |
4935 | ap->sta[ac].rx_bytes += p->sta[ac].rx_bytes; | |
4936 | ap->sta[ac].rx_pkts += p->sta[ac].rx_pkts; | |
4937 | ap->sta[ac].rx_error += p->sta[ac].rx_error; | |
4938 | ap->sta[ac].rx_discard += p->sta[ac].rx_discard; | |
4939 | } | |
4940 | ||
4941 | } else { | |
4942 | WMI_TARGET_STATS *pTarget = (WMI_TARGET_STATS *)ptr; | |
4943 | TARGET_STATS *pStats = &ar->arTargetStats; | |
4944 | ||
4945 | if (len < sizeof(*pTarget)) { | |
4946 | return; | |
4947 | } | |
4948 | ||
4949 | // Update the RSSI of the connected bss. | |
4950 | if (ar->arConnected) { | |
4951 | bss_t *pConnBss = NULL; | |
4952 | ||
4953 | pConnBss = wmi_find_node(ar->arWmi,ar->arBssid); | |
4954 | if (pConnBss) | |
4955 | { | |
4956 | pConnBss->ni_rssi = pTarget->cservStats.cs_aveBeacon_rssi; | |
4957 | pConnBss->ni_snr = pTarget->cservStats.cs_aveBeacon_snr; | |
4958 | wmi_node_return(ar->arWmi, pConnBss); | |
4959 | } | |
4960 | } | |
4961 | ||
4962 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 updating target stats\n")); | |
4963 | pStats->tx_packets += pTarget->txrxStats.tx_stats.tx_packets; | |
4964 | pStats->tx_bytes += pTarget->txrxStats.tx_stats.tx_bytes; | |
4965 | pStats->tx_unicast_pkts += pTarget->txrxStats.tx_stats.tx_unicast_pkts; | |
4966 | pStats->tx_unicast_bytes += pTarget->txrxStats.tx_stats.tx_unicast_bytes; | |
4967 | pStats->tx_multicast_pkts += pTarget->txrxStats.tx_stats.tx_multicast_pkts; | |
4968 | pStats->tx_multicast_bytes += pTarget->txrxStats.tx_stats.tx_multicast_bytes; | |
4969 | pStats->tx_broadcast_pkts += pTarget->txrxStats.tx_stats.tx_broadcast_pkts; | |
4970 | pStats->tx_broadcast_bytes += pTarget->txrxStats.tx_stats.tx_broadcast_bytes; | |
4971 | pStats->tx_rts_success_cnt += pTarget->txrxStats.tx_stats.tx_rts_success_cnt; | |
4972 | for(ac = 0; ac < WMM_NUM_AC; ac++) | |
4973 | pStats->tx_packet_per_ac[ac] += pTarget->txrxStats.tx_stats.tx_packet_per_ac[ac]; | |
4974 | pStats->tx_errors += pTarget->txrxStats.tx_stats.tx_errors; | |
4975 | pStats->tx_failed_cnt += pTarget->txrxStats.tx_stats.tx_failed_cnt; | |
4976 | pStats->tx_retry_cnt += pTarget->txrxStats.tx_stats.tx_retry_cnt; | |
4977 | pStats->tx_mult_retry_cnt += pTarget->txrxStats.tx_stats.tx_mult_retry_cnt; | |
4978 | pStats->tx_rts_fail_cnt += pTarget->txrxStats.tx_stats.tx_rts_fail_cnt; | |
4979 | pStats->tx_unicast_rate = wmi_get_rate(pTarget->txrxStats.tx_stats.tx_unicast_rate); | |
4980 | ||
4981 | pStats->rx_packets += pTarget->txrxStats.rx_stats.rx_packets; | |
4982 | pStats->rx_bytes += pTarget->txrxStats.rx_stats.rx_bytes; | |
4983 | pStats->rx_unicast_pkts += pTarget->txrxStats.rx_stats.rx_unicast_pkts; | |
4984 | pStats->rx_unicast_bytes += pTarget->txrxStats.rx_stats.rx_unicast_bytes; | |
4985 | pStats->rx_multicast_pkts += pTarget->txrxStats.rx_stats.rx_multicast_pkts; | |
4986 | pStats->rx_multicast_bytes += pTarget->txrxStats.rx_stats.rx_multicast_bytes; | |
4987 | pStats->rx_broadcast_pkts += pTarget->txrxStats.rx_stats.rx_broadcast_pkts; | |
4988 | pStats->rx_broadcast_bytes += pTarget->txrxStats.rx_stats.rx_broadcast_bytes; | |
4989 | pStats->rx_fragment_pkt += pTarget->txrxStats.rx_stats.rx_fragment_pkt; | |
4990 | pStats->rx_errors += pTarget->txrxStats.rx_stats.rx_errors; | |
4991 | pStats->rx_crcerr += pTarget->txrxStats.rx_stats.rx_crcerr; | |
4992 | pStats->rx_key_cache_miss += pTarget->txrxStats.rx_stats.rx_key_cache_miss; | |
4993 | pStats->rx_decrypt_err += pTarget->txrxStats.rx_stats.rx_decrypt_err; | |
4994 | pStats->rx_duplicate_frames += pTarget->txrxStats.rx_stats.rx_duplicate_frames; | |
4995 | pStats->rx_unicast_rate = wmi_get_rate(pTarget->txrxStats.rx_stats.rx_unicast_rate); | |
4996 | ||
4997 | ||
4998 | pStats->tkip_local_mic_failure | |
4999 | += pTarget->txrxStats.tkipCcmpStats.tkip_local_mic_failure; | |
5000 | pStats->tkip_counter_measures_invoked | |
5001 | += pTarget->txrxStats.tkipCcmpStats.tkip_counter_measures_invoked; | |
5002 | pStats->tkip_replays += pTarget->txrxStats.tkipCcmpStats.tkip_replays; | |
5003 | pStats->tkip_format_errors += pTarget->txrxStats.tkipCcmpStats.tkip_format_errors; | |
5004 | pStats->ccmp_format_errors += pTarget->txrxStats.tkipCcmpStats.ccmp_format_errors; | |
5005 | pStats->ccmp_replays += pTarget->txrxStats.tkipCcmpStats.ccmp_replays; | |
5006 | ||
5007 | pStats->power_save_failure_cnt += pTarget->pmStats.power_save_failure_cnt; | |
5008 | pStats->noise_floor_calibation = pTarget->noise_floor_calibation; | |
5009 | ||
5010 | pStats->cs_bmiss_cnt += pTarget->cservStats.cs_bmiss_cnt; | |
5011 | pStats->cs_lowRssi_cnt += pTarget->cservStats.cs_lowRssi_cnt; | |
5012 | pStats->cs_connect_cnt += pTarget->cservStats.cs_connect_cnt; | |
5013 | pStats->cs_disconnect_cnt += pTarget->cservStats.cs_disconnect_cnt; | |
5014 | pStats->cs_aveBeacon_snr = pTarget->cservStats.cs_aveBeacon_snr; | |
5015 | pStats->cs_aveBeacon_rssi = pTarget->cservStats.cs_aveBeacon_rssi; | |
5016 | ||
5017 | if (enablerssicompensation) { | |
5018 | pStats->cs_aveBeacon_rssi = | |
5019 | rssi_compensation_calc(ar, pStats->cs_aveBeacon_rssi); | |
5020 | } | |
5021 | pStats->cs_lastRoam_msec = pTarget->cservStats.cs_lastRoam_msec; | |
5022 | pStats->cs_snr = pTarget->cservStats.cs_snr; | |
5023 | pStats->cs_rssi = pTarget->cservStats.cs_rssi; | |
5024 | ||
5025 | pStats->lq_val = pTarget->lqVal; | |
5026 | ||
5027 | pStats->wow_num_pkts_dropped += pTarget->wowStats.wow_num_pkts_dropped; | |
5028 | pStats->wow_num_host_pkt_wakeups += pTarget->wowStats.wow_num_host_pkt_wakeups; | |
5029 | pStats->wow_num_host_event_wakeups += pTarget->wowStats.wow_num_host_event_wakeups; | |
5030 | pStats->wow_num_events_discarded += pTarget->wowStats.wow_num_events_discarded; | |
5031 | pStats->arp_received += pTarget->arpStats.arp_received; | |
5032 | pStats->arp_matched += pTarget->arpStats.arp_matched; | |
5033 | pStats->arp_replied += pTarget->arpStats.arp_replied; | |
5034 | ||
5035 | if (ar->statsUpdatePending) { | |
5036 | ar->statsUpdatePending = FALSE; | |
5037 | wake_up(&arEvent); | |
5038 | } | |
5039 | } | |
5040 | } | |
5041 | ||
5042 | void | |
5043 | ar6000_rssiThreshold_event(AR_SOFTC_T *ar, WMI_RSSI_THRESHOLD_VAL newThreshold, A_INT16 rssi) | |
5044 | { | |
5045 | USER_RSSI_THOLD userRssiThold; | |
5046 | ||
5047 | rssi = rssi + SIGNAL_QUALITY_NOISE_FLOOR; | |
5048 | ||
5049 | if (enablerssicompensation) { | |
5050 | rssi = rssi_compensation_calc(ar, rssi); | |
5051 | } | |
5052 | ||
5053 | /* Send an event to the app */ | |
5054 | userRssiThold.tag = ar->rssi_map[newThreshold].tag; | |
5055 | userRssiThold.rssi = rssi; | |
5056 | A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold, | |
5057 | userRssiThold.tag, userRssiThold.rssi); | |
5058 | ||
5059 | ar6000_send_event_to_app(ar, WMI_RSSI_THRESHOLD_EVENTID,(A_UINT8 *)&userRssiThold, sizeof(USER_RSSI_THOLD)); | |
5060 | } | |
5061 | ||
5062 | ||
5063 | void | |
5064 | ar6000_hbChallengeResp_event(AR_SOFTC_T *ar, A_UINT32 cookie, A_UINT32 source) | |
5065 | { | |
5066 | if (source == APP_HB_CHALLENGE) { | |
5067 | /* Report it to the app in case it wants a positive acknowledgement */ | |
5068 | ar6000_send_event_to_app(ar, WMIX_HB_CHALLENGE_RESP_EVENTID, | |
5069 | (A_UINT8 *)&cookie, sizeof(cookie)); | |
5070 | } else { | |
5071 | /* This would ignore the replys that come in after their due time */ | |
5072 | if (cookie == ar->arHBChallengeResp.seqNum) { | |
5073 | ar->arHBChallengeResp.outstanding = FALSE; | |
5074 | } | |
5075 | } | |
5076 | } | |
5077 | ||
5078 | ||
5079 | void | |
5080 | ar6000_reportError_event(AR_SOFTC_T *ar, WMI_TARGET_ERROR_VAL errorVal) | |
5081 | { | |
5082 | char *errString[] = { | |
5083 | [WMI_TARGET_PM_ERR_FAIL] "WMI_TARGET_PM_ERR_FAIL", | |
5084 | [WMI_TARGET_KEY_NOT_FOUND] "WMI_TARGET_KEY_NOT_FOUND", | |
5085 | [WMI_TARGET_DECRYPTION_ERR] "WMI_TARGET_DECRYPTION_ERR", | |
5086 | [WMI_TARGET_BMISS] "WMI_TARGET_BMISS", | |
5087 | [WMI_PSDISABLE_NODE_JOIN] "WMI_PSDISABLE_NODE_JOIN" | |
5088 | }; | |
5089 | ||
5090 | A_PRINTF("AR6000 Error on Target. Error = 0x%x\n", errorVal); | |
5091 | ||
5092 | /* One error is reported at a time, and errorval is a bitmask */ | |
5093 | if(errorVal & (errorVal - 1)) | |
5094 | return; | |
5095 | ||
5096 | A_PRINTF("AR6000 Error type = "); | |
5097 | switch(errorVal) | |
5098 | { | |
5099 | case WMI_TARGET_PM_ERR_FAIL: | |
5100 | case WMI_TARGET_KEY_NOT_FOUND: | |
5101 | case WMI_TARGET_DECRYPTION_ERR: | |
5102 | case WMI_TARGET_BMISS: | |
5103 | case WMI_PSDISABLE_NODE_JOIN: | |
5104 | A_PRINTF("%s\n", errString[errorVal]); | |
5105 | break; | |
5106 | default: | |
5107 | A_PRINTF("INVALID\n"); | |
5108 | break; | |
5109 | } | |
5110 | ||
5111 | } | |
5112 | ||
5113 | ||
5114 | void | |
5115 | ar6000_cac_event(AR_SOFTC_T *ar, A_UINT8 ac, A_UINT8 cacIndication, | |
5116 | A_UINT8 statusCode, A_UINT8 *tspecSuggestion) | |
5117 | { | |
5118 | WMM_TSPEC_IE *tspecIe; | |
5119 | ||
5120 | /* | |
5121 | * This is the TSPEC IE suggestion from AP. | |
5122 | * Suggestion provided by AP under some error | |
5123 | * cases, could be helpful for the host app. | |
5124 | * Check documentation. | |
5125 | */ | |
5126 | tspecIe = (WMM_TSPEC_IE *)tspecSuggestion; | |
5127 | ||
5128 | /* | |
5129 | * What do we do, if we get TSPEC rejection? One thought | |
5130 | * that comes to mind is implictly delete the pstream... | |
5131 | */ | |
5132 | A_PRINTF("AR6000 CAC notification. " | |
5133 | "AC = %d, cacIndication = 0x%x, statusCode = 0x%x\n", | |
5134 | ac, cacIndication, statusCode); | |
5135 | } | |
5136 | ||
5137 | void | |
5138 | ar6000_channel_change_event(AR_SOFTC_T *ar, A_UINT16 oldChannel, | |
5139 | A_UINT16 newChannel) | |
5140 | { | |
5141 | A_PRINTF("Channel Change notification\nOld Channel: %d, New Channel: %d\n", | |
5142 | oldChannel, newChannel); | |
5143 | } | |
5144 | ||
5145 | #define AR6000_PRINT_BSSID(_pBss) do { \ | |
5146 | A_PRINTF("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ",\ | |
5147 | (_pBss)[0],(_pBss)[1],(_pBss)[2],(_pBss)[3],\ | |
5148 | (_pBss)[4],(_pBss)[5]); \ | |
5149 | } while(0) | |
5150 | ||
5151 | void | |
5152 | ar6000_roam_tbl_event(AR_SOFTC_T *ar, WMI_TARGET_ROAM_TBL *pTbl) | |
5153 | { | |
5154 | A_UINT8 i; | |
5155 | ||
5156 | A_PRINTF("ROAM TABLE NO OF ENTRIES is %d ROAM MODE is %d\n", | |
5157 | pTbl->numEntries, pTbl->roamMode); | |
5158 | for (i= 0; i < pTbl->numEntries; i++) { | |
5159 | A_PRINTF("[%d]bssid %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x ", i, | |
5160 | pTbl->bssRoamInfo[i].bssid[0], pTbl->bssRoamInfo[i].bssid[1], | |
5161 | pTbl->bssRoamInfo[i].bssid[2], | |
5162 | pTbl->bssRoamInfo[i].bssid[3], | |
5163 | pTbl->bssRoamInfo[i].bssid[4], | |
5164 | pTbl->bssRoamInfo[i].bssid[5]); | |
5165 | A_PRINTF("RSSI %d RSSIDT %d LAST RSSI %d UTIL %d ROAM_UTIL %d" | |
5166 | " BIAS %d\n", | |
5167 | pTbl->bssRoamInfo[i].rssi, | |
5168 | pTbl->bssRoamInfo[i].rssidt, | |
5169 | pTbl->bssRoamInfo[i].last_rssi, | |
5170 | pTbl->bssRoamInfo[i].util, | |
5171 | pTbl->bssRoamInfo[i].roam_util, | |
5172 | pTbl->bssRoamInfo[i].bias); | |
5173 | } | |
5174 | } | |
5175 | ||
5176 | void | |
5177 | ar6000_wow_list_event(struct ar6_softc *ar, A_UINT8 num_filters, WMI_GET_WOW_LIST_REPLY *wow_reply) | |
5178 | { | |
5179 | A_UINT8 i,j; | |
5180 | ||
5181 | /*Each event now contains exactly one filter, see bug 26613*/ | |
5182 | A_PRINTF("WOW pattern %d of %d patterns\n", wow_reply->this_filter_num, wow_reply->num_filters); | |
5183 | A_PRINTF("wow mode = %s host mode = %s\n", | |
5184 | (wow_reply->wow_mode == 0? "disabled":"enabled"), | |
5185 | (wow_reply->host_mode == 1 ? "awake":"asleep")); | |
5186 | ||
5187 | ||
5188 | /*If there are no patterns, the reply will only contain generic | |
5189 | WoW information. Pattern information will exist only if there are | |
5190 | patterns present. Bug 26716*/ | |
5191 | ||
5192 | /* If this event contains pattern information, display it*/ | |
5193 | if (wow_reply->this_filter_num) { | |
5194 | i=0; | |
5195 | A_PRINTF("id=%d size=%d offset=%d\n", | |
5196 | wow_reply->wow_filters[i].wow_filter_id, | |
5197 | wow_reply->wow_filters[i].wow_filter_size, | |
5198 | wow_reply->wow_filters[i].wow_filter_offset); | |
5199 | A_PRINTF("wow pattern = "); | |
5200 | for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) { | |
5201 | A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_pattern[j]); | |
5202 | } | |
5203 | ||
5204 | A_PRINTF("\nwow mask = "); | |
5205 | for (j=0; j< wow_reply->wow_filters[i].wow_filter_size; j++) { | |
5206 | A_PRINTF("%2.2x",wow_reply->wow_filters[i].wow_filter_mask[j]); | |
5207 | } | |
5208 | A_PRINTF("\n"); | |
5209 | } | |
5210 | } | |
5211 | ||
5212 | /* | |
5213 | * Report the Roaming related data collected on the target | |
5214 | */ | |
5215 | void | |
5216 | ar6000_display_roam_time(WMI_TARGET_ROAM_TIME *p) | |
5217 | { | |
5218 | A_PRINTF("Disconnect Data : BSSID: "); | |
5219 | AR6000_PRINT_BSSID(p->disassoc_bssid); | |
5220 | A_PRINTF(" RSSI %d DISASSOC Time %d NO_TXRX_TIME %d\n", | |
5221 | p->disassoc_bss_rssi,p->disassoc_time, | |
5222 | p->no_txrx_time); | |
5223 | A_PRINTF("Connect Data: BSSID: "); | |
5224 | AR6000_PRINT_BSSID(p->assoc_bssid); | |
5225 | A_PRINTF(" RSSI %d ASSOC Time %d TXRX_TIME %d\n", | |
5226 | p->assoc_bss_rssi,p->assoc_time, | |
5227 | p->allow_txrx_time); | |
5228 | } | |
5229 | ||
5230 | void | |
5231 | ar6000_roam_data_event(AR_SOFTC_T *ar, WMI_TARGET_ROAM_DATA *p) | |
5232 | { | |
5233 | switch (p->roamDataType) { | |
5234 | case ROAM_DATA_TIME: | |
5235 | ar6000_display_roam_time(&p->u.roamTime); | |
5236 | break; | |
5237 | default: | |
5238 | break; | |
5239 | } | |
5240 | } | |
5241 | ||
5242 | void | |
5243 | ar6000_bssInfo_event_rx(AR_SOFTC_T *ar, A_UINT8 *datap, int len) | |
5244 | { | |
5245 | struct sk_buff *skb; | |
5246 | WMI_BSS_INFO_HDR *bih = (WMI_BSS_INFO_HDR *)datap; | |
5247 | ||
5248 | ||
5249 | if (!ar->arMgmtFilter) { | |
5250 | return; | |
5251 | } | |
5252 | if (((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_BEACON) && | |
5253 | (bih->frameType != BEACON_FTYPE)) || | |
5254 | ((ar->arMgmtFilter & IEEE80211_FILTER_TYPE_PROBE_RESP) && | |
5255 | (bih->frameType != PROBERESP_FTYPE))) | |
5256 | { | |
5257 | return; | |
5258 | } | |
5259 | ||
5260 | if ((skb = A_NETBUF_ALLOC_RAW(len)) != NULL) { | |
5261 | ||
5262 | A_NETBUF_PUT(skb, len); | |
5263 | A_MEMCPY(A_NETBUF_DATA(skb), datap, len); | |
5264 | skb->dev = ar->arNetDev; | |
5265 | A_MEMCPY(skb_mac_header(skb), A_NETBUF_DATA(skb), 6); | |
5266 | skb->ip_summed = CHECKSUM_NONE; | |
5267 | skb->pkt_type = PACKET_OTHERHOST; | |
5268 | skb->protocol = __constant_htons(0x0019); | |
5269 | netif_rx(skb); | |
5270 | } | |
5271 | } | |
5272 | ||
5273 | A_UINT32 wmiSendCmdNum; | |
5274 | ||
5275 | A_STATUS | |
5276 | ar6000_control_tx(void *devt, void *osbuf, HTC_ENDPOINT_ID eid) | |
5277 | { | |
5278 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
5279 | A_STATUS status = A_OK; | |
5280 | struct ar_cookie *cookie = NULL; | |
5281 | int i; | |
5282 | #ifdef CONFIG_PM | |
5283 | if (ar->arWowState != WLAN_WOW_STATE_NONE) { | |
5284 | A_NETBUF_FREE(osbuf); | |
5285 | return A_EACCES; | |
5286 | } | |
5287 | #endif /* CONFIG_PM */ | |
5288 | /* take lock to protect ar6000_alloc_cookie() */ | |
5289 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
5290 | ||
5291 | do { | |
5292 | ||
5293 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("ar_contrstatus = ol_tx: skb=0x%lx, len=0x%x eid =%d\n", | |
5294 | (unsigned long)osbuf, A_NETBUF_LEN(osbuf), eid)); | |
5295 | ||
5296 | if (ar->arWMIControlEpFull && (eid == ar->arControlEp)) { | |
5297 | /* control endpoint is full, don't allocate resources, we | |
5298 | * are just going to drop this packet */ | |
5299 | cookie = NULL; | |
5300 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,(" WMI Control EP full, dropping packet : 0x%lX, len:%d \n", | |
5301 | (unsigned long)osbuf, A_NETBUF_LEN(osbuf))); | |
5302 | } else { | |
5303 | cookie = ar6000_alloc_cookie(ar); | |
5304 | } | |
5305 | ||
5306 | if (cookie == NULL) { | |
5307 | status = A_NO_MEMORY; | |
5308 | break; | |
5309 | } | |
5310 | ||
5311 | if(logWmiRawMsgs) { | |
5312 | A_PRINTF("WMI cmd send, msgNo %d :", wmiSendCmdNum); | |
5313 | for(i = 0; i < a_netbuf_to_len(osbuf); i++) | |
5314 | A_PRINTF("%x ", ((A_UINT8 *)a_netbuf_to_data(osbuf))[i]); | |
5315 | A_PRINTF("\n"); | |
5316 | } | |
5317 | ||
5318 | wmiSendCmdNum++; | |
5319 | ||
5320 | } while (FALSE); | |
5321 | ||
5322 | if (cookie != NULL) { | |
5323 | /* got a structure to send it out on */ | |
5324 | ar->arTxPending[eid]++; | |
5325 | ||
5326 | if (eid != ar->arControlEp) { | |
5327 | ar->arTotalTxDataPending++; | |
5328 | } | |
5329 | } | |
5330 | ||
5331 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
5332 | ||
5333 | if (cookie != NULL) { | |
5334 | cookie->arc_bp[0] = (unsigned long)osbuf; | |
5335 | cookie->arc_bp[1] = 0; | |
5336 | SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, | |
5337 | cookie, | |
5338 | A_NETBUF_DATA(osbuf), | |
5339 | A_NETBUF_LEN(osbuf), | |
5340 | eid, | |
5341 | AR6K_CONTROL_PKT_TAG); | |
5342 | /* this interface is asynchronous, if there is an error, cleanup will happen in the | |
5343 | * TX completion callback */ | |
5344 | HTCSendPkt(ar->arHtcTarget, &cookie->HtcPkt); | |
5345 | status = A_OK; | |
5346 | } | |
5347 | ||
5348 | if (status != A_OK) { | |
5349 | A_NETBUF_FREE(osbuf); | |
5350 | } | |
5351 | return status; | |
5352 | } | |
5353 | ||
5354 | /* indicate tx activity or inactivity on a WMI stream */ | |
5355 | void ar6000_indicate_tx_activity(void *devt, A_UINT8 TrafficClass, A_BOOL Active) | |
5356 | { | |
5357 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
5358 | HTC_ENDPOINT_ID eid ; | |
5359 | int i; | |
5360 | ||
5361 | if (ar->arWmiEnabled) { | |
5362 | eid = arAc2EndpointID(ar, TrafficClass); | |
5363 | ||
5364 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
5365 | ||
5366 | ar->arAcStreamActive[TrafficClass] = Active; | |
5367 | ||
5368 | if (Active) { | |
5369 | /* when a stream goes active, keep track of the active stream with the highest priority */ | |
5370 | ||
5371 | if (ar->arAcStreamPriMap[TrafficClass] > ar->arHiAcStreamActivePri) { | |
5372 | /* set the new highest active priority */ | |
5373 | ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[TrafficClass]; | |
5374 | } | |
5375 | ||
5376 | } else { | |
5377 | /* when a stream goes inactive, we may have to search for the next active stream | |
5378 | * that is the highest priority */ | |
5379 | ||
5380 | if (ar->arHiAcStreamActivePri == ar->arAcStreamPriMap[TrafficClass]) { | |
5381 | ||
5382 | /* the highest priority stream just went inactive */ | |
5383 | ||
5384 | /* reset and search for the "next" highest "active" priority stream */ | |
5385 | ar->arHiAcStreamActivePri = 0; | |
5386 | for (i = 0; i < WMM_NUM_AC; i++) { | |
5387 | if (ar->arAcStreamActive[i]) { | |
5388 | if (ar->arAcStreamPriMap[i] > ar->arHiAcStreamActivePri) { | |
5389 | /* set the new highest active priority */ | |
5390 | ar->arHiAcStreamActivePri = ar->arAcStreamPriMap[i]; | |
5391 | } | |
5392 | } | |
5393 | } | |
5394 | } | |
5395 | } | |
5396 | ||
5397 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
5398 | ||
5399 | } else { | |
5400 | /* for mbox ping testing, the traffic class is mapped directly as a stream ID, | |
5401 | * see handling of AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE in ioctl.c | |
5402 | * convert the stream ID to a endpoint */ | |
5403 | eid = arAc2EndpointID(ar, TrafficClass); | |
5404 | } | |
5405 | ||
5406 | /* notify HTC, this may cause credit distribution changes */ | |
5407 | ||
5408 | HTCIndicateActivityChange(ar->arHtcTarget, | |
5409 | eid, | |
5410 | Active); | |
5411 | ||
5412 | } | |
5413 | ||
5414 | void | |
5415 | ar6000_btcoex_config_event(struct ar6_softc *ar, A_UINT8 *ptr, A_UINT32 len) | |
5416 | { | |
5417 | ||
5418 | WMI_BTCOEX_CONFIG_EVENT *pBtcoexConfig = (WMI_BTCOEX_CONFIG_EVENT *)ptr; | |
5419 | WMI_BTCOEX_CONFIG_EVENT *pArbtcoexConfig =&ar->arBtcoexConfig; | |
5420 | ||
5421 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n")); | |
5422 | ||
5423 | A_PRINTF("received config event\n"); | |
5424 | pArbtcoexConfig->btProfileType = pBtcoexConfig->btProfileType; | |
5425 | pArbtcoexConfig->linkId = pBtcoexConfig->linkId; | |
5426 | ||
5427 | switch (pBtcoexConfig->btProfileType) { | |
5428 | case WMI_BTCOEX_BT_PROFILE_SCO: | |
5429 | A_MEMCPY(&pArbtcoexConfig->info.scoConfigCmd, &pBtcoexConfig->info.scoConfigCmd, | |
5430 | sizeof(WMI_SET_BTCOEX_SCO_CONFIG_CMD)); | |
5431 | break; | |
5432 | case WMI_BTCOEX_BT_PROFILE_A2DP: | |
5433 | A_MEMCPY(&pArbtcoexConfig->info.a2dpConfigCmd, &pBtcoexConfig->info.a2dpConfigCmd, | |
5434 | sizeof(WMI_SET_BTCOEX_A2DP_CONFIG_CMD)); | |
5435 | break; | |
5436 | case WMI_BTCOEX_BT_PROFILE_ACLCOEX: | |
5437 | A_MEMCPY(&pArbtcoexConfig->info.aclcoexConfig, &pBtcoexConfig->info.aclcoexConfig, | |
5438 | sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD)); | |
5439 | break; | |
5440 | case WMI_BTCOEX_BT_PROFILE_INQUIRY_PAGE: | |
5441 | A_MEMCPY(&pArbtcoexConfig->info.btinquiryPageConfigCmd, &pBtcoexConfig->info.btinquiryPageConfigCmd, | |
5442 | sizeof(WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD)); | |
5443 | break; | |
5444 | } | |
5445 | if (ar->statsUpdatePending) { | |
5446 | ar->statsUpdatePending = FALSE; | |
5447 | wake_up(&arEvent); | |
5448 | } | |
5449 | } | |
5450 | ||
5451 | void | |
5452 | ar6000_btcoex_stats_event(struct ar6_softc *ar, A_UINT8 *ptr, A_UINT32 len) | |
5453 | { | |
5454 | WMI_BTCOEX_STATS_EVENT *pBtcoexStats = (WMI_BTCOEX_STATS_EVENT *)ptr; | |
5455 | ||
5456 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("AR6000 BTCOEX CONFIG EVENT \n")); | |
5457 | ||
5458 | A_MEMCPY(&ar->arBtcoexStats, pBtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT)); | |
5459 | ||
5460 | if (ar->statsUpdatePending) { | |
5461 | ar->statsUpdatePending = FALSE; | |
5462 | wake_up(&arEvent); | |
5463 | } | |
5464 | ||
5465 | } | |
5466 | module_init(ar6000_init_module); | |
5467 | module_exit(ar6000_cleanup_module); | |
5468 | ||
5469 | /* Init cookie queue */ | |
5470 | static void | |
5471 | ar6000_cookie_init(AR_SOFTC_T *ar) | |
5472 | { | |
5473 | A_UINT32 i; | |
5474 | ||
5475 | ar->arCookieList = NULL; | |
5476 | ar->arCookieCount = 0; | |
5477 | ||
5478 | A_MEMZERO(s_ar_cookie_mem, sizeof(s_ar_cookie_mem)); | |
5479 | ||
5480 | for (i = 0; i < MAX_COOKIE_NUM; i++) { | |
5481 | ar6000_free_cookie(ar, &s_ar_cookie_mem[i]); | |
5482 | } | |
5483 | } | |
5484 | ||
5485 | /* cleanup cookie queue */ | |
5486 | static void | |
5487 | ar6000_cookie_cleanup(AR_SOFTC_T *ar) | |
5488 | { | |
5489 | /* It is gone .... */ | |
5490 | ar->arCookieList = NULL; | |
5491 | ar->arCookieCount = 0; | |
5492 | } | |
5493 | ||
5494 | /* Init cookie queue */ | |
5495 | static void | |
5496 | ar6000_free_cookie(AR_SOFTC_T *ar, struct ar_cookie * cookie) | |
5497 | { | |
5498 | /* Insert first */ | |
5499 | A_ASSERT(ar != NULL); | |
5500 | A_ASSERT(cookie != NULL); | |
5501 | ||
5502 | cookie->arc_list_next = ar->arCookieList; | |
5503 | ar->arCookieList = cookie; | |
5504 | ar->arCookieCount++; | |
5505 | } | |
5506 | ||
5507 | /* cleanup cookie queue */ | |
5508 | static struct ar_cookie * | |
5509 | ar6000_alloc_cookie(AR_SOFTC_T *ar) | |
5510 | { | |
5511 | struct ar_cookie *cookie; | |
5512 | ||
5513 | cookie = ar->arCookieList; | |
5514 | if(cookie != NULL) | |
5515 | { | |
5516 | ar->arCookieList = cookie->arc_list_next; | |
5517 | ar->arCookieCount--; | |
5518 | } | |
5519 | ||
5520 | return cookie; | |
5521 | } | |
5522 | ||
5523 | #ifdef SEND_EVENT_TO_APP | |
5524 | /* | |
5525 | * This function is used to send event which come from taget to | |
5526 | * the application. The buf which send to application is include | |
5527 | * the event ID and event content. | |
5528 | */ | |
5529 | #define EVENT_ID_LEN 2 | |
5530 | void ar6000_send_event_to_app(AR_SOFTC_T *ar, A_UINT16 eventId, | |
5531 | A_UINT8 *datap, int len) | |
5532 | { | |
5533 | ||
5534 | #if (WIRELESS_EXT >= 15) | |
5535 | ||
5536 | /* note: IWEVCUSTOM only exists in wireless extensions after version 15 */ | |
5537 | ||
5538 | char *buf; | |
5539 | A_UINT16 size; | |
5540 | union iwreq_data wrqu; | |
5541 | ||
5542 | size = len + EVENT_ID_LEN; | |
5543 | ||
5544 | if (size > IW_CUSTOM_MAX) { | |
5545 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVCUSTOM (max=%d) \n", | |
5546 | eventId, size, IW_CUSTOM_MAX)); | |
5547 | return; | |
5548 | } | |
5549 | ||
5550 | buf = A_MALLOC_NOWAIT(size); | |
5551 | if (NULL == buf){ | |
5552 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); | |
5553 | return; | |
5554 | } | |
5555 | ||
5556 | A_MEMZERO(buf, size); | |
5557 | A_MEMCPY(buf, &eventId, EVENT_ID_LEN); | |
5558 | A_MEMCPY(buf+EVENT_ID_LEN, datap, len); | |
5559 | ||
5560 | //AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("event ID = %d,len = %d\n",*(A_UINT16*)buf, size)); | |
5561 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
5562 | wrqu.data.length = size; | |
5563 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
5564 | A_FREE(buf); | |
5565 | #endif | |
5566 | ||
5567 | ||
5568 | } | |
5569 | ||
5570 | /* | |
5571 | * This function is used to send events larger than 256 bytes | |
5572 | * to the application. The buf which is sent to application | |
5573 | * includes the event ID and event content. | |
5574 | */ | |
5575 | void ar6000_send_generic_event_to_app(AR_SOFTC_T *ar, A_UINT16 eventId, | |
5576 | A_UINT8 *datap, int len) | |
5577 | { | |
5578 | ||
5579 | #if (WIRELESS_EXT >= 18) | |
5580 | ||
5581 | /* IWEVGENIE exists in wireless extensions version 18 onwards */ | |
5582 | ||
5583 | char *buf; | |
5584 | A_UINT16 size; | |
5585 | union iwreq_data wrqu; | |
5586 | ||
5587 | size = len + EVENT_ID_LEN; | |
5588 | ||
5589 | if (size > IW_GENERIC_IE_MAX) { | |
5590 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVGENIE (max=%d) \n", | |
5591 | eventId, size, IW_GENERIC_IE_MAX)); | |
5592 | return; | |
5593 | } | |
5594 | ||
5595 | buf = A_MALLOC_NOWAIT(size); | |
5596 | if (NULL == buf){ | |
5597 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); | |
5598 | return; | |
5599 | } | |
5600 | ||
5601 | A_MEMZERO(buf, size); | |
5602 | A_MEMCPY(buf, &eventId, EVENT_ID_LEN); | |
5603 | A_MEMCPY(buf+EVENT_ID_LEN, datap, len); | |
5604 | ||
5605 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
5606 | wrqu.data.length = size; | |
5607 | wireless_send_event(ar->arNetDev, IWEVGENIE, &wrqu, buf); | |
5608 | ||
5609 | A_FREE(buf); | |
5610 | ||
5611 | #endif /* (WIRELESS_EXT >= 18) */ | |
5612 | ||
5613 | } | |
5614 | #endif /* SEND_EVENT_TO_APP */ | |
5615 | ||
5616 | ||
5617 | void | |
5618 | ar6000_tx_retry_err_event(void *devt) | |
5619 | { | |
5620 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Tx retries reach maximum!\n")); | |
5621 | } | |
5622 | ||
5623 | void | |
5624 | ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, A_UINT8 snr) | |
5625 | { | |
5626 | WMI_SNR_THRESHOLD_EVENT event; | |
5627 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
5628 | ||
5629 | event.range = newThreshold; | |
5630 | event.snr = snr; | |
5631 | ||
5632 | ar6000_send_event_to_app(ar, WMI_SNR_THRESHOLD_EVENTID, (A_UINT8 *)&event, | |
5633 | sizeof(WMI_SNR_THRESHOLD_EVENT)); | |
5634 | } | |
5635 | ||
5636 | void | |
5637 | ar6000_lqThresholdEvent_rx(void *devt, WMI_LQ_THRESHOLD_VAL newThreshold, A_UINT8 lq) | |
5638 | { | |
5639 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("lq threshold range %d, lq %d\n", newThreshold, lq)); | |
5640 | } | |
5641 | ||
5642 | ||
5643 | ||
5644 | A_UINT32 | |
5645 | a_copy_to_user(void *to, const void *from, A_UINT32 n) | |
5646 | { | |
5647 | return(copy_to_user(to, from, n)); | |
5648 | } | |
5649 | ||
5650 | A_UINT32 | |
5651 | a_copy_from_user(void *to, const void *from, A_UINT32 n) | |
5652 | { | |
5653 | return(copy_from_user(to, from, n)); | |
5654 | } | |
5655 | ||
5656 | ||
5657 | A_STATUS | |
5658 | ar6000_get_driver_cfg(struct net_device *dev, | |
5659 | A_UINT16 cfgParam, | |
5660 | void *result) | |
5661 | { | |
5662 | ||
5663 | A_STATUS ret = 0; | |
5664 | ||
5665 | switch(cfgParam) | |
5666 | { | |
5667 | case AR6000_DRIVER_CFG_GET_WLANNODECACHING: | |
5668 | *((A_UINT32 *)result) = wlanNodeCaching; | |
5669 | break; | |
5670 | case AR6000_DRIVER_CFG_LOG_RAW_WMI_MSGS: | |
5671 | *((A_UINT32 *)result) = logWmiRawMsgs; | |
5672 | break; | |
5673 | default: | |
5674 | ret = EINVAL; | |
5675 | break; | |
5676 | } | |
5677 | ||
5678 | return ret; | |
5679 | } | |
5680 | ||
5681 | void | |
5682 | ar6000_keepalive_rx(void *devt, A_UINT8 configured) | |
5683 | { | |
5684 | AR_SOFTC_T *ar = (AR_SOFTC_T *)devt; | |
5685 | ||
5686 | ar->arKeepaliveConfigured = configured; | |
5687 | wake_up(&arEvent); | |
5688 | } | |
5689 | ||
5690 | void | |
5691 | ar6000_pmkid_list_event(void *devt, A_UINT8 numPMKID, WMI_PMKID *pmkidList, | |
5692 | A_UINT8 *bssidList) | |
5693 | { | |
5694 | A_UINT8 i, j; | |
5695 | ||
5696 | A_PRINTF("Number of Cached PMKIDs is %d\n", numPMKID); | |
5697 | ||
5698 | for (i = 0; i < numPMKID; i++) { | |
5699 | A_PRINTF("\nBSSID %d ", i); | |
5700 | for (j = 0; j < ATH_MAC_LEN; j++) { | |
5701 | A_PRINTF("%2.2x", bssidList[j]); | |
5702 | } | |
5703 | bssidList += (ATH_MAC_LEN + WMI_PMKID_LEN); | |
5704 | A_PRINTF("\nPMKID %d ", i); | |
5705 | for (j = 0; j < WMI_PMKID_LEN; j++) { | |
5706 | A_PRINTF("%2.2x", pmkidList->pmkid[j]); | |
5707 | } | |
5708 | pmkidList = (WMI_PMKID *)((A_UINT8 *)pmkidList + ATH_MAC_LEN + | |
5709 | WMI_PMKID_LEN); | |
5710 | } | |
5711 | } | |
5712 | ||
5713 | void ar6000_pspoll_event(AR_SOFTC_T *ar,A_UINT8 aid) | |
5714 | { | |
5715 | sta_t *conn=NULL; | |
5716 | A_BOOL isPsqEmpty = FALSE; | |
5717 | ||
5718 | conn = ieee80211_find_conn_for_aid(ar, aid); | |
5719 | ||
5720 | /* If the PS q for this STA is not empty, dequeue and send a pkt from | |
5721 | * the head of the q. Also update the More data bit in the WMI_DATA_HDR | |
5722 | * if there are more pkts for this STA in the PS q. If there are no more | |
5723 | * pkts for this STA, update the PVB for this STA. | |
5724 | */ | |
5725 | A_MUTEX_LOCK(&conn->psqLock); | |
5726 | isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); | |
5727 | A_MUTEX_UNLOCK(&conn->psqLock); | |
5728 | ||
5729 | if (isPsqEmpty) { | |
5730 | /* TODO:No buffered pkts for this STA. Send out a NULL data frame */ | |
5731 | } else { | |
5732 | struct sk_buff *skb = NULL; | |
5733 | ||
5734 | A_MUTEX_LOCK(&conn->psqLock); | |
5735 | skb = A_NETBUF_DEQUEUE(&conn->psq); | |
5736 | A_MUTEX_UNLOCK(&conn->psqLock); | |
5737 | /* Set the STA flag to PSPolled, so that the frame will go out */ | |
5738 | STA_SET_PS_POLLED(conn); | |
5739 | ar6000_data_tx(skb, ar->arNetDev); | |
5740 | STA_CLR_PS_POLLED(conn); | |
5741 | ||
5742 | /* Clear the PVB for this STA if the queue has become empty */ | |
5743 | A_MUTEX_LOCK(&conn->psqLock); | |
5744 | isPsqEmpty = A_NETBUF_QUEUE_EMPTY(&conn->psq); | |
5745 | A_MUTEX_UNLOCK(&conn->psqLock); | |
5746 | ||
5747 | if (isPsqEmpty) { | |
5748 | wmi_set_pvb_cmd(ar->arWmi, conn->aid, 0); | |
5749 | } | |
5750 | } | |
5751 | } | |
5752 | ||
5753 | void ar6000_dtimexpiry_event(AR_SOFTC_T *ar) | |
5754 | { | |
5755 | A_BOOL isMcastQueued = FALSE; | |
5756 | struct sk_buff *skb = NULL; | |
5757 | ||
5758 | /* If there are no associated STAs, ignore the DTIM expiry event. | |
5759 | * There can be potential race conditions where the last associated | |
5760 | * STA may disconnect & before the host could clear the 'Indicate DTIM' | |
5761 | * request to the firmware, the firmware would have just indicated a DTIM | |
5762 | * expiry event. The race is between 'clear DTIM expiry cmd' going | |
5763 | * from the host to the firmware & the DTIM expiry event happening from | |
5764 | * the firmware to the host. | |
5765 | */ | |
5766 | if (ar->sta_list_index == 0) { | |
5767 | return; | |
5768 | } | |
5769 | ||
5770 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
5771 | isMcastQueued = A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq); | |
5772 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
5773 | ||
5774 | A_ASSERT(isMcastQueued == FALSE); | |
5775 | ||
5776 | /* Flush the mcast psq to the target */ | |
5777 | /* Set the STA flag to DTIMExpired, so that the frame will go out */ | |
5778 | ar->DTIMExpired = TRUE; | |
5779 | ||
5780 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
5781 | while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) { | |
5782 | skb = A_NETBUF_DEQUEUE(&ar->mcastpsq); | |
5783 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
5784 | ||
5785 | ar6000_data_tx(skb, ar->arNetDev); | |
5786 | ||
5787 | A_MUTEX_LOCK(&ar->mcastpsqLock); | |
5788 | } | |
5789 | A_MUTEX_UNLOCK(&ar->mcastpsqLock); | |
5790 | ||
5791 | /* Reset the DTIMExpired flag back to 0 */ | |
5792 | ar->DTIMExpired = FALSE; | |
5793 | ||
5794 | /* Clear the LSB of the BitMapCtl field of the TIM IE */ | |
5795 | wmi_set_pvb_cmd(ar->arWmi, MCAST_AID, 0); | |
5796 | } | |
5797 | ||
5798 | void | |
5799 | read_rssi_compensation_param(AR_SOFTC_T *ar) | |
5800 | { | |
5801 | A_UINT8 *cust_data_ptr; | |
5802 | ||
5803 | //#define RSSICOMPENSATION_PRINT | |
5804 | ||
5805 | #ifdef RSSICOMPENSATION_PRINT | |
5806 | A_INT16 i; | |
5807 | cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType); | |
5808 | for (i=0; i<16; i++) { | |
5809 | A_PRINTF("cust_data_%d = %x \n", i, *(A_UINT8 *)cust_data_ptr); | |
5810 | cust_data_ptr += 1; | |
5811 | } | |
5812 | #endif | |
5813 | ||
5814 | cust_data_ptr = ar6000_get_cust_data_buffer(ar->arTargetType); | |
5815 | ||
5816 | rssi_compensation_param.customerID = *(A_UINT16 *)cust_data_ptr & 0xffff; | |
5817 | rssi_compensation_param.enable = *(A_UINT16 *)(cust_data_ptr+2) & 0xffff; | |
5818 | rssi_compensation_param.bg_param_a = *(A_UINT16 *)(cust_data_ptr+4) & 0xffff; | |
5819 | rssi_compensation_param.bg_param_b = *(A_UINT16 *)(cust_data_ptr+6) & 0xffff; | |
5820 | rssi_compensation_param.a_param_a = *(A_UINT16 *)(cust_data_ptr+8) & 0xffff; | |
5821 | rssi_compensation_param.a_param_b = *(A_UINT16 *)(cust_data_ptr+10) &0xffff; | |
5822 | rssi_compensation_param.reserved = *(A_UINT32 *)(cust_data_ptr+12); | |
5823 | ||
5824 | #ifdef RSSICOMPENSATION_PRINT | |
5825 | A_PRINTF("customerID = 0x%x \n", rssi_compensation_param.customerID); | |
5826 | A_PRINTF("enable = 0x%x \n", rssi_compensation_param.enable); | |
5827 | A_PRINTF("bg_param_a = 0x%x and %d \n", rssi_compensation_param.bg_param_a, rssi_compensation_param.bg_param_a); | |
5828 | A_PRINTF("bg_param_b = 0x%x and %d \n", rssi_compensation_param.bg_param_b, rssi_compensation_param.bg_param_b); | |
5829 | A_PRINTF("a_param_a = 0x%x and %d \n", rssi_compensation_param.a_param_a, rssi_compensation_param.a_param_a); | |
5830 | A_PRINTF("a_param_b = 0x%x and %d \n", rssi_compensation_param.a_param_b, rssi_compensation_param.a_param_b); | |
5831 | A_PRINTF("Last 4 bytes = 0x%x \n", rssi_compensation_param.reserved); | |
5832 | #endif | |
5833 | ||
5834 | if (rssi_compensation_param.enable != 0x1) { | |
5835 | rssi_compensation_param.enable = 0; | |
5836 | } | |
5837 | ||
5838 | return; | |
5839 | } | |
5840 | ||
5841 | A_INT32 | |
5842 | rssi_compensation_calc_tcmd(A_UINT32 freq, A_INT32 rssi, A_UINT32 totalPkt) | |
5843 | { | |
5844 | ||
5845 | if (freq > 5000) | |
5846 | { | |
5847 | if (rssi_compensation_param.enable) | |
5848 | { | |
5849 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); | |
5850 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt)); | |
5851 | rssi = rssi * rssi_compensation_param.a_param_a + totalPkt * rssi_compensation_param.a_param_b; | |
5852 | rssi = (rssi-50) /100; | |
5853 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); | |
5854 | } | |
5855 | } | |
5856 | else | |
5857 | { | |
5858 | if (rssi_compensation_param.enable) | |
5859 | { | |
5860 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); | |
5861 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d, totalPkt = %d\n", rssi,totalPkt)); | |
5862 | rssi = rssi * rssi_compensation_param.bg_param_a + totalPkt * rssi_compensation_param.bg_param_b; | |
5863 | rssi = (rssi-50) /100; | |
5864 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); | |
5865 | } | |
5866 | } | |
5867 | ||
5868 | return rssi; | |
5869 | } | |
5870 | ||
5871 | A_INT16 | |
5872 | rssi_compensation_calc(AR_SOFTC_T *ar, A_INT16 rssi) | |
5873 | { | |
5874 | if (ar->arBssChannel > 5000) | |
5875 | { | |
5876 | if (rssi_compensation_param.enable) | |
5877 | { | |
5878 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); | |
5879 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi)); | |
5880 | rssi = rssi * rssi_compensation_param.a_param_a + rssi_compensation_param.a_param_b; | |
5881 | rssi = (rssi-50) /100; | |
5882 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); | |
5883 | } | |
5884 | } | |
5885 | else | |
5886 | { | |
5887 | if (rssi_compensation_param.enable) | |
5888 | { | |
5889 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); | |
5890 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before compensation = %d\n", rssi)); | |
5891 | rssi = rssi * rssi_compensation_param.bg_param_a + rssi_compensation_param.bg_param_b; | |
5892 | rssi = (rssi-50) /100; | |
5893 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after compensation = %d\n", rssi)); | |
5894 | } | |
5895 | } | |
5896 | ||
5897 | return rssi; | |
5898 | } | |
5899 | ||
5900 | A_INT16 | |
5901 | rssi_compensation_reverse_calc(AR_SOFTC_T *ar, A_INT16 rssi, A_BOOL Above) | |
5902 | { | |
5903 | A_INT16 i; | |
5904 | ||
5905 | if (ar->arBssChannel > 5000) | |
5906 | { | |
5907 | if (rssi_compensation_param.enable) | |
5908 | { | |
5909 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11a\n")); | |
5910 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi)); | |
5911 | rssi = rssi * 100; | |
5912 | rssi = (rssi - rssi_compensation_param.a_param_b) / rssi_compensation_param.a_param_a; | |
5913 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi)); | |
5914 | } | |
5915 | } | |
5916 | else | |
5917 | { | |
5918 | if (rssi_compensation_param.enable) | |
5919 | { | |
5920 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, (">>> 11bg\n")); | |
5921 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi before rev compensation = %d\n", rssi)); | |
5922 | ||
5923 | if (Above) { | |
5924 | for (i=95; i>=0; i--) { | |
5925 | if (rssi <= rssi_compensation_table[i]) { | |
5926 | rssi = 0 - i; | |
5927 | break; | |
5928 | } | |
5929 | } | |
5930 | } else { | |
5931 | for (i=0; i<=95; i++) { | |
5932 | if (rssi >= rssi_compensation_table[i]) { | |
5933 | rssi = 0 - i; | |
5934 | break; | |
5935 | } | |
5936 | } | |
5937 | } | |
5938 | AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("rssi after rev compensation = %d\n", rssi)); | |
5939 | } | |
5940 | } | |
5941 | ||
5942 | return rssi; | |
5943 | } | |
5944 | ||
5945 | #ifdef WAPI_ENABLE | |
5946 | void ap_wapi_rekey_event(AR_SOFTC_T *ar, A_UINT8 type, A_UINT8 *mac) | |
5947 | { | |
5948 | union iwreq_data wrqu; | |
5949 | A_CHAR buf[20]; | |
5950 | ||
5951 | A_MEMZERO(buf, sizeof(buf)); | |
5952 | ||
5953 | strcpy(buf, "WAPI_REKEY"); | |
5954 | buf[10] = type; | |
5955 | A_MEMCPY(&buf[11], mac, ATH_MAC_LEN); | |
5956 | ||
5957 | A_MEMZERO(&wrqu, sizeof(wrqu)); | |
5958 | wrqu.data.length = 10+1+ATH_MAC_LEN; | |
5959 | wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); | |
5960 | ||
5961 | A_PRINTF("WAPI REKEY - %d - %02x:%02x\n", type, mac[4], mac[5]); | |
5962 | } | |
5963 | #endif | |
5964 | ||
5965 | #ifdef USER_KEYS | |
5966 | static A_STATUS | |
5967 | ||
5968 | ar6000_reinstall_keys(AR_SOFTC_T *ar, A_UINT8 key_op_ctrl) | |
5969 | { | |
5970 | A_STATUS status = A_OK; | |
5971 | struct ieee80211req_key *uik = &ar->user_saved_keys.ucast_ik; | |
5972 | struct ieee80211req_key *bik = &ar->user_saved_keys.bcast_ik; | |
5973 | CRYPTO_TYPE keyType = ar->user_saved_keys.keyType; | |
5974 | ||
5975 | if (IEEE80211_CIPHER_CCKM_KRK != uik->ik_type) { | |
5976 | if (NONE_CRYPT == keyType) { | |
5977 | goto _reinstall_keys_out; | |
5978 | } | |
5979 | ||
5980 | if (uik->ik_keylen) { | |
5981 | status = wmi_addKey_cmd(ar->arWmi, uik->ik_keyix, | |
5982 | ar->user_saved_keys.keyType, PAIRWISE_USAGE, | |
5983 | uik->ik_keylen, (A_UINT8 *)&uik->ik_keyrsc, | |
5984 | uik->ik_keydata, key_op_ctrl, uik->ik_macaddr, SYNC_BEFORE_WMIFLAG); | |
5985 | } | |
5986 | ||
5987 | } else { | |
5988 | status = wmi_add_krk_cmd(ar->arWmi, uik->ik_keydata); | |
5989 | } | |
5990 | ||
5991 | if (IEEE80211_CIPHER_CCKM_KRK != bik->ik_type) { | |
5992 | if (NONE_CRYPT == keyType) { | |
5993 | goto _reinstall_keys_out; | |
5994 | } | |
5995 | ||
5996 | if (bik->ik_keylen) { | |
5997 | status = wmi_addKey_cmd(ar->arWmi, bik->ik_keyix, | |
5998 | ar->user_saved_keys.keyType, GROUP_USAGE, | |
5999 | bik->ik_keylen, (A_UINT8 *)&bik->ik_keyrsc, | |
6000 | bik->ik_keydata, key_op_ctrl, bik->ik_macaddr, NO_SYNC_WMIFLAG); | |
6001 | } | |
6002 | } else { | |
6003 | status = wmi_add_krk_cmd(ar->arWmi, bik->ik_keydata); | |
6004 | } | |
6005 | ||
6006 | _reinstall_keys_out: | |
6007 | ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; | |
6008 | ar->user_key_ctrl = 0; | |
6009 | ||
6010 | return status; | |
6011 | } | |
6012 | #endif /* USER_KEYS */ | |
6013 | ||
6014 | ||
6015 | void | |
6016 | ar6000_dset_open_req( | |
6017 | void *context, | |
6018 | A_UINT32 id, | |
6019 | A_UINT32 targHandle, | |
6020 | A_UINT32 targReplyFn, | |
6021 | A_UINT32 targReplyArg) | |
6022 | { | |
6023 | } | |
6024 | ||
6025 | void | |
6026 | ar6000_dset_close( | |
6027 | void *context, | |
6028 | A_UINT32 access_cookie) | |
6029 | { | |
6030 | return; | |
6031 | } | |
6032 | ||
6033 | void | |
6034 | ar6000_dset_data_req( | |
6035 | void *context, | |
6036 | A_UINT32 accessCookie, | |
6037 | A_UINT32 offset, | |
6038 | A_UINT32 length, | |
6039 | A_UINT32 targBuf, | |
6040 | A_UINT32 targReplyFn, | |
6041 | A_UINT32 targReplyArg) | |
6042 | { | |
6043 | } | |
6044 | ||
6045 | int | |
6046 | ar6000_ap_mode_profile_commit(struct ar6_softc *ar) | |
6047 | { | |
6048 | WMI_CONNECT_CMD p; | |
6049 | unsigned long flags; | |
6050 | ||
6051 | /* No change in AP's profile configuration */ | |
6052 | if(ar->ap_profile_flag==0) { | |
6053 | A_PRINTF("COMMIT: No change in profile!!!\n"); | |
6054 | return -ENODATA; | |
6055 | } | |
6056 | ||
6057 | if(!ar->arSsidLen) { | |
6058 | A_PRINTF("SSID not set!!!\n"); | |
6059 | return -ECHRNG; | |
6060 | } | |
6061 | ||
6062 | switch(ar->arAuthMode) { | |
6063 | case NONE_AUTH: | |
6064 | if((ar->arPairwiseCrypto != NONE_CRYPT) && | |
6065 | #ifdef WAPI_ENABLE | |
6066 | (ar->arPairwiseCrypto != WAPI_CRYPT) && | |
6067 | #endif | |
6068 | (ar->arPairwiseCrypto != WEP_CRYPT)) { | |
6069 | A_PRINTF("Cipher not supported in AP mode Open auth\n"); | |
6070 | return -EOPNOTSUPP; | |
6071 | } | |
6072 | break; | |
6073 | case WPA_PSK_AUTH: | |
6074 | case WPA2_PSK_AUTH: | |
6075 | case (WPA_PSK_AUTH|WPA2_PSK_AUTH): | |
6076 | break; | |
6077 | default: | |
6078 | A_PRINTF("This key mgmt type not supported in AP mode\n"); | |
6079 | return -EOPNOTSUPP; | |
6080 | } | |
6081 | ||
6082 | /* Update the arNetworkType */ | |
6083 | ar->arNetworkType = ar->arNextMode; | |
6084 | ||
6085 | A_MEMZERO(&p,sizeof(p)); | |
6086 | p.ssidLength = ar->arSsidLen; | |
6087 | A_MEMCPY(p.ssid,ar->arSsid,p.ssidLength); | |
6088 | p.channel = ar->arChannelHint; | |
6089 | p.networkType = ar->arNetworkType; | |
6090 | ||
6091 | p.dot11AuthMode = ar->arDot11AuthMode; | |
6092 | p.authMode = ar->arAuthMode; | |
6093 | p.pairwiseCryptoType = ar->arPairwiseCrypto; | |
6094 | p.pairwiseCryptoLen = ar->arPairwiseCryptoLen; | |
6095 | p.groupCryptoType = ar->arGroupCrypto; | |
6096 | p.groupCryptoLen = ar->arGroupCryptoLen; | |
6097 | p.ctrl_flags = ar->arConnectCtrlFlags; | |
6098 | ||
6099 | ar->arConnected = FALSE; | |
6100 | ||
6101 | wmi_ap_profile_commit(ar->arWmi, &p); | |
6102 | spin_lock_irqsave(&ar->arLock, flags); | |
6103 | ar->arConnected = TRUE; | |
6104 | netif_carrier_on(ar->arNetDev); | |
6105 | spin_unlock_irqrestore(&ar->arLock, flags); | |
6106 | ar->ap_profile_flag = 0; | |
6107 | return 0; | |
6108 | } | |
6109 | ||
6110 | A_STATUS | |
6111 | ar6000_connect_to_ap(struct ar6_softc *ar) | |
6112 | { | |
6113 | /* The ssid length check prevents second "essid off" from the user, | |
6114 | to be treated as a connect cmd. The second "essid off" is ignored. | |
6115 | */ | |
6116 | if((ar->arWmiReady == TRUE) && (ar->arSsidLen > 0) && ar->arNetworkType!=AP_NETWORK) | |
6117 | { | |
6118 | A_STATUS status; | |
6119 | if((ADHOC_NETWORK != ar->arNetworkType) && | |
6120 | (NONE_AUTH==ar->arAuthMode) && | |
6121 | (WEP_CRYPT==ar->arPairwiseCrypto)) { | |
6122 | ar6000_install_static_wep_keys(ar); | |
6123 | } | |
6124 | ||
6125 | if (!ar->arUserBssFilter) { | |
6126 | if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != A_OK) { | |
6127 | return -EIO; | |
6128 | } | |
6129 | } | |
6130 | #ifdef WAPI_ENABLE | |
6131 | if (ar->arWapiEnable) { | |
6132 | ar->arPairwiseCrypto = WAPI_CRYPT; | |
6133 | ar->arPairwiseCryptoLen = 0; | |
6134 | ar->arGroupCrypto = WAPI_CRYPT; | |
6135 | ar->arGroupCryptoLen = 0; | |
6136 | ar->arAuthMode = NONE_AUTH; | |
6137 | ar->arConnectCtrlFlags |= CONNECT_IGNORE_WPAx_GROUP_CIPHER; | |
6138 | } | |
6139 | #endif | |
6140 | AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Connect called with authmode %d dot11 auth %d"\ | |
6141 | " PW crypto %d PW crypto Len %d GRP crypto %d"\ | |
6142 | " GRP crypto Len %d\n", | |
6143 | ar->arAuthMode, ar->arDot11AuthMode, | |
6144 | ar->arPairwiseCrypto, ar->arPairwiseCryptoLen, | |
6145 | ar->arGroupCrypto, ar->arGroupCryptoLen)); | |
6146 | reconnect_flag = 0; | |
6147 | /* Set the listen interval into 1000TUs or more. This value will be indicated to Ap in the conn. | |
6148 | later set it back locally at the STA to 100/1000 TUs depending on the power mode */ | |
6149 | if ((ar->arNetworkType == INFRA_NETWORK)) { | |
6150 | wmi_listeninterval_cmd(ar->arWmi, max(ar->arListenIntervalT, (A_UINT16)A_MAX_WOW_LISTEN_INTERVAL), 0); | |
6151 | } | |
6152 | status = wmi_connect_cmd(ar->arWmi, ar->arNetworkType, | |
6153 | ar->arDot11AuthMode, ar->arAuthMode, | |
6154 | ar->arPairwiseCrypto, ar->arPairwiseCryptoLen, | |
6155 | ar->arGroupCrypto,ar->arGroupCryptoLen, | |
6156 | ar->arSsidLen, ar->arSsid, | |
6157 | ar->arReqBssid, ar->arChannelHint, | |
6158 | ar->arConnectCtrlFlags); | |
6159 | if (status != A_OK) { | |
6160 | wmi_listeninterval_cmd(ar->arWmi, ar->arListenIntervalT, ar->arListenIntervalB); | |
6161 | if (!ar->arUserBssFilter) { | |
6162 | wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0); | |
6163 | } | |
6164 | return status; | |
6165 | } | |
6166 | ||
6167 | if ((!(ar->arConnectCtrlFlags & CONNECT_DO_WPA_OFFLOAD)) && | |
6168 | ((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode))) | |
6169 | { | |
6170 | A_TIMEOUT_MS(&ar->disconnect_timer, A_DISCONNECT_TIMER_INTERVAL, 0); | |
6171 | } | |
6172 | ||
6173 | ar->arConnectCtrlFlags &= ~CONNECT_DO_WPA_OFFLOAD; | |
6174 | ||
6175 | ar->arConnectPending = TRUE; | |
6176 | return status; | |
6177 | } | |
6178 | return A_ERROR; | |
6179 | } | |
6180 | ||
6181 | A_STATUS | |
6182 | ar6000_ap_mode_get_wpa_ie(struct ar6_softc *ar, struct ieee80211req_wpaie *wpaie) | |
6183 | { | |
6184 | sta_t *conn = NULL; | |
6185 | conn = ieee80211_find_conn(ar, wpaie->wpa_macaddr); | |
6186 | ||
6187 | A_MEMZERO(wpaie->wpa_ie, IEEE80211_MAX_IE); | |
6188 | A_MEMZERO(wpaie->rsn_ie, IEEE80211_MAX_IE); | |
6189 | ||
6190 | if(conn) { | |
6191 | A_MEMCPY(wpaie->wpa_ie, conn->wpa_ie, IEEE80211_MAX_IE); | |
6192 | } | |
6193 | ||
6194 | return 0; | |
6195 | } | |
6196 | ||
6197 | A_STATUS | |
6198 | is_iwioctl_allowed(A_UINT8 mode, A_UINT16 cmd) | |
6199 | { | |
6200 | if(cmd >= SIOCSIWCOMMIT && cmd <= SIOCGIWPOWER) { | |
6201 | cmd -= SIOCSIWCOMMIT; | |
6202 | if(sioctl_filter[cmd] == 0xFF) return A_OK; | |
6203 | if(sioctl_filter[cmd] & mode) return A_OK; | |
6204 | } else if(cmd >= SIOCIWFIRSTPRIV && cmd <= (SIOCIWFIRSTPRIV+30)) { | |
6205 | cmd -= SIOCIWFIRSTPRIV; | |
6206 | if(pioctl_filter[cmd] == 0xFF) return A_OK; | |
6207 | if(pioctl_filter[cmd] & mode) return A_OK; | |
6208 | } else { | |
6209 | return A_ERROR; | |
6210 | } | |
6211 | return A_ENOTSUP; | |
6212 | } | |
6213 | ||
6214 | A_STATUS | |
6215 | is_xioctl_allowed(A_UINT8 mode, int cmd) | |
6216 | { | |
6217 | if(sizeof(xioctl_filter)-1 < cmd) { | |
6218 | A_PRINTF("Filter for this cmd=%d not defined\n",cmd); | |
6219 | return 0; | |
6220 | } | |
6221 | if(xioctl_filter[cmd] == 0xFF) return A_OK; | |
6222 | if(xioctl_filter[cmd] & mode) return A_OK; | |
6223 | return A_ERROR; | |
6224 | } | |
6225 | ||
6226 | #ifdef WAPI_ENABLE | |
6227 | int | |
6228 | ap_set_wapi_key(struct ar6_softc *ar, void *ikey) | |
6229 | { | |
6230 | struct ieee80211req_key *ik = (struct ieee80211req_key *)ikey; | |
6231 | KEY_USAGE keyUsage = 0; | |
6232 | A_STATUS status; | |
6233 | ||
6234 | if (A_MEMCMP(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN) == 0) { | |
6235 | keyUsage = GROUP_USAGE; | |
6236 | } else { | |
6237 | keyUsage = PAIRWISE_USAGE; | |
6238 | } | |
6239 | A_PRINTF("WAPI_KEY: Type:%d ix:%d mac:%02x:%02x len:%d\n", | |
6240 | keyUsage, ik->ik_keyix, ik->ik_macaddr[4], ik->ik_macaddr[5], | |
6241 | ik->ik_keylen); | |
6242 | ||
6243 | status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, WAPI_CRYPT, keyUsage, | |
6244 | ik->ik_keylen, (A_UINT8 *)&ik->ik_keyrsc, | |
6245 | ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, | |
6246 | SYNC_BOTH_WMIFLAG); | |
6247 | ||
6248 | if (A_OK != status) { | |
6249 | return -EIO; | |
6250 | } | |
6251 | return 0; | |
6252 | } | |
6253 | #endif | |
6254 | ||
6255 | void ar6000_peer_event( | |
6256 | void *context, | |
6257 | A_UINT8 eventCode, | |
6258 | A_UINT8 *macAddr) | |
6259 | { | |
6260 | A_UINT8 pos; | |
6261 | ||
6262 | for (pos=0;pos<6;pos++) | |
6263 | printk("%02x: ",*(macAddr+pos)); | |
6264 | printk("\n"); | |
6265 | } | |
6266 | ||
6267 | #ifdef HTC_TEST_SEND_PKTS | |
6268 | #define HTC_TEST_DUPLICATE 8 | |
6269 | static void DoHTCSendPktsTest(AR_SOFTC_T *ar, int MapNo, HTC_ENDPOINT_ID eid, struct sk_buff *dupskb) | |
6270 | { | |
6271 | struct ar_cookie *cookie; | |
6272 | struct ar_cookie *cookieArray[HTC_TEST_DUPLICATE]; | |
6273 | struct sk_buff *new_skb; | |
6274 | int i; | |
6275 | int pkts = 0; | |
6276 | HTC_PACKET_QUEUE pktQueue; | |
6277 | EPPING_HEADER *eppingHdr; | |
6278 | ||
6279 | eppingHdr = A_NETBUF_DATA(dupskb); | |
6280 | ||
6281 | if (eppingHdr->Cmd_h == EPPING_CMD_NO_ECHO) { | |
6282 | /* skip test if this is already a tx perf test */ | |
6283 | return; | |
6284 | } | |
6285 | ||
6286 | for (i = 0; i < HTC_TEST_DUPLICATE; i++,pkts++) { | |
6287 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
6288 | cookie = ar6000_alloc_cookie(ar); | |
6289 | if (cookie != NULL) { | |
6290 | ar->arTxPending[eid]++; | |
6291 | ar->arTotalTxDataPending++; | |
6292 | } | |
6293 | ||
6294 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
6295 | ||
6296 | if (NULL == cookie) { | |
6297 | break; | |
6298 | } | |
6299 | ||
6300 | new_skb = A_NETBUF_ALLOC(A_NETBUF_LEN(dupskb)); | |
6301 | ||
6302 | if (new_skb == NULL) { | |
6303 | AR6000_SPIN_LOCK(&ar->arLock, 0); | |
6304 | ar6000_free_cookie(ar,cookie); | |
6305 | AR6000_SPIN_UNLOCK(&ar->arLock, 0); | |
6306 | break; | |
6307 | } | |
6308 | ||
6309 | A_NETBUF_PUT_DATA(new_skb, A_NETBUF_DATA(dupskb), A_NETBUF_LEN(dupskb)); | |
6310 | cookie->arc_bp[0] = (unsigned long)new_skb; | |
6311 | cookie->arc_bp[1] = MapNo; | |
6312 | SET_HTC_PACKET_INFO_TX(&cookie->HtcPkt, | |
6313 | cookie, | |
6314 | A_NETBUF_DATA(new_skb), | |
6315 | A_NETBUF_LEN(new_skb), | |
6316 | eid, | |
6317 | AR6K_DATA_PKT_TAG); | |
6318 | ||
6319 | cookieArray[i] = cookie; | |
6320 | ||
6321 | { | |
6322 | EPPING_HEADER *pHdr = (EPPING_HEADER *)A_NETBUF_DATA(new_skb); | |
6323 | pHdr->Cmd_h = EPPING_CMD_NO_ECHO; /* do not echo the packet */ | |
6324 | } | |
6325 | } | |
6326 | ||
6327 | if (pkts == 0) { | |
6328 | return; | |
6329 | } | |
6330 | ||
6331 | INIT_HTC_PACKET_QUEUE(&pktQueue); | |
6332 | ||
6333 | for (i = 0; i < pkts; i++) { | |
6334 | HTC_PACKET_ENQUEUE(&pktQueue,&cookieArray[i]->HtcPkt); | |
6335 | } | |
6336 | ||
6337 | HTCSendPktsMultiple(ar->arHtcTarget, &pktQueue); | |
6338 | ||
6339 | } | |
6340 | #endif | |
6341 | ||
6342 | #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT | |
6343 | /* | |
6344 | * Add support for adding and removing a virtual adapter for soft AP. | |
6345 | * Some OS requires different adapters names for station and soft AP mode. | |
6346 | * To support these requirement, create and destory a netdevice instance | |
6347 | * when the AP mode is operational. A full fledged support for virual device | |
6348 | * is not implemented. Rather a virtual interface is created and is linked | |
6349 | * with the existing physical device instance during the operation of the | |
6350 | * AP mode. | |
6351 | */ | |
6352 | ||
6353 | A_STATUS ar6000_start_ap_interface(AR_SOFTC_T *ar) | |
6354 | { | |
6355 | AR_VIRTUAL_INTERFACE_T *arApDev; | |
6356 | ||
6357 | /* Change net_device to point to AP instance */ | |
6358 | arApDev = (AR_VIRTUAL_INTERFACE_T *)ar->arApDev; | |
6359 | ar->arNetDev = arApDev->arNetDev; | |
6360 | ||
6361 | return A_OK; | |
6362 | } | |
6363 | ||
6364 | A_STATUS ar6000_stop_ap_interface(AR_SOFTC_T *ar) | |
6365 | { | |
6366 | AR_VIRTUAL_INTERFACE_T *arApDev; | |
6367 | ||
6368 | /* Change net_device to point to sta instance */ | |
6369 | arApDev = (AR_VIRTUAL_INTERFACE_T *)ar->arApDev; | |
6370 | if (arApDev) { | |
6371 | ar->arNetDev = arApDev->arStaNetDev; | |
6372 | } | |
6373 | ||
6374 | return A_OK; | |
6375 | } | |
6376 | ||
6377 | ||
6378 | A_STATUS ar6000_create_ap_interface(AR_SOFTC_T *ar, char *ap_ifname) | |
6379 | { | |
6380 | struct net_device *dev; | |
6381 | AR_VIRTUAL_INTERFACE_T *arApDev; | |
6382 | ||
6383 | dev = alloc_etherdev(sizeof(AR_VIRTUAL_INTERFACE_T)); | |
6384 | if (dev == NULL) { | |
6385 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: can't alloc etherdev\n")); | |
6386 | return A_ERROR; | |
6387 | } | |
6388 | ||
6389 | ether_setup(dev); | |
6390 | init_netdev(dev, ap_ifname); | |
6391 | ||
6392 | if (register_netdev(dev)) { | |
6393 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_create_ap_interface: register_netdev failed\n")); | |
6394 | return A_ERROR; | |
6395 | } | |
6396 | ||
6397 | arApDev = netdev_priv(dev); | |
6398 | arApDev->arDev = ar; | |
6399 | arApDev->arNetDev = dev; | |
6400 | arApDev->arStaNetDev = ar->arNetDev; | |
6401 | ||
6402 | ar->arApDev = arApDev; | |
6403 | arApNetDev = dev; | |
6404 | ||
6405 | /* Copy the MAC address */ | |
6406 | A_MEMCPY(dev->dev_addr, ar->arNetDev->dev_addr, AR6000_ETH_ADDR_LEN); | |
6407 | ||
6408 | return A_OK; | |
6409 | } | |
6410 | ||
6411 | A_STATUS ar6000_add_ap_interface(AR_SOFTC_T *ar, char *ap_ifname) | |
6412 | { | |
6413 | /* Interface already added, need not proceed further */ | |
6414 | if (ar->arApDev != NULL) { | |
6415 | AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_add_ap_interface: interface already present \n")); | |
6416 | return A_OK; | |
6417 | } | |
6418 | ||
6419 | if (ar6000_create_ap_interface(ar, ap_ifname) != A_OK) { | |
6420 | return A_ERROR; | |
6421 | } | |
6422 | ||
6423 | A_PRINTF("Add AP interface %s \n",ap_ifname); | |
6424 | ||
6425 | return ar6000_start_ap_interface(ar); | |
6426 | } | |
6427 | ||
6428 | A_STATUS ar6000_remove_ap_interface(AR_SOFTC_T *ar) | |
6429 | { | |
6430 | if (arApNetDev) { | |
6431 | ar6000_stop_ap_interface(ar); | |
6432 | ||
6433 | unregister_netdev(arApNetDev); | |
6434 | #ifndef free_netdev | |
6435 | kfree(arApNetDev); | |
6436 | #else | |
6437 | free_netdev(apApNetDev); | |
6438 | #endif | |
6439 | ||
6440 | A_PRINTF("Remove AP interface\n"); | |
6441 | } | |
6442 | ar->arApDev = NULL; | |
6443 | arApNetDev = NULL; | |
6444 | ||
6445 | ||
6446 | return A_OK; | |
6447 | } | |
6448 | #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ | |
6449 | ||
6450 | ||
6451 | #ifdef EXPORT_HCI_BRIDGE_INTERFACE | |
6452 | EXPORT_SYMBOL(setupbtdev); | |
6453 | #endif |