Skip to contentSkip to conversation

rt2x00: Fix hwmode selection

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

lore
Share & tools
lore
#0 lore raw

PATCH 16/28 rt2x00: Fix hwmode selection

Store the current selected mode, and use that whenever for selecting the modes during later configuration steps.

---

drivers/net/wireless/mac80211/rt2x00/rt2400pci.c +49 -27
index 30f9bf3..18e615c 100644
@@ -650,6 +650,7 @@ static void rt2400pci_config_rate(struct rt2x00_dev *rt2x00dev, const int rate)
 static void rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev,
 	const int phymode)
 {
+	struct ieee80211_hw_mode *mode;
 	struct ieee80211_rate *rate;
 
 	/*
@@ -658,8 +659,10 @@ static void rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev,
 	if (rt2x00dev->rx_status.phymode == phymode)
 		return;
 
-	rate = &rt2x00dev->hwmodes[0].rates[
-		rt2x00dev->hwmodes[0].num_rates - 1];
+	rt2x00dev->curr_hwmode = HWMODE_B;
+
+	mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode];
+	rate = &mode->rates[mode->num_rates - 1];
 
 	rt2400pci_config_rate(rt2x00dev, rate->val2);
 
@@ -2666,6 +2669,10 @@ static void rt2400pci_init_hw_rates(struct rt2x00_dev *rt2x00dev,
 
 static int rt2400pci_init_hw_modes(struct rt2x00_dev *rt2x00dev)
 {
+	struct ieee80211_channel *channels;
+	struct ieee80211_rate *rates;
+	int status = -ENOMEM;
+
 	/*
 	 * RT2400 only supports 802.11b.
 	 * Allocate memory for 14 OFDM channels and 4 CCK rates.
@@ -2675,43 +2682,59 @@ static int rt2400pci_init_hw_modes(struct rt2x00_dev *rt2x00dev)
 	if (!rt2x00dev->hwmodes)
 		goto exit;
 
-	rt2x00dev->hwmodes[0].num_channels = 14;
-	rt2x00dev->hwmodes[0].channels =
-		kzalloc(sizeof(struct ieee80211_channel) * 14, GFP_KERNEL);
-	if (!rt2x00dev->hwmodes[0].channels)
+	channels = kzalloc(sizeof(struct ieee80211_channel) * 14,
+		GFP_KERNEL);
+	if (!channels)
 		goto exit_free_modes;
 
-	rt2x00dev->hwmodes[0].num_rates = 4;
-	rt2x00dev->hwmodes[0].rates =
-		kzalloc(sizeof(struct ieee80211_rate) * 4, GFP_KERNEL);
-	if (!rt2x00dev->hwmodes[0].rates)
+	rates = kzalloc(sizeof(struct ieee80211_rate) * 4, GFP_KERNEL);
+	if (!rates)
 		goto exit_free_channels;
 
 	/*
-	 * Initialize modes.
+	 * Initialize channels and rate arrays.
+	 */
+	rt2400pci_init_hw_channels(rt2x00dev, channels);
+	rt2400pci_init_hw_rates(rt2x00dev, rates);
+
+	/*
+	 * Intitialize 802.11b
+	 * Rates: CCK.
+	 * Channels: OFDM.
 	 */
-	rt2x00dev->hwmodes[0].mode = MODE_IEEE80211B;
+	rt2x00dev->hwmodes[HWMODE_B].mode = MODE_IEEE80211B;
+	rt2x00dev->hwmodes[HWMODE_B].num_channels = 14;
+	rt2x00dev->hwmodes[HWMODE_B].num_rates = 4;
+	rt2x00dev->hwmodes[HWMODE_B].channels = channels;
+	rt2x00dev->hwmodes[HWMODE_B].rates = rates;
 
-	rt2400pci_init_hw_channels(rt2x00dev, rt2x00dev->hwmodes[0].channels);
-	rt2400pci_init_hw_rates(rt2x00dev, rt2x00dev->hwmodes[0].rates);
+	/*
+	 * Register the working modes.
+	 */
+	status = ieee80211_register_hwmode(rt2x00dev->hw,
+		&rt2x00dev->hwmodes[HWMODE_B]);
+	if (status)
+		goto exit_free_rates;
 
 	return 0;
 
+exit_free_rates:
+	kfree(rates);
+
 exit_free_channels:
-	kfree(rt2x00dev->hwmodes[0].channels);
-	rt2x00dev->hwmodes[0].channels = NULL;
+	kfree(channels);
 
 exit_free_modes:
 	kfree(rt2x00dev->hwmodes);
+	rt2x00dev->hwmodes = NULL;
 
 exit:
 	ERROR("Allocation ieee80211 modes failed.\n");
-	return -ENOMEM;
+	return status;
 }
 
 static int rt2400pci_init_hw(struct rt2x00_dev *rt2x00dev)
 {
-	int err;
 	int status;
 
 	if (GET_FLAG(rt2x00dev, DEVICE_INITIALIZED_HW))
@@ -2737,18 +2760,16 @@ static int rt2400pci_init_hw(struct rt2x00_dev *rt2x00dev)
 		IEEE80211_HW_MONITOR_DURING_OPER;
 	rt2x00dev->hw->extra_tx_headroom = 0;
 	rt2x00dev->hw->max_rssi = MAX_RX_SSI;
+	rt2x00dev->hw->max_noise = MAX_RX_NOISE;
 	rt2x00dev->hw->queues = RING_NUM_TX;
 
-	status = rt2400pci_init_hw_modes(rt2x00dev);
-	if (status)
-		return status;
-
 	if (ieee80211_register_hw(rt2x00dev->hw))
 		return -EIO;
-	err = ieee80211_register_hwmode(rt2x00dev->hw, &rt2x00dev->hwmodes[0]);
-	if (err) {
+
+	status = rt2400pci_init_hw_modes(rt2x00dev);
+	if (status) {
 		ieee80211_unregister_hw(rt2x00dev->hw);
-		return err;
+		return status;
 	}
 
 	SET_FLAG(rt2x00dev, DEVICE_INITIALIZED_HW);
@@ -2794,9 +2815,10 @@ static void rt2400pci_free_dev(struct rt2x00_dev *rt2x00dev)
 	 * Free ieee80211_hw memory.
 	 */
 	if (likely(rt2x00dev->hwmodes)) {
-		kfree(rt2x00dev->hwmodes[0].channels);
-		kfree(rt2x00dev->hwmodes[0].rates);
+		kfree(rt2x00dev->hwmodes->channels);
+		kfree(rt2x00dev->hwmodes->rates);
 		kfree(rt2x00dev->hwmodes);
+		rt2x00dev->hwmodes = NULL;
 	}
 }
 
drivers/net/wireless/mac80211/rt2x00/rt2400pci.h +1 -0
index 6e20d42..489877c 100644
@@ -37,6 +37,7 @@
  * Max RSSI value, required for RSSI <-> dBm conversion.
  */
 #define MAX_RX_SSI			100
+#define MAX_RX_NOISE			-110
 
 /*
  * Register layout information.
drivers/net/wireless/mac80211/rt2x00/rt2500pci.c +76 -55

217 lines not on this page · raw message

drivers/net/wireless/mac80211/rt2x00/rt2500usb.c +87 -58

245 lines not on this page · raw message

drivers/net/wireless/mac80211/rt2x00/rt61pci.c +78 -60

220 lines not on this page · raw message

drivers/net/wireless/mac80211/rt2x00/rt73usb.c +77 -59

229 lines not on this page · raw message