PERFORCE change 570643 for review

Brooks Davis brooks at FreeBSD.org
Tue Sep 3 20:37:56 UTC 2013


http://p4web.freebsd.org/@@570643?ac=10

Change 570643 by brooks at brooks_zenith on 2013/09/03 20:37:44

	Sanity check various timeout values.
	
	Requested by:	imp

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/sys/dev/cfi/cfi_core.c#19 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/sys/dev/cfi/cfi_core.c#19 (text+ko) ====

@@ -270,6 +270,7 @@
 	struct cfi_softc *sc;
 	u_int blksz, blocks;
 	u_int r, u;
+	uint64_t mtoexp, ttoexp;
 #ifdef CFI_SUPPORT_STRATAFLASH
 	uint64_t ppr;
 	char name[KENV_MNAMELEN], value[32];
@@ -288,23 +289,71 @@
 	sc->sc_handle = rman_get_bushandle(sc->sc_res);
 
 	/* Get time-out values for erase, write, and buffer write. */
-	sc->sc_typical_timeouts[CFI_TIMEOUT_ERASE] =
-		SBT_1MS * (1 << cfi_read_qry(sc, CFI_QRY_TTO_ERASE));
+	ttoexp = cfi_read_qry(sc, CFI_QRY_TTO_ERASE);
+	mtoexp = cfi_read_qry(sc, CFI_QRY_MTO_ERASE);
+	if (ttoexp == 0) {
+		device_printf(dev, "erase timeout == 0, using 2^16ms\n");
+		ttoexp = 16;
+	}
+	if (ttoexp > 41) {
+		device_printf(dev, "insane timeout: 2^%jdms\n", ttoexp);
+		return (EINVAL);
+	}
+	if (mtoexp == 0) {
+		device_printf(dev, "max erase timeout == 0, using 2^%jdms\n",
+		    ttoexp + 4);
+		mtoexp = 4;
+	}
+	if (ttoexp + mtoexp > 41) {
+		device_printf(dev, "insane max erase timeout: 2^%jd\n",
+		    ttoexp + mtoexp);
+		return (EINVAL);
+	}
+	sc->sc_typical_timeouts[CFI_TIMEOUT_ERASE] = SBT_1MS * (1ULL << ttoexp);
 	sc->sc_max_timeouts[CFI_TIMEOUT_ERASE] =
-	    sc->sc_typical_timeouts[CFI_TIMEOUT_ERASE] *
-	    (1 << cfi_read_qry(sc, CFI_QRY_MTO_ERASE));
+	    sc->sc_typical_timeouts[CFI_TIMEOUT_ERASE] * (1ULL << mtoexp);
 
-	sc->sc_typical_timeouts[CFI_TIMEOUT_WRITE] =
-	    SBT_1US * (1 << cfi_read_qry(sc, CFI_QRY_TTO_WRITE));
+	ttoexp = cfi_read_qry(sc, CFI_QRY_TTO_WRITE);
+	mtoexp = cfi_read_qry(sc, CFI_QRY_MTO_WRITE);
+	if (ttoexp == 0) {
+		device_printf(dev, "write timeout == 0, using 2^18ns\n");
+		ttoexp = 18;
+	}
+	if (ttoexp > 51) {
+		device_printf(dev, "insane write timeout: 2^%jdus\n", ttoexp);
+		return (EINVAL);
+	}
+	if (mtoexp == 0) {
+		device_printf(dev, "max write timeout == 0, using 2^%jdms\n",
+		    ttoexp + 4);
+		mtoexp = 4;
+	}
+	if (ttoexp + mtoexp > 51) {
+		device_printf(dev, "insane max write timeout: 2^%jdus\n",
+		    ttoexp + mtoexp);
+		return (EINVAL);
+	}
+	sc->sc_typical_timeouts[CFI_TIMEOUT_WRITE] = SBT_1US * (1ULL << ttoexp);
 	sc->sc_max_timeouts[CFI_TIMEOUT_WRITE] =
-	    sc->sc_typical_timeouts[CFI_TIMEOUT_WRITE] *
-	    (1 << cfi_read_qry(sc, CFI_QRY_MTO_WRITE));
+	    sc->sc_typical_timeouts[CFI_TIMEOUT_WRITE] * (1ULL << mtoexp);
 
+	ttoexp = cfi_read_qry(sc, CFI_QRY_TTO_BUFWRITE);
+	mtoexp = cfi_read_qry(sc, CFI_QRY_MTO_BUFWRITE);
+	/* Don't check for 0, it means not-supported. */
+	if (ttoexp > 51) {
+		device_printf(dev, "insane write timeout: 2^%jdus\n", ttoexp);
+		return (EINVAL);
+	}
+	if (ttoexp + mtoexp > 51) {
+		device_printf(dev, "insane max write timeout: 2^%jdus\n",
+		    ttoexp + mtoexp);
+		return (EINVAL);
+	}
 	sc->sc_typical_timeouts[CFI_TIMEOUT_BUFWRITE] =
-	    SBT_1US * (1 << cfi_read_qry(sc, CFI_QRY_TTO_BUFWRITE));
+	    SBT_1US * (1ULL << cfi_read_qry(sc, CFI_QRY_TTO_BUFWRITE));
 	sc->sc_max_timeouts[CFI_TIMEOUT_BUFWRITE] =
 	    sc->sc_typical_timeouts[CFI_TIMEOUT_BUFWRITE] *
-	    (1 << cfi_read_qry(sc, CFI_QRY_MTO_BUFWRITE));
+	    (1ULL << cfi_read_qry(sc, CFI_QRY_MTO_BUFWRITE));
 
 	/* Get the maximum size of a multibyte program */
 	if (sc->sc_typical_timeouts[CFI_TIMEOUT_BUFWRITE] != 0)


More information about the p4-projects mailing list