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