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