phy.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright(c) 2019-2020 Realtek Corporation
  3. */
  4. #ifndef __RTW89_PHY_H__
  5. #define __RTW89_PHY_H__
  6. #include "core.h"
  7. #define RTW89_RF_ADDR_ADSEL_MASK BIT(16)
  8. #define get_phy_headline(addr) FIELD_GET(GENMASK(31, 28), addr)
  9. #define PHY_HEADLINE_VALID 0xf
  10. #define get_phy_target(addr) FIELD_GET(GENMASK(27, 0), addr)
  11. #define get_phy_compare(rfe, cv) (FIELD_PREP(GENMASK(23, 16), rfe) | \
  12. FIELD_PREP(GENMASK(7, 0), cv))
  13. #define get_phy_cond(addr) FIELD_GET(GENMASK(31, 28), addr)
  14. #define get_phy_cond_rfe(addr) FIELD_GET(GENMASK(23, 16), addr)
  15. #define get_phy_cond_pkg(addr) FIELD_GET(GENMASK(15, 8), addr)
  16. #define get_phy_cond_cv(addr) FIELD_GET(GENMASK(7, 0), addr)
  17. #define phy_div(a, b) ({typeof(b) _b = (b); (_b) ? ((a) / (_b)) : 0; })
  18. #define PHY_COND_BRANCH_IF 0x8
  19. #define PHY_COND_BRANCH_ELIF 0x9
  20. #define PHY_COND_BRANCH_ELSE 0xa
  21. #define PHY_COND_BRANCH_END 0xb
  22. #define PHY_COND_CHECK 0x4
  23. #define PHY_COND_DONT_CARE 0xff
  24. #define RA_MASK_CCK_RATES GENMASK_ULL(3, 0)
  25. #define RA_MASK_OFDM_RATES GENMASK_ULL(11, 4)
  26. #define RA_MASK_SUBCCK_RATES 0x5ULL
  27. #define RA_MASK_SUBOFDM_RATES 0x10ULL
  28. #define RA_MASK_HT_1SS_RATES GENMASK_ULL(19, 12)
  29. #define RA_MASK_HT_2SS_RATES GENMASK_ULL(31, 24)
  30. #define RA_MASK_HT_3SS_RATES GENMASK_ULL(43, 36)
  31. #define RA_MASK_HT_4SS_RATES GENMASK_ULL(55, 48)
  32. #define RA_MASK_HT_RATES GENMASK_ULL(55, 12)
  33. #define RA_MASK_VHT_1SS_RATES GENMASK_ULL(21, 12)
  34. #define RA_MASK_VHT_2SS_RATES GENMASK_ULL(33, 24)
  35. #define RA_MASK_VHT_3SS_RATES GENMASK_ULL(45, 36)
  36. #define RA_MASK_VHT_4SS_RATES GENMASK_ULL(57, 48)
  37. #define RA_MASK_VHT_RATES GENMASK_ULL(57, 12)
  38. #define RA_MASK_HE_1SS_RATES GENMASK_ULL(23, 12)
  39. #define RA_MASK_HE_2SS_RATES GENMASK_ULL(35, 24)
  40. #define RA_MASK_HE_3SS_RATES GENMASK_ULL(47, 36)
  41. #define RA_MASK_HE_4SS_RATES GENMASK_ULL(59, 48)
  42. #define RA_MASK_HE_RATES GENMASK_ULL(59, 12)
  43. #define CFO_TRK_ENABLE_TH (2 << 2)
  44. #define CFO_TRK_STOP_TH_4 (30 << 2)
  45. #define CFO_TRK_STOP_TH_3 (20 << 2)
  46. #define CFO_TRK_STOP_TH_2 (10 << 2)
  47. #define CFO_TRK_STOP_TH_1 (00 << 2)
  48. #define CFO_TRK_STOP_TH (2 << 2)
  49. #define CFO_SW_COMP_FINE_TUNE (2 << 2)
  50. #define CFO_PERIOD_CNT 15
  51. #define CFO_BOUND 64
  52. #define CFO_TP_UPPER 100
  53. #define CFO_TP_LOWER 50
  54. #define CFO_COMP_PERIOD 250
  55. #define CFO_COMP_WEIGHT 8
  56. #define MAX_CFO_TOLERANCE 30
  57. #define CFO_TF_CNT_TH 300
  58. #define UL_TB_TF_CNT_L2H_TH 100
  59. #define UL_TB_TF_CNT_H2L_TH 70
  60. #define ANTDIV_TRAINNING_CNT 2
  61. #define ANTDIV_TRAINNING_INTVL 30
  62. #define ANTDIV_DELAY 110
  63. #define ANTDIV_TP_DIFF_TH_HIGH 100
  64. #define ANTDIV_TP_DIFF_TH_LOW 5
  65. #define ANTDIV_EVM_DIFF_TH 8
  66. #define ANTDIV_RSSI_DIFF_TH 3
  67. #define CCX_MAX_PERIOD 2097
  68. #define CCX_MAX_PERIOD_UNIT 32
  69. #define MS_TO_4US_RATIO 250
  70. #define ENV_MNTR_FAIL_DWORD 0xffffffff
  71. #define ENV_MNTR_IFSCLM_HIS_MAX 127
  72. #define PERMIL 1000
  73. #define PERCENT 100
  74. #define IFS_CLM_TH0_UPPER 64
  75. #define IFS_CLM_TH_MUL 4
  76. #define IFS_CLM_TH_START_IDX 0
  77. #define TIA0_GAIN_A 12
  78. #define TIA0_GAIN_G 16
  79. #define LNA0_GAIN (-24)
  80. #define U4_MAX_BIT 3
  81. #define U8_MAX_BIT 7
  82. #define DIG_GAIN_SHIFT 2
  83. #define DIG_GAIN 8
  84. #define LNA_IDX_MAX 6
  85. #define LNA_IDX_MIN 0
  86. #define TIA_IDX_MAX 1
  87. #define TIA_IDX_MIN 0
  88. #define RXB_IDX_MAX 31
  89. #define RXB_IDX_MIN 0
  90. #define IGI_RSSI_MAX 110
  91. #define PD_TH_MAX_RSSI 70
  92. #define PD_TH_MIN_RSSI 8
  93. #define CCKPD_TH_MIN_RSSI (-18)
  94. #define PD_TH_BW160_CMP_VAL 9
  95. #define PD_TH_BW80_CMP_VAL 6
  96. #define PD_TH_BW40_CMP_VAL 3
  97. #define PD_TH_BW20_CMP_VAL 0
  98. #define PD_TH_CMP_VAL 3
  99. #define PD_TH_SB_FLTR_CMP_VAL 7
  100. #define PHYSTS_MGNT BIT(RTW89_RX_TYPE_MGNT)
  101. #define PHYSTS_CTRL BIT(RTW89_RX_TYPE_CTRL)
  102. #define PHYSTS_DATA BIT(RTW89_RX_TYPE_DATA)
  103. #define PHYSTS_RSVD BIT(RTW89_RX_TYPE_RSVD)
  104. #define PPDU_FILTER_BITMAP (PHYSTS_MGNT | PHYSTS_DATA)
  105. enum rtw89_phy_c2h_ra_func {
  106. RTW89_PHY_C2H_FUNC_STS_RPT,
  107. RTW89_PHY_C2H_FUNC_MU_GPTBL_RPT,
  108. RTW89_PHY_C2H_FUNC_TXSTS,
  109. RTW89_PHY_C2H_FUNC_RA_MAX,
  110. };
  111. enum rtw89_phy_c2h_dm_func {
  112. RTW89_PHY_C2H_DM_FUNC_FW_TEST,
  113. RTW89_PHY_C2H_DM_FUNC_FW_TRIG_TX_RPT,
  114. RTW89_PHY_C2H_DM_FUNC_SIGB,
  115. RTW89_PHY_C2H_DM_FUNC_LOWRT_RTY,
  116. RTW89_PHY_C2H_DM_FUNC_MCC_DIG,
  117. RTW89_PHY_C2H_DM_FUNC_NUM,
  118. };
  119. enum rtw89_phy_c2h_class {
  120. RTW89_PHY_C2H_CLASS_RUA,
  121. RTW89_PHY_C2H_CLASS_RA,
  122. RTW89_PHY_C2H_CLASS_DM,
  123. RTW89_PHY_C2H_CLASS_BTC_MIN = 0x10,
  124. RTW89_PHY_C2H_CLASS_BTC_MAX = 0x17,
  125. RTW89_PHY_C2H_CLASS_MAX,
  126. };
  127. enum rtw89_env_monitor_result_level {
  128. RTW89_PHY_ENV_MON_CCX_FAIL = 0,
  129. RTW89_PHY_ENV_MON_NHM = BIT(0),
  130. RTW89_PHY_ENV_MON_CLM = BIT(1),
  131. RTW89_PHY_ENV_MON_FAHM = BIT(2),
  132. RTW89_PHY_ENV_MON_IFS_CLM = BIT(3),
  133. RTW89_PHY_ENV_MON_EDCCA_CLM = BIT(4),
  134. };
  135. #define CCX_US_BASE_RATIO 4
  136. enum rtw89_ccx_unit {
  137. RTW89_CCX_4_US = 0,
  138. RTW89_CCX_8_US = 1,
  139. RTW89_CCX_16_US = 2,
  140. RTW89_CCX_32_US = 3
  141. };
  142. enum rtw89_phy_status_ie_type {
  143. RTW89_PHYSTS_IE00_CMN_CCK = 0,
  144. RTW89_PHYSTS_IE01_CMN_OFDM = 1,
  145. RTW89_PHYSTS_IE02_CMN_EXT_AX = 2,
  146. RTW89_PHYSTS_IE03_CMN_EXT_SEG_1 = 3,
  147. RTW89_PHYSTS_IE04_CMN_EXT_PATH_A = 4,
  148. RTW89_PHYSTS_IE05_CMN_EXT_PATH_B = 5,
  149. RTW89_PHYSTS_IE06_CMN_EXT_PATH_C = 6,
  150. RTW89_PHYSTS_IE07_CMN_EXT_PATH_D = 7,
  151. RTW89_PHYSTS_IE08_FTR_CH = 8,
  152. RTW89_PHYSTS_IE09_FTR_0 = 9,
  153. RTW89_PHYSTS_IE10_FTR_PLCP_EXT = 10,
  154. RTW89_PHYSTS_IE11_FTR_PLCP_HISTOGRAM = 11,
  155. RTW89_PHYSTS_IE12_MU_EIGEN_INFO = 12,
  156. RTW89_PHYSTS_IE13_DL_MU_DEF = 13,
  157. RTW89_PHYSTS_IE14_TB_UL_CQI = 14,
  158. RTW89_PHYSTS_IE15_TB_UL_DEF = 15,
  159. RTW89_PHYSTS_IE16_RSVD16 = 16,
  160. RTW89_PHYSTS_IE17_TB_UL_CTRL = 17,
  161. RTW89_PHYSTS_IE18_DBG_OFDM_FD_CMN = 18,
  162. RTW89_PHYSTS_IE19_DBG_OFDM_TD_CMN = 19,
  163. RTW89_PHYSTS_IE20_DBG_OFDM_FD_USER_SEG_0 = 20,
  164. RTW89_PHYSTS_IE21_DBG_OFDM_FD_USER_SEG_1 = 21,
  165. RTW89_PHYSTS_IE22_DBG_OFDM_FD_USER_AGC = 22,
  166. RTW89_PHYSTS_IE23_RSVD23 = 23,
  167. RTW89_PHYSTS_IE24_OFDM_TD_PATH_A = 24,
  168. RTW89_PHYSTS_IE25_OFDM_TD_PATH_B = 25,
  169. RTW89_PHYSTS_IE26_OFDM_TD_PATH_C = 26,
  170. RTW89_PHYSTS_IE27_OFDM_TD_PATH_D = 27,
  171. RTW89_PHYSTS_IE28_DBG_CCK_PATH_A = 28,
  172. RTW89_PHYSTS_IE29_DBG_CCK_PATH_B = 29,
  173. RTW89_PHYSTS_IE30_DBG_CCK_PATH_C = 30,
  174. RTW89_PHYSTS_IE31_DBG_CCK_PATH_D = 31,
  175. /* keep last */
  176. RTW89_PHYSTS_IE_NUM,
  177. RTW89_PHYSTS_IE_MAX = RTW89_PHYSTS_IE_NUM - 1
  178. };
  179. enum rtw89_phy_status_bitmap {
  180. RTW89_TD_SEARCH_FAIL = 0,
  181. RTW89_BRK_BY_TX_PKT = 1,
  182. RTW89_CCA_SPOOF = 2,
  183. RTW89_OFDM_BRK = 3,
  184. RTW89_CCK_BRK = 4,
  185. RTW89_DL_MU_SPOOFING = 5,
  186. RTW89_HE_MU = 6,
  187. RTW89_VHT_MU = 7,
  188. RTW89_UL_TB_SPOOFING = 8,
  189. RTW89_RSVD_9 = 9,
  190. RTW89_TRIG_BASE_PPDU = 10,
  191. RTW89_CCK_PKT = 11,
  192. RTW89_LEGACY_OFDM_PKT = 12,
  193. RTW89_HT_PKT = 13,
  194. RTW89_VHT_PKT = 14,
  195. RTW89_HE_PKT = 15,
  196. RTW89_PHYSTS_BITMAP_NUM
  197. };
  198. enum rtw89_dig_gain_type {
  199. RTW89_DIG_GAIN_LNA_G = 0,
  200. RTW89_DIG_GAIN_TIA_G = 1,
  201. RTW89_DIG_GAIN_LNA_A = 2,
  202. RTW89_DIG_GAIN_TIA_A = 3,
  203. RTW89_DIG_GAIN_MAX = 4
  204. };
  205. enum rtw89_dig_gain_lna_idx {
  206. RTW89_DIG_GAIN_LNA_IDX1 = 1,
  207. RTW89_DIG_GAIN_LNA_IDX2 = 2,
  208. RTW89_DIG_GAIN_LNA_IDX3 = 3,
  209. RTW89_DIG_GAIN_LNA_IDX4 = 4,
  210. RTW89_DIG_GAIN_LNA_IDX5 = 5,
  211. RTW89_DIG_GAIN_LNA_IDX6 = 6
  212. };
  213. enum rtw89_dig_gain_tia_idx {
  214. RTW89_DIG_GAIN_TIA_IDX0 = 0,
  215. RTW89_DIG_GAIN_TIA_IDX1 = 1
  216. };
  217. enum rtw89_tssi_bandedge_cfg {
  218. RTW89_TSSI_BANDEDGE_FLAT,
  219. RTW89_TSSI_BANDEDGE_LOW,
  220. RTW89_TSSI_BANDEDGE_MID,
  221. RTW89_TSSI_BANDEDGE_HIGH,
  222. RTW89_TSSI_CFG_NUM,
  223. };
  224. enum rtw89_tssi_sbw_idx {
  225. RTW89_TSSI_SBW20,
  226. RTW89_TSSI_SBW40_0,
  227. RTW89_TSSI_SBW40_1,
  228. RTW89_TSSI_SBW80_0,
  229. RTW89_TSSI_SBW80_1,
  230. RTW89_TSSI_SBW80_2,
  231. RTW89_TSSI_SBW80_3,
  232. RTW89_TSSI_SBW160_0,
  233. RTW89_TSSI_SBW160_1,
  234. RTW89_TSSI_SBW160_2,
  235. RTW89_TSSI_SBW160_3,
  236. RTW89_TSSI_SBW160_4,
  237. RTW89_TSSI_SBW160_5,
  238. RTW89_TSSI_SBW160_6,
  239. RTW89_TSSI_SBW160_7,
  240. RTW89_TSSI_SBW_NUM,
  241. };
  242. struct rtw89_txpwr_byrate_cfg {
  243. enum rtw89_band band;
  244. enum rtw89_nss nss;
  245. enum rtw89_rate_section rs;
  246. u8 shf;
  247. u8 len;
  248. u32 data;
  249. };
  250. #define DELTA_SWINGIDX_SIZE 30
  251. struct rtw89_txpwr_track_cfg {
  252. const s8 (*delta_swingidx_6gb_n)[DELTA_SWINGIDX_SIZE];
  253. const s8 (*delta_swingidx_6gb_p)[DELTA_SWINGIDX_SIZE];
  254. const s8 (*delta_swingidx_6ga_n)[DELTA_SWINGIDX_SIZE];
  255. const s8 (*delta_swingidx_6ga_p)[DELTA_SWINGIDX_SIZE];
  256. const s8 (*delta_swingidx_5gb_n)[DELTA_SWINGIDX_SIZE];
  257. const s8 (*delta_swingidx_5gb_p)[DELTA_SWINGIDX_SIZE];
  258. const s8 (*delta_swingidx_5ga_n)[DELTA_SWINGIDX_SIZE];
  259. const s8 (*delta_swingidx_5ga_p)[DELTA_SWINGIDX_SIZE];
  260. const s8 *delta_swingidx_2gb_n;
  261. const s8 *delta_swingidx_2gb_p;
  262. const s8 *delta_swingidx_2ga_n;
  263. const s8 *delta_swingidx_2ga_p;
  264. const s8 *delta_swingidx_2g_cck_b_n;
  265. const s8 *delta_swingidx_2g_cck_b_p;
  266. const s8 *delta_swingidx_2g_cck_a_n;
  267. const s8 *delta_swingidx_2g_cck_a_p;
  268. };
  269. struct rtw89_phy_dig_gain_cfg {
  270. const struct rtw89_reg_def *table;
  271. u8 size;
  272. };
  273. struct rtw89_phy_dig_gain_table {
  274. const struct rtw89_phy_dig_gain_cfg *cfg_lna_g;
  275. const struct rtw89_phy_dig_gain_cfg *cfg_tia_g;
  276. const struct rtw89_phy_dig_gain_cfg *cfg_lna_a;
  277. const struct rtw89_phy_dig_gain_cfg *cfg_tia_a;
  278. };
  279. struct rtw89_phy_tssi_dbw_table {
  280. u32 data[RTW89_TSSI_CFG_NUM][RTW89_TSSI_SBW_NUM];
  281. };
  282. struct rtw89_phy_reg3_tbl {
  283. const struct rtw89_reg3_def *reg3;
  284. int size;
  285. };
  286. #define DECLARE_PHY_REG3_TBL(_name) \
  287. const struct rtw89_phy_reg3_tbl _name ## _tbl = { \
  288. .reg3 = _name, \
  289. .size = ARRAY_SIZE(_name), \
  290. }
  291. struct rtw89_nbi_reg_def {
  292. struct rtw89_reg_def notch1_idx;
  293. struct rtw89_reg_def notch1_frac_idx;
  294. struct rtw89_reg_def notch1_en;
  295. struct rtw89_reg_def notch2_idx;
  296. struct rtw89_reg_def notch2_frac_idx;
  297. struct rtw89_reg_def notch2_en;
  298. };
  299. struct rtw89_ccx_regs {
  300. u32 setting_addr;
  301. u32 edcca_opt_mask;
  302. u32 measurement_trig_mask;
  303. u32 trig_opt_mask;
  304. u32 en_mask;
  305. u32 ifs_cnt_addr;
  306. u32 ifs_clm_period_mask;
  307. u32 ifs_clm_cnt_unit_mask;
  308. u32 ifs_clm_cnt_clear_mask;
  309. u32 ifs_collect_en_mask;
  310. u32 ifs_t1_addr;
  311. u32 ifs_t1_th_h_mask;
  312. u32 ifs_t1_en_mask;
  313. u32 ifs_t1_th_l_mask;
  314. u32 ifs_t2_addr;
  315. u32 ifs_t2_th_h_mask;
  316. u32 ifs_t2_en_mask;
  317. u32 ifs_t2_th_l_mask;
  318. u32 ifs_t3_addr;
  319. u32 ifs_t3_th_h_mask;
  320. u32 ifs_t3_en_mask;
  321. u32 ifs_t3_th_l_mask;
  322. u32 ifs_t4_addr;
  323. u32 ifs_t4_th_h_mask;
  324. u32 ifs_t4_en_mask;
  325. u32 ifs_t4_th_l_mask;
  326. u32 ifs_clm_tx_cnt_addr;
  327. u32 ifs_clm_edcca_excl_cca_fa_mask;
  328. u32 ifs_clm_tx_cnt_msk;
  329. u32 ifs_clm_cca_addr;
  330. u32 ifs_clm_ofdmcca_excl_fa_mask;
  331. u32 ifs_clm_cckcca_excl_fa_mask;
  332. u32 ifs_clm_fa_addr;
  333. u32 ifs_clm_ofdm_fa_mask;
  334. u32 ifs_clm_cck_fa_mask;
  335. u32 ifs_his_addr;
  336. u32 ifs_t4_his_mask;
  337. u32 ifs_t3_his_mask;
  338. u32 ifs_t2_his_mask;
  339. u32 ifs_t1_his_mask;
  340. u32 ifs_avg_l_addr;
  341. u32 ifs_t2_avg_mask;
  342. u32 ifs_t1_avg_mask;
  343. u32 ifs_avg_h_addr;
  344. u32 ifs_t4_avg_mask;
  345. u32 ifs_t3_avg_mask;
  346. u32 ifs_cca_l_addr;
  347. u32 ifs_t2_cca_mask;
  348. u32 ifs_t1_cca_mask;
  349. u32 ifs_cca_h_addr;
  350. u32 ifs_t4_cca_mask;
  351. u32 ifs_t3_cca_mask;
  352. u32 ifs_total_addr;
  353. u32 ifs_cnt_done_mask;
  354. u32 ifs_total_mask;
  355. };
  356. struct rtw89_physts_regs {
  357. u32 setting_addr;
  358. u32 dis_trigger_fail_mask;
  359. u32 dis_trigger_brk_mask;
  360. };
  361. struct rtw89_phy_gen_def {
  362. u32 cr_base;
  363. const struct rtw89_ccx_regs *ccx;
  364. const struct rtw89_physts_regs *physts;
  365. };
  366. extern const struct rtw89_phy_gen_def rtw89_phy_gen_ax;
  367. extern const struct rtw89_phy_gen_def rtw89_phy_gen_be;
  368. static inline void rtw89_phy_write8(struct rtw89_dev *rtwdev,
  369. u32 addr, u8 data)
  370. {
  371. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  372. rtw89_write8(rtwdev, addr + phy->cr_base, data);
  373. }
  374. static inline void rtw89_phy_write16(struct rtw89_dev *rtwdev,
  375. u32 addr, u16 data)
  376. {
  377. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  378. rtw89_write16(rtwdev, addr + phy->cr_base, data);
  379. }
  380. static inline void rtw89_phy_write32(struct rtw89_dev *rtwdev,
  381. u32 addr, u32 data)
  382. {
  383. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  384. rtw89_write32(rtwdev, addr + phy->cr_base, data);
  385. }
  386. static inline void rtw89_phy_write32_set(struct rtw89_dev *rtwdev,
  387. u32 addr, u32 bits)
  388. {
  389. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  390. rtw89_write32_set(rtwdev, addr + phy->cr_base, bits);
  391. }
  392. static inline void rtw89_phy_write32_clr(struct rtw89_dev *rtwdev,
  393. u32 addr, u32 bits)
  394. {
  395. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  396. rtw89_write32_clr(rtwdev, addr + phy->cr_base, bits);
  397. }
  398. static inline void rtw89_phy_write32_mask(struct rtw89_dev *rtwdev,
  399. u32 addr, u32 mask, u32 data)
  400. {
  401. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  402. rtw89_write32_mask(rtwdev, addr + phy->cr_base, mask, data);
  403. }
  404. static inline u8 rtw89_phy_read8(struct rtw89_dev *rtwdev, u32 addr)
  405. {
  406. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  407. return rtw89_read8(rtwdev, addr + phy->cr_base);
  408. }
  409. static inline u16 rtw89_phy_read16(struct rtw89_dev *rtwdev, u32 addr)
  410. {
  411. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  412. return rtw89_read16(rtwdev, addr + phy->cr_base);
  413. }
  414. static inline u32 rtw89_phy_read32(struct rtw89_dev *rtwdev, u32 addr)
  415. {
  416. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  417. return rtw89_read32(rtwdev, addr + phy->cr_base);
  418. }
  419. static inline u32 rtw89_phy_read32_mask(struct rtw89_dev *rtwdev,
  420. u32 addr, u32 mask)
  421. {
  422. const struct rtw89_phy_gen_def *phy = rtwdev->chip->phy_def;
  423. return rtw89_read32_mask(rtwdev, addr + phy->cr_base, mask);
  424. }
  425. static inline
  426. enum rtw89_gain_offset rtw89_subband_to_gain_offset_band_of_ofdm(enum rtw89_subband subband)
  427. {
  428. switch (subband) {
  429. default:
  430. case RTW89_CH_2G:
  431. return RTW89_GAIN_OFFSET_2G_OFDM;
  432. case RTW89_CH_5G_BAND_1:
  433. return RTW89_GAIN_OFFSET_5G_LOW;
  434. case RTW89_CH_5G_BAND_3:
  435. return RTW89_GAIN_OFFSET_5G_MID;
  436. case RTW89_CH_5G_BAND_4:
  437. return RTW89_GAIN_OFFSET_5G_HIGH;
  438. }
  439. }
  440. static inline
  441. enum rtw89_phy_bb_gain_band rtw89_subband_to_bb_gain_band(enum rtw89_subband subband)
  442. {
  443. switch (subband) {
  444. default:
  445. case RTW89_CH_2G:
  446. return RTW89_BB_GAIN_BAND_2G;
  447. case RTW89_CH_5G_BAND_1:
  448. return RTW89_BB_GAIN_BAND_5G_L;
  449. case RTW89_CH_5G_BAND_3:
  450. return RTW89_BB_GAIN_BAND_5G_M;
  451. case RTW89_CH_5G_BAND_4:
  452. return RTW89_BB_GAIN_BAND_5G_H;
  453. case RTW89_CH_6G_BAND_IDX0:
  454. case RTW89_CH_6G_BAND_IDX1:
  455. return RTW89_BB_GAIN_BAND_6G_L;
  456. case RTW89_CH_6G_BAND_IDX2:
  457. case RTW89_CH_6G_BAND_IDX3:
  458. return RTW89_BB_GAIN_BAND_6G_M;
  459. case RTW89_CH_6G_BAND_IDX4:
  460. case RTW89_CH_6G_BAND_IDX5:
  461. return RTW89_BB_GAIN_BAND_6G_H;
  462. case RTW89_CH_6G_BAND_IDX6:
  463. case RTW89_CH_6G_BAND_IDX7:
  464. return RTW89_BB_GAIN_BAND_6G_UH;
  465. }
  466. }
  467. enum rtw89_rfk_flag {
  468. RTW89_RFK_F_WRF = 0,
  469. RTW89_RFK_F_WM = 1,
  470. RTW89_RFK_F_WS = 2,
  471. RTW89_RFK_F_WC = 3,
  472. RTW89_RFK_F_DELAY = 4,
  473. RTW89_RFK_F_NUM,
  474. };
  475. struct rtw89_rfk_tbl {
  476. const struct rtw89_reg5_def *defs;
  477. u32 size;
  478. };
  479. #define RTW89_DECLARE_RFK_TBL(_name) \
  480. const struct rtw89_rfk_tbl _name ## _tbl = { \
  481. .defs = _name, \
  482. .size = ARRAY_SIZE(_name), \
  483. }
  484. #define RTW89_DECL_RFK_WRF(_path, _addr, _mask, _data) \
  485. {.flag = RTW89_RFK_F_WRF, \
  486. .path = _path, \
  487. .addr = _addr, \
  488. .mask = _mask, \
  489. .data = _data,}
  490. #define RTW89_DECL_RFK_WM(_addr, _mask, _data) \
  491. {.flag = RTW89_RFK_F_WM, \
  492. .addr = _addr, \
  493. .mask = _mask, \
  494. .data = _data,}
  495. #define RTW89_DECL_RFK_WS(_addr, _mask) \
  496. {.flag = RTW89_RFK_F_WS, \
  497. .addr = _addr, \
  498. .mask = _mask,}
  499. #define RTW89_DECL_RFK_WC(_addr, _mask) \
  500. {.flag = RTW89_RFK_F_WC, \
  501. .addr = _addr, \
  502. .mask = _mask,}
  503. #define RTW89_DECL_RFK_DELAY(_data) \
  504. {.flag = RTW89_RFK_F_DELAY, \
  505. .data = _data,}
  506. void
  507. rtw89_rfk_parser(struct rtw89_dev *rtwdev, const struct rtw89_rfk_tbl *tbl);
  508. #define rtw89_rfk_parser_by_cond(dev, cond, tbl_t, tbl_f) \
  509. do { \
  510. typeof(dev) __dev = (dev); \
  511. if (cond) \
  512. rtw89_rfk_parser(__dev, (tbl_t)); \
  513. else \
  514. rtw89_rfk_parser(__dev, (tbl_f)); \
  515. } while (0)
  516. void rtw89_phy_write_reg3_tbl(struct rtw89_dev *rtwdev,
  517. const struct rtw89_phy_reg3_tbl *tbl);
  518. u8 rtw89_phy_get_txsc(struct rtw89_dev *rtwdev,
  519. const struct rtw89_chan *chan,
  520. enum rtw89_bandwidth dbw);
  521. u32 rtw89_phy_read_rf(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
  522. u32 addr, u32 mask);
  523. u32 rtw89_phy_read_rf_v1(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
  524. u32 addr, u32 mask);
  525. bool rtw89_phy_write_rf(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
  526. u32 addr, u32 mask, u32 data);
  527. bool rtw89_phy_write_rf_v1(struct rtw89_dev *rtwdev, enum rtw89_rf_path rf_path,
  528. u32 addr, u32 mask, u32 data);
  529. void rtw89_phy_init_bb_reg(struct rtw89_dev *rtwdev);
  530. void rtw89_phy_init_rf_reg(struct rtw89_dev *rtwdev, bool noio);
  531. void rtw89_phy_config_rf_reg_v1(struct rtw89_dev *rtwdev,
  532. const struct rtw89_reg2_def *reg,
  533. enum rtw89_rf_path rf_path,
  534. void *extra_data);
  535. void rtw89_phy_dm_init(struct rtw89_dev *rtwdev);
  536. void rtw89_phy_write32_idx(struct rtw89_dev *rtwdev, u32 addr, u32 mask,
  537. u32 data, enum rtw89_phy_idx phy_idx);
  538. u32 rtw89_phy_read32_idx(struct rtw89_dev *rtwdev, u32 addr, u32 mask,
  539. enum rtw89_phy_idx phy_idx);
  540. s8 *rtw89_phy_raw_byr_seek(struct rtw89_dev *rtwdev,
  541. struct rtw89_txpwr_byrate *head,
  542. const struct rtw89_rate_desc *desc);
  543. void rtw89_phy_load_txpwr_byrate(struct rtw89_dev *rtwdev,
  544. const struct rtw89_txpwr_table *tbl);
  545. s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band,
  546. u8 bw, u8 ntx, u8 rs, u8 bf, u8 ch);
  547. void rtw89_phy_set_txpwr_byrate(struct rtw89_dev *rtwdev,
  548. const struct rtw89_chan *chan,
  549. enum rtw89_phy_idx phy_idx);
  550. void rtw89_phy_set_txpwr_offset(struct rtw89_dev *rtwdev,
  551. const struct rtw89_chan *chan,
  552. enum rtw89_phy_idx phy_idx);
  553. void rtw89_phy_set_txpwr_limit(struct rtw89_dev *rtwdev,
  554. const struct rtw89_chan *chan,
  555. enum rtw89_phy_idx phy_idx);
  556. void rtw89_phy_set_txpwr_limit_ru(struct rtw89_dev *rtwdev,
  557. const struct rtw89_chan *chan,
  558. enum rtw89_phy_idx phy_idx);
  559. void rtw89_phy_ra_assoc(struct rtw89_dev *rtwdev, struct ieee80211_sta *sta);
  560. void rtw89_phy_ra_update(struct rtw89_dev *rtwdev);
  561. void rtw89_phy_ra_updata_sta(struct rtw89_dev *rtwdev, struct ieee80211_sta *sta,
  562. u32 changed);
  563. void rtw89_phy_rate_pattern_vif(struct rtw89_dev *rtwdev,
  564. struct ieee80211_vif *vif,
  565. const struct cfg80211_bitrate_mask *mask);
  566. void rtw89_phy_c2h_handle(struct rtw89_dev *rtwdev, struct sk_buff *skb,
  567. u32 len, u8 class, u8 func);
  568. void rtw89_phy_cfo_track(struct rtw89_dev *rtwdev);
  569. void rtw89_phy_cfo_track_work(struct work_struct *work);
  570. void rtw89_phy_cfo_parse(struct rtw89_dev *rtwdev, s16 cfo_val,
  571. struct rtw89_rx_phy_ppdu *phy_ppdu);
  572. void rtw89_phy_stat_track(struct rtw89_dev *rtwdev);
  573. void rtw89_phy_env_monitor_track(struct rtw89_dev *rtwdev);
  574. void rtw89_phy_set_phy_regs(struct rtw89_dev *rtwdev, u32 addr, u32 mask,
  575. u32 val);
  576. void rtw89_phy_dig_reset(struct rtw89_dev *rtwdev);
  577. void rtw89_phy_dig(struct rtw89_dev *rtwdev);
  578. void rtw89_phy_tx_path_div_track(struct rtw89_dev *rtwdev);
  579. void rtw89_phy_antdiv_parse(struct rtw89_dev *rtwdev,
  580. struct rtw89_rx_phy_ppdu *phy_ppdu);
  581. void rtw89_phy_antdiv_track(struct rtw89_dev *rtwdev);
  582. void rtw89_phy_antdiv_work(struct work_struct *work);
  583. void rtw89_phy_set_bss_color(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif);
  584. void rtw89_phy_tssi_ctrl_set_bandedge_cfg(struct rtw89_dev *rtwdev,
  585. enum rtw89_mac_idx mac_idx,
  586. enum rtw89_tssi_bandedge_cfg bandedge_cfg);
  587. void rtw89_phy_ul_tb_assoc(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
  588. void rtw89_phy_ul_tb_ctrl_track(struct rtw89_dev *rtwdev);
  589. u8 rtw89_encode_chan_idx(struct rtw89_dev *rtwdev, u8 central_ch, u8 band);
  590. void rtw89_decode_chan_idx(struct rtw89_dev *rtwdev, u8 chan_idx,
  591. u8 *ch, enum nl80211_band *band);
  592. void rtw89_phy_config_edcca(struct rtw89_dev *rtwdev, bool scan);
  593. #endif