![Ben Hutchings](/assets/img/avatar_default.png)
To avoid recurrence of bugs such as <http://bugs.debian.org/575726>, change the type of the first parameter to linux_pci_{map,unmap}_single() from void * to struct rt_rtmp_adapter *. Also do not define the macros PCI_{MAP,UNMAP}_SINGLE() when building the rt2870sta driver; they are not used and if they were that would be a bug. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>, Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
842 lines
29 KiB
C
842 lines
29 KiB
C
/*
|
|
*************************************************************************
|
|
* Ralink Tech Inc.
|
|
* 5F., No.36, Taiyuan St., Jhubei City,
|
|
* Hsinchu County 302,
|
|
* Taiwan, R.O.C.
|
|
*
|
|
* (c) Copyright 2002-2007, Ralink Technology, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
* *
|
|
*************************************************************************
|
|
|
|
Module Name:
|
|
rt_linux.h
|
|
|
|
Abstract:
|
|
|
|
Revision History:
|
|
Who When What
|
|
--------- ---------- ----------------------------------------------
|
|
*/
|
|
|
|
#ifndef __RT_LINUX_H__
|
|
#define __RT_LINUX_H__
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/init.h>
|
|
#include <linux/string.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/ethtool.h>
|
|
#include <linux/wireless.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/if_arp.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <net/iw_handler.h>
|
|
|
|
/* load firmware */
|
|
#define __KERNEL_SYSCALLS__
|
|
#include <linux/unistd.h>
|
|
#include <asm/uaccess.h>
|
|
#include <asm/types.h>
|
|
#include <asm/unaligned.h> /* for get_unaligned() */
|
|
|
|
#define KTHREAD_SUPPORT 1
|
|
/* RT2870 2.1.0.0 has it disabled */
|
|
|
|
#ifdef KTHREAD_SUPPORT
|
|
#include <linux/err.h>
|
|
#include <linux/kthread.h>
|
|
#endif /* KTHREAD_SUPPORT // */
|
|
|
|
/***********************************************************************************
|
|
* Profile related sections
|
|
***********************************************************************************/
|
|
|
|
#ifdef RTMP_MAC_PCI
|
|
#define STA_DRIVER_VERSION "2.1.0.0"
|
|
#endif /* RTMP_MAC_PCI // */
|
|
#ifdef RTMP_MAC_USB
|
|
#define STA_DRIVER_VERSION "2.1.0.0"
|
|
/* RT3070 version: 2.1.1.0 */
|
|
#endif /* RTMP_MAC_USB // */
|
|
|
|
extern const struct iw_handler_def rt28xx_iw_handler_def;
|
|
|
|
/***********************************************************************************
|
|
* Compiler related definitions
|
|
***********************************************************************************/
|
|
#undef __inline
|
|
#define __inline static inline
|
|
#define IN
|
|
#define OUT
|
|
#define INOUT
|
|
|
|
/***********************************************************************************
|
|
* OS Specific definitions and data structures
|
|
***********************************************************************************/
|
|
typedef int (*HARD_START_XMIT_FUNC) (struct sk_buff * skb,
|
|
struct net_device * net_dev);
|
|
|
|
#ifdef RTMP_MAC_PCI
|
|
#ifndef PCI_DEVICE
|
|
#define PCI_DEVICE(vend,dev) \
|
|
.vendor = (vend), .device = (dev), \
|
|
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
|
|
#endif /* PCI_DEVICE // */
|
|
#endif /* RTMP_MAC_PCI // */
|
|
|
|
#define RT_MOD_INC_USE_COUNT() \
|
|
if (!try_module_get(THIS_MODULE)) \
|
|
{ \
|
|
DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
|
|
return -1; \
|
|
}
|
|
|
|
#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
|
|
|
|
#define RTMP_INC_REF(_A) 0
|
|
#define RTMP_DEC_REF(_A) 0
|
|
#define RTMP_GET_REF(_A) 0
|
|
|
|
/* This function will be called when query /proc */
|
|
struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev);
|
|
|
|
/***********************************************************************************
|
|
* Network related constant definitions
|
|
***********************************************************************************/
|
|
#ifndef IFNAMSIZ
|
|
#define IFNAMSIZ 16
|
|
#endif
|
|
|
|
#define ETH_LENGTH_OF_ADDRESS 6
|
|
|
|
#define NDIS_STATUS_SUCCESS 0x00
|
|
#define NDIS_STATUS_FAILURE 0x01
|
|
#define NDIS_STATUS_INVALID_DATA 0x02
|
|
#define NDIS_STATUS_RESOURCES 0x03
|
|
|
|
#define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
|
|
#define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
|
|
|
|
/* statistics counter */
|
|
#define STATS_INC_RX_PACKETS(_pAd, _dev)
|
|
#define STATS_INC_TX_PACKETS(_pAd, _dev)
|
|
|
|
#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
|
|
#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
|
|
|
|
#define STATS_INC_RX_ERRORS(_pAd, _dev)
|
|
#define STATS_INC_TX_ERRORS(_pAd, _dev)
|
|
|
|
#define STATS_INC_RX_DROPPED(_pAd, _dev)
|
|
#define STATS_INC_TX_DROPPED(_pAd, _dev)
|
|
|
|
/***********************************************************************************
|
|
* Ralink Specific network related constant definitions
|
|
***********************************************************************************/
|
|
#define MIN_NET_DEVICE_FOR_AID 0x00 /*0x00~0x3f */
|
|
#define MIN_NET_DEVICE_FOR_MBSSID 0x00 /*0x00,0x10,0x20,0x30 */
|
|
#define MIN_NET_DEVICE_FOR_WDS 0x10 /*0x40,0x50,0x60,0x70 */
|
|
#define MIN_NET_DEVICE_FOR_APCLI 0x20
|
|
#define MIN_NET_DEVICE_FOR_MESH 0x30
|
|
#define MIN_NET_DEVICE_FOR_DLS 0x40
|
|
#define NET_DEVICE_REAL_IDX_MASK 0x0f /* for each operation mode, we maximum support 15 entities. */
|
|
|
|
#define NDIS_PACKET_TYPE_DIRECTED 0
|
|
#define NDIS_PACKET_TYPE_MULTICAST 1
|
|
#define NDIS_PACKET_TYPE_BROADCAST 2
|
|
#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
|
|
#define NDIS_PACKET_TYPE_PROMISCUOUS 4
|
|
|
|
/***********************************************************************************
|
|
* OS signaling related constant definitions
|
|
***********************************************************************************/
|
|
|
|
/***********************************************************************************
|
|
* OS file operation related data structure definitions
|
|
***********************************************************************************/
|
|
struct rt_rtmp_os_fs_info {
|
|
int fsuid;
|
|
int fsgid;
|
|
mm_segment_t fs;
|
|
};
|
|
|
|
#define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
|
|
|
|
/***********************************************************************************
|
|
* OS semaphore related data structure and definitions
|
|
***********************************************************************************/
|
|
struct os_lock {
|
|
spinlock_t lock;
|
|
unsigned long flags;
|
|
};
|
|
|
|
/* */
|
|
/* spin_lock enhanced for Nested spin lock */
|
|
/* */
|
|
#define NdisAllocateSpinLock(__lock) \
|
|
{ \
|
|
spin_lock_init((spinlock_t *)(__lock)); \
|
|
}
|
|
|
|
#define NdisFreeSpinLock(lock) \
|
|
do{}while(0)
|
|
|
|
#define RTMP_SEM_LOCK(__lock) \
|
|
{ \
|
|
spin_lock_bh((spinlock_t *)(__lock)); \
|
|
}
|
|
|
|
#define RTMP_SEM_UNLOCK(__lock) \
|
|
{ \
|
|
spin_unlock_bh((spinlock_t *)(__lock)); \
|
|
}
|
|
|
|
/* sample, use semaphore lock to replace IRQ lock, 2007/11/15 */
|
|
#define RTMP_IRQ_LOCK(__lock, __irqflags) \
|
|
{ \
|
|
__irqflags = 0; \
|
|
spin_lock_bh((spinlock_t *)(__lock)); \
|
|
pAd->irq_disabled |= 1; \
|
|
}
|
|
|
|
#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
|
|
{ \
|
|
pAd->irq_disabled &= 0; \
|
|
spin_unlock_bh((spinlock_t *)(__lock)); \
|
|
}
|
|
|
|
#define RTMP_INT_LOCK(__lock, __irqflags) \
|
|
{ \
|
|
spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
|
|
}
|
|
|
|
#define RTMP_INT_UNLOCK(__lock, __irqflag) \
|
|
{ \
|
|
spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
|
|
}
|
|
|
|
#define NdisAcquireSpinLock RTMP_SEM_LOCK
|
|
#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
|
|
|
|
#ifndef wait_event_interruptible_timeout
|
|
#define __wait_event_interruptible_timeout(wq, condition, ret) \
|
|
do { \
|
|
wait_queue_t __wait; \
|
|
init_waitqueue_entry(&__wait, current); \
|
|
add_wait_queue(&wq, &__wait); \
|
|
for (;;) { \
|
|
set_current_state(TASK_INTERRUPTIBLE); \
|
|
if (condition) \
|
|
break; \
|
|
if (!signal_pending(current)) { \
|
|
ret = schedule_timeout(ret); \
|
|
if (!ret) \
|
|
break; \
|
|
continue; \
|
|
} \
|
|
ret = -ERESTARTSYS; \
|
|
break; \
|
|
} \
|
|
current->state = TASK_RUNNING; \
|
|
remove_wait_queue(&wq, &__wait); \
|
|
} while (0)
|
|
|
|
#define wait_event_interruptible_timeout(wq, condition, timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
if (!(condition)) \
|
|
__wait_event_interruptible_timeout(wq, condition, __ret); \
|
|
__ret; \
|
|
})
|
|
#endif
|
|
|
|
#define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
|
|
#define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
|
|
#define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
|
|
#define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
|
|
|
|
#ifdef KTHREAD_SUPPORT
|
|
#define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
|
|
{ \
|
|
wait_event_interruptible(_pTask->kthread_q, \
|
|
_pTask->kthread_running || kthread_should_stop()); \
|
|
_pTask->kthread_running = FALSE; \
|
|
if (kthread_should_stop()) \
|
|
{ \
|
|
RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
|
|
break; \
|
|
} \
|
|
}
|
|
#endif
|
|
|
|
#ifdef KTHREAD_SUPPORT
|
|
#define WAKE_UP(_pTask) \
|
|
do{ \
|
|
if ((_pTask)->kthread_task) \
|
|
{ \
|
|
(_pTask)->kthread_running = TRUE; \
|
|
wake_up(&(_pTask)->kthread_q); \
|
|
} \
|
|
}while(0)
|
|
#endif
|
|
|
|
/***********************************************************************************
|
|
* OS Memory Access related data structure and definitions
|
|
***********************************************************************************/
|
|
#define MEM_ALLOC_FLAG (GFP_ATOMIC) /*(GFP_DMA | GFP_ATOMIC) */
|
|
|
|
#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
|
|
#define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
|
|
#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
|
|
#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
|
|
#define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
|
|
#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
|
|
#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
|
|
|
|
#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
|
|
#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
|
|
|
|
#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
|
|
|
|
/***********************************************************************************
|
|
* OS task related data structure and definitions
|
|
***********************************************************************************/
|
|
#define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
|
|
|
|
#define THREAD_PID_INIT_VALUE NULL
|
|
#define GET_PID(_v) find_get_pid((_v))
|
|
#define GET_PID_NUMBER(_v) pid_nr((_v))
|
|
#define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0)
|
|
#define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
|
|
|
|
/***********************************************************************************
|
|
* Timer related definitions and data structures.
|
|
**********************************************************************************/
|
|
#define OS_HZ HZ
|
|
|
|
typedef void (*TIMER_FUNCTION) (unsigned long);
|
|
|
|
#define OS_WAIT(_time) \
|
|
{ int _i; \
|
|
long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
|
|
wait_queue_head_t _wait; \
|
|
init_waitqueue_head(&_wait); \
|
|
for (_i=0; _i<(_loop); _i++) \
|
|
wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
|
|
|
|
#define RTMP_TIME_AFTER(a,b) \
|
|
(typecheck(unsigned long, (unsigned long)a) && \
|
|
typecheck(unsigned long, (unsigned long)b) && \
|
|
((long)(b) - (long)(a) < 0))
|
|
|
|
#define RTMP_TIME_AFTER_EQ(a,b) \
|
|
(typecheck(unsigned long, (unsigned long)a) && \
|
|
typecheck(unsigned long, (unsigned long)b) && \
|
|
((long)(a) - (long)(b) >= 0))
|
|
#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
|
|
|
|
#define ONE_TICK 1
|
|
|
|
static inline void NdisGetSystemUpTime(unsigned long * time)
|
|
{
|
|
*time = jiffies;
|
|
}
|
|
|
|
/***********************************************************************************
|
|
* OS specific cookie data structure binding to struct rt_rtmp_adapter
|
|
***********************************************************************************/
|
|
|
|
struct os_cookie {
|
|
#ifdef RTMP_MAC_PCI
|
|
struct pci_dev *pci_dev;
|
|
struct pci_dev *parent_pci_dev;
|
|
u16 DeviceID;
|
|
dma_addr_t pAd_pa;
|
|
#endif /* RTMP_MAC_PCI // */
|
|
#ifdef RTMP_MAC_USB
|
|
struct usb_device *pUsb_Dev;
|
|
#endif /* RTMP_MAC_USB // */
|
|
|
|
struct tasklet_struct rx_done_task;
|
|
struct tasklet_struct mgmt_dma_done_task;
|
|
struct tasklet_struct ac0_dma_done_task;
|
|
struct tasklet_struct ac1_dma_done_task;
|
|
struct tasklet_struct ac2_dma_done_task;
|
|
struct tasklet_struct ac3_dma_done_task;
|
|
struct tasklet_struct tbtt_task;
|
|
#ifdef RTMP_MAC_PCI
|
|
struct tasklet_struct fifo_statistic_full_task;
|
|
#endif /* RTMP_MAC_PCI // */
|
|
#ifdef RTMP_MAC_USB
|
|
struct tasklet_struct null_frame_complete_task;
|
|
struct tasklet_struct rts_frame_complete_task;
|
|
struct tasklet_struct pspoll_frame_complete_task;
|
|
#endif /* RTMP_MAC_USB // */
|
|
|
|
unsigned long apd_pid; /*802.1x daemon pid */
|
|
int ioctl_if_type;
|
|
int ioctl_if;
|
|
};
|
|
|
|
/***********************************************************************************
|
|
* OS debugging and printing related definitions and data structure
|
|
***********************************************************************************/
|
|
#define PRINT_MAC(addr) \
|
|
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
|
|
|
#ifdef DBG
|
|
extern unsigned long RTDebugLevel;
|
|
|
|
#define DBGPRINT_RAW(Level, Fmt) \
|
|
do{ \
|
|
if (Level <= RTDebugLevel) \
|
|
{ \
|
|
printk Fmt; \
|
|
} \
|
|
}while(0)
|
|
|
|
#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
|
|
|
|
#define DBGPRINT_ERR(Fmt) \
|
|
{ \
|
|
printk("ERROR! "); \
|
|
printk Fmt; \
|
|
}
|
|
|
|
#define DBGPRINT_S(Status, Fmt) \
|
|
{ \
|
|
printk Fmt; \
|
|
}
|
|
|
|
#else
|
|
#define DBGPRINT(Level, Fmt)
|
|
#define DBGPRINT_RAW(Level, Fmt)
|
|
#define DBGPRINT_S(Status, Fmt)
|
|
#define DBGPRINT_ERR(Fmt)
|
|
#endif
|
|
|
|
#define ASSERT(x)
|
|
|
|
void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
|
|
|
|
/*********************************************************************************************************
|
|
The following code are not revised, temporary put it here.
|
|
*********************************************************************************************************/
|
|
|
|
/***********************************************************************************
|
|
* Device DMA Access related definitions and data structures.
|
|
**********************************************************************************/
|
|
#ifdef RTMP_MAC_PCI
|
|
struct rt_rtmp_adapter;
|
|
dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr,
|
|
size_t size, int sd_idx, int direction);
|
|
void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr,
|
|
size_t size, int direction);
|
|
|
|
#define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
|
|
linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
|
|
|
|
#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
|
|
linux_pci_unmap_single(_handle, _ptr, _size, _dir)
|
|
|
|
#define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
|
|
pci_alloc_consistent(_pci_dev, _size, _ptr)
|
|
|
|
#define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
|
|
pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
|
|
|
|
#define DEV_ALLOC_SKB(_length) \
|
|
dev_alloc_skb(_length)
|
|
#endif /* RTMP_MAC_PCI // */
|
|
|
|
/*
|
|
* unsigned long
|
|
* RTMP_GetPhysicalAddressLow(
|
|
* dma_addr_t PhysicalAddress);
|
|
*/
|
|
#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
|
|
|
|
/*
|
|
* unsigned long
|
|
* RTMP_GetPhysicalAddressHigh(
|
|
* dma_addr_t PhysicalAddress);
|
|
*/
|
|
#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
|
|
|
|
/*
|
|
* void
|
|
* RTMP_SetPhysicalAddressLow(
|
|
* dma_addr_t PhysicalAddress,
|
|
* unsigned long Value);
|
|
*/
|
|
#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
|
|
PhysicalAddress = Value;
|
|
|
|
/*
|
|
* void
|
|
* RTMP_SetPhysicalAddressHigh(
|
|
* dma_addr_t PhysicalAddress,
|
|
* unsigned long Value);
|
|
*/
|
|
#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
|
|
|
|
#define NdisMIndicateStatus(_w, _x, _y, _z)
|
|
|
|
/***********************************************************************************
|
|
* Device Register I/O Access related definitions and data structures.
|
|
**********************************************************************************/
|
|
#ifdef RTMP_MAC_PCI
|
|
/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
|
|
#define RTMP_IO_READ32(_A, _R, _pV) \
|
|
{ \
|
|
if ((_A)->bPCIclkOff == FALSE) \
|
|
{ \
|
|
(*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
|
|
(*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
|
|
} \
|
|
else \
|
|
*_pV = 0; \
|
|
}
|
|
|
|
#define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
|
|
{ \
|
|
(*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
|
|
(*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
|
|
}
|
|
|
|
#define RTMP_IO_READ8(_A, _R, _pV) \
|
|
{ \
|
|
(*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
|
|
(*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
|
|
}
|
|
#define RTMP_IO_WRITE32(_A, _R, _V) \
|
|
{ \
|
|
if ((_A)->bPCIclkOff == FALSE) \
|
|
{ \
|
|
u32 Val; \
|
|
Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
|
|
writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
|
|
} \
|
|
}
|
|
|
|
#define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
|
|
{ \
|
|
u32 Val; \
|
|
Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
|
|
writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
|
|
}
|
|
|
|
#if defined(RALINK_2880) || defined(RALINK_3052)
|
|
#define RTMP_IO_WRITE8(_A, _R, _V) \
|
|
{ \
|
|
unsigned long Val; \
|
|
u8 _i; \
|
|
_i = ((_R) & 0x3); \
|
|
Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
|
|
Val = Val & (~(0x000000ff << ((_i)*8))); \
|
|
Val = Val | ((unsigned long)(_V) << ((_i)*8)); \
|
|
writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
|
|
}
|
|
#else
|
|
#define RTMP_IO_WRITE8(_A, _R, _V) \
|
|
{ \
|
|
u32 Val; \
|
|
Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
|
|
writeb((_V), (u8 *)((_A)->CSRBaseAddress + (_R))); \
|
|
}
|
|
#endif /* #if defined(BRCM_6358) || defined(RALINK_2880) // */
|
|
|
|
#define RTMP_IO_WRITE16(_A, _R, _V) \
|
|
{ \
|
|
u32 Val; \
|
|
Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
|
|
writew((_V), (u16 *)((_A)->CSRBaseAddress + (_R))); \
|
|
}
|
|
#endif /* RTMP_MAC_PCI // */
|
|
#ifdef RTMP_MAC_USB
|
|
/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
|
|
#define RTMP_IO_READ32(_A, _R, _pV) \
|
|
RTUSBReadMACRegister((_A), (_R), (u32 *)(_pV))
|
|
|
|
#define RTMP_IO_READ8(_A, _R, _pV) \
|
|
{ \
|
|
}
|
|
|
|
#define RTMP_IO_WRITE32(_A, _R, _V) \
|
|
RTUSBWriteMACRegister((_A), (_R), (u32)(_V))
|
|
|
|
#define RTMP_IO_WRITE8(_A, _R, _V) \
|
|
{ \
|
|
u16 _Val = _V; \
|
|
RTUSBSingleWrite((_A), (_R), (u16)(_Val)); \
|
|
}
|
|
|
|
#define RTMP_IO_WRITE16(_A, _R, _V) \
|
|
{ \
|
|
RTUSBSingleWrite((_A), (_R), (u16)(_V)); \
|
|
}
|
|
#endif /* RTMP_MAC_USB // */
|
|
|
|
/***********************************************************************************
|
|
* Network Related data structure and marco definitions
|
|
***********************************************************************************/
|
|
#define PKTSRC_NDIS 0x7f
|
|
#define PKTSRC_DRIVER 0x0f
|
|
|
|
#define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
|
|
#define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
|
|
#define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
|
|
#define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
|
|
|
|
#define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
|
|
#define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
|
|
#define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
|
|
#define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
|
|
|
|
#define QUEUE_ENTRY_TO_PACKET(pEntry) \
|
|
(void *)(pEntry)
|
|
|
|
#define PACKET_TO_QUEUE_ENTRY(pPacket) \
|
|
(struct rt_queue_entry *)(pPacket)
|
|
|
|
#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
|
|
rt_get_sg_list_from_packet(_p, _sc)
|
|
|
|
#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
|
|
{ \
|
|
RTMPFreeNdisPacket(_pAd, _pPacket); \
|
|
}
|
|
|
|
/*
|
|
* packet helper
|
|
* - convert internal rt packet to os packet or
|
|
* os packet to rt packet
|
|
*/
|
|
#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
|
|
#define OSPKT_TO_RTPKT(_p) ((void *)(_p))
|
|
|
|
#define GET_OS_PKT_DATAPTR(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->data)
|
|
#define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
|
|
(RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
|
|
|
|
#define GET_OS_PKT_LEN(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->len)
|
|
#define SET_OS_PKT_LEN(_pkt, _len) \
|
|
(RTPKT_TO_OSPKT(_pkt)->len) = (_len)
|
|
|
|
#define GET_OS_PKT_DATATAIL(_pkt) \
|
|
(skb_tail_pointer(RTPKT_TO_OSPKT(_pkt))
|
|
#define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
|
|
(skb_set_tail_pointer(RTPKT_TO_OSPKT(_pkt), _len))
|
|
|
|
#define GET_OS_PKT_HEAD(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->head)
|
|
|
|
#define GET_OS_PKT_END(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->end)
|
|
|
|
#define GET_OS_PKT_NETDEV(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->dev)
|
|
#define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
|
|
(RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
|
|
|
|
#define GET_OS_PKT_TYPE(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt))
|
|
|
|
#define GET_OS_PKT_NEXT(_pkt) \
|
|
(RTPKT_TO_OSPKT(_pkt)->next)
|
|
|
|
#define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
|
|
|
|
#define OS_NTOHS(_Val) \
|
|
(ntohs(_Val))
|
|
#define OS_HTONS(_Val) \
|
|
(htons(_Val))
|
|
#define OS_NTOHL(_Val) \
|
|
(ntohl(_Val))
|
|
#define OS_HTONL(_Val) \
|
|
(htonl(_Val))
|
|
|
|
#define CB_OFF 10
|
|
|
|
/* User Priority */
|
|
#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
|
|
#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
|
|
|
|
/* Fragment # */
|
|
#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
|
|
#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
|
|
|
|
/* 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. */
|
|
/*(this value also as MAC(on-chip WCID) table index) */
|
|
/* 0x80~0xff: TX to a WDS link. b0~6: WDS index */
|
|
#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
|
|
#define RTMP_GET_PACKET_WCID(_p) ((u8)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
|
|
|
|
/* 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet */
|
|
#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
|
|
#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
|
|
|
|
/* RTS/CTS-to-self protection method */
|
|
#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
|
|
#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
|
|
/* see RTMP_S(G)ET_PACKET_EMACTAB */
|
|
|
|
/* TX rate index */
|
|
#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
|
|
#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
|
|
|
|
/* From which Interface */
|
|
#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
|
|
#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
|
|
#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
|
|
#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
|
|
#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
|
|
#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
|
|
#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
|
|
#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
|
|
|
|
#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
|
|
#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
|
|
|
|
/* */
|
|
/* Sepcific Pakcet Type definition */
|
|
/* */
|
|
#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
|
|
|
|
#define RTMP_PACKET_SPECIFIC_DHCP 0x01
|
|
#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
|
|
#define RTMP_PACKET_SPECIFIC_IPV4 0x04
|
|
#define RTMP_PACKET_SPECIFIC_WAI 0x08
|
|
#define RTMP_PACKET_SPECIFIC_VLAN 0x10
|
|
#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
|
|
|
|
/*Specific */
|
|
#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
|
|
|
|
/*DHCP */
|
|
#define RTMP_SET_PACKET_DHCP(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
|
|
}while(0)
|
|
#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
|
|
|
|
/*EAPOL */
|
|
#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
|
|
}while(0)
|
|
#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
|
|
|
|
/*WAI */
|
|
#define RTMP_SET_PACKET_WAI(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
|
|
}while(0)
|
|
#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
|
|
|
|
#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))
|
|
|
|
/*VLAN */
|
|
#define RTMP_SET_PACKET_VLAN(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
|
|
}while(0)
|
|
#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
|
|
|
|
/*LLC/SNAP */
|
|
#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
|
|
}while(0)
|
|
|
|
#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
|
|
|
|
/* IP */
|
|
#define RTMP_SET_PACKET_IPV4(_p, _flg) \
|
|
do{ \
|
|
if (_flg) \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
|
|
else \
|
|
(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
|
|
}while(0)
|
|
|
|
#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
|
|
|
|
/* If this flag is set, it indicates that this EAPoL frame MUST be clear. */
|
|
#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
|
|
#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
|
|
|
|
/* use bit3 of cb[CB_OFF+16] */
|
|
|
|
#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
|
|
#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
|
|
|
|
/* Max skb->cb = 48B = [CB_OFF+38] */
|
|
|
|
/***********************************************************************************
|
|
* Other function prototypes definitions
|
|
***********************************************************************************/
|
|
void RTMP_GetCurrentSystemTime(LARGE_INTEGER * time);
|
|
int rt28xx_packet_xmit(struct sk_buff *skb);
|
|
|
|
#ifdef RTMP_MAC_PCI
|
|
/* function declarations */
|
|
#define IRQ_HANDLE_TYPE irqreturn_t
|
|
|
|
IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
|
|
#endif /* RTMP_MAC_PCI // */
|
|
|
|
int rt28xx_sta_ioctl(struct net_device *net_dev, IN OUT struct ifreq *rq, int cmd);
|
|
|
|
extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char * buf);
|
|
extern int ra_mtd_read(int num, loff_t from, size_t len, u_char * buf);
|
|
|
|
#define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (struct rt_rtmp_adapter *)(_net_dev)->ml_priv;
|
|
|
|
#endif /* __RT_LINUX_H__ // */
|