git: e269958566ff - stable/13 - LinuxKPI: 802.11: cleanup debugging

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 27 Mar 2022 20:14:17 UTC
The branch stable/13 has been updated by bz:

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

commit e269958566ff0df8d479996507636ed14ff6078a
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-03-24 19:09:04 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-03-27 18:13:00 +0000

    LinuxKPI: 802.11: cleanup debugging
    
    Cleanup some debugging.  Rename the global variable to be less
    generic.  Hide all debugging behind #ifdef for now and turn off.
    Rename the debugging sysctl so we can start adding more to the
    subtree.
    
    There is a need to change that wildly grown infrastructure into
    something more homogenic soon but this should do for 13.1.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 9d9ba2b79b3196935431879efd9094eb9bfedd95)
---
 .../linuxkpi/common/include/linux/ieee80211.h      |   8 +-
 sys/compat/linuxkpi/common/include/net/cfg80211.h  |   6 +-
 sys/compat/linuxkpi/common/src/linux_80211.c       | 125 ++++++++++++++-------
 3 files changed, 88 insertions(+), 51 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/ieee80211.h b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
index 55e31a7a88ae..e0aa558fe273 100644
--- a/sys/compat/linuxkpi/common/include/linux/ieee80211.h
+++ b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
@@ -38,9 +38,6 @@
 #include <linux/bitops.h>
 #include <linux/if_ether.h>
 
-/* linux_80211.c */
-extern int debug_80211;
-
 
 /* 9.4.2.55 Management MIC element (CMAC-256, GMAC-128, and GMAC-256). */
 struct ieee80211_mmie_16 {
@@ -544,9 +541,8 @@ ieee80211_hdrlen(__le16 fc)
 
 	if (ieee80211_is_mgmt(fc)) {
 #ifdef __notyet__
-		if (debug_80211 > 0)
-			printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
-			    __func__, fc, size);
+		printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
+		    __func__, fc, size);
 #endif
 		;
 	}
diff --git a/sys/compat/linuxkpi/common/include/net/cfg80211.h b/sys/compat/linuxkpi/common/include/net/cfg80211.h
index 64aef659c771..29fe65395385 100644
--- a/sys/compat/linuxkpi/common/include/net/cfg80211.h
+++ b/sys/compat/linuxkpi/common/include/net/cfg80211.h
@@ -44,16 +44,16 @@
 #include <net/regulatory.h>
 
 /* linux_80211.c */
-extern int debug_80211;
+extern int linuxkpi_debug_80211;
 #ifndef	D80211_TODO
 #define	D80211_TODO		0x1
 #endif
 #ifndef	D80211_IMPROVE
 #define	D80211_IMPROVE		0x2
 #endif
-#define	TODO()		if (debug_80211 & D80211_TODO)			\
+#define	TODO()		if (linuxkpi_debug_80211 & D80211_TODO)		\
     printf("%s:%d: XXX LKPI80211 TODO\n", __func__, __LINE__)
-#define	IMPROVE(...)	if (debug_80211 & D80211_IMPROVE)		\
+#define	IMPROVE(...)	if (linuxkpi_debug_80211 & D80211_IMPROVE)	\
     printf("%s:%d: XXX LKPI80211 IMPROVE\n", __func__, __LINE__)
 
 enum rfkill_hard_block_reasons {
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 384d068d7920..3a70d8bbfcab 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -70,16 +70,21 @@ __FBSDID("$FreeBSD$");
 #include <linux/workqueue.h>
 #include "linux_80211.h"
 
-static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "Linux KPI 80211 compat");
+static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat");
 
 /* -------------------------------------------------------------------------- */
 
-int debug_80211;
-SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_80211, CTLFLAG_RWTUN,
-    &debug_80211, 0, "80211 debug Level");
+/* Keep public for as long as header files are using it too. */
+int linuxkpi_debug_80211;
 
-#define LINUXKPI_DEBUG_80211
 #ifdef LINUXKPI_DEBUG_80211
+SYSCTL_DECL(_compat_linuxkpi);
+SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+    "LinuxKPI 802.11 compatibility layer");
+
+SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN,
+    &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level");
+
 #ifndef	D80211_TODO
 #define	D80211_TODO		0x1
 #endif
@@ -96,9 +101,9 @@ SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_80211, CTLFLAG_RWTUN,
 #define	D80211_TRACEX		(D80211_TRACE_TX|D80211_TRACE_RX)
 #define	D80211_TRACEX_DUMP	(D80211_TRACE_TX_DUMP|D80211_TRACE_RX_DUMP)
 #define	D80211_TRACE_STA	0x10000
-#define	UNIMPLEMENTED		if (debug_80211 & D80211_TODO)		\
+#define	UNIMPLEMENTED		if (linuxkpi_debug_80211 & D80211_TODO)		\
     printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__)
-#define	TRACEOK()		if (debug_80211 & D80211_TRACEOK)	\
+#define	TRACEOK()		if (linuxkpi_debug_80211 & D80211_TRACEOK)	\
     printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__)
 #else
 #define	UNIMPLEMENTED		do { } while (0)
@@ -145,7 +150,8 @@ lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni,
     const char *_f, int _l)
 {
 
-	if ((debug_80211 & D80211_TRACE_STA) == 0)
+#ifdef LINUXKPI_DEBUG_80211
+	if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0)
 		return;
 	if (lsta == NULL)
 		return;
@@ -157,6 +163,7 @@ lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni,
 	printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq));
 	printf("\tkc %p state %d added_to_drv %d in_mgd %d\n",
 		lsta->kc, lsta->state, lsta->added_to_drv, lsta->in_mgd);
+#endif
 }
 
 static void
@@ -626,9 +633,11 @@ lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt)
 	list_add(&addr->addr_list, &mc_list->addr_list);
 	mc_list->count++;
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		printf("%s:%d: mc_list count %d: added %6D\n",
 		    __func__, __LINE__, mc_list->count, addr->addr, ":");
+#endif
 
 	return (1);
 }
@@ -674,9 +683,11 @@ lkpi_update_mcast_filter(struct ieee80211com *ic, bool force)
 	total_flags = changed_flags;
 	lkpi_80211_mo_configure_filter(hw, changed_flags, &total_flags, mc);
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		printf("%s: changed_flags %#06x count %d total_flags %#010x\n",
 		    __func__, changed_flags, mc_list.count, total_flags);
+#endif
 
 	if (mc_list.count != 0) {
 		list_for_each_safe(le, next, &mc_list.addr_list) {
@@ -697,7 +708,8 @@ lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
 
 	bss_changed = 0;
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
 		    "dtim_period %u sync_dtim_count %u sync_tsf %ju "
 		    "sync_device_ts %u bss_changed %#08x\n",
@@ -708,6 +720,7 @@ lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
 			(uintmax_t)vif->bss_conf.sync_tsf,
 			vif->bss_conf.sync_device_ts,
 			bss_changed);
+#endif
 
 	if (vif->bss_conf.beacon_int != ni->ni_intval) {
 		vif->bss_conf.beacon_int = ni->ni_intval;
@@ -726,7 +739,8 @@ lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
 	vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf);
 	/* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
 		    "dtim_period %u sync_dtim_count %u sync_tsf %ju "
 		    "sync_device_ts %u bss_changed %#08x\n",
@@ -737,6 +751,7 @@ lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
 			(uintmax_t)vif->bss_conf.sync_tsf,
 			vif->bss_conf.sync_device_ts,
 			bss_changed);
+#endif
 
 	return (bss_changed);
 }
@@ -1003,6 +1018,8 @@ lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int
 	lsta->added_to_drv = true;	/* mo manages. */
 #endif
 
+	lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
 	/*
 	 * Wakeup all queues now that sta is there so we have as much time to
 	 * possibly prepare the queue in the driver to be ready for the 1st
@@ -1967,9 +1984,11 @@ lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 	IEEE80211_LOCK_ASSERT(ic);
 	ostate = vap->iv_state;
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n",
 		    __func__, __LINE__, vap, nstate, arg);
+#endif
 
 	if (vap->iv_opmode == IEEE80211_M_STA) {
 
@@ -1992,11 +2011,13 @@ lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 	error = 0;
 	for (; s->handler != NULL; s++) {
 		if (ostate == s->ostate && nstate == s->nstate) {
-			if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+			if (linuxkpi_debug_80211 & D80211_TRACE)
 				ic_printf(vap->iv_ic, "%s: new state %d (%s) ->"
 				    " %d (%s): arg %d.\n", __func__,
 				    ostate, ieee80211_state_name[ostate],
 				    nstate, ieee80211_state_name[nstate], arg);
+#endif
 			error = s->handler(vap, nstate, arg);
 			break;
 		}
@@ -2013,11 +2034,13 @@ lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 	}
 
 	if (error == EALREADY) {
-		if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+		if (linuxkpi_debug_80211 & D80211_TRACE)
 			ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> "
 			    "%d (%s): iv_newstate already handled: %d.\n",
 			    __func__, ostate, ieee80211_state_name[ostate],
 			    nstate, ieee80211_state_name[nstate], error);
+#endif
 		return (0);
 	}
 
@@ -2030,10 +2053,12 @@ lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
 		/* return (error); */
 	}
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x "
 		    "calling net80211 parent\n",
 		    __func__, __LINE__, vap, nstate, arg);
+#endif
 
 	return (lvif->iv_newstate(vap, nstate, arg));
 }
@@ -2055,6 +2080,14 @@ lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
 	lvif = VAP_TO_LVIF(vap);
 	obss = vap->iv_bss;
 
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
+		ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p "
+		    "ni %p ni_drv_data %p\n", __func__,
+		    obss, (obss != NULL) ? obss->ni_drv_data : NULL,
+		    ni, (ni != NULL) ? ni->ni_drv_data : NULL);
+#endif
+
 	/* Nothing to copy from.  Just return. */
 	if (obss == NULL || obss->ni_drv_data == NULL)
 		goto out;
@@ -2068,12 +2101,6 @@ lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
 	if (obss == ni)
 		goto out;
 
-	if (debug_80211 & D80211_TRACE)
-		ic_printf(vap->iv_ic, "%s: obss %p ni_drv_data %p "
-		    "ni %p ni_drv_data %p\n", __func__,
-		    obss, (obss != NULL) ? obss->ni_drv_data : NULL,
-		    ni, (ni != NULL) ? ni->ni_drv_data : NULL);
-
 	lsta = obss->ni_drv_data;
 	obss->ni_drv_data = ni->ni_drv_data;
 	ni->ni_drv_data = lsta;
@@ -2802,10 +2829,12 @@ lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
 	mbufq_enqueue(&lsta->txq, m);
 	LKPI_80211_LSTA_UNLOCK(lsta);
 
-	if (debug_80211 & D80211_TRACE_TX)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE_TX)
 		printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n",
 		    __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":",
 		    mbufq_len(&lsta->txq));
+#endif
 
 	taskqueue_enqueue(taskqueue_thread, &lsta->txq_task);
 	return (0);
@@ -2832,7 +2861,7 @@ lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m)
 
 	M_ASSERTPKTHDR(m);
 #ifdef LINUXKPI_DEBUG_80211
-	if (debug_80211 & D80211_TRACE_TX_DUMP)
+	if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP)
 		hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0);
 #endif
 
@@ -2967,22 +2996,26 @@ lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m)
 			goto ops_tx;
 
 		skb_queue_tail(&ltxq->skbq, skb);
-		if (debug_80211 & D80211_TRACE_TX)
+#ifdef LINUXKPI_DEBUG_80211
+		if (linuxkpi_debug_80211 & D80211_TRACE_TX)
 			printf("%s:%d lsta %p sta %p ni %p %6D skb %p lxtq %p "
 			    "qlen %u WAKE_TX_Q ac %d prio %u qmap %u\n",
 			    __func__, __LINE__, lsta, sta, ni,
 			    ni->ni_macaddr, ":", skb, ltxq,
 			    skb_queue_len(&ltxq->skbq), ac,
 			    skb->priority, skb->qmap);
+#endif
 		lkpi_80211_mo_wake_tx_queue(hw, sta->txq[ac]);	/* XXX-BZ */
 		return;
 	}
 
 ops_tx:
-	if (debug_80211 & D80211_TRACE_TX)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE_TX)
 		printf("%s:%d lsta %p sta %p ni %p %6D skb %p TX ac %d prio %u qmap %u\n",
 		    __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":",
 		    skb, ac, skb->priority, skb->qmap);
+#endif
 	memset(&control, 0, sizeof(control));
 	control.sta = sta;
 
@@ -2994,17 +3027,17 @@ static void
 lkpi_80211_txq_task(void *ctx, int pending)
 {
 	struct lkpi_sta *lsta;
-	struct ieee80211_node *ni;
 	struct mbufq mq;
 	struct mbuf *m;
 
 	lsta = ctx;
-	ni = lsta->ni;
 
-	if (debug_80211 & D80211_TRACE_TX)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE_TX)
 		printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n",
-		    __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":",
+		    __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":",
 		    pending, mbufq_len(&lsta->txq));
+#endif
 
 	mbufq_init(&mq, IFQ_MAXLEN);
 
@@ -3613,7 +3646,7 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct ieee80211vap *vap;
 	struct ieee80211_hdr *hdr;
 	struct lkpi_sta *lsta;
-	int i, offset, ok, type;
+	int i, offset, ok;
 	bool is_beacon;
 
 	if (skb->len < 2) {
@@ -3646,10 +3679,10 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	is_beacon = ieee80211_is_beacon(hdr->frame_control);
 
 #ifdef LINUXKPI_DEBUG_80211
-	if (is_beacon && (debug_80211 & D80211_TRACE_RX_BEACONS) == 0)
+	if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0)
 		goto no_trace_beacons;
 
-	if (debug_80211 & D80211_TRACE_RX)
+	if (linuxkpi_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%s\n",
 		    __func__, skb, skb->_alloc_len, skb->len, skb->data_len,
@@ -3657,11 +3690,11 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 		    shinfo, shinfo->nr_frags,
 		    m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : "");
 
-	if (debug_80211 & D80211_TRACE_RX_DUMP)
+	if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP)
 		hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0);
 
 	/* Implement a dump_rxcb() !!! */
-	if (debug_80211 & D80211_TRACE_RX)
+	if (linuxkpi_debug_80211 & D80211_TRACE_RX)
 		printf("TRACE %s: RXCB: %ju %ju %u, %#0x, %u, %#0x, %#0x, "
 		    "%u band %u, %u %u %u %u, %u, %#x %#x %#x %#x %u %u %u\n",
 			__func__,
@@ -3738,10 +3771,12 @@ no_trace_beacons:
 		 */
 		vap = TAILQ_FIRST(&ic->ic_vaps);
 
-	if (debug_80211 & D80211_TRACE_RX)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE_RX)
 		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" : "");
+#endif
 
 	if (ni != NULL && vap != NULL && is_beacon &&
 	    rx_status->device_timestamp > 0 &&
@@ -3799,15 +3834,17 @@ skip_device_ts:
 
 	NET_EPOCH_ENTER(et);
 	if (ni != NULL) {
-		type = ieee80211_input_mimo(ni, m);
+		ok = ieee80211_input_mimo(ni, m);
 		ieee80211_free_node(ni);
 	} else {
-		type = ieee80211_input_mimo_all(ic, m);
+		ok = ieee80211_input_mimo_all(ic, m);
 	}
 	NET_EPOCH_EXIT(et);
 
-	if (debug_80211 & D80211_TRACE_RX)
-		printf("TRACE %s: handled frame type %#0x\n", __func__, type);
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+		printf("TRACE %s: handled frame type %#0x\n", __func__, ok);
+#endif
 
 	IMPROVE();
 
@@ -4159,8 +4196,10 @@ linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif)
 	nstate = IEEE80211_S_INIT;
 	arg = 0;	/* Not a valid reason. */
 
-	if (debug_80211 & D80211_TRACE)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE)
 		ic_printf(vap->iv_ic, "%s: vif %p\n", __func__, vif);
+#endif
 	ieee80211_new_state(vap, nstate, arg);
 }
 
@@ -4184,9 +4223,11 @@ linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif)
 	arg = 0;
 
 	/* We should be in RUN.  Can we assert that? */
-	if (debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN)
+#ifdef LINUXKPI_DEBUG_80211
+	if (linuxkpi_debug_80211 & D80211_TRACE || vap->iv_state != IEEE80211_S_RUN)
 		ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s\n", __func__,
 		    vif, vap, ieee80211_state_name[vap->iv_state]);
+#endif
 	ieee80211_new_state(vap, nstate, arg);
 }