Module Name:    src
Committed By:   riz
Date:           Thu Jul 12 17:17:27 UTC 2012

Modified Files:
        src/sys/dev/mscp [netbsd-6]: mscp.c mscp.h mscp_subr.c

Log Message:
Pull up following revision(s) (requested by abs in ticket #410):
        sys/dev/mscp/mscp.h: revision 1.9
        sys/dev/mscp/mscp.c: revision 1.35
        sys/dev/mscp/mscp_subr.c: revision 1.43
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.34.18.1 src/sys/dev/mscp/mscp.c
cvs rdiff -u -r1.8 -r1.8.116.1 src/sys/dev/mscp/mscp.h
cvs rdiff -u -r1.41.18.1 -r1.41.18.2 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.34.18.1
--- src/sys/dev/mscp/mscp.c:1.34	Tue May 12 14:37:59 2009
+++ src/sys/dev/mscp/mscp.c	Thu Jul 12 17:17:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp.c,v 1.34 2009/05/12 14:37:59 cegger Exp $	*/
+/*	$NetBSD: mscp.c,v 1.34.18.1 2012/07/12 17:17:27 riz 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.34.18.1 2012/07/12 17:17:27 riz 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.8.116.1
--- src/sys/dev/mscp/mscp.h:1.8	Sun Dec 11 12:22:47 2005
+++ src/sys/dev/mscp/mscp.h	Thu Jul 12 17:17:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp.h,v 1.8 2005/12/11 12:22:47 christos Exp $	*/
+/*	$NetBSD: mscp.h,v 1.8.116.1 2012/07/12 17:17:26 riz 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_subr.c
diff -u src/sys/dev/mscp/mscp_subr.c:1.41.18.1 src/sys/dev/mscp/mscp_subr.c:1.41.18.2
--- src/sys/dev/mscp/mscp_subr.c:1.41.18.1	Wed Jul  4 20:41:47 2012
+++ src/sys/dev/mscp/mscp_subr.c	Thu Jul 12 17:17:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mscp_subr.c,v 1.41.18.1 2012/07/04 20:41:47 jdc Exp $	*/
+/*	$NetBSD: mscp_subr.c,v 1.41.18.2 2012/07/12 17:17:27 riz 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.41.18.1 2012/07/04 20:41:47 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mscp_subr.c,v 1.41.18.2 2012/07/12 17:17:27 riz 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