Skip to contentSkip to conversation

various fixes for eal/bsd

PATCH Applied Tiwei Bie 3 participants 8 messages May 7, 2017 – May 10, 2017

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

cover various fixes for eal/bsd

Tiwei Bie (2):
eal/bsd: fix ioport write operation
eal/bsd: fix the read operation on PCI configuration space

 lib/librte_eal/bsdapp/eal/eal_pci.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
Signature · 1 line
2.12.1
author
#1 lore raw

PATCH 1/2 eal/bsd: fix ioport write operation

The first param of out*() on FreeBSD is port, and the second one is data. But they are reversed in DPDK. This patch fixes it.

Fixes 756ce64b1ecd ("eal: introduce PCI ioport API")
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +3 -3
index 6294b7eab..59ceb7665 100644
@@ -618,13 +618,13 @@ pci_uio_ioport_write(struct rte_pci_ioport *p,
 	for (s = data; len > 0; s += size, reg += size, len -= size) {
 		if (len >= 4) {
 			size = 4;
-			outl(*(const uint32_t *)s, reg);
+			outl(reg, *(const uint32_t *)s);
 		} else if (len >= 2) {
 			size = 2;
-			outw(*(const uint16_t *)s, reg);
+			outw(reg, *(const uint16_t *)s);
 		} else {
 			size = 1;
-			outb(*s, reg);
+			outb(reg, *s);
 		}
 	}
 #else
Signature · 1 line
2.12.1
#2 lore raw

Re: [PATCH 1/2] eal/bsd: fix ioport write operation

Quoted 7 lines · Tiwei Bie

The first param of out*() on FreeBSD is port, and the second one is data. But they are reversed in DPDK. This patch fixes it.

Fixes 756ce64b1ecd ("eal: introduce PCI ioport API") Cc:

[email protected]

How was this bug discovered so that we can verify that it is fixed?. Is this in use by virtio or was it just discovered via code inspection?

/Bruce

author
#3 lore raw

Re: [PATCH 1/2] eal/bsd: fix ioport write operation

Quoted 11 lines · Bruce Richardson
Quoted 7 lines · Tiwei Bie

The first param of out*() on FreeBSD is port, and the second one is data. But they are reversed in DPDK. This patch fixes it.

Fixes 756ce64b1ecd ("eal: introduce PCI ioport API") Cc:

[email protected]

How was this bug discovered so that we can verify that it is fixed?. Is this in use by virtio or was it just discovered via code inspection?

The virtio PMD in legacy mode doesn't work FreeBSD, and I tried to fix this issue. And then I found this bug.

Best regards,
Tiwei Bie

#4 lore raw

Re: [PATCH 1/2] eal/bsd: fix ioport write operation

Quoted 13 lines · Tiwei Bie
Quoted 11 lines · Bruce Richardson
Quoted 7 lines · Tiwei Bie

The first param of out*() on FreeBSD is port, and the second one is data. But they are reversed in DPDK. This patch fixes it.

Fixes 756ce64b1ecd ("eal: introduce PCI ioport API") Cc:

[email protected]

How was this bug discovered so that we can verify that it is fixed?. Is this in use by virtio or was it just discovered via code inspection?

Quoted 5 lines

The virtio PMD in legacy mode doesn't work FreeBSD, and I tried to fix this issue. And then I found this bug.

Best regards,
Tiwei Bie

author
#5 lore raw

PATCH 2/2 eal/bsd: fix the read operation on PCI configuration space

In reply to Tiwei Bie

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")
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +13 -9
index 59ceb7665..e321461d8 100644
@@ -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:
Signature · 1 line
2.12.1
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] eal/bsd: fix the read operation on PCI configuration space

Quoted 11 lines · Tiwei Bie

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")

---

#7 lore raw
In reply to Tiwei Bie

07/05/2017 15:33, Tiwei Bie:

Quoted 6 lines

Tiwei Bie (2):
eal/bsd: fix ioport write operation
eal/bsd: fix the read operation on PCI configuration space

 lib/librte_eal/bsdapp/eal/eal_pci.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

Applied, thanks