net: convert ne2000 to NICState
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									1673ad513e
								
							
						
					
					
						commit
						1c2045b549
					
				@ -35,13 +35,21 @@ typedef struct ISANE2000State {
 | 
				
			|||||||
    NE2000State ne2000;
 | 
					    NE2000State ne2000;
 | 
				
			||||||
} ISANE2000State;
 | 
					} ISANE2000State;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void isa_ne2000_cleanup(VLANClientState *vc)
 | 
					static void isa_ne2000_cleanup(VLANClientState *nc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NE2000State *s = vc->opaque;
 | 
					    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->vc = NULL;
 | 
					    s->nic = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static NetClientInfo net_ne2000_isa_info = {
 | 
				
			||||||
 | 
					    .type = NET_CLIENT_TYPE_NIC,
 | 
				
			||||||
 | 
					    .size = sizeof(NICState),
 | 
				
			||||||
 | 
					    .can_receive = ne2000_can_receive,
 | 
				
			||||||
 | 
					    .receive = ne2000_receive,
 | 
				
			||||||
 | 
					    .cleanup = isa_ne2000_cleanup,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int isa_ne2000_initfn(ISADevice *dev)
 | 
					static int isa_ne2000_initfn(ISADevice *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
 | 
					    ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
 | 
				
			||||||
@ -63,11 +71,9 @@ static int isa_ne2000_initfn(ISADevice *dev)
 | 
				
			|||||||
    qemu_macaddr_default_if_unset(&s->c.macaddr);
 | 
					    qemu_macaddr_default_if_unset(&s->c.macaddr);
 | 
				
			||||||
    ne2000_reset(s);
 | 
					    ne2000_reset(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
 | 
					    s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
 | 
				
			||||||
                                 dev->qdev.info->name, dev->qdev.id,
 | 
					                          dev->qdev.info->name, dev->qdev.id, s);
 | 
				
			||||||
                                 ne2000_can_receive, ne2000_receive, NULL,
 | 
					    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 | 
				
			||||||
                                 NULL, isa_ne2000_cleanup, s);
 | 
					 | 
				
			||||||
    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vmstate_register(-1, &vmstate_ne2000, s);
 | 
					    vmstate_register(-1, &vmstate_ne2000, s);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										35
									
								
								hw/ne2000.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								hw/ne2000.c
									
									
									
									
									
								
							@ -188,9 +188,9 @@ static int ne2000_buffer_full(NE2000State *s)
 | 
				
			|||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ne2000_can_receive(VLANClientState *vc)
 | 
					int ne2000_can_receive(VLANClientState *nc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NE2000State *s = vc->opaque;
 | 
					    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (s->cmd & E8390_STOP)
 | 
					    if (s->cmd & E8390_STOP)
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
@ -199,9 +199,9 @@ int ne2000_can_receive(VLANClientState *vc)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define MIN_BUF_SIZE 60
 | 
					#define MIN_BUF_SIZE 60
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
 | 
					ssize_t ne2000_receive(VLANClientState *nc, const uint8_t *buf, size_t size_)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NE2000State *s = vc->opaque;
 | 
					    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 | 
				
			||||||
    int size = size_;
 | 
					    int size = size_;
 | 
				
			||||||
    uint8_t *p;
 | 
					    uint8_t *p;
 | 
				
			||||||
    unsigned int total_len, next, avail, len, index, mcast_idx;
 | 
					    unsigned int total_len, next, avail, len, index, mcast_idx;
 | 
				
			||||||
@ -323,7 +323,7 @@ void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 | 
				
			|||||||
                    index -= NE2000_PMEM_SIZE;
 | 
					                    index -= NE2000_PMEM_SIZE;
 | 
				
			||||||
                /* fail safe: check range on the transmitted length  */
 | 
					                /* fail safe: check range on the transmitted length  */
 | 
				
			||||||
                if (index + s->tcnt <= NE2000_PMEM_END) {
 | 
					                if (index + s->tcnt <= NE2000_PMEM_END) {
 | 
				
			||||||
                    qemu_send_packet(s->vc, s->mem + index, s->tcnt);
 | 
					                    qemu_send_packet(&s->nic->nc, s->mem + index, s->tcnt);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                /* signal end of transfer */
 | 
					                /* signal end of transfer */
 | 
				
			||||||
                s->tsr = ENTSR_PTX;
 | 
					                s->tsr = ENTSR_PTX;
 | 
				
			||||||
@ -698,13 +698,21 @@ static void ne2000_map(PCIDevice *pci_dev, int region_num,
 | 
				
			|||||||
    register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
 | 
					    register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void ne2000_cleanup(VLANClientState *vc)
 | 
					static void ne2000_cleanup(VLANClientState *nc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NE2000State *s = vc->opaque;
 | 
					    NE2000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->vc = NULL;
 | 
					    s->nic = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static NetClientInfo net_ne2000_info = {
 | 
				
			||||||
 | 
					    .type = NET_CLIENT_TYPE_NIC,
 | 
				
			||||||
 | 
					    .size = sizeof(NICState),
 | 
				
			||||||
 | 
					    .can_receive = ne2000_can_receive,
 | 
				
			||||||
 | 
					    .receive = ne2000_receive,
 | 
				
			||||||
 | 
					    .cleanup = ne2000_cleanup,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int pci_ne2000_init(PCIDevice *pci_dev)
 | 
					static int pci_ne2000_init(PCIDevice *pci_dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
 | 
					    PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
 | 
				
			||||||
@ -725,11 +733,10 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    qemu_macaddr_default_if_unset(&s->c.macaddr);
 | 
					    qemu_macaddr_default_if_unset(&s->c.macaddr);
 | 
				
			||||||
    ne2000_reset(s);
 | 
					    ne2000_reset(s);
 | 
				
			||||||
    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer,
 | 
					
 | 
				
			||||||
                                 pci_dev->qdev.info->name, pci_dev->qdev.id,
 | 
					    s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
 | 
				
			||||||
                                 ne2000_can_receive, ne2000_receive, NULL,
 | 
					                          pci_dev->qdev.info->name, pci_dev->qdev.id, s);
 | 
				
			||||||
                                 NULL, ne2000_cleanup, s);
 | 
					    qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
 | 
				
			||||||
    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!pci_dev->qdev.hotplugged) {
 | 
					    if (!pci_dev->qdev.hotplugged) {
 | 
				
			||||||
        static int loaded = 0;
 | 
					        static int loaded = 0;
 | 
				
			||||||
@ -749,7 +756,7 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)
 | 
				
			|||||||
    NE2000State *s = &d->ne2000;
 | 
					    NE2000State *s = &d->ne2000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vmstate_unregister(&vmstate_pci_ne2000, s);
 | 
					    vmstate_unregister(&vmstate_pci_ne2000, s);
 | 
				
			||||||
    qemu_del_vlan_client(s->vc);
 | 
					    qemu_del_vlan_client(&s->nic->nc);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@ typedef struct NE2000State {
 | 
				
			|||||||
    uint8_t curpag;
 | 
					    uint8_t curpag;
 | 
				
			||||||
    uint8_t mult[8]; /* multicast mask array */
 | 
					    uint8_t mult[8]; /* multicast mask array */
 | 
				
			||||||
    qemu_irq irq;
 | 
					    qemu_irq irq;
 | 
				
			||||||
    VLANClientState *vc;
 | 
					    NICState *nic;
 | 
				
			||||||
    NICConf c;
 | 
					    NICConf c;
 | 
				
			||||||
    uint8_t mem[NE2000_MEM_SIZE];
 | 
					    uint8_t mem[NE2000_MEM_SIZE];
 | 
				
			||||||
} NE2000State;
 | 
					} NE2000State;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user