From fda53ca869881135d3e9cccad121fb87821f9a67 Mon Sep 17 00:00:00 2001 From: Kevin Lo Date: Wed, 23 Aug 2017 09:25:18 +0000 Subject: Fix up rssi calculations and r88e_rx_cck structure for RTL8188EU. Tested with TL-WN725N v2 (rtl8188eu) on amd64. ok stsp@ --- sys/dev/ic/r92creg.h | 26 ++++++++-------- sys/dev/ic/rtwn.c | 81 +++++++++++++++++--------------------------------- sys/dev/usb/if_urtwn.c | 5 ++-- 3 files changed, 44 insertions(+), 68 deletions(-) diff --git a/sys/dev/ic/r92creg.h b/sys/dev/ic/r92creg.h index 047fdd7df5b..3e1b40a5002 100644 --- a/sys/dev/ic/r92creg.h +++ b/sys/dev/ic/r92creg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: r92creg.h,v 1.13 2017/08/16 01:26:46 kevlo Exp $ */ +/* $OpenBSD: r92creg.h,v 1.14 2017/08/23 09:25:17 kevlo Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini @@ -1157,22 +1157,23 @@ struct r88e_tx_rpt_ccx { uint8_t rptb7; } __packed; -struct r88e_rx_cck { +struct r88e_rx_phystat { uint8_t path_agc[2]; - uint8_t sig_qual; + uint8_t ch_corr[2]; + uint8_t sq_rpt; uint8_t agc_rpt; uint8_t rpt_b; uint8_t reserved1; uint8_t noise_power; - uint8_t path_cfotail[2]; + int8_t path_cfotail[2]; uint8_t pcts_mask[2]; - uint8_t stream_rxevm[2]; + int8_t stream_rxevm[2]; uint8_t path_rxsnr[2]; uint8_t noise_power_db_lsb; uint8_t reserved2[3]; uint8_t stream_csi[2]; uint8_t stream_target_csi[2]; - uint8_t sig_evm; + int8_t sig_evm; uint8_t reserved3; uint8_t reserved4; } __packed; @@ -1222,6 +1223,12 @@ struct r92c_rx_desc_usb { #define R92C_RXDW3_RATE_S 0 #define R92C_RXDW3_HT 0x00000040 #define R92C_RXDW3_HTC 0x00000400 +#define R88E_RXDW3_RPT_M 0x0000c000 +#define R88E_RXDW3_RPT_S 14 +#define R88E_RXDW3_RPT_RX 0 +#define R88E_RXDW3_RPT_TX1 1 +#define R88E_RXDW3_RPT_TX2 2 +#define R88E_RXDW3_RPT_HIS 3 /* Tx MAC descriptor. */ @@ -1294,13 +1301,6 @@ struct r92c_tx_desc_usb { #define R88E_TXDW2_AGGBK 0x00010000 #define R92C_TXDW2_CCX_RPT 0x00080000 -#define R88E_RXDW3_RPT_M 0x0000c000 -#define R88E_RXDW3_RPT_S 14 -#define R88E_RXDW3_RPT_RX 0 -#define R88E_RXDW3_RPT_TX1 1 -#define R88E_RXDW3_RPT_TX2 2 -#define R88E_RXDW3_RPT_HIS 3 - #define R92C_TXDW4_RTSRATE_M 0x0000001f #define R92C_TXDW4_RTSRATE_S 0 #define R92C_TXDW4_QOS 0x00000040 diff --git a/sys/dev/ic/rtwn.c b/sys/dev/ic/rtwn.c index 748cbcb22a3..f2f94e0c4bc 100644 --- a/sys/dev/ic/rtwn.c +++ b/sys/dev/ic/rtwn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtwn.c,v 1.32 2017/08/21 03:02:54 jsg Exp $ */ +/* $OpenBSD: rtwn.c,v 1.33 2017/08/23 09:25:17 kevlo Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini @@ -1236,19 +1236,21 @@ rtwn_update_avgrssi(struct rtwn_softc *sc, int rate, int8_t rssi) pwdb = 100; else pwdb = 100 + rssi; - if (rate <= 3) { - /* CCK gain is smaller than OFDM/MCS gain. */ - pwdb += 6; - if (pwdb > 100) - pwdb = 100; - if (pwdb <= 14) - pwdb -= 4; - else if (pwdb <= 26) - pwdb -= 8; - else if (pwdb <= 34) - pwdb -= 6; - else if (pwdb <= 42) - pwdb -= 2; + if (sc->chip & (RTWN_CHIP_92C | RTWN_CHIP_88C)) { + if (rate <= 3) { + /* CCK gain is smaller than OFDM/MCS gain. */ + pwdb += 6; + if (pwdb > 100) + pwdb = 100; + if (pwdb <= 14) + pwdb -= 4; + else if (pwdb <= 26) + pwdb -= 8; + else if (pwdb <= 34) + pwdb -= 6; + else if (pwdb <= 42) + pwdb -= 2; + } } if (sc->avg_pwdb == -1) /* Init. */ sc->avg_pwdb = pwdb; @@ -1291,50 +1293,23 @@ rtwn_get_rssi(struct rtwn_softc *sc, int rate, void *physt) int8_t rtwn_r88e_get_rssi(struct rtwn_softc *sc, int rate, void *physt) { - struct r92c_rx_phystat *phy; - struct r88e_rx_cck *cck; - uint8_t cck_agc_rpt, lna_idx, vga_idx; + static const int8_t cckoff[] = { 20, 14, 10, -4, -16, -22, -38, -40 }; + struct r88e_rx_phystat *phy; + uint8_t rpt; int8_t rssi; - rssi = 0; + phy = (struct r88e_rx_phystat *)physt; + if (rate <= 3) { - cck = (struct r88e_rx_cck *)physt; - cck_agc_rpt = cck->agc_rpt; - lna_idx = (cck_agc_rpt & 0xe0) >> 5; - vga_idx = cck_agc_rpt & 0x1f; - switch (lna_idx) { - case 7: - if (vga_idx <= 27) - rssi = -100 + 2* (27 - vga_idx); - else - rssi = -100; - break; - case 6: - rssi = -48 + 2 * (2 - vga_idx); - break; - case 5: - rssi = -42 + 2 * (7 - vga_idx); - break; - case 4: - rssi = -36 + 2 * (7 - vga_idx); - break; - case 3: - rssi = -24 + 2 * (7 - vga_idx); - break; - case 2: - rssi = -12 + 2 * (5 - vga_idx); - break; - case 1: - rssi = 8 - (2 * vga_idx); - break; - case 0: - rssi = 14 - (2 * vga_idx); - break; + rpt = (phy->agc_rpt >> 5) & 0x7; + rssi = (phy->agc_rpt & 0x1f) << 1; + if (sc->sc_flags & RTWN_FLAG_CCK_HIPWR) { + if (rpt == 2) + rssi -= 6; } - rssi += 6; + rssi = (phy->agc_rpt & 0x1f) > 27 ? -94 : cckoff[rpt] - rssi; } else { /* OFDM/HT. */ - phy = (struct r92c_rx_phystat *)physt; - rssi = ((le32toh(phy->phydw1) >> 1) & 0x7f) - 110; + rssi = ((le32toh(phy->sq_rpt) >> 1) & 0x7f) - 110; } return (rssi); } diff --git a/sys/dev/usb/if_urtwn.c b/sys/dev/usb/if_urtwn.c index 74bb18c6559..e6e9cbd670e 100644 --- a/sys/dev/usb/if_urtwn.c +++ b/sys/dev/usb/if_urtwn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urtwn.c,v 1.74 2017/08/16 01:26:46 kevlo Exp $ */ +/* $OpenBSD: if_urtwn.c,v 1.75 2017/08/23 09:25:17 kevlo Exp $ */ /*- * Copyright (c) 2010 Damien Bergamini @@ -1126,7 +1126,6 @@ urtwn_rx_frame(struct urtwn_softc *sc, uint8_t *buf, int pktlen) tap->wr_flags = 0; /* Map HW rate index to 802.11 rate. */ - tap->wr_flags = 2; if (!(rxdw3 & R92C_RXDW3_HT)) { switch (rate) { /* CCK. */ @@ -1144,6 +1143,8 @@ urtwn_rx_frame(struct urtwn_softc *sc, uint8_t *buf, int pktlen) case 10: tap->wr_rate = 96; break; case 11: tap->wr_rate = 108; break; } + if (rate <= 3) + tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; } else if (rate >= 12) { /* MCS0~15. */ /* Bit 7 set means HT MCS instead of rate. */ tap->wr_rate = 0x80 | (rate - 12); -- cgit v1.2.3