]>
Commit | Line | Data |
---|---|---|
ca97b838 BZ |
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 | ||
ca97b838 BZ |
46 | #define USB_CYC_CFG 0x02a4 |
47 | ||
48 | #define BEACON_RING_SIZE 2 | |
cc277069 | 49 | #define MGMTPIPEIDX 0 /* EP6 is highest priority */ |
ca97b838 | 50 | |
cc277069 | 51 | #define RTMP_PKT_TAIL_PADDING 11 /* 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding) */ |
ca97b838 BZ |
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 | ||
cc277069 BZ |
58 | /* */ |
59 | /* RXINFO appends at the end of each rx packet. */ | |
60 | /* */ | |
ca97b838 BZ |
61 | #define RXINFO_SIZE 4 |
62 | #define RT2870_RXDMALEN_FIELD_SIZE 4 | |
63 | ||
52b81c89 | 64 | typedef struct PACKED _RXINFO_STRUC { |
51126deb BZ |
65 | u32 BA:1; |
66 | u32 DATA:1; | |
67 | u32 NULLDATA:1; | |
68 | u32 FRAG:1; | |
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. */ | |
76 | u32 HTC:1; | |
77 | u32 RSSI:1; | |
78 | u32 L2PAD:1; | |
79 | u32 AMPDU:1; /* To be moved */ | |
80 | u32 Decrypted:1; | |
81 | u32 PlcpRssil:1; | |
82 | u32 CipherAlg:1; | |
83 | u32 LastAMSDU:1; | |
84 | u32 PlcpSignal:12; | |
52b81c89 | 85 | } RXINFO_STRUC, *PRXINFO_STRUC, RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC; |
ca97b838 | 86 | |
cc277069 BZ |
87 | /* */ |
88 | /* TXINFO */ | |
89 | /* */ | |
ca97b838 BZ |
90 | #define TXINFO_SIZE 4 |
91 | ||
52b81c89 | 92 | typedef struct _TXINFO_STRUC { |
cc277069 | 93 | /* Word 0 */ |
51126deb BZ |
94 | u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */ |
95 | u32 rsv:8; | |
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 */ | |
52b81c89 | 102 | } TXINFO_STRUC, *PTXINFO_STRUC; |
ca97b838 | 103 | |
cc277069 BZ |
104 | /* */ |
105 | /* Management ring buffer format */ | |
106 | /* */ | |
52b81c89 BZ |
107 | typedef struct _MGMT_STRUC { |
108 | BOOLEAN Valid; | |
51126deb BZ |
109 | u8 *pBuffer; |
110 | unsigned long Length; | |
52b81c89 | 111 | } MGMT_STRUC, *PMGMT_STRUC; |
ca97b838 | 112 | |
cc277069 BZ |
113 | /*////////////////////////////////////////////////////////////////////////// */ |
114 | /* The TX_BUFFER structure forms the transmitted USB packet to the device */ | |
115 | /*////////////////////////////////////////////////////////////////////////// */ | |
52b81c89 BZ |
116 | typedef struct __TX_BUFFER { |
117 | union { | |
51126deb | 118 | u8 WirelessPacket[TX_BUFFER_NORMSIZE]; |
52b81c89 BZ |
119 | HEADER_802_11 NullFrame; |
120 | PSPOLL_FRAME PsPollPacket; | |
121 | RTS_FRAME RTSFrame; | |
122 | } field; | |
51126deb | 123 | u8 Aggregation[4]; /*Buffer for save Aggregation size. */ |
ca97b838 BZ |
124 | } TX_BUFFER, *PTX_BUFFER; |
125 | ||
52b81c89 BZ |
126 | typedef struct __HTTX_BUFFER { |
127 | union { | |
51126deb | 128 | u8 WirelessPacket[MAX_TXBULK_SIZE]; |
52b81c89 BZ |
129 | HEADER_802_11 NullFrame; |
130 | PSPOLL_FRAME PsPollPacket; | |
131 | RTS_FRAME RTSFrame; | |
132 | } field; | |
51126deb | 133 | u8 Aggregation[4]; /*Buffer for save Aggregation size. */ |
ca97b838 BZ |
134 | } HTTX_BUFFER, *PHTTX_BUFFER; |
135 | ||
cc277069 | 136 | /* used to track driver-generated write irps */ |
52b81c89 | 137 | typedef struct _TX_CONTEXT { |
51126deb | 138 | void *pAd; /*Initialized in MiniportInitialize */ |
cc277069 BZ |
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 */ | |
51126deb BZ |
143 | unsigned long BulkOutSize; |
144 | u8 BulkOutPipeId; | |
145 | u8 SelfIdx; | |
52b81c89 | 146 | BOOLEAN InUse; |
cc277069 BZ |
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. */ | |
52b81c89 BZ |
149 | BOOLEAN IRPPending; |
150 | BOOLEAN LastOne; | |
151 | BOOLEAN bAggregatible; | |
51126deb BZ |
152 | u8 Header_802_3[LENGTH_802_3]; |
153 | u8 Rsv[2]; | |
154 | unsigned long DataOffset; | |
155 | u32 TxRate; | |
cc277069 | 156 | dma_addr_t data_dma; /* urb dma on linux */ |
52b81c89 BZ |
157 | |
158 | } TX_CONTEXT, *PTX_CONTEXT, **PPTX_CONTEXT; | |
ca97b838 | 159 | |
cc277069 | 160 | /* used to track driver-generated write irps */ |
52b81c89 | 161 | typedef struct _HT_TX_CONTEXT { |
51126deb | 162 | void *pAd; /*Initialized in MiniportInitialize */ |
cc277069 BZ |
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 */ | |
51126deb BZ |
167 | unsigned long BulkOutSize; /* Indicate the total bulk-out size in bytes in one bulk-transmission */ |
168 | u8 BulkOutPipeId; | |
52b81c89 BZ |
169 | BOOLEAN IRPPending; |
170 | BOOLEAN LastOne; | |
171 | BOOLEAN bCurWriting; | |
172 | BOOLEAN bRingEmpty; | |
173 | BOOLEAN bCopySavePad; | |
51126deb BZ |
174 | u8 SavedPad[8]; |
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 */ | |
180 | u32 TxRate; | |
cc277069 | 181 | dma_addr_t data_dma; /* urb dma on linux */ |
52b81c89 | 182 | } HT_TX_CONTEXT, *PHT_TX_CONTEXT, **PPHT_TX_CONTEXT; |
ca97b838 | 183 | |
cc277069 BZ |
184 | /* */ |
185 | /* Structure to keep track of receive packets and buffers to indicate */ | |
186 | /* receive data to the protocol. */ | |
187 | /* */ | |
52b81c89 | 188 | typedef struct _RX_CONTEXT { |
51126deb BZ |
189 | u8 *TransferBuffer; |
190 | void *pAd; | |
cc277069 | 191 | PIRP pIrp; /*used to cancel pending bulk in. */ |
52b81c89 | 192 | PURB pUrb; |
cc277069 | 193 | /*These 2 Boolean shouldn't both be 1 at the same time. */ |
51126deb | 194 | unsigned long BulkInOffset; /* number of packets waiting for reordering . */ |
cc277069 BZ |
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 */ | |
52b81c89 BZ |
200 | atomic_t IrpLock; |
201 | NDIS_SPIN_LOCK RxContextLock; | |
cc277069 | 202 | dma_addr_t data_dma; /* urb dma on linux */ |
52b81c89 | 203 | } RX_CONTEXT, *PRX_CONTEXT; |
ca97b838 BZ |
204 | |
205 | /****************************************************************************** | |
206 | ||
207 | USB Frimware Related MACRO | |
208 | ||
209 | ******************************************************************************/ | |
cc277069 | 210 | /* 8051 firmware image for usb - use last-half base address = 0x3000 */ |
ca97b838 | 211 | #define FIRMWARE_IMAGE_BASE 0x3000 |
cc277069 | 212 | #define MAX_FIRMWARE_IMAGE_SIZE 0x1000 /* 4kbyte */ |
ca97b838 BZ |
213 | |
214 | #define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \ | |
215 | RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen) | |
216 | ||
ca97b838 BZ |
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) \ | |
52b81c89 | 270 | /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */ |
ca97b838 BZ |
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 | ||
cc277069 | 281 | #define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) /*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */ |
ca97b838 BZ |
282 | #define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx) |
283 | ||
ca97b838 BZ |
284 | /* ----------------- RX Related MACRO ----------------- */ |
285 | ||
ca97b838 BZ |
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 | ||
ca97b838 BZ |
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 | ||
ca97b838 BZ |
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 | { \ | |
51126deb | 335 | u16 _psm_val; \ |
ca97b838 | 336 | _psm_val = _val; \ |
51126deb | 337 | RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \ |
ca97b838 BZ |
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 | ||
cc277069 | 347 | #endif /*__MAC_USB_H__ // */ |