]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/rt2860/chip/mac_usb.h
Staging: rt28x0: run *.h files through Lindent
[net-next-2.6.git] / drivers / staging / rt2860 / chip / mac_usb.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     Module Name:
28         mac_usb.h
29
30     Abstract:
31
32     Revision History:
33     Who          When          What
34     ---------    ----------    ----------------------------------------------
35  */
36
37 #ifndef __MAC_USB_H__
38 #define __MAC_USB_H__
39
40 #include "../rtmp_type.h"
41 #include "rtmp_mac.h"
42 #include "rtmp_phy.h"
43 #include "../rtmp_iface.h"
44 #include "../rtmp_dot11.h"
45
46 #define USB_CYC_CFG                             0x02a4
47
48 #define BEACON_RING_SIZE                2
49 #define MGMTPIPEIDX                             0       // EP6 is highest priority
50
51 #define RTMP_PKT_TAIL_PADDING   11      // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
52
53 #define fRTMP_ADAPTER_NEED_STOP_TX              \
54                 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
55                  fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
56                  fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
57
58 //
59 // RXINFO appends at the end of each rx packet.
60 //
61 #define RXINFO_SIZE                             4
62 #define RT2870_RXDMALEN_FIELD_SIZE      4
63
64 typedef struct PACKED _RXINFO_STRUC {
65         UINT32 BA:1;
66         UINT32 DATA:1;
67         UINT32 NULLDATA:1;
68         UINT32 FRAG:1;
69         UINT32 U2M:1;           // 1: this RX frame is unicast to me
70         UINT32 Mcast:1;         // 1: this is a multicast frame
71         UINT32 Bcast:1;         // 1: this is a broadcast frame
72         UINT32 MyBss:1;         // 1: this frame belongs to the same BSSID
73         UINT32 Crc:1;           // 1: CRC error
74         UINT32 CipherErr:2;     // 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid
75         UINT32 AMSDU:1;         // rx with 802.3 header, not 802.11 header.
76         UINT32 HTC:1;
77         UINT32 RSSI:1;
78         UINT32 L2PAD:1;
79         UINT32 AMPDU:1;         // To be moved
80         UINT32 Decrypted:1;
81         UINT32 PlcpRssil:1;
82         UINT32 CipherAlg:1;
83         UINT32 LastAMSDU:1;
84         UINT32 PlcpSignal:12;
85 } RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
86
87 //
88 // TXINFO
89 //
90 #define TXINFO_SIZE                             4
91
92 typedef struct _TXINFO_STRUC {
93         // Word 0
94         UINT32 USBDMATxPktLen:16;       //used ONLY in USB bulk Aggregation,  Total byte counts of all sub-frame.
95         UINT32 rsv:8;
96         UINT32 WIV:1;           // Wireless Info Valid. 1 if Driver already fill WI,  o if DMA needs to copy WI to correctposition
97         UINT32 QSEL:2;          // select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA
98         UINT32 SwUseLastRound:1;        // Software use.
99         UINT32 rsv2:2;          // Software use.
100         UINT32 USBDMANextVLD:1; //used ONLY in USB bulk Aggregation, NextValid
101         UINT32 USBDMATxburst:1; //used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint
102 } TXINFO_STRUC, *PTXINFO_STRUC;
103
104 //
105 // Management ring buffer format
106 //
107 typedef struct _MGMT_STRUC {
108         BOOLEAN Valid;
109         PUCHAR pBuffer;
110         ULONG Length;
111 } MGMT_STRUC, *PMGMT_STRUC;
112
113 ////////////////////////////////////////////////////////////////////////////
114 // The TX_BUFFER structure forms the transmitted USB packet to the device
115 ////////////////////////////////////////////////////////////////////////////
116 typedef struct __TX_BUFFER {
117         union {
118                 UCHAR WirelessPacket[TX_BUFFER_NORMSIZE];
119                 HEADER_802_11 NullFrame;
120                 PSPOLL_FRAME PsPollPacket;
121                 RTS_FRAME RTSFrame;
122         } field;
123         UCHAR Aggregation[4];   //Buffer for save Aggregation size.
124 } TX_BUFFER, *PTX_BUFFER;
125
126 typedef struct __HTTX_BUFFER {
127         union {
128                 UCHAR WirelessPacket[MAX_TXBULK_SIZE];
129                 HEADER_802_11 NullFrame;
130                 PSPOLL_FRAME PsPollPacket;
131                 RTS_FRAME RTSFrame;
132         } field;
133         UCHAR Aggregation[4];   //Buffer for save Aggregation size.
134 } HTTX_BUFFER, *PHTTX_BUFFER;
135
136 // used to track driver-generated write irps
137 typedef struct _TX_CONTEXT {
138         PVOID pAd;              //Initialized in MiniportInitialize
139         PURB pUrb;              //Initialized in MiniportInitialize
140         PIRP pIrp;              //used to cancel pending bulk out.
141         //Initialized in MiniportInitialize
142         PTX_BUFFER TransferBuffer;      //Initialized in MiniportInitialize
143         ULONG BulkOutSize;
144         UCHAR BulkOutPipeId;
145         UCHAR SelfIdx;
146         BOOLEAN InUse;
147         BOOLEAN bWaitingBulkOut;        // at least one packet is in this TxContext, ready for making IRP anytime.
148         BOOLEAN bFullForBulkOut;        // all tx buffer are full , so waiting for tx bulkout.
149         BOOLEAN IRPPending;
150         BOOLEAN LastOne;
151         BOOLEAN bAggregatible;
152         UCHAR Header_802_3[LENGTH_802_3];
153         UCHAR Rsv[2];
154         ULONG DataOffset;
155         UINT TxRate;
156         dma_addr_t data_dma;    // urb dma on linux
157
158 } TX_CONTEXT, *PTX_CONTEXT, **PPTX_CONTEXT;
159
160 // used to track driver-generated write irps
161 typedef struct _HT_TX_CONTEXT {
162         PVOID pAd;              //Initialized in MiniportInitialize
163         PURB pUrb;              //Initialized in MiniportInitialize
164         PIRP pIrp;              //used to cancel pending bulk out.
165         //Initialized in MiniportInitialize
166         PHTTX_BUFFER TransferBuffer;    //Initialized in MiniportInitialize
167         ULONG BulkOutSize;      // Indicate the total bulk-out size in bytes in one bulk-transmission
168         UCHAR BulkOutPipeId;
169         BOOLEAN IRPPending;
170         BOOLEAN LastOne;
171         BOOLEAN bCurWriting;
172         BOOLEAN bRingEmpty;
173         BOOLEAN bCopySavePad;
174         UCHAR SavedPad[8];
175         UCHAR Header_802_3[LENGTH_802_3];
176         ULONG CurWritePosition; // Indicate the buffer offset which packet will be inserted start from.
177         ULONG CurWriteRealPos;  // Indicate the buffer offset which packet now are writing to.
178         ULONG NextBulkOutPosition;      // Indicate the buffer start offset of a bulk-transmission
179         ULONG ENextBulkOutPosition;     // Indicate the buffer end offset of a bulk-transmission
180         UINT TxRate;
181         dma_addr_t data_dma;    // urb dma on linux
182 } HT_TX_CONTEXT, *PHT_TX_CONTEXT, **PPHT_TX_CONTEXT;
183
184 //
185 // Structure to keep track of receive packets and buffers to indicate
186 // receive data to the protocol.
187 //
188 typedef struct _RX_CONTEXT {
189         PUCHAR TransferBuffer;
190         PVOID pAd;
191         PIRP pIrp;              //used to cancel pending bulk in.
192         PURB pUrb;
193         //These 2 Boolean shouldn't both be 1 at the same time.
194         ULONG BulkInOffset;     // number of packets waiting for reordering .
195 //      BOOLEAN                         ReorderInUse;   // At least one packet in this buffer are in reordering buffer and wait for receive indication
196         BOOLEAN bRxHandling;    // Notify this packet is being process now.
197         BOOLEAN InUse;          // USB Hardware Occupied. Wait for USB HW to put packet.
198         BOOLEAN Readable;       // Receive Complete back. OK for driver to indicate receiving packet.
199         BOOLEAN IRPPending;     // TODO: To be removed
200         atomic_t IrpLock;
201         NDIS_SPIN_LOCK RxContextLock;
202         dma_addr_t data_dma;    // urb dma on linux
203 } RX_CONTEXT, *PRX_CONTEXT;
204
205 /******************************************************************************
206
207         USB Frimware Related MACRO
208
209 ******************************************************************************/
210 // 8051 firmware image for usb - use last-half base address = 0x3000
211 #define FIRMWARE_IMAGE_BASE                     0x3000
212 #define MAX_FIRMWARE_IMAGE_SIZE         0x1000  // 4kbyte
213
214 #define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen)            \
215         RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
216
217 /******************************************************************************
218
219         USB TX Related MACRO
220
221 ******************************************************************************/
222 #define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags)                               \
223                         do{                                                                                                     \
224                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
225                                 if (pAd->DeQueueRunning[QueIdx])                                                \
226                                 {                                                                                                               \
227                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
228                                         DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx));                \
229                                         continue;                                                                                       \
230                                 }                                                                                                               \
231                                 else                                                                                                    \
232                                 {                                                                                                               \
233                                         pAd->DeQueueRunning[QueIdx] = TRUE;                                     \
234                                         RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
235                                 }                                                                                                               \
236                         }while(0)
237
238 #define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags)                                                \
239                         do{                                                                                                                     \
240                                 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags);             \
241                                 pAd->DeQueueRunning[QueIdx] = FALSE;                                    \
242                                 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);   \
243                         }while(0)
244
245 #define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
246                 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
247
248 #define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx)                 \
249                 do{}while(0)
250
251 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType)          \
252                 ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
253
254 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)       \
255                         RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
256
257 #define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)   \
258                         RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
259
260 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
261                         RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
262
263 #define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)     \
264                         RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
265
266 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)     \
267                         RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
268
269 #define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
270                                 /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
271
272 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx)      \
273                         RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
274
275 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)   \
276                         RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
277
278 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen)   \
279                         RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
280
281 #define GET_TXRING_FREENO(_pAd, _QueIdx)        (_QueIdx)       //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
282 #define GET_MGMTRING_FREENO(_pAd)                       (_pAd->MgmtRing.TxSwFreeIdx)
283
284 /* ----------------- RX Related MACRO ----------------- */
285
286 /*
287   *     Device Hardware Interface Related MACRO
288   */
289 #define RTMP_IRQ_INIT(pAd)                              do{}while(0)
290 #define RTMP_IRQ_ENABLE(pAd)                    do{}while(0)
291
292 /*
293   *     MLME Related MACRO
294   */
295 #define RTMP_MLME_HANDLER(pAd)                  RTUSBMlmeUp(pAd)
296
297 #define RTMP_MLME_PRE_SANITY_CHECK(pAd)                                                         \
298         {       if ((pAd->CommonCfg.bHardwareRadio == TRUE) &&                                  \
299                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) &&          \
300                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) {       \
301                         RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
302
303 #define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd)    \
304         {       RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0);      \
305                 RTUSBMlmeUp(pAd); }
306
307 #define RTMP_MLME_RESET_STATE_MACHINE(pAd)      \
308                         MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL);     \
309                         RTUSBMlmeUp(pAd);
310
311 #define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)              \
312         {       RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY));      \
313                 RTUSBMlmeUp(_pAd);                                                                      \
314         }
315
316 /*
317   *     Power Save Related MACRO
318   */
319 #define RTMP_PS_POLL_ENQUEUE(pAd)                                               \
320         {       RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL);       \
321                 RTUSBKickBulkOut(pAd); }
322
323 #define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
324         RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
325
326 #define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
327     RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
328
329 #define RTMP_SET_PSM_BIT(_pAd, _val) \
330         {\
331                 if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
332                         MlmeSetPsmBit(_pAd, _val);\
333                 else \
334                 { \
335                         USHORT _psm_val; \
336                         _psm_val = _val; \
337                         RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(USHORT)); \
338                 }\
339         }
340
341 #define RTMP_MLME_RADIO_ON(pAd) \
342     RT28xxUsbMlmeRadioOn(pAd);
343
344 #define RTMP_MLME_RADIO_OFF(pAd) \
345     RT28xxUsbMlmeRadioOFF(pAd);
346
347 #endif //__MAC_USB_H__ //