7 Mds_initial(struct wbsoft_priv
*adapter
)
9 struct wb35_mds
*pMds
= &adapter
->Mds
;
11 pMds
->TxPause
= false;
12 pMds
->TxRTSThreshold
= DEFAULT_RTSThreshold
;
13 pMds
->TxFragmentThreshold
= DEFAULT_FRAGMENT_THRESHOLD
;
15 return hal_get_tx_buffer(&adapter
->sHwData
, &pMds
->pTxBuffer
);
18 static void Mds_DurationSet(struct wbsoft_priv
*adapter
,
19 struct wb35_descriptor
*pDes
, u8
*buffer
)
21 struct T00_descriptor
*pT00
;
22 struct T01_descriptor
*pT01
;
23 u16 Duration
, NextBodyLen
, OffsetSize
;
25 unsigned char CTS_on
= false, RTS_on
= false;
26 struct T00_descriptor
*pNextT00
;
28 unsigned char boGroupAddr
= false;
30 OffsetSize
= pDes
->FragmentThreshold
+ 32 + 3;
32 Rate
= pDes
->TxRate
>> 1;
36 pT00
= (struct T00_descriptor
*)buffer
;
37 pT01
= (struct T01_descriptor
*)(buffer
+4);
38 pNextT00
= (struct T00_descriptor
*)(buffer
+OffsetSize
);
40 if (buffer
[DOT_11_DA_OFFSET
+8] & 0x1) /* +8 for USB hdr */
43 /******************************************
44 * Set RTS/CTS mechanism
45 ******************************************/
47 /* NOTE : If the protection mode is enabled and the MSDU will
48 * be fragmented, the tx rates of MPDUs will all be DSSS
49 * rates. So it will not use CTS-to-self in this case.
50 * CTS-To-self will only be used when without
51 * fragmentation. -- 20050112 */
52 BodyLen
= (u16
)pT00
->T00_frame_length
; /* include 802.11 header */
53 BodyLen
+= 4; /* CRC */
55 if (BodyLen
>= CURRENT_RTS_THRESHOLD
)
56 RTS_on
= true; /* Using RTS */
58 if (pT01
->T01_modulation_type
) { /* Is using OFDM */
59 /* Is using protect */
60 if (CURRENT_PROTECT_MECHANISM
)
61 CTS_on
= true; /* Using CTS */
66 if (RTS_on
|| CTS_on
) {
67 if (pT01
->T01_modulation_type
) { /* Is using OFDM */
69 * 2 SIFS + DATA transmit time + 1 ACK
70 * ACK Rate : 24 Mega bps
71 * ACK frame length = 14 bytes */
72 Duration
= 2*DEFAULT_SIFSTIME
+
73 2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION
+
74 ((BodyLen
*8 + 22 + Rate
*4 - 1)/(Rate
*4))*Tsym
+
75 ((112 + 22 + 95)/96)*Tsym
;
78 * 2 SIFS + DATA transmit time + 1 ACK
80 * ACK frame length = 14 bytes */
81 if (pT01
->T01_plcp_header_length
) /* long preamble */
82 Duration
= LONG_PREAMBLE_PLUS_PLCPHEADER_TIME
*2;
84 Duration
= SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME
*2;
86 Duration
+= (((BodyLen
+ 14)*8 + Rate
-1) / Rate
+
91 if (pT01
->T01_modulation_type
) { /* Is using OFDM */
92 /* CTS + 1 SIFS + CTS duration
93 * CTS Rate : 24 Mega bps
94 * CTS frame length = 14 bytes */
95 Duration
+= (DEFAULT_SIFSTIME
+
96 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION
+
97 ((112 + 22 + 95)/96)*Tsym
);
99 /* CTS + 1 SIFS + CTS duration
100 * CTS Rate : ?? Mega bps
101 * CTS frame length = 14 bytes
104 if (pT01
->T01_plcp_header_length
)
105 Duration
+= LONG_PREAMBLE_PLUS_PLCPHEADER_TIME
;
107 Duration
+= SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME
;
109 Duration
+= (((112 + Rate
-1) / Rate
) +
114 /* Set the value into USB descriptor */
115 pT01
->T01_add_rts
= RTS_on
? 1 : 0;
116 pT01
->T01_add_cts
= CTS_on
? 1 : 0;
117 pT01
->T01_rts_cts_duration
= Duration
;
120 /******************************************
121 * Fill the more fragment descriptor
122 ******************************************/
126 for (i
= pDes
->FragmentCount
-1; i
> 0; i
--) {
127 NextBodyLen
= (u16
)pNextT00
->T00_frame_length
;
128 NextBodyLen
+= 4; /* CRC */
130 if (pT01
->T01_modulation_type
) {
132 * data transmit time + 3 SIFS + 2 ACK
134 * ACK frame length = 14 bytes, tx rate = 24M */
135 Duration
= PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION
* 3;
136 Duration
+= (((NextBodyLen
*8 + 22 + Rate
*4 - 1)
138 (((2*14)*8 + 22 + 95)/96)*Tsym
+
142 * data transmit time + 2 ACK + 3 SIFS
144 * ACK frame length = 14 bytes
146 if (pT01
->T01_plcp_header_length
) /* long preamble */
147 Duration
= LONG_PREAMBLE_PLUS_PLCPHEADER_TIME
*3;
149 Duration
= SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME
*3;
151 Duration
+= (((NextBodyLen
+ (2*14))*8
155 /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
156 ((u16
*)buffer
)[5] = cpu_to_le16(Duration
);
158 /* ----20061009 add by anson's endian */
159 pNextT00
->value
= cpu_to_le32(pNextT00
->value
);
160 pT01
->value
= cpu_to_le32(pT01
->value
);
161 /* ----end 20061009 add by anson's endian */
163 buffer
+= OffsetSize
;
164 pT01
= (struct T01_descriptor
*)(buffer
+4);
165 /* The last fragment will not have the next fragment */
167 pNextT00
= (struct T00_descriptor
*)(buffer
+OffsetSize
);
170 /*******************************************
171 * Fill the last fragment descriptor
172 *******************************************/
173 if (pT01
->T01_modulation_type
) {
177 * ACK frame length = 14 bytes */
178 Duration
= PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION
;
179 /* The Tx rate of ACK use 24M */
180 Duration
+= (((112 + 22 + 95)/96)*Tsym
+
186 * ACK frame length = 14 bytes(112 bits) */
187 if (pT01
->T01_plcp_header_length
) /* long preamble */
188 Duration
= LONG_PREAMBLE_PLUS_PLCPHEADER_TIME
;
190 Duration
= SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME
;
192 Duration
+= ((112 + Rate
-1)/Rate
+ DEFAULT_SIFSTIME
);
196 /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
197 ((u16
*)buffer
)[5] = cpu_to_le16(Duration
);
198 pT00
->value
= cpu_to_le32(pT00
->value
);
199 pT01
->value
= cpu_to_le32(pT01
->value
);
200 /* --end 20061009 add */
204 /* The function return the 4n size of usb pk */
205 static u16
Mds_BodyCopy(struct wbsoft_priv
*adapter
,
206 struct wb35_descriptor
*pDes
, u8
*TargetBuffer
)
208 struct T00_descriptor
*pT00
;
209 struct wb35_mds
*pMds
= &adapter
->Mds
;
214 u16 SizeLeft
, CopySize
, CopyLeft
, stmp
;
215 u8 buf_index
, FragmentCount
= 0;
218 /* Copy fragment body */
219 buffer
= TargetBuffer
; /* shift 8B usb + 24B 802.11 */
220 SizeLeft
= pDes
->buffer_total_size
;
221 buf_index
= pDes
->buffer_start_index
;
223 pT00
= (struct T00_descriptor
*)buffer
;
225 pT00
= (struct T00_descriptor
*)buffer
;
227 if (SizeLeft
> pDes
->FragmentThreshold
) {
228 CopySize
= pDes
->FragmentThreshold
;
230 pT00
->T00_frame_length
= 24 + CopySize
;
231 } else /* Set USB length */
232 pT00
->T00_frame_length
= 24 + SizeLeft
;
234 SizeLeft
-= CopySize
;
236 /* 1 Byte operation */
237 pctmp
= (u8
*)(buffer
+ 8 + DOT_11_SEQUENCE_OFFSET
);
239 *pctmp
|= FragmentCount
; /* 931130.5.m */
241 pT00
->T00_first_mpdu
= 1;
243 buffer
+= 32; /* 8B usb + 24B 802.11 header */
246 /* Copy into buffer */
248 stmp
&= ~0x03; /* 4n Alignment */
249 Size
+= stmp
; /* Current 4n offset of mpdu */
253 src_buffer
= pDes
->buffer_address
[buf_index
];
255 if (CopySize
>= pDes
->buffer_size
[buf_index
]) {
256 CopyLeft
= pDes
->buffer_size
[buf_index
];
258 /* Get the next buffer of descriptor */
260 buf_index
%= MAX_DESCRIPTOR_BUFFER_INDEX
;
262 u8
*pctmp
= pDes
->buffer_address
[buf_index
];
264 pDes
->buffer_address
[buf_index
] = pctmp
;
265 pDes
->buffer_size
[buf_index
] -= CopySize
;
268 memcpy(buffer
, src_buffer
, CopyLeft
);
270 CopySize
-= CopyLeft
;
276 pMds
->MicWriteAddress
[pMds
->MicWriteIndex
] =
277 buffer
- pMds
->MicAdd
;
278 pMds
->MicWriteSize
[pMds
->MicWriteIndex
] =
281 } else if (SizeLeft
< 8) { /* 931130.5.p */
282 pMds
->MicAdd
= SizeLeft
;
283 pMds
->MicWriteAddress
[pMds
->MicWriteIndex
] =
284 buffer
- (8 - SizeLeft
);
285 pMds
->MicWriteSize
[pMds
->MicWriteIndex
] =
287 pMds
->MicWriteIndex
++;
291 /* Does it need to generate the new header for next mpdu? */
293 /* Get the next 4n start address */
294 buffer
= TargetBuffer
+ Size
;
295 /* Copy 8B USB +24B 802.11 */
296 memcpy(buffer
, TargetBuffer
, 32);
297 pT00
= (struct T00_descriptor
*)buffer
;
298 pT00
->T00_first_mpdu
= 0;
304 pT00
->T00_last_mpdu
= 1;
305 pT00
->T00_IsLastMpdu
= 1;
306 buffer
= (u8
*)pT00
+ 8; /* +8 for USB hdr */
307 buffer
[1] &= ~0x04; /* Clear more frag bit of 802.11 frame control */
308 /* Update the correct fragment number */
309 pDes
->FragmentCount
= FragmentCount
;
313 static void Mds_HeaderCopy(struct wbsoft_priv
*adapter
,
314 struct wb35_descriptor
*pDes
, u8
*TargetBuffer
)
316 struct wb35_mds
*pMds
= &adapter
->Mds
;
317 u8
*src_buffer
= pDes
->buffer_address
[0]; /* 931130.5.g */
318 struct T00_descriptor
*pT00
;
319 struct T01_descriptor
*pT01
;
321 u8 i
, ctmp1
, ctmp2
, ctmpf
;
322 u16 FragmentThreshold
= CURRENT_FRAGMENT_THRESHOLD
;
325 stmp
= pDes
->buffer_total_size
;
327 * Set USB header 8 byte
329 pT00
= (struct T00_descriptor
*)TargetBuffer
;
331 pT01
= (struct T01_descriptor
*)TargetBuffer
;
334 pT00
->value
= 0; /* Clear */
335 pT01
->value
= 0; /* Clear */
337 pT00
->T00_tx_packet_id
= pDes
->Descriptor_ID
; /* Set packet ID */
338 pT00
->T00_header_length
= 24; /* Set header length */
339 pT01
->T01_retry_abort_enable
= 1; /* 921013 931130.5.h */
342 pT01
->T01_wep_id
= 0;
344 FragmentThreshold
= DEFAULT_FRAGMENT_THRESHOLD
; /* Do not fragment */
345 /* Copy full data, the 1'st buffer contain all the data 931130.5.j */
347 memcpy(TargetBuffer
, src_buffer
, DOT_11_MAC_HEADER_SIZE
);
348 pDes
->buffer_address
[0] = src_buffer
+ DOT_11_MAC_HEADER_SIZE
;
349 pDes
->buffer_total_size
-= DOT_11_MAC_HEADER_SIZE
;
350 pDes
->buffer_size
[0] = pDes
->buffer_total_size
;
352 /* Set fragment threshold */
353 FragmentThreshold
-= (DOT_11_MAC_HEADER_SIZE
+ 4);
354 pDes
->FragmentThreshold
= FragmentThreshold
;
356 /* Set more frag bit */
357 TargetBuffer
[1] |= 0x04; /* Set more frag bit */
362 stmp
= *(u16
*)(TargetBuffer
+30); /* 2n alignment address */
365 ctmp1
= ctmpf
= CURRENT_TX_RATE_FOR_MNG
;
367 pDes
->TxRate
= ctmp1
;
368 pr_debug("Tx rate =%x\n", ctmp1
);
370 pT01
->T01_modulation_type
= (ctmp1
%3) ? 0 : 1;
372 for (i
= 0; i
< 2; i
++) {
375 /* backup the ta rate and fall back rate */
376 pMds
->TxRate
[pDes
->Descriptor_ID
][i
] = ctmp1
;
380 else if (ctmp1
== 96)
381 ctmp2
= 6; /* Rate convert for USB */
382 else if (ctmp1
== 72)
384 else if (ctmp1
== 48)
386 else if (ctmp1
== 36)
388 else if (ctmp1
== 24)
390 else if (ctmp1
== 18)
392 else if (ctmp1
== 12)
394 else if (ctmp1
== 22)
396 else if (ctmp1
== 11)
401 ctmp2
= 0; /* if( ctmp1 == 2 ) or default */
404 pT01
->T01_transmit_rate
= ctmp2
;
406 pT01
->T01_fall_back_rate
= ctmp2
;
413 if ((pT01
->T01_modulation_type
== 0) && (pT01
->T01_transmit_rate
== 0))
414 pDes
->PreambleMode
= WLAN_PREAMBLE_TYPE_LONG
;
416 pDes
->PreambleMode
= CURRENT_PREAMBLE_MODE
;
417 pT01
->T01_plcp_header_length
= pDes
->PreambleMode
; /* Set preamble */
421 static void MLME_GetNextPacket(struct wbsoft_priv
*adapter
,
422 struct wb35_descriptor
*desc
)
424 desc
->InternalUsed
= desc
->buffer_start_index
+ desc
->buffer_number
;
425 desc
->InternalUsed
%= MAX_DESCRIPTOR_BUFFER_INDEX
;
426 desc
->buffer_address
[desc
->InternalUsed
] = adapter
->sMlmeFrame
.pMMPDU
;
427 desc
->buffer_size
[desc
->InternalUsed
] = adapter
->sMlmeFrame
.len
;
428 desc
->buffer_total_size
+= adapter
->sMlmeFrame
.len
;
429 desc
->buffer_number
++;
430 desc
->Type
= adapter
->sMlmeFrame
.data_type
;
433 static void MLMEfreeMMPDUBuffer(struct wbsoft_priv
*adapter
, s8
*pData
)
437 /* Reclaim the data buffer */
438 for (i
= 0; i
< MAX_NUM_TX_MMPDU
; i
++) {
439 if (pData
== (s8
*)&(adapter
->sMlmeFrame
.TxMMPDU
[i
]))
442 if (adapter
->sMlmeFrame
.TxMMPDUInUse
[i
])
443 adapter
->sMlmeFrame
.TxMMPDUInUse
[i
] = false;
446 PD43 Add debug code here??? */
450 static void MLME_SendComplete(struct wbsoft_priv
*adapter
, u8 PacketID
,
451 unsigned char SendOK
)
453 /* Reclaim the data buffer */
454 adapter
->sMlmeFrame
.len
= 0;
455 MLMEfreeMMPDUBuffer(adapter
, adapter
->sMlmeFrame
.pMMPDU
);
457 /* Return resource */
458 adapter
->sMlmeFrame
.is_in_used
= PACKET_FREE_TO_USE
;
462 Mds_Tx(struct wbsoft_priv
*adapter
)
464 struct hw_data
*pHwData
= &adapter
->sHwData
;
465 struct wb35_mds
*pMds
= &adapter
->Mds
;
466 struct wb35_descriptor TxDes
;
467 struct wb35_descriptor
*pTxDes
= &TxDes
;
469 u16 XmitBufSize
, PacketSize
, stmp
, CurrentSize
, FragmentThreshold
;
470 u8 FillIndex
, TxDesIndex
, FragmentCount
, FillCount
;
471 unsigned char BufferFilled
= false;
476 if (!hal_driver_init_OK(pHwData
))
479 /* Only one thread can be run here */
480 if (atomic_inc_return(&pMds
->TxThreadCount
) != 1)
483 /* Start to fill the data */
485 FillIndex
= pMds
->TxFillIndex
;
486 /* Is owned by software 0:Yes 1:No */
487 if (pMds
->TxOwner
[FillIndex
]) {
488 pr_debug("[Mds_Tx] Tx Owner is H/W.\n");
493 XmitBufAddress
= pMds
->pTxBuffer
+ (MAX_USB_TX_BUFFER
* FillIndex
);
497 PacketSize
= adapter
->sMlmeFrame
.len
;
501 /* For Check the buffer resource */
502 FragmentThreshold
= CURRENT_FRAGMENT_THRESHOLD
;
504 FragmentCount
= PacketSize
/FragmentThreshold
+ 1;
505 /* 931130.5.c 8:MIC */
506 stmp
= PacketSize
+ FragmentCount
*32 + 8;
507 if ((XmitBufSize
+ stmp
) >= MAX_USB_TX_BUFFER
)
508 break; /* buffer is not enough */
515 /* Leaves first u8 intact */
516 memset((u8
*)pTxDes
+ 1, 0, sizeof(struct wb35_descriptor
) - 1);
518 TxDesIndex
= pMds
->TxDesIndex
; /* Get the current ID */
519 pTxDes
->Descriptor_ID
= TxDesIndex
;
520 /* Storing the information of source coming from */
521 pMds
->TxDesFrom
[TxDesIndex
] = 2;
523 pMds
->TxDesIndex
%= MAX_USB_TX_DESCRIPTOR
;
525 MLME_GetNextPacket(adapter
, pTxDes
);
528 * Copy header. 8byte USB + 24byte 802.11Hdr.
529 * Set TxRate, Preamble type
531 Mds_HeaderCopy(adapter
, pTxDes
, XmitBufAddress
);
533 /* For speed up Key setting */
534 if (pTxDes
->EapFix
) {
535 pr_debug("35: EPA 4th frame detected. Size = %d\n",
537 pHwData
->IsKeyPreSet
= 1;
540 /* Copy (fragment) frame body, and set USB, 802.11 hdr flag */
541 CurrentSize
= Mds_BodyCopy(adapter
, pTxDes
, XmitBufAddress
);
543 /* Set RTS/CTS and Normal duration field into buffer */
544 Mds_DurationSet(adapter
, pTxDes
, XmitBufAddress
);
546 /* Shift to the next address */
547 XmitBufSize
+= CurrentSize
;
548 XmitBufAddress
+= CurrentSize
;
550 /* Get packet to transmit completed,
551 * 1:TESTSTA 2:MLME 3: Ndis data
553 MLME_SendComplete(adapter
, 0, true);
555 /* Software TSC count 20060214 */
557 if (pMds
->TxTsc
== 0)
560 FillCount
++; /* 20060928 */
562 * End of multiple MSDU copy loop.
564 * true = multiple sending
566 } while (HAL_USB_MODE_BURST(pHwData
));
568 /* Move to the next one, if necessary */
571 pMds
->TxBufferSize
[FillIndex
] = XmitBufSize
;
573 /* 20060928 set Tx count */
574 pMds
->TxCountInBuffer
[FillIndex
] = FillCount
;
577 pMds
->TxOwner
[FillIndex
] = 1;
580 pMds
->TxFillIndex
%= MAX_USB_TX_BUFFER_NUMBER
;
581 BufferFilled
= false;
585 if (!PacketSize
) /* No more pk for transmitting */
591 * Start to send by lower module
593 if (!pHwData
->IsKeyPreSet
)
594 Wb35Tx_start(adapter
);
597 atomic_dec(&pMds
->TxThreadCount
);
601 Mds_SendComplete(struct wbsoft_priv
*adapter
, struct T02_descriptor
*pT02
)
603 struct wb35_mds
*pMds
= &adapter
->Mds
;
604 struct hw_data
*pHwData
= &adapter
->sHwData
;
605 u8 PacketId
= (u8
)pT02
->T02_Tx_PktID
;
606 unsigned char SendOK
= true;
607 u8 RetryCount
, TxRate
;
609 if (pT02
->T02_IgnoreResult
) /* Don't care about the result */
611 if (pT02
->T02_IsLastMpdu
) {
612 /* TODO: DTO -- get the retry count and fragment count */
614 TxRate
= pMds
->TxRate
[PacketId
][0];
615 RetryCount
= (u8
)pT02
->T02_MPDU_Cnt
;
616 if (pT02
->value
& FLAG_ERROR_TX_MASK
) {
619 if (pT02
->T02_transmit_abort
|| pT02
->T02_out_of_MaxTxMSDULiftTime
) {
621 pHwData
->dto_tx_retry_count
+= (RetryCount
+1);
624 pHwData
->tx_retry_count
[RetryCount
] += RetryCount
;
626 pHwData
->tx_retry_count
[7] += RetryCount
;
627 pr_debug("dto_tx_retry_count =%d\n",
628 pHwData
->dto_tx_retry_count
);
629 MTO_SetTxCount(adapter
, TxRate
, RetryCount
);
631 pHwData
->dto_tx_frag_count
+= (RetryCount
+1);
634 if (pT02
->T02_transmit_abort_due_to_TBTT
)
635 pHwData
->tx_TBTT_start_count
++;
636 if (pT02
->T02_transmit_without_encryption_due_to_wep_on_false
)
637 pHwData
->tx_WepOn_false_count
++;
638 if (pT02
->T02_discard_due_to_null_wep_key
)
639 pHwData
->tx_Null_key_count
++;
641 if (pT02
->T02_effective_transmission_rate
)
642 pHwData
->tx_ETR_count
++;
643 MTO_SetTxCount(adapter
, TxRate
, RetryCount
);
646 /* Clear send result buffer */
647 pMds
->TxResult
[PacketId
] = 0;
649 pMds
->TxResult
[PacketId
] |= ((u16
)(pT02
->value
& 0x0ffff));