DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Neil Horman <nhorman@tuxdriver.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: Mon, 11 May 2015 10:31:04 -0700	[thread overview]
Message-ID: <20150511103104.1c60565b@urahara> (raw)
In-Reply-To: <38426478085b4e779e18967cd1b6ae4f@BRMWP-EXMB11.corp.brocade.com>

On Mon, 11 May 2015 12:54:54 +0000
Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, May 07, 2015 at 04:25:32PM -0700, Stephen Hemminger wrote:
> > From: Stephen Hemminger <shemming@brocade.com>
> > 
> > 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.
> > 

Could someone who has BSD infrastructure try this, not sure if it will even
build.

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 61e8921..8ba5b13 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -490,6 +490,76 @@ 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 *dev,
+			    void *buf, size_t len, off_t offset)
+{
+	int fd = -1;
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	struct pci_io pi = {
+		.pi_sel = {
+			.pc_domain = dev->addr.domain,
+			.bus = dev->addr.bus,
+			.pc_dev = dev->addr.devid,
+			.pc_func = dev->addr.function,
+		},
+		.pi_reg = offset,
+		.pi_data = buf,
+		.pi_width = len,
+	};
+
+	if (ioctl(fd, PCIIOCREAD, &pi) < 0)
+		goto error;
+	close(fd);
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
+/* 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)
+{
+	int fd = -1;
+
+	fd = open("/dev/pci", O_RDONLY);
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+		goto error;
+	}
+
+	struct pci_io pi = {
+		.pi_sel = {
+			.pc_domain = dev->addr.domain,
+			.bus = dev->addr.bus,
+			.pc_dev = dev->addr.devid,
+			.pc_func = dev->addr.function,
+		},
+		.pi_reg = offset,
+		.pi_data = buf,
+		.pi_width = len,
+	};
+
+	if (ioctl(fd, PCIIOCWRITE, &pi) < 0)
+		goto error;
+	close(fd);
+	return 0;
+
+error:
+	if (fd >= 0)
+		close(fd);
+	return -1;
+}
+
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)

  parent reply	other threads:[~2015-05-11 17:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2015-05-12  9:56       ` Bruce Richardson
2015-05-07 23:25 ` [dpdk-dev] [PATCH 2/4] bnx2x: new poll mode driver (part1) Stephen Hemminger
2015-05-07 23:25 ` [dpdk-dev] [PATCH 3/4] bnx2x: new poll mode driver (part2) Stephen Hemminger
2015-05-07 23:25 ` [dpdk-dev] [PATCH 4/4] bnx2x: enable BNX2X poll mode driver Stephen Hemminger
  -- strict thread matches above, loose matches on Subject: below --
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

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=20150511103104.1c60565b@urahara \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=nhorman@tuxdriver.com \
    --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).