Staging: rt3070: remove kernel version compatibility wrappers
[linux-2.6] / drivers / staging / rt2870 / 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 #include <linux/kthread.h>
48
49 #include <linux/spinlock.h>
50 #include <linux/init.h>
51 #include <linux/string.h>
52 #include <linux/timer.h>
53 #include <linux/errno.h>
54 #include <linux/slab.h>
55 #include <linux/interrupt.h>
56 #include <linux/pci.h>
57 #include <linux/netdevice.h>
58 #include <linux/etherdevice.h>
59 #include <linux/skbuff.h>
60 #include <linux/ethtool.h>
61 #include <linux/wireless.h>
62 #include <linux/proc_fs.h>
63 #include <linux/delay.h>
64 #include <linux/if_arp.h>
65 #include <linux/ctype.h>
66 #include <linux/vmalloc.h>
67
68
69 #include <net/iw_handler.h>
70
71 // load firmware
72 #define __KERNEL_SYSCALLS__
73 #include <linux/unistd.h>
74 #include <asm/uaccess.h>
75
76
77 #define MEM_ALLOC_FLAG      (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
78
79 #ifndef IFNAMSIZ
80 #define IFNAMSIZ 16
81 #endif
82
83 //#define CONFIG_CKIP_SUPPORT
84
85 #undef __inline
86 #define __inline           static inline
87
88 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
89
90 // add by kathy
91
92 #ifdef CONFIG_STA_SUPPORT
93
94 #ifdef RT2870
95 #define STA_PROFILE_PATH                        "/etc/Wireless/RT2870STA/RT2870STA.dat"
96 #define STA_RT2870_IMAGE_FILE_NAME  "/etc/Wireless/RT2870STA/rt2870.bin"
97 #define STA_NIC_DEVICE_NAME                     "RT2870STA"
98 #define STA_DRIVER_VERSION                      "1.4.0.0"
99 #ifdef MULTIPLE_CARD_SUPPORT
100 #define CARD_INFO_PATH                  "/etc/Wireless/RT2870STA/RT2870STACard.dat"
101 #endif // MULTIPLE_CARD_SUPPORT //
102 #endif // RT2870 //
103
104 #endif // CONFIG_STA_SUPPORT //
105
106
107 #define RTMP_TIME_AFTER(a,b)            \
108         (typecheck(unsigned long, (unsigned long)a) && \
109          typecheck(unsigned long, (unsigned long)b) && \
110          ((long)(b) - (long)(a) < 0))
111
112 #define RTMP_TIME_AFTER_EQ(a,b) \
113         (typecheck(unsigned long, (unsigned long)a) && \
114          typecheck(unsigned long, (unsigned long)b) && \
115          ((long)(a) - (long)(b) >= 0))
116 #define RTMP_TIME_BEFORE(a,b)   RTMP_TIME_AFTER_EQ(b,a)
117
118 #define RT_MOD_INC_USE_COUNT() \
119         if (!try_module_get(THIS_MODULE)) \
120         { \
121                 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
122                 return -1; \
123         }
124
125 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
126
127 #define OS_HZ                   HZ
128
129 #define ETH_LENGTH_OF_ADDRESS   6
130
131 #define IN
132 #define OUT
133
134 #define NDIS_STATUS                             INT
135 #define NDIS_STATUS_SUCCESS                     0x00
136 #define NDIS_STATUS_FAILURE                     0x01
137 #define NDIS_STATUS_INVALID_DATA                                0x02
138 #define NDIS_STATUS_RESOURCES                   0x03
139
140 #define MIN_NET_DEVICE_FOR_AID                  0x00            //0x00~0x3f
141 #define MIN_NET_DEVICE_FOR_MBSSID               0x00            //0x00,0x10,0x20,0x30
142 #define MIN_NET_DEVICE_FOR_WDS                  0x10            //0x40,0x50,0x60,0x70
143 #define MIN_NET_DEVICE_FOR_APCLI                0x20
144 #define MIN_NET_DEVICE_FOR_MESH                 0x30
145 #ifdef CONFIG_STA_SUPPORT
146 #define MIN_NET_DEVICE_FOR_DLS                  0x40
147 #endif // CONFIG_STA_SUPPORT //
148
149
150 #ifdef CONFIG_STA_SUPPORT
151 #define NDIS_PACKET_TYPE_DIRECTED               0
152 #define NDIS_PACKET_TYPE_MULTICAST              1
153 #define NDIS_PACKET_TYPE_BROADCAST              2
154 #define NDIS_PACKET_TYPE_ALL_MULTICAST  3
155 #endif // CONFIG_STA_SUPPORT //
156
157 typedef struct pid *    THREAD_PID;
158 #define GET_PID(_v)     find_get_pid(_v)
159 #define GET_PID_NUMBER(_v)      pid_nr(_v)
160 #define CHECK_PID_LEGALITY(_pid)        if (pid_nr(_pid) >= 0)
161 #define KILL_THREAD_PID(_A, _B, _C)     kill_pid(_A, _B, _C)
162
163 struct os_lock  {
164         spinlock_t              lock;
165         unsigned long   flags;
166 };
167
168
169 struct os_cookie {
170
171 #ifdef RT2870
172         struct usb_device       *pUsb_Dev;
173
174         struct task_struct      *MLMEThr_task;
175         struct task_struct      *RTUSBCmdThr_task;
176         struct task_struct      *TimerQThr_task;
177 #endif // RT2870 //
178
179         struct tasklet_struct   rx_done_task;
180         struct tasklet_struct   mgmt_dma_done_task;
181         struct tasklet_struct   ac0_dma_done_task;
182         struct tasklet_struct   ac1_dma_done_task;
183         struct tasklet_struct   ac2_dma_done_task;
184         struct tasklet_struct   ac3_dma_done_task;
185         struct tasklet_struct   hcca_dma_done_task;
186         struct tasklet_struct   tbtt_task;
187 #ifdef RT2870
188         struct tasklet_struct   null_frame_complete_task;
189         struct tasklet_struct   rts_frame_complete_task;
190         struct tasklet_struct   pspoll_frame_complete_task;
191 #endif // RT2870 //
192
193
194         unsigned long                   apd_pid; //802.1x daemon pid
195         INT                                             ioctl_if_type;
196         INT                                     ioctl_if;
197 };
198
199 typedef struct _VIRTUAL_ADAPTER
200 {
201         struct net_device               *RtmpDev;
202         struct net_device               *VirtualDev;
203 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
204
205 #undef  ASSERT
206 #define ASSERT(x)                                                               \
207 {                                                                               \
208     if (!(x))                                                                   \
209     {                                                                           \
210         printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__);    \
211     }                                                                           \
212 }
213
214 typedef struct os_cookie        * POS_COOKIE;
215 typedef struct pci_dev          * PPCI_DEV;
216 typedef struct net_device       * PNET_DEV;
217 typedef void                            * PNDIS_PACKET;
218 typedef char                            NDIS_PACKET;
219 typedef PNDIS_PACKET            * PPNDIS_PACKET;
220 typedef dma_addr_t                      NDIS_PHYSICAL_ADDRESS;
221 typedef dma_addr_t                      * PNDIS_PHYSICAL_ADDRESS;
222 //typedef struct timer_list     RALINK_TIMER_STRUCT;
223 //typedef struct timer_list     * PRALINK_TIMER_STRUCT;
224 //typedef struct os_lock                NDIS_SPIN_LOCK;
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
250 #ifdef RT2870
251 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
252
253 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
254 #endif // RT2870 //
255
256
257 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size)       \
258         dma_cache_wback(_ptr, _size)
259
260
261 //////////////////////////////////////////
262 //
263 //////////////////////////////////////////
264
265
266 #define NdisMIndicateStatus(_w, _x, _y, _z)
267
268 typedef struct timer_list       RTMP_OS_TIMER;
269
270 #ifdef RT2870
271 /* ----------------- Timer Related MARCO ---------------*/
272 // In RT2870, we have a lot of timer functions and will read/write register, it's
273 //      not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
274 //  to ctrl pipe). So we need a wrapper function to take care it.
275
276 typedef VOID (*RT2870_TIMER_HANDLE)(
277         IN  PVOID   SystemSpecific1,
278         IN  PVOID   FunctionContext,
279         IN  PVOID   SystemSpecific2,
280         IN  PVOID   SystemSpecific3);
281 #endif // RT2870 //
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 #ifdef RT2870
293         RT2870_TIMER_HANDLE     handle;
294         void                            *pAd;
295 #endif // RT2870 //
296 }   RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
297
298
299 #ifdef RT2870
300
301 typedef enum _RT2870_KERNEL_THREAD_STATUS_
302 {
303         RT2870_THREAD_UNKNOWN = 0,
304         RT2870_THREAD_INITED = 1,
305         RT2870_THREAD_RUNNING = 2,
306         RT2870_THREAD_STOPED = 4,
307 }RT2870_KERNEL_THREAD_STATUS;
308
309 #define RT2870_THREAD_CAN_DO_INSERT             (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
310
311 typedef struct _RT2870_TIMER_ENTRY_
312 {
313         RALINK_TIMER_STRUCT                     *pRaTimer;
314         struct _RT2870_TIMER_ENTRY_     *pNext;
315 }RT2870_TIMER_ENTRY;
316
317
318 #define TIMER_QUEUE_SIZE_MAX    128
319 typedef struct _RT2870_TIMER_QUEUE_
320 {
321         unsigned int            status;
322         //wait_queue_head_t     timerWaitQ;
323         //atomic_t                      count;
324         UCHAR                           *pTimerQPoll;
325         RT2870_TIMER_ENTRY      *pQPollFreeList;
326         RT2870_TIMER_ENTRY      *pQHead;
327         RT2870_TIMER_ENTRY      *pQTail;
328 }RT2870_TIMER_QUEUE;
329 #endif // RT2870 //
330
331
332 //#define DBG   1
333
334 //
335 //  MACRO for debugging information
336 //
337
338 #ifdef DBG
339 extern ULONG    RTDebugLevel;
340
341 #define DBGPRINT_RAW(Level, Fmt)    \
342 {                                   \
343     if (Level <= RTDebugLevel)      \
344     {                               \
345         printk Fmt;               \
346     }                               \
347 }
348
349 #define DBGPRINT(Level, Fmt)    DBGPRINT_RAW(Level, Fmt)
350
351
352 #define DBGPRINT_ERR(Fmt)           \
353 {                                   \
354     printk("ERROR!!! ");          \
355     printk Fmt;                  \
356 }
357
358 #define DBGPRINT_S(Status, Fmt)         \
359 {                                                                       \
360         printk Fmt;                                     \
361 }
362
363
364 #else
365 #define DBGPRINT(Level, Fmt)
366 #define DBGPRINT_RAW(Level, Fmt)
367 #define DBGPRINT_S(Status, Fmt)
368 #define DBGPRINT_ERR(Fmt)
369 #endif
370
371
372 //
373 //  spin_lock enhanced for Nested spin lock
374 //
375 #define NdisAllocateSpinLock(__lock)      \
376 {                                       \
377     spin_lock_init((spinlock_t *)(__lock));               \
378 }
379
380 #define NdisFreeSpinLock(lock)          \
381 {                                       \
382 }
383
384
385 #define RTMP_SEM_LOCK(__lock)                                   \
386 {                                                                                               \
387         spin_lock_bh((spinlock_t *)(__lock));                           \
388 }
389
390 #define RTMP_SEM_UNLOCK(__lock)                                 \
391 {                                                                                               \
392         spin_unlock_bh((spinlock_t *)(__lock));                         \
393 }
394
395 #if 0 // sample, IRQ LOCK
396 #define RTMP_IRQ_LOCK(__lock, __irqflags)                                       \
397 {                                                                                                       \
398         spin_lock_irqsave((spinlock_t *)__lock, __irqflags);    \
399         pAd->irq_disabled |= 1; \
400 }
401
402 #define RTMP_IRQ_UNLOCK(__lock, __irqflag)                                              \
403 {                                                                                                               \
404         pAd->irq_disabled &= 0; \
405         spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag));     \
406 }
407 #else
408
409 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
410 #define RTMP_IRQ_LOCK(__lock, __irqflags)                       \
411 {                                                                                                       \
412         __irqflags = 0;                                                                 \
413         spin_lock_bh((spinlock_t *)(__lock));                   \
414         pAd->irq_disabled |= 1; \
415 }
416
417 #define RTMP_IRQ_UNLOCK(__lock, __irqflag)                      \
418 {                                                                                                       \
419         pAd->irq_disabled &= 0; \
420         spin_unlock_bh((spinlock_t *)(__lock));                 \
421 }
422
423 #define RTMP_INT_LOCK(__lock, __irqflags)                       \
424 {                                                                                                       \
425         spin_lock_irqsave((spinlock_t *)__lock, __irqflags);    \
426 }
427
428 #define RTMP_INT_UNLOCK(__lock, __irqflag)                      \
429 {                                                                                                       \
430         spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag));     \
431 }
432 #endif
433
434
435
436 #ifdef RT2870
437 //Patch for ASIC turst read/write bug, needs to remove after metel fix
438 #define RTMP_IO_READ32(_A, _R, _pV)                                                             \
439         RTUSBReadMACRegister(_A, _R, _pV)
440
441 #define RTMP_IO_READ8(_A, _R, _pV)                                                              \
442 {                                                                                                                               \
443 }
444
445 #define RTMP_IO_WRITE32(_A, _R, _V)                                                             \
446         RTUSBWriteMACRegister(_A, _R, _V)
447
448
449 #define RTMP_IO_WRITE8(_A, _R, _V)                                                              \
450 {                                                                                                                               \
451         USHORT  _Val = _V;                                                                                      \
452         RTUSBSingleWrite(_A, _R, _Val);                                                         \
453 }
454
455
456 #define RTMP_IO_WRITE16(_A, _R, _V)                                                             \
457 {                                                                                                                               \
458         RTUSBSingleWrite(_A, _R, _V);                                                           \
459 }
460 #endif // RT2870 //
461
462 #ifndef wait_event_interruptible_timeout
463 #define __wait_event_interruptible_timeout(wq, condition, ret) \
464 do { \
465         wait_queue_t __wait; \
466         init_waitqueue_entry(&__wait, current); \
467         add_wait_queue(&wq, &__wait); \
468         for (;;) { \
469                 set_current_state(TASK_INTERRUPTIBLE); \
470                 if (condition) \
471                         break; \
472                 if (!signal_pending(current)) { \
473                         ret = schedule_timeout(ret); \
474                         if (!ret) \
475                                 break; \
476                         continue; \
477                 } \
478                 ret = -ERESTARTSYS; \
479                 break; \
480         } \
481         current->state = TASK_RUNNING; \
482         remove_wait_queue(&wq, &__wait); \
483 } while (0)
484
485 #define wait_event_interruptible_timeout(wq, condition, timeout) \
486 ({ \
487         long __ret = timeout; \
488         if (!(condition)) \
489                 __wait_event_interruptible_timeout(wq, condition, __ret); \
490         __ret; \
491 })
492 #endif
493 #define ONE_TICK 1
494 #define OS_WAIT(_time) \
495 {       int _i; \
496         long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
497         wait_queue_head_t _wait; \
498         init_waitqueue_head(&_wait); \
499         for (_i=0; _i<(_loop); _i++) \
500                 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
501
502
503 typedef void (*TIMER_FUNCTION)(unsigned long);
504
505 #define COPY_MAC_ADDR(Addr1, Addr2)             memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
506
507 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
508 #define MlmeFreeMemory(_pAd, _pVA)     os_free_mem(_pAd, _pVA)
509
510
511 #ifdef RT2870
512 #define BUILD_TIMER_FUNCTION(_func)                                                                                                     \
513 void linux_##_func(unsigned long data)                                                                                          \
514 {                                                                                                                                                                       \
515         PRALINK_TIMER_STRUCT    _pTimer = (PRALINK_TIMER_STRUCT)data;                                   \
516         RT2870_TIMER_ENTRY              *_pQNode;                                                                                               \
517         RTMP_ADAPTER                    *_pAd;                                                                                                  \
518                                                                                                                                                                 \
519         _pTimer->handle = _func;                                                                                                                        \
520         _pAd = (RTMP_ADAPTER *)_pTimer->pAd;                                                                                            \
521         _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer);                                                                  \
522         if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT))   \
523                 RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ);                                                      \
524 }
525 #endif // RT2870 //
526
527
528 #define DECLARE_TIMER_FUNCTION(_func)                   \
529 void linux_##_func(unsigned long data)
530
531 #define GET_TIMER_FUNCTION(_func)                               \
532                 linux_##_func
533
534 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
535 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
536 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
537 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
538 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
539 #ifdef RT2870
540 DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
541 #endif // RT2870 //
542
543
544 #ifdef CONFIG_STA_SUPPORT
545 DECLARE_TIMER_FUNCTION(BeaconTimeout);
546 DECLARE_TIMER_FUNCTION(ScanTimeout);
547 DECLARE_TIMER_FUNCTION(AuthTimeout);
548 DECLARE_TIMER_FUNCTION(AssocTimeout);
549 DECLARE_TIMER_FUNCTION(ReassocTimeout);
550 DECLARE_TIMER_FUNCTION(DisassocTimeout);
551 DECLARE_TIMER_FUNCTION(LinkDownExec);
552 #ifdef LEAP_SUPPORT
553 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
554 #endif
555 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
556 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
557 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
558 DECLARE_TIMER_FUNCTION(RadioOnExec);
559
560 #ifdef QOS_DLS_SUPPORT
561 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
562 #endif // QOS_DLS_SUPPORT //
563 #endif // CONFIG_STA_SUPPORT //
564
565 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
566
567
568 /*
569  * packet helper
570  *      - convert internal rt packet to os packet or
571  *             os packet to rt packet
572  */
573 #define RTPKT_TO_OSPKT(_p)              ((struct sk_buff *)(_p))
574 #define OSPKT_TO_RTPKT(_p)              ((PNDIS_PACKET)(_p))
575
576 #define GET_OS_PKT_DATAPTR(_pkt) \
577                 (RTPKT_TO_OSPKT(_pkt)->data)
578
579 #define GET_OS_PKT_LEN(_pkt) \
580                 (RTPKT_TO_OSPKT(_pkt)->len)
581
582 #define GET_OS_PKT_DATATAIL(_pkt) \
583                 (RTPKT_TO_OSPKT(_pkt)->tail)
584
585 #define GET_OS_PKT_HEAD(_pkt) \
586                 (RTPKT_TO_OSPKT(_pkt)->head)
587
588 #define GET_OS_PKT_END(_pkt) \
589                 (RTPKT_TO_OSPKT(_pkt)->end)
590
591 #define GET_OS_PKT_NETDEV(_pkt) \
592                 (RTPKT_TO_OSPKT(_pkt)->dev)
593
594 #define GET_OS_PKT_TYPE(_pkt) \
595                 (RTPKT_TO_OSPKT(_pkt))
596
597 #define GET_OS_PKT_NEXT(_pkt) \
598                 (RTPKT_TO_OSPKT(_pkt)->next)
599
600
601 #define OS_NTOHS(_Val) \
602                 (ntohs(_Val))
603 #define OS_HTONS(_Val) \
604                 (htons(_Val))
605 #define OS_NTOHL(_Val) \
606                 (ntohl(_Val))
607 #define OS_HTONL(_Val) \
608                 (htonl(_Val))
609
610 /* statistics counter */
611 #define STATS_INC_RX_PACKETS(_pAd, _dev)
612 #define STATS_INC_TX_PACKETS(_pAd, _dev)
613
614 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
615 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
616
617 #define STATS_INC_RX_ERRORS(_pAd, _dev)
618 #define STATS_INC_TX_ERRORS(_pAd, _dev)
619
620 #define STATS_INC_RX_DROPPED(_pAd, _dev)
621 #define STATS_INC_TX_DROPPED(_pAd, _dev)
622
623
624 #define CB_OFF  10
625
626
627 //   check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
628 //   ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
629 //
630 //#define RTMP_GET_PACKET_MR(_p)                        (RTPKT_TO_OSPKT(_p))
631
632 // User Priority
633 #define RTMP_SET_PACKET_UP(_p, _prio)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
634 #define RTMP_GET_PACKET_UP(_p)                                  (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
635
636 // Fragment #
637 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
638 #define RTMP_GET_PACKET_FRAGMENTS(_p)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
639
640 // 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.
641 //(this value also as MAC(on-chip WCID) table index)
642 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
643 #define RTMP_SET_PACKET_WCID(_p, _wdsidx)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
644 #define RTMP_GET_PACKET_WCID(_p)                        ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
645
646 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
647 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
648 #define RTMP_GET_PACKET_SOURCE(_p)                      (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
649
650 // RTS/CTS-to-self protection method
651 #define RTMP_SET_PACKET_RTS(_p, _num)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
652 #define RTMP_GET_PACKET_RTS(_p)                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
653 // see RTMP_S(G)ET_PACKET_EMACTAB
654
655 // TX rate index
656 #define RTMP_SET_PACKET_TXRATE(_p, _rate)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
657 #define RTMP_GET_PACKET_TXRATE(_p)                              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
658
659 // From which Interface
660 #define RTMP_SET_PACKET_IF(_p, _ifdx)           (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
661 #define RTMP_GET_PACKET_IF(_p)                          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
662 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)             RTMP_SET_PACKET_IF((_p), (_bss))
663 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss)                RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
664 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx)      RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
665 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx)       RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
666 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)                   RTMP_GET_PACKET_IF((_p))
667 #define RTMP_GET_PACKET_NET_DEVICE(_p)                                  RTMP_GET_PACKET_IF((_p))
668
669 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit)          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
670 #define RTMP_GET_PACKET_MOREDATA(_p)                            (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
671
672 //#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)   (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
673 //#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)         (RTPKT_TO_OSPKT(_p)->cb[8])
674
675
676
677
678 #if 0
679 //#define RTMP_SET_PACKET_DHCP(_p, _flg)        (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
680 //#define RTMP_GET_PACKET_DHCP(_p)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
681 #else
682 //
683 //      Sepcific Pakcet Type definition
684 //
685 #define RTMP_PACKET_SPECIFIC_CB_OFFSET  11
686
687 #define RTMP_PACKET_SPECIFIC_DHCP               0x01
688 #define RTMP_PACKET_SPECIFIC_EAPOL              0x02
689 #define RTMP_PACKET_SPECIFIC_IPV4               0x04
690 #define RTMP_PACKET_SPECIFIC_WAI                0x08
691 #define RTMP_PACKET_SPECIFIC_VLAN               0x10
692 #define RTMP_PACKET_SPECIFIC_LLCSNAP    0x20
693
694 //Specific
695 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
696
697 //DHCP
698 #define RTMP_SET_PACKET_DHCP(_p, _flg)                                                                                                          \
699                         do{                                                                                                                                                             \
700                                 if (_flg)                                                                                                                                       \
701                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP);             \
702                                 else                                                                                                                                            \
703                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP);    \
704                         }while(0)
705 #define RTMP_GET_PACKET_DHCP(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
706
707 //EAPOL
708 #define RTMP_SET_PACKET_EAPOL(_p, _flg)                                                                                                         \
709                         do{                                                                                                                                                             \
710                                 if (_flg)                                                                                                                                       \
711                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL);            \
712                                 else                                                                                                                                            \
713                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL);   \
714                         }while(0)
715 #define RTMP_GET_PACKET_EAPOL(_p)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
716
717 //WAI
718 #define RTMP_SET_PACKET_WAI(_p, _flg)                                                                                                           \
719                         do{                                                                                                                                                             \
720                                 if (_flg)                                                                                                                                       \
721                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI);              \
722                                 else                                                                                                                                            \
723                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI);     \
724                         }while(0)
725 #define RTMP_GET_PACKET_WAI(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
726
727 #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))
728
729 //VLAN
730 #define RTMP_SET_PACKET_VLAN(_p, _flg)                                                                                                          \
731                         do{                                                                                                                                                             \
732                                 if (_flg)                                                                                                                                       \
733                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN);             \
734                                 else                                                                                                                                            \
735                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN);    \
736                         }while(0)
737 #define RTMP_GET_PACKET_VLAN(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
738
739 //LLC/SNAP
740 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg)                                                                                                       \
741                         do{                                                                                                                                                             \
742                                 if (_flg)                                                                                                                                       \
743                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP);          \
744                                 else                                                                                                                                            \
745                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP);         \
746                         }while(0)
747
748 #define RTMP_GET_PACKET_LLCSNAP(_p)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
749
750 // IP
751 #define RTMP_SET_PACKET_IPV4(_p, _flg)                                                                                                          \
752                         do{                                                                                                                                                             \
753                                 if (_flg)                                                                                                                                       \
754                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4);             \
755                                 else                                                                                                                                            \
756                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4);    \
757                         }while(0)
758
759 #define RTMP_GET_PACKET_IPV4(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
760
761 #endif
762
763
764 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
765 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
766 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
767
768 #define RTMP_SET_PACKET_5VT(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
769 #define RTMP_GET_PACKET_5VT(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
770
771
772 #ifdef CONFIG_5VT_ENHANCE
773 #define BRIDGE_TAG 0x35564252    // depends on 5VT define in br_input.c
774 #endif
775
776
777 #define NDIS_SET_PACKET_STATUS(_p, _status)
778
779
780 #define GET_SG_LIST_FROM_PACKET(_p, _sc)        \
781     rt_get_sg_list_from_packet(_p, _sc)
782
783
784 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
785 #define NdisZeroMemory(Destination, Length)         memset(Destination, 0, Length)
786 #define NdisFillMemory(Destination, Length, Fill)   memset(Destination, Fill, Length)
787 #define NdisEqualMemory(Source1, Source2, Length)   (!memcmp(Source1, Source2, Length))
788 #define RTMPEqualMemory(Source1, Source2, Length)       (!memcmp(Source1, Source2, Length))
789
790
791 #define RTMP_INC_REF(_A)                0
792 #define RTMP_DEC_REF(_A)                0
793 #define RTMP_GET_REF(_A)                0
794
795
796
797 /*
798  * ULONG
799  * RTMP_GetPhysicalAddressLow(
800  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
801  */
802 #define RTMP_GetPhysicalAddressLow(PhysicalAddress)             (PhysicalAddress)
803
804 /*
805  * ULONG
806  * RTMP_GetPhysicalAddressHigh(
807  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
808  */
809 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress)            (0)
810
811 /*
812  * VOID
813  * RTMP_SetPhysicalAddressLow(
814  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
815  *   IN ULONG  Value);
816  */
817 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value)      \
818                         PhysicalAddress = Value;
819
820 /*
821  * VOID
822  * RTMP_SetPhysicalAddressHigh(
823  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
824  *   IN ULONG  Value);
825  */
826 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
827
828
829 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
830 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
831         (PNDIS_PACKET)(pEntry)
832
833 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
834         (PQUEUE_ENTRY)(pPacket)
835
836
837 #ifndef CONTAINING_RECORD
838 #define CONTAINING_RECORD(address, type, field)                 \
839 ((type *)((PCHAR)(address) - offsetof(type, field)))
840 #endif
841
842
843 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status)                    \
844 {                                                                       \
845         RTMPFreeNdisPacket(_pAd, _pPacket);                             \
846 }
847
848
849 #define SWITCH_PhyAB(_pAA, _pBB)    \
850 {                                                                           \
851     ULONG       AABasePaHigh;                           \
852     ULONG       AABasePaLow;                           \
853     ULONG       BBBasePaHigh;                           \
854     ULONG       BBBasePaLow;                           \
855     BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB);                                                 \
856     BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB);                                                 \
857     AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA);                                                 \
858     AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA);                                                 \
859     RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh);                                                 \
860     RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow);                                                 \
861     RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh);                                                 \
862     RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow);                                                 \
863 }
864
865
866 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
867 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e)           NDIS_STATUS_SUCCESS
868
869
870 #define NdisAcquireSpinLock             RTMP_SEM_LOCK
871 #define NdisReleaseSpinLock             RTMP_SEM_UNLOCK
872
873 static inline void NdisGetSystemUpTime(ULONG *time)
874 {
875         *time = jiffies;
876 }
877
878 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
879 #define QUEUE_ENTRY_TO_PKT(pEntry) \
880                 ((PNDIS_PACKET) (pEntry))
881
882 int rt28xx_packet_xmit(struct sk_buff *skb);
883
884
885
886 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
887
888