Module Name:    src
Committed By:   martin
Date:           Tue Dec 24 17:34:33 UTC 2019

Modified Files:
        src/sys/dev/ic [netbsd-9]: ahcisata_core.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #576):

        sys/dev/ic/ahcisata_core.c: revision 1.79

When resetting a drive, if the command list is running and CLO is not
supported, attempt to stop the drive first and fail gracefully if that
fails instead of triggering a KASSERT on DIAGNOSTIC kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.75.4.1 -r1.75.4.2 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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.75.4.1 src/sys/dev/ic/ahcisata_core.c:1.75.4.2
--- src/sys/dev/ic/ahcisata_core.c:1.75.4.1	Wed Oct 23 18:06:46 2019
+++ src/sys/dev/ic/ahcisata_core.c	Tue Dec 24 17:34:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.75.4.1 2019/10/23 18:06:46 martin Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.75.4.2 2019/12/24 17:34:33 martin Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.75.4.1 2019/10/23 18:06:46 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.75.4.2 2019/12/24 17:34:33 martin Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -807,7 +807,7 @@ ahci_do_reset_drive(struct ata_channel *
 	struct ahci_cmd_tbl *cmd_tbl;
 	struct ahci_cmd_header *cmd_h;
 	int i, error = 0;
-	uint32_t sig;
+	uint32_t sig, cmd;
 	int noclo_retry = 0;
 
 	ata_channel_lock_owned(chp);
@@ -825,6 +825,19 @@ again:
 		ahci_channel_start(sc, chp, flags, 1);
 	} else {
 		/* Can't handle command still running without CLO */
+		cmd = AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel));
+		if ((cmd & AHCI_P_CMD_CR) != 0) {
+			ahci_channel_stop(sc, chp, flags);
+			cmd = AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel));
+			if ((cmd & AHCI_P_CMD_CR) != 0) {
+				aprint_error("%s port %d: DMA engine busy "
+				    "for drive %d\n", AHCINAME(sc),
+				    chp->ch_channel, drive);
+				error = EBUSY;
+				goto end;
+			}
+		}
+
 		KASSERT((AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) & AHCI_P_CMD_CR) == 0);
 
 		ahci_channel_start(sc, chp, flags, 0);

Reply via email to