CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Oct 21 18:13:14 UTC 2018

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

Log Message:
decouple siisata_reset_channel() from siisata_reinit_port(); the former
now needs channel lock, but we don't have it in siisata_init_port()
during attach

instead call siisata_reset_channel() when siisata_reinit_port() fails,
and ignore the error during attach


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.10 -r1.35.6.11 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/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.35.6.10 src/sys/dev/ic/siisata.c:1.35.6.11
--- src/sys/dev/ic/siisata.c:1.35.6.10	Mon Oct 15 21:18:53 2018
+++ src/sys/dev/ic/siisata.c	Sun Oct 21 18:13:14 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.35.6.10 2018/10/15 21:18:53 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.35.6.11 2018/10/21 18:13:14 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.10 2018/10/15 21:18:53 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.11 2018/10/21 18:13:14 jdolecek Exp $");
 
 #include 
 #include 
@@ -162,7 +162,7 @@ void siisata_bio_abort(struct ata_channe
 void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
 int siisata_exec_command(struct ata_drive_datas *, struct ata_xfer *);
 
-static void siisata_reinit_port(struct ata_channel *, int);
+static int siisata_reinit_port(struct ata_channel *, int);
 static void siisata_device_reset(struct ata_channel *);
 static void siisata_activate_prb(struct siisata_channel *, int);
 static void siisata_deactivate_prb(struct siisata_channel *, int);
@@ -261,11 +261,12 @@ siisata_enable_port_interrupt(struct ata
 	PR_PIS_CMDERRR | PR_PIS_CMDCMPL);
 }
 
-static void
+static int
 siisata_init_port(struct siisata_softc *sc, int port)
 {
 	struct siisata_channel *schp;
 	struct ata_channel *chp;
+	int error;
 
 	schp = &sc->sc_channels[port];
 	chp = (struct ata_channel *)schp;
@@ -277,11 +278,13 @@ siisata_init_port(struct siisata_softc *
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC),
 	PR_PC_32BA | PR_PC_INCOR | PR_PC_PORT_RESET);
 	/* initialize port */
-	siisata_reinit_port(chp, -1);
+	error = siisata_reinit_port(chp, -1);
 	/* enable CmdErrr+CmdCmpl interrupting */
 	siisata_enable_port_interrupt(chp);
 	/* enable port interrupt */
 	GRWRITE(sc, GR_GC, GRREAD(sc, GR_GC) | GR_GC_PXIE(chp->ch_channel));
+
+	return error;
 }
 
 static void
@@ -398,7 +401,7 @@ siisata_attach_port(struct siisata_softc
 		return;
 	}
 
-	siisata_init_port(sc, port);
+	(void)siisata_init_port(sc, port);
 
 	ata_channel_attach(chp);
 
@@ -450,15 +453,22 @@ siisata_detach(struct siisata_softc *sc,
 void
 siisata_resume(struct siisata_softc *sc)
 {
-	int i;
-
 	/* come out of reset state */
 	GRWRITE(sc, GR_GC, 0);
 
-	for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
-		siisata_init_port(sc, i);
-	}
+	for (int port = 0; port < sc->sc_atac.atac_nchannels; port++) {
+		int error;
+
+		error = siisata_init_port(sc, port);
+		if (error) {
+			struct siisata_channel *schp = &sc->sc_channels[port];
+			struct ata_channel *chp = (struct ata_channel *)schp;
 
+			ata_channel_lock(chp);
+			siisata_reset_channel(chp, AT_POLL);
+			ata_channel_unlock(chp);
+		}
+	}
 }
 
 int
@@ -625,7 +635,7 @@ siisata_channel_recover(struct ata_chann
 	}
 
 	KASSERT(drive >= 0);
-	siisata_reinit_port(chp, drive);
+	(void)siisata_reinit_port(chp, drive);
 
 	ata_recovery_resume(chp, drive, tfd, flags);
 
@@ -648,7 +658,8 @@ siisata_reset_drive(struct ata_drive_dat
 
 	ata_channel_lock_owned(chp);
 
-	siisata_reinit_port(chp, drvp->drive);
+	if (siisata_reinit_port(chp, drvp->drive))
+		siisata_reset_channel(chp, flags);
 
 	/* get a slot for running the command on */
 	if (!ata_queue_alloc_slot(chp, &c_slot, ATA_MAX_OPENINGS)) {
@@ -815,7 +826,8 @@ siisata_probe_drive(struct ata_channel *
 			aprint_error_dev(sc->sc_atac.atac_dev,
 			"timed out waiting for PORT_READY on port %d, " 
 			"reinitializing\n", chp->ch_channel);
-			siisata_reinit_port(chp, -1);
+			if (siisata_reinit_port(chp, -1))
+siisata_reset_channel(chp, AT_WAIT);
 		}
 
 		prb = schp->sch_prb[c_slot];
@@ -851,7 +863,8 @@ siisata_probe_drive(struct ata_channel *
 			PRREAD(sc, PRX(chp->ch_channel, PRO_PCE)),
 			PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)),
 			PRREAD(sc, PRX(chp->ch_channel, PRO_PIS)));
-			siisata_reinit_port(chp, -1);
+			if (siisata_reinit_port(chp, -1))
+siisata_reset_channel(chp, AT_WAIT);
 			break;
 		}
 
@@ -1427,12 +1440,12 @@ siisata_deactivate_prb(struct siisata_ch
 	SIISATA_PRB_SYNC(sc, schp, slot, BUS_DMASYNC_POSTWRITE);
 }
 
-static void
+static int
 siisata_reinit_port(struct ata_channel *chp, int drive)
 {
 	struct siisata_softc *sc = (struct siisata_softc *)c

CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Oct 13 09:31:46 UTC 2018

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

Log Message:
make compile again with MVSATA_WITHOUTDMA


To generate a diff of this commit:
cvs rdiff -u -r1.41.2.8 -r1.41.2.9 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.41.2.8 src/sys/dev/ic/mvsata.c:1.41.2.9
--- src/sys/dev/ic/mvsata.c:1.41.2.8	Sat Oct 13 07:23:34 2018
+++ src/sys/dev/ic/mvsata.c	Sat Oct 13 09:31:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.41.2.8 2018/10/13 07:23:34 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.41.2.9 2018/10/13 09:31:46 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.8 2018/10/13 07:23:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.9 2018/10/13 09:31:46 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -107,9 +107,9 @@ int	mvsata_debug = 0;
 
 
 static void mvsata_probe_drive(struct ata_channel *);
-static void mvsata_reset_channel(struct ata_channel *, int);
 
 #ifndef MVSATA_WITHOUTDMA
+static void mvsata_reset_channel(struct ata_channel *, int);
 static int mvsata_bio(struct ata_drive_datas *, struct ata_xfer *);
 static void mvsata_reset_drive(struct ata_drive_datas *, int, uint32_t *);
 static int mvsata_exec_command(struct ata_drive_datas *, struct ata_xfer *);
@@ -651,7 +651,6 @@ mvsata_reset_drive(struct ata_drive_data
 		mvsata_edma_enable(mvport);
 	}
 }
-#endif /* MVSATA_WITHOUTDMA */
 
 static void
 mvsata_reset_channel(struct ata_channel *chp, int flags)
@@ -689,14 +688,11 @@ mvsata_reset_channel(struct ata_channel 
 
 	ata_kill_active(chp, KILL_RESET, flags);
 
-#ifndef MVSATA_WITHOUTDMA
 	mvsata_edma_config(mvport, mvport->port_edmamode_curr);
 	mvsata_edma_reset_qptr(mvport);
 	mvsata_edma_enable(mvport);
-#endif
 }
 
-#ifndef MVSATA_WITHOUTDMA
 static int
 mvsata_addref(struct ata_drive_datas *drvp)
 {
@@ -896,23 +892,19 @@ mvsata_atapi_kill_pending(struct scsipi_
 static void
 mvsata_setup_channel(struct ata_channel *chp)
 {
-#if !defined(MVSATA_WITHOUTDMA) || defined(MVSATA_DEBUG)
+#ifndef MVSATA_WITHOUTDMA
 	struct mvsata_port *mvport = (struct mvsata_port *)chp;
-#endif
 	struct ata_drive_datas *drvp;
-	uint32_t edma_mode;
 	int drive, s;
-#ifndef MVSATA_WITHOUTDMA
+	uint32_t edma_mode = nodma;
 	int i;
 	const int crqb_size = sizeof(union mvsata_crqb) * MVSATA_EDMAQ_LEN;
 	const int crpb_size = sizeof(struct crpb) * MVSATA_EDMAQ_LEN;
 	const int eprd_buf_size = MVSATA_EPRD_MAX_SIZE * MVSATA_EDMAQ_LEN;
-#endif
 
 	DPRINTF(DEBUG_FUNCS, ("%s:%d: mvsata_setup_channel: ",
 	device_xname(MVSATA_DEV2(mvport)), chp->ch_channel));
 
-	edma_mode = nodma;
 	for (drive = 0; drive < chp->ch_ndrives; drive++) {
 		drvp = &chp->ch_drive[drive];
 
@@ -938,7 +930,6 @@ mvsata_setup_channel(struct ata_channel 
 	DPRINTF(DEBUG_FUNCS,
 	("EDMA %sactive mode\n", (edma_mode == nodma) ? "not " : ""));
 
-#ifndef MVSATA_WITHOUTDMA
 	if (edma_mode == nodma) {
 no_edma:
 		if (mvport->port_crqb != NULL)



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Oct 13 07:23:34 UTC 2018

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

Log Message:
add C_TIMEOUT KASSERT() on fail path of mvsata_bio_poll() for clarity


To generate a diff of this commit:
cvs rdiff -u -r1.41.2.7 -r1.41.2.8 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.41.2.7 src/sys/dev/ic/mvsata.c:1.41.2.8
--- src/sys/dev/ic/mvsata.c:1.41.2.7	Thu Oct 11 20:57:51 2018
+++ src/sys/dev/ic/mvsata.c	Sat Oct 13 07:23:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.41.2.7 2018/10/11 20:57:51 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.41.2.8 2018/10/13 07:23:34 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.7 2018/10/11 20:57:51 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.8 2018/10/13 07:23:34 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1281,8 +1281,10 @@ mvsata_bio_poll(struct ata_channel *chp,
 		chp->ch_flags &= ~ATACH_DMA_WAIT;
 	}
 
-	if ((xfer->c_bio.flags & ATA_ITSDONE) == 0)
+	if ((xfer->c_bio.flags & ATA_ITSDONE) == 0) {
+		KASSERT(xfer->c_flags & C_TIMEOU);
 		mvsata_bio_intr(chp, xfer, 0);
+	}
 }
 
 static int



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-07 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Oct  7 15:44:48 UTC 2018

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

Log Message:
move atastart() call after xfer deactivation during ATA command completion,
so that it's executed after the slot is freed


To generate a diff of this commit:
cvs rdiff -u -r1.62.2.7 -r1.62.2.8 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.62.2.7 src/sys/dev/ic/ahcisata_core.c:1.62.2.8
--- src/sys/dev/ic/ahcisata_core.c:1.62.2.7	Thu Oct  4 17:59:35 2018
+++ src/sys/dev/ic/ahcisata_core.c	Sun Oct  7 15:44:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.62.2.7 2018/10/04 17:59:35 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.62.2.8 2018/10/07 15:44:47 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.7 2018/10/04 17:59:35 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.8 2018/10/07 15:44:47 jdolecek Exp $");
 
 #include 
 #include 
@@ -1233,6 +1233,9 @@ ahci_cmd_complete(struct ata_channel *ch
 	achp->ahcic_cmds_active &= ~(1U << xfer->c_slot);
 	ata_deactivate_xfer(chp, xfer);
 
+	if ((ata_c->flags & (AT_TIMEOU|AT_ERROR)) == 0)
+		atastart(chp);
+
 	return 0;
 }
 
@@ -1243,7 +1246,6 @@ ahci_cmd_done(struct ata_channel *chp, s
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 	struct ata_command *ata_c = &xfer->c_ata_c;
 	uint16_t *idwordbuf;
-	int flags = ata_c->flags;
 	int i;
 
 	AHCIDEBUG_PRINT(("ahci_cmd_done channel %d flags %#x/%#x\n",
@@ -1273,9 +1275,6 @@ ahci_cmd_done(struct ata_channel *chp, s
 		ata_c->flags |= AT_XFDONE;
 
 	ahci_cmd_done_end(chp, xfer);
-
-	if ((flags & (AT_TIMEOU|AT_ERROR)) == 0)
-		atastart(chp);
 }
 
 static void



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-07 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Oct  7 15:42:47 UTC 2018

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

Log Message:
call atastart() when ATA command completes without timeout or error, similar
to AHCI


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.7 -r1.35.6.8 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/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.35.6.7 src/sys/dev/ic/siisata.c:1.35.6.8
--- src/sys/dev/ic/siisata.c:1.35.6.7	Thu Oct  4 17:59:35 2018
+++ src/sys/dev/ic/siisata.c	Sun Oct  7 15:42:47 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.35.6.7 2018/10/04 17:59:35 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.35.6.8 2018/10/07 15:42:47 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.7 2018/10/04 17:59:35 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.8 2018/10/07 15:42:47 jdolecek Exp $");
 
 #include 
 #include 
@@ -1180,6 +1180,9 @@ siisata_cmd_complete(struct ata_channel 
 	siisata_deactivate_prb(schp, xfer->c_slot);
 	ata_deactivate_xfer(chp, xfer);
 
+	if ((ata_c->flags & (AT_TIMEOU|AT_ERROR)) == 0)
+		atastart(chp);
+
 	return 0;
 }
 



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-10-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Oct  4 17:59:35 UTC 2018

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

Log Message:
further channel locking pass for reset


To generate a diff of this commit:
cvs rdiff -u -r1.62.2.6 -r1.62.2.7 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.41.2.5 -r1.41.2.6 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.35.6.6 -r1.35.6.7 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.6 src/sys/dev/ic/ahcisata_core.c:1.62.2.7
--- src/sys/dev/ic/ahcisata_core.c:1.62.2.6	Wed Oct  3 19:20:48 2018
+++ src/sys/dev/ic/ahcisata_core.c	Thu Oct  4 17:59:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.62.2.6 2018/10/03 19:20:48 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.62.2.7 2018/10/04 17:59:35 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.6 2018/10/03 19:20:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.7 2018/10/04 17:59:35 jdolecek Exp $");
 
 #include 
 #include 
@@ -885,7 +885,7 @@ ahci_reset_channel(struct ata_channel *c
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 	int i, tfd;
 
-	ata_channel_lock(chp);
+	ata_channel_lock_owned(chp);
 
 	ahci_channel_stop(sc, chp, flags);
 	if (sata_reset_interface(chp, sc->sc_ahcit, achp->ahcic_scontrol,
@@ -915,8 +915,6 @@ ahci_reset_channel(struct ata_channel *c
 	/* clear port interrupt register */
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), 0x);
 
-	ata_channel_unlock(chp);
-
 	return;
 }
 
@@ -1709,7 +1707,9 @@ ahci_channel_recover(struct ahci_softc *
 		 * transfers.
 		 */
 reset:
+		ata_channel_lock(chp);
 		ahci_reset_channel(chp, AT_POLL);
+		ata_channel_unlock(chp);
 		goto out;
 		/* NOTREACHED */
 

Index: src/sys/dev/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.41.2.5 src/sys/dev/ic/mvsata.c:1.41.2.6
--- src/sys/dev/ic/mvsata.c:1.41.2.5	Wed Oct  3 19:20:48 2018
+++ src/sys/dev/ic/mvsata.c	Thu Oct  4 17:59:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.41.2.5 2018/10/03 19:20:48 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.41.2.6 2018/10/04 17:59:35 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.5 2018/10/03 19:20:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.41.2.6 2018/10/04 17:59:35 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -635,7 +635,9 @@ mvsata_channel_recover(struct mvsata_por
 		 * reset the drive. This will also kill all still outstanding
 		 * transfers.
 		 */
+		ata_channel_lock(chp);
 		mvsata_reset_channel(chp, AT_POLL);
+		ata_channel_unlock(chp);
 		goto out;
 		/* NOTREACHED */
 

Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.35.6.6 src/sys/dev/ic/siisata.c:1.35.6.7
--- src/sys/dev/ic/siisata.c:1.35.6.6	Wed Oct  3 19:20:48 2018
+++ src/sys/dev/ic/siisata.c	Thu Oct  4 17:59:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.35.6.6 2018/10/03 19:20:48 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.35.6.7 2018/10/04 17:59:35 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.6 2018/10/03 19:20:48 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.35.6.7 2018/10/04 17:59:35 jdolecek Exp $");
 
 #include 
 #include 
@@ -686,7 +686,9 @@ siisata_channel_recover(struct ata_chann
 		 * transfers.
 		 */
 reset:
+		ata_channel_lock(chp);
 		siisata_device_reset(chp);
+		ata_channel_unlock(chp);
 		goto out;
 		/* NOTREACHED */
 
@@ -730,10 +732,10 @@ siisata_reset_drive(struct ata_drive_dat
 	int i;
 	bool timed_out;
 
-	siisata_reinit_port(chp, drvp->drive);
-
 	ata_channel_lock_owned(chp);
 
+	siisata_reinit_port(chp, drvp->drive);
+
 	/* get a slot for running the command on */
 	if (!ata_queue_alloc_slot(chp, &c_slot, ATA_MAX_OPENINGS)) {
 		panic("%s: %s: failed to get xfer for reset, port %d\n",
@@ -1556,7 +1558,9 @@ siisata_reinit_port(struct ata_channel *
 	}
 	if ((ps & PR_PS_PORT_READY) == 0) {
 		printf("%s: timeout waiting for port to be ready\n", __func__);
+		ata_channel_lock(chp);
 		siisata_reset_channel(chp, AT_POLL);
+		ata_channel_unlock(chp);
 	}
 
 	if (chp->ch_ndrives > 1)



CVS commit: [jdolecek-ncqfixes] src/sys/dev/ic

2018-09-01 Thread Jaromir Dolecek
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 
-__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 
 #include 
@@ -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 
-__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 
 #include 
@@ -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;
 	}
 	SIISA