From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-we0-f173.google.com (mail-we0-f173.google.com [74.125.82.173]) by dpdk.org (Postfix) with ESMTP id 264ACAFD7 for ; Fri, 9 May 2014 15:16:06 +0200 (CEST) Received: by mail-we0-f173.google.com with SMTP id u57so3911123wes.4 for ; Fri, 09 May 2014 06:16:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PvnWQP5+iuZtPEG4OuwwsZ0RKqvNOoU9V9qYdCQD0bM=; b=GvXQyC9VaY02N1Cee3L0dQeNqKYMxTBD7jI3i0i+FX6c94dqthiycbPdng+MqLIwNH L4NO6t3hUa9xGql80RlCp6pYxPZVI/t+8aXeeeH2KG83jpfLDCemotWApE2+2RSjupjo hYel+KtTxmbNKq5Nq1WiuUCKjHVsfk0YXjUcbdnPMEmnLoyHkN0J+k1P05DllX35HwPc 3SthbFy941hx2k50PZqzVx605sRcwXrAWTFF557ZwEO8HqkVNXWrSWEl2q7Z2qB39rh6 EOfHCgUxmBjTKeM9Vo2Omr1LHTo3aBalKIhvUjCyfkw1KB0S5KCZSvn1kHHfdXlAy/WE g9sg== X-Gm-Message-State: ALoCoQnZ6klZloFR7OjWgafdyIh02xljJnydgVkb073Af46wel2lUGjpOc7xSVhjmCPrfW829nAT X-Received: by 10.180.100.234 with SMTP id fb10mr3393441wib.26.1399641372248; Fri, 09 May 2014 06:16:12 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id go1sm5086560wib.7.2014.05.09.06.16.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 May 2014 06:16:11 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Fri, 9 May 2014 15:15:55 +0200 Message-Id: <1399641359-11267-4-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399641359-11267-1-git-send-email-david.marchand@6wind.com> References: <1399641359-11267-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 3/7] pci: remove virtio-uio workaround X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 May 2014 13:16:06 -0000 virtio-uio does not need eal to map bars from uio device, so remove flag RTE_PCI_DRV_NEED_IGB_UIO. Then, move virtio-uio workaround out of generic eal_pci.c for linux implementation. Signed-off-by: David Marchand --- lib/librte_eal/bsdapp/eal/eal_pci.c | 9 +-- lib/librte_eal/linuxapp/eal/eal_pci.c | 30 +------- lib/librte_pmd_virtio/virtio_ethdev.c | 133 ++++++++++++++++++++++++++++++++- 3 files changed, 134 insertions(+), 38 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 5d8bcbd..a8945e4 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -221,8 +221,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) dev->intr_handle.fd = -1; /* secondary processes - use already recorded details */ - if ((rte_eal_process_type() != RTE_PROC_PRIMARY) && - (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET)) + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return (pci_uio_map_secondary(dev)); rte_snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u", @@ -234,12 +233,6 @@ pci_uio_map_resource(struct rte_pci_device *dev) return -1; } - if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) { - /* I/O port address already assigned */ - /* rte_virtio_pmd does not need any other bar even if available */ - return (0); - } - /* allocate the mapping details for secondary processes*/ if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) { RTE_LOG(ERR, EAL, diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 99e07d2..c006cf5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -584,11 +584,9 @@ pci_uio_map_resource(struct rte_pci_device *dev) { int i, j; char dirname[PATH_MAX]; - char filename[PATH_MAX]; char devname[PATH_MAX]; /* contains the /dev/uioX */ void *mapaddr; int uio_num; - unsigned long start,size; uint64_t phaddr; uint64_t offset; uint64_t pagesz; @@ -600,8 +598,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) dev->intr_handle.fd = -1; /* secondary processes - use already recorded details */ - if ((rte_eal_process_type() != RTE_PROC_PRIMARY) && - (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET)) + if (rte_eal_process_type() != RTE_PROC_PRIMARY) return (pci_uio_map_secondary(dev)); /* find uio resource */ @@ -612,31 +609,6 @@ pci_uio_map_resource(struct rte_pci_device *dev) return -1; } - if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) { - /* get portio size */ - rte_snprintf(filename, sizeof(filename), - "%s/portio/port0/size", dirname); - if (eal_parse_sysfs_value(filename, &size) < 0) { - RTE_LOG(ERR, EAL, "%s(): cannot parse size\n", - __func__); - return -1; - } - - /* get portio start */ - rte_snprintf(filename, sizeof(filename), - "%s/portio/port0/start", dirname); - if (eal_parse_sysfs_value(filename, &start) < 0) { - RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n", - __func__); - return -1; - } - dev->mem_resource[0].addr = (void *)(uintptr_t)start; - dev->mem_resource[0].len = (uint64_t)size; - RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%lx with size=0x%lx\n", start, size); - /* rte_virtio_pmd does not need any other bar even if available */ - return (0); - } - /* allocate the mapping details for secondary processes*/ if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) { RTE_LOG(ERR, EAL, diff --git a/lib/librte_pmd_virtio/virtio_ethdev.c b/lib/librte_pmd_virtio/virtio_ethdev.c index f107161..c6a1df5 100644 --- a/lib/librte_pmd_virtio/virtio_ethdev.c +++ b/lib/librte_pmd_virtio/virtio_ethdev.c @@ -36,6 +36,9 @@ #include #include #include +#ifdef RTE_EXEC_ENV_LINUXAPP +#include +#endif #include #include @@ -392,6 +395,103 @@ virtio_negotiate_features(struct virtio_hw *hw) hw->guest_features = vtpci_negotiate_features(hw, guest_features); } +#ifdef RTE_EXEC_ENV_LINUXAPP +static int +parse_sysfs_value(const char *filename, unsigned long *val) +{ + FILE *f; + char buf[BUFSIZ]; + char *end = NULL; + + if ((f = fopen(filename, "r")) == NULL) { + PMD_INIT_LOG(ERR, "%s(): cannot open sysfs value %s\n", + __func__, filename); + return -1; + } + + if (fgets(buf, sizeof(buf), f) == NULL) { + PMD_INIT_LOG(ERR, "%s(): cannot read sysfs value %s\n", + __func__, filename); + fclose(f); + return -1; + } + *val = strtoul(buf, &end, 0); + if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) { + PMD_INIT_LOG(ERR, "%s(): cannot parse sysfs value %s\n", + __func__, filename); + fclose(f); + return -1; + } + fclose(f); + return 0; +} + +static int get_uio_dev(struct rte_pci_addr *loc, char *buf, unsigned int buflen) +{ + unsigned int uio_num; + struct dirent *e; + DIR *dir; + char dirname[PATH_MAX]; + + /* depending on kernel version, uio can be located in uio/uioX + * or uio:uioX */ + rte_snprintf(dirname, sizeof(dirname), + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio", + loc->domain, loc->bus, loc->devid, loc->function); + dir = opendir(dirname); + if (dir == NULL) { + /* retry with the parent directory */ + rte_snprintf(dirname, sizeof(dirname), + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT, + loc->domain, loc->bus, loc->devid, loc->function); + dir = opendir(dirname); + + if (dir == NULL) { + PMD_INIT_LOG(ERR, "Cannot opendir %s\n", dirname); + return -1; + } + } + + /* take the first file starting with "uio" */ + while ((e = readdir(dir)) != NULL) { + /* format could be uio%d ...*/ + int shortprefix_len = sizeof("uio") - 1; + /* ... or uio:uio%d */ + int longprefix_len = sizeof("uio:uio") - 1; + char *endptr; + + if (strncmp(e->d_name, "uio", 3) != 0) + continue; + + /* first try uio%d */ + errno = 0; + uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10); + if (errno == 0 && endptr != (e->d_name + shortprefix_len)) { + rte_snprintf(buf, buflen, "%s/uio%u", dirname, uio_num); + break; + } + + /* then try uio:uio%d */ + errno = 0; + uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10); + if (errno == 0 && endptr != (e->d_name + longprefix_len)) { + rte_snprintf(buf, buflen, "%s/uio:uio%u", dirname, + uio_num); + break; + } + } + closedir(dir); + + /* No uio resource found */ + if (e == NULL) { + PMD_INIT_LOG(ERR, "Could not find uio resource\n"); + return -1; + } + + return 0; +} +#endif + /* * This function is based on probe() function in virtio_pci.c * It returns 0 on success. @@ -426,6 +526,38 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv, hw->device_id = pci_dev->id.device_id; hw->vendor_id = pci_dev->id.vendor_id; +#ifdef RTE_EXEC_ENV_LINUXAPP + { + char dirname[PATH_MAX]; + char filename[PATH_MAX]; + unsigned long start,size; + + if (get_uio_dev(&pci_dev->addr, dirname, sizeof(dirname)) < 0) + return -1; + + /* get portio size */ + rte_snprintf(filename, sizeof(filename), + "%s/portio/port0/size", dirname); + if (parse_sysfs_value(filename, &size) < 0) { + PMD_INIT_LOG(ERR, "%s(): cannot parse size\n", + __func__); + return -1; + } + + /* get portio start */ + rte_snprintf(filename, sizeof(filename), + "%s/portio/port0/start", dirname); + if (parse_sysfs_value(filename, &start) < 0) { + PMD_INIT_LOG(ERR, "%s(): cannot parse portio start\n", + __func__); + return -1; + } + pci_dev->mem_resource[0].addr = (void *)(uintptr_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\n", start, size); + } +#endif hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr; hw->max_rx_queues = VIRTIO_MAX_RX_QUEUES; @@ -474,7 +606,6 @@ static struct eth_driver rte_virtio_pmd = { { .name = "rte_virtio_pmd", .id_table = pci_id_virtio_map, - .drv_flags = RTE_PCI_DRV_NEED_IGB_UIO, }, .eth_dev_init = eth_virtio_dev_init, .dev_private_size = sizeof(struct virtio_adapter), -- 1.7.10.4