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