DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ouyang Changchun <changchun.ouyang@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [RFC PATCH 17/17] virtio: Use port IO to get PCI resource.
Date: Mon,  8 Dec 2014 14:21:56 +0800	[thread overview]
Message-ID: <1418019716-4962-18-git-send-email-changchun.ouyang@intel.com> (raw)
In-Reply-To: <1418019716-4962-1-git-send-email-changchun.ouyang@intel.com>

Make virtio not require UIO for some security reasons, this is to match 6Wind's virtio-net-pmd.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 lib/librte_eal/common/include/rte_pci.h |  2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  3 +-
 lib/librte_pmd_virtio/virtio_ethdev.c   | 75 ++++++++++++++++++++++++++++++++-
 3 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 66ed793..2021b3b 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -193,6 +193,8 @@ struct rte_pci_driver {
 
 /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */
 #define RTE_PCI_DRV_NEED_MAPPING 0x0001
+/** Device needs port IO(done with /proc/ioports) */
+#define RTE_PCI_DRV_IO_PORT 0x0002
 /** Device driver must be registered several times until failure - deprecated */
 #pragma GCC poison RTE_PCI_DRV_MULTIPLE
 /** Device needs to be unbound even if no module is provided */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index b5f5410..dd60793 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -573,7 +573,8 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
 #endif
 			/* map resources for devices that use igb_uio */
 			ret = pci_map_device(dev);
-			if (ret != 0)
+			if ((ret != 0) &&
+				((dr->drv_flags & RTE_PCI_DRV_IO_PORT) == 0))
 				return ret;
 		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
 		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
diff --git a/lib/librte_pmd_virtio/virtio_ethdev.c b/lib/librte_pmd_virtio/virtio_ethdev.c
index 1ec29e1..4490a06 100644
--- a/lib/librte_pmd_virtio/virtio_ethdev.c
+++ b/lib/librte_pmd_virtio/virtio_ethdev.c
@@ -961,6 +961,69 @@ static int virtio_resource_init(struct rte_pci_device *pci_dev)
 		     start, size);
 	return 0;
 }
+
+/* Extract I/O port numbers from proc/ioports */
+static int virtio_resource_init_by_ioport(struct rte_pci_device *pci_dev)
+{
+	uint16_t start, end;
+	int size;
+	FILE* fp;
+	char* line = NULL;
+	char pci_id[16];
+	int found = 0;
+	size_t linesz;
+
+	snprintf(pci_id, sizeof(pci_id), PCI_PRI_FMT,
+		 pci_dev->addr.domain,
+		 pci_dev->addr.bus,
+		 pci_dev->addr.devid,
+		 pci_dev->addr.function);
+
+	fp = fopen("/proc/ioports", "r");
+	if (fp == NULL) {
+		PMD_INIT_LOG(ERR, "%s(): can't open ioports", __func__);
+		return -1;
+	}
+
+	while (getdelim(&line, &linesz, '\n', fp) > 0) {
+		char* ptr = line;
+		char* left;
+		int n;
+
+		n = strcspn(ptr, ":");
+		ptr[n]= 0;
+		left = &ptr[n+1];
+
+		while (*left && isspace(*left))
+			left++;
+
+		if (!strncmp(left, pci_id, strlen(pci_id))) {
+			found = 1;
+
+			while (*ptr && isspace(*ptr))
+				ptr++;
+
+			sscanf(ptr, "%04hx-%04hx", &start, &end);
+			size = end - start + 1;
+
+			break;
+		}
+	}
+
+	free(line);
+	fclose(fp);
+
+	if (!found)
+		return -1;
+
+	pci_dev->mem_resource[0].addr = (void *)(uintptr_t)(uint32_t)start;
+	pci_dev->mem_resource[0].len =  (uint64_t)size;
+	PMD_INIT_LOG(DEBUG,
+		     "PCI Port IO found start=0x%lx with size=0x%lx",
+		     start, size);
+	return 0;
+}
+
 #else
 static int
 virtio_has_msix(const struct rte_pci_addr *loc __rte_unused)
@@ -974,6 +1037,12 @@ static int virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused)
 	/* no setup required */
 	return 0;
 }
+
+static int virtio_resource_init_by_ioport(struct rte_pci_device *pci_dev)
+{
+	/* no setup required */
+	return 0;
+}
 #endif
 
 /*
@@ -1039,7 +1108,8 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv,
 
 	pci_dev = eth_dev->pci_dev;
 	if (virtio_resource_init(pci_dev) < 0)
-		return -1;
+		if (virtio_resource_init_by_ioport(pci_dev) < 0)
+			return -1;
 
 	hw->use_msix = virtio_has_msix(&pci_dev->addr);
 	hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr;
@@ -1136,7 +1206,8 @@ static struct eth_driver rte_virtio_pmd = {
 	{
 		.name = "rte_virtio_pmd",
 		.id_table = pci_id_virtio_map,
-		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_IO_PORT |\
+			 RTE_PCI_DRV_INTR_LSC,
 	},
 	.eth_dev_init = eth_virtio_dev_init,
 	.dev_private_size = sizeof(struct virtio_hw),
-- 
1.8.4.2

  parent reply	other threads:[~2014-12-08  6:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-08  6:21 [dpdk-dev] [RFC PATCH 00/17] Single virtio implementation Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 01/17] virtio: Rearrange resource initialization Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 02/17] virtio: Use weaker barriers Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 03/17] virtio: Allow starting with link down Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 04/17] virtio: Add support for Link State interrupt Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 05/17] ether: Add soft vlan encap/decap functions Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 06/17] virtio: Use software vlan stripping Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 07/17] virtio: Remove unnecessary adapter structure Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 08/17] virtio: Remove redundant vq_alignment Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 09/17] virtio: Fix how states are handled during initialization Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 10/17] virtio: Make vtpci_get_status local Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 11/17] virtio: Check for packet headroom at compile time Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 12/17] virtio: Move allocation before initialization Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 13/17] virtio: Add support for vlan filtering Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 14/17] virtio: Add suport for multiple mac addresses Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 15/17] virtio: Add ability to set MAC address Ouyang Changchun
2014-12-08  6:21 ` [dpdk-dev] [RFC PATCH 16/17] virtio: Free mbuf's with threshold Ouyang Changchun
2014-12-08  6:21 ` Ouyang Changchun [this message]
2014-12-08  9:30 ` [dpdk-dev] [RFC PATCH 00/17] Single virtio implementation Thomas Monjalon
2014-12-09  1:08   ` Ouyang, Changchun
2014-12-09  3:23     ` Qiu, Michael
2014-12-09  5:24       ` Stephen Hemminger
2014-12-09  5:41       ` Ouyang, Changchun
2014-12-09  6:11         ` Thomas Monjalon
2014-12-09  6:40           ` Ouyang, Changchun
2014-12-09  8:53             ` Thomas Monjalon
2014-12-09  9:46             ` Bruce Richardson
2014-12-09 14:08               ` Ouyang, Changchun
2014-12-09 16:03                 ` Qiu, Michael
2014-12-10  0:29                   ` Ouyang, Changchun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418019716-4962-18-git-send-email-changchun.ouyang@intel.com \
    --to=changchun.ouyang@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).