Skip to contentSkip to conversation

network: Added option to disable NIC option roms

PATCH In review Gerhard Wiesinger 4 participants 9 messages Jan 25, 2012 – Feb 16, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 network: Added option to disable NIC option roms

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

Examples with 2 NICs with disabled Option ROM (separated on different lines for readabi$ -device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,romfile=disabled
-net tap,ifname=tap0,script=no,downscript=no,vlan=0
-device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,romfile=disabled
-net tap,ifname=tap1,script=no,downscript=no,vlan=1

---
 hw/ne2000.c    |    2 +-
 hw/pci.c       |   39 ++++++++++++++++++++++++++++++++++++---
 hw/pci.h       |    7 +++++++
 hw/pcnet-pci.c |    2 +-
 4 files changed, 45 insertions(+), 5 deletions(-)
hw/ne2000.c +1 -1
index 62e082f..67bf458 100644
@@ -765,7 +765,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
-        if (!loaded) {
+        if (!loaded && pci_has_not_explicitly_disabled_option_romfile(pci_dev)) {
             rom_add_option("pxe-ne2k_pci.rom", -1);
             loaded = 1;
         }
hw/pci.c +36 -3
index c3082bc..a9e0758 100644
@@ -126,6 +126,41 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
     bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
 }
 
+static int pci_is_disabled_romfile_string(const char *s)
+{
+    if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE) == 0)
+        return 1;
+    if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE1) == 0)
+        return 1;
+    if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE2) == 0)
+        return 1;
+    return 0;
+}
+
+int pci_has_enabled_option_romfile(PCIDevice *pdev)
+{
+    PCI_DPRINTF("pci_has_enabled_option_romfile: device=%s, romfile=%s\n", pdev->name, pdev->romfile);
+    if (pdev->romfile == NULL)
+        return 0;
+    if (strlen(pdev->romfile) == 0)
+        return 0;
+    if (pci_is_disabled_romfile_string(pdev->romfile))
+        return 0;
+    return 1;
+}
+
+int pci_has_not_explicitly_disabled_option_romfile(PCIDevice *pdev)
+{
+    PCI_DPRINTF("pci_has_not_explicitly_disabled_option_romfile: device=%s, romfile=%s\n", pdev->name, pdev->romfile);
+
+    /* No romfile is present for hotplugged devices, therefore dynamic codes decides */
+    if (pdev->romfile == NULL)
+        return 1;
+    if (pci_is_disabled_romfile_string(pdev->romfile))
+        return 0;
+    return 1;
+}
+
 int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
 {
     assert(irq_num >= 0);
@@ -1725,9 +1760,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
     void *ptr;
     char name[32];
 
-    if (!pdev->romfile)
-        return 0;
-    if (strlen(pdev->romfile) == 0)
+    if (!pci_has_enabled_option_romfile(pdev))
         return 0;
 
     if (!pdev->rom_bar) {
hw/pci.h +7 -0
index 625e717..c5d071d 100644
@@ -78,6 +78,10 @@
 
 #define FMT_PCIBUS                      PRIx64
 
+#define PCI_DEVICE_DISABLED_OPTION_ROMFILE "disabled"
+#define PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE1 "none"
+#define PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE2 "no"
+
 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
                                 uint32_t address, uint32_t data, int len);
 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
@@ -275,6 +279,9 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
 
 void pci_device_deassert_intx(PCIDevice *dev);
 
+int pci_has_enabled_option_romfile(PCIDevice *pdev);
+int pci_has_not_explicitly_disabled_option_romfile(PCIDevice *pdev);
+
 static inline void
 pci_set_byte(uint8_t *config, uint8_t val)
 {
hw/pcnet-pci.c +1 -1
index 4e164da..e65745f 100644
@@ -332,7 +332,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
 
     if (!pci_dev->qdev.hotplugged) {
         static int loaded = 0;
-        if (!loaded) {
+        if (!loaded && pci_has_not_explicitly_disabled_option_romfile(pci_dev)) {
             rom_add_option("pxe-pcnet.rom", -1);
             loaded = 1;
         }
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Any way to fix "romfile="?

Quoted 7 lines

Examples with 2 NICs with disabled Option ROM (separated on different lines for readabi$

(quoted diff) +0 -4
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,romfile=disabled
-net tap,ifname=tap0,script=no,downscript=no,vlan=0
-device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,romfile=disabled
-net tap,ifname=tap1,script=no,downscript=no,vlan=1

I_do_not_usually_do_this_but_I_make_an_exception_due_to_your_choice_of_illegibly_long_identifiers:
CODING_STYLE, please feed to scripts/checkpatch.pl and correct :)

#2 lore raw
Quoted 11 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Any way to fix "romfile="?

Sure.

cheers,
Gerd

Quoted 1 line

From 4c17b5a36e6228536318e06a18a41166ff8356c5 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 26 Jan 2012 11:40:07 +0100
Subject: [PATCH] nic: zap obsolote romloading bits from ne2k + pcnet

These days one just needs to specify the romfile in PCiDeviceInfo and everything magically works. It also allows to disable pxe rom loading via "romfile=<emptystring>" like it is possible for all other nics.

---
 hw/ne2000.c    |    9 +--------
 hw/pcnet-pci.c |    9 +--------
 2 files changed, 2 insertions(+), 16 deletions(-)
hw/ne2000.c +1 -8
index 62e082f..83328bb 100644
@@ -763,14 +763,6 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
                           pci_dev->qdev.info->name, pci_dev->qdev.id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 
-    if (!pci_dev->qdev.hotplugged) {
-        static int loaded = 0;
-        if (!loaded) {
-            rom_add_option("pxe-ne2k_pci.rom", -1);
-            loaded = 1;
-        }
-    }
-
     add_boot_device_path(s->c.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
 
     return 0;
@@ -792,6 +784,7 @@ static PCIDeviceInfo ne2000_info = {
     .qdev.vmsd  = &vmstate_pci_ne2000,
     .init       = pci_ne2000_init,
     .exit       = pci_ne2000_exit,
+    .romfile    = "pxe-ne2k_pci.rom",
     .vendor_id  = PCI_VENDOR_ID_REALTEK,
     .device_id  = PCI_DEVICE_ID_REALTEK_8029,
     .class_id   = PCI_CLASS_NETWORK_ETHERNET,
hw/pcnet-pci.c +1 -8
index 4e164da..2f333e2 100644
@@ -330,14 +330,6 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_write = pci_physical_memory_write;
     s->dma_opaque = pci_dev;
 
-    if (!pci_dev->qdev.hotplugged) {
-        static int loaded = 0;
-        if (!loaded) {
-            rom_add_option("pxe-pcnet.rom", -1);
-            loaded = 1;
-        }
-    }
-
     return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info);
 }
 
@@ -355,6 +347,7 @@ static PCIDeviceInfo pcnet_info = {
     .qdev.vmsd  = &vmstate_pci_pcnet,
     .init       = pci_pcnet_init,
     .exit       = pci_pcnet_uninit,
+    .romfile    = "pxe-pcnet.rom",
     .vendor_id  = PCI_VENDOR_ID_AMD,
     .device_id  = PCI_DEVICE_ID_AMD_LANCE,
     .revision   = 0x10,
Signature · 1 line
1.7.1
#3 lore raw
Quoted 9 lines · Gerd Hoffmann
Quoted 8 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

Quoted 5 lines
Quoted 3 lines

And now filenames "disabled", "no" and "none" don't work.

Any way to fix "romfile="?

Sure.

This patch looks much better. Gerhard does it solve your problem? Gerd, you might want to repost it in its own thread, as maintainers can easily miss patches buried deep in replies.

#4 lore raw
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any way to fix "romfile="?

Sure.

This patch looks much better. Gerhard does it solve your problem? Gerd, you might want to repost it in its own thread, as maintainers can easily miss patches buried deep in replies.

Patch looks good to me, it just initializes like all other devices.

But I still have to test it. Hopefully today in the evening or tomorrow.

Ciao,
Gerhard

--
http://www.wiesinger.com/

#5 lore raw
In reply to Markus Armbruster
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any way to fix "romfile="?

Sure.

This patch looks much better. Gerhard does it solve your problem? Gerd, you might want to repost it in its own thread, as maintainers can easily miss patches buried deep in replies.

Can confirm this patch works well in all tried combinations.

3 Comments:
1.) NOK?: 2 NICs installed, no bootindex specified: Tries to boot only from one NIC, then from C: (one NIC has index first, second one has last index) -boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0 -net tap,ifname=tap0,script=no,downscript=no,vlan=0
-device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
I would expect to try to boot from both NICs
1. iPXE (PCI 00:04:0)
...
8. iPXE (PCI 00:05:0)

2.) OK: 2 NICs installed, bootindex specified: Tries to boot from first and second NIC -boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=1 -net tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=2 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:04:0)
2. iPXE (PCI 00:05:0)
...

3.) NOK: 2 NICs installed, bootindex specified in reverse order: Tries to boot from 7e NIC and reboots ... -boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=2 -net tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=1 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:05:0)
2. iPXE (PCI 00:04:0)
...

Ciao,
Gerhard

--
http://www.wiesinger.com/

#6 lore raw
Quoted 50 lines · Gerhard Wiesinger
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any way to fix "romfile="?

Sure.

This patch looks much better. Gerhard does it solve your problem? Gerd, you might want to repost it in its own thread, as maintainers can easily miss patches buried deep in replies.

Can confirm this patch works well in all tried combinations.

3 Comments:
1.) NOK?: 2 NICs installed, no bootindex specified: Tries to boot only from one NIC, then from C: (one NIC has index first, second one has last index)

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0 -net 

tap,ifname=tap0,script=no,downscript=no,vlan=0
-device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1 -net
tap,ifname=tap1,script=no,downscript=no,vlan=1
I would expect to try to boot from both NICs
1. iPXE (PCI 00:04:0)
...
8. iPXE (PCI 00:05:0)

2.) OK: 2 NICs installed, bootindex specified: Tries to boot from first and second NIC

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=1 -net 

tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=2 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:04:0)
2. iPXE (PCI 00:05:0)
...

3.) NOK: 2 NICs installed, bootindex specified in reverse order: Tries to boot from 7e NIC and reboots ...

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=2 -net 
Quoted 6 lines

tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=1 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:05:0)
2. iPXE (PCI 00:04:0)
...

Still waiting for commit ...

Ciao,
Gerhard

--
http://www.wiesinger.com/

#7 lore raw
Quoted 61 lines · Gerhard Wiesinger
Quoted 50 lines · Gerhard Wiesinger
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

And now filenames "disabled", "no" and "none" don't work.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any way to fix "romfile="?

Sure.

This patch looks much better. Gerhard does it solve your problem? Gerd, you might want to repost it in its own thread, as maintainers can easily miss patches buried deep in replies.

Can confirm this patch works well in all tried combinations.

3 Comments:
1.) NOK?: 2 NICs installed, no bootindex specified: Tries to boot only from one NIC, then from C: (one NIC has index first, second one has last index)

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0 -net 

tap,ifname=tap0,script=no,downscript=no,vlan=0
-device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1 -net
tap,ifname=tap1,script=no,downscript=no,vlan=1
I would expect to try to boot from both NICs
1. iPXE (PCI 00:04:0)
...
8. iPXE (PCI 00:05:0)

2.) OK: 2 NICs installed, bootindex specified: Tries to boot from first and second NIC

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=1 -net 

tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=2 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:04:0)
2. iPXE (PCI 00:05:0)
...

3.) NOK: 2 NICs installed, bootindex specified in reverse order: Tries to boot from 7e NIC and reboots ...

(quoted diff) +0 -2
-boot order=nca,menu=on
-device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,bootindex=2 -net 
Quoted 6 lines

tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,bootindex=1 -net tap,ifname=tap1,script=no,downscript=no,vlan=1
1. iPXE (PCI 00:05:0)
2. iPXE (PCI 00:04:0)
...

Still waiting for commit ...

Quoted 2 lines

Ciao,
Gerhard

Still waiting for commit ...

Ciao,
Gerhard

--
http://www.wiesinger.com/

#8 lore raw
In reply to Gerd Hoffmann
Quoted 9 lines · Gerd Hoffmann
Quoted 8 lines · Markus Armbruster
Quoted 5 lines · Gerhard Wiesinger

Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable).

Quoted 5 lines
Quoted 3 lines

And now filenames "disabled", "no" and "none" don't work.

Any way to fix "romfile="?

Sure.

Care to submit as a proper patch?

Regards,

Anthony Liguori

Quoted 3 lines

cheers,
Gerd