[PATCH v2 9/9] hw/riscv: Add a network device e1000e to the boston-aia

Djordje Todorovic posted 9 patches 5 months, 2 weeks ago
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
There is a newer version of this series
[PATCH v2 9/9] hw/riscv: Add a network device e1000e to the boston-aia
Posted by Djordje Todorovic 5 months, 2 weeks ago
Add a network device e1000e to the boston-aia board model.
There is no pch_gbe emulation, so we add e1000e in slot 0 func 1,
instead. We need to pass func to call pci_parse_devaddr to find
out slot and func.

Signed-off-by: Chao-ying Fu <cfu@mips.com>
Signed-off-by: Djordje Todorovic <djordje.todorovic@htecgroup.com>
---
 hw/pci/pci.c          | 15 +++++++++------
 hw/riscv/boston-aia.c |  5 +++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index f5ab510697..23f7f02837 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -974,14 +974,15 @@ static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
 
     slot = val;
 
-    if (funcp != NULL) {
-        if (*e != '.')
+    if (funcp != NULL && *e != 0) {
+        if (*e != '.') {
             return -1;
-
+        }
         p = e + 1;
         val = strtoul(p, &e, 16);
-        if (e == p)
+        if (e == p) {
             return -1;
+        }
 
         func = val;
     }
@@ -2045,13 +2046,15 @@ bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model,
     int dom, busnr, devfn;
     PCIDevice *pci_dev;
     unsigned slot;
+
     PCIBus *bus;
 
     if (!nd) {
         return false;
     }
 
-    if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, NULL) < 0) {
+    unsigned func;
+    if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, &func) < 0) {
         error_report("Invalid PCI device address %s for device %s",
                      devaddr, model);
         exit(1);
@@ -2062,7 +2065,7 @@ bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model,
         exit(1);
     }
 
-    devfn = PCI_DEVFN(slot, 0);
+    devfn = PCI_DEVFN(slot, func);
 
     bus = pci_find_bus_nr(rootbus, busnr);
     if (!bus) {
diff --git a/hw/riscv/boston-aia.c b/hw/riscv/boston-aia.c
index 6ed5c636cc..34cc0abe79 100644
--- a/hw/riscv/boston-aia.c
+++ b/hw/riscv/boston-aia.c
@@ -437,6 +437,11 @@ static void boston_mach_init(MachineState *machine)
     ide_drive_get(hd, ich9->ahci.ports);
     ahci_ide_create_devs(&ich9->ahci, hd);
 
+    /* Create e1000e using slot 0 func 1 */
+    pci_init_nic_in_slot(&PCI_BRIDGE(&pcie2->root)->sec_bus, "e1000e", NULL,
+                         "00.1");
+    pci_init_nic_devices(&PCI_BRIDGE(&pcie2->root)->sec_bus, "e1000e");
+
     if (machine->firmware) {
         fw_size = load_image_targphys(machine->firmware,
                                       0x1fc00000, 4 * MiB);
-- 
2.34.1
Re: [PATCH v2 9/9] hw/riscv: Add a network device e1000e to the boston-aia
Posted by Alistair Francis 5 months, 1 week ago
On Mon, Jun 2, 2025 at 11:13 PM Djordje Todorovic
<Djordje.Todorovic@htecgroup.com> wrote:
>
> Add a network device e1000e to the boston-aia board model.
> There is no pch_gbe emulation, so we add e1000e in slot 0 func 1,
> instead. We need to pass func to call pci_parse_devaddr to find
> out slot and func.
>
> Signed-off-by: Chao-ying Fu <cfu@mips.com>
> Signed-off-by: Djordje Todorovic <djordje.todorovic@htecgroup.com>
> ---
>  hw/pci/pci.c          | 15 +++++++++------
>  hw/riscv/boston-aia.c |  5 +++++
>  2 files changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index f5ab510697..23f7f02837 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -974,14 +974,15 @@ static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
>
>      slot = val;
>
> -    if (funcp != NULL) {
> -        if (*e != '.')
> +    if (funcp != NULL && *e != 0) {
> +        if (*e != '.') {
>              return -1;
> -
> +        }
>          p = e + 1;
>          val = strtoul(p, &e, 16);
> -        if (e == p)
> +        if (e == p) {
>              return -1;
> +        }
>
>          func = val;
>      }
> @@ -2045,13 +2046,15 @@ bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model,
>      int dom, busnr, devfn;
>      PCIDevice *pci_dev;
>      unsigned slot;
> +
>      PCIBus *bus;
>
>      if (!nd) {
>          return false;
>      }
>
> -    if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, NULL) < 0) {
> +    unsigned func;
> +    if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, &func) < 0) {
>          error_report("Invalid PCI device address %s for device %s",
>                       devaddr, model);
>          exit(1);
> @@ -2062,7 +2065,7 @@ bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model,
>          exit(1);
>      }
>
> -    devfn = PCI_DEVFN(slot, 0);
> +    devfn = PCI_DEVFN(slot, func);

These core pci changes should be split out into their own patch and
will need a bit more justification

Alistair

>
>      bus = pci_find_bus_nr(rootbus, busnr);
>      if (!bus) {
> diff --git a/hw/riscv/boston-aia.c b/hw/riscv/boston-aia.c
> index 6ed5c636cc..34cc0abe79 100644
> --- a/hw/riscv/boston-aia.c
> +++ b/hw/riscv/boston-aia.c
> @@ -437,6 +437,11 @@ static void boston_mach_init(MachineState *machine)
>      ide_drive_get(hd, ich9->ahci.ports);
>      ahci_ide_create_devs(&ich9->ahci, hd);
>
> +    /* Create e1000e using slot 0 func 1 */
> +    pci_init_nic_in_slot(&PCI_BRIDGE(&pcie2->root)->sec_bus, "e1000e", NULL,
> +                         "00.1");
> +    pci_init_nic_devices(&PCI_BRIDGE(&pcie2->root)->sec_bus, "e1000e");
> +
>      if (machine->firmware) {
>          fw_size = load_image_targphys(machine->firmware,
>                                        0x1fc00000, 4 * MiB);
> --
> 2.34.1
>