qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] network: Added option to disable NIC option roms
@ 2012-01-08 11:55 Gerhard Wiesinger
  2012-01-08 16:40 ` Stefan Hajnoczi
  2012-01-09  9:15 ` Gerd Hoffmann
  0 siblings, 2 replies; 17+ messages in thread
From: Gerhard Wiesinger @ 2012-01-08 11:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin O'Connor, Gerd Hoffmann, Gleb Natapov

Option ROM for network interface cards (NICs) can now explicitly disabled
with romfile=disabled 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 readability):
-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

Signed-off-by: Gerhard Wiesinger <lists@wiesinger.com>
---
  hw/ne2000.c    |    2 +-
  hw/pci.c       |   28 +++++++++++++++++++++++++---
  hw/pci.h       |    5 +++++
  hw/pcnet-pci.c |    2 +-
  4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/hw/ne2000.c b/hw/ne2000.c
index 62e082f..67bf458 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -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;
          }
diff --git a/hw/pci.c b/hw/pci.c
index c3082bc..fbce1a7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -126,6 +126,30 @@ 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);
  }

+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 (strcmp(pdev->romfile, PCI_DEVICE_DISABLED_OPTION_ROMFILE) == 0)
+        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 (strcmp(pdev->romfile, PCI_DEVICE_DISABLED_OPTION_ROMFILE) == 0)
+        return 0;
+    return 1;
+}
+
  int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
  {
      assert(irq_num >= 0);
@@ -1725,9 +1749,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) {
diff --git a/hw/pci.h b/hw/pci.h
index 625e717..5146bba 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -78,6 +78,8 @@

  #define FMT_PCIBUS                      PRIx64

+#define PCI_DEVICE_DISABLED_OPTION_ROMFILE "disabled"
+
  typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
                                  uint32_t address, uint32_t data, int len);
  typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
@@ -275,6 +277,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)
  {
diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c
index 4e164da..e65745f 100644
--- a/hw/pcnet-pci.c
+++ b/hw/pcnet-pci.c
@@ -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;
          }
-- 
1.7.6.5

^ permalink raw reply related	[flat|nested] 17+ messages in thread
* [Qemu-devel] [PATCH] network: Added option to disable NIC option roms
@ 2012-01-25 21:01 Gerhard Wiesinger
  2012-01-26  7:45 ` Markus Armbruster
  0 siblings, 1 reply; 17+ messages in thread
From: Gerhard Wiesinger @ 2012-01-25 21:01 UTC (permalink / raw)
  To: qemu-devel

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

Signed-off-by: Gerhard Wiesinger <lists@wiesinger.com>
---
  hw/ne2000.c    |    2 +-
  hw/pci.c       |   39 ++++++++++++++++++++++++++++++++++++---
  hw/pci.h       |    7 +++++++
  hw/pcnet-pci.c |    2 +-
  4 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/hw/ne2000.c b/hw/ne2000.c
index 62e082f..67bf458 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -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;
          }
diff --git a/hw/pci.c b/hw/pci.c
index c3082bc..a9e0758 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -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) {
diff --git a/hw/pci.h b/hw/pci.h
index 625e717..c5d071d 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -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)
  {
diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c
index 4e164da..e65745f 100644
--- a/hw/pcnet-pci.c
+++ b/hw/pcnet-pci.c
@@ -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;
          }
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-02-16  6:43 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-08 11:55 [Qemu-devel] [PATCH] network: Added option to disable NIC option roms Gerhard Wiesinger
2012-01-08 16:40 ` Stefan Hajnoczi
2012-01-08 20:56   ` Gerhard Wiesinger
2012-01-09  8:06     ` Stefan Hajnoczi
2012-01-09  9:15 ` Gerd Hoffmann
2012-01-12  6:45   ` Gerhard Wiesinger
2012-01-12  7:58     ` Gerd Hoffmann
2012-01-25 21:08       ` Gerhard Wiesinger
  -- strict thread matches above, loose matches on Subject: below --
2012-01-25 21:01 Gerhard Wiesinger
2012-01-26  7:45 ` Markus Armbruster
2012-01-26 10:45   ` Gerd Hoffmann
2012-01-26 11:00     ` Markus Armbruster
2012-01-27  6:56       ` Gerhard Wiesinger
2012-01-27 16:02       ` Gerhard Wiesinger
2012-02-13  6:23         ` Gerhard Wiesinger
2012-02-16  6:41           ` Gerhard Wiesinger
2012-02-01 22:19     ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).