Module Name:    src
Committed By:   abs
Date:           Tue Jul 10 22:30:24 UTC 2012

Modified Files:
        src/sys/dev/mscp: mscp.c mscp.h mscp_disk.c mscp_subr.c

Log Message:
Adjust MSCP attach routines. The current code worked fine on simh-vax, but
unfortunately failed on at least one 'real' SCSI MSCP adaptor.
In the updated code
mscp_dorsp()


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/mscp/mscp.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/mscp/mscp.h
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/mscp/mscp_disk.c
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/mscp/mscp_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/mscp/mscp.c
diff -u src/sys/dev/mscp/mscp.c:1.34 src/sys/dev/mscp/mscp.c:1.35
--- src/sys/dev/mscp/mscp.c:1.34	Tue May 12 14:37:59 2009
+++ src/sys/dev/mscp/mscp.c	Tue Jul 10 22:30:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp.c,v 1.34 2009/05/12 14:37:59 cegger Exp $	*/
+/*	$NetBSD: mscp.c,v 1.35 2012/07/10 22:30:23 abs Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mscp.c,v 1.34 2009/05/12 14:37:59 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mscp.c,v 1.35 2012/07/10 22:30:23 abs Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -173,7 +173,8 @@ mscp_dorsp(struct mscp_softc *mi)
 	struct mscp_xi *mxi;
 	int nextrsp;
 	int st, error;
-	extern struct mscp slavereply;
+	extern struct mscp mscp_cold_reply;
+	extern int mscp_cold_unit;
 
 	nextrsp = mi->mi_rsp.mri_next;
 loop:
@@ -287,8 +288,12 @@ loop:
 		 * to set it up, otherwise it's just a "normal" unit
 		 * status.
 		 */
-		if (cold)
-			memcpy(&slavereply, mp, sizeof(struct mscp));
+		if (cold) {
+			memcpy(&mscp_cold_reply, mp, sizeof(struct mscp));
+			/* Detect that we've reached the end of all units */
+			if (mp->mscp_unit < mscp_cold_unit)
+				break;
+		}
 
 		if (mp->mscp_status == (M_ST_OFFLINE|M_OFFLINE_UNKNOWN))
 			break;

Index: src/sys/dev/mscp/mscp.h
diff -u src/sys/dev/mscp/mscp.h:1.8 src/sys/dev/mscp/mscp.h:1.9
--- src/sys/dev/mscp/mscp.h:1.8	Sun Dec 11 12:22:47 2005
+++ src/sys/dev/mscp/mscp.h	Tue Jul 10 22:30:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp.h,v 1.8 2005/12/11 12:22:47 christos Exp $	*/
+/*	$NetBSD: mscp.h,v 1.9 2012/07/10 22:30:23 abs Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -40,6 +40,8 @@
  * IF DEC SOLD DOCUMENTATION FOR THEIR OWN CONTROLLERS.
  */
 
+#define MSCP_MAX_UNIT	4095
+
 /*
  * Control message opcodes
  */

Index: src/sys/dev/mscp/mscp_disk.c
diff -u src/sys/dev/mscp/mscp_disk.c:1.72 src/sys/dev/mscp/mscp_disk.c:1.73
--- src/sys/dev/mscp/mscp_disk.c:1.72	Fri Jun 22 20:42:24 2012
+++ src/sys/dev/mscp/mscp_disk.c	Tue Jul 10 22:30:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp_disk.c,v 1.72 2012/06/22 20:42:24 abs Exp $	*/
+/*	$NetBSD: mscp_disk.c,v 1.73 2012/07/10 22:30:23 abs Exp $	*/
 /*
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
@@ -82,11 +82,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mscp_disk.c,v 1.72 2012/06/22 20:42:24 abs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mscp_disk.c,v 1.73 2012/07/10 22:30:23 abs Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
 #include <sys/bufq.h>
+#include <sys/cdio.h>
 #include <sys/device.h>
 #include <sys/disk.h>
 #include <sys/disklabel.h>
@@ -305,7 +306,7 @@ raclose(dev_t dev, int flags, int fmt, s
 			(void) tsleep(&udautab[unit], PZERO - 1,
 			    "raclose", 0);
 		splx(s);
-		ra->ra_state = CLOSED;
+		ra->ra_state = DK_CLOSED;
 		ra->ra_wlabel = 0;
 	}
 #endif
@@ -461,9 +462,8 @@ raioctl(dev_t dev, u_long cmd, void *dat
 		if (cmd == ODIOCGDEFLABEL)
 			tp = &newlabel;
 		else
-#else
-		tp = (struct disklabel *)data;
 #endif
+		tp = (struct disklabel *)data;
 		memset(tp, 0, sizeof(struct disklabel));
 		tp->d_secsize = lp->d_secsize;
 		tp->d_nsectors = lp->d_nsectors;
@@ -516,14 +516,21 @@ raioctl(dev_t dev, u_long cmd, void *dat
 		return (dkwedge_list(&ra->ra_disk, dkwl, l));
 	    }
 
+	case DIOCTUR:
+		/* test unit ready */
+		if (ra->ra_state == DK_CLOSED &&
+		    ra_putonline(dev, ra) == MSCP_FAILED)
+			error = ENXIO;
+		*((int*)data) = (ra->ra_state == DK_OPEN);
+		return error;
+
 	default:
 		error = ENOTTY;
 		break;
 	}
-	return (error);
+	return error;
 }
 
-
 int
 radump(dev_t dev, daddr_t blkno, void *va, size_t size)
 {
@@ -750,6 +757,7 @@ rx_putonline(struct rx_softc *rx)
 	return MSCP_DONE;
 }
 
+
 #if NRX
 
 /*

Index: src/sys/dev/mscp/mscp_subr.c
diff -u src/sys/dev/mscp/mscp_subr.c:1.42 src/sys/dev/mscp/mscp_subr.c:1.43
--- src/sys/dev/mscp/mscp_subr.c:1.42	Fri Jun 22 20:42:24 2012
+++ src/sys/dev/mscp/mscp_subr.c	Tue Jul 10 22:30:23 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp_subr.c,v 1.42 2012/06/22 20:42:24 abs Exp $	*/
+/*	$NetBSD: mscp_subr.c,v 1.43 2012/07/10 22:30:23 abs Exp $	*/
 /*
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mscp_subr.c,v 1.42 2012/06/22 20:42:24 abs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mscp_subr.c,v 1.43 2012/07/10 22:30:23 abs Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -112,7 +112,8 @@ CFATTACH_DECL(mscpbus, sizeof(struct msc
 #define	WRITE_IP(x)	bus_space_write_2(mi->mi_iot, mi->mi_iph, 0, (x))
 #define	WRITE_SW(x)	bus_space_write_2(mi->mi_iot, mi->mi_swh, 0, (x))
 
-struct	mscp slavereply;
+struct	mscp mscp_cold_reply;
+int	     mscp_cold_unit;
 
 #define NITEMS		4
 
@@ -178,7 +179,7 @@ mscp_attach(device_t parent, device_t se
 	struct mscp *mp2;
 	volatile struct mscp *mp;
 	volatile int i;
-	int	timeout, error, next = 0;
+	int	timeout, error, unit;
 
 	mi->mi_mc = ma->ma_mc;
 	mi->mi_me = NULL;
@@ -263,96 +264,101 @@ mscp_attach(device_t parent, device_t se
 	 * Go out and search for sub-units on this MSCP bus,
 	 * and call config_found for each found.
 	 */
-findunit:
-	mp = mscp_getcp(mi, MSCP_DONTWAIT);
-	if (mp == NULL)
-		panic("mscpattach: no packets");
-	mp->mscp_opcode = M_OP_GETUNITST;
-	mp->mscp_unit = next;
-	mp->mscp_modifier = M_GUM_NEXTUNIT;
-	*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
-	slavereply.mscp_opcode = 0;
-
-	i = bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
-	mp = &slavereply;
-	timeout = 1000;
-	while (timeout-- > 0) {
-		DELAY(10000);
-		if (mp->mscp_opcode)
-			goto gotit;
-	}
-	printf("%s: no response to Get Unit Status request\n",
-	    device_xname(&mi->mi_dev));
-	return;
-
-gotit:	/*
-	 * Got a slave response.  If the unit is there, use it.
-	 */
-	switch (mp->mscp_status & M_ST_MASK) {
-
-	case M_ST_SUCCESS:	/* worked */
-	case M_ST_AVAILABLE:	/* found another drive */
-		break;		/* use it */
+	for (unit = 0; unit <= MSCP_MAX_UNIT; ++unit) {
+		mp = mscp_getcp(mi, MSCP_DONTWAIT);
+		if (mp == NULL)
+			panic("mscpattach: no packets");
+		mp->mscp_opcode = M_OP_GETUNITST;
+		mp->mscp_unit = unit;
+		mp->mscp_modifier = M_GUM_NEXTUNIT;
+		*mp->mscp_addr |= MSCP_OWN | MSCP_INT;
+		mscp_cold_reply.mscp_opcode = 0;
+		mscp_cold_unit = mp->mscp_unit;
+
+		i = bus_space_read_2(mi->mi_iot, mi->mi_iph, 0);
+		mp = &mscp_cold_reply;
+		timeout = 1000;
+
+		while (!mp->mscp_opcode) {
+			if ( --timeout == 0) {
+				printf("%s: no Get Unit Status response\n",
+				    device_xname(&mi->mi_dev));
+				return;
+			}
+			DELAY(10000);
+		}
 
-	case M_ST_OFFLINE:
 		/*
-		 * Figure out why it is off line.  It may be because
-		 * it is nonexistent, or because it is spun down, or
-		 * for some other reason.
+		 * Got a slave response.  If the unit is there, use it.
 		 */
-		switch (mp->mscp_status & ~M_ST_MASK) {
 
-		case M_OFFLINE_UNKNOWN:
-			/*
-			 * No such drive, and there are none with
-			 * higher unit numbers either, if we are
-			 * using M_GUM_NEXTUNIT.
-			 */
-			mi->mi_ierr = 3;
+		/*
+		 * If we get a lower number, we have circulated around all
+		 * devices and are finished, otherwise try to find next unit.
+		 */
+		if (mp->mscp_unit < unit)
 			return;
+		/*
+		 * If a higher number, use it to skip non-present devices
+		 */
+		if (mp->mscp_unit > unit)
+			unit = mp->mscp_unit;
+
+		switch (mp->mscp_status & M_ST_MASK) {
+
+		case M_ST_SUCCESS:	/* worked */
+		case M_ST_AVAILABLE:	/* found another drive */
+			break;		/* use it */
 
-		case M_OFFLINE_UNMOUNTED:
+		case M_ST_OFFLINE:
 			/*
-			 * The drive is not spun up.  Use it anyway.
-			 *
-			 * N.B.: this seems to be a common occurrance
-			 * after a power failure.  The first attempt
-			 * to bring it on line seems to spin it up
-			 * (and thus takes several minutes).  Perhaps
-			 * we should note here that the on-line may
-			 * take longer than usual.
+			 * Figure out why it is off line.  It may be because
+			 * it is nonexistent, or because it is spun down, or
+			 * for some other reason.
 			 */
+			switch (mp->mscp_status & ~M_ST_MASK) {
+
+			case M_OFFLINE_UNKNOWN:
+				/*
+				 * No such drive, and there are none with
+				 * higher unit numbers either, if we are
+				 * using M_GUM_NEXTUNIT.
+				 */
+				mi->mi_ierr = 3;
+				break; /* return */
+
+			case M_OFFLINE_UNMOUNTED:
+				/*
+				 * The drive is not spun up.  Use it anyway.
+				 *
+				 * N.B.: this seems to be a common occurrance
+				 * after a power failure.  The first attempt
+				 * to bring it on line seems to spin it up
+				 * (and thus takes several minutes).  Perhaps
+				 * we should note here that the on-line may
+				 * take longer than usual.
+				 */
+				break;
+
+			default:
+				/*
+				 * In service, or something else unusable.
+				 */
+				printf("%s: unit %d off line: ",
+				    device_xname(&mi->mi_dev), mp->mscp_unit);
+				mp2 = __UNVOLATILE(mp);
+				mscp_printevent(mp2);
+				break;
+			}
 			break;
 
 		default:
-			/*
-			 * In service, or something else equally unusable.
-			 */
-			printf("%s: unit %d off line: ", device_xname(&mi->mi_dev),
-				mp->mscp_unit);
-			mp2 = __UNVOLATILE(mp);
-			mscp_printevent(mp2);
-			next++;
-			goto findunit;
+			aprint_error_dev(&mi->mi_dev,
+			    "unable to get unit status: ");
+			mscp_printevent(__UNVOLATILE(mp));
+			return;
 		}
-		break;
-
-	default:
-		aprint_error_dev(&mi->mi_dev, "unable to get unit status: ");
-		mscp_printevent(__UNVOLATILE(mp));
-		return;
 	}
-
-	/*
-	 * If we get a lower number, we have circulated around all
-	 * devices and are finished, otherwise try to find next unit.
-	 * We shouldn't ever get this, it's a workaround.
-	 */
-	if (mp->mscp_unit < next)
-		return;
-
-	next = mp->mscp_unit + 1;
-	goto findunit;
 }
 
 

Reply via email to