From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f175.google.com (mail-pd0-f175.google.com [209.85.192.175]) by dpdk.org (Postfix) with ESMTP id BFA37ADCC for ; Tue, 24 Feb 2015 05:50:08 +0100 (CET) Received: by pdev10 with SMTP id v10so30628728pde.7 for ; Mon, 23 Feb 2015 20:50:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XCmF/TIUL7kRrXrHEJtBkWiBOS6wVfU8KeUyKFlfQYg=; b=TtsYH6/vqZ2y+S6uaZFqvVt4bOgOTIz8vFV/BdlyasRDV3ddoa2brVZRu3u4vjo+7R 3QBDlfsesSI0pOMsfs1uWe0AG4img+SV9LcqGT7fu9Muzl6yhQe9ni7m42KLSjTONege Cgtn6FYcJ9MN5dCr2Q4kK9m8DILlVb3xZfmjvOv+sWOYY6HrMVd8BPBK77OBqEOQaMcs bMnhj8hO0OCbHj71fz/v0tsq35lxNe9/mmgztH5oqM43+WVgc51qzyAJUcOzdycKC3Vu jSCFbpdKgC1SdS7QF7rc5hwMzyNlgT0zQofVI8vGMF+W4ts/OyvUFo4kq7nvygINp8C2 TAiw== X-Gm-Message-State: ALoCoQnykpR+6AT3voGEVaNT8G2fVmqowOaMZ32ai8FhRPpMGp++ofAAWHCVamK/vlQW2E7bnDUp X-Received: by 10.66.144.36 with SMTP id sj4mr3463160pab.32.1424753408214; Mon, 23 Feb 2015 20:50:08 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id r5sm26736146pdd.60.2015.02.23.20.50.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Feb 2015 20:50:07 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 24 Feb 2015 13:49:36 +0900 Message-Id: <1424753389-29864-3-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424753389-29864-1-git-send-email-mukawa@igel.co.jp> References: <1424060073-23484-2-git-send-email-mukawa@igel.co.jp> <1424753389-29864-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v13 02/13] eal_pci: Add flag to hold kernel driver type 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: Tue, 24 Feb 2015 04:50:09 -0000 From: Michael Qiu Currently, dpdk has no ability to know which type of driver( vfio-pci/igb_uio/uio_pci_generic) the device used. It only can check whether vfio is enabled or not staticly. It really useful to have the flag, becasue different type need to handle differently in runtime. For example, pci memory map, pot hotplug, and so on. This patch add a flag field for pci device to solve above issue. Signed-off-by: Michael Qiu Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/include/rte_pci.h | 8 +++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 4301c16..5e0ba00 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -142,6 +142,13 @@ struct rte_pci_addr { struct rte_devargs; +enum rte_pt_driver { + RTE_PT_UNKNOWN = 0, + RTE_PT_IGB_UIO = 1, + RTE_PT_VFIO = 2, + RTE_PT_UIO_GENERIC = 3, +}; + /** * A structure describing a PCI device. */ @@ -155,6 +162,7 @@ struct rte_pci_device { uint16_t max_vfs; /**< sriov enable if not zero */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Device user arguments */ + enum rte_pt_driver pt_driver; /**< Driver of passthrough */ }; /** Any PCI device identifier (vendor, device, ...) */ diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index a4fd5f5..4615756 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -97,6 +97,35 @@ error: return -1; } +static int +pci_get_kernel_driver_by_path(const char *filename, char *dri_name) +{ + int count; + char path[PATH_MAX]; + char *name; + + if (!filename || !dri_name) + return -1; + + count = readlink(filename, path, PATH_MAX); + if (count >= PATH_MAX) + return -1; + + /* For device does not have a driver */ + if (count < 0) + return 1; + + path[count] = '\0'; + + name = strrchr(path, '/'); + if (name) { + strncpy(dri_name, name + 1, strlen(name + 1) + 1); + return 0; + } + + return -1; +} + void * pci_find_max_end_va(void) { @@ -221,11 +250,12 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, char filename[PATH_MAX]; unsigned long tmp; struct rte_pci_device *dev; + char driver[PATH_MAX]; + int ret; dev = malloc(sizeof(*dev)); - if (dev == NULL) { + if (dev == NULL) return -1; - } memset(dev, 0, sizeof(*dev)); dev->addr.domain = domain; @@ -304,6 +334,25 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, return -1; } + /* parse driver */ + snprintf(filename, sizeof(filename), "%s/driver", dirname); + ret = pci_get_kernel_driver_by_path(filename, driver); + if (!ret) { + if (!strcmp(driver, "vfio-pci")) + dev->pt_driver = RTE_PT_VFIO; + else if (!strcmp(driver, "igb_uio")) + dev->pt_driver = RTE_PT_IGB_UIO; + else if (!strcmp(driver, "uio_pci_generic")) + dev->pt_driver = RTE_PT_UIO_GENERIC; + else + dev->pt_driver = RTE_PT_UNKNOWN; + } else if (ret < 0) { + RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); + free(dev); + return -1; + } else + dev->pt_driver = RTE_PT_UNKNOWN; + /* device is valid, add in list (sorted) */ if (TAILQ_EMPTY(&pci_device_list)) { TAILQ_INSERT_TAIL(&pci_device_list, dev, next); -- 1.9.1