38 static bool _rtl92d_is_fw_downloaded(
struct rtl_priv *rtlpriv)
55 rtl_write_byte(rtlpriv,
REG_MCUFWDL + 2, tmp & 0xf7);
66 static void _rtl92d_fw_block_write(
struct ieee80211_hw *hw,
70 u32 blocksize =
sizeof(
u32);
71 u8 *bufferptr = (
u8 *) buffer;
72 u32 *pu4BytePtr = (
u32 *) buffer;
75 blockCount = size / blocksize;
76 remainSize = size % blocksize;
77 for (i = 0; i < blockCount; i++) {
78 offset = i * blocksize;
83 offset = blockCount * blocksize;
85 for (i = 0; i < remainSize; i++) {
87 offset + i), *(bufferptr + i));
92 static void _rtl92d_fw_page_write(
struct ieee80211_hw *hw,
97 u8 u8page = (
u8) (page & 0x07);
99 value8 = (rtl_read_byte(rtlpriv,
REG_MCUFWDL + 2) & 0xF8) | u8page;
100 rtl_write_byte(rtlpriv, (
REG_MCUFWDL + 2), value8);
101 _rtl92d_fw_block_write(hw, buffer, size);
104 static void _rtl92d_fill_dummy(
u8 *pfwbuf,
u32 *pfwlen)
107 u8 remain = (
u8) (fwlen % 4);
109 remain = (remain == 0) ? 0 : (4 - remain);
124 u32 pagenums, remainSize;
129 _rtl92d_fill_dummy(bufferPtr, &size);
134 "Page numbers should not greater then 8\n");
136 for (page = 0; page < pagenums; page++) {
138 _rtl92d_fw_page_write(hw, page, (bufferPtr + offset),
144 _rtl92d_fw_page_write(hw, page, (bufferPtr + offset),
149 static int _rtl92d_fw_free_to_go(
struct ieee80211_hw *hw)
161 "chksum report faill ! REG_MCUFWDL:0x%08x\n",
166 "Checksum report OK ! REG_MCUFWDL:0x%08x\n", value32);
180 rtl_write_byte(rtlpriv,
REG_HMETFR + 3, 0x20);
182 while (u1b_tmp &
BIT(2)) {
189 RT_ASSERT((delay > 0),
"8051 reset failed!\n");
191 "=====> 8051 reset success (%d)\n", delay);
208 "Polling FW ready success!! REG_MCUFWDL: 0x%x\n",
209 rtl_read_byte(rtlpriv,
218 "Polling FW ready success!! REG_MCUFWDL: 0x%x\n",
219 rtl_read_byte(rtlpriv,
229 "Polling FW ready fail!! MAC0 FW init not ready: 0x%x\n",
233 "Polling FW ready fail!! MAC1 FW init not ready: 0x%x\n",
237 "Polling FW ready fail!! REG_MCUFWDL:0x%08ul\n",
253 bool fw_downloaded =
false, fwdl_in_process =
false;
264 "FirmwareVersion(%d), FirmwareSubVersion(%d), Signature(%#x)\n",
269 "Shift 32 bytes for FW header!!\n");
270 pfwdata = pfwdata + 32;
271 fwsize = fwsize - 32;
275 fw_downloaded = _rtl92d_is_fw_downloaded(rtlpriv);
276 if ((rtl_read_byte(rtlpriv, 0x1f) &
BIT(5)) ==
BIT(5))
277 fwdl_in_process =
true;
279 fwdl_in_process =
false;
283 }
else if (fwdl_in_process) {
285 for (count = 0; count < 5000; count++) {
288 fw_downloaded = _rtl92d_is_fw_downloaded(rtlpriv);
289 if ((rtl_read_byte(rtlpriv, 0x1f) &
BIT(5)) ==
BIT(5))
290 fwdl_in_process =
true;
292 fwdl_in_process =
false;
297 else if (!fwdl_in_process)
301 "Wait for another mac download fw\n");
304 value = rtl_read_byte(rtlpriv, 0x1f);
306 rtl_write_byte(rtlpriv, 0x1f, value);
309 value = rtl_read_byte(rtlpriv, 0x1f);
311 rtl_write_byte(rtlpriv, 0x1f, value);
323 _rtl92d_enable_fw_download(hw,
true);
324 _rtl92d_write_fw(hw, version, pfwdata, fwsize);
325 _rtl92d_enable_fw_download(hw,
false);
327 err = _rtl92d_fw_free_to_go(hw);
329 value = rtl_read_byte(rtlpriv, 0x1f);
331 rtl_write_byte(rtlpriv, 0x1f, value);
335 "fw is not ready to run!\n");
341 err = _rtl92d_fw_init(hw);
345 static bool _rtl92d_check_fw_read_last_h2c(
struct ieee80211_hw *hw,
u8 boxnum)
351 val_hmetfr = rtl_read_byte(rtlpriv,
REG_HMETFR);
352 if (((val_hmetfr >> boxnum) &
BIT(0)) == 0)
357 static void _rtl92d_fill_h2c_command(
struct ieee80211_hw *hw,
364 u16 box_reg = 0, box_extreg = 0;
366 bool isfw_read =
false;
368 bool bwrite_success =
false;
369 u8 wait_h2c_limmit = 100;
370 u8 wait_writeh2c_limmit = 100;
371 u8 boxcontent[4], boxextcontent[2];
372 u32 h2c_waitcounter = 0;
378 "Return as RF is off!!!\n");
386 "H2C set in progress! Wait to set..element_id(%d)\n",
390 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock,
394 "Wait 100 us (%d times)...\n",
398 if (h2c_waitcounter > 1000)
404 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
407 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
411 while (!bwrite_success) {
412 wait_writeh2c_limmit--;
413 if (wait_writeh2c_limmit == 0) {
415 "Write H2C fail because no trigger for FW INT!\n");
438 "switch case not processed\n");
441 isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
444 if (wait_h2c_limmit == 0) {
446 "Waiting too long for FW read clear HMEBox(%d)!\n",
451 isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
452 u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF);
454 "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n",
459 "Write H2C register BOX[%d] fail!!!!! Fw do not read.\n",
463 memset(boxcontent, 0,
sizeof(boxcontent));
464 memset(boxextcontent, 0,
sizeof(boxextcontent));
467 "Write element_id box_reg(%4x) = %2x\n",
468 box_reg, element_id);
471 boxcontent[0] &= ~(
BIT(7));
472 memcpy(boxcontent + 1, cmdbuffer + buf_index, 1);
473 for (idx = 0; idx < 4; idx++)
474 rtl_write_byte(rtlpriv, box_reg + idx,
478 boxcontent[0] &= ~(
BIT(7));
479 memcpy(boxcontent + 1, cmdbuffer + buf_index, 2);
480 for (idx = 0; idx < 4; idx++)
481 rtl_write_byte(rtlpriv, box_reg + idx,
485 boxcontent[0] &= ~(
BIT(7));
486 memcpy(boxcontent + 1, cmdbuffer + buf_index, 3);
487 for (idx = 0; idx < 4; idx++)
488 rtl_write_byte(rtlpriv, box_reg + idx,
492 boxcontent[0] |= (
BIT(7));
493 memcpy(boxextcontent, cmdbuffer + buf_index, 2);
494 memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 2);
495 for (idx = 0; idx < 2; idx++)
496 rtl_write_byte(rtlpriv, box_extreg + idx,
498 for (idx = 0; idx < 4; idx++)
499 rtl_write_byte(rtlpriv, box_reg + idx,
503 boxcontent[0] |= (
BIT(7));
504 memcpy(boxextcontent, cmdbuffer + buf_index, 2);
505 memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 3);
506 for (idx = 0; idx < 2; idx++)
507 rtl_write_byte(rtlpriv, box_extreg + idx,
509 for (idx = 0; idx < 4; idx++)
510 rtl_write_byte(rtlpriv, box_reg + idx,
515 "switch case not processed\n");
518 bwrite_success =
true;
523 "pHalData->last_hmeboxnum = %d\n",
528 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
533 u8 element_id,
u32 cmd_len,
u8 *cmdbuffer)
538 memcpy(tmp_cmdbuf, cmdbuffer, cmd_len);
539 _rtl92d_fill_h2c_command(hw, element_id, cmd_len, (
u8 *)&tmp_cmdbuf);
546 u8 u1_h2c_set_pwrmode[3] = { 0 };
555 "rtl92d_set_fw_rsvdpagepkt(): u1_h2c_set_pwrmode",
556 u1_h2c_set_pwrmode, 3);
560 static bool _rtl92d_cmd_send_packet(
struct ieee80211_hw *hw,
572 pskb = __skb_dequeue(&ring->
queue);
578 rtlpriv->
cfg->ops->fill_tx_cmddesc(hw, (
u8 *) pdesc, 1, 1, skb);
579 __skb_queue_tail(&ring->
queue, skb);
580 spin_unlock_irqrestore(&rtlpriv->
locks.irq_th_lock, flags);
588 #define PROBERSP_PG 4
589 #define TOTAL_RESERVED_PKT_LEN 768
593 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
594 0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
595 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x50, 0x08,
596 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
597 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
598 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
599 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
600 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
601 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
602 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
603 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
604 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
605 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
606 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
607 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
608 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
611 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
612 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
613 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
614 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
615 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
616 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
617 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
619 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
621 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
622 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
623 0x10, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x10, 0x00,
624 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
625 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
626 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
629 0xA4, 0x10, 0x01, 0xC0, 0x00, 0x40, 0x10, 0x10,
630 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
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 0x18, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
642 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
643 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
644 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
647 0x48, 0x01, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
648 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
649 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
650 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
651 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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 0x72, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
660 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
661 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
662 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
665 0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
666 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
667 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
668 0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00,
669 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
670 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
671 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
672 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
673 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
674 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
675 0x03, 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 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
679 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
680 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
683 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
684 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
685 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
686 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
708 u8 u1RsvdPageLoc[3] = { 0 };
717 beacon = &reserved_page_packet[
BEACON_PG * 128];
723 p_pspoll = &reserved_page_packet[
PSPOLL_PG * 128];
731 nullfunc = &reserved_page_packet[
NULL_PG * 128];
739 p_probersp = &reserved_page_packet[
PROBERSP_PG * 128];
746 "rtl92d_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL",
747 &reserved_page_packet[0], totalpacketlen);
749 "rtl92d_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL",
751 skb = dev_alloc_skb(totalpacketlen);
756 &reserved_page_packet, totalpacketlen);
757 rtstatus = _rtl92d_cmd_send_packet(hw, skb);
764 "Set RSVD page location to Fw\n");
766 "H2C_RSVDPAGE", u1RsvdPageLoc, 3);
768 sizeof(u1RsvdPageLoc), u1RsvdPageLoc);
771 "Set RSVD page location to Fw FAIL!!!!!!\n");
776 u8 u1_joinbssrpt_parm[1] = {0};