33 #include "../rtl8192ce/reg.h"
34 #include "../rtl8192ce/def.h"
36 #include <linux/export.h>
63 rtl_write_byte(rtlpriv,
REG_MCUFWDL + 2, tmp & 0xf7);
79 u8 *bufferPtr = (
u8 *) buffer;
82 blockCount = size / blockSize;
83 remainSize = size % blockSize;
85 for (i = 0; i < blockCount; i++) {
86 offset = i * blockSize;
87 rtlpriv->
io.writeN_sync(rtlpriv,
89 (
void *)(bufferPtr + offset),
94 offset = blockCount * blockSize;
95 rtlpriv->
io.writeN_sync(rtlpriv,
97 (
void *)(bufferPtr + offset),
102 static void _rtl92c_fw_block_write(
struct ieee80211_hw *hw,
103 const u8 *buffer,
u32 size)
106 u32 blockSize =
sizeof(
u32);
107 u8 *bufferPtr = (
u8 *) buffer;
108 u32 *pu4BytePtr = (
u32 *) buffer;
112 if (rtlpriv->
io.writeN_sync) {
113 rtl_block_fw_writeN(hw, buffer, size);
116 blockCount = size / blockSize;
117 remainSize = size % blockSize;
120 for (i = 0; i < 4 - remainSize; i++)
121 *(bufferPtr + size + i) = 0;
125 for (i = 0; i < blockCount; i++) {
126 offset = i * blockSize;
137 static void _rtl92c_fw_page_write(
struct ieee80211_hw *hw,
142 u8 u8page = (
u8) (page & 0x07);
144 value8 = (rtl_read_byte(rtlpriv,
REG_MCUFWDL + 2) & 0xF8) | u8page;
146 rtl_write_byte(rtlpriv, (
REG_MCUFWDL + 2), value8);
147 _rtl92c_fw_block_write(hw, buffer, size);
150 static void _rtl92c_fill_dummy(
u8 *pfwbuf,
u32 *pfwlen)
153 u8 remain = (
u8) (fwlen % 4);
155 remain = (remain == 0) ? 0 : (4 - remain);
176 u32 pageNums, remainSize;
180 _rtl92c_fill_dummy(bufferPtr, &size);
187 "Page numbers should not greater then 4\n");
190 for (page = 0; page < pageNums; page++) {
192 _rtl92c_fw_page_write(hw, page, (bufferPtr + offset),
199 _rtl92c_fw_page_write(hw, page, (bufferPtr + offset),
203 _rtl92c_fw_block_write(hw, buffer, size);
207 static int _rtl92c_fw_free_to_go(
struct ieee80211_hw *hw)
220 "chksum report faill ! REG_MCUFWDL:0x%08x\n", value32);
225 "Checksum report OK ! REG_MCUFWDL:0x%08x\n", value32);
238 "Polling FW ready success!! REG_MCUFWDL:0x%08x\n",
248 "Polling FW ready fail!! REG_MCUFWDL:0x%08x\n", value32);
270 "Firmware Version(%d), Signature(%#x),Size(%d)\n",
279 _rtl92c_enable_fw_download(hw,
true);
280 _rtl92c_write_fw(hw, version, pfwdata, fwsize);
281 _rtl92c_enable_fw_download(hw,
false);
283 if (_rtl92c_fw_free_to_go(hw)) {
285 "Firmware is not ready to run!\n");
288 "Firmware is ready to run!\n");
295 static bool _rtl92c_check_fw_read_last_h2c(
struct ieee80211_hw *hw,
u8 boxnum)
298 u8 val_hmetfr, val_mcutst_1;
301 val_hmetfr = rtl_read_byte(rtlpriv,
REG_HMETFR);
302 val_mcutst_1 = rtl_read_byte(rtlpriv, (
REG_MCUTST_1 + boxnum));
304 if (((val_hmetfr >> boxnum) &
BIT(0)) == 0 && val_mcutst_1 == 0)
309 static void _rtl92c_fill_h2c_command(
struct ieee80211_hw *hw,
315 u16 box_reg = 0, box_extreg = 0;
317 bool isfw_read =
false;
318 bool bwrite_success =
false;
319 u8 wait_h2c_limmit = 100;
320 u8 wait_writeh2c_limmit = 100;
321 u8 boxcontent[4], boxextcontent[2];
322 u32 h2c_waitcounter = 0;
332 "H2C set in progress! Wait to set..element_id(%d)\n",
336 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock,
340 "Wait 100 us (%d times)...\n",
344 if (h2c_waitcounter > 1000)
349 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
352 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
357 while (!bwrite_success) {
358 wait_writeh2c_limmit--;
359 if (wait_writeh2c_limmit == 0) {
361 "Write H2C fail because no trigger for FW INT!\n");
385 "switch case not processed\n");
389 isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum);
393 if (wait_h2c_limmit == 0) {
395 "Waiting too long for FW read clear HMEBox(%d)!\n",
402 isfw_read = _rtl92c_check_fw_read_last_h2c(hw, boxnum);
403 u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF);
405 "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n",
411 "Write H2C register BOX[%d] fail!!!!! Fw do not read\n",
416 memset(boxcontent, 0,
sizeof(boxcontent));
417 memset(boxextcontent, 0,
sizeof(boxextcontent));
420 "Write element_id box_reg(%4x) = %2x\n",
421 box_reg, element_id);
425 boxcontent[0] &= ~(
BIT(7));
429 for (idx = 0; idx < 4; idx++) {
430 rtl_write_byte(rtlpriv, box_reg + idx,
435 boxcontent[0] &= ~(
BIT(7));
439 for (idx = 0; idx < 4; idx++) {
440 rtl_write_byte(rtlpriv, box_reg + idx,
445 boxcontent[0] &= ~(
BIT(7));
449 for (idx = 0; idx < 4; idx++) {
450 rtl_write_byte(rtlpriv, box_reg + idx,
455 boxcontent[0] |= (
BIT(7));
461 for (idx = 0; idx < 2; idx++) {
462 rtl_write_byte(rtlpriv, box_extreg + idx,
466 for (idx = 0; idx < 4; idx++) {
467 rtl_write_byte(rtlpriv, box_reg + idx,
472 boxcontent[0] |= (
BIT(7));
478 for (idx = 0; idx < 2; idx++) {
479 rtl_write_byte(rtlpriv, box_extreg + idx,
483 for (idx = 0; idx < 4; idx++) {
484 rtl_write_byte(rtlpriv, box_reg + idx,
490 "switch case not processed\n");
494 bwrite_success =
true;
501 "pHalData->last_hmeboxnum = %d\n",
507 spin_unlock_irqrestore(&rtlpriv->
locks.h2c_lock, flag);
513 u8 element_id,
u32 cmd_len,
u8 *p_cmdbuffer)
518 memcpy(tmp_cmdbuf, p_cmdbuffer, cmd_len);
519 _rtl92c_fill_h2c_command(hw, element_id, cmd_len, (
u8 *)&tmp_cmdbuf);
531 rtl_write_byte(rtlpriv,
REG_HMETFR + 3, 0x20);
534 while (u1b_tmp &
BIT(2)) {
537 RT_ASSERT(
false,
"8051 reset fail\n");
549 u8 u1_h2c_set_pwrmode[3] = {0};
560 "rtl92c_set_fw_rsvdpagepkt(): u1_h2c_set_pwrmode",
561 u1_h2c_set_pwrmode, 3);
567 static bool _rtl92c_cmd_send_packet(
struct ieee80211_hw *hw,
579 pskb = __skb_dequeue(&ring->
queue);
584 pdesc = &ring->
desc[0];
586 rtlpriv->
cfg->ops->fill_tx_cmddesc(hw, (
u8 *) pdesc, 1, 1, skb);
588 __skb_queue_tail(&ring->
queue, skb);
590 spin_unlock_irqrestore(&rtlpriv->
locks.irq_th_lock, flags);
600 #define PROBERSP_PG 4
602 #define TOTAL_RESERVED_PKT_LEN 768
606 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
607 0xFF, 0xFF, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
608 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x50, 0x08,
609 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
611 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
612 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
613 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
614 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
615 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
616 0x03, 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 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
620 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
621 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
624 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
625 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
626 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 0x10, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x10, 0x00,
637 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
638 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
639 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
642 0xA4, 0x10, 0x01, 0xC0, 0x00, 0x40, 0x10, 0x10,
643 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
644 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
645 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 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 0x18, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
655 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
656 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
657 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
660 0x48, 0x01, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
661 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
662 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 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 0x72, 0x00, 0x20, 0x8C, 0x00, 0x12, 0x00, 0x00,
673 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
674 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
675 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
678 0x50, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x10,
679 0x00, 0x03, 0x00, 0xE0, 0x4C, 0x76, 0x00, 0x42,
680 0x00, 0x40, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00,
681 0x9E, 0x46, 0x15, 0x32, 0x27, 0xF2, 0x2D, 0x00,
682 0x64, 0x00, 0x00, 0x04, 0x00, 0x0C, 0x6C, 0x69,
683 0x6E, 0x6B, 0x73, 0x79, 0x73, 0x5F, 0x77, 0x6C,
684 0x61, 0x6E, 0x01, 0x04, 0x82, 0x84, 0x8B, 0x96,
685 0x03, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x2A,
686 0x01, 0x00, 0x32, 0x08, 0x24, 0x30, 0x48, 0x6C,
687 0x0C, 0x12, 0x18, 0x60, 0x2D, 0x1A, 0x6C, 0x18,
688 0x03, 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 0x3D, 0x00, 0xDD, 0x06, 0x00, 0xE0, 0x4C, 0x02,
692 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
693 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 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
722 u8 u1RsvdPageLoc[3] = {0};
732 beacon = &reserved_page_packet[
BEACON_PG * 128];
739 pspoll = &reserved_page_packet[
PSPOLL_PG * 128];
749 nullfunc = &reserved_page_packet[
NULL_PG * 128];
759 probersp = &reserved_page_packet[
PROBERSP_PG * 128];
769 "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL",
770 &reserved_page_packet[0], totalpacketlen);
772 "rtl92c_set_fw_rsvdpagepkt(): HW_VAR_SET_TX_CMD: ALL",
776 skb = dev_alloc_skb(totalpacketlen);
782 &reserved_page_packet, totalpacketlen);
784 rtstatus = _rtl92c_cmd_send_packet(hw, skb);
791 "Set RSVD page location to Fw\n");
793 "H2C_RSVDPAGE", u1RsvdPageLoc, 3);
795 sizeof(u1RsvdPageLoc), u1RsvdPageLoc);
798 "Set RSVD page location to Fw FAIL!!!!!!\n");
804 u8 u1_joinbssrpt_parm[1] = {0};