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