Module Name:    src
Committed By:   jdolecek
Date:           Sat Sep  1 10:13:41 UTC 2018

Modified Files:
        src/sys/dev/ic [jdolecek-ncqfixes]: ahcisata_core.c siisata.c

Log Message:
only call ata_deactivate_xfer() once completely done with the active
xfer in controller code (i.e. after bus_dmamap_sync() et.al.), so that
the command slot is safe to be reused immediatelly after deactivate


To generate a diff of this commit:
cvs rdiff -u -r1.62.2.1 -r1.62.2.2 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.35.6.1 -r1.35.6.2 src/sys/dev/ic/siisata.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/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.62.2.1 src/sys/dev/ic/ahcisata_core.c:1.62.2.2
--- src/sys/dev/ic/ahcisata_core.c:1.62.2.1	Fri Aug 31 19:08:03 2018
+++ src/sys/dev/ic/ahcisata_core.c	Sat Sep  1 10:13:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.62.2.1 2018/08/31 19:08:03 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.62.2.2 2018/09/01 10:13:41 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.1 2018/08/31 19:08:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.2 2018/09/01 10:13:41 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -1206,9 +1206,6 @@ ahci_cmd_complete(struct ata_channel *ch
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
-	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
-
 	if (xfer->c_flags & C_TIMEOU) {
 		ata_c->flags |= AT_TIMEOU;
 	}
@@ -1225,6 +1222,8 @@ ahci_cmd_complete(struct ata_channel *ch
 
 	ahci_cmd_done(chp, xfer);
 
+	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
+	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
 	ata_deactivate_xfer(chp, xfer);
 
 	return 0;
@@ -1453,10 +1452,6 @@ ahci_bio_complete(struct ata_channel *ch
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
-	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
-	ata_deactivate_xfer(chp, xfer);
-
 	if (xfer->c_flags & C_TIMEOU) {
 		ata_bio->error = TIMEOUT;
 	}
@@ -1497,6 +1492,11 @@ ahci_bio_complete(struct ata_channel *ch
 			    le32toh(achp->ahcic_cmdh[xfer->c_slot].cmdh_prdbc);
 	}
 	AHCIDEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS);
+
+	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
+	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
+	ata_deactivate_xfer(chp, xfer);
+
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer);
 	if ((AHCI_TFD_ST(tfd) & WDCS_ERR) == 0)
 		atastart(chp);
@@ -1997,10 +1997,6 @@ ahci_atapi_complete(struct ata_channel *
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
-	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
-	ata_deactivate_xfer(chp, xfer);
-
 	if (xfer->c_flags & C_TIMEOU) {
 		sc_xfer->error = XS_TIMEOUT;
 	}
@@ -2030,7 +2026,12 @@ ahci_atapi_complete(struct ata_channel *
 			sc_xfer->error = XS_BUSY;
 			sc_xfer->status = SCSI_CHECK;
 		}
-	} 
+	}
+
+	KASSERT((achp->ahcic_cmds_active & (1U << xfer->c_slot)) != 0);
+	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
+	ata_deactivate_xfer(chp, xfer);
+
 	ata_free_xfer(chp, xfer);
 	scsipi_done(sc_xfer);
 	if ((AHCI_TFD_ST(tfd) & WDCS_ERR) == 0)

Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.35.6.1 src/sys/dev/ic/siisata.c:1.35.6.2
--- src/sys/dev/ic/siisata.c:1.35.6.1	Fri Aug 31 19:08:03 2018
+++ src/sys/dev/ic/siisata.c	Sat Sep  1 10:13:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.35.6.1 2018/08/31 19:08:03 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.35.6.2 2018/09/01 10:13:41 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.1 2018/08/31 19:08:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.2 2018/09/01 10:13:41 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1154,8 +1154,6 @@ siisata_cmd_complete(struct ata_channel 
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	siisata_deactivate_prb(schp, xfer->c_slot);
-
 	if (xfer->c_flags & C_TIMEOU)
 		ata_c->flags |= AT_TIMEOU;
 
@@ -1168,6 +1166,7 @@ siisata_cmd_complete(struct ata_channel 
 
 	siisata_cmd_done(chp, xfer, tfd);
 
+	siisata_deactivate_prb(schp, xfer->c_slot);
 	ata_deactivate_xfer(chp, xfer);
 
 	return 0;
@@ -1382,9 +1381,6 @@ siisata_bio_complete(struct ata_channel 
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	siisata_deactivate_prb(schp, xfer->c_slot);
-	ata_deactivate_xfer(chp, xfer);
-
 	if (xfer->c_flags & C_TIMEOU) {
 		ata_bio->error = TIMEOUT;
 	}
@@ -1414,6 +1410,10 @@ siisata_bio_complete(struct ata_channel 
 			ata_bio->bcount = 0;
 	}
 	SIISATA_DEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS);
+
+	siisata_deactivate_prb(schp, xfer->c_slot);
+	ata_deactivate_xfer(chp, xfer);
+
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer);
 	if ((ATACH_ST(tfd) & WDCS_ERR) == 0)
 		atastart(chp);
@@ -1949,10 +1949,6 @@ siisata_atapi_complete(struct ata_channe
 	if (ata_waitdrain_xfer_check(chp, xfer))
 		return 0;
 
-	/* this command is not active any more */
-	siisata_deactivate_prb(schp, xfer->c_slot);
-	ata_deactivate_xfer(chp, xfer);
-
 	if (xfer->c_flags & C_TIMEOU) {
 		sc_xfer->error = XS_TIMEOUT;
 	}
@@ -1980,6 +1976,10 @@ siisata_atapi_complete(struct ata_channe
 			sc_xfer->status = SCSI_CHECK;
 		}
 	}
+
+	siisata_deactivate_prb(schp, xfer->c_slot);
+	ata_deactivate_xfer(chp, xfer);
+
 	ata_free_xfer(chp, xfer);
 	scsipi_done(sc_xfer);
 	if ((ATACH_ST(tfd) & WDCS_ERR) == 0)

Reply via email to