Home | History | Annotate | Download | only in obio
History log of /src/sys/arch/mac68k/obio/esp.c
RevisionDateAuthorComments
 1.64  15-Aug-2022  rin Rework avdma to fix PR port-mac68k/56131 as well as add synchronous
transfer support.

According to analysis by Michael Zucca, PSC (DMAC for Quadra/Centris AV)
seems to require that DMA buffer is
(1) aligned to 16-byte boundaries, and
(2) multiple of 16 bytes in size.
If the buffer does not satisfy these constraints, esp.c rev 1.63 and
prior carry out partial PIO to align or shave off it.

However, partial PIO does not always work correctly for combination of
NCR53C94 and PSC, which results in failures observed as port-mac68k/56131.

Also, PIO spoils synchronous transfer, which is timing critical.

Therefore, for buffers that do not satisfy the boundary conditions,
completely stop using PIO and use DMA with ``bounce'' buffers.

This fixes port-mac68k/56131 and enables sync transfer as a big bonus.

Note that bounce DMA does not hurt performance at all. For filesystem
and swap I/O, buffers always satisfy the constraints above, and bounce
DMA is necessary only
(a) when disk is attached, or
(b) for special utilities like fsck(8) or fdisk(8),
as far as I can tell.

Also:

- Stop providing ``DMA-friendly'' sc_imess and sc_omess; transfer for
MSGIN or MSGOUT does not almost certainly satisfy boundary condition
(2). Again, this does not affect performance at all.

- SCSI bus frequency is 20MHz (i.e., 5MB/s for sync transfer) for AV
models, according to ``Quadra 840AV Service Source''.
 1.63  15-Aug-2022  rin Remove stray newline. No binary changes.
 1.62  15-Aug-2022  rin For avdma, bus_dmamap_create(9) with nsegments = 1, as PSC supports
only one physically contiguous segment in a single DMA transaction.

Slightly improves performance.
 1.61  15-Aug-2022  rin Minor cosmetic changes. NFC.

- Use switch instead of if-else-if chain.
- Dedup codes a bit.
 1.60  22-Feb-2021  rin Elucidate why synchronous transfer is disabled for AV Macs.

Sync negotiation times out when drive advertises that capability:

----
sd1 at scsibus0 target 1 lun 0: <codesrc, SCSI2SD, 6.0> disk fixed
sd1: 16384 MB, 2088 cyl, 255 head, 63 sec, 512 bytes/sect x 33554432 sectors
sd1: sync (160.00ns offset 15), 8-bit (6.250MB/s) transfers
...
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x1, dleft 8, stat 0)], <state 5, nexus 0x9f7fc4, phase(l 1, c 1, p 1), resid 8, msg(q 0,o 80) DMA active>
sd1(esp0:0:1:0): sync negotiation disabled
sd1(esp0:0:1:0): esp0: timed out [ecb 0x9f7fc4 (flags 0x41, dleft 8, stat 0)], <state 5, nexus 0x9f7fc4, phase(l 1, c 1, p 1), resid 8, msg(q 20,o 80) DMA active> AGAIN
sd1: async, 8-bit transfers
----

This is observed for real SCSI drives as well as SCSI2SD (rev 6.0).

Note that this is not a fallout from DMA patch for AV Macs; timeout
takes place even if ``avdma'' code is forcibly disabled.

No binary changes.
 1.59  22-Feb-2021  rin - Add missing \n's to printf(9).
- Whitespace fixes.
 1.58  23-Jul-2019  rin branches: 1.58.10;
PR port-mac68k/24883

Support DMA xfer for SCSI adapter of AV Mac (660/840AV), written by
Michael Zucca.

This improves disk I/O performance by nearly one order of magnitude.
In addition, interrupt storm due to heavy disk PIO is resolved.

I'm deeply grateful to Michael Zucca for his analysis of DMA engine
and submission of PR. I also thank Izumi Tsutsui (useful comments on
port-mac68k@) and Martin Husemann (test on 660AV).
 1.57  23-Jul-2019  rin PR port-mac68k/24883

Style-only changes in preparation to import AV DMA code:

- G/C unused from esp_softc
- clean up headers:
- prefer <sys/bus.h> over <machine/bus.h>
- G/C unused
- sort
- staticify private functions and variables
- stop using inline qualifier for functions called via function pointers
- use C99 initializer
- provide bus_space_vaddr(9) and use it, instead of using member of
bus_handle_t directly
- use uint*_t:
- u_char --> uint8_t
- u_int*_t --> uint*_t
- use proper names from ncr53c9xreg.h instead of magic numbers
- and some KNF, and etc.

No functional changes intended.
 1.56  08-Jan-2019  jdolecek no need to include <machine/param.h> if <sys/param.h> already included
 1.55  18-Feb-2012  rmind branches: 1.55.38; 1.55.40;
Replace few simple_lock(9) cases.
 1.54  02-Aug-2011  uebayasi branches: 1.54.2; 1.54.6;
ncr53c9x was converted to use mutex(9), follow that. Fix DEBUG build too.
 1.53  02-Aug-2011  uebayasi Include sys/simplelock.h to use simple_lock(); fix build.
 1.52  23-Nov-2009  rmind Use lwp_getpcb() on m68k ports, clean from struct user usage.
 1.51  02-Jun-2008  hauke esp_quick_dma_go() gets called from the MI ncr53c9x_intr() handler,
which protects itself against multiple invocation with a
simple_lock. Follow the example of ncr53c9x_poll() for servicing an
interrupt that came while we run in splhigh(), and 'manually' unlock
the MI handler for calling ncr53c9x_intr().

Fixes PR mac68k/38758.
 1.50  13-Apr-2008  tsutsui branches: 1.50.2; 1.50.4; 1.50.6;
Split device_t/softc for MI ncr53c9x and some related devices,
with various cleanup.
 1.49  17-Oct-2007  garbled branches: 1.49.16;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.48  08-Jun-2007  tsutsui branches: 1.48.10;
On my LC630 64KB DMA xfer causes timeout errors
so limit sc_maxxfer size to 63KB.
 1.47  07-Mar-2007  tsutsui branches: 1.47.2; 1.47.4; 1.47.10;
Previous fix is not correct. sc_dmaaddr is actually
pointer against pointer, so just use proper casts
rather than bogus void pointers.
 1.46  05-Mar-2007  he Add two instances of an overlooked indirection.
 1.45  04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.44  08-Mar-2006  lukem branches: 1.44.14; 1.44.16;
Use the SI capitalization for "Hz", "kHz", and "MHz" in comments and strings.
Add a space between numbers and Hz unit.
 1.43  24-Dec-2005  perry branches: 1.43.4; 1.43.6; 1.43.8; 1.43.10;
__asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.42  24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.41  11-Dec-2005  christos merge ktrace-lwp.
 1.40  16-Jun-2005  jmc branches: 1.40.2;
Fixes for volatile problems
 1.39  05-Mar-2005  chs use attach args instead of dv_unit, just like cf_unit.
 1.38  19-Jan-2005  chs branches: 1.38.2;
only one of the obio locators was actually used, so get rid of the others
and collapse the two variations of obio into one. use the remaining locator
("addr") to differentiate the two possible esp and sbc devices (instead of
using the unit number).
 1.37  15-Jan-2005  chs branches: 1.37.2;
really ansify.
 1.36  15-Jan-2005  chs de-__P, remove register, ansify, b* -> mem*.
 1.35  15-Jul-2003  lukem __KERNEL_RCSID()
 1.34  02-Oct-2002  thorpej branches: 1.34.6;
Use CFATTACH_DECL().
 1.33  27-Sep-2002  thorpej Declare all cfattach structures const.
 1.32  27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.31  30-May-2002  thorpej Don't use multi-line string literals.
 1.30  18-Nov-2001  briggs branches: 1.30.8;
Correct operation of non-pseudo-DMA mode. Used on 660 & 840 AV models.
From Takeshi Shibagaki<ie9t-sbgk@asahi-net.or.jp>.
 1.29  25-Apr-2001  bouyer branches: 1.29.2; 1.29.8;
Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.28  18-Jan-2001  briggs branches: 1.28.2;
Handle the TRPAD case a little better.
Also, if the so-called DMA operation is a write and ends without target-
complete set, count the data in the FIFO as residual and add that to the
amount in the counters. Hauke Fath reports that this passes early testing
on his Quantum Viking.
 1.27  29-Dec-2000  briggs Do not try to second-guess the ncr53c9x driver by setting *dmasize to 0
if it is 64k. TCL and TCM will be set properly if we just leave it alone.
Not only that, the ncr53c9x driver issues TRPAD or TRANS based on this
value. We do not want TRPAD in this case!
 1.26  29-Dec-2000  briggs Rework the esp driver a little bit to improve performance. This requires
an ugly bit where we record the value of a2 while handling a "nofault" bus
error in locore.s in order to know how far the transaction got before a
disconnect (see esp.c comments for more details on this).
Also get rid of a loop (and delay()!) in the interrupt routine--hinted at
and researched by Chas Williams <chas@cmf.nrl.navy.mil>.
 1.25  05-Jun-2000  nisimura branches: 1.25.2;
Have MI ncr53c9x_attach() the 2nd and 3rd arguments for scsipi_adater
and scsipi_device respectively, with size reduction of ncr53c9x_softc.
Specifying NULL instructs the driver to use default adapter and default
device codes. Every target port has ncr53c9x_attach(sc, NULL, NULL) anyway.
 1.24  19-Oct-1999  thorpej branches: 1.24.4;
Program the 53c96's interrupt routing info into the VIA before doing
anything that might cause an interrupt (e.g. the SCSI bus reset in
ncr53c9x_attach()). If we don't do this, the initial interrupt is
lost, thus causing the state machine to never enter IDLE state, thus
causing SCSI commands to never be executed.

Fixes kern/8544, reported by Erik Bertelsen <erik@mediator.uni-c.dk>.
 1.23  27-Jun-1999  briggs branches: 1.23.2; 1.23.4; 1.23.6;
Undo some of my recent changes that were misguided.
 1.22  09-Jun-1999  briggs Remove some register declarations.
Get Q9x0 dual SCSI at least basically working.
Be paranoid about some register reads.
 1.21  01-Jun-1999  briggs Raise spl4 to spl6 in quick_go--I am now experimenting with interrupts
at levels 5 (sound) and 6 (via1) on the Q700.
Raise splhigh when reading and writing registers. It's ugly, but it's
possible that we could get an interrupt from a higher-level source,
causing a re-read of a memory location.
This is not good when, e.g., we are reading the interrupt register.
Ideally, we would just raise splhigh() in ncr53c9x_readregs(), but
that's m.i. code, and it may be expensive on other architectures.
 1.20  22-Dec-1998  scottr branches: 1.20.2; 1.20.6;
vm_offset_t -> {paddr_t, vaddr_t}
 1.19  19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.18  10-Oct-1998  thorpej Garbage-collect the open_target_lu and close_target_lu entry points from
struct scsipi_adapter; they were not used.

Add a scsipi_ioctl entry point to struct scsipi_adapter. This will be
used to issue ioctl commands to the host adapters.

Inspired by PR #6090, from Matt Jacob.
 1.17  05-Sep-1998  pk Relinquish my copyright claims on this file.
 1.16  09-May-1998  briggs Get both SCSI busses operational on the Q900 and Q950.
 1.15  02-May-1998  scottr Move on-board I/O and NuBus drivers to their own directories
via repository copy, and make the necessary adjustments to reflect
the moved files.
 1.14  12-Jan-1998  thorpej Update for changes to config.
 1.13  19-Nov-1997  briggs * Disable parity checking on all devices until we find a better way to
deal with cheap CD-ROMs and other devices that do not appear to have
any way to enable parity generation. In the future, it might be nice
to have this configurable on a per-device basis with back-to-back
parity errors automatically disabling parity for the device. That
would require some MI changes.
* Handle unaligned and odd-length transfers.
This could probably be handled better in the future.
 1.12  05-Nov-1997  briggs A first cut at faster SCSI for non-AV quadras. Could probably perform better,
but is a marked improvement. This takes advantage of a pseudo-DMA hardware
hack of Apple's that exposes a 16-bit register that the Apple-designed
memory controller acts like a DMA controller and handshakes into or out
of the FIFO. Wierd.
 1.11  27-Aug-1997  bouyer branches: 1.11.4;
Merge scsipi branch in the mainline. This add support for ATAPI devices
(currently only CD-ROM drives on i386). The sys/dev/scsipi system provides 2
busses to which devices can attach (scsibus and atapibus). This needed to
change some include files and structure names in the low level scsi drivers.
 1.10  05-Mar-1997  briggs branches: 1.10.2; 1.10.4;
Copyright foo.
 1.9  01-Mar-1997  scottr Fix prototype for espmatch()
 1.8  28-Feb-1997  scottr Convert to generalized VIA interrupt registration
 1.7  27-Feb-1997  briggs mac68k-specific portion of m.i. ncr53c9x driver.
 1.6  16-Dec-1996  scottr branches: 1.6.6;
Convert all foo_match() functions to use a `struct cfdata *' for their
second argument. The NuBus autoconfig code had to be reorganized as a
result of this, and looks much more like a directly-attached bus now.
These changes eliminate __BROKEN_INDIRECT_CONFIG.
 1.5  10-Dec-1996  thorpej Fill in sc_link.max_target
 1.4  04-Nov-1996  briggs - Move offset for 2nd scsi controller (Q900/Q950/WGS95) to 0x402
instead of 0x400.
- Restructure interrupt handling for more performance--continue to
read/write data as long as the device keeps us in a data xfer phase.
There is still a lot of room for speed improvement here. Perhaps it
lies is speeding up the interrupt path in general?
 1.3  02-Nov-1996  briggs Improve reliability on my Q700, at least. Was getting the occasional
glitch--an extra byte on occasion.
 1.2  30-Oct-1996  briggs macs with scsibase offset 0x10000 from iobase use a SCSI CLK of 16.5MHz
(off PrimeTime)--all others appear to use 25MHz.
 1.1  29-Oct-1996  briggs Interrupt-driven, but slow, NCR 53c96 driver for the 040-based macs. Contains
some guesses for the machines that have two of these buggers (I don't have
such a machine). This driver is a copy of the sparc/alpha esp with a
minimum of changes--after we get it performing a bit more respectably,
we should see about re-normalizing the sources.
 1.6.6.1  12-Mar-1997  is Merge in changes from The Trunk, partially just reimplementing newarp.
 1.10.4.1  27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.10.2.1  01-Jul-1997  bouyer Updates for new scsipi subsystem. Actally known to work on i386 and sparc.
 1.11.4.2  19-Nov-1997  mellon Pull rev 1.13 up from trunk (briggs)
 1.11.4.1  15-Nov-1997  mellon Pull rev 1.12 up from trunk (briggs)
 1.20.6.2  01-Jul-1999  thorpej Sync w/ -current.
 1.20.6.1  21-Jun-1999  thorpej Sync w/ -current.
 1.20.2.1  01-Nov-1999  scottr Sync with main branch.
 1.23.6.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.23.4.1  15-Nov-1999  fvdl Sync with -current
 1.23.2.5  29-Mar-2001  bouyer Pass compile-test on i386.
 1.23.2.4  11-Feb-2001  bouyer Sync with HEAD.
 1.23.2.3  05-Jan-2001  bouyer Sync with HEAD
 1.23.2.2  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.23.2.1  20-Oct-1999  thorpej Sync w/ trunk.
 1.24.4.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.25.2.2  22-Dec-2001  he Pull up revision 1.30 (requested by briggs):
Correct operation of non-pseudo-DMA mode, as used on 660 and 840
AV models.
 1.25.2.1  25-Jan-2001  jhawk Pull up revisions 1.26-1.28 (requested by briggs):
Improve performance of the pseudo-DMA mode of the esp driver, and handle
residual FIFO data on write.
 1.28.2.1  21-Jun-2001  nathanw Catch up to -current.
 1.29.8.4  18-Oct-2002  nathanw Catch up to -current.
 1.29.8.3  20-Jun-2002  nathanw Catch up to -current.
 1.29.8.2  08-Jan-2002  nathanw Catch up to -current.
 1.29.8.1  25-Apr-2001  nathanw file esp.c was added on branch nathanw_sa on 2002-01-08 00:26:08 +0000
 1.29.2.3  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.29.2.2  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.29.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.30.8.1  14-Jul-2002  gehenna catch up with -current.
 1.34.6.7  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.34.6.6  08-Mar-2005  skrll Sync with HEAD.
 1.34.6.5  24-Jan-2005  skrll Sync with HEAD.
 1.34.6.4  17-Jan-2005  skrll Sync with HEAD.
 1.34.6.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.34.6.2  18-Sep-2004  skrll Sync with HEAD.
 1.34.6.1  03-Aug-2004  skrll Sync with HEAD
 1.37.2.1  29-Apr-2005  kent sync with -current
 1.38.2.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.40.2.2  03-Sep-2007  yamt sync with head.
 1.40.2.1  21-Jun-2006  yamt sync with head.
 1.43.10.1  19-Apr-2006  elad sync with head - hopefully this will work
 1.43.8.1  13-Mar-2006  yamt sync with head.
 1.43.6.1  22-Apr-2006  simonb Sync with head.
 1.43.4.1  09-Sep-2006  rpaulo sync with head
 1.44.16.1  12-Mar-2007  rmind Sync with HEAD.
 1.44.14.1  11-May-2009  bouyer Pull up following revision(s) (requested by hauke in ticket #1315):
sys/arch/mac68k/obio/esp.c: revision 1.51 via patch
sys/arch/mac68k/conf/GENERIC: revision 1.188
Add LOCKDEBUG option, commented out, so that people know it's there.
esp_quick_dma_go() gets called from the MI ncr53c9x_intr() handler,
which protects itself against multiple invocation with a
simple_lock. Follow the example of ncr53c9x_poll() for servicing an
interrupt that came while we run in splhigh(), and 'manually' unlock
the MI handler for calling ncr53c9x_intr().
Fixes PR mac68k/38758.
 1.47.10.1  26-Jun-2007  garbled Sync with HEAD.
 1.47.4.1  11-Jul-2007  mjf Sync with head.
 1.47.2.1  15-Jul-2007  ad Sync with head.
 1.48.10.1  06-Nov-2007  matt sync with HEAD
 1.49.16.2  05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.49.16.1  02-Jun-2008  mjf Sync with HEAD.
 1.50.6.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.50.4.2  11-Mar-2010  yamt sync with head
 1.50.4.1  04-May-2009  yamt sync with head.
 1.50.2.1  04-Jun-2008  yamt sync with head
 1.54.6.1  24-Feb-2012  mrg sync to -current.
 1.54.2.1  17-Apr-2012  yamt sync with head
 1.55.40.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.55.40.1  10-Jun-2019  christos Sync with HEAD
 1.55.38.1  18-Jan-2019  pgoyette Synch with HEAD
 1.58.10.1  03-Apr-2021  thorpej Sync with HEAD.

RSS XML Feed