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