rtl8821c_mac.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 Realtek Corporation. All rights reserved.
  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. *
  19. ******************************************************************************/
  20. #define _RTL8821C_MAC_C_
  21. #include <drv_types.h> /* PADAPTER, basic_types.h and etc. */
  22. #include <hal_data.h> /* HAL_DATA_TYPE */
  23. #include "../hal_halmac.h" /* Register Definition and etc. */
  24. inline u8 rtl8821c_rcr_config(PADAPTER p, u32 rcr)
  25. {
  26. int err;
  27. err = rtw_write32(p, REG_RCR_8821C, rcr);
  28. if (_FAIL == err)
  29. return _FALSE;
  30. GET_HAL_DATA(p)->ReceiveConfig = rcr;
  31. return _TRUE;
  32. }
  33. inline u8 rtl8821c_rcr_get(PADAPTER p, u32 *rcr)
  34. {
  35. u32 v32;
  36. v32 = rtw_read32(p, REG_RCR_8821C);
  37. if (rcr)
  38. *rcr = v32;
  39. GET_HAL_DATA(p)->ReceiveConfig = v32;
  40. return _TRUE;
  41. }
  42. inline u8 rtl8821c_rcr_check(PADAPTER p, u32 check_bit)
  43. {
  44. PHAL_DATA_TYPE hal;
  45. u32 rcr;
  46. hal = GET_HAL_DATA(p);
  47. rcr = hal->ReceiveConfig;
  48. if ((rcr & check_bit) == check_bit)
  49. return _TRUE;
  50. return _FALSE;
  51. }
  52. inline u8 rtl8821c_rcr_add(PADAPTER p, u32 add)
  53. {
  54. PHAL_DATA_TYPE hal;
  55. u32 rcr;
  56. u8 ret = _TRUE;
  57. hal = GET_HAL_DATA(p);
  58. rcr = hal->ReceiveConfig;
  59. rcr |= add;
  60. if (rcr != hal->ReceiveConfig)
  61. ret = rtl8821c_rcr_config(p, rcr);
  62. return ret;
  63. }
  64. inline u8 rtl8821c_rcr_clear(PADAPTER p, u32 clear)
  65. {
  66. PHAL_DATA_TYPE hal;
  67. u32 rcr;
  68. u8 ret = _TRUE;
  69. hal = GET_HAL_DATA(p);
  70. rcr = hal->ReceiveConfig;
  71. rcr &= ~clear;
  72. if (rcr != hal->ReceiveConfig)
  73. ret = rtl8821c_rcr_config(p, rcr);
  74. return ret;
  75. }
  76. #ifdef CONFIG_XMIT_ACK
  77. inline u8 rtl8821c_set_mgnt_xmit_ack(_adapter *adapter)
  78. {
  79. int err;
  80. /*ack for xmit mgmt frames.*/
  81. err = rtw_write32(adapter, REG_FWHW_TXQ_CTRL_8821C, rtw_read32(adapter, REG_FWHW_TXQ_CTRL_8821C) | BIT(12));
  82. if (err == _FAIL)
  83. return _FAIL;
  84. return _SUCCESS;
  85. }
  86. #endif
  87. inline u8 rtl8821c_rx_ba_ssn_appended(PADAPTER p)
  88. {
  89. return rtl8821c_rcr_check(p, BIT_APP_BASSN_8821C);
  90. }
  91. inline u8 rtl8821c_rx_fcs_append_switch(PADAPTER p, u8 enable)
  92. {
  93. u32 rcr_bit;
  94. u8 ret = _TRUE;
  95. rcr_bit = BIT_APP_FCS_8821C;
  96. if (_TRUE == enable)
  97. ret = rtl8821c_rcr_add(p, rcr_bit);
  98. else
  99. ret = rtl8821c_rcr_clear(p, rcr_bit);
  100. return ret;
  101. }
  102. inline u8 rtl8821c_rx_fcs_appended(PADAPTER p)
  103. {
  104. return rtl8821c_rcr_check(p, BIT_APP_FCS_8821C);
  105. }
  106. u8 rtl8821c_rx_tsf_addr_filter_config(_adapter *adapter, u8 config)
  107. {
  108. u8 v8;
  109. int err;
  110. v8 = GET_HAL_DATA(adapter)->rx_tsf_addr_filter_config;
  111. if (v8 != config) {
  112. err = rtw_write8(adapter, REG_NAN_RX_TSF_FILTER_8821C, config);
  113. if (_FAIL == err)
  114. return _FALSE;
  115. }
  116. GET_HAL_DATA(adapter)->rx_tsf_addr_filter_config = config;
  117. return _TRUE;
  118. }
  119. /*
  120. * Return:
  121. * _SUCCESS Download Firmware OK.
  122. * _FAIL Download Firmware FAIL!
  123. */
  124. s32 rtl8821c_fw_dl(PADAPTER adapter, u8 wowlan)
  125. {
  126. struct dvobj_priv *d = adapter_to_dvobj(adapter);
  127. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  128. int err;
  129. u8 fw_bin = _TRUE;
  130. #ifdef CONFIG_FILE_FWIMG
  131. fw_bin = _TRUE;
  132. if (_TRUE == wowlan) {
  133. rtw_get_phy_file_path(adapter, MAC_FILE_FW_WW_IMG);
  134. err = rtw_halmac_dlfw_from_file(d, rtw_phy_para_file_path);
  135. } else {
  136. rtw_get_phy_file_path(adapter, MAC_FILE_FW_NIC);
  137. err = rtw_halmac_dlfw_from_file(d, rtw_phy_para_file_path);
  138. }
  139. #else
  140. fw_bin = _FALSE;
  141. if (_TRUE == wowlan)
  142. err = rtw_halmac_dlfw(d, array_mp_8821c_fw_wowlan, array_length_mp_8821c_fw_wowlan);
  143. else
  144. err = rtw_halmac_dlfw(d, array_mp_8821c_fw_nic, array_length_mp_8821c_fw_nic);
  145. #endif
  146. if (!err) {
  147. adapter->bFWReady = _TRUE;
  148. hal_data->fw_ractrl = _TRUE;
  149. RTW_INFO("%s Download Firmware from %s success\n", __func__, (fw_bin) ? "file" : "array");
  150. RTW_INFO("%s FW Version:%d SubVersion:%d\n", (wowlan) ? "WOW" : "NIC", hal_data->firmware_version, hal_data->firmware_sub_version);
  151. return _SUCCESS;
  152. } else {
  153. RTW_ERR("%s Download Firmware from %s failed\n", __func__, (fw_bin) ? "file" : "array");
  154. return _FAIL;
  155. }
  156. }
  157. /*
  158. * Return:
  159. * _SUCCESS Download Firmware MEM OK.
  160. * _FAIL Download Firmware MEM FAIL!
  161. */
  162. s32 rtl8821c_fw_mem_dl(PADAPTER adapter, enum fw_mem mem)
  163. {
  164. struct dvobj_priv *d = adapter_to_dvobj(adapter);
  165. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
  166. int err = 0;
  167. u8 fw_bin = _TRUE;
  168. #ifdef CONFIG_FILE_FWIMG
  169. fw_bin = _TRUE;
  170. rtw_get_phy_file_path(adapter, MAC_FILE_FW_NIC);
  171. err = rtw_halmac_dlfw_mem_from_file(d, rtw_phy_para_file_path, mem);
  172. #else
  173. fw_bin = _FALSE;
  174. err = rtw_halmac_dlfw_mem(d, array_mp_8821c_fw_nic, array_length_mp_8821c_fw_nic, mem);
  175. #endif
  176. if (err) {
  177. RTW_ERR("%s Download Firmware MEM from %s failed\n", __func__, (fw_bin) ? "file" : "array");
  178. return _FAIL;
  179. }
  180. RTW_INFO("%s Download Firmware MEM from %s success\n", __func__, (fw_bin) ? "file" : "array");
  181. return _SUCCESS;
  182. }