qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] Add param Error** to msix_init() & modify the c


From: Cao jin
Subject: [Qemu-devel] [PATCH 2/2] Add param Error** to msix_init() & modify the callers
Date: Mon, 7 Dec 2015 16:08:45 +0800

msix_init() is a supporting function in PCI device initialization, in
order to convert .init() to .realize(), it should be modified first.
Also modify the callers.

Signed-off-by: Cao jin <address@hidden>
---
 hw/net/rocker/rocker.c |  3 ++-
 hw/net/vmxnet3.c       |  4 +++-
 hw/pci/msix.c          | 13 ++++++++++---
 hw/scsi/megasas.c      | 16 ++++++++++++----
 hw/usb/hcd-xhci.c      |  2 +-
 hw/vfio/pci.c          |  4 +++-
 include/hw/pci/msix.h  |  3 ++-
 7 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
index c57f1a6..9faa117 100644
--- a/hw/net/rocker/rocker.c
+++ b/hw/net/rocker/rocker.c
@@ -1248,13 +1248,14 @@ static int rocker_msix_init(Rocker *r)
 {
     PCIDevice *dev = PCI_DEVICE(r);
     int err;
+    Error *local_err = NULL;
 
     err = msix_init(dev, ROCKER_MSIX_VEC_COUNT(r->fp_ports),
                     &r->msix_bar,
                     ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_TABLE_OFFSET,
                     &r->msix_bar,
                     ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_PBA_OFFSET,
-                    0);
+                    0, &local_err);
     if (err) {
         return err;
     }
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 4269141..fad783e 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2098,12 +2098,14 @@ static bool
 vmxnet3_init_msix(VMXNET3State *s)
 {
     PCIDevice *d = PCI_DEVICE(s);
+    Error *local_err = NULL;
+
     int res = msix_init(d, VMXNET3_MAX_INTRS,
                         &s->msix_bar,
                         VMXNET3_MSIX_BAR_IDX, VMXNET3_OFF_MSIX_TABLE,
                         &s->msix_bar,
                         VMXNET3_MSIX_BAR_IDX, VMXNET3_OFF_MSIX_PBA,
-                        0);
+                        0, &local_err);
 
     if (0 > res) {
         VMW_WRPRN("Failed to initialize MSI-X, error %d", res);
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 64c93d8..28c14d1 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -233,7 +233,8 @@ static void msix_mask_all(struct PCIDevice *dev, unsigned 
nentries)
 int msix_init(struct PCIDevice *dev, unsigned short nentries,
               MemoryRegion *table_bar, uint8_t table_bar_nr,
               unsigned table_offset, MemoryRegion *pba_bar,
-              uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos)
+              uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos,
+              Error **errp)
 {
     int cap;
     unsigned table_size, pba_size;
@@ -241,10 +242,13 @@ int msix_init(struct PCIDevice *dev, unsigned short 
nentries,
 
     /* Nothing to do if MSI is not supported by interrupt controller */
     if (!msi_supported) {
+        error_setg(errp, "MSI-X is not supported by interrupt controller");
         return -ENOTSUP;
     }
 
     if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1) {
+        error_setg(errp, "Vector number %d invalid, should be 1 ~ %d",
+                nentries, PCI_MSIX_FLAGS_QSIZE + 1);
         return -EINVAL;
     }
 
@@ -257,10 +261,12 @@ int msix_init(struct PCIDevice *dev, unsigned short 
nentries,
         table_offset + table_size > memory_region_size(table_bar) ||
         pba_offset + pba_size > memory_region_size(pba_bar) ||
         (table_offset | pba_offset) & PCI_MSIX_FLAGS_BIRMASK) {
+        error_setg(errp, "Arguments invalid. please check them carefully");
         return -EINVAL;
     }
 
-    cap = pci_add_capability(dev, PCI_CAP_ID_MSIX, cap_pos, MSIX_CAP_LENGTH);
+    cap = pci_add_capability2(dev, PCI_CAP_ID_MSIX, cap_pos,
+                              MSIX_CAP_LENGTH, errp);
     if (cap < 0) {
         return cap;
     }
@@ -304,6 +310,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short 
nentries,
     uint32_t bar_size = 4096;
     uint32_t bar_pba_offset = bar_size / 2;
     uint32_t bar_pba_size = (nentries / 8 + 1) * 8;
+    Error *local_err = NULL;
 
     /*
      * Migration compatibility dictates that this remains a 4k
@@ -329,7 +336,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned short 
nentries,
     ret = msix_init(dev, nentries, &dev->msix_exclusive_bar, bar_nr,
                     0, &dev->msix_exclusive_bar,
                     bar_nr, bar_pba_offset,
-                    0);
+                    0, &local_err);
     if (ret) {
         return ret;
     }
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 4759fb5..ef52a85 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2356,11 +2356,19 @@ static void megasas_scsi_realize(PCIDevice *dev, Error 
**errp)
             return;
         }
     }
-    if (megasas_use_msix(s) &&
-        msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
-                  &s->mmio_io, b->mmio_bar, 0x3800, 0x68)) {
-        s->flags &= ~MEGASAS_MASK_USE_MSIX;
+
+    if (megasas_use_msix(s)) {
+        int ret;
+
+        ret = msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
+                  &s->mmio_io, b->mmio_bar, 0x3800, 0x68, errp);
+        if (ret > 0) {
+            s->flags &= ~MEGASAS_MASK_USE_MSIX;
+        } else {
+            return;
+        }
     }
+
     if (pci_is_express(dev)) {
         pcie_endpoint_cap_init(dev, 0xa0);
     }
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index b452c52..26e81d5 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3652,7 +3652,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error 
**errp)
         msix_init(dev, xhci->numintrs,
                   &xhci->mem, 0, OFF_MSIX_TABLE,
                   &xhci->mem, 0, OFF_MSIX_PBA,
-                  0x90);
+                  0x90, errp);
     }
 }
 
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 8559950..6b2bf5c 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1251,12 +1251,14 @@ static int vfio_msix_early_setup(VFIOPCIDevice *vdev)
 static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos)
 {
     int ret;
+    Error *local_err = NULL;
 
     ret = msix_init(&vdev->pdev, vdev->msix->entries,
                     &vdev->bars[vdev->msix->table_bar].region.mem,
                     vdev->msix->table_bar, vdev->msix->table_offset,
                     &vdev->bars[vdev->msix->pba_bar].region.mem,
-                    vdev->msix->pba_bar, vdev->msix->pba_offset, pos);
+                    vdev->msix->pba_bar, vdev->msix->pba_offset, pos,
+                    &local_err);
     if (ret < 0) {
         if (ret == -ENOTSUP) {
             return 0;
diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h
index 72e5f93..6535a6c 100644
--- a/include/hw/pci/msix.h
+++ b/include/hw/pci/msix.h
@@ -9,7 +9,8 @@ MSIMessage msix_get_message(PCIDevice *dev, unsigned int 
vector);
 int msix_init(PCIDevice *dev, unsigned short nentries,
               MemoryRegion *table_bar, uint8_t table_bar_nr,
               unsigned table_offset, MemoryRegion *pba_bar,
-              uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos);
+              uint8_t pba_bar_nr, unsigned pba_offset, uint8_t cap_pos,
+              Error **errp);
 int msix_init_exclusive_bar(PCIDevice *dev, unsigned short nentries,
                             uint8_t bar_nr);
 
-- 
2.1.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]