Module Name:    src
Committed By:   mlelstv
Date:           Sun Apr  8 11:57:43 UTC 2018

Modified Files:
        src/sys/dev/ic: mvsata.c

Log Message:
Avoid rounding errors for timeout values.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/ic/mvsata.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/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.39 src/sys/dev/ic/mvsata.c:1.40
--- src/sys/dev/ic/mvsata.c:1.39	Tue Oct 17 16:24:14 2017
+++ src/sys/dev/ic/mvsata.c	Sun Apr  8 11:57:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.39 2017/10/17 16:24:14 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.40 2018/04/08 11:57:43 mlelstv Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.39 2017/10/17 16:24:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.40 2018/04/08 11:57:43 mlelstv Exp $");
 
 #include "opt_mvsata.h"
 
@@ -3574,32 +3574,40 @@ mvsata_edma_disable(struct mvsata_port *
 {
 	struct ata_channel *chp = &mvport->port_ata_channel;
 	uint32_t status, command;
-	int ms;
+	uint32_t idlestatus = EDMA_S_EDMAIDLE | EDMA_S_ECACHEEMPTY;
+	int t;
 
 	if (MVSATA_EDMA_READ_4(mvport, EDMA_CMD) & EDMA_CMD_EENEDMA) {
-		for (ms = 0; ms < timeout; ms++) {
+
+		timeout = mstohz(timeout + hztoms(1) - 1);
+
+		for (t = 0; ; ++t) {
 			status = MVSATA_EDMA_READ_4(mvport, EDMA_S);
-			if (status & EDMA_S_EDMAIDLE)
+			if ((status & idlestatus) == idlestatus)
 				break;
-			ata_delay(chp, 1, "mvsata_edma1", wflags);
+			if (t >= timeout)
+				break;
+			ata_delay(chp, hztoms(1), "mvsata_edma1", wflags);
 		}
-		if (ms == timeout) {
-			aprint_error("%s:%d:%d: unable to disable EDMA\n",
+		if (t >= timeout) {
+			aprint_error("%s:%d:%d: unable to stop EDMA\n",
 			    device_xname(MVSATA_DEV2(mvport)),
 			    mvport->port_hc->hc, mvport->port);
 			return EBUSY;
 		}
 
-		/* The diable bit (eDsEDMA) is self negated. */
+		/* The disable bit (eDsEDMA) is self negated. */
 		MVSATA_EDMA_WRITE_4(mvport, EDMA_CMD, EDMA_CMD_EDSEDMA);
 
-		for ( ; ms < timeout; ms++) {
+		for (t = 0; ; ++t) {
 			command = MVSATA_EDMA_READ_4(mvport, EDMA_CMD);
 			if (!(command & EDMA_CMD_EENEDMA))
 				break;
-			ata_delay(chp, 1, "mvsata_edma2", wflags);
+			if (t >= timeout)
+				break;
+			ata_delay(chp, hztoms(1), "mvsata_edma2", wflags);
 		}
-		if (ms == timeout) {
+		if (t >= timeout) {
 			aprint_error("%s:%d:%d: unable to re-enable EDMA\n",
 			    device_xname(MVSATA_DEV2(mvport)),
 			    mvport->port_hc->hc, mvport->port);

Reply via email to