Statistics
| Branch: | Revision:

root / hw / lance.c @ 6059631c

History | View | Annotate | Download (4.6 kB)

1 94e1a912 Gerd Hoffmann
/*
2 94e1a912 Gerd Hoffmann
 * QEMU AMD PC-Net II (Am79C970A) emulation
3 94e1a912 Gerd Hoffmann
 *
4 94e1a912 Gerd Hoffmann
 * Copyright (c) 2004 Antony T Curtis
5 94e1a912 Gerd Hoffmann
 *
6 94e1a912 Gerd Hoffmann
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 94e1a912 Gerd Hoffmann
 * of this software and associated documentation files (the "Software"), to deal
8 94e1a912 Gerd Hoffmann
 * in the Software without restriction, including without limitation the rights
9 94e1a912 Gerd Hoffmann
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 94e1a912 Gerd Hoffmann
 * copies of the Software, and to permit persons to whom the Software is
11 94e1a912 Gerd Hoffmann
 * furnished to do so, subject to the following conditions:
12 94e1a912 Gerd Hoffmann
 *
13 94e1a912 Gerd Hoffmann
 * The above copyright notice and this permission notice shall be included in
14 94e1a912 Gerd Hoffmann
 * all copies or substantial portions of the Software.
15 94e1a912 Gerd Hoffmann
 *
16 94e1a912 Gerd Hoffmann
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 94e1a912 Gerd Hoffmann
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 94e1a912 Gerd Hoffmann
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 94e1a912 Gerd Hoffmann
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 94e1a912 Gerd Hoffmann
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 94e1a912 Gerd Hoffmann
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 94e1a912 Gerd Hoffmann
 * THE SOFTWARE.
23 94e1a912 Gerd Hoffmann
 */
24 94e1a912 Gerd Hoffmann
25 94e1a912 Gerd Hoffmann
/* This software was written to be compatible with the specification:
26 94e1a912 Gerd Hoffmann
 * AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
27 94e1a912 Gerd Hoffmann
 * AMD Publication# 19436  Rev:E  Amendment/0  Issue Date: June 2000
28 94e1a912 Gerd Hoffmann
 */
29 94e1a912 Gerd Hoffmann
30 94e1a912 Gerd Hoffmann
/*
31 94e1a912 Gerd Hoffmann
 * On Sparc32, this is the Lance (Am7990) part of chip STP2000 (Master I/O), also
32 94e1a912 Gerd Hoffmann
 * produced as NCR89C100. See
33 94e1a912 Gerd Hoffmann
 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C100.txt
34 94e1a912 Gerd Hoffmann
 * and
35 94e1a912 Gerd Hoffmann
 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR92C990.txt
36 94e1a912 Gerd Hoffmann
 */
37 94e1a912 Gerd Hoffmann
38 94e1a912 Gerd Hoffmann
#include "sysbus.h"
39 94e1a912 Gerd Hoffmann
#include "net.h"
40 94e1a912 Gerd Hoffmann
#include "qemu-timer.h"
41 94e1a912 Gerd Hoffmann
#include "qemu_socket.h"
42 94e1a912 Gerd Hoffmann
#include "sun4m.h"
43 94e1a912 Gerd Hoffmann
#include "pcnet.h"
44 97bf4851 Blue Swirl
#include "trace.h"
45 94e1a912 Gerd Hoffmann
46 94e1a912 Gerd Hoffmann
typedef struct {
47 94e1a912 Gerd Hoffmann
    SysBusDevice busdev;
48 94e1a912 Gerd Hoffmann
    PCNetState state;
49 94e1a912 Gerd Hoffmann
} SysBusPCNetState;
50 94e1a912 Gerd Hoffmann
51 94e1a912 Gerd Hoffmann
static void parent_lance_reset(void *opaque, int irq, int level)
52 94e1a912 Gerd Hoffmann
{
53 94e1a912 Gerd Hoffmann
    SysBusPCNetState *d = opaque;
54 94e1a912 Gerd Hoffmann
    if (level)
55 94e1a912 Gerd Hoffmann
        pcnet_h_reset(&d->state);
56 94e1a912 Gerd Hoffmann
}
57 94e1a912 Gerd Hoffmann
58 94e1a912 Gerd Hoffmann
static void lance_mem_writew(void *opaque, target_phys_addr_t addr,
59 94e1a912 Gerd Hoffmann
                             uint32_t val)
60 94e1a912 Gerd Hoffmann
{
61 94e1a912 Gerd Hoffmann
    SysBusPCNetState *d = opaque;
62 97bf4851 Blue Swirl
63 97bf4851 Blue Swirl
    trace_lance_mem_writew(addr, val & 0xffff);
64 94e1a912 Gerd Hoffmann
    pcnet_ioport_writew(&d->state, addr, val & 0xffff);
65 94e1a912 Gerd Hoffmann
}
66 94e1a912 Gerd Hoffmann
67 94e1a912 Gerd Hoffmann
static uint32_t lance_mem_readw(void *opaque, target_phys_addr_t addr)
68 94e1a912 Gerd Hoffmann
{
69 94e1a912 Gerd Hoffmann
    SysBusPCNetState *d = opaque;
70 94e1a912 Gerd Hoffmann
    uint32_t val;
71 94e1a912 Gerd Hoffmann
72 94e1a912 Gerd Hoffmann
    val = pcnet_ioport_readw(&d->state, addr);
73 97bf4851 Blue Swirl
    trace_lance_mem_readw(addr, val & 0xffff);
74 94e1a912 Gerd Hoffmann
    return val & 0xffff;
75 94e1a912 Gerd Hoffmann
}
76 94e1a912 Gerd Hoffmann
77 94e1a912 Gerd Hoffmann
static CPUReadMemoryFunc * const lance_mem_read[3] = {
78 94e1a912 Gerd Hoffmann
    NULL,
79 94e1a912 Gerd Hoffmann
    lance_mem_readw,
80 94e1a912 Gerd Hoffmann
    NULL,
81 94e1a912 Gerd Hoffmann
};
82 94e1a912 Gerd Hoffmann
83 94e1a912 Gerd Hoffmann
static CPUWriteMemoryFunc * const lance_mem_write[3] = {
84 94e1a912 Gerd Hoffmann
    NULL,
85 94e1a912 Gerd Hoffmann
    lance_mem_writew,
86 94e1a912 Gerd Hoffmann
    NULL,
87 94e1a912 Gerd Hoffmann
};
88 94e1a912 Gerd Hoffmann
89 1fa51482 Mark McLoughlin
static void lance_cleanup(VLANClientState *nc)
90 94e1a912 Gerd Hoffmann
{
91 1fa51482 Mark McLoughlin
    PCNetState *d = DO_UPCAST(NICState, nc, nc)->opaque;
92 94e1a912 Gerd Hoffmann
93 94e1a912 Gerd Hoffmann
    pcnet_common_cleanup(d);
94 94e1a912 Gerd Hoffmann
}
95 94e1a912 Gerd Hoffmann
96 1fa51482 Mark McLoughlin
static NetClientInfo net_lance_info = {
97 1fa51482 Mark McLoughlin
    .type = NET_CLIENT_TYPE_NIC,
98 1fa51482 Mark McLoughlin
    .size = sizeof(NICState),
99 1fa51482 Mark McLoughlin
    .can_receive = pcnet_can_receive,
100 1fa51482 Mark McLoughlin
    .receive = pcnet_receive,
101 1fa51482 Mark McLoughlin
    .cleanup = lance_cleanup,
102 1fa51482 Mark McLoughlin
};
103 1fa51482 Mark McLoughlin
104 be73cfe2 Juan Quintela
static const VMStateDescription vmstate_lance = {
105 be73cfe2 Juan Quintela
    .name = "pcnet",
106 be73cfe2 Juan Quintela
    .version_id = 3,
107 be73cfe2 Juan Quintela
    .minimum_version_id = 2,
108 be73cfe2 Juan Quintela
    .minimum_version_id_old = 2,
109 be73cfe2 Juan Quintela
    .fields      = (VMStateField []) {
110 be73cfe2 Juan Quintela
        VMSTATE_STRUCT(state, SysBusPCNetState, 0, vmstate_pcnet, PCNetState),
111 be73cfe2 Juan Quintela
        VMSTATE_END_OF_LIST()
112 be73cfe2 Juan Quintela
    }
113 be73cfe2 Juan Quintela
};
114 be73cfe2 Juan Quintela
115 94e1a912 Gerd Hoffmann
static int lance_init(SysBusDevice *dev)
116 94e1a912 Gerd Hoffmann
{
117 94e1a912 Gerd Hoffmann
    SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev);
118 94e1a912 Gerd Hoffmann
    PCNetState *s = &d->state;
119 94e1a912 Gerd Hoffmann
120 94e1a912 Gerd Hoffmann
    s->mmio_index =
121 2507c12a Alexander Graf
        cpu_register_io_memory(lance_mem_read, lance_mem_write, d,
122 2507c12a Alexander Graf
                               DEVICE_NATIVE_ENDIAN);
123 94e1a912 Gerd Hoffmann
124 94e1a912 Gerd Hoffmann
    qdev_init_gpio_in(&dev->qdev, parent_lance_reset, 1);
125 94e1a912 Gerd Hoffmann
126 94e1a912 Gerd Hoffmann
    sysbus_init_mmio(dev, 4, s->mmio_index);
127 94e1a912 Gerd Hoffmann
128 94e1a912 Gerd Hoffmann
    sysbus_init_irq(dev, &s->irq);
129 94e1a912 Gerd Hoffmann
130 94e1a912 Gerd Hoffmann
    s->phys_mem_read = ledma_memory_read;
131 94e1a912 Gerd Hoffmann
    s->phys_mem_write = ledma_memory_write;
132 1fa51482 Mark McLoughlin
    return pcnet_common_init(&dev->qdev, s, &net_lance_info);
133 94e1a912 Gerd Hoffmann
}
134 94e1a912 Gerd Hoffmann
135 94e1a912 Gerd Hoffmann
static void lance_reset(DeviceState *dev)
136 94e1a912 Gerd Hoffmann
{
137 94e1a912 Gerd Hoffmann
    SysBusPCNetState *d = DO_UPCAST(SysBusPCNetState, busdev.qdev, dev);
138 94e1a912 Gerd Hoffmann
139 94e1a912 Gerd Hoffmann
    pcnet_h_reset(&d->state);
140 94e1a912 Gerd Hoffmann
}
141 94e1a912 Gerd Hoffmann
142 94e1a912 Gerd Hoffmann
static SysBusDeviceInfo lance_info = {
143 94e1a912 Gerd Hoffmann
    .init       = lance_init,
144 94e1a912 Gerd Hoffmann
    .qdev.name  = "lance",
145 779206de Gleb Natapov
    .qdev.fw_name  = "ethernet",
146 94e1a912 Gerd Hoffmann
    .qdev.size  = sizeof(SysBusPCNetState),
147 94e1a912 Gerd Hoffmann
    .qdev.reset = lance_reset,
148 be73cfe2 Juan Quintela
    .qdev.vmsd  = &vmstate_lance,
149 94e1a912 Gerd Hoffmann
    .qdev.props = (Property[]) {
150 94e1a912 Gerd Hoffmann
        DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
151 94e1a912 Gerd Hoffmann
        DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf),
152 94e1a912 Gerd Hoffmann
        DEFINE_PROP_END_OF_LIST(),
153 94e1a912 Gerd Hoffmann
    }
154 94e1a912 Gerd Hoffmann
};
155 94e1a912 Gerd Hoffmann
156 94e1a912 Gerd Hoffmann
static void lance_register_devices(void)
157 94e1a912 Gerd Hoffmann
{
158 94e1a912 Gerd Hoffmann
    sysbus_register_withprop(&lance_info);
159 94e1a912 Gerd Hoffmann
}
160 94e1a912 Gerd Hoffmann
device_init(lance_register_devices)