mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: "niko3x@proton.me" <niko3x@proton.me>,
	Jes Sorensen <Jes.Sorensen@gmail.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH rtw-next 2/2] wifi: rtl8xxxu: report real TX status on RTL8188CU/RTL8192CU
Date: Sun, 22 Nov 2026 02:58:54 +0000	[thread overview]
Message-ID: <87a031c8ede14efd9c83bc8206fd2aac@realtek.com> (raw)
In-Reply-To: <20261120-b4-tx-status-v1-2-abdab21c77fe@proton.me>

Ahmet Zeren via B4 Relay <devnull+niko3x.proton.me@kernel.org> wrote:

[...]

> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/8192c.c
> b/drivers/net/wireless/realtek/rtl8xxxu/8192c.c
> index 508322a8f3..401cc1f6da 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/8192c.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/8192c.c
> @@ -726,6 +726,7 @@ struct rtl8xxxu_fileops rtl8192cu_fops = {

move .has_c2hevt_tx_report here to be almost the same order as
definition in struct rtl8xxxu_fileops.

>         .hw_feature_report = 0,
>         .max_macid_num = 32,
>         .max_sec_cam_num = 32,
> +       .has_c2hevt_tx_report = 1,
>         .adda_1t_init = 0x0b1b25a0,
>         .adda_1t_path_on = 0x0bdb25a0,
>         .adda_2t_path_on_a = 0x04db25a4,
> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/core.c
> b/drivers/net/wireless/realtek/rtl8xxxu/core.c
> index ab2818986c..36f0a266af 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/core.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/core.c
> @@ -5148,6 +5148,105 @@ static void rtl8xxxu_free_tx_urb(struct rtl8xxxu_priv *priv,
>         spin_unlock_irqrestore(&priv->tx_urb_lock, flags);
>  }
> 
> +/*
> + * Gen1 chips can report the ACK status of a frame through the C2H event
> + * mailbox. There is no way to tell which frame a report belongs to, so
> + * only one frame at a time asks for one, until its report arrives. The
> + * report comes when the frame is done, which can take seconds with many
> + * retries, so wait for it rather than risk taking it for the next frame.
> + */
> +#define RTL8XXXU_TX_REPORT_TIMEOUT     msecs_to_jiffies(10000)
> +
> +static bool rtl8xxxu_tx_report_claim(struct rtl8xxxu_priv *priv,
> +                                    struct sk_buff *skb)
> +{
> +       struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
> +       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
> +       unsigned long flags;
> +       bool claimed = false;

In reverse X'mas order.

> +
> +       if (!priv->fops->has_c2hevt_tx_report ||
> +           !(tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) ||
> +           (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ||
> +           is_multicast_ether_addr(hdr->addr1))
> +               return false;
> +
> +       spin_lock_irqsave(&priv->tx_report_lock, flags);
> +       if (!priv->tx_report_skb) {
> +               priv->tx_report_skb = skb;
> +               claimed = true;
> +       }
> +       spin_unlock_irqrestore(&priv->tx_report_lock, flags);
> +
> +       return claimed;
> +}
> +
> +static bool rtl8xxxu_tx_report_release(struct rtl8xxxu_priv *priv,
> +                                      struct sk_buff *skb)
> +{
> +       unsigned long flags;
> +       bool claimed;
> +
> +       spin_lock_irqsave(&priv->tx_report_lock, flags);
> +       claimed = priv->tx_report_skb == skb;
> +       if (claimed)
> +               priv->tx_report_skb = NULL;
> +       spin_unlock_irqrestore(&priv->tx_report_lock, flags);
> +
> +       return claimed;
> +}
> +
> +static void rtl8xxxu_tx_report_work(struct work_struct *work)

I'd point out this is a polling work. How about naming rtl8xxxu_tx_report_poll_work()? 

> +{
> +       struct rtl8xxxu_priv *priv = container_of(work, struct rtl8xxxu_priv,
> +                                                 tx_report_work.work);
> +       struct ieee80211_tx_info *tx_info;
> +       unsigned long flags, elapsed;
> +       u8 retry = 0, status = 0;
> +       bool reported = false;
> +       struct sk_buff *skb;
> +
> +       if (rtl8xxxu_read8(priv, REG_C2HEVT_CLEAR) == C2H_EVT_FW_CLOSE) {
> +               u8 id = rtl8xxxu_read8(priv, REG_C2HEVT_MSG_NORMAL);
> +
> +               if ((id & C2H_EVT_ID_MASK) == C2H_EVT_CCX_TX_RPT) {
> +                       retry = rtl8xxxu_read8(priv, REG_C2HEVT_MSG_NORMAL + 2 +
> +                                                    CCX_TX_RPT_RETRY);
> +                       status = rtl8xxxu_read8(priv, REG_C2HEVT_MSG_NORMAL + 2 +
> +                                                     CCX_TX_RPT_STATUS);
> +                       reported = true;
> +               }
> +               rtl8xxxu_write8(priv, REG_C2HEVT_CLEAR, C2H_EVT_HOST_CLOSE);
> +       }
> +
> +       elapsed = jiffies - priv->tx_report_start;
> +       if (!reported && elapsed < RTL8XXXU_TX_REPORT_TIMEOUT) {
> +               /* Most frames are done within a few ms, poll often at first */
> +               ieee80211_queue_delayed_work(priv->hw, &priv->tx_report_work,
> +                                            elapsed < msecs_to_jiffies(20) ?
> +                                            1 : msecs_to_jiffies(10));
> +               return;
> +       }
> +
> +       spin_lock_irqsave(&priv->tx_report_lock, flags);
> +       skb = priv->tx_report_skb;
> +       priv->tx_report_skb = NULL;
> +       spin_unlock_irqrestore(&priv->tx_report_lock, flags);
> +
> +       if (!skb)
> +               return;
> +
> +       tx_info = IEEE80211_SKB_CB(skb);
> +       ieee80211_tx_info_clear_status(tx_info);
> +       if (!(tx_info->flags & IEEE80211_TX_CTL_INJECTED))
> +               tx_info->status.rates[0].idx = -1;
> +       tx_info->status.rates[0].count = (retry & CCX_TX_RPT_RETRY_CNT) + 1;
> +       if (status & CCX_TX_RPT_PKT_OK)
> +               tx_info->flags |= IEEE80211_TX_STAT_ACK;
> +
> +       ieee80211_tx_status_irqsafe(priv->hw, skb);
> +}
> +
>  static void rtl8xxxu_tx_complete(struct urb *urb)
>  {
>         struct sk_buff *skb = (struct sk_buff *)urb->context;

[...]

> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> index 8cbadcf719..387ffdc970 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
> @@ -1546,6 +1546,17 @@ enum c2h_evt_8723b {
>         C2H_8723B_FW_DEBUG = 0xff,
>  };
> 
> +/* Gen1 C2H events are read from the REG_C2HEVT_MSG_NORMAL mailbox */
> +#define C2H_EVT_HOST_CLOSE             0x00
> +#define C2H_EVT_FW_CLOSE               0xff

move these together with REG_C2HEVT_CLEAR

> +#define C2H_EVT_ID_MASK                        GENMASK(3, 0)
> +#define C2H_EVT_CCX_TX_RPT             3

move these together with REG_C2HEVT_MSG_NORMAL

> +/* Offsets in the CCX TX report payload, after the 2 byte event header */

Add a definition for 2 bytes?

> +#define CCX_TX_RPT_RETRY               0
> +#define  CCX_TX_RPT_RETRY_CNT          GENMASK(5, 0)
> +#define CCX_TX_RPT_STATUS              7
> +#define  CCX_TX_RPT_PKT_OK             BIT(6)

With hierarchy:

#define REG_C2HEVT_MSG_NORMAL		0x01a0
#define  C2H_EVT_ID_MASK			GENMASK(3, 0)
#define   C2H_EVT_CCX_TX_RPT		3
// the modified naming is still not good. Actually it is offset from 0x01a0
#define  C2HEVT_MSG_CCX_TX_RPT_RETRY		0
// the modified naming is also not good. Can you think of it a bit?
#define   CCX_TX_RPT_RETRY_CNT_MASK		GENMASK(5, 0)

> +
>  enum bt_info_src_8723b {
>         BT_INFO_SRC_8723B_WIFI_FW = 0x0,
>          BT_INFO_SRC_8723B_BT_RSP = 0x1,
> @@ -1919,6 +1930,11 @@ struct rtl8xxxu_priv {
>         struct work_struct c2hcmd_work;
>         struct sk_buff_head c2hcmd_queue;
>         struct delayed_work update_beacon_work;
> +       /* Frame waiting for its TX report in the C2H event mailbox */
> +       struct sk_buff *tx_report_skb;
> +       spinlock_t tx_report_lock; /* protects tx_report_skb */
> +       struct delayed_work tx_report_work;
> +       unsigned long tx_report_start;

Put in a small group like spinlock_t tx_urb_lock/rx_urb_lock.

>         struct rtl8xxxu_btcoex bt_coex;
>         struct rtl8xxxu_ra_report ra_report;
>         struct rtl8xxxu_cfo_tracking cfo_tracking;
> @@ -2009,6 +2025,7 @@ struct rtl8xxxu_fileops {
>         char rx_desc_size;
>         u8 has_s0s1:1;
>         u8 has_tx_report:1;
> +       u8 has_c2hevt_tx_report:1;
>         u8 gen2_thermal_meter:1;
>         u8 needs_full_init:1;
>         u8 init_reg_rxfltmap:1;
> 
> --
> 2.56.1
> 

pw-bot: cr



      reply	other threads:[~2026-11-22  2:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 22:12 [PATCH rtw-next 0/2] " Ahmet Zeren via B4 Relay
2026-11-19 22:12 ` [PATCH rtw-next 1/2] wifi: rtl8xxxu: don't report frames sent without ACK as acked Ahmet Zeren via B4 Relay
2026-11-22  2:15   ` Ping-Ke Shih
2026-11-19 22:12 ` [PATCH rtw-next 2/2] wifi: rtl8xxxu: report real TX status on RTL8188CU/RTL8192CU Ahmet Zeren via B4 Relay
2026-11-22  2:58   ` Ping-Ke Shih [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a031c8ede14efd9c83bc8206fd2aac@realtek.com \
    --to=pkshih@realtek.com \
    --cc=Jes.Sorensen@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=niko3x@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®