All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, Matthew Rosato <mjrosato@linux.ibm.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Zhuoying Cai <zycai@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>
Subject: [PULL 14/23] pc-bios/s390-ccw: Add support for virtio-net-pci IPL
Date: Wed, 30 Sep 2026 11:24:11 -0400	[thread overview]
Message-ID: <20260930152420.1956230-15-farman@linux.ibm.com> (raw)
In-Reply-To: <20260930152420.1956230-1-farman@linux.ibm.com>

From: Zhuoying Cai <zycai@linux.ibm.com>

Enable network booting via virtio-net-pci by implementing PCI transport
support for virtio-net.

This patch also extends endianness handling for virtio PCI ring operations in
little-endian to ensure correct behavior on s390x.

Signed-off-by: Zhuoying Cai <zycai@linux.ibm.com>
Reviewed-by: Jared Rossi <jrossi@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20260924222949.147720-5-zycai@linux.ibm.com
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
 pc-bios/s390-ccw/main.c       |  2 ++
 pc-bios/s390-ccw/netmain.c    |  8 ++++++-
 pc-bios/s390-ccw/virtio-net.c | 41 ++++++++++++++++++++++++++++-------
 pc-bios/s390-ccw/virtio-pci.c | 20 +++++++++++++++++
 4 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c
index d2a2ac3138..b06d67c563 100644
--- a/pc-bios/s390-ccw/main.c
+++ b/pc-bios/s390-ccw/main.c
@@ -342,7 +342,9 @@ static void ipl_pci_device(void)
         return;
     }
 
+    /* net, scsi, and block all intentionally use the same shared boot setup */
     switch (vdev->dev_type) {
+    case VIRTIO_ID_NET:
     case VIRTIO_ID_SCSI:
     case VIRTIO_ID_BLOCK:
         if (virtio_setup() == 0) {
diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c
index bcb62bf6ca..dd02c5c71f 100644
--- a/pc-bios/s390-ccw/netmain.c
+++ b/pc-bios/s390-ccw/netmain.c
@@ -498,7 +498,13 @@ int netmain(void)
     sclp_setup();
     puts("Network boot starting...");
 
-    if (!virtio_ccw_net_setup()) {
+    /*
+     * CCW devices require subchannel enumeration here.
+     * PCI devices don't need specific net setup; the virtio-net-pci devices
+     * still follow the regular Virtio, PCI, and generic network setup.
+     */
+    if (virtio_get_device()->ipl_type == S390_IPL_TYPE_CCW &&
+        !virtio_ccw_net_setup()) {
         puts("No valid virtio ccw net device found.");
         return -1;
     }
diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c
index 7bb3f8f551..632ce059d6 100644
--- a/pc-bios/s390-ccw/virtio-net.c
+++ b/pc-bios/s390-ccw/virtio-net.c
@@ -66,7 +66,22 @@ int virtio_net_init(void *mac_addr)
     rx_last_idx = 0;
 
     vdev->guest_features[0] = VIRTIO_NET_F_MAC_BIT;
-    virtio_ccw_setup(vdev);
+    switch (virtio_get_device()->ipl_type) {
+    case S390_IPL_TYPE_CCW:
+        if (virtio_ccw_setup(vdev)) {
+            puts("Setup failed for virtio-net-ccw");
+            return -1;
+        }
+        break;
+    case S390_IPL_TYPE_PCI:
+        if (virtio_pci_setup(vdev)) {
+            puts("Setup failed for virtio-net-pci");
+            return -1;
+        }
+        break;
+    default:
+        return -1;
+    }
 
     if (!(vdev->guest_features[0] & VIRTIO_NET_F_MAC_BIT)) {
         puts("virtio-net device does not support the MAC address feature");
@@ -118,22 +133,30 @@ int recv(int fd, void *buf, int maxlen, int flags)
     VRing *rxvq = &vdev->vrings[VQ_RX];
     int len, id;
     uint8_t *pkt;
+    uint16_t rx_used_idx, rx_avail_idx;
+    uint32_t rx_used_len, rx_used_id;
+    uint64_t rx_desc_addr;
 
-    if (rx_last_idx == rxvq->used->idx) {
+    rx_used_idx = virtio_tswap16(rxvq->used->idx);
+    if (rx_last_idx == rx_used_idx) {
         return 0;
     }
 
-    len = rxvq->used->ring[rx_last_idx % rxvq->num].len - virtio_net_hdr_size;
+    rx_used_len = virtio_tswap32(rxvq->used->ring[rx_last_idx % rxvq->num].len);
+    rx_used_id = virtio_tswap32(rxvq->used->ring[rx_last_idx % rxvq->num].id);
+
+    len = rx_used_len - virtio_net_hdr_size;
     if (len > maxlen) {
         puts("virtio-net: Receive buffer too small");
         len = maxlen;
     }
-    id = rxvq->used->ring[rx_last_idx % rxvq->num].id % rxvq->num;
-    pkt = (uint8_t *)(rxvq->desc[id].addr + virtio_net_hdr_size);
+    id = rx_used_id % rxvq->num;
+    rx_desc_addr = virtio_tswap64(rxvq->desc[id].addr);
+    pkt = (uint8_t *)(rx_desc_addr + virtio_net_hdr_size);
 
 #if DEBUG_VIRTIO_NET   /* Dump packet */
     int i;
-    printf("\nbuf %p: len=%i\n", (void *)rxvq->desc[id].addr, len);
+    printf("\nbuf %p: len=%i\n", (void *)rx_desc_addr, len);
     for (i = 0; i < 64; i++) {
         printf(" %02x", pkt[i]);
         if ((i % 16) == 15) {
@@ -147,8 +170,10 @@ int recv(int fd, void *buf, int maxlen, int flags)
     memcpy(buf, pkt, len);
 
     /* Mark buffer as available to the host again */
-    rxvq->avail->ring[rxvq->avail->idx % rxvq->num] = id;
-    rxvq->avail->idx = rxvq->avail->idx + 1;
+    rx_avail_idx = virtio_tswap16(rxvq->avail->idx);
+    rxvq->avail->ring[rx_avail_idx % rxvq->num] = virtio_tswap16(id);
+    rx_avail_idx++;
+    rxvq->avail->idx = virtio_tswap16(rx_avail_idx);
     vring_notify(rxvq);
 
     /* Move index to next entry */
diff --git a/pc-bios/s390-ccw/virtio-pci.c b/pc-bios/s390-ccw/virtio-pci.c
index 277c3ea68d..eb47e7c534 100644
--- a/pc-bios/s390-ccw/virtio-pci.c
+++ b/pc-bios/s390-ccw/virtio-pci.c
@@ -56,6 +56,10 @@ void virtio_pci_id2type(VDev *vdev, uint16_t device_id)
     case 0x1004:
         vdev->dev_type = VIRTIO_ID_SCSI;
         break;
+    case 0x1041:
+    case 0x1000:
+        vdev->dev_type = VIRTIO_ID_NET;
+        break;
     default:
         vdev->dev_type = 0;
     }
@@ -223,6 +227,17 @@ static int virtio_pci_get_scsi_config(void)
     return rc;
 }
 
+static int virtio_pci_get_net_config(void)
+{
+    VirtioNetConfig *cfg = &virtio_get_device()->config.net;
+
+    /*
+     * Byte-swapping is not needed as only the MAC address (byte array)
+     * is used here. Byte-swap if other fields are added.
+     */
+    return vpci_read_flex(d_cap.off, d_cap.bar, cfg, sizeof(VirtioNetConfig));
+}
+
 static int virtio_pci_negotiate(void)
 {
     int i, rc;
@@ -355,6 +370,7 @@ bool virtio_pci_is_supported(VDev *vdev)
         switch (vdev->dev_type) {
         case VIRTIO_ID_BLOCK:
         case VIRTIO_ID_SCSI:
+        case VIRTIO_ID_NET:
             return true;
         default:
             return false;
@@ -414,6 +430,10 @@ int virtio_pci_setup(VDev *vdev)
         vdev->cmd_vr_idx = 2;
         virtio_pci_get_scsi_config();
         break;
+    case VIRTIO_ID_NET:
+        vdev->nr_vqs = 2;
+        virtio_pci_get_net_config();
+        break;
     default:
         puts("Unsupported virtio device");
         return -ENODEV;
-- 
2.55.0



  parent reply	other threads:[~2026-09-30 15:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 15:23 [PULL 00/23] s390x queue Eric Farman
2026-09-30 15:23 ` [PULL 01/23] virtio-ccw: Limit ISC to MAX_ISC Eric Farman
2026-09-30 15:23 ` [PULL 02/23] virtio-ccw: Do not overwrite existing indicators Eric Farman
2026-09-30 15:24 ` [PULL 03/23] virtio-ccw: Fix rc check in read configuration path Eric Farman
2026-09-30 15:24 ` [PULL 04/23] vfio/ap: Clear error object pointer after non-fatal errors Eric Farman
2026-09-30 15:24 ` [PULL 05/23] vfio/ccw: " Eric Farman
2026-09-30 15:24 ` [PULL 06/23] hw/intc/s390x: Fix payload to KVM_HAS_DEVICE_ATTR ioctl Eric Farman
2026-09-30 15:24 ` [PULL 07/23] hw/intc/s390x: Fix check after g_try_realloc Eric Farman
2026-09-30 15:24 ` [PULL 08/23] s390x/css: Use datastream pointer for checking no-data CCWs Eric Farman
2026-09-30 15:24 ` [PULL 09/23] s390x/sclp: Reject short headers in PV case Eric Farman
2026-09-30 15:24 ` [PULL 10/23] s390x: Expose pv attribute in QOM Eric Farman
2026-09-30 15:24 ` [PULL 11/23] pc-bios/s390-ccw: Move CCW net setup to virtio-ccw Eric Farman
2026-09-30 15:24 ` [PULL 12/23] pc-bios/s390-ccw: Add dynamic net header size handling Eric Farman
2026-09-30 15:24 ` [PULL 13/23] pc-bios/s390-ccw: Introduce virtio_tswap helpers Eric Farman
2026-09-30 15:24 ` Eric Farman [this message]
2026-09-30 15:24 ` [PULL 15/23] hw/virtio: Add "loadparm" property to virtio net PCI devices booting on s390x Eric Farman
2026-09-30 15:24 ` [PULL 16/23] tests/qtest: Check s390x boot device support in pxe-test.c Eric Farman
2026-10-07 20:02   ` Bernhard Beschow
2026-10-08 12:19     ` Eric Farman
2026-09-30 15:24 ` [PULL 17/23] tests/qtest: Add s390x virtio net PCI test to pxe-test.c Eric Farman
2026-09-30 15:24 ` [PULL 18/23] tests/functional/s390x: Add tests for virtio net PCI in test_pxelinux.py Eric Farman
2026-09-30 15:24 ` [PULL 19/23] s390x/sclpconsole: fix indentation for console_reset Eric Farman
2026-09-30 15:24 ` [PULL 20/23] s390x/pci: Fix frame stepping in rpcit_service_call() Eric Farman
2026-09-30 15:24 ` [PULL 21/23] s390x/pci: Use qemu_log_mask() for guest-triggered errors in reg_ioat() Eric Farman
2026-09-30 15:24 ` [PULL 22/23] s390x/pci: Reject apertures beyond IOAT capacity in translation mode Eric Farman
2026-09-30 15:24 ` [PULL 23/23] pc-bios/s390-ccw.img: update s390x bios Eric Farman
2026-10-01  7:03 ` [PULL 00/23] s390x queue Richard Henderson

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=20260930152420.1956230-15-farman@linux.ibm.com \
    --to=farman@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=zycai@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.