From wilko@yedi.iaf.nl  Sun Nov 30 15:35:26 1997
Received: from iafnl.es.iaf.nl (uucp@iafnl.es.iaf.nl [195.108.17.20])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id PAA14200
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 30 Nov 1997 15:35:25 -0800 (PST)
          (envelope-from wilko@yedi.iaf.nl)
Received: by iafnl.es.iaf.nl with UUCP id AA19170
  (5.67b/IDA-1.5 for FreeBSD-gnats-submit@freebsd.org); Mon, 1 Dec 1997 00:35:29 +0100
Received: (from wilko@localhost) by yedi.iaf.nl (8.8.5/8.6.12) id AAA28132; Mon, 1 Dec 1997 00:25:23 +0100 (MET)
Message-Id: <199711302325.AAA28132@yedi.iaf.nl>
Date: Mon, 1 Dec 1997 00:25:23 +0100 (MET)
From: wilko@yedi.iaf.nl
Reply-To: wilko@yedi.iaf.nl
To: FreeBSD-gnats-submit@freebsd.org
Subject: patch to allow slow scsi cdroms more time to startup
X-Send-Pr-Version: 3.2

>Number:         5181
>Category:       kern
>Synopsis:       patch to allow slow scsi cdroms more time to startup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 30 15:40:01 PST 1997
>Closed-Date:    Sat Dec 13 16:33:16 PST 1997
>Last-Modified:  Sat Dec 13 16:36:21 PST 1997
>Originator:     Wilko Bulte
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
Private FreeBSD site - Arnhem, The Netherlands
>Environment:

	FreeBSD 2.2.1-R but also applicable to FreeBSD-2.2.5R
	Toshiba XM5701 12x SCSI cdrom connected to a NCR810

>Description:

	Some SCSI cdroms are slow to react to a start_unit command after the
	media has been changed. While getting up to speed, they report 
	'not ready'. This makes the cd_open() fail immediately with ENXIO,
	resulting in misleading 'device not configured' errors when 'mount'
	is run.

>How-To-Repeat:

	Change media and immediately perform mount of the cdrom.

>Fix:
	
	Below is a diff -c based on the 2.2.1R sources for /sys/scsi/cd.c
	that fixes the issue:

	
*** cd.c.orig	Wed Nov 26 20:18:54 1997
--- cd.c	Mon Dec  1 00:12:05 1997
***************
*** 246,251 ****
--- 246,252 ----
  	errval  errcode = 0;
  	u_int32_t unit, part;
  	struct scsi_data *cd;
+ 	int n = 0;
  
  	unit = CDUNIT(dev);
  	part = PARTITION(dev);
***************
*** 285,295 ****
--- 286,312 ----
  	scsi_start_unit(sc_link, CD_START);
  	SC_DEBUG(sc_link, SDEV_DB3, ("'start' attempted "));
  	sc_link->flags |= SDEV_OPEN;	/* unit attn errors are now errors */
+ 
+ 	/* Some drives e.g. Toshiba's tend to take a long time to become ready
+ 	 * after a disc swap and report 'Not Ready' while doing so. 
+ 	 * They should have reported 'Unit In The Process Of Getting Ready' 
+ 	 * but alas they don't. Attempts to e.g. mount during this period 
+ 	 * will result in device not configured due to ENXIO. The code below
+ 	 * gives them some time to come up.
+ 	 */
+ 	while ((scsi_test_unit_ready(sc_link, SCSI_SILENT) != 0) && 
+ 		(n != 12)) {
+ 		tsleep(cd, PRIBIO | PCATCH, "cdrdy", hz);
+ 		n++;
+ 	}
+ 	
+ 	/* It really should be ready by now. If not, it's time to give up */
  	if (scsi_test_unit_ready(sc_link, SCSI_SILENT) != 0) {
  		SC_DEBUG(sc_link, SDEV_DB3, ("not ready\n"));
  		errcode = ENXIO;
  		goto bad;
  	}
+ 
  	SC_DEBUG(sc_link, SDEV_DB3, ("Device present\n"));
  	scsi_prevent(sc_link, PR_PREVENT, SCSI_SILENT);
  	/*

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jraynard 
State-Changed-When: Sat Dec 13 16:33:16 PST 1997 
State-Changed-Why:  
Suggested patch committed (with a couple of cosmetic changes).  Thanks! 
>Unformatted:
