DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Chao Zhu" <chaozhu@linux.vnet.ibm.com>
To: "'Olivier Matz'" <olivier.matz@6wind.com>, <dev@dpdk.org>
Cc: <david.marchand@6wind.com>, <yuanhan.liu@linux.intel.com>,
	<huawei.xie@intel.com>
Subject: Re: [dpdk-dev] [PATCH v2 6/7] virtio: fix pci accesses for ppc64 in legacy mode
Date: Thu, 19 May 2016 17:13:52 +0800	[thread overview]
Message-ID: <000301d1b1ae$cebf1470$6c3d3d50$@linux.vnet.ibm.com> (raw)
In-Reply-To: <1463479192-2488-7-git-send-email-olivier.matz@6wind.com>

Olivier,

Thanks for the patches! 
Just one comment:
POWER8 machine only supports little endian OS on bare metal. In VM guest, it
can support both little endian and big endian OS. Did you try to run it on
both host (little endian) and guest (big endian and little endian)?

-----Original Message-----
From: Olivier Matz [mailto:olivier.matz@6wind.com] 
Sent: 2016年5月17日 18:00
To: dev@dpdk.org
Cc: david.marchand@6wind.com; chaozhu@linux.vnet.ibm.com; yuanhan.liu@linux.
intel.com; huawei.xie@intel.com
Subject: [PATCH v2 6/7] virtio: fix pci accesses for ppc64 in legacy mode

From: David Marchand <david.marchand@6wind.com>

Although ppc supports both endianesses, qemu supposes that the cpu is big
endian and enforces this for the virtio-net stuff.

Fix PCI accesses in legacy mode. Only ppc64le is supported at the moment.

Signed-off-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 drivers/net/virtio/virtio_pci.c | 68
+++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/net/virtio/virtio_pci.c
b/drivers/net/virtio/virtio_pci.c index 9cdca06..ebf4cf7 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -55,20 +55,88 @@
  */
 #define VIRTIO_PCI_CONFIG(hw) (((hw)->use_msix) ? 24 : 20)

+/*
+ * Since we are in legacy mode:
+ * http://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf
+ *
+ * "Note that this is possible because while the virtio header is PCI (i.e.
+ * little) endian, the device-specific region is encoded in the native 
+endian of
+ * the guest (where such distinction is applicable)."
+ *
+ * For powerpc which supports both, qemu supposes that cpu is big 
+endian and
+ * enforces this for the virtio-net stuff.
+ */
+
 static void
 legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
 		       void *dst, int length)
 {
+#ifdef RTE_ARCH_PPC_64
+	int size;
+
+	while (length > 0) {
+		if (length >= 4) {
+			size = 4;
+			rte_eal_pci_ioport_read(&hw->io, dst, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+			*(uint32_t *)dst = rte_be_to_cpu_32(*(uint32_t
*)dst);
+		} else if (length >= 2) {
+			size = 2;
+			rte_eal_pci_ioport_read(&hw->io, dst, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+			*(uint16_t *)dst = rte_be_to_cpu_16(*(uint16_t
*)dst);
+		} else {
+			size = 1;
+			rte_eal_pci_ioport_read(&hw->io, dst, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+		}
+
+		dst = (char *)dst + size;
+		offset += size;
+		length -= size;
+	}
+#else
 	rte_eal_pci_ioport_read(&hw->io, dst, length,
 				VIRTIO_PCI_CONFIG(hw) + offset);
+#endif
 }

 static void
 legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
 			const void *src, int length)
 {
+#ifdef RTE_ARCH_PPC_64
+	union {
+		uint32_t u32;
+		uint16_t u16;
+	} tmp;
+	int size;
+
+	while (length > 0) {
+		if (length >= 4) {
+			size = 4;
+			tmp.u32 = rte_cpu_to_be_32(*(const uint32_t *)src);
+			rte_eal_pci_ioport_write(&hw->io, &tmp.u32, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+		} else if (length >= 2) {
+			size = 2;
+			tmp.u16 = rte_cpu_to_be_16(*(const uint16_t *)src);
+			rte_eal_pci_ioport_write(&hw->io, &tmp.u16, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+		} else {
+			size = 1;
+			rte_eal_pci_ioport_write(&hw->io, src, size,
+				VIRTIO_PCI_CONFIG(hw) + offset);
+		}
+
+		src = (const char *)src + size;
+		offset += size;
+		length -= size;
+	}
+#else
 	rte_eal_pci_ioport_write(&hw->io, src, length,
 				 VIRTIO_PCI_CONFIG(hw) + offset);
+#endif
 }

 static uint64_t
--
2.8.0.rc3

  reply	other threads:[~2016-05-19  9:13 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 12:50 [dpdk-dev] [PATCH 0/7] virtio-net support on ppc64 Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 1/7] eal: fix typos in ioport API doxygen comments Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 2/7] eal/linux: only call iopl on x86 Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 3/7] eal/linux: remove invalid comment Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 4/7] eal/linux: split function parsing pci resources in sysfs Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 5/7] eal/linux: mmap ioports on ppc64 Olivier Matz
2016-05-13 14:33   ` David Marchand
2016-05-13 16:36     ` Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 6/7] virtio: fix pci accesses for ppc64 in legacy mode Olivier Matz
2016-05-13 14:28   ` David Marchand
2016-05-13 16:34     ` Olivier Matz
2016-05-13 12:50 ` [dpdk-dev] [PATCH 7/7] config: enable virtio-net pmd for ppc64 Olivier Matz
2016-05-17  9:59 ` [dpdk-dev] [PATCH v2 0/7] virtio-net support on ppc64 Olivier Matz
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 1/7] eal: fix typos in ioport API doxygen comments Olivier Matz
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 2/7] eal/linux: only call iopl on x86 Olivier Matz
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 3/7] eal/linux: remove invalid comment Olivier Matz
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 4/7] eal/linux: split function parsing pci resources in sysfs Olivier Matz
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 5/7] eal/linux: mmap ioports on ppc64 Olivier Matz
2016-05-17 15:54     ` David Marchand
2016-05-18 11:17       ` Olivier Matz
2016-05-23 13:07       ` Yuanhan Liu
2016-05-23 13:40         ` Olivier Matz
2016-05-24  5:15           ` Yuanhan Liu
2016-05-30  8:45             ` Olivier Matz
2016-06-15 16:13               ` Thomas Monjalon
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 6/7] virtio: fix pci accesses for ppc64 in legacy mode Olivier Matz
2016-05-19  9:13     ` Chao Zhu [this message]
2016-05-20 12:11       ` Olivier Matz
2016-05-20 12:18         ` Olivier Matz
2016-05-24  6:28         ` Chao Zhu
2016-05-17  9:59   ` [dpdk-dev] [PATCH v2 7/7] config: enable virtio-net pmd for ppc64 Olivier Matz
2016-06-15 17:08   ` [dpdk-dev] [PATCH v2 0/7] virtio-net support on ppc64 Thomas Monjalon

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='000301d1b1ae$cebf1470$6c3d3d50$@linux.vnet.ibm.com' \
    --to=chaozhu@linux.vnet.ibm.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    --cc=olivier.matz@6wind.com \
    --cc=yuanhan.liu@linux.intel.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).