From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi0-f46.google.com (mail-oi0-f46.google.com [209.85.218.46]) by dpdk.org (Postfix) with ESMTP id A4B352C7A for ; Mon, 9 Feb 2015 10:45:02 +0100 (CET) Received: by mail-oi0-f46.google.com with SMTP id a141so21663425oig.5 for ; Mon, 09 Feb 2015 01:45:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=eKIGDDOBDq4EWisInA6m9xMKHhjiu4vIpevAOjQkWd8=; b=NFwvsMyns0BkkDxLsMVBdWESMMv6PQAMnvyrfnGhRaO6oiyj5w+vd39I6xXlVujAyi BvX46eqO4hQ01ZG2qI3VmNkGWq0nIq+Z2NioPexWGOXeIKTXJpLWwnka5/LgJViAyqyQ bQcfCnjJ+Gh6kEDPcX2PJ3eh7PATEiKO4o45CRapWMyNh38w/igFfkUt0T63rGU+Q7aR Ka58YoNUtoaoeWEkxfpeaW/Sv/Gaftg5Jifp1Tass9fj+QwUJ0lywD/gVYjg7vNBniil nqJnTx2vY0PNbm1zwCUoLSt7f7/u/32YlUb6tON5Try7cJLBeFOEfziv3eKWmY/+A/sz rVmg== X-Gm-Message-State: ALoCoQmVqVpoLKPaun2jynrzURRP52U9eSkbUA1ttw2m9jWFIAu4spC9hiM4plcaohmlZysWuHJN MIME-Version: 1.0 X-Received: by 10.182.120.230 with SMTP id lf6mr11135054obb.39.1423475102017; Mon, 09 Feb 2015 01:45:02 -0800 (PST) Received: by 10.76.95.198 with HTTP; Mon, 9 Feb 2015 01:45:01 -0800 (PST) In-Reply-To: <1423247795-22399-2-git-send-email-stephen@networkplumber.org> References: <1423247795-22399-1-git-send-email-stephen@networkplumber.org> <1423247795-22399-2-git-send-email-stephen@networkplumber.org> Date: Mon, 9 Feb 2015 10:45:01 +0100 Message-ID: From: David Marchand To: Stephen Hemminger Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 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: Mon, 09 Feb 2015 09:45:03 -0000 Hello Stephen, - It looks a bit odd to me, we end up with something asymetric between uio / vfio wrt pci config space. Can we an api consistent between the two ? Does this mean that your pmd cannot work / has not been used with vfio ? - Anyway, I suppose we could reuse this api to remove the RTE_PCI_CONFIG #ifdef / hardcoded stuff from linux eal / igb_uio. Opinion ? -- David Marchand On Fri, Feb 6, 2015 at 7:36 PM, Stephen Hemminger < stephen@networkplumber.org> wrote: > From: Stephen Hemminger > > 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 +++++++++ > lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 ++ > 4 files changed, 56 insertions(+) > > diff --git a/lib/librte_eal/common/include/rte_pci.h > b/lib/librte_eal/common/include/rte_pci.h > index 66ed793..a78081f 100644 > --- a/lib/librte_eal/common/include/rte_pci.h > +++ b/lib/librte_eal/common/include/rte_pci.h > @@ -152,6 +152,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 > */ > + int config_fd; /**< PCI config access */ > }; > > /** Any PCI device identifier (vendor, device, ...) */ > @@ -298,6 +299,34 @@ void rte_eal_pci_register(struct rte_pci_driver > *driver); > */ > 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 > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c > b/lib/librte_eal/linuxapp/eal/eal_pci.c > index b5f5410..5bcfffa 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c > @@ -233,6 +233,7 @@ pci_scan_one(const char *dirname, uint16_t domain, > uint8_t bus, > 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); > @@ -592,6 +593,20 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver > *dr, struct rte_pci_device *d > 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) > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > index e53f06b..0396eaa 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -213,6 +213,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char > *dstbuf, > struct dirent *e; > DIR *dir; > char dirname[PATH_MAX]; > + char filename[PATH_MAX]; > > /* depending on kernel version, uio can be located in uio/uioX > * or uio:uioX */ > @@ -268,6 +269,15 @@ pci_get_uio_dev(struct rte_pci_device *dev, char > *dstbuf, > if (e == NULL) > return -1; > > + /* Open fd for access to PCI config */ > + snprintf(filename, sizeof(filename), "%s/device/config", dirname); > + 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; > + } > + > /* create uio device if we've been asked to */ > if (internal_config.create_uio_dev && > pci_mknod_uio_dev(dstbuf, uio_num) < 0) > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > index d36286e..626689c 100644 > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map > @@ -40,6 +40,8 @@ DPDK_2.0 { > rte_eal_pci_probe; > rte_eal_pci_register; > rte_eal_pci_unregister; > + rte_eal_pci_read_config; > + rte_eal_pci_write_config; > rte_eal_process_type; > rte_eal_remote_launch; > rte_eal_tailq_lookup; > -- > 2.1.4 > >