Commit e3ec7017 authored by Ping-Ke Shih's avatar Ping-Ke Shih Committed by Kalle Valo

rtw89: add Realtek 802.11ax driver

This driver named rtw89, which is the next generation of rtw88, supports
Realtek 8852AE 802.11ax 2x2 chip whose new features are OFDMA, DBCC,
Spatial reuse, TWT and BSS coloring; now some of them aren't implemented
though.

The chip architecture is entirely different from the chips supported by
rtw88 like RTL8822CE 802.11ac chip. First of all, register address ranges
are totally redefined, so it's impossible to reuse register definition. To
communicate with firmware, new H2C/C2H format is proposed. In order to have
better utilization, TX DMA flow is changed to two stages DMA. To provide
rich RX status information, additional RX PPDU packets are added.

Since there are so many differences mentioned above, we decide to propose
a new driver. It has many authors, they are listed in alphabetic order:

Chin-Yen Lee <timlee@realtek.com>
Ping-Ke Shih <pkshih@realtek.com>
Po Hao Huang <phhuang@realtek.com>
Tzu-En Huang <tehuang@realtek.com>
Vincent Fann <vincent_fann@realtek.com>
Yan-Hsuan Chuang <tony0620emma@gmail.com>
Zong-Zhe Yang <kevin_yang@realtek.com>
Tested-by: default avatarAaron Ma <aaron.ma@canonical.com>
Tested-by: default avatarBrian Norris <briannorris@chromium.org>
Signed-off-by: default avatarPing-Ke Shih <pkshih@realtek.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20211008035627.19463-1-pkshih@realtek.com
parent 9b793db5
......@@ -16,5 +16,6 @@ source "drivers/net/wireless/realtek/rtl818x/Kconfig"
source "drivers/net/wireless/realtek/rtlwifi/Kconfig"
source "drivers/net/wireless/realtek/rtl8xxxu/Kconfig"
source "drivers/net/wireless/realtek/rtw88/Kconfig"
source "drivers/net/wireless/realtek/rtw89/Kconfig"
endif # WLAN_VENDOR_REALTEK
......@@ -8,4 +8,5 @@ obj-$(CONFIG_RTL8187) += rtl818x/
obj-$(CONFIG_RTLWIFI) += rtlwifi/
obj-$(CONFIG_RTL8XXXU) += rtl8xxxu/
obj-$(CONFIG_RTW88) += rtw88/
obj-$(CONFIG_RTW89) += rtw89/
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
menuconfig RTW89
tristate "Realtek 802.11ax wireless chips support"
depends on MAC80211
help
This module adds support for mac80211-based wireless drivers that
enables Realtek IEEE 802.11ax wireless chipsets.
If you choose to build a module, it'll be called rtw89.
if RTW89
config RTW89_CORE
tristate
config RTW89_PCI
tristate
config RTW89_8852AE
tristate "Realtek 8852AE PCI wireless network adapter"
depends on PCI
select RTW89_CORE
select RTW89_PCI
help
Select this option will enable support for 8852AE chipset
802.11ax PCIe wireless network adapter
config RTW89_DEBUG
bool
config RTW89_DEBUGMSG
bool "Realtek rtw89 debug message support"
depends on RTW89_CORE
select RTW89_DEBUG
help
Enable debug message support
If unsure, say Y to simplify debug problems
config RTW89_DEBUGFS
bool "Realtek rtw89 debugfs support"
depends on RTW89_CORE
select RTW89_DEBUG
help
Enable debugfs support
If unsure, say Y to simplify debug problems
endif
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
obj-$(CONFIG_RTW89_CORE) += rtw89_core.o
rtw89_core-y += core.o \
mac80211.o \
mac.o \
phy.o \
fw.o \
rtw8852a.o \
rtw8852a_table.o \
rtw8852a_rfk.o \
rtw8852a_rfk_table.o \
cam.o \
efuse.o \
regd.o \
sar.o \
coex.o \
ps.o \
ser.o
rtw89_core-$(CONFIG_RTW89_DEBUG) += debug.o
obj-$(CONFIG_RTW89_PCI) += rtw89_pci.o
rtw89_pci-y := pci.o
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_CAM_H__
#define __RTW89_CAM_H__
#include "core.h"
#define RTW89_SEC_CAM_LEN 20
#define FWCMD_SET_ADDR_IDX(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_OFFSET(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_LEN(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 1, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_VALID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(0))
#define FWCMD_SET_ADDR_NET_TYPE(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(2, 1))
#define FWCMD_SET_ADDR_BCN_HIT_COND(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(4, 3))
#define FWCMD_SET_ADDR_HIT_RULE(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(6, 5))
#define FWCMD_SET_ADDR_BB_SEL(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, BIT(7))
#define FWCMD_SET_ADDR_ADDR_MASK(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(13, 8))
#define FWCMD_SET_ADDR_MASK_SEL(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(15, 14))
#define FWCMD_SET_ADDR_SMA_HASH(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_TMA_HASH(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 2, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_BSSID_CAM_IDX(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 3, value, GENMASK(5, 0))
#define FWCMD_SET_ADDR_SMA0(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_SMA1(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_SMA2(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_SMA3(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 4, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_SMA4(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_SMA5(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_TMA0(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_TMA1(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 5, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_TMA2(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_TMA3(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_TMA4(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_TMA5(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 6, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_MACID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_PORT_INT(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(10, 8))
#define FWCMD_SET_ADDR_TSF_SYNC(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(13, 11))
#define FWCMD_SET_ADDR_TF_TRS(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(14))
#define FWCMD_SET_ADDR_LSIG_TXOP(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, BIT(15))
#define FWCMD_SET_ADDR_TGT_IND(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(26, 24))
#define FWCMD_SET_ADDR_FRM_TGT_IND(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 8, value, GENMASK(29, 27))
#define FWCMD_SET_ADDR_AID12(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 0))
#define FWCMD_SET_ADDR_AID12_0(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_AID12_1(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(11, 8))
#define FWCMD_SET_ADDR_WOL_PATTERN(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(12))
#define FWCMD_SET_ADDR_WOL_UC(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(13))
#define FWCMD_SET_ADDR_WOL_MAGIC(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(14))
#define FWCMD_SET_ADDR_WAPI(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, BIT(15))
#define FWCMD_SET_ADDR_SEC_ENT_MODE(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(17, 16))
#define FWCMD_SET_ADDR_SEC_ENT0_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(19, 18))
#define FWCMD_SET_ADDR_SEC_ENT1_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(21, 20))
#define FWCMD_SET_ADDR_SEC_ENT2_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(23, 22))
#define FWCMD_SET_ADDR_SEC_ENT3_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(25, 24))
#define FWCMD_SET_ADDR_SEC_ENT4_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(27, 26))
#define FWCMD_SET_ADDR_SEC_ENT5_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(29, 28))
#define FWCMD_SET_ADDR_SEC_ENT6_KEYID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 9, value, GENMASK(31, 30))
#define FWCMD_SET_ADDR_SEC_ENT_VALID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_SEC_ENT0(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_SEC_ENT1(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_SEC_ENT2(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 10, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_SEC_ENT3(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_SEC_ENT4(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_SEC_ENT5(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_SEC_ENT6(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 11, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_BSSID_IDX(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_BSSID_OFFSET(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_BSSID_LEN(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 12, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_BSSID_VALID(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(0))
#define FWCMD_SET_ADDR_BSSID_BB_SEL(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 13, value, BIT(1))
#define FWCMD_SET_ADDR_BSSID_BSS_COLOR(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(13, 8))
#define FWCMD_SET_ADDR_BSSID_BSSID0(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_BSSID_BSSID1(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 13, value, GENMASK(31, 24))
#define FWCMD_SET_ADDR_BSSID_BSSID2(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(7, 0))
#define FWCMD_SET_ADDR_BSSID_BSSID3(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(15, 8))
#define FWCMD_SET_ADDR_BSSID_BSSID4(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(23, 16))
#define FWCMD_SET_ADDR_BSSID_BSSID5(cmd, value) \
le32p_replace_bits((__le32 *)(cmd) + 14, value, GENMASK(31, 24))
int rtw89_cam_init(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
void rtw89_cam_deinit(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
void rtw89_cam_fill_addr_cam_info(struct rtw89_dev *rtwdev,
struct rtw89_vif *vif, u8 *cmd);
int rtw89_cam_fill_bssid_cam_info(struct rtw89_dev *rtwdev,
struct rtw89_vif *vif, u8 *cmd);
int rtw89_cam_sec_key_add(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key);
int rtw89_cam_sec_key_del(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta,
struct ieee80211_key_conf *key,
bool inform_fw);
void rtw89_cam_bssid_changed(struct rtw89_dev *rtwdev,
struct rtw89_vif *rtwvif);
void rtw89_cam_reset_keys(struct rtw89_dev *rtwdev);
#endif
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_COEX_H__
#define __RTW89_COEX_H__
#include "core.h"
enum btc_mode {
BTC_MODE_NORMAL,
BTC_MODE_WL,
BTC_MODE_BT,
BTC_MODE_WLOFF,
BTC_MODE_MAX
};
enum btc_wl_rfk_type {
BTC_WRFKT_IQK = 0,
BTC_WRFKT_LCK = 1,
BTC_WRFKT_DPK = 2,
BTC_WRFKT_TXGAPK = 3,
BTC_WRFKT_DACK = 4,
BTC_WRFKT_RXDCK = 5,
BTC_WRFKT_TSSI = 6,
};
#define NM_EXEC false
#define FC_EXEC true
#define RTW89_COEX_ACT1_WORK_PERIOD round_jiffies_relative(HZ * 4)
#define RTW89_COEX_BT_DEVINFO_WORK_PERIOD round_jiffies_relative(HZ * 16)
#define RTW89_COEX_RFK_CHK_WORK_PERIOD msecs_to_jiffies(300)
#define BTC_RFK_PATH_MAP GENMASK(3, 0)
#define BTC_RFK_PHY_MAP GENMASK(5, 4)
#define BTC_RFK_BAND_MAP GENMASK(7, 6)
enum btc_wl_rfk_state {
BTC_WRFK_STOP = 0,
BTC_WRFK_START = 1,
BTC_WRFK_ONESHOT_START = 2,
BTC_WRFK_ONESHOT_STOP = 3,
};
enum btc_pri {
BTC_PRI_MASK_RX_RESP = 0,
BTC_PRI_MASK_TX_RESP,
BTC_PRI_MASK_BEACON,
BTC_PRI_MASK_RX_CCK,
BTC_PRI_MASK_TX_MNGQ,
BTC_PRI_MASK_MAX,
};
enum btc_bt_trs {
BTC_BT_SS_GROUP = 0x0,
BTC_BT_TX_GROUP = 0x2,
BTC_BT_RX_GROUP = 0x3,
BTC_BT_MAX_GROUP,
};
enum btc_rssi_st {
BTC_RSSI_ST_LOW = 0x0,
BTC_RSSI_ST_HIGH,
BTC_RSSI_ST_STAY_LOW,
BTC_RSSI_ST_STAY_HIGH,
BTC_RSSI_ST_MAX
};
#define BTC_RSSI_HIGH(_rssi_) \
({typeof(_rssi_) __rssi = (_rssi_); \
((__rssi == BTC_RSSI_ST_HIGH || \
__rssi == BTC_RSSI_ST_STAY_HIGH) ? 1 : 0); })
#define BTC_RSSI_LOW(_rssi_) \
({typeof(_rssi_) __rssi = (_rssi_); \
((__rssi == BTC_RSSI_ST_LOW || \
__rssi == BTC_RSSI_ST_STAY_LOW) ? 1 : 0); })
#define BTC_RSSI_CHANGE(_rssi_) \
({typeof(_rssi_) __rssi = (_rssi_); \
((__rssi == BTC_RSSI_ST_LOW || \
__rssi == BTC_RSSI_ST_HIGH) ? 1 : 0); })
enum btc_ant {
BTC_ANT_SHARED = 0,
BTC_ANT_DEDICATED,
BTC_ANTTYPE_MAX
};
enum btc_bt_btg {
BTC_BT_ALONE = 0,
BTC_BT_BTG
};
enum btc_switch {
BTC_SWITCH_INTERNAL = 0,
BTC_SWITCH_EXTERNAL
};
enum btc_pkt_type {
PACKET_DHCP,
PACKET_ARP,
PACKET_EAPOL,
PACKET_EAPOL_END,
PACKET_ICMP,
PACKET_MAX
};
enum btc_bt_mailbox_id {
BTC_BTINFO_REPLY = 0x23,
BTC_BTINFO_AUTO = 0x27
};
enum btc_role_state {
BTC_ROLE_START,
BTC_ROLE_STOP,
BTC_ROLE_CHG_TYPE,
BTC_ROLE_MSTS_STA_CONN_START,
BTC_ROLE_MSTS_STA_CONN_END,
BTC_ROLE_MSTS_STA_DIS_CONN,
BTC_ROLE_MSTS_AP_START,
BTC_ROLE_MSTS_AP_STOP,
BTC_ROLE_STATE_UNKNOWN
};
enum btc_rfctrl {
BTC_RFCTRL_WL_OFF,
BTC_RFCTRL_WL_ON,
BTC_RFCTRL_FW_CTRL,
BTC_RFCTRL_MAX
};
void rtw89_btc_ntfy_poweron(struct rtw89_dev *rtwdev);
void rtw89_btc_ntfy_poweroff(struct rtw89_dev *rtwdev);
void rtw89_btc_ntfy_init(struct rtw89_dev *rtwdev, u8 mode);
void rtw89_btc_ntfy_scan_start(struct rtw89_dev *rtwdev, u8 phy_idx, u8 band);
void rtw89_btc_ntfy_scan_finish(struct rtw89_dev *rtwdev, u8 phy_idx);
void rtw89_btc_ntfy_switch_band(struct rtw89_dev *rtwdev, u8 phy_idx, u8 band);
void rtw89_btc_ntfy_specific_packet(struct rtw89_dev *rtwdev,
enum btc_pkt_type pkt_type);
void rtw89_btc_ntfy_eapol_packet_work(struct work_struct *work);
void rtw89_btc_ntfy_arp_packet_work(struct work_struct *work);
void rtw89_btc_ntfy_dhcp_packet_work(struct work_struct *work);
void rtw89_btc_ntfy_icmp_packet_work(struct work_struct *work);
void rtw89_btc_ntfy_role_info(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
struct rtw89_sta *rtwsta, enum btc_role_state state);
void rtw89_btc_ntfy_radio_state(struct rtw89_dev *rtwdev, enum btc_rfctrl rf_state);
void rtw89_btc_ntfy_wl_rfk(struct rtw89_dev *rtwdev, u8 phy_map,
enum btc_wl_rfk_type type,
enum btc_wl_rfk_state state);
void rtw89_btc_ntfy_wl_sta(struct rtw89_dev *rtwdev);
void rtw89_btc_c2h_handle(struct rtw89_dev *rtwdev, struct sk_buff *skb,
u32 len, u8 class, u8 func);
void rtw89_btc_dump_info(struct rtw89_dev *rtwdev, struct seq_file *m);
void rtw89_coex_act1_work(struct work_struct *work);
void rtw89_coex_bt_devinfo_work(struct work_struct *work);
void rtw89_coex_rfk_chk_work(struct work_struct *work);
void rtw89_coex_power_on(struct rtw89_dev *rtwdev);
static inline u8 rtw89_btc_phymap(struct rtw89_dev *rtwdev,
enum rtw89_phy_idx phy_idx,
enum rtw89_rf_path_bit paths)
{
struct rtw89_hal *hal = &rtwdev->hal;
u8 phy_map;
phy_map = FIELD_PREP(BTC_RFK_PATH_MAP, paths) |
FIELD_PREP(BTC_RFK_PHY_MAP, BIT(phy_idx)) |
FIELD_PREP(BTC_RFK_BAND_MAP, hal->current_band_type);
return phy_map;
}
static inline u8 rtw89_btc_path_phymap(struct rtw89_dev *rtwdev,
enum rtw89_phy_idx phy_idx,
enum rtw89_rf_path path)
{
return rtw89_btc_phymap(rtwdev, phy_idx, BIT(path));
}
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_DEBUG_H__
#define __RTW89_DEBUG_H__
#include "core.h"
enum rtw89_debug_mask {
RTW89_DBG_TXRX = BIT(0),
RTW89_DBG_RFK = BIT(1),
RTW89_DBG_RFK_TRACK = BIT(2),
RTW89_DBG_CFO = BIT(3),
RTW89_DBG_TSSI = BIT(4),
RTW89_DBG_TXPWR = BIT(5),
RTW89_DBG_HCI = BIT(6),
RTW89_DBG_RA = BIT(7),
RTW89_DBG_REGD = BIT(8),
RTW89_DBG_PHY_TRACK = BIT(9),
RTW89_DBG_DIG = BIT(10),
RTW89_DBG_SER = BIT(11),
RTW89_DBG_FW = BIT(12),
RTW89_DBG_BTC = BIT(13),
RTW89_DBG_BF = BIT(14),
};
enum rtw89_debug_mac_reg_sel {
RTW89_DBG_SEL_MAC_00,
RTW89_DBG_SEL_MAC_40,
RTW89_DBG_SEL_MAC_80,
RTW89_DBG_SEL_MAC_C0,
RTW89_DBG_SEL_MAC_E0,
RTW89_DBG_SEL_BB,
RTW89_DBG_SEL_IQK,
RTW89_DBG_SEL_RFC,
};
#ifdef CONFIG_RTW89_DEBUGFS
void rtw89_debugfs_init(struct rtw89_dev *rtwdev);
#else
static inline void rtw89_debugfs_init(struct rtw89_dev *rtwdev) {}
#endif
#define rtw89_info(rtwdev, a...) dev_info((rtwdev)->dev, ##a)
#define rtw89_warn(rtwdev, a...) dev_warn((rtwdev)->dev, ##a)
#define rtw89_err(rtwdev, a...) dev_err((rtwdev)->dev, ##a)
#ifdef CONFIG_RTW89_DEBUGMSG
extern unsigned int rtw89_debug_mask;
#define rtw89_debug(rtwdev, a...) __rtw89_debug(rtwdev, ##a)
__printf(3, 4)
void __rtw89_debug(struct rtw89_dev *rtwdev,
enum rtw89_debug_mask mask,
const char *fmt, ...);
static inline void rtw89_hex_dump(struct rtw89_dev *rtwdev,
enum rtw89_debug_mask mask,
const char *prefix_str,
const void *buf, size_t len)
{
if (!(rtw89_debug_mask & mask))
return;
print_hex_dump_bytes(prefix_str, DUMP_PREFIX_OFFSET, buf, len);
}
#else
static inline void rtw89_debug(struct rtw89_dev *rtwdev,
enum rtw89_debug_mask mask,
const char *fmt, ...) {}
static inline void rtw89_hex_dump(struct rtw89_dev *rtwdev,
enum rtw89_debug_mask mask,
const char *prefix_str,
const void *buf, size_t len) {}
#endif
#endif
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#include "debug.h"
#include "efuse.h"
#include "reg.h"
enum rtw89_efuse_bank {
RTW89_EFUSE_BANK_WIFI,
RTW89_EFUSE_BANK_BT,
};
static int rtw89_switch_efuse_bank(struct rtw89_dev *rtwdev,
enum rtw89_efuse_bank bank)
{
u8 val;
val = rtw89_read32_mask(rtwdev, R_AX_EFUSE_CTRL_1,
B_AX_EF_CELL_SEL_MASK);
if (bank == val)
return 0;
rtw89_write32_mask(rtwdev, R_AX_EFUSE_CTRL_1, B_AX_EF_CELL_SEL_MASK,
bank);
val = rtw89_read32_mask(rtwdev, R_AX_EFUSE_CTRL_1,
B_AX_EF_CELL_SEL_MASK);
if (bank == val)
return 0;
return -EBUSY;
}
static int rtw89_dump_physical_efuse_map(struct rtw89_dev *rtwdev, u8 *map,
u32 dump_addr, u32 dump_size)
{
u32 efuse_ctl;
u32 addr;
int ret;
rtw89_switch_efuse_bank(rtwdev, RTW89_EFUSE_BANK_WIFI);
for (addr = dump_addr; addr < dump_addr + dump_size; addr++) {
efuse_ctl = u32_encode_bits(addr, B_AX_EF_ADDR_MASK);
rtw89_write32(rtwdev, R_AX_EFUSE_CTRL, efuse_ctl & ~B_AX_EF_RDY);
ret = read_poll_timeout_atomic(rtw89_read32, efuse_ctl,
efuse_ctl & B_AX_EF_RDY, 1, 1000000,
true, rtwdev, R_AX_EFUSE_CTRL);
if (ret)
return -EBUSY;
*map++ = (u8)(efuse_ctl & 0xff);
}
return 0;
}
#define invalid_efuse_header(hdr1, hdr2) \
((hdr1) == 0xff || (hdr2) == 0xff)
#define invalid_efuse_content(word_en, i) \
(((word_en) & BIT(i)) != 0x0)
#define get_efuse_blk_idx(hdr1, hdr2) \
((((hdr2) & 0xf0) >> 4) | (((hdr1) & 0x0f) << 4))
#define block_idx_to_logical_idx(blk_idx, i) \
(((blk_idx) << 3) + ((i) << 1))
static int rtw89_dump_logical_efuse_map(struct rtw89_dev *rtwdev, u8 *phy_map,
u8 *log_map)
{
u32 physical_size = rtwdev->chip->physical_efuse_size;
u32 logical_size = rtwdev->chip->logical_efuse_size;
u8 sec_ctrl_size = rtwdev->chip->sec_ctrl_efuse_size;
u32 phy_idx = sec_ctrl_size;
u32 log_idx;
u8 hdr1, hdr2;
u8 blk_idx;
u8 word_en;
int i;
while (phy_idx < physical_size - sec_ctrl_size) {
hdr1 = phy_map[phy_idx];
hdr2 = phy_map[phy_idx + 1];
if (invalid_efuse_header(hdr1, hdr2))
break;
blk_idx = get_efuse_blk_idx(hdr1, hdr2);
word_en = hdr2 & 0xf;
phy_idx += 2;
for (i = 0; i < 4; i++) {
if (invalid_efuse_content(word_en, i))
continue;
log_idx = block_idx_to_logical_idx(blk_idx, i);
if (phy_idx + 1 > physical_size - sec_ctrl_size - 1 ||
log_idx + 1 > logical_size)
return -EINVAL;
log_map[log_idx] = phy_map[phy_idx];
log_map[log_idx + 1] = phy_map[phy_idx + 1];
phy_idx += 2;
}
}
return 0;
}
int rtw89_parse_efuse_map(struct rtw89_dev *rtwdev)
{
u32 phy_size = rtwdev->chip->physical_efuse_size;
u32 log_size = rtwdev->chip->logical_efuse_size;
u8 *phy_map = NULL;
u8 *log_map = NULL;
int ret;
if (rtw89_read16(rtwdev, R_AX_SYS_WL_EFUSE_CTRL) & B_AX_AUTOLOAD_SUS)
rtwdev->efuse.valid = true;
else
rtw89_warn(rtwdev, "failed to check efuse autoload\n");
phy_map = kmalloc(phy_size, GFP_KERNEL);
log_map = kmalloc(log_size, GFP_KERNEL);
if (!phy_map || !log_map) {
ret = -ENOMEM;
goto out_free;
}
ret = rtw89_dump_physical_efuse_map(rtwdev, phy_map, 0, phy_size);
if (ret) {
rtw89_warn(rtwdev, "failed to dump efuse physical map\n");
goto out_free;
}
memset(log_map, 0xff, log_size);
ret = rtw89_dump_logical_efuse_map(rtwdev, phy_map, log_map);
if (ret) {
rtw89_warn(rtwdev, "failed to dump efuse logical map\n");
goto out_free;
}
rtw89_hex_dump(rtwdev, RTW89_DBG_FW, "log_map: ", log_map, log_size);
ret = rtwdev->chip->ops->read_efuse(rtwdev, log_map);
if (ret) {
rtw89_warn(rtwdev, "failed to read efuse map\n");
goto out_free;
}
out_free:
kfree(log_map);
kfree(phy_map);
return ret;
}
int rtw89_parse_phycap_map(struct rtw89_dev *rtwdev)
{
u32 phycap_addr = rtwdev->chip->phycap_addr;
u32 phycap_size = rtwdev->chip->phycap_size;
u8 *phycap_map = NULL;
int ret = 0;
if (!phycap_size)
return 0;
phycap_map = kmalloc(phycap_size, GFP_KERNEL);
if (!phycap_map)
return -ENOMEM;
ret = rtw89_dump_physical_efuse_map(rtwdev, phycap_map,
phycap_addr, phycap_size);
if (ret) {
rtw89_warn(rtwdev, "failed to dump phycap map\n");
goto out_free;
}
ret = rtwdev->chip->ops->read_phycap(rtwdev, phycap_map);
if (ret) {
rtw89_warn(rtwdev, "failed to read phycap map\n");
goto out_free;
}
out_free:
kfree(phycap_map);
return ret;
}
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_EFUSE_H__
#define __RTW89_EFUSE_H__
#include "core.h"
int rtw89_parse_efuse_map(struct rtw89_dev *rtwdev);
int rtw89_parse_phycap_map(struct rtw89_dev *rtwdev);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#include "coex.h"
#include "core.h"
#include "debug.h"
#include "fw.h"
#include "mac.h"
#include "ps.h"
#include "reg.h"
#include "util.h"
static int rtw89_fw_leave_lps_check(struct rtw89_dev *rtwdev, u8 macid)
{
u32 pwr_en_bit = 0xE;
u32 chk_msk = pwr_en_bit << (4 * macid);
u32 polling;
int ret;
ret = read_poll_timeout_atomic(rtw89_read32_mask, polling, !polling,
1000, 50000, false, rtwdev,
R_AX_PPWRBIT_SETTING, chk_msk);
if (ret) {
rtw89_info(rtwdev, "rtw89: failed to leave lps state\n");
return -EBUSY;
}
return 0;
}
static void __rtw89_enter_ps_mode(struct rtw89_dev *rtwdev)
{
if (!rtwdev->ps_mode)
return;
if (test_and_set_bit(RTW89_FLAG_LOW_POWER_MODE, rtwdev->flags))
return;
rtw89_mac_power_mode_change(rtwdev, true);
}
void __rtw89_leave_ps_mode(struct rtw89_dev *rtwdev)
{
if (!rtwdev->ps_mode)
return;
if (test_and_clear_bit(RTW89_FLAG_LOW_POWER_MODE, rtwdev->flags))
rtw89_mac_power_mode_change(rtwdev, false);
}
static void __rtw89_enter_lps(struct rtw89_dev *rtwdev, u8 mac_id)
{
struct rtw89_lps_parm lps_param = {
.macid = mac_id,
.psmode = RTW89_MAC_AX_PS_MODE_LEGACY,
.lastrpwm = RTW89_LAST_RPWM_PS,
};
rtw89_btc_ntfy_radio_state(rtwdev, BTC_RFCTRL_FW_CTRL);
rtw89_fw_h2c_lps_parm(rtwdev, &lps_param);
}
static void __rtw89_leave_lps(struct rtw89_dev *rtwdev, u8 mac_id)
{
struct rtw89_lps_parm lps_param = {
.macid = mac_id,
.psmode = RTW89_MAC_AX_PS_MODE_ACTIVE,
.lastrpwm = RTW89_LAST_RPWM_ACTIVE,
};
rtw89_fw_h2c_lps_parm(rtwdev, &lps_param);
rtw89_fw_leave_lps_check(rtwdev, 0);
rtw89_btc_ntfy_radio_state(rtwdev, BTC_RFCTRL_WL_ON);
}
void rtw89_leave_ps_mode(struct rtw89_dev *rtwdev)
{
lockdep_assert_held(&rtwdev->mutex);
__rtw89_leave_ps_mode(rtwdev);
}
void rtw89_enter_lps(struct rtw89_dev *rtwdev, u8 mac_id)
{
lockdep_assert_held(&rtwdev->mutex);
if (test_and_set_bit(RTW89_FLAG_LEISURE_PS, rtwdev->flags))
return;
__rtw89_enter_lps(rtwdev, mac_id);
__rtw89_enter_ps_mode(rtwdev);
}
static void rtw89_leave_lps_vif(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif)
{
if (rtwvif->wifi_role != RTW89_WIFI_ROLE_STATION)
return;
__rtw89_leave_ps_mode(rtwdev);
__rtw89_leave_lps(rtwdev, rtwvif->mac_id);
}
void rtw89_leave_lps(struct rtw89_dev *rtwdev)
{
struct rtw89_vif *rtwvif;
lockdep_assert_held(&rtwdev->mutex);
if (!test_and_clear_bit(RTW89_FLAG_LEISURE_PS, rtwdev->flags))
return;
rtw89_for_each_rtwvif(rtwdev, rtwvif)
rtw89_leave_lps_vif(rtwdev, rtwvif);
}
void rtw89_enter_ips(struct rtw89_dev *rtwdev)
{
struct rtw89_vif *rtwvif;
set_bit(RTW89_FLAG_INACTIVE_PS, rtwdev->flags);
rtw89_for_each_rtwvif(rtwdev, rtwvif)
rtw89_mac_vif_deinit(rtwdev, rtwvif);
rtw89_core_stop(rtwdev);
}
void rtw89_leave_ips(struct rtw89_dev *rtwdev)
{
struct rtw89_vif *rtwvif;
int ret;
ret = rtw89_core_start(rtwdev);
if (ret)
rtw89_err(rtwdev, "failed to leave idle state\n");
rtw89_set_channel(rtwdev);
rtw89_for_each_rtwvif(rtwdev, rtwvif)
rtw89_mac_vif_init(rtwdev, rtwvif);
clear_bit(RTW89_FLAG_INACTIVE_PS, rtwdev->flags);
}
void rtw89_set_coex_ctrl_lps(struct rtw89_dev *rtwdev, bool btc_ctrl)
{
if (btc_ctrl)
rtw89_leave_lps(rtwdev);
}
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_PS_H_
#define __RTW89_PS_H_
void rtw89_enter_lps(struct rtw89_dev *rtwdev, u8 mac_id);
void rtw89_leave_lps(struct rtw89_dev *rtwdev);
void __rtw89_leave_ps_mode(struct rtw89_dev *rtwdev);
void rtw89_leave_ps_mode(struct rtw89_dev *rtwdev);
void rtw89_enter_ips(struct rtw89_dev *rtwdev);
void rtw89_leave_ips(struct rtw89_dev *rtwdev);
void rtw89_set_coex_ctrl_lps(struct rtw89_dev *rtwdev, bool btc_ctrl);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_8852A_RFK_H__
#define __RTW89_8852A_RFK_H__
#include "core.h"
void rtw8852a_rck(struct rtw89_dev *rtwdev);
void rtw8852a_dack(struct rtw89_dev *rtwdev);
void rtw8852a_iqk(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx);
void rtw8852a_iqk_track(struct rtw89_dev *rtwdev);
void rtw8852a_rx_dck(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy_idx,
bool is_afe);
void rtw8852a_dpk(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy);
void rtw8852a_dpk_track(struct rtw89_dev *rtwdev);
void rtw8852a_tssi(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy);
void rtw8852a_tssi_scan(struct rtw89_dev *rtwdev, enum rtw89_phy_idx phy);
void rtw8852a_tssi_track(struct rtw89_dev *rtwdev);
void rtw8852a_wifi_scan_notify(struct rtw89_dev *rtwdev, bool scan_start,
enum rtw89_phy_idx phy_idx);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __RTW89_8852A_TABLE_H__
#define __RTW89_8852A_TABLE_H__
#include "core.h"
extern const struct rtw89_phy_table rtw89_8852a_phy_bb_table;
extern const struct rtw89_phy_table rtw89_8852a_phy_radioa_table;
extern const struct rtw89_phy_table rtw89_8852a_phy_radiob_table;
extern const struct rtw89_phy_table rtw89_8852a_phy_nctl_table;
extern const struct rtw89_txpwr_table rtw89_8852a_byr_table;
extern const struct rtw89_phy_dig_gain_table rtw89_8852a_phy_dig_table;
extern const struct rtw89_txpwr_track_cfg rtw89_8852a_trk_cfg;
extern const s8 rtw89_8852a_txpwr_lmt_2g[RTW89_2G_BW_NUM][RTW89_NTX_NUM]
[RTW89_RS_LMT_NUM][RTW89_BF_NUM]
[RTW89_REGD_NUM][RTW89_2G_CH_NUM];
extern const s8 rtw89_8852a_txpwr_lmt_5g[RTW89_5G_BW_NUM][RTW89_NTX_NUM]
[RTW89_RS_LMT_NUM][RTW89_BF_NUM]
[RTW89_REGD_NUM][RTW89_5G_CH_NUM];
extern const s8 rtw89_8852a_txpwr_lmt_ru_2g[RTW89_RU_NUM][RTW89_NTX_NUM]
[RTW89_REGD_NUM][RTW89_2G_CH_NUM];
extern const s8 rtw89_8852a_txpwr_lmt_ru_5g[RTW89_RU_NUM][RTW89_NTX_NUM]
[RTW89_REGD_NUM][RTW89_5G_CH_NUM];
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
* Copyright(c) 2019-2020 Realtek Corporation
*/
#ifndef __SER_H__
#define __SER_H__
#include "core.h"
int rtw89_ser_init(struct rtw89_dev *rtwdev);
int rtw89_ser_deinit(struct rtw89_dev *rtwdev);
int rtw89_ser_notify(struct rtw89_dev *rtwdev, u32 err);
void rtw89_ser_recfg_done(struct rtw89_dev *rtwdev);
#endif /* __SER_H__*/
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment