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 Justin P. Mattock 11/07/2010 Fix a typo
35 --------- ---------- ----------------------------------------------
41 #include "../rtmp_type.h"
44 #include "../rtmp_iface.h"
45 #include "../rtmp_dot11.h"
47 #define USB_CYC_CFG 0x02a4
49 #define BEACON_RING_SIZE 2
50 #define MGMTPIPEIDX 0 /* EP6 is highest priority */
52 #define RTMP_PKT_TAIL_PADDING 11 /* 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding) */
54 #define fRTMP_ADAPTER_NEED_STOP_TX \
55 (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \
56 fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \
57 fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS)
60 /* RXINFO appends at the end of each rx packet. */
63 #define RT2870_RXDMALEN_FIELD_SIZE 4
65 typedef struct PACKED rt_rxinfo {
70 u32 U2M:1; /* 1: this RX frame is unicast to me */
71 u32 Mcast:1; /* 1: this is a multicast frame */
72 u32 Bcast:1; /* 1: this is a broadcast frame */
73 u32 MyBss:1; /* 1: this frame belongs to the same BSSID */
74 u32 Crc:1; /* 1: CRC error */
75 u32 CipherErr:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */
76 u32 AMSDU:1; /* rx with 802.3 header, not 802.11 header. */
80 u32 AMPDU:1; /* To be moved */
86 } RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC;
95 u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */
97 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */
98 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
99 u32 SwUseLastRound:1; /* Software use. */
100 u32 rsv2:2; /* Software use. */
101 u32 USBDMANextVLD:1; /*used ONLY in USB bulk Aggregation, NextValid */
102 u32 USBDMATxburst:1; /*used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint */
106 /* Management ring buffer format */
111 unsigned long Length;
114 /*////////////////////////////////////////////////////////////////////////// */
115 /* The struct rt_tx_buffer structure forms the transmitted USB packet to the device */
116 /*////////////////////////////////////////////////////////////////////////// */
117 struct rt_tx_buffer {
119 u8 WirelessPacket[TX_BUFFER_NORMSIZE];
120 struct rt_header_802_11 NullFrame;
121 struct rt_pspoll_frame PsPollPacket;
122 struct rt_rts_frame RTSFrame;
124 u8 Aggregation[4]; /*Buffer for save Aggregation size. */
127 struct rt_httx_buffer {
129 u8 WirelessPacket[MAX_TXBULK_SIZE];
130 struct rt_header_802_11 NullFrame;
131 struct rt_pspoll_frame PsPollPacket;
132 struct rt_rts_frame RTSFrame;
134 u8 Aggregation[4]; /*Buffer for save Aggregation size. */
137 /* used to track driver-generated write irps */
138 struct rt_tx_context {
139 void *pAd; /*Initialized in MiniportInitialize */
140 PURB pUrb; /*Initialized in MiniportInitialize */
141 PIRP pIrp; /*used to cancel pending bulk out. */
142 /*Initialized in MiniportInitialize */
143 struct rt_tx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */
144 unsigned long BulkOutSize;
148 BOOLEAN bWaitingBulkOut; /* at least one packet is in this TxContext, ready for making IRP anytime. */
149 BOOLEAN bFullForBulkOut; /* all tx buffer are full , so waiting for tx bulkout. */
152 BOOLEAN bAggregatible;
153 u8 Header_802_3[LENGTH_802_3];
155 unsigned long DataOffset;
157 dma_addr_t data_dma; /* urb dma on linux */
161 /* used to track driver-generated write irps */
162 struct rt_ht_tx_context {
163 void *pAd; /*Initialized in MiniportInitialize */
164 PURB pUrb; /*Initialized in MiniportInitialize */
165 PIRP pIrp; /*used to cancel pending bulk out. */
166 /*Initialized in MiniportInitialize */
167 struct rt_httx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */
168 unsigned long BulkOutSize; /* Indicate the total bulk-out size in bytes in one bulk-transmission */
174 BOOLEAN bCopySavePad;
176 u8 Header_802_3[LENGTH_802_3];
177 unsigned long CurWritePosition; /* Indicate the buffer offset which packet will be inserted start from. */
178 unsigned long CurWriteRealPos; /* Indicate the buffer offset which packet now are writing to. */
179 unsigned long NextBulkOutPosition; /* Indicate the buffer start offset of a bulk-transmission */
180 unsigned long ENextBulkOutPosition; /* Indicate the buffer end offset of a bulk-transmission */
182 dma_addr_t data_dma; /* urb dma on linux */
186 /* Structure to keep track of receive packets and buffers to indicate */
187 /* receive data to the protocol. */
189 struct rt_rx_context {
192 PIRP pIrp; /*used to cancel pending bulk in. */
194 /*These 2 Boolean shouldn't both be 1 at the same time. */
195 unsigned long BulkInOffset; /* number of packets waiting for reordering . */
196 /* BOOLEAN ReorderInUse; // At least one packet in this buffer are in reordering buffer and wait for receive indication */
197 BOOLEAN bRxHandling; /* Notify this packet is being process now. */
198 BOOLEAN InUse; /* USB Hardware Occupied. Wait for USB HW to put packet. */
199 BOOLEAN Readable; /* Receive Complete back. OK for driver to indicate receiving packet. */
200 BOOLEAN IRPPending; /* TODO: To be removed */
202 spinlock_t RxContextLock;
203 dma_addr_t data_dma; /* urb dma on linux */
206 /******************************************************************************
208 USB Frimware Related MACRO
210 ******************************************************************************/
211 /* 8051 firmware image for usb - use last-half base address = 0x3000 */
212 #define FIRMWARE_IMAGE_BASE 0x3000
213 #define MAX_FIRMWARE_IMAGE_SIZE 0x1000 /* 4kbyte */
215 #define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \
216 RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen)
218 /******************************************************************************
222 ******************************************************************************/
223 #define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) \
225 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
226 if (pAd->DeQueueRunning[QueIdx]) { \
227 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
228 DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx)); \
231 pAd->DeQueueRunning[QueIdx] = TRUE; \
232 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
236 #define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
238 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
239 pAd->DeQueueRunning[QueIdx] = FALSE; \
240 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
243 #define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
244 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
246 #define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
249 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
250 ((_TxFrameType == TX_RALINK_FRAME) && \
251 (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
253 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
254 RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
256 #define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
257 RtmpUSB_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
259 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
260 RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
262 #define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \
263 RtmpUSB_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)
265 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
266 RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
268 #define HAL_LastTxIdx(pAd, QueIdx, TxIdx) \
269 /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
271 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
272 RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
274 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
275 RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
277 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
278 RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
280 #define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) /*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */
281 #define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
283 /* ----------------- RX Related MACRO ----------------- */
286 * Device Hardware Interface Related MACRO
288 #define RTMP_IRQ_INIT(pAd) do {} while (0)
289 #define RTMP_IRQ_ENABLE(pAd) do {} while (0)
294 #define RTMP_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
296 #define RTMP_MLME_PRE_SANITY_CHECK(pAd) \
297 { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \
298 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \
299 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \
300 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
302 #define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
303 { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
306 #define RTMP_MLME_RESET_STATE_MACHINE(pAd) \
307 { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
310 #define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
311 { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(struct rt_mac_table_entry)); \
316 * Power Save Related MACRO
318 #define RTMP_PS_POLL_ENQUEUE(pAd) \
319 { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
320 RTUSBKickBulkOut(pAd); }
322 #define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
323 RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
325 #define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
326 RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
328 #define RTMP_SET_PSM_BIT(_pAd, _val) \
330 if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
331 MlmeSetPsmBit(_pAd, _val);\
335 RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \
339 #define RTMP_MLME_RADIO_ON(pAd) \
340 RT28xxUsbMlmeRadioOn(pAd);
342 #define RTMP_MLME_RADIO_OFF(pAd) \
343 RT28xxUsbMlmeRadioOFF(pAd);
345 #endif /*__MAC_USB_H__ // */