[6216] Add a model string to VLANClientState (Mark McLoughlin)
Revision: 6216
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6216 Author: aliguori Date: 2009-01-07 17:42:25 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
Add a model string to VLANClientState (Mark McLoughlin)
Don't lose track of what type/model a vlan client is so that we can e.g. assign a global per-model id to clients.
The entire patch is basically a tedious excercise in making sure the type/model string gets propagated down to qemu_new_vlan_client().
Modified Paths:
--------------
trunk/hw/e1000.c
trunk/hw/eepro100.c
trunk/hw/etraxfs_eth.c
trunk/hw/mcf_fec.c
trunk/hw/mipsnet.c
trunk/hw/musicpal.c
trunk/hw/ne2000.c
trunk/hw/pcnet.c
trunk/hw/rtl8139.c
trunk/hw/smc91c111.c
trunk/hw/stellaris_enet.c
trunk/hw/usb-net.c
trunk/hw/virtio-net.c
trunk/net.c
trunk/net.h
trunk/sysemu.h
trunk/tap-win32.cModified: trunk/hw/e1000.c
===================================================================
hw/e1000.c +2 -2
@@ -1071,8 +1071,8 @@ d->rxbuf_min_shift =1 ;memset (&d->tx,0 ,sizeof d->tx); - d->vc =qemu_new_vlan_client (nd->vlan, e1000_receive, - e1000_can_receive, d); + d->vc =qemu_new_vlan_client (nd->vlan, nd->model, + e1000_receive, e1000_can_receive, d); snprintf(d->vc->info_str, sizeof(d->vc->info_str), "%s macaddr=%02x:%02x:%02x:%02x:%02x:%02x", info_str,
Modified: trunk/hw/eepro100.c
===================================================================
hw/eepro100.c +2 -1
@@ -1776,7 +1776,8 @@nic_reset (s); - s->vc =qemu_new_vlan_client (nd->vlan, nic_receive, nic_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + nic_receive, nic_can_receive, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "eepro100 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
Modified: trunk/hw/etraxfs_eth.c
===================================================================
hw/etraxfs_eth.c +1 -1
@@ -572,7 +572,7 @@ eth->ethregs =cpu_register_io_memory (0 , eth_read, eth_write, eth);cpu_register_physical_memory (base,0x5c , eth->ethregs); - eth->vc =qemu_new_vlan_client (nd->vlan, + eth->vc =qemu_new_vlan_client (nd->vlan, nd->model, eth_receive, eth_can_receive, eth);return dma;
Modified: trunk/hw/mcf_fec.c
===================================================================
hw/mcf_fec.c +2 -2
@@ -452,7 +452,7 @@ mcf_fec_writefn, s);cpu_register_physical_memory (base,0x400 , iomemtype); - s->vc =qemu_new_vlan_client (nd->vlan, mcf_fec_receive, - mcf_fec_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + mcf_fec_receive, mcf_fec_can_receive, s);memcpy (s->macaddr, nd->macaddr,6 ); }
Modified: trunk/hw/mipsnet.c
===================================================================
hw/mipsnet.c +2 -2
@@ -250,8 +250,8 @@ s->irq = irq; s->nd = nd;if (nd && nd->vlan) { - s->vc =qemu_new_vlan_client (nd->vlan, mipsnet_receive, - mipsnet_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + mipsnet_receive, mipsnet_can_receive, s); }else { s->vc =NULL ; }
Modified: trunk/hw/musicpal.c
===================================================================
hw/musicpal.c +2 -1
@@ -718,7 +718,8 @@if (!s)return ; s->irq = irq; - s->vc =qemu_new_vlan_client (nd->vlan, eth_receive, eth_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + eth_receive, eth_can_receive, s); iomemtype =cpu_register_io_memory (0 , mv88w8618_eth_readfn, mv88w8618_eth_writefn, s);cpu_register_physical_memory (base,MP_ETH_SIZE , iomemtype);
Modified: trunk/hw/ne2000.c
===================================================================
hw/ne2000.c +4 -4
@@ -741,8 +741,8 @@ne2000_reset (s); - s->vc =qemu_new_vlan_client (nd->vlan, ne2000_receive, - ne2000_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + ne2000_receive, ne2000_can_receive, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
@@ -811,8 +811,8 @@ s->pci_dev = (PCIDevice *)d;memcpy (s->macaddr, nd->macaddr,6 );ne2000_reset (s); - s->vc =qemu_new_vlan_client (nd->vlan, ne2000_receive, - ne2000_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + ne2000_receive, ne2000_can_receive, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
Modified: trunk/hw/pcnet.c
===================================================================
hw/pcnet.c +2 -2
@@ -1936,8 +1936,8 @@ d->nd = nd;if (nd && nd->vlan) { - d->vc =qemu_new_vlan_client (nd->vlan, pcnet_receive, - pcnet_can_receive, d); + d->vc =qemu_new_vlan_client (nd->vlan, nd->model, + pcnet_receive, pcnet_can_receive, d); snprintf(d->vc->info_str, sizeof(d->vc->info_str), "pcnet macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
Modified: trunk/hw/rtl8139.c
===================================================================
hw/rtl8139.c +2 -2
@@ -3438,8 +3438,8 @@ s->pci_dev = (PCIDevice *)d;memcpy (s->macaddr, nd->macaddr,6 );rtl8139_reset (s); - s->vc =qemu_new_vlan_client (nd->vlan, rtl8139_receive, - rtl8139_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + rtl8139_receive, rtl8139_can_receive, s); snprintf(s->vc->info_str, sizeof(s->vc->info_str), "rtl8139 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
Modified: trunk/hw/smc91c111.c
===================================================================
hw/smc91c111.c +2 -2
@@ -704,7 +704,7 @@smc91c111_reset (s); - s->vc =qemu_new_vlan_client (nd->vlan, smc91c111_receive, - smc91c111_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + smc91c111_receive, smc91c111_can_receive, s);/* ??? Save/restore. */ }
Modified: trunk/hw/stellaris_enet.c
===================================================================
hw/stellaris_enet.c +2 -2
@@ -397,8 +397,8 @@memcpy (s->macaddr, nd->macaddr,6 );if (nd->vlan) - s->vc =qemu_new_vlan_client (nd->vlan, stellaris_enet_receive, - stellaris_enet_can_receive, s); + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, + stellaris_enet_receive, stellaris_enet_can_receive, s);stellaris_enet_reset (s); register_savevm("stellaris_enet", -1, 1,
Modified: trunk/hw/usb-net.c
===================================================================
hw/usb-net.c +1 -1
@@ -1453,7 +1453,7 @@pstrcpy (s->dev.devname,sizeof (s->dev.devname),"QEMU USB Network Interface" ); - s->vc =qemu_new_vlan_client (nd->vlan, + s->vc =qemu_new_vlan_client (nd->vlan, nd->model, usbnet_receive, usbnet_can_receive, s); snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
Modified: trunk/hw/virtio-net.c
===================================================================
hw/virtio-net.c +2 -2
@@ -315,8 +315,8 @@ n->rx_vq =virtio_add_queue (&n->vdev,256 , virtio_net_handle_rx); n->tx_vq =virtio_add_queue (&n->vdev,256 , virtio_net_handle_tx);memcpy (n->mac, nd->macaddr,6 ); - n->vc =qemu_new_vlan_client (nd->vlan, virtio_net_receive, - virtio_net_can_receive, n); + n->vc =qemu_new_vlan_client (nd->vlan, nd->model, + virtio_net_receive, virtio_net_can_receive, n); n->tx_timer =qemu_new_timer (vm_clock, virtio_net_tx_timer, n); n->tx_timer_active =0 ;
Modified: trunk/net.c
===================================================================
net.c +43 -35
270 lines not on this page · raw message
Modified: trunk/net.h
===================================================================
net.h +2 -0
@@ -18,6 +18,7 @@void *opaque;struct VLANClientState *next;struct VLANState *vlan; +char *model;char info_str[256 ]; };
@@ -30,6 +31,7 @@VLANState *qemu_find_vlan (int id);VLANClientState *qemu_new_vlan_client (VLANState *vlan, +const char *model,IOReadHandler *fd_read,IOCanRWHandler *fd_can_read,void *opaque);
Modified: trunk/sysemu.h
===================================================================
sysemu.h +1 -1
@@ -75,7 +75,7 @@#endif /* TAP win32 */ -int tap_win32_init (VLANState *vlan,const char *ifname); +int tap_win32_init (VLANState *vlan,const char *model,const char *ifname);/* SLIRP */ void do_info_slirp (void );
Modified: trunk/tap-win32.c
===================================================================
tap-win32.c +2 -2
@@ -660,7 +660,7 @@ } } -int tap_win32_init (VLANState *vlan,const char *ifname) +int tap_win32_init (VLANState *vlan,const char *model,const char *ifname) {TAPState *s;
@@ -672,7 +672,7 @@return -1 ; } - s->vc =qemu_new_vlan_client (vlan, tap_receive,NULL , s); + s->vc =qemu_new_vlan_client (vlan, model, tap_receive,NULL , s);snprintf (s->vc->info_str,sizeof (s->vc->info_str),"tap: ifname=%s" , ifname);
Quoted 51 lines · Anthony Liguori
Revision: 6216
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6216 Author: aliguori Date: 2009-01-07 17:42:25 +0000 (Wed, 07 Jan 2009)Log Message:
-----------
Add a model string to VLANClientState (Mark McLoughlin)Don't lose track of what type/model a vlan client is so that we can e.g. assign a global per-model id to clients.
The entire patch is basically a tedious excercise in making sure the type/model string gets propagated down to
qemu_new_vlan_client().Signed-off-by Mark McLoughlin <[email protected]>Signed-off-by Anthony Liguori <[email protected]>Modified Paths:
--------------trunk/hw/e1000.c trunk/hw/eepro100.c trunk/hw/etraxfs_eth.c trunk/hw/mcf_fec.c trunk/hw/mipsnet.c trunk/hw/musicpal.c trunk/hw/ne2000.c trunk/hw/pcnet.c trunk/hw/rtl8139.c trunk/hw/smc91c111.c trunk/hw/stellaris_enet.c trunk/hw/usb-net.c trunk/hw/virtio-net.c trunk/net.c trunk/net.h trunk/sysemu.h trunk/tap-win32.cModified:
trunk/net.c
===================================================================net.c +1
-0@@ -297,6 +297,7 @@#endif VLANClientState *qemu_new_vlan_client (VLANState *vlan, +const char *model,IOReadHandler *fd_read,IOCanRWHandler *fd_can_read,void *opaque)
net.c line 310
Quoted 5 lines
net.c +1
-0@@ -305,6 +306,7 @@ vc =qemu_mallocz (sizeof (VLANClientState));if (!vc)return NULL ; + vc->model =strdup (model);
Some targets don't force a value for model, so it can be NULL. This raises a SIGSEGV crash. Should targets set model, or is it better to catch this case here?
net.c line 333
Quoted 13 lines
net.c +0
-0vc->fd_read = fd_read; vc->fd_can_read = fd_can_read;vc->opaque = opaque;net.c +1
-0@@ -325,6 +327,7 @@while (*pvc !=NULL )if (*pvc == vc) { *pvc = vc->next; +free (vc->model);free (vc);break ; }else
Regards
Stefan Weil
Quoted 18 lines · Stefan Weil
Quoted 17 lines · Anthony Liguori
Revision: 6216
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6216 Author: aliguori Date: 2009-01-07 17:42:25 +0000 (Wed, 07 Jan 2009)Log Message:
-----------
Add a model string to VLANClientState (Mark McLoughlin)Don't lose track of what type/model a vlan client is so that we can e.g. assign a global per-model id to clients.
The entire patch is basically a tedious excercise in making sure the type/model string gets propagated down to
qemu_new_vlan_client().Signed-off-by Mark McLoughlin <[email protected]>Signed-off-by Anthony Liguori <[email protected]>
...
Quoted 7 lines
Quoted 7 lines
Modified:
trunk/net.c
===================================================================net.c +0
-0@@ -297,6 +297,7 @@#endif
Quoted 15 lines
net.c line 310
Quoted 11 lines
net.c +2
-0VLANClientState *qemu_new_vlan_client (VLANState *vlan, +const char *model,IOReadHandler *fd_read,IOCanRWHandler *fd_can_read,void *opaque)@@ -305,6 +306,7 @@ vc =qemu_mallocz (sizeof (VLANClientState));if (!vc)return NULL ; + vc->model =strdup (model);Some targets don't force a value for model, so it can be NULL. This raises a SIGSEGV crash. Should targets set model, or is it better to catch this case here?
Ouch.
It'd be much nicer to make sure we always get a model string here rather than having names default to e.g. "nic.1".
So, I went and fixed up all the targets to make sure that nd->model is always set.
That sucked, though, so I went through a couple of iterations of cleaning all this stuff up and settled on the patches that follow this mail.
Cheers,
Mark.
PATCH 1/4 Add qemu_check_nic_model() and qemu_check_nic_model_list()
--- net.c | 34 ++++++++++++++++++++++++++++++++++ net.h | 3 +++ 2 files changed, 37 insertions(+), 0 deletions(-)
net.c +34 -0
@@ -1491,6 +1491,40 @@ VLANState *qemu_find_vlan(int id)return vlan; } +void qemu_check_nic_model (NICInfo *nd,const char *model) +{ +const char *models[2 ]; + + models[0 ] = model; + models[1 ] =NULL ; + +qemu_check_nic_model_list (nd, models, model); +} + +void qemu_check_nic_model_list (NICInfo *nd,const char *const *models, +const char *default_model) +{ +int i, exit_status =0 ; + +if (!nd->model) + nd->model =strdup (default_model); + +if (strcmp (nd->model,"?" ) !=0 ) { +for (i =0 ; models[i]; i++) +if (strcmp (nd->model, models[i]) ==0 ) +return ; + +fprintf (stderr,"qemu: Unsupported NIC model: %s\n" , nd->model); + exit_status =1 ; + } + +fprintf (stderr,"qemu: Supported NIC models: " ); +for (i =0 ; models[i]; i++) +fprintf (stderr,"%s%c" , models[i], models[i+1 ] ?',' :'\n' ); + +exit (exit_status); +} +int net_client_init (const char *device,const char *p) {char buf[1024 ];
net.h +3 -0
@@ -43,6 +43,9 @@ ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt);void qemu_send_packet (VLANClientState *vc,const uint8_t *buf,int size);void qemu_format_nic_info_str (VLANClientState *vc,uint8_t macaddr[6 ]); +void qemu_check_nic_model (NICInfo *nd,const char *model); +void qemu_check_nic_model_list (NICInfo *nd,const char *const *models, +const char *default_model);void qemu_handler_true (void *opaque);void do_info_network (void );
Signature · 1 line
1.6.0.6
PATCH 2/4 Check NIC model in some NIC init functions
Some NIC init functions are only called when that model is the only valid model. In that case, it makes sense to use qemu_check_nic_model() from the NIC init function itself.
--- hw/axis_dev88.c | 5 +---- hw/etraxfs.c | 5 +---- hw/etraxfs_eth.c | 2 ++ hw/integratorcp.c | 14 ++------------ hw/mcf5208.c | 14 ++------------ hw/mcf_fec.c | 2 ++ hw/mips_mipssim.c | 16 +++------------- hw/mips_r4k.c | 14 ++------------ hw/mipsnet.c | 2 ++ hw/musicpal.c | 2 ++ hw/ne2000.c | 2 ++ hw/pcnet.c | 2 ++ hw/realview.c | 8 +++++--- hw/smc91c111.c | 2 ++ hw/stellaris.c | 4 +--- hw/stellaris_enet.c | 2 ++ hw/sun4m.c | 33 +++------------------------------ hw/versatilepb.c | 8 +++++--- 18 files changed, 41 insertions(+), 96 deletions(-)
hw/axis_dev88.c +1 -4
@@ -303,12 +303,9 @@ void axisdev88_init (ram_addr_t ram_size, int vga_ram_size, }/* Add the two ethernet blocks. */ - nd_table[0 ].model = nd_table[0 ].model ? nd_table[0 ].model :"fseth" ; eth[0 ] =etraxfs_eth_init (&nd_table[0 ], env, pic->irq +25 ,0x30034000 ); -if (nb_nics >1 ) { - nd_table[1 ].model = nd_table[1 ].model ? nd_table[1 ].model :"fseth" ; +if (nb_nics >1 ) eth[1 ] =etraxfs_eth_init (&nd_table[1 ], env, pic->irq +26 ,0x30036000 ); - }/* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client (etraxfs_dmac,0 , eth[0 ]);
hw/etraxfs.c +1 -4
@@ -94,12 +94,9 @@ void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size, }/* Add the two ethernet blocks. */ - nd_table[0 ].model = nd_table[0 ].model ? nd_table[0 ].model :"fseth" ; eth[0 ] =etraxfs_eth_init (&nd_table[0 ], env, pic->irq +25 ,0x30034000 ); -if (nb_nics >1 ) { - nd_table[1 ].model = nd_table[1 ].model ? nd_table[1 ].model :"fseth" ; +if (nb_nics >1 ) eth[1 ] =etraxfs_eth_init (&nd_table[1 ], env, pic->irq +26 ,0x30036000 ); - }/* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client (etraxfs_dmac,0 , eth[0 ]);
hw/etraxfs_eth.c +2 -0
@@ -546,6 +546,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,struct etraxfs_dma_client *dma =NULL ;struct fs_eth *eth =NULL ; +qemu_check_nic_model (nd,"fseth" ); + dma =qemu_mallocz (sizeof *dma *2 );if (!dma)return NULL ;
hw/integratorcp.c +2 -12
@@ -497,18 +497,8 @@ static void integratorcp_init(ram_addr_t ram_size, int vga_ram_size,exit (1 ); }pl181_init (0x1c000000 , drives_table[sd].bdrv, pic[23 ], pic[24 ]); -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"smc91c111" ) ==0 ) { -smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: smc91c111\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]);pl110_init (ds,0xc0000000 , pic[22 ],0 ); integrator_binfo.ram_size = ram_size;
hw/mcf5208.c +2 -12
@@ -241,18 +241,8 @@ static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size,fprintf (stderr,"Too many NICs\n" );exit (1 ); } -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"mcf_fec" ) ==0 ) { -mcf_fec_init (&nd_table[0 ],0xfc030000 , pic +36 ); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: mcf_fec\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +mcf_fec_init (&nd_table[0 ],0xfc030000 , pic +36 );/* 0xfc000000 SCM. */ /* 0xfc004000 XBS. */
hw/mcf_fec.c +2 -0
@@ -446,6 +446,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)mcf_fec_state *s;int iomemtype; +qemu_check_nic_model (nd,"mcf_fec" ); + s = (mcf_fec_state *)qemu_mallocz (sizeof (mcf_fec_state)); s->irq = irq; iomemtype = cpu_register_io_memory(0, mcf_fec_readfn,
hw/mips_mipssim.c +3 -13
@@ -175,19 +175,9 @@ mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size,if (serial_hds[0 ])serial_init (0x3f8 , env->irq[4 ],115200 , serial_hds[0 ]); -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"mipsnet" ) ==0 ) { -/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ -mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: mipsnet\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ +mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); }QEMUMachine mips_mipssim_machine = {
hw/mips_r4k.c +2 -12
@@ -247,18 +247,8 @@ void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size,isa_vga_init (ds, phys_ram_base + ram_size, ram_size, vga_ram_size); -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"ne2k_isa" ) ==0 ) { -isa_ne2000_init (0x300 , i8259[9 ], &nd_table[0 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: ne2k_isa\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +isa_ne2000_init (0x300 , i8259[9 ], &nd_table[0 ]);if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );
hw/mipsnet.c +2 -0
@@ -236,6 +236,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) {MIPSnetState *s; +qemu_check_nic_model (nd,"mipsnet" ); + s =qemu_mallocz (sizeof (MIPSnetState));if (!s)return ;
hw/musicpal.c +2 -0
@@ -714,6 +714,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)mv88w8618_eth_state *s;int iomemtype; +qemu_check_nic_model (nd,"mv88w8618" ); + s =qemu_mallocz (sizeof (mv88w8618_eth_state));if (!s)return ;
hw/ne2000.c +2 -0
@@ -722,6 +722,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) {NE2000State *s; +qemu_check_nic_model (nd,"ne2k_isa" ); + s =qemu_mallocz (sizeof (NE2000State));if (!s)return ;
hw/pcnet.c +2 -0
@@ -2087,6 +2087,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,PCNetState *d;int lance_io_memory; +qemu_check_nic_model (nd,"lance" ); + d =qemu_mallocz (sizeof (PCNetState));if (!d)return ;
hw/realview.c +5 -3
@@ -121,11 +121,13 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size, }for (n =0 ; n < nb_nics; n++) { nd = &nd_table[n]; -if (!nd->model) - nd->model = done_smc ?"rtl8139" :"smc91c111" ; -if (strcmp (nd->model,"smc91c111" ) ==0 ) { + +if ((!nd->model && !done_smc) ||strcmp (nd->model,"smc91c111" ) ==0 ) {smc91c111_init (nd,0x4e000000 , pic[28 ]); + done_smc =1 ; }else { +if (!nd->model) + nd->model ="rtl8139" ;pci_nic_init (pci_bus, nd,-1 ); } }
hw/smc91c111.c +2 -0
@@ -695,6 +695,8 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)smc91c111_state *s;int iomemtype; +qemu_check_nic_model (nd,"smc91c111" ); + s = (smc91c111_state *)qemu_mallocz (sizeof (smc91c111_state)); iomemtype =cpu_register_io_memory (0 , smc91c111_readfn, smc91c111_writefn, s);
hw/stellaris.c +1 -3
@@ -1361,10 +1361,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,pl022_init (0x40008000 , pic[7 ],NULL ,NULL ); } } -if (board->dc4 & (1 <<28 )) { -/* FIXME: Obey network model. */ +if (board->dc4 & (1 <<28 ))stellaris_enet_init (&nd_table[0 ],0x40048000 , pic[42 ]); - }if (board->peripherals &BP_GAMEPAD ) {qemu_irq gpad_irq[5 ];static const int gpad_keycode[5 ] = {0xc8 ,0xd0 ,0xcb ,0xcd ,0x1d };
hw/stellaris_enet.c +2 -0
@@ -389,6 +389,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)stellaris_enet_state *s;int iomemtype; +qemu_check_nic_model (nd,"stellaris" ); + s = (stellaris_enet_state *)qemu_mallocz (sizeof (stellaris_enet_state)); iomemtype =cpu_register_io_memory (0 , stellaris_enet_readfn, stellaris_enet_writefn, s);
hw/sun4m.c +3 -30
@@ -533,16 +533,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (slavio_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,8 );
@@ -1325,16 +1316,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (sbi_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,8 );
@@ -1540,16 +1522,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (slavio_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,2 );
hw/versatilepb.c +5 -3
@@ -194,11 +194,13 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,so many of the qemu PCI devices are not useable. */ for (n =0 ; n < nb_nics; n++) { nd = &nd_table[n]; -if (!nd->model) - nd->model = done_smc ?"rtl8139" :"smc91c111" ; -if (strcmp (nd->model,"smc91c111" ) ==0 ) { + +if ((!nd->model && !done_smc) ||strcmp (nd->model,"smc91c111" ) ==0 ) {smc91c111_init (nd,0x10010000 , sic[25 ]); + done_smc =1 ; }else { +if (!nd->model) + nd->model ="rtl8139" ;pci_nic_init (pci_bus, nd,-1 ); } }
Signature · 1 line
1.6.0.6
PATCH 3/4 Make virtio_net_init() return void
All PCI NIC init functions return void and nothing uses the return value from virtio_net_init().
--- hw/virtio-net.c | 6 ++---- hw/virtio-net.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
hw/virtio-net.c +2 -4
@@ -299,7 +299,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -PCIDevice *virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn) +void virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn) {VirtIONet *n;static int virtio_net_id;
@@ -309,7 +309,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)0x02 ,0x00 ,0x00 , 6, sizeof(VirtIONet));if (!n) -return NULL ; +return ; n->vdev.get_config = virtio_net_update_config; n->vdev.get_features = virtio_net_get_features;
@@ -328,6 +328,4 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)register_savevm ("virtio-net" , virtio_net_id++,2 , virtio_net_save, virtio_net_load, n); - -return (PCIDevice *)n; }
hw/virtio-net.h +1 -1
@@ -75,6 +75,6 @@ struct virtio_net_hdr_mrg_rxbuf uint16_t num_buffers; /* Number of merged rx buffers */ }; -PCIDevice *virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn); +void virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn);#endif
Signature · 1 line
1.6.0.6
PATCH 4/4 Make pci_nic_init() use qemu_setup_nic_model()
Add a table of PCI NIC models to pass to qemu_setup_nic_model().
While we're at it, also add a corresponding table of NIC init functions.
--- hw/mips_malta.c | 17 ++++++-------- hw/pc.c | 26 ++++------------------ hw/pci.c | 60 ++++++++++++++++++++++++++++++--------------------- hw/pci.h | 3 +- hw/ppc440_bamboo.c | 11 ++------- hw/ppc_chrp.c | 8 ++---- hw/ppc_oldworld.c | 7 +---- hw/ppc_prep.c | 2 +- hw/r2d.c | 4 +- hw/realview.c | 4 +-- hw/sun4u.c | 7 +---- hw/versatilepb.c | 4 +-- 12 files changed, 64 insertions(+), 89 deletions(-)
hw/mips_malta.c +7 -10
@@ -487,19 +487,16 @@ static void audio_init (PCIBus *pci_bus)static void network_init (PCIBus *pci_bus) {int i; -NICInfo *nd;for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { - nd->model ="pcnet" ; - } -if (i ==0 &&strcmp (nd->model,"pcnet" ) ==0 ) { +NICInfo *nd = &nd_table[i]; +int devfn =-1 ; + +if (i ==0 && (!nd->model ||strcmp (nd->model,"pcnet" ) ==0 ))/* The malta board has a PCNet card using PCI SLOT 11 */ -pci_nic_init (pci_bus, nd,88 ); - }else { -pci_nic_init (pci_bus, nd,-1 ); - } + devfn =88 ; + +pci_nic_init (pci_bus, nd, devfn,"pcnet" ); } }
hw/pc.c +5 -21
@@ -764,7 +764,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,PCIBus *pci_bus;int piix3_devfn =-1 ;CPUState *env; -NICInfo *nd;qemu_irq *cpu_irq;qemu_irq *i8259;int index;
@@ -1000,27 +999,12 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, }for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { -if (pci_enabled) { - nd->model ="ne2k_pci" ; - }else { - nd->model ="ne2k_isa" ; - } - } -if (strcmp (nd->model,"ne2k_isa" ) ==0 ) { +NICInfo *nd = &nd_table[i]; + +if (!pci_enabled || (nd->model &&strcmp (nd->model,"ne2k_isa" ) ==0 ))pc_init_ne2k_isa (nd, i8259); - }else if (pci_enabled) { -if (strcmp (nd->model,"?" ) ==0 ) -fprintf (stderr,"qemu: Supported ISA NICs: ne2k_isa\n" ); -pci_nic_init (pci_bus, nd,-1 ); - }else if (strcmp (nd->model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported ISA NICs: ne2k_isa\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd->model); -exit (1 ); - } +else +pci_nic_init (pci_bus, nd,-1 ,"ne2k_pci" ); }if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {
hw/pci.c +35 -25
68 lines not on this page · raw message
hw/pci.h +2 -1
@@ -118,7 +118,8 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);PCIBus *pci_register_bus (pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,qemu_irq *pic,int devfn_min,int nirq); -void pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn); +void pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn, +const char *default_model);void pci_data_write (void *opaque,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (void *opaque,uint32_t addr,int len);int pci_bus_num (PCIBus *s);
hw/ppc440_bamboo.c +3 -8
@@ -90,7 +90,6 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size, const char *cpu_model) {unsigned int pci_irq_nrs[4 ] = {28 ,27 ,26 ,25 }; -NICInfo *nd;PCIBus *pcibus;CPUState *env;uint64_t elf_entry;
@@ -118,13 +117,9 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,/* Register network interfaces. */ for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { -/* There are no PCI NICs on the Bamboo board, but there are -* PCI slots, so we can pick model whatever we want. */ - nd->model ="e1000" ; - } -pci_nic_init (pcibus, nd,-1 ); +/* There are no PCI NICs on the Bamboo board, but there are +* PCI slots, so we can pick whatever default model we want. */ +pci_nic_init (pcibus, &nd_table[i],-1 ,"e1000" ); } }
hw/ppc_chrp.c +3 -5
@@ -264,11 +264,9 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size,/* XXX: use Mac Serial port */ serial_init (0x3f8 , dummy_irq[4 ],115200 , serial_hds[0 ]); -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );exit (1 );
hw/ppc_oldworld.c +2 -5
@@ -305,11 +305,8 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,/* XXX: use Mac Serial port */ serial_init (0x3f8 , dummy_irq[4 ],115200 , serial_hds[0 ]); -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" );/* First IDE channel is a CMD646 on the PCI bus */
hw/ppc_prep.c +1 -1
@@ -675,7 +675,7 @@ static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size, || strcmp(nd_table[i].model, "ne2k_isa") == 0) { isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]); } else { -pci_nic_init (pci_bus, &nd_table[i],-1 ); +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); } }
hw/r2d.c +2 -2
@@ -230,9 +230,9 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, drives_table[drive_get_index(IF_IDE, 0, 0)].bdrv, NULL);/* NIC: rtl8139 on-board, and 2 slots. */ -pci_rtl8139_init (pci, &nd_table[0 ],2 <<3 ); +pci_nic_init (pci, &nd_table[0 ],2 <<3 ,"rtl8139" );for (i =1 ; i < nb_nics; i++) -pci_nic_init (pci, &nd_table[i],-1 ); +pci_nic_init (pci, &nd_table[i],-1 ,"ne2k_pci" );/* Todo: register on board registers */ {
hw/realview.c +1 -3
@@ -126,9 +126,7 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size,smc91c111_init (nd,0x4e000000 , pic[28 ]); done_smc =1 ; }else { -if (!nd->model) - nd->model ="rtl8139" ; -pci_nic_init (pci_bus, nd,-1 ); +pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); } }
hw/sun4u.c +2 -5
@@ -488,11 +488,8 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size, } } -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); irq =qemu_allocate_irqs (cpu_set_irq, env,MAX_PILS );if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {
hw/versatilepb.c +1 -3
@@ -199,9 +199,7 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,smc91c111_init (nd,0x10010000 , sic[25 ]); done_smc =1 ; }else { -if (!nd->model) - nd->model ="rtl8139" ; -pci_nic_init (pci_bus, nd,-1 ); +pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); } }if (usb_enabled) {
Signature · 1 line
1.6.0.6
PATCH 1/3 Check NIC model in some NIC init functions
In reply to Mark McLoughlinSome NIC init functions are only called when that model is the only valid model. In that case, it makes sense to use qemu_check_nic_model() from the NIC init function itself.
--- hw/axis_dev88.c | 5 +---- hw/etraxfs.c | 5 +---- hw/etraxfs_eth.c | 2 ++ hw/integratorcp.c | 14 ++------------ hw/mcf5208.c | 14 ++------------ hw/mcf_fec.c | 2 ++ hw/mips_mipssim.c | 16 +++------------- hw/mips_r4k.c | 16 ++-------------- hw/mipsnet.c | 2 ++ hw/musicpal.c | 2 ++ hw/ne2000.c | 2 ++ hw/pcnet.c | 2 ++ hw/realview.c | 8 +++++--- hw/smc91c111.c | 2 ++ hw/stellaris.c | 4 +--- hw/stellaris_enet.c | 2 ++ hw/sun4m.c | 36 +++--------------------------------- hw/versatilepb.c | 8 +++++--- 18 files changed, 41 insertions(+), 101 deletions(-)
hw/axis_dev88.c +1 -4
@@ -303,13 +303,10 @@ void axisdev88_init (ram_addr_t ram_size, int vga_ram_size, }/* Add the two ethernet blocks. */ - nd_table[0 ].model = nd_table[0 ].model ? nd_table[0 ].model :"fseth" ; eth[0 ] =etraxfs_eth_init (&nd_table[0 ], env, pic->irq +25 ,0x30034000 ,1 ); -if (nb_nics >1 ) { - nd_table[1 ].model = nd_table[1 ].model ? nd_table[1 ].model :"fseth" ; +if (nb_nics >1 ) eth[1 ] =etraxfs_eth_init (&nd_table[1 ], env, pic->irq +26 ,0x30036000 ,2 ); - }/* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client (etraxfs_dmac,0 , eth[0 ]);
hw/etraxfs.c +1 -4
@@ -94,13 +94,10 @@ void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size, }/* Add the two ethernet blocks. */ - nd_table[0 ].model = nd_table[0 ].model ? nd_table[0 ].model :"fseth" ; eth[0 ] =etraxfs_eth_init (&nd_table[0 ], env, pic->irq +25 ,0x30034000 ,1 ); -if (nb_nics >1 ) { - nd_table[1 ].model = nd_table[1 ].model ? nd_table[1 ].model :"fseth" ; +if (nb_nics >1 ) eth[1 ] =etraxfs_eth_init (&nd_table[1 ], env, pic->irq +26 ,0x30036000 ,2 ); - }/* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client (etraxfs_dmac,0 , eth[0 ]);
hw/etraxfs_eth.c +2 -0
@@ -561,6 +561,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,struct etraxfs_dma_client *dma =NULL ;struct fs_eth *eth =NULL ; +qemu_check_nic_model (nd,"fseth" ); + dma =qemu_mallocz (sizeof *dma *2 );if (!dma)return NULL ;
hw/integratorcp.c +2 -12
@@ -497,18 +497,8 @@ static void integratorcp_init(ram_addr_t ram_size, int vga_ram_size,exit (1 ); }pl181_init (0x1c000000 , drives_table[sd].bdrv, pic[23 ], pic[24 ]); -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"smc91c111" ) ==0 ) { -smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: smc91c111\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]);pl110_init (ds,0xc0000000 , pic[22 ],0 ); integrator_binfo.ram_size = ram_size;
hw/mcf5208.c +2 -12
@@ -241,18 +241,8 @@ static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size,fprintf (stderr,"Too many NICs\n" );exit (1 ); } -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"mcf_fec" ) ==0 ) { -mcf_fec_init (&nd_table[0 ],0xfc030000 , pic +36 ); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: mcf_fec\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +mcf_fec_init (&nd_table[0 ],0xfc030000 , pic +36 );/* 0xfc000000 SCM. */ /* 0xfc004000 XBS. */
hw/mcf_fec.c +2 -0
@@ -446,6 +446,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)mcf_fec_state *s;int iomemtype; +qemu_check_nic_model (nd,"mcf_fec" ); + s = (mcf_fec_state *)qemu_mallocz (sizeof (mcf_fec_state)); s->irq = irq; iomemtype = cpu_register_io_memory(0, mcf_fec_readfn,
hw/mips_mipssim.c +3 -13
@@ -175,19 +175,9 @@ mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size,if (serial_hds[0 ])serial_init (0x3f8 , env->irq[4 ],115200 , serial_hds[0 ]); -if (nd_table[0 ].vlan) { -if (nd_table[0 ].model ==NULL - ||strcmp (nd_table[0 ].model,"mipsnet" ) ==0 ) { -/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ -mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: mipsnet\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ +mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); }QEMUMachine mips_mipssim_machine = {
hw/mips_r4k.c +2 -14
@@ -247,20 +247,8 @@ void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size,isa_vga_init (ds, phys_ram_base + ram_size, ram_size, vga_ram_size); -if (nd_table[0 ].vlan) { -if (nd_table[i].model ==NULL ) { - nd_table[i].model ="ne2k_isa" ; - } -if (strcmp (nd_table[0 ].model,"ne2k_isa" ) ==0 ) { -isa_ne2000_init (0x300 , i8259[9 ], &nd_table[0 ]); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: ne2k_isa\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } - } +if (nd_table[0 ].vlan) +isa_ne2000_init (0x300 , i8259[9 ], &nd_table[0 ]);if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );
hw/mipsnet.c +2 -0
@@ -236,6 +236,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) {MIPSnetState *s; +qemu_check_nic_model (nd,"mipsnet" ); + s =qemu_mallocz (sizeof (MIPSnetState));if (!s)return ;
hw/musicpal.c +2 -0
@@ -714,6 +714,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)mv88w8618_eth_state *s;int iomemtype; +qemu_check_nic_model (nd,"mv88w8618" ); + s =qemu_mallocz (sizeof (mv88w8618_eth_state));if (!s)return ;
hw/ne2000.c +2 -0
@@ -722,6 +722,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) {NE2000State *s; +qemu_check_nic_model (nd,"ne2k_isa" ); + s =qemu_mallocz (sizeof (NE2000State));if (!s)return ;
hw/pcnet.c +2 -0
@@ -2087,6 +2087,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,PCNetState *d;int lance_io_memory; +qemu_check_nic_model (nd,"lance" ); + d =qemu_mallocz (sizeof (PCNetState));if (!d)return ;
hw/realview.c +5 -3
@@ -121,11 +121,13 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size, }for (n =0 ; n < nb_nics; n++) { nd = &nd_table[n]; -if (!nd->model) - nd->model = done_smc ?"rtl8139" :"smc91c111" ; -if (strcmp (nd->model,"smc91c111" ) ==0 ) { + +if ((!nd->model && !done_smc) ||strcmp (nd->model,"smc91c111" ) ==0 ) {smc91c111_init (nd,0x4e000000 , pic[28 ]); + done_smc =1 ; }else { +if (!nd->model) + nd->model ="rtl8139" ;pci_nic_init (pci_bus, nd,-1 ); } }
hw/smc91c111.c +2 -0
@@ -695,6 +695,8 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)smc91c111_state *s;int iomemtype; +qemu_check_nic_model (nd,"smc91c111" ); + s = (smc91c111_state *)qemu_mallocz (sizeof (smc91c111_state)); iomemtype =cpu_register_io_memory (0 , smc91c111_readfn, smc91c111_writefn, s);
hw/stellaris.c +1 -3
@@ -1361,10 +1361,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,pl022_init (0x40008000 , pic[7 ],NULL ,NULL ); } } -if (board->dc4 & (1 <<28 )) { -/* FIXME: Obey network model. */ +if (board->dc4 & (1 <<28 ))stellaris_enet_init (&nd_table[0 ],0x40048000 , pic[42 ]); - }if (board->peripherals &BP_GAMEPAD ) {qemu_irq gpad_irq[5 ];static const int gpad_keycode[5 ] = {0xc8 ,0xd0 ,0xcb ,0xcd ,0x1d };
hw/stellaris_enet.c +2 -0
@@ -389,6 +389,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)stellaris_enet_state *s;int iomemtype; +qemu_check_nic_model (nd,"stellaris" ); + s = (stellaris_enet_state *)qemu_mallocz (sizeof (stellaris_enet_state)); iomemtype =cpu_register_io_memory (0 , stellaris_enet_readfn, stellaris_enet_writefn, s);
hw/sun4m.c +3 -33
@@ -536,17 +536,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL ) - nd_table[0 ].model ="lance" ; -if (strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (slavio_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,8 );
@@ -1329,17 +1319,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL ) - nd_table[0 ].model ="lance" ; -if (strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (sbi_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,8 );
@@ -1545,17 +1525,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,tcx_init (ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, hwdef->vram_size, graphic_width, graphic_height, graphic_depth); -if (nd_table[0 ].model ==NULL ) - nd_table[0 ].model ="lance" ; -if (strcmp (nd_table[0 ].model,"lance" ) ==0 ) { -lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); - }else if (strcmp (nd_table[0 ].model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported NICs: lance\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd_table[0 ].model); -exit (1 ); - } +lance_init (&nd_table[0 ], hwdef->le_base, ledma, *ledma_irq, le_reset); nvram =m48t59_init (slavio_irq[0 ], hwdef->nvram_base,0 , hwdef->nvram_size,2 );
hw/versatilepb.c +5 -3
@@ -194,11 +194,13 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,so many of the qemu PCI devices are not useable. */ for (n =0 ; n < nb_nics; n++) { nd = &nd_table[n]; -if (!nd->model) - nd->model = done_smc ?"rtl8139" :"smc91c111" ; -if (strcmp (nd->model,"smc91c111" ) ==0 ) { + +if ((!nd->model && !done_smc) ||strcmp (nd->model,"smc91c111" ) ==0 ) {smc91c111_init (nd,0x10010000 , sic[25 ]); + done_smc =1 ; }else { +if (!nd->model) + nd->model ="rtl8139" ;pci_nic_init (pci_bus, nd,-1 ); } }
Signature · 1 line
1.6.0.6
PATCH 2/3 Make virtio_net_init() return void
All PCI NIC init functions return void and nothing uses the return value from virtio_net_init().
--- hw/virtio-net.c | 6 ++---- hw/virtio-net.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
hw/virtio-net.c +2 -4
@@ -315,7 +315,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -PCIDevice *virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn) +void virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn) {VirtIONet *n;static int virtio_net_id;
@@ -326,7 +326,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)sizeof (struct virtio_net_config ), sizeof(VirtIONet));if (!n) -return NULL ; +return ; n->vdev.get_config = virtio_net_update_config; n->vdev.get_features = virtio_net_get_features;
@@ -347,6 +347,4 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)register_savevm ("virtio-net" , virtio_net_id++,2 , virtio_net_save, virtio_net_load, n); - -return (PCIDevice *)n; }
hw/virtio-net.h +1 -1
@@ -80,6 +80,6 @@ struct virtio_net_hdr_mrg_rxbuf uint16_t num_buffers; /* Number of merged rx buffers */ }; -PCIDevice *virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn); +void virtio_net_init (PCIBus *bus,NICInfo *nd,int devfn);#endif
Signature · 1 line
1.6.0.6
PATCH 3/3 Make pci_nic_init() use qemu_setup_nic_model()
Add a table of PCI NIC models to pass to qemu_setup_nic_model().
While we're at it, also add a corresponding table of NIC init functions.
--- hw/mips_malta.c | 17 ++++++-------- hw/pc.c | 26 ++++------------------ hw/pci.c | 60 ++++++++++++++++++++++++++++++--------------------- hw/pci.h | 3 +- hw/ppc440_bamboo.c | 11 ++------- hw/ppc_chrp.c | 9 +++---- hw/ppc_oldworld.c | 7 +---- hw/ppc_prep.c | 2 +- hw/r2d.c | 4 +- hw/realview.c | 4 +-- hw/sun4u.c | 7 +---- hw/versatilepb.c | 4 +-- 12 files changed, 65 insertions(+), 89 deletions(-)
hw/mips_malta.c +7 -10
@@ -487,19 +487,16 @@ static void audio_init (PCIBus *pci_bus)static void network_init (PCIBus *pci_bus) {int i; -NICInfo *nd;for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { - nd->model ="pcnet" ; - } -if (i ==0 &&strcmp (nd->model,"pcnet" ) ==0 ) { +NICInfo *nd = &nd_table[i]; +int devfn =-1 ; + +if (i ==0 && (!nd->model ||strcmp (nd->model,"pcnet" ) ==0 ))/* The malta board has a PCNet card using PCI SLOT 11 */ -pci_nic_init (pci_bus, nd,88 ); - }else { -pci_nic_init (pci_bus, nd,-1 ); - } + devfn =88 ; + +pci_nic_init (pci_bus, nd, devfn,"pcnet" ); } }
hw/pc.c +5 -21
@@ -764,7 +764,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,PCIBus *pci_bus;int piix3_devfn =-1 ;CPUState *env; -NICInfo *nd;qemu_irq *cpu_irq;qemu_irq *i8259;int index;
@@ -1000,27 +999,12 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, }for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { -if (pci_enabled) { - nd->model ="ne2k_pci" ; - }else { - nd->model ="ne2k_isa" ; - } - } -if (strcmp (nd->model,"ne2k_isa" ) ==0 ) { +NICInfo *nd = &nd_table[i]; + +if (!pci_enabled || (nd->model &&strcmp (nd->model,"ne2k_isa" ) ==0 ))pc_init_ne2k_isa (nd, i8259); - }else if (pci_enabled) { -if (strcmp (nd->model,"?" ) ==0 ) -fprintf (stderr,"qemu: Supported ISA NICs: ne2k_isa\n" ); -pci_nic_init (pci_bus, nd,-1 ); - }else if (strcmp (nd->model,"?" ) ==0 ) { -fprintf (stderr,"qemu: Supported ISA NICs: ne2k_isa\n" ); -exit (1 ); - }else { -fprintf (stderr,"qemu: Unsupported NIC: %s\n" , nd->model); -exit (1 ); - } +else +pci_nic_init (pci_bus, nd,-1 ,"ne2k_pci" ); }if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {
hw/pci.c +35 -25
68 lines not on this page · raw message
hw/pci.h +2 -1
@@ -118,7 +118,8 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);PCIBus *pci_register_bus (pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,qemu_irq *pic,int devfn_min,int nirq); -void pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn); +void pci_nic_init (PCIBus *bus,NICInfo *nd,int devfn, +const char *default_model);void pci_data_write (void *opaque,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (void *opaque,uint32_t addr,int len);int pci_bus_num (PCIBus *s);
hw/ppc440_bamboo.c +3 -8
@@ -90,7 +90,6 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size, const char *cpu_model) {unsigned int pci_irq_nrs[4 ] = {28 ,27 ,26 ,25 }; -NICInfo *nd;PCIBus *pcibus;CPUState *env;uint64_t elf_entry;
@@ -118,13 +117,9 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,/* Register network interfaces. */ for (i =0 ; i < nb_nics; i++) { - nd = &nd_table[i]; -if (!nd->model) { -/* There are no PCI NICs on the Bamboo board, but there are -* PCI slots, so we can pick model whatever we want. */ - nd->model ="e1000" ; - } -pci_nic_init (pcibus, nd,-1 ); +/* There are no PCI NICs on the Bamboo board, but there are +* PCI slots, so we can pick whatever default model we want. */ +pci_nic_init (pcibus, &nd_table[i],-1 ,"e1000" ); } }
hw/ppc_chrp.c +4 -5
@@ -265,11 +265,10 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size, escc_mem_index =escc_init (0x80013000 , dummy_irq[4 ], serial_hds[0 ], serial_hds[1 ],ESCC_CLOCK ,4 ); -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } + +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); +if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {fprintf (stderr,"qemu: too many IDE bus\n" );exit (1 );
hw/ppc_oldworld.c +2 -5
@@ -307,11 +307,8 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size, escc_mem_index =escc_init (0x80013000 , pic[0x10 ], serial_hds[0 ], serial_hds[1 ],ESCC_CLOCK ,4 ); -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" );/* First IDE channel is a CMD646 on the PCI bus */
hw/ppc_prep.c +1 -1
@@ -677,7 +677,7 @@ static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size,if (strcmp (nd_table[i].model,"ne2k_isa" ) ==0 ) {isa_ne2000_init (ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]); }else { -pci_nic_init (pci_bus, &nd_table[i],-1 ); +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); } }
hw/r2d.c +2 -2
@@ -230,9 +230,9 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size, drives_table[drive_get_index(IF_IDE, 0, 0)].bdrv, NULL);/* NIC: rtl8139 on-board, and 2 slots. */ -pci_rtl8139_init (pci, &nd_table[0 ],2 <<3 ); +pci_nic_init (pci, &nd_table[0 ],2 <<3 ,"rtl8139" );for (i =1 ; i < nb_nics; i++) -pci_nic_init (pci, &nd_table[i],-1 ); +pci_nic_init (pci, &nd_table[i],-1 ,"ne2k_pci" );/* Todo: register on board registers */ {
hw/realview.c +1 -3
@@ -126,9 +126,7 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size,smc91c111_init (nd,0x4e000000 , pic[28 ]); done_smc =1 ; }else { -if (!nd->model) - nd->model ="rtl8139" ; -pci_nic_init (pci_bus, nd,-1 ); +pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); } }
hw/sun4u.c +2 -5
@@ -535,11 +535,8 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size, } } -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model) - nd_table[i].model ="ne2k_pci" ; -pci_nic_init (pci_bus, &nd_table[i],-1 ); - } +for (i =0 ; i < nb_nics; i++) +pci_nic_init (pci_bus, &nd_table[i],-1 ,"ne2k_pci" ); irq =qemu_allocate_irqs (cpu_set_irq, env,MAX_PILS );if (drive_get_max_bus (IF_IDE ) >=MAX_IDE_BUS ) {
hw/versatilepb.c +1 -3
@@ -199,9 +199,7 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,smc91c111_init (nd,0x10010000 , sic[25 ]); done_smc =1 ; }else { -if (!nd->model) - nd->model ="rtl8139" ; -pci_nic_init (pci_bus, nd,-1 ); +pci_nic_init (pci_bus, nd,-1 ,"rtl8139" ); } }if (usb_enabled) {
Signature · 1 line
1.6.0.6
Anthony Liguori
Applied[Qemu-devel] Re: [PATCH 1/3] Check NIC model in some NIC init functions
In reply to Mark McLoughlinQuoted 6 lines · Mark McLoughlin
Some NIC init functions are only called when that model is the only valid model. In that case, it makes sense to use
qemu_check_nic_model()from the NIC init function itself.Signed-off-by Mark McLoughlin <[email protected]>
Applied all 4. Thanks.
Regards,
Anthony Liguori
[Qemu-devel] Re: [PATCH 1/3] Check NIC model in some NIC init functions
----- Message d'origine ----
Quoted 11 lines
De : Anthony Liguori <[email protected]>
À : Mark McLoughlin <[email protected]>
Cc : [email protected]
Envoyé le : Mardi, 13 Janvier 2009, 20h47mn 19s
Objet : [Qemu-devel] Re: [PATCH 1/3] Check NIC model in some NIC init functionsQuoted 4 lines · Mark McLoughlin
Some NIC init functions are only called when that model is the only valid model. In that case, it makes sense to use
qemu_check_nic_model()from the NIC init function itself.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Mark McLoughlinApplied all 4. Thanks.
Regards,
Anthony Liguori
It seems the virtio part of these 4 hasn't been applied.
Kind regards,
Sylvain Petreolle