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