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