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