Module Name:    src
Committed By:   jdolecek
Date:           Wed Jun 21 22:34:46 UTC 2017

Modified Files:
        src/sys/dev/ata [jdolecek-ncq]: ata.c
        src/sys/dev/scsipi [jdolecek-ncq]: atapi_wdc.c

Log Message:
two last forgotten on-stack xfers replaced with using the queue xfer -
ata_get_params() and ata_set_mode()

fix wdc_atapi_get_params() to free the xfer used for soft reset before
calling ata_get_params() - it's now necessary, as ata_get_params() doesn't
invent a private xfer own any more


To generate a diff of this commit:
cvs rdiff -u -r1.132.8.13 -r1.132.8.14 src/sys/dev/ata/ata.c
cvs rdiff -u -r1.123.4.7 -r1.123.4.8 src/sys/dev/scsipi/atapi_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/ata/ata.c
diff -u src/sys/dev/ata/ata.c:1.132.8.13 src/sys/dev/ata/ata.c:1.132.8.14
--- src/sys/dev/ata/ata.c:1.132.8.13	Wed Jun 21 19:38:43 2017
+++ src/sys/dev/ata/ata.c	Wed Jun 21 22:34:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata.c,v 1.132.8.13 2017/06/21 19:38:43 jdolecek Exp $	*/
+/*	$NetBSD: ata.c,v 1.132.8.14 2017/06/21 22:34:46 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.13 2017/06/21 19:38:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.132.8.14 2017/06/21 22:34:46 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -129,8 +129,6 @@ static bool atabus_resume(device_t, cons
 static bool atabus_suspend(device_t, const pmf_qual_t *);
 static void atabusconfig_thread(void *);
 
-static void ata_xfer_init(struct ata_xfer *, bool);
-static void ata_xfer_destroy(struct ata_xfer *);
 static void ata_channel_idle(struct ata_channel *);
 
 /*
@@ -859,7 +857,7 @@ int
 ata_get_params(struct ata_drive_datas *drvp, uint8_t flags,
     struct ataparams *prms)
 {
-	struct ata_xfer xfer;
+	struct ata_xfer *xfer;
 	struct ata_channel *chp = drvp->chnl_softc;
 	struct atac_softc *atac = chp->ch_atac;
 	char *tb;
@@ -868,44 +866,50 @@ ata_get_params(struct ata_drive_datas *d
 
 	ATADEBUG_PRINT(("%s\n", __func__), DEBUG_FUNCS);
 
+	xfer = ata_get_xfer(chp);
+	if (xfer == NULL) {
+		ATADEBUG_PRINT(("%s: no xfer\n", __func__),
+		    DEBUG_FUNCS|DEBUG_PROBE);
+		return CMD_AGAIN;
+	}
+
 	tb = kmem_zalloc(DEV_BSIZE, KM_SLEEP);
 	memset(prms, 0, sizeof(struct ataparams));
-	ata_xfer_init(&xfer, true);
 
 	if (drvp->drive_type == ATA_DRIVET_ATA) {
-		xfer.c_ata_c.r_command = WDCC_IDENTIFY;
-		xfer.c_ata_c.r_st_bmask = WDCS_DRDY;
-		xfer.c_ata_c.r_st_pmask = WDCS_DRQ;
-		xfer.c_ata_c.timeout = 3000; /* 3s */
+		xfer->c_ata_c.r_command = WDCC_IDENTIFY;
+		xfer->c_ata_c.r_st_bmask = WDCS_DRDY;
+		xfer->c_ata_c.r_st_pmask = WDCS_DRQ;
+		xfer->c_ata_c.timeout = 3000; /* 3s */
 	} else if (drvp->drive_type == ATA_DRIVET_ATAPI) {
-		xfer.c_ata_c.r_command = ATAPI_IDENTIFY_DEVICE;
-		xfer.c_ata_c.r_st_bmask = 0;
-		xfer.c_ata_c.r_st_pmask = WDCS_DRQ;
-		xfer.c_ata_c.timeout = 10000; /* 10s */
+		xfer->c_ata_c.r_command = ATAPI_IDENTIFY_DEVICE;
+		xfer->c_ata_c.r_st_bmask = 0;
+		xfer->c_ata_c.r_st_pmask = WDCS_DRQ;
+		xfer->c_ata_c.timeout = 10000; /* 10s */
 	} else {
 		ATADEBUG_PRINT(("ata_get_parms: no disks\n"),
 		    DEBUG_FUNCS|DEBUG_PROBE);
 		rv = CMD_ERR;
 		goto out;
 	}
-	xfer.c_ata_c.flags = AT_READ | flags;
-	xfer.c_ata_c.data = tb;
-	xfer.c_ata_c.bcount = DEV_BSIZE;
+	xfer->c_ata_c.flags = AT_READ | flags;
+	xfer->c_ata_c.data = tb;
+	xfer->c_ata_c.bcount = DEV_BSIZE;
 	if ((*atac->atac_bustype_ata->ata_exec_command)(drvp,
-						&xfer) != ATACMD_COMPLETE) {
+						xfer) != ATACMD_COMPLETE) {
 		ATADEBUG_PRINT(("ata_get_parms: wdc_exec_command failed\n"),
 		    DEBUG_FUNCS|DEBUG_PROBE);
 		rv = CMD_AGAIN;
 		goto out;
 	}
-	if (xfer.c_ata_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
+	if (xfer->c_ata_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
 		ATADEBUG_PRINT(("ata_get_parms: ata_c.flags=0x%x\n",
-		    xfer.c_ata_c.flags), DEBUG_FUNCS|DEBUG_PROBE);
+		    xfer->c_ata_c.flags), DEBUG_FUNCS|DEBUG_PROBE);
 		rv = CMD_ERR;
 		goto out;
 	}
 	/* if we didn't read any data something is wrong */
-	if ((xfer.c_ata_c.flags & AT_XFDONE) == 0) {
+	if ((xfer->c_ata_c.flags & AT_XFDONE) == 0) {
 		rv = CMD_ERR;
 		goto out;
 	}
@@ -953,35 +957,40 @@ ata_get_params(struct ata_drive_datas *d
 	rv = CMD_OK;
  out:
 	kmem_free(tb, DEV_BSIZE);
-	ata_xfer_destroy(&xfer);
+	ata_free_xfer(chp, xfer);
 	return rv;
 }
 
 int
 ata_set_mode(struct ata_drive_datas *drvp, uint8_t mode, uint8_t flags)
 {
-	struct ata_xfer xfer;
+	struct ata_xfer *xfer;
 	int rv;
 	struct ata_channel *chp = drvp->chnl_softc;
 	struct atac_softc *atac = chp->ch_atac;
 
 	ATADEBUG_PRINT(("ata_set_mode=0x%x\n", mode), DEBUG_FUNCS);
 
-	ata_xfer_init(&xfer, true);
+	xfer = ata_get_xfer(chp);
+	if (xfer == NULL) {
+		ATADEBUG_PRINT(("%s: no xfer\n", __func__),
+		    DEBUG_FUNCS|DEBUG_PROBE);
+		return CMD_AGAIN;
+	}
 
-	xfer.c_ata_c.r_command = SET_FEATURES;
-	xfer.c_ata_c.r_st_bmask = 0;
-	xfer.c_ata_c.r_st_pmask = 0;
-	xfer.c_ata_c.r_features = WDSF_SET_MODE;
-	xfer.c_ata_c.r_count = mode;
-	xfer.c_ata_c.flags = flags;
-	xfer.c_ata_c.timeout = 1000; /* 1s */
+	xfer->c_ata_c.r_command = SET_FEATURES;
+	xfer->c_ata_c.r_st_bmask = 0;
+	xfer->c_ata_c.r_st_pmask = 0;
+	xfer->c_ata_c.r_features = WDSF_SET_MODE;
+	xfer->c_ata_c.r_count = mode;
+	xfer->c_ata_c.flags = flags;
+	xfer->c_ata_c.timeout = 1000; /* 1s */
 	if ((*atac->atac_bustype_ata->ata_exec_command)(drvp,
-						&xfer) != ATACMD_COMPLETE) {
+						xfer) != ATACMD_COMPLETE) {
 		rv = CMD_AGAIN;
 		goto out;
 	}
-	if (xfer.c_ata_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
+	if (xfer->c_ata_c.flags & (AT_ERROR | AT_TIMEOU | AT_DF)) {
 		rv = CMD_ERR;
 		goto out;
 	}
@@ -989,7 +998,7 @@ ata_set_mode(struct ata_drive_datas *drv
 	rv = CMD_OK;
 
 out:
-	ata_xfer_destroy(&xfer);
+	ata_free_xfer(chp, xfer);
 	return rv;
 }
 

Index: src/sys/dev/scsipi/atapi_wdc.c
diff -u src/sys/dev/scsipi/atapi_wdc.c:1.123.4.7 src/sys/dev/scsipi/atapi_wdc.c:1.123.4.8
--- src/sys/dev/scsipi/atapi_wdc.c:1.123.4.7	Tue Jun 20 20:58:23 2017
+++ src/sys/dev/scsipi/atapi_wdc.c	Wed Jun 21 22:34:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: atapi_wdc.c,v 1.123.4.7 2017/06/20 20:58:23 jdolecek Exp $	*/
+/*	$NetBSD: atapi_wdc.c,v 1.123.4.8 2017/06/21 22:34:46 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.123.4.7 2017/06/20 20:58:23 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.123.4.8 2017/06/21 22:34:46 jdolecek Exp $");
 
 #ifndef ATADEBUG
 #define ATADEBUG
@@ -224,10 +224,12 @@ wdc_atapi_get_params(struct scsipi_chann
 		    device_xname(atac->atac_dev), chp->ch_channel, drive,
 		    xfer->c_ata_c.r_error), DEBUG_PROBE);
 		rv = -1;
-		goto out;
+		goto out_xfer;
 	}
 	chp->ch_drive[drive].state = 0;
 
+	ata_free_xfer(chp, xfer);
+
 	(void)bus_space_read_1(wdr->cmd_iot, wdr->cmd_iohs[wd_status], 0);
 
 	/* Some ATAPI devices need a bit more time after software reset. */
@@ -241,8 +243,10 @@ wdc_atapi_get_params(struct scsipi_chann
 		goto out;
 	}
 	rv = 0;
-
 out:
+	return rv;
+
+out_xfer:
 	ata_free_xfer(chp, xfer);
 	return rv;
 }

Reply via email to