coex.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright(c) 2018-2019 Realtek Corporation
  3. */
  4. #ifndef __RTW_COEX_H__
  5. #define __RTW_COEX_H__
  6. #define COEX_CCK_2 0x1
  7. #define COEX_RESP_ACK_BY_WL_FW 0x1
  8. #define COEX_REQUEST_TIMEOUT msecs_to_jiffies(10)
  9. #define COEX_MIN_DELAY 10 /* delay unit in ms */
  10. #define COEX_RFK_TIMEOUT 600 /* RFK timeout in ms */
  11. #define COEX_BT_GAMEHID_CNT 800
  12. #define COEX_RF_OFF 0x0
  13. #define COEX_RF_ON 0x1
  14. #define COEX_H2C69_WL_LEAKAP 0xc
  15. #define PARA1_H2C69_DIS_5MS 0x1
  16. #define PARA1_H2C69_EN_5MS 0x0
  17. #define COEX_H2C69_TDMA_SLOT 0xb
  18. #define PARA1_H2C69_TDMA_4SLOT 0xc1
  19. #define PARA1_H2C69_TDMA_2SLOT 0x1
  20. #define PARA1_H2C69_TBTT_TIMES GENMASK(5, 0)
  21. #define PARA1_H2C69_TBTT_DIV100 BIT(7)
  22. #define COEX_H2C69_TOGGLE_TABLE_A 0xd
  23. #define COEX_H2C69_TOGGLE_TABLE_B 0x7
  24. #define TDMA_4SLOT BIT(8)
  25. #define TDMA_TIMER_TYPE_2SLOT 0
  26. #define TDMA_TIMER_TYPE_4SLOT 3
  27. #define COEX_RSSI_STEP 4
  28. #define COEX_RSSI_HIGH(rssi) \
  29. ({ typeof(rssi) __rssi__ = rssi; \
  30. (__rssi__ == COEX_RSSI_STATE_HIGH || \
  31. __rssi__ == COEX_RSSI_STATE_STAY_HIGH ? true : false); })
  32. #define COEX_RSSI_MEDIUM(rssi) \
  33. ({ typeof(rssi) __rssi__ = rssi; \
  34. (__rssi__ == COEX_RSSI_STATE_MEDIUM || \
  35. __rssi__ == COEX_RSSI_STATE_STAY_MEDIUM ? true : false); })
  36. #define COEX_RSSI_LOW(rssi) \
  37. ({ typeof(rssi) __rssi__ = rssi; \
  38. (__rssi__ == COEX_RSSI_STATE_LOW || \
  39. __rssi__ == COEX_RSSI_STATE_STAY_LOW ? true : false); })
  40. #define GET_COEX_RESP_BT_SUPP_VER(payload) \
  41. le64_get_bits(*((__le64 *)(payload)), GENMASK_ULL(39, 32))
  42. #define GET_COEX_RESP_BT_SUPP_FEAT(payload) \
  43. le64_get_bits(*((__le64 *)(payload)), GENMASK_ULL(39, 24))
  44. #define GET_COEX_RESP_BT_PATCH_VER(payload) \
  45. le64_get_bits(*((__le64 *)(payload)), GENMASK_ULL(55, 24))
  46. #define GET_COEX_RESP_BT_REG_VAL(payload) \
  47. le64_get_bits(*((__le64 *)(payload)), GENMASK_ULL(39, 24))
  48. #define GET_COEX_RESP_BT_SCAN_TYPE(payload) \
  49. le64_get_bits(*((__le64 *)(payload)), GENMASK(31, 24))
  50. enum coex_mp_info_op {
  51. BT_MP_INFO_OP_PATCH_VER = 0x00,
  52. BT_MP_INFO_OP_READ_REG = 0x11,
  53. BT_MP_INFO_OP_SUPP_FEAT = 0x2a,
  54. BT_MP_INFO_OP_SUPP_VER = 0x2b,
  55. BT_MP_INFO_OP_SCAN_TYPE = 0x2d,
  56. BT_MP_INFO_OP_LNA_CONSTRAINT = 0x32,
  57. };
  58. enum coex_set_ant_phase {
  59. COEX_SET_ANT_INIT,
  60. COEX_SET_ANT_WONLY,
  61. COEX_SET_ANT_WOFF,
  62. COEX_SET_ANT_2G,
  63. COEX_SET_ANT_5G,
  64. COEX_SET_ANT_POWERON,
  65. COEX_SET_ANT_2G_WLBT,
  66. COEX_SET_ANT_2G_FREERUN,
  67. COEX_SET_ANT_MAX
  68. };
  69. enum coex_runreason {
  70. COEX_RSN_2GSCANSTART = 0,
  71. COEX_RSN_5GSCANSTART = 1,
  72. COEX_RSN_SCANFINISH = 2,
  73. COEX_RSN_2GSWITCHBAND = 3,
  74. COEX_RSN_5GSWITCHBAND = 4,
  75. COEX_RSN_2GCONSTART = 5,
  76. COEX_RSN_5GCONSTART = 6,
  77. COEX_RSN_2GCONFINISH = 7,
  78. COEX_RSN_5GCONFINISH = 8,
  79. COEX_RSN_2GMEDIA = 9,
  80. COEX_RSN_5GMEDIA = 10,
  81. COEX_RSN_MEDIADISCON = 11,
  82. COEX_RSN_BTINFO = 12,
  83. COEX_RSN_LPS = 13,
  84. COEX_RSN_WLSTATUS = 14,
  85. COEX_RSN_BTSTATUS = 15,
  86. COEX_RSN_MAX
  87. };
  88. enum coex_lte_coex_table_type {
  89. COEX_CTT_WL_VS_LTE,
  90. COEX_CTT_BT_VS_LTE,
  91. };
  92. enum coex_gnt_setup_state {
  93. COEX_GNT_SET_HW_PTA = 0x0,
  94. COEX_GNT_SET_SW_LOW = 0x1,
  95. COEX_GNT_SET_SW_HIGH = 0x3,
  96. };
  97. enum coex_ext_ant_switch_pos_type {
  98. COEX_SWITCH_TO_BT,
  99. COEX_SWITCH_TO_WLG,
  100. COEX_SWITCH_TO_WLA,
  101. COEX_SWITCH_TO_NOCARE,
  102. COEX_SWITCH_TO_WLG_BT,
  103. COEX_SWITCH_TO_MAX
  104. };
  105. enum coex_ext_ant_switch_ctrl_type {
  106. COEX_SWITCH_CTRL_BY_BBSW,
  107. COEX_SWITCH_CTRL_BY_PTA,
  108. COEX_SWITCH_CTRL_BY_ANTDIV,
  109. COEX_SWITCH_CTRL_BY_MAC,
  110. COEX_SWITCH_CTRL_BY_BT,
  111. COEX_SWITCH_CTRL_BY_FW,
  112. COEX_SWITCH_CTRL_MAX
  113. };
  114. enum coex_algorithm {
  115. COEX_ALGO_NOPROFILE = 0,
  116. COEX_ALGO_HFP = 1,
  117. COEX_ALGO_HID = 2,
  118. COEX_ALGO_A2DP = 3,
  119. COEX_ALGO_PAN = 4,
  120. COEX_ALGO_A2DP_HID = 5,
  121. COEX_ALGO_A2DP_PAN = 6,
  122. COEX_ALGO_PAN_HID = 7,
  123. COEX_ALGO_A2DP_PAN_HID = 8,
  124. COEX_ALGO_MAX
  125. };
  126. enum coex_bt_profile {
  127. BPM_NOPROFILE = 0,
  128. BPM_HFP = BIT(0),
  129. BPM_HID = BIT(1),
  130. BPM_A2DP = BIT(2),
  131. BPM_PAN = BIT(3),
  132. BPM_HID_HFP = BPM_HID | BPM_HFP,
  133. BPM_A2DP_HFP = BPM_A2DP | BPM_HFP,
  134. BPM_A2DP_HID = BPM_A2DP | BPM_HID,
  135. BPM_A2DP_HID_HFP = BPM_A2DP | BPM_HID | BPM_HFP,
  136. BPM_PAN_HFP = BPM_PAN | BPM_HFP,
  137. BPM_PAN_HID = BPM_PAN | BPM_HID,
  138. BPM_PAN_HID_HFP = BPM_PAN | BPM_HID | BPM_HFP,
  139. BPM_PAN_A2DP = BPM_PAN | BPM_A2DP,
  140. BPM_PAN_A2DP_HFP = BPM_PAN | BPM_A2DP | BPM_HFP,
  141. BPM_PAN_A2DP_HID = BPM_PAN | BPM_A2DP | BPM_HID,
  142. BPM_PAN_A2DP_HID_HFP = BPM_PAN | BPM_A2DP | BPM_HID | BPM_HFP,
  143. };
  144. enum coex_wl_link_mode {
  145. COEX_WLINK_2G1PORT = 0x0,
  146. COEX_WLINK_5G = 0x3,
  147. COEX_WLINK_2GFREE = 0x7,
  148. COEX_WLINK_MAX
  149. };
  150. enum coex_wl2bt_scoreboard {
  151. COEX_SCBD_ACTIVE = BIT(0),
  152. COEX_SCBD_ONOFF = BIT(1),
  153. COEX_SCBD_SCAN = BIT(2),
  154. COEX_SCBD_UNDERTEST = BIT(3),
  155. COEX_SCBD_RXGAIN = BIT(4),
  156. COEX_SCBD_BT_RFK = BIT(5),
  157. COEX_SCBD_WLBUSY = BIT(6),
  158. COEX_SCBD_EXTFEM = BIT(8),
  159. COEX_SCBD_TDMA = BIT(9),
  160. COEX_SCBD_FIX2M = BIT(10),
  161. COEX_SCBD_ALL = GENMASK(15, 0),
  162. };
  163. enum coex_power_save_type {
  164. COEX_PS_WIFI_NATIVE = 0,
  165. COEX_PS_LPS_ON = 1,
  166. COEX_PS_LPS_OFF = 2,
  167. };
  168. enum coex_rssi_state {
  169. COEX_RSSI_STATE_HIGH,
  170. COEX_RSSI_STATE_MEDIUM,
  171. COEX_RSSI_STATE_LOW,
  172. COEX_RSSI_STATE_STAY_HIGH,
  173. COEX_RSSI_STATE_STAY_MEDIUM,
  174. COEX_RSSI_STATE_STAY_LOW,
  175. };
  176. enum coex_notify_type_ips {
  177. COEX_IPS_LEAVE = 0x0,
  178. COEX_IPS_ENTER = 0x1,
  179. };
  180. enum coex_notify_type_lps {
  181. COEX_LPS_DISABLE = 0x0,
  182. COEX_LPS_ENABLE = 0x1,
  183. };
  184. enum coex_notify_type_scan {
  185. COEX_SCAN_FINISH,
  186. COEX_SCAN_START,
  187. COEX_SCAN_START_2G,
  188. COEX_SCAN_START_5G,
  189. };
  190. enum coex_notify_type_switchband {
  191. COEX_NOT_SWITCH,
  192. COEX_SWITCH_TO_24G,
  193. COEX_SWITCH_TO_5G,
  194. COEX_SWITCH_TO_24G_NOFORSCAN,
  195. };
  196. enum coex_notify_type_associate {
  197. COEX_ASSOCIATE_FINISH,
  198. COEX_ASSOCIATE_START,
  199. COEX_ASSOCIATE_5G_FINISH,
  200. COEX_ASSOCIATE_5G_START,
  201. };
  202. enum coex_notify_type_media_status {
  203. COEX_MEDIA_DISCONNECT,
  204. COEX_MEDIA_CONNECT,
  205. COEX_MEDIA_CONNECT_5G,
  206. };
  207. enum coex_bt_status {
  208. COEX_BTSTATUS_NCON_IDLE = 0,
  209. COEX_BTSTATUS_CON_IDLE = 1,
  210. COEX_BTSTATUS_INQ_PAGE = 2,
  211. COEX_BTSTATUS_ACL_BUSY = 3,
  212. COEX_BTSTATUS_SCO_BUSY = 4,
  213. COEX_BTSTATUS_ACL_SCO_BUSY = 5,
  214. COEX_BTSTATUS_MAX
  215. };
  216. enum coex_wl_tput_dir {
  217. COEX_WL_TPUT_TX = 0x0,
  218. COEX_WL_TPUT_RX = 0x1,
  219. COEX_WL_TPUT_MAX
  220. };
  221. enum coex_wl_priority_mask {
  222. COEX_WLPRI_RX_RSP = 2,
  223. COEX_WLPRI_TX_RSP = 3,
  224. COEX_WLPRI_TX_BEACON = 4,
  225. COEX_WLPRI_TX_OFDM = 11,
  226. COEX_WLPRI_TX_CCK = 12,
  227. COEX_WLPRI_TX_BEACONQ = 27,
  228. COEX_WLPRI_RX_CCK = 28,
  229. COEX_WLPRI_RX_OFDM = 29,
  230. COEX_WLPRI_MAX
  231. };
  232. enum coex_commom_chip_setup {
  233. COEX_CSETUP_INIT_HW = 0x0,
  234. COEX_CSETUP_ANT_SWITCH = 0x1,
  235. COEX_CSETUP_GNT_FIX = 0x2,
  236. COEX_CSETUP_GNT_DEBUG = 0x3,
  237. COEX_CSETUP_RFE_TYPE = 0x4,
  238. COEX_CSETUP_COEXINFO_HW = 0x5,
  239. COEX_CSETUP_WL_TX_POWER = 0x6,
  240. COEX_CSETUP_WL_RX_GAIN = 0x7,
  241. COEX_CSETUP_WLAN_ACT_IPS = 0x8,
  242. COEX_CSETUP_MAX
  243. };
  244. enum coex_indirect_reg_type {
  245. COEX_INDIRECT_1700 = 0x0,
  246. COEX_INDIRECT_7C0 = 0x1,
  247. COEX_INDIRECT_MAX
  248. };
  249. enum coex_pstdma_type {
  250. COEX_PSTDMA_FORCE_LPSOFF = 0x0,
  251. COEX_PSTDMA_FORCE_LPSON = 0x1,
  252. COEX_PSTDMA_MAX
  253. };
  254. enum coex_btrssi_type {
  255. COEX_BTRSSI_RATIO = 0x0,
  256. COEX_BTRSSI_DBM = 0x1,
  257. COEX_BTRSSI_MAX
  258. };
  259. struct coex_table_para {
  260. u32 bt;
  261. u32 wl;
  262. };
  263. struct coex_tdma_para {
  264. u8 para[5];
  265. };
  266. struct coex_5g_afh_map {
  267. u32 wl_5g_ch;
  268. u8 bt_skip_ch;
  269. u8 bt_skip_span;
  270. };
  271. struct coex_rf_para {
  272. u8 wl_pwr_dec_lvl;
  273. u8 bt_pwr_dec_lvl;
  274. bool wl_low_gain_en;
  275. u8 bt_lna_lvl;
  276. };
  277. static inline void rtw_coex_set_init(struct rtw_dev *rtwdev)
  278. {
  279. const struct rtw_chip_info *chip = rtwdev->chip;
  280. chip->ops->coex_set_init(rtwdev);
  281. }
  282. static inline
  283. void rtw_coex_set_ant_switch(struct rtw_dev *rtwdev, u8 ctrl_type, u8 pos_type)
  284. {
  285. const struct rtw_chip_info *chip = rtwdev->chip;
  286. if (!chip->ops->coex_set_ant_switch)
  287. return;
  288. chip->ops->coex_set_ant_switch(rtwdev, ctrl_type, pos_type);
  289. }
  290. static inline void rtw_coex_set_gnt_fix(struct rtw_dev *rtwdev)
  291. {
  292. const struct rtw_chip_info *chip = rtwdev->chip;
  293. chip->ops->coex_set_gnt_fix(rtwdev);
  294. }
  295. static inline void rtw_coex_set_gnt_debug(struct rtw_dev *rtwdev)
  296. {
  297. const struct rtw_chip_info *chip = rtwdev->chip;
  298. chip->ops->coex_set_gnt_debug(rtwdev);
  299. }
  300. static inline void rtw_coex_set_rfe_type(struct rtw_dev *rtwdev)
  301. {
  302. const struct rtw_chip_info *chip = rtwdev->chip;
  303. chip->ops->coex_set_rfe_type(rtwdev);
  304. }
  305. static inline void rtw_coex_set_wl_tx_power(struct rtw_dev *rtwdev, u8 wl_pwr)
  306. {
  307. const struct rtw_chip_info *chip = rtwdev->chip;
  308. chip->ops->coex_set_wl_tx_power(rtwdev, wl_pwr);
  309. }
  310. static inline
  311. void rtw_coex_set_wl_rx_gain(struct rtw_dev *rtwdev, bool low_gain)
  312. {
  313. const struct rtw_chip_info *chip = rtwdev->chip;
  314. chip->ops->coex_set_wl_rx_gain(rtwdev, low_gain);
  315. }
  316. void rtw_coex_info_response(struct rtw_dev *rtwdev, struct sk_buff *skb);
  317. u32 rtw_coex_read_indirect_reg(struct rtw_dev *rtwdev, u16 addr);
  318. void rtw_coex_write_indirect_reg(struct rtw_dev *rtwdev, u16 addr,
  319. u32 mask, u32 val);
  320. void rtw_coex_write_scbd(struct rtw_dev *rtwdev, u16 bitpos, bool set);
  321. void rtw_coex_bt_relink_work(struct work_struct *work);
  322. void rtw_coex_bt_reenable_work(struct work_struct *work);
  323. void rtw_coex_defreeze_work(struct work_struct *work);
  324. void rtw_coex_wl_remain_work(struct work_struct *work);
  325. void rtw_coex_bt_remain_work(struct work_struct *work);
  326. void rtw_coex_wl_connecting_work(struct work_struct *work);
  327. void rtw_coex_bt_multi_link_remain_work(struct work_struct *work);
  328. void rtw_coex_wl_ccklock_work(struct work_struct *work);
  329. void rtw_coex_power_on_setting(struct rtw_dev *rtwdev);
  330. void rtw_coex_power_off_setting(struct rtw_dev *rtwdev);
  331. void rtw_coex_init_hw_config(struct rtw_dev *rtwdev, bool wifi_only);
  332. void rtw_coex_ips_notify(struct rtw_dev *rtwdev, u8 type);
  333. void rtw_coex_lps_notify(struct rtw_dev *rtwdev, u8 type);
  334. void rtw_coex_scan_notify(struct rtw_dev *rtwdev, u8 type);
  335. void rtw_coex_connect_notify(struct rtw_dev *rtwdev, u8 type);
  336. void rtw_coex_media_status_notify(struct rtw_dev *rtwdev, u8 type);
  337. void rtw_coex_bt_info_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length);
  338. void rtw_coex_bt_hid_info_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length);
  339. void rtw_coex_wl_fwdbginfo_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length);
  340. void rtw_coex_switchband_notify(struct rtw_dev *rtwdev, u8 type);
  341. void rtw_coex_wl_status_change_notify(struct rtw_dev *rtwdev, u32 type);
  342. void rtw_coex_wl_status_check(struct rtw_dev *rtwdev);
  343. void rtw_coex_query_bt_hid_list(struct rtw_dev *rtwdev);
  344. void rtw_coex_display_coex_info(struct rtw_dev *rtwdev, struct seq_file *m);
  345. static inline bool rtw_coex_disabled(struct rtw_dev *rtwdev)
  346. {
  347. struct rtw_coex *coex = &rtwdev->coex;
  348. struct rtw_coex_stat *coex_stat = &coex->stat;
  349. return coex_stat->bt_disabled;
  350. }
  351. #endif