From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by dpdk.org (Postfix) with ESMTP id 9ABAD903 for ; Wed, 11 Feb 2015 02:23:47 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id ey11so654892pad.11 for ; Tue, 10 Feb 2015 17:23:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=gUT05nTVadqi5mphBmQ0hlgbFPmJrNvwTWwirM6k13A=; b=IppNTBQQ7VBP8gu3+Ir14IwSxxQ3ivMRdDHPG9/Yo8zsvjID85qc85Kl3xKI6elHcb yNfWq0uOUHqq3nZ8k2xLjc5iqSdpIJyvm4Y7bFOknNKXh+31/PQs1MpH2PGs5nNTVerg qSRhp4odaBjkq1arNuOVTG13F267OSb7+XgcLECkqBtpj+MPmobC1jMXaFJtD/Yyi1jl hDazWpmAtnrOS5Ne2p49u133LgBBhBCk3KNMg9EmD19Kk9cPqmq+GRX6lcQrJwow3Qt8 mLF77CyEeSXnadIaK/wnlg2zXHV6ELJQk31d1mI0Itt6emSSAw92n8jv7xa0DZDnsLK+ 9a7w== X-Gm-Message-State: ALoCoQmh0s+V/mpHTbIJyJBp/Pkx7Xp5brNjAR6mWMKHjfz5fLHzkcO+kJOeopVR0YhLq5UB1bUG X-Received: by 10.70.22.66 with SMTP id b2mr42553251pdf.9.1423617826493; Tue, 10 Feb 2015 17:23:46 -0800 (PST) Received: from uryu.home.lan ([144.49.132.22]) by mx.google.com with ESMTPSA id q4sm20559578pdm.88.2015.02.10.17.23.45 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Feb 2015 17:23:46 -0800 (PST) Date: Tue, 10 Feb 2015 17:23:43 -0800 From: Stephen Hemminger To: David Marchand Message-ID: <20150210172343.3fb6d3fe@uryu.home.lan> In-Reply-To: References: <1423247795-22399-1-git-send-email-stephen@networkplumber.org> <1423247795-22399-2-git-send-email-stephen@networkplumber.org> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "dev@dpdk.org" , Stephen Hemminger Subject: Re: [dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space 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: Wed, 11 Feb 2015 01:23:48 -0000 Here is a revised version that works for both UIO and VFIO. The config access is property of device not the I/O model. From: Stephen Hemminger Subject: [PATCH 1/4] pci: allow access to PCI config space Some drivers need ability to access PCI config (for example for power management). This adds an abstraction to do this; only implemented on Linux, but should be possible on BSD. Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/include/rte_pci.h | 29 +++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 +++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 10 ++++++++++ 3 files changed, 54 insertions(+) Index: dpdk/lib/librte_eal/common/include/rte_pci.h =================================================================== --- dpdk.orig/lib/librte_eal/common/include/rte_pci.h 2015-02-10 15:58:53.915744256 -0800 +++ dpdk/lib/librte_eal/common/include/rte_pci.h 2015-02-10 15:58:53.911744221 -0800 @@ -152,6 +152,7 @@ uint16_t max_vfs; /**< sriov enable if not zero */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Device user arguments */ + int config_fd; /**< PCI config access */ }; /** Any PCI device identifier (vendor, device, ...) */ @@ -304,6 +305,34 @@ */ void rte_eal_pci_unregister(struct rte_pci_driver *driver); +/** + * Read PCI config space. + * + * @param device + * A pointer to a rte_pci_device structure describing the device + * to use + * @param buf + * A data buffer where the bytes should be read into + * @param size + * The length of the data buffer. + */ +int rte_eal_pci_read_config(const struct rte_pci_device *device, + void *buf, size_t len, off_t offset); + +/** + * Write PCI config space. + * + * @param device + * A pointer to a rte_pci_device structure describing the device + * to use + * @param buf + * A data buffer containing the bytes should be written + * @param size + * The length of the data buffer. + */ +int rte_eal_pci_write_config(const struct rte_pci_device *device, + const void *buf, size_t len, off_t offset); + #ifdef __cplusplus } #endif Index: dpdk/lib/librte_eal/linuxapp/eal/eal_pci.c =================================================================== --- dpdk.orig/lib/librte_eal/linuxapp/eal/eal_pci.c 2015-02-10 15:58:53.915744256 -0800 +++ dpdk/lib/librte_eal/linuxapp/eal/eal_pci.c 2015-02-10 15:59:46.564201569 -0800 @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -233,6 +234,7 @@ dev->addr.bus = bus; dev->addr.devid = devid; dev->addr.function = function; + dev->config_fd = -1; /* get vendor id */ snprintf(filename, sizeof(filename), "%s/vendor", dirname); @@ -498,6 +500,26 @@ #endif static int +pci_config_open(struct rte_pci_device *dev) +{ + struct rte_pci_addr *loc = &dev->addr; + char filename[PATH_MAX]; + + /* Open fd for access to PCI config */ + snprintf(filename, sizeof(filename), + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/config", + loc->domain, loc->bus, loc->devid, loc->function); + dev->config_fd = open(filename, O_RDWR); + if (dev->config_fd < 0) { + RTE_LOG(ERR, EAL, "%s(): cannot open %s: %s\n", + __func__, filename, strerror(errno)); + return -1; + } + + return 0; +} + +static int pci_map_device(struct rte_pci_device *dev) { int ret, mapped = 0; @@ -518,7 +540,8 @@ if (ret != 0) return ret; } - return 0; + + return pci_config_open(dev); } /* @@ -595,6 +618,20 @@ return 1; } +/* Read PCI config space. */ +int rte_eal_pci_read_config(const struct rte_pci_device *device, + void *buf, size_t len, off_t offset) +{ + return pread(device->config_fd, buf, len, offset); +} + +/* Write PCI config space. */ +int rte_eal_pci_write_config(const struct rte_pci_device *device, + const void *buf, size_t len, off_t offset) +{ + return pwrite(device->config_fd, buf, len, offset); +} + /* Init the PCI EAL subsystem */ int rte_eal_pci_init(void)