From: Stephen Hemminger <stephen@networkplumber.org>
To: David Marchand <david.marchand@6wind.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, Stephen Hemminger <shemming@Brocade.com>
Subject: Re: [dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space
Date: Tue, 10 Feb 2015 17:23:43 -0800 [thread overview]
Message-ID: <20150210172343.3fb6d3fe@uryu.home.lan> (raw)
In-Reply-To: <c058fdefd5564f3f96bd21593c9ea19a@BRMWP-EXMB11.corp.brocade.com>
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 <stephen@networkplumber.org>
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 <stephen@networkplumber.org>
---
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 <string.h>
#include <dirent.h>
#include <sys/mman.h>
+#include <sys/fcntl.h>
#include <rte_log.h>
#include <rte_pci.h>
@@ -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)
next prev parent reply other threads:[~2015-02-11 1:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-06 18:36 [dpdk-dev] [PATCH 0/4] Broadcom 10G NIC Poll Mode Driver Stephen Hemminger
2015-02-06 18:36 ` [dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space Stephen Hemminger
2015-02-09 9:45 ` David Marchand
2015-02-10 23:49 ` Stephen Hemminger
[not found] ` <c058fdefd5564f3f96bd21593c9ea19a@BRMWP-EXMB11.corp.brocade.com>
2015-02-11 1:23 ` Stephen Hemminger [this message]
2015-02-06 18:36 ` [dpdk-dev] [PATCH 2/4] bcm: add BCM pci device ids Stephen Hemminger
2015-02-06 18:36 ` [dpdk-dev] [PATCH 3/4] bcm: new poll mode driver Stephen Hemminger
2015-02-06 18:36 ` [dpdk-dev] [PATCH 4/4] bcm: enable BCM poll mode driver in config Stephen Hemminger
2015-02-07 9:15 ` [dpdk-dev] [PATCH 0/4] Broadcom 10G NIC Poll Mode Driver Jun Xiao
2015-02-07 15:15 ` Stephen Hemminger
2015-02-07 16:05 ` Jun Xiao
2015-02-07 22:23 ` Stephen Hemminger
2015-02-12 14:00 ` Thomas Monjalon
2015-02-12 14:33 ` Stephen Hemminger
2015-02-12 14:56 ` Thomas Monjalon
[not found] ` <0a8c8ae93e354bf0a74dd8ade9d1cc70@BRMWP-EXMB11.corp.brocade.com>
2015-02-12 21:45 ` Stephen Hemminger
2015-02-13 8:31 ` Thomas Monjalon
2015-05-07 23:25 [dpdk-dev] [PATCH 0/4 v4] bnx2x: new poll mode driver Stephen Hemminger
2015-05-07 23:25 ` [dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space Stephen Hemminger
2015-05-11 12:54 ` Neil Horman
[not found] ` <38426478085b4e779e18967cd1b6ae4f@BRMWP-EXMB11.corp.brocade.com>
2015-05-11 15:23 ` Stephen Hemminger
2015-05-11 15:37 ` Neil Horman
2015-05-11 17:30 ` Stephen Hemminger
2015-05-11 17:31 ` Stephen Hemminger
2015-05-12 9:56 ` Bruce Richardson
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=20150210172343.3fb6d3fe@uryu.home.lan \
--to=stephen@networkplumber.org \
--cc=david.marchand@6wind.com \
--cc=dev@dpdk.org \
--cc=shemming@Brocade.com \
/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).