2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
34 --------- ---------- ----------------------------------------------
40 #include "../rtmp_type.h"
43 #include "../rtmp_iface.h"
44 #include "../rtmp_dot11.h"
46 #define USB_CYC_CFG 0x02a4
48 #define BEACON_RING_SIZE 2
49 #define MGMTPIPEIDX 0 // EP6 is highest priority
51 #define RTMP_PKT_TAIL_PADDING 11 // 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding)
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)
59 // RXINFO appends at the end of each rx packet.
62 #define RT2870_RXDMALEN_FIELD_SIZE 4
64 typedef struct PACKED _RXINFO_STRUC {
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.
79 UINT32 AMPDU:1; // To be moved
85 } RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
92 typedef struct _TXINFO_STRUC {
94 UINT32 USBDMATxPktLen:16; //used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame.
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;
105 // Management ring buffer format
107 typedef struct _MGMT_STRUC {
111 } MGMT_STRUC, *PMGMT_STRUC;
113 ////////////////////////////////////////////////////////////////////////////
114 // The TX_BUFFER structure forms the transmitted USB packet to the device
115 ////////////////////////////////////////////////////////////////////////////
116 typedef struct __TX_BUFFER {
118 UCHAR WirelessPacket[TX_BUFFER_NORMSIZE];
119 HEADER_802_11 NullFrame;
120 PSPOLL_FRAME PsPollPacket;
123 UCHAR Aggregation[4]; //Buffer for save Aggregation size.
124 } TX_BUFFER, *PTX_BUFFER;
126 typedef struct __HTTX_BUFFER {
128 UCHAR WirelessPacket[MAX_TXBULK_SIZE];
129 HEADER_802_11 NullFrame;
130 PSPOLL_FRAME PsPollPacket;
133 UCHAR Aggregation[4]; //Buffer for save Aggregation size.
134 } HTTX_BUFFER, *PHTTX_BUFFER;
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
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.
151 BOOLEAN bAggregatible;
152 UCHAR Header_802_3[LENGTH_802_3];
156 dma_addr_t data_dma; // urb dma on linux
158 } TX_CONTEXT, *PTX_CONTEXT, **PPTX_CONTEXT;
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
173 BOOLEAN bCopySavePad;
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
181 dma_addr_t data_dma; // urb dma on linux
182 } HT_TX_CONTEXT, *PHT_TX_CONTEXT, **PPHT_TX_CONTEXT;
185 // Structure to keep track of receive packets and buffers to indicate
186 // receive data to the protocol.
188 typedef struct _RX_CONTEXT {
189 PUCHAR TransferBuffer;
191 PIRP pIrp; //used to cancel pending bulk in.
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
201 NDIS_SPIN_LOCK RxContextLock;
202 dma_addr_t data_dma; // urb dma on linux
203 } RX_CONTEXT, *PRX_CONTEXT;
205 /******************************************************************************
207 USB Frimware Related MACRO
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
214 #define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
215 RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
217 /******************************************************************************
221 ******************************************************************************/
222 #define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) \
224 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
225 if (pAd->DeQueueRunning[QueIdx]) \
227 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
228 DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx)); \
233 pAd->DeQueueRunning[QueIdx] = TRUE; \
234 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
238 #define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
240 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
241 pAd->DeQueueRunning[QueIdx] = FALSE; \
242 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
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)
248 #define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
251 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
252 ((_TxFrameType == TX_RALINK_FRAME) && (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
254 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
255 RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
257 #define HAL_WriteTxResource(pAd, pTxBlk,bIsLast, pFreeNumber) \
258 RtmpUSB_WriteSingleTxResource(pAd, pTxBlk,bIsLast, pFreeNumber)
260 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
261 RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
263 #define HAL_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber) \
264 RtmpUSB_WriteMultiTxResource(pAd, pTxBlk,frameNum, pFreeNumber)
266 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
267 RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
269 #define HAL_LastTxIdx(pAd, QueIdx,TxIdx) \
270 /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
272 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
273 RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
275 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
276 RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
278 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
279 RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
281 #define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) //(_pAd->TxRing[_QueIdx].TxSwFreeIdx)
282 #define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
284 /* ----------------- RX Related MACRO ----------------- */
287 * Device Hardware Interface Related MACRO
289 #define RTMP_IRQ_INIT(pAd) do{}while(0)
290 #define RTMP_IRQ_ENABLE(pAd) do{}while(0)
295 #define RTMP_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
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); } }
303 #define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
304 { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
307 #define RTMP_MLME_RESET_STATE_MACHINE(pAd) \
308 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
311 #define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
312 { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(MAC_TABLE_ENTRY)); \
317 * Power Save Related MACRO
319 #define RTMP_PS_POLL_ENQUEUE(pAd) \
320 { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
321 RTUSBKickBulkOut(pAd); }
323 #define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
324 RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
326 #define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
327 RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
329 #define RTMP_SET_PSM_BIT(_pAd, _val) \
331 if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
332 MlmeSetPsmBit(_pAd, _val);\
337 RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(USHORT)); \
341 #define RTMP_MLME_RADIO_ON(pAd) \
342 RT28xxUsbMlmeRadioOn(pAd);
344 #define RTMP_MLME_RADIO_OFF(pAd) \
345 RT28xxUsbMlmeRadioOFF(pAd);
347 #endif //__MAC_USB_H__ //