Skip to contentSkip to conversation

rt2x00: Periodically read statistics

PATCH In review Ivo van Doorn 1 participant 1 message Jul 31, 2007 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 20/24 rt2x00: Periodically read statistics

Quoted 1 line

From ae4ebe1eadb9e5d8a4ea63aa6e2e260fb107eadf Mon Sep 17 00:00:00 2001

From: Ivo van Doorn <[email protected]>
Date: Tue, 31 Jul 2007 14:09:45 +0200
Subject: [PATCH 20/24] rt2x00: Periodically read statistics

Split the link tuner up into 2 actions,
first reading of statistics. Where the CCA count
and the FCS error count can be read.
second part where the link tuner is handled.

This has 2 benefits, statistics are read on a single location and we can use this location to determine the signal quality later on.
And we can move the get_stats callback function into rt2x00mac.c since no device specific things are inside.

For rt2400pci this also changes the link tuner, previously it only degraded the sensitivity but now it uses the same values as the other drivers to either increase but also decrease the AGC VGC value.

---
 drivers/net/wireless/rt2400pci.c |   71 +++++++++++++++----------------------
 drivers/net/wireless/rt2500pci.c |   45 +++++++++++-------------
 drivers/net/wireless/rt2500usb.c |   48 ++++++++++++-------------
 drivers/net/wireless/rt2500usb.h |   29 ++++++++++++---
 drivers/net/wireless/rt2x00.h    |    3 ++
 drivers/net/wireless/rt2x00dev.c |   12 ++++--
 drivers/net/wireless/rt2x00mac.c |   16 ++++++++
 drivers/net/wireless/rt61pci.c   |   47 +++++++++++--------------
 drivers/net/wireless/rt73usb.c   |   49 ++++++++++++--------------
 9 files changed, 165 insertions(+), 155 deletions(-)
drivers/net/wireless/rt2400pci.c +29 -42
index 4ea2217..2c60c3e 100644
@@ -624,6 +624,25 @@ static void rt2400pci_disable_led(struct rt2x00_dev *rt2x00dev)
 /*
  * Link tuning
  */
+static void rt2400pci_link_stats(struct rt2x00_dev *rt2x00dev)
+{
+	u32 reg;
+	u8 bbp;
+
+	/*
+	 * Update FCS error count from register.
+	 */
+	rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
+	rt2x00dev->low_level_stats.dot11FCSErrorCount +=
+	    rt2x00_get_field32(reg, CNT0_FCS_ERROR);
+
+	/*
+	 * Update False CCA count from register.
+	 */
+	rt2400pci_bbp_read(rt2x00dev, 39, &bbp);
+	rt2x00dev->link.false_cca = bbp;
+}
+
 static void rt2400pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
 {
 	rt2400pci_bbp_write(rt2x00dev, 13, 0x08);
@@ -632,7 +651,6 @@ static void rt2400pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
 static void rt2400pci_link_tuner(struct rt2x00_dev *rt2x00dev)
 {
 	u8 reg;
-	char false_cca_delta;
 
 	/*
 	 * The link tuner should not run longer then 60 seconds,
@@ -642,28 +660,16 @@ static void rt2400pci_link_tuner(struct rt2x00_dev *rt2x00dev)
 		return;
 
 	/*
-	 * Read false CCA counter.
+	 * Base r13 link tuning on the false cca count.
 	 */
-	rt2400pci_bbp_read(rt2x00dev, 39, &reg);
+	rt2400pci_bbp_read(rt2x00dev, 13, &reg);
 
-	/*
-	 * Determine difference with previous CCA counter.
-	 */
-	false_cca_delta = reg - rt2x00dev->link.false_cca;
-	rt2x00dev->link.false_cca = reg;
-
-	/*
-	 * Check if the difference is higher than the
-	 * threshold and if so, tune the link.
-	 */
-	if (false_cca_delta >= 8) {
-		/*
-		 * Read and update RX AGC VGC.
-		 */
-		rt2400pci_bbp_read(rt2x00dev, 13, &reg);
-		reg += 2;
-		if (reg < 0x20)
-			rt2400pci_bbp_write(rt2x00dev, 13, reg);
+	if (rt2x00dev->link.false_cca > 512 && reg < 0x20) {
+		rt2400pci_bbp_write(rt2x00dev, 13, ++reg);
+		rt2x00dev->link.vgc_level = reg;
+	} else if (rt2x00dev->link.false_cca < 100 && reg > 0x08) {
+		rt2400pci_bbp_write(rt2x00dev, 13, --reg);
+		rt2x00dev->link.vgc_level = reg;
 	}
 }
 
@@ -1510,26 +1516,6 @@ static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
 /*
  * IEEE80211 stack callback functions.
  */
-static int rt2400pci_get_stats(struct ieee80211_hw *hw,
-			       struct ieee80211_low_level_stats *stats)
-{
-	struct rt2x00_dev *rt2x00dev = hw->priv;
-	u32 reg;
-
-	/*
-	 * Update FCS error count from register.
-	 * The dot11ACKFailureCount, dot11RTSFailureCount and
-	 * dot11RTSSuccessCount are updated in interrupt time.
-	 */
-	rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
-	rt2x00dev->low_level_stats.dot11FCSErrorCount +=
-	    rt2x00_get_field32(reg, CNT0_FCS_ERROR);
-
-	memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats));
-
-	return 0;
-}
-
 static int rt2400pci_set_retry_limit(struct ieee80211_hw *hw,
 				     u32 short_retry, u32 long_retry)
 {
@@ -1608,7 +1594,7 @@ static const struct ieee80211_ops rt2400pci_mac80211_ops = {
 	.config			= rt2x00mac_config,
 	.config_interface	= rt2x00mac_config_interface,
 	.set_multicast_list	= rt2x00mac_set_multicast_list,
-	.get_stats		= rt2400pci_get_stats,
+	.get_stats		= rt2x00mac_get_stats,
 	.set_retry_limit	= rt2400pci_set_retry_limit,
 	.conf_tx		= rt2400pci_conf_tx,
 	.get_tx_stats		= rt2x00mac_get_tx_stats,
@@ -1627,6 +1613,7 @@ static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = {
 #ifdef CONFIG_RT2400PCI_RFKILL
 	.rfkill_poll		= rt2400pci_rfkill_poll,
 #endif /* CONFIG_RT2400PCI_RFKILL */
+	.link_stats		= rt2400pci_link_stats,
 	.reset_tuner		= rt2400pci_reset_tuner,
 	.link_tuner		= rt2400pci_link_tuner,
 	.write_tx_desc		= rt2400pci_write_tx_desc,
drivers/net/wireless/rt2500pci.c +20 -25

81 lines not on this page · raw message

drivers/net/wireless/rt2500usb.c +23 -25

92 lines not on this page · raw message

drivers/net/wireless/rt2500usb.h +23 -6
index 9df67fb..f0eaead 100644
@@ -474,18 +474,35 @@
 #define STA_CSR0_FCS_ERROR		FIELD16(0xffff)
 
 /*
- * Statistic Register.
- * STA_CSR1: PLCP error.
- * STA_CSR2: LONG error.
- * STA_CSR3: CCA false alarm.
- * STA_CSR4: RX FIFO overflow.
- * STA_CSR5: Beacon sent counter.
+ * STA_CSR1: PLCP error count.
  */
 #define STA_CSR1			0x04e2
+
+/*
+ * STA_CSR2: LONG error count.
+ */
 #define STA_CSR2			0x04e4
+
+/*
+ * STA_CSR3: CCA false alarm.
+ * FALSE_CCA_ERROR: False CCA error count, cleared when read.
+ */
 #define STA_CSR3			0x04e6
+#define STA_CSR3_FALSE_CCA_ERROR	FIELD16(0xffff)
+
+/*
+ * STA_CSR4: RX FIFO overflow.
+ */
 #define STA_CSR4			0x04e8
+
+/*
+ * STA_CSR5: Beacon sent counter.
+ */
 #define STA_CSR5			0x04ea
+
+/*
+ *  Statistics registers
+ */
 #define STA_CSR6			0x04ec
 #define STA_CSR7			0x04ee
 #define STA_CSR8			0x04f0
drivers/net/wireless/rt2x00.h +3 -0
index 9a52251..b7e2578 100644
@@ -357,6 +357,7 @@ struct rt2x00lib_ops {
 	int (*set_device_state) (struct rt2x00_dev *rt2x00dev,
 				 enum dev_state state);
 	int (*rfkill_poll) (struct rt2x00_dev *rt2x00dev);
+	void (*link_stats) (struct rt2x00_dev *rt2x00dev);
 	void (*reset_tuner) (struct rt2x00_dev *rt2x00dev);
 	void (*link_tuner) (struct rt2x00_dev *rt2x00dev);
 
@@ -733,6 +734,8 @@ int rt2x00mac_config_interface(struct ieee80211_hw *hw, int if_id,
 			       struct ieee80211_if_conf *conf);
 void rt2x00mac_set_multicast_list(struct ieee80211_hw *hw,
 				  unsigned short flags, int mc_count);
+int rt2x00mac_get_stats(struct ieee80211_hw *hw,
+			struct ieee80211_low_level_stats *stats);
 int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
 			   struct ieee80211_tx_queue_stats *stats);
 int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue,
drivers/net/wireless/rt2x00dev.c +8 -4
index f0c00d7..42308ed 100644
@@ -175,12 +175,16 @@ static void rt2x00lib_link_tuner(struct work_struct *work)
 	    container_of(work, struct rt2x00_dev, link.work.work);
 
 	/*
-	 * Check if the Link tuning has been disabled.
+	 * Update statistics.
 	 */
-	if (test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
-		return;
+	rt2x00dev->ops->lib->link_stats(rt2x00dev);
 
-	rt2x00dev->ops->lib->link_tuner(rt2x00dev);
+	/*
+	 * Only perform the link tuning when Link tuning
+	 * has been enabled (This could have been disabled from the EEPROM).
+	 */
+	if (!test_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags))
+		rt2x00dev->ops->lib->link_tuner(rt2x00dev);
 
 	/*
 	 * Increase tuner counter, and reschedule the next link tuner run.
drivers/net/wireless/rt2x00mac.c +16 -0
index c36ac4a..9c6d043 100644
@@ -350,6 +350,22 @@ void rt2x00mac_set_multicast_list(struct ieee80211_hw *hw,
 }
 EXPORT_SYMBOL_GPL(rt2x00mac_set_multicast_list);
 
+int rt2x00mac_get_stats(struct ieee80211_hw *hw,
+			struct ieee80211_low_level_stats *stats)
+{
+	struct rt2x00_dev *rt2x00dev = hw->priv;
+
+	/*
+	 * The dot11ACKFailureCount, dot11RTSFailureCount and
+	 * dot11RTSSuccessCount are updated in interrupt time.
+	 * dot11FCSErrorCount is updated in the link tuner.
+	 */
+	memcpy(stats, &rt2x00dev->low_level_stats, sizeof(*stats));
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(rt2x00mac_get_stats);
+
 int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
 			   struct ieee80211_tx_queue_stats *stats)
 {
drivers/net/wireless/rt61pci.c +21 -26

83 lines not on this page · raw message

drivers/net/wireless/rt73usb.c +22 -27

85 lines not on this page · raw message

Signature · 1 line
1.5.2.4