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 *************************************************************************
31 Ralink USB driver Tx/Rx functions.
35 -------- ---------- ----------------------------------------------
36 Jan 03-25-2006 created
42 #include "../rt_config.h"
44 extern u8 Phy11BGNextRateUpward[]; /* defined in mlme.c */
45 extern u8 EpToQueue[];
47 void REPORT_AMSDU_FRAMES_TO_LLC(struct rt_rtmp_adapter *pAd,
48 u8 *pData, unsigned long DataSize)
55 /* allocate a rx packet */
56 pSkb = dev_alloc_skb(RX_BUFFER_AGGRESIZE);
57 pPacket = (void *)OSPKT_TO_RTPKT(pSkb);
60 /* convert 802.11 to 802.3 packet */
61 pSkb->dev = get_netdev_from_bssid(pAd, BSS0);
62 RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS);
63 deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize);
65 DBGPRINT(RT_DEBUG_ERROR, ("Can't allocate skb\n"));
70 ========================================================================
73 This subroutine will scan through releative ring descriptor to find
74 out available free ring descriptor and compare with request size.
77 pAd Pointer to our adapter
78 RingType Selected Ring
81 NDIS_STATUS_FAILURE Not enough free descriptor
82 NDIS_STATUS_SUCCESS Enough free descriptor
86 ========================================================================
88 int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd,
92 /* u8 FreeNumber = 0; */
94 int Status = NDIS_STATUS_FAILURE;
95 unsigned long IrqFlags;
96 struct rt_ht_tx_context *pHTTXContext;
98 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
99 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
100 if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition)
102 ((pHTTXContext->CurWritePosition + NumberRequired +
103 LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition)) {
105 RTUSB_SET_BULK_FLAG(pAd,
106 (fRTUSB_BULK_OUT_DATA_NORMAL <<
108 } else if ((pHTTXContext->CurWritePosition == 8)
109 && (pHTTXContext->NextBulkOutPosition <
110 (NumberRequired + LOCAL_TXBUF_SIZE))) {
111 RTUSB_SET_BULK_FLAG(pAd,
112 (fRTUSB_BULK_OUT_DATA_NORMAL <<
114 } else if (pHTTXContext->bCurWriting == TRUE) {
115 DBGPRINT(RT_DEBUG_TRACE,
116 ("RTUSBFreeD c3 --> QueIdx=%d, CWPos=%ld, NBOutPos=%ld!\n",
117 BulkOutPipeId, pHTTXContext->CurWritePosition,
118 pHTTXContext->NextBulkOutPosition));
119 RTUSB_SET_BULK_FLAG(pAd,
120 (fRTUSB_BULK_OUT_DATA_NORMAL <<
123 Status = NDIS_STATUS_SUCCESS;
125 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
130 int RTUSBFreeDescriptorRelease(struct rt_rtmp_adapter *pAd,
133 unsigned long IrqFlags;
134 struct rt_ht_tx_context *pHTTXContext;
136 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
137 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
138 pHTTXContext->bCurWriting = FALSE;
139 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
141 return NDIS_STATUS_SUCCESS;
144 BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId)
146 unsigned long IrqFlags;
147 struct rt_ht_tx_context *pHTTXContext;
148 BOOLEAN needQueBack = FALSE;
150 pHTTXContext = &pAd->TxContext[BulkOutPipeId];
152 RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
153 if ((pHTTXContext->IRPPending ==
154 TRUE) /*&& (pAd->TxSwQueue[BulkOutPipeId].Number == 0) */) {
155 if ((pHTTXContext->CurWritePosition <
156 pHTTXContext->ENextBulkOutPosition)
158 (((pHTTXContext->ENextBulkOutPosition +
159 MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT)
160 || (pHTTXContext->CurWritePosition >
161 MAX_AGGREGATION_SIZE))) {
164 if ((pHTTXContext->CurWritePosition >
165 pHTTXContext->ENextBulkOutPosition)
167 ((pHTTXContext->ENextBulkOutPosition +
168 MAX_AGGREGATION_SIZE) <
169 pHTTXContext->CurWritePosition)) {
173 RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags);
180 ========================================================================
192 ========================================================================
194 void RTUSBRejectPendingPackets(struct rt_rtmp_adapter *pAd)
197 struct rt_queue_entry *pEntry;
199 struct rt_queue_header *pQueue;
201 for (Index = 0; Index < 4; Index++) {
202 NdisAcquireSpinLock(&pAd->TxSwQueueLock[Index]);
203 while (pAd->TxSwQueue[Index].Head != NULL) {
204 pQueue = (struct rt_queue_header *)&(pAd->TxSwQueue[Index]);
205 pEntry = RemoveHeadQueue(pQueue);
206 pPacket = QUEUE_ENTRY_TO_PACKET(pEntry);
207 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
209 NdisReleaseSpinLock(&pAd->TxSwQueueLock[Index]);
216 ========================================================================
219 Calculates the duration which is required to transmit out frames
220 with given size and specified rate.
223 pTxD Pointer to transmit descriptor
224 Ack Setting for Ack requirement bit
225 Fragment Setting for Fragment bit
226 RetryMode Setting for retry mode
227 Ifs Setting for IFS gap
228 Rate Setting for transmit rate
229 Service Setting for service
231 TxPreamble Short or Long preamble when using CCK rates
232 QueIdx - 0-3, according to 802.11e/d4.4 June/2003
238 IRQL = DISPATCH_LEVEL
240 ========================================================================
243 void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd,
244 struct rt_txinfo *pTxInfo,
247 u8 QueueSel, u8 NextValid, u8 TxBurst)
249 pTxInfo->USBDMATxPktLen = USBDMApktLen;
250 pTxInfo->QSEL = QueueSel;
251 if (QueueSel != FIFO_EDCA)
252 DBGPRINT(RT_DEBUG_TRACE,
253 ("====> QueueSel != FIFO_EDCA<============\n"));
254 pTxInfo->USBDMANextVLD = FALSE; /*NextValid; // Need to check with Jan about this. */
255 pTxInfo->USBDMATxburst = TxBurst;
257 pTxInfo->SwUseLastRound = 0;
262 #endif /* RTMP_MAC_USB // */