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