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