1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15 #define _RTL8188E_CMD_C_
16
17 #include <osdep_service.h>
18 #include <drv_types.h>
19 #include <recv_osdep.h>
20 #include <mlme_osdep.h>
21 #include <rtw_ioctl_set.h>
22
23 #include <rtl8188e_hal.h>
24
25 #define RTL88E_MAX_H2C_BOX_NUMS 4
26 #define RTL88E_MAX_CMD_LEN 7
27 #define RTL88E_MESSAGE_BOX_SIZE 4
28 #define RTL88E_EX_MESSAGE_BOX_SIZE 4
29
_is_fw_read_cmd_down(struct adapter * adapt,u8 msgbox_num)30 static u8 _is_fw_read_cmd_down(struct adapter *adapt, u8 msgbox_num)
31 {
32 u8 read_down = false;
33 int retry_cnts = 100;
34
35 u8 valid;
36
37 do {
38 valid = usb_read8(adapt, REG_HMETFR) & BIT(msgbox_num);
39 if (0 == valid)
40 read_down = true;
41 } while ((!read_down) && (retry_cnts--));
42
43 return read_down;
44 }
45
46 /*****************************************
47 * H2C Msg format :
48 * 0x1DF - 0x1D0
49 *| 31 - 8 | 7-5 4 - 0 |
50 *| h2c_msg |Class_ID CMD_ID |
51 *
52 * Extend 0x1FF - 0x1F0
53 *|31 - 0 |
54 *|ext_msg|
55 ******************************************/
FillH2CCmd_88E(struct adapter * adapt,u8 ElementID,u32 CmdLen,u8 * pCmdBuffer)56 static s32 FillH2CCmd_88E(struct adapter *adapt, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer)
57 {
58 u8 bcmd_down = false;
59 s32 retry_cnts = 100;
60 u8 h2c_box_num;
61 u32 msgbox_addr;
62 u32 msgbox_ex_addr;
63 u8 cmd_idx, ext_cmd_len;
64 u32 h2c_cmd = 0;
65 u32 h2c_cmd_ex = 0;
66 s32 ret = _FAIL;
67
68
69 if (!adapt->bFWReady) {
70 DBG_88E("FillH2CCmd_88E(): return H2C cmd because fw is not ready\n");
71 return ret;
72 }
73
74 if (!pCmdBuffer)
75 goto exit;
76 if (CmdLen > RTL88E_MAX_CMD_LEN)
77 goto exit;
78 if (adapt->bSurpriseRemoved)
79 goto exit;
80
81 /* pay attention to if race condition happened in H2C cmd setting. */
82 do {
83 h2c_box_num = adapt->HalData->LastHMEBoxNum;
84
85 if (!_is_fw_read_cmd_down(adapt, h2c_box_num)) {
86 DBG_88E(" fw read cmd failed...\n");
87 goto exit;
88 }
89
90 *(u8 *)(&h2c_cmd) = ElementID;
91
92 if (CmdLen <= 3) {
93 memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, CmdLen);
94 } else {
95 memcpy((u8 *)(&h2c_cmd)+1, pCmdBuffer, 3);
96 ext_cmd_len = CmdLen-3;
97 memcpy((u8 *)(&h2c_cmd_ex), pCmdBuffer+3, ext_cmd_len);
98
99 /* Write Ext command */
100 msgbox_ex_addr = REG_HMEBOX_EXT_0 + (h2c_box_num * RTL88E_EX_MESSAGE_BOX_SIZE);
101 for (cmd_idx = 0; cmd_idx < ext_cmd_len; cmd_idx++) {
102 usb_write8(adapt, msgbox_ex_addr+cmd_idx, *((u8 *)(&h2c_cmd_ex)+cmd_idx));
103 }
104 }
105 /* Write command */
106 msgbox_addr = REG_HMEBOX_0 + (h2c_box_num * RTL88E_MESSAGE_BOX_SIZE);
107 for (cmd_idx = 0; cmd_idx < RTL88E_MESSAGE_BOX_SIZE; cmd_idx++) {
108 usb_write8(adapt, msgbox_addr+cmd_idx, *((u8 *)(&h2c_cmd)+cmd_idx));
109 }
110 bcmd_down = true;
111
112 adapt->HalData->LastHMEBoxNum =
113 (h2c_box_num+1) % RTL88E_MAX_H2C_BOX_NUMS;
114
115 } while ((!bcmd_down) && (retry_cnts--));
116
117 ret = _SUCCESS;
118
119 exit:
120
121
122 return ret;
123 }
124
125 /* bitmap[0:27] = tx_rate_bitmap */
126 /* bitmap[28:31]= Rate Adaptive id */
127 /* arg[0:4] = macid */
128 /* arg[5] = Short GI */
rtw_hal_add_ra_tid(struct adapter * pAdapter,u32 bitmap,u8 arg,u8 rssi_level)129 void rtw_hal_add_ra_tid(struct adapter *pAdapter, u32 bitmap, u8 arg, u8 rssi_level)
130 {
131 struct odm_dm_struct *odmpriv = &pAdapter->HalData->odmpriv;
132
133 u8 macid, init_rate, raid, shortGIrate = false;
134
135 macid = arg&0x1f;
136
137 raid = (bitmap>>28) & 0x0f;
138 bitmap &= 0x0fffffff;
139
140 if (rssi_level != DM_RATR_STA_INIT)
141 bitmap = ODM_Get_Rate_Bitmap(odmpriv, macid, bitmap, rssi_level);
142
143 bitmap |= ((raid<<28)&0xf0000000);
144
145 init_rate = get_highest_rate_idx(bitmap&0x0fffffff)&0x3f;
146
147 shortGIrate = (arg & BIT(5)) ? true : false;
148
149 if (shortGIrate)
150 init_rate |= BIT(6);
151
152 raid = (bitmap>>28) & 0x0f;
153
154 bitmap &= 0x0fffffff;
155
156 DBG_88E("%s=> mac_id:%d, raid:%d, ra_bitmap=0x%x, shortGIrate=0x%02x\n",
157 __func__, macid, raid, bitmap, shortGIrate);
158
159 ODM_RA_UpdateRateInfo_8188E(odmpriv, macid, raid, bitmap, shortGIrate);
160 }
161
rtl8188e_set_FwPwrMode_cmd(struct adapter * adapt,u8 Mode)162 void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode)
163 {
164 struct setpwrmode_parm H2CSetPwrMode;
165 struct pwrctrl_priv *pwrpriv = &adapt->pwrctrlpriv;
166 u8 RLBM = 0; /* 0:Min, 1:Max, 2:User define */
167
168 DBG_88E("%s: Mode=%d SmartPS=%d UAPSD=%d\n", __func__,
169 Mode, pwrpriv->smart_ps, adapt->registrypriv.uapsd_enable);
170
171 switch (Mode) {
172 case PS_MODE_ACTIVE:
173 H2CSetPwrMode.Mode = 0;
174 break;
175 case PS_MODE_MIN:
176 H2CSetPwrMode.Mode = 1;
177 break;
178 case PS_MODE_MAX:
179 RLBM = 1;
180 H2CSetPwrMode.Mode = 1;
181 break;
182 case PS_MODE_DTIM:
183 RLBM = 2;
184 H2CSetPwrMode.Mode = 1;
185 break;
186 case PS_MODE_UAPSD_WMM:
187 H2CSetPwrMode.Mode = 2;
188 break;
189 default:
190 H2CSetPwrMode.Mode = 0;
191 break;
192 }
193
194 H2CSetPwrMode.SmartPS_RLBM = (((pwrpriv->smart_ps<<4)&0xf0) | (RLBM & 0x0f));
195
196 H2CSetPwrMode.AwakeInterval = 1;
197
198 H2CSetPwrMode.bAllQueueUAPSD = adapt->registrypriv.uapsd_enable;
199
200 if (Mode > 0)
201 H2CSetPwrMode.PwrState = 0x00;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */
202 else
203 H2CSetPwrMode.PwrState = 0x0C;/* AllON(0x0C), RFON(0x04), RFOFF(0x00) */
204
205 FillH2CCmd_88E(adapt, H2C_PS_PWR_MODE, sizeof(H2CSetPwrMode), (u8 *)&H2CSetPwrMode);
206
207 }
208
rtl8188e_set_FwMediaStatus_cmd(struct adapter * adapt,__le16 mstatus_rpt)209 void rtl8188e_set_FwMediaStatus_cmd(struct adapter *adapt, __le16 mstatus_rpt)
210 {
211 u8 opmode, macid;
212 u16 mst_rpt = le16_to_cpu(mstatus_rpt);
213 opmode = (u8)mst_rpt;
214 macid = (u8)(mst_rpt >> 8);
215
216 DBG_88E("### %s: MStatus=%x MACID=%d\n", __func__, opmode, macid);
217 FillH2CCmd_88E(adapt, H2C_COM_MEDIA_STATUS_RPT, sizeof(mst_rpt), (u8 *)&mst_rpt);
218 }
219
ConstructBeacon(struct adapter * adapt,u8 * pframe,u32 * pLength)220 static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength)
221 {
222 struct ieee80211_hdr *pwlanhdr;
223 __le16 *fctrl;
224 u32 rate_len, pktlen;
225 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
226 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
227 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
228 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
229
230 pwlanhdr = (struct ieee80211_hdr *)pframe;
231
232 fctrl = &pwlanhdr->frame_control;
233 *(fctrl) = 0;
234
235 ether_addr_copy(pwlanhdr->addr1, bc_addr);
236 ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv)));
237 ether_addr_copy(pwlanhdr->addr3, cur_network->MacAddress);
238
239 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
240 SetFrameSubType(pframe, WIFI_BEACON);
241
242 pframe += sizeof(struct ieee80211_hdr_3addr);
243 pktlen = sizeof(struct ieee80211_hdr_3addr);
244
245 /* timestamp will be inserted by hardware */
246 pframe += 8;
247 pktlen += 8;
248
249 /* beacon interval: 2 bytes */
250 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
251
252 pframe += 2;
253 pktlen += 2;
254
255 /* capability info: 2 bytes */
256 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
257
258 pframe += 2;
259 pktlen += 2;
260
261 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
262 pktlen += cur_network->IELength - sizeof(struct ndis_802_11_fixed_ie);
263 memcpy(pframe, cur_network->IEs+sizeof(struct ndis_802_11_fixed_ie), pktlen);
264
265 goto _ConstructBeacon;
266 }
267
268 /* below for ad-hoc mode */
269
270 /* SSID */
271 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pktlen);
272
273 /* supported rates... */
274 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
275 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(u32, rate_len, 8), cur_network->SupportedRates, &pktlen);
276
277 /* DS parameter set */
278 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen);
279
280 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
281 u32 ATIMWindow;
282 /* IBSS Parameter Set... */
283 ATIMWindow = 0;
284 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pktlen);
285 }
286
287 /* todo: ERP IE */
288
289 /* EXTERNDED SUPPORTED RATE */
290 if (rate_len > 8)
291 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pktlen);
292
293 /* todo:HT for adhoc */
294
295 _ConstructBeacon:
296
297 if ((pktlen + TXDESC_SIZE) > 512) {
298 DBG_88E("beacon frame too large\n");
299 return;
300 }
301
302 *pLength = pktlen;
303 }
304
ConstructPSPoll(struct adapter * adapt,u8 * pframe,u32 * pLength)305 static void ConstructPSPoll(struct adapter *adapt, u8 *pframe, u32 *pLength)
306 {
307 struct ieee80211_hdr *pwlanhdr;
308 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
309 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
310 __le16 *fctrl;
311 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
312
313 pwlanhdr = (struct ieee80211_hdr *)pframe;
314
315 /* Frame control. */
316 fctrl = &pwlanhdr->frame_control;
317 *(fctrl) = 0;
318 SetPwrMgt(fctrl);
319 SetFrameSubType(pframe, WIFI_PSPOLL);
320
321 /* AID. */
322 SetDuration(pframe, (pmlmeinfo->aid | 0xc000));
323
324 /* BSSID. */
325 ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress);
326
327 /* TA. */
328 ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv)));
329
330 *pLength = 16;
331 }
332
ConstructNullFunctionData(struct adapter * adapt,u8 * pframe,u32 * pLength,u8 * StaAddr,u8 bQoS,u8 AC,u8 bEosp,u8 bForcePowerSave)333 static void ConstructNullFunctionData(struct adapter *adapt, u8 *pframe,
334 u32 *pLength,
335 u8 *StaAddr,
336 u8 bQoS,
337 u8 AC,
338 u8 bEosp,
339 u8 bForcePowerSave)
340 {
341 struct ieee80211_hdr *pwlanhdr;
342 __le16 *fctrl;
343 u32 pktlen;
344 struct mlme_priv *pmlmepriv = &adapt->mlmepriv;
345 struct wlan_network *cur_network = &pmlmepriv->cur_network;
346 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
347 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
348 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
349
350 pwlanhdr = (struct ieee80211_hdr *)pframe;
351
352 fctrl = &pwlanhdr->frame_control;
353 *(fctrl) = 0;
354 if (bForcePowerSave)
355 SetPwrMgt(fctrl);
356
357 switch (cur_network->network.InfrastructureMode) {
358 case Ndis802_11Infrastructure:
359 SetToDs(fctrl);
360 ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress);
361 ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv)));
362 ether_addr_copy(pwlanhdr->addr3, StaAddr);
363 break;
364 case Ndis802_11APMode:
365 SetFrDs(fctrl);
366 ether_addr_copy(pwlanhdr->addr1, StaAddr);
367 ether_addr_copy(pwlanhdr->addr2, pnetwork->MacAddress);
368 ether_addr_copy(pwlanhdr->addr3, myid(&(adapt->eeprompriv)));
369 break;
370 case Ndis802_11IBSS:
371 default:
372 ether_addr_copy(pwlanhdr->addr1, StaAddr);
373 ether_addr_copy(pwlanhdr->addr2, myid(&(adapt->eeprompriv)));
374 ether_addr_copy(pwlanhdr->addr3, pnetwork->MacAddress);
375 break;
376 }
377
378 SetSeqNum(pwlanhdr, 0);
379
380 if (bQoS) {
381 struct ieee80211_qos_hdr *pwlanqoshdr;
382
383 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
384
385 pwlanqoshdr = (struct ieee80211_qos_hdr *)pframe;
386 SetPriority(&pwlanqoshdr->qos_ctrl, AC);
387 SetEOSP(&pwlanqoshdr->qos_ctrl, bEosp);
388
389 pktlen = sizeof(struct ieee80211_qos_hdr);
390 } else {
391 SetFrameSubType(pframe, WIFI_DATA_NULL);
392
393 pktlen = sizeof(struct ieee80211_hdr_3addr);
394 }
395
396 *pLength = pktlen;
397 }
398
ConstructProbeRsp(struct adapter * adapt,u8 * pframe,u32 * pLength,u8 * StaAddr,bool bHideSSID)399 static void ConstructProbeRsp(struct adapter *adapt, u8 *pframe, u32 *pLength, u8 *StaAddr, bool bHideSSID)
400 {
401 struct ieee80211_hdr *pwlanhdr;
402 __le16 *fctrl;
403 u8 *mac, *bssid;
404 u32 pktlen;
405 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
406 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
407 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
408
409 pwlanhdr = (struct ieee80211_hdr *)pframe;
410
411 mac = myid(&(adapt->eeprompriv));
412 bssid = cur_network->MacAddress;
413
414 fctrl = &pwlanhdr->frame_control;
415 *(fctrl) = 0;
416 ether_addr_copy(pwlanhdr->addr1, StaAddr);
417 ether_addr_copy(pwlanhdr->addr2, mac);
418 ether_addr_copy(pwlanhdr->addr3, bssid);
419
420 SetSeqNum(pwlanhdr, 0);
421 SetFrameSubType(fctrl, WIFI_PROBERSP);
422
423 pktlen = sizeof(struct ieee80211_hdr_3addr);
424 pframe += pktlen;
425
426 if (cur_network->IELength > MAX_IE_SZ)
427 return;
428
429 memcpy(pframe, cur_network->IEs, cur_network->IELength);
430 pframe += cur_network->IELength;
431 pktlen += cur_network->IELength;
432
433 *pLength = pktlen;
434 }
435
436 /* */
437 /* Description: Fill the reserved packets that FW will use to RSVD page. */
438 /* Now we just send 4 types packet to rsvd page. */
439 /* (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. */
440 /* Input: */
441 /* bDLFinished - false: At the first time we will send all the packets as a large packet to Hw, */
442 /* so we need to set the packet length to total length. */
443 /* true: At the second time, we should send the first packet (default:beacon) */
444 /* to Hw again and set the length in descriptor to the real beacon length. */
445 /* 2009.10.15 by tynli. */
SetFwRsvdPagePkt(struct adapter * adapt,bool bDLFinished)446 static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished)
447 {
448 struct xmit_frame *pmgntframe;
449 struct pkt_attrib *pattrib;
450 struct xmit_priv *pxmitpriv;
451 struct mlme_ext_priv *pmlmeext;
452 struct mlme_ext_info *pmlmeinfo;
453 u32 BeaconLength = 0, ProbeRspLength = 0, PSPollLength;
454 u32 NullDataLength, QosNullLength;
455 u8 *ReservedPagePacket;
456 u8 PageNum, PageNeed, TxDescLen;
457 u16 BufIndex;
458 u32 TotalPacketLen;
459 struct rsvdpage_loc RsvdPageLoc;
460 struct wlan_bssid_ex *pnetwork;
461
462 DBG_88E("%s\n", __func__);
463 ReservedPagePacket = kzalloc(1000, GFP_KERNEL);
464 if (!ReservedPagePacket) {
465 DBG_88E("%s: alloc ReservedPagePacket fail!\n", __func__);
466 return;
467 }
468
469 pxmitpriv = &adapt->xmitpriv;
470 pmlmeext = &adapt->mlmeextpriv;
471 pmlmeinfo = &pmlmeext->mlmext_info;
472 pnetwork = &(pmlmeinfo->network);
473
474 TxDescLen = TXDESC_SIZE;
475 PageNum = 0;
476
477 /* 3 (1) beacon * 2 pages */
478 BufIndex = TXDESC_OFFSET;
479 ConstructBeacon(adapt, &ReservedPagePacket[BufIndex], &BeaconLength);
480
481 /* When we count the first page size, we need to reserve description size for the RSVD */
482 /* packet, it will be filled in front of the packet in TXPKTBUF. */
483 PageNeed = (u8)PageNum_128(TxDescLen + BeaconLength);
484 /* To reserved 2 pages for beacon buffer. 2010.06.24. */
485 if (PageNeed == 1)
486 PageNeed += 1;
487 PageNum += PageNeed;
488 adapt->HalData->FwRsvdPageStartOffset = PageNum;
489
490 BufIndex += PageNeed*128;
491
492 /* 3 (2) ps-poll *1 page */
493 RsvdPageLoc.LocPsPoll = PageNum;
494 ConstructPSPoll(adapt, &ReservedPagePacket[BufIndex], &PSPollLength);
495 rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], PSPollLength, true, false);
496
497 PageNeed = (u8)PageNum_128(TxDescLen + PSPollLength);
498 PageNum += PageNeed;
499
500 BufIndex += PageNeed*128;
501
502 /* 3 (3) null data * 1 page */
503 RsvdPageLoc.LocNullData = PageNum;
504 ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex], &NullDataLength, pnetwork->MacAddress, false, 0, 0, false);
505 rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], NullDataLength, false, false);
506
507 PageNeed = (u8)PageNum_128(TxDescLen + NullDataLength);
508 PageNum += PageNeed;
509
510 BufIndex += PageNeed*128;
511
512 /* 3 (4) probe response * 1page */
513 RsvdPageLoc.LocProbeRsp = PageNum;
514 ConstructProbeRsp(adapt, &ReservedPagePacket[BufIndex], &ProbeRspLength, pnetwork->MacAddress, false);
515 rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], ProbeRspLength, false, false);
516
517 PageNeed = (u8)PageNum_128(TxDescLen + ProbeRspLength);
518 PageNum += PageNeed;
519
520 BufIndex += PageNeed*128;
521
522 /* 3 (5) Qos null data */
523 RsvdPageLoc.LocQosNull = PageNum;
524 ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex],
525 &QosNullLength, pnetwork->MacAddress, true, 0, 0, false);
526 rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], QosNullLength, false, false);
527
528 PageNeed = (u8)PageNum_128(TxDescLen + QosNullLength);
529 PageNum += PageNeed;
530
531 TotalPacketLen = BufIndex + QosNullLength;
532 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
533 if (!pmgntframe)
534 goto exit;
535
536 /* update attribute */
537 pattrib = &pmgntframe->attrib;
538 update_mgntframe_attrib(adapt, pattrib);
539 pattrib->qsel = 0x10;
540 pattrib->last_txcmdsz = TotalPacketLen - TXDESC_OFFSET;
541 pattrib->pktlen = pattrib->last_txcmdsz;
542 memcpy(pmgntframe->buf_addr, ReservedPagePacket, TotalPacketLen);
543
544 rtw_hal_mgnt_xmit(adapt, pmgntframe);
545
546 DBG_88E("%s: Set RSVD page location to Fw\n", __func__);
547 FillH2CCmd_88E(adapt, H2C_COM_RSVD_PAGE, sizeof(RsvdPageLoc), (u8 *)&RsvdPageLoc);
548
549 exit:
550 kfree(ReservedPagePacket);
551 }
552
rtl8188e_set_FwJoinBssReport_cmd(struct adapter * adapt,u8 mstatus)553 void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus)
554 {
555 struct hal_data_8188e *haldata = adapt->HalData;
556 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
557 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
558 bool bSendBeacon = false;
559 bool bcn_valid = false;
560 u8 DLBcnCount = 0;
561 u32 poll = 0;
562
563
564 DBG_88E("%s mstatus(%x)\n", __func__, mstatus);
565
566 if (mstatus == 1) {
567 /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */
568 /* Suggested by filen. Added by tynli. */
569 usb_write16(adapt, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid));
570 /* Do not set TSF again here or vWiFi beacon DMA INT will not work. */
571
572 /* Set REG_CR bit 8. DMA beacon by SW. */
573 haldata->RegCR_1 |= BIT(0);
574 usb_write8(adapt, REG_CR+1, haldata->RegCR_1);
575
576 /* Disable Hw protection for a time which revserd for Hw sending beacon. */
577 /* Fix download reserved page packet fail that access collision with the protection time. */
578 /* 2010.05.11. Added by tynli. */
579 usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(3)));
580 usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(4));
581
582 if (haldata->RegFwHwTxQCtrl & BIT(6)) {
583 DBG_88E("HalDownloadRSVDPage(): There is an Adapter is sending beacon.\n");
584 bSendBeacon = true;
585 }
586
587 /* Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame. */
588 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl&(~BIT(6))));
589 haldata->RegFwHwTxQCtrl &= (~BIT(6));
590
591 /* Clear beacon valid check bit. */
592 rtw_hal_set_hwreg(adapt, HW_VAR_BCN_VALID, NULL);
593 DLBcnCount = 0;
594 poll = 0;
595 do {
596 /* download rsvd page. */
597 SetFwRsvdPagePkt(adapt, false);
598 DLBcnCount++;
599 do {
600 yield();
601 /* mdelay(10); */
602 /* check rsvd page download OK. */
603 rtw_hal_get_hwreg(adapt, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid));
604 poll++;
605 } while (!bcn_valid && (poll%10) != 0 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped);
606 } while (!bcn_valid && DLBcnCount <= 100 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped);
607
608 if (adapt->bSurpriseRemoved || adapt->bDriverStopped)
609 ;
610 else if (!bcn_valid)
611 DBG_88E("%s: 1 Download RSVD page failed! DLBcnCount:%u, poll:%u\n", __func__, DLBcnCount, poll);
612 else
613 DBG_88E("%s: 1 Download RSVD success! DLBcnCount:%u, poll:%u\n", __func__, DLBcnCount, poll);
614 /* */
615 /* We just can send the reserved page twice during the time that Tx thread is stopped (e.g. pnpsetpower) */
616 /* because we need to free the Tx BCN Desc which is used by the first reserved page packet. */
617 /* At run time, we cannot get the Tx Desc until it is released in TxHandleInterrupt() so we will return */
618 /* the beacon TCB in the following code. 2011.11.23. by tynli. */
619 /* */
620
621 /* Enable Bcn */
622 usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(3));
623 usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(4)));
624
625 /* To make sure that if there exists an adapter which would like to send beacon. */
626 /* If exists, the origianl value of 0x422[6] will be 1, we should check this to */
627 /* prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */
628 /* the beacon cannot be sent by HW. */
629 /* 2010.06.23. Added by tynli. */
630 if (bSendBeacon) {
631 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl | BIT(6)));
632 haldata->RegFwHwTxQCtrl |= BIT(6);
633 }
634
635 /* Update RSVD page location H2C to Fw. */
636 if (bcn_valid) {
637 rtw_hal_set_hwreg(adapt, HW_VAR_BCN_VALID, NULL);
638 DBG_88E("Set RSVD page location to Fw.\n");
639 }
640
641 /* Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli. */
642 /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
643 haldata->RegCR_1 &= (~BIT(0));
644 usb_write8(adapt, REG_CR+1, haldata->RegCR_1);
645 }
646 }
647