2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
34 --------- ---------- ----------------------------------------------
37 #ifndef __RT_LINUX_H__
38 #define __RT_LINUX_H__
40 #include <linux/module.h>
41 #include <linux/version.h>
42 #include <linux/kernel.h>
43 #include <linux/spinlock.h>
44 #include <linux/init.h>
45 #include <linux/string.h>
46 #include <linux/timer.h>
47 #include <linux/errno.h>
48 #include <linux/slab.h>
49 #include <linux/interrupt.h>
50 #include <linux/pci.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/skbuff.h>
54 #include <linux/ethtool.h>
55 #include <linux/wireless.h>
56 #include <linux/proc_fs.h>
57 #include <linux/delay.h>
58 #include <linux/if_arp.h>
59 #include <linux/ctype.h>
60 #include <linux/vmalloc.h>
61 #include <linux/wireless.h>
62 #include <net/iw_handler.h>
65 #include <asm/amazon_se/ifx_ppa_interface.h>
66 #include <asm/amazon_se/ifx_ppa_hook.h>
67 #endif // INF_AMAZON_PPA //
70 #define __KERNEL_SYSCALLS__
71 #include <linux/unistd.h>
72 #include <asm/uaccess.h>
73 #include <asm/types.h>
74 #include <asm/unaligned.h> // for get_unaligned()
76 #ifdef KTHREAD_SUPPORT
77 #include <linux/err.h>
78 #include <linux/kthread.h>
79 #endif // KTHREAD_SUPPORT //
81 #undef AP_WSC_INCLUDED
82 #undef STA_WSC_INCLUDED
86 #ifdef CONFIG_STA_SUPPORT
87 #endif // CONFIG_STA_SUPPORT //
90 #ifdef KTHREAD_SUPPORT
91 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4)
92 #error "This kerne version doesn't support kthread!!"
94 #endif // KTHREAD_SUPPORT //
96 /***********************************************************************************
97 * Profile related sections
98 ***********************************************************************************/
101 #ifdef CONFIG_STA_SUPPORT
103 #define STA_PROFILE_PATH "/etc/Wireless/RT2860STA/RT2860STA.dat"
104 #define STA_DRIVER_VERSION "2.1.0.0"
105 #ifdef MULTIPLE_CARD_SUPPORT
106 #define CARD_INFO_PATH "/etc/Wireless/RT2860STA/RT2860STACard.dat"
107 #endif // MULTIPLE_CARD_SUPPORT //
108 #endif // RTMP_MAC_PCI //
112 extern const struct iw_handler_def rt28xx_iw_handler_def
;
113 #endif // CONFIG_STA_SUPPORT //
115 #ifdef CONFIG_APSTA_MIXED_SUPPORT
116 extern const struct iw_handler_def rt28xx_ap_iw_handler_def
;
117 #endif // CONFIG_APSTA_MIXED_SUPPORT //
119 /***********************************************************************************
120 * Compiler related definitions
121 ***********************************************************************************/
123 #define __inline static inline
127 #define NDIS_STATUS INT
130 /***********************************************************************************
131 * OS Specific definitions and data structures
132 ***********************************************************************************/
133 typedef struct pci_dev
* PPCI_DEV
;
134 typedef struct net_device
* PNET_DEV
;
135 typedef void * PNDIS_PACKET
;
136 typedef char NDIS_PACKET
;
137 typedef PNDIS_PACKET
* PPNDIS_PACKET
;
138 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS
;
139 typedef dma_addr_t
* PNDIS_PHYSICAL_ADDRESS
;
140 typedef void * NDIS_HANDLE
;
141 typedef char * PNDIS_BUFFER
;
143 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
144 typedef struct pid
* RTMP_OS_PID
;
146 typedef pid_t RTMP_OS_PID
;
149 typedef struct semaphore RTMP_OS_SEM
;
153 #define PCI_DEVICE(vend,dev) \
154 .vendor = (vend), .device = (dev), \
155 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
156 #endif // PCI_DEVICE //
157 #endif // RTMP_MAC_PCI //
159 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
160 #define RT_MOD_INC_USE_COUNT() \
161 if (!try_module_get(THIS_MODULE)) \
163 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __FUNCTION__)); \
167 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
169 #define RT_MOD_INC_USE_COUNT() MOD_INC_USE_COUNT;
170 #define RT_MOD_DEC_USE_COUNT() MOD_DEC_USE_COUNT;
173 #define RTMP_INC_REF(_A) 0
174 #define RTMP_DEC_REF(_A) 0
175 #define RTMP_GET_REF(_A) 0
178 #if WIRELESS_EXT >= 12
179 // This function will be called when query /proc
180 struct iw_statistics
*rt28xx_get_wireless_stats(
181 IN
struct net_device
*net_dev
);
185 /***********************************************************************************
186 * Network related constant definitions
187 ***********************************************************************************/
192 #define ETH_LENGTH_OF_ADDRESS 6
194 #define NDIS_STATUS_SUCCESS 0x00
195 #define NDIS_STATUS_FAILURE 0x01
196 #define NDIS_STATUS_INVALID_DATA 0x02
197 #define NDIS_STATUS_RESOURCES 0x03
199 #define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
200 #define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
202 /* statistics counter */
203 #define STATS_INC_RX_PACKETS(_pAd, _dev)
204 #define STATS_INC_TX_PACKETS(_pAd, _dev)
206 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
207 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
209 #define STATS_INC_RX_ERRORS(_pAd, _dev)
210 #define STATS_INC_TX_ERRORS(_pAd, _dev)
212 #define STATS_INC_RX_DROPPED(_pAd, _dev)
213 #define STATS_INC_TX_DROPPED(_pAd, _dev)
216 /***********************************************************************************
217 * Ralink Specific network related constant definitions
218 ***********************************************************************************/
219 #define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
220 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
221 #define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
222 #define MIN_NET_DEVICE_FOR_APCLI 0x20
223 #define MIN_NET_DEVICE_FOR_MESH 0x30
224 #ifdef CONFIG_STA_SUPPORT
225 #define MIN_NET_DEVICE_FOR_DLS 0x40
226 #endif // CONFIG_STA_SUPPORT //
227 #define NET_DEVICE_REAL_IDX_MASK 0x0f // for each operation mode, we maximum support 15 entities.
230 #ifdef CONFIG_STA_SUPPORT
231 #define NDIS_PACKET_TYPE_DIRECTED 0
232 #define NDIS_PACKET_TYPE_MULTICAST 1
233 #define NDIS_PACKET_TYPE_BROADCAST 2
234 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
235 #define NDIS_PACKET_TYPE_PROMISCUOUS 4
236 #endif // CONFIG_STA_SUPPORT //
239 /***********************************************************************************
240 * OS signaling related constant definitions
241 ***********************************************************************************/
244 /***********************************************************************************
245 * OS file operation related data structure definitions
246 ***********************************************************************************/
247 typedef struct file
* RTMP_OS_FD
;
249 typedef struct _RTMP_OS_FS_INFO_
256 #define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
259 /***********************************************************************************
260 * OS semaphore related data structure and definitions
261 ***********************************************************************************/
267 typedef spinlock_t NDIS_SPIN_LOCK
;
270 // spin_lock enhanced for Nested spin lock
272 #define NdisAllocateSpinLock(__lock) \
274 spin_lock_init((spinlock_t *)(__lock)); \
277 #define NdisFreeSpinLock(lock) \
281 #define RTMP_SEM_LOCK(__lock) \
283 spin_lock_bh((spinlock_t *)(__lock)); \
286 #define RTMP_SEM_UNLOCK(__lock) \
288 spin_unlock_bh((spinlock_t *)(__lock)); \
292 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
293 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
296 spin_lock_bh((spinlock_t *)(__lock)); \
297 pAd->irq_disabled |= 1; \
300 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
302 pAd->irq_disabled &= 0; \
303 spin_unlock_bh((spinlock_t *)(__lock)); \
306 #define RTMP_INT_LOCK(__lock, __irqflags) \
308 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
311 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
313 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
316 #define NdisAcquireSpinLock RTMP_SEM_LOCK
317 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
319 #ifndef wait_event_interruptible_timeout
320 #define __wait_event_interruptible_timeout(wq, condition, ret) \
322 wait_queue_t __wait; \
323 init_waitqueue_entry(&__wait, current); \
324 add_wait_queue(&wq, &__wait); \
326 set_current_state(TASK_INTERRUPTIBLE); \
329 if (!signal_pending(current)) { \
330 ret = schedule_timeout(ret); \
335 ret = -ERESTARTSYS; \
338 current->state = TASK_RUNNING; \
339 remove_wait_queue(&wq, &__wait); \
342 #define wait_event_interruptible_timeout(wq, condition, timeout) \
344 long __ret = timeout; \
346 __wait_event_interruptible_timeout(wq, condition, __ret); \
351 #define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
352 #define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
353 #define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
354 #define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
356 #ifdef KTHREAD_SUPPORT
357 #define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
359 wait_event_interruptible(_pTask->kthread_q, \
360 _pTask->kthread_running || kthread_should_stop()); \
361 _pTask->kthread_running = FALSE; \
362 if (kthread_should_stop()) \
364 RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
370 #ifdef KTHREAD_SUPPORT
371 #define WAKE_UP(_pTask) \
373 if ((_pTask)->kthread_task) \
375 (_pTask)->kthread_running = TRUE; \
376 wake_up(&(_pTask)->kthread_q); \
381 /***********************************************************************************
382 * OS Memory Access related data structure and definitions
383 ***********************************************************************************/
384 #define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
386 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
387 #define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
388 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
389 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
390 #define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
391 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
392 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
394 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
395 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
397 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
400 /***********************************************************************************
401 * OS task related data structure and definitions
402 ***********************************************************************************/
403 #define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
405 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
406 typedef struct pid
* THREAD_PID
;
407 #define THREAD_PID_INIT_VALUE NULL
408 #define GET_PID(_v) find_get_pid((_v))
409 #define GET_PID_NUMBER(_v) pid_nr((_v))
410 #define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) >= 0)
411 #define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
413 typedef pid_t THREAD_PID
;
414 #define THREAD_PID_INIT_VALUE -1
415 #define GET_PID(_v) (_v)
416 #define GET_PID_NUMBER(_v) (_v)
417 #define CHECK_PID_LEGALITY(_pid) if ((_pid) >= 0)
418 #define KILL_THREAD_PID(_A, _B, _C) kill_proc((_A), (_B), (_C))
421 typedef struct tasklet_struct RTMP_NET_TASK_STRUCT
;
422 typedef struct tasklet_struct
*PRTMP_NET_TASK_STRUCT
;
425 /***********************************************************************************
426 * Timer related definitions and data structures.
427 **********************************************************************************/
430 typedef struct timer_list NDIS_MINIPORT_TIMER
;
431 typedef struct timer_list RTMP_OS_TIMER
;
432 typedef void (*TIMER_FUNCTION
)(unsigned long);
435 #define OS_WAIT(_time) \
437 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
438 wait_queue_head_t _wait; \
439 init_waitqueue_head(&_wait); \
440 for (_i=0; _i<(_loop); _i++) \
441 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
443 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
444 #define RTMP_TIME_AFTER(a,b) \
445 (typecheck(unsigned long, (unsigned long)a) && \
446 typecheck(unsigned long, (unsigned long)b) && \
447 ((long)(b) - (long)(a) < 0))
449 #define RTMP_TIME_AFTER_EQ(a,b) \
450 (typecheck(unsigned long, (unsigned long)a) && \
451 typecheck(unsigned long, (unsigned long)b) && \
452 ((long)(a) - (long)(b) >= 0))
453 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
455 #define typecheck(type,x) \
457 typeof(x) __dummy2; \
458 (void)(&__dummy == &__dummy2); \
461 #define RTMP_TIME_AFTER_EQ(a,b) \
462 (typecheck(unsigned long, (unsigned long)a) && \
463 typecheck(unsigned long, (unsigned long)b) && \
464 ((long)(a) - (long)(b) >= 0))
465 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
466 #define RTMP_TIME_AFTER(a,b) time_after(a, b)
471 static inline void NdisGetSystemUpTime(ULONG
*time
)
477 /***********************************************************************************
478 * OS specific cookie data structure binding to RTMP_ADAPTER
479 ***********************************************************************************/
483 struct pci_dev
*pci_dev
;
484 struct pci_dev
*parent_pci_dev
;
487 #endif // RTMP_MAC_PCI //
490 RTMP_NET_TASK_STRUCT rx_done_task
;
491 RTMP_NET_TASK_STRUCT mgmt_dma_done_task
;
492 RTMP_NET_TASK_STRUCT ac0_dma_done_task
;
493 RTMP_NET_TASK_STRUCT ac1_dma_done_task
;
494 RTMP_NET_TASK_STRUCT ac2_dma_done_task
;
495 RTMP_NET_TASK_STRUCT ac3_dma_done_task
;
496 /*RTMP_NET_TASK_STRUCT hcca_dma_done_task;*/
497 RTMP_NET_TASK_STRUCT tbtt_task
;
499 RTMP_NET_TASK_STRUCT fifo_statistic_full_task
;
500 #endif // RTMP_MAC_PCI //
504 unsigned long apd_pid
; //802.1x daemon pid
509 typedef struct os_cookie
* POS_COOKIE
;
513 /***********************************************************************************
514 * OS debugging and printing related definitions and data structure
515 ***********************************************************************************/
516 #define PRINT_MAC(addr) \
517 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
520 extern ULONG RTDebugLevel
;
522 #define DBGPRINT_RAW(Level, Fmt) \
524 if (Level <= RTDebugLevel) \
530 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
533 #define DBGPRINT_ERR(Fmt) \
535 printk("ERROR!!! "); \
539 #define DBGPRINT_S(Status, Fmt) \
544 #define DBGPRINT(Level, Fmt)
545 #define DBGPRINT_RAW(Level, Fmt)
546 #define DBGPRINT_S(Status, Fmt)
547 #define DBGPRINT_ERR(Fmt)
555 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
559 void hex_dump(char *str
, unsigned char *pSrcBufVA
, unsigned int SrcBufLen
);
562 /*********************************************************************************************************
563 The following code are not revised, temporary put it here.
564 *********************************************************************************************************/
567 /***********************************************************************************
568 * Device DMA Access related definitions and data structures.
569 **********************************************************************************/
571 dma_addr_t
linux_pci_map_single(void *handle
, void *ptr
, size_t size
, int sd_idx
, int direction
);
572 void linux_pci_unmap_single(void *handle
, dma_addr_t dma_addr
, size_t size
, int direction
);
574 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
575 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
577 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
578 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
580 #define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
581 pci_alloc_consistent(_pci_dev, _size, _ptr)
583 #define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
584 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
586 #define DEV_ALLOC_SKB(_length) \
587 dev_alloc_skb(_length)
588 #endif // RTMP_MAC_PCI //
594 * RTMP_GetPhysicalAddressLow(
595 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
597 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
601 * RTMP_GetPhysicalAddressHigh(
602 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
604 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
608 * RTMP_SetPhysicalAddressLow(
609 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
612 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
613 PhysicalAddress = Value;
617 * RTMP_SetPhysicalAddressHigh(
618 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
621 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
623 #define NdisMIndicateStatus(_w, _x, _y, _z)
627 /***********************************************************************************
628 * Device Register I/O Access related definitions and data structures.
629 **********************************************************************************/
631 #if defined(INF_TWINPASS) || defined(INF_DANUBE) || defined(IKANOS_VX_1X0)
632 //Patch for ASIC turst read/write bug, needs to remove after metel fix
633 #define RTMP_IO_READ32(_A, _R, _pV) \
635 if ((_A)->bPCIclkOff == FALSE) \
637 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
638 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
639 (*_pV = SWAP32(*((UINT32 *)(_pV)))); \
643 #define RTMP_IO_READ8(_A, _R, _pV) \
645 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
646 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
649 #define RTMP_IO_WRITE32(_A, _R, _V) \
651 if ((_A)->bPCIclkOff == FALSE) \
654 _Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
656 writel(_Val, (void *)((_A)->CSRBaseAddress + (_R))); \
660 #define RTMP_IO_WRITE8(_A, _R, _V) \
663 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
664 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
667 #define RTMP_IO_WRITE16(_A, _R, _V) \
670 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
671 writew(SWAP16((_V)), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
674 //Patch for ASIC turst read/write bug, needs to remove after metel fix
675 #define RTMP_IO_READ32(_A, _R, _pV) \
677 if ((_A)->bPCIclkOff == FALSE) \
679 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
680 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
686 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
688 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
689 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
692 #define RTMP_IO_READ8(_A, _R, _pV) \
694 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
695 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
698 #define RTMP_IO_WRITE32(_A, _R, _V) \
700 if ((_A)->bPCIclkOff == FALSE) \
703 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
704 writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
708 #define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
711 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
712 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
717 #if defined(BRCM_6358) || defined(RALINK_2880) || defined(RALINK_3052)
718 #define RTMP_IO_WRITE8(_A, _R, _V) \
723 Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
724 Val = Val & (~(0x000000ff << ((_i)*8))); \
725 Val = Val | ((ULONG)(_V) << ((_i)*8)); \
726 writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
729 #define RTMP_IO_WRITE8(_A, _R, _V) \
732 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
733 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
735 #endif // #if defined(BRCM_6358) || defined(RALINK_2880) //
737 #define RTMP_IO_WRITE16(_A, _R, _V) \
740 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
741 writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
743 #endif // #if defined(INF_TWINPASS) || defined(INF_DANUBE) || defined(IKANOS_VX_1X0) //
744 #endif // RTMP_MAC_PCI //
748 /***********************************************************************************
749 * Network Related data structure and marco definitions
750 ***********************************************************************************/
751 #define PKTSRC_NDIS 0x7f
752 #define PKTSRC_DRIVER 0x0f
755 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
756 #define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->priv = (_pPriv))
757 #define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->priv)
759 #define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
760 #define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
762 #define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
763 #define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
765 #define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
766 #define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
767 #define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
768 #define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
770 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
771 (PNDIS_PACKET)(pEntry)
773 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
774 (PQUEUE_ENTRY)(pPacket)
776 #ifdef CONFIG_5VT_ENHANCE
777 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
780 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
781 rt_get_sg_list_from_packet(_p, _sc)
783 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
785 RTMPFreeNdisPacket(_pAd, _pPacket); \
790 * - convert internal rt packet to os packet or
791 * os packet to rt packet
793 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
794 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
796 #define GET_OS_PKT_DATAPTR(_pkt) \
797 (RTPKT_TO_OSPKT(_pkt)->data)
798 #define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
799 (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
801 #define GET_OS_PKT_LEN(_pkt) \
802 (RTPKT_TO_OSPKT(_pkt)->len)
803 #define SET_OS_PKT_LEN(_pkt, _len) \
804 (RTPKT_TO_OSPKT(_pkt)->len) = (_len)
806 #define GET_OS_PKT_DATATAIL(_pkt) \
807 (RTPKT_TO_OSPKT(_pkt)->tail)
808 #define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
809 ((RTPKT_TO_OSPKT(_pkt))->tail) = (PUCHAR)((_start) + (_len))
811 #define GET_OS_PKT_HEAD(_pkt) \
812 (RTPKT_TO_OSPKT(_pkt)->head)
814 #define GET_OS_PKT_END(_pkt) \
815 (RTPKT_TO_OSPKT(_pkt)->end)
817 #define GET_OS_PKT_NETDEV(_pkt) \
818 (RTPKT_TO_OSPKT(_pkt)->dev)
819 #define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
820 (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
822 #define GET_OS_PKT_TYPE(_pkt) \
823 (RTPKT_TO_OSPKT(_pkt))
825 #define GET_OS_PKT_NEXT(_pkt) \
826 (RTPKT_TO_OSPKT(_pkt)->next)
829 #define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
831 #define OS_NTOHS(_Val) \
833 #define OS_HTONS(_Val) \
835 #define OS_NTOHL(_Val) \
837 #define OS_HTONL(_Val) \
843 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
844 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
847 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
848 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
850 // 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.
851 //(this value also as MAC(on-chip WCID) table index)
852 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
853 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
854 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
856 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
857 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
858 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
860 // RTS/CTS-to-self protection method
861 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
862 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
863 // see RTMP_S(G)ET_PACKET_EMACTAB
866 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
867 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
869 // From which Interface
870 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
871 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
872 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
873 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
874 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
875 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
876 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
877 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
879 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
880 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
887 // Sepcific Pakcet Type definition
889 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
891 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
892 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
893 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
894 #define RTMP_PACKET_SPECIFIC_WAI 0x08
895 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
896 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
899 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
902 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
905 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
907 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
909 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
912 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
915 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
917 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
919 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
922 #define RTMP_SET_PACKET_WAI(_p, _flg) \
925 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
927 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
929 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
931 #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))
934 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
937 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
939 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
941 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
944 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
947 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
949 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
952 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
955 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
958 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
960 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
963 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
966 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
967 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
968 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
972 /* use bit3 of cb[CB_OFF+16] */
974 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
975 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
978 /* [CB_OFF+28], 1B, Iverson patch for WMM A5-T07 ,WirelessStaToWirelessSta do not bulk out aggregate */
979 #define RTMP_SET_PACKET_NOBULKOUT(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+28] = _morebit)
980 #define RTMP_GET_PACKET_NOBULKOUT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+28])
981 #endif // INF_AMAZON_SE //
982 /* Max skb->cb = 48B = [CB_OFF+38] */
986 /***********************************************************************************
987 * Other function prototypes definitions
988 ***********************************************************************************/
989 void RTMP_GetCurrentSystemTime(LARGE_INTEGER
*time
);
990 int rt28xx_packet_xmit(struct sk_buff
*skb
);
993 void FlashWrite(UCHAR
* p
, ULONG a
, ULONG b
);
994 void FlashRead(UCHAR
* p
, ULONG a
, ULONG b
);
996 #if LINUX_VERSION_CODE <= 0x20402 // Red Hat 7.1
997 struct net_device
*alloc_netdev(int sizeof_priv
, const char *mask
, void (*setup
)(struct net_device
*));
998 #endif // LINUX_VERSION_CODE //
1002 /* function declarations */
1003 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1004 #define IRQ_HANDLE_TYPE irqreturn_t
1006 #define IRQ_HANDLE_TYPE void
1010 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
1011 rt2860_interrupt(int irq
, void *dev_instance
);
1013 rt2860_interrupt(int irq
, void *dev_instance
, struct pt_regs
*regs
);
1016 #endif // RTMP_MAC_PCI //
1019 IN PNET_DEV net_dev
,
1020 IN OUT
struct ifreq
*rq
,
1024 #ifdef CONFIG_STA_SUPPORT
1025 INT
rt28xx_sta_ioctl(
1026 IN PNET_DEV net_dev
,
1027 IN OUT
struct ifreq
*rq
,
1029 #endif // CONFIG_STA_SUPPORT //
1031 extern int ra_mtd_write(int num
, loff_t to
, size_t len
, const u_char
*buf
);
1032 extern int ra_mtd_read(int num
, loff_t from
, size_t len
, u_char
*buf
);
1034 #endif // __RT_LINUX_H__ //