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