Subject: cmpci audio driver and dma issues
To: None <tech-kern@netbsd.org>
From: Murray Armfield <murray@river-styx.org>
List: tech-kern
Date: 01/26/2004 20:41:23
Hi Folks,
	I've been tearing my hair out trying to fix a problem with the cmpci audio
driver on NetBSD-current and was wondering if someone could help me. The
problem with the existing driver is that every couple of minutes, the audio
will get a bit of static. I have traced this back to the dma transfers
between
the audio ring buffer and the device on the end.
	First some basic environment stuff. I'm running current kernels as of
today on MP i386. Userland is only a week behind. I have been noticing this
problem for a couple of years and I am finally doing something about it. For
more details, just ask.
	I have tried adding bus_dmamap_sync's around the transfers but this
doesn't clear up the problem. I added some logging which follows...

buffersize: 0x8000
blocksize: 0x1000
sample size: 4

(BTW, after watching the dma, I have corrected the round_blocksize
calculation
as the device only moves data around on slightly large boundaries, and then
ensured round_buffersize was also rounded appropriately)

The columns below..
	cpu - offset for bus_dmamap_sync, caculated on interrupt
	dma - current dma address read directly from end device
	bus - current count of samples in ring buffer left read from end device
	codec - current count of samples between interrupts read from end device

About halfway down, the codec figure drops, the dma is read from a different
address and this ripples through for subsequent addresses. This change
corresponds precisely with the static heard from playing audio. Compare
the cpu and dma figures after the change, off by 0x1000 !! bus and codec
figures indicate device is working at the correct rate after the change,
but dma address is off.

Can anyone help me please?

Thanks in advance,
	Murray

.....
(After many lines with exactly the same data and perfect operation...)
.....
cpu:0       dma:28aa000     bus:7ff         codec:3ff
cpu:1000    dma:28ab000     bus:3ff         codec:3ff
cpu:2000    dma:28a4000     bus:1fff        codec:3ff
cpu:3000    dma:28a5000     bus:1bff        codec:3ff
cpu:4000    dma:28a6000     bus:17ff        codec:3ff
cpu:5000    dma:28a7000     bus:13ff        codec:3ff
cpu:6000    dma:28a8000     bus:fff         codec:3ff
cpu:7000    dma:28a9000     bus:bff         codec:3ff
cpu:0       dma:28aa000     bus:7ff         codec:3ff
cpu:1000    dma:28ab000     bus:3ff         codec:3ff
cpu:2000    dma:28a4000     bus:1fff        codec:3ff
cpu:3000    dma:28a5000     bus:1bff        codec:3ff
cpu:4000    dma:28a6000     bus:17ff        codec:3ff
cpu:5000    dma:28a7000     bus:13ff        codec:3ff
cpu:6000    dma:28a8000     bus:fff         codec:3ff
cpu:7000    dma:28a9000     bus:bff         codec:3ff
cpu:0       dma:28aa000     bus:7ff         codec:3ff
cpu:1000    dma:28ab000     bus:3ff         codec:3ff
cpu:2000    dma:28a4000     bus:1fff        codec:3ff
cpu:3000    dma:28a5000     bus:1bff        codec:3ff
cpu:4000    dma:28a6000     bus:17ff        codec:3ff
cpu:5000    dma:28a8ac0     bus:d4f         codec:14f	<-- XXX : Static
cpu:6000    dma:28a9000     bus:bff         codec:3ff		from here on until
cpu:7000    dma:28aa000     bus:7ff         codec:3ff		another bump
cpu:0       dma:28ab000     bus:3ff         codec:3ff
cpu:1000    dma:28a4000     bus:1fff        codec:3ff
cpu:2000    dma:28a5000     bus:1bff        codec:3ff
cpu:3000    dma:28a6000     bus:17ff        codec:3ff
cpu:4000    dma:28a7000     bus:13ff        codec:3ff
cpu:5000    dma:28a8000     bus:fff         codec:3ff
cpu:6000    dma:28a9000     bus:bff         codec:3ff
cpu:7000    dma:28aa000     bus:7ff         codec:3ff
cpu:0       dma:28ab000     bus:3ff         codec:3ff
cpu:1000    dma:28a4000     bus:1fff        codec:3ff
cpu:2000    dma:28a5000     bus:1bff        codec:3ff
cpu:3000    dma:28a6000     bus:17ff        codec:3ff
cpu:4000    dma:28a7000     bus:13ff        codec:3ff