Staging: rt2870: remove dead code
[linux-2.6] / drivers / staging / rt2870 / 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
28 /***********************************************************************/
29 /*                                                                     */
30 /*   Program:    rt_linux.c                                            */
31 /*   Created:    4/21/2006 1:17:38 PM                                  */
32 /*   Author:     Wu Xi-Kun                                             */
33 /*   Comments:   `description`                                         */
34 /*                                                                     */
35 /*---------------------------------------------------------------------*/
36 /*                                                                     */
37 /* History:                                                            */
38 /*    Revision 1.1 4/21/2006 1:17:38 PM  xsikun                        */
39 /*    Initial revision                                                 */
40 /*                                                                     */
41 /***********************************************************************/
42
43 #include "rtmp_type.h"
44 #include <linux/module.h>
45 #include <linux/version.h>
46 #include <linux/kernel.h>
47 #include <linux/kthread.h>
48
49 #include <linux/spinlock.h>
50 #include <linux/init.h>
51 #include <linux/string.h>
52 #include <linux/timer.h>
53 #include <linux/errno.h>
54 #include <linux/slab.h>
55 #include <linux/interrupt.h>
56 #include <linux/pci.h>
57 #include <linux/netdevice.h>
58 #include <linux/etherdevice.h>
59 #include <linux/skbuff.h>
60 #include <linux/ethtool.h>
61 #include <linux/wireless.h>
62 #include <linux/proc_fs.h>
63 #include <linux/delay.h>
64 #include <linux/if_arp.h>
65 #include <linux/ctype.h>
66 #include <linux/vmalloc.h>
67
68
69 #include <net/iw_handler.h>
70
71 // load firmware
72 #define __KERNEL_SYSCALLS__
73 #include <linux/unistd.h>
74 #include <asm/uaccess.h>
75
76
77 #define MEM_ALLOC_FLAG      (GFP_ATOMIC) //(GFP_DMA | GFP_ATOMIC)
78
79 #ifndef IFNAMSIZ
80 #define IFNAMSIZ 16
81 #endif
82
83 //#define CONFIG_CKIP_SUPPORT
84
85 #undef __inline
86 #define __inline           static inline
87
88 typedef int (*HARD_START_XMIT_FUNC)(struct sk_buff *skb, struct net_device *net_dev);
89
90 // add by kathy
91
92 #ifdef RT2870
93 #define STA_PROFILE_PATH                        "/etc/Wireless/RT2870STA/RT2870STA.dat"
94 #define STA_RT2870_IMAGE_FILE_NAME  "/etc/Wireless/RT2870STA/rt2870.bin"
95 #define STA_NIC_DEVICE_NAME                     "RT2870STA"
96 #define STA_DRIVER_VERSION                      "1.4.0.0"
97 #endif // RT2870 //
98
99 #define RTMP_TIME_AFTER(a,b)            \
100         (typecheck(unsigned long, (unsigned long)a) && \
101          typecheck(unsigned long, (unsigned long)b) && \
102          ((long)(b) - (long)(a) < 0))
103
104 #define RTMP_TIME_AFTER_EQ(a,b) \
105         (typecheck(unsigned long, (unsigned long)a) && \
106          typecheck(unsigned long, (unsigned long)b) && \
107          ((long)(a) - (long)(b) >= 0))
108 #define RTMP_TIME_BEFORE(a,b)   RTMP_TIME_AFTER_EQ(b,a)
109
110 #define RT_MOD_INC_USE_COUNT() \
111         if (!try_module_get(THIS_MODULE)) \
112         { \
113                 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
114                 return -1; \
115         }
116
117 #define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
118
119 #define OS_HZ                   HZ
120
121 #define ETH_LENGTH_OF_ADDRESS   6
122
123 #define IN
124 #define OUT
125
126 #define NDIS_STATUS                             INT
127 #define NDIS_STATUS_SUCCESS                     0x00
128 #define NDIS_STATUS_FAILURE                     0x01
129 #define NDIS_STATUS_INVALID_DATA                                0x02
130 #define NDIS_STATUS_RESOURCES                   0x03
131
132 #define MIN_NET_DEVICE_FOR_AID                  0x00            //0x00~0x3f
133 #define MIN_NET_DEVICE_FOR_MBSSID               0x00            //0x00,0x10,0x20,0x30
134 #define MIN_NET_DEVICE_FOR_WDS                  0x10            //0x40,0x50,0x60,0x70
135 #define MIN_NET_DEVICE_FOR_APCLI                0x20
136 #define MIN_NET_DEVICE_FOR_MESH                 0x30
137 #define MIN_NET_DEVICE_FOR_DLS                  0x40
138
139 #define NDIS_PACKET_TYPE_DIRECTED               0
140 #define NDIS_PACKET_TYPE_MULTICAST              1
141 #define NDIS_PACKET_TYPE_BROADCAST              2
142 #define NDIS_PACKET_TYPE_ALL_MULTICAST  3
143
144 typedef struct pid *    THREAD_PID;
145 #define GET_PID(_v)     find_get_pid(_v)
146 #define GET_PID_NUMBER(_v)      pid_nr(_v)
147 #define CHECK_PID_LEGALITY(_pid)        if (pid_nr(_pid) >= 0)
148 #define KILL_THREAD_PID(_A, _B, _C)     kill_pid(_A, _B, _C)
149
150 struct os_lock  {
151         spinlock_t              lock;
152         unsigned long   flags;
153 };
154
155
156 struct os_cookie {
157
158 #ifdef RT2870
159         struct usb_device       *pUsb_Dev;
160
161         struct task_struct      *MLMEThr_task;
162         struct task_struct      *RTUSBCmdThr_task;
163         struct task_struct      *TimerQThr_task;
164 #endif // RT2870 //
165
166         struct tasklet_struct   rx_done_task;
167         struct tasklet_struct   mgmt_dma_done_task;
168         struct tasklet_struct   ac0_dma_done_task;
169         struct tasklet_struct   ac1_dma_done_task;
170         struct tasklet_struct   ac2_dma_done_task;
171         struct tasklet_struct   ac3_dma_done_task;
172         struct tasklet_struct   hcca_dma_done_task;
173         struct tasklet_struct   tbtt_task;
174 #ifdef RT2870
175         struct tasklet_struct   null_frame_complete_task;
176         struct tasklet_struct   rts_frame_complete_task;
177         struct tasklet_struct   pspoll_frame_complete_task;
178 #endif // RT2870 //
179
180
181         unsigned long                   apd_pid; //802.1x daemon pid
182         INT                                             ioctl_if_type;
183         INT                                     ioctl_if;
184 };
185
186 typedef struct _VIRTUAL_ADAPTER
187 {
188         struct net_device               *RtmpDev;
189         struct net_device               *VirtualDev;
190 } VIRTUAL_ADAPTER, PVIRTUAL_ADAPTER;
191
192 #undef  ASSERT
193 #define ASSERT(x)
194
195 typedef struct os_cookie        * POS_COOKIE;
196 typedef struct pci_dev          * PPCI_DEV;
197 typedef struct net_device       * PNET_DEV;
198 typedef void                            * PNDIS_PACKET;
199 typedef char                            NDIS_PACKET;
200 typedef PNDIS_PACKET            * PPNDIS_PACKET;
201 typedef dma_addr_t                      NDIS_PHYSICAL_ADDRESS;
202 typedef dma_addr_t                      * PNDIS_PHYSICAL_ADDRESS;
203 typedef spinlock_t                      NDIS_SPIN_LOCK;
204 typedef struct timer_list       NDIS_MINIPORT_TIMER;
205 typedef void                            * NDIS_HANDLE;
206 typedef char                            * PNDIS_BUFFER;
207
208
209
210 void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
211
212 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction);
213 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction);
214
215
216 ////////////////////////////////////////
217 // MOVE TO rtmp.h ?
218 /////////////////////////////////////////
219 #define PKTSRC_NDIS             0x7f
220 #define PKTSRC_DRIVER           0x0f
221 #define PRINT_MAC(addr) \
222         addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
223
224
225 #define RT2860_PCI_DEVICE_ID            0x0601
226
227
228 #ifdef RT2870
229 #define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (ULONG)0
230
231 #define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
232 #endif // RT2870 //
233
234
235 #define BEACON_FRAME_DMA_CACHE_WBACK(_ptr, _size)       \
236         dma_cache_wback(_ptr, _size)
237
238
239 //////////////////////////////////////////
240 //
241 //////////////////////////////////////////
242
243
244 #define NdisMIndicateStatus(_w, _x, _y, _z)
245
246 typedef struct timer_list       RTMP_OS_TIMER;
247
248 #ifdef RT2870
249 /* ----------------- Timer Related MARCO ---------------*/
250 // In RT2870, we have a lot of timer functions and will read/write register, it's
251 //      not allowed in Linux USB sub-system to do it ( because of sleep issue when submit
252 //  to ctrl pipe). So we need a wrapper function to take care it.
253
254 typedef VOID (*RT2870_TIMER_HANDLE)(
255         IN  PVOID   SystemSpecific1,
256         IN  PVOID   FunctionContext,
257         IN  PVOID   SystemSpecific2,
258         IN  PVOID   SystemSpecific3);
259 #endif // RT2870 //
260
261
262 typedef struct  _RALINK_TIMER_STRUCT    {
263     RTMP_OS_TIMER               TimerObj;       // Ndis Timer object
264         BOOLEAN                         Valid;                  // Set to True when call RTMPInitTimer
265     BOOLEAN             State;          // True if timer cancelled
266     BOOLEAN                     PeriodicType;   // True if timer is periodic timer
267     BOOLEAN             Repeat;         // True if periodic timer
268     ULONG               TimerValue;     // Timer value in milliseconds
269         ULONG                           cookie;                 // os specific object
270 #ifdef RT2870
271         RT2870_TIMER_HANDLE     handle;
272         void                            *pAd;
273 #endif // RT2870 //
274 }   RALINK_TIMER_STRUCT, *PRALINK_TIMER_STRUCT;
275
276
277 #ifdef RT2870
278
279 typedef enum _RT2870_KERNEL_THREAD_STATUS_
280 {
281         RT2870_THREAD_UNKNOWN = 0,
282         RT2870_THREAD_INITED = 1,
283         RT2870_THREAD_RUNNING = 2,
284         RT2870_THREAD_STOPED = 4,
285 }RT2870_KERNEL_THREAD_STATUS;
286
287 #define RT2870_THREAD_CAN_DO_INSERT             (RT2870_THREAD_INITED |RT2870_THREAD_RUNNING)
288
289 typedef struct _RT2870_TIMER_ENTRY_
290 {
291         RALINK_TIMER_STRUCT                     *pRaTimer;
292         struct _RT2870_TIMER_ENTRY_     *pNext;
293 }RT2870_TIMER_ENTRY;
294
295
296 #define TIMER_QUEUE_SIZE_MAX    128
297 typedef struct _RT2870_TIMER_QUEUE_
298 {
299         unsigned int            status;
300         UCHAR                           *pTimerQPoll;
301         RT2870_TIMER_ENTRY      *pQPollFreeList;
302         RT2870_TIMER_ENTRY      *pQHead;
303         RT2870_TIMER_ENTRY      *pQTail;
304 }RT2870_TIMER_QUEUE;
305 #endif // RT2870 //
306
307
308 //#define DBG   1
309
310 //
311 //  MACRO for debugging information
312 //
313
314 #ifdef DBG
315 extern ULONG    RTDebugLevel;
316
317 #define DBGPRINT_RAW(Level, Fmt)    \
318 {                                   \
319     if (Level <= RTDebugLevel)      \
320     {                               \
321         printk Fmt;               \
322     }                               \
323 }
324
325 #define DBGPRINT(Level, Fmt)    DBGPRINT_RAW(Level, Fmt)
326
327
328 #define DBGPRINT_ERR(Fmt)           \
329 {                                   \
330     printk("ERROR!!! ");          \
331     printk Fmt;                  \
332 }
333
334 #define DBGPRINT_S(Status, Fmt)         \
335 {                                                                       \
336         printk Fmt;                                     \
337 }
338
339
340 #else
341 #define DBGPRINT(Level, Fmt)
342 #define DBGPRINT_RAW(Level, Fmt)
343 #define DBGPRINT_S(Status, Fmt)
344 #define DBGPRINT_ERR(Fmt)
345 #endif
346
347
348 //
349 //  spin_lock enhanced for Nested spin lock
350 //
351 #define NdisAllocateSpinLock(__lock)      \
352 {                                       \
353     spin_lock_init((spinlock_t *)(__lock));               \
354 }
355
356 #define NdisFreeSpinLock(lock)          \
357 {                                       \
358 }
359
360
361 #define RTMP_SEM_LOCK(__lock)                                   \
362 {                                                                                               \
363         spin_lock_bh((spinlock_t *)(__lock));                           \
364 }
365
366 #define RTMP_SEM_UNLOCK(__lock)                                 \
367 {                                                                                               \
368         spin_unlock_bh((spinlock_t *)(__lock));                         \
369 }
370
371 // sample, use semaphore lock to replace IRQ lock, 2007/11/15
372 #define RTMP_IRQ_LOCK(__lock, __irqflags)                       \
373 {                                                                                                       \
374         __irqflags = 0;                                                                 \
375         spin_lock_bh((spinlock_t *)(__lock));                   \
376         pAd->irq_disabled |= 1; \
377 }
378
379 #define RTMP_IRQ_UNLOCK(__lock, __irqflag)                      \
380 {                                                                                                       \
381         pAd->irq_disabled &= 0; \
382         spin_unlock_bh((spinlock_t *)(__lock));                 \
383 }
384
385 #define RTMP_INT_LOCK(__lock, __irqflags)                       \
386 {                                                                                                       \
387         spin_lock_irqsave((spinlock_t *)__lock, __irqflags);    \
388 }
389
390 #define RTMP_INT_UNLOCK(__lock, __irqflag)                      \
391 {                                                                                                       \
392         spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag));     \
393 }
394
395
396
397 #ifdef RT2870
398 //Patch for ASIC turst read/write bug, needs to remove after metel fix
399 #define RTMP_IO_READ32(_A, _R, _pV)                                                             \
400         RTUSBReadMACRegister(_A, _R, _pV)
401
402 #define RTMP_IO_READ8(_A, _R, _pV)                                                              \
403 {                                                                                                                               \
404 }
405
406 #define RTMP_IO_WRITE32(_A, _R, _V)                                                             \
407         RTUSBWriteMACRegister(_A, _R, _V)
408
409
410 #define RTMP_IO_WRITE8(_A, _R, _V)                                                              \
411 {                                                                                                                               \
412         USHORT  _Val = _V;                                                                                      \
413         RTUSBSingleWrite(_A, _R, _Val);                                                         \
414 }
415
416
417 #define RTMP_IO_WRITE16(_A, _R, _V)                                                             \
418 {                                                                                                                               \
419         RTUSBSingleWrite(_A, _R, _V);                                                           \
420 }
421 #endif // RT2870 //
422
423 #ifndef wait_event_interruptible_timeout
424 #define __wait_event_interruptible_timeout(wq, condition, ret) \
425 do { \
426         wait_queue_t __wait; \
427         init_waitqueue_entry(&__wait, current); \
428         add_wait_queue(&wq, &__wait); \
429         for (;;) { \
430                 set_current_state(TASK_INTERRUPTIBLE); \
431                 if (condition) \
432                         break; \
433                 if (!signal_pending(current)) { \
434                         ret = schedule_timeout(ret); \
435                         if (!ret) \
436                                 break; \
437                         continue; \
438                 } \
439                 ret = -ERESTARTSYS; \
440                 break; \
441         } \
442         current->state = TASK_RUNNING; \
443         remove_wait_queue(&wq, &__wait); \
444 } while (0)
445
446 #define wait_event_interruptible_timeout(wq, condition, timeout) \
447 ({ \
448         long __ret = timeout; \
449         if (!(condition)) \
450                 __wait_event_interruptible_timeout(wq, condition, __ret); \
451         __ret; \
452 })
453 #endif
454 #define ONE_TICK 1
455 #define OS_WAIT(_time) \
456 {       int _i; \
457         long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
458         wait_queue_head_t _wait; \
459         init_waitqueue_head(&_wait); \
460         for (_i=0; _i<(_loop); _i++) \
461                 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
462
463
464 typedef void (*TIMER_FUNCTION)(unsigned long);
465
466 #define COPY_MAC_ADDR(Addr1, Addr2)             memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
467
468 #define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
469 #define MlmeFreeMemory(_pAd, _pVA)     os_free_mem(_pAd, _pVA)
470
471
472 #ifdef RT2870
473 #define BUILD_TIMER_FUNCTION(_func)                                                                                                     \
474 void linux_##_func(unsigned long data)                                                                                          \
475 {                                                                                                                                                                       \
476         PRALINK_TIMER_STRUCT    _pTimer = (PRALINK_TIMER_STRUCT)data;                                   \
477         RT2870_TIMER_ENTRY              *_pQNode;                                                                                               \
478         RTMP_ADAPTER                    *_pAd;                                                                                                  \
479                                                                                                                                                                 \
480         _pTimer->handle = _func;                                                                                                                        \
481         _pAd = (RTMP_ADAPTER *)_pTimer->pAd;                                                                                            \
482         _pQNode = RT2870_TimerQ_Insert(_pAd, _pTimer);                                                                  \
483         if ((_pQNode == NULL) && (_pAd->TimerQ.status & RT2870_THREAD_CAN_DO_INSERT))   \
484                 RTMP_OS_Add_Timer(&_pTimer->TimerObj, HZ);                                                      \
485 }
486 #endif // RT2870 //
487
488
489 #define DECLARE_TIMER_FUNCTION(_func)                   \
490 void linux_##_func(unsigned long data)
491
492 #define GET_TIMER_FUNCTION(_func)                               \
493                 linux_##_func
494
495 DECLARE_TIMER_FUNCTION(MlmePeriodicExec);
496 DECLARE_TIMER_FUNCTION(MlmeRssiReportExec);
497 DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout);
498 DECLARE_TIMER_FUNCTION(APSDPeriodicExec);
499 DECLARE_TIMER_FUNCTION(AsicRfTuningExec);
500 #ifdef RT2870
501 DECLARE_TIMER_FUNCTION(BeaconUpdateExec);
502 #endif // RT2870 //
503
504 DECLARE_TIMER_FUNCTION(BeaconTimeout);
505 DECLARE_TIMER_FUNCTION(ScanTimeout);
506 DECLARE_TIMER_FUNCTION(AuthTimeout);
507 DECLARE_TIMER_FUNCTION(AssocTimeout);
508 DECLARE_TIMER_FUNCTION(ReassocTimeout);
509 DECLARE_TIMER_FUNCTION(DisassocTimeout);
510 DECLARE_TIMER_FUNCTION(LinkDownExec);
511 DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec);
512 DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc);
513 DECLARE_TIMER_FUNCTION(PsPollWakeExec);
514 DECLARE_TIMER_FUNCTION(RadioOnExec);
515
516 void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time);
517
518
519 /*
520  * packet helper
521  *      - convert internal rt packet to os packet or
522  *             os packet to rt packet
523  */
524 #define RTPKT_TO_OSPKT(_p)              ((struct sk_buff *)(_p))
525 #define OSPKT_TO_RTPKT(_p)              ((PNDIS_PACKET)(_p))
526
527 #define GET_OS_PKT_DATAPTR(_pkt) \
528                 (RTPKT_TO_OSPKT(_pkt)->data)
529
530 #define GET_OS_PKT_LEN(_pkt) \
531                 (RTPKT_TO_OSPKT(_pkt)->len)
532
533 #define GET_OS_PKT_DATATAIL(_pkt) \
534                 (RTPKT_TO_OSPKT(_pkt)->tail)
535
536 #define GET_OS_PKT_HEAD(_pkt) \
537                 (RTPKT_TO_OSPKT(_pkt)->head)
538
539 #define GET_OS_PKT_END(_pkt) \
540                 (RTPKT_TO_OSPKT(_pkt)->end)
541
542 #define GET_OS_PKT_NETDEV(_pkt) \
543                 (RTPKT_TO_OSPKT(_pkt)->dev)
544
545 #define GET_OS_PKT_TYPE(_pkt) \
546                 (RTPKT_TO_OSPKT(_pkt))
547
548 #define GET_OS_PKT_NEXT(_pkt) \
549                 (RTPKT_TO_OSPKT(_pkt)->next)
550
551
552 #define OS_NTOHS(_Val) \
553                 (ntohs(_Val))
554 #define OS_HTONS(_Val) \
555                 (htons(_Val))
556 #define OS_NTOHL(_Val) \
557                 (ntohl(_Val))
558 #define OS_HTONL(_Val) \
559                 (htonl(_Val))
560
561 /* statistics counter */
562 #define STATS_INC_RX_PACKETS(_pAd, _dev)
563 #define STATS_INC_TX_PACKETS(_pAd, _dev)
564
565 #define STATS_INC_RX_BYTESS(_pAd, _dev, len)
566 #define STATS_INC_TX_BYTESS(_pAd, _dev, len)
567
568 #define STATS_INC_RX_ERRORS(_pAd, _dev)
569 #define STATS_INC_TX_ERRORS(_pAd, _dev)
570
571 #define STATS_INC_RX_DROPPED(_pAd, _dev)
572 #define STATS_INC_TX_DROPPED(_pAd, _dev)
573
574
575 #define CB_OFF  10
576
577
578 //   check DDK NDIS_PACKET data structure and find out only MiniportReservedEx[0..7] can be used by our driver without
579 //   ambiguity. Fields after pPacket->MiniportReservedEx[8] may be used by other wrapper layer thus crashes the driver
580 //
581
582 // User Priority
583 #define RTMP_SET_PACKET_UP(_p, _prio)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
584 #define RTMP_GET_PACKET_UP(_p)                                  (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
585
586 // Fragment #
587 #define RTMP_SET_PACKET_FRAGMENTS(_p, _num)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
588 #define RTMP_GET_PACKET_FRAGMENTS(_p)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
589
590 // 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.
591 //(this value also as MAC(on-chip WCID) table index)
592 // 0x80~0xff: TX to a WDS link. b0~6: WDS index
593 #define RTMP_SET_PACKET_WCID(_p, _wdsidx)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
594 #define RTMP_GET_PACKET_WCID(_p)                        ((UCHAR)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
595
596 // 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet
597 #define RTMP_SET_PACKET_SOURCE(_p, _pktsrc)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
598 #define RTMP_GET_PACKET_SOURCE(_p)                      (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
599
600 // RTS/CTS-to-self protection method
601 #define RTMP_SET_PACKET_RTS(_p, _num)                   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
602 #define RTMP_GET_PACKET_RTS(_p)                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
603 // see RTMP_S(G)ET_PACKET_EMACTAB
604
605 // TX rate index
606 #define RTMP_SET_PACKET_TXRATE(_p, _rate)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
607 #define RTMP_GET_PACKET_TXRATE(_p)                              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
608
609 // From which Interface
610 #define RTMP_SET_PACKET_IF(_p, _ifdx)           (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
611 #define RTMP_GET_PACKET_IF(_p)                          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
612 #define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss)             RTMP_SET_PACKET_IF((_p), (_bss))
613 #define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss)                RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
614 #define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx)      RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
615 #define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx)       RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
616 #define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p)                   RTMP_GET_PACKET_IF((_p))
617 #define RTMP_GET_PACKET_NET_DEVICE(_p)                                  RTMP_GET_PACKET_IF((_p))
618
619 #define RTMP_SET_PACKET_MOREDATA(_p, _morebit)          (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
620 #define RTMP_GET_PACKET_MOREDATA(_p)                            (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
621
622
623 //
624 //      Sepcific Pakcet Type definition
625 //
626 #define RTMP_PACKET_SPECIFIC_CB_OFFSET  11
627
628 #define RTMP_PACKET_SPECIFIC_DHCP               0x01
629 #define RTMP_PACKET_SPECIFIC_EAPOL              0x02
630 #define RTMP_PACKET_SPECIFIC_IPV4               0x04
631 #define RTMP_PACKET_SPECIFIC_WAI                0x08
632 #define RTMP_PACKET_SPECIFIC_VLAN               0x10
633 #define RTMP_PACKET_SPECIFIC_LLCSNAP    0x20
634
635 //Specific
636 #define RTMP_SET_PACKET_SPECIFIC(_p, _flg)              (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
637
638 //DHCP
639 #define RTMP_SET_PACKET_DHCP(_p, _flg)                                                                                                          \
640                         do{                                                                                                                                                             \
641                                 if (_flg)                                                                                                                                       \
642                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP);             \
643                                 else                                                                                                                                            \
644                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP);    \
645                         }while(0)
646 #define RTMP_GET_PACKET_DHCP(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
647
648 //EAPOL
649 #define RTMP_SET_PACKET_EAPOL(_p, _flg)                                                                                                         \
650                         do{                                                                                                                                                             \
651                                 if (_flg)                                                                                                                                       \
652                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL);            \
653                                 else                                                                                                                                            \
654                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL);   \
655                         }while(0)
656 #define RTMP_GET_PACKET_EAPOL(_p)               (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
657
658 //WAI
659 #define RTMP_SET_PACKET_WAI(_p, _flg)                                                                                                           \
660                         do{                                                                                                                                                             \
661                                 if (_flg)                                                                                                                                       \
662                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI);              \
663                                 else                                                                                                                                            \
664                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI);     \
665                         }while(0)
666 #define RTMP_GET_PACKET_WAI(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
667
668 #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))
669
670 //VLAN
671 #define RTMP_SET_PACKET_VLAN(_p, _flg)                                                                                                          \
672                         do{                                                                                                                                                             \
673                                 if (_flg)                                                                                                                                       \
674                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN);             \
675                                 else                                                                                                                                            \
676                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN);    \
677                         }while(0)
678 #define RTMP_GET_PACKET_VLAN(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
679
680 //LLC/SNAP
681 #define RTMP_SET_PACKET_LLCSNAP(_p, _flg)                                                                                                       \
682                         do{                                                                                                                                                             \
683                                 if (_flg)                                                                                                                                       \
684                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP);          \
685                                 else                                                                                                                                            \
686                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP);         \
687                         }while(0)
688
689 #define RTMP_GET_PACKET_LLCSNAP(_p)             (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
690
691 // IP
692 #define RTMP_SET_PACKET_IPV4(_p, _flg)                                                                                                          \
693                         do{                                                                                                                                                             \
694                                 if (_flg)                                                                                                                                       \
695                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4);             \
696                                 else                                                                                                                                            \
697                                         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4);    \
698                         }while(0)
699
700 #define RTMP_GET_PACKET_IPV4(_p)                (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
701
702
703 // If this flag is set, it indicates that this EAPoL frame MUST be clear.
704 #define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
705 #define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
706
707 #define RTMP_SET_PACKET_5VT(_p, _flg)   (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
708 #define RTMP_GET_PACKET_5VT(_p)         (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
709
710
711 #ifdef CONFIG_5VT_ENHANCE
712 #define BRIDGE_TAG 0x35564252    // depends on 5VT define in br_input.c
713 #endif
714
715
716 #define NDIS_SET_PACKET_STATUS(_p, _status)
717
718
719 #define GET_SG_LIST_FROM_PACKET(_p, _sc)        \
720     rt_get_sg_list_from_packet(_p, _sc)
721
722
723 #define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
724 #define NdisZeroMemory(Destination, Length)         memset(Destination, 0, Length)
725 #define NdisFillMemory(Destination, Length, Fill)   memset(Destination, Fill, Length)
726 #define NdisEqualMemory(Source1, Source2, Length)   (!memcmp(Source1, Source2, Length))
727 #define RTMPEqualMemory(Source1, Source2, Length)       (!memcmp(Source1, Source2, Length))
728
729
730 #define RTMP_INC_REF(_A)                0
731 #define RTMP_DEC_REF(_A)                0
732 #define RTMP_GET_REF(_A)                0
733
734
735
736 /*
737  * ULONG
738  * RTMP_GetPhysicalAddressLow(
739  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
740  */
741 #define RTMP_GetPhysicalAddressLow(PhysicalAddress)             (PhysicalAddress)
742
743 /*
744  * ULONG
745  * RTMP_GetPhysicalAddressHigh(
746  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress);
747  */
748 #define RTMP_GetPhysicalAddressHigh(PhysicalAddress)            (0)
749
750 /*
751  * VOID
752  * RTMP_SetPhysicalAddressLow(
753  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
754  *   IN ULONG  Value);
755  */
756 #define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value)      \
757                         PhysicalAddress = Value;
758
759 /*
760  * VOID
761  * RTMP_SetPhysicalAddressHigh(
762  *   IN NDIS_PHYSICAL_ADDRESS  PhysicalAddress,
763  *   IN ULONG  Value);
764  */
765 #define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
766
767
768 //CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
769 #define QUEUE_ENTRY_TO_PACKET(pEntry) \
770         (PNDIS_PACKET)(pEntry)
771
772 #define PACKET_TO_QUEUE_ENTRY(pPacket) \
773         (PQUEUE_ENTRY)(pPacket)
774
775
776 #ifndef CONTAINING_RECORD
777 #define CONTAINING_RECORD(address, type, field)                 \
778 ((type *)((PCHAR)(address) - offsetof(type, field)))
779 #endif
780
781
782 #define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status)                    \
783 {                                                                       \
784         RTMPFreeNdisPacket(_pAd, _pPacket);                             \
785 }
786
787
788 #define SWITCH_PhyAB(_pAA, _pBB)    \
789 {                                                                           \
790     ULONG       AABasePaHigh;                           \
791     ULONG       AABasePaLow;                           \
792     ULONG       BBBasePaHigh;                           \
793     ULONG       BBBasePaLow;                           \
794     BBBasePaHigh = RTMP_GetPhysicalAddressHigh(_pBB);                                                 \
795     BBBasePaLow = RTMP_GetPhysicalAddressLow(_pBB);                                                 \
796     AABasePaHigh = RTMP_GetPhysicalAddressHigh(_pAA);                                                 \
797     AABasePaLow = RTMP_GetPhysicalAddressLow(_pAA);                                                 \
798     RTMP_SetPhysicalAddressHigh(_pAA, BBBasePaHigh);                                                 \
799     RTMP_SetPhysicalAddressLow(_pAA, BBBasePaLow);                                                 \
800     RTMP_SetPhysicalAddressHigh(_pBB, AABasePaHigh);                                                 \
801     RTMP_SetPhysicalAddressLow(_pBB, AABasePaLow);                                                 \
802 }
803
804
805 #define NdisWriteErrorLogEntry(_a, _b, _c, _d)
806 #define NdisMAllocateMapRegisters(_a, _b, _c, _d, _e)           NDIS_STATUS_SUCCESS
807
808
809 #define NdisAcquireSpinLock             RTMP_SEM_LOCK
810 #define NdisReleaseSpinLock             RTMP_SEM_UNLOCK
811
812 static inline void NdisGetSystemUpTime(ULONG *time)
813 {
814         *time = jiffies;
815 }
816
817 //pPacket = CONTAINING_RECORD(pEntry, NDIS_PACKET, MiniportReservedEx);
818 #define QUEUE_ENTRY_TO_PKT(pEntry) \
819                 ((PNDIS_PACKET) (pEntry))
820
821 int rt28xx_packet_xmit(struct sk_buff *skb);
822
823
824
825 void rtmp_os_thread_init(PUCHAR pThreadName, PVOID pNotify);
826
827