2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_2/os/linux/include/gl_os.h#2 $
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 * [WCXRP00001166] [Wi-Fi] [Driver] cfg80211 integration for p2p newtork
61 * cfg80211 integration for p2p network.
64 * [WCXRP00001153] [MT6620 Wi-Fi][Driver] Adding the get_ch_list and set_tx_power proto type function
65 * Check in the Add Tx power Cmd to driver.
68 * [WCXRP00001136] [All Wi-Fi][Driver] Add wake lock for pending timer
69 * Add wake lock if timer timeout value is smaller than 5 seconds
71 * 11 19 2011 yuche.tsai
75 * 11 19 2011 yuche.tsai
77 * Add P2P RSSI Link Quality Query Support. (Default Off)
79 * 11 16 2011 yuche.tsai
81 * Avoid using work thread.
83 * 11 11 2011 yuche.tsai
85 * Fix work thread cancel issue.
87 * 10 19 2011 yuche.tsai
88 * [WCXRP00001045] [WiFi Direct][Driver] Check 2.1 branch.
90 * Davinci Maintrunk Label: MT6620_WIFI_DRIVER_FW_TRUNK_MT6620E5_111019_0926.
93 * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
94 * Remove flag CFG_WIFI_DIRECT_MOVED.
97 * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for RESET_START and RESET_END events
98 * sync. whole-chip resetting mechanism to V2.0 branch.
101 * [WCXRP00000577] [MT6620 Wi-Fi][Driver][FW] Create V2.0 branch for firmware and driver
102 * create V2.0 driver release based on label "MT6620_WIFI_DRIVER_V2_0_110318_1600" from main trunk
104 * 03 17 2011 chinglan.wang
105 * [WCXRP00000570] [MT6620 Wi-Fi][Driver] Add Wi-Fi Protected Setup v2.0 feature
108 * 03 03 2011 jeffrey.chang
109 * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
110 * support concurrent network
112 * 03 03 2011 jeffrey.chang
113 * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
114 * modify net device relative functions to support multiple H/W queues
117 * [WCXRP00000506] [MT6620 Wi-Fi][Driver][FW] Add Security check related code
118 * Add security check code.
121 * [WCXRP00000482] [MT6620 Wi-Fi][Driver] Simplify logic for checking NVRAM existence in driver domain
122 * simplify logic for checking NVRAM existence only once.
124 * 02 16 2011 jeffrey.chang
126 * Add query ipv4 and ipv6 address during early suspend and late resume
128 * 02 10 2011 chinghwa.yu
129 * [WCXRP00000065] Update BoW design and settings
130 * Fix kernel API change issue.
131 * Before ALPS 2.2 (2.2 included), kfifo_alloc() is
132 * struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask, spinlock_t *lock);
133 * After ALPS 2.3, kfifo_alloc() is changed to
134 * int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask);
137 * [WCXRP00000433] [MT6620 Wi-Fi][Driver] Remove WAPI structure define for avoid P2P module with structure miss-align pointer issue
138 * always pre-allio WAPI related structure for align p2p module.
140 * 02 09 2011 terry.wu
141 * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
142 * Halt p2p module init and exit until TxThread finished p2p register and unregister.
144 * 02 01 2011 cm.chang
145 * [WCXRP00000415] [MT6620 Wi-Fi][Driver] Check if any memory leakage happens when uninitializing in DGB mode
148 * 01 27 2011 cm.chang
149 * [WCXRP00000402] [MT6620 Wi-Fi][Driver] Enable MCR read/write by iwpriv by default
153 * [WCXRP00000357] [MT6620 Wi-Fi][Driver][Bluetooth over Wi-Fi] add another net device interface for BT AMP
154 * implementation of separate BT_OVER_WIFI data path.
157 * [WCXRP00000356] [MT6620 Wi-Fi][Driver] fill mac header length for security frames 'cause hardware header translation needs such information
158 * fill mac header length information for 802.1x frames.
160 * 01 11 2011 chinglan.wang
162 * Modify to reslove the CR :[ALPS00028994] Use WEP security to connect Marvell 11N AP. Connection establish successfully.
163 * Use the WPS function to connect AP, the privacy bit always is set to 1.
166 * [WCXRP00000349] [MT6620 Wi-Fi][Driver] make kalIoctl() of linux port as a thread safe API to avoid potential issues due to multiple access
167 * use mutex to protect kalIoctl() for thread safe.
170 * [WCXRP00000283] [MT6620 Wi-Fi][Driver][Wi-Fi Direct] Implementation of interface for supporting Wi-Fi Direct Service Discovery
171 * ioctl implementations for P2P Service Discovery
174 * [WCXRP00000164] [MT6620 Wi-Fi][Driver] Support the p2p random SSID
175 * adding the p2p random ssid support.
178 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000086] [MT6620 Wi-Fi][Driver] The mac address is all zero at android
179 * complete implementation of Android NVRAM access
183 * [WCXRP00000069][MT6620 Wi-Fi][Driver] Fix some code for phase 1 P2P Demo.
186 * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check
187 * add skeleton for NVRAM integration
191 * add waitq for poll() and read().
195 * adding the code for beacon/probe req/ probe rsp wsc ie at p2p.
199 * let the p2p can set the privacy bit at beacon and rsn ie at assoc req at key handshake state.
201 * 09 03 2010 kevin.huang
203 * Refine #include sequence and solve recursive/nested #include issue
207 * adding the wapi support for integration test.
209 * 08 31 2010 kevin.huang
211 * Use LINK LIST operation to process SCAN result
215 * revise constant definitions to be matched with implementation (original cmd-event definition is deprecated)
219 * P2P packets are now marked when being queued into driver, and identified later without checking MAC address
223 * revised implementation of Wi-Fi Direct io controls.
227 * 1) do not use in-stack variable for beacon updating. (for MAUI porting)
228 * 2) extending scanning result to 64 instead of 48
232 * driver hook modifications corresponding to ioctl interface change.
236 * [Wi-Fi Direct] add framework for driver hooks
238 * 08 02 2010 jeffrey.chang
240 * 1) modify tx service thread to avoid busy looping
241 * 2) add spin lock declartion for linux build
243 * 07 23 2010 jeffrey.chang
247 * 07 22 2010 jeffrey.chang
249 * modify tx thread and remove some spinlock
251 * 07 19 2010 jeffrey.chang
253 * add security frame pending count
257 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
259 * 06 06 2010 kevin.huang
260 * [WPD00003832][MT6620 5931] Create driver base
261 * [MT6620 5931] Create driver base
264 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
265 * add ioctl to configure scan mode for p2p connection
268 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
269 * add cfg80211 interface, which is to replace WE, for further extension
272 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
273 * add ioctl framework for Wi-Fi Direct by reusing wireless extension ioctls as well
276 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
277 * p2p ioctls revised.
280 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
281 * add ioctl for controlling p2p scan phase parameters
284 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
285 * implement basic wi-fi direct framework
287 * 05 07 2010 jeffrey.chang
288 * [WPD00003826]Initial import for Linux port
289 * prevent supplicant accessing driver during resume
292 * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
293 * add basic framework for implementating P2P driver hook.
296 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
297 * change variable names for multiple physical link to match with coding convention
300 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
301 * identify BT Over Wi-Fi Security frame and mark it as 802.1X frame
304 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
305 * add multiple physical link support
307 * 04 27 2010 jeffrey.chang
308 * [WPD00003826]Initial import for Linux port
309 * 1) fix firmware download bug
310 * 2) remove query statistics for acelerating firmware download
312 * 04 27 2010 jeffrey.chang
313 * [WPD00003826]Initial import for Linux port
314 * follow Linux's firmware framework, and remove unused kal API
317 * [WPD00001943]Create WiFi test driver framework on WinXP
318 * surpress compiler warning
320 * 04 19 2010 jeffrey.chang
321 * [WPD00003826]Initial import for Linux port
322 * supporting power management
324 * 04 14 2010 jeffrey.chang
325 * [WPD00003826]Initial import for Linux port
326 * pvInformationBuffer and u4InformationBufferLength are no longer in glue
329 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
330 * add framework for BT-over-Wi-Fi support.
331 * * * * * * * * * * * * * * * * * * * * 1) prPendingCmdInfo is replaced by queue for multiple handler capability
332 * * * * * * * * * * * * * * * * * * * * 2) command sequence number is now increased atomically
333 * * * * * * * * * * * * * * * * * * * * 3) private data could be hold and taken use for other purpose
336 * [WPD00001943]Create WiFi test driver framework on WinXP
337 * rWlanInfo should be placed at adapter rather than glue due to most operations
338 * * * * * * * * * * are done in adapter layer.
340 * 04 06 2010 jeffrey.chang
341 * [WPD00003826]Initial import for Linux port
342 * Tag the packet for QoS on Tx path
344 * 04 06 2010 jeffrey.chang
345 * [WPD00003826]Initial import for Linux port
346 * (1)deliver the kalOidComplete status to upper layer
347 * * (2) fix spin lock
349 * 04 06 2010 jeffrey.chang
350 * [WPD00003826]Initial import for Linux port
351 * add timeout check in the kalOidComplete
353 * 04 06 2010 jeffrey.chang
354 * [WPD00003826]Initial import for Linux port
355 * improve none-glue code portability
358 * [WPD00001943]Create WiFi test driver framework on WinXP
359 * code refine: fgTestMode should be at adapter rather than glue due to the device/fw is also involved
362 * [WPD00001943]Create WiFi test driver framework on WinXP
363 * eliminate direct access for prGlueInfo->fgIsCardRemoved in non-glue layer
365 * 03 30 2010 jeffrey.chang
366 * [WPD00003826]Initial import for Linux port
367 * emulate NDIS Pending OID facility
369 * 03 26 2010 jeffrey.chang
370 * [WPD00003826]Initial import for Linux port
371 * [WPD00003826] Initial import for Linux port
372 * adding firmware download related data type
375 * [WPD00001943]Create WiFi test driver framework on WinXP
376 * 1) correct OID_802_11_CONFIGURATION with frequency setting behavior.
377 * * * * the frequency is used for adhoc connection only
378 * * * * 2) update with SD1 v0.9 CMD/EVENT documentation
381 * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
382 * add Bluetooth-over-Wifi frame header check
384 * 03 24 2010 jeffrey.chang
385 * [WPD00003826]Initial import for Linux port
386 * initial import for Linux port
387 ** \main\maintrunk.MT5921\30 2009-10-20 17:38:31 GMT mtk01090
388 ** Refine driver unloading and clean up procedure. Block requests, stop main thread and clean up queued requests, and then stop hw.
389 ** \main\maintrunk.MT5921\29 2009-10-08 10:33:33 GMT mtk01090
390 ** Avoid accessing private data of net_device directly. Replace with netdev_priv(). Add more checking for input parameters and pointers.
391 ** \main\maintrunk.MT5921\28 2009-09-28 20:19:26 GMT mtk01090
392 ** Add private ioctl to carry OID structures. Restructure public/private ioctl interfaces to Linux kernel.
393 ** \main\maintrunk.MT5921\27 2009-08-18 22:57:12 GMT mtk01090
394 ** Add Linux SDIO (with mmc core) support.
395 ** Add Linux 2.6.21, 2.6.25, 2.6.26.
396 ** Fix compile warning in Linux.
397 ** \main\maintrunk.MT5921\26 2009-07-06 21:42:25 GMT mtk01088
398 ** fixed the compiling error at linux
399 ** \main\maintrunk.MT5921\25 2009-07-06 20:51:46 GMT mtk01088
400 ** adding the wapi 1x ether type define
401 ** \main\maintrunk.MT5921\24 2009-06-23 23:19:18 GMT mtk01090
402 ** Add build option BUILD_USE_EEPROM and compile option CFG_SUPPORT_EXT_CONFIG for NVRAM support
403 ** \main\maintrunk.MT5921\23 2009-02-07 15:05:06 GMT mtk01088
404 ** add the privacy flag to ingo driver the supplicant selected ap's security
405 ** \main\maintrunk.MT5921\22 2009-02-05 15:34:09 GMT mtk01088
406 ** fixed the compiling error for using bits marco for only one parameter
407 ** \main\maintrunk.MT5921\21 2009-01-22 13:02:13 GMT mtk01088
408 ** data frame is or not 802.1x value share with tid, using the same reserved byte, provide the function to set and get
409 ** \main\maintrunk.MT5921\20 2008-10-24 12:04:16 GMT mtk01088
410 ** move the config.h from precomp.h to here for lint check
411 ** \main\maintrunk.MT5921\19 2008-09-22 23:19:02 GMT mtk01461
412 ** Update driver for code review
413 ** \main\maintrunk.MT5921\18 2008-09-05 17:25:13 GMT mtk01461
414 ** Update Driver for Code Review
415 ** \main\maintrunk.MT5921\17 2008-08-01 13:32:47 GMT mtk01084
416 ** Prevent redundent driver assertion in driver logic when BUS is detached
417 ** \main\maintrunk.MT5921\16 2008-05-30 14:41:43 GMT mtk01461
418 ** Remove WMM Assoc Flag in KAL
419 ** \main\maintrunk.MT5921\15 2008-05-29 14:16:25 GMT mtk01084
420 ** remoev un-used variable
421 ** \main\maintrunk.MT5921\14 2008-05-03 15:17:14 GMT mtk01461
422 ** Add Media Status variable in Glue Layer
423 ** \main\maintrunk.MT5921\13 2008-04-24 11:58:41 GMT mtk01461
424 ** change threshold to 256
425 ** \main\maintrunk.MT5921\12 2008-03-11 14:51:05 GMT mtk01461
426 ** Remove redundant GL_CONN_INFO_T
427 ** \main\maintrunk.MT5921\11 2008-01-07 15:07:41 GMT mtk01461
428 ** Adjust the netif stop threshold to 150
429 ** \main\maintrunk.MT5921\10 2007-11-26 19:43:46 GMT mtk01461
430 ** Add OS_TIMESTAMP macro
432 ** \main\maintrunk.MT5921\9 2007-11-07 18:38:38 GMT mtk01461
434 ** \main\maintrunk.MT5921\8 2007-11-02 01:04:00 GMT mtk01461
435 ** Unify TX Path for Normal and IBSS Power Save + IBSS neighbor learning
436 ** Revision 1.5 2007/07/12 11:04:28 MTK01084
437 ** update macro to delay for ms order
439 ** Revision 1.4 2007/07/05 07:25:34 MTK01461
440 ** Add Linux initial code, modify doc, add 11BB, RF init code
442 ** Revision 1.3 2007/06/27 02:18:51 MTK01461
443 ** Update SCAN_FSM, Initial(Can Load Module), Proc(Can do Reg R/W), TX API
445 ** Revision 1.2 2007/06/25 06:16:24 MTK01461
446 ** Update illustrations, gl_init.c, gl_kal.c, gl_kal.h, gl_os.h and RX API
453 /*******************************************************************************
454 * C O M P I L E R F L A G S
455 ********************************************************************************
457 /*------------------------------------------------------------------------------
458 * Flags for LINUX(OS) dependent
459 *------------------------------------------------------------------------------
461 #define CFG_MAX_WLAN_DEVICES 1 /* number of wlan card will coexist*/
463 #define CFG_MAX_TXQ_NUM 4 /* number of tx queue for support multi-queue h/w */
466 #define CFG_USE_SPIN_LOCK_BOTTOM_HALF 0 /* 1: Enable use of SPIN LOCK Bottom Half for LINUX
467 0: Disable - use SPIN LOCK IRQ SAVE instead */
469 #define CFG_TX_PADDING_SMALL_ETH_PACKET 0 /* 1: Enable - Drop ethernet packet if it < 14 bytes.
470 And pad ethernet packet with dummy 0 if it < 60 bytes.
473 #define CFG_TX_STOP_NETIF_QUEUE_THRESHOLD 256 /* packets */
475 #define CFG_TX_STOP_NETIF_PER_QUEUE_THRESHOLD 64 /* packets */
476 #define CFG_TX_START_NETIF_PER_QUEUE_THRESHOLD 32 /* packets */
479 #define ETH_P_1X 0x888E
480 #define IPTOS_PREC_OFFSET 5
481 #define USER_PRIORITY_DEFAULT 0
483 #define ETH_WPI_1X 0x88B4
486 #define ETH_TYPE_LEN_OFFSET 12
487 #define ETH_P_IP 0x0800
488 #define ETH_P_1X 0x888E
489 #define ETH_P_PRE_1X 0x88C7
492 #define IP_HEADER_LEN 20
494 #define IPVH_VERSION_OFFSET 4 // For Little-Endian
495 #define IPVH_VERSION_MASK 0xF0
496 #define IPTOS_PREC_OFFSET 5
497 #define IPTOS_PREC_MASK 0xE0
499 #define SOURCE_PORT_LEN 2
500 /* NOTE(Kevin): Without IP Option Length */
501 #define LOOK_AHEAD_LEN (ETH_HLEN + IP_HEADER_LEN + SOURCE_PORT_LEN)
504 #define ETH_LLC_OFFSET (ETH_HLEN)
505 #define ETH_LLC_LEN 3
506 #define ETH_LLC_DSAP_SNAP 0xAA
507 #define ETH_LLC_SSAP_SNAP 0xAA
508 #define ETH_LLC_CONTROL_UNNUMBERED_INFORMATION 0x03
511 #define ETH_SNAP_OFFSET (ETH_HLEN + ETH_LLC_LEN)
512 #define ETH_SNAP_LEN 5
513 #define ETH_SNAP_BT_SIG_OUI_0 0x00
514 #define ETH_SNAP_BT_SIG_OUI_1 0x19
515 #define ETH_SNAP_BT_SIG_OUI_2 0x58
517 #define BOW_PROTOCOL_ID_SECURITY_FRAME 0x0003
521 #define DRV_NAME "[MT6620]: "
522 #elif defined(MT5931)
523 #define DRV_NAME "[MT5931]: "
524 #elif defined(MT6628)
525 #define DRV_NAME "[MT6628]: "
528 /* Define if target platform is Android.
529 * It should already be defined in Android kernel source
531 #ifndef CONFIG_ANDROID
532 #define CONFIG_ANDROID 0
535 /*******************************************************************************
536 * E X T E R N A L R E F E R E N C E S
537 ********************************************************************************
539 #include <linux/version.h> /* constant of kernel version */
541 #include <linux/kernel.h> /* bitops.h */
543 #include <linux/timer.h> /* struct timer_list */
544 #include <linux/jiffies.h> /* jiffies */
545 #include <linux/delay.h> /* udelay and mdelay macro */
548 #include <linux/wakelock.h>
551 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12)
552 #include <linux/irq.h> /* IRQT_FALLING */
555 #include <linux/netdevice.h> /* struct net_device, struct net_device_stats */
556 #include <linux/etherdevice.h> /* for eth_type_trans() function */
557 #include <linux/wireless.h> /* struct iw_statistics */
558 #include <linux/if_arp.h>
559 #include <linux/inetdevice.h> /* struct in_device */
561 #include <linux/ip.h> /* struct iphdr */
563 #include <linux/string.h> /* for memcpy()/memset() function */
564 #include <linux/stddef.h> /* for offsetof() macro */
566 #include <linux/proc_fs.h> /* The proc filesystem constants/structures */
568 #include <linux/rtnetlink.h> /* for rtnl_lock() and rtnl_unlock() */
569 #include <linux/kthread.h> /* kthread_should_stop(), kthread_run() */
570 #include <asm/uaccess.h> /* for copy_from_user() */
571 #include <linux/fs.h> /* for firmware download */
572 #include <linux/vmalloc.h>
574 #include <linux/kfifo.h> /* for kfifo interface */
575 #include <linux/cdev.h> /* for cdev interface */
577 #include <linux/firmware.h> /* for firmware download */
579 #if defined(_HIF_SDIO)
580 #include <linux/mmc/sdio.h>
581 #include <linux/mmc/sdio_func.h>
584 #include <linux/random.h>
587 #include <asm/io.h> /* readw and writew */
589 #if WIRELESS_EXT > 12
590 #include <net/iw_handler.h>
596 #if CFG_ENABLE_WIFI_DIRECT_CFG_80211
597 #include <linux/wireless.h>
598 #include <net/cfg80211.h>
601 #include "gl_typedef.h"
605 #if CFG_CHIP_RESET_SUPPORT
613 #include "wlan_lib.h"
614 #include "wlan_oid.h"
617 extern BOOLEAN fgIsBusAccessFailed;
619 /*******************************************************************************
621 ********************************************************************************
623 #define GLUE_FLAG_HALT BIT(0)
624 #define GLUE_FLAG_INT BIT(1)
625 #define GLUE_FLAG_OID BIT(2)
626 #define GLUE_FLAG_TIMEOUT BIT(3)
627 #define GLUE_FLAG_TXREQ BIT(4)
628 #define GLUE_FLAG_SUB_MOD_INIT BIT(5)
629 #define GLUE_FLAG_SUB_MOD_EXIT BIT(6)
630 #define GLUE_FLAG_SUB_MOD_MULTICAST BIT(7)
631 #define GLUE_FLAG_HALT_BIT (0)
632 #define GLUE_FLAG_INT_BIT (1)
633 #define GLUE_FLAG_OID_BIT (2)
634 #define GLUE_FLAG_TIMEOUT_BIT (3)
635 #define GLUE_FLAG_TXREQ_BIT (4)
636 #define GLUE_FLAG_SUB_MOD_INIT_BIT (5)
637 #define GLUE_FLAG_SUB_MOD_EXIT_BIT (6)
638 #define GLUE_FLAG_SUB_MOD_MULTICAST_BIT (7)
642 #define GLUE_BOW_KFIFO_DEPTH (1024)
643 //#define GLUE_BOW_DEVICE_NAME "MT6620 802.11 AMP"
644 #define GLUE_BOW_DEVICE_NAME "ampc0"
647 /*******************************************************************************
649 ********************************************************************************
651 typedef struct _GL_WPA_INFO_T {
652 UINT_32 u4WpaVersion;
654 UINT_32 u4CipherGroup;
655 UINT_32 u4CipherPairwise;
657 BOOLEAN fgPrivacyInvoke;
658 #if CFG_SUPPORT_802_11W
661 } GL_WPA_INFO_T, *P_GL_WPA_INFO_T;
663 typedef enum _ENUM_RSSI_TRIGGER_TYPE {
664 ENUM_RSSI_TRIGGER_NONE,
665 ENUM_RSSI_TRIGGER_GREATER,
666 ENUM_RSSI_TRIGGER_LESS,
667 ENUM_RSSI_TRIGGER_TRIGGERED,
668 ENUM_RSSI_TRIGGER_NUM
669 } ENUM_RSSI_TRIGGER_TYPE;
671 #if CFG_ENABLE_WIFI_DIRECT
672 typedef enum _ENUM_SUB_MODULE_IDX_T {
675 } ENUM_SUB_MODULE_IDX_T;
678 typedef struct _GL_IO_REQ_T {
679 QUE_ENTRY_T rQueEntry;
680 //wait_queue_head_t cmdwait_q;
683 #if CFG_ENABLE_WIFI_DIRECT
686 P_ADAPTER_T prAdapter;
687 PFN_OID_HANDLER_FUNC pfnOidHandler;
689 UINT_32 u4InfoBufLen;
690 PUINT_32 pu4QryInfoLen;
693 } GL_IO_REQ_T, *P_GL_IO_REQ_T;
695 #if CFG_ENABLE_BT_OVER_WIFI
696 typedef struct _GL_BOW_INFO {
697 BOOLEAN fgIsRegistered;
698 dev_t u4DeviceNumber; /* dynamic device number */
699 // struct kfifo *prKfifo; /* for buffering indicated events */
700 struct kfifo rKfifo; /* for buffering indicated events */
701 spinlock_t rSpinLock; /* spin lock for kfifo */
703 UINT_32 u4FreqInKHz; /* frequency */
705 UINT_8 aucRole[CFG_BOW_PHYSICAL_LINK_NUM]; /* 0: Responder, 1: Initiator */
706 ENUM_BOW_DEVICE_STATE aeState[CFG_BOW_PHYSICAL_LINK_NUM];
707 PARAM_MAC_ADDRESS arPeerAddr[CFG_BOW_PHYSICAL_LINK_NUM];
709 wait_queue_head_t outq;
711 #if CFG_BOW_SEPARATE_DATA_PATH
713 struct net_device *prDevHandler;
714 BOOLEAN fgIsNetRegistered;
717 } GL_BOW_INFO, *P_GL_BOW_INFO;
721 * type definition of pointer to p2p structure
723 typedef struct _GL_P2P_INFO_T GL_P2P_INFO_T, *P_GL_P2P_INFO_T;
725 struct _GLUE_INFO_T {
727 struct net_device *prDevHandler;
729 /* Device Index(index of arWlanDevInfo[]) */
732 /* Device statistics */
733 struct net_device_stats rNetDevStats;
735 /* Wireless statistics struct net_device */
736 struct iw_statistics rIwStats;
738 /* spinlock to sync power save mechanism */
739 spinlock_t rSpinLock[SPIN_LOCK_NUM];
741 /* semaphore for ioctl */
742 struct semaphore ioctl_sem;
744 UINT_32 u4Flag; /* GLUE_FLAG_XXX */
746 //UINT_32 u4TimeoutFlag;
747 UINT_32 u4ReadyFlag; /* check if card is ready */
749 /* Number of pending frames, also used for debuging if any frame is
750 * missing during the process of unloading Driver.
752 * NOTE(Kevin): In Linux, we also use this variable as the threshold
753 * for manipulating the netif_stop(wake)_queue() func.
755 INT_32 ai4TxPendingFrameNumPerQueue[4][CFG_MAX_TXQ_NUM];
756 INT_32 i4TxPendingFrameNum;
757 INT_32 i4TxPendingSecurityFrameNum;
759 /* current IO request for kalIoctl */
760 GL_IO_REQ_T OidEntry;
766 struct firmware *prFw;
768 /* Host interface related information */
769 /* defined in related hif header file */
770 GL_HIF_INFO_T rHifInfo;
772 /*! \brief wext wpa related information */
773 GL_WPA_INFO_T rWpaInfo;
776 /* Pointer to ADAPTER_T - main data structure of internal protocol stack */
777 P_ADAPTER_T prAdapter;
779 #ifdef WLAN_INCLUDE_PROC
780 struct proc_dir_entry *pProcRoot;
781 #endif /* WLAN_INCLUDE_PROC */
783 /* Indicated media state */
784 ENUM_PARAM_MEDIA_STATE_T eParamMediaStateIndicated;
786 /* Device power state D0~D3 */
787 PARAM_DEVICE_POWER_STATE ePowerState;
789 struct completion rScanComp; /* indicate scan complete */
790 struct completion rHaltComp; /* indicate main thread halt complete */
791 struct completion rPendComp; /* indicate main thread halt complete */
792 #if CFG_ENABLE_WIFI_DIRECT
793 struct completion rSubModComp; /*indicate sub module init or exit complete*/
795 WLAN_STATUS rPendStatus;
802 //PVOID pvInformationBuffer;
803 //UINT_32 u4InformationBufferLength;
805 //PUINT_8 pucIOReqBuff;
807 //QUE_T rFreeIOReqQueue;
809 wait_queue_head_t waitq;
810 struct task_struct *main_thread;
812 struct timer_list tickfn;
815 #if CFG_SUPPORT_EXT_CONFIG
816 UINT_16 au2ExtCfg[256]; /* NVRAM data buffer */
817 UINT_32 u4ExtCfgLength; /* 0 means data is NOT valid */
820 #if 1//CFG_SUPPORT_WAPI
821 /* Should be large than the PARAM_WAPI_ASSOC_INFO_T */
822 UINT_8 aucWapiAssocInfoIEs[42];
823 UINT_16 u2WapiAssocInfoIESz;
826 #if CFG_ENABLE_BT_OVER_WIFI
827 GL_BOW_INFO rBowInfo;
830 #if CFG_ENABLE_WIFI_DIRECT
831 P_GL_P2P_INFO_T prP2PInfo;
832 #if CFG_SUPPORT_P2P_RSSI_QUERY
833 /* Wireless statistics struct net_device */
834 struct iw_statistics rP2pIwStats;
838 UINT_8 aucWSCIE[500]; /*for probe req*/
840 UINT_8 aucWSCAssocInfoIE[200]; /*for Assoc req*/
841 UINT_16 u2WSCAssocInfoIELen;
843 /* NVRAM availability */
844 BOOLEAN fgNvramAvailable;
846 BOOLEAN fgMcrAccessAllowed;
848 /* MAC Address Overriden by IOCTL */
849 BOOLEAN fgIsMacAddrOverride;
850 PARAM_MAC_ADDRESS rMacAddrOverride;
852 SET_TXPWR_CTRL_T rTxPwr;
855 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
857 typedef void (*PFN_WLANISR)(int irq, void *dev_id, struct pt_regs *regs);
859 typedef irqreturn_t (*PFN_WLANISR)(int irq, void *dev_id, struct pt_regs *regs);
862 typedef void (*PFN_LINUX_TIMER_FUNC)(unsigned long);
865 /* generic sub module init/exit handler
866 * now, we only have one sub module, p2p
868 #if CFG_ENABLE_WIFI_DIRECT
869 typedef BOOLEAN (*SUB_MODULE_INIT)(P_GLUE_INFO_T prGlueInfo);
870 typedef BOOLEAN (*SUB_MODULE_EXIT)(P_GLUE_INFO_T prGlueInfo);
872 typedef struct _SUB_MODULE_HANDLER {
873 SUB_MODULE_INIT subModInit;
874 SUB_MODULE_EXIT subModExit;
876 } SUB_MODULE_HANDLER, *P_SUB_MODULE_HANDLER;
881 /*******************************************************************************
882 * P U B L I C D A T A
883 ********************************************************************************
886 /*******************************************************************************
887 * P R I V A T E D A T A
888 ********************************************************************************
891 /*******************************************************************************
893 ********************************************************************************
895 /*----------------------------------------------------------------------------*/
896 /* Macros of SPIN LOCK operations for using in Glue Layer */
897 /*----------------------------------------------------------------------------*/
898 #if CFG_USE_SPIN_LOCK_BOTTOM_HALF
899 #define GLUE_SPIN_LOCK_DECLARATION()
900 #define GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, rLockCategory) \
902 if (rLockCategory < SPIN_LOCK_NUM) \
903 spin_lock_bh(&(prGlueInfo->rSpinLock[rLockCategory])); \
905 #define GLUE_RELEASE_SPIN_LOCK(prGlueInfo, rLockCategory) \
907 if (rLockCategory < SPIN_LOCK_NUM) \
908 spin_unlock_bh(&(prGlueInfo->rSpinLock[rLockCategory])); \
910 #else /* !CFG_USE_SPIN_LOCK_BOTTOM_HALF */
911 #define GLUE_SPIN_LOCK_DECLARATION() UINT_32 __u4Flags = 0
912 #define GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, rLockCategory) \
914 if (rLockCategory < SPIN_LOCK_NUM) \
915 spin_lock_irqsave(&(prGlueInfo)->rSpinLock[rLockCategory], __u4Flags); \
917 #define GLUE_RELEASE_SPIN_LOCK(prGlueInfo, rLockCategory) \
919 if (rLockCategory < SPIN_LOCK_NUM) \
920 spin_unlock_irqrestore(&(prGlueInfo->rSpinLock[rLockCategory]), __u4Flags); \
922 #endif /* !CFG_USE_SPIN_LOCK_BOTTOM_HALF */
925 /*----------------------------------------------------------------------------*/
926 /* Macros for accessing Reserved Fields of native packet */
927 /*----------------------------------------------------------------------------*/
928 #define GLUE_GET_PKT_QUEUE_ENTRY(_p) \
929 (&( ((struct sk_buff *)(_p))->cb[0] ))
931 #define GLUE_GET_PKT_DESCRIPTOR(_prQueueEntry) \
932 ((P_NATIVE_PACKET) ((UINT_32)_prQueueEntry - offsetof(struct sk_buff, cb[0])) )
934 #define GLUE_SET_PKT_FLAG_802_11(_p) \
935 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(7))
937 #define GLUE_SET_PKT_FLAG_1X(_p) \
938 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(6))
940 #define GLUE_SET_PKT_FLAG_PAL(_p) \
941 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(5))
943 #define GLUE_SET_PKT_FLAG_P2P(_p) \
944 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= BIT(4))
948 #define GLUE_SET_PKT_TID(_p, _tid) \
949 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) |= (((UINT_8)((_tid) & (BITS(0,3))))))
952 #define GLUE_SET_PKT_FRAME_LEN(_p, _u2PayloadLen) \
953 (*((PUINT_16) &( ((struct sk_buff *)(_p))->cb[6] )) = (UINT_16)(_u2PayloadLen))
955 #define GLUE_GET_PKT_FRAME_LEN(_p) \
956 (*((PUINT_16) &( ((struct sk_buff *)(_p))->cb[6] )) )
959 #define GLUE_GET_PKT_IS_802_11(_p) \
960 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(7)))
962 #define GLUE_GET_PKT_IS_1X(_p) \
963 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(6)))
965 #define GLUE_GET_PKT_TID(_p) \
966 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BITS(0,3)))
969 #define GLUE_GET_PKT_IS_PAL(_p) \
970 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(5)))
972 #define GLUE_GET_PKT_IS_P2P(_p) \
973 ((*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[4] )) ) & (BIT(4)))
976 #define GLUE_SET_PKT_HEADER_LEN(_p, _ucMacHeaderLen) \
977 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[5] )) = (UINT_8)(_ucMacHeaderLen))
979 #define GLUE_GET_PKT_HEADER_LEN(_p) \
980 (*((PUINT_8) &( ((struct sk_buff *)(_p))->cb[5] )) )
982 #define GLUE_SET_PKT_ARRIVAL_TIME(_p, _rSysTime) \
983 (*((POS_SYSTIME) &( ((struct sk_buff *)(_p))->cb[8] )) = (OS_SYSTIME)(_rSysTime))
985 #define GLUE_GET_PKT_ARRIVAL_TIME(_p) \
986 (*((POS_SYSTIME) &( ((struct sk_buff *)(_p))->cb[8] )) )
988 /* Check validity of prDev, private data, and pointers */
989 #define GLUE_CHK_DEV(prDev) \
990 ((prDev && netdev_priv(prDev)) ? TRUE : FALSE)
992 #define GLUE_CHK_PR2(prDev, pr2) \
993 ((GLUE_CHK_DEV(prDev) && pr2) ? TRUE : FALSE)
995 #define GLUE_CHK_PR3(prDev, pr2, pr3) \
996 ((GLUE_CHK_PR2(prDev, pr2) && pr3) ? TRUE : FALSE)
998 #define GLUE_CHK_PR4(prDev, pr2, pr3, pr4) \
999 ((GLUE_CHK_PR3(prDev, pr2, pr3) && pr4) ? TRUE : FALSE)
1001 #define GLUE_SET_EVENT(pr) \
1004 #define GLUE_INC_REF_CNT(_refCount) atomic_inc((atomic_t *)&(_refCount))
1005 #define GLUE_DEC_REF_CNT(_refCount) atomic_dec((atomic_t *)&(_refCount))
1008 #define DbgPrint(...)
1009 /*******************************************************************************
1010 * F U N C T I O N D E C L A R A T I O N S
1011 ********************************************************************************
1013 #ifdef WLAN_INCLUDE_PROC
1016 struct net_device *prDev,
1022 struct net_device *prDev,
1025 #endif /* WLAN_INCLUDE_PROC */
1027 #if CFG_ENABLE_BT_OVER_WIFI
1030 P_GLUE_INFO_T prGlueInfo
1035 P_GLUE_INFO_T prGlueInfo
1039 #if CFG_ENABLE_WIFI_DIRECT
1043 P_GLUE_INFO_T prGlueInfo
1048 P_GLUE_INFO_T prGlueInfo
1053 P_GLUE_INFO_T prGlueInfo
1058 P_GLUE_INFO_T prGlueInfo
1062 wlanSubModRegisterInitExit(
1063 SUB_MODULE_INIT rSubModInit,
1064 SUB_MODULE_EXIT rSubModExit,
1065 ENUM_SUB_MODULE_IDX_T eSubModIdx
1070 P_GLUE_INFO_T *prGlueInfoExpAddr
1079 p2pSetMulticastListWorkQueueWrapper(
1080 P_GLUE_INFO_T prGlueInfo
1087 /*******************************************************************************
1089 ********************************************************************************
1092 #endif /* _GL_OS_H */