From owner-p4-projects@FreeBSD.ORG Sat May 17 20:49:58 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2F0E0106567B; Sat, 17 May 2008 20:49:58 +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 E8F34106564A for ; Sat, 17 May 2008 20:49:57 +0000 (UTC) (envelope-from thompsa@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id D774C8FC27 for ; Sat, 17 May 2008 20:49:57 +0000 (UTC) (envelope-from thompsa@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 m4HKnvds026859 for ; Sat, 17 May 2008 20:49:57 GMT (envelope-from thompsa@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m4HKnuio026857 for perforce@freebsd.org; Sat, 17 May 2008 20:49:56 GMT (envelope-from thompsa@freebsd.org) Date: Sat, 17 May 2008 20:49:56 GMT Message-Id: <200805172049.m4HKnuio026857@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to thompsa@freebsd.org using -f From: Andrew Thompson To: Perforce Change Reviews Cc: Subject: PERFORCE change 141785 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: Sat, 17 May 2008 20:49:58 -0000 http://perforce.freebsd.org/chv.cgi?CH=141785 Change 141785 by thompsa@thompsa_burger on 2008/05/17 20:49:08 Calculate the noise floor supplied from the hardware. Info from: http://bcm-specs.sipsolutions.net/ Affected files ... .. //depot/projects/vap/sys/dev/bwi/bwirf.c#6 edit .. //depot/projects/vap/sys/dev/bwi/bwirf.h#4 edit .. //depot/projects/vap/sys/dev/bwi/if_bwi.c#22 edit .. //depot/projects/vap/sys/dev/bwi/if_bwireg.h#2 edit .. //depot/projects/vap/sys/dev/bwi/if_bwivar.h#10 edit Differences ... ==== //depot/projects/vap/sys/dev/bwi/bwirf.c#6 (text+ko) ==== @@ -137,6 +137,9 @@ const struct bwi_rxbuf_hdr *); static int bwi_rf_calc_rssi_bcm2060(struct bwi_mac *, const struct bwi_rxbuf_hdr *); +static int bwi_rf_calc_noise_bcm2050(struct bwi_mac *); +static int bwi_rf_calc_noise_bcm2053(struct bwi_mac *); +static int bwi_rf_calc_noise_bcm2060(struct bwi_mac *); static void bwi_rf_on_11a(struct bwi_mac *); static void bwi_rf_on_11bg(struct bwi_mac *); @@ -275,14 +278,17 @@ rf->rf_on = bwi_rf_on_11a; rf->rf_off = bwi_rf_off_11a; rf->rf_calc_rssi = bwi_rf_calc_rssi_bcm2060; + rf->rf_calc_noise = bwi_rf_calc_noise_bcm2060; break; case IEEE80211_MODE_11B: if (type == BWI_RF_T_BCM2050) { rf->rf_ctrl_rd = BWI_RF_CTRL_RD_11BG; rf->rf_calc_rssi = bwi_rf_calc_rssi_bcm2050; + rf->rf_calc_noise = bwi_rf_calc_noise_bcm2050; } else if (type == BWI_RF_T_BCM2053) { rf->rf_ctrl_adj = 1; rf->rf_calc_rssi = bwi_rf_calc_rssi_bcm2053; + rf->rf_calc_noise = bwi_rf_calc_noise_bcm2053; } else { device_printf(sc->sc_dev, "only BCM2050/BCM2053 RF " "is supported for 11B PHY\n"); @@ -312,6 +318,7 @@ rf->rf_calc_nrssi_slope = bwi_rf_calc_nrssi_slope_11g; rf->rf_set_nrssi_thr = bwi_rf_set_nrssi_thr_11g; rf->rf_calc_rssi = bwi_rf_calc_rssi_bcm2050; + rf->rf_calc_noise = bwi_rf_calc_noise_bcm2050; rf->rf_lo_update = bwi_rf_lo_update_11g; break; default: @@ -2532,6 +2539,51 @@ return rssi; } +static int +bwi_rf_calc_noise_bcm2050(struct bwi_mac *mac) +{ + uint16_t val; + int noise; + + val = MOBJ_READ_2(mac, BWI_COMM_MOBJ, BWI_COMM_MOBJ_RF_NOISE); + noise = (int)val; /* XXX check bounds? */ + + if (mac->mac_sc->sc_card_flags & BWI_CARD_F_SW_NRSSI) { + struct bwi_rf *rf = &mac->mac_rf; + + if (noise >= BWI_NRSSI_TBLSZ) + noise = BWI_NRSSI_TBLSZ - 1; + + noise = ((31 - (int)rf->rf_nrssi_table[noise]) * -131) / 128; + noise -= 67; + } else { + noise = ((31 - noise) * -149) / 128; + noise -= 68; + } + return noise; +} + +static int +bwi_rf_calc_noise_bcm2053(struct bwi_mac *mac) +{ + uint16_t val; + int noise; + + val = MOBJ_READ_2(mac, BWI_COMM_MOBJ, BWI_COMM_MOBJ_RF_NOISE); + noise = (int)val; /* XXX check bounds? */ + + noise = ((noise - 11) * 103) / 64; + noise -= 109; + return noise; +} + +static int +bwi_rf_calc_noise_bcm2060(struct bwi_mac *mac) +{ + /* XXX Dont know how to calc */ + return (BWI_NOISE_FLOOR); +} + static uint16_t bwi_rf_lo_measure_11b(struct bwi_mac *mac) { ==== //depot/projects/vap/sys/dev/bwi/bwirf.h#4 (text+ko) ==== @@ -95,6 +95,12 @@ return _mac->mac_rf.rf_calc_rssi(_mac, _hdr); } +static __inline int +bwi_rf_calc_noise(struct bwi_mac *_mac) +{ + return _mac->mac_rf.rf_calc_noise(_mac); +} + static __inline void bwi_rf_lo_update(struct bwi_mac *_mac) { ==== //depot/projects/vap/sys/dev/bwi/if_bwi.c#22 (text+ko) ==== @@ -119,10 +119,11 @@ static void bwi_calibrate(void *); static int bwi_calc_rssi(struct bwi_softc *, const struct bwi_rxbuf_hdr *); +static int bwi_calc_noise(struct bwi_softc *); static __inline uint8_t bwi_ofdm_plcp2rate(const uint32_t *); static __inline uint8_t bwi_ds_plcp2rate(const struct ieee80211_ds_plcp_hdr *); static void bwi_rx_radiotap(struct ifnet *, struct mbuf *, - struct bwi_rxbuf_hdr *, const void *, int, int); + struct bwi_rxbuf_hdr *, const void *, int, int, int); static void bwi_restart(void *, int); static void bwi_init_statechg(struct bwi_softc *, int); @@ -2639,7 +2640,7 @@ struct mbuf *m; const void *plcp; uint16_t flags2; - int buflen, wh_ofs, hdr_extra, rssi, type, rate; + int buflen, wh_ofs, hdr_extra, rssi, noise, type, rate; m = rb->rb_mbuf; bus_dmamap_sync(sc->sc_buf_dtag, rb->rb_dmap, @@ -2669,6 +2670,7 @@ plcp = ((const uint8_t *)(hdr + 1) + hdr_extra); rssi = bwi_calc_rssi(sc, hdr); + noise = bwi_calc_noise(sc); m->m_pkthdr.rcvif = ifp; m->m_len = m->m_pkthdr.len = buflen + sizeof(*hdr); @@ -2681,7 +2683,7 @@ /* RX radio tap */ if (bpf_peers_present(ifp->if_bpf)) - bwi_rx_radiotap(ifp, m, hdr, plcp, rate, rssi); + bwi_rx_radiotap(ifp, m, hdr, plcp, rate, rssi, noise); m_adj(m, -IEEE80211_CRC_LEN); @@ -2690,12 +2692,11 @@ wh = mtod(m, struct ieee80211_frame_min *); ni = ieee80211_find_rxnode(ic, wh); if (ni != NULL) { - type = ieee80211_input(ni, m, rssi - BWI_NOISE_FLOOR, - BWI_NOISE_FLOOR, 0); + type = ieee80211_input(ni, m, rssi - noise, noise, 0); ieee80211_free_node(ni); } else - type = ieee80211_input_all(ic, m, - rssi - BWI_NOISE_FLOOR, BWI_NOISE_FLOOR, 0); + type = ieee80211_input_all(ic, m, rssi - noise, + noise, 0); if (type == IEEE80211_FC0_TYPE_DATA) { rx_data = 1; sc->sc_rx_rate = rate; @@ -3783,6 +3784,18 @@ return bwi_rf_calc_rssi(mac, hdr); } +static int +bwi_calc_noise(struct bwi_softc *sc) +{ + struct bwi_mac *mac; + + KASSERT(sc->sc_cur_regwin->rw_type == BWI_REGWIN_T_MAC, + ("current regwin type %d", sc->sc_cur_regwin->rw_type)); + mac = (struct bwi_mac *)sc->sc_cur_regwin; + + return bwi_rf_calc_noise(mac); +} + static __inline uint8_t bwi_ofdm_plcp2rate(const uint32_t *plcp0) { @@ -3802,7 +3815,7 @@ static void bwi_rx_radiotap(struct ifnet *ifp, struct mbuf *m, - struct bwi_rxbuf_hdr *hdr, const void *plcp, int rate, int rssi) + struct bwi_rxbuf_hdr *hdr, const void *plcp, int rate, int rssi, int noise) { struct bwi_softc *sc = ifp->if_softc; const struct ieee80211_frame_min *wh; @@ -3818,7 +3831,7 @@ sc->sc_rx_th.wr_tsf = hdr->rxh_tsf; /* No endian convertion */ sc->sc_rx_th.wr_rate = rate; sc->sc_rx_th.wr_antsignal = rssi; - sc->sc_rx_th.wr_antnoise = BWI_NOISE_FLOOR; + sc->sc_rx_th.wr_antnoise = noise; bpf_mtap2(ifp->if_bpf, &sc->sc_rx_th, sc->sc_rx_th_len, m); } ==== //depot/projects/vap/sys/dev/bwi/if_bwireg.h#2 (text+ko) ==== @@ -203,6 +203,7 @@ #define BWI_COMM_MOBJ_HFLAGS_MI 0x60 #define BWI_COMM_MOBJ_HFLAGS_HI 0x62 #define BWI_COMM_MOBJ_RF_ATTEN 0x64 +#define BWI_COMM_MOBJ_RF_NOISE 0x6e #define BWI_COMM_MOBJ_TSSI_OFDM 0x70 #define BWI_COMM_MOBJ_PROBE_RESP_TO 0x74 #define BWI_COMM_MOBJ_CHAN 0xa0 ==== //depot/projects/vap/sys/dev/bwi/if_bwivar.h#10 (text+ko) ==== @@ -419,6 +419,7 @@ int (*rf_calc_rssi) (struct bwi_mac *, const struct bwi_rxbuf_hdr *); + int (*rf_calc_noise)(struct bwi_mac *); void (*rf_lo_update)(struct bwi_mac *);