Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jan 2008 00:09:39 GMT
From:      Sam Leffler <sam@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 134262 for review
Message-ID:  <200801280009.m0S09d3K066795@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=134262

Change 134262 by sam@sam_ebb on 2008/01/28 00:09:07

	convert as an example of how to use the phy routines

Affected files ...

.. //depot/projects/vap/sys/dev/ral/rt2560.c#9 edit
.. //depot/projects/vap/sys/dev/ral/rt2560var.h#5 edit

Differences ...

==== //depot/projects/vap/sys/dev/ral/rt2560.c#9 (text) ====

@@ -52,6 +52,7 @@
 #include <net/if_types.h>
 
 #include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_phy.h>
 #include <net80211/ieee80211_radiotap.h>
 #include <net80211/ieee80211_regdomain.h>
 
@@ -113,11 +114,9 @@
 static void		rt2560_beacon_expire(struct rt2560_softc *);
 static void		rt2560_wakeup_expire(struct rt2560_softc *);
 static uint8_t		rt2560_rxrate(struct rt2560_rx_desc *);
-static int		rt2560_ack_rate(struct ieee80211com *, int);
 static void		rt2560_scan_start(struct ieee80211com *);
 static void		rt2560_scan_end(struct ieee80211com *);
 static void		rt2560_set_channel(struct ieee80211com *);
-static uint16_t		rt2560_txtime(int, int, uint32_t);
 static uint8_t		rt2560_plcp_signal(int);
 static void		rt2560_setup_tx_desc(struct rt2560_softc *,
 			    struct rt2560_tx_desc *, uint32_t, int, int, int,
@@ -1395,12 +1394,6 @@
 	RAL_UNLOCK(sc);
 }
 
-/* quickly determine if a given rate is CCK or OFDM */
-#define RAL_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22)
-
-#define RAL_ACK_SIZE	14	/* 10 + 4(FCS) */
-#define RAL_CTS_SIZE	14	/* 10 + 4(FCS) */
-
 #define RAL_SIFS		10	/* us */
 
 #define RT2560_TXRX_TURNAROUND	10	/* us */
@@ -1436,66 +1429,6 @@
 	return 2;	/* should not get there */
 }
 
-/*
- * Return the expected ack rate for a frame transmitted at rate `rate'.
- * XXX: this should depend on the destination node basic rate set.
- */
-static int
-rt2560_ack_rate(struct ieee80211com *ic, int rate)
-{
-	switch (rate) {
-	/* CCK rates */
-	case 2:
-		return 2;
-	case 4:
-	case 11:
-	case 22:
-		return (ic->ic_curmode == IEEE80211_MODE_11B) ? 4 : rate;
-
-	/* OFDM rates */
-	case 12:
-	case 18:
-		return 12;
-	case 24:
-	case 36:
-		return 24;
-	case 48:
-	case 72:
-	case 96:
-	case 108:
-		return 48;
-	}
-
-	/* default to 1Mbps */
-	return 2;
-}
-
-/*
- * Compute the duration (in us) needed to transmit `len' bytes at rate `rate'.
- * The function automatically determines the operating mode depending on the
- * given rate. `flags' indicates whether short preamble is in use or not.
- */
-static uint16_t
-rt2560_txtime(int len, int rate, uint32_t flags)
-{
-	uint16_t txtime;
-
-	if (RAL_RATE_IS_OFDM(rate)) {
-		/* IEEE Std 802.11a-1999, pp. 37 */
-		txtime = (8 + 4 * len + 3 + rate - 1) / rate;
-		txtime = 16 + 4 + 4 * txtime + 6;
-	} else {
-		/* IEEE Std 802.11b-1999, pp. 28 */
-		txtime = (16 * len + rate - 1) / rate;
-		if (rate != 2 && (flags & IEEE80211_F_SHPREAMBLE))
-			txtime +=  72 + 24;
-		else
-			txtime += 144 + 48;
-	}
-
-	return txtime;
-}
-
 static uint8_t
 rt2560_plcp_signal(int rate)
 {
@@ -1545,7 +1478,7 @@
 	desc->plcp_service = 4;
 
 	len += IEEE80211_CRC_LEN;
-	if (RAL_RATE_IS_OFDM(rate)) {
+	if (ieee80211_rate2phytype(sc->sc_currates, rate) == IEEE80211_T_OFDM) {
 		desc->flags |= htole32(RT2560_TX_OFDM);
 
 		plcp_length = len & 0xfff;
@@ -1678,8 +1611,8 @@
 	if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
 		flags |= RT2560_TX_ACK;
 
-		dur = rt2560_txtime(RAL_ACK_SIZE, rate, ic->ic_flags) +
-		      RAL_SIFS;
+		dur = ieee80211_ack_duration(sc->sc_currates,
+		    rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE);
 		*(uint16_t *)wh->i_dur = htole16(dur);
 
 		/* tell hardware to add timestamp for probe responses */
@@ -1864,16 +1797,18 @@
 	    m0->m_pkthdr.len > vap->iv_rtsthreshold) {
 		struct mbuf *m;
 		uint16_t dur;
-		int rtsrate, ackrate;
+		int rtsrate;
 
-		rtsrate = IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan) ? 12 : 2;
-		ackrate = rt2560_ack_rate(ic, rate);
+		rtsrate = ieee80211_ack_rate(sc->sc_currates, rate);
+		dur = ieee80211_compute_duration(sc->sc_currates,
+		    m0->m_pkthdr.len + IEEE80211_CRC_LEN,
+		    rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE);
+		/* NB: assumes ACK and CTS are the same size */
+		dur += ieee80211_ack_duration(sc->sc_currates,
+		    rtsrate, ic->ic_flags & IEEE80211_F_SHPREAMBLE);
+		dur += ieee80211_ack_duration(sc->sc_currates,
+		    rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE);
 
-		dur = rt2560_txtime(m0->m_pkthdr.len + 4, rate, ic->ic_flags) +
-		      rt2560_txtime(RAL_CTS_SIZE, rtsrate, ic->ic_flags) +
-		      rt2560_txtime(RAL_ACK_SIZE, ackrate, ic->ic_flags) +
-		      3 * RAL_SIFS;
-
 		m = rt2560_get_rts(sc, wh, dur);
 
 		desc = &sc->txq.desc[sc->txq.cur_encrypt];
@@ -1979,8 +1914,8 @@
 	if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
 		flags |= RT2560_TX_ACK;
 
-		dur = rt2560_txtime(RAL_ACK_SIZE, rt2560_ack_rate(ic, rate),
-		    ic->ic_flags) + RAL_SIFS;
+		dur = ieee80211_ack_duration(sc->sc_currates,
+		    rate, ic->ic_flags & IEEE80211_F_SHPREAMBLE);
 		*(uint16_t *)wh->i_dur = htole16(dur);
 	}
 
@@ -2165,8 +2100,9 @@
 	u_int i, chan;
 
 	chan = ieee80211_chan2ieee(ic, c);
-	if (chan == 0 || chan == IEEE80211_CHAN_ANY)
-		return;
+	KASSERT(chan != 0 && chan != IEEE80211_CHAN_ANY, ("chan 0x%x", chan));
+
+	sc->sc_currates = ieee80211_get_ratetable(c);
 
 	if (IEEE80211_IS_CHAN_2GHZ(c))
 		power = min(sc->txpow[chan - 1], 31);

==== //depot/projects/vap/sys/dev/ral/rt2560var.h#5 (text) ====

@@ -120,6 +120,8 @@
 
 	int			sc_tx_timer;
 	int                     sc_invalid;
+
+	const struct ieee80211_rate_table *sc_currates;
 /*
  * The same in both up to here
  * ------------------------------------------------



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801280009.m0S09d3K066795>