Lines Matching defs:rtwdev
62 static void _rtw_fw_dump_dbg_info(struct rtw_dev *rtwdev,
71 val = rtw_read32_mask(rtwdev, reg->addr, reg->mask);
73 rtw_dbg(rtwdev, RTW_DBG_FW, "[%s]addr:0x%x mask:0x%x value:0x%x\n",
78 void rtw_fw_dump_dbg_info(struct rtw_dev *rtwdev)
82 if (!rtw_dbg_is_enabled(rtwdev, RTW_DBG_FW))
85 _rtw_fw_dump_dbg_info(rtwdev, fw_h2c_regs, ARRAY_SIZE(fw_h2c_regs));
86 _rtw_fw_dump_dbg_info(rtwdev, fw_c2h_regs, ARRAY_SIZE(fw_c2h_regs));
88 rtw_dbg(rtwdev, RTW_DBG_FW, "Firmware Coredump %dth\n", i + 1);
89 _rtw_fw_dump_dbg_info(rtwdev, fw_core_regs, ARRAY_SIZE(fw_core_regs));
93 static void rtw_fw_c2h_cmd_handle_ext(struct rtw_dev *rtwdev,
104 rtw_tx_report_handle(rtwdev, skb, C2H_CCX_RPT);
107 rtw_hw_scan_status_report(rtwdev, skb);
110 rtw_hw_scan_chan_switch(rtwdev, skb);
140 struct rtw_dev *rtwdev;
197 static void rtw_fw_ra_report_handle(struct rtw_dev *rtwdev, u8 *payload,
205 rtwdev->dm_info.tx_rate = GET_RA_REPORT_RATE(payload);
206 ra_data.rtwdev = rtwdev;
208 rtw_iterate_stas_atomic(rtwdev, rtw_fw_ra_report_iter, &ra_data);
212 struct rtw_dev *rtwdev;
220 struct rtw_dev *rtwdev = iter_data->rtwdev;
236 rtwdev->beacon_loss = false;
239 rtwdev->beacon_loss = true;
240 rtw_leave_lps(rtwdev);
245 static void rtw_fw_bcn_filter_notify(struct rtw_dev *rtwdev, u8 *payload,
250 dev_iter_data.rtwdev = rtwdev;
252 rtw_iterate_vifs(rtwdev, rtw_fw_bcn_filter_notify_vif_iter,
256 static void rtw_fw_scan_result(struct rtw_dev *rtwdev, u8 *payload,
259 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
263 rtw_dbg(rtwdev, RTW_DBG_FW, "scan.density = %x\n",
267 static void rtw_fw_adaptivity_result(struct rtw_dev *rtwdev, u8 *payload,
270 struct rtw_hw_reg_offset *edcca_th = rtwdev->chip->edcca_th;
273 rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY,
278 rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY, "Reg Setting: L2H %x H2L %x\n",
279 rtw_read32_mask(rtwdev, edcca_th[EDCCA_TH_L2H_IDX].hw_reg.addr,
281 rtw_read32_mask(rtwdev, edcca_th[EDCCA_TH_H2L_IDX].hw_reg.addr,
284 rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY, "EDCCA Flag %s\n",
285 rtw_read32_mask(rtwdev, REG_EDCCA_REPORT, BIT_EDCCA_FLAG) ?
289 void rtw_fw_c2h_cmd_handle(struct rtw_dev *rtwdev, struct sk_buff *skb)
299 mutex_lock(&rtwdev->mutex);
301 if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags))
306 rtw_tx_report_handle(rtwdev, skb, C2H_CCX_TX_RPT);
309 rtw_coex_bt_info_notify(rtwdev, c2h->payload, len);
312 rtw_coex_bt_hid_info_notify(rtwdev, c2h->payload, len);
315 rtw_coex_wl_fwdbginfo_notify(rtwdev, c2h->payload, len);
318 rtw_fw_bcn_filter_notify(rtwdev, c2h->payload, len);
321 rtw_fw_c2h_cmd_handle_ext(rtwdev, skb);
324 rtw_fw_ra_report_handle(rtwdev, c2h->payload, len);
327 rtw_dbg(rtwdev, RTW_DBG_FW, "C2H 0x%x isn't handled\n", c2h->id);
332 mutex_unlock(&rtwdev->mutex);
335 void rtw_fw_c2h_cmd_rx_irqsafe(struct rtw_dev *rtwdev, u32 pkt_offset,
345 rtw_dbg(rtwdev, RTW_DBG_FW, "recv C2H, id=0x%02x, seq=0x%02x, len=%d\n",
350 rtw_coex_info_response(rtwdev, skb);
353 complete(&rtwdev->lps_leave_check);
357 complete(&rtwdev->fw_scan_density);
358 rtw_fw_scan_result(rtwdev, c2h->payload, len);
362 rtw_fw_adaptivity_result(rtwdev, c2h->payload, len);
368 skb_queue_tail(&rtwdev->c2h_queue, skb);
369 ieee80211_queue_work(rtwdev->hw, &rtwdev->c2h_work);
375 void rtw_fw_c2h_cmd_isr(struct rtw_dev *rtwdev)
377 if (rtw_read8(rtwdev, REG_MCU_TST_CFG) == VAL_FW_TRIGGER)
378 rtw_fw_recovery(rtwdev);
380 rtw_warn(rtwdev, "unhandled firmware c2h interrupt\n");
384 static void rtw_fw_send_h2c_command_register(struct rtw_dev *rtwdev,
391 rtw_dbg(rtwdev, RTW_DBG_FW, "send H2C content %08x %08x\n", h2c->w0,
394 lockdep_assert_held(&rtwdev->mutex);
396 box = rtwdev->h2c.last_box_num;
421 false, rtwdev, REG_HMETFR);
424 rtw_err(rtwdev, "failed to send h2c command\n");
425 rtw_fw_dump_dbg_info(rtwdev);
429 rtw_write32(rtwdev, box_ex_reg, h2c->w1);
430 rtw_write32(rtwdev, box_reg, h2c->w0);
432 if (++rtwdev->h2c.last_box_num >= 4)
433 rtwdev->h2c.last_box_num = 0;
436 static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev,
445 rtw_dbg(rtwdev, RTW_DBG_FW,
450 lockdep_assert_held(&rtwdev->mutex);
452 box = rtwdev->h2c.last_box_num;
477 false, rtwdev, REG_HMETFR);
480 rtw_err(rtwdev, "failed to send h2c command\n");
484 rtw_write32(rtwdev, box_ex_reg, le32_to_cpu(h2c_cmd->msg_ext));
485 rtw_write32(rtwdev, box_reg, le32_to_cpu(h2c_cmd->msg));
487 if (++rtwdev->h2c.last_box_num >= 4)
488 rtwdev->h2c.last_box_num = 0;
491 void rtw_fw_h2c_cmd_dbg(struct rtw_dev *rtwdev, u8 *h2c)
493 rtw_fw_send_h2c_command(rtwdev, h2c);
496 static void rtw_fw_send_h2c_packet(struct rtw_dev *rtwdev, u8 *h2c_pkt)
500 lockdep_assert_held(&rtwdev->mutex);
502 FW_OFFLOAD_H2C_SET_SEQ_NUM(h2c_pkt, rtwdev->h2c.seq);
503 ret = rtw_hci_write_data_h2c(rtwdev, h2c_pkt, H2C_PKT_SIZE);
505 rtw_err(rtwdev, "failed to send h2c packet\n");
506 rtwdev->h2c.seq++;
510 rtw_fw_send_general_info(struct rtw_dev *rtwdev)
512 struct rtw_fifo_conf *fifo = &rtwdev->fifo;
516 if (rtw_chip_wcpu_11n(rtwdev))
527 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
531 rtw_fw_send_phydm_info(struct rtw_dev *rtwdev)
533 struct rtw_hal *hal = &rtwdev->hal;
534 struct rtw_efuse *efuse = &rtwdev->efuse;
539 if (rtw_chip_wcpu_11n(rtwdev))
556 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
559 void rtw_fw_do_iqk(struct rtw_dev *rtwdev, struct rtw_iqk_para *para)
569 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
573 void rtw_fw_inform_rfk_status(struct rtw_dev *rtwdev, bool start)
581 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
585 void rtw_fw_query_bt_info(struct rtw_dev *rtwdev)
593 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
596 void rtw_fw_default_port(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
604 rtw_leave_lps(rtwdev);
610 rtw_fw_send_h2c_command_register(rtwdev, &h2c);
613 void rtw_fw_wl_ch_info(struct rtw_dev *rtwdev, u8 link, u8 ch, u8 bw)
623 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
626 void rtw_fw_query_bt_mp_info(struct rtw_dev *rtwdev,
639 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
642 void rtw_fw_force_bt_tx_power(struct rtw_dev *rtwdev, u8 bt_pwr_dec_lvl)
651 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
654 void rtw_fw_bt_ignore_wlan_action(struct rtw_dev *rtwdev, bool enable)
662 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
665 void rtw_fw_coex_tdma_type(struct rtw_dev *rtwdev,
678 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
681 void rtw_fw_coex_query_hid_info(struct rtw_dev *rtwdev, u8 sub_id, u8 data)
690 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
693 void rtw_fw_bt_wifi_control(struct rtw_dev *rtwdev, u8 op_code, u8 *data)
707 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
710 void rtw_fw_send_rssi_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si)
722 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
725 void rtw_fw_send_ra_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si,
749 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
752 void rtw_fw_media_status_report(struct rtw_dev *rtwdev, u8 mac_id, bool connect)
760 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
763 void rtw_fw_update_wl_phy_info(struct rtw_dev *rtwdev)
765 struct rtw_traffic_stats *stats = &rtwdev->stats;
766 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
775 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
778 void rtw_fw_beacon_filter_config(struct rtw_dev *rtwdev, bool connect,
790 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_BCN_FILTER))
801 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
811 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
824 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
827 void rtw_fw_set_pwr_mode(struct rtw_dev *rtwdev)
829 struct rtw_lps_conf *conf = &rtwdev->lps_conf;
841 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
844 void rtw_fw_set_keep_alive_cmd(struct rtw_dev *rtwdev, bool enable)
859 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
862 void rtw_fw_set_disconnect_decision_cmd(struct rtw_dev *rtwdev, bool enable)
864 struct rtw_wow_param *rtw_wow = &rtwdev->wow;
881 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
884 void rtw_fw_set_wowlan_ctrl_cmd(struct rtw_dev *rtwdev, bool enable)
886 struct rtw_wow_param *rtw_wow = &rtwdev->wow;
892 if (rtw_wow_mgd_linked(rtwdev)) {
903 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
906 void rtw_fw_set_aoac_global_info_cmd(struct rtw_dev *rtwdev,
917 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
920 void rtw_fw_set_remote_wake_ctrl_cmd(struct rtw_dev *rtwdev, bool enable)
928 if (rtw_wow_no_link(rtwdev))
931 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
934 static u8 rtw_get_rsvd_page_location(struct rtw_dev *rtwdev,
940 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
948 void rtw_fw_set_nlo_info(struct rtw_dev *rtwdev, bool enable)
953 loc_nlo = rtw_get_rsvd_page_location(rtwdev, RSVD_NLO_INFO);
959 if (rtw_get_lps_deep_mode(rtwdev) != LPS_DEEP_MODE_NONE)
965 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
968 void rtw_fw_set_recover_bt_device(struct rtw_dev *rtwdev)
975 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
978 void rtw_fw_set_pg_info(struct rtw_dev *rtwdev)
980 struct rtw_lps_conf *conf = &rtwdev->lps_conf;
984 loc_pg = rtw_get_rsvd_page_location(rtwdev, RSVD_LPS_PG_INFO);
985 loc_dpk = rtw_get_rsvd_page_location(rtwdev, RSVD_LPS_PG_DPK);
994 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
997 static u8 rtw_get_rsvd_page_probe_req_location(struct rtw_dev *rtwdev,
1003 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
1014 static u16 rtw_get_rsvd_page_probe_req_size(struct rtw_dev *rtwdev,
1020 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
1031 void rtw_send_rsvd_page_h2c(struct rtw_dev *rtwdev)
1038 location = rtw_get_rsvd_page_location(rtwdev, RSVD_PROBE_RESP);
1040 rtw_dbg(rtwdev, RTW_DBG_FW, "RSVD_PROBE_RESP loc: %d\n", location);
1042 location = rtw_get_rsvd_page_location(rtwdev, RSVD_PS_POLL);
1044 rtw_dbg(rtwdev, RTW_DBG_FW, "RSVD_PS_POLL loc: %d\n", location);
1046 location = rtw_get_rsvd_page_location(rtwdev, RSVD_NULL);
1048 rtw_dbg(rtwdev, RTW_DBG_FW, "RSVD_NULL loc: %d\n", location);
1050 location = rtw_get_rsvd_page_location(rtwdev, RSVD_QOS_NULL);
1052 rtw_dbg(rtwdev, RTW_DBG_FW, "RSVD_QOS_NULL loc: %d\n", location);
1054 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
1059 struct rtw_dev *rtwdev = hw->priv;
1060 const struct rtw_chip_info *chip = rtwdev->chip;
1061 struct rtw_pno_request *pno_req = &rtwdev->wow.pno_req;
1094 loc = rtw_get_rsvd_page_probe_req_location(rtwdev, ssid);
1096 rtw_err(rtwdev, "failed to get probe req rsvd loc\n");
1114 struct rtw_dev *rtwdev = hw->priv;
1115 const struct rtw_chip_info *chip = rtwdev->chip;
1116 struct rtw_pno_request *pno_req = &rtwdev->wow.pno_req;
1148 struct rtw_dev *rtwdev = hw->priv;
1149 const struct rtw_chip_info *chip = rtwdev->chip;
1150 struct rtw_dpk_info *dpk_info = &rtwdev->dm_info.dpk_info;
1173 struct rtw_dev *rtwdev = hw->priv;
1174 const struct rtw_chip_info *chip = rtwdev->chip;
1175 struct rtw_lps_conf *conf = &rtwdev->lps_conf;
1177 struct rtw_wow_param *rtw_wow = &rtwdev->wow;
1188 pg_info_hdr->tx_bu_page_count = rtwdev->fifo.rsvd_drv_pg_num;
1189 pg_info_hdr->macid = find_first_bit(rtwdev->mac_id_map, RTW_MAX_MAC_ID_NUM);
1191 rtw_sec_cam_pg_backup(rtwdev, pg_info_hdr->sec_cam);
1274 static void rtw_fill_rsvd_page_desc(struct rtw_dev *rtwdev, struct sk_buff *skb,
1278 const struct rtw_chip_info *chip = rtwdev->chip;
1281 rtw_tx_rsvd_page_pkt_info_update(rtwdev, &pkt_info, skb, type);
1292 static void rtw_rsvd_page_list_to_buf(struct rtw_dev *rtwdev, u8 page_size,
1305 static struct rtw_rsvd_page *rtw_alloc_rsvd_page(struct rtw_dev *rtwdev,
1324 static void rtw_insert_rsvd_page(struct rtw_dev *rtwdev,
1328 lockdep_assert_held(&rtwdev->mutex);
1333 static void rtw_add_rsvd_page(struct rtw_dev *rtwdev,
1340 rsvd_pkt = rtw_alloc_rsvd_page(rtwdev, type, txdesc);
1342 rtw_err(rtwdev, "failed to alloc rsvd page %d\n", type);
1347 rtw_insert_rsvd_page(rtwdev, rtwvif, rsvd_pkt);
1350 static void rtw_add_rsvd_page_probe_req(struct rtw_dev *rtwdev,
1356 rsvd_pkt = rtw_alloc_rsvd_page(rtwdev, RSVD_PROBE_REQ, true);
1358 rtw_err(rtwdev, "failed to alloc probe req rsvd page\n");
1364 rtw_insert_rsvd_page(rtwdev, rtwvif, rsvd_pkt);
1367 void rtw_remove_rsvd_page(struct rtw_dev *rtwdev,
1372 lockdep_assert_held(&rtwdev->mutex);
1384 void rtw_add_rsvd_page_bcn(struct rtw_dev *rtwdev,
1392 rtw_warn(rtwdev, "Cannot add beacon rsvd page for %d\n",
1397 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_BEACON, false);
1400 void rtw_add_rsvd_page_pno(struct rtw_dev *rtwdev,
1404 struct rtw_wow_param *rtw_wow = &rtwdev->wow;
1410 rtw_warn(rtwdev, "Cannot add PNO rsvd page for %d\n",
1417 rtw_add_rsvd_page_probe_req(rtwdev, rtwvif, ssid);
1420 rtw_add_rsvd_page_probe_req(rtwdev, rtwvif, NULL);
1421 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_NLO_INFO, false);
1422 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_CH_INFO, true);
1425 void rtw_add_rsvd_page_sta(struct rtw_dev *rtwdev,
1431 rtw_warn(rtwdev, "Cannot add sta rsvd page for %d\n",
1436 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_PS_POLL, true);
1437 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_QOS_NULL, true);
1438 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_NULL, true);
1439 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_LPS_PG_DPK, true);
1440 rtw_add_rsvd_page(rtwdev, rtwvif, RSVD_LPS_PG_INFO, true);
1443 int rtw_fw_write_data_rsvd_page(struct rtw_dev *rtwdev, u16 pg_addr,
1453 lockdep_assert_held(&rtwdev->mutex);
1458 if (rtw_chip_wcpu_11n(rtwdev)) {
1459 rtw_write32_set(rtwdev, REG_DWBCN0_CTRL, BIT_BCN_VALID);
1463 rtw_write16(rtwdev, REG_FIFOPAGE_CTRL_2, pg_addr);
1466 val = rtw_read8(rtwdev, REG_CR + 1);
1469 rtw_write8(rtwdev, REG_CR + 1, val);
1471 val = rtw_read8(rtwdev, REG_FWHW_TXQ_CTRL + 2);
1474 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 2, val);
1476 ret = rtw_hci_write_data_rsvd_page(rtwdev, buf, size);
1478 rtw_err(rtwdev, "failed to write data to rsvd page\n");
1482 if (rtw_chip_wcpu_11n(rtwdev)) {
1490 if (!check_hw_ready(rtwdev, bcn_valid_addr, bcn_valid_mask, 1)) {
1491 rtw_err(rtwdev, "error beacon valid\n");
1496 rsvd_pg_head = rtwdev->fifo.rsvd_boundary;
1497 rtw_write16(rtwdev, REG_FIFOPAGE_CTRL_2,
1499 rtw_write8(rtwdev, REG_FWHW_TXQ_CTRL + 2, bckp[1]);
1500 rtw_write8(rtwdev, REG_CR + 1, bckp[0]);
1505 static int rtw_download_drv_rsvd_page(struct rtw_dev *rtwdev, u8 *buf, u32 size)
1511 pg_size = rtwdev->chip->page_size;
1513 if (pg_num > rtwdev->fifo.rsvd_drv_pg_num)
1516 pg_addr = rtwdev->fifo.rsvd_drv_addr;
1518 return rtw_fw_write_data_rsvd_page(rtwdev, pg_addr, buf, size);
1521 static void __rtw_build_rsvd_page_reset(struct rtw_dev *rtwdev)
1525 list_for_each_entry_safe(rsvd_pkt, tmp, &rtwdev->rsvd_page_list,
1540 struct rtw_dev *rtwdev = data;
1545 if (vif->type == NL80211_IFTYPE_AP && !rtwdev->ap_active)
1551 &rtwdev->rsvd_page_list);
1554 &rtwdev->rsvd_page_list);
1558 static int __rtw_build_rsvd_page_from_vifs(struct rtw_dev *rtwdev)
1562 __rtw_build_rsvd_page_reset(rtwdev);
1565 rtw_iterate_vifs_atomic(rtwdev, rtw_build_rsvd_page_iter, rtwdev);
1567 rsvd_pkt = list_first_entry_or_null(&rtwdev->rsvd_page_list,
1578 dummy_pkt = rtw_alloc_rsvd_page(rtwdev, RSVD_DUMMY, false);
1580 rtw_err(rtwdev, "failed to alloc dummy rsvd page\n");
1584 list_add(&dummy_pkt->build_list, &rtwdev->rsvd_page_list);
1590 static u8 *rtw_build_rsvd_page(struct rtw_dev *rtwdev, u32 *size)
1592 struct ieee80211_hw *hw = rtwdev->hw;
1593 const struct rtw_chip_info *chip = rtwdev->chip;
1606 ret = __rtw_build_rsvd_page_from_vifs(rtwdev);
1608 rtw_err(rtwdev,
1613 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
1616 rtw_err(rtwdev, "failed to build rsvd packet\n");
1624 rtw_fill_rsvd_page_desc(rtwdev, iter, rsvd_pkt->type);
1640 rtw_err(rtwdev, "first page should be a beacon\n");
1650 if (total_page > rtwdev->fifo.rsvd_drv_pg_num) {
1651 rtw_err(rtwdev, "rsvd page over size: %d\n", total_page);
1667 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
1668 rtw_rsvd_page_list_to_buf(rtwdev, page_size, page_margin,
1683 list_for_each_entry(rsvd_pkt, &rtwdev->rsvd_page_list, build_list) {
1691 static int rtw_download_beacon(struct rtw_dev *rtwdev)
1693 struct ieee80211_hw *hw = rtwdev->hw;
1698 rsvd_pkt = list_first_entry_or_null(&rtwdev->rsvd_page_list,
1701 rtw_err(rtwdev, "failed to get rsvd page from build list\n");
1707 rtw_err(rtwdev, "invalid rsvd page type %d, should be beacon or dummy\n",
1714 rtw_err(rtwdev, "failed to get beacon skb\n");
1718 ret = rtw_download_drv_rsvd_page(rtwdev, skb->data, skb->len);
1720 rtw_err(rtwdev, "failed to download drv rsvd page\n");
1727 int rtw_fw_download_rsvd_page(struct rtw_dev *rtwdev)
1733 buf = rtw_build_rsvd_page(rtwdev, &size);
1735 rtw_err(rtwdev, "failed to build rsvd page pkt\n");
1739 ret = rtw_download_drv_rsvd_page(rtwdev, buf, size);
1741 rtw_err(rtwdev, "failed to download drv rsvd page\n");
1750 ret = rtw_download_beacon(rtwdev);
1752 rtw_err(rtwdev, "failed to download beacon\n");
1764 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
1767 mutex_lock(&rtwdev->mutex);
1768 rtw_fw_download_rsvd_page(rtwdev);
1769 rtw_send_rsvd_page_h2c(rtwdev);
1770 mutex_unlock(&rtwdev->mutex);
1773 static void rtw_fw_read_fifo_page(struct rtw_dev *rtwdev, u32 offset, u32 size,
1780 ctl = rtw_read16(rtwdev, REG_PKTBUF_DBG_CTRL) & 0xf000;
1782 rtw_write32_set(rtwdev, REG_RCR, BIT_DISGCLK);
1785 rtw_write16(rtwdev, REG_PKTBUF_DBG_CTRL, start_pg | ctl);
1789 buf[idx++] = rtw_read32(rtwdev, i);
1800 rtw_write16(rtwdev, REG_PKTBUF_DBG_CTRL, ctl);
1802 rtw_write32_clr(rtwdev, REG_RCR, BIT_DISGCLK);
1805 static void rtw_fw_read_fifo(struct rtw_dev *rtwdev, enum rtw_fw_fifo_sel sel,
1808 const struct rtw_chip_info *chip = rtwdev->chip;
1812 rtw_dbg(rtwdev, RTW_DBG_FW, "wrong fw fifo sel\n");
1816 offset += rtwdev->fifo.rsvd_boundary << TX_PAGE_SIZE_SHIFT;
1820 rtw_fw_read_fifo_page(rtwdev, offset, size, buf, residue, start_pg);
1823 static bool rtw_fw_dump_check_size(struct rtw_dev *rtwdev,
1830 if ((start_addr + size) > rtwdev->chip->fw_fifo_addr[sel])
1838 int rtw_fw_dump_fifo(struct rtw_dev *rtwdev, u8 fifo_sel, u32 addr, u32 size,
1841 if (!rtwdev->chip->fw_fifo_addr[0]) {
1842 rtw_dbg(rtwdev, RTW_DBG_FW, "chip not support dump fw fifo\n");
1850 rtw_dbg(rtwdev, RTW_DBG_FW, "not 4byte alignment\n");
1854 if (!rtw_fw_dump_check_size(rtwdev, fifo_sel, addr, size)) {
1855 rtw_dbg(rtwdev, RTW_DBG_FW, "fw fifo dump size overflow\n");
1859 rtw_fw_read_fifo(rtwdev, fifo_sel, addr, size, buffer);
1864 static void __rtw_fw_update_pkt(struct rtw_dev *rtwdev, u8 pkt_id, u16 size,
1867 const struct rtw_chip_info *chip = rtwdev->chip;
1881 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
1884 void rtw_fw_update_pkt_probe_req(struct rtw_dev *rtwdev,
1890 loc = rtw_get_rsvd_page_probe_req_location(rtwdev, ssid);
1892 rtw_err(rtwdev, "failed to get probe_req rsvd loc\n");
1896 size = rtw_get_rsvd_page_probe_req_size(rtwdev, ssid);
1898 rtw_err(rtwdev, "failed to get probe_req rsvd size\n");
1902 __rtw_fw_update_pkt(rtwdev, RTW_PACKET_PROBE_REQ, size, loc);
1905 void rtw_fw_channel_switch(struct rtw_dev *rtwdev, bool enable)
1907 struct rtw_pno_request *rtw_pno_req = &rtwdev->wow.pno_req;
1938 loc_ch_info = rtw_get_rsvd_page_location(rtwdev, RSVD_CH_INFO);
1941 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
1944 void rtw_fw_adaptivity(struct rtw_dev *rtwdev)
1946 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1951 rtw_dbg(rtwdev, RTW_DBG_ADAPTIVITY,
1962 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
1965 void rtw_fw_scan_notify(struct rtw_dev *rtwdev, bool start)
1972 rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
1975 static int rtw_append_probe_req_ie(struct rtw_dev *rtwdev, struct sk_buff *skb,
1979 const struct rtw_chip_info *chip = rtwdev->chip;
1999 static int _rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev, u8 num_probes,
2002 const struct rtw_chip_info *chip = rtwdev->chip;
2005 u16 pg_addr = rtwdev->fifo.rsvd_h2c_info_addr, loc;
2012 if (rtw_fw_feature_ext_check(&rtwdev->fw, FW_FEATURE_EXT_OLD_PAGE_NUM))
2026 rtw_fill_rsvd_page_desc(rtwdev, skb, RSVD_PROBE_REQ);
2037 loc = pg_addr - rtwdev->fifo.rsvd_boundary + page_offset;
2038 __rtw_fw_update_pkt(rtwdev, RTW_PACKET_PROBE_REQ, pkt_len, loc);
2045 ret = rtw_fw_write_data_rsvd_page(rtwdev, pg_addr, buf, buf_offset);
2047 rtw_err(rtwdev, "Download probe request to firmware failed\n");
2051 rtwdev->scan_info.probe_pg_size = page_offset;
2060 static int rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev,
2071 skb = ieee80211_probereq_get(rtwdev->hw, rtwvif->mac_addr,
2079 ret = rtw_append_probe_req_ie(rtwdev, skb, &list, &bands,
2087 return _rtw_hw_scan_update_probe_req(rtwdev, num * bands, &list);
2096 static int rtw_add_chan_info(struct rtw_dev *rtwdev, struct rtw_chan_info *info,
2125 static int rtw_add_chan_list(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
2129 struct rtw_fifo_conf *fifo = &rtwdev->fifo;
2153 ret = rtw_add_chan_info(rtwdev, &ch_info, list, buf);
2159 rtw_err(rtwdev, "List exceeds rsvd page total size\n");
2163 list->addr = fifo->rsvd_h2c_info_addr + rtwdev->scan_info.probe_pg_size;
2164 ret = rtw_fw_write_data_rsvd_page(rtwdev, list->addr, buf, list->size);
2166 rtw_err(rtwdev, "Download channel list failed\n");
2171 static void rtw_fw_set_scan_offload(struct rtw_dev *rtwdev,
2176 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2178 struct rtw_fifo_conf *fifo = &rtwdev->fifo;
2204 rtw_fw_send_h2c_packet(rtwdev, h2c_pkt);
2207 void rtw_hw_scan_start(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
2214 rtwdev->scan_info.scanning_vif = vif;
2218 ieee80211_stop_queues(rtwdev->hw);
2219 rtw_leave_lps_deep(rtwdev);
2220 rtw_hci_flush_all_queues(rtwdev, false);
2221 rtw_mac_flush_all_queues(rtwdev, false);
2228 rtw_core_scan_start(rtwdev, rtwvif, mac_addr, true);
2230 rtwdev->hal.rcr &= ~BIT_CBSSID_BCN;
2231 rtw_write32(rtwdev, REG_RCR, rtwdev->hal.rcr);
2234 void rtw_hw_scan_complete(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
2240 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2241 struct rtw_hal *hal = &rtwdev->hal;
2248 rtwdev->hal.rcr |= BIT_CBSSID_BCN;
2249 rtw_write32(rtwdev, REG_RCR, rtwdev->hal.rcr);
2251 rtw_core_scan_complete(rtwdev, vif, true);
2255 rtw_store_op_chan(rtwdev, false);
2256 rtw_phy_set_tx_power_level(rtwdev, hal->current_channel);
2257 ieee80211_wake_queues(rtwdev->hw);
2258 ieee80211_scan_completed(rtwdev->hw, &info);
2262 rtwdev->scan_info.scanning_vif = NULL;
2265 static int rtw_hw_scan_prehandle(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
2277 ret = rtw_hw_scan_update_probe_req(rtwdev, rtwvif);
2279 rtw_err(rtwdev, "Update probe request failed\n");
2286 ret = rtw_add_chan_list(rtwdev, rtwvif, list, buf);
2293 int rtw_hw_scan_offload(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
2297 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2308 ret = rtw_hw_scan_prehandle(rtwdev, rtwvif, &chan_list);
2312 rtw_fw_set_scan_offload(rtwdev, &cs_option, rtwvif, &chan_list);
2314 if (rtwdev->ap_active) {
2315 ret = rtw_download_beacon(rtwdev);
2317 rtw_err(rtwdev, "HW scan download beacon failed\n");
2323 void rtw_hw_scan_abort(struct rtw_dev *rtwdev)
2325 struct ieee80211_vif *vif = rtwdev->scan_info.scanning_vif;
2327 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_SCAN_OFFLOAD))
2330 rtw_hw_scan_offload(rtwdev, vif, false);
2331 rtw_hw_scan_complete(rtwdev, vif, true);
2334 void rtw_hw_scan_status_report(struct rtw_dev *rtwdev, struct sk_buff *skb)
2336 struct ieee80211_vif *vif = rtwdev->scan_info.scanning_vif;
2341 if (!test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
2347 rtw_hw_scan_complete(rtwdev, vif, aborted);
2350 rtw_dbg(rtwdev, RTW_DBG_HW_SCAN, "HW scan aborted with code: %d\n", rc);
2353 void rtw_store_op_chan(struct rtw_dev *rtwdev, bool backup)
2355 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2356 struct rtw_hal *hal = &rtwdev->hal;
2366 rtw_update_channel(rtwdev, scan_info->op_chan,
2372 void rtw_clear_op_chan(struct rtw_dev *rtwdev)
2374 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2382 static bool rtw_is_op_chan(struct rtw_dev *rtwdev, u8 channel)
2384 struct rtw_hw_scan_info *scan_info = &rtwdev->scan_info;
2389 void rtw_hw_scan_chan_switch(struct rtw_dev *rtwdev, struct sk_buff *skb)
2391 struct rtw_hal *hal = &rtwdev->hal;
2396 if (!test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
2406 rtw_update_channel(rtwdev, chan, chan, band,
2408 if (rtw_is_op_chan(rtwdev, chan)) {
2409 rtw_store_op_chan(rtwdev, false);
2410 ieee80211_wake_queues(rtwdev->hw);
2411 rtw_core_enable_beacon(rtwdev, true);
2415 rtw_coex_switchband_notify(rtwdev, COEX_SWITCH_TO_5G);
2419 if (test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
2423 rtw_coex_switchband_notify(rtwdev, chan_type);
2429 if (!rtw_is_op_chan(rtwdev, chan) &&
2430 rtw_is_op_chan(rtwdev, hal->current_channel)) {
2431 rtw_core_enable_beacon(rtwdev, false);
2432 ieee80211_stop_queues(rtwdev->hw);
2436 rtw_dbg(rtwdev, RTW_DBG_HW_SCAN,