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 rt_rxinfo
{
69 u32 U2M
:1; /* 1: this RX frame is unicast to me */
70 u32 Mcast
:1; /* 1: this is a multicast frame */
71 u32 Bcast
:1; /* 1: this is a broadcast frame */
72 u32 MyBss
:1; /* 1: this frame belongs to the same BSSID */
73 u32 Crc
:1; /* 1: CRC error */
74 u32 CipherErr
:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */
75 u32 AMSDU
:1; /* rx with 802.3 header, not 802.11 header. */
79 u32 AMPDU
:1; /* To be moved */
85 } RT28XX_RXD_STRUC
, *PRT28XX_RXD_STRUC
;
94 u32 USBDMATxPktLen
:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */
96 u32 WIV
:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition */
97 u32 QSEL
:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
98 u32 SwUseLastRound
:1; /* Software use. */
99 u32 rsv2
:2; /* Software use. */
100 u32 USBDMANextVLD
:1; /*used ONLY in USB bulk Aggregation, NextValid */
101 u32 USBDMATxburst
:1; /*used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint */
105 /* Management ring buffer format */
110 unsigned long Length
;
113 /*////////////////////////////////////////////////////////////////////////// */
114 /* The struct rt_tx_buffer structure forms the transmitted USB packet to the device */
115 /*////////////////////////////////////////////////////////////////////////// */
116 struct rt_tx_buffer
{
118 u8 WirelessPacket
[TX_BUFFER_NORMSIZE
];
119 struct rt_header_802_11 NullFrame
;
120 struct rt_pspoll_frame PsPollPacket
;
121 struct rt_rts_frame RTSFrame
;
123 u8 Aggregation
[4]; /*Buffer for save Aggregation size. */
126 struct rt_httx_buffer
{
128 u8 WirelessPacket
[MAX_TXBULK_SIZE
];
129 struct rt_header_802_11 NullFrame
;
130 struct rt_pspoll_frame PsPollPacket
;
131 struct rt_rts_frame RTSFrame
;
133 u8 Aggregation
[4]; /*Buffer for save Aggregation size. */
136 /* used to track driver-generated write irps */
137 struct rt_tx_context
{
138 void *pAd
; /*Initialized in MiniportInitialize */
139 PURB pUrb
; /*Initialized in MiniportInitialize */
140 PIRP pIrp
; /*used to cancel pending bulk out. */
141 /*Initialized in MiniportInitialize */
142 struct rt_tx_buffer
*TransferBuffer
; /*Initialized in MiniportInitialize */
143 unsigned long BulkOutSize
;
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 u8 Header_802_3
[LENGTH_802_3
];
154 unsigned long DataOffset
;
156 dma_addr_t data_dma
; /* urb dma on linux */
160 /* used to track driver-generated write irps */
161 struct rt_ht_tx_context
{
162 void *pAd
; /*Initialized in MiniportInitialize */
163 PURB pUrb
; /*Initialized in MiniportInitialize */
164 PIRP pIrp
; /*used to cancel pending bulk out. */
165 /*Initialized in MiniportInitialize */
166 struct rt_httx_buffer
*TransferBuffer
; /*Initialized in MiniportInitialize */
167 unsigned long BulkOutSize
; /* Indicate the total bulk-out size in bytes in one bulk-transmission */
173 BOOLEAN bCopySavePad
;
175 u8 Header_802_3
[LENGTH_802_3
];
176 unsigned long CurWritePosition
; /* Indicate the buffer offset which packet will be inserted start from. */
177 unsigned long CurWriteRealPos
; /* Indicate the buffer offset which packet now are writing to. */
178 unsigned long NextBulkOutPosition
; /* Indicate the buffer start offset of a bulk-transmission */
179 unsigned long ENextBulkOutPosition
; /* Indicate the buffer end offset of a bulk-transmission */
181 dma_addr_t data_dma
; /* urb dma on linux */
185 /* Structure to keep track of receive packets and buffers to indicate */
186 /* receive data to the protocol. */
188 struct rt_rx_context
{
191 PIRP pIrp
; /*used to cancel pending bulk in. */
193 /*These 2 Boolean shouldn't both be 1 at the same time. */
194 unsigned long 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 spinlock_t RxContextLock
;
202 dma_addr_t data_dma
; /* urb dma on linux */
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]) { \
226 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
227 DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx)); \
230 pAd->DeQueueRunning[QueIdx] = TRUE; \
231 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\
235 #define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \
237 RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
238 pAd->DeQueueRunning[QueIdx] = FALSE; \
239 RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \
242 #define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \
243 (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS)
245 #define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) \
248 #define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \
249 ((_TxFrameType == TX_RALINK_FRAME) && \
250 (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx)))
252 #define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
253 RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
255 #define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \
256 RtmpUSB_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber)
258 #define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \
259 RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber)
261 #define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \
262 RtmpUSB_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber)
264 #define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \
265 RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx)
267 #define HAL_LastTxIdx(pAd, QueIdx, TxIdx) \
268 /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */
270 #define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \
271 RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx)
273 #define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \
274 RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen)
276 #define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \
277 RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen)
279 #define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) /*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */
280 #define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx)
282 /* ----------------- RX Related MACRO ----------------- */
285 * Device Hardware Interface Related MACRO
287 #define RTMP_IRQ_INIT(pAd) do {} while (0)
288 #define RTMP_IRQ_ENABLE(pAd) do {} while (0)
293 #define RTMP_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd)
295 #define RTMP_MLME_PRE_SANITY_CHECK(pAd) \
296 { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \
297 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \
298 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \
299 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } }
301 #define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \
302 { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \
305 #define RTMP_MLME_RESET_STATE_MACHINE(pAd) \
306 { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \
309 #define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \
310 { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(struct rt_mac_table_entry)); \
315 * Power Save Related MACRO
317 #define RTMP_PS_POLL_ENQUEUE(pAd) \
318 { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \
319 RTUSBKickBulkOut(pAd); }
321 #define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \
322 RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx);
324 #define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \
325 RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
327 #define RTMP_SET_PSM_BIT(_pAd, _val) \
329 if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \
330 MlmeSetPsmBit(_pAd, _val);\
334 RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \
338 #define RTMP_MLME_RADIO_ON(pAd) \
339 RT28xxUsbMlmeRadioOn(pAd);
341 #define RTMP_MLME_RADIO_OFF(pAd) \
342 RT28xxUsbMlmeRadioOFF(pAd);
344 #endif /*__MAC_USB_H__ // */