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