From luigi@prova.iet.unipi.it  Fri Jan 16 06:42:26 1998
Received: from prova.iet.unipi.it (prova1.iet.unipi.it [131.114.9.11])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA17817
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 16 Jan 1998 06:42:22 -0800 (PST)
          (envelope-from luigi@prova.iet.unipi.it)
Received: (from luigi@localhost)
	by prova.iet.unipi.it (8.8.5/8.8.5) id PAA01301;
	Fri, 16 Jan 1998 15:44:19 +0100 (CET)
Message-Id: <199801161444.PAA01301@prova.iet.unipi.it>
Date: Fri, 16 Jan 1998 15:44:19 +0100 (CET)
From: Luigi Rizzo <luigi@iet.unipi.it>
Reply-To: luigi@iet.unipi.it
To: FreeBSD-gnats-submit@freebsd.org
Subject: Incomplete ATAPI diagnostic at boot
X-Send-Pr-Version: 3.2

>Number:         5510
>Category:       kern
>Synopsis:       [PATCH] Incomplete ATAPI diagnostic at boot
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    sos
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 16 06:50:01 PST 1998
>Closed-Date:    Mon Feb 28 11:32:55 PST 2000
>Last-Modified:  Mon Feb 28 11:33:30 PST 2000
>Originator:     Luigi Rizzo
>Release:        all
>Organization:
DEIT
>Environment:

	wcd (atapi) driver, all versions of FreeBSD, ATAPI cdrom

>Description:

	Some ATAPI CD ROM drives return an error to the
	ATAPI_MODE_SENSE command more than once at boot time. This
	behaviour is not deterministic and might be due to timing
	issues (how fast is the boot phase, how long the drive takes
	to identify the media, etc.).

	The following patch retries the ATAPI_MODE_SENSE command
	several times to leave the drive time to settle and return
	without errors.

>How-To-Repeat:

    boot a 2.2.x kernel on a system with ATAPI cdrom, and try
    how it works during cold vs. warm boot, or with tray
    open/closed, data or audio cd, etc.

    At times, the drive returns two errors and you will not see
    reports like
    wcd0: 344Kb/sec, 256Kb cache, audio play, 256 volume levels, ...

>Fix:

	Apply the following patch. Tested on 2.2.1, should apply
	cleanly to all versions and has no side effects I believe
	(I set the number of retries to 10, although I have never seen
	more than 3 or perhaps 4 necessary on my machines).
	

--- wcd.c.orig	Sun Sep  8 12:28:23 1996
+++ wcd.c	Thu Jan 15 17:38:29 1998
@@ -272,6 +272,7 @@
 	struct wcd *t;
 	struct atapires result;
 	int lun;
+	int loops = 0 ;
 
 	if (wcdnlun >= NUNIT) {
 		printf ("wcd: too many units\n");
@@ -302,18 +303,14 @@
 	}
 
 	/* Get drive capabilities. */
+	for (loops = 0 ; loops < 10 ; loops++) {
+	     /* some drives are slow to respond at boot time... */
 	result = atapi_request_immediate (ata, unit, ATAPI_MODE_SENSE,
 		0, CAP_PAGE, 0, 0, 0, 0, sizeof (t->cap) >> 8, sizeof (t->cap),
 		0, 0, 0, 0, 0, 0, 0, (char*) &t->cap, sizeof (t->cap));
-
-	/* Do it twice to avoid the stale media changed state. */
-	if (result.code == RES_ERR &&
-	    (result.error & AER_SKEY) == AER_SK_UNIT_ATTENTION)
-		result = atapi_request_immediate (ata, unit, ATAPI_MODE_SENSE,
-			0, CAP_PAGE, 0, 0, 0, 0, sizeof (t->cap) >> 8,
-			sizeof (t->cap), 0, 0, 0, 0, 0, 0, 0,
-			(char*) &t->cap, sizeof (t->cap));
-
+	    if (result.code == 0 || result.code == RES_UNDERRUN)
+		    break;
+	}
 	/* Some drives have shorter capabilities page. */
 	if (result.code == RES_UNDERRUN)
 		result.code = 0;


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Thu Apr 30 23:01:59 PDT 1998 
State-Changed-Why:  
waiting for sos to look at it 


Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: phk 
Responsible-Changed-When: Thu Apr 30 23:01:59 PDT 1998 
Responsible-Changed-Why:  
->sos 
State-Changed-From-To: suspended->closed 
State-Changed-By: sos 
State-Changed-When: Mon Feb 28 11:32:55 PST 2000 
State-Changed-Why:  
Fixed in 4.0. 
>Unformatted:
