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