From: Tiwei Bie <tiwei.bie@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, stable@dpdk.org
Subject: [dpdk-stable] [PATCH 2/2] eal/bsd: fix the read operation on PCI configuration space
Date: Sun, 7 May 2017 13:33:34 +0000 [thread overview]
Message-ID: <20170507133334.16219-3-tiwei.bie@intel.com> (raw)
In-Reply-To: <20170507133334.16219-1-tiwei.bie@intel.com>
Some drivers (such as virtio) may need to read more than 4 bytes
data from PCI configuration space via rte_eal_pci_read_config().
But it will return with an error on FreeBSD when the expected
data length is bigger than the size of pi.pi_data whose type is
u_int32_t. This patch removes this limitation.
Fixes: 632b2d1deeed ("eal: provide functions to access PCI config")
Cc: stable@dpdk.org
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
lib/librte_eal/bsdapp/eal/eal_pci.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 59ceb7665..e321461d8 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -459,6 +459,7 @@ int rte_pci_read_config(const struct rte_pci_device *dev,
void *buf, size_t len, off_t offset)
{
int fd = -1;
+ int size;
struct pci_io pi = {
.pi_sel = {
.pc_domain = dev->addr.domain,
@@ -467,25 +468,28 @@ int rte_pci_read_config(const struct rte_pci_device *dev,
.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_RDWR);
if (fd < 0) {
RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
goto error;
}
- if (ioctl(fd, PCIOCREAD, &pi) < 0)
- goto error;
+ while (len > 0) {
+ size = (len >= 4) ? 4 : ((len >= 2) ? 2 : 1);
+ pi.pi_width = size;
+
+ if (ioctl(fd, PCIOCREAD, &pi) < 0)
+ goto error;
+ memcpy(buf, &pi.pi_data, size);
+
+ buf = (char *)buf + size;
+ pi.pi_reg += size;
+ len -= size;
+ }
close(fd);
- memcpy(buf, &pi.pi_data, len);
return 0;
error:
--
2.12.1
next prev parent reply other threads:[~2017-05-07 13:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20170507133334.16219-1-tiwei.bie@intel.com>
2017-05-07 13:33 ` [dpdk-stable] [PATCH 1/2] eal/bsd: fix ioport write operation Tiwei Bie
2017-05-08 8:55 ` Bruce Richardson
2017-05-08 9:07 ` Tiwei Bie
2017-05-08 9:46 ` Bruce Richardson
2017-05-07 13:33 ` Tiwei Bie [this message]
2017-05-08 9:47 ` [dpdk-stable] [PATCH 2/2] eal/bsd: fix the read operation on PCI configuration space Bruce Richardson
[not found] <20170507132611.14016-1-tiwei.bie@intel.com>
2017-05-07 13:26 ` Tiwei Bie
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=20170507133334.16219-3-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.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).