Commit ffe6370c9f2a596814bf14e472910fe6ef7e001d

Authored by Michael S. Tsirkin
Committed by Anthony Liguori
1 parent 566e2d3e

qemu/net: flag to control the number of vectors a nic has

Add an option to specify the number of MSI-X vectors for PCI NIC cards. This
can also be used to disable MSI-X, for compatibility with old qemu. This
option currently only affects virtio cards.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/virtio-net.c
... ... @@ -745,7 +745,10 @@ VirtIODevice *virtio_net_init(DeviceState *dev)
745 745 n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
746 746  
747 747 n->vlans = qemu_mallocz(MAX_VLAN >> 3);
748   - n->vdev.nvectors = 3;
  748 + if (dev->nd->nvectors == NIC_NVECTORS_UNSPECIFIED)
  749 + n->vdev.nvectors = 3;
  750 + else
  751 + n->vdev.nvectors = dev->nd->nvectors;
749 752  
750 753 register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
751 754 virtio_net_save, virtio_net_load, n);
... ...
... ... @@ -2169,7 +2169,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
2169 2169 }
2170 2170 if (!strcmp(device, "nic")) {
2171 2171 static const char * const nic_params[] = {
2172   - "vlan", "name", "macaddr", "model", "addr", NULL
  2172 + "vlan", "name", "macaddr", "model", "addr", "vectors", NULL
2173 2173 };
2174 2174 NICInfo *nd;
2175 2175 uint8_t *macaddr;
... ... @@ -2207,6 +2207,22 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
2207 2207 if (get_param_value(buf, sizeof(buf), "addr", p)) {
2208 2208 nd->devaddr = strdup(buf);
2209 2209 }
  2210 + nd->nvectors = NIC_NVECTORS_UNSPECIFIED;
  2211 + if (get_param_value(buf, sizeof(buf), "vectors", p)) {
  2212 + char *endptr;
  2213 + long vectors = strtol(buf, &endptr, 0);
  2214 + if (*endptr) {
  2215 + config_error(mon, "invalid syntax for # of vectors\n");
  2216 + ret = -1;
  2217 + goto out;
  2218 + }
  2219 + if (vectors < 0 || vectors > 0x7ffffff) {
  2220 + config_error(mon, "invalid # of vectors\n");
  2221 + ret = -1;
  2222 + goto out;
  2223 + }
  2224 + nd->nvectors = vectors;
  2225 + }
2210 2226 nd->vlan = vlan;
2211 2227 nd->name = name;
2212 2228 nd->used = 1;
... ...
... ... @@ -84,6 +84,9 @@ int do_set_link(Monitor *mon, const char *name, const char *up_or_down);
84 84 /* NIC info */
85 85  
86 86 #define MAX_NICS 8
  87 +enum {
  88 + NIC_NVECTORS_UNSPECIFIED = -1
  89 +};
87 90  
88 91 struct NICInfo {
89 92 uint8_t macaddr[6];
... ... @@ -94,6 +97,7 @@ struct NICInfo {
94 97 void *private;
95 98 int used;
96 99 int bootable;
  100 + int nvectors;
97 101 };
98 102  
99 103 extern int nb_nics;
... ...
qemu-options.hx
... ... @@ -736,7 +736,7 @@ STEXI
736 736 ETEXI
737 737  
738 738 DEF("net", HAS_ARG, QEMU_OPTION_net,
739   - "-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str]\n"
  739 + "-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n"
740 740 " create a new Network Interface Card and connect it to VLAN 'n'\n"
741 741 #ifdef CONFIG_SLIRP
742 742 "-net user[,vlan=n][,name=str][,hostname=host]\n"
... ... @@ -777,16 +777,18 @@ DEF(&quot;net&quot;, HAS_ARG, QEMU_OPTION_net,
777 777 "-net none use it alone to have zero network devices; if no -net option\n"
778 778 " is provided, the default is '-net nic -net user'\n")
779 779 STEXI
780   -@item -net nic[,vlan=@var{n}][,macaddr=@var{mac}][,model=@var{type}][,name=@var{name}][,addr=@var{addr}]
  780 +@item -net nic[,vlan=@var{n}][,macaddr=@var{mac}][,model=@var{type}][,name=@var{name}][,addr=@var{addr}][,vectors=@var{v}]
781 781 Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n}
782 782 = 0 is the default). The NIC is an ne2k_pci by default on the PC
783 783 target. Optionally, the MAC address can be changed to @var{mac}, the
784 784 device address set to @var{addr} (PCI cards only),
785   -and a @var{name} can be assigned for use in monitor commands. If no
786   -@option{-net} option is specified, a single NIC is created.
787   -Qemu can emulate several different models of network card.
  785 +and a @var{name} can be assigned for use in monitor commands.
  786 +Optionally, for PCI cards, you can specify the number @var{v} of MSI-X vectors
  787 +that the card should have; this option currently only affects virtio cards; set
  788 +@var{v} = 0 to disable MSI-X. If no @option{-net} option is specified, a single
  789 +NIC is created. Qemu can emulate several different models of network card.
788 790 Valid values for @var{type} are
789   -@code{i82551}, @code{i82557b}, @code{i82559er},
  791 +@code{virtio}, @code{i82551}, @code{i82557b}, @code{i82559er},
790 792 @code{ne2k_pci}, @code{ne2k_isa}, @code{pcnet}, @code{rtl8139},
791 793 @code{e1000}, @code{smc91c111}, @code{lance} and @code{mcf_fec}.
792 794 Not all devices are supported on all targets. Use -net nic,model=?
... ...