wifi: rtl8xxxu: Clean up some messy ifs
authorBitterblue Smith <rtl8821cerfe2@gmail.com>
Mon, 10 Apr 2023 15:35:45 +0000 (18:35 +0300)
committerKalle Valo <kvalo@kernel.org>
Fri, 14 Apr 2023 12:32:09 +0000 (15:32 +0300)
Add some new members to rtl8xxxu_fileops and use them instead of
checking priv->rtl_chip.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/e24a5534-6e33-cfb9-0634-0caf4646513f@gmail.com
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188e.c
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8710b.c
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c

index 9d48c69ffece15ba6c7ec58a4281dd6b16e0c010..39fee07917e7dc2d007bddc8a752c544e6c549d6 100644 (file)
@@ -1923,6 +1923,11 @@ struct rtl8xxxu_fileops {
        u8 has_tx_report:1;
        u8 gen2_thermal_meter:1;
        u8 needs_full_init:1;
+       u8 init_reg_rxfltmap:1;
+       u8 init_reg_pkt_life_time:1;
+       u8 init_reg_hmtfr:1;
+       u8 ampdu_max_time;
+       u8 ustime_tsf_edca;
        u32 adda_1t_init;
        u32 adda_1t_path_on;
        u32 adda_2t_path_on_a;
index 6a82ec47568ee67d44dc7a4624ce31c4ff00192b..af8436070ba77e181107581cc201a14035a3d762 100644 (file)
@@ -1883,6 +1883,7 @@ struct rtl8xxxu_fileops rtl8188eu_fops = {
        .rx_desc_size = sizeof(struct rtl8xxxu_rxdesc16),
        .tx_desc_size = sizeof(struct rtl8xxxu_txdesc32),
        .has_tx_report = 1,
+       .init_reg_pkt_life_time = 1,
        .gen2_thermal_meter = 1,
        .adda_1t_init = 0x0b1b25a0,
        .adda_1t_path_on = 0x0bdb25a0,
index 82dee1fed47796323230958c1d34ddcae1434b0f..dfb250adb1689290b11936f350b4a28aaeb0e65e 100644 (file)
@@ -1746,6 +1746,11 @@ struct rtl8xxxu_fileops rtl8188fu_fops = {
        .has_tx_report = 1,
        .gen2_thermal_meter = 1,
        .needs_full_init = 1,
+       .init_reg_rxfltmap = 1,
+       .init_reg_pkt_life_time = 1,
+       .init_reg_hmtfr = 1,
+       .ampdu_max_time = 0x70,
+       .ustime_tsf_edca = 0x28,
        .adda_1t_init = 0x03c00014,
        .adda_1t_path_on = 0x03c00014,
        .trxff_boundary = 0x3f7f,
index 920466e39604bf3e6160e6fa588dca7770f9e4c1..22d4704dd31e1897df9d274a7a61d718b94d75ae 100644 (file)
@@ -1865,6 +1865,15 @@ struct rtl8xxxu_fileops rtl8710bu_fops = {
        .has_tx_report = 1,
        .gen2_thermal_meter = 1,
        .needs_full_init = 1,
+       .init_reg_rxfltmap = 1,
+       .init_reg_pkt_life_time = 1,
+       .init_reg_hmtfr = 1,
+       .ampdu_max_time = 0x5e,
+       /*
+        * The RTL8710BU vendor driver uses 0x50 here and it works fine,
+        * but in rtl8xxxu 0x50 causes slow upload and random packet loss. Why?
+        */
+       .ustime_tsf_edca = 0x28,
        .adda_1t_init = 0x03c00016,
        .adda_1t_path_on = 0x03c00016,
        .trxff_boundary = 0x3f7f,
index d99538eb83983496f964520d047e99194b9bab51..c31c2b52ac7737339c3a8c8d48612066c10315f0 100644 (file)
@@ -1741,6 +1741,9 @@ struct rtl8xxxu_fileops rtl8723bu_fops = {
        .has_tx_report = 1,
        .gen2_thermal_meter = 1,
        .needs_full_init = 1,
+       .init_reg_hmtfr = 1,
+       .ampdu_max_time = 0x5e,
+       .ustime_tsf_edca = 0x50,
        .adda_1t_init = 0x01c00014,
        .adda_1t_path_on = 0x01c00014,
        .adda_2t_path_on_a = 0x01c00014,
index c152b228606f168b85717b3dec970818fd19405a..62dd53a5765941bb02b93016426dfb36389b9f61 100644 (file)
@@ -1916,7 +1916,7 @@ static int rtl8xxxu_start_firmware(struct rtl8xxxu_priv *priv)
        /*
         * Init H2C command
         */
-       if (priv->rtl_chip == RTL8723B || priv->rtl_chip == RTL8188F || priv->rtl_chip == RTL8710B)
+       if (priv->fops->init_reg_hmtfr)
                rtl8xxxu_write8(priv, REG_HMTFR, 0x0f);
 exit:
        return ret;
@@ -3864,11 +3864,8 @@ void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
        rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
 
        rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
-       if (priv->rtl_chip == RTL8723B || priv->rtl_chip == RTL8710B)
-               val8 = 0x5e;
-       else if (priv->rtl_chip == RTL8188F)
-               val8 = 0x70; /* 0x5e would make it very slow */
-       rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, val8);
+       rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B,
+                       priv->fops->ampdu_max_time);
        rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
        rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
        rtl8xxxu_write8(priv, REG_PIFS, 0x00);
@@ -3876,16 +3873,8 @@ void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
                rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, FWHW_TXQ_CTRL_AMPDU_RETRY);
                rtl8xxxu_write32(priv, REG_FAST_EDCA_CTRL, 0x03086666);
        }
-       /*
-        * The RTL8710BU vendor driver uses 0x50 here and it works fine,
-        * but in rtl8xxxu 0x50 causes slow upload and random packet loss. Why?
-        */
-       if (priv->rtl_chip == RTL8723B)
-               val8 = 0x50;
-       else if (priv->rtl_chip == RTL8188F || priv->rtl_chip == RTL8710B)
-               val8 = 0x28; /* 0x50 would make the upload slow */
-       rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, val8);
-       rtl8xxxu_write8(priv, REG_USTIME_EDCA, val8);
+       rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, priv->fops->ustime_tsf_edca);
+       rtl8xxxu_write8(priv, REG_USTIME_EDCA, priv->fops->ustime_tsf_edca);
 
        /* to prevent mac is reseted by bus. */
        val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
@@ -4102,7 +4091,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
                RCR_APPEND_PHYSTAT | RCR_APPEND_ICV | RCR_APPEND_MIC;
        rtl8xxxu_write32(priv, REG_RCR, val32);
 
-       if (priv->rtl_chip == RTL8188F || priv->rtl_chip == RTL8710B) {
+       if (fops->init_reg_rxfltmap) {
                /* Accept all data frames */
                rtl8xxxu_write16(priv, REG_RXFLTMAP2, 0xffff);
 
@@ -4187,8 +4176,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
        if (fops->init_aggregation)
                fops->init_aggregation(priv);
 
-       if (priv->rtl_chip == RTL8188F || priv->rtl_chip == RTL8188E ||
-           priv->rtl_chip == RTL8710B) {
+       if (fops->init_reg_pkt_life_time) {
                rtl8xxxu_write16(priv, REG_PKT_VO_VI_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */
                rtl8xxxu_write16(priv, REG_PKT_BE_BK_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */
        }