CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2021-03-07 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Mar  7 13:09:43 UTC 2021

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: bta2dpd.8 bta2dpd.c

Log Message:
Intoduce "-n" switch.

Running btat2dpd with "-n" especially for use with pad(4) will stop bta2dpd
from exiting upon a read error from pad(4) devices.

This is to compenstate for the behaviour in NetBSD current that pad(4) will
no longer output 0's when its corresponding audio(4) device is not active.

I believe that this new pad(4) behaviour is not present in -9 and -8.

While here I've improved its function as a daemon and it should reconnect to
bluetooth speakers when they are disconnected/reconnected.

Reported and tested by reinoud@ and maya@


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.4 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.5
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.4	Sat Jul 27 20:10:29 2019
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8	Sun Mar  7 13:09:43 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: bta2dpd.8,v 1.4 2019/07/27 20:10:29 nakayama Exp $
+.\"	$NetBSD: bta2dpd.8,v 1.5 2021/03/07 13:09:43 nat Exp $
 .\"
 .\" Copyright (c) 2015 - 2016  Nathanial Sloss 
 .\" All rights reserved.
@@ -37,7 +37,7 @@
 .Nd Bluetooth Advanced Audio Distribution Profile daemon
 .Sh SYNOPSIS
 .Nm
-.Op Fl \
+.Op Fl \
 .Op Fl A Ar bitpool_allocation
 .Op Fl B Ar bitpool
 .Op Fl b Ar blocks
@@ -107,6 +107,10 @@ with only the
 option and the maximum bitpool for your device will be printed to stdout.
 .It Fl D
 Run in the background.
+.It Fl n
+Do not close conection on end of file (EOF).
+Useful for
+.Xr pad 4 .
 .It Fl d Ar device
 Local device address.
 May be given as BDADDR or device name.

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.7 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.8
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.7	Sun May 31 06:17:23 2020
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c	Sun Mar  7 13:09:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bta2dpd.c,v 1.7 2020/05/31 06:17:23 nat Exp $ */
+/* $NetBSD: bta2dpd.c,v 1.8 2021/03/07 13:09:43 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss 
@@ -220,12 +220,14 @@ static struct event ctl_ev;			/* avdtp c
 struct l2cap_info	info;
 static bool		runasDaemon;
 static bool		asSpeaker;
+static bool		dontStop;
 static bool		initDiscover;	/* initiate avdtp discover */
 static bool 		verbose;	/* copy to stdout */
 static bool 		test_mode;	/* copy to stdout */
 static uint8_t		channel_mode = MODE_STEREO;
 static uint8_t		alloc_method = ALLOC_LOUDNESS;
 static uint8_t		frequency = FREQ_44_1K;
+static int		freqnum = 44100;
 static uint8_t		freqs[4];
 static uint8_t		blocks_config[4];
 static uint8_t		channel_config[4];
@@ -252,6 +254,7 @@ int audfile;
 static void do_interrupt(int, short, void *);
 static void do_recv(int, short, void *);
 static void do_ctlreq(int, short, void *);
+static void bt_exit(int fd);
 
 #define log_err(st, fmt, args...)	\
 	do { syslog(LOG_ERR, fmt, ##args); exit(st); } while (0)
@@ -262,12 +265,13 @@ static void do_ctlreq(int, short, void *
 int
 main(int ac, char *av[])
 {
-	int enc, i, n, m, l, j, k, o, ch, freqnum, blocksnum;
+	int enc, i, n, m, l, j, k, o, ch, blocksnum;
 	u_int tmpbitpool;
 	bdaddr_copy(, BDADDR_ANY);
 
 	sc = hc = -1;
 	verbose = asSpeaker = test_mode = initDiscover = runasDaemon = false;
+	dontStop = false;
 	n = m = l = i = j = o = 0;
 	freqs[0] = frequency;
 	channel_config[0] = channel_mode;
@@ -276,7 +280,8 @@ main(int ac, char *av[])
 	alloc_config[0] = alloc_method;
 	channel_config[0] = channel_mode;
 
-	while ((ch = getopt(ac, av, "A:a:B:b:Dd:e:f:IKM:m:p:r:tV:v")) != EOF) {
+	while ((ch = getopt(ac, av, "A:a:B:b:Dd:e:f:IKnM:m:p:r:tV:v")) !=
+	EOF) {
 		switch (ch) {
 		case 'A':
 			for (k = 0; k < (int)strlen(optarg); k++) {
@@ -405,6 +410,9 @@ main(int ac, char *av[])
 errx(EXIT_FAILURE, "%s: unknown mode", optarg);
 
 			break;
+		case 'n':
+			dontStop = true;
+			break;
 		case 'p':
 			l2cap_psm = (uint16_t)atoi(optarg);
 			break;
@@ -556,7 +564,7 @@ again:
 		audfile = -1;
 	}
 
-	if (asSpeaker)
+	if (runasDaemon)
 		goto again;
 
 	return EXIT_SUCCESS;
@@ -566,9 +574,9 @@ static void
 usage(void)
 {
 	fprintf(stderr,
-	"usage:\t%s [-v] [-D] [-d device] [-m mode] [-r rate] [-M mtu]\n"
-	"\t\t[-V volume] [-f mode] [-b blocks] [-e bands] [-A alloc]\n"
-	"\t\t[-B bitpool] -a address files...\n"
+	"usage:\t%s [-v] [-D] [-n] [-d device] [-m mode] [-r rate]\n"
+	"\t\t[-M mtu] [-V volume] [-f mode

CVS commit: src/sys/dev/usb

2021-03-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Mar  2 22:21:38 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
OppsRemove irrelavent debug code and don't free_m before IFQ_DEQUEUE().

Identified and reported by Patrick Welche and remedy found by Martin Husemann.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.95 src/sys/dev/usb/if_urtwn.c:1.96
--- src/sys/dev/usb/if_urtwn.c:1.95	Fri Feb 26 01:38:44 2021
+++ src/sys/dev/usb/if_urtwn.c	Tue Mar  2 22:21:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.96 2021/03/02 22:21:38 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.96 2021/03/02 22:21:38 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1470,10 +1470,6 @@ urtwn_read_rom(struct urtwn_softc *sc)
 	sc->pa_setting, sc->board_type, sc->regulatory, 0);
 
 	IEEE80211_ADDR_COPY(ic->ic_myaddr, rom->macaddr);
-#if 0
-	uint8_t new_myaddr[6] = {0x90,0x0a,0x1a,0xe7,0x1e,0xf0}; //Camera
-	IEEE80211_ADDR_COPY(ic->ic_myaddr, new_myaddr);
-#endif
 
 	sc->sc_rf_write = urtwn_r92c_rf_write;
 	sc->sc_power_on = urtwn_r92c_power_on;
@@ -2913,7 +2909,6 @@ urtwn_start(struct ifnet *ifp)
 		data = urtwn_get_tx_data(sc, sc->ac2idx[qid]);
 
 		if (data == NULL) {
-			m_freem(m);
 			ifp->if_flags |= IFF_OACTIVE;
 			DPRINTFN(DBG_TX, "empty tx_free_list", 0, 0, 0, 0);
 			return;



CVS commit: src/sys/dev/usb

2021-02-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Feb 26 01:38:44 UTC 2021

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
Also free assocated mbufs.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.94 src/sys/dev/usb/if_urtwn.c:1.95
--- src/sys/dev/usb/if_urtwn.c:1.94	Sun Feb 21 23:06:13 2021
+++ src/sys/dev/usb/if_urtwn.c	Fri Feb 26 01:38:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.94 2021/02/21 23:06:13 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.95 2021/02/26 01:38:44 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1470,6 +1470,10 @@ urtwn_read_rom(struct urtwn_softc *sc)
 	sc->pa_setting, sc->board_type, sc->regulatory, 0);
 
 	IEEE80211_ADDR_COPY(ic->ic_myaddr, rom->macaddr);
+#if 0
+	uint8_t new_myaddr[6] = {0x90,0x0a,0x1a,0xe7,0x1e,0xf0}; //Camera
+	IEEE80211_ADDR_COPY(ic->ic_myaddr, new_myaddr);
+#endif
 
 	sc->sc_rf_write = urtwn_r92c_rf_write;
 	sc->sc_power_on = urtwn_r92c_power_on;
@@ -2660,6 +2664,7 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		k = ieee80211_crypto_encap(ic, ni, m);
 		if (k == NULL) {
 			urtwn_put_tx_data(sc, data);
+			m_free(m);
 			return ENOBUFS;
 		}
 
@@ -2908,6 +2913,7 @@ urtwn_start(struct ifnet *ifp)
 		data = urtwn_get_tx_data(sc, sc->ac2idx[qid]);
 
 		if (data == NULL) {
+			m_freem(m);
 			ifp->if_flags |= IFF_OACTIVE;
 			DPRINTFN(DBG_TX, "empty tx_free_list", 0, 0, 0, 0);
 			return;
@@ -2919,16 +2925,17 @@ urtwn_start(struct ifnet *ifp)
 			device_printf(sc->sc_dev, "m_pullup failed\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
 		ni = ieee80211_find_txnode(ic, eh->ether_dhost);
 		if (ni == NULL) {
-			m_freem(m);
 			device_printf(sc->sc_dev,
 			"unable to find transmit node\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
 
@@ -2940,6 +2947,7 @@ urtwn_start(struct ifnet *ifp)
 			"unable to encapsulate packet\n");
 			if_statinc(ifp, if_oerrors);
 			urtwn_put_tx_data(sc, data);
+			m_freem(m);
 			continue;
 		}
  sendit:



CVS commit: src/distrib/sets/lists/debug

2021-01-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan  2 03:41:07 UTC 2021

Modified Files:
src/distrib/sets/lists/debug: mi

Log Message:
Update the debug set for testpat(6).


To generate a diff of this commit:
cvs rdiff -u -r1.345 -r1.346 src/distrib/sets/lists/debug/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.345 src/distrib/sets/lists/debug/mi:1.346
--- src/distrib/sets/lists/debug/mi:1.345	Mon Dec 28 14:28:54 2020
+++ src/distrib/sets/lists/debug/mi	Sat Jan  2 03:41:06 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.345 2020/12/28 14:28:54 martin Exp $
+# $NetBSD: mi,v 1.346 2021/01/02 03:41:06 nat Exp $
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib	comp-sys-usr		compatdir
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib,compatfile
@@ -937,6 +937,7 @@
 ./usr/libdata/debug/usr/games/snscore.debug	comp-games-debug	debug
 ./usr/libdata/debug/usr/games/strfile.debug	comp-utils-debug	debug
 ./usr/libdata/debug/usr/games/teachgammon.debug	comp-games-debug	debug
+./usr/libdata/debug/usr/games/testpat.debug	comp-games-debug	debug
 ./usr/libdata/debug/usr/games/tetris.debug	comp-games-debug	debug
 ./usr/libdata/debug/usr/games/trek.debug	comp-games-debug	debug
 ./usr/libdata/debug/usr/games/unstr.debug	comp-utils-debug	debug



CVS commit: src/distrib/sets/lists/games

2021-01-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan  2 03:24:02 UTC 2021

Modified Files:
src/distrib/sets/lists/games: mi

Log Message:
Add testpat(6) to the games set.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/distrib/sets/lists/games/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/games/mi
diff -u src/distrib/sets/lists/games/mi:1.59 src/distrib/sets/lists/games/mi:1.60
--- src/distrib/sets/lists/games/mi:1.59	Tue Nov 10 21:47:41 2020
+++ src/distrib/sets/lists/games/mi	Sat Jan  2 03:24:01 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.59 2020/11/10 21:47:41 kamil Exp $
+# $NetBSD: mi,v 1.60 2021/01/02 03:24:01 nat Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -85,6 +85,7 @@
 ./usr/games/snscoregames-games-bin
 ./usr/games/strfilegames-utils-bin
 ./usr/games/teachgammongames-games-bin
+./usr/games/testpatgames-games-bin
 ./usr/games/tetrisgames-games-bin
 ./usr/games/trekgames-games-bin
 ./usr/games/unstrgames-utils-bin
@@ -256,6 +257,7 @@
 ./usr/share/man/cat6/rot13.0			games-utils-catman	.cat
 ./usr/share/man/cat6/sail.0			games-games-catman	.cat
 ./usr/share/man/cat6/snake.0			games-games-catman	.cat
+./usr/share/man/cat6/testpat.0			games-games-catman	.cat
 ./usr/share/man/cat6/tetris.0			games-games-catman	.cat
 ./usr/share/man/cat6/trek.0			games-games-catman	.cat
 ./usr/share/man/cat6/wargames.0			games-games-catman	.cat
@@ -311,6 +313,7 @@
 ./usr/share/man/html6/rot13.html		games-utils-htmlman	html
 ./usr/share/man/html6/sail.html			games-games-htmlman	html
 ./usr/share/man/html6/snake.html		games-games-htmlman	html
+./usr/share/man/html6/testpat.html		games-games-htmlman	html
 ./usr/share/man/html6/tetris.html		games-games-htmlman	html
 ./usr/share/man/html6/trek.html			games-games-htmlman	html
 ./usr/share/man/html6/wargames.html		games-games-htmlman	html
@@ -368,6 +371,7 @@
 ./usr/share/man/man6/rot13.6			games-utils-man		.man
 ./usr/share/man/man6/sail.6			games-games-man		.man
 ./usr/share/man/man6/snake.6			games-games-man		.man
+./usr/share/man/man6/testpat.6			games-games-man		.man
 ./usr/share/man/man6/tetris.6			games-games-man		.man
 ./usr/share/man/man6/trek.6			games-games-man		.man
 ./usr/share/man/man6/wargames.6			games-games-man		.man



CVS commit: src/games

2021-01-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan  2 03:21:39 UTC 2021

Modified Files:
src/games: Makefile
Added Files:
src/games/testpat: Makefile testpat.6 testpat.c

Log Message:
Add testpat(6) to games.

Testpat displays a test pattern in curses(3).


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/games/Makefile
cvs rdiff -u -r0 -r1.1 src/games/testpat/Makefile src/games/testpat/testpat.6 \
src/games/testpat/testpat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/Makefile
diff -u src/games/Makefile:1.30 src/games/Makefile:1.31
--- src/games/Makefile:1.30	Tue Nov 10 08:49:08 2020
+++ src/games/Makefile	Sat Jan  2 03:21:39 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.30 2020/11/10 08:49:08 kamil Exp $
+#	$NetBSD: Makefile,v 1.31 2021/01/02 03:21:39 nat Exp $
 #	@(#)Makefile	8.3 (Berkeley) 7/24/94
 
 # Missing: dungeon
@@ -13,7 +13,7 @@ SUBDIR=	adventure arithmetic atc \
 	dm factor fish fortune gomoku \
 	hack hals_end hangman hunt larn mille monop morse number \
 	phantasia pig pom ppt primes quiz \
-	rain random robots rogue sail snake tetris trek \
+	rain random robots rogue sail snake testpat tetris trek \
 	wargames warp worm worms wtf wump
 
 .if ${MKCXX} != "no"

Added files:

Index: src/games/testpat/Makefile
diff -u /dev/null src/games/testpat/Makefile:1.1
--- /dev/null	Sat Jan  2 03:21:39 2021
+++ src/games/testpat/Makefile	Sat Jan  2 03:21:39 2021
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1 2021/01/02 03:21:39 nat Exp $
+
+PROG=  testpat
+MAN=   testpat.6
+DPADD=	${LIBMATH} ${LIBCURSES} ${LIBTERMINFO}
+LDADD=	-lcurses -lm -lterminfo
+
+.include 
Index: src/games/testpat/testpat.6
diff -u /dev/null src/games/testpat/testpat.6:1.1
--- /dev/null	Sat Jan  2 03:21:39 2021
+++ src/games/testpat/testpat.6	Sat Jan  2 03:21:39 2021
@@ -0,0 +1,50 @@
+.\"	$NetBSD: testpat.6,v 1.1 2021/01/02 03:21:39 nat Exp $
+.\"
+.\" Copyright (c) 2021 Nathanial Sloss 
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd Janurary 2, 2021
+.Dt TESTPAT 6
+.Os
+.Sh NAME
+.Nm testpat
+.Nd display test pattern
+.Sh SYNOPSIS
+.Nm
+.Op title
+.Sh DESCRIPTION
+The
+.Nm
+command displays a test pattern on a color capable terminal using
+.Xr curses 3 .
+
+Title is a string to display as the title of the test pattern.
+.Sh SEE ALSO
+.Xr curses 3
+.Sh HISTORY
+.Nm
+appeared in
+.Nx 10.0 .
+.Sh AUTHORS
+Nathanial Sloss
Index: src/games/testpat/testpat.c
diff -u /dev/null src/games/testpat/testpat.c:1.1
--- /dev/null	Sat Jan  2 03:21:39 2021
+++ src/games/testpat/testpat.c	Sat Jan  2 03:21:39 2021
@@ -0,0 +1,459 @@
+/* $NetBSD: testpat.c,v 1.1 2021/01/02 03:21:39 nat Exp $ */
+
+/*-
+ * Copyright (c) 2016 Nathanial Sloss 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPL

CVS commit: src/usr.bin/calendar/calendars

2020-10-07 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Oct  7 19:06:50 UTC 2020

Modified Files:
src/usr.bin/calendar/calendars: calendar.music

Log Message:
Eddie Van Halen, co-founder of Van Halen dies.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/calendar/calendars/calendar.music

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/calendar/calendars/calendar.music
diff -u src/usr.bin/calendar/calendars/calendar.music:1.24 src/usr.bin/calendar/calendars/calendar.music:1.25
--- src/usr.bin/calendar/calendars/calendar.music:1.24	Thu May 21 08:43:57 2020
+++ src/usr.bin/calendar/calendars/calendar.music	Wed Oct  7 19:06:50 2020
@@ -143,6 +143,7 @@
 09/26	George Gershwin born in Brooklyn, NY, 1898
 10/03	Stevie Ray Vaughan born in Dallas, TX, 1954
 10/04	Janis Joplin dies of a heroin overdose in Hollywood, 1970
+10/06	Eddie Van Halen dies in Santa Monica, CA,  2020
 10/05	Steve Miller is born in Dallas, 1943
 10/07	First Bandstand (later, American Bandstand) broadcast, 1957
 10/09	John Lennon born in Liverpool, England, 1940



CVS commit: src/sys/dev/cardbus

2020-10-04 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Oct  4 06:15:55 UTC 2020

Modified Files:
src/sys/dev/cardbus: cardslot.c

Log Message:
Ensure event_thread stays in event loop upon creation.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/cardbus/cardslot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/cardbus/cardslot.c
diff -u src/sys/dev/cardbus/cardslot.c:1.56 src/sys/dev/cardbus/cardslot.c:1.57
--- src/sys/dev/cardbus/cardslot.c:1.56	Sat Sep 24 23:54:49 2016
+++ src/sys/dev/cardbus/cardslot.c	Sun Oct  4 06:15:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cardslot.c,v 1.56 2016/09/24 23:54:49 mrg Exp $	*/
+/*	$NetBSD: cardslot.c,v 1.57 2020/10/04 06:15:54 nat Exp $	*/
 
 /*
  * Copyright (c) 1999 and 2000
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cardslot.c,v 1.56 2016/09/24 23:54:49 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cardslot.c,v 1.57 2020/10/04 06:15:54 nat Exp $");
 
 #include "opt_cardslot.h"
 
@@ -157,6 +157,7 @@ cardslotattach(device_t parent, device_t
 	}
 
 	if (csc != NULL || psc != NULL) {
+		sc->sc_th_enable = 1;
 		config_pending_incr(self);
 		if (kthread_create(PRI_NONE, 0, NULL, cardslot_event_thread,
 		sc, >sc_event_thread, "%s", device_xname(self))) {
@@ -164,7 +165,6 @@ cardslotattach(device_t parent, device_t
 	 "unable to create thread\n");
 			panic("cardslotattach");
 		}
-		sc->sc_th_enable = 1;
 	}
 
 	if (csc && (csc->sc_cf->cardbus_ctrl)(csc->sc_cc, CARDBUS_CD)) {



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2020-05-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun May 31 06:17:24 UTC 2020

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: bta2dpd.c

Log Message:
Avoid running of the end of the array if a file cannot be opened.

Found by plunky@.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.6 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.7
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.6	Sat Jul 27 20:10:29 2019
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c	Sun May 31 06:17:23 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bta2dpd.c,v 1.6 2019/07/27 20:10:29 nakayama Exp $ */
+/* $NetBSD: bta2dpd.c,v 1.7 2020/05/31 06:17:23 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss 
@@ -844,6 +844,7 @@ do_interrupt(int fd, short ev, void *arg
 	len = stream(fd, sc, channel_mode, frequency, bands, blocks,
 	alloc_method, bitpool, mtu, volume);
 
+next_file:
 	if (len == -1 && currentFileInd >= numfiles -1) {
 		event_del(_ev);
 		close(fd);
@@ -851,7 +852,6 @@ do_interrupt(int fd, short ev, void *arg
 		exit(1);
 	} else if (len == -1) {
 		close(fd);
-next_file:
 		currentFileInd++;
 		audfile = open(files2open[currentFileInd], O_RDONLY);
 		if (audfile < 0) {



CVS commit: src/sys/net

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 23:35:40 UTC 2020

Modified Files:
src/sys/net: pfil.c

Log Message:
Remove inappropriate place for __predict_false.

Ok mrg@ maya@.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/net/pfil.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/pfil.c
diff -u src/sys/net/pfil.c:1.37 src/sys/net/pfil.c:1.38
--- src/sys/net/pfil.c:1.37	Mon Apr 27 23:05:31 2020
+++ src/sys/net/pfil.c	Mon Apr 27 23:35:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pfil.c,v 1.37 2020/04/27 23:05:31 nat Exp $	*/
+/*	$NetBSD: pfil.c,v 1.38 2020/04/27 23:35:40 nat Exp $	*/
 
 /*
  * Copyright (c) 2013 Mindaugas Rasiukevicius 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.37 2020/04/27 23:05:31 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.38 2020/04/27 23:35:40 nat Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_net_mpsafe.h"
@@ -399,7 +399,7 @@ pfil_run_hooks(pfil_head_t *ph, struct m
 
 	KASSERT(dir == PFIL_IN || dir == PFIL_OUT);
 
-	if (__predict_false(ph == NULL)) {
+	if (ph == NULL) {
 		return ret;
 	}
 



CVS commit: src/sys/net

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 23:05:31 UTC 2020

Modified Files:
src/sys/net: pfil.c

Log Message:
Skip pfil_run_hooks if no packet filter configured in kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/pfil.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/pfil.c
diff -u src/sys/net/pfil.c:1.36 src/sys/net/pfil.c:1.37
--- src/sys/net/pfil.c:1.36	Sat Feb  1 02:54:31 2020
+++ src/sys/net/pfil.c	Mon Apr 27 23:05:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pfil.c,v 1.36 2020/02/01 02:54:31 riastradh Exp $	*/
+/*	$NetBSD: pfil.c,v 1.37 2020/04/27 23:05:31 nat Exp $	*/
 
 /*
  * Copyright (c) 2013 Mindaugas Rasiukevicius 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.36 2020/02/01 02:54:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.37 2020/04/27 23:05:31 nat Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_net_mpsafe.h"
@@ -398,6 +398,11 @@ pfil_run_hooks(pfil_head_t *ph, struct m
 	int ret = 0;
 
 	KASSERT(dir == PFIL_IN || dir == PFIL_OUT);
+
+	if (__predict_false(ph == NULL)) {
+		return ret;
+	}
+
 	if (__predict_false((phlistset = pfil_hook_get(dir, ph)) == NULL)) {
 		return ret;
 	}



CVS commit: [phil-wifi] src/sys/net80211

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:45:57 UTC 2020

Modified Files:
src/sys/net80211 [phil-wifi]: ieee80211_ioctl.c

Log Message:
Pass the error through to the hardware to initialize.


To generate a diff of this commit:
cvs rdiff -u -r1.60.18.9 -r1.60.18.10 src/sys/net80211/ieee80211_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_ioctl.c
diff -u src/sys/net80211/ieee80211_ioctl.c:1.60.18.9 src/sys/net80211/ieee80211_ioctl.c:1.60.18.10
--- src/sys/net80211/ieee80211_ioctl.c:1.60.18.9	Mon Apr 13 08:05:16 2020
+++ src/sys/net80211/ieee80211_ioctl.c	Mon Apr 27 07:45:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.60.18.9 2020/04/13 08:05:16 martin Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.60.18.10 2020/04/27 07:45:57 nat Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
 
 #include 
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.60.18.9 2020/04/13 08:05:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.60.18.10 2020/04/27 07:45:57 nat Exp $");
 #endif
 
 /*
@@ -3638,11 +3638,11 @@ ieee80211_ioctl_set80211(struct ieee8021
 		if (IS_UP_AUTO(vap))
 #if __FreeBSD__
 			ieee80211_init(vap);
+		error = 0;
 #elif __NetBSD__
 			/* arg is a vap in 802.11 code */ 
 			ieee80211_init((struct ifnet *)vap);
 #endif
-		error = 0;
 	}
 	return error;
 }



CVS commit: [phil-wifi] src/sys/net80211

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:40:50 UTC 2020

Modified Files:
src/sys/net80211 [phil-wifi]: ieee80211_sta.c

Log Message:
Make ostate reflect the updated state.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.6 -r1.1.2.7 src/sys/net80211/ieee80211_sta.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211_sta.c
diff -u src/sys/net80211/ieee80211_sta.c:1.1.2.6 src/sys/net80211/ieee80211_sta.c:1.1.2.7
--- src/sys/net80211/ieee80211_sta.c:1.1.2.6	Mon Jun 10 22:09:46 2019
+++ src/sys/net80211/ieee80211_sta.c	Mon Apr 27 07:40:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_sta.c,v 1.1.2.6 2019/06/10 22:09:46 christos Exp $ */
+/*	$NetBSD: ieee80211_sta.c,v 1.1.2.7 2020/04/27 07:40:50 nat Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -29,7 +29,7 @@
 
 #include 
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_sta.c,v 1.1.2.6 2019/06/10 22:09:46 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_sta.c,v 1.1.2.7 2020/04/27 07:40:50 nat Exp $");
 #endif
 
 
@@ -298,6 +298,7 @@ sta_newstate(struct ieee80211vap *vap, e
 		default:
 			break;
 		}
+		ostate = vap->iv_state;
 		if (ostate != IEEE80211_S_INIT) {
 			/* NB: optimize INIT -> INIT case */
 			ieee80211_reset_bss(vap);
@@ -464,6 +465,7 @@ sta_newstate(struct ieee80211vap *vap, e
 			goto invalid;
 		}
 		ieee80211_sync_curchan(ic);
+		ostate = vap->iv_state;
 		if (ostate != IEEE80211_S_RUN)
 			sta_swbmiss_start(vap);
 		/*



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:38:25 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Software crypto definitions from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.17 -r1.59.2.18 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.17 src/sys/dev/usb/if_urtwn.c:1.59.2.18
--- src/sys/dev/usb/if_urtwn.c:1.59.2.17	Mon Apr 27 07:37:01 2020
+++ src/sys/dev/usb/if_urtwn.c	Mon Apr 27 07:38:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.18 2020/04/27 07:38:25 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.18 2020/04/27 07:38:25 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -527,6 +527,11 @@ urtwn_attach(device_t parent, device_t s
 	IEEE80211_HTCAP_SHORTGI40;		/* short GI in 40MHz */
 #endif
 
+	ic->ic_cryptocaps =
+		IEEE80211_CRYPTO_WEP |
+		IEEE80211_CRYPTO_TKIP |
+		IEEE80211_CRYPTO_AES_CCM;
+
 	ic->ic_txstream = sc->ntxchains;
 	ic->ic_rxstream = sc->nrxchains;
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:37:01 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Fix resource leak in rx/tx free lists.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.16 -r1.59.2.17 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.16 src/sys/dev/usb/if_urtwn.c:1.59.2.17
--- src/sys/dev/usb/if_urtwn.c:1.59.2.16	Sat Apr 25 14:40:11 2020
+++ src/sys/dev/usb/if_urtwn.c	Mon Apr 27 07:37:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.17 2020/04/27 07:37:01 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -814,19 +814,23 @@ urtwn_alloc_rx_list(struct urtwn_softc *
 static void
 urtwn_free_rx_list(struct urtwn_softc *sc)
 {
+	struct urtwn_rx_data *data = NULL;
 	struct usbd_xfer *xfer;
-	size_t i;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
 	/* NB: Caller must abort pipe first. */
 	for (size_t j = 0; j < sc->rx_npipe; j++) {
-		for (i = 0; i < URTWN_RX_LIST_COUNT; i++) {
+		mutex_enter(>sc_rx_mtx); 
+		while (!TAILQ_EMPTY(>rx_free_list[j])) {
+			data = TAILQ_FIRST(>rx_free_list[j]);
+			TAILQ_REMOVE(>rx_free_list[j], data, next);
 			CTASSERT(sizeof(xfer) == sizeof(void *));
-			xfer = atomic_swap_ptr(>rx_data[j][i].xfer, NULL);
+			xfer = atomic_swap_ptr(>xfer, NULL);
 			if (xfer != NULL)
 usbd_destroy_xfer(xfer);
 		}
+		mutex_exit(>sc_rx_mtx);
 	}
 }
 
@@ -875,19 +879,23 @@ urtwn_alloc_tx_list(struct urtwn_softc *
 static void
 urtwn_free_tx_list(struct urtwn_softc *sc)
 {
+	struct urtwn_tx_data *data = NULL;
 	struct usbd_xfer *xfer;
-	size_t i;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n", device_xname(sc->sc_dev), __func__));
 
 	/* NB: Caller must abort pipe first. */
 	for (size_t j = 0; j < sc->tx_npipe; j++) {
-		for (i = 0; i < URTWN_TX_LIST_COUNT; i++) {
+		mutex_enter(>sc_tx_mtx); 
+		while (!TAILQ_EMPTY(>tx_free_list[j])) {
+			data = TAILQ_FIRST(>tx_free_list[j]);
+			TAILQ_REMOVE(>tx_free_list[j], data, next);
 			CTASSERT(sizeof(xfer) == sizeof(void *));
-			xfer = atomic_swap_ptr(>tx_data[j][i].xfer, NULL);
+			xfer = atomic_swap_ptr(>xfer, NULL);
 			if (xfer != NULL)
 usbd_destroy_xfer(xfer);
 		}
+		mutex_exit(>sc_tx_mtx);
 	}
 }
 



CVS commit: [phil-wifi] src/sys/net

2020-04-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Apr 27 07:27:35 UTC 2020

Modified Files:
src/sys/net [phil-wifi]: pfil.c

Log Message:
Skip pfil_run_hooks if no packet filter enabled in the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.35.14.1 -r1.35.14.2 src/sys/net/pfil.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/pfil.c
diff -u src/sys/net/pfil.c:1.35.14.1 src/sys/net/pfil.c:1.35.14.2
--- src/sys/net/pfil.c:1.35.14.1	Wed Apr  8 14:08:57 2020
+++ src/sys/net/pfil.c	Mon Apr 27 07:27:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pfil.c,v 1.35.14.1 2020/04/08 14:08:57 martin Exp $	*/
+/*	$NetBSD: pfil.c,v 1.35.14.2 2020/04/27 07:27:35 nat Exp $	*/
 
 /*
  * Copyright (c) 2013 Mindaugas Rasiukevicius 
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.35.14.1 2020/04/08 14:08:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pfil.c,v 1.35.14.2 2020/04/27 07:27:35 nat Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_net_mpsafe.h"
@@ -398,6 +398,11 @@ pfil_run_hooks(pfil_head_t *ph, struct m
 	int ret = 0;
 
 	KASSERT(dir == PFIL_IN || dir == PFIL_OUT);
+	
+	if (__predict_false(ph == NULL)) {
+		return ret;
+	}
+
 	if (__predict_false((phlistset = pfil_hook_get(dir, ph)) == NULL)) {
 		return ret;
 	}



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 14:40:12 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Remove configuring 40Mhz channels for now.

Avoid duplicate state transitions in urtwn_newstate.
Avoid changing channel parameters in urtwn_newstate.

Rework of tx desc parameters for all types of packets.

Don't create a percpuq as the stack is not expecting it //XXX not sure

Tested connections to an open 11n network with 8188CUS, 8192CU and 8192EU
usb adaptors.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.15 -r1.59.2.16 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.15 src/sys/dev/usb/if_urtwn.c:1.59.2.16
--- src/sys/dev/usb/if_urtwn.c:1.59.2.15	Sat Apr 25 09:32:16 2020
+++ src/sys/dev/usb/if_urtwn.c	Sat Apr 25 14:40:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.16 2020/04/25 14:40:11 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2173,7 +2173,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
 		} else /* IEEE_MODE_11NG */
-			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 11);
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -2227,7 +2227,7 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 		urtwn_write_1(sc, R92C_T2T_SIFS + 1, sifs_time);
 
 		/* Initialize rate adaptation. */
-		if (ISSET(sc->chip, URTWN_CHIP_88E) ||
+		if (1 || ISSET(sc->chip, URTWN_CHIP_88E) ||
 		ISSET(sc->chip, URTWN_CHIP_92EU))
 			ni->ni_txrate = ni->ni_rates.rs_nrates - 1;
 		else
@@ -2311,6 +2311,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_RUN:
+		if (nstate == IEEE80211_S_RUN)
+			break;
 		/* Turn link LED off. */
 		urtwn_set_led(sc, URTWN_LED_LINK, 0);
 
@@ -2328,9 +2330,11 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_read_1(sc, R92C_BCN_CTRL) |
 		  R92C_BCN_CTRL_DIS_TSF_UDT0);
 
+#if 0
 		/* Back to 20MHz mode */
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		if (ic->ic_opmode == IEEE80211_M_IBSS ||
 		ic->ic_opmode == IEEE80211_M_HOSTAP) {
@@ -2364,6 +2368,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_SCAN:
+		if (ostate == IEEE80211_S_SCAN)
+			break;
 		if (ostate != IEEE80211_S_SCAN) {
 			/*
 			 * Begin of scanning
@@ -2404,8 +2410,10 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_write_1(sc, R92C_TXPAUSE,
 		urtwn_read_1(sc, R92C_TXPAUSE) | 0x0f);
 
+#if 0
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		/* Start periodic scan. */
 		if (!sc->sc_dying)
@@ -2413,6 +2421,8 @@ urtwn_newstate(struct ieee80211vap *vap,
 		break;
 
 	case IEEE80211_S_AUTH:
+		if (ostate == IEEE80211_S_AUTH)
+			break;
 		/* Set initial gain under link. */
 		reg = urtwn_bb_read(sc, R92C_OFDM0_AGCCORE1(0));
 		reg = RW(reg, R92C_OFDM0_AGCCORE1_GAIN, 0x32);
@@ -2432,24 +2442,32 @@ urtwn_newstate(struct ieee80211vap *vap,
 		urtwn_read_4(sc, R92C_RCR) &
 		  ~(R92C_RCR_CBSSID_DATA | R92C_RCR_CBSSID_BCN));
 
+#if 0
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 		break;
 
 	case IEEE80211_S_ASSOC:
 		break;
 
 	case IEEE80211_S_RUN:
+		if (ostate == IEEE80211_S_RUN)
+			break;
 		ni = vap->iv_bss;
 
+#if 0
 		/* XXX: Set 20MHz mode */
 		urtwn_set_chan(sc, ic->ic_curchan,
 		IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 		if (ic->ic_opmode == IEEE80211_M_MONITOR) {
+#if 0
 			/* Back to 20MHz mode */
 			urtwn_set_chan(sc, ic->ic_curchan,
 			IEEE80211_HTINFO_2NDCHAN_NONE);
+#endif
 
 			/* Set media status to 'No Link'. */
 			urtwn_set_nettype0_msr(sc, R92C_CR_NETTYPE_NOLINK);
@@ -3108,9 +3126,6 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		R92C_TXDW0_OWN | R92C_TXDW0_FSG | R92C_TXDW0_LSG);
 	}
 
-	if (ic->ic_curmode == IEEE80211_MODE_11NG)
-		txd->txdw5 |= htole32(R92C_TXDW5_SGI);
-
 	if (IEEE80211_IS_MULTICAST(wh->i_addr1))
 		txd->txdw0 |= htole32(R92C_TXDW0_BMCAST);
 
@@ -3120,15 +3135,21 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		device_xname(sc->sc_dev), __func__, padsize));
 		txd->txdw1 |= htole32(SM(R92C_TXDW1_PKTOFF, (padsize / 8)));
 	}
+	if (ic->ic_curmode == IEEE80211_MODE_11B) {
+		raid = R92C_RAID_11B;
+		txd->txdw5 |= htole32(SM(R92C_TXDW5_DATARATE, 0));
+	} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
+		

CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Apr 25 09:32:16 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Compete some more of 11n support.
htcaps and streams values from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.14 -r1.59.2.15 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.14 src/sys/dev/usb/if_urtwn.c:1.59.2.15
--- src/sys/dev/usb/if_urtwn.c:1.59.2.14	Tue Apr 21 18:42:38 2020
+++ src/sys/dev/usb/if_urtwn.c	Sat Apr 25 09:32:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.14 2020/04/21 18:42:38 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.14 2020/04/21 18:42:38 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.15 2020/04/25 09:32:16 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -515,6 +515,21 @@ urtwn_attach(device_t parent, device_t s
 	IEEE80211_C_WME |		/* 802.11e */
 	IEEE80211_C_WPA;		/* 802.11i */
 
+	ic->ic_htcaps =
+	IEEE80211_HTC_HT |
+	IEEE80211_HTCAP_SHORTGI20 |		/* short GI in 20MHz */
+#if 0
+	IEEE80211_HTCAP_MAXAMSDU_3839 |	/* max A-MSDU length */
+#endif
+	IEEE80211_HTCAP_SMPS_OFF;		/* SM PS mode disabled */
+#if 0
+	IEEE80211_HTCAP_CHWIDTH40 |		/* 40 MHz channel width */
+	IEEE80211_HTCAP_SHORTGI40;		/* short GI in 40MHz */
+#endif
+
+	ic->ic_txstream = sc->ntxchains;
+	ic->ic_rxstream = sc->nrxchains;
+
 	ic->ic_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 
 #ifdef should_delete_NNN
@@ -3667,7 +3682,8 @@ urtwn_getradiocaps(struct ieee80211com *
 	setbit(bands, IEEE80211_MODE_11G);
 	setbit(bands, IEEE80211_MODE_11NG);
 	ieee80211_add_channel_list_2ghz(chans, maxchans, nchans,
-	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, 0);
+	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, IEEE80211_CHAN_HT20 |
+	IEEE80211_CHAN_HT40U | IEEE80211_CHAN_HT40D);
 }
 
 



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-19 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Apr 19 13:57:23 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Initial 11n support for urtwn.

Compile tested only... More to come.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.12 -r1.59.2.13 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.12 src/sys/dev/usb/if_urtwn.c:1.59.2.13
--- src/sys/dev/usb/if_urtwn.c:1.59.2.12	Fri Apr 17 13:44:37 2020
+++ src/sys/dev/usb/if_urtwn.c	Sun Apr 19 13:57:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.13 2020/04/19 13:57:23 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.12 2020/04/17 13:44:37 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.13 2020/04/19 13:57:23 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1651,9 +1651,10 @@ urtwn_ra_init(struct ieee80211vap *vap)
 	}
 	if (ic->ic_curmode == IEEE80211_MODE_11B) {
 		mode = R92C_RAID_11B;
-	} else {
+	} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 		mode = R92C_RAID_11BG;
-	}
+	} else /* mode = IEEE80211_MODE_11NG */
+		mode = R92C_RAID_11GN;
 	DPRINTFN(DBG_INIT, ("%s: %s: mode=%#x rates=%#x, basicrates=%#x, "
 	"maxrate=%zx, maxbasicrate=%zx\n",
 	device_xname(sc->sc_dev), __func__, mode, rates, basicrates,
@@ -2153,10 +2154,11 @@ urtwn_newstate_cb(struct urtwn_softc *sc
 
 		if (ic->ic_curmode == IEEE80211_MODE_11B) {
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 0);
-		} else {
+		} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
-		}
+		} else /* IEEE_MODE_11NG */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -2464,10 +2466,11 @@ urtwn_newstate(struct ieee80211vap *vap,
 
 		if (ic->ic_curmode == IEEE80211_MODE_11B) {
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 0);
-		} else {
+		} else if (ic->ic_curmode == IEEE80211_MODE_11G) {
 			/* 802.11b/g */
 			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 3);
-		}
+		} else /* IEEE_MODE_11NG */
+			urtwn_write_1(sc, R92C_INIRTS_RATE_SEL, 12); /* MCS 0 */
 
 		/* Enable Rx of data frames. */
 		urtwn_write_2(sc, R92C_RXFLTMAP2, 0x);
@@ -3090,6 +3093,9 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 		R92C_TXDW0_OWN | R92C_TXDW0_FSG | R92C_TXDW0_LSG);
 	}
 
+	if (ic->ic_curmode == IEEE80211_MODE_11NG)
+		txd->txdw5 |= htole32(R92C_TXDW5_SGI);
+
 	if (IEEE80211_IS_MULTICAST(wh->i_addr1))
 		txd->txdw0 |= htole32(R92C_TXDW0_BMCAST);
 
@@ -3104,8 +3110,10 @@ urtwn_tx(struct urtwn_softc *sc, struct 
 	type == IEEE80211_FC0_TYPE_DATA) {
 		if (ic->ic_curmode == IEEE80211_MODE_11B)
 			raid = R92C_RAID_11B;
-		else
+		else if (ic->ic_curmode == IEEE80211_MODE_11G)
 			raid = R92C_RAID_11BG;
+		else	/* IEEE80211_MODE_11NG */
+			raid = R92C_RAID_11GN;
 		DPRINTFN(DBG_TX,
 		("%s: %s: data packet: tid=%d, raid=%d\n",
 		device_xname(sc->sc_dev), __func__, tid, raid));
@@ -3657,6 +3665,7 @@ urtwn_getradiocaps(struct ieee80211com *
 	memset(bands, 0, sizeof(bands));
 	setbit(bands, IEEE80211_MODE_11B);
 	setbit(bands, IEEE80211_MODE_11G);
+	setbit(bands, IEEE80211_MODE_11NG);
 	ieee80211_add_channel_list_2ghz(chans, maxchans, nchans,
 	urtwn_chan_2ghz, nitems(urtwn_chan_2ghz), bands, 0);
 }



CVS commit: [phil-wifi] src/sys/dev

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 17:24:49 UTC 2020

Modified Files:
src/sys/dev/ic [phil-wifi]: rtwnreg.h
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Update with 92EU changes from -current.


To generate a diff of this commit:
cvs rdiff -u -r1.1.8.3 -r1.1.8.4 src/sys/dev/ic/rtwnreg.h
cvs rdiff -u -r1.59.2.10 -r1.59.2.11 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/rtwnreg.h
diff -u src/sys/dev/ic/rtwnreg.h:1.1.8.3 src/sys/dev/ic/rtwnreg.h:1.1.8.4
--- src/sys/dev/ic/rtwnreg.h:1.1.8.3	Mon Apr 13 08:04:22 2020
+++ src/sys/dev/ic/rtwnreg.h	Thu Apr 16 17:24:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtwnreg.h,v 1.1.8.3 2020/04/13 08:04:22 martin Exp $	*/
+/*	$NetBSD: rtwnreg.h,v 1.1.8.4 2020/04/16 17:24:49 nat Exp $	*/
 /*	$OpenBSD: r92creg.h,v 1.16 2017/09/22 13:41:56 kevlo Exp $	*/
 
 /*-
@@ -1341,6 +1341,8 @@ struct r92c_rx_desc_usb {
 
 #define R92C_RXDW2_PKTCNT_M	0x00ff
 #define R92C_RXDW2_PKTCNT_S	16
+#define R92E_RXDW2_PKTCNT_M	0x3fc0
+#define R92E_RXDW2_PKTCNT_S	22
 
 #define R92C_RXDW3_RATE_M	0x003f
 #define R92C_RXDW3_RATE_S	0

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.10 src/sys/dev/usb/if_urtwn.c:1.59.2.11
--- src/sys/dev/usb/if_urtwn.c:1.59.2.10	Thu Apr 16 15:33:07 2020
+++ src/sys/dev/usb/if_urtwn.c	Thu Apr 16 17:24:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.11 2020/04/16 17:24:49 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.11 2020/04/16 17:24:49 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2923,7 +2923,10 @@ urtwn_rxeof(struct usbd_xfer *xfer, void
 
 	/* Get the number of encapsulated frames. */
 	stat = (struct r92c_rx_desc_usb *)buf;
-	npkts = MS(le32toh(stat->rxdw2), R92C_RXDW2_PKTCNT);
+	if (ISSET(sc->chip, URTWN_CHIP_92EU))
+		npkts = MS(le32toh(stat->rxdw2), R92E_RXDW2_PKTCNT);
+	else
+		npkts = MS(le32toh(stat->rxdw2), R92C_RXDW2_PKTCNT);
 	DPRINTFN(DBG_RX, ("%s: %s: Rx %d frames in one chunk\n",
 	device_xname(sc->sc_dev), __func__, npkts));
 



CVS commit: src/sys/dev

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 17:18:28 UTC 2020

Modified Files:
src/sys/dev/ic: rtwnreg.h
src/sys/dev/usb: if_urtwn.c

Log Message:
Correct rx packet count for 8192EU.  Tested OK.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/ic/rtwnreg.h
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/rtwnreg.h
diff -u src/sys/dev/ic/rtwnreg.h:1.2 src/sys/dev/ic/rtwnreg.h:1.3
--- src/sys/dev/ic/rtwnreg.h:1.2	Thu Jul 25 14:31:35 2019
+++ src/sys/dev/ic/rtwnreg.h	Thu Apr 16 17:18:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtwnreg.h,v 1.2 2019/07/25 14:31:35 msaitoh Exp $	*/
+/*	$NetBSD: rtwnreg.h,v 1.3 2020/04/16 17:18:27 nat Exp $	*/
 /*	$OpenBSD: r92creg.h,v 1.16 2017/09/22 13:41:56 kevlo Exp $	*/
 
 /*-
@@ -1341,6 +1341,8 @@ struct r92c_rx_desc_usb {
 
 #define R92C_RXDW2_PKTCNT_M	0x00ff
 #define R92C_RXDW2_PKTCNT_S	16
+#define R92E_RXDW2_PKTCNT_M	0x3fc0
+#define R92E_RXDW2_PKTCNT_S	22
 
 #define R92C_RXDW3_RATE_M	0x003f
 #define R92C_RXDW3_RATE_S	0

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.85 src/sys/dev/usb/if_urtwn.c:1.86
--- src/sys/dev/usb/if_urtwn.c:1.85	Sat Apr  4 08:46:01 2020
+++ src/sys/dev/usb/if_urtwn.c	Thu Apr 16 17:18:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.85 2020/04/04 08:46:01 skrll Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.86 2020/04/16 17:18:27 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.85 2020/04/04 08:46:01 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.86 2020/04/16 17:18:27 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2527,7 +2527,10 @@ urtwn_rxeof(struct usbd_xfer *xfer, void
 
 	/* Get the number of encapsulated frames. */
 	stat = (struct r92c_rx_desc_usb *)buf;
-	npkts = MS(le32toh(stat->rxdw2), R92C_RXDW2_PKTCNT);
+	if (ISSET(sc->chip, URTWN_CHIP_92EU))
+		npkts = MS(le32toh(stat->rxdw2), R92E_RXDW2_PKTCNT);
+	else
+		npkts = MS(le32toh(stat->rxdw2), R92C_RXDW2_PKTCNT);
 	DPRINTFN(DBG_RX, "Rx %jd frames in one chunk", npkts, 0, 0, 0);
 
 	if (npkts != 0)



CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:33:08 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwn.c

Log Message:
Use if_stat functions.


To generate a diff of this commit:
cvs rdiff -u -r1.59.2.9 -r1.59.2.10 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.59.2.9 src/sys/dev/usb/if_urtwn.c:1.59.2.10
--- src/sys/dev/usb/if_urtwn.c:1.59.2.9	Mon Apr 13 08:04:49 2020
+++ src/sys/dev/usb/if_urtwn.c	Thu Apr 16 15:33:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.59.2.9 2020/04/13 08:04:49 martin Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.9 2020/04/13 08:04:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.59.2.10 2020/04/16 15:33:07 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2762,7 +2762,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 		 */
 		DPRINTFN(DBG_RX, ("%s: %s: CRC error\n",
 		device_xname(sc->sc_dev), __func__));
-		ifp->if_ierrors++;
+		if_statinc(ifp, if_ierrors);
 		return;
 	}
 
@@ -2775,13 +2775,13 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 		DPRINTFN(DBG_RX, ("%s: %s: packet too short %d\n",
 		device_xname(sc->sc_dev), __func__, pktlen));
 		vap->iv_stats.is_rx_tooshort++;
-		ifp->if_ierrors++;
+		if_statinc(ifp,if_ierrors);
 		return;
 	}
 	if (__predict_false(pktlen > MCLBYTES)) {
 		DPRINTFN(DBG_RX, ("%s: %s: packet too big %d\n",
 		device_xname(sc->sc_dev), __func__, pktlen));
-		ifp->if_ierrors++;
+   	if_statinc(ifp, if_ierrors);
 		return;
 	}
 
@@ -2805,7 +2805,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 	if (__predict_false(m == NULL)) {
 		aprint_error_dev(sc->sc_dev, "couldn't allocate rx mbuf\n");
 		vap->iv_stats.is_rx_nobuf++;
-		ifp->if_ierrors++;
+   	if_statinc(ifp, if_ierrors);
 		return;
 	}
 	if (pktlen > (int)MHLEN) {
@@ -2815,7 +2815,7 @@ urtwn_rx_frame(struct urtwn_softc *sc, u
 			"couldn't allocate rx mbuf cluster\n");
 			m_freem(m);
 			vap->iv_stats.is_rx_nobuf++;
-			ifp->if_ierrors++;
+	if_statinc(ifp, if_ierrors);
 			return;
 		}
 	}
@@ -3000,13 +3000,13 @@ urtwn_txeof(struct usbd_xfer *xfer, void
 usbd_clear_endpoint_stall_async(pipe);
 			}
 			printf("ERROR1\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 		}
 		splx(s);
 		return;
 	}
 
-	ifp->if_opackets++;
+	if_statinc(ifp, if_opackets);
 	urtwn_start(ifp); 
 	splx(s);
 
@@ -3308,7 +3308,7 @@ urtwn_start(struct ifnet *ifp)
 		if (m->m_len < (int)sizeof(*eh) &&
 		(m = m_pullup(m, sizeof(*eh))) == NULL) {
 			printf("ERROR6\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 		eh = mtod(m, struct ether_header *);
@@ -3316,7 +3316,7 @@ urtwn_start(struct ifnet *ifp)
 		if (ni == NULL) {
 			m_freem(m);
 			printf("ERROR5\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 
@@ -3327,7 +3327,7 @@ urtwn_start(struct ifnet *ifp)
 			m_freem(m);
 			ieee80211_free_node(ni);
 			printf("ERROR3\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			continue;
 		}
 		m_freem(m);
@@ -3352,7 +3352,7 @@ urtwn_watchdog(struct ifnet *ifp)
 			aprint_error_dev(sc->sc_dev, "device timeout\n");
 			/* urtwn_init(ifp); XXX needs a process context! */
 			printf("ERROR2\n");
-			ifp->if_oerrors++;
+	if_statinc(ifp, if_oerrors);
 			return;
 		}
 		ifp->if_timer = 1;
@@ -3449,7 +3449,7 @@ urtwn_parent(struct ieee80211com *ic)
 static void
 urtwn_scan_start(struct ieee80211com *ic)
 {
-	struct urtwn_softc *sc = ic->ic_softc;
+	//struct urtwn_softc *sc = ic->ic_softc;
 	//uint32_t reg;
 	//int s;
 
@@ -3512,7 +3512,7 @@ urtwn_scan_start(struct ieee80211com *ic
 static void
 urtwn_scan_end(struct ieee80211com *ic)
 {
-	struct urtwn_softc *sc = ic->ic_softc;
+	//struct urtwn_softc *sc = ic->ic_softc;
 
 	DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
 
@@ -3565,9 +3565,9 @@ urtwn_transmit(struct ieee80211com *ic, 
 
 IF_ENQUEUE(>sc_sendq, m);
 
-vap->iv_ifp->if_obytes += pktlen;
+if_statadd(vap->iv_ifp, if_obytes, pktlen);
 if (mcast)
-vap->iv_ifp->if_omcasts++;
+if_statinc(vap->iv_ifp, if_omcasts);
 
 if ((vap->iv_ifp->if_flags & IFF_OACTIVE) == 0)
 if_start_lock(vap->iv_ifp);
@@ -3626,7 +3626,7 @@ urtwn_raw_xmit(struct ieee80211_node *ni
 	error = urtwn_tx(sc, m, ni, data);
 	if (error != 0) {
 		printf("ERROR3\n");
-		vap->iv_ifp->if_oerrors++;
+if_statinc(vap->iv_ifp, if_oerrors);
 	} else {
 		sc->tx_timer = 5;
 		

CVS commit: [phil-wifi] src/sys/dev/usb

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:32:24 UTC 2020

Modified Files:
src/sys/dev/usb [phil-wifi]: if_urtwnvar.h

Log Message:
Pull in 


To generate a diff of this commit:
cvs rdiff -u -r1.10.16.5 -r1.10.16.6 src/sys/dev/usb/if_urtwnvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwnvar.h
diff -u src/sys/dev/usb/if_urtwnvar.h:1.10.16.5 src/sys/dev/usb/if_urtwnvar.h:1.10.16.6
--- src/sys/dev/usb/if_urtwnvar.h:1.10.16.5	Mon Apr 13 08:04:49 2020
+++ src/sys/dev/usb/if_urtwnvar.h	Thu Apr 16 15:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwnvar.h,v 1.10.16.5 2020/04/13 08:04:49 martin Exp $	*/
+/*	$NetBSD: if_urtwnvar.h,v 1.10.16.6 2020/04/16 15:32:24 nat Exp $	*/
 /*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
 
 /*-
@@ -19,6 +19,8 @@
 #ifndef _IF_URTWNVAR_H_
 #define _IF_URTWNVAR_H_
 
+#include 
+
 /*
  * Driver definitions.
  */



CVS commit: [phil-wifi] src/sys/net80211

2020-04-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Apr 16 15:30:00 UTC 2020

Modified Files:
src/sys/net80211 [phil-wifi]: ieee80211.c ieee80211_netbsd.c
ieee80211_netbsd.h

Log Message:
Use if_stat functions.


To generate a diff of this commit:
cvs rdiff -u -r1.56.18.8 -r1.56.18.9 src/sys/net80211/ieee80211.c
cvs rdiff -u -r1.31.2.9 -r1.31.2.10 src/sys/net80211/ieee80211_netbsd.c
cvs rdiff -u -r1.21.2.11 -r1.21.2.12 src/sys/net80211/ieee80211_netbsd.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net80211/ieee80211.c
diff -u src/sys/net80211/ieee80211.c:1.56.18.8 src/sys/net80211/ieee80211.c:1.56.18.9
--- src/sys/net80211/ieee80211.c:1.56.18.8	Mon Apr 13 08:05:15 2020
+++ src/sys/net80211/ieee80211.c	Thu Apr 16 15:30:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.56.18.8 2020/04/13 08:05:15 martin Exp $ */
+/*	$NetBSD: ieee80211.c,v 1.56.18.9 2020/04/16 15:30:00 nat Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
 
 #include 
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.56.18.8 2020/04/13 08:05:15 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.56.18.9 2020/04/16 15:30:00 nat Exp $");
 #endif
 
 /*
@@ -2016,7 +2016,13 @@ ieee80211_media_init(struct ieee80211com
 	ifm_change_cb_t media_change, ifm_stat_cb_t media_stat)
 {
 
-	ieee80211_media_init_with_lock(ic, media_change, media_stat, NULL);
+	struct ieee80211vap *vap;
+
+	vap = TAILQ_FIRST(>ic_vaps);
+	KASSERT(vap != NULL, ("media vap is null"));
+
+	ifmedia_init_with_lock(>iv_media, 0, media_change,
+	media_stat, NULL);
 }
 
 void
@@ -2030,8 +2036,8 @@ ieee80211_announce(struct ieee80211com *
 	for (mode = IEEE80211_MODE_AUTO+1; mode < IEEE80211_MODE_11NA; mode++) {
 		if (isclr(ic->ic_modecaps, mode))
 			continue;
-		aprint_debug("%s: %s rates: ", ifp->if_xname,
-		ieee80211_phymode_name[mode]);
+		//aprint_debug("%s: %s rates: ", ifp->if_xname,
+		 //   ieee80211_phymode_name[mode]);
 		ic_printf(ic, "%s rates: ", ieee80211_phymode_name[mode]);
 		rs = >ic_sup_rates[mode];
 		for (i = 0; i < rs->rs_nrates; i++) {

Index: src/sys/net80211/ieee80211_netbsd.c
diff -u src/sys/net80211/ieee80211_netbsd.c:1.31.2.9 src/sys/net80211/ieee80211_netbsd.c:1.31.2.10
--- src/sys/net80211/ieee80211_netbsd.c:1.31.2.9	Tue Nov 19 19:17:16 2019
+++ src/sys/net80211/ieee80211_netbsd.c	Thu Apr 16 15:30:00 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.31.2.9 2019/11/19 19:17:16 phil Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.31.2.10 2020/04/16 15:30:00 nat Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -29,7 +29,7 @@
 
 #include 
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.31.2.9 2019/11/19 19:17:16 phil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.31.2.10 2020/04/16 15:30:00 nat Exp $");
 #endif
 
 /*
@@ -1183,45 +1183,59 @@ wlan_iflladdr(void *arg __unused, struct
 }
 #endif
 
+int64_t
+if_get_counter_default(struct ifnet * ifp, ift_counter cnt)
+{
+	struct if_data if_stats;
+	int64_t result;
+
+	if_stats_to_if_data(ifp, _stats, false);
+
+	result = (cnt == IFCOUNTER_OERRORS ? if_stats.ifi_oerrors :
+	(cnt == IFCOUNTER_IERRORS ? if_stats.ifi_ierrors : 0 ));
+
+	return result;
+}
+
 void
 if_inc_counter(struct ifnet *ifp, ift_counter ifc, int64_t value)
 {
 	switch (ifc) {
 	case IFCOUNTER_IPACKETS:
-		ifp->if_data.ifi_ipackets += value;
+		if_statadd(ifp, if_ipackets, value);
 		break;
 	case IFCOUNTER_IERRORS:
-		ifp->if_data.ifi_ierrors += value;
+		if_statadd(ifp, if_ierrors, value);
 		break;
 	case IFCOUNTER_OPACKETS:
-		ifp->if_data.ifi_opackets += value;
+		if_statadd(ifp, if_opackets, value);
 		break;
 	case IFCOUNTER_OERRORS:
-		ifp->if_data.ifi_oerrors += value;
+		if_statadd(ifp, if_oerrors, value);
 		break;
 case IFCOUNTER_COLLISIONS:
-		ifp->if_data.ifi_collisions += value;
+		if_statadd(ifp, if_collisions, value);
 		break;
 case IFCOUNTER_IBYTES:
-		ifp->if_data.ifi_ibytes += value;
+		if_statadd(ifp, if_ibytes, value);
 		break;
 case IFCOUNTER_OBYTES:
-		ifp->if_data.ifi_obytes += value;
+		if_statadd(ifp, if_obytes, value);
 		break;
 case IFCOUNTER_IMCASTS:
-		ifp->if_data.ifi_imcasts += value;
+		if_statadd(ifp, if_imcasts, value);
 		break;
 case IFCOUNTER_OMCASTS:
-		ifp->if_data.ifi_omcasts += value;
+		if_statadd(ifp, if_omcasts, value);
 		break;
 case IFCOUNTER_IQDROPS:
-		ifp->if_data.ifi_iqdrops += value;
+		if_statadd(ifp, if_iqdrops, value);
 		break;
 case IFCOUNTER_OQDROPS:
 		/* ifp->if_data.ifi_oqdrops += value; No such field, just ignore it q*/
 		break;
 case IFCOUNTER_NOPROTO:
-		ifp->if_data.ifi_noproto += value;
+		if_statadd(ifp, if_noproto, value);
 		break;
 	default:
 		panic("if_inc_counter: non-existant counter");

Index: src/sys/net80211/ieee80211_netbsd.h
diff -u 

CVS commit: src/doc

2019-05-08 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed May  8 22:01:47 UTC 2019

Modified Files:
src/doc: RESPONSIBLE

Log Message:
Sync with reality.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/doc/RESPONSIBLE

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/RESPONSIBLE
diff -u src/doc/RESPONSIBLE:1.122 src/doc/RESPONSIBLE:1.123
--- src/doc/RESPONSIBLE:1.122	Fri Nov  9 07:54:25 2018
+++ src/doc/RESPONSIBLE	Wed May  8 22:01:47 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: RESPONSIBLE,v 1.122 2018/11/09 07:54:25 mbalmer Exp $
+#	$NetBSD: RESPONSIBLE,v 1.123 2019/05/08 22:01:47 nat Exp $
 
 List of sections of the system, and who is responsible for them (or at
 least considered an expert on them).
@@ -117,7 +117,7 @@ Kernel:
 device support:
 
 acpi		thorpej*, kochi*, jmcneill, joerg
-audio		augustss*, jmcneill, nat
+audio		augustss*, jmcneill
 cgd		elric
 firewire	jmc*
 flash		ahoka



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2019-03-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Mar 31 11:44:11 UTC 2019

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: sbc_encode.c

Log Message:
Opps... Remove extra ')'


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.4 src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.5
--- src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.4	Sun Mar 31 11:33:27 2019
+++ src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c	Sun Mar 31 11:44:11 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sbc_encode.c,v 1.4 2019/03/31 11:33:27 nat Exp $ */
+/* $NetBSD: sbc_encode.c,v 1.5 2019/03/31 11:44:11 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss 
@@ -609,7 +609,7 @@ sbc_decode(int32_t *samples, int16_t *pc
 	audioout = samples[numsamples]
 	* 2) + 1) * delta[chan][sb]) /
 	levels[chan][sb]) -
-	delta[chan][sb]);
+	delta[chan][sb];
 }
 samples[numsamples] = (int32_t)audioout;
 numsamples++;



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2019-03-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Mar 31 11:33:27 UTC 2019

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: sbc_encode.c

Log Message:
Remove dead code from sbc decoder.

Found by Hans Petter Selasky.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.3 src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.4
--- src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c:1.3	Sat May 27 10:04:57 2017
+++ src/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c	Sun Mar 31 11:33:27 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sbc_encode.c,v 1.3 2017/05/27 10:04:57 nat Exp $ */
+/* $NetBSD: sbc_encode.c,v 1.4 2019/03/31 11:33:27 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss 
@@ -606,10 +606,10 @@ sbc_decode(int32_t *samples, int16_t *pc
 if (bits[chan][sb] == 0)
 	audioout = 0;
 else {
-	audioout = (samples[numsamples]
-	* 2) + 1) * delta[chan][sb])/
+	audioout = samples[numsamples]
+	* 2) + 1) * delta[chan][sb]) /
 	levels[chan][sb]) -
-	(1 * delta[chan][sb]));
+	delta[chan][sb]);
 }
 samples[numsamples] = (int32_t)audioout;
 numsamples++;



CVS commit: src/sys/dev

2018-06-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jun 23 03:18:49 UTC 2018

Modified Files:
src/sys/dev: auconv.c

Log Message:
Add all encoding supported by the mixer.

Addresses PR kern/52585.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/dev/auconv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/auconv.c
diff -u src/sys/dev/auconv.c:1.35 src/sys/dev/auconv.c:1.36
--- src/sys/dev/auconv.c:1.35	Sat Dec 16 16:09:36 2017
+++ src/sys/dev/auconv.c	Sat Jun 23 03:18:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.c,v 1.35 2017/12/16 16:09:36 nat Exp $	*/
+/*	$NetBSD: auconv.c,v 1.36 2018/06/23 03:18:49 nat Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.35 2017/12/16 16:09:36 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.36 2018/06/23 03:18:49 nat Exp $");
 
 #include 
 #include 
@@ -2340,8 +2340,9 @@ auconv_create_encodings(const struct aud
 {
 	struct audio_encoding_set *buf;
 	int capacity;
-	int i;
+	int i, j;
 	int err;
+	static int enc_precision[] = { 16, 32 };
 
 #define	ADD_ENCODING(enc, prec, flags)	do { \
 	err = auconv_add_encoding(enc, prec, flags, , ); \
@@ -2358,120 +2359,33 @@ auconv_create_encodings(const struct aud
 	for (i = 0; i < nformats; i++) {
 		if (!AUFMT_IS_VALID([i]))
 			continue;
-		switch (formats[i].encoding) {
-		case AUDIO_ENCODING_SLINEAR_LE:
-			ADD_ENCODING(formats[i].encoding,
- formats[i].precision, 0);
-			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_BE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_LE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_BE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-#if NMULAW > 0
-			if (formats[i].precision == 8
-			|| formats[i].precision == 16) {
-ADD_ENCODING(AUDIO_ENCODING_ULAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-ADD_ENCODING(AUDIO_ENCODING_ALAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-			}
-#endif
-			break;
-		case AUDIO_ENCODING_SLINEAR_BE:
-			ADD_ENCODING(formats[i].encoding,
- formats[i].precision, 0);
-			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_LE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_LE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_BE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-#if NMULAW > 0
-			if (formats[i].precision == 8
-			|| formats[i].precision == 16) {
-ADD_ENCODING(AUDIO_ENCODING_ULAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-ADD_ENCODING(AUDIO_ENCODING_ALAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-			}
-#endif
-			break;
-		case AUDIO_ENCODING_ULINEAR_LE:
-			ADD_ENCODING(formats[i].encoding,
- formats[i].precision, 0);
+
+		for (j = 0; j < __arraycount(enc_precision); j++) {
 			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_BE,
- formats[i].precision,
+ enc_precision[j],
  AUDIO_ENCODINGFLAG_EMULATED);
 			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_LE,
- formats[i].precision,
+ enc_precision[j],
  AUDIO_ENCODINGFLAG_EMULATED);
 			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_BE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-#if NMULAW > 0
-			if (formats[i].precision == 8
-			|| formats[i].precision == 16) {
-ADD_ENCODING(AUDIO_ENCODING_ULAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-ADD_ENCODING(AUDIO_ENCODING_ALAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-			}
-#endif
-			break;
-		case AUDIO_ENCODING_ULINEAR_BE:
-			ADD_ENCODING(formats[i].encoding,
- formats[i].precision, 0);
-			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_BE,
- formats[i].precision,
+ enc_precision[j],
  AUDIO_ENCODINGFLAG_EMULATED);
 			ADD_ENCODING(AUDIO_ENCODING_ULINEAR_LE,
- formats[i].precision,
- AUDIO_ENCODINGFLAG_EMULATED);
-			ADD_ENCODING(AUDIO_ENCODING_SLINEAR_LE,
- formats[i].precision,
+ enc_precision[j],
  AUDIO_ENCODINGFLAG_EMULATED);
-#if NMULAW > 0
-			if (formats[i].precision == 8
-			|| formats[i].precision == 16) {
-ADD_ENCODING(AUDIO_ENCODING_ULAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-ADD_ENCODING(AUDIO_ENCODING_ALAW, 8,
-	 AUDIO_ENCODINGFLAG_EMULATED);
-			}
-#endif
-			break;
-
-		case AUDIO_ENCODING_ULAW:
-		case AUDIO_ENCODING_ALAW:
-		case AUDIO_ENCODING_ADPCM:
-		case AUDIO_ENCODING_MPEG_L1_STREAM:
-		case AUDIO_ENCODING_MPEG_L1_PACKETS:
-		case AUDIO_ENCODING_MPEG_L1_SYSTEM:
-		case AUDIO_ENCODING_MPEG_L2_STREAM:
-		case AUDIO_ENCODING_MPEG_L2_PACKETS:
-		case AUDIO_ENCODING_MPEG_L2_SYSTEM:
-		case AUDIO_ENCODING_AC3:
-			

CVS commit: src/usr.bin/fstat

2018-06-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Jun  4 01:42:49 UTC 2018

Modified Files:
src/usr.bin/fstat: misc.c

Log Message:
Update fstat for audio(4) and pad(4) devices.

XXX - pullup 8.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/fstat/misc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/fstat/misc.c
diff -u src/usr.bin/fstat/misc.c:1.17 src/usr.bin/fstat/misc.c:1.18
--- src/usr.bin/fstat/misc.c:1.17	Fri Dec 30 21:08:23 2016
+++ src/usr.bin/fstat/misc.c	Mon Jun  4 01:42:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $	*/
+/*	$NetBSD: misc.c,v 1.18 2018/06/04 01:42:49 nat Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $");
+__RCSID("$NetBSD: misc.c,v 1.18 2018/06/04 01:42:49 nat Exp $");
 
 #include 
 #include 
@@ -102,7 +102,11 @@ static struct nlist nl[] = {
 { .n_name = "vnops" },
 #define NL_XENEVT	17
 { .n_name = "xenevt_fileops" },
-#define NL_MAX		18
+#define NL_AUDIO	18
+{ .n_name = "audio_fileops" },
+#define NL_PAD		19
+{ .n_name = "pad_fileops" },
+#define NL_MAX		20
 { .n_name = NULL }
 };
 
@@ -277,6 +281,12 @@ pmisc(struct file *f, const char *name)
 	case NL_CRYPTO:
 		printf("* crypto %p\n", f->f_data);
 		return 0;
+	case NL_AUDIO:
+		printf("* audio %p\n", f->f_data);
+		return 0;
+	case NL_PAD:
+		printf("* pad %p\n", f->f_data);
+		return 0;
 	case NL_MAX:
 		printf("* %s ops=%p %p\n", name, f->f_ops, f->f_data);
 		return 0;



CVS commit: src/sys/dev/usb

2018-06-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Jun  1 19:19:54 UTC 2018

Modified Files:
src/sys/dev/usb: if_urtwn.c

Log Message:
Fix support for 8192eu, notably TPLINK TL-WN823NV2, by using the right
registers when setting receiver gain.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/usb/if_urtwn.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwn.c
diff -u src/sys/dev/usb/if_urtwn.c:1.57 src/sys/dev/usb/if_urtwn.c:1.58
--- src/sys/dev/usb/if_urtwn.c:1.57	Thu Feb  8 09:05:20 2018
+++ src/sys/dev/usb/if_urtwn.c	Fri Jun  1 19:19:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwn.c,v 1.57 2018/02/08 09:05:20 dholland Exp $	*/
+/*	$NetBSD: if_urtwn.c,v 1.58 2018/06/01 19:19:54 nat Exp $	*/
 /*	$OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $	*/
 
 /*-
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.57 2018/02/08 09:05:20 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.58 2018/06/01 19:19:54 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3800,12 +3800,19 @@ urtwn_bb_init(struct urtwn_softc *sc)
 		DELAY(1);
 		urtwn_bb_write(sc, R92C_OFDM0_AGCCORE1(0), 0x69553420);
 		DELAY(1);
+	}
 
-		if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
-			urtwn_write_2(sc, R92C_AFE_CTRL3, urtwn_read_2(sc,
-			R92C_AFE_CTRL3));
-		}
-
+	if (ISSET(sc->chip, URTWN_CHIP_92EU)) {
+		crystalcap = sc->r88e_rom[0xb9];
+		if (crystalcap == 0x00)
+			crystalcap = 0x20;
+		crystalcap &= 0x3f;
+		reg = urtwn_bb_read(sc, R92C_AFE_CTRL3);
+		urtwn_bb_write(sc, R92C_AFE_CTRL3,
+		RW(reg, R92C_AFE_XTAL_CTRL_ADDR,
+		crystalcap | crystalcap << 6));
+		urtwn_write_4(sc, R92C_AFE_XTAL_CTRL, 0xf81fb);
+	} else if (ISSET(sc->chip, URTWN_CHIP_88E)) {
 		crystalcap = sc->r88e_rom[0xb9];
 		if (crystalcap == 0xff)
 			crystalcap = 0x20;



CVS commit: src/sys/dev/usb

2018-06-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Jun  1 19:17:04 UTC 2018

Modified Files:
src/sys/dev/usb: if_urtwnreg.h

Log Message:
Add another register as found on 8192eu.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/usb/if_urtwnreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/if_urtwnreg.h
diff -u src/sys/dev/usb/if_urtwnreg.h:1.10 src/sys/dev/usb/if_urtwnreg.h:1.11
--- src/sys/dev/usb/if_urtwnreg.h:1.10	Wed Oct 12 03:23:29 2016
+++ src/sys/dev/usb/if_urtwnreg.h	Fri Jun  1 19:17:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_urtwnreg.h,v 1.10 2016/10/12 03:23:29 nat Exp $	*/
+/*	$NetBSD: if_urtwnreg.h,v 1.11 2018/06/01 19:17:04 nat Exp $	*/
 /*	$OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $	*/
 
 /*-
@@ -83,6 +83,7 @@
 #define R92C_FSISR			0x054
 #define R92C_HSIMR			0x058
 #define R92C_HSISR			0x05c
+#define R92C_PAD_CTRL			0x064
 #define R92C_AFE_CTRL4			0x078
 #define R92C_MCUFWDL			0x080
 #define R92C_HMEBOX_EXT(idx)		(0x088 + (idx) * 2)



CVS commit: src

2018-05-27 Thread Nathanial Sloss
are/man/man4/audio.4:1.85	Tue May 15 00:54:01 2018
+++ src/share/man/man4/audio.4	Mon May 28 00:18:05 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.85 2018/05/15 00:54:01 nat Exp $
+.\"	$NetBSD: audio.4,v 1.86 2018/05/28 00:18:05 nat Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -812,7 +812,7 @@ string values.
 .Ss USB
 .Xr uaudio 4
 .Ss The NetBSD audio specification
-.Xr audio 7
+.Xr audio_system 9
 .Sh HISTORY
 Support for virtual channels and mixing first appeared in
 .Nx 8.0 .

Index: src/share/man/man7/Makefile
diff -u src/share/man/man7/Makefile:1.32 src/share/man/man7/Makefile:1.33
--- src/share/man/man7/Makefile:1.32	Tue May 15 00:54:01 2018
+++ src/share/man/man7/Makefile	Mon May 28 00:18:06 2018
@@ -1,14 +1,14 @@
-#	$NetBSD: Makefile,v 1.32 2018/05/15 00:54:01 nat Exp $
+#	$NetBSD: Makefile,v 1.33 2018/05/28 00:18:06 nat Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/5/93
 
 .include 
 
 # missing: eqnchar.7 man.7 ms.7 term.7
 
-MAN=	ascii.7 audio.7 c.7 environ.7 glob.7 hier.7 hostname.7 intro.7 \
-	mailaddr.7 module.7 nls.7 operator.7 orders.7 pkgsrc.7 release.7 \
-	rfc6056.7 security.7 script.7 setuid.7 signal.7 src.7 sticky.7 \
-	symlink.7 sysctl.7 tests.7
+MAN=	ascii.7 c.7 environ.7 glob.7 hier.7 hostname.7 intro.7 mailaddr.7 \
+	module.7 nls.7 operator.7 orders.7 pkgsrc.7 release.7  rfc6056.7 \
+	security.7 script.7 setuid.7 signal.7 src.7 sticky.7 symlink.7 \
+	sysctl.7 tests.7
 
 CLEANFILES=	tests.7
 .if ${MKKYUA} != "no"

Index: src/share/man/man7/intro.7
diff -u src/share/man/man7/intro.7:1.25 src/share/man/man7/intro.7:1.26
--- src/share/man/man7/intro.7:1.25	Tue May 15 09:13:36 2018
+++ src/share/man/man7/intro.7	Mon May 28 00:18:06 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: intro.7,v 1.25 2018/05/15 09:13:36 wiz Exp $
+.\"	$NetBSD: intro.7,v 1.26 2018/05/28 00:18:06 nat Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -40,9 +40,6 @@ This section contains miscellaneous docu
 .Bl -tag -width "mdoc.samples(7)" -offset indent
 .It Xr ascii 7
 map of ASCII character set
-.It Xr audio 7
-the
-.Nx audio specification
 .It Xr c 7
 the C programming language
 .It Xr environ 7

Index: src/share/man/man9/Makefile
diff -u src/share/man/man9/Makefile:1.421 src/share/man/man9/Makefile:1.422
--- src/share/man/man9/Makefile:1.421	Sun May 27 21:09:39 2018
+++ src/share/man/man9/Makefile	Mon May 28 00:18:06 2018
@@ -1,9 +1,9 @@
-#   $NetBSD: Makefile,v 1.421 2018/05/27 21:09:39 maya Exp $
+#   $NetBSD: Makefile,v 1.422 2018/05/28 00:18:06 nat Exp $
 
 #	Makefile for section 9 (kernel function and variable) manual pages.
 
 MAN=	accept_filter.9 accf_data.9 accf_http.9 \
-	altq.9 arp.9 audio.9 autoconf.9 \
+	altq.9 arp.9 audio.9 audio_system.9 autoconf.9 \
 	bcdtobin.9 bcmp.9 bcopy.9 bintime_add.9 bluetooth.9 boothowto.9 bpf.9 \
 	buffercache.9 bufferio.9 bufq.9 bus_dma.9 bus_space.9 byteorder.9 \
 	bzero.9 \

Index: src/share/man/man9/audio.9
diff -u src/share/man/man9/audio.9:1.46 src/share/man/man9/audio.9:1.47
--- src/share/man/man9/audio.9:1.46	Tue May 15 00:54:01 2018
+++ src/share/man/man9/audio.9	Mon May 28 00:18:06 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.9,v 1.46 2018/05/15 00:54:01 nat Exp $
+.\"	$NetBSD: audio.9,v 1.47 2018/05/28 00:18:06 nat Exp $
 .\"
 .\" Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -592,7 +592,7 @@ of class
 .Dv AudioCmonitor .
 .Sh SEE ALSO
 .Xr audio 4 ,
-.Xr audio 7
+.Xr audio_system 9
 .Sh HISTORY
 This
 .Nm

Index: src/share/man/man9/intro.9
diff -u src/share/man/man9/intro.9:1.19 src/share/man/man9/intro.9:1.20
--- src/share/man/man9/intro.9:1.19	Sun Nov 12 21:07:15 2017
+++ src/share/man/man9/intro.9	Mon May 28 00:18:06 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: intro.9,v 1.19 2017/11/12 21:07:15 riastradh Exp $
+.\" $NetBSD: intro.9,v 1.20 2018/05/28 00:18:06 nat Exp $
 .\"
 .\" Copyright (c) 1997, 2007 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -435,6 +435,11 @@ Interface between low and high level aud
 See
 .Xr audio 9 .
 .Pp
+The
+.Nx audio specification.
+See
+.Xr audio_system 9 .
+.Pp
 Bluetooth Device/Protocol API.
 See
 .Xr bluetooth 9 .

Added files:

Index: src/share/man/man9/audio_system.9
diff -u /dev/null src/share/man/man9/audio_system.9:1.1
--- /dev/null	Mon May 28 00:18:06 2018
+++ src/share/man/man9/audio_system.9	Mon May 28 00:18:06 2018
@@ -0,0 +1,307 @@
+.\"	$NetBSD: audio_system.9,v 1.1 2018/05/28 00:18:06 nat Exp $
+.\"
+.\" Copyright (c) 2016 - 2018  Nathanial Sloss <nathanialsl...@yahoo.com.au>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code

CVS commit: src

2018-05-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 22 01:35:49 UTC 2018

Modified Files:
src/share/man/man7: audio.7
src/sys/dev: audio.c

Log Message:
Using audioctl without the -p switch defaults to the mix ring.  This allows
setting the hardware gain etc.

Update the audio spec in audio.7 to reflect these changes.

Addresses PR kern/52781.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/man/man7/audio.7
cvs rdiff -u -r1.456 -r1.457 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man7/audio.7
diff -u src/share/man/man7/audio.7:1.2 src/share/man/man7/audio.7:1.3
--- src/share/man/man7/audio.7:1.2	Tue May 15 09:30:01 2018
+++ src/share/man/man7/audio.7	Tue May 22 01:35:49 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.7,v 1.2 2018/05/15 09:30:01 wiz Exp $
+.\"	$NetBSD: audio.7,v 1.3 2018/05/22 01:35:49 nat Exp $
 .\"
 .\" Copyright (c) 2016 - 2018  Nathanial Sloss <nathanialsl...@yahoo.com.au>
 .\" All rights reserved.
@@ -144,7 +144,7 @@ device so to check on buffer usage and s
 .Pp
 As opening an
 .Xr audioctl 4
-device would result in a new vchan being created, these
+device would represent vchan 0 (the mix ring), these
 ioctls allow setting the target vchan and
 .Vt audio_info
 structure to that of an existing vchan.
@@ -188,22 +188,21 @@ are numbered starting at zero (0).
 .Pp
 Not specifying
 .Fl p
-will result in working with a new vchan and this is only
-desired when the next subsequent audio open is to be
-.Pa /dev/sound ,
-i.e.:
+is the same as specifying
+.Fl p
+0 and will result in working with vchan 0 (the mix ring).
+This will display the audio parameters of the mix ring and allow
+setting the hardware gain and balance.
 .Pp
-.Dl audioctl -w play.gain=120
-.Dl open /dev/sound this will have an initial software volume level of 120.
+This is for compatibility with existing applications and shell scrpits
+that are unaware of the
+.Fl p
+switch.
 .Pp
 The parameters for playback and recording only effect the particular vchan
 being operated on (gain, sample rate, channels, encoding etc), except
 .Fl p Ar 0
 (the mix ring).
-Specifying
-.Fl p Ar 0
-will display the audio parameters of the mix ring and allow
-setting the hardware gain and balance.
 .Sh ADDED SYSCTLS
 With the introduction of the audio mixer the following
 .Xr sysctl 7 Ns s

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.456 src/sys/dev/audio.c:1.457
--- src/sys/dev/audio.c:1.456	Thu May 17 11:35:31 2018
+++ src/sys/dev/audio.c	Tue May 22 01:35:49 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.456 2018/05/17 11:35:31 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.457 2018/05/22 01:35:49 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.456 2018/05/17 11:35:31 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.457 2018/05/22 01:35:49 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -234,6 +234,8 @@ int	audiosetinfo(struct audio_softc *, s
 int	audiogetinfo(struct audio_softc *, struct audio_info *, int,
 		 struct virtual_channel *);
 
+int	audioctl_open(dev_t, struct audio_softc *, int, int, struct lwp *,
+		   struct file **);
 int	audio_open(dev_t, struct audio_softc *, int, int, struct lwp *,
 		   struct file **);
 int	audio_close(struct audio_softc *, int, struct audio_chan *);
@@ -1678,9 +1680,11 @@ audioopen(dev_t dev, int flags, int ifmt
 	switch (AUDIODEV(dev)) {
 	case SOUND_DEVICE:
 	case AUDIO_DEVICE:
-	case AUDIOCTL_DEVICE:
 		error = audio_open(dev, sc, flags, ifmt, l, );
 		break;
+	case AUDIOCTL_DEVICE:
+		error = audioctl_open(dev, sc, flags, ifmt, l, );
+		break;
 	case MIXER_DEVICE:
 		error = mixer_open(dev, sc, flags, ifmt, l, );
 		break;
@@ -1714,9 +1718,11 @@ audioclose(struct file *fp)
 	switch (AUDIODEV(dev)) {
 	case SOUND_DEVICE:
 	case AUDIO_DEVICE:
-	case AUDIOCTL_DEVICE:
 		error = audio_close(sc, fp->f_flag, chan);
 		break;
+	case AUDIOCTL_DEVICE:
+		error = 0;
+		break;
 	case MIXER_DEVICE:
 		error = mixer_close(sc, fp->f_flag, chan);
 		break;
@@ -2144,6 +2150,50 @@ audio_calcwater(struct audio_softc *sc, 
 }
 
 int
+audioctl_open(dev_t dev, struct audio_softc *sc, int flags, int ifmt,
+struct lwp *l, struct file **nfp)
+{
+	struct file *fp;
+	int error, fd;
+	const struct audio_hw_if *hw;
+	struct virtual_channel *vc;
+	struct audio_chan *chan;
+
+	KASSERT(mutex_owned(sc->sc_lock));
+
+	if (sc->sc_usemixer && !sc->sc_ready)
+		return ENXIO;
+
+	hw = sc->hw_if;
+	if (hw == NULL)
+		return ENXIO;
+
+	chan = kmem_zalloc(sizeof(struct audio_chan), KM_SLEEP);
+	if (sc->sc_usemixer)
+		vc = >sc_mixring;
+	else
+		vc = sc->sc_hwvc;
+	chan->vc = vc;
+
+	error = fd_allocfile(, );
+	if (error)
+	

CVS commit: src/sys/dev

2018-05-17 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu May 17 11:35:31 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Fix a typo with sc_out/inports when setting the hardware recording gain on the
mix ring.  Found by mrg@

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.455 -r1.456 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.455 src/sys/dev/audio.c:1.456
--- src/sys/dev/audio.c:1.455	Tue May 15 10:23:03 2018
+++ src/sys/dev/audio.c	Thu May 17 11:35:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.456 2018/05/17 11:35:31 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.456 2018/05/17 11:35:31 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4766,8 +4766,8 @@ done:
 
 	if (SPECIFIED(r->gain)) {
 		if (!sc->sc_usemixer || vc == >sc_mixring) {
-			au_get_gain(sc, >sc_outports, , );
-			error = au_set_gain(sc, >sc_outports, r->gain, balance);
+			au_get_gain(sc, >sc_inports, , );
+			error = au_set_gain(sc, >sc_inports, r->gain, balance);
 			if (error)
 goto cleanup;
 		} else



CVS commit: src/sys/dev

2018-05-15 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 10:23:03 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Fix over cautious compiler error - setmode may not be initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.454 -r1.455 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.454 src/sys/dev/audio.c:1.455
--- src/sys/dev/audio.c:1.454	Tue May 15 00:28:00 2018
+++ src/sys/dev/audio.c	Tue May 15 10:23:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.455 2018/05/15 10:23:03 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4567,6 +4567,7 @@ audiosetinfo(struct audio_softc *sc, str
 	pp = vc->sc_pparams;	/* Temporary encoding storage in */
 	rp = vc->sc_rparams;	/* case setting the modes fails. */
 	nr = np = 0;
+	setmode = 0;
 
 	if (vc == >sc_mixring)
 		goto done;
@@ -4624,7 +4625,6 @@ audiosetinfo(struct audio_softc *sc, str
 	if (np > 0 && (error = audio_check_params()))
 		return error;
 
-	setmode = 0;
 	if (nr > 0) {
 		if (!cleared) {
 			audio_clear_intr_unlocked(sc, vc);



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2018-05-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 04:25:25 UTC 2018

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: bta2dpd.8

Log Message:
Use the correct tag options.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.2 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.3
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8:1.2	Sat Jan 28 23:52:45 2017
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.8	Tue May 15 04:25:25 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: bta2dpd.8,v 1.2 2017/01/28 23:52:45 wiz Exp $
+.\"	$NetBSD: bta2dpd.8,v 1.3 2018/05/15 04:25:25 nat Exp $
 .\"
 .\" Copyright (c) 2015 - 2016  Nathanial Sloss <nathanialsl...@yahoo.com.au>
 .\" All rights reserved.
@@ -85,7 +85,7 @@ The
 daemon is used to transmit/receive audio to/from Bluetooth devices such as
 speakers or headphones, using the Advanced Audio Distribution Profile
 (A2DP).
-.Bl -tag -indent width
+.Bl -tag -width indent
 .It Fl a Ar address
 Remote device address.
 The
@@ -165,7 +165,7 @@ command as stated in
 .Sx EXAMPLES .
 .El
 .Ss Channel Modes
-.Bl -tag -indent width
+.Bl -tag -width indent
 .It Fl f Ar channel_mode
 .Bl -tag -width 2n
 .It Ar 0
@@ -194,9 +194,9 @@ This defaults to 44.1 kHz.
 A value of 0 will arbitrate from the highest to lowest frequency.
 .El
 .Ss Sub Band Codec (SBC) Encoding Options
-.Bl -tag -indent width
+.Bl -tag -width indent
 .It Fl A Ar bitpool_allocation
-.Bl -tag width 2n
+.Bl -tag -width 2n
 .It Ar 0
 Bit Allocation is negotiated starting with Loudness then SNR.
 .It Ar S



CVS commit: src/share/man/man7

2018-05-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 01:07:37 UTC 2018

Modified Files:
src/share/man/man7: intro.7

Log Message:
Update the introduction page to section 7 of the manual noting the audio
spec.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/share/man/man7/intro.7

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man7/intro.7
diff -u src/share/man/man7/intro.7:1.23 src/share/man/man7/intro.7:1.24
--- src/share/man/man7/intro.7:1.23	Sun Jul  1 16:18:00 2012
+++ src/share/man/man7/intro.7	Tue May 15 01:07:37 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: intro.7,v 1.23 2012/07/01 16:18:00 christos Exp $
+.\"	$NetBSD: intro.7,v 1.24 2018/05/15 01:07:37 nat Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)intro.7	8.1 (Berkeley) 6/5/93
 .\"
-.Dd July 1, 2012
+.Dd May 15, 2018
 .Dt INTRO 7
 .Os
 .Sh NAME
@@ -42,6 +42,9 @@ This section contains miscellaneous docu
 map of
 .Tn ASCII
 character set
+.It Xr audio 7
+the
+.Nx audio specification
 .It Xr c 7
 the C programming language
 .It Xr environ 7



CVS commit: src

2018-05-14 Thread Nathanial Sloss
 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 13, 2014
+.Dd May 15, 2018
 .Dt AUDIO 9
 .Os
 .Sh NAME
@@ -591,7 +591,8 @@ and that is a control named
 of class
 .Dv AudioCmonitor .
 .Sh SEE ALSO
-.Xr audio 4
+.Xr audio 4 ,
+.Xr audio 7
 .Sh HISTORY
 This
 .Nm

Added files:

Index: src/share/man/man7/audio.7
diff -u /dev/null src/share/man/man7/audio.7:1.1
--- /dev/null	Tue May 15 00:54:02 2018
+++ src/share/man/man7/audio.7	Tue May 15 00:54:01 2018
@@ -0,0 +1,251 @@
+.\"	$NetBSD: audio.7,v 1.1 2018/05/15 00:54:01 nat Exp $
+.\"
+.\" Copyright (c) 2016 - 2018  Nathanial Sloss <nathanialsl...@yahoo.com.au>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd May 4, 2018
+.Dt AUDIO 7
+.Os
+.Sh NAME
+.Nm audio
+.Nd the
+.Nx
+in-kernel audio mixer specification
+.Sh INTRODUCTION
+This document aims to describe all aspects of the in-kernel audio mixer
+included with
+.Nx 8 and onwards.
+Describing its current behavior as of 2018.
+.Sh VIRTUAL CHANNEL (VCHAN)
+This is the most fundamental element to the mixer.
+The vchan has all of the properties of the traditional single open
+.Nx
+audio channel.
+It consists of playback and record rings along with audio_info structures.
+.Pp
+Upon opening of /dev/audio or /dev/sound a new vchan and mixerctl structure is
+created.
+In the case of /dev/sound, audio_info structures are inherited from the last
+open of /dev/audio or /dev/sound.
+.Pp
+All vchans are up or down sampled into the mix ring (intermediate) format
+before being sent to hardware.
+.Pp
+It is described in the following diagram:
+.Bd -literal
+	VCHAN1-\\
+			\\   VCHAN0
+	VCHAN2-MIX RING  HARDWARE
+		... /
+	VCHANn-/
+.Ed
+.Pp
+In the case of sysctl usemixer=0 (see below) there is only one vchan whose play
+and record rings are the hardware play/record rings.
+.Pp
+User accessible vchans are numbered starting at one(1).
+Vchan 0 is used internaly by the mixer for the mix ring and its ring buffers
+are not user accessible.
+.Pp
+The only limit to the number of open vchans is the speed of the computer and the
+number of free file descriptors.
+.Sh BLOCK - SIZE / LATENCY
+A block of audio data is the basic unit for audio data.
+Audio applications will not commence play back until three(3) blocks have been
+written - this is the source of latency in the mixer along with the size of the
+audio data block.
+.Pp
+For normal uses audio read/write their will be three blocks of audio data before
+play back commences one in the vchan, one in the mix ring and one in the
+hardware ring.
+.Pp
+The size of the audio data block is dependent on the audio format configured
+by the application the latency sysctl and the underlying audio hardware.
+.Pp
+Some audio hardware devices only support a static block size, as such the
+overall latency of the mixer for these devices cannot be changed.
+Other devices such as those supported by hdaudio allow the hardware block size
+to be changed, allowing the latency of the mixer to change from 4
+milliseconds(ms) to 128 ms with the mixer intermediate format being 16 bit,
+stereo, 48 kHz.
+.Pp
+With regard to mmapped audio, blocks are played back immediately so the latency
+presented to applications is one third of the latency sysctl value.
+.Pp
+Latency can be calculated by the following formula:
+.Bd -literal
+	Latency (ms) =	 blocksize(bytes) * num blocks * 1000
+			--
+			freq(Hz) * bytes per sample * c

CVS commit: src/sys/dev

2018-05-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 00:28:00 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Expose the audio_info structure of vchan zero(0) the mix ring to allow
setting the hardware gain and balance via audioctl(1) using the -p 0
switch.

It is not possible to influence the hardware gain/blance from the
audio_info structure of vchans 1 onwards.  It is now possible to return
the audio mixers audio format from the audio_info structure of vchan 0 to
ease applications configuring for mmapped play back.

This is conformant to the audio specification posted on tech-kern see:
"NetBSD Audio Specification 2018"
or audio.7 manual page to be added in a follow up commit.


To generate a diff of this commit:
cvs rdiff -u -r1.453 -r1.454 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.453 src/sys/dev/audio.c:1.454
--- src/sys/dev/audio.c:1.453	Tue May 15 00:19:08 2018
+++ src/sys/dev/audio.c	Tue May 15 00:28:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.453 2018/05/15 00:19:08 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.453 2018/05/15 00:19:08 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.454 2018/05/15 00:28:00 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3076,7 +3076,7 @@ audio_ioctl(dev_t dev, struct audio_soft
 
 	KASSERT(mutex_owned(sc->sc_lock));
 
-	if (sc->sc_usemixer) {
+	if (sc->sc_usemixer && chan->deschan != 0) {
 		SIMPLEQ_FOREACH(pchan, >sc_audiochan, entries) {
 			if (pchan->chan == chan->deschan)
 break;
@@ -3086,7 +3086,10 @@ audio_ioctl(dev_t dev, struct audio_soft
 	} else
 		pchan = chan;
 
-	vc = pchan->vc;
+	if (chan->deschan != 0)
+		vc = pchan->vc;
+	else
+		vc = >sc_mixring;
 
 	DPRINTF(("audio_ioctl(%lu,'%c',%lu)\n",
 		 IOCPARM_LEN(cmd), (char)IOCGROUP(cmd), cmd&0xff));
@@ -3100,7 +3103,7 @@ audio_ioctl(dev_t dev, struct audio_soft
 			*(int*)addr = chan->chan;
 		break;
 	case AUDIO_SETCHAN:
-		if ((int *)addr != NULL && *(int*)addr > 0)
+		if ((int *)addr != NULL && *(int*)addr >= 0)
 			chan->deschan = *(int*)addr;
 		break;
 	case FIONBIO:
@@ -4195,6 +4198,12 @@ audio_set_vchan_defaults(struct audio_so
 
 	if (error == 0)
 		error = audiosetinfo(sc, , true, vc);
+	if (error == 0) {
+		vc = >sc_mixring;
+
+		vc->sc_rparams = sc->sc_vchan_params;
+		vc->sc_pparams = sc->sc_vchan_params;
+	}
 
 	return error;
 }
@@ -4559,6 +4568,9 @@ audiosetinfo(struct audio_softc *sc, str
 	rp = vc->sc_rparams;	/* case setting the modes fails. */
 	nr = np = 0;
 
+	if (vc == >sc_mixring)
+		goto done;
+
 	if (SPECIFIED(p->sample_rate)) {
 		pp.sample_rate = p->sample_rate;
 		np++;
@@ -4644,9 +4656,10 @@ audiosetinfo(struct audio_softc *sc, str
 			vc->sc_mode &= ~AUMODE_RECORD;
 	}
 
+done:
 	oldpus = vc->sc_pustream;
 	oldrus = vc->sc_rustream;
-	if (modechange || reset) {
+	if (vc != >sc_mixring && (modechange || reset)) {
 		int indep;
 
 		indep = audio_get_props(sc) & AUDIO_PROP_INDEPENDENT;
@@ -4741,23 +4754,41 @@ audiosetinfo(struct audio_softc *sc, str
 		if (error)
 			goto cleanup;
 	}
-	if (SPECIFIED(p->gain))
-		vc->sc_swvol = p->gain;
+	if (SPECIFIED(p->gain)) {
+		if (!sc->sc_usemixer || vc == >sc_mixring) {
+			au_get_gain(sc, >sc_outports, , );
+			error = au_set_gain(sc, >sc_outports, p->gain, balance);
+			if (error)
+goto cleanup;
+		} else
+			vc->sc_swvol = p->gain;
+	}
 
-	if (SPECIFIED(r->gain))
-		vc->sc_recswvol = r->gain;
+	if (SPECIFIED(r->gain)) {
+		if (!sc->sc_usemixer || vc == >sc_mixring) {
+			au_get_gain(sc, >sc_outports, , );
+			error = au_set_gain(sc, >sc_outports, r->gain, balance);
+			if (error)
+goto cleanup;
+		} else
+			vc->sc_recswvol = r->gain;
+	}
 
 	if (SPECIFIED_CH(p->balance)) {
-		au_get_gain(sc, >sc_outports, , );
-		error = au_set_gain(sc, >sc_outports, gain, p->balance);
-		if (error)
-			goto cleanup;
+		if (!sc->sc_usemixer || vc == >sc_mixring) {
+			au_get_gain(sc, >sc_outports, , );
+			error = au_set_gain(sc, >sc_outports, gain, p->balance);
+			if (error)
+goto cleanup;
+		}
 	}
 	if (SPECIFIED_CH(r->balance)) {
-		au_get_gain(sc, >sc_inports, , );
-		error = au_set_gain(sc, >sc_inports, gain, r->balance);
-		if (error)
-			goto cleanup;
+		if (!sc->sc_usemixer || vc == >sc_mixring) {
+			au_get_gain(sc, >sc_inports, , );
+			error = au_set_gain(sc, >sc_inports, gain, r->balance);
+			if (err

CVS commit: src/sys/dev

2018-05-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue May 15 00:19:08 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Fix numbering of vchan mixer controls to correspond to the vchan number in
use.
This makes the numbering of vchans consistient for audioctl and mixerctl.


To generate a diff of this commit:
cvs rdiff -u -r1.452 -r1.453 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.452 src/sys/dev/audio.c:1.453
--- src/sys/dev/audio.c:1.452	Tue Feb  6 04:39:18 2018
+++ src/sys/dev/audio.c	Tue May 15 00:19:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.452 2018/02/06 04:39:18 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.453 2018/05/15 00:19:08 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.452 2018/02/06 04:39:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.453 2018/05/15 00:19:08 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5784,6 +5784,9 @@ unitscopy(mixer_devinfo_t *di, const cha
 static int
 audio_query_devinfo(struct audio_softc *sc, mixer_devinfo_t *di)
 {
+	struct audio_chan *chan;
+	unsigned int j;
+
 	KASSERT(mutex_owned(sc->sc_lock));
 
 	if (sc->sc_static_nmixer_states == 0 || sc->sc_nmixer_states == 0)
@@ -5799,18 +5802,40 @@ audio_query_devinfo(struct audio_softc *
 			di->type = AUDIO_MIXER_CLASS;
 		} else if ((di->index - sc->sc_static_nmixer_states) % 2 == 0) {
 			di->mixer_class = sc->sc_static_nmixer_states -1;
+			j = 0;
+			SIMPLEQ_FOREACH(chan, >sc_audiochan, entries) {
+if (j == (di->index -
+sc->sc_static_nmixer_states) / 2)
+	break;
+j++;
+			}
+			if (j != (di->index - sc->sc_static_nmixer_states) / 2)
+return 0;
+
+			j = chan->deschan;
+
 			snprintf(di->label.name, sizeof(di->label.name),
-			AudioNdac"%d",
-			(di->index - sc->sc_static_nmixer_states) / 2);
+			AudioNdac"%d", j);
 			di->type = AUDIO_MIXER_VALUE;
 			di->next = di->prev = AUDIO_MIXER_LAST;
 			di->un.v.num_channels = 1;
 			unitscopy(di, AudioNvolume);
 		} else {
 			di->mixer_class = sc->sc_static_nmixer_states -1;
+			j = 0;
+			SIMPLEQ_FOREACH(chan, >sc_audiochan, entries) {
+if (j == (di->index -
+sc->sc_static_nmixer_states) / 2)
+	break;
+j++;
+			}
+			if (j != (di->index - sc->sc_static_nmixer_states) / 2)
+return 0;
+
+			j = chan->deschan;
+
 			snprintf(di->label.name, sizeof(di->label.name),
-			AudioNmicrophone "%d",
-			(di->index - sc->sc_static_nmixer_states) / 2);
+			AudioNmicrophone "%d", j);
 			di->type = AUDIO_MIXER_VALUE;
 			di->next = di->prev = AUDIO_MIXER_LAST;
 			di->un.v.num_channels = 1;



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2018-01-13 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan 13 10:20:45 UTC 2018

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: bta2dpd.c

Log Message:
Set size of mtusize before calling getsockopt to obtain mtu size.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.4 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.5
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.4	Sun Aug 27 10:39:18 2017
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c	Sat Jan 13 10:20:45 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: bta2dpd.c,v 1.4 2017/08/27 10:39:18 nat Exp $ */
+/* $NetBSD: bta2dpd.c,v 1.5 2018/01/13 10:20:45 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -784,13 +784,12 @@ opened_connection:
 		state = 7;
 	}
 
+	mtusize = sizeof(uint16_t);
 	getsockopt(sc, BTPROTO_L2CAP, SO_L2CAP_OMTU, , );
 	if (userset_mtu != 0 && userset_mtu > 100 && userset_mtu < mtu)
 		mtu = userset_mtu;
 	else if (userset_mtu == 0 && mtu >= 500)
 		mtu /= 2;
-
-	mtusize = sizeof(uint16_t);
 }
 
 static void



CVS commit: src/sys/dev

2018-01-11 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Jan 12 04:10:10 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Allow open of audioctl devices whilst audio is open with the mixer
disabled.

XXX pullup -8


To generate a diff of this commit:
cvs rdiff -u -r1.449 -r1.450 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.449 src/sys/dev/audio.c:1.450
--- src/sys/dev/audio.c:1.449	Tue Jan  9 04:14:21 2018
+++ src/sys/dev/audio.c	Fri Jan 12 04:10:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.450 2018/01/12 04:10:10 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.450 2018/01/12 04:10:10 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2175,6 +2175,9 @@ audio_open(dev_t dev, struct audio_softc
 		vc = sc->sc_hwvc;
 	chan->vc = vc;
 
+	if (!sc->sc_usemixer && AUDIODEV(dev) == AUDIOCTL_DEVICE)
+		goto audioctl_dev;
+
 	if (sc->sc_usemixer) {
 		vc->sc_open = 0;
 		vc->sc_mode = 0;
@@ -2292,9 +2295,12 @@ audio_open(dev_t dev, struct audio_softc
 	/* audio_close() decreases sc_mpr[n].usedlow, recalculate here */
 	audio_calcwater(sc, vc);
 
+audioctl_dev:
 	error = fd_allocfile(, );
 	if (error)
 		goto bad;
+	if (!sc->sc_usemixer && AUDIODEV(dev) == AUDIOCTL_DEVICE)
+		goto setup_chan;
 
 	DPRINTF(("audio_open: done sc_mode = 0x%x\n", vc->sc_mode));
 
@@ -2304,6 +2310,8 @@ audio_open(dev_t dev, struct audio_softc
 		sc->sc_recopens++;
 	if (flags & FWRITE)
 		sc->sc_opens++;
+
+setup_chan:
 	chan->dev = dev;
 	chan->chan = n;
 	chan->deschan = n;
@@ -2480,6 +2488,9 @@ audio_close(struct audio_softc *sc, int 
 
 	KASSERT(mutex_owned(sc->sc_lock));
 	
+	if (!sc->sc_usemixer && AUDIODEV(chan->dev) == AUDIOCTL_DEVICE)
+		return 0;
+
 	if (sc->sc_opens == 0 && sc->sc_recopens == 0)
 		return ENXIO;
 



CVS commit: src/sys/dev/pad

2018-01-08 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Jan  9 04:23:59 UTC 2018

Modified Files:
src/sys/dev/pad: pad.c

Log Message:
Fix pad on systems with many cores/cpus:

* Introduce a lock to serialize attach/detach of pad devices.
* Forcefully detach children of pad on close.
* Be more carefull in pad_open with regards to config_detach only
  if new instances of the pad device are created and fail to open.

Addresses PR kern/52889.

These changes were developed with and tested by pgoyette@.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/pad/pad.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pad/pad.c
diff -u src/sys/dev/pad/pad.c:1.49 src/sys/dev/pad/pad.c:1.50
--- src/sys/dev/pad/pad.c:1.49	Sun Dec 17 21:57:11 2017
+++ src/sys/dev/pad/pad.c	Tue Jan  9 04:23:59 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.49 2017/12/17 21:57:11 pgoyette Exp $ */
+/* $NetBSD: pad.c,v 1.50 2018/01/09 04:23:59 nat Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.49 2017/12/17 21:57:11 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.50 2018/01/09 04:23:59 nat Exp $");
 
 #include 
 #include 
@@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.49
 #define PADENC		AUDIO_ENCODING_SLINEAR_LE
 
 extern struct cfdriver pad_cd;
+kmutex_t padconfig;
 
 typedef struct pad_block {
 	uint8_t		*pb_ptr;
@@ -200,6 +201,7 @@ padattach(int n)
 		config_cfdriver_detach(_cd);
 		return;
 	}
+	mutex_init(, MUTEX_DEFAULT, IPL_NONE);
 
 	return;
 }
@@ -286,34 +288,13 @@ static int
 pad_detach(device_t self, int flags)
 {
 	pad_softc_t *sc;
-	int cmaj, mn, rc;
+	int cmaj, mn;
 
 	sc = device_private(self);
-	config_deactivate(sc->sc_audiodev);
-	
-	/* Start draining existing accessors of the device. */
-	if ((rc = config_detach_children(self, flags)) != 0)
-		return rc;
-
-	mutex_enter(>sc_lock);
-	sc->sc_dying = true;
-	cv_broadcast(>sc_condvar);
-	mutex_exit(>sc_lock);
-
-	KASSERT(sc->sc_open > 0);
-	sc->sc_open = 0;
-
 	cmaj = cdevsw_lookup_major(_cdevsw);
 	mn = device_unit(sc->sc_dev);
-	vdevgone(cmaj, mn, mn, VCHR);
-
-	pmf_device_deregister(sc->sc_dev);
-
-	mutex_destroy(>sc_lock);
-	mutex_destroy(>sc_intr_lock);
-	cv_destroy(>sc_condvar);
-
-	auconv_delete_encodings(sc->sc_encodings);
+	if (!sc->sc_dying)
+		vdevgone(cmaj, mn, mn, VCHR);
 
 	return 0;
 }
@@ -327,16 +308,17 @@ pad_open(dev_t dev, int flags, int fmt, 
 	cfdata_t cf;
 	int error, fd, i;
 
+	mutex_enter();
 	if (PADUNIT(dev) == PADCLONER) {
 		for (i = 0; i < MAXDEVS; i++) {
 			if (device_lookup(_cd, i) == NULL)
 break;
 		}
 		if (i == MAXDEVS)
-			return ENXIO;
+			goto bad;
 	} else {
 		if (PADUNIT(dev) >= MAXDEVS)
-			return ENXIO;
+			goto bad;
 		i = PADUNIT(dev);
 	}
 
@@ -346,18 +328,23 @@ pad_open(dev_t dev, int flags, int fmt, 
 	cf->cf_unit = i;
 	cf->cf_fstate = FSTATE_STAR;
 
+	bool existing = false;
 	paddev = device_lookup(_cd, minor(dev));
 	if (paddev == NULL)
 		paddev = config_attach_pseudo(cf);
+	else
+		existing = true;
 	if (paddev == NULL)
-		return ENXIO;
+		goto bad;
 
 	sc = device_private(paddev);
 	if (sc == NULL)
-		return ENXIO;
+		goto bad;
 
-	if (sc->sc_open == 1)
+	if (sc->sc_open == 1) {
+		mutex_exit();
 		return EBUSY;
+	}
 
 	sc->sc_dev = paddev;
 	sc->sc_dying = false;
@@ -365,7 +352,9 @@ pad_open(dev_t dev, int flags, int fmt, 
 	if (PADUNIT(dev) == PADCLONER) {
 		error = fd_allocfile(, );
 		if (error) {
-			config_detach(sc->sc_dev, 0);
+			if (existing == false)
+config_detach(sc->sc_dev, 0);
+			mutex_exit();
 			return error;
 		}
 	}
@@ -373,7 +362,9 @@ pad_open(dev_t dev, int flags, int fmt, 
 	if (auconv_create_encodings(pad_formats, PAD_NFORMATS,
 	>sc_encodings) != 0) {
 		aprint_error_dev(sc->sc_dev, "couldn't create encodings\n");
-		config_detach(sc->sc_dev, 0);
+		if (existing == false)
+			config_detach(sc->sc_dev, 0);
+		mutex_exit();
 		return EINVAL;
 	}
 
@@ -394,17 +385,52 @@ pad_open(dev_t dev, int flags, int fmt, 
 		KASSERT(error == EMOVEFD);
 	}	
 	sc->sc_open = 1;
+	mutex_exit();
 
 	return error;
+bad:
+	mutex_exit();
+	return ENXIO;
 }
 
 static int
 pad_close(struct pad_softc *sc)
 {
+	int rc;
+
 	if (sc == NULL)
 		return ENXIO;
 
-	return config_detach(sc->sc_dev, DETACH_FORCE);
+	mutex_enter();
+	config_deactivate(sc->sc_audiodev);
+	
+	/* Start draining existing accessors of the device. */
+	if ((rc = config_detach_children(sc->sc_dev,
+	DETACH_SHUTDOWN|DETACH_FORCE)) != 0) {
+		mutex_exit();
+		return rc;
+	}
+
+	mutex_enter(>sc_lock);
+	sc->sc_dying = true;
+	cv_broadcast(>sc_condvar);
+	mutex_exit(>sc_lock);
+
+	KASSERT(sc->sc_open > 0);
+	sc->sc_open = 0;
+
+	pmf_device_deregister(sc->sc_dev);
+
+	mutex_destroy(>sc_lock);
+	mutex_destroy(>sc_intr_lock);
+	cv_destroy(>sc_condvar);
+
+	

CVS commit: src/sys/dev

2018-01-08 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Jan  9 04:14:21 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Forcefully detach children of audio instances.

This addresses part of PR kern/52889 as children of pad(4) were not
detaching.


To generate a diff of this commit:
cvs rdiff -u -r1.448 -r1.449 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.448 src/sys/dev/audio.c:1.449
--- src/sys/dev/audio.c:1.448	Tue Jan  9 04:10:27 2018
+++ src/sys/dev/audio.c	Tue Jan  9 04:14:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.448 2018/01/09 04:10:27 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.448 2018/01/09 04:10:27 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -894,7 +894,7 @@ audiodetach(device_t self, int flags)
 	DPRINTF(("audio_detach: sc=%p flags=%d\n", sc, flags));
 
 	/* Start draining existing accessors of the device. */
-	if ((rc = config_detach_children(self, flags)) != 0)
+	if ((rc = config_detach_children(self, flags | DETACH_FORCE)) != 0)
 		return rc;
 	mutex_enter(sc->sc_lock);
 	sc->sc_dying = true;



CVS commit: src/sys/dev

2018-01-08 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Jan  9 04:10:27 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Rework of play/rec threads to ensure effective use of locks.

Addresses part of PR kern/52889 where the mixing thread would not exit on
audio detach.


To generate a diff of this commit:
cvs rdiff -u -r1.447 -r1.448 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.447 src/sys/dev/audio.c:1.448
--- src/sys/dev/audio.c:1.447	Sat Jan  6 23:15:36 2018
+++ src/sys/dev/audio.c	Tue Jan  9 04:10:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.447 2018/01/06 23:15:36 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.448 2018/01/09 04:10:27 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.447 2018/01/06 23:15:36 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.448 2018/01/09 04:10:27 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5858,22 +5858,24 @@ audio_play_thread(void *v)
 	sc = (struct audio_softc *)v;
 
 	for (;;) {
-		mutex_enter(sc->sc_intr_lock);
-		cv_wait_sig(>sc_condvar, sc->sc_intr_lock);
+		mutex_enter(sc->sc_lock);
 		if (sc->sc_dying) {
-			mutex_exit(sc->sc_intr_lock);
+			mutex_exit(sc->sc_lock);
 			kthread_exit(0);
 		}
+		if (!sc->sc_trigger_started)
+			goto play_wait;
 
-		while (sc->sc_usemixer &&
+		while (!sc->sc_dying && sc->sc_usemixer &&
 		audio_stream_get_used(>sc_mixring.sc_mpr.s) <
-		sc->sc_mixring.sc_mpr.blksize) {
-			mutex_exit(sc->sc_intr_lock);
-			mutex_enter(sc->sc_lock);
+		sc->sc_mixring.sc_mpr.blksize)
 			audio_mix(sc);
-			mutex_exit(sc->sc_lock);
-			mutex_enter(sc->sc_intr_lock);
-		}
+
+play_wait:
+		mutex_exit(sc->sc_lock);
+
+		mutex_enter(sc->sc_intr_lock);
+		cv_wait_sig(>sc_condvar, sc->sc_intr_lock);
 		mutex_exit(sc->sc_intr_lock);
 	}
 }
@@ -5886,17 +5888,21 @@ audio_rec_thread(void *v)
 	sc = (struct audio_softc *)v;
 
 	for (;;) {
-		mutex_enter(sc->sc_intr_lock);
-		cv_wait_sig(>sc_rcondvar, sc->sc_intr_lock);
+		mutex_enter(sc->sc_lock);
 		if (sc->sc_dying) {
-			mutex_exit(sc->sc_intr_lock);
+			mutex_exit(sc->sc_lock);
 			kthread_exit(0);
 		}
-		mutex_exit(sc->sc_intr_lock);
+		if (!sc->sc_rec_started)
+			goto rec_wait;
 
-		mutex_enter(sc->sc_lock);
 		audio_upmix(sc);
+rec_wait:
 		mutex_exit(sc->sc_lock);
+
+		mutex_enter(sc->sc_intr_lock);
+		cv_wait_sig(>sc_rcondvar, sc->sc_intr_lock);
+		mutex_exit(sc->sc_intr_lock);
 	}
 
 }



CVS commit: src/sys/dev

2018-01-06 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan  6 23:15:36 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Only signal a pause change on a transition of a pause change.

This addresses a problem found in audio/sox causing high cpu usage.

Path and analysis by Onno van der Linden.


To generate a diff of this commit:
cvs rdiff -u -r1.446 -r1.447 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.446 src/sys/dev/audio.c:1.447
--- src/sys/dev/audio.c:1.446	Sat Jan  6 21:16:36 2018
+++ src/sys/dev/audio.c	Sat Jan  6 23:15:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.446 2018/01/06 21:16:36 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.447 2018/01/06 23:15:36 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.446 2018/01/06 21:16:36 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.447 2018/01/06 23:15:36 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4762,14 +4762,18 @@ audiosetinfo(struct audio_softc *sc, str
 	}
 
 	if (SPECIFIED_CH(p->pause)) {
-		vc->sc_mpr.pause = p->pause;
 		pbus = !p->pause;
-		pausechange = true;
+		if (pbus != !vc->sc_mpr.pause) {
+			vc->sc_mpr.pause = p->pause;
+			pausechange = true;
+		}
 	}
 	if (SPECIFIED_CH(r->pause)) {
-		vc->sc_mrr.pause = r->pause;
 		rbus = !r->pause;
-		pausechange = true;
+		if (rbus != !vc->sc_mrr.pause) {
+			vc->sc_mrr.pause = r->pause;
+			pausechange = true;
+		}
 	}
 
 	if (SPECIFIED(ai->mode)) {



CVS commit: src/sys/dev

2018-01-06 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Jan  6 21:16:36 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.445 -r1.446 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.445 src/sys/dev/audio.c:1.446
--- src/sys/dev/audio.c:1.445	Sat Dec 16 16:04:20 2017
+++ src/sys/dev/audio.c	Sat Jan  6 21:16:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.445 2017/12/16 16:04:20 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.446 2018/01/06 21:16:36 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.445 2017/12/16 16:04:20 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.446 2018/01/06 21:16:36 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4794,7 +4794,7 @@ audiosetinfo(struct audio_softc *sc, str
 	vc->sc_lastinfovalid = true;
 
 cleanup:
-	if (error == 0 && (cleared || pausechange|| reset)) {
+	if (error == 0 && (cleared || pausechange || reset)) {
 		int init_error;
 
 		init_error = (pausechange == 1 && reset == 0) ? 0 :



CVS commit: src/sys/dev

2017-12-26 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Dec 27 00:12:06 UTC 2017

Modified Files:
src/sys/dev: mulaw.c mulaw.h

Log Message:
mulaw/alaw_to_linearN macros replaced with individual faster filters.
NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/mulaw.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/mulaw.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/mulaw.c
diff -u src/sys/dev/mulaw.c:1.32 src/sys/dev/mulaw.c:1.33
--- src/sys/dev/mulaw.c:1.32	Mon Jun 26 12:17:09 2017
+++ src/sys/dev/mulaw.c	Wed Dec 27 00:12:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mulaw.c,v 1.32 2017/06/26 12:17:09 nat Exp $	*/
+/*	$NetBSD: mulaw.c,v 1.33 2017/12/27 00:12:06 nat Exp $	*/
 
 /*
  * Copyright (c) 1991-1993 Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.32 2017/06/26 12:17:09 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mulaw.c,v 1.33 2017/12/27 00:12:06 nat Exp $");
 
 #include 
 #include 
@@ -295,118 +295,197 @@ DEFINE_FILTER(mulaw_to_linear8)
 	return 0;
 }
 
-#define MULAWTOLINEARN(n_prec) 		\
-DEFINE_FILTER(mulaw_to_linear##n_prec)	\
-{	\
-	stream_filter_t *this;		\
-	int hw, j, m, err;		\
-	\
-	hw = n_prec / NBBY;		\
-	this = (stream_filter_t *)self;	\
-	max_used = (max_used + 1) & ~1; /* round up to even */		\
-	if ((err = this->prev->fetch_to(sc, this->prev,			\
-		this->src, max_used / hw)))\
-		return err;		\
-	m = (dst->end - dst->start) & ~1;\
-	m = min(m, max_used);		\
-	switch (dst->param.encoding) {	\
-	case AUDIO_ENCODING_ULINEAR_LE:	\
-		FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) {	\
-			j = hw - 2;	\
-			d[hw - 2] = mulawtolin16[s[0]][1];		\
-			d[hw - 1] = mulawtolin16[s[0]][0];		\
-			while (j > 0)	\
-d[--j] = 0;\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-		break;			\
-	case AUDIO_ENCODING_ULINEAR_BE:	\
-		FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) {	\
-			j = 2;		\
-			d[0] = mulawtolin16[s[0]][0];			\
-			d[1] = mulawtolin16[s[0]][1];			\
-			while (j < hw)	\
-d[j++] = 0;\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-		break;			\
-	case AUDIO_ENCODING_SLINEAR_LE:	\
-		FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) {	\
-			j = hw - 2;	\
-			d[hw - 2] = mulawtolin16[s[0]][1];		\
-			d[hw - 1] = mulawtolin16[s[0]][0] ^ 0x80;	\
-			while (j > 0)	\
-d[--j] = 0;\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-		break;			\
-	case AUDIO_ENCODING_SLINEAR_BE:	\
-		FILTER_LOOP_PROLOGUE(this->src, 1, dst, hw, m) {	\
-			j = 2;		\
-			d[0] = mulawtolin16[s[0]][0] ^ 0x80;		\
-			d[1] = mulawtolin16[s[0]][1];			\
-			while (j < hw)	\
-d[j++] = 0;\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-		break;			\
-	default:			\
-		aprint_error(		\
-		"%s: encoding must be [s/u]linear_[le/be]\n",	\
-		__func__);		\
-		break;			\
-	}\
-	return 0;			\
+DEFINE_FILTER(mulaw_to_linear16)
+{
+	stream_filter_t *this;
+	int m, err;
+
+	this = (stream_filter_t *)self;
+	max_used = (max_used + 1) & ~1;
+	if ((err = this->prev->fetch_to(sc, this->prev,
+		this->src, max_used / 2)))
+		return err;
+	m = (dst->end - dst->start) & ~1;
+	m = min(m, max_used);
+	switch (dst->param.encoding) {
+	case AUDIO_ENCODING_ULINEAR_LE:
+		FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+			d[1] = mulawtolin16[s[0]][0];
+			d[0] = mulawtolin16[s[0]][1];
+		} FILTER_LOOP_EPILOGUE(this->src, dst);
+		break;
+	case AUDIO_ENCODING_ULINEAR_BE:
+		FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+			d[0] = mulawtolin16[s[0]][0];
+			d[1] = mulawtolin16[s[0]][1];
+		} FILTER_LOOP_EPILOGUE(this->src, dst);
+		break;
+	case AUDIO_ENCODING_SLINEAR_LE:
+		FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+			d[1] = mulawtolin16[s[0]][0] ^ 0x80;
+			d[0] = mulawtolin16[s[0]][1];
+		} FILTER_LOOP_EPILOGUE(this->src, dst);
+		break;
+	case AUDIO_ENCODING_SLINEAR_BE:
+		FILTER_LOOP_PROLOGUE(this->src, 1, dst, 2, m) {
+			d[0] = mulawtolin16[s[0]][0] ^ 0x80;
+			d[1] = mulawtolin16[s[0]][1];
+		} FILTER_LOOP_EPILOGUE(this->src, dst);
+		break;
+	default:
+		aprint_error(
+		"%s: encoding must be [s/u]linear_[le/be]\n",
+		__func__);
+		break;
+	}
+	return 0;
 }
 
-MULAWTOLINEARN(32)
-MULAWTOLINEARN(24)
-MULAWTOLINEARN(16)
-
-#define LINEARNTOMULAW(n_prec, n_valid)	\
-DEFINE_FILTER(linear##n_prec##_##n_valid##_to_mulaw)			\
-{	\
-	stream_filter_t *this;		\
-	int hw, m, err;			\
-	\
-	hw = n_prec / NBBY;		\
-	this = (stream_filter_t *)self;	\
-	if ((err = this->prev->fetch_to(sc, this->prev, this->src,	\
-		 max_used * hw)))	\
-		return err;		\
-	m = dst->end - dst->start;	\
-	m = min(m, max_used);		\
-	switch (this->src->param.encoding) {\
-	case AUDIO_ENCODING_SLINEAR_LE:	\

CVS commit: src/sys/arch/arm/sunxi

2017-12-21 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Dec 21 11:52:00 UTC 2017

Modified Files:
src/sys/arch/arm/sunxi: sun8i_h3_codec.c

Log Message:
The reset bit for the analog portion of the codec is bit 28.  As per
Allwinner H3 datasheet.

Ok jmcneill@.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sun8i_h3_codec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sun8i_h3_codec.c
diff -u src/sys/arch/arm/sunxi/sun8i_h3_codec.c:1.2 src/sys/arch/arm/sunxi/sun8i_h3_codec.c:1.3
--- src/sys/arch/arm/sunxi/sun8i_h3_codec.c:1.2	Mon Aug  7 21:50:34 2017
+++ src/sys/arch/arm/sunxi/sun8i_h3_codec.c	Thu Dec 21 11:52:00 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_h3_codec.c,v 1.2 2017/08/07 21:50:34 jmcneill Exp $ */
+/* $NetBSD: sun8i_h3_codec.c,v 1.3 2017/12/21 11:52:00 nat Exp $ */
 
 /*-
  * Copyright (c) 2014-2017 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sun8i_h3_codec.c,v 1.2 2017/08/07 21:50:34 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun8i_h3_codec.c,v 1.3 2017/12/21 11:52:00 nat Exp $");
 
 #include 
 #include 
@@ -42,8 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: sun8i_h3_cod
 #include 
 
 #define	H3_PR_CFG		0x00
+#define	 H3_AC_PR_RST		__BIT(28)
 #define	 H3_AC_PR_RW		__BIT(24)
-#define	 H3_AC_PR_RST		__BIT(18)
 #define	 H3_AC_PR_ADDR		__BITS(20,16)
 #define	 H3_ACDA_PR_WDAT	__BITS(15,8)
 #define	 H3_ACDA_PR_RDAT	__BITS(7,0)



CVS commit: src/sys/dev

2017-12-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Dec 16 16:09:36 UTC 2017

Modified Files:
src/sys/dev: auconv.c auconv.h

Log Message:
Replace LINEARN_TO_LINEARN macro with individual optimized functions for
8, 16, 24 and 32 bits linear to linear conversions.

Addresses PR kern/52586.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/auconv.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/auconv.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/auconv.c
diff -u src/sys/dev/auconv.c:1.34 src/sys/dev/auconv.c:1.35
--- src/sys/dev/auconv.c:1.34	Tue Nov  7 01:15:42 2017
+++ src/sys/dev/auconv.c	Sat Dec 16 16:09:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.c,v 1.34 2017/11/07 01:15:42 nat Exp $	*/
+/*	$NetBSD: auconv.c,v 1.35 2017/12/16 16:09:36 nat Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.34 2017/11/07 01:15:42 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.35 2017/12/16 16:09:36 nat Exp $");
 
 #include 
 #include 
@@ -113,6 +113,7 @@ struct conv_table {
 	stream_filter_factory_t *play_conv;
 	stream_filter_factory_t *rec_conv;
 };
+
 #define TABLE_LIST(prec, valid, target) \
 	{AUDIO_ENCODING_SLINEAR_LE, prec, valid,			\
 	 linear##target##_##target##_to_linear##prec,			\
@@ -485,225 +486,1395 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 	return 0;
 }
 
-#define LINEARN_LINEAR(n_prec, n_validbits, t_prec)			\
-	DEFINE_FILTER(linear##n_prec##_##n_validbits##_to_linear##t_prec)\
-{	\
-	stream_filter_t *this;		\
-	int m, err, enc_dst, enc_src;	\
-	int target, valid, hw, i, j;	\
-	\
-	hw = n_prec / NBBY;		\
-	valid = n_validbits / NBBY;	\
-	target = t_prec / NBBY;		\
-	this = (stream_filter_t *)self;	\
-	max_used = ((max_used / hw) * hw);\
-	\
-	if ((err = this->prev->fetch_to(sc, this->prev, this->src,	\
-			max_used)))	\
-		return err;		\
-	m = (((dst->end - dst->start) / target) * target) & ~1;		\
-	m = min(m, max_used * hw / target);\
-	enc_dst = dst->param.encoding;	\
-	enc_src = this->src->param.encoding;\
-	if ((enc_src == AUDIO_ENCODING_SLINEAR_LE			\
-	 && enc_dst == AUDIO_ENCODING_SLINEAR_LE)			\
-	|| (enc_src == AUDIO_ENCODING_ULINEAR_LE			\
-		&& enc_dst == AUDIO_ENCODING_ULINEAR_LE)) {		\
-		/*			\
-		 * slinearNle -> slinearNle\
-		 * ulinearNle -> ulinearNle\
-		 */			\
-		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = valid;	\
-			j = target;	\
-			if (j < i) {	\
-while (j > 0)\
-	d[--j] = s[--i];		\
-			} else {	\
-while (i > 0)\
-	d[--j] = s[--i];		\
-while (j > 0)\
-	d[--j] = 0;			\
-			}		\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_BE		\
-	 && enc_dst == AUDIO_ENCODING_SLINEAR_BE)			\
-	|| (enc_src == AUDIO_ENCODING_ULINEAR_BE			\
-		&& enc_dst == AUDIO_ENCODING_ULINEAR_BE)) {		\
-		/*			\
-		 * slinearNbe -> slinearNbe\
-		 * ulinearNbe -> ulinearNbe\
-		 */			\
-		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = valid;	\
-			j = target;	\
-			if (j < i) {	\
-j = 0;	\
-while (j < target)			\
-	d[j++] = s[i++];		\
-			} else {	\
-j = 0;	\
-i = 0;	\
-while (i < valid)			\
-	d[j++] = s[i++];		\
-while (j < target)			\
-	d[j++] = 0;			\
-			}		\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_LE		\
-		&& enc_dst == AUDIO_ENCODING_SLINEAR_BE)		\
-		   || (enc_src == AUDIO_ENCODING_ULINEAR_LE		\
-		   && enc_dst == AUDIO_ENCODING_ULINEAR_BE)) {	\
-		/*			\
-		 * slinearNle -> slinearNbe\
-		 * ulinearNle -> ulinearNbe\
-		 */			\
-		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = valid;	\
-			j = target;	\
-			if (j < i) {	\
-while (j > 0) {\
-	d[target - j] = s[--i];		\
-	j--;\
-}	\
-			} else {	\
-while (j > i)\
-	d[--j] = 0;			\
-j = 0;	\
-while (i > 0) {\
-	d[j++] = s[--i];		\
-}	\
-			}		\
-		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
-	} else if ((enc_src == AUDIO_ENCODING_ULINEAR_BE		\
-		&& enc_dst == AUDIO_ENCODING_SLINEAR_LE)		\
-		   || (enc_src == AUDIO_ENCODING_SLINEAR_BE		\
-		   && enc_dst == AUDIO_ENCODING_ULINEAR_LE)) {	\
-		/*			\
-		 * ulinearNbe -> slinearNle\
-		 * slinearNbe -> ulinearNle\
-		 */			\
-		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = 0;		\
-			j = target;	\
-			if (target < valid) {\
-while (j > 0)\
-	d[--j] = s[i++];		\
-			} else {	\
-while (i < valid)			\
-	d[--j] = s[i++];		\
-while (j > 0)\
-	d[--j] = 0;			\
-			}		\

CVS commit: src/sys/dev

2017-12-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Dec 16 16:04:20 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Convert double block size of data though the play back filters.  This is
primarily for when audio mixing is disabled to stop inserting silence when
there is data available.

This change should have no effect when mixing is enabled as there is only
1 block of data in the mix ring.


To generate a diff of this commit:
cvs rdiff -u -r1.444 -r1.445 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.444 src/sys/dev/audio.c:1.445
--- src/sys/dev/audio.c:1.444	Sat Dec 16 15:58:56 2017
+++ src/sys/dev/audio.c	Sat Dec 16 16:04:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.444 2017/12/16 15:58:56 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.445 2017/12/16 16:04:20 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.444 2017/12/16 15:58:56 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.445 2017/12/16 16:04:20 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2994,7 +2994,10 @@ audio_write(struct audio_softc *sc, stru
 			filter = vc->sc_pfilters[0];
 			filter->set_fetcher(filter, );
 			fetcher = >sc_pfilters[vc->sc_npfilters - 1]->base;
-			cc = sc->sc_mixring.sc_mpr.blksize * 2;
+			if (sc->sc_usemixer)
+cc = sc->sc_mixring.sc_mpr.blksize * 2;
+			else
+cc = vc->sc_mpr.blksize * 2;
 			error = fetcher->fetch_to(sc, fetcher, , cc);
 			if (error != 0) {
 fetcher = 
@@ -5535,12 +5538,14 @@ mix_write(void *arg)
 			sc->sc_mixring.sc_mpr.blksize);
 	}
 
-	if (vc->sc_npfilters > 0) {
+	if (vc->sc_npfilters > 0 &&
+	(sc->sc_usemixer || sc->sc_trigger_started)) {
 		null_fetcher.fetch_to = null_fetcher_fetch_to;
 		filter = vc->sc_pfilters[0];
 		filter->set_fetcher(filter, _fetcher);
 		fetcher = >sc_pfilters[vc->sc_npfilters - 1]->base;
-		fetcher->fetch_to(sc, fetcher, >sc_mpr.s, vc->sc_mpr.blksize);
+		fetcher->fetch_to(sc, fetcher, >sc_mpr.s,
+		vc->sc_mpr.blksize * 2);
  	}
 
 	if (sc->hw_if->trigger_output && sc->sc_trigger_started == false) {



CVS commit: src/sys/dev

2017-12-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Dec 16 15:58:56 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Allow the hwvc block size to be set to any amount with audio mixing
disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.443 -r1.444 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.443 src/sys/dev/audio.c:1.444
--- src/sys/dev/audio.c:1.443	Sat Dec 16 15:56:00 2017
+++ src/sys/dev/audio.c	Sat Dec 16 15:58:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.443 2017/12/16 15:56:00 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.444 2017/12/16 15:58:56 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.443 2017/12/16 15:56:00 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.444 2017/12/16 15:58:56 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2725,12 +2725,13 @@ audio_setblksize(struct audio_softc *sc,
 		stream = vc->sc_pustream;
 	}
 
-	if (vc == sc->sc_hwvc) {
+	if (sc->sc_usemixer && vc == sc->sc_hwvc) {
 		mixcb->blksize = audio_calc_blksize(sc, parm);
 		cb->blksize = audio_calc_blksize(sc, >s.param);
 	} else {
 		cb->blksize = audio_calc_blksize(sc, >param);
-		if (SPECIFIED(blksize) && blksize > cb->blksize)
+		if ((!sc->sc_usemixer && SPECIFIED(blksize)) ||
+		(SPECIFIED(blksize) && blksize > cb->blksize))
 			cb->blksize = blksize;
 	}
 }



CVS commit: src/sys/dev

2017-12-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Dec 16 15:56:00 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Only init the mix ring if sc_usemixer is enabled as with mixing set to
false the mix ring is not used.


To generate a diff of this commit:
cvs rdiff -u -r1.442 -r1.443 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.442 src/sys/dev/audio.c:1.443
--- src/sys/dev/audio.c:1.442	Thu Nov 30 20:25:54 2017
+++ src/sys/dev/audio.c	Sat Dec 16 15:56:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.442 2017/11/30 20:25:54 christos Exp $	*/
+/*	$NetBSD: audio.c,v 1.443 2017/12/16 15:56:00 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.442 2017/11/30 20:25:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.443 2017/12/16 15:56:00 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2223,10 +2223,10 @@ audio_open(dev_t dev, struct audio_softc
 			}
 		}
 		audio_initbufs(sc, NULL);
-		if (audio_can_playback(sc))
+		if (sc->sc_usemixer && audio_can_playback(sc))
 			audio_init_ringbuffer(sc, >sc_mixring.sc_mpr,
 			AUMODE_PLAY);
-		if (audio_can_capture(sc))
+		if (sc->sc_usemixer && audio_can_capture(sc))
 			audio_init_ringbuffer(sc, >sc_mixring.sc_mrr,
 			AUMODE_RECORD);
 		sc->schedule_wih = false;



CVS commit: src/sys/dev

2017-11-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Nov 28 07:35:27 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Speed up improvements for MIX_FUNC.

As suggested by jmcneill@.


To generate a diff of this commit:
cvs rdiff -u -r1.440 -r1.441 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.440 src/sys/dev/audio.c:1.441
--- src/sys/dev/audio.c:1.440	Thu Nov 16 23:43:48 2017
+++ src/sys/dev/audio.c	Tue Nov 28 07:35:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.440 2017/11/16 23:43:48 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.441 2017/11/28 07:35:27 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.440 2017/11/16 23:43:48 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.441 2017/11/28 07:35:27 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5592,14 +5592,20 @@ mix_write(void *arg)
 cc = cc2;\
 	\
 			for (m = 0; m < (cc / (bits / NBBY)); m++) {	\
+if (vc->sc_swvol == 255)		\
+	goto vol_done;			\
 tomix[m] = (bigger_type)tomix[m] *	\
 (bigger_type)(vc->sc_swvol) / 255;	\
+vol_done:\
 result = (bigger_type)orig[m] + tomix[m]; \
+if (sc->sc_opens == 1)			\
+	goto adj_done;			\
 product = (bigger_type)orig[m] * tomix[m]; \
 if (orig[m] > 0 && tomix[m] > 0)	\
 	result -= product / MAXVAL;	\
 else if (orig[m] < 0 && tomix[m] < 0)	\
 	result -= product / MINVAL;	\
+adj_done:\
 orig[m] = result;			\
 			}		\
 	\



CVS commit: src/sys/dev

2017-11-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Nov 16 23:43:48 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Use correct combination of mix ring block size and vc playring used low
for signalling the writer or fetching data from the vc play ring filters.

When dealing with the ring buffer sc_mpr.s it is necessary to use the hwvc
or mixring block sizes as they represent the final size of the data to be
played back from the stream vc.

When dealing with sc_pustream when there is play back filters or not one
should use the vc->sc_mpr.blocksize, as this represents the amount of data
before going through play back filters.

This should address PR kern/52685.


To generate a diff of this commit:
cvs rdiff -u -r1.439 -r1.440 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.439 src/sys/dev/audio.c:1.440
--- src/sys/dev/audio.c:1.439	Thu Nov 16 23:32:11 2017
+++ src/sys/dev/audio.c	Thu Nov 16 23:43:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.439 2017/11/16 23:32:11 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.440 2017/11/16 23:43:48 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.439 2017/11/16 23:32:11 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.440 2017/11/16 23:43:48 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3802,7 +3802,7 @@ audio_mix(void *v)
 		 * at accurate timing.  If used < blksize, uaudio(4) already
 		 * request transfer of garbage data.
 		 */
-		if (used <= cb->usedlow && !cb->copying &&
+		if (used <= sc->sc_hwvc->sc_mpr.usedlow && !cb->copying &&
 		vc->sc_npfilters > 0) {
 			/* we might have data in filter pipeline */
 			null_fetcher.fetch_to = null_fetcher_fetch_to;
@@ -3863,7 +3863,7 @@ audio_mix(void *v)
 			 audio_stream_get_used(>s), cb->usedlow));
 
 		if ((vc->sc_mode & AUMODE_PLAY) && !cb->pause) {
-			if (audio_stream_get_used(>s) <= cb->usedlow)
+			if (audio_stream_get_used(vc->sc_pustream) <= cb->usedlow)
 sc->schedule_wih = true;
 		}
 		/* Possible to return one or more "phantom blocks" now. */



CVS commit: src/sys/dev

2017-11-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Nov 16 23:32:12 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Add vc to debug messages in audio_mix.
Also add debug message when available data in the vc is less than the mix
ring blocksize.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.438 -r1.439 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.438 src/sys/dev/audio.c:1.439
--- src/sys/dev/audio.c:1.438	Wed Nov 15 04:28:45 2017
+++ src/sys/dev/audio.c	Thu Nov 16 23:32:11 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.438 2017/11/15 04:28:45 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.439 2017/11/16 23:32:11 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.438 2017/11/15 04:28:45 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.439 2017/11/16 23:32:11 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3749,8 +3749,9 @@ audio_mix(void *v)
 		inp = cb->s.inp;
 		cb->stamp += blksize;
 		if (cb->mmapped) {
-			DPRINTF(("audio_pint: mmapped outp=%p cc=%d inp=%p\n",
- cb->s.outp, blksize, cb->s.inp));
+			DPRINTF(("audio_pint: vc=%p mmapped outp=%p cc=%d "
+ "inp=%p\n", vc, cb->s.outp, blksize,
+  cb->s.inp));
 			mutex_enter(sc->sc_intr_lock);
 			mix_func(sc, cb, vc);
 			cb->s.outp = audio_stream_add_outp(>s, cb->s.outp,
@@ -3825,6 +3826,9 @@ audio_mix(void *v)
 DPRINTFN(1, ("audio_pint: copying in "
 	 "progress\n"));
 			} else {
+DPRINTF(("audio_pint: used < blksize vc=%p "
+	  "used=%d blksize=%d\n", vc, used,
+	  blksize));
 inp = cb->s.inp;
 cc = blksize - (inp - cb->s.start) % blksize;
 if (cb->pause)
@@ -3847,17 +3851,16 @@ audio_mix(void *v)
 			}
 		}
 
-		DPRINTFN(5, ("audio_pint: outp=%p cc=%d\n", cb->s.outp,
-			 blksize));
+		DPRINTFN(5, ("audio_pint: vc=%p outp=%p used=%d cc=%d\n", vc,
+			 cb->s.outp, used, blksize));
 		mutex_enter(sc->sc_intr_lock);
 		mix_func(sc, cb, vc);
 		mutex_exit(sc->sc_intr_lock);
 		cb->s.outp = audio_stream_add_outp(>s, cb->s.outp, blksize);
 
-		DPRINTFN(2, ("audio_pint: mode=%d pause=%d used=%d lowat=%d\n",
-			 vc->sc_mode, cb->pause,
-			 audio_stream_get_used(vc->sc_pustream),
-			 cb->usedlow));
+		DPRINTFN(2, ("audio_pint: vc=%p mode=%d pause=%d used=%d "
+			 "lowat=%d\n", vc, vc->sc_mode, cb->pause,
+			 audio_stream_get_used(>s), cb->usedlow));
 
 		if ((vc->sc_mode & AUMODE_PLAY) && !cb->pause) {
 			if (audio_stream_get_used(>s) <= cb->usedlow)



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 04:28:45 UTC 2017

Modified Files:
src/sys/dev: audio.c audiovar.h

Log Message:
For the virtual stream it is required to insert silence.  As these streams
are not harware streams audio_pint_silence is ineffective.

As audio_mix() was the only consumer of audio_pint_silence it has been
removed along with sc_sil_count - which was only used by this function.


To generate a diff of this commit:
cvs rdiff -u -r1.437 -r1.438 src/sys/dev/audio.c
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/audiovar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.437 src/sys/dev/audio.c:1.438
--- src/sys/dev/audio.c:1.437	Wed Nov 15 02:13:33 2017
+++ src/sys/dev/audio.c	Wed Nov 15 04:28:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.437 2017/11/15 02:13:33 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.438 2017/11/15 04:28:45 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.437 2017/11/15 02:13:33 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.438 2017/11/15 04:28:45 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -294,9 +294,6 @@ int	audio_drain(struct audio_softc *, st
 void	audio_clear(struct audio_softc *, struct virtual_channel *);
 void	audio_clear_intr_unlocked(struct audio_softc *sc,
   struct virtual_channel *);
-static inline void
-	audio_pint_silence(struct audio_softc *, struct audio_ringbuffer *,
-			   uint8_t *, int, struct virtual_channel *);
 int	audio_alloc_ring(struct audio_softc *, struct audio_ringbuffer *, int,
 			 size_t);
 void	audio_free_ring(struct audio_softc *, struct audio_ringbuffer *);
@@ -2086,7 +2083,6 @@ audio_initbufs(struct audio_softc *sc, s
 		((vc->sc_open & AUOPEN_WRITE) || vc == sc->sc_hwvc)) {
 		audio_init_ringbuffer(sc, >sc_mpr,
 		AUMODE_PLAY);
-		vc->sc_sil_count = 0;
 		if (sc->sc_opens == 0 && (vc->sc_open & AUOPEN_WRITE)) {
 			if (hw->init_output) {
 error = hw->init_output(sc->hw_hdl,
@@ -2181,7 +2177,6 @@ audio_open(dev_t dev, struct audio_softc
 	if (sc->sc_usemixer) {
 		vc->sc_open = 0;
 		vc->sc_mode = 0;
-		vc->sc_sil_count = 0;
 		vc->sc_nrfilters = 0;
 		memset(vc->sc_rfilters, 0,
 		sizeof(vc->sc_rfilters));
@@ -3020,12 +3015,6 @@ audio_write(struct audio_softc *sc, stru
 		einp = cb->s.inp;
 
 		/*
-		 * This is a very suboptimal way of keeping track of
-		 * silence in the buffer, but it is simple.
-		 */
-		vc->sc_sil_count = 0;
-
-		/*
 		 * If the interrupt routine wants the last block filled AND
 		 * the copy did not fill the last block completely it needs to
 		 * be padded.
@@ -3623,60 +3612,6 @@ done:
 	return error;
 }
 
-/*
- * When the play interrupt routine finds that the write isn't keeping
- * the buffer filled it will insert silence in the buffer to make up
- * for this.  The part of the buffer that is filled with silence
- * is kept track of in a very approximate way: it starts at sc_sil_start
- * and extends sc_sil_count bytes.  If there is already silence in
- * the requested area nothing is done; so when the whole buffer is
- * silent nothing happens.  When the writer starts again sc_sil_count
- * is set to 0.
- *
- * XXX
- * Putting silence into the output buffer should not really be done
- * from the device interrupt handler.  Consider deferring to the soft
- * interrupt.
- */
-static inline void
-audio_pint_silence(struct audio_softc *sc, struct audio_ringbuffer *cb,
-		   uint8_t *inp, int cc, struct virtual_channel *vc)
-{
-	uint8_t *s, *e, *p, *q;
-
-	KASSERT(mutex_owned(sc->sc_lock));
-
-	if (vc->sc_sil_count > 0) {
-		s = vc->sc_sil_start; /* start of silence */
-		e = s + vc->sc_sil_count; /* end of sil., may be beyond end */
-		p = inp;	/* adjusted pointer to area to fill */
-		if (p < s)
-			p += cb->s.end - cb->s.start;
-		q = p + cc;
-		/* Check if there is already silence. */
-		if (!(s <= p && p <  e &&
-		  s <= q && q <= e)) {
-			if (s <= p)
-vc->sc_sil_count = max(vc->sc_sil_count, q-s);
-			DPRINTFN(5,("audio_pint_silence: fill cc=%d inp=%p, "
-"count=%d size=%d\n",
-cc, inp, vc->sc_sil_count,
-(int)(cb->s.end - cb->s.start)));
-			audio_fill_silence(>s.param, inp, cc);
-		} else {
-			DPRINTFN(5,("audio_pint_silence: already silent "
-"cc=%d inp=%p\n", cc, inp));
-
-		}
-	} else {
-		vc->sc_sil_start = inp;
-		vc->sc_sil_count = cc;
-		DPRINTFN(5, ("audio_pint_silence: start fill %p %d\n",
-			 inp, cc));
-		audio_fill_silence(>s.param, inp, cc);
-	}
-}
-
 static void
 audio_softintr_rd(

CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 02:13:33 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
The harware vc is rounded to a power of two then round_blocksize is called.

This improves playback and makes it possibile to use mmapped audio on usb.


To generate a diff of this commit:
cvs rdiff -u -r1.436 -r1.437 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.436 src/sys/dev/audio.c:1.437
--- src/sys/dev/audio.c:1.436	Wed Nov 15 02:02:55 2017
+++ src/sys/dev/audio.c	Wed Nov 15 02:13:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.436 2017/11/15 02:02:55 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.437 2017/11/15 02:13:33 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.436 2017/11/15 02:02:55 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.437 2017/11/15 02:13:33 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2021,27 +2021,19 @@ audio_init_ringbuffer(struct audio_softc
 	DPRINTF(("audio_init_ringbuffer: MI blksize=%d\n", blksize));
 
 	struct virtual_channel *hwvc = sc->sc_hwvc;
+
+	int tmpblksize = 1; 	 
+	/* round blocksize to a power of 2 */ 	 
+	while (tmpblksize < blksize)
+		tmpblksize <<= 1; 	 
+
+	blksize = tmpblksize;
+
 	if (sc->hw_if->round_blocksize &&
-	(rp == >sc_mpr || rp == >sc_mrr)) {
+	(rp == >sc_mpr || rp == >sc_mrr || rp ==
+	>sc_mixring.sc_mpr || rp == >sc_mixring.sc_mrr)) {
 		blksize = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
 		mode, >s.param);
-	} else {
-		int hwblksize = rp->s.bufsize;
-		if (sc->hw_if->round_blocksize) {
-			if (audio_can_capture(sc))
-hwblksize = sc->sc_hwvc->sc_mpr.blksize;
-			else
-hwblksize = sc->sc_hwvc->sc_mrr.blksize;
-		}
-
-		int tmpblksize = 1; 	 
-		/* round blocksize to a power of 2 */ 	 
-		while (tmpblksize < blksize) 	 
-			tmpblksize <<= 1; 	 
-
-		blksize = tmpblksize;
-		if (blksize > hwblksize)
-			blksize = hwblksize;
 	}
 
 	if (blksize <= 0)



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 02:02:55 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
audio_pint improvements for when audio mixing is disabled.

When audio mixing is disabled there is only the hardware vc the mix ring
is not used.


To generate a diff of this commit:
cvs rdiff -u -r1.435 -r1.436 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.435 src/sys/dev/audio.c:1.436
--- src/sys/dev/audio.c:1.435	Wed Nov 15 01:58:48 2017
+++ src/sys/dev/audio.c	Wed Nov 15 02:02:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.435 2017/11/15 01:58:48 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.436 2017/11/15 02:02:55 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.435 2017/11/15 01:58:48 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.436 2017/11/15 02:02:55 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3735,6 +3735,7 @@ void
 audio_pint(void *v)
 {
 	struct audio_softc *sc;
+	struct audio_ringbuffer *cb;
 	struct virtual_channel *vc;
 	int blksize, cc, used;
 
@@ -3745,31 +3746,34 @@ audio_pint(void *v)
 	if (sc->sc_dying == true || sc->sc_trigger_started == false)
 		return;
 
-	if (vc->sc_draining && (!sc->sc_usemixer ||
-	(sc->sc_mixring.sc_mpr.drops != sc->sc_last_drops))) {
+	if (sc->sc_usemixer)
+		cb = >sc_mixring.sc_mpr;
+	else
+		cb = >sc_mpr;
+
+	if (vc->sc_draining && cb->drops != sc->sc_last_drops) {
 		vc->sc_mpr.drops += blksize;
 		cv_broadcast(>sc_wchan);
 	}
-	sc->sc_last_drops = sc->sc_mixring.sc_mpr.drops;
+
+	sc->sc_last_drops = cb->drops;
 
 	vc->sc_mpr.s.outp = audio_stream_add_outp(>sc_mpr.s,
 	vc->sc_mpr.s.outp, blksize);
 
-	if (audio_stream_get_used(>sc_mixring.sc_mpr.s) < blksize) {
+	if (audio_stream_get_used(>s) < blksize) {
 		DPRINTFN(3, ("HW RING - INSERT SILENCE\n"));
 		used = blksize;
 		while (used > 0) {
-			cc = sc->sc_mixring.sc_mpr.s.end -
-			sc->sc_mixring.sc_mpr.s.inp;
+			cc = cb->s.end - cb->s.inp;
 			if (cc > used)
 cc = used;
-			audio_fill_silence(>sc_pustream->param,
-			sc->sc_mixring.sc_mpr.s.inp, cc);
-			sc->sc_mixring.sc_mpr.s.inp =
-			audio_stream_add_inp(>sc_mixring.sc_mpr.s,
-			sc->sc_mixring.sc_mpr.s.inp, cc);
+			audio_fill_silence(>s.param, cb->s.inp, cc);
+			cb->s.inp =
+			audio_stream_add_inp(>s, cb->s.inp, cc);
 			used -= cc;
 		}
+		vc->sc_mpr.drops += blksize;
 	}
 
 	mix_write(sc);



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 01:58:48 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Improved audiostartp for when audio mixing is disabled.


To generate a diff of this commit:
cvs rdiff -u -r1.434 -r1.435 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.434 src/sys/dev/audio.c:1.435
--- src/sys/dev/audio.c:1.434	Wed Nov 15 01:55:45 2017
+++ src/sys/dev/audio.c	Wed Nov 15 01:58:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.434 2017/11/15 01:55:45 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.435 2017/11/15 01:58:48 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.434 2017/11/15 01:55:45 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.435 2017/11/15 01:58:48 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3593,7 +3593,13 @@ audiostartp(struct audio_softc *sc, stru
 	if (vc == sc->sc_hwvc && sc->sc_usemixer)
 		return 0;
 
-	if (!vc->sc_mpr.mmapped && used < sc->sc_mixring.sc_mpr.blksize) {
+	int blksize;
+	if (sc->sc_usemixer)
+		blksize = sc->sc_mixring.sc_mpr.blksize;
+	else
+		blksize = vc->sc_mpr.blksize;
+
+	if (!vc->sc_mpr.mmapped && used < blksize) {
 		cv_broadcast(>sc_wchan);
 		DPRINTF(("%s: wakeup and return\n", __func__));
 		return 0;
@@ -3610,13 +3616,14 @@ audiostartp(struct audio_softc *sc, stru
 		error = mix_write(sc);
 		if (error)
 			goto done;
-		vc = sc->sc_hwvc;
-		vc->sc_mpr.s.outp =
-		audio_stream_add_outp(>sc_mpr.s,
-		  vc->sc_mpr.s.outp, vc->sc_mpr.blksize);
-		error = mix_write(sc);
-		if (sc->sc_usemixer)
+		if (sc->sc_usemixer) {
+			vc = sc->sc_hwvc;
+			vc->sc_mpr.s.outp =
+			audio_stream_add_outp(>sc_mpr.s,
+			  vc->sc_mpr.s.outp, vc->sc_mpr.blksize);
+			error = mix_write(sc);
 			cv_broadcast(>sc_condvar);
+		}
 done:
 		mutex_exit(sc->sc_intr_lock);
 	}



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 01:55:46 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Improved draining function for when the mixer is and is not enabled.

One block of silence is also played in audio drivers using start_output
when draining the hardware, this helps playback of short (less than
blocksize) samples.


To generate a diff of this commit:
cvs rdiff -u -r1.433 -r1.434 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.433 src/sys/dev/audio.c:1.434
--- src/sys/dev/audio.c:1.433	Wed Nov 15 01:49:59 2017
+++ src/sys/dev/audio.c	Wed Nov 15 01:55:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.433 2017/11/15 01:49:59 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.434 2017/11/15 01:55:45 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.433 2017/11/15 01:49:59 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.434 2017/11/15 01:55:45 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2402,13 +2402,13 @@ audio_drain(struct audio_softc *sc, stru
 		return 0;
 
 	used = audio_stream_get_used(>s);
-	if (vc == sc->sc_hwvc) {
+	if (vc == sc->sc_hwvc && sc->sc_usemixer) {
 		hw = true;
 		used += audio_stream_get_used(>sc_mixring.sc_mpr.s);
 	}
 	for (i = 0; i < vc->sc_npfilters; i++)
 		used += audio_stream_get_used(>sc_pstreams[i]);
-	if (used <= 0 || (hw == true && sc->hw_if->trigger_output == NULL))
+	if (used <= 0)
 		return 0;
 
 	if (hw == false && !vc->sc_pbus) {
@@ -2457,9 +2457,14 @@ audio_drain(struct audio_softc *sc, stru
 #endif
 	vc->sc_draining = true;
 
-	drops = cb->drops + (cb->blksize * PREFILL_BLOCKS);
+	drops = cb->drops;
+	if (vc == sc->sc_hwvc)
+		drops += cb->blksize;
+	else if (sc->sc_usemixer)
+		drops += sc->sc_mixring.sc_mpr.blksize * PREFILL_BLOCKS;
+
 	error = 0;
-	while (cb->drops < drops && !error) {
+	while (cb->drops <= drops && !error) {
 		DPRINTF(("audio_drain: vc=%p used=%d, drops=%ld\n",
 			vc,
 			audio_stream_get_used(>sc_mpr.s),



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 01:49:59 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Plug memory leak as the mixer state does not grow or shrink when audio
mixing is disabled.  This avoids triggering a panic also.


To generate a diff of this commit:
cvs rdiff -u -r1.432 -r1.433 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.432 src/sys/dev/audio.c:1.433
--- src/sys/dev/audio.c:1.432	Wed Nov 15 01:45:57 2017
+++ src/sys/dev/audio.c	Wed Nov 15 01:49:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.432 2017/11/15 01:45:57 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.433 2017/11/15 01:49:59 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.432 2017/11/15 01:45:57 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.433 2017/11/15 01:49:59 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2310,7 +2310,8 @@ audio_open(dev_t dev, struct audio_softc
 
 	DPRINTF(("audio_open: done sc_mode = 0x%x\n", vc->sc_mode));
 
-	grow_mixer_states(sc, 2);
+	if (sc->sc_usemixer)
+		grow_mixer_states(sc, 2);
 	if (flags & FREAD)
 		sc->sc_recopens++;
 	if (flags & FWRITE)



CVS commit: src/sys/dev

2017-11-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Nov 15 01:45:57 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Don't return EIO falsely when dealing with the hardware vc.
Draining of the hardware vc on close is now possible.


To generate a diff of this commit:
cvs rdiff -u -r1.431 -r1.432 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.431 src/sys/dev/audio.c:1.432
--- src/sys/dev/audio.c:1.431	Tue Nov  7 09:26:55 2017
+++ src/sys/dev/audio.c	Wed Nov 15 01:45:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.431 2017/11/07 09:26:55 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.432 2017/11/15 01:45:57 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.431 2017/11/07 09:26:55 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.432 2017/11/15 01:45:57 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -1605,7 +1605,7 @@ audio_waitio(struct audio_softc *sc, kco
 	/* Wait for pending I/O to complete. */
 	error = cv_wait_sig(chan, sc->sc_lock);
 
-	if (!sc->sc_usemixer)
+	if (!sc->sc_usemixer || vc == sc->sc_hwvc)
 		return error;
 
 	found = false;



CVS commit: src/sys/dev

2017-11-07 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Nov  7 09:26:55 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Use mixring blocksizes in the right places when mixer is enabled.

This means that x68k's vs audio works once again with sysctl usemixer=1.

Tested with xm6i.


To generate a diff of this commit:
cvs rdiff -u -r1.430 -r1.431 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.430 src/sys/dev/audio.c:1.431
--- src/sys/dev/audio.c:1.430	Tue Nov  7 01:13:19 2017
+++ src/sys/dev/audio.c	Tue Nov  7 09:26:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.430 2017/11/07 01:13:19 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.431 2017/11/07 09:26:55 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.430 2017/11/07 01:13:19 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.431 2017/11/07 09:26:55 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3789,7 +3789,7 @@ audio_mix(void *v)
 	if (sc->sc_dying == true)
 		return;
 
-	blksize = sc->sc_hwvc->sc_mpr.blksize;
+	blksize = sc->sc_mixring.sc_mpr.blksize;
 	SIMPLEQ_FOREACH(chan, >sc_audiochan, entries) {
 		vc = chan->vc;
 
@@ -5552,10 +5552,10 @@ mix_write(void *arg)
 
 	if (sc->sc_usemixer &&
 	audio_stream_get_used(vc->sc_pustream) <=
-vc->sc_mpr.blksize) {
+sc->sc_mixring.sc_mpr.blksize) {
 		tocopy = vc->sc_pustream->inp;
 		orig = sc->sc_mixring.sc_mpr.s.outp;
-		used = vc->sc_mpr.blksize;
+		used = sc->sc_mixring.sc_mpr.blksize;
 
 		while (used > 0) {
 			cc = used;
@@ -5578,12 +5578,12 @@ mix_write(void *arg)
 		}
 
 		vc->sc_pustream->inp = audio_stream_add_inp(vc->sc_pustream,
-		vc->sc_pustream->inp, vc->sc_mpr.blksize);
+		vc->sc_pustream->inp, sc->sc_mixring.sc_mpr.blksize);
 
 		sc->sc_mixring.sc_mpr.s.outp =
 		audio_stream_add_outp(>sc_mixring.sc_mpr.s,
 			sc->sc_mixring.sc_mpr.s.outp,
-			vc->sc_mpr.blksize);
+			sc->sc_mixring.sc_mpr.blksize);
 	}
 
 	if (vc->sc_npfilters > 0) {
@@ -5901,7 +5901,7 @@ audio_play_thread(void *v)
 			kthread_exit(0);
 		}
 
-		while (sc->sc_trigger_started && sc->sc_usemixer &&
+		while (sc->sc_usemixer &&
 		audio_stream_get_used(>sc_mixring.sc_mpr.s) <
 		sc->sc_mixring.sc_mpr.blksize) {
 			mutex_exit(sc->sc_intr_lock);



CVS commit: src/sys/dev

2017-11-06 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Nov  7 01:15:43 UTC 2017

Modified Files:
src/sys/dev: auconv.c auconv.h

Log Message:
Remove 24 bit in a 32 bit container filters.

At present this filter did not work well and has caused problems with
the audio mixer disabled for hdaudio(4).

These filters may return when they are fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/auconv.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/auconv.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/auconv.c
diff -u src/sys/dev/auconv.c:1.33 src/sys/dev/auconv.c:1.34
--- src/sys/dev/auconv.c:1.33	Mon Oct  2 07:06:15 2017
+++ src/sys/dev/auconv.c	Tue Nov  7 01:15:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.c,v 1.33 2017/10/02 07:06:15 nat Exp $	*/
+/*	$NetBSD: auconv.c,v 1.34 2017/11/07 01:15:42 nat Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.33 2017/10/02 07:06:15 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.34 2017/11/07 01:15:42 nat Exp $");
 
 #include 
 #include 
@@ -141,7 +141,6 @@ struct conv_table {
  */
 static const struct conv_table s8_table[] = {
 	TABLE_LIST(32, 32, 8)
-	TABLE_LIST(24, 32, 8)
 	TABLE_LIST(24, 24, 8)
 	TABLE_LIST(16, 16, 8)
 	TABLE_LIST(8, 8, 8)
@@ -151,7 +150,6 @@ static const struct conv_table s8_table[
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u8_table[] = {
 	TABLE_LIST(32, 32, 8)
-	TABLE_LIST(24, 32, 8)
 	TABLE_LIST(24, 24, 8)
 	TABLE_LIST(16, 16, 8)
 	TABLE_LIST(8, 8, 8)
@@ -161,7 +159,6 @@ static const struct conv_table u8_table[
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table s16le_table[] = {
 	TABLE_LIST(32, 32, 16)
-	TABLE_LIST(24, 32, 16)
 	TABLE_LIST(24, 24, 16)
 	TABLE_LIST(16, 16, 16)
 	TABLE_LIST(8, 8, 16)
@@ -171,7 +168,6 @@ static const struct conv_table s16le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table s16be_table[] = {
 	TABLE_LIST(32, 32, 16)
-	TABLE_LIST(24, 32, 16)
 	TABLE_LIST(24, 24, 16)
 	TABLE_LIST(16, 16, 16)
 	TABLE_LIST(8, 8, 16)
@@ -181,7 +177,6 @@ static const struct conv_table s16be_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u16le_table[] = {
 	TABLE_LIST(32, 32, 16)
-	TABLE_LIST(24, 32, 16)
 	TABLE_LIST(24, 24, 16)
 	TABLE_LIST(16, 16, 16)
 	TABLE_LIST(8, 8, 16)
@@ -191,7 +186,6 @@ static const struct conv_table u16le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u16be_table[] = {
 	TABLE_LIST(32, 32, 16)
-	TABLE_LIST(24, 32, 16)
 	TABLE_LIST(24, 24, 16)
 	TABLE_LIST(16, 16, 16)
 	TABLE_LIST(8, 8, 16)
@@ -202,7 +196,6 @@ static const struct conv_table u16be_tab
 #ifdef notdef
 static const struct conv_table s24le_table[] = {
 	TABLE_LIST(32, 32, 24)
-	TABLE_LIST(24, 32, 24)
 	TABLE_LIST(24, 24, 24)
 	TABLE_LIST(16, 16, 24)
 	TABLE_LIST(8, 8, 24)
@@ -212,7 +205,6 @@ static const struct conv_table s24le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table s24be_table[] = {
 	TABLE_LIST(32, 32, 24)
-	TABLE_LIST(24, 32, 24)
 	TABLE_LIST(24, 24, 24)
 	TABLE_LIST(16, 16, 24)
 	TABLE_LIST(8, 8, 24)
@@ -222,7 +214,6 @@ static const struct conv_table s24be_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u24le_table[] = {
 	TABLE_LIST(32, 32, 24)
-	TABLE_LIST(24, 32, 24)
 	TABLE_LIST(24, 24, 24)
 	TABLE_LIST(16, 16, 24)
 	TABLE_LIST(8, 8, 24)
@@ -232,7 +223,6 @@ static const struct conv_table u24le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u24be_table[] = {
 	TABLE_LIST(32, 32, 24)
-	TABLE_LIST(24, 32, 24)
 	TABLE_LIST(24, 24, 24)
 	TABLE_LIST(16, 16, 24)
 	TABLE_LIST(8, 8, 24)
@@ -243,7 +233,6 @@ static const struct conv_table u24be_tab
 #endif
 static const struct conv_table s32le_table[] = {
 	TABLE_LIST(32, 32, 32)
-	TABLE_LIST(24, 32, 32)
 	TABLE_LIST(24, 24, 32)
 	TABLE_LIST(16, 16, 32)
 	TABLE_LIST(8, 8, 32)
@@ -253,7 +242,6 @@ static const struct conv_table s32le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table s32be_table[] = {
 	TABLE_LIST(32, 32, 32)
-	TABLE_LIST(24, 32, 32)
 	TABLE_LIST(24, 24, 32)
 	TABLE_LIST(16, 16, 32)
 	TABLE_LIST(8, 8, 32)
@@ -263,7 +251,6 @@ static const struct conv_table s32be_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u32le_table[] = {
 	TABLE_LIST(32, 32, 32)
-	TABLE_LIST(24, 32, 32)
 	TABLE_LIST(24, 24, 32)
 	TABLE_LIST(16, 16, 32)
 	TABLE_LIST(8, 8, 32)
@@ -273,7 +260,6 @@ static const struct conv_table u32le_tab
 	{0, 0, 0, NULL, NULL}};
 static const struct conv_table u32be_table[] = {
 	TABLE_LIST(32, 32, 32)
-	TABLE_LIST(24, 32, 32)
 	TABLE_LIST(24, 24, 32)
 	TABLE_LIST(16, 16, 32)
 	TABLE_LIST(8, 8, 32)
@@ -312,7 +298,6 @@ static const struct conv_table u32be_tab
 
 static const struct conv_table mulaw_table[] = {
 	MULAW_LIST(32, 32, 32)
-	MULAW_LIST(24, 32, 24)
 	MULAW_LIST(24, 24, 24)
 	MULAW_LIST(16, 16, 16)
 	

CVS commit: src/sys/dev

2017-11-06 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Nov  7 01:13:19 UTC 2017

Modified Files:
src/sys/dev: audio.c audiovar.h

Log Message:
A sysctl is now available to disable the in kernel mixer.
sysctl -w hw.hdafg0.usemixer=0

There currently is a problem draining the last block with the mixer
disabled.  I will fix this in a follow up commit.

AFAIK there will be a problem wiht vs(4) on x68k with the mixer disabled
as the filters for mulaw, alaw and unsigned linear have been removed post
audio mixing changes.

Documentation for this sysctl variable will be made to audio.4 in a follow
up commit.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.429 -r1.430 src/sys/dev/audio.c
cvs rdiff -u -r1.66 -r1.67 src/sys/dev/audiovar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.429 src/sys/dev/audio.c:1.430
--- src/sys/dev/audio.c:1.429	Sat Nov  4 01:50:48 2017
+++ src/sys/dev/audio.c	Tue Nov  7 01:13:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.429 2017/11/04 01:50:48 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.430 2017/11/07 01:13:19 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.429 2017/11/04 01:50:48 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.430 2017/11/07 01:13:19 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -320,6 +320,7 @@ static int audio_sysctl_frequency(SYSCTL
 static int audio_sysctl_precision(SYSCTLFN_PROTO);
 static int audio_sysctl_channels(SYSCTLFN_PROTO);
 static int audio_sysctl_latency(SYSCTLFN_PROTO);
+static int audio_sysctl_usemixer(SYSCTLFN_PROTO);
 
 static int	audiomatch(device_t, cfdata_t, void *);
 static void	audioattach(device_t, device_t, void *);
@@ -608,6 +609,7 @@ audioattach(device_t parent, device_t se
 
 	sc->sc_lastgain = 128;
 	sc->sc_multiuser = false;
+	sc->sc_usemixer = true;
 
 	error = vchan_autoconfig(sc);
 	if (error != 0) {
@@ -814,6 +816,15 @@ audioattach(device_t parent, device_t se
 			>sc_multiuser, 0,
 			CTL_HW, node->sysctl_num,
 			CTL_CREATE, CTL_EOL);
+
+		sysctl_createv(>sc_log, 0, NULL, NULL,
+			CTLFLAG_READWRITE,
+			CTLTYPE_BOOL, "usemixer",
+			SYSCTL_DESCR("allow in-kernel mixing"),
+			audio_sysctl_usemixer, 0,
+			(void *)sc, 0,
+			CTL_HW, node->sysctl_num,
+			CTL_CREATE, CTL_EOL);
 	}
 
 	selinit(>sc_rsel);
@@ -1594,6 +1605,9 @@ audio_waitio(struct audio_softc *sc, kco
 	/* Wait for pending I/O to complete. */
 	error = cv_wait_sig(chan, sc->sc_lock);
 
+	if (!sc->sc_usemixer)
+		return error;
+
 	found = false;
 	SIMPLEQ_FOREACH(vchan, >sc_audiochan, entries) {
 		if (vchan->vc == vc) {
@@ -2153,7 +2167,7 @@ audio_open(dev_t dev, struct audio_softc
 
 	KASSERT(mutex_owned(sc->sc_lock));
 
-	if (sc->sc_ready == false)
+	if (sc->sc_usemixer && !sc->sc_ready)
 		return ENXIO;
 
 	hw = sc->hw_if;
@@ -2166,36 +2180,50 @@ audio_open(dev_t dev, struct audio_softc
 		n = chan->chan + 1;
 
 	chan = kmem_zalloc(sizeof(struct audio_chan), KM_SLEEP);
-	vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);
+	if (sc->sc_usemixer)
+		vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);
+	else
+		vc = sc->sc_hwvc;
 	chan->vc = vc;
 
-	vc->sc_open = 0;
-	vc->sc_mode = 0;
-	vc->sc_sil_count = 0;
-	vc->sc_nrfilters = 0;
-	memset(vc->sc_rfilters, 0,
-	sizeof(vc->sc_rfilters));
-	vc->sc_rbus = false;
-	vc->sc_npfilters = 0;
-	memset(vc->sc_pfilters, 0,
-	sizeof(vc->sc_pfilters));
-	vc->sc_draining = false;
-	vc->sc_pbus = false;
-	vc->sc_lastinfovalid = false;
-	vc->sc_swvol = 255;
-	vc->sc_recswvol = 255;
+	if (sc->sc_usemixer) {
+		vc->sc_open = 0;
+		vc->sc_mode = 0;
+		vc->sc_sil_count = 0;
+		vc->sc_nrfilters = 0;
+		memset(vc->sc_rfilters, 0,
+		sizeof(vc->sc_rfilters));
+		vc->sc_rbus = false;
+		vc->sc_npfilters = 0;
+		memset(vc->sc_pfilters, 0,
+		sizeof(vc->sc_pfilters));
+		vc->sc_draining = false;
+		vc->sc_pbus = false;
+		vc->sc_lastinfovalid = false;
+		vc->sc_swvol = 255;
+		vc->sc_recswvol = 255;
+	} else {
+		if (sc->sc_opens > 0 || sc->sc_recopens > 0 ) {
+			kmem_free(chan, sizeof(struct audio_chan));
+			return EBUSY;
+		}
+	}
 
 	DPRINTF(("audio_open: flags=0x%x sc=%p hdl=%p\n",
 		 flags, sc, sc->hw_hdl));
 
-	error = audio_alloc_ring(sc, >sc_mpr, AUMODE_PLAY, AU_RING_SIZE);
-	if (error)
-		goto bad;
-	error = audio_alloc_ring(sc, >sc_mrr, AUMODE_RECORD, AU_RING_SIZE);
-	if (error)
-		goto bad;
+	if (sc->sc_usemixer) {
+		error = audio_alloc_ring(sc, >sc_mpr, AUMODE_PLAY,
+		AU_RING_SIZE);
+		if (error)
+			goto bad;
+		

CVS commit: src/sys/dev

2017-11-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Nov  4 01:50:48 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
AU_RING_SIZE -> s.bufsize in audio_initbufs.


To generate a diff of this commit:
cvs rdiff -u -r1.428 -r1.429 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.428 src/sys/dev/audio.c:1.429
--- src/sys/dev/audio.c:1.428	Fri Nov  3 21:15:18 2017
+++ src/sys/dev/audio.c	Sat Nov  4 01:50:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.428 2017/11/03 21:15:18 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.429 2017/11/04 01:50:48 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.428 2017/11/03 21:15:18 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.429 2017/11/04 01:50:48 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2012,7 +2012,7 @@ audio_init_ringbuffer(struct audio_softc
 		blksize = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
 		mode, >s.param);
 	} else {
-		int hwblksize = AU_RING_SIZE;
+		int hwblksize = rp->s.bufsize;
 		if (sc->hw_if->round_blocksize) {
 			if (audio_can_capture(sc))
 hwblksize = sc->sc_hwvc->sc_mpr.blksize;



CVS commit: src/sys/dev/isa

2017-11-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sat Nov  4 01:46:56 UTC 2017

Modified Files:
src/sys/dev/isa: sbdsp.c

Log Message:
Add AUDIO_ENCODING_SLINEAR to supported encodings.  This allows sb, sbpro
& sb16 to configure with 8-bit precision.

Tested in games/mame with a 486DX emulation.


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/dev/isa/sbdsp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/isa/sbdsp.c
diff -u src/sys/dev/isa/sbdsp.c:1.136 src/sys/dev/isa/sbdsp.c:1.137
--- src/sys/dev/isa/sbdsp.c:1.136	Mon Jul 11 11:31:50 2016
+++ src/sys/dev/isa/sbdsp.c	Sat Nov  4 01:46:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: sbdsp.c,v 1.136 2016/07/11 11:31:50 msaitoh Exp $	*/
+/*	$NetBSD: sbdsp.c,v 1.137 2017/11/04 01:46:56 nat Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2008 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sbdsp.c,v 1.136 2016/07/11 11:31:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sbdsp.c,v 1.137 2017/11/04 01:46:56 nat Exp $");
 
 #include "midi.h"
 #include "mpu.h"
@@ -640,6 +640,7 @@ sbdsp_set_params(
 	swcode = swap_bytes;
 }
 /* fall into */
+			case AUDIO_ENCODING_SLINEAR:
 			case AUDIO_ENCODING_SLINEAR_LE:
 bmode = SB_BMODE_SIGNED;
 break;
@@ -682,6 +683,7 @@ sbdsp_set_params(
 bmode |= SB_BMODE_STEREO;
 		} else if (m->model == SB_JAZZ && m->precision == 16) {
 			switch (p->encoding) {
+			case AUDIO_ENCODING_SLINEAR:
 			case AUDIO_ENCODING_SLINEAR_LE:
 break;
 			case AUDIO_ENCODING_ULINEAR_LE:
@@ -716,6 +718,7 @@ sbdsp_set_params(
 			switch (p->encoding) {
 			case AUDIO_ENCODING_SLINEAR_BE:
 			case AUDIO_ENCODING_SLINEAR_LE:
+			case AUDIO_ENCODING_SLINEAR:
 hw.encoding = AUDIO_ENCODING_ULINEAR_LE;
 swcode = change_sign8;
 break;



CVS commit: src/sys/dev

2017-11-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 21:15:18 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Blocksizes sould be rounded to a power of 2 as OSS applications need this.

Tested by martin@.


To generate a diff of this commit:
cvs rdiff -u -r1.427 -r1.428 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.427 src/sys/dev/audio.c:1.428
--- src/sys/dev/audio.c:1.427	Fri Nov  3 21:12:44 2017
+++ src/sys/dev/audio.c	Fri Nov  3 21:15:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.427 2017/11/03 21:12:44 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.428 2017/11/03 21:15:18 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.427 2017/11/03 21:12:44 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.428 2017/11/03 21:15:18 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2020,6 +2020,12 @@ audio_init_ringbuffer(struct audio_softc
 hwblksize = sc->sc_hwvc->sc_mrr.blksize;
 		}
 
+		int tmpblksize = 1; 	 
+		/* round blocksize to a power of 2 */ 	 
+		while (tmpblksize < blksize) 	 
+			tmpblksize <<= 1; 	 
+
+		blksize = tmpblksize;
 		if (blksize > hwblksize)
 			blksize = hwblksize;
 	}



CVS commit: src/sys/dev

2017-11-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 21:12:44 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Revert to previous.  It is necessary to use the calculated blocksize if
none supplied.

Tested by martin@.


To generate a diff of this commit:
cvs rdiff -u -r1.426 -r1.427 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.426 src/sys/dev/audio.c:1.427
--- src/sys/dev/audio.c:1.426	Fri Nov  3 05:31:38 2017
+++ src/sys/dev/audio.c	Fri Nov  3 21:12:44 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.426 2017/11/03 05:31:38 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.427 2017/11/03 21:12:44 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.426 2017/11/03 05:31:38 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.427 2017/11/03 21:12:44 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2676,22 +2676,26 @@ audio_setblksize(struct audio_softc *sc,
 {
 	struct audio_ringbuffer *mixcb, *cb;
 	audio_params_t *parm;
+	audio_stream_t *stream;
 
 	if (mode == AUMODE_RECORD) {
 		mixcb = >sc_mixring.sc_mrr;
 		cb = >sc_mrr;
 		parm = >sc_rparams;
+		stream = vc->sc_rustream;
 	} else {
 		mixcb = >sc_mixring.sc_mpr;
 		cb = >sc_mpr;
 		parm = >sc_pparams;
+		stream = vc->sc_pustream;
 	}
 
 	if (vc == sc->sc_hwvc) {
 		mixcb->blksize = audio_calc_blksize(sc, parm);
 		cb->blksize = audio_calc_blksize(sc, >s.param);
 	} else {
-		if (SPECIFIED(blksize))
+		cb->blksize = audio_calc_blksize(sc, >param);
+		if (SPECIFIED(blksize) && blksize > cb->blksize)
 			cb->blksize = blksize;
 	}
 }



CVS commit: src/sys/dev

2017-11-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 05:31:38 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
No need to ratify block size twice as this is done in audio_initbufs.

This is a rework of rev 1.421.


To generate a diff of this commit:
cvs rdiff -u -r1.425 -r1.426 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.425 src/sys/dev/audio.c:1.426
--- src/sys/dev/audio.c:1.425	Fri Nov  3 05:09:49 2017
+++ src/sys/dev/audio.c	Fri Nov  3 05:31:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.425 2017/11/03 05:09:49 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.426 2017/11/03 05:31:38 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.425 2017/11/03 05:09:49 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.426 2017/11/03 05:31:38 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2676,26 +2676,22 @@ audio_setblksize(struct audio_softc *sc,
 {
 	struct audio_ringbuffer *mixcb, *cb;
 	audio_params_t *parm;
-	audio_stream_t *stream;
 
 	if (mode == AUMODE_RECORD) {
 		mixcb = >sc_mixring.sc_mrr;
 		cb = >sc_mrr;
 		parm = >sc_rparams;
-		stream = vc->sc_rustream;
 	} else {
 		mixcb = >sc_mixring.sc_mpr;
 		cb = >sc_mpr;
 		parm = >sc_pparams;
-		stream = vc->sc_pustream;
 	}
 
 	if (vc == sc->sc_hwvc) {
 		mixcb->blksize = audio_calc_blksize(sc, parm);
 		cb->blksize = audio_calc_blksize(sc, >s.param);
 	} else {
-		cb->blksize = audio_calc_blksize(sc, >param);
-		if (SPECIFIED(blksize) && blksize > cb->blksize)
+		if (SPECIFIED(blksize))
 			cb->blksize = blksize;
 	}
 }



CVS commit: src/sys/dev

2017-11-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 05:09:49 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Calc latency when altering precision, frequency and channels sysctls.


To generate a diff of this commit:
cvs rdiff -u -r1.424 -r1.425 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.424 src/sys/dev/audio.c:1.425
--- src/sys/dev/audio.c:1.424	Fri Nov  3 05:07:37 2017
+++ src/sys/dev/audio.c	Fri Nov  3 05:09:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.424 2017/11/03 05:07:37 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.425 2017/11/03 05:09:49 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.424 2017/11/03 05:07:37 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.425 2017/11/03 05:09:49 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -5916,6 +5916,8 @@ audio_sysctl_frequency(SYSCTLFN_ARGS)
 	if (error)
 		aprint_error_dev(sc->sc_dev, "Error setting frequency, "
  "please check hardware capabilities\n");
+	if (error == 0)
+		audio_calc_latency(sc);
 	mutex_exit(sc->sc_lock);
 
 	return error;
@@ -5968,6 +5970,8 @@ audio_sysctl_precision(SYSCTLFN_ARGS)
 	if (error)
 		aprint_error_dev(sc->sc_dev, "Error setting precision, "
  "please check hardware capabilities\n");
+	if (error == 0)
+		audio_calc_latency(sc);
 	mutex_exit(sc->sc_lock);
 
 	return error;
@@ -6009,6 +6013,8 @@ audio_sysctl_channels(SYSCTLFN_ARGS)
 	if (error)
 		aprint_error_dev(sc->sc_dev, "Error setting channels, "
  "please check hardware capabilities\n");
+	if (error == 0)
+		audio_calc_latency(sc);
 	mutex_exit(sc->sc_lock);
 
 	return error;



CVS commit: src/sys/dev

2017-11-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 05:07:37 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Allow for block sizes less than hw block size.  This allows for the lowest
possible latency for all precision, sample rate and frequencies.

This is a rework of rev 1.419.


To generate a diff of this commit:
cvs rdiff -u -r1.423 -r1.424 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.423 src/sys/dev/audio.c:1.424
--- src/sys/dev/audio.c:1.423	Fri Nov  3 05:04:17 2017
+++ src/sys/dev/audio.c	Fri Nov  3 05:07:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.423 2017/11/03 05:04:17 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.424 2017/11/03 05:07:37 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.423 2017/11/03 05:04:17 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.424 2017/11/03 05:07:37 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2005,9 +2005,25 @@ audio_init_ringbuffer(struct audio_softc
 		blksize = rp->s.bufsize / AUMINNOBLK;
 	ROUNDSIZE(blksize);
 	DPRINTF(("audio_init_ringbuffer: MI blksize=%d\n", blksize));
-	if (sc->hw_if->round_blocksize)
+
+	struct virtual_channel *hwvc = sc->sc_hwvc;
+	if (sc->hw_if->round_blocksize &&
+	(rp == >sc_mpr || rp == >sc_mrr)) {
 		blksize = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
-		 mode, >s.param);
+		mode, >s.param);
+	} else {
+		int hwblksize = AU_RING_SIZE;
+		if (sc->hw_if->round_blocksize) {
+			if (audio_can_capture(sc))
+hwblksize = sc->sc_hwvc->sc_mpr.blksize;
+			else
+hwblksize = sc->sc_hwvc->sc_mrr.blksize;
+		}
+
+		if (blksize > hwblksize)
+			blksize = hwblksize;
+	}
+
 	if (blksize <= 0)
 		panic("audio_init_ringbuffer: blksize=%d", blksize);
 	nblks = rp->s.bufsize / blksize;



CVS commit: src/sys/dev

2017-11-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Nov  3 05:04:17 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Use mix ring block size in audio write, startp, and audio drain.


To generate a diff of this commit:
cvs rdiff -u -r1.422 -r1.423 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.422 src/sys/dev/audio.c:1.423
--- src/sys/dev/audio.c:1.422	Thu Nov  2 02:08:02 2017
+++ src/sys/dev/audio.c	Fri Nov  3 05:04:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.422 2017/11/02 02:08:02 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.423 2017/11/03 05:04:17 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.422 2017/11/02 02:08:02 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.423 2017/11/03 05:04:17 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2360,8 +2360,9 @@ audio_drain(struct audio_softc *sc, stru
 		 * block was too short.  Pad it and start now.
 		 */
 		uint8_t *inp = cb->s.inp;
+		int blksize = sc->sc_mixring.sc_mpr.blksize;
 
-		cc = cb->blksize - (inp - cb->s.start) % cb->blksize;
+		cc = blksize - (inp - cb->s.start) % blksize;
 		audio_fill_silence(>s.param, inp, cc);
 		cb->s.inp = audio_stream_add_inp(>s, inp, cc);
 		mutex_exit(sc->sc_intr_lock);
@@ -2400,9 +2401,9 @@ audio_drain(struct audio_softc *sc, stru
 #endif
 	vc->sc_draining = true;
 
-	drops = cb->drops;
+	drops = cb->drops + (cb->blksize * PREFILL_BLOCKS);
 	error = 0;
-	while (cb->drops == drops && !error) {
+	while (cb->drops < drops && !error) {
 		DPRINTF(("audio_drain: vc=%p used=%d, drops=%ld\n",
 			vc,
 			audio_stream_get_used(>sc_mpr.s),
@@ -2941,7 +2942,7 @@ audio_write(struct audio_softc *sc, stru
 			filter = vc->sc_pfilters[0];
 			filter->set_fetcher(filter, );
 			fetcher = >sc_pfilters[vc->sc_npfilters - 1]->base;
-			cc = cb->blksize * 2;
+			cc = sc->sc_mixring.sc_mpr.blksize * 2;
 			error = fetcher->fetch_to(sc, fetcher, , cc);
 			if (error != 0) {
 fetcher = 
@@ -3525,7 +3526,7 @@ audiostartp(struct audio_softc *sc, stru
 	if (vc == sc->sc_hwvc)
 		return 0;
 
-	if (!vc->sc_mpr.mmapped && used < vc->sc_mpr.blksize) {
+	if (!vc->sc_mpr.mmapped && used < sc->sc_mixring.sc_mpr.blksize) {
 		cv_broadcast(>sc_wchan);
 		DPRINTF(("%s: wakeup and return\n", __func__));
 		return 0;



CVS commit: src/sys/dev

2017-11-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Nov  2 02:08:02 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Revert commit rev 1.419 to audio.c.  This should address PR kern/52685.

This also means that drivers that have a static block size will have more
latency at lower sample rates/precision/channels.  Also audio drivers that
do more than supply rounded blocksizes in their round_blocksize functions
will have to be changed.


To generate a diff of this commit:
cvs rdiff -u -r1.421 -r1.422 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.421 src/sys/dev/audio.c:1.422
--- src/sys/dev/audio.c:1.421	Tue Oct 31 21:18:02 2017
+++ src/sys/dev/audio.c	Thu Nov  2 02:08:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.421 2017/10/31 21:18:02 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.422 2017/11/02 02:08:02 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.421 2017/10/31 21:18:02 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.422 2017/11/02 02:08:02 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2005,21 +2005,9 @@ audio_init_ringbuffer(struct audio_softc
 		blksize = rp->s.bufsize / AUMINNOBLK;
 	ROUNDSIZE(blksize);
 	DPRINTF(("audio_init_ringbuffer: MI blksize=%d\n", blksize));
-
-	struct virtual_channel *hwvc = sc->sc_hwvc;
-	if (sc->hw_if->round_blocksize &&
-	(rp == >sc_mpr || rp == >sc_mrr)) {
+	if (sc->hw_if->round_blocksize)
 		blksize = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
-		mode, >s.param);
-	} else {
-		int tmpblksize = 1;
-		/* round blocksize to a power of 2 */
-		while (tmpblksize < blksize)
-			tmpblksize <<= 1;
-
-		blksize = tmpblksize;
-	}
-
+		 mode, >s.param);
 	if (blksize <= 0)
 		panic("audio_init_ringbuffer: blksize=%d", blksize);
 	nblks = rp->s.bufsize / blksize;



CVS commit: src/sys/dev/isa

2017-10-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Oct 31 21:53:48 UTC 2017

Modified Files:
src/sys/dev/isa: gus.c

Log Message:
Add padding to gus.c so fields match up when it ts cast to a ad1848_isa
softc for the allocation of hw ring buffers.

Locking fixes as gus KASSERTS / uses the codec locks.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/dev/isa/gus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/isa/gus.c
diff -u src/sys/dev/isa/gus.c:1.111 src/sys/dev/isa/gus.c:1.112
--- src/sys/dev/isa/gus.c:1.111	Wed Feb  1 19:10:33 2017
+++ src/sys/dev/isa/gus.c	Tue Oct 31 21:53:48 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gus.c,v 1.111 2017/02/01 19:10:33 jakllsch Exp $	*/
+/*	$NetBSD: gus.c,v 1.112 2017/10/31 21:53:48 nat Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1999, 2008 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gus.c,v 1.111 2017/02/01 19:10:33 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gus.c,v 1.112 2017/10/31 21:53:48 nat Exp $");
 
 #include 
 #include 
@@ -175,15 +175,16 @@ struct gus_softc {
 	kmutex_t sc_intr_lock;
 	void *sc_ih;			/* interrupt vector */
 	bus_space_tag_t sc_iot;		/* tag */
-	isa_chipset_tag_t sc_ic;	/* ISA chipset info */
 	bus_space_handle_t sc_ioh1;	/* handle */
 	bus_space_handle_t sc_ioh2;	/* handle */
 	bus_space_handle_t sc_ioh3;	/* ICS2101 handle */
 	bus_space_handle_t sc_ioh4;	/* MIDI handle */
+	char padding[20];
 
 	callout_t sc_dmaout_ch;
 
-	int sc_iobase;			/* I/O base address */
+	isa_chipset_tag_t sc_ic;	/* ISA chipset info */
+	char padding1[4];
 	int sc_irq;			/* IRQ used */
 	int sc_playdrq;			/* DMA channel for play */
 	bus_size_t sc_play_maxsize;	/* DMA size for play */
@@ -257,6 +258,7 @@ struct gus_softc {
 		struct ics2101_softc sc_mixer_u;
 		struct ad1848_isa_softc sc_codec_u;
 	} u;
+	int sc_iobase;			/* I/O base address */
 #define sc_mixer u.sc_mixer_u
 #define sc_codec u.sc_codec_u
 };
@@ -818,9 +820,12 @@ gusattach(device_t parent, device_t self
 	const struct audio_hw_if *hwif;
 
 	sc = device_private(self);
+	sc->sc_dev = self;
 	ia = aux;
 	callout_init(>sc_dmaout_ch, CALLOUT_MPSAFE);
 	ad1848_init_locks(>sc_codec.sc_ad1848, IPL_AUDIO);
+	sc->sc_lock = sc->sc_codec.sc_ad1848.sc_lock;
+	sc->sc_intr_lock = sc->sc_codec.sc_ad1848.sc_intr_lock;
 
 	sc->sc_iot = iot = ia->ia_iot;
 	sc->sc_ic = ia->ia_ic;
@@ -859,7 +864,7 @@ gusattach(device_t parent, device_t self
 
 	delay(500);
 
-	mutex_spin_enter(>sc_intr_lock);
+	mutex_spin_enter(>sc_codec.sc_ad1848.sc_intr_lock);
 
 	c = bus_space_read_1(iot, ioh3, GUS_BOARD_REV);
 	if (c != 0xff)
@@ -872,7 +877,7 @@ gusattach(device_t parent, device_t self
 
 	gusreset(sc, GUS_MAX_VOICES); /* initialize all voices */
 	gusreset(sc, GUS_MIN_VOICES); /* then set to just the ones we use */
-	mutex_spin_exit(>sc_intr_lock);
+	mutex_spin_exit(>sc_codec.sc_ad1848.sc_intr_lock);
 
 	/*
 	 * Setup the IRQ and DRQ lines in software, using values from
@@ -2311,7 +2316,7 @@ gus_set_params(void *addr,int setmode, i
 		return EINVAL;
 	}
 
-	mutex_spin_enter(>sc_intr_lock);
+	mutex_spin_enter(>sc_codec.sc_ad1848.sc_intr_lock);
 
 	if (p->precision == 8) {
 		sc->sc_voc[GUS_VOICE_LEFT].voccntl &= ~GUSMASK_DATA_SIZE16;
@@ -2332,7 +2337,7 @@ gus_set_params(void *addr,int setmode, i
 	if (setmode & AUMODE_PLAY)
 		sc->sc_orate = p->sample_rate;
 
-	mutex_spin_exit(>sc_intr_lock);
+	mutex_spin_exit(>sc_codec.sc_ad1848.sc_intr_lock);
 
 	hw = *p;
 	/* clear req_size before setting a filter to avoid confliction



CVS commit: src/sys/dev

2017-10-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Oct 31 21:18:02 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Only allow blocksizes greater or equal to the calculated one.

This should help applications as the blocksize obtained (AUDIO_SET/GETINFO)
will work without stutter.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.420 -r1.421 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.420 src/sys/dev/audio.c:1.421
--- src/sys/dev/audio.c:1.420	Tue Oct 31 21:13:24 2017
+++ src/sys/dev/audio.c	Tue Oct 31 21:18:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.421 2017/10/31 21:18:02 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.421 2017/10/31 21:18:02 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2689,11 +2689,9 @@ audio_setblksize(struct audio_softc *sc,
 		mixcb->blksize = audio_calc_blksize(sc, parm);
 		cb->blksize = audio_calc_blksize(sc, >s.param);
 	} else {
-		if (SPECIFIED(blksize))
+		cb->blksize = audio_calc_blksize(sc, >param);
+		if (SPECIFIED(blksize) && blksize > cb->blksize)
 			cb->blksize = blksize;
-		else {
-			cb->blksize = audio_calc_blksize(sc, >param);
-		}
 	}
 }
 



CVS commit: src/sys/dev

2017-10-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Oct 31 21:13:24 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Move calculation of sc_latency into a function.

The latency of the audio device is updated on attach in the audio auto
config and shown on screen.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.419 -r1.420 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.419 src/sys/dev/audio.c:1.420
--- src/sys/dev/audio.c:1.419	Tue Oct 31 21:09:26 2017
+++ src/sys/dev/audio.c	Tue Oct 31 21:13:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.419 2017/10/31 21:09:26 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.419 2017/10/31 21:09:26 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -278,6 +278,7 @@ int	mix_write(void *);
 int	mix_read(void *);
 int	audio_check_params(struct audio_params *);
 
+static void	audio_calc_latency(struct audio_softc *);
 static void	audio_setblksize(struct audio_softc *,
  struct virtual_channel *, int, int);
 int	audio_calc_blksize(struct audio_softc *, const audio_params_t *);
@@ -2653,6 +2654,18 @@ audio_clear_intr_unlocked(struct audio_s
 }
 
 static void
+audio_calc_latency(struct audio_softc *sc)
+{
+	const struct audio_params *ap = >sc_vchan_params;
+
+	if (ap->sample_rate == 0 || ap->channels == 0 || ap->precision == 0)
+		return;
+
+	sc->sc_latency = sc->sc_hwvc->sc_mpr.blksize * 1000 * PREFILL_BLOCKS
+	* NBBY / ap->sample_rate / ap->channels / ap->precision;
+}
+
+static void
 audio_setblksize(struct audio_softc *sc, struct virtual_channel *vc,
 int blksize, int mode)
 {
@@ -6043,14 +6056,7 @@ audio_sysctl_latency(SYSCTLFN_ARGS)
 		AUMODE_PLAY | AUMODE_PLAY_ALL | AUMODE_RECORD);
 	}
 
-	if (sc->sc_vchan_params.sample_rate > 0 &&
-	sc->sc_vchan_params.channels > 0 &&
-	sc->sc_vchan_params.precision > 0) {
-		sc->sc_latency = sc->sc_hwvc->sc_mpr.blksize * 1000 * 
-		PREFILL_BLOCKS / sc->sc_vchan_params.sample_rate /
-		sc->sc_vchan_params.channels * NBBY /
-		sc->sc_vchan_params.precision;
-	}
+	audio_calc_latency(sc);
 	mutex_exit(sc->sc_lock);
 
 	return error;
@@ -6100,19 +6106,25 @@ vchan_autoconfig(struct audio_softc *sc)
 		sc->sc_vchan_params.precision,
 		sc->sc_vchan_params.channels,
 		sc->sc_vchan_params.sample_rate);
-	mutex_exit(sc->sc_lock);
 
-	return 0;
+	goto found;
 }
 			}
 		}
 	}
 
-	aprint_error_dev(sc->sc_dev, "Virtual format auto config failed!\n"
-		 "Please check hardware capabilities\n");
+found:
+	if (error == 0) {
+		audio_calc_latency(sc);
+		aprint_normal_dev(sc->sc_dev, "Latency: %d milliseconds\n",
+		sc->sc_latency);
+	} else {
+		aprint_error_dev(sc->sc_dev, "Virtual format auto config failed!\n");
+		aprint_error_dev(sc->sc_dev, "Please check hardware capabilities\n");
+	}
 	mutex_exit(sc->sc_lock);
 
-	return EINVAL;
+	return error;
 }
 
 static void



CVS commit: src/sys/dev

2017-10-31 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Oct 31 21:09:27 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
round_blocksize is only used for the hardware ring buffer.  All other
buffers (mix ring, streams) are set to be a power of 2.

This allows for consistent latency where a static blocksize is enforced by
the underlying audio device driver.

Ok christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.418 -r1.419 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.418 src/sys/dev/audio.c:1.419
--- src/sys/dev/audio.c:1.418	Sat Oct 28 03:34:26 2017
+++ src/sys/dev/audio.c	Tue Oct 31 21:09:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.418 2017/10/28 03:34:26 riastradh Exp $	*/
+/*	$NetBSD: audio.c,v 1.419 2017/10/31 21:09:26 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.418 2017/10/28 03:34:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.419 2017/10/31 21:09:26 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2004,9 +2004,21 @@ audio_init_ringbuffer(struct audio_softc
 		blksize = rp->s.bufsize / AUMINNOBLK;
 	ROUNDSIZE(blksize);
 	DPRINTF(("audio_init_ringbuffer: MI blksize=%d\n", blksize));
-	if (sc->hw_if->round_blocksize)
+
+	struct virtual_channel *hwvc = sc->sc_hwvc;
+	if (sc->hw_if->round_blocksize &&
+	(rp == >sc_mpr || rp == >sc_mrr)) {
 		blksize = sc->hw_if->round_blocksize(sc->hw_hdl, blksize,
-		 mode, >s.param);
+		mode, >s.param);
+	} else {
+		int tmpblksize = 1;
+		/* round blocksize to a power of 2 */
+		while (tmpblksize < blksize)
+			tmpblksize <<= 1;
+
+		blksize = tmpblksize;
+	}
+
 	if (blksize <= 0)
 		panic("audio_init_ringbuffer: blksize=%d", blksize);
 	nblks = rp->s.bufsize / blksize;



CVS commit: src/share/man/man4

2017-10-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Oct 27 19:00:07 UTC 2017

Modified Files:
src/share/man/man4: audio.4

Log Message:
Document the hw.driverN.latency sysctl variable.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/share/man/man4/audio.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/audio.4
diff -u src/share/man/man4/audio.4:1.80 src/share/man/man4/audio.4:1.81
--- src/share/man/man4/audio.4:1.80	Mon Jul  3 21:30:58 2017
+++ src/share/man/man4/audio.4	Fri Oct 27 19:00:07 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: audio.4,v 1.80 2017/07/03 21:30:58 wiz Exp $
+.\"	$NetBSD: audio.4,v 1.81 2017/10/27 19:00:07 nat Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -112,6 +112,7 @@ variables.
 .It hw.driverN.precision
 .It hw.driverN.frequency
 .It hw.driverN.channels
+.It hw.driverN.latency
 .It hw.driverN.multiuser
 .El
 .Pp
@@ -124,10 +125,28 @@ hw.hdafg0.channels, hw.hdafg0.precision,
 For best results, values close to the underlying hardware should be chosen.
 These variables may only be changed when the sampling device is not in use.
 .Pp
-An additional
+The hw.driverN.latency
+.Xr sysctl 8
+variable controls the latency of the in-kernel mixer by varying the hardware
+blocksize.
+It accepts a value in milliseconds(ms), fractional values are not allowed.
+A value of zero will default to 150ms.
+.Pp
+If a static blocksize is enforced by the underlying hardware driver this value
+cannot be changed.
+.Pp
+For audio applications that do not specify a preferred blocksize when configuring
+the audio device, this will be the latency these applications have.
+.Pp
+For audio applications that
+.Xr mmap 2
+the audio device for play back the resultant latency is a third (1/3) of the value
+of the hw.driverN.latency variable.
+.Pp
+The hw.driverN.multiuser
 .Xr sysctl 8
 variable determines if multiple users are allowed to access the sampling
-device, hw.driverN.multiuser.
+device.
 .Pp
 By default it is set to false.
 This means that the sampling device may be only used by



CVS commit: src/sys/dev

2017-10-26 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Oct 27 01:34:32 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Independent blocksizes for virtual channels where a static blocksize is
not stipulated by the underlying hw driver.

This improves latency in games esp. when the stream format differs from
the harware format.

OK christos@.


To generate a diff of this commit:
cvs rdiff -u -r1.416 -r1.417 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.416 src/sys/dev/audio.c:1.417
--- src/sys/dev/audio.c:1.416	Thu Oct 26 22:45:00 2017
+++ src/sys/dev/audio.c	Fri Oct 27 01:34:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.416 2017/10/26 22:45:00 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.417 2017/10/27 01:34:32 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.416 2017/10/26 22:45:00 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.417 2017/10/27 01:34:32 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -276,6 +276,8 @@ int	mix_write(void *);
 int	mix_read(void *);
 int	audio_check_params(struct audio_params *);
 
+static void	audio_setblksize(struct audio_softc *,
+ struct virtual_channel *, int, int);
 int	audio_calc_blksize(struct audio_softc *, const audio_params_t *);
 void	audio_fill_silence(const struct audio_params *, uint8_t *, int);
 int	audio_silence_copyout(struct audio_softc *, int, struct uio *);
@@ -2221,9 +2223,6 @@ audio_open(dev_t dev, struct audio_softc
 		mode |= AUMODE_PLAY | AUMODE_PLAY_ALL;
 	}
 
-	vc->sc_mpr.blksize = sc->sc_mixring.sc_mpr.blksize;
-	vc->sc_mrr.blksize = sc->sc_mixring.sc_mrr.blksize;
-
 	/*
 	 * Multiplex device: /dev/audio (MU-Law) and /dev/sound (linear)
 	 * The /dev/audio is always (re)set to 8-bit MU-Law mono
@@ -2641,6 +2640,38 @@ audio_clear_intr_unlocked(struct audio_s
 	mutex_exit(sc->sc_intr_lock);
 }
 
+static void
+audio_setblksize(struct audio_softc *sc, struct virtual_channel *vc,
+int blksize, int mode)
+{
+	struct audio_ringbuffer *mixcb, *cb;
+	audio_params_t *parm;
+	audio_stream_t *stream;
+
+	if (mode == AUMODE_RECORD) {
+		mixcb = >sc_mixring.sc_mrr;
+		cb = >sc_mrr;
+		parm = >sc_rparams;
+		stream = vc->sc_rustream;
+	} else {
+		mixcb = >sc_mixring.sc_mpr;
+		cb = >sc_mpr;
+		parm = >sc_pparams;
+		stream = vc->sc_pustream;
+	}
+
+	if (vc == sc->sc_hwvc) {
+		mixcb->blksize = audio_calc_blksize(sc, parm);
+		cb->blksize = audio_calc_blksize(sc, >s.param);
+	} else {
+		if (SPECIFIED(blksize))
+			cb->blksize = blksize;
+		else {
+			cb->blksize = audio_calc_blksize(sc, >param);
+		}
+	}
+}
+
 int
 audio_calc_blksize(struct audio_softc *sc, const audio_params_t *parm)
 {
@@ -4714,24 +4745,10 @@ audiosetinfo(struct audio_softc *sc, str
 			audio_init_record(sc, vc);
 	}
 
-	if (vc == sc->sc_hwvc) {
-		if (!cleared) {
-			audio_clear_intr_unlocked(sc, vc);
-			cleared = true;
-		}
-		if (nr > 0) {
-			sc->sc_mixring.sc_mrr.blksize =
-			audio_calc_blksize(sc, >sc_rparams);
-			vc->sc_mrr.blksize = audio_calc_blksize(sc,
-			>sc_mrr.s.param);
-		}
-		if (np > 0) {
-			sc->sc_mixring.sc_mpr.blksize = audio_calc_blksize(sc,
-			>sc_pparams);
-			vc->sc_mpr.blksize = audio_calc_blksize(sc,
-			>sc_mpr.s.param);
-		}
-	}
+	if (nr > 0)
+		audio_setblksize(sc, vc, ai->blocksize, AUMODE_RECORD);
+	if (np > 0)
+		audio_setblksize(sc, vc, ai->blocksize, AUMODE_PLAY);
 
 	if (hw->commit_settings && sc->sc_opens + sc->sc_recopens == 0) {
 		error = hw->commit_settings(sc->hw_hdl);



CVS commit: src/sys/dev

2017-10-26 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Oct 26 22:45:00 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Ensure that the low/high water marks are at least PREFILL_BLOCKS.


To generate a diff of this commit:
cvs rdiff -u -r1.415 -r1.416 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.415 src/sys/dev/audio.c:1.416
--- src/sys/dev/audio.c:1.415	Thu Oct 26 22:38:27 2017
+++ src/sys/dev/audio.c	Thu Oct 26 22:45:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.415 2017/10/26 22:38:27 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.416 2017/10/26 22:45:00 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.415 2017/10/26 22:38:27 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.416 2017/10/26 22:45:00 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -4769,14 +4769,16 @@ cleanup:
 		blks = ai->hiwat;
 		if (blks > vc->sc_mpr.maxblks)
 			blks = vc->sc_mpr.maxblks;
-		if (blks < 2)
-			blks = 2;
+		if (blks < PREFILL_BLOCKS + 1)
+			blks = PREFILL_BLOCKS + 1;
 		vc->sc_mpr.usedhigh = blks * vc->sc_mpr.blksize;
 	}
 	if (SPECIFIED(ai->lowat)) {
 		blks = ai->lowat;
 		if (blks > vc->sc_mpr.maxblks - 1)
 			blks = vc->sc_mpr.maxblks - 1;
+		if (blks < PREFILL_BLOCKS)
+			blks = PREFILL_BLOCKS;
 		vc->sc_mpr.usedlow = blks * vc->sc_mpr.blksize;
 	}
 	if (SPECIFIED(ai->hiwat) || SPECIFIED(ai->lowat)) {



CVS commit: src/sys/dev

2017-10-26 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Oct 26 22:38:27 UTC 2017

Modified Files:
src/sys/dev: audio.c audiovar.h

Log Message:
Add latency sysctl to adjust hw blocksize and hence latency of the mixer.

usage: sysctl -w hw.hdafg0.lantency="value in milliseconds"

It is possible to set the latency of the mixer unless a static blocksize
is configured by the underlying hardware driver (pad, vcaudio on RPI).

Documentation updates to audio.4 will occur in a follow up commit.

OK christos@.  XXX pullup-8.


To generate a diff of this commit:
cvs rdiff -u -r1.414 -r1.415 src/sys/dev/audio.c
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/audiovar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.414 src/sys/dev/audio.c:1.415
--- src/sys/dev/audio.c:1.414	Wed Oct 25 08:12:38 2017
+++ src/sys/dev/audio.c	Thu Oct 26 22:38:27 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.414 2017/10/25 08:12:38 maya Exp $	*/
+/*	$NetBSD: audio.c,v 1.415 2017/10/26 22:38:27 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.414 2017/10/25 08:12:38 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.415 2017/10/26 22:38:27 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -205,6 +205,7 @@ int	audiodebug = AUDIO_DEBUG;
 #define DPRINTFN(n,x)
 #endif
 
+#define PREFILL_BLOCKS	3	/* no. audioblocks required to start stream */
 #define ROUNDSIZE(x)	(x) &= -16	/* round to nice boundary */
 #define SPECIFIED(x)	((int)(x) != ~0)
 #define SPECIFIED_CH(x)	((x) != (u_char)~0)
@@ -313,6 +314,7 @@ int	audio_set_defaults(struct audio_soft
 static int audio_sysctl_frequency(SYSCTLFN_PROTO);
 static int audio_sysctl_precision(SYSCTLFN_PROTO);
 static int audio_sysctl_channels(SYSCTLFN_PROTO);
+static int audio_sysctl_latency(SYSCTLFN_PROTO);
 
 static int	audiomatch(device_t, cfdata_t, void *);
 static void	audioattach(device_t, device_t, void *);
@@ -498,6 +500,7 @@ audioattach(device_t parent, device_t se
 	sc->sc_recopens = 0;
 	sc->sc_aivalid = false;
  	sc->sc_ready = true;
+	sc->sc_latency = audio_blk_ms * PREFILL_BLOCKS;
 
  	sc->sc_format[0].mode = AUMODE_PLAY | AUMODE_RECORD;
  	sc->sc_format[0].encoding =
@@ -793,6 +796,15 @@ audioattach(device_t parent, device_t se
 
 		sysctl_createv(>sc_log, 0, NULL, NULL,
 			CTLFLAG_READWRITE,
+			CTLTYPE_INT, "latency",
+			SYSCTL_DESCR("latency"),
+			audio_sysctl_latency, 0,
+			(void *)sc, 0,
+			CTL_HW, node->sysctl_num,
+			CTL_CREATE, CTL_EOL);
+
+		sysctl_createv(>sc_log, 0, NULL, NULL,
+			CTLFLAG_READWRITE,
 			CTLTYPE_BOOL, "multiuser",
 			SYSCTL_DESCR("allow multiple user acess"),
 			NULL, 0,
@@ -2634,8 +2646,8 @@ audio_calc_blksize(struct audio_softc *s
 {
 	int blksize;
 
-	blksize = parm->sample_rate * audio_blk_ms / 1000 *
-	 parm->channels * parm->precision / NBBY;
+	blksize = parm->sample_rate * sc->sc_latency * parm->channels /
+	1000 * parm->precision / NBBY / PREFILL_BLOCKS;
 	return blksize;
 }
 
@@ -4106,7 +4118,7 @@ audio_set_vchan_defaults(struct audio_so
 	>sc_encodings);
 
 	if (error == 0)
-		error = audiosetinfo(sc, , false, vc);
+		error = audiosetinfo(sc, , true, vc);
 
 	return error;
 }
@@ -5955,6 +5967,64 @@ audio_sysctl_channels(SYSCTLFN_ARGS)
 	return error;
 }
 
+/* sysctl helper to set audio latency */
+static int
+audio_sysctl_latency(SYSCTLFN_ARGS)
+{
+	struct sysctlnode node;
+	struct audio_softc *sc;
+	int t, error;
+
+	node = *rnode;
+	sc = node.sysctl_data;
+
+	t = sc->sc_latency;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL)
+		return error;
+
+	mutex_enter(sc->sc_lock);
+
+	/* This may not change when a virtual channel is open */
+	if (sc->sc_opens || sc->sc_recopens) {
+		mutex_exit(sc->sc_lock);
+		return EBUSY;
+	}
+
+	if (t < 0 || t > 4000) {
+		mutex_exit(sc->sc_lock);
+		return EINVAL;
+	}
+
+	if (t == 0)
+		sc->sc_latency = audio_blk_ms * PREFILL_BLOCKS;
+	else
+		sc->sc_latency = (unsigned int)t;
+
+	error = audio_set_vchan_defaults(sc,
+	AUMODE_PLAY | AUMODE_PLAY_ALL | AUMODE_RECORD);
+	if (error) {
+		aprint_error_dev(sc->sc_dev, "Error setting latency, "
+ "latency restored to default\n");
+		sc->sc_latency = audio_blk_ms * PREFILL_BLOCKS;
+		error = audio_set_vchan_defaults(sc,
+		AUMODE_PLAY | AUMODE_PLAY_ALL | AUMODE_RECORD);
+	}
+
+	if (sc->sc_vchan_params.sample_rate > 0 &&
+	sc->sc_vchan_params.channels > 0 &&
+	sc->sc_vchan_params.precision > 0) {
+		sc->sc_latency = sc->sc_hwvc->sc_mpr.blksize * 1000 * 
+		PREFILL_BLOCKS /

CVS commit: src/sys/dev

2017-10-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Oct  2 07:06:15 UTC 2017

Modified Files:
src/sys/dev: auconv.c

Log Message:
Allow maxused to be an odd number of bytes.  This makes single byte
conversions work for the test described in the PR.

Addresses another part of PR kern/52586.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/auconv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/auconv.c
diff -u src/sys/dev/auconv.c:1.32 src/sys/dev/auconv.c:1.33
--- src/sys/dev/auconv.c:1.32	Mon Oct  2 06:06:43 2017
+++ src/sys/dev/auconv.c	Mon Oct  2 07:06:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.c,v 1.32 2017/10/02 06:06:43 nat Exp $	*/
+/*	$NetBSD: auconv.c,v 1.33 2017/10/02 07:06:15 nat Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.32 2017/10/02 06:06:43 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.33 2017/10/02 07:06:15 nat Exp $");
 
 #include 
 #include 
@@ -512,7 +512,7 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 	valid = n_validbits / NBBY;	\
 	target = t_prec / NBBY;		\
 	this = (stream_filter_t *)self;	\
-	max_used = ((max_used / hw) * hw) & ~1;\
+	max_used = ((max_used / hw) * hw);\
 	\
 	if ((err = this->prev->fetch_to(sc, this->prev, this->src,	\
 			max_used)))	\



CVS commit: src/sys/dev

2017-10-02 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Oct  2 06:06:43 UTC 2017

Modified Files:
src/sys/dev: auconv.c

Log Message:
Improve LINEAR_LINEARN macro - inparticular BE/LE conversions.

Addresses part of PR kern/52586 analyzed and reported by isaki@.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/auconv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/auconv.c
diff -u src/sys/dev/auconv.c:1.31 src/sys/dev/auconv.c:1.32
--- src/sys/dev/auconv.c:1.31	Sun Jul 30 00:47:48 2017
+++ src/sys/dev/auconv.c	Mon Oct  2 06:06:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: auconv.c,v 1.31 2017/07/30 00:47:48 nat Exp $	*/
+/*	$NetBSD: auconv.c,v 1.32 2017/10/02 06:06:43 nat Exp $	*/
 
 /*
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.31 2017/07/30 00:47:48 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.32 2017/10/02 06:06:43 nat Exp $");
 
 #include 
 #include 
@@ -542,6 +542,30 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 	d[--j] = 0;			\
 			}		\
 		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
+	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_BE		\
+	 && enc_dst == AUDIO_ENCODING_SLINEAR_BE)			\
+	|| (enc_src == AUDIO_ENCODING_ULINEAR_BE			\
+		&& enc_dst == AUDIO_ENCODING_ULINEAR_BE)) {		\
+		/*			\
+		 * slinearNbe -> slinearNbe\
+		 * ulinearNbe -> ulinearNbe\
+		 */			\
+		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
+			i = valid;	\
+			j = target;	\
+			if (j < i) {	\
+j = 0;	\
+while (j < target)			\
+	d[j++] = s[i++];		\
+			} else {	\
+j = 0;	\
+i = 0;	\
+while (i < valid)			\
+	d[j++] = s[i++];		\
+while (j < target)			\
+	d[j++] = 0;			\
+			}		\
+		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
 	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_LE		\
 		&& enc_dst == AUDIO_ENCODING_SLINEAR_BE)		\
 		   || (enc_src == AUDIO_ENCODING_ULINEAR_LE		\
@@ -555,15 +579,15 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 			j = target;	\
 			if (j < i) {	\
 while (j > 0) {\
-	d[--j] = s[target - i];		\
-	i--;\
+	d[target - j] = s[--i];		\
+	j--;\
 }	\
 			} else {	\
 while (j > i)\
 	d[--j] = 0;			\
-while (j > 0) {\
-	d[--j] = s[target - i];		\
-	i--;\
+j = 0;	\
+while (i > 0) {\
+	d[j++] = s[--i];		\
 }	\
 			}		\
 		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
@@ -576,18 +600,14 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 		 * slinearNbe -> ulinearNle\
 		 */			\
 		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = valid;	\
+			i = 0;		\
 			j = target;	\
-			if (j < i) {	\
-while (j > 0) {\
-	d[--j] = s[valid - i];		\
-	i--;\
-}	\
+			if (target < valid) {\
+while (j > 0)\
+	d[--j] = s[i++];		\
 			} else {	\
-while (j > 0) {\
-	d[--j] = s[valid - i];		\
-	i--;\
-}	\
+while (i < valid)			\
+	d[--j] = s[i++];		\
 while (j > 0)\
 	d[--j] = 0;			\
 			}		\
@@ -602,21 +622,42 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 		 * ulinearNbe -> ulinearNle\
 		 */			\
 		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
+			i = 0;		\
+			j = target;	\
+			if (target < valid) {\
+while (j > 0)\
+	d[--j] = s[i++];		\
+			} else {	\
+while (i < valid)			\
+	d[--j] = s[i++];		\
+while (j > 0)\
+	d[--j] = 0;			\
+			}		\
+		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
+	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_LE		\
+		&& enc_dst == AUDIO_ENCODING_ULINEAR_BE)		\
+		   || (enc_src == AUDIO_ENCODING_ULINEAR_LE		\
+		   && enc_dst == AUDIO_ENCODING_SLINEAR_BE)) {	\
+		/*			\
+		 * slinearNle -> ulinearNbe\
+		 * ulinearNle -> slinearNbe\
+		 */			\
+		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
 			i = valid;	\
 			j = target;	\
 			if (j < i) {	\
-while (j > 0) {\
-	d[--j] = s[valid - i];		\
-	i--;\
+j = 0;	\
+while (j < target) {			\
+	d[j++] = s[i--];		\
 }	\
 			} else {	\
-while (j > 0) {\
-	d[--j] = s[valid - i];		\
-	i--;\
-}	\
-while (j > 0)\
-	d[--j] = 0;			\
+j = 0;	\
+while (i > 0)\
+	d[j++] = s[--i];		\
+while (j < target)			\
+	d[j++] = 0;			\
 			}		\
+			d[0] ^= 0x80;	\
 		} FILTER_LOOP_EPILOGUE(this->src, dst);			\
 	} else if ((enc_src == AUDIO_ENCODING_SLINEAR_BE		\
 		&& enc_dst == AUDIO_ENCODING_ULINEAR_BE)		\
@@ -627,21 +668,16 @@ DEFINE_FILTER(swap_bytes_change_sign16)
 		 * ulinearNbe -> slinearNbe\
 		 */			\
 		FILTER_LOOP_PROLOGUE(this->src, hw, dst, target, m) {	\
-			i = 

CVS commit: src/sys/dev

2017-10-01 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Oct  1 21:49:20 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Ensure proper use of sc_opens (play back) and sc_recopens (recording).
Fix logic for /dev/sound so audiosetinfo is only called once.

These changes are to ensure that init_output/input is only called once for
the respective function play back or recording.  For multiple recording or
plack back streams init_input/output is only called once fot the first
play/rec stream.

This addresses PR kern/52580, PR kern/52581 and PR kern/52582 analyzed and
reported by isaki@.


To generate a diff of this commit:
cvs rdiff -u -r1.409 -r1.410 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.409 src/sys/dev/audio.c:1.410
--- src/sys/dev/audio.c:1.409	Sat Sep 30 05:37:55 2017
+++ src/sys/dev/audio.c	Sun Oct  1 21:49:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.409 2017/09/30 05:37:55 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.410 2017/10/01 21:49:20 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.409 2017/09/30 05:37:55 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.410 2017/10/01 21:49:20 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2027,7 +2027,7 @@ audio_initbufs(struct audio_softc *sc, s
 		((vc->sc_open & AUOPEN_READ) || vc == sc->sc_hwvc)) {
 		audio_init_ringbuffer(sc, >sc_mrr,
 		AUMODE_RECORD);
-		if (sc->sc_opens == 0 && (vc->sc_mode & AUMODE_RECORD)) {
+		if (sc->sc_recopens == 0 && (vc->sc_open & AUOPEN_READ)) {
 			if (hw->init_input) {
 error = hw->init_input(sc->hw_hdl,
 vc->sc_mrr.s.start,
@@ -2043,7 +2043,7 @@ audio_initbufs(struct audio_softc *sc, s
 		audio_init_ringbuffer(sc, >sc_mpr,
 		AUMODE_PLAY);
 		vc->sc_sil_count = 0;
-		if (sc->sc_opens == 0 && (vc->sc_mode & AUMODE_PLAY)) {
+		if (sc->sc_opens == 0 && (vc->sc_open & AUOPEN_WRITE)) {
 			if (hw->init_output) {
 error = hw->init_output(sc->hw_hdl,
 vc->sc_mpr.s.start,
@@ -2157,7 +2157,7 @@ audio_open(dev_t dev, struct audio_softc
 	if (error)
 		goto bad;
 
-	if (sc->sc_opens == 0) {
+	if (sc->sc_opens + sc->sc_recopens == 0) {
 		sc->sc_credentials = kauth_cred_get();
 		kauth_cred_hold(sc->sc_credentials);
 		if (hw->open != NULL) {
@@ -2216,13 +2216,13 @@ audio_open(dev_t dev, struct audio_softc
 	 * The /dev/audio is always (re)set to 8-bit MU-Law mono
 	 * For the other devices, you get what they were last set to.
 	 */
-	error = audio_set_defaults(sc, mode, vc);
-	if (!error && ISDEVSOUND(dev) && sc->sc_aivalid == true) {
+	if (ISDEVSOUND(dev) && sc->sc_aivalid == true) {
 		sc->sc_ai.mode = mode;
 		sc->sc_ai.play.port = ~0;
 		sc->sc_ai.record.port = ~0;
 		error = audiosetinfo(sc, >sc_ai, true, vc);
-	}
+	} else
+		error = audio_set_defaults(sc, mode, vc);
 	if (error)
 		goto bad;
 
@@ -2250,7 +2250,8 @@ audio_open(dev_t dev, struct audio_softc
 	grow_mixer_states(sc, 2);
 	if (flags & FREAD)
 		sc->sc_recopens++;
-	sc->sc_opens++;
+	if (flags & FWRITE)
+		sc->sc_opens++;
 	chan->dev = dev;
 	chan->chan = n;
 	chan->deschan = n;
@@ -2265,7 +2266,7 @@ audio_open(dev_t dev, struct audio_softc
 bad:
 	audio_destroy_pfilters(vc);
 	audio_destroy_rfilters(vc);
-	if (hw->close != NULL && sc->sc_opens == 0)
+	if (hw->close != NULL && sc->sc_opens == 0 && sc->sc_recopens == 0)
 		hw->close(sc->hw_hdl);
 	mutex_exit(sc->sc_lock);
 	audio_free_ring(sc, >sc_mpr);
@@ -2285,7 +2286,7 @@ audio_init_record(struct audio_softc *sc
 
 	KASSERT(mutex_owned(sc->sc_lock));
 	
-	if (sc->sc_opens != 0)
+	if (sc->sc_recopens != 0)
 		return;
 
 	mutex_enter(sc->sc_intr_lock);
@@ -2416,7 +2417,7 @@ audio_close(struct audio_softc *sc, int 
 
 	KASSERT(mutex_owned(sc->sc_lock));
 	
-	if (sc->sc_opens == 0)
+	if (sc->sc_opens == 0 && sc->sc_recopens == 0)
 		return ENXIO;
 
 	vc = chan->vc;
@@ -2450,7 +2451,7 @@ audio_close(struct audio_softc *sc, int 
 			audio_drain(sc, chan->vc);
 		vc->sc_pbus = false;
 	}
-	if (sc->sc_opens == 1) {
+	if ((flags & FWRITE) && (sc->sc_opens == 1)) {
 		if (vc->sc_mpr.mmapped == false)
 			audio_drain(sc, sc->sc_hwvc);
 		if (hw->drain)
@@ -2461,11 +2462,11 @@ audio_close(struct audio_softc *sc, int 
 	if ((flags & FREAD) && (sc->sc_recopens == 1))
 		sc->sc_rec_started = false;
 
-	if (sc->sc_opens == 1 && hw->close != NULL)
+	if (sc->sc_opens + sc->sc_recopens

CVS commit: src/sys/dev

2017-09-25 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Tue Sep 26 04:34:59 UTC 2017

Modified Files:
src/sys/dev: audio.c

Log Message:
Call audio_mix for a third time - thus ensuring there is a block of data
in the mix ring before the audio interrupt occurs.

This addresses the instability seen in the audio atf tests.


To generate a diff of this commit:
cvs rdiff -u -r1.407 -r1.408 src/sys/dev/audio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.407 src/sys/dev/audio.c:1.408
--- src/sys/dev/audio.c:1.407	Sun Sep 24 23:40:41 2017
+++ src/sys/dev/audio.c	Tue Sep 26 04:34:59 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.407 2017/09/24 23:40:41 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.408 2017/09/26 04:34:59 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.407 2017/09/24 23:40:41 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.408 2017/09/26 04:34:59 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -3466,6 +3466,7 @@ audiostartp(struct audio_softc *sc, stru
 	if (sc->sc_trigger_started == false) {
 		audio_mix(sc);
 		audio_mix(sc);
+		audio_mix(sc);
 		mutex_enter(sc->sc_intr_lock);
 		error = mix_write(sc);
 		if (error)



CVS commit: src/sys/dev

2017-09-24 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Sep 24 23:40:41 UTC 2017

Modified Files:
src/sys/dev: audio.c audiovar.h

Log Message:
Move play/rec mix ring buffers into a virtual channel sc_mixring.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.406 -r1.407 src/sys/dev/audio.c
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/audiovar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/audio.c
diff -u src/sys/dev/audio.c:1.406 src/sys/dev/audio.c:1.407
--- src/sys/dev/audio.c:1.406	Sat Sep  2 15:26:43 2017
+++ src/sys/dev/audio.c	Sun Sep 24 23:40:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.406 2017/09/02 15:26:43 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.407 2017/09/24 23:40:41 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.406 2017/09/02 15:26:43 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.407 2017/09/24 23:40:41 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -930,8 +930,8 @@ audiodetach(device_t self, int flags)
 	}
 	audio_free_ring(sc, >sc_hwvc->sc_mpr);
 	audio_free_ring(sc, >sc_hwvc->sc_mrr);
-	audio_free_ring(sc, >sc_pr);
-	audio_free_ring(sc, >sc_rr);
+	audio_free_ring(sc, >sc_mixring.sc_mpr);
+	audio_free_ring(sc, >sc_mixring.sc_mrr);
 	SIMPLEQ_FOREACH(chan, >sc_audiochan, entries) {
 		audio_destroy_pfilters(chan->vc);
 		audio_destroy_rfilters(chan->vc);
@@ -1114,13 +1114,13 @@ audio_allocbufs(struct audio_softc *sc)
 
 	vc = sc->sc_hwvc;
 
-	sc->sc_pr.s.start = NULL;
+	sc->sc_mixring.sc_mpr.s.start = NULL;
 	vc->sc_mpr.s.start = NULL;
-	sc->sc_rr.s.start = NULL;
+	sc->sc_mixring.sc_mrr.s.start = NULL;
 	vc->sc_mrr.s.start = NULL;
 
 	if (audio_can_playback(sc)) {
-		error = audio_alloc_ring(sc, >sc_pr,
+		error = audio_alloc_ring(sc, >sc_mixring.sc_mpr,
 		AUMODE_PLAY, AU_RING_SIZE);
 		if (error)
 			goto bad_play1;
@@ -1131,7 +1131,7 @@ audio_allocbufs(struct audio_softc *sc)
 			goto bad_play2;
 	}
 	if (audio_can_capture(sc)) {
-		error = audio_alloc_ring(sc, >sc_rr,
+		error = audio_alloc_ring(sc, >sc_mixring.sc_mrr,
 		AUMODE_RECORD, AU_RING_SIZE);
 		if (error)
 			goto bad_rec1;
@@ -1144,14 +1144,14 @@ audio_allocbufs(struct audio_softc *sc)
 	return 0;
 
 bad_rec2:
-	if (sc->sc_rr.s.start != NULL)
-		audio_free_ring(sc, >sc_rr);
+	if (sc->sc_mixring.sc_mrr.s.start != NULL)
+		audio_free_ring(sc, >sc_mixring.sc_mrr);
 bad_rec1:
 	if (vc->sc_mpr.s.start != NULL)
 		audio_free_ring(sc, >sc_mpr);
 bad_play2:
-	if (sc->sc_pr.s.start != NULL)
-		audio_free_ring(sc, >sc_pr);
+	if (sc->sc_mixring.sc_mpr.s.start != NULL)
+		audio_free_ring(sc, >sc_mixring.sc_mpr);
 bad_play1:
 	return error;
 }
@@ -2166,9 +2166,11 @@ audio_open(dev_t dev, struct audio_softc
 		}
 		audio_initbufs(sc, NULL);
 		if (audio_can_playback(sc))
-			audio_init_ringbuffer(sc, >sc_pr, AUMODE_PLAY);
+			audio_init_ringbuffer(sc, >sc_mixring.sc_mpr,
+			AUMODE_PLAY);
 		if (audio_can_capture(sc))
-			audio_init_ringbuffer(sc, >sc_rr, AUMODE_RECORD);
+			audio_init_ringbuffer(sc, >sc_mixring.sc_mrr,
+			AUMODE_RECORD);
 		sc->schedule_wih = false;
 		sc->schedule_rih = false;
 		sc->sc_last_drops = 0;
@@ -2202,8 +2204,8 @@ audio_open(dev_t dev, struct audio_softc
 		mode |= AUMODE_PLAY | AUMODE_PLAY_ALL;
 	}
 
-	vc->sc_mpr.blksize = sc->sc_pr.blksize;
-	vc->sc_mrr.blksize = sc->sc_rr.blksize;
+	vc->sc_mpr.blksize = sc->sc_mixring.sc_mpr.blksize;
+	vc->sc_mrr.blksize = sc->sc_mixring.sc_mrr.blksize;
 
 	/*
 	 * Multiplex device: /dev/audio (MU-Law) and /dev/sound (linear)
@@ -2328,7 +2330,7 @@ audio_drain(struct audio_softc *sc, stru
 	used = audio_stream_get_used(>s);
 	if (vc == sc->sc_hwvc) {
 		hw = true;
-		used += audio_stream_get_used(>sc_pr.s);
+		used += audio_stream_get_used(>sc_mixring.sc_mpr.s);
 	}
 	for (i = 0; i < vc->sc_npfilters; i++)
 		used += audio_stream_get_used(>sc_pstreams[i]);
@@ -2350,15 +2352,18 @@ audio_drain(struct audio_softc *sc, stru
 		if (error)
 			return error;
 	} else if (hw == true) {
-		used = cb->blksize - (sc->sc_pr.s.inp - sc->sc_pr.s.start)
-		% cb->blksize;
+		used = cb->blksize - (sc->sc_mixring.sc_mpr.s.inp -
+		sc->sc_mixring.sc_mpr.s.start) % cb->blksize;
 		while (used > 0) {
-			cc = sc->sc_pr.s.end - sc->sc_pr.s.inp;
+			cc = sc->sc_mixring.sc_mpr.s.end -
+			sc->sc_mixring.sc_mpr.s.inp;
 			if (cc > used)
 cc = used;
-			audio_fill_silence(>s.param, sc->sc_pr.s.inp, cc);
-			sc->sc_pr.s.inp = audio_stream_add_inp(>sc_pr.s,
-			sc->sc_pr.s.inp, cc);
+			audio_fill_silence(>s.param,
+			sc->sc_mixring.sc_mpr.s.

CVS commit: src/sys/dev/bluetooth

2017-09-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Sep  3 23:11:19 UTC 2017

Modified Files:
src/sys/dev/bluetooth: bth5.c bth5.h

Log Message:
Remove references to BlueCore.
Enable XON/XOFF flowcontrol in SLIP layer depending on config response.
Send an acknowlegment packet on timeout/retry.
Compute tx{ack,seq} and rx{ack,seq} according to the specification.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/bluetooth/bth5.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/bluetooth/bth5.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/bluetooth/bth5.c
diff -u src/sys/dev/bluetooth/bth5.c:1.4 src/sys/dev/bluetooth/bth5.c:1.5
--- src/sys/dev/bluetooth/bth5.c:1.4	Mon Aug 14 12:51:11 2017
+++ src/sys/dev/bluetooth/bth5.c	Sun Sep  3 23:11:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $	*/
+/*	$NetBSD: bth5.c,v 1.5 2017/09/03 23:11:19 nat Exp $	*/
 /*
  * Copyright (c) 2017 Nathanial Sloss <nathanialsl...@yahoo.com.au>
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.5 2017/09/03 23:11:19 nat Exp $");
 
 #include 
 #include 
@@ -110,14 +110,16 @@ struct bth5_softc {
 	MBUFQ_HEAD() sc_seqq;			/* Sequencing Layer queue */
 	MBUFQ_HEAD() sc_seq_retryq;		/* retry queue */
 	uint32_t sc_seq_txseq;
-	uint32_t sc_seq_txack;
 	uint32_t sc_seq_expected_rxseq;
+	uint32_t sc_seq_total_rxpkts;
+	uint32_t sc_seq_winack;
 	uint32_t sc_seq_winspace;
 	uint32_t sc_seq_retries;
 	callout_t sc_seq_timer;
 	uint32_t sc_seq_timeout;
 	uint32_t sc_seq_winsize;
 	uint32_t sc_seq_retry_limit;
+	bool	 sc_oof_flow_control;
 
 	/* variables of Datagram Queue Layer */
 	MBUFQ_HEAD() sc_dgq;			/* Datagram Queue Layer queue */
@@ -500,10 +502,13 @@ bth5_slip_transmit(struct tty *tp)
 	struct mbuf *m;
 	int count, rlen;
 	uint8_t *rptr;
+	int s;
 
 	m = sc->sc_txp;
 	if (m == NULL) {
+		s = spltty();
 		sc->sc_flags &= ~BTH5_XMIT;
+		splx(s);
 		bth5_mux_transmit(sc);
 		return 0;
 	}
@@ -526,12 +531,18 @@ bth5_slip_transmit(struct tty *tp)
 		count++;
 
 		if (sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_PKTEND ||
-		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XON ||
-		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XOFF ||
 		sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_ESCAPE) {
 			rlen++;
 			rptr++;
 		}
+		if (sc->sc_oof_flow_control == true) {
+			if (sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XON ||
+			sc->sc_slip_txrsv == BTH5_SLIP_ESCAPE_XOFF) {
+rlen++;
+rptr++;
+			}
+		}
+
 		sc->sc_slip_txrsv = 0;
 	}
 
@@ -571,7 +582,8 @@ bth5_slip_transmit(struct tty *tp)
 			}
 			DPRINTFN(4, ("0x%02x ", BTH5_SLIP_ESCAPE_PKTEND));
 			rptr++;
-		} else if (*rptr == BTH5_SLIP_XON) {
+		} else if (sc->sc_oof_flow_control == true && *rptr ==
+			 BTH5_SLIP_XON) {
 			if (putc(BTH5_SLIP_ESCAPE, >t_outq) < 0)
 break;
 			count++;
@@ -583,7 +595,8 @@ bth5_slip_transmit(struct tty *tp)
 			}
 			DPRINTFN(4, ("0x%02x ", BTH5_SLIP_ESCAPE_XON));
 			rptr++;
-		} else if (*rptr == BTH5_SLIP_XOFF) {
+		} else if (sc->sc_oof_flow_control == true && *rptr ==
+			 BTH5_SLIP_XOFF) {
 			if (putc(BTH5_SLIP_ESCAPE, >t_outq) < 0)
 break;
 			count++;
@@ -728,10 +741,12 @@ bth5_slip_receive(int c, struct tty *tp)
 			if (c == BTH5_SLIP_ESCAPE_PKTEND)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_PKTEND;
-			else if (c == BTH5_SLIP_ESCAPE_XON)
+			else if (sc->sc_oof_flow_control == true &&
+		c == BTH5_SLIP_ESCAPE_XON)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_XON;
-			else if (c == BTH5_SLIP_ESCAPE_XOFF)
+			else if (sc->sc_oof_flow_control == true &&
+		c == BTH5_SLIP_ESCAPE_XOFF)
 mtod(m, uint8_t *)[m->m_len++] =
 BTH5_SLIP_XOFF;
 			else if (c == BTH5_SLIP_ESCAPE_ESCAPE)
@@ -921,6 +936,7 @@ bth5_mux_transmit(struct bth5_softc *sc)
 {
 	struct mbuf *m;
 	bth5_hdr_t *hdrp;
+	int s;
 
 	DPRINTFN(2, ("%s: mux transmit: sc_flags=0x%x, choke=%d",
 	device_xname(sc->sc_dev), sc->sc_flags, sc->sc_mux_choke));
@@ -963,8 +979,12 @@ bth5_mux_transmit(struct bth5_softc *sc)
 		hdrp->flags |= BTH5_FLAGS_PROTOCOL_REL;		/* Reliable */
 		goto transmit;
 	}
-	sc->sc_flags &= ~BTH5_XMIT;
-	bth5_start(sc);
+
+	s = spltty();
+	if ((sc->sc_flags & BTH5_XMIT) == 0)
+		bth5_start(sc);
+	splx(s);
+
 	if (sc->sc_mux_send_ack == true) {
 		m = bth5_create_ackpkt();
 		if (m != NULL)
@@ -975,6 +995,7 @@ bth5_mux_transmit(struct bth5_softc *sc)
 
 	/* Nothing to send */
 	DPRINTFN(2, ("\n"));
+
 	return;
 
 transmit:
@@ -1017,6 +1038,9 @@ bth5_mux_receive(struct bth5_softc *sc, 
 	if (BTH5_FLAGS_SEQ(hdrp->flags) == 0 &&
 	hdrp->iden

CVS commit: src/usr.sbin/btattach

2017-09-03 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Sep  3 22:54:12 UTC 2017

Modified Files:
src/usr.sbin/btattach: init_bcm43xx.c

Log Message:
Fix copyright error.

Ok plunky@.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/btattach/init_bcm43xx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/init_bcm43xx.c
diff -u src/usr.sbin/btattach/init_bcm43xx.c:1.4 src/usr.sbin/btattach/init_bcm43xx.c:1.5
--- src/usr.sbin/btattach/init_bcm43xx.c:1.4	Mon Aug 14 05:28:23 2017
+++ src/usr.sbin/btattach/init_bcm43xx.c	Sun Sep  3 22:54:12 2017
@@ -1,7 +1,7 @@
-/*	$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $	*/
+/*	$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $	*/
 
 /*-
- * Copyright (c) 2017 Iain Hibbert
+ * Copyright (c) 2017 Nathanial Sloss <nathanialsl...@yahoo.com.au>
  * All rights reserved.
  *
  * Copyright (c) 2008 Iain Hibbert
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $");
+__RCSID("$NetBSD: init_bcm43xx.c,v 1.5 2017/09/03 22:54:12 nat Exp $");
 
 #include 
 



CVS commit: src/usr.sbin/bta2dpd/bta2dpd

2017-08-27 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Sun Aug 27 10:39:18 UTC 2017

Modified Files:
src/usr.sbin/bta2dpd/bta2dpd: bta2dpd.c

Log Message:
Connection state machine improvement upon transition from AVDTP_OPEN to
AVDTP_START/SUSPEND.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
diff -u src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.3 src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.4
--- src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c:1.3	Sat May 27 10:04:57 2017
+++ src/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c	Sun Aug 27 10:39:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: bta2dpd.c,v 1.3 2017/05/27 10:04:57 nat Exp $ */
+/* $NetBSD: bta2dpd.c,v 1.4 2017/08/27 10:39:18 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -674,7 +674,8 @@ do_ctlreq(int fd, short ev, void *arg)
 		case AVDTP_SUSPEND:
 		case AVDTP_START:
 			avdtpSendAccept(fd, fd, trans, signal);
-			state = 6;
+			if (state < 6)
+state = 6;
 			break;
 		default:
 			avdtpSendReject(fd, fd, trans, signal);
@@ -717,7 +718,8 @@ do_ctlreq(int fd, short ev, void *arg)
 			break;
 		case AVDTP_SUSPEND:
 		case AVDTP_START:
-			state = 6;
+			if (state < 6)
+state = 6;
 			break;
 		default:
 			avdtpSendReject(fd, fd, trans, signal);
@@ -730,7 +732,7 @@ do_ctlreq(int fd, short ev, void *arg)
 	if (state < 5 || state > 7)
 		return;
 
-	if (asSpeaker) {
+	if (asSpeaker && state == 6) {
 		len = sizeof(addr);
 		if ((sc = accept(orighc,(struct sockaddr*), )) < 0)
 			err(EXIT_FAILURE, "stream accept");



CVS commit: src/sys/dev/pckbport

2017-08-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Aug 16 21:18:58 UTC 2017

Modified Files:
src/sys/dev/pckbport: alps.c

Log Message:
Remove extra newline.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/pckbport/alps.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pckbport/alps.c
diff -u src/sys/dev/pckbport/alps.c:1.3 src/sys/dev/pckbport/alps.c:1.4
--- src/sys/dev/pckbport/alps.c:1.3	Wed Aug 16 21:09:48 2017
+++ src/sys/dev/pckbport/alps.c	Wed Aug 16 21:18:58 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: alps.c,v 1.3 2017/08/16 21:09:48 nat Exp $ */
+/* $NetBSD: alps.c,v 1.4 2017/08/16 21:18:58 nat Exp $ */
 
 /*-
  * Copyright (c) 2017 Ryo ONODERA 
@@ -30,7 +30,7 @@
 #include "opt_pms.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: alps.c,v 1.3 2017/08/16 21:09:48 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: alps.c,v 1.4 2017/08/16 21:18:58 nat Exp $");
 
 #include 
 #include 
@@ -687,7 +687,6 @@ pms_alps_probe_init(void *opaque)
 	int res;
 	u_char cmd[1], resp[3];
 
-
 	sc->last_x1 = 0;
 	sc->last_y1 = 0;
 	sc->last_x2 = 0;



CVS commit: src/sys/dev/pckbport

2017-08-16 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Wed Aug 16 21:09:48 UTC 2017

Modified Files:
src/sys/dev/pckbport: alps.c

Log Message:
If ALPS probe fails, send a PMS_RESET.
Restores functionality on a wrong version ALPS touchpad.

Addresses PR kern/52489.

This patch was prepared by/committed on behalf of maya@.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pckbport/alps.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pckbport/alps.c
diff -u src/sys/dev/pckbport/alps.c:1.2 src/sys/dev/pckbport/alps.c:1.3
--- src/sys/dev/pckbport/alps.c:1.2	Tue Aug 15 22:23:09 2017
+++ src/sys/dev/pckbport/alps.c	Wed Aug 16 21:09:48 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: alps.c,v 1.2 2017/08/15 22:23:09 ryoon Exp $ */
+/* $NetBSD: alps.c,v 1.3 2017/08/16 21:09:48 nat Exp $ */
 
 /*-
  * Copyright (c) 2017 Ryo ONODERA 
@@ -30,7 +30,7 @@
 #include "opt_pms.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: alps.c,v 1.2 2017/08/15 22:23:09 ryoon Exp $");
+__KERNEL_RCSID(0, "$NetBSD: alps.c,v 1.3 2017/08/16 21:09:48 nat Exp $");
 
 #include 
 #include 
@@ -685,6 +685,8 @@ pms_alps_probe_init(void *opaque)
 	uint8_t e7sig[3];
 	uint8_t ecsig[3];
 	int res;
+	u_char cmd[1], resp[3];
+
 
 	sc->last_x1 = 0;
 	sc->last_y1 = 0;
@@ -726,8 +728,8 @@ pms_alps_probe_init(void *opaque)
 		aprint_normal_dev(psc->sc_dev,
 			"ALPS PS/2 V2 pointing device\n");
 	} else {
-		aprint_error_dev(psc->sc_dev, "No supported device found.\n");
-		return EINVAL;
+		res = EINVAL;
+		goto err;
 	}
 
 	/* From sysctl */
@@ -740,14 +742,17 @@ pms_alps_probe_init(void *opaque)
 		pckbport_set_inputhandler(psc->sc_kbctag, psc->sc_kbcslot,
 			pms_alps_input_v2, psc, device_xname(psc->sc_dev));
 	} else {
-		aprint_error_dev(psc->sc_dev, "No supported device found.\n");
-		return EINVAL;
+		res = EINVAL;
+		goto err;
 	}
 	/* Palm detection is enabled. */
 
 	return 0;
 
 err:
+	cmd[0] = PMS_RESET;
+	(void)pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd,
+	1, 2, resp, 1);
 	aprint_error_dev(psc->sc_dev, "Failed to initialize an ALPS device.\n");
 	return res;
 }



CVS commit: src/sys/dev/bluetooth

2017-08-14 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Aug 14 12:51:11 UTC 2017

Modified Files:
src/sys/dev/bluetooth: bth5.c

Log Message:
Apply the sequence number mask to txack.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/bluetooth/bth5.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/bluetooth/bth5.c
diff -u src/sys/dev/bluetooth/bth5.c:1.3 src/sys/dev/bluetooth/bth5.c:1.4
--- src/sys/dev/bluetooth/bth5.c:1.3	Mon Aug 14 05:33:30 2017
+++ src/sys/dev/bluetooth/bth5.c	Mon Aug 14 12:51:11 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bth5.c,v 1.3 2017/08/14 05:33:30 nat Exp $	*/
+/*	$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $	*/
 /*
  * Copyright (c) 2017 Nathanial Sloss <nathanialsl...@yahoo.com.au>
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.3 2017/08/14 05:33:30 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.4 2017/08/14 12:51:11 nat Exp $");
 
 #include 
 #include 
@@ -1149,7 +1149,7 @@ bth5_sequencing_receive(struct bth5_soft
 	if (sc->sc_seq_expected_rxseq / sc->sc_seq_winsize  ==
 	 sc->sc_seq_winsize) {
 		bth5_send_ack_command(sc);
-		sc->sc_seq_txack = sc->sc_seq_expected_rxseq;
+		sc->sc_seq_txack = sc->sc_seq_expected_rxseq & BTH5_FLAGS_SEQ_MASK;
 	} else
 		sc->sc_seq_txack = rxseq;
 



CVS commit: src/sys/dev/bluetooth

2017-08-13 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Aug 14 05:33:30 UTC 2017

Modified Files:
src/sys/dev/bluetooth: bth5.c

Log Message:
Conform to the spec. with regards to acknowlegment packets.  This prevents
the host controller from freezing.

Inmprove communication from inactive to active state.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/bluetooth/bth5.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/bluetooth/bth5.c
diff -u src/sys/dev/bluetooth/bth5.c:1.2 src/sys/dev/bluetooth/bth5.c:1.3
--- src/sys/dev/bluetooth/bth5.c:1.2	Fri Aug 11 00:58:37 2017
+++ src/sys/dev/bluetooth/bth5.c	Mon Aug 14 05:33:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bth5.c,v 1.2 2017/08/11 00:58:37 nat Exp $	*/
+/*	$NetBSD: bth5.c,v 1.3 2017/08/14 05:33:30 nat Exp $	*/
 /*
  * Copyright (c) 2017 Nathanial Sloss <nathanialsl...@yahoo.com.au>
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.2 2017/08/11 00:58:37 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.3 2017/08/14 05:33:30 nat Exp $");
 
 #include 
 #include 
@@ -1076,13 +1076,14 @@ static void
 bth5_sequencing_receive(struct bth5_softc *sc, struct mbuf *m)
 {
 	bth5_hdr_t hdr;
-	uint32_t rxseq;
+	uint32_t exp_rxseq, rxseq;
 
+	exp_rxseq = sc->sc_seq_expected_rxseq & BTH5_FLAGS_SEQ_MASK;
 	m_copydata(m, 0, sizeof(bth5_hdr_t), );
 	rxseq = BTH5_FLAGS_SEQ(hdr.flags);
 
 	DPRINTFN(1, ("%s: seq receive: rxseq=%d, expected %d\n",
-	device_xname(sc->sc_dev), rxseq, sc->sc_seq_expected_rxseq));
+	device_xname(sc->sc_dev), rxseq, exp_rxseq));
 #ifdef BTH5_DEBUG
 	if (bth5_debug == 2)
 		bth5_packet_print(m);
@@ -1094,9 +1095,10 @@ bth5_sequencing_receive(struct bth5_soft
 	 */
 	m_adj(m, sizeof(bth5_hdr_t) - sizeof(uint8_t));
 
-	if (rxseq != sc->sc_seq_expected_rxseq) {
+	if (rxseq != exp_rxseq) {
 		m_freem(m);
 
+		bth5_send_ack_command(sc);
 		/* send ack packet, if needly */
 		bth5_mux_transmit(sc);
 
@@ -1144,10 +1146,15 @@ bth5_sequencing_receive(struct bth5_soft
 		break;
 	}
 
+	if (sc->sc_seq_expected_rxseq / sc->sc_seq_winsize  ==
+	 sc->sc_seq_winsize) {
+		bth5_send_ack_command(sc);
+		sc->sc_seq_txack = sc->sc_seq_expected_rxseq;
+	} else
+		sc->sc_seq_txack = rxseq;
+
 	sc->sc_seq_expected_rxseq =
-	(sc->sc_seq_expected_rxseq + 1) & BTH5_FLAGS_SEQ_MASK;
-	sc->sc_seq_txack = sc->sc_seq_expected_rxseq;
-	bth5_send_ack_command(sc);
+	(sc->sc_seq_expected_rxseq + 1);
 }
 
 static bool
@@ -1539,7 +1546,7 @@ bth5_input_le(struct bth5_softc *sc, str
 		} else if (*rcvpkt == *(const uint16_t *)syncresp) {
 			DPRINTF(("%s: state change to curious\n",
 			device_xname(sc->sc_dev)));
-
+			rplypkt = conf;
 			callout_schedule(>sc_le_timer,
 			BTH5_LE_TCONF_TIMEOUT);
 			sc->sc_le_state = le_state_curious;
@@ -1551,6 +1558,8 @@ bth5_input_le(struct bth5_softc *sc, str
 	case le_state_curious:
 		if (*rcvpkt == *(const uint16_t *)sync)
 			rplypkt = syncresp;
+		else if (*rcvpkt == *(const uint16_t *)syncresp)
+			rplypkt = conf;
 		else if (*rcvpkt == *(const uint16_t *)conf)
 			rplypkt = confresp;
 		else if (*rcvpkt == *(const uint16_t *)confresp) {



CVS commit: src/usr.sbin/btattach

2017-08-13 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon Aug 14 05:28:23 UTC 2017

Modified Files:
src/usr.sbin/btattach: init_bcm43xx.c

Log Message:
Set controller clock based on baud rate.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/btattach/init_bcm43xx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btattach/init_bcm43xx.c
diff -u src/usr.sbin/btattach/init_bcm43xx.c:1.3 src/usr.sbin/btattach/init_bcm43xx.c:1.4
--- src/usr.sbin/btattach/init_bcm43xx.c:1.3	Thu Aug 10 20:43:12 2017
+++ src/usr.sbin/btattach/init_bcm43xx.c	Mon Aug 14 05:28:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_bcm43xx.c,v 1.3 2017/08/10 20:43:12 jmcneill Exp $	*/
+/*	$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $	*/
 
 /*-
  * Copyright (c) 2017 Iain Hibbert
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: init_bcm43xx.c,v 1.3 2017/08/10 20:43:12 jmcneill Exp $");
+__RCSID("$NetBSD: init_bcm43xx.c,v 1.4 2017/08/14 05:28:23 nat Exp $");
 
 #include 
 
@@ -56,11 +56,17 @@ __RCSID("$NetBSD: init_bcm43xx.c,v 1.3 2
 #define HCI_CMD_BCM43XX_SET_BDADDR		\
 	HCI_OPCODE(HCI_OGF_VENDOR, 0x006)
 
+#define HCI_CMD_BCM43XX_SET_CLOCK		\
+	HCI_OPCODE(HCI_OGF_VENDOR, 0x045)
+
 #define HCI_CMD_43XXFWDN 			\
 	HCI_OPCODE(HCI_OGF_VENDOR, 0x02e)
 
 #define HCI_CMD_GET_LOCAL_NAME			0x0c14
 
+#define BCM43XX_CLK_48	1
+#define BCM43XX_CLK_24	2
+
 static int
 bcm43xx_get_local_name(int fd, char *name, size_t namelen)
 {
@@ -85,7 +91,7 @@ bcm43xx_get_local_name(int fd, char *nam
 void
 init_bcm43xx(int fd, unsigned int speed)
 {
-	uint8_t rate[6];
+	uint8_t rate[6], clock;
 	uint8_t fw_buf[1024];
 	int fwfd, fw_len;
 	uint8_t resp[7];
@@ -134,6 +140,14 @@ init_bcm43xx(int fd, unsigned int speed)
 	uart_recv_cc(fd, HCI_CMD_RESET, , sizeof(resp));
 	/* assume it succeeded? */
 
+	if (speed >= 300) 
+		clock = BCM43XX_CLK_48;
+	else
+		clock = BCM43XX_CLK_24;
+
+	uart_send_cmd(fd, HCI_CMD_BCM43XX_SET_CLOCK, , sizeof(clock));
+	uart_recv_cc(fd, HCI_CMD_BCM43XX_SET_CLOCK, , sizeof(resp));
+
 	rate[2] = speed;
 	rate[3] = speed >> 8;
 	rate[4] = speed >> 16;



CVS commit: src/sys/dev/bluetooth

2017-08-10 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Aug 11 00:58:37 UTC 2017

Modified Files:
src/sys/dev/bluetooth: bth5.c

Log Message:
Ensure the XMIT flag is cleared before calling bth5_start.

This avoids a panic due to a diagnostic assertion.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/bluetooth/bth5.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/bluetooth/bth5.c
diff -u src/sys/dev/bluetooth/bth5.c:1.1 src/sys/dev/bluetooth/bth5.c:1.2
--- src/sys/dev/bluetooth/bth5.c:1.1	Thu Aug 10 13:22:19 2017
+++ src/sys/dev/bluetooth/bth5.c	Fri Aug 11 00:58:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bth5.c,v 1.1 2017/08/10 13:22:19 nat Exp $	*/
+/*	$NetBSD: bth5.c,v 1.2 2017/08/11 00:58:37 nat Exp $	*/
 /*
  * Copyright (c) 2017 Nathanial Sloss <nathanialsl...@yahoo.com.au>
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.1 2017/08/10 13:22:19 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bth5.c,v 1.2 2017/08/11 00:58:37 nat Exp $");
 
 #include 
 #include 
@@ -963,6 +963,7 @@ bth5_mux_transmit(struct bth5_softc *sc)
 		hdrp->flags |= BTH5_FLAGS_PROTOCOL_REL;		/* Reliable */
 		goto transmit;
 	}
+	sc->sc_flags &= ~BTH5_XMIT;
 	bth5_start(sc);
 	if (sc->sc_mux_send_ack == true) {
 		m = bth5_create_ackpkt();



CVS commit: src

2017-08-10 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Aug 10 15:31:49 UTC 2017

Modified Files:
src/distrib/sets/lists/base: mi
src/external: Makefile

Log Message:
Add bcm43xx bluetooth controller firmware to the lists and update relevant
makefiles.


To generate a diff of this commit:
cvs rdiff -u -r1.1159 -r1.1160 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.18 -r1.19 src/external/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/base/mi
diff -u src/distrib/sets/lists/base/mi:1.1159 src/distrib/sets/lists/base/mi:1.1160
--- src/distrib/sets/lists/base/mi:1.1159	Tue Aug  1 20:07:43 2017
+++ src/distrib/sets/lists/base/mi	Thu Aug 10 15:31:49 2017
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1159 2017/08/01 20:07:43 joerg Exp $
+# $NetBSD: mi,v 1.1160 2017/08/10 15:31:49 nat Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -1289,6 +1289,9 @@
 ./usr/libdata/debug/usr/mdec			base-sys-usr
 ./usr/libdata/debug/usr/sbin			base-sys-usr
 ./usr/libdata/firmwarebase-firmware-usr
+./usr/libdata/firmware/bcm43xx			base-firmware-usr
+./usr/libdata/firmware/bcm43xx/BCM43430A1.hcd	base-firmware-usr
+./usr/libdata/firmware/bcm43xx/LICENCE.broadcom_bcm43xx		base-firmware-usr
 ./usr/libdata/firmware/radeon			base-obsolete	obsolete
 ./usr/libdata/firmware/radeon/ARUBA_me.bin	base-obsolete	obsolete
 ./usr/libdata/firmware/radeon/ARUBA_pfp.bin	base-obsolete	obsolete

Index: src/external/Makefile
diff -u src/external/Makefile:1.18 src/external/Makefile:1.19
--- src/external/Makefile:1.18	Thu Jun 14 04:14:36 2012
+++ src/external/Makefile	Thu Aug 10 15:31:49 2017
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.18 2012/06/14 04:14:36 riz Exp $
+#	$NetBSD: Makefile,v 1.19 2017/08/10 15:31:49 nat Exp $
 
-SUBDIR+= apache2 atheros bsd cddl gpl2 gpl3 historical intel-fw-eula
+SUBDIR+= apache2 atheros broadcom bsd cddl gpl2 gpl3 historical intel-fw-eula
 SUBDIR+= intel-fw-public ibm-public mit public-domain realtek
 
 .include 



CVS commit: src/external/broadcom

2017-08-10 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Aug 10 15:15:48 UTC 2017

Added Files:
src/external/broadcom: Makefile Makefile.inc
src/external/broadcom/bcm43xx: BCM43430A1.hcd LICENCE.broadcom_bcm43xx
Makefile

Log Message:
Add firmware and license for bcm43430 bluetooth uart interface.
This firmware is used by the Raspberry Pi 3 on-board bluetooth controller.

For additional licensing information, see:
https://github.com/raspberrypi/linux/issues/1325#issuecomment-195560582


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/external/broadcom/Makefile \
src/external/broadcom/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/external/broadcom/bcm43xx/BCM43430A1.hcd \
src/external/broadcom/bcm43xx/LICENCE.broadcom_bcm43xx \
src/external/broadcom/bcm43xx/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/external/broadcom/Makefile
diff -u /dev/null src/external/broadcom/Makefile:1.1
--- /dev/null	Thu Aug 10 15:15:48 2017
+++ src/external/broadcom/Makefile	Thu Aug 10 15:15:48 2017
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1 2017/08/10 15:15:48 nat Exp $
+
+SUBDIR+=	bcm43xx
+
+.include 
Index: src/external/broadcom/Makefile.inc
diff -u /dev/null src/external/broadcom/Makefile.inc:1.1
--- /dev/null	Thu Aug 10 15:15:48 2017
+++ src/external/broadcom/Makefile.inc	Thu Aug 10 15:15:48 2017
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile.inc,v 1.1 2017/08/10 15:15:48 nat Exp $
+
+FILESOWN=	${FIRMWAREOWN}
+FILESGRP=	${FIRMWAREGRP}
+FILESMODE=	${FIRMWAREMODE}
+
+includes:
+clean:
+cleandir:

Index: src/external/broadcom/bcm43xx/BCM43430A1.hcd
Binary files are different
Index: src/external/broadcom/bcm43xx/LICENCE.broadcom_bcm43xx
diff -u /dev/null src/external/broadcom/bcm43xx/LICENCE.broadcom_bcm43xx:1.1
--- /dev/null	Thu Aug 10 15:15:48 2017
+++ src/external/broadcom/bcm43xx/LICENCE.broadcom_bcm43xx	Thu Aug 10 15:15:48 2017
@@ -0,0 +1,65 @@
+SOFTWARE LICENSE AGREEMENT
+
+The accompanying software in binary code form ("Software"), is licensed to you,
+or, if you are accepting on behalf of an entity, the entity and its affiliates
+exercising rights hereunder ("Licensee") subject to the terms of this software
+license agreement ("Agreement"), unless Licensee and Broadcom Corporation
+("Broadcom") execute a separate written software license agreement governing
+use of the Software. ANY USE, REPRODUCTION, OR DISTRIBUTION OF THE SOFTWARE
+CONSTITUTES LICENSEES ACCEPTANCE OF THIS AGREEMENT.
+
+1.	License. Subject to the terms and conditions of this Agreement,
+Broadcom hereby grants to Licensee a limited, non-exclusive, non-transferable,
+royalty-free license: (i) to use and integrate the Software with any other
+software; and (ii) to reproduce and distribute the Software complete,
+unmodified, and as provided by Broadcom, solely for use with Broadcom
+proprietary integrated circuit product(s) sold by Broadcom with which the
+Software was designed to be used, or their successors.
+
+2.	Restrictions. Licensee shall distribute Software with a copy of this
+Agreement. Licensee shall not remove, efface or obscure any copyright or
+trademark notices from the Software. Reproductions of the Broadcom copyright
+notice shall be included with each copy of the Software, except where such
+Software is embedded in a manner not readily accessible to the end user.
+Licensee shall not: (i) use, license, sell or otherwise distribute the Software
+except as provided in this Agreement; (ii) attempt to modify in any way,
+reverse engineer, decompile or disassemble any portion of the Software; or
+(iii) use the Software or other material in violation of any applicable law or
+regulation, including but not limited to any regulatory agency. This Agreement
+shall automatically terminate upon Licensees failure to comply with any of the
+terms of this Agreement. In such event, Licensee will destroy all copies of the
+Software and its component parts.
+
+3.	Ownership. The Software is licensed and not sold.  Title to and
+ownership of the Software, including all intellectual property rights thereto,
+and any portion thereof remain with Broadcom or its licensors. Licensee hereby
+covenants that it will not assert any claim that the Software created by or for
+Broadcom infringe any intellectual property right owned or controlled by
+Licensee.
+
+4. 	Disclaimer. THE SOFTWARE IS OFFERED "AS IS," AND BROADCOM PROVIDES AND
+GRANTS AND LICENSEE RECEIVES NO SUPPORT AND NO WARRANTIES OF ANY KIND, EXPRESS
+OR IMPLIED, BY STATUTE, COMMUNICATION OR CONDUCT WITH LICENSEE, OR OTHERWISE.
+BROADCOM SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A SPECIFIC PURPOSE, OR NONINFRINGEMENT CONCERNING THE SOFTWARE OR
+ANY UPGRADES TO OR DOCUMENTATION FOR THE SOFTWARE. WITHOUT LIMITATION OF THE
+ABOVE, BROADCOM GRANTS NO WARRANTY THAT THE SOFTWARE IS ERROR-FREE OR WILL
+OPERATE WITHOUT INTERRUPTION, 

CVS commit: src/sys/arch/evbarm/conf

2017-08-10 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Aug 10 13:48:20 UTC 2017

Modified Files:
src/sys/arch/evbarm/conf: RPI

Log Message:
Add bluetooth serial uart devices.

RPI3 on-board bluetooth controller works with the bthfive pseudo-device.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/evbarm/conf/RPI

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/evbarm/conf/RPI
diff -u src/sys/arch/evbarm/conf/RPI:1.74 src/sys/arch/evbarm/conf/RPI:1.75
--- src/sys/arch/evbarm/conf/RPI:1.74	Sun Jul 30 23:48:32 2017
+++ src/sys/arch/evbarm/conf/RPI	Thu Aug 10 13:48:19 2017
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: RPI,v 1.74 2017/07/30 23:48:32 jmcneill Exp $
+#	$NetBSD: RPI,v 1.75 2017/08/10 13:48:19 nat Exp $
 #
 #	RPi -- Raspberry Pi
 #
@@ -219,3 +219,8 @@ pseudo-device	wsfont
 
 # local configuration
 cinclude "arch/evbarm/conf/RPI.local"
+
+# Bluetooth serial UART devices
+pseudo-device btuart
+pseudo-device bcsp
+pseudo-device bthfive



  1   2   3   4   >