git: 999377a66d2e - stable/13 - LinuxKPI: 802.11 simplify beacon checks in rx path

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 20 Feb 2022 18:15:55 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=999377a66d2e21460fc156dd35708d4315fe901b

commit 999377a66d2e21460fc156dd35708d4315fe901b
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-02-17 00:58:12 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-02-20 16:26:06 +0000

    LinuxKPI: 802.11 simplify beacon checks in rx path
    
    In linuxkpi_ieee80211_rx() check if the frame is a beacon once upfront
    and use the result for enhanced debugging and further checks.
    This was done intially for rx_status->device_timestamp debugging.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit c0cadd99d1e36ffe0994f8b30df2939f1d3d0fee)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index b5fde7e10781..2fe8b4ebddd0 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -3165,6 +3165,7 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct ieee80211_hdr *hdr;
 	struct lkpi_sta *lsta;
 	int i, offset, ok, type;
+	bool is_beacon;
 
 	if (skb->len < 2) {
 		/* Need 80211 stats here. */
@@ -3192,19 +3193,20 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 
 	rx_status = IEEE80211_SKB_RXCB(skb);
 
-#ifdef LINUXKPI_DEBUG_80211
 	hdr = (void *)skb->data;
-	if ((debug_80211 & D80211_TRACE_RX_BEACONS) == 0 &&
-	    ieee80211_is_beacon(hdr->frame_control))
+	is_beacon = ieee80211_is_beacon(hdr->frame_control);
+
+#ifdef LINUXKPI_DEBUG_80211
+	if (is_beacon && (debug_80211 & D80211_TRACE_RX_BEACONS) == 0)
 		goto no_trace_beacons;
 
 	if (debug_80211 & D80211_TRACE_RX)
 		printf("TRACE-RX: %s: skb %p a/l/d/t-len (%u/%u/%u/%u) "
-		    "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u\n",
+		    "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n",
 		    __func__, skb, skb->_alloc_len, skb->len, skb->data_len,
 		    skb->truesize, skb->head, skb->data, skb->tail, skb->end,
 		    shinfo, shinfo->nr_frags,
-		    m, m->m_pkthdr.len, m->m_len);
+		    m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : "");
 
 	if (debug_80211 & D80211_TRACE_RX_DUMP)
 		hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0);
@@ -3288,10 +3290,11 @@ no_trace_beacons:
 		vap = TAILQ_FIRST(&ic->ic_vaps);
 
 	if (debug_80211 & D80211_TRACE_RX)
-		printf("TRACE %s: sta %p lsta %p ni %p vap %p\n", __func__, sta, lsta, ni, vap);
+		printf("TRACE %s: sta %p lsta %p state %d ni %p vap %p%s\n",
+		    __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1,
+		    ni, vap, is_beacon ? " beacon" : "");
 
-	if (ni != NULL && vap != NULL &&
-	    ieee80211_is_beacon(hdr->frame_control) &&
+	if (ni != NULL && vap != NULL && is_beacon &&
 	    rx_status->device_timestamp > 0 &&
 	    m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) {
 		struct lkpi_vif *lvif;