Merge tag 'nfs-for-3.14-3' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / rtl8821ae / rtl8821ae / fw.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2010  Realtek Corporation.
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <wlanfae@realtek.com>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <Larry.Finger@lwfinger.net>
27  *
28  *****************************************************************************/
29
30 #include "../wifi.h"
31 #include "../pci.h"
32 #include "../base.h"
33 #include "reg.h"
34 #include "def.h"
35 #include "fw.h"
36 #include "dm.h"
37
38 static void _rtl8821ae_enable_fw_download(struct ieee80211_hw *hw, bool enable)
39 {
40         struct rtl_priv *rtlpriv = rtl_priv(hw);
41         u8 tmp;
42
43         if (enable) {
44                 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x05);
45
46                 tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL + 2);
47                 rtl_write_byte(rtlpriv, REG_MCUFWDL + 2, tmp & 0xf7);
48
49                 tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
50                 //printk("0x80=%02x.\n",tmp);
51         } else {
52                 tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
53                 rtl_write_byte(rtlpriv, REG_MCUFWDL, tmp & 0xfe);
54                 tmp = rtl_read_byte(rtlpriv, REG_MCUFWDL);
55                 //printk("0x80=%02x.\n",tmp);
56         }
57
58 }
59
60 static void _rtl8821ae_fw_block_write(struct ieee80211_hw *hw,
61                                    const u8 *buffer, u32 size)
62 {
63         struct rtl_priv *rtlpriv = rtl_priv(hw);
64         u32 blockSize = sizeof(u32);
65         u8 *bufferPtr = (u8 *) buffer;
66         u32 *pu4BytePtr = (u32 *) buffer;
67         u32 i, offset, blockCount, remainSize;
68
69         blockCount = size / blockSize;
70         remainSize = size % blockSize;
71
72         for (i = 0; i < blockCount; i++) {
73                 offset = i * blockSize;
74                 rtl_write_dword(rtlpriv, (FW_8821AE_START_ADDRESS + offset),
75                                 *(pu4BytePtr + i));
76         }
77
78         if (remainSize) {
79                 offset = blockCount * blockSize;
80                 bufferPtr += offset;
81                 for (i = 0; i < remainSize; i++) {
82                         rtl_write_byte(rtlpriv, (FW_8821AE_START_ADDRESS +
83                                                  offset + i), *(bufferPtr + i));
84                 }
85         }
86 }
87
88 static void _rtl8821ae_fw_page_write(struct ieee80211_hw *hw,
89                                   u32 page, const u8 *buffer, u32 size)
90 {
91         struct rtl_priv *rtlpriv = rtl_priv(hw);
92         u8 value8;
93         u8 u8page = (u8) (page & 0x07);
94
95         value8 = (rtl_read_byte(rtlpriv, REG_MCUFWDL + 2) & 0xF8) | u8page;
96
97         rtl_write_byte(rtlpriv, (REG_MCUFWDL + 2), value8);
98         _rtl8821ae_fw_block_write(hw, buffer, size);
99 }
100
101 static void _rtl8821ae_fill_dummy(u8 *pfwbuf, u32 *pfwlen)
102 {
103         u32 fwlen = *pfwlen;
104         u8 remain = (u8) (fwlen % 4);
105
106         remain = (remain == 0) ? 0 : (4 - remain);
107
108         while (remain > 0) {
109                 pfwbuf[fwlen] = 0;
110                 fwlen++;
111                 remain--;
112         }
113
114         *pfwlen = fwlen;
115 }
116
117 static void _rtl8821ae_write_fw(struct ieee80211_hw *hw,
118                                                                   enum version_8821ae version,
119                                                                   u8 *buffer, u32 size)
120 {
121         struct rtl_priv *rtlpriv = rtl_priv(hw);
122         u8 *bufferPtr = (u8 *) buffer;
123         u32 pageNums, remainSize;
124         u32 page, offset;
125
126         RT_TRACE(COMP_FW, DBG_LOUD, ("FW size is %d bytes,\n", size));
127
128         _rtl8821ae_fill_dummy(bufferPtr, &size);
129
130         pageNums = size / FW_8821AE_PAGE_SIZE;
131         remainSize = size % FW_8821AE_PAGE_SIZE;
132
133         if (pageNums > 8) {
134                 RT_TRACE(COMP_ERR, DBG_EMERG,
135                          ("Page numbers should not greater then 8\n"));
136         }
137
138         for (page = 0; page < pageNums; page++) {
139                 offset = page * FW_8821AE_PAGE_SIZE;
140                 _rtl8821ae_fw_page_write(hw, page, (bufferPtr + offset),
141                                       FW_8821AE_PAGE_SIZE);
142         }
143
144         if (remainSize) {
145                 offset = pageNums * FW_8821AE_PAGE_SIZE;
146                 page = pageNums;
147                 _rtl8821ae_fw_page_write(hw, page, (bufferPtr + offset),
148                                       remainSize);
149         }
150
151 }
152
153 static int _rtl8821ae_fw_free_to_go(struct ieee80211_hw *hw)
154 {
155         struct rtl_priv *rtlpriv = rtl_priv(hw);
156         int err = -EIO;
157         u32 counter = 0;
158         u32 value32;
159
160         do {
161                 value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
162         } while ((counter++ < FW_8821AE_POLLING_TIMEOUT_COUNT) &&
163                  (!(value32 & FWDL_CHKSUM_RPT)));
164
165         if (counter >= FW_8821AE_POLLING_TIMEOUT_COUNT) {
166                 RT_TRACE(COMP_ERR, DBG_LOUD,
167                          ("chksum report faill ! REG_MCUFWDL:0x%08x .\n",
168                           value32));
169                 goto exit;
170         }
171
172         RT_TRACE(COMP_FW, DBG_EMERG,
173                  ("Checksum report OK ! REG_MCUFWDL:0x%08x .\n", value32));
174
175         value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
176         value32 |= MCUFWDL_RDY;
177         value32 &= ~WINTINI_RDY;
178         rtl_write_dword(rtlpriv, REG_MCUFWDL, value32);
179
180         rtl8821ae_firmware_selfreset(hw);
181
182         counter = 0;
183         do {
184                 value32 = rtl_read_dword(rtlpriv, REG_MCUFWDL);
185                 if (value32 & WINTINI_RDY) {
186                         RT_TRACE(COMP_FW, DBG_LOUD,
187                                  ("Polling FW ready success!! REG_MCUFWDL:0x%08x .\n",
188                                   value32));
189                         err = 0;
190                         goto exit;
191                 }
192
193                 udelay(FW_8821AE_POLLING_DELAY);
194
195         } while (counter++ < FW_8821AE_POLLING_TIMEOUT_COUNT);
196
197         RT_TRACE(COMP_ERR, DBG_EMERG,
198                  ("Polling FW ready fail!! REG_MCUFWDL:0x%08x .\n", value32));
199
200 exit:
201         return err;
202 }
203
204 int rtl8821ae_download_fw(struct ieee80211_hw *hw,
205         bool buse_wake_on_wlan_fw
206         )
207 {
208         struct rtl_priv *rtlpriv = rtl_priv(hw);
209         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
210         struct rtl8821a_firmware_header *pfwheader;
211         u8 *pfwdata;
212         u32 fwsize;
213         int err;
214         enum version_8821ae version = rtlhal->version;
215
216         if(!rtlhal->pfirmware)
217                 return 1;
218
219         pfwheader = (struct rtl8821a_firmware_header *)rtlhal->pfirmware;
220         pfwdata = (u8 *) rtlhal->pfirmware;
221         fwsize = rtlhal->fwsize;
222         RT_TRACE(COMP_FW, DBG_DMESG,
223                  ("normal Firmware SIZE %d \n",fwsize));
224
225         if (IS_FW_HEADER_EXIST_8812(pfwheader) || IS_FW_HEADER_EXIST_8821(pfwheader)) {
226                 RT_TRACE(COMP_FW, DBG_DMESG,
227                          ("Firmware Version(%d), Signature(%#x),Size(%d)\n",
228                           pfwheader->version, pfwheader->signature,
229                           (int)sizeof(struct rtl8821a_firmware_header)));
230
231                 pfwdata = pfwdata + sizeof(struct rtl8821a_firmware_header);
232                 fwsize = fwsize - sizeof(struct rtl8821a_firmware_header);
233         }
234
235         if(rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)){
236                 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
237                 rtl8821ae_firmware_selfreset(hw);
238         }
239         _rtl8821ae_enable_fw_download(hw, true);
240         _rtl8821ae_write_fw(hw, version, pfwdata, fwsize);
241         _rtl8821ae_enable_fw_download(hw, false);
242
243         err = _rtl8821ae_fw_free_to_go(hw);
244         if (err) {
245                 RT_TRACE(COMP_ERR, DBG_EMERG,
246                          ("Firmware is not ready to run!\n"));
247         } else {
248                 RT_TRACE(COMP_FW, DBG_LOUD,
249                          ("Firmware is ready to run!\n"));
250         }
251
252         return 0;
253 }
254
255 static bool _rtl8821ae_check_fw_read_last_h2c(struct ieee80211_hw *hw, u8 boxnum)
256 {
257         struct rtl_priv *rtlpriv = rtl_priv(hw);
258         u8 val_hmetfr;
259         bool result = false;
260
261         val_hmetfr = rtl_read_byte(rtlpriv, REG_HMETFR);
262         if (((val_hmetfr >> boxnum) & BIT(0)) == 0)
263                 result = true;
264         return result;
265 }
266
267 static void _rtl8821ae_fill_h2c_command(struct ieee80211_hw *hw,
268                               u8 element_id, u32 cmd_len, u8 *p_cmdbuffer)
269 {
270         struct rtl_priv *rtlpriv = rtl_priv(hw);
271         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
272         u8 boxnum =0;
273         u16 box_reg = 0, box_extreg = 0;
274         u8 u1b_tmp = 0;
275         bool isfw_read = false;
276         u8 buf_index = 0;
277         bool bwrite_sucess = false;
278         u8 wait_h2c_limmit = 100;
279         /*u8 wait_writeh2c_limmit = 100;*/
280         u8 boxcontent[4], boxextcontent[4];
281         u32 h2c_waitcounter = 0;
282         unsigned long flag =0;
283         u8 idx =0;
284
285         RT_TRACE(COMP_CMD, DBG_LOUD, ("come in\n"));
286
287         while (true) {
288                 spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
289                 if (rtlhal->b_h2c_setinprogress) {
290                         RT_TRACE(COMP_CMD, DBG_LOUD,
291                                  ("H2C set in progress! Wait to set.."
292                                   "element_id(%d).\n", element_id));
293
294                         while (rtlhal->b_h2c_setinprogress) {
295                                 spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock,
296                                                        flag);
297                                 h2c_waitcounter++;
298                                 RT_TRACE(COMP_CMD, DBG_LOUD,
299                                          ("Wait 100 us (%d times)...\n",
300                                           h2c_waitcounter));
301                                 udelay(100);
302
303                                 if (h2c_waitcounter > 1000)
304                                         return;
305                                 spin_lock_irqsave(&rtlpriv->locks.h2c_lock,
306                                                   flag);
307                         }
308                         spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
309                 } else {
310                         rtlhal->b_h2c_setinprogress = true;
311                         spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
312                         break;
313                 }
314         }
315
316         while (!bwrite_sucess) {
317         /*cosa remove this because never reach this.*/
318 #if 0
319                 wait_writeh2c_limmit--;
320                 if (wait_writeh2c_limmit == 0) {
321                         RT_TRACE(COMP_ERR, DBG_EMERG,
322                                  ("Write H2C fail because no trigger "
323                                   "for FW INT!\n"));
324                         break;
325                 }
326 #endif
327
328                 boxnum = rtlhal->last_hmeboxnum;
329                 switch (boxnum) {
330                 case 0:
331                         box_reg = REG_HMEBOX_0;
332                         box_extreg = REG_HMEBOX_EXT_0;
333                         break;
334                 case 1:
335                         box_reg = REG_HMEBOX_1;
336                         box_extreg = REG_HMEBOX_EXT_1;
337                         break;
338                 case 2:
339                         box_reg = REG_HMEBOX_2;
340                         box_extreg = REG_HMEBOX_EXT_2;
341                         break;
342                 case 3:
343                         box_reg = REG_HMEBOX_3;
344                         box_extreg = REG_HMEBOX_EXT_3;
345                         break;
346                 default:
347                         RT_TRACE(COMP_ERR, DBG_EMERG,
348                                  ("switch case not process \n"));
349                         break;
350                 }
351
352                 isfw_read = false;
353                 u1b_tmp = rtl_read_byte(rtlpriv, REG_CR);
354
355                 if (u1b_tmp != 0xEA)
356                         isfw_read = true;
357                 else {
358                         if( rtl_read_byte(rtlpriv, REG_TXDMA_STATUS) == 0xEA ||
359                                 rtl_read_byte(rtlpriv, REG_TXPKT_EMPTY) == 0xEA)
360                                 rtl_write_byte(rtlpriv, REG_SYS_CFG1 + 3, 0xFF);
361                 }
362
363                 if (isfw_read == true) {
364                         wait_h2c_limmit = 100;
365                         isfw_read = _rtl8821ae_check_fw_read_last_h2c(hw, boxnum);
366                         while (!isfw_read) {
367                                 /*wait until Fw read*/
368                                 wait_h2c_limmit--;
369                                 if (wait_h2c_limmit == 0) {
370                                         RT_TRACE(COMP_CMD, DBG_LOUD,
371                                                  ("Wating too long for FW read "
372                                                   "clear HMEBox(%d)!\n", boxnum));
373                                         break;
374                                 }
375
376                                 udelay(10);
377
378                                 isfw_read = _rtl8821ae_check_fw_read_last_h2c(hw, boxnum);
379                                 u1b_tmp = rtl_read_byte(rtlpriv, 0x130);
380                                 RT_TRACE(COMP_CMD, DBG_LOUD,
381                                          ("Wating for FW read clear HMEBox(%d)!!! "
382                                           "0x130 = %2x\n", boxnum, u1b_tmp));
383                         }
384                 }
385
386                 if (!isfw_read) {
387                         RT_TRACE(COMP_CMD, DBG_LOUD,
388                                  ("Write H2C register BOX[%d] fail!!!!! "
389                                   "Fw do not read. \n", boxnum));
390                         break;
391                 }
392
393                 memset(boxcontent, 0, sizeof(boxcontent));
394                 memset(boxextcontent, 0, sizeof(boxextcontent));
395                 boxcontent[0] = element_id;
396                 RT_TRACE(COMP_CMD, DBG_LOUD,
397                          ("Write element_id box_reg(%4x) = %2x \n",
398                           box_reg, element_id));
399
400                 switch (cmd_len) {
401                 case 1:
402                 case 2:
403                 case 3:
404                         /*boxcontent[0] &= ~(BIT(7));*/
405                         memcpy((u8 *) (boxcontent) + 1,
406                                p_cmdbuffer + buf_index, cmd_len);
407
408                         for (idx = 0; idx < 4; idx++) {
409                                 rtl_write_byte(rtlpriv, box_reg + idx,
410                                                boxcontent[idx]);
411                         }
412                         break;
413                 case 4:
414                 case 5:
415                 case 6:
416                 case 7:
417                         /*boxcontent[0] |= (BIT(7));*/
418                         memcpy((u8 *) (boxextcontent),
419                                p_cmdbuffer + buf_index+3, cmd_len-3);
420                         memcpy((u8 *) (boxcontent) + 1,
421                                p_cmdbuffer + buf_index, 3);
422
423                         for (idx = 0; idx < 4; idx++) {
424                                 rtl_write_byte(rtlpriv, box_extreg + idx,
425                                                boxextcontent[idx]);
426                         }
427
428                         for (idx = 0; idx < 4; idx++) {
429                                 rtl_write_byte(rtlpriv, box_reg + idx,
430                                                boxcontent[idx]);
431                         }
432                         break;
433                 default:
434                         RT_TRACE(COMP_ERR, DBG_EMERG,
435                                  ("switch case not process \n"));
436                         break;
437                 }
438
439                 bwrite_sucess = true;
440
441                 rtlhal->last_hmeboxnum = boxnum + 1;
442                 if (rtlhal->last_hmeboxnum == 4)
443                         rtlhal->last_hmeboxnum = 0;
444
445                 RT_TRACE(COMP_CMD, DBG_LOUD,
446                          ("pHalData->last_hmeboxnum  = %d\n",
447                           rtlhal->last_hmeboxnum));
448         }
449
450         spin_lock_irqsave(&rtlpriv->locks.h2c_lock, flag);
451         rtlhal->b_h2c_setinprogress = false;
452         spin_unlock_irqrestore(&rtlpriv->locks.h2c_lock, flag);
453
454         RT_TRACE(COMP_CMD, DBG_LOUD, ("go out\n"));
455 }
456
457 void rtl8821ae_fill_h2c_cmd(struct ieee80211_hw *hw,
458                          u8 element_id, u32 cmd_len, u8 *p_cmdbuffer)
459 {
460         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
461         u32 tmp_cmdbuf[2];
462
463         if (rtlhal->bfw_ready == false) {
464                 RT_ASSERT(false, ("return H2C cmd because of Fw "
465                                   "download fail!!!\n"));
466                 return;
467         }
468
469         memset(tmp_cmdbuf, 0, 8);
470         memcpy(tmp_cmdbuf, p_cmdbuffer, cmd_len);
471         _rtl8821ae_fill_h2c_command(hw, element_id, cmd_len, (u8 *) & tmp_cmdbuf);
472
473         return;
474 }
475
476 void rtl8821ae_firmware_selfreset(struct ieee80211_hw *hw)
477 {
478         u8 u1b_tmp;
479         struct rtl_priv *rtlpriv = rtl_priv(hw);
480         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
481
482         if(rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
483         {
484                 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
485                 rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp & (~BIT(3))));
486         }else {
487                 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
488                 rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp & (~BIT(0))));
489         }
490
491         u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
492         rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1b_tmp & (~BIT(2))));
493         udelay(50);
494
495         if(rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE)
496         {
497                 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
498                 rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp | BIT(3)));
499         }else {
500                 u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
501                 rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp | BIT(0)));
502         }
503
504         u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
505         rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1b_tmp | BIT(2)));
506
507         RT_TRACE(COMP_INIT, DBG_LOUD, ("  _8051Reset8812ae(): 8051 reset success .\n"));
508
509 }
510
511 void rtl8821ae_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode)
512 {
513         struct rtl_priv *rtlpriv = rtl_priv(hw);
514         u8 u1_h2c_set_pwrmode[H2C_8821AE_PWEMODE_LENGTH] = { 0 };
515         struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
516         u8 rlbm,power_state = 0;
517         RT_TRACE(COMP_POWER, DBG_LOUD, ("FW LPS mode = %d\n", mode));
518
519         SET_H2CCMD_PWRMODE_PARM_MODE(u1_h2c_set_pwrmode, ((mode) ? 1 : 0));
520         rlbm = 0;/*YJ,temp,120316. FW now not support RLBM=2.*/
521         SET_H2CCMD_PWRMODE_PARM_RLBM(u1_h2c_set_pwrmode, rlbm);
522         SET_H2CCMD_PWRMODE_PARM_SMART_PS(u1_h2c_set_pwrmode, (rtlpriv->mac80211.p2p) ? ppsc->smart_ps : 1);
523         SET_H2CCMD_PWRMODE_PARM_AWAKE_INTERVAL(u1_h2c_set_pwrmode, ppsc->reg_max_lps_awakeintvl);
524         SET_H2CCMD_PWRMODE_PARM_ALL_QUEUE_UAPSD(u1_h2c_set_pwrmode, 0);
525         if(mode == FW_PS_ACTIVE_MODE)
526         {
527                 power_state |= FW_PWR_STATE_ACTIVE;
528         }
529         else
530         {
531                 power_state |= FW_PWR_STATE_RF_OFF;
532         }
533         SET_H2CCMD_PWRMODE_PARM_PWR_STATE(u1_h2c_set_pwrmode, power_state);
534
535         RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
536                       "rtl92c_set_fw_pwrmode(): u1_h2c_set_pwrmode \n",
537                       u1_h2c_set_pwrmode, H2C_8821AE_PWEMODE_LENGTH);
538         rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_SETPWRMODE, H2C_8821AE_PWEMODE_LENGTH, u1_h2c_set_pwrmode);
539
540 }
541
542 void rtl8821ae_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus)
543 {
544         u8 u1_joinbssrpt_parm[1] = { 0 };
545
546         SET_H2CCMD_JOINBSSRPT_PARM_OPMODE(u1_joinbssrpt_parm, mstatus);
547
548         rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_JOINBSSRPT, 1, u1_joinbssrpt_parm);
549 }
550
551 void rtl8821ae_set_fw_ap_off_load_cmd(struct ieee80211_hw *hw,  u8 ap_offload_enable)
552 {
553         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
554         u8 u1_apoffload_parm[H2C_8821AE_AP_OFFLOAD_LENGTH] = { 0 };
555
556         SET_H2CCMD_AP_OFFLOAD_ON(u1_apoffload_parm, ap_offload_enable);
557         SET_H2CCMD_AP_OFFLOAD_HIDDEN(u1_apoffload_parm, mac->bhiddenssid);
558         SET_H2CCMD_AP_OFFLOAD_DENYANY(u1_apoffload_parm, 0);
559
560         rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_AP_OFFLOAD, H2C_8821AE_AP_OFFLOAD_LENGTH, u1_apoffload_parm);
561
562 }
563
564 static bool _rtl8821ae_cmd_send_packet(struct ieee80211_hw *hw,
565                                 struct sk_buff *skb)
566 {
567         struct rtl_priv *rtlpriv = rtl_priv(hw);
568         struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
569         struct rtl8192_tx_ring *ring;
570         struct rtl_tx_desc *pdesc;
571         u8 own;
572         unsigned long flags;
573         struct sk_buff *pskb = NULL;
574
575         ring = &rtlpci->tx_ring[BEACON_QUEUE];
576
577         pskb = __skb_dequeue(&ring->queue);
578         if (pskb)
579                 kfree_skb(pskb);
580
581         spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
582
583         pdesc = &ring->desc[0];
584         own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc, true, HW_DESC_OWN);
585
586         rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *) pdesc, 1, 1, skb);
587
588         __skb_queue_tail(&ring->queue, skb);
589
590         spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
591
592         rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE);
593
594         return true;
595 }
596
597 #define BEACON_PG               0 /* ->1 */
598 #define PSPOLL_PG               2
599 #define NULL_PG                 3
600 #define PROBERSP_PG             4 /* ->5 */
601
602 #define BEACON_PG_8812          0
603 #define PSPOLL_PG_8812          1
604 #define NULL_PG_8812                    2
605 #define PROBERSP_PG_8812                3
606
607 #define BEACON_PG_8821          0
608 #define PSPOLL_PG_8821          1
609 #define NULL_PG_8821                    2
610 #define PROBERSP_PG_8821                3
611
612 #define TOTAL_RESERVED_PKT_LEN_8812     2048
613 #define TOTAL_RESERVED_PKT_LEN_8821     1024
614
615
616 static u8 reserved_page_packet_8821[TOTAL_RESERVED_PKT_LEN_8821] = {
617         /* page 0 */
618         0x80, 0x00, 0x00, 0x00,  0xff, 0xff, 0xff, 0xff,
619         0xff, 0xff, 0x00, 0xe0,  0x4c, 0x02, 0xe2, 0x64,
620         0x40, 0x16, 0x9f, 0x23,  0xd4, 0x46, 0x20, 0x00,
621         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
622         0x64, 0x00, 0x20, 0x04,  0x00, 0x06, 0x64, 0x6c,
623         0x69, 0x6e, 0x6b, 0x31,  0x01, 0x08, 0x82, 0x84,
624         0x8b, 0x96, 0x0c, 0x18,  0x30, 0x48, 0x03, 0x01,
625         0x0b, 0x06, 0x02, 0x00,  0x00, 0x2a, 0x01, 0x8b,
626         0x32, 0x04, 0x12, 0x24,  0x60, 0x6c, 0x00, 0x00,
627         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
628         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
629         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
630         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
631         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
632         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
633         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
634         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
635         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
636         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
637         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
638         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
639         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
640         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
641         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
642         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
643         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
644         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
645         0x10, 0x00, 0x28, 0x8c,  0x00, 0x12, 0x00, 0x00,
646         0x00, 0x00, 0x00, 0x00,  0x00, 0x81, 0x00, 0x00,
647         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
648         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
649         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
650         /* page 1 */
651         0xa4, 0x10, 0x01, 0xc0,  0x40, 0x16, 0x9f, 0x23,
652         0xd4, 0x46, 0x00, 0xe0,  0x4c, 0x02, 0xe2, 0x64,
653         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
654         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
655         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
656         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
657         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
658         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
659         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
660         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
661         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
662         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
663         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
664         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
665         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
666         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
667         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
668         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
669         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
670         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
671         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
672         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
673         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
674         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
675         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
676         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
677         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
678         0x18, 0x00, 0x28, 0x8c,  0x00, 0x12, 0x00, 0x00,
679         0x00, 0x00, 0x00, 0x00,  0x00, 0x01, 0x00, 0x00,
680         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
681         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
682         0x00, 0x80, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
683         /* page 2 */
684         0x48, 0x01, 0x00, 0x00,  0x40, 0x16, 0x9f, 0x23,
685         0xd4, 0x46, 0x00, 0xe0,  0x4c, 0x02, 0xe2, 0x64,
686         0x40, 0x16, 0x9f, 0x23,  0xd4, 0x46, 0x00, 0x00,
687         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
688         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
689         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
690         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
691         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
692         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
693         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
694         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
695         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
696         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
697         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
698         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
699         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
700         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
701         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
702         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
703         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
704         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
705         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
706         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
707         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
708         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
709         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
710         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
711         0x1a, 0x00, 0x28, 0x8c,  0x00, 0x12, 0x00, 0x00,
712         0x00, 0x00, 0x00, 0x00,  0x00, 0x01, 0x00, 0x00,
713         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
714         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
715         0x00, 0x80, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
716         /* page 3 */
717         0xc8, 0x01, 0x00, 0x00,  0x40, 0x16, 0x9f, 0x23,
718         0xd4, 0x46, 0x00, 0xe0,  0x4c, 0x02, 0xe2, 0x64,
719         0x40, 0x16, 0x9f, 0x23,  0xd4, 0x46, 0x00, 0x00,
720         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
721         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
722         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
723         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
724         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
725         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
726         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
727         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
728         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
729         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
730         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
731         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
732         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
733         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
734         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
735         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
736         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
737         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
738         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
739         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
740         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
741         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
742         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
743         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
744         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
745         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
746         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
747         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
748         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
749 };
750
751
752 static u8 reserved_page_packet_8812[TOTAL_RESERVED_PKT_LEN_8812] = {
753         0x80, 0x00, 0x00, 0x00,  0xFF, 0xFF, 0xFF, 0xFF,
754         0xFF, 0xFF, 0x00, 0xE0,  0x4C, 0x02, 0x53, 0xE5,
755         0xE0, 0x46, 0x9A, 0x57,  0x71, 0x30, 0x20, 0x00,
756         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
757         0x64, 0x00, 0x30, 0x04,  0x00, 0x0C, 0x4E, 0x45,
758         0x54, 0x47, 0x45, 0x41,  0x52, 0x5F, 0x31, 0x35,
759         0x30, 0x4E, 0x01, 0x08,  0x82, 0x84, 0x8B, 0x96,
760         0x0C, 0x12, 0x18, 0x24,  0x03, 0x01, 0x03, 0x06,
761         0x02, 0x00, 0x00, 0x2A,  0x01, 0x8A, 0x32, 0x04,
762         0x30, 0x48, 0x60, 0x6C,  0xDD, 0x18, 0x00, 0x50,
763         0xF2, 0x01, 0x01, 0x00,  0x00, 0x50, 0xF2, 0x02,
764         0x01, 0x00, 0x00, 0x50,  0xF2, 0x02, 0x01, 0x00,
765         0x00, 0x50, 0xF2, 0x02,  0x00, 0x00, 0x00, 0x00,
766         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
767         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
768         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
769         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
770         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
771         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
772         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
773         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
774         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
775         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
776         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
777         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
778         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
779         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
780         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
781         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
782         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
783         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
784         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
785         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
786         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
787         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
788         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
789         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
790         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
791         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
792         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
793         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
794         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
795         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
796         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
797         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
798         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
799         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
800         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
801         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
802         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
803         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
804         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
805         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
806         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
807         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
808         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
809         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
810         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
811         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
812         0x10, 0x00, 0x28, 0x8C,  0x00, 0x12, 0x00, 0x00,
813         0x00, 0x00, 0x00, 0x00,  0x00, 0x81, 0x00, 0x00,
814         0x04, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
815         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
816         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
817
818         0xA4, 0x10, 0x02, 0xC0,  0xE0, 0x46, 0x9A, 0x57,
819         0x71, 0x30, 0x00, 0xE0,  0x4C, 0x02, 0x53, 0xE5,
820         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
821         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
822         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
823         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
824         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
825         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
826         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
827         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
828         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
829         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
830         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
831         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
832         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
833         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
834         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
835         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
836         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
837         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
838         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
839         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
840         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
841         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
842         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
843         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
844         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
845         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
846         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
847         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
848         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
849         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
850         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
851         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
852         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
853         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
854         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
855         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
856         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
857         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
858         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
859         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
860         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
861         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
862         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
863         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
864         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
865         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
866         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
867         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
868         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
869         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
870         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
871         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
872         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
873         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
874         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
875         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
876         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
877         0x18, 0x00, 0x28, 0x8C,  0x00, 0x12, 0x00, 0x00,
878         0x00, 0x00, 0x00, 0x00,  0x00, 0x01, 0x00, 0x00,
879         0x04, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
880         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
881         0x00, 0x80, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
882
883         0x48, 0x01, 0x00, 0x00,  0xE0, 0x46, 0x9A, 0x57,
884         0x71, 0x30, 0x00, 0xE0,  0x4C, 0x02, 0x53, 0xE5,
885         0xE0, 0x46, 0x9A, 0x57,  0x71, 0x30, 0x00, 0x00,
886         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
887         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
888         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
889         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
890         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
891         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
892         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
893         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
894         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
895         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
896         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
897         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
898         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
899         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
900         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
901         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
902         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
903         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
904         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
905         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
906         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
907         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
908         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
909         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
910         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
911         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
912         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
913         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
914         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
915         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
916         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
917         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
918         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
919         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
920         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
921         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
922         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
923         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
924         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
925         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
926         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
927         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
928         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
929         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
930         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
931         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
932         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
933         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
934         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
935         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
936         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
937         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
938         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
939         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
940         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
941         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
942         0x1A, 0x00, 0x28, 0x8C,  0x00, 0x12, 0x00, 0x00,
943         0x00, 0x00, 0x00, 0x00,  0x00, 0x01, 0x00, 0x00,
944         0x04, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
945         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
946         0x00, 0x80, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
947
948         0xC8, 0x01, 0x00, 0x00,  0xE0, 0x46, 0x9A, 0x57,
949         0x71, 0x30, 0x00, 0xE0,  0x4C, 0x02, 0x53, 0xE5,
950         0xE0, 0x46, 0x9A, 0x57,  0x71, 0x30, 0x00, 0x00,
951         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
952         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
953         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
954         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
955         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
956         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
957         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
958         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
959         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
960         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
961         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
962         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
963         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
964         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
965         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
966         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
967         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
968         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
969         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
970         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
971         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
972         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
973         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
974         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
975         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
976         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
977         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
978         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
979         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
980         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
981         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
982         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
983         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
984         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
985         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
986         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
987         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
988         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
989         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
990         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
991         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
992         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
993         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
994         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
995         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
996         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
997         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
998         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
999         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1000         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1001         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1002         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1003         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1004         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1005         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1006         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1007         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1008         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1009         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1010         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1011         0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00,
1012 };
1013
1014 void rtl8812ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
1015 {
1016         struct rtl_priv *rtlpriv = rtl_priv(hw);
1017         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1018         struct sk_buff *skb = NULL;
1019
1020         u32 totalpacketlen;
1021         bool rtstatus;
1022         u8 u1RsvdPageLoc[5] = { 0 };
1023         bool b_dlok = false;
1024
1025         u8* beacon;
1026         u8* p_pspoll;
1027         u8* nullfunc;
1028         u8* p_probersp;
1029         /*---------------------------------------------------------
1030                                 (1) beacon
1031         ---------------------------------------------------------*/
1032         beacon = &reserved_page_packet_8812[BEACON_PG_8812 * 512];
1033         SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr);
1034         SET_80211_HDR_ADDRESS3(beacon, mac->bssid);
1035
1036         /*-------------------------------------------------------
1037                                 (2) ps-poll
1038         --------------------------------------------------------*/
1039         p_pspoll = &reserved_page_packet_8812[PSPOLL_PG_8812 * 512];
1040         SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000));
1041         SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid);
1042         SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr);
1043
1044         SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1RsvdPageLoc, PSPOLL_PG_8812);
1045
1046         /*--------------------------------------------------------
1047                                 (3) null data
1048         ---------------------------------------------------------*/
1049         nullfunc = &reserved_page_packet_8812[NULL_PG_8812* 512];
1050         SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid);
1051         SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr);
1052         SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid);
1053
1054         SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1RsvdPageLoc, NULL_PG_8812);
1055
1056         /*---------------------------------------------------------
1057                                 (4) probe response
1058         ----------------------------------------------------------*/
1059         p_probersp = &reserved_page_packet_8812[PROBERSP_PG_8812 * 512];
1060         SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid);
1061         SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr);
1062         SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid);
1063
1064         SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1RsvdPageLoc, PROBERSP_PG_8812);
1065
1066         totalpacketlen = TOTAL_RESERVED_PKT_LEN_8812;
1067
1068         RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
1069                       "rtl8821ae_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL \n",
1070                       &reserved_page_packet_8812[0], totalpacketlen);
1071         RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
1072                       "rtl8821ae_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL \n",
1073                       u1RsvdPageLoc, 3);
1074
1075
1076         skb = dev_alloc_skb(totalpacketlen);
1077         memcpy((u8 *) skb_put(skb, totalpacketlen),
1078                &reserved_page_packet_8812, totalpacketlen);
1079
1080         rtstatus = _rtl8821ae_cmd_send_packet(hw, skb);
1081
1082         if (rtstatus)
1083                 b_dlok = true;
1084
1085         if (b_dlok) {
1086                 RT_TRACE(COMP_POWER, DBG_LOUD,
1087                          ("Set RSVD page location to Fw.\n"));
1088                 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
1089                                 "H2C_RSVDPAGE:\n",
1090                                 u1RsvdPageLoc, 3);
1091                 rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_RSVDPAGE,
1092                                     sizeof(u1RsvdPageLoc), u1RsvdPageLoc);
1093         } else
1094                 RT_TRACE(COMP_ERR, DBG_WARNING,
1095                          ("Set RSVD page location to Fw FAIL!!!!!!.\n"));
1096 }
1097
1098 void rtl8821ae_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
1099 {
1100         struct rtl_priv *rtlpriv = rtl_priv(hw);
1101         struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1102         struct sk_buff *skb = NULL;
1103
1104         u32 totalpacketlen;
1105         bool rtstatus;
1106         u8 u1RsvdPageLoc[5] = { 0 };
1107         bool b_dlok = false;
1108
1109         u8* beacon;
1110         u8* p_pspoll;
1111         u8* nullfunc;
1112         u8* p_probersp;
1113         /*---------------------------------------------------------
1114                                 (1) beacon
1115         ---------------------------------------------------------*/
1116         beacon = &reserved_page_packet_8821[BEACON_PG_8821 * 256];
1117         SET_80211_HDR_ADDRESS2(beacon, mac->mac_addr);
1118         SET_80211_HDR_ADDRESS3(beacon, mac->bssid);
1119
1120         /*-------------------------------------------------------
1121                                 (2) ps-poll
1122         --------------------------------------------------------*/
1123         p_pspoll = &reserved_page_packet_8821[PSPOLL_PG_8821 * 256];
1124         SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000));
1125         SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid);
1126         SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr);
1127
1128         SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1RsvdPageLoc, PSPOLL_PG_8821);
1129
1130         /*--------------------------------------------------------
1131                                 (3) null data
1132         ---------------------------------------------------------*/
1133         nullfunc = &reserved_page_packet_8821[NULL_PG_8821 * 256];
1134         SET_80211_HDR_ADDRESS1(nullfunc, mac->bssid);
1135         SET_80211_HDR_ADDRESS2(nullfunc, mac->mac_addr);
1136         SET_80211_HDR_ADDRESS3(nullfunc, mac->bssid);
1137
1138         SET_H2CCMD_RSVDPAGE_LOC_NULL_DATA(u1RsvdPageLoc, NULL_PG_8821);
1139
1140         /*---------------------------------------------------------
1141                                 (4) probe response
1142         ----------------------------------------------------------*/
1143         p_probersp = &reserved_page_packet_8821[PROBERSP_PG_8821 * 256];
1144         SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid);
1145         SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr);
1146         SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid);
1147
1148         SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1RsvdPageLoc, PROBERSP_PG_8821);
1149
1150         totalpacketlen = TOTAL_RESERVED_PKT_LEN_8821;
1151
1152         RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
1153                       "rtl8821ae_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL \n",
1154                       &reserved_page_packet_8821[0], totalpacketlen);
1155         RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
1156                       "rtl8821ae_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL \n",
1157                       u1RsvdPageLoc, 3);
1158
1159
1160         skb = dev_alloc_skb(totalpacketlen);
1161         memcpy((u8 *) skb_put(skb, totalpacketlen),
1162                &reserved_page_packet_8821, totalpacketlen);
1163
1164         rtstatus = _rtl8821ae_cmd_send_packet(hw, skb);
1165
1166         if (rtstatus)
1167                 b_dlok = true;
1168
1169         if (b_dlok) {
1170                 RT_TRACE(COMP_POWER, DBG_LOUD,
1171                          ("Set RSVD page location to Fw.\n"));
1172                 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
1173                                 "H2C_RSVDPAGE:\n",
1174                                 u1RsvdPageLoc, 3);
1175                 rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_RSVDPAGE,
1176                                     sizeof(u1RsvdPageLoc), u1RsvdPageLoc);
1177         } else
1178                 RT_TRACE(COMP_ERR, DBG_WARNING,
1179                          ("Set RSVD page location to Fw FAIL!!!!!!.\n"));
1180 }
1181
1182 /*Shoud check FW support p2p or not.*/
1183 void rtl8821ae_set_p2p_ctw_period_cmd(struct ieee80211_hw *hw, u8 ctwindow)
1184 {
1185         u8 u1_ctwindow_period[1] ={ ctwindow};
1186
1187         rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_P2P_PS_CTW_CMD, 1, u1_ctwindow_period);
1188
1189 }
1190
1191 void rtl8821ae_set_p2p_ps_offload_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state)
1192 {
1193         struct rtl_priv *rtlpriv = rtl_priv(hw);
1194         struct rtl_ps_ctl *rtlps = rtl_psc(rtl_priv(hw));
1195         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1196         struct rtl_p2p_ps_info *p2pinfo = &(rtlps->p2p_ps_info);
1197         struct p2p_ps_offload_t *p2p_ps_offload = &rtlhal->p2p_ps_offload;
1198         u8      i;
1199         u16     ctwindow;
1200         u32     start_time, tsf_low;
1201
1202         switch(p2p_ps_state)
1203         {
1204                 case P2P_PS_DISABLE:
1205                         RT_TRACE(COMP_FW, DBG_LOUD,("P2P_PS_DISABLE \n"));
1206                         memset(p2p_ps_offload, 0, 1);
1207                         break;
1208                 case P2P_PS_ENABLE:
1209                         RT_TRACE(COMP_FW, DBG_LOUD,("P2P_PS_ENABLE \n"));
1210                         /* update CTWindow value. */
1211                         if( p2pinfo->ctwindow > 0 )
1212                         {
1213                                 p2p_ps_offload->CTWindow_En = 1;
1214                                 ctwindow = p2pinfo->ctwindow;
1215                                 rtl8821ae_set_p2p_ctw_period_cmd(hw, ctwindow);
1216                         }
1217
1218                         /* hw only support 2 set of NoA */
1219                         for( i=0 ; i<p2pinfo->noa_num ; i++)
1220                         {
1221                                 /* To control the register setting for which NOA*/
1222                                 rtl_write_byte(rtlpriv, 0x5cf, (i << 4));
1223                                 if(i == 0)
1224                                         p2p_ps_offload->NoA0_En = 1;
1225                                 else
1226                                         p2p_ps_offload->NoA1_En = 1;
1227
1228                                 /* config P2P NoA Descriptor Register */
1229                                 rtl_write_dword(rtlpriv, 0x5E0, p2pinfo->noa_duration[i]);
1230                                 rtl_write_dword(rtlpriv, 0x5E4, p2pinfo->noa_interval[i]);
1231
1232                                 /*Get Current \14TSF value */
1233                                 tsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
1234
1235                                 start_time = p2pinfo->noa_start_time[i];
1236                                 if(p2pinfo->noa_count_type[i] != 1)
1237                                 {
1238                                         while( start_time <= (tsf_low+(50*1024) ) ) {
1239                                                 start_time += p2pinfo->noa_interval[i];
1240                                                 if(p2pinfo->noa_count_type[i] != 255)
1241                                                         p2pinfo->noa_count_type[i]--;
1242                                         }
1243                                 }
1244                                 rtl_write_dword(rtlpriv, 0x5E8, start_time);
1245                                 rtl_write_dword(rtlpriv, 0x5EC, p2pinfo->noa_count_type[i] );
1246
1247                         }
1248
1249                         if( (p2pinfo->opp_ps == 1) || (p2pinfo->noa_num > 0) )
1250                         {
1251                                 /* rst p2p circuit */
1252                                 rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, BIT(4));
1253
1254                                 p2p_ps_offload->Offload_En = 1;
1255
1256                                 if(P2P_ROLE_GO == rtlpriv->mac80211.p2p)
1257                                 {
1258                                         p2p_ps_offload->role= 1;
1259                                         p2p_ps_offload->AllStaSleep = 0;
1260                                 }
1261                                 else
1262                                 {
1263                                         p2p_ps_offload->role= 0;
1264                                 }
1265
1266                                 p2p_ps_offload->discovery = 0;
1267                         }
1268                         break;
1269                 case P2P_PS_SCAN:
1270                         RT_TRACE(COMP_FW, DBG_LOUD,("P2P_PS_SCAN \n"));
1271                         p2p_ps_offload->discovery = 1;
1272                         break;
1273                 case P2P_PS_SCAN_DONE:
1274                         RT_TRACE(COMP_FW, DBG_LOUD,("P2P_PS_SCAN_DONE \n"));
1275                         p2p_ps_offload->discovery = 0;
1276                         p2pinfo->p2p_ps_state = P2P_PS_ENABLE;
1277                         break;
1278                 default:
1279                         break;
1280         }
1281
1282         rtl8821ae_fill_h2c_cmd(hw, H2C_8821AE_P2P_PS_OFFLOAD, 1, (u8 *)p2p_ps_offload);
1283
1284 }
1285
1286 void rtl8812ae_c2h_ra_report_handler(
1287         struct ieee80211_hw *hw,
1288         u8 *cmd_buf,
1289         u8 cmd_len
1290 )
1291 {
1292         struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1293         u8 rate = cmd_buf[0] & 0x3F;
1294
1295         rtlhal->current_ra_rate= rtl8812ae_hw_rate_to_mrate(hw, rate);
1296
1297         rtl8812ae_dm_update_init_rate(hw, rate);
1298 }
1299
1300
1301 void _rtl8812ae_c2h_content_parsing(
1302         struct ieee80211_hw *hw,
1303         u8 c2h_cmd_id,
1304         u8 c2h_cmd_len,
1305         u8 *tmp_buf
1306 )
1307 {
1308         struct rtl_priv *rtlpriv = rtl_priv(hw);
1309
1310         switch (c2h_cmd_id) {
1311         case C2H_8812_DBG:
1312                 RT_TRACE(COMP_FW, DBG_LOUD,("[C2H], C2H_8812_DBG!!\n"));
1313                 break;
1314
1315         case C2H_8812_RA_RPT:
1316                 rtl8812ae_c2h_ra_report_handler(hw, tmp_buf, c2h_cmd_len);
1317                 break;
1318
1319         default:
1320                 break;
1321         }
1322
1323 }
1324
1325 void rtl8812ae_c2h_packet_handler(
1326         struct ieee80211_hw *hw,
1327         u8 *buffer,
1328         u8 length
1329         )
1330 {
1331         struct rtl_priv *rtlpriv = rtl_priv(hw);
1332         u8 c2h_cmd_id=0, c2h_cmd_seq=0, c2h_cmd_len=0;
1333         u8 *tmp_buf=NULL;
1334
1335         c2h_cmd_id = buffer[0];
1336         c2h_cmd_seq = buffer[1];
1337         c2h_cmd_len = length -2;
1338         tmp_buf = buffer + 2;
1339
1340         RT_TRACE(COMP_FW, DBG_LOUD,
1341                 ("[C2H packet], c2hCmdId=0x%x, c2hCmdSeq=0x%x, c2hCmdLen=%d\n",
1342                 c2h_cmd_id, c2h_cmd_seq, c2h_cmd_len));
1343
1344         RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_LOUD,
1345                 "[C2H packet], Content Hex:\n", tmp_buf, c2h_cmd_len);
1346         _rtl8812ae_c2h_content_parsing(hw, c2h_cmd_id, c2h_cmd_len, tmp_buf);
1347 }
1348
1349