Subject: ncr5380sbc and rude targets
To: None <tech-kern@NetBSD.ORG>
From: Matthias Pfaller <leo@dachau.marco.de>
List: tech-kern
Date: 02/25/1997 10:42:35
There are some targets (like the cabletron EA41x) that transfer more
data then requested. The sparc esp and the ISA aic6360 driver discard
additional data on DATA_IN and provide additional data to the target on
DATA_OUT. The following patch makes the ncr5380 driver behave like the
aic6360 and the sparc esp driver. If there are no objections, I'd like
to put this change into the tree. Comments?

Matthias

--- ncr5380sbc.c.ORIG	Sun Dec 15 13:19:57 1996
+++ ncr5380sbc.c	Fri Feb 21 11:33:11 1997
@@ -257,7 +257,7 @@
 			break;
 
 		/* Put the data on the bus. */
-		*sc->sci_odata = *data++;
+		*sc->sci_odata = data ? *data++ : 0;
 
 		/* Tell the target it's there. */
 		icmd |= SCI_ICMD_ACK;
@@ -295,6 +295,7 @@
 	register u_char 	icmd;
 	register int		resid;
 	register int		error;
+	int			discard;
 
 	icmd = *(sc->sci_icmd) & SCI_ICMD_RMASK;
 
@@ -313,7 +314,10 @@
 			break;
 
 		/* Read the data bus. */
-		*data++ = *sc->sci_data;
+		if (data)
+			*data++ = *sc->sci_data;
+		else
+			discard = *sc->sci_data;
 
 		/* Tell target we got it. */
 		icmd |= SCI_ICMD_ACK;
@@ -1837,7 +1869,7 @@
 			goto noop;
 		}
 		resel = (sc->sc_flags & NCR5380_PERMIT_RESELECT) ? 1 : 0;
-		resel &= (sr->sr_flags & (SR_IMMED | SR_SENSE)) ? 0 : 1;
+		resel &= (sr->sr_flags & SR_SENSE) ? 0 : 1;
 		sc->sc_omess[0] = MSG_IDENTIFY(sr->sr_lun, resel);
 		n = 1;
 		break;
@@ -2077,9 +2109,18 @@
 
 	/* Make sure we have some data to move. */
 	if (sc->sc_datalen <= 0) {
-		printf("%s: can not transfer more data\n",
-		    sc->sc_dev.dv_xname);
-		goto abort;
+		/* Device needs padding. */
+		if (phase == PHASE_DATA_IN)
+			ncr5380_pio_in(sc, phase, 4096, NULL);
+		else
+			ncr5380_pio_out(sc, phase, 4096, NULL);
+		if (SCI_BUS_PHASE(*sc->sci_bus_csr) == phase) {
+			/* More then 4k is just too much! */
+			printf("%s: too much data padding\n",
+				sc->sc_dev.dv_xname);
+			goto abort;
+		}
+		return ACT_CONTINUE;
 	}
 
 	/*
-- 
leo@dachau.marco.de			in real life: Matthias Pfaller
marco GmbH, 85221 Dachau, Germany	tel: +49 8131 516142