halmac_common_8821c.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2017 - 2018 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. ******************************************************************************/
  15. #include "halmac_8821c_cfg.h"
  16. #include "halmac_common_8821c.h"
  17. #include "../halmac_common_88xx.h"
  18. #include "halmac_cfg_wmac_8821c.h"
  19. #if HALMAC_PCIE_SUPPORT
  20. #include "halmac_pcie_8821c.h"
  21. #endif
  22. #if HALMAC_8821C_SUPPORT
  23. static void
  24. cfg_ldo25_8821c(struct halmac_adapter *adapter, u8 enable);
  25. /**
  26. * get_hw_value_8821c() -get hw config value
  27. * @adapter : the adapter of halmac
  28. * @hw_id : hw id for driver to query
  29. * @value : hw value, reference table to get data type
  30. * Author : KaiYuan Chang / Ivan Lin
  31. * Return : enum halmac_ret_status
  32. * More details of status code can be found in prototype document
  33. */
  34. enum halmac_ret_status
  35. get_hw_value_8821c(struct halmac_adapter *adapter, enum halmac_hw_id hw_id,
  36. void *value)
  37. {
  38. PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
  39. if (!value) {
  40. PLTFM_MSG_ERR("[ERR]null pointer\n");
  41. return HALMAC_RET_NULL_POINTER;
  42. }
  43. if (get_hw_value_88xx(adapter, hw_id, value) == HALMAC_RET_SUCCESS)
  44. return HALMAC_RET_SUCCESS;
  45. switch (hw_id) {
  46. case HALMAC_HW_FW_MAX_SIZE:
  47. *(u32 *)value = WLAN_FW_MAX_SIZE_8821C;
  48. break;
  49. case HALMAC_HW_SDIO_INT_LAT:
  50. break;
  51. case HALMAC_HW_SDIO_CLK_CNT:
  52. break;
  53. default:
  54. return HALMAC_RET_PARA_NOT_SUPPORT;
  55. }
  56. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  57. return HALMAC_RET_SUCCESS;
  58. }
  59. /**
  60. * set_hw_value_8821c() -set hw config value
  61. * @adapter : the adapter of halmac
  62. * @hw_id : hw id for driver to config
  63. * @value : hw value, reference table to get data type
  64. * Author : KaiYuan Chang / Ivan Lin
  65. * Return : enum halmac_ret_status
  66. * More details of status code can be found in prototype document
  67. */
  68. enum halmac_ret_status
  69. set_hw_value_8821c(struct halmac_adapter *adapter, enum halmac_hw_id hw_id,
  70. void *value)
  71. {
  72. enum halmac_ret_status status = HALMAC_RET_SUCCESS;
  73. PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
  74. if (!value) {
  75. PLTFM_MSG_ERR("[ERR]null pointer\n");
  76. return HALMAC_RET_NULL_POINTER;
  77. }
  78. if (set_hw_value_88xx(adapter, hw_id, value) == HALMAC_RET_SUCCESS)
  79. return HALMAC_RET_SUCCESS;
  80. switch (hw_id) {
  81. case HALMAC_HW_AMPDU_CONFIG:
  82. status = cfg_ampdu_8821c(adapter,
  83. (struct halmac_ampdu_config *)value);
  84. break;
  85. case HALMAC_HW_SDIO_TX_FORMAT:
  86. break;
  87. case HALMAC_HW_RXGCK_FIFO:
  88. break;
  89. case HALMAC_HW_RX_IGNORE:
  90. break;
  91. case HALMAC_HW_LDO25_EN:
  92. cfg_ldo25_8821c(adapter, *(u8 *)value);
  93. break;
  94. #if HALMAC_PCIE_SUPPORT
  95. case HALMAC_HW_PCIE_REF_AUTOK:
  96. if (adapter->intf != HALMAC_INTERFACE_PCIE)
  97. return HALMAC_RET_WRONG_INTF;
  98. status = auto_refclk_cal_8821c_pcie(adapter);
  99. if (status != HALMAC_RET_SUCCESS)
  100. return status;
  101. break;
  102. #endif
  103. case HALMAC_HW_SDIO_WT_EN:
  104. break;
  105. case HALMAC_HW_SDIO_CLK_MONITOR:
  106. break;
  107. default:
  108. return HALMAC_RET_PARA_NOT_SUPPORT;
  109. }
  110. PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
  111. return status;
  112. }
  113. /**
  114. * halmac_fill_txdesc_check_sum_88xx() - fill in tx desc check sum
  115. * @adapter : the adapter of halmac
  116. * @txdesc : tx desc packet
  117. * Author : KaiYuan Chang/Ivan Lin
  118. * Return : enum halmac_ret_status
  119. * More details of status code can be found in prototype document
  120. */
  121. enum halmac_ret_status
  122. fill_txdesc_check_sum_8821c(struct halmac_adapter *adapter, u8 *txdesc)
  123. {
  124. __le16 chksum = 0;
  125. __le16 *data;
  126. u32 i;
  127. if (!txdesc) {
  128. PLTFM_MSG_ERR("[ERR]null pointer\n");
  129. return HALMAC_RET_NULL_POINTER;
  130. }
  131. if (adapter->tx_desc_checksum != 1)
  132. PLTFM_MSG_TRACE("[TRACE]chksum disable\n");
  133. SET_TX_DESC_TXDESC_CHECKSUM(txdesc, 0x0000);
  134. data = (__le16 *)(txdesc);
  135. /* HW clculates only 32byte */
  136. for (i = 0; i < 8; i++)
  137. chksum ^= (*(data + 2 * i) ^ *(data + (2 * i + 1)));
  138. /* *(data + 2 * i) & *(data + (2 * i + 1) have endain issue*/
  139. /* Process eniadn issue after checksum calculation */
  140. SET_TX_DESC_TXDESC_CHECKSUM(txdesc, rtk_le16_to_cpu(chksum));
  141. return HALMAC_RET_SUCCESS;
  142. }
  143. static void
  144. cfg_ldo25_8821c(struct halmac_adapter *adapter, u8 enable)
  145. {
  146. u8 value8;
  147. struct halmac_api *api = (struct halmac_api *)adapter->halmac_api;
  148. value8 = HALMAC_REG_R8(REG_LDO_EFUSE_CTRL + 3);
  149. if (enable == 1)
  150. HALMAC_REG_W8(REG_LDO_EFUSE_CTRL + 3, (u8)(value8 | BIT(7)));
  151. else
  152. HALMAC_REG_W8(REG_LDO_EFUSE_CTRL + 3, (u8)(value8 & ~BIT(7)));
  153. }
  154. #endif /* HALMAC_8821C_SUPPORT */