From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <root@localhost.my.domain>
Received: from localhost.my.domain (84.95.210.61.forward.012.net.il
 [84.95.210.61]) by dpdk.org (Postfix) with ESMTP id E6B265A68
 for <dev@dpdk.org>; Wed,  4 Mar 2015 10:49:38 +0100 (CET)
Received: from localhost.my.domain (localhost [127.0.0.1])
 by localhost.my.domain (8.14.9/8.14.9) with ESMTP id t24BlYUc002448
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO);
 Wed, 4 Mar 2015 11:47:34 GMT (envelope-from root@localhost.my.domain)
Received: (from root@localhost)
 by localhost.my.domain (8.14.9/8.14.9/Submit) id t24BlXcY002447;
 Wed, 4 Mar 2015 11:47:33 GMT (envelope-from root)
From: Raz Amir <razamir22@gmail.com>
To: dev@dpdk.org
Date: Wed,  4 Mar 2015 11:47:04 +0000
Message-Id: <1425469624-2409-1-git-send-email-razamir22@gmail.com>
X-Mailer: git-send-email 2.1.2
In-Reply-To: <1424932400-66862-1-git-send-email-razamir22@gmail.com>
References: <1424932400-66862-1-git-send-email-razamir22@gmail.com>
Subject: [dpdk-dev] [PATCH v2] pci: save list of detached devices,
	and re-probe during driver unload
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 04 Mar 2015 09:49:39 -0000

Added code that saves the pointers to the detached devices, during
driver loading, and during driver unloading, go over the list,
and re-attach them by calling device_probe_and_attach
on each device.

Signed-off-by: Raz Amir <razamir22@gmail.com>
---
 lib/librte_eal/bsdapp/nic_uio/nic_uio.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
index 5ae8560..077bdb3 100644
--- a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
+++ b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
@@ -55,6 +55,9 @@ __FBSDID("$FreeBSD$");
 
 #define MAX_BARS (PCIR_MAX_BAR_0 + 1)
 
+#define MAX_DETACHED_DEVICES	128
+static device_t detached_devices[MAX_DETACHED_DEVICES] = {};
+static int num_detached = 0;
 
 struct nic_uio_softc {
 	device_t        dev_t;
@@ -289,16 +292,37 @@ nic_uio_load(void)
 
 		dev = pci_find_bsf(bus, device, function);
 		if (dev != NULL)
-			for (i = 0; i < NUM_DEVICES; i++)
-				if (pci_get_vendor(dev) == devices[i].vend &&
-						pci_get_device(dev) == devices[i].dev)
-							device_detach(dev);
+			continue;
+		
+		for (i = 0; i < NUM_DEVICES; i++)
+			if (pci_get_vendor(dev) == devices[i].vend &&
+					pci_get_device(dev) == devices[i].dev) {
+						if (num_detached < MAX_DETACHED_DEVICES-1) {
+							printf("nic_uio_load: detaching and storing dev=%p\n", dev);
+							detached_devices[num_detached++] = dev;
+						}
+						else
+							printf("nic_uio_load: reached MAX_DETACHED_DEVICES=%d. dev=%p won't be reattached\n",
+								MAX_DETACHED_DEVICES, dev);
+						device_detach(dev);
+			}
 	}
 }
 
 static void
 nic_uio_unload(void)
 {
+	int i;
+	printf("nic_uio_unload: entered ... \n");
+
+	for (i = 0; i < num_detached; i++) {
+		printf("nic_uio_unload: calling to device_probe_and_attach for dev=%p...\n",
+			detached_devices[i]);
+		device_probe_and_attach(detached_devices[i]);
+		printf("nic_uio_unload: done.\n");
+	}
+
+	printf("nic_uio_unload: leaving ... \n");
 }
 
 static int
-- 
2.1.2