Revision 254111ec hw/rtl8139.c

b/hw/rtl8139.c
47 47
#include "pci.h"
48 48
#include "qemu-timer.h"
49 49
#include "net.h"
50
#include "loader.h"
50 51

  
51 52
/* debug RTL8139 card */
52 53
//#define DEBUG_RTL8139 1
......
465 466
    uint8_t  TxThresh;
466 467

  
467 468
    VLANClientState *vc;
468
    uint8_t macaddr[6];
469
    NICConf conf;
469 470
    int rtl8139_mmio_io_addr;
470 471

  
471 472
    /* C ring mode */
......
1179 1180
    int i;
1180 1181

  
1181 1182
    /* restore MAC address */
1182
    memcpy(s->phys, s->macaddr, 6);
1183
    memcpy(s->phys, s->conf.macaddr.a, 6);
1183 1184

  
1184 1185
    /* reset interrupt mask */
1185 1186
    s->IntrStatus = 0;
......
1195 1196
    s->eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
1196 1197
#endif
1197 1198

  
1198
    s->eeprom.contents[7] = s->macaddr[0] | s->macaddr[1] << 8;
1199
    s->eeprom.contents[8] = s->macaddr[2] | s->macaddr[3] << 8;
1200
    s->eeprom.contents[9] = s->macaddr[4] | s->macaddr[5] << 8;
1199
    s->eeprom.contents[7] = s->conf.macaddr.a[0] | s->conf.macaddr.a[1] << 8;
1200
    s->eeprom.contents[8] = s->conf.macaddr.a[2] | s->conf.macaddr.a[3] << 8;
1201
    s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
1201 1202

  
1202 1203
    /* mark all status registers as owned by host */
1203 1204
    for (i = 0; i < 4; ++i)
......
3171 3172

  
3172 3173
    i = 0;
3173 3174
    qemu_put_be32s(f, &i); /* unused.  */
3174
    qemu_put_buffer(f, s->macaddr, 6);
3175
    qemu_put_buffer(f, s->conf.macaddr.a, 6);
3175 3176
    qemu_put_be32(f, s->rtl8139_mmio_io_addr);
3176 3177

  
3177 3178
    qemu_put_be32s(f, &s->currTxDesc);
......
3268 3269
    qemu_get_8s(f, &s->TxThresh);
3269 3270

  
3270 3271
    qemu_get_be32s(f, &i); /* unused.  */
3271
    qemu_get_buffer(f, s->macaddr, 6);
3272
    qemu_get_buffer(f, s->conf.macaddr.a, 6);
3272 3273
    s->rtl8139_mmio_io_addr=qemu_get_be32(f);
3273 3274

  
3274 3275
    qemu_get_be32s(f, &s->currTxDesc);
......
3416 3417
{
3417 3418
    RTL8139State *s = vc->opaque;
3418 3419

  
3420
    s->vc = NULL;
3421
}
3422

  
3423
static int pci_rtl8139_uninit(PCIDevice *dev)
3424
{
3425
    RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
3426

  
3427
    cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
3419 3428
    if (s->cplus_txbuffer) {
3420 3429
        qemu_free(s->cplus_txbuffer);
3421 3430
        s->cplus_txbuffer = NULL;
3422 3431
    }
3423

  
3424 3432
#ifdef RTL8139_ONBOARD_TIMER
3425 3433
    qemu_del_timer(s->timer);
3426 3434
    qemu_free_timer(s->timer);
3427 3435
#endif
3428

  
3429 3436
    unregister_savevm("rtl8139", s);
3430
}
3431

  
3432
static int pci_rtl8139_uninit(PCIDevice *dev)
3433
{
3434
    RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
3435

  
3436
    cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
3437

  
3437
    qemu_del_vlan_client(s->vc);
3438 3438
    return 0;
3439 3439
}
3440 3440

  
......
3463 3463
    pci_register_bar(&s->dev, 1, 0x100,
3464 3464
                           PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
3465 3465

  
3466
    qdev_get_macaddr(&dev->qdev, s->macaddr);
3466
    qemu_macaddr_default_if_unset(&s->conf.macaddr);
3467 3467
    rtl8139_reset(&s->dev.qdev);
3468
    s->vc = qdev_get_vlan_client(&dev->qdev,
3468
    s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC,
3469
                                 s->conf.vlan, s->conf.peer,
3470
                                 dev->qdev.info->name, dev->qdev.id,
3469 3471
                                 rtl8139_can_receive, rtl8139_receive, NULL,
3470
                                 rtl8139_cleanup, s);
3471

  
3472
    qemu_format_nic_info_str(s->vc, s->macaddr);
3472
                                 NULL, rtl8139_cleanup, s);
3473
    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
3473 3474

  
3474 3475
    s->cplus_txbuffer = NULL;
3475 3476
    s->cplus_txbuffer_len = 0;
......
3483 3484
    qemu_mod_timer(s->timer,
3484 3485
        rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
3485 3486
#endif /* RTL8139_ONBOARD_TIMER */
3487

  
3488
    if (!dev->qdev.hotplugged) {
3489
        static int loaded = 0;
3490
        if (!loaded) {
3491
            rom_add_option("pxe-rtl8139.bin");
3492
            loaded = 1;
3493
        }
3494
    }
3486 3495
    return 0;
3487 3496
}
3488 3497

  
......
3492 3501
    .qdev.reset = rtl8139_reset,
3493 3502
    .init       = pci_rtl8139_init,
3494 3503
    .exit       = pci_rtl8139_uninit,
3504
    .qdev.props = (Property[]) {
3505
        DEFINE_NIC_PROPERTIES(RTL8139State, conf),
3506
        DEFINE_PROP_END_OF_LIST(),
3507
    }
3495 3508
};
3496 3509

  
3497 3510
static void rtl8139_register_devices(void)

Also available in: Unified diff