Module Name:    src
Committed By:   jdolecek
Date:           Mon Apr 24 15:15:02 UTC 2017

Modified Files:
        src/sys/dev/ata [jdolecek-ncq]: TODO.ncq
        src/sys/dev/ic [jdolecek-ncq]: ahcisata_core.c

Log Message:
do not use PRD Byte Count for queued commands to determine number of bytes
actually transferred; it should not be used and is not guaranteed to be
valid according to AHCI spec, underflow is always invalid for queued cmds

this fixes my ls problem under QEMU


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.9 -r1.1.2.10 src/sys/dev/ata/TODO.ncq
cvs rdiff -u -r1.57.6.9 -r1.57.6.10 src/sys/dev/ic/ahcisata_core.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/ata/TODO.ncq
diff -u src/sys/dev/ata/TODO.ncq:1.1.2.9 src/sys/dev/ata/TODO.ncq:1.1.2.10
--- src/sys/dev/ata/TODO.ncq:1.1.2.9	Mon Apr 24 10:46:42 2017
+++ src/sys/dev/ata/TODO.ncq	Mon Apr 24 15:15:02 2017
@@ -1,11 +1,6 @@
 Bugs
 ----
 
-under QEMU, the mounted AHCI drive doesn't show directories for ls,
-but cd, mkdir, stat and creating files wroks just fine - what do?
-- https://lists.freebsd.org/pipermail/freebsd-current/2011-September/027294.html
-- somewhat critical since we use QEMU for babylon builds
-
 mvsata, siisata - fix all 'XXX slot' 
 
 test wd* at umass?, confirm the ata_channel kludge works

Index: src/sys/dev/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.57.6.9 src/sys/dev/ic/ahcisata_core.c:1.57.6.10
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.9	Mon Apr 24 10:21:15 2017
+++ src/sys/dev/ic/ahcisata_core.c	Mon Apr 24 15:15:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.9 2017/04/24 10:21:15 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.10 2017/04/24 15:15:02 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.9 2017/04/24 10:21:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.10 2017/04/24 15:15:02 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -1331,14 +1331,20 @@ ahci_bio_complete(struct ata_channel *ch
 	AHCIDEBUG_PRINT(("ahci_bio_complete bcount %ld",
 	    ata_bio->bcount), DEBUG_XFERS);
 	/* 
-	 * if it was a write, complete data buffer may have been transfered
+	 * If it was a write, complete data buffer may have been transfered
 	 * before error detection; in this case don't use cmdh_prdbc
 	 * as it won't reflect what was written to media. Assume nothing
 	 * was transfered and leave bcount as-is.
+	 * For queued commands, PRD Byte Count should not be used, and is
+	 * not required to be valid; in that case underflow is always illegal.
 	 */
-	if ((ata_bio->flags & ATA_READ) || ata_bio->error == NOERROR)
+	if ((xfer->c_flags & C_NCQ) != 0) {
+		ata_bio->bcount = 0;
+	} else {
+	    if ((ata_bio->flags & ATA_READ) || ata_bio->error == NOERROR)
 		ata_bio->bcount -=
 		    le32toh(achp->ahcic_cmdh[xfer->c_slot].cmdh_prdbc);
+	}
 	AHCIDEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS);
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer);
 	atastart(chp);

Reply via email to