Skip to content

Commit

Permalink
net: introduce qemu_get_queue()
Browse files Browse the repository at this point in the history
To support multiqueue, the patch introduce a helper qemu_get_queue()
which is used to get the NetClientState of a device. The following patches would
refactor this helper to support multiqueue.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
jasowang authored and Anthony Liguori committed Feb 1, 2013
1 parent 28a6589 commit b356f76
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 115 deletions.
9 changes: 5 additions & 4 deletions hw/cadence_gem.c
Expand Up @@ -389,10 +389,10 @@ static void gem_init_register_masks(GemState *s)
*/
static void phy_update_link(GemState *s)
{
DB_PRINT("down %d\n", s->nic->nc.link_down);
DB_PRINT("down %d\n", qemu_get_queue(s->nic)->link_down);

/* Autonegotiation status mirrors link status. */
if (s->nic->nc.link_down) {
if (qemu_get_queue(s->nic)->link_down) {
s->phy_regs[PHY_REG_STATUS] &= ~(PHY_REG_STATUS_ANEGCMPL |
PHY_REG_STATUS_LINK);
s->phy_regs[PHY_REG_INT_ST] |= PHY_REG_INT_ST_LINKC;
Expand Down Expand Up @@ -908,9 +908,10 @@ static void gem_transmit(GemState *s)

/* Send the packet somewhere */
if (s->phy_loop) {
gem_receive(&s->nic->nc, tx_packet, total_bytes);
gem_receive(qemu_get_queue(s->nic), tx_packet, total_bytes);
} else {
qemu_send_packet(&s->nic->nc, tx_packet, total_bytes);
qemu_send_packet(qemu_get_queue(s->nic), tx_packet,
total_bytes);
}

/* Prepare for next packet */
Expand Down
9 changes: 5 additions & 4 deletions hw/dp8393x.c
Expand Up @@ -339,6 +339,7 @@ static void do_receiver_disable(dp8393xState *s)

static void do_transmit_packets(dp8393xState *s)
{
NetClientState *nc = qemu_get_queue(s->nic);
uint16_t data[12];
int width, size;
int tx_len, len;
Expand Down Expand Up @@ -408,13 +409,13 @@ static void do_transmit_packets(dp8393xState *s)
if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
/* Loopback */
s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
if (s->nic->nc.info->can_receive(&s->nic->nc)) {
if (nc->info->can_receive(nc)) {
s->loopback_packet = 1;
s->nic->nc.info->receive(&s->nic->nc, s->tx_buffer, tx_len);
nc->info->receive(nc, s->tx_buffer, tx_len);
}
} else {
/* Transmit packet */
qemu_send_packet(&s->nic->nc, s->tx_buffer, tx_len);
qemu_send_packet(nc, s->tx_buffer, tx_len);
}
s->regs[SONIC_TCR] |= SONIC_TCR_PTX;

Expand Down Expand Up @@ -903,7 +904,7 @@ void dp83932_init(NICInfo *nd, hwaddr base, int it_shift,

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_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
qemu_register_reset(nic_reset, s);
nic_reset(s);

Expand Down
22 changes: 12 additions & 10 deletions hw/e1000.c
Expand Up @@ -166,7 +166,7 @@ static void
set_phy_ctrl(E1000State *s, int index, uint16_t val)
{
if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) {
s->nic->nc.link_down = true;
qemu_get_queue(s->nic)->link_down = true;
e1000_link_down(s);
s->phy_reg[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE;
DBGOUT(PHY, "Start link auto negotiation\n");
Expand All @@ -178,7 +178,7 @@ static void
e1000_autoneg_timer(void *opaque)
{
E1000State *s = opaque;
s->nic->nc.link_down = false;
qemu_get_queue(s->nic)->link_down = false;
e1000_link_up(s);
s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE;
DBGOUT(PHY, "Auto negotiation is completed\n");
Expand Down Expand Up @@ -291,7 +291,7 @@ static void e1000_reset(void *opaque)
d->rxbuf_min_shift = 1;
memset(&d->tx, 0, sizeof d->tx);

if (d->nic->nc.link_down) {
if (qemu_get_queue(d->nic)->link_down) {
e1000_link_down(d);
}

Expand Down Expand Up @@ -319,7 +319,7 @@ set_rx_control(E1000State *s, int index, uint32_t val)
s->rxbuf_min_shift = ((val / E1000_RCTL_RDMTS_QUAT) & 3) + 1;
DBGOUT(RX, "RCTL: %d, mac_reg[RCTL] = 0x%x\n", s->mac_reg[RDT],
s->mac_reg[RCTL]);
qemu_flush_queued_packets(&s->nic->nc);
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}

static void
Expand Down Expand Up @@ -470,10 +470,11 @@ fcs_len(E1000State *s)
static void
e1000_send_packet(E1000State *s, const uint8_t *buf, int size)
{
NetClientState *nc = qemu_get_queue(s->nic);
if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) {
s->nic->nc.info->receive(&s->nic->nc, buf, size);
nc->info->receive(nc, buf, size);
} else {
qemu_send_packet(&s->nic->nc, buf, size);
qemu_send_packet(nc, buf, size);
}
}

Expand Down Expand Up @@ -958,7 +959,7 @@ set_rdt(E1000State *s, int index, uint32_t val)
{
s->mac_reg[index] = val & 0xffff;
if (e1000_has_rxbufs(s, 1)) {
qemu_flush_queued_packets(&s->nic->nc);
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}
}

Expand Down Expand Up @@ -1112,10 +1113,11 @@ static bool is_version_1(void *opaque, int version_id)
static int e1000_post_load(void *opaque, int version_id)
{
E1000State *s = opaque;
NetClientState *nc = qemu_get_queue(s->nic);

/* nc.link_down can't be migrated, so infer link_down according
* to link status bit in mac_reg[STATUS] */
s->nic->nc.link_down = (s->mac_reg[STATUS] & E1000_STATUS_LU) == 0;
nc->link_down = (s->mac_reg[STATUS] & E1000_STATUS_LU) == 0;

return 0;
}
Expand Down Expand Up @@ -1247,7 +1249,7 @@ pci_e1000_uninit(PCIDevice *dev)
qemu_free_timer(d->autoneg_timer);
memory_region_destroy(&d->mmio);
memory_region_destroy(&d->io);
qemu_del_net_client(&d->nic->nc);
qemu_del_net_client(qemu_get_queue(d->nic));
}

static NetClientInfo net_e1000_info = {
Expand Down Expand Up @@ -1294,7 +1296,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
object_get_typename(OBJECT(d)), d->dev.qdev.id, d);

qemu_format_nic_info_str(&d->nic->nc, macaddr);
qemu_format_nic_info_str(qemu_get_queue(d->nic), macaddr);

add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");

Expand Down
12 changes: 6 additions & 6 deletions hw/eepro100.c
Expand Up @@ -828,7 +828,7 @@ static void tx_command(EEPRO100State *s)
}
}
TRACE(RXTX, logout("%p sending frame, len=%d,%s\n", s, size, nic_dump(buf, size)));
qemu_send_packet(&s->nic->nc, buf, size);
qemu_send_packet(qemu_get_queue(s->nic), buf, size);
s->statistics.tx_good_frames++;
/* Transmit with bad status would raise an CX/TNO interrupt.
* (82557 only). Emulation never has bad status. */
Expand Down Expand Up @@ -1036,7 +1036,7 @@ static void eepro100_ru_command(EEPRO100State * s, uint8_t val)
}
set_ru_state(s, ru_ready);
s->ru_offset = e100_read_reg4(s, SCBPointer);
qemu_flush_queued_packets(&s->nic->nc);
qemu_flush_queued_packets(qemu_get_queue(s->nic));
TRACE(OTHER, logout("val=0x%02x (rx start)\n", val));
break;
case RX_RESUME:
Expand Down Expand Up @@ -1849,7 +1849,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
memory_region_destroy(&s->flash_bar);
vmstate_unregister(&pci_dev->qdev, s->vmstate, s);
eeprom93xx_free(&pci_dev->qdev, s->eeprom);
qemu_del_net_client(&s->nic->nc);
qemu_del_net_client(qemu_get_queue(s->nic));
}

static NetClientInfo net_eepro100_info = {
Expand Down Expand Up @@ -1895,14 +1895,14 @@ static int e100_nic_init(PCIDevice *pci_dev)
s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);

qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
TRACE(OTHER, logout("%s\n", qemu_get_queue(s->nic)->info_str));

qemu_register_reset(nic_reset, s);

s->vmstate = g_malloc(sizeof(vmstate_eepro100));
memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100));
s->vmstate->name = s->nic->nc.model;
s->vmstate->name = qemu_get_queue(s->nic)->model;
vmstate_register(&pci_dev->qdev, -1, s->vmstate, s);

add_boot_device_path(s->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
Expand Down
5 changes: 3 additions & 2 deletions hw/etraxfs_eth.c
Expand Up @@ -555,7 +555,7 @@ static int eth_tx_push(void *opaque, unsigned char *buf, int len, bool eop)
struct fs_eth *eth = opaque;

D(printf("%s buf=%p len=%d\n", __func__, buf, len));
qemu_send_packet(&eth->nic->nc, buf, len);
qemu_send_packet(qemu_get_queue(eth->nic), buf, len);
return len;
}

Expand Down Expand Up @@ -616,7 +616,8 @@ static int fs_eth_init(SysBusDevice *dev)
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);
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);
Expand Down
10 changes: 5 additions & 5 deletions hw/lan9118.c
Expand Up @@ -341,7 +341,7 @@ static void lan9118_update(lan9118_state *s)

static void lan9118_mac_changed(lan9118_state *s)
{
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
}

static void lan9118_reload_eeprom(lan9118_state *s)
Expand Down Expand Up @@ -373,7 +373,7 @@ static void phy_update_irq(lan9118_state *s)
static void phy_update_link(lan9118_state *s)
{
/* Autonegotiation status mirrors link status. */
if (s->nic->nc.link_down) {
if (qemu_get_queue(s->nic)->link_down) {
s->phy_status &= ~0x0024;
s->phy_int |= PHY_INT_DOWN;
} else {
Expand Down Expand Up @@ -657,9 +657,9 @@ static void do_tx_packet(lan9118_state *s)
/* FIXME: Honor TX disable, and allow queueing of packets. */
if (s->phy_control & 0x4000) {
/* This assumes the receive routine doesn't touch the VLANClient. */
lan9118_receive(&s->nic->nc, s->txp->data, s->txp->len);
lan9118_receive(qemu_get_queue(s->nic), s->txp->data, s->txp->len);
} else {
qemu_send_packet(&s->nic->nc, s->txp->data, s->txp->len);
qemu_send_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len);
}
s->txp->fifo_used = 0;

Expand Down Expand Up @@ -1335,7 +1335,7 @@ static int lan9118_init1(SysBusDevice *dev)

s->nic = qemu_new_nic(&net_lan9118_info, &s->conf,
object_get_typename(OBJECT(dev)), dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
s->eeprom[0] = 0xa5;
for (i = 0; i < 6; i++) {
s->eeprom[i + 1] = s->conf.macaddr.a[i];
Expand Down
4 changes: 2 additions & 2 deletions hw/mcf_fec.c
Expand Up @@ -174,7 +174,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
if (bd.flags & FEC_BD_L) {
/* Last buffer in frame. */
DPRINTF("Sending packet\n");
qemu_send_packet(&s->nic->nc, frame, len);
qemu_send_packet(qemu_get_queue(s->nic), frame, len);
ptr = frame;
frame_size = 0;
s->eir |= FEC_INT_TXF;
Expand Down Expand Up @@ -476,5 +476,5 @@ void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd,

s->nic = qemu_new_nic(&net_mcf_fec_info, &s->conf, nd->model, nd->name, s);

qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
}
4 changes: 2 additions & 2 deletions hw/milkymist-minimac2.c
Expand Up @@ -257,7 +257,7 @@ static void minimac2_tx(MilkymistMinimac2State *s)
trace_milkymist_minimac2_tx_frame(txcount - 12);

/* send packet, skipping preamble and sfd */
qemu_send_packet_raw(&s->nic->nc, buf + 8, txcount - 12);
qemu_send_packet_raw(qemu_get_queue(s->nic), buf + 8, txcount - 12);

s->regs[R_TXCOUNT] = 0;

Expand Down Expand Up @@ -480,7 +480,7 @@ static int milkymist_minimac2_init(SysBusDevice *dev)
qemu_macaddr_default_if_unset(&s->conf.macaddr);
s->nic = qemu_new_nic(&net_milkymist_minimac2_info, &s->conf,
object_get_typename(OBJECT(dev)), dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions hw/mipsnet.c
Expand Up @@ -173,7 +173,7 @@ static void mipsnet_ioport_write(void *opaque, hwaddr addr,
if (s->tx_written == s->tx_count) {
/* Send buffer. */
trace_mipsnet_send(s->tx_count);
qemu_send_packet(&s->nic->nc, s->tx_buffer, s->tx_count);
qemu_send_packet(qemu_get_queue(s->nic), s->tx_buffer, s->tx_count);
s->tx_count = s->tx_written = 0;
s->intctl |= MIPSNET_INTCTL_TXDONE;
s->busy = 1;
Expand Down Expand Up @@ -241,7 +241,7 @@ static int mipsnet_sysbus_init(SysBusDevice *dev)

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);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/musicpal.c
Expand Up @@ -257,7 +257,7 @@ static void eth_send(mv88w8618_eth_state *s, int queue_index)
len = desc.bytes;
if (len < 2048) {
cpu_physical_memory_read(desc.buffer, buf, len);
qemu_send_packet(&s->nic->nc, buf, len);
qemu_send_packet(qemu_get_queue(s->nic), buf, len);
}
desc.cmdstat &= ~MP_ETH_TX_OWN;
s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
Expand Down
2 changes: 1 addition & 1 deletion hw/ne2000-isa.c
Expand Up @@ -77,7 +77,7 @@ static int isa_ne2000_initfn(ISADevice *dev)

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);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions hw/ne2000.c
Expand Up @@ -300,7 +300,8 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
index -= NE2000_PMEM_SIZE;
/* fail safe: check range on the transmitted length */
if (index + s->tcnt <= NE2000_PMEM_END) {
qemu_send_packet(&s->nic->nc, s->mem + index, s->tcnt);
qemu_send_packet(qemu_get_queue(s->nic), s->mem + index,
s->tcnt);
}
/* signal end of transfer */
s->tsr = ENTSR_PTX;
Expand Down Expand Up @@ -737,7 +738,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)

s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
object_get_typename(OBJECT(pci_dev)), pci_dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);

add_boot_device_path(s->c.bootindex, &pci_dev->qdev, "/ethernet-phy@0");

Expand All @@ -750,7 +751,7 @@ static void pci_ne2000_exit(PCIDevice *pci_dev)
NE2000State *s = &d->ne2000;

memory_region_destroy(&s->io);
qemu_del_net_client(&s->nic->nc);
qemu_del_net_client(qemu_get_queue(s->nic));
}

static Property ne2000_properties[] = {
Expand Down
6 changes: 3 additions & 3 deletions hw/opencores_eth.c
Expand Up @@ -339,7 +339,7 @@ static void open_eth_reset(void *opaque)
s->rx_desc = 0x40;

mii_reset(&s->mii);
open_eth_set_link_status(&s->nic->nc);
open_eth_set_link_status(qemu_get_queue(s->nic));
}

static int open_eth_can_receive(NetClientState *nc)
Expand Down Expand Up @@ -499,7 +499,7 @@ static void open_eth_start_xmit(OpenEthState *s, desc *tx)
if (tx_len > len) {
memset(buf + len, 0, tx_len - len);
}
qemu_send_packet(&s->nic->nc, buf, tx_len);
qemu_send_packet(qemu_get_queue(s->nic), buf, tx_len);

if (tx->len_flags & TXD_WR) {
s->tx_desc = 0;
Expand Down Expand Up @@ -606,7 +606,7 @@ static void open_eth_mii_command_host_write(OpenEthState *s, uint32_t val)
} else {
s->regs[MIIRX_DATA] = 0xffff;
}
SET_REGFIELD(s, MIISTATUS, LINKFAIL, s->nic->nc.link_down);
SET_REGFIELD(s, MIISTATUS, LINKFAIL, qemu_get_queue(s->nic)->link_down);
}
}

Expand Down
2 changes: 1 addition & 1 deletion hw/pcnet-pci.c
Expand Up @@ -279,7 +279,7 @@ static void pci_pcnet_uninit(PCIDevice *dev)
memory_region_destroy(&d->io_bar);
qemu_del_timer(d->state.poll_timer);
qemu_free_timer(d->state.poll_timer);
qemu_del_net_client(&d->state.nic->nc);
qemu_del_net_client(qemu_get_queue(d->state.nic));
}

static NetClientInfo net_pci_pcnet_info = {
Expand Down

0 comments on commit b356f76

Please sign in to comment.