Staging: rt3070: remove dead MULTIPLE_CARD_SUPPORT 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 #ifdef LEAP_SUPPORT
526 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
527 #endif
528 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
529 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
530 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
531 DECLARE_TIMER_FUNCTION(RadioOnExec);
532
533 #ifdef QOS_DLS_SUPPORT
534 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
535 #endif // QOS_DLS_SUPPORT //
536 #endif // CONFIG_STA_SUPPORT //
537
538 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
539
540
541 /*
542  * packet helper
543  *      - convert internal rt packet to os packet or
544  *             os packet to rt packet
545  */
546 #define RTPKT_TO_OSPKT(_p)              ((struct sk_buff *)(_p))
547 #define OSPKT_TO_RTPKT(_p)              ((PNDIS_PACKET)(_p))
548
549 #define GET_OS_PKT_DATAPTR(_pkt) \
550                 (RTPKT_TO_OSPKT(_pkt)->data)
551
552 #define GET_OS_PKT_LEN(_pkt) \
553                 (RTPKT_TO_OSPKT(_pkt)->len)
554
555 #define GET_OS_PKT_DATATAIL(_pkt) \
556                 (RTPKT_TO_OSPKT(_pkt)->tail)
557
558 #define GET_OS_PKT_HEAD(_pkt) \
559                 (RTPKT_TO_OSPKT(_pkt)->head)
560
561 #define GET_OS_PKT_END(_pkt) \
562                 (RTPKT_TO_OSPKT(_pkt)->end)
563
564 #define GET_OS_PKT_NETDEV(_pkt) \
565                 (RTPKT_TO_OSPKT(_pkt)->dev)
566
567 #define GET_OS_PKT_TYPE(_pkt) \
568                 (RTPKT_TO_OSPKT(_pkt))
569
570 #define GET_OS_PKT_NEXT(_pkt) \
571                 (RTPKT_TO_OSPKT(_pkt)->next)
572
573
574 #define OS_NTOHS(_Val) \
575                 (ntohs(_Val))
576 #define OS_HTONS(_Val) \
577                 (htons(_Val))
578 #define OS_NTOHL(_Val) \
579                 (ntohl(_Val))
580 #define OS_HTONL(_Val) \
581                 (htonl(_Val))
582
583 /* statistics counter */
584 #define STATS_INC_RX_PACKETS(_pAd, _dev)
585 #define STATS_INC_TX_PACKETS(_pAd, _dev)
586
587 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
588 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
589
590 #define STATS_INC_RX_ERRORS(_pAd, _dev)
591 #define STATS_INC_TX_ERRORS(_pAd, _dev)
592
593 #define STATS_INC_RX_DROPPED(_pAd, _dev)
594 #define STATS_INC_TX_DROPPED(_pAd, _dev)
595
596
597 #define CB_OFF  10
598
599
600 //   check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
601 //   ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
602 //
603 //#define RTMP_GET_PACKET_MR(_p)                        (RTPKT_TO_OSPKT(_p))
604
605 // User Priority
606 #define RTMP_SET_PACKET_UP(_p, _prio)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
607 #define RTMP_GET_PACKET_UP(_p)                                  (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
608
609 // Fragment #
610 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
611 #define RTMP_GET_PACKET_FRAGMENTS(_p)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
612
613 // 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.
614 //(this value also as MAC(on-chip WCID) table index)
615 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
616 #define RTMP_SET_PACKET_WCID(_p, _wdsidx)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
617 #define RTMP_GET_PACKET_WCID(_p)                        ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
618
619 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
620 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
621 #define RTMP_GET_PACKET_SOURCE(_p)                      (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
622
623 // RTS/CTS-to-self protection method
624 #define RTMP_SET_PACKET_RTS(_p, _num)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
625 #define RTMP_GET_PACKET_RTS(_p)                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
626 // see RTMP_S(G)ET_PACKET_EMACTAB
627
628 // TX rate index
629 #define RTMP_SET_PACKET_TXRATE(_p, _rate)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
630 #define RTMP_GET_PACKET_TXRATE(_p)                              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
631
632 // From which Interface
633 #define RTMP_SET_PACKET_IF(_p, _ifdx)           (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
634 #define RTMP_GET_PACKET_IF(_p)                          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
635 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)             RTMP_SET_PACKET_IF((_p), (_bss))
636 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss)                RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
637 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx)      RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
638 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx)       RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
639 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)                   RTMP_GET_PACKET_IF((_p))
640 #define RTMP_GET_PACKET_NET_DEVICE(_p)                                  RTMP_GET_PACKET_IF((_p))
641
642 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit)          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
643 #define RTMP_GET_PACKET_MOREDATA(_p)                            (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
644
645 //#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)   (RTPKT_TO_OSPKT(_p)->cb[8] = _bss)
646 //#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)         (RTPKT_TO_OSPKT(_p)->cb[8])
647
648 //
649 //      Sepcific Pakcet Type definition
650 //
651 #define RTMP_PACKET_SPECIFIC_CB_OFFSET  11
652
653 #define RTMP_PACKET_SPECIFIC_DHCP               0x01
654 #define RTMP_PACKET_SPECIFIC_EAPOL              0x02
655 #define RTMP_PACKET_SPECIFIC_IPV4               0x04
656 #define RTMP_PACKET_SPECIFIC_WAI                0x08
657 #define RTMP_PACKET_SPECIFIC_VLAN               0x10
658 #define RTMP_PACKET_SPECIFIC_LLCSNAP    0x20
659
660 //Specific
661 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
662
663 //DHCP
664 #define RTMP_SET_PACKET_DHCP(_p, _flg)                                                                                                          \
665                         do{                                                                                                                                                             \
666                                 if (_flg)                                                                                                                                       \
667                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP);             \
668                                 else                                                                                                                                            \
669                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP);    \
670                         }while(0)
671 #define RTMP_GET_PACKET_DHCP(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
672
673 //EAPOL
674 #define RTMP_SET_PACKET_EAPOL(_p, _flg)                                                                                                         \
675                         do{                                                                                                                                                             \
676                                 if (_flg)                                                                                                                                       \
677                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL);            \
678                                 else                                                                                                                                            \
679                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL);   \
680                         }while(0)
681 #define RTMP_GET_PACKET_EAPOL(_p)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
682
683 //WAI
684 #define RTMP_SET_PACKET_WAI(_p, _flg)                                                                                                           \
685                         do{                                                                                                                                                             \
686                                 if (_flg)                                                                                                                                       \
687                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI);              \
688                                 else                                                                                                                                            \
689                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI);     \
690                         }while(0)
691 #define RTMP_GET_PACKET_WAI(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
692
693 #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))
694
695 //VLAN
696 #define RTMP_SET_PACKET_VLAN(_p, _flg)                                                                                                          \
697                         do{                                                                                                                                                             \
698                                 if (_flg)                                                                                                                                       \
699                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN);             \
700                                 else                                                                                                                                            \
701                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN);    \
702                         }while(0)
703 #define RTMP_GET_PACKET_VLAN(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
704
705 //LLC/SNAP
706 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg)                                                                                                       \
707                         do{                                                                                                                                                             \
708                                 if (_flg)                                                                                                                                       \
709                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP);          \
710                                 else                                                                                                                                            \
711                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP);         \
712                         }while(0)
713
714 #define RTMP_GET_PACKET_LLCSNAP(_p)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
715
716 // IP
717 #define RTMP_SET_PACKET_IPV4(_p, _flg)                                                                                                          \
718                         do{                                                                                                                                                             \
719                                 if (_flg)                                                                                                                                       \
720                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4);             \
721                                 else                                                                                                                                            \
722                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4);    \
723                         }while(0)
724
725 #define RTMP_GET_PACKET_IPV4(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
726
727 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
728 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
729 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
730
731 #define RTMP_SET_PACKET_5VT(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
732 #define RTMP_GET_PACKET_5VT(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
733
734
735 #ifdef INF_AMAZON_SE
736 /*Iverson patch for WMM A5-T07 ,WirelessStaToWirelessSta do not bulk out aggregate */
737 #define RTMP_SET_PACKET_NOBULKOUT(_p, _morebit)                 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+23] = _morebit)
738 #define RTMP_GET_PACKET_NOBULKOUT(_p)                                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+23])
739 #endif // INF_AMAZON_SE //
740
741
742
743 #ifdef CONFIG_5VT_ENHANCE
744 #define BRIDGE_TAG 0x35564252    // depends on 5VT define in br_input.c
745 #endif
746
747
748 #define NDIS_SET_PACKET_STATUS(_p, _status)
749
750
751 #define GET_SG_LIST_FROM_PACKET(_p, _sc)        \
752     rt_get_sg_list_from_packet(_p, _sc)
753
754 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
755 #define NdisZeroMemory(Destination, Length)         memset(Destination, 0, Length)
756 #define NdisFillMemory(Destination, Length, Fill)   memset(Destination, Fill, Length)
757 #define NdisEqualMemory(Source1, Source2, Length)   (!memcmp(Source1, Source2, Length))
758 #define RTMPEqualMemory(Source1, Source2, Length)       (!memcmp(Source1, Source2, Length))
759
760
761 #define RTMP_INC_REF(_A)                0
762 #define RTMP_DEC_REF(_A)                0
763 #define RTMP_GET_REF(_A)                0
764
765
766
767 /*
768  * ULONG
769  * RTMP_GetPhysicalAddressLow(
770  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
771  */
772 #define RTMP_GetPhysicalAddressLow(PhysicalAddress)             (PhysicalAddress)
773
774 /*
775  * ULONG
776  * RTMP_GetPhysicalAddressHigh(
777  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
778  */
779 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress)            (0)
780
781 /*
782  * VOID
783  * RTMP_SetPhysicalAddressLow(
784  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
785  *   IN ULONG  Value);
786  */
787 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value)      \
788                         PhysicalAddress = Value;
789
790 /*
791  * VOID
792  * RTMP_SetPhysicalAddressHigh(
793  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
794  *   IN ULONG  Value);
795  */
796 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
797
798
799 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
800 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
801         (PNDIS_PACKET)(pEntry)
802
803 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
804         (PQUEUE_ENTRY)(pPacket)
805
806
807 #ifndef CONTAINING_RECORD
808 #define CONTAINING_RECORD(address, type, field)                 \
809 ((type *)((PCHAR)(address) - offsetof(type, field)))
810 #endif
811
812
813 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status)                    \
814 {                                                                       \
815         RTMPFreeNdisPacket(_pAd, _pPacket);                             \
816 }
817
818
819 #define SWITCH_PhyAB(_pAA, _pBB)    \
820 {                                                                           \
821     ULONG       AABasePaHigh;                           \
822     ULONG       AABasePaLow;                           \
823     ULONG       BBBasePaHigh;                           \
824     ULONG       BBBasePaLow;                           \
825     BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB);                                                 \
826     BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB);                                                 \
827     AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA);                                                 \
828     AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA);                                                 \
829     RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh);                                                 \
830     RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow);                                                 \
831     RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh);                                                 \
832     RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow);                                                 \
833 }
834
835
836 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
837 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e)           NDIS_STATUS_SUCCESS
838
839
840 #define NdisAcquireSpinLock             RTMP_SEM_LOCK
841 #define NdisReleaseSpinLock             RTMP_SEM_UNLOCK
842
843 static inline void NdisGetSystemUpTime(ULONG *time)
844 {
845         *time = jiffies;
846 }
847
848 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
849 #define QUEUE_ENTRY_TO_PKT(pEntry) \
850                 ((PNDIS_PACKET) (pEntry))
851
852 int rt28xx_packet_xmit(struct sk_buff *skb);
853
854
855
856 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
857
858
859