mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: Mehmet Fide <mehmet.fide@gmail.com>
Cc: Bitterblue Smith <rtl8821cerfe2@gmail.com>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mehmet.fide@screeningeagle.com" <mehmet.fide@screeningeagle.com>
Subject: RE: [PATCH rtw-next] wifi: rtw88: honour the transmit power mac80211 asks for
Date: Tue, 22 Sep 2026 01:56:44 +0000	[thread overview]
Message-ID: <dc09d252a96c4992ad18e2ba70cfad31@realtek.com> (raw)
In-Reply-To: <20260917141906.1361197-1-mehmet.fide@gmail.com>

Mehmet Fide <mehmet.fide@gmail.com> wrote:
> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
> 
> The per-rate power index is the by-rate value capped by the regulatory
> limit and the SAR limit; the level mac80211 hands over in conf.power_level
> is never looked at, so "iw phy <phy> set txpower fixed <mBm>" is accepted
> and silently ignored. Devices that share a small enclosure with their
> client, or that must back off for coexistence, have no way to run below
> the regulatory maximum.
> 
> Treat the requested level like the SAR limit: convert the dBm value to
> the by-rate offset domain with the chip's gain index granularity and use
> it as one more ceiling on the offset, then program the indices again
> whenever the level changes. The level is the total the device may
> radiate, so with two, three or four transmit paths each path gets 3, 5
> or 6 dB less, the way ath9k and the vendor driver share it. mac80211
> hands over the minimum of the regulatory maximum and the user's request,
> so a channel's maximum is respected as well; before the first
> configuration there is no request and nothing is capped, which keeps the
> behaviour of a driver that does not honour the level at all.
> 
> Tested on RTL8822BU (2T) and RTL8821CU (1T) in AP mode: "fixed 1000"
> moves every rate that sat above 10 dBm down to the 10 dBm index, less
> the 3 dB path share on the 8822BU, while the rates already below stay,
> "auto" restores the tables and the client stays associated through the
> changes; a second radio saw the beacons drop by the requested amount.

How did you measure the TX power decreasing as your expectation?

And, curiously, what is the purpose you added this? which application?

> 
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
> ---
>  drivers/net/wireless/realtek/rtw88/mac80211.c |  3 +++
>  drivers/net/wireless/realtek/rtw88/phy.c      | 26 +++++++++++++++++++
>  drivers/net/wireless/realtek/rtw88/phy.h      |  1 +

Miss to add pwr_param->pwr_user to rtw_debugfs_get_tx_pwr_tbl() to
show the correct final TX power and pwr_user factor.

>  3 files changed, 30 insertions(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c
> b/drivers/net/wireless/realtek/rtw88/mac80211.c
> index 2a9b09fa76e7..e0462e934438 100644
> --- a/drivers/net/wireless/realtek/rtw88/mac80211.c
> +++ b/drivers/net/wireless/realtek/rtw88/mac80211.c
> @@ -3,6 +3,7 @@
>   */
> 
>  #include "main.h"
> +#include "phy.h"
>  #include "sec.h"
>  #include "tx.h"
>  #include "fw.h"
> @@ -94,6 +95,8 @@ static int rtw_ops_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)
> 
>         if (changed & IEEE80211_CONF_CHANGE_CHANNEL)
>                 rtw_set_channel(rtwdev);
> +       else if (changed & IEEE80211_CONF_CHANGE_POWER)

Should it be 'if' instead of 'else if'?

> +               rtw_phy_set_tx_power_level(rtwdev, rtwdev->hal.current_channel);
> 
>         if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
>             (hw->conf.flags & IEEE80211_CONF_IDLE) &&
> diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
> index e2ac5c6fd500..0dfcd0739423 100644
> --- a/drivers/net/wireless/realtek/rtw88/phy.c
> +++ b/drivers/net/wireless/realtek/rtw88/phy.c
> @@ -2236,6 +2236,29 @@ static s8 rtw_phy_get_tx_power_sar(struct rtw_dev *rtwdev, u8 sar_band,
>         return (s8)rtwdev->chip->max_power_index;
>  }
> 
> +static s8 rtw_phy_get_tx_power_user(struct rtw_dev *rtwdev, u8 band, u8 path,
> +                                   u8 rate)
> +{
> +       struct rtw_hal *hal = &rtwdev->hal;
> +       const struct rtw_chip_info *chip = rtwdev->chip;
> +       static const u8 path_share_dbm[] = { 0, 0, 3, 5, 6 };
> +       int power_level = rtwdev->hw->conf.power_level;
> +       u8 rs = rtw_phy_rate_to_rate_section(rate);
> +       u8 paths = clamp_t(u8, hweight8(hal->antenna_tx), 1, 4);

In reverse X'mas tree order.

> +       s32 idx;
> +       s8 base;
> +
> +       if (power_level <= 0 || rs == RTW_RATE_SECTION_NUM)
> +               return (s8)chip->max_power_index;
> +
> +       idx = (power_level - path_share_dbm[paths]) << chip->txgi_factor;
> +       base = band == PHY_BAND_2G ? hal->tx_pwr_by_rate_base_2g[path][rs] :
> +                                    hal->tx_pwr_by_rate_base_5g[path][rs];
> +
> +       return (s8)clamp_t(s32, idx, -chip->max_power_index - 1,
> +                          chip->max_power_index) - base;

Should it clamp after 'idx - base' ?

> +}
> +
>  void rtw_get_tx_power_params(struct rtw_dev *rtwdev, u8 path, u8 rate, u8 bw,
>                              u8 ch, u8 regd, struct rtw_power_params *pwr_param)
>  {




  reply	other threads:[~2026-09-22  1:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 14:19 Mehmet Fide
2026-09-22  1:56 ` Ping-Ke Shih [this message]
2026-09-22  6:26   ` Mehmet Fide
2026-09-22  6:48     ` Ping-Ke Shih
2026-09-22  6:59       ` Mehmet Fide

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=dc09d252a96c4992ad18e2ba70cfad31@realtek.com \
    --to=pkshih@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mehmet.fide@gmail.com \
    --cc=mehmet.fide@screeningeagle.com \
    --cc=rtl8821cerfe2@gmail.com \
    /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®