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