0ca544028c8803fa2e0209995cb16f3b9b3e06a2
[safe/jmp/linux-2.6] / 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 #ifndef RT30xx
50 #define RETRY_LIMIT             10
51 #endif
52 #define BUFFER_SIZE                             2400    //2048
53 #define TX_RING                                 0xa
54 #define PRIO_RING                               0xc
55
56
57 // Flags for Bulkflags control for bulk out data
58 //
59 #define fRTUSB_BULK_OUT_DATA_NULL                               0x00000001
60 #define fRTUSB_BULK_OUT_RTS                                             0x00000002
61 #define fRTUSB_BULK_OUT_MLME                                    0x00000004
62
63 #define fRTUSB_BULK_OUT_DATA_NORMAL                             0x00010000
64 #define fRTUSB_BULK_OUT_DATA_NORMAL_2                   0x00020000
65 #define fRTUSB_BULK_OUT_DATA_NORMAL_3                   0x00040000
66 #define fRTUSB_BULK_OUT_DATA_NORMAL_4                   0x00080000
67 #ifdef RT30xx
68 #define fRTUSB_BULK_OUT_DATA_NORMAL_5                   0x00100000
69 #endif
70
71 #define fRTUSB_BULK_OUT_PSPOLL                                  0x00000020
72 #define fRTUSB_BULK_OUT_DATA_FRAG                               0x00000040
73 #define fRTUSB_BULK_OUT_DATA_FRAG_2                             0x00000080
74 #define fRTUSB_BULK_OUT_DATA_FRAG_3                             0x00000100
75 #define fRTUSB_BULK_OUT_DATA_FRAG_4                             0x00000200
76
77 #define FREE_HTTX_RING(_p, _b, _t)                      \
78 {                                                                               \
79         if ((_t)->ENextBulkOutPosition == (_t)->CurWritePosition)                               \
80         {                                                                                                                                       \
81                 (_t)->bRingEmpty = TRUE;                        \
82         }                                                                                                                                       \
83         /*NdisInterlockedDecrement(&(_p)->TxCount); */\
84 }
85
86 //
87 // RXINFO appends at the end of each rx packet.
88 //
89 typedef struct  PACKED _RXINFO_STRUC {
90         UINT32          BA:1;
91         UINT32          DATA:1;
92         UINT32          NULLDATA:1;
93         UINT32          FRAG:1;
94         UINT32          U2M:1;              // 1: this RX frame is unicast to me
95         UINT32          Mcast:1;            // 1: this is a multicast frame
96         UINT32          Bcast:1;            // 1: this is a broadcast frame
97         UINT32          MyBss:1;        // 1: this frame belongs to the same BSSID
98         UINT32          Crc:1;              // 1: CRC error
99         UINT32          CipherErr:2;        // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
100         UINT32          AMSDU:1;                // rx with 802.3 header, not 802.11 header.
101         UINT32          HTC:1;
102         UINT32          RSSI:1;
103         UINT32          L2PAD:1;
104         UINT32          AMPDU:1;                // To be moved
105         UINT32          Decrypted:1;
106         UINT32          PlcpRssil:1;
107         UINT32          CipherAlg:1;
108         UINT32          LastAMSDU:1;
109         UINT32          PlcpSignal:12;
110 }       RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
111
112 //
113 // TXINFO
114 //
115 typedef struct  _TXINFO_STRUC {
116         // Word 0
117         UINT32          USBDMATxPktLen:16;      //used ONLY in USB bulk Aggregation,  Total byte counts of all sub-frame.
118         UINT32          rsv:8;
119         UINT32          WIV:1;  // Wireless Info Valid. 1 if Driver already fill WI,  o if DMA needs to copy WI to correctposition
120         UINT32          QSEL:2; // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
121         UINT32          SwUseLastRound:1; // Software use.
122         UINT32          rsv2:2;  // Software use.
123         UINT32          USBDMANextVLD:1;        //used ONLY in USB bulk Aggregation, NextValid
124         UINT32          USBDMATxburst:1;//used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
125 }       TXINFO_STRUC, *PTXINFO_STRUC;
126
127 #define TXINFO_SIZE                             4
128 #define RXINFO_SIZE                             4
129 #define TXPADDING_SIZE                  11
130
131 //
132 // Management ring buffer format
133 //
134 typedef struct  _MGMT_STRUC     {
135         BOOLEAN         Valid;
136         PUCHAR          pBuffer;
137         ULONG           Length;
138 }       MGMT_STRUC, *PMGMT_STRUC;
139
140
141 /* ----------------- EEPROM Related MACRO ----------------- */
142 #ifdef RT30xx
143 #define RT28xx_EEPROM_READ16(pAd, offset, var)                                  \
144         do {                                                                                                            \
145                 RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2);                \
146                 if(!pAd->bUseEfuse)                                                                             \
147                 var = le2cpu16(var);                                                                    \
148         }while(0)
149
150 #define RT28xx_EEPROM_WRITE16(pAd, offset, var)                                 \
151         do{                                                                                                                     \
152                 USHORT _tmpVar=var;                                                                             \
153                 if(!pAd->bUseEfuse)                                                                     \
154                 _tmpVar = cpu2le16(var);                                                                \
155                 RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2);   \
156         }while(0)
157 #endif // RT30xx //
158 #ifndef RT30xx
159 #define RT28xx_EEPROM_READ16(pAd, offset, var)                                  \
160         do {                                                                                                            \
161                 RTUSBReadEEPROM(pAd, offset, (PUCHAR)&(var), 2);                \
162                 var = le2cpu16(var);                                                                    \
163         }while(0)
164
165 #define RT28xx_EEPROM_WRITE16(pAd, offset, var)                                 \
166         do{                                                                                                                     \
167                 USHORT _tmpVar;                                                                                 \
168                 _tmpVar = cpu2le16(var);                                                                \
169                 RTUSBWriteEEPROM(pAd, offset, (PUCHAR)&(_tmpVar), 2);   \
170         }while(0)
171 #endif // RT30xx //
172
173 /* ----------------- TASK/THREAD Related MACRO ----------------- */
174 #define RT28XX_TASK_THREAD_INIT(pAd, Status)            \
175         Status = CreateThreads(net_dev);
176
177
178 /* ----------------- Frimware Related MACRO ----------------- */
179 #define RT28XX_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen)          \
180         RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
181
182 /* ----------------- TX Related MACRO ----------------- */
183 #define RT28XX_START_DEQUEUE(pAd, QueIdx, irqFlags)                             \
184                         {                                                                                                       \
185                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
186                                 if (pAd->DeQueueRunning[QueIdx])                                                \
187                                 {                                                                                                               \
188                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
189                                         printk("DeQueueRunning[%d]= TRUE!\n", QueIdx);          \
190                                         continue;                                                                                       \
191                                 }                                                                                                               \
192                                 else                                                                                                    \
193                                 {                                                                                                               \
194                                         pAd->DeQueueRunning[QueIdx] = TRUE;                                     \
195                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
196                                 }                                                                                                               \
197                         }
198 #define RT28XX_STOP_DEQUEUE(pAd, QueIdx, irqFlags)                                              \
199                         do{                                                                                                                     \
200                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
201                                 pAd->DeQueueRunning[QueIdx] = FALSE;                                    \
202                                 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);   \
203                         }while(0)
204
205
206 #define RT28XX_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
207                 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
208
209 #define RT28XX_RELEASE_DESC_RESOURCE(pAd, QueIdx)                       \
210                 do{}while(0)
211
212 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType)          \
213                 ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
214
215
216
217 #define fRTMP_ADAPTER_NEED_STOP_TX              \
218                 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
219                  fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
220                  fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
221
222
223 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)       \
224                         RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
225
226 #define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)   \
227                         RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
228
229 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
230                         RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
231
232 #define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)     \
233                         RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
234
235 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)     \
236                         RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
237
238 #define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
239                         /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx)*/
240
241 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx)      \
242                         RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
243
244
245 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)   \
246                         RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
247
248 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen)   \
249                         RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
250
251 #define RTMP_PKT_TAIL_PADDING   11 // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
252
253 extern UCHAR EpToQueue[6];
254
255
256 #ifdef RT2870
257 #define GET_TXRING_FREENO(_pAd, _QueIdx)        (_QueIdx) //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
258 #define GET_MGMTRING_FREENO(_pAd)                       (_pAd->MgmtRing.TxSwFreeIdx)
259 #endif // RT2870 //
260
261
262 /* ----------------- RX Related MACRO ----------------- */
263 //#define RT28XX_RX_ERROR_CHECK                         RTMPCheckRxWI
264
265 #define RT28XX_RV_ALL_BUF_END(bBulkReceive)             \
266         /* We return STATUS_MORE_PROCESSING_REQUIRED so that the completion */  \
267         /* routine (IofCompleteRequest) will stop working on the irp. */                \
268         if (bBulkReceive == TRUE)       RTUSBBulkReceive(pAd);
269
270
271 /* ----------------- ASIC Related MACRO ----------------- */
272
273 // reset MAC of a station entry to 0xFFFFFFFFFFFF
274 #define RT28XX_STA_ENTRY_MAC_RESET(pAd, Wcid)                                   \
275         {       RT_SET_ASIC_WCID        SetAsicWcid;                                            \
276                 SetAsicWcid.WCID = Wcid;                                                                \
277                 SetAsicWcid.SetTid = 0xffffffff;                                                \
278                 SetAsicWcid.DeleteTid = 0xffffffff;                                             \
279                 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID,   \
280                                 &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));        }
281
282 // add this entry into ASIC RX WCID search table
283 #define RT28XX_STA_ENTRY_ADD(pAd, pEntry)                                                       \
284         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY,    \
285                                                         pEntry, sizeof(MAC_TABLE_ENTRY));
286
287 #ifdef RT30xx
288 // add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
289 // Set MAC register value according operation mode
290 #define RT28XX_UPDATE_PROTECT(pAd)      \
291         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_UPDATE_PROTECT, NULL, 0);
292 // end johnli
293 #endif
294
295 // remove Pair-wise key material from ASIC
296 // yet implement
297 #define RT28XX_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid)
298
299 // add Client security information into ASIC WCID table and IVEIV table
300 #define RT28XX_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry)                                         \
301         {       RT28XX_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid);                                                           \
302                 if (pEntry->Aid >= 1) {                                                                                                         \
303                         RT_SET_ASIC_WCID_ATTRI  SetAsicWcidAttri;                                                               \
304                         SetAsicWcidAttri.WCID = pEntry->Aid;                                                                    \
305                         if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) &&                               \
306                                 (pEntry->WepStatus == Ndis802_11Encryption1Enabled))                            \
307                         {                                                                                                                                               \
308                                 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg;       \
309                         }                                                                                                                                               \
310                         else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone)                                 \
311                         {                                                                                                                                               \
312                                 SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg;       \
313                         }                                                                                                                                               \
314                         else SetAsicWcidAttri.Cipher = 0;                                                                               \
315             DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher));       \
316                         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER,                    \
317                                                         &SetAsicWcidAttri, sizeof(RT_SET_ASIC_WCID_ATTRI)); } }
318
319 // Insert the BA bitmap to ASIC for the Wcid entry
320 #define RT28XX_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID)                                 \
321                 do{                                                                                                                             \
322                         RT_SET_ASIC_WCID        SetAsicWcid;                                                    \
323                         SetAsicWcid.WCID = (_Aid);                                                                      \
324                         SetAsicWcid.SetTid = (0x10000<<(_TID));                                         \
325                         SetAsicWcid.DeleteTid = 0xffffffff;                                                     \
326                         RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));       \
327                 }while(0)
328
329 // Remove the BA bitmap from ASIC for the Wcid entry
330 #define RT28XX_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID)                              \
331                 do{                                                                                                                             \
332                         RT_SET_ASIC_WCID        SetAsicWcid;                                                    \
333                         SetAsicWcid.WCID = (_Wcid);                                                                     \
334                         SetAsicWcid.SetTid = (0xffffffff);                                                      \
335                         SetAsicWcid.DeleteTid = (0x10000<<(_TID) );                                     \
336                         RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(RT_SET_ASIC_WCID));       \
337                 }while(0)
338
339
340 /* ----------------- PCI/USB Related MACRO ----------------- */
341 #define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p)                 \
342         ((POS_COOKIE)handle)->pUsb_Dev = dev_p;
343
344 // no use
345 #define RT28XX_UNMAP()
346 #define RT28XX_IRQ_REQUEST(net_dev)
347 #define RT28XX_IRQ_RELEASE(net_dev)
348 #define RT28XX_IRQ_INIT(pAd)
349 #define RT28XX_IRQ_ENABLE(pAd)
350
351
352 /* ----------------- MLME Related MACRO ----------------- */
353 #define RT28XX_MLME_HANDLER(pAd)                        RTUSBMlmeUp(pAd)
354
355 #define RT28XX_MLME_PRE_SANITY_CHECK(pAd)                                                               \
356         {       if ((pAd->CommonCfg.bHardwareRadio == TRUE) &&                                  \
357                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&          \
358                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {       \
359                         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
360
361 #define RT28XX_MLME_STA_QUICK_RSP_WAKE_UP(pAd)  \
362         {       RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0);      \
363                 RTUSBMlmeUp(pAd); }
364
365 #define RT28XX_MLME_RESET_STATE_MACHINE(pAd)    \
366                         MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL);     \
367                         RTUSBMlmeUp(pAd);
368
369 #define RT28XX_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)            \
370         {       RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY));      \
371                 RTUSBMlmeUp(_pAd);                                                                      \
372         }
373
374
375 /* ----------------- Power Save Related MACRO ----------------- */
376 #define RT28XX_PS_POLL_ENQUEUE(pAd)                                             \
377         {       RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);       \
378                 RTUSBKickBulkOut(pAd); }
379
380 #ifdef RT30xx
381 #define RT28xx_CHIP_NAME            "RT3070"
382 #else
383 #define RT28xx_CHIP_NAME            "RT2870"
384 #endif
385 #define USB_CYC_CFG                 0x02a4
386 #ifndef RT30xx
387 #define STATUS_SUCCESS                          0x00
388 #define STATUS_UNSUCCESSFUL             0x01
389 #endif
390 #define NT_SUCCESS(status)                      (((status) > 0) ? (1):(0))
391 #define InterlockedIncrement            atomic_inc
392 #define NdisInterlockedIncrement        atomic_inc
393 #define InterlockedDecrement            atomic_dec
394 #define NdisInterlockedDecrement        atomic_dec
395 #define InterlockedExchange                     atomic_set
396 //#define NdisMSendComplete                     RTMP_SendComplete
397 #define NdisMCancelTimer                        RTMPCancelTimer
398 #define NdisAllocMemory(_ptr, _size, _flag)     \
399                                                                         do{_ptr = kmalloc((_size),(_flag));}while(0)
400 #define NdisFreeMemory(a, b, c)         kfree((a))
401 #define NdisMSleep                                      RTMPusecDelay           /* unit: microsecond */
402
403
404 #define USBD_TRANSFER_DIRECTION_OUT             0
405 #define USBD_TRANSFER_DIRECTION_IN              0
406 #define USBD_SHORT_TRANSFER_OK                  0
407 #define PURB                    purbb_t
408
409 #define RTUSB_FREE_URB(pUrb)    usb_free_urb(pUrb)
410
411 //#undef MlmeAllocateMemory
412 //#undef MlmeFreeMemory
413
414 #ifndef RT30xx
415 typedef int                             NTSTATUS;
416 #endif
417 typedef struct usb_device       * PUSB_DEV;
418
419 /* MACRO for linux usb */
420 typedef struct urb *purbb_t;
421 typedef struct usb_ctrlrequest devctrlrequest;
422 #define PIRP            PVOID
423 #define PMDL            PVOID
424 #define NDIS_OID        UINT
425 #ifndef USB_ST_NOERROR
426 #define USB_ST_NOERROR     0
427 #endif
428
429 // vendor-specific control operations
430 #define CONTROL_TIMEOUT_JIFFIES ( (100 * HZ) / 1000)
431 #define UNLINK_TIMEOUT_MS               3
432
433 /* unlink urb   */
434 #define RTUSB_UNLINK_URB(pUrb)          usb_kill_urb(pUrb)
435
436 // Prototypes of completion funuc.
437 VOID RTUSBBulkOutDataPacketComplete(purbb_t purb, struct pt_regs *pt_regs);
438 VOID RTUSBBulkOutMLMEPacketComplete(purbb_t pUrb, struct pt_regs *pt_regs);
439 VOID RTUSBBulkOutNullFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
440 VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs);
441 VOID RTUSBBulkOutPsPollComplete(purbb_t pUrb, struct pt_regs *pt_regs);
442 VOID RTUSBBulkRxComplete(purbb_t pUrb, struct pt_regs *pt_regs);
443
444 #define RTUSBMlmeUp(pAd)                \
445 {                                                                   \
446         POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
447         if (pid_nr(pObj->MLMEThr_pid) > 0) \
448         up(&(pAd->mlme_semaphore)); \
449 }
450
451 #define RTUSBCMDUp(pAd)                 \
452 {                                                                           \
453         POS_COOKIE pObj = (POS_COOKIE) pAd->OS_Cookie;  \
454         if (pid_nr(pObj->RTUSBCmdThr_pid) > 0) \
455             up(&(pAd->RTUSBCmd_semaphore)); \
456 }
457
458 static inline NDIS_STATUS RTMPAllocateMemory(
459         OUT PVOID *ptr,
460         IN size_t size)
461 {
462         *ptr = kmalloc(size, GFP_ATOMIC);
463         if(*ptr)
464                 return NDIS_STATUS_SUCCESS;
465         else
466                 return NDIS_STATUS_RESOURCES;
467 }
468
469 /* rtmp.h */
470 #define BEACON_RING_SIZE                2
471 #define DEVICE_VENDOR_REQUEST_OUT       0x40
472 #define DEVICE_VENDOR_REQUEST_IN        0xc0
473 #define INTERFACE_VENDOR_REQUEST_OUT    0x41
474 #define INTERFACE_VENDOR_REQUEST_IN     0xc1
475 #define MGMTPIPEIDX                                             0       // EP6 is highest priority
476
477 #define BULKOUT_MGMT_RESET_FLAG                         0x80
478
479 #define RTUSB_SET_BULK_FLAG(_M, _F)                             ((_M)->BulkFlags |= (_F))
480 #define RTUSB_CLEAR_BULK_FLAG(_M, _F)                   ((_M)->BulkFlags &= ~(_F))
481 #define RTUSB_TEST_BULK_FLAG(_M, _F)                    (((_M)->BulkFlags & (_F)) != 0)
482
483 #define EnqueueCmd(cmdq, cmdqelmt)              \
484 {                                                                               \
485         if (cmdq->size == 0)                            \
486                 cmdq->head = cmdqelmt;                  \
487         else                                                            \
488                 cmdq->tail->next = cmdqelmt;    \
489         cmdq->tail = cmdqelmt;                          \
490         cmdqelmt->next = NULL;                          \
491         cmdq->size++;                                           \
492 }
493
494 typedef struct   _RT_SET_ASIC_WCID {
495         ULONG WCID;          // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
496         ULONG SetTid;        // time-based: seconds, packet-based: kilo-packets
497         ULONG DeleteTid;        // time-based: seconds, packet-based: kilo-packets
498 #ifndef RT30xx
499         UCHAR Addr[MAC_ADDR_LEN];       // avoid in interrupt when write key
500 #endif
501 } RT_SET_ASIC_WCID,*PRT_SET_ASIC_WCID;
502
503 typedef struct   _RT_SET_ASIC_WCID_ATTRI {
504         ULONG   WCID;          // mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based
505         ULONG   Cipher;        // ASIC Cipher definition
506         UCHAR   Addr[ETH_LENGTH_OF_ADDRESS];
507 } RT_SET_ASIC_WCID_ATTRI,*PRT_SET_ASIC_WCID_ATTRI;
508
509 typedef struct _MLME_MEMORY_STRUCT {
510         PVOID                           AllocVa;    //Pointer to the base virtual address of the allocated memory
511         struct _MLME_MEMORY_STRUCT      *Next;      //Pointer to the next virtual address of the allocated memory
512 }   MLME_MEMORY_STRUCT, *PMLME_MEMORY_STRUCT;
513
514 typedef struct  _MLME_MEMORY_HANDLER {
515         BOOLEAN                 MemRunning;         //The flag of the Mlme memory handler's status
516         UINT                    MemoryCount;        //Total nonpaged system-space memory not size
517         UINT                    InUseCount;         //Nonpaged system-space memory in used counts
518         UINT                    UnUseCount;         //Nonpaged system-space memory available counts
519         INT                    PendingCount;       //Nonpaged system-space memory for free counts
520         PMLME_MEMORY_STRUCT     pInUseHead;         //Pointer to the first nonpaed memory not used
521         PMLME_MEMORY_STRUCT     pInUseTail;         //Pointer to the last nonpaged memory not used
522         PMLME_MEMORY_STRUCT     pUnUseHead;         //Pointer to the first nonpaged memory in used
523         PMLME_MEMORY_STRUCT     pUnUseTail;         //Pointer to the last nonpaged memory in used
524         PULONG                  MemFreePending[MAX_MLME_HANDLER_MEMORY];   //an array to keep pending free-memory's pointer (32bits)
525 }   MLME_MEMORY_HANDLER, *PMLME_MEMORY_HANDLER;
526
527 typedef struct _CmdQElmt        {
528         UINT                            command;
529         PVOID                           buffer;
530         ULONG                           bufferlength;
531         BOOLEAN                         CmdFromNdis;
532         BOOLEAN                         SetOperation;
533         struct _CmdQElmt        *next;
534 }       CmdQElmt, *PCmdQElmt;
535
536 typedef struct  _CmdQ   {
537         UINT            size;
538         CmdQElmt        *head;
539         CmdQElmt        *tail;
540         UINT32          CmdQState;
541 }CmdQ, *PCmdQ;
542
543 /* oid.h */
544 // Cipher suite type for mixed mode group cipher, P802.11i-2004
545 typedef enum _RT_802_11_CIPHER_SUITE_TYPE {
546         Cipher_Type_NONE,
547         Cipher_Type_WEP40,
548         Cipher_Type_TKIP,
549         Cipher_Type_RSVD,
550         Cipher_Type_CCMP,
551         Cipher_Type_WEP104
552 } RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE;
553
554 //CMDTHREAD_MULTI_READ_MAC
555 //CMDTHREAD_MULTI_WRITE_MAC
556 //CMDTHREAD_VENDOR_EEPROM_READ
557 //CMDTHREAD_VENDOR_EEPROM_WRITE
558 typedef struct  _CMDHandler_TLV {
559         USHORT          Offset;
560         USHORT          Length;
561         UCHAR           DataFirst;
562 }       CMDHandler_TLV, *PCMDHandler_TLV;
563
564 // New for MeetingHouse Api support
565 #define CMDTHREAD_VENDOR_RESET                      0x0D730101  // cmd
566 #define CMDTHREAD_VENDOR_UNPLUG                     0x0D730102  // cmd
567 #define CMDTHREAD_VENDOR_SWITCH_FUNCTION            0x0D730103  // cmd
568 #define CMDTHREAD_MULTI_WRITE_MAC                   0x0D730107  // cmd
569 #define CMDTHREAD_MULTI_READ_MAC                    0x0D730108  // cmd
570 #define CMDTHREAD_VENDOR_EEPROM_WRITE               0x0D73010A  // cmd
571 #define CMDTHREAD_VENDOR_EEPROM_READ                0x0D73010B  // cmd
572 #define CMDTHREAD_VENDOR_ENTER_TESTMODE             0x0D73010C  // cmd
573 #define CMDTHREAD_VENDOR_EXIT_TESTMODE              0x0D73010D  // cmd
574 #define CMDTHREAD_VENDOR_WRITE_BBP                  0x0D730119  // cmd
575 #define CMDTHREAD_VENDOR_READ_BBP                   0x0D730118  // cmd
576 #define CMDTHREAD_VENDOR_WRITE_RF                   0x0D73011A  // cmd
577 #define CMDTHREAD_VENDOR_FLIP_IQ                    0x0D73011D  // cmd
578 #define CMDTHREAD_RESET_BULK_OUT                    0x0D730210  // cmd
579 #define CMDTHREAD_RESET_BULK_IN                     0x0D730211  // cmd
580 #define CMDTHREAD_SET_PSM_BIT_SAVE                  0x0D730212  // cmd
581 #define CMDTHREAD_SET_RADIO                         0x0D730214  // cmd
582 #define CMDTHREAD_UPDATE_TX_RATE                    0x0D730216  // cmd
583 #define CMDTHREAD_802_11_ADD_KEY_WEP                0x0D730218  // cmd
584 #define CMDTHREAD_RESET_FROM_ERROR                  0x0D73021A  // cmd
585 #define CMDTHREAD_LINK_DOWN                         0x0D73021B  // cmd
586 #define CMDTHREAD_RESET_FROM_NDIS                   0x0D73021C  // cmd
587 #define CMDTHREAD_CHECK_GPIO                        0x0D730215  // cmd
588 #define CMDTHREAD_FORCE_WAKE_UP                     0x0D730222  // cmd
589 #define CMDTHREAD_SET_BW                            0x0D730225  // cmd
590 #define CMDTHREAD_SET_ASIC_WCID                     0x0D730226  // cmd
591 #define CMDTHREAD_SET_ASIC_WCID_CIPHER              0x0D730227  // cmd
592 #define CMDTHREAD_QKERIODIC_EXECUT                  0x0D73023D  // cmd
593 #define RT_CMD_SET_KEY_TABLE                        0x0D730228  // cmd
594 #define RT_CMD_SET_RX_WCID_TABLE                    0x0D730229  // cmd
595 #define CMDTHREAD_SET_CLIENT_MAC_ENTRY              0x0D73023E  // cmd
596 #define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER    0x0D710105  // cmd
597 #define CMDTHREAD_802_11_SET_PHY_MODE               0x0D79010C  // cmd
598 #define CMDTHREAD_802_11_SET_STA_CONFIG             0x0D790111  // cmd
599 #define CMDTHREAD_802_11_SET_PREAMBLE               0x0D790101  // cmd
600 #define CMDTHREAD_802_11_COUNTER_MEASURE                        0x0D790102      // cmd
601
602 #ifdef RT30xx
603 // add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet
604 #define CMDTHREAD_UPDATE_PROTECT                                        0x0D790103      // cmd
605 // end johnli
606 #endif
607
608 #define WPA1AKMBIT          0x01
609 #define WPA2AKMBIT          0x02
610 #define WPA1PSKAKMBIT   0x04
611 #define WPA2PSKAKMBIT   0x08
612 #define TKIPBIT         0x01
613 #define CCMPBIT         0x02
614
615
616 #define RT28XX_STA_FORCE_WAKEUP(pAd, bFromTx) \
617     RT28xxUsbStaAsicForceWakeup(pAd, bFromTx);
618
619 #define RT28XX_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
620     RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
621
622 #define RT28XX_MLME_RADIO_ON(pAd) \
623     RT28xxUsbMlmeRadioOn(pAd);
624
625 #define RT28XX_MLME_RADIO_OFF(pAd) \
626     RT28xxUsbMlmeRadioOFF(pAd);
627
628 #endif //__RT2870_H__