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 *************************************************************************
28 /***********************************************************************/
30 /* Program: rt_linux.c */
31 /* Created: 4/21/2006 1:17:38 PM */
32 /* Author: Wu Xi-Kun */
33 /* Comments: `description` */
35 /*---------------------------------------------------------------------*/
38 /* Revision 1.1 4/21/2006 1:17:38 PM xsikun */
39 /* Initial revision */
41 /***********************************************************************/
43 #include "rtmp_type.h"
44 #include <linux/module.h>
45 #include <linux/version.h>
46 #include <linux/kernel.h>
48 #include <linux/spinlock.h>
49 #include <linux/init.h>
50 #include <linux/string.h>
51 #include <linux/timer.h>
52 #include <linux/errno.h>
53 #include <linux/slab.h>
54 #include <linux/interrupt.h>
55 #include <linux/pci.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/skbuff.h>
59 #include <linux/ethtool.h>
60 #include <linux/wireless.h>
61 #include <linux/proc_fs.h>
62 #include <linux/delay.h>
63 #include <linux/if_arp.h>
64 #include <linux/ctype.h>
65 #include <linux/vmalloc.h>
68 #include <net/iw_handler.h>
71 #define __KERNEL_SYSCALLS__
72 #include <linux/unistd.h>
73 #include <asm/uaccess.h>
76 #define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
82 //#define CONFIG_CKIP_SUPPORT
85 #define __inline static inline
87 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
91 #ifdef CONFIG_STA_SUPPORT
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 #ifdef MULTIPLE_CARD_SUPPORT
97 #define CARD_INFO_PATH "/etc/Wireless/RT2860STA/RT2860STACard.dat"
98 #endif // MULTIPLE_CARD_SUPPORT //
101 #endif // CONFIG_STA_SUPPORT //
104 #define PCI_DEVICE(vend,dev) \
105 .vendor = (vend), .device = (dev), \
106 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
107 #endif // PCI_DEVICE //
109 #define RTMP_TIME_AFTER(a,b) \
110 (typecheck(unsigned long, (unsigned long)a) && \
111 typecheck(unsigned long, (unsigned long)b) && \
112 ((long)(b) - (long)(a) < 0))
114 #define RTMP_TIME_AFTER_EQ(a,b) \
115 (typecheck(unsigned long, (unsigned long)a) && \
116 typecheck(unsigned long, (unsigned long)b) && \
117 ((long)(a) - (long)(b) >= 0))
118 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
120 #define RT_MOD_INC_USE_COUNT() \
121 if (!try_module_get(THIS_MODULE)) \
123 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
127 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
131 #define ETH_LENGTH_OF_ADDRESS 6
136 #define NDIS_STATUS INT
137 #define NDIS_STATUS_SUCCESS 0x00
138 #define NDIS_STATUS_FAILURE 0x01
139 #define NDIS_STATUS_INVALID_DATA 0x02
140 #define NDIS_STATUS_RESOURCES 0x03
142 #define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
143 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
144 #define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
145 #define MIN_NET_DEVICE_FOR_APCLI 0x20
146 #define MIN_NET_DEVICE_FOR_MESH 0x30
147 #ifdef CONFIG_STA_SUPPORT
148 #define MIN_NET_DEVICE_FOR_DLS 0x40
149 #endif // CONFIG_STA_SUPPORT //
152 #ifdef CONFIG_STA_SUPPORT
153 #define NDIS_PACKET_TYPE_DIRECTED 0
154 #define NDIS_PACKET_TYPE_MULTICAST 1
155 #define NDIS_PACKET_TYPE_BROADCAST 2
156 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
157 #endif // CONFIG_STA_SUPPORT //
159 typedef struct pid * THREAD_PID;
160 #define THREAD_PID_INIT_VALUE NULL
161 #define GET_PID(_v) find_get_pid(_v)
162 #define GET_PID_NUMBER(_v) pid_nr(_v)
163 #define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
164 #define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
173 struct pci_dev *pci_dev;
174 struct pci_dev *parent_pci_dev;
178 struct tasklet_struct rx_done_task;
179 struct tasklet_struct mgmt_dma_done_task;
180 struct tasklet_struct ac0_dma_done_task;
181 struct tasklet_struct ac1_dma_done_task;
182 struct tasklet_struct ac2_dma_done_task;
183 struct tasklet_struct ac3_dma_done_task;
184 struct tasklet_struct hcca_dma_done_task;
185 struct tasklet_struct tbtt_task;
186 struct tasklet_struct fifo_statistic_full_task;
189 unsigned long apd_pid; //802.1x daemon pid
194 typedef struct _VIRTUAL_ADAPTER
196 struct net_device *RtmpDev;
197 struct net_device *VirtualDev;
198 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
205 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
209 typedef struct os_cookie * POS_COOKIE;
210 typedef struct pci_dev * PPCI_DEV;
211 typedef struct net_device * PNET_DEV;
212 typedef void * PNDIS_PACKET;
213 typedef char NDIS_PACKET;
214 typedef PNDIS_PACKET * PPNDIS_PACKET;
215 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
216 typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
217 typedef spinlock_t NDIS_SPIN_LOCK;
218 typedef struct timer_list NDIS_MINIPORT_TIMER;
219 typedef void * NDIS_HANDLE;
220 typedef char * PNDIS_BUFFER;
224 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
226 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
227 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
230 ////////////////////////////////////////
232 /////////////////////////////////////////
233 #define PKTSRC_NDIS 0x7f
234 #define PKTSRC_DRIVER 0x0f
235 #define PRINT_MAC(addr) \
236 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
239 #define RT2860_PCI_DEVICE_ID 0x0601
241 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
242 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
244 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
245 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
247 #define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
248 pci_alloc_consistent(_pci_dev, _size, _ptr)
250 #define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
251 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
253 #define DEV_ALLOC_SKB(_length) \
254 dev_alloc_skb(_length)
258 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
259 dma_cache_wback(_ptr, _size)
262 //////////////////////////////////////////
264 //////////////////////////////////////////
267 #define NdisMIndicateStatus(_w, _x, _y, _z)
270 typedef struct timer_list RTMP_OS_TIMER;
274 typedef struct _RALINK_TIMER_STRUCT {
275 RTMP_OS_TIMER TimerObj; // Ndis Timer object
276 BOOLEAN Valid; // Set to True when call RTMPInitTimer
277 BOOLEAN State; // True if timer cancelled
278 BOOLEAN PeriodicType; // True if timer is periodic timer
279 BOOLEAN Repeat; // True if periodic timer
280 ULONG TimerValue; // Timer value in milliseconds
281 ULONG cookie; // os specific object
282 } RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
290 // MACRO for debugging information
294 extern ULONG RTDebugLevel;
296 #define DBGPRINT_RAW(Level, Fmt) \
298 if (Level <= RTDebugLevel) \
304 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
307 #define DBGPRINT_ERR(Fmt) \
309 printk("ERROR!!! "); \
313 #define DBGPRINT_S(Status, Fmt) \
320 #define DBGPRINT(Level, Fmt)
321 #define DBGPRINT_RAW(Level, Fmt)
322 #define DBGPRINT_S(Status, Fmt)
323 #define DBGPRINT_ERR(Fmt)
328 // spin_lock enhanced for Nested spin lock
330 #define NdisAllocateSpinLock(__lock) \
332 spin_lock_init((spinlock_t *)(__lock)); \
335 #define NdisFreeSpinLock(lock) \
340 #define RTMP_SEM_LOCK(__lock) \
342 spin_lock_bh((spinlock_t *)(__lock)); \
345 #define RTMP_SEM_UNLOCK(__lock) \
347 spin_unlock_bh((spinlock_t *)(__lock)); \
350 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
351 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
354 spin_lock_bh((spinlock_t *)(__lock)); \
355 pAd->irq_disabled |= 1; \
358 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
360 pAd->irq_disabled &= 0; \
361 spin_unlock_bh((spinlock_t *)(__lock)); \
364 #define RTMP_INT_LOCK(__lock, __irqflags) \
366 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
369 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
371 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
374 #if defined(INF_TWINPASS) || defined(INF_DANUBE) || defined(IKANOS_VX_1X0)
375 //Patch for ASIC turst read/write bug, needs to remove after metel fix
376 #define RTMP_IO_READ32(_A, _R, _pV) \
378 if ((_A)->bPCIclkOff == FALSE) \
380 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
381 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
382 (*_pV = SWAP32(*((UINT32 *)(_pV)))); \
385 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
387 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
388 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
389 (*_pV = SWAP32(*((UINT32 *)(_pV)))); \
391 #define RTMP_IO_READ8(_A, _R, _pV) \
393 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
394 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
396 #define RTMP_IO_WRITE32(_A, _R, _V) \
398 if ((_A)->bPCIclkOff == FALSE) \
401 _Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
403 writel(_Val, (void *)((_A)->CSRBaseAddress + (_R))); \
406 #define RTMP_IO_WRITE8(_A, _R, _V) \
409 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
410 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
412 #define RTMP_IO_WRITE16(_A, _R, _V) \
415 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
416 writew(SWAP16((_V)), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
419 //Patch for ASIC turst read/write bug, needs to remove after metel fix
420 #define RTMP_IO_READ32(_A, _R, _pV) \
422 if ((_A)->bPCIclkOff == FALSE) \
424 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
425 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
430 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
432 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
433 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
435 #define RTMP_IO_READ8(_A, _R, _pV) \
437 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
438 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
440 #define RTMP_IO_WRITE32(_A, _R, _V) \
442 if ((_A)->bPCIclkOff == FALSE) \
445 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
446 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
449 #if defined(BRCM_6358)
450 #define RTMP_IO_WRITE8(_A, _R, _V) \
455 Val = readl((void *)((_A)->CSRBaseAddress + (_R - _i))); \
456 Val = Val & (~(0x000000ff << ((_i)*8))); \
457 Val = Val | ((ULONG)_V << ((_i)*8)); \
458 writel((Val), (void *)((_A)->CSRBaseAddress + (_R - _i))); \
461 #define RTMP_IO_WRITE8(_A, _R, _V) \
464 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
465 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
468 #define RTMP_IO_WRITE16(_A, _R, _V) \
471 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
472 writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
477 #ifndef wait_event_interruptible_timeout
478 #define __wait_event_interruptible_timeout(wq, condition, ret) \
480 wait_queue_t __wait; \
481 init_waitqueue_entry(&__wait, current); \
482 add_wait_queue(&wq, &__wait); \
484 set_current_state(TASK_INTERRUPTIBLE); \
487 if (!signal_pending(current)) { \
488 ret = schedule_timeout(ret); \
493 ret = -ERESTARTSYS; \
496 current->state = TASK_RUNNING; \
497 remove_wait_queue(&wq, &__wait); \
500 #define wait_event_interruptible_timeout(wq, condition, timeout) \
502 long __ret = timeout; \
504 __wait_event_interruptible_timeout(wq, condition, __ret); \
509 #define OS_WAIT(_time) \
511 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
512 wait_queue_head_t _wait; \
513 init_waitqueue_head(&_wait); \
514 for (_i=0; _i<(_loop); _i++) \
515 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
518 /* Modified by Wu Xi-Kun 4/21/2006 */
519 typedef void (*TIMER_FUNCTION)(unsigned long);
521 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
523 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
524 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
526 #define BUILD_TIMER_FUNCTION(_func) \
527 void linux_##_func(unsigned long data) \
529 PRALINK_TIMER_STRUCT pTimer = (PRALINK_TIMER_STRUCT) data; \
531 _func(NULL, (PVOID) pTimer->cookie, NULL, pTimer); \
532 if (pTimer->Repeat) \
533 RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue); \
538 #define DECLARE_TIMER_FUNCTION(_func) \
539 void linux_##_func(unsigned long data)
541 #define GET_TIMER_FUNCTION(_func) \
544 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
545 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
546 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
547 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
548 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
551 #ifdef CONFIG_STA_SUPPORT
552 DECLARE_TIMER_FUNCTION(BeaconTimeout);
553 DECLARE_TIMER_FUNCTION(ScanTimeout);
554 DECLARE_TIMER_FUNCTION(AuthTimeout);
555 DECLARE_TIMER_FUNCTION(AssocTimeout);
556 DECLARE_TIMER_FUNCTION(ReassocTimeout);
557 DECLARE_TIMER_FUNCTION(DisassocTimeout);
558 DECLARE_TIMER_FUNCTION(LinkDownExec);
560 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
562 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
563 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
564 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
565 DECLARE_TIMER_FUNCTION(RadioOnExec);
567 #ifdef QOS_DLS_SUPPORT
568 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
569 #endif // QOS_DLS_SUPPORT //
570 #endif // CONFIG_STA_SUPPORT //
572 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
577 * - convert internal rt packet to os packet or
578 * os packet to rt packet
580 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
581 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
583 #define GET_OS_PKT_DATAPTR(_pkt) \
584 (RTPKT_TO_OSPKT(_pkt)->data)
586 #define GET_OS_PKT_LEN(_pkt) \
587 (RTPKT_TO_OSPKT(_pkt)->len)
589 #define GET_OS_PKT_DATATAIL(_pkt) \
590 (RTPKT_TO_OSPKT(_pkt)->tail)
592 #define GET_OS_PKT_HEAD(_pkt) \
593 (RTPKT_TO_OSPKT(_pkt)->head)
595 #define GET_OS_PKT_END(_pkt) \
596 (RTPKT_TO_OSPKT(_pkt)->end)
598 #define GET_OS_PKT_NETDEV(_pkt) \
599 (RTPKT_TO_OSPKT(_pkt)->dev)
601 #define GET_OS_PKT_TYPE(_pkt) \
602 (RTPKT_TO_OSPKT(_pkt))
604 #define GET_OS_PKT_NEXT(_pkt) \
605 (RTPKT_TO_OSPKT(_pkt)->next)
608 #define OS_NTOHS(_Val) \
610 #define OS_HTONS(_Val) \
612 #define OS_NTOHL(_Val) \
614 #define OS_HTONL(_Val) \
617 /* statistics counter */
618 #define STATS_INC_RX_PACKETS(_pAd, _dev)
619 #define STATS_INC_TX_PACKETS(_pAd, _dev)
621 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
622 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
624 #define STATS_INC_RX_ERRORS(_pAd, _dev)
625 #define STATS_INC_TX_ERRORS(_pAd, _dev)
627 #define STATS_INC_RX_DROPPED(_pAd, _dev)
628 #define STATS_INC_TX_DROPPED(_pAd, _dev)
634 // check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
635 // ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
639 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
640 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
643 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
644 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
646 // 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.
647 //(this value also as MAC(on-chip WCID) table index)
648 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
649 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
650 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
652 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
653 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
654 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
656 // RTS/CTS-to-self protection method
657 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
658 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
659 // see RTMP_S(G)ET_PACKET_EMACTAB
662 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
663 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
665 // From which Interface
666 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
667 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
668 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
669 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
670 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
671 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
672 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
673 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
675 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
676 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
680 //#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
681 //#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
684 // Sepcific Pakcet Type definition
686 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
688 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
689 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
690 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
691 #define RTMP_PACKET_SPECIFIC_WAI 0x08
692 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
693 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
696 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
699 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
702 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
704 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
706 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
709 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
712 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
714 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
716 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
719 #define RTMP_SET_PACKET_WAI(_p, _flg) \
722 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
724 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
726 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
728 #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))
731 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
734 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
736 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
738 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
741 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
744 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
746 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
749 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
752 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
755 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
757 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
760 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
765 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
766 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
767 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
769 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
770 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
772 #ifdef CONFIG_5VT_ENHANCE
773 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
777 #define NDIS_SET_PACKET_STATUS(_p, _status)
780 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
781 rt_get_sg_list_from_packet(_p, _sc)
783 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
784 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
785 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
786 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
787 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
790 #define RTMP_INC_REF(_A) 0
791 #define RTMP_DEC_REF(_A) 0
792 #define RTMP_GET_REF(_A) 0
798 * RTMP_GetPhysicalAddressLow(
799 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
801 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
805 * RTMP_GetPhysicalAddressHigh(
806 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
808 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
812 * RTMP_SetPhysicalAddressLow(
813 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
816 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
817 PhysicalAddress = Value;
821 * RTMP_SetPhysicalAddressHigh(
822 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
825 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
828 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
829 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
830 (PNDIS_PACKET)(pEntry)
832 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
833 (PQUEUE_ENTRY)(pPacket)
836 #ifndef CONTAINING_RECORD
837 #define CONTAINING_RECORD(address, type, field) \
838 ((type *)((PCHAR)(address) - offsetof(type, field)))
842 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
844 RTMPFreeNdisPacket(_pAd, _pPacket); \
848 #define SWITCH_PhyAB(_pAA, _pBB) \
850 ULONG AABasePaHigh; \
852 ULONG BBBasePaHigh; \
854 BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
855 BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
856 AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
857 AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
858 RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
859 RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
860 RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
861 RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
865 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
866 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
869 #define NdisAcquireSpinLock RTMP_SEM_LOCK
870 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
872 static inline void NdisGetSystemUpTime(ULONG *time)
877 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
878 #define QUEUE_ENTRY_TO_PKT(pEntry) \
879 ((PNDIS_PACKET) (pEntry))
881 int rt28xx_packet_xmit(struct sk_buff *skb);
885 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
887 #if !defined(PCI_CAP_ID_EXP)
888 #define PCI_CAP_ID_EXP 0x10
891 #if !defined(PCI_EXP_LNKCTL)
892 #define PCI_EXP_LNKCTL 0x10
895 #if !defined(PCI_CLASS_BRIDGE_PCI)
896 #define PCI_CLASS_BRIDGE_PCI 0x0604
899 #define PCIBUS_INTEL_VENDOR 0x8086