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