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