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