DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
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, 12 May 2015 10:56:25 +0100	[thread overview]
Message-ID: <20150512095624.GA12516@bricha3-MOBL3> (raw)
In-Reply-To: <20150511103104.1c60565b@urahara>

On Mon, May 11, 2015 at 10:31:04AM -0700, Stephen Hemminger wrote:
> 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.

No, it doesn't. :-)
Version that compiles is below. However, I haven't tried testing it yet or
anything. Is there any easy way for me to do so?

/Bruce

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 61e8921..4194199 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -490,6 +490,87 @@ 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;
+
+       struct pci_io pi = {
+               .pi_sel = {
+                       .pc_domain = dev->addr.domain,
+                       .pc_bus = dev->addr.bus,
+                       .pc_dev = dev->addr.devid,
+                       .pc_func = dev->addr.function,
+               },
+               .pi_reg = offset,
+               .pi_width = len,
+       };
+
+       if (len == 3 || len > sizeof(pi.pi_data)) {
+               RTE_LOG(ERR, EAL, "%s(): invalid pci read length\n", __func__);
+               goto error;
+       }
+
+       fd = open("/dev/pci", O_RDONLY);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+               goto error;
+       }
+
+       if (ioctl(fd, PCIOCREAD, &pi) < 0)
+               goto error;
+       close(fd);
+
+       memcpy(buf, &pi.pi_data, len);
+       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 *dev,
+                            const void *buf, size_t len, off_t offset)
+{
+       int fd = -1;
+
+       struct pci_io pi = {
+               .pi_sel = {
+                       .pc_domain = dev->addr.domain,
+                       .pc_bus = dev->addr.bus,
+                       .pc_dev = dev->addr.devid,
+                       .pc_func = dev->addr.function,
+               },
+               .pi_reg = offset,
+               .pi_data = *(u_int32_t *)buf,
+               .pi_width = len,
+       };
+
+       if (len == 3 || len > sizeof(pi.pi_data)) {
+               RTE_LOG(ERR, EAL, "%s(): invalid pci read length\n", __func__);
+               goto error;
+       }
+
+       fd = open("/dev/pci", O_RDONLY);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+               goto error;
+       }
+
+       if (ioctl(fd, PCIOCWRITE, &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)

  reply	other threads:[~2015-05-12  9:56 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
2015-05-12  9:56       ` Bruce Richardson [this message]
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=20150512095624.GA12516@bricha3-MOBL3 \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=shemming@Brocade.com \
    --cc=stephen@networkplumber.org \
    /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).