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/kernel.h>
42 #include <linux/spinlock.h>
43 #include <linux/init.h>
44 #include <linux/string.h>
45 #include <linux/timer.h>
46 #include <linux/errno.h>
47 #include <linux/slab.h>
48 #include <linux/interrupt.h>
49 #include <linux/pci.h>
50 #include <linux/netdevice.h>
51 #include <linux/etherdevice.h>
52 #include <linux/skbuff.h>
53 #include <linux/ethtool.h>
54 #include <linux/wireless.h>
55 #include <linux/proc_fs.h>
56 #include <linux/delay.h>
57 #include <linux/if_arp.h>
58 #include <linux/ctype.h>
59 #include <linux/vmalloc.h>
61 #include <net/iw_handler.h>
64 #define __KERNEL_SYSCALLS__
65 #include <linux/unistd.h>
66 #include <asm/uaccess.h>
67 #include <asm/types.h>
68 #include <asm/unaligned.h> /* for get_unaligned() */
70 #define KTHREAD_SUPPORT 1
71 /* RT2870 2.1.0.0 has it disabled */
73 #ifdef KTHREAD_SUPPORT
74 #include <linux/err.h>
75 #include <linux/kthread.h>
76 #endif /* KTHREAD_SUPPORT // */
78 /***********************************************************************************
79 * Profile related sections
80 ***********************************************************************************/
83 #define STA_PROFILE_PATH "/etc/Wireless/RT2860STA/RT2860STA.dat"
84 #define STA_DRIVER_VERSION "2.1.0.0"
85 #endif /* RTMP_MAC_PCI // */
87 #define STA_PROFILE_PATH "/etc/Wireless/RT2870STA/RT2870STA.dat"
88 #define STA_DRIVER_VERSION "2.1.0.0"
89 /* RT3070 version: 2.1.1.0 */
90 #endif /* RTMP_MAC_USB // */
92 extern const struct iw_handler_def rt28xx_iw_handler_def;
94 /***********************************************************************************
95 * Compiler related definitions
96 ***********************************************************************************/
98 #define __inline static inline
102 #define NDIS_STATUS INT
104 /***********************************************************************************
105 * OS Specific definitions and data structures
106 ***********************************************************************************/
107 typedef struct pci_dev *PPCI_DEV;
108 typedef struct net_device *PNET_DEV;
109 typedef void *PNDIS_PACKET;
110 typedef char NDIS_PACKET;
111 typedef PNDIS_PACKET *PPNDIS_PACKET;
112 typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
113 typedef dma_addr_t *PNDIS_PHYSICAL_ADDRESS;
114 typedef void *NDIS_HANDLE;
115 typedef char *PNDIS_BUFFER;
116 typedef struct pid *RTMP_OS_PID;
117 typedef struct semaphore RTMP_OS_SEM;
119 typedef int (*HARD_START_XMIT_FUNC) (struct sk_buff * skb,
120 struct net_device * net_dev);
124 #define PCI_DEVICE(vend,dev) \
125 .vendor = (vend), .device = (dev), \
126 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
127 #endif /* PCI_DEVICE // */
128 #endif /* RTMP_MAC_PCI // */
130 #define RT_MOD_INC_USE_COUNT() \
131 if (!try_module_get(THIS_MODULE)) \
133 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
137 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
139 #define RTMP_INC_REF(_A) 0
140 #define RTMP_DEC_REF(_A) 0
141 #define RTMP_GET_REF(_A) 0
143 /* This function will be called when query /proc */
144 struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev);
146 /***********************************************************************************
147 * Network related constant definitions
148 ***********************************************************************************/
153 #define ETH_LENGTH_OF_ADDRESS 6
155 #define NDIS_STATUS_SUCCESS 0x00
156 #define NDIS_STATUS_FAILURE 0x01
157 #define NDIS_STATUS_INVALID_DATA 0x02
158 #define NDIS_STATUS_RESOURCES 0x03
160 #define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
161 #define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
163 /* statistics counter */
164 #define STATS_INC_RX_PACKETS(_pAd, _dev)
165 #define STATS_INC_TX_PACKETS(_pAd, _dev)
167 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
168 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
170 #define STATS_INC_RX_ERRORS(_pAd, _dev)
171 #define STATS_INC_TX_ERRORS(_pAd, _dev)
173 #define STATS_INC_RX_DROPPED(_pAd, _dev)
174 #define STATS_INC_TX_DROPPED(_pAd, _dev)
176 /***********************************************************************************
177 * Ralink Specific network related constant definitions
178 ***********************************************************************************/
179 #define MIN_NET_DEVICE_FOR_AID 0x00 /*0x00~0x3f */
180 #define MIN_NET_DEVICE_FOR_MBSSID 0x00 /*0x00,0x10,0x20,0x30 */
181 #define MIN_NET_DEVICE_FOR_WDS 0x10 /*0x40,0x50,0x60,0x70 */
182 #define MIN_NET_DEVICE_FOR_APCLI 0x20
183 #define MIN_NET_DEVICE_FOR_MESH 0x30
184 #define MIN_NET_DEVICE_FOR_DLS 0x40
185 #define NET_DEVICE_REAL_IDX_MASK 0x0f /* for each operation mode, we maximum support 15 entities. */
187 #define NDIS_PACKET_TYPE_DIRECTED 0
188 #define NDIS_PACKET_TYPE_MULTICAST 1
189 #define NDIS_PACKET_TYPE_BROADCAST 2
190 #define NDIS_PACKET_TYPE_ALL_MULTICAST 3
191 #define NDIS_PACKET_TYPE_PROMISCUOUS 4
193 /***********************************************************************************
194 * OS signaling related constant definitions
195 ***********************************************************************************/
197 /***********************************************************************************
198 * OS file operation related data structure definitions
199 ***********************************************************************************/
200 typedef struct file *RTMP_OS_FD;
202 typedef struct _RTMP_OS_FS_INFO_ {
208 #define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
210 /***********************************************************************************
211 * OS semaphore related data structure and definitions
212 ***********************************************************************************/
218 typedef spinlock_t NDIS_SPIN_LOCK;
221 /* spin_lock enhanced for Nested spin lock */
223 #define NdisAllocateSpinLock(__lock) \
225 spin_lock_init((spinlock_t *)(__lock)); \
228 #define NdisFreeSpinLock(lock) \
231 #define RTMP_SEM_LOCK(__lock) \
233 spin_lock_bh((spinlock_t *)(__lock)); \
236 #define RTMP_SEM_UNLOCK(__lock) \
238 spin_unlock_bh((spinlock_t *)(__lock)); \
241 /* sample, use semaphore lock to replace IRQ lock, 2007/11/15 */
242 #define RTMP_IRQ_LOCK(__lock, __irqflags) \
245 spin_lock_bh((spinlock_t *)(__lock)); \
246 pAd->irq_disabled |= 1; \
249 #define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
251 pAd->irq_disabled &= 0; \
252 spin_unlock_bh((spinlock_t *)(__lock)); \
255 #define RTMP_INT_LOCK(__lock, __irqflags) \
257 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
260 #define RTMP_INT_UNLOCK(__lock, __irqflag) \
262 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
265 #define NdisAcquireSpinLock RTMP_SEM_LOCK
266 #define NdisReleaseSpinLock RTMP_SEM_UNLOCK
268 #ifndef wait_event_interruptible_timeout
269 #define __wait_event_interruptible_timeout(wq, condition, ret) \
271 wait_queue_t __wait; \
272 init_waitqueue_entry(&__wait, current); \
273 add_wait_queue(&wq, &__wait); \
275 set_current_state(TASK_INTERRUPTIBLE); \
278 if (!signal_pending(current)) { \
279 ret = schedule_timeout(ret); \
284 ret = -ERESTARTSYS; \
287 current->state = TASK_RUNNING; \
288 remove_wait_queue(&wq, &__wait); \
291 #define wait_event_interruptible_timeout(wq, condition, timeout) \
293 long __ret = timeout; \
295 __wait_event_interruptible_timeout(wq, condition, __ret); \
300 #define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
301 #define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
302 #define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
303 #define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
305 #ifdef KTHREAD_SUPPORT
306 #define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
308 wait_event_interruptible(_pTask->kthread_q, \
309 _pTask->kthread_running || kthread_should_stop()); \
310 _pTask->kthread_running = FALSE; \
311 if (kthread_should_stop()) \
313 RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
319 #ifdef KTHREAD_SUPPORT
320 #define WAKE_UP(_pTask) \
322 if ((_pTask)->kthread_task) \
324 (_pTask)->kthread_running = TRUE; \
325 wake_up(&(_pTask)->kthread_q); \
330 /***********************************************************************************
331 * OS Memory Access related data structure and definitions
332 ***********************************************************************************/
333 #define MEM_ALLOC_FLAG (GFP_ATOMIC) /*(GFP_DMA | GFP_ATOMIC) */
335 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
336 #define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
337 #define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
338 #define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
339 #define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
340 #define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
341 #define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
343 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
344 #define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
346 #define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
348 /***********************************************************************************
349 * OS task related data structure and definitions
350 ***********************************************************************************/
351 #define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
353 typedef struct pid *THREAD_PID;
354 #define THREAD_PID_INIT_VALUE NULL
355 #define GET_PID(_v) find_get_pid((_v))
356 #define GET_PID_NUMBER(_v) pid_nr((_v))
357 #define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0)
358 #define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
360 typedef struct tasklet_struct RTMP_NET_TASK_STRUCT;
361 typedef struct tasklet_struct *PRTMP_NET_TASK_STRUCT;
363 /***********************************************************************************
364 * Timer related definitions and data structures.
365 **********************************************************************************/
368 typedef struct timer_list NDIS_MINIPORT_TIMER;
369 typedef struct timer_list RTMP_OS_TIMER;
370 typedef void (*TIMER_FUNCTION) (unsigned long);
372 #define OS_WAIT(_time) \
374 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
375 wait_queue_head_t _wait; \
376 init_waitqueue_head(&_wait); \
377 for (_i=0; _i<(_loop); _i++) \
378 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
380 #define RTMP_TIME_AFTER(a,b) \
381 (typecheck(unsigned long, (unsigned long)a) && \
382 typecheck(unsigned long, (unsigned long)b) && \
383 ((long)(b) - (long)(a) < 0))
385 #define RTMP_TIME_AFTER_EQ(a,b) \
386 (typecheck(unsigned long, (unsigned long)a) && \
387 typecheck(unsigned long, (unsigned long)b) && \
388 ((long)(a) - (long)(b) >= 0))
389 #define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
393 static inline void NdisGetSystemUpTime(ULONG * time)
398 /***********************************************************************************
399 * OS specific cookie data structure binding to RTMP_ADAPTER
400 ***********************************************************************************/
404 struct pci_dev *pci_dev;
405 struct pci_dev *parent_pci_dev;
408 #endif /* RTMP_MAC_PCI // */
410 struct usb_device *pUsb_Dev;
411 #endif /* RTMP_MAC_USB // */
413 RTMP_NET_TASK_STRUCT rx_done_task;
414 RTMP_NET_TASK_STRUCT mgmt_dma_done_task;
415 RTMP_NET_TASK_STRUCT ac0_dma_done_task;
416 RTMP_NET_TASK_STRUCT ac1_dma_done_task;
417 RTMP_NET_TASK_STRUCT ac2_dma_done_task;
418 RTMP_NET_TASK_STRUCT ac3_dma_done_task;
419 RTMP_NET_TASK_STRUCT tbtt_task;
421 RTMP_NET_TASK_STRUCT fifo_statistic_full_task;
422 #endif /* RTMP_MAC_PCI // */
424 RTMP_NET_TASK_STRUCT null_frame_complete_task;
425 RTMP_NET_TASK_STRUCT rts_frame_complete_task;
426 RTMP_NET_TASK_STRUCT pspoll_frame_complete_task;
427 #endif /* RTMP_MAC_USB // */
429 unsigned long apd_pid; /*802.1x daemon pid */
434 typedef struct os_cookie *POS_COOKIE;
436 /***********************************************************************************
437 * OS debugging and printing related definitions and data structure
438 ***********************************************************************************/
439 #define PRINT_MAC(addr) \
440 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
443 extern ULONG RTDebugLevel;
445 #define DBGPRINT_RAW(Level, Fmt) \
447 if (Level <= RTDebugLevel) \
453 #define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
455 #define DBGPRINT_ERR(Fmt) \
457 printk("ERROR!!! "); \
461 #define DBGPRINT_S(Status, Fmt) \
467 #define DBGPRINT(Level, Fmt)
468 #define DBGPRINT_RAW(Level, Fmt)
469 #define DBGPRINT_S(Status, Fmt)
470 #define DBGPRINT_ERR(Fmt)
475 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
477 /*********************************************************************************************************
478 The following code are not revised, temporary put it here.
479 *********************************************************************************************************/
481 /***********************************************************************************
482 * Device DMA Access related definitions and data structures.
483 **********************************************************************************/
485 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size,
486 int sd_idx, int direction);
487 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size,
490 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
491 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
493 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
494 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
496 #define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
497 pci_alloc_consistent(_pci_dev, _size, _ptr)
499 #define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
500 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
502 #define DEV_ALLOC_SKB(_length) \
503 dev_alloc_skb(_length)
504 #endif /* RTMP_MAC_PCI // */
506 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
508 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
509 #endif /* RTMP_MAC_USB // */
513 * RTMP_GetPhysicalAddressLow(
514 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
516 #define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
520 * RTMP_GetPhysicalAddressHigh(
521 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
523 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
527 * RTMP_SetPhysicalAddressLow(
528 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
531 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
532 PhysicalAddress = Value;
536 * RTMP_SetPhysicalAddressHigh(
537 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
540 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
542 #define NdisMIndicateStatus(_w, _x, _y, _z)
544 /***********************************************************************************
545 * Device Register I/O Access related definitions and data structures.
546 **********************************************************************************/
548 /*Patch for ASIC turst read/write bug, needs to remove after metel fix */
549 #define RTMP_IO_READ32(_A, _R, _pV) \
551 if ((_A)->bPCIclkOff == FALSE) \
553 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
554 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
560 #define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
562 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
563 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
566 #define RTMP_IO_READ8(_A, _R, _pV) \
568 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
569 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
571 #define RTMP_IO_WRITE32(_A, _R, _V) \
573 if ((_A)->bPCIclkOff == FALSE) \
576 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
577 writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
581 #define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
584 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
585 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
588 #if defined(RALINK_2880) || defined(RALINK_3052)
589 #define RTMP_IO_WRITE8(_A, _R, _V) \
594 Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
595 Val = Val & (~(0x000000ff << ((_i)*8))); \
596 Val = Val | ((ULONG)(_V) << ((_i)*8)); \
597 writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
600 #define RTMP_IO_WRITE8(_A, _R, _V) \
603 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
604 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
606 #endif /* #if defined(BRCM_6358) || defined(RALINK_2880) // */
608 #define RTMP_IO_WRITE16(_A, _R, _V) \
611 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
612 writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
614 #endif /* RTMP_MAC_PCI // */
616 /*Patch for ASIC turst read/write bug, needs to remove after metel fix */
617 #define RTMP_IO_READ32(_A, _R, _pV) \
618 RTUSBReadMACRegister((_A), (_R), (PUINT32) (_pV))
620 #define RTMP_IO_READ8(_A, _R, _pV) \
624 #define RTMP_IO_WRITE32(_A, _R, _V) \
625 RTUSBWriteMACRegister((_A), (_R), (UINT32) (_V))
627 #define RTMP_IO_WRITE8(_A, _R, _V) \
630 RTUSBSingleWrite((_A), (_R), (USHORT) (_Val)); \
633 #define RTMP_IO_WRITE16(_A, _R, _V) \
635 RTUSBSingleWrite((_A), (_R), (USHORT) (_V)); \
637 #endif /* RTMP_MAC_USB // */
639 /***********************************************************************************
640 * Network Related data structure and marco definitions
641 ***********************************************************************************/
642 #define PKTSRC_NDIS 0x7f
643 #define PKTSRC_DRIVER 0x0f
645 #define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
646 #define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
647 #define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
648 #define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
650 #define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
651 #define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
652 #define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
653 #define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
655 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
656 (PNDIS_PACKET)(pEntry)
658 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
659 (PQUEUE_ENTRY)(pPacket)
661 #define GET_SG_LIST_FROM_PACKET(_p, _sc) \
662 rt_get_sg_list_from_packet(_p, _sc)
664 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
666 RTMPFreeNdisPacket(_pAd, _pPacket); \
671 * - convert internal rt packet to os packet or
672 * os packet to rt packet
674 #define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
675 #define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
677 #define GET_OS_PKT_DATAPTR(_pkt) \
678 (RTPKT_TO_OSPKT(_pkt)->data)
679 #define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
680 (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
682 #define GET_OS_PKT_LEN(_pkt) \
683 (RTPKT_TO_OSPKT(_pkt)->len)
684 #define SET_OS_PKT_LEN(_pkt, _len) \
685 (RTPKT_TO_OSPKT(_pkt)->len) = (_len)
687 #define GET_OS_PKT_DATATAIL(_pkt) \
688 (RTPKT_TO_OSPKT(_pkt)->tail)
689 #define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
690 ((RTPKT_TO_OSPKT(_pkt))->tail) = (PUCHAR)((_start) + (_len))
692 #define GET_OS_PKT_HEAD(_pkt) \
693 (RTPKT_TO_OSPKT(_pkt)->head)
695 #define GET_OS_PKT_END(_pkt) \
696 (RTPKT_TO_OSPKT(_pkt)->end)
698 #define GET_OS_PKT_NETDEV(_pkt) \
699 (RTPKT_TO_OSPKT(_pkt)->dev)
700 #define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
701 (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
703 #define GET_OS_PKT_TYPE(_pkt) \
704 (RTPKT_TO_OSPKT(_pkt))
706 #define GET_OS_PKT_NEXT(_pkt) \
707 (RTPKT_TO_OSPKT(_pkt)->next)
709 #define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
711 #define OS_NTOHS(_Val) \
713 #define OS_HTONS(_Val) \
715 #define OS_NTOHL(_Val) \
717 #define OS_HTONL(_Val) \
723 #define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
724 #define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
727 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
728 #define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
730 /* 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. */
731 /*(this value also as MAC(on-chip WCID) table index) */
732 /* 0x80~0xff: TX to a WDS link. b0~6: WDS index */
733 #define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
734 #define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
736 /* 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet */
737 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
738 #define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
740 /* RTS/CTS-to-self protection method */
741 #define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
742 #define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
743 /* see RTMP_S(G)ET_PACKET_EMACTAB */
746 #define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
747 #define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
749 /* From which Interface */
750 #define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
751 #define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
752 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
753 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
754 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
755 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
756 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
757 #define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
759 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
760 #define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
763 /* Sepcific Pakcet Type definition */
765 #define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
767 #define RTMP_PACKET_SPECIFIC_DHCP 0x01
768 #define RTMP_PACKET_SPECIFIC_EAPOL 0x02
769 #define RTMP_PACKET_SPECIFIC_IPV4 0x04
770 #define RTMP_PACKET_SPECIFIC_WAI 0x08
771 #define RTMP_PACKET_SPECIFIC_VLAN 0x10
772 #define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
775 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
778 #define RTMP_SET_PACKET_DHCP(_p, _flg) \
781 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
783 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
785 #define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
788 #define RTMP_SET_PACKET_EAPOL(_p, _flg) \
791 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
793 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
795 #define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
798 #define RTMP_SET_PACKET_WAI(_p, _flg) \
801 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
803 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
805 #define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
807 #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))
810 #define RTMP_SET_PACKET_VLAN(_p, _flg) \
813 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
815 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
817 #define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
820 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
823 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
825 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
828 #define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
831 #define RTMP_SET_PACKET_IPV4(_p, _flg) \
834 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
836 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
839 #define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
841 /* If this flag is set, it indicates that this EAPoL frame MUST be clear. */
842 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
843 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
845 /* use bit3 of cb[CB_OFF+16] */
847 #define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
848 #define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
850 /* Max skb->cb = 48B = [CB_OFF+38] */
852 /***********************************************************************************
853 * Other function prototypes definitions
854 ***********************************************************************************/
855 void RTMP_GetCurrentSystemTime(LARGE_INTEGER * time);
856 int rt28xx_packet_xmit(struct sk_buff *skb);
859 /* function declarations */
860 #define IRQ_HANDLE_TYPE irqreturn_t
862 IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
863 #endif /* RTMP_MAC_PCI // */
865 INT rt28xx_sta_ioctl(IN PNET_DEV net_dev, IN OUT struct ifreq *rq, IN INT cmd);
867 extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char * buf);
868 extern int ra_mtd_read(int num, loff_t from, size_t len, u_char * buf);
870 #define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (PRTMP_ADAPTER)(_net_dev)->ml_priv;
872 #endif /* __RT_LINUX_H__ // */