Subject: Transfer length/residuals on ATAPI CD-ROM driver
To: 'port-i386@netbsd.org' <port-i386@netbsd.org>
From: David Jones <david.jones@intrinsix.com>
List: port-i386
Date: 02/18/2002 13:11:14
I am doing "raw" SCSI (MMC3) programming through the ATAPI CD-ROM driver.
Some successes, but a couple of perplexing results.

- If I do a read command, I would expect datalen_used to report how many
bytes were
  actually transferred to/from the device.  Sometimes this happens, and
other times it
  does not.  Usually, I do not get correct residuals immediately after boot,
and then
  later on (after some unknown event occurs), I do.  Although I can work
around this
  in software, I would rather know the root cause.

- I tried reading a sector from a known bad disc.  The CD-ROM drive took a
long time to
  read the block, and the SCSI command timed out.  Fair enough, but
afterwards, the device
  driver and/or ATAPI bus seemed to "lock up": future attempts to open
/dev/rcd0d would
  return EIO.  I would also get PIO lost interrupts on the console.
  The only recourse was to reboot.  Is there a way to reset the ATAPI device
  programmatically?  Preferably one that does not require /dev/rcd0d to be
opened
  beforehand, since this open will not succeed.

- This may be a problem in my code  but I'll ask anyway.  My application is
built around
  Tcl/Tk, and adds specialized commands to access the CD-ROM device at the
ATAPI/SCSI
  level.  Every now and then, the program will lock up.  Investigation with
GDB reveals that
  the program is blocked in read(), apparently from the Tcl interpreter main
loop.  This
  happens even if I provide a script name on the command line, so the Tcl
shell does not
  run interactively.  Strangely, single-stepping through the code with GDB
will often
  clear this up, and another run of the program, with the same arguments,
will run to
  completion without locking up.

Other than the ATAPI bus lockup after reading the bad disc and timeout, none
of these
problems are consistently reproducible.  Any ideas?

Please email me directly; I don't subscribe to this list.

Thanks in advance.