diff mbox series

[16/16] nvme: factor out controller identify setup

Message ID 20200415102445.564803-17-its@irrelevant.dk
State New
Headers show
Series nvme: refactoring and cleanups | expand

Commit Message

Klaus Jensen April 15, 2020, 10:24 a.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/block/nvme.c | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

Comments

Philippe Mathieu-Daudé April 15, 2020, 11:07 a.m. UTC | #1
On 4/15/20 12:24 PM, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> ---
>   hw/block/nvme.c | 42 ++++++++++++++++++++++++------------------
>   1 file changed, 24 insertions(+), 18 deletions(-)

The review is trivial using 'git-diff -W'.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 7387cf409f96..d1566b56381d 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -1428,27 +1428,11 @@ static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev)
>       }
>   }
>   
> -static void nvme_realize(PCIDevice *pci_dev, Error **errp)
> +static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
>   {
> -    NvmeCtrl *n = NVME(pci_dev);
>       NvmeIdCtrl *id = &n->id_ctrl;
> +    uint8_t *pci_conf = pci_dev->config;
>   
> -    int i;
> -    uint8_t *pci_conf;
> -
> -    if (nvme_check_constraints(n, errp)) {
> -        return;
> -    }
> -
> -    nvme_init_state(n);
> -
> -    if (nvme_init_blk(n, errp)) {
> -        return;
> -    }
> -
> -    nvme_init_pci(n, pci_dev);
> -
> -    pci_conf = pci_dev->config;
>       id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID));
>       id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID));
>       strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' ');
> @@ -1482,6 +1466,28 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
>       n->bar.vs = 0x00010200;
>       n->bar.intmc = n->bar.intms = 0;
>   
> +
> +}
> +
> +static void nvme_realize(PCIDevice *pci_dev, Error **errp)
> +{
> +    NvmeCtrl *n = NVME(pci_dev);
> +
> +    int i;
> +
> +    if (nvme_check_constraints(n, errp)) {
> +        return;
> +    }
> +
> +    nvme_init_state(n);
> +
> +    if (nvme_init_blk(n, errp)) {
> +        return;
> +    }
> +
> +    nvme_init_pci(n, pci_dev);
> +    nvme_init_ctrl(n, pci_dev);
> +
>       for (i = 0; i < n->num_namespaces; i++) {
>           if (nvme_init_namespace(n, &n->namespaces[i], errp)) {
>               return;
>
diff mbox series

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 7387cf409f96..d1566b56381d 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1428,27 +1428,11 @@  static void nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev)
     }
 }
 
-static void nvme_realize(PCIDevice *pci_dev, Error **errp)
+static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
 {
-    NvmeCtrl *n = NVME(pci_dev);
     NvmeIdCtrl *id = &n->id_ctrl;
+    uint8_t *pci_conf = pci_dev->config;
 
-    int i;
-    uint8_t *pci_conf;
-
-    if (nvme_check_constraints(n, errp)) {
-        return;
-    }
-
-    nvme_init_state(n);
-
-    if (nvme_init_blk(n, errp)) {
-        return;
-    }
-
-    nvme_init_pci(n, pci_dev);
-
-    pci_conf = pci_dev->config;
     id->vid = cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID));
     id->ssvid = cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR_ID));
     strpadcpy((char *)id->mn, sizeof(id->mn), "QEMU NVMe Ctrl", ' ');
@@ -1482,6 +1466,28 @@  static void nvme_realize(PCIDevice *pci_dev, Error **errp)
     n->bar.vs = 0x00010200;
     n->bar.intmc = n->bar.intms = 0;
 
+
+}
+
+static void nvme_realize(PCIDevice *pci_dev, Error **errp)
+{
+    NvmeCtrl *n = NVME(pci_dev);
+
+    int i;
+
+    if (nvme_check_constraints(n, errp)) {
+        return;
+    }
+
+    nvme_init_state(n);
+
+    if (nvme_init_blk(n, errp)) {
+        return;
+    }
+
+    nvme_init_pci(n, pci_dev);
+    nvme_init_ctrl(n, pci_dev);
+
     for (i = 0; i < n->num_namespaces; i++) {
         if (nvme_init_namespace(n, &n->namespaces[i], errp)) {
             return;