From owner-p4-projects@FreeBSD.ORG Tue Sep 3 20:37:56 2013 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5E9E5DE1; Tue, 3 Sep 2013 20:37:56 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 08587DDF for ; Tue, 3 Sep 2013 20:37:56 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [8.8.178.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E8FDF27AC for ; Tue, 3 Sep 2013 20:37:55 +0000 (UTC) Received: from skunkworks.freebsd.org ([127.0.1.74]) by skunkworks.freebsd.org (8.14.7/8.14.7) with ESMTP id r83Kbtdb080651 for ; Tue, 3 Sep 2013 20:37:55 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.7/8.14.6/Submit) id r83Kbt8q080648 for perforce@freebsd.org; Tue, 3 Sep 2013 20:37:55 GMT (envelope-from brooks@freebsd.org) Date: Tue, 3 Sep 2013 20:37:55 GMT Message-Id: <201309032037.r83Kbt8q080648@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis Subject: PERFORCE change 570643 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Sep 2013 20:37:56 -0000 http://p4web.freebsd.org/@@570643?ac=10 Change 570643 by brooks@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)