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