Subject: kern/14230: Supporting SCSI drives reporting illegal sector size
To: None <gnats-bugs@gnats.netbsd.org>
From: Takahiro Kambe <taca@kyoto.jepro.co.jp>
List: netbsd-bugs
Date: 10/12/2001 20:09:59
>Number:         14230
>Category:       kern
>Synopsis:       Supporting SCSI drives reporting illegal sector size
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 12 04:11:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Takahiro Kambe
>Release:        NetBSD 1.5.2
>Organization:
JEPRO Co., Ltd.
>Environment:
	
System: NetBSD cancel.kyoto.jepro.co.jp 1.5.2 NetBSD 1.5.2 (CANCEL) #30: Fri Sep 14 18:05:08 JST 2001 taca@cancel.kyoto.jepro.co.jp:/usr/src/sys/arch/i386/compile/CANCEL i386


>Description:
	Some vendor sells "External SCSI hard disk drive", which is
	eally constructed with IDE hard disk drive and IDE-SCSI
	converter.

	Some of those *cheap* products report illegal sector size
	as bellow:

sd0 at scsibus0 target 4 lun 0: <MELCO, DSU-GTH, 1.0H> SCSI3 0/direct fixed
sd0: 4810 MB, 12968 cyl, 6 head, 1028 sec, 63 bytes/sect x 80063424 sectors

	Of cource, this disk's real sector size isn't 63 bytes but
	512 bytes.  (I have opened the case and found an IDE disk
	drive in it.)  And ignoring reported sector size, those
	defective products may be used.

>How-To-Repeat:
	Boot NetBSD with cheap "External SCSI hard disk drive".
>Fix:
	Adding a new quirk bit.  But quirks in scsipi_link structure
	is u_int16 type and all bits are already defined.

	I assume in bellow patch that "ADEV_" and "SDEV_" bits would
	never used for the same device, and defined SDEV_NOSECSIZE
	same as ADEV_LITTLETOC.

	P.S.
	Once I met other type of problem with another product, which
	had broken SCSI disconnect command implementation.  If SCSI
	disconnect command could be disabled with SCSI inquiry
	information.

Index: scsiconf.c
===================================================================
RCS file: /usr/pkg/libdata/cvs/netbsd/sys/dev/scsipi/scsiconf.c,v
retrieving revision 1.1.1.6.2.2
diff -u -u -r1.1.1.6.2.2 scsiconf.c
--- scsiconf.c	2000/09/06 05:15:57	1.1.1.6.2.2
+++ scsiconf.c	2001/10/12 07:17:12
@@ -588,6 +588,8 @@
 	 "SEAGATE ", "ST34501FC       ", ""},     SDEV_NOMODESENSE},
 	{{T_DIRECT, T_FIXED,
 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
+	{{T_DIRECT, T_FIXED,
+	 "MELCO ", "DSU-GTH", ""}, 		  SDEV_NOSECSIZE},
 	{{T_DIRECT, T_REMOV,
 	 "iomega", "jaz 1GB", 		 ""},	  SDEV_NOMODESENSE},
 	{{T_DIRECT, T_REMOV,
Index: scsipiconf.h
===================================================================
RCS file: /usr/pkg/libdata/cvs/netbsd/sys/dev/scsipi/scsipiconf.h,v
retrieving revision 1.1.1.5
diff -u -u -r1.1.1.5 scsipiconf.h
--- scsipiconf.h	2000/06/15 00:01:21	1.1.1.5
+++ scsipiconf.h	2001/10/12 07:17:12
@@ -212,6 +212,7 @@
 #define ADEV_NODOORLOCK		0x2000	/* device can't lock door */
 #define ADEV_NOSENSE		0x4000	/* device can't handle request sense */
 #define SDEV_ONLYBIG		0x8000	/* only use SCSI_{READ,WRITE}_BIG */
+#define SDEV_NOSECSIZE		0x0400	/* device reports bad secotr size */
 
 	struct	scsipi_device *device;	/* device entry points etc. */
 	void	*device_softc;		/* needed for call to foo_start */
Index: sd_scsi.c
===================================================================
RCS file: /usr/pkg/libdata/cvs/netbsd/sys/dev/scsipi/sd_scsi.c,v
retrieving revision 1.1.1.3
diff -u -u -r1.1.1.3 sd_scsi.c
--- sd_scsi.c	2000/06/15 00:01:21	1.1.1.3
+++ sd_scsi.c	2001/10/12 07:17:12
@@ -293,7 +293,7 @@
 		if (dp->heads == 0 || dp->cyls == 0)
 			goto fake_it;
 
-		if (dp->blksize == 0)
+		if (dp->blksize == 0 || (link->quirks & SDEV_NOSECSIZE))
 			dp->blksize = 512;
 
 		sectors = scsipi_size(link, flags);
@@ -314,7 +314,7 @@
 		if (dp->disksize == 0)
 			goto fake_it;
 
-		if (dp->blksize == 0)
+		if (dp->blksize == 0 || (link->quirks & SDEV_NOSECSIZE))
 			dp->blksize = 512;
 
 		return (SDGP_RESULT_OK);

>Release-Note:
>Audit-Trail:
>Unformatted: