phydm_primary_cca.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 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. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. /*************************************************************
  26. * include files
  27. ************************************************************/
  28. #include "mp_precomp.h"
  29. #include "phydm_precomp.h"
  30. #ifdef PHYDM_PRIMARY_CCA
  31. void phydm_write_dynamic_cca(
  32. void *dm_void,
  33. u8 curr_mf_state
  34. )
  35. {
  36. struct dm_struct *dm = (struct dm_struct *)dm_void;
  37. struct phydm_pricca_struct *pri_cca = &dm->dm_pri_cca;
  38. if (pri_cca->mf_state == curr_mf_state)
  39. return;
  40. if (dm->support_ic_type & ODM_IC_11N_SERIES) {
  41. if (curr_mf_state == MF_USC_LSC) {
  42. odm_set_bb_reg(dm, R_0xc6c, 0x180, MF_USC_LSC);
  43. /*@40M OFDM MF CCA threshold*/
  44. odm_set_bb_reg(dm, R_0xc84, 0xf0000000,
  45. pri_cca->cca_th_40m_bkp);
  46. } else {
  47. odm_set_bb_reg(dm, R_0xc6c, 0x180, curr_mf_state);
  48. /*@40M OFDM MF CCA threshold*/
  49. odm_set_bb_reg(dm, R_0xc84, 0xf0000000, 0);
  50. }
  51. }
  52. pri_cca->mf_state = curr_mf_state;
  53. PHYDM_DBG(dm, DBG_PRI_CCA, "Set CCA at ((%s SB)), 0xc6c[8:7]=((%d))\n",
  54. ((curr_mf_state == MF_USC_LSC) ? "D" :
  55. ((curr_mf_state == MF_LSC) ? "L" : "U")), curr_mf_state);
  56. }
  57. void phydm_primary_cca_reset(
  58. void *dm_void)
  59. {
  60. struct dm_struct *dm = (struct dm_struct *)dm_void;
  61. struct phydm_pricca_struct *pri_cca = &dm->dm_pri_cca;
  62. PHYDM_DBG(dm, DBG_PRI_CCA, "[PriCCA] Reset\n");
  63. pri_cca->mf_state = 0xff;
  64. pri_cca->pre_bw = (enum channel_width)0xff;
  65. phydm_write_dynamic_cca(dm, MF_USC_LSC);
  66. }
  67. void phydm_primary_cca_11n(
  68. void *dm_void)
  69. {
  70. struct dm_struct *dm = (struct dm_struct *)dm_void;
  71. struct phydm_pricca_struct *pri_cca = &dm->dm_pri_cca;
  72. enum channel_width curr_bw = (enum channel_width)*dm->band_width;
  73. if (!(dm->support_ability & ODM_BB_PRIMARY_CCA))
  74. return;
  75. if (!dm->is_linked) {
  76. PHYDM_DBG(dm, DBG_PRI_CCA, "[PriCCA][No Link!!!]\n");
  77. if (pri_cca->pri_cca_is_become_linked) {
  78. phydm_primary_cca_reset(dm);
  79. pri_cca->pri_cca_is_become_linked = dm->is_linked;
  80. }
  81. return;
  82. } else {
  83. if (!pri_cca->pri_cca_is_become_linked) {
  84. PHYDM_DBG(dm, DBG_PRI_CCA, "[PriCCA][Linked !!!]\n");
  85. pri_cca->pri_cca_is_become_linked = dm->is_linked;
  86. }
  87. }
  88. if (curr_bw != pri_cca->pre_bw) {
  89. PHYDM_DBG(dm, DBG_PRI_CCA, "[Primary CCA] start ==>\n");
  90. pri_cca->pre_bw = curr_bw;
  91. if (curr_bw == CHANNEL_WIDTH_40) {
  92. if (*dm->sec_ch_offset == SECOND_CH_AT_LSB) {
  93. /* Primary CH @ upper sideband*/
  94. PHYDM_DBG(dm, DBG_PRI_CCA,
  95. "BW40M, Primary CH at USB\n");
  96. phydm_write_dynamic_cca(dm, MF_USC);
  97. } else {
  98. /*Primary CH @ lower sideband*/
  99. PHYDM_DBG(dm, DBG_PRI_CCA,
  100. "BW40M, Primary CH at LSB\n");
  101. phydm_write_dynamic_cca(dm, MF_LSC);
  102. }
  103. } else {
  104. PHYDM_DBG(dm, DBG_PRI_CCA, "Not BW40M, USB + LSB\n");
  105. phydm_primary_cca_reset(dm);
  106. }
  107. }
  108. }
  109. boolean
  110. odm_dynamic_primary_cca_dup_rts(void *dm_void)
  111. {
  112. struct dm_struct *dm = (struct dm_struct *)dm_void;
  113. struct phydm_pricca_struct *pri_cca = &dm->dm_pri_cca;
  114. return pri_cca->dup_rts_flag;
  115. }
  116. void phydm_primary_cca_init(void *dm_void)
  117. {
  118. struct dm_struct *dm = (struct dm_struct *)dm_void;
  119. struct phydm_pricca_struct *pri_cca = &dm->dm_pri_cca;
  120. if (!(dm->support_ability & ODM_BB_PRIMARY_CCA))
  121. return;
  122. if (!(dm->support_ic_type & ODM_IC_11N_SERIES))
  123. return;
  124. PHYDM_DBG(dm, DBG_PRI_CCA, "[PriCCA] Init ==>\n");
  125. #if (RTL8188E_SUPPORT == 1) || (RTL8192E_SUPPORT == 1)
  126. pri_cca->dup_rts_flag = 0;
  127. pri_cca->intf_flag = 0;
  128. pri_cca->intf_type = 0;
  129. pri_cca->monitor_flag = 0;
  130. pri_cca->pri_cca_flag = 0;
  131. pri_cca->ch_offset = 0;
  132. #endif
  133. pri_cca->mf_state = 0xff;
  134. pri_cca->pre_bw = (enum channel_width)0xff;
  135. pri_cca->cca_th_40m_bkp = (u8)odm_get_bb_reg(dm, R_0xc84, 0xf0000000);
  136. }
  137. void phydm_primary_cca(void *dm_void)
  138. {
  139. #ifdef PHYDM_PRIMARY_CCA
  140. struct dm_struct *dm = (struct dm_struct *)dm_void;
  141. if (!(dm->support_ic_type & ODM_IC_11N_SERIES))
  142. return;
  143. if (!(dm->support_ability & ODM_BB_PRIMARY_CCA))
  144. return;
  145. phydm_primary_cca_11n(dm);
  146. #endif
  147. }
  148. #endif