Lines Matching refs:rtwdev

12 static u8 rtw_coex_next_rssi_state(struct rtw_dev *rtwdev, u8 pre_state,
15 struct rtw_chip_info *chip = rtwdev->chip;
35 static void rtw_coex_limited_tx(struct rtw_dev *rtwdev,
38 struct rtw_chip_info *chip = rtwdev->chip;
39 struct rtw_coex *coex = &rtwdev->coex;
52 coex_stat->darfrc = rtw_read32(rtwdev, REG_DARFRC);
53 coex_stat->darfrch = rtw_read32(rtwdev, REG_DARFRCH);
54 coex_stat->retry_limit = rtw_read16(rtwdev, REG_RETRY_LIMIT);
59 rtw_read8(rtwdev, REG_AMPDU_MAX_TIME_V1);
68 rtw_write8_set(rtwdev, REG_TX_HANG_CTRL, BIT_EN_GNT_BT_AWAKE);
73 rtw_write8_set(rtwdev, REG_LIFETIME_EN, 0xf);
74 rtw_write16(rtwdev, REG_RETRY_LIMIT, 0x0808);
78 rtw_write32(rtwdev, REG_DARFRC, 0x1000000);
79 rtw_write32(rtwdev, REG_DARFRCH, 0x1010101);
81 rtw_write32(rtwdev, REG_DARFRC, 0x1000000);
82 rtw_write32(rtwdev, REG_DARFRCH, 0x4030201);
85 rtw_write8_clr(rtwdev, REG_TX_HANG_CTRL, BIT_EN_GNT_BT_AWAKE);
86 rtw_write8_clr(rtwdev, REG_LIFETIME_EN, 0xf);
88 rtw_write16(rtwdev, REG_RETRY_LIMIT, coex_stat->retry_limit);
89 rtw_write32(rtwdev, REG_DARFRC, coex_stat->darfrc);
90 rtw_write32(rtwdev, REG_DARFRCH, coex_stat->darfrch);
94 rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1, 0x20);
96 rtw_write8(rtwdev, REG_AMPDU_MAX_TIME_V1,
100 static void rtw_coex_limited_wl(struct rtw_dev *rtwdev)
102 struct rtw_coex *coex = &rtwdev->coex;
118 rtw_coex_limited_tx(rtwdev, tx_limit, tx_agg_ctrl);
121 static void rtw_coex_wl_ccklock_action(struct rtw_dev *rtwdev)
123 struct rtw_coex *coex = &rtwdev->coex;
134 rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
149 rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
155 rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
160 static void rtw_coex_wl_ccklock_detect(struct rtw_dev *rtwdev)
162 struct rtw_coex *coex = &rtwdev->coex;
171 static void rtw_coex_wl_noisy_detect(struct rtw_dev *rtwdev)
173 struct rtw_coex *coex = &rtwdev->coex;
175 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
217 static void rtw_coex_tdma_timer_base(struct rtw_dev *rtwdev, u8 type)
219 struct rtw_coex *coex = &rtwdev->coex;
235 rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
239 rtw_coex_wl_ccklock_action(rtwdev);
242 static void rtw_coex_set_wl_pri_mask(struct rtw_dev *rtwdev, u8 bitmap,
250 rtw_write8_mask(rtwdev, addr, BIT(bitmap), data);
253 void rtw_coex_write_scbd(struct rtw_dev *rtwdev, u16 bitpos, bool set)
255 struct rtw_chip_info *chip = rtwdev->chip;
256 struct rtw_coex *coex = &rtwdev->coex;
283 rtw_write16(rtwdev, REG_WIFI_BT_INFO, val);
288 static u16 rtw_coex_read_scbd(struct rtw_dev *rtwdev)
290 struct rtw_chip_info *chip = rtwdev->chip;
295 return (rtw_read16(rtwdev, REG_WIFI_BT_INFO)) & ~(BIT_BT_INT_EN);
298 static void rtw_coex_check_rfk(struct rtw_dev *rtwdev)
300 struct rtw_chip_info *chip = rtwdev->chip;
301 struct rtw_coex *coex = &rtwdev->coex;
313 btk = !!(rtw_coex_read_scbd(rtwdev) & COEX_SCBD_BT_RFK);
316 wlk = !!(rtw_read8(rtwdev, REG_ARFR4) & BIT_WL_RFK);
329 static void rtw_coex_query_bt_info(struct rtw_dev *rtwdev)
331 struct rtw_coex *coex = &rtwdev->coex;
337 rtw_fw_query_bt_info(rtwdev);
340 static void rtw_coex_monitor_bt_enable(struct rtw_dev *rtwdev)
342 struct rtw_chip_info *chip = rtwdev->chip;
343 struct rtw_coex *coex = &rtwdev->coex;
350 score_board = rtw_coex_read_scbd(rtwdev);
355 rtw_dbg(rtwdev, RTW_DBG_COEX, "coex: BT state changed (%d) -> (%d)\n",
365 ieee80211_queue_delayed_work(rtwdev->hw,
373 static void rtw_coex_update_wl_link_info(struct rtw_dev *rtwdev, u8 reason)
375 struct rtw_coex *coex = &rtwdev->coex;
378 struct rtw_chip_info *chip = rtwdev->chip;
379 struct rtw_traffic_stats *stats = &rtwdev->stats;
388 scan = test_bit(RTW_FLAG_SCANNING, rtwdev->flags);
389 coex_stat->wl_connected = !!rtwdev->sta_cnt;
391 wl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
396 ieee80211_queue_delayed_work(rtwdev->hw,
412 rtw_coex_wl_noisy_detect(rtwdev);
417 rssi = rtwdev->dm_info.min_rssi;
418 rssi_state = rtw_coex_next_rssi_state(rtwdev, rssi_state,
437 if (rtwdev->hal.current_band_type == RTW_BAND_5G)
458 void rtw_coex_info_response(struct rtw_dev *rtwdev, struct sk_buff *skb)
460 struct rtw_coex *coex = &rtwdev->coex;
470 static struct sk_buff *rtw_coex_info_request(struct rtw_dev *rtwdev,
473 struct rtw_coex *coex = &rtwdev->coex;
478 rtw_fw_query_bt_mp_info(rtwdev, req);
482 rtw_err(rtwdev, "coex request time out\n");
488 rtw_err(rtwdev, "failed to get coex info response\n");
497 static bool rtw_coex_get_bt_scan_type(struct rtw_dev *rtwdev, u8 *scan_type)
505 skb = rtw_coex_info_request(rtwdev, &req);
518 static bool rtw_coex_set_lna_constrain_level(struct rtw_dev *rtwdev,
527 skb = rtw_coex_info_request(rtwdev, &req);
538 static void rtw_coex_update_bt_link_info(struct rtw_dev *rtwdev)
540 struct rtw_coex *coex = &rtwdev->coex;
543 struct rtw_chip_info *chip = rtwdev->chip;
554 rssi_state = rtw_coex_next_rssi_state(rtwdev, rssi_state,
562 rssi = rtwdev->dm_info.min_rssi;
563 rssi_state = rtw_coex_next_rssi_state(rtwdev, rssi_state,
572 if (rtw_coex_get_bt_scan_type(rtwdev, &scan_type)) {
642 rtw_dbg(rtwdev, RTW_DBG_COEX, "coex: bt status(%d)\n", coex_dm->bt_status);
645 static void rtw_coex_update_wl_ch_info(struct rtw_dev *rtwdev, u8 type)
647 struct rtw_chip_info *chip = rtwdev->chip;
648 struct rtw_coex_dm *coex_dm = &rtwdev->coex.dm;
649 struct rtw_efuse *efuse = &rtwdev->efuse;
655 bw = rtwdev->hal.current_band_width;
658 center_chan = rtwdev->hal.current_channel;
684 rtw_fw_wl_ch_info(rtwdev, link, center_chan, bw);
687 static void rtw_coex_set_bt_tx_power(struct rtw_dev *rtwdev, u8 bt_pwr_dec_lvl)
689 struct rtw_coex *coex = &rtwdev->coex;
697 rtw_fw_force_bt_tx_power(rtwdev, bt_pwr_dec_lvl);
700 static void rtw_coex_set_bt_rx_gain(struct rtw_dev *rtwdev, u8 bt_lna_lvl)
702 struct rtw_coex *coex = &rtwdev->coex;
712 rtw_coex_set_lna_constrain_level(rtwdev, bt_lna_lvl);
713 rtw_coex_write_scbd(rtwdev, COEX_SCBD_RXGAIN, true);
715 rtw_coex_write_scbd(rtwdev, COEX_SCBD_RXGAIN, false);
719 static void rtw_coex_set_rf_para(struct rtw_dev *rtwdev,
722 struct rtw_coex *coex = &rtwdev->coex;
729 rtw_coex_set_wl_tx_power(rtwdev, para.wl_pwr_dec_lvl);
730 rtw_coex_set_bt_tx_power(rtwdev, para.bt_pwr_dec_lvl + offset);
731 rtw_coex_set_wl_rx_gain(rtwdev, para.wl_low_gain_en);
732 rtw_coex_set_bt_rx_gain(rtwdev, para.bt_lna_lvl);
735 u32 rtw_coex_read_indirect_reg(struct rtw_dev *rtwdev, u16 addr)
739 if (!ltecoex_read_reg(rtwdev, addr, &val)) {
740 rtw_err(rtwdev, "failed to read indirect register\n");
748 void rtw_coex_write_indirect_reg(struct rtw_dev *rtwdev, u16 addr,
754 tmp = rtw_coex_read_indirect_reg(rtwdev, addr);
757 if (!ltecoex_reg_write(rtwdev, addr, tmp))
758 rtw_err(rtwdev, "failed to write indirect register\n");
762 static void rtw_coex_coex_ctrl_owner(struct rtw_dev *rtwdev, bool wifi_control)
764 struct rtw_chip_info *chip = rtwdev->chip;
768 rtw_write32_set(rtwdev, REG_SYS_SDIO_CTRL, BIT_LTE_MUX_CTRL_PATH);
770 rtw_write8_set(rtwdev, btg_reg->addr, btg_reg->mask);
772 rtw_write32_clr(rtwdev, REG_SYS_SDIO_CTRL, BIT_LTE_MUX_CTRL_PATH);
774 rtw_write8_clr(rtwdev, btg_reg->addr, btg_reg->mask);
778 static void rtw_coex_set_gnt_bt(struct rtw_dev *rtwdev, u8 state)
780 rtw_coex_write_indirect_reg(rtwdev, 0x38, 0xc000, state);
781 rtw_coex_write_indirect_reg(rtwdev, 0x38, 0x0c00, state);
784 static void rtw_coex_set_gnt_wl(struct rtw_dev *rtwdev, u8 state)
786 rtw_coex_write_indirect_reg(rtwdev, 0x38, 0x3000, state);
787 rtw_coex_write_indirect_reg(rtwdev, 0x38, 0x0300, state);
790 static void rtw_coex_set_table(struct rtw_dev *rtwdev, u32 table0, u32 table1)
793 rtw_write32(rtwdev, REG_BT_COEX_TABLE0, table0);
794 rtw_write32(rtwdev, REG_BT_COEX_TABLE1, table1);
795 rtw_write32(rtwdev, REG_BT_COEX_BRK_TABLE, DEF_BRK_TABLE_VAL);
798 static void rtw_coex_table(struct rtw_dev *rtwdev, u8 type)
800 struct rtw_coex *coex = &rtwdev->coex;
802 struct rtw_chip_info *chip = rtwdev->chip;
803 struct rtw_efuse *efuse = &rtwdev->efuse;
809 rtw_coex_set_table(rtwdev,
815 rtw_coex_set_table(rtwdev,
821 static void rtw_coex_ignore_wlan_act(struct rtw_dev *rtwdev, bool enable)
823 struct rtw_coex *coex = &rtwdev->coex;
828 rtw_fw_bt_ignore_wlan_action(rtwdev, enable);
831 static void rtw_coex_power_save_state(struct rtw_dev *rtwdev, u8 ps_type,
834 struct rtw_coex *coex = &rtwdev->coex;
838 lps_mode = rtwdev->lps_conf.mode;
845 rtw_leave_lps(rtwdev);
850 rtw_fw_coex_tdma_type(rtwdev, 0x8, 0, 0, 0, 0);
852 rtw_leave_lps(rtwdev);
859 static void rtw_coex_set_tdma(struct rtw_dev *rtwdev, u8 byte1, u8 byte2,
862 struct rtw_coex *coex = &rtwdev->coex;
864 struct rtw_chip_info *chip = rtwdev->chip;
876 rtw_coex_power_save_state(rtwdev, ps_type, 0x0, 0x0);
882 rtw_coex_power_save_state(rtwdev, ps_type, 0x50, 0x4);
885 rtw_coex_power_save_state(rtwdev, ps_type, 0x0, 0x0);
894 rtw_fw_coex_tdma_type(rtwdev, byte1, byte2, byte3, byte4, byte5);
897 static void rtw_coex_tdma(struct rtw_dev *rtwdev, bool force, u32 tcase)
899 struct rtw_coex *coex = &rtwdev->coex;
902 struct rtw_chip_info *chip = rtwdev->chip;
903 struct rtw_efuse *efuse = &rtwdev->efuse;
909 rtw_coex_tdma_timer_base(rtwdev, 3);
911 rtw_coex_tdma_timer_base(rtwdev, 0);
926 rtw_write8_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION);
928 wl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
933 rtw_coex_write_scbd(rtwdev, COEX_SCBD_TDMA, false);
935 rtw_coex_write_scbd(rtwdev, COEX_SCBD_TDMA, true);
939 rtw_coex_set_tdma(rtwdev,
948 rtw_coex_set_tdma(rtwdev,
960 rtw_dbg(rtwdev, RTW_DBG_COEX, "coex: coex tdma type (%d)\n", type);
963 static void rtw_coex_set_ant_path(struct rtw_dev *rtwdev, bool force, u8 phase)
965 struct rtw_coex *coex = &rtwdev->coex;
977 rtw_coex_check_rfk(rtwdev);
983 rtw_coex_coex_ctrl_owner(rtwdev, true);
985 rtw_coex_coex_ctrl_owner(rtwdev, false);
993 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_LOW);
996 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
999 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_HIGH);
1002 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_LOW);
1006 rtw_coex_coex_ctrl_owner(rtwdev, true);
1013 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_LOW);
1016 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
1019 rtw_coex_coex_ctrl_owner(rtwdev, true);
1026 rtw_coex_coex_ctrl_owner(rtwdev, false);
1033 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
1036 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_HW_PTA);
1039 rtw_coex_coex_ctrl_owner(rtwdev, true);
1046 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_HIGH);
1049 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
1052 rtw_coex_coex_ctrl_owner(rtwdev, true);
1059 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_SW_HIGH);
1062 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_SW_HIGH);
1065 rtw_coex_coex_ctrl_owner(rtwdev, true);
1072 rtw_coex_set_gnt_bt(rtwdev, COEX_GNT_SET_HW_PTA);
1075 rtw_coex_set_gnt_wl(rtwdev, COEX_GNT_SET_HW_PTA);
1078 rtw_coex_coex_ctrl_owner(rtwdev, true);
1089 rtw_coex_set_ant_switch(rtwdev, ctrl_type, pos_type);
1092 static u8 rtw_coex_algorithm(struct rtw_dev *rtwdev)
1094 struct rtw_coex *coex = &rtwdev->coex;
1155 static void rtw_coex_action_coex_all_off(struct rtw_dev *rtwdev)
1157 struct rtw_efuse *efuse = &rtwdev->efuse;
1158 struct rtw_chip_info *chip = rtwdev->chip;
1171 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1172 rtw_coex_table(rtwdev, table_case);
1173 rtw_coex_tdma(rtwdev, false, tdma_case);
1176 static void rtw_coex_action_freerun(struct rtw_dev *rtwdev)
1178 struct rtw_coex *coex = &rtwdev->coex;
1181 struct rtw_efuse *efuse = &rtwdev->efuse;
1182 struct rtw_chip_info *chip = rtwdev->chip;
1191 rtw_coex_update_wl_ch_info(rtwdev, COEX_MEDIA_CONNECT);
1193 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G_FREERUN);
1195 rtw_coex_write_scbd(rtwdev, COEX_SCBD_FIX2M, false);
1210 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_tx[level]);
1212 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[level]);
1214 rtw_coex_table(rtwdev, 100);
1215 rtw_coex_tdma(rtwdev, false, 100);
1218 static void rtw_coex_action_bt_whql_test(struct rtw_dev *rtwdev)
1220 struct rtw_efuse *efuse = &rtwdev->efuse;
1221 struct rtw_chip_info *chip = rtwdev->chip;
1234 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1235 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1236 rtw_coex_table(rtwdev, table_case);
1237 rtw_coex_tdma(rtwdev, false, tdma_case);
1240 static void rtw_coex_action_bt_relink(struct rtw_dev *rtwdev)
1242 struct rtw_efuse *efuse = &rtwdev->efuse;
1243 struct rtw_chip_info *chip = rtwdev->chip;
1256 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1257 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1258 rtw_coex_table(rtwdev, table_case);
1259 rtw_coex_tdma(rtwdev, false, tdma_case);
1262 static void rtw_coex_action_bt_idle(struct rtw_dev *rtwdev)
1264 struct rtw_coex *coex = &rtwdev->coex;
1267 struct rtw_efuse *efuse = &rtwdev->efuse;
1268 struct rtw_chip_info *chip = rtwdev->chip;
1285 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G_FREERUN);
1286 rtw_coex_table(rtwdev, table_case);
1287 rtw_coex_tdma(rtwdev, false, tdma_case);
1291 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1320 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1321 rtw_coex_table(rtwdev, table_case);
1322 rtw_coex_tdma(rtwdev, false, tdma_case);
1325 static void rtw_coex_action_bt_inquiry(struct rtw_dev *rtwdev)
1327 struct rtw_coex *coex = &rtwdev->coex;
1329 struct rtw_efuse *efuse = &rtwdev->efuse;
1330 struct rtw_chip_info *chip = rtwdev->chip;
1397 rtw_dbg(rtwdev, RTW_DBG_COEX, "coex: wifi hi(%d), bt page(%d)\n",
1400 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1401 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1402 rtw_coex_table(rtwdev, table_case);
1403 rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
1406 static void rtw_coex_action_bt_hfp(struct rtw_dev *rtwdev)
1408 struct rtw_coex *coex = &rtwdev->coex;
1410 struct rtw_efuse *efuse = &rtwdev->efuse;
1411 struct rtw_chip_info *chip = rtwdev->chip;
1434 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1435 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1436 rtw_coex_table(rtwdev, table_case);
1437 rtw_coex_tdma(rtwdev, false, tdma_case);
1440 static void rtw_coex_action_bt_hid(struct rtw_dev *rtwdev)
1442 struct rtw_coex *coex = &rtwdev->coex;
1444 struct rtw_efuse *efuse = &rtwdev->efuse;
1445 struct rtw_chip_info *chip = rtwdev->chip;
1449 wl_bw = rtwdev->hal.current_band_width;
1499 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1500 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1501 rtw_coex_table(rtwdev, table_case);
1502 rtw_coex_tdma(rtwdev, false, tdma_case);
1505 static void rtw_coex_action_bt_a2dp(struct rtw_dev *rtwdev)
1507 struct rtw_coex *coex = &rtwdev->coex;
1510 struct rtw_efuse *efuse = &rtwdev->efuse;
1511 struct rtw_chip_info *chip = rtwdev->chip;
1538 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1539 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1540 rtw_coex_table(rtwdev, table_case);
1541 rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
1544 static void rtw_coex_action_bt_a2dpsink(struct rtw_dev *rtwdev)
1546 struct rtw_coex *coex = &rtwdev->coex;
1548 struct rtw_efuse *efuse = &rtwdev->efuse;
1549 struct rtw_chip_info *chip = rtwdev->chip;
1574 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1575 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1576 rtw_coex_table(rtwdev, table_case);
1577 rtw_coex_tdma(rtwdev, false, tdma_case);
1580 static void rtw_coex_action_bt_pan(struct rtw_dev *rtwdev)
1582 struct rtw_coex *coex = &rtwdev->coex;
1584 struct rtw_efuse *efuse = &rtwdev->efuse;
1585 struct rtw_chip_info *chip = rtwdev->chip;
1609 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1610 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1611 rtw_coex_table(rtwdev, table_case);
1612 rtw_coex_tdma(rtwdev, false, tdma_case);
1615 static void rtw_coex_action_bt_a2dp_hid(struct rtw_dev *rtwdev)
1617 struct rtw_coex *coex = &rtwdev->coex;
1620 struct rtw_efuse *efuse = &rtwdev->efuse;
1621 struct rtw_chip_info *chip = rtwdev->chip;
1652 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1653 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1654 rtw_coex_table(rtwdev, table_case);
1655 rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
1658 static void rtw_coex_action_bt_a2dp_pan(struct rtw_dev *rtwdev)
1660 struct rtw_coex *coex = &rtwdev->coex;
1662 struct rtw_efuse *efuse = &rtwdev->efuse;
1663 struct rtw_chip_info *chip = rtwdev->chip;
1688 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1689 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1690 rtw_coex_table(rtwdev, table_case);
1691 rtw_coex_tdma(rtwdev, false, tdma_case);
1694 static void rtw_coex_action_bt_pan_hid(struct rtw_dev *rtwdev)
1696 struct rtw_coex *coex = &rtwdev->coex;
1698 struct rtw_efuse *efuse = &rtwdev->efuse;
1699 struct rtw_chip_info *chip = rtwdev->chip;
1720 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1721 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1722 rtw_coex_table(rtwdev, table_case);
1723 rtw_coex_tdma(rtwdev, false, tdma_case);
1726 static void rtw_coex_action_bt_a2dp_pan_hid(struct rtw_dev *rtwdev)
1728 struct rtw_coex *coex = &rtwdev->coex;
1730 struct rtw_efuse *efuse = &rtwdev->efuse;
1731 struct rtw_chip_info *chip = rtwdev->chip;
1752 rtw_coex_set_ant_path(rtwdev, false, COEX_SET_ANT_2G);
1753 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1754 rtw_coex_table(rtwdev, table_case);
1755 rtw_coex_tdma(rtwdev, false, tdma_case);
1758 static void rtw_coex_action_wl_under5g(struct rtw_dev *rtwdev)
1760 struct rtw_efuse *efuse = &rtwdev->efuse;
1761 struct rtw_chip_info *chip = rtwdev->chip;
1764 rtw_coex_write_scbd(rtwdev, COEX_SCBD_FIX2M, false);
1776 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
1777 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1778 rtw_coex_table(rtwdev, table_case);
1779 rtw_coex_tdma(rtwdev, false, tdma_case);
1782 static void rtw_coex_action_wl_only(struct rtw_dev *rtwdev)
1784 struct rtw_efuse *efuse = &rtwdev->efuse;
1785 struct rtw_chip_info *chip = rtwdev->chip;
1798 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
1799 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1800 rtw_coex_table(rtwdev, table_case);
1801 rtw_coex_tdma(rtwdev, false, tdma_case);
1804 static void rtw_coex_action_wl_native_lps(struct rtw_dev *rtwdev)
1806 struct rtw_coex *coex = &rtwdev->coex;
1807 struct rtw_efuse *efuse = &rtwdev->efuse;
1808 struct rtw_chip_info *chip = rtwdev->chip;
1824 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
1825 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1826 rtw_coex_table(rtwdev, table_case);
1827 rtw_coex_tdma(rtwdev, false, tdma_case);
1830 static void rtw_coex_action_wl_linkscan(struct rtw_dev *rtwdev)
1832 struct rtw_coex *coex = &rtwdev->coex;
1834 struct rtw_efuse *efuse = &rtwdev->efuse;
1835 struct rtw_chip_info *chip = rtwdev->chip;
1860 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
1861 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1862 rtw_coex_table(rtwdev, table_case);
1863 rtw_coex_tdma(rtwdev, false, tdma_case | slot_type);
1866 static void rtw_coex_action_wl_not_connected(struct rtw_dev *rtwdev)
1868 struct rtw_efuse *efuse = &rtwdev->efuse;
1869 struct rtw_chip_info *chip = rtwdev->chip;
1882 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
1883 rtw_coex_set_rf_para(rtwdev, chip->wl_rf_para_rx[0]);
1884 rtw_coex_table(rtwdev, table_case);
1885 rtw_coex_tdma(rtwdev, false, tdma_case);
1888 static void rtw_coex_action_wl_connected(struct rtw_dev *rtwdev)
1890 struct rtw_coex *coex = &rtwdev->coex;
1893 struct rtw_efuse *efuse = &rtwdev->efuse;
1900 rtw_coex_action_freerun(rtwdev);
1904 algorithm = rtw_coex_algorithm(rtwdev);
1908 rtw_coex_action_bt_hfp(rtwdev);
1911 rtw_coex_action_bt_hid(rtwdev);
1915 rtw_coex_action_bt_a2dpsink(rtwdev);
1917 rtw_coex_action_bt_a2dp(rtwdev);
1920 rtw_coex_action_bt_pan(rtwdev);
1923 rtw_coex_action_bt_a2dp_hid(rtwdev);
1926 rtw_coex_action_bt_a2dp_pan(rtwdev);
1929 rtw_coex_action_bt_pan_hid(rtwdev);
1932 rtw_coex_action_bt_a2dp_pan_hid(rtwdev);
1936 rtw_coex_action_bt_idle(rtwdev);
1941 static void rtw_coex_run_coex(struct rtw_dev *rtwdev, u8 reason)
1943 struct rtw_coex *coex = &rtwdev->coex;
1947 lockdep_assert_held(&rtwdev->mutex);
1949 if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags))
1955 rtw_coex_update_wl_link_info(rtwdev, reason);
1957 rtw_coex_monitor_bt_enable(rtwdev);
1975 rtw_coex_action_wl_under5g(rtwdev);
1980 rtw_coex_write_scbd(rtwdev, COEX_SCBD_FIX2M, false);
1982 rtw_coex_action_wl_only(rtwdev);
1987 rtw_coex_action_wl_native_lps(rtwdev);
1992 rtw_coex_action_bt_whql_test(rtwdev);
1997 rtw_coex_action_bt_relink(rtwdev);
2002 rtw_coex_action_bt_inquiry(rtwdev);
2009 rtw_coex_action_bt_idle(rtwdev);
2014 rtw_coex_action_wl_linkscan(rtwdev);
2019 rtw_coex_action_wl_connected(rtwdev);
2021 rtw_coex_action_wl_not_connected(rtwdev);
2024 rtw_coex_set_gnt_fix(rtwdev);
2025 rtw_coex_limited_wl(rtwdev);
2028 static void rtw_coex_init_coex_var(struct rtw_dev *rtwdev)
2030 struct rtw_coex *coex = &rtwdev->coex;
2053 static void __rtw_coex_init_hw_config(struct rtw_dev *rtwdev, bool wifi_only)
2055 struct rtw_coex *coex = &rtwdev->coex;
2057 rtw_coex_init_coex_var(rtwdev);
2058 rtw_coex_monitor_bt_enable(rtwdev);
2059 rtw_coex_set_rfe_type(rtwdev);
2060 rtw_coex_set_init(rtwdev);
2063 rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_RSP, 1);
2066 rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_BEACON, 1);
2069 rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_TX_BEACONQ, 1);
2073 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WOFF);
2074 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ALL, false);
2077 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WONLY);
2078 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_SCAN,
2082 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_INIT);
2083 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_SCAN,
2090 rtw_coex_table(rtwdev, 0);
2091 rtw_coex_tdma(rtwdev, true, 0);
2092 rtw_coex_query_bt_info(rtwdev);
2095 void rtw_coex_power_on_setting(struct rtw_dev *rtwdev)
2097 struct rtw_coex *coex = &rtwdev->coex;
2103 rtw_write8_set(rtwdev, REG_SYS_FUNC_EN, BIT(0) | BIT(1));
2105 rtw_coex_monitor_bt_enable(rtwdev);
2106 rtw_coex_set_rfe_type(rtwdev);
2109 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_POWERON);
2112 rtw_write8(rtwdev, 0xff1a, 0x0);
2115 void rtw_coex_init_hw_config(struct rtw_dev *rtwdev, bool wifi_only)
2117 __rtw_coex_init_hw_config(rtwdev, wifi_only);
2120 void rtw_coex_ips_notify(struct rtw_dev *rtwdev, u8 type)
2122 struct rtw_coex *coex = &rtwdev->coex;
2132 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ALL, false);
2134 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_WOFF);
2135 rtw_coex_action_coex_all_off(rtwdev);
2137 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_ONOFF, true);
2140 __rtw_coex_init_hw_config(rtwdev, false);
2147 void rtw_coex_lps_notify(struct rtw_dev *rtwdev, u8 type)
2149 struct rtw_coex *coex = &rtwdev->coex;
2160 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
2163 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, false);
2165 rtw_coex_run_coex(rtwdev, COEX_RSN_LPS);
2171 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
2174 rtw_coex_query_bt_info(rtwdev);
2178 void rtw_coex_scan_notify(struct rtw_dev *rtwdev, u8 type)
2180 struct rtw_coex *coex = &rtwdev->coex;
2189 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_SCAN |
2193 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
2194 rtw_coex_run_coex(rtwdev, COEX_RSN_5GSCANSTART);
2199 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
2200 rtw_coex_run_coex(rtwdev, COEX_RSN_2GSCANSTART);
2203 rtw_coex_run_coex(rtwdev, COEX_RSN_SCANFINISH);
2207 void rtw_coex_switchband_notify(struct rtw_dev *rtwdev, u8 type)
2209 struct rtw_coex *coex = &rtwdev->coex;
2215 rtw_coex_run_coex(rtwdev, COEX_RSN_5GSWITCHBAND);
2217 rtw_coex_run_coex(rtwdev, COEX_RSN_2GSWITCHBAND);
2219 rtw_coex_scan_notify(rtwdev, COEX_SCAN_START_2G);
2222 void rtw_coex_connect_notify(struct rtw_dev *rtwdev, u8 type)
2224 struct rtw_coex *coex = &rtwdev->coex;
2230 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE | COEX_SCBD_SCAN |
2234 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
2235 rtw_coex_run_coex(rtwdev, COEX_RSN_5GCONSTART);
2237 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
2238 rtw_coex_run_coex(rtwdev, COEX_RSN_5GCONFINISH);
2244 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
2246 rtw_coex_run_coex(rtwdev, COEX_RSN_2GCONSTART);
2252 ieee80211_queue_delayed_work(rtwdev->hw, &coex->defreeze_work,
2258 rtw_coex_run_coex(rtwdev, COEX_RSN_2GCONFINISH);
2262 void rtw_coex_media_status_notify(struct rtw_dev *rtwdev, u8 type)
2264 struct rtw_coex *coex = &rtwdev->coex;
2272 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
2274 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_5G);
2275 rtw_coex_run_coex(rtwdev, COEX_RSN_5GMEDIA);
2277 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, true);
2280 rtw_coex_set_ant_path(rtwdev, true, COEX_SET_ANT_2G);
2283 rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_RX_CCK, 1);
2288 rtw_fw_bt_wifi_control(rtwdev, para[0], &para[1]);
2290 rtw_coex_run_coex(rtwdev, COEX_RSN_2GMEDIA);
2292 rtw_coex_write_scbd(rtwdev, COEX_SCBD_ACTIVE, false);
2294 rtw_coex_set_wl_pri_mask(rtwdev, COEX_WLPRI_RX_CCK, 0);
2296 rtw_coex_run_coex(rtwdev, COEX_RSN_MEDIADISCON);
2299 rtw_coex_update_wl_ch_info(rtwdev, type);
2302 void rtw_coex_bt_info_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length)
2304 struct rtw_coex *coex = &rtwdev->coex;
2306 struct rtw_chip_info *chip = rtwdev->chip;
2326 rtw_coex_monitor_bt_enable(rtwdev);
2329 rtw_coex_run_coex(rtwdev, COEX_RSN_BTINFO);
2339 ieee80211_queue_delayed_work(rtwdev->hw,
2353 rtw_coex_update_bt_link_info(rtwdev);
2354 rtw_coex_run_coex(rtwdev, COEX_RSN_BTINFO);
2386 ieee80211_queue_delayed_work(rtwdev->hw,
2406 rtw_coex_write_scbd(rtwdev, COEX_SCBD_SCAN, true);
2408 rtw_coex_write_scbd(rtwdev, COEX_SCBD_SCAN, false);
2410 rtw_coex_write_scbd(rtwdev, COEX_SCBD_SCAN, false);
2437 ieee80211_queue_delayed_work(rtwdev->hw,
2457 rtw_coex_update_wl_ch_info(rtwdev, type);
2463 rtw_coex_ignore_wlan_act(rtwdev, false);
2485 rtw_coex_update_bt_link_info(rtwdev);
2486 rtw_coex_run_coex(rtwdev, COEX_RSN_BTINFO);
2489 void rtw_coex_wl_fwdbginfo_notify(struct rtw_dev *rtwdev, u8 *buf, u8 length)
2491 struct rtw_coex *coex = &rtwdev->coex;
2513 rtw_coex_wl_ccklock_action(rtwdev);
2514 rtw_coex_wl_ccklock_detect(rtwdev);
2517 void rtw_coex_wl_status_change_notify(struct rtw_dev *rtwdev)
2519 struct rtw_coex *coex = &rtwdev->coex;
2524 rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
2529 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
2531 struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
2533 mutex_lock(&rtwdev->mutex);
2535 rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
2536 mutex_unlock(&rtwdev->mutex);
2541 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
2543 struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
2545 mutex_lock(&rtwdev->mutex);
2547 mutex_unlock(&rtwdev->mutex);
2552 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
2554 struct rtw_coex *coex = &rtwdev->coex;
2555 struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
2557 mutex_lock(&rtwdev->mutex);
2560 rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
2561 mutex_unlock(&rtwdev->mutex);
2566 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
2568 struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
2570 mutex_lock(&rtwdev->mutex);
2571 coex_stat->wl_gl_busy = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
2572 rtw_coex_run_coex(rtwdev, COEX_RSN_WLSTATUS);
2573 mutex_unlock(&rtwdev->mutex);
2578 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
2580 struct rtw_coex_stat *coex_stat = &rtwdev->coex.stat;
2582 mutex_lock(&rtwdev->mutex);
2584 rtw_coex_run_coex(rtwdev, COEX_RSN_BTSTATUS);
2585 mutex_unlock(&rtwdev->mutex);
2631 static int rtw_coex_addr_info(struct rtw_dev *rtwdev,
2676 static int rtw_coex_val_info(struct rtw_dev *rtwdev,
2689 rtw_read32_mask(rtwdev, reg->addr, reg->mask));
2692 rtw_read16_mask(rtwdev, reg->addr, reg->mask));
2695 rtw_read8_mask(rtwdev, reg->addr, reg->mask));
2708 rtw_read_rf(rtwdev, rf_path, reg->addr, reg->mask));
2711 static void rtw_coex_set_coexinfo_hw(struct rtw_dev *rtwdev, struct seq_file *m)
2713 struct rtw_chip_info *chip = rtwdev->chip;
2724 n_addr += rtw_coex_addr_info(rtwdev, reg, addr_info, n_addr);
2725 n_val += rtw_coex_val_info(rtwdev, reg, val_info, n_val);
2738 static bool rtw_coex_get_bt_reg(struct rtw_dev *rtwdev,
2751 skb = rtw_coex_info_request(rtwdev, &req);
2763 static bool rtw_coex_get_bt_patch_version(struct rtw_dev *rtwdev,
2772 skb = rtw_coex_info_request(rtwdev, &req);
2784 static bool rtw_coex_get_bt_supported_version(struct rtw_dev *rtwdev,
2793 skb = rtw_coex_info_request(rtwdev, &req);
2805 static bool rtw_coex_get_bt_supported_feature(struct rtw_dev *rtwdev,
2814 skb = rtw_coex_info_request(rtwdev, &req);
2850 struct rtw_dev *rtwdev;
2859 struct rtw_dev *rtwdev = vif_iter_data->rtwdev;
2872 rtw_iterate_stas_atomic(rtwdev, rtw_coex_sta_stat_iter,
2876 void rtw_coex_display_coex_info(struct rtw_dev *rtwdev, struct seq_file *m)
2878 struct rtw_chip_info *chip = rtwdev->chip;
2879 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
2880 struct rtw_coex *coex = &rtwdev->coex;
2883 struct rtw_hal *hal = &rtwdev->hal;
2884 struct rtw_efuse *efuse = &rtwdev->efuse;
2885 struct rtw_fw_state *fw = &rtwdev->fw;
2895 score_board_BW = rtw_coex_read_scbd(rtwdev);
2897 wl_reg_6c0 = rtw_read32(rtwdev, 0x6c0);
2898 wl_reg_6c4 = rtw_read32(rtwdev, 0x6c4);
2899 wl_reg_6c8 = rtw_read32(rtwdev, 0x6c8);
2900 wl_reg_6cc = rtw_read32(rtwdev, 0x6cc);
2901 wl_reg_778 = rtw_read32(rtwdev, 0x778);
2902 bt_hi_pri = rtw_read32(rtwdev, 0x770);
2903 bt_lo_pri = rtw_read32(rtwdev, 0x774);
2904 rtw_write8(rtwdev, 0x76e, 0xc);
2905 sys_lte = rtw_read8(rtwdev, 0x73);
2906 lte_coex = rtw_coex_read_indirect_reg(rtwdev, 0x38);
2907 bt_coex = rtw_coex_read_indirect_reg(rtwdev, 0x54);
2910 rtw_coex_get_bt_supported_version(rtwdev,
2912 rtw_coex_get_bt_patch_version(rtwdev, &coex_stat->patch_ver);
2913 rtw_coex_get_bt_supported_feature(rtwdev,
2915 rtw_coex_get_bt_reg(rtwdev, 3, 0xae, &coex_stat->bt_reg_vendor_ae);
2916 rtw_coex_get_bt_reg(rtwdev, 3, 0xac, &coex_stat->bt_reg_vendor_ac);
3003 "Scanning", test_bit(RTW_FLAG_SCANNING, rtwdev->flags));
3007 rtwdev->stats.tx_throughput, rtwdev->stats.rx_throughput);
3010 test_bit(RTW_FLAG_INACTIVE_PS, rtwdev->flags),
3011 test_bit(RTW_FLAG_LEISURE_PS_DEEP, rtwdev->flags),
3012 rtwdev->lps_conf.mode);
3014 vif_iter_data.rtwdev = rtwdev;
3016 rtw_iterate_vifs_atomic(rtwdev, rtw_coex_vif_stat_iter, &vif_iter_data);
3076 rtw_coex_set_coexinfo_hw(rtwdev, m);