Staging: rt2870: remove kernel version compatibility wrappers
[pandora-kernel.git] / drivers / staging / rt2870 / rt2870.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 #ifndef __RT2870_H__
29 #define __RT2870_H__
30
31 //usb header files
32 #include <linux/usb.h>
33
34 /* rtmp_def.h */
35 //
36 #define BULKAGGRE_ZISE          100
37 #define RT28XX_DRVDATA_SET(_a)                                             usb_set_intfdata(_a, pAd);
38 #define RT28XX_PUT_DEVICE                                                  usb_put_dev
39 #define RTUSB_ALLOC_URB(iso)                                               usb_alloc_urb(iso, GFP_ATOMIC)
40 #define RTUSB_SUBMIT_URB(pUrb)                                             usb_submit_urb(pUrb, GFP_ATOMIC)
41 #define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr)               usb_buffer_alloc(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)
42 #define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)   usb_buffer_free(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)
43
44 #define RXBULKAGGRE_ZISE        12
45 #define MAX_TXBULK_LIMIT        (LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1))
46 #define MAX_TXBULK_SIZE         (LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE)
47 #define MAX_RXBULK_SIZE         (LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE)
48 #define MAX_MLME_HANDLER_MEMORY 20
49 #define RETRY_LIMIT             10
50 #define BUFFER_SIZE                             2400    //2048
51 #define TX_RING                                 0xa
52 #define PRIO_RING                               0xc
53
54
55 // Flags for Bulkflags control for bulk out data
56 //
57 #define fRTUSB_BULK_OUT_DATA_NULL                               0x00000001
58 #define fRTUSB_BULK_OUT_RTS                                             0x00000002
59 #define fRTUSB_BULK_OUT_MLME                                    0x00000004
60
61 #define fRTUSB_BULK_OUT_DATA_NORMAL                             0x00010000
62 #define fRTUSB_BULK_OUT_DATA_NORMAL_2                   0x00020000
63 #define fRTUSB_BULK_OUT_DATA_NORMAL_3                   0x00040000
64 #define fRTUSB_BULK_OUT_DATA_NORMAL_4                   0x00080000
65
66 #define fRTUSB_BULK_OUT_PSPOLL                                  0x00000020
67 #define fRTUSB_BULK_OUT_DATA_FRAG                               0x00000040
68 #define fRTUSB_BULK_OUT_DATA_FRAG_2                             0x00000080
69 #define fRTUSB_BULK_OUT_DATA_FRAG_3                             0x00000100
70 #define fRTUSB_BULK_OUT_DATA_FRAG_4                             0x00000200
71
72 #ifdef RALINK_ATE
73 #define fRTUSB_BULK_OUT_DATA_ATE                                0x00100000
74 #endif // RALINK_ATE //
75
76 #define RT2870_USB_DEVICES      \
77 {       \
78         {USB_DEVICE(0x148F,0x2770)}, /* Ralink */               \
79         {USB_DEVICE(0x1737,0x0071)}, /* Linksys WUSB600N */     \
80         {USB_DEVICE(0x148F,0x2870)}, /* Ralink */               \
81         {USB_DEVICE(0x148F,0x3070)}, /* Ralink */               \
82         {USB_DEVICE(0x0B05,0x1731)}, /* Asus */                 \
83         {USB_DEVICE(0x0B05,0x1732)}, /* Asus */                 \
84         {USB_DEVICE(0x0B05,0x1742)}, /* Asus */                 \
85         {USB_DEVICE(0x0DF6,0x0017)}, /* Sitecom */              \
86         {USB_DEVICE(0x0DF6,0x002B)}, /* Sitecom */              \
87         {USB_DEVICE(0x0DF6,0x002C)}, /* Sitecom */              \
88         {USB_DEVICE(0x0DF6,0x002D)}, /* Sitecom */              \
89         {USB_DEVICE(0x0DF6,0x0039)}, /* Sitecom */              \
90         {USB_DEVICE(0x14B2,0x3C06)}, /* Conceptronic */         \
91         {USB_DEVICE(0x14B2,0x3C28)}, /* Conceptronic */         \
92         {USB_DEVICE(0x2019,0xED06)}, /* Planex Communications, Inc. */          \
93         {USB_DEVICE(0x2019,0xAB25)}, /* Planex Communications, Inc. RT3070 */           \
94         {USB_DEVICE(0x07D1,0x3C09)}, /* D-Link */               \
95         {USB_DEVICE(0x07D1,0x3C11)}, /* D-Link */               \
96         {USB_DEVICE(0x14B2,0x3C07)}, /* AL */                   \
97         {USB_DEVICE(0x14B2,0x3C12)}, /* AL */           \
98         {USB_DEVICE(0x050D,0x8053)}, /* Belkin */               \
99         {USB_DEVICE(0x14B2,0x3C23)}, /* Airlink */              \
100         {USB_DEVICE(0x14B2,0x3C27)}, /* Airlink */              \
101         {USB_DEVICE(0x07AA,0x002F)}, /* Corega */               \
102         {USB_DEVICE(0x07AA,0x003C)}, /* Corega */               \
103         {USB_DEVICE(0x07AA,0x003F)}, /* Corega */               \
104         {USB_DEVICE(0x18C5,0x0012)}, /* Corega */               \
105         {USB_DEVICE(0x1044,0x800B)}, /* Gigabyte */             \
106         {USB_DEVICE(0x15A9,0x0006)}, /* Sparklan */             \
107         {USB_DEVICE(0x083A,0xB522)}, /* SMC */                  \
108         {USB_DEVICE(0x083A,0xA618)}, /* SMC */                  \
109         {USB_DEVICE(0x083A,0x7522)}, /* Arcadyan */             \
110         {USB_DEVICE(0x0CDE,0x0022)}, /* ZCOM */                 \
111         {USB_DEVICE(0x0586,0x3416)}, /* Zyxel */                \
112         {USB_DEVICE(0x0CDE,0x0025)}, /* Zyxel */                \
113         {USB_DEVICE(0x1740,0x9701)}, /* EnGenius */             \
114         {USB_DEVICE(0x1740,0x9702)}, /* EnGenius */             \
115         {USB_DEVICE(0x0471,0x200f)}, /* Philips */              \
116         {USB_DEVICE(0x14B2,0x3C25)}, /* Draytek */              \
117         {USB_DEVICE(0x13D3,0x3247)}, /* AzureWave */    \
118         {USB_DEVICE(0x083A,0x6618)}, /* Accton */               \
119         {USB_DEVICE(0x15c5,0x0008)}, /* Amit */                 \
120         {USB_DEVICE(0x0E66,0x0001)}, /* Hawking */              \
121         {USB_DEVICE(0x0E66,0x0003)}, /* Hawking */              \
122         {USB_DEVICE(0x129B,0x1828)}, /* Siemens */              \
123         {USB_DEVICE(0x157E,0x300E)},    /* U-Media */   \
124         {USB_DEVICE(0x050d,0x805c)},                                    \
125         {USB_DEVICE(0x1482,0x3C09)}, /* Abocom*/                \
126         {USB_DEVICE(0x14B2,0x3C09)}, /* Alpha */                \
127         {USB_DEVICE(0x04E8,0x2018)}, /* samsung */      \
128         {USB_DEVICE(0x07B8,0x3070)}, /* AboCom */               \
129         {USB_DEVICE(0x07B8,0x3071)}, /* AboCom */               \
130         {USB_DEVICE(0x07B8,0x2870)}, /* AboCom */               \
131         {USB_DEVICE(0x07B8,0x2770)}, /* AboCom */               \
132         {USB_DEVICE(0x7392,0x7711)}, /* Edimax */               \
133         {USB_DEVICE(0x5A57,0x0280)}, /* Zinwell */              \
134         {USB_DEVICE(0x5A57,0x0282)}, /* Zinwell */              \
135         {USB_DEVICE(0x0789,0x0162)}, /* Logitec */              \
136         {USB_DEVICE(0x0789,0x0163)}, /* Logitec */              \
137         {USB_DEVICE(0x0789,0x0164)}, /* Logitec */              \
138         {USB_DEVICE(0x7392,0x7717)}, /* Edimax */               \
139         { }/* Terminating entry */                      \
140 }
141
142 #define FREE_HTTX_RING(_p, _b, _t)                      \
143 {                                                                               \
144         if ((_t)->ENextBulkOutPosition == (_t)->CurWritePosition)                               \
145         {                                                                                                                                       \
146                 (_t)->bRingEmpty = TRUE;                        \
147         }                                                                                                                                       \
148         /*NdisInterlockedDecrement(&(_p)->TxCount); */\
149 }
150
151 //
152 // RXINFO appends at the end of each rx packet.
153 //
154 #ifdef RT_BIG_ENDIAN
155 typedef struct  PACKED _RXINFO_STRUC {
156         UINT32          PlcpSignal:12;
157         UINT32          LastAMSDU:1;
158         UINT32          CipherAlg:1;
159         UINT32          PlcpRssil:1;
160         UINT32          Decrypted:1;
161         UINT32          AMPDU:1;                // To be moved
162         UINT32          L2PAD:1;
163         UINT32          RSSI:1;
164         UINT32          HTC:1;
165         UINT32          AMSDU:1;                // rx with 802.3 header, not 802.11 header.
166         UINT32          CipherErr:2;        // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
167         UINT32          Crc:1;              // 1: CRC error
168         UINT32          MyBss:1;        // 1: this frame belongs to the same BSSID
169         UINT32          Bcast:1;            // 1: this is a broadcast frame
170         UINT32          Mcast:1;            // 1: this is a multicast frame
171         UINT32          U2M:1;              // 1: this RX frame is unicast to me
172         UINT32          FRAG:1;
173         UINT32          NULLDATA:1;
174         UINT32          DATA:1;
175         UINT32          BA:1;
176 }       RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
177 #else
178 typedef struct  PACKED _RXINFO_STRUC {
179         UINT32          BA:1;
180         UINT32          DATA:1;
181         UINT32          NULLDATA:1;
182         UINT32          FRAG:1;
183         UINT32          U2M:1;              // 1: this RX frame is unicast to me
184         UINT32          Mcast:1;            // 1: this is a multicast frame
185         UINT32          Bcast:1;            // 1: this is a broadcast frame
186         UINT32          MyBss:1;        // 1: this frame belongs to the same BSSID
187         UINT32          Crc:1;              // 1: CRC error
188         UINT32          CipherErr:2;        // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
189         UINT32          AMSDU:1;                // rx with 802.3 header, not 802.11 header.
190         UINT32          HTC:1;
191         UINT32          RSSI:1;
192         UINT32          L2PAD:1;
193         UINT32          AMPDU:1;                // To be moved
194         UINT32          Decrypted:1;
195         UINT32          PlcpRssil:1;
196         UINT32          CipherAlg:1;
197         UINT32          LastAMSDU:1;
198         UINT32          PlcpSignal:12;
199 }       RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
200 #endif
201
202
203 //
204 // TXINFO
205 //
206 #ifdef RT_BIG_ENDIAN
207 typedef struct  _TXINFO_STRUC {
208         // Word 0
209         UINT32          USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
210         UINT32          USBDMANextVLD:1;        //used ONLY in USB bulk Aggregation, NextValid
211         UINT32          rsv2:2;  // Software use.
212         UINT32          SwUseLastRound:1; // Software use.
213         UINT32          QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
214         UINT32          WIV:1;  // Wireless Info Valid. 1 if Driver already fill WI,  o if DMA needs to copy WI to correctposition
215         UINT32          rsv:8;
216         UINT32          USBDMATxPktLen:16;      //used ONLY in USB bulk Aggregation,  Total byte counts of all sub-frame.
217 }       TXINFO_STRUC, *PTXINFO_STRUC;
218 #else
219 typedef struct  _TXINFO_STRUC {
220         // Word 0
221         UINT32          USBDMATxPktLen:16;      //used ONLY in USB bulk Aggregation,  Total byte counts of all sub-frame.
222         UINT32          rsv:8;
223         UINT32          WIV:1;  // Wireless Info Valid. 1 if Driver already fill WI,  o if DMA needs to copy WI to correctposition
224         UINT32          QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
225         UINT32          SwUseLastRound:1; // Software use.
226         UINT32          rsv2:2;  // Software use.
227         UINT32          USBDMANextVLD:1;        //used ONLY in USB bulk Aggregation, NextValid
228         UINT32          USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
229 }       TXINFO_STRUC, *PTXINFO_STRUC;
230 #endif
231
232 #define TXINFO_SIZE                             4
233 #define RXINFO_SIZE                             4
234 #define TXPADDING_SIZE                  11
235
236 //
237 // Management ring buffer format
238 //
239 typedef struct  _MGMT_STRUC     {
240         BOOLEAN         Valid;
241         PUCHAR          pBuffer;
242         ULONG           Length;
243 }       MGMT_STRUC, *PMGMT_STRUC;
244
245
246 /* ----------------- EEPROM Related MACRO ----------------- */
247 #define RT28xx_EEPROM_READ16(pAd, offset, var)                                  \
248         do {                                                                                                            \
249                 RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2);                \
250                 var = le2cpu16(var);                                                                    \
251         }while(0)
252
253 #define RT28xx_EEPROM_WRITE16(pAd, offset, var)                                 \
254         do{                                                                                                                     \
255                 USHORT _tmpVar;                                                                                 \
256                 _tmpVar = cpu2le16(var);                                                                \
257                 RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2);   \
258         }while(0)
259
260 /* ----------------- TASK/THREAD Related MACRO ----------------- */
261 #define RT28XX_TASK_THREAD_INIT(pAd, Status)            \
262         Status = CreateThreads(net_dev);
263
264
265 /* ----------------- Frimware Related MACRO ----------------- */
266 #if 0
267 #define RT28XX_FIRMUD_INIT(pAd)         \
268         {       UINT32  MacReg;                         \
269                 RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg); }
270
271 #define RT28XX_FIRMUD_END(pAd)  \
272         RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff); \
273         RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff); \
274         RTUSBFirmwareRun(pAd);
275 #else
276 #define RT28XX_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen)          \
277         RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
278 #endif
279
280 /* ----------------- TX Related MACRO ----------------- */
281 #define RT28XX_START_DEQUEUE(pAd, QueIdx, irqFlags)                             \
282                         {                                                                                                       \
283                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
284                                 if (pAd->DeQueueRunning[QueIdx])                                                \
285                                 {                                                                                                               \
286                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
287                                         printk("DeQueueRunning[%d]= TRUE!\n", QueIdx);          \
288                                         continue;                                                                                       \
289                                 }                                                                                                               \
290                                 else                                                                                                    \
291                                 {                                                                                                               \
292                                         pAd->DeQueueRunning[QueIdx] = TRUE;                                     \
293                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
294                                 }                                                                                                               \
295                         }
296 #define RT28XX_STOP_DEQUEUE(pAd, QueIdx, irqFlags)                                              \
297                         do{                                                                                                                     \
298                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
299                                 pAd->DeQueueRunning[QueIdx] = FALSE;                                    \
300                                 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);   \
301                         }while(0)
302
303
304 #define RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
305                 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
306
307 #define RT28XX_RELEASE_DESC_RESOURCE(pAd, QueIdx)                       \
308                 do{}while(0)
309
310 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType)          \
311                 ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
312
313
314
315 #define fRTMP_ADAPTER_NEED_STOP_TX              \
316                 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
317                  fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
318                  fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
319
320
321 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)       \
322                         RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
323
324 #define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)   \
325                         RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
326
327 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
328                         RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
329
330 #define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)     \
331                         RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
332
333 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)     \
334                         RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
335
336 #define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
337                         /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx)*/
338
339 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx)      \
340                         RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
341
342
343 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)   \
344                         RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
345
346 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen)   \
347                         RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
348
349 #define RTMP_PKT_TAIL_PADDING   11 // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
350
351 extern UCHAR EpToQueue[6];
352
353
354 #ifdef RT2870
355 #define GET_TXRING_FREENO(_pAd, _QueIdx)        (_QueIdx) //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
356 #define GET_MGMTRING_FREENO(_pAd)                       (_pAd->MgmtRing.TxSwFreeIdx)
357 #endif // RT2870 //
358
359
360 /* ----------------- RX Related MACRO ----------------- */
361 //#define RT28XX_RX_ERROR_CHECK                         RTMPCheckRxWI
362
363 #if 0
364 #define RT28XX_RCV_INIT(pAd)                                    \
365         pAd->TransferBufferLength = 0;                          \
366         pAd->ReadPosition = 0;                                          \
367         pAd->pCurrRxContext = NULL;
368 #endif
369
370 #define RT28XX_RV_ALL_BUF_END(bBulkReceive)             \
371         /* We return STATUS_MORE_PROCESSING_REQUIRED so that the completion */  \
372         /* routine (IofCompleteRequest) will stop working on the irp. */                \
373         if (bBulkReceive == TRUE)       RTUSBBulkReceive(pAd);
374
375
376 /* ----------------- ASIC Related MACRO ----------------- */
377 #if 0
378 #define RT28XX_DMA_WRITE_INIT(GloCfg)                   \
379         {       GloCfg.field.EnTXWriteBackDDONE = 1;    \
380                 GloCfg.field.EnableRxDMA = 1;                   \
381                 GloCfg.field.EnableTxDMA = 1; }
382
383 #define RT28XX_DMA_POST_WRITE(_pAd)                             \
384         do{     USB_DMA_CFG_STRUC       UsbCfg;                         \
385                 UsbCfg.word = 0;                                                \
386                 /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */ \
387                 UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE /1024)-3;  \
388                 UsbCfg.field.phyclear = 0;                                                              \
389                 /* usb version is 1.1,do not use bulk in aggregation */ \
390                 if (_pAd->BulkInMaxPacketSize == 512)                                   \
391                         UsbCfg.field.RxBulkAggEn = 1;                                           \
392                 UsbCfg.field.RxBulkEn = 1;                                                              \
393                 UsbCfg.field.TxBulkEn = 1;                                                              \
394                 UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */             \
395                 RTUSBWriteMACRegister(_pAd, USB_DMA_CFG, UsbCfg.word);  \
396         }while(0)
397 #endif
398
399 // reset MAC of a station entry to 0xFFFFFFFFFFFF
400 #define RT28XX_STA_ENTRY_MAC_RESET(pAd, Wcid)                                   \
401         {       RT_SET_ASIC_WCID        SetAsicWcid;                                            \
402                 SetAsicWcid.WCID = Wcid;                                                                \
403                 SetAsicWcid.SetTid = 0xffffffff;                                                \
404                 SetAsicWcid.DeleteTid = 0xffffffff;                                             \
405                 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID,   \
406                                 &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));        }
407
408 // add this entry into ASIC RX WCID search table
409 #define RT28XX_STA_ENTRY_ADD(pAd, pEntry)                                                       \
410         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY,    \
411                                                         pEntry, sizeof(MAC_TABLE_ENTRY));
412
413 // remove Pair-wise key material from ASIC
414 // yet implement
415 #define RT28XX_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid)
416
417 // add Client security information into ASIC WCID table and IVEIV table
418 #define RT28XX_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry)                                         \
419         {       RT28XX_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid);                                                           \
420                 if (pEntry->Aid >= 1) {                                                                                                         \
421                         RT_SET_ASIC_WCID_ATTRI  SetAsicWcidAttri;                                                               \
422                         SetAsicWcidAttri.WCID = pEntry->Aid;                                                                    \
423                         if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) &&                               \
424                                 (pEntry->WepStatus == Ndis802_11Encryption1Enabled))                            \
425                         {                                                                                                                                               \
426                                 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg;       \
427                         }                                                                                                                                               \
428                         else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone)                                 \
429                         {                                                                                                                                               \
430                                 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg;       \
431                         }                                                                                                                                               \
432                         else SetAsicWcidAttri.Cipher = 0;                                                                               \
433             DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher));       \
434                         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER,                    \
435                                                         &SetAsicWcidAttri, sizeof(RT_SET_ASIC_WCID_ATTRI)); } }
436
437 // Insert the BA bitmap to ASIC for the Wcid entry
438 #define RT28XX_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID)                                 \
439                 do{                                                                                                                             \
440                         RT_SET_ASIC_WCID        SetAsicWcid;                                                    \
441                         SetAsicWcid.WCID = (_Aid);                                                                      \
442                         SetAsicWcid.SetTid = (0x10000<<(_TID));                                         \
443                         SetAsicWcid.DeleteTid = 0xffffffff;                                                     \
444                         RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));       \
445                 }while(0)
446
447 // Remove the BA bitmap from ASIC for the Wcid entry
448 #define RT28XX_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID)                              \
449                 do{                                                                                                                             \
450                         RT_SET_ASIC_WCID        SetAsicWcid;                                                    \
451                         SetAsicWcid.WCID = (_Wcid);                                                                     \
452                         SetAsicWcid.SetTid = (0xffffffff);                                                      \
453                         SetAsicWcid.DeleteTid = (0x10000<<(_TID) );                                     \
454                         RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));       \
455                 }while(0)
456
457
458 /* ----------------- PCI/USB Related MACRO ----------------- */
459 #define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p)                 \
460         ((POS_COOKIE)handle)->pUsb_Dev = dev_p;
461
462 // no use
463 #define RT28XX_UNMAP()
464 #define RT28XX_IRQ_REQUEST(net_dev)
465 #define RT28XX_IRQ_RELEASE(net_dev)
466 #define RT28XX_IRQ_INIT(pAd)
467 #define RT28XX_IRQ_ENABLE(pAd)
468
469
470 /* ----------------- MLME Related MACRO ----------------- */
471 #define RT28XX_MLME_HANDLER(pAd)                        RTUSBMlmeUp(pAd)
472
473 #define RT28XX_MLME_PRE_SANITY_CHECK(pAd)                                                               \
474         {       if ((pAd->CommonCfg.bHardwareRadio == TRUE) &&                                  \
475                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&          \
476                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {       \
477                         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
478
479 #define RT28XX_MLME_STA_QUICK_RSP_WAKE_UP(pAd)  \
480         {       RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0);      \
481                 RTUSBMlmeUp(pAd); }
482
483 #define RT28XX_MLME_RESET_STATE_MACHINE(pAd)    \
484                         MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL);     \
485                         RTUSBMlmeUp(pAd);
486
487 #define RT28XX_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)            \
488         {       RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY));      \
489                 RTUSBMlmeUp(_pAd);                                                                      \
490         }
491
492
493 /* ----------------- Power Save Related MACRO ----------------- */
494 #define RT28XX_PS_POLL_ENQUEUE(pAd)                                             \
495         {       RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);       \
496                 RTUSBKickBulkOut(pAd); }
497
498 #define RT28xx_CHIP_NAME            "RT2870"
499 #define USB_CYC_CFG                 0x02a4
500 #define STATUS_SUCCESS                          0x00
501 #define STATUS_UNSUCCESSFUL             0x01
502 #define NT_SUCCESS(status)                      (((status) > 0) ? (1):(0))
503 #define InterlockedIncrement            atomic_inc
504 #define NdisInterlockedIncrement        atomic_inc
505 #define InterlockedDecrement            atomic_dec
506 #define NdisInterlockedDecrement        atomic_dec
507 #define InterlockedExchange                     atomic_set
508 //#define NdisMSendComplete                     RTMP_SendComplete
509 #define NdisMCancelTimer                        RTMPCancelTimer
510 #define NdisAllocMemory(_ptr, _size, _flag)     \
511                                                                         do{_ptr = kmalloc((_size),(_flag));}while(0)
512 #define NdisFreeMemory(a, b, c)         kfree((a))
513 #define NdisMSleep                                      RTMPusecDelay           /* unit: microsecond */
514
515
516 #define USBD_TRANSFER_DIRECTION_OUT             0
517 #define USBD_TRANSFER_DIRECTION_IN              0
518 #define USBD_SHORT_TRANSFER_OK                  0
519 #define PURB                    purbb_t
520
521 #define RTUSB_FREE_URB(pUrb)    usb_free_urb(pUrb)
522
523 //#undef MlmeAllocateMemory
524 //#undef MlmeFreeMemory
525
526 typedef int                             NTSTATUS;
527 typedef struct usb_device       * PUSB_DEV;
528
529 /* MACRO for linux usb */
530 typedef struct urb *purbb_t;
531 typedef struct usb_ctrlrequest devctrlrequest;
532 #define PIRP            PVOID
533 #define PMDL            PVOID
534 #define NDIS_OID        UINT
535 #ifndef USB_ST_NOERROR
536 #define USB_ST_NOERROR     0
537 #endif
538
539 // vendor-specific control operations
540 #define CONTROL_TIMEOUT_JIFFIES ( (100 * HZ) / 1000)
541 #define UNLINK_TIMEOUT_MS               3
542
543 /* unlink urb   */
544 #define RTUSB_UNLINK_URB(pUrb)          usb_kill_urb(pUrb)
545
546 // Prototypes of completion funuc.
547 VOID RTUSBBulkOutDataPacketComplete(purbb_t purb, struct pt_regs *pt_regs);
548 VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs);
549 VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
550 VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
551 VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb, struct pt_regs *pt_regs);
552 VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs);
553
554
555 #define RTUSBMlmeUp(pAd)                \
556 {                                                                   \
557         POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
558         BUG_ON(pObj->MLMEThr_task == NULL);                 \
559         CHECK_PID_LEGALITY(task_pid(pObj->MLMEThr_task))                    \
560         up(&(pAd->mlme_semaphore)); \
561 }
562
563 #define RTUSBCMDUp(pAd)                 \
564 {                                                                           \
565         POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
566         BUG_ON(pObj->RTUSBCmdThr_task == NULL);     \
567         CHECK_PID_LEGALITY(task_pid(pObj->RTUSBCmdThr_task))        \
568             up(&(pAd->RTUSBCmd_semaphore)); \
569 }
570
571
572 static inline NDIS_STATUS RTMPAllocateMemory(
573         OUT PVOID *ptr,
574         IN size_t size)
575 {
576         *ptr = kmalloc(size, GFP_ATOMIC);
577         if(*ptr)
578                 return NDIS_STATUS_SUCCESS;
579         else
580                 return NDIS_STATUS_RESOURCES;
581 }
582
583 /* rtmp.h */
584 #define BEACON_RING_SIZE                2
585 #define DEVICE_VENDOR_REQUEST_OUT       0x40
586 #define DEVICE_VENDOR_REQUEST_IN        0xc0
587 #define INTERFACE_VENDOR_REQUEST_OUT    0x41
588 #define INTERFACE_VENDOR_REQUEST_IN     0xc1
589 #define MGMTPIPEIDX                                             0       // EP6 is highest priority
590
591 #define BULKOUT_MGMT_RESET_FLAG                         0x80
592
593 #define RTUSB_SET_BULK_FLAG(_M, _F)                             ((_M)->BulkFlags |= (_F))
594 #define RTUSB_CLEAR_BULK_FLAG(_M, _F)                   ((_M)->BulkFlags &= ~(_F))
595 #define RTUSB_TEST_BULK_FLAG(_M, _F)                    (((_M)->BulkFlags & (_F)) != 0)
596
597 #define EnqueueCmd(cmdq, cmdqelmt)              \
598 {                                                                               \
599         if (cmdq->size == 0)                            \
600                 cmdq->head = cmdqelmt;                  \
601         else                                                            \
602                 cmdq->tail->next = cmdqelmt;    \
603         cmdq->tail = cmdqelmt;                          \
604         cmdqelmt->next = NULL;                          \
605         cmdq->size++;                                           \
606 }
607
608 typedef struct   _RT_SET_ASIC_WCID {
609         ULONG WCID;          // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
610         ULONG SetTid;        // time-based: seconds, packet-based: kilo-packets
611         ULONG DeleteTid;        // time-based: seconds, packet-based: kilo-packets
612         UCHAR Addr[MAC_ADDR_LEN];       // avoid in interrupt when write key
613 } RT_SET_ASIC_WCID,*PRT_SET_ASIC_WCID;
614
615 typedef struct   _RT_SET_ASIC_WCID_ATTRI {
616         ULONG   WCID;          // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
617         ULONG   Cipher;        // ASIC Cipher definition
618         UCHAR   Addr[ETH_LENGTH_OF_ADDRESS];
619 } RT_SET_ASIC_WCID_ATTRI,*PRT_SET_ASIC_WCID_ATTRI;
620
621 typedef struct _MLME_MEMORY_STRUCT {
622         PVOID                           AllocVa;    //Pointer to the base virtual address of the allocated memory
623         struct _MLME_MEMORY_STRUCT      *Next;      //Pointer to the next virtual address of the allocated memory
624 }   MLME_MEMORY_STRUCT, *PMLME_MEMORY_STRUCT;
625
626 typedef struct  _MLME_MEMORY_HANDLER {
627         BOOLEAN                 MemRunning;         //The flag of the Mlme memory handler's status
628         UINT                    MemoryCount;        //Total nonpaged system-space memory not size
629         UINT                    InUseCount;         //Nonpaged system-space memory in used counts
630         UINT                    UnUseCount;         //Nonpaged system-space memory available counts
631         INT                    PendingCount;       //Nonpaged system-space memory for free counts
632         PMLME_MEMORY_STRUCT     pInUseHead;         //Pointer to the first nonpaed memory not used
633         PMLME_MEMORY_STRUCT     pInUseTail;         //Pointer to the last nonpaged memory not used
634         PMLME_MEMORY_STRUCT     pUnUseHead;         //Pointer to the first nonpaged memory in used
635         PMLME_MEMORY_STRUCT     pUnUseTail;         //Pointer to the last nonpaged memory in used
636         PULONG                  MemFreePending[MAX_MLME_HANDLER_MEMORY];   //an array to keep pending free-memory's pointer (32bits)
637 }   MLME_MEMORY_HANDLER, *PMLME_MEMORY_HANDLER;
638
639 typedef struct _CmdQElmt        {
640         UINT                            command;
641         PVOID                           buffer;
642         ULONG                           bufferlength;
643         BOOLEAN                         CmdFromNdis;
644         BOOLEAN                         SetOperation;
645         struct _CmdQElmt        *next;
646 }       CmdQElmt, *PCmdQElmt;
647
648 typedef struct  _CmdQ   {
649         UINT            size;
650         CmdQElmt        *head;
651         CmdQElmt        *tail;
652         UINT32          CmdQState;
653 }CmdQ, *PCmdQ;
654
655 //
656 // For WPA SUPPLICANT: WIRELESS EXT support wireless events: v14 or newer
657 //
658 #if WIRELESS_EXT >= 14
659 //#define WPA_SUPPLICANT_SUPPORT  1
660 #endif
661
662 /* oid.h */
663 // Cipher suite type for mixed mode group cipher, P802.11i-2004
664 typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
665         Cipher_Type_NONE,
666         Cipher_Type_WEP40,
667         Cipher_Type_TKIP,
668         Cipher_Type_RSVD,
669         Cipher_Type_CCMP,
670         Cipher_Type_WEP104
671 } RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
672
673 //CMDTHREAD_MULTI_READ_MAC
674 //CMDTHREAD_MULTI_WRITE_MAC
675 //CMDTHREAD_VENDOR_EEPROM_READ
676 //CMDTHREAD_VENDOR_EEPROM_WRITE
677 typedef struct  _CMDHandler_TLV {
678         USHORT          Offset;
679         USHORT          Length;
680         UCHAR           DataFirst;
681 }       CMDHandler_TLV, *PCMDHandler_TLV;
682
683 // New for MeetingHouse Api support
684 #define CMDTHREAD_VENDOR_RESET                      0x0D730101  // cmd
685 #define CMDTHREAD_VENDOR_UNPLUG                     0x0D730102  // cmd
686 #define CMDTHREAD_VENDOR_SWITCH_FUNCTION            0x0D730103  // cmd
687 #define CMDTHREAD_MULTI_WRITE_MAC                   0x0D730107  // cmd
688 #define CMDTHREAD_MULTI_READ_MAC                    0x0D730108  // cmd
689 #define CMDTHREAD_VENDOR_EEPROM_WRITE               0x0D73010A  // cmd
690 #define CMDTHREAD_VENDOR_EEPROM_READ                0x0D73010B  // cmd
691 #define CMDTHREAD_VENDOR_ENTER_TESTMODE             0x0D73010C  // cmd
692 #define CMDTHREAD_VENDOR_EXIT_TESTMODE              0x0D73010D  // cmd
693 #define CMDTHREAD_VENDOR_WRITE_BBP                  0x0D730119  // cmd
694 #define CMDTHREAD_VENDOR_READ_BBP                   0x0D730118  // cmd
695 #define CMDTHREAD_VENDOR_WRITE_RF                   0x0D73011A  // cmd
696 #define CMDTHREAD_VENDOR_FLIP_IQ                    0x0D73011D  // cmd
697 #define CMDTHREAD_RESET_BULK_OUT                    0x0D730210  // cmd
698 #define CMDTHREAD_RESET_BULK_IN                     0x0D730211  // cmd
699 #define CMDTHREAD_SET_PSM_BIT_SAVE                  0x0D730212  // cmd
700 #define CMDTHREAD_SET_RADIO                         0x0D730214  // cmd
701 #define CMDTHREAD_UPDATE_TX_RATE                    0x0D730216  // cmd
702 #define CMDTHREAD_802_11_ADD_KEY_WEP                0x0D730218  // cmd
703 #define CMDTHREAD_RESET_FROM_ERROR                  0x0D73021A  // cmd
704 #define CMDTHREAD_LINK_DOWN                         0x0D73021B  // cmd
705 #define CMDTHREAD_RESET_FROM_NDIS                   0x0D73021C  // cmd
706 #define CMDTHREAD_CHECK_GPIO                        0x0D730215  // cmd
707 #define CMDTHREAD_FORCE_WAKE_UP                     0x0D730222  // cmd
708 #define CMDTHREAD_SET_BW                            0x0D730225  // cmd
709 #define CMDTHREAD_SET_ASIC_WCID                     0x0D730226  // cmd
710 #define CMDTHREAD_SET_ASIC_WCID_CIPHER              0x0D730227  // cmd
711 #define CMDTHREAD_QKERIODIC_EXECUT                  0x0D73023D  // cmd
712 #define RT_CMD_SET_KEY_TABLE                        0x0D730228  // cmd
713 #define RT_CMD_SET_RX_WCID_TABLE                    0x0D730229  // cmd
714 #define CMDTHREAD_SET_CLIENT_MAC_ENTRY              0x0D73023E  // cmd
715 #define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER    0x0D710105  // cmd
716 #define CMDTHREAD_802_11_SET_PHY_MODE               0x0D79010C  // cmd
717 #define CMDTHREAD_802_11_SET_STA_CONFIG             0x0D790111  // cmd
718 #define CMDTHREAD_802_11_SET_PREAMBLE               0x0D790101  // cmd
719 #define CMDTHREAD_802_11_COUNTER_MEASURE                        0x0D790102      // cmd
720
721
722 #define WPA1AKMBIT          0x01
723 #define WPA2AKMBIT          0x02
724 #define WPA1PSKAKMBIT   0x04
725 #define WPA2PSKAKMBIT   0x08
726 #define TKIPBIT         0x01
727 #define CCMPBIT         0x02
728
729
730 #define RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx) \
731     RT28xxUsbStaAsicForceWakeup(pAd, bFromTx);
732
733 #define RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
734     RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
735
736 #define RT28XX_MLME_RADIO_ON(pAd) \
737     RT28xxUsbMlmeRadioOn(pAd);
738
739 #define RT28XX_MLME_RADIO_OFF(pAd) \
740     RT28xxUsbMlmeRadioOFF(pAd);
741
742 #endif //__RT2870_H__