Skip to contentSkip to conversation

wifi: rtl8xxxu: implement AP mode for 8188EU

RFC PATCH In review Georg Müller 4 participants 15 messages Mar 13 – Nov 25 RTL8XXXU wireless driver (rtl8xxxu)

lore
Share & tools
lore
#0 lore raw

v3 cover wifi: rtl8xxxu: implement AP mode for 8188EU

This series tries to implement AP mode for Realtek RTL8188EU chips.

This is not final. I still have issues connecting to the AP, searching for some input on what may be the reason or how to further debug issues.

Patch 1 could be picked independently as it shouldn't change anything for the non-AP mode.

---
Changes in v3:
- fix compile errors caused by testing on machine with older kernel Changes in v2:
- add patch to move dynamic_tx_rpt_timing_counter from ra_info to priv
- convert ra_info to a dynamic array
- update max report mac id after station add/remove

---
Georg Müller (4):
wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to
priv
wifi: rtl8xxxu: handle rate control for 8188e a per mac_id
wifi: rtl8xxxu: update max report mac id on station add / remove for

    8188e chips

wifi: rtl8xxxu: Enable AP mode for RTL8188EU

 drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 22 +++++-----
 drivers/net/wireless/realtek/rtl8xxxu/core.c  | 41 ++++++++++++++++---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  5 ++-
 3 files changed, 50 insertions(+), 18 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

RFC PATCH v3 1/4 wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to priv

dynamic_tx_rpt_timing_counter is not per mac_id, but used across all mac_ids.

---
 drivers/net/wireless/realtek/rtl8xxxu/8188e.c    | 8 ++++----
 drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +4 -4
index 766a7a7c7d28..de2837a91bbe 100644
@@ -1550,14 +1550,14 @@ static void rtl8188e_rate_decision(struct rtl8xxxu_ra_info *ra)
 	}
 
 	if (ra->decision_rate == ra->pre_rate)
-		ra->dynamic_tx_rpt_timing_counter++;
+		priv->dynamic_tx_rpt_timing_counter++;
 	else
-		ra->dynamic_tx_rpt_timing_counter = 0;
+		priv->dynamic_tx_rpt_timing_counter = 0;
 
-	if (ra->dynamic_tx_rpt_timing_counter >= 4) {
+	if (priv->dynamic_tx_rpt_timing_counter >= 4) {
 		/* Rate didn't change 4 times, extend RPT timing */
 		rtl8188e_set_tx_rpt_timing(ra, INCREASE_TIMING);
-		ra->dynamic_tx_rpt_timing_counter = 0;
+		priv->dynamic_tx_rpt_timing_counter = 0;
 	}
 
 	ra->pre_rate = ra->decision_rate;
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -1
index 9fb2583ffffc..4a744b5c1aec 100644
@@ -1756,7 +1756,6 @@ struct rtl8xxxu_ra_info {
 	u16 drop;
 	u16 rpt_time;
 	u16 pre_min_rpt_time;
-	u8 dynamic_tx_rpt_timing_counter;
 	u8 ra_waiting_counter;
 	u8 ra_pending_counter;
 	u8 ra_drop_after_down;
@@ -1917,6 +1916,7 @@ struct rtl8xxxu_priv {
 	struct rtl8xxxu_ra_report ra_report;
 	struct rtl8xxxu_cfo_tracking cfo_tracking;
 	struct rtl8xxxu_ra_info ra_info;
+	u8 dynamic_tx_rpt_timing_counter; // 8188e specific
 
 	bool led_registered;
 	char led_name[32];
Signature · 1 line
2.53.0
#2 lore raw

RE: [RFC PATCH v3 1/4] wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to priv

Quoted 2 lines · Georg Müller

dynamic_tx_rpt_timing_counter is not per mac_id, but used across all mac_ids.

I don't know the purpose of dynamic_tx_rpt_timing_counter. Could you share your study?

Ping-Ke

#3 lore raw

Re: [RFC PATCH v3 1/4] wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to priv

Am 16.03.26 um 07:17 schrieb Ping-Ke Shih:

Quoted 8 lines
Quoted 2 lines · Georg Müller

dynamic_tx_rpt_timing_counter is not per mac_id, but used across all mac_ids.

I don't know the purpose of dynamic_tx_rpt_timing_counter. Could you share your study?

It is used globally (not per mac) like this in the vendor driver as well [1][2]. Bitterblue Smith gave the hint that this should not be per macid [3], so it should move out of struct ra_info.

[1] https://github.com/lwfinger/rtl8188eu/blob/master/hal/Hal8188ERateAdaptive.c#L248
[2] https://github.com/lwfinger/rtl8188eu/blob/v5.2.2.4/hal8188erateadaptive.c#L285
[3] https://lore.kernel.org/linux-wireless/[email protected]/

#4 lore raw

RE: [RFC PATCH v3 1/4] wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to priv

Quoted 14 lines · Georg Müller

Am 16.03.26 um 07:17 schrieb Ping-Ke Shih:

Quoted 8 lines
Quoted 2 lines · Georg Müller

dynamic_tx_rpt_timing_counter is not per mac_id, but used across all mac_ids.

I don't know the purpose of dynamic_tx_rpt_timing_counter. Could you share your study?

It is used globally (not per mac) like this in the vendor driver as well [1][2]. Bitterblue Smith gave the hint that this should not be per macid [3], so it should move
out of struct ra_info.

Quoted 10 lines

[1]
https://github.com/lwfinger/rtl8188eu/blob/master/hal/Hal8188ERateAdaptive.c
#L248
[2]
https://github.com/lwfinger/rtl8188eu/blob/v5.2.2.4/hal8188erateadaptive.c#L
285
[3]
https://lore.kernel.org/linux-wireless/938ae608-a865-4056-06de-c230d74e1847@
gmail.com/

Thanks for the info. I can't find the log internally, so let's keep it as github does.

Ping-Ke

#5 lore raw

RFC PATCH v3 2/4 wifi: rtl8xxxu: handle rate control for 8188e a per mac_id

In reply to Georg Müller

convert member ra_info to an array with one entry per mac id. This allows having different rate control settings per connected station in ap mode.

The max_macid_num is conservative. The old driver used 32 [1], some other sources said 64 [2]. I have not enough adapters to test any of the higher values. Given the usage of this chipset in nano dongles, I think the 16 might be high enough.

[1] https://github.com/lwfinger/rtl8188eu/blob/f5d1c8df2e2d8b217ea0113bf2cf3e37df8cb716/include/sta_info.h#L28
[2] https://lore.kernel.org/linux-wireless/[email protected]/

---
 drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 12 ++++++------
 drivers/net/wireless/realtek/rtl8xxxu/core.c  | 19 ++++++++++++++-----
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  3 ++-
 3 files changed, 22 insertions(+), 12 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +6 -6
index de2837a91bbe..607ca62194fc 100644
@@ -1468,9 +1468,8 @@ static void rtl8188e_reset_ra_counter(struct rtl8xxxu_ra_info *ra)
 	ra->nsc_down = (n_threshold_high[rate_id] + n_threshold_low[rate_id]) >> 1;
 }
 
-static void rtl8188e_rate_decision(struct rtl8xxxu_ra_info *ra)
+static void rtl8188e_rate_decision(struct rtl8xxxu_priv *priv, struct rtl8xxxu_ra_info *ra)
 {
-	struct rtl8xxxu_priv *priv = container_of(ra, struct rtl8xxxu_priv, ra_info);
 	const u8 *retry_penalty_idx_0;
 	const u8 *retry_penalty_idx_1;
 	const u8 *retry_penalty_up_idx;
@@ -1669,7 +1668,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *s
 	u32 *_rx_desc = (u32 *)(skb->data - sizeof(struct rtl8xxxu_rxdesc16));
 	struct rtl8xxxu_rxdesc16 *rx_desc = (struct rtl8xxxu_rxdesc16 *)_rx_desc;
 	struct device *dev = &priv->udev->dev;
-	struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+	struct rtl8xxxu_ra_info *ra;
 	u32 tx_rpt_len = rx_desc->pktlen & 0x3ff;
 	u32 items = tx_rpt_len / TX_RPT2_ITEM_SIZE;
 	u64 macid_valid = ((u64)_rx_desc[5] << 32) | _rx_desc[4];
@@ -1688,6 +1687,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *s
 
 	for (macid = 0; macid < items; macid++) {
 		valid = false;
+		ra = &priv->ra_info[macid];
 
 		if (macid < 64)
 			valid = macid_valid & BIT(macid);
@@ -1704,7 +1704,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *s
 
 			if (ra->total > 0) {
 				if (ra->ra_stage < 5)
-					rtl8188e_rate_decision(ra);
+					rtl8188e_rate_decision(priv, ra);
 				else if (ra->ra_stage == 5)
 					rtl8188e_power_training_try_state(ra);
 				else /* ra->ra_stage == 6 */
@@ -1781,7 +1781,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
 			  u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
 			  u8 macid)
 {
-	struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+	struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
 
 	ra->rate_id = rateid;
 	ra->rate_mask = ramask;
@@ -1792,7 +1792,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
 
 static void rtl8188e_ra_set_rssi(struct rtl8xxxu_priv *priv, u8 macid, u8 rssi)
 {
-	priv->ra_info.rssi_sta_ra = rssi;
+	priv->ra_info[macid].rssi_sta_ra = rssi;
 }
 
 void rtl8188e_ra_info_init_all(struct rtl8xxxu_ra_info *ra)
drivers/net/wireless/realtek/rtl8xxxu/core.c +14 -5
index 794187d28caa..5ad23c5c9305 100644
@@ -3921,6 +3921,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
 	struct device *dev = &priv->udev->dev;
 	struct rtl8xxxu_fileops *fops = priv->fops;
 	bool macpower;
+	u16 mac_id;
 	int ret;
 	u8 val8;
 	u16 val16;
@@ -4393,9 +4394,16 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
 		priv->cfo_tracking.crystal_cap = priv->default_crystal_cap;
 	}
 
-	if (priv->rtl_chip == RTL8188E)
-		rtl8188e_ra_info_init_all(&priv->ra_info);
-
+	if (priv->rtl_chip == RTL8188E)	{
+		priv->ra_info = kmalloc_array(RTL8188E_MAX_MAC_ID_NUM, sizeof(*priv->ra_info), GFP_KERNEL);
+		if (!priv->ra_info) {
+			ret = -ENOMEM;
+			goto exit;
+		}
+		for (mac_id = 0; mac_id < RTL8188E_MAX_MAC_ID_NUM; mac_id++) {
+			rtl8188e_ra_info_init_all(&priv->ra_info[mac_id]);
+		}
+	}
 	set_bit(RTL8XXXU_BC_MC_MACID, priv->mac_id_map);
 	set_bit(RTL8XXXU_BC_MC_MACID1, priv->mac_id_map);
 
@@ -5338,7 +5346,7 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 {
 	struct rtl8xxxu_priv *priv = hw->priv;
 	struct device *dev = &priv->udev->dev;
-	struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+	struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
 	u8 *qc = ieee80211_get_qos_ctl(hdr);
 	u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
 	u32 rate = 0;
@@ -7895,6 +7903,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
 err_set_intfdata:
 	usb_set_intfdata(interface, NULL);
 
+	kfree(priv->ra_info);
 	kfree(priv->fw_data);
 	mutex_destroy(&priv->usb_buf_mutex);
 	mutex_destroy(&priv->syson_indirect_access_mutex);
@@ -7924,7 +7933,7 @@ static void rtl8xxxu_disconnect(struct usb_interface *interface)
 	usb_set_intfdata(interface, NULL);
 
 	dev_info(&priv->udev->dev, "disconnecting\n");
-
+	kfree(priv->ra_info);
 	kfree(priv->fw_data);
 	mutex_destroy(&priv->usb_buf_mutex);
 	mutex_destroy(&priv->syson_indirect_access_mutex);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2 -1
index 4a744b5c1aec..9ce820ff4793 100644
@@ -76,6 +76,7 @@
 #define RTL_FW_PAGE_SIZE		4096
 #define RTL8XXXU_FIRMWARE_POLL_MAX	1000
 
+#define RTL8188E_MAX_MAC_ID_NUM		16
 #define RTL8723A_CHANNEL_GROUPS		3
 #define RTL8723A_MAX_RF_PATHS		2
 #define RTL8723B_CHANNEL_GROUPS		6
@@ -1915,7 +1916,7 @@ struct rtl8xxxu_priv {
 	struct rtl8xxxu_btcoex bt_coex;
 	struct rtl8xxxu_ra_report ra_report;
 	struct rtl8xxxu_cfo_tracking cfo_tracking;
-	struct rtl8xxxu_ra_info ra_info;
+	struct rtl8xxxu_ra_info *ra_info;
 	u8 dynamic_tx_rpt_timing_counter; // 8188e specific
 
 	bool led_registered;
Signature · 1 line
2.53.0
#6 lore raw

RE: [RFC PATCH v3 2/4] wifi: rtl8xxxu: handle rate control for 8188e a per mac_id

Quoted 52 lines · Georg Müller

convert member ra_info to an array with one entry per mac id. This allows having different rate control settings per connected station in ap mode.

The max_macid_num is conservative. The old driver used 32 [1], some other sources said 64 [2]. I have not enough adapters to test any of the higher values. Given the usage of this chipset in nano dongles, I think the 16 might be high enough.

[1]
https://github.com/lwfinger/rtl8188eu/blob/f5d1c8df2e2d8b217ea0113bf2cf3e37d
f8cb716/include/sta_info.h#L28
[2]
https://lore.kernel.org/linux-wireless/27e83382-4c84-1841-c428-d1e5143ea20c@
gmail.com/

---
 drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 12 ++++++------
 drivers/net/wireless/realtek/rtl8xxxu/core.c  | 19 ++++++++++++++-----
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  3 ++-
 3 files changed, 22 insertions(+), 12 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -2
index de2837a91bbe..607ca62194fc 100644
@@ -1468,9 +1468,8 @@ static void rtl8188e_reset_ra_counter(struct
 rtl8xxxu_ra_info *ra)
        ra->nsc_down = (n_threshold_high[rate_id] + n_threshold_low[rate_id])
 >> 1;
 }
 
-static void rtl8188e_rate_decision(struct rtl8xxxu_ra_info *ra)
+static void rtl8188e_rate_decision(struct rtl8xxxu_priv *priv, struct
 rtl8xxxu_ra_info *ra)
 {
-       struct rtl8xxxu_priv *priv = container_of(ra, struct rtl8xxxu_priv,
ra_info);
        const u8 *retry_penalty_idx_0;
        const u8 *retry_penalty_idx_1;
        const u8 *retry_penalty_up_idx;
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -1
@@ -1669,7 +1668,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
        u32 *_rx_desc = (u32 *)(skb->data - sizeof(struct rtl8xxxu_rxdesc16));
        struct rtl8xxxu_rxdesc16 *rx_desc = (struct rtl8xxxu_rxdesc16
 *)_rx_desc;
        struct device *dev = &priv->udev->dev;
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra;
        u32 tx_rpt_len = rx_desc->pktlen & 0x3ff;
Quoted 1 line
        u32 items = tx_rpt_len / TX_RPT2_ITEM_SIZE;

The 'items' should be smaller or equal to RTL8188E_MAX_MAC_ID_NUM.

Quoted 53 lines
        u64 macid_valid = ((u64)_rx_desc[5] << 32) | _rx_desc[4];
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -0
@@ -1688,6 +1687,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
 
        for (macid = 0; macid < items; macid++) {
                valid = false;
+               ra = &priv->ra_info[macid];
 
                if (macid < 64)
                        valid = macid_valid & BIT(macid);
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -1
@@ -1704,7 +1704,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
 
                        if (ra->total > 0) {
                                if (ra->ra_stage < 5)
-                                       rtl8188e_rate_decision(ra);
+                                       rtl8188e_rate_decision(priv, ra);
                                else if (ra->ra_stage == 5)
 
rtl8188e_power_training_try_state(ra);
                                else /* ra->ra_stage == 6 */
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +2 -2
@@ -1781,7 +1781,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
                          u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
                          u8 macid)
 {
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
 
        ra->rate_id = rateid;
        ra->rate_mask = ramask;
@@ -1792,7 +1792,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
 
 static void rtl8188e_ra_set_rssi(struct rtl8xxxu_priv *priv, u8 macid, u8 rssi)
 {
-       priv->ra_info.rssi_sta_ra = rssi;
+       priv->ra_info[macid].rssi_sta_ra = rssi;
 }
 
 void rtl8188e_ra_info_init_all(struct rtl8xxxu_ra_info *ra)
drivers/net/wireless/realtek/rtl8xxxu/core.c +1 -0
index 794187d28caa..5ad23c5c9305 100644
@@ -3921,6 +3921,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
        struct device *dev = &priv->udev->dev;
        struct rtl8xxxu_fileops *fops = priv->fops;
        bool macpower;
+       u16 mac_id;
        int ret;
        u8 val8;
        u16 val16;

drivers/net/wireless/realtek/rtl8xxxu/core.c static int rtl8xxxu_init_device(struct ieee80211_hw *hw) · line 4399

Quoted 9 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -3
@@ -4393,9 +4394,16 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
                priv->cfo_tracking.crystal_cap = priv->default_crystal_cap;
        }
 
-       if (priv->rtl_chip == RTL8188E)
-               rtl8188e_ra_info_init_all(&priv->ra_info);
-
+       if (priv->rtl_chip == RTL8188E) {
+               priv->ra_info = kmalloc_array(RTL8188E_MAX_MAC_ID_NUM,
 sizeof(*priv->ra_info), GFP_KERNEL);

How about devm_ series? Then, no need to free on error path or disconnection.

drivers/net/wireless/realtek/rtl8xxxu/core.c static int rtl8xxxu_init_device(struct ieee80211_hw *hw) · line 4405

Quoted 7 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +7 -0
+               if (!priv->ra_info) {
+                       ret = -ENOMEM;
+                       goto exit;
+               }
+               for (mac_id = 0; mac_id < RTL8188E_MAX_MAC_ID_NUM; mac_id++) {
+                       rtl8188e_ra_info_init_all(&priv->ra_info[mac_id]);
+               }

no need brace for single line statement.

Quoted 46 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -1
+       }
        set_bit(RTL8XXXU_BC_MC_MACID, priv->mac_id_map);
        set_bit(RTL8XXXU_BC_MC_MACID1, priv->mac_id_map);
@@ -5338,7 +5346,7 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct
 ieee80211_hdr *hdr,
 {
        struct rtl8xxxu_priv *priv = hw->priv;
        struct device *dev = &priv->udev->dev;
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
        u8 *qc = ieee80211_get_qos_ctl(hdr);
        u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
        u32 rate = 0;
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -1
@@ -7895,6 +7903,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
 err_set_intfdata:
        usb_set_intfdata(interface, NULL);
 
+       kfree(priv->ra_info);
        kfree(priv->fw_data);
        mutex_destroy(&priv->usb_buf_mutex);
        mutex_destroy(&priv->syson_indirect_access_mutex);
@@ -7924,7 +7933,7 @@ static void rtl8xxxu_disconnect(struct usb_interface
 *interface)
        usb_set_intfdata(interface, NULL);
 
        dev_info(&priv->udev->dev, "disconnecting\n");
-
+       kfree(priv->ra_info);
        kfree(priv->fw_data);
        mutex_destroy(&priv->usb_buf_mutex);
        mutex_destroy(&priv->syson_indirect_access_mutex);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -0
index 4a744b5c1aec..9ce820ff4793 100644
@@ -76,6 +76,7 @@
 #define RTL_FW_PAGE_SIZE               4096
 #define RTL8XXXU_FIRMWARE_POLL_MAX     1000
 
+#define RTL8188E_MAX_MAC_ID_NUM                16
 #define RTL8723A_CHANNEL_GROUPS                3
 #define RTL8723A_MAX_RF_PATHS          2
 #define RTL8723B_CHANNEL_GROUPS                6

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h struct rtl8xxxu_priv { · line 1919

Quoted 5 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -1
@@ -1915,7 +1916,7 @@ struct rtl8xxxu_priv {
        struct rtl8xxxu_btcoex bt_coex;
        struct rtl8xxxu_ra_report ra_report;
        struct rtl8xxxu_cfo_tracking cfo_tracking;
-       struct rtl8xxxu_ra_info ra_info;
+       struct rtl8xxxu_ra_info *ra_info;

It looks like this is also 8188e specific. Could you add comment by the way? (but please /**/ style)

Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +0 -1
        u8 dynamic_tx_rpt_timing_counter; // 8188e specific
 
        bool led_registered;
--

2.53.0

#7 lore raw

Re: [RFC PATCH v3 2/4] wifi: rtl8xxxu: handle rate control for 8188e a per mac_id

Am 16.03.26 um 07:35 schrieb Ping-Ke Shih:

Quoted 48 lines
Quoted 47 lines · Georg Müller

convert member ra_info to an array with one entry per mac id. This allows having different rate control settings per connected station in ap mode.

The max_macid_num is conservative. The old driver used 32 [1], some other sources said 64 [2]. I have not enough adapters to test any of the higher values. Given the usage of this chipset in nano dongles, I think the 16 might be high enough.

[1]
https://github.com/lwfinger/rtl8188eu/blob/f5d1c8df2e2d8b217ea0113bf2cf3e37d
f8cb716/include/sta_info.h#L28
[2]
https://lore.kernel.org/linux-wireless/27e83382-4c84-1841-c428-d1e5143ea20c@
gmail.com/

---
  drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 12 ++++++------
  drivers/net/wireless/realtek/rtl8xxxu/core.c  | 19 ++++++++++++++-----
  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  3 ++-
  3 files changed, 22 insertions(+), 12 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -2
index de2837a91bbe..607ca62194fc 100644
@@ -1468,9 +1468,8 @@ static void rtl8188e_reset_ra_counter(struct
 rtl8xxxu_ra_info *ra)
         ra->nsc_down = (n_threshold_high[rate_id] + n_threshold_low[rate_id])
 >> 1;
  }
 
-static void rtl8188e_rate_decision(struct rtl8xxxu_ra_info *ra)
+static void rtl8188e_rate_decision(struct rtl8xxxu_priv *priv, struct
 rtl8xxxu_ra_info *ra)
  {
-       struct rtl8xxxu_priv *priv = container_of(ra, struct rtl8xxxu_priv,
ra_info);
         const u8 *retry_penalty_idx_0;
         const u8 *retry_penalty_idx_1;
         const u8 *retry_penalty_up_idx;
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +0 -0
@@ -1669,7 +1668,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
         u32 *_rx_desc = (u32 *)(skb->data - sizeof(struct rtl8xxxu_rxdesc16));
         struct rtl8xxxu_rxdesc16 *rx_desc = (struct rtl8xxxu_rxdesc16
Quoted 8 lines
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -1
 *)_rx_desc;
         struct device *dev = &priv->udev->dev;
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra;
         u32 tx_rpt_len = rx_desc->pktlen & 0x3ff;
         u32 items = tx_rpt_len / TX_RPT2_ITEM_SIZE;

The 'items' should be smaller or equal to RTL8188E_MAX_MAC_ID_NUM.

I will add a check.

Quoted 56 lines
Quoted 56 lines
         u64 macid_valid = ((u64)_rx_desc[5] << 32) | _rx_desc[4];
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -0
@@ -1688,6 +1687,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
 
         for (macid = 0; macid < items; macid++) {
                 valid = false;
+               ra = &priv->ra_info[macid];
 
                 if (macid < 64)
                         valid = macid_valid & BIT(macid);
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +1 -1
@@ -1704,7 +1704,7 @@ void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv
 *priv, struct sk_buff *s
 
                         if (ra->total > 0) {
                                 if (ra->ra_stage < 5)
-                                       rtl8188e_rate_decision(ra);
+                                       rtl8188e_rate_decision(priv, ra);
                                 else if (ra->ra_stage == 5)
 
rtl8188e_power_training_try_state(ra);
                                 else /* ra->ra_stage == 6 */
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +2 -2
@@ -1781,7 +1781,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
                           u32 ramask, u8 rateid, int sgi, int txbw_40mhz,
                           u8 macid)
  {
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
 
         ra->rate_id = rateid;
         ra->rate_mask = ramask;
@@ -1792,7 +1792,7 @@ rtl8188e_update_rate_mask(struct rtl8xxxu_priv *priv,
 
  static void rtl8188e_ra_set_rssi(struct rtl8xxxu_priv *priv, u8 macid, u8 rssi)
  {
-       priv->ra_info.rssi_sta_ra = rssi;
+       priv->ra_info[macid].rssi_sta_ra = rssi;
  }
 
  void rtl8188e_ra_info_init_all(struct rtl8xxxu_ra_info *ra)
drivers/net/wireless/realtek/rtl8xxxu/core.c +1 -0
index 794187d28caa..5ad23c5c9305 100644
@@ -3921,6 +3921,7 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
         struct device *dev = &priv->udev->dev;
         struct rtl8xxxu_fileops *fops = priv->fops;
         bool macpower;
+       u16 mac_id;
         int ret;
         u8 val8;
         u16 val16;
@@ -4393,9 +4394,16 @@ static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
                 priv->cfo_tracking.crystal_cap = priv->default_crystal_cap;
         }
 
Quoted 8 lines

drivers/net/wireless/realtek/rtl8xxxu/core.c static int rtl8xxxu_init_device(struct ieee80211_hw *hw)

Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -3
-       if (priv->rtl_chip == RTL8188E)
-               rtl8188e_ra_info_init_all(&priv->ra_info);
-
+       if (priv->rtl_chip == RTL8188E) {
+               priv->ra_info = kmalloc_array(RTL8188E_MAX_MAC_ID_NUM,
 sizeof(*priv->ra_info), GFP_KERNEL);

How about devm_ series? Then, no need to free on error path or disconnection.

I didn't know about these and will change it in the next version.

Quoted 9 lines

drivers/net/wireless/realtek/rtl8xxxu/core.c static int rtl8xxxu_init_device(struct ieee80211_hw *hw) · line 4405

Quoted 7 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +7 -0
+               if (!priv->ra_info) {
+                       ret = -ENOMEM;
+                       goto exit;
+               }
+               for (mac_id = 0; mac_id < RTL8188E_MAX_MAC_ID_NUM; mac_id++) {
+                       rtl8188e_ra_info_init_all(&priv->ra_info[mac_id]);
+               }

no need brace for single line statement.

I will change it in the next version.

Quoted 41 lines
Quoted 41 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -1
+       }
         set_bit(RTL8XXXU_BC_MC_MACID, priv->mac_id_map);
         set_bit(RTL8XXXU_BC_MC_MACID1, priv->mac_id_map);
@@ -5338,7 +5346,7 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct
 ieee80211_hdr *hdr,
  {
         struct rtl8xxxu_priv *priv = hw->priv;
         struct device *dev = &priv->udev->dev;
-       struct rtl8xxxu_ra_info *ra = &priv->ra_info;
+       struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
         u8 *qc = ieee80211_get_qos_ctl(hdr);
         u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
         u32 rate = 0;
drivers/net/wireless/realtek/rtl8xxxu/core.c +2 -1
@@ -7895,6 +7903,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
  err_set_intfdata:
         usb_set_intfdata(interface, NULL);
 
+       kfree(priv->ra_info);
         kfree(priv->fw_data);
         mutex_destroy(&priv->usb_buf_mutex);
         mutex_destroy(&priv->syson_indirect_access_mutex);
@@ -7924,7 +7933,7 @@ static void rtl8xxxu_disconnect(struct usb_interface
 *interface)
         usb_set_intfdata(interface, NULL);
 
         dev_info(&priv->udev->dev, "disconnecting\n");
-
+       kfree(priv->ra_info);
         kfree(priv->fw_data);
         mutex_destroy(&priv->usb_buf_mutex);
         mutex_destroy(&priv->syson_indirect_access_mutex);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +0 -0
index 4a744b5c1aec..9ce820ff4793 100644
@@ -76,6 +76,7 @@
  #define RTL_FW_PAGE_SIZE               4096
  #define RTL8XXXU_FIRMWARE_POLL_MAX     1000
 
Quoted 13 lines

drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h struct rtl8xxxu_priv { · line 1919

Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +2 -1
+#define RTL8188E_MAX_MAC_ID_NUM                16
  #define RTL8723A_CHANNEL_GROUPS                3
  #define RTL8723A_MAX_RF_PATHS          2
  #define RTL8723B_CHANNEL_GROUPS                6
@@ -1915,7 +1916,7 @@ struct rtl8xxxu_priv {
         struct rtl8xxxu_btcoex bt_coex;
         struct rtl8xxxu_ra_report ra_report;
         struct rtl8xxxu_cfo_tracking cfo_tracking;
-       struct rtl8xxxu_ra_info ra_info;
+       struct rtl8xxxu_ra_info *ra_info;

It looks like this is also 8188e specific. Could you add comment by the way? (but please /**/ style)

ok

Quoted 7 lines
Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +0 -1
         u8 dynamic_tx_rpt_timing_counter; // 8188e specific
 
         bool led_registered;
--

2.53.0

#8 lore raw

RFC PATCH v3 3/4 wifi: rtl8xxxu: update max report mac id on station add / remove for 8188e chips

In reply to Georg Müller
---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 23 +++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +22 -1
index 5ad23c5c9305..15fc4843edb2 100644
@@ -3884,6 +3884,15 @@ void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
 	rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
 }
 
+static u8 rtl8xxxu_max_acquired_macid(struct rtl8xxxu_priv *priv)
+{
+	u8 macid;
+
+	macid = find_last_bit(priv->mac_id_map, RTL8XXXU_MAX_MAC_ID_NUM);
+
+	return macid;
+}
+
 static u8 rtl8xxxu_acquire_macid(struct rtl8xxxu_priv *priv)
 {
 	u8 macid;
@@ -7499,6 +7508,7 @@ static int rtl8xxxu_sta_add(struct ieee80211_hw *hw,
 	struct rtl8xxxu_sta_info *sta_info = (struct rtl8xxxu_sta_info *)sta->drv_priv;
 	struct rtl8xxxu_vif *rtlvif = (struct rtl8xxxu_vif *)vif->drv_priv;
 	struct rtl8xxxu_priv *priv = hw->priv;
+	u8 max_mac_id;
 
 	mutex_lock(&priv->sta_mutex);
 	ewma_rssi_init(&sta_info->avg_rssi);
@@ -7510,6 +7520,11 @@ static int rtl8xxxu_sta_add(struct ieee80211_hw *hw,
 			return -ENOSPC;
 		}
 
+		if (priv->rtl_chip == RTL8188E) {
+			max_mac_id = rtl8xxxu_max_acquired_macid(priv);
+			rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1, max_mac_id + 1);
+		}
+
 		rtl8xxxu_refresh_rate_mask(priv, 0, sta, true);
 		priv->fops->report_connect(priv, sta_info->macid, H2C_MACID_ROLE_STA, true);
 	} else {
@@ -7535,10 +7550,16 @@ static int rtl8xxxu_sta_remove(struct ieee80211_hw *hw,
 {
 	struct rtl8xxxu_sta_info *sta_info = (struct rtl8xxxu_sta_info *)sta->drv_priv;
 	struct rtl8xxxu_priv *priv = hw->priv;
+	u8 max_mac_id;
 
 	mutex_lock(&priv->sta_mutex);
-	if (vif->type == NL80211_IFTYPE_AP)
+	if (vif->type == NL80211_IFTYPE_AP) {
 		rtl8xxxu_release_macid(priv, sta_info->macid);
+		if (priv->rtl_chip == RTL8188E) {
+			max_mac_id = rtl8xxxu_max_acquired_macid(priv);
+			rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1, max_mac_id + 1);
+		}
+	}
 	mutex_unlock(&priv->sta_mutex);
 
 	return 0;
Signature · 1 line
2.53.0
#9 lore raw

RE: [RFC PATCH v3 3/4] wifi: rtl8xxxu: update max report mac id on station add / remove for 8188e chips

Georg Müller <[email protected]> wrote:

remember to add commit messages when you send formal patch.

Quoted 56 lines
---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 23 +++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +10 -0
index 5ad23c5c9305..15fc4843edb2 100644
@@ -3884,6 +3884,15 @@ void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
        rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
 }
 
+static u8 rtl8xxxu_max_acquired_macid(struct rtl8xxxu_priv *priv)
+{
+       u8 macid;
+
+       macid = find_last_bit(priv->mac_id_map, RTL8XXXU_MAX_MAC_ID_NUM);
+
+       return macid;
+}
+
 static u8 rtl8xxxu_acquire_macid(struct rtl8xxxu_priv *priv)
 {
        u8 macid;
@@ -7499,6 +7508,7 @@ static int rtl8xxxu_sta_add(struct ieee80211_hw *hw,
        struct rtl8xxxu_sta_info *sta_info = (struct rtl8xxxu_sta_info
 *)sta->drv_priv;
        struct rtl8xxxu_vif *rtlvif = (struct rtl8xxxu_vif *)vif->drv_priv;
        struct rtl8xxxu_priv *priv = hw->priv;
+       u8 max_mac_id;
 
        mutex_lock(&priv->sta_mutex);
        ewma_rssi_init(&sta_info->avg_rssi);
drivers/net/wireless/realtek/rtl8xxxu/core.c +5 -0
@@ -7510,6 +7520,11 @@ static int rtl8xxxu_sta_add(struct ieee80211_hw *hw,
                        return -ENOSPC;
                }
 
+               if (priv->rtl_chip == RTL8188E) {
+                       max_mac_id = rtl8xxxu_max_acquired_macid(priv);
+                       rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1,
 max_mac_id + 1);
+               }
+
                rtl8xxxu_refresh_rate_mask(priv, 0, sta, true);
                priv->fops->report_connect(priv, sta_info->macid,
H2C_MACID_ROLE_STA, true);
        } else {
drivers/net/wireless/realtek/rtl8xxxu/core.c +1 -0
@@ -7535,10 +7550,16 @@ static int rtl8xxxu_sta_remove(struct ieee80211_hw *hw,
 {
        struct rtl8xxxu_sta_info *sta_info = (struct rtl8xxxu_sta_info
 *)sta->drv_priv;
        struct rtl8xxxu_priv *priv = hw->priv;
+       u8 max_mac_id;
 

drivers/net/wireless/realtek/rtl8xxxu/core.c static int rtl8xxxu_sta_remove(struct ieee80211_hw *hw, · line 7564

Quoted 10 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +6 -1
        mutex_lock(&priv->sta_mutex);
-       if (vif->type == NL80211_IFTYPE_AP)
+       if (vif->type == NL80211_IFTYPE_AP) {
                rtl8xxxu_release_macid(priv, sta_info->macid);
+               if (priv->rtl_chip == RTL8188E) {
+                       max_mac_id = rtl8xxxu_max_acquired_macid(priv);
+                       rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL + 1,
 max_mac_id + 1);
+               }
+       }

At first glance, I'd say should we consider STA+AP concurrent case? Because days ago, we talked about that in another thread.

It looks like MAC ID is another problem for concurrent case, because rtl8xxxu_max_acquired_macid() returns MAC ID starting from 0.

But special MAC IDs are defined for non-AP vif:

#define RTL8XXXU_BC_MC_MACID 0
#define RTL8XXXU_BC_MC_MACID1 1

(But this is not scope of this patch.)

Quoted 6 lines
drivers/net/wireless/realtek/rtl8xxxu/core.c +0 -0
        mutex_unlock(&priv->sta_mutex);
        return 0;

--
2.53.0

#10 lore raw

RFC PATCH v3 4/4 wifi: rtl8xxxu: Enable AP mode for RTL8188EU

In reply to Georg Müller

Allow devices with this driver to be used as a wireless access point.

---
 drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/realtek/rtl8xxxu/8188e.c +2 -0
index 607ca62194fc..67fd77944d67 100644
@@ -1867,6 +1867,8 @@ struct rtl8xxxu_fileops rtl8188eu_fops = {
 	.init_reg_pkt_life_time = 1,
 	.gen2_thermal_meter = 1,
 	.max_sec_cam_num = 32,
+	.supports_ap = 1,
+	.max_macid_num = RTL8188E_MAX_MAC_ID_NUM,
 	.adda_1t_init = 0x0b1b25a0,
 	.adda_1t_path_on = 0x0bdb25a0,
 	/*
Signature · 1 line
2.53.0
#11 lore raw
In reply to Georg Müller
Quoted 5 lines · Georg Müller

This series tries to implement AP mode for Realtek RTL8188EU chips.

This is not final. I still have issues connecting to the AP, searching for some input on what may be the reason or how to further debug issues.

What are the issues? Were they happening with your original patch which only added supports_ap and max_macid_num?

Another thing still missing is the macid in the TX descriptor (rtl8xxxu_fill_txdesc_v3).

Quoted 25 lines

Patch 1 could be picked independently as it shouldn't change anything for the non-AP mode.

---
Changes in v3:
- fix compile errors caused by testing on machine with older kernel Changes in v2:
- add patch to move dynamic_tx_rpt_timing_counter from ra_info to priv
- convert ra_info to a dynamic array
- update max report mac id after station add/remove

---
Georg Müller (4):
wifi: rtl8xxxu: move dynamic_tx_rpt_timing_counter from ra_info to
priv
wifi: rtl8xxxu: handle rate control for 8188e a per mac_id
wifi: rtl8xxxu: update max report mac id on station add / remove for

    8188e chips

wifi: rtl8xxxu: Enable AP mode for RTL8188EU

 drivers/net/wireless/realtek/rtl8xxxu/8188e.c | 22 +++++-----
 drivers/net/wireless/realtek/rtl8xxxu/core.c  | 41 ++++++++++++++++---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  5 ++-
 3 files changed, 50 insertions(+), 18 deletions(-)
#12 lore raw

Just to give a litte update:

Am 14.03.26 um 00:14 schrieb Bitterblue Smith:

Quoted 5 lines

What are the issues? Were they happening with your original patch which only added supports_ap and max_macid_num?

Another thing still missing is the macid in the TX descriptor (rtl8xxxu_fill_txdesc_v3).

I added setting the macid in rtl8xxxu_fill_txdesc_v3 and the other comments to the patches.

There are still some issues:

In a test setup, I connected 5 different devices to a host running with a 8188eu wifi dongle running in AP mode and a web server running on it.

All were able to fetch a web page served by the host.

Sometimes the connection was a bit stuck, but this recovered after some time.

In the logs of the server with the 8188eu dongle, I sometimes observed the following messages in dmesg (with debug messages turned on):

C2H TX report type 2 rtl8188e_handle_ra_tx_report2: len: 24 items: 3 rtl8188e_handle_ra_tx_report2: TX report item 0 not valid

  rtl8188e_handle_ra_tx_report2:  valid: 0 retry: 0 0 0 0 0 drop: 0
  rtl8188e_handle_ra_tx_report2:  valid: 0 retry: 0 0 0 0 0 drop: 0
  rtl8188e_handle_ra_tx_report2:  valid: 1 retry: 5 0 0 0 0 drop: 0

another thing which sometimes occurred:

rtl8xxxu_read8(020a) = 0x00, len 1 # <- repeated 50-70 times
rtl8xxxu_send_beacon_frame: Failed to read beacon valid bit

What I observed on one of the clients was DUP ping responses. I will try to debug this with a wifi capture device.

Best regards,
Georg

#13 lore raw

Hi Georg, Bitterblue,

I tested v3 on rtw-next (18d0bedbb5f0, context fixes in patches 2 and 4 only) with an Edimax EW-7811Un V2 (RTL8188EUS rev D) as AP and a separate sniffer. I found three problems in the AP part, plus an older one that explains the duplicate pings.

1. Beacons. After hostapd starts, the 8188e sends one beacon and then none. Probe responses go out, so clients still find the AP by active scanning, but association takes about 6 s and a passive scan sees nothing. BCN_VALID is set and the beacon function is enabled; the hardware clears the beacon queue after the first beacon. In AP mode the vendor driver (hw_var_set_opmode()) sets BIT(3) | BIT(4) in REG_MBID_NUM, commented "If set 0, hw will clr bcnq when tx becon ok/fail". With that there is a beacon at every TBTT and association takes 0.5 s.

2. TBTT hold time. rtl8xxxu_start_tx_beacon() writes 0x80 to REG_TBTT_PROHIBIT + 1 and clears bit 0 of + 2; the vendor ResumeTxBeacon() writes 0xff and sets bit 0. On channel 6 with several neighbour APs, 7 runs of about 120 TBTTs each: 2-5 % of the beacons missing (one run 42 %) with the rtl8xxxu value; with the vendor value 0 % in 5 runs and 1-3 % in 2.

3. macid in the TX descriptor, which Bitterblue pointed out:
rtl8xxxu_fill_txdesc_v3() still does not set it; the vendor driver puts mac_id & 0x3f into txdw1. The same function also indexes priv->ra_info[macid] now, but for group addressed frames with a key, rtl8xxxu_tx() replaces macid with the security CAM index, which can go past the 16 entries of ra_info.

This is what I use on top of v3 for 1-3:

drivers/net/wireless/realtek/rtl8xxxu/core.c +20 -1
index 49c167fd6ee4..9a297b077443 100644
@@ -1154,6 +1154,14 @@ static void rtl8xxxu_start_tx_beacon(struct rtl8xxxu_priv *priv)
 	val8 |= EN_BCNQ_DL >> 16;
 	rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
 
+	if (priv->rtl_chip == RTL8188E) {
+		rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0xff);
+		val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
+		val8 |= BIT(0);
+		rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
+		return;
+	}
+
 	rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x80);
 	val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
 	val8 &= 0xF0;
@@ -5572,7 +5580,7 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 {
 	struct rtl8xxxu_priv *priv = hw->priv;
 	struct device *dev = &priv->udev->dev;
-	struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
+	struct rtl8xxxu_ra_info *ra;
 	u8 *qc = ieee80211_get_qos_ctl(hdr);
 	u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
 	u32 rate = 0;
@@ -5580,6 +5588,10 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 
 	seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
 
+	/* macid is the security CAM index for group addressed frames */
+	ra = &priv->ra_info[macid < RTL8188E_MAX_MAC_ID_NUM ? macid : 0];
+	tx_desc->txdw1 |= cpu_to_le32(macid & 0x3f);
+
 	if (ieee80211_is_data(hdr->frame_control)) {
 		rate = ra->decision_rate;
 		tx_desc->txdw5 = cpu_to_le32(rate);
@@ -7002,6 +7014,13 @@ static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
 		rtl8xxxu_write16(priv, REG_TSFTR_SYN_OFFSET, 0x7fff); /* ~32ms */
 		rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, DUAL_TSF_RESET_TSF0);
 
+		/* The 8188e clears the beacon queue after each beacon unless told not to */
+		if (priv->rtl_chip == RTL8188E) {
+			val8 = rtl8xxxu_read8(priv, REG_MBID_NUM);
+			val8 |= BIT(3) | BIT(4);
+			rtl8xxxu_write8(priv, REG_MBID_NUM, val8);
+		}
+
 		/* enable BCN0 function */
 		rtl8xxxu_write8(priv, REG_BEACON_CTRL,
 				BEACON_DISABLE_TSF_UPDATE |

With these, beacon loss is 0.5-3.4 % at the sniffer and association takes 0.5 s.

4. Duplicate pings. I can reproduce them with two clients, on one of the two and in both directions, and not with one client. The captures show the client sending the same MSDU again with a new sequence number after its retry limit, because many of its frames are not acked: 62-73 % of the frames sent to the 8188e carry the retry bit.

This is not AP specific. With the 8188e as a station of an rtw88 AP, same dongle, place and traffic, 63 % of the frames to the 8188e are retries with rtl8xxxu and 0 % with Realtek's v5.3.9 driver (aircrack-ng/rtl8188eus with kernel API fixes only, on a non-RT kernel; it crashes on PREEMPT_RT). I dumped the registers of both
drivers while associated and wrote the vendor values into rtl8xxxu one group at a time. The difference is REG_OFDM0_XA_AGC_CORE1:
rtl8xxxu_start() sets the IGI to 0x1e (see c8bc37602779 ("wifi:
rtl8xxxu: Simplify setting the initial gain")) and nothing changes it later, while the vendor driver had 0x40 in that test. With IGI 0x40 alone the retries drop to 1 %.

A fixed value does not solve it, though. In AP mode with the two clients at -44 and -52 dBm, IGI 0x40 removes the duplicates but loses 35-65 % of the pings. The 8188e seems to need the vendor's dynamic initial gain (IGI from the lowest station RSSI and the false alarm count). Bitterblue, is there a reason rtl8xxxu has no DIG, or would a simple one for the 8188e be acceptable?

Georg, do you plan a v4? I can send 1-3 as patches on top of your series, or include them in a v4 with your patches if you prefer.

Best regards,
Mehmet

#14 lore raw
Quoted 24 lines · Mehmet Fide

Hi Georg, Bitterblue,

I tested v3 on rtw-next (18d0bedbb5f0, context fixes in patches 2 and 4 only) with an Edimax EW-7811Un V2 (RTL8188EUS rev D) as AP and a separate sniffer. I found three problems in the AP part, plus an older one that explains the duplicate pings.

1. Beacons. After hostapd starts, the 8188e sends one beacon and then none. Probe responses go out, so clients still find the AP by active scanning, but association takes about 6 s and a passive scan sees nothing. BCN_VALID is set and the beacon function is enabled; the hardware clears the beacon queue after the first beacon. In AP mode the vendor driver (hw_var_set_opmode()) sets BIT(3) | BIT(4) in REG_MBID_NUM, commented "If set 0, hw will clr bcnq when tx becon ok/fail". With that there is a beacon at every TBTT and association takes 0.5 s.

2. TBTT hold time. rtl8xxxu_start_tx_beacon() writes 0x80 to REG_TBTT_PROHIBIT + 1 and clears bit 0 of + 2; the vendor ResumeTxBeacon() writes 0xff and sets bit 0. On channel 6 with several neighbour APs, 7 runs of about 120 TBTTs each: 2-5 % of the beacons missing (one run 42 %) with the rtl8xxxu value; with the vendor value 0 % in 5 runs and 1-3 % in 2.

Quoted 6 lines

3. macid in the TX descriptor, which Bitterblue pointed out:
rtl8xxxu_fill_txdesc_v3() still does not set it; the vendor driver puts mac_id & 0x3f into txdw1. The same function also indexes priv->ra_info[macid] now, but for group addressed frames with a key, rtl8xxxu_tx() replaces macid with the security CAM index, which can go past the 16 entries of ra_info.

RTL8188E_MAX_MAC_ID_NUM should be 64 (hal_spec->macid_num = 64 in hal/rtl8188e/rtl8188e_hal_init.c).

Quoted 78 lines

This is what I use on top of v3 for 1-3:

drivers/net/wireless/realtek/rtl8xxxu/core.c +20 -1
index 49c167fd6ee4..9a297b077443 100644
@@ -1154,6 +1154,14 @@ static void rtl8xxxu_start_tx_beacon(struct rtl8xxxu_priv *priv)
 	val8 |= EN_BCNQ_DL >> 16;
 	rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL + 2, val8);
 
+	if (priv->rtl_chip == RTL8188E) {
+		rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0xff);
+		val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
+		val8 |= BIT(0);
+		rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 2, val8);
+		return;
+	}
+
 	rtl8xxxu_write8(priv, REG_TBTT_PROHIBIT + 1, 0x80);
 	val8 = rtl8xxxu_read8(priv, REG_TBTT_PROHIBIT + 2);
 	val8 &= 0xF0;
@@ -5572,7 +5580,7 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 {
 	struct rtl8xxxu_priv *priv = hw->priv;
 	struct device *dev = &priv->udev->dev;
-	struct rtl8xxxu_ra_info *ra = &priv->ra_info[macid];
+	struct rtl8xxxu_ra_info *ra;
 	u8 *qc = ieee80211_get_qos_ctl(hdr);
 	u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
 	u32 rate = 0;
@@ -5580,6 +5588,10 @@ rtl8xxxu_fill_txdesc_v3(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 
 	seq_number = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
 
+	/* macid is the security CAM index for group addressed frames */
+	ra = &priv->ra_info[macid < RTL8188E_MAX_MAC_ID_NUM ? macid : 0];
+	tx_desc->txdw1 |= cpu_to_le32(macid & 0x3f);
+
 	if (ieee80211_is_data(hdr->frame_control)) {
 		rate = ra->decision_rate;
 		tx_desc->txdw5 = cpu_to_le32(rate);
@@ -7002,6 +7014,13 @@ static int rtl8xxxu_add_interface(struct ieee80211_hw *hw,
 		rtl8xxxu_write16(priv, REG_TSFTR_SYN_OFFSET, 0x7fff); /* ~32ms */
 		rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, DUAL_TSF_RESET_TSF0);
 
+		/* The 8188e clears the beacon queue after each beacon unless told not to */
+		if (priv->rtl_chip == RTL8188E) {
+			val8 = rtl8xxxu_read8(priv, REG_MBID_NUM);
+			val8 |= BIT(3) | BIT(4);
+			rtl8xxxu_write8(priv, REG_MBID_NUM, val8);
+		}
+
 		/* enable BCN0 function */
 		rtl8xxxu_write8(priv, REG_BEACON_CTRL,
 				BEACON_DISABLE_TSF_UPDATE |

With these, beacon loss is 0.5-3.4 % at the sniffer and association takes 0.5 s.

4. Duplicate pings. I can reproduce them with two clients, on one of the two and in both directions, and not with one client. The captures show the client sending the same MSDU again with a new sequence number after its retry limit, because many of its frames are not acked: 62-73 % of the frames sent to the 8188e carry the retry bit.

This is not AP specific. With the 8188e as a station of an rtw88 AP, same dongle, place and traffic, 63 % of the frames to the 8188e are retries with rtl8xxxu and 0 % with Realtek's v5.3.9 driver (aircrack-ng/rtl8188eus with kernel API fixes only, on a non-RT kernel; it crashes on PREEMPT_RT). I dumped the registers of both
drivers while associated and wrote the vendor values into rtl8xxxu one group at a time. The difference is REG_OFDM0_XA_AGC_CORE1:
rtl8xxxu_start() sets the IGI to 0x1e (see c8bc37602779 ("wifi:
rtl8xxxu: Simplify setting the initial gain")) and nothing changes it later, while the vendor driver had 0x40 in that test. With IGI 0x40 alone the retries drop to 1 %.

Quoted 6 lines

A fixed value does not solve it, though. In AP mode with the two clients at -44 and -52 dBm, IGI 0x40 removes the duplicates but loses 35-65 % of the pings. The 8188e seems to need the vendor's dynamic initial gain (IGI from the lowest station RSSI and the false alarm count). Bitterblue, is there a reason rtl8xxxu has no DIG, or would a simple one for the 8188e be acceptable?

I think the reason is just that nobody implemented it yet.

Quoted 6 lines

Georg, do you plan a v4? I can send 1-3 as patches on top of your series, or include them in a v4 with your patches if you prefer.

Best regards,
Mehmet