Lines Matching defs:rtwdev

170 	struct rtw_dev *rtwdev;
174 static void rtw_dynamic_csi_rate(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif)
176 struct rtw_bf_info *bf_info = &rtwdev->bf_info;
184 rtw_chip_cfg_csi_rate(rtwdev, rtwdev->dm_info.min_rssi,
201 rtw_dynamic_csi_rate(iter_data->rtwdev, rtwvif);
214 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
216 struct rtw_traffic_stats *stats = &rtwdev->stats;
218 bool busy_traffic = test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
221 mutex_lock(&rtwdev->mutex);
223 if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags))
226 ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->watch_dog_work,
229 if (rtwdev->stats.tx_cnt > 100 || rtwdev->stats.rx_cnt > 100)
230 set_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
232 clear_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags);
234 if (busy_traffic != test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags))
235 rtw_coex_wl_status_change_notify(rtwdev, 0);
256 if (test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
260 rtw_leave_lps(rtwdev);
261 rtw_coex_wl_status_check(rtwdev);
262 rtw_coex_query_bt_hid_list(rtwdev);
264 rtw_phy_dynamic_mechanism(rtwdev);
266 data.rtwdev = rtwdev;
270 rtw_iterate_vifs(rtwdev, rtw_vif_watch_dog_iter, &data);
281 if (rtwdev->ps_enabled && data.rtwvif && !ps_active &&
282 !rtwdev->beacon_loss && !rtwdev->ap_active)
283 rtw_enter_lps(rtwdev, data.rtwvif->port);
285 rtwdev->watch_dog_cnt++;
288 mutex_unlock(&rtwdev->mutex);
293 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev, c2h_work);
296 skb_queue_walk_safe(&rtwdev->c2h_queue, skb, tmp) {
297 skb_unlink(skb, &rtwdev->c2h_queue);
298 rtw_fw_c2h_cmd_handle(rtwdev, skb);
305 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev, ips_work);
307 mutex_lock(&rtwdev->mutex);
308 if (rtwdev->hw->conf.flags & IEEE80211_CONF_IDLE)
309 rtw_enter_ips(rtwdev);
310 mutex_unlock(&rtwdev->mutex);
313 static u8 rtw_acquire_macid(struct rtw_dev *rtwdev)
317 mac_id = find_first_zero_bit(rtwdev->mac_id_map, RTW_MAX_MAC_ID_NUM);
319 set_bit(mac_id, rtwdev->mac_id_map);
328 struct rtw_dev *rtwdev = si->rtwdev;
330 mutex_lock(&rtwdev->mutex);
331 rtw_update_sta_info(rtwdev, si, true);
332 mutex_unlock(&rtwdev->mutex);
335 int rtw_sta_add(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
342 si->mac_id = rtw_acquire_macid(rtwdev);
348 si->rtwdev = rtwdev;
354 rtw_txq_init(rtwdev, sta->txq[i]);
357 rtw_update_sta_info(rtwdev, si, true);
358 rtw_fw_media_status_report(rtwdev, si->mac_id, true);
360 rtwdev->sta_cnt++;
361 rtwdev->beacon_loss = false;
363 rtw_dbg(rtwdev, RTW_DBG_STATE, "sta %pM joined with macid %d\n",
366 rtw_dbg(rtwdev, RTW_DBG_STATE, "sta %6D joined with macid %d\n",
373 void rtw_sta_remove(struct rtw_dev *rtwdev, struct ieee80211_sta *sta,
381 rtw_release_macid(rtwdev, si->mac_id);
383 rtw_fw_media_status_report(rtwdev, si->mac_id, false);
386 rtw_txq_cleanup(rtwdev, sta->txq[i]);
390 rtwdev->sta_cnt--;
392 rtw_dbg(rtwdev, RTW_DBG_STATE, "sta %pM with macid %d left\n",
395 rtw_dbg(rtwdev, RTW_DBG_STATE, "sta %6D with macid %d left\n",
407 static int rtw_fwcd_prep(struct rtw_dev *rtwdev)
409 const struct rtw_chip_info *chip = rtwdev->chip;
410 struct rtw_fwcd_desc *desc = &rtwdev->fw.fwcd_desc;
432 static u8 *rtw_fwcd_next(struct rtw_dev *rtwdev, u32 item, u32 size)
434 struct rtw_fwcd_desc *desc = &rtwdev->fw.fwcd_desc;
439 rtw_dbg(rtwdev, RTW_DBG_FW, "fwcd isn't prepared successfully\n");
445 rtw_dbg(rtwdev, RTW_DBG_FW, "fwcd isn't prepared enough\n");
459 static void rtw_fwcd_dump(struct rtw_dev *rtwdev)
461 struct rtw_fwcd_desc *desc = &rtwdev->fw.fwcd_desc;
463 rtw_dbg(rtwdev, RTW_DBG_FW, "dump fwcd\n");
470 dev_coredumpv(rtwdev->dev, desc->data, desc->size, GFP_KERNEL);
473 static void rtw_fwcd_free(struct rtw_dev *rtwdev, bool free_self)
475 struct rtw_fwcd_desc *desc = &rtwdev->fw.fwcd_desc;
478 rtw_dbg(rtwdev, RTW_DBG_FW, "free fwcd by self\n");
486 static int rtw_fw_dump_crash_log(struct rtw_dev *rtwdev)
488 u32 size = rtwdev->chip->fw_rxff_size;
492 buf = (u32 *)rtw_fwcd_next(rtwdev, RTW_FWCD_TLV, size);
496 if (rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RXBUF_FW, 0, size, buf)) {
497 rtw_dbg(rtwdev, RTW_DBG_FW, "dump fw fifo fail\n");
502 rtw_dbg(rtwdev, RTW_DBG_FW, "fw crash dump's length is 0\n");
508 rtw_dbg(rtwdev, RTW_DBG_FW,
516 int rtw_dump_fw(struct rtw_dev *rtwdev, const u32 ocp_src, u32 size,
519 u32 rxff = rtwdev->chip->fw_rxff_size;
524 buf = rtw_fwcd_next(rtwdev, fwcd_item, size);
531 ret = rtw_ddma_to_fw_fifo(rtwdev, ocp_src + done_size,
534 rtw_err(rtwdev,
540 ret = rtw_fw_dump_fifo(rtwdev, RTW_FW_FIFO_SEL_RXBUF_FW, 0,
543 rtw_err(rtwdev,
557 int rtw_dump_reg(struct rtw_dev *rtwdev, const u32 addr, const u32 size)
567 buf = rtw_fwcd_next(rtwdev, RTW_FWCD_REG, size);
572 *(u32 *)(buf + i) = rtw_read32(rtwdev, addr + i);
601 struct rtw_dev *rtwdev = (struct rtw_dev *)data;
602 struct rtw_sec_desc *sec = &rtwdev->sec;
604 rtw_sec_clear_cam(rtwdev, sec, key->hw_key_idx);
609 struct rtw_dev *rtwdev = (struct rtw_dev *)data;
611 if (rtwdev->sta_cnt == 0) {
612 rtw_warn(rtwdev, "sta count before reset should not be 0\n");
615 rtw_sta_remove(rtwdev, sta, false);
620 struct rtw_dev *rtwdev = (struct rtw_dev *)data;
623 rtw_bf_disassoc(rtwdev, vif, NULL);
625 rtw_txq_cleanup(rtwdev, vif->txq);
628 void rtw_fw_recovery(struct rtw_dev *rtwdev)
630 if (!test_bit(RTW_FLAG_RESTARTING, rtwdev->flags))
631 ieee80211_queue_work(rtwdev->hw, &rtwdev->fw_recovery_work);
634 static void __fw_recovery_work(struct rtw_dev *rtwdev)
638 set_bit(RTW_FLAG_RESTARTING, rtwdev->flags);
639 clear_bit(RTW_FLAG_RESTART_TRIGGERING, rtwdev->flags);
641 ret = rtw_fwcd_prep(rtwdev);
644 ret = rtw_fw_dump_crash_log(rtwdev);
647 ret = rtw_chip_dump_fw_crash(rtwdev);
651 rtw_fwcd_dump(rtwdev);
653 rtw_fwcd_free(rtwdev, !!ret);
654 rtw_write8(rtwdev, REG_MCU_TST_CFG, 0);
659 rtw_iterate_keys_rcu(rtwdev, NULL, rtw_reset_key_iter, rtwdev);
661 rtw_iterate_stas_atomic(rtwdev, rtw_reset_sta_iter, rtwdev);
662 rtw_iterate_vifs_atomic(rtwdev, rtw_reset_vif_iter, rtwdev);
663 bitmap_zero(rtwdev->hw_port, RTW_PORT_NUM);
664 rtw_enter_ips(rtwdev);
669 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev,
672 mutex_lock(&rtwdev->mutex);
673 __fw_recovery_work(rtwdev);
674 mutex_unlock(&rtwdev->mutex);
676 ieee80211_restart_hw(rtwdev->hw);
707 struct rtw_dev *rtwdev = container_of(work, struct rtw_dev, ba_work);
710 rtw_iterate_stas_atomic(rtwdev, rtw_txq_ba_iter, &data);
726 void rtw_set_dtim_period(struct rtw_dev *rtwdev, int dtim_period)
728 rtw_write32_set(rtwdev, REG_TCR, BIT_TCR_UPDATE_TIMIE);
729 rtw_write8(rtwdev, REG_DTIM_COUNTER_ROOT, dtim_period - 1);
732 void rtw_update_channel(struct rtw_dev *rtwdev, u8 center_channel,
737 struct rtw_hal *hal = &rtwdev->hal;
864 void rtw_set_channel(struct rtw_dev *rtwdev)
866 const struct rtw_chip_info *chip = rtwdev->chip;
867 struct ieee80211_hw *hw = rtwdev->hw;
868 struct rtw_hal *hal = &rtwdev->hal;
881 rtw_update_channel(rtwdev, center_chan, primary_chan, band, bandwidth);
883 if (rtwdev->scan_info.op_chan)
884 rtw_store_op_chan(rtwdev, true);
886 chip->ops->set_channel(rtwdev, center_chan, bandwidth,
890 rtw_coex_switchband_notify(rtwdev, COEX_SWITCH_TO_5G);
892 if (test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
893 rtw_coex_switchband_notify(rtwdev, COEX_SWITCH_TO_24G);
895 rtw_coex_switchband_notify(rtwdev, COEX_SWITCH_TO_24G_NOFORSCAN);
898 rtw_phy_set_tx_power_level(rtwdev, center_chan);
904 if (!test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
905 rtwdev->need_rfk = true;
908 void rtw_chip_prepare_tx(struct rtw_dev *rtwdev)
910 const struct rtw_chip_info *chip = rtwdev->chip;
912 if (rtwdev->need_rfk) {
913 rtwdev->need_rfk = false;
914 chip->ops->phy_calibration(rtwdev);
918 static void rtw_vif_write_addr(struct rtw_dev *rtwdev, u32 start, u8 *addr)
923 rtw_write8(rtwdev, start + i, addr[i]);
926 void rtw_vif_port_config(struct rtw_dev *rtwdev,
934 rtw_vif_write_addr(rtwdev, addr, rtwvif->mac_addr);
938 rtw_vif_write_addr(rtwdev, addr, rtwvif->bssid);
943 rtw_write32_mask(rtwdev, addr, mask, rtwvif->net_type);
948 rtw_write32_mask(rtwdev, addr, mask, rtwvif->aid);
953 rtw_write8_mask(rtwdev, addr, mask, rtwvif->bcn_ctrl);
977 static void rtw_hw_config_rf_ant_num(struct rtw_dev *rtwdev, u8 hw_ant_num)
979 const struct rtw_chip_info *chip = rtwdev->chip;
980 struct rtw_hal *hal = &rtwdev->hal;
1163 static u64 rtw_rate_mask_cfg(struct rtw_dev *rtwdev, struct rtw_sta_info *si,
1166 struct rtw_hal *hal = &rtwdev->hal;
1205 void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si,
1208 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
1210 struct rtw_efuse *efuse = &rtwdev->efuse;
1211 struct rtw_hal *hal = &rtwdev->hal;
1240 if (efuse->hw_cap.nss == 1 || rtwdev->hal.txrx_1ss)
1281 rtw_err(rtwdev, "Unknown band type\n");
1316 ra_mask = rtw_rate_mask_cfg(rtwdev, si, ra_mask, is_vht_enable);
1327 rtw_fw_send_ra_info(rtwdev, si, reset_ra_mask);
1330 static int rtw_wait_firmware_completion(struct rtw_dev *rtwdev)
1332 const struct rtw_chip_info *chip = rtwdev->chip;
1335 fw = &rtwdev->fw;
1341 fw = &rtwdev->wow_fw;
1350 static enum rtw_lps_deep_mode rtw_update_lps_deep_mode(struct rtw_dev *rtwdev,
1353 const struct rtw_chip_info *chip = rtwdev->chip;
1370 static int rtw_power_on(struct rtw_dev *rtwdev)
1372 const struct rtw_chip_info *chip = rtwdev->chip;
1373 struct rtw_fw_state *fw = &rtwdev->fw;
1377 ret = rtw_hci_setup(rtwdev);
1379 rtw_err(rtwdev, "failed to setup hci\n");
1384 ret = rtw_mac_power_on(rtwdev);
1386 rtw_err(rtwdev, "failed to power on mac\n");
1390 ret = rtw_wait_firmware_completion(rtwdev);
1392 rtw_err(rtwdev, "failed to wait firmware completion\n");
1396 ret = rtw_download_firmware(rtwdev, fw);
1398 rtw_err(rtwdev, "failed to download firmware\n");
1403 ret = rtw_mac_init(rtwdev);
1405 rtw_err(rtwdev, "failed to configure mac\n");
1409 chip->ops->phy_set_param(rtwdev);
1411 ret = rtw_hci_start(rtwdev);
1413 rtw_err(rtwdev, "failed to start hci\n");
1418 rtw_fw_send_general_info(rtwdev);
1419 rtw_fw_send_phydm_info(rtwdev);
1421 wifi_only = !rtwdev->efuse.btcoex;
1422 rtw_coex_power_on_setting(rtwdev);
1423 rtw_coex_init_hw_config(rtwdev, wifi_only);
1428 rtw_mac_power_off(rtwdev);
1434 void rtw_core_fw_scan_notify(struct rtw_dev *rtwdev, bool start)
1436 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_NOTIFY_SCAN))
1440 rtw_fw_scan_notify(rtwdev, true);
1442 reinit_completion(&rtwdev->fw_scan_density);
1443 rtw_fw_scan_notify(rtwdev, false);
1444 if (!wait_for_completion_timeout(&rtwdev->fw_scan_density,
1446 rtw_warn(rtwdev, "firmware failed to report density after scan\n");
1450 void rtw_core_scan_start(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif,
1456 rtw_leave_lps(rtwdev);
1458 if (hw_scan && (rtwdev->hw->conf.flags & IEEE80211_CONF_IDLE)) {
1459 ret = rtw_leave_ips(rtwdev);
1461 rtw_err(rtwdev, "failed to leave idle state\n");
1468 rtw_vif_port_config(rtwdev, rtwvif, config);
1470 rtw_coex_scan_notify(rtwdev, COEX_SCAN_START);
1471 rtw_core_fw_scan_notify(rtwdev, true);
1473 set_bit(RTW_FLAG_DIG_DISABLE, rtwdev->flags);
1474 set_bit(RTW_FLAG_SCANNING, rtwdev->flags);
1477 void rtw_core_scan_complete(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
1486 clear_bit(RTW_FLAG_SCANNING, rtwdev->flags);
1487 clear_bit(RTW_FLAG_DIG_DISABLE, rtwdev->flags);
1489 rtw_core_fw_scan_notify(rtwdev, false);
1493 rtw_vif_port_config(rtwdev, rtwvif, config);
1495 rtw_coex_scan_notify(rtwdev, COEX_SCAN_FINISH);
1497 if (hw_scan && (rtwdev->hw->conf.flags & IEEE80211_CONF_IDLE))
1498 ieee80211_queue_work(rtwdev->hw, &rtwdev->ips_work);
1501 int rtw_core_start(struct rtw_dev *rtwdev)
1505 ret = rtw_power_on(rtwdev);
1509 rtw_sec_enable_sec_engine(rtwdev);
1511 rtwdev->lps_conf.deep_mode = rtw_update_lps_deep_mode(rtwdev, &rtwdev->fw);
1512 rtwdev->lps_conf.wow_deep_mode = rtw_update_lps_deep_mode(rtwdev, &rtwdev->wow_fw);
1515 rtw_write32(rtwdev, REG_RCR, rtwdev->hal.rcr);
1517 ieee80211_queue_delayed_work(rtwdev->hw, &rtwdev->watch_dog_work,
1520 set_bit(RTW_FLAG_RUNNING, rtwdev->flags);
1525 static void rtw_power_off(struct rtw_dev *rtwdev)
1527 rtw_hci_stop(rtwdev);
1528 rtw_coex_power_off_setting(rtwdev);
1529 rtw_mac_power_off(rtwdev);
1532 void rtw_core_stop(struct rtw_dev *rtwdev)
1534 struct rtw_coex *coex = &rtwdev->coex;
1536 clear_bit(RTW_FLAG_RUNNING, rtwdev->flags);
1537 clear_bit(RTW_FLAG_FW_RUNNING, rtwdev->flags);
1539 mutex_unlock(&rtwdev->mutex);
1541 cancel_work_sync(&rtwdev->c2h_work);
1542 cancel_work_sync(&rtwdev->update_beacon_work);
1543 cancel_delayed_work_sync(&rtwdev->watch_dog_work);
1553 mutex_lock(&rtwdev->mutex);
1555 rtw_power_off(rtwdev);
1558 static void rtw_init_ht_cap(struct rtw_dev *rtwdev,
1561 const struct rtw_chip_info *chip = rtwdev->chip;
1562 struct rtw_efuse *efuse = &rtwdev->efuse;
1570 if (rtw_chip_has_rx_ldpc(rtwdev))
1572 if (rtw_chip_has_tx_stbc(rtwdev))
1595 static void rtw_init_vht_cap(struct rtw_dev *rtwdev,
1598 struct rtw_efuse *efuse = &rtwdev->efuse;
1613 if (rtwdev->hal.rf_path_num > 1)
1617 vht_cap->cap |= (rtwdev->hal.bfee_sts_cap <<
1620 if (rtw_chip_has_rx_ldpc(rtwdev))
1644 static u16 rtw_get_max_scan_ie_len(struct rtw_dev *rtwdev)
1648 len = rtwdev->chip->max_scan_ie_len;
1650 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_SCAN_OFFLOAD) &&
1651 rtwdev->chip->id == RTW_CHIP_TYPE_8822C)
1653 else if (rtw_fw_feature_ext_check(&rtwdev->fw, FW_FEATURE_EXT_OLD_PAGE_NUM))
1662 struct rtw_dev *rtwdev = hw->priv;
1670 rtw_init_ht_cap(rtwdev, &sband->ht_cap);
1679 rtw_init_ht_cap(rtwdev, &sband->ht_cap);
1681 rtw_init_vht_cap(rtwdev, &sband->vht_cap);
1688 rtw_err(rtwdev, "failed to set supported band\n");
1701 struct rtw_dev *rtwdev = (struct rtw_dev *)data;
1706 if (rtwdev->hal.txrx_1ss)
1712 void rtw_set_txrx_1ss(struct rtw_dev *rtwdev, bool txrx_1ss)
1714 const struct rtw_chip_info *chip = rtwdev->chip;
1715 struct rtw_hal *hal = &rtwdev->hal;
1717 if (!chip->ops->config_txrx_mode || rtwdev->hal.txrx_1ss == txrx_1ss)
1720 rtwdev->hal.txrx_1ss = txrx_1ss;
1722 chip->ops->config_txrx_mode(rtwdev, BB_PATH_A, BB_PATH_A, false);
1724 chip->ops->config_txrx_mode(rtwdev, hal->antenna_tx,
1726 rtw_iterate_vifs_atomic(rtwdev, rtw_vif_smps_iter, rtwdev);
1729 static void __update_firmware_feature(struct rtw_dev *rtwdev,
1739 if (rtwdev->chip->id == RTW_CHIP_TYPE_8822C &&
1740 RTW_FW_SUIT_VER_CODE(rtwdev->fw) < RTW_FW_VER_CODE(9, 9, 13))
1744 static void __update_firmware_info(struct rtw_dev *rtwdev,
1755 __update_firmware_feature(rtwdev, fw);
1758 static void __update_firmware_info_legacy(struct rtw_dev *rtwdev,
1774 static void update_firmware_info(struct rtw_dev *rtwdev,
1777 if (rtw_chip_wcpu_11n(rtwdev))
1778 __update_firmware_info_legacy(rtwdev, fw);
1780 __update_firmware_info(rtwdev, fw);
1786 struct rtw_dev *rtwdev = fw->rtwdev;
1789 rtw_err(rtwdev, "failed to request firmware\n");
1795 update_firmware_info(rtwdev, fw);
1798 rtw_info(rtwdev, "%sFirmware version %u.%u.%u, H2C version %u\n",
1803 static int rtw_load_firmware(struct rtw_dev *rtwdev, enum rtw_fw_type type)
1811 fw = &rtwdev->wow_fw;
1812 fw_name = rtwdev->chip->wow_fw_name;
1816 fw = &rtwdev->fw;
1817 fw_name = rtwdev->chip->fw_name;
1821 rtw_warn(rtwdev, "unsupported firmware type\n");
1826 fw->rtwdev = rtwdev;
1829 ret = request_firmware_nowait(THIS_MODULE, true, fw_name, rtwdev->dev,
1832 rtw_err(rtwdev, "failed to async firmware request\n");
1839 static int rtw_chip_parameter_setup(struct rtw_dev *rtwdev)
1841 const struct rtw_chip_info *chip = rtwdev->chip;
1842 struct rtw_hal *hal = &rtwdev->hal;
1843 struct rtw_efuse *efuse = &rtwdev->efuse;
1845 switch (rtw_hci_type(rtwdev)) {
1847 rtwdev->hci.rpwm_addr = 0x03d9;
1848 rtwdev->hci.cpwm_addr = 0x03da;
1851 rtwdev->hci.rpwm_addr = REG_SDIO_HRPWM1;
1852 rtwdev->hci.cpwm_addr = REG_SDIO_HCPWM1_V2;
1855 rtwdev->hci.rpwm_addr = 0xfe58;
1856 rtwdev->hci.cpwm_addr = 0xfe57;
1859 rtw_err(rtwdev, "unsupported hci type\n");
1863 hal->chip_version = rtw_read32(rtwdev, REG_SYS_CFG1);
1885 rtwdev->hal.rcr |= BIT_VHT_DACK;
1892 static int rtw_chip_efuse_enable(struct rtw_dev *rtwdev)
1894 struct rtw_fw_state *fw = &rtwdev->fw;
1897 ret = rtw_hci_setup(rtwdev);
1899 rtw_err(rtwdev, "failed to setup hci\n");
1903 ret = rtw_mac_power_on(rtwdev);
1905 rtw_err(rtwdev, "failed to power on mac\n");
1909 rtw_write8(rtwdev, REG_C2HEVT, C2H_HW_FEATURE_DUMP);
1914 rtw_err(rtwdev, "failed to load firmware\n");
1918 ret = rtw_download_firmware(rtwdev, fw);
1920 rtw_err(rtwdev, "failed to download firmware\n");
1927 rtw_mac_power_off(rtwdev);
1933 static int rtw_dump_hw_feature(struct rtw_dev *rtwdev)
1935 struct rtw_efuse *efuse = &rtwdev->efuse;
1941 id = rtw_read8(rtwdev, REG_C2HEVT);
1943 rtw_err(rtwdev, "failed to read hw feature report\n");
1948 hw_feature[i] = rtw_read8(rtwdev, REG_C2HEVT + 2 + i);
1950 rtw_write8(rtwdev, REG_C2HEVT, 0);
1959 rtw_hw_config_rf_ant_num(rtwdev, efuse->hw_cap.ant_num);
1962 efuse->hw_cap.nss > rtwdev->hal.rf_path_num)
1963 efuse->hw_cap.nss = rtwdev->hal.rf_path_num;
1965 rtw_dbg(rtwdev, RTW_DBG_EFUSE,
1973 static void rtw_chip_efuse_disable(struct rtw_dev *rtwdev)
1975 rtw_hci_stop(rtwdev);
1976 rtw_mac_power_off(rtwdev);
1979 static int rtw_chip_efuse_info_setup(struct rtw_dev *rtwdev)
1981 struct rtw_efuse *efuse = &rtwdev->efuse;
1984 mutex_lock(&rtwdev->mutex);
1987 ret = rtw_chip_efuse_enable(rtwdev);
1991 ret = rtw_parse_efuse_map(rtwdev);
1995 ret = rtw_dump_hw_feature(rtwdev);
1999 ret = rtw_check_supported_rfe(rtwdev);
2034 dev_warn(rtwdev->dev, "efuse MAC invalid, using random\n");
2038 rtw_chip_efuse_disable(rtwdev);
2041 mutex_unlock(&rtwdev->mutex);
2045 static int rtw_chip_board_info_setup(struct rtw_dev *rtwdev)
2047 struct rtw_hal *hal = &rtwdev->hal;
2048 const struct rtw_rfe_def *rfe_def = rtw_get_rfe_def(rtwdev);
2053 rtw_phy_setup_phy_cond(rtwdev, hal->pkg_type);
2055 rtw_phy_init_tx_power(rtwdev);
2056 rtw_load_table(rtwdev, rfe_def->phy_pg_tbl);
2057 rtw_load_table(rtwdev, rfe_def->txpwr_lmt_tbl);
2064 int rtw_chip_info_setup(struct rtw_dev *rtwdev)
2068 ret = rtw_chip_parameter_setup(rtwdev);
2070 rtw_err(rtwdev, "failed to setup chip parameters\n");
2074 ret = rtw_chip_efuse_info_setup(rtwdev);
2076 rtw_err(rtwdev, "failed to setup chip efuse info\n");
2080 ret = rtw_chip_board_info_setup(rtwdev);
2082 rtw_err(rtwdev, "failed to setup chip board info\n");
2093 static void rtw_stats_init(struct rtw_dev *rtwdev)
2095 struct rtw_traffic_stats *stats = &rtwdev->stats;
2096 struct rtw_dm_info *dm_info = &rtwdev->dm_info;
2108 int rtw_core_init(struct rtw_dev *rtwdev)
2110 const struct rtw_chip_info *chip = rtwdev->chip;
2111 struct rtw_coex *coex = &rtwdev->coex;
2114 INIT_LIST_HEAD(&rtwdev->rsvd_page_list);
2115 INIT_LIST_HEAD(&rtwdev->txqs);
2117 timer_setup(&rtwdev->tx_report.purge_timer,
2119 rtwdev->tx_wq = alloc_workqueue("rtw_tx_wq", WQ_UNBOUND | WQ_HIGHPRI, 0);
2120 if (!rtwdev->tx_wq) {
2121 rtw_warn(rtwdev, "alloc_workqueue rtw_tx_wq failed\n");
2125 INIT_DELAYED_WORK(&rtwdev->watch_dog_work, rtw_watch_dog_work);
2135 INIT_WORK(&rtwdev->tx_work, rtw_tx_work);
2136 INIT_WORK(&rtwdev->c2h_work, rtw_c2h_work);
2137 INIT_WORK(&rtwdev->ips_work, rtw_ips_work);
2138 INIT_WORK(&rtwdev->fw_recovery_work, rtw_fw_recovery_work);
2139 INIT_WORK(&rtwdev->update_beacon_work, rtw_fw_update_beacon_work);
2140 INIT_WORK(&rtwdev->ba_work, rtw_txq_ba_work);
2141 skb_queue_head_init(&rtwdev->c2h_queue);
2142 skb_queue_head_init(&rtwdev->coex.queue);
2143 skb_queue_head_init(&rtwdev->tx_report.queue);
2145 spin_lock_init(&rtwdev->txq_lock);
2146 spin_lock_init(&rtwdev->tx_report.q_lock);
2148 mutex_init(&rtwdev->mutex);
2149 mutex_init(&rtwdev->hal.tx_power_mutex);
2151 init_waitqueue_head(&rtwdev->coex.wait);
2152 init_completion(&rtwdev->lps_leave_check);
2153 init_completion(&rtwdev->fw_scan_density);
2155 rtwdev->sec.total_cam_num = 32;
2156 rtwdev->hal.current_channel = 1;
2157 rtwdev->dm_info.fix_rate = U8_MAX;
2158 set_bit(RTW_BC_MC_MACID, rtwdev->mac_id_map);
2160 rtw_stats_init(rtwdev);
2163 rtwdev->hal.rcr = BIT_APP_FCS | BIT_APP_MIC | BIT_APP_ICV |
2167 ret = rtw_load_firmware(rtwdev, RTW_NORMAL_FW);
2169 rtw_warn(rtwdev, "no firmware loaded\n");
2174 ret = rtw_load_firmware(rtwdev, RTW_WOWLAN_FW);
2176 rtw_warn(rtwdev, "no wow firmware loaded\n");
2177 wait_for_completion(&rtwdev->fw.completion);
2178 if (rtwdev->fw.firmware)
2179 release_firmware(rtwdev->fw.firmware);
2185 rtw_wait_firmware_completion(rtwdev);
2191 destroy_workqueue(rtwdev->tx_wq);
2196 void rtw_core_deinit(struct rtw_dev *rtwdev)
2198 struct rtw_fw_state *fw = &rtwdev->fw;
2199 struct rtw_fw_state *wow_fw = &rtwdev->wow_fw;
2203 rtw_wait_firmware_completion(rtwdev);
2211 destroy_workqueue(rtwdev->tx_wq);
2212 timer_delete_sync(&rtwdev->tx_report.purge_timer);
2213 spin_lock_irqsave(&rtwdev->tx_report.q_lock, flags);
2214 skb_queue_purge(&rtwdev->tx_report.queue);
2215 spin_unlock_irqrestore(&rtwdev->tx_report.q_lock, flags);
2216 skb_queue_purge(&rtwdev->coex.queue);
2217 skb_queue_purge(&rtwdev->c2h_queue);
2219 list_for_each_entry_safe(rsvd_pkt, tmp, &rtwdev->rsvd_page_list,
2225 mutex_destroy(&rtwdev->mutex);
2226 mutex_destroy(&rtwdev->hal.tx_power_mutex);
2230 int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw)
2232 bool sta_mode_only = rtwdev->hci.type == RTW_HCI_TYPE_SDIO;
2233 struct rtw_hal *hal = &rtwdev->hal;
2237 max_tx_headroom = rtwdev->chip->tx_pkt_desc_sz;
2239 if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO)
2275 hw->wiphy->max_scan_ie_len = rtw_get_max_scan_ie_len(rtwdev);
2277 if (!sta_mode_only && rtwdev->chip->id == RTW_CHIP_TYPE_8822C) {
2287 hw->wiphy->wowlan = rtwdev->chip->wowlan_stub;
2288 hw->wiphy->max_sched_scan_ssids = rtwdev->chip->max_sched_scan_ssids;
2290 rtw_set_supported_band(hw, rtwdev->chip);
2291 SET_IEEE80211_PERM_ADDR(hw, rtwdev->efuse.addr);
2295 ret = rtw_regd_init(rtwdev);
2297 rtw_err(rtwdev, "failed to init regd\n");
2303 rtw_err(rtwdev, "failed to register hw\n");
2307 ret = rtw_regd_hint(rtwdev);
2309 rtw_err(rtwdev, "failed to hint regd\n");
2313 rtw_debugfs_init(rtwdev);
2315 rtwdev->bf_info.bfer_mu_cnt = 0;
2316 rtwdev->bf_info.bfer_su_cnt = 0;
2322 void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw)
2324 const struct rtw_chip_info *chip = rtwdev->chip;
2332 void rtw_swap_reg_nbytes(struct rtw_dev *rtwdev, const struct rtw_hw_reg *reg1,
2338 u8 v1 = rtw_read8(rtwdev, reg1->addr + i);
2339 u8 v2 = rtw_read8(rtwdev, reg2->addr + i);
2341 rtw_write8(rtwdev, reg1->addr + i, v2);
2342 rtw_write8(rtwdev, reg2->addr + i, v1);
2347 void rtw_swap_reg_mask(struct rtw_dev *rtwdev, const struct rtw_hw_reg *reg1,
2352 v1 = rtw_read32_mask(rtwdev, reg1->addr, reg1->mask);
2353 v2 = rtw_read32_mask(rtwdev, reg2->addr, reg2->mask);
2354 rtw_write32_mask(rtwdev, reg2->addr, reg2->mask, v1);
2355 rtw_write32_mask(rtwdev, reg1->addr, reg1->mask, v2);
2359 struct rtw_dev *rtwdev;
2366 struct rtw_dev *rtwdev = iter_data->rtwdev;
2374 rtw_dbg(rtwdev, RTW_DBG_STATE, "AP port switch from %d -> %d\n",
2378 rtw_leave_lps(rtwdev);
2382 rtw_swap_reg_mask(rtwdev, reg1, reg2);
2386 rtw_swap_reg_nbytes(rtwdev, reg1, reg2, ETH_ALEN);
2390 rtw_swap_reg_nbytes(rtwdev, reg1, reg2, ETH_ALEN);
2394 rtw_swap_reg_nbytes(rtwdev, reg1, reg2, 1);
2399 rtw_fw_default_port(rtwdev, rtwvif_target);
2402 void rtw_core_port_switch(struct rtw_dev *rtwdev, struct ieee80211_vif *vif)
2410 iter_data.rtwdev = rtwdev;
2412 rtw_iterate_vifs(rtwdev, rtw_port_switch_iter, &iter_data);
2430 bool rtw_core_check_sta_active(struct rtw_dev *rtwdev)
2434 rtw_iterate_vifs(rtwdev, rtw_check_sta_active_iter, &sta_active);
2436 return rtwdev->ap_active || sta_active;
2439 void rtw_core_enable_beacon(struct rtw_dev *rtwdev, bool enable)
2441 if (!rtwdev->ap_active)
2445 rtw_write32_set(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION);
2446 rtw_write32_clr(rtwdev, REG_TXPAUSE, BIT_HIGH_QUEUE);
2448 rtw_write32_clr(rtwdev, REG_BCN_CTRL, BIT_EN_BCN_FUNCTION);
2449 rtw_write32_set(rtwdev, REG_TXPAUSE, BIT_HIGH_QUEUE);