* [PATCH wireless] wifi: b43: keep the N-PHY TX power control from drifting while idle
@ 2026-10-17 0:51 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-10-17 0:51 UTC (permalink / raw)
To: linux-wireless
Cc: Rafał Miłecki, John W. Linville,
open list:B43 WIRELESS DRIVER, open list
On N-PHY rev 3 and later, the hardware TX power control moves the base
gain index of each core according to the power it estimates for the
frames sent. CCK frames do not update the estimate, but the loop keeps
stepping on them with the last one. An access point with no traffic
only sends CCK beacons, and when the last estimate is below the target,
each beacon adds gain.
On an ASUS RT-N16 (N-PHY rev 5, external PAs), both cores sit at base
index 76-79 while OFDM frames go out, and walk down to index 0, maximum
gain, within 20 s (core 2) and 60 s (core 1) after traffic stops, with
the estimates frozen at 71 and 73 against a target of 74. The OFDM
frames sent after that overdrive the PAs, so the higher rates fail
until the loop has caught up: after 45 s of idle, only 2 of 8 pings
to an 802.11g station got through.
Remember the base indices while OFDM frames are being sent, and when
sending starts again after half a second without, load them back
through the base index register. The loaded value only takes while the
load bit is set as frames go out, so keep it set until OFDM frames have
been sent for a while. Until then, the base indices stay where they
were loaded instead of drifting. Forget the indices when the power
control is set up again or the channel changes.
With this, the base indices stay at 75-79 over idle periods, and all
pings after them get through. Throughput is unchanged.
Fixes: c7d643103508 ("b43: N-PHY: determine various PHY params")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/wireless/broadcom/b43/main.c | 20 +++++++
drivers/net/wireless/broadcom/b43/phy_n.c | 64 +++++++++++++++++++++++
drivers/net/wireless/broadcom/b43/phy_n.h | 12 +++++
3 files changed, 96 insertions(+)
diff --git a/drivers/net/wireless/broadcom/b43/main.c b/drivers/net/wireless/broadcom/b43/main.c
index 3825b6ad9f4f..a205db22a07d 100644
--- a/drivers/net/wireless/broadcom/b43/main.c
+++ b/drivers/net/wireless/broadcom/b43/main.c
@@ -3589,11 +3589,27 @@ static int b43_rng_init(struct b43_wl *wl)
return err;
}
+/* Whether an N-PHY device sends @skb with OFDM or HT modulation */
+static bool b43_tx_is_ofdm(struct b43_wldev *dev, struct sk_buff *skb)
+{
+ struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+ const struct ieee80211_rate *rate;
+
+ if (dev->phy.type != B43_PHYTYPE_N)
+ return false;
+ if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
+ return true;
+ rate = ieee80211_get_tx_rate(dev->wl->hw, info);
+
+ return rate && b43_is_ofdm_rate(rate->hw_value);
+}
+
static void b43_tx_work(struct work_struct *work)
{
struct b43_wl *wl = container_of(work, struct b43_wl, tx_work);
struct b43_wldev *dev;
struct sk_buff *skb;
+ bool ofdm_seen = false;
int queue_num;
int err = 0;
@@ -3607,6 +3623,10 @@ static void b43_tx_work(struct work_struct *work)
for (queue_num = 0; queue_num < B43_QOS_QUEUE_NUM; queue_num++) {
while (skb_queue_len(&wl->tx_queue[queue_num])) {
skb = skb_dequeue(&wl->tx_queue[queue_num]);
+ if (!ofdm_seen && b43_tx_is_ofdm(dev, skb)) {
+ b43_nphy_txpctl_ofdm_tx(dev);
+ ofdm_seen = true;
+ }
if (b43_using_pio_transfers(dev))
err = b43_pio_tx(dev, skb);
else
diff --git a/drivers/net/wireless/broadcom/b43/phy_n.c b/drivers/net/wireless/broadcom/b43/phy_n.c
index 22359bd9db47..b5fca1d20bfb 100644
--- a/drivers/net/wireless/broadcom/b43/phy_n.c
+++ b/drivers/net/wireless/broadcom/b43/phy_n.c
@@ -3605,6 +3605,11 @@ static void b43_nphy_tx_power_ctrl(struct b43_wldev *dev, bool enable)
b43_nphy_stay_in_carrier_search(dev, 1);
nphy->txpwrctrl = enable;
+ nphy->txpctl_bidx_valid = false;
+ if (nphy->txpctl_bidx_loaded) {
+ b43_phy_write(dev, B43_NPHY_TXPCTL_BIDX, 0);
+ nphy->txpctl_bidx_loaded = false;
+ }
if (!enable) {
if (dev->phy.rev >= 3 &&
(b43_phy_read(dev, B43_NPHY_TXPCTL_CMD) &
@@ -6326,6 +6331,60 @@ static void b43_nphy_channel_setup(struct b43_wldev *dev,
b43_nphy_spur_workaround(dev);
}
+/*
+ * Called before OFDM or HT frames are queued for transmission.
+ *
+ * The hardware TX power control adjusts the base index of each core with
+ * the power it estimates for transmitted frames. CCK frames do not update
+ * the estimate, but the loop still steps on them with the last one. Once
+ * an AP has only beacons to send, that drives the base index all the way
+ * to maximum gain, within 20-60 s on an ASUS RT-N16, and the first OFDM
+ * frames after that compress the external PA: 16-QAM and 64-QAM fail
+ * until the loop has caught up again.
+ *
+ * Remember the base indices while OFDM frames are being sent, and load
+ * them back when sending starts again after a pause. The base indices
+ * only take the loaded values while the load bit is set as frames go
+ * out, so it stays set until frames have been sent for a while. Until
+ * then, the base indices stay where they were loaded.
+ */
+void b43_nphy_txpctl_ofdm_tx(struct b43_wldev *dev)
+{
+ struct b43_phy_n *nphy = dev->phy.n;
+ unsigned long now = jiffies;
+ u16 c1, c2;
+
+ if (dev->phy.rev < 3 || !nphy->txpwrctrl)
+ return;
+
+ if (nphy->txpctl_bidx_valid &&
+ time_after(now, nphy->txpctl_last_tx + HZ / 2)) {
+ b43_phy_write(dev, B43_NPHY_TXPCTL_BIDX,
+ B43_NPHY_TXPCTL_BIDX_LOAD | nphy->txpctl_bidx);
+ nphy->txpctl_bidx_loaded = true;
+ nphy->txpctl_last_sample = now;
+ } else if (nphy->txpctl_bidx_loaded) {
+ if (time_after(now, nphy->txpctl_last_sample + HZ / 50)) {
+ b43_phy_write(dev, B43_NPHY_TXPCTL_BIDX,
+ nphy->txpctl_bidx);
+ nphy->txpctl_bidx_loaded = false;
+ nphy->txpctl_last_sample = now;
+ }
+ } else if (time_before(now, nphy->txpctl_last_tx + HZ / 20) &&
+ (!nphy->txpctl_bidx_valid ||
+ time_after(now, nphy->txpctl_last_sample + HZ / 5))) {
+ c1 = b43_phy_read(dev, B43_NPHY_C1_TXPCTL_STAT);
+ c2 = b43_phy_read(dev, B43_NPHY_C2_TXPCTL_STAT);
+ nphy->txpctl_bidx = (c1 & B43_NPHY_TXPCTL_STAT_BIDX) >>
+ B43_NPHY_TXPCTL_STAT_BIDX_SHIFT;
+ nphy->txpctl_bidx |= c2 & B43_NPHY_TXPCTL_STAT_BIDX;
+ nphy->txpctl_bidx_valid = true;
+ nphy->txpctl_last_sample = now;
+ }
+
+ nphy->txpctl_last_tx = now;
+}
+
/* https://bcm-v4.sipsolutions.net/802.11/PHY/N/SetChanspec */
static int b43_nphy_set_channel(struct b43_wldev *dev,
struct ieee80211_channel *channel,
@@ -6363,6 +6422,11 @@ static int b43_nphy_set_channel(struct b43_wldev *dev,
/* Channel is set later in common code, but we need to set it on our
own to let this function's subcalls work properly. */
phy->channel = channel->hw_value;
+ dev->phy.n->txpctl_bidx_valid = false;
+ if (dev->phy.n->txpctl_bidx_loaded) {
+ b43_phy_write(dev, B43_NPHY_TXPCTL_BIDX, 0);
+ dev->phy.n->txpctl_bidx_loaded = false;
+ }
#if 0
if (b43_channel_type_is_40mhz(phy->channel_type) !=
diff --git a/drivers/net/wireless/broadcom/b43/phy_n.h b/drivers/net/wireless/broadcom/b43/phy_n.h
index b96ded0ef539..787ad3e9b5ac 100644
--- a/drivers/net/wireless/broadcom/b43/phy_n.h
+++ b/drivers/net/wireless/broadcom/b43/phy_n.h
@@ -973,6 +973,16 @@ struct b43_phy_n {
u16 tx_pwr_last_recalc_freq;
int tx_pwr_last_recalc_limit;
+ /*
+ * Base indices of the hardware TX power control while OFDM frames
+ * were sent, to restore them when sending starts again after idle.
+ */
+ bool txpctl_bidx_valid;
+ bool txpctl_bidx_loaded;
+ u16 txpctl_bidx;
+ unsigned long txpctl_last_tx;
+ unsigned long txpctl_last_sample;
+
u8 txrx_chain;
u16 tx_rx_cal_phy_saveregs[11];
u16 tx_rx_cal_radio_saveregs[22];
@@ -1005,4 +1015,6 @@ struct b43_phy_n {
struct b43_phy_operations;
extern const struct b43_phy_operations b43_phyops_n;
+void b43_nphy_txpctl_ofdm_tx(struct b43_wldev *dev);
+
#endif /* B43_NPHY_H_ */
--
2.56.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-17 0:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-17 0:51 [PATCH wireless] wifi: b43: keep the N-PHY TX power control from drifting while idle Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox