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