Commit | Line | Data |
---|---|---|
94a79942 LF |
1 | /****************************************************************************** |
2 | * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. | |
3 | * | |
4 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
5 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
6 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
7 | * more details. | |
8 | * | |
9 | * You should have received a copy of the GNU General Public License along with | |
10 | * this program; if not, write to the Free Software Foundation, Inc., | |
11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | |
12 | * | |
13 | * The full GNU General Public License is included in this distribution in the | |
14 | * file called LICENSE. | |
15 | * | |
16 | * Contact Information: | |
17 | * wlanfae <wlanfae@realtek.com> | |
18 | ******************************************************************************/ | |
94a79942 LF |
19 | |
20 | #include "rtl_core.h" | |
21 | #include "r8192E_hw.h" | |
22 | #include "r8192E_cmdpkt.h" | |
23 | /*---------------------------Define Local Constant---------------------------*/ | |
24 | /* Debug constant*/ | |
25 | #define CMPK_DEBOUNCE_CNT 1 | |
26 | #define CMPK_PRINT(Address)\ | |
27 | {\ | |
28 | unsigned char i;\ | |
29 | u32 temp[10];\ | |
30 | \ | |
31 | memcpy(temp, Address, 40);\ | |
ac513a88 LF |
32 | for (i = 0; i < 40; i += 4)\ |
33 | printk(KERN_INFO "\r\n %08x", temp[i]);\ | |
34 | } | |
94a79942 LF |
35 | |
36 | /*---------------------------Define functions---------------------------------*/ | |
49aab5fd | 37 | bool cmpk_message_handle_tx( |
94a79942 | 38 | struct net_device *dev, |
ac513a88 | 39 | u8 *code_virtual_address, |
94a79942 LF |
40 | u32 packettype, |
41 | u32 buffer_len) | |
42 | { | |
43 | ||
44 | bool rt_status = true; | |
e3e37629 | 45 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
46 | u16 frag_threshold; |
47 | u16 frag_length = 0, frag_offset = 0; | |
5aca114d | 48 | struct rt_firmware *pfirmware = priv->pFirmware; |
94a79942 LF |
49 | struct sk_buff *skb; |
50 | unsigned char *seg_ptr; | |
3b83db43 | 51 | struct cb_desc *tcb_desc; |
94a79942 LF |
52 | u8 bLastIniPkt; |
53 | ||
a07dc3d1 | 54 | struct tx_fwinfo_8190pci *pTxFwInfo = NULL; |
94a79942 | 55 | |
ac513a88 | 56 | RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, buffer_len); |
94a79942 LF |
57 | firmware_init_param(dev); |
58 | frag_threshold = pfirmware->cmdpacket_frag_thresold; | |
59 | ||
60 | do { | |
61 | if ((buffer_len - frag_offset) > frag_threshold) { | |
62 | frag_length = frag_threshold ; | |
63 | bLastIniPkt = 0; | |
64 | ||
65 | } else { | |
ac513a88 | 66 | frag_length = (u16)(buffer_len - frag_offset); |
94a79942 LF |
67 | bLastIniPkt = 1; |
68 | } | |
69 | ||
ac513a88 LF |
70 | skb = dev_alloc_skb(frag_length + |
71 | priv->rtllib->tx_headroom + 4); | |
94a79942 LF |
72 | |
73 | if (skb == NULL) { | |
74 | rt_status = false; | |
75 | goto Failed; | |
76 | } | |
77 | ||
ac513a88 | 78 | memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); |
3b83db43 | 79 | tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
94a79942 LF |
80 | tcb_desc->queue_index = TXCMD_QUEUE; |
81 | tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL; | |
82 | tcb_desc->bLastIniPkt = bLastIniPkt; | |
83 | tcb_desc->pkt_size = frag_length; | |
84 | ||
85 | seg_ptr = skb_put(skb, priv->rtllib->tx_headroom); | |
a07dc3d1 | 86 | pTxFwInfo = (struct tx_fwinfo_8190pci *)seg_ptr; |
ac513a88 LF |
87 | memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci)); |
88 | memset(pTxFwInfo, 0x12, 8); | |
94a79942 LF |
89 | |
90 | seg_ptr = skb_put(skb, frag_length); | |
91 | memcpy(seg_ptr, code_virtual_address, (u32)frag_length); | |
92 | ||
ac513a88 | 93 | priv->rtllib->softmac_hard_start_xmit(skb, dev); |
94a79942 LF |
94 | |
95 | code_virtual_address += frag_length; | |
96 | frag_offset += frag_length; | |
97 | ||
ac513a88 | 98 | } while (frag_offset < buffer_len); |
94a79942 LF |
99 | |
100 | write_nic_byte(dev, TPPoll, TPPoll_CQ); | |
101 | Failed: | |
102 | return rt_status; | |
103 | } /* CMPK_Message_Handle_Tx */ | |
104 | ||
105 | static void | |
106 | cmpk_count_txstatistic( | |
107 | struct net_device *dev, | |
d3ab7211 | 108 | struct cmpk_txfb *pstx_fb) |
94a79942 LF |
109 | { |
110 | struct r8192_priv *priv = rtllib_priv(dev); | |
111 | #ifdef ENABLE_PS | |
de7c885a | 112 | enum rt_rf_power_state rtState; |
94a79942 | 113 | |
ac513a88 LF |
114 | pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE, |
115 | (pu1Byte)(&rtState)); | |
94a79942 LF |
116 | |
117 | if (rtState == eRfOff) | |
94a79942 | 118 | return; |
94a79942 LF |
119 | #endif |
120 | ||
cb762154 | 121 | if (pstx_fb->tok) { |
94a79942 LF |
122 | priv->stats.txfeedbackok++; |
123 | priv->stats.txoktotal++; | |
124 | priv->stats.txokbytestotal += pstx_fb->pkt_length; | |
125 | priv->stats.txokinperiod++; | |
126 | ||
cb762154 | 127 | if (pstx_fb->pkt_type == PACKET_MULTICAST) { |
94a79942 LF |
128 | priv->stats.txmulticast++; |
129 | priv->stats.txbytesmulticast += pstx_fb->pkt_length; | |
cb762154 | 130 | } else if (pstx_fb->pkt_type == PACKET_BROADCAST) { |
94a79942 LF |
131 | priv->stats.txbroadcast++; |
132 | priv->stats.txbytesbroadcast += pstx_fb->pkt_length; | |
cb762154 | 133 | } else { |
94a79942 LF |
134 | priv->stats.txunicast++; |
135 | priv->stats.txbytesunicast += pstx_fb->pkt_length; | |
136 | } | |
cb762154 | 137 | } else { |
94a79942 LF |
138 | priv->stats.txfeedbackfail++; |
139 | priv->stats.txerrtotal++; | |
140 | priv->stats.txerrbytestotal += pstx_fb->pkt_length; | |
141 | ||
142 | if (pstx_fb->pkt_type == PACKET_MULTICAST) | |
94a79942 | 143 | priv->stats.txerrmulticast++; |
94a79942 | 144 | else if (pstx_fb->pkt_type == PACKET_BROADCAST) |
94a79942 | 145 | priv->stats.txerrbroadcast++; |
94a79942 | 146 | else |
94a79942 | 147 | priv->stats.txerrunicast++; |
94a79942 LF |
148 | } |
149 | ||
150 | priv->stats.txretrycount += pstx_fb->retry_cnt; | |
151 | priv->stats.txfeedbackretry += pstx_fb->retry_cnt; | |
152 | ||
153 | } /* cmpk_CountTxStatistic */ | |
154 | ||
155 | ||
156 | ||
ac513a88 | 157 | static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg) |
94a79942 LF |
158 | { |
159 | struct r8192_priv *priv = rtllib_priv(dev); | |
d3ab7211 | 160 | struct cmpk_txfb rx_tx_fb; /* */ |
94a79942 LF |
161 | |
162 | priv->stats.txfeedback++; | |
163 | ||
164 | ||
ac513a88 | 165 | memcpy((u8 *)&rx_tx_fb, pmsg, sizeof(struct cmpk_txfb)); |
94a79942 LF |
166 | cmpk_count_txstatistic(dev, &rx_tx_fb); |
167 | ||
168 | } /* cmpk_Handle_Tx_Feedback */ | |
169 | ||
49aab5fd | 170 | static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev) |
94a79942 LF |
171 | { |
172 | struct r8192_priv *priv = rtllib_priv(dev); | |
173 | u16 tx_rate; | |
94a79942 | 174 | |
ac513a88 LF |
175 | if ((priv->rtllib->current_network.mode == IEEE_A) || |
176 | (priv->rtllib->current_network.mode == IEEE_N_5G) || | |
177 | ((priv->rtllib->current_network.mode == IEEE_N_24G) && | |
178 | (!priv->rtllib->pHTInfo->bCurSuppCCK))) { | |
179 | tx_rate = 60; | |
180 | DMESG("send beacon frame tx rate is 6Mbpm\n"); | |
181 | } else { | |
182 | tx_rate = 10; | |
183 | DMESG("send beacon frame tx rate is 1Mbpm\n"); | |
94a79942 LF |
184 | } |
185 | ||
186 | } | |
187 | ||
ac513a88 | 188 | static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg) |
94a79942 | 189 | { |
a76d9849 | 190 | struct cmpk_intr_sta rx_intr_status; /* */ |
94a79942 LF |
191 | struct r8192_priv *priv = rtllib_priv(dev); |
192 | ||
193 | DMESG("---> cmpk_Handle_Interrupt_Status()\n"); | |
194 | ||
195 | ||
196 | rx_intr_status.length = pmsg[1]; | |
ac513a88 | 197 | if (rx_intr_status.length != (sizeof(struct cmpk_intr_sta) - 2)) { |
94a79942 LF |
198 | DMESG("cmpk_Handle_Interrupt_Status: wrong length!\n"); |
199 | return; | |
200 | } | |
201 | ||
202 | ||
ac513a88 | 203 | if (priv->rtllib->iw_mode == IW_MODE_ADHOC) { |
94a79942 LF |
204 | rx_intr_status.interrupt_status = *((u32 *)(pmsg + 4)); |
205 | ||
ac513a88 LF |
206 | DMESG("interrupt status = 0x%x\n", |
207 | rx_intr_status.interrupt_status); | |
94a79942 | 208 | |
ac513a88 | 209 | if (rx_intr_status.interrupt_status & ISR_TxBcnOk) { |
94a79942 LF |
210 | priv->rtllib->bibsscoordinator = true; |
211 | priv->stats.txbeaconokint++; | |
ac513a88 | 212 | } else if (rx_intr_status.interrupt_status & ISR_TxBcnErr) { |
94a79942 LF |
213 | priv->rtllib->bibsscoordinator = false; |
214 | priv->stats.txbeaconerr++; | |
215 | } | |
216 | ||
217 | if (rx_intr_status.interrupt_status & ISR_BcnTimerIntr) | |
94a79942 | 218 | cmdpkt_beacontimerinterrupt_819xusb(dev); |
94a79942 LF |
219 | } |
220 | ||
94a79942 LF |
221 | DMESG("<---- cmpk_handle_interrupt_status()\n"); |
222 | ||
223 | } /* cmpk_handle_interrupt_status */ | |
224 | ||
225 | ||
ac513a88 | 226 | static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg) |
94a79942 LF |
227 | { |
228 | cmpk_query_cfg_t rx_query_cfg; /* */ | |
229 | ||
230 | ||
ac513a88 LF |
231 | rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000)>>31; |
232 | rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5; | |
233 | rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3; | |
234 | rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0; | |
235 | rx_query_cfg.cfg_offset = pmsg[7]; | |
236 | rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) | | |
237 | (pmsg[10] << 8) | (pmsg[11] << 0); | |
238 | rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) | | |
239 | (pmsg[14] << 8) | (pmsg[15] << 0); | |
94a79942 LF |
240 | |
241 | } /* cmpk_Handle_Query_Config_Rx */ | |
242 | ||
243 | ||
ac513a88 LF |
244 | static void cmpk_count_tx_status(struct net_device *dev, |
245 | struct cmpk_tx_status *pstx_status) | |
94a79942 LF |
246 | { |
247 | struct r8192_priv *priv = rtllib_priv(dev); | |
248 | ||
249 | #ifdef ENABLE_PS | |
250 | ||
de7c885a | 251 | enum rt_rf_power_state rtstate; |
94a79942 | 252 | |
ac513a88 LF |
253 | pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE, |
254 | (pu1Byte)(&rtState)); | |
94a79942 LF |
255 | |
256 | if (rtState == eRfOff) | |
94a79942 | 257 | return; |
94a79942 LF |
258 | #endif |
259 | ||
260 | priv->stats.txfeedbackok += pstx_status->txok; | |
261 | priv->stats.txoktotal += pstx_status->txok; | |
262 | ||
263 | priv->stats.txfeedbackfail += pstx_status->txfail; | |
264 | priv->stats.txerrtotal += pstx_status->txfail; | |
265 | ||
266 | priv->stats.txretrycount += pstx_status->txretry; | |
267 | priv->stats.txfeedbackretry += pstx_status->txretry; | |
268 | ||
269 | ||
270 | priv->stats.txmulticast += pstx_status->txmcok; | |
271 | priv->stats.txbroadcast += pstx_status->txbcok; | |
272 | priv->stats.txunicast += pstx_status->txucok; | |
273 | ||
274 | priv->stats.txerrmulticast += pstx_status->txmcfail; | |
275 | priv->stats.txerrbroadcast += pstx_status->txbcfail; | |
276 | priv->stats.txerrunicast += pstx_status->txucfail; | |
277 | ||
278 | priv->stats.txbytesmulticast += pstx_status->txmclength; | |
279 | priv->stats.txbytesbroadcast += pstx_status->txbclength; | |
280 | priv->stats.txbytesunicast += pstx_status->txuclength; | |
281 | ||
282 | priv->stats.last_packet_rate = pstx_status->rate; | |
283 | } /* cmpk_CountTxStatus */ | |
284 | ||
285 | ||
286 | ||
ac513a88 | 287 | static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg) |
94a79942 | 288 | { |
7f6aa06c | 289 | struct cmpk_tx_status rx_tx_sts; /* */ |
94a79942 | 290 | |
ac513a88 | 291 | memcpy((void *)&rx_tx_sts, (void *)pmsg, sizeof(struct cmpk_tx_status)); |
94a79942 | 292 | cmpk_count_tx_status(dev, &rx_tx_sts); |
94a79942 LF |
293 | } |
294 | ||
ac513a88 | 295 | static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg) |
94a79942 | 296 | { |
1b419253 | 297 | struct cmpk_tx_rahis *ptxrate; |
ac513a88 | 298 | u8 i, j; |
1b419253 | 299 | u16 length = sizeof(struct cmpk_tx_rahis); |
ac513a88 | 300 | u32 *ptemp; |
94a79942 LF |
301 | struct r8192_priv *priv = rtllib_priv(dev); |
302 | ||
303 | ||
304 | #ifdef ENABLE_PS | |
ac513a88 LF |
305 | pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE, |
306 | (pu1Byte)(&rtState)); | |
94a79942 LF |
307 | |
308 | if (rtState == eRfOff) | |
94a79942 | 309 | return; |
94a79942 LF |
310 | #endif |
311 | ||
312 | ptemp = (u32 *)pmsg; | |
313 | ||
ac513a88 | 314 | for (i = 0; i < (length / 4); i++) { |
94a79942 LF |
315 | u16 temp1, temp2; |
316 | ||
ac513a88 LF |
317 | temp1 = ptemp[i] & 0x0000FFFF; |
318 | temp2 = ptemp[i] >> 16; | |
319 | ptemp[i] = (temp1 << 16) | temp2; | |
94a79942 LF |
320 | } |
321 | ||
1b419253 | 322 | ptxrate = (struct cmpk_tx_rahis *)pmsg; |
94a79942 | 323 | |
ac513a88 | 324 | if (ptxrate == NULL) |
94a79942 | 325 | return; |
94a79942 | 326 | |
ac513a88 | 327 | for (i = 0; i < 16; i++) { |
94a79942 LF |
328 | if (i < 4) |
329 | priv->stats.txrate.cck[i] += ptxrate->cck[i]; | |
330 | ||
ac513a88 | 331 | if (i < 8) |
94a79942 LF |
332 | priv->stats.txrate.ofdm[i] += ptxrate->ofdm[i]; |
333 | ||
334 | for (j = 0; j < 4; j++) | |
ac513a88 LF |
335 | priv->stats.txrate.ht_mcs[j][i] += |
336 | ptxrate->ht_mcs[j][i]; | |
94a79942 LF |
337 | } |
338 | ||
339 | } | |
340 | ||
341 | ||
49aab5fd LF |
342 | u32 cmpk_message_handle_rx(struct net_device *dev, |
343 | struct rtllib_rx_stats *pstats) | |
94a79942 | 344 | { |
94a79942 LF |
345 | int total_length; |
346 | u8 cmd_length, exe_cnt = 0; | |
347 | u8 element_id; | |
348 | u8 *pcmd_buff; | |
349 | ||
350 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx()\n"); | |
351 | ||
ac513a88 | 352 | if (pstats == NULL) { |
94a79942 LF |
353 | /* Print error message. */ |
354 | /*RT_TRACE(COMP_SEND, DebugLevel, | |
355 | ("\n\r[CMPK]-->Err queue id or pointer"));*/ | |
356 | return 0; | |
357 | } | |
358 | ||
359 | total_length = pstats->Length; | |
360 | ||
361 | pcmd_buff = pstats->virtual_address; | |
362 | ||
363 | element_id = pcmd_buff[0]; | |
364 | ||
ac513a88 | 365 | while (total_length > 0 || exe_cnt++ > 100) { |
94a79942 LF |
366 | element_id = pcmd_buff[0]; |
367 | ||
368 | switch (element_id) { | |
369 | case RX_TX_FEEDBACK: | |
ac513a88 LF |
370 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
371 | "RX_TX_FEEDBACK\n"); | |
372 | cmpk_handle_tx_feedback(dev, pcmd_buff); | |
94a79942 LF |
373 | cmd_length = CMPK_RX_TX_FB_SIZE; |
374 | break; | |
375 | case RX_INTERRUPT_STATUS: | |
ac513a88 LF |
376 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
377 | "RX_INTERRUPT_STATUS\n"); | |
94a79942 | 378 | cmpk_handle_interrupt_status(dev, pcmd_buff); |
a76d9849 | 379 | cmd_length = sizeof(struct cmpk_intr_sta); |
94a79942 LF |
380 | break; |
381 | case BOTH_QUERY_CONFIG: | |
ac513a88 LF |
382 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
383 | "BOTH_QUERY_CONFIG\n"); | |
94a79942 LF |
384 | cmpk_handle_query_config_rx(dev, pcmd_buff); |
385 | cmd_length = CMPK_BOTH_QUERY_CONFIG_SIZE; | |
386 | break; | |
387 | case RX_TX_STATUS: | |
ac513a88 LF |
388 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
389 | "RX_TX_STATUS\n"); | |
94a79942 LF |
390 | cmpk_handle_tx_status(dev, pcmd_buff); |
391 | cmd_length = CMPK_RX_TX_STS_SIZE; | |
392 | break; | |
393 | case RX_TX_PER_PKT_FEEDBACK: | |
ac513a88 LF |
394 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
395 | "RX_TX_PER_PKT_FEEDBACK\n"); | |
94a79942 LF |
396 | cmd_length = CMPK_RX_TX_FB_SIZE; |
397 | break; | |
398 | case RX_TX_RATE_HISTORY: | |
ac513a88 LF |
399 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
400 | "RX_TX_HISTORY\n"); | |
94a79942 LF |
401 | cmpk_handle_tx_rate_history(dev, pcmd_buff); |
402 | cmd_length = CMPK_TX_RAHIS_SIZE; | |
403 | break; | |
404 | default: | |
405 | ||
ac513a88 LF |
406 | RT_TRACE(COMP_CMDPKT, "---->cmpk_message_handle_rx():" |
407 | "unknow CMD Element\n"); | |
94a79942 LF |
408 | return 1; |
409 | } | |
410 | ||
94a79942 LF |
411 | total_length -= cmd_length; |
412 | pcmd_buff += cmd_length; | |
413 | } | |
414 | return 1; | |
94a79942 | 415 | } |