blob: 7ab9e22f8957df0cac610b50ffa75d7585c102be [file] [log] [blame]
Florian Schilhabela6f81aa2010-07-14 14:43:26 +02001/******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 * Linux device driver for RTL8192U
Florian Schilhabel8dba5992010-03-06 20:45:25 +01004 *
Florian Schilhabela6f81aa2010-07-14 14:43:26 +02005 * This program is distributed in the hope that it will be useful, but WITHOUT
6 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
8 * more details.
Florian Schilhabel8dba5992010-03-06 20:45:25 +01009 *
Florian Schilhabela6f81aa2010-07-14 14:43:26 +020010 * You should have received a copy of the GNU General Public License along with
11 * this program; if not, write to the Free Software Foundation, Inc.,
12 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
13 *
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19******************************************************************************/
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070020#include "r8192U.h"
21#include "r819xU_cmdpkt.h"
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070022
Florian Schilhabel8dba5992010-03-06 20:45:25 +010023bool SendTxCommandPacket(struct net_device *dev, void *pData, u32 DataLen)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070024{
25 bool rtStatus = true;
26 struct r8192_priv *priv = ieee80211_priv(dev);
27 struct sk_buff *skb;
28 cb_desc *tcb_desc;
29 unsigned char *ptr_buf;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070030
Florian Schilhabel8dba5992010-03-06 20:45:25 +010031 /*
32 * Get TCB and local buffer from common pool.
33 * (It is shared by CmdQ, MgntQ, and USB coalesce DataQ)
34 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070035 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + DataLen + 4);
Florian Schilhabela6f81aa2010-07-14 14:43:26 +020036 if (!skb)
37 return false;
Florian Schilhabel8dba5992010-03-06 20:45:25 +010038 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
39 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070040 tcb_desc->queue_index = TXCMD_QUEUE;
41 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL;
42 tcb_desc->bLastIniPkt = 0;
43 skb_reserve(skb, USB_HWDESC_HEADER_LEN);
44 ptr_buf = skb_put(skb, DataLen);
Florian Schilhabel8dba5992010-03-06 20:45:25 +010045 memcpy(ptr_buf, pData, DataLen);
46 tcb_desc->txbuf_size = (u16)DataLen;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070047
Florian Schilhabel8dba5992010-03-06 20:45:25 +010048 if (!priv->ieee80211->check_nic_enough_desc(dev, tcb_desc->queue_index) ||
49 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index])) ||
50 (priv->ieee80211->queue_stop)) {
51 RT_TRACE(COMP_FIRMWARE, "NULL packet => tx full\n");
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070052 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb);
53 } else {
Florian Schilhabel8dba5992010-03-06 20:45:25 +010054 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070055 }
56
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070057 return rtStatus;
58}
59
Florian Schilhabel8dba5992010-03-06 20:45:25 +010060/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070061 * Function: cmpk_message_handle_tx()
62 *
63 * Overview: Driver internal module can call the API to send message to
Florian Schilhabel8dba5992010-03-06 20:45:25 +010064 * firmware side. For example, you can send a debug command packet.
65 * Or you can send a request for FW to modify RLX4181 LBUS HW bank.
66 * Otherwise, you can change MAC/PHT/RF register by firmware at
67 * run time. We do not support message more than one segment now.
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070068 *
69 * Input: NONE
70 *
71 * Output: NONE
72 *
73 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +010074 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070075 extern bool cmpk_message_handle_tx(
76 struct net_device *dev,
Florian Schilhabel8dba5992010-03-06 20:45:25 +010077 u8 *codevirtualaddress,
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070078 u32 packettype,
79 u32 buffer_len)
80{
Florian Schilhabel8dba5992010-03-06 20:45:25 +010081 bool rt_status = true;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070082 return rt_status;
Florian Schilhabel8dba5992010-03-06 20:45:25 +010083}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070084
Florian Schilhabel8dba5992010-03-06 20:45:25 +010085/*
86 * Function: cmpk_counttxstatistic()
87 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070088static void
Florian Schilhabel8dba5992010-03-06 20:45:25 +010089cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070090{
91 struct r8192_priv *priv = ieee80211_priv(dev);
92#ifdef ENABLE_PS
Florian Schilhabel8dba5992010-03-06 20:45:25 +010093 RT_RF_POWER_STATE rtState;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070094
Florian Schilhabel8dba5992010-03-06 20:45:25 +010095 pAdapter->HalFunc.GetHwRegHandler(pAdapter,
96 HW_VAR_RF_STATE,
97 (pu1Byte)(&rtState));
Jerry Chuang5f53d8c2009-05-21 22:16:02 -070098
Florian Schilhabel8dba5992010-03-06 20:45:25 +010099 /*
100 * When RF is off, we should not count the packet for hw/sw synchronize
101 * reason, ie. there may be a duration while sw switch is changed and hw
102 * switch is being changed.
103 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700104 if (rtState == eRfOff)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700105 return;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700106#endif
107
108#ifdef TODO
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100109 if (pAdapter->bInHctTest)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700110 return;
111#endif
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100112 /*
113 * We can not know the packet length and transmit type:
114 * broadcast or uni or multicast.
115 * So the relative statistics must be collected in tx feedback info
116 */
117 if (pstx_fb->tok) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700118 priv->stats.txfeedbackok++;
119 priv->stats.txoktotal++;
120 priv->stats.txokbytestotal += pstx_fb->pkt_length;
121 priv->stats.txokinperiod++;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700122 /* We can not make sure broadcast/multicast or unicast mode. */
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100123 if (pstx_fb->pkt_type == PACKET_MULTICAST) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700124 priv->stats.txmulticast++;
125 priv->stats.txbytesmulticast += pstx_fb->pkt_length;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100126 } else if (pstx_fb->pkt_type == PACKET_BROADCAST) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700127 priv->stats.txbroadcast++;
128 priv->stats.txbytesbroadcast += pstx_fb->pkt_length;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100129 } else {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700130 priv->stats.txunicast++;
131 priv->stats.txbytesunicast += pstx_fb->pkt_length;
132 }
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100133 } else {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700134 priv->stats.txfeedbackfail++;
135 priv->stats.txerrtotal++;
136 priv->stats.txerrbytestotal += pstx_fb->pkt_length;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700137 /* We can not make sure broadcast/multicast or unicast mode. */
138 if (pstx_fb->pkt_type == PACKET_MULTICAST)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700139 priv->stats.txerrmulticast++;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700140 else if (pstx_fb->pkt_type == PACKET_BROADCAST)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700141 priv->stats.txerrbroadcast++;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700142 else
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700143 priv->stats.txerrunicast++;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700144 }
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700145 priv->stats.txretrycount += pstx_fb->retry_cnt;
146 priv->stats.txfeedbackretry += pstx_fb->retry_cnt;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100147}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700148
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100149/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700150 * Function: cmpk_handle_tx_feedback()
151 *
152 * Overview: The function is responsible for extract the message inside TX
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100153 * feedbck message from firmware. It will contain dedicated info in
154 * ws-06-0063-rtl8190-command-packet-specification. Please
155 * refer to chapter "TX Feedback Element". We have to read 20 bytes
156 * in the command packet.
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700157 *
158 * Input: struct net_device * dev
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100159 * u8 *pmsg - Msg Ptr of the command packet.
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700160 *
161 * Output: NONE
162 *
163 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100164 */
165static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700166{
167 struct r8192_priv *priv = ieee80211_priv(dev);
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100168 cmpk_txfb_t rx_tx_fb;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700169
170 priv->stats.txfeedback++;
171
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700172 /* 1. Extract TX feedback info from RFD to temp structure buffer. */
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100173 memcpy((u8 *)&rx_tx_fb, pmsg, sizeof(cmpk_txfb_t));
Bartlomiej Zolnierkiewicz35c1b462009-07-03 16:08:32 +0200174
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700175 /* 2. Use tx feedback info to count TX statistics. */
176 cmpk_count_txstatistic(dev, &rx_tx_fb);
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100177}
Bartlomiej Zolnierkiewicz35c1b462009-07-03 16:08:32 +0200178
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100179void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700180{
181 struct r8192_priv *priv = ieee80211_priv(dev);
182 u16 tx_rate;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700183
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100184 if (priv->ieee80211->current_network.mode == IEEE_A ||
185 priv->ieee80211->current_network.mode == IEEE_N_5G ||
186 (priv->ieee80211->current_network.mode == IEEE_N_24G &&
187 (!priv->ieee80211->pHTInfo->bCurSuppCCK))) {
188 tx_rate = 60;
189 DMESG("send beacon frame tx rate is 6Mbpm\n");
190 } else {
191 tx_rate = 10;
192 DMESG("send beacon frame tx rate is 1Mbpm\n");
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700193 }
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100194 rtl819xusb_beacon_tx(dev, tx_rate); /* HW Beacon */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700195}
196
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100197/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700198 * Function: cmpk_handle_interrupt_status()
199 *
200 * Overview: The function is responsible for extract the message from
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100201 * firmware. It will contain dedicated info in
202 * ws-07-0063-v06-rtl819x-command-packet-specification-070315.doc.
203 * Please refer to chapter "Interrupt Status Element".
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700204 *
205 * Input: struct net_device *dev,
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100206 * u8* pmsg - Message Pointer of the command packet.
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700207 *
208 * Output: NONE
209 *
210 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100211 */
212static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700213{
214 cmpk_intr_sta_t rx_intr_status; /* */
215 struct r8192_priv *priv = ieee80211_priv(dev);
216
217 DMESG("---> cmpk_Handle_Interrupt_Status()\n");
218
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700219 /* 1. Extract TX feedback info from RFD to temp structure buffer. */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700220 rx_intr_status.length = pmsg[1];
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100221 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700222 DMESG("cmpk_Handle_Interrupt_Status: wrong length!\n");
223 return;
224 }
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100225 /* Statistics of beacon for ad-hoc mode. */
226 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700227 //2 maybe need endian transform?
228 rx_intr_status.interrupt_status = *((u32 *)(pmsg + 4));
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700229
230 DMESG("interrupt status = 0x%x\n", rx_intr_status.interrupt_status);
231
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100232 if (rx_intr_status.interrupt_status & ISR_TxBcnOk) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700233 priv->ieee80211->bibsscoordinator = true;
234 priv->stats.txbeaconokint++;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100235 } else if (rx_intr_status.interrupt_status & ISR_TxBcnErr) {
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700236 priv->ieee80211->bibsscoordinator = false;
237 priv->stats.txbeaconerr++;
238 }
239
240 if (rx_intr_status.interrupt_status & ISR_BcnTimerIntr)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700241 cmdpkt_beacontimerinterrupt_819xusb(dev);
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700242 }
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100243 /* Other informations in interrupt status we need? */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700244 DMESG("<---- cmpk_handle_interrupt_status()\n");
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100245}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700246
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100247/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700248 * Function: cmpk_handle_query_config_rx()
249 *
250 * Overview: The function is responsible for extract the message from
251 * firmware. It will contain dedicated info in
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100252 * ws-06-0063-rtl8190-command-packet-specification
253 * Please refer to chapter "Beacon State Element".
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700254 *
255 * Input: u8 * pmsg - Message Pointer of the command packet.
256 *
257 * Output: NONE
258 *
259 * Return: NONE
260 *
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100261 */
262static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700263{
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100264 cmpk_query_cfg_t rx_query_cfg;
265 /*
266 * Extract TX feedback info from RFD to temp structure buffer.
267 */
268 rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000) >> 31;
269 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5;
270 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3;
271 rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0;
272 rx_query_cfg.cfg_offset = pmsg[7];
273 rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) |
274 (pmsg[10] << 8) | (pmsg[11] << 0);
275 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) |
276 (pmsg[14] << 8) | (pmsg[15] << 0);
277}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700278
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100279/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700280 * Function: cmpk_count_tx_status()
281 *
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100282 * Overview: Count aggregated tx status from firmware of one type rx command
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700283 * packet element id = RX_TX_STATUS.
284 *
285 * Input: NONE
286 *
287 * Output: NONE
288 *
289 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100290 */
291static void cmpk_count_tx_status(struct net_device *dev,
292 cmpk_tx_status_t *pstx_status)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700293{
294 struct r8192_priv *priv = ieee80211_priv(dev);
295
296#ifdef ENABLE_PS
297
298 RT_RF_POWER_STATE rtstate;
299
300 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE, (pu1Byte)(&rtState));
301
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100302 /*
303 * When RF is off, we should not count the packet for hw/sw synchronize
304 * reason, ie. there may be a duration while sw switch is changed and hw
305 * switch is being changed.
306 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700307 if (rtState == eRfOff)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700308 return;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700309#endif
310
311 priv->stats.txfeedbackok += pstx_status->txok;
312 priv->stats.txoktotal += pstx_status->txok;
313
314 priv->stats.txfeedbackfail += pstx_status->txfail;
315 priv->stats.txerrtotal += pstx_status->txfail;
316
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100317 priv->stats.txretrycount += pstx_status->txretry;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700318 priv->stats.txfeedbackretry += pstx_status->txretry;
319
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100320 priv->stats.txmulticast += pstx_status->txmcok;
321 priv->stats.txbroadcast += pstx_status->txbcok;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700322 priv->stats.txunicast += pstx_status->txucok;
323
324 priv->stats.txerrmulticast += pstx_status->txmcfail;
325 priv->stats.txerrbroadcast += pstx_status->txbcfail;
326 priv->stats.txerrunicast += pstx_status->txucfail;
327
328 priv->stats.txbytesmulticast += pstx_status->txmclength;
329 priv->stats.txbytesbroadcast += pstx_status->txbclength;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100330 priv->stats.txbytesunicast += pstx_status->txuclength;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700331
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100332 priv->stats.last_packet_rate = pstx_status->rate;
333}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700334
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100335/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700336 * Function: cmpk_handle_tx_status()
337 *
338 * Overview: Firmware add a new tx feedback status to reduce rx command
339 * packet buffer operation load.
340 *
341 * Input: NONE
342 *
343 * Output: NONE
344 *
345 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100346 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700347static void
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100348cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700349{
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100350 cmpk_tx_status_t rx_tx_sts;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700351
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100352 memcpy((void *)&rx_tx_sts, (void *)pmsg, sizeof(cmpk_tx_status_t));
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700353 /* 2. Use tx feedback info to count TX statistics. */
354 cmpk_count_tx_status(dev, &rx_tx_sts);
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100355}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700356
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100357/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700358 * Function: cmpk_handle_tx_rate_history()
359 *
360 * Overview: Firmware add a new tx rate history
361 *
362 * Input: NONE
363 *
364 * Output: NONE
365 *
366 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100367 */
368static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700369{
370 cmpk_tx_rahis_t *ptxrate;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100371 u8 i, j;
372 u16 length = sizeof(cmpk_tx_rahis_t);
373 u32 *ptemp;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700374 struct r8192_priv *priv = ieee80211_priv(dev);
375
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700376#ifdef ENABLE_PS
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100377 pAdapter->HalFunc.GetHwRegHandler(pAdapter,
378 HW_VAR_RF_STATE,
379 (pu1Byte)(&rtState));
380 /*
381 * When RF is off, we should not count the packet for hw/sw synchronize
382 * reason, ie. there may be a duration while sw switch is changed and hw
383 * switch is being changed.
384 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700385 if (rtState == eRfOff)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700386 return;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700387#endif
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700388 ptemp = (u32 *)pmsg;
389
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100390 /*
391 * Do endian transfer to word alignment(16 bits) for windows system.
392 * You must do different endian transfer for linux and MAC OS
393 */
394 for (i = 0; i < (length/4); i++) {
395 u16 temp1, temp2;
396 temp1 = ptemp[i] & 0x0000FFFF;
397 temp2 = ptemp[i] >> 16;
398 ptemp[i] = (temp1 << 16) | temp2;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700399 }
400
401 ptxrate = (cmpk_tx_rahis_t *)pmsg;
402
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100403 if (ptxrate == NULL)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700404 return;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700405
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100406 for (i = 0; i < 16; i++) {
407 /* Collect CCK rate packet num */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700408 if (i < 4)
409 priv->stats.txrate.cck[i] += ptxrate->cck[i];
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100410 /* Collect OFDM rate packet num */
411 if (i < 8)
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700412 priv->stats.txrate.ofdm[i] += ptxrate->ofdm[i];
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700413 for (j = 0; j < 4; j++)
414 priv->stats.txrate.ht_mcs[j][i] += ptxrate->ht_mcs[j][i];
415 }
416
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100417}
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700418
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100419/*
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700420 * Function: cmpk_message_handle_rx()
421 *
422 * Overview: In the function, we will capture different RX command packet
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100423 * info. Every RX command packet element has different message
424 * length and meaning in content. We only support three type of RX
425 * command packet now. Please refer to document
426 * ws-06-0063-rtl8190-command-packet-specification.
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700427 *
428 * Input: NONE
429 *
430 * Output: NONE
431 *
432 * Return: NONE
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100433 */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700434extern u32
435cmpk_message_handle_rx(
436 struct net_device *dev,
437 struct ieee80211_rx_stats *pstats)
438{
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700439 struct r8192_priv *priv = ieee80211_priv(dev);
440 int total_length;
441 u8 cmd_length, exe_cnt = 0;
442 u8 element_id;
443 u8 *pcmd_buff;
444
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100445 /*
446 * 0. Check input arguments.
447 * If is is a command queue message or pointer is null
448 */
449 if ((pstats == NULL))
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700450 return 0; /* This is not a command packet. */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700451
452 /* 1. Read received command packet message length from RFD. */
453 total_length = pstats->Length;
454
455 /* 2. Read virtual address from RFD. */
456 pcmd_buff = pstats->virtual_address;
457
458 /* 3. Read command pakcet element id and length. */
459 element_id = pcmd_buff[0];
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700460
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100461 /*
462 * 4. Check every received command packet conent according to different
463 * element type. Because FW may aggregate RX command packet to minimize
464 * transmit time between DRV and FW.
465 */
466
467 /* Add a counter to prevent to locked in the loop too long */
468 while (total_length > 0 || exe_cnt++ > 100) {
469 /* We support aggregation of different cmd in the same packet */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700470 element_id = pcmd_buff[0];
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100471 switch (element_id) {
472 case RX_TX_FEEDBACK:
473 cmpk_handle_tx_feedback(dev, pcmd_buff);
474 cmd_length = CMPK_RX_TX_FB_SIZE;
475 break;
476 case RX_INTERRUPT_STATUS:
477 cmpk_handle_interrupt_status(dev, pcmd_buff);
478 cmd_length = sizeof(cmpk_intr_sta_t);
479 break;
480 case BOTH_QUERY_CONFIG:
481 cmpk_handle_query_config_rx(dev, pcmd_buff);
482 cmd_length = CMPK_BOTH_QUERY_CONFIG_SIZE;
483 break;
484 case RX_TX_STATUS:
485 cmpk_handle_tx_status(dev, pcmd_buff);
486 cmd_length = CMPK_RX_TX_STS_SIZE;
487 break;
488 case RX_TX_PER_PKT_FEEDBACK:
489 cmd_length = CMPK_RX_TX_FB_SIZE;
490 break;
491 case RX_TX_RATE_HISTORY:
492 cmpk_handle_tx_rate_history(dev, pcmd_buff);
493 cmd_length = CMPK_TX_RAHIS_SIZE;
494 break;
Florian Schilhabela6f81aa2010-07-14 14:43:26 +0200495 case RX_TX_TSSI_MEAN_BACK:
496 {
497 u32 *pMsg;
498 pMsg = (u32 *)pcmd_buff;
499 }
500 cmd_length = 32;
501 break;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100502 default:
503 RT_TRACE(COMP_ERR, "(%s): unknown CMD Element\n",
504 __func__);
505 return 1; /* This is a command packet. */
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700506 }
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700507 priv->stats.rxcmdpkt[element_id]++;
Jerry Chuang5f53d8c2009-05-21 22:16:02 -0700508 total_length -= cmd_length;
509 pcmd_buff += cmd_length;
Florian Schilhabel8dba5992010-03-06 20:45:25 +0100510 }
511 return 1; /* This is a command packet. */
512}