Subject: scsipi change
To: None <tech-kern@netbsd.org>
From: Andrew Doran <ad@netbsd.org>
List: tech-kern
Date: 10/05/2000 12:31:22
Any objection to a change along these lines? I can think of other ways to do
it, but they all seem equally crap.

Index: atapi_wdc.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/atapi_wdc.c,v
retrieving revision 1.38
diff -u -r1.38 atapi_wdc.c
--- atapi_wdc.c	2000/08/03 23:14:31	1.38
+++ atapi_wdc.c	2000/10/05 12:28:21
@@ -103,8 +103,8 @@
 	/*
 	 * Fill in the adapter.
 	 */
-	wdc->sc_atapi_adapter._generic.scsipi_cmd = wdc_atapi_send_cmd;
-	wdc->sc_atapi_adapter._generic.scsipi_minphys = wdc_atapi_minphys;
+	wdc->sc_atapi_adapter.scsipi.scsipi_cmd = wdc_atapi_send_cmd;
+	wdc->sc_atapi_adapter.scsipi.scsipi_minphys = wdc_atapi_minphys;
 	wdc->sc_atapi_adapter.atapi_probedev = wdc_atapi_probedev;
 	wdc->sc_atapi_adapter.atapi_kill_pending = atapi_kill_pending;
 
Index: atapiconf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/atapiconf.h,v
retrieving revision 1.10
diff -u -r1.10 atapiconf.h
--- atapiconf.h	2000/04/02 23:38:19	1.10
+++ atapiconf.h	2000/10/05 12:28:21
@@ -46,7 +46,7 @@
  */
 
 struct atapi_adapter {
-	struct scsipi_adapter _generic;
+	struct scsipi_adapter scsipi;
 	void (*atapi_probedev) __P((struct atapibus_softc *, int));
 	void (*atapi_kill_pending) __P((struct scsipi_link *));
 };
Index: scsiconf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsiconf.c,v
retrieving revision 1.151
diff -u -r1.151 scsiconf.c
--- scsiconf.c	2000/09/22 16:45:17	1.151
+++ scsiconf.c	2000/10/05 12:28:28
@@ -322,6 +322,7 @@
 	int bus, target, lun;
 {
 	struct scsibus_softc *scsi;
+	struct scsi_adapter *scad;
 	int maxtarget, mintarget, maxlun, minlun;
 	u_int8_t scsi_addr;
 	int error;
@@ -352,6 +353,14 @@
 		maxlun = minlun = lun;
 	}
 
+	scad = (struct scsi_adapter *)scsi->adapter_link->adapter;
+	if (scad->scsi_prescan != NULL) {
+		error = (*scad->scsi_prescan)(scsi->adapter_link, bus,
+		    target, lun);
+		if (error != 0)
+		    	return (error);
+	}
+
 	if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0)
 		return (error);
 	for (target = mintarget; target <= maxtarget; target++) {
@@ -681,6 +690,7 @@
 	int checkdtype, priority, docontinue;
 	struct scsipibus_attach_args sa;
 	struct cfdata *cf;
+	struct scsi_adapter *scad;
 
 	/*
 	 * Assume no more luns to search after this one.
@@ -817,9 +827,10 @@
 		break;
 	}
 
-	/* Let the adapter driver handle the device separatley if it wants. */
-	if (sc_link->adapter->scsipi_accesschk != NULL &&
-	    (*sc_link->adapter->scsipi_accesschk)(sc_link, &sa.sa_inqbuf))
+	/* Let the adapter driver handle the device if it wants to. */
+	scad = (struct scsi_adapter *)sc_link->adapter;
+	if (scad->scsi_accesschk != NULL &&
+	    (*scad->scsi_accesschk)(sc_link, &sa.sa_inqbuf))
 		goto bad;
 
 	if (checkdtype) {
Index: scsiconf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsiconf.h,v
retrieving revision 1.48
diff -u -r1.48 scsiconf.h
--- scsiconf.h	1999/10/20 15:22:28	1.48
+++ scsiconf.h	2000/10/05 12:28:30
@@ -82,6 +82,21 @@
 /* sc_flags */
 #define	SCSIBUSF_OPEN	0x00000001	/* bus is open */
 
+/*
+ * These entrypoints are called by the high-end drivers to get services from
+ * whatever low-end drivers they are attached to.
+ *
+ *	scsi_accesschk	optional
+ *	scsi_prescan	optional
+ */
+struct scsipi_inquiry_pattern;
+struct scsi_adapter {
+	struct	scsipi_adapter scsipi;
+	int	(*scsi_accesschk) __P((struct scsipi_link *,
+		    struct scsipi_inquiry_pattern *));
+	int	(*scsi_prescan) __P((struct scsipi_link *, int, int, int));
+};
+
 #define SCSI_OP_TARGET	0x0001
 #define	SCSI_OP_RESET	0x0002
 #define	SCSI_OP_BDINFO	0x0003
Index: scsipiconf.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsipiconf.h,v
retrieving revision 1.46
diff -u -r1.46 scsipiconf.h
--- scsipiconf.h	2000/09/22 16:45:17	1.46
+++ scsipiconf.h	2000/10/05 12:28:30
@@ -68,7 +68,9 @@
  * various structures defined in this file:
  *
  * each adapter type has a scsipi_adapter struct. This describes the adapter
- *    and identifies routines that can be called to use the adapter.
+ *    and identifies routines that can be called to use the adapter. (SCSI
+ *    and ATAPI adapters have scsi_adapter and atapi_adapter structs 
+ *    respectively; each begins with a scsipi_adapter struct).
  * each device type has a scsipi_device struct. This describes the device and
  *    identifies routines that can be called to use the device.
  * each existing device position (scsibus + target + lun or atapibus + drive)
@@ -148,10 +150,8 @@
  *	scsipi_ioctl		optional
  *	scsipi_enable		optional
  *	scsipi_getgeom		optional
- *	scsipi_accesschk	optional
  */
 struct disk_parms;
-struct scsipi_inquiry_pattern;
 struct scsipi_adapter {
 	int	scsipi_refcnt;		/* adapter reference count */
 	int	(*scsipi_cmd) __P((struct scsipi_xfer *));
@@ -161,8 +161,6 @@
 	int	(*scsipi_enable) __P((void *, int));
 	int	(*scsipi_getgeom) __P((struct scsipi_link *,
 		    struct disk_parms *, u_long));
-	int	(*scsipi_accesschk) __P((struct scsipi_link *,
-		    struct scsipi_inquiry_pattern *));
 };
 
 /*