Bug 23409

Summary: CD-RW driver fails unless CD in drive at boot up
Product: Base System Reporter: Eyal Soha <eyal>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.2-STABLE   
Hardware: Any   
OS: Any   

Description Eyal Soha 2000-12-10 00:00:01 UTC
When booting, the CD-RW drive is not recognized unless there is a CD
in the drive.  Here's the tail end of dmesg after booting without a CD
loaded in the drive:

ad4: 8809MB <QUANTUM FIREBALLP KA9.1> [17898/16/63] at ata2-master UDMA66
ad5: 14594MB <ST315320A> [29651/16/63] at ata2-slave UDMA66
ad7: 3098MB <IBM-DAQA-33240> [6296/16/63] at ata3-slave WDMA2
ata3-master: timeout waiting for command=ef s=00 e=00
ata3-master: <SAF CD-RW2224/2.06> CDROM device - NO DRIVER!
Mounting root from ufs:/dev/ad5s1a

Here's the tail end of dmesg after booting with a CD loaded in the drive:

ad4: 8809MB <QUANTUM FIREBALLP KA9.1> [17898/16/63] at ata2-master UDMA66
ad5: 14594MB <ST315320A> [29651/16/63] at ata2-slave UDMA66
ad7: 3098MB <IBM-DAQA-33240> [6296/16/63] at ata3-slave WDMA2
ata3-master: timeout waiting for command=ef s=00 e=00
acd0: CD-RW <SAF CD-RW2224> at ata3-master using BIOSPIO
Mounting root from ufs:/dev/ad5s1a

In the failure case, the drive is not mountable and unusable.  In the
case where the drive is recognized at boot up, the drive can be
mounted if any CD is inserted and the drive works exactly as expected.
I suspect that the timeout is normal, probably because the command is
not recognized by the CD-RW.

Fix: 

Boot the system while a CD is in the CD-RW drive.  After bootup is complete, that CD may be removed or replaced by any CD.
How-To-Repeat: 
Make sure CD-RW has no CD in it.  Reboot the system.
Comment 1 esoha 2000-12-11 01:53:21 UTC
The error is in sys/dev/ata/atapi-cd.c, line 122:

    /* get drive capabilities, some drives needs this repeated */
    for (count = 0 ; count < 5 ; count++) {
	if (!(error = acd_mode_sense(cdp, ATAPI_CDROM_CAP_PAGE,
				     (caddr_t)&cdp->cap, sizeof(cdp->cap))))
	    break;
    }

For debugging purposes, I changed 5 to 0xffffff.

When I have a CD installed in the drive or the CD-RW tray is open, I
usually need only two or three retries.  When the CD-RW drive is
closed and there is no CD in it, I need between 6400 and 6500 retries.
The number of retries required fluctuates and drops significantly if I
put a delay before the for() loop.  The drive is likely not ready by
the time the ATAPI_CDROM_CAP_PAGE command is being issued.

When the bug isn't being exhibited, the error returned by
acd_mode_sense is 0x5.  (After getting error 0x5 once or twice, the
drive responds properly.)

When in the bug case (closed and empty CD-RW drive), the error
returned on the first call to acd_mode_sense() is 0x5.  Subsequent
calls all return 0x10 (between 0x400 and 0x440 times) until the final
call which returns 0.

-- 
Eyal Soha <esoha@cisco.com>                    Work: (408) 527-9276
Software Engineer                              Page: (800) 365-4578
Cisco Systems <http://www.cisco.com>   Epage: esoha@epage.cisco.com
Comment 2 Søren Schmidt freebsd_committer freebsd_triage 2001-05-30 11:54:52 UTC
State Changed
From-To: open->closed

This drive is buggy, but the atapi CDROM drive should 
cope with this now.