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

2017-09-26 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Sep 26 17:05:37 UTC 2017

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

Log Message:
make compile without MVSATA_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.29 -r1.35.6.30 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.35.6.29 src/sys/dev/ic/mvsata.c:1.35.6.30
--- src/sys/dev/ic/mvsata.c:1.35.6.29	Mon Sep 25 22:50:20 2017
+++ src/sys/dev/ic/mvsata.c	Tue Sep 26 17:05:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.29 2017/09/25 22:50:20 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.30 2017/09/26 17:05:37 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.29 2017/09/25 22:50:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.30 2017/09/26 17:05:37 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1673,7 +1673,6 @@ static int
 mvsata_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
 	struct ata_channel *chp = drvp->chnl_softc;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	struct ata_command *ata_c = >c_ata_c;
 	int rv, s;
 
@@ -1681,7 +1680,8 @@ mvsata_exec_command(struct ata_drive_dat
 	("%s:%d: mvsata_exec_command: drive=%d, bcount=%d,"
 	" r_lba=0x%012"PRIx64", r_count=0x%04x, r_features=0x%04x,"
 	" r_device=0x%02x, r_command=0x%02x\n",
-	device_xname(MVSATA_DEV2(mvport)), chp->ch_channel,
+	device_xname(MVSATA_DEV2((struct mvsata_port *)chp)),
+	chp->ch_channel,
 	drvp->drive, ata_c->bcount, ata_c->r_lba, ata_c->r_count,
 	ata_c->r_features, ata_c->r_device, ata_c->r_command));
 



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

2017-09-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 25 22:50:20 UTC 2017

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

Log Message:
move mvsata_quetag_get() to the start routines, so that it always matches
the active list of ata queue; important during error recovery, fixes
panics when calling

in mvsata_edma_handle() ignore events for non-active xfers

fix some missing ata_channel_unlock() on error path in mvsata_bio_intr()
and mvsata_atapi_intr(), fixes 'locking against myself' with LOCKDEBUG

with this, mvsata(4) finally survives full fio run with wdcdebug_wd_cnt == 200


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.28 -r1.35.6.29 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.35.6.28 src/sys/dev/ic/mvsata.c:1.35.6.29
--- src/sys/dev/ic/mvsata.c:1.35.6.28	Fri Sep 22 20:19:08 2017
+++ src/sys/dev/ic/mvsata.c	Mon Sep 25 22:50:20 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.28 2017/09/22 20:19:08 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.29 2017/09/25 22:50:20 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.28 2017/09/22 20:19:08 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.29 2017/09/25 22:50:20 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1086,7 +1086,6 @@ static int
 mvsata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
 	struct ata_channel *chp = drvp->chnl_softc;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	struct atac_softc *atac = chp->ch_atac;
 	struct ata_bio *ata_bio = >c_bio;
 
@@ -1095,8 +1094,6 @@ mvsata_bio(struct ata_drive_datas *drvp,
 	", bcount=%ld\n", device_xname(atac->atac_dev), chp->ch_channel,
 	drvp->drive, ata_bio->blkno, ata_bio->bcount));
 
-	mvsata_quetag_get(mvport, xfer->c_slot);
-
 	if (atac->atac_cap & ATAC_CAP_NOIRQ)
 		ata_bio->flags |= ATA_POLL;
 	if (ata_bio->flags & ATA_POLL)
@@ -1135,6 +1132,8 @@ mvsata_bio_start(struct ata_channel *chp
 
 	ata_channel_lock_owned(chp);
 
+	mvsata_quetag_get(mvport, xfer->c_slot);
+
 	if (xfer->c_flags & C_DMA)
 		if (drvp->n_xfers <= NXFER)
 			drvp->n_xfers++;
@@ -1410,8 +1409,10 @@ mvsata_bio_intr(struct ata_channel *chp,
 	if (!(xfer->c_flags & C_DMA) &&
 	(wdc_wait_for_unbusy(chp, (irq == 0) ? ATA_DELAY : 0, AT_POLL, )
 			== WDCWAIT_TOUT)) {
-		if (irq && (xfer->c_flags & C_TIMEOU) == 0)
+		if (irq && (xfer->c_flags & C_TIMEOU) == 0) {
+			ata_channel_unlock(chp);
 			return 0;	/* IRQ was not for us */
+		}
 		aprint_error_dev(atac->atac_dev,
 		"channel %d: drive %d timeout, c_bcount=%d, c_skip%d\n",
 		chp->ch_channel, xfer->c_drive, xfer->c_bcount,
@@ -1570,6 +1571,8 @@ mvsata_bio_ready(struct mvsata_port *mvp
 
 	flags |= AT_POLL;	/* XXX */
 
+	ata_channel_lock_owned(chp);
+
 	/*
 	 * disable interrupts, all commands here should be quick
 	 * enough to be able to poll, and we don't go here that often
@@ -1682,8 +1685,6 @@ mvsata_exec_command(struct ata_drive_dat
 	drvp->drive, ata_c->bcount, ata_c->r_lba, ata_c->r_count,
 	ata_c->r_features, ata_c->r_device, ata_c->r_command));
 
-	mvsata_quetag_get(mvport, xfer->c_slot);
-
 	if (ata_c->flags & AT_POLL)
 		xfer->c_flags |= C_POLL;
 	if (ata_c->flags & AT_WAIT)
@@ -1736,6 +1737,8 @@ mvsata_wdc_cmd_start(struct ata_channel 
 
 	ata_channel_lock_owned(chp);
 
+	mvsata_quetag_get(mvport, xfer->c_slot);
+
 	/* First, EDMA disable, if enabled this channel. */
 	KASSERT((chp->ch_flags & ATACH_NCQ) == 0);
 	if (mvport->port_edmamode_curr != nodma)
@@ -2050,7 +2053,6 @@ mvsata_atapi_scsipi_request(struct scsip
 	struct atac_softc *atac = >sc_wdcdev.sc_atac;
 	struct ata_channel *chp = atac->atac_channels[chan->chan_channel];
 	struct ata_xfer *xfer;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	int drive, s;
 
 switch (req) {
@@ -2071,8 +2073,6 @@ mvsata_atapi_scsipi_request(struct scsip
 			return;
 		}
 
-		mvsata_quetag_get(mvport, xfer->c_slot);
-
 		if (sc_xfer->xs_control & XS_CTL_POLL)
 			xfer->c_flags |= C_POLL;
 		xfer->c_drive = drive;
@@ -2122,6 +2122,8 @@ mvsata_atapi_start(struct ata_channel *c
 
 	ata_channel_lock_owned(chp);
 
+	mvsata_quetag_get(mvport, xfer->c_slot);
+
 	KASSERT((chp->ch_flags  & ATACH_NCQ) == 0);
 	if (mvport->port_edmamode_curr != nodma)
 		mvsata_edma_disable(mvport, 10 /* ms */, wait_flags);
@@ -2426,6 +2428,7 @@ again:
 			if (xfer->c_flags & C_DMA)
 ata_dmaerr(drvp,
 (xfer->c_flags & C_POLL) ? AT_POLL : 0);
+			ata_channel_unlock(chp);
 			sc_xfer->error = XS_TIMEOUT;
 			mvsata_atapi_reset(chp, xfer);
 			return 1;
@@ -2883,8 +2886,15 @@ mvsata_edma_handle(struct mvsata_port *m
 			mvsata_print_crpb(mvport, erpqop);
 #endif
 		crpb = mvport->port_crpb + erpqop;
+		

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

2017-09-22 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Sep 22 20:19:08 UTC 2017

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

Log Message:
fix inverted logic for calling atastart()


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.27 -r1.35.6.28 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.35.6.27 src/sys/dev/ic/mvsata.c:1.35.6.28
--- src/sys/dev/ic/mvsata.c:1.35.6.27	Wed Sep 20 18:35:37 2017
+++ src/sys/dev/ic/mvsata.c	Fri Sep 22 20:19:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.27 2017/09/20 18:35:37 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.28 2017/09/22 20:19:08 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.27 2017/09/20 18:35:37 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.28 2017/09/22 20:19:08 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1529,7 +1529,7 @@ mvsata_bio_done(struct ata_channel *chp,
 	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	struct ata_bio *ata_bio = >c_bio;
 	int drive = xfer->c_drive;
-	bool iserror = (ata_bio->error == NOERROR);
+	bool iserror = (ata_bio->error != NOERROR);
 
 	DPRINTF(DEBUG_FUNCS|DEBUG_XFERS,
 	("%s:%d: mvsata_bio_done: drive=%d, flags=0x%x\n",
@@ -2689,7 +2689,7 @@ mvsata_atapi_done(struct ata_channel *ch
 {
 	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	struct scsipi_xfer *sc_xfer = xfer->c_scsipi;
-	bool iserror = (sc_xfer->error == XS_NOERROR);
+	bool iserror = (sc_xfer->error != XS_NOERROR);
 
 	DPRINTF(DEBUG_FUNCS|DEBUG_XFERS,
 	("%s:%d:%d: mvsata_atapi_done: flags 0x%x\n",



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

2017-09-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Sep 20 18:35:37 UTC 2017

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

Log Message:
make compile again with MVSATA_WITHOUTDMA


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.26 -r1.35.6.27 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.35.6.26 src/sys/dev/ic/mvsata.c:1.35.6.27
--- src/sys/dev/ic/mvsata.c:1.35.6.26	Tue Sep 19 21:06:25 2017
+++ src/sys/dev/ic/mvsata.c	Wed Sep 20 18:35:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.26 2017/09/19 21:06:25 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.27 2017/09/20 18:35:37 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.26 2017/09/19 21:06:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.27 2017/09/20 18:35:37 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -107,10 +107,11 @@ 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 int mvsata_bio(struct ata_drive_datas *, struct ata_xfer *);
 static void mvsata_reset_drive(struct ata_drive_datas *, int, uint32_t *);
-static void mvsata_reset_channel(struct ata_channel *, int);
 static int mvsata_exec_command(struct ata_drive_datas *, struct ata_xfer *);
 static int mvsata_addref(struct ata_drive_datas *);
 static void mvsata_delref(struct ata_drive_datas *);
@@ -731,6 +732,7 @@ mvsata_reset_drive(struct ata_drive_data
 
 	return;
 }
+#endif /* MVSATA_WITHOUTDMA */
 
 static void
 mvsata_reset_channel(struct ata_channel *chp, int flags)
@@ -768,16 +770,18 @@ 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
 
 	ata_channel_unlock(chp);
 
 	return;
 }
 
-
+#ifndef MVSATA_WITHOUTDMA
 static int
 mvsata_addref(struct ata_drive_datas *drvp)
 {



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

2017-09-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Sep 19 17:52:52 UTC 2017

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

Log Message:
seems the CMD/CCS slot is always zero at least under QEMU for successful
polled commands, so go back to using it only on error path; while the value
seems good on real hardware, there is no good reason for register read anyway


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.27 -r1.57.6.28 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.57.6.27 src/sys/dev/ic/ahcisata_core.c:1.57.6.28
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.27	Sun Sep 10 19:31:15 2017
+++ src/sys/dev/ic/ahcisata_core.c	Tue Sep 19 17:52:52 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.27 2017/09/10 19:31:15 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.28 2017/09/19 17:52:52 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.27 2017/09/10 19:31:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.28 2017/09/19 17:52:52 jdolecek Exp $");
 
 #include 
 #include 
@@ -568,7 +568,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 	uint32_t is, tfd, sact;
 	struct ata_channel *chp = >ata_channel;
 	struct ata_xfer *xfer;
-	int slot;
+	int slot = -1;
 	bool recover = false;
 
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
@@ -585,12 +585,9 @@ ahci_intr_port(struct ahci_softc *sc, st
 	if ((chp->ch_flags & ATACH_NCQ) == 0) {
 		/* Non-NCQ operation */
 		sact = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel));
-		slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
-			& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
 	} else {
 		/* NCQ operation */
 		sact = AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
-		slot = -1;
 	}
 
 	/* Handle errors */
@@ -600,6 +597,14 @@ ahci_intr_port(struct ahci_softc *sc, st
 		if (is & AHCI_P_IX_TFES) {
 			tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
 
+			if ((chp->ch_flags & ATACH_NCQ) == 0) {
+/* Slot valid only for Non-NCQ operation */
+slot = (AHCI_READ(sc,
+AHCI_P_CMD(chp->ch_channel))
+& AHCI_P_CMD_CCS_MASK)
+>> AHCI_P_CMD_CCS_SHIFT;
+			}
+
 			aprint_error("%s port %d: active %x is 0x%x tfd 0x%x\n",
 			AHCINAME(sc), chp->ch_channel, sact, is, tfd);
 		} else {
@@ -657,7 +662,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 			if ((aslots & __BIT(slot)) != 0 &&
 			(sact & __BIT(slot)) == 0) {
 xfer = ata_queue_hwslot_to_xfer(chp, slot);
-xfer->c_intr(chp, xfer, 0);
+xfer->c_intr(chp, xfer, tfd);
 			}
 		}
 	}



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

2017-09-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Sep 11 22:19:23 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: wdc.c

Log Message:
fix condition for calling atastart() when command is done


To generate a diff of this commit:
cvs rdiff -u -r1.283.2.14 -r1.283.2.15 src/sys/dev/ic/wdc.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/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.283.2.14 src/sys/dev/ic/wdc.c:1.283.2.15
--- src/sys/dev/ic/wdc.c:1.283.2.14	Sun Sep 10 19:31:15 2017
+++ src/sys/dev/ic/wdc.c	Mon Sep 11 22:19:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.283.2.14 2017/09/10 19:31:15 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.283.2.15 2017/09/11 22:19:23 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.14 2017/09/10 19:31:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.15 2017/09/11 22:19:23 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -1589,7 +1589,7 @@ __wdccommand_done(struct ata_channel *ch
 	struct wdc_softc *wdc = CHAN_TO_WDC(chp);
 	struct wdc_regs *wdr = >regs[chp->ch_channel];
 	struct ata_command *ata_c = >c_ata_c;
-	bool start = false;
+	bool start = true;
 
 	ATADEBUG_PRINT(("__wdccommand_done %s:%d:%d flags 0x%x\n",
 	device_xname(atac->atac_dev), chp->ch_channel, xfer->c_drive,



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

2017-09-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Sep 10 18:37:21 UTC 2017

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

Log Message:
move mvsata_bio(), mvsata_exec_command() and mvsata_atapi_scsipi_request()
just before their respective hook functions


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.23 -r1.35.6.24 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.35.6.23 src/sys/dev/ic/mvsata.c:1.35.6.24
--- src/sys/dev/ic/mvsata.c:1.35.6.23	Sun Aug 13 11:48:53 2017
+++ src/sys/dev/ic/mvsata.c	Sun Sep 10 18:37:21 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.23 2017/08/13 11:48:53 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.24 2017/09/10 18:37:21 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.23 2017/08/13 11:48:53 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.24 2017/09/10 18:37:21 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -688,38 +688,6 @@ mvsata_probe_drive(struct ata_channel *c
 }
 
 #ifndef MVSATA_WITHOUTDMA
-static int
-mvsata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
-{
-	struct ata_channel *chp = drvp->chnl_softc;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
-	struct atac_softc *atac = chp->ch_atac;
-	struct ata_bio *ata_bio = >c_bio;
-
-	DPRINTF(DEBUG_FUNCS|DEBUG_XFERS,
-	("%s:%d: mvsata_bio: drive=%d, blkno=%" PRId64
-	", bcount=%ld\n", device_xname(atac->atac_dev), chp->ch_channel,
-	drvp->drive, ata_bio->blkno, ata_bio->bcount));
-
-	mvsata_quetag_get(mvport, xfer->c_slot);
-
-	if (atac->atac_cap & ATAC_CAP_NOIRQ)
-		ata_bio->flags |= ATA_POLL;
-	if (ata_bio->flags & ATA_POLL)
-		xfer->c_flags |= C_POLL;
-	if ((drvp->drive_flags & (ATA_DRIVE_DMA | ATA_DRIVE_UDMA)) &&
-	(ata_bio->flags & ATA_SINGLE) == 0)
-		xfer->c_flags |= C_DMA;
-	xfer->c_drive = drvp->drive;
-	xfer->c_databuf = ata_bio->databuf;
-	xfer->c_bcount = ata_bio->bcount;
-	xfer->c_start = mvsata_bio_start;
-	xfer->c_intr = mvsata_bio_intr;
-	xfer->c_kill_xfer = mvsata_bio_kill_xfer;
-	ata_exec_xfer(chp, xfer);
-	return (ata_bio->flags & ATA_ITSDONE) ? ATACMD_COMPLETE : ATACMD_QUEUED;
-}
-
 static void
 mvsata_reset_drive(struct ata_drive_datas *drvp, int flags, uint32_t *sigp)
 {
@@ -794,55 +762,6 @@ mvsata_reset_channel(struct ata_channel 
 
 
 static int
-mvsata_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
-{
-	struct ata_channel *chp = drvp->chnl_softc;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
-	struct ata_command *ata_c = >c_ata_c;
-	int rv, s;
-
-	DPRINTF(DEBUG_FUNCS|DEBUG_XFERS,
-	("%s:%d: mvsata_exec_command: drive=%d, bcount=%d,"
-	" r_lba=0x%012"PRIx64", r_count=0x%04x, r_features=0x%04x,"
-	" r_device=0x%02x, r_command=0x%02x\n",
-	device_xname(MVSATA_DEV2(mvport)), chp->ch_channel,
-	drvp->drive, ata_c->bcount, ata_c->r_lba, ata_c->r_count,
-	ata_c->r_features, ata_c->r_device, ata_c->r_command));
-
-	mvsata_quetag_get(mvport, xfer->c_slot);
-
-	if (ata_c->flags & AT_POLL)
-		xfer->c_flags |= C_POLL;
-	if (ata_c->flags & AT_WAIT)
-		xfer->c_flags |= C_WAIT;
-	xfer->c_drive = drvp->drive;
-	xfer->c_databuf = ata_c->data;
-	xfer->c_bcount = ata_c->bcount;
-	xfer->c_start = mvsata_wdc_cmd_start;
-	xfer->c_intr = mvsata_wdc_cmd_intr;
-	xfer->c_kill_xfer = mvsata_wdc_cmd_kill_xfer;
-	s = splbio();
-	ata_exec_xfer(chp, xfer);
-#ifdef DIAGNOSTIC
-	if ((ata_c->flags & AT_POLL) != 0 &&
-	(ata_c->flags & AT_DONE) == 0)
-		panic("mvsata_exec_command: polled command not done");
-#endif
-	if (ata_c->flags & AT_DONE)
-		rv = ATACMD_COMPLETE;
-	else {
-		if (ata_c->flags & AT_WAIT) {
-			while ((ata_c->flags & AT_DONE) == 0)
-tsleep(ata_c, PRIBIO, "mvsatacmd", 0);
-			rv = ATACMD_COMPLETE;
-		} else
-			rv = ATACMD_QUEUED;
-	}
-	splx(s);
-	return rv;
-}
-
-static int
 mvsata_addref(struct ata_drive_datas *drvp)
 {
 
@@ -899,68 +818,6 @@ mvsata_atapibus_attach(struct atabus_sof
 }
 
 static void
-mvsata_atapi_scsipi_request(struct scsipi_channel *chan,
-			scsipi_adapter_req_t req, void *arg)
-{
-	struct scsipi_adapter *adapt = chan->chan_adapter;
-	struct scsipi_periph *periph;
-	struct scsipi_xfer *sc_xfer;
-	struct mvsata_softc *sc = device_private(adapt->adapt_dev);
-	struct atac_softc *atac = >sc_wdcdev.sc_atac;
-	struct ata_channel *chp = atac->atac_channels[chan->chan_channel];
-	struct ata_xfer *xfer;
-	struct mvsata_port *mvport = (struct mvsata_port *)chp;
-	int drive, s;
-
-switch (req) {
-	case ADAPTER_REQ_RUN_XFER:
-		sc_xfer = arg;
-		periph = sc_xfer->xs_periph;
-		drive = periph->periph_target;
-
-		if (!device_is_active(atac->atac_dev)) {
-			sc_xfer->error = XS_DRIVER_STUFFUP;
-			scsipi_done(sc_xfer);
-			return;
-		}
-		

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

2017-08-15 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Tue Aug 15 20:12:29 UTC 2017

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

Log Message:
Use ata_queue_free() instead of free() to deallocate chp->ch_queue during 
detach.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.35 -r1.30.4.36 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.30.4.35 src/sys/dev/ic/siisata.c:1.30.4.36
--- src/sys/dev/ic/siisata.c:1.30.4.35	Sat Aug 12 22:12:04 2017
+++ src/sys/dev/ic/siisata.c	Tue Aug 15 20:12:28 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.35 2017/08/12 22:12:04 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.36 2017/08/15 20:12:28 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.35 2017/08/12 22:12:04 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.36 2017/08/15 20:12:28 jakllsch Exp $");
 
 #include 
 #include 
@@ -426,7 +426,8 @@ siisata_detach(struct siisata_softc *sc,
 		bus_dmamem_free(sc->sc_dmat,
 		>sch_prb_seg, schp->sch_prb_nseg);
 
-		free(chp->ch_queue, M_DEVBUF);
+		ata_queue_free(chp->ch_queue);
+		chp->ch_queue = NULL;
 		chp->atabus = NULL;
 
 		ata_channel_detach(chp);



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

2017-08-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Aug 13 11:48:53 UTC 2017

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

Log Message:
put the non-NCQ KASSERT() before edma disable for bio PIO, we are not supposed
to get there with NCQ command even on retries any more


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.22 -r1.35.6.23 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.35.6.22 src/sys/dev/ic/mvsata.c:1.35.6.23
--- src/sys/dev/ic/mvsata.c:1.35.6.22	Sat Aug 12 22:43:22 2017
+++ src/sys/dev/ic/mvsata.c	Sun Aug 13 11:48:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.22 2017/08/12 22:43:22 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.23 2017/08/13 11:48:53 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.22 2017/08/12 22:43:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.23 2017/08/13 11:48:53 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1339,6 +1339,7 @@ do_pio:
 			WDCC_READ : WDCC_WRITE;
 
 		/* EDMA disable, if enabled this channel. */
+		KASSERT((chp->ch_flags & ATACH_NCQ) == 0);
 		if (mvport->port_edmamode_curr != nodma)
 			mvsata_edma_disable(mvport, 10 /* ms */, wait_flags);
 



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

2017-08-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Aug 12 13:41:46 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: wdc.c

Log Message:
remove debug printf


To generate a diff of this commit:
cvs rdiff -u -r1.283.2.11 -r1.283.2.12 src/sys/dev/ic/wdc.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/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.283.2.11 src/sys/dev/ic/wdc.c:1.283.2.12
--- src/sys/dev/ic/wdc.c:1.283.2.11	Sat Aug 12 09:52:28 2017
+++ src/sys/dev/ic/wdc.c	Sat Aug 12 13:41:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.283.2.11 2017/08/12 09:52:28 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.283.2.12 2017/08/12 13:41:46 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.11 2017/08/12 09:52:28 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.12 2017/08/12 13:41:46 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -1254,7 +1254,6 @@ wdcwait(struct ata_channel *chp, int mas
  */
 ata_channel_freeze(chp);
 wakeup(>ch_thread);
-printf("wdcwait_thr");
 return(WDCWAIT_THR);
 			}
 		}



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

2017-08-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Aug 12 09:38:58 UTC 2017

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

Log Message:
fix condition for switching to kernel thread for ATAPI and bio reset recovery
to match atapi_wdc.c, __wdcwait() postpones to the thread whenever neither
AT_POLL nor AT_WAIT flags are present

fixes spurious 'timeout' for the command on mvsata, followed by 'unexpected'
interrupt


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.18 -r1.35.6.19 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.35.6.18 src/sys/dev/ic/mvsata.c:1.35.6.19
--- src/sys/dev/ic/mvsata.c:1.35.6.18	Wed Jun 28 19:59:36 2017
+++ src/sys/dev/ic/mvsata.c	Sat Aug 12 09:38:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.18 2017/06/28 19:59:36 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.19 2017/08/12 09:38:58 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.18 2017/06/28 19:59:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.19 2017/08/12 09:38:58 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1222,7 +1222,8 @@ do_pio:
 			 * If it's not a polled command, we need the kernel
 			 * thread
 			 */
-			if ((xfer->c_flags & C_POLL) == 0 && cpu_intr_p()) {
+			if ((xfer->c_flags & C_POLL) == 0 &&
+			(chp->ch_flags & ATACH_TH_RUN) == 0) {
 ata_channel_freeze(chp);
 wakeup(>ch_thread);
 return;
@@ -1910,7 +1911,8 @@ mvsata_atapi_start(struct ata_channel *c
 	/* Do control operations specially. */
 	if (__predict_false(drvp->state < READY)) {
 		/* If it's not a polled command, we need the kernel thread */
-		if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 && cpu_intr_p()) {
+		if ((sc_xfer->xs_control & XS_CTL_POLL) == 0 &&
+		(chp->ch_flags & ATACH_TH_RUN) == 0) {
 			ata_channel_freeze(chp);
 			wakeup(>ch_thread);
 			return;



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

2017-08-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Aug 11 18:20:13 UTC 2017

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

Log Message:
replace magic 3100 with locall defined WDC_RESET_WAIT


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.33 -r1.30.4.34 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.30.4.33 src/sys/dev/ic/siisata.c:1.30.4.34
--- src/sys/dev/ic/siisata.c:1.30.4.33	Fri Aug  4 20:53:46 2017
+++ src/sys/dev/ic/siisata.c	Fri Aug 11 18:20:13 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.33 2017/08/04 20:53:46 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.34 2017/08/11 18:20:13 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.33 2017/08/04 20:53:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.34 2017/08/11 18:20:13 jdolecek Exp $");
 
 #include 
 #include 
@@ -109,6 +109,7 @@ int siisata_debug_mask = 0;
 #endif
 
 #define ATA_DELAY 1		/* 10s for a drive I/O */
+#define WDC_RESET_WAIT 31000	/* 31s for drive reset */
 
 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
 #if _BYTE_ORDER == _LITTLE_ENDIAN
@@ -721,6 +722,7 @@ siisata_reset_drive(struct ata_drive_dat
 	struct ata_xfer *xfer;
 	uint32_t pss, pis;
 	int i;
+	bool timed_out;
 
 	siisata_reinit_port(chp, drvp->drive);
 
@@ -737,10 +739,13 @@ siisata_reset_drive(struct ata_drive_dat
 
 	siisata_activate_prb(schp, xfer->c_slot);
 
-	for(i = 0; i < 3100; i++) {
+	timed_out = true;
+	for(i = 0; i < WDC_RESET_WAIT / 10; i++) {
 		pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
-		if ((pss & PR_PXSS(xfer->c_slot)) == 0)
+		if ((pss & PR_PXSS(xfer->c_slot)) == 0) {
+			timed_out = false;
 			break;
+		}
 		if (pss & PR_PSS_ATTENTION)
 			break;
 		ata_delay(10, "siiprb", flags);
@@ -764,7 +769,7 @@ siisata_reset_drive(struct ata_drive_dat
 
 	siisata_enable_port_interrupt(chp);
 
-	if (i == 3100) {
+	if (timed_out) {
 		/* timeout */
 		siisata_device_reset(chp);	/* XXX is this right? */
 		if (sigp)
@@ -888,7 +893,7 @@ siisata_probe_drive(struct ata_channel *
 		siisata_activate_prb(schp, xfer->c_slot);
 
 		timed_out = 1;
-		for(i = 0; i < 3100; i++) {
+		for(i = 0; i < WDC_RESET_WAIT / 10; i++) {
 			if ((PRREAD(sc, PRX(chp->ch_channel, PRO_PSS)) &
 			PR_PXSS(xfer->c_slot)) == 0) {
 /* prb completed */



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

2017-08-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Aug  4 20:53:47 UTC 2017

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

Log Message:
prb_control need to add (or) PRB_CF_INTERRUPT_MASK for polled commands,
rather that set - the field may be nonzero for ATAPI or for protocol override


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.32 -r1.30.4.33 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.30.4.32 src/sys/dev/ic/siisata.c:1.30.4.33
--- src/sys/dev/ic/siisata.c:1.30.4.32	Fri Aug  4 20:49:24 2017
+++ src/sys/dev/ic/siisata.c	Fri Aug  4 20:53:46 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.32 2017/08/04 20:49:24 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.33 2017/08/04 20:53:46 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.32 2017/08/04 20:49:24 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.33 2017/08/04 20:53:46 jdolecek Exp $");
 
 #include 
 #include 
@@ -1039,7 +1039,7 @@ siisata_cmd_start(struct ata_channel *ch
 
 	if (xfer->c_flags & C_POLL) {
 		/* polled command, disable interrupts */
-		prb->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
+		prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK);
 		siisata_disable_port_interrupt(chp);
 	}
 
@@ -1256,7 +1256,7 @@ siisata_bio_start(struct ata_channel *ch
 
 	if (xfer->c_flags & C_POLL) {
 		/* polled command, disable interrupts */
-		prb->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
+		prb->prb_control |= htole16(PRB_CF_INTERRUPT_MASK);
 		siisata_disable_port_interrupt(chp);
 	}
 
@@ -1849,7 +1849,7 @@ siisata_atapi_start(struct ata_channel *
 
 	if (xfer->c_flags & C_POLL) {
 		/* polled command, disable interrupts */
-		prbp->prb_control = htole16(PRB_CF_INTERRUPT_MASK);
+		prbp->prb_control |= htole16(PRB_CF_INTERRUPT_MASK);
 		siisata_disable_port_interrupt(chp);
 	}
 



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

2017-08-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Aug  4 20:49:24 UTC 2017

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

Log Message:
restore part of what was removed in 1.30.4.30 - the success of command
needs to be driven by PSS so that it works also for polled commands, apparently
PR_PIS_CMDCMPL is not set in that case; now do error handling again only when
PSS_ATTENTION is set

this fixes timeout for polled commands like standby on shutdown,
and (ehm ehm), READ LOG EXT on NCQ error recovery


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.31 -r1.30.4.32 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.30.4.31 src/sys/dev/ic/siisata.c:1.30.4.32
--- src/sys/dev/ic/siisata.c:1.30.4.31	Tue Aug  1 22:02:32 2017
+++ src/sys/dev/ic/siisata.c	Fri Aug  4 20:49:24 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.31 2017/08/01 22:02:32 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.32 2017/08/04 20:49:24 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.31 2017/08/01 22:02:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.32 2017/08/04 20:49:24 jdolecek Exp $");
 
 #include 
 #include 
@@ -262,9 +262,12 @@ siisata_init_port(struct siisata_softc *
 	schp = >sc_channels[port];
 	chp = (struct ata_channel *)schp;
 
-	/* come out of reset, 64-bit activation */
+	/*
+	 * Come out of reset. Disable no clearing of PR_PIS_CMDCMPL on read
+	 * of PR_PSS. Disable 32-bit PRB activation, we use 64-bit activation.
+	 */
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC),
-	PR_PC_32BA | PR_PC_PORT_RESET);
+	PR_PC_32BA | PR_PC_INCOR | PR_PC_PORT_RESET);
 	/* initialize port */
 	siisata_reinit_port(chp, -1);
 	/* enable CmdErrr+CmdCmpl interrupting */
@@ -478,22 +481,22 @@ siisata_intr_port(struct siisata_channel
 	uint32_t pss, pis, tfd = 0;
 	bool recover = false;
 
-	pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
+	/* get slot status, clearing completion interrupt */
+	pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
 
-	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ",
-	SIISATANAME(sc), __func__, chp->ch_channel, pis),
+	SIISATA_DEBUG_PRINT(("%s: %s port %d, pss 0x%x ",
+	SIISATANAME(sc), __func__, chp->ch_channel, pss),
 	DEBUG_INTR);
 
-	if (pis & PR_PIS_CMDCMPL) {
-		/* get slot status, clearing completion interrupt */
-		pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
-
-		SIISATA_DEBUG_PRINT(("pss 0x%x\n", pss), DEBUG_INTR);
-	} else {
-		/* commands will be killed after recovery */
-		pss = 0x;
+	if (__predict_true((pss & PR_PSS_ATTENTION) == 0)) {
+		SIISATA_DEBUG_PRINT(("no attention"), DEBUG_INTR);
+		goto process;
 	}
 
+	pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
+
+	SIISATA_DEBUG_PRINT(("pis 0x%x\n", pss), DEBUG_INTR);
+
 	if (pis & PR_PIS_CMDERRR) {
 		uint32_t ec;
 
@@ -552,6 +555,7 @@ siisata_intr_port(struct siisata_channel
 	if (__predict_false(recover))
 		ata_channel_freeze(chp);
 
+process:
 	if (xfer != NULL) {
 		xfer->c_intr(chp, xfer, tfd);
 	} else {



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

2017-08-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Aug  1 22:02:32 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: ahcisata_core.c ahcisatavar.h
mvsatavar.h siisata.c siisatavar.h

Log Message:
fix logic bug in processing of finished commands - mask of active
commands can change during the loop as c_intr() callback can queue
new commands, so the interrupt routine should only mark as finished
those which were actually active before the loop started; otherwise
the code marked as finished commands which were just started, and
being executed by HBA, leading to all sorts of data corruption

while here mark the active mask volatile, as it is modified from
interrupt context

this fixes for good the random crashes, short reads, and fatal command
errors which I've been tracing down for past couple weeks

thanks to Jonathan (jakllsch@) for testing, and a script to easily
triggered the condition, and led to this bug being finally found and squashed


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.24 -r1.57.6.25 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.17.6.2 -r1.17.6.3 src/sys/dev/ic/ahcisatavar.h
cvs rdiff -u -r1.2.48.2 -r1.2.48.3 src/sys/dev/ic/mvsatavar.h
cvs rdiff -u -r1.30.4.30 -r1.30.4.31 src/sys/dev/ic/siisata.c
cvs rdiff -u -r1.6.48.2 -r1.6.48.3 src/sys/dev/ic/siisatavar.h

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.57.6.24 src/sys/dev/ic/ahcisata_core.c:1.57.6.25
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.24	Sat Jul 29 16:50:32 2017
+++ src/sys/dev/ic/ahcisata_core.c	Tue Aug  1 22:02:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.24 2017/07/29 16:50:32 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.25 2017/08/01 22:02:32 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.24 2017/07/29 16:50:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.25 2017/08/01 22:02:32 jdolecek Exp $");
 
 #include 
 #include 
@@ -559,7 +559,7 @@ ahci_intr(void *v)
 static void
 ahci_intr_port(struct ahci_softc *sc, struct ahci_channel *achp)
 {
-	uint32_t is, tfd, active;
+	uint32_t is, tfd, sact;
 	struct ata_channel *chp = >ata_channel;
 	struct ata_xfer *xfer;
 	int slot;
@@ -578,12 +578,12 @@ ahci_intr_port(struct ahci_softc *sc, st
 
 	if ((chp->ch_flags & ATACH_NCQ) == 0) {
 		/* Non-NCQ operation */
-		active = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel));
+		sact = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel));
 		slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
 			& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
 	} else {
 		/* NCQ operation */
-		active = AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
+		sact = AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
 		slot = -1;
 	}
 
@@ -595,7 +595,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 			tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
 
 			aprint_error("%s port %d: active %x is 0x%x tfd 0x%x\n",
-			AHCINAME(sc), chp->ch_channel, active, is, tfd);
+			AHCINAME(sc), chp->ch_channel, sact, is, tfd);
 		} else {
 			/* mark an error, and set BSY */
 			tfd = (WDCE_ABRT << AHCI_P_TFD_ERR_SHIFT) |
@@ -630,8 +630,8 @@ ahci_intr_port(struct ahci_softc *sc, st
 		ata_channel_freeze(chp);
 
 	if (slot >= 0) {
-		if ((achp->ahcic_cmds_active & (1 << slot)) != 0 &&
-		(active & (1 << slot)) == 0) {
+		if ((achp->ahcic_cmds_active & __BIT(slot)) != 0 &&
+		(sact & __BIT(slot)) == 0) {
 			xfer = ata_queue_hwslot_to_xfer(chp, slot);
 			xfer->c_intr(chp, xfer, tfd);
 		}
@@ -641,10 +641,15 @@ ahci_intr_port(struct ahci_softc *sc, st
 		 * and any further D2H FISes are ignored until the error
 		 * condition is cleared. Hence if a command is inactive,
 		 * it means it actually already finished successfully.
+		 * Note: active slots can change as c_intr() callback
+		 * can activate another command(s), so must only process
+		 * commands active before we start processing.
 		 */
+		uint32_t aslots = achp->ahcic_cmds_active;
+
 		for (slot=0; slot < sc->sc_ncmds; slot++) {
-			if ((achp->ahcic_cmds_active & (1 << slot)) != 0 &&
-			(active & (1 << slot)) == 0) {
+			if ((aslots & __BIT(slot)) != 0 &&
+			(sact & __BIT(slot)) == 0) {
 xfer = ata_queue_hwslot_to_xfer(chp, slot);
 xfer->c_intr(chp, xfer, 0);
 			}

Index: src/sys/dev/ic/ahcisatavar.h
diff -u src/sys/dev/ic/ahcisatavar.h:1.17.6.2 src/sys/dev/ic/ahcisatavar.h:1.17.6.3
--- src/sys/dev/ic/ahcisatavar.h:1.17.6.2	Sat Jul 29 15:07:46 2017
+++ src/sys/dev/ic/ahcisatavar.h	Tue Aug  1 22:02:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisatavar.h,v 1.17.6.2 2017/07/29 15:07:46 jdolecek Exp $	*/
+/*	$NetBSD: ahcisatavar.h,v 1.17.6.3 2017/08/01 22:02:32 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -82,7 +82,7 @@ struct 

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

2017-08-01 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Aug  1 21:43:49 UTC 2017

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

Log Message:
adjust code to be closer to HEAD to it's easier to compare and find
regressions, undoing some changes which were actually not necessary


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.29 -r1.30.4.30 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.30.4.29 src/sys/dev/ic/siisata.c:1.30.4.30
--- src/sys/dev/ic/siisata.c:1.30.4.29	Sun Jul 30 20:46:31 2017
+++ src/sys/dev/ic/siisata.c	Tue Aug  1 21:43:49 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.29 2017/07/30 20:46:31 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.30 2017/08/01 21:43:49 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.29 2017/07/30 20:46:31 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.30 2017/08/01 21:43:49 jdolecek Exp $");
 
 #include 
 #include 
@@ -245,7 +245,10 @@ siisata_enable_port_interrupt(struct ata
 {
 	struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
 
-	/* enable CmdErrr+CmdCmpl interrupting */
+	/* clear any interrupts */
+	(void)PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
+	PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0x);
+	/* and enable CmdErrr+CmdCmpl interrupting */
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_PIES),
 	PR_PIS_CMDERRR | PR_PIS_CMDCMPL);
 }
@@ -259,12 +262,9 @@ siisata_init_port(struct siisata_softc *
 	schp = >sc_channels[port];
 	chp = (struct ata_channel *)schp;
 
-	/*
-	 * Come out of reset. Disable no clearing of PR_PIS_CMDCMPL on read
-	 * of PR_PSS. Disable 32-bit PRB activation, we use 64-bit activation.
-	 */
+	/* come out of reset, 64-bit activation */
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_PCC),
-	PR_PC_32BA | PR_PC_INCOR | PR_PC_PORT_RESET);
+	PR_PC_32BA | PR_PC_PORT_RESET);
 	/* initialize port */
 	siisata_reinit_port(chp, -1);
 	/* enable CmdErrr+CmdCmpl interrupting */
@@ -474,29 +474,25 @@ siisata_intr_port(struct siisata_channel
 	struct siisata_softc *sc =
 	(struct siisata_softc *)schp->ata_channel.ch_atac;
 	struct ata_channel *chp = >ata_channel;
-	struct ata_xfer *xfer;
-	int slot = -1;
+	struct ata_xfer *xfer = NULL;
 	uint32_t pss, pis, tfd = 0;
 	bool recover = false;
 
-	/* get slot status, clearing completion interrupt (PR_PIS_CMDCMPL) */
-	pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
-
-	SIISATA_DEBUG_PRINT(("%s: %s port %d, pss 0x%x\n",
-	SIISATANAME(sc), __func__, chp->ch_channel, pss), DEBUG_INTR);
-
-	/* if no errors, just process finished commands and we're done */
-	if (__predict_true((pss & PR_PSS_ATTENTION) == 0))
-		goto process;
-
 	pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
 
 	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ",
 	SIISATANAME(sc), __func__, chp->ch_channel, pis),
 	DEBUG_INTR);
 
-	/* clear */
-	PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), pis);
+	if (pis & PR_PIS_CMDCMPL) {
+		/* get slot status, clearing completion interrupt */
+		pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
+
+		SIISATA_DEBUG_PRINT(("pss 0x%x\n", pss), DEBUG_INTR);
+	} else {
+		/* commands will be killed after recovery */
+		pss = 0x;
+	}
 
 	if (pis & PR_PIS_CMDERRR) {
 		uint32_t ec;
@@ -510,15 +506,12 @@ siisata_intr_port(struct siisata_channel
 		if (ec <= PR_PCE_DATAFISERROR) {
 			if (ec == PR_PCE_DEVICEERROR
 			&& (chp->ch_flags & ATACH_NCQ) == 0) {
-uint32_t ps = PRREAD(sc,
-PRX(chp->ch_channel, PRO_PS));
-/* This is only relevant for non-NCQ commands */
-slot = PR_PS_ACTIVE_SLOT(ps);
+xfer = ata_queue_get_active_xfer(chp);
 
 /* read in specific information about error */
 uint32_t prbfis = bus_space_read_stream_4(
 sc->sc_prt, sc->sc_prh,
-PRSX(chp->ch_channel, slot,
+PRSX(chp->ch_channel, xfer->c_slot,
 PRSO_FIS));
 
 /* get status and error */
@@ -528,30 +521,39 @@ siisata_intr_port(struct siisata_channel
 if (ATACH_ST(ntfd) & WDCS_ERR)
 	tfd = ntfd;
 			}
+
+			/*
+			 * We don't expect the recovery to trigger error,
+			 * but handle this just in case.
+			 */
+			if (!schp->sch_recovering) 
+recover = true;
+			else {
+aprint_error_dev(sc->sc_atac.atac_dev,
+"error ec %x while recovering\n", ec);
+
+/* Command will be marked as errored out */
+pss = 0;
+			}
 		} else {
 			aprint_error_dev(sc->sc_atac.atac_dev, "fatal error %d"
 			" on channel %d (ctx 0x%x), resetting\n",
 			ec, chp->ch_channel,
 			PRREAD(sc, PRX(chp->ch_channel, PRO_PCR)));
 
-			tfd |= ATACH_ERR_ST(0, WDCS_BSY);
+			/* okay, we have a "Fatal Error" */
+			siisata_device_reset(chp);
 		}
-
-		if (!schp->sch_recovering)
-			recover = true;
-	} else {

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

2017-07-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Jul 30 20:46:31 UTC 2017

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

Log Message:
undo debug code


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.28 -r1.30.4.29 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.30.4.28 src/sys/dev/ic/siisata.c:1.30.4.29
--- src/sys/dev/ic/siisata.c:1.30.4.28	Sun Jul 30 20:24:45 2017
+++ src/sys/dev/ic/siisata.c	Sun Jul 30 20:46:31 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.28 2017/07/30 20:24:45 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.29 2017/07/30 20:46:31 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.28 2017/07/30 20:24:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.29 2017/07/30 20:46:31 jdolecek Exp $");
 
 #include 
 #include 
@@ -288,7 +288,7 @@ siisata_attach_port(struct siisata_softc
 	sc->sc_chanarray[port] = chp;
 	chp->ch_channel = port;
 	chp->ch_atac = >sc_atac;
-	chp->ch_queue = ata_queue_alloc(4) ; //SIISATA_MAX_SLOTS);
+	chp->ch_queue = ata_queue_alloc(SIISATA_MAX_SLOTS);
 	if (chp->ch_queue == NULL) {
 		aprint_error_dev(sc->sc_atac.atac_dev,
 		"port %d: can't allocate memory "



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

2017-07-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Jul 30 20:24:45 UTC 2017

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

Log Message:
adjust error recovery to similar shape as ahcisata; also switch to using
siisata_reset_channel(), as that seems more reliably get the HBA to running
state again after some errors

besides this, change several places checking PORT_READY to use
siisata_reinit_port() and properly timeout - seen several cases
where it would just loop there indefinitely on some errors with no
way to get into ddb and no error message, due to the tight DELAY() loop


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.27 -r1.30.4.28 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.30.4.27 src/sys/dev/ic/siisata.c:1.30.4.28
--- src/sys/dev/ic/siisata.c:1.30.4.27	Wed Jul 19 20:24:59 2017
+++ src/sys/dev/ic/siisata.c	Sun Jul 30 20:24:45 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.27 2017/07/19 20:24:59 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.28 2017/07/30 20:24:45 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.27 2017/07/19 20:24:59 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.28 2017/07/30 20:24:45 jdolecek Exp $");
 
 #include 
 #include 
@@ -157,12 +157,12 @@ int siisata_bio_complete(struct ata_chan
 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 *);
+static void 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);
 static int siisata_dma_setup(struct ata_channel *, int, void *, size_t, int);
-static void siisata_channel_recover(struct ata_channel *, int, int);
+void siisata_channel_recover(struct ata_channel *, uint32_t);
 
 #if NATAPIBUS > 0
 void siisata_atapibus_attach(struct atabus_softc *);
@@ -266,7 +266,7 @@ 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);
+	siisata_reinit_port(chp, -1);
 	/* enable CmdErrr+CmdCmpl interrupting */
 	siisata_enable_port_interrupt(chp);
 	/* enable port interrupt */
@@ -288,7 +288,7 @@ siisata_attach_port(struct siisata_softc
 	sc->sc_chanarray[port] = chp;
 	chp->ch_channel = port;
 	chp->ch_atac = >sc_atac;
-	chp->ch_queue = ata_queue_alloc(SIISATA_MAX_SLOTS);
+	chp->ch_queue = ata_queue_alloc(4) ; //SIISATA_MAX_SLOTS);
 	if (chp->ch_queue == NULL) {
 		aprint_error_dev(sc->sc_atac.atac_dev,
 		"port %d: can't allocate memory "
@@ -471,54 +471,29 @@ siisata_intr(void *v)
 static void
 siisata_intr_port(struct siisata_channel *schp)
 {
-	struct siisata_softc *sc;
-	struct ata_channel *chp;
+	struct siisata_softc *sc =
+	(struct siisata_softc *)schp->ata_channel.ch_atac;
+	struct ata_channel *chp = >ata_channel;
 	struct ata_xfer *xfer;
-	u_int slot;
-	uint32_t pss, pis;
-
-	sc = (struct siisata_softc *)schp->ata_channel.ch_atac;
-	chp = >ata_channel;
+	int slot = -1;
+	uint32_t pss, pis, tfd = 0;
+	bool recover = false;
 
 	/* get slot status, clearing completion interrupt (PR_PIS_CMDCMPL) */
 	pss = PRREAD(sc, PRX(chp->ch_channel, PRO_PSS));
+
 	SIISATA_DEBUG_PRINT(("%s: %s port %d, pss 0x%x\n",
 	SIISATANAME(sc), __func__, chp->ch_channel, pss), DEBUG_INTR);
 
-	for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) {
-		if (((schp->sch_active_slots >> slot) & 1) == 0) {
-			/* there's nothing executing here, skip */
-			continue;
-		}
-		if (((pss >> slot) & 1) != 0) {
-			/* execution is incomplete or unsuccessful, skip
-			 * for now */
-			continue;
-		}
-		xfer = ata_queue_hwslot_to_xfer(chp, slot);
-		if (xfer->c_intr == NULL) {
-			wakeup(schp);
-			continue;
-		}
-		KASSERT(xfer != NULL);
-		KASSERT(xfer->c_intr != NULL);
-		xfer->c_intr(chp, xfer, 0);
-	}
-	/* if no errors, we're done now */
-	if ((pss & PR_PSS_ATTENTION) == 0) {
-		pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
-		pis &= 0x;
-		if (pis) {
-			PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS),
-			pis & 0xfffcfffc);
-		}
-		return;
-	}
+	/* if no errors, just process finished commands and we're done */
+	if (__predict_true((pss & PR_PSS_ATTENTION) == 0))
+		goto process;
 
 	pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
 
-	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ", SIISATANAME(sc),
-	__func__, chp->ch_channel, pis), DEBUG_INTR);
+	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ",
+	SIISATANAME(sc), __func__, chp->ch_channel, pis),
+	

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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 22:40:04 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: siisatareg.h

Log Message:
add macro for getting the slot from context register, just for reference for now


To generate a diff of this commit:
cvs rdiff -u -r1.7.42.3 -r1.7.42.4 src/sys/dev/ic/siisatareg.h

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/siisatareg.h
diff -u src/sys/dev/ic/siisatareg.h:1.7.42.3 src/sys/dev/ic/siisatareg.h:1.7.42.4
--- src/sys/dev/ic/siisatareg.h:1.7.42.3	Wed Jul 19 20:03:29 2017
+++ src/sys/dev/ic/siisatareg.h	Sat Jul 29 22:40:04 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatareg.h,v 1.7.42.3 2017/07/19 20:03:29 jdolecek Exp $ */
+/* $NetBSD: siisatareg.h,v 1.7.42.4 2017/07/29 22:40:04 jdolecek Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2010, 2011 Jonathan A. Kollasch.
@@ -188,6 +188,7 @@ struct siisata_prb {
 #define PRO_CARX(p,s) (PRX(p, PRO_CAR) + (s) * sizeof(uint64_t))
 
 #define PRO_PCR		0x1e04		/* port context register */
+#define PRO_PCR_SLOT(x)	(((x) & __BITS(4, 0)) >> 0) /* Slot */
 #define PRO_PCR_PMP(x)	(((x) & __BITS(8, 5)) >> 5) /* PM Port */
 #define PRO_SCONTROL	0x1f00		/* SControl */
 #define PRO_SSTATUS	0x1f04		/* SStatus */



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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 16:50:32 UTC 2017

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

Log Message:
whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.23 -r1.57.6.24 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.57.6.23 src/sys/dev/ic/ahcisata_core.c:1.57.6.24
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.23	Sat Jul 29 15:07:46 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Jul 29 16:50:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.23 2017/07/29 15:07:46 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.24 2017/07/29 16:50:32 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.23 2017/07/29 15:07:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.24 2017/07/29 16:50:32 jdolecek Exp $");
 
 #include 
 #include 
@@ -1609,7 +1609,6 @@ ahci_channel_recover(struct ahci_softc *
 		/*
 		 * Failed to get resources to run the recovery command, must
 		 * reset the drive. This will also kill all still outstanding
-
 		 * transfers.
 		 */
 reset:



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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 15:07:46 UTC 2017

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

Log Message:
make compile without AHCI_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.22 -r1.57.6.23 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.17.6.1 -r1.17.6.2 src/sys/dev/ic/ahcisatavar.h

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.57.6.22 src/sys/dev/ic/ahcisata_core.c:1.57.6.23
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.22	Sat Jul 29 14:50:58 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Jul 29 15:07:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.22 2017/07/29 14:50:58 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.23 2017/07/29 15:07:46 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.22 2017/07/29 14:50:58 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.23 2017/07/29 15:07:46 jdolecek Exp $");
 
 #include 
 #include 
@@ -967,9 +967,9 @@ ahci_exec_command(struct ata_drive_datas
 	int ret;
 	int s;
 
-	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	AHCIDEBUG_PRINT(("ahci_exec_command port %d CI 0x%x\n",
-	chp->ch_channel, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
+	chp->ch_channel,
+	AHCI_READ(AHCI_CH2SC(chp), AHCI_P_CI(chp->ch_channel))),
 	DEBUG_XFERS);
 	if (ata_c->flags & AT_POLL)
 		xfer->c_flags |= C_POLL;
@@ -1007,17 +1007,17 @@ ahci_exec_command(struct ata_drive_datas
 static void
 ahci_cmd_start(struct ata_channel *chp, struct ata_xfer *xfer)
 {
-	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
+	struct ahci_softc *sc = AHCI_CH2SC(chp);
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 	struct ata_command *ata_c = >c_ata_c;
 	int slot = xfer->c_slot;
 	struct ahci_cmd_tbl *cmd_tbl;
 	struct ahci_cmd_header *cmd_h;
 	int i;
-	int channel = chp->ch_channel;
 
 	AHCIDEBUG_PRINT(("ahci_cmd_start CI 0x%x timo %d\n slot %d",
-	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)), ata_c->timeout, slot),
+	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)),
+	ata_c->timeout, slot),
 	DEBUG_XFERS);
 
 	KASSERT((achp->ahcic_cmds_active & (1 << slot)) == 0);
@@ -1072,11 +1072,14 @@ ahci_cmd_start(struct ata_channel *chp, 
 		ahci_intr_port(sc, achp);
 		ata_delay(10, "ahcipl", ata_c->flags);
 	}
-	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), channel, 
+	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), chp->ch_channel, 
 	AHCI_READ(sc, AHCI_GHC), AHCI_READ(sc, AHCI_IS),
-	AHCI_READ(sc, AHCI_P_CLBU(channel)), AHCI_READ(sc, AHCI_P_CLB(channel)),
-	AHCI_READ(sc, AHCI_P_FBU(channel)), AHCI_READ(sc, AHCI_P_FB(channel)),
-	AHCI_READ(sc, AHCI_P_CMD(channel)), AHCI_READ(sc, AHCI_P_CI(channel))),
+	AHCI_READ(sc, AHCI_P_CLBU(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_CLB(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_FBU(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_FB(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
 	DEBUG_XFERS);
 	if ((ata_c->flags & AT_DONE) == 0) {
 		ata_c->flags |= AT_TIMEOU;
@@ -1127,12 +1130,12 @@ static int
 ahci_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int tfd)
 {
 	struct ata_command *ata_c = >c_ata_c;
-	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 
 	AHCIDEBUG_PRINT(("ahci_cmd_complete channel %d CMD 0x%x CI 0x%x\n",
-	chp->ch_channel, AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)),
-	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
+	chp->ch_channel,
+	AHCI_READ(AHCI_CH2SC(chp), AHCI_P_CMD(chp->ch_channel)),
+	AHCI_READ(AHCI_CH2SC(chp), AHCI_P_CI(chp->ch_channel))),
 	DEBUG_FUNCS);
 
 	if (ata_waitdrain_xfer_check(chp, xfer))
@@ -1217,9 +1220,9 @@ ahci_ata_bio(struct ata_drive_datas *drv
 	struct ata_channel *chp = drvp->chnl_softc;
 	struct ata_bio *ata_bio = >c_bio;
 
-	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	AHCIDEBUG_PRINT(("ahci_ata_bio port %d CI 0x%x\n",
-	chp->ch_channel, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
+	chp->ch_channel,
+	AHCI_READ(AHCI_CH2SC(chp), AHCI_P_CI(chp->ch_channel))),
 	DEBUG_XFERS);
 	if (ata_bio->flags & ATA_POLL)
 		xfer->c_flags |= C_POLL;
@@ -1242,7 +1245,6 @@ ahci_bio_start(struct ata_channel *chp, 
 	struct ahci_cmd_tbl *cmd_tbl;
 	struct ahci_cmd_header *cmd_h;
 	int i;
-	int channel = chp->ch_channel;
 
 	AHCIDEBUG_PRINT(("ahci_bio_start CI 0x%x\n",
 	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))), DEBUG_XFERS);
@@ -1297,11 

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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 14:50:58 UTC 2017

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

Log Message:
make ahci_channel_recover() non-static, so that it's visible in backtrace,
and can set a separate breakpoint there


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.21 -r1.57.6.22 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.57.6.21 src/sys/dev/ic/ahcisata_core.c:1.57.6.22
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.21	Sat Jul 29 13:02:50 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Jul 29 14:50:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.21 2017/07/29 13:02:50 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.22 2017/07/29 14:50:58 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.21 2017/07/29 13:02:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.22 2017/07/29 14:50:58 jdolecek Exp $");
 
 #include 
 #include 
@@ -77,8 +77,7 @@ static void ahci_bio_kill_xfer(struct at
 static void ahci_channel_stop(struct ahci_softc *, struct ata_channel *, int);
 static void ahci_channel_start(struct ahci_softc *, struct ata_channel *,
 int, int);
-static void ahci_channel_recover(struct ahci_softc *, struct ata_channel *,
-int);
+void ahci_channel_recover(struct ahci_softc *, struct ata_channel *, int);
 static int  ahci_dma_setup(struct ata_channel *, int, void *, size_t, int);
 
 #if NATAPIBUS > 0
@@ -627,7 +626,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 		tfd = 0;
 	}
 
-	if (recover)
+	if (__predict_false(recover))
 		ata_channel_freeze(chp);
 
 	if (slot >= 0) {
@@ -652,7 +651,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 		}
 	}
 
-	if (recover) {
+	if (__predict_false(recover)) {
 		ata_channel_thaw(chp);
 		ahci_channel_recover(sc, chp, tfd);
 	}



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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 13:04:43 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: ahcisatareg.h

Log Message:
fix AHCI_P_CMD_CCS_SHIFT - must shift only by 8, otherwise the result would
be always 0


To generate a diff of this commit:
cvs rdiff -u -r1.12.26.1 -r1.12.26.2 src/sys/dev/ic/ahcisatareg.h

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/ahcisatareg.h
diff -u src/sys/dev/ic/ahcisatareg.h:1.12.26.1 src/sys/dev/ic/ahcisatareg.h:1.12.26.2
--- src/sys/dev/ic/ahcisatareg.h:1.12.26.1	Wed Jul 19 20:21:42 2017
+++ src/sys/dev/ic/ahcisatareg.h	Sat Jul 29 13:04:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisatareg.h,v 1.12.26.1 2017/07/19 20:21:42 jdolecek Exp $	*/
+/*	$NetBSD: ahcisatareg.h,v 1.12.26.2 2017/07/29 13:04:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -234,8 +234,8 @@ struct ahci_r_fis {
 #define		AHCI_P_CMD_CR	0x8000 /* command list running */
 #define		AHCI_P_CMD_FR	0x4000 /* FIS receive running */
 #define		AHCI_P_CMD_MPSS	0x2000 /* mechanical switch state */
-#define		AHCI_P_CMD_CCS_MASK 0x1f00 /* current command slot */
-#define		AHCI_P_CMD_CCS_SHIFT 12
+#define		AHCI_P_CMD_CCS_MASK __BITS(12, 8) /* current command slot */
+#define		AHCI_P_CMD_CCS_SHIFT 8
 #define		AHCI_P_CMD_FRE	0x0010 /* FIS receive enable */
 #define		AHCI_P_CMD_CLO	0x0008 /* command list override */
 #define		AHCI_P_CMD_POD	0x0004 /* power on device */



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

2017-07-29 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jul 29 13:02:50 UTC 2017

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

Log Message:
do not do the drive reset on non-fatal recovery - spec explicitely says
says the READ LOG EXT should only be done when neither COMRESET nor software
reset was done, and indeed it returns junk in this case

use C_RECOVERY slot for drive reset, so that it now will always succeed
in getting a slot, in cases when it would be necessary

adjust code and comments on the recovery path to explain better what's going on

with this AHCI error recovery works with real hardware without timeouts again


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.20 -r1.57.6.21 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.57.6.20 src/sys/dev/ic/ahcisata_core.c:1.57.6.21
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.20	Sun Jul 23 14:14:43 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Jul 29 13:02:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.20 2017/07/23 14:14:43 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.21 2017/07/29 13:02:50 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.20 2017/07/23 14:14:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.21 2017/07/29 13:02:50 jdolecek Exp $");
 
 #include 
 #include 
@@ -568,10 +568,12 @@ ahci_intr_port(struct ahci_softc *sc, st
 
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), is);
-	AHCIDEBUG_PRINT(("ahci_intr_port %s port %d is 0x%x CI 0x%x TFD 0x%x\n",
+	AHCIDEBUG_PRINT((
+	"ahci_intr_port %s port %d is 0x%x CI 0x%x SACT 0x%x TFD 0x%x\n",
 	AHCINAME(sc),
 	chp->ch_channel, is,
 	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel)),
 	AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel))),
 	DEBUG_INTR);
 
@@ -613,8 +615,9 @@ ahci_intr_port(struct ahci_softc *sc, st
 		tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
 
 		/* D2H Register FIS or Set Device Bits */
-		if ((tfd & WDCS_ERR) != 0 && !achp->ahcic_recovering) {
-			recover = true;
+		if ((tfd & WDCS_ERR) != 0) {
+			if (!achp->ahcic_recovering)
+recover = true;
 
 			aprint_error("%s port %d: transfer aborted 0x%x\n",
 			AHCINAME(sc), chp->ch_channel, tfd);
@@ -757,11 +760,7 @@ again:
 
 	/* polled command, assume interrupts are disabled */
 	/* use available slot to send reset, if none available fail */
-	xfer = ata_get_xfer_ext(chp, false, 0);
-	if (xfer == NULL) {
-		printf("%s: no xfer\n", __func__);
-		return 1;
-	}
+	xfer = ata_get_xfer_ext(chp, C_RECOVERY, 0);
 
 	cmd_h = >ahcic_cmdh[xfer->c_slot];
 	cmd_tbl = achp->ahcic_cmd_tbl[xfer->c_slot];
@@ -1556,22 +1555,16 @@ ahci_channel_recover(struct ahci_softc *
 
 	/*
 	 * If BSY or DRQ bits are set, must execute COMRESET to return
-	 * device to idle state. Otherwise, commands can be reissued
-	 * after resetting CMD.ST. After resetting CMD.ST, need to execute
-	 * READ LOG EXT for NCQ to unblock device processing if COMRESET
-	 * was not done.
+	 * device to idle state. If drive is idle, it's enough to just
+	 * reset CMD.ST, it's not necessary to do software reset.
+	 * After resetting CMD.ST, need to execute READ LOG EXT for NCQ
+	 * to unblock device processing if COMRESET was not done.
 	 */
 	if (reset || (AHCI_TFD_ST(tfd) & (WDCS_BSY|WDCS_DRQ)) != 0)
 		goto reset;
 
 	KASSERT(drive >= 0);
 	ahci_channel_stop(sc, chp, AT_POLL);
-	if (ahci_do_reset_drive(chp, drive, AT_POLL, NULL) != 0) {
-reset:
-		/* This will also kill all still outstanding transfers */
-		ahci_reset_channel(chp, AT_POLL);
-		goto out;
-	}
 	ahci_channel_start(sc, chp, AT_POLL,
	(sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0);
 
@@ -1585,18 +1578,48 @@ reset:
 
 	ahci_unhold(achp);
 
-	if (error == 0) {
+	switch (error) {
+	case 0:
 		/* Error out the particular NCQ xfer, then requeue the others */
-		xfer = ata_queue_hwslot_to_xfer(chp, eslot);
-		xfer->c_intr(chp, xfer, (err << AHCI_P_TFD_ERR_SHIFT) | st);
-	} else if (error == EOPNOTSUPP) {
-		/* command already processed before entering recovery */
-		KASSERT(achp->ahcic_cmds_active == 0);
-	} else {
+		if ((achp->ahcic_cmds_active & (1 << eslot)) != 0) {
+			xfer = ata_queue_hwslot_to_xfer(chp, eslot);
+			xfer->c_intr(chp, xfer,
+			(err << AHCI_P_TFD_ERR_SHIFT) | st);
+		}
+		break;
+
+	case EOPNOTSUPP:
+		/*
+		 * Non-NCQ command error, just find the slot and end with
+		 * the error.
+		 */
+		for (slot = 0; slot < sc->sc_ncmds; slot++) {
+			if ((achp->ahcic_cmds_active & (1 << slot)) != 0) {
+xfer = ata_queue_hwslot_to_xfer(chp, slot);
+xfer->c_intr(chp, xfer, tfd);
+			}
+		}
+		break;
+
+	

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

2017-07-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Jul 23 14:14:44 UTC 2017

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

Log Message:
rework the error handling and recovery, so that errors during the recovery
are handled correctly, and the recovery more closely follows the spec

this fixes e.g. NCQ error handling under QEMU, which doesn't implement
READ LOG EXT - previous code actually made the call 'succeed', returning bogus
(zero) slot/error/status

finished xfers are still handled before entering recovery (with channel frozen)
to avoid unnecessary retries


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.19 -r1.57.6.20 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.57.6.19 src/sys/dev/ic/ahcisata_core.c:1.57.6.20
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.19	Fri Jul 21 18:36:47 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sun Jul 23 14:14:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.19 2017/07/21 18:36:47 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.20 2017/07/23 14:14:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.19 2017/07/21 18:36:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.20 2017/07/23 14:14:43 jdolecek Exp $");
 
 #include 
 #include 
@@ -77,7 +77,8 @@ static void ahci_bio_kill_xfer(struct at
 static void ahci_channel_stop(struct ahci_softc *, struct ata_channel *, int);
 static void ahci_channel_start(struct ahci_softc *, struct ata_channel *,
 int, int);
-static void ahci_channel_recover(struct ahci_softc *, struct ata_channel *);
+static void ahci_channel_recover(struct ahci_softc *, struct ata_channel *,
+int);
 static int  ahci_dma_setup(struct ata_channel *, int, void *, size_t, int);
 
 #if NATAPIBUS > 0
@@ -563,6 +564,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 	struct ata_channel *chp = >ata_channel;
 	struct ata_xfer *xfer;
 	int slot;
+	bool recover = false;
 
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), is);
@@ -573,34 +575,30 @@ ahci_intr_port(struct ahci_softc *sc, st
 	AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel))),
 	DEBUG_INTR);
 
-	active = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))
-		| AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
-
-	/* Complete all successful commands first */
-	for (slot=0; slot < sc->sc_ncmds; slot++) {
-		if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-			continue;
-		if ((active & (1 << slot)) == 0) {
-			xfer = ata_queue_hwslot_to_xfer(chp, slot);
-			xfer->c_intr(chp, xfer, 0);
-		}
+	if ((chp->ch_flags & ATACH_NCQ) == 0) {
+		/* Non-NCQ operation */
+		active = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel));
+		slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
+			& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
+	} else {
+		/* NCQ operation */
+		active = AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
+		slot = -1;
 	}
 
 	/* Handle errors */
 	if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_HBDS |
 	AHCI_P_IX_IFS | AHCI_P_IX_OFS | AHCI_P_IX_UFS)) {
+		/* Fatal errors */
 		if (is & AHCI_P_IX_TFES) {
 			tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
 
-			if ((AHCI_TFD_ST(tfd) & (WDCS_DRQ|WDCS_BSY)) == 0 &&
-			!achp->ahcic_recovering)
-goto recover;
-
 			aprint_error("%s port %d: active %x is 0x%x tfd 0x%x\n",
 			AHCINAME(sc), chp->ch_channel, active, is, tfd);
 		} else {
-			/* emulate a CRC error */
-			tfd = (WDCE_CRC << AHCI_P_TFD_ERR_SHIFT) | WDCS_ERR;
+			/* mark an error, and set BSY */
+			tfd = (WDCE_ABRT << AHCI_P_TFD_ERR_SHIFT) |
+			WDCS_ERR | WDCS_BSY;
 		}
 
 		if (is & AHCI_P_IX_IFS) {
@@ -609,29 +607,52 @@ ahci_intr_port(struct ahci_softc *sc, st
 			AHCI_READ(sc, AHCI_P_SERR(chp->ch_channel)));
 		}
 
-		/* Request channel reset */
-		ata_reset_channel(chp, 0);
-		return;
+		if (!achp->ahcic_recovering)
+			recover = true;
 	} else if (is & (AHCI_P_IX_DHRS|AHCI_P_IX_SDBS)) {
-		/* D2H Register FIS or Set Device Bits */
 		tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
+
+		/* D2H Register FIS or Set Device Bits */
 		if ((tfd & WDCS_ERR) != 0 && !achp->ahcic_recovering) {
-recover:
+			recover = true;
+
 			aprint_error("%s port %d: transfer aborted 0x%x\n",
 			AHCINAME(sc), chp->ch_channel, tfd);
 
-			/*
-			 * Device indicated transfer aborted without any fatal
-			 * error. Transfers can be reissued after resetting
-			 * CMD.ST. Need to execute READ LOG EXT for NCQ
-			 * commands.
-			 */
-			ahci_channel_stop(sc, chp, AT_POLL);
-			ahci_channel_start(sc, chp, AT_POLL,
-			(sc->sc_ahci_cap & AHCI_CAP_CLO) ? 1 : 0);
-			ahci_channel_recover(sc, chp);
+		}
+	} else {
+		tfd = 0;
+	}
+
+	if (recover)
+		

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

2017-07-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Jul 21 18:36:47 UTC 2017

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

Log Message:
use free slot for drive reset, rather than always using slot zero; if we can't
get the slot, fallback to channel reset as usual

note this increases the odds of not being able to do the reset, when all slots
happen to be active

this is in same area as problem reported by PR kern/52372 but I
don't believe that this change actually make any change for it - during
probe/attach there shouldn't be any paralell request with drive reset


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.18 -r1.57.6.19 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.57.6.18 src/sys/dev/ic/ahcisata_core.c:1.57.6.19
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.18	Wed Jul 19 20:21:42 2017
+++ src/sys/dev/ic/ahcisata_core.c	Fri Jul 21 18:36:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.18 2017/07/19 20:21:42 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.19 2017/07/21 18:36:47 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.18 2017/07/19 20:21:42 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.19 2017/07/21 18:36:47 jdolecek Exp $");
 
 #include 
 #include 
@@ -650,7 +650,7 @@ ahci_reset_drive(struct ata_drive_datas 
 
 /* return error code from ata_bio */
 static int
-ahci_exec_fis(struct ata_channel *chp, int timeout, int flags)
+ahci_exec_fis(struct ata_channel *chp, int timeout, int flags, int slot)
 {
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
@@ -667,11 +667,13 @@ ahci_exec_fis(struct ata_channel *chp, i
 	else
 		timeout = timeout / 10;
 
-	AHCI_CMDH_SYNC(sc, achp, 0, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
+	AHCI_CMDH_SYNC(sc, achp, slot,
+	BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
 	/* start command */
-	AHCI_WRITE(sc, AHCI_P_CI(chp->ch_channel), 1 << 0);
+	AHCI_WRITE(sc, AHCI_P_CI(chp->ch_channel), 1 << slot);
 	for (i = 0; i < timeout; i++) {
-		if ((AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)) & 1 << 0) == 0)
+		if ((AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)) & (1 << slot)) ==
+		0)
 			return 0;
 		is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 		if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_HBDS |
@@ -708,6 +710,7 @@ ahci_do_reset_drive(struct ata_channel *
 	struct ahci_cmd_header *cmd_h;
 	int i;
 	uint32_t sig;
+	struct ata_xfer *xfer = NULL;
 
 	KASSERT((AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) & AHCI_P_CMD_CR) == 0);
 again:
@@ -732,9 +735,15 @@ again:
 		goto skip_reset;
 
 	/* polled command, assume interrupts are disabled */
-	/* use slot 0 to send reset, the channel is idle */
-	cmd_h = >ahcic_cmdh[0];
-	cmd_tbl = achp->ahcic_cmd_tbl[0];
+	/* use available slot to send reset, if none available fail */
+	xfer = ata_get_xfer_ext(chp, false, 0);
+	if (xfer == NULL) {
+		printf("%s: no xfer\n", __func__);
+		return 1;
+	}
+
+	cmd_h = >ahcic_cmdh[xfer->c_slot];
+	cmd_tbl = achp->ahcic_cmd_tbl[xfer->c_slot];
 	cmd_h->cmdh_flags = htole16(AHCI_CMDH_F_RST | AHCI_CMDH_F_CBSY |
 	RHD_FISLEN / 4 | (drive << AHCI_CMDH_F_PMP_SHIFT));
 	cmd_h->cmdh_prdbc = 0;
@@ -742,7 +751,7 @@ again:
 	cmd_tbl->cmdt_cfis[fis_type] = RHD_FISTYPE;
 	cmd_tbl->cmdt_cfis[rhd_c] = drive;
 	cmd_tbl->cmdt_cfis[rhd_control] = WDCTL_RST;
-	switch(ahci_exec_fis(chp, 100, flags)) {
+	switch(ahci_exec_fis(chp, 100, flags, xfer->c_slot)) {
 	case ERR_DF:
 	case TIMEOUT:
 		aprint_error("%s channel %d: setting WDCTL_RST failed "
@@ -760,7 +769,7 @@ again:
 	cmd_tbl->cmdt_cfis[fis_type] = RHD_FISTYPE;
 	cmd_tbl->cmdt_cfis[rhd_c] = drive;
 	cmd_tbl->cmdt_cfis[rhd_control] = 0;
-	switch(ahci_exec_fis(chp, 310, flags)) {
+	switch(ahci_exec_fis(chp, 310, flags, xfer->c_slot)) {
 	case ERR_DF:
 	case TIMEOUT:
 		if ((sc->sc_ahci_quirks & AHCI_QUIRK_BADPMPRESET) != 0 &&
@@ -811,6 +820,8 @@ skip_reset:
 	AHCINAME(sc), chp->ch_channel, sig,
 	AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))), DEBUG_PROBE);
 end:
+	if (xfer != NULL)
+		ata_free_xfer(chp, xfer);
 	ahci_channel_stop(sc, chp, flags);
 	ata_delay(500, "ahcirst", flags);
 	/* clear port interrupt register */



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

2017-07-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 19 20:24:59 UTC 2017

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

Log Message:
forced commit to get into history - previous commit removed also
the siisata-specific downgrade of SATA channel speed on CRC, as it
doesn't really fit with error/state not being available after
c_intr(); as noted this handling should be in generic code, and
it's overly harsh to do this after single error anyway, particularly
since there is no way to get back


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.26 -r1.30.4.27 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.30.4.26 src/sys/dev/ic/siisata.c:1.30.4.27
--- src/sys/dev/ic/siisata.c:1.30.4.26	Wed Jul 19 20:02:40 2017
+++ src/sys/dev/ic/siisata.c	Wed Jul 19 20:24:59 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.26 2017/07/19 20:02:40 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.27 2017/07/19 20:24:59 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.26 2017/07/19 20:02:40 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.27 2017/07/19 20:24:59 jdolecek Exp $");
 
 #include 
 #include 



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

2017-07-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 19 20:21:42 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: ahcisata_core.c ahcisatareg.h
ahcisatavar.h

Log Message:
update error handling:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
  ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
  to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

ahcisata-specific tweaks:
- add some handling for PM in the error recovery using FBS register,
  according to spec it should be independant of actual FBSS feature; untested
  as my hw doesn't support PM


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.17 -r1.57.6.18 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.12 -r1.12.26.1 src/sys/dev/ic/ahcisatareg.h
cvs rdiff -u -r1.17 -r1.17.6.1 src/sys/dev/ic/ahcisatavar.h

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.57.6.17 src/sys/dev/ic/ahcisata_core.c:1.57.6.18
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.17	Tue Jun 27 18:36:03 2017
+++ src/sys/dev/ic/ahcisata_core.c	Wed Jul 19 20:21:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.17 2017/06/27 18:36:03 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.18 2017/07/19 20:21:42 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.17 2017/06/27 18:36:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.18 2017/07/19 20:21:42 jdolecek Exp $");
 
 #include 
 #include 
@@ -68,7 +68,7 @@ static void ahci_killpending(struct ata_
 
 static void ahci_cmd_start(struct ata_channel *, struct ata_xfer *);
 static int  ahci_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
-static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *);
+static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *, int);
 static void ahci_cmd_done_end(struct ata_channel *, struct ata_xfer *);
 static void ahci_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
 static void ahci_bio_start(struct ata_channel *, struct ata_xfer *);
@@ -77,7 +77,7 @@ static void ahci_bio_kill_xfer(struct at
 static void ahci_channel_stop(struct ahci_softc *, struct ata_channel *, int);
 static void ahci_channel_start(struct ahci_softc *, struct ata_channel *,
 int, int);
-static void ahci_timeout(void *);
+static void ahci_channel_recover(struct ahci_softc *, struct ata_channel *);
 static int  ahci_dma_setup(struct ata_channel *, int, void *, size_t, int);
 
 #if NATAPIBUS > 0
@@ -566,8 +566,11 @@ ahci_intr_port(struct ahci_softc *sc, st
 
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), is);
-	AHCIDEBUG_PRINT(("ahci_intr_port %s port %d is 0x%x CI 0x%x\n", AHCINAME(sc),
-	chp->ch_channel, is, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
+	AHCIDEBUG_PRINT(("ahci_intr_port %s port %d is 0x%x CI 0x%x TFD 0x%x\n",
+	AHCINAME(sc),
+	chp->ch_channel, is,
+	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)),
+	AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel))),
 	DEBUG_INTR);
 
 	active = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))
@@ -584,38 +587,50 @@ ahci_intr_port(struct ahci_softc *sc, st
 	}
 
 	/* Handle errors */
-	if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_IFS |
-	AHCI_P_IX_OFS | AHCI_P_IX_UFS)) {
-		/* stop channel */
-		ahci_channel_stop(sc, chp, 0);
+	if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_HBDS |
+	AHCI_P_IX_IFS | AHCI_P_IX_OFS | AHCI_P_IX_UFS)) {
 		if (is & AHCI_P_IX_TFES) {
 			tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
-			chp->ch_error =
-			(tfd & AHCI_P_TFD_ERR_MASK) >> AHCI_P_TFD_ERR_SHIFT;
-			chp->ch_status = (tfd & 0xff);
+
+			if ((AHCI_TFD_ST(tfd) & (WDCS_DRQ|WDCS_BSY)) == 0 &&
+			!achp->ahcic_recovering)
+goto recover;
+
+			aprint_error("%s port %d: active %x is 0x%x tfd 0x%x\n",
+			AHCINAME(sc), chp->ch_channel, active, is, tfd);
 		} else {
 			/* emulate a CRC error */
-			chp->ch_error = WDCE_CRC;
-			chp->ch_status = WDCS_ERR;
+			tfd = (WDCE_CRC << AHCI_P_TFD_ERR_SHIFT) | WDCS_ERR;
 		}
+
 		if (is & AHCI_P_IX_IFS) {
 			aprint_error("%s port %d: SERR 0x%x\n",
 			AHCINAME(sc), chp->ch_channel,
 			AHCI_READ(sc, AHCI_P_SERR(chp->ch_channel)));
 		}
-		/* complete all pending commands with error statuses */
-		for (slot=0; slot < sc->sc_ncmds; slot++) {
-			if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-continue;
-			if ((active & (1 << slot)) == 1) {
-xfer = ata_queue_hwslot_to_xfer(chp, slot);
-xfer->c_intr(chp, xfer, is);
-			}
+
+		/* Request channel reset */
+		ata_reset_channel(chp, 0);
+		return;
+	} else if (is & (AHCI_P_IX_DHRS|AHCI_P_IX_SDBS)) {
+	

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

2017-07-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 19 20:03:29 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: siisatareg.h siisatavar.h

Log Message:
header changes for siisata switch to new error handling world order


To generate a diff of this commit:
cvs rdiff -u -r1.7.42.2 -r1.7.42.3 src/sys/dev/ic/siisatareg.h
cvs rdiff -u -r1.6.48.1 -r1.6.48.2 src/sys/dev/ic/siisatavar.h

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/siisatareg.h
diff -u src/sys/dev/ic/siisatareg.h:1.7.42.2 src/sys/dev/ic/siisatareg.h:1.7.42.3
--- src/sys/dev/ic/siisatareg.h:1.7.42.2	Mon Jun 12 23:51:40 2017
+++ src/sys/dev/ic/siisatareg.h	Wed Jul 19 20:03:29 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatareg.h,v 1.7.42.2 2017/06/12 23:51:40 jakllsch Exp $ */
+/* $NetBSD: siisatareg.h,v 1.7.42.3 2017/07/19 20:03:29 jdolecek Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2010, 2011 Jonathan A. Kollasch.
@@ -164,6 +164,8 @@ struct siisata_prb {
 #define PRSO_RTC	0x04		/* recieved transfer count */
 #define PRSO_FIS	0x08		/* base of FIS */
 
+#define PRO_PMPSTS(i)	(0x0f80 + i * 8)
+#define PRO_PMPQACT(i)	(0x0f80 + i * 8 + 4)
 #define PRO_PCS		0x1000		/* (write) port control set */
 #define PRO_PS		PRO_PCS		/* (read) port status */
 #define PRO_PCC		0x1004		/* port control clear */
@@ -186,6 +188,7 @@ struct siisata_prb {
 #define PRO_CARX(p,s) (PRX(p, PRO_CAR) + (s) * sizeof(uint64_t))
 
 #define PRO_PCR		0x1e04		/* port context register */
+#define PRO_PCR_PMP(x)	(((x) & __BITS(8, 5)) >> 5) /* PM Port */
 #define PRO_SCONTROL	0x1f00		/* SControl */
 #define PRO_SSTATUS	0x1f04		/* SStatus */
 #define PRO_SERROR	0x1f08		/* SError */

Index: src/sys/dev/ic/siisatavar.h
diff -u src/sys/dev/ic/siisatavar.h:1.6.48.1 src/sys/dev/ic/siisatavar.h:1.6.48.2
--- src/sys/dev/ic/siisatavar.h:1.6.48.1	Tue Jun 13 00:02:19 2017
+++ src/sys/dev/ic/siisatavar.h	Wed Jul 19 20:03:29 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatavar.h,v 1.6.48.1 2017/06/13 00:02:19 jakllsch Exp $ */
+/* $NetBSD: siisatavar.h,v 1.6.48.2 2017/07/19 20:03:29 jdolecek Exp $ */
 
 /* from ahcisatavar.h */
 
@@ -101,6 +101,8 @@ struct siisata_softc {
 		bus_dmamap_t sch_datad[SIISATA_MAX_SLOTS];
 
 		uint32_t sch_active_slots;
+		uint32_t sch_hold_slots;
+		bool sch_recovering;
 	} sc_channels[SIISATA_MAX_PORTS];
 };
 



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

2017-07-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 19 20:02:40 UTC 2017

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

Log Message:
convert over to new error handling world order:
- switch to ata_timeout()
- stop using ch_status/ch_error for passing state/error, stop setting
  ATACH_IRQ_WAIT in ch_flags; pass the state via the last parameter
  to c_intr() routine
- add NCQ recovery and KILL_REQUEUE
- only call atastart() in c_intr() if there was no error

several siisata specific tweaks:
- improve reset to better handle PM - need to reset couple more registers
- add timeouts for unbusy wait - ATA_DELAY (10s)
- siisata_bio_complete() do not use PRSO_RTC for byte count for NCQ transfers,
  they never return partial reads; and that register might contain some random
  junk, at least that's the case with ahcisata cmdh_prdbc


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.25 -r1.30.4.26 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.30.4.25 src/sys/dev/ic/siisata.c:1.30.4.26
--- src/sys/dev/ic/siisata.c:1.30.4.25	Tue Jun 27 20:13:56 2017
+++ src/sys/dev/ic/siisata.c	Wed Jul 19 20:02:40 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.25 2017/06/27 20:13:56 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.26 2017/07/19 20:02:40 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.25 2017/06/27 20:13:56 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.26 2017/07/19 20:02:40 jdolecek Exp $");
 
 #include 
 #include 
@@ -148,7 +148,7 @@ void siisata_killpending(struct ata_driv
 
 void siisata_cmd_start(struct ata_channel *, struct ata_xfer *);
 int siisata_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
-void siisata_cmd_done(struct ata_channel *, struct ata_xfer *);
+void siisata_cmd_done(struct ata_channel *, struct ata_xfer *, int);
 static void siisata_cmd_done_end(struct ata_channel *, struct ata_xfer *);
 void siisata_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
 
@@ -157,14 +157,12 @@ int siisata_bio_complete(struct ata_chan
 void siisata_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
 int siisata_exec_command(struct ata_drive_datas *, struct ata_xfer *);
 
-void siisata_timeout(void *);
-
 static void siisata_reinit_port(struct ata_channel *);
 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);
-static int siisata_dma_setup(struct ata_channel *chp, int, void *,
-size_t, int);
+static int siisata_dma_setup(struct ata_channel *, int, void *, size_t, int);
+static void siisata_channel_recover(struct ata_channel *, int, int);
 
 #if NATAPIBUS > 0
 void siisata_atapibus_attach(struct atabus_softc *);
@@ -478,7 +476,6 @@ siisata_intr_port(struct siisata_channel
 	struct ata_xfer *xfer;
 	u_int slot;
 	uint32_t pss, pis;
-	uint32_t prbfis;
 
 	sc = (struct siisata_softc *)schp->ata_channel.ch_atac;
 	chp = >ata_channel;
@@ -489,12 +486,15 @@ siisata_intr_port(struct siisata_channel
 	SIISATANAME(sc), __func__, chp->ch_channel, pss), DEBUG_INTR);
 
 	for (slot = 0; slot < SIISATA_MAX_SLOTS; slot++) {
-		if (((schp->sch_active_slots >> slot) & 1) == 0)
+		if (((schp->sch_active_slots >> slot) & 1) == 0) {
 			/* there's nothing executing here, skip */
 			continue;
-		if (((pss >> slot) & 1) != 0)
-			/* execution is incomplete or unsuccessful, skip for now */
+		}
+		if (((pss >> slot) & 1) != 0) {
+			/* execution is incomplete or unsuccessful, skip
+			 * for now */
 			continue;
+		}
 		xfer = ata_queue_hwslot_to_xfer(chp, slot);
 		if (xfer->c_intr == NULL) {
 			wakeup(schp);
@@ -520,54 +520,145 @@ siisata_intr_port(struct siisata_channel
 	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ", SIISATANAME(sc),
 	__func__, chp->ch_channel, pis), DEBUG_INTR);
 
+	/* clear */
+	PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), pis);
+
 	if (pis & PR_PIS_CMDERRR) {
 		uint32_t ec;
-		uint32_t ps;
 
-		ps = PRREAD(sc, PRX(chp->ch_channel, PRO_PS));
 		ec = PRREAD(sc, PRX(chp->ch_channel, PRO_PCE));
 		SIISATA_DEBUG_PRINT(("ec %d\n", ec), DEBUG_INTR);
 
-		slot = PR_PS_ACTIVE_SLOT(ps); /* XXX invalid for NCQ? */
-
 		/* emulate a CRC error by default */
-		chp->ch_status = WDCS_ERR;
-		chp->ch_error = WDCE_CRC;
+		int tfd = ATACH_ERR_ST(WDCE_CRC, WDCS_ERR);
 
-		if (ec <= PR_PCE_DATAFISERROR) {
-			if (ec == PR_PCE_DEVICEERROR) {
-/* read in specific information about error */
-prbfis = bus_space_read_stream_4(
-sc->sc_prt, sc->sc_prh,
-				PRSX(chp->ch_channel, slot,
-PRSO_FIS));
-/* set ch_status and ch_error */
-satafis_rdh_parse(chp, (uint8_t *));
-			}
-			

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

2017-06-28 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jun 28 19:59:36 UTC 2017

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

Log Message:
enable ATAPI on mvsata(4); it seems to work fine for my cdrom


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.17 -r1.35.6.18 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.35.6.17 src/sys/dev/ic/mvsata.c:1.35.6.18
--- src/sys/dev/ic/mvsata.c:1.35.6.17	Tue Jun 27 18:36:03 2017
+++ src/sys/dev/ic/mvsata.c	Wed Jun 28 19:59:36 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.17 2017/06/27 18:36:03 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.18 2017/06/28 19:59:36 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.17 2017/06/27 18:36:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.18 2017/06/28 19:59:36 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -760,10 +760,8 @@ mvsata_atapibus_attach(struct atabus_sof
 	chan->chan_ntargets = 1;
 	chan->chan_nluns = 1;
 
-#if 0 /* XXX ATAPI implementation not finished. */
 	chp->atapibus =
 	config_found_ia(ata_sc->sc_dev, "atapi", chan, atapiprint);
-#endif
 }
 
 static void



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

2017-06-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jun 27 20:13:56 UTC 2017

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

Log Message:
need to explicitely call siisata_timeout() also for polled bio command when
it times out to clean up; this should avoid the 'polled command has been
queued' panic from wddump()


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.24 -r1.30.4.25 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.30.4.24 src/sys/dev/ic/siisata.c:1.30.4.25
--- src/sys/dev/ic/siisata.c:1.30.4.24	Tue Jun 27 18:36:04 2017
+++ src/sys/dev/ic/siisata.c	Tue Jun 27 20:13:56 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.24 2017/06/27 18:36:04 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.25 2017/06/27 20:13:56 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.24 2017/06/27 18:36:04 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.25 2017/06/27 20:13:56 jdolecek Exp $");
 
 #include 
 #include 
@@ -1169,6 +1169,10 @@ siisata_bio_start(struct ata_channel *ch
 		DELAY(100);
 	}
 
+	if ((ata_bio->flags & ATA_ITSDONE) == 0) {
+		siisata_timeout(xfer);
+	}
+
 	siisata_enable_port_interrupt(chp);
 out:
 	SIISATA_DEBUG_PRINT(("%s: %s: done\n",



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

2017-06-26 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 26 20:36:14 UTC 2017

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

Log Message:
when reducing DELAY(), it's necessary to appropriately increase number
of iteration, or command can timeout too soon

adjust also siisata_atapi_start() to use DELAY(100) for the polled command,
mostly for consistency, ATAPI devices are quite slow so likely won't have
real effect


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.22 -r1.30.4.23 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.30.4.22 src/sys/dev/ic/siisata.c:1.30.4.23
--- src/sys/dev/ic/siisata.c:1.30.4.22	Sat Jun 24 11:34:33 2017
+++ src/sys/dev/ic/siisata.c	Mon Jun 26 20:36:14 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.22 2017/06/24 11:34:33 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.23 2017/06/26 20:36:14 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.22 2017/06/24 11:34:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.23 2017/06/26 20:36:14 jdolecek Exp $");
 
 #include 
 #include 
@@ -944,7 +944,7 @@ siisata_cmd_start(struct ata_channel *ch
 	/*
 	 * polled command
 	 */
-	for (i = 0; i < ata_c->timeout / 10; i++) {
+	for (i = 0; i < ata_c->timeout * 10; i++) {
 		if (ata_c->flags & AT_DONE)
 			break;
 		siisata_intr_port(schp);
@@ -1148,7 +1148,7 @@ siisata_bio_start(struct ata_channel *ch
 	/*
 	 * polled command
 	 */
-	for (i = 0; i < ATA_DELAY / 10; i++) {
+	for (i = 0; i < ATA_DELAY * 10; i++) {
 		if (ata_bio->flags & ATA_ITSDONE)
 			break;
 		siisata_intr_port(schp);
@@ -1693,11 +1693,11 @@ siisata_atapi_start(struct ata_channel *
 	/*
 	 * polled command
 	 */
-	for (i = 0; i < ATA_DELAY / 10; i++) {
+	for (i = 0; i < ATA_DELAY * 10; i++) {
 		if (sc_xfer->xs_status & XS_STS_DONE)
 			break;
 		siisata_intr_port(schp);
-		DELAY(1000);
+		DELAY(100);
 	}
 	if ((sc_xfer->xs_status & XS_STS_DONE) == 0) {
 		siisata_timeout(xfer);



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

2017-06-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 24 14:59:10 UTC 2017

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

Log Message:
fix confusion around AT_WAIT vs AT_POLL for mvsata_edma_disable(), and switch
all the tsleep()/delay() ifs to just use ata_delay()


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.15 -r1.35.6.16 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.35.6.15 src/sys/dev/ic/mvsata.c:1.35.6.16
--- src/sys/dev/ic/mvsata.c:1.35.6.15	Sat Jun 24 14:33:06 2017
+++ src/sys/dev/ic/mvsata.c	Sat Jun 24 14:59:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.15 2017/06/24 14:33:06 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.16 2017/06/24 14:59:10 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.15 2017/06/24 14:33:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.16 2017/06/24 14:59:10 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1081,7 +1081,7 @@ mvsata_bio_start(struct ata_channel *chp
 	struct wdc_softc *wdc = CHAN_TO_WDC(chp);
 	struct ata_bio *ata_bio = >c_bio;
 	struct ata_drive_datas *drvp = >ch_drive[xfer->c_drive];
-	int wait_flags = (xfer->c_flags & C_POLL) ? AT_POLL : 0;
+	int wait_flags =  ata_bio->flags & AT_WAIT;
 	u_int16_t cyl;
 	u_int8_t head, sect, cmd = 0;
 	int nblks, error;
@@ -3206,10 +3206,10 @@ mvsata_reset_hc(struct mvsata_hc *mvhc)
 #define WDCNDELAY_RST (WDC_RESET_WAIT * 1000 / WDCDELAY)
 
 static uint32_t
-mvsata_softreset(struct mvsata_port *mvport, int waitok)
+mvsata_softreset(struct mvsata_port *mvport, int flags)
 {
 	uint32_t sig0 = ~0;
-	int timeout, nloop;
+	int timeout;
 	uint8_t st0;
 
 	MVSATA_WDC_WRITE_1(mvport, SRB_CAS, WDCTL_RST | WDCTL_IDS | WDCTL_4BIT);
@@ -3218,13 +3218,8 @@ mvsata_softreset(struct mvsata_port *mvp
 	MVSATA_WDC_WRITE_1(mvport, SRB_CAS, WDCTL_IDS | WDCTL_4BIT);
 	delay(10);
 
-	if (!waitok)
-		nloop = WDCNDELAY_RST;
-	else
-		nloop = WDC_RESET_WAIT * hz / 1000;
-
 	/* wait for BSY to deassert */
-	for (timeout = 0; timeout < nloop; timeout++) {
+	for (timeout = 0; timeout < WDCNDELAY_RST; timeout++) {
 		st0 = MVSATA_WDC_READ_1(mvport, SRB_CS);
 
 		if ((st0 & WDCS_BSY) == 0) {
@@ -3234,10 +3229,7 @@ mvsata_softreset(struct mvsata_port *mvp
 			sig0 |= MVSATA_WDC_READ_1(mvport, SRB_LBAH) << 24;
 			goto out;
 		}
-		if (!waitok)
-			delay(WDCDELAY);
-		else
-			tsleep(, PRIBIO, "atarst", 1);
+		ata_delay(WDCDELAY, "atarst", flags);
 	}
 	
 out:
@@ -3270,7 +3262,7 @@ mvsata_edma_enable(struct mvsata_port *m
 }
 
 static int
-mvsata_edma_disable(struct mvsata_port *mvport, int timeout, int waitok)
+mvsata_edma_disable(struct mvsata_port *mvport, int timeout, int wflags)
 {
 	uint32_t status, command;
 	int ms;
@@ -3280,11 +3272,7 @@ mvsata_edma_disable(struct mvsata_port *
 			status = MVSATA_EDMA_READ_4(mvport, EDMA_S);
 			if (status & EDMA_S_EDMAIDLE)
 break;
-			if (waitok)
-tsleep(, PRIBIO, "mvsata_edma1",
-mstohz(1));
-			else
-delay(1000);
+			ata_delay(1, "mvsata_edma1", wflags);
 		}
 		if (ms == timeout) {
 			aprint_error("%s:%d:%d: unable to disable EDMA\n",
@@ -3300,11 +3288,7 @@ mvsata_edma_disable(struct mvsata_port *
 			command = MVSATA_EDMA_READ_4(mvport, EDMA_CMD);
 			if (!(command & EDMA_CMD_EENEDMA))
 break;
-			if (waitok)
-tsleep(, PRIBIO, "mvsata_edma2",
-mstohz(1));
-			else
-delay(1000);
+			ata_delay(1, "mvsata_edma2", wflags);
 		}
 		if (ms == timeout) {
 			aprint_error("%s:%d:%d: unable to re-enable EDMA\n",



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

2017-06-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 24 11:34:33 UTC 2017

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

Log Message:
reduce the polling interval also for siisata_cmd_start()


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.21 -r1.30.4.22 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.30.4.21 src/sys/dev/ic/siisata.c:1.30.4.22
--- src/sys/dev/ic/siisata.c:1.30.4.21	Fri Jun 23 23:49:20 2017
+++ src/sys/dev/ic/siisata.c	Sat Jun 24 11:34:33 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.21 2017/06/23 23:49:20 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.22 2017/06/24 11:34:33 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.21 2017/06/23 23:49:20 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.22 2017/06/24 11:34:33 jdolecek Exp $");
 
 #include 
 #include 
@@ -948,7 +948,7 @@ siisata_cmd_start(struct ata_channel *ch
 		if (ata_c->flags & AT_DONE)
 			break;
 		siisata_intr_port(schp);
-		DELAY(1000);
+		DELAY(100);
 	}
 
 	if ((ata_c->flags & AT_DONE) == 0) {



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

2017-06-23 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Jun 23 23:45:56 UTC 2017

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

Log Message:
ata/TODO.ncq


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.19 -r1.30.4.20 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.30.4.19 src/sys/dev/ic/siisata.c:1.30.4.20
--- src/sys/dev/ic/siisata.c:1.30.4.19	Wed Jun 21 19:38:43 2017
+++ src/sys/dev/ic/siisata.c	Fri Jun 23 23:45:56 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.19 2017/06/21 19:38:43 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.20 2017/06/23 23:45:56 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.19 2017/06/21 19:38:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.20 2017/06/23 23:45:56 jdolecek Exp $");
 
 #include 
 #include 
@@ -590,6 +590,7 @@ siisata_reset_drive(struct ata_drive_dat
 	 */
 	xfer = ata_get_xfer_ext(chp, false, 0);
 	if (xfer == NULL) {
+		printf("%s: no xfer\n", __func__);
 		siisata_reset_channel(chp, flags);
 		return;
 	}
@@ -1151,7 +1152,7 @@ siisata_bio_start(struct ata_channel *ch
 		if (ata_bio->flags & ATA_ITSDONE)
 			break;
 		siisata_intr_port(schp);
-		DELAY(1000);
+		DELAY(100);
 	}
 
 	siisata_enable_port_interrupt(chp);
@@ -1245,8 +1246,6 @@ siisata_bio_complete(struct ata_channel 
 			ata_bio->bcount = 0;
 	}
 	SIISATA_DEBUG_PRINT((" now %ld\n", ata_bio->bcount), DEBUG_XFERS);
-	if (ata_bio->flags & ATA_POLL)
-		return 1;
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc, xfer);
 	atastart(chp);
 	return 0;



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

2017-06-20 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jun 20 21:00:47 UTC 2017

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

Log Message:
remove ata queue downsizing - every device, attached to the same channel,
uses slots according to it's own limits

wdc code changed to expect maximum one active xfer, and not check number
of openings in the channel; this is to facilitate using wdc functions
for e.g. handling of atapi commands  for drivers which support both ATAPI
and NCQ

siisata(4) part, including fix to hang on drive probe (missing ata_free_xfer())


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.17 -r1.30.4.18 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.30.4.17 src/sys/dev/ic/siisata.c:1.30.4.18
--- src/sys/dev/ic/siisata.c:1.30.4.17	Mon Jun 19 21:00:00 2017
+++ src/sys/dev/ic/siisata.c	Tue Jun 20 21:00:47 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.17 2017/06/19 21:00:00 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.18 2017/06/20 21:00:47 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.17 2017/06/19 21:00:00 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.18 2017/06/20 21:00:47 jdolecek Exp $");
 
 #include 
 #include 
@@ -588,7 +588,7 @@ siisata_reset_drive(struct ata_drive_dat
 	 * Try to get available slot. If there is none available, must
 	 * do full channel reset.
 	 */
-	xfer = ata_get_xfer(chp, false);
+	xfer = ata_get_xfer_ext(chp, false, 0);
 	if (xfer == NULL) {
 		siisata_reset_channel(chp, flags);
 		return;
@@ -738,7 +738,7 @@ siisata_probe_drive(struct ata_channel *
 	SIISATA_DEBUG_PRINT(("%s: %s: port %d start\n", SIISATANAME(sc),
 	__func__, chp->ch_channel), DEBUG_FUNCS);
 
-	xfer = ata_get_xfer(chp, true);
+	xfer = ata_get_xfer(chp);
 	if (xfer == NULL) {
 		aprint_error_dev(sc->sc_atac.atac_dev,
 		"failed to get xfer port %d\n",
@@ -821,6 +821,9 @@ siisata_probe_drive(struct ata_channel *
 	}
 
 	siisata_enable_port_interrupt(chp);
+
+	ata_free_xfer(chp, xfer);
+
 	SIISATA_DEBUG_PRINT(("%s: %s: port %d done\n", SIISATANAME(sc),
 	__func__, chp->ch_channel), DEBUG_PROBE);
 	return;
@@ -1597,7 +1600,7 @@ siisata_atapi_scsipi_request(struct scsi
 			scsipi_done(sc_xfer);
 			return;
 		}
-		xfer = ata_get_xfer(atac->atac_channels[channel], false);
+		xfer = ata_get_xfer_ext(atac->atac_channels[channel], false, 0);
 		if (xfer == NULL) {
 			sc_xfer->error = XS_RESOURCE_SHORTAGE;
 			scsipi_done(sc_xfer);



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

2017-06-13 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jun 13 19:15:32 UTC 2017

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

Log Message:
use MVSATA_EDMAQ_LEN instead of magic number for number of queue slots


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.9 -r1.35.6.10 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.35.6.9 src/sys/dev/ic/mvsata.c:1.35.6.10
--- src/sys/dev/ic/mvsata.c:1.35.6.9	Mon Jun 12 21:38:50 2017
+++ src/sys/dev/ic/mvsata.c	Tue Jun 13 19:15:32 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.9 2017/06/12 21:38:50 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.10 2017/06/13 19:15:32 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.9 2017/06/12 21:38:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.10 2017/06/13 19:15:32 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -2881,7 +2881,7 @@ mvsata_port_init(struct mvsata_hc *mvhc,
 	chp = >port_ata_channel;
 	chp->ch_channel = channel;
 	chp->ch_atac = >sc_wdcdev.sc_atac;
-	chp->ch_queue = ata_queue_alloc(32);
+	chp->ch_queue = ata_queue_alloc(MVSATA_EDMAQ_LEN);
 	sc->sc_ata_channels[channel] = chp;
 
 	rv = mvsata_wdc_reg_init(mvport, sc->sc_wdcdev.regs + channel);



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

2017-06-12 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Jun 12 23:51:41 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: siisatareg.h

Log Message:
Macro argument parentheses paranoia.
Annotate another register initialism.


To generate a diff of this commit:
cvs rdiff -u -r1.7.42.1 -r1.7.42.2 src/sys/dev/ic/siisatareg.h

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/siisatareg.h
diff -u src/sys/dev/ic/siisatareg.h:1.7.42.1 src/sys/dev/ic/siisatareg.h:1.7.42.2
--- src/sys/dev/ic/siisatareg.h:1.7.42.1	Mon Apr 24 13:05:26 2017
+++ src/sys/dev/ic/siisatareg.h	Mon Jun 12 23:51:40 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatareg.h,v 1.7.42.1 2017/04/24 13:05:26 jakllsch Exp $ */
+/* $NetBSD: siisatareg.h,v 1.7.42.2 2017/06/12 23:51:40 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2010, 2011 Jonathan A. Kollasch.
@@ -181,9 +181,9 @@ struct siisata_prb {
 #define PRO_PPHYC	0x1050		/* phy config */
 #define PRO_PSS		0x1800		/* port slot status */
 /* technically this is a shadow of the CAR */
-#define PRO_CAR		0x1c00
+#define PRO_CAR		0x1c00		/* command activation register */
 
-#define PRO_CARX(p,s) (PRX(p, PRO_CAR) + s * sizeof(uint64_t))
+#define PRO_CARX(p,s) (PRX(p, PRO_CAR) + (s) * sizeof(uint64_t))
 
 #define PRO_PCR		0x1e04		/* port context register */
 #define PRO_SCONTROL	0x1f00		/* SControl */



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

2017-06-12 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 12 21:38:50 UTC 2017

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

Log Message:
add support for NCQ on Gen IIe hardware

mvsata_quetag_get()/put() pairs adjusted to work also for non-DMA code paths,
i.e. during probe; replaced wdcintr() call with local routine which uses
currently active command tag, rather than assuming always tag 0 on that
code path

~55MB/s -> ~80MB/s sequential read using fio(1) on a test HDD, quite nice


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.8 -r1.35.6.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.35.6.8 src/sys/dev/ic/mvsata.c:1.35.6.9
--- src/sys/dev/ic/mvsata.c:1.35.6.8	Sat Jun 10 13:25:51 2017
+++ src/sys/dev/ic/mvsata.c	Mon Jun 12 21:38:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.8 2017/06/10 13:25:51 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.9 2017/06/12 21:38:50 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.8 2017/06/10 13:25:51 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.9 2017/06/12 21:38:50 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -159,6 +159,8 @@ static void mvsata_bdma_start(struct mvs
 #endif
 #endif
 
+static int mvsata_nondma_handle(struct mvsata_port *);
+
 static int mvsata_port_init(struct mvsata_hc *, int);
 static int mvsata_wdc_reg_init(struct mvsata_port *, struct wdc_regs *);
 #ifndef MVSATA_WITHOUTDMA
@@ -289,6 +291,7 @@ mvsata_attach(struct mvsata_softc *sc, s
 		_fix_phy = mvsata_fix_phy_gen2;
 #ifndef MVSATA_WITHOUTDMA
 		edma_setup_crqb = mvsata_edma_setup_crqb_gen2e;
+		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NCQ;
 #endif
 		break;
 	}
@@ -401,6 +404,7 @@ mvsata_intr(struct mvsata_hc *mvhc)
 	if (cause & SATAHC_IC_SAINTCOAL)
 		MVSATA_HC_WRITE_4(mvhc, SATAHC_IC, ~SATAHC_IC_SAINTCOAL);
 	cause &= ~SATAHC_IC_SAINTCOAL;
+
 	for (port = 0; port < sc->sc_port; port++) {
 		mvport = mvhc->hc_ports[port];
 
@@ -413,7 +417,7 @@ mvsata_intr(struct mvsata_hc *mvhc)
 		}
 
 		if (cause & SATAHC_IC_SADEVINTERRUPT(port)) {
-			wdcintr(>port_ata_channel);
+			(void) mvsata_nondma_handle(mvport);
 			MVSATA_HC_WRITE_4(mvhc, SATAHC_IC,
 			~SATAHC_IC_SADEVINTERRUPT(port));
 			handled = 1;
@@ -423,6 +427,35 @@ mvsata_intr(struct mvsata_hc *mvhc)
 	return handled;
 }
 
+static int
+mvsata_nondma_handle(struct mvsata_port *mvport)
+{
+	struct ata_channel *chp = >port_ata_channel;
+	struct ata_xfer *xfer;
+	int ret, quetag;
+
+	/*
+	 * The chip doesn't support several pending non-DMA commands,
+	 * and the ata middle layer never issues several non-NCQ commands,
+	 * so there must be exactly one active command at this moment.
+	 */
+	for (quetag = 0; quetag < MVSATA_EDMAQ_LEN; quetag++) {
+		if ((mvport->port_quetagidx & __BIT(quetag)) == 0)
+			continue;
+
+		break;
+	}
+	KASSERT(quetag < MVSATA_EDMAQ_LEN);
+
+	xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, quetag);
+	chp->ch_flags &= ~ATACH_IRQ_WAIT;
+	KASSERT(xfer->c_intr != NULL);
+	ret = xfer->c_intr(chp, xfer, 1);
+	if (ret == 0) /* irq was not for us, still waiting for irq */
+		chp->ch_flags |= ATACH_IRQ_WAIT;
+	return (ret);
+}
+
 int
 mvsata_error(struct mvsata_port *mvport)
 {
@@ -528,6 +561,7 @@ static int
 mvsata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
 	struct ata_channel *chp = drvp->chnl_softc;
+	struct mvsata_port *mvport = (struct mvsata_port *)chp;
 	struct atac_softc *atac = chp->ch_atac;
 	struct ata_bio *ata_bio = >c_bio;
 
@@ -535,6 +569,8 @@ mvsata_bio(struct ata_drive_datas *drvp,
 	", bcount=%ld\n", device_xname(atac->atac_dev), chp->ch_channel,
 	drvp->drive, ata_bio->blkno, ata_bio->bcount));
 
+	mvsata_quetag_get(mvport, xfer->c_slot);
+
 	if (atac->atac_cap & ATAC_CAP_NOIRQ)
 		ata_bio->flags |= ATA_POLL;
 	if (ata_bio->flags & ATA_POLL)
@@ -636,9 +672,7 @@ static int
 mvsata_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
 	struct ata_channel *chp = drvp->chnl_softc;
-#ifdef MVSATA_DEBUG
 	struct mvsata_port *mvport = (struct mvsata_port *)chp;
-#endif
 	struct ata_command *ata_c = >c_ata_c;
 	int rv, s;
 
@@ -649,6 +683,8 @@ mvsata_exec_command(struct ata_drive_dat
 	drvp->drive, ata_c->bcount, ata_c->r_lba, ata_c->r_count,
 	ata_c->r_features, ata_c->r_device, ata_c->r_command));
 
+	mvsata_quetag_get(mvport, xfer->c_slot);
+
 	if (ata_c->flags & AT_POLL)
 		xfer->c_flags |= C_POLL;
 	if (ata_c->flags & AT_WAIT)
@@ -747,8 +783,9 @@ mvsata_atapi_scsipi_request(struct scsip
 	struct scsipi_xfer *sc_xfer;
 	struct mvsata_softc *sc = device_private(adapt->adapt_dev);
 	struct atac_softc *atac = >sc_wdcdev.sc_atac;
+	struct ata_channel *chp = atac->atac_channels[chan->chan_channel];
 	

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

2017-06-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 10 13:25:51 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: mvsata.c mvsatareg.h

Log Message:
use satafis routine to build the command block for Gen IIe to reduce code
duplication


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.7 -r1.35.6.8 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.3 -r1.3.28.1 src/sys/dev/ic/mvsatareg.h

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.35.6.7 src/sys/dev/ic/mvsata.c:1.35.6.8
--- src/sys/dev/ic/mvsata.c:1.35.6.7	Fri Jun  9 20:18:58 2017
+++ src/sys/dev/ic/mvsata.c	Sat Jun 10 13:25:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.7 2017/06/09 20:18:58 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.8 2017/06/10 13:25:51 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.7 2017/06/09 20:18:58 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.8 2017/06/10 13:25:51 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -46,6 +46,8 @@ __KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -3632,59 +3634,30 @@ mvsata_edma_setup_crqb_gen2e(struct mvsa
 {
 	struct crqb_gen2e *crqb;
 	bus_addr_t eprd_addr;
-	daddr_t blkno;
 	uint32_t ctrlflg, rw;
-	uint8_t cmd, head;
-	struct ata_bio  *ata_bio = >c_bio;
+	uint8_t fis[RHD_FISLEN];
 
 	eprd_addr = mvport->port_eprd_dmamap->dm_segs[0].ds_addr +
 	mvport->port_reqtbl[xfer->c_slot].eprd_offset;
-	rw = (ata_bio->flags & ATA_READ) ? CRQB_CDIR_READ : CRQB_CDIR_WRITE;
+	rw = (xfer->c_bio.flags & ATA_READ) ? CRQB_CDIR_READ : CRQB_CDIR_WRITE;
 	ctrlflg = (rw | CRQB_CDEVICEQUETAG(0) | /* XXX slot */
 	CRQB_CPMPORT(xfer->c_drive) |
 	CRQB_CPRDMODE_EPRD | CRQB_CHOSTQUETAG_GEN2(xfer->c_slot));
-	cmd = (ata_bio->flags & ATA_READ) ? WDCC_READDMA : WDCC_WRITEDMA;
-	if (ata_bio->flags & (ATA_LBA|ATA_LBA48)) {
-		head = WDSD_LBA;
-	} else {
-		head = 0;
-	}
-	blkno = ata_bio->blkno;
-	if (ata_bio->flags & ATA_LBA48)
-		cmd = atacmd_to48(cmd);
-	else {
-		head |= ((ata_bio->blkno >> 24) & 0xf);
-		blkno &= 0xff;
-	}
+
 	crqb = >port_crqb->crqb_gen2e + erqqip;
 	crqb->cprdbl = htole32(eprd_addr & CRQB_CRQBL_EPRD_MASK);
 	crqb->cprdbh = htole32((eprd_addr >> 16) >> 16);
 	crqb->ctrlflg = htole32(ctrlflg);
-	if (mvport->port_edmamode == dma) {
-		crqb->atacommand[0] = htole32(cmd << 16);
-		crqb->atacommand[1] = htole32((blkno & 0xff) | head << 24);
-		crqb->atacommand[2] = htole32(((blkno >> 24) & 0xff));
-		crqb->atacommand[3] = htole32(ata_bio->nblks & 0x);
-	} else { /* ncq/queued */
 
-		/*
-		 * : Oops, ata command is not correct.  And, atabus layer
-		 * has not been supported yet now.
-		 *   Queued DMA read/write.
-		 *   read/write FPDMAQueued.
-		 */
+	satafis_rhd_construct_bio(xfer, fis);
 
-		crqb->atacommand[0] = htole32(
-		(cmd << 16) | ((ata_bio->nblks & 0xff) << 24));
-		crqb->atacommand[1] = htole32((blkno & 0xff) | head << 24);
-		crqb->atacommand[2] = htole32(((blkno >> 24) & 0xff) |
-		((ata_bio->nblks >> 8) & 0xff));
-		crqb->atacommand[3] = htole32(ata_bio->nblks & 0x);
-		crqb->atacommand[3] = htole32(xfer->c_slot << 3);
-	}
+	crqb->atacommand[0] = 0;
+	crqb->atacommand[1] = 0;
+	/* copy over the ATA command part of the fis */
+	memcpy(>atacommand[2], [rhd_command],
+	MIN(sizeof(crqb->atacommand) - 2, RHD_FISLEN - rhd_command));
 }
 
-
 #ifdef MVSATA_DEBUG
 #define MVSATA_DEBUG_PRINT(type, size, n, p)		\
 	do {		\

Index: src/sys/dev/ic/mvsatareg.h
diff -u src/sys/dev/ic/mvsatareg.h:1.3 src/sys/dev/ic/mvsatareg.h:1.3.28.1
--- src/sys/dev/ic/mvsatareg.h:1.3	Wed Aug 29 16:50:10 2012
+++ src/sys/dev/ic/mvsatareg.h	Sat Jun 10 13:25:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsatareg.h,v 1.3 2012/08/29 16:50:10 jakllsch Exp $	*/
+/*	$NetBSD: mvsatareg.h,v 1.3.28.1 2017/06/10 13:25:51 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -261,7 +261,7 @@ struct crqb_gen2e {
 	uint32_t cprdbh;	/* cPRD Desriptor Table Base High Address */
 	uint32_t ctrlflg;	/* Control Flags */
 	uint32_t drbc;		/* Data Region Byte Count */
-	uint32_t atacommand[4];
+	uint8_t atacommand[16];
 } __packed __aligned(8);
 
 



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

2017-06-09 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Jun  9 20:18:58 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: mvsata.c mvsatavar.h

Log Message:
fix the driver to work again - switch to using tag from xfer, adjust
to framework changes (queue dynamically allocated), and do not store
pointer to xfer inside internal structures

unhide the ATAPI code and fix to compile, keep it disabled however

no indended functional changes, logic kept as close as possible to what was
there before; tested with Adaptec 1430SA (88SX7042)


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.6 -r1.35.6.7 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.2 -r1.2.48.1 src/sys/dev/ic/mvsatavar.h

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.35.6.6 src/sys/dev/ic/mvsata.c:1.35.6.7
--- src/sys/dev/ic/mvsata.c:1.35.6.6	Wed Apr 19 20:49:17 2017
+++ src/sys/dev/ic/mvsata.c	Fri Jun  9 20:18:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.6 2017/04/19 20:49:17 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.7 2017/06/09 20:18:58 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,17 +26,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.6 2017/04/19 20:49:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.7 2017/06/09 20:18:58 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
-/* ATAPI implementation not finished. */
-//#include "atapibus.h"
-
 #include 
-#if NATAPIBUS > 0
 #include 
-#endif
 #include 
 #include 
 #include 
@@ -55,16 +50,15 @@ __KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1
 #include 
 #include 
 
-#if NATAPIBUS > 0
 #include 	/* for SCSI status */
-#endif
 
-#include 
+#include "atapibus.h"
+
+#include  /* XXX should not be here */
 
 #include 
 #include 
 
-
 #define MVSATA_DEV(sc)		((sc)->sc_wdcdev.sc_atac.atac_dev)
 #define MVSATA_DEV2(mvport)	((mvport)->port_ata_channel.ch_atac->atac_dev)
 
@@ -152,13 +146,13 @@ static void mvsata_atapi_done(struct ata
 static void mvsata_atapi_polldsc(void *);
 #endif
 
-static int mvsata_edma_enqueue(struct mvsata_port *, struct ata_bio *, void *);
+static int mvsata_edma_enqueue(struct mvsata_port *, struct ata_xfer *);
 static int mvsata_edma_handle(struct mvsata_port *, struct ata_xfer *);
 static int mvsata_edma_wait(struct mvsata_port *, struct ata_xfer *, int);
 static void mvsata_edma_timeout(void *);
 static void mvsata_edma_rqq_remove(struct mvsata_port *, struct ata_xfer *);
 #if NATAPIBUS > 0
-static int mvsata_bdma_init(struct mvsata_port *, struct scsipi_xfer *, void *);
+static int mvsata_bdma_init(struct mvsata_port *, struct ata_xfer *);
 static void mvsata_bdma_start(struct mvsata_port *);
 #endif
 #endif
@@ -166,9 +160,8 @@ static void mvsata_bdma_start(struct mvs
 static int mvsata_port_init(struct mvsata_hc *, int);
 static int mvsata_wdc_reg_init(struct mvsata_port *, struct wdc_regs *);
 #ifndef MVSATA_WITHOUTDMA
-static inline void mvsata_quetag_init(struct mvsata_port *);
-static inline int mvsata_quetag_get(struct mvsata_port *);
-static inline void mvsata_quetag_put(struct mvsata_port *, int);
+static inline void mvsata_quetag_get(struct mvsata_port *, uint8_t);
+static inline void mvsata_quetag_put(struct mvsata_port *, uint8_t);
 static void *mvsata_edma_resource_prepare(struct mvsata_port *, bus_dma_tag_t,
 	  bus_dmamap_t *, size_t, int);
 static void mvsata_edma_resource_purge(struct mvsata_port *, bus_dma_tag_t,
@@ -187,8 +180,8 @@ static inline void mvsata_edma_enable(st
 static int mvsata_edma_disable(struct mvsata_port *, int, int);
 static void mvsata_edma_config(struct mvsata_port *, int);
 
-static void mvsata_edma_setup_crqb(struct mvsata_port *, int, int,
-   struct ata_bio  *);
+static void mvsata_edma_setup_crqb(struct mvsata_port *, int,
+   struct ata_xfer *);
 #endif
 static uint32_t mvsata_read_preamps_gen1(struct mvsata_port *);
 static void mvsata_fix_phy_gen1(struct mvsata_port *);
@@ -197,8 +190,8 @@ static void mvsata_devconn_gen1(struct m
 static uint32_t mvsata_read_preamps_gen2(struct mvsata_port *);
 static void mvsata_fix_phy_gen2(struct mvsata_port *);
 #ifndef MVSATA_WITHOUTDMA
-static void mvsata_edma_setup_crqb_gen2e(struct mvsata_port *, int, int,
-	 struct ata_bio  *);
+static void mvsata_edma_setup_crqb_gen2e(struct mvsata_port *, int,
+	 struct ata_xfer *);
 
 #ifdef MVSATA_DEBUG
 static void mvsata_print_crqb(struct mvsata_port *, int);
@@ -206,7 +199,7 @@ static void mvsata_print_crpb(struct mvs
 static void mvsata_print_eprd(struct mvsata_port *, int);
 #endif
 
-struct ata_bustype mvsata_ata_bustype = {
+static const struct ata_bustype mvsata_ata_bustype = {
 	SCSIPI_BUSTYPE_ATA,
 	mvsata_bio,
 	mvsata_reset_drive,
@@ -260,7 +253,7 @@ mvsata_attach(struct mvsata_softc *sc, s
 	void (*_fix_phy)(struct mvsata_port *) = NULL;
 #ifndef 

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

2017-04-25 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 25 20:55:05 UTC 2017

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

Log Message:
make compile without DIAGNOSTIC


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.11 -r1.57.6.12 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.57.6.11 src/sys/dev/ic/ahcisata_core.c:1.57.6.12
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.11	Mon Apr 24 18:22:31 2017
+++ src/sys/dev/ic/ahcisata_core.c	Tue Apr 25 20:55:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.11 2017/04/24 18:22:31 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.12 2017/04/25 20:55:05 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.11 2017/04/24 18:22:31 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.12 2017/04/25 20:55:05 jdolecek Exp $");
 
 #include 
 #include 
@@ -1429,7 +1429,7 @@ ahci_timeout(void *v)
 {
 	struct ata_xfer *xfer = v;
 	struct ata_channel *chp = xfer->c_chp;
-	struct ahci_channel *achp = (struct ahci_channel *)chp;
+	struct ahci_channel *achp __diagused = (struct ahci_channel *)chp;
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	int s;
 



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

2017-04-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Apr 24 21:19:21 UTC 2017

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

Log Message:
Merge HEAD.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.13 -r1.30.4.14 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.30.4.13 src/sys/dev/ic/siisata.c:1.30.4.14
--- src/sys/dev/ic/siisata.c:1.30.4.13	Mon Apr 24 13:24:33 2017
+++ src/sys/dev/ic/siisata.c	Mon Apr 24 21:19:21 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.13 2017/04/24 13:24:33 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.14 2017/04/24 21:19:21 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.13 2017/04/24 13:24:33 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.14 2017/04/24 21:19:21 jakllsch Exp $");
 
 #include 
 #include 
@@ -557,7 +557,7 @@ siisata_reset_drive(struct ata_drive_dat
 		DELAY(10);
 
 	prb = schp->sch_prb[slot];
-	memset(prb, 0, sizeof(struct siisata_prb));
+	memset(prb, 0, SIISATA_CMD_SIZE);
 	prb->prb_control =
 	htole16(PRB_CF_SOFT_RESET | PRB_CF_INTERRUPT_MASK);
 	KASSERT(drvp->drive <= PMP_PORT_CTL);
@@ -692,7 +692,7 @@ siisata_probe_drive(struct ata_channel *
 		& PR_PS_PORT_READY))
 			DELAY(10);
 		prb = schp->sch_prb[slot];
-		memset(prb, 0, sizeof(struct siisata_prb));
+		memset(prb, 0, SIISATA_CMD_SIZE);
 		prb->prb_control = htole16(PRB_CF_SOFT_RESET);
 		prb->prb_fis[rhd_c] = PMP_PORT_CTL;
 
@@ -827,14 +827,12 @@ siisata_cmd_start(struct ata_channel *ch
 	chp->ch_error = 0;
 
 	prb = schp->sch_prb[slot];
-	memset(prb, 0, sizeof(struct siisata_prb));
+	memset(prb, 0, SIISATA_CMD_SIZE);
 
 	satafis_rhd_construct_cmd(ata_c, prb->prb_fis);
 	KASSERT(xfer->c_drive <= PMP_PORT_CTL);
 	prb->prb_fis[rhd_c] |= xfer->c_drive;
 
-	memset(prb->prb_atapi, 0, sizeof(prb->prb_atapi));
-
 	if (ata_c->r_command == ATA_DATA_SET_MANAGEMENT) {
 		prb->prb_control |= htole16(PRB_CF_PROTOCOL_OVERRIDE);
 		prb->prb_protocol_override |= htole16(PRB_PO_WRITE);
@@ -1036,14 +1034,12 @@ siisata_bio_start(struct ata_channel *ch
 	chp->ch_error = 0;
 
 	prb = schp->sch_prb[slot];
-	memset(prb, 0, sizeof(struct siisata_prb));
+	memset(prb, 0, SIISATA_CMD_SIZE);
 
 	satafis_rhd_construct_bio(xfer, prb->prb_fis);
 	KASSERT(xfer->c_drive <= PMP_PORT_CTL);
 	prb->prb_fis[rhd_c] |= xfer->c_drive;
 
-	memset(prb->prb_atapi, 0, sizeof(prb->prb_atapi));
-
 	if (siisata_dma_setup(chp, slot, ata_bio->databuf, ata_bio->bcount,
 	(ata_bio->flags & ATA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) {
 		ata_bio->error = ERR_DMA;
@@ -1217,9 +1213,6 @@ siisata_dma_setup(struct ata_channel *ch
 	schp->sch_datad[slot]->dm_mapsize,
 	(op == BUS_DMA_READ) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
 
-	/* make sure it's clean */
-	memset(prbp->prb_sge, 0, SIISATA_NSGE * sizeof(struct siisata_prb));
-
 	SIISATA_DEBUG_PRINT(("%s: %d segs, %ld count\n", __func__,
 	schp->sch_datad[slot]->dm_nsegs, (long unsigned int) count),
 	DEBUG_FUNCS | DEBUG_DEBUG);
@@ -1573,8 +1566,7 @@ siisata_atapi_start(struct ata_channel *
 	chp->ch_error = 0;
 
 	prbp = schp->sch_prb[slot];
-	memset(prbp, 0, sizeof(struct siisata_prb));
-
+	memset(prbp, 0, SIISATA_CMD_SIZE);
 
 	/* fill in direction for ATAPI command */
 	if ((sc_xfer->xs_control & XS_CTL_DATA_IN))



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

2017-04-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 24 18:22:32 UTC 2017

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

Log Message:
only clear the bcount for NCQ case when the transfer actually ended w/o error


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.10 -r1.57.6.11 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.57.6.10 src/sys/dev/ic/ahcisata_core.c:1.57.6.11
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.10	Mon Apr 24 15:15:02 2017
+++ src/sys/dev/ic/ahcisata_core.c	Mon Apr 24 18:22:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.10 2017/04/24 15:15:02 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.11 2017/04/24 18:22:31 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.10 2017/04/24 15:15:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.11 2017/04/24 18:22:31 jdolecek Exp $");
 
 #include 
 #include 
@@ -1339,7 +1339,8 @@ ahci_bio_complete(struct ata_channel *ch
 	 * not required to be valid; in that case underflow is always illegal.
 	 */
 	if ((xfer->c_flags & C_NCQ) != 0) {
-		ata_bio->bcount = 0;
+		if (ata_bio->error == NOERROR)
+			ata_bio->bcount = 0;
 	} else {
 	if ((ata_bio->flags & ATA_READ) || ata_bio->error == NOERROR)
 		ata_bio->bcount -=



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

2017-04-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Apr 24 13:24:34 UTC 2017

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

Log Message:
Merge HEAD.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.12 -r1.30.4.13 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.30.4.12 src/sys/dev/ic/siisata.c:1.30.4.13
--- src/sys/dev/ic/siisata.c:1.30.4.12	Mon Apr 24 13:09:37 2017
+++ src/sys/dev/ic/siisata.c	Mon Apr 24 13:24:33 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.12 2017/04/24 13:09:37 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.13 2017/04/24 13:24:33 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.12 2017/04/24 13:09:37 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.13 2017/04/24 13:24:33 jakllsch Exp $");
 
 #include 
 #include 
@@ -1646,7 +1646,7 @@ siisata_atapi_complete(struct ata_channe
 	SIISATA_DEBUG_PRINT(("%s: %s()\n", SIISATANAME(sc), __func__),
 	DEBUG_INTR);
 
-	/* this comamnd is not active any more */
+	/* this command is not active any more */
 	schp->sch_active_slots &= ~__BIT(slot);
 	chp->ch_flags &= ~ATACH_IRQ_WAIT;
 	if (xfer->c_flags & C_TIMEOU) {



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

2017-04-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Apr 24 13:09:37 UTC 2017

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

Log Message:
Merge HEAD.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.11 -r1.30.4.12 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.30.4.11 src/sys/dev/ic/siisata.c:1.30.4.12
--- src/sys/dev/ic/siisata.c:1.30.4.11	Sun Apr 23 14:33:28 2017
+++ src/sys/dev/ic/siisata.c	Mon Apr 24 13:09:37 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.11 2017/04/23 14:33:28 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.12 2017/04/24 13:09:37 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.11 2017/04/23 14:33:28 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.12 2017/04/24 13:09:37 jakllsch Exp $");
 
 #include 
 #include 
@@ -122,7 +122,8 @@ bus_space_read_stream_4(bus_space_tag_t 
 }
 
 static inline void
-bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, uint32_t *p, bus_size_t c)
+bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
+bus_size_t o, uint32_t *p, bus_size_t c)
 {
 	bus_space_read_region_4(t, h, o, p, c);
 	for (bus_size_t i = 0; i < c; i++) {
@@ -161,8 +162,8 @@ static void siisata_reinit_port(struct a
 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);
-static int siisata_dma_setup(struct ata_channel *chp, int slot,
-void *data, size_t, int);
+static int siisata_dma_setup(struct ata_channel *chp, int, void *,
+size_t, int);
 
 #if NATAPIBUS > 0
 void siisata_atapibus_attach(struct atabus_softc *);
@@ -171,7 +172,6 @@ void siisata_atapi_minphys(struct buf *)
 void siisata_atapi_start(struct ata_channel *,struct ata_xfer *);
 int siisata_atapi_complete(struct ata_channel *, struct ata_xfer *, int);
 void siisata_atapi_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
-void siisata_atapi_done(struct ata_channel *, struct ata_xfer *, int);
 void siisata_atapi_scsipi_request(struct scsipi_channel *,
 scsipi_adapter_req_t, void *);
 void siisata_atapi_kill_pending(struct scsipi_periph *);
@@ -219,7 +219,7 @@ siisata_attach(struct siisata_softc *sc)
 	sc->sc_atac.atac_set_modes = siisata_setup_channel;
 #if NATAPIBUS > 0
 	sc->sc_atac.atac_atapibus_attach = siisata_atapibus_attach;
-#endif	
+#endif
 
 	/* come out of reset state */
 	GRWRITE(sc, GR_GC, 0);
@@ -228,9 +228,8 @@ siisata_attach(struct siisata_softc *sc)
 		siisata_attach_port(sc, i);
 	}
 
-	SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n",
-	SIISATANAME(sc), __func__, GRREAD(sc, GR_GC)),
-	DEBUG_FUNCS);
+	SIISATA_DEBUG_PRINT(("%s: %s: GR_GC: 0x%08x\n", SIISATANAME(sc),
+	__func__, GRREAD(sc, GR_GC)), DEBUG_FUNCS);
 	return;
 }
 
@@ -448,7 +447,7 @@ siisata_resume(struct siisata_softc *sc)
 	for (i = 0; i < sc->sc_atac.atac_nchannels; i++) {
 		siisata_init_port(sc, i);
 	}
-	
+
 }
 
 int
@@ -485,8 +484,8 @@ siisata_intr_port(struct siisata_channel
 
 	pis = PRREAD(sc, PRX(chp->ch_channel, PRO_PIS));
 
-	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ",
-	SIISATANAME(sc), __func__, chp->ch_channel, pis), DEBUG_INTR);
+	SIISATA_DEBUG_PRINT(("%s: %s port %d, pis 0x%x ", SIISATANAME(sc),
+	__func__, chp->ch_channel, pis), DEBUG_INTR);
 
 	if (pis & PR_PIS_CMDCMPL) {
 		/* get slot status, clearing completion interrupt */
@@ -499,7 +498,7 @@ siisata_intr_port(struct siisata_channel
 			"completion on port %d\n",
 			SIISATANAME(sc), chp->ch_channel);
 			return;
-		} 
+		}
 		if ((~pss & __BIT(slot)) == 0) {
 			aprint_error( "%s: unknown slot "
 			"completion on port %d, pss 0x%x\n",
@@ -520,7 +519,7 @@ siisata_intr_port(struct siisata_channel
 /* read in specific information about error */
 prbfis = bus_space_read_stream_4(
 sc->sc_prt, sc->sc_prh,
-				PRSX(chp->ch_channel, slot, PRSO_FIS));
+PRSX(chp->ch_channel, slot, PRSO_FIS));
 /* set ch_status and ch_error */
 satafis_rdh_parse(chp, (uint8_t *));
 			}
@@ -820,9 +819,8 @@ siisata_cmd_start(struct ata_channel *ch
 	int i;
 
 	SIISATA_DEBUG_PRINT(("%s: %s port %d drive %d command 0x%x, slot %d\n",
-	SIISATANAME((struct siisata_softc *)chp->ch_atac),
-	__func__, chp->ch_channel, xfer->c_drive,
-	ata_c->r_command, slot),
+	SIISATANAME((struct siisata_softc *)chp->ch_atac), __func__,
+	chp->ch_channel, xfer->c_drive, ata_c->r_command, slot),
 	DEBUG_FUNCS|DEBUG_XFERS);
 
 	chp->ch_status = 0;
@@ -845,7 +843,7 @@ siisata_cmd_start(struct ata_channel *ch
 	if (siisata_dma_setup(chp, slot,
 	(ata_c->flags & (AT_READ | AT_WRITE)) ? ata_c->data 

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

2017-04-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon Apr 24 13:05:26 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: siisatareg.h

Log Message:
Merge HEAD.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.42.1 src/sys/dev/ic/siisatareg.h

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/siisatareg.h
diff -u src/sys/dev/ic/siisatareg.h:1.7 src/sys/dev/ic/siisatareg.h:1.7.42.1
--- src/sys/dev/ic/siisatareg.h:1.7	Wed Nov  2 16:03:01 2011
+++ src/sys/dev/ic/siisatareg.h	Mon Apr 24 13:05:26 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisatareg.h,v 1.7 2011/11/02 16:03:01 jakllsch Exp $ */
+/* $NetBSD: siisatareg.h,v 1.7.42.1 2017/04/24 13:05:26 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2007, 2008, 2009, 2010, 2011 Jonathan A. Kollasch.
@@ -141,7 +141,7 @@ struct siisata_prb {
 #define GR_GC_DEVSEL		__BIT(19)
 #define GR_GC_STOP		__BIT(18)
 #define GR_GC_TRDY		__BIT(17)
-#define GR_GC_M66EN		__BIT(16)	
+#define GR_GC_M66EN		__BIT(16)
 #define GR_GC_PXIE_MASK		__BITS(SIISATA_MAX_PORTS - 1, 0)
 #define GR_GC_PXIE(n)		__SHIFTIN(__BIT(n), GR_GC_PXIE_MASK)
 
@@ -247,6 +247,8 @@ struct siisata_prb {
 #define PR_PC_PMP_ENABLE	__BIT(13)
 #define PR_PC_AIA		__BIT(14)
 #define PR_PC_LED_ON		__BIT(15)
+#define PR_PS_ACTIVE_SLOT_MASK	__BITS(20,16)
+#define PR_PS_ACTIVE_SLOT(x)	__SHIFTOUT((x), PR_PS_ACTIVE_SLOT_MASK)
 #define PR_PC_OOB_BYPASS	__BIT(25)
 #define PR_PS_PORT_READY	__BIT(31)
 



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

2017-04-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 24 10:21:15 UTC 2017

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

Log Message:
adjust error handling in interrupt handler - finish the successfully
finished xfers, and iterate to error out all the unfinished ones


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.8 -r1.57.6.9 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.57.6.8 src/sys/dev/ic/ahcisata_core.c:1.57.6.9
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.8	Thu Apr 20 19:24:25 2017
+++ src/sys/dev/ic/ahcisata_core.c	Mon Apr 24 10:21:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.8 2017/04/20 19:24:25 jakllsch Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.9 2017/04/24 10:21:15 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.8 2017/04/20 19:24:25 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.9 2017/04/24 10:21:15 jdolecek Exp $");
 
 #include 
 #include 
@@ -556,7 +556,7 @@ ahci_intr(void *v)
 static void
 ahci_intr_port(struct ahci_softc *sc, struct ahci_channel *achp)
 {
-	uint32_t is, tfd;
+	uint32_t is, tfd, active;
 	struct ata_channel *chp = >ata_channel;
 	struct ata_xfer *xfer;
 	int slot;
@@ -567,20 +567,25 @@ ahci_intr_port(struct ahci_softc *sc, st
 	chp->ch_channel, is, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
 	DEBUG_INTR);
 
+	active = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))
+		| AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
+
+	/* Complete all successful commands first */
+	for (slot=0; slot < sc->sc_ncmds; slot++) {
+		if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
+			continue;
+		if ((active & (1 << slot)) == 0) {
+			xfer = ata_queue_hwslot_to_xfer(chp->ch_queue,
+			slot);
+			xfer->c_intr(chp, xfer, 0);
+		}
+	}
+
+	/* Handle errors */
 	if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_IFS |
 	AHCI_P_IX_OFS | AHCI_P_IX_UFS)) {
-#if 1
-	printf("ahci_intr_port %s port %d is 0x%x CI 0x%x\n", AHCINAME(sc),
-	chp->ch_channel, is, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)));
-#endif
-		slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
-			& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
-		/* XXX iterate */
-		if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-			return;
 		/* stop channel */
 		ahci_channel_stop(sc, chp, 0);
-		xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, slot);
 		if (is & AHCI_P_IX_TFES) {
 			tfd = AHCI_READ(sc, AHCI_P_TFD(chp->ch_channel));
 			chp->ch_error =
@@ -596,24 +601,20 @@ ahci_intr_port(struct ahci_softc *sc, st
 			AHCINAME(sc), chp->ch_channel,
 			AHCI_READ(sc, AHCI_P_SERR(chp->ch_channel)));
 		}
-		xfer->c_intr(chp, xfer, is);
-		/* if channel has not been restarted, do it now */
-		if ((AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) & AHCI_P_CMD_CR)
-		== 0)
-			ahci_channel_start(sc, chp, 0, 0);
-	} else {
-		uint32_t clear = AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))
-			| AHCI_READ(sc, AHCI_P_SACT(chp->ch_channel));
-
+		/* complete all pending commands with error statuses */
 		for (slot=0; slot < sc->sc_ncmds; slot++) {
 			if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
 continue;
-			if ((clear & (1 << slot)) == 0) {
+			if ((active & (1 << slot)) == 1) {
 xfer = ata_queue_hwslot_to_xfer(chp->ch_queue,
 slot);
-xfer->c_intr(chp, xfer, 0);
+xfer->c_intr(chp, xfer, is);
 			}
 		}
+		/* if channel has not been restarted, do it now */
+		if ((AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel)) & AHCI_P_CMD_CR)
+		== 0)
+			ahci_channel_start(sc, chp, 0, 0);
 	}
 }
 



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

2017-04-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Apr 24 08:29:33 UTC 2017

Modified Files:
src/sys/dev/ic [jdolecek-ncq]: ninjaata32.c ninjaata32var.h

Log Message:
adjust to interface changes - ata_queue is now dynamically allocated


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.18.28.1 src/sys/dev/ic/ninjaata32.c
cvs rdiff -u -r1.5 -r1.5.44.1 src/sys/dev/ic/ninjaata32var.h

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/ninjaata32.c
diff -u src/sys/dev/ic/ninjaata32.c:1.18 src/sys/dev/ic/ninjaata32.c:1.18.28.1
--- src/sys/dev/ic/ninjaata32.c:1.18	Tue Jul 31 15:50:34 2012
+++ src/sys/dev/ic/ninjaata32.c	Mon Apr 24 08:29:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ninjaata32.c,v 1.18 2012/07/31 15:50:34 bouyer Exp $	*/
+/*	$NetBSD: ninjaata32.c,v 1.18.28.1 2017/04/24 08:29:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 ITOH Yasufumi.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ninjaata32.c,v 1.18 2012/07/31 15:50:34 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ninjaata32.c,v 1.18.28.1 2017/04/24 08:29:33 jdolecek Exp $");
 
 #include 
 #include 
@@ -191,7 +191,7 @@ njata32_attach(struct njata32_softc *sc)
 	sc->sc_wdc_chanarray[0] = >sc_ch[0].ch_ata_channel;
 	sc->sc_ch[0].ch_ata_channel.ch_channel = 0;
 	sc->sc_ch[0].ch_ata_channel.ch_atac = >sc_wdcdev.sc_atac;
-	sc->sc_ch[0].ch_ata_channel.ch_queue = >sc_wdc_chqueue;
+	sc->sc_ch[0].ch_ata_channel.ch_queue = ata_queue_alloc(1);
 	sc->sc_wdcdev.wdc_maxdrives = 2; /* max number of drives per channel */
 
 	/* map ATA registers */
@@ -264,6 +264,8 @@ njata32_detach(struct njata32_softc *sc,
 		bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_sgtpg,
 		sizeof(struct njata32_dma_page));
 		bus_dmamem_free(sc->sc_dmat, >sc_sgt_seg, sc->sc_sgt_nsegs);
+
+		ata_queue_free(sc->sc_ch[0].ch_ata_channel.ch_queue);
 	}
 
 	return 0;

Index: src/sys/dev/ic/ninjaata32var.h
diff -u src/sys/dev/ic/ninjaata32var.h:1.5 src/sys/dev/ic/ninjaata32var.h:1.5.44.1
--- src/sys/dev/ic/ninjaata32var.h:1.5	Mon Feb 21 02:32:00 2011
+++ src/sys/dev/ic/ninjaata32var.h	Mon Apr 24 08:29:33 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ninjaata32var.h,v 1.5 2011/02/21 02:32:00 itohy Exp $	*/
+/*	$NetBSD: ninjaata32var.h,v 1.5.44.1 2017/04/24 08:29:33 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 ITOH Yasufumi.
@@ -69,7 +69,6 @@ struct njata32_softc {
 	} sc_ch[NJATA32_NCHAN];
 
 	struct ata_channel	*sc_wdc_chanarray[NJATA32_NCHAN];
-	struct ata_queue	sc_wdc_chqueue;
 	struct wdc_regs		sc_wdc_regs;
 #define NJATA32_REGT(sc)	(sc)->sc_wdc_regs.cmd_iot
 #define NJATA32_REGH(sc)	(sc)->sc_wdc_regs.cmd_baseioh



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

2017-04-23 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Apr 23 14:33:28 UTC 2017

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

Log Message:
Allocate a full compliment of queue slots for each channel.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.10 -r1.30.4.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.30.4.10 src/sys/dev/ic/siisata.c:1.30.4.11
--- src/sys/dev/ic/siisata.c:1.30.4.10	Sun Apr 23 14:25:02 2017
+++ src/sys/dev/ic/siisata.c	Sun Apr 23 14:33:28 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.10 2017/04/23 14:25:02 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.11 2017/04/23 14:33:28 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.10 2017/04/23 14:25:02 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.11 2017/04/23 14:33:28 jakllsch Exp $");
 
 #include 
 #include 
@@ -290,7 +290,7 @@ siisata_attach_port(struct siisata_softc
 	sc->sc_chanarray[port] = chp;
 	chp->ch_channel = port;
 	chp->ch_atac = >sc_atac;
-	chp->ch_queue = ata_queue_alloc(1);	// XXX
+	chp->ch_queue = ata_queue_alloc(SIISATA_MAX_SLOTS);
 	if (chp->ch_queue == NULL) {
 		aprint_error_dev(sc->sc_atac.atac_dev,
 		"port %d: can't allocate memory "



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

2017-04-23 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Apr 23 14:25:03 UTC 2017

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

Log Message:
Use ata_kill_active() in siisata_reset_channel() so as to ensure all
in-flight xfers are taken care of.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.9 -r1.30.4.10 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.30.4.9 src/sys/dev/ic/siisata.c:1.30.4.10
--- src/sys/dev/ic/siisata.c:1.30.4.9	Sun Apr 23 01:26:50 2017
+++ src/sys/dev/ic/siisata.c	Sun Apr 23 14:25:02 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.9 2017/04/23 01:26:50 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.10 2017/04/23 14:25:02 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.9 2017/04/23 01:26:50 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.10 2017/04/23 14:25:02 jakllsch Exp $");
 
 #include 
 #include 
@@ -624,7 +624,6 @@ siisata_reset_channel(struct ata_channel
 {
 	struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
 	struct siisata_channel *schp = (struct siisata_channel *)chp;
-	struct ata_xfer *xfer;
 
 	SIISATA_DEBUG_PRINT(("%s: %s\n", SIISATANAME(sc), __func__),
 	DEBUG_FUNCS);
@@ -640,9 +639,7 @@ siisata_reset_channel(struct ata_channel
 		DELAY(10);
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_SERROR),
 	PRREAD(sc, PRX(chp->ch_channel, PRO_SERROR)));
-	if ((xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, 0)) != NULL) { /* XXX slot */
-		(*xfer->c_kill_xfer)(chp, xfer, KILL_RESET);
-	}
+	ata_kill_active(chp, KILL_RESET);
 
 	return;
 }



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

2017-04-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Apr 23 01:26:50 UTC 2017

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

Log Message:
Fix inverted ata_waitdrain_xfer_check() logic in siisata_atapi_complete().


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.8 -r1.30.4.9 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.30.4.8 src/sys/dev/ic/siisata.c:1.30.4.9
--- src/sys/dev/ic/siisata.c:1.30.4.8	Sat Apr 22 14:08:38 2017
+++ src/sys/dev/ic/siisata.c	Sun Apr 23 01:26:50 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.8 2017/04/22 14:08:38 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.9 2017/04/23 01:26:50 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.8 2017/04/22 14:08:38 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.9 2017/04/23 01:26:50 jakllsch Exp $");
 
 #include 
 #include 
@@ -1668,7 +1668,7 @@ siisata_atapi_complete(struct ata_channe
 
 	ata_deactivate_xfer(chp, xfer);
 
-	if (!ata_waitdrain_xfer_check(chp, xfer)) {
+	if (ata_waitdrain_xfer_check(chp, xfer)) {
 		sc_xfer->error = XS_DRIVER_STUFFUP;
 		return 0; /* XXX verify */
 	}



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

2017-04-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Apr 22 14:08:38 UTC 2017

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

Log Message:
Another one missed in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.7 -r1.30.4.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.30.4.7 src/sys/dev/ic/siisata.c:1.30.4.8
--- src/sys/dev/ic/siisata.c:1.30.4.7	Sat Apr 22 13:40:50 2017
+++ src/sys/dev/ic/siisata.c	Sat Apr 22 14:08:38 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.7 2017/04/22 13:40:50 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.8 2017/04/22 14:08:38 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.7 2017/04/22 13:40:50 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.8 2017/04/22 14:08:38 jakllsch Exp $");
 
 #include 
 #include 
@@ -1640,11 +1640,12 @@ out:
 
 int
 siisata_atapi_complete(struct ata_channel *chp, struct ata_xfer *xfer,
-int slot)
+int is)
 {
 	struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
 	struct siisata_channel *schp = (struct siisata_channel *)chp;
 	struct scsipi_xfer *sc_xfer = xfer->c_scsipi;
+	int slot = SIISATA_NON_NCQ_SLOT;
 
 	SIISATA_DEBUG_PRINT(
 	("%s: %s()\n", SIISATANAME(sc), __func__), DEBUG_INTR);



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

2017-04-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Apr 22 13:40:50 UTC 2017

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

Log Message:
3rd xfer interrupt argument fix change missed in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.6 -r1.30.4.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/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.30.4.6 src/sys/dev/ic/siisata.c:1.30.4.7
--- src/sys/dev/ic/siisata.c:1.30.4.6	Sat Apr 22 13:19:28 2017
+++ src/sys/dev/ic/siisata.c	Sat Apr 22 13:40:50 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.6 2017/04/22 13:19:28 jakllsch Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.7 2017/04/22 13:40:50 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.6 2017/04/22 13:19:28 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.7 2017/04/22 13:40:50 jakllsch Exp $");
 
 #include 
 #include 
@@ -1054,7 +1054,7 @@ siisata_bio_start(struct ata_channel *ch
 	(ata_bio->flags & ATA_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) {
 		ata_bio->error = ERR_DMA;
 		ata_bio->r_error = 0;
-		siisata_bio_complete(chp, xfer, slot);
+		siisata_bio_complete(chp, xfer, 0);
 		return;
 	}
 



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

2017-04-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Apr 22 13:19:28 UTC 2017

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

Log Message:
Don't use the third argument of the xfer interrupt functions to pass the slot 
number in siisata(4).

This (abuse) is redundant because we are now storing the slot in the xfer 
structure.


To generate a diff of this commit:
cvs rdiff -u -r1.30.4.5 -r1.30.4.6 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.30.4.5 src/sys/dev/ic/siisata.c:1.30.4.6
--- src/sys/dev/ic/siisata.c:1.30.4.5	Wed Apr 19 20:49:17 2017
+++ src/sys/dev/ic/siisata.c	Sat Apr 22 13:19:28 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.5 2017/04/19 20:49:17 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.6 2017/04/22 13:19:28 jakllsch Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.5 2017/04/19 20:49:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.6 2017/04/22 13:19:28 jakllsch Exp $");
 
 #include 
 #include 
@@ -538,7 +538,7 @@ siisata_intr_port(struct siisata_channel
 	/* clear some (ok, all) ints */
 	PRWRITE(sc, PRX(chp->ch_channel, PRO_PIS), 0x);
 	if (xfer && xfer->c_intr)
-		xfer->c_intr(chp, xfer, slot);
+		xfer->c_intr(chp, xfer, 0);
 
 	return;
 }
@@ -850,7 +850,7 @@ siisata_cmd_start(struct ata_channel *ch
 	ata_c->bcount,
 	(ata_c->flags & AT_READ) ? BUS_DMA_READ : BUS_DMA_WRITE)) { 
 		ata_c->flags |= AT_DF;
-		siisata_cmd_complete(chp, xfer, slot);
+		siisata_cmd_complete(chp, xfer, 0);
 		return;
 	}
 
@@ -914,12 +914,13 @@ siisata_cmd_kill_xfer(struct ata_channel
 }
 
 int
-siisata_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
+siisata_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int is)
 {
 	struct ata_command *ata_c = >c_ata_c;
 #ifdef SIISATA_DEBUG
 	struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
 #endif
+	int slot = SIISATA_NON_NCQ_SLOT;
 
 	SIISATA_DEBUG_PRINT(
 	("%s: %s\n", SIISATANAME(sc), __func__), DEBUG_FUNCS|DEBUG_XFERS);
@@ -1121,12 +1122,13 @@ siisata_bio_kill_xfer(struct ata_channel
 }
 
 int
-siisata_bio_complete(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
+siisata_bio_complete(struct ata_channel *chp, struct ata_xfer *xfer, int is)
 {
 	struct siisata_softc *sc = (struct siisata_softc *)chp->ch_atac;
 	struct siisata_channel *schp = (struct siisata_channel *)chp;
 	struct ata_bio *ata_bio = >c_bio;
 	int drive = xfer->c_drive;
+	int slot = SIISATA_NON_NCQ_SLOT;
 
 	schp->sch_active_slots &= ~__BIT(slot);
 	chp->ch_flags &= ~ATACH_IRQ_WAIT;
@@ -1180,13 +1182,12 @@ siisata_timeout(void *v)
 {
 	struct ata_xfer *xfer = v;
 	struct ata_channel *chp = xfer->c_chp;
-	int slot = SIISATA_NON_NCQ_SLOT;
 	int s = splbio();
 	SIISATA_DEBUG_PRINT(("%s: %p\n", __func__, xfer), DEBUG_INTR);
 	siisata_device_reset(chp);
 	if ((chp->ch_flags & ATACH_IRQ_WAIT) != 0) {
 		xfer->c_flags |= C_TIMEOU;
-		xfer->c_intr(chp, xfer, slot);
+		xfer->c_intr(chp, xfer, 0);
 	}
 	splx(s);
 }



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

2017-04-20 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Apr 20 19:24:25 UTC 2017

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

Log Message:
Don't bail out of handling interrupts at the first inactive slot.

Appears to fix the frequent timeouts issue.


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.7 -r1.57.6.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.57.6.7 src/sys/dev/ic/ahcisata_core.c:1.57.6.8
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.7	Wed Apr 19 20:49:17 2017
+++ src/sys/dev/ic/ahcisata_core.c	Thu Apr 20 19:24:25 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.7 2017/04/19 20:49:17 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.8 2017/04/20 19:24:25 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.7 2017/04/19 20:49:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.8 2017/04/20 19:24:25 jakllsch Exp $");
 
 #include 
 #include 
@@ -607,7 +607,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 
 		for (slot=0; slot < sc->sc_ncmds; slot++) {
 			if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-return;
+continue;
 			if ((clear & (1 << slot)) == 0) {
 xfer = ata_queue_hwslot_to_xfer(chp->ch_queue,
 slot);



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

2017-04-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 15 23:58:32 UTC 2017

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

Log Message:
use xfer->c_slot instead of slot = 0

fix ahci_bio_complete() calls - last param is reason, not slot


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.5 -r1.57.6.6 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.57.6.5 src/sys/dev/ic/ahcisata_core.c:1.57.6.6
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.5	Sat Apr 15 23:54:41 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Apr 15 23:58:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.5 2017/04/15 23:54:41 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.6 2017/04/15 23:58:31 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.5 2017/04/15 23:54:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.6 2017/04/15 23:58:31 jdolecek Exp $");
 
 #include 
 #include 
@@ -68,8 +68,8 @@ static void ahci_killpending(struct ata_
 
 static void ahci_cmd_start(struct ata_channel *, struct ata_xfer *);
 static int  ahci_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
-static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *, int);
-static void ahci_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int) ;
+static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *);
+static void ahci_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
 static void ahci_bio_start(struct ata_channel *, struct ata_xfer *);
 static int  ahci_bio_complete(struct ata_channel *, struct ata_xfer *, int);
 static void ahci_bio_kill_xfer(struct ata_channel *, struct ata_xfer *, int) ;
@@ -365,7 +365,7 @@ ahci_attach(struct ahci_softc *sc)
 		sc->sc_chanarray[i] = chp;
 		chp->ch_channel = i;
 		chp->ch_atac = >sc_atac;
-		chp->ch_queue = ata_queue_alloc(1); // XXX
+		chp->ch_queue = ata_queue_alloc(1); // XXX sc_ncmds
 		if (chp->ch_queue == NULL) {
 			aprint_error("%s port %d: can't allocate memory for "
 			"command queue", AHCINAME(sc), i);
@@ -1063,13 +1063,12 @@ ahci_cmd_kill_xfer(struct ata_channel *c
 		printf("ahci_cmd_kill_xfer: unknown reason %d\n", reason);
 		panic("ahci_cmd_kill_xfer");
 	}
-	ahci_cmd_done(chp, xfer, 0 /* XXX slot */);
+	ahci_cmd_done(chp, xfer);
 }
 
 static int
 ahci_cmd_complete(struct ata_channel *chp, struct ata_xfer *xfer, int is)
 {
-	int slot = 0; /* XXX slot */
 	struct ata_command *ata_c = >c_ata_c;
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
@@ -1099,12 +1098,12 @@ ahci_cmd_complete(struct ata_channel *ch
 	if (ata_c->flags & AT_READREG)
 		satafis_rdh_cmd_readreg(ata_c, achp->ahcic_rfis->rfis_rfis);
 
-	ahci_cmd_done(chp, xfer, slot);
+	ahci_cmd_done(chp, xfer);
 	return 0;
 }
 
 static void
-ahci_cmd_done(struct ata_channel *chp, struct ata_xfer *xfer, int slot)
+ahci_cmd_done(struct ata_channel *chp, struct ata_xfer *xfer)
 {
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
@@ -1116,17 +1115,17 @@ ahci_cmd_done(struct ata_channel *chp, s
 	chp->ch_channel, chp->ch_status, xfer->c_flags, ata_c->flags), DEBUG_FUNCS);
 
 	/* this comamnd is not active any more */
-	achp->ahcic_cmds_active &= ~(1 << slot);
+	achp->ahcic_cmds_active &= ~(1 << xfer->c_slot);
 
 	if (ata_c->flags & (AT_READ|AT_WRITE) && ata_c->bcount > 0) {
-		bus_dmamap_t map = achp->ahcic_datad[slot];
+		bus_dmamap_t map = achp->ahcic_datad[xfer->c_slot];
 		bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
 		(ata_c->flags & AT_READ) ? BUS_DMASYNC_POSTREAD :
 		BUS_DMASYNC_POSTWRITE);
 		bus_dmamap_unload(sc->sc_dmat, map);
 	}
 
-	AHCI_CMDH_SYNC(sc, achp, slot,
+	AHCI_CMDH_SYNC(sc, achp, xfer->c_slot,
 	BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
 
 	/* ata(4) expects IDENTIFY data to be in host endianess */
@@ -1139,7 +1138,7 @@ ahci_cmd_done(struct ata_channel *chp, s
 	}
 
 	ata_c->flags |= AT_DONE;
-	if (achp->ahcic_cmdh[slot].cmdh_prdbc)
+	if (achp->ahcic_cmdh[xfer->c_slot].cmdh_prdbc)
 		ata_c->flags |= AT_XFDONE;
 
 	if (ata_c->flags & AT_WAIT)
@@ -1178,7 +1177,6 @@ ahci_bio_start(struct ata_channel *chp, 
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 	struct ata_bio *ata_bio = >c_bio;
-	int slot = 0 /* XXX slot */;
 	struct ahci_cmd_tbl *cmd_tbl;
 	struct ahci_cmd_header *cmd_h;
 	int i;
@@ -1187,28 +1185,28 @@ ahci_bio_start(struct ata_channel *chp, 
 	AHCIDEBUG_PRINT(("ahci_bio_start CI 0x%x\n",
 	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))), DEBUG_XFERS);
 
-	cmd_tbl = 

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

2017-04-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Apr 15 23:54:41 UTC 2017

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

Log Message:
ahci_intr_port(): use same code on both the error and non-error path for
for getting the slot and skipping interrupts for non-active slots


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.4 -r1.57.6.5 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.57.6.4 src/sys/dev/ic/ahcisata_core.c:1.57.6.5
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.4	Sat Apr 15 17:14:11 2017
+++ src/sys/dev/ic/ahcisata_core.c	Sat Apr 15 23:54:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.4 2017/04/15 17:14:11 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.5 2017/04/15 23:54:41 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.4 2017/04/15 17:14:11 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.5 2017/04/15 23:54:41 jdolecek Exp $");
 
 #include 
 #include 
@@ -566,12 +566,13 @@ ahci_intr_port(struct ahci_softc *sc, st
 	chp->ch_channel, is, AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))),
 	DEBUG_INTR);
 
+	slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
+		& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
+	if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
+		return;
+
 	if (is & (AHCI_P_IX_TFES | AHCI_P_IX_HBFS | AHCI_P_IX_IFS |
 	AHCI_P_IX_OFS | AHCI_P_IX_UFS)) {
-		slot = (AHCI_READ(sc, AHCI_P_CMD(chp->ch_channel))
-			& AHCI_P_CMD_CCS_MASK) >> AHCI_P_CMD_CCS_SHIFT;
-		if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-			return;
 		/* stop channel */
 		ahci_channel_stop(sc, chp, 0);
 		if (slot != 0) {
@@ -600,14 +601,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 		== 0)
 			ahci_channel_start(sc, chp, 0, 0);
 	} else {
-		slot = 0; /* XXX */
 		xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, slot);
-		is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
-		AHCIDEBUG_PRINT(("ahci_intr_port port %d is 0x%x act 0x%x CI 0x%x\n",
-		chp->ch_channel, is, achp->ahcic_cmds_active,
-		AHCI_READ(sc, AHCI_P_CI(chp->ch_channel))), DEBUG_INTR);
-		if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
-			return;
 		if ((AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)) & (1 << slot))
 		== 0) {
 			xfer->c_intr(chp, xfer, 0);



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

2017-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 11 18:14:47 UTC 2017

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

Log Message:
remove left-over curly brace


To generate a diff of this commit:
cvs rdiff -u -r1.35.6.2 -r1.35.6.3 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.35.6.2 src/sys/dev/ic/mvsata.c:1.35.6.3
--- src/sys/dev/ic/mvsata.c:1.35.6.2	Tue Apr 11 18:13:17 2017
+++ src/sys/dev/ic/mvsata.c	Tue Apr 11 18:14:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.2 2017/04/11 18:13:17 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.3 2017/04/11 18:14:47 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.2 2017/04/11 18:13:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.3 2017/04/11 18:14:47 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -1453,7 +1453,7 @@ mvsata_bio_done(struct ata_channel *chp,
 	ata_deactivate_xfer(chp, xfer);
 	ata_free_xfer(chp, xfer);
 
-	if (ata_waitdrain_check(chp, drive)) {
+	if (ata_waitdrain_check(chp, drive))
 		ata_bio->error = ERR_NODEV;
 	ata_bio->flags |= ATA_ITSDONE;
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc);



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

2017-04-11 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Apr 11 18:13:17 UTC 2017

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

Log Message:
fix to not access active_xfer directly


To generate a diff of this commit:
cvs rdiff -u -r1.57.6.1 -r1.57.6.2 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.35.6.1 -r1.35.6.2 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.30.4.1 -r1.30.4.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.57.6.1 src/sys/dev/ic/ahcisata_core.c:1.57.6.2
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.1	Mon Apr 10 22:57:02 2017
+++ src/sys/dev/ic/ahcisata_core.c	Tue Apr 11 18:13:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.1 2017/04/10 22:57:02 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.2 2017/04/11 18:13:17 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.1 2017/04/10 22:57:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.2 2017/04/11 18:13:17 jdolecek Exp $");
 
 #include 
 #include 
@@ -1433,7 +1433,7 @@ static void
 ahci_timeout(void *v)
 {
 	struct ata_channel *chp = (struct ata_channel *)v;
-	struct ata_xfer *xfer = chp->ch_queue->active_xfers[0];
+	struct ata_xfer *xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, 0); /* XXX slot */
 #ifdef AHCI_DEBUG
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 #endif

Index: src/sys/dev/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.35.6.1 src/sys/dev/ic/mvsata.c:1.35.6.2
--- src/sys/dev/ic/mvsata.c:1.35.6.1	Mon Apr 10 22:57:02 2017
+++ src/sys/dev/ic/mvsata.c	Tue Apr 11 18:13:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.1 2017/04/10 22:57:02 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.2 2017/04/11 18:13:17 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.1 2017/04/10 22:57:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.2 2017/04/11 18:13:17 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -630,7 +630,10 @@ mvsata_reset_channel(struct ata_channel 
 		xfer = mvport->port_reqtbl[i].xfer;
 		if (xfer == NULL)
 			continue;
-		chp->ch_queue->active_xfers[0] = xfer;
+#if 0
+		/* This doesn't seem to be needed? */
+		chp->ch_queue->active_xfers[0] = xfer; /* XXX slot */
+#endif
 		xfer->c_kill_xfer(chp, xfer, KILL_RESET);
 	}
 
@@ -1447,15 +1450,11 @@ mvsata_bio_done(struct ata_channel *chp,
 	ata_bio->bcount = xfer->c_bcount;
 
 	/* mark controller inactive and free xfer */
-	KASSERT(chp->ch_queue->active_xfers[0] != NULL);
 	ata_deactivate_xfer(chp, xfer);
 	ata_free_xfer(chp, xfer);
 
-	if (chp->ch_drive[drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
+	if (ata_waitdrain_check(chp, drive)) {
 		ata_bio->error = ERR_NODEV;
-		chp->ch_drive[drive].drive_flags &= ~ATA_DRIVE_WAITDRAIN;
-		wakeup(chp->ch_queue->active_xfers);
-	}
 	ata_bio->flags |= ATA_ITSDONE;
 	(*chp->ch_drive[drive].drv_done)(chp->ch_drive[drive].drv_softc);
 	atastart(chp);
@@ -1820,11 +1819,8 @@ mvsata_wdc_cmd_done(struct ata_channel *
 		MVSATA_WDC_WRITE_1(mvport, SRB_CAS, WDCTL_4BIT);
 		delay(10);	/* some drives need a little delay here */
 	}
-	if (chp->ch_drive[xfer->c_drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
-		mvsata_wdc_cmd_kill_xfer(chp, xfer, KILL_GONE);
-		chp->ch_drive[xfer->c_drive].drive_flags &= ~ATA_DRIVE_WAITDRAIN;
-		wakeup(chp->ch_queue->active_xfers);
-	} else
+
+	if (!ata_waitdrain_xfer_check(chp, xfer))
 		mvsata_wdc_cmd_done_end(chp, xfer);
 }
 
@@ -2462,8 +2458,9 @@ mvsata_edma_enqueue(struct mvsata_port *
 		return rv;
 
 	KASSERT(mvport->port_reqtbl[quetag].xfer == NULL);
-	KASSERT(chp->ch_queue->active_xfers[0] != NULL);
-	mvport->port_reqtbl[quetag].xfer = chp->ch_queue->active_xfers[0];
+	KASSERT(ata_queue_hwslot_to_xfer(chp->ch_queue, 0) != NULL);
+	mvport->port_reqtbl[quetag].xfer = ata_queue_hwslot_to_xfer(
+	chp->ch_queue, 0);	/* XXX slot */
 
 	/* setup EDMA Physical Region Descriptors (ePRD) Table Data */
 	data_dmamap = mvport->port_reqtbl[quetag].data_dmamap;
@@ -2576,8 +2573,8 @@ mvsata_edma_handle(struct mvsata_port *m
 #endif
 		crpb = mvport->port_crpb + erpqop;
 		quetag = CRPB_CHOSTQUETAG(le16toh(crpb->id));
-		KASSERT(chp->ch_queue->active_xfers[0] != NULL);
-		xfer = chp->ch_queue->active_xfers[0];
+		xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, 0); /* XXX slot */
+		KASSERT(xfer != NULL);
 		KASSERT(xfer == mvport->port_reqtbl[quetag].xfer);
 #ifdef DIAGNOSTIC
 		if (xfer == NULL)
@@ -2765,9 +2762,10 @@ mvsata_bdma_init(struct mvsata_port *mvp
 	if (rv != 0)
 		return rv;
 
-	KASSERT(chp->ch_queue->active_xfers[0] != NULL);
+	KASSERT(ata_queue_hwslot_to_xfer(chp->ch_queue, 0) !=