Linux wireless drivers development
 help / color / mirror / Atom feed
From: Kordian Chmielewski <kudzo51@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: Arend van Spriel <arend.vanspriel@broadcom.com>,
	brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH wireless-next v2] wifi: brcmfmac: delete the flowrings of an AP that stops or goes down
Date: Mon, 16 Nov 2026 13:49:35 +0100	[thread overview]
Message-ID: <20261116124935.685189-1-kudzo51@gmail.com> (raw)

An access point has a flowring for each station and access category,
and one for its broadcast and multicast frames. The rings of a station
are deleted when it leaves, by brcmf_proto_delete_peer() with its
address. Stopping the AP deletes none of them, and neither does a
link-down event: delete_peer then gets the address of the event, which
names no station; on a BCM43684 it is the BSSID of the AP. When the
interface is started again as an AP, it keeps the old broadcast ring.

Seen with a BCM43684 whose AP was stopped and started again at boot:
the firmware no longer read the broadcast ring in use when the first
start ended. The broadcasts of that BSS, ARP included, stayed in the
ring, and once it was full flow control stopped the interface for all
of its stations, until the ring was deleted hours later by a change of
the interface type; the firmware then served new rings normally. The
vendor driver deletes all the rings of an interface on a link-down
event.

Do the same, and delete them in brcmf_cfg80211_stop_ap() after
BRCMF_C_DOWN: brcmf_flowring_delete_peer() without a peer now deletes
every ring of the interface.

Fixes: 9a1bb60250d2 ("brcmfmac: Adding msgbuf protocol.")
Signed-off-by: Kordian Chmielewski <kudzo51@gmail.com>
---

Notes:
    v2:
    - the call in brcmf_cfg80211_stop_ap() now comes after BRCMF_C_DOWN,
      in both branches (Arend): before it, a broadcast could open a new
      ring between the delete and BRCMF_C_DOWN
    - commit message: rings per station and access category, what the
      address of the link-down event names, and the restart at boot
      without a guess at its cause
    v1: https://lore.kernel.org/all/20261110231145.206744-1-kudzo51@gmail.com/
    
    Arend, you suggested this or dropping the call and relying on the
    link-down event. I kept the call so that the stop does not depend on
    the event: on my BCM43684 it comes with reason 4 (BSS disabled),
    possibly from the empty SET_SSID rather than from BRCMF_C_DOWN, and
    the mbss branch sends only BRCMF_C_DOWN.
    
    The mainline driver does not run my BCM43684 (it needs the BCA host
    interface, about 60 patches that are not upstream), so this patch is
    compile-tested only. In my tree, with the variants behind module
    parameters, I stopped and started a BCM43684 access point 45 times
    with hostapd_cli disable and enable while 500 or 2000 broadcasts a
    second went to it:
    - without the patch the broadcast ring outlived the stop (7 of 7), and
      after the first restart in each of the 3 runs without the patch the
      firmware did not read it again: the ring stayed full and its read
      pointer did not move
    - stopping the AP brought a link-down event (reason 4, BSS disabled)
      at every stop, before the carrier went off; its address was the
      BSSID at each of the 25 stops where I logged it
    - with the call before BRCMF_C_DOWN, as in v1, a broadcast asked for a
      new ring before BRCMF_C_DOWN at 2 of 5 stops; in one of them the
      ring opened, and only the link-down event deleted it
    - after BRCMF_C_DOWN no ring opened: the firmware refused all 29 it
      answered in that time
    - with the call after BRCMF_C_DOWN no ring was left (17 stops), also
      with the link-down handling turned off, and the firmware read the
      new broadcast ring after each of the 10 starts where I checked
    - my tree has a lock around the ring table and mainline has none;
      there brcmf_msgbuf_delete_flowring() marks the ring RING_CLOSING
      before it waits, so the second caller normally skips it, but the
      check and the mark are not atomic and the table is read without a
      lock, as for any delete_peer call today
    - the mbss branch and a P2P GO were not tested: my tree takes down an
      extra BSS with the "bss" iovar
    - the vendor driver also opens no new ring while the link of the
      interface is down; this patch does not, and in my test the firmware
      refused such rings itself
    - under that load the delete of the broadcast ring timed out waiting
      for tx status 20 times out of 35; in mainline that leaves the tx
      status counter of the ring wrong, which "msgbuf: count tx status
      only for the current flowring" fixes:
      https://lore.kernel.org/all/20261112175754.396469-1-kudzo51@gmail.com/

 .../broadcom/brcm80211/brcmfmac/cfg80211.c        | 15 ++++++++++++++-
 .../broadcom/brcm80211/brcmfmac/flowring.c        |  5 +++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index b0eaf9641..d5b0a0770 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -5492,6 +5492,8 @@ static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev,
 
 		if (ifp->vif->mbss) {
 			err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
+			/* the BSS goes away, and so do all of its rings */
+			brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, NULL);
 			return err;
 		}
 
@@ -5507,6 +5509,10 @@ static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev,
 		err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
 		if (err < 0)
 			bphy_err(drvr, "BRCMF_C_DOWN error %d\n", err);
+		/* the BSS goes away, and so do all of its rings: no station
+		 * deletes the one for broadcast and multicast frames
+		 */
+		brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, NULL);
 		err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
 		if (err < 0)
 			bphy_err(drvr, "setting AP mode failed %d\n", err);
@@ -6750,7 +6756,14 @@ brcmf_notify_connect_status(struct brcmf_if *ifp,
 	    (e->event_code == BRCMF_E_DEAUTH_IND) ||
 	    (e->event_code == BRCMF_E_DISASSOC_IND) ||
 	    ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
-		brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
+		/* the address of a link event of an AP names no station:
+		 * the BSS is down, and so are all of its rings
+		 */
+		if (e->event_code == BRCMF_E_LINK && brcmf_is_apmode(ifp->vif))
+			brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, NULL);
+		else
+			brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx,
+						(u8 *)e->addr);
 	}
 
 	if (brcmf_is_apmode(ifp->vif)) {
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
index 35cbcea0a..b9570d638 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
@@ -432,9 +432,10 @@ void brcmf_flowring_delete_peer(struct brcmf_flowring *flow, int ifidx,
 	u16 flowid;
 	bool sta;
 
-	sta = (flow->addr_mode[ifidx] == ADDR_INDIRECT);
+	/* without a peer: every ring of the interface */
+	sta = (flow->addr_mode[ifidx] == ADDR_INDIRECT) || !peer;
 
-	search = flow->tdls_entry;
+	search = peer ? flow->tdls_entry : NULL;
 	prev = NULL;
 	while (search) {
 		if (memcmp(search->mac, peer, ETH_ALEN) == 0) {

base-commit: 5dbf2415ca9821a611d09308e3b29d2c37e7cd77
-- 
2.56.1


                 reply	other threads:[~2026-11-16 12:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261116124935.685189-1-kudzo51@gmail.com \
    --to=kudzo51@gmail.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=brcm80211@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /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