linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] ath: Add common function for reading cycle counters
@ 2010-10-05  9:55 Bruno Randolf
  2010-10-05  9:55 ` [PATCH 2/5] ath5k: Use common cycle counters for ANI Bruno Randolf
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Bruno Randolf @ 2010-10-05  9:55 UTC (permalink / raw)
  To: linville; +Cc: nbd, ath5k-devel, linux-wireless, adrian, vasanth

Implement a common function to access the cycle counters (profile counters) for
use in ath5k and ath9k. This is necessary because we want to access the cycle
counters from different places: ANI uses it in it's algorithm to calculate the
"listen time" and at the same time we want to show it for debugging purposes
and add it to the "survey" command later.

This is a very simple implementation, which resets the HW counters to zero
after every read (to avoid overflows) and currently takes care of two different
counters, one for ANI and one for survey. If additional counters should be
required they would have to be added by hardcoding them in the function. This
is not the most flexible way to deal with this, but it's easy and simple and i
believe should be sufficient.

Users have to hold the lock while accessing the counters.

Signed-off-by: Bruno Randolf <br1@einfach.org>
---
 drivers/net/wireless/ath/ath.h |   23 +++++++++++++++++++++++
 drivers/net/wireless/ath/hw.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/reg.h |   11 +++++++++++
 3 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
index dd236c3..699c904 100644
--- a/drivers/net/wireless/ath/ath.h
+++ b/drivers/net/wireless/ath/ath.h
@@ -97,6 +97,13 @@ enum ath_cipher {
 	ATH_CIPHER_MIC = 127
 };
 
+struct ath_cycle_counters {
+	u32 cycles;
+	u32 rx_busy; /* register is called "rx clear" but it's the inverse */
+	u32 rx_frame;
+	u32 tx_frame;
+};
+
 /**
  * struct ath_ops - Register read/write operations
  *
@@ -148,6 +155,10 @@ struct ath_common {
 	DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
 	enum ath_crypt_caps crypt_caps;
 
+	struct ath_cycle_counters cc_ani;
+	struct ath_cycle_counters cc_survey;
+	spinlock_t cc_lock;
+
 	struct ath_regulatory regulatory;
 	const struct ath_ops *ops;
 	const struct ath_bus_ops *bus_ops;
@@ -165,4 +176,16 @@ int ath_key_config(struct ath_common *common,
 			  struct ieee80211_key_conf *key);
 bool ath_hw_keyreset(struct ath_common *common, u16 entry);
 
+void ath_hw_cycle_counters_update(struct ath_common *common);
+
+static inline void ath_hw_cycle_counters_lock(struct ath_common *common)
+{
+	spin_lock_bh(&common->cc_lock);
+}
+
+static inline void ath_hw_cycle_counters_unlock(struct ath_common *common)
+{
+	spin_unlock_bh(&common->cc_lock);
+}
+
 #endif /* ATH_H */
diff --git a/drivers/net/wireless/ath/hw.c b/drivers/net/wireless/ath/hw.c
index a8f81ea..f26730f 100644
--- a/drivers/net/wireless/ath/hw.c
+++ b/drivers/net/wireless/ath/hw.c
@@ -124,3 +124,43 @@ void ath_hw_setbssidmask(struct ath_common *common)
 	REG_WRITE(ah, get_unaligned_le16(common->bssidmask + 4), AR_BSSMSKU);
 }
 EXPORT_SYMBOL(ath_hw_setbssidmask);
+
+/**
+ * ath_hw_cycle_counters_update - common function to update cycle counters
+ *
+ * @common: the ath_common struct for the device.
+ *
+ * This function is used to update all cycle counters in one place.
+ * It has to be called while holding common->cc_lock!
+ */
+void ath_hw_cycle_counters_update(struct ath_common *common)
+{
+	u32 cycles, busy, rx, tx;
+
+	/* freeze */
+	REG_WRITE(common, AR_MIBC_FMC, AR_MIBC);
+	/* read */
+	cycles = REG_READ(common, AR_CCCNT);
+	busy = REG_READ(common, AR_RCCNT);
+	rx = REG_READ(common, AR_RFCNT);
+	tx = REG_READ(common, AR_TFCNT);
+	/* clear */
+	REG_WRITE(common, 0, AR_CCCNT);
+	REG_WRITE(common, 0, AR_RFCNT);
+	REG_WRITE(common, 0, AR_RCCNT);
+	REG_WRITE(common, 0, AR_TFCNT);
+	/* unfreeze */
+	REG_WRITE(common, 0, AR_MIBC);
+
+	/* update all cycle counters here */
+	common->cc_ani.cycles += cycles;
+	common->cc_ani.rx_busy += busy;
+	common->cc_ani.rx_frame += rx;
+	common->cc_ani.tx_frame += tx;
+
+	common->cc_survey.cycles += cycles;
+	common->cc_survey.rx_busy += busy;
+	common->cc_survey.rx_frame += rx;
+	common->cc_survey.tx_frame += tx;
+}
+EXPORT_SYMBOL(ath_hw_cycle_counters_update);
diff --git a/drivers/net/wireless/ath/reg.h b/drivers/net/wireless/ath/reg.h
index e798ef4..298e53f 100644
--- a/drivers/net/wireless/ath/reg.h
+++ b/drivers/net/wireless/ath/reg.h
@@ -17,6 +17,12 @@
 #ifndef ATH_REGISTERS_H
 #define ATH_REGISTERS_H
 
+#define AR_MIBC			0x0040
+#define AR_MIBC_COW		0x00000001
+#define AR_MIBC_FMC		0x00000002
+#define AR_MIBC_CMC		0x00000004
+#define AR_MIBC_MCS		0x00000008
+
 /*
  * BSSID mask registers. See ath_hw_set_bssid_mask()
  * for detailed documentation about these registers.
@@ -24,6 +30,11 @@
 #define AR_BSSMSKL		0x80e0
 #define AR_BSSMSKU		0x80e4
 
+#define AR_TFCNT		0x80ec
+#define AR_RFCNT		0x80f0
+#define AR_RCCNT		0x80f4
+#define AR_CCCNT		0x80f8
+
 #define AR_KEYTABLE_0           0x8800
 #define AR_KEYTABLE(_n)         (AR_KEYTABLE_0 + ((_n)*32))
 #define AR_KEY_CACHE_SIZE       128


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2010-10-08 17:41 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-05  9:55 [PATCH 1/5] ath: Add common function for reading cycle counters Bruno Randolf
2010-10-05  9:55 ` [PATCH 2/5] ath5k: Use common cycle counters for ANI Bruno Randolf
2010-10-05  9:55 ` [PATCH 3/5] ath9k: Use common cycle counters Bruno Randolf
2010-10-05 20:14   ` [ath5k-devel] " Luis R. Rodriguez
2010-10-06  1:10     ` Bruno Randolf
2010-10-06  1:13       ` Luis R. Rodriguez
2010-10-06  1:18   ` Luis R. Rodriguez
2010-10-06  2:00     ` Bruno Randolf
2010-10-06  2:15       ` [ath5k-devel] " Luis R. Rodriguez
2010-10-05  9:55 ` [PATCH 4/5] nl80211/mac80211: Add channel utilization to survey Bruno Randolf
2010-10-05 22:36   ` Luis R. Rodriguez
2010-10-06  2:35     ` Bruno Randolf
2010-10-06  9:54   ` Helmut Schaa
2010-10-07  1:03     ` Bruno Randolf
2010-10-07  3:02       ` [ath5k-devel] " Luis R. Rodriguez
2010-10-07  6:51       ` Helmut Schaa
2010-10-07  7:06         ` Bruno Randolf
2010-10-07  7:35           ` Jonathan Guerin
2010-10-07  7:44           ` Helmut Schaa
2010-10-07  7:52             ` Johannes Berg
2010-10-08 17:41               ` Helmut Schaa
2010-10-05  9:55 ` [PATCH 5/5] ath5k: Add busy ratios to survey data Bruno Randolf
2010-10-05 22:38   ` Luis R. Rodriguez
2010-10-06  2:25     ` Bruno Randolf
2010-10-06  2:45       ` Felix Fietkau
2010-10-06  2:50         ` Bruno Randolf
2010-10-06 14:13           ` Luis R. Rodriguez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).