static int fs_eth_init(SysBusDevice *dev) { struct fs_eth *s = FROM_SYSBUS(typeof(*s), dev); int eth_regs; if (!s->dma_out || !s->dma_in) { hw_error("Unconnected ETRAX-FS Ethernet MAC.\n"); } s->dma_out->client.push = eth_tx_push; s->dma_out->client.opaque = s; s->dma_in->client.opaque = s; s->dma_in->client.pull = NULL; eth_regs = cpu_register_io_memory(eth_read, eth_write, s, DEVICE_LITTLE_ENDIAN); sysbus_init_mmio(dev, 0x5c, eth_regs); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf, dev->qdev.info->name, dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); tdk_init(&s->phy); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); return 0; }
void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, qemu_irq irq, void* mem_opaque, void (*memory_rw)(void *opaque, target_phys_addr_t addr, uint8_t *buf, int len, int is_write)) { dp8393xState *s; qemu_check_nic_model(nd, "dp83932"); s = qemu_mallocz(sizeof(dp8393xState)); s->mem_opaque = mem_opaque; s->memory_rw = memory_rw; s->it_shift = it_shift; s->irq = irq; s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ s->conf.macaddr = nd->macaddr; s->conf.vlan = nd->vlan; s->conf.peer = nd->netdev; s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); qemu_register_reset(nic_reset, s); nic_reset(s); s->mmio_index = cpu_register_io_memory(dp8393x_read, dp8393x_write, s); cpu_register_physical_memory(base, 0x40 << it_shift, s->mmio_index); }
void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) { struct etraxfs_dma_client *dma = NULL; struct fs_eth *eth = NULL; qemu_check_nic_model(nd, "fseth"); dma = qemu_mallocz(sizeof *dma * 2); eth = qemu_mallocz(sizeof *eth); dma[0].client.push = eth_tx_push; dma[0].client.opaque = eth; dma[1].client.opaque = eth; dma[1].client.pull = NULL; eth->dma_out = dma; eth->dma_in = dma + 1; /* Connect the phy. */ eth->phyaddr = phyaddr & 0x1f; tdk_init(ð->phy); mdio_attach(ð->mdio_bus, ð->phy, eth->phyaddr); eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth); cpu_register_physical_memory (base, 0x5c, eth->ethregs); memcpy(eth->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr)); eth->conf.vlan = nd->vlan; eth->conf.peer = nd->netdev; eth->nic = qemu_new_nic(&net_etraxfs_info, ð->conf, nd->model, nd->name, eth); return dma; }
static int net_init(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); /* read xenstore entries */ if (netdev->mac == NULL) { netdev->mac = xenstore_read_be_str(&netdev->xendev, "mac"); } /* do we have all we need? */ if (netdev->mac == NULL) { return -1; } if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0) { return -1; } netdev->conf.vlan = qemu_find_vlan(netdev->xendev.dev, 1); netdev->conf.peer = NULL; netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, "xen", NULL, netdev); snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str), "nic: xenbus vif macaddr=%s", netdev->mac); /* fill info */ xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1); xenstore_write_be_int(&netdev->xendev, "feature-rx-flip", 0); return 0; }
void dp83932_init(NICInfo *nd, hwaddr base, int it_shift, MemoryRegion *address_space, qemu_irq irq, void* mem_opaque, void (*memory_rw)(void *opaque, hwaddr addr, uint8_t *buf, int len, int is_write)) { dp8393xState *s; qemu_check_nic_model(nd, "dp83932"); s = g_malloc0(sizeof(dp8393xState)); s->address_space = address_space; s->mem_opaque = mem_opaque; s->memory_rw = memory_rw; s->it_shift = it_shift; s->irq = irq; s->watchdog = timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s); s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ s->conf.macaddr = nd->macaddr; s->conf.peers.ncs[0] = nd->netdev; s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->name, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); qemu_register_reset(nic_reset, s); nic_reset(s); memory_region_init_io(&s->mmio, NULL, &dp8393x_ops, s, "dp8393x", 0x40 << it_shift); memory_region_add_subregion(address_space, base, &s->mmio); }
static int fs_eth_init(SysBusDevice *sbd) { DeviceState *dev = DEVICE(sbd); ETRAXFSEthState *s = ETRAX_FS_ETH(dev); if (!s->dma_out || !s->dma_in) { error_report("Unconnected ETRAX-FS Ethernet MAC"); return -1; } s->dma_out->client.push = eth_tx_push; s->dma_out->client.opaque = s; s->dma_in->client.opaque = s; s->dma_in->client.pull = NULL; memory_region_init_io(&s->mmio, OBJECT(dev), ð_ops, s, "etraxfs-eth", 0x5c); sysbus_init_mmio(sbd, &s->mmio); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf, object_get_typename(OBJECT(s)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); tdk_init(&s->phy); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); return 0; }
void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) { MIPSnetState *s; qemu_check_nic_model(nd, "mipsnet"); s = qemu_mallocz(sizeof(MIPSnetState)); register_ioport_write(base, 36, 1, mipsnet_ioport_write, s); register_ioport_read(base, 36, 1, mipsnet_ioport_read, s); register_ioport_write(base, 36, 2, mipsnet_ioport_write, s); register_ioport_read(base, 36, 2, mipsnet_ioport_read, s); register_ioport_write(base, 36, 4, mipsnet_ioport_write, s); register_ioport_read(base, 36, 4, mipsnet_ioport_read, s); s->io_base = base; s->irq = irq; if (nd) { memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr)); s->conf.vlan = nd->vlan; s->conf.peer = nd->netdev; s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf, nd->model, nd->name, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); } mipsnet_reset(s); vmstate_register(NULL, 0, &vmstate_mipsnet, s); }
static int fs_eth_init(SysBusDevice *dev) { struct fs_eth *s = FROM_SYSBUS(typeof(*s), dev); if (!s->dma_out || !s->dma_in) { hw_error("Unconnected ETRAX-FS Ethernet MAC.\n"); } s->dma_out->client.push = eth_tx_push; s->dma_out->client.opaque = s; s->dma_in->client.opaque = s; s->dma_in->client.pull = NULL; memory_region_init_io(&s->mmio, ð_ops, s, "etraxfs-eth", 0x5c); sysbus_init_mmio(dev, &s->mmio); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_etraxfs_info, &s->conf, object_get_typename(OBJECT(s)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); tdk_init(&s->phy); mdio_attach(&s->mdio_bus, &s->phy, s->phyaddr); return 0; }
FpPort *fp_port_alloc(Rocker *r, char *sw_name, MACAddr *start_mac, unsigned int index, NICPeers *peers) { FpPort *port = g_new0(FpPort, 1); if (!port) { return NULL; } port->r = r; port->index = index; port->pport = index + 1; /* front-panel switch port names are 1-based */ port->name = g_strdup_printf("%sp%d", sw_name, port->pport); memcpy(port->conf.macaddr.a, start_mac, sizeof(port->conf.macaddr.a)); port->conf.macaddr.a[5] += index; port->conf.bootindex = -1; port->conf.peers = *peers; port->nic = qemu_new_nic(&fp_port_info, &port->conf, sw_name, NULL, port); qemu_format_nic_info_str(qemu_get_queue(port->nic), port->conf.macaddr.a); fp_port_reset(port); return port; }
static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) { struct xlx_ethlite *s = XILINX_ETHLITE(dev); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); }
static int spapr_vlan_init(VIOsPAPRDevice *sdev) { VIOsPAPRVLANDevice *dev = (VIOsPAPRVLANDevice *)sdev; qemu_macaddr_default_if_unset(&dev->nicconf.macaddr); dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf, object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev); qemu_format_nic_info_str(&dev->nic->nc, dev->nicconf.macaddr.a); return 0; }
static void etsec_realize(DeviceState *dev, Error **errp) { eTSEC *etsec = ETSEC_COMMON(dev); etsec->nic = qemu_new_nic(&net_etsec_info, &etsec->conf, object_get_typename(OBJECT(dev)), dev->id, etsec); qemu_format_nic_info_str(qemu_get_queue(etsec->nic), etsec->conf.macaddr.a); etsec->bh = qemu_bh_new(etsec_timer_hit, etsec); etsec->ptimer = ptimer_init(etsec->bh, PTIMER_POLICY_DEFAULT); ptimer_set_freq(etsec->ptimer, 100); }
static int spapr_vlan_init(VIOsPAPRDevice *sdev) { VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); qemu_macaddr_default_if_unset(&dev->nicconf.macaddr); dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf, object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev); qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a); add_boot_device_path(dev->nicconf.bootindex, DEVICE(dev), ""); return 0; }
static int mipsnet_sysbus_init(SysBusDevice *dev) { MIPSnetState *s = DO_UPCAST(MIPSnetState, busdev, dev); memory_region_init_io(&s->io, &mipsnet_ioport_ops, s, "mipsnet-io", 36); sysbus_init_mmio(dev, &s->io); sysbus_init_irq(dev, &s->irq); s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf, object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); return 0; }
static int smc91c111_init1(SysBusDevice *dev) { smc91c111_state *s = FROM_SYSBUS(smc91c111_state, dev); memory_region_init_io(&s->mmio, &smc91c111_mem_ops, s, "smc91c111-mmio", 16); sysbus_init_mmio(dev, &s->mmio); sysbus_init_irq(dev, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf, object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); /* ??? Save/restore. */ return 0; }
static void spapr_vlan_realize(VIOsPAPRDevice *sdev, Error **errp) { VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); qemu_macaddr_default_if_unset(&dev->nicconf.macaddr); memcpy(&dev->perm_mac.a, &dev->nicconf.macaddr.a, sizeof(dev->perm_mac.a)); dev->nic = qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf, object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev); qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a); dev->rxp_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, spapr_vlan_flush_rx_queue, dev); }
static int xilinx_ethlite_init(SysBusDevice *dev) { struct xlx_ethlite *s = FROM_SYSBUS(typeof (*s), dev); sysbus_init_irq(dev, &s->irq); s->rxbuf = 0; memory_region_init_io(&s->mmio, ð_ops, s, "xilinx-ethlite", R_MAX * 4); sysbus_init_mmio(dev, &s->mmio); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, dev->qdev.info->name, dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); return 0; }
static int mipsnet_sysbus_init(SysBusDevice *sbd) { DeviceState *dev = DEVICE(sbd); MIPSnetState *s = MIPS_NET(dev); memory_region_init_io(&s->io, OBJECT(dev), &mipsnet_ioport_ops, s, "mipsnet-io", 36); sysbus_init_mmio(sbd, &s->io); sysbus_init_irq(sbd, &s->irq); s->nic = qemu_new_nic(&net_mipsnet_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); return 0; }
static int smc91c111_init1(SysBusDevice *sbd) { DeviceState *dev = DEVICE(sbd); smc91c111_state *s = SMC91C111(dev); memory_region_init_io(&s->mmio, OBJECT(s), &smc91c111_mem_ops, s, "smc91c111-mmio", 16); sysbus_init_mmio(sbd, &s->mmio); sysbus_init_irq(sbd, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); /* ??? Save/restore. */ return 0; }
static int xilinx_ethlite_init(SysBusDevice *dev) { struct xlx_ethlite *s = FROM_SYSBUS(typeof (*s), dev); sysbus_init_irq(dev, &s->irq); s->rxbuf = 0; memory_region_init_io(&s->mmio, ð_ops, s, "xlnx.xps-ethernetlite", R_MAX * 4); sysbus_init_mmio(dev, &s->mmio); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); return 0; }
static int xilinx_ethlite_init(SysBusDevice *dev) { struct xlx_ethlite *s = FROM_SYSBUS(typeof (*s), dev); int regs; sysbus_init_irq(dev, &s->irq); s->rxbuf = 0; regs = cpu_register_io_memory(eth_read, eth_write, s, DEVICE_NATIVE_ENDIAN); sysbus_init_mmio(dev, R_MAX * 4, regs); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, dev->qdev.info->name, dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); return 0; }
static int smc91c111_init1(SysBusDevice *dev) { smc91c111_state *s = FROM_SYSBUS(smc91c111_state, dev); s->mmio_index = cpu_register_io_memory(smc91c111_readfn, smc91c111_writefn, s); sysbus_init_mmio(dev, 16, s->mmio_index); sysbus_init_irq(dev, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); smc91c111_reset(s); s->nic = qemu_new_nic(&net_smc91c111_info, &s->conf, dev->qdev.info->name, dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); /* ??? Save/restore. */ return 0; }
static void ftgmac100_realize(DeviceState *dev, Error **errp) { Ftgmac100State *s = FTGMAC100(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s, TYPE_FTGMAC100, 0x2000); sysbus_init_mmio(sbd, &s->iomem); sysbus_init_irq(sbd, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->conf.peers.ncs[0] = nd_table[0].netdev; s->nic = qemu_new_nic(&net_ftgmac100_info, &s->conf, object_get_typename(OBJECT(dev)), DEVICE(dev)->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); }
static int isa_ne2000_initfn(ISADevice *dev) { ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev); NE2000State *s = &isa->ne2000; ne2000_setup_io(s, 0x20); isa_register_ioport(dev, &s->io, isa->iobase); isa_init_irq(dev, &s->irq, isa->isairq); qemu_macaddr_default_if_unset(&s->c.macaddr); ne2000_reset(s); s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c, object_get_typename(OBJECT(dev)), dev->qdev.id, s); qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a); return 0; }
static void e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) { DeviceState *dev = DEVICE(pci_dev); NetClientState *nc; int i; s->nic = qemu_new_nic(&net_e1000e_info, &s->conf, object_get_typename(OBJECT(s)), dev->id, s); s->core.max_queue_num = s->conf.peers.queues - 1; trace_e1000e_mac_set_permanent(MAC_ARG(macaddr)); memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac)); qemu_format_nic_info_str(qemu_get_queue(s->nic), macaddr); /* Setup virtio headers */ if (s->disable_vnet) { s->core.has_vnet = false; trace_e1000e_cfg_support_virtio(false); return; } else { s->core.has_vnet = true; } for (i = 0; i < s->conf.peers.queues; i++) { nc = qemu_get_subqueue(s->nic, i); if (!nc->peer || !qemu_has_vnet_hdr(nc->peer)) { s->core.has_vnet = false; trace_e1000e_cfg_support_virtio(false); return; } } trace_e1000e_cfg_support_virtio(true); for (i = 0; i < s->conf.peers.queues; i++) { nc = qemu_get_subqueue(s->nic, i); qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); qemu_using_vnet_hdr(nc->peer, true); } }
static int tnetw1130_init(PCIDevice *pci_dev) { TNETW1130State *d = DO_UPCAST(TNETW1130State, dev, pci_dev); tnetw1130_t *s = &d->tnetw1130; /* TI TNETW1130 */ tnetw1130_pci_config(d->dev.config); /* Handler for memory-mapped I/O */ memory_region_init_io(&d->mmio_bar0, &tnetw1130_ops0, s, "tnetw1130_mmio0", TNETW1130_MEM0_SIZE); memory_region_init_io(&d->mmio_bar1, &tnetw1130_ops1, s, "tnetw1130_mmio1", TNETW1130_MEM1_SIZE); pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio_bar0); pci_register_bar(&d->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio_bar1); #if 0 static const char macaddr[6] = { 0x00, 0x60, 0x65, 0x02, 0x4a, 0x8e }; memcpy(s->conf.macaddr.a, macaddr, 6); #endif qemu_macaddr_default_if_unset(&s->conf.macaddr); tnetw1130_reset(s); s->nic = qemu_new_nic(&net_info, &s->conf, object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); qemu_register_reset(nic_reset, d); return 0; }
static void dp8393x_realize(DeviceState *dev, Error **errp) { dp8393xState *s = DP8393X(dev); int i, checksum; uint8_t *prom; Error *local_err = NULL; address_space_init(&s->as, s->dma_mr, "dp8393x"); memory_region_init_io(&s->mmio, OBJECT(dev), &dp8393x_ops, s, "dp8393x-regs", 0x40 << s->it_shift); s->nic = qemu_new_nic(&net_dp83932_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); s->watchdog = timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s); s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ memory_region_init_ram(&s->prom, OBJECT(dev), "dp8393x-prom", SONIC_PROM_SIZE, &local_err); if (local_err) { error_propagate(errp, local_err); return; } memory_region_set_readonly(&s->prom, true); prom = memory_region_get_ram_ptr(&s->prom); checksum = 0; for (i = 0; i < 6; i++) { prom[i] = s->conf.macaddr.a[i]; checksum += prom[i]; if (checksum > 0xff) { checksum = (checksum + 1) & 0xff; } } prom[7] = 0xff - checksum; }