提交 a03e2aec 编写于 作者: M Mark McLoughlin 提交者: Anthony Liguori

net: convert e1000 to NICState

Signed-off-by: NMark McLoughlin <markmc@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 eb6b6c12
...@@ -75,7 +75,7 @@ enum { ...@@ -75,7 +75,7 @@ enum {
typedef struct E1000State_st { typedef struct E1000State_st {
PCIDevice dev; PCIDevice dev;
VLANClientState *vc; NICState *nic;
NICConf conf; NICConf conf;
int mmio_index; int mmio_index;
...@@ -385,9 +385,9 @@ xmit_seg(E1000State *s) ...@@ -385,9 +385,9 @@ xmit_seg(E1000State *s)
if (tp->vlan_needed) { if (tp->vlan_needed) {
memmove(tp->vlan, tp->data, 12); memmove(tp->vlan, tp->data, 12);
memcpy(tp->data + 8, tp->vlan_header, 4); memcpy(tp->data + 8, tp->vlan_header, 4);
qemu_send_packet(s->vc, tp->vlan, tp->size + 4); qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4);
} else } else
qemu_send_packet(s->vc, tp->data, tp->size); qemu_send_packet(&s->nic->nc, tp->data, tp->size);
s->mac_reg[TPT]++; s->mac_reg[TPT]++;
s->mac_reg[GPTC]++; s->mac_reg[GPTC]++;
n = s->mac_reg[TOTL]; n = s->mac_reg[TOTL];
...@@ -590,12 +590,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size) ...@@ -590,12 +590,12 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
} }
static void static void
e1000_set_link_status(VLANClientState *vc) e1000_set_link_status(VLANClientState *nc)
{ {
E1000State *s = vc->opaque; E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
uint32_t old_status = s->mac_reg[STATUS]; uint32_t old_status = s->mac_reg[STATUS];
if (vc->link_down) if (nc->link_down)
s->mac_reg[STATUS] &= ~E1000_STATUS_LU; s->mac_reg[STATUS] &= ~E1000_STATUS_LU;
else else
s->mac_reg[STATUS] |= E1000_STATUS_LU; s->mac_reg[STATUS] |= E1000_STATUS_LU;
...@@ -605,17 +605,17 @@ e1000_set_link_status(VLANClientState *vc) ...@@ -605,17 +605,17 @@ e1000_set_link_status(VLANClientState *vc)
} }
static int static int
e1000_can_receive(VLANClientState *vc) e1000_can_receive(VLANClientState *nc)
{ {
E1000State *s = vc->opaque; E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
return (s->mac_reg[RCTL] & E1000_RCTL_EN); return (s->mac_reg[RCTL] & E1000_RCTL_EN);
} }
static ssize_t static ssize_t
e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size) e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{ {
E1000State *s = vc->opaque; E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
struct e1000_rx_desc desc; struct e1000_rx_desc desc;
target_phys_addr_t base; target_phys_addr_t base;
unsigned int n, rdt; unsigned int n, rdt;
...@@ -1037,11 +1037,11 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num, ...@@ -1037,11 +1037,11 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num,
} }
static void static void
e1000_cleanup(VLANClientState *vc) e1000_cleanup(VLANClientState *nc)
{ {
E1000State *d = vc->opaque; E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
d->vc = NULL; s->nic = NULL;
} }
static int static int
...@@ -1050,7 +1050,7 @@ pci_e1000_uninit(PCIDevice *dev) ...@@ -1050,7 +1050,7 @@ pci_e1000_uninit(PCIDevice *dev)
E1000State *d = DO_UPCAST(E1000State, dev, dev); E1000State *d = DO_UPCAST(E1000State, dev, dev);
cpu_unregister_io_memory(d->mmio_index); cpu_unregister_io_memory(d->mmio_index);
qemu_del_vlan_client(d->vc); qemu_del_vlan_client(&d->nic->nc);
vmstate_unregister(&vmstate_e1000, d); vmstate_unregister(&vmstate_e1000, d);
return 0; return 0;
} }
...@@ -1067,6 +1067,15 @@ static void e1000_reset(void *opaque) ...@@ -1067,6 +1067,15 @@ static void e1000_reset(void *opaque)
memset(&d->tx, 0, sizeof d->tx); memset(&d->tx, 0, sizeof d->tx);
} }
static NetClientInfo net_e1000_info = {
.type = NET_CLIENT_TYPE_NIC,
.size = sizeof(NICState),
.can_receive = e1000_can_receive,
.receive = e1000_receive,
.cleanup = e1000_cleanup,
.link_status_changed = e1000_set_link_status,
};
static int pci_e1000_init(PCIDevice *pci_dev) static int pci_e1000_init(PCIDevice *pci_dev)
{ {
E1000State *d = DO_UPCAST(E1000State, dev, pci_dev); E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
...@@ -1107,14 +1116,10 @@ static int pci_e1000_init(PCIDevice *pci_dev) ...@@ -1107,14 +1116,10 @@ static int pci_e1000_init(PCIDevice *pci_dev)
checksum = (uint16_t) EEPROM_SUM - checksum; checksum = (uint16_t) EEPROM_SUM - checksum;
d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
d->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
d->conf.vlan, d->conf.peer, d->dev.qdev.info->name, d->dev.qdev.id, d);
d->dev.qdev.info->name, d->dev.qdev.id,
e1000_can_receive, e1000_receive, NULL,
NULL, e1000_cleanup, d);
d->vc->link_status_changed = e1000_set_link_status;
qemu_format_nic_info_str(d->vc, macaddr); qemu_format_nic_info_str(&d->nic->nc, macaddr);
vmstate_register(-1, &vmstate_e1000, d); vmstate_register(-1, &vmstate_e1000, d);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册