PERFORCE change 127083 for review

Andrew Thompson thompsa at FreeBSD.org
Mon Oct 1 19:58:08 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=127083

Change 127083 by thompsa at thompsa_heff on 2007/10/02 02:57:19

	Simplify ipw_media_status() rate conversion.
	
	Obtained from:	sam

Affected files ...

.. //depot/projects/wifi/sys/dev/ipw/if_ipw.c#31 edit

Differences ...

==== //depot/projects/wifi/sys/dev/ipw/if_ipw.c#31 (text+ko) ====

@@ -779,6 +779,18 @@
 	return (error);
 }
 
+static int
+ipw_cvtrate(int ipwrate)
+{
+	switch (ipwrate) {
+	case IPW_RATE_DS1:	return 2;
+	case IPW_RATE_DS2:	return 4;
+	case IPW_RATE_DS5:	return 11;
+	case IPW_RATE_DS11:	return 22;
+	}
+	return 0;
+}
+
 /*
  * The firmware automatically adapts the transmit speed. We report its current
  * value here.
@@ -786,20 +798,9 @@
 static void
 ipw_media_status(struct ifnet *ifp, struct ifmediareq *imr)
 {
-#define N(a)	(sizeof (a) / sizeof (a[0]))
 	struct ipw_softc *sc = ifp->if_softc;
 	struct ieee80211com *ic = &sc->sc_ic;
-	static const struct {
-		uint32_t	val;
-		int		rate;
-	} rates[] = {
-		{ IPW_RATE_DS1,   2 },
-		{ IPW_RATE_DS2,   4 },
-		{ IPW_RATE_DS5,  11 },
-		{ IPW_RATE_DS11, 22 },
-	};
-	uint32_t val;
-	int rate, i;
+	int rate;
 
 	imr->ifm_status = IFM_AVALID;
 	imr->ifm_active = IFM_IEEE80211;
@@ -807,14 +808,9 @@
 		imr->ifm_status |= IFM_ACTIVE;
 
 	/* read current transmission rate from adapter */
-	val = ipw_read_table1(sc, IPW_INFO_CURRENT_TX_RATE) & 0xf;
-
-	/* convert ipw rate to 802.11 rate */
-	for (i = 0; i < N(rates) && rates[i].val != val; i++);
-	rate = (i < N(rates)) ? rates[i].rate : 0;
+	rate = ipw_cvtrate(ipw_read_table1(sc, IPW_INFO_CURRENT_TX_RATE) & 0xf);
+	imr->ifm_active |= ieee80211_rate2media(ic, rate, IEEE80211_MODE_11B);
 
-	imr->ifm_active |= IFM_IEEE80211_11B;
-	imr->ifm_active |= ieee80211_rate2media(ic, rate, IEEE80211_MODE_11B);
 	switch (ic->ic_opmode) {
 	case IEEE80211_M_STA:
 		break;
@@ -833,7 +829,6 @@
 		/* should not get there */
 		break;
 	}
-#undef N
 }
 
 static int


More information about the p4-projects mailing list