Re: systat(1) and uvmexp.nswget documentation

2020-04-22 Thread Theo de Raadt
OK

Martin Pieuchot  wrote:

> schwarze@ pointed out that systat(1) refers to a non-documented
> function: uvm_swap_get().  I doubt referencing a UVM function is
> something appropriate.  Diff below tries to explain in word what the
> counter is: the number of swap page that have been read from disk.
> 
> It is not only incremented in the page fault handler, so I used the
> word 'moved'.
> 
> Comments, oks?
> 
> Index: usr.bin/systat/systat.1
> ===
> RCS file: /cvs/src/usr.bin/systat/systat.1,v
> retrieving revision 1.114
> diff -u -p -r1.114 systat.1
> --- usr.bin/systat/systat.1   16 Jan 2020 16:46:47 -  1.114
> +++ usr.bin/systat/systat.1   22 Apr 2020 21:16:00 -
> @@ -715,7 +715,7 @@ swap pages in use
>  .It swpgonly
>  in use swap pages not in RAM
>  .It nswget
> -fault called uvm_swap_get()
> +swap pages moved from disk to RAM
>  .It nanon
>  total anon's
>  .Pp
> Index: sys/uvm/uvmexp.h
> ===
> RCS file: /cvs/src/sys/uvm/uvmexp.h,v
> retrieving revision 1.4
> diff -u -p -r1.4 uvmexp.h
> --- sys/uvm/uvmexp.h  6 Nov 2018 07:49:38 -   1.4
> +++ sys/uvm/uvmexp.h  22 Apr 2020 21:15:37 -
> @@ -78,7 +78,7 @@ struct uvmexp {
>   int swpages;/* number of PAGE_SIZE'ed swap pages */
>   int swpginuse;  /* number of swap pages in use */
>   int swpgonly;   /* number of swap pages in use, not also in RAM */
> - int nswget; /* number of times fault calls uvm_swap_get() */
> + int nswget; /* number of swap pages moved from disk to RAM */
>   int nanon;  /* XXX number total of anon's in system */
>   int unused05;   /* formerly nanonneeded */
>   int unused06;   /* formerly nfreeanon */
> 



Re: [PATCH] [src] usr.bin/audioctl/audioctl.8, usr.bin/mixerctl/mixerctl.8 - manpages moved to section 8, mark them as such

2020-04-22 Thread Ingo Schwarze
Hi Raf,

Raf Czlonka wrote on Thu, Apr 23, 2020 at 12:58:41AM +0100:

> Recently moved manpages bear section 1 number - update accordingly.

Committed, thanks.
  Ingo


> Index: usr.bin/audioctl/audioctl.8
> ===
> RCS file: /cvs/src/usr.bin/audioctl/audioctl.8,v
> retrieving revision 1.3
> diff -u -p -r1.3 audioctl.8
> --- usr.bin/audioctl/audioctl.8   22 Apr 2020 21:39:21 -  1.3
> +++ usr.bin/audioctl/audioctl.8   22 Apr 2020 23:55:27 -
> @@ -27,7 +27,7 @@
>  .\" POSSIBILITY OF SUCH DAMAGE.
>  .\"
>  .Dd $Mdocdate: April 22 2020 $
> -.Dt AUDIOCTL 1
> +.Dt AUDIOCTL 8
>  .Os
>  .Sh NAME
>  .Nm audioctl
> Index: usr.bin/mixerctl/mixerctl.8
> ===
> RCS file: /cvs/src/usr.bin/mixerctl/mixerctl.8,v
> retrieving revision 1.4
> diff -u -p -r1.4 mixerctl.8
> --- usr.bin/mixerctl/mixerctl.8   22 Apr 2020 21:39:21 -  1.4
> +++ usr.bin/mixerctl/mixerctl.8   22 Apr 2020 23:56:20 -
> @@ -28,7 +28,7 @@
>  .\" POSSIBILITY OF SUCH DAMAGE.
>  .\"
>  .Dd $Mdocdate: April 22 2020 $
> -.Dt MIXERCTL 1
> +.Dt MIXERCTL 8
>  .Os
>  .Sh NAME
>  .Nm mixerctl



[PATCH] [src] usr.bin/audioctl/audioctl.8, usr.bin/mixerctl/mixerctl.8 - manpages moved to section 8, mark them as such

2020-04-22 Thread Raf Czlonka
Hi all,

Recently moved manpages bear section 1 number - update accordingly.

Regards,

Raf

Index: usr.bin/audioctl/audioctl.8
===
RCS file: /cvs/src/usr.bin/audioctl/audioctl.8,v
retrieving revision 1.3
diff -u -p -r1.3 audioctl.8
--- usr.bin/audioctl/audioctl.8 22 Apr 2020 21:39:21 -  1.3
+++ usr.bin/audioctl/audioctl.8 22 Apr 2020 23:55:27 -
@@ -27,7 +27,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .Dd $Mdocdate: April 22 2020 $
-.Dt AUDIOCTL 1
+.Dt AUDIOCTL 8
 .Os
 .Sh NAME
 .Nm audioctl
Index: usr.bin/mixerctl/mixerctl.8
===
RCS file: /cvs/src/usr.bin/mixerctl/mixerctl.8,v
retrieving revision 1.4
diff -u -p -r1.4 mixerctl.8
--- usr.bin/mixerctl/mixerctl.8 22 Apr 2020 21:39:21 -  1.4
+++ usr.bin/mixerctl/mixerctl.8 22 Apr 2020 23:56:20 -
@@ -28,7 +28,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .Dd $Mdocdate: April 22 2020 $
-.Dt MIXERCTL 1
+.Dt MIXERCTL 8
 .Os
 .Sh NAME
 .Nm mixerctl



systat(1) and uvmexp.nswget documentation

2020-04-22 Thread Martin Pieuchot
schwarze@ pointed out that systat(1) refers to a non-documented
function: uvm_swap_get().  I doubt referencing a UVM function is
something appropriate.  Diff below tries to explain in word what the
counter is: the number of swap page that have been read from disk.

It is not only incremented in the page fault handler, so I used the
word 'moved'.

Comments, oks?

Index: usr.bin/systat/systat.1
===
RCS file: /cvs/src/usr.bin/systat/systat.1,v
retrieving revision 1.114
diff -u -p -r1.114 systat.1
--- usr.bin/systat/systat.1 16 Jan 2020 16:46:47 -  1.114
+++ usr.bin/systat/systat.1 22 Apr 2020 21:16:00 -
@@ -715,7 +715,7 @@ swap pages in use
 .It swpgonly
 in use swap pages not in RAM
 .It nswget
-fault called uvm_swap_get()
+swap pages moved from disk to RAM
 .It nanon
 total anon's
 .Pp
Index: sys/uvm/uvmexp.h
===
RCS file: /cvs/src/sys/uvm/uvmexp.h,v
retrieving revision 1.4
diff -u -p -r1.4 uvmexp.h
--- sys/uvm/uvmexp.h6 Nov 2018 07:49:38 -   1.4
+++ sys/uvm/uvmexp.h22 Apr 2020 21:15:37 -
@@ -78,7 +78,7 @@ struct uvmexp {
int swpages;/* number of PAGE_SIZE'ed swap pages */
int swpginuse;  /* number of swap pages in use */
int swpgonly;   /* number of swap pages in use, not also in RAM */
-   int nswget; /* number of times fault calls uvm_swap_get() */
+   int nswget; /* number of swap pages moved from disk to RAM */
int nanon;  /* XXX number total of anon's in system */
int unused05;   /* formerly nanonneeded */
int unused06;   /* formerly nfreeanon */



athn(4): WPA2 crypto hardware offload

2020-04-22 Thread Stefan Sperling
This makes athn(4) offload CCMP encryption and decryption to hardware.
CCMP is used with WPA2, so this reduces CPU load on WPA2 networks only.

The WPA1 (TKIP) and WEP ciphers remain in software because this simplifies
the driver. TKIP in particular is a annoying to deal with on this hardware.
Old ciphers should not be used anymore anyway and they don't work in 11n mode.

I have successfully tested the following on this device:
athn0 at pci1 dev 0 function 0 "Atheros AR9281" rev 0x01: apic 2 int 16
athn0: AR9280 rev 2 (2T2R), ROM rev 22, address xx:xx:xx:xx:xx:xx

Hostap mode with multiple clients in parallel: wpa2, wpa1, wep, plaintext
Client mode: wpa2, plaintext

Could anyone else test this?

diff c50b0f0215d7dd5773e0ee8623d8aa2c7d2107c6 
72190e7ad96414fa4e11cb3c5ff1dc74b1d69795
blob - 9dd0499c9704c87fbe039b65f02e907284fea120
blob + 8ebdc15cbec490ea4a2f28a0fadab014e3d62645
--- sys/dev/ic/ar5008.c
+++ sys/dev/ic/ar5008.c
@@ -254,6 +254,8 @@ ar5008_attach(struct athn_softc *sc)
kc_entries_log = MS(base->deviceCap, AR_EEP_DEVCAP_KC_ENTRIES);
sc->kc_entries = (kc_entries_log != 0) ?
1 << kc_entries_log : AR_KEYTABLE_SIZE;
+   if (sc->kc_entries > AR_KEYTABLE_SIZE)
+   sc->kc_entries = AR_KEYTABLE_SIZE;
 
sc->txchainmask = base->txMask;
if (sc->mac_ver == AR_SREV_VERSION_5416_PCI &&
@@ -781,6 +783,111 @@ ar5008_rx_radiotap(struct athn_softc *sc, struct mbuf 
 }
 #endif
 
+int
+ar5008_ccmp_decap(struct athn_softc *sc, struct mbuf *m, struct ieee80211_node 
*ni)
+{
+   struct ieee80211com *ic = >sc_ic;
+   struct ieee80211_key *k;
+   struct ieee80211_frame *wh;
+   struct ieee80211_rx_ba *ba;
+   uint64_t pn, *prsc;
+   u_int8_t *ivp, *mmie;
+   uint8_t tid;
+   uint16_t kid;
+   int hdrlen, hasqos;
+   uintptr_t entry;
+
+   wh = mtod(m, struct ieee80211_frame *);
+   hdrlen = ieee80211_get_hdrlen(wh);
+   ivp = mtod(m, u_int8_t *) + hdrlen;
+
+   /* find key for decryption */
+   if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) {
+   k = >ni_pairwise_key;
+   } else if ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
+   IEEE80211_FC0_TYPE_MGT) {
+   /* retrieve group data key id from IV field */
+   /* check that IV field is present */
+   if (m->m_len < hdrlen + 4)
+   return 1;
+   kid = ivp[3] >> 6;
+   k = >ic_nw_keys[kid];
+   } else {
+   /* retrieve integrity group key id from MMIE */
+   if (m->m_len < sizeof(*wh) + IEEE80211_MMIE_LEN) {
+   return 1;
+   }
+   /* it is assumed management frames are contiguous */
+   mmie = (u_int8_t *)wh + m->m_len - IEEE80211_MMIE_LEN;
+   /* check that MMIE is valid */
+   if (mmie[0] != IEEE80211_ELEMID_MMIE || mmie[1] != 16) {
+   return 1;
+   }
+   kid = LE_READ_2([2]);
+   if (kid != 4 && kid != 5) {
+   return 1;
+   }
+   k = >ic_nw_keys[kid];
+   }
+
+   if (k->k_cipher != IEEE80211_CIPHER_CCMP)
+   return 1;
+
+   /* Sanity checks to ensure this is really a key we installed. */
+   entry = (uintptr_t)k->k_priv;
+   if (k->k_flags & IEEE80211_KEY_GROUP) {
+   if (k->k_id > IEEE80211_WEP_NKID ||
+   entry != k->k_id)
+   return 1;
+   } else if (entry != IEEE80211_WEP_NKID +
+   IEEE80211_AID(ni->ni_associd))
+   return 1;
+
+   /* Check that ExtIV bit is be set. */
+   if (!(ivp[3] & IEEE80211_WEP_EXTIV))
+   return 1;
+
+   hasqos = ieee80211_has_qos(wh);
+   tid = hasqos ? ieee80211_get_qos(wh) & IEEE80211_QOS_TID : 0;
+   ba = hasqos ? >ni_rx_ba[tid] : NULL;
+   prsc = >k_rsc[0];
+
+   /* Extract the 48-bit PN from the CCMP header. */
+   pn = (uint64_t)ivp[0]   |
+(uint64_t)ivp[1] <<  8 |
+(uint64_t)ivp[4] << 16 |
+(uint64_t)ivp[5] << 24 |
+(uint64_t)ivp[6] << 32 |
+(uint64_t)ivp[7] << 40;
+   if (pn <= *prsc) {
+   if (hasqos && ba->ba_state == IEEE80211_BA_AGREED) {
+   /*
+* This is an A-MPDU subframe.
+* Such frames may be received out of order due to
+* legitimate retransmissions of failed subframes
+* in previous A-MPDUs. Duplicates will be handled
+* in ieee80211_inputm() as part of A-MPDU reordering.
+*
+* XXX TODO We can probably do better than this! Store
+* re-ordered PN in BA agreement state and check it?
+*/
+   } else {
+   

athn(4): configure Tx interrupt mitigation

2020-04-22 Thread Stefan Sperling
We currently configure interrupt mitigation for Rx, but not for Tx.

And there is also a global Tx/Rx interrupt limit which can be configured
via the MIRT register. Setting this could prevent Tx/Rx interrupt storms.

This change doesn't really buy us anything during regular use of the
device, but during my testing it didn't hurt either.

OK?

diff 9b00dd5006bdfc0cf9d71dac4defe47f2ccfda0d 
c50b0f0215d7dd5773e0ee8623d8aa2c7d2107c6
blob - 88784561c133b42b2b23dff2cea0075cf2ffdd27
blob + b3532eb8263f678c80a44257fe4f55820458a18c
--- sys/dev/ic/athn.c
+++ sys/dev/ic/athn.c
@@ -2428,6 +2428,12 @@ athn_hw_reset(struct athn_softc *sc, struct ieee80211_
/* Setup Rx interrupt mitigation. */
AR_WRITE(sc, AR_RIMT, SM(AR_RIMT_FIRST, 2000) | SM(AR_RIMT_LAST, 500));
 
+   /* Setup Tx interrupt mitigation. */
+   AR_WRITE(sc, AR_TIMT, SM(AR_TIMT_FIRST, 2000) | SM(AR_TIMT_LAST, 500));
+
+   /* Set maximum interrupt rate threshold (in micro seconds). */
+   AR_WRITE(sc, AR_MIRT, SM(AR_MIRT_RATE_THRES, 2000));
+
ops->init_baseband(sc);
 
if ((error = athn_init_calib(sc, c, extc)) != 0) {
blob - 92b937ce3b3a0977a0f8548051863c39656a4862
blob + e14c096b90b5350712548d245a9bfd919b66f23b
--- sys/dev/ic/athnreg.h
+++ sys/dev/ic/athnreg.h
@@ -280,6 +280,10 @@
 /* Bits for AR_IER. */
 #define AR_IER_ENABLE  0x0001
 
+/* Bits for AR_MIRT. */
+#define AR_MIRT_RATE_THRES_M   0x
+#define AR_MIRT_RATE_THRES_S   0 
+
 /* Bits for AR_TIMT. */
 #define AR_TIMT_LAST_M 0x
 #define AR_TIMT_LAST_S 0