summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkevlo <kevlo@openbsd.org>2017-09-22 13:41:56 +0000
committerkevlo <kevlo@openbsd.org>2017-09-22 13:41:56 +0000
commit56fbb35b9322390248de712115131c10340e5aca (patch)
tree9c3efc558e263c241a8fd3f738aceb544ed2b02c
parentRemove unused code. (diff)
downloadwireguard-openbsd-56fbb35b9322390248de712115131c10340e5aca.tar.xz
wireguard-openbsd-56fbb35b9322390248de712115131c10340e5aca.zip
- Fix short preamble for rtl8188eu
- Use R92C_MSR rather than R92C_CR to set media status - Replace magic numbers with something more readable ok stsp@
-rw-r--r--sys/dev/ic/r92creg.h34
-rw-r--r--sys/dev/ic/rtwn.c79
2 files changed, 87 insertions, 26 deletions
diff --git a/sys/dev/ic/r92creg.h b/sys/dev/ic/r92creg.h
index 1dd13cdd00c..14bd44da72d 100644
--- a/sys/dev/ic/r92creg.h
+++ b/sys/dev/ic/r92creg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: r92creg.h,v 1.15 2017/09/03 16:20:09 stsp Exp $ */
+/* $OpenBSD: r92creg.h,v 1.16 2017/09/22 13:41:56 kevlo Exp $ */
/*-
* Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
@@ -75,6 +75,7 @@
#define R92C_SYS_CFG 0x0f0
/* MAC General Configuration. */
#define R92C_CR 0x100
+#define R92C_MSR 0x102
#define R92C_PBP 0x104
#define R92C_TRXDMA_CTRL 0x10c
#define R92C_TRXFF_BNDY 0x114
@@ -223,6 +224,7 @@
#define R92C_RESP_SIFS_CCK 0x63c
#define R92C_RESP_SIFS_OFDM 0x63e
#define R92C_ACKTO 0x640
+#define R92C_WMAC_TRXPTCL_CTL 0x668
#define R92C_CAMCMD 0x670
#define R92C_CAMWRITE 0x674
#define R92C_CAMREAD 0x678
@@ -417,12 +419,13 @@
#define R92C_CR_MACRXEN 0x00000080
#define R92C_CR_ENSEC 0x00000200
#define R92C_CR_CALTMR_EN 0x00000400
-#define R92C_CR_NETTYPE_S 16
-#define R92C_CR_NETTYPE_M 0x00030000
-#define R92C_CR_NETTYPE_NOLINK 0
-#define R92C_CR_NETTYPE_ADHOC 1
-#define R92C_CR_NETTYPE_INFRA 2
-#define R92C_CR_NETTYPE_AP 3
+
+/* Bits for R92C_MSR. */
+#define R92C_MSR_NETTYPE_NOLINK 0x00
+#define R92C_MSR_NETTYPE_ADHOC 0x01
+#define R92C_MSR_NETTYPE_INFRA 0x02
+#define R92C_MSR_NETTYPE_AP 0x03
+#define R92C_MSR_NETTYPE_MASK 0x03
/* Bits for R92C_PBP. */
#define R92C_PBP_PSRX_M 0x0f
@@ -537,6 +540,15 @@
#define R92C_TXPAUSE_AC_VI 0x02
#define R92C_TXPAUSE_AC_BE 0x04
#define R92C_TXPAUSE_AC_BK 0x08
+#define R92C_TXPAUSE_MGNT 0x10
+#define R92C_TXPAUSE_HIGH 0x20
+#define R92C_TXPAUSE_BCN 0x40
+#define R92C_TXPAUSE_BCN_HIGH_MGNT 0x80
+
+#define R92C_TXPAUSE_ALL (R92C_TXPAUSE_AC_VO | R92C_TXPAUSE_AC_VI | \
+ R92C_TXPAUSE_AC_BE | R92C_TXPAUSE_AC_BK | \
+ R92C_TXPAUSE_MGNT | R92C_TXPAUSE_HIGH | \
+ R92C_TXPAUSE_BCN | R92C_TXPAUSE_BCN_HIGH_MGNT)
/* Bits for R92C_BCN_CTRL. */
#define R92C_BCN_CTRL_EN_MBSSID 0x02
@@ -593,6 +605,9 @@
#define R92C_RCR_APP_MIC 0x40000000
#define R92C_RCR_APPFCS 0x80000000
+/* Bits for R92C_WMAC_TRXPTCL_CTL. */
+#define R92C_WMAC_TRXPTCL_CTL_SHORT 0x00020000
+
/* Bits for R92C_CAMCMD. */
#define R92C_CAMCMD_ADDR_M 0x0000ffff
#define R92C_CAMCMD_ADDR_S 0
@@ -667,8 +682,8 @@
/*Receive DMA OK interrupt */
#define R92C_IMR_ROK 0x00000001
-#define R92C_IBSS_INT_MASK (R92C_IMR_BCNINT | R92C_IMR_TBDOK | R92C_IMR_TBDER)
-
+#define R92C_IBSS_INT_MASK (R92C_IMR_BCNINT | R92C_IMR_TBDOK | \
+ R92C_IMR_TBDER)
/*
* Baseband registers.
@@ -1313,6 +1328,7 @@ struct r92c_tx_desc_usb {
#define R92C_TXDW4_SCO_S 20
#define R92C_TXDW4_SCO_SCA 1
#define R92C_TXDW4_SCO_SCB 2
+#define R92C_TXDW4_SHORTPRE 0x01000000
#define R92C_TXDW4_40MHZ 0x02000000
#define R92C_TXDW4_RTS_SHORT 0x04000000
diff --git a/sys/dev/ic/rtwn.c b/sys/dev/ic/rtwn.c
index f2f94e0c4bc..5dab9b5f2d7 100644
--- a/sys/dev/ic/rtwn.c
+++ b/sys/dev/ic/rtwn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtwn.c,v 1.33 2017/08/23 09:25:17 kevlo Exp $ */
+/* $OpenBSD: rtwn.c,v 1.34 2017/09/22 13:41:56 kevlo Exp $ */
/*-
* Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
@@ -126,7 +126,10 @@ int rtwn_r88e_ra_init(struct rtwn_softc *, u_int8_t, u_int32_t,
int, uint32_t, int);
void rtwn_tsf_sync_enable(struct rtwn_softc *);
void rtwn_set_led(struct rtwn_softc *, int, int);
+void rtwn_set_nettype(struct rtwn_softc *, enum ieee80211_opmode);
void rtwn_update_short_preamble(struct ieee80211com *);
+void rtwn_r92c_update_short_preamble(struct rtwn_softc *);
+void rtwn_r88e_update_short_preamble(struct rtwn_softc *);
int8_t rtwn_r88e_get_rssi(struct rtwn_softc *, int, void *);
void rtwn_watchdog(struct ifnet *);
void rtwn_fw_reset(struct rtwn_softc *);
@@ -815,7 +818,7 @@ rtwn_tsf_sync_enable(struct rtwn_softc *sc)
rtwn_read_1(sc, R92C_BCN_CTRL) & ~R92C_BCN_CTRL_EN_BCN);
/* Set initial TSF. */
- memcpy(&tsf, ni->ni_tstamp, 8);
+ memcpy(&tsf, ni->ni_tstamp, sizeof(tsf));
tsf = letoh64(tsf);
tsf = tsf - (tsf % (ni->ni_intval * IEEE80211_DUR_TU));
tsf -= IEEE80211_DUR_TU;
@@ -864,6 +867,27 @@ rtwn_set_led(struct rtwn_softc *sc, int led, int on)
}
void
+rtwn_set_nettype(struct rtwn_softc *sc, enum ieee80211_opmode opmode)
+{
+ uint8_t msr;
+
+ msr = rtwn_read_1(sc, R92C_MSR) & ~R92C_MSR_NETTYPE_MASK;
+
+ switch (opmode) {
+ case IEEE80211_M_MONITOR:
+ msr |= R92C_MSR_NETTYPE_NOLINK;
+ break;
+ case IEEE80211_M_STA:
+ msr |= R92C_MSR_NETTYPE_INFRA;
+ break;
+ default:
+ break;
+ }
+
+ rtwn_write_1(sc, R92C_MSR, msr);
+}
+
+void
rtwn_calib(struct rtwn_softc *sc)
{
struct r92c_fw_cmd_rssi cmd;
@@ -920,9 +944,7 @@ rtwn_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
rtwn_set_led(sc, RTWN_LED_LINK, 0);
/* Set media status to 'No Link'. */
- reg = rtwn_read_4(sc, R92C_CR);
- reg = RW(reg, R92C_CR_NETTYPE, R92C_CR_NETTYPE_NOLINK);
- rtwn_write_4(sc, R92C_CR, reg);
+ rtwn_set_nettype(sc, IEEE80211_M_MONITOR);
/* Stop Rx of data frames. */
rtwn_write_2(sc, R92C_RXFLTMAP2, 0);
@@ -973,7 +995,9 @@ rtwn_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
/* Pause AC Tx queues. */
rtwn_write_1(sc, R92C_TXPAUSE,
- rtwn_read_1(sc, R92C_TXPAUSE) | 0x0f);
+ rtwn_read_1(sc, R92C_TXPAUSE) | R92C_TXPAUSE_AC_VO |
+ R92C_TXPAUSE_AC_VI | R92C_TXPAUSE_AC_BE |
+ R92C_TXPAUSE_AC_BK);
rtwn_set_chan(sc, ic->ic_bss->ni_chan, NULL);
sc->sc_ops.next_scan(sc->sc_ops.cookie);
@@ -1009,9 +1033,7 @@ rtwn_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
ni = ic->ic_bss;
/* Set media status to 'Associated'. */
- reg = rtwn_read_4(sc, R92C_CR);
- reg = RW(reg, R92C_CR_NETTYPE, R92C_CR_NETTYPE_INFRA);
- rtwn_write_4(sc, R92C_CR, reg);
+ rtwn_set_nettype(sc, IEEE80211_M_STA);
/* Set BSSID. */
rtwn_write_4(sc, R92C_BSSID + 0, LE_READ_4(&ni->ni_bssid[0]));
@@ -1029,7 +1051,7 @@ rtwn_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
rtwn_write_2(sc, R92C_RXFLTMAP2, 0xffff);
/* Flush all AC queues. */
- rtwn_write_1(sc, R92C_TXPAUSE, 0);
+ rtwn_write_1(sc, R92C_TXPAUSE, ~R92C_TXPAUSE_ALL);
/* Set beacon interval. */
rtwn_write_2(sc, R92C_BCN_INTERVAL, ni->ni_intval);
@@ -1067,10 +1089,20 @@ void
rtwn_update_short_preamble(struct ieee80211com *ic)
{
struct rtwn_softc *sc = ic->ic_softc;
+
+ if (sc->chip & RTWN_CHIP_88E)
+ rtwn_r88e_update_short_preamble(sc);
+ else
+ rtwn_r92c_update_short_preamble(sc);
+}
+
+void
+rtwn_r92c_update_short_preamble(struct rtwn_softc *sc)
+{
uint32_t reg;
reg = rtwn_read_4(sc, R92C_RRSR);
- if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)
+ if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE)
reg |= R92C_RRSR_SHORT;
else
reg &= ~R92C_RRSR_SHORT;
@@ -1078,6 +1110,19 @@ rtwn_update_short_preamble(struct ieee80211com *ic)
}
void
+rtwn_r88e_update_short_preamble(struct rtwn_softc *sc)
+{
+ uint32_t reg;
+
+ reg = rtwn_read_4(sc, R92C_WMAC_TRXPTCL_CTL);
+ if (sc->sc_ic.ic_flags & IEEE80211_F_SHPREAMBLE)
+ reg |= R92C_WMAC_TRXPTCL_CTL_SHORT;
+ else
+ reg &= ~R92C_WMAC_TRXPTCL_CTL_SHORT;
+ rtwn_write_4(sc, R92C_WMAC_TRXPTCL_CTL, reg);
+}
+
+void
rtwn_updateslot(struct ieee80211com *ic)
{
struct rtwn_softc *sc = ic->ic_softc;
@@ -2268,7 +2313,9 @@ rtwn_iq_calib_run(struct rtwn_softc *sc, int n, uint16_t tx[2][2],
rtwn_bb_write(sc, R92C_LSSI_PARAM(1), 0x00010000);
}
- rtwn_write_1(sc, R92C_TXPAUSE, 0x3f);
+ rtwn_write_1(sc, R92C_TXPAUSE, R92C_TXPAUSE_AC_VO |
+ R92C_TXPAUSE_AC_VI | R92C_TXPAUSE_AC_BE | R92C_TXPAUSE_AC_BK |
+ R92C_TXPAUSE_MGNT | R92C_TXPAUSE_HIGH);
rtwn_write_1(sc, R92C_BCN_CTRL,
iq_cal_regs->bcn_ctrl & ~(R92C_BCN_CTRL_EN_BCN));
rtwn_write_1(sc, R92C_BCN_CTRL1,
@@ -2507,7 +2554,7 @@ rtwn_lc_calib(struct rtwn_softc *sc)
}
} else {
/* Block all Tx queues. */
- rtwn_write_1(sc, R92C_TXPAUSE, 0xff);
+ rtwn_write_1(sc, R92C_TXPAUSE, R92C_TXPAUSE_ALL);
}
/* Start calibration. */
rtwn_rf_write(sc, 0, R92C_RF_CHNLBW,
@@ -2525,7 +2572,7 @@ rtwn_lc_calib(struct rtwn_softc *sc)
rtwn_rf_write(sc, i, R92C_RF_AC, rf_ac[i]);
} else {
/* Unblock all Tx queues. */
- rtwn_write_1(sc, R92C_TXPAUSE, 0x00);
+ rtwn_write_1(sc, R92C_TXPAUSE, ~R92C_TXPAUSE_ALL);
}
}
@@ -2664,9 +2711,7 @@ rtwn_init(struct ifnet *ifp)
rtwn_write_1(sc, R92C_MACID + i, ic->ic_myaddr[i]);
/* Set initial network type. */
- reg = rtwn_read_4(sc, R92C_CR);
- reg = RW(reg, R92C_CR_NETTYPE, R92C_CR_NETTYPE_INFRA);
- rtwn_write_4(sc, R92C_CR, reg);
+ rtwn_set_nettype(sc, IEEE80211_M_MONITOR);
rtwn_rxfilter_init(sc);