]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/rt2860/rt_linux.h
Staging: rt2860: add RT3090 chipset support
[net-next-2.6.git] / drivers / staging / rt2860 / rt_linux.h
CommitLineData
91980990
GKH
1/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
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. *
14 * *
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. *
19 * *
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. *
24 * *
25 *************************************************************************
91980990 26
ca97b838
BZ
27 Module Name:
28 rt_linux.h
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35*/
36
37#ifndef __RT_LINUX_H__
38#define __RT_LINUX_H__
39
91980990 40#include <linux/module.h>
91980990 41#include <linux/kernel.h>
91980990
GKH
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>
60
91980990
GKH
61#include <net/iw_handler.h>
62
63// load firmware
64#define __KERNEL_SYSCALLS__
65#include <linux/unistd.h>
66#include <asm/uaccess.h>
ca97b838
BZ
67#include <asm/types.h>
68#include <asm/unaligned.h> // for get_unaligned()
91980990 69
ca97b838
BZ
70#define KTHREAD_SUPPORT 1
71// RT2870 2.1.0.0 has it disabled
91980990 72
ca97b838
BZ
73#ifdef KTHREAD_SUPPORT
74#include <linux/err.h>
75#include <linux/kthread.h>
76#endif // KTHREAD_SUPPORT //
77
78#undef AP_WSC_INCLUDED
79#undef STA_WSC_INCLUDED
80#undef WSC_INCLUDED
81
82
83
84
85#ifdef KTHREAD_SUPPORT
86#endif // KTHREAD_SUPPORT //
87
88/***********************************************************************************
89 * Profile related sections
90 ***********************************************************************************/
91980990 91
91980990 92
ca97b838
BZ
93#ifdef RTMP_MAC_PCI
94#define STA_PROFILE_PATH "/etc/Wireless/RT2860STA/RT2860STA.dat"
95#define STA_DRIVER_VERSION "2.1.0.0"
96#endif // RTMP_MAC_PCI //
97#ifdef RTMP_MAC_USB
98#define STA_PROFILE_PATH "/etc/Wireless/RT2870STA/RT2870STA.dat"
99#define STA_DRIVER_VERSION "2.1.0.0"
100// RT3070 version: 2.1.1.0
101#endif // RTMP_MAC_USB //
91980990 102
ca97b838
BZ
103extern const struct iw_handler_def rt28xx_iw_handler_def;
104
105
106/***********************************************************************************
107 * Compiler related definitions
108 ***********************************************************************************/
91980990
GKH
109#undef __inline
110#define __inline static inline
ca97b838
BZ
111#define IN
112#define OUT
113#define INOUT
114#define NDIS_STATUS INT
91980990 115
91980990 116
ca97b838
BZ
117/***********************************************************************************
118 * OS Specific definitions and data structures
119 ***********************************************************************************/
120typedef struct pci_dev * PPCI_DEV;
121typedef struct net_device * PNET_DEV;
122typedef void * PNDIS_PACKET;
123typedef char NDIS_PACKET;
124typedef PNDIS_PACKET * PPNDIS_PACKET;
125typedef dma_addr_t NDIS_PHYSICAL_ADDRESS;
126typedef dma_addr_t * PNDIS_PHYSICAL_ADDRESS;
127typedef void * NDIS_HANDLE;
128typedef char * PNDIS_BUFFER;
129typedef struct pid * RTMP_OS_PID;
130typedef struct semaphore RTMP_OS_SEM;
131
132typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
91980990 133
ca97b838 134#ifdef RTMP_MAC_PCI
91980990
GKH
135#ifndef PCI_DEVICE
136#define PCI_DEVICE(vend,dev) \
137 .vendor = (vend), .device = (dev), \
138 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
139#endif // PCI_DEVICE //
ca97b838 140#endif // RTMP_MAC_PCI //
91980990 141
91980990
GKH
142#define RT_MOD_INC_USE_COUNT() \
143 if (!try_module_get(THIS_MODULE)) \
144 { \
d599edca 145 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
91980990
GKH
146 return -1; \
147 }
148
149#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
91980990 150
ca97b838
BZ
151#define RTMP_INC_REF(_A) 0
152#define RTMP_DEC_REF(_A) 0
153#define RTMP_GET_REF(_A) 0
91980990 154
91980990 155
ca97b838
BZ
156// This function will be called when query /proc
157struct iw_statistics *rt28xx_get_wireless_stats(
158 IN struct net_device *net_dev);
159
160
161/***********************************************************************************
162 * Network related constant definitions
163 ***********************************************************************************/
164#ifndef IFNAMSIZ
165#define IFNAMSIZ 16
166#endif
167
168#define ETH_LENGTH_OF_ADDRESS 6
91980990 169
91980990
GKH
170#define NDIS_STATUS_SUCCESS 0x00
171#define NDIS_STATUS_FAILURE 0x01
172#define NDIS_STATUS_INVALID_DATA 0x02
173#define NDIS_STATUS_RESOURCES 0x03
174
ca97b838
BZ
175#define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
176#define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
177
178/* statistics counter */
179#define STATS_INC_RX_PACKETS(_pAd, _dev)
180#define STATS_INC_TX_PACKETS(_pAd, _dev)
181
182#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
183#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
184
185#define STATS_INC_RX_ERRORS(_pAd, _dev)
186#define STATS_INC_TX_ERRORS(_pAd, _dev)
187
188#define STATS_INC_RX_DROPPED(_pAd, _dev)
189#define STATS_INC_TX_DROPPED(_pAd, _dev)
190
191
192/***********************************************************************************
193 * Ralink Specific network related constant definitions
194 ***********************************************************************************/
91980990
GKH
195#define MIN_NET_DEVICE_FOR_AID 0x00 //0x00~0x3f
196#define MIN_NET_DEVICE_FOR_MBSSID 0x00 //0x00,0x10,0x20,0x30
197#define MIN_NET_DEVICE_FOR_WDS 0x10 //0x40,0x50,0x60,0x70
198#define MIN_NET_DEVICE_FOR_APCLI 0x20
199#define MIN_NET_DEVICE_FOR_MESH 0x30
91980990 200#define MIN_NET_DEVICE_FOR_DLS 0x40
ca97b838
BZ
201#define NET_DEVICE_REAL_IDX_MASK 0x0f // for each operation mode, we maximum support 15 entities.
202
91980990 203
91980990
GKH
204#define NDIS_PACKET_TYPE_DIRECTED 0
205#define NDIS_PACKET_TYPE_MULTICAST 1
206#define NDIS_PACKET_TYPE_BROADCAST 2
207#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
ca97b838
BZ
208#define NDIS_PACKET_TYPE_PROMISCUOUS 4
209
210
211/***********************************************************************************
212 * OS signaling related constant definitions
213 ***********************************************************************************/
214
215
216/***********************************************************************************
217 * OS file operation related data structure definitions
218 ***********************************************************************************/
219typedef struct file* RTMP_OS_FD;
220
221typedef struct _RTMP_OS_FS_INFO_
222{
223 int fsuid;
224 int fsgid;
225 mm_segment_t fs;
226}RTMP_OS_FS_INFO;
91980990 227
ca97b838
BZ
228#define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
229
230
231/***********************************************************************************
232 * OS semaphore related data structure and definitions
233 ***********************************************************************************/
91980990
GKH
234struct os_lock {
235 spinlock_t lock;
ca97b838 236 unsigned long flags;
91980990
GKH
237};
238
ca97b838 239typedef spinlock_t NDIS_SPIN_LOCK;
91980990 240
ca97b838
BZ
241//
242// spin_lock enhanced for Nested spin lock
243//
244#define NdisAllocateSpinLock(__lock) \
245{ \
246 spin_lock_init((spinlock_t *)(__lock)); \
247}
91980990 248
ca97b838
BZ
249#define NdisFreeSpinLock(lock) \
250 do{}while(0)
91980990 251
91980990 252
ca97b838
BZ
253#define RTMP_SEM_LOCK(__lock) \
254{ \
255 spin_lock_bh((spinlock_t *)(__lock)); \
256}
91980990 257
ca97b838
BZ
258#define RTMP_SEM_UNLOCK(__lock) \
259{ \
260 spin_unlock_bh((spinlock_t *)(__lock)); \
261}
91980990
GKH
262
263
ca97b838
BZ
264// sample, use semaphore lock to replace IRQ lock, 2007/11/15
265#define RTMP_IRQ_LOCK(__lock, __irqflags) \
266{ \
267 __irqflags = 0; \
268 spin_lock_bh((spinlock_t *)(__lock)); \
269 pAd->irq_disabled |= 1; \
270}
91980990 271
ca97b838
BZ
272#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
273{ \
274 pAd->irq_disabled &= 0; \
275 spin_unlock_bh((spinlock_t *)(__lock)); \
276}
91980990 277
ca97b838
BZ
278#define RTMP_INT_LOCK(__lock, __irqflags) \
279{ \
280 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
281}
91980990 282
ca97b838
BZ
283#define RTMP_INT_UNLOCK(__lock, __irqflag) \
284{ \
285 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
286}
91980990 287
ca97b838
BZ
288#define NdisAcquireSpinLock RTMP_SEM_LOCK
289#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
91980990 290
ca97b838
BZ
291#ifndef wait_event_interruptible_timeout
292#define __wait_event_interruptible_timeout(wq, condition, ret) \
293do { \
294 wait_queue_t __wait; \
295 init_waitqueue_entry(&__wait, current); \
296 add_wait_queue(&wq, &__wait); \
297 for (;;) { \
298 set_current_state(TASK_INTERRUPTIBLE); \
299 if (condition) \
300 break; \
301 if (!signal_pending(current)) { \
302 ret = schedule_timeout(ret); \
303 if (!ret) \
304 break; \
305 continue; \
306 } \
307 ret = -ERESTARTSYS; \
308 break; \
309 } \
310 current->state = TASK_RUNNING; \
311 remove_wait_queue(&wq, &__wait); \
312} while (0)
91980990 313
ca97b838
BZ
314#define wait_event_interruptible_timeout(wq, condition, timeout) \
315({ \
316 long __ret = timeout; \
317 if (!(condition)) \
318 __wait_event_interruptible_timeout(wq, condition, __ret); \
319 __ret; \
320})
321#endif
91980990 322
ca97b838
BZ
323#define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
324#define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
325#define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
326#define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
327
328#ifdef KTHREAD_SUPPORT
329#define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
330{ \
331 wait_event_interruptible(_pTask->kthread_q, \
332 _pTask->kthread_running || kthread_should_stop()); \
333 _pTask->kthread_running = FALSE; \
334 if (kthread_should_stop()) \
335 { \
336 RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
337 break; \
338 } \
339}
340#endif
91980990 341
ca97b838
BZ
342#ifdef KTHREAD_SUPPORT
343#define WAKE_UP(_pTask) \
344 do{ \
345 if ((_pTask)->kthread_task) \
346 { \
347 (_pTask)->kthread_running = TRUE; \
348 wake_up(&(_pTask)->kthread_q); \
349 } \
350 }while(0)
351#endif
91980990 352
ca97b838
BZ
353/***********************************************************************************
354 * OS Memory Access related data structure and definitions
355 ***********************************************************************************/
356#define MEM_ALLOC_FLAG (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
91980990 357
ca97b838
BZ
358#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
359#define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
360#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
361#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
362#define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
363#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
364#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
91980990 365
ca97b838
BZ
366#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
367#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
91980990 368
ca97b838 369#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
91980990
GKH
370
371
ca97b838
BZ
372/***********************************************************************************
373 * OS task related data structure and definitions
374 ***********************************************************************************/
375#define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
91980990 376
ca97b838
BZ
377typedef struct pid * THREAD_PID;
378#define THREAD_PID_INIT_VALUE NULL
379#define GET_PID(_v) find_get_pid((_v))
380#define GET_PID_NUMBER(_v) pid_nr((_v))
381#define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0)
382#define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
91980990 383
ca97b838
BZ
384typedef struct tasklet_struct RTMP_NET_TASK_STRUCT;
385typedef struct tasklet_struct *PRTMP_NET_TASK_STRUCT;
91980990
GKH
386
387
ca97b838
BZ
388/***********************************************************************************
389 * Timer related definitions and data structures.
390 **********************************************************************************/
391#define OS_HZ HZ
91980990 392
ca97b838 393typedef struct timer_list NDIS_MINIPORT_TIMER;
91980990 394typedef struct timer_list RTMP_OS_TIMER;
ca97b838 395typedef void (*TIMER_FUNCTION)(unsigned long);
91980990 396
3a32ed12 397
ca97b838
BZ
398#define OS_WAIT(_time) \
399{ int _i; \
400 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
401 wait_queue_head_t _wait; \
402 init_waitqueue_head(&_wait); \
403 for (_i=0; _i<(_loop); _i++) \
404 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
3a32ed12 405
ca97b838
BZ
406#define RTMP_TIME_AFTER(a,b) \
407 (typecheck(unsigned long, (unsigned long)a) && \
408 typecheck(unsigned long, (unsigned long)b) && \
409 ((long)(b) - (long)(a) < 0))
3a32ed12 410
ca97b838
BZ
411#define RTMP_TIME_AFTER_EQ(a,b) \
412 (typecheck(unsigned long, (unsigned long)a) && \
413 typecheck(unsigned long, (unsigned long)b) && \
414 ((long)(a) - (long)(b) >= 0))
415#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
416
417#define ONE_TICK 1
3a32ed12 418
ca97b838 419static inline void NdisGetSystemUpTime(ULONG *time)
3a32ed12 420{
ca97b838
BZ
421 *time = jiffies;
422}
91980990
GKH
423
424
ca97b838
BZ
425/***********************************************************************************
426 * OS specific cookie data structure binding to RTMP_ADAPTER
427 ***********************************************************************************/
428
429struct os_cookie {
430#ifdef RTMP_MAC_PCI
431 struct pci_dev *pci_dev;
432 struct pci_dev *parent_pci_dev;
433 USHORT DeviceID;
434 dma_addr_t pAd_pa;
435#endif // RTMP_MAC_PCI //
436#ifdef RTMP_MAC_USB
437 struct usb_device *pUsb_Dev;
438#endif // RTMP_MAC_USB //
439
440 RTMP_NET_TASK_STRUCT rx_done_task;
441 RTMP_NET_TASK_STRUCT mgmt_dma_done_task;
442 RTMP_NET_TASK_STRUCT ac0_dma_done_task;
443 RTMP_NET_TASK_STRUCT ac1_dma_done_task;
444 RTMP_NET_TASK_STRUCT ac2_dma_done_task;
445 RTMP_NET_TASK_STRUCT ac3_dma_done_task;
446 RTMP_NET_TASK_STRUCT tbtt_task;
447#ifdef RTMP_MAC_PCI
448 RTMP_NET_TASK_STRUCT fifo_statistic_full_task;
449#endif // RTMP_MAC_PCI //
450#ifdef RTMP_MAC_USB
451 RTMP_NET_TASK_STRUCT null_frame_complete_task;
452 RTMP_NET_TASK_STRUCT rts_frame_complete_task;
453 RTMP_NET_TASK_STRUCT pspoll_frame_complete_task;
454#endif // RTMP_MAC_USB //
455
456 unsigned long apd_pid; //802.1x daemon pid
457 INT ioctl_if_type;
458 INT ioctl_if;
459};
460
461typedef struct os_cookie * POS_COOKIE;
91980990 462
ca97b838
BZ
463
464
465/***********************************************************************************
466 * OS debugging and printing related definitions and data structure
467 ***********************************************************************************/
468#define PRINT_MAC(addr) \
469 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
91980990
GKH
470
471#ifdef DBG
472extern ULONG RTDebugLevel;
473
474#define DBGPRINT_RAW(Level, Fmt) \
ca97b838 475do{ \
91980990
GKH
476 if (Level <= RTDebugLevel) \
477 { \
478 printk Fmt; \
479 } \
ca97b838 480}while(0)
91980990
GKH
481
482#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
483
484
485#define DBGPRINT_ERR(Fmt) \
486{ \
487 printk("ERROR!!! "); \
488 printk Fmt; \
489}
490
491#define DBGPRINT_S(Status, Fmt) \
492{ \
493 printk Fmt; \
494}
495
496
497#else
498#define DBGPRINT(Level, Fmt)
499#define DBGPRINT_RAW(Level, Fmt)
500#define DBGPRINT_S(Status, Fmt)
501#define DBGPRINT_ERR(Fmt)
502#endif
503
ca97b838 504#define ASSERT(x)
91980990 505
ca97b838 506void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
91980990 507
91980990 508
ca97b838
BZ
509/*********************************************************************************************************
510 The following code are not revised, temporary put it here.
511 *********************************************************************************************************/
91980990 512
91980990 513
ca97b838
BZ
514/***********************************************************************************
515 * Device DMA Access related definitions and data structures.
516 **********************************************************************************/
517#ifdef RTMP_MAC_PCI
518dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
519void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
91980990 520
ca97b838
BZ
521#define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
522 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
91980990 523
ca97b838
BZ
524#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
525 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
91980990 526
ca97b838
BZ
527#define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
528 pci_alloc_consistent(_pci_dev, _size, _ptr)
91980990 529
ca97b838
BZ
530#define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
531 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
532
533#define DEV_ALLOC_SKB(_length) \
534 dev_alloc_skb(_length)
535#endif // RTMP_MAC_PCI //
536#ifdef RTMP_MAC_USB
537#define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
91980990 538
ca97b838
BZ
539#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
540#endif // RTMP_MAC_USB //
541
542/*
543 * ULONG
544 * RTMP_GetPhysicalAddressLow(
545 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
546 */
547#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
548
549/*
550 * ULONG
551 * RTMP_GetPhysicalAddressHigh(
552 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress);
553 */
554#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
555
556/*
557 * VOID
558 * RTMP_SetPhysicalAddressLow(
559 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
560 * IN ULONG Value);
561 */
562#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
563 PhysicalAddress = Value;
564
565/*
566 * VOID
567 * RTMP_SetPhysicalAddressHigh(
568 * IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
569 * IN ULONG Value);
570 */
571#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
572
573#define NdisMIndicateStatus(_w, _x, _y, _z)
574
575
576
577/***********************************************************************************
578 * Device Register I/O Access related definitions and data structures.
579 **********************************************************************************/
580#ifdef RTMP_MAC_PCI
91980990
GKH
581//Patch for ASIC turst read/write bug, needs to remove after metel fix
582#define RTMP_IO_READ32(_A, _R, _pV) \
583{ \
584 if ((_A)->bPCIclkOff == FALSE) \
585 { \
586 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
587 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
588 } \
589 else \
590 *_pV = 0; \
591}
ca97b838 592
e44fd1cf
BZ
593#define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
594{ \
595 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
596 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
597}
598
91980990
GKH
599#define RTMP_IO_READ8(_A, _R, _pV) \
600{ \
601 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
602 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
603}
604#define RTMP_IO_WRITE32(_A, _R, _V) \
605{ \
606 if ((_A)->bPCIclkOff == FALSE) \
607 { \
608 UINT Val; \
609 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
ca97b838 610 writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
91980990
GKH
611 } \
612}
ca97b838 613
e44fd1cf
BZ
614#define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
615{ \
616 UINT Val; \
617 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
618 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
619}
ca97b838
BZ
620
621#if defined(RALINK_2880) || defined(RALINK_3052)
622#define RTMP_IO_WRITE8(_A, _R, _V) \
623{ \
624 ULONG Val; \
625 UCHAR _i; \
626 _i = ((_R) & 0x3); \
627 Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
628 Val = Val & (~(0x000000ff << ((_i)*8))); \
629 Val = Val | ((ULONG)(_V) << ((_i)*8)); \
630 writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
631}
632#else
91980990
GKH
633#define RTMP_IO_WRITE8(_A, _R, _V) \
634{ \
635 UINT Val; \
636 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
637 writeb((_V), (PUCHAR)((_A)->CSRBaseAddress + (_R))); \
638}
ca97b838
BZ
639#endif // #if defined(BRCM_6358) || defined(RALINK_2880) //
640
91980990
GKH
641#define RTMP_IO_WRITE16(_A, _R, _V) \
642{ \
643 UINT Val; \
644 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
645 writew((_V), (PUSHORT)((_A)->CSRBaseAddress + (_R))); \
646}
ca97b838
BZ
647#endif // RTMP_MAC_PCI //
648#ifdef RTMP_MAC_USB
3a32ed12
BZ
649//Patch for ASIC turst read/write bug, needs to remove after metel fix
650#define RTMP_IO_READ32(_A, _R, _pV) \
ca97b838 651 RTUSBReadMACRegister((_A), (_R), (PUINT32) (_pV))
3a32ed12
BZ
652
653#define RTMP_IO_READ8(_A, _R, _pV) \
654{ \
655}
91980990 656
3a32ed12 657#define RTMP_IO_WRITE32(_A, _R, _V) \
ca97b838 658 RTUSBWriteMACRegister((_A), (_R), (UINT32) (_V))
3a32ed12
BZ
659
660#define RTMP_IO_WRITE8(_A, _R, _V) \
661{ \
662 USHORT _Val = _V; \
ca97b838 663 RTUSBSingleWrite((_A), (_R), (USHORT) (_Val)); \
3a32ed12
BZ
664}
665
3a32ed12
BZ
666#define RTMP_IO_WRITE16(_A, _R, _V) \
667{ \
ca97b838 668 RTUSBSingleWrite((_A), (_R), (USHORT) (_V)); \
3a32ed12 669}
ca97b838 670#endif // RTMP_MAC_USB //
91980990 671
ca97b838
BZ
672/***********************************************************************************
673 * Network Related data structure and marco definitions
674 ***********************************************************************************/
675#define PKTSRC_NDIS 0x7f
676#define PKTSRC_DRIVER 0x0f
91980990 677
ca97b838
BZ
678#define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
679#define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
680#define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
681#define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
91980990 682
ca97b838
BZ
683#define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
684#define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
685#define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
686#define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
91980990 687
ca97b838
BZ
688#define QUEUE_ENTRY_TO_PACKET(pEntry) \
689 (PNDIS_PACKET)(pEntry)
91980990 690
ca97b838
BZ
691#define PACKET_TO_QUEUE_ENTRY(pPacket) \
692 (PQUEUE_ENTRY)(pPacket)
91980990 693
ca97b838
BZ
694#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
695 rt_get_sg_list_from_packet(_p, _sc)
91980990 696
ca97b838
BZ
697#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
698{ \
699 RTMPFreeNdisPacket(_pAd, _pPacket); \
3a32ed12 700}
91980990
GKH
701
702/*
703 * packet helper
704 * - convert internal rt packet to os packet or
705 * os packet to rt packet
706 */
707#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
708#define OSPKT_TO_RTPKT(_p) ((PNDIS_PACKET)(_p))
709
710#define GET_OS_PKT_DATAPTR(_pkt) \
711 (RTPKT_TO_OSPKT(_pkt)->data)
ca97b838
BZ
712#define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
713 (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
91980990
GKH
714
715#define GET_OS_PKT_LEN(_pkt) \
716 (RTPKT_TO_OSPKT(_pkt)->len)
ca97b838
BZ
717#define SET_OS_PKT_LEN(_pkt, _len) \
718 (RTPKT_TO_OSPKT(_pkt)->len) = (_len)
91980990
GKH
719
720#define GET_OS_PKT_DATATAIL(_pkt) \
721 (RTPKT_TO_OSPKT(_pkt)->tail)
ca97b838
BZ
722#define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
723 ((RTPKT_TO_OSPKT(_pkt))->tail) = (PUCHAR)((_start) + (_len))
91980990
GKH
724
725#define GET_OS_PKT_HEAD(_pkt) \
726 (RTPKT_TO_OSPKT(_pkt)->head)
727
728#define GET_OS_PKT_END(_pkt) \
729 (RTPKT_TO_OSPKT(_pkt)->end)
730
731#define GET_OS_PKT_NETDEV(_pkt) \
732 (RTPKT_TO_OSPKT(_pkt)->dev)
ca97b838
BZ
733#define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
734 (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
91980990
GKH
735
736#define GET_OS_PKT_TYPE(_pkt) \
737 (RTPKT_TO_OSPKT(_pkt))
738
739#define GET_OS_PKT_NEXT(_pkt) \
740 (RTPKT_TO_OSPKT(_pkt)->next)
741
742
ca97b838
BZ
743#define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
744
91980990
GKH
745#define OS_NTOHS(_Val) \
746 (ntohs(_Val))
747#define OS_HTONS(_Val) \
748 (htons(_Val))
749#define OS_NTOHL(_Val) \
750 (ntohl(_Val))
751#define OS_HTONL(_Val) \
752 (htonl(_Val))
753
91980990
GKH
754#define CB_OFF 10
755
91980990
GKH
756// User Priority
757#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
758#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
759
760// Fragment #
761#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
762#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
763
764// 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.
765//(this value also as MAC(on-chip WCID) table index)
766// 0x80~0xff: TX to a WDS link. b0~6: WDS index
767#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
768#define RTMP_GET_PACKET_WCID(_p) ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
769
770// 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
771#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
772#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
773
774// RTS/CTS-to-self protection method
775#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
776#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
777// see RTMP_S(G)ET_PACKET_EMACTAB
778
779// TX rate index
780#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
781#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
782
783// From which Interface
784#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
785#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
786#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
787#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
788#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
789#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
790#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
791#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
792
793#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
794#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
795
796
91980990
GKH
797//
798// Sepcific Pakcet Type definition
799//
800#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
801
802#define RTMP_PACKET_SPECIFIC_DHCP 0x01
803#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
804#define RTMP_PACKET_SPECIFIC_IPV4 0x04
805#define RTMP_PACKET_SPECIFIC_WAI 0x08
806#define RTMP_PACKET_SPECIFIC_VLAN 0x10
807#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
808
809//Specific
810#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
811
812//DHCP
813#define RTMP_SET_PACKET_DHCP(_p, _flg) \
814 do{ \
815 if (_flg) \
816 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
817 else \
818 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
819 }while(0)
820#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
821
822//EAPOL
823#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
824 do{ \
825 if (_flg) \
826 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
827 else \
828 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
829 }while(0)
830#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
831
832//WAI
833#define RTMP_SET_PACKET_WAI(_p, _flg) \
834 do{ \
835 if (_flg) \
836 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
837 else \
838 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
839 }while(0)
840#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
841
842#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))
843
844//VLAN
845#define RTMP_SET_PACKET_VLAN(_p, _flg) \
846 do{ \
847 if (_flg) \
848 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
849 else \
850 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
851 }while(0)
852#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
853
854//LLC/SNAP
855#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
856 do{ \
857 if (_flg) \
858 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
859 else \
860 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
861 }while(0)
862
863#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
864
865// IP
866#define RTMP_SET_PACKET_IPV4(_p, _flg) \
867 do{ \
868 if (_flg) \
869 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
870 else \
871 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
872 }while(0)
873
874#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
875
91980990
GKH
876
877// If this flag is set, it indicates that this EAPoL frame MUST be clear.
878#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
879#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
880
91980990 881
91980990 882
ca97b838 883/* use bit3 of cb[CB_OFF+16] */
91980990 884
ca97b838
BZ
885#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
886#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
91980990 887
ca97b838 888/* Max skb->cb = 48B = [CB_OFF+38] */
91980990 889
91980990 890
91980990 891
ca97b838
BZ
892/***********************************************************************************
893 * Other function prototypes definitions
894 ***********************************************************************************/
895void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
91980990
GKH
896int rt28xx_packet_xmit(struct sk_buff *skb);
897
ca97b838
BZ
898#ifdef RTMP_MAC_PCI
899/* function declarations */
900#define IRQ_HANDLE_TYPE irqreturn_t
91980990 901
ca97b838
BZ
902IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
903#endif // RTMP_MAC_PCI //
91980990 904
ca97b838
BZ
905INT rt28xx_sta_ioctl(
906 IN PNET_DEV net_dev,
907 IN OUT struct ifreq *rq,
908 IN INT cmd);
91980990 909
ca97b838
BZ
910extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char *buf);
911extern int ra_mtd_read(int num, loff_t from, size_t len, u_char *buf);
91980990 912
ca97b838 913#define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (PRTMP_ADAPTER)(_net_dev)->ml_priv;
91980990 914
ca97b838 915#endif // __RT_LINUX_H__ //