2 #include "mlmetxrx_f.h"
9 Mds_initial(struct wbsoft_priv *adapter)
11 struct wb35_mds *pMds = &adapter->Mds;
13 pMds->TxPause = false;
14 pMds->TxRTSThreshold = DEFAULT_RTSThreshold;
15 pMds->TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
17 return hal_get_tx_buffer( &adapter->sHwData, &pMds->pTxBuffer );
21 Mds_Destroy(struct wbsoft_priv *adapter)
25 static void Mds_DurationSet(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *buffer)
29 u16 Duration, NextBodyLen, OffsetSize;
31 unsigned char CTS_on = false, RTS_on = false;
32 PT00_DESCRIPTOR pNextT00;
34 unsigned char boGroupAddr = false;
36 OffsetSize = pDes->FragmentThreshold + 32 + 3;
38 Rate = pDes->TxRate >> 1;
42 pT00 = (PT00_DESCRIPTOR)buffer;
43 pT01 = (PT01_DESCRIPTOR)(buffer+4);
44 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
46 if( buffer[ DOT_11_DA_OFFSET+8 ] & 0x1 ) /* +8 for USB hdr */
49 /******************************************
50 * Set RTS/CTS mechanism
51 ******************************************/
54 /* NOTE : If the protection mode is enabled and the MSDU will be fragmented,
55 * the tx rates of MPDUs will all be DSSS rates. So it will not use
56 * CTS-to-self in this case. CTS-To-self will only be used when without
57 * fragmentation. -- 20050112 */
58 BodyLen = (u16)pT00->T00_frame_length; /* include 802.11 header */
59 BodyLen += 4; /* CRC */
61 if( BodyLen >= CURRENT_RTS_THRESHOLD )
62 RTS_on = true; /* Using RTS */
65 if( pT01->T01_modulation_type ) /* Is using OFDM */
67 if( CURRENT_PROTECT_MECHANISM ) /* Is using protect */
68 CTS_on = true; /* Using CTS */
73 if( RTS_on || CTS_on )
75 if( pT01->T01_modulation_type) /* Is using OFDM */
78 * 2 SIFS + DATA transmit time + 1 ACK
79 * ACK Rate : 24 Mega bps
80 * ACK frame length = 14 bytes */
81 Duration = 2*DEFAULT_SIFSTIME +
82 2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
83 ((BodyLen*8 + 22 + Rate*4 - 1)/(Rate*4))*Tsym +
84 ((112 + 22 + 95)/96)*Tsym;
89 * 2 SIFS + DATA transmit time + 1 ACK
91 * ACK frame length = 14 bytes */
92 if( pT01->T01_plcp_header_length ) /* long preamble */
93 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
95 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
97 Duration += ( ((BodyLen + 14)*8 + Rate-1) / Rate +
103 if( pT01->T01_modulation_type ) /* Is using OFDM */
105 /* CTS + 1 SIFS + CTS duration
106 * CTS Rate : 24 Mega bps
107 * CTS frame length = 14 bytes */
108 Duration += (DEFAULT_SIFSTIME +
109 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
110 ((112 + 22 + 95)/96)*Tsym);
114 /* CTS + 1 SIFS + CTS duration
115 * CTS Rate : ?? Mega bps
116 * CTS frame length = 14 bytes */
117 if( pT01->T01_plcp_header_length ) /* long preamble */
118 Duration += LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
120 Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
122 Duration += ( ((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME );
126 /* Set the value into USB descriptor */
127 pT01->T01_add_rts = RTS_on ? 1 : 0;
128 pT01->T01_add_cts = CTS_on ? 1 : 0;
129 pT01->T01_rts_cts_duration = Duration;
132 /******************************************
133 * Fill the more fragment descriptor
134 ******************************************/
139 for( i=pDes->FragmentCount-1; i>0; i-- )
141 NextBodyLen = (u16)pNextT00->T00_frame_length;
142 NextBodyLen += 4; /* CRC */
144 if( pT01->T01_modulation_type )
147 * data transmit time + 3 SIFS + 2 ACK
149 * ACK frame length = 14 bytes, tx rate = 24M */
150 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION * 3;
151 Duration += (((NextBodyLen*8 + 22 + Rate*4 - 1)/(Rate*4)) * Tsym +
152 (((2*14)*8 + 22 + 95)/96)*Tsym +
158 * data transmit time + 2 ACK + 3 SIFS
160 * ACK frame length = 14 bytes
162 if( pT01->T01_plcp_header_length ) /* long preamble */
163 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
165 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
167 Duration += ( ((NextBodyLen + (2*14))*8 + Rate-1) / Rate +
168 DEFAULT_SIFSTIME*3 );
171 ((u16 *)buffer)[5] = cpu_to_le16(Duration); /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
173 /* ----20061009 add by anson's endian */
174 pNextT00->value = cpu_to_le32(pNextT00->value);
175 pT01->value = cpu_to_le32( pT01->value );
176 /* ----end 20061009 add by anson's endian */
178 buffer += OffsetSize;
179 pT01 = (PT01_DESCRIPTOR)(buffer+4);
180 if (i != 1) /* The last fragment will not have the next fragment */
181 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
184 /*******************************************
185 * Fill the last fragment descriptor
186 *******************************************/
187 if( pT01->T01_modulation_type )
192 * ACK frame length = 14 bytes */
193 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION;
194 /* The Tx rate of ACK use 24M */
195 Duration += (((112 + 22 + 95)/96)*Tsym + DEFAULT_SIFSTIME );
202 * ACK frame length = 14 bytes(112 bits) */
203 if( pT01->T01_plcp_header_length ) /* long preamble */
204 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
206 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
208 Duration += ( (112 + Rate-1)/Rate + DEFAULT_SIFSTIME );
212 ((u16 *)buffer)[5] = cpu_to_le16(Duration); /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
213 pT00->value = cpu_to_le32(pT00->value);
214 pT01->value = cpu_to_le32(pT01->value);
215 /* --end 20061009 add */
219 /* The function return the 4n size of usb pk */
220 static u16 Mds_BodyCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *TargetBuffer)
222 PT00_DESCRIPTOR pT00;
223 struct wb35_mds *pMds = &adapter->Mds;
228 u16 SizeLeft, CopySize, CopyLeft, stmp;
229 u8 buf_index, FragmentCount = 0;
232 /* Copy fragment body */
233 buffer = TargetBuffer; /* shift 8B usb + 24B 802.11 */
234 SizeLeft = pDes->buffer_total_size;
235 buf_index = pDes->buffer_start_index;
237 pT00 = (PT00_DESCRIPTOR)buffer;
239 pT00 = (PT00_DESCRIPTOR)buffer;
241 if (SizeLeft > pDes->FragmentThreshold) {
242 CopySize = pDes->FragmentThreshold;
243 pT00->T00_frame_length = 24 + CopySize; /* Set USB length */
245 pT00->T00_frame_length = 24 + SizeLeft; /* Set USB length */
247 SizeLeft -= CopySize;
249 /* 1 Byte operation */
250 pctmp = (u8 *)( buffer + 8 + DOT_11_SEQUENCE_OFFSET );
252 *pctmp |= FragmentCount; /* 931130.5.m */
254 pT00->T00_first_mpdu = 1;
256 buffer += 32; /* 8B usb + 24B 802.11 header */
259 /* Copy into buffer */
261 stmp &= ~0x03; /* 4n Alignment */
262 Size += stmp; /* Current 4n offset of mpdu */
266 src_buffer = pDes->buffer_address[buf_index];
268 if (CopySize >= pDes->buffer_size[buf_index]) {
269 CopyLeft = pDes->buffer_size[buf_index];
271 /* Get the next buffer of descriptor */
273 buf_index %= MAX_DESCRIPTOR_BUFFER_INDEX;
275 u8 *pctmp = pDes->buffer_address[buf_index];
277 pDes->buffer_address[buf_index] = pctmp;
278 pDes->buffer_size[buf_index] -= CopySize;
281 memcpy(buffer, src_buffer, CopyLeft);
283 CopySize -= CopyLeft;
289 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - pMds->MicAdd;
290 pMds->MicWriteSize[ pMds->MicWriteIndex ] = pMds->MicAdd;
293 else if( SizeLeft < 8 ) /* 931130.5.p */
295 pMds->MicAdd = SizeLeft;
296 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - ( 8 - SizeLeft );
297 pMds->MicWriteSize[ pMds->MicWriteIndex ] = 8 - SizeLeft;
298 pMds->MicWriteIndex++;
302 /* Does it need to generate the new header for next mpdu? */
304 buffer = TargetBuffer + Size; /* Get the next 4n start address */
305 memcpy( buffer, TargetBuffer, 32 ); /* Copy 8B USB +24B 802.11 */
306 pT00 = (PT00_DESCRIPTOR)buffer;
307 pT00->T00_first_mpdu = 0;
313 pT00->T00_last_mpdu = 1;
314 pT00->T00_IsLastMpdu = 1;
315 buffer = (u8 *)pT00 + 8; /* +8 for USB hdr */
316 buffer[1] &= ~0x04; /* Clear more frag bit of 802.11 frame control */
317 pDes->FragmentCount = FragmentCount; /* Update the correct fragment number */
321 static void Mds_HeaderCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *TargetBuffer)
323 struct wb35_mds *pMds = &adapter->Mds;
324 u8 *src_buffer = pDes->buffer_address[0]; /* 931130.5.g */
325 PT00_DESCRIPTOR pT00;
326 PT01_DESCRIPTOR pT01;
328 u8 i, ctmp1, ctmp2, ctmpf;
329 u16 FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
332 stmp = pDes->buffer_total_size;
334 * Set USB header 8 byte
336 pT00 = (PT00_DESCRIPTOR)TargetBuffer;
338 pT01 = (PT01_DESCRIPTOR)TargetBuffer;
341 pT00->value = 0; /* Clear */
342 pT01->value = 0; /* Clear */
344 pT00->T00_tx_packet_id = pDes->Descriptor_ID; /* Set packet ID */
345 pT00->T00_header_length = 24; /* Set header length */
346 pT01->T01_retry_abort_ebable = 1; /* 921013 931130.5.h */
349 pT01->T01_wep_id = 0;
351 FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; /* Do not fragment */
352 /* Copy full data, the 1'st buffer contain all the data 931130.5.j */
353 memcpy( TargetBuffer, src_buffer, DOT_11_MAC_HEADER_SIZE ); /* Copy header */
354 pDes->buffer_address[0] = src_buffer + DOT_11_MAC_HEADER_SIZE;
355 pDes->buffer_total_size -= DOT_11_MAC_HEADER_SIZE;
356 pDes->buffer_size[0] = pDes->buffer_total_size;
358 /* Set fragment threshold */
359 FragmentThreshold -= (DOT_11_MAC_HEADER_SIZE + 4);
360 pDes->FragmentThreshold = FragmentThreshold;
362 /* Set more frag bit */
363 TargetBuffer[1] |= 0x04; /* Set more frag bit */
368 stmp = *(u16 *)(TargetBuffer+30); /* 2n alignment address */
371 ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG;
373 pDes->TxRate = ctmp1;
375 printk("Tx rate =%x\n", ctmp1);
378 pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1;
380 for( i=0; i<2; i++ ) {
384 pMds->TxRate[pDes->Descriptor_ID][i] = ctmp1; /* backup the ta rate and fall back rate */
386 if( ctmp1 == 108) ctmp2 = 7;
387 else if( ctmp1 == 96 ) ctmp2 = 6; /* Rate convert for USB */
388 else if( ctmp1 == 72 ) ctmp2 = 5;
389 else if( ctmp1 == 48 ) ctmp2 = 4;
390 else if( ctmp1 == 36 ) ctmp2 = 3;
391 else if( ctmp1 == 24 ) ctmp2 = 2;
392 else if( ctmp1 == 18 ) ctmp2 = 1;
393 else if( ctmp1 == 12 ) ctmp2 = 0;
394 else if( ctmp1 == 22 ) ctmp2 = 3;
395 else if( ctmp1 == 11 ) ctmp2 = 2;
396 else if( ctmp1 == 4 ) ctmp2 = 1;
397 else ctmp2 = 0; /* if( ctmp1 == 2 ) or default */
400 pT01->T01_transmit_rate = ctmp2;
402 pT01->T01_fall_back_rate = ctmp2;
408 if ((pT01->T01_modulation_type == 0) && (pT01->T01_transmit_rate == 0)) /* RATE_1M */
409 pDes->PreambleMode = WLAN_PREAMBLE_TYPE_LONG;
411 pDes->PreambleMode = CURRENT_PREAMBLE_MODE;
412 pT01->T01_plcp_header_length = pDes->PreambleMode; /* Set preamble */
417 Mds_Tx(struct wbsoft_priv *adapter)
419 struct hw_data *pHwData = &adapter->sHwData;
420 struct wb35_mds *pMds = &adapter->Mds;
421 struct wb35_descriptor TxDes;
422 struct wb35_descriptor *pTxDes = &TxDes;
424 u16 XmitBufSize, PacketSize, stmp, CurrentSize, FragmentThreshold;
425 u8 FillIndex, TxDesIndex, FragmentCount, FillCount;
426 unsigned char BufferFilled = false;
431 if (!hal_driver_init_OK(pHwData))
434 /* Only one thread can be run here */
435 if (atomic_inc_return(&pMds->TxThreadCount) != 1)
438 /* Start to fill the data */
440 FillIndex = pMds->TxFillIndex;
441 if (pMds->TxOwner[FillIndex]) { /* Is owned by software 0:Yes 1:No */
443 printk("[Mds_Tx] Tx Owner is H/W.\n");
448 XmitBufAddress = pMds->pTxBuffer + (MAX_USB_TX_BUFFER * FillIndex); /* Get buffer */
452 PacketSize = adapter->sMlmeFrame.len;
456 /* For Check the buffer resource */
457 FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
459 FragmentCount = PacketSize/FragmentThreshold + 1;
460 stmp = PacketSize + FragmentCount*32 + 8; /* 931130.5.c 8:MIC */
461 if ((XmitBufSize + stmp) >= MAX_USB_TX_BUFFER) {
462 printk("[Mds_Tx] Excess max tx buffer.\n");
463 break; /* buffer is not enough */
472 /* Leaves first u8 intact */
473 memset((u8 *)pTxDes + 1, 0, sizeof(struct wb35_descriptor) - 1);
475 TxDesIndex = pMds->TxDesIndex; /* Get the current ID */
476 pTxDes->Descriptor_ID = TxDesIndex;
477 pMds->TxDesFrom[ TxDesIndex ] = 2; /* Storing the information of source comming from */
479 pMds->TxDesIndex %= MAX_USB_TX_DESCRIPTOR;
481 MLME_GetNextPacket( adapter, pTxDes );
483 /* Copy header. 8byte USB + 24byte 802.11Hdr. Set TxRate, Preamble type */
484 Mds_HeaderCopy( adapter, pTxDes, XmitBufAddress );
486 /* For speed up Key setting */
487 if (pTxDes->EapFix) {
489 printk("35: EPA 4th frame detected. Size = %d\n", PacketSize);
491 pHwData->IsKeyPreSet = 1;
494 /* Copy (fragment) frame body, and set USB, 802.11 hdr flag */
495 CurrentSize = Mds_BodyCopy(adapter, pTxDes, XmitBufAddress);
497 /* Set RTS/CTS and Normal duration field into buffer */
498 Mds_DurationSet(adapter, pTxDes, XmitBufAddress);
500 /* Shift to the next address */
501 XmitBufSize += CurrentSize;
502 XmitBufAddress += CurrentSize;
504 #ifdef _IBSS_BEACON_SEQ_STICK_
505 if ((XmitBufAddress[ DOT_11_DA_OFFSET+8 ] & 0xfc) != MAC_SUBTYPE_MNGMNT_PROBE_REQUEST) /* +8 for USB hdr */
507 pMds->TxToggle = true;
509 /* Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data */
510 MLME_SendComplete(adapter, 0, true);
512 /* Software TSC count 20060214 */
514 if (pMds->TxTsc == 0)
517 FillCount++; /* 20060928 */
518 } while (HAL_USB_MODE_BURST(pHwData)); /* End of multiple MSDU copy loop. false = single true = multiple sending */
520 /* Move to the next one, if necessary */
523 pMds->TxBufferSize[ FillIndex ] = XmitBufSize;
525 /* 20060928 set Tx count */
526 pMds->TxCountInBuffer[FillIndex] = FillCount;
529 pMds->TxOwner[FillIndex] = 1;
532 pMds->TxFillIndex %= MAX_USB_TX_BUFFER_NUMBER;
533 BufferFilled = false;
537 if (!PacketSize) /* No more pk for transmitting */
543 * Start to send by lower module
545 if (!pHwData->IsKeyPreSet)
546 Wb35Tx_start(adapter);
549 atomic_dec(&pMds->TxThreadCount);
553 Mds_SendComplete(struct wbsoft_priv *adapter, PT02_DESCRIPTOR pT02)
555 struct wb35_mds *pMds = &adapter->Mds;
556 struct hw_data *pHwData = &adapter->sHwData;
557 u8 PacketId = (u8)pT02->T02_Tx_PktID;
558 unsigned char SendOK = true;
559 u8 RetryCount, TxRate;
561 if (pT02->T02_IgnoreResult) /* Don't care the result */
563 if (pT02->T02_IsLastMpdu) {
564 /* TODO: DTO -- get the retry count and fragment count */
566 TxRate = pMds->TxRate[ PacketId ][ 0 ];
567 RetryCount = (u8)pT02->T02_MPDU_Cnt;
568 if (pT02->value & FLAG_ERROR_TX_MASK) {
571 if (pT02->T02_transmit_abort || pT02->T02_out_of_MaxTxMSDULiftTime) {
573 pHwData->dto_tx_retry_count += (RetryCount+1);
576 pHwData->tx_retry_count[RetryCount] += RetryCount;
578 pHwData->tx_retry_count[7] += RetryCount;
579 #ifdef _PE_STATE_DUMP_
580 printk("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count);
582 MTO_SetTxCount(adapter, TxRate, RetryCount);
584 pHwData->dto_tx_frag_count += (RetryCount+1);
587 if (pT02->T02_transmit_abort_due_to_TBTT)
588 pHwData->tx_TBTT_start_count++;
589 if (pT02->T02_transmit_without_encryption_due_to_wep_on_false)
590 pHwData->tx_WepOn_false_count++;
591 if (pT02->T02_discard_due_to_null_wep_key)
592 pHwData->tx_Null_key_count++;
594 if (pT02->T02_effective_transmission_rate)
595 pHwData->tx_ETR_count++;
596 MTO_SetTxCount(adapter, TxRate, RetryCount);
599 /* Clear send result buffer */
600 pMds->TxResult[ PacketId ] = 0;
602 pMds->TxResult[ PacketId ] |= ((u16)(pT02->value & 0x0ffff));