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