]> Pileus Git - ~andy/linux/blob - drivers/staging/winbond/mds.c
Staging: w35und: Merge wbhal_f.h to wbhal_s.h
[~andy/linux] / drivers / staging / winbond / mds.c
1 #include "mds_f.h"
2 #include "mlmetxrx_f.h"
3 #include "mto.h"
4 #include "sysdef.h"
5 #include "wbhal_s.h"
6 #include "wblinux_f.h"
7 #include "wb35tx_f.h"
8
9 unsigned char
10 Mds_initial(struct wbsoft_priv *adapter)
11 {
12         struct wb35_mds *pMds = &adapter->Mds;
13
14         pMds->TxPause = false;
15         pMds->TxRTSThreshold = DEFAULT_RTSThreshold;
16         pMds->TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
17
18         return hal_get_tx_buffer(&adapter->sHwData, &pMds->pTxBuffer);
19 }
20
21 void
22 Mds_Destroy(struct wbsoft_priv *adapter)
23 {
24 }
25
26 static void Mds_DurationSet(struct wbsoft_priv *adapter,  struct wb35_descriptor *pDes,  u8 *buffer)
27 {
28         struct T00_descriptor *pT00;
29         struct T01_descriptor *pT01;
30         u16     Duration, NextBodyLen, OffsetSize;
31         u8      Rate, i;
32         unsigned char   CTS_on = false, RTS_on = false;
33         struct T00_descriptor *pNextT00;
34         u16 BodyLen = 0;
35         unsigned char boGroupAddr = false;
36
37         OffsetSize = pDes->FragmentThreshold + 32 + 3;
38         OffsetSize &= ~0x03;
39         Rate = pDes->TxRate >> 1;
40         if (!Rate)
41                 Rate = 1;
42
43         pT00 = (struct T00_descriptor *)buffer;
44         pT01 = (struct T01_descriptor *)(buffer+4);
45         pNextT00 = (struct T00_descriptor *)(buffer+OffsetSize);
46
47         if (buffer[DOT_11_DA_OFFSET+8] & 0x1) /* +8 for USB hdr */
48                 boGroupAddr = true;
49
50         /******************************************
51          * Set RTS/CTS mechanism
52          ******************************************/
53         if (!boGroupAddr) {
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 */
60
61                 if (BodyLen >= CURRENT_RTS_THRESHOLD)
62                         RTS_on = true; /* Using RTS */
63                 else {
64                         if (pT01->T01_modulation_type) { /* Is using OFDM */
65                                 if (CURRENT_PROTECT_MECHANISM) /* Is using protect */
66                                         CTS_on = true; /* Using CTS */
67                         }
68                 }
69         }
70
71         if (RTS_on || CTS_on) {
72                 if (pT01->T01_modulation_type) { /* Is using OFDM */
73                         /* CTS duration
74                          *  2 SIFS + DATA transmit time + 1 ACK
75                          *  ACK Rate : 24 Mega bps
76                          *  ACK frame length = 14 bytes */
77                         Duration = 2*DEFAULT_SIFSTIME +
78                                            2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
79                                            ((BodyLen*8 + 22 + Rate*4 - 1)/(Rate*4))*Tsym +
80                                            ((112 + 22 + 95)/96)*Tsym;
81                 } else  { /* DSSS */
82                         /* CTS duration
83                          *  2 SIFS + DATA transmit time + 1 ACK
84                          *  Rate : ?? Mega bps
85                          *  ACK frame length = 14 bytes */
86                         if (pT01->T01_plcp_header_length) /* long preamble */
87                                 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
88                         else
89                                 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
90
91                         Duration += (((BodyLen + 14)*8 + Rate-1) / Rate +
92                                                 DEFAULT_SIFSTIME*2);
93                 }
94
95                 if (RTS_on) {
96                         if (pT01->T01_modulation_type) { /* Is using OFDM */
97                                 /* CTS + 1 SIFS + CTS duration
98                                  * CTS Rate : 24 Mega bps
99                                  * CTS frame length = 14 bytes */
100                                 Duration += (DEFAULT_SIFSTIME +
101                                                                 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
102                                                                 ((112 + 22 + 95)/96)*Tsym);
103                         } else {
104                                 /* CTS + 1 SIFS + CTS duration
105                                  * CTS Rate : ?? Mega bps
106                                  * CTS frame length = 14 bytes */
107                                 if (pT01->T01_plcp_header_length) /* long preamble */
108                                         Duration += LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
109                                 else
110                                         Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
111
112                                 Duration += (((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME);
113                         }
114                 }
115
116                 /* Set the value into USB descriptor */
117                 pT01->T01_add_rts = RTS_on ? 1 : 0;
118                 pT01->T01_add_cts = CTS_on ? 1 : 0;
119                 pT01->T01_rts_cts_duration = Duration;
120         }
121
122         /******************************************
123          * Fill the more fragment descriptor
124          ******************************************/
125         if (boGroupAddr)
126                 Duration = 0;
127         else {
128                 for (i = pDes->FragmentCount-1; i > 0; i--) {
129                         NextBodyLen = (u16)pNextT00->T00_frame_length;
130                         NextBodyLen += 4;       /* CRC */
131
132                         if (pT01->T01_modulation_type) {
133                                 /* OFDM
134                                  *  data transmit time + 3 SIFS + 2 ACK
135                                  *  Rate : ??Mega bps
136                                  *  ACK frame length = 14 bytes, tx rate = 24M */
137                                 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION * 3;
138                                 Duration += (((NextBodyLen*8 + 22 + Rate*4 - 1)/(Rate*4)) * Tsym +
139                                                         (((2*14)*8 + 22 + 95)/96)*Tsym +
140                                                         DEFAULT_SIFSTIME*3);
141                         } else {
142                                 /* DSSS
143                                  *  data transmit time + 2 ACK + 3 SIFS
144                                  *  Rate : ??Mega bps
145                                  *  ACK frame length = 14 bytes
146                                  * TODO : */
147                                 if (pT01->T01_plcp_header_length) /* long preamble */
148                                         Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
149                                 else
150                                         Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
151
152                                 Duration += (((NextBodyLen + (2*14))*8 + Rate-1) / Rate +
153                                                         DEFAULT_SIFSTIME*3);
154                         }
155
156                         ((u16 *)buffer)[5] = cpu_to_le16(Duration); /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
157
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 */
162
163                         buffer += OffsetSize;
164                         pT01 = (struct T01_descriptor *)(buffer+4);
165                         if (i != 1)     /* The last fragment will not have the next fragment */
166                                 pNextT00 = (struct T00_descriptor *)(buffer+OffsetSize);
167                 }
168
169                 /*******************************************
170                  * Fill the last fragment descriptor
171                  *******************************************/
172                 if (pT01->T01_modulation_type) {
173                         /* OFDM
174                          *  1 SIFS + 1 ACK
175                          *  Rate : 24 Mega bps
176                          * ACK frame length = 14 bytes */
177                         Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION;
178                         /* The Tx rate of ACK use 24M */
179                         Duration += (((112 + 22 + 95)/96)*Tsym + DEFAULT_SIFSTIME);
180                 } else {
181                         /* DSSS
182                          * 1 ACK + 1 SIFS
183                          * Rate : ?? Mega bps
184                          * ACK frame length = 14 bytes(112 bits) */
185                         if (pT01->T01_plcp_header_length) /* long preamble */
186                                 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
187                         else
188                                 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
189
190                         Duration += ((112 + Rate-1)/Rate + DEFAULT_SIFSTIME);
191                 }
192         }
193
194         ((u16 *)buffer)[5] = cpu_to_le16(Duration); /* 4 USHOR for skip 8B USB, 2USHORT=FC + Duration */
195         pT00->value = cpu_to_le32(pT00->value);
196         pT01->value = cpu_to_le32(pT01->value);
197         /* --end 20061009 add */
198
199 }
200
201 /* The function return the 4n size of usb pk */
202 static u16 Mds_BodyCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *TargetBuffer)
203 {
204         struct T00_descriptor *pT00;
205         struct wb35_mds *pMds = &adapter->Mds;
206         u8      *buffer;
207         u8      *src_buffer;
208         u8      *pctmp;
209         u16     Size = 0;
210         u16     SizeLeft, CopySize, CopyLeft, stmp;
211         u8      buf_index, FragmentCount = 0;
212
213
214         /* Copy fragment body */
215         buffer = TargetBuffer; /* shift 8B usb + 24B 802.11 */
216         SizeLeft = pDes->buffer_total_size;
217         buf_index = pDes->buffer_start_index;
218
219         pT00 = (struct T00_descriptor *)buffer;
220         while (SizeLeft) {
221                 pT00 = (struct T00_descriptor *)buffer;
222                 CopySize = SizeLeft;
223                 if (SizeLeft > pDes->FragmentThreshold) {
224                         CopySize = pDes->FragmentThreshold;
225                         pT00->T00_frame_length = 24 + CopySize; /* Set USB length */
226                 } else
227                         pT00->T00_frame_length = 24 + SizeLeft; /* Set USB length */
228
229                 SizeLeft -= CopySize;
230
231                 /* 1 Byte operation */
232                 pctmp = (u8 *)(buffer + 8 + DOT_11_SEQUENCE_OFFSET);
233                 *pctmp &= 0xf0;
234                 *pctmp |= FragmentCount; /* 931130.5.m */
235                 if (!FragmentCount)
236                         pT00->T00_first_mpdu = 1;
237
238                 buffer += 32; /* 8B usb + 24B 802.11 header */
239                 Size += 32;
240
241                 /* Copy into buffer */
242                 stmp = CopySize + 3;
243                 stmp &= ~0x03; /* 4n Alignment */
244                 Size += stmp; /* Current 4n offset of mpdu */
245
246                 while (CopySize) {
247                         /* Copy body */
248                         src_buffer = pDes->buffer_address[buf_index];
249                         CopyLeft = CopySize;
250                         if (CopySize >= pDes->buffer_size[buf_index]) {
251                                 CopyLeft = pDes->buffer_size[buf_index];
252
253                                 /* Get the next buffer of descriptor */
254                                 buf_index++;
255                                 buf_index %= MAX_DESCRIPTOR_BUFFER_INDEX;
256                         } else {
257                                 u8      *pctmp = pDes->buffer_address[buf_index];
258                                 pctmp += CopySize;
259                                 pDes->buffer_address[buf_index] = pctmp;
260                                 pDes->buffer_size[buf_index] -= CopySize;
261                         }
262
263                         memcpy(buffer, src_buffer, CopyLeft);
264                         buffer += CopyLeft;
265                         CopySize -= CopyLeft;
266                 }
267
268                 /* 931130.5.n */
269                 if (pMds->MicAdd) {
270                         if (!SizeLeft) {
271                                 pMds->MicWriteAddress[pMds->MicWriteIndex] = buffer - pMds->MicAdd;
272                                 pMds->MicWriteSize[pMds->MicWriteIndex] = pMds->MicAdd;
273                                 pMds->MicAdd = 0;
274                         } else if (SizeLeft < 8) { /* 931130.5.p */
275                                 pMds->MicAdd = SizeLeft;
276                                 pMds->MicWriteAddress[pMds->MicWriteIndex] = buffer - (8 - SizeLeft);
277                                 pMds->MicWriteSize[pMds->MicWriteIndex] = 8 - SizeLeft;
278                                 pMds->MicWriteIndex++;
279                         }
280                 }
281
282                 /* Does it need to generate the new header for next mpdu? */
283                 if (SizeLeft) {
284                         buffer = TargetBuffer + Size; /* Get the next 4n start address */
285                         memcpy(buffer, TargetBuffer, 32); /* Copy 8B USB +24B 802.11 */
286                         pT00 = (struct T00_descriptor *)buffer;
287                         pT00->T00_first_mpdu = 0;
288                 }
289
290                 FragmentCount++;
291         }
292
293         pT00->T00_last_mpdu = 1;
294         pT00->T00_IsLastMpdu = 1;
295         buffer = (u8 *)pT00 + 8; /* +8 for USB hdr */
296         buffer[1] &= ~0x04; /* Clear more frag bit of 802.11 frame control */
297         pDes->FragmentCount = FragmentCount; /* Update the correct fragment number */
298         return Size;
299 }
300
301 static void Mds_HeaderCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *TargetBuffer)
302 {
303         struct wb35_mds *pMds = &adapter->Mds;
304         u8      *src_buffer = pDes->buffer_address[0]; /* 931130.5.g */
305         struct T00_descriptor *pT00;
306         struct T01_descriptor *pT01;
307         u16     stmp;
308         u8      i, ctmp1, ctmp2, ctmpf;
309         u16     FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
310
311
312         stmp = pDes->buffer_total_size;
313         /*
314          * Set USB header 8 byte
315          */
316         pT00 = (struct T00_descriptor *)TargetBuffer;
317         TargetBuffer += 4;
318         pT01 = (struct T01_descriptor *)TargetBuffer;
319         TargetBuffer += 4;
320
321         pT00->value = 0; /* Clear */
322         pT01->value = 0; /* Clear */
323
324         pT00->T00_tx_packet_id = pDes->Descriptor_ID; /* Set packet ID */
325         pT00->T00_header_length = 24; /* Set header length */
326         pT01->T01_retry_abort_ebable = 1; /* 921013 931130.5.h */
327
328         /* Key ID setup */
329         pT01->T01_wep_id = 0;
330
331         FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; /* Do not fragment */
332         /* Copy full data, the 1'st buffer contain all the data 931130.5.j */
333         memcpy(TargetBuffer, src_buffer, DOT_11_MAC_HEADER_SIZE); /* Copy header */
334         pDes->buffer_address[0] = src_buffer + DOT_11_MAC_HEADER_SIZE;
335         pDes->buffer_total_size -= DOT_11_MAC_HEADER_SIZE;
336         pDes->buffer_size[0] = pDes->buffer_total_size;
337
338         /* Set fragment threshold */
339         FragmentThreshold -= (DOT_11_MAC_HEADER_SIZE + 4);
340         pDes->FragmentThreshold = FragmentThreshold;
341
342         /* Set more frag bit */
343         TargetBuffer[1] |= 0x04; /* Set more frag bit */
344
345         /*
346          * Set tx rate
347          */
348         stmp = *(u16 *)(TargetBuffer+30); /* 2n alignment address */
349
350         /* Use basic rate */
351         ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG;
352
353         pDes->TxRate = ctmp1;
354         #ifdef _PE_TX_DUMP_
355         printk("Tx rate =%x\n", ctmp1);
356         #endif
357
358         pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1;
359
360         for (i = 0; i < 2; i++) {
361                 if (i == 1)
362                         ctmp1 = ctmpf;
363
364                 pMds->TxRate[pDes->Descriptor_ID][i] = ctmp1; /* backup the ta rate and fall back rate */
365
366                 if (ctmp1 == 108)
367                         ctmp2 = 7;
368                 else if (ctmp1 == 96)
369                         ctmp2 = 6; /* Rate convert for USB */
370                 else if (ctmp1 == 72)
371                         ctmp2 = 5;
372                 else if (ctmp1 == 48)
373                         ctmp2 = 4;
374                 else if (ctmp1 == 36)
375                         ctmp2 = 3;
376                 else if (ctmp1 == 24)
377                         ctmp2 = 2;
378                 else if (ctmp1 == 18)
379                         ctmp2 = 1;
380                 else if (ctmp1 == 12)
381                         ctmp2 = 0;
382                 else if (ctmp1 == 22)
383                         ctmp2 = 3;
384                 else if (ctmp1 == 11)
385                         ctmp2 = 2;
386                 else if (ctmp1 == 4)
387                         ctmp2 = 1;
388                 else
389                         ctmp2 = 0; /* if( ctmp1 == 2  ) or default */
390
391                 if (i == 0)
392                         pT01->T01_transmit_rate = ctmp2;
393                 else
394                         pT01->T01_fall_back_rate = ctmp2;
395         }
396
397         /*
398          * Set preamble type
399          */
400         if ((pT01->T01_modulation_type == 0) && (pT01->T01_transmit_rate == 0)) /* RATE_1M */
401                 pDes->PreambleMode =  WLAN_PREAMBLE_TYPE_LONG;
402         else
403                 pDes->PreambleMode =  CURRENT_PREAMBLE_MODE;
404         pT01->T01_plcp_header_length = pDes->PreambleMode;      /* Set preamble */
405
406 }
407
408 void
409 Mds_Tx(struct wbsoft_priv *adapter)
410 {
411         struct hw_data *pHwData = &adapter->sHwData;
412         struct wb35_mds *pMds = &adapter->Mds;
413         struct wb35_descriptor  TxDes;
414         struct wb35_descriptor *pTxDes = &TxDes;
415         u8              *XmitBufAddress;
416         u16             XmitBufSize, PacketSize, stmp, CurrentSize, FragmentThreshold;
417         u8              FillIndex, TxDesIndex, FragmentCount, FillCount;
418         unsigned char   BufferFilled = false;
419
420
421         if (pMds->TxPause)
422                 return;
423         if (!hal_driver_init_OK(pHwData))
424                 return;
425
426         /* Only one thread can be run here */
427         if (atomic_inc_return(&pMds->TxThreadCount) != 1)
428                 goto cleanup;
429
430         /* Start to fill the data */
431         do {
432                 FillIndex = pMds->TxFillIndex;
433                 if (pMds->TxOwner[FillIndex]) { /* Is owned by software 0:Yes 1:No */
434 #ifdef _PE_TX_DUMP_
435                         printk("[Mds_Tx] Tx Owner is H/W.\n");
436 #endif
437                         break;
438                 }
439
440                 XmitBufAddress = pMds->pTxBuffer + (MAX_USB_TX_BUFFER * FillIndex); /* Get buffer */
441                 XmitBufSize = 0;
442                 FillCount = 0;
443                 do {
444                         PacketSize = adapter->sMlmeFrame.len;
445                         if (!PacketSize)
446                                 break;
447
448                         /* For Check the buffer resource */
449                         FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
450                         /* 931130.5.b */
451                         FragmentCount = PacketSize/FragmentThreshold + 1;
452                         stmp = PacketSize + FragmentCount*32 + 8; /* 931130.5.c 8:MIC */
453                         if ((XmitBufSize + stmp) >= MAX_USB_TX_BUFFER) {
454                                 printk("[Mds_Tx] Excess max tx buffer.\n");
455                                 break; /* buffer is not enough */
456                         }
457
458
459                         /*
460                          * Start transmitting
461                          */
462                         BufferFilled = true;
463
464                         /* Leaves first u8 intact */
465                         memset((u8 *)pTxDes + 1, 0, sizeof(struct wb35_descriptor) - 1);
466
467                         TxDesIndex = pMds->TxDesIndex; /* Get the current ID */
468                         pTxDes->Descriptor_ID = TxDesIndex;
469                         pMds->TxDesFrom[TxDesIndex] = 2; /* Storing the information of source comming from */
470                         pMds->TxDesIndex++;
471                         pMds->TxDesIndex %= MAX_USB_TX_DESCRIPTOR;
472
473                         MLME_GetNextPacket(adapter, pTxDes);
474
475                         /* Copy header. 8byte USB + 24byte 802.11Hdr. Set TxRate, Preamble type */
476                         Mds_HeaderCopy(adapter, pTxDes, XmitBufAddress);
477
478                         /* For speed up Key setting */
479                         if (pTxDes->EapFix) {
480 #ifdef _PE_TX_DUMP_
481                                 printk("35: EPA 4th frame detected. Size = %d\n", PacketSize);
482 #endif
483                                 pHwData->IsKeyPreSet = 1;
484                         }
485
486                         /* Copy (fragment) frame body, and set USB, 802.11 hdr flag */
487                         CurrentSize = Mds_BodyCopy(adapter, pTxDes, XmitBufAddress);
488
489                         /* Set RTS/CTS and Normal duration field into buffer */
490                         Mds_DurationSet(adapter, pTxDes, XmitBufAddress);
491
492                         /* Shift to the next address */
493                         XmitBufSize += CurrentSize;
494                         XmitBufAddress += CurrentSize;
495
496 #ifdef _IBSS_BEACON_SEQ_STICK_
497                         if ((XmitBufAddress[DOT_11_DA_OFFSET+8] & 0xfc) != MAC_SUBTYPE_MNGMNT_PROBE_REQUEST) /* +8 for USB hdr */
498 #endif
499                                 pMds->TxToggle = true;
500
501                         /* Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data */
502                         MLME_SendComplete(adapter, 0, true);
503
504                         /* Software TSC count 20060214 */
505                         pMds->TxTsc++;
506                         if (pMds->TxTsc == 0)
507                                 pMds->TxTsc_2++;
508
509                         FillCount++; /* 20060928 */
510                 } while (HAL_USB_MODE_BURST(pHwData)); /* End of multiple MSDU copy loop. false = single true = multiple sending  */
511
512                 /* Move to the next one, if necessary */
513                 if (BufferFilled) {
514                         /* size setting */
515                         pMds->TxBufferSize[FillIndex] = XmitBufSize;
516
517                         /* 20060928 set Tx count */
518                         pMds->TxCountInBuffer[FillIndex] = FillCount;
519
520                         /* Set owner flag */
521                         pMds->TxOwner[FillIndex] = 1;
522
523                         pMds->TxFillIndex++;
524                         pMds->TxFillIndex %= MAX_USB_TX_BUFFER_NUMBER;
525                         BufferFilled = false;
526                 } else
527                         break;
528
529                 if (!PacketSize) /* No more pk for transmitting */
530                         break;
531
532         } while (true);
533
534         /*
535          * Start to send by lower module
536          */
537         if (!pHwData->IsKeyPreSet)
538                 Wb35Tx_start(adapter);
539
540 cleanup:
541                 atomic_dec(&pMds->TxThreadCount);
542 }
543
544 void
545 Mds_SendComplete(struct wbsoft_priv *adapter, struct T02_descriptor *pT02)
546 {
547         struct wb35_mds *pMds = &adapter->Mds;
548         struct hw_data *pHwData = &adapter->sHwData;
549         u8      PacketId = (u8)pT02->T02_Tx_PktID;
550         unsigned char   SendOK = true;
551         u8      RetryCount, TxRate;
552
553         if (pT02->T02_IgnoreResult) /* Don't care the result */
554                 return;
555         if (pT02->T02_IsLastMpdu) {
556                 /* TODO: DTO -- get the retry count and fragment count */
557                 /* Tx rate */
558                 TxRate = pMds->TxRate[PacketId][0];
559                 RetryCount = (u8)pT02->T02_MPDU_Cnt;
560                 if (pT02->value & FLAG_ERROR_TX_MASK) {
561                         SendOK = false;
562
563                         if (pT02->T02_transmit_abort || pT02->T02_out_of_MaxTxMSDULiftTime) {
564                                 /* retry error */
565                                 pHwData->dto_tx_retry_count += (RetryCount+1);
566                                 /* [for tx debug] */
567                                 if (RetryCount < 7)
568                                         pHwData->tx_retry_count[RetryCount] += RetryCount;
569                                 else
570                                         pHwData->tx_retry_count[7] += RetryCount;
571                                 #ifdef _PE_STATE_DUMP_
572                                 printk("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count);
573                                 #endif
574                                 MTO_SetTxCount(adapter, TxRate, RetryCount);
575                         }
576                         pHwData->dto_tx_frag_count += (RetryCount+1);
577
578                         /* [for tx debug] */
579                         if (pT02->T02_transmit_abort_due_to_TBTT)
580                                 pHwData->tx_TBTT_start_count++;
581                         if (pT02->T02_transmit_without_encryption_due_to_wep_on_false)
582                                 pHwData->tx_WepOn_false_count++;
583                         if (pT02->T02_discard_due_to_null_wep_key)
584                                 pHwData->tx_Null_key_count++;
585                 } else {
586                         if (pT02->T02_effective_transmission_rate)
587                                 pHwData->tx_ETR_count++;
588                         MTO_SetTxCount(adapter, TxRate, RetryCount);
589                 }
590
591                 /* Clear send result buffer */
592                 pMds->TxResult[PacketId] = 0;
593         } else
594                 pMds->TxResult[PacketId] |= ((u16)(pT02->value & 0x0ffff));
595 }