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