PERFORCE change 165764 for review

Scott Long scottl at FreeBSD.org
Tue Jul 7 17:49:04 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=165764

Change 165764 by scottl at scottl-y1 on 2009/07/07 17:48:54

	Add a 'maxio' parameter to the XPT_PATH_INQ/cpi structure.  It represents
	the max number of bytes that the SIM can handle for an i/o transaction,
	and is passed to the disk/block layer by the periphs.  For legacy
	compatibility, not setting it, or setting it to 0, results in a default
	of 64k for the 'da' driver, just like it always has been.
	
	Eliminate the blind use of MAXPHYS throughout the driver tree, in preparation
	for MAXPHYS being increased.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/cam/cam_ccb.h#23 edit
.. //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_da.c#40 edit
.. //depot/projects/scottl-camlock/src/sys/dev/advansys/advansys.c#12 edit
.. //depot/projects/scottl-camlock/src/sys/dev/advansys/advlib.h#4 edit
.. //depot/projects/scottl-camlock/src/sys/dev/aic7xxx/aic79xx_osm.h#13 edit
.. //depot/projects/scottl-camlock/src/sys/dev/aic7xxx/aic7xxx_osm.h#14 edit
.. //depot/projects/scottl-camlock/src/sys/dev/amd/amd.h#3 edit
.. //depot/projects/scottl-camlock/src/sys/dev/ciss/ciss.c#20 edit
.. //depot/projects/scottl-camlock/src/sys/dev/ciss/cissvar.h#6 edit
.. //depot/projects/scottl-camlock/src/sys/dev/firewire/sbp.c#13 edit
.. //depot/projects/scottl-camlock/src/sys/dev/isp/isp_freebsd.h#18 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mfi/mfi.c#16 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mfi/mfivar.h#8 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mlx/mlx.c#7 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mlx/mlxvar.h#3 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mpt/mpt.h#22 edit
.. //depot/projects/scottl-camlock/src/sys/dev/mpt/mpt_pci.c#23 edit
.. //depot/projects/scottl-camlock/src/sys/dev/trm/trm.h#3 edit
.. //depot/projects/scottl-camlock/src/sys/kern/subr_bus.c#26 integrate

Differences ...

==== //depot/projects/scottl-camlock/src/sys/cam/cam_ccb.h#23 (text+ko) ====

@@ -572,6 +572,7 @@
 		struct ccb_pathinq_settings_sas sas;
 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
 	} xport_specific;
+	u_int		maxio;		/* Max supported I/O size, in bytes. */
 };
 
 /* Path Statistics CCB */

==== //depot/projects/scottl-camlock/src/sys/cam/scsi/scsi_da.c#40 (text+ko) ====

@@ -1198,6 +1198,7 @@
 		softc->quirks = DA_Q_NONE;
 
 	/* Check if the SIM does not want 6 byte commands */
+	bzero(&cpi, sizeof(cpi));
 	xpt_setup_ccb(&cpi.ccb_h, periph->path, /*priority*/1);
 	cpi.ccb_h.func_code = XPT_PATH_INQ;
 	xpt_action((union ccb *)&cpi);
@@ -1247,7 +1248,12 @@
 	softc->disk->d_dump = dadump;
 	softc->disk->d_name = "da";
 	softc->disk->d_drv1 = periph;
-	softc->disk->d_maxsize = DFLTPHYS; /* XXX: probably not arbitrary */
+	if (cpi.maxio == 0)
+		softc->disk->d_maxsize = DFLTPHYS;	/* traditional default */
+	else if (cpi.maxio > MAXPHYS)
+		softc->disk->d_maxsize = DFLTPHYS;	/* for safety */
+	else
+		softc->disk->d_maxsize = cpi.maxio;
 	softc->disk->d_unit = periph->unit_number;
 	softc->disk->d_flags = 0;
 	if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)

==== //depot/projects/scottl-camlock/src/sys/dev/advansys/advansys.c#12 (text+ko) ====

@@ -1345,7 +1345,7 @@
 			/* highaddr	*/ BUS_SPACE_MAXADDR,
 			/* filter	*/ NULL,
 			/* filterarg	*/ NULL,
-			/* maxsize	*/ MAXPHYS,
+			/* maxsize	*/ ADV_MAXPHYS,
 			/* nsegments	*/ max_sg,
 			/* maxsegsz	*/ BUS_SPACE_MAXSIZE_32BIT,
 			/* flags	*/ BUS_DMA_ALLOCNOW,

==== //depot/projects/scottl-camlock/src/sys/dev/advansys/advlib.h#4 (text+ko) ====

@@ -58,6 +58,8 @@
 #define ADV_MAX_TID		7
 #define ADV_MAX_LUN		7
 
+#define ADV_MAXPHYS		(128 * 1024)
+
 /* Enumeration of board types */
 typedef enum {
 	ADV_NONE	= 0x000,

==== //depot/projects/scottl-camlock/src/sys/dev/aic7xxx/aic79xx_osm.h#13 (text+ko) ====

@@ -102,7 +102,8 @@
  * The number of dma segments supported.  The sequencer can handle any number
  * of physically contiguous S/G entrys.  To reduce the driver's memory
  * consumption, we limit the number supported to be sufficient to handle
- * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
+ * the largest mapping supported by the the legacy kernel MAXPHYS setting of
+ * 128K.  This can be increased once some testing is done.  Assuming the
  * transfer is as fragmented as possible and unaligned, this turns out to
  * be the number of paged sized transfers in MAXPHYS plus an extra element
  * to handle any unaligned residual.  The sequencer fetches SG elements
@@ -110,7 +111,8 @@
  * multiple of 16 which should align us on even the largest of cacheline
  * boundaries. 
  */
-#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
+#define AHD_MAXPHYS (128 * 1024)
+#define AHD_NSEG (roundup(btoc(AHD_MAXPHYS) + 1, 16))
 
 /* This driver supports target mode */
 #ifdef NOT_YET

==== //depot/projects/scottl-camlock/src/sys/dev/aic7xxx/aic7xxx_osm.h#14 (text+ko) ====

@@ -115,15 +115,16 @@
  * The number of dma segments supported.  The sequencer can handle any number
  * of physically contiguous S/G entrys.  To reduce the driver's memory
  * consumption, we limit the number supported to be sufficient to handle
- * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
- * transfer is as fragmented as possible and unaligned, this turns out to
+ * the largest mapping supported by the the legacy kernel MAXPHYS setting of
+ * 128K.  This can be increased once some testing is done.  Assuming the
  * be the number of paged sized transfers in MAXPHYS plus an extra element
  * to handle any unaligned residual.  The sequencer fetches SG elements
  * in cacheline sized chucks, so make the number per-transaction an even
  * multiple of 16 which should align us on even the largest of cacheline
  * boundaries. 
  */
-#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
+#define AHC_MAXPHYS (128 * 1024)
+#define AHC_NSEG (roundup(btoc(AHC_MAXPHYS) + 1, 16))
 
 /* This driver supports target mode */
 #define AHC_TARGET_MODE 1

==== //depot/projects/scottl-camlock/src/sys/dev/amd/amd.h#3 (text+ko) ====

@@ -95,7 +95,8 @@
 #define AMD_MAX_SYNC_OFFSET	15
 #define AMD_TARGET_MAX	7
 #define AMD_LUN_MAX		7
-#define AMD_NSEG		(btoc(MAXPHYS) + 1)
+#define AMD_MAXPHYS		(128 * 1024) /* legacy MAXPHYS */
+#define AMD_NSEG		(btoc(AMD_MAXPHYS) + 1)
 #define AMD_MAXTRANSFER_SIZE	0xFFFFFF /* restricted by 24 bit counter */
 #define MAX_DEVICES		10
 #define MAX_TAGS_CMD_QUEUE	256

==== //depot/projects/scottl-camlock/src/sys/dev/ciss/ciss.c#20 (text+ko) ====

@@ -2976,6 +2976,7 @@
 	cpi->transport_version = 2;
 	cpi->protocol = PROTO_SCSI;
 	cpi->protocol_version = SCSI_REV_2;
+	cpi->maxio = (CISS_MAX_SG_ELEMENTS - 1) * PAGE_SIZE;
 	ccb->ccb_h.status = CAM_REQ_CMP;
 	break;
     }

==== //depot/projects/scottl-camlock/src/sys/dev/ciss/cissvar.h#6 (text+ko) ====

@@ -141,6 +141,9 @@
 #define CISS_COMMAND_SG_LENGTH	((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \
 				 / sizeof(struct ciss_sg_entry))
 
+/* XXX Prep for increasing max i/o */
+#define CISS_MAX_SG_ELEMENTS   33
+
 /*
  * Per-logical-drive data.
  */

==== //depot/projects/scottl-camlock/src/sys/dev/firewire/sbp.c#13 (text+ko) ====


==== //depot/projects/scottl-camlock/src/sys/dev/isp/isp_freebsd.h#18 (text+ko) ====

@@ -561,7 +561,8 @@
 #endif
 
 /* Should be BUS_SPACE_MAXSIZE, but MAXPHYS is larger than BUS_SPACE_MAXSIZE */
-#define ISP_NSEGS ((MAXPHYS / PAGE_SIZE) + 1)  
+#define ISP_MAXPHYS (128 * 1024)
+#define ISP_NSEGS ((ISP_MAXPHYS / PAGE_SIZE) + 1)  
 
 /*
  * Platform specific inline functions

==== //depot/projects/scottl-camlock/src/sys/dev/mfi/mfi.c#16 (text) ====

@@ -341,7 +341,7 @@
 	status = sc->mfi_read_fw_status(sc);
 	sc->mfi_max_fw_cmds = status & MFI_FWSTATE_MAXCMD_MASK;
 	max_fw_sge = (status & MFI_FWSTATE_MAXSGL_MASK) >> 16;
-	sc->mfi_max_sge = min(max_fw_sge, ((MAXPHYS / PAGE_SIZE) + 1));
+	sc->mfi_max_sge = min(max_fw_sge, ((MFI_MAXPHYS / PAGE_SIZE) + 1));
 
 	/*
 	 * Create the dma tag for data buffers.  Used both for block I/O

==== //depot/projects/scottl-camlock/src/sys/dev/mfi/mfivar.h#8 (text) ====

@@ -379,6 +379,7 @@
 MALLOC_DECLARE(M_MFIBUF);
 
 #define MFI_CMD_TIMEOUT 30
+#define MFI_MAXPHYS (128 * 1024)
 
 #ifdef MFI_DEBUG
 extern void mfi_print_cmd(struct mfi_command *cm);

==== //depot/projects/scottl-camlock/src/sys/dev/mlx/mlx.c#7 (text+ko) ====

@@ -1979,7 +1979,7 @@
      * initial contents
      */
     if (mu->mu_datasize > 0) {
-	if (mu->mu_datasize > MAXPHYS) {
+	if (mu->mu_datasize > MLX_MAXPHYS) {
 	    error = EINVAL;
 	    goto out;
 	}

==== //depot/projects/scottl-camlock/src/sys/dev/mlx/mlxvar.h#3 (text+ko) ====

@@ -47,6 +47,7 @@
  * making that fit cleanly without crossing page boundaries requires rounding up
  * to the next power of two.
  */
+#define MLX_MAXPHYS	(128 * 124)
 #define MLX_NSEG	64
 
 #define MLX_NSLOTS	256		/* max number of command slots */

==== //depot/projects/scottl-camlock/src/sys/dev/mpt/mpt.h#22 (text+ko) ====

@@ -986,6 +986,9 @@
 /* Max MPT Reply we are willing to accept (must be power of 2) */
 #define MPT_REPLY_SIZE   	256
 
+/* Max i/o size, based on legacy MAXPHYS.  Can be increased. */
+#define MPT_MAXPHYS		(128 * 1024)
+
 /*
  * Must be less than 16384 in order for target mode to work
  */

==== //depot/projects/scottl-camlock/src/sys/dev/mpt/mpt_pci.c#23 (text+ko) ====

@@ -795,9 +795,9 @@
 	/*
 	 * XXX: we should say that nsegs is 'unrestricted, but that
 	 * XXX: tickles a horrible bug in the busdma code. Instead,
-	 * XXX: we'll derive a reasonable segment limit from MAXPHYS
+	 * XXX: we'll derive a reasonable segment limit from MPT_MAXPHYS
 	 */
-	nsegs = (MAXPHYS / PAGE_SIZE) + 1;
+	nsegs = (MPT_MAXPHYS / PAGE_SIZE) + 1;
 	if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1,
 	    0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
 	    NULL, NULL, MAXBSIZE, nsegs, BUS_SPACE_MAXSIZE_32BIT, 0,

==== //depot/projects/scottl-camlock/src/sys/dev/trm/trm.h#3 (text+ko) ====

@@ -94,7 +94,8 @@
 #define TRM_MAX_CMD_PER_LUN    	32
 #define TRM_MAX_SRB_CNT	       	256
 #define TRM_MAX_START_JOB       256
-#define TRM_NSEG	        (btoc(MAXPHYS) + 1)
+#define TRM_MAXPHYS		(128 * 1024)
+#define TRM_NSEG	        (btoc(TRM_MAXPHYS) + 1)
 #define TRM_MAXTRANSFER_SIZE    0xFFFFFF /* restricted by 24 bit counter */
 #define PAGELEN 	       	4096
 

==== //depot/projects/scottl-camlock/src/sys/kern/subr_bus.c#26 (text+ko) ====

@@ -68,7 +68,6 @@
 	TAILQ_ENTRY(driverlink) link;	/* list of drivers in devclass */
 	int		pass;
 	TAILQ_ENTRY(driverlink) passlink;
-	TAILQ_ENTRY(driverlink) probe_link;
 };
 
 /*
@@ -90,14 +89,8 @@
 
 	struct sysctl_ctx_list sysctl_ctx;
 	struct sysctl_oid *sysctl_tree;
-
-	int		class_ref;
-	int		class_busy;
 };
 
-#define DC_REF(dc)	(dc)->class_ref++
-#define DC_UNREF(dc)	(dc)->class_ref--
-
 /**
  * @brief Implementation of device.
  */
@@ -143,14 +136,8 @@
 
 	struct sysctl_ctx_list sysctl_ctx; /**< state for sysctl variables  */
 	struct sysctl_oid *sysctl_tree;	/**< state for sysctl variables */
-
-	int		device_ref;
-	int		device_busy;
 };
 
-#define DT_REF(dt)	(dt)->device_ref++
-#define DT_UNREF(dt)	(dt)->device_ref--
-
 static MALLOC_DEFINE(M_BUS, "bus", "Bus data structures");
 static MALLOC_DEFINE(M_BUS_SC, "bus-sc", "Bus data structures, softc");
 
@@ -377,7 +364,7 @@
 
 static struct cdevsw dev_cdevsw = {
 	.d_version =	D_VERSION,
-	.d_flags =	0,
+	.d_flags =	D_NEEDGIANT,
 	.d_open =	devopen,
 	.d_close =	devclose,
 	.d_read =	devread,
@@ -866,9 +853,6 @@
 
 static devclass_list_t devclasses = TAILQ_HEAD_INITIALIZER(devclasses);
 
-static struct mtx devclasses_mtx;
-MTX_SYSINIT(devclasses, &devclasses_mtx, "devclass global mtx", MTX_DEF);
-
 /**
  * @internal
  * @brief Find or create a device class
@@ -885,13 +869,11 @@
  * @param create	non-zero to create a devclass
  */
 static devclass_t
-devclass_find_internal_locked(const char *classname, const char *parentname,
-			      int create)
+devclass_find_internal(const char *classname, const char *parentname,
+		       int create)
 {
 	devclass_t dc;
 
-	mtx_assert(&devclasses_mtx, MA_OWNED);
-
 	PDEBUG(("looking for %s", classname));
 	if (!classname)
 		return (NULL);
@@ -926,26 +908,13 @@
 	 */
 	if (parentname && dc && !dc->parent &&
 	    strcmp(classname, parentname) != 0) {
-		dc->parent = devclass_find_internal_locked(parentname, NULL,
-							   TRUE);
+		dc->parent = devclass_find_internal(parentname, NULL, TRUE);
 		dc->parent->flags |= DC_HAS_CHILDREN;
 	}
 
 	return (dc);
 }
 
-static devclass_t
-devclass_find_internal(const char *classname, const char *parentname,
-		       int create)
-{
-	devclass_t dc;
-
-	mtx_lock(&devclasses_mtx);
-	dc = devclass_find_internal_locked(classname, parentname, create);
-	mtx_unlock(&devclasses_mtx);
-	return (dc);
-}
-
 /**
  * @brief Create a device class
  *
@@ -992,36 +961,16 @@
 static void
 devclass_driver_added(devclass_t dc, driver_t *driver)
 {
-	device_t *devlist;
 	devclass_t parent;
-	int i, maxunit = 0;
-
-	mtx_assert(&devclasses_mtx, MA_OWNED);
+	int i;
 
 	/*
 	 * Call BUS_DRIVER_ADDED for any existing busses in this class.
 	 */
-	devlist = malloc(sizeof(device_t)*dc->maxunit, M_BUS, M_NOWAIT|M_ZERO);
-	if (devlist == NULL)
-		/* XXX error? */
-		return;
-
-	for (i = 0; i < dc->maxunit; i++) {
-		if (dc->devices[i]) {
-			DT_REF(dc->devices[i]);
-			devlist[maxunit++] = dc->devices[i];
-		}
-	}
-
-	mtx_unlock(&devclasses_mtx);
-	for (i = 0; i < maxunit; i++)
-		BUS_DRIVER_ADDED(devlist[i], driver);
+	for (i = 0; i < dc->maxunit; i++)
+		if (dc->devices[i])
+			BUS_DRIVER_ADDED(dc->devices[i], driver);
 
-	mtx_lock(&devclasses_mtx);
-	for (i = 0; i < maxunit; i++)
-		DT_UNREF(devlist[i]);
-	free(devlist, M_BUS);
-
 	/*
 	 * Walk through the children classes.  Since we only keep a
 	 * single parent pointer around, we walk the entire list of
@@ -1034,11 +983,8 @@
 		return;
 	parent = dc;
 	TAILQ_FOREACH(dc, &devclasses, link) {
-		if (dc->parent == parent) {
-			DC_REF(dc);
+		if (dc->parent == parent)
 			devclass_driver_added(dc, driver);
-			DC_UNREF(dc);
-		}
 	}
 }
 
@@ -1074,24 +1020,21 @@
 	 * goes. This means we can safely use static methods and avoids a
 	 * double-free in devclass_delete_driver.
 	 */
-	mtx_lock(&devclasses_mtx);
 	kobj_class_compile((kobj_class_t) driver);
 
 	/*
 	 * Make sure the devclass which the driver is implementing exists.
 	 */
-	devclass_find_internal_locked(driver->name, NULL, TRUE);
+	devclass_find_internal(driver->name, NULL, TRUE);
 
 	dl->driver = driver;
 	TAILQ_INSERT_TAIL(&dc->drivers, dl, link);
 	driver->refs++;		/* XXX: kobj_mtx */
 	dl->pass = pass;
 	driver_register_pass(dl);
-	DC_REF(dc);
 
 	devclass_driver_added(dc, driver);
 	bus_data_generation_update();
-	mtx_unlock(&devclasses_mtx);
 	return (0);
 }
 
@@ -1114,8 +1057,8 @@
 {
 	devclass_t dc = devclass_find(driver->name);
 	driverlink_t dl;
-	device_t *devlist, dev;
-	int i, maxunit = 0;
+	device_t dev;
+	int i;
 	int error;
 
 	PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
@@ -1126,7 +1069,6 @@
 	/*
 	 * Find the link structure in the bus' list of drivers.
 	 */
-	mtx_lock(&devclasses_mtx);
 	TAILQ_FOREACH(dl, &busclass->drivers, link) {
 		if (dl->driver == driver)
 			break;
@@ -1135,7 +1077,6 @@
 	if (!dl) {
 		PDEBUG(("%s not found in %s list", driver->name,
 		    busclass->name));
-		mtx_unlock(&devclasses_mtx);
 		return (ENOENT);
 	}
 
@@ -1149,59 +1090,27 @@
 	 * should not detach devices which are not children of devices in
 	 * the affected devclass.
 	 */
-	devlist = malloc(sizeof(device_t)*dc->maxunit, M_BUS, M_NOWAIT|M_ZERO);
-	if (devlist == NULL) {
-		mtx_unlock(&devclasses_mtx);
-		return (ENOMEM);
-	}
-
 	for (i = 0; i < dc->maxunit; i++) {
 		if (dc->devices[i]) {
 			dev = dc->devices[i];
 			if (dev->driver == driver && dev->parent &&
 			    dev->parent->devclass == busclass) {
-				DT_REF(dev);
-				devlist[maxunit++] = dev;
+				if ((error = device_detach(dev)) != 0)
+					return (error);
+				device_set_driver(dev, NULL);
 			}
 		}
 	}
 
-	mtx_unlock(&devclasses_mtx);
-	error = 0;
-	for (i = 0; i < maxunit; i++) {
-		dev = devlist[i];
-		/*
-		 * If device_detach() generates an error, the rest of the
-		 * devices in the list still need to be deref'd.
-		 */
-		if ((error = device_detach(dev)) != 0)
-			break;
-		device_set_driver(dev, NULL);
-	}
-
-	mtx_lock(&devclasses_mtx);
-	for (i = 0; i < maxunit; i++) {
-		dev = devlist[i];
-		DT_UNREF(dev);
-	}
-
-	free(devlist, M_BUS);
-	if (error) {
-		mtx_unlock(&devclasses_mtx);
-		return (error);
-	}
-
 	TAILQ_REMOVE(&busclass->drivers, dl, link);
 	free(dl, M_BUS);
 
 	/* XXX: kobj_mtx */
-	DC_UNREF(dc);
 	driver->refs--;
 	if (driver->refs == 0)
-	kobj_class_free((kobj_class_t) driver);
+		kobj_class_free((kobj_class_t) driver);
 
 	bus_data_generation_update();
-	mtx_unlock(&devclasses_mtx);
 	return (0);
 }
 
@@ -1223,8 +1132,8 @@
 {
 	devclass_t dc = devclass_find(driver->name);
 	driverlink_t dl;
-	device_t *devlist, dev;
-	int i, maxunit = 0;
+	device_t dev;
+	int i;
 	int error;
 
 	PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
@@ -1235,7 +1144,6 @@
 	/*
 	 * Find the link structure in the bus' list of drivers.
 	 */
-	mtx_lock(&devclasses_mtx);
 	TAILQ_FOREACH(dl, &busclass->drivers, link) {
 		if (dl->driver == driver)
 			break;
@@ -1244,7 +1152,6 @@
 	if (!dl) {
 		PDEBUG(("%s not found in %s list", driver->name,
 		    busclass->name));
-		mtx_unlock(&devclasses_mtx);
 		return (ENOENT);
 	}
 
@@ -1258,38 +1165,18 @@
 	 * should not quiesce devices which are not children of
 	 * devices in the affected devclass.
 	 */
-	devlist = malloc(sizeof(device_t)*dc->maxunit, M_BUS, M_NOWAIT|M_ZERO);
-	if (devlist == NULL) {
-		mtx_unlock(&devclasses_mtx);
-		return (ENOMEM);
-	}
-
 	for (i = 0; i < dc->maxunit; i++) {
 		if (dc->devices[i]) {
 			dev = dc->devices[i];
 			if (dev->driver == driver && dev->parent &&
 			    dev->parent->devclass == busclass) {
-				DT_REF(dev);
-				devlist[maxunit++] = dev;
+				if ((error = device_quiesce(dev)) != 0)
+					return (error);
 			}
 		}
 	}
 
-	mtx_unlock(&devclasses_mtx);
-	error = 0;
-	for (i = 0; i < maxunit; i++) {
-		if ((error = device_quiesce(devlist[i])) != 0)
-			break;
-	}
-
-	mtx_lock(&devclasses_mtx);
-	for (i = 0; i < maxunit; i++) {
-		DT_UNREF(devlist[i]);
-	}
-	mtx_unlock(&devclasses_mtx);
-
-	free(devlist, M_BUS);
-	return (error);
+	return (0);
 }
 
 /**
@@ -1302,8 +1189,6 @@
 
 	PDEBUG(("%s in devclass %s", classname, DEVCLANAME(dc)));
 
-	mtx_assert(&devclasses_mtx, MA_OWNED);
-
 	TAILQ_FOREACH(dl, &dc->drivers, link) {
 		if (!strcmp(dl->driver->name, classname))
 			return (dl);
@@ -1334,17 +1219,9 @@
 device_t
 devclass_get_device(devclass_t dc, int unit)
 {
-	device_t dev;
-
 	if (dc == NULL || unit < 0 || unit >= dc->maxunit)
 		return (NULL);
-
-	mtx_lock(&devclasses_mtx);
-	dev = dc->devices[unit];
-	DT_REF(dev);
-	mtx_unlock(&devclasses_mtx);
-
-	return (dev);
+	return (dc->devices[unit]);
 }
 
 /**
@@ -1361,17 +1238,12 @@
 devclass_get_softc(devclass_t dc, int unit)
 {
 	device_t dev;
-	void *sc;
 
 	dev = devclass_get_device(dc, unit);
 	if (!dev)
 		return (NULL);
 
-	sc = device_get_softc(dev);
-	mtx_lock(&devclasses_mtx);
-	DT_UNREF(dev);
-	mtx_unlock(&devclasses_mtx);
-	return (sc);
+	return (device_get_softc(dev));
 }
 
 /**
@@ -1394,27 +1266,20 @@
 devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp)
 {
 	int count, i;
-	device_t dev;
 	device_t *list;
 
 	count = devclass_get_count(dc);
 	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
-	if (!list) {
-		mtx_unlock(&devclasses_mtx);
+	if (!list)
 		return (ENOMEM);
-	}
 
 	count = 0;
-	mtx_lock(&devclasses_mtx);
 	for (i = 0; i < dc->maxunit; i++) {
-		dev = dc->devices[i];
-		if (dev) {
-			DT_REF(dev);
-			list[count] = dev;
+		if (dc->devices[i]) {
+			list[count] = dc->devices[i];
 			count++;
 		}
 	}
-	mtx_unlock(&devclasses_mtx);
 
 	*devlistp = list;
 	*devcountp = count;
@@ -1446,21 +1311,17 @@
 	int count;
 
 	count = 0;
-	mtx_lock(&devclasses_mtx);
 	TAILQ_FOREACH(dl, &dc->drivers, link)
 		count++;
 	list = malloc(count * sizeof(driver_t *), M_TEMP, M_NOWAIT);
-	if (list == NULL) {
-		mtx_unlock(&devclasses_mtx);
+	if (list == NULL)
 		return (ENOMEM);
-	}
 
 	count = 0;
 	TAILQ_FOREACH(dl, &dc->drivers, link) {
 		list[count] = dl->driver;
 		count++;
 	}
-	mtx_unlock(&devclasses_mtx);
 	*listp = list;
 	*countp = count;
 
@@ -1478,11 +1339,9 @@
 	int count, i;
 
 	count = 0;
-	mtx_lock(&devclasses_mtx);
 	for (i = 0; i < dc->maxunit; i++)
 		if (dc->devices[i])
 			count++;
-	mtx_unlock(&devclasses_mtx);
 	return (count);
 }
 
@@ -1590,14 +1449,12 @@
 
 	/* If we were given a wired unit number, check for existing device */
 	/* XXX imp XXX */
-	mtx_lock(&devclasses_mtx);
 	if (unit != -1) {
 		if (unit >= 0 && unit < dc->maxunit &&
 		    dc->devices[unit] != NULL) {
 			if (bootverbose)
 				printf("%s: %s%d already exists; skipping it\n",
 				    dc->name, dc->name, *unitp);
-			mtx_unlock(&devclasses_mtx);
 			return (EEXIST);
 		}
 	} else {
@@ -1640,10 +1497,8 @@
 		if (oldlist != NULL)
 			free(oldlist, M_BUS);
 	}
-	dc->devices[unit] = dev;
-	mtx_unlock(&devclasses_mtx);
+	PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));
 
-	PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));
 	*unitp = unit;
 	return (0);
 }
@@ -1683,11 +1538,8 @@
 		dev->nameunit = NULL;
 		return (error);
 	}
-	mtx_lock(&devclasses_mtx);
-	DC_REF(dc);
-	DT_REF(dev);
+	dc->devices[dev->unit] = dev;
 	dev->devclass = dc;
-	mtx_unlock(&devclasses_mtx);
 	snprintf(dev->nameunit, buflen, "%s%d", dc->name, dev->unit);
 
 	return (0);
@@ -1713,18 +1565,14 @@
 
 	PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
 
-	mtx_lock(&devclasses_mtx);
 	if (dev->devclass != dc || dc->devices[dev->unit] != dev)
 		panic("devclass_delete_device: inconsistent device class");
-	DT_UNREF(dev);
-	DC_UNREF(dc);
 	dc->devices[dev->unit] = NULL;
 	if (dev->flags & DF_WILDCARD)
 		dev->unit = -1;
 	dev->devclass = NULL;
 	free(dev->nameunit, M_BUS);
 	dev->nameunit = NULL;
-	mtx_unlock(&devclasses_mtx);
 
 	return (0);
 }
@@ -1790,10 +1638,8 @@
 
 	dev->state = DS_NOTPRESENT;
 
-	mtx_lock(&devclasses_mtx);
 	TAILQ_INSERT_TAIL(&bus_data_devices, dev, devlink);
 	bus_data_generation_update();
-	mtx_unlock(&devclasses_mtx);
 
 	return (dev);
 }
@@ -2008,7 +1854,6 @@
 	devclass_t dc;
 	driverlink_t best = NULL;
 	driverlink_t dl;
-	driver_list_t dllist;
 	int result, pri = 0;
 	int hasclass = (child->devclass != NULL);
 
@@ -2025,8 +1870,6 @@
 	if (child->state == DS_ALIVE && (child->flags & DF_REBID) == 0)
 		return (0);
 
-	mtx_lock(&devclasses_mtx);
-	TAILQ_INIT(&dllist);
 	for (; dc; dc = dc->parent) {
 		for (dl = first_matching_driver(dc, child);
 		     dl;
@@ -2036,14 +1879,6 @@
 			if (dl->pass > bus_current_pass)
 				continue;
 
-			TAILQ_INSERT_TAIL(&dllist, dl, probe_link);
-		}
-	}
-	mtx_unlock(&devclasses_mtx);
-
-	while ((dl = TAILQ_FIRST(&dllist)) != NULL) {
-		TAILQ_REMOVE(&dllist, dl, probe_link);
-		{
 			PDEBUG(("Trying %s", DRIVERNAME(dl->driver)));
 			device_set_driver(child, dl->driver);
 			if (!hasclass) {
@@ -4455,11 +4290,9 @@
 	devclass_t dc;
 
 	printf("Short listing of devclasses, drivers & devices:\n");
-	mtx_lock(&devclasses_mtx);
 	TAILQ_FOREACH(dc, &devclasses, link) {
 		print_devclass_short(dc, 0);
 	}
-	mtx_unlock(&devclasses_mtx);
 }
 
 void
@@ -4468,11 +4301,9 @@
 	devclass_t dc;
 
 	printf("Full listing of devclasses, drivers & devices:\n");
-	mtx_lock(&devclasses_mtx);
 	TAILQ_FOREACH(dc, &devclasses, link) {
 		print_devclass(dc, 0);
 	}
-	mtx_unlock(&devclasses_mtx);
 }
 
 #endif


More information about the p4-projects mailing list