Module Name:    src
Committed By:   jdolecek
Date:           Wed Jun 21 19:38:43 UTC 2017

Modified Files:
        src/sys/dev/ata [jdolecek-ncq]: ata.c atavar.h
        src/sys/dev/ic [jdolecek-ncq]: ahcisata_core.c mvsata.c siisata.c wdc.c
        src/sys/dev/usb [jdolecek-ncq]: umass_isdata.c

Log Message:
change ata_queue_hwslot_to_xfer() and ata_queue_get_active_xfer() to take
ata_channel instead of ata_queue as parameter, and lock the channel while
traversing the queue


To generate a diff of this commit:
cvs rdiff -u -r1.132.8.12 -r1.132.8.13 src/sys/dev/ata/ata.c
cvs rdiff -u -r1.92.8.12 -r1.92.8.13 src/sys/dev/ata/atavar.h
cvs rdiff -u -r1.57.6.15 -r1.57.6.16 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.35.6.13 -r1.35.6.14 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.30.4.18 -r1.30.4.19 src/sys/dev/ic/siisata.c
cvs rdiff -u -r1.283.2.8 -r1.283.2.9 src/sys/dev/ic/wdc.c
cvs rdiff -u -r1.33.4.4 -r1.33.4.5 src/sys/dev/usb/umass_isdata.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ata/ata.c
diff -u src/sys/dev/ata/ata.c:1.132.8.12 src/sys/dev/ata/ata.c:1.132.8.13
--- src/sys/dev/ata/ata.c:1.132.8.12	Tue Jun 20 20:58:22 2017
+++ src/sys/dev/ata/ata.c	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata.c,v 1.132.8.12 2017/06/20 20:58:22 jdolecek Exp $	*/
+/*	$NetBSD: ata.c,v 1.132.8.13 2017/06/21 19:38:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.12 2017/06/20 20:58:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.13 2017/06/21 19:38:43 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -196,9 +196,12 @@ ata_queue_reset(struct ata_queue *chq)
 }
 
 struct ata_xfer *
-ata_queue_hwslot_to_xfer(struct ata_queue *chq, int hwslot)
+ata_queue_hwslot_to_xfer(struct ata_channel *chp, int hwslot)
 {
-	struct ata_xfer *xfer;
+	struct ata_queue *chq = chp->ch_queue;
+	struct ata_xfer *xfer = NULL;
+
+	mutex_enter(&chp->ch_lock);
 
 	KASSERT(hwslot < chq->queue_openings);
 	KASSERT((chq->active_xfers_used & __BIT(hwslot)) != 0);
@@ -206,11 +209,16 @@ ata_queue_hwslot_to_xfer(struct ata_queu
 	/* Usually the first entry will be the one */
 	TAILQ_FOREACH(xfer, &chq->active_xfers, c_activechain) {
 		if (xfer->c_slot == hwslot)
-			return xfer;
+			break;
 	}
 
-	panic("%s: xfer with slot %d not found (active %x)", __func__, hwslot,
-	    chq->active_xfers_used);
+	mutex_exit(&chp->ch_lock);
+
+	KASSERTMSG((xfer != NULL),
+	    "%s: xfer with slot %d not found (active %x)", __func__,
+	    hwslot, chq->active_xfers_used);
+
+	return xfer;
 }
 
 /*
@@ -220,10 +228,18 @@ ata_queue_hwslot_to_xfer(struct ata_queu
  * is preferred in all NCQ cases.
  */
 struct ata_xfer *
-ata_queue_get_active_xfer(struct ata_queue *chq)
+ata_queue_get_active_xfer(struct ata_channel *chp)
 {
-	KASSERT(chq->queue_active <= 1);
-	return TAILQ_FIRST(&chq->active_xfers);
+	struct ata_xfer *xfer = NULL;
+
+	mutex_enter(&chp->ch_lock);
+
+	KASSERT(chp->ch_queue->queue_active <= 1);
+	xfer = TAILQ_FIRST(&chp->ch_queue->active_xfers);
+
+	mutex_exit(&chp->ch_lock);
+
+	return xfer;
 }
 
 static void

Index: src/sys/dev/ata/atavar.h
diff -u src/sys/dev/ata/atavar.h:1.92.8.12 src/sys/dev/ata/atavar.h:1.92.8.13
--- src/sys/dev/ata/atavar.h:1.92.8.12	Wed Jun 21 19:21:25 2017
+++ src/sys/dev/ata/atavar.h	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: atavar.h,v 1.92.8.12 2017/06/21 19:21:25 jdolecek Exp $	*/
+/*	$NetBSD: atavar.h,v 1.92.8.13 2017/06/21 19:38:43 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -516,9 +516,9 @@ struct ata_queue *
 	ata_queue_alloc(uint8_t openings);
 void	ata_queue_free(struct ata_queue *);
 struct ata_xfer *
-	ata_queue_hwslot_to_xfer(struct ata_queue *, int);
+	ata_queue_hwslot_to_xfer(struct ata_channel *, int);
 struct ata_xfer *
-	ata_queue_get_active_xfer(struct ata_queue *);
+	ata_queue_get_active_xfer(struct ata_channel *);
 
 void	ata_delay(int, const char *, int);
 

Index: src/sys/dev/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.57.6.15 src/sys/dev/ic/ahcisata_core.c:1.57.6.16
--- src/sys/dev/ic/ahcisata_core.c:1.57.6.15	Tue Jun 20 20:58:22 2017
+++ src/sys/dev/ic/ahcisata_core.c	Wed Jun 21 19:38:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.57.6.15 2017/06/20 20:58:22 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.57.6.16 2017/06/21 19:38:42 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.15 2017/06/20 20:58:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.57.6.16 2017/06/21 19:38:42 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -577,8 +577,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 		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 = ata_queue_hwslot_to_xfer(chp, slot);
 			xfer->c_intr(chp, xfer, 0);
 		}
 	}
@@ -608,8 +607,7 @@ ahci_intr_port(struct ahci_softc *sc, st
 			if ((achp->ahcic_cmds_active & (1 << slot)) == 0)
 				continue;
 			if ((active & (1 << slot)) == 1) {
-				xfer = ata_queue_hwslot_to_xfer(chp->ch_queue,
-				    slot);
+				xfer = ata_queue_hwslot_to_xfer(chp, slot);
 				xfer->c_intr(chp, xfer, is);
 			}
 		}

Index: src/sys/dev/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.35.6.13 src/sys/dev/ic/mvsata.c:1.35.6.14
--- src/sys/dev/ic/mvsata.c:1.35.6.13	Tue Jun 20 20:58:22 2017
+++ src/sys/dev/ic/mvsata.c	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.35.6.13 2017/06/20 20:58:22 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.35.6.14 2017/06/21 19:38:43 jdolecek Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.13 2017/06/20 20:58:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.35.6.14 2017/06/21 19:38:43 jdolecek Exp $");
 
 #include "opt_mvsata.h"
 
@@ -447,7 +447,7 @@ mvsata_nondma_handle(struct mvsata_port 
 	}
 	KASSERT(quetag < MVSATA_EDMAQ_LEN);
 
-	xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, quetag);
+	xfer = ata_queue_hwslot_to_xfer(chp, quetag);
 	chp->ch_flags &= ~ATACH_IRQ_WAIT;
 	KASSERT(xfer->c_intr != NULL);
 	ret = xfer->c_intr(chp, xfer, 1);
@@ -2587,7 +2587,7 @@ mvsata_edma_handle(struct mvsata_port *m
 		crpb = mvport->port_crpb + erpqop;
 		quetag = CRPB_CHOSTQUETAG(le16toh(crpb->id));
 
-		xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, quetag);
+		xfer = ata_queue_hwslot_to_xfer(chp, quetag);
 
 		bus_dmamap_sync(mvport->port_dmat, mvport->port_eprd_dmamap,
 		    mvport->port_reqtbl[xfer->c_slot].eprd_offset,
@@ -2720,7 +2720,7 @@ mvsata_edma_rqq_remove(struct mvsata_por
 			continue;
 		}
 
-		rqxfer = ata_queue_hwslot_to_xfer(chp->ch_queue, i);
+		rqxfer = ata_queue_hwslot_to_xfer(chp, i);
 		sc->sc_edma_setup_crqb(mvport, erqqip, rqxfer);
 		erqqip++;
 	}

Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.30.4.18 src/sys/dev/ic/siisata.c:1.30.4.19
--- src/sys/dev/ic/siisata.c:1.30.4.18	Tue Jun 20 21:00:47 2017
+++ src/sys/dev/ic/siisata.c	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.30.4.18 2017/06/20 21:00:47 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.30.4.19 2017/06/21 19:38:43 jdolecek Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.18 2017/06/20 21:00:47 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.30.4.19 2017/06/21 19:38:43 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -494,7 +494,7 @@ siisata_intr_port(struct siisata_channel
 		if (((pss >> slot) & 1) != 0)
 			/* execution is incomplete or unsuccessful, skip for now */
 			continue;
-		xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, slot);
+		xfer = ata_queue_hwslot_to_xfer(chp, slot);
 		if (xfer->c_intr == NULL) {
 			wakeup(schp);
 			continue;
@@ -556,7 +556,7 @@ siisata_intr_port(struct siisata_channel
 			/* there's nothing executing here, skip */
 			if (((schp->sch_active_slots >> slot) & 1) == 0)
 				continue;
-			xfer = ata_queue_hwslot_to_xfer(chp->ch_queue, slot);
+			xfer = ata_queue_hwslot_to_xfer(chp, slot);
 			if (xfer == NULL)
 				continue;
 			xfer->c_intr(chp, xfer, 0);

Index: src/sys/dev/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.283.2.8 src/sys/dev/ic/wdc.c:1.283.2.9
--- src/sys/dev/ic/wdc.c:1.283.2.8	Wed Jun 21 19:21:25 2017
+++ src/sys/dev/ic/wdc.c	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.283.2.8 2017/06/21 19:21:25 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.283.2.9 2017/06/21 19:38:43 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.8 2017/06/21 19:21:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.283.2.9 2017/06/21 19:38:43 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -873,7 +873,7 @@ wdcintr(void *arg)
 	}
 
 	ATADEBUG_PRINT(("wdcintr\n"), DEBUG_INTR);
-	xfer = ata_queue_get_active_xfer(chp->ch_queue);
+	xfer = ata_queue_get_active_xfer(chp);
 	KASSERT(xfer != NULL);
 #ifdef DIAGNOSTIC
 	if (xfer->c_chp != chp) {
@@ -931,7 +931,7 @@ wdc_reset_channel(struct ata_channel *ch
 	 * if the current command is on an ATAPI device, issue a
 	 * ATAPI_SOFT_RESET
 	 */
-	xfer = ata_queue_get_active_xfer(chp->ch_queue);
+	xfer = ata_queue_get_active_xfer(chp);
 	if (xfer && xfer->c_chp == chp && (xfer->c_flags & C_ATAPI)) {
 		wdccommandshort(chp, xfer->c_drive, ATAPI_SOFT_RESET);
 		if (flags & AT_WAIT)
@@ -1204,7 +1204,7 @@ __wdcwait(struct ata_channel *chp, int m
 	if (!cold && xtime > WDCNDELAY_DEBUG) {
 		struct ata_xfer *xfer;
 
-		xfer = ata_queue_get_active_xfer(chp->ch_queue);
+		xfer = ata_queue_get_active_xfer(chp);
 		if (xfer == NULL)
 			printf("%s channel %d: warning: busy-wait took %dus\n",
 			    device_xname(chp->ch_atac->atac_dev),
@@ -1812,7 +1812,7 @@ static void
 __wdcerror(struct ata_channel *chp, const char *msg)
 {
 	struct atac_softc *atac = chp->ch_atac;
-	struct ata_xfer *xfer = ata_queue_get_active_xfer(chp->ch_queue);
+	struct ata_xfer *xfer = ata_queue_get_active_xfer(chp);
 
 	if (xfer == NULL)
 		aprint_error("%s:%d: %s\n", device_xname(atac->atac_dev),

Index: src/sys/dev/usb/umass_isdata.c
diff -u src/sys/dev/usb/umass_isdata.c:1.33.4.4 src/sys/dev/usb/umass_isdata.c:1.33.4.5
--- src/sys/dev/usb/umass_isdata.c:1.33.4.4	Tue Jun 20 20:58:22 2017
+++ src/sys/dev/usb/umass_isdata.c	Wed Jun 21 19:38:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: umass_isdata.c,v 1.33.4.4 2017/06/20 20:58:22 jdolecek Exp $	*/
+/*	$NetBSD: umass_isdata.c,v 1.33.4.5 2017/06/21 19:38:43 jdolecek Exp $	*/
 
 /*
  * TODO:
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_isdata.c,v 1.33.4.4 2017/06/20 20:58:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_isdata.c,v 1.33.4.5 2017/06/21 19:38:43 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -502,7 +502,7 @@ uisdata_kill_pending(struct ata_drive_da
 	struct ata_channel *chp = drv->chnl_softc;
 	struct umass_softc *sc = CH2SELF(chp);
 	struct uisdata_softc *scbus = (struct uisdata_softc *)sc->bus;
-	struct ata_xfer *xfer = ata_queue_get_active_xfer(chp->ch_queue);
+	struct ata_xfer *xfer = ata_queue_get_active_xfer(chp);
 	struct ata_bio *ata_bio = &xfer->c_bio;
 
 	DPRINTFN(-1,("%s\n", __func__));

Reply via email to