git: 64d3da006376 - main - LinuxKPI: 802.11: add MO tracing

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 23 Oct 2022 21:53:59 UTC
The branch main has been updated by bz:

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

commit 64d3da006376576201677809474f8cebf061c81c
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-10-23 21:48:22 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-10-23 21:48:22 +0000

    LinuxKPI: 802.11: add MO tracing
    
    Add a macro to each implemented mac80211 operation.  This currently
    turns into a printf if LINUXKPI_80211_DEBUG is defined but in the
    future could become a different probe as well.
    This is helpful for quick analysis and boot-time problem debugging
    when DTrace and other frameworks may be harder to use.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
---
 sys/compat/linuxkpi/common/src/linux_80211.c       | 16 ---------
 sys/compat/linuxkpi/common/src/linux_80211.h       | 20 +++++++++++
 .../linuxkpi/common/src/linux_80211_macops.c       | 42 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 1eb520b2140f..b4438c0b1518 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -88,22 +88,6 @@ SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
 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
-#ifndef D80211_IMPROVE
-#define	D80211_IMPROVE		0x2
-#endif
-#define	D80211_TRACE		0x10
-#define	D80211_TRACEOK		0x20
-#define	D80211_TRACE_TX		0x100
-#define	D80211_TRACE_TX_DUMP	0x200
-#define	D80211_TRACE_RX		0x1000
-#define	D80211_TRACE_RX_DUMP	0x2000
-#define	D80211_TRACE_RX_BEACONS	0x4000
-#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 (linuxkpi_debug_80211 & D80211_TODO)		\
     printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__)
 #define	TRACEOK()		if (linuxkpi_debug_80211 & D80211_TRACEOK)	\
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h
index 65e78ba0fc08..587549ee786a 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.h
+++ b/sys/compat/linuxkpi/common/src/linux_80211.h
@@ -42,6 +42,26 @@
 #ifndef _LKPI_SRC_LINUX_80211_H
 #define _LKPI_SRC_LINUX_80211_H
 
+/* #define	LINUXKPI_DEBUG_80211 */
+
+#ifndef	D80211_TODO
+#define	D80211_TODO		0x1
+#endif
+#ifndef D80211_IMPROVE
+#define	D80211_IMPROVE		0x2
+#endif
+#define	D80211_TRACE		0x10
+#define	D80211_TRACEOK		0x20
+#define	D80211_TRACE_TX		0x100
+#define	D80211_TRACE_TX_DUMP	0x200
+#define	D80211_TRACE_RX		0x1000
+#define	D80211_TRACE_RX_DUMP	0x2000
+#define	D80211_TRACE_RX_BEACONS	0x4000
+#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	D80211_TRACE_MO		0x100000
+
 struct lkpi_radiotap_tx_hdr {
 	struct ieee80211_radiotap_header wt_ihdr;
 	uint8_t		wt_flags;
diff --git a/sys/compat/linuxkpi/common/src/linux_80211_macops.c b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
index 4fede921f017..5e08ad570668 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211_macops.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
@@ -39,6 +39,16 @@ __FBSDID("$FreeBSD$");
 
 #include "linux_80211.h"
 
+/* Could be a different tracing framework later. */
+#ifdef LINUXKPI_DEBUG_80211
+#define	LKPI_80211_TRACE_MO(fmt, ...)					\
+    if (linuxkpi_debug_80211 & D80211_TRACE_MO)				\
+	printf("LKPI_80211_TRACE_MO %s:%d:_" fmt "\n",			\
+	    __func__, __LINE__, __VA_ARGS__)
+#else
+#define	LKPI_80211_TRACE_MO(...)	do { } while(0)
+#endif
+
 int
 lkpi_80211_mo_start(struct ieee80211_hw *hw)
 {
@@ -56,6 +66,7 @@ lkpi_80211_mo_start(struct ieee80211_hw *hw)
 		error = EEXIST;
 		goto out;
 	}
+	LKPI_80211_TRACE_MO("hw %p", hw);
 	error = lhw->ops->start(hw);
 	if (error == 0)
 		lhw->sc_flags |= LKPI_MAC80211_DRV_STARTED;
@@ -73,6 +84,7 @@ lkpi_80211_mo_stop(struct ieee80211_hw *hw)
 	if (lhw->ops->stop == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p", hw);
 	lhw->ops->stop(hw);
 	lhw->sc_flags &= ~LKPI_MAC80211_DRV_STARTED;
 }
@@ -89,6 +101,7 @@ lkpi_80211_mo_get_antenna(struct ieee80211_hw *hw, u32 *txs, u32 *rxs)
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p", hw);
 	error = lhw->ops->get_antenna(hw, txs, rxs);
 
 out:
@@ -107,6 +120,7 @@ lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *hw, uint32_t frag_th)
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p frag_th %u", hw, frag_th);
 	error = lhw->ops->set_frag_threshold(hw, frag_th);
 
 out:
@@ -125,6 +139,7 @@ lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *hw, uint32_t rts_th)
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p rts_th %u", hw, rts_th);
 	error = lhw->ops->set_rts_threshold(hw, rts_th);
 
 out:
@@ -155,6 +170,7 @@ lkpi_80211_mo_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	}
 	LKPI_80211_LVIF_UNLOCK(lvif);
 
+	LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
 	error = lhw->ops->add_interface(hw, vif);
 	if (error == 0) {
 		LKPI_80211_LVIF_LOCK(lvif);
@@ -184,6 +200,7 @@ lkpi_80211_mo_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vi
 	}
 	LKPI_80211_LVIF_UNLOCK(lvif);
 
+	LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
 	lhw->ops->remove_interface(hw, vif);
 	LKPI_80211_LVIF_LOCK(lvif);
 	lvif->added_to_drv = false;
@@ -206,6 +223,7 @@ lkpi_80211_mo_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	}
 
 	lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING;
+	LKPI_80211_TRACE_MO("hw %p vif %p sr %p", hw, vif, sr);
 	error = lhw->ops->hw_scan(hw, vif, sr);
 	if (error != 0)
 		lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
@@ -223,6 +241,7 @@ lkpi_80211_mo_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	if (lhw->ops->cancel_hw_scan == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
 	lhw->ops->cancel_hw_scan(hw, vif);
 }
 
@@ -235,6 +254,7 @@ lkpi_80211_mo_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vi
 	if (lhw->ops->sw_scan_complete == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
 	lhw->ops->sw_scan_complete(hw, vif);
 	lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
 }
@@ -249,6 +269,7 @@ lkpi_80211_mo_sw_scan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	if (lhw->ops->sw_scan_start == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
 	lhw->ops->sw_scan_start(hw, vif, addr);
 }
 
@@ -267,6 +288,7 @@ lkpi_80211_mo_prepare_multicast(struct ieee80211_hw *hw,
 	if (lhw->ops->prepare_multicast == NULL)
 		return (0);
 
+	LKPI_80211_TRACE_MO("hw %p mc_list %p", hw, mc_list);
 	ptr = lhw->ops->prepare_multicast(hw, mc_list);
 	return (ptr);
 }
@@ -284,6 +306,7 @@ lkpi_80211_mo_configure_filter(struct ieee80211_hw *hw, unsigned int changed_fla
 	if (mc_ptr == 0)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p changed_flags %#x total_flags %p mc_ptr %ju", hw, changed_flags, total_flags, (uintmax_t)mc_ptr);
 	lhw->ops->configure_filter(hw, changed_flags, total_flags, mc_ptr);
 }
 
@@ -313,6 +336,7 @@ lkpi_80211_mo_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
 	error = lhw->ops->sta_add(hw, vif, sta);
 	if (error == 0)
 		lsta->added_to_drv = true;
@@ -342,6 +366,7 @@ lkpi_80211_mo_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
 	error = lhw->ops->sta_remove(hw, vif, sta);
 	if (error == 0)
 		lsta->added_to_drv = false;
@@ -361,6 +386,7 @@ lkpi_80211_mo_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	lhw = HW_TO_LHW(hw);
 	lsta = STA_TO_LSTA(sta);
 	if (lhw->ops->sta_state != NULL) {
+		LKPI_80211_TRACE_MO("hw %p vif %p sta %p nstate %d", hw, vif, sta, nstate);
 		error = lhw->ops->sta_state(hw, vif, sta, lsta->state, nstate);
 		if (error == 0) {
 			if (nstate == IEEE80211_STA_NOTEXIST)
@@ -405,6 +431,7 @@ lkpi_80211_mo_config(struct ieee80211_hw *hw, uint32_t changed)
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p changed %u", hw, changed);
 	error = lhw->ops->config(hw, changed);
 
 out:
@@ -425,6 +452,7 @@ lkpi_80211_mo_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p vif %p chanctx_conf %p", hw, vif, chanctx_conf);
 	error = lhw->ops->assign_vif_chanctx(hw, vif, NULL, chanctx_conf);
 	if (error == 0)
 		vif->chanctx_conf = chanctx_conf;
@@ -446,6 +474,7 @@ lkpi_80211_mo_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif
 	if (*chanctx_conf == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p chanctx_conf %p", hw, vif, *chanctx_conf);
 	lhw->ops->unassign_vif_chanctx(hw, vif, NULL, *chanctx_conf);
 	*chanctx_conf = NULL;
 }
@@ -464,6 +493,7 @@ lkpi_80211_mo_add_chanctx(struct ieee80211_hw *hw,
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p chanctx_conf %p", hw, chanctx_conf);
 	error = lhw->ops->add_chanctx(hw, chanctx_conf);
 
 out:
@@ -480,6 +510,7 @@ lkpi_80211_mo_change_chanctx(struct ieee80211_hw *hw,
 	if (lhw->ops->change_chanctx == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p chanctx_conf %p changed %u", hw, chanctx_conf, changed);
 	lhw->ops->change_chanctx(hw, chanctx_conf, changed);
 }
 
@@ -493,6 +524,7 @@ lkpi_80211_mo_remove_chanctx(struct ieee80211_hw *hw,
 	if (lhw->ops->remove_chanctx == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p chanctx_conf %p", hw, chanctx_conf);
 	lhw->ops->remove_chanctx(hw, chanctx_conf);
 }
 
@@ -506,6 +538,7 @@ lkpi_80211_mo_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vi
 	if (lhw->ops->bss_info_changed == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p conf %p changed %#jx", hw, vif, conf, (uintmax_t)changed);
 	lhw->ops->bss_info_changed(hw, vif, conf, changed);
 }
 
@@ -523,6 +556,7 @@ lkpi_80211_mo_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p vif %p ac %u txpq %p", hw, vif, ac, txqp);
 	error = lhw->ops->conf_tx(hw, vif, 0, ac, txqp);
 
 out:
@@ -539,6 +573,7 @@ lkpi_80211_mo_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	if (lhw->ops->flush == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p nqueues %u drop %d", hw, vif, nqueues, drop);
 	lhw->ops->flush(hw, vif, nqueues, drop);
 }
 
@@ -552,6 +587,7 @@ lkpi_80211_mo_mgd_prepare_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 	if (lhw->ops->mgd_prepare_tx == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p txinfo %p", hw, vif, txinfo);
 	lhw->ops->mgd_prepare_tx(hw, vif, txinfo);
 }
 
@@ -565,6 +601,7 @@ lkpi_80211_mo_mgd_complete_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif
 	if (lhw->ops->mgd_complete_tx == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p txinfo %p", hw, vif, txinfo);
 	lhw->ops->mgd_complete_tx(hw, vif, txinfo);
 }
 
@@ -578,6 +615,7 @@ lkpi_80211_mo_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *txctrl,
 	if (lhw->ops->tx == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p txctrl %p skb %p", hw, txctrl, skb);
 	lhw->ops->tx(hw, txctrl, skb);
 }
 
@@ -590,6 +628,7 @@ lkpi_80211_mo_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
 	if (lhw->ops->wake_tx_queue == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p txq %p", hw, txq);
 	lhw->ops->wake_tx_queue(hw, txq);
 }
 
@@ -602,6 +641,7 @@ lkpi_80211_mo_sync_rx_queues(struct ieee80211_hw *hw)
 	if (lhw->ops->sync_rx_queues == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p", hw);
 	lhw->ops->sync_rx_queues(hw);
 }
 
@@ -615,6 +655,7 @@ lkpi_80211_mo_sta_pre_rcu_remove(struct ieee80211_hw *hw,
 	if (lhw->ops->sta_pre_rcu_remove == NULL)
 		return;
 
+	LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
 	lhw->ops->sta_pre_rcu_remove(hw, vif, sta);
 }
 
@@ -632,6 +673,7 @@ lkpi_80211_mo_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 		goto out;
 	}
 
+	LKPI_80211_TRACE_MO("hw %p cmd %d vif %p sta %p kc %p", hw, cmd, vif, sta, kc);
 	error = lhw->ops->set_key(hw, cmd, vif, sta, kc);
 
 out: