Revision 7c9d8e07 hw/lance.c

b/hw/lance.c
154 154
#define LEDMA_MAXADDR (LEDMA_REGS * 4 - 1)
155 155

  
156 156
typedef struct LANCEState {
157
    NetDriverState *nd;
157
    VLANClientState *vc;
158
    uint8_t macaddr[6]; /* init mac address */
158 159
    uint32_t leptr;
159 160
    uint16_t addr;
160 161
    uint16_t regs[LE_NREGS];
......
169 170
static void lance_reset(void *opaque)
170 171
{
171 172
    LANCEState *s = opaque;
172
    memcpy(s->phys, s->nd->macaddr, 6);
173
    memcpy(s->phys, s->macaddr, 6);
173 174
    s->rxptr = 0;
174 175
    s->txptr = 0;
175 176
    memset(s->regs, 0, LE_NREGS * 2);
......
280 281
};
281 282

  
282 283

  
283
/* return the max buffer size if the LANCE can receive more data */
284
static int lance_can_receive(void *opaque)
285
{
286
    LANCEState *s = opaque;
287
    uint32_t dmaptr = s->leptr + s->ledmaregs[3];
288
    struct lance_init_block *ib;
289
    int i;
290
    uint8_t temp8;
291

  
292
    if ((s->regs[LE_CSR0] & LE_C0_STOP) == LE_C0_STOP)
293
	return 0;
294

  
295
    ib = (void *) iommu_translate(dmaptr);
296

  
297
    for (i = 0; i < RX_RING_SIZE; i++) {
298
	cpu_physical_memory_read((uint32_t)&ib->brx_ring[i].rmd1_bits, (void *) &temp8, 1);
299
	if (temp8 == (LE_R1_OWN)) {
300
	    DPRINTF("can receive %d\n", RX_BUFF_SIZE);
301
	    return RX_BUFF_SIZE;
302
	}
303
    }
304
    DPRINTF("cannot receive\n");
305
    return 0;
306
}
307

  
308 284
#define MIN_BUF_SIZE 60
309 285

  
310 286
static void lance_receive(void *opaque, const uint8_t *buf, int size)
......
368 344
	    temp16 = (~temp16) + 1;
369 345
	    cpu_physical_memory_read((uint32_t)&ib->tx_buf[i], pkt_buf, temp16);
370 346
	    DPRINTF("sending packet, len %d\n", temp16);
371
	    qemu_send_packet(s->nd, pkt_buf, temp16);
347
	    qemu_send_packet(s->vc, pkt_buf, temp16);
372 348
	    temp8 = LE_T1_POK;
373 349
	    cpu_physical_memory_write((uint32_t)&ib->btx_ring[i].tmd1_bits, (void *) &temp8, 1);
374 350
	    s->txptr = (s->txptr + 1) & TX_RING_MOD_MASK;
......
443 419
    return 0;
444 420
}
445 421

  
446
void lance_init(NetDriverState *nd, int irq, uint32_t leaddr, uint32_t ledaddr)
422
void lance_init(NICInfo *nd, int irq, uint32_t leaddr, uint32_t ledaddr)
447 423
{
448 424
    LANCEState *s;
449 425
    int lance_io_memory, ledma_io_memory;
......
452 428
    if (!s)
453 429
        return;
454 430

  
455
    s->nd = nd;
456 431
    s->irq = irq;
457 432

  
458 433
    lance_io_memory = cpu_register_io_memory(0, lance_mem_read, lance_mem_write, s);
......
461 436
    ledma_io_memory = cpu_register_io_memory(0, ledma_mem_read, ledma_mem_write, s);
462 437
    cpu_register_physical_memory(ledaddr, 16, ledma_io_memory);
463 438

  
439
    memcpy(s->macaddr, nd->macaddr, 6);
440

  
464 441
    lance_reset(s);
465
    qemu_add_read_packet(nd, lance_can_receive, lance_receive, s);
442

  
443
    s->vc = qemu_new_vlan_client(nd->vlan, lance_receive, s);
444

  
445
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
446
             "lance macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
447
             s->macaddr[0],
448
             s->macaddr[1],
449
             s->macaddr[2],
450
             s->macaddr[3],
451
             s->macaddr[4],
452
             s->macaddr[5]);
453

  
466 454
    register_savevm("lance", leaddr, 1, lance_save, lance_load, s);
467 455
    qemu_register_reset(lance_reset, s);
468 456
}

Also available in: Unified diff