2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/os/linux/include/gl_os.h#1 $
6 \brief List the external reference to OS for GLUE Layer.
8 In this file we define the data structure - GLUE_INFO_T to store those objects
9 we acquired from OS - e.g. TIMER, SPINLOCK, NET DEVICE ... . And all the
10 external reference (header file, extern func() ..) to OS for GLUE Layer should
14 /*******************************************************************************
15 * Copyright (c) 2007 MediaTek Inc.
17 * All rights reserved. Copying, compilation, modification, distribution
18 * or any other use whatsoever of this material is strictly prohibited
19 * except in accordance with a Software License Agreement with
21 ********************************************************************************
24 /*******************************************************************************
27 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
28 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
29 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
30 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
31 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
32 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
33 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
34 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
35 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
36 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
37 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
38 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
39 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
41 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
42 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
43 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
44 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
45 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
47 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
48 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
49 * OF LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
50 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
51 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
53 ********************************************************************************
60 ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
63 ** 08 20 2012 yuche.tsai
65 ** Try to fix frame register KE issue.
69 * Add AEE message support
70 * 1) Show AEE warning(red screen) if SDIO access error occurs
75 * Enable CFG80211 Support.
78 * [WCXRP00001153] [MT6620 Wi-Fi][Driver] Adding the get_ch_list and set_tx_power proto type function
79 * Adding the related ioctl / wlan oid function to set the Tx power cfg.
82 * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
83 * Add wake lock if timer timeout value is smaller than 5 seconds
85 * 11 18 2011 yuche.tsai
87 * CONFIG P2P support RSSI query, default turned off.
89 * 11 16 2011 yuche.tsai
91 * Avoid using work thread.
93 * 11 11 2011 yuche.tsai
95 * Fix work thread cancel issue.
98 * [WCXRP00001036] [MT6620 Wi-Fi][Driver][FW] Adding the 802.11w code for MFP
99 * adding the 802.11w related function and define .
101 * 09 29 2011 terry.wu
103 * Show DRV_NAME by chip id.
105 * 04 18 2011 terry.wu
106 * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
107 * Remove flag CFG_WIFI_DIRECT_MOVED.
110 * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for RESET_START and RESET_END events
111 * implement kernel-to-userspace communication via generic netlink socket for whole-chip resetting mechanism
114 * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
115 * portability improvement
117 * 03 17 2011 chinglan.wang
118 * [WCXRP00000570] [MT6620 Wi-Fi][Driver] Add Wi-Fi Protected Setup v2.0 feature
121 * 03 03 2011 jeffrey.chang
122 * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
123 * support concurrent network
125 * 03 03 2011 jeffrey.chang
126 * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
127 * modify net device relative functions to support multiple H/W queues
130 * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
131 * Add security check code.
134 * [WCXRP00000482] [MT6620 Wi-Fi][Driver] Simplify logic for checking NVRAM existence in driver domain
135 * simplify logic for checking NVRAM existence only once.
137 * 02 16 2011 jeffrey.chang
139 * Add query ipv4 and ipv6 address during early suspend and late resume
141 * 02 10 2011 chinghwa.yu
142 * [WCXRP00000065] Update BoW design and settings
143 * Fix kernel API change issue.
144 * Before ALPS 2.2 (2.2 included), kfifo_alloc() is
145 * struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask, spinlock_t *lock);
146 * After ALPS 2.3, kfifo_alloc() is changed to
147 * int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask);
150 * [WCXRP00000433] [MT6620 Wi-Fi][Driver] Remove WAPI structure define for avoid P2P module with structure miss-align pointer issue
151 * always pre-allio WAPI related structure for align p2p module.
153 * 02 09 2011 terry.wu
154 * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
155 * Halt p2p module init and exit until TxThread finished p2p register and unregister.
157 * 02 01 2011 cm.chang
158 * [WCXRP00000415] [MT6620 Wi-Fi][Driver] Check if any memory leakage happens when uninitializing in DGB mode
161 * 01 27 2011 cm.chang
162 * [WCXRP00000402] [MT6620 Wi-Fi][Driver] Enable MCR read/write by iwpriv by default
166 * [WCXRP00000357] [MT6620 Wi-Fi][Driver][Bluetooth over Wi-Fi] add another net device interface for BT AMP
167 * implementation of separate BT_OVER_WIFI data path.
170 * [WCXRP00000356] [MT6620 Wi-Fi][Driver] fill mac header length for security frames 'cause hardware header translation needs such information
171 * fill mac header length information for 802.1x frames.
173 * 01 11 2011 chinglan.wang
175 * Modify to reslove the CR :[ALPS00028994] Use WEP security to connect Marvell 11N AP. Connection establish successfully.
176 * Use the WPS function to connect AP, the privacy bit always is set to 1.
179 * [WCXRP00000349] [MT6620 Wi-Fi][Driver] make kalIoctl() of linux port as a thread safe API to avoid potential issues due to multiple access
180 * use mutex to protect kalIoctl() for thread safe.
183 * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service Discovery
184 * ioctl implementations for P2P Service Discovery
187 * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
188 * adding the p2p random ssid support.
191 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000086] [MT6620 Wi-Fi][Driver] The mac address is all zero at android
192 * complete implementation of Android NVRAM access
196 * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
199 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check
200 * add skeleton for NVRAM integration
204 * add waitq for poll() and read().
208 * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
212 * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
214 * 09 03 2010 kevin.huang
216 * Refine #include sequence and solve recursive/nested #include issue
220 * adding the wapi support for integration test.
222 * 08 31 2010 kevin.huang
224 * Use LINK LIST operation to process SCAN result
228 * revise constant definitions to be matched with implementation (original cmd-event definition is deprecated)
232 * P2P packets are now marked when being queued into driver, and identified later without checking MAC address
236 * revised implementation of Wi-Fi Direct io controls.
240 * 1) do not use in-stack variable for beacon updating. (for MAUI porting)
241 * 2) extending scanning result to 64 instead of 48
245 * driver hook modifications corresponding to ioctl interface change.
249 * [Wi-Fi Direct] add framework for driver hooks
251 * 08 02 2010 jeffrey.chang
253 * 1) modify tx service thread to avoid busy looping
254 * 2) add spin lock declartion for linux build
256 * 07 23 2010 jeffrey.chang
260 * 07 22 2010 jeffrey.chang
262 * modify tx thread and remove some spinlock
264 * 07 19 2010 jeffrey.chang
266 * add security frame pending count
270 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
272 * 06 06 2010 kevin.huang
273 * [WPD00003832][MT6620 5931] Create driver base
274 * [MT6620 5931] Create driver base
277 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
278 * add ioctl to configure scan mode for p2p connection
281 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
282 * add cfg80211 interface, which is to replace WE, for further extension
285 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
286 * add ioctl framework for Wi-Fi Direct by reusing wireless extension ioctls as well
289 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
290 * p2p ioctls revised.
293 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
294 * add ioctl for controlling p2p scan phase parameters
297 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
298 * implement basic wi-fi direct framework
300 * 05 07 2010 jeffrey.chang
301 * [WPD00003826]Initial import for Linux port
302 * prevent supplicant accessing driver during resume
305 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
306 * add basic framework for implementating P2P driver hook.
309 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
310 * change variable names for multiple physical link to match with coding convention
313 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
314 * identify BT Over Wi-Fi Security frame and mark it as 802.1X frame
317 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
318 * add multiple physical link support
320 * 04 27 2010 jeffrey.chang
321 * [WPD00003826]Initial import for Linux port
322 * 1) fix firmware download bug
323 * 2) remove query statistics for acelerating firmware download
325 * 04 27 2010 jeffrey.chang
326 * [WPD00003826]Initial import for Linux port
327 * follow Linux's firmware framework, and remove unused kal API
330 * [WPD00001943]Create WiFi test driver framework on WinXP
331 * surpress compiler warning
333 * 04 19 2010 jeffrey.chang
334 * [WPD00003826]Initial import for Linux port
335 * supporting power management
337 * 04 14 2010 jeffrey.chang
338 * [WPD00003826]Initial import for Linux port
339 * pvInformationBuffer and u4InformationBufferLength are no longer in glue
342 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
343 * add framework for BT-over-Wi-Fi support.
344 * * * * * * * * * * * * * * * * * * * * 1) prPendingCmdInfo is replaced by queue for multiple handler capability
345 * * * * * * * * * * * * * * * * * * * * 2) command sequence number is now increased atomically
346 * * * * * * * * * * * * * * * * * * * * 3) private data could be hold and taken use for other purpose
349 * [WPD00001943]Create WiFi test driver framework on WinXP
350 * rWlanInfo should be placed at adapter rather than glue due to most operations
351 * * * * * * * * * * are done in adapter layer.
353 * 04 06 2010 jeffrey.chang
354 * [WPD00003826]Initial import for Linux port
355 * Tag the packet for QoS on Tx path
357 * 04 06 2010 jeffrey.chang
358 * [WPD00003826]Initial import for Linux port
359 * (1)deliver the kalOidComplete status to upper layer
360 * * (2) fix spin lock
362 * 04 06 2010 jeffrey.chang
363 * [WPD00003826]Initial import for Linux port
364 * add timeout check in the kalOidComplete
366 * 04 06 2010 jeffrey.chang
367 * [WPD00003826]Initial import for Linux port
368 * improve none-glue code portability
371 * [WPD00001943]Create WiFi test driver framework on WinXP
372 * code refine: fgTestMode should be at adapter rather than glue due to the device/fw is also involved
375 * [WPD00001943]Create WiFi test driver framework on WinXP
376 * eliminate direct access for prGlueInfo->fgIsCardRemoved in non-glue layer
378 * 03 30 2010 jeffrey.chang
379 * [WPD00003826]Initial import for Linux port
380 * emulate NDIS Pending OID facility
382 * 03 26 2010 jeffrey.chang
383 * [WPD00003826]Initial import for Linux port
384 * [WPD00003826] Initial import for Linux port
385 * adding firmware download related data type
388 * [WPD00001943]Create WiFi test driver framework on WinXP
389 * 1) correct OID_802_11_CONFIGURATION with frequency setting behavior.
390 * * * * the frequency is used for adhoc connection only
391 * * * * 2) update with SD1 v0.9 CMD/EVENT documentation
394 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
395 * add Bluetooth-over-Wifi frame header check
397 * 03 24 2010 jeffrey.chang
398 * [WPD00003826]Initial import for Linux port
399 * initial import for Linux port
400 ** \main\maintrunk.MT5921\30 2009-10-20 17:38:31 GMT mtk01090
401 ** Refine driver unloading and clean up procedure. Block requests, stop main thread and clean up queued requests, and then stop hw.
402 ** \main\maintrunk.MT5921\29 2009-10-08 10:33:33 GMT mtk01090
403 ** Avoid accessing private data of net_device directly. Replace with netdev_priv(). Add more checking for input parameters and pointers.
404 ** \main\maintrunk.MT5921\28 2009-09-28 20:19:26 GMT mtk01090
405 ** Add private ioctl to carry OID structures. Restructure public/private ioctl interfaces to Linux kernel.
406 ** \main\maintrunk.MT5921\27 2009-08-18 22:57:12 GMT mtk01090
407 ** Add Linux SDIO (with mmc core) support.
408 ** Add Linux 2.6.21, 2.6.25, 2.6.26.
409 ** Fix compile warning in Linux.
410 ** \main\maintrunk.MT5921\26 2009-07-06 21:42:25 GMT mtk01088
411 ** fixed the compiling error at linux
412 ** \main\maintrunk.MT5921\25 2009-07-06 20:51:46 GMT mtk01088
413 ** adding the wapi 1x ether type define
414 ** \main\maintrunk.MT5921\24 2009-06-23 23:19:18 GMT mtk01090
415 ** Add build option BUILD_USE_EEPROM and compile option CFG_SUPPORT_EXT_CONFIG for NVRAM support
416 ** \main\maintrunk.MT5921\23 2009-02-07 15:05:06 GMT mtk01088
417 ** add the privacy flag to ingo driver the supplicant selected ap's security
418 ** \main\maintrunk.MT5921\22 2009-02-05 15:34:09 GMT mtk01088
419 ** fixed the compiling error for using bits marco for only one parameter
420 ** \main\maintrunk.MT5921\21 2009-01-22 13:02:13 GMT mtk01088
421 ** data frame is or not 802.1x value share with tid, using the same reserved byte, provide the function to set and get
422 ** \main\maintrunk.MT5921\20 2008-10-24 12:04:16 GMT mtk01088
423 ** move the config.h from precomp.h to here for lint check
424 ** \main\maintrunk.MT5921\19 2008-09-22 23:19:02 GMT mtk01461
425 ** Update driver for code review
426 ** \main\maintrunk.MT5921\18 2008-09-05 17:25:13 GMT mtk01461
427 ** Update Driver for Code Review
428 ** \main\maintrunk.MT5921\17 2008-08-01 13:32:47 GMT mtk01084
429 ** Prevent redundent driver assertion in driver logic when BUS is detached
430 ** \main\maintrunk.MT5921\16 2008-05-30 14:41:43 GMT mtk01461
431 ** Remove WMM Assoc Flag in KAL
432 ** \main\maintrunk.MT5921\15 2008-05-29 14:16:25 GMT mtk01084
433 ** remoev un-used variable
434 ** \main\maintrunk.MT5921\14 2008-05-03 15:17:14 GMT mtk01461
435 ** Add Media Status variable in Glue Layer
436 ** \main\maintrunk.MT5921\13 2008-04-24 11:58:41 GMT mtk01461
437 ** change threshold to 256
438 ** \main\maintrunk.MT5921\12 2008-03-11 14:51:05 GMT mtk01461
439 ** Remove redundant GL_CONN_INFO_T
440 ** \main\maintrunk.MT5921\11 2008-01-07 15:07:41 GMT mtk01461
441 ** Adjust the netif stop threshold to 150
442 ** \main\maintrunk.MT5921\10 2007-11-26 19:43:46 GMT mtk01461
443 ** Add OS_TIMESTAMP macro
445 ** \main\maintrunk.MT5921\9 2007-11-07 18:38:38 GMT mtk01461
447 ** \main\maintrunk.MT5921\8 2007-11-02 01:04:00 GMT mtk01461
448 ** Unify TX Path for Normal and IBSS Power Save + IBSS neighbor learning
449 ** Revision 1.5 2007/07/12 11:04:28 MTK01084
450 ** update macro to delay for ms order
452 ** Revision 1.4 2007/07/05 07:25:34 MTK01461
453 ** Add Linux initial code, modify doc, add 11BB, RF init code
455 ** Revision 1.3 2007/06/27 02:18:51 MTK01461
456 ** Update SCAN_FSM, Initial(Can Load Module), Proc(Can do Reg R/W), TX API
458 ** Revision 1.2 2007/06/25 06:16:24 MTK01461
459 ** Update illustrations, gl_init.c, gl_kal.c, gl_kal.h, gl_os.h and RX API
466 /*******************************************************************************
467 * C O M P I L E R F L A G S
468 ********************************************************************************
470 /*------------------------------------------------------------------------------
471 * Flags for LINUX(OS) dependent
472 *------------------------------------------------------------------------------
474 #define CFG_MAX_WLAN_DEVICES 1 /* number of wlan card will coexist*/
476 #define CFG_MAX_TXQ_NUM 4 /* number of tx queue for support multi-queue h/w */
479 #define CFG_USE_SPIN_LOCK_BOTTOM_HALF 0 /* 1: Enable use of SPIN LOCK Bottom Half for LINUX
480 0: Disable - use SPIN LOCK IRQ SAVE instead */
482 #define CFG_TX_PADDING_SMALL_ETH_PACKET 0 /* 1: Enable - Drop ethernet packet if it < 14 bytes.
483 And pad ethernet packet with dummy 0 if it < 60 bytes.
486 #define CFG_TX_STOP_NETIF_QUEUE_THRESHOLD 256 /* packets */
488 #define CFG_TX_STOP_NETIF_PER_QUEUE_THRESHOLD 256 /* packets */
489 #define CFG_TX_START_NETIF_PER_QUEUE_THRESHOLD 128 /* packets */
492 #define ETH_P_1X 0x888E
493 #define IPTOS_PREC_OFFSET 5
494 #define USER_PRIORITY_DEFAULT 0
496 #define ETH_WPI_1X 0x88B4
499 #define ETH_TYPE_LEN_OFFSET 12
500 #define ETH_P_IP 0x0800
501 #define ETH_P_1X 0x888E
502 #define ETH_P_PRE_1X 0x88C7
505 #define IP_HEADER_LEN 20
507 #define IPVH_VERSION_OFFSET 4 // For Little-Endian
508 #define IPVH_VERSION_MASK 0xF0
509 #define IPTOS_PREC_OFFSET 5
510 #define IPTOS_PREC_MASK 0xE0
512 #define SOURCE_PORT_LEN 2
513 /* NOTE(Kevin): Without IP Option Length */
514 #define LOOK_AHEAD_LEN (ETH_HLEN + IP_HEADER_LEN + SOURCE_PORT_LEN)
517 #define ETH_LLC_OFFSET (ETH_HLEN)
518 #define ETH_LLC_LEN 3
519 #define ETH_LLC_DSAP_SNAP 0xAA
520 #define ETH_LLC_SSAP_SNAP 0xAA
521 #define ETH_LLC_CONTROL_UNNUMBERED_INFORMATION 0x03
524 #define ETH_SNAP_OFFSET (ETH_HLEN + ETH_LLC_LEN)
525 #define ETH_SNAP_LEN 5
526 #define ETH_SNAP_BT_SIG_OUI_0 0x00
527 #define ETH_SNAP_BT_SIG_OUI_1 0x19
528 #define ETH_SNAP_BT_SIG_OUI_2 0x58
530 #define BOW_PROTOCOL_ID_SECURITY_FRAME 0x0003
534 #define CHIP_NAME "MT6620"
535 #elif defined(MT5931)
536 #define CHIP_NAME "MT5931"
537 #elif defined(MT6628)
538 #define CHIP_NAME "MT6628"
541 #define DRV_NAME "["CHIP_NAME"]: "
543 /* Define if target platform is Android.
544 * It should already be defined in Android kernel source
546 #ifndef CONFIG_ANDROID
547 #define CONFIG_ANDROID 0
550 /* for CFG80211 IE buffering mechanism */
551 #define CFG_CFG80211_IE_BUF_LEN (512)
553 /*******************************************************************************
554 * E X T E R N A L R E F E R E N C E S
555 ********************************************************************************
557 #include <linux/version.h> /* constant of kernel version */
559 #include <linux/kernel.h> /* bitops.h */
561 #include <linux/timer.h> /* struct timer_list */
562 #include <linux/jiffies.h> /* jiffies */
563 #include <linux/delay.h> /* udelay and mdelay macro */
566 #include <linux/wakelock.h>
569 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12)
570 #include <linux/irq.h> /* IRQT_FALLING */
573 #include <linux/netdevice.h> /* struct net_device, struct net_device_stats */
574 #include <linux/etherdevice.h> /* for eth_type_trans() function */
575 #include <linux/wireless.h> /* struct iw_statistics */
576 #include <linux/if_arp.h>
577 #include <linux/inetdevice.h> /* struct in_device */
579 #include <linux/ip.h> /* struct iphdr */
581 #include <linux/string.h> /* for memcpy()/memset() function */
582 #include <linux/stddef.h> /* for offsetof() macro */
584 #include <linux/proc_fs.h> /* The proc filesystem constants/structures */
586 #include <linux/rtnetlink.h> /* for rtnl_lock() and rtnl_unlock() */
587 #include <linux/kthread.h> /* kthread_should_stop(), kthread_run() */
588 #include <asm/uaccess.h> /* for copy_from_user() */
589 #include <linux/fs.h> /* for firmware download */
590 #include <linux/vmalloc.h>
592 #include <linux/kfifo.h> /* for kfifo interface */
593 #include <linux/cdev.h> /* for cdev interface */
595 #include <linux/firmware.h> /* for firmware download */
597 #if defined(_HIF_SDIO)
598 #include <linux/mmc/sdio.h>
599 #include <linux/mmc/sdio_func.h>
602 #include <linux/random.h>
604 #include <linux/lockdep.h>
606 #include <asm/io.h> /* readw and writew */
608 #if WIRELESS_EXT > 12
609 #include <net/iw_handler.h>
615 #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
616 #include <linux/wireless.h>
617 #include <net/cfg80211.h>
620 #include <linux/module.h>
622 #include "gl_typedef.h"
626 #if CFG_CHIP_RESET_SUPPORT
634 #include "wlan_lib.h"
635 #include "wlan_oid.h"
637 #if CFG_ENABLE_AEE_MSG
638 #include <linux/aee.h>
641 extern BOOLEAN fgIsBusAccessFailed;
643 /*******************************************************************************
645 ********************************************************************************
647 #define GLUE_FLAG_HALT BIT(0)
648 #define GLUE_FLAG_INT BIT(1)
649 #define GLUE_FLAG_OID BIT(2)
650 #define GLUE_FLAG_TIMEOUT BIT(3)
651 #define GLUE_FLAG_TXREQ BIT(4)
652 #define GLUE_FLAG_SUB_MOD_INIT BIT(5)
653 #define GLUE_FLAG_SUB_MOD_EXIT BIT(6)
654 #define GLUE_FLAG_SUB_MOD_MULTICAST BIT(7)
655 #define GLUE_FLAG_FRAME_FILTER BIT(8)
656 #define GLUE_FLAG_HALT_BIT (0)
657 #define GLUE_FLAG_INT_BIT (1)
658 #define GLUE_FLAG_OID_BIT (2)
659 #define GLUE_FLAG_TIMEOUT_BIT (3)
660 #define GLUE_FLAG_TXREQ_BIT (4)
661 #define GLUE_FLAG_SUB_MOD_INIT_BIT (5)
662 #define GLUE_FLAG_SUB_MOD_EXIT_BIT (6)
663 #define GLUE_FLAG_SUB_MOD_MULTICAST_BIT (7)
664 #define GLUE_FLAG_FRAME_FILTER_BIT (8)
668 #define GLUE_BOW_KFIFO_DEPTH (1024)
669 //#define GLUE_BOW_DEVICE_NAME "MT6620 802.11 AMP"
670 #define GLUE_BOW_DEVICE_NAME "ampc0"
673 /*******************************************************************************
675 ********************************************************************************
677 typedef struct _GL_WPA_INFO_T {
678 UINT_32 u4WpaVersion;
680 UINT_32 u4CipherGroup;
681 UINT_32 u4CipherPairwise;
683 BOOLEAN fgPrivacyInvoke;
684 #if CFG_SUPPORT_802_11W
687 } GL_WPA_INFO_T, *P_GL_WPA_INFO_T;
689 typedef enum _ENUM_RSSI_TRIGGER_TYPE {
690 ENUM_RSSI_TRIGGER_NONE,
691 ENUM_RSSI_TRIGGER_GREATER,
692 ENUM_RSSI_TRIGGER_LESS,
693 ENUM_RSSI_TRIGGER_TRIGGERED,
694 ENUM_RSSI_TRIGGER_NUM
695 } ENUM_RSSI_TRIGGER_TYPE;
697 #if CFG_ENABLE_WIFI_DIRECT
698 typedef enum _ENUM_SUB_MODULE_IDX_T {
701 } ENUM_SUB_MODULE_IDX_T;
703 typedef enum _ENUM_NET_REG_STATE_T {
704 ENUM_NET_REG_STATE_UNREGISTERED,
705 ENUM_NET_REG_STATE_REGISTERING,
706 ENUM_NET_REG_STATE_REGISTERED,
707 ENUM_NET_REG_STATE_UNREGISTERING,
708 ENUM_NET_REG_STATE_NUM
709 } ENUM_NET_REG_STATE_T;
713 typedef struct _GL_IO_REQ_T {
714 QUE_ENTRY_T rQueEntry;
715 //wait_queue_head_t cmdwait_q;
718 #if CFG_ENABLE_WIFI_DIRECT
721 P_ADAPTER_T prAdapter;
722 PFN_OID_HANDLER_FUNC pfnOidHandler;
724 UINT_32 u4InfoBufLen;
725 PUINT_32 pu4QryInfoLen;
728 } GL_IO_REQ_T, *P_GL_IO_REQ_T;
730 #if CFG_ENABLE_BT_OVER_WIFI
731 typedef struct _GL_BOW_INFO {
732 BOOLEAN fgIsRegistered;
733 dev_t u4DeviceNumber; /* dynamic device number */
734 // struct kfifo *prKfifo; /* for buffering indicated events */
735 struct kfifo rKfifo; /* for buffering indicated events */
736 spinlock_t rSpinLock; /* spin lock for kfifo */
738 UINT_32 u4FreqInKHz; /* frequency */
740 UINT_8 aucRole[CFG_BOW_PHYSICAL_LINK_NUM]; /* 0: Responder, 1: Initiator */
741 ENUM_BOW_DEVICE_STATE aeState[CFG_BOW_PHYSICAL_LINK_NUM];
742 PARAM_MAC_ADDRESS arPeerAddr[CFG_BOW_PHYSICAL_LINK_NUM];
744 wait_queue_head_t outq;
746 #if CFG_BOW_SEPARATE_DATA_PATH
748 struct net_device *prDevHandler;
749 BOOLEAN fgIsNetRegistered;
752 } GL_BOW_INFO, *P_GL_BOW_INFO;
756 * type definition of pointer to p2p structure
758 typedef struct _GL_P2P_INFO_T GL_P2P_INFO_T, *P_GL_P2P_INFO_T;
760 struct _GLUE_INFO_T {
762 struct net_device *prDevHandler;
764 /* Device Index(index of arWlanDevInfo[]) */
767 /* Device statistics */
768 struct net_device_stats rNetDevStats;
770 /* Wireless statistics struct net_device */
771 struct iw_statistics rIwStats;
773 /* spinlock to sync power save mechanism */
774 spinlock_t rSpinLock[SPIN_LOCK_NUM];
776 /* semaphore for ioctl */
777 struct semaphore ioctl_sem;
779 UINT_32 u4Flag; /* GLUE_FLAG_XXX */
781 //UINT_32 u4TimeoutFlag;
782 UINT_32 u4OidCompleteFlag;
783 UINT_32 u4ReadyFlag; /* check if card is ready */
785 /* Number of pending frames, also used for debuging if any frame is
786 * missing during the process of unloading Driver.
788 * NOTE(Kevin): In Linux, we also use this variable as the threshold
789 * for manipulating the netif_stop(wake)_queue() func.
791 INT_32 ai4TxPendingFrameNumPerQueue[4][CFG_MAX_TXQ_NUM];
792 INT_32 i4TxPendingFrameNum;
793 INT_32 i4TxPendingSecurityFrameNum;
795 /* current IO request for kalIoctl */
796 GL_IO_REQ_T OidEntry;
802 struct firmware *prFw;
804 /* Host interface related information */
805 /* defined in related hif header file */
806 GL_HIF_INFO_T rHifInfo;
808 /*! \brief wext wpa related information */
809 GL_WPA_INFO_T rWpaInfo;
812 /* Pointer to ADAPTER_T - main data structure of internal protocol stack */
813 P_ADAPTER_T prAdapter;
815 #ifdef WLAN_INCLUDE_PROC
816 struct proc_dir_entry *pProcRoot;
817 #endif /* WLAN_INCLUDE_PROC */
819 /* Indicated media state */
820 ENUM_PARAM_MEDIA_STATE_T eParamMediaStateIndicated;
822 /* Device power state D0~D3 */
823 PARAM_DEVICE_POWER_STATE ePowerState;
825 struct completion rScanComp; /* indicate scan complete */
826 struct completion rHaltComp; /* indicate main thread halt complete */
827 struct completion rPendComp; /* indicate main thread halt complete */
829 #if 0// LINUX_VERSION_CODE < KERNEL_VERSION(2, 3, 0)
830 struct completion rMgmtTxComp; /* indicate supp mgmt TX done, supp can request channel again. */
834 #if CFG_ENABLE_WIFI_DIRECT
835 struct completion rSubModComp; /*indicate sub module init or exit complete*/
837 WLAN_STATUS rPendStatus;
844 //PVOID pvInformationBuffer;
845 //UINT_32 u4InformationBufferLength;
847 //PUINT_8 pucIOReqBuff;
849 //QUE_T rFreeIOReqQueue;
851 wait_queue_head_t waitq;
852 struct task_struct *main_thread;
854 struct timer_list tickfn;
857 #if CFG_SUPPORT_EXT_CONFIG
858 UINT_16 au2ExtCfg[256]; /* NVRAM data buffer */
859 UINT_32 u4ExtCfgLength; /* 0 means data is NOT valid */
862 #if 1//CFG_SUPPORT_WAPI
863 /* Should be large than the PARAM_WAPI_ASSOC_INFO_T */
864 UINT_8 aucWapiAssocInfoIEs[42];
865 UINT_16 u2WapiAssocInfoIESz;
868 #if CFG_ENABLE_BT_OVER_WIFI
869 GL_BOW_INFO rBowInfo;
872 #if CFG_ENABLE_WIFI_DIRECT
873 P_GL_P2P_INFO_T prP2PInfo;
874 #if CFG_SUPPORT_P2P_RSSI_QUERY
875 /* Wireless statistics struct net_device */
876 struct iw_statistics rP2pIwStats;
880 UINT_8 aucWSCIE[500]; /*for probe req*/
882 UINT_8 aucWSCAssocInfoIE[200]; /*for Assoc req*/
883 UINT_16 u2WSCAssocInfoIELen;
885 /* NVRAM availability */
886 BOOLEAN fgNvramAvailable;
888 BOOLEAN fgMcrAccessAllowed;
890 /* MAC Address Overriden by IOCTL */
891 BOOLEAN fgIsMacAddrOverride;
892 PARAM_MAC_ADDRESS rMacAddrOverride;
894 SET_TXPWR_CTRL_T rTxPwr;
896 /* for cfg80211 scan done indication */
897 struct cfg80211_scan_request *prScanRequest;
899 /* to indicate registered or not */
900 BOOLEAN fgIsRegistered;
902 /* for cfg80211 connected indication */
903 UINT_32 u4RspIeLength;
904 UINT_8 aucRspIe[CFG_CFG80211_IE_BUF_LEN];
906 UINT_32 u4ReqIeLength;
907 UINT_8 aucReqIe[CFG_CFG80211_IE_BUF_LEN];
910 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
912 typedef void (*PFN_WLANISR)(int irq, void *dev_id, struct pt_regs *regs);
914 typedef irqreturn_t (*PFN_WLANISR)(int irq, void *dev_id, struct pt_regs *regs);
917 typedef void (*PFN_LINUX_TIMER_FUNC)(unsigned long);
920 /* generic sub module init/exit handler
921 * now, we only have one sub module, p2p
923 #if CFG_ENABLE_WIFI_DIRECT
924 typedef BOOLEAN (*SUB_MODULE_INIT)(P_GLUE_INFO_T prGlueInfo);
925 typedef BOOLEAN (*SUB_MODULE_EXIT)(P_GLUE_INFO_T prGlueInfo);
927 typedef struct _SUB_MODULE_HANDLER {
928 SUB_MODULE_INIT subModInit;
929 SUB_MODULE_EXIT subModExit;
931 } SUB_MODULE_HANDLER, *P_SUB_MODULE_HANDLER;
935 #if CONFIG_NL80211_TESTMODE
937 typedef struct _NL80211_DRIVER_TEST_MODE_PARAMS {
940 } NL80211_DRIVER_TEST_MODE_PARAMS, *P_NL80211_DRIVER_TEST_MODE_PARAMS;
943 typedef struct _NL80211_DRIVER_SW_CMD_PARAMS {
944 NL80211_DRIVER_TEST_MODE_PARAMS hdr;
948 }NL80211_DRIVER_SW_CMD_PARAMS, *P_NL80211_DRIVER_SW_CMD_PARAMS;
950 struct iw_encode_exts {
951 __u32 ext_flags; /*!< IW_ENCODE_EXT_* */
952 __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /*!< LSB first */
953 __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /*!< LSB first */
954 __u8 addr[MAC_ADDR_LEN]; /*!< ff:ff:ff:ff:ff:ff for broadcast/multicast
955 * (group) keys or unicast address for
957 __u16 alg; /*!< IW_ENCODE_ALG_* */
963 typedef struct _NL80211_DRIVER_SET_KEY_EXTS {
964 NL80211_DRIVER_TEST_MODE_PARAMS hdr;
967 struct iw_encode_exts ext;
968 }NL80211_DRIVER_SET_KEY_EXTS, *P_NL80211_DRIVER_SET_KEY_EXTS;
973 /*******************************************************************************
974 * P U B L I C D A T A
975 ********************************************************************************
978 /*******************************************************************************
979 * P R I V A T E D A T A
980 ********************************************************************************
983 /*******************************************************************************
985 ********************************************************************************
987 /*----------------------------------------------------------------------------*/
988 /* Macros of SPIN LOCK operations for using in Glue Layer */
989 /*----------------------------------------------------------------------------*/
990 #if CFG_USE_SPIN_LOCK_BOTTOM_HALF
991 #define GLUE_SPIN_LOCK_DECLARATION()
992 #define GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, rLockCategory) \
994 if (rLockCategory < SPIN_LOCK_NUM) \
995 spin_lock_bh(&(prGlueInfo->rSpinLock[rLockCategory])); \
997 #define GLUE_RELEASE_SPIN_LOCK(prGlueInfo, rLockCategory) \
999 if (rLockCategory < SPIN_LOCK_NUM) \
1000 spin_unlock_bh(&(prGlueInfo->rSpinLock[rLockCategory])); \
1002 #else /* !CFG_USE_SPIN_LOCK_BOTTOM_HALF */
1003 #define GLUE_SPIN_LOCK_DECLARATION() UINT_32 __u4Flags = 0
1004 #define GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, rLockCategory) \
1006 if (rLockCategory < SPIN_LOCK_NUM) \
1007 spin_lock_irqsave(&(prGlueInfo)->rSpinLock[rLockCategory], __u4Flags); \
1009 #define GLUE_RELEASE_SPIN_LOCK(prGlueInfo, rLockCategory) \
1011 if (rLockCategory < SPIN_LOCK_NUM) \
1012 spin_unlock_irqrestore(&(prGlueInfo->rSpinLock[rLockCategory]), __u4Flags); \
1014 #endif /* !CFG_USE_SPIN_LOCK_BOTTOM_HALF */
1017 /*----------------------------------------------------------------------------*/
1018 /* Macros for accessing Reserved Fields of native packet */
1019 /*----------------------------------------------------------------------------*/
1020 #define GLUE_GET_PKT_QUEUE_ENTRY(_p) \
1021 (&( ((struct sk_buff *)(_p))->cb[0] ))
1023 #define GLUE_GET_PKT_DESCRIPTOR(_prQueueEntry) \
1024 ((P_NATIVE_PACKET) ((UINT_32)_prQueueEntry - offsetof(struct sk_buff, cb[0])) )
1026 #define GLUE_SET_PKT_FLAG_802_11(_p) \
1027 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(7))
1029 #define GLUE_SET_PKT_FLAG_1X(_p) \
1030 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(6))
1032 #define GLUE_SET_PKT_FLAG_PAL(_p) \
1033 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(5))
1035 #define GLUE_SET_PKT_FLAG_P2P(_p) \
1036 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(4))
1040 #define GLUE_SET_PKT_TID(_p, _tid) \
1041 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= (((UINT_8)((_tid) & (BITS(0,3))))))
1044 #define GLUE_SET_PKT_FRAME_LEN(_p, _u2PayloadLen) \
1045 (*((PUINT_16) &( ((struct sk_buff *)(_p))->cb[6] )) = (UINT_16)(_u2PayloadLen))
1047 #define GLUE_GET_PKT_FRAME_LEN(_p) \
1048 (*((PUINT_16) &( ((struct sk_buff *)(_p))->cb[6] )) )
1051 #define GLUE_GET_PKT_IS_802_11(_p) \
1052 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(7)))
1054 #define GLUE_GET_PKT_IS_1X(_p) \
1055 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(6)))
1057 #define GLUE_GET_PKT_TID(_p) \
1058 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BITS(0,3)))
1061 #define GLUE_GET_PKT_IS_PAL(_p) \
1062 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(5)))
1064 #define GLUE_GET_PKT_IS_P2P(_p) \
1065 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(4)))
1068 #define GLUE_SET_PKT_HEADER_LEN(_p, _ucMacHeaderLen) \
1069 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[5] )) = (UINT_8)(_ucMacHeaderLen))
1071 #define GLUE_GET_PKT_HEADER_LEN(_p) \
1072 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[5] )) )
1074 #define GLUE_SET_PKT_ARRIVAL_TIME(_p, _rSysTime) \
1075 (*((POS_SYSTIME) &( ((struct sk_buff *)(_p))->cb[8] )) = (OS_SYSTIME)(_rSysTime))
1077 #define GLUE_GET_PKT_ARRIVAL_TIME(_p) \
1078 (*((POS_SYSTIME) &( ((struct sk_buff *)(_p))->cb[8] )) )
1080 /* Check validity of prDev, private data, and pointers */
1081 #define GLUE_CHK_DEV(prDev) \
1082 ((prDev && *((P_GLUE_INFO_T *) netdev_priv(prDev))) ? TRUE : FALSE)
1084 #define GLUE_CHK_PR2(prDev, pr2) \
1085 ((GLUE_CHK_DEV(prDev) && pr2) ? TRUE : FALSE)
1087 #define GLUE_CHK_PR3(prDev, pr2, pr3) \
1088 ((GLUE_CHK_PR2(prDev, pr2) && pr3) ? TRUE : FALSE)
1090 #define GLUE_CHK_PR4(prDev, pr2, pr3, pr4) \
1091 ((GLUE_CHK_PR3(prDev, pr2, pr3) && pr4) ? TRUE : FALSE)
1093 #define GLUE_SET_EVENT(pr) \
1096 #define GLUE_INC_REF_CNT(_refCount) atomic_inc((atomic_t *)&(_refCount))
1097 #define GLUE_DEC_REF_CNT(_refCount) atomic_dec((atomic_t *)&(_refCount))
1100 #define DbgPrint(...)
1101 /*******************************************************************************
1102 * F U N C T I O N D E C L A R A T I O N S
1103 ********************************************************************************
1105 #ifdef WLAN_INCLUDE_PROC
1108 struct net_device *prDev,
1114 struct net_device *prDev,
1117 #endif /* WLAN_INCLUDE_PROC */
1119 #if CFG_ENABLE_BT_OVER_WIFI
1122 P_GLUE_INFO_T prGlueInfo
1127 P_GLUE_INFO_T prGlueInfo
1131 #if CFG_ENABLE_WIFI_DIRECT
1135 P_GLUE_INFO_T prGlueInfo
1140 P_GLUE_INFO_T prGlueInfo
1145 P_GLUE_INFO_T prGlueInfo
1150 P_GLUE_INFO_T prGlueInfo
1154 wlanSubModRegisterInitExit(
1155 SUB_MODULE_INIT rSubModInit,
1156 SUB_MODULE_EXIT rSubModExit,
1157 ENUM_SUB_MODULE_IDX_T eSubModIdx
1162 P_GLUE_INFO_T *prGlueInfoExpAddr
1171 p2pSetMulticastListWorkQueueWrapper(
1172 P_GLUE_INFO_T prGlueInfo
1179 /*******************************************************************************
1181 ********************************************************************************
1184 #endif /* _GL_OS_H */