blob: f85508d9d5a99cd9e237e1e886eb62cbd1d9ea2e [file] [log] [blame]
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001/*
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 *************************************************************************
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070026
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020027 Module Name:
28 rt_linux.h
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070029
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020030 Abstract:
31
32 Revision History:
33 Who When What
34 --------- ---------- ----------------------------------------------
35*/
36
37#ifndef __RT_LINUX_H__
38#define __RT_LINUX_H__
39
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070040#include <linux/module.h>
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070041#include <linux/kernel.h>
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070042#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
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070061#include <net/iw_handler.h>
62
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080063/* load firmware */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070064#define __KERNEL_SYSCALLS__
65#include <linux/unistd.h>
66#include <asm/uaccess.h>
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020067#include <asm/types.h>
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080068#include <asm/unaligned.h> /* for get_unaligned() */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020069
70#define KTHREAD_SUPPORT 1
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080071/* RT2870 2.1.0.0 has it disabled */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020072
73#ifdef KTHREAD_SUPPORT
74#include <linux/err.h>
75#include <linux/kthread.h>
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080076#endif /* KTHREAD_SUPPORT // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020077
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020078/***********************************************************************************
79 * Profile related sections
80 ***********************************************************************************/
81
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020082#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020083#define STA_DRIVER_VERSION "2.1.0.0"
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080084#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020085#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020086#define STA_DRIVER_VERSION "2.1.0.0"
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -080087/* RT3070 version: 2.1.1.0 */
88#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020089
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -080090extern const struct iw_handler_def rt28xx_iw_handler_def;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020091
92/***********************************************************************************
93 * Compiler related definitions
94 ***********************************************************************************/
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070095#undef __inline
96#define __inline static inline
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020097#define IN
98#define OUT
99#define INOUT
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200100
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200101/***********************************************************************************
102 * OS Specific definitions and data structures
103 ***********************************************************************************/
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800104typedef int (*HARD_START_XMIT_FUNC) (struct sk_buff * skb,
105 struct net_device * net_dev);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700106
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200107#ifdef RTMP_MAC_PCI
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700108#ifndef PCI_DEVICE
109#define PCI_DEVICE(vend,dev) \
110 .vendor = (vend), .device = (dev), \
111 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800112#endif /* PCI_DEVICE // */
113#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700114
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700115#define RT_MOD_INC_USE_COUNT() \
116 if (!try_module_get(THIS_MODULE)) \
117 { \
Harvey Harrisond599edc2009-01-07 14:31:57 -0800118 DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700119 return -1; \
120 }
121
122#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700123
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200124#define RTMP_INC_REF(_A) 0
125#define RTMP_DEC_REF(_A) 0
126#define RTMP_GET_REF(_A) 0
127
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800128/* This function will be called when query /proc */
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800129struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200130
131/***********************************************************************************
132 * Network related constant definitions
133 ***********************************************************************************/
134#ifndef IFNAMSIZ
135#define IFNAMSIZ 16
136#endif
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700137
138#define ETH_LENGTH_OF_ADDRESS 6
139
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700140#define NDIS_STATUS_SUCCESS 0x00
141#define NDIS_STATUS_FAILURE 0x01
142#define NDIS_STATUS_INVALID_DATA 0x02
143#define NDIS_STATUS_RESOURCES 0x03
144
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200145#define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0)
146#define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0)
147
148/* statistics counter */
149#define STATS_INC_RX_PACKETS(_pAd, _dev)
150#define STATS_INC_TX_PACKETS(_pAd, _dev)
151
152#define STATS_INC_RX_BYTESS(_pAd, _dev, len)
153#define STATS_INC_TX_BYTESS(_pAd, _dev, len)
154
155#define STATS_INC_RX_ERRORS(_pAd, _dev)
156#define STATS_INC_TX_ERRORS(_pAd, _dev)
157
158#define STATS_INC_RX_DROPPED(_pAd, _dev)
159#define STATS_INC_TX_DROPPED(_pAd, _dev)
160
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200161/***********************************************************************************
162 * Ralink Specific network related constant definitions
163 ***********************************************************************************/
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800164#define MIN_NET_DEVICE_FOR_AID 0x00 /*0x00~0x3f */
165#define MIN_NET_DEVICE_FOR_MBSSID 0x00 /*0x00,0x10,0x20,0x30 */
166#define MIN_NET_DEVICE_FOR_WDS 0x10 /*0x40,0x50,0x60,0x70 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700167#define MIN_NET_DEVICE_FOR_APCLI 0x20
168#define MIN_NET_DEVICE_FOR_MESH 0x30
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700169#define MIN_NET_DEVICE_FOR_DLS 0x40
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800170#define NET_DEVICE_REAL_IDX_MASK 0x0f /* for each operation mode, we maximum support 15 entities. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700171
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700172#define NDIS_PACKET_TYPE_DIRECTED 0
173#define NDIS_PACKET_TYPE_MULTICAST 1
174#define NDIS_PACKET_TYPE_BROADCAST 2
175#define NDIS_PACKET_TYPE_ALL_MULTICAST 3
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200176#define NDIS_PACKET_TYPE_PROMISCUOUS 4
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700177
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200178/***********************************************************************************
179 * OS signaling related constant definitions
180 ***********************************************************************************/
181
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200182/***********************************************************************************
183 * OS file operation related data structure definitions
184 ***********************************************************************************/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800185struct rt_rtmp_os_fs_info {
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800186 int fsuid;
187 int fsgid;
188 mm_segment_t fs;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800189};
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200190
191#define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd))
192
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200193/***********************************************************************************
194 * OS semaphore related data structure and definitions
195 ***********************************************************************************/
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800196struct os_lock {
197 spinlock_t lock;
198 unsigned long flags;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700199};
200
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800201/* */
202/* spin_lock enhanced for Nested spin lock */
203/* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700204#define NdisAllocateSpinLock(__lock) \
205{ \
206 spin_lock_init((spinlock_t *)(__lock)); \
207}
208
209#define NdisFreeSpinLock(lock) \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200210 do{}while(0)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700211
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700212#define RTMP_SEM_LOCK(__lock) \
213{ \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200214 spin_lock_bh((spinlock_t *)(__lock)); \
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700215}
216
217#define RTMP_SEM_UNLOCK(__lock) \
218{ \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200219 spin_unlock_bh((spinlock_t *)(__lock)); \
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700220}
221
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800222/* sample, use semaphore lock to replace IRQ lock, 2007/11/15 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700223#define RTMP_IRQ_LOCK(__lock, __irqflags) \
224{ \
225 __irqflags = 0; \
226 spin_lock_bh((spinlock_t *)(__lock)); \
227 pAd->irq_disabled |= 1; \
228}
229
230#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \
231{ \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200232 pAd->irq_disabled &= 0; \
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700233 spin_unlock_bh((spinlock_t *)(__lock)); \
234}
235
236#define RTMP_INT_LOCK(__lock, __irqflags) \
237{ \
238 spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \
239}
240
241#define RTMP_INT_UNLOCK(__lock, __irqflag) \
242{ \
243 spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \
244}
245
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200246#define NdisAcquireSpinLock RTMP_SEM_LOCK
247#define NdisReleaseSpinLock RTMP_SEM_UNLOCK
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700248
249#ifndef wait_event_interruptible_timeout
250#define __wait_event_interruptible_timeout(wq, condition, ret) \
251do { \
252 wait_queue_t __wait; \
253 init_waitqueue_entry(&__wait, current); \
254 add_wait_queue(&wq, &__wait); \
255 for (;;) { \
256 set_current_state(TASK_INTERRUPTIBLE); \
257 if (condition) \
258 break; \
259 if (!signal_pending(current)) { \
260 ret = schedule_timeout(ret); \
261 if (!ret) \
262 break; \
263 continue; \
264 } \
265 ret = -ERESTARTSYS; \
266 break; \
267 } \
268 current->state = TASK_RUNNING; \
269 remove_wait_queue(&wq, &__wait); \
270} while (0)
271
272#define wait_event_interruptible_timeout(wq, condition, timeout) \
273({ \
274 long __ret = timeout; \
275 if (!(condition)) \
276 __wait_event_interruptible_timeout(wq, condition, __ret); \
277 __ret; \
278})
279#endif
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200280
281#define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0)
282#define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1)
283#define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema)))
284#define RTMP_SEM_EVENT_UP(_pSema) up(_pSema)
285
286#ifdef KTHREAD_SUPPORT
287#define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \
288{ \
289 wait_event_interruptible(_pTask->kthread_q, \
290 _pTask->kthread_running || kthread_should_stop()); \
291 _pTask->kthread_running = FALSE; \
292 if (kthread_should_stop()) \
293 { \
294 RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \
295 break; \
296 } \
297}
298#endif
299
300#ifdef KTHREAD_SUPPORT
301#define WAKE_UP(_pTask) \
302 do{ \
303 if ((_pTask)->kthread_task) \
304 { \
305 (_pTask)->kthread_running = TRUE; \
306 wake_up(&(_pTask)->kthread_q); \
307 } \
308 }while(0)
309#endif
310
311/***********************************************************************************
312 * OS Memory Access related data structure and definitions
313 ***********************************************************************************/
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800314#define MEM_ALLOC_FLAG (GFP_ATOMIC) /*(GFP_DMA | GFP_ATOMIC) */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200315
316#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length)
317#define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length)
318#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length)
319#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length)
320#define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length)
321#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
322#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length))
323
324#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE)
325#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA)
326
327#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN)
328
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200329/***********************************************************************************
330 * OS task related data structure and definitions
331 ***********************************************************************************/
332#define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM
333
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200334#define THREAD_PID_INIT_VALUE NULL
335#define GET_PID(_v) find_get_pid((_v))
336#define GET_PID_NUMBER(_v) pid_nr((_v))
337#define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0)
338#define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C))
339
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200340/***********************************************************************************
341 * Timer related definitions and data structures.
342 **********************************************************************************/
343#define OS_HZ HZ
344
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800345typedef void (*TIMER_FUNCTION) (unsigned long);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200346
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700347#define OS_WAIT(_time) \
348{ int _i; \
349 long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\
350 wait_queue_head_t _wait; \
351 init_waitqueue_head(&_wait); \
352 for (_i=0; _i<(_loop); _i++) \
353 wait_event_interruptible_timeout(_wait, 0, ONE_TICK); }
354
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200355#define RTMP_TIME_AFTER(a,b) \
356 (typecheck(unsigned long, (unsigned long)a) && \
357 typecheck(unsigned long, (unsigned long)b) && \
358 ((long)(b) - (long)(a) < 0))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700359
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200360#define RTMP_TIME_AFTER_EQ(a,b) \
361 (typecheck(unsigned long, (unsigned long)a) && \
362 typecheck(unsigned long, (unsigned long)b) && \
363 ((long)(a) - (long)(b) >= 0))
364#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700365
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200366#define ONE_TICK 1
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700367
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800368static inline void NdisGetSystemUpTime(unsigned long * time)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200369{
370 *time = jiffies;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700371}
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200372
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200373/***********************************************************************************
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800374 * OS specific cookie data structure binding to struct rt_rtmp_adapter
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200375 ***********************************************************************************/
376
377struct os_cookie {
378#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800379 struct pci_dev *pci_dev;
380 struct pci_dev *parent_pci_dev;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800381 u16 DeviceID;
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800382 dma_addr_t pAd_pa;
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800383#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200384#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800385 struct usb_device *pUsb_Dev;
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800386#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200387
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800388 struct tasklet_struct rx_done_task;
389 struct tasklet_struct mgmt_dma_done_task;
390 struct tasklet_struct ac0_dma_done_task;
391 struct tasklet_struct ac1_dma_done_task;
392 struct tasklet_struct ac2_dma_done_task;
393 struct tasklet_struct ac3_dma_done_task;
394 struct tasklet_struct tbtt_task;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200395#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800396 struct tasklet_struct fifo_statistic_full_task;
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800397#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200398#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800399 struct tasklet_struct null_frame_complete_task;
400 struct tasklet_struct rts_frame_complete_task;
401 struct tasklet_struct pspoll_frame_complete_task;
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800402#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200403
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800404 unsigned long apd_pid; /*802.1x daemon pid */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800405 int ioctl_if_type;
406 int ioctl_if;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200407};
408
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200409/***********************************************************************************
410 * OS debugging and printing related definitions and data structure
411 ***********************************************************************************/
412#define PRINT_MAC(addr) \
413 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
414
415#ifdef DBG
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800416extern unsigned long RTDebugLevel;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200417
418#define DBGPRINT_RAW(Level, Fmt) \
419do{ \
420 if (Level <= RTDebugLevel) \
421 { \
422 printk Fmt; \
423 } \
424}while(0)
425
426#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
427
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200428#define DBGPRINT_ERR(Fmt) \
429{ \
Sebastian Dalfuß06aea992009-11-07 17:31:12 +0100430 printk("ERROR! "); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200431 printk Fmt; \
432}
433
434#define DBGPRINT_S(Status, Fmt) \
435{ \
436 printk Fmt; \
437}
438
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200439#else
440#define DBGPRINT(Level, Fmt)
441#define DBGPRINT_RAW(Level, Fmt)
442#define DBGPRINT_S(Status, Fmt)
443#define DBGPRINT_ERR(Fmt)
Bartlomiej Zolnierkiewicz3a32ed12009-04-26 16:06:25 +0200444#endif
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200445
446#define ASSERT(x)
447
448void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen);
449
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200450/*********************************************************************************************************
451 The following code are not revised, temporary put it here.
452 *********************************************************************************************************/
453
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200454/***********************************************************************************
455 * Device DMA Access related definitions and data structures.
456 **********************************************************************************/
457#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800458dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size,
459 int sd_idx, int direction);
460void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size,
461 int direction);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200462
463#define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \
464 linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir)
465
466#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \
467 linux_pci_unmap_single(_handle, _ptr, _size, _dir)
468
469#define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \
470 pci_alloc_consistent(_pci_dev, _size, _ptr)
471
472#define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \
473 pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr)
474
475#define DEV_ALLOC_SKB(_length) \
476 dev_alloc_skb(_length)
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800477#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200478#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800479#define PCI_MAP_SINGLE(_handle, _ptr, _size, _dir) (unsigned long)0
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200480
481#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir)
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800482#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200483
484/*
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800485 * unsigned long
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200486 * RTMP_GetPhysicalAddressLow(
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800487 * dma_addr_t PhysicalAddress);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200488 */
489#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress)
490
491/*
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800492 * unsigned long
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200493 * RTMP_GetPhysicalAddressHigh(
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800494 * dma_addr_t PhysicalAddress);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200495 */
496#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0)
497
498/*
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800499 * void
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200500 * RTMP_SetPhysicalAddressLow(
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800501 * dma_addr_t PhysicalAddress,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800502 * unsigned long Value);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200503 */
504#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \
505 PhysicalAddress = Value;
506
507/*
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800508 * void
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200509 * RTMP_SetPhysicalAddressHigh(
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800510 * dma_addr_t PhysicalAddress,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800511 * unsigned long Value);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200512 */
513#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value)
514
515#define NdisMIndicateStatus(_w, _x, _y, _z)
516
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200517/***********************************************************************************
518 * Device Register I/O Access related definitions and data structures.
519 **********************************************************************************/
520#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800521/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200522#define RTMP_IO_READ32(_A, _R, _pV) \
523{ \
524 if ((_A)->bPCIclkOff == FALSE) \
525 { \
526 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
527 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
528 } \
529 else \
530 *_pV = 0; \
Bartlomiej Zolnierkiewicz3a32ed12009-04-26 16:06:25 +0200531}
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200532
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +0200533#define RTMP_IO_FORCE_READ32(_A, _R, _pV) \
534{ \
535 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
536 (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \
537}
538
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200539#define RTMP_IO_READ8(_A, _R, _pV) \
540{ \
541 (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \
542 (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \
543}
544#define RTMP_IO_WRITE32(_A, _R, _V) \
545{ \
546 if ((_A)->bPCIclkOff == FALSE) \
547 { \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800548 u32 Val; \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200549 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
550 writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \
551 } \
552}
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700553
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +0200554#define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \
555{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800556 u32 Val; \
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +0200557 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
558 writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \
559}
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700560
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200561#if defined(RALINK_2880) || defined(RALINK_3052)
562#define RTMP_IO_WRITE8(_A, _R, _V) \
563{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800564 unsigned long Val; \
565 u8 _i; \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200566 _i = ((_R) & 0x3); \
567 Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
568 Val = Val & (~(0x000000ff << ((_i)*8))); \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800569 Val = Val | ((unsigned long)(_V) << ((_i)*8)); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200570 writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \
571}
572#else
573#define RTMP_IO_WRITE8(_A, _R, _V) \
574{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800575 u32 Val; \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200576 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800577 writeb((_V), (u8 *)((_A)->CSRBaseAddress + (_R))); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200578}
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800579#endif /* #if defined(BRCM_6358) || defined(RALINK_2880) // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700580
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200581#define RTMP_IO_WRITE16(_A, _R, _V) \
582{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800583 u32 Val; \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200584 Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800585 writew((_V), (u16 *)((_A)->CSRBaseAddress + (_R))); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200586}
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800587#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200588#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800589/*Patch for ASIC turst read/write bug, needs to remove after metel fix */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200590#define RTMP_IO_READ32(_A, _R, _pV) \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800591 RTUSBReadMACRegister((_A), (_R), (u32 *)(_pV))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700592
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200593#define RTMP_IO_READ8(_A, _R, _pV) \
594{ \
595}
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700596
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200597#define RTMP_IO_WRITE32(_A, _R, _V) \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800598 RTUSBWriteMACRegister((_A), (_R), (u32)(_V))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700599
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200600#define RTMP_IO_WRITE8(_A, _R, _V) \
601{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800602 u16 _Val = _V; \
603 RTUSBSingleWrite((_A), (_R), (u16)(_Val)); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200604}
605
606#define RTMP_IO_WRITE16(_A, _R, _V) \
607{ \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800608 RTUSBSingleWrite((_A), (_R), (u16)(_V)); \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200609}
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800610#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200611
612/***********************************************************************************
613 * Network Related data structure and marco definitions
614 ***********************************************************************************/
615#define PKTSRC_NDIS 0x7f
616#define PKTSRC_DRIVER 0x0f
617
618#define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv))
619#define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv)
620#define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name)
621#define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr)
622
623#define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev))
624#define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev))
625#define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev))
626#define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev))
627
628#define QUEUE_ENTRY_TO_PACKET(pEntry) \
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800629 (void *)(pEntry)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200630
631#define PACKET_TO_QUEUE_ENTRY(pPacket) \
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800632 (struct rt_queue_entry *)(pPacket)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200633
634#define GET_SG_LIST_FROM_PACKET(_p, _sc) \
635 rt_get_sg_list_from_packet(_p, _sc)
636
637#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \
638{ \
639 RTMPFreeNdisPacket(_pAd, _pPacket); \
640}
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700641
642/*
643 * packet helper
644 * - convert internal rt packet to os packet or
645 * os packet to rt packet
646 */
647#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p))
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800648#define OSPKT_TO_RTPKT(_p) ((void *)(_p))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700649
650#define GET_OS_PKT_DATAPTR(_pkt) \
651 (RTPKT_TO_OSPKT(_pkt)->data)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200652#define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \
653 (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700654
655#define GET_OS_PKT_LEN(_pkt) \
656 (RTPKT_TO_OSPKT(_pkt)->len)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200657#define SET_OS_PKT_LEN(_pkt, _len) \
658 (RTPKT_TO_OSPKT(_pkt)->len) = (_len)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700659
660#define GET_OS_PKT_DATATAIL(_pkt) \
661 (RTPKT_TO_OSPKT(_pkt)->tail)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200662#define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800663 ((RTPKT_TO_OSPKT(_pkt))->tail) = (u8 *)((_start) + (_len))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700664
665#define GET_OS_PKT_HEAD(_pkt) \
666 (RTPKT_TO_OSPKT(_pkt)->head)
667
668#define GET_OS_PKT_END(_pkt) \
669 (RTPKT_TO_OSPKT(_pkt)->end)
670
671#define GET_OS_PKT_NETDEV(_pkt) \
672 (RTPKT_TO_OSPKT(_pkt)->dev)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200673#define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \
674 (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700675
676#define GET_OS_PKT_TYPE(_pkt) \
677 (RTPKT_TO_OSPKT(_pkt))
678
679#define GET_OS_PKT_NEXT(_pkt) \
680 (RTPKT_TO_OSPKT(_pkt)->next)
681
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200682#define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt))
683
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700684#define OS_NTOHS(_Val) \
685 (ntohs(_Val))
686#define OS_HTONS(_Val) \
687 (htons(_Val))
688#define OS_NTOHL(_Val) \
689 (ntohl(_Val))
690#define OS_HTONL(_Val) \
691 (htonl(_Val))
692
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700693#define CB_OFF 10
694
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800695/* User Priority */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700696#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio)
697#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0])
698
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800699/* Fragment # */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700700#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num)
701#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1])
702
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800703/* 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. */
704/*(this value also as MAC(on-chip WCID) table index) */
705/* 0x80~0xff: TX to a WDS link. b0~6: WDS index */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700706#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx)
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800707#define RTMP_GET_PACKET_WCID(_p) ((u8)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2]))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700708
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800709/* 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700710#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc)
711#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3])
712
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800713/* RTS/CTS-to-self protection method */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700714#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num)
715#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4])
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800716/* see RTMP_S(G)ET_PACKET_EMACTAB */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700717
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800718/* TX rate index */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700719#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate)
720#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5])
721
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800722/* From which Interface */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700723#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx)
724#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6])
725#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss))
726#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS))
727#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI))
728#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH))
729#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p))
730#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p))
731
732#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit)
733#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
734
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800735/* */
736/* Sepcific Pakcet Type definition */
737/* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700738#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
739
740#define RTMP_PACKET_SPECIFIC_DHCP 0x01
741#define RTMP_PACKET_SPECIFIC_EAPOL 0x02
742#define RTMP_PACKET_SPECIFIC_IPV4 0x04
743#define RTMP_PACKET_SPECIFIC_WAI 0x08
744#define RTMP_PACKET_SPECIFIC_VLAN 0x10
745#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20
746
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800747/*Specific */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700748#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg)
749
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800750/*DHCP */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700751#define RTMP_SET_PACKET_DHCP(_p, _flg) \
752 do{ \
753 if (_flg) \
754 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \
755 else \
756 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \
757 }while(0)
758#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP)
759
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800760/*EAPOL */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700761#define RTMP_SET_PACKET_EAPOL(_p, _flg) \
762 do{ \
763 if (_flg) \
764 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \
765 else \
766 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \
767 }while(0)
768#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL)
769
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800770/*WAI */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700771#define RTMP_SET_PACKET_WAI(_p, _flg) \
772 do{ \
773 if (_flg) \
774 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \
775 else \
776 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \
777 }while(0)
778#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI)
779
780#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))
781
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800782/*VLAN */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700783#define RTMP_SET_PACKET_VLAN(_p, _flg) \
784 do{ \
785 if (_flg) \
786 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \
787 else \
788 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \
789 }while(0)
790#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN)
791
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800792/*LLC/SNAP */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700793#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \
794 do{ \
795 if (_flg) \
796 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \
797 else \
798 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \
799 }while(0)
800
801#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP)
802
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800803/* IP */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700804#define RTMP_SET_PACKET_IPV4(_p, _flg) \
805 do{ \
806 if (_flg) \
807 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \
808 else \
809 (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \
810 }while(0)
811
812#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4)
813
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800814/* If this flag is set, it indicates that this EAPoL frame MUST be clear. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700815#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg)
816#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12])
817
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200818/* use bit3 of cb[CB_OFF+16] */
819
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700820#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg)
821#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22])
822
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200823/* Max skb->cb = 48B = [CB_OFF+38] */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700824
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200825/***********************************************************************************
826 * Other function prototypes definitions
827 ***********************************************************************************/
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800828void RTMP_GetCurrentSystemTime(LARGE_INTEGER * time);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700829int rt28xx_packet_xmit(struct sk_buff *skb);
830
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200831#ifdef RTMP_MAC_PCI
832/* function declarations */
833#define IRQ_HANDLE_TYPE irqreturn_t
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700834
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200835IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance);
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800836#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700837
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800838int rt28xx_sta_ioctl(struct net_device *net_dev, IN OUT struct ifreq *rq, int cmd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700839
Bartlomiej Zolnierkiewicz52b81c82009-12-11 12:23:14 -0800840extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char * buf);
841extern int ra_mtd_read(int num, loff_t from, size_t len, u_char * buf);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700842
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800843#define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (struct rt_rtmp_adapter *)(_net_dev)->ml_priv;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700844
Bartlomiej Zolnierkiewiczcc277062009-12-11 12:23:15 -0800845#endif /* __RT_LINUX_H__ // */