mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH rtw-next 0/3] wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames
@ 2026-11-19 22:09 Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips Ahmet Zeren via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ahmet Zeren via B4 Relay @ 2026-11-19 22:09 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: linux-wireless, linux-kernel, Ping-Ke Shih, Ahmet Zeren

rtl8xxxu ignores most of the radiotap header of injected frames. On a
RTL8192CU every injected frame went out at MCS 7 and 20 MHz whatever was
requested, the retry count was ignored, and NOACK frames were retried up
to 48 times. That makes the driver unusable for tools that rely on
fixed-rate injection.

Patch 1 makes gen1 chips (RTL8188CU, RTL8192CU, RTL8723AU) use the
injected rate and guard interval, without rate fallback.

Patch 2 makes the radiotap retry count and NOACK work. max_rate_tries is
0 today, so mac80211 clamps injected retries to zero, and the hardware
default of 48 retries is used instead: unicast frames to an absent
station then stalled injection for over 100 s in my tests.

Patch 3 sends injected frames at 40 MHz when they ask for it. Only QoS
data frames get the 40 MHz descriptor bits today.

Frames without radiotap rate information are not affected.

Gen2 chips and the RTL8188EU use other descriptor formats. Patches for
them follow as a separate RFT series, since I cannot test them.

Testing, all on RTL8192CU (0bda:8178) in monitor mode, received by a
second radio:
- 1, 5.5, 6 and 54 Mbps and MCS 0/7/8/15 with long and short GI arrive
  at the requested rate (stock driver: all MCS 7).
- Unicast frames to an absent station: drain time grows with the
  requested retry count, NOACK frames are sent once.
- Channel 6 HT40+ and HT40-: MCS 0 and 7 requested at 40 MHz arrive at
  40 MHz (stock driver: 20 MHz).
- checkpatch --strict, W=1 and sparse are clean for each patch.

AI tool use (Documentation/process/generated-content.rst): the patches
were written with help from Claude Code (Claude Opus 5.5). It was asked
to find why injected frames ignore the radiotap rate, retry count and
bandwidth, write the fixes, and run the over-the-air tests above. I have
reviewed and tested the changes and take responsibility for them.

---
Ahmet Zeren (3):
      wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
      wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips
      wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips

 drivers/net/wireless/realtek/rtl8xxxu/core.c | 78 +++++++++++++++++++++++++---
 1 file changed, 70 insertions(+), 8 deletions(-)
---
base-commit: 0bdc579dbfc251a6b6838ee9459b6771b948c617
change-id: 20261120-b4-inject-f6f4bc873392

Best regards,
--  
Ahmet Zeren <niko3x@proton.me>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
  2026-11-19 22:09 [PATCH rtw-next 0/3] wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames Ahmet Zeren via B4 Relay
@ 2026-11-19 22:09 ` Ahmet Zeren via B4 Relay
  2026-11-22  1:51   ` Ping-Ke Shih
  2026-11-19 22:09 ` [PATCH rtw-next 2/3] wifi: rtl8xxxu: honour the retry count " Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 3/3] wifi: rtl8xxxu: honour the bandwidth " Ahmet Zeren via B4 Relay
  2 siblings, 1 reply; 5+ messages in thread
From: Ahmet Zeren via B4 Relay @ 2026-11-19 22:09 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: linux-wireless, linux-kernel, Ping-Ke Shih, Ahmet Zeren

From: Ahmet Zeren <niko3x@proton.me>

When a frame is injected with a rate in its radiotap header, the driver
ignores it and leaves the choice to the firmware rate adaptation. On a
RTL8192CU every injected frame went out at MCS 7, whatever was asked.

Use the injected rate and guard interval, and disable rate fallback so
the frame is sent at exactly that rate.

Tested on RTL8192CU (0bda:8178) in monitor mode on 2.4 GHz: 1, 5.5, 6
and 54 Mbps, MCS 0/7/8/15 with long and short GI were all received at
the requested rate. Frames without a radiotap rate are unchanged.

Signed-off-by: Ahmet Zeren <niko3x@proton.me>
---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 29 ++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c
index 604bb1e5b0..969875fd54 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
@@ -5223,6 +5223,28 @@ static void rtl8xxxu_dump_action(struct device *dev,
 	}
 }
 
+/*
+ * Use the rate from the radiotap header of an injected frame, if any.
+ * mac80211 has already checked it against what we advertise.
+ */
+static bool rtl8xxxu_tx_rate_inject(struct ieee80211_tx_info *tx_info,
+				    u32 *rate, bool *sgi)
+{
+	struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
+
+	if (!(tx_info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT))
+		return false;
+
+	if (txrate->flags & IEEE80211_TX_RC_MCS)
+		*rate = DESC_RATE_MCS0 + txrate->idx;
+	else
+		*rate = rtl8xxxu_legacy_ratetable[txrate->idx].hw_value;
+
+	*sgi = txrate->flags & IEEE80211_TX_RC_SHORT_GI;
+
+	return true;
+}
+
 /*
  * Fill in v1 (gen1) specific TX descriptor bits.
  * This format is used on 8188cu/8192cu/8723au
@@ -5240,6 +5262,9 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 	u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
 	u32 rate = 0;
 	u16 seq_number;
+	bool inject;
+
+	inject = rtl8xxxu_tx_rate_inject(tx_info, &rate, &sgi);
 
 	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
 		dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
@@ -5285,6 +5310,10 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 	if (sgi)
 		tx_desc->txdw5 |= cpu_to_le32(TXDESC32_SHORT_GI);
 
+	if (inject)
+		tx_desc->txdw4 |= cpu_to_le32(TXDESC32_USE_DRIVER_RATE |
+					      TXDESC_DISABLE_DATA_FB);
+
 	/*
 	 * rts_rate is zero if RTS/CTS or CTS to SELF are not enabled
 	 */

-- 
2.56.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH rtw-next 2/3] wifi: rtl8xxxu: honour the retry count of injected frames on gen1 chips
  2026-11-19 22:09 [PATCH rtw-next 0/3] wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips Ahmet Zeren via B4 Relay
@ 2026-11-19 22:09 ` Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 3/3] wifi: rtl8xxxu: honour the bandwidth " Ahmet Zeren via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Ahmet Zeren via B4 Relay @ 2026-11-19 22:09 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: linux-wireless, linux-kernel, Ping-Ke Shih, Ahmet Zeren

From: Ahmet Zeren <niko3x@proton.me>

max_rate_tries is never set, so mac80211 clamps the retry count of every
injected frame to zero and the radiotap retries field has no effect.
Injected frames also ignore IEEE80211_TX_CTL_NO_ACK and use the default
hardware retry limit of 48. Unicast frames to an absent station then
take seconds each, which stalls all injection behind them.

Advertise the 6-bit retry limit of the TX descriptor, and on gen1 chips
program the retry limit of injected frames: none when no ACK is
expected, otherwise the radiotap retry count.

Tested on RTL8192CU (0bda:8178): 40 unicast frames at 1 Mbps to an
absent station drain in ~0.13 s with NOACK or 0 retries, ~0.45 s with
2, ~1.1 s with 4 and ~3.3 s with 6 retries. Without this patch the same
frames had not drained after 100 s, even with NOACK.

Signed-off-by: Ahmet Zeren <niko3x@proton.me>
---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c
index 969875fd54..b159d9b64c 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
@@ -5245,6 +5245,24 @@ static bool rtl8xxxu_tx_rate_inject(struct ieee80211_tx_info *tx_info,
 	return true;
 }
 
+/*
+ * Retry limit of an injected frame: none if no ACK is expected, else the
+ * radiotap retry count. -1 leaves it to the hardware.
+ */
+static int rtl8xxxu_tx_retry_inject(struct ieee80211_tx_info *tx_info)
+{
+	if (!(tx_info->flags & IEEE80211_TX_CTL_INJECTED))
+		return -1;
+
+	if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
+		return 0;
+
+	if (tx_info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
+		return tx_info->control.rates[0].count - 1;
+
+	return -1;
+}
+
 /*
  * Fill in v1 (gen1) specific TX descriptor bits.
  * This format is used on 8188cu/8192cu/8723au
@@ -5262,9 +5280,11 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 	u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
 	u32 rate = 0;
 	u16 seq_number;
+	int retries;
 	bool inject;
 
 	inject = rtl8xxxu_tx_rate_inject(tx_info, &rate, &sgi);
+	retries = rtl8xxxu_tx_retry_inject(tx_info);
 
 	if (rtl8xxxu_debug & RTL8XXXU_DEBUG_TX)
 		dev_info(dev, "%s: TX rate: %d, pkt size %u\n",
@@ -5314,6 +5334,12 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 		tx_desc->txdw4 |= cpu_to_le32(TXDESC32_USE_DRIVER_RATE |
 					      TXDESC_DISABLE_DATA_FB);
 
+	if (retries >= 0) {
+		tx_desc->txdw5 &= ~cpu_to_le32(TXDESC32_RETRY_LIMIT_MASK);
+		tx_desc->txdw5 |= cpu_to_le32(retries << TXDESC32_RETRY_LIMIT_SHIFT |
+					      TXDESC32_RETRY_LIMIT_ENABLE);
+	}
+
 	/*
 	 * rts_rate is zero if RTS/CTS or CTS to SELF are not enabled
 	 */
@@ -7979,6 +8005,8 @@ static int rtl8xxxu_probe(struct usb_interface *interface,
 	SET_IEEE80211_PERM_ADDR(hw, priv->mac_addr);
 
 	hw->extra_tx_headroom = priv->fops->tx_desc_size;
+	/* The TX descriptor retry limit is 6 bits wide */
+	hw->max_rate_tries = 64;
 	ieee80211_hw_set(hw, SIGNAL_DBM);
 
 	/*

-- 
2.56.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH rtw-next 3/3] wifi: rtl8xxxu: honour the bandwidth of injected frames on gen1 chips
  2026-11-19 22:09 [PATCH rtw-next 0/3] wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips Ahmet Zeren via B4 Relay
  2026-11-19 22:09 ` [PATCH rtw-next 2/3] wifi: rtl8xxxu: honour the retry count " Ahmet Zeren via B4 Relay
@ 2026-11-19 22:09 ` Ahmet Zeren via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Ahmet Zeren via B4 Relay @ 2026-11-19 22:09 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: linux-wireless, linux-kernel, Ping-Ke Shih, Ahmet Zeren

From: Ahmet Zeren <niko3x@proton.me>

Injected frames are always sent at 20 MHz, even when they ask for 40 MHz
on a 40 MHz channel, because only QoS data frames get the 40 MHz bits in
the TX descriptor.

Set them for injected frames with IEEE80211_TX_RC_40_MHZ_WIDTH.

Tested on RTL8192CU (0bda:8178) on channel 6 HT40+ and HT40-, received
by a second radio sniffing at 40 MHz: MCS 0 and 7 requested at 40 MHz
arrive at 40 MHz (without this patch: 20 MHz), requested at 20 MHz they
stay at 20 MHz.

Signed-off-by: Ahmet Zeren <niko3x@proton.me>
---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c b/drivers/net/wireless/realtek/rtl8xxxu/core.c
index b159d9b64c..2eef4585a8 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
@@ -5281,7 +5281,7 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 	u32 rate = 0;
 	u16 seq_number;
 	int retries;
-	bool inject;
+	bool inject, bw40;
 
 	inject = rtl8xxxu_tx_rate_inject(tx_info, &rate, &sgi);
 	retries = rtl8xxxu_tx_retry_inject(tx_info);
@@ -5311,17 +5311,22 @@ rtl8xxxu_fill_txdesc_v1(struct ieee80211_hw *hw, struct ieee80211_hdr *hdr,
 		tx_desc->txdw5 |= cpu_to_le32(TXDESC32_RETRY_LIMIT_ENABLE);
 	}
 
-	if (ieee80211_is_data_qos(hdr->frame_control)) {
+	if (ieee80211_is_data_qos(hdr->frame_control))
 		tx_desc->txdw4 |= cpu_to_le32(TXDESC32_QOS);
 
-		if (conf_is_ht40(&hw->conf)) {
-			tx_desc->txdw4 |= cpu_to_le32(TXDESC_DATA_BW);
+	if (inject)
+		bw40 = tx_info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH;
+	else
+		bw40 = ieee80211_is_data_qos(hdr->frame_control) &&
+		       conf_is_ht40(&hw->conf);
 
-			if (conf_is_ht40_minus(&hw->conf))
-				tx_desc->txdw4 |= cpu_to_le32(TXDESC_PRIME_CH_OFF_UPPER);
-			else
-				tx_desc->txdw4 |= cpu_to_le32(TXDESC_PRIME_CH_OFF_LOWER);
-		}
+	if (bw40) {
+		tx_desc->txdw4 |= cpu_to_le32(TXDESC_DATA_BW);
+
+		if (conf_is_ht40_minus(&hw->conf))
+			tx_desc->txdw4 |= cpu_to_le32(TXDESC_PRIME_CH_OFF_UPPER);
+		else
+			tx_desc->txdw4 |= cpu_to_le32(TXDESC_PRIME_CH_OFF_LOWER);
 	}
 
 	if (short_preamble)

-- 
2.56.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips
  2026-11-19 22:09 ` [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips Ahmet Zeren via B4 Relay
@ 2026-11-22  1:51   ` Ping-Ke Shih
  0 siblings, 0 replies; 5+ messages in thread
From: Ping-Ke Shih @ 2026-11-22  1:51 UTC (permalink / raw)
  To: niko3x, Jes Sorensen; +Cc: linux-wireless, linux-kernel

Ahmet Zeren via B4 Relay <devnull+niko3x.proton.me@kernel.org> wrote:
> From: Ahmet Zeren <niko3x@proton.me>
> 
> When a frame is injected with a rate in its radiotap header, the driver
> ignores it and leaves the choice to the firmware rate adaptation. On a
> RTL8192CU every injected frame went out at MCS 7, whatever was asked.
> 
> Use the injected rate and guard interval, and disable rate fallback so
> the frame is sent at exactly that rate.
> 
> Tested on RTL8192CU (0bda:8178) in monitor mode on 2.4 GHz: 1, 5.5, 6
> and 54 Mbps, MCS 0/7/8/15 with long and short GI were all received at
> the requested rate. Frames without a radiotap rate are unchanged.
> 
> Signed-off-by: Ahmet Zeren <niko3x@proton.me>

The comment is not unnecessary. Otherwise, looks good to me:

Reviewed-by: Ping-Ke Shih <pkshih@realtek.com>

> ---
>  drivers/net/wireless/realtek/rtl8xxxu/core.c | 29 ++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c
> b/drivers/net/wireless/realtek/rtl8xxxu/core.c
> index 604bb1e5b0..969875fd54 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
> @@ -5223,6 +5223,28 @@ static void rtl8xxxu_dump_action(struct device *dev,
>         }
>  }
> 
> +/*
> + * Use the rate from the radiotap header of an injected frame, if any.
> + * mac80211 has already checked it against what we advertise.
> + */

No need the comment. The code does as the comment.

> +static bool rtl8xxxu_tx_rate_inject(struct ieee80211_tx_info *tx_info,
> +                                   u32 *rate, bool *sgi)
> +{
> +       struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0];
> +
> +       if (!(tx_info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT))
> +               return false;
> +
> +       if (txrate->flags & IEEE80211_TX_RC_MCS)
> +               *rate = DESC_RATE_MCS0 + txrate->idx;
> +       else
> +               *rate = rtl8xxxu_legacy_ratetable[txrate->idx].hw_value;
> +
> +       *sgi = txrate->flags & IEEE80211_TX_RC_SHORT_GI;
> +
> +       return true;
> +}
> +



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-22  1:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 22:09 [PATCH rtw-next 0/3] wifi: rtl8xxxu: honour rate, retries and bandwidth of injected frames Ahmet Zeren via B4 Relay
2026-11-19 22:09 ` [PATCH rtw-next 1/3] wifi: rtl8xxxu: honour the rate of injected frames on gen1 chips Ahmet Zeren via B4 Relay
2026-11-22  1:51   ` Ping-Ke Shih
2026-11-19 22:09 ` [PATCH rtw-next 2/3] wifi: rtl8xxxu: honour the retry count " Ahmet Zeren via B4 Relay
2026-11-19 22:09 ` [PATCH rtw-next 3/3] wifi: rtl8xxxu: honour the bandwidth " Ahmet Zeren via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®