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