Subject: [PATCH 19/26] rt2x00: Fix channel_change_time calculation

From: Ivo van Doorn <[email-masked]>
Date: Sun, 3 Dec 2006 19:18:58 +0100

Correctly initialize the channel_change_time.
Make sure that channel is reset afterwards,
otherwise the channel is not correctly initialized
and rx/tx will fail.

Signed-off-by Ivo van Doorn <[email-masked]>

---

diff -rU3 wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2400pci.c wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2400pci.c
--- wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2400pci.c	2006-12-03 14:45:46.000000000 +0100
+++ wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2400pci.c	2006-12-03 14:52:04.000000000 +0100
@@ -1124,6 +1124,19 @@
 	unsigned long jiffies_end;
 
 	/*
+	 * Only initialize the channel_change_time
+	 * if it has not been set previously.
+	 */
+	if (rt2x00dev->hw->channel_change_time)
+		return 0;
+
+	/*
+	 * Invalidate the rx_params.channel value to make sure
+	 * the config channel will be correctly executed.
+	 */
+	rt2x00dev->rx_params.channel = 0;
+
+	/*
 	 * Determine channel_change_time
 	 * by measuring the time it takes
 	 * to switch the channel.
@@ -1171,10 +1184,11 @@
 	}
 
 	/*
-	 * Determine channel change time.
+	 * Reset the channel_change_time value
+	 * to make sure it will be correctly initialized
+	 * after the radio has been enabled.
 	 */
-	if (rt2400pci_init_channel_time(rt2x00dev))
-		goto exit_fail;
+	rt2x00dev->hw->channel_change_time = 0;
 
 	/*
 	 * Register interrupt handler.
diff -rU3 wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2500pci.c wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2500pci.c
--- wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2500pci.c	2006-12-03 14:46:09.000000000 +0100
+++ wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2500pci.c	2006-12-03 14:52:32.000000000 +0100
@@ -1248,6 +1248,19 @@
 	unsigned long jiffies_end;
 
 	/*
+	 * Only initialize the channel_change_time
+	 * if it has not been set previously.
+	 */
+	if (rt2x00dev->hw->channel_change_time)
+		return 0;
+
+	/*
+	 * Invalidate the rx_params.channel value to make sure
+	 * the config channel will be correctly executed.
+	 */
+	rt2x00dev->rx_params.channel = 0;
+
+	/*
 	 * Determine channel_change_time
 	 * by measuring the time it takes
 	 * to switch the channel.
@@ -1296,10 +1309,11 @@
 	}
 
 	/*
-	 * Determine channel change time.
+	 * Reset the channel_change_time value
+	 * to make sure it will be correctly initialized
+	 * after the radio has been enabled.
 	 */
-	if (rt2500pci_init_channel_time(rt2x00dev))
-		goto exit_fail;
+	rt2x00dev->hw->channel_change_time = 0;
 
 	/*
 	 * Register interrupt handler.
diff -rU3 wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2500usb.c wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2500usb.c
--- wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt2500usb.c	2006-12-03 14:46:19.000000000 +0100
+++ wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt2500usb.c	2006-12-03 14:52:36.000000000 +0100
@@ -1214,6 +1214,19 @@
 	unsigned long jiffies_end;
 
 	/*
+	 * Only initialize the channel_change_time
+	 * if it has not been set previously.
+	 */
+	if (rt2x00dev->hw->channel_change_time)
+		return 0;
+
+	/*
+	 * Invalidate the rx_params.channel value to make sure
+	 * the config channel will be correctly executed.
+	 */
+	rt2x00dev->rx_params.channel = 0;
+
+	/*
 	 * Determine channel_change_time
 	 * by measuring the time it takes
 	 * to switch the channel.
@@ -1262,10 +1275,11 @@
 	}
 
 	/*
-	 * Determine channel change time.
+	 * Reset the channel_change_time value
+	 * to make sure it will be correctly initialized
+	 * after the radio has been enabled.
 	 */
-	if (rt2500usb_init_channel_time(rt2x00dev))
-		goto exit_fail;
+	rt2x00dev->hw->channel_change_time = 0;
 
 	SET_FLAG(rt2x00dev, DEVICE_INITIALIZED);
 
diff -rU3 wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt61pci.c wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt61pci.c
--- wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt61pci.c	2006-12-03 14:46:31.000000000 +0100
+++ wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt61pci.c	2006-12-03 14:52:40.000000000 +0100
@@ -1681,6 +1681,19 @@
 	unsigned long jiffies_end;
 
 	/*
+	 * Only initialize the channel_change_time
+	 * if it has not been set previously.
+	 */
+	if (rt2x00dev->hw->channel_change_time)
+		return 0;
+
+	/*
+	 * Invalidate the rx_params.channel value to make sure
+	 * the config channel will be correctly executed.
+	 */
+	rt2x00dev->rx_params.channel = 0;
+
+	/*
 	 * Determine channel_change_time
 	 * by measuring the time it takes
 	 * to switch the channel.
@@ -1736,10 +1749,11 @@
 	}
 
 	/*
-	 * Determine channel change time.
+	 * Reset the channel_change_time value
+	 * to make sure it will be correctly initialized
+	 * after the radio has been enabled.
 	 */
-	if (rt61pci_init_channel_time(rt2x00dev))
-		goto exit_fail;
+	rt2x00dev->hw->channel_change_time = 0;
 
 	/*
 	 * Register interrupt handler.
diff -rU3 wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt73usb.c wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt73usb.c
--- wireless-dev-mac/drivers/net/wireless/d80211/rt2x00/rt73usb.c	2006-12-03 14:46:42.000000000 +0100
+++ wireless-dev-channel/drivers/net/wireless/d80211/rt2x00/rt73usb.c	2006-12-03 14:52:44.000000000 +0100
@@ -1463,6 +1463,19 @@
 	unsigned long jiffies_end;
 
 	/*
+	 * Only initialize the channel_change_time
+	 * if it has not been set previously.
+	 */
+	if (rt2x00dev->hw->channel_change_time)
+		return 0;
+
+	/*
+	 * Invalidate the rx_params.channel value to make sure
+	 * the config channel will be correctly executed.
+	 */
+	rt2x00dev->rx_params.channel = 0;
+
+	/*
 	 * Determine channel_change_time
 	 * by measuring the time it takes
 	 * to switch the channel.
@@ -1518,10 +1531,11 @@
 	}
 
 	/*
-	 * Determine channel change time.
+	 * Reset the channel_change_time value
+	 * to make sure it will be correctly initialized
+	 * after the radio has been enabled.
 	 */
-	if (rt73usb_init_channel_time(rt2x00dev))
-		goto exit_fail;
+	rt2x00dev->hw->channel_change_time = 0;
 
 	SET_FLAG(rt2x00dev, DEVICE_INITIALIZED);