]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/staging/rt2860/rt_linux.h
f1686917e8322c9328eb7fc0691b26a09571f51e
[linux-2.6-omap-h63xx.git] / drivers / staging / rt2860 / rt_linux.h
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26  */
27
28 /***********************************************************************/
29 /*                                                                     */
30 /*   Program:    rt_linux.c                                            */
31 /*   Created:    4/21/2006 1:17:38 PM                                  */
32 /*   Author:     Wu Xi-Kun                                             */
33 /*   Comments:   `description`                                         */
34 /*                                                                     */
35 /*---------------------------------------------------------------------*/
36 /*                                                                     */
37 /* History:                                                            */
38 /*    Revision 1.1 4/21/2006 1:17:38 PM  xsikun                        */
39 /*    Initial revision                                                 */
40 /*                                                                     */
41 /***********************************************************************/
42
43 #include "rtmp_type.h"
44 #include <linux/module.h>
45 #include <linux/version.h>
46 #include <linux/kernel.h>
47
48 #include <linux/spinlock.h>
49 #include <linux/init.h>
50 #include <linux/string.h>
51 #include <linux/timer.h>
52 #include <linux/errno.h>
53 #include <linux/slab.h>
54 #include <linux/interrupt.h>
55 #include <linux/pci.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/skbuff.h>
59 #include <linux/ethtool.h>
60 #include <linux/wireless.h>
61 #include <linux/proc_fs.h>
62 #include <linux/delay.h>
63 #include <linux/if_arp.h>
64 #include <linux/ctype.h>
65 #include <linux/vmalloc.h>
66
67
68 #include <net/iw_handler.h>
69
70 // load firmware
71 #define __KERNEL_SYSCALLS__
72 #include <linux/unistd.h>
73 #include <asm/uaccess.h>
74
75
76 #define MEM_ALLOC_FLAG      (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
77
78 #ifndef IFNAMSIZ
79 #define IFNAMSIZ 16
80 #endif
81
82 //#define CONFIG_CKIP_SUPPORT
83
84 #undef __inline
85 #define __inline           static inline
86
87 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
88
89 // add by kathy
90
91 #ifdef CONFIG_STA_SUPPORT
92 #ifdef RT2860
93 #define STA_PROFILE_PATH                        "/etc/Wireless/RT2860STA/RT2860STA.dat"
94 #define STA_RTMP_FIRMWARE_FILE_NAME "/etc/Wireless/RT2860STA/RT2860STA.bin"
95 #define STA_NIC_DEVICE_NAME                     "RT2860STA"
96 #define STA_DRIVER_VERSION                      "1.8.0.0"
97 #ifdef MULTIPLE_CARD_SUPPORT
98 #define CARD_INFO_PATH                  "/etc/Wireless/RT2860STA/RT2860STACard.dat"
99 #endif // MULTIPLE_CARD_SUPPORT //
100 #endif // RT2860 //
101
102
103 #endif // CONFIG_STA_SUPPORT //
104
105 #ifdef RT2860
106 #ifndef PCI_DEVICE
107 #define PCI_DEVICE(vend,dev) \
108         .vendor = (vend), .device = (dev), \
109         .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
110 #endif // PCI_DEVICE //
111 #endif // RT2860 //
112
113 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
114
115 #define RTMP_TIME_AFTER(a,b)            \
116         (typecheck(unsigned long, (unsigned long)a) && \
117          typecheck(unsigned long, (unsigned long)b) && \
118          ((long)(b) - (long)(a) < 0))
119
120 #define RTMP_TIME_AFTER_EQ(a,b) \
121         (typecheck(unsigned long, (unsigned long)a) && \
122          typecheck(unsigned long, (unsigned long)b) && \
123          ((long)(a) - (long)(b) >= 0))
124 #define RTMP_TIME_BEFORE(a,b)   RTMP_TIME_AFTER_EQ(b,a)
125 #else
126 #define RTMP_TIME_AFTER(a,b) time_after(a, b)
127 #endif
128
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
130 #define RT_MOD_INC_USE_COUNT() \
131         if (!try_module_get(THIS_MODULE)) \
132         { \
133                 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
134                 return -1; \
135         }
136
137 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
138 #else
139 #define RT_MOD_INC_USE_COUNT()  MOD_INC_USE_COUNT;
140 #define RT_MOD_DEC_USE_COUNT() MOD_DEC_USE_COUNT;
141 #endif
142
143 #define OS_HZ                   HZ
144
145 #define ETH_LENGTH_OF_ADDRESS   6
146
147 #define IN
148 #define OUT
149
150 #define NDIS_STATUS                             INT
151 #define NDIS_STATUS_SUCCESS                     0x00
152 #define NDIS_STATUS_FAILURE                     0x01
153 #define NDIS_STATUS_INVALID_DATA                                0x02
154 #define NDIS_STATUS_RESOURCES                   0x03
155
156 #define MIN_NET_DEVICE_FOR_AID                  0x00            //0x00~0x3f
157 #define MIN_NET_DEVICE_FOR_MBSSID               0x00            //0x00,0x10,0x20,0x30
158 #define MIN_NET_DEVICE_FOR_WDS                  0x10            //0x40,0x50,0x60,0x70
159 #define MIN_NET_DEVICE_FOR_APCLI                0x20
160 #define MIN_NET_DEVICE_FOR_MESH                 0x30
161 #ifdef CONFIG_STA_SUPPORT
162 #define MIN_NET_DEVICE_FOR_DLS                  0x40
163 #endif // CONFIG_STA_SUPPORT //
164
165
166 #ifdef CONFIG_STA_SUPPORT
167 #define NDIS_PACKET_TYPE_DIRECTED               0
168 #define NDIS_PACKET_TYPE_MULTICAST              1
169 #define NDIS_PACKET_TYPE_BROADCAST              2
170 #define NDIS_PACKET_TYPE_ALL_MULTICAST  3
171 #endif // CONFIG_STA_SUPPORT //
172
173 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
174 typedef struct pid *    THREAD_PID;
175 #define THREAD_PID_INIT_VALUE   NULL
176 #define GET_PID(_v)     find_get_pid(_v)
177 #define GET_PID_NUMBER(_v)      pid_nr(_v)
178 #define CHECK_PID_LEGALITY(_pid)        if (pid_nr(_pid) >= 0)
179 #define KILL_THREAD_PID(_A, _B, _C)     kill_pid(_A, _B, _C)
180 #else
181 typedef pid_t   THREAD_PID;
182 #define THREAD_PID_INIT_VALUE   -1
183 #define GET_PID(_v)     _v
184 #define GET_PID_NUMBER(_v)      _v
185 #define CHECK_PID_LEGALITY(_pid)        if (_pid >= 0)
186 #define KILL_THREAD_PID(_A, _B, _C)     kill_proc(_A, _B, _C)
187 #endif
188
189 struct os_lock  {
190         spinlock_t              lock;
191         unsigned long   flags;
192 };
193
194
195 struct os_cookie {
196 #ifdef RT2860
197         struct pci_dev                  *pci_dev;
198         struct pci_dev                  *parent_pci_dev;
199         dma_addr_t                              pAd_pa;
200 #endif // RT2860 //
201
202
203         struct tasklet_struct   rx_done_task;
204         struct tasklet_struct   mgmt_dma_done_task;
205         struct tasklet_struct   ac0_dma_done_task;
206         struct tasklet_struct   ac1_dma_done_task;
207         struct tasklet_struct   ac2_dma_done_task;
208         struct tasklet_struct   ac3_dma_done_task;
209         struct tasklet_struct   hcca_dma_done_task;
210         struct tasklet_struct   tbtt_task;
211 #ifdef RT2860
212         struct tasklet_struct   fifo_statistic_full_task;
213 #endif // RT2860 //
214
215
216         unsigned long                   apd_pid; //802.1x daemon pid
217         INT                                             ioctl_if_type;
218         INT                                     ioctl_if;
219 };
220
221 typedef struct _VIRTUAL_ADAPTER
222 {
223         struct net_device               *RtmpDev;
224         struct net_device               *VirtualDev;
225 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
226
227 #undef  ASSERT
228 #define ASSERT(x)                                                               \
229 {                                                                               \
230     if (!(x))                                                                   \
231     {                                                                           \
232         printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__);    \
233     }                                                                           \
234 }
235
236 typedef struct os_cookie        * POS_COOKIE;
237 typedef struct pci_dev          * PPCI_DEV;
238 typedef struct net_device       * PNET_DEV;
239 typedef void                            * PNDIS_PACKET;
240 typedef char                            NDIS_PACKET;
241 typedef PNDIS_PACKET            * PPNDIS_PACKET;
242 typedef dma_addr_t                      NDIS_PHYSICAL_ADDRESS;
243 typedef dma_addr_t                      * PNDIS_PHYSICAL_ADDRESS;
244 typedef spinlock_t                      NDIS_SPIN_LOCK;
245 typedef struct timer_list       NDIS_MINIPORT_TIMER;
246 typedef void                            * NDIS_HANDLE;
247 typedef char                            * PNDIS_BUFFER;
248
249
250
251 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
252
253 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
254 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
255
256
257 ////////////////////////////////////////
258 // MOVE TO rtmp.h ?
259 /////////////////////////////////////////
260 #define PKTSRC_NDIS             0x7f
261 #define PKTSRC_DRIVER           0x0f
262 #define PRINT_MAC(addr) \
263         addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
264
265
266 #define RT2860_PCI_DEVICE_ID            0x0601
267
268 #ifdef RT2860
269 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
270         linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
271
272 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
273         linux_pci_unmap_single(_handle, _ptr, _size, _dir)
274
275 #define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
276         pci_alloc_consistent(_pci_dev, _size, _ptr)
277
278 #define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
279         pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
280
281 #define DEV_ALLOC_SKB(_length) \
282         dev_alloc_skb(_length)
283 #endif // RT2860 //
284
285
286
287 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size)       \
288         dma_cache_wback(_ptr, _size)
289
290
291 //////////////////////////////////////////
292 //
293 //////////////////////////////////////////
294
295
296 #define NdisMIndicateStatus(_w, _x, _y, _z)
297
298
299 typedef struct timer_list       RTMP_OS_TIMER;
300
301
302
303 typedef struct  _RALINK_TIMER_STRUCT    {
304     RTMP_OS_TIMER               TimerObj;       // Ndis Timer object
305         BOOLEAN                         Valid;                  // Set to True when call RTMPInitTimer
306     BOOLEAN             State;          // True if timer cancelled
307     BOOLEAN                     PeriodicType;   // True if timer is periodic timer
308     BOOLEAN             Repeat;         // True if periodic timer
309     ULONG               TimerValue;     // Timer value in milliseconds
310         ULONG                           cookie;                 // os specific object
311 }   RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
312
313
314
315
316 //#define DBG   1
317
318 //
319 //  MACRO for debugging information
320 //
321
322 #ifdef DBG
323 extern ULONG    RTDebugLevel;
324
325 #define DBGPRINT_RAW(Level, Fmt)    \
326 {                                   \
327     if (Level <= RTDebugLevel)      \
328     {                               \
329         printk Fmt;               \
330     }                               \
331 }
332
333 #define DBGPRINT(Level, Fmt)    DBGPRINT_RAW(Level, Fmt)
334
335
336 #define DBGPRINT_ERR(Fmt)           \
337 {                                   \
338     printk("ERROR!!! ");          \
339     printk Fmt;                  \
340 }
341
342 #define DBGPRINT_S(Status, Fmt)         \
343 {                                                                       \
344         printk Fmt;                                     \
345 }
346
347
348 #else
349 #define DBGPRINT(Level, Fmt)
350 #define DBGPRINT_RAW(Level, Fmt)
351 #define DBGPRINT_S(Status, Fmt)
352 #define DBGPRINT_ERR(Fmt)
353 #endif
354
355
356 //
357 //  spin_lock enhanced for Nested spin lock
358 //
359 #define NdisAllocateSpinLock(__lock)      \
360 {                                       \
361     spin_lock_init((spinlock_t *)(__lock));               \
362 }
363
364 #define NdisFreeSpinLock(lock)          \
365 {                                       \
366 }
367
368
369 #define RTMP_SEM_LOCK(__lock)                                   \
370 {                                                                                               \
371         spin_lock_bh((spinlock_t *)(__lock));                           \
372 }
373
374 #define RTMP_SEM_UNLOCK(__lock)                                 \
375 {                                                                                               \
376         spin_unlock_bh((spinlock_t *)(__lock));                         \
377 }
378
379 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
380 #define RTMP_IRQ_LOCK(__lock, __irqflags)                       \
381 {                                                                                                       \
382         __irqflags = 0;                                                                 \
383         spin_lock_bh((spinlock_t *)(__lock));                   \
384         pAd->irq_disabled |= 1; \
385 }
386
387 #define RTMP_IRQ_UNLOCK(__lock, __irqflag)                      \
388 {                                                                                                       \
389         pAd->irq_disabled &= 0; \
390         spin_unlock_bh((spinlock_t *)(__lock));                 \
391 }
392
393 #define RTMP_INT_LOCK(__lock, __irqflags)                       \
394 {                                                                                                       \
395         spin_lock_irqsave((spinlock_t *)__lock, __irqflags);    \
396 }
397
398 #define RTMP_INT_UNLOCK(__lock, __irqflag)                      \
399 {                                                                                                       \
400         spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag));     \
401 }
402
403 #ifdef RT2860
404 #if defined(INF_TWINPASS) || defined(INF_DANUBE) || defined(IKANOS_VX_1X0)
405 //Patch for ASIC turst read/write bug, needs to remove after metel fix
406 #define RTMP_IO_READ32(_A, _R, _pV)                                                                     \
407 {                                                                                                                                       \
408     if ((_A)->bPCIclkOff == FALSE)                                      \
409     {                                                                   \
410         (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)));              \
411         (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R))));                  \
412         (*_pV = SWAP32(*((UINT32 *)(_pV))));                           \
413     }                                                                   \
414 }
415 #define RTMP_IO_READ8(_A, _R, _pV)                                                                      \
416 {                                                                                                                                       \
417         (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)));              \
418         (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R))));                  \
419 }
420 #define RTMP_IO_WRITE32(_A, _R, _V)                                                                     \
421 {                                                                                                                                       \
422     if ((_A)->bPCIclkOff == FALSE)                                      \
423     {                                                                   \
424         UINT32  _Val;                                                                                                   \
425         _Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));                \
426         _Val = SWAP32(_V);                                                                                              \
427         writel(_Val, (void *)((_A)->CSRBaseAddress + (_R)));                    \
428     }                                                                   \
429 }
430 #define RTMP_IO_WRITE8(_A, _R, _V)                                                                      \
431 {                                                                                                                                       \
432         UINT    Val;                                                                                                    \
433         Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));         \
434         writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R)));                    \
435 }
436 #define RTMP_IO_WRITE16(_A, _R, _V)                                                                     \
437 {                                                                                                                                       \
438         UINT    Val;                                                                                                    \
439         Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));         \
440         writew(SWAP16((_V)), (PUSHORT)((_A)->CSRBaseAddress + (_R)));   \
441 }
442 #else
443 //Patch for ASIC turst read/write bug, needs to remove after metel fix
444 #define RTMP_IO_READ32(_A, _R, _pV)                                                             \
445 {                                                                                                                               \
446     if ((_A)->bPCIclkOff == FALSE)                                  \
447     {                                                               \
448                 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)));              \
449                 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R))));                  \
450     }                                                               \
451     else                                                                                                                        \
452                 *_pV = 0;                                                                                                       \
453 }
454 #define RTMP_IO_READ8(_A, _R, _pV)                                                              \
455 {                                                                                                                               \
456         (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)));                      \
457         (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R))));                          \
458 }
459 #define RTMP_IO_WRITE32(_A, _R, _V)                                                                                             \
460 {                                                                                                                                                               \
461     if ((_A)->bPCIclkOff == FALSE)                                  \
462     {                                                               \
463         UINT    Val;                                                                                                                            \
464         Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));                 \
465         writel(_V, (void *)((_A)->CSRBaseAddress + (_R)));                                                              \
466     }                                                               \
467 }
468 #if defined(BRCM_6358)
469 #define RTMP_IO_WRITE8(_A, _R, _V)            \
470 {                    \
471         ULONG Val;                \
472         UCHAR _i;                \
473         _i = (_R & 0x3);             \
474         Val = readl((void *)((_A)->CSRBaseAddress + (_R - _i)));   \
475         Val = Val & (~(0x000000ff << ((_i)*8)));         \
476         Val = Val | ((ULONG)_V << ((_i)*8));         \
477         writel((Val), (void *)((_A)->CSRBaseAddress + (_R - _i)));    \
478 }
479 #else
480 #define RTMP_IO_WRITE8(_A, _R, _V)                                                                                              \
481 {                                                                                                                                                               \
482         UINT    Val;                                                                                                                            \
483         Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));                 \
484         writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R)));            \
485 }
486 #endif
487 #define RTMP_IO_WRITE16(_A, _R, _V)                                                                                             \
488 {                                                                                                                                                               \
489         UINT    Val;                                                                                                                            \
490         Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0));                 \
491         writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R)));   \
492 }
493 #endif
494 #endif // RT2860 //
495
496
497 #ifndef wait_event_interruptible_timeout
498 #define __wait_event_interruptible_timeout(wq, condition, ret) \
499 do { \
500         wait_queue_t __wait; \
501         init_waitqueue_entry(&__wait, current); \
502         add_wait_queue(&wq, &__wait); \
503         for (;;) { \
504                 set_current_state(TASK_INTERRUPTIBLE); \
505                 if (condition) \
506                         break; \
507                 if (!signal_pending(current)) { \
508                         ret = schedule_timeout(ret); \
509                         if (!ret) \
510                                 break; \
511                         continue; \
512                 } \
513                 ret = -ERESTARTSYS; \
514                 break; \
515         } \
516         current->state = TASK_RUNNING; \
517         remove_wait_queue(&wq, &__wait); \
518 } while (0)
519
520 #define wait_event_interruptible_timeout(wq, condition, timeout) \
521 ({ \
522         long __ret = timeout; \
523         if (!(condition)) \
524                 __wait_event_interruptible_timeout(wq, condition, __ret); \
525         __ret; \
526 })
527 #endif
528 #define ONE_TICK 1
529 #define OS_WAIT(_time) \
530 {       int _i; \
531         long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
532         wait_queue_head_t _wait; \
533         init_waitqueue_head(&_wait); \
534         for (_i=0; _i<(_loop); _i++) \
535                 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
536
537
538 /* Modified by Wu Xi-Kun 4/21/2006 */
539 typedef void (*TIMER_FUNCTION)(unsigned long);
540
541 #define COPY_MAC_ADDR(Addr1, Addr2)             memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
542
543 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
544 #define MlmeFreeMemory(_pAd, _pVA)     os_free_mem(_pAd, _pVA)
545
546 #ifdef RT2860
547 #define BUILD_TIMER_FUNCTION(_func)                                                                                             \
548 void linux_##_func(unsigned long data)                                                                                  \
549 {                                                                                                                                                               \
550         PRALINK_TIMER_STRUCT    pTimer = (PRALINK_TIMER_STRUCT) data;                           \
551                                                                                                                                                                 \
552         _func(NULL, (PVOID) pTimer->cookie, NULL, pTimer);                                                      \
553         if (pTimer->Repeat)                                                                                                                     \
554                 RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue);                               \
555 }
556 #endif // RT2860 //
557
558
559
560 #define DECLARE_TIMER_FUNCTION(_func)                   \
561 void linux_##_func(unsigned long data)
562
563 #define GET_TIMER_FUNCTION(_func)                               \
564                 linux_##_func
565
566 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
567 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
568 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
569 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
570 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
571
572
573 #ifdef CONFIG_STA_SUPPORT
574 DECLARE_TIMER_FUNCTION(BeaconTimeout);
575 DECLARE_TIMER_FUNCTION(ScanTimeout);
576 DECLARE_TIMER_FUNCTION(AuthTimeout);
577 DECLARE_TIMER_FUNCTION(AssocTimeout);
578 DECLARE_TIMER_FUNCTION(ReassocTimeout);
579 DECLARE_TIMER_FUNCTION(DisassocTimeout);
580 DECLARE_TIMER_FUNCTION(LinkDownExec);
581 #ifdef LEAP_SUPPORT
582 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
583 #endif
584 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
585 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
586 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
587 DECLARE_TIMER_FUNCTION(RadioOnExec);
588
589 #ifdef QOS_DLS_SUPPORT
590 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
591 #endif // QOS_DLS_SUPPORT //
592 #endif // CONFIG_STA_SUPPORT //
593
594 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
595
596
597 /*
598  * packet helper
599  *      - convert internal rt packet to os packet or
600  *             os packet to rt packet
601  */
602 #define RTPKT_TO_OSPKT(_p)              ((struct sk_buff *)(_p))
603 #define OSPKT_TO_RTPKT(_p)              ((PNDIS_PACKET)(_p))
604
605 #define GET_OS_PKT_DATAPTR(_pkt) \
606                 (RTPKT_TO_OSPKT(_pkt)->data)
607
608 #define GET_OS_PKT_LEN(_pkt) \
609                 (RTPKT_TO_OSPKT(_pkt)->len)
610
611 #define GET_OS_PKT_DATATAIL(_pkt) \
612                 (RTPKT_TO_OSPKT(_pkt)->tail)
613
614 #define GET_OS_PKT_HEAD(_pkt) \
615                 (RTPKT_TO_OSPKT(_pkt)->head)
616
617 #define GET_OS_PKT_END(_pkt) \
618                 (RTPKT_TO_OSPKT(_pkt)->end)
619
620 #define GET_OS_PKT_NETDEV(_pkt) \
621                 (RTPKT_TO_OSPKT(_pkt)->dev)
622
623 #define GET_OS_PKT_TYPE(_pkt) \
624                 (RTPKT_TO_OSPKT(_pkt))
625
626 #define GET_OS_PKT_NEXT(_pkt) \
627                 (RTPKT_TO_OSPKT(_pkt)->next)
628
629
630 #define OS_NTOHS(_Val) \
631                 (ntohs(_Val))
632 #define OS_HTONS(_Val) \
633                 (htons(_Val))
634 #define OS_NTOHL(_Val) \
635                 (ntohl(_Val))
636 #define OS_HTONL(_Val) \
637                 (htonl(_Val))
638
639 /* statistics counter */
640 #define STATS_INC_RX_PACKETS(_pAd, _dev)
641 #define STATS_INC_TX_PACKETS(_pAd, _dev)
642
643 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
644 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
645
646 #define STATS_INC_RX_ERRORS(_pAd, _dev)
647 #define STATS_INC_TX_ERRORS(_pAd, _dev)
648
649 #define STATS_INC_RX_DROPPED(_pAd, _dev)
650 #define STATS_INC_TX_DROPPED(_pAd, _dev)
651
652
653 #define CB_OFF  10
654
655
656 //   check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
657 //   ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
658 //
659
660 // User Priority
661 #define RTMP_SET_PACKET_UP(_p, _prio)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
662 #define RTMP_GET_PACKET_UP(_p)                                  (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
663
664 // Fragment #
665 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
666 #define RTMP_GET_PACKET_FRAGMENTS(_p)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
667
668 // 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too.
669 //(this value also as MAC(on-chip WCID) table index)
670 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
671 #define RTMP_SET_PACKET_WCID(_p, _wdsidx)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
672 #define RTMP_GET_PACKET_WCID(_p)                        ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
673
674 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
675 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
676 #define RTMP_GET_PACKET_SOURCE(_p)                      (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
677
678 // RTS/CTS-to-self protection method
679 #define RTMP_SET_PACKET_RTS(_p, _num)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
680 #define RTMP_GET_PACKET_RTS(_p)                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
681 // see RTMP_S(G)ET_PACKET_EMACTAB
682
683 // TX rate index
684 #define RTMP_SET_PACKET_TXRATE(_p, _rate)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
685 #define RTMP_GET_PACKET_TXRATE(_p)                              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
686
687 // From which Interface
688 #define RTMP_SET_PACKET_IF(_p, _ifdx)           (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
689 #define RTMP_GET_PACKET_IF(_p)                          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
690 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)             RTMP_SET_PACKET_IF((_p), (_bss))
691 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss)                RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
692 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx)      RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
693 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx)       RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
694 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)                   RTMP_GET_PACKET_IF((_p))
695 #define RTMP_GET_PACKET_NET_DEVICE(_p)                                  RTMP_GET_PACKET_IF((_p))
696
697 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit)          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
698 #define RTMP_GET_PACKET_MOREDATA(_p)                            (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
699
700
701 #if 0
702 //#define RTMP_SET_PACKET_DHCP(_p, _flg)        (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
703 //#define RTMP_GET_PACKET_DHCP(_p)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
704 #else
705 //
706 //      Sepcific Pakcet Type definition
707 //
708 #define RTMP_PACKET_SPECIFIC_CB_OFFSET  11
709
710 #define RTMP_PACKET_SPECIFIC_DHCP               0x01
711 #define RTMP_PACKET_SPECIFIC_EAPOL              0x02
712 #define RTMP_PACKET_SPECIFIC_IPV4               0x04
713 #define RTMP_PACKET_SPECIFIC_WAI                0x08
714 #define RTMP_PACKET_SPECIFIC_VLAN               0x10
715 #define RTMP_PACKET_SPECIFIC_LLCSNAP    0x20
716
717 //Specific
718 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
719
720 //DHCP
721 #define RTMP_SET_PACKET_DHCP(_p, _flg)                                                                                                          \
722                         do{                                                                                                                                                             \
723                                 if (_flg)                                                                                                                                       \
724                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP);             \
725                                 else                                                                                                                                            \
726                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP);    \
727                         }while(0)
728 #define RTMP_GET_PACKET_DHCP(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
729
730 //EAPOL
731 #define RTMP_SET_PACKET_EAPOL(_p, _flg)                                                                                                         \
732                         do{                                                                                                                                                             \
733                                 if (_flg)                                                                                                                                       \
734                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL);            \
735                                 else                                                                                                                                            \
736                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL);   \
737                         }while(0)
738 #define RTMP_GET_PACKET_EAPOL(_p)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
739
740 //WAI
741 #define RTMP_SET_PACKET_WAI(_p, _flg)                                                                                                           \
742                         do{                                                                                                                                                             \
743                                 if (_flg)                                                                                                                                       \
744                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI);              \
745                                 else                                                                                                                                            \
746                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI);     \
747                         }while(0)
748 #define RTMP_GET_PACKET_WAI(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
749
750 #define RTMP_GET_PACKET_LOWRATE(_p)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI))
751
752 //VLAN
753 #define RTMP_SET_PACKET_VLAN(_p, _flg)                                                                                                          \
754                         do{                                                                                                                                                             \
755                                 if (_flg)                                                                                                                                       \
756                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN);             \
757                                 else                                                                                                                                            \
758                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN);    \
759                         }while(0)
760 #define RTMP_GET_PACKET_VLAN(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
761
762 //LLC/SNAP
763 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg)                                                                                                       \
764                         do{                                                                                                                                                             \
765                                 if (_flg)                                                                                                                                       \
766                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP);          \
767                                 else                                                                                                                                            \
768                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP);         \
769                         }while(0)
770
771 #define RTMP_GET_PACKET_LLCSNAP(_p)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
772
773 // IP
774 #define RTMP_SET_PACKET_IPV4(_p, _flg)                                                                                                          \
775                         do{                                                                                                                                                             \
776                                 if (_flg)                                                                                                                                       \
777                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4);             \
778                                 else                                                                                                                                            \
779                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4);    \
780                         }while(0)
781
782 #define RTMP_GET_PACKET_IPV4(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
783
784 #endif
785
786
787 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
788 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
789 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
790
791 #define RTMP_SET_PACKET_5VT(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
792 #define RTMP_GET_PACKET_5VT(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
793
794 #ifdef CONFIG_5VT_ENHANCE
795 #define BRIDGE_TAG 0x35564252    // depends on 5VT define in br_input.c
796 #endif
797
798
799 #define NDIS_SET_PACKET_STATUS(_p, _status)
800
801
802 #define GET_SG_LIST_FROM_PACKET(_p, _sc)        \
803     rt_get_sg_list_from_packet(_p, _sc)
804
805 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
806 #define NdisZeroMemory(Destination, Length)         memset(Destination, 0, Length)
807 #define NdisFillMemory(Destination, Length, Fill)   memset(Destination, Fill, Length)
808 #define NdisEqualMemory(Source1, Source2, Length)   (!memcmp(Source1, Source2, Length))
809 #define RTMPEqualMemory(Source1, Source2, Length)       (!memcmp(Source1, Source2, Length))
810
811
812 #define RTMP_INC_REF(_A)                0
813 #define RTMP_DEC_REF(_A)                0
814 #define RTMP_GET_REF(_A)                0
815
816
817
818 /*
819  * ULONG
820  * RTMP_GetPhysicalAddressLow(
821  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
822  */
823 #define RTMP_GetPhysicalAddressLow(PhysicalAddress)             (PhysicalAddress)
824
825 /*
826  * ULONG
827  * RTMP_GetPhysicalAddressHigh(
828  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
829  */
830 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress)            (0)
831
832 /*
833  * VOID
834  * RTMP_SetPhysicalAddressLow(
835  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
836  *   IN ULONG  Value);
837  */
838 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value)      \
839                         PhysicalAddress = Value;
840
841 /*
842  * VOID
843  * RTMP_SetPhysicalAddressHigh(
844  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
845  *   IN ULONG  Value);
846  */
847 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
848
849
850 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
851 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
852         (PNDIS_PACKET)(pEntry)
853
854 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
855         (PQUEUE_ENTRY)(pPacket)
856
857
858 #ifndef CONTAINING_RECORD
859 #define CONTAINING_RECORD(address, type, field)                 \
860 ((type *)((PCHAR)(address) - offsetof(type, field)))
861 #endif
862
863
864 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status)                    \
865 {                                                                       \
866         RTMPFreeNdisPacket(_pAd, _pPacket);                             \
867 }
868
869
870 #define SWITCH_PhyAB(_pAA, _pBB)    \
871 {                                                                           \
872     ULONG       AABasePaHigh;                           \
873     ULONG       AABasePaLow;                           \
874     ULONG       BBBasePaHigh;                           \
875     ULONG       BBBasePaLow;                           \
876     BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB);                                                 \
877     BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB);                                                 \
878     AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA);                                                 \
879     AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA);                                                 \
880     RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh);                                                 \
881     RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow);                                                 \
882     RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh);                                                 \
883     RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow);                                                 \
884 }
885
886
887 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
888 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e)           NDIS_STATUS_SUCCESS
889
890
891 #define NdisAcquireSpinLock             RTMP_SEM_LOCK
892 #define NdisReleaseSpinLock             RTMP_SEM_UNLOCK
893
894 static inline void NdisGetSystemUpTime(ULONG *time)
895 {
896         *time = jiffies;
897 }
898
899 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
900 #define QUEUE_ENTRY_TO_PKT(pEntry) \
901                 ((PNDIS_PACKET) (pEntry))
902
903 int rt28xx_packet_xmit(struct sk_buff *skb);
904
905
906
907 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
908
909 #ifdef RT2860
910 #if !defined(PCI_CAP_ID_EXP)
911 #define PCI_CAP_ID_EXP                      0x10
912 #endif
913
914 #if !defined(PCI_EXP_LNKCTL)
915 #define PCI_EXP_LNKCTL                      0x10
916 #endif
917
918 #if !defined(PCI_CLASS_BRIDGE_PCI)
919 #define PCI_CLASS_BRIDGE_PCI            0x0604
920 #endif
921
922 #define PCIBUS_INTEL_VENDOR         0x8086
923 #endif // RT2860 //
924
925