From owner-p4-projects@FreeBSD.ORG Sun Mar 16 17:56:56 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3BED91065689; Sun, 16 Mar 2008 17:56:56 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EDE7C1065680 for ; Sun, 16 Mar 2008 17:56:55 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B704E8FC35 for ; Sun, 16 Mar 2008 17:56:55 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m2GHutjO004113 for ; Sun, 16 Mar 2008 17:56:55 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m2GHutZY004111 for perforce@freebsd.org; Sun, 16 Mar 2008 17:56:55 GMT (envelope-from sam@freebsd.org) Date: Sun, 16 Mar 2008 17:56:55 GMT Message-Id: <200803161756.m2GHutZY004111@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 137849 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Mar 2008 17:56:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=137849 Change 137849 by sam@sam_ebb on 2008/03/16 17:56:51 blindly convert to use common phy support routines Affected files ... .. //depot/projects/vap/sys/dev/usb/if_rum.c#12 edit .. //depot/projects/vap/sys/dev/usb/if_rumvar.h#8 edit Differences ... ==== //depot/projects/vap/sys/dev/usb/if_rum.c#12 (text+ko) ==== @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -143,10 +144,6 @@ usbd_status); static void rum_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status); -static int rum_rxrate(struct rum_rx_desc *); -static int rum_ack_rate(struct ieee80211com *, int); -static uint16_t rum_txtime(int, int, uint32_t); -static uint8_t rum_plcp_signal(int); static void rum_setup_tx_desc(struct rum_softc *, struct rum_tx_desc *, uint32_t, uint16_t, int, int); @@ -524,6 +521,8 @@ ic->ic_vap_create = rum_vap_create; ic->ic_vap_delete = rum_vap_delete; + sc->sc_rates = ieee80211_get_ratetable(ic->ic_curchan); + bpfattach(ifp, DLT_IEEE802_11_RADIO, sizeof (struct ieee80211_frame) + sizeof(sc->sc_txtap)); @@ -831,12 +830,6 @@ } } -/* quickly determine if a given rate is CCK or OFDM */ -#define RUM_RATE_IS_OFDM(rate) ((rate) >= 12 && (rate) != 22) - -#define RUM_ACK_SIZE 14 /* 10 + 4(FCS) */ -#define RUM_CTS_SIZE 14 /* 10 + 4(FCS) */ - static void rum_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { @@ -939,7 +932,8 @@ struct rum_rx_radiotap_header *tap = &sc->sc_rxtap; tap->wr_flags = IEEE80211_RADIOTAP_F_FCS; - tap->wr_rate = rum_rxrate(desc); + tap->wr_rate = ieee80211_plcp2rate(desc->rate, + le32toh(desc->flags) & RT2573_RX_OFDM); tap->wr_chan_freq = htole16(ic->ic_curchan->ic_freq); tap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags); tap->wr_antenna = sc->rx_ant; @@ -966,120 +960,6 @@ usbd_transfer(xfer); } -/* - * This function is only used by the Rx radiotap code. - */ -static int -rum_rxrate(struct rum_rx_desc *desc) -{ - if (le32toh(desc->flags) & RT2573_RX_OFDM) { - /* reverse function of rum_plcp_signal */ - switch (desc->rate) { - case 0xb: return 12; - case 0xf: return 18; - case 0xa: return 24; - case 0xe: return 36; - case 0x9: return 48; - case 0xd: return 72; - case 0x8: return 96; - case 0xc: return 108; - } - } else { - if (desc->rate == 10) - return 2; - if (desc->rate == 20) - return 4; - if (desc->rate == 55) - return 11; - if (desc->rate == 110) - return 22; - } - return 2; /* should not get there */ -} - -/* - * Return the expected ack rate for a frame transmitted at rate `rate'. - */ -static int -rum_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 -rum_txtime(int len, int rate, uint32_t flags) -{ - uint16_t txtime; - - if (RUM_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 -rum_plcp_signal(int rate) -{ - switch (rate) { - /* CCK rates (returned values are device-dependent) */ - case 2: return 0x0; - case 4: return 0x1; - case 11: return 0x2; - case 22: return 0x3; - - /* OFDM rates (cf IEEE Std 802.11a-1999, pp. 14 Table 80) */ - case 12: return 0xb; - case 18: return 0xf; - case 24: return 0xa; - case 36: return 0xe; - case 48: return 0x9; - case 72: return 0xd; - case 96: return 0x8; - case 108: return 0xc; - - /* unsupported rates (should not get there) */ - default: return 0xff; - } -} - static void rum_setup_tx_desc(struct rum_softc *sc, struct rum_tx_desc *desc, uint32_t flags, uint16_t xflags, int len, int rate) @@ -1098,11 +978,11 @@ RT2573_LOGCWMIN(4) | RT2573_LOGCWMAX(10)); /* setup PLCP fields */ - desc->plcp_signal = rum_plcp_signal(rate); + desc->plcp_signal = ieee80211_rate2plcp(rate); desc->plcp_service = 4; len += IEEE80211_CRC_LEN; - if (RUM_RATE_IS_OFDM(rate)) { + if (ieee80211_rate2phytype(sc->sc_rates, rate) == IEEE80211_T_OFDM) { desc->flags |= htole32(RT2573_TX_OFDM); plcp_length = len & 0xfff; @@ -1134,7 +1014,7 @@ struct rum_tx_desc *desc; struct rum_tx_data *data; struct mbuf *mprot; - int protrate, ackrate, pktlen, flags; + int protrate, ackrate, pktlen, flags, isshort; uint16_t dur; usbd_status error; @@ -1144,17 +1024,16 @@ wh = mtod(m, const struct ieee80211_frame *); pktlen = m->m_pkthdr.len + IEEE80211_CRC_LEN; - /* XXX use phy support */ - protrate = 2; - ackrate = rum_ack_rate(ic, rate); + protrate = ieee80211_ctl_rate(sc->sc_rates, rate); + ackrate = ieee80211_ack_rate(sc->sc_rates, rate); - dur = rum_txtime(pktlen, rate, ic->ic_flags) + - rum_txtime(RUM_ACK_SIZE, ackrate, ic->ic_flags) + - 2 * sc->sifs; + isshort = (ic->ic_flags & IEEE80211_F_SHPREAMBLE) != 0; + dur = ieee80211_compute_duration(sc->sc_rates, pktlen, rate, isshort); + + ieee80211_ack_duration(sc->sc_rates, rate, isshort); flags = RT2573_TX_MORE_FRAG; if (prot == IEEE80211_PROT_RTSCTS) { - dur += rum_txtime(RUM_CTS_SIZE, - rum_ack_rate(ic, protrate), ic->ic_flags) + sc->sifs; + /* NB: CTS is the same size as an ACK */ + dur += ieee80211_ack_duration(sc->sc_rates, rate, isshort); flags |= RT2573_TX_NEED_ACK; mprot = ieee80211_alloc_rts(ic, wh->i_addr1, wh->i_addr2, dur); } else { @@ -1169,7 +1048,8 @@ data->m = mprot; data->ni = ieee80211_ref_node(ni); - m_copydata(mprot, 0, mprot->m_pkthdr.len, data->buf + RT2573_TX_DESC_SIZE); + m_copydata(mprot, 0, mprot->m_pkthdr.len, + data->buf + RT2573_TX_DESC_SIZE); rum_setup_tx_desc(sc, desc, flags, 0, mprot->m_pkthdr.len, protrate); usbd_setup_xfer(data->xfer, sc->sc_tx_pipeh, data, data->buf, @@ -1226,8 +1106,8 @@ if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { flags |= RT2573_TX_NEED_ACK; - dur = rum_txtime(RUM_ACK_SIZE, rum_ack_rate(ic, tp->mgmtrate), - ic->ic_flags) + sc->sifs; + dur = ieee80211_ack_duration(sc->sc_rates, tp->mgmtrate, + ic->ic_flags & IEEE80211_F_SHPREAMBLE); *(uint16_t *)wh->i_dur = htole16(dur); /* tell hardware to add timestamp for probe responses */ @@ -1410,7 +1290,7 @@ if (m0->m_pkthdr.len + IEEE80211_CRC_LEN > vap->iv_rtsthreshold) prot = IEEE80211_PROT_RTSCTS; else if ((ic->ic_flags & IEEE80211_F_USEPROT) && - RUM_RATE_IS_OFDM(rate)) + ieee80211_rate2phytype(sc->sc_rates, rate) == IEEE80211_T_OFDM) prot = ic->ic_protmode; if (prot != IEEE80211_PROT_NONE) { error = rum_sendprot(sc, m0, ni, prot, rate); @@ -1432,8 +1312,8 @@ flags |= RT2573_TX_NEED_ACK; flags |= RT2573_TX_MORE_FRAG; - dur = rum_txtime(RUM_ACK_SIZE, rum_ack_rate(ic, rate), - ic->ic_flags) + sc->sifs; + dur = ieee80211_ack_duration(sc->sc_rates, rate, + ic->ic_flags & IEEE80211_F_SHPREAMBLE); *(uint16_t *)wh->i_dur = htole16(dur); } @@ -1839,9 +1719,6 @@ else tmp |= RT2573_PA_PE_5GHZ; rum_write(sc, RT2573_PHY_CSR0, tmp); - - /* 802.11a uses a 16 microseconds short interframe space */ - sc->sifs = IEEE80211_IS_CHAN_5GHZ(c) ? 16 : 10; } static void @@ -2521,6 +2398,8 @@ /* do it in a process context */ sc->sc_scan_action = RUM_SET_CHANNEL; usb_add_task(sc->sc_udev, &sc->sc_scantask, USB_TASKQ_DRIVER); + + sc->sc_rates = ieee80211_get_ratetable(ic->ic_curchan); } static void ==== //depot/projects/vap/sys/dev/usb/if_rumvar.h#8 (text+ko) ==== @@ -89,6 +89,7 @@ struct rum_softc { struct ieee80211com sc_ic; /* NB: must be first */ struct ifnet *sc_ifp; + const struct ieee80211_rate_table *sc_rates; device_t sc_dev; usbd_device_handle sc_udev; @@ -143,7 +144,6 @@ int ext_5ghz_lna; int rssi_2ghz_corr; int rssi_5ghz_corr; - int sifs; uint8_t bbp17; struct rum_rx_radiotap_header sc_rxtap;