Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Oct 2015 16:46:21 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r289760 - head/sys/dev/ioat
Message-ID:  <201510221646.t9MGkL3D056752@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Thu Oct 22 16:46:21 2015
New Revision: 289760
URL: https://svnweb.freebsd.org/changeset/base/289760

Log:
  ioat: Fix some attach/detach issues
  
  Don't run the selftest until after we've enabled bus mastering, or the
  DMA engine can't copy anything for our test.
  
  Create the ioat_test device on attach, if so tuned.  Destroy the
  ioat_test device on teardown.
  
  Replace deprecated 'CALLOUT_MPSAFE' with correct '1' in callout_init().
  
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/sys/dev/ioat/ioat.c
  head/sys/dev/ioat/ioat_internal.h
  head/sys/dev/ioat/ioat_test.c

Modified: head/sys/dev/ioat/ioat.c
==============================================================================
--- head/sys/dev/ioat/ioat.c	Thu Oct 22 16:38:01 2015	(r289759)
+++ head/sys/dev/ioat/ioat.c	Thu Oct 22 16:46:21 2015	(r289760)
@@ -56,6 +56,7 @@ static int ioat_detach(device_t device);
 static int ioat_setup_intr(struct ioat_softc *ioat);
 static int ioat_teardown_intr(struct ioat_softc *ioat);
 static int ioat3_attach(device_t device);
+static int ioat3_selftest(struct ioat_softc *ioat);
 static int ioat_map_pci_bar(struct ioat_softc *ioat);
 static void ioat_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg,
     int error);
@@ -239,7 +240,15 @@ ioat_attach(device_t device)
 	if (error != 0)
 		goto err;
 
+	error = ioat3_selftest(ioat);
+	if (error != 0)
+		return (error);
+
+	ioat_process_events(ioat);
+	ioat_setup_sysctl(device);
+
 	ioat_channel[ioat_channel_index++] = ioat;
+	ioat_test_attach();
 
 err:
 	if (error != 0)
@@ -254,6 +263,8 @@ ioat_detach(device_t device)
 	uint32_t i;
 
 	ioat = DEVICE2SOFTC(device);
+
+	ioat_test_detach();
 	callout_drain(&ioat->timer);
 
 	pci_disable_busmaster(device);
@@ -347,7 +358,7 @@ ioat3_attach(device_t device)
 
 	mtx_init(&ioat->submit_lock, "ioat_submit", NULL, MTX_DEF);
 	mtx_init(&ioat->cleanup_lock, "ioat_process_events", NULL, MTX_DEF);
-	callout_init(&ioat->timer, CALLOUT_MPSAFE);
+	callout_init(&ioat->timer, 1);
 
 	ioat->is_resize_pending = FALSE;
 	ioat->is_completion_pending = FALSE;
@@ -415,13 +426,6 @@ ioat3_attach(device_t device)
 	ioat_write_chanctrl(ioat, IOAT_CHANCTRL_RUN);
 	ioat_write_chancmp(ioat, ioat->comp_update_bus_addr);
 	ioat_write_chainaddr(ioat, ring[0]->hw_desc_bus_addr);
-
-	error = ioat3_selftest(ioat);
-	if (error != 0)
-		return (error);
-
-	ioat_process_events(ioat);
-	ioat_setup_sysctl(device);
 	return (0);
 }
 

Modified: head/sys/dev/ioat/ioat_internal.h
==============================================================================
--- head/sys/dev/ioat/ioat_internal.h	Thu Oct 22 16:38:01 2015	(r289759)
+++ head/sys/dev/ioat/ioat_internal.h	Thu Oct 22 16:46:21 2015	(r289760)
@@ -366,6 +366,9 @@ struct ioat_softc {
 	struct mtx		cleanup_lock;
 };
 
+void ioat_test_attach(void);
+void ioat_test_detach(void);
+
 static inline uint64_t
 ioat_get_chansts(struct ioat_softc *ioat)
 {

Modified: head/sys/dev/ioat/ioat_test.c
==============================================================================
--- head/sys/dev/ioat/ioat_test.c	Thu Oct 22 16:38:01 2015	(r289759)
+++ head/sys/dev/ioat/ioat_test.c	Thu Oct 22 16:46:21 2015	(r289760)
@@ -367,6 +367,22 @@ static struct cdevsw ioat_cdevsw = {
 };
 
 static int
+enable_ioat_test(bool enable)
+{
+
+	mtx_assert(&Giant, MA_OWNED);
+
+	if (enable && g_ioat_cdev == NULL) {
+		g_ioat_cdev = make_dev(&ioat_cdevsw, 0, UID_ROOT, GID_WHEEL,
+		    0600, "ioat_test");
+	} else if (!enable && g_ioat_cdev != NULL) {
+		destroy_dev(g_ioat_cdev);
+		g_ioat_cdev = NULL;
+	}
+	return (0);
+}
+
+static int
 sysctl_enable_ioat_test(SYSCTL_HANDLER_ARGS)
 {
 	int error, enabled;
@@ -376,15 +392,32 @@ sysctl_enable_ioat_test(SYSCTL_HANDLER_A
 	if (error != 0 || req->newptr == NULL)
 		return (error);
 
-	if (enabled != 0 && g_ioat_cdev == NULL) {
-		g_ioat_cdev = make_dev(&ioat_cdevsw, 0, UID_ROOT, GID_WHEEL,
-		    0600, "ioat_test");
-	} else if (enabled == 0 && g_ioat_cdev != NULL) {
-		destroy_dev(g_ioat_cdev);
-		g_ioat_cdev = NULL;
-	}
+	enable_ioat_test(enabled);
 	return (0);
 }
 SYSCTL_PROC(_hw_ioat, OID_AUTO, enable_ioat_test, CTLTYPE_INT | CTLFLAG_RW,
     0, 0, sysctl_enable_ioat_test, "I",
     "Non-zero: Enable the /dev/ioat_test device");
+
+void
+ioat_test_attach(void)
+{
+	char *val;
+
+	val = kern_getenv("hw.ioat.enable_ioat_test");
+	if (val != NULL && strcmp(val, "0") != 0) {
+		mtx_lock(&Giant);
+		enable_ioat_test(true);
+		mtx_unlock(&Giant);
+	}
+	freeenv(val);
+}
+
+void
+ioat_test_detach(void)
+{
+
+	mtx_lock(&Giant);
+	enable_ioat_test(false);
+	mtx_unlock(&Giant);
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510221646.t9MGkL3D056752>