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/kernel.h>
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>
67 #include <net/iw_handler.h>
70 #define __KERNEL_SYSCALLS__
71 #include <linux/unistd.h>
72 #include <asm/uaccess.h>
75 #define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
81 //#define CONFIG_CKIP_SUPPORT
84 #define __inline static inline
86 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
90 #ifdef CONFIG_STA_SUPPORT
91 #define STA_PROFILE_PATH "/etc/Wireless/RT2860STA/RT2860STA.dat"
92 #define STA_RTMP_FIRMWARE_FILE_NAME "/etc/Wireless/RT2860STA/RT2860STA.bin"
93 #define STA_NIC_DEVICE_NAME "RT2860STA"
94 #define STA_DRIVER_VERSION "1.8.1.1"
95 #ifdef MULTIPLE_CARD_SUPPORT
96 #define CARD_INFO_PATH "/etc/Wireless/RT2860STA/RT2860STACard.dat"
97 #endif // MULTIPLE_CARD_SUPPORT //
100 #endif // CONFIG_STA_SUPPORT //
103 #define PCI_DEVICE(vend,dev) \
104 .vendor = (vend), .device = (dev), \
105 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
106 #endif // PCI_DEVICE //
108 #define RTMP_TIME_AFTER(a,b) \
109 (typecheck(unsigned long, (unsigned long)a) && \
110 typecheck(unsigned long, (unsigned long)b) && \
111 ((long)(b) - (long)(a) < 0))
113 #define RTMP_TIME_AFTER_EQ(a,b) \
114 (typecheck(unsigned long, (unsigned long)a) && \
115 typecheck(unsigned long, (unsigned long)b) && \
116 ((long)(a) - (long)(b) >= 0))
117 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
119 #define RT_MOD_INC_USE_COUNT() \
120 if (!try_module_get(THIS_MODULE)) \
122 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
126 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
130 #define ETH_LENGTH_OF_ADDRESS 6
135 #define NDIS_STATUS INT
136 #define NDIS_STATUS_SUCCESS 0x00
137 #define NDIS_STATUS_FAILURE 0x01
138 #define NDIS_STATUS_INVALID_DATA 0x02
139 #define NDIS_STATUS_RESOURCES 0x03
141 #define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
142 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
143 #define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
144 #define MIN_NET_DEVICE_FOR_APCLI 0x20
145 #define MIN_NET_DEVICE_FOR_MESH 0x30
146 #ifdef CONFIG_STA_SUPPORT
147 #define MIN_NET_DEVICE_FOR_DLS 0x40
148 #endif // CONFIG_STA_SUPPORT //
151 #ifdef CONFIG_STA_SUPPORT
152 #define NDIS_PACKET_TYPE_DIRECTED 0
153 #define NDIS_PACKET_TYPE_MULTICAST 1
154 #define NDIS_PACKET_TYPE_BROADCAST 2
155 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
156 #endif // CONFIG_STA_SUPPORT //
158 typedef struct pid * THREAD_PID;
159 #define THREAD_PID_INIT_VALUE NULL
160 #define GET_PID(_v) find_get_pid(_v)
161 #define GET_PID_NUMBER(_v) pid_nr(_v)
162 #define CHECK_PID_LEGALITY(_pid) if (pid_nr(_pid) >= 0)
163 #define KILL_THREAD_PID(_A, _B, _C) kill_pid(_A, _B, _C)
172 struct pci_dev *pci_dev;
173 struct pci_dev *parent_pci_dev;
177 struct tasklet_struct rx_done_task;
178 struct tasklet_struct mgmt_dma_done_task;
179 struct tasklet_struct ac0_dma_done_task;
180 struct tasklet_struct ac1_dma_done_task;
181 struct tasklet_struct ac2_dma_done_task;
182 struct tasklet_struct ac3_dma_done_task;
183 struct tasklet_struct hcca_dma_done_task;
184 struct tasklet_struct tbtt_task;
185 struct tasklet_struct fifo_statistic_full_task;
188 unsigned long apd_pid; //802.1x daemon pid
193 typedef struct _VIRTUAL_ADAPTER
195 struct net_device *RtmpDev;
196 struct net_device *VirtualDev;
197 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
204 printk(KERN_WARNING __FILE__ ":%d assert " #x "failed\n", __LINE__); \
208 typedef struct os_cookie * POS_COOKIE;
209 typedef struct pci_dev * PPCI_DEV;
210 typedef struct net_device * PNET_DEV;
211 typedef void * PNDIS_PACKET;
212 typedef char NDIS_PACKET;
213 typedef PNDIS_PACKET * PPNDIS_PACKET;
214 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
215 typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
216 typedef spinlock_t NDIS_SPIN_LOCK;
217 typedef struct timer_list NDIS_MINIPORT_TIMER;
218 typedef void * NDIS_HANDLE;
219 typedef char * PNDIS_BUFFER;
223 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
225 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
226 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
229 ////////////////////////////////////////
231 /////////////////////////////////////////
232 #define PKTSRC_NDIS 0x7f
233 #define PKTSRC_DRIVER 0x0f
234 #define PRINT_MAC(addr) \
235 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
238 #define RT2860_PCI_DEVICE_ID 0x0601
240 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
241 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
243 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
244 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
246 #define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
247 pci_alloc_consistent(_pci_dev, _size, _ptr)
249 #define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
250 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
252 #define DEV_ALLOC_SKB(_length) \
253 dev_alloc_skb(_length)
257 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size) \
258 dma_cache_wback(_ptr, _size)
261 //////////////////////////////////////////
263 //////////////////////////////////////////
266 #define NdisMIndicateStatus(_w, _x, _y, _z)
269 typedef struct timer_list RTMP_OS_TIMER;
273 typedef struct _RALINK_TIMER_STRUCT {
274 RTMP_OS_TIMER TimerObj; // Ndis Timer object
275 BOOLEAN Valid; // Set to True when call RTMPInitTimer
276 BOOLEAN State; // True if timer cancelled
277 BOOLEAN PeriodicType; // True if timer is periodic timer
278 BOOLEAN Repeat; // True if periodic timer
279 ULONG TimerValue; // Timer value in milliseconds
280 ULONG cookie; // os specific object
281 } RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
289 // MACRO for debugging information
293 extern ULONG RTDebugLevel;
295 #define DBGPRINT_RAW(Level, Fmt) \
297 if (Level <= RTDebugLevel) \
303 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
306 #define DBGPRINT_ERR(Fmt) \
308 printk("ERROR!!! "); \
312 #define DBGPRINT_S(Status, Fmt) \
319 #define DBGPRINT(Level, Fmt)
320 #define DBGPRINT_RAW(Level, Fmt)
321 #define DBGPRINT_S(Status, Fmt)
322 #define DBGPRINT_ERR(Fmt)
327 // spin_lock enhanced for Nested spin lock
329 #define NdisAllocateSpinLock(__lock) \
331 spin_lock_init((spinlock_t *)(__lock)); \
334 #define NdisFreeSpinLock(lock) \
339 #define RTMP_SEM_LOCK(__lock) \
341 spin_lock_bh((spinlock_t *)(__lock)); \
344 #define RTMP_SEM_UNLOCK(__lock) \
346 spin_unlock_bh((spinlock_t *)(__lock)); \
349 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
350 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
353 spin_lock_bh((spinlock_t *)(__lock)); \
354 pAd->irq_disabled |= 1; \
357 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
359 pAd->irq_disabled &= 0; \
360 spin_unlock_bh((spinlock_t *)(__lock)); \
363 #define RTMP_INT_LOCK(__lock, __irqflags) \
365 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
368 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
370 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
373 #if defined(INF_TWINPASS) || defined(INF_DANUBE) || defined(IKANOS_VX_1X0)
374 //Patch for ASIC turst read/write bug, needs to remove after metel fix
375 #define RTMP_IO_READ32(_A, _R, _pV) \
377 if ((_A)->bPCIclkOff == FALSE) \
379 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
380 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
381 (*_pV = SWAP32(*((UINT32 *)(_pV)))); \
384 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
386 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
387 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
388 (*_pV = SWAP32(*((UINT32 *)(_pV)))); \
390 #define RTMP_IO_READ8(_A, _R, _pV) \
392 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
393 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
395 #define RTMP_IO_WRITE32(_A, _R, _V) \
397 if ((_A)->bPCIclkOff == FALSE) \
400 _Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
402 writel(_Val, (void *)((_A)->CSRBaseAddress + (_R))); \
405 #define RTMP_IO_WRITE8(_A, _R, _V) \
408 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
409 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
411 #define RTMP_IO_WRITE16(_A, _R, _V) \
414 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
415 writew(SWAP16((_V)), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
418 //Patch for ASIC turst read/write bug, needs to remove after metel fix
419 #define RTMP_IO_READ32(_A, _R, _pV) \
421 if ((_A)->bPCIclkOff == FALSE) \
423 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
424 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
429 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
431 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
432 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
434 #define RTMP_IO_READ8(_A, _R, _pV) \
436 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
437 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
439 #define RTMP_IO_WRITE32(_A, _R, _V) \
441 if ((_A)->bPCIclkOff == FALSE) \
444 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
445 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
448 #if defined(BRCM_6358)
449 #define RTMP_IO_WRITE8(_A, _R, _V) \
454 Val = readl((void *)((_A)->CSRBaseAddress + (_R - _i))); \
455 Val = Val & (~(0x000000ff << ((_i)*8))); \
456 Val = Val | ((ULONG)_V << ((_i)*8)); \
457 writel((Val), (void *)((_A)->CSRBaseAddress + (_R - _i))); \
460 #define RTMP_IO_WRITE8(_A, _R, _V) \
463 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
464 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
467 #define RTMP_IO_WRITE16(_A, _R, _V) \
470 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
471 writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
476 #ifndef wait_event_interruptible_timeout
477 #define __wait_event_interruptible_timeout(wq, condition, ret) \
479 wait_queue_t __wait; \
480 init_waitqueue_entry(&__wait, current); \
481 add_wait_queue(&wq, &__wait); \
483 set_current_state(TASK_INTERRUPTIBLE); \
486 if (!signal_pending(current)) { \
487 ret = schedule_timeout(ret); \
492 ret = -ERESTARTSYS; \
495 current->state = TASK_RUNNING; \
496 remove_wait_queue(&wq, &__wait); \
499 #define wait_event_interruptible_timeout(wq, condition, timeout) \
501 long __ret = timeout; \
503 __wait_event_interruptible_timeout(wq, condition, __ret); \
508 #define OS_WAIT(_time) \
510 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
511 wait_queue_head_t _wait; \
512 init_waitqueue_head(&_wait); \
513 for (_i=0; _i<(_loop); _i++) \
514 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
517 /* Modified by Wu Xi-Kun 4/21/2006 */
518 typedef void (*TIMER_FUNCTION)(unsigned long);
520 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
522 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
523 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
525 #define BUILD_TIMER_FUNCTION(_func) \
526 void linux_##_func(unsigned long data) \
528 PRALINK_TIMER_STRUCT pTimer = (PRALINK_TIMER_STRUCT) data; \
530 _func(NULL, (PVOID) pTimer->cookie, NULL, pTimer); \
531 if (pTimer->Repeat) \
532 RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue); \
537 #define DECLARE_TIMER_FUNCTION(_func) \
538 void linux_##_func(unsigned long data)
540 #define GET_TIMER_FUNCTION(_func) \
543 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
544 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
545 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
546 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
547 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
550 #ifdef CONFIG_STA_SUPPORT
551 DECLARE_TIMER_FUNCTION(BeaconTimeout);
552 DECLARE_TIMER_FUNCTION(ScanTimeout);
553 DECLARE_TIMER_FUNCTION(AuthTimeout);
554 DECLARE_TIMER_FUNCTION(AssocTimeout);
555 DECLARE_TIMER_FUNCTION(ReassocTimeout);
556 DECLARE_TIMER_FUNCTION(DisassocTimeout);
557 DECLARE_TIMER_FUNCTION(LinkDownExec);
559 DECLARE_TIMER_FUNCTION(LeapAuthTimeout);
561 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
562 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
563 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
564 DECLARE_TIMER_FUNCTION(RadioOnExec);
566 #ifdef QOS_DLS_SUPPORT
567 DECLARE_TIMER_FUNCTION(DlsTimeoutAction);
568 #endif // QOS_DLS_SUPPORT //
569 #endif // CONFIG_STA_SUPPORT //
571 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
576 * - convert internal rt packet to os packet or
577 * os packet to rt packet
579 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
580 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
582 #define GET_OS_PKT_DATAPTR(_pkt) \
583 (RTPKT_TO_OSPKT(_pkt)->data)
585 #define GET_OS_PKT_LEN(_pkt) \
586 (RTPKT_TO_OSPKT(_pkt)->len)
588 #define GET_OS_PKT_DATATAIL(_pkt) \
589 (RTPKT_TO_OSPKT(_pkt)->tail)
591 #define GET_OS_PKT_HEAD(_pkt) \
592 (RTPKT_TO_OSPKT(_pkt)->head)
594 #define GET_OS_PKT_END(_pkt) \
595 (RTPKT_TO_OSPKT(_pkt)->end)
597 #define GET_OS_PKT_NETDEV(_pkt) \
598 (RTPKT_TO_OSPKT(_pkt)->dev)
600 #define GET_OS_PKT_TYPE(_pkt) \
601 (RTPKT_TO_OSPKT(_pkt))
603 #define GET_OS_PKT_NEXT(_pkt) \
604 (RTPKT_TO_OSPKT(_pkt)->next)
607 #define OS_NTOHS(_Val) \
609 #define OS_HTONS(_Val) \
611 #define OS_NTOHL(_Val) \
613 #define OS_HTONL(_Val) \
616 /* statistics counter */
617 #define STATS_INC_RX_PACKETS(_pAd, _dev)
618 #define STATS_INC_TX_PACKETS(_pAd, _dev)
620 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
621 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
623 #define STATS_INC_RX_ERRORS(_pAd, _dev)
624 #define STATS_INC_TX_ERRORS(_pAd, _dev)
626 #define STATS_INC_RX_DROPPED(_pAd, _dev)
627 #define STATS_INC_TX_DROPPED(_pAd, _dev)
633 // check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
634 // ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
638 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
639 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
642 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
643 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
645 // 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too.
646 //(this value also as MAC(on-chip WCID) table index)
647 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
648 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
649 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
651 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
652 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
653 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
655 // RTS/CTS-to-self protection method
656 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
657 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
658 // see RTMP_S(G)ET_PACKET_EMACTAB
661 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
662 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
664 // From which Interface
665 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
666 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
667 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
668 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
669 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
670 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
671 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
672 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
674 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
675 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
679 //#define RTMP_SET_PACKET_DHCP(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
680 //#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11])
683 // Sepcific Pakcet Type definition
685 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
687 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
688 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
689 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
690 #define RTMP_PACKET_SPECIFIC_WAI 0x08
691 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
692 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
695 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
698 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
701 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
703 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
705 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
708 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
711 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
713 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
715 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
718 #define RTMP_SET_PACKET_WAI(_p, _flg) \
721 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
723 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
725 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
727 #define RTMP_GET_PACKET_LOWRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI))
730 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
733 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
735 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
737 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
740 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
743 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
745 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
748 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
751 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
754 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
756 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
759 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
764 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
765 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
766 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
768 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
769 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
771 #ifdef CONFIG_5VT_ENHANCE
772 #define BRIDGE_TAG 0x35564252 // depends on 5VT define in br_input.c
776 #define NDIS_SET_PACKET_STATUS(_p, _status)
779 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
780 rt_get_sg_list_from_packet(_p, _sc)
782 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
783 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
784 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
785 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
786 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
789 #define RTMP_INC_REF(_A) 0
790 #define RTMP_DEC_REF(_A) 0
791 #define RTMP_GET_REF(_A) 0
797 * RTMP_GetPhysicalAddressLow(
798 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
800 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
804 * RTMP_GetPhysicalAddressHigh(
805 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
807 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
811 * RTMP_SetPhysicalAddressLow(
812 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
815 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
816 PhysicalAddress = Value;
820 * RTMP_SetPhysicalAddressHigh(
821 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
824 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
827 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
828 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
829 (PNDIS_PACKET)(pEntry)
831 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
832 (PQUEUE_ENTRY)(pPacket)
835 #ifndef CONTAINING_RECORD
836 #define CONTAINING_RECORD(address, type, field) \
837 ((type *)((PCHAR)(address) - offsetof(type, field)))
841 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
843 RTMPFreeNdisPacket(_pAd, _pPacket); \
847 #define SWITCH_PhyAB(_pAA, _pBB) \
849 ULONG AABasePaHigh; \
851 ULONG BBBasePaHigh; \
853 BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB); \
854 BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB); \
855 AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA); \
856 AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA); \
857 RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh); \
858 RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow); \
859 RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh); \
860 RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow); \
864 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
865 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e) NDIS_STATUS_SUCCESS
868 #define NdisAcquireSpinLock RTMP_SEM_LOCK
869 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
871 static inline void NdisGetSystemUpTime(ULONG *time)
876 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
877 #define QUEUE_ENTRY_TO_PKT(pEntry) \
878 ((PNDIS_PACKET) (pEntry))
880 int rt28xx_packet_xmit(struct sk_buff *skb);
884 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
886 #if !defined(PCI_CAP_ID_EXP)
887 #define PCI_CAP_ID_EXP 0x10
890 #if !defined(PCI_EXP_LNKCTL)
891 #define PCI_EXP_LNKCTL 0x10
894 #if !defined(PCI_CLASS_BRIDGE_PCI)
895 #define PCI_CLASS_BRIDGE_PCI 0x0604
898 #define PCIBUS_INTEL_VENDOR 0x8086